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: Eric Auger X-Patchwork-Id: 8288141 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id DD56B9F3CD for ; Fri, 12 Feb 2016 08:16:46 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F1682203C4 for ; Fri, 12 Feb 2016 08:16:45 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0B6042035D for ; Fri, 12 Feb 2016 08:16:45 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1aU8sl-0005q3-So; Fri, 12 Feb 2016 08:15:15 +0000 Received: from mail-wm0-x22b.google.com ([2a00:1450:400c:c09::22b]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1aU8s3-0004lI-5C for linux-arm-kernel@lists.infradead.org; Fri, 12 Feb 2016 08:14:33 +0000 Received: by mail-wm0-x22b.google.com with SMTP id c200so9148711wme.0 for ; Fri, 12 Feb 2016 00:14:10 -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=OaiHXSRH2accYTALe938lz9UafKPSzVO3OmEsg4p/QmkaQaciyIYc1UJubc1yVUn/d Qx+VfajFFRYb0dHmhXbQCLul+mW97Rb/9+/N4WUXZAhwHqRNGa1zcr74Ab5BO01TR2mw Vs2icRSxqykYRVHKa2/GeYGBHLcXQEhdd5HaYP4kfuRtTaUzqRaDIARv25UGxUxJFB7G 4QETXNN7QZpwweCx0a8ataZKhQqPIm8cWNLtaCPOZQFgr+nYiHT8rySDUVyTkyZ+U+VA 5kEJjTSHVm27LxlxhIkWBh1s8C/AfM/UG7NwbhoAN6pn4UMwQE582175IKMMPeNfgSPI xUaw== X-Gm-Message-State: AG10YOT3eMuEvUM292Do+FC089WoztTtsfSULEn6Edpe4YIk3ilO8rCDTwnkfpztpY1VKDnk X-Received: by 10.28.59.212 with SMTP id i203mr1410511wma.69.1455264849422; Fri, 12 Feb 2016 00:14:09 -0800 (PST) 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 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> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160212_001431_611527_43003AA5 X-CRM114-Status: GOOD ( 12.74 ) X-Spam-Score: -2.7 (--) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas.Lendacky@amd.com, brijesh.singh@amd.com, patches@linaro.org, Manish.Jaggi@caviumnetworks.com, p.fedin@samsung.com, linux-kernel@vger.kernel.org, Bharat.Bhushan@freescale.com, iommu@lists.linux-foundation.org, pranav.sawargaonkar@gmail.com, leo.duran@amd.com, suravee.suthikulpanit@amd.com, sherry.hurwitz@amd.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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(+) 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);