aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoerg Roedel <joerg.roedel@amd.com>2010-01-08 07:35:09 -0500
committerJoerg Roedel <joerg.roedel@amd.com>2010-03-07 12:01:11 -0500
commitcefc53c7f494240d4813c80154c7617452d1904d (patch)
tree675370ec20df0841e404ed7b191d2d41f30f7e52
parent4abc14a733f9002c05623db755aaafdd27fa7a91 (diff)
iommu-api: Add iommu_map and iommu_unmap functions
These two functions provide support for mapping and unmapping physical addresses to io virtual addresses. The difference to the iommu_(un)map_range() is that the new functions take a gfp_order parameter instead of a size. This allows the IOMMU backend implementations to detect easier if a given range can be mapped by larger page sizes. These new functions should replace the old ones in the long term. Signed-off-by: Joerg Roedel <joerg.roedel@amd.com>
-rw-r--r--drivers/base/iommu.c31
-rw-r--r--include/linux/iommu.h16
2 files changed, 47 insertions, 0 deletions
diff --git a/drivers/base/iommu.c b/drivers/base/iommu.c
index f4c86c429297..cf7cbec116ed 100644
--- a/drivers/base/iommu.c
+++ b/drivers/base/iommu.c
@@ -107,3 +107,34 @@ int iommu_domain_has_cap(struct iommu_domain *domain,
107 return iommu_ops->domain_has_cap(domain, cap); 107 return iommu_ops->domain_has_cap(domain, cap);
108} 108}
109EXPORT_SYMBOL_GPL(iommu_domain_has_cap); 109EXPORT_SYMBOL_GPL(iommu_domain_has_cap);
110
111int iommu_map(struct iommu_domain *domain, unsigned long iova,
112 phys_addr_t paddr, int gfp_order, int prot)
113{
114 unsigned long invalid_mask;
115 size_t size;
116
117 size = 0x1000UL << gfp_order;
118 invalid_mask = size - 1;
119
120 BUG_ON((iova | paddr) & invalid_mask);
121
122 return iommu_ops->map_range(domain, iova, paddr, size, prot);
123}
124EXPORT_SYMBOL_GPL(iommu_map);
125
126int iommu_unmap(struct iommu_domain *domain, unsigned long iova, int gfp_order)
127{
128 unsigned long invalid_mask;
129 size_t size;
130
131 size = 0x1000UL << gfp_order;
132 invalid_mask = size - 1;
133
134 BUG_ON(iova & invalid_mask);
135
136 iommu_ops->unmap_range(domain, iova, size);
137
138 return gfp_order;
139}
140EXPORT_SYMBOL_GPL(iommu_unmap);
diff --git a/include/linux/iommu.h b/include/linux/iommu.h
index 0f18f37a6503..6d0035bb1a0c 100644
--- a/include/linux/iommu.h
+++ b/include/linux/iommu.h
@@ -60,6 +60,10 @@ extern int iommu_map_range(struct iommu_domain *domain, unsigned long iova,
60 phys_addr_t paddr, size_t size, int prot); 60 phys_addr_t paddr, size_t size, int prot);
61extern void iommu_unmap_range(struct iommu_domain *domain, unsigned long iova, 61extern void iommu_unmap_range(struct iommu_domain *domain, unsigned long iova,
62 size_t size); 62 size_t size);
63extern int iommu_map(struct iommu_domain *domain, unsigned long iova,
64 phys_addr_t paddr, int gfp_order, int prot);
65extern int iommu_unmap(struct iommu_domain *domain, unsigned long iova,
66 int gfp_order);
63extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, 67extern phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
64 unsigned long iova); 68 unsigned long iova);
65extern int iommu_domain_has_cap(struct iommu_domain *domain, 69extern int iommu_domain_has_cap(struct iommu_domain *domain,
@@ -108,6 +112,18 @@ static inline void iommu_unmap_range(struct iommu_domain *domain,
108{ 112{
109} 113}
110 114
115static inline int iommu_map(struct iommu_domain *domain, unsigned long iova,
116 phys_addr_t paddr, int gfp_order, int prot)
117{
118 return -ENODEV;
119}
120
121static inline int iommu_unmap(struct iommu_domain *domain, unsigned long iova,
122 int gfp_order)
123{
124 return -ENODEV;
125}
126
111static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, 127static inline phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain,
112 unsigned long iova) 128 unsigned long iova)
113{ 129{