* [PATCH v3 1/2] drm/mipi-dbi: honour the plane source offset when flushing
2026-09-23 20:58 [PATCH v3 0/2] drm/mipi-dbi: display a cropped region of an oversized framebuffer Jonathan Frazin
@ 2026-09-23 20:58 ` Jonathan Frazin
2026-09-23 20:58 ` [PATCH v3 2/2] drm/tiny: allow a framebuffer larger than the panel on MIPI DBI drivers Jonathan Frazin
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Frazin @ 2026-09-23 20:58 UTC (permalink / raw)
To: dri-devel
Cc: maarten.lankhorst, mripard, tzimmermann, airlied, simona,
kamlesh.gurudasani, lanzano.alex, phil, linux-kernel,
Jonathan Frazin, Dave Stevenson
mipi_dbi_fb_dirty() takes the damage rectangle from
drm_atomic_helper_damage_merged(), which is expressed in framebuffer
coordinates and already clipped to the plane's source rectangle. It
then passed that rectangle straight to mipi_dbi_set_window_address(),
which is correct only while the source rectangle starts at (0,0) - i.e.
while the framebuffer is exactly panel-sized.
If a driver allows a framebuffer larger than the panel and the plane
selects a sub-region with a non-zero src_x/src_y, the controller was
still addressed in framebuffer coordinates, so the wrong part of the
panel was written and an out-of-range window could be programmed.
Pass the integer plane source origin down to mipi_dbi_fb_dirty() and
subtract it when programming the column/page address. The copy into the
transfer buffer still uses the framebuffer-coordinate rectangle, so it
keeps reading the correct pixels from an oversized source. With a
panel-sized framebuffer src_x/src_y are zero and behaviour is unchanged.
The rectangle from drm_atomic_helper_damage_merged() is clipped against
the src rectangle's exact 16.16 fixed-point bounds, while src_x/src_y
above are that same origin truncated to whole pixels. When the origin
has a fractional part, the truncation can leave the rectangle's far
edge up to a pixel past where a whole-pixel origin would place the
panel's own width/height - and tx_buf is sized for exactly the panel,
with no slack for that overshoot. Clamp the rectangle to the panel's
fixed mode before using it for the window address or the transfer
length.
A damage clip can also lie entirely within that one-pixel sliver past
the panel edge - the damage iterator clips only against the exact
fixed-point bound, not the whole-pixel one used here - collapsing the
clamped rectangle to zero width or height. Skip the flush in that case
rather than program an inverted (start past end) address window, which
is undefined behaviour per the MIPI DCS spec.
Cc: Dave Stevenson <dave.stevenson@raspberrypi.com>
Signed-off-by: Jonathan Frazin <frazinjonathan@gmail.com>
---
Changes since v2:
- A damage clip lying entirely within the one-pixel sliver the v2 clamp
cuts off collapses the clamped rectangle to zero width or height,
which was still reaching mipi_dbi_set_window_address() as an inverted
(start past end) address window ahead of a zero-length write - skip
the flush when the clamped rectangle is empty. Thanks again to the
automated review for catching this on v2.
Changes since v1:
- Clamp the damage rectangle to the panel's fixed mode before using it,
as described above. Thanks to the automated review for catching this.
drivers/gpu/drm/drm_mipi_dbi.c | 43 ++++++++++++++++++++++++++++++----
1 file changed, 38 insertions(+), 5 deletions(-)
diff --git a/drivers/gpu/drm/drm_mipi_dbi.c b/drivers/gpu/drm/drm_mipi_dbi.c
index 25cf04d02..bb557fab1 100644
--- a/drivers/gpu/drm/drm_mipi_dbi.c
+++ b/drivers/gpu/drm/drm_mipi_dbi.c
@@ -271,19 +271,45 @@ static void mipi_dbi_set_window_address(struct mipi_dbi_dev *dbidev,
}
static void mipi_dbi_fb_dirty(struct iosys_map *src, struct drm_framebuffer *fb,
- struct drm_rect *rect, struct drm_format_conv_state *fmtcnv_state)
+ struct drm_rect *rect, unsigned int src_x, unsigned int src_y,
+ struct drm_format_conv_state *fmtcnv_state)
{
struct mipi_dbi_dev *dbidev = drm_to_mipi_dbi_dev(fb->dev);
- unsigned int height = rect->y2 - rect->y1;
- unsigned int width = rect->x2 - rect->x1;
const struct drm_format_info *dst_format;
struct mipi_dbi *dbi = &dbidev->dbi;
bool swap = dbi->swap_bytes;
+ unsigned int height, width;
int ret = 0;
size_t len;
bool full;
void *tr;
+ /*
+ * @rect is in framebuffer coordinates, clipped to the plane's src
+ * rectangle by the damage iterator against that rectangle's exact
+ * 16.16 fixed-point bounds. @src_x/@src_y are that same origin
+ * truncated to whole pixels. When the origin has a fractional part,
+ * that truncation can leave @rect's far edge up to a pixel past
+ * where a whole-pixel @src_x/@src_y would place the panel's own
+ * width/height -- and tx_buf is sized for exactly the panel, with no
+ * slack for that overshoot. Clamp before using @rect for anything.
+ *
+ * A damage clip can lie entirely in that one-pixel sliver past the
+ * panel edge -- the iterator above clips only against the exact
+ * fixed-point bound, not the whole-pixel one used here -- in which
+ * case the clamp collapses @rect to zero width or height. Nothing in
+ * it was ever visible on the panel, so skip the flush rather than
+ * program an inverted (start past end) address window.
+ */
+ rect->x2 = min_t(int, rect->x2, src_x + dbidev->mode.hdisplay);
+ rect->y2 = min_t(int, rect->y2, src_y + dbidev->mode.vdisplay);
+
+ if (rect->x2 <= rect->x1 || rect->y2 <= rect->y1)
+ return;
+
+ height = rect->y2 - rect->y1;
+ width = rect->x2 - rect->x1;
+
full = width == fb->width && height == fb->height;
DRM_DEBUG_KMS("Flushing [FB:%d] " DRM_RECT_FMT "\n", fb->base.id, DRM_RECT_ARG(rect));
@@ -298,8 +324,13 @@ static void mipi_dbi_fb_dirty(struct iosys_map *src, struct drm_framebuffer *fb,
tr = src->vaddr; /* TODO: Use mapping abstraction properly */
}
- mipi_dbi_set_window_address(dbidev, rect->x1, rect->x2 - 1, rect->y1,
- rect->y2 - 1);
+ /*
+ * @rect is in framebuffer coordinates and has been clipped to the plane
+ * src rectangle by the damage iterator. The panel is addressed relative
+ * to the src origin, so subtract it here.
+ */
+ mipi_dbi_set_window_address(dbidev, rect->x1 - src_x, rect->x2 - 1 - src_x,
+ rect->y1 - src_y, rect->y2 - 1 - src_y);
if (fb->format->format == DRM_FORMAT_XRGB8888)
dst_format = drm_format_info(dbidev->pixel_format);
@@ -390,6 +421,8 @@ void drm_mipi_dbi_plane_helper_atomic_update(struct drm_plane *plane,
if (drm_dev_enter(plane->dev, &idx)) {
if (drm_atomic_helper_damage_merged(old_plane_state, plane_state, &rect))
mipi_dbi_fb_dirty(&shadow_plane_state->data[0], fb, &rect,
+ plane_state->src_x >> 16,
+ plane_state->src_y >> 16,
&shadow_plane_state->fmtcnv_state);
drm_dev_exit(idx);
}
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread* [PATCH v3 2/2] drm/tiny: allow a framebuffer larger than the panel on MIPI DBI drivers
2026-09-23 20:58 [PATCH v3 0/2] drm/mipi-dbi: display a cropped region of an oversized framebuffer Jonathan Frazin
2026-09-23 20:58 ` [PATCH v3 1/2] drm/mipi-dbi: honour the plane source offset when flushing Jonathan Frazin
@ 2026-09-23 20:58 ` Jonathan Frazin
1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Frazin @ 2026-09-23 20:58 UTC (permalink / raw)
To: dri-devel
Cc: maarten.lankhorst, mripard, tzimmermann, airlied, simona,
kamlesh.gurudasani, lanzano.alex, phil, linux-kernel,
Jonathan Frazin, Dave Stevenson
Every drm/tiny MIPI DBI driver pins mode_config.max_width/max_height to
the panel size, so KMS rejects any framebuffer that is not exactly
panel-sized:
ili9341 spi0.0: bad framebuffer width 480, should be >= 240 && <= 240
Raise the maximums to DRM_SHADOW_PLANE_MAX_WIDTH/HEIGHT (which its
kerneldoc recommends for shadow-plane drivers) on the drivers that flush
through the shared drm_mipi_dbi_plane_helper_atomic_update(), so a client
can allocate a larger framebuffer and pick the displayed region through
the plane source rectangle - a crop / pan with no scaling, now that
drm_mipi_dbi honours the source offset (previous patch):
ili9341, hx8357d, ili9486, mi0283qt, ili9163, panel-mipi-dbi,
st7735r
The fixed mode, the minimums and the connector are unchanged. The plane
check (drm_mipi_dbi_plane_helper_atomic_check) still forbids scaling and
repositioning, and the transfer buffer is sized from the display mode,
so the flushed rectangle stays bounded by the panel regardless of the
framebuffer dimensions.
ili9225 is left out: it has its own atomic_update / ili9225_fb_dirty()
that addresses the panel from the damage rectangle without the source
offset, so raising its limits would let a mispositioned buffer through.
st7735r lives under drivers/gpu/drm/sitronix/ rather than
drivers/gpu/drm/tiny/ and was missed in the original pass over this
list; confirmed by grepping the whole tree for
DRM_MIPI_DBI_PLANE_HELPER_FUNCS, which finds exactly these seven
drivers and no others.
Cc: Dave Stevenson <dave.stevenson@raspberrypi.com>
Signed-off-by: Jonathan Frazin <frazinjonathan@gmail.com>
---
Changes since v2:
- Add st7735r, missed from the original list because it lives under
drivers/gpu/drm/sitronix/ rather than drivers/gpu/drm/tiny/. Confirmed
by grepping the whole tree for DRM_MIPI_DBI_PLANE_HELPER_FUNCS that no
other driver shares this flush path. Thanks to the automated review
for catching this.
Changes since v1: unchanged.
drivers/gpu/drm/sitronix/st7735r.c | 8 ++++++--
drivers/gpu/drm/tiny/hx8357d.c | 8 ++++++--
drivers/gpu/drm/tiny/ili9163.c | 8 ++++++--
drivers/gpu/drm/tiny/ili9341.c | 8 ++++++--
drivers/gpu/drm/tiny/ili9486.c | 8 ++++++--
drivers/gpu/drm/tiny/mi0283qt.c | 8 ++++++--
drivers/gpu/drm/tiny/panel-mipi-dbi.c | 8 ++++++--
7 files changed, 42 insertions(+), 14 deletions(-)
diff --git a/drivers/gpu/drm/sitronix/st7735r.c b/drivers/gpu/drm/sitronix/st7735r.c
index bd763871d..e78bd2da3 100644
--- a/drivers/gpu/drm/sitronix/st7735r.c
+++ b/drivers/gpu/drm/sitronix/st7735r.c
@@ -295,9 +295,13 @@ static int st7735r_probe(struct spi_device *spi)
return ret;
drm->mode_config.min_width = dbidev->mode.hdisplay;
- drm->mode_config.max_width = dbidev->mode.hdisplay;
+ /*
+ * Allow a framebuffer larger than the panel so a sub-region can be
+ * displayed via the plane source rectangle (crop / pan, no scaling).
+ */
+ drm->mode_config.max_width = DRM_SHADOW_PLANE_MAX_WIDTH;
drm->mode_config.min_height = dbidev->mode.vdisplay;
- drm->mode_config.max_height = dbidev->mode.vdisplay;
+ drm->mode_config.max_height = DRM_SHADOW_PLANE_MAX_HEIGHT;
drm->mode_config.funcs = &st7735r_mode_config_funcs;
drm->mode_config.preferred_depth = 16;
drm->mode_config.helper_private = &st7735r_mode_config_helper_funcs;
diff --git a/drivers/gpu/drm/tiny/hx8357d.c b/drivers/gpu/drm/tiny/hx8357d.c
index f942a8d09..0599b8ccf 100644
--- a/drivers/gpu/drm/tiny/hx8357d.c
+++ b/drivers/gpu/drm/tiny/hx8357d.c
@@ -320,9 +320,13 @@ static int hx8357d_probe(struct spi_device *spi)
return ret;
drm->mode_config.min_width = dbidev->mode.hdisplay;
- drm->mode_config.max_width = dbidev->mode.hdisplay;
+ /*
+ * Allow a framebuffer larger than the panel so a sub-region can be
+ * displayed via the plane source rectangle (crop / pan, no scaling).
+ */
+ drm->mode_config.max_width = DRM_SHADOW_PLANE_MAX_WIDTH;
drm->mode_config.min_height = dbidev->mode.vdisplay;
- drm->mode_config.max_height = dbidev->mode.vdisplay;
+ drm->mode_config.max_height = DRM_SHADOW_PLANE_MAX_HEIGHT;
drm->mode_config.funcs = &hx8357d_mode_config_funcs;
drm->mode_config.preferred_depth = 16;
drm->mode_config.helper_private = &hx8357d_mode_config_helper_funcs;
diff --git a/drivers/gpu/drm/tiny/ili9163.c b/drivers/gpu/drm/tiny/ili9163.c
index 884242450..fe6c13056 100644
--- a/drivers/gpu/drm/tiny/ili9163.c
+++ b/drivers/gpu/drm/tiny/ili9163.c
@@ -251,9 +251,13 @@ static int ili9163_probe(struct spi_device *spi)
return ret;
drm->mode_config.min_width = dbidev->mode.hdisplay;
- drm->mode_config.max_width = dbidev->mode.hdisplay;
+ /*
+ * Allow a framebuffer larger than the panel so a sub-region can be
+ * displayed via the plane source rectangle (crop / pan, no scaling).
+ */
+ drm->mode_config.max_width = DRM_SHADOW_PLANE_MAX_WIDTH;
drm->mode_config.min_height = dbidev->mode.vdisplay;
- drm->mode_config.max_height = dbidev->mode.vdisplay;
+ drm->mode_config.max_height = DRM_SHADOW_PLANE_MAX_HEIGHT;
drm->mode_config.funcs = &ili9163_mode_config_funcs;
drm->mode_config.preferred_depth = 16;
drm->mode_config.helper_private = &ili9163_mode_config_helper_funcs;
diff --git a/drivers/gpu/drm/tiny/ili9341.c b/drivers/gpu/drm/tiny/ili9341.c
index 003381aa2..1e4bb56e3 100644
--- a/drivers/gpu/drm/tiny/ili9341.c
+++ b/drivers/gpu/drm/tiny/ili9341.c
@@ -282,9 +282,13 @@ static int ili9341_probe(struct spi_device *spi)
return ret;
drm->mode_config.min_width = dbidev->mode.hdisplay;
- drm->mode_config.max_width = dbidev->mode.hdisplay;
+ /*
+ * Allow a framebuffer larger than the panel so a sub-region can be
+ * displayed via the plane source rectangle (crop / pan, no scaling).
+ */
+ drm->mode_config.max_width = DRM_SHADOW_PLANE_MAX_WIDTH;
drm->mode_config.min_height = dbidev->mode.vdisplay;
- drm->mode_config.max_height = dbidev->mode.vdisplay;
+ drm->mode_config.max_height = DRM_SHADOW_PLANE_MAX_HEIGHT;
drm->mode_config.funcs = &ili9341_mode_config_funcs;
drm->mode_config.preferred_depth = 16;
drm->mode_config.helper_private = &ili9341_mode_config_helper_funcs;
diff --git a/drivers/gpu/drm/tiny/ili9486.c b/drivers/gpu/drm/tiny/ili9486.c
index fab8bd7ce..de33d702a 100644
--- a/drivers/gpu/drm/tiny/ili9486.c
+++ b/drivers/gpu/drm/tiny/ili9486.c
@@ -309,9 +309,13 @@ static int ili9486_probe(struct spi_device *spi)
return ret;
drm->mode_config.min_width = dbidev->mode.hdisplay;
- drm->mode_config.max_width = dbidev->mode.hdisplay;
+ /*
+ * Allow a framebuffer larger than the panel so a sub-region can be
+ * displayed via the plane source rectangle (crop / pan, no scaling).
+ */
+ drm->mode_config.max_width = DRM_SHADOW_PLANE_MAX_WIDTH;
drm->mode_config.min_height = dbidev->mode.vdisplay;
- drm->mode_config.max_height = dbidev->mode.vdisplay;
+ drm->mode_config.max_height = DRM_SHADOW_PLANE_MAX_HEIGHT;
drm->mode_config.funcs = &ili9486_mode_config_funcs;
drm->mode_config.preferred_depth = 16;
drm->mode_config.helper_private = &ili9486_mode_config_helper_funcs;
diff --git a/drivers/gpu/drm/tiny/mi0283qt.c b/drivers/gpu/drm/tiny/mi0283qt.c
index b0121e89e..df3801914 100644
--- a/drivers/gpu/drm/tiny/mi0283qt.c
+++ b/drivers/gpu/drm/tiny/mi0283qt.c
@@ -290,9 +290,13 @@ static int mi0283qt_probe(struct spi_device *spi)
return ret;
drm->mode_config.min_width = dbidev->mode.hdisplay;
- drm->mode_config.max_width = dbidev->mode.hdisplay;
+ /*
+ * Allow a framebuffer larger than the panel so a sub-region can be
+ * displayed via the plane source rectangle (crop / pan, no scaling).
+ */
+ drm->mode_config.max_width = DRM_SHADOW_PLANE_MAX_WIDTH;
drm->mode_config.min_height = dbidev->mode.vdisplay;
- drm->mode_config.max_height = dbidev->mode.vdisplay;
+ drm->mode_config.max_height = DRM_SHADOW_PLANE_MAX_HEIGHT;
drm->mode_config.funcs = &mi0283qt_mode_config_funcs;
drm->mode_config.preferred_depth = 16;
drm->mode_config.helper_private = &mi0283qt_mode_config_helper_funcs;
diff --git a/drivers/gpu/drm/tiny/panel-mipi-dbi.c b/drivers/gpu/drm/tiny/panel-mipi-dbi.c
index 60cd65cae..a0a098b0d 100644
--- a/drivers/gpu/drm/tiny/panel-mipi-dbi.c
+++ b/drivers/gpu/drm/tiny/panel-mipi-dbi.c
@@ -448,9 +448,13 @@ static int panel_mipi_dbi_spi_probe(struct spi_device *spi)
return ret;
drm->mode_config.min_width = dbidev->mode.hdisplay;
- drm->mode_config.max_width = dbidev->mode.hdisplay;
+ /*
+ * Allow a framebuffer larger than the panel so a sub-region can be
+ * displayed via the plane source rectangle (crop / pan, no scaling).
+ */
+ drm->mode_config.max_width = DRM_SHADOW_PLANE_MAX_WIDTH;
drm->mode_config.min_height = dbidev->mode.vdisplay;
- drm->mode_config.max_height = dbidev->mode.vdisplay;
+ drm->mode_config.max_height = DRM_SHADOW_PLANE_MAX_HEIGHT;
drm->mode_config.funcs = &panel_mipi_dbi_mode_config_funcs;
drm->mode_config.preferred_depth = bpp;
drm->mode_config.helper_private = &panel_mipi_dbi_mode_config_helper_funcs;
--
2.53.0
^ permalink raw reply [flat|nested] 3+ messages in thread