Commit 4009793e15d44469da1547a46ab129cc08ffa503
Committed by
Marek Szyprowski
1 parent
387870f2d6
Exists in
smarc-l5.0.0_1.0.0-ga
and in
5 other branches
drivers: cma: represent physical addresses as phys_addr_t
This commit changes the CMA early initialization code to use phys_addr_t for representing physical addresses instead of unsigned long. Without this change, among other things, dma_declare_contiguous() simply discards any memory regions whose address is not representable as unsigned long. This is a problem on 32-bit PAE machines where unsigned long is 32-bit but physical address space is larger. Signed-off-by: Vitaly Andrianov <vitalya@ti.com> Signed-off-by: Cyril Chemparathy <cyril@ti.com> Acked-by: Michal Nazarewicz <mina86@mina86.com> Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com>
Showing 2 changed files with 12 additions and 16 deletions Side-by-side Diff
drivers/base/dma-contiguous.c
... | ... | @@ -57,8 +57,8 @@ |
57 | 57 | * Users, who want to set the size of global CMA area for their system |
58 | 58 | * should use cma= kernel parameter. |
59 | 59 | */ |
60 | -static const unsigned long size_bytes = CMA_SIZE_MBYTES * SZ_1M; | |
61 | -static long size_cmdline = -1; | |
60 | +static const phys_addr_t size_bytes = CMA_SIZE_MBYTES * SZ_1M; | |
61 | +static phys_addr_t size_cmdline = -1; | |
62 | 62 | |
63 | 63 | static int __init early_cma(char *p) |
64 | 64 | { |
... | ... | @@ -70,7 +70,7 @@ |
70 | 70 | |
71 | 71 | #ifdef CONFIG_CMA_SIZE_PERCENTAGE |
72 | 72 | |
73 | -static unsigned long __init __maybe_unused cma_early_percent_memory(void) | |
73 | +static phys_addr_t __init __maybe_unused cma_early_percent_memory(void) | |
74 | 74 | { |
75 | 75 | struct memblock_region *reg; |
76 | 76 | unsigned long total_pages = 0; |
... | ... | @@ -88,7 +88,7 @@ |
88 | 88 | |
89 | 89 | #else |
90 | 90 | |
91 | -static inline __maybe_unused unsigned long cma_early_percent_memory(void) | |
91 | +static inline __maybe_unused phys_addr_t cma_early_percent_memory(void) | |
92 | 92 | { |
93 | 93 | return 0; |
94 | 94 | } |
... | ... | @@ -106,7 +106,7 @@ |
106 | 106 | */ |
107 | 107 | void __init dma_contiguous_reserve(phys_addr_t limit) |
108 | 108 | { |
109 | - unsigned long selected_size = 0; | |
109 | + phys_addr_t selected_size = 0; | |
110 | 110 | |
111 | 111 | pr_debug("%s(limit %08lx)\n", __func__, (unsigned long)limit); |
112 | 112 | |
... | ... | @@ -126,7 +126,7 @@ |
126 | 126 | |
127 | 127 | if (selected_size) { |
128 | 128 | pr_debug("%s: reserving %ld MiB for global area\n", __func__, |
129 | - selected_size / SZ_1M); | |
129 | + (unsigned long)selected_size / SZ_1M); | |
130 | 130 | |
131 | 131 | dma_declare_contiguous(NULL, selected_size, 0, limit); |
132 | 132 | } |
133 | 133 | |
... | ... | @@ -227,11 +227,11 @@ |
227 | 227 | * called by board specific code when early allocator (memblock or bootmem) |
228 | 228 | * is still activate. |
229 | 229 | */ |
230 | -int __init dma_declare_contiguous(struct device *dev, unsigned long size, | |
230 | +int __init dma_declare_contiguous(struct device *dev, phys_addr_t size, | |
231 | 231 | phys_addr_t base, phys_addr_t limit) |
232 | 232 | { |
233 | 233 | struct cma_reserved *r = &cma_reserved[cma_reserved_count]; |
234 | - unsigned long alignment; | |
234 | + phys_addr_t alignment; | |
235 | 235 | |
236 | 236 | pr_debug("%s(size %lx, base %08lx, limit %08lx)\n", __func__, |
237 | 237 | (unsigned long)size, (unsigned long)base, |
... | ... | @@ -268,10 +268,6 @@ |
268 | 268 | if (!addr) { |
269 | 269 | base = -ENOMEM; |
270 | 270 | goto err; |
271 | - } else if (addr + size > ~(unsigned long)0) { | |
272 | - memblock_free(addr, size); | |
273 | - base = -EINVAL; | |
274 | - goto err; | |
275 | 271 | } else { |
276 | 272 | base = addr; |
277 | 273 | } |
278 | 274 | |
... | ... | @@ -285,14 +281,14 @@ |
285 | 281 | r->size = size; |
286 | 282 | r->dev = dev; |
287 | 283 | cma_reserved_count++; |
288 | - pr_info("CMA: reserved %ld MiB at %08lx\n", size / SZ_1M, | |
284 | + pr_info("CMA: reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M, | |
289 | 285 | (unsigned long)base); |
290 | 286 | |
291 | 287 | /* Architecture specific contiguous memory fixup. */ |
292 | 288 | dma_contiguous_early_fixup(base, size); |
293 | 289 | return 0; |
294 | 290 | err: |
295 | - pr_err("CMA: failed to reserve %ld MiB\n", size / SZ_1M); | |
291 | + pr_err("CMA: failed to reserve %ld MiB\n", (unsigned long)size / SZ_1M); | |
296 | 292 | return base; |
297 | 293 | } |
298 | 294 |
include/linux/dma-contiguous.h
... | ... | @@ -68,7 +68,7 @@ |
68 | 68 | extern struct cma *dma_contiguous_default_area; |
69 | 69 | |
70 | 70 | void dma_contiguous_reserve(phys_addr_t addr_limit); |
71 | -int dma_declare_contiguous(struct device *dev, unsigned long size, | |
71 | +int dma_declare_contiguous(struct device *dev, phys_addr_t size, | |
72 | 72 | phys_addr_t base, phys_addr_t limit); |
73 | 73 | |
74 | 74 | struct page *dma_alloc_from_contiguous(struct device *dev, int count, |
... | ... | @@ -83,7 +83,7 @@ |
83 | 83 | static inline void dma_contiguous_reserve(phys_addr_t limit) { } |
84 | 84 | |
85 | 85 | static inline |
86 | -int dma_declare_contiguous(struct device *dev, unsigned long size, | |
86 | +int dma_declare_contiguous(struct device *dev, phys_addr_t size, | |
87 | 87 | phys_addr_t base, phys_addr_t limit) |
88 | 88 | { |
89 | 89 | return -ENOSYS; |