From patchwork Fri Feb 9 14:39:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 127822 Delivered-To: patch@linaro.org Received: by 10.46.124.24 with SMTP id x24csp679583ljc; Fri, 9 Feb 2018 06:41:58 -0800 (PST) X-Google-Smtp-Source: AH8x225cV5io35ck5YRsekOol2XoYm1IByFlf0O2qjOqcXizVEl3RMjDVrUr9PVDcwP9JINCq029 X-Received: by 10.36.214.9 with SMTP id o9mr3537029itg.132.1518187318004; Fri, 09 Feb 2018 06:41:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1518187317; cv=none; d=google.com; s=arc-20160816; b=gmSU3DfmguyBeCJhxhnORkYhha4h6dM/niHh4v/upUVcanH6L4nsuVy2rrVH7TQfdV txHPMaGO4lLUxJIScL8nORxZwpYd9BqDju/ZY2kgICfNvinX4DMqIkG71/QsAe3RF236 IZEe0wj0Rkn7KJkR4dd4eD7g9l0C5grBglroR8TvEIun43l6tkr0XBJX6oY+WQHCi/G5 epR0jUoRNRshSg/G9+HG1VNDpvYSb8+qt4fmFNa5A+cgAbsDArjhugH/KOCsJQZ5mYWl uI1/XdL8H/GsHUfpmb2mXzm3T9hv7DrF8oFprU4Ac+qibT4AOjNCFVRr2RzQBCXirAMv R5wQ== 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=GGXV33hD6BaXILR1Z42HGv/+5Yzf21N1Ep9jN9FEykA=; b=vFAkRKkg31g+BDqe7d6bBq3auk0PTBYLT4jwCnmV3ncyB80tcpyd4jWndcIcRipKJ1 VgD9l2z5b0bEuqxA516VU45v8K66FTDm0A0XuQVtWf/CSB71eKh93odLuoe+AcIuzL23 oPovzDm0tsQbW+5XLPBJEOLgsk5IbTINAgbesZRDRDn1R2QOmo9sTaz9TN8ZYyfq/+CT ofW51yxos+X1ma5gJh5AwSfx3i+yeXIpl8dm9FGHulUBUqUpqiCYhgEqrSUYKp+5rUgL QrmfTqr6z7kXLMneAYwmKgnfdF3/OZOygh4/WGg9jX73JlSb+0LKOkiknVDYdXg7aOht XIgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=dM+Whtzd; 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 l206si1677348ita.80.2018.02.09.06.41.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Feb 2018 06:41:57 -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=dM+Whtzd; 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 1ek9qh-0001Hf-M9; Fri, 09 Feb 2018 14:40:23 +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 1ek9qg-0001D4-Cy for xen-devel@lists.xenproject.org; Fri, 09 Feb 2018 14:40:22 +0000 X-Inumbo-ID: 167afeae-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 167afeae-0da7-11e8-ba59-bc764e045a96; Fri, 09 Feb 2018 15:39:53 +0100 (CET) Received: by mail-wm0-x241.google.com with SMTP id 143so15758189wma.5 for ; Fri, 09 Feb 2018 06:40:21 -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=xT9jW6gK65oavpkRtt4G+109ROqRRUMkTGJt39zOXz0=; b=dM+WhtzdSzZOCuKDdQTvg+OQQ3kzd5mBVhCAEwAX2XwhHTnbq7bX9p9s13hOzlw+wy +MrninOGlJdhu1dtgXME6cNK/VK8rAH9aBY4RYy16JN7dRr2DGwcHJA3l1Avwktrg2aw zNZo0LlPt5m6kCEMCWY8YceCu7EgApf5oWd9k= 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=xT9jW6gK65oavpkRtt4G+109ROqRRUMkTGJt39zOXz0=; b=hsjUtY8OGU31I2PtIKxkvb7hL4AFVzJUAYESTr+ZjpE3lMjFTvyqJvXfglFdVKHQlg DR7fplRbRFnZb8l5/iUzwdyf2CoT2sJp6ZbNJBlag+jJR1dp40nGU5DfMfC31MvWNDzB K1RFT58CV/bHUYxsUl8eWP1B9jf55ykMatPHVzrne0oIFV98AI0elEhqkIgvx+Un7giW tPuit7tRkSBM0ExALYQuthMXyErX1moHSYMkQBxOvN2cqsF2UUOH6DR5C47ieuiJ1ptp QZ80LVW+Cf9sU6YFc7Uq/TyEfydniS+RRQdCAin+9NT1+R5Oggz0IOgQkEbNzWh/8sl9 YJnw== X-Gm-Message-State: APf1xPBRDqW68tU5zc4pL1/5OuRT7WXKt2TMOtxOX8ZLOhZWkyp2VxQ5 waWfZGw3N6B+jo/XApglijUjXA== X-Received: by 10.28.122.11 with SMTP id v11mr2084671wmc.38.1518187220022; Fri, 09 Feb 2018 06:40:20 -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.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Feb 2018 06:40:19 -0800 (PST) From: Andre Przywara To: Stefano Stabellini , Julien Grall , xen-devel@lists.xenproject.org Date: Fri, 9 Feb 2018 14:39:21 +0000 Message-Id: <20180209143937.28866-34-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 33/49] ARM: new VGIC: Add PRIORITY 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 priority 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. There is a corner case when we change the priority of a pending interrupt which we don't handle at the moment. This is based on Linux commit dd238ec2b87b, 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 | 47 ++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/vgic/vgic-mmio.h | 7 ++++++ xen/arch/arm/vgic/vgic.h | 2 ++ 4 files changed, 58 insertions(+), 2 deletions(-) diff --git a/xen/arch/arm/vgic/vgic-mmio-v2.c b/xen/arch/arm/vgic/vgic-mmio-v2.c index eba24d9866..0574ff9b16 100644 --- a/xen/arch/arm/vgic/vgic-mmio-v2.c +++ b/xen/arch/arm/vgic/vgic-mmio-v2.c @@ -92,8 +92,8 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = { vgic_mmio_read_active, vgic_mmio_write_cactive, NULL, NULL, 1, VGIC_ACCESS_32bit), REGISTER_DESC_WITH_BITS_PER_IRQ(GICD_IPRIORITYR, - vgic_mmio_read_raz, vgic_mmio_write_wi, NULL, NULL, 8, - VGIC_ACCESS_32bit | VGIC_ACCESS_8bit), + vgic_mmio_read_priority, vgic_mmio_write_priority, NULL, NULL, + 8, VGIC_ACCESS_32bit | VGIC_ACCESS_8bit), REGISTER_DESC_WITH_BITS_PER_IRQ(GICD_ITARGETSR, vgic_mmio_read_raz, vgic_mmio_write_wi, NULL, NULL, 8, VGIC_ACCESS_32bit | VGIC_ACCESS_8bit), diff --git a/xen/arch/arm/vgic/vgic-mmio.c b/xen/arch/arm/vgic/vgic-mmio.c index ac3aa03fbc..14570d9d8e 100644 --- a/xen/arch/arm/vgic/vgic-mmio.c +++ b/xen/arch/arm/vgic/vgic-mmio.c @@ -309,6 +309,53 @@ void vgic_mmio_write_sactive(struct vcpu *vcpu, spin_unlock(&vcpu->domain->domain_lock); } +unsigned long vgic_mmio_read_priority(struct vcpu *vcpu, + paddr_t addr, unsigned int len) +{ + u32 intid = VGIC_ADDR_TO_INTID(addr, 8); + int i; + u64 val = 0; + + for ( i = 0; i < len; i++ ) + { + struct vgic_irq *irq = vgic_get_irq(vcpu->domain, vcpu, intid + i); + + val |= (u64)irq->priority << (i * 8); + + vgic_put_irq(vcpu->domain, irq); + } + + return val; +} + +/* + * We currently don't handle changing the priority of an interrupt that + * is already pending on a VCPU. If there is a need for this, we would + * need to make this VCPU exit and re-evaluate the priorities, potentially + * leading to this interrupt getting presented now to the guest (if it has + * been masked by the priority mask before). + */ +void vgic_mmio_write_priority(struct vcpu *vcpu, + paddr_t addr, unsigned int len, + unsigned long val) +{ + u32 intid = VGIC_ADDR_TO_INTID(addr, 8); + int i; + unsigned long flags; + + for ( i = 0; i < len; i++ ) + { + struct vgic_irq *irq = vgic_get_irq(vcpu->domain, vcpu, intid + i); + + spin_lock_irqsave(&irq->irq_lock, flags); + /* Narrow the priority range to what we actually support */ + irq->priority = (val >> (i * 8)) & GENMASK(7, 8 - VGIC_PRI_BITS); + 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 39e854232e..30221096b9 100644 --- a/xen/arch/arm/vgic/vgic-mmio.h +++ b/xen/arch/arm/vgic/vgic-mmio.h @@ -170,6 +170,13 @@ void vgic_mmio_write_sactive(struct vcpu *vcpu, paddr_t addr, unsigned int len, unsigned long val); +unsigned long vgic_mmio_read_priority(struct vcpu *vcpu, + paddr_t addr, unsigned int len); + +void vgic_mmio_write_priority(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 */ diff --git a/xen/arch/arm/vgic/vgic.h b/xen/arch/arm/vgic/vgic.h index 82fe902e26..b104f8e964 100644 --- a/xen/arch/arm/vgic/vgic.h +++ b/xen/arch/arm/vgic/vgic.h @@ -20,6 +20,8 @@ #define PRODUCT_ID_KVM 0x4b /* ASCII code K */ #define IMPLEMENTER_ARM 0x43b +#define VGIC_PRI_BITS 5 + #define vgic_irq_is_sgi(intid) ((intid) < VGIC_NR_SGIS) static inline bool irq_is_pending(struct vgic_irq *irq)