Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Russell King | 0ddbccd | 2008-09-25 15:59:19 +0100 | [diff] [blame] | 2 | * linux/arch/arm/mm/dma-mapping.c |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2000-2004 Russell King |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | * |
| 10 | * DMA uncached mapping support. |
| 11 | */ |
| 12 | #include <linux/module.h> |
| 13 | #include <linux/mm.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 14 | #include <linux/gfp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/errno.h> |
| 16 | #include <linux/list.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/device.h> |
| 19 | #include <linux/dma-mapping.h> |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 20 | #include <linux/dma-contiguous.h> |
Nicolas Pitre | 39af22a | 2010-12-15 15:14:45 -0500 | [diff] [blame] | 21 | #include <linux/highmem.h> |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 22 | #include <linux/memblock.h> |
Jon Medhurst | 99d1717 | 2011-08-02 17:28:27 +0100 | [diff] [blame] | 23 | #include <linux/slab.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Lennert Buytenhek | 23759dc | 2006-04-02 00:07:39 +0100 | [diff] [blame] | 25 | #include <asm/memory.h> |
Nicolas Pitre | 4337745 | 2009-03-12 22:52:09 -0400 | [diff] [blame] | 26 | #include <asm/highmem.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <asm/cacheflush.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <asm/tlbflush.h> |
Kevin Hilman | 37134cd | 2006-01-12 16:12:21 +0000 | [diff] [blame] | 29 | #include <asm/sizes.h> |
Jon Medhurst | 99d1717 | 2011-08-02 17:28:27 +0100 | [diff] [blame] | 30 | #include <asm/mach/arch.h> |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 31 | #include <asm/mach/map.h> |
| 32 | #include <asm/system_info.h> |
| 33 | #include <asm/dma-contiguous.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
Russell King | 022ae53 | 2011-07-08 21:26:59 +0100 | [diff] [blame] | 35 | #include "mm.h" |
| 36 | |
Marek Szyprowski | 8b59d2a | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 37 | /* |
| 38 | * The DMA API is built upon the notion of "buffer ownership". A buffer |
| 39 | * is either exclusively owned by the CPU (and therefore may be accessed |
| 40 | * by it) or exclusively owned by the DMA device. These helper functions |
| 41 | * represent the transitions between these two ownership states. |
| 42 | * |
| 43 | * Note, however, that on later ARMs, this notion does not work due to |
| 44 | * speculative prefetches. We model our approach on the assumption that |
| 45 | * the CPU does do speculative prefetches, which means we clean caches |
| 46 | * before transfers and delay cache invalidation until transfer completion. |
| 47 | * |
Marek Szyprowski | 8b59d2a | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 48 | */ |
Marek Szyprowski | 53e207d | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 49 | static void __dma_page_cpu_to_dev(struct page *, unsigned long, |
Marek Szyprowski | 8b59d2a | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 50 | size_t, enum dma_data_direction); |
Marek Szyprowski | 53e207d | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 51 | static void __dma_page_dev_to_cpu(struct page *, unsigned long, |
Marek Szyprowski | 8b59d2a | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 52 | size_t, enum dma_data_direction); |
| 53 | |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 54 | /** |
| 55 | * arm_dma_map_page - map a portion of a page for streaming DMA |
| 56 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices |
| 57 | * @page: page that buffer resides in |
| 58 | * @offset: offset into page for start of buffer |
| 59 | * @size: size of buffer to map |
| 60 | * @dir: DMA transfer direction |
| 61 | * |
| 62 | * Ensure that any data held in the cache is appropriately discarded |
| 63 | * or written back. |
| 64 | * |
| 65 | * The device owns this memory once this call has completed. The CPU |
| 66 | * can regain ownership by calling dma_unmap_page(). |
| 67 | */ |
Marek Szyprowski | 53e207d | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 68 | static dma_addr_t arm_dma_map_page(struct device *dev, struct page *page, |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 69 | unsigned long offset, size_t size, enum dma_data_direction dir, |
| 70 | struct dma_attrs *attrs) |
| 71 | { |
Marek Szyprowski | 53e207d | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 72 | if (!arch_is_coherent()) |
| 73 | __dma_page_cpu_to_dev(page, offset, size, dir); |
| 74 | return pfn_to_dma(dev, page_to_pfn(page)) + offset; |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | /** |
| 78 | * arm_dma_unmap_page - unmap a buffer previously mapped through dma_map_page() |
| 79 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices |
| 80 | * @handle: DMA address of buffer |
| 81 | * @size: size of buffer (same as passed to dma_map_page) |
| 82 | * @dir: DMA transfer direction (same as passed to dma_map_page) |
| 83 | * |
| 84 | * Unmap a page streaming mode DMA translation. The handle and size |
| 85 | * must match what was provided in the previous dma_map_page() call. |
| 86 | * All other usages are undefined. |
| 87 | * |
| 88 | * After this call, reads by the CPU to the buffer are guaranteed to see |
| 89 | * whatever the device wrote there. |
| 90 | */ |
Marek Szyprowski | 53e207d | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 91 | static void arm_dma_unmap_page(struct device *dev, dma_addr_t handle, |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 92 | size_t size, enum dma_data_direction dir, |
| 93 | struct dma_attrs *attrs) |
| 94 | { |
Marek Szyprowski | 53e207d | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 95 | if (!arch_is_coherent()) |
| 96 | __dma_page_dev_to_cpu(pfn_to_page(dma_to_pfn(dev, handle)), |
| 97 | handle & ~PAGE_MASK, size, dir); |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 98 | } |
| 99 | |
Marek Szyprowski | 53e207d | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 100 | static void arm_dma_sync_single_for_cpu(struct device *dev, |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 101 | dma_addr_t handle, size_t size, enum dma_data_direction dir) |
| 102 | { |
| 103 | unsigned int offset = handle & (PAGE_SIZE - 1); |
| 104 | struct page *page = pfn_to_page(dma_to_pfn(dev, handle-offset)); |
Marek Szyprowski | 53e207d | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 105 | if (!arch_is_coherent()) |
| 106 | __dma_page_dev_to_cpu(page, offset, size, dir); |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 107 | } |
| 108 | |
Marek Szyprowski | 53e207d | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 109 | static void arm_dma_sync_single_for_device(struct device *dev, |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 110 | dma_addr_t handle, size_t size, enum dma_data_direction dir) |
| 111 | { |
| 112 | unsigned int offset = handle & (PAGE_SIZE - 1); |
| 113 | struct page *page = pfn_to_page(dma_to_pfn(dev, handle-offset)); |
Marek Szyprowski | 53e207d | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 114 | if (!arch_is_coherent()) |
| 115 | __dma_page_cpu_to_dev(page, offset, size, dir); |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static int arm_dma_set_mask(struct device *dev, u64 dma_mask); |
| 119 | |
| 120 | struct dma_map_ops arm_dma_ops = { |
Marek Szyprowski | f8f9d07 | 2012-05-16 18:31:23 +0200 | [diff] [blame^] | 121 | .alloc = arm_dma_alloc, |
| 122 | .free = arm_dma_free, |
| 123 | .mmap = arm_dma_mmap, |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 124 | .map_page = arm_dma_map_page, |
| 125 | .unmap_page = arm_dma_unmap_page, |
| 126 | .map_sg = arm_dma_map_sg, |
| 127 | .unmap_sg = arm_dma_unmap_sg, |
| 128 | .sync_single_for_cpu = arm_dma_sync_single_for_cpu, |
| 129 | .sync_single_for_device = arm_dma_sync_single_for_device, |
| 130 | .sync_sg_for_cpu = arm_dma_sync_sg_for_cpu, |
| 131 | .sync_sg_for_device = arm_dma_sync_sg_for_device, |
| 132 | .set_dma_mask = arm_dma_set_mask, |
| 133 | }; |
| 134 | EXPORT_SYMBOL(arm_dma_ops); |
| 135 | |
Catalin Marinas | ab6494f | 2009-07-24 12:35:02 +0100 | [diff] [blame] | 136 | static u64 get_coherent_dma_mask(struct device *dev) |
| 137 | { |
Russell King | 022ae53 | 2011-07-08 21:26:59 +0100 | [diff] [blame] | 138 | u64 mask = (u64)arm_dma_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | |
Catalin Marinas | ab6494f | 2009-07-24 12:35:02 +0100 | [diff] [blame] | 140 | if (dev) { |
| 141 | mask = dev->coherent_dma_mask; |
| 142 | |
| 143 | /* |
| 144 | * Sanity check the DMA mask - it must be non-zero, and |
| 145 | * must be able to be satisfied by a DMA allocation. |
| 146 | */ |
| 147 | if (mask == 0) { |
| 148 | dev_warn(dev, "coherent DMA mask is unset\n"); |
| 149 | return 0; |
| 150 | } |
| 151 | |
Russell King | 022ae53 | 2011-07-08 21:26:59 +0100 | [diff] [blame] | 152 | if ((~mask) & (u64)arm_dma_limit) { |
Catalin Marinas | ab6494f | 2009-07-24 12:35:02 +0100 | [diff] [blame] | 153 | dev_warn(dev, "coherent DMA mask %#llx is smaller " |
| 154 | "than system GFP_DMA mask %#llx\n", |
Russell King | 022ae53 | 2011-07-08 21:26:59 +0100 | [diff] [blame] | 155 | mask, (u64)arm_dma_limit); |
Catalin Marinas | ab6494f | 2009-07-24 12:35:02 +0100 | [diff] [blame] | 156 | return 0; |
| 157 | } |
| 158 | } |
| 159 | |
| 160 | return mask; |
| 161 | } |
| 162 | |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 163 | static void __dma_clear_buffer(struct page *page, size_t size) |
| 164 | { |
| 165 | void *ptr; |
| 166 | /* |
| 167 | * Ensure that the allocated pages are zeroed, and that any data |
| 168 | * lurking in the kernel direct-mapped region is invalidated. |
| 169 | */ |
| 170 | ptr = page_address(page); |
| 171 | memset(ptr, 0, size); |
| 172 | dmac_flush_range(ptr, ptr + size); |
| 173 | outer_flush_range(__pa(ptr), __pa(ptr) + size); |
| 174 | } |
| 175 | |
Russell King | 7a9a32a | 2009-11-19 15:31:07 +0000 | [diff] [blame] | 176 | /* |
| 177 | * Allocate a DMA buffer for 'dev' of size 'size' using the |
| 178 | * specified gfp mask. Note that 'size' must be page aligned. |
| 179 | */ |
| 180 | static struct page *__dma_alloc_buffer(struct device *dev, size_t size, gfp_t gfp) |
| 181 | { |
| 182 | unsigned long order = get_order(size); |
| 183 | struct page *page, *p, *e; |
Russell King | 7a9a32a | 2009-11-19 15:31:07 +0000 | [diff] [blame] | 184 | |
| 185 | page = alloc_pages(gfp, order); |
| 186 | if (!page) |
| 187 | return NULL; |
| 188 | |
| 189 | /* |
| 190 | * Now split the huge page and free the excess pages |
| 191 | */ |
| 192 | split_page(page, order); |
| 193 | for (p = page + (size >> PAGE_SHIFT), e = page + (1 << order); p < e; p++) |
| 194 | __free_page(p); |
| 195 | |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 196 | __dma_clear_buffer(page, size); |
Russell King | 7a9a32a | 2009-11-19 15:31:07 +0000 | [diff] [blame] | 197 | |
| 198 | return page; |
| 199 | } |
| 200 | |
| 201 | /* |
| 202 | * Free a DMA buffer. 'size' must be page aligned. |
| 203 | */ |
| 204 | static void __dma_free_buffer(struct page *page, size_t size) |
| 205 | { |
| 206 | struct page *e = page + (size >> PAGE_SHIFT); |
| 207 | |
| 208 | while (page < e) { |
| 209 | __free_page(page); |
| 210 | page++; |
| 211 | } |
| 212 | } |
| 213 | |
Catalin Marinas | ab6494f | 2009-07-24 12:35:02 +0100 | [diff] [blame] | 214 | #ifdef CONFIG_MMU |
Catalin Marinas | a5e9d38 | 2010-06-21 15:09:06 +0100 | [diff] [blame] | 215 | |
Jon Medhurst | 99d1717 | 2011-08-02 17:28:27 +0100 | [diff] [blame] | 216 | #define CONSISTENT_OFFSET(x) (((unsigned long)(x) - consistent_base) >> PAGE_SHIFT) |
Linus Torvalds | 1fdb24e | 2011-10-28 12:02:27 -0700 | [diff] [blame] | 217 | #define CONSISTENT_PTE_INDEX(x) (((unsigned long)(x) - consistent_base) >> PMD_SHIFT) |
Catalin Marinas | a5e9d38 | 2010-06-21 15:09:06 +0100 | [diff] [blame] | 218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | /* |
Kevin Hilman | 37134cd | 2006-01-12 16:12:21 +0000 | [diff] [blame] | 220 | * These are the page tables (2MB each) covering uncached, DMA consistent allocations |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | */ |
Jon Medhurst | 99d1717 | 2011-08-02 17:28:27 +0100 | [diff] [blame] | 222 | static pte_t **consistent_pte; |
| 223 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 224 | #define DEFAULT_CONSISTENT_DMA_SIZE (7*SZ_2M) |
Jon Medhurst | 99d1717 | 2011-08-02 17:28:27 +0100 | [diff] [blame] | 225 | |
| 226 | unsigned long consistent_base = CONSISTENT_END - DEFAULT_CONSISTENT_DMA_SIZE; |
| 227 | |
| 228 | void __init init_consistent_dma_size(unsigned long size) |
| 229 | { |
| 230 | unsigned long base = CONSISTENT_END - ALIGN(size, SZ_2M); |
| 231 | |
| 232 | BUG_ON(consistent_pte); /* Check we're called before DMA region init */ |
| 233 | BUG_ON(base < VMALLOC_END); |
| 234 | |
| 235 | /* Grow region to accommodate specified size */ |
| 236 | if (base < consistent_base) |
| 237 | consistent_base = base; |
| 238 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | |
Russell King | 13ccf3a | 2009-11-19 15:07:04 +0000 | [diff] [blame] | 240 | #include "vmregion.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
Russell King | 13ccf3a | 2009-11-19 15:07:04 +0000 | [diff] [blame] | 242 | static struct arm_vmregion_head consistent_head = { |
| 243 | .vm_lock = __SPIN_LOCK_UNLOCKED(&consistent_head.vm_lock), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | .vm_list = LIST_HEAD_INIT(consistent_head.vm_list), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | .vm_end = CONSISTENT_END, |
| 246 | }; |
| 247 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | #ifdef CONFIG_HUGETLB_PAGE |
| 249 | #error ARM Coherent DMA allocator does not (yet) support huge TLB |
| 250 | #endif |
| 251 | |
Russell King | 88c58f3 | 2009-11-19 16:46:02 +0000 | [diff] [blame] | 252 | /* |
| 253 | * Initialise the consistent memory allocation. |
| 254 | */ |
| 255 | static int __init consistent_init(void) |
| 256 | { |
| 257 | int ret = 0; |
| 258 | pgd_t *pgd; |
Russell King | 516295e | 2010-11-21 16:27:49 +0000 | [diff] [blame] | 259 | pud_t *pud; |
Russell King | 88c58f3 | 2009-11-19 16:46:02 +0000 | [diff] [blame] | 260 | pmd_t *pmd; |
| 261 | pte_t *pte; |
| 262 | int i = 0; |
Jon Medhurst | 99d1717 | 2011-08-02 17:28:27 +0100 | [diff] [blame] | 263 | unsigned long base = consistent_base; |
Catalin Marinas | 53cbcbc | 2011-11-17 13:11:21 +0100 | [diff] [blame] | 264 | unsigned long num_ptes = (CONSISTENT_END - base) >> PMD_SHIFT; |
Jon Medhurst | 99d1717 | 2011-08-02 17:28:27 +0100 | [diff] [blame] | 265 | |
Marek Szyprowski | 5ee6b06 | 2012-05-30 10:48:29 +0200 | [diff] [blame] | 266 | if (IS_ENABLED(CONFIG_CMA) && !IS_ENABLED(CONFIG_ARM_DMA_USE_IOMMU)) |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 267 | return 0; |
| 268 | |
Jon Medhurst | 99d1717 | 2011-08-02 17:28:27 +0100 | [diff] [blame] | 269 | consistent_pte = kmalloc(num_ptes * sizeof(pte_t), GFP_KERNEL); |
| 270 | if (!consistent_pte) { |
| 271 | pr_err("%s: no memory\n", __func__); |
| 272 | return -ENOMEM; |
| 273 | } |
| 274 | |
| 275 | pr_debug("DMA memory: 0x%08lx - 0x%08lx:\n", base, CONSISTENT_END); |
| 276 | consistent_head.vm_start = base; |
Russell King | 88c58f3 | 2009-11-19 16:46:02 +0000 | [diff] [blame] | 277 | |
| 278 | do { |
| 279 | pgd = pgd_offset(&init_mm, base); |
Russell King | 516295e | 2010-11-21 16:27:49 +0000 | [diff] [blame] | 280 | |
| 281 | pud = pud_alloc(&init_mm, pgd, base); |
| 282 | if (!pud) { |
Marek Szyprowski | e2a8e41 | 2012-02-28 10:19:14 +0100 | [diff] [blame] | 283 | pr_err("%s: no pud tables\n", __func__); |
Russell King | 516295e | 2010-11-21 16:27:49 +0000 | [diff] [blame] | 284 | ret = -ENOMEM; |
| 285 | break; |
| 286 | } |
| 287 | |
| 288 | pmd = pmd_alloc(&init_mm, pud, base); |
Russell King | 88c58f3 | 2009-11-19 16:46:02 +0000 | [diff] [blame] | 289 | if (!pmd) { |
Marek Szyprowski | e2a8e41 | 2012-02-28 10:19:14 +0100 | [diff] [blame] | 290 | pr_err("%s: no pmd tables\n", __func__); |
Russell King | 88c58f3 | 2009-11-19 16:46:02 +0000 | [diff] [blame] | 291 | ret = -ENOMEM; |
| 292 | break; |
| 293 | } |
| 294 | WARN_ON(!pmd_none(*pmd)); |
| 295 | |
| 296 | pte = pte_alloc_kernel(pmd, base); |
| 297 | if (!pte) { |
Marek Szyprowski | e2a8e41 | 2012-02-28 10:19:14 +0100 | [diff] [blame] | 298 | pr_err("%s: no pte tables\n", __func__); |
Russell King | 88c58f3 | 2009-11-19 16:46:02 +0000 | [diff] [blame] | 299 | ret = -ENOMEM; |
| 300 | break; |
| 301 | } |
| 302 | |
| 303 | consistent_pte[i++] = pte; |
Catalin Marinas | e73fc88 | 2011-08-23 14:07:23 +0100 | [diff] [blame] | 304 | base += PMD_SIZE; |
Russell King | 88c58f3 | 2009-11-19 16:46:02 +0000 | [diff] [blame] | 305 | } while (base < CONSISTENT_END); |
| 306 | |
| 307 | return ret; |
| 308 | } |
Russell King | 88c58f3 | 2009-11-19 16:46:02 +0000 | [diff] [blame] | 309 | core_initcall(consistent_init); |
| 310 | |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 311 | static void *__alloc_from_contiguous(struct device *dev, size_t size, |
| 312 | pgprot_t prot, struct page **ret_page); |
| 313 | |
| 314 | static struct arm_vmregion_head coherent_head = { |
| 315 | .vm_lock = __SPIN_LOCK_UNLOCKED(&coherent_head.vm_lock), |
| 316 | .vm_list = LIST_HEAD_INIT(coherent_head.vm_list), |
| 317 | }; |
| 318 | |
| 319 | size_t coherent_pool_size = DEFAULT_CONSISTENT_DMA_SIZE / 8; |
| 320 | |
| 321 | static int __init early_coherent_pool(char *p) |
| 322 | { |
| 323 | coherent_pool_size = memparse(p, &p); |
| 324 | return 0; |
| 325 | } |
| 326 | early_param("coherent_pool", early_coherent_pool); |
| 327 | |
| 328 | /* |
| 329 | * Initialise the coherent pool for atomic allocations. |
| 330 | */ |
| 331 | static int __init coherent_init(void) |
| 332 | { |
| 333 | pgprot_t prot = pgprot_dmacoherent(pgprot_kernel); |
| 334 | size_t size = coherent_pool_size; |
| 335 | struct page *page; |
| 336 | void *ptr; |
| 337 | |
Marek Szyprowski | 5ee6b06 | 2012-05-30 10:48:29 +0200 | [diff] [blame] | 338 | if (!IS_ENABLED(CONFIG_CMA)) |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 339 | return 0; |
| 340 | |
| 341 | ptr = __alloc_from_contiguous(NULL, size, prot, &page); |
| 342 | if (ptr) { |
| 343 | coherent_head.vm_start = (unsigned long) ptr; |
| 344 | coherent_head.vm_end = (unsigned long) ptr + size; |
| 345 | printk(KERN_INFO "DMA: preallocated %u KiB pool for atomic coherent allocations\n", |
| 346 | (unsigned)size / 1024); |
| 347 | return 0; |
| 348 | } |
| 349 | printk(KERN_ERR "DMA: failed to allocate %u KiB pool for atomic coherent allocation\n", |
| 350 | (unsigned)size / 1024); |
| 351 | return -ENOMEM; |
| 352 | } |
| 353 | /* |
| 354 | * CMA is activated by core_initcall, so we must be called after it. |
| 355 | */ |
| 356 | postcore_initcall(coherent_init); |
| 357 | |
| 358 | struct dma_contig_early_reserve { |
| 359 | phys_addr_t base; |
| 360 | unsigned long size; |
| 361 | }; |
| 362 | |
| 363 | static struct dma_contig_early_reserve dma_mmu_remap[MAX_CMA_AREAS] __initdata; |
| 364 | |
| 365 | static int dma_mmu_remap_num __initdata; |
| 366 | |
| 367 | void __init dma_contiguous_early_fixup(phys_addr_t base, unsigned long size) |
| 368 | { |
| 369 | dma_mmu_remap[dma_mmu_remap_num].base = base; |
| 370 | dma_mmu_remap[dma_mmu_remap_num].size = size; |
| 371 | dma_mmu_remap_num++; |
| 372 | } |
| 373 | |
| 374 | void __init dma_contiguous_remap(void) |
| 375 | { |
| 376 | int i; |
| 377 | for (i = 0; i < dma_mmu_remap_num; i++) { |
| 378 | phys_addr_t start = dma_mmu_remap[i].base; |
| 379 | phys_addr_t end = start + dma_mmu_remap[i].size; |
| 380 | struct map_desc map; |
| 381 | unsigned long addr; |
| 382 | |
| 383 | if (end > arm_lowmem_limit) |
| 384 | end = arm_lowmem_limit; |
| 385 | if (start >= end) |
| 386 | return; |
| 387 | |
| 388 | map.pfn = __phys_to_pfn(start); |
| 389 | map.virtual = __phys_to_virt(start); |
| 390 | map.length = end - start; |
| 391 | map.type = MT_MEMORY_DMA_READY; |
| 392 | |
| 393 | /* |
| 394 | * Clear previous low-memory mapping |
| 395 | */ |
| 396 | for (addr = __phys_to_virt(start); addr < __phys_to_virt(end); |
| 397 | addr += PGDIR_SIZE) |
| 398 | pmd_clear(pmd_off_k(addr)); |
| 399 | |
| 400 | iotable_init(&map, 1); |
| 401 | } |
| 402 | } |
| 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | static void * |
Russell King | 45cd529 | 2012-01-12 23:08:07 +0000 | [diff] [blame] | 405 | __dma_alloc_remap(struct page *page, size_t size, gfp_t gfp, pgprot_t prot, |
| 406 | const void *caller) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | { |
Russell King | 13ccf3a | 2009-11-19 15:07:04 +0000 | [diff] [blame] | 408 | struct arm_vmregion *c; |
Russell King | 5bc23d3 | 2010-07-25 08:57:02 +0100 | [diff] [blame] | 409 | size_t align; |
| 410 | int bit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | |
Jon Medhurst | 99d1717 | 2011-08-02 17:28:27 +0100 | [diff] [blame] | 412 | if (!consistent_pte) { |
Marek Szyprowski | e2a8e41 | 2012-02-28 10:19:14 +0100 | [diff] [blame] | 413 | pr_err("%s: not initialised\n", __func__); |
Russell King | ebd7a84 | 2009-11-19 20:58:31 +0000 | [diff] [blame] | 414 | dump_stack(); |
Russell King | ebd7a84 | 2009-11-19 20:58:31 +0000 | [diff] [blame] | 415 | return NULL; |
| 416 | } |
| 417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | /* |
Russell King | 5bc23d3 | 2010-07-25 08:57:02 +0100 | [diff] [blame] | 419 | * Align the virtual region allocation - maximum alignment is |
| 420 | * a section size, minimum is a page size. This helps reduce |
| 421 | * fragmentation of the DMA space, and also prevents allocations |
| 422 | * smaller than a section from crossing a section boundary. |
| 423 | */ |
Russell King | c947f69 | 2010-11-03 16:00:15 +0000 | [diff] [blame] | 424 | bit = fls(size - 1); |
Russell King | 5bc23d3 | 2010-07-25 08:57:02 +0100 | [diff] [blame] | 425 | if (bit > SECTION_SHIFT) |
| 426 | bit = SECTION_SHIFT; |
| 427 | align = 1 << bit; |
| 428 | |
| 429 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | * Allocate a virtual address in the consistent mapping region. |
| 431 | */ |
Russell King | 5bc23d3 | 2010-07-25 08:57:02 +0100 | [diff] [blame] | 432 | c = arm_vmregion_alloc(&consistent_head, align, size, |
Russell King | 45cd529 | 2012-01-12 23:08:07 +0000 | [diff] [blame] | 433 | gfp & ~(__GFP_DMA | __GFP_HIGHMEM), caller); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | if (c) { |
Kevin Hilman | 37134cd | 2006-01-12 16:12:21 +0000 | [diff] [blame] | 435 | pte_t *pte; |
Kevin Hilman | 37134cd | 2006-01-12 16:12:21 +0000 | [diff] [blame] | 436 | int idx = CONSISTENT_PTE_INDEX(c->vm_start); |
| 437 | u32 off = CONSISTENT_OFFSET(c->vm_start) & (PTRS_PER_PTE-1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | |
Kevin Hilman | 37134cd | 2006-01-12 16:12:21 +0000 | [diff] [blame] | 439 | pte = consistent_pte[idx] + off; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | c->vm_pages = page; |
| 441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | do { |
| 443 | BUG_ON(!pte_none(*pte)); |
| 444 | |
Russell King | ad1ae2f | 2006-12-13 14:34:43 +0000 | [diff] [blame] | 445 | set_pte_ext(pte, mk_pte(page, prot), 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | page++; |
| 447 | pte++; |
Kevin Hilman | 37134cd | 2006-01-12 16:12:21 +0000 | [diff] [blame] | 448 | off++; |
| 449 | if (off >= PTRS_PER_PTE) { |
| 450 | off = 0; |
| 451 | pte = consistent_pte[++idx]; |
| 452 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | } while (size -= PAGE_SIZE); |
| 454 | |
Russell King | 2be23c4 | 2010-09-08 16:27:56 +0100 | [diff] [blame] | 455 | dsb(); |
| 456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | return (void *)c->vm_start; |
| 458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | return NULL; |
| 460 | } |
Russell King | 695ae0a | 2009-11-19 16:31:39 +0000 | [diff] [blame] | 461 | |
| 462 | static void __dma_free_remap(void *cpu_addr, size_t size) |
| 463 | { |
| 464 | struct arm_vmregion *c; |
| 465 | unsigned long addr; |
| 466 | pte_t *ptep; |
| 467 | int idx; |
| 468 | u32 off; |
| 469 | |
| 470 | c = arm_vmregion_find_remove(&consistent_head, (unsigned long)cpu_addr); |
| 471 | if (!c) { |
Marek Szyprowski | e2a8e41 | 2012-02-28 10:19:14 +0100 | [diff] [blame] | 472 | pr_err("%s: trying to free invalid coherent area: %p\n", |
Russell King | 695ae0a | 2009-11-19 16:31:39 +0000 | [diff] [blame] | 473 | __func__, cpu_addr); |
| 474 | dump_stack(); |
| 475 | return; |
| 476 | } |
| 477 | |
| 478 | if ((c->vm_end - c->vm_start) != size) { |
Marek Szyprowski | e2a8e41 | 2012-02-28 10:19:14 +0100 | [diff] [blame] | 479 | pr_err("%s: freeing wrong coherent size (%ld != %d)\n", |
Russell King | 695ae0a | 2009-11-19 16:31:39 +0000 | [diff] [blame] | 480 | __func__, c->vm_end - c->vm_start, size); |
| 481 | dump_stack(); |
| 482 | size = c->vm_end - c->vm_start; |
| 483 | } |
| 484 | |
| 485 | idx = CONSISTENT_PTE_INDEX(c->vm_start); |
| 486 | off = CONSISTENT_OFFSET(c->vm_start) & (PTRS_PER_PTE-1); |
| 487 | ptep = consistent_pte[idx] + off; |
| 488 | addr = c->vm_start; |
| 489 | do { |
| 490 | pte_t pte = ptep_get_and_clear(&init_mm, addr, ptep); |
Russell King | 695ae0a | 2009-11-19 16:31:39 +0000 | [diff] [blame] | 491 | |
| 492 | ptep++; |
| 493 | addr += PAGE_SIZE; |
| 494 | off++; |
| 495 | if (off >= PTRS_PER_PTE) { |
| 496 | off = 0; |
| 497 | ptep = consistent_pte[++idx]; |
| 498 | } |
| 499 | |
Russell King | acaac25 | 2009-11-20 18:19:52 +0000 | [diff] [blame] | 500 | if (pte_none(pte) || !pte_present(pte)) |
Marek Szyprowski | e2a8e41 | 2012-02-28 10:19:14 +0100 | [diff] [blame] | 501 | pr_crit("%s: bad page in kernel page table\n", |
| 502 | __func__); |
Russell King | 695ae0a | 2009-11-19 16:31:39 +0000 | [diff] [blame] | 503 | } while (size -= PAGE_SIZE); |
| 504 | |
| 505 | flush_tlb_kernel_range(c->vm_start, c->vm_end); |
| 506 | |
| 507 | arm_vmregion_free(&consistent_head, c); |
| 508 | } |
| 509 | |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 510 | static int __dma_update_pte(pte_t *pte, pgtable_t token, unsigned long addr, |
| 511 | void *data) |
| 512 | { |
| 513 | struct page *page = virt_to_page(addr); |
| 514 | pgprot_t prot = *(pgprot_t *)data; |
| 515 | |
| 516 | set_pte_ext(pte, mk_pte(page, prot), 0); |
| 517 | return 0; |
| 518 | } |
| 519 | |
| 520 | static void __dma_remap(struct page *page, size_t size, pgprot_t prot) |
| 521 | { |
| 522 | unsigned long start = (unsigned long) page_address(page); |
| 523 | unsigned end = start + size; |
| 524 | |
| 525 | apply_to_page_range(&init_mm, start, size, __dma_update_pte, &prot); |
| 526 | dsb(); |
| 527 | flush_tlb_kernel_range(start, end); |
| 528 | } |
| 529 | |
| 530 | static void *__alloc_remap_buffer(struct device *dev, size_t size, gfp_t gfp, |
| 531 | pgprot_t prot, struct page **ret_page, |
| 532 | const void *caller) |
| 533 | { |
| 534 | struct page *page; |
| 535 | void *ptr; |
| 536 | page = __dma_alloc_buffer(dev, size, gfp); |
| 537 | if (!page) |
| 538 | return NULL; |
| 539 | |
| 540 | ptr = __dma_alloc_remap(page, size, gfp, prot, caller); |
| 541 | if (!ptr) { |
| 542 | __dma_free_buffer(page, size); |
| 543 | return NULL; |
| 544 | } |
| 545 | |
| 546 | *ret_page = page; |
| 547 | return ptr; |
| 548 | } |
| 549 | |
| 550 | static void *__alloc_from_pool(struct device *dev, size_t size, |
| 551 | struct page **ret_page, const void *caller) |
| 552 | { |
| 553 | struct arm_vmregion *c; |
| 554 | size_t align; |
| 555 | |
| 556 | if (!coherent_head.vm_start) { |
| 557 | printk(KERN_ERR "%s: coherent pool not initialised!\n", |
| 558 | __func__); |
| 559 | dump_stack(); |
| 560 | return NULL; |
| 561 | } |
| 562 | |
| 563 | /* |
| 564 | * Align the region allocation - allocations from pool are rather |
| 565 | * small, so align them to their order in pages, minimum is a page |
| 566 | * size. This helps reduce fragmentation of the DMA space. |
| 567 | */ |
| 568 | align = PAGE_SIZE << get_order(size); |
| 569 | c = arm_vmregion_alloc(&coherent_head, align, size, 0, caller); |
| 570 | if (c) { |
| 571 | void *ptr = (void *)c->vm_start; |
| 572 | struct page *page = virt_to_page(ptr); |
| 573 | *ret_page = page; |
| 574 | return ptr; |
| 575 | } |
| 576 | return NULL; |
| 577 | } |
| 578 | |
| 579 | static int __free_from_pool(void *cpu_addr, size_t size) |
| 580 | { |
| 581 | unsigned long start = (unsigned long)cpu_addr; |
| 582 | unsigned long end = start + size; |
| 583 | struct arm_vmregion *c; |
| 584 | |
| 585 | if (start < coherent_head.vm_start || end > coherent_head.vm_end) |
| 586 | return 0; |
| 587 | |
| 588 | c = arm_vmregion_find_remove(&coherent_head, (unsigned long)start); |
| 589 | |
| 590 | if ((c->vm_end - c->vm_start) != size) { |
| 591 | printk(KERN_ERR "%s: freeing wrong coherent size (%ld != %d)\n", |
| 592 | __func__, c->vm_end - c->vm_start, size); |
| 593 | dump_stack(); |
| 594 | size = c->vm_end - c->vm_start; |
| 595 | } |
| 596 | |
| 597 | arm_vmregion_free(&coherent_head, c); |
| 598 | return 1; |
| 599 | } |
| 600 | |
| 601 | static void *__alloc_from_contiguous(struct device *dev, size_t size, |
| 602 | pgprot_t prot, struct page **ret_page) |
| 603 | { |
| 604 | unsigned long order = get_order(size); |
| 605 | size_t count = size >> PAGE_SHIFT; |
| 606 | struct page *page; |
| 607 | |
| 608 | page = dma_alloc_from_contiguous(dev, count, order); |
| 609 | if (!page) |
| 610 | return NULL; |
| 611 | |
| 612 | __dma_clear_buffer(page, size); |
| 613 | __dma_remap(page, size, prot); |
| 614 | |
| 615 | *ret_page = page; |
| 616 | return page_address(page); |
| 617 | } |
| 618 | |
| 619 | static void __free_from_contiguous(struct device *dev, struct page *page, |
| 620 | size_t size) |
| 621 | { |
| 622 | __dma_remap(page, size, pgprot_kernel); |
| 623 | dma_release_from_contiguous(dev, page, size >> PAGE_SHIFT); |
| 624 | } |
| 625 | |
Marek Szyprowski | f8f9d07 | 2012-05-16 18:31:23 +0200 | [diff] [blame^] | 626 | static inline pgprot_t __get_dma_pgprot(struct dma_attrs *attrs, pgprot_t prot) |
| 627 | { |
| 628 | prot = dma_get_attr(DMA_ATTR_WRITE_COMBINE, attrs) ? |
| 629 | pgprot_writecombine(prot) : |
| 630 | pgprot_dmacoherent(prot); |
| 631 | return prot; |
| 632 | } |
| 633 | |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 634 | #define nommu() 0 |
| 635 | |
Catalin Marinas | ab6494f | 2009-07-24 12:35:02 +0100 | [diff] [blame] | 636 | #else /* !CONFIG_MMU */ |
Russell King | 695ae0a | 2009-11-19 16:31:39 +0000 | [diff] [blame] | 637 | |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 638 | #define nommu() 1 |
| 639 | |
| 640 | #define __alloc_remap_buffer(dev, size, gfp, prot, ret, c) NULL |
| 641 | #define __alloc_from_pool(dev, size, ret_page, c) NULL |
| 642 | #define __alloc_from_contiguous(dev, size, prot, ret) NULL |
| 643 | #define __free_from_pool(cpu_addr, size) 0 |
| 644 | #define __free_from_contiguous(dev, page, size) do { } while (0) |
| 645 | #define __dma_free_remap(cpu_addr, size) do { } while (0) |
Marek Szyprowski | f8f9d07 | 2012-05-16 18:31:23 +0200 | [diff] [blame^] | 646 | #define __get_dma_pgprot(attrs, prot) __pgprot(0) |
Russell King | 31ebf94 | 2009-11-19 21:12:17 +0000 | [diff] [blame] | 647 | |
| 648 | #endif /* CONFIG_MMU */ |
| 649 | |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 650 | static void *__alloc_simple_buffer(struct device *dev, size_t size, gfp_t gfp, |
| 651 | struct page **ret_page) |
Catalin Marinas | ab6494f | 2009-07-24 12:35:02 +0100 | [diff] [blame] | 652 | { |
Russell King | 04da569 | 2009-11-19 15:54:45 +0000 | [diff] [blame] | 653 | struct page *page; |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 654 | page = __dma_alloc_buffer(dev, size, gfp); |
| 655 | if (!page) |
| 656 | return NULL; |
| 657 | |
| 658 | *ret_page = page; |
| 659 | return page_address(page); |
| 660 | } |
| 661 | |
| 662 | |
| 663 | |
| 664 | static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, |
| 665 | gfp_t gfp, pgprot_t prot, const void *caller) |
| 666 | { |
| 667 | u64 mask = get_coherent_dma_mask(dev); |
| 668 | struct page *page; |
Russell King | 31ebf94 | 2009-11-19 21:12:17 +0000 | [diff] [blame] | 669 | void *addr; |
Catalin Marinas | ab6494f | 2009-07-24 12:35:02 +0100 | [diff] [blame] | 670 | |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 671 | #ifdef CONFIG_DMA_API_DEBUG |
| 672 | u64 limit = (mask + 1) & ~mask; |
| 673 | if (limit && size >= limit) { |
| 674 | dev_warn(dev, "coherent allocation too big (requested %#x mask %#llx)\n", |
| 675 | size, mask); |
| 676 | return NULL; |
| 677 | } |
| 678 | #endif |
| 679 | |
| 680 | if (!mask) |
| 681 | return NULL; |
| 682 | |
| 683 | if (mask < 0xffffffffULL) |
| 684 | gfp |= GFP_DMA; |
| 685 | |
Sumit Bhattacharya | ea2e705 | 2011-11-24 00:47:12 +0100 | [diff] [blame] | 686 | /* |
| 687 | * Following is a work-around (a.k.a. hack) to prevent pages |
| 688 | * with __GFP_COMP being passed to split_page() which cannot |
| 689 | * handle them. The real problem is that this flag probably |
| 690 | * should be 0 on ARM as it is not supported on this |
| 691 | * platform; see CONFIG_HUGETLBFS. |
| 692 | */ |
| 693 | gfp &= ~(__GFP_COMP); |
| 694 | |
Marek Szyprowski | 1dc8f00 | 2012-02-29 14:45:28 +0100 | [diff] [blame] | 695 | *handle = DMA_ERROR_CODE; |
Russell King | 04da569 | 2009-11-19 15:54:45 +0000 | [diff] [blame] | 696 | size = PAGE_ALIGN(size); |
| 697 | |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 698 | if (arch_is_coherent() || nommu()) |
| 699 | addr = __alloc_simple_buffer(dev, size, gfp, &page); |
Marek Szyprowski | 5ee6b06 | 2012-05-30 10:48:29 +0200 | [diff] [blame] | 700 | else if (!IS_ENABLED(CONFIG_CMA)) |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 701 | addr = __alloc_remap_buffer(dev, size, gfp, prot, &page, caller); |
| 702 | else if (gfp & GFP_ATOMIC) |
| 703 | addr = __alloc_from_pool(dev, size, &page, caller); |
Russell King | 31ebf94 | 2009-11-19 21:12:17 +0000 | [diff] [blame] | 704 | else |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 705 | addr = __alloc_from_contiguous(dev, size, prot, &page); |
Russell King | 31ebf94 | 2009-11-19 21:12:17 +0000 | [diff] [blame] | 706 | |
| 707 | if (addr) |
Russell King | 9eedd96 | 2011-01-03 00:00:17 +0000 | [diff] [blame] | 708 | *handle = pfn_to_dma(dev, page_to_pfn(page)); |
Russell King | 31ebf94 | 2009-11-19 21:12:17 +0000 | [diff] [blame] | 709 | |
| 710 | return addr; |
Catalin Marinas | ab6494f | 2009-07-24 12:35:02 +0100 | [diff] [blame] | 711 | } |
Russell King | 695ae0a | 2009-11-19 16:31:39 +0000 | [diff] [blame] | 712 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | /* |
| 714 | * Allocate DMA-coherent memory space and return both the kernel remapped |
| 715 | * virtual and bus address for that space. |
| 716 | */ |
Marek Szyprowski | f8f9d07 | 2012-05-16 18:31:23 +0200 | [diff] [blame^] | 717 | void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle, |
| 718 | gfp_t gfp, struct dma_attrs *attrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 719 | { |
Marek Szyprowski | f8f9d07 | 2012-05-16 18:31:23 +0200 | [diff] [blame^] | 720 | pgprot_t prot = __get_dma_pgprot(attrs, pgprot_kernel); |
Dmitry Baryshkov | 1fe5326 | 2008-07-18 13:30:14 +0400 | [diff] [blame] | 721 | void *memory; |
| 722 | |
| 723 | if (dma_alloc_from_coherent(dev, size, handle, &memory)) |
| 724 | return memory; |
| 725 | |
Marek Szyprowski | f8f9d07 | 2012-05-16 18:31:23 +0200 | [diff] [blame^] | 726 | return __dma_alloc(dev, size, handle, gfp, prot, |
Russell King | 45cd529 | 2012-01-12 23:08:07 +0000 | [diff] [blame] | 727 | __builtin_return_address(0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | |
| 730 | /* |
Marek Szyprowski | f8f9d07 | 2012-05-16 18:31:23 +0200 | [diff] [blame^] | 731 | * Create userspace mapping for the DMA-coherent memory. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | */ |
Marek Szyprowski | f8f9d07 | 2012-05-16 18:31:23 +0200 | [diff] [blame^] | 733 | int arm_dma_mmap(struct device *dev, struct vm_area_struct *vma, |
| 734 | void *cpu_addr, dma_addr_t dma_addr, size_t size, |
| 735 | struct dma_attrs *attrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | { |
Catalin Marinas | ab6494f | 2009-07-24 12:35:02 +0100 | [diff] [blame] | 737 | int ret = -ENXIO; |
| 738 | #ifdef CONFIG_MMU |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 739 | unsigned long pfn = dma_to_pfn(dev, dma_addr); |
Marek Szyprowski | f8f9d07 | 2012-05-16 18:31:23 +0200 | [diff] [blame^] | 740 | vma->vm_page_prot = __get_dma_pgprot(attrs, vma->vm_page_prot); |
Marek Szyprowski | f504f8e | 2012-05-15 19:04:13 +0200 | [diff] [blame] | 741 | |
| 742 | if (dma_mmap_from_coherent(dev, vma, cpu_addr, size, &ret)) |
| 743 | return ret; |
| 744 | |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 745 | ret = remap_pfn_range(vma, vma->vm_start, |
| 746 | pfn + vma->vm_pgoff, |
| 747 | vma->vm_end - vma->vm_start, |
| 748 | vma->vm_page_prot); |
Catalin Marinas | ab6494f | 2009-07-24 12:35:02 +0100 | [diff] [blame] | 749 | #endif /* CONFIG_MMU */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | |
| 751 | return ret; |
| 752 | } |
| 753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | /* |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 755 | * Free a buffer as defined by the above mapping. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | */ |
Marek Szyprowski | f8f9d07 | 2012-05-16 18:31:23 +0200 | [diff] [blame^] | 757 | void arm_dma_free(struct device *dev, size_t size, void *cpu_addr, |
| 758 | dma_addr_t handle, struct dma_attrs *attrs) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | { |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 760 | struct page *page = pfn_to_page(dma_to_pfn(dev, handle)); |
Russell King | 5edf71a | 2005-11-25 15:52:51 +0000 | [diff] [blame] | 761 | |
Dmitry Baryshkov | 1fe5326 | 2008-07-18 13:30:14 +0400 | [diff] [blame] | 762 | if (dma_release_from_coherent(dev, get_order(size), cpu_addr)) |
| 763 | return; |
| 764 | |
Russell King | 3e82d01 | 2009-11-19 15:38:12 +0000 | [diff] [blame] | 765 | size = PAGE_ALIGN(size); |
| 766 | |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 767 | if (arch_is_coherent() || nommu()) { |
| 768 | __dma_free_buffer(page, size); |
Marek Szyprowski | 5ee6b06 | 2012-05-30 10:48:29 +0200 | [diff] [blame] | 769 | } else if (!IS_ENABLED(CONFIG_CMA)) { |
Russell King | 695ae0a | 2009-11-19 16:31:39 +0000 | [diff] [blame] | 770 | __dma_free_remap(cpu_addr, size); |
Marek Szyprowski | d4398df | 2011-12-29 13:09:51 +0100 | [diff] [blame] | 771 | __dma_free_buffer(page, size); |
| 772 | } else { |
| 773 | if (__free_from_pool(cpu_addr, size)) |
| 774 | return; |
| 775 | /* |
| 776 | * Non-atomic allocations cannot be freed with IRQs disabled |
| 777 | */ |
| 778 | WARN_ON(irqs_disabled()); |
| 779 | __free_from_contiguous(dev, page, size); |
| 780 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
Russell King | 65af191 | 2009-11-24 17:53:33 +0000 | [diff] [blame] | 783 | static void dma_cache_maint_page(struct page *page, unsigned long offset, |
Russell King | a9c9147 | 2009-11-26 16:19:58 +0000 | [diff] [blame] | 784 | size_t size, enum dma_data_direction dir, |
| 785 | void (*op)(const void *, size_t, int)) |
Russell King | 65af191 | 2009-11-24 17:53:33 +0000 | [diff] [blame] | 786 | { |
| 787 | /* |
| 788 | * A single sg entry may refer to multiple physically contiguous |
| 789 | * pages. But we still need to process highmem pages individually. |
| 790 | * If highmem is not configured then the bulk of this loop gets |
| 791 | * optimized out. |
| 792 | */ |
| 793 | size_t left = size; |
| 794 | do { |
| 795 | size_t len = left; |
Russell King | 93f1d62 | 2009-11-24 14:41:01 +0000 | [diff] [blame] | 796 | void *vaddr; |
| 797 | |
| 798 | if (PageHighMem(page)) { |
| 799 | if (len + offset > PAGE_SIZE) { |
| 800 | if (offset >= PAGE_SIZE) { |
| 801 | page += offset / PAGE_SIZE; |
| 802 | offset %= PAGE_SIZE; |
| 803 | } |
| 804 | len = PAGE_SIZE - offset; |
Russell King | 65af191 | 2009-11-24 17:53:33 +0000 | [diff] [blame] | 805 | } |
Russell King | 93f1d62 | 2009-11-24 14:41:01 +0000 | [diff] [blame] | 806 | vaddr = kmap_high_get(page); |
| 807 | if (vaddr) { |
| 808 | vaddr += offset; |
Russell King | a9c9147 | 2009-11-26 16:19:58 +0000 | [diff] [blame] | 809 | op(vaddr, len, dir); |
Russell King | 93f1d62 | 2009-11-24 14:41:01 +0000 | [diff] [blame] | 810 | kunmap_high(page); |
Nicolas Pitre | 7e5a69e | 2010-03-29 21:46:02 +0100 | [diff] [blame] | 811 | } else if (cache_is_vipt()) { |
Nicolas Pitre | 39af22a | 2010-12-15 15:14:45 -0500 | [diff] [blame] | 812 | /* unmapped pages might still be cached */ |
| 813 | vaddr = kmap_atomic(page); |
Nicolas Pitre | 7e5a69e | 2010-03-29 21:46:02 +0100 | [diff] [blame] | 814 | op(vaddr + offset, len, dir); |
Nicolas Pitre | 39af22a | 2010-12-15 15:14:45 -0500 | [diff] [blame] | 815 | kunmap_atomic(vaddr); |
Russell King | 93f1d62 | 2009-11-24 14:41:01 +0000 | [diff] [blame] | 816 | } |
| 817 | } else { |
| 818 | vaddr = page_address(page) + offset; |
Russell King | a9c9147 | 2009-11-26 16:19:58 +0000 | [diff] [blame] | 819 | op(vaddr, len, dir); |
Russell King | 65af191 | 2009-11-24 17:53:33 +0000 | [diff] [blame] | 820 | } |
Russell King | 65af191 | 2009-11-24 17:53:33 +0000 | [diff] [blame] | 821 | offset = 0; |
| 822 | page++; |
| 823 | left -= len; |
| 824 | } while (left); |
| 825 | } |
| 826 | |
Marek Szyprowski | 53e207d | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 827 | /* |
| 828 | * Make an area consistent for devices. |
| 829 | * Note: Drivers should NOT use this function directly, as it will break |
| 830 | * platforms with CONFIG_DMABOUNCE. |
| 831 | * Use the driver DMA support - see dma-mapping.h (dma_sync_*) |
| 832 | */ |
| 833 | static void __dma_page_cpu_to_dev(struct page *page, unsigned long off, |
Russell King | 65af191 | 2009-11-24 17:53:33 +0000 | [diff] [blame] | 834 | size_t size, enum dma_data_direction dir) |
| 835 | { |
Nicolas Pitre | 4337745 | 2009-03-12 22:52:09 -0400 | [diff] [blame] | 836 | unsigned long paddr; |
Nicolas Pitre | 4337745 | 2009-03-12 22:52:09 -0400 | [diff] [blame] | 837 | |
Russell King | a9c9147 | 2009-11-26 16:19:58 +0000 | [diff] [blame] | 838 | dma_cache_maint_page(page, off, size, dir, dmac_map_area); |
Nicolas Pitre | 4337745 | 2009-03-12 22:52:09 -0400 | [diff] [blame] | 839 | |
Russell King | 65af191 | 2009-11-24 17:53:33 +0000 | [diff] [blame] | 840 | paddr = page_to_phys(page) + off; |
Russell King | 2ffe2da | 2009-10-31 16:52:16 +0000 | [diff] [blame] | 841 | if (dir == DMA_FROM_DEVICE) { |
| 842 | outer_inv_range(paddr, paddr + size); |
| 843 | } else { |
| 844 | outer_clean_range(paddr, paddr + size); |
| 845 | } |
| 846 | /* FIXME: non-speculating: flush on bidirectional mappings? */ |
Nicolas Pitre | 4337745 | 2009-03-12 22:52:09 -0400 | [diff] [blame] | 847 | } |
Russell King | 4ea0d73 | 2009-11-24 16:27:17 +0000 | [diff] [blame] | 848 | |
Marek Szyprowski | 53e207d | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 849 | static void __dma_page_dev_to_cpu(struct page *page, unsigned long off, |
Russell King | 4ea0d73 | 2009-11-24 16:27:17 +0000 | [diff] [blame] | 850 | size_t size, enum dma_data_direction dir) |
| 851 | { |
Russell King | 2ffe2da | 2009-10-31 16:52:16 +0000 | [diff] [blame] | 852 | unsigned long paddr = page_to_phys(page) + off; |
| 853 | |
| 854 | /* FIXME: non-speculating: not required */ |
| 855 | /* don't bother invalidating if DMA to device */ |
| 856 | if (dir != DMA_TO_DEVICE) |
| 857 | outer_inv_range(paddr, paddr + size); |
| 858 | |
Russell King | a9c9147 | 2009-11-26 16:19:58 +0000 | [diff] [blame] | 859 | dma_cache_maint_page(page, off, size, dir, dmac_unmap_area); |
Catalin Marinas | c017780 | 2010-09-13 15:57:36 +0100 | [diff] [blame] | 860 | |
| 861 | /* |
| 862 | * Mark the D-cache clean for this page to avoid extra flushing. |
| 863 | */ |
| 864 | if (dir != DMA_TO_DEVICE && off == 0 && size >= PAGE_SIZE) |
| 865 | set_bit(PG_dcache_clean, &page->flags); |
Russell King | 4ea0d73 | 2009-11-24 16:27:17 +0000 | [diff] [blame] | 866 | } |
Nicolas Pitre | 4337745 | 2009-03-12 22:52:09 -0400 | [diff] [blame] | 867 | |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 868 | /** |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 869 | * arm_dma_map_sg - map a set of SG buffers for streaming mode DMA |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 870 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices |
| 871 | * @sg: list of buffers |
| 872 | * @nents: number of buffers to map |
| 873 | * @dir: DMA transfer direction |
| 874 | * |
| 875 | * Map a set of buffers described by scatterlist in streaming mode for DMA. |
| 876 | * This is the scatter-gather version of the dma_map_single interface. |
| 877 | * Here the scatter gather list elements are each tagged with the |
| 878 | * appropriate dma address and length. They are obtained via |
| 879 | * sg_dma_{address,length}. |
| 880 | * |
| 881 | * Device ownership issues as mentioned for dma_map_single are the same |
| 882 | * here. |
| 883 | */ |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 884 | int arm_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents, |
| 885 | enum dma_data_direction dir, struct dma_attrs *attrs) |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 886 | { |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 887 | struct dma_map_ops *ops = get_dma_ops(dev); |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 888 | struct scatterlist *s; |
Russell King | 01135d9 | 2008-09-25 21:05:02 +0100 | [diff] [blame] | 889 | int i, j; |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 890 | |
| 891 | for_each_sg(sg, s, nents, i) { |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 892 | s->dma_address = ops->map_page(dev, sg_page(s), s->offset, |
| 893 | s->length, dir, attrs); |
Russell King | 01135d9 | 2008-09-25 21:05:02 +0100 | [diff] [blame] | 894 | if (dma_mapping_error(dev, s->dma_address)) |
| 895 | goto bad_mapping; |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 896 | } |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 897 | return nents; |
Russell King | 01135d9 | 2008-09-25 21:05:02 +0100 | [diff] [blame] | 898 | |
| 899 | bad_mapping: |
| 900 | for_each_sg(sg, s, i, j) |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 901 | ops->unmap_page(dev, sg_dma_address(s), sg_dma_len(s), dir, attrs); |
Russell King | 01135d9 | 2008-09-25 21:05:02 +0100 | [diff] [blame] | 902 | return 0; |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 903 | } |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 904 | |
| 905 | /** |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 906 | * arm_dma_unmap_sg - unmap a set of SG buffers mapped by dma_map_sg |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 907 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices |
| 908 | * @sg: list of buffers |
Linus Walleij | 0adfca6 | 2011-01-12 18:50:37 +0100 | [diff] [blame] | 909 | * @nents: number of buffers to unmap (same as was passed to dma_map_sg) |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 910 | * @dir: DMA transfer direction (same as was passed to dma_map_sg) |
| 911 | * |
| 912 | * Unmap a set of streaming mode DMA translations. Again, CPU access |
| 913 | * rules concerning calls here are the same as for dma_unmap_single(). |
| 914 | */ |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 915 | void arm_dma_unmap_sg(struct device *dev, struct scatterlist *sg, int nents, |
| 916 | enum dma_data_direction dir, struct dma_attrs *attrs) |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 917 | { |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 918 | struct dma_map_ops *ops = get_dma_ops(dev); |
Russell King | 01135d9 | 2008-09-25 21:05:02 +0100 | [diff] [blame] | 919 | struct scatterlist *s; |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 920 | |
Russell King | 01135d9 | 2008-09-25 21:05:02 +0100 | [diff] [blame] | 921 | int i; |
| 922 | |
| 923 | for_each_sg(sg, s, nents, i) |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 924 | ops->unmap_page(dev, sg_dma_address(s), sg_dma_len(s), dir, attrs); |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 925 | } |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 926 | |
| 927 | /** |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 928 | * arm_dma_sync_sg_for_cpu |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 929 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices |
| 930 | * @sg: list of buffers |
| 931 | * @nents: number of buffers to map (returned from dma_map_sg) |
| 932 | * @dir: DMA transfer direction (same as was passed to dma_map_sg) |
| 933 | */ |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 934 | void arm_dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *sg, |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 935 | int nents, enum dma_data_direction dir) |
| 936 | { |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 937 | struct dma_map_ops *ops = get_dma_ops(dev); |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 938 | struct scatterlist *s; |
| 939 | int i; |
| 940 | |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 941 | for_each_sg(sg, s, nents, i) |
| 942 | ops->sync_single_for_cpu(dev, sg_dma_address(s), s->length, |
| 943 | dir); |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 944 | } |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 945 | |
| 946 | /** |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 947 | * arm_dma_sync_sg_for_device |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 948 | * @dev: valid struct device pointer, or NULL for ISA and EISA-like devices |
| 949 | * @sg: list of buffers |
| 950 | * @nents: number of buffers to map (returned from dma_map_sg) |
| 951 | * @dir: DMA transfer direction (same as was passed to dma_map_sg) |
| 952 | */ |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 953 | void arm_dma_sync_sg_for_device(struct device *dev, struct scatterlist *sg, |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 954 | int nents, enum dma_data_direction dir) |
| 955 | { |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 956 | struct dma_map_ops *ops = get_dma_ops(dev); |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 957 | struct scatterlist *s; |
| 958 | int i; |
| 959 | |
Marek Szyprowski | 36dbd4c | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 960 | for_each_sg(sg, s, nents, i) |
| 961 | ops->sync_single_for_device(dev, sg_dma_address(s), s->length, |
| 962 | dir); |
Russell King | afd1a32 | 2008-09-25 16:30:57 +0100 | [diff] [blame] | 963 | } |
Russell King | 24056f5 | 2011-01-03 11:29:28 +0000 | [diff] [blame] | 964 | |
Russell King | 022ae53 | 2011-07-08 21:26:59 +0100 | [diff] [blame] | 965 | /* |
| 966 | * Return whether the given device DMA address mask can be supported |
| 967 | * properly. For example, if your device can only drive the low 24-bits |
| 968 | * during bus mastering, then you would pass 0x00ffffff as the mask |
| 969 | * to this function. |
| 970 | */ |
| 971 | int dma_supported(struct device *dev, u64 mask) |
| 972 | { |
| 973 | if (mask < (u64)arm_dma_limit) |
| 974 | return 0; |
| 975 | return 1; |
| 976 | } |
| 977 | EXPORT_SYMBOL(dma_supported); |
| 978 | |
Marek Szyprowski | e9bb4d1 | 2012-02-10 19:55:20 +0100 | [diff] [blame] | 979 | static int arm_dma_set_mask(struct device *dev, u64 dma_mask) |
Russell King | 022ae53 | 2011-07-08 21:26:59 +0100 | [diff] [blame] | 980 | { |
| 981 | if (!dev->dma_mask || !dma_supported(dev, dma_mask)) |
| 982 | return -EIO; |
| 983 | |
Russell King | 022ae53 | 2011-07-08 21:26:59 +0100 | [diff] [blame] | 984 | *dev->dma_mask = dma_mask; |
Russell King | 022ae53 | 2011-07-08 21:26:59 +0100 | [diff] [blame] | 985 | |
| 986 | return 0; |
| 987 | } |
Russell King | 022ae53 | 2011-07-08 21:26:59 +0100 | [diff] [blame] | 988 | |
Russell King | 24056f5 | 2011-01-03 11:29:28 +0000 | [diff] [blame] | 989 | #define PREALLOC_DMA_DEBUG_ENTRIES 4096 |
| 990 | |
| 991 | static int __init dma_debug_do_init(void) |
| 992 | { |
Russell King | 45cd529 | 2012-01-12 23:08:07 +0000 | [diff] [blame] | 993 | #ifdef CONFIG_MMU |
| 994 | arm_vmregion_create_proc("dma-mappings", &consistent_head); |
| 995 | #endif |
Russell King | 24056f5 | 2011-01-03 11:29:28 +0000 | [diff] [blame] | 996 | dma_debug_init(PREALLOC_DMA_DEBUG_ENTRIES); |
| 997 | return 0; |
| 998 | } |
| 999 | fs_initcall(dma_debug_do_init); |