dma-direct: rename and cleanup __phys_to_dma
authorChristoph Hellwig <hch@lst.de>
Mon, 17 Aug 2020 15:34:03 +0000 (17:34 +0200)
committerChristoph Hellwig <hch@lst.de>
Fri, 11 Sep 2020 07:14:43 +0000 (09:14 +0200)
The __phys_to_dma vs phys_to_dma distinction isn't exactly obvious.  Try
to improve the situation by renaming __phys_to_dma to
phys_to_dma_unencryped, and not forcing architectures that want to
override phys_to_dma to actually provide __phys_to_dma.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Robin Murphy <robin.murphy@arm.com>
15 files changed:
arch/arm/include/asm/dma-direct.h
arch/mips/bmips/dma.c
arch/mips/cavium-octeon/dma-octeon.c
arch/mips/include/asm/dma-direct.h
arch/mips/loongson2ef/fuloong-2e/dma.c
arch/mips/loongson2ef/lemote-2f/dma.c
arch/mips/loongson64/dma.c
arch/mips/pci/pci-ar2315.c
arch/mips/pci/pci-xtalk-bridge.c
arch/mips/sgi-ip32/ip32-dma.c
arch/powerpc/include/asm/dma-direct.h
drivers/iommu/intel/iommu.c
include/linux/dma-direct.h
kernel/dma/direct.c
kernel/dma/swiotlb.c

index a8cee87a93e8ab38f1734ffe9da5410c158ee88f..bca0de567534396bf97c09c49a83dd7636392ac0 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef ASM_ARM_DMA_DIRECT_H
 #define ASM_ARM_DMA_DIRECT_H 1
 
-static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
+static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 {
        unsigned int offset = paddr & ~PAGE_MASK;
        return pfn_to_dma(dev, __phys_to_pfn(paddr)) + offset;
index ba2a5d33dfd3fa0d309a24de758d2fcf188a8f91..49061b870680b9e68f01c152285196f16da481f5 100644 (file)
@@ -40,7 +40,7 @@ static struct bmips_dma_range *bmips_dma_ranges;
 
 #define FLUSH_RAC              0x100
 
-dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t pa)
+dma_addr_t phys_to_dma(struct device *dev, phys_addr_t pa)
 {
        struct bmips_dma_range *r;
 
index 388b13ba2558c2e939076789718637943848dbbc..232fa1017b1ec91fd0a4a9d2716fb1ae089e2181 100644 (file)
@@ -168,7 +168,7 @@ void __init octeon_pci_dma_init(void)
 }
 #endif /* CONFIG_PCI */
 
-dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
+dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 {
 #ifdef CONFIG_PCI
        if (dev && dev_is_pci(dev))
index 8e178651c638c279fd74f431e08408fc0baaa9b8..9a640118316c9d923140a5af8b38a8efac81bd27 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef _MIPS_DMA_DIRECT_H
 #define _MIPS_DMA_DIRECT_H 1
 
-dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr);
+dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr);
 phys_addr_t dma_to_phys(struct device *dev, dma_addr_t daddr);
 
 #endif /* _MIPS_DMA_DIRECT_H */
index 83fadeb3fd7d56605b7615453e8a09c87fb62374..cea167d8aba8dbf2812ab87a015c9ef4e8236fa8 100644 (file)
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/dma-direct.h>
 
-dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
+dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 {
        return paddr | 0x80000000;
 }
index 302b43a14eee74055812920bc0006d048f8b0162..3c9e994563578cde9799b59731176ee9819e059f 100644 (file)
@@ -1,7 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0
 #include <linux/dma-direct.h>
 
-dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
+dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 {
        return paddr | 0x80000000;
 }
index b3dc5d0bd2b113c4b6548d0c2d5cb531aa9223eb..364f2f27c8723fdcbdcf3770bbd3be87717fd0c3 100644 (file)
@@ -4,7 +4,7 @@
 #include <linux/swiotlb.h>
 #include <boot_param.h>
 
-dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
+dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 {
        /* We extract 2bit node id (bit 44~47, only bit 44~45 used now) from
         * Loongson-3's 48bit address space and embed it into 40bit */
index d88395684f487df81c9e5d1bb39e32057aa68be1..cef4a47ab06311e826a17bccd2424a625666be95 100644 (file)
@@ -170,7 +170,7 @@ static inline dma_addr_t ar2315_dev_offset(struct device *dev)
        return 0;
 }
 
-dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
+dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 {
        return paddr + ar2315_dev_offset(dev);
 }
index f1b37f32b55395f81e92ad2933c1c0c39986ab22..50f7d42cca5a7840b2d42204553c9839e54acdd5 100644 (file)
@@ -25,7 +25,7 @@
 /*
  * Common phys<->dma mapping for platforms using pci xtalk bridge
  */
-dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
+dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 {
        struct pci_dev *pdev = to_pci_dev(dev);
        struct bridge_controller *bc = BRIDGE_CONTROLLER(pdev->bus);
index 160317294d97a93752348663a3de9fe93d66dfa6..20c6da9d76bc5e3b062c574e77eda9ccca391dea 100644 (file)
@@ -18,7 +18,7 @@
 
 #define RAM_OFFSET_MASK 0x3fffffffUL
 
-dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
+dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 {
        dma_addr_t dma_addr = paddr & RAM_OFFSET_MASK;
 
index 95b09313d2a4cf78032f48bddba24f2f468265e7..128304cbee1d870cfcf672797a9f053b7556c488 100644 (file)
@@ -2,7 +2,7 @@
 #ifndef ASM_POWERPC_DMA_DIRECT_H
 #define ASM_POWERPC_DMA_DIRECT_H 1
 
-static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
+static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
 {
        return paddr + dev->archdata.dma_offset;
 }
index f8177c59d229a65957dccb598a5d0cf16731054c..7983c13b9eef7d397041880b7bd562b62104f41e 100644 (file)
@@ -3736,7 +3736,7 @@ bounce_map_single(struct device *dev, phys_addr_t paddr, size_t size,
         */
        if (!IS_ALIGNED(paddr | size, VTD_PAGE_SIZE)) {
                tlb_addr = swiotlb_tbl_map_single(dev,
-                               __phys_to_dma(dev, io_tlb_start),
+                               phys_to_dma_unencrypted(dev, io_tlb_start),
                                paddr, size, aligned_size, dir, attrs);
                if (tlb_addr == DMA_MAPPING_ERROR) {
                        goto swiotlb_error;
index f00e262ab6b154ed74709588b2ab307eb69d4367..805010ea5346f91244bd4678a8dc0a61862166fc 100644 (file)
@@ -16,14 +16,29 @@ extern unsigned int zone_dma_bits;
 
 #ifdef CONFIG_ARCH_HAS_PHYS_TO_DMA
 #include <asm/dma-direct.h>
+#ifndef phys_to_dma_unencrypted
+#define phys_to_dma_unencrypted                phys_to_dma
+#endif
 #else
-static inline dma_addr_t __phys_to_dma(struct device *dev, phys_addr_t paddr)
+static inline dma_addr_t phys_to_dma_unencrypted(struct device *dev,
+               phys_addr_t paddr)
 {
        dma_addr_t dev_addr = (dma_addr_t)paddr;
 
        return dev_addr - ((dma_addr_t)dev->dma_pfn_offset << PAGE_SHIFT);
 }
 
+/*
+ * If memory encryption is supported, phys_to_dma will set the memory encryption
+ * bit in the DMA address, and dma_to_phys will clear it.
+ * phys_to_dma_unencrypted is for use on special unencrypted memory like swiotlb
+ * buffers.
+ */
+static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
+{
+       return __sme_set(phys_to_dma_unencrypted(dev, paddr));
+}
+
 static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
 {
        phys_addr_t paddr = (phys_addr_t)dev_addr +
@@ -42,17 +57,6 @@ static inline bool force_dma_unencrypted(struct device *dev)
 }
 #endif /* CONFIG_ARCH_HAS_FORCE_DMA_UNENCRYPTED */
 
-/*
- * If memory encryption is supported, phys_to_dma will set the memory encryption
- * bit in the DMA address, and dma_to_phys will clear it.  The raw __phys_to_dma
- * version should only be used on non-encrypted memory for
- * special occasions like DMA coherent buffers.
- */
-static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
-{
-       return __sme_set(__phys_to_dma(dev, paddr));
-}
-
 static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size,
                bool is_ram)
 {
index bfb479c8a370fa7c5a594459502dce5a02db0c0b..54db9cfdaecc6d4aa2d95248e8258ee9628dcae4 100644 (file)
@@ -25,7 +25,7 @@ static inline dma_addr_t phys_to_dma_direct(struct device *dev,
                phys_addr_t phys)
 {
        if (force_dma_unencrypted(dev))
-               return __phys_to_dma(dev, phys);
+               return phys_to_dma_unencrypted(dev, phys);
        return phys_to_dma(dev, phys);
 }
 
@@ -438,13 +438,13 @@ int dma_direct_supported(struct device *dev, u64 mask)
                return 1;
 
        /*
-        * This check needs to be against the actual bit mask value, so
-        * use __phys_to_dma() here so that the SME encryption mask isn't
+        * This check needs to be against the actual bit mask value, so use
+        * phys_to_dma_unencrypted() here so that the SME encryption mask isn't
         * part of the check.
         */
        if (IS_ENABLED(CONFIG_ZONE_DMA))
                min_mask = min_t(u64, min_mask, DMA_BIT_MASK(zone_dma_bits));
-       return mask >= __phys_to_dma(dev, min_mask);
+       return mask >= phys_to_dma_unencrypted(dev, min_mask);
 }
 
 size_t dma_direct_max_mapping_size(struct device *dev)
index c19379fabd200ebb13c5a134b4f366291751982b..4ea72d145cd27d2e698be79ae78942fe4aa8ddca 100644 (file)
@@ -670,13 +670,13 @@ dma_addr_t swiotlb_map(struct device *dev, phys_addr_t paddr, size_t size,
                              swiotlb_force);
 
        swiotlb_addr = swiotlb_tbl_map_single(dev,
-                       __phys_to_dma(dev, io_tlb_start),
+                       phys_to_dma_unencrypted(dev, io_tlb_start),
                        paddr, size, size, dir, attrs);
        if (swiotlb_addr == (phys_addr_t)DMA_MAPPING_ERROR)
                return DMA_MAPPING_ERROR;
 
        /* Ensure that the address returned is DMA'ble */
-       dma_addr = __phys_to_dma(dev, swiotlb_addr);
+       dma_addr = phys_to_dma_unencrypted(dev, swiotlb_addr);
        if (unlikely(!dma_capable(dev, dma_addr, size, true))) {
                swiotlb_tbl_unmap_single(dev, swiotlb_addr, size, size, dir,
                        attrs | DMA_ATTR_SKIP_CPU_SYNC);