vfio_iommu_spapr_tce.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. /*
  2. * VFIO: IOMMU DMA mapping support for TCE on POWER
  3. *
  4. * Copyright (C) 2013 IBM Corp. All rights reserved.
  5. * Author: Alexey Kardashevskiy <aik@ozlabs.ru>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * Derived from original vfio_iommu_type1.c:
  12. * Copyright (C) 2012 Red Hat, Inc. All rights reserved.
  13. * Author: Alex Williamson <alex.williamson@redhat.com>
  14. */
  15. #include <linux/module.h>
  16. #include <linux/pci.h>
  17. #include <linux/slab.h>
  18. #include <linux/uaccess.h>
  19. #include <linux/err.h>
  20. #include <linux/vfio.h>
  21. #include <linux/vmalloc.h>
  22. #include <asm/iommu.h>
  23. #include <asm/tce.h>
  24. #include <asm/mmu_context.h>
  25. #define DRIVER_VERSION "0.1"
  26. #define DRIVER_AUTHOR "aik@ozlabs.ru"
  27. #define DRIVER_DESC "VFIO IOMMU SPAPR TCE"
  28. static void tce_iommu_detach_group(void *iommu_data,
  29. struct iommu_group *iommu_group);
  30. static long try_increment_locked_vm(struct mm_struct *mm, long npages)
  31. {
  32. long ret = 0, locked, lock_limit;
  33. if (WARN_ON_ONCE(!mm))
  34. return -EPERM;
  35. if (!npages)
  36. return 0;
  37. down_write(&mm->mmap_sem);
  38. locked = mm->locked_vm + npages;
  39. lock_limit = rlimit(RLIMIT_MEMLOCK) >> PAGE_SHIFT;
  40. if (locked > lock_limit && !capable(CAP_IPC_LOCK))
  41. ret = -ENOMEM;
  42. else
  43. mm->locked_vm += npages;
  44. pr_debug("[%d] RLIMIT_MEMLOCK +%ld %ld/%ld%s\n", current->pid,
  45. npages << PAGE_SHIFT,
  46. mm->locked_vm << PAGE_SHIFT,
  47. rlimit(RLIMIT_MEMLOCK),
  48. ret ? " - exceeded" : "");
  49. up_write(&mm->mmap_sem);
  50. return ret;
  51. }
  52. static void decrement_locked_vm(struct mm_struct *mm, long npages)
  53. {
  54. if (!mm || !npages)
  55. return;
  56. down_write(&mm->mmap_sem);
  57. if (WARN_ON_ONCE(npages > mm->locked_vm))
  58. npages = mm->locked_vm;
  59. mm->locked_vm -= npages;
  60. pr_debug("[%d] RLIMIT_MEMLOCK -%ld %ld/%ld\n", current->pid,
  61. npages << PAGE_SHIFT,
  62. mm->locked_vm << PAGE_SHIFT,
  63. rlimit(RLIMIT_MEMLOCK));
  64. up_write(&mm->mmap_sem);
  65. }
  66. /*
  67. * VFIO IOMMU fd for SPAPR_TCE IOMMU implementation
  68. *
  69. * This code handles mapping and unmapping of user data buffers
  70. * into DMA'ble space using the IOMMU
  71. */
  72. struct tce_iommu_group {
  73. struct list_head next;
  74. struct iommu_group *grp;
  75. };
  76. /*
  77. * A container needs to remember which preregistered region it has
  78. * referenced to do proper cleanup at the userspace process exit.
  79. */
  80. struct tce_iommu_prereg {
  81. struct list_head next;
  82. struct mm_iommu_table_group_mem_t *mem;
  83. };
  84. /*
  85. * The container descriptor supports only a single group per container.
  86. * Required by the API as the container is not supplied with the IOMMU group
  87. * at the moment of initialization.
  88. */
  89. struct tce_container {
  90. struct mutex lock;
  91. bool enabled;
  92. bool v2;
  93. bool def_window_pending;
  94. unsigned long locked_pages;
  95. struct mm_struct *mm;
  96. struct iommu_table *tables[IOMMU_TABLE_GROUP_MAX_TABLES];
  97. struct list_head group_list;
  98. struct list_head prereg_list;
  99. };
  100. static long tce_iommu_mm_set(struct tce_container *container)
  101. {
  102. if (container->mm) {
  103. if (container->mm == current->mm)
  104. return 0;
  105. return -EPERM;
  106. }
  107. BUG_ON(!current->mm);
  108. container->mm = current->mm;
  109. atomic_inc(&container->mm->mm_count);
  110. return 0;
  111. }
  112. static long tce_iommu_prereg_free(struct tce_container *container,
  113. struct tce_iommu_prereg *tcemem)
  114. {
  115. long ret;
  116. ret = mm_iommu_put(container->mm, tcemem->mem);
  117. if (ret)
  118. return ret;
  119. list_del(&tcemem->next);
  120. kfree(tcemem);
  121. return 0;
  122. }
  123. static long tce_iommu_unregister_pages(struct tce_container *container,
  124. __u64 vaddr, __u64 size)
  125. {
  126. struct mm_iommu_table_group_mem_t *mem;
  127. struct tce_iommu_prereg *tcemem;
  128. bool found = false;
  129. if ((vaddr & ~PAGE_MASK) || (size & ~PAGE_MASK))
  130. return -EINVAL;
  131. mem = mm_iommu_find(container->mm, vaddr, size >> PAGE_SHIFT);
  132. if (!mem)
  133. return -ENOENT;
  134. list_for_each_entry(tcemem, &container->prereg_list, next) {
  135. if (tcemem->mem == mem) {
  136. found = true;
  137. break;
  138. }
  139. }
  140. if (!found)
  141. return -ENOENT;
  142. return tce_iommu_prereg_free(container, tcemem);
  143. }
  144. static long tce_iommu_register_pages(struct tce_container *container,
  145. __u64 vaddr, __u64 size)
  146. {
  147. long ret = 0;
  148. struct mm_iommu_table_group_mem_t *mem = NULL;
  149. struct tce_iommu_prereg *tcemem;
  150. unsigned long entries = size >> PAGE_SHIFT;
  151. if ((vaddr & ~PAGE_MASK) || (size & ~PAGE_MASK) ||
  152. ((vaddr + size) < vaddr))
  153. return -EINVAL;
  154. mem = mm_iommu_find(container->mm, vaddr, entries);
  155. if (mem) {
  156. list_for_each_entry(tcemem, &container->prereg_list, next) {
  157. if (tcemem->mem == mem)
  158. return -EBUSY;
  159. }
  160. }
  161. ret = mm_iommu_get(container->mm, vaddr, entries, &mem);
  162. if (ret)
  163. return ret;
  164. tcemem = kzalloc(sizeof(*tcemem), GFP_KERNEL);
  165. if (!tcemem) {
  166. mm_iommu_put(container->mm, mem);
  167. return -ENOMEM;
  168. }
  169. tcemem->mem = mem;
  170. list_add(&tcemem->next, &container->prereg_list);
  171. container->enabled = true;
  172. return 0;
  173. }
  174. static long tce_iommu_userspace_view_alloc(struct iommu_table *tbl,
  175. struct mm_struct *mm)
  176. {
  177. unsigned long cb = _ALIGN_UP(sizeof(tbl->it_userspace[0]) *
  178. tbl->it_size, PAGE_SIZE);
  179. unsigned long *uas;
  180. long ret;
  181. BUG_ON(tbl->it_userspace);
  182. ret = try_increment_locked_vm(mm, cb >> PAGE_SHIFT);
  183. if (ret)
  184. return ret;
  185. uas = vzalloc(cb);
  186. if (!uas) {
  187. decrement_locked_vm(mm, cb >> PAGE_SHIFT);
  188. return -ENOMEM;
  189. }
  190. tbl->it_userspace = uas;
  191. return 0;
  192. }
  193. static void tce_iommu_userspace_view_free(struct iommu_table *tbl,
  194. struct mm_struct *mm)
  195. {
  196. unsigned long cb = _ALIGN_UP(sizeof(tbl->it_userspace[0]) *
  197. tbl->it_size, PAGE_SIZE);
  198. if (!tbl->it_userspace)
  199. return;
  200. vfree(tbl->it_userspace);
  201. tbl->it_userspace = NULL;
  202. decrement_locked_vm(mm, cb >> PAGE_SHIFT);
  203. }
  204. static bool tce_page_is_contained(struct page *page, unsigned page_shift)
  205. {
  206. /*
  207. * Check that the TCE table granularity is not bigger than the size of
  208. * a page we just found. Otherwise the hardware can get access to
  209. * a bigger memory chunk that it should.
  210. */
  211. return (PAGE_SHIFT + compound_order(compound_head(page))) >= page_shift;
  212. }
  213. static inline bool tce_groups_attached(struct tce_container *container)
  214. {
  215. return !list_empty(&container->group_list);
  216. }
  217. static long tce_iommu_find_table(struct tce_container *container,
  218. phys_addr_t ioba, struct iommu_table **ptbl)
  219. {
  220. long i;
  221. for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) {
  222. struct iommu_table *tbl = container->tables[i];
  223. if (tbl) {
  224. unsigned long entry = ioba >> tbl->it_page_shift;
  225. unsigned long start = tbl->it_offset;
  226. unsigned long end = start + tbl->it_size;
  227. if ((start <= entry) && (entry < end)) {
  228. *ptbl = tbl;
  229. return i;
  230. }
  231. }
  232. }
  233. return -1;
  234. }
  235. static int tce_iommu_find_free_table(struct tce_container *container)
  236. {
  237. int i;
  238. for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) {
  239. if (!container->tables[i])
  240. return i;
  241. }
  242. return -ENOSPC;
  243. }
  244. static int tce_iommu_enable(struct tce_container *container)
  245. {
  246. int ret = 0;
  247. unsigned long locked;
  248. struct iommu_table_group *table_group;
  249. struct tce_iommu_group *tcegrp;
  250. if (container->enabled)
  251. return -EBUSY;
  252. /*
  253. * When userspace pages are mapped into the IOMMU, they are effectively
  254. * locked memory, so, theoretically, we need to update the accounting
  255. * of locked pages on each map and unmap. For powerpc, the map unmap
  256. * paths can be very hot, though, and the accounting would kill
  257. * performance, especially since it would be difficult to impossible
  258. * to handle the accounting in real mode only.
  259. *
  260. * To address that, rather than precisely accounting every page, we
  261. * instead account for a worst case on locked memory when the iommu is
  262. * enabled and disabled. The worst case upper bound on locked memory
  263. * is the size of the whole iommu window, which is usually relatively
  264. * small (compared to total memory sizes) on POWER hardware.
  265. *
  266. * Also we don't have a nice way to fail on H_PUT_TCE due to ulimits,
  267. * that would effectively kill the guest at random points, much better
  268. * enforcing the limit based on the max that the guest can map.
  269. *
  270. * Unfortunately at the moment it counts whole tables, no matter how
  271. * much memory the guest has. I.e. for 4GB guest and 4 IOMMU groups
  272. * each with 2GB DMA window, 8GB will be counted here. The reason for
  273. * this is that we cannot tell here the amount of RAM used by the guest
  274. * as this information is only available from KVM and VFIO is
  275. * KVM agnostic.
  276. *
  277. * So we do not allow enabling a container without a group attached
  278. * as there is no way to know how much we should increment
  279. * the locked_vm counter.
  280. */
  281. if (!tce_groups_attached(container))
  282. return -ENODEV;
  283. tcegrp = list_first_entry(&container->group_list,
  284. struct tce_iommu_group, next);
  285. table_group = iommu_group_get_iommudata(tcegrp->grp);
  286. if (!table_group)
  287. return -ENODEV;
  288. if (!table_group->tce32_size)
  289. return -EPERM;
  290. ret = tce_iommu_mm_set(container);
  291. if (ret)
  292. return ret;
  293. locked = table_group->tce32_size >> PAGE_SHIFT;
  294. ret = try_increment_locked_vm(container->mm, locked);
  295. if (ret)
  296. return ret;
  297. container->locked_pages = locked;
  298. container->enabled = true;
  299. return ret;
  300. }
  301. static void tce_iommu_disable(struct tce_container *container)
  302. {
  303. if (!container->enabled)
  304. return;
  305. container->enabled = false;
  306. BUG_ON(!container->mm);
  307. decrement_locked_vm(container->mm, container->locked_pages);
  308. }
  309. static void *tce_iommu_open(unsigned long arg)
  310. {
  311. struct tce_container *container;
  312. if ((arg != VFIO_SPAPR_TCE_IOMMU) && (arg != VFIO_SPAPR_TCE_v2_IOMMU)) {
  313. pr_err("tce_vfio: Wrong IOMMU type\n");
  314. return ERR_PTR(-EINVAL);
  315. }
  316. container = kzalloc(sizeof(*container), GFP_KERNEL);
  317. if (!container)
  318. return ERR_PTR(-ENOMEM);
  319. mutex_init(&container->lock);
  320. INIT_LIST_HEAD_RCU(&container->group_list);
  321. INIT_LIST_HEAD_RCU(&container->prereg_list);
  322. container->v2 = arg == VFIO_SPAPR_TCE_v2_IOMMU;
  323. return container;
  324. }
  325. static int tce_iommu_clear(struct tce_container *container,
  326. struct iommu_table *tbl,
  327. unsigned long entry, unsigned long pages);
  328. static void tce_iommu_free_table(struct tce_container *container,
  329. struct iommu_table *tbl);
  330. static void tce_iommu_release(void *iommu_data)
  331. {
  332. struct tce_container *container = iommu_data;
  333. struct tce_iommu_group *tcegrp;
  334. long i;
  335. while (tce_groups_attached(container)) {
  336. tcegrp = list_first_entry(&container->group_list,
  337. struct tce_iommu_group, next);
  338. tce_iommu_detach_group(iommu_data, tcegrp->grp);
  339. }
  340. /*
  341. * If VFIO created a table, it was not disposed
  342. * by tce_iommu_detach_group() so do it now.
  343. */
  344. for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) {
  345. struct iommu_table *tbl = container->tables[i];
  346. if (!tbl)
  347. continue;
  348. tce_iommu_clear(container, tbl, tbl->it_offset, tbl->it_size);
  349. tce_iommu_free_table(container, tbl);
  350. }
  351. while (!list_empty(&container->prereg_list)) {
  352. struct tce_iommu_prereg *tcemem;
  353. tcemem = list_first_entry(&container->prereg_list,
  354. struct tce_iommu_prereg, next);
  355. WARN_ON_ONCE(tce_iommu_prereg_free(container, tcemem));
  356. }
  357. tce_iommu_disable(container);
  358. if (container->mm)
  359. mmdrop(container->mm);
  360. mutex_destroy(&container->lock);
  361. kfree(container);
  362. }
  363. static void tce_iommu_unuse_page(struct tce_container *container,
  364. unsigned long hpa)
  365. {
  366. struct page *page;
  367. page = pfn_to_page(hpa >> PAGE_SHIFT);
  368. put_page(page);
  369. }
  370. static int tce_iommu_prereg_ua_to_hpa(struct tce_container *container,
  371. unsigned long tce, unsigned long size,
  372. unsigned long *phpa, struct mm_iommu_table_group_mem_t **pmem)
  373. {
  374. long ret = 0;
  375. struct mm_iommu_table_group_mem_t *mem;
  376. mem = mm_iommu_lookup(container->mm, tce, size);
  377. if (!mem)
  378. return -EINVAL;
  379. ret = mm_iommu_ua_to_hpa(mem, tce, phpa);
  380. if (ret)
  381. return -EINVAL;
  382. *pmem = mem;
  383. return 0;
  384. }
  385. static void tce_iommu_unuse_page_v2(struct tce_container *container,
  386. struct iommu_table *tbl, unsigned long entry)
  387. {
  388. struct mm_iommu_table_group_mem_t *mem = NULL;
  389. int ret;
  390. unsigned long hpa = 0;
  391. unsigned long *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl, entry);
  392. if (!pua)
  393. return;
  394. ret = tce_iommu_prereg_ua_to_hpa(container, *pua, IOMMU_PAGE_SIZE(tbl),
  395. &hpa, &mem);
  396. if (ret)
  397. pr_debug("%s: tce %lx at #%lx was not cached, ret=%d\n",
  398. __func__, *pua, entry, ret);
  399. if (mem)
  400. mm_iommu_mapped_dec(mem);
  401. *pua = 0;
  402. }
  403. static int tce_iommu_clear(struct tce_container *container,
  404. struct iommu_table *tbl,
  405. unsigned long entry, unsigned long pages)
  406. {
  407. unsigned long oldhpa;
  408. long ret;
  409. enum dma_data_direction direction;
  410. for ( ; pages; --pages, ++entry) {
  411. direction = DMA_NONE;
  412. oldhpa = 0;
  413. ret = iommu_tce_xchg(tbl, entry, &oldhpa, &direction);
  414. if (ret)
  415. continue;
  416. if (direction == DMA_NONE)
  417. continue;
  418. if (container->v2) {
  419. tce_iommu_unuse_page_v2(container, tbl, entry);
  420. continue;
  421. }
  422. tce_iommu_unuse_page(container, oldhpa);
  423. }
  424. return 0;
  425. }
  426. static int tce_iommu_use_page(unsigned long tce, unsigned long *hpa)
  427. {
  428. struct page *page = NULL;
  429. enum dma_data_direction direction = iommu_tce_direction(tce);
  430. if (get_user_pages_fast(tce & PAGE_MASK, 1,
  431. direction != DMA_TO_DEVICE, &page) != 1)
  432. return -EFAULT;
  433. *hpa = __pa((unsigned long) page_address(page));
  434. return 0;
  435. }
  436. static long tce_iommu_build(struct tce_container *container,
  437. struct iommu_table *tbl,
  438. unsigned long entry, unsigned long tce, unsigned long pages,
  439. enum dma_data_direction direction)
  440. {
  441. long i, ret = 0;
  442. struct page *page;
  443. unsigned long hpa;
  444. enum dma_data_direction dirtmp;
  445. for (i = 0; i < pages; ++i) {
  446. unsigned long offset = tce & IOMMU_PAGE_MASK(tbl) & ~PAGE_MASK;
  447. ret = tce_iommu_use_page(tce, &hpa);
  448. if (ret)
  449. break;
  450. page = pfn_to_page(hpa >> PAGE_SHIFT);
  451. if (!tce_page_is_contained(page, tbl->it_page_shift)) {
  452. ret = -EPERM;
  453. break;
  454. }
  455. hpa |= offset;
  456. dirtmp = direction;
  457. ret = iommu_tce_xchg(tbl, entry + i, &hpa, &dirtmp);
  458. if (ret) {
  459. tce_iommu_unuse_page(container, hpa);
  460. pr_err("iommu_tce: %s failed ioba=%lx, tce=%lx, ret=%ld\n",
  461. __func__, entry << tbl->it_page_shift,
  462. tce, ret);
  463. break;
  464. }
  465. if (dirtmp != DMA_NONE)
  466. tce_iommu_unuse_page(container, hpa);
  467. tce += IOMMU_PAGE_SIZE(tbl);
  468. }
  469. if (ret)
  470. tce_iommu_clear(container, tbl, entry, i);
  471. return ret;
  472. }
  473. static long tce_iommu_build_v2(struct tce_container *container,
  474. struct iommu_table *tbl,
  475. unsigned long entry, unsigned long tce, unsigned long pages,
  476. enum dma_data_direction direction)
  477. {
  478. long i, ret = 0;
  479. struct page *page;
  480. unsigned long hpa;
  481. enum dma_data_direction dirtmp;
  482. if (!tbl->it_userspace) {
  483. ret = tce_iommu_userspace_view_alloc(tbl, container->mm);
  484. if (ret)
  485. return ret;
  486. }
  487. for (i = 0; i < pages; ++i) {
  488. struct mm_iommu_table_group_mem_t *mem = NULL;
  489. unsigned long *pua = IOMMU_TABLE_USERSPACE_ENTRY(tbl,
  490. entry + i);
  491. ret = tce_iommu_prereg_ua_to_hpa(container,
  492. tce, IOMMU_PAGE_SIZE(tbl), &hpa, &mem);
  493. if (ret)
  494. break;
  495. page = pfn_to_page(hpa >> PAGE_SHIFT);
  496. if (!tce_page_is_contained(page, tbl->it_page_shift)) {
  497. ret = -EPERM;
  498. break;
  499. }
  500. /* Preserve offset within IOMMU page */
  501. hpa |= tce & IOMMU_PAGE_MASK(tbl) & ~PAGE_MASK;
  502. dirtmp = direction;
  503. /* The registered region is being unregistered */
  504. if (mm_iommu_mapped_inc(mem))
  505. break;
  506. ret = iommu_tce_xchg(tbl, entry + i, &hpa, &dirtmp);
  507. if (ret) {
  508. /* dirtmp cannot be DMA_NONE here */
  509. tce_iommu_unuse_page_v2(container, tbl, entry + i);
  510. pr_err("iommu_tce: %s failed ioba=%lx, tce=%lx, ret=%ld\n",
  511. __func__, entry << tbl->it_page_shift,
  512. tce, ret);
  513. break;
  514. }
  515. if (dirtmp != DMA_NONE)
  516. tce_iommu_unuse_page_v2(container, tbl, entry + i);
  517. *pua = tce;
  518. tce += IOMMU_PAGE_SIZE(tbl);
  519. }
  520. if (ret)
  521. tce_iommu_clear(container, tbl, entry, i);
  522. return ret;
  523. }
  524. static long tce_iommu_create_table(struct tce_container *container,
  525. struct iommu_table_group *table_group,
  526. int num,
  527. __u32 page_shift,
  528. __u64 window_size,
  529. __u32 levels,
  530. struct iommu_table **ptbl)
  531. {
  532. long ret, table_size;
  533. table_size = table_group->ops->get_table_size(page_shift, window_size,
  534. levels);
  535. if (!table_size)
  536. return -EINVAL;
  537. ret = try_increment_locked_vm(container->mm, table_size >> PAGE_SHIFT);
  538. if (ret)
  539. return ret;
  540. ret = table_group->ops->create_table(table_group, num,
  541. page_shift, window_size, levels, ptbl);
  542. WARN_ON(!ret && !(*ptbl)->it_ops->free);
  543. WARN_ON(!ret && ((*ptbl)->it_allocated_size != table_size));
  544. return ret;
  545. }
  546. static void tce_iommu_free_table(struct tce_container *container,
  547. struct iommu_table *tbl)
  548. {
  549. unsigned long pages = tbl->it_allocated_size >> PAGE_SHIFT;
  550. tce_iommu_userspace_view_free(tbl, container->mm);
  551. tbl->it_ops->free(tbl);
  552. decrement_locked_vm(container->mm, pages);
  553. }
  554. static long tce_iommu_create_window(struct tce_container *container,
  555. __u32 page_shift, __u64 window_size, __u32 levels,
  556. __u64 *start_addr)
  557. {
  558. struct tce_iommu_group *tcegrp;
  559. struct iommu_table_group *table_group;
  560. struct iommu_table *tbl = NULL;
  561. long ret, num;
  562. num = tce_iommu_find_free_table(container);
  563. if (num < 0)
  564. return num;
  565. /* Get the first group for ops::create_table */
  566. tcegrp = list_first_entry(&container->group_list,
  567. struct tce_iommu_group, next);
  568. table_group = iommu_group_get_iommudata(tcegrp->grp);
  569. if (!table_group)
  570. return -EFAULT;
  571. if (!(table_group->pgsizes & (1ULL << page_shift)))
  572. return -EINVAL;
  573. if (!table_group->ops->set_window || !table_group->ops->unset_window ||
  574. !table_group->ops->get_table_size ||
  575. !table_group->ops->create_table)
  576. return -EPERM;
  577. /* Create TCE table */
  578. ret = tce_iommu_create_table(container, table_group, num,
  579. page_shift, window_size, levels, &tbl);
  580. if (ret)
  581. return ret;
  582. BUG_ON(!tbl->it_ops->free);
  583. /*
  584. * Program the table to every group.
  585. * Groups have been tested for compatibility at the attach time.
  586. */
  587. list_for_each_entry(tcegrp, &container->group_list, next) {
  588. table_group = iommu_group_get_iommudata(tcegrp->grp);
  589. ret = table_group->ops->set_window(table_group, num, tbl);
  590. if (ret)
  591. goto unset_exit;
  592. }
  593. container->tables[num] = tbl;
  594. /* Return start address assigned by platform in create_table() */
  595. *start_addr = tbl->it_offset << tbl->it_page_shift;
  596. return 0;
  597. unset_exit:
  598. list_for_each_entry(tcegrp, &container->group_list, next) {
  599. table_group = iommu_group_get_iommudata(tcegrp->grp);
  600. table_group->ops->unset_window(table_group, num);
  601. }
  602. tce_iommu_free_table(container, tbl);
  603. return ret;
  604. }
  605. static long tce_iommu_remove_window(struct tce_container *container,
  606. __u64 start_addr)
  607. {
  608. struct iommu_table_group *table_group = NULL;
  609. struct iommu_table *tbl;
  610. struct tce_iommu_group *tcegrp;
  611. int num;
  612. num = tce_iommu_find_table(container, start_addr, &tbl);
  613. if (num < 0)
  614. return -EINVAL;
  615. BUG_ON(!tbl->it_size);
  616. /* Detach groups from IOMMUs */
  617. list_for_each_entry(tcegrp, &container->group_list, next) {
  618. table_group = iommu_group_get_iommudata(tcegrp->grp);
  619. /*
  620. * SPAPR TCE IOMMU exposes the default DMA window to
  621. * the guest via dma32_window_start/size of
  622. * VFIO_IOMMU_SPAPR_TCE_GET_INFO. Some platforms allow
  623. * the userspace to remove this window, some do not so
  624. * here we check for the platform capability.
  625. */
  626. if (!table_group->ops || !table_group->ops->unset_window)
  627. return -EPERM;
  628. table_group->ops->unset_window(table_group, num);
  629. }
  630. /* Free table */
  631. tce_iommu_clear(container, tbl, tbl->it_offset, tbl->it_size);
  632. tce_iommu_free_table(container, tbl);
  633. container->tables[num] = NULL;
  634. return 0;
  635. }
  636. static long tce_iommu_create_default_window(struct tce_container *container)
  637. {
  638. long ret;
  639. __u64 start_addr = 0;
  640. struct tce_iommu_group *tcegrp;
  641. struct iommu_table_group *table_group;
  642. if (!container->def_window_pending)
  643. return 0;
  644. if (!tce_groups_attached(container))
  645. return -ENODEV;
  646. tcegrp = list_first_entry(&container->group_list,
  647. struct tce_iommu_group, next);
  648. table_group = iommu_group_get_iommudata(tcegrp->grp);
  649. if (!table_group)
  650. return -ENODEV;
  651. ret = tce_iommu_create_window(container, IOMMU_PAGE_SHIFT_4K,
  652. table_group->tce32_size, 1, &start_addr);
  653. WARN_ON_ONCE(!ret && start_addr);
  654. if (!ret)
  655. container->def_window_pending = false;
  656. return ret;
  657. }
  658. static long tce_iommu_ioctl(void *iommu_data,
  659. unsigned int cmd, unsigned long arg)
  660. {
  661. struct tce_container *container = iommu_data;
  662. unsigned long minsz, ddwsz;
  663. long ret;
  664. switch (cmd) {
  665. case VFIO_CHECK_EXTENSION:
  666. switch (arg) {
  667. case VFIO_SPAPR_TCE_IOMMU:
  668. case VFIO_SPAPR_TCE_v2_IOMMU:
  669. ret = 1;
  670. break;
  671. default:
  672. ret = vfio_spapr_iommu_eeh_ioctl(NULL, cmd, arg);
  673. break;
  674. }
  675. return (ret < 0) ? 0 : ret;
  676. }
  677. /*
  678. * Sanity check to prevent one userspace from manipulating
  679. * another userspace mm.
  680. */
  681. BUG_ON(!container);
  682. if (container->mm && container->mm != current->mm)
  683. return -EPERM;
  684. switch (cmd) {
  685. case VFIO_IOMMU_SPAPR_TCE_GET_INFO: {
  686. struct vfio_iommu_spapr_tce_info info;
  687. struct tce_iommu_group *tcegrp;
  688. struct iommu_table_group *table_group;
  689. if (!tce_groups_attached(container))
  690. return -ENXIO;
  691. tcegrp = list_first_entry(&container->group_list,
  692. struct tce_iommu_group, next);
  693. table_group = iommu_group_get_iommudata(tcegrp->grp);
  694. if (!table_group)
  695. return -ENXIO;
  696. minsz = offsetofend(struct vfio_iommu_spapr_tce_info,
  697. dma32_window_size);
  698. if (copy_from_user(&info, (void __user *)arg, minsz))
  699. return -EFAULT;
  700. if (info.argsz < minsz)
  701. return -EINVAL;
  702. info.dma32_window_start = table_group->tce32_start;
  703. info.dma32_window_size = table_group->tce32_size;
  704. info.flags = 0;
  705. memset(&info.ddw, 0, sizeof(info.ddw));
  706. if (table_group->max_dynamic_windows_supported &&
  707. container->v2) {
  708. info.flags |= VFIO_IOMMU_SPAPR_INFO_DDW;
  709. info.ddw.pgsizes = table_group->pgsizes;
  710. info.ddw.max_dynamic_windows_supported =
  711. table_group->max_dynamic_windows_supported;
  712. info.ddw.levels = table_group->max_levels;
  713. }
  714. ddwsz = offsetofend(struct vfio_iommu_spapr_tce_info, ddw);
  715. if (info.argsz >= ddwsz)
  716. minsz = ddwsz;
  717. if (copy_to_user((void __user *)arg, &info, minsz))
  718. return -EFAULT;
  719. return 0;
  720. }
  721. case VFIO_IOMMU_MAP_DMA: {
  722. struct vfio_iommu_type1_dma_map param;
  723. struct iommu_table *tbl = NULL;
  724. long num;
  725. enum dma_data_direction direction;
  726. if (!container->enabled)
  727. return -EPERM;
  728. minsz = offsetofend(struct vfio_iommu_type1_dma_map, size);
  729. if (copy_from_user(&param, (void __user *)arg, minsz))
  730. return -EFAULT;
  731. if (param.argsz < minsz)
  732. return -EINVAL;
  733. if (param.flags & ~(VFIO_DMA_MAP_FLAG_READ |
  734. VFIO_DMA_MAP_FLAG_WRITE))
  735. return -EINVAL;
  736. ret = tce_iommu_create_default_window(container);
  737. if (ret)
  738. return ret;
  739. num = tce_iommu_find_table(container, param.iova, &tbl);
  740. if (num < 0)
  741. return -ENXIO;
  742. if ((param.size & ~IOMMU_PAGE_MASK(tbl)) ||
  743. (param.vaddr & ~IOMMU_PAGE_MASK(tbl)))
  744. return -EINVAL;
  745. /* iova is checked by the IOMMU API */
  746. if (param.flags & VFIO_DMA_MAP_FLAG_READ) {
  747. if (param.flags & VFIO_DMA_MAP_FLAG_WRITE)
  748. direction = DMA_BIDIRECTIONAL;
  749. else
  750. direction = DMA_TO_DEVICE;
  751. } else {
  752. if (param.flags & VFIO_DMA_MAP_FLAG_WRITE)
  753. direction = DMA_FROM_DEVICE;
  754. else
  755. return -EINVAL;
  756. }
  757. ret = iommu_tce_put_param_check(tbl, param.iova, param.vaddr);
  758. if (ret)
  759. return ret;
  760. if (container->v2)
  761. ret = tce_iommu_build_v2(container, tbl,
  762. param.iova >> tbl->it_page_shift,
  763. param.vaddr,
  764. param.size >> tbl->it_page_shift,
  765. direction);
  766. else
  767. ret = tce_iommu_build(container, tbl,
  768. param.iova >> tbl->it_page_shift,
  769. param.vaddr,
  770. param.size >> tbl->it_page_shift,
  771. direction);
  772. iommu_flush_tce(tbl);
  773. return ret;
  774. }
  775. case VFIO_IOMMU_UNMAP_DMA: {
  776. struct vfio_iommu_type1_dma_unmap param;
  777. struct iommu_table *tbl = NULL;
  778. long num;
  779. if (!container->enabled)
  780. return -EPERM;
  781. minsz = offsetofend(struct vfio_iommu_type1_dma_unmap,
  782. size);
  783. if (copy_from_user(&param, (void __user *)arg, minsz))
  784. return -EFAULT;
  785. if (param.argsz < minsz)
  786. return -EINVAL;
  787. /* No flag is supported now */
  788. if (param.flags)
  789. return -EINVAL;
  790. ret = tce_iommu_create_default_window(container);
  791. if (ret)
  792. return ret;
  793. num = tce_iommu_find_table(container, param.iova, &tbl);
  794. if (num < 0)
  795. return -ENXIO;
  796. if (param.size & ~IOMMU_PAGE_MASK(tbl))
  797. return -EINVAL;
  798. ret = iommu_tce_clear_param_check(tbl, param.iova, 0,
  799. param.size >> tbl->it_page_shift);
  800. if (ret)
  801. return ret;
  802. ret = tce_iommu_clear(container, tbl,
  803. param.iova >> tbl->it_page_shift,
  804. param.size >> tbl->it_page_shift);
  805. iommu_flush_tce(tbl);
  806. return ret;
  807. }
  808. case VFIO_IOMMU_SPAPR_REGISTER_MEMORY: {
  809. struct vfio_iommu_spapr_register_memory param;
  810. if (!container->v2)
  811. break;
  812. minsz = offsetofend(struct vfio_iommu_spapr_register_memory,
  813. size);
  814. ret = tce_iommu_mm_set(container);
  815. if (ret)
  816. return ret;
  817. if (copy_from_user(&param, (void __user *)arg, minsz))
  818. return -EFAULT;
  819. if (param.argsz < minsz)
  820. return -EINVAL;
  821. /* No flag is supported now */
  822. if (param.flags)
  823. return -EINVAL;
  824. mutex_lock(&container->lock);
  825. ret = tce_iommu_register_pages(container, param.vaddr,
  826. param.size);
  827. mutex_unlock(&container->lock);
  828. return ret;
  829. }
  830. case VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY: {
  831. struct vfio_iommu_spapr_register_memory param;
  832. if (!container->v2)
  833. break;
  834. if (!container->mm)
  835. return -EPERM;
  836. minsz = offsetofend(struct vfio_iommu_spapr_register_memory,
  837. size);
  838. if (copy_from_user(&param, (void __user *)arg, minsz))
  839. return -EFAULT;
  840. if (param.argsz < minsz)
  841. return -EINVAL;
  842. /* No flag is supported now */
  843. if (param.flags)
  844. return -EINVAL;
  845. mutex_lock(&container->lock);
  846. ret = tce_iommu_unregister_pages(container, param.vaddr,
  847. param.size);
  848. mutex_unlock(&container->lock);
  849. return ret;
  850. }
  851. case VFIO_IOMMU_ENABLE:
  852. if (container->v2)
  853. break;
  854. mutex_lock(&container->lock);
  855. ret = tce_iommu_enable(container);
  856. mutex_unlock(&container->lock);
  857. return ret;
  858. case VFIO_IOMMU_DISABLE:
  859. if (container->v2)
  860. break;
  861. mutex_lock(&container->lock);
  862. tce_iommu_disable(container);
  863. mutex_unlock(&container->lock);
  864. return 0;
  865. case VFIO_EEH_PE_OP: {
  866. struct tce_iommu_group *tcegrp;
  867. ret = 0;
  868. list_for_each_entry(tcegrp, &container->group_list, next) {
  869. ret = vfio_spapr_iommu_eeh_ioctl(tcegrp->grp,
  870. cmd, arg);
  871. if (ret)
  872. return ret;
  873. }
  874. return ret;
  875. }
  876. case VFIO_IOMMU_SPAPR_TCE_CREATE: {
  877. struct vfio_iommu_spapr_tce_create create;
  878. if (!container->v2)
  879. break;
  880. ret = tce_iommu_mm_set(container);
  881. if (ret)
  882. return ret;
  883. if (!tce_groups_attached(container))
  884. return -ENXIO;
  885. minsz = offsetofend(struct vfio_iommu_spapr_tce_create,
  886. start_addr);
  887. if (copy_from_user(&create, (void __user *)arg, minsz))
  888. return -EFAULT;
  889. if (create.argsz < minsz)
  890. return -EINVAL;
  891. if (create.flags)
  892. return -EINVAL;
  893. mutex_lock(&container->lock);
  894. ret = tce_iommu_create_default_window(container);
  895. if (!ret)
  896. ret = tce_iommu_create_window(container,
  897. create.page_shift,
  898. create.window_size, create.levels,
  899. &create.start_addr);
  900. mutex_unlock(&container->lock);
  901. if (!ret && copy_to_user((void __user *)arg, &create, minsz))
  902. ret = -EFAULT;
  903. return ret;
  904. }
  905. case VFIO_IOMMU_SPAPR_TCE_REMOVE: {
  906. struct vfio_iommu_spapr_tce_remove remove;
  907. if (!container->v2)
  908. break;
  909. ret = tce_iommu_mm_set(container);
  910. if (ret)
  911. return ret;
  912. if (!tce_groups_attached(container))
  913. return -ENXIO;
  914. minsz = offsetofend(struct vfio_iommu_spapr_tce_remove,
  915. start_addr);
  916. if (copy_from_user(&remove, (void __user *)arg, minsz))
  917. return -EFAULT;
  918. if (remove.argsz < minsz)
  919. return -EINVAL;
  920. if (remove.flags)
  921. return -EINVAL;
  922. if (container->def_window_pending && !remove.start_addr) {
  923. container->def_window_pending = false;
  924. return 0;
  925. }
  926. mutex_lock(&container->lock);
  927. ret = tce_iommu_remove_window(container, remove.start_addr);
  928. mutex_unlock(&container->lock);
  929. return ret;
  930. }
  931. }
  932. return -ENOTTY;
  933. }
  934. static void tce_iommu_release_ownership(struct tce_container *container,
  935. struct iommu_table_group *table_group)
  936. {
  937. int i;
  938. for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) {
  939. struct iommu_table *tbl = container->tables[i];
  940. if (!tbl)
  941. continue;
  942. tce_iommu_clear(container, tbl, tbl->it_offset, tbl->it_size);
  943. tce_iommu_userspace_view_free(tbl, container->mm);
  944. if (tbl->it_map)
  945. iommu_release_ownership(tbl);
  946. container->tables[i] = NULL;
  947. }
  948. }
  949. static int tce_iommu_take_ownership(struct tce_container *container,
  950. struct iommu_table_group *table_group)
  951. {
  952. int i, j, rc = 0;
  953. for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) {
  954. struct iommu_table *tbl = table_group->tables[i];
  955. if (!tbl || !tbl->it_map)
  956. continue;
  957. rc = iommu_take_ownership(tbl);
  958. if (rc) {
  959. for (j = 0; j < i; ++j)
  960. iommu_release_ownership(
  961. table_group->tables[j]);
  962. return rc;
  963. }
  964. }
  965. for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i)
  966. container->tables[i] = table_group->tables[i];
  967. return 0;
  968. }
  969. static void tce_iommu_release_ownership_ddw(struct tce_container *container,
  970. struct iommu_table_group *table_group)
  971. {
  972. long i;
  973. if (!table_group->ops->unset_window) {
  974. WARN_ON_ONCE(1);
  975. return;
  976. }
  977. for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i)
  978. table_group->ops->unset_window(table_group, i);
  979. table_group->ops->release_ownership(table_group);
  980. }
  981. static long tce_iommu_take_ownership_ddw(struct tce_container *container,
  982. struct iommu_table_group *table_group)
  983. {
  984. long i, ret = 0;
  985. if (!table_group->ops->create_table || !table_group->ops->set_window ||
  986. !table_group->ops->release_ownership) {
  987. WARN_ON_ONCE(1);
  988. return -EFAULT;
  989. }
  990. table_group->ops->take_ownership(table_group);
  991. /* Set all windows to the new group */
  992. for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i) {
  993. struct iommu_table *tbl = container->tables[i];
  994. if (!tbl)
  995. continue;
  996. ret = table_group->ops->set_window(table_group, i, tbl);
  997. if (ret)
  998. goto release_exit;
  999. }
  1000. return 0;
  1001. release_exit:
  1002. for (i = 0; i < IOMMU_TABLE_GROUP_MAX_TABLES; ++i)
  1003. table_group->ops->unset_window(table_group, i);
  1004. table_group->ops->release_ownership(table_group);
  1005. return ret;
  1006. }
  1007. static int tce_iommu_attach_group(void *iommu_data,
  1008. struct iommu_group *iommu_group)
  1009. {
  1010. int ret;
  1011. struct tce_container *container = iommu_data;
  1012. struct iommu_table_group *table_group;
  1013. struct tce_iommu_group *tcegrp = NULL;
  1014. mutex_lock(&container->lock);
  1015. /* pr_debug("tce_vfio: Attaching group #%u to iommu %p\n",
  1016. iommu_group_id(iommu_group), iommu_group); */
  1017. table_group = iommu_group_get_iommudata(iommu_group);
  1018. if (!table_group) {
  1019. ret = -ENODEV;
  1020. goto unlock_exit;
  1021. }
  1022. if (tce_groups_attached(container) && (!table_group->ops ||
  1023. !table_group->ops->take_ownership ||
  1024. !table_group->ops->release_ownership)) {
  1025. ret = -EBUSY;
  1026. goto unlock_exit;
  1027. }
  1028. /* Check if new group has the same iommu_ops (i.e. compatible) */
  1029. list_for_each_entry(tcegrp, &container->group_list, next) {
  1030. struct iommu_table_group *table_group_tmp;
  1031. if (tcegrp->grp == iommu_group) {
  1032. pr_warn("tce_vfio: Group %d is already attached\n",
  1033. iommu_group_id(iommu_group));
  1034. ret = -EBUSY;
  1035. goto unlock_exit;
  1036. }
  1037. table_group_tmp = iommu_group_get_iommudata(tcegrp->grp);
  1038. if (table_group_tmp->ops->create_table !=
  1039. table_group->ops->create_table) {
  1040. pr_warn("tce_vfio: Group %d is incompatible with group %d\n",
  1041. iommu_group_id(iommu_group),
  1042. iommu_group_id(tcegrp->grp));
  1043. ret = -EPERM;
  1044. goto unlock_exit;
  1045. }
  1046. }
  1047. tcegrp = kzalloc(sizeof(*tcegrp), GFP_KERNEL);
  1048. if (!tcegrp) {
  1049. ret = -ENOMEM;
  1050. goto unlock_exit;
  1051. }
  1052. if (!table_group->ops || !table_group->ops->take_ownership ||
  1053. !table_group->ops->release_ownership) {
  1054. if (container->v2) {
  1055. ret = -EPERM;
  1056. goto unlock_exit;
  1057. }
  1058. ret = tce_iommu_take_ownership(container, table_group);
  1059. } else {
  1060. if (!container->v2) {
  1061. ret = -EPERM;
  1062. goto unlock_exit;
  1063. }
  1064. ret = tce_iommu_take_ownership_ddw(container, table_group);
  1065. if (!tce_groups_attached(container) && !container->tables[0])
  1066. container->def_window_pending = true;
  1067. }
  1068. if (!ret) {
  1069. tcegrp->grp = iommu_group;
  1070. list_add(&tcegrp->next, &container->group_list);
  1071. }
  1072. unlock_exit:
  1073. if (ret && tcegrp)
  1074. kfree(tcegrp);
  1075. mutex_unlock(&container->lock);
  1076. return ret;
  1077. }
  1078. static void tce_iommu_detach_group(void *iommu_data,
  1079. struct iommu_group *iommu_group)
  1080. {
  1081. struct tce_container *container = iommu_data;
  1082. struct iommu_table_group *table_group;
  1083. bool found = false;
  1084. struct tce_iommu_group *tcegrp;
  1085. mutex_lock(&container->lock);
  1086. list_for_each_entry(tcegrp, &container->group_list, next) {
  1087. if (tcegrp->grp == iommu_group) {
  1088. found = true;
  1089. break;
  1090. }
  1091. }
  1092. if (!found) {
  1093. pr_warn("tce_vfio: detaching unattached group #%u\n",
  1094. iommu_group_id(iommu_group));
  1095. goto unlock_exit;
  1096. }
  1097. list_del(&tcegrp->next);
  1098. kfree(tcegrp);
  1099. table_group = iommu_group_get_iommudata(iommu_group);
  1100. BUG_ON(!table_group);
  1101. if (!table_group->ops || !table_group->ops->release_ownership)
  1102. tce_iommu_release_ownership(container, table_group);
  1103. else
  1104. tce_iommu_release_ownership_ddw(container, table_group);
  1105. unlock_exit:
  1106. mutex_unlock(&container->lock);
  1107. }
  1108. const struct vfio_iommu_driver_ops tce_iommu_driver_ops = {
  1109. .name = "iommu-vfio-powerpc",
  1110. .owner = THIS_MODULE,
  1111. .open = tce_iommu_open,
  1112. .release = tce_iommu_release,
  1113. .ioctl = tce_iommu_ioctl,
  1114. .attach_group = tce_iommu_attach_group,
  1115. .detach_group = tce_iommu_detach_group,
  1116. };
  1117. static int __init tce_iommu_init(void)
  1118. {
  1119. return vfio_register_iommu_driver(&tce_iommu_driver_ops);
  1120. }
  1121. static void __exit tce_iommu_cleanup(void)
  1122. {
  1123. vfio_unregister_iommu_driver(&tce_iommu_driver_ops);
  1124. }
  1125. module_init(tce_iommu_init);
  1126. module_exit(tce_iommu_cleanup);
  1127. MODULE_VERSION(DRIVER_VERSION);
  1128. MODULE_LICENSE("GPL v2");
  1129. MODULE_AUTHOR(DRIVER_AUTHOR);
  1130. MODULE_DESCRIPTION(DRIVER_DESC);