From: Chaoyi Chen <chaoyi.chen@rock-chips.com>
To: Francesco Saverio Pavone <pavone.lawyer@gmail.com>
Cc: Joerg Roedel <joro@8bytes.org>, Will Deacon <will@kernel.org>,
Robin Murphy <robin.murphy@arm.com>,
Sandy Huang <hjc@rock-chips.com>,
Heiko Stuebner <heiko@sntech.de>, Andy Yan <andyshrk@163.com>,
Damon Ding <damon.ding@rock-chips.com>,
Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Maxime Ripard <mripard@kernel.org>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Jiaxing Hu <gahing@gahingwoo.com>,
iommu@lists.linux.dev, dri-devel@lists.freedesktop.org,
devicetree@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-arm-kernel@lists.infradead.org
Subject: Re: [RFC PATCH 3/3] drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain
Date: Fri, 4 Dec 2026 15:14:23 +0800 [thread overview]
Message-ID: <2e35a072-45ff-4438-a5d9-cd67cf8d1424@rock-chips.com> (raw)
In-Reply-To: <43f9ba0b26794fc58762d4e3188796fbf92becd2.1796334467.git.pavone.lawyer@gmail.com>
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@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, ®ions);
> +
> + list_for_each_entry(region, ®ions, 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, ®ions);
> +}
> +
> +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
prev parent reply other threads:[~2026-12-04 7:14 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 6:24 [RFC PATCH 0/3] rockchip: keep the bootloader framebuffer mapped behind the VOP IOMMU Francesco Saverio Pavone
2026-12-04 6:24 ` [RFC PATCH 1/3] iommu/rockchip: Report the reserved regions from the devicetree Francesco Saverio Pavone
2026-12-04 6:32 ` Chaoyi Chen
2026-12-04 6:44 ` sashiko-bot
2026-12-04 6:24 ` [RFC PATCH 2/3] dt-bindings: display: vop2: Allow memory-region Francesco Saverio Pavone
2026-12-04 6:24 ` [RFC PATCH 3/3] drm/rockchip: Map the reserved regions 1:1 in the DRM IOMMU domain Francesco Saverio Pavone
2026-12-04 6:48 ` sashiko-bot
2026-12-04 7:14 ` Chaoyi Chen [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=2e35a072-45ff-4438-a5d9-cd67cf8d1424@rock-chips.com \
--to=chaoyi.chen@rock-chips.com \
--cc=airlied@gmail.com \
--cc=andyshrk@163.com \
--cc=conor+dt@kernel.org \
--cc=damon.ding@rock-chips.com \
--cc=devicetree@vger.kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=gahing@gahingwoo.com \
--cc=heiko@sntech.de \
--cc=hjc@rock-chips.com \
--cc=iommu@lists.linux.dev \
--cc=joro@8bytes.org \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=pavone.lawyer@gmail.com \
--cc=robh@kernel.org \
--cc=robin.murphy@arm.com \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
--cc=will@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox