aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/platforms/pseries/iommu.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/powerpc/platforms/pseries/iommu.c')
-rw-r--r--arch/powerpc/platforms/pseries/iommu.c117
1 files changed, 50 insertions, 67 deletions
diff --git a/arch/powerpc/platforms/pseries/iommu.c b/arch/powerpc/platforms/pseries/iommu.c
index d24ba547e53f..3c95392f4f41 100644
--- a/arch/powerpc/platforms/pseries/iommu.c
+++ b/arch/powerpc/platforms/pseries/iommu.c
@@ -57,9 +57,6 @@ static void tce_build_pSeries(struct iommu_table *tbl, long index,
57 u64 *tcep; 57 u64 *tcep;
58 u64 rpn; 58 u64 rpn;
59 59
60 index <<= TCE_PAGE_FACTOR;
61 npages <<= TCE_PAGE_FACTOR;
62
63 proto_tce = TCE_PCI_READ; // Read allowed 60 proto_tce = TCE_PCI_READ; // Read allowed
64 61
65 if (direction != DMA_TO_DEVICE) 62 if (direction != DMA_TO_DEVICE)
@@ -82,9 +79,6 @@ static void tce_free_pSeries(struct iommu_table *tbl, long index, long npages)
82{ 79{
83 u64 *tcep; 80 u64 *tcep;
84 81
85 npages <<= TCE_PAGE_FACTOR;
86 index <<= TCE_PAGE_FACTOR;
87
88 tcep = ((u64 *)tbl->it_base) + index; 82 tcep = ((u64 *)tbl->it_base) + index;
89 83
90 while (npages--) 84 while (npages--)
@@ -95,7 +89,6 @@ static unsigned long tce_get_pseries(struct iommu_table *tbl, long index)
95{ 89{
96 u64 *tcep; 90 u64 *tcep;
97 91
98 index <<= TCE_PAGE_FACTOR;
99 tcep = ((u64 *)tbl->it_base) + index; 92 tcep = ((u64 *)tbl->it_base) + index;
100 93
101 return *tcep; 94 return *tcep;
@@ -109,9 +102,6 @@ static void tce_build_pSeriesLP(struct iommu_table *tbl, long tcenum,
109 u64 proto_tce, tce; 102 u64 proto_tce, tce;
110 u64 rpn; 103 u64 rpn;
111 104
112 tcenum <<= TCE_PAGE_FACTOR;
113 npages <<= TCE_PAGE_FACTOR;
114
115 rpn = (virt_to_abs(uaddr)) >> TCE_SHIFT; 105 rpn = (virt_to_abs(uaddr)) >> TCE_SHIFT;
116 proto_tce = TCE_PCI_READ; 106 proto_tce = TCE_PCI_READ;
117 if (direction != DMA_TO_DEVICE) 107 if (direction != DMA_TO_DEVICE)
@@ -146,7 +136,7 @@ static void tce_buildmulti_pSeriesLP(struct iommu_table *tbl, long tcenum,
146 u64 rpn; 136 u64 rpn;
147 long l, limit; 137 long l, limit;
148 138
149 if (TCE_PAGE_FACTOR == 0 && npages == 1) 139 if (npages == 1)
150 return tce_build_pSeriesLP(tbl, tcenum, npages, uaddr, 140 return tce_build_pSeriesLP(tbl, tcenum, npages, uaddr,
151 direction); 141 direction);
152 142
@@ -164,9 +154,6 @@ static void tce_buildmulti_pSeriesLP(struct iommu_table *tbl, long tcenum,
164 __get_cpu_var(tce_page) = tcep; 154 __get_cpu_var(tce_page) = tcep;
165 } 155 }
166 156
167 tcenum <<= TCE_PAGE_FACTOR;
168 npages <<= TCE_PAGE_FACTOR;
169
170 rpn = (virt_to_abs(uaddr)) >> TCE_SHIFT; 157 rpn = (virt_to_abs(uaddr)) >> TCE_SHIFT;
171 proto_tce = TCE_PCI_READ; 158 proto_tce = TCE_PCI_READ;
172 if (direction != DMA_TO_DEVICE) 159 if (direction != DMA_TO_DEVICE)
@@ -207,9 +194,6 @@ static void tce_free_pSeriesLP(struct iommu_table *tbl, long tcenum, long npages
207{ 194{
208 u64 rc; 195 u64 rc;
209 196
210 tcenum <<= TCE_PAGE_FACTOR;
211 npages <<= TCE_PAGE_FACTOR;
212
213 while (npages--) { 197 while (npages--) {
214 rc = plpar_tce_put((u64)tbl->it_index, (u64)tcenum << 12, 0); 198 rc = plpar_tce_put((u64)tbl->it_index, (u64)tcenum << 12, 0);
215 199
@@ -229,9 +213,6 @@ static void tce_freemulti_pSeriesLP(struct iommu_table *tbl, long tcenum, long n
229{ 213{
230 u64 rc; 214 u64 rc;
231 215
232 tcenum <<= TCE_PAGE_FACTOR;
233 npages <<= TCE_PAGE_FACTOR;
234
235 rc = plpar_tce_stuff((u64)tbl->it_index, (u64)tcenum << 12, 0, npages); 216 rc = plpar_tce_stuff((u64)tbl->it_index, (u64)tcenum << 12, 0, npages);
236 217
237 if (rc && printk_ratelimit()) { 218 if (rc && printk_ratelimit()) {
@@ -248,7 +229,6 @@ static unsigned long tce_get_pSeriesLP(struct iommu_table *tbl, long tcenum)
248 u64 rc; 229 u64 rc;
249 unsigned long tce_ret; 230 unsigned long tce_ret;
250 231
251 tcenum <<= TCE_PAGE_FACTOR;
252 rc = plpar_tce_get((u64)tbl->it_index, (u64)tcenum << 12, &tce_ret); 232 rc = plpar_tce_get((u64)tbl->it_index, (u64)tcenum << 12, &tce_ret);
253 233
254 if (rc && printk_ratelimit()) { 234 if (rc && printk_ratelimit()) {
@@ -289,7 +269,7 @@ static void iommu_table_setparms(struct pci_controller *phb,
289 tbl->it_busno = phb->bus->number; 269 tbl->it_busno = phb->bus->number;
290 270
291 /* Units of tce entries */ 271 /* Units of tce entries */
292 tbl->it_offset = phb->dma_window_base_cur >> PAGE_SHIFT; 272 tbl->it_offset = phb->dma_window_base_cur >> IOMMU_PAGE_SHIFT;
293 273
294 /* Test if we are going over 2GB of DMA space */ 274 /* Test if we are going over 2GB of DMA space */
295 if (phb->dma_window_base_cur + phb->dma_window_size > 0x80000000ul) { 275 if (phb->dma_window_base_cur + phb->dma_window_size > 0x80000000ul) {
@@ -300,7 +280,7 @@ static void iommu_table_setparms(struct pci_controller *phb,
300 phb->dma_window_base_cur += phb->dma_window_size; 280 phb->dma_window_base_cur += phb->dma_window_size;
301 281
302 /* Set the tce table size - measured in entries */ 282 /* Set the tce table size - measured in entries */
303 tbl->it_size = phb->dma_window_size >> PAGE_SHIFT; 283 tbl->it_size = phb->dma_window_size >> IOMMU_PAGE_SHIFT;
304 284
305 tbl->it_index = 0; 285 tbl->it_index = 0;
306 tbl->it_blocksize = 16; 286 tbl->it_blocksize = 16;
@@ -325,11 +305,11 @@ static void iommu_table_setparms_lpar(struct pci_controller *phb,
325 tbl->it_base = 0; 305 tbl->it_base = 0;
326 tbl->it_blocksize = 16; 306 tbl->it_blocksize = 16;
327 tbl->it_type = TCE_PCI; 307 tbl->it_type = TCE_PCI;
328 tbl->it_offset = offset >> PAGE_SHIFT; 308 tbl->it_offset = offset >> IOMMU_PAGE_SHIFT;
329 tbl->it_size = size >> PAGE_SHIFT; 309 tbl->it_size = size >> IOMMU_PAGE_SHIFT;
330} 310}
331 311
332static void iommu_bus_setup_pSeries(struct pci_bus *bus) 312static void pci_dma_bus_setup_pSeries(struct pci_bus *bus)
333{ 313{
334 struct device_node *dn; 314 struct device_node *dn;
335 struct iommu_table *tbl; 315 struct iommu_table *tbl;
@@ -338,10 +318,9 @@ static void iommu_bus_setup_pSeries(struct pci_bus *bus)
338 struct pci_dn *pci; 318 struct pci_dn *pci;
339 int children; 319 int children;
340 320
341 DBG("iommu_bus_setup_pSeries, bus %p, bus->self %p\n", bus, bus->self);
342
343 dn = pci_bus_to_OF_node(bus); 321 dn = pci_bus_to_OF_node(bus);
344 pci = PCI_DN(dn); 322
323 DBG("pci_dma_bus_setup_pSeries: setting up bus %s\n", dn->full_name);
345 324
346 if (bus->self) { 325 if (bus->self) {
347 /* This is not a root bus, any setup will be done for the 326 /* This is not a root bus, any setup will be done for the
@@ -349,6 +328,7 @@ static void iommu_bus_setup_pSeries(struct pci_bus *bus)
349 */ 328 */
350 return; 329 return;
351 } 330 }
331 pci = PCI_DN(dn);
352 332
353 /* Check if the ISA bus on the system is under 333 /* Check if the ISA bus on the system is under
354 * this PHB. 334 * this PHB.
@@ -410,17 +390,17 @@ static void iommu_bus_setup_pSeries(struct pci_bus *bus)
410} 390}
411 391
412 392
413static void iommu_bus_setup_pSeriesLP(struct pci_bus *bus) 393static void pci_dma_bus_setup_pSeriesLP(struct pci_bus *bus)
414{ 394{
415 struct iommu_table *tbl; 395 struct iommu_table *tbl;
416 struct device_node *dn, *pdn; 396 struct device_node *dn, *pdn;
417 struct pci_dn *ppci; 397 struct pci_dn *ppci;
418 const void *dma_window = NULL; 398 const void *dma_window = NULL;
419 399
420 DBG("iommu_bus_setup_pSeriesLP, bus %p, bus->self %p\n", bus, bus->self);
421
422 dn = pci_bus_to_OF_node(bus); 400 dn = pci_bus_to_OF_node(bus);
423 401
402 DBG("pci_dma_bus_setup_pSeriesLP: setting up bus %s\n", dn->full_name);
403
424 /* Find nearest ibm,dma-window, walking up the device tree */ 404 /* Find nearest ibm,dma-window, walking up the device tree */
425 for (pdn = dn; pdn != NULL; pdn = pdn->parent) { 405 for (pdn = dn; pdn != NULL; pdn = pdn->parent) {
426 dma_window = get_property(pdn, "ibm,dma-window", NULL); 406 dma_window = get_property(pdn, "ibm,dma-window", NULL);
@@ -429,11 +409,15 @@ static void iommu_bus_setup_pSeriesLP(struct pci_bus *bus)
429 } 409 }
430 410
431 if (dma_window == NULL) { 411 if (dma_window == NULL) {
432 DBG("iommu_bus_setup_pSeriesLP: bus %s seems to have no ibm,dma-window property\n", dn->full_name); 412 DBG(" no ibm,dma-window property !\n");
433 return; 413 return;
434 } 414 }
435 415
436 ppci = PCI_DN(pdn); 416 ppci = PCI_DN(pdn);
417
418 DBG(" parent is %s, iommu_table: 0x%p\n",
419 pdn->full_name, ppci->iommu_table);
420
437 if (!ppci->iommu_table) { 421 if (!ppci->iommu_table) {
438 /* Bussubno hasn't been copied yet. 422 /* Bussubno hasn't been copied yet.
439 * Do it now because iommu_table_setparms_lpar needs it. 423 * Do it now because iommu_table_setparms_lpar needs it.
@@ -447,6 +431,7 @@ static void iommu_bus_setup_pSeriesLP(struct pci_bus *bus)
447 iommu_table_setparms_lpar(ppci->phb, pdn, tbl, dma_window); 431 iommu_table_setparms_lpar(ppci->phb, pdn, tbl, dma_window);
448 432
449 ppci->iommu_table = iommu_init_table(tbl, ppci->phb->node); 433 ppci->iommu_table = iommu_init_table(tbl, ppci->phb->node);
434 DBG(" created table: %p\n", ppci->iommu_table);
450 } 435 }
451 436
452 if (pdn != dn) 437 if (pdn != dn)
@@ -454,27 +439,27 @@ static void iommu_bus_setup_pSeriesLP(struct pci_bus *bus)
454} 439}
455 440
456 441
457static void iommu_dev_setup_pSeries(struct pci_dev *dev) 442static void pci_dma_dev_setup_pSeries(struct pci_dev *dev)
458{ 443{
459 struct device_node *dn, *mydn; 444 struct device_node *dn;
460 struct iommu_table *tbl; 445 struct iommu_table *tbl;
461 446
462 DBG("iommu_dev_setup_pSeries, dev %p (%s)\n", dev, pci_name(dev)); 447 DBG("pci_dma_dev_setup_pSeries: %s\n", pci_name(dev));
463 448
464 mydn = dn = pci_device_to_OF_node(dev); 449 dn = dev->dev.archdata.of_node;
465 450
466 /* If we're the direct child of a root bus, then we need to allocate 451 /* If we're the direct child of a root bus, then we need to allocate
467 * an iommu table ourselves. The bus setup code should have setup 452 * an iommu table ourselves. The bus setup code should have setup
468 * the window sizes already. 453 * the window sizes already.
469 */ 454 */
470 if (!dev->bus->self) { 455 if (!dev->bus->self) {
456 struct pci_controller *phb = PCI_DN(dn)->phb;
457
471 DBG(" --> first child, no bridge. Allocating iommu table.\n"); 458 DBG(" --> first child, no bridge. Allocating iommu table.\n");
472 tbl = kmalloc_node(sizeof(struct iommu_table), GFP_KERNEL, 459 tbl = kmalloc_node(sizeof(struct iommu_table), GFP_KERNEL,
473 PCI_DN(dn)->phb->node); 460 phb->node);
474 iommu_table_setparms(PCI_DN(dn)->phb, dn, tbl); 461 iommu_table_setparms(phb, dn, tbl);
475 PCI_DN(dn)->iommu_table = iommu_init_table(tbl, 462 dev->dev.archdata.dma_data = iommu_init_table(tbl, phb->node);
476 PCI_DN(dn)->phb->node);
477
478 return; 463 return;
479 } 464 }
480 465
@@ -485,11 +470,11 @@ static void iommu_dev_setup_pSeries(struct pci_dev *dev)
485 while (dn && PCI_DN(dn) && PCI_DN(dn)->iommu_table == NULL) 470 while (dn && PCI_DN(dn) && PCI_DN(dn)->iommu_table == NULL)
486 dn = dn->parent; 471 dn = dn->parent;
487 472
488 if (dn && PCI_DN(dn)) { 473 if (dn && PCI_DN(dn))
489 PCI_DN(mydn)->iommu_table = PCI_DN(dn)->iommu_table; 474 dev->dev.archdata.dma_data = PCI_DN(dn)->iommu_table;
490 } else { 475 else
491 DBG("iommu_dev_setup_pSeries, dev %p (%s) has no iommu table\n", dev, pci_name(dev)); 476 printk(KERN_WARNING "iommu: Device %s has no iommu table\n",
492 } 477 pci_name(dev));
493} 478}
494 479
495static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node) 480static int iommu_reconfig_notifier(struct notifier_block *nb, unsigned long action, void *node)
@@ -515,14 +500,14 @@ static struct notifier_block iommu_reconfig_nb = {
515 .notifier_call = iommu_reconfig_notifier, 500 .notifier_call = iommu_reconfig_notifier,
516}; 501};
517 502
518static void iommu_dev_setup_pSeriesLP(struct pci_dev *dev) 503static void pci_dma_dev_setup_pSeriesLP(struct pci_dev *dev)
519{ 504{
520 struct device_node *pdn, *dn; 505 struct device_node *pdn, *dn;
521 struct iommu_table *tbl; 506 struct iommu_table *tbl;
522 const void *dma_window = NULL; 507 const void *dma_window = NULL;
523 struct pci_dn *pci; 508 struct pci_dn *pci;
524 509
525 DBG("iommu_dev_setup_pSeriesLP, dev %p (%s)\n", dev, pci_name(dev)); 510 DBG("pci_dma_dev_setup_pSeriesLP: %s\n", pci_name(dev));
526 511
527 /* dev setup for LPAR is a little tricky, since the device tree might 512 /* dev setup for LPAR is a little tricky, since the device tree might
528 * contain the dma-window properties per-device and not neccesarily 513 * contain the dma-window properties per-device and not neccesarily
@@ -531,6 +516,7 @@ static void iommu_dev_setup_pSeriesLP(struct pci_dev *dev)
531 * already allocated. 516 * already allocated.
532 */ 517 */
533 dn = pci_device_to_OF_node(dev); 518 dn = pci_device_to_OF_node(dev);
519 DBG(" node is %s\n", dn->full_name);
534 520
535 for (pdn = dn; pdn && PCI_DN(pdn) && !PCI_DN(pdn)->iommu_table; 521 for (pdn = dn; pdn && PCI_DN(pdn) && !PCI_DN(pdn)->iommu_table;
536 pdn = pdn->parent) { 522 pdn = pdn->parent) {
@@ -539,16 +525,17 @@ static void iommu_dev_setup_pSeriesLP(struct pci_dev *dev)
539 break; 525 break;
540 } 526 }
541 527
528 DBG(" parent is %s\n", pdn->full_name);
529
542 /* Check for parent == NULL so we don't try to setup the empty EADS 530 /* Check for parent == NULL so we don't try to setup the empty EADS
543 * slots on POWER4 machines. 531 * slots on POWER4 machines.
544 */ 532 */
545 if (dma_window == NULL || pdn->parent == NULL) { 533 if (dma_window == NULL || pdn->parent == NULL) {
546 DBG("No dma window for device, linking to parent\n"); 534 DBG(" no dma window for device, linking to parent\n");
547 PCI_DN(dn)->iommu_table = PCI_DN(pdn)->iommu_table; 535 dev->dev.archdata.dma_data = PCI_DN(pdn)->iommu_table;
548 return; 536 return;
549 } else {
550 DBG("Found DMA window, allocating table\n");
551 } 537 }
538 DBG(" found DMA window, table: %p\n", pci->iommu_table);
552 539
553 pci = PCI_DN(pdn); 540 pci = PCI_DN(pdn);
554 if (!pci->iommu_table) { 541 if (!pci->iommu_table) {
@@ -561,24 +548,20 @@ static void iommu_dev_setup_pSeriesLP(struct pci_dev *dev)
561 iommu_table_setparms_lpar(pci->phb, pdn, tbl, dma_window); 548 iommu_table_setparms_lpar(pci->phb, pdn, tbl, dma_window);
562 549
563 pci->iommu_table = iommu_init_table(tbl, pci->phb->node); 550 pci->iommu_table = iommu_init_table(tbl, pci->phb->node);
551 DBG(" created table: %p\n", pci->iommu_table);
564 } 552 }
565 553
566 if (pdn != dn) 554 dev->dev.archdata.dma_data = pci->iommu_table;
567 PCI_DN(dn)->iommu_table = pci->iommu_table;
568} 555}
569 556
570static void iommu_bus_setup_null(struct pci_bus *b) { }
571static void iommu_dev_setup_null(struct pci_dev *d) { }
572
573/* These are called very early. */ 557/* These are called very early. */
574void iommu_init_early_pSeries(void) 558void iommu_init_early_pSeries(void)
575{ 559{
576 if (of_chosen && get_property(of_chosen, "linux,iommu-off", NULL)) { 560 if (of_chosen && get_property(of_chosen, "linux,iommu-off", NULL)) {
577 /* Direct I/O, IOMMU off */ 561 /* Direct I/O, IOMMU off */
578 ppc_md.iommu_dev_setup = iommu_dev_setup_null; 562 ppc_md.pci_dma_dev_setup = NULL;
579 ppc_md.iommu_bus_setup = iommu_bus_setup_null; 563 ppc_md.pci_dma_bus_setup = NULL;
580 pci_direct_iommu_init(); 564 pci_dma_ops = &dma_direct_ops;
581
582 return; 565 return;
583 } 566 }
584 567
@@ -591,19 +574,19 @@ void iommu_init_early_pSeries(void)
591 ppc_md.tce_free = tce_free_pSeriesLP; 574 ppc_md.tce_free = tce_free_pSeriesLP;
592 } 575 }
593 ppc_md.tce_get = tce_get_pSeriesLP; 576 ppc_md.tce_get = tce_get_pSeriesLP;
594 ppc_md.iommu_bus_setup = iommu_bus_setup_pSeriesLP; 577 ppc_md.pci_dma_bus_setup = pci_dma_bus_setup_pSeriesLP;
595 ppc_md.iommu_dev_setup = iommu_dev_setup_pSeriesLP; 578 ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_pSeriesLP;
596 } else { 579 } else {
597 ppc_md.tce_build = tce_build_pSeries; 580 ppc_md.tce_build = tce_build_pSeries;
598 ppc_md.tce_free = tce_free_pSeries; 581 ppc_md.tce_free = tce_free_pSeries;
599 ppc_md.tce_get = tce_get_pseries; 582 ppc_md.tce_get = tce_get_pseries;
600 ppc_md.iommu_bus_setup = iommu_bus_setup_pSeries; 583 ppc_md.pci_dma_bus_setup = pci_dma_bus_setup_pSeries;
601 ppc_md.iommu_dev_setup = iommu_dev_setup_pSeries; 584 ppc_md.pci_dma_dev_setup = pci_dma_dev_setup_pSeries;
602 } 585 }
603 586
604 587
605 pSeries_reconfig_notifier_register(&iommu_reconfig_nb); 588 pSeries_reconfig_notifier_register(&iommu_reconfig_nb);
606 589
607 pci_iommu_init(); 590 pci_dma_ops = &dma_iommu_ops;
608} 591}
609 592