aboutsummaryrefslogtreecommitdiffstats
path: root/arch/powerpc/platforms/powernv/pci-ioda.c
diff options
context:
space:
mode:
authorGavin Shan <shangw@linux.vnet.ibm.com>2013-04-25 15:21:00 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2013-04-26 02:09:59 -0400
commit4cce95508bfeaa1cab74b08558993c81436dcbe0 (patch)
treee7c8e24087a508c7288954a8d4da2d65f9f62d19 /arch/powerpc/platforms/powernv/pci-ioda.c
parent137436c9a6ee385c883db09e41af763888ee7642 (diff)
powerpc/powernv: TCE invalidation for PHB3
The TCE should be invalidated while it's created or free'd. The approach to do that for IODA1 and IODA2 compliant PHBs are different. So the patch differentiate them with different functions called to do that for IODA1 and IODA2 compliant PHBs. It's notable that the PCI address is used to invalidate the corresponding TCE on IODA2 compliant PHB3. Signed-off-by: Gavin Shan <shangw@linux.vnet.ibm.com> Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'arch/powerpc/platforms/powernv/pci-ioda.c')
-rw-r--r--arch/powerpc/platforms/powernv/pci-ioda.c85
1 files changed, 83 insertions, 2 deletions
diff --git a/arch/powerpc/platforms/powernv/pci-ioda.c b/arch/powerpc/platforms/powernv/pci-ioda.c
index 3f88c51cb95b..1c7e808a1302 100644
--- a/arch/powerpc/platforms/powernv/pci-ioda.c
+++ b/arch/powerpc/platforms/powernv/pci-ioda.c
@@ -89,6 +89,7 @@ static int pnv_ioda_alloc_pe(struct pnv_phb *phb)
89 return IODA_INVALID_PE; 89 return IODA_INVALID_PE;
90 } while(test_and_set_bit(pe, phb->ioda.pe_alloc)); 90 } while(test_and_set_bit(pe, phb->ioda.pe_alloc));
91 91
92 phb->ioda.pe_array[pe].phb = phb;
92 phb->ioda.pe_array[pe].pe_number = pe; 93 phb->ioda.pe_array[pe].pe_number = pe;
93 return pe; 94 return pe;
94} 95}
@@ -449,6 +450,85 @@ static void pnv_ioda_setup_bus_dma(struct pnv_ioda_pe *pe, struct pci_bus *bus)
449 } 450 }
450} 451}
451 452
453static void pnv_pci_ioda1_tce_invalidate(struct iommu_table *tbl,
454 u64 *startp, u64 *endp)
455{
456 u64 __iomem *invalidate = (u64 __iomem *)tbl->it_index;
457 unsigned long start, end, inc;
458
459 start = __pa(startp);
460 end = __pa(endp);
461
462 /* BML uses this case for p6/p7/galaxy2: Shift addr and put in node */
463 if (tbl->it_busno) {
464 start <<= 12;
465 end <<= 12;
466 inc = 128 << 12;
467 start |= tbl->it_busno;
468 end |= tbl->it_busno;
469 } else if (tbl->it_type & TCE_PCI_SWINV_PAIR) {
470 /* p7ioc-style invalidation, 2 TCEs per write */
471 start |= (1ull << 63);
472 end |= (1ull << 63);
473 inc = 16;
474 } else {
475 /* Default (older HW) */
476 inc = 128;
477 }
478
479 end |= inc - 1; /* round up end to be different than start */
480
481 mb(); /* Ensure above stores are visible */
482 while (start <= end) {
483 __raw_writeq(start, invalidate);
484 start += inc;
485 }
486
487 /*
488 * The iommu layer will do another mb() for us on build()
489 * and we don't care on free()
490 */
491}
492
493static void pnv_pci_ioda2_tce_invalidate(struct pnv_ioda_pe *pe,
494 struct iommu_table *tbl,
495 u64 *startp, u64 *endp)
496{
497 unsigned long start, end, inc;
498 u64 __iomem *invalidate = (u64 __iomem *)tbl->it_index;
499
500 /* We'll invalidate DMA address in PE scope */
501 start = 0x2ul << 60;
502 start |= (pe->pe_number & 0xFF);
503 end = start;
504
505 /* Figure out the start, end and step */
506 inc = tbl->it_offset + (((u64)startp - tbl->it_base) / sizeof(u64));
507 start |= (inc << 12);
508 inc = tbl->it_offset + (((u64)endp - tbl->it_base) / sizeof(u64));
509 end |= (inc << 12);
510 inc = (0x1ul << 12);
511 mb();
512
513 while (start <= end) {
514 __raw_writeq(start, invalidate);
515 start += inc;
516 }
517}
518
519void pnv_pci_ioda_tce_invalidate(struct iommu_table *tbl,
520 u64 *startp, u64 *endp)
521{
522 struct pnv_ioda_pe *pe = container_of(tbl, struct pnv_ioda_pe,
523 tce32_table);
524 struct pnv_phb *phb = pe->phb;
525
526 if (phb->type == PNV_PHB_IODA1)
527 pnv_pci_ioda1_tce_invalidate(tbl, startp, endp);
528 else
529 pnv_pci_ioda2_tce_invalidate(pe, tbl, startp, endp);
530}
531
452static void pnv_pci_ioda_setup_dma_pe(struct pnv_phb *phb, 532static void pnv_pci_ioda_setup_dma_pe(struct pnv_phb *phb,
453 struct pnv_ioda_pe *pe, unsigned int base, 533 struct pnv_ioda_pe *pe, unsigned int base,
454 unsigned int segs) 534 unsigned int segs)
@@ -520,8 +600,9 @@ static void pnv_pci_ioda_setup_dma_pe(struct pnv_phb *phb,
520 */ 600 */
521 tbl->it_busno = 0; 601 tbl->it_busno = 0;
522 tbl->it_index = (unsigned long)ioremap(be64_to_cpup(swinvp), 8); 602 tbl->it_index = (unsigned long)ioremap(be64_to_cpup(swinvp), 8);
523 tbl->it_type = TCE_PCI_SWINV_CREATE | TCE_PCI_SWINV_FREE 603 tbl->it_type = TCE_PCI_SWINV_CREATE | TCE_PCI_SWINV_FREE;
524 | TCE_PCI_SWINV_PAIR; 604 if (phb->type == PNV_PHB_IODA1)
605 tbl->it_type |= TCE_PCI_SWINV_PAIR;
525 } 606 }
526 iommu_init_table(tbl, phb->hose->node); 607 iommu_init_table(tbl, phb->hose->node);
527 608