mirror of
https://github.com/torvalds/linux.git
synced 2024-11-21 19:41:42 +00:00
f7ae20f2fc
There are bunch of codes in driver like if (dma_set_mask_and_coherent(dev, DMA_BIT_MASK(64))) dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32)) Actually it is wrong because if dma_set_mask_and_coherent(64) fails, dma_set_mask_and_coherent(32) will fail for the same reason. And dma_set_mask_and_coherent(64) never returns failure. According to the definition of dma_set_mask(), it indicates the width of address that device DMA can access. If it can access 64-bit address, it must access 32-bit address inherently. So only need set biggest address width. See below code fragment: dma_set_mask(mask) { mask = (dma_addr_t)mask; if (!dev->dma_mask || !dma_supported(dev, mask)) return -EIO; arch_dma_set_mask(dev, mask); *dev->dma_mask = mask; return 0; } dma_supported() will call dma_direct_supported or iommux's dma_supported call back function. int dma_direct_supported(struct device *dev, u64 mask) { u64 min_mask = (max_pfn - 1) << PAGE_SHIFT; /* * Because 32-bit DMA masks are so common we expect every architecture * to be able to satisfy them - either by not supporting more physical * memory, or by providing a ZONE_DMA32. If neither is the case, the * architecture needs to use an IOMMU instead of the direct mapping. */ if (mask >= DMA_BIT_MASK(32)) return 1; ... } The iommux's dma_supported() actually means iommu requires devices's minimized dma capability. An example: static int sba_dma_supported( struct device *dev, u64 mask)() { ... * check if mask is >= than the current max IO Virt Address * The max IO Virt address will *always* < 30 bits. */ return((int)(mask >= (ioc->ibase - 1 + (ioc->pdir_size / sizeof(u64) * IOVP_SIZE) ))); ... } 1 means supported. 0 means unsupported. Correct document to make it more clear and provide correct sample code. Signed-off-by: Frank Li <Frank.Li@nxp.com> Reviewed-by: Christoph Hellwig <hch@lst.de> Signed-off-by: Jonathan Corbet <corbet@lwn.net> [jc: fixed then/than typo] Link: https://lore.kernel.org/r/20240401174159.642998-1-Frank.Li@nxp.com |
||
---|---|---|
.. | ||
irq | ||
wrappers | ||
asm-annotations.rst | ||
assoc_array.rst | ||
boot-time-mm.rst | ||
cachetlb.rst | ||
circular-buffers.rst | ||
cpu_hotplug.rst | ||
debug-objects.rst | ||
debugging-via-ohci1394.rst | ||
dma-api-howto.rst | ||
dma-api.rst | ||
dma-attributes.rst | ||
dma-isa-lpc.rst | ||
entry.rst | ||
errseq.rst | ||
genalloc.rst | ||
generic-radix-tree.rst | ||
genericirq.rst | ||
gfp_mask-from-fs-io.rst | ||
idr.rst | ||
index.rst | ||
kernel-api.rst | ||
kobject.rst | ||
kref.rst | ||
librs.rst | ||
local_ops.rst | ||
maple_tree.rst | ||
memory-allocation.rst | ||
memory-hotplug.rst | ||
mm-api.rst | ||
netlink.rst | ||
packing.rst | ||
padata.rst | ||
pin_user_pages.rst | ||
printk-basics.rst | ||
printk-formats.rst | ||
printk-index.rst | ||
protection-keys.rst | ||
rbtree.rst | ||
refcount-vs-atomic.rst | ||
symbol-namespaces.rst | ||
this_cpu_ops.rst | ||
timekeeping.rst | ||
tracepoint.rst | ||
unaligned-memory-access.rst | ||
watch_queue.rst | ||
workqueue.rst | ||
xarray.rst |