aboutsummaryrefslogtreecommitdiffstats
path: root/arch/ppc64/kernel/pSeries_iommu.c
diff options
context:
space:
mode:
authorPaul Mackerras <paulus@samba.org>2005-09-25 08:51:50 -0400
committerPaul Mackerras <paulus@samba.org>2005-09-25 08:51:50 -0400
commite5baa396af7560382d2cf3f0871d616b61fc284c (patch)
tree6afc166894b8c8b3b2cf6add72a726be14ae2443 /arch/ppc64/kernel/pSeries_iommu.c
parentd6a4c847e43c851cc0ddf73087a730227223f989 (diff)
parentef6bd6eb90ad72ee8ee7ba8b271f27102e9a90c1 (diff)
Merge from Linus' tree.
Diffstat (limited to 'arch/ppc64/kernel/pSeries_iommu.c')
-rw-r--r--arch/ppc64/kernel/pSeries_iommu.c181
1 files changed, 95 insertions, 86 deletions
diff --git a/arch/ppc64/kernel/pSeries_iommu.c b/arch/ppc64/kernel/pSeries_iommu.c
index 2b5e622732f4..5914f61a152e 100644
--- a/arch/ppc64/kernel/pSeries_iommu.c
+++ b/arch/ppc64/kernel/pSeries_iommu.c
@@ -281,8 +281,10 @@ static void iommu_table_setparms(struct pci_controller *phb,
281 tbl->it_offset = phb->dma_window_base_cur >> PAGE_SHIFT; 281 tbl->it_offset = phb->dma_window_base_cur >> PAGE_SHIFT;
282 282
283 /* Test if we are going over 2GB of DMA space */ 283 /* Test if we are going over 2GB of DMA space */
284 if (phb->dma_window_base_cur + phb->dma_window_size > (1L << 31)) 284 if (phb->dma_window_base_cur + phb->dma_window_size > 0x80000000ul) {
285 udbg_printf("PCI_DMA: Unexpected number of IOAs under this PHB.\n");
285 panic("PCI_DMA: Unexpected number of IOAs under this PHB.\n"); 286 panic("PCI_DMA: Unexpected number of IOAs under this PHB.\n");
287 }
286 288
287 phb->dma_window_base_cur += phb->dma_window_size; 289 phb->dma_window_base_cur += phb->dma_window_size;
288 290
@@ -326,92 +328,85 @@ static void iommu_table_setparms_lpar(struct pci_controller *phb,
326 328
327static void iommu_bus_setup_pSeries(struct pci_bus *bus) 329static void iommu_bus_setup_pSeries(struct pci_bus *bus)
328{ 330{
329 struct device_node *dn, *pdn; 331 struct device_node *dn;
330 struct pci_dn *pci;
331 struct iommu_table *tbl; 332 struct iommu_table *tbl;
333 struct device_node *isa_dn, *isa_dn_orig;
334 struct device_node *tmp;
335 struct pci_dn *pci;
336 int children;
332 337
333 DBG("iommu_bus_setup_pSeries, bus %p, bus->self %p\n", bus, bus->self); 338 DBG("iommu_bus_setup_pSeries, bus %p, bus->self %p\n", bus, bus->self);
334 339
335 /* For each (root) bus, we carve up the available DMA space in 256MB 340 dn = pci_bus_to_OF_node(bus);
336 * pieces. Since each piece is used by one (sub) bus/device, that would 341 pci = PCI_DN(dn);
337 * give a maximum of 7 devices per PHB. In most cases, this is plenty. 342
338 * 343 if (bus->self) {
339 * The exception is on Python PHBs (pre-POWER4). Here we don't have EADS 344 /* This is not a root bus, any setup will be done for the
340 * bridges below the PHB to allocate the sectioned tables to, so instead 345 * device-side of the bridge in iommu_dev_setup_pSeries().
341 * we allocate a 1GB table at the PHB level. 346 */
347 return;
348 }
349
350 /* Check if the ISA bus on the system is under
351 * this PHB.
342 */ 352 */
353 isa_dn = isa_dn_orig = of_find_node_by_type(NULL, "isa");
343 354
344 dn = pci_bus_to_OF_node(bus); 355 while (isa_dn && isa_dn != dn)
345 pci = dn->data; 356 isa_dn = isa_dn->parent;
346 357
347 if (!bus->self) { 358 if (isa_dn_orig)
348 /* Root bus */ 359 of_node_put(isa_dn_orig);
349 if (is_python(dn)) {
350 unsigned int *iohole;
351
352 DBG("Python root bus %s\n", bus->name);
353
354 iohole = (unsigned int *)get_property(dn, "io-hole", 0);
355
356 if (iohole) {
357 /* On first bus we need to leave room for the
358 * ISA address space. Just skip the first 256MB
359 * alltogether. This leaves 768MB for the window.
360 */
361 DBG("PHB has io-hole, reserving 256MB\n");
362 pci->phb->dma_window_size = 3 << 28;
363 pci->phb->dma_window_base_cur = 1 << 28;
364 } else {
365 /* 1GB window by default */
366 pci->phb->dma_window_size = 1 << 30;
367 pci->phb->dma_window_base_cur = 0;
368 }
369
370 tbl = kmalloc(sizeof(struct iommu_table), GFP_KERNEL);
371
372 iommu_table_setparms(pci->phb, dn, tbl);
373 pci->iommu_table = iommu_init_table(tbl);
374 } else {
375 /* Do a 128MB table at root. This is used for the IDE
376 * controller on some SMP-mode POWER4 machines. It
377 * doesn't hurt to allocate it on other machines
378 * -- it'll just be unused since new tables are
379 * allocated on the EADS level.
380 *
381 * Allocate at offset 128MB to avoid having to deal
382 * with ISA holes; 128MB table for IDE is plenty.
383 */
384 pci->phb->dma_window_size = 1 << 27;
385 pci->phb->dma_window_base_cur = 1 << 27;
386
387 tbl = kmalloc(sizeof(struct iommu_table), GFP_KERNEL);
388
389 iommu_table_setparms(pci->phb, dn, tbl);
390 pci->iommu_table = iommu_init_table(tbl);
391
392 /* All child buses have 256MB tables */
393 pci->phb->dma_window_size = 1 << 28;
394 }
395 } else {
396 pdn = pci_bus_to_OF_node(bus->parent);
397 360
398 if (!bus->parent->self && !is_python(pdn)) { 361 /* Count number of direct PCI children of the PHB.
399 struct iommu_table *tbl; 362 * All PCI device nodes have class-code property, so it's
400 /* First child and not python means this is the EADS 363 * an easy way to find them.
401 * level. Allocate new table for this slot with 256MB 364 */
402 * window. 365 for (children = 0, tmp = dn->child; tmp; tmp = tmp->sibling)
403 */ 366 if (get_property(tmp, "class-code", NULL))
367 children++;
404 368
405 tbl = kmalloc(sizeof(struct iommu_table), GFP_KERNEL); 369 DBG("Children: %d\n", children);
406 370
407 iommu_table_setparms(pci->phb, dn, tbl); 371 /* Calculate amount of DMA window per slot. Each window must be
372 * a power of two (due to pci_alloc_consistent requirements).
373 *
374 * Keep 256MB aside for PHBs with ISA.
375 */
408 376
409 pci->iommu_table = iommu_init_table(tbl); 377 if (!isa_dn) {
410 } else { 378 /* No ISA/IDE - just set window size and return */
411 /* Lower than first child or under python, use parent table */ 379 pci->phb->dma_window_size = 0x80000000ul; /* To be divided */
412 pci->iommu_table = PCI_DN(pdn)->iommu_table; 380
413 } 381 while (pci->phb->dma_window_size * children > 0x80000000ul)
382 pci->phb->dma_window_size >>= 1;
383 DBG("No ISA/IDE, window size is 0x%lx\n",
384 pci->phb->dma_window_size);
385 pci->phb->dma_window_base_cur = 0;
386
387 return;
414 } 388 }
389
390 /* If we have ISA, then we probably have an IDE
391 * controller too. Allocate a 128MB table but
392 * skip the first 128MB to avoid stepping on ISA
393 * space.
394 */
395 pci->phb->dma_window_size = 0x8000000ul;
396 pci->phb->dma_window_base_cur = 0x8000000ul;
397
398 tbl = kmalloc(sizeof(struct iommu_table), GFP_KERNEL);
399
400 iommu_table_setparms(pci->phb, dn, tbl);
401 pci->iommu_table = iommu_init_table(tbl);
402
403 /* Divide the rest (1.75GB) among the children */
404 pci->phb->dma_window_size = 0x80000000ul;
405 while (pci->phb->dma_window_size * children > 0x70000000ul)
406 pci->phb->dma_window_size >>= 1;
407
408 DBG("ISA/IDE, window size is 0x%lx\n", pci->phb->dma_window_size);
409
415} 410}
416 411
417 412
@@ -462,21 +457,36 @@ static void iommu_bus_setup_pSeriesLP(struct pci_bus *bus)
462static void iommu_dev_setup_pSeries(struct pci_dev *dev) 457static void iommu_dev_setup_pSeries(struct pci_dev *dev)
463{ 458{
464 struct device_node *dn, *mydn; 459 struct device_node *dn, *mydn;
460 struct iommu_table *tbl;
461
462 DBG("iommu_dev_setup_pSeries, dev %p (%s)\n", dev, pci_name(dev));
465 463
466 DBG("iommu_dev_setup_pSeries, dev %p (%s)\n", dev, dev->pretty_name);
467 /* Now copy the iommu_table ptr from the bus device down to the
468 * pci device_node. This means get_iommu_table() won't need to search
469 * up the device tree to find it.
470 */
471 mydn = dn = pci_device_to_OF_node(dev); 464 mydn = dn = pci_device_to_OF_node(dev);
472 465
466 /* 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
468 * the window sizes already.
469 */
470 if (!dev->bus->self) {
471 DBG(" --> first child, no bridge. Allocating iommu table.\n");
472 tbl = kmalloc(sizeof(struct iommu_table), GFP_KERNEL);
473 iommu_table_setparms(PCI_DN(dn)->phb, dn, tbl);
474 PCI_DN(mydn)->iommu_table = iommu_init_table(tbl);
475
476 return;
477 }
478
479 /* If this device is further down the bus tree, search upwards until
480 * an already allocated iommu table is found and use that.
481 */
482
473 while (dn && dn->data && PCI_DN(dn)->iommu_table == NULL) 483 while (dn && dn->data && PCI_DN(dn)->iommu_table == NULL)
474 dn = dn->parent; 484 dn = dn->parent;
475 485
476 if (dn && dn->data) { 486 if (dn && dn->data) {
477 PCI_DN(mydn)->iommu_table = PCI_DN(dn)->iommu_table; 487 PCI_DN(mydn)->iommu_table = PCI_DN(dn)->iommu_table;
478 } else { 488 } else {
479 DBG("iommu_dev_setup_pSeries, dev %p (%s) has no iommu table\n", dev, dev->pretty_name); 489 DBG("iommu_dev_setup_pSeries, dev %p (%s) has no iommu table\n", dev, pci_name(dev));
480 } 490 }
481} 491}
482 492
@@ -510,7 +520,7 @@ static void iommu_dev_setup_pSeriesLP(struct pci_dev *dev)
510 int *dma_window = NULL; 520 int *dma_window = NULL;
511 struct pci_dn *pci; 521 struct pci_dn *pci;
512 522
513 DBG("iommu_dev_setup_pSeriesLP, dev %p (%s)\n", dev, dev->pretty_name); 523 DBG("iommu_dev_setup_pSeriesLP, dev %p (%s)\n", dev, pci_name(dev));
514 524
515 /* dev setup for LPAR is a little tricky, since the device tree might 525 /* dev setup for LPAR is a little tricky, since the device tree might
516 * contain the dma-window properties per-device and not neccesarily 526 * contain the dma-window properties per-device and not neccesarily
@@ -532,9 +542,8 @@ static void iommu_dev_setup_pSeriesLP(struct pci_dev *dev)
532 * slots on POWER4 machines. 542 * slots on POWER4 machines.
533 */ 543 */
534 if (dma_window == NULL || pdn->parent == NULL) { 544 if (dma_window == NULL || pdn->parent == NULL) {
535 /* Fall back to regular (non-LPAR) dev setup */ 545 DBG("No dma window for device, linking to parent\n");
536 DBG("No dma window for device, falling back to regular setup\n"); 546 PCI_DN(dn)->iommu_table = PCI_DN(pdn)->iommu_table;
537 iommu_dev_setup_pSeries(dev);
538 return; 547 return;
539 } else { 548 } else {
540 DBG("Found DMA window, allocating table\n"); 549 DBG("Found DMA window, allocating table\n");