From patchwork Wed Apr 5 23:19:14 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Przywara X-Patchwork-Id: 9665917 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 EEE8960352 for ; Wed, 5 Apr 2017 23:23:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0CE62816B for ; Wed, 5 Apr 2017 23:23:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D448D28584; Wed, 5 Apr 2017 23:23:26 +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 750B82816B for ; Wed, 5 Apr 2017 23:23:26 +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 1cvuEk-00055u-9V; Wed, 05 Apr 2017 23:21:14 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1cvuEj-00052r-0i for xen-devel@lists.xenproject.org; Wed, 05 Apr 2017 23:21:13 +0000 Received: from [193.109.254.147] by server-5.bemta-6.messagelabs.com id 83/88-27545-8EB75E85; Wed, 05 Apr 2017 23:21:12 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrCLMWRWlGSWpSXmKPExsVysyfVTfd59dM Ig5N7DCy+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxPrZMYC27KV+zra2ZqYDwv3sXIxSEksIlR 4lDTRFYIZy+jxIO1T4EcTg42AV2JHTdfM4PYIgKhEnN+PgKyOTiYBSoluhfxg5jCAhYSE3eyg VSwCKhKzLwxBczmFXCXOL9+OQtIiYSAnMSVfwkgYU6g8MvWYywgtpCAm8S1iVNZJjByL2BkWM WoUZxaVJZapGtorpdUlJmeUZKbmJmja2hgppebWlycmJ6ak5hUrJecn7uJEehbBiDYwXh7Y8A hRkkOJiVRXgWfJxFCfEn5KZUZicUZ8UWlOanFhxhlODiUJHhtqp5GCAkWpaanVqRl5gCDDCYt wcGjJMJrBZLmLS5IzC3OTIdInWJUlBLn1QVJCIAkMkrz4NpggX2JUVZKmJcR6BAhnoLUotzME lT5V4ziHIxKwrw3QabwZOaVwE1/BbSYCWjxkzsPQRaXJCKkpBoYRcUXnTx2er++gPTP2adm7l OcfFPt2/cv7+a48VyomdPEdEJBgWNXcNGBd98//SjZ2NDgublo/prdcbPts1f+sBYxTVevMuI 1j9273F+tRO7Uy4l+he6v5L7+PbR13/lZjW3OKptKpaZ5vEnJ3SM+ZZPIUYtDPCWKtm8znyed Chc2W7skwPOYjhJLcUaioRZzUXEiAD+BkiVnAgAA X-Env-Sender: andre.przywara@arm.com X-Msg-Ref: server-13.tower-27.messagelabs.com!1491434471!86452681!1 X-Originating-IP: [217.140.101.70] X-SpamReason: No, hits=0.5 required=7.0 tests=BODY_RANDOM_LONG X-StarScan-Received: X-StarScan-Version: 9.4.12; banners=-,-,- X-VirusChecked: Checked Received: (qmail 64100 invoked from network); 5 Apr 2017 23:21:11 -0000 Received: from foss.arm.com (HELO foss.arm.com) (217.140.101.70) by server-13.tower-27.messagelabs.com with SMTP; 5 Apr 2017 23:21:11 -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 E1685344; Wed, 5 Apr 2017 16:21:10 -0700 (PDT) Received: from slackpad.lan (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A072A3F4FF; Wed, 5 Apr 2017 16:21:09 -0700 (PDT) From: Andre Przywara To: Stefano Stabellini , Julien Grall Date: Thu, 6 Apr 2017 00:19:14 +0100 Message-Id: <1491434362-30310-23-git-send-email-andre.przywara@arm.com> X-Mailer: git-send-email 2.8.2 In-Reply-To: <1491434362-30310-1-git-send-email-andre.przywara@arm.com> References: <1491434362-30310-1-git-send-email-andre.przywara@arm.com> Cc: xen-devel@lists.xenproject.org, Shanker Donthineni , Vijay Kilari Subject: [Xen-devel] [PATCH v5 22/30] ARM: vITS: handle MAPD 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 MAPD command maps a device by associating a memory region for storing ITEs with a certain device ID. We store the given guest physical address in the device table, and, if this command comes from Dom0, tell the host ITS driver about this new mapping, so it can issue the corresponding host MAPD command and create the required tables. We simply use our existing guest memory access function to find the right ITT entry and store the mapping there. Signed-off-by: Andre Przywara --- xen/arch/arm/vgic-v3-its.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/xen/arch/arm/vgic-v3-its.c b/xen/arch/arm/vgic-v3-its.c index bbca5cf..0372ed0 100644 --- a/xen/arch/arm/vgic-v3-its.c +++ b/xen/arch/arm/vgic-v3-its.c @@ -42,6 +42,7 @@ */ struct virt_its { struct domain *d; + paddr_t doorbell_address; unsigned int devid_bits; unsigned int intid_bits; spinlock_t vcmd_lock; /* Protects the virtual command buffer, which */ @@ -144,6 +145,20 @@ static struct vcpu *get_vcpu_from_collection(struct virt_its *its, #define DEV_TABLE_ENTRY(addr, bits) \ (((addr) & GENMASK_ULL(51, 8)) | (((bits) - 1) & GENMASK_ULL(7, 0))) +/* Set the address of an ITT for a given device ID. */ +static int its_set_itt_address(struct virt_its *its, uint32_t devid, + paddr_t itt_address, uint32_t nr_bits) +{ + paddr_t addr = get_baser_phys_addr(its->baser_dev); + uint64_t itt_entry = DEV_TABLE_ENTRY(itt_address, nr_bits); + + if ( devid >= its->max_devices ) + return -ENOENT; + + return vgic_access_guest_memory(its->d, addr + devid * sizeof(uint64_t), + &itt_entry, sizeof(itt_entry), true); +} + /* * Lookup the address of the Interrupt Translation Table associated with * a device ID and return the address of the ITTE belonging to the event ID @@ -384,6 +399,47 @@ static int its_handle_mapc(struct virt_its *its, uint64_t *cmdptr) return 0; } +static int its_handle_mapd(struct virt_its *its, uint64_t *cmdptr) +{ + /* size and devid get validated by the functions called below. */ + uint32_t devid = its_cmd_get_deviceid(cmdptr); + unsigned int size = its_cmd_get_size(cmdptr) + 1; + bool valid = its_cmd_get_validbit(cmdptr); + paddr_t itt_addr = its_cmd_get_ittaddr(cmdptr); + int ret; + + /* + * There is no easy and clean way for Xen to know the ITS device ID of a + * particular (PCI) device, so we have to rely on the guest telling + * us about it. For *now* we are just using the device ID *Dom0* uses, + * because the driver there has the actual knowledge. + * Eventually this will be replaced with a dedicated hypercall to + * announce pass-through of devices. + */ + if ( is_hardware_domain(its->d) ) + { + /* + * Dom0's ITSes are mapped 1:1, so both addresses are the same. + * Also the device IDs are equal. + */ + ret = gicv3_its_map_guest_device(its->d, its->doorbell_address, devid, + its->doorbell_address, devid, + BIT(size), valid); + if ( ret ) + return ret; + } + + spin_lock(&its->its_lock); + if ( valid ) + ret = its_set_itt_address(its, devid, itt_addr, size); + else + ret = its_set_itt_address(its, devid, INVALID_PADDR, 1); + + spin_unlock(&its->its_lock); + + return ret; +} + #define ITS_CMD_BUFFER_SIZE(baser) ((((baser) & 0xff) + 1) << 12) /* @@ -421,6 +477,9 @@ static int vgic_its_handle_cmds(struct domain *d, struct virt_its *its) case GITS_CMD_MAPC: ret = its_handle_mapc(its, command); break; + case GITS_CMD_MAPD: + ret = its_handle_mapd(its, command); + break; case GITS_CMD_SYNC: /* We handle ITS commands synchronously, so we ignore SYNC. */ break;