powerpc/powernv: Do not set "read" flag if direction==DMA_NONE
authorAlexey Kardashevskiy <aik@ozlabs.ru>
Fri, 5 Jun 2015 06:35:05 +0000 (16:35 +1000)
committerMichael Ellerman <mpe@ellerman.id.au>
Thu, 11 Jun 2015 05:14:56 +0000 (15:14 +1000)
Normally a bitmap from the iommu_table is used to track what TCE entry
is in use. Since we are going to use iommu_table without its locks and
do xchg() instead, it becomes essential not to put bits which are not
implied in the direction flag as the old TCE value (more precisely -
the permission bits) will be used to decide whether to put the page or not.

This adds iommu_direction_to_tce_perm() (its counterpart is there already)
and uses it for powernv's pnv_tce_build().

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>
arch/powerpc/include/asm/iommu.h
arch/powerpc/kernel/iommu.c
arch/powerpc/platforms/powernv/pci.c

index e94a5e3c5a2f6e1f0a8b217bdd67f2b3d5ad0faf..d91bd69d3196badfeab3f2f4f86d1043a808df97 100644 (file)
@@ -200,6 +200,7 @@ extern int iommu_take_ownership(struct iommu_table *tbl);
 extern void iommu_release_ownership(struct iommu_table *tbl);
 
 extern enum dma_data_direction iommu_tce_direction(unsigned long tce);
+extern unsigned long iommu_direction_to_tce_perm(enum dma_data_direction dir);
 
 #endif /* __KERNEL__ */
 #endif /* _ASM_IOMMU_H */
index 0019c80aa81d9414a089dd97ff0389b5bb1c13f5..ac2f959adf9aa0ce0a92c93c6c16620239f491a6 100644 (file)
@@ -866,6 +866,21 @@ void iommu_free_coherent(struct iommu_table *tbl, size_t size,
        }
 }
 
+unsigned long iommu_direction_to_tce_perm(enum dma_data_direction dir)
+{
+       switch (dir) {
+       case DMA_BIDIRECTIONAL:
+               return TCE_PCI_READ | TCE_PCI_WRITE;
+       case DMA_FROM_DEVICE:
+               return TCE_PCI_WRITE;
+       case DMA_TO_DEVICE:
+               return TCE_PCI_READ;
+       default:
+               return 0;
+       }
+}
+EXPORT_SYMBOL_GPL(iommu_direction_to_tce_perm);
+
 #ifdef CONFIG_IOMMU_API
 /*
  * SPAPR TCE API
index 3c35487e97787ff7f595f4d18698f08d80aa34e3..1477422b907a013ba7df35e4089d2b66a51fd8b3 100644 (file)
@@ -576,15 +576,10 @@ static int pnv_tce_build(struct iommu_table *tbl, long index, long npages,
                         unsigned long uaddr, enum dma_data_direction direction,
                         struct dma_attrs *attrs, bool rm)
 {
-       u64 proto_tce;
+       u64 proto_tce = iommu_direction_to_tce_perm(direction);
        __be64 *tcep, *tces;
        u64 rpn;
 
-       proto_tce = TCE_PCI_READ; // Read allowed
-
-       if (direction != DMA_TO_DEVICE)
-               proto_tce |= TCE_PCI_WRITE;
-
        tces = tcep = ((__be64 *)tbl->it_base) + index - tbl->it_offset;
        rpn = __pa(uaddr) >> tbl->it_page_shift;