iommu.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  1. /*
  2. * Copyright (C) 2001 Mike Corrigan & Dave Engebretsen, IBM Corporation
  3. *
  4. * Rewrite, cleanup:
  5. *
  6. * Copyright (C) 2004 Olof Johansson <olof@lixom.net>, IBM Corporation
  7. * Copyright (C) 2006 Olof Johansson <olof@lixom.net>
  8. *
  9. * Dynamic DMA mapping support, pSeries-specific parts, both SMP and LPAR.
  10. *
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #include <linux/init.h>
  27. #include <linux/types.h>
  28. #include <linux/slab.h>
  29. #include <linux/mm.h>
  30. #include <linux/spinlock.h>
  31. #include <linux/sched.h> /* for show_stack */
  32. #include <linux/string.h>
  33. #include <linux/pci.h>
  34. #include <linux/dma-mapping.h>
  35. #include <linux/crash_dump.h>
  36. #include <linux/memory.h>
  37. #include <asm/io.h>
  38. #include <asm/prom.h>
  39. #include <asm/rtas.h>
  40. #include <asm/iommu.h>
  41. #include <asm/pci-bridge.h>
  42. #include <asm/machdep.h>
  43. #include <asm/abs_addr.h>
  44. #include <asm/pSeries_reconfig.h>
  45. #include <asm/firmware.h>
  46. #include <asm/tce.h>
  47. #include <asm/ppc-pci.h>
  48. #include <asm/udbg.h>
  49. #include <asm/mmzone.h>
  50. #include "plpar_wrappers.h"
  51. static int tce_build_pSeries(struct iommu_table *tbl, long index,
  52. long npages, unsigned long uaddr,
  53. enum dma_data_direction direction,
  54. struct dma_attrs *attrs)
  55. {
  56. u64 proto_tce;
  57. u64 *tcep;
  58. u64 rpn;
  59. proto_tce = TCE_PCI_READ; // Read allowed
  60. if (direction != DMA_TO_DEVICE)
  61. proto_tce |= TCE_PCI_WRITE;
  62. tcep = ((u64 *)tbl->it_base) + index;
  63. while (npages--) {
  64. /* can't move this out since we might cross MEMBLOCK boundary */
  65. rpn = (virt_to_abs(uaddr)) >> TCE_SHIFT;
  66. *tcep = proto_tce | (rpn & TCE_RPN_MASK) << TCE_RPN_SHIFT;
  67. uaddr += TCE_PAGE_SIZE;
  68. tcep++;
  69. }
  70. return 0;
  71. }
  72. static void tce_free_pSeries(struct iommu_table *tbl, long index, long npages)
  73. {
  74. u64 *tcep;
  75. tcep = ((u64 *)tbl->it_base) + index;
  76. while (npages--)
  77. *(tcep++) = 0;
  78. }
  79. static unsigned long tce_get_pseries(struct iommu_table *tbl, long index)
  80. {
  81. u64 *tcep;
  82. tcep = ((u64 *)tbl->it_base) + index;
  83. return *tcep;
  84. }
  85. static void tce_free_pSeriesLP(struct iommu_table*, long, long);
  86. static void tce_freemulti_pSeriesLP(struct iommu_table*, long, long);
  87. static int tce_build_pSeriesLP(struct iommu_table *tbl, long tcenum,
  88. long npages, unsigned long uaddr,
  89. enum dma_data_direction direction,
  90. struct dma_attrs *attrs)
  91. {
  92. u64 rc = 0;
  93. u64 proto_tce, tce;
  94. u64 rpn;
  95. int ret = 0;
  96. long tcenum_start = tcenum, npages_start = npages;
  97. rpn = (virt_to_abs(uaddr)) >> TCE_SHIFT;
  98. proto_tce = TCE_PCI_READ;
  99. if (direction != DMA_TO_DEVICE)
  100. proto_tce |= TCE_PCI_WRITE;
  101. while (npages--) {
  102. tce = proto_tce | (rpn & TCE_RPN_MASK) << TCE_RPN_SHIFT;
  103. rc = plpar_tce_put((u64)tbl->it_index, (u64)tcenum << 12, tce);
  104. if (unlikely(rc == H_NOT_ENOUGH_RESOURCES)) {
  105. ret = (int)rc;
  106. tce_free_pSeriesLP(tbl, tcenum_start,
  107. (npages_start - (npages + 1)));
  108. break;
  109. }
  110. if (rc && printk_ratelimit()) {
  111. printk("tce_build_pSeriesLP: plpar_tce_put failed. rc=%lld\n", rc);
  112. printk("\tindex = 0x%llx\n", (u64)tbl->it_index);
  113. printk("\ttcenum = 0x%llx\n", (u64)tcenum);
  114. printk("\ttce val = 0x%llx\n", tce );
  115. show_stack(current, (unsigned long *)__get_SP());
  116. }
  117. tcenum++;
  118. rpn++;
  119. }
  120. return ret;
  121. }
  122. static DEFINE_PER_CPU(u64 *, tce_page);
  123. static int tce_buildmulti_pSeriesLP(struct iommu_table *tbl, long tcenum,
  124. long npages, unsigned long uaddr,
  125. enum dma_data_direction direction,
  126. struct dma_attrs *attrs)
  127. {
  128. u64 rc = 0;
  129. u64 proto_tce;
  130. u64 *tcep;
  131. u64 rpn;
  132. long l, limit;
  133. long tcenum_start = tcenum, npages_start = npages;
  134. int ret = 0;
  135. if (npages == 1) {
  136. return tce_build_pSeriesLP(tbl, tcenum, npages, uaddr,
  137. direction, attrs);
  138. }
  139. tcep = __get_cpu_var(tce_page);
  140. /* This is safe to do since interrupts are off when we're called
  141. * from iommu_alloc{,_sg}()
  142. */
  143. if (!tcep) {
  144. tcep = (u64 *)__get_free_page(GFP_ATOMIC);
  145. /* If allocation fails, fall back to the loop implementation */
  146. if (!tcep) {
  147. return tce_build_pSeriesLP(tbl, tcenum, npages, uaddr,
  148. direction, attrs);
  149. }
  150. __get_cpu_var(tce_page) = tcep;
  151. }
  152. rpn = (virt_to_abs(uaddr)) >> TCE_SHIFT;
  153. proto_tce = TCE_PCI_READ;
  154. if (direction != DMA_TO_DEVICE)
  155. proto_tce |= TCE_PCI_WRITE;
  156. /* We can map max one pageful of TCEs at a time */
  157. do {
  158. /*
  159. * Set up the page with TCE data, looping through and setting
  160. * the values.
  161. */
  162. limit = min_t(long, npages, 4096/TCE_ENTRY_SIZE);
  163. for (l = 0; l < limit; l++) {
  164. tcep[l] = proto_tce | (rpn & TCE_RPN_MASK) << TCE_RPN_SHIFT;
  165. rpn++;
  166. }
  167. rc = plpar_tce_put_indirect((u64)tbl->it_index,
  168. (u64)tcenum << 12,
  169. (u64)virt_to_abs(tcep),
  170. limit);
  171. npages -= limit;
  172. tcenum += limit;
  173. } while (npages > 0 && !rc);
  174. if (unlikely(rc == H_NOT_ENOUGH_RESOURCES)) {
  175. ret = (int)rc;
  176. tce_freemulti_pSeriesLP(tbl, tcenum_start,
  177. (npages_start - (npages + limit)));
  178. return ret;
  179. }
  180. if (rc && printk_ratelimit()) {
  181. printk("tce_buildmulti_pSeriesLP: plpar_tce_put failed. rc=%lld\n", rc);
  182. printk("\tindex = 0x%llx\n", (u64)tbl->it_index);
  183. printk("\tnpages = 0x%llx\n", (u64)npages);
  184. printk("\ttce[0] val = 0x%llx\n", tcep[0]);
  185. show_stack(current, (unsigned long *)__get_SP());
  186. }
  187. return ret;
  188. }
  189. static void tce_free_pSeriesLP(struct iommu_table *tbl, long tcenum, long npages)
  190. {
  191. u64 rc;
  192. while (npages--) {
  193. rc = plpar_tce_put((u64)tbl->it_index, (u64)tcenum << 12, 0);
  194. if (rc && printk_ratelimit()) {
  195. printk("tce_free_pSeriesLP: plpar_tce_put failed. rc=%lld\n", rc);
  196. printk("\tindex = 0x%llx\n", (u64)tbl->it_index);
  197. printk("\ttcenum = 0x%llx\n", (u64)tcenum);
  198. show_stack(current, (unsigned long *)__get_SP());
  199. }
  200. tcenum++;
  201. }
  202. }
  203. static void tce_freemulti_pSeriesLP(struct iommu_table *tbl, long tcenum, long npages)
  204. {
  205. u64 rc;
  206. rc = plpar_tce_stuff((u64)tbl->it_index, (u64)tcenum << 12, 0, npages);
  207. if (rc && printk_ratelimit()) {
  208. printk("tce_freemulti_pSeriesLP: plpar_tce_stuff failed\n");
  209. printk("\trc = %lld\n", rc);
  210. printk("\tindex = 0x%llx\n", (u64)tbl->it_index);
  211. printk("\tnpages = 0x%llx\n", (u64)npages);
  212. show_stack(current, (unsigned long *)__get_SP());
  213. }
  214. }
  215. static unsigned long tce_get_pSeriesLP(struct iommu_table *tbl, long tcenum)
  216. {
  217. u64 rc;
  218. unsigned long tce_ret;
  219. rc = plpar_tce_get((u64)tbl->it_index, (u64)tcenum << 12, &tce_ret);
  220. if (rc && printk_ratelimit()) {
  221. printk("tce_get_pSeriesLP: plpar_tce_get failed. rc=%lld\n", rc);
  222. printk("\tindex = 0x%llx\n", (u64)tbl->it_index);
  223. printk("\ttcenum = 0x%llx\n", (u64)tcenum);
  224. show_stack(current, (unsigned long *)__get_SP());
  225. }
  226. return tce_ret;
  227. }
  228. /* this is compatible with cells for the device tree property */
  229. struct dynamic_dma_window_prop {
  230. __be32 liobn; /* tce table number */
  231. __be64 dma_base; /* address hi,lo */
  232. __be32 tce_shift; /* ilog2(tce_page_size) */
  233. __be32 window_shift; /* ilog2(tce_window_size) */
  234. };
  235. struct direct_window {
  236. struct device_node *device;
  237. const struct dynamic_dma_window_prop *prop;
  238. struct list_head list;
  239. };
  240. /* Dynamic DMA Window support */
  241. struct ddw_query_response {
  242. u32 windows_available;
  243. u32 largest_available_block;
  244. u32 page_size;
  245. u32 migration_capable;
  246. };
  247. struct ddw_create_response {
  248. u32 liobn;
  249. u32 addr_hi;
  250. u32 addr_lo;
  251. };
  252. static LIST_HEAD(direct_window_list);
  253. /* prevents races between memory on/offline and window creation */
  254. static DEFINE_SPINLOCK(direct_window_list_lock);
  255. /* protects initializing window twice for same device */
  256. static DEFINE_MUTEX(direct_window_init_mutex);
  257. #define DIRECT64_PROPNAME "linux,direct64-ddr-window-info"
  258. static int tce_clearrange_multi_pSeriesLP(unsigned long start_pfn,
  259. unsigned long num_pfn, const void *arg)
  260. {
  261. const struct dynamic_dma_window_prop *maprange = arg;
  262. int rc;
  263. u64 tce_size, num_tce, dma_offset, next;
  264. u32 tce_shift;
  265. long limit;
  266. tce_shift = be32_to_cpu(maprange->tce_shift);
  267. tce_size = 1ULL << tce_shift;
  268. next = start_pfn << PAGE_SHIFT;
  269. num_tce = num_pfn << PAGE_SHIFT;
  270. /* round back to the beginning of the tce page size */
  271. num_tce += next & (tce_size - 1);
  272. next &= ~(tce_size - 1);
  273. /* covert to number of tces */
  274. num_tce |= tce_size - 1;
  275. num_tce >>= tce_shift;
  276. do {
  277. /*
  278. * Set up the page with TCE data, looping through and setting
  279. * the values.
  280. */
  281. limit = min_t(long, num_tce, 512);
  282. dma_offset = next + be64_to_cpu(maprange->dma_base);
  283. rc = plpar_tce_stuff((u64)be32_to_cpu(maprange->liobn),
  284. dma_offset,
  285. 0, limit);
  286. num_tce -= limit;
  287. } while (num_tce > 0 && !rc);
  288. return rc;
  289. }
  290. static int tce_setrange_multi_pSeriesLP(unsigned long start_pfn,
  291. unsigned long num_pfn, const void *arg)
  292. {
  293. const struct dynamic_dma_window_prop *maprange = arg;
  294. u64 *tcep, tce_size, num_tce, dma_offset, next, proto_tce, liobn;
  295. u32 tce_shift;
  296. u64 rc = 0;
  297. long l, limit;
  298. local_irq_disable(); /* to protect tcep and the page behind it */
  299. tcep = __get_cpu_var(tce_page);
  300. if (!tcep) {
  301. tcep = (u64 *)__get_free_page(GFP_ATOMIC);
  302. if (!tcep) {
  303. local_irq_enable();
  304. return -ENOMEM;
  305. }
  306. __get_cpu_var(tce_page) = tcep;
  307. }
  308. proto_tce = TCE_PCI_READ | TCE_PCI_WRITE;
  309. liobn = (u64)be32_to_cpu(maprange->liobn);
  310. tce_shift = be32_to_cpu(maprange->tce_shift);
  311. tce_size = 1ULL << tce_shift;
  312. next = start_pfn << PAGE_SHIFT;
  313. num_tce = num_pfn << PAGE_SHIFT;
  314. /* round back to the beginning of the tce page size */
  315. num_tce += next & (tce_size - 1);
  316. next &= ~(tce_size - 1);
  317. /* covert to number of tces */
  318. num_tce |= tce_size - 1;
  319. num_tce >>= tce_shift;
  320. /* We can map max one pageful of TCEs at a time */
  321. do {
  322. /*
  323. * Set up the page with TCE data, looping through and setting
  324. * the values.
  325. */
  326. limit = min_t(long, num_tce, 4096/TCE_ENTRY_SIZE);
  327. dma_offset = next + be64_to_cpu(maprange->dma_base);
  328. for (l = 0; l < limit; l++) {
  329. tcep[l] = proto_tce | next;
  330. next += tce_size;
  331. }
  332. rc = plpar_tce_put_indirect(liobn,
  333. dma_offset,
  334. (u64)virt_to_abs(tcep),
  335. limit);
  336. num_tce -= limit;
  337. } while (num_tce > 0 && !rc);
  338. /* error cleanup: caller will clear whole range */
  339. local_irq_enable();
  340. return rc;
  341. }
  342. static int tce_setrange_multi_pSeriesLP_walk(unsigned long start_pfn,
  343. unsigned long num_pfn, void *arg)
  344. {
  345. return tce_setrange_multi_pSeriesLP(start_pfn, num_pfn, arg);
  346. }
  347. #ifdef CONFIG_PCI
  348. static void iommu_table_setparms(struct pci_controller *phb,
  349. struct device_node *dn,
  350. struct iommu_table *tbl)
  351. {
  352. struct device_node *node;
  353. const unsigned long *basep;
  354. const u32 *sizep;
  355. node = phb->dn;
  356. basep = of_get_property(node, "linux,tce-base", NULL);
  357. sizep = of_get_property(node, "linux,tce-size", NULL);
  358. if (basep == NULL || sizep == NULL) {
  359. printk(KERN_ERR "PCI_DMA: iommu_table_setparms: %s has "
  360. "missing tce entries !\n", dn->full_name);
  361. return;
  362. }
  363. tbl->it_base = (unsigned long)__va(*basep);
  364. if (!is_kdump_kernel())
  365. memset((void *)tbl->it_base, 0, *sizep);
  366. tbl->it_busno = phb->bus->number;
  367. /* Units of tce entries */
  368. tbl->it_offset = phb->dma_window_base_cur >> IOMMU_PAGE_SHIFT;
  369. /* Test if we are going over 2GB of DMA space */
  370. if (phb->dma_window_base_cur + phb->dma_window_size > 0x80000000ul) {
  371. udbg_printf("PCI_DMA: Unexpected number of IOAs under this PHB.\n");
  372. panic("PCI_DMA: Unexpected number of IOAs under this PHB.\n");
  373. }
  374. phb->dma_window_base_cur += phb->dma_window_size;
  375. /* Set the tce table size - measured in entries */
  376. tbl->it_size = phb->dma_window_size >> IOMMU_PAGE_SHIFT;
  377. tbl->it_index = 0;
  378. tbl->it_blocksize = 16;
  379. tbl->it_type = TCE_PCI;
  380. }
  381. /*
  382. * iommu_table_setparms_lpar
  383. *
  384. * Function: On pSeries LPAR systems, return TCE table info, given a pci bus.
  385. */
  386. static void iommu_table_setparms_lpar(struct pci_controller *phb,
  387. struct device_node *dn,
  388. struct iommu_table *tbl,
  389. const void *dma_window)
  390. {
  391. unsigned long offset, size;
  392. of_parse_dma_window(dn, dma_window, &tbl->it_index, &offset, &size);
  393. tbl->it_busno = phb->bus->number;
  394. tbl->it_base = 0;
  395. tbl->it_blocksize = 16;
  396. tbl->it_type = TCE_PCI;
  397. tbl->it_offset = offset >> IOMMU_PAGE_SHIFT;
  398. tbl->it_size = size >> IOMMU_PAGE_SHIFT;
  399. }
  400. static void pci_dma_bus_setup_pSeries(struct pci_bus *bus)
  401. {
  402. struct device_node *dn;
  403. struct iommu_table *tbl;
  404. struct device_node *isa_dn, *isa_dn_orig;
  405. struct device_node *tmp;
  406. struct pci_dn *pci;
  407. int children;
  408. dn = pci_bus_to_OF_node(bus);
  409. pr_debug("pci_dma_bus_setup_pSeries: setting up bus %s\n", dn->full_name);
  410. if (bus->self) {
  411. /* This is not a root bus, any setup will be done for the
  412. * device-side of the bridge in iommu_dev_setup_pSeries().
  413. */
  414. return;
  415. }
  416. pci = PCI_DN(dn);
  417. /* Check if the ISA bus on the system is under
  418. * this PHB.
  419. */
  420. isa_dn = isa_dn_orig = of_find_node_by_type(NULL, "isa");
  421. while (isa_dn && isa_dn != dn)
  422. isa_dn = isa_dn->parent;
  423. if (isa_dn_orig)
  424. of_node_put(isa_dn_orig);
  425. /* Count number of direct PCI children of the PHB. */
  426. for (children = 0, tmp = dn->child; tmp; tmp = tmp->sibling)
  427. children++;
  428. pr_debug("Children: %d\n", children);
  429. /* Calculate amount of DMA window per slot. Each window must be
  430. * a power of two (due to pci_alloc_consistent requirements).
  431. *
  432. * Keep 256MB aside for PHBs with ISA.
  433. */
  434. if (!isa_dn) {
  435. /* No ISA/IDE - just set window size and return */
  436. pci->phb->dma_window_size = 0x80000000ul; /* To be divided */
  437. while (pci->phb->dma_window_size * children > 0x80000000ul)
  438. pci->phb->dma_window_size >>= 1;
  439. pr_debug("No ISA/IDE, window size is 0x%llx\n",
  440. pci->phb->dma_window_size);
  441. pci->phb->dma_window_base_cur = 0;
  442. return;
  443. }
  444. /* If we have ISA, then we probably have an IDE
  445. * controller too. Allocate a 128MB table but
  446. * skip the first 128MB to avoid stepping on ISA
  447. * space.
  448. */
  449. pci->phb->dma_window_size = 0x8000000ul;
  450. pci->phb->dma_window_base_cur = 0x8000000ul;
  451. tbl = kzalloc_node(sizeof(struct iommu_table), GFP_KERNEL,
  452. pci->phb->node);
  453. iommu_table_setparms(pci->phb, dn, tbl);
  454. pci->iommu_table = iommu_init_table(tbl, pci->phb->node);
  455. /* Divide the rest (1.75GB) among the children */
  456. pci->phb->dma_window_size = 0x80000000ul;
  457. while (pci->phb->dma_window_size * children > 0x70000000ul)
  458. pci->phb->dma_window_size >>= 1;
  459. pr_debug("ISA/IDE, window size is 0x%llx\n", pci->phb->dma_window_size);
  460. }
  461. static void pci_dma_bus_setup_pSeriesLP(struct pci_bus *bus)
  462. {
  463. struct iommu_table *tbl;
  464. struct device_node *dn, *pdn;
  465. struct pci_dn *ppci;
  466. const void *dma_window = NULL;
  467. dn = pci_bus_to_OF_node(bus);
  468. pr_debug("pci_dma_bus_setup_pSeriesLP: setting up bus %s\n",
  469. dn->full_name);
  470. /* Find nearest ibm,dma-window, walking up the device tree */
  471. for (pdn = dn; pdn != NULL; pdn = pdn->parent) {
  472. dma_window = of_get_property(pdn, "ibm,dma-window", NULL);
  473. if (dma_window != NULL)
  474. break;
  475. }
  476. if (dma_window == NULL) {
  477. pr_debug(" no ibm,dma-window property !\n");
  478. return;
  479. }
  480. ppci = PCI_DN(pdn);
  481. pr_debug(" parent is %s, iommu_table: 0x%p\n",
  482. pdn->full_name, ppci->iommu_table);
  483. if (!ppci->iommu_table) {
  484. tbl = kzalloc_node(sizeof(struct iommu_table), GFP_KERNEL,
  485. ppci->phb->node);
  486. iommu_table_setparms_lpar(ppci->phb, pdn, tbl, dma_window);
  487. ppci->iommu_table = iommu_init_table(tbl, ppci->phb->node);
  488. pr_debug(" created table: %p\n", ppci->iommu_table);
  489. }
  490. }
  491. static void pci_dma_dev_setup_pSeries(struct pci_dev *dev)
  492. {
  493. struct device_node *dn;
  494. struct iommu_table *tbl;
  495. pr_debug("pci_dma_dev_setup_pSeries: %s\n", pci_name(dev));
  496. dn = dev->dev.of_node;
  497. /* If we're the direct child of a root bus, then we need to allocate
  498. * an iommu table ourselves. The bus setup code should have setup
  499. * the window sizes already.
  500. */
  501. if (!dev->bus->self) {
  502. struct pci_controller *phb = PCI_DN(dn)->phb;
  503. pr_debug(" --> first child, no bridge. Allocating iommu table.\n");
  504. tbl = kzalloc_node(sizeof(struct iommu_table), GFP_KERNEL,
  505. phb->node);
  506. iommu_table_setparms(phb, dn, tbl);
  507. PCI_DN(dn)->iommu_table = iommu_init_table(tbl, phb->node);
  508. set_iommu_table_base(&dev->dev, PCI_DN(dn)->iommu_table);
  509. return;
  510. }
  511. /* If this device is further down the bus tree, search upwards until
  512. * an already allocated iommu table is found and use that.
  513. */
  514. while (dn && PCI_DN(dn) && PCI_DN(dn)->iommu_table == NULL)
  515. dn = dn->parent;
  516. if (dn && PCI_DN(dn))
  517. set_iommu_table_base(&dev->dev, PCI_DN(dn)->iommu_table);
  518. else
  519. printk(KERN_WARNING "iommu: Device %s has no iommu table\n",
  520. pci_name(dev));
  521. }
  522. static int __read_mostly disable_ddw;
  523. static int __init disable_ddw_setup(char *str)
  524. {
  525. disable_ddw = 1;
  526. printk(KERN_INFO "ppc iommu: disabling ddw.\n");
  527. return 0;
  528. }
  529. early_param("disable_ddw", disable_ddw_setup);
  530. static void remove_ddw(struct device_node *np)
  531. {
  532. struct dynamic_dma_window_prop *dwp;
  533. struct property *win64;
  534. const u32 *ddw_avail;
  535. u64 liobn;
  536. int len, ret;
  537. ddw_avail = of_get_property(np, "ibm,ddw-applicable", &len);
  538. win64 = of_find_property(np, DIRECT64_PROPNAME, NULL);
  539. if (!win64)
  540. return;
  541. if (!ddw_avail || len < 3 * sizeof(u32) || win64->length < sizeof(*dwp))
  542. goto delprop;
  543. dwp = win64->value;
  544. liobn = (u64)be32_to_cpu(dwp->liobn);
  545. /* clear the whole window, note the arg is in kernel pages */
  546. ret = tce_clearrange_multi_pSeriesLP(0,
  547. 1ULL << (be32_to_cpu(dwp->window_shift) - PAGE_SHIFT), dwp);
  548. if (ret)
  549. pr_warning("%s failed to clear tces in window.\n",
  550. np->full_name);
  551. else
  552. pr_debug("%s successfully cleared tces in window.\n",
  553. np->full_name);
  554. ret = rtas_call(ddw_avail[2], 1, 1, NULL, liobn);
  555. if (ret)
  556. pr_warning("%s: failed to remove direct window: rtas returned "
  557. "%d to ibm,remove-pe-dma-window(%x) %llx\n",
  558. np->full_name, ret, ddw_avail[2], liobn);
  559. else
  560. pr_debug("%s: successfully removed direct window: rtas returned "
  561. "%d to ibm,remove-pe-dma-window(%x) %llx\n",
  562. np->full_name, ret, ddw_avail[2], liobn);
  563. delprop:
  564. ret = prom_remove_property(np, win64);
  565. if (ret)
  566. pr_warning("%s: failed to remove direct window property: %d\n",
  567. np->full_name, ret);
  568. }
  569. static u64 find_existing_ddw(struct device_node *pdn)
  570. {
  571. struct direct_window *window;
  572. const struct dynamic_dma_window_prop *direct64;
  573. u64 dma_addr = 0;
  574. spin_lock(&direct_window_list_lock);
  575. /* check if we already created a window and dupe that config if so */
  576. list_for_each_entry(window, &direct_window_list, list) {
  577. if (window->device == pdn) {
  578. direct64 = window->prop;
  579. dma_addr = direct64->dma_base;
  580. break;
  581. }
  582. }
  583. spin_unlock(&direct_window_list_lock);
  584. return dma_addr;
  585. }
  586. static int find_existing_ddw_windows(void)
  587. {
  588. int len;
  589. struct device_node *pdn;
  590. struct direct_window *window;
  591. const struct dynamic_dma_window_prop *direct64;
  592. if (!firmware_has_feature(FW_FEATURE_LPAR))
  593. return 0;
  594. for_each_node_with_property(pdn, DIRECT64_PROPNAME) {
  595. direct64 = of_get_property(pdn, DIRECT64_PROPNAME, &len);
  596. if (!direct64)
  597. continue;
  598. window = kzalloc(sizeof(*window), GFP_KERNEL);
  599. if (!window || len < sizeof(struct dynamic_dma_window_prop)) {
  600. kfree(window);
  601. remove_ddw(pdn);
  602. continue;
  603. }
  604. window->device = pdn;
  605. window->prop = direct64;
  606. spin_lock(&direct_window_list_lock);
  607. list_add(&window->list, &direct_window_list);
  608. spin_unlock(&direct_window_list_lock);
  609. }
  610. return 0;
  611. }
  612. machine_arch_initcall(pseries, find_existing_ddw_windows);
  613. static int query_ddw(struct pci_dev *dev, const u32 *ddw_avail,
  614. struct ddw_query_response *query)
  615. {
  616. struct device_node *dn;
  617. struct pci_dn *pcidn;
  618. u32 cfg_addr;
  619. u64 buid;
  620. int ret;
  621. /*
  622. * Get the config address and phb buid of the PE window.
  623. * Rely on eeh to retrieve this for us.
  624. * Retrieve them from the pci device, not the node with the
  625. * dma-window property
  626. */
  627. dn = pci_device_to_OF_node(dev);
  628. pcidn = PCI_DN(dn);
  629. cfg_addr = pcidn->eeh_config_addr;
  630. if (pcidn->eeh_pe_config_addr)
  631. cfg_addr = pcidn->eeh_pe_config_addr;
  632. buid = pcidn->phb->buid;
  633. ret = rtas_call(ddw_avail[0], 3, 5, (u32 *)query,
  634. cfg_addr, BUID_HI(buid), BUID_LO(buid));
  635. dev_info(&dev->dev, "ibm,query-pe-dma-windows(%x) %x %x %x"
  636. " returned %d\n", ddw_avail[0], cfg_addr, BUID_HI(buid),
  637. BUID_LO(buid), ret);
  638. return ret;
  639. }
  640. static int create_ddw(struct pci_dev *dev, const u32 *ddw_avail,
  641. struct ddw_create_response *create, int page_shift,
  642. int window_shift)
  643. {
  644. struct device_node *dn;
  645. struct pci_dn *pcidn;
  646. u32 cfg_addr;
  647. u64 buid;
  648. int ret;
  649. /*
  650. * Get the config address and phb buid of the PE window.
  651. * Rely on eeh to retrieve this for us.
  652. * Retrieve them from the pci device, not the node with the
  653. * dma-window property
  654. */
  655. dn = pci_device_to_OF_node(dev);
  656. pcidn = PCI_DN(dn);
  657. cfg_addr = pcidn->eeh_config_addr;
  658. if (pcidn->eeh_pe_config_addr)
  659. cfg_addr = pcidn->eeh_pe_config_addr;
  660. buid = pcidn->phb->buid;
  661. do {
  662. /* extra outputs are LIOBN and dma-addr (hi, lo) */
  663. ret = rtas_call(ddw_avail[1], 5, 4, (u32 *)create, cfg_addr,
  664. BUID_HI(buid), BUID_LO(buid), page_shift, window_shift);
  665. } while (rtas_busy_delay(ret));
  666. dev_info(&dev->dev,
  667. "ibm,create-pe-dma-window(%x) %x %x %x %x %x returned %d "
  668. "(liobn = 0x%x starting addr = %x %x)\n", ddw_avail[1],
  669. cfg_addr, BUID_HI(buid), BUID_LO(buid), page_shift,
  670. window_shift, ret, create->liobn, create->addr_hi, create->addr_lo);
  671. return ret;
  672. }
  673. /*
  674. * If the PE supports dynamic dma windows, and there is space for a table
  675. * that can map all pages in a linear offset, then setup such a table,
  676. * and record the dma-offset in the struct device.
  677. *
  678. * dev: the pci device we are checking
  679. * pdn: the parent pe node with the ibm,dma_window property
  680. * Future: also check if we can remap the base window for our base page size
  681. *
  682. * returns the dma offset for use by dma_set_mask
  683. */
  684. static u64 enable_ddw(struct pci_dev *dev, struct device_node *pdn)
  685. {
  686. int len, ret;
  687. struct ddw_query_response query;
  688. struct ddw_create_response create;
  689. int page_shift;
  690. u64 dma_addr, max_addr;
  691. struct device_node *dn;
  692. const u32 *uninitialized_var(ddw_avail);
  693. struct direct_window *window;
  694. struct property *win64;
  695. struct dynamic_dma_window_prop *ddwprop;
  696. mutex_lock(&direct_window_init_mutex);
  697. dma_addr = find_existing_ddw(pdn);
  698. if (dma_addr != 0)
  699. goto out_unlock;
  700. /*
  701. * the ibm,ddw-applicable property holds the tokens for:
  702. * ibm,query-pe-dma-window
  703. * ibm,create-pe-dma-window
  704. * ibm,remove-pe-dma-window
  705. * for the given node in that order.
  706. * the property is actually in the parent, not the PE
  707. */
  708. ddw_avail = of_get_property(pdn, "ibm,ddw-applicable", &len);
  709. if (!ddw_avail || len < 3 * sizeof(u32))
  710. goto out_unlock;
  711. /*
  712. * Query if there is a second window of size to map the
  713. * whole partition. Query returns number of windows, largest
  714. * block assigned to PE (partition endpoint), and two bitmasks
  715. * of page sizes: supported and supported for migrate-dma.
  716. */
  717. dn = pci_device_to_OF_node(dev);
  718. ret = query_ddw(dev, ddw_avail, &query);
  719. if (ret != 0)
  720. goto out_unlock;
  721. if (query.windows_available == 0) {
  722. /*
  723. * no additional windows are available for this device.
  724. * We might be able to reallocate the existing window,
  725. * trading in for a larger page size.
  726. */
  727. dev_dbg(&dev->dev, "no free dynamic windows");
  728. goto out_unlock;
  729. }
  730. if (query.page_size & 4) {
  731. page_shift = 24; /* 16MB */
  732. } else if (query.page_size & 2) {
  733. page_shift = 16; /* 64kB */
  734. } else if (query.page_size & 1) {
  735. page_shift = 12; /* 4kB */
  736. } else {
  737. dev_dbg(&dev->dev, "no supported direct page size in mask %x",
  738. query.page_size);
  739. goto out_unlock;
  740. }
  741. /* verify the window * number of ptes will map the partition */
  742. /* check largest block * page size > max memory hotplug addr */
  743. max_addr = memory_hotplug_max();
  744. if (query.largest_available_block < (max_addr >> page_shift)) {
  745. dev_dbg(&dev->dev, "can't map partiton max 0x%llx with %u "
  746. "%llu-sized pages\n", max_addr, query.largest_available_block,
  747. 1ULL << page_shift);
  748. goto out_unlock;
  749. }
  750. len = order_base_2(max_addr);
  751. win64 = kzalloc(sizeof(struct property), GFP_KERNEL);
  752. if (!win64) {
  753. dev_info(&dev->dev,
  754. "couldn't allocate property for 64bit dma window\n");
  755. goto out_unlock;
  756. }
  757. win64->name = kstrdup(DIRECT64_PROPNAME, GFP_KERNEL);
  758. win64->value = ddwprop = kmalloc(sizeof(*ddwprop), GFP_KERNEL);
  759. win64->length = sizeof(*ddwprop);
  760. if (!win64->name || !win64->value) {
  761. dev_info(&dev->dev,
  762. "couldn't allocate property name and value\n");
  763. goto out_free_prop;
  764. }
  765. ret = create_ddw(dev, ddw_avail, &create, page_shift, len);
  766. if (ret != 0)
  767. goto out_free_prop;
  768. ddwprop->liobn = cpu_to_be32(create.liobn);
  769. ddwprop->dma_base = cpu_to_be64(of_read_number(&create.addr_hi, 2));
  770. ddwprop->tce_shift = cpu_to_be32(page_shift);
  771. ddwprop->window_shift = cpu_to_be32(len);
  772. dev_dbg(&dev->dev, "created tce table LIOBN 0x%x for %s\n",
  773. create.liobn, dn->full_name);
  774. window = kzalloc(sizeof(*window), GFP_KERNEL);
  775. if (!window)
  776. goto out_clear_window;
  777. ret = walk_system_ram_range(0, memblock_end_of_DRAM() >> PAGE_SHIFT,
  778. win64->value, tce_setrange_multi_pSeriesLP_walk);
  779. if (ret) {
  780. dev_info(&dev->dev, "failed to map direct window for %s: %d\n",
  781. dn->full_name, ret);
  782. goto out_free_window;
  783. }
  784. ret = prom_add_property(pdn, win64);
  785. if (ret) {
  786. dev_err(&dev->dev, "unable to add dma window property for %s: %d",
  787. pdn->full_name, ret);
  788. goto out_free_window;
  789. }
  790. window->device = pdn;
  791. window->prop = ddwprop;
  792. spin_lock(&direct_window_list_lock);
  793. list_add(&window->list, &direct_window_list);
  794. spin_unlock(&direct_window_list_lock);
  795. dma_addr = of_read_number(&create.addr_hi, 2);
  796. goto out_unlock;
  797. out_free_window:
  798. kfree(window);
  799. out_clear_window:
  800. remove_ddw(pdn);
  801. out_free_prop:
  802. kfree(win64->name);
  803. kfree(win64->value);
  804. kfree(win64);
  805. out_unlock:
  806. mutex_unlock(&direct_window_init_mutex);
  807. return dma_addr;
  808. }
  809. static void pci_dma_dev_setup_pSeriesLP(struct pci_dev *dev)
  810. {
  811. struct device_node *pdn, *dn;
  812. struct iommu_table *tbl;
  813. const void *dma_window = NULL;
  814. struct pci_dn *pci;
  815. pr_debug("pci_dma_dev_setup_pSeriesLP: %s\n", pci_name(dev));
  816. /* dev setup for LPAR is a little tricky, since the device tree might
  817. * contain the dma-window properties per-device and not necessarily
  818. * for the bus. So we need to search upwards in the tree until we
  819. * either hit a dma-window property, OR find a parent with a table
  820. * already allocated.
  821. */
  822. dn = pci_device_to_OF_node(dev);
  823. pr_debug(" node is %s\n", dn->full_name);
  824. for (pdn = dn; pdn && PCI_DN(pdn) && !PCI_DN(pdn)->iommu_table;
  825. pdn = pdn->parent) {
  826. dma_window = of_get_property(pdn, "ibm,dma-window", NULL);
  827. if (dma_window)
  828. break;
  829. }
  830. if (!pdn || !PCI_DN(pdn)) {
  831. printk(KERN_WARNING "pci_dma_dev_setup_pSeriesLP: "
  832. "no DMA window found for pci dev=%s dn=%s\n",
  833. pci_name(dev), dn? dn->full_name : "<null>");
  834. return;
  835. }
  836. pr_debug(" parent is %s\n", pdn->full_name);
  837. pci = PCI_DN(pdn);
  838. if (!pci->iommu_table) {
  839. tbl = kzalloc_node(sizeof(struct iommu_table), GFP_KERNEL,
  840. pci->phb->node);
  841. iommu_table_setparms_lpar(pci->phb, pdn, tbl, dma_window);
  842. pci->iommu_table = iommu_init_table(tbl, pci->phb->node);
  843. pr_debug(" created table: %p\n", pci->iommu_table);
  844. } else {
  845. pr_debug(" found DMA window, table: %p\n", pci->iommu_table);
  846. }
  847. set_iommu_table_base(&dev->dev, pci->iommu_table);
  848. }
  849. static int dma_set_mask_pSeriesLP(struct device *dev, u64 dma_mask)
  850. {
  851. bool ddw_enabled = false;
  852. struct device_node *pdn, *dn;
  853. struct pci_dev *pdev;
  854. const void *dma_window = NULL;
  855. u64 dma_offset;
  856. if (!dev->dma_mask)
  857. return -EIO;
  858. if (!dev_is_pci(dev))
  859. goto check_mask;
  860. pdev = to_pci_dev(dev);
  861. /* only attempt to use a new window if 64-bit DMA is requested */
  862. if (!disable_ddw && dma_mask == DMA_BIT_MASK(64)) {
  863. dn = pci_device_to_OF_node(pdev);
  864. dev_dbg(dev, "node is %s\n", dn->full_name);
  865. /*
  866. * the device tree might contain the dma-window properties
  867. * per-device and not necessarily for the bus. So we need to
  868. * search upwards in the tree until we either hit a dma-window
  869. * property, OR find a parent with a table already allocated.
  870. */
  871. for (pdn = dn; pdn && PCI_DN(pdn) && !PCI_DN(pdn)->iommu_table;
  872. pdn = pdn->parent) {
  873. dma_window = of_get_property(pdn, "ibm,dma-window", NULL);
  874. if (dma_window)
  875. break;
  876. }
  877. if (pdn && PCI_DN(pdn)) {
  878. dma_offset = enable_ddw(pdev, pdn);
  879. if (dma_offset != 0) {
  880. dev_info(dev, "Using 64-bit direct DMA at offset %llx\n", dma_offset);
  881. set_dma_offset(dev, dma_offset);
  882. set_dma_ops(dev, &dma_direct_ops);
  883. ddw_enabled = true;
  884. }
  885. }
  886. }
  887. /* fall back on iommu ops, restore table pointer with ops */
  888. if (!ddw_enabled && get_dma_ops(dev) != &dma_iommu_ops) {
  889. dev_info(dev, "Restoring 32-bit DMA via iommu\n");
  890. set_dma_ops(dev, &dma_iommu_ops);
  891. pci_dma_dev_setup_pSeriesLP(pdev);
  892. }
  893. check_mask:
  894. if (!dma_supported(dev, dma_mask))
  895. return -EIO;
  896. *dev->dma_mask = dma_mask;
  897. return 0;
  898. }
  899. static u64 dma_get_required_mask_pSeriesLP(struct device *dev)
  900. {
  901. if (!dev->dma_mask)
  902. return 0;
  903. if (!disable_ddw && dev_is_pci(dev)) {
  904. struct pci_dev *pdev = to_pci_dev(dev);
  905. struct device_node *dn;
  906. dn = pci_device_to_OF_node(pdev);
  907. /* search upwards for ibm,dma-window */
  908. for (; dn && PCI_DN(dn) && !PCI_DN(dn)->iommu_table;
  909. dn = dn->parent)
  910. if (of_get_property(dn, "ibm,dma-window", NULL))
  911. break;
  912. /* if there is a ibm,ddw-applicable property require 64 bits */
  913. if (dn && PCI_DN(dn) &&
  914. of_get_property(dn, "ibm,ddw-applicable", NULL))
  915. return DMA_BIT_MASK(64);
  916. }
  917. return dma_iommu_ops.get_required_mask(dev);
  918. }
  919. #else /* CONFIG_PCI */
  920. #define pci_dma_bus_setup_pSeries NULL
  921. #define pci_dma_dev_setup_pSeries NULL
  922. #define pci_dma_bus_setup_pSeriesLP NULL
  923. #define pci_dma_dev_setup_pSeriesLP NULL
  924. #define dma_set_mask_pSeriesLP NULL
  925. #define dma_get_required_mask_pSeriesLP NULL
  926. #endif /* !CONFIG_PCI */
  927. static int iommu_mem_notifier(struct notifier_block *nb, unsigned long action,
  928. void *data)
  929. {
  930. struct direct_window *window;
  931. struct memory_notify *arg = data;
  932. int ret = 0;
  933. switch (action) {
  934. case MEM_GOING_ONLINE:
  935. spin_lock(&direct_window_list_lock);
  936. list_for_each_entry(window, &direct_window_list, list) {
  937. ret |= tce_setrange_multi_pSeriesLP(arg->start_pfn,
  938. arg->nr_pages, window->prop);
  939. /* XXX log error */
  940. }
  941. spin_unlock(&direct_window_list_lock);
  942. break;
  943. case MEM_CANCEL_ONLINE:
  944. case MEM_OFFLINE:
  945. spin_lock(&direct_window_list_lock);
  946. list_for_each_entry(window, &direct_window_list, list) {
  947. ret |= tce_clearrange_multi_pSeriesLP(arg->start_pfn,
  948. arg->nr_pages, window->prop);
  949. /* XXX log error */
  950. }
  951. spin_unlock(&direct_window_list_lock);
  952. break;
  953. default:
  954. break;
  955. }
  956. if (ret && action != MEM_CANCEL_ONLINE)
  957. return NOTIFY_BAD;
  958. return NOTIFY_OK;
  959. }
  960. static struct notifier_block iommu_mem_nb = {
  961. .notifier_call = iommu_mem_notifier,
  962. };
  963. static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node)
  964. {
  965. int err = NOTIFY_OK;
  966. struct device_node *np = node;
  967. struct pci_dn *pci = PCI_DN(np);
  968. struct direct_window *window;
  969. switch (action) {
  970. case PSERIES_RECONFIG_REMOVE:
  971. if (pci && pci->iommu_table)
  972. iommu_free_table(pci->iommu_table, np->full_name);
  973. spin_lock(&direct_window_list_lock);
  974. list_for_each_entry(window, &direct_window_list, list) {
  975. if (window->device == np) {
  976. list_del(&window->list);
  977. kfree(window);
  978. break;
  979. }
  980. }
  981. spin_unlock(&direct_window_list_lock);
  982. /*
  983. * Because the notifier runs after isolation of the
  984. * slot, we are guaranteed any DMA window has already
  985. * been revoked and the TCEs have been marked invalid,
  986. * so we don't need a call to remove_ddw(np). However,
  987. * if an additional notifier action is added before the
  988. * isolate call, we should update this code for
  989. * completeness with such a call.
  990. */
  991. break;
  992. default:
  993. err = NOTIFY_DONE;
  994. break;
  995. }
  996. return err;
  997. }
  998. static struct notifier_block iommu_reconfig_nb = {
  999. .notifier_call = iommu_reconfig_notifier,
  1000. };
  1001. /* These are called very early. */
  1002. void iommu_init_early_pSeries(void)
  1003. {
  1004. if (of_chosen && of_get_property(of_chosen, "linux,iommu-off", NULL))
  1005. return;
  1006. if (firmware_has_feature(FW_FEATURE_LPAR)) {
  1007. if (firmware_has_feature(FW_FEATURE_MULTITCE)) {
  1008. ppc_md.tce_build = tce_buildmulti_pSeriesLP;
  1009. ppc_md.tce_free = tce_freemulti_pSeriesLP;
  1010. } else {
  1011. ppc_md.tce_build = tce_build_pSeriesLP;
  1012. ppc_md.tce_free = tce_free_pSeriesLP;
  1013. }
  1014. ppc_md.tce_get = tce_get_pSeriesLP;
  1015. ppc_md.pci_dma_bus_setup = pci_dma_bus_setup_pSeriesLP;
  1016. ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_pSeriesLP;
  1017. ppc_md.dma_set_mask = dma_set_mask_pSeriesLP;
  1018. ppc_md.dma_get_required_mask = dma_get_required_mask_pSeriesLP;
  1019. } else {
  1020. ppc_md.tce_build = tce_build_pSeries;
  1021. ppc_md.tce_free = tce_free_pSeries;
  1022. ppc_md.tce_get = tce_get_pseries;
  1023. ppc_md.pci_dma_bus_setup = pci_dma_bus_setup_pSeries;
  1024. ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_pSeries;
  1025. }
  1026. pSeries_reconfig_notifier_register(&iommu_reconfig_nb);
  1027. register_memory_notifier(&iommu_mem_nb);
  1028. set_pci_dma_ops(&dma_iommu_ops);
  1029. }
  1030. static int __init disable_multitce(char *str)
  1031. {
  1032. if (strcmp(str, "off") == 0 &&
  1033. firmware_has_feature(FW_FEATURE_LPAR) &&
  1034. firmware_has_feature(FW_FEATURE_MULTITCE)) {
  1035. printk(KERN_INFO "Disabling MULTITCE firmware feature\n");
  1036. ppc_md.tce_build = tce_build_pSeriesLP;
  1037. ppc_md.tce_free = tce_free_pSeriesLP;
  1038. powerpc_firmware_features &= ~FW_FEATURE_MULTITCE;
  1039. }
  1040. return 1;
  1041. }
  1042. __setup("multitce=", disable_multitce);