From patchwork Thu Sep 21 00:37:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Goel, Sameer" X-Patchwork-Id: 9963107 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 983B76056A for ; Thu, 21 Sep 2017 00:39:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8A1062927E for ; Thu, 21 Sep 2017 00:39:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7EA7029282; Thu, 21 Sep 2017 00:39:43 +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 2A4962927E for ; Thu, 21 Sep 2017 00:39:42 +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 1dupUk-0000JA-Pw; Thu, 21 Sep 2017 00:37:34 +0000 Received: from mail6.bemta6.messagelabs.com ([193.109.254.103]) by lists.xenproject.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dupUk-0000Ik-5o for xen-devel@lists.xenproject.org; Thu, 21 Sep 2017 00:37:34 +0000 Received: from [193.109.254.147] by server-11.bemta-6.messagelabs.com id B5/9B-03616-DC903C95; Thu, 21 Sep 2017 00:37:33 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrKIsWRWlGSWpSXmKPExsVybKJsgu4ZzsO RBtufalh83zKZyYHR4/CHKywBjFGsmXlJ+RUJrBk3525gLehUrlh/8A9rA+MSmS5GTg4hgSKJ h63nWbsYuThYBBqYJY5dnMcCkpAQiJZYt+EYO4TNJ3HxxQ8mkCIJgQmMEr++NjOCOEIC+5gk3 m74g9D+dUoLM0gLi4CLxKr+yawgNqNAgcScDR8ZIewUiVldb8BsNgENif4Th8HqRQRCJW7OPc 8GMohZ4BejxMmus2BFwgKOEisfdwLdxAE0VFViy1JukDAv0PztGx+wQZwnJ3HyGMQuTgFXiZZ 5R1ggfnOReDH7OuMERuEFjAyrGDWKU4vKUot0jYz1kooy0zNKchMzc3QNDcz0clOLixPTU3MS k4r1kvNzNzECg5QBCHYw/pkfeIhRkoNJSZQ3XPlQpBBfUn5KZUZicUZ8UWlOavEhRhkODiUJ3 h4VoJxgUWp6akVaZg4wXmDSEhw8SiK8m0FaeYsLEnOLM9MhUqcYdTk6bt79wyTEkpeflyolzq sKMkMApCijNA9uBCx2LzHKSgnzMgIdJcRTkFqUm1mCKv+KUZyDUUmY1whkCk9mXgncpldARzA BHZG94QDIESWJCCmpBkYdh4X+TZ4J25sfC9p8/fy7OuNVxqf0w4/WPlzcqiV/L6Z70fH+BeWv NMx/fTVKDN5yvexsyMWwz+29zQL83GnPHEs4hY7Jd0sav3y06vb9pfuX+xrySm6xSrFoWXLpq XXOxCXJM1/cKRW4zPmws15OTX6XSo/t+zzdqGnLFI33mFTf4np4xUiJpTgj0VCLuag4EQA9E9 UF2AIAAA== X-Env-Sender: sgoel@codeaurora.org X-Msg-Ref: server-11.tower-27.messagelabs.com!1505954251!85953033!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 25764 invoked from network); 21 Sep 2017 00:37:32 -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; 21 Sep 2017 00:37:32 -0000 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 6D2CB6087D; Thu, 21 Sep 2017 00:37:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1505954250; bh=k//Nph36QCAwlQT1Q7twlO57LkcvsbfuE1ReGQCeM2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z9Y0vrMNUoyWuHeHz2lCuGwXKyZIhem3exRI6AjFyt6MW7zgwoi1zSAVEUJ75bMWT ijXelvH1rm44NLGSwnVJcWAIJyBO8KHqI6M4e16O5Jcw2vfztgskoi3TD8EixVtZgw FLG0o20yUXsh2ebQa86FwpBLe6mCGCAdd7ZL5Xzo= 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 7196560879; Thu, 21 Sep 2017 00:37:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1505954247; bh=k//Nph36QCAwlQT1Q7twlO57LkcvsbfuE1ReGQCeM2I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SBBrozb9B/y6wbZXlqaxWhdyodNxfqu+6FPk0CryYFhDDA3y1P5hNnRwemVbYubYL zdJ9vpTeaK1h9gDd0WMTyxlbrCtGZ9gimx9sD1lrGH38re6pk7vQaxWnQ7t5nws8RN ItD/5NpWC2AnFWHdoXkQxh/Oxhr8FlAN4rE0FNv0= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 7196560879 From: Sameer Goel To: xen-devel@lists.xenproject.org, julien.grall@arm.com, mjaggi@caviumnetworks.com Date: Wed, 20 Sep 2017 18:37:06 -0600 Message-Id: <1505954230-18892-4-git-send-email-sgoel@codeaurora.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1505954230-18892-1-git-send-email-sgoel@codeaurora.org> References: <1505954230-18892-1-git-send-email-sgoel@codeaurora.org> Cc: sstabellini@kernel.org, wei.liu2@citrix.com, george.dunlap@eu.citrix.com, Andrew.Cooper3@citrix.com, jbeulich@suse.com, Sameer Goel , Ian.Jackson@citrix.com, nd@arm.com, robin.murphy@arm.com, shankerd@codeaurora.org Subject: [Xen-devel] [RFC v2 3/7] 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 | 66 +++++++++++++++++++++++++++++++++++++ xen/include/asm-arm/device.h | 1 + xen/include/xen/iommu.h | 29 ++++++++++++++++ 3 files changed, 96 insertions(+) diff --git a/xen/drivers/passthrough/arm/iommu.c b/xen/drivers/passthrough/arm/iommu.c index 95b1abb..41c6497 100644 --- a/xen/drivers/passthrough/arm/iommu.c +++ b/xen/drivers/passthrough/arm/iommu.c @@ -73,3 +73,69 @@ int arch_iommu_populate_page_table(struct domain *d) /* The IOMMU shares the p2m with the CPU */ return -ENOSYS; } + +const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode) +{ + return iommu_get_ops(); +} + +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(sizeof(struct iommu_fwspec), sizeof(void *)); + if ( !fwspec ) + return -ENOMEM; + + 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 ) + { + 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; + struct iommu_fwspec *fwspec_n = NULL; + size_t size, size_n; + int i; + + if ( !fwspec ) + return -EINVAL; + + size = offsetof(struct iommu_fwspec, ids[fwspec->num_ids]); + size_n = offsetof(struct iommu_fwspec, ids[fwspec->num_ids + num_ids]); + if ( size_n > size ) + { + fwspec_n = _xzalloc(size_n, sizeof(void *)); + if ( !fwspec_n ) + return -ENOMEM; + + memcpy(fwspec_n, fwspec, size); + xfree(fwspec); + } + + for (i = 0; i < num_ids; i++) + fwspec_n->ids[fwspec_n->num_ids + i] = ids[i]; + + fwspec_n->num_ids += num_ids; + dev->iommu_fwspec = fwspec_n; + + 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 0dac4f3..34e8d68 100644 --- a/xen/include/xen/iommu.h +++ b/xen/include/xen/iommu.h @@ -208,4 +208,33 @@ 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) +/** + * 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); +const struct iommu_ops *iommu_ops_from_fwnode(struct fwnode_handle *fwnode); + +#endif #endif /* _IOMMU_H_ */