Skip to content

Commit 882cd65

Browse files
committed
Merge tag 'dma-mapping-6.15-2025-04-25' of git://git.kernel.org/pub/scm/linux/kernel/git/mszyprowski/linux
Pull dma-maping fixes from Marek Szyprowski: - avoid unused variable warnings (Arnd Bergmann, Marek Szyprowski) - add runtume warnings and debug messages for devices with limited DMA capabilities (Balbir Singh, Chen-Yu Tsai) * tag 'dma-mapping-6.15-2025-04-25' of git://git.kernel.org/pub/scm/linux/kernel/git/mszyprowski/linux: dma-coherent: Warn if OF reserved memory is beyond current coherent DMA mask dma-mapping: Fix warning reported for missing prototype dma-mapping: avoid potential unused data compilation warning dma/mapping.c: dev_dbg support for dma_addressing_limited dma/contiguous: avoid warning about unused size_bytes
2 parents b22a194 + 89461db commit 882cd65

File tree

4 files changed

+35
-17
lines changed

4 files changed

+35
-17
lines changed

include/linux/dma-mapping.h

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -629,10 +629,14 @@ static inline int dma_mmap_wc(struct device *dev,
629629
#else
630630
#define DEFINE_DMA_UNMAP_ADDR(ADDR_NAME)
631631
#define DEFINE_DMA_UNMAP_LEN(LEN_NAME)
632-
#define dma_unmap_addr(PTR, ADDR_NAME) (0)
633-
#define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) do { } while (0)
634-
#define dma_unmap_len(PTR, LEN_NAME) (0)
635-
#define dma_unmap_len_set(PTR, LEN_NAME, VAL) do { } while (0)
632+
#define dma_unmap_addr(PTR, ADDR_NAME) \
633+
({ typeof(PTR) __p __maybe_unused = PTR; 0; })
634+
#define dma_unmap_addr_set(PTR, ADDR_NAME, VAL) \
635+
do { typeof(PTR) __p __maybe_unused = PTR; } while (0)
636+
#define dma_unmap_len(PTR, LEN_NAME) \
637+
({ typeof(PTR) __p __maybe_unused = PTR; 0; })
638+
#define dma_unmap_len_set(PTR, LEN_NAME, VAL) \
639+
do { typeof(PTR) __p __maybe_unused = PTR; } while (0)
636640
#endif
637641

638642
#endif /* _LINUX_DMA_MAPPING_H */

kernel/dma/coherent.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,16 +336,22 @@ static phys_addr_t dma_reserved_default_memory_size __initdata;
336336

337337
static int rmem_dma_device_init(struct reserved_mem *rmem, struct device *dev)
338338
{
339-
if (!rmem->priv) {
340-
struct dma_coherent_mem *mem;
339+
struct dma_coherent_mem *mem = rmem->priv;
341340

341+
if (!mem) {
342342
mem = dma_init_coherent_memory(rmem->base, rmem->base,
343343
rmem->size, true);
344344
if (IS_ERR(mem))
345345
return PTR_ERR(mem);
346346
rmem->priv = mem;
347347
}
348-
dma_assign_coherent_memory(dev, rmem->priv);
348+
349+
/* Warn if the device potentially can't use the reserved memory */
350+
if (mem->device_base + rmem->size - 1 >
351+
min_not_zero(dev->coherent_dma_mask, dev->bus_dma_limit))
352+
dev_warn(dev, "reserved memory is beyond device's set DMA address range\n");
353+
354+
dma_assign_coherent_memory(dev, mem);
349355
return 0;
350356
}
351357

kernel/dma/contiguous.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,7 @@ struct cma *dma_contiguous_default_area;
6464
* Users, who want to set the size of global CMA area for their system
6565
* should use cma= kernel parameter.
6666
*/
67-
static const phys_addr_t size_bytes __initconst =
68-
(phys_addr_t)CMA_SIZE_MBYTES * SZ_1M;
67+
#define size_bytes ((phys_addr_t)CMA_SIZE_MBYTES * SZ_1M)
6968
static phys_addr_t size_cmdline __initdata = -1;
7069
static phys_addr_t base_cmdline __initdata;
7170
static phys_addr_t limit_cmdline __initdata;

kernel/dma/mapping.c

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,19 @@ int dma_set_coherent_mask(struct device *dev, u64 mask)
910910
}
911911
EXPORT_SYMBOL(dma_set_coherent_mask);
912912

913+
static bool __dma_addressing_limited(struct device *dev)
914+
{
915+
const struct dma_map_ops *ops = get_dma_ops(dev);
916+
917+
if (min_not_zero(dma_get_mask(dev), dev->bus_dma_limit) <
918+
dma_get_required_mask(dev))
919+
return true;
920+
921+
if (unlikely(ops) || use_dma_iommu(dev))
922+
return false;
923+
return !dma_direct_all_ram_mapped(dev);
924+
}
925+
913926
/**
914927
* dma_addressing_limited - return if the device is addressing limited
915928
* @dev: device to check
@@ -920,15 +933,11 @@ EXPORT_SYMBOL(dma_set_coherent_mask);
920933
*/
921934
bool dma_addressing_limited(struct device *dev)
922935
{
923-
const struct dma_map_ops *ops = get_dma_ops(dev);
924-
925-
if (min_not_zero(dma_get_mask(dev), dev->bus_dma_limit) <
926-
dma_get_required_mask(dev))
927-
return true;
928-
929-
if (unlikely(ops) || use_dma_iommu(dev))
936+
if (!__dma_addressing_limited(dev))
930937
return false;
931-
return !dma_direct_all_ram_mapped(dev);
938+
939+
dev_dbg(dev, "device is DMA addressing limited\n");
940+
return true;
932941
}
933942
EXPORT_SYMBOL_GPL(dma_addressing_limited);
934943

0 commit comments

Comments
 (0)