On Wed, Nov 4, 2015 at 6:27 PM, Russell King - ARM Linux <li...@arm.linux.org.uk> wrote: > On Wed, Nov 04, 2015 at 02:12:03PM +0900, Tomasz Figa wrote: >> My understanding of a scatterlist was that it represents a buffer as a >> whole, by joining together its physically discontinuous segments. > > Correct, and it may also be scattered in CPU virtual space as well. > >> I don't see how single segments (layout of which is completely up to >> the allocator; often just single pages) would be usable for hardware >> that needs to do some work more serious than just writing a byte >> stream continuously to subsequent buffers. In case of such simple >> devices you don't even need an IOMMU (for means other than protection >> and/or getting over address space limitations). > > All that's required is that the addresses described in the scatterlist > are accessed as an apparently contiguous series of bytes. They don't > have to be contiguous in any address view, provided the device access > appears to be contiguous. How that is done is really neither here nor > there. > > IOMMUs are normally there as an address translator - for example, the > underlying device may not have the capability to address a scatterlist > (eg, because it makes effectively random access) and in order to be > accessible to the device, it needs to be made contiguous in device > address space. > > Another scenario is that you have more bits of physical address than > a device can generate itself for DMA purposes, and you need an IOMMU > to create a (possibly scattered) mapping in device address space > within the ability of the device to address. > > The requirements here depend on the device behind the IOMMU.
I fully agree with you. The problem is that the code being discussed here breaks the case of devices that don't have the capability of addressing a scatterlist, supposedly for the sake of devices that have such capability (but as I suggested, they both could be happily supported, by distinguishing special values of DMA max segment size and boundary mask). >> However, IMHO the most important use case of an IOMMU is to make >> buffers, which are contiguous in CPU virtual address space (VA), >> contiguous in device's address space (IOVA). > > No - there is no requirement for CPU virtual contiguous buffers to also > be contiguous in the device address space. There is no requirement, but shouldn't it be desired for the mapping code to map them as such? Otherwise, how could the IOMMU use case you described above (address translator for devices which don't have the capability to address a scatterlist) be handled properly? Is the general conclusion now that dma_map_sg() should not be used to create IOMMU mappings and we should make a step backwards making all drivers (or frameworks, such as videobuf2) do that manually? That would be really backwards, because code not aware of IOMMU existence at all would have to become aware of it. Best regards, Tomasz -- To unsubscribe from this list: send the line "unsubscribe linux-media" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html