From patchwork Fri Feb 9 14:39:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 127857 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp679766ljc; Fri, 9 Feb 2018 06:42:08 -0800 (PST) X-Google-Smtp-Source: AH8x225TAd+4ZbCkZt8EOcg1KS5rW7co6SXrGMaG1vGIdQvuYtK3bN4vNgFR5ax8UzbEuAxuQxeD X-Received: by 10.36.146.196 with SMTP id l187mr3835194itd.115.1518187328076; Fri, 09 Feb 2018 06:42:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518187328; cv=none; d=google.com; s=arc-20160816; b=HiL0/Hr6GU8ovbKF1174DcGSJ1tIpQDbaRuoazmFD9lutUIohMzhwTMb3UNRe073gp sDoB//XZLpTMsvmmoxIkaOTDdKYQ6A7aI1YvWal7llFJHP2OwxymFMwak0YMvLNmD1Ek Rkd+OAwq7BoR86jyADqLxDUteOaWlgAk2vl9yvhqthOvoywcztHnb17d4J1xFQWjmWw1 oiJrrsjBKoYj8y3Ul6ZghOkcR/rq9TlhY8e8RisBZKg/V8ELb/RouNjEumE6JCir1Lbj DhgF6pxTVoT7H2uihCR2jVdBvsAeDiQBxR3nS5h2yT6O8SU3tnLeYd2Qvh3XiLAN5HBh 4zwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-unsubscribe:list-id :precedence:subject:references:in-reply-to:message-id:date:to:from :dkim-signature:arc-authentication-results; bh=RMWImH2/Jkjoe90e2eUhSGmdkpvgy5AdXDt7HfE0PzM=; b=s4CHuHikNA46iNlK9T/iVVNdgW4L4Jhey5dJfL4PXdNhuYJ2MwAZ9fUlzA4Pf+rD0E MByTX712NiclDCQYeeZDiFSG4Sd10X/z1T/iffLzuM/LNUPvcfRZdIYh7rgAvxnpp1Zu nWpt2ITU5O1zMOD7S4mJo306fLR0U3Qa93i4YggWSsLSJEvJlmtiaRJjmQQ2NwnX5VnS zxN9q69QYxwkA0Nob/T4xbJ3rtDyRBWRHkZ2LLbOo0rKUo03w5Be5b9HtmbyFR+ndaEB tW1dNtCYDKjMmn4+MSwZPniavUs6rzNqg43eQpQ0MvWYvYf/9hnnj9XnoWqivXJOFs9O 5YTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TZlGogoS; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org. [192.237.175.120]) by mx.google.com with ESMTPS id b64si327486itb.151.2018.02.09.06.42.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Feb 2018 06:42:08 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=TZlGogoS; spf=pass (google.com: best guess record for domain of xen-devel-bounces@lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ek9qf-0001AG-5q; Fri, 09 Feb 2018 14:40:21 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ek9qe-000160-4R for xen-devel@lists.xenproject.org; Fri, 09 Feb 2018 14:40:20 +0000 X-Inumbo-ID: 1538bf18-0da7-11e8-ba59-bc764e045a96 Received: from mail-wm0-x241.google.com (unknown [2a00:1450:400c:c09::241]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 1538bf18-0da7-11e8-ba59-bc764e045a96; Fri, 09 Feb 2018 15:39:50 +0100 (CET) Received: by mail-wm0-x241.google.com with SMTP id v123so16701751wmd.5 for ; Fri, 09 Feb 2018 06:40:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references; bh=w1/mc7EUc6Pu1axvPzxD6xvfxu53NeLtG1vfF8+rYUE=; b=TZlGogoS341cVJ2lNvSruq3NpC2lDqZfokMleYFJMIWHawEfB7gTlAy8I9iS/F9+RO WVRIIVyUOrGP783Ep4OW5xQn8Bh2s7HdiTLciXvgMSBvW6oXSfd3JApCBut7O05hkb0N x6pqGUiZruK5YKNlc7qQWJwZLR1HvRC2rGh6s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=w1/mc7EUc6Pu1axvPzxD6xvfxu53NeLtG1vfF8+rYUE=; b=FbYHf1LVy3pAdhyYCA7eZ1o42Z1MbjQz/Qx+YA79Zkcx5vRpT0sex/qh1G8fdAHZ1z iz5O7fRkvYyXcZ0sn1Ztkgu/1OmGIoKL+LYryzOh5uql4kkHh1jtAYJzHInhUkZvPZHM IH56ZDohhrOcnCWG25pfCWADDPGPqyE0bQ0RNhrB1ozNd5vASwurXQ2XT3j8RwZ57zO8 QVYxe5hPGaR/Gsm5BrLAkMgItEEuxpgmtt2GpZZ8ao3g5B5HEx2SlOmZWlulVWs+Jm02 uHue7qbYA3hGYRpyVcpMwV8x1z4X7OgHobdqaOzncd5BzUsP3np6K/QU1gMs012mWNad CwEw== X-Gm-Message-State: APf1xPCOPERUTj2eV3RMzIKjNnTikubgsaTXoVyJtiNs/0rqVgWhka2o 9Y9Vd/rf+NNPA7fImhO6VOBIjg== X-Received: by 10.28.20.8 with SMTP id 8mr2172214wmu.106.1518187217937; Fri, 09 Feb 2018 06:40:17 -0800 (PST) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id b35sm2552229wra.13.2018.02.09.06.40.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Feb 2018 06:40:17 -0800 (PST) From: Andre Przywara To: Stefano Stabellini , Julien Grall , xen-devel@lists.xenproject.org Date: Fri, 9 Feb 2018 14:39:19 +0000 Message-Id: <20180209143937.28866-32-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180209143937.28866-1-andre.przywara@linaro.org> References: <20180209143937.28866-1-andre.przywara@linaro.org> Subject: [Xen-devel] [RFC PATCH 31/49] ARM: new VGIC: Add PENDING registers handlers X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The pending register handlers are shared between the v2 and v3 emulation, so their implementation goes into vgic-mmio.c, to be easily referenced from the v3 emulation as well later. For level triggered interrupts the real line level is unaffected by this write, so we keep this state separate and combine it with the device's level to get the actual pending state. This is based on Linux commit 96b298000db4, written by Andre Przywara. Signed-off-by: Andre Przywara --- xen/arch/arm/vgic/vgic-mmio-v2.c | 4 +-- xen/arch/arm/vgic/vgic-mmio.c | 62 ++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/vgic/vgic-mmio.h | 11 +++++++ 3 files changed, 75 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/vgic/vgic-mmio-v2.c b/xen/arch/arm/vgic/vgic-mmio-v2.c index eca6840ff9..ceb86900a0 100644 --- a/xen/arch/arm/vgic/vgic-mmio-v2.c +++ b/xen/arch/arm/vgic/vgic-mmio-v2.c @@ -80,10 +80,10 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = { vgic_mmio_read_enable, vgic_mmio_write_cenable, NULL, NULL, 1, VGIC_ACCESS_32bit), REGISTER_DESC_WITH_BITS_PER_IRQ(GICD_ISPENDR, - vgic_mmio_read_raz, vgic_mmio_write_wi, NULL, NULL, 1, + vgic_mmio_read_pending, vgic_mmio_write_spending, NULL, NULL, 1, VGIC_ACCESS_32bit), REGISTER_DESC_WITH_BITS_PER_IRQ(GICD_ICPENDR, - vgic_mmio_read_raz, vgic_mmio_write_wi, NULL, NULL, 1, + vgic_mmio_read_pending, vgic_mmio_write_cpending, NULL, NULL, 1, VGIC_ACCESS_32bit), REGISTER_DESC_WITH_BITS_PER_IRQ(GICD_ISACTIVER, vgic_mmio_read_raz, vgic_mmio_write_wi, NULL, NULL, 1, diff --git a/xen/arch/arm/vgic/vgic-mmio.c b/xen/arch/arm/vgic/vgic-mmio.c index 3d9fa02a10..9a65e39d78 100644 --- a/xen/arch/arm/vgic/vgic-mmio.c +++ b/xen/arch/arm/vgic/vgic-mmio.c @@ -153,6 +153,68 @@ void vgic_mmio_write_cenable(struct vcpu *vcpu, } } +unsigned long vgic_mmio_read_pending(struct vcpu *vcpu, + paddr_t addr, unsigned int len) +{ + u32 intid = VGIC_ADDR_TO_INTID(addr, 1); + u32 value = 0; + int i; + + /* Loop over all IRQs affected by this read */ + for ( i = 0; i < len * 8; i++ ) + { + struct vgic_irq *irq = vgic_get_irq(vcpu->domain, vcpu, intid + i); + + if ( irq_is_pending(irq) ) + value |= (1U << i); + + vgic_put_irq(vcpu->domain, irq); + } + + return value; +} + +void vgic_mmio_write_spending(struct vcpu *vcpu, + paddr_t addr, unsigned int len, + unsigned long val) +{ + u32 intid = VGIC_ADDR_TO_INTID(addr, 1); + int i; + unsigned long flags; + + for_each_set_bit( i, &val, len * 8 ) + { + struct vgic_irq *irq = vgic_get_irq(vcpu->domain, vcpu, intid + i); + + spin_lock_irqsave(&irq->irq_lock, flags); + irq->pending_latch = true; + + vgic_queue_irq_unlock(vcpu->domain, irq, flags); + vgic_put_irq(vcpu->domain, irq); + } +} + +void vgic_mmio_write_cpending(struct vcpu *vcpu, + paddr_t addr, unsigned int len, + unsigned long val) +{ + u32 intid = VGIC_ADDR_TO_INTID(addr, 1); + int i; + unsigned long flags; + + for_each_set_bit( i, &val, len * 8 ) + { + struct vgic_irq *irq = vgic_get_irq(vcpu->domain, vcpu, intid + i); + + spin_lock_irqsave(&irq->irq_lock, flags); + + irq->pending_latch = false; + + spin_unlock_irqrestore(&irq->irq_lock, flags); + vgic_put_irq(vcpu->domain, irq); + } +} + static int match_region(const void *key, const void *elt) { const unsigned int offset = (unsigned long)key; diff --git a/xen/arch/arm/vgic/vgic-mmio.h b/xen/arch/arm/vgic/vgic-mmio.h index 9f34bd1aec..209afbbb9a 100644 --- a/xen/arch/arm/vgic/vgic-mmio.h +++ b/xen/arch/arm/vgic/vgic-mmio.h @@ -148,6 +148,17 @@ void vgic_mmio_write_cenable(struct vcpu *vcpu, paddr_t addr, unsigned int len, unsigned long val); +unsigned long vgic_mmio_read_pending(struct vcpu *vcpu, + paddr_t addr, unsigned int len); + +void vgic_mmio_write_spending(struct vcpu *vcpu, + paddr_t addr, unsigned int len, + unsigned long val); + +void vgic_mmio_write_cpending(struct vcpu *vcpu, + paddr_t addr, unsigned int len, + unsigned long val); + unsigned int vgic_v2_init_dist_iodev(struct vgic_io_device *dev); /* Find the proper register handler entry given a certain address offset */