From patchwork Fri Sep 29 21:02:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Goel, Sameer" X-Patchwork-Id: 9978689 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 C05CB60311 for ; Fri, 29 Sep 2017 21:05:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B0B1F285F1 for ; Fri, 29 Sep 2017 21:05:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A2108298C1; Fri, 29 Sep 2017 21:05:35 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID 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 DE984298BF for ; Fri, 29 Sep 2017 21:05:34 +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 1dy2RC-000806-EL; Fri, 29 Sep 2017 21:03:10 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dy2RB-000800-3Z for xen-devel@lists.xenproject.org; Fri, 29 Sep 2017 21:03:09 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id 05/D8-03616-C05BEC95; Fri, 29 Sep 2017 21:03:08 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrFIsWRWlGSWpSXmKPExsVybKJsgi7X1nO RBg8nall83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBn/r/xjLOhWqpg87wxTA+Nf6S5GTg4hgSKJ Yy8Xs4LYLAIvmSRe/1QCsSUEoiXWbTjGDmHzSVx88YOpi5ELyJ7AKPHrazMjiCMksI9J4mbDO gzdLAIuEhcO3ACLMwoUSMzZ8JERwk6RmNX1BsxmE9CQ6D9xmBnEFhFQkri3ajLQBg4OZgFbiY sLwI4TFtCWOHjpNDPESFWJP7e2gLXyCjhLnH+zjw3iODmJk8cms05gFFzAyLCKUaM4tagstUj X0EAvqSgzPaMkNzEzB8gz08tNLS5OTE/NSUwq1kvOz93ECAw3BiDYwXj8fdwhRkkOJiVR3oa1 5yKF+JLyUyozEosz4otKc1KLDzHKcHAoSfCKbwHKCRalpqdWpGXmAAMfJi3BwaMkwisFkuYtL kjMLc5Mh0idYtTl6Lh59w+TEEtefl6qlDgvO0iRAEhRRmke3AhYFF5ilJUS5mUEOkqIpyC1KD ezBFX+FaM4B6OSMK8iyBSezLwSuE2vgI5gAjpi8sQzIEeUJCKkpBoYtSVOz75zfV0E+9PP/l/ 3ZwnVWxUeDxQRsI0t2K6guTvOcul9qd9ZN8/oJvKovsqPLLnfv8+57VWVna5k64UfdZtrF+8y yDmRNZnp+cIFLQbh/J7SL6Yc5XDNYOfjjNh+dUnut1q902daU6b+zKvYkKQ8xWia2/HuV2wpp t7i8qxv9Dl+LwtWYinOSDTUYi4qTgQAhVJqub0CAAA= X-Env-Sender: sgoel@codeaurora.org X-Msg-Ref: server-11.tower-27.messagelabs.com!1506718985!87435929!1 X-Originating-IP: [198.145.29.96] X-SpamReason: No, hits=0.0 required=7.0 tests= X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 51697 invoked from network); 29 Sep 2017 21:03:06 -0000 Received: from smtp.codeaurora.org (HELO smtp.codeaurora.org) (198.145.29.96) by server-11.tower-27.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 29 Sep 2017 21:03:06 -0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id B5E0B6039B; Fri, 29 Sep 2017 21:03:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1506718984; bh=fVt9wYX/yYr+Mq8E22cvzhd28SZdKWjNKkpw7+sHai8=; h=From:To:Cc:Subject:Date:From; b=FVNQMv0iu37Y1AIhbAC0JdzWW1HqduwTI3Ec4een6oNQS9FWRxBsOwiFsLB5Neibf JE7ImDQrgHm0FqXq27hI3ntuMUyI+8uXtsGbq95UMYKvhnvV5nxL3ZIGR27acvssBk 6uP2yh0xIaj4C4iaTgn4aTyUT2jCnq0urMqIpIsY= Received: from sgoel1-lnx.qualcomm.com (unknown [129.46.14.86]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: sgoel@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id ECBA260350; Fri, 29 Sep 2017 21:03:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1506718984; bh=fVt9wYX/yYr+Mq8E22cvzhd28SZdKWjNKkpw7+sHai8=; h=From:To:Cc:Subject:Date:From; b=FVNQMv0iu37Y1AIhbAC0JdzWW1HqduwTI3Ec4een6oNQS9FWRxBsOwiFsLB5Neibf JE7ImDQrgHm0FqXq27hI3ntuMUyI+8uXtsGbq95UMYKvhnvV5nxL3ZIGR27acvssBk 6uP2yh0xIaj4C4iaTgn4aTyUT2jCnq0urMqIpIsY= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org ECBA260350 From: Sameer Goel To: xen-devel@lists.xenproject.org Date: Fri, 29 Sep 2017 15:02:51 -0600 Message-Id: <1506718971-5250-1-git-send-email-sgoel@codeaurora.org> X-Mailer: git-send-email 1.9.1 Cc: Sameer Goel , julien.grall@arm.com Subject: [Xen-devel] [PATCH] Test code for SMMUv3 setup 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 DO NOT MERGE This patch contains test code for programming stream tables for PCIe devices seen by DOM0. This change can be used on top of [1]. [1] [RFC v2 0/7] SMMUv3 driver and the supporting framework --- xen/arch/arm/physdev.c | 41 +++++++++++++++++++++++++++++++++-- xen/drivers/passthrough/arm/smmu-v3.c | 36 ++++++++++++++++++++++++++++++ xen/include/asm-arm/device.h | 5 +++-- 3 files changed, 78 insertions(+), 4 deletions(-) diff --git a/xen/arch/arm/physdev.c b/xen/arch/arm/physdev.c index e91355f..18a5786 100644 --- a/xen/arch/arm/physdev.c +++ b/xen/arch/arm/physdev.c @@ -8,13 +8,50 @@ #include #include #include +#include #include +extern void acpi_setup_smmu_for_test(struct domain *d, u16 seg, u8 bus, u8 devfn); + int do_physdev_op(int cmd, XEN_GUEST_HANDLE_PARAM(void) arg) { - gdprintk(XENLOG_DEBUG, "PHYSDEVOP cmd=%d: not implemented\n", cmd); - return -ENOSYS; + int ret = 0; + + switch (cmd ) + { + case PHYSDEVOP_pci_device_add: { + struct physdev_pci_device_add add; + struct pci_dev_info pdev_info; + + ret = -EFAULT; + if ( copy_from_guest(&add, arg, 1) != 0 ) + break; + + pdev_info.is_extfn = !!(add.flags & XEN_PCI_DEV_EXTFN); + if ( add.flags & XEN_PCI_DEV_VIRTFN ) + { + pdev_info.is_virtfn = 1; + pdev_info.physfn.bus = add.physfn.bus; + pdev_info.physfn.devfn = add.physfn.devfn; + } + else + pdev_info.is_virtfn = 0; + + gdprintk(XENLOG_DEBUG, "PHYSDEVOP cmd=%d: domain:%d seg:%d bus:%d \ + devfn:%d\n", cmd, hardware_domain->domain_id, add.seg, \ + add.bus, add.devfn); + acpi_setup_smmu_for_test(hardware_domain, add.seg, add.bus, add.devfn); + break; + } + + default: + gdprintk(XENLOG_DEBUG, "PHYSDEVOP cmd=%d: not implemented\n", cmd); + ret = -ENOSYS; + break; + } + + return ret; } /* diff --git a/xen/drivers/passthrough/arm/smmu-v3.c b/xen/drivers/passthrough/arm/smmu-v3.c index 0bbf0cd..f5b5d77 100644 --- a/xen/drivers/passthrough/arm/smmu-v3.c +++ b/xen/drivers/passthrough/arm/smmu-v3.c @@ -46,6 +46,7 @@ #include #include #include +#include typedef paddr_t phys_addr_t; typedef paddr_t dma_addr_t; @@ -3410,3 +3411,38 @@ ACPI_DEVICE_START(asmmuv3, "ARM SMMU V3", DEVICE_IOMMU) ACPI_DEVICE_END #endif + +void acpi_setup_smmu_for_test(struct domain *d, u16 seg, u8 bus, u8 devfn) +{ + struct pci_dev pci_device; + struct device *device; + struct arm_smmu_device *smmu; + + arm_smmu_iommu_domain_init(d); + memset(&pci_device, 0, sizeof(struct pci_dev)); + device = &(pci_device.dev); + + pci_device.domain = d; + *(u16*) &pci_device.seg = seg; + *(u8*) &pci_device.bus = bus; + *(u8*) &pci_device.devfn = devfn; + + pci_device.dev.type = DEV_PCI; + printk("%d %d %d \n",pci_device.seg,pci_device.bus,pci_device.devfn); + + iort_iommu_configure(device); + + if (device->iommu_fwspec) { + printk("num-ids: %d\n", device->iommu_fwspec->num_ids); + printk("fwnode: 0x%p\n", device->iommu_fwspec->iommu_fwnode); + smmu = arm_smmu_get_by_fwnode( device->iommu_fwspec->iommu_fwnode); + printk("smmu-device-node: 0x%p\n",smmu); + arm_smmu_assign_dev(d, 0, device, 0); + } else { + printk("Failed to initialize fw_spec\n"); + } + + + printk("%s called %d\n", __func__, __LINE__); +} + diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h index 4eef9ce..57c114b 100644 --- a/xen/include/asm-arm/device.h +++ b/xen/include/asm-arm/device.h @@ -8,6 +8,7 @@ enum device_type { DEV_DT, DEV_ACPI, + DEV_PCI, }; struct dev_archdata { @@ -32,8 +33,8 @@ typedef struct device device_t; #include /* TODO: Correctly implement dev_is_pci when PCI is supported on ARM */ -#define dev_is_pci(dev) ((void)(dev), 0) -#define dev_is_dt(dev) ((dev->type == DEV_DT) +#define dev_is_pci(dev) (dev->type == DEV_PCI) +#define dev_is_dt(dev) (dev->type == DEV_DT) enum device_class {