]> git.ipfire.org Git - thirdparty/linux.git/blobdiff - kernel/dma/swiotlb.c
Merge branch 'for-linus-5.2' of git://git.kernel.org/pub/scm/linux/kernel/git/konrad...
[thirdparty/linux.git] / kernel / dma / swiotlb.c
index 2ca8a200be977322d25579c13583f7e6aa58ebaf..9de232229063bcf78b1d0ce942fe6a38a9e78dba 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0-only
 /*
  * Dynamic DMA mapping support.
  *
@@ -199,6 +200,7 @@ void __init swiotlb_update_mem_attributes(void)
 int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 {
        unsigned long i, bytes;
+       size_t alloc_size;
 
        bytes = nslabs << IO_TLB_SHIFT;
 
@@ -211,12 +213,18 @@ int __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
         * to find contiguous free memory regions of size up to IO_TLB_SEGSIZE
         * between io_tlb_start and io_tlb_end.
         */
-       io_tlb_list = memblock_alloc(
-                               PAGE_ALIGN(io_tlb_nslabs * sizeof(int)),
-                               PAGE_SIZE);
-       io_tlb_orig_addr = memblock_alloc(
-                               PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t)),
-                               PAGE_SIZE);
+       alloc_size = PAGE_ALIGN(io_tlb_nslabs * sizeof(int));
+       io_tlb_list = memblock_alloc(alloc_size, PAGE_SIZE);
+       if (!io_tlb_list)
+               panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
+                     __func__, alloc_size, PAGE_SIZE);
+
+       alloc_size = PAGE_ALIGN(io_tlb_nslabs * sizeof(phys_addr_t));
+       io_tlb_orig_addr = memblock_alloc(alloc_size, PAGE_SIZE);
+       if (!io_tlb_orig_addr)
+               panic("%s: Failed to allocate %zu bytes align=0x%lx\n",
+                     __func__, alloc_size, PAGE_SIZE);
+
        for (i = 0; i < io_tlb_nslabs; i++) {
                io_tlb_list[i] = IO_TLB_SEGSIZE - OFFSET(i, IO_TLB_SEGSIZE);
                io_tlb_orig_addr[i] = INVALID_PHYS_ADDR;
@@ -249,7 +257,7 @@ swiotlb_init(int verbose)
        bytes = io_tlb_nslabs << IO_TLB_SHIFT;
 
        /* Get IO TLB memory from the low pages */
-       vstart = memblock_alloc_low_nopanic(PAGE_ALIGN(bytes), PAGE_SIZE);
+       vstart = memblock_alloc_low(PAGE_ALIGN(bytes), PAGE_SIZE);
        if (vstart && !swiotlb_init_with_tbl(vstart, io_tlb_nslabs, verbose))
                return;
 
@@ -672,45 +680,30 @@ bool swiotlb_map(struct device *dev, phys_addr_t *phys, dma_addr_t *dma_addr,
        return true;
 }
 
-/*
- * Return whether the given device DMA address mask can be supported
- * properly.  For example, if your device can only drive the low 24-bits
- * during bus mastering, then you would pass 0x00ffffff as the mask to
- * this function.
- */
-int
-swiotlb_dma_supported(struct device *hwdev, u64 mask)
+size_t swiotlb_max_mapping_size(struct device *dev)
 {
-       return __phys_to_dma(hwdev, io_tlb_end - 1) <= mask;
+       return ((size_t)1 << IO_TLB_SHIFT) * IO_TLB_SEGSIZE;
+}
+
+bool is_swiotlb_active(void)
+{
+       /*
+        * When SWIOTLB is initialized, even if io_tlb_start points to physical
+        * address zero, io_tlb_end surely doesn't.
+        */
+       return io_tlb_end != 0;
 }
 
 #ifdef CONFIG_DEBUG_FS
 
 static int __init swiotlb_create_debugfs(void)
 {
-       struct dentry *d_swiotlb_usage;
-       struct dentry *ent;
-
-       d_swiotlb_usage = debugfs_create_dir("swiotlb", NULL);
-
-       if (!d_swiotlb_usage)
-               return -ENOMEM;
-
-       ent = debugfs_create_ulong("io_tlb_nslabs", 0400,
-                                  d_swiotlb_usage, &io_tlb_nslabs);
-       if (!ent)
-               goto fail;
-
-       ent = debugfs_create_ulong("io_tlb_used", 0400,
-                                  d_swiotlb_usage, &io_tlb_used);
-       if (!ent)
-               goto fail;
+       struct dentry *root;
 
+       root = debugfs_create_dir("swiotlb", NULL);
+       debugfs_create_ulong("io_tlb_nslabs", 0400, root, &io_tlb_nslabs);
+       debugfs_create_ulong("io_tlb_used", 0400, root, &io_tlb_used);
        return 0;
-
-fail:
-       debugfs_remove_recursive(d_swiotlb_usage);
-       return -ENOMEM;
 }
 
 late_initcall(swiotlb_create_debugfs);