linux-mm.kvack.org archive mirror
 help / color / mirror / Atom feed
From: j.glisse@gmail.com
To: linux-kernel@vger.kernel.org, linux-mm@kvack.org,
	akpm@linux-foundation.org, Haggai Eran <haggaie@mellanox.com>
Cc: "Linus Torvalds" <torvalds@linux-foundation.org>,
	joro@8bytes.org, "Mel Gorman" <mgorman@suse.de>,
	"H. Peter Anvin" <hpa@zytor.com>,
	"Peter Zijlstra" <peterz@infradead.org>,
	"Andrea Arcangeli" <aarcange@redhat.com>,
	"Johannes Weiner" <jweiner@redhat.com>,
	"Larry Woodman" <lwoodman@redhat.com>,
	"Rik van Riel" <riel@redhat.com>,
	"Dave Airlie" <airlied@redhat.com>,
	"Brendan Conoboy" <blc@redhat.com>,
	"Joe Donohue" <jdonohue@redhat.com>,
	"Duncan Poole" <dpoole@nvidia.com>,
	"Sherry Cheung" <SCheung@nvidia.com>,
	"Subhash Gutti" <sgutti@nvidia.com>,
	"John Hubbard" <jhubbard@nvidia.com>,
	"Mark Hairgrove" <mhairgrove@nvidia.com>,
	"Lucien Dunning" <ldunning@nvidia.com>,
	"Cameron Buschardt" <cabuschardt@nvidia.com>,
	"Arvind Gopalakrishnan" <arvindg@nvidia.com>,
	"Shachar Raindel" <raindel@mellanox.com>,
	"Liran Liss" <liranl@mellanox.com>,
	"Roland Dreier" <roland@purestorage.com>,
	"Ben Sander" <ben.sander@amd.com>,
	"Greg Stoner" <Greg.Stoner@amd.com>,
	"John Bridgman" <John.Bridgman@amd.com>,
	"Michael Mantor" <Michael.Mantor@amd.com>,
	"Paul Blinzer" <Paul.Blinzer@amd.com>,
	"Laurent Morichetti" <Laurent.Morichetti@amd.com>,
	"Alexander Deucher" <Alexander.Deucher@amd.com>,
	"Oded Gabbay" <Oded.Gabbay@amd.com>,
	"Jérôme Glisse" <jglisse@redhat.com>
Subject: [RFC PATCH 5/6] iommu: new api to map an array of page frame number into a domain.
Date: Fri, 29 Aug 2014 15:10:14 -0400	[thread overview]
Message-ID: <1409339415-3626-6-git-send-email-j.glisse@gmail.com> (raw)
In-Reply-To: <1409339415-3626-1-git-send-email-j.glisse@gmail.com>

From: JA(C)rA'me Glisse <jglisse@redhat.com>

New user of iommu can share the same mapping for device in same domain.
Which allow saving resources. For this a new iommu domain callback is
needed. This add the core support for the callback.

Signed-off-by: JA(C)rA'me Glisse <jglisse@redhat.com>
---
 include/linux/iommu.h | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 145 insertions(+)

diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 20f9a52..ff6983f 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -97,6 +97,9 @@ enum iommu_attr {
  * @domain_has_cap: domain capabilities query
  * @add_device: add device to iommu grouping
  * @remove_device: remove device from iommu grouping
+ * @domain_map_directory: Map a directory of pages.
+ * @domain_update_directory: Update a directory of pages mapping.
+ * @domain_unmap_directory: Unmap a directory of pages.
  * @domain_get_attr: Query domain attributes
  * @domain_set_attr: Change domain attributes
  * @pgsize_bitmap: bitmap of supported page sizes
@@ -130,6 +133,26 @@ struct iommu_ops {
 	/* Get the numer of window per domain */
 	u32 (*domain_get_windows)(struct iommu_domain *domain);
 
+	int (*domain_map_directory)(struct iommu_domain *domain,
+				    unsigned long npages,
+				    unsigned long *pfns,
+				    unsigned long pfn_mask,
+				    unsigned long pfn_shift,
+				    unsigned long pfn_valid,
+				    unsigned long pfn_write,
+				    dma_addr_t *iova_base);
+	int (*domain_update_directory)(struct iommu_domain *domain,
+				       unsigned long npages,
+				       unsigned long *pfns,
+				       unsigned long pfn_mask,
+				       unsigned long pfn_shift,
+				       unsigned long pfn_valid,
+				       unsigned long pfn_write,
+				       dma_addr_t iova_base);
+	int (*domain_unmap_directory)(struct iommu_domain *domain,
+				      unsigned long npages,
+				      dma_addr_t iova);
+
 	unsigned long pgsize_bitmap;
 };
 
@@ -240,6 +263,97 @@ static inline int report_iommu_fault(struct iommu_domain *domain,
 	return ret;
 }
 
+/* iommu_domain_map_directory() - Map a directory of pages into a given domain.
+ *
+ * @domain: Domain into which mapping should happen.
+ * @npages: The maximum number of page to map.
+ * @pfns: The pfns directory array.
+ * @pfn_mask: The pfn mask (pfn_for_i = (pfns[i] & pfn_mask) >> pfn_shift).
+ * @pfn_shift: The pfn shift (pfn_for_i = (pfns[i] & pfn_mask) >> pfn_shift).
+ * @pfn_valid: An entry in the array is valid if (pfns[i] & pfn_valid).
+ * @pfn_write: An entry should be mapped write if (pfns[i] & pfn_write)
+ * @iova_base: Base io virtual address at which directory is mapped on success.
+ * Returns: Number of mapped pages on success, negative errno otherwise.
+ *
+ * This allow to map contiguously a directory of pages into a specific domain.
+ * On success it sets the base io virtual address at which the directory is
+ * mapped and it returns the number of page successfully mapped. Each entry in
+ * the directory can either be a valid page in read only or in read and write
+ * depending on flags and there can be gaps.
+ */
+static inline int iommu_domain_map_directory(struct iommu_domain *domain,
+					     unsigned long npages,
+					     unsigned long *pfns,
+					     unsigned long pfn_mask,
+					     unsigned long pfn_shift,
+					     unsigned long pfn_valid,
+					     unsigned long pfn_write,
+					     dma_addr_t *iova_base)
+{
+	if (!domain->ops->domain_map_directory)
+		return -EINVAL;
+	return domain->ops->domain_map_directory(domain, npages, pfns,
+						 pfn_mask, pfn_shift,
+						 pfn_valid, pfn_write,
+						 iova_base);
+}
+
+/* iommu_domain_update_directory() - Update a directory mapping of pages.
+ *
+ * @domain: Domain into which mapping exist.
+ * @npages: The maximum number of page to map.
+ * @pfns: The pfns directory array.
+ * @pfn_mask: The pfn mask (pfn_for_i = (pfns[i] & pfn_mask) >> pfn_shift).
+ * @pfn_shift: The pfn shift (pfn_for_i = (pfns[i] & pfn_mask) >> pfn_shift).
+ * @pfn_valid: An entry in the array is valid if (pfns[i] & pfn_valid).
+ * @pfn_write: An entry should be mapped write if (pfns[i] & pfn_write)
+ * @iova_base: Base io virtual address at which directory is mapped.
+ * Returns: Number of mapped (positive) or unmapped (negative) pages.
+ *
+ * This allow to update a previously successfull directory mapping of pages,
+ * either by adding or removing or replacing pages or modifying page mapping
+ * (read only to read and write or read and write to read only). It returns
+ * the number of new or removed mapping. Modified mapping are not counted.
+ * So if return value is positive it means there is an increase in the number
+ * of valid mapped entry. If it is negative it means there is a decrease in
+ * the number of valid mapped entry. In all case |return| <= npages.
+ */
+static inline int iommu_domain_update_directory(struct iommu_domain *domain,
+						unsigned long npages,
+						unsigned long *pfns,
+						unsigned long pfn_mask,
+						unsigned long pfn_shift,
+						unsigned long pfn_valid,
+						unsigned long pfn_write,
+						dma_addr_t iova_base)
+{
+	if (!domain->ops->domain_update_directory)
+		return -EINVAL;
+	return domain->ops->domain_update_directory(domain, npages, pfns,
+						    pfn_mask, pfn_shift,
+						    pfn_valid, pfn_write,
+						    iova_base);
+}
+
+/* iommu_domain_unmap_directory() - Unmap a directory of pages in a domain.
+ *
+ * @domain: Domain into which mapping should happen.
+ * @npages: The maximum number of page to map.
+ * @iova_base: Base io virtual address at which directory is mapped.
+ * Returns: Number of unmapped pages.
+ *
+ * This allow to unmap a previously successfull directory mapping of pages. It
+ * free the iova and return the number of valid unmapped entries.
+ */
+static inline int iommu_domain_unmap_directory(struct iommu_domain *domain,
+					       unsigned long npages,
+					       dma_addr_t iova_base)
+{
+	if (!domain->ops->domain_unmap_directory)
+		return 0;
+	return domain->ops->domain_unmap_directory(domain, npages, iova_base);
+}
+
 #else /* CONFIG_IOMMU_API */
 
 struct iommu_ops {};
@@ -424,6 +538,37 @@ static inline void iommu_device_unlink(struct device *dev, struct device *link)
 {
 }
 
+static inline int iommu_domain_map_directory(struct iommu_domain *domain,
+					     unsigned long npages,
+					     unsigned long *pfns,
+					     unsigned long pfn_mask,
+					     unsigned long pfn_shift,
+					     unsigned long pfn_valid,
+					     unsigned long pfn_write,
+					     dma_addr_t *iova_base)
+{
+	return -EINVAL;
+}
+
+static inline int iommu_domain_update_directory(struct iommu_domain *domain,
+						unsigned long npages,
+						unsigned long *pfns,
+						unsigned long pfn_mask,
+						unsigned long pfn_shift,
+						unsigned long pfn_valid,
+						unsigned long pfn_write,
+						dma_addr_t iova_base)
+{
+	return -EINVAL;
+}
+
+static inline void iommu_domain_unmap_directory(struct iommu_domain *domain,
+						unsigned long npages,
+						dma_addr_t iova_base)
+{
+	return;
+}
+
 #endif /* CONFIG_IOMMU_API */
 
 #endif /* __LINUX_IOMMU_H */
-- 
1.9.3

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

  parent reply	other threads:[~2014-08-29 19:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-08-29 19:10 [RFC PATCH 0/6] HMM (heterogeneous memory management) v4 j.glisse
2014-08-29 19:10 ` [RFC PATCH 1/6] mmu_notifier: add event information to address invalidation v4 j.glisse
2014-09-11 10:00   ` Haggai Eran
2014-09-11 14:13     ` Jerome Glisse
2014-08-29 19:10 ` [RFC PATCH 2/6] lib: lockless generic and arch independent page table (gpt) j.glisse
2014-08-29 19:10 ` [RFC PATCH 3/6] hmm: heterogeneous memory management v5 j.glisse
2014-08-29 19:10 ` [RFC PATCH 4/6] hmm/dummy: dummy driver to showcase the hmm api v2 j.glisse
2014-08-29 19:10 ` j.glisse [this message]
2014-08-29 19:10 ` [RFC PATCH 6/6] hmm: add support for iommu domain j.glisse

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1409339415-3626-6-git-send-email-j.glisse@gmail.com \
    --to=j.glisse@gmail.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Greg.Stoner@amd.com \
    --cc=John.Bridgman@amd.com \
    --cc=Laurent.Morichetti@amd.com \
    --cc=Michael.Mantor@amd.com \
    --cc=Oded.Gabbay@amd.com \
    --cc=Paul.Blinzer@amd.com \
    --cc=SCheung@nvidia.com \
    --cc=aarcange@redhat.com \
    --cc=airlied@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=arvindg@nvidia.com \
    --cc=ben.sander@amd.com \
    --cc=blc@redhat.com \
    --cc=cabuschardt@nvidia.com \
    --cc=dpoole@nvidia.com \
    --cc=haggaie@mellanox.com \
    --cc=hpa@zytor.com \
    --cc=jdonohue@redhat.com \
    --cc=jglisse@redhat.com \
    --cc=jhubbard@nvidia.com \
    --cc=joro@8bytes.org \
    --cc=jweiner@redhat.com \
    --cc=ldunning@nvidia.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=liranl@mellanox.com \
    --cc=lwoodman@redhat.com \
    --cc=mgorman@suse.de \
    --cc=mhairgrove@nvidia.com \
    --cc=peterz@infradead.org \
    --cc=raindel@mellanox.com \
    --cc=riel@redhat.com \
    --cc=roland@purestorage.com \
    --cc=sgutti@nvidia.com \
    --cc=torvalds@linux-foundation.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).