[PATCH v3 1/8] drm/arcpgu: replace struct drm_simple_display_pipe with regular atomic helpers
Ze Huang <[email protected]> Mon, 27 Jul 2026 03:45:14 +0800
| Newsgroups | org.ozlabs.lists.linux-aspeed,dev.linux.lists.imx,org.infradead.lists.linux-arm-kernel,org.kernel.vger.linux-kernel,org.xenproject.lists.xen-devel |
|---|---|
| Message-ID | <20260727-drm-simple-kms-removal-v3-1-cd5dc89858c6@oss.qualcomm.com> |
Instantiate the primary plane, CRTC and encoder directly and wire them up with standard atomic helpers. Move the simple-pipe callbacks into explicit plane and CRTC helper callbacks. Use commit-local CRTC and plane state in the CRTC enable path for mode and pixel-format programming. Handle missing remote encoder nodes explicitly and take the CRTC modeset lock while reading CRTC state from debugfs. Signed-off-by: Ze Huang <[email protected]> --- Changes in v3: - Use commit-local CRTC and plane state in the CRTC enable path. - Handle missing remote encoder nodes explicitly. - Lock CRTC state access in debugfs. --- drivers/gpu/drm/tiny/arcpgu.c | 201 ++++++++++++++++++++++++++++++++---------- 1 file changed, 152 insertions(+), 49 deletions(-) diff --git a/drivers/gpu/drm/tiny/arcpgu.c b/drivers/gpu/drm/tiny/arcpgu.c index c93d61ac0bb7..19a943f5f792 100644 --- a/drivers/gpu/drm/tiny/arcpgu.c +++ b/drivers/gpu/drm/tiny/arcpgu.c @@ -8,6 +8,7 @@ #include <linux/clk.h> #include <drm/clients/drm_client_setup.h> +#include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> #include <drm/drm_debugfs.h> #include <drm/drm_device.h> @@ -17,12 +18,13 @@ #include <drm/drm_fbdev_dma.h> #include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> +#include <drm/drm_gem_atomic_helper.h> #include <drm/drm_gem_dma_helper.h> #include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_module.h> #include <drm/drm_of.h> +#include <drm/drm_plane.h> #include <drm/drm_probe_helper.h> -#include <drm/drm_simple_kms_helper.h> #include <linux/dma-mapping.h> #include <linux/module.h> #include <linux/of_reserved_mem.h> @@ -52,13 +54,16 @@ struct arcpgu_drm_private { struct drm_device drm; void __iomem *regs; struct clk *clk; - struct drm_simple_display_pipe pipe; + struct drm_plane plane; + struct drm_crtc crtc; + struct drm_encoder encoder; struct drm_connector sim_conn; }; -#define dev_to_arcpgu(x) container_of(x, struct arcpgu_drm_private, drm) - -#define pipe_to_arcpgu_priv(x) container_of(x, struct arcpgu_drm_private, pipe) +static inline struct arcpgu_drm_private *dev_to_arcpgu(struct drm_device *drm) +{ + return container_of(drm, struct arcpgu_drm_private, drm); +} static inline void arc_pgu_write(struct arcpgu_drm_private *arcpgu, unsigned int reg, u32 value) @@ -115,9 +120,10 @@ static const u32 arc_pgu_supported_formats[] = { DRM_FORMAT_ARGB8888, }; -static void arc_pgu_set_pxl_fmt(struct arcpgu_drm_private *arcpgu) +static void arc_pgu_set_pxl_fmt(struct arcpgu_drm_private *arcpgu, + const struct drm_plane_state *plane_state) { - const struct drm_framebuffer *fb = arcpgu->pipe.plane.state->fb; + const struct drm_framebuffer *fb = plane_state->fb; uint32_t pixel_format = fb->format->format; u32 format = DRM_FORMAT_INVALID; int i; @@ -139,10 +145,10 @@ static void arc_pgu_set_pxl_fmt(struct arcpgu_drm_private *arcpgu) arc_pgu_write(arcpgu, ARCPGU_REG_CTRL, reg_ctrl); } -static enum drm_mode_status arc_pgu_mode_valid(struct drm_simple_display_pipe *pipe, - const struct drm_display_mode *mode) +static enum drm_mode_status arcpgu_crtc_helper_mode_valid(struct drm_crtc *crtc, + const struct drm_display_mode *mode) { - struct arcpgu_drm_private *arcpgu = pipe_to_arcpgu_priv(pipe); + struct arcpgu_drm_private *arcpgu = dev_to_arcpgu(crtc->dev); long rate, clk_rate = mode->clock * 1000; long diff = clk_rate / 200; /* +-0.5% allowed by HDMI spec */ @@ -153,9 +159,11 @@ static enum drm_mode_status arc_pgu_mode_valid(struct drm_simple_display_pipe *p return MODE_NOCLOCK; } -static void arc_pgu_mode_set(struct arcpgu_drm_private *arcpgu) +static void arc_pgu_mode_set(struct arcpgu_drm_private *arcpgu, + struct drm_crtc_state *crtc_state, + struct drm_plane_state *plane_state) { - struct drm_display_mode *m = &arcpgu->pipe.crtc.state->adjusted_mode; + struct drm_display_mode *m = &crtc_state->adjusted_mode; u32 val; arc_pgu_write(arcpgu, ARCPGU_REG_FMT, @@ -189,18 +197,19 @@ static void arc_pgu_mode_set(struct arcpgu_drm_private *arcpgu) arc_pgu_write(arcpgu, ARCPGU_REG_STRIDE, 0); arc_pgu_write(arcpgu, ARCPGU_REG_START_SET, 1); - arc_pgu_set_pxl_fmt(arcpgu); + arc_pgu_set_pxl_fmt(arcpgu, plane_state); clk_set_rate(arcpgu->clk, m->crtc_clock * 1000); } -static void arc_pgu_enable(struct drm_simple_display_pipe *pipe, - struct drm_crtc_state *crtc_state, - struct drm_plane_state *plane_state) +static void arcpgu_crtc_helper_atomic_enable(struct drm_crtc *crtc, + struct drm_atomic_commit *commit) { - struct arcpgu_drm_private *arcpgu = pipe_to_arcpgu_priv(pipe); + struct arcpgu_drm_private *arcpgu = dev_to_arcpgu(crtc->dev); + struct drm_plane_state *pstate = drm_atomic_get_new_plane_state(commit, &arcpgu->plane); + struct drm_crtc_state *cstate = drm_atomic_get_new_crtc_state(commit, crtc); - arc_pgu_mode_set(arcpgu); + arc_pgu_mode_set(arcpgu, cstate, pstate); clk_prepare_enable(arcpgu->clk); arc_pgu_write(arcpgu, ARCPGU_REG_CTRL, @@ -208,9 +217,10 @@ static void arc_pgu_enable(struct drm_simple_display_pipe *pipe, ARCPGU_CTRL_ENABLE_MASK); } -static void arc_pgu_disable(struct drm_simple_display_pipe *pipe) +static void arcpgu_crtc_helper_atomic_disable(struct drm_crtc *crtc, + struct drm_atomic_commit *commit) { - struct arcpgu_drm_private *arcpgu = pipe_to_arcpgu_priv(pipe); + struct arcpgu_drm_private *arcpgu = dev_to_arcpgu(crtc->dev); clk_disable_unprepare(arcpgu->clk); arc_pgu_write(arcpgu, ARCPGU_REG_CTRL, @@ -218,27 +228,21 @@ static void arc_pgu_disable(struct drm_simple_display_pipe *pipe) ~ARCPGU_CTRL_ENABLE_MASK); } -static void arc_pgu_update(struct drm_simple_display_pipe *pipe, - struct drm_plane_state *state) +static void arcpgu_plane_helper_atomic_update(struct drm_plane *plane, + struct drm_atomic_commit *commit) { + struct drm_plane_state *pstate = drm_atomic_get_new_plane_state(commit, plane); struct arcpgu_drm_private *arcpgu; struct drm_gem_dma_object *gem; - if (!pipe->plane.state->fb) + if (!pstate->fb) return; - arcpgu = pipe_to_arcpgu_priv(pipe); - gem = drm_fb_dma_get_gem_obj(pipe->plane.state->fb, 0); + arcpgu = dev_to_arcpgu(plane->dev); + gem = drm_fb_dma_get_gem_obj(pstate->fb, 0); arc_pgu_write(arcpgu, ARCPGU_REG_BUF0_ADDR, gem->dma_addr); } -static const struct drm_simple_display_pipe_funcs arc_pgu_pipe_funcs = { - .update = arc_pgu_update, - .mode_valid = arc_pgu_mode_valid, - .enable = arc_pgu_enable, - .disable = arc_pgu_disable, -}; - static const struct drm_mode_config_funcs arcpgu_drm_modecfg_funcs = { .fb_create = drm_gem_fb_create, .atomic_check = drm_atomic_helper_check, @@ -247,6 +251,74 @@ static const struct drm_mode_config_funcs arcpgu_drm_modecfg_funcs = { DEFINE_DRM_GEM_DMA_FOPS(arcpgu_drm_ops); +static int arcpgu_plane_helper_atomic_check(struct drm_plane *plane, + struct drm_atomic_commit *commit) +{ + struct drm_plane_state *plane_state = drm_atomic_get_new_plane_state(commit, plane); + struct drm_crtc_state *crtc_state = NULL; + + if (plane_state->crtc) { + crtc_state = drm_atomic_get_crtc_state(commit, plane_state->crtc); + if (IS_ERR(crtc_state)) + return PTR_ERR(crtc_state); + } + + return drm_atomic_helper_check_plane_state(plane_state, crtc_state, + DRM_PLANE_NO_SCALING, + DRM_PLANE_NO_SCALING, + false, false); +} + +static const struct drm_plane_helper_funcs arcpgu_plane_helper_funcs = { + .prepare_fb = drm_gem_plane_helper_prepare_fb, + .atomic_check = arcpgu_plane_helper_atomic_check, + .atomic_update = arcpgu_plane_helper_atomic_update, +}; + +static const struct drm_plane_funcs arcpgu_plane_funcs = { + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .destroy = drm_plane_cleanup, + .reset = drm_atomic_helper_plane_reset, + .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, +}; + +static int arcpgu_crtc_helper_atomic_check(struct drm_crtc *crtc, + struct drm_atomic_commit *commit) +{ + struct drm_crtc_state *crtc_state = drm_atomic_get_new_crtc_state(commit, crtc); + int ret; + + if (crtc_state->enable) { + ret = drm_atomic_helper_check_crtc_primary_plane(crtc_state); + if (ret) + return ret; + } + + return drm_atomic_add_affected_planes(commit, crtc); +} + +static const struct drm_crtc_helper_funcs arcpgu_crtc_helper_funcs = { + .mode_valid = arcpgu_crtc_helper_mode_valid, + .atomic_check = arcpgu_crtc_helper_atomic_check, + .atomic_enable = arcpgu_crtc_helper_atomic_enable, + .atomic_disable = arcpgu_crtc_helper_atomic_disable, +}; + +static const struct drm_crtc_funcs arcpgu_crtc_funcs = { + .reset = drm_atomic_helper_crtc_reset, + .destroy = drm_crtc_cleanup, + .set_config = drm_atomic_helper_set_config, + .page_flip = drm_atomic_helper_page_flip, + .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, +}; + +static const struct drm_encoder_funcs arcpgu_encoder_funcs = { + .destroy = drm_encoder_cleanup, +}; + static int arcpgu_load(struct arcpgu_drm_private *arcpgu) { struct platform_device *pdev = to_platform_device(arcpgu->drm.dev); @@ -254,6 +326,9 @@ static int arcpgu_load(struct arcpgu_drm_private *arcpgu) struct device_node *endpoint_node = NULL; struct drm_connector *connector = NULL; struct drm_device *drm = &arcpgu->drm; + struct drm_plane *plane; + struct drm_encoder *encoder; + struct drm_crtc *crtc; int ret; arcpgu->clk = devm_clk_get(drm->dev, "pxlclk"); @@ -285,6 +360,30 @@ static int arcpgu_load(struct arcpgu_drm_private *arcpgu) if (dma_set_mask_and_coherent(drm->dev, DMA_BIT_MASK(32))) return -ENODEV; + plane = &arcpgu->plane; + ret = drm_universal_plane_init(drm, plane, 0, + &arcpgu_plane_funcs, + arc_pgu_supported_formats, + ARRAY_SIZE(arc_pgu_supported_formats), + NULL, + DRM_PLANE_TYPE_PRIMARY, NULL); + if (ret) + return ret; + drm_plane_helper_add(plane, &arcpgu_plane_helper_funcs); + + crtc = &arcpgu->crtc; + ret = drm_crtc_init_with_planes(drm, crtc, plane, NULL, + &arcpgu_crtc_funcs, NULL); + if (ret) + return ret; + drm_crtc_helper_add(crtc, &arcpgu_crtc_helper_funcs); + + encoder = &arcpgu->encoder; + ret = drm_encoder_init(drm, encoder, &arcpgu_encoder_funcs, DRM_MODE_ENCODER_NONE, NULL); + if (ret) + return ret; + encoder->possible_crtcs = drm_crtc_mask(crtc); + /* * There is only one output port inside each device. It is linked with * encoder endpoint. @@ -293,29 +392,26 @@ static int arcpgu_load(struct arcpgu_drm_private *arcpgu) if (endpoint_node) { encoder_node = of_graph_get_remote_port_parent(endpoint_node); of_node_put(endpoint_node); - } else { - connector = &arcpgu->sim_conn; - dev_info(drm->dev, "no encoder found. Assumed virtual LCD on simulation platform\n"); - ret = arcpgu_drm_sim_init(drm, connector); - if (ret < 0) - return ret; - } + if (!encoder_node) + return -ENODEV; - ret = drm_simple_display_pipe_init(drm, &arcpgu->pipe, &arc_pgu_pipe_funcs, - arc_pgu_supported_formats, - ARRAY_SIZE(arc_pgu_supported_formats), - NULL, connector); - if (ret) - return ret; - - if (encoder_node) { /* Locate drm bridge from the hdmi encoder DT node */ struct drm_bridge *bridge __free(drm_bridge_put) = of_drm_find_and_get_bridge(encoder_node); if (!bridge) return -EPROBE_DEFER; - ret = drm_simple_display_pipe_attach_bridge(&arcpgu->pipe, bridge); + ret = drm_bridge_attach(encoder, bridge, NULL, 0); + if (ret) + return ret; + } else { + connector = &arcpgu->sim_conn; + dev_info(drm->dev, "no encoder found. Assumed virtual LCD on simulation platform\n"); + ret = arcpgu_drm_sim_init(drm, connector); + if (ret < 0) + return ret; + + ret = drm_connector_attach_encoder(connector, encoder); if (ret) return ret; } @@ -342,7 +438,14 @@ static int arcpgu_show_pxlclock(struct seq_file *m, void *arg) struct drm_device *drm = node->minor->dev; struct arcpgu_drm_private *arcpgu = dev_to_arcpgu(drm); unsigned long clkrate = clk_get_rate(arcpgu->clk); - unsigned long mode_clock = arcpgu->pipe.crtc.mode.crtc_clock * 1000; + unsigned long mode_clock; + int ret; + + ret = drm_modeset_lock_single_interruptible(&arcpgu->crtc.mutex); + if (ret) + return ret; + mode_clock = arcpgu->crtc.state->mode.crtc_clock * 1000; + drm_modeset_unlock(&arcpgu->crtc.mutex); seq_printf(m, "hw : %lu\n", clkrate); seq_printf(m, "mode: %lu\n", mode_clock); -- 2.43.0