Hi everyone, This is an attempt to revive Rob Herring's "DMA per allocation kernel mappings" [1] series from 2019. This series stacks on top of my recent "drm/gem-dma: Support dedicated DMA device for allocation" series [2]. Many of the allocation paths are touched by both.
The 3 driver conversions from the original series are not included, as the changes have landed in some other form. Patch 1 makes the rcar-du driver use one of the GEM DMA helpers to get a scatter gather table, instead of calling dma_get_sgtable() directly. This reduces one location where the DMA APIs are directly used with drm_gem_dma_object outside the helpers. Patch 2 adds the kernel internal DRM_MODE_DUMB_KERNEL_MAP flag. Patch 3 adds the dma_attr field to drm_gem_dma_object, and converts the GEM DMA helpers to use the dma_*_attrs() variant of the DMA API. Patch 4 adds support for DRM_MODE_DUMB_KERNEL_MAP to the GEM DMA helpers by setting the DMA_ATTR_NO_KERNEL_MAPING attribute for requests without the DRM_MODE_DUMB_KERNEL_MAP flag. Existing callers of drm_gem_dma_dumb_create_internal(), with the exception of adp, all use the DRM client API, and otherwise do not have any direct use of the kernel mapping. Thus only the adp driver gains setting DRM_MODE_DUMB_KERNEL_MAP before calling drm_gem_dma_dumb_create_internal(). I have also started to convert the exynos driver to use the GEM DMA helpers. I also plan on looking into the rockchip driver, but that one has a separate IOMMU path that needs to be handled. I might copy the approach used in the exynos driver to deal with it. Changes compared to the original version from Rob (v1): - Link to original v1: https://lore.kernel.org/dri-devel/[email protected]/ - Rebased onto renamed GEM DMA helpers - New patch for rcar-du - Patch 2 - Make drm_mode_create_dumb_ioctl() emit warning if args->flags is not zero - Patch 3 - Made vc4_bo_purge() use dma_free_attrs(); this is the other location of DMA API used with drm_gem_dma_object outside the helpers - Expanded commit message - Patch 4 - Added kernal mapping check in drm_fb_dma_get_scanout_buffer() and drm_gem_dma_vmap(). - Made drm_gem_dma_print_info() show "vaddr=(no mapping)" for objects allocated without kernel mapping - Dropped existing DRM_MODE_DUMB_KERNEL_MAP flag addition in various drivers - Added DRM_MODE_DUMB_KERNEL_MAP flag to adp_drm_gem_dumb_create() - Added flags field kerneldoc for drm_gem_dma_create_with_handle() I dropped all the original Reviewed-by tags, as it's been 5 years since the changes were first posted, and also because the code has changed a lot. Please have a look. Thanks ChenYu Original cover letter from Rob: This series adds support for CMA/DMA users to skip kernel mappings for GEM allocations. The DMA API only guarantees a kernel mapping at allocation time. Creating mappings with vmap() after allocation may or may not work as not all allocations have a struct page. As virtual memory space is limited on 32-bit systems some drivers will skip kernel mappings when possible. This prevents those drivers from using CMA helpers and the generic fbdev emulation which results in a lot of duplicated code. In order to distinguish between kernel and userspace allocations, a new flag, DRM_MODE_DUMB_KERNEL_MAP, for drm_mode_create_dumb() is introduced. This allows drivers to override the default behavior for CMA helpers of always creating a kernel mapping. Mediatek is converted to CMA helpers and Rockchip is converted to generic fbdev support. I also have patches to convert Rockchip to CMA and shmem helpers, but they need a bit more work. Exynos can also probably be converted to use CMA helpers. Compile tested only. I did test fbdev on Rockchip, but the h/w I have has an IOMMU, so the CMA code path doesn't get tested. - end quote - [1] https://lore.kernel.org/dri-devel/[email protected]/ [2] https://lore.kernel.org/all/[email protected]/ Chen-Yu Tsai (1): drm/rcar-du: Use drm_gem_dma_get_sg_table() helper to get scatter gather table Rob Herring (3): drm: Introduce DRM_MODE_DUMB_KERNEL_MAP flag drm/gem-dma: Use the dma_*_attr API variant drm/gem-dma: Support DRM_MODE_DUMB_KERNEL_MAP flag drivers/gpu/drm/adp/adp_drv.c | 1 + drivers/gpu/drm/drm_client.c | 1 + drivers/gpu/drm/drm_dumb_buffers.c | 4 + drivers/gpu/drm/drm_fb_dma_helper.c | 4 + drivers/gpu/drm/drm_gem_dma_helper.c | 93 ++++++++++++------- drivers/gpu/drm/renesas/rcar-du/rcar_du_vsp.c | 12 ++- drivers/gpu/drm/vc4/vc4_bo.c | 2 +- include/drm/drm_gem_dma_helper.h | 3 + include/uapi/drm/drm_mode.h | 2 + 9 files changed, 82 insertions(+), 40 deletions(-) -- 2.53.0.851.ga537e3e6e9-goog
