Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

powerpc/powernv: Implement accessor to TCE entry

This replaces direct accesses to TCE table with a helper which
returns an TCE entry address. This does not make difference now but will
when multi-level TCE tables get introduces.

No change in behavior is expected.

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Reviewed-by: David Gibson <david@gibson.dropbear.id.au>
Reviewed-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

authored by

Alexey Kardashevskiy and committed by
Michael Ellerman
c5bb44ed e57080f1

+21 -13
+21 -13
arch/powerpc/platforms/powernv/pci.c
··· 572 572 .write = pnv_pci_write_config, 573 573 }; 574 574 575 + static __be64 *pnv_tce(struct iommu_table *tbl, long idx) 576 + { 577 + __be64 *tmp = ((__be64 *)tbl->it_base); 578 + 579 + return tmp + idx; 580 + } 581 + 575 582 int pnv_tce_build(struct iommu_table *tbl, long index, long npages, 576 583 unsigned long uaddr, enum dma_data_direction direction, 577 584 struct dma_attrs *attrs) 578 585 { 579 586 u64 proto_tce = iommu_direction_to_tce_perm(direction); 580 - __be64 *tcep; 581 - u64 rpn; 587 + u64 rpn = __pa(uaddr) >> tbl->it_page_shift; 588 + long i; 582 589 583 - tcep = ((__be64 *)tbl->it_base) + index - tbl->it_offset; 584 - rpn = __pa(uaddr) >> tbl->it_page_shift; 590 + for (i = 0; i < npages; i++) { 591 + unsigned long newtce = proto_tce | 592 + ((rpn + i) << tbl->it_page_shift); 593 + unsigned long idx = index - tbl->it_offset + i; 585 594 586 - while (npages--) 587 - *(tcep++) = cpu_to_be64(proto_tce | 588 - (rpn++ << tbl->it_page_shift)); 589 - 595 + *(pnv_tce(tbl, idx)) = cpu_to_be64(newtce); 596 + } 590 597 591 598 return 0; 592 599 } 593 600 594 601 void pnv_tce_free(struct iommu_table *tbl, long index, long npages) 595 602 { 596 - __be64 *tcep; 603 + long i; 597 604 598 - tcep = ((__be64 *)tbl->it_base) + index - tbl->it_offset; 605 + for (i = 0; i < npages; i++) { 606 + unsigned long idx = index - tbl->it_offset + i; 599 607 600 - while (npages--) 601 - *(tcep++) = cpu_to_be64(0); 608 + *(pnv_tce(tbl, idx)) = cpu_to_be64(0); 609 + } 602 610 } 603 611 604 612 unsigned long pnv_tce_get(struct iommu_table *tbl, long index) 605 613 { 606 - return ((u64 *)tbl->it_base)[index - tbl->it_offset]; 614 + return *(pnv_tce(tbl, index - tbl->it_offset)); 607 615 } 608 616 609 617 struct iommu_table *pnv_pci_table_alloc(int nid)