From patchwork Mon Mar 5 16:04:03 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 130699 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp2855779lja; Mon, 5 Mar 2018 08:08:48 -0800 (PST) X-Google-Smtp-Source: AG47ELvqH4KMJYI+uN2dJUAsJ422M/fDPkDysBQk57rwQ5gCDYPjavjYCfCjoUG3uoWSdeGgEIWt X-Received: by 10.36.170.1 with SMTP id b1mr14510635itf.52.1520266026322; Mon, 05 Mar 2018 08:07:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520266026; cv=none; d=google.com; s=arc-20160816; b=RPxMpyV/upBFv+UvKlRuJEX+zH1UTeYv8S9+uh54+zc+bZ4QSjTzg7S/bW1BiwcLg8 zX/H0+TVxxEurgADkN0m+rdJ/wDlO0vmgOsAL4qv4wvegkm9USodptcOECH7KxotHjJr rxbXHO/02sTXZpXyJ1FBH17nqsS9KRLNqnqvE5skbdLTypwib1Q2demQ8uFhsIPei/gc tQwI5ffpw75WpN5qA2lvuKAwzkKi/wVvddQwh8n1LeBmaZjZYtP/oiq5TskLfrSY05rO rmjZllD2sSjjMRHqG4AGlT9riTvU3+UX4dZ/scQkyfMDFARcLOH1wk3GWFsEEIjjnd44 F5pQ== 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:cc:references:in-reply-to:message-id:date:to :from:dkim-signature:arc-authentication-results; bh=ljQgQZ/VU5nVSC3fn+t3+01mO4MXizLTv1+ZFdC2+pw=; b=XGUWZWpSzkNJoWKTpqRMzG842Thtvv6P5aGNE8WGkzwKECeS9nUomqpWCKvvVwtrnT MbrrAsebmvuYDi/q9xkG0+vLw4zw86OALlzcV/8HifgAHClJb5bC1egTXunUM23wPwqp MtCnW95I40J7V/NB3I1cGT+Hh3JnIXD9T3LB5hX5YRdQIIvgf6IOmXNgQqNCNz7b7Xh2 LuU+PXzcUFJ7t69Gl+a6fL/alLz4pfPyaB8vkxaIG5BMd7QNzuJzI9npCihQ6r99jrOo H0E4m0+AM5D4FC4gZHTCpFd3gHBh+DvV61P4EvkeaCKlsjDozyDtda4u358MXBiZY6Un 5yFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=ksuFbYJT; 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 q191si6136990itc.104.2018.03.05.08.07.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 05 Mar 2018 08:07:06 -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=ksuFbYJT; 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 1essbw-0000Ml-UR; Mon, 05 Mar 2018 16:05:12 +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 1essbu-0000FC-Sp for xen-devel@lists.xenproject.org; Mon, 05 Mar 2018 16:05:10 +0000 X-Inumbo-ID: d3153a93-208e-11e8-ba59-bc764e045a96 Received: from mail-wr0-x244.google.com (unknown [2a00:1450:400c:c0c::244]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id d3153a93-208e-11e8-ba59-bc764e045a96; Mon, 05 Mar 2018 17:04:04 +0100 (CET) Received: by mail-wr0-x244.google.com with SMTP id o8so6334444wra.1 for ; Mon, 05 Mar 2018 08:05:09 -0800 (PST) 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=GkG/sDZxhswJCygAgxWAVo79Cq2hilsODFIZLMWuicc=; b=ksuFbYJTvzzd4uo83AKyGk/9tcIXBNkN9xfZ0KLZNkiR8u+dww73BXOLH5gvPSAGKS SMhCd2Mr+J5kCy3thgL7BDls+vmeebF6qjdLbzE4H3MhAajTBCbs5CXtMw3jtBc0IN1f 5k7hOjyra7MYgOH+4Xsjinm3bzipuOQtXY64A= 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=GkG/sDZxhswJCygAgxWAVo79Cq2hilsODFIZLMWuicc=; b=bBQaAhqtYmZ2WfYGo48RtuGhCq61jsiYSnSvpdmGxN4LeRsfLAG5GAAWT1GLJTRTNT P5i6FeK9MDfKcA0x1J7pktVTaaA1H0thfizz1a0b4hgmWdgynHAVTgvID0qy4hgXpmOd dITSB1w7U07P3nBqMcgx9lZ47pTjs1w9xVCbNAHQaDMH+USBDmTZRn3yWYFTTg+a2IMQ U+0TAhxAE8WwVHzq6+lSfleUApXy17P0Zd959Y2MlW3EOkU2l/RWRVv98gVeuWGO8U/u 8dK9n5192IQEPGAS45yiwBQU4K/nsBQNHVmFD6Rt2QweI4mBChKZjNIR5F4l97/S3gpU XGfw== X-Gm-Message-State: APf1xPAXLYC//gT5PhvEoZXWTwlcq9bKo1xHvejro1EPNw4LYWw1B1Gj hz9guDviXVUY2sejCfYb/Fcohg== X-Received: by 10.223.176.228 with SMTP id j33mr12378245wra.67.1520265908634; Mon, 05 Mar 2018 08:05:08 -0800 (PST) Received: from e104803-lin.lan (mail.andrep.de. [217.160.17.100]) by smtp.gmail.com with ESMTPSA id y6sm6574381wmy.14.2018.03.05.08.05.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 05 Mar 2018 08:05:08 -0800 (PST) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Mon, 5 Mar 2018 16:04:03 +0000 Message-Id: <20180305160415.16760-46-andre.przywara@linaro.org> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180305160415.16760-1-andre.przywara@linaro.org> References: <20180305160415.16760-1-andre.przywara@linaro.org> Cc: xen-devel@lists.xenproject.org Subject: [Xen-devel] [PATCH 45/57] ARM: new VGIC: Handle hardware mapped IRQs 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 VGIC supports virtual IRQs to be connected to a hardware IRQ, so when a guest EOIs the virtual interrupt, it affects the state of that corresponding interrupt on the hardware side at the same time. Implement the interface that the Xen arch/core code expects to connect the virtual and the physical world. Signed-off-by: Andre Przywara Reviewed-by: Julien Grall --- Changelog RFC ... v1: - add ASSERT for hardware mapped IRQs being SPI only - check h/w IRQ matches before disconnecting xen/arch/arm/vgic/vgic.c | 71 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/xen/arch/arm/vgic/vgic.c b/xen/arch/arm/vgic/vgic.c index 5246d7c2e7..5bbf55da21 100644 --- a/xen/arch/arm/vgic/vgic.c +++ b/xen/arch/arm/vgic/vgic.c @@ -698,6 +698,77 @@ void vgic_kick_vcpus(struct domain *d) } } +struct irq_desc *vgic_get_hw_irq_desc(struct domain *d, struct vcpu *v, + unsigned int virq) +{ + struct irq_desc *desc = NULL; + struct vgic_irq *irq = vgic_get_irq(d, v, virq); + unsigned long flags; + + if ( !irq ) + return NULL; + + spin_lock_irqsave(&irq->irq_lock, flags); + if ( irq->hw ) + { + ASSERT(irq->hwintid >= VGIC_NR_PRIVATE_IRQS); + desc = irq_to_desc(irq->hwintid); + } + spin_unlock_irqrestore(&irq->irq_lock, flags); + + vgic_put_irq(d, irq); + + return desc; +} + +/* + * was: + * int kvm_vgic_map_phys_irq(struct vcpu *vcpu, u32 virt_irq, u32 phys_irq) + * int kvm_vgic_unmap_phys_irq(struct vcpu *vcpu, unsigned int virt_irq) + */ +int vgic_connect_hw_irq(struct domain *d, struct vcpu *vcpu, + unsigned int virt_irq, struct irq_desc *desc, + bool connect) +{ + struct vgic_irq *irq = vgic_get_irq(d, vcpu, virt_irq); + unsigned long flags; + int ret = 0; + + if ( !irq ) + return -EINVAL; + + spin_lock_irqsave(&irq->irq_lock, flags); + + if ( connect ) /* assign a mapped IRQ */ + { + /* The VIRQ should not be already enabled by the guest */ + if ( !irq->hw && !irq->enabled ) + { + irq->hw = true; + irq->hwintid = desc->irq; + } + else + ret = -EBUSY; + } + else /* remove a mapped IRQ */ + { + if ( desc && irq->hwintid != desc->irq ) + { + ret = -EINVAL; + } + else + { + irq->hw = false; + irq->hwintid = 0; + } + } + + spin_unlock_irqrestore(&irq->irq_lock, flags); + vgic_put_irq(d, irq); + + return ret; +} + static unsigned int translate_irq_type(bool is_level) { return is_level ? IRQ_TYPE_LEVEL_HIGH : IRQ_TYPE_EDGE_RISING;