Skip to content

Commit 39a2d35

Browse files
author
Christoph Hellwig
committed
dma-mapping: add a dma_init_global_coherent helper
Add a new helper to initialize the global coherent pool. This both cleans up the existing initialization which indirects through the reserved_mem_ops that are normally only used for struct device, and also allows using the global pool for non-devicetree architectures. Signed-off-by: Christoph Hellwig <[email protected]> Tested-by: Dillon Min <[email protected]>
1 parent a693357 commit 39a2d35

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

include/linux/dma-map-ops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void *dma_alloc_from_global_coherent(struct device *dev, ssize_t size,
177177
int dma_release_from_global_coherent(int order, void *vaddr);
178178
int dma_mmap_from_global_coherent(struct vm_area_struct *vma, void *cpu_addr,
179179
size_t size, int *ret);
180-
180+
int dma_init_global_coherent(phys_addr_t phys_addr, size_t size);
181181
#else
182182
static inline int dma_declare_coherent_memory(struct device *dev,
183183
phys_addr_t phys_addr, dma_addr_t device_addr, size_t size)

kernel/dma/coherent.c

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,18 @@ int dma_mmap_from_global_coherent(struct vm_area_struct *vma, void *vaddr,
300300
vaddr, size, ret);
301301
}
302302

303+
int dma_init_global_coherent(phys_addr_t phys_addr, size_t size)
304+
{
305+
struct dma_coherent_mem *mem;
306+
307+
mem = dma_init_coherent_memory(phys_addr, phys_addr, size, true);
308+
if (IS_ERR(mem))
309+
return PTR_ERR(mem);
310+
dma_coherent_default_memory = mem;
311+
pr_info("DMA: default coherent area is set\n");
312+
return 0;
313+
}
314+
303315
/*
304316
* Support for reserved memory regions defined in device tree
305317
*/
@@ -367,26 +379,10 @@ static int __init rmem_dma_setup(struct reserved_mem *rmem)
367379

368380
static int __init dma_init_reserved_memory(void)
369381
{
370-
const struct reserved_mem_ops *ops;
371-
int ret;
372-
373382
if (!dma_reserved_default_memory)
374383
return -ENOMEM;
375-
376-
ops = dma_reserved_default_memory->ops;
377-
378-
/*
379-
* We rely on rmem_dma_device_init() does not propagate error of
380-
* dma_assign_coherent_memory() for "NULL" device.
381-
*/
382-
ret = ops->device_init(dma_reserved_default_memory, NULL);
383-
384-
if (!ret) {
385-
dma_coherent_default_memory = dma_reserved_default_memory->priv;
386-
pr_info("DMA: default coherent area is set\n");
387-
}
388-
389-
return ret;
384+
return dma_init_global_coherent(dma_reserved_default_memory->base,
385+
dma_reserved_default_memory->size);
390386
}
391387

392388
core_initcall(dma_init_reserved_memory);

0 commit comments

Comments
 (0)