Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007-2008 Advanced Micro Devices, Inc. |
| 3 | * Author: Joerg Roedel <joerg.roedel@amd.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of the GNU General Public License version 2 as published |
| 7 | * by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | */ |
| 18 | |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 19 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
| 20 | |
Joerg Roedel | 905d66c | 2011-09-06 16:03:26 +0200 | [diff] [blame] | 21 | #include <linux/device.h> |
Ohad Ben-Cohen | 4099818 | 2011-09-02 13:32:32 -0400 | [diff] [blame] | 22 | #include <linux/kernel.h> |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 23 | #include <linux/bug.h> |
| 24 | #include <linux/types.h> |
Andrew Morton | 60db402 | 2009-05-06 16:03:07 -0700 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/slab.h> |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 27 | #include <linux/errno.h> |
| 28 | #include <linux/iommu.h> |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 29 | #include <linux/scatterlist.h> |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 30 | |
Alex Williamson | 1460432 | 2011-10-21 15:56:05 -0400 | [diff] [blame] | 31 | static ssize_t show_iommu_group(struct device *dev, |
| 32 | struct device_attribute *attr, char *buf) |
| 33 | { |
| 34 | unsigned int groupid; |
| 35 | |
| 36 | if (iommu_device_group(dev, &groupid)) |
| 37 | return 0; |
| 38 | |
| 39 | return sprintf(buf, "%u", groupid); |
| 40 | } |
| 41 | static DEVICE_ATTR(iommu_group, S_IRUGO, show_iommu_group, NULL); |
| 42 | |
| 43 | static int add_iommu_group(struct device *dev, void *data) |
| 44 | { |
| 45 | unsigned int groupid; |
| 46 | |
| 47 | if (iommu_device_group(dev, &groupid) == 0) |
| 48 | return device_create_file(dev, &dev_attr_iommu_group); |
| 49 | |
| 50 | return 0; |
| 51 | } |
| 52 | |
| 53 | static int remove_iommu_group(struct device *dev) |
| 54 | { |
| 55 | unsigned int groupid; |
| 56 | |
| 57 | if (iommu_device_group(dev, &groupid) == 0) |
| 58 | device_remove_file(dev, &dev_attr_iommu_group); |
| 59 | |
| 60 | return 0; |
| 61 | } |
| 62 | |
| 63 | static int iommu_device_notifier(struct notifier_block *nb, |
| 64 | unsigned long action, void *data) |
| 65 | { |
| 66 | struct device *dev = data; |
| 67 | |
| 68 | if (action == BUS_NOTIFY_ADD_DEVICE) |
| 69 | return add_iommu_group(dev, NULL); |
| 70 | else if (action == BUS_NOTIFY_DEL_DEVICE) |
| 71 | return remove_iommu_group(dev); |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | |
| 76 | static struct notifier_block iommu_device_nb = { |
| 77 | .notifier_call = iommu_device_notifier, |
| 78 | }; |
| 79 | |
Joerg Roedel | ff21776 | 2011-08-26 16:48:26 +0200 | [diff] [blame] | 80 | static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops) |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 81 | { |
Alex Williamson | 1460432 | 2011-10-21 15:56:05 -0400 | [diff] [blame] | 82 | bus_register_notifier(bus, &iommu_device_nb); |
| 83 | bus_for_each_dev(bus, NULL, NULL, add_iommu_group); |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 84 | } |
| 85 | |
Joerg Roedel | ff21776 | 2011-08-26 16:48:26 +0200 | [diff] [blame] | 86 | /** |
| 87 | * bus_set_iommu - set iommu-callbacks for the bus |
| 88 | * @bus: bus. |
| 89 | * @ops: the callbacks provided by the iommu-driver |
| 90 | * |
| 91 | * This function is called by an iommu driver to set the iommu methods |
| 92 | * used for a particular bus. Drivers for devices on that bus can use |
| 93 | * the iommu-api after these ops are registered. |
| 94 | * This special function is needed because IOMMUs are usually devices on |
| 95 | * the bus itself, so the iommu drivers are not initialized when the bus |
| 96 | * is set up. With this function the iommu-driver can set the iommu-ops |
| 97 | * afterwards. |
| 98 | */ |
| 99 | int bus_set_iommu(struct bus_type *bus, struct iommu_ops *ops) |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 100 | { |
Joerg Roedel | ff21776 | 2011-08-26 16:48:26 +0200 | [diff] [blame] | 101 | if (bus->iommu_ops != NULL) |
| 102 | return -EBUSY; |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 103 | |
Joerg Roedel | ff21776 | 2011-08-26 16:48:26 +0200 | [diff] [blame] | 104 | bus->iommu_ops = ops; |
| 105 | |
| 106 | /* Do IOMMU specific setup for this bus-type */ |
| 107 | iommu_bus_init(bus, ops); |
| 108 | |
| 109 | return 0; |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 110 | } |
Joerg Roedel | ff21776 | 2011-08-26 16:48:26 +0200 | [diff] [blame] | 111 | EXPORT_SYMBOL_GPL(bus_set_iommu); |
| 112 | |
Joerg Roedel | a1b60c1 | 2011-09-06 18:46:34 +0200 | [diff] [blame] | 113 | bool iommu_present(struct bus_type *bus) |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 114 | { |
Joerg Roedel | 94441c3 | 2011-09-06 18:58:54 +0200 | [diff] [blame] | 115 | return bus->iommu_ops != NULL; |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 116 | } |
Joerg Roedel | a1b60c1 | 2011-09-06 18:46:34 +0200 | [diff] [blame] | 117 | EXPORT_SYMBOL_GPL(iommu_present); |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 118 | |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 119 | /** |
| 120 | * iommu_set_fault_handler() - set a fault handler for an iommu domain |
| 121 | * @domain: iommu domain |
| 122 | * @handler: fault handler |
Ohad Ben-Cohen | d506953 | 2012-05-21 20:20:05 +0300 | [diff] [blame^] | 123 | * @token: user data, will be passed back to the fault handler |
Ohad Ben-Cohen | 0ed6d2d | 2011-09-27 07:36:40 -0400 | [diff] [blame] | 124 | * |
| 125 | * This function should be used by IOMMU users which want to be notified |
| 126 | * whenever an IOMMU fault happens. |
| 127 | * |
| 128 | * The fault handler itself should return 0 on success, and an appropriate |
| 129 | * error code otherwise. |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 130 | */ |
| 131 | void iommu_set_fault_handler(struct iommu_domain *domain, |
Ohad Ben-Cohen | d506953 | 2012-05-21 20:20:05 +0300 | [diff] [blame^] | 132 | iommu_fault_handler_t handler, |
| 133 | void *token) |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 134 | { |
| 135 | BUG_ON(!domain); |
| 136 | |
| 137 | domain->handler = handler; |
Ohad Ben-Cohen | d506953 | 2012-05-21 20:20:05 +0300 | [diff] [blame^] | 138 | domain->handler_token = token; |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 139 | } |
Ohad Ben-Cohen | 30bd918 | 2011-09-26 09:11:46 -0400 | [diff] [blame] | 140 | EXPORT_SYMBOL_GPL(iommu_set_fault_handler); |
Ohad Ben-Cohen | 4f3f8d9 | 2011-09-13 15:25:23 -0400 | [diff] [blame] | 141 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 142 | struct iommu_domain *iommu_domain_alloc(struct bus_type *bus, int flags) |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 143 | { |
| 144 | struct iommu_domain *domain; |
| 145 | int ret; |
| 146 | |
Joerg Roedel | 94441c3 | 2011-09-06 18:58:54 +0200 | [diff] [blame] | 147 | if (bus == NULL || bus->iommu_ops == NULL) |
Joerg Roedel | 905d66c | 2011-09-06 16:03:26 +0200 | [diff] [blame] | 148 | return NULL; |
| 149 | |
KyongHo Cho | 8bd6960 | 2011-12-16 21:38:25 +0900 | [diff] [blame] | 150 | domain = kzalloc(sizeof(*domain), GFP_KERNEL); |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 151 | if (!domain) |
| 152 | return NULL; |
| 153 | |
Joerg Roedel | 94441c3 | 2011-09-06 18:58:54 +0200 | [diff] [blame] | 154 | domain->ops = bus->iommu_ops; |
Joerg Roedel | 905d66c | 2011-09-06 16:03:26 +0200 | [diff] [blame] | 155 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 156 | ret = domain->ops->domain_init(domain, flags); |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 157 | if (ret) |
| 158 | goto out_free; |
| 159 | |
| 160 | return domain; |
| 161 | |
| 162 | out_free: |
| 163 | kfree(domain); |
| 164 | |
| 165 | return NULL; |
| 166 | } |
| 167 | EXPORT_SYMBOL_GPL(iommu_domain_alloc); |
| 168 | |
| 169 | void iommu_domain_free(struct iommu_domain *domain) |
| 170 | { |
Joerg Roedel | e5aa7f0 | 2011-09-06 16:44:29 +0200 | [diff] [blame] | 171 | if (likely(domain->ops->domain_destroy != NULL)) |
| 172 | domain->ops->domain_destroy(domain); |
| 173 | |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 174 | kfree(domain); |
| 175 | } |
| 176 | EXPORT_SYMBOL_GPL(iommu_domain_free); |
| 177 | |
| 178 | int iommu_attach_device(struct iommu_domain *domain, struct device *dev) |
| 179 | { |
Joerg Roedel | e5aa7f0 | 2011-09-06 16:44:29 +0200 | [diff] [blame] | 180 | if (unlikely(domain->ops->attach_dev == NULL)) |
| 181 | return -ENODEV; |
| 182 | |
| 183 | return domain->ops->attach_dev(domain, dev); |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 184 | } |
| 185 | EXPORT_SYMBOL_GPL(iommu_attach_device); |
| 186 | |
| 187 | void iommu_detach_device(struct iommu_domain *domain, struct device *dev) |
| 188 | { |
Joerg Roedel | e5aa7f0 | 2011-09-06 16:44:29 +0200 | [diff] [blame] | 189 | if (unlikely(domain->ops->detach_dev == NULL)) |
| 190 | return; |
| 191 | |
| 192 | domain->ops->detach_dev(domain, dev); |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 193 | } |
| 194 | EXPORT_SYMBOL_GPL(iommu_detach_device); |
| 195 | |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 196 | phys_addr_t iommu_iova_to_phys(struct iommu_domain *domain, |
| 197 | unsigned long iova) |
| 198 | { |
Joerg Roedel | e5aa7f0 | 2011-09-06 16:44:29 +0200 | [diff] [blame] | 199 | if (unlikely(domain->ops->iova_to_phys == NULL)) |
| 200 | return 0; |
| 201 | |
| 202 | return domain->ops->iova_to_phys(domain, iova); |
Joerg Roedel | fc2100e | 2008-11-26 17:21:24 +0100 | [diff] [blame] | 203 | } |
| 204 | EXPORT_SYMBOL_GPL(iommu_iova_to_phys); |
Sheng Yang | dbb9fd8 | 2009-03-18 15:33:06 +0800 | [diff] [blame] | 205 | |
| 206 | int iommu_domain_has_cap(struct iommu_domain *domain, |
| 207 | unsigned long cap) |
| 208 | { |
Joerg Roedel | e5aa7f0 | 2011-09-06 16:44:29 +0200 | [diff] [blame] | 209 | if (unlikely(domain->ops->domain_has_cap == NULL)) |
| 210 | return 0; |
| 211 | |
| 212 | return domain->ops->domain_has_cap(domain, cap); |
Sheng Yang | dbb9fd8 | 2009-03-18 15:33:06 +0800 | [diff] [blame] | 213 | } |
| 214 | EXPORT_SYMBOL_GPL(iommu_domain_has_cap); |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 215 | |
| 216 | int iommu_map(struct iommu_domain *domain, unsigned long iova, |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 217 | phys_addr_t paddr, size_t size, int prot) |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 218 | { |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 219 | unsigned long orig_iova = iova; |
| 220 | unsigned int min_pagesz; |
| 221 | size_t orig_size = size; |
| 222 | int ret = 0; |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 223 | |
Joerg Roedel | e5aa7f0 | 2011-09-06 16:44:29 +0200 | [diff] [blame] | 224 | if (unlikely(domain->ops->map == NULL)) |
| 225 | return -ENODEV; |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 226 | |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 227 | /* find out the minimum page size supported */ |
| 228 | min_pagesz = 1 << __ffs(domain->ops->pgsize_bitmap); |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 229 | |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 230 | /* |
| 231 | * both the virtual address and the physical one, as well as |
| 232 | * the size of the mapping, must be aligned (at least) to the |
| 233 | * size of the smallest page supported by the hardware |
| 234 | */ |
| 235 | if (!IS_ALIGNED(iova | paddr | size, min_pagesz)) { |
| 236 | pr_err("unaligned: iova 0x%lx pa 0x%lx size 0x%lx min_pagesz " |
| 237 | "0x%x\n", iova, (unsigned long)paddr, |
| 238 | (unsigned long)size, min_pagesz); |
| 239 | return -EINVAL; |
| 240 | } |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 241 | |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 242 | pr_debug("map: iova 0x%lx pa 0x%lx size 0x%lx\n", iova, |
| 243 | (unsigned long)paddr, (unsigned long)size); |
| 244 | |
| 245 | while (size) { |
| 246 | unsigned long pgsize, addr_merge = iova | paddr; |
| 247 | unsigned int pgsize_idx; |
| 248 | |
| 249 | /* Max page size that still fits into 'size' */ |
| 250 | pgsize_idx = __fls(size); |
| 251 | |
| 252 | /* need to consider alignment requirements ? */ |
| 253 | if (likely(addr_merge)) { |
| 254 | /* Max page size allowed by both iova and paddr */ |
| 255 | unsigned int align_pgsize_idx = __ffs(addr_merge); |
| 256 | |
| 257 | pgsize_idx = min(pgsize_idx, align_pgsize_idx); |
| 258 | } |
| 259 | |
| 260 | /* build a mask of acceptable page sizes */ |
| 261 | pgsize = (1UL << (pgsize_idx + 1)) - 1; |
| 262 | |
| 263 | /* throw away page sizes not supported by the hardware */ |
| 264 | pgsize &= domain->ops->pgsize_bitmap; |
| 265 | |
| 266 | /* make sure we're still sane */ |
| 267 | BUG_ON(!pgsize); |
| 268 | |
| 269 | /* pick the biggest page */ |
| 270 | pgsize_idx = __fls(pgsize); |
| 271 | pgsize = 1UL << pgsize_idx; |
| 272 | |
| 273 | pr_debug("mapping: iova 0x%lx pa 0x%lx pgsize %lu\n", iova, |
| 274 | (unsigned long)paddr, pgsize); |
| 275 | |
| 276 | ret = domain->ops->map(domain, iova, paddr, pgsize, prot); |
| 277 | if (ret) |
| 278 | break; |
| 279 | |
| 280 | iova += pgsize; |
| 281 | paddr += pgsize; |
| 282 | size -= pgsize; |
| 283 | } |
| 284 | |
| 285 | /* unroll mapping in case something went wrong */ |
| 286 | if (ret) |
| 287 | iommu_unmap(domain, orig_iova, orig_size - size); |
| 288 | |
| 289 | return ret; |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 290 | } |
| 291 | EXPORT_SYMBOL_GPL(iommu_map); |
| 292 | |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 293 | size_t iommu_unmap(struct iommu_domain *domain, unsigned long iova, size_t size) |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 294 | { |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 295 | size_t unmapped_page, unmapped = 0; |
| 296 | unsigned int min_pagesz; |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 297 | |
Joerg Roedel | e5aa7f0 | 2011-09-06 16:44:29 +0200 | [diff] [blame] | 298 | if (unlikely(domain->ops->unmap == NULL)) |
| 299 | return -ENODEV; |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 300 | |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 301 | /* find out the minimum page size supported */ |
| 302 | min_pagesz = 1 << __ffs(domain->ops->pgsize_bitmap); |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 303 | |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 304 | /* |
| 305 | * The virtual address, as well as the size of the mapping, must be |
| 306 | * aligned (at least) to the size of the smallest page supported |
| 307 | * by the hardware |
| 308 | */ |
| 309 | if (!IS_ALIGNED(iova | size, min_pagesz)) { |
| 310 | pr_err("unaligned: iova 0x%lx size 0x%lx min_pagesz 0x%x\n", |
| 311 | iova, (unsigned long)size, min_pagesz); |
| 312 | return -EINVAL; |
| 313 | } |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 314 | |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 315 | pr_debug("unmap this: iova 0x%lx size 0x%lx\n", iova, |
| 316 | (unsigned long)size); |
Ohad Ben-Cohen | 5009065 | 2011-11-10 11:32:25 +0200 | [diff] [blame] | 317 | |
Ohad Ben-Cohen | 7d3002c | 2011-11-10 11:32:26 +0200 | [diff] [blame] | 318 | /* |
| 319 | * Keep iterating until we either unmap 'size' bytes (or more) |
| 320 | * or we hit an area that isn't mapped. |
| 321 | */ |
| 322 | while (unmapped < size) { |
| 323 | size_t left = size - unmapped; |
| 324 | |
| 325 | unmapped_page = domain->ops->unmap(domain, iova, left); |
| 326 | if (!unmapped_page) |
| 327 | break; |
| 328 | |
| 329 | pr_debug("unmapped: iova 0x%lx size %lx\n", iova, |
| 330 | (unsigned long)unmapped_page); |
| 331 | |
| 332 | iova += unmapped_page; |
| 333 | unmapped += unmapped_page; |
| 334 | } |
| 335 | |
| 336 | return unmapped; |
Joerg Roedel | cefc53c | 2010-01-08 13:35:09 +0100 | [diff] [blame] | 337 | } |
| 338 | EXPORT_SYMBOL_GPL(iommu_unmap); |
Alex Williamson | 1460432 | 2011-10-21 15:56:05 -0400 | [diff] [blame] | 339 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 340 | int iommu_map_range(struct iommu_domain *domain, unsigned int iova, |
| 341 | struct scatterlist *sg, unsigned int len, int prot) |
| 342 | { |
| 343 | if (unlikely(domain->ops->map_range == NULL)) |
| 344 | return -ENODEV; |
| 345 | |
| 346 | BUG_ON(iova & (~PAGE_MASK)); |
| 347 | |
| 348 | return domain->ops->map_range(domain, iova, sg, len, prot); |
| 349 | } |
| 350 | EXPORT_SYMBOL_GPL(iommu_map_range); |
| 351 | |
| 352 | int iommu_unmap_range(struct iommu_domain *domain, unsigned int iova, |
| 353 | unsigned int len) |
| 354 | { |
| 355 | if (unlikely(domain->ops->unmap_range == NULL)) |
| 356 | return -ENODEV; |
| 357 | |
| 358 | BUG_ON(iova & (~PAGE_MASK)); |
| 359 | |
| 360 | return domain->ops->unmap_range(domain, iova, len); |
| 361 | } |
| 362 | EXPORT_SYMBOL_GPL(iommu_unmap_range); |
| 363 | |
| 364 | phys_addr_t iommu_get_pt_base_addr(struct iommu_domain *domain) |
| 365 | { |
| 366 | if (unlikely(domain->ops->get_pt_base_addr == NULL)) |
| 367 | return 0; |
| 368 | |
| 369 | return domain->ops->get_pt_base_addr(domain); |
| 370 | } |
| 371 | EXPORT_SYMBOL_GPL(iommu_get_pt_base_addr); |
| 372 | |
Alex Williamson | 1460432 | 2011-10-21 15:56:05 -0400 | [diff] [blame] | 373 | int iommu_device_group(struct device *dev, unsigned int *groupid) |
| 374 | { |
| 375 | if (iommu_present(dev->bus) && dev->bus->iommu_ops->device_group) |
| 376 | return dev->bus->iommu_ops->device_group(dev, groupid); |
| 377 | |
| 378 | return -ENODEV; |
| 379 | } |
| 380 | EXPORT_SYMBOL_GPL(iommu_device_group); |