* [PATCH v3 1/9] drm/meson: honor framebuffer offsets for the primary plane
2026-12-03 19:55 [PATCH v3 0/9] drm/meson: add a second RGB plane on G12A Guillaume La Roque
@ 2026-12-03 19:55 ` Guillaume La Roque
2026-12-03 20:18 ` sashiko-bot
2026-12-03 19:55 ` [PATCH v3 2/9] drm/meson: isolate primary plane scaler setup Guillaume La Roque
` (7 subsequent siblings)
8 siblings, 1 reply; 13+ messages in thread
From: Guillaume La Roque @ 2026-12-03 19:55 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
linux-kernel, Guillaume La Roque
The canvas and AFBC decoder use the GEM object address directly. Include
the framebuffer plane offset so scanout starts at the requested offset
within the object.
Fixes: bbbe775ec5b5 ("drm: Add support for Amlogic Meson Graphic Controller")
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_plane.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index c17afe6712f9..7174093227fd 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -363,7 +363,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
/* Update Canvas with buffer address */
gem = drm_fb_dma_get_gem_obj(fb, 0);
- priv->viu.osd1_addr = gem->dma_addr;
+ priv->viu.osd1_addr = gem->dma_addr + fb->offsets[0];
priv->viu.osd1_stride = fb->pitches[0];
priv->viu.osd1_height = fb->height;
priv->viu.osd1_width = fb->width;
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v3 1/9] drm/meson: honor framebuffer offsets for the primary plane
2026-12-03 19:55 ` [PATCH v3 1/9] drm/meson: honor framebuffer offsets for the primary plane Guillaume La Roque
@ 2026-12-03 20:18 ` sashiko-bot
0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-12-03 20:18 UTC (permalink / raw)
To: Guillaume La Roque; +Cc: dri-devel, linux-amlogic, neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/meson: unvalidated fb->offsets[0] alignment for OSD1
scanout
--
commit a76c56c51bbe01c45cc0741259ad172d1e6ce025
Author: Guillaume La Roque <glaroque@baylibre.com>
drm/meson: honor framebuffer offsets for the primary plane
This commit adds fb->offsets[0] to gem->dma_addr when computing
priv->viu.osd1_addr in meson_plane_atomic_update() so primary plane scanout
honors the framebuffer plane offset.
> diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
> index c17afe6712f93..7174093227fd7 100644
> --- a/drivers/gpu/drm/meson/meson_plane.c
> +++ b/drivers/gpu/drm/meson/meson_plane.c
> @@ -363,7 +363,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
> /* Update Canvas with buffer address */
> gem = drm_fb_dma_get_gem_obj(fb, 0);
>
> - priv->viu.osd1_addr = gem->dma_addr;
> + priv->viu.osd1_addr = gem->dma_addr + fb->offsets[0];
> priv->viu.osd1_stride = fb->pitches[0];
> priv->viu.osd1_height = fb->height;
> priv->viu.osd1_width = fb->width;
[Severity: Medium]
Should meson_plane_atomic_check() validate the alignment of fb->offsets[0]
before adding it to gem->dma_addr?
Neither drm_gem_fb_create() nor meson_plane_atomic_check() checks offset
alignment. In linear mode, meson_canvas_config() programs ((addr + 7) >> 3),
silently rounding a non-8-byte-aligned offset (such as a 4-byte XRGB8888
offset) up by up to 7 bytes.
That shifts the scanout start and can cause the Canvas DMA engine to read up
to 7 bytes past the end of a tightly sized GEM buffer.
In AFBC mode, meson_gxm_afbcd_setup() truncates bits [3:0] for
OSD1_AFBCD_HDR_PTR and OSD1_AFBCD_FRAME_PTR while keeping them in
OSD1_AFBCD_CHROMA_PTR, and meson_g12a_afbcd_setup() writes osd1_addr without
checking 64-byte AFBC header alignment.
Rejecting unaligned fb->offsets[0] with -EINVAL in meson_plane_atomic_check()
for linear (8-byte) and AFBC modes would avoid silent misprogramming.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-meson-g12a-osd2-v3-0-2cf76729b5d5@baylibre.com?part=1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 2/9] drm/meson: isolate primary plane scaler setup
2026-12-03 19:55 [PATCH v3 0/9] drm/meson: add a second RGB plane on G12A Guillaume La Roque
2026-12-03 19:55 ` [PATCH v3 1/9] drm/meson: honor framebuffer offsets for the primary plane Guillaume La Roque
@ 2026-12-03 19:55 ` Guillaume La Roque
2026-12-03 19:55 ` [PATCH v3 3/9] drm/meson: keep RGB scanout state per OSD Guillaume La Roque
` (6 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Guillaume La Roque @ 2026-12-03 19:55 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
linux-kernel, Guillaume La Roque
Separate the OSD1 scaler from format, buffer and geometry handling so
another RGB plane can reuse scanout setup without changing the primary
scaler state.
Keep the primary blender dimensions based on crtc_w and crtc_h,
including the existing height division for interlaced modes.
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_plane.c | 224 +++++++++++++++++++-----------------
1 file changed, 119 insertions(+), 105 deletions(-)
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 7174093227fd..0506e29b6ef3 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -131,6 +131,118 @@ static u32 meson_g12a_afbcd_line_stride(struct meson_drm *priv)
return ((line_stride + 1) >> 1) << 1;
}
+static void meson_plane_setup_scaler(struct meson_drm *priv,
+ struct drm_plane_state *new_state,
+ struct drm_rect *dest)
+{
+ int vsc_ini_rcv_num, vsc_ini_rpt_p0_num;
+ int vsc_bot_rcv_num, vsc_bot_rpt_p0_num;
+ int hsc_ini_rcv_num, hsc_ini_rpt_p0_num;
+ int hf_phase_step, vf_phase_step;
+ int src_w, src_h, dst_w, dst_h;
+ int bot_ini_phase;
+ int hf_bank_len;
+ int vf_bank_len;
+
+ /* Default scaler parameters */
+ vsc_bot_rcv_num = 0;
+ vsc_bot_rpt_p0_num = 0;
+ hf_bank_len = 4;
+ vf_bank_len = 4;
+
+ if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
+ vsc_bot_rcv_num = 6;
+ vsc_bot_rpt_p0_num = 2;
+ }
+
+ hsc_ini_rcv_num = hf_bank_len;
+ vsc_ini_rcv_num = vf_bank_len;
+ hsc_ini_rpt_p0_num = (hf_bank_len / 2) - 1;
+ vsc_ini_rpt_p0_num = (vf_bank_len / 2) - 1;
+
+ src_w = fixed16_to_int(new_state->src_w);
+ src_h = fixed16_to_int(new_state->src_h);
+ dst_w = new_state->crtc_w;
+ dst_h = new_state->crtc_h;
+
+ /*
+ * When the output is interlaced, the OSD must switch between
+ * each field using the INTERLACE_SEL_ODD (0) of VIU_OSD1_BLK0_CFG_W0
+ * at each vsync.
+ * But the vertical scaler can provide such funtionnality if
+ * is configured for 2:1 scaling with interlace options enabled.
+ */
+ if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
+ dest->y1 /= 2;
+ dest->y2 /= 2;
+ dst_h /= 2;
+ }
+
+ hf_phase_step = ((src_w << 18) / dst_w) << 6;
+ vf_phase_step = (src_h << 20) / dst_h;
+
+ if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
+ bot_ini_phase = ((vf_phase_step / 2) >> 4);
+ else
+ bot_ini_phase = 0;
+
+ vf_phase_step = (vf_phase_step << 4);
+
+ /* In interlaced mode, scaler is always active */
+ if (src_h != dst_h || src_w != dst_w) {
+ priv->viu.osd_sc_i_wh_m1 = SCI_WH_M1_W(src_w - 1) |
+ SCI_WH_M1_H(src_h - 1);
+ priv->viu.osd_sc_o_h_start_end = SCO_HV_START(dest->x1) |
+ SCO_HV_END(dest->x2 - 1);
+ priv->viu.osd_sc_o_v_start_end = SCO_HV_START(dest->y1) |
+ SCO_HV_END(dest->y2 - 1);
+ /* Enable OSD Scaler */
+ priv->viu.osd_sc_ctrl0 = SC_CTRL0_PATH_EN | SC_CTRL0_SEL_OSD1;
+ } else {
+ priv->viu.osd_sc_i_wh_m1 = 0;
+ priv->viu.osd_sc_o_h_start_end = 0;
+ priv->viu.osd_sc_o_v_start_end = 0;
+ priv->viu.osd_sc_ctrl0 = 0;
+ }
+
+ /* In interlaced mode, vertical scaler is always active */
+ if (src_h != dst_h) {
+ priv->viu.osd_sc_v_ctrl0 =
+ VSC_BANK_LEN(vf_bank_len) |
+ VSC_TOP_INI_RCV_NUM(vsc_ini_rcv_num) |
+ VSC_TOP_RPT_L0_NUM(vsc_ini_rpt_p0_num) |
+ VSC_VERTICAL_SCALER_EN;
+
+ if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
+ priv->viu.osd_sc_v_ctrl0 |=
+ VSC_BOT_INI_RCV_NUM(vsc_bot_rcv_num) |
+ VSC_BOT_RPT_L0_NUM(vsc_bot_rpt_p0_num) |
+ VSC_PROG_INTERLACE;
+
+ priv->viu.osd_sc_v_phase_step = SC_PHASE_STEP(vf_phase_step);
+ priv->viu.osd_sc_v_ini_phase = VSC_INI_PHASE_BOT(bot_ini_phase);
+ } else {
+ priv->viu.osd_sc_v_ctrl0 = 0;
+ priv->viu.osd_sc_v_phase_step = 0;
+ priv->viu.osd_sc_v_ini_phase = 0;
+ }
+
+ /* Horizontal scaler is only used if width does not match */
+ if (src_w != dst_w) {
+ priv->viu.osd_sc_h_ctrl0 =
+ HSC_BANK_LENGTH(hf_bank_len) |
+ HSC_INI_RCV_NUM0(hsc_ini_rcv_num) |
+ HSC_RPT_P0_NUM0(hsc_ini_rpt_p0_num) |
+ HSC_HORIZ_SCALER_EN;
+ priv->viu.osd_sc_h_phase_step = SC_PHASE_STEP(hf_phase_step);
+ priv->viu.osd_sc_h_ini_phase = 0;
+ } else {
+ priv->viu.osd_sc_h_ctrl0 = 0;
+ priv->viu.osd_sc_h_phase_step = 0;
+ priv->viu.osd_sc_h_ini_phase = 0;
+ }
+}
+
static void meson_plane_atomic_update(struct drm_plane *plane,
struct drm_atomic_commit *state)
{
@@ -142,14 +254,6 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
struct drm_framebuffer *fb = new_state->fb;
struct drm_gem_dma_object *gem;
unsigned long flags;
- int vsc_ini_rcv_num, vsc_ini_rpt_p0_num;
- int vsc_bot_rcv_num, vsc_bot_rpt_p0_num;
- int hsc_ini_rcv_num, hsc_ini_rpt_p0_num;
- int hf_phase_step, vf_phase_step;
- int src_w, src_h, dst_w, dst_h;
- int bot_ini_phase;
- int hf_bank_len;
- int vf_bank_len;
u8 canvas_id_osd1;
/*
@@ -241,103 +345,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
/* Use the pixel's alpha */
priv->viu.osd1_ctrl_stat2 &= ~OSD_REPLACE_EN;
- /* Default scaler parameters */
- vsc_bot_rcv_num = 0;
- vsc_bot_rpt_p0_num = 0;
- hf_bank_len = 4;
- vf_bank_len = 4;
-
- if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
- vsc_bot_rcv_num = 6;
- vsc_bot_rpt_p0_num = 2;
- }
-
- hsc_ini_rcv_num = hf_bank_len;
- vsc_ini_rcv_num = vf_bank_len;
- hsc_ini_rpt_p0_num = (hf_bank_len / 2) - 1;
- vsc_ini_rpt_p0_num = (vf_bank_len / 2) - 1;
-
- src_w = fixed16_to_int(new_state->src_w);
- src_h = fixed16_to_int(new_state->src_h);
- dst_w = new_state->crtc_w;
- dst_h = new_state->crtc_h;
-
- /*
- * When the output is interlaced, the OSD must switch between
- * each field using the INTERLACE_SEL_ODD (0) of VIU_OSD1_BLK0_CFG_W0
- * at each vsync.
- * But the vertical scaler can provide such funtionnality if
- * is configured for 2:1 scaling with interlace options enabled.
- */
- if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
- dest.y1 /= 2;
- dest.y2 /= 2;
- dst_h /= 2;
- }
-
- hf_phase_step = ((src_w << 18) / dst_w) << 6;
- vf_phase_step = (src_h << 20) / dst_h;
-
- if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
- bot_ini_phase = ((vf_phase_step / 2) >> 4);
- else
- bot_ini_phase = 0;
-
- vf_phase_step = (vf_phase_step << 4);
-
- /* In interlaced mode, scaler is always active */
- if (src_h != dst_h || src_w != dst_w) {
- priv->viu.osd_sc_i_wh_m1 = SCI_WH_M1_W(src_w - 1) |
- SCI_WH_M1_H(src_h - 1);
- priv->viu.osd_sc_o_h_start_end = SCO_HV_START(dest.x1) |
- SCO_HV_END(dest.x2 - 1);
- priv->viu.osd_sc_o_v_start_end = SCO_HV_START(dest.y1) |
- SCO_HV_END(dest.y2 - 1);
- /* Enable OSD Scaler */
- priv->viu.osd_sc_ctrl0 = SC_CTRL0_PATH_EN | SC_CTRL0_SEL_OSD1;
- } else {
- priv->viu.osd_sc_i_wh_m1 = 0;
- priv->viu.osd_sc_o_h_start_end = 0;
- priv->viu.osd_sc_o_v_start_end = 0;
- priv->viu.osd_sc_ctrl0 = 0;
- }
-
- /* In interlaced mode, vertical scaler is always active */
- if (src_h != dst_h) {
- priv->viu.osd_sc_v_ctrl0 =
- VSC_BANK_LEN(vf_bank_len) |
- VSC_TOP_INI_RCV_NUM(vsc_ini_rcv_num) |
- VSC_TOP_RPT_L0_NUM(vsc_ini_rpt_p0_num) |
- VSC_VERTICAL_SCALER_EN;
-
- if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
- priv->viu.osd_sc_v_ctrl0 |=
- VSC_BOT_INI_RCV_NUM(vsc_bot_rcv_num) |
- VSC_BOT_RPT_L0_NUM(vsc_bot_rpt_p0_num) |
- VSC_PROG_INTERLACE;
-
- priv->viu.osd_sc_v_phase_step = SC_PHASE_STEP(vf_phase_step);
- priv->viu.osd_sc_v_ini_phase = VSC_INI_PHASE_BOT(bot_ini_phase);
- } else {
- priv->viu.osd_sc_v_ctrl0 = 0;
- priv->viu.osd_sc_v_phase_step = 0;
- priv->viu.osd_sc_v_ini_phase = 0;
- }
-
- /* Horizontal scaler is only used if width does not match */
- if (src_w != dst_w) {
- priv->viu.osd_sc_h_ctrl0 =
- HSC_BANK_LENGTH(hf_bank_len) |
- HSC_INI_RCV_NUM0(hsc_ini_rcv_num) |
- HSC_RPT_P0_NUM0(hsc_ini_rpt_p0_num) |
- HSC_HORIZ_SCALER_EN;
- priv->viu.osd_sc_h_phase_step = SC_PHASE_STEP(hf_phase_step);
- priv->viu.osd_sc_h_ini_phase = 0;
- } else {
- priv->viu.osd_sc_h_ctrl0 = 0;
- priv->viu.osd_sc_h_phase_step = 0;
- priv->viu.osd_sc_h_ini_phase = 0;
- }
+ meson_plane_setup_scaler(priv, new_state, &dest);
/*
* The format of these registers is (x2 << 16 | x1),
@@ -354,6 +362,12 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
priv->viu.osd1_blk0_cfg[4] = ((dest.y2 - 1) << 16) | dest.y1;
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
+ int dst_w = new_state->crtc_w;
+ int dst_h = new_state->crtc_h;
+
+ if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
+ dst_h /= 2;
+
priv->viu.osd_blend_din0_scope_h = ((dest.x2 - 1) << 16) | dest.x1;
priv->viu.osd_blend_din0_scope_v = ((dest.y2 - 1) << 16) | dest.y1;
priv->viu.osb_blend0_size = dst_h << 16 | dst_w;
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v3 3/9] drm/meson: keep RGB scanout state per OSD
2026-12-03 19:55 [PATCH v3 0/9] drm/meson: add a second RGB plane on G12A Guillaume La Roque
2026-12-03 19:55 ` [PATCH v3 1/9] drm/meson: honor framebuffer offsets for the primary plane Guillaume La Roque
2026-12-03 19:55 ` [PATCH v3 2/9] drm/meson: isolate primary plane scaler setup Guillaume La Roque
@ 2026-12-03 19:55 ` Guillaume La Roque
2026-12-03 20:21 ` sashiko-bot
2026-12-03 19:55 ` [PATCH v3 4/9] drm/meson: parameterize the G12A OSD color matrix setup Guillaume La Roque
` (5 subsequent siblings)
8 siblings, 1 reply; 13+ messages in thread
From: Guillaume La Roque @ 2026-12-03 19:55 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
linux-kernel, Guillaume La Roque
Group the register cache and framebuffer parameters per RGB plane. Keep
the primary scaler and AFBC controls separate so each OSD can own its
scanout state.
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_crtc.c | 58 ++++++++++++++--------------
drivers/gpu/drm/meson/meson_drv.c | 6 +--
drivers/gpu/drm/meson/meson_drv.h | 42 +++++++++++++-------
drivers/gpu/drm/meson/meson_osd_afbcd.c | 36 ++++++++---------
drivers/gpu/drm/meson/meson_plane.c | 68 ++++++++++++++++-----------------
drivers/gpu/drm/meson/meson_viu.c | 4 +-
6 files changed, 113 insertions(+), 101 deletions(-)
diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
index d1317ddcdfab..27a10508c56e 100644
--- a/drivers/gpu/drm/meson/meson_crtc.c
+++ b/drivers/gpu/drm/meson/meson_crtc.c
@@ -155,8 +155,8 @@ static void meson_g12a_crtc_atomic_disable(struct drm_crtc *crtc,
drm_crtc_vblank_off(crtc);
- priv->viu.osd1_enabled = false;
- priv->viu.osd1_commit = false;
+ priv->viu.osd[0].enabled = false;
+ priv->viu.osd[0].commit = false;
priv->viu.vd1_enabled = false;
priv->viu.vd1_commit = false;
@@ -180,8 +180,8 @@ static void meson_crtc_atomic_disable(struct drm_crtc *crtc,
drm_crtc_vblank_off(crtc);
- priv->viu.osd1_enabled = false;
- priv->viu.osd1_commit = false;
+ priv->viu.osd[0].enabled = false;
+ priv->viu.osd[0].commit = false;
priv->viu.vd1_enabled = false;
priv->viu.vd1_commit = false;
@@ -222,7 +222,7 @@ static void meson_crtc_atomic_flush(struct drm_crtc *crtc,
struct meson_crtc *meson_crtc = to_meson_crtc(crtc);
struct meson_drm *priv = meson_crtc->priv;
- priv->viu.osd1_commit = true;
+ priv->viu.osd[0].commit = true;
priv->viu.vd1_commit = true;
}
@@ -268,16 +268,16 @@ static void meson_crtc_g12a_enable_osd1_afbc(struct meson_drm *priv)
static void meson_g12a_crtc_enable_osd1(struct meson_drm *priv)
{
- writel_relaxed(priv->viu.osd_blend_din0_scope_h,
+ writel_relaxed(priv->viu.osd[0].blk0_cfg[3],
priv->io_base +
_REG(VIU_OSD_BLEND_DIN0_SCOPE_H));
- writel_relaxed(priv->viu.osd_blend_din0_scope_v,
+ writel_relaxed(priv->viu.osd[0].blk0_cfg[4],
priv->io_base +
_REG(VIU_OSD_BLEND_DIN0_SCOPE_V));
- writel_relaxed(priv->viu.osb_blend0_size,
+ writel_relaxed(priv->viu.osd[0].blend_size,
priv->io_base +
_REG(VIU_OSD_BLEND_BLEND0_SIZE));
- writel_relaxed(priv->viu.osb_blend1_size,
+ writel_relaxed(priv->viu.osd[0].blend_size,
priv->io_base +
_REG(VIU_OSD_BLEND_BLEND1_SIZE));
writel_bits_relaxed(3 << 8, 3 << 8,
@@ -316,21 +316,21 @@ void meson_crtc_irq(struct meson_drm *priv)
unsigned long flags;
/* Update the OSD registers */
- if (priv->viu.osd1_enabled && priv->viu.osd1_commit) {
- writel_relaxed(priv->viu.osd1_ctrl_stat,
- priv->io_base + _REG(VIU_OSD1_CTRL_STAT));
- writel_relaxed(priv->viu.osd1_ctrl_stat2,
- priv->io_base + _REG(VIU_OSD1_CTRL_STAT2));
- writel_relaxed(priv->viu.osd1_blk0_cfg[0],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W0));
- writel_relaxed(priv->viu.osd1_blk0_cfg[1],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W1));
- writel_relaxed(priv->viu.osd1_blk0_cfg[2],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W2));
- writel_relaxed(priv->viu.osd1_blk0_cfg[3],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W3));
- writel_relaxed(priv->viu.osd1_blk0_cfg[4],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W4));
+ if (priv->viu.osd[0].enabled && priv->viu.osd[0].commit) {
+ writel_relaxed(priv->viu.osd[0].ctrl_stat,
+ priv->io_base + _REG(VIU_OSD1_CTRL_STAT));
+ writel_relaxed(priv->viu.osd[0].ctrl_stat2,
+ priv->io_base + _REG(VIU_OSD1_CTRL_STAT2));
+ writel_relaxed(priv->viu.osd[0].blk0_cfg[0],
+ priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W0));
+ writel_relaxed(priv->viu.osd[0].blk0_cfg[1],
+ priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W1));
+ writel_relaxed(priv->viu.osd[0].blk0_cfg[2],
+ priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W2));
+ writel_relaxed(priv->viu.osd[0].blk0_cfg[3],
+ priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W3));
+ writel_relaxed(priv->viu.osd[0].blk0_cfg[4],
+ priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W4));
if (priv->viu.osd1_afbcd) {
if (meson_crtc->enable_osd1_afbc)
@@ -367,10 +367,10 @@ void meson_crtc_irq(struct meson_drm *priv)
priv->io_base + _REG(VPP_OSD_VSC_CTRL0));
if (!priv->viu.osd1_afbcd)
- meson_canvas_config(priv->canvas, priv->canvas_id_osd1,
- priv->viu.osd1_addr,
- priv->viu.osd1_stride,
- priv->viu.osd1_height,
+ meson_canvas_config(priv->canvas, priv->canvas_id_osd[0],
+ priv->viu.osd[0].addr,
+ priv->viu.osd[0].stride,
+ priv->viu.osd[0].height,
MESON_CANVAS_WRAP_NONE,
MESON_CANVAS_BLKMODE_LINEAR, 0);
@@ -385,7 +385,7 @@ void meson_crtc_irq(struct meson_drm *priv)
meson_crtc->vsync_forced = true;
}
- priv->viu.osd1_commit = false;
+ priv->viu.osd[0].commit = false;
}
/* Update the VD1 registers */
diff --git a/drivers/gpu/drm/meson/meson_drv.c b/drivers/gpu/drm/meson/meson_drv.c
index 920e43b93d09..4158f2b33ed6 100644
--- a/drivers/gpu/drm/meson/meson_drv.c
+++ b/drivers/gpu/drm/meson/meson_drv.c
@@ -247,7 +247,7 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
goto free_drm;
}
- ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_osd1);
+ ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_osd[0]);
if (ret)
goto free_drm;
ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_0);
@@ -372,7 +372,7 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
free_canvas_vd1_0:
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_0);
free_canvas_osd1:
- meson_canvas_free(priv->canvas, priv->canvas_id_osd1);
+ meson_canvas_free(priv->canvas, priv->canvas_id_osd[0]);
free_drm:
drm_dev_put(drm);
@@ -397,7 +397,7 @@ static void meson_drv_unbind(struct device *dev)
struct drm_device *drm = priv->drm;
if (priv->canvas) {
- meson_canvas_free(priv->canvas, priv->canvas_id_osd1);
+ meson_canvas_free(priv->canvas, priv->canvas_id_osd[0]);
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_0);
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_1);
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_2);
diff --git a/drivers/gpu/drm/meson/meson_drv.h b/drivers/gpu/drm/meson/meson_drv.h
index be4b0e4df6e1..77a5c5e792e9 100644
--- a/drivers/gpu/drm/meson/meson_drv.h
+++ b/drivers/gpu/drm/meson/meson_drv.h
@@ -40,6 +40,32 @@ struct meson_drm_soc_limits {
unsigned long long max_hdmi_phy_freq;
};
+/**
+ * struct meson_osd_state - RGB plane registers applied at vblank
+ * @enabled: Whether the plane is visible
+ * @commit: Whether the register cache is ready to be applied
+ * @ctrl_stat: OSD control and global alpha
+ * @ctrl_stat2: Pixel alpha replacement control
+ * @blk0_cfg: Format and source/destination rectangles
+ * @addr: Framebuffer DMA address, including its plane offset
+ * @stride: Framebuffer pitch in bytes
+ * @height: Framebuffer height in pixels
+ * @width: Framebuffer width in pixels
+ * @blend_size: OSD blender input size
+ */
+struct meson_osd_state {
+ bool enabled;
+ bool commit;
+ u32 ctrl_stat;
+ u32 ctrl_stat2;
+ u32 blk0_cfg[5];
+ u32 addr;
+ u32 stride;
+ u32 height;
+ u32 width;
+ u32 blend_size;
+};
+
struct meson_drm {
struct device *dev;
enum vpu_compatible compat;
@@ -48,7 +74,7 @@ struct meson_drm {
int vsync_irq;
struct meson_canvas *canvas;
- u8 canvas_id_osd1;
+ u8 canvas_id_osd[2];
u8 canvas_id_vd1_0;
u8 canvas_id_vd1_1;
u8 canvas_id_vd1_2;
@@ -63,19 +89,11 @@ struct meson_drm {
/* Components Data */
struct {
- bool osd1_enabled;
+ struct meson_osd_state osd[2];
bool osd1_interlace;
- bool osd1_commit;
bool osd1_afbcd;
- uint32_t osd1_ctrl_stat;
- uint32_t osd1_ctrl_stat2;
- uint32_t osd1_blk0_cfg[5];
uint32_t osd1_blk1_cfg4;
uint32_t osd1_blk2_cfg4;
- uint32_t osd1_addr;
- uint32_t osd1_stride;
- uint32_t osd1_height;
- uint32_t osd1_width;
uint32_t osd_sc_ctrl0;
uint32_t osd_sc_i_wh_m1;
uint32_t osd_sc_o_h_start_end;
@@ -86,10 +104,6 @@ struct meson_drm {
uint32_t osd_sc_h_phase_step;
uint32_t osd_sc_h_ctrl0;
uint32_t osd_sc_v_ctrl0;
- uint32_t osd_blend_din0_scope_h;
- uint32_t osd_blend_din0_scope_v;
- uint32_t osb_blend0_size;
- uint32_t osb_blend1_size;
bool vd1_enabled;
bool vd1_commit;
diff --git a/drivers/gpu/drm/meson/meson_osd_afbcd.c b/drivers/gpu/drm/meson/meson_osd_afbcd.c
index 0cdbe899402f..8f6e9bb73a30 100644
--- a/drivers/gpu/drm/meson/meson_osd_afbcd.c
+++ b/drivers/gpu/drm/meson/meson_osd_afbcd.c
@@ -133,28 +133,28 @@ static int meson_gxm_afbcd_setup(struct meson_drm *priv)
writel_relaxed(mode, priv->io_base + _REG(OSD1_AFBCD_MODE));
writel_relaxed(FIELD_PREP(OSD1_AFBCD_HREG_VSIZE_IN,
- priv->viu.osd1_width) |
+ priv->viu.osd[0].width) |
FIELD_PREP(OSD1_AFBCD_HREG_HSIZE_IN,
- priv->viu.osd1_height),
+ priv->viu.osd[0].height),
priv->io_base + _REG(OSD1_AFBCD_SIZE_IN));
- writel_relaxed(priv->viu.osd1_addr >> 4,
+ writel_relaxed(priv->viu.osd[0].addr >> 4,
priv->io_base + _REG(OSD1_AFBCD_HDR_PTR));
- writel_relaxed(priv->viu.osd1_addr >> 4,
+ writel_relaxed(priv->viu.osd[0].addr >> 4,
priv->io_base + _REG(OSD1_AFBCD_FRAME_PTR));
/* TOFIX: bits 31:24 are not documented, nor the meaning of 0xe4 */
- writel_relaxed((0xe4 << 24) | (priv->viu.osd1_addr & 0xffffff),
+ writel_relaxed((0xe4 << 24) | (priv->viu.osd[0].addr & 0xffffff),
priv->io_base + _REG(OSD1_AFBCD_CHROMA_PTR));
- if (priv->viu.osd1_width <= 128)
+ if (priv->viu.osd[0].width <= 128)
conv_lbuf_len = 32;
- else if (priv->viu.osd1_width <= 256)
+ else if (priv->viu.osd[0].width <= 256)
conv_lbuf_len = 64;
- else if (priv->viu.osd1_width <= 512)
+ else if (priv->viu.osd[0].width <= 512)
conv_lbuf_len = 128;
- else if (priv->viu.osd1_width <= 1024)
+ else if (priv->viu.osd[0].width <= 1024)
conv_lbuf_len = 256;
- else if (priv->viu.osd1_width <= 2048)
+ else if (priv->viu.osd[0].width <= 2048)
conv_lbuf_len = 512;
else
conv_lbuf_len = 1024;
@@ -164,12 +164,12 @@ static int meson_gxm_afbcd_setup(struct meson_drm *priv)
writel_relaxed(FIELD_PREP(OSD1_AFBCD_DEC_PIXEL_BGN_H, 0) |
FIELD_PREP(OSD1_AFBCD_DEC_PIXEL_END_H,
- priv->viu.osd1_width - 1),
+ priv->viu.osd[0].width - 1),
priv->io_base + _REG(OSD1_AFBCD_PIXEL_HSCOPE));
writel_relaxed(FIELD_PREP(OSD1_AFBCD_DEC_PIXEL_BGN_V, 0) |
FIELD_PREP(OSD1_AFBCD_DEC_PIXEL_END_V,
- priv->viu.osd1_height - 1),
+ priv->viu.osd[0].height - 1),
priv->io_base + _REG(OSD1_AFBCD_PIXEL_VSCOPE));
return 0;
@@ -359,23 +359,23 @@ static int meson_g12a_afbcd_setup(struct meson_drm *priv)
meson_rdma_writel_sync(priv, format,
VPU_MAFBC_FORMAT_SPECIFIER_S0);
- meson_rdma_writel_sync(priv, priv->viu.osd1_addr,
+ meson_rdma_writel_sync(priv, priv->viu.osd[0].addr,
VPU_MAFBC_HEADER_BUF_ADDR_LOW_S0);
meson_rdma_writel_sync(priv, 0,
VPU_MAFBC_HEADER_BUF_ADDR_HIGH_S0);
- meson_rdma_writel_sync(priv, priv->viu.osd1_width,
+ meson_rdma_writel_sync(priv, priv->viu.osd[0].width,
VPU_MAFBC_BUFFER_WIDTH_S0);
- meson_rdma_writel_sync(priv, ALIGN(priv->viu.osd1_height, 32),
+ meson_rdma_writel_sync(priv, ALIGN(priv->viu.osd[0].height, 32),
VPU_MAFBC_BUFFER_HEIGHT_S0);
meson_rdma_writel_sync(priv, 0,
VPU_MAFBC_BOUNDING_BOX_X_START_S0);
- meson_rdma_writel_sync(priv, priv->viu.osd1_width - 1,
+ meson_rdma_writel_sync(priv, priv->viu.osd[0].width - 1,
VPU_MAFBC_BOUNDING_BOX_X_END_S0);
meson_rdma_writel_sync(priv, 0,
VPU_MAFBC_BOUNDING_BOX_Y_START_S0);
- meson_rdma_writel_sync(priv, priv->viu.osd1_height - 1,
+ meson_rdma_writel_sync(priv, priv->viu.osd[0].height - 1,
VPU_MAFBC_BOUNDING_BOX_Y_END_S0);
meson_rdma_writel_sync(priv, MESON_G12A_AFBCD_OUT_ADDR,
@@ -383,7 +383,7 @@ static int meson_g12a_afbcd_setup(struct meson_drm *priv)
meson_rdma_writel_sync(priv, 0,
VPU_MAFBC_OUTPUT_BUF_ADDR_HIGH_S0);
- meson_rdma_writel_sync(priv, priv->viu.osd1_width *
+ meson_rdma_writel_sync(priv, priv->viu.osd[0].width *
(meson_g12a_afbcd_bpp(priv->afbcd.format) / 8),
VPU_MAFBC_OUTPUT_BUF_STRIDE_S0);
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 0506e29b6ef3..1698aaecee88 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -117,14 +117,14 @@ static u32 meson_g12a_afbcd_line_stride(struct meson_drm *priv)
switch (priv->afbcd.format) {
case DRM_FORMAT_RGB565:
- line_stride = ((priv->viu.osd1_width << 4) + 127) >> 7;
+ line_stride = ((priv->viu.osd[0].width << 4) + 127) >> 7;
break;
case DRM_FORMAT_RGB888:
case DRM_FORMAT_XRGB8888:
case DRM_FORMAT_ARGB8888:
case DRM_FORMAT_XBGR8888:
case DRM_FORMAT_ABGR8888:
- line_stride = ((priv->viu.osd1_width << 5) + 127) >> 7;
+ line_stride = ((priv->viu.osd[0].width << 5) + 127) >> 7;
break;
}
@@ -251,6 +251,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
plane);
struct drm_rect dest = drm_plane_state_dest(new_state);
struct meson_drm *priv = meson_plane->priv;
+ struct meson_osd_state *osd = &priv->viu.osd[0];
struct drm_framebuffer *fb = new_state->fb;
struct drm_gem_dma_object *gem;
unsigned long flags;
@@ -273,65 +274,65 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
priv->viu.osd1_afbcd = false;
/* Enable OSD and BLK0, set max global alpha */
- priv->viu.osd1_ctrl_stat = OSD_ENABLE |
+ osd->ctrl_stat = OSD_ENABLE |
(0x100 << OSD_GLOBAL_ALPHA_SHIFT) |
OSD_BLK0_ENABLE;
- priv->viu.osd1_ctrl_stat2 = readl(priv->io_base +
+ osd->ctrl_stat2 = readl(priv->io_base +
_REG(VIU_OSD1_CTRL_STAT2));
- canvas_id_osd1 = priv->canvas_id_osd1;
+ canvas_id_osd1 = priv->canvas_id_osd[0];
/* Set up BLK0 to point to the right canvas */
- priv->viu.osd1_blk0_cfg[0] = canvas_id_osd1 << OSD_CANVAS_SEL;
+ osd->blk0_cfg[0] = canvas_id_osd1 << OSD_CANVAS_SEL;
if (priv->viu.osd1_afbcd) {
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
/* This is the internal decoding memory address */
priv->viu.osd1_blk1_cfg4 = MESON_G12A_AFBCD_OUT_ADDR;
- priv->viu.osd1_blk0_cfg[0] |= OSD_ENDIANNESS_BE;
- priv->viu.osd1_ctrl_stat2 |= OSD_PENDING_STAT_CLEAN;
- priv->viu.osd1_ctrl_stat |= VIU_OSD1_CFG_SYN_EN;
+ osd->blk0_cfg[0] |= OSD_ENDIANNESS_BE;
+ osd->ctrl_stat2 |= OSD_PENDING_STAT_CLEAN;
+ osd->ctrl_stat |= VIU_OSD1_CFG_SYN_EN;
}
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM)) {
- priv->viu.osd1_blk0_cfg[0] |= OSD_ENDIANNESS_LE;
- priv->viu.osd1_ctrl_stat2 |= OSD_DPATH_MALI_AFBCD;
+ osd->blk0_cfg[0] |= OSD_ENDIANNESS_LE;
+ osd->ctrl_stat2 |= OSD_DPATH_MALI_AFBCD;
}
} else {
- priv->viu.osd1_blk0_cfg[0] |= OSD_ENDIANNESS_LE;
+ osd->blk0_cfg[0] |= OSD_ENDIANNESS_LE;
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
- priv->viu.osd1_ctrl_stat2 &= ~OSD_DPATH_MALI_AFBCD;
+ osd->ctrl_stat2 &= ~OSD_DPATH_MALI_AFBCD;
}
/* On GXBB, Use the old non-HDR RGB2YUV converter */
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB))
- priv->viu.osd1_blk0_cfg[0] |= OSD_OUTPUT_COLOR_RGB;
+ osd->blk0_cfg[0] |= OSD_OUTPUT_COLOR_RGB;
if (priv->viu.osd1_afbcd &&
meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
- priv->viu.osd1_blk0_cfg[0] |= OSD_MALI_SRC_EN |
+ osd->blk0_cfg[0] |= OSD_MALI_SRC_EN |
priv->afbcd.ops->fmt_to_blk_mode(fb->modifier,
fb->format->format);
} else {
switch (fb->format->format) {
case DRM_FORMAT_XRGB8888:
case DRM_FORMAT_ARGB8888:
- priv->viu.osd1_blk0_cfg[0] |= OSD_BLK_MODE_32 |
+ osd->blk0_cfg[0] |= OSD_BLK_MODE_32 |
OSD_COLOR_MATRIX_32_ARGB;
break;
case DRM_FORMAT_XBGR8888:
case DRM_FORMAT_ABGR8888:
- priv->viu.osd1_blk0_cfg[0] |= OSD_BLK_MODE_32 |
+ osd->blk0_cfg[0] |= OSD_BLK_MODE_32 |
OSD_COLOR_MATRIX_32_ABGR;
break;
case DRM_FORMAT_RGB888:
- priv->viu.osd1_blk0_cfg[0] |= OSD_BLK_MODE_24 |
+ osd->blk0_cfg[0] |= OSD_BLK_MODE_24 |
OSD_COLOR_MATRIX_24_RGB;
break;
case DRM_FORMAT_RGB565:
- priv->viu.osd1_blk0_cfg[0] |= OSD_BLK_MODE_16 |
+ osd->blk0_cfg[0] |= OSD_BLK_MODE_16 |
OSD_COLOR_MATRIX_16_RGB565;
break;
}
@@ -340,10 +341,10 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
if (!fb->format->has_alpha ||
new_state->pixel_blend_mode == DRM_MODE_BLEND_PIXEL_NONE)
/* Ignore the pixel's alpha */
- priv->viu.osd1_ctrl_stat2 |= OSD_REPLACE_EN;
+ osd->ctrl_stat2 |= OSD_REPLACE_EN;
else
/* Use the pixel's alpha */
- priv->viu.osd1_ctrl_stat2 &= ~OSD_REPLACE_EN;
+ osd->ctrl_stat2 &= ~OSD_REPLACE_EN;
meson_plane_setup_scaler(priv, new_state, &dest);
@@ -352,14 +353,14 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
* where x2 is exclusive.
* e.g. +30x1920 would be (1919 << 16) | 30
*/
- priv->viu.osd1_blk0_cfg[1] =
+ osd->blk0_cfg[1] =
((fixed16_to_int(new_state->src.x2) - 1) << 16) |
fixed16_to_int(new_state->src.x1);
- priv->viu.osd1_blk0_cfg[2] =
+ osd->blk0_cfg[2] =
((fixed16_to_int(new_state->src.y2) - 1) << 16) |
fixed16_to_int(new_state->src.y1);
- priv->viu.osd1_blk0_cfg[3] = ((dest.x2 - 1) << 16) | dest.x1;
- priv->viu.osd1_blk0_cfg[4] = ((dest.y2 - 1) << 16) | dest.y1;
+ osd->blk0_cfg[3] = ((dest.x2 - 1) << 16) | dest.x1;
+ osd->blk0_cfg[4] = ((dest.y2 - 1) << 16) | dest.y1;
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
int dst_w = new_state->crtc_w;
@@ -368,19 +369,16 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
dst_h /= 2;
- priv->viu.osd_blend_din0_scope_h = ((dest.x2 - 1) << 16) | dest.x1;
- priv->viu.osd_blend_din0_scope_v = ((dest.y2 - 1) << 16) | dest.y1;
- priv->viu.osb_blend0_size = dst_h << 16 | dst_w;
- priv->viu.osb_blend1_size = dst_h << 16 | dst_w;
+ osd->blend_size = dst_h << 16 | dst_w;
}
/* Update Canvas with buffer address */
gem = drm_fb_dma_get_gem_obj(fb, 0);
- priv->viu.osd1_addr = gem->dma_addr + fb->offsets[0];
- priv->viu.osd1_stride = fb->pitches[0];
- priv->viu.osd1_height = fb->height;
- priv->viu.osd1_width = fb->width;
+ osd->addr = gem->dma_addr + fb->offsets[0];
+ osd->stride = fb->pitches[0];
+ osd->height = fb->height;
+ osd->width = fb->width;
if (priv->viu.osd1_afbcd) {
priv->afbcd.modifier = fb->modifier;
@@ -401,7 +399,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
meson_plane->enabled = true;
}
- priv->viu.osd1_enabled = true;
+ osd->enabled = true;
spin_unlock_irqrestore(&priv->drm->event_lock, flags);
}
@@ -426,7 +424,7 @@ static void meson_plane_atomic_disable(struct drm_plane *plane,
priv->io_base + _REG(VPP_MISC));
meson_plane->enabled = false;
- priv->viu.osd1_enabled = false;
+ priv->viu.osd[0].enabled = false;
}
static const struct drm_plane_helper_funcs meson_plane_helper_funcs = {
diff --git a/drivers/gpu/drm/meson/meson_viu.c b/drivers/gpu/drm/meson/meson_viu.c
index cd399b0b7181..2716d970fe8c 100644
--- a/drivers/gpu/drm/meson/meson_viu.c
+++ b/drivers/gpu/drm/meson/meson_viu.c
@@ -500,7 +500,7 @@ void meson_viu_init(struct meson_drm *priv)
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
meson_viu_gxm_disable_osd1_afbc(priv);
- priv->viu.osd1_enabled = false;
- priv->viu.osd1_commit = false;
+ priv->viu.osd[0].enabled = false;
+ priv->viu.osd[0].commit = false;
priv->viu.osd1_interlace = false;
}
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v3 3/9] drm/meson: keep RGB scanout state per OSD
2026-12-03 19:55 ` [PATCH v3 3/9] drm/meson: keep RGB scanout state per OSD Guillaume La Roque
@ 2026-12-03 20:21 ` sashiko-bot
0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-12-03 20:21 UTC (permalink / raw)
To: Guillaume La Roque; +Cc: dri-devel, linux-amlogic, neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/meson: unvalidated fb->offsets[0] alignment for OSD1
canvas and GXM AFBC
--
commit 3b070782f8ebee577006ed589de24b8f70f0c4cc
Author: Guillaume La Roque <glaroque@baylibre.com>
drm/meson: keep RGB scanout state per OSD
This commit groups the OSD register cache and framebuffer parameters into a
per-plane struct meson_osd_state array while keeping the primary scaler and
AFBC controls separate.
> diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
> index 0506e29b6ef3b..1698aaecee88b 100644
> --- a/drivers/gpu/drm/meson/meson_plane.c
> +++ b/drivers/gpu/drm/meson/meson_plane.c
[ ... ]
> @@ -368,19 +369,16 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
> if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
> dst_h /= 2;
>
> - priv->viu.osd_blend_din0_scope_h = ((dest.x2 - 1) << 16) | dest.x1;
> - priv->viu.osd_blend_din0_scope_v = ((dest.y2 - 1) << 16) | dest.y1;
> - priv->viu.osb_blend0_size = dst_h << 16 | dst_w;
> - priv->viu.osb_blend1_size = dst_h << 16 | dst_w;
> + osd->blend_size = dst_h << 16 | dst_w;
> }
>
> /* Update Canvas with buffer address */
> gem = drm_fb_dma_get_gem_obj(fb, 0);
>
> - priv->viu.osd1_addr = gem->dma_addr + fb->offsets[0];
> - priv->viu.osd1_stride = fb->pitches[0];
> - priv->viu.osd1_height = fb->height;
> - priv->viu.osd1_width = fb->width;
> + osd->addr = gem->dma_addr + fb->offsets[0];
> + osd->stride = fb->pitches[0];
> + osd->height = fb->height;
> + osd->width = fb->width;
[Severity: Medium]
Does meson_plane_atomic_check() validate fb->offsets[0] alignment before
osd->addr is programmed?
drm_gem_fb_create() checks buffer size but not fb->offsets[0] alignment. For
linear scanout, meson_canvas_config() rounds addr up to an 8-byte boundary
via ((addr + 7) >> 3), shifting scanout and allowing canvas DMA to read up to
8 bytes past the end of a tightly sized buffer.
For GXM AFBC, meson_gxm_afbcd_setup() shifts priv->viu.osd[0].addr right by 4
bits, silently dropping the low 4 bits of a non-16-byte-aligned address and
pointing the decoder at the wrong header.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-meson-g12a-osd2-v3-0-2cf76729b5d5@baylibre.com?part=3
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 4/9] drm/meson: parameterize the G12A OSD color matrix setup
2026-12-03 19:55 [PATCH v3 0/9] drm/meson: add a second RGB plane on G12A Guillaume La Roque
` (2 preceding siblings ...)
2026-12-03 19:55 ` [PATCH v3 3/9] drm/meson: keep RGB scanout state per OSD Guillaume La Roque
@ 2026-12-03 19:55 ` Guillaume La Roque
2026-12-03 19:55 ` [PATCH v3 5/9] drm/meson: handle primary plane zpos allocation failure Guillaume La Roque
` (4 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Guillaume La Roque @ 2026-12-03 19:55 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
linux-kernel, Guillaume La Roque
The OSD wrap matrices have the same register layout at different bases.
Select the base by OSD index so both RGB planes can share the CSC setup.
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_viu.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/drivers/gpu/drm/meson/meson_viu.c b/drivers/gpu/drm/meson/meson_viu.c
index 2716d970fe8c..f618e6ba4731 100644
--- a/drivers/gpu/drm/meson/meson_viu.c
+++ b/drivers/gpu/drm/meson/meson_viu.c
@@ -78,32 +78,33 @@ static int eotf_bypass_coeff[EOTF_COEFF_SIZE] = {
EOTF_COEFF_RIGHTSHIFT /* right shift */
};
-static void meson_viu_set_g12a_osd1_matrix(struct meson_drm *priv,
- int *m, bool csc_on)
+static void meson_viu_set_g12a_osd_matrix(struct meson_drm *priv,
+ unsigned int index, int *m)
{
- /* VPP WRAP OSD1 matrix */
+ u32 offset = index ? VPP_WRAP_OSD2_MATRIX_COEF00_01 -
+ VPP_WRAP_OSD1_MATRIX_COEF00_01 : 0;
writel(((m[0] & 0xfff) << 16) | (m[1] & 0xfff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_PRE_OFFSET0_1));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_PRE_OFFSET0_1 + offset));
writel(m[2] & 0xfff,
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_PRE_OFFSET2));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_PRE_OFFSET2 + offset));
writel(((m[3] & 0x1fff) << 16) | (m[4] & 0x1fff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF00_01));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF00_01 + offset));
writel(((m[5] & 0x1fff) << 16) | (m[6] & 0x1fff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF02_10));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF02_10 + offset));
writel(((m[7] & 0x1fff) << 16) | (m[8] & 0x1fff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF11_12));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF11_12 + offset));
writel(((m[9] & 0x1fff) << 16) | (m[10] & 0x1fff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF20_21));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF20_21 + offset));
writel((m[11] & 0x1fff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF22));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_COEF22 + offset));
writel(((m[18] & 0xfff) << 16) | (m[19] & 0xfff),
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_OFFSET0_1));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_OFFSET0_1 + offset));
writel(m[20] & 0xfff,
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_OFFSET2));
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_OFFSET2 + offset));
- writel_bits_relaxed(BIT(0), csc_on ? BIT(0) : 0,
- priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_EN_CTRL));
+ writel_bits_relaxed(BIT(0), BIT(0),
+ priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_EN_CTRL + offset));
}
static void meson_viu_set_osd_matrix(struct meson_drm *priv,
@@ -426,8 +427,7 @@ void meson_viu_init(struct meson_drm *priv)
meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXL))
meson_viu_load_matrix(priv);
else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
- meson_viu_set_g12a_osd1_matrix(priv, RGB709_to_YUV709l_coeff,
- true);
+ meson_viu_set_g12a_osd_matrix(priv, 0, RGB709_to_YUV709l_coeff);
/* fix green/pink color distortion from vendor u-boot */
writel_bits_relaxed(OSD1_HDR2_CTRL_REG_ONLY_MAT |
OSD1_HDR2_CTRL_VDIN0_HDR2_TOP_EN, 0,
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v3 5/9] drm/meson: handle primary plane zpos allocation failure
2026-12-03 19:55 [PATCH v3 0/9] drm/meson: add a second RGB plane on G12A Guillaume La Roque
` (3 preceding siblings ...)
2026-12-03 19:55 ` [PATCH v3 4/9] drm/meson: parameterize the G12A OSD color matrix setup Guillaume La Roque
@ 2026-12-03 19:55 ` Guillaume La Roque
2026-12-03 19:55 ` [PATCH v3 6/9] drm/meson: select RGB plane registers by OSD index Guillaume La Roque
` (3 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Guillaume La Roque @ 2026-12-03 19:55 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
linux-kernel, Guillaume La Roque
Return the allocation error and clean up the primary plane if its zpos
property cannot be created. Otherwise probe succeeds without the property
that describes the plane's fixed stacking order.
Fixes: fd311d880c76 ("drm/meson: Add zpos immutable property to planes")
Reviewed-by: Neil Armstrong <neil.armstrong@linaro.org>
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_plane.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 1698aaecee88..f52eefdd19cc 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -571,7 +571,11 @@ int meson_plane_create(struct meson_drm *priv)
drm_plane_helper_add(plane, &meson_plane_helper_funcs);
/* For now, OSD Primary plane is always on the front */
- drm_plane_create_zpos_immutable_property(plane, 1);
+ ret = drm_plane_create_zpos_immutable_property(plane, 1);
+ if (ret) {
+ drm_plane_cleanup(plane);
+ return ret;
+ }
ret = drm_plane_create_blend_mode_property(plane, blend_modes);
if (ret)
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v3 6/9] drm/meson: select RGB plane registers by OSD index
2026-12-03 19:55 [PATCH v3 0/9] drm/meson: add a second RGB plane on G12A Guillaume La Roque
` (4 preceding siblings ...)
2026-12-03 19:55 ` [PATCH v3 5/9] drm/meson: handle primary plane zpos allocation failure Guillaume La Roque
@ 2026-12-03 19:55 ` Guillaume La Roque
2026-12-03 19:55 ` [PATCH v3 7/9] drm/meson: serialize OSD state updates with the IRQ Guillaume La Roque
` (2 subsequent siblings)
8 siblings, 0 replies; 13+ messages in thread
From: Guillaume La Roque @ 2026-12-03 19:55 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
linux-kernel, Guillaume La Roque
Pass the OSD index through plane creation and use it to select the scanout
cache, canvas and control registers. Move the common register writes to
meson_crtc_flush_osd() so OSD2 can reuse them.
Keep OSD1 as the only registered RGB plane and preserve its AFBC test and
hardware programming order.
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_crtc.c | 33 +++++++++++++++++++--------------
drivers/gpu/drm/meson/meson_drv.c | 2 +-
drivers/gpu/drm/meson/meson_plane.c | 25 ++++++++++++++++---------
drivers/gpu/drm/meson/meson_plane.h | 2 +-
4 files changed, 37 insertions(+), 25 deletions(-)
diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
index 27a10508c56e..71efaa58c183 100644
--- a/drivers/gpu/drm/meson/meson_crtc.c
+++ b/drivers/gpu/drm/meson/meson_crtc.c
@@ -145,6 +145,24 @@ static void meson_crtc_atomic_enable(struct drm_crtc *crtc,
drm_crtc_vblank_on(crtc);
}
+static void meson_crtc_flush_osd(struct meson_drm *priv, unsigned int index)
+{
+ struct meson_osd_state *osd = &priv->viu.osd[index];
+ u32 ctrl_stat = index ? VIU_OSD2_CTRL_STAT : VIU_OSD1_CTRL_STAT;
+ u32 ctrl_stat2 = index ? VIU_OSD2_CTRL_STAT2 : VIU_OSD1_CTRL_STAT2;
+ u32 blk0_cfg = index ? VIU_OSD2_BLK0_CFG_W0 : VIU_OSD1_BLK0_CFG_W0;
+ u32 blk0_cfg4 = index ? VIU_OSD2_BLK0_CFG_W4 : VIU_OSD1_BLK0_CFG_W4;
+ unsigned int i;
+
+ writel_relaxed(osd->ctrl_stat, priv->io_base + _REG(ctrl_stat));
+ writel_relaxed(osd->ctrl_stat2, priv->io_base + _REG(ctrl_stat2));
+ for (i = 0; i < 4; i++)
+ writel_relaxed(osd->blk0_cfg[i],
+ priv->io_base + _REG(blk0_cfg + i));
+
+ writel_relaxed(osd->blk0_cfg[4], priv->io_base + _REG(blk0_cfg4));
+}
+
static void meson_g12a_crtc_atomic_disable(struct drm_crtc *crtc,
struct drm_atomic_commit *state)
{
@@ -317,20 +335,7 @@ void meson_crtc_irq(struct meson_drm *priv)
/* Update the OSD registers */
if (priv->viu.osd[0].enabled && priv->viu.osd[0].commit) {
- writel_relaxed(priv->viu.osd[0].ctrl_stat,
- priv->io_base + _REG(VIU_OSD1_CTRL_STAT));
- writel_relaxed(priv->viu.osd[0].ctrl_stat2,
- priv->io_base + _REG(VIU_OSD1_CTRL_STAT2));
- writel_relaxed(priv->viu.osd[0].blk0_cfg[0],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W0));
- writel_relaxed(priv->viu.osd[0].blk0_cfg[1],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W1));
- writel_relaxed(priv->viu.osd[0].blk0_cfg[2],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W2));
- writel_relaxed(priv->viu.osd[0].blk0_cfg[3],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W3));
- writel_relaxed(priv->viu.osd[0].blk0_cfg[4],
- priv->io_base + _REG(VIU_OSD1_BLK0_CFG_W4));
+ meson_crtc_flush_osd(priv, 0);
if (priv->viu.osd1_afbcd) {
if (meson_crtc->enable_osd1_afbc)
diff --git a/drivers/gpu/drm/meson/meson_drv.c b/drivers/gpu/drm/meson/meson_drv.c
index 4158f2b33ed6..8b5ad1598457 100644
--- a/drivers/gpu/drm/meson/meson_drv.c
+++ b/drivers/gpu/drm/meson/meson_drv.c
@@ -328,7 +328,7 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
goto exit_afbcd;
}
- ret = meson_plane_create(priv);
+ ret = meson_plane_create(priv, 0);
if (ret)
goto exit_afbcd;
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index f52eefdd19cc..79b86d5338d8 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -66,6 +66,7 @@
struct meson_plane {
struct drm_plane base;
struct meson_drm *priv;
+ unsigned int index;
bool enabled;
};
#define to_meson_plane(x) container_of(x, struct meson_plane, base)
@@ -251,11 +252,11 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
plane);
struct drm_rect dest = drm_plane_state_dest(new_state);
struct meson_drm *priv = meson_plane->priv;
- struct meson_osd_state *osd = &priv->viu.osd[0];
struct drm_framebuffer *fb = new_state->fb;
struct drm_gem_dma_object *gem;
unsigned long flags;
- u8 canvas_id_osd1;
+ unsigned int index = meson_plane->index;
+ struct meson_osd_state *osd = &priv->viu.osd[index];
/*
* Update Coordinates
@@ -279,12 +280,10 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
OSD_BLK0_ENABLE;
osd->ctrl_stat2 = readl(priv->io_base +
- _REG(VIU_OSD1_CTRL_STAT2));
-
- canvas_id_osd1 = priv->canvas_id_osd[0];
+ _REG(index ? VIU_OSD2_CTRL_STAT2 : VIU_OSD1_CTRL_STAT2));
/* Set up BLK0 to point to the right canvas */
- osd->blk0_cfg[0] = canvas_id_osd1 << OSD_CANVAS_SEL;
+ osd->blk0_cfg[0] = priv->canvas_id_osd[index] << OSD_CANVAS_SEL;
if (priv->viu.osd1_afbcd) {
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
@@ -424,7 +423,7 @@ static void meson_plane_atomic_disable(struct drm_plane *plane,
priv->io_base + _REG(VPP_MISC));
meson_plane->enabled = false;
- priv->viu.osd[0].enabled = false;
+ priv->viu.osd[meson_plane->index].enabled = false;
}
static const struct drm_plane_helper_funcs meson_plane_helper_funcs = {
@@ -537,7 +536,14 @@ static const uint64_t format_modifiers_default[] = {
DRM_FORMAT_MOD_INVALID,
};
-int meson_plane_create(struct meson_drm *priv)
+/**
+ * meson_plane_create - Register an RGB plane
+ * @priv: Meson DRM device
+ * @index: Zero-based OSD index
+ *
+ * Return: 0 on success or a negative error code.
+ */
+int meson_plane_create(struct meson_drm *priv, unsigned int index)
{
struct meson_plane *meson_plane;
struct drm_plane *plane;
@@ -550,6 +556,7 @@ int meson_plane_create(struct meson_drm *priv)
return -ENOMEM;
meson_plane->priv = priv;
+ meson_plane->index = index;
plane = &meson_plane->base;
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
@@ -571,7 +578,7 @@ int meson_plane_create(struct meson_drm *priv)
drm_plane_helper_add(plane, &meson_plane_helper_funcs);
/* For now, OSD Primary plane is always on the front */
- ret = drm_plane_create_zpos_immutable_property(plane, 1);
+ ret = drm_plane_create_zpos_immutable_property(plane, index + 1);
if (ret) {
drm_plane_cleanup(plane);
return ret;
diff --git a/drivers/gpu/drm/meson/meson_plane.h b/drivers/gpu/drm/meson/meson_plane.h
index 1460e182cd22..6e891d54bb63 100644
--- a/drivers/gpu/drm/meson/meson_plane.h
+++ b/drivers/gpu/drm/meson/meson_plane.h
@@ -13,6 +13,6 @@
#include "meson_drv.h"
-int meson_plane_create(struct meson_drm *priv);
+int meson_plane_create(struct meson_drm *priv, unsigned int index);
#endif /* __MESON_PLANE_H */
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v3 7/9] drm/meson: serialize OSD state updates with the IRQ
2026-12-03 19:55 [PATCH v3 0/9] drm/meson: add a second RGB plane on G12A Guillaume La Roque
` (5 preceding siblings ...)
2026-12-03 19:55 ` [PATCH v3 6/9] drm/meson: select RGB plane registers by OSD index Guillaume La Roque
@ 2026-12-03 19:55 ` Guillaume La Roque
2026-12-03 19:55 ` [PATCH v3 8/9] drm/meson: clear pending primary updates while disabled Guillaume La Roque
2026-12-03 19:55 ` [PATCH v3 9/9] drm/meson: add a linear RGB overlay on G12A OSD2 Guillaume La Roque
8 siblings, 0 replies; 13+ messages in thread
From: Guillaume La Roque @ 2026-12-03 19:55 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
linux-kernel, Guillaume La Roque
Use event_lock when the IRQ consumes the cached OSD state and when atomic
flush publishes the commit flags, matching the lock held by plane update.
Clear the cached enable state under the same lock before disabling the
primary hardware. This prevents the IRQ from programming it during
teardown and prepares the shared state handling for a second OSD.
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_crtc.c | 13 +++++++++++++
drivers/gpu/drm/meson/meson_plane.c | 9 ++++++---
2 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
index 71efaa58c183..70acb034b812 100644
--- a/drivers/gpu/drm/meson/meson_crtc.c
+++ b/drivers/gpu/drm/meson/meson_crtc.c
@@ -168,13 +168,16 @@ static void meson_g12a_crtc_atomic_disable(struct drm_crtc *crtc,
{
struct meson_crtc *meson_crtc = to_meson_crtc(crtc);
struct meson_drm *priv = meson_crtc->priv;
+ unsigned long flags;
DRM_DEBUG_DRIVER("\n");
drm_crtc_vblank_off(crtc);
+ spin_lock_irqsave(&priv->drm->event_lock, flags);
priv->viu.osd[0].enabled = false;
priv->viu.osd[0].commit = false;
+ spin_unlock_irqrestore(&priv->drm->event_lock, flags);
priv->viu.vd1_enabled = false;
priv->viu.vd1_commit = false;
@@ -193,11 +196,13 @@ static void meson_crtc_atomic_disable(struct drm_crtc *crtc,
{
struct meson_crtc *meson_crtc = to_meson_crtc(crtc);
struct meson_drm *priv = meson_crtc->priv;
+ unsigned long flags;
DRM_DEBUG_DRIVER("\n");
drm_crtc_vblank_off(crtc);
+ spin_lock_irqsave(&priv->drm->event_lock, flags);
priv->viu.osd[0].enabled = false;
priv->viu.osd[0].commit = false;
@@ -208,6 +213,7 @@ static void meson_crtc_atomic_disable(struct drm_crtc *crtc,
writel_bits_relaxed(VPP_OSD1_POSTBLEND | VPP_VD1_POSTBLEND |
VPP_VD1_PREBLEND | VPP_POSTBLEND_ENABLE, 0,
priv->io_base + _REG(VPP_MISC));
+ spin_unlock_irqrestore(&priv->drm->event_lock, flags);
if (crtc->state->event && !crtc->state->active) {
spin_lock_irq(&crtc->dev->event_lock);
@@ -239,9 +245,12 @@ static void meson_crtc_atomic_flush(struct drm_crtc *crtc,
{
struct meson_crtc *meson_crtc = to_meson_crtc(crtc);
struct meson_drm *priv = meson_crtc->priv;
+ unsigned long flags;
+ spin_lock_irqsave(&priv->drm->event_lock, flags);
priv->viu.osd[0].commit = true;
priv->viu.vd1_commit = true;
+ spin_unlock_irqrestore(&priv->drm->event_lock, flags);
}
static const struct drm_crtc_helper_funcs meson_crtc_helper_funcs = {
@@ -333,6 +342,8 @@ void meson_crtc_irq(struct meson_drm *priv)
struct meson_crtc *meson_crtc = to_meson_crtc(priv->crtc);
unsigned long flags;
+ spin_lock_irqsave(&priv->drm->event_lock, flags);
+
/* Update the OSD registers */
if (priv->viu.osd[0].enabled && priv->viu.osd[0].commit) {
meson_crtc_flush_osd(priv, 0);
@@ -393,6 +404,8 @@ void meson_crtc_irq(struct meson_drm *priv)
priv->viu.osd[0].commit = false;
}
+ spin_unlock_irqrestore(&priv->drm->event_lock, flags);
+
/* Update the VD1 registers */
if (priv->viu.vd1_enabled && priv->viu.vd1_commit) {
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index 79b86d5338d8..ab3faa8d5226 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -408,6 +408,12 @@ static void meson_plane_atomic_disable(struct drm_plane *plane,
{
struct meson_plane *meson_plane = to_meson_plane(plane);
struct meson_drm *priv = meson_plane->priv;
+ unsigned long flags;
+
+ spin_lock_irqsave(&priv->drm->event_lock, flags);
+ meson_plane->enabled = false;
+ priv->viu.osd[meson_plane->index].enabled = false;
+ spin_unlock_irqrestore(&priv->drm->event_lock, flags);
if (priv->afbcd.ops) {
priv->afbcd.ops->reset(priv);
@@ -421,9 +427,6 @@ static void meson_plane_atomic_disable(struct drm_plane *plane,
else
writel_bits_relaxed(VPP_OSD1_POSTBLEND, 0,
priv->io_base + _REG(VPP_MISC));
-
- meson_plane->enabled = false;
- priv->viu.osd[meson_plane->index].enabled = false;
}
static const struct drm_plane_helper_funcs meson_plane_helper_funcs = {
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 13+ messages in thread* [PATCH v3 8/9] drm/meson: clear pending primary updates while disabled
2026-12-03 19:55 [PATCH v3 0/9] drm/meson: add a second RGB plane on G12A Guillaume La Roque
` (6 preceding siblings ...)
2026-12-03 19:55 ` [PATCH v3 7/9] drm/meson: serialize OSD state updates with the IRQ Guillaume La Roque
@ 2026-12-03 19:55 ` Guillaume La Roque
2026-12-03 20:41 ` sashiko-bot
2026-12-03 19:55 ` [PATCH v3 9/9] drm/meson: add a linear RGB overlay on G12A OSD2 Guillaume La Roque
8 siblings, 1 reply; 13+ messages in thread
From: Guillaume La Roque @ 2026-12-03 19:55 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
linux-kernel, Guillaume La Roque
A flush with the primary plane disabled leaves its commit flag set.
When the plane is enabled again, an IRQ can consume its new register
cache before atomic_flush publishes the update.
Clear the pending flag at each vsync after handling OSD1, including
when the plane is disabled.
Fixes: cc0c43a0450c ("drm/meson: Use crtc_state for hdisplay and fix atomic flush/enable sync for vsync commit")
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_crtc.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
index 70acb034b812..19412d0d7432 100644
--- a/drivers/gpu/drm/meson/meson_crtc.c
+++ b/drivers/gpu/drm/meson/meson_crtc.c
@@ -400,9 +400,8 @@ void meson_crtc_irq(struct meson_drm *priv)
priv->afbcd.ops->enable(priv);
meson_crtc->vsync_forced = true;
}
-
- priv->viu.osd[0].commit = false;
}
+ priv->viu.osd[0].commit = false;
spin_unlock_irqrestore(&priv->drm->event_lock, flags);
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 13+ messages in thread* Re: [PATCH v3 8/9] drm/meson: clear pending primary updates while disabled
2026-12-03 19:55 ` [PATCH v3 8/9] drm/meson: clear pending primary updates while disabled Guillaume La Roque
@ 2026-12-03 20:41 ` sashiko-bot
0 siblings, 0 replies; 13+ messages in thread
From: sashiko-bot @ 2026-12-03 20:41 UTC (permalink / raw)
To: Guillaume La Roque; +Cc: dri-devel, linux-amlogic, neil.armstrong
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/meson: stale osd[0].commit race remains after
meson_crtc_atomic_flush()
--
commit a6c0c91ee07dba45520e5b6a8a5a8aea3e7d0fd6
Author: Guillaume La Roque <glaroque@baylibre.com>
drm/meson: clear pending primary updates while disabled
This commit moves clearing priv->viu.osd[0].commit in meson_crtc_irq() outside
the enabled check so pending primary plane updates are cleared on vsync even
when OSD1 is disabled.
> diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
> index 70acb034b8125..19412d0d74328 100644
> --- a/drivers/gpu/drm/meson/meson_crtc.c
> +++ b/drivers/gpu/drm/meson/meson_crtc.c
> @@ -400,9 +400,8 @@ void meson_crtc_irq(struct meson_drm *priv)
> priv->afbcd.ops->enable(priv);
> meson_crtc->vsync_forced = true;
> }
> -
> - priv->viu.osd[0].commit = false;
> }
> + priv->viu.osd[0].commit = false;
>
> spin_unlock_irqrestore(&priv->drm->event_lock, flags);
[Severity: Medium]
Can priv->viu.osd[0].commit still remain set when OSD1 is re-enabled?
meson_crtc_atomic_begin() arms meson_crtc->event before atomic_flush(), and
meson_crtc_atomic_flush() still sets priv->viu.osd[0].commit = true even when
OSD1 is disabled. If a vsync IRQ runs between the two on a nonblocking
commit, it clears the flag and signals flip_done before atomic_flush():
CPU0 CPU1 (<hardirq>)
/* Commit 1: OSD1 disabled */
meson_crtc_atomic_begin()
meson_crtc->event = state->event
meson_crtc_irq()
osd[0].commit = false
drm_crtc_send_vblank_event()
/* signals Commit 1 flip_done */
meson_crtc_atomic_flush()
osd[0].commit = true
drm_atomic_helper_commit_hw_done()
/* Commit 2: re-enables OSD1 */
drm_crtc_commit_wait() /* passes */
meson_plane_atomic_update()
osd[0].enabled = true
meson_crtc_irq()
/* enabled && commit are true */
meson_crtc_flush_osd() <-- early
Because Commit 2 only waits on Commit 1's hw_done and flip_done,
meson_plane_atomic_update() can re-enable OSD1 while the stale commit flag is
still set. A vsync IRQ before Commit 2's atomic_flush() then latches the new
register cache prematurely, causing tearing or desynchronized plane updates.
Gating priv->viu.osd[0].commit = true on priv->viu.osd[0].enabled in
meson_crtc_atomic_flush(), clearing commit in meson_plane_atomic_disable(),
and arming meson_crtc->event in meson_crtc_atomic_flush() under event_lock
would prevent the stale flag from surviving across commits.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261203-meson-g12a-osd2-v3-0-2cf76729b5d5@baylibre.com?part=8
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply [flat|nested] 13+ messages in thread
* [PATCH v3 9/9] drm/meson: add a linear RGB overlay on G12A OSD2
2026-12-03 19:55 [PATCH v3 0/9] drm/meson: add a second RGB plane on G12A Guillaume La Roque
` (7 preceding siblings ...)
2026-12-03 19:55 ` [PATCH v3 8/9] drm/meson: clear pending primary updates while disabled Guillaume La Roque
@ 2026-12-03 19:55 ` Guillaume La Roque
8 siblings, 0 replies; 13+ messages in thread
From: Guillaume La Roque @ 2026-12-03 19:55 UTC (permalink / raw)
To: Neil Armstrong, Maarten Lankhorst, Maxime Ripard,
Thomas Zimmermann, David Airlie, Simona Vetter, Kevin Hilman,
Jerome Brunet, Martin Blumenstingl
Cc: dri-devel, linux-amlogic, linux-arm-kernel, Simona Vetter,
linux-kernel, Guillaume La Roque
The VD1 overlay cannot scan out the RGB buffers used by the UI. Expose
OSD2 above the primary plane on G12A, G12B and SM1 to allow hardware
composition of another RGB layer.
The RGB-to-YUV CSC expects straight RGB. Enable the alpha divider for
premultiplied buffers and use straight alpha at postblend. Limit this
plane to linear buffers without scaling or interlace.
Signed-off-by: Guillaume La Roque <glaroque@baylibre.com>
---
drivers/gpu/drm/meson/meson_crtc.c | 68 ++++++++++++-
drivers/gpu/drm/meson/meson_drv.c | 17 +++-
drivers/gpu/drm/meson/meson_drv.h | 3 +
drivers/gpu/drm/meson/meson_encoder_dsi.c | 2 +
drivers/gpu/drm/meson/meson_plane.c | 157 ++++++++++++++++++++++--------
drivers/gpu/drm/meson/meson_registers.h | 5 +
drivers/gpu/drm/meson/meson_viu.c | 16 +++
7 files changed, 224 insertions(+), 44 deletions(-)
diff --git a/drivers/gpu/drm/meson/meson_crtc.c b/drivers/gpu/drm/meson/meson_crtc.c
index 19412d0d7432..38a813772c79 100644
--- a/drivers/gpu/drm/meson/meson_crtc.c
+++ b/drivers/gpu/drm/meson/meson_crtc.c
@@ -12,6 +12,7 @@
#include <linux/bitfield.h>
#include <linux/soc/amlogic/meson-canvas.h>
+#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/drm_device.h>
#include <drm/drm_print.h>
@@ -154,6 +155,18 @@ static void meson_crtc_flush_osd(struct meson_drm *priv, unsigned int index)
u32 blk0_cfg4 = index ? VIU_OSD2_BLK0_CFG_W4 : VIU_OSD1_BLK0_CFG_W4;
unsigned int i;
+ if (!osd->enabled) {
+ writel_bits_relaxed(OSD_ENABLE | OSD_BLK0_ENABLE, 0,
+ priv->io_base + _REG(ctrl_stat));
+ if (index) {
+ writel_bits_relaxed(OSD_BLEND_POSTBLD_SRC_MASK, 0,
+ priv->io_base + _REG(OSD2_BLEND_SRC_CTRL));
+ writel_bits_relaxed(VIU_OSD_BLEND_DIN_EN(8), 0,
+ priv->io_base + _REG(VIU_OSD_BLEND_CTRL));
+ }
+ return;
+ }
+
writel_relaxed(osd->ctrl_stat, priv->io_base + _REG(ctrl_stat));
writel_relaxed(osd->ctrl_stat2, priv->io_base + _REG(ctrl_stat2));
for (i = 0; i < 4; i++)
@@ -161,6 +174,44 @@ static void meson_crtc_flush_osd(struct meson_drm *priv, unsigned int index)
priv->io_base + _REG(blk0_cfg + i));
writel_relaxed(osd->blk0_cfg[4], priv->io_base + _REG(blk0_cfg4));
+
+ if (!index)
+ return;
+
+ meson_canvas_config(priv->canvas, priv->canvas_id_osd[index],
+ osd->addr, osd->stride, osd->height,
+ MESON_CANVAS_WRAP_NONE,
+ MESON_CANVAS_BLKMODE_LINEAR, 0);
+
+ writel_bits_relaxed(OSD_MALI_ALPHA_DIV_EN,
+ osd->alpha_div ? OSD_MALI_ALPHA_DIV_EN : 0,
+ priv->io_base + _REG(VIU_OSD2_MALI_UNPACK_CTRL));
+ writel_relaxed(osd->blk0_cfg[3],
+ priv->io_base + _REG(VIU_OSD_BLEND_DIN3_SCOPE_H));
+ writel_relaxed(osd->blk0_cfg[4],
+ priv->io_base + _REG(VIU_OSD_BLEND_DIN3_SCOPE_V));
+ /*
+ * DIN0 and DIN3 feed DOUT0 and DOUT1 directly. The BLEND1-to-BLEND2
+ * route stays configured but is outside both bypass paths. DIN3 and
+ * VPP scopes stay in CRTC coordinates; BLEND1_SIZE is the clipped
+ * OSD2 raster size without the CRTC offset.
+ */
+ writel_relaxed(osd->blend_size,
+ priv->io_base + _REG(VIU_OSD_BLEND_BLEND1_SIZE));
+ writel_relaxed((osd->blk0_cfg[3] << 16) | (osd->blk0_cfg[3] >> 16),
+ priv->io_base + _REG(VPP_OSD2_BLD_H_SCOPE));
+ writel_relaxed((osd->blk0_cfg[4] << 16) | (osd->blk0_cfg[4] >> 16),
+ priv->io_base + _REG(VPP_OSD2_BLD_V_SCOPE));
+ writel_bits_relaxed(VIU_OSD_BLEND_REORDER(3, 0xf) |
+ VIU_OSD_BLEND_DIN_EN(8),
+ VIU_OSD_BLEND_REORDER(3, 2) |
+ VIU_OSD_BLEND_DIN_EN(8),
+ priv->io_base + _REG(VIU_OSD_BLEND_CTRL));
+ /* DIN3 bypasses the OSD blender, so VPP receives straight alpha. */
+ writel_bits_relaxed(OSD_BLEND_POSTBLD_SRC_MASK |
+ OSD_BLEND_POSTBLD_PREMULT_EN,
+ OSD_BLEND_POSTBLD_SRC_OSD2,
+ priv->io_base + _REG(OSD2_BLEND_SRC_CTRL));
}
static void meson_g12a_crtc_atomic_disable(struct drm_crtc *crtc,
@@ -177,6 +228,9 @@ static void meson_g12a_crtc_atomic_disable(struct drm_crtc *crtc,
spin_lock_irqsave(&priv->drm->event_lock, flags);
priv->viu.osd[0].enabled = false;
priv->viu.osd[0].commit = false;
+ priv->viu.osd[1].enabled = false;
+ priv->viu.osd[1].commit = false;
+ meson_crtc_flush_osd(priv, 1);
spin_unlock_irqrestore(&priv->drm->event_lock, flags);
priv->viu.vd1_enabled = false;
@@ -205,6 +259,8 @@ static void meson_crtc_atomic_disable(struct drm_crtc *crtc,
spin_lock_irqsave(&priv->drm->event_lock, flags);
priv->viu.osd[0].enabled = false;
priv->viu.osd[0].commit = false;
+ priv->viu.osd[1].enabled = false;
+ priv->viu.osd[1].commit = false;
priv->viu.vd1_enabled = false;
priv->viu.vd1_commit = false;
@@ -249,6 +305,9 @@ static void meson_crtc_atomic_flush(struct drm_crtc *crtc,
spin_lock_irqsave(&priv->drm->event_lock, flags);
priv->viu.osd[0].commit = true;
+ if (priv->osd2_plane &&
+ drm_atomic_get_new_plane_state(state, priv->osd2_plane))
+ priv->viu.osd[1].commit = true;
priv->viu.vd1_commit = true;
spin_unlock_irqrestore(&priv->drm->event_lock, flags);
}
@@ -304,7 +363,8 @@ static void meson_g12a_crtc_enable_osd1(struct meson_drm *priv)
writel_relaxed(priv->viu.osd[0].blend_size,
priv->io_base +
_REG(VIU_OSD_BLEND_BLEND0_SIZE));
- writel_relaxed(priv->viu.osd[0].blend_size,
+ writel_relaxed(priv->viu.osd[1].enabled ? priv->viu.osd[1].blend_size :
+ priv->viu.osd[0].blend_size,
priv->io_base +
_REG(VIU_OSD_BLEND_BLEND1_SIZE));
writel_bits_relaxed(3 << 8, 3 << 8,
@@ -344,6 +404,12 @@ void meson_crtc_irq(struct meson_drm *priv)
spin_lock_irqsave(&priv->drm->event_lock, flags);
+ if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A) &&
+ priv->viu.osd[1].commit) {
+ meson_crtc_flush_osd(priv, 1);
+ priv->viu.osd[1].commit = false;
+ }
+
/* Update the OSD registers */
if (priv->viu.osd[0].enabled && priv->viu.osd[0].commit) {
meson_crtc_flush_osd(priv, 0);
diff --git a/drivers/gpu/drm/meson/meson_drv.c b/drivers/gpu/drm/meson/meson_drv.c
index 8b5ad1598457..fdfd1e53bd73 100644
--- a/drivers/gpu/drm/meson/meson_drv.c
+++ b/drivers/gpu/drm/meson/meson_drv.c
@@ -250,9 +250,14 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_osd[0]);
if (ret)
goto free_drm;
+ if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
+ ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_osd[1]);
+ if (ret)
+ goto free_canvas_osd1;
+ }
ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_0);
if (ret)
- goto free_canvas_osd1;
+ goto free_canvas_osd2;
ret = meson_canvas_alloc(priv->canvas, &priv->canvas_id_vd1_1);
if (ret)
goto free_canvas_vd1_0;
@@ -335,6 +340,11 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
ret = meson_overlay_create(priv);
if (ret)
goto exit_afbcd;
+ if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
+ ret = meson_plane_create(priv, 1);
+ if (ret)
+ goto exit_afbcd;
+ }
ret = meson_crtc_create(priv);
if (ret)
@@ -371,6 +381,9 @@ static int meson_drv_bind_master(struct device *dev, bool has_components)
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_1);
free_canvas_vd1_0:
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_0);
+free_canvas_osd2:
+ if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
+ meson_canvas_free(priv->canvas, priv->canvas_id_osd[1]);
free_canvas_osd1:
meson_canvas_free(priv->canvas, priv->canvas_id_osd[0]);
free_drm:
@@ -398,6 +411,8 @@ static void meson_drv_unbind(struct device *dev)
if (priv->canvas) {
meson_canvas_free(priv->canvas, priv->canvas_id_osd[0]);
+ if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
+ meson_canvas_free(priv->canvas, priv->canvas_id_osd[1]);
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_0);
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_1);
meson_canvas_free(priv->canvas, priv->canvas_id_vd1_2);
diff --git a/drivers/gpu/drm/meson/meson_drv.h b/drivers/gpu/drm/meson/meson_drv.h
index 77a5c5e792e9..0f2dcf9755b2 100644
--- a/drivers/gpu/drm/meson/meson_drv.h
+++ b/drivers/gpu/drm/meson/meson_drv.h
@@ -44,6 +44,7 @@ struct meson_drm_soc_limits {
* struct meson_osd_state - RGB plane registers applied at vblank
* @enabled: Whether the plane is visible
* @commit: Whether the register cache is ready to be applied
+ * @alpha_div: Convert premultiplied RGB to straight RGB before the CSC
* @ctrl_stat: OSD control and global alpha
* @ctrl_stat2: Pixel alpha replacement control
* @blk0_cfg: Format and source/destination rectangles
@@ -56,6 +57,7 @@ struct meson_drm_soc_limits {
struct meson_osd_state {
bool enabled;
bool commit;
+ bool alpha_div;
u32 ctrl_stat;
u32 ctrl_stat2;
u32 blk0_cfg[5];
@@ -82,6 +84,7 @@ struct meson_drm {
struct drm_device *drm;
struct drm_crtc *crtc;
struct drm_plane *primary_plane;
+ struct drm_plane *osd2_plane;
struct drm_plane *overlay_plane;
void *encoders[MESON_ENC_LAST];
diff --git a/drivers/gpu/drm/meson/meson_encoder_dsi.c b/drivers/gpu/drm/meson/meson_encoder_dsi.c
index faa309cb97a6..8283734aedac 100644
--- a/drivers/gpu/drm/meson/meson_encoder_dsi.c
+++ b/drivers/gpu/drm/meson/meson_encoder_dsi.c
@@ -74,6 +74,7 @@ static void meson_encoder_dsi_atomic_enable(struct drm_bridge *bridge,
writel_relaxed(0, priv->io_base + _REG(ENCL_TST_EN));
writel_bits_relaxed(BIT(0), 0, priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_EN_CTRL));
+ writel_bits_relaxed(BIT(0), 0, priv->io_base + _REG(VPP_WRAP_OSD2_MATRIX_EN_CTRL));
writel_relaxed(1, priv->io_base + _REG(ENCL_VIDEO_EN));
}
@@ -88,6 +89,7 @@ static void meson_encoder_dsi_atomic_disable(struct drm_bridge *bridge,
writel_relaxed(0, priv->io_base + _REG(ENCL_VIDEO_EN));
writel_bits_relaxed(BIT(0), BIT(0), priv->io_base + _REG(VPP_WRAP_OSD1_MATRIX_EN_CTRL));
+ writel_bits_relaxed(BIT(0), BIT(0), priv->io_base + _REG(VPP_WRAP_OSD2_MATRIX_EN_CTRL));
}
static const struct drm_bridge_funcs meson_encoder_dsi_bridge_funcs = {
diff --git a/drivers/gpu/drm/meson/meson_plane.c b/drivers/gpu/drm/meson/meson_plane.c
index ab3faa8d5226..9c670ec4eae2 100644
--- a/drivers/gpu/drm/meson/meson_plane.c
+++ b/drivers/gpu/drm/meson/meson_plane.c
@@ -10,6 +10,7 @@
*/
#include <linux/bitfield.h>
+#include <linux/sizes.h>
#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
@@ -78,7 +79,11 @@ static int meson_plane_atomic_check(struct drm_plane *plane,
{
struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
plane);
+ struct meson_plane *meson_plane = to_meson_plane(plane);
+ struct drm_framebuffer *fb = new_plane_state->fb;
+ struct drm_gem_dma_object *gem;
struct drm_crtc_state *crtc_state;
+ int ret;
if (!new_plane_state->crtc)
return 0;
@@ -88,16 +93,33 @@ static int meson_plane_atomic_check(struct drm_plane *plane,
if (IS_ERR(crtc_state))
return PTR_ERR(crtc_state);
- /*
- * Only allow :
- * - Upscaling up to 5x, vertical and horizontal
- * - Final coordinates must match crtc size
- */
- return drm_atomic_helper_check_plane_state(new_plane_state,
- crtc_state,
- FRAC_16_16(1, 5),
- DRM_PLANE_NO_SCALING,
- false, true);
+ if (meson_plane->index &&
+ crtc_state->adjusted_mode.flags & DRM_MODE_FLAG_INTERLACE)
+ return -EINVAL;
+
+ /* OSD1 can upscale up to 5x; OSD2 is positioned without scaling. */
+ ret = drm_atomic_helper_check_plane_state(new_plane_state, crtc_state,
+ meson_plane->index ?
+ DRM_PLANE_NO_SCALING : FRAC_16_16(1, 5),
+ DRM_PLANE_NO_SCALING,
+ meson_plane->index != 0, true);
+ if (ret || !meson_plane->index || !new_plane_state->visible)
+ return ret;
+
+ if ((new_plane_state->src.x1 | new_plane_state->src.y1 |
+ new_plane_state->src.x2 | new_plane_state->src.y2) & 0xffff)
+ return -EINVAL;
+
+ /* The canvas stride is a 12-bit field in units of eight bytes. */
+ if (fb->pitches[0] >= SZ_32K)
+ return -EINVAL;
+
+ gem = drm_fb_dma_get_gem_obj(fb, 0);
+ if (!IS_ALIGNED(gem->dma_addr + fb->offsets[0], 8) ||
+ !IS_ALIGNED(fb->pitches[0], 8))
+ return -EINVAL;
+
+ return 0;
}
#define MESON_MOD_AFBC_VALID_BITS (AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 | \
@@ -257,6 +279,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
unsigned long flags;
unsigned int index = meson_plane->index;
struct meson_osd_state *osd = &priv->viu.osd[index];
+ bool afbcd = false;
/*
* Update Coordinates
@@ -266,18 +289,27 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
*/
spin_lock_irqsave(&priv->drm->event_lock, flags);
- /* Check if AFBC decoder is required for this buffer */
- if ((meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
- meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) &&
- fb->modifier & DRM_FORMAT_MOD_ARM_AFBC(MESON_MOD_AFBC_VALID_BITS))
- priv->viu.osd1_afbcd = true;
- else
- priv->viu.osd1_afbcd = false;
+ if (index && !new_state->visible) {
+ osd->enabled = false;
+ spin_unlock_irqrestore(&priv->drm->event_lock, flags);
+ return;
+ }
+
+ if (index) {
+ dest = new_state->dst;
+ } else {
+ /* Only OSD1 has an AFBC decoder in this pipeline. */
+ if ((meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
+ meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) &&
+ fb->modifier & DRM_FORMAT_MOD_ARM_AFBC(MESON_MOD_AFBC_VALID_BITS))
+ afbcd = true;
+ priv->viu.osd1_afbcd = afbcd;
+ }
- /* Enable OSD and BLK0, set max global alpha */
- osd->ctrl_stat = OSD_ENABLE |
- (0x100 << OSD_GLOBAL_ALPHA_SHIFT) |
- OSD_BLK0_ENABLE;
+ /* Enable OSD and BLK0. */
+ osd->ctrl_stat = OSD_ENABLE | OSD_BLK0_ENABLE |
+ ((index ? DIV_ROUND_CLOSEST(new_state->alpha * 256, 0xffff) :
+ 0x100) << OSD_GLOBAL_ALPHA_SHIFT);
osd->ctrl_stat2 = readl(priv->io_base +
_REG(index ? VIU_OSD2_CTRL_STAT2 : VIU_OSD1_CTRL_STAT2));
@@ -285,7 +317,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
/* Set up BLK0 to point to the right canvas */
osd->blk0_cfg[0] = priv->canvas_id_osd[index] << OSD_CANVAS_SEL;
- if (priv->viu.osd1_afbcd) {
+ if (afbcd) {
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
/* This is the internal decoding memory address */
priv->viu.osd1_blk1_cfg4 = MESON_G12A_AFBCD_OUT_ADDR;
@@ -309,7 +341,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXBB))
osd->blk0_cfg[0] |= OSD_OUTPUT_COLOR_RGB;
- if (priv->viu.osd1_afbcd &&
+ if (afbcd &&
meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
osd->blk0_cfg[0] |= OSD_MALI_SRC_EN |
priv->afbcd.ops->fmt_to_blk_mode(fb->modifier,
@@ -345,7 +377,14 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
/* Use the pixel's alpha */
osd->ctrl_stat2 &= ~OSD_REPLACE_EN;
- meson_plane_setup_scaler(priv, new_state, &dest);
+ if (index) {
+ /* The RGB-to-YUV CSC requires straight RGB components. */
+ osd->alpha_div = fb->format->has_alpha &&
+ new_state->pixel_blend_mode == DRM_MODE_BLEND_PREMULTI;
+ }
+
+ if (!index)
+ meson_plane_setup_scaler(priv, new_state, &dest);
/*
* The format of these registers is (x2 << 16 | x1),
@@ -365,8 +404,12 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
int dst_w = new_state->crtc_w;
int dst_h = new_state->crtc_h;
- if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE)
+ if (index) {
+ dst_w = drm_rect_width(&dest);
+ dst_h = drm_rect_height(&dest);
+ } else if (new_state->crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) {
dst_h /= 2;
+ }
osd->blend_size = dst_h << 16 | dst_w;
}
@@ -379,7 +422,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
osd->height = fb->height;
osd->width = fb->width;
- if (priv->viu.osd1_afbcd) {
+ if (afbcd) {
priv->afbcd.modifier = fb->modifier;
priv->afbcd.format = fb->format->format;
@@ -389,7 +432,7 @@ static void meson_plane_atomic_update(struct drm_plane *plane,
meson_g12a_afbcd_line_stride(priv);
}
- if (!meson_plane->enabled) {
+ if (!index && !meson_plane->enabled) {
/* Reset OSD1 before enabling it on GXL+ SoCs */
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) ||
meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXL))
@@ -415,6 +458,9 @@ static void meson_plane_atomic_disable(struct drm_plane *plane,
priv->viu.osd[meson_plane->index].enabled = false;
spin_unlock_irqrestore(&priv->drm->event_lock, flags);
+ if (meson_plane->index)
+ return;
+
if (priv->afbcd.ops) {
priv->afbcd.ops->reset(priv);
priv->afbcd.ops->disable(priv);
@@ -448,6 +494,9 @@ static bool meson_plane_format_mod_supported(struct drm_plane *plane,
if (modifier == DRM_FORMAT_MOD_LINEAR)
return true;
+ if (meson_plane->index)
+ return false;
+
if (!meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM) &&
!meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
return false;
@@ -490,6 +539,13 @@ static const uint32_t supported_drm_formats[] = {
DRM_FORMAT_RGB565,
};
+static const u32 supported_drm_formats_osd2[] = {
+ DRM_FORMAT_ARGB8888,
+ DRM_FORMAT_ABGR8888,
+ DRM_FORMAT_XRGB8888,
+ DRM_FORMAT_XBGR8888,
+};
+
static const uint64_t format_modifiers_afbc_gxm[] = {
DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 |
AFBC_FORMAT_MOD_SPARSE |
@@ -542,7 +598,7 @@ static const uint64_t format_modifiers_default[] = {
/**
* meson_plane_create - Register an RGB plane
* @priv: Meson DRM device
- * @index: Zero-based OSD index
+ * @index: OSD index, 0 for the primary plane or 1 for the G12A overlay
*
* Return: 0 on success or a negative error code.
*/
@@ -551,8 +607,9 @@ int meson_plane_create(struct meson_drm *priv, unsigned int index)
struct meson_plane *meson_plane;
struct drm_plane *plane;
const uint64_t *format_modifiers = format_modifiers_default;
+ unsigned int blend_modes = BIT(DRM_MODE_BLEND_PIXEL_NONE) |
+ BIT(DRM_MODE_BLEND_COVERAGE);
int ret;
- unsigned int blend_modes = BIT(DRM_MODE_BLEND_PIXEL_NONE) | BIT(DRM_MODE_BLEND_COVERAGE);
meson_plane = devm_kzalloc_obj(priv->drm->dev, *meson_plane);
if (!meson_plane)
@@ -562,17 +619,21 @@ int meson_plane_create(struct meson_drm *priv, unsigned int index)
meson_plane->index = index;
plane = &meson_plane->base;
- if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
- format_modifiers = format_modifiers_afbc_gxm;
- else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
- format_modifiers = format_modifiers_afbc_g12a;
+ if (!index) {
+ if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
+ format_modifiers = format_modifiers_afbc_gxm;
+ else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A))
+ format_modifiers = format_modifiers_afbc_g12a;
+ }
ret = drm_universal_plane_init(priv->drm, plane, 0xFF,
&meson_plane_funcs,
- supported_drm_formats,
- ARRAY_SIZE(supported_drm_formats),
+ index ? supported_drm_formats_osd2 : supported_drm_formats,
+ index ? ARRAY_SIZE(supported_drm_formats_osd2) :
+ ARRAY_SIZE(supported_drm_formats),
format_modifiers,
- DRM_PLANE_TYPE_PRIMARY, "meson_primary_plane");
+ index ? DRM_PLANE_TYPE_OVERLAY : DRM_PLANE_TYPE_PRIMARY,
+ index ? "meson_osd2_plane" : "meson_primary_plane");
if (ret) {
devm_kfree(priv->drm->dev, meson_plane);
return ret;
@@ -580,18 +641,30 @@ int meson_plane_create(struct meson_drm *priv, unsigned int index)
drm_plane_helper_add(plane, &meson_plane_helper_funcs);
- /* For now, OSD Primary plane is always on the front */
ret = drm_plane_create_zpos_immutable_property(plane, index + 1);
- if (ret) {
- drm_plane_cleanup(plane);
- return ret;
+ if (ret)
+ goto cleanup;
+
+ if (index) {
+ ret = drm_plane_create_alpha_property(plane);
+ if (ret)
+ goto cleanup;
+
+ blend_modes |= BIT(DRM_MODE_BLEND_PREMULTI);
}
ret = drm_plane_create_blend_mode_property(plane, blend_modes);
if (ret)
- return ret;
+ goto cleanup;
- priv->primary_plane = plane;
+ if (index)
+ priv->osd2_plane = plane;
+ else
+ priv->primary_plane = plane;
return 0;
+
+cleanup:
+ drm_plane_cleanup(plane);
+ return ret;
}
diff --git a/drivers/gpu/drm/meson/meson_registers.h b/drivers/gpu/drm/meson/meson_registers.h
index 3d73d00a1f4c..4b882d628192 100644
--- a/drivers/gpu/drm/meson/meson_registers.h
+++ b/drivers/gpu/drm/meson/meson_registers.h
@@ -238,6 +238,9 @@
#define VIU_OSD2_TEST_RDDATA 0x1a4c
#define VIU_OSD2_PROT_CTRL 0x1a4e
#define VIU_OSD2_MALI_UNPACK_CTRL 0x1abd
+#define OSD_MALI_ALPHA_DIV_EN BIT(28)
+#define OSD_MALI_ALPHA_DIV_CLK_GATE GENMASK(27, 26)
+#define OSD_MALI_ALPHA_MAPPING GENMASK(25, 24)
#define VIU_OSD2_DIMM_CTRL 0x1acf
#define VIU_OSD3_CTRL_STAT 0x3d80
@@ -1896,6 +1899,8 @@
#define VD_BLEND_POSTBLD_PREMULT_EN BIT(16)
#define OSD1_BLEND_SRC_CTRL 0x1dfd
#define OSD2_BLEND_SRC_CTRL 0x1dfe
+#define OSD_BLEND_POSTBLD_PREMULT_EN BIT(16)
+#define OSD_BLEND_POSTBLD_SRC_MASK GENMASK(11, 8)
#define OSD_BLEND_POSTBLD_SRC_VD1 (1 << 8)
#define OSD_BLEND_POSTBLD_SRC_VD2 (2 << 8)
#define OSD_BLEND_POSTBLD_SRC_OSD1 (3 << 8)
diff --git a/drivers/gpu/drm/meson/meson_viu.c b/drivers/gpu/drm/meson/meson_viu.c
index f618e6ba4731..9d10766c8bca 100644
--- a/drivers/gpu/drm/meson/meson_viu.c
+++ b/drivers/gpu/drm/meson/meson_viu.c
@@ -428,6 +428,7 @@ void meson_viu_init(struct meson_drm *priv)
meson_viu_load_matrix(priv);
else if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_G12A)) {
meson_viu_set_g12a_osd_matrix(priv, 0, RGB709_to_YUV709l_coeff);
+ meson_viu_set_g12a_osd_matrix(priv, 1, RGB709_to_YUV709l_coeff);
/* fix green/pink color distortion from vendor u-boot */
writel_bits_relaxed(OSD1_HDR2_CTRL_REG_ONLY_MAT |
OSD1_HDR2_CTRL_VDIN0_HDR2_TOP_EN, 0,
@@ -495,6 +496,19 @@ void meson_viu_init(struct meson_drm *priv)
priv->io_base + _REG(DOLBY_PATH_CTRL));
meson_viu_g12a_disable_osd1_afbc(priv);
+
+ /* OSD2 uses the canvas path without its scaler or AFBC decoder. */
+ writel_relaxed(0, priv->io_base + _REG(OSD2_SC_CTRL0));
+ writel_relaxed(0, priv->io_base + _REG(OSD2_VSC_CTRL0));
+ writel_relaxed(0, priv->io_base + _REG(OSD2_HSC_CTRL0));
+ writel_relaxed(0, priv->io_base + _REG(VIU_OSD2_DIMM_CTRL));
+ writel_bits_relaxed(OSD_PATH_OSD_AXI_SEL_OSD2_AFBCD, 0,
+ priv->io_base + _REG(OSD_PATH_MISC_CTRL));
+ writel_bits_relaxed(VIU_OSD1_MALI_UNPACK_EN |
+ OSD_MALI_ALPHA_DIV_EN |
+ OSD_MALI_ALPHA_DIV_CLK_GATE |
+ OSD_MALI_ALPHA_MAPPING, 0,
+ priv->io_base + _REG(VIU_OSD2_MALI_UNPACK_CTRL));
}
if (meson_vpu_is_compatible(priv, VPU_COMPATIBLE_GXM))
@@ -502,5 +516,7 @@ void meson_viu_init(struct meson_drm *priv)
priv->viu.osd[0].enabled = false;
priv->viu.osd[0].commit = false;
+ priv->viu.osd[1].enabled = false;
+ priv->viu.osd[1].commit = false;
priv->viu.osd1_interlace = false;
}
--
2.34.1
_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic
^ permalink raw reply related [flat|nested] 13+ messages in thread