From patchwork Wed Mar 21 16:32:20 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 132207 Delivered-To: patch@linaro.org Received: by 10.46.84.29 with SMTP id i29csp2355892ljb; Wed, 21 Mar 2018 09:34:49 -0700 (PDT) X-Google-Smtp-Source: AG47ELuIBeBhffM+xMN/4LiO2yZ/dO4XBV7grdnzwJP41RTnSV3thYOkqQ2DTu3xZc64H5QmCLsu X-Received: by 2002:a24:cac7:: with SMTP id k190-v6mr3413960itg.0.1521650089510; Wed, 21 Mar 2018 09:34:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521650089; cv=none; d=google.com; s=arc-20160816; b=G8Ke8pug5HpLhh+I2idl7oDa6GjlgN9gb+c57+RWc4RhB7TC8ki/Hky1F3pjQwJzJ3 WiIABjISizBSnh4/Z8thl+9f4ZSjVPb4UxxaX0ONr15xsJtL7vU0vkADjV8i3kJb874e PR7CcW2bBpn5To4JnVF6bzD5B+t/O+TPt/f4vOs3StMkx+LQo6JOMORIyuxpNSd9Y26k OxzZEeMVJt5latdw84uySia2HRpVu62+fCYmaZf4ZgeHxM8Ge8XfOm8sDqxdBqOMelOF bBpXnremhz+H+DE4YGvXlwlxUcZROQANNqAmdxKOfKfFzq9oqT9nyPbm6/5vKIwg6Exf nDIg== 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:cc :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=IMlig+SnerEi7W+yurnMZNCo1F74onNZ7EvzMXdF/ts=; b=FyQ8Wa7VvhNm326ZtFKzR6Jq5ZfXNVsx6v9++V+JVOrNU/M1201LX3yjWJj16b/Px+ piTm/kjHoTtPFE3HqcVvDeynFMNfTS15/E4wsHU3LlYxCqysXpHhBlXWcgpAZFv0Dz91 CU6LDFovVsFqp05q5fv4mXrXren2Yr7yGX0Tkaca4Q62CYJx+OhKh0wWajBZ0HN92Rqg yBznMqT6rJsBbqa85444WMUjVFbebzpWmOs2S4bYsN1XyY+7gkVM5IVycdXDwRMdBA8a YEpQhNLnTaYShTbAlRjbvbLUJmnloL5jrc+GeGKjVgYmf/YPGHvp6yEjpOlqWu9Jd9DS I02g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=cs4dxG5p; 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 n76-v6si3476214itn.68.2018.03.21.09.34.49 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 21 Mar 2018 09:34:49 -0700 (PDT) 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=cs4dxG5p; 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.89) (envelope-from ) id 1eygft-0002dF-ID; Wed, 21 Mar 2018 16:33:17 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1eygfs-0002Zh-3M for xen-devel@lists.xenproject.org; Wed, 21 Mar 2018 16:33:16 +0000 X-Inumbo-ID: 84b603d2-2d25-11e8-9728-bc764e045a96 Received: from mail-wr0-x241.google.com (unknown [2a00:1450:400c:c0c::241]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id 84b603d2-2d25-11e8-9728-bc764e045a96; Wed, 21 Mar 2018 17:33:00 +0100 (CET) Received: by mail-wr0-x241.google.com with SMTP id z8so5831716wrh.7 for ; Wed, 21 Mar 2018 09:33:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=OyPcE5GC5Hg7OEzY+KzVcR5/c1fJcK6Hys2lUm5hClg=; b=cs4dxG5p19yf4l+Ff/eRUs2e8+trljUri+YhEjNpFZ9qjcmKhB/FuqPEX5O6+E02yD 2ywfs0poHYNuDLlvzvS+T1Ii77pQ/5QSl2FwsBZBRWM26afgq5SOBG13l7Q3OYF3o57H fiRpYpTw2mKjp2qDlNkq6IB/oSvtesi+lFZ/M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=OyPcE5GC5Hg7OEzY+KzVcR5/c1fJcK6Hys2lUm5hClg=; b=cJfxZMgZMAYH35/htGyj/EsRZ3z+rreEpvXd6tnmmrxBsuHmKXNDZkBIcvChryHFVV /AyGw2ZIn+mw3o3Qo42Jt653b5HZa98TvyrBb/uk+kBr7wWx7xtlnHRkehgJVh/ylOLs rEkfZusi7fDvjusAX7cpB5IrkZVsoFjzePtUbQzIcU5gZcZUtnCYcGW38SGu/9+2zelS 47Nkuyy12HeiAq8bsEmZ5TIr+JyFukxpzsQ1yBmQ9XtZ4rdfl6ilexj1y/859aMQ5Tka 6Ja4xU8Hd7YSh/rnNQ8OwrNe1IITwvdjFRjff5sp/vhmdewm8F64G/Prz2obWERGE4MJ VNFw== X-Gm-Message-State: AElRT7GtTUr6uxXOVy+VYIwF1PX/x3RIrZd4vaWo2Ryd3WFRf75g4Vz6 5Iaj96KgmNuyX2CwznnwlZ7ZTQ== X-Received: by 10.223.192.3 with SMTP id z3mr9198256wre.177.1521649994108; Wed, 21 Mar 2018 09:33:14 -0700 (PDT) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id n64sm4423724wmd.11.2018.03.21.09.33.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Mar 2018 09:33:13 -0700 (PDT) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Wed, 21 Mar 2018 16:32:20 +0000 Message-Id: <20180321163235.12529-25-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180321163235.12529-1-andre.przywara@linaro.org> References: <20180321163235.12529-1-andre.przywara@linaro.org> Subject: [Xen-devel] [PATCH v3 24/39] ARM: new VGIC: Add TARGET registers handlers X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: xen-devel@lists.xenproject.org, Andre Przywara MIME-Version: 1.0 Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" The target register handlers are v2 emulation specific, so their implementation lives entirely in vgic-mmio-v2.c. We copy the old VGIC behaviour of assigning an IRQ to the first VCPU set in the target mask instead of making it possibly pending on multiple VCPUs. We update the physical affinity of a hardware mapped vIRQ on the way. This is based on Linux commit 2c234d6f1826, written by Andre Przywara. Signed-off-by: Andre Przywara Reviewed-by: Julien Grall Acked-by: Stefano Stabellini --- xen/arch/arm/vgic/vgic-mmio-v2.c | 59 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 58 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/vgic/vgic-mmio-v2.c b/xen/arch/arm/vgic/vgic-mmio-v2.c index a28d0e459b..b333de9ed7 100644 --- a/xen/arch/arm/vgic/vgic-mmio-v2.c +++ b/xen/arch/arm/vgic/vgic-mmio-v2.c @@ -81,6 +81,63 @@ static void vgic_mmio_write_v2_misc(struct vcpu *vcpu, } } +static unsigned long vgic_mmio_read_target(struct vcpu *vcpu, + paddr_t addr, unsigned int len) +{ + uint32_t intid = VGIC_ADDR_TO_INTID(addr, 8); + uint32_t val = 0; + unsigned int i; + + for ( i = 0; i < len; i++ ) + { + struct vgic_irq *irq = vgic_get_irq(vcpu->domain, vcpu, intid + i); + + val |= (uint32_t)irq->targets << (i * 8); + + vgic_put_irq(vcpu->domain, irq); + } + + return val; +} + +static void vgic_mmio_write_target(struct vcpu *vcpu, + paddr_t addr, unsigned int len, + unsigned long val) +{ + uint32_t intid = VGIC_ADDR_TO_INTID(addr, 8); + uint8_t cpu_mask = GENMASK(vcpu->domain->max_vcpus - 1, 0); + unsigned int i; + unsigned long flags; + + /* GICD_ITARGETSR[0-7] are read-only */ + if ( intid < VGIC_NR_PRIVATE_IRQS ) + return; + + for ( i = 0; i < len; i++ ) + { + struct vgic_irq *irq = vgic_get_irq(vcpu->domain, NULL, intid + i); + + spin_lock_irqsave(&irq->irq_lock, flags); + + irq->targets = (val >> (i * 8)) & cpu_mask; + if ( irq->targets ) + { + irq->target_vcpu = vcpu->domain->vcpu[ffs(irq->targets) - 1]; + if ( irq->hw ) + { + struct irq_desc *desc = irq_to_desc(irq->hwintid); + + irq_set_affinity(desc, cpumask_of(irq->target_vcpu->processor)); + } + } + else + irq->target_vcpu = NULL; + + spin_unlock_irqrestore(&irq->irq_lock, flags); + vgic_put_irq(vcpu->domain, irq); + } +} + static const struct vgic_register_region vgic_v2_dist_registers[] = { REGISTER_DESC_WITH_LENGTH(GICD_CTLR, vgic_mmio_read_v2_misc, vgic_mmio_write_v2_misc, 12, @@ -110,7 +167,7 @@ static const struct vgic_register_region vgic_v2_dist_registers[] = { vgic_mmio_read_priority, vgic_mmio_write_priority, 8, VGIC_ACCESS_32bit | VGIC_ACCESS_8bit), REGISTER_DESC_WITH_BITS_PER_IRQ(GICD_ITARGETSR, - vgic_mmio_read_raz, vgic_mmio_write_wi, 8, + vgic_mmio_read_target, vgic_mmio_write_target, 8, VGIC_ACCESS_32bit | VGIC_ACCESS_8bit), REGISTER_DESC_WITH_BITS_PER_IRQ(GICD_ICFGR, vgic_mmio_read_config, vgic_mmio_write_config, 2,