From patchwork Thu Dec 22 18:24:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9485461 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C7309600BA for ; Thu, 22 Dec 2016 18:26:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id AA6DD2843F for ; Thu, 22 Dec 2016 18:26:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9F58E2844B; Thu, 22 Dec 2016 18:26:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 385152843F for ; Thu, 22 Dec 2016 18:26:17 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cK82M-0005l5-CK; Thu, 22 Dec 2016 18:24:18 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cK82K-0005gH-Bh for xen-devel@lists.xenproject.org; Thu, 22 Dec 2016 18:24:16 +0000 Received: from [85.158.137.68] by server-9.bemta-3.messagelabs.com id C7/F9-12625-F4A1C585; Thu, 22 Dec 2016 18:24:15 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrCLMWRWlGSWpSXmKPExsVysyfVTddPKib C4OI9Q4vvWyYzOTB6HP5whSWAMYo1My8pvyKBNWPL8Z2MBT9UKq6e7WVrYFwr08XIySEksJlR 4v7HeAh7OaPEli+FIDabgK7EjpuvmUFsEYFQiacLvgPZHBzMAl4SX957g4SFBWwljrZcZAOxW QRUJTbNeghWzitgI/H+2GKwuISAnETD+ftgcU6g+Kuvk5ggVllLHJy4g3kCI/cCRoZVjBrFqU VlqUW6hmZ6SUWZ6RkluYmZObqGBsZ6uanFxYnpqTmJScV6yfm5mxiBvmUAgh2Mq7Z7HmKU5GB SEuXN4Y2JEOJLyk+pzEgszogvKs1JLT7EKMPBoSTBe1oCKCdYlJqeWpGWmQMMMpi0BAePkggv kyRQmre4IDG3ODMdInWKUVFKnPcuSJ8ASCKjNA+uDRbYlxhlpYR5GYEOEeIpSC3KzSxBlX/FK M7BqCTMewFkCk9mXgnc9FdAi5mAFts2R4MsLklESEk1MBqueGzq/JVPeeXznRdLqxX6xf7z/D 2TLfS6V2vFCpaS5xJyByZMPy/yh/9V8qIFfQkrUspnTbHZ2/Qwyzth9Ynl7fWTBe5o9U1mv5T tscXmxdEHu1+srXn85MH2jafeM9/5eEKvKlpRrPDyJu4wjb/WjtNVPjXFiXyR1ONlPHBJLuhq qXaG8UMlluKMREMt5qLiRABbOYPdZwIAAA== X-Env-Sender: andre.przywara@arm.com X-Msg-Ref: server-4.tower-31.messagelabs.com!1482431054!19425502!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.1.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 23780 invoked from network); 22 Dec 2016 18:24:14 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-4.tower-31.messagelabs.com with SMTP; 22 Dec 2016 18:24:14 -0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id DCB9E152D; Thu, 22 Dec 2016 10:24:13 -0800 (PST) Received: from e104803-lin.lan (unknown [10.1.207.46]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 056FD3F220; Thu, 22 Dec 2016 10:24:12 -0800 (PST) From: Andre Przywara To: Julien Grall , Stefano Stabellini Date: Thu, 22 Dec 2016 18:24:39 +0000 Message-Id: <20161222182446.18791-20-andre.przywara@arm.com> X-Mailer: git-send-email 2.9.0 In-Reply-To: <20161222182446.18791-1-andre.przywara@arm.com> References: <20161222182446.18791-1-andre.przywara@arm.com> Cc: xen-devel@lists.xenproject.org, Vijay Kilari Subject: [Xen-devel] [RFC PATCH v2 19/26] ARM: vITS: handle MAPTI command X-BeenThere: xen-devel@lists.xen.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.xen.org Sender: "Xen-devel" X-Virus-Scanned: ClamAV using ClamSMTP The MAPTI commands associates a DeviceID/EventID pair with a LPI/CPU pair and actually instantiates LPI interrupts. We connect the already allocated host LPI to this virtual LPI, so that any triggering IRQ on the host can be quickly forwarded to a guest. Signed-off-by: Andre Przywara --- xen/arch/arm/gic-its.c | 49 +++++++++++++++++++++++++++++++++++++++++++ xen/arch/arm/vgic-its.c | 44 ++++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/gic-its.h | 4 ++++ 3 files changed, 97 insertions(+) diff --git a/xen/arch/arm/gic-its.c b/xen/arch/arm/gic-its.c index 54e604a..0acbd83 100644 --- a/xen/arch/arm/gic-its.c +++ b/xen/arch/arm/gic-its.c @@ -754,6 +754,55 @@ retry: return 0; } +static union host_lpi *find_guest_lpi(struct domain *d, + uint32_t devid, uint32_t eventid) +{ + struct its_devices *dev; + uint32_t lpi; + + list_for_each_entry( dev, &d->arch.vgic.its_devices, entry ) + { + if (dev->guest_devid != devid ) + continue; + + if ( eventid >= dev->eventids ) + return NULL; + + lpi = dev->host_lpis[eventid / 32] + (eventid % 32); + if (lpi < 8192) + return NULL; + + lpi -= 8192; + + return &lpi_data.host_lpis[lpi / HOST_LPIS_PER_PAGE][lpi % HOST_LPIS_PER_PAGE]; + } + + return NULL; +} + +/* Connects the event ID for an already assigned device to the given VCPU/vLPI + * pair. The corresponding physical LPI is already mapped on the host side + * (when assigning the physical device to the guest), so we just connect the + * target VCPU/vLPI pair to that interrupt to inject it properly if it fires. + */ +int gicv3_assign_guest_event(struct domain *d, uint32_t devid, uint32_t eventid, + struct vcpu *v, uint32_t virt_lpi) +{ + union host_lpi hlpi, *hlpip; + + hlpip = find_guest_lpi(d, devid, eventid); + if ( !hlpip ) + return -1; + + hlpi.virt_lpi = virt_lpi; + hlpi.dom_id = d->domain_id; + hlpi.vcpu_id = v->vcpu_id; + + hlpip->data = hlpi.data; + + return 0; +} + /* Scan the DT for any ITS nodes and create a list of host ITSes out of it. */ void gicv3_its_dt_init(const struct dt_device_node *node) { diff --git a/xen/arch/arm/vgic-its.c b/xen/arch/arm/vgic-its.c index 918b504..f9f438a 100644 --- a/xen/arch/arm/vgic-its.c +++ b/xen/arch/arm/vgic-its.c @@ -276,6 +276,46 @@ static int its_handle_mapd(struct virt_its *its, uint64_t *cmdptr) return 0; } +static int its_handle_mapti(struct virt_its *its, uint64_t *cmdptr) +{ + uint32_t devid = its_cmd_get_deviceid(cmdptr); + uint32_t eventid = its_cmd_get_id(cmdptr); + uint32_t intid = its_cmd_get_physical_id(cmdptr); + int collid = its_cmd_get_collection(cmdptr); + struct vits_itte *itte; + struct vcpu *vcpu; + int ret = -1; + + if ( its_cmd_get_command(cmdptr) == GITS_CMD_MAPI ) + intid = eventid; + + if ( collid >= its->max_collections ) + return -1; + + spin_lock(&its->its_lock); + vcpu = get_vcpu_from_collection(its, collid); + if ( !vcpu ) + goto out_unlock; + + itte = get_devid_evid(its, devid, eventid); + if ( !itte ) + goto out_unlock; + + itte->vlpi = intid; + itte->collection = collid; + + gicv3_assign_guest_event(its->d, devid, eventid, vcpu, intid); + + ret = 0; + + put_devid_evid(its, itte); + +out_unlock: + spin_unlock(&its->its_lock); + + return ret; +} + #define ITS_CMD_BUFFER_SIZE(baser) ((((baser) & 0xff) + 1) << 12) static int vgic_its_handle_cmds(struct domain *d, struct virt_its *its, @@ -308,6 +348,10 @@ static int vgic_its_handle_cmds(struct domain *d, struct virt_its *its, case GITS_CMD_MAPD: its_handle_mapd(its, cmdptr); break; + case GITS_CMD_MAPI: + case GITS_CMD_MAPTI: + its_handle_mapti(its, cmdptr); + break; case GITS_CMD_SYNC: /* We handle ITS commands synchronously, so we ignore SYNC. */ break; diff --git a/xen/include/asm-arm/gic-its.h b/xen/include/asm-arm/gic-its.h index d1ebc19..9843674 100644 --- a/xen/include/asm-arm/gic-its.h +++ b/xen/include/asm-arm/gic-its.h @@ -137,6 +137,10 @@ void gicv3_its_setup_collection(int cpu); int gicv3_its_map_device(struct domain *d, int host_devid, int guest_devid, int bits, bool valid); +int gicv3_assign_guest_event(struct domain *d, + uint32_t devid, uint32_t eventid, + struct vcpu *v, uint32_t virt_lpi); + #else static inline void gicv3_its_dt_init(const struct dt_device_node *node)