vfio_iommu_spapr_tce.c 33 KB

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