[RFC PATCH 3/3] drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain

Chaoyi Chen chaoyi.chen at rock-chips.com
Thu Dec 3 23:14:23 PST 2026


Hi,

On 12/4/2026 2:24 PM, Francesco Saverio Pavone wrote:
> The driver allocates its own IOMMU domain and attaches a VOP to it on
> the first CRTC enable. If the bootloader left a window scanning out of
> its own framebuffer, that buffer has no mapping in the new domain, and
> the VOP reads it until the first new frame is latched. On a ROCK 5B+
> started from EDK2, with the buffer mapped in the default domain only,
> this shows at the first modeset as
> 
>   rk_iommu fdd97e00.iommu: Page fault at 0x00000000e6810400 of type read
> 
> and the two "Enable stall request timed out" lines come back later,
> when the compositor takes over.
> 
> When the devicetree describes the buffer as a reserved region of the
> VOP ("memory-region" with "iommu-addresses"), the iommu core maps it
> 1:1 in the default domain. Collect the direct-mapped regions of every
> VOP when it is bound, then give them the same mapping in the DRM domain
> before any device is attached, and reserve the range in the drm_mm so
> that no GEM object is given those addresses.
> 
> A region that does not fit in the aperture of the domain is skipped
> with a warning. The mappings are kept until the domain is freed: the
> driver does not know when the last read of the old buffer happens.
> Signed-off-by: Francesco Saverio Pavone <pavone.lawyer at gmail.com>

Again, please consider condensing your commit message.

> ---
>  drivers/gpu/drm/rockchip/rockchip_drm_drv.c | 121 ++++++++++++++++++++
>  drivers/gpu/drm/rockchip/rockchip_drm_drv.h |   2 +
>  2 files changed, 123 insertions(+)
> 
> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
> index ba417f7e9e474..aed22787c05e2 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.c
> @@ -88,6 +88,121 @@ void rockchip_drm_dma_detach_device(struct drm_device *drm_dev,
>  	iommu_detach_device(private->domain, dev);
>  }
>  
> +struct rockchip_drm_resv {
> +	struct list_head list;
> +	struct drm_mm_node node;
> +	int prot;
> +};
> +
> +/*
> + * Remember the direct-mapped reserved regions of a VOP. The iommu core maps
> + * them 1:1 in the default domain of the device; rockchip_drm_init_iommu()
> + * gives them the same mapping in the DRM domain.
> + */

Drop this comment.

> +static void rockchip_drm_collect_resv_regions(struct drm_device *drm_dev,
> +					      struct device *dev)
> +{
> +	struct rockchip_drm_private *private = drm_dev->dev_private;
> +	struct iommu_resv_region *region;
> +	struct rockchip_drm_resv *resv;
> +	LIST_HEAD(regions);
> +
> +	iommu_get_resv_regions(dev, &regions);
> +
> +	list_for_each_entry(region, &regions, list) {
> +		if (region->type != IOMMU_RESV_DIRECT &&
> +		    region->type != IOMMU_RESV_DIRECT_RELAXABLE)
> +			continue;
> +
> +		resv = devm_kzalloc_obj(drm_dev->dev, *resv);
> +		if (!resv)
> +			break;
> +
> +		resv->node.start = region->start;
> +		resv->node.size = region->length;

This looks somewhat similar to iommu_create_device_direct_mapping().
Consider aligning the address range to page_size?

> +		resv->prot = region->prot;
> +		list_add_tail(&resv->list, &private->resv_list);
> +	}
> +
> +	iommu_put_resv_regions(dev, &regions);
> +}
> +
> +static void rockchip_drm_unmap_resv_regions(struct rockchip_drm_private *private)
> +{
> +	struct rockchip_drm_resv *resv;
> +
> +	list_for_each_entry(resv, &private->resv_list, list) {
> +		if (!drm_mm_node_allocated(&resv->node))
> +			continue;
> +
> +		iommu_unmap(private->domain, resv->node.start, resv->node.size);
> +		drm_mm_remove_node(&resv->node);
> +	}
> +}
> +
> +/*
> + * Map the reserved regions of the VOPs 1:1 in the DRM domain and keep their
> + * addresses away from the GEM objects, so that a scanout left running by the
> + * bootloader keeps working when a VOP is moved over to this domain. The VOP
> + * reads the old buffer until the first new frame is latched, so the mappings
> + * stay for as long as the domain does.
> + */

Drop this comment.

> +static void rockchip_drm_map_resv_regions(struct drm_device *drm_dev)
> +{
> +	struct rockchip_drm_private *private = drm_dev->dev_private;
> +	struct iommu_domain_geometry *geometry = &private->domain->geometry;
> +	unsigned long pgsz = 1UL << __ffs(private->domain->pgsize_bitmap);
> +	struct rockchip_drm_resv *resv, *other;
> +	u64 start, end;
> +	int ret;
> +
> +	list_for_each_entry(resv, &private->resv_list, list) {
> +		/* Same rounding as the direct mappings of the iommu core. */
> +		start = ALIGN(resv->node.start, pgsz);
> +		end = ALIGN(resv->node.start + resv->node.size, pgsz);

Oops, it looks like you perform the alignment here, but isn't that 
too late for your subsequent comparison?

> +		if (start >= end)
> +			continue;
> +
> +		/* Two VOPs may point at the same region. */
> +		ret = 0;
> +		list_for_each_entry(other, &private->resv_list, list) {
> +			if (other == resv)
> +				break;
> +			if (drm_mm_node_allocated(&other->node) &&
> +			    other->node.start == start &&
> +			    other->node.size == end - start)
> +				ret = -EEXIST;
> +		}
> +		if (ret)
> +			continue;
> +

Hmm, this doesn't seem to handle overlapping cases,
but it's sufficient for now.

> +		if (start < geometry->aperture_start ||
> +		    end - 1 > geometry->aperture_end) {
> +			drm_warn(drm_dev,
> +				 "reserved region [%#llx-%#llx] is outside the IOMMU aperture\n",
> +				 start, end - 1);
> +			continue;
> +		}
> +
> +		resv->node.start = start;
> +		resv->node.size = end - start;
> +		ret = drm_mm_reserve_node(&private->mm, &resv->node);
> +		if (ret) {
> +			drm_warn(drm_dev, "cannot reserve [%#llx-%#llx]: %d\n",
> +				 start, end - 1, ret);
> +			continue;
> +		}
> +
> +		ret = iommu_map(private->domain, start, start, end - start,
> +				resv->prot, GFP_KERNEL);
> +		if (ret) {
> +			drm_warn(drm_dev, "cannot map [%#llx-%#llx]: %d\n",
> +				 start, end - 1, ret);
> +			drm_mm_remove_node(&resv->node);
> +		}
> +	}
> +}
> +
>  void rockchip_drm_dma_init_device(struct drm_device *drm_dev,
>  				  struct device *dev)
>  {
> @@ -100,6 +215,9 @@ void rockchip_drm_dma_init_device(struct drm_device *drm_dev,
>  
>  	if (!IS_ERR(private->iommu_dev))
>  		drm_dev_set_dma_dev(drm_dev, private->iommu_dev);
> +
> +	if (device_iommu_mapped(dev))
> +		rockchip_drm_collect_resv_regions(drm_dev, dev);
>  }
>  
>  static int rockchip_drm_init_iommu(struct drm_device *drm_dev)
> @@ -127,6 +245,7 @@ static int rockchip_drm_init_iommu(struct drm_device *drm_dev)
>  		  start, end);
>  	drm_mm_init(&private->mm, start, end - start + 1);
>  	mutex_init(&private->mm_lock);
> +	rockchip_drm_map_resv_regions(drm_dev);
>  
>  	return 0;
>  }
> @@ -138,6 +257,7 @@ static void rockchip_iommu_cleanup(struct drm_device *drm_dev)
>  	if (!private->domain)
>  		return;
>  
> +	rockchip_drm_unmap_resv_regions(private);
>  	drm_mm_takedown(&private->mm);
>  	iommu_domain_free(private->domain);
>  }
> @@ -170,6 +290,7 @@ static int rockchip_drm_bind(struct device *dev)
>  	}
>  
>  	drm_dev->dev_private = private;
> +	INIT_LIST_HEAD(&private->resv_list);
>  
>  	ret = drmm_mode_config_init(drm_dev);
>  	if (ret)
> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h
> index 4705dc6b8bd7d..f107342527c6d 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_drv.h
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_drv.h
> @@ -67,12 +67,14 @@ struct rockchip_crtc_state {
>   * @crtc: array of enabled CRTCs, used to map from "pipe" to drm_crtc.
>   * @num_pipe: number of pipes for this device.
>   * @mm_lock: protect drm_mm on multi-threads.
> + * @resv_list: reserved regions of the VOPs, mapped 1:1 in @domain.
>   */
>  struct rockchip_drm_private {
>  	struct iommu_domain *domain;
>  	struct device *iommu_dev;
>  	struct mutex mm_lock;
>  	struct drm_mm mm;
> +	struct list_head resv_list;
>  };
>  
>  struct rockchip_encoder {

-- 
Best, 
Chaoyi



More information about the linux-arm-kernel mailing list