From patchwork Thu Jun 8 19:30:45 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Goel, Sameer" X-Patchwork-Id: 9776325 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 4D53C603F1 for ; Thu, 8 Jun 2017 19:33:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3C09228577 for ; Thu, 8 Jun 2017 19:33:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3101228579; Thu, 8 Jun 2017 19:33:46 +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 4C65328596 for ; Thu, 8 Jun 2017 19:33:45 +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 1dJ39I-00014y-3n; Thu, 08 Jun 2017 19:31:16 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dJ39H-00014m-Du for xen-devel@lists.xenproject.org; Thu, 08 Jun 2017 19:31:15 +0000 Received: from [85.158.143.35] by server-9.bemta-6.messagelabs.com id 8E/5D-03557-206A9395; Thu, 08 Jun 2017 19:31:14 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrOIsWRWlGSWpSXmKPExsVybKJsgi7jMst IgyUHTC2+b5nM5MDocfjDFZYAxijWzLyk/IoE1oxnh1ezFXxRqJi8p529gfGPVBcjJ4eQQJFE ++V2dhCbRaCBWaJhIhuILSEQLbFuwzF2CJtP4uKLH0xdjFxA9gRGiV9fmxlBHCGBg0wSv//NB cuAdTf+XsoCMcpFYtqVqWA2o0CBxJwNHxkh7BSJWV1vwGw2AQ2J/hOHmUFsEQEPiavNy9hABj ELfGGU+Lu2A8jh4BAWsJPYs9oDYqaqRM+5f2C9vALOEuteL2OBOE9B4vj2bWBxTqC9M0/0sEK 85ixxbP1D1gmMwgsYGVYxqhenFpWlFuka6SUVZaZnlOQmZuboGhqY6eWmFhcnpqfmJCYV6yXn 525iBAYoAxDsYFz21+kQoyQHk5Ior2KrZaQQX1J+SmVGYnFGfFFpTmrxIUYZDg4lCd6DS4Byg kWp6akVaZk5wFiBSUtw8CiJ8IqApHmLCxJzizPTIVKnGBWlxHl3gSQEQBIZpXlwbbD4vMQoKy XMywh0iBBPQWpRbmYJqvwrRnEORiVh3n6QKTyZeSVw018BLWYCWrzknQXI4pJEhJRUA2NBkam bk03YNJ0+NdddqRsfXPGYfrf8lf36sj8df2wfXJy+/6bzuid5yj+S8n+a1YnN73wTFWAjczZS 7uMK55S+DtHdoo8rpji+aFdUFlBkWBQpeFPr57FcpfNb8hZf/9+vW8lTla0gn935eWqOjELUG q+4picWUbVnExrDWh7LuX0MYK/iV2Ipzkg01GIuKk4EAEyStuzKAgAA X-Env-Sender: sgoel@codeaurora.org X-Msg-Ref: server-12.tower-21.messagelabs.com!1496950272!72966618!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.19; banners=-,-,- X-VirusChecked: Checked Received: (qmail 30554 invoked from network); 8 Jun 2017 19:31:13 -0000 Received: from smtp.codeaurora.org (HELO smtp.codeaurora.org) (198.145.29.96) by server-12.tower-21.messagelabs.com with DHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 8 Jun 2017 19:31:13 -0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 0D91461201; Thu, 8 Jun 2017 19:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1496950272; bh=CMFcCco+6fIibKEtTmwqOrTeiRYLduRGjPSLMUELStQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=M6+QPHTQ4TkjnPrIr+dWZlHmi3xjAQYV5bajPp8aaZ65CDmEQdn28jFsxOzGeZK7g NnoB5tP5k369R1+JX4ckGrxPDGL2p0AZD+pOUcpRlUZCauARpsJ3n2CQ6sEkxDpRx1 jWvVuWK+4RdENyNdlGwgrd14e5MYBKNEbutVHn9s= Received: from sgoel-lnx.qualcomm.com (unknown [129.46.14.70]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: sgoel@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id A1D67611B4; Thu, 8 Jun 2017 19:31:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1496950271; bh=CMFcCco+6fIibKEtTmwqOrTeiRYLduRGjPSLMUELStQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=I+yT7RlqmIUqD8lqiIBd+RYWsYle/Z0gsh7jlYLM57QCoxsI/phzopamGJSTLLPqX FhTdhwpkJCsGyZqwujB+9z09ndVNMmDV8OraeIuK7Y8zO1q/gQk7MI3dVdPeao7l+U fwMaNWCxnF9+AX+2031upejy5FcAUUGJtrqoXpl4= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org A1D67611B4 From: Sameer Goel To: xen-devel@lists.xenproject.org, Julien Grall Date: Thu, 8 Jun 2017 13:30:45 -0600 Message-Id: <1496950247-8755-5-git-send-email-sgoel@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 In-Reply-To: <1496950247-8755-1-git-send-email-sgoel@codeaurora.org> References: <1496950247-8755-1-git-send-email-sgoel@codeaurora.org> Cc: Stefano Stabellini , Tomasz Nowicki , Punit Agrawal , Sameer Goel , Robin Murphy , Shanker Donthineni Subject: [Xen-devel] [RFC 4/6] xen/passthrough/arm: Introduce iommu_fwspec 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 Introduce a common structure to hold the fw (ACPI or DT) defined configuration for SMMU hw. The current use case is for arm SMMUs. So, making this architecture specific. Based on Linux kernel commit 57f98d2f61e1: iommu: Introduce iommu_fwspec Signed-off-by: Sameer Goel --- xen/drivers/passthrough/arm/iommu.c | 57 +++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/device.h | 1 + xen/include/xen/iommu.h | 28 ++++++++++++++++++ 3 files changed, 86 insertions(+) diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/arm/iommu.c index 95b1abb..edf70c2 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -73,3 +73,60 @@ int arch_iommu_populate_page_table(struct domain *d) /* The IOMMU shares the p2m with the CPU */ return -ENOSYS; } + +int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, + const struct iommu_ops *ops) +{ + struct iommu_fwspec *fwspec = dev->iommu_fwspec; + + if (fwspec) + return ops == fwspec->ops ? 0 : -EINVAL; + + fwspec = xzalloc(struct iommu_fwspec); + if (!fwspec) + return -ENOMEM; + + /* Ref counting for the dt device node is not needed */ + + /*of_node_get(to_of_node(iommu_fwnode));*/ + + fwspec->iommu_fwnode = iommu_fwnode; + fwspec->ops = ops; + dev->iommu_fwspec = fwspec; + return 0; +} + +void iommu_fwspec_free(struct device *dev) +{ + struct iommu_fwspec *fwspec = dev->iommu_fwspec; + + if (fwspec) { + /*fwnode_handle_put(fwspec->iommu_fwnode);*/ + xfree(fwspec); + dev->iommu_fwspec = NULL; + } +} + +int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids) +{ + struct iommu_fwspec *fwspec = dev->iommu_fwspec; + size_t size; + int i; + + if (!fwspec) + return -EINVAL; + + size = offsetof(struct iommu_fwspec, ids[fwspec->num_ids + num_ids]); + if (size > sizeof(*fwspec)) { + fwspec = _xrealloc(dev->iommu_fwspec, size, sizeof(void *)); + if (!fwspec) + return -ENOMEM; + } + + for (i = 0; i < num_ids; i++) + fwspec->ids[fwspec->num_ids + i] = ids[i]; + + fwspec->num_ids += num_ids; + dev->iommu_fwspec = fwspec; + return 0; +} diff --git a/xen/include/asm-arm/device.h b/xen/include/asm-arm/device.h index 78c38fe..5027c87 100644 --- a/xen/include/asm-arm/device.h +++ b/xen/include/asm-arm/device.h @@ -21,6 +21,7 @@ struct device struct dt_device_node *of_node; /* Used by drivers imported from Linux */ #endif struct fwnode_handle *fwnode; /*fw device node identifier */ + struct iommu_fwspec *iommu_fwspec; struct dev_archdata archdata; }; diff --git a/xen/include/xen/iommu.h b/xen/include/xen/iommu.h index 5803e3f..7ef9b93 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -224,4 +224,32 @@ DECLARE_PER_CPU(bool_t, iommu_dont_flush_iotlb); extern struct spinlock iommu_pt_cleanup_lock; extern struct page_list_head iommu_pt_cleanup_list; +/** + * Following block was ported from Linux to help with the implementation of + * arm64 iommu devices. Hence the architecture specific compile + */ + +#if defined(CONFIG_ARM_64) || defined(CONFIG_ARM) +/** + * struct iommu_fwspec - per-device IOMMU instance data + * @ops: ops for this device's IOMMU + * @iommu_fwnode: firmware handle for this device's IOMMU + * @iommu_priv: IOMMU driver private data for this device + * @num_ids: number of associated device IDs + * @ids: IDs which this device may present to the IOMMU + */ +struct iommu_fwspec { + const struct iommu_ops *ops; + struct fwnode_handle *iommu_fwnode; + void *iommu_priv; + unsigned int num_ids; + u32 ids[1]; +}; + +int iommu_fwspec_init(struct device *dev, struct fwnode_handle *iommu_fwnode, + const struct iommu_ops *ops); +void iommu_fwspec_free(struct device *dev); +int iommu_fwspec_add_ids(struct device *dev, u32 *ids, int num_ids); + +#endif #endif /* _IOMMU_H_ */