From patchwork Fri Feb 12 08:13:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Auger Eric X-Patchwork-Id: 61821 Delivered-To: patches@linaro.org Received: by 10.112.43.199 with SMTP id y7csp676634lbl; Fri, 12 Feb 2016 00:14:09 -0800 (PST) X-Received: by 10.28.223.69 with SMTP id w66mr1549139wmg.89.1455264849623; Fri, 12 Feb 2016 00:14:09 -0800 (PST) Return-Path: Received: from mail-wm0-x229.google.com (mail-wm0-x229.google.com. [2a00:1450:400c:c09::229]) by mx.google.com with ESMTPS id gh6si17639161wjb.245.2016.02.12.00.14.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 12 Feb 2016 00:14:09 -0800 (PST) Received-SPF: pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::229 as permitted sender) client-ip=2a00:1450:400c:c09::229; Authentication-Results: mx.google.com; spf=pass (google.com: domain of eric.auger@linaro.org designates 2a00:1450:400c:c09::229 as permitted sender) smtp.mailfrom=eric.auger@linaro.org; dkim=pass header.i=@linaro.org Received: by mail-wm0-x229.google.com with SMTP id g62so8941447wme.0 for ; Fri, 12 Feb 2016 00:14:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=PycT5Fh0zHMir2IgWHLTtv2ePsZow5lrWdwKJAKMztM=; b=FT/SYZf2vJD3K6GJE41aova2X6aFZWa41Y3xqhpCrYRmNhHTZDPecDGeSL6iNm5wR2 tui/qdjLYgnwVlNyC3X/0s5xSebbfJBaOB+qwmMcKa4ULguiNwkFz+EB+6HkMMGdMkGc YJPKPt4nWU8f50u+BefQRbmYTPxBQHWQGZgSE= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=PycT5Fh0zHMir2IgWHLTtv2ePsZow5lrWdwKJAKMztM=; b=Ptr0o5OVurSkAzWjCb5m8HxEBCq9CdaVFctxnHRck69UNAJ8q2tVgfwVFSbC3hW2+y T8MLS0cYi8mh65UiZ89TMJ+2HfKgSGxvsW7mZLRLKJ+8+c0U1lv6sYjhX4UK9V/3NXKO Ilz6QapDYJPTInZP/TYaNFwm1Wczc93Sqkqg8XiUakEAAW2cK1edGyHiXlhCx/E9LDLZ SciYjNp0MhMKYi/KPz1kkTkpNBNk7OgCWE9a0/oht1IKpaF/JojA52Y/AKGFUXTBLAtI wNOU1fXyUrF1KV3yl3oH+EBjyADtD2aMZE71NDUvhpgr2n8RsbF8AB1qcn/osxfLZrBJ w4ow== X-Gm-Message-State: AG10YORjERzrBlncvsGMaq7aEpRE6O8pXvhI4zGTeU7eVEUIPpgtabRjpXXdRJQ19eQ7UHNlES0= X-Received: by 10.28.59.212 with SMTP id i203mr1410511wma.69.1455264849422; Fri, 12 Feb 2016 00:14:09 -0800 (PST) Return-Path: Received: from new-host-17.home (LMontsouris-657-1-37-90.w80-11.abo.wanadoo.fr. [80.11.198.90]) by smtp.gmail.com with ESMTPSA id x66sm1243977wmb.20.2016.02.12.00.14.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 12 Feb 2016 00:14:07 -0800 (PST) From: Eric Auger To: eric.auger@st.com, eric.auger@linaro.org, alex.williamson@redhat.com, will.deacon@arm.com, joro@8bytes.org, tglx@linutronix.de, jason@lakedaemon.net, marc.zyngier@arm.com, christoffer.dall@linaro.org, linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, kvm@vger.kernel.org Cc: suravee.suthikulpanit@amd.com, patches@linaro.org, linux-kernel@vger.kernel.org, Manish.Jaggi@caviumnetworks.com, Bharat.Bhushan@freescale.com, pranav.sawargaonkar@gmail.com, p.fedin@samsung.com, iommu@lists.linux-foundation.org, sherry.hurwitz@amd.com, brijesh.singh@amd.com, leo.duran@amd.com, Thomas.Lendacky@amd.com Subject: [RFC v3 04/15] iommu: add alloc/free_reserved_iova_domain Date: Fri, 12 Feb 2016 08:13:06 +0000 Message-Id: <1455264797-2334-5-git-send-email-eric.auger@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1455264797-2334-1-git-send-email-eric.auger@linaro.org> References: <1455264797-2334-1-git-send-email-eric.auger@linaro.org> Introduce alloc/free_reserved_iova_domain in the IOMMU API. alloc_reserved_iova_domain initializes an iova domain at a given iova base address and with a given size. This iova domain will be used to allocate iova within that window. Those IOVAs will be reserved for special purpose, typically MSI frame binding. Allocation function within the reserved iova domain will be introduced in subsequent patches. This is the responsability of the API user to make sure any IOVA belonging to that domain are allocated with those allocation functions. Signed-off-by: Eric Auger --- v2 -> v3: - remove iommu_alloc_reserved_iova_domain & iommu_free_reserved_iova_domain static implementation in case CONFIG_IOMMU_API is not set v1 -> v2: - moved from vfio API to IOMMU API --- drivers/iommu/iommu.c | 22 ++++++++++++++++++++++ include/linux/iommu.h | 10 ++++++++++ 2 files changed, 32 insertions(+) -- 1.9.1 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 0e3b009..a994f34 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -1557,6 +1557,28 @@ int iommu_domain_set_attr(struct iommu_domain *domain, } EXPORT_SYMBOL_GPL(iommu_domain_set_attr); +int iommu_alloc_reserved_iova_domain(struct iommu_domain *domain, + dma_addr_t iova, size_t size, + unsigned long order) +{ + int ret; + + if (!domain->ops->alloc_reserved_iova_domain) + return -EINVAL; + ret = domain->ops->alloc_reserved_iova_domain(domain, iova, + size, order); + return ret; +} +EXPORT_SYMBOL_GPL(iommu_alloc_reserved_iova_domain); + +void iommu_free_reserved_iova_domain(struct iommu_domain *domain) +{ + if (!domain->ops->free_reserved_iova_domain) + return; + domain->ops->free_reserved_iova_domain(domain); +} +EXPORT_SYMBOL_GPL(iommu_free_reserved_iova_domain); + void iommu_get_dm_regions(struct device *dev, struct list_head *list) { const struct iommu_ops *ops = dev->bus->iommu_ops; diff --git a/include/linux/iommu.h b/include/linux/iommu.h index a4fe04a..2d1f155 100644 --- a/include/linux/iommu.h +++ b/include/linux/iommu.h @@ -195,6 +195,12 @@ struct iommu_ops { int (*domain_set_windows)(struct iommu_domain *domain, u32 w_count); /* Get the number of windows per domain */ u32 (*domain_get_windows)(struct iommu_domain *domain); + /* allocates the reserved iova domain */ + int (*alloc_reserved_iova_domain)(struct iommu_domain *domain, + dma_addr_t iova, size_t size, + unsigned long order); + /* frees the reserved iova domain */ + void (*free_reserved_iova_domain)(struct iommu_domain *domain); #ifdef CONFIG_OF_IOMMU int (*of_xlate)(struct device *dev, struct of_phandle_args *args); @@ -266,6 +272,10 @@ extern int iommu_domain_get_attr(struct iommu_domain *domain, enum iommu_attr, void *data); extern int iommu_domain_set_attr(struct iommu_domain *domain, enum iommu_attr, void *data); +extern int iommu_alloc_reserved_iova_domain(struct iommu_domain *domain, + dma_addr_t iova, size_t size, + unsigned long order); +extern void iommu_free_reserved_iova_domain(struct iommu_domain *domain); struct device *iommu_device_create(struct device *parent, void *drvdata, const struct attribute_group **groups, const char *fmt, ...) __printf(4, 5);