summaryrefslogtreecommitdiffstats
path: root/kernel/dma/coherent.c
Commit message (Collapse)AuthorAgeFilesLines
* dma-mapping: clear dev->dma_mem to NULL after freeing itJoakim Zhang2023-12-151-1/+3
| | | | | | | | | | | | | | Reproduced with below sequence: dma_declare_coherent_memory()->dma_release_coherent_memory() ->dma_declare_coherent_memory()->"return -EBUSY" error It will return -EBUSY from the dma_assign_coherent_memory() in dma_declare_coherent_memory(), the reason is that dev->dma_mem pointer has not been set to NULL after it's freed. Fixes: cf65a0f6f6ff ("dma-mapping: move all DMA mapping code to kernel/dma") Signed-off-by: Joakim Zhang <joakim.zhang@cixtech.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
* dma-mapping: Add dma_release_coherent_memory to DMA APIMark-PK Tsai2022-06-241-2/+8
| | | | | | | | | | | Add dma_release_coherent_memory to DMA API to allow dma user call it to release dev->dma_mem when the device is removed. Signed-off-by: Mark-PK Tsai <mark-pk.tsai@mediatek.com> Acked-by: Christoph Hellwig <hch@lst.de> Link: https://lore.kernel.org/r/20220422062436.14384-2-mark-pk.tsai@mediatek.com Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
* dma-mapping: use 'bitmap_zalloc()' when applicableChristophe JAILLET2021-10-271-3/+2
| | | | | | | | | | | | 'dma_mem->bitmap' is a bitmap. So use 'bitmap_zalloc()' to simplify code, improve the semantic and avoid some open-coded arithmetic in allocator arguments. Also change the corresponding 'kfree()' into 'bitmap_free()' to keep consistency. Signed-off-by: Christophe JAILLET <christophe.jaillet@wanadoo.fr> Signed-off-by: Christoph Hellwig <hch@lst.de>
* dma-mapping: make the global coherent pool conditionalChristoph Hellwig2021-08-191-22/+27
| | | | | | | | Only build the code to support the global coherent pool if support for it is enabled. Signed-off-by: Christoph Hellwig <hch@lst.de> Tested-by: Dillon Min <dillon.minfei@gmail.com>
* dma-mapping: add a dma_init_global_coherent helperChristoph Hellwig2021-08-181-18/+14
| | | | | | | | | | 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 <hch@lst.de> Tested-by: Dillon Min <dillon.minfei@gmail.com>
* dma-mapping: simplify dma_init_coherent_memoryChristoph Hellwig2021-08-181-45/+33
| | | | | | | | | Return the allocated dma_coherent_mem structure, set the use_dma_pfn_offset and print the failure warning inside of dma_init_coherent_memory instead of leaving that to the callers. Signed-off-by: Christoph Hellwig <hch@lst.de> Tested-by: Dillon Min <dillon.minfei@gmail.com>
* dma-mapping: allow using the global coherent pool for !ARMChristoph Hellwig2021-08-181-0/+2
| | | | | | | | | Switch an ifdef so that the global coherent pool is initialized for any architecture that selects the DMA_GLOBAL_POOL symbol insted of hardcoding ARM. Signed-off-by: Christoph Hellwig <hch@lst.de> Tested-by: Dillon Min <dillon.minfei@gmail.com>
* dma-mapping: remove a trailing spaceZhen Lei2021-06-221-1/+1
| | | | | Signed-off-by: Zhen Lei <thunder.leizhen@huawei.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
* dma-mapping: split <linux/dma-mapping.h>Christoph Hellwig2020-10-061-0/+1
| | | | | | | | | | | Split out all the bits that are purely for dma_map_ops implementations and related code into a new <linux/dma-map-ops.h> header so that they don't get pulled into all the drivers. That also means the architecture specific <asm/dma-mapping.h> is not pulled in by <linux/dma-mapping.h> any more, which leads to a missing includes that were pulled in by the x86 or arm versions in a few not overly portable drivers. Signed-off-by: Christoph Hellwig <hch@lst.de>
* dma-mapping: introduce DMA range map, supplanting dma_pfn_offsetJim Quinlan2020-09-171-4/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | The new field 'dma_range_map' in struct device is used to facilitate the use of single or multiple offsets between mapping regions of cpu addrs and dma addrs. It subsumes the role of "dev->dma_pfn_offset" which was only capable of holding a single uniform offset and had no region bounds checking. The function of_dma_get_range() has been modified so that it takes a single argument -- the device node -- and returns a map, NULL, or an error code. The map is an array that holds the information regarding the DMA regions. Each range entry contains the address offset, the cpu_start address, the dma_start address, and the size of the region. of_dma_configure() is the typical manner to set range offsets but there are a number of ad hoc assignments to "dev->dma_pfn_offset" in the kernel driver code. These cases now invoke the function dma_direct_set_offset(dev, cpu_addr, dma_addr, size). Signed-off-by: Jim Quinlan <james.quinlan@broadcom.com> [hch: various interface cleanups] Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Mathieu Poirier <mathieu.poirier@linaro.org> Tested-by: Mathieu Poirier <mathieu.poirier@linaro.org> Tested-by: Nathan Chancellor <natechancellor@gmail.com>
* dma-mapping: move the dma_declare_coherent_memory documentationChristoph Hellwig2020-09-111-0/+17
| | | | | | | | | dma_declare_coherent_memory should not be in a DMA API guide aimed at driver writers (that is consumers of the API). Move it to a comment near the function instead. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Robin Murphy <robin.murphy@arm.com>
* dma-coherent: fix integer overflow in the reserved-memory dma allocationKevin Grandemange2020-03-161-6/+7
| | | | | | | | | | | | | | | | | | | | | | pageno is an int and the PAGE_SHIFT shift is done on an int, overflowing if the memory is bigger than 2G This can be reproduced using for example a reserved-memory of 4G reserved-memory { #address-cells = <2>; #size-cells = <2>; ranges; reserved_dma: buffer@0 { compatible = "shared-dma-pool"; no-map; reg = <0x5 0x00000000 0x1 0x0>; }; }; Signed-off-by: Kevin Grandemange <kevin.grandemange@allegrodvt.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
* dma-mapping: fix handling of dma-ranges for reserved memory (again)Vladimir Murzin2019-10-301-7/+9
| | | | | | | | | | | | | | | | | Daniele reported that issue previously fixed in c41f9ea998f3 ("drivers: dma-coherent: Account dma_pfn_offset when used with device tree") reappear shortly after 43fc509c3efb ("dma-coherent: introduce interface for default DMA pool") where fix was accidentally dropped. Lets put fix back in place and respect dma-ranges for reserved memory. Fixes: 43fc509c3efb ("dma-coherent: introduce interface for default DMA pool") Reported-by: Daniele Alessandrelli <daniele.alessandrelli@gmail.com> Tested-by: Daniele Alessandrelli <daniele.alessandrelli@gmail.com> Tested-by: Alexandre Torgue <alexandre.torgue@st.com> Signed-off-by: Vladimir Murzin <vladimir.murzin@arm.com> Signed-off-by: Christoph Hellwig <hch@lst.de>
* dma-mapping: remove the dma_declare_coherent_memory exportChristoph Hellwig2019-09-041-1/+0
| | | | | | | | | dma_declare_coherent_memory is something that the platform setup code (which pretty much means the device tree these days) need to do so that drivers can use the memory as declared by the platform. Drivers themselves have no business calling this function. Signed-off-by: Christoph Hellwig <hch@lst.de>
* dma-mapping: remove the dma_mmap_from_dev_coherent exportChristoph Hellwig2019-09-041-1/+0
| | | | | | | dma_mmap_from_dev_coherent is only used by dma_map_ops instances, none of which is modular. Signed-off-by: Christoph Hellwig <hch@lst.de>
* dma-mapping: remove dma_release_declared_memoryChristoph Hellwig2019-09-041-11/+0
| | | | | | | This function is entirely unused given that declared memory is generally provided by platform setup code. Signed-off-by: Christoph Hellwig <hch@lst.de>
* dma-mapping: remove the DMA_MEMORY_EXCLUSIVE flagChristoph Hellwig2019-02-201-18/+7
| | | | | | | | All users of dma_declare_coherent want their allocations to be exclusive, so default to exclusive allocations. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
* dma-mapping: remove dma_mark_declared_memory_occupiedChristoph Hellwig2019-02-201-23/+0
| | | | | | This API is not used anywhere, so remove it. Signed-off-by: Christoph Hellwig <hch@lst.de>
* dma-mapping: remove an incorrect __iommem annotationChristoph Hellwig2019-02-131-1/+1
| | | | | | memmap return a regular void pointer, not and __iomem one. Signed-off-by: Christoph Hellwig <hch@lst.de>
* dma-mapping: remove a few unused exportsChristoph Hellwig2019-01-041-2/+0
| | | | | | | Now that the slow path DMA API calls are implemented out of line a few helpers only used by them don't need to be exported anymore. Signed-off-by: Christoph Hellwig <hch@lst.de>
* dma-mapping: move all DMA mapping code to kernel/dmaChristoph Hellwig2018-06-141-0/+434
Currently the code is split over various files with dma- prefixes in the lib/ and drives/base directories, and the number of files keeps growing. Move them into a single directory to keep the code together and remove the file name prefixes. To match the irq infrastructure this directory is placed under the kernel/ directory. Signed-off-by: Christoph Hellwig <hch@lst.de>