Merge tag 'dma-mapping-6.4-2023-04-28' of git://git.infradead.org/users/hch/dma-mapping
[platform/kernel/linux-starfive.git] / kernel / dma / swiotlb.c
index e67dafc..af2e304 100644 (file)
@@ -73,8 +73,6 @@ static bool swiotlb_force_disable;
 
 struct io_tlb_mem io_tlb_default_mem;
 
-phys_addr_t swiotlb_unencrypted_base;
-
 static unsigned long default_nslabs = IO_TLB_DEFAULT_SIZE >> IO_TLB_SHIFT;
 static unsigned long default_nareas;
 
@@ -202,34 +200,6 @@ static inline unsigned long nr_slots(u64 val)
 }
 
 /*
- * Remap swioltb memory in the unencrypted physical address space
- * when swiotlb_unencrypted_base is set. (e.g. for Hyper-V AMD SEV-SNP
- * Isolation VMs).
- */
-#ifdef CONFIG_HAS_IOMEM
-static void *swiotlb_mem_remap(struct io_tlb_mem *mem, unsigned long bytes)
-{
-       void *vaddr = NULL;
-
-       if (swiotlb_unencrypted_base) {
-               phys_addr_t paddr = mem->start + swiotlb_unencrypted_base;
-
-               vaddr = memremap(paddr, bytes, MEMREMAP_WB);
-               if (!vaddr)
-                       pr_err("Failed to map the unencrypted memory %pa size %lx.\n",
-                              &paddr, bytes);
-       }
-
-       return vaddr;
-}
-#else
-static void *swiotlb_mem_remap(struct io_tlb_mem *mem, unsigned long bytes)
-{
-       return NULL;
-}
-#endif
-
-/*
  * Early SWIOTLB allocation may be too early to allow an architecture to
  * perform the desired operations.  This function allows the architecture to
  * call SWIOTLB when the operations are possible.  It needs to be called
@@ -238,18 +208,12 @@ static void *swiotlb_mem_remap(struct io_tlb_mem *mem, unsigned long bytes)
 void __init swiotlb_update_mem_attributes(void)
 {
        struct io_tlb_mem *mem = &io_tlb_default_mem;
-       void *vaddr;
        unsigned long bytes;
 
        if (!mem->nslabs || mem->late_alloc)
                return;
-       vaddr = phys_to_virt(mem->start);
        bytes = PAGE_ALIGN(mem->nslabs << IO_TLB_SHIFT);
-       set_memory_decrypted((unsigned long)vaddr, bytes >> PAGE_SHIFT);
-
-       mem->vaddr = swiotlb_mem_remap(mem, bytes);
-       if (!mem->vaddr)
-               mem->vaddr = vaddr;
+       set_memory_decrypted((unsigned long)mem->vaddr, bytes >> PAGE_SHIFT);
 }
 
 static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
@@ -280,13 +244,6 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
                mem->slots[i].alloc_size = 0;
        }
 
-       /*
-        * If swiotlb_unencrypted_base is set, the bounce buffer memory will
-        * be remapped and cleared in swiotlb_update_mem_attributes.
-        */
-       if (swiotlb_unencrypted_base)
-               return;
-
        memset(vaddr, 0, bytes);
        mem->vaddr = vaddr;
        return;
@@ -657,7 +614,7 @@ static int swiotlb_do_find_slots(struct device *dev, int area_index,
                phys_to_dma_unencrypted(dev, mem->start) & boundary_mask;
        unsigned long max_slots = get_max_slots(boundary_mask);
        unsigned int iotlb_align_mask =
-               dma_get_min_align_mask(dev) & ~(IO_TLB_SIZE - 1);
+               dma_get_min_align_mask(dev) | alloc_align_mask;
        unsigned int nslots = nr_slots(alloc_size), stride;
        unsigned int offset = swiotlb_align_offset(dev, orig_addr);
        unsigned int index, slots_checked, count = 0, i;
@@ -673,8 +630,8 @@ static int swiotlb_do_find_slots(struct device *dev, int area_index,
         * allocations.
         */
        if (alloc_size >= PAGE_SIZE)
-               iotlb_align_mask &= PAGE_MASK;
-       iotlb_align_mask &= alloc_align_mask;
+               iotlb_align_mask |= ~PAGE_MASK;
+       iotlb_align_mask &= ~(IO_TLB_SIZE - 1);
 
        /*
         * For mappings with an alignment requirement don't bother looping to