drm/mediatek: fix cursor issue and apply CMDQ in MTK DRM
Subsystems (3)
v2 cover drm/mediatek: fix cursor issue and apply CMDQ in MTK DRM
The CMDQ (Command Queue) in MT8183 is used to help update all relevant display controller registers with critical time limation. This patch add cmdq interface in ddp_comp interface, let all ddp_comp interface can support cpu/cmdq function at the same time.
These patches also can fixup cursor moving is not smooth when heavy load in webgl.
This patch depends on ptach:
add drm support for MT8183
(https://patchwork.kernel.org/cover/11121519/)
support gce on mt8183 platform
(https://patchwork.kernel.org/cover/11255147)
drm/mediatek: Refactor plane init/check and support rotation
(https://pw-emeril.freedesktop.org/series/69015/)
drm/mediatek: Check return value of mtk_drm_ddp_comp_for_plane
(https://lore.kernel.org/patchwork/patch/1154517/)
Changes since v1:
- remove redundant code
- merge the duplicate code
- use async instead of cursor
Changes since v0:
- remove redundant code
- remove patch
"drm/mediatek: fix atomic_state reference counting" After remove this patch, the issue we met before is gone. So I do not add any extra code to do something.
Bibby Hsieh (6):
drm/mediatek: use DRM core's atomic commit helper drm/mediatek: handle events when enabling/disabling crtc drm/mediatek: update cursors by using async atomic update drm/mediatek: remove unused external function drm/mediatek: support CMDQ interface in ddp component drm/mediatek: apply CMDQ control flow
drivers/gpu/drm/mediatek/mtk_disp_color.c | 7 +- drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 67 ++++---- drivers/gpu/drm/mediatek/mtk_disp_rdma.c | 43 ++--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 168 ++++++++++++++++---- drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 2 + drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 136 ++++++++++++---- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 47 +++--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 86 +--------- drivers/gpu/drm/mediatek/mtk_drm_drv.h | 7 - drivers/gpu/drm/mediatek/mtk_drm_plane.c | 50 ++++++ drivers/gpu/drm/mediatek/mtk_drm_plane.h | 2 + 11 files changed, 393 insertions(+), 222 deletions(-)
Signature · 1 line
2.18.0
PATCH v2 1/6 drm/mediatek: use DRM core's atomic commit helper
The DRM core atomic helper now supports asynchronous commits natively. The custom drm implementation isn't needed anymore, remove it.
--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 86 ++------------------------ drivers/gpu/drm/mediatek/mtk_drm_drv.h | 7 --- 2 files changed, 5 insertions(+), 88 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_drv.c +5 -81
@@ -36,89 +36,14 @@#define DRIVER_MAJOR 1#define DRIVER_MINOR 0 -static void mtk_atomic_schedule (struct mtk_drm_private *private, -struct drm_atomic_state *state) -{ - private->commit.state = state; -schedule_work (&private->commit.work); -} - -static void mtk_atomic_complete (struct mtk_drm_private *private, -struct drm_atomic_state *state) -{ -struct drm_device *drm = private->drm; - -drm_atomic_helper_wait_for_fences (drm, state, false); - -/* -* Mediatek drm supports runtime PM, so plane registers cannot be -* written when their crtc is disabled. -* -* The comment for drm_atomic_helper_commit states: -* For drivers supporting runtime PM the recommended sequence is -* -* drm_atomic_helper_commit_modeset_disables(dev, state); -* drm_atomic_helper_commit_modeset_enables(dev, state); -* drm_atomic_helper_commit_planes(dev, state, -* DRM_PLANE_COMMIT_ACTIVE_ONLY); -* -* See the kerneldoc entries for these three functions for more details. -*/ -drm_atomic_helper_commit_modeset_disables (drm, state); -drm_atomic_helper_commit_modeset_enables (drm, state); -drm_atomic_helper_commit_planes (drm, state, -DRM_PLANE_COMMIT_ACTIVE_ONLY ); - -drm_atomic_helper_wait_for_vblanks (drm, state); - -drm_atomic_helper_cleanup_planes (drm, state); -drm_atomic_state_put (state); -} - -static void mtk_atomic_work (struct work_struct *work) -{ -struct mtk_drm_private *private =container_of (work, - struct mtk_drm_private, commit.work); - -mtk_atomic_complete (private, private->commit.state); -} - -static int mtk_atomic_commit (struct drm_device *drm, -struct drm_atomic_state *state, -bool async) -{ -struct mtk_drm_private *private = drm->dev_private; -int ret; - - ret =drm_atomic_helper_prepare_planes (drm, state); -if (ret) -return ret; - -mutex_lock (&private->commit.lock); -flush_work (&private->commit.work); - - ret =drm_atomic_helper_swap_state (state, true); -if (ret) { -mutex_unlock (&private->commit.lock); -drm_atomic_helper_cleanup_planes (drm, state); -return ret; - } - -drm_atomic_state_get (state); -if (async) -mtk_atomic_schedule (private, state); -else -mtk_atomic_complete (private, state); - -mutex_unlock (&private->commit.lock); - -return 0 ; -} +static const struct drm_mode_config_helper_funcs mtk_drm_mode_config_helpers = { + .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, +};static const struct drm_mode_config_funcs mtk_drm_mode_config_funcs = { .fb_create = mtk_drm_mode_fb_create, .atomic_check = drm_atomic_helper_check, - .atomic_commit = mtk_atomic_commit, + .atomic_commit = drm_atomic_helper_commit, };static const enum mtk_ddp_comp_id mt2701_mtk_ddp_main[] = {
@@ -265,6 +190,7 @@ static int mtk_drm_kms_init(struct drm_device *drm) drm->mode_config.max_width =4096 ; drm->mode_config.max_height =4096 ; drm->mode_config.funcs = &mtk_drm_mode_config_funcs; + drm->mode_config.helper_private = &mtk_drm_mode_config_helpers; ret =component_bind_all (drm->dev, drm);if (ret)
@@ -540,8 +466,6 @@ static int mtk_drm_probe(struct platform_device *pdev)if (!private)return -ENOMEM ; -mutex_init (&private->commit.lock); -INIT_WORK (&private->commit.work, mtk_atomic_work); private->data =of_device_get_match_data (dev); mem =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
drivers/gpu/drm/mediatek/mtk_drm_drv.h +0 -7
@@ -46,13 +46,6 @@ struct mtk_drm_private {struct device_node *comp_node[DDP_COMPONENT_ID_MAX ];struct mtk_ddp_comp *ddp_comp[DDP_COMPONENT_ID_MAX ];const struct mtk_mmsys_driver_data *data; - -struct { -struct drm_atomic_state *state; -struct work_struct work; -struct mutex lock; - } commit; -struct drm_atomic_state *suspend_state;bool dma_parms_allocated;
Signature · 5 lines
2.18.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 2/6 drm/mediatek: handle events when enabling/disabling crtc
In reply to Bibby HsiehThe driver currently handles vblank events only when updating planes on an already enabled CRTC. The atomic update API however allows requesting an event when enabling or disabling a CRTC. This currently leads to event objects being leaked in the kernel and to events not being sent out. Fix it.
--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +8 -0
@@ -334,6 +334,7 @@ static int mtk_crtc_ddp_hw_init(struct mtk_drm_crtc *mtk_crtc)static void mtk_crtc_ddp_hw_fini (struct mtk_drm_crtc *mtk_crtc) {struct drm_device *drm = mtk_crtc->base.dev; +struct drm_crtc *crtc = &mtk_crtc->base;int i;DRM_DEBUG_DRIVER ("%s\n" , __func__);
@@ -357,6 +358,13 @@ static void mtk_crtc_ddp_hw_fini(struct mtk_drm_crtc *mtk_crtc)mtk_disp_mutex_unprepare (mtk_crtc->mutex);pm_runtime_put (drm->dev); + +if (crtc->state->event && !crtc->state->active) { +spin_lock_irq (&crtc->dev->event_lock); +drm_crtc_send_vblank_event (crtc, crtc->state->event); + crtc->state->event =NULL ; +spin_unlock_irq (&crtc->dev->event_lock); + } }static void mtk_crtc_ddp_config (struct drm_crtc *crtc)
Signature · 5 lines
2.18.0 _______________________________________________ dri-devel mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 3/6 drm/mediatek: update cursors by using async atomic update
In reply to Bibby HsiehSupport to async updates of cursors by using the new atomic interface for that.
--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 33 ++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 2 + drivers/gpu/drm/mediatek/mtk_drm_plane.c | 50 ++++++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_plane.h | 2 + 4 files changed, 87 insertions(+)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +33 -0
@@ -422,6 +422,39 @@ int mtk_drm_crtc_plane_check(struct drm_crtc *crtc, struct drm_plane *plane,return 0 ; } +void mtk_drm_crtc_async_update (struct drm_crtc *crtc,struct drm_plane *plane, +struct drm_plane_state *new_state) +{ +struct mtk_drm_private *priv = crtc->dev->dev_private; +struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc); +const struct drm_plane_helper_funcs *plane_helper_funcs = + plane->helper_private; +int i; + +if (!mtk_crtc->enabled) +return ; + + plane_helper_funcs->atomic_update (plane, new_state); + +for (i =0 ; i < mtk_crtc->layer_nr; i++) { +struct drm_plane *plane = &mtk_crtc->planes[i]; +struct mtk_plane_state *plane_state; + + plane_state =to_mtk_plane_state (plane->state); +if (plane_state->pending.async_dirty) { + plane_state->pending.config = true; + plane_state->pending.async_update = false; + plane_state->pending.async_dirty = false; + } + } + mtk_crtc->pending_planes = true; +if (priv->data->shadow_register) { +mtk_disp_mutex_acquire (mtk_crtc->mutex); +mtk_crtc_ddp_config (crtc); +mtk_disp_mutex_release (mtk_crtc->mutex); + } +} +static void mtk_drm_crtc_atomic_enable (struct drm_crtc *crtc,struct drm_crtc_state *old_state) {
drivers/gpu/drm/mediatek/mtk_drm_crtc.h +2 -0
@@ -21,5 +21,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev, unsigned int path_len);int mtk_drm_crtc_plane_check (struct drm_crtc *crtc,struct drm_plane *plane,struct mtk_plane_state *state); +void mtk_drm_crtc_async_update (struct drm_crtc *crtc,struct drm_plane *plane, +struct drm_plane_state *plane_state);#endif /* MTK_DRM_CRTC_H */
drivers/gpu/drm/mediatek/mtk_drm_plane.c +50 -0
74 lines not on this page · raw message
drivers/gpu/drm/mediatek/mtk_drm_plane.h +2 -0
@@ -22,6 +22,8 @@ struct mtk_plane_pending_state {unsigned int height;unsigned int rotation;bool dirty; +bool async_dirty; +bool async_update; };struct mtk_plane_state {
Signature · 1 line
2.18.0
Re: [PATCH v2 3/6] drm/mediatek: update cursors by using async atomic update
Hi, Bibby:
You move the mutex protection to [PATCH v2 6/6] drm/mediatek: apply CMDQ control flow, but the race condition exist in this patch. So you should move that back in this patch.
Regards,
CK
Quoted 154 lines · Bibby Hsieh
Support to async updates of cursors by using the new atomic interface for that.
Signed-off-by Bibby Hsieh <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 33 ++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 2 + drivers/gpu/drm/mediatek/mtk_drm_plane.c | 50 ++++++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_plane.h | 2 + 4 files changed, 87 insertions(+)drivers/gpu/drm/mediatek/mtk_drm_crtc.c +33
-0@@ -422,6 +422,39 @@ int mtk_drm_crtc_plane_check(struct drm_crtc *crtc, struct drm_plane *plane,return 0 ; } +void mtk_drm_crtc_async_update (struct drm_crtc *crtc,struct drm_plane *plane, +struct drm_plane_state *new_state) +{ +struct mtk_drm_private *priv = crtc->dev->dev_private; +struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc); +const struct drm_plane_helper_funcs *plane_helper_funcs = + plane->helper_private; +int i; + +if (!mtk_crtc->enabled) +return ; + + plane_helper_funcs->atomic_update (plane, new_state); + +for (i =0 ; i < mtk_crtc->layer_nr; i++) { +struct drm_plane *plane = &mtk_crtc->planes[i]; +struct mtk_plane_state *plane_state; + + plane_state =to_mtk_plane_state (plane->state); +if (plane_state->pending.async_dirty) { + plane_state->pending.config = true; + plane_state->pending.async_update = false; + plane_state->pending.async_dirty = false; + } + } + mtk_crtc->pending_planes = true; +if (priv->data->shadow_register) { +mtk_disp_mutex_acquire (mtk_crtc->mutex); +mtk_crtc_ddp_config (crtc); +mtk_disp_mutex_release (mtk_crtc->mutex); + } +} +static void mtk_drm_crtc_atomic_enable (struct drm_crtc *crtc,struct drm_crtc_state *old_state) {drivers/gpu/drm/mediatek/mtk_drm_crtc.h +2
-0@@ -21,5 +21,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev, unsigned int path_len);int mtk_drm_crtc_plane_check (struct drm_crtc *crtc,struct drm_plane *plane,struct mtk_plane_state *state); +void mtk_drm_crtc_async_update (struct drm_crtc *crtc,struct drm_plane *plane, +struct drm_plane_state *plane_state);#endif /* MTK_DRM_CRTC_H */ drivers/gpu/drm/mediatek/mtk_drm_plane.c +50
-0@@ -7,6 +7,7 @@#include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> #include <drm/drm_fourcc.h> +#include <drm/drm_atomic_uapi.h> #include <drm/drm_plane_helper.h> #include <drm/drm_gem_framebuffer_helper.h> @@ -70,6 +71,50 @@ static void mtk_drm_plane_destroy_state(struct drm_plane *plane,kfree (to_mtk_plane_state (state)); } +static int mtk_plane_atomic_async_check (struct drm_plane *plane, +struct drm_plane_state *state) +{ +struct drm_crtc_state *crtc_state; + +if (plane != state->crtc->cursor) +return -EINVAL ; + +if (!plane->state) +return -EINVAL ; + +if (!plane->state->fb) +return -EINVAL ; + +if (state->state) + crtc_state =drm_atomic_get_existing_crtc_state (state->state, + state->crtc); +else /* Special case for asynchronous cursor updates. */ + crtc_state = state->crtc->state; + +return drm_atomic_helper_check_plane_state (plane->state, crtc_state, +DRM_PLANE_HELPER_NO_SCALING , +DRM_PLANE_HELPER_NO_SCALING , + true, true); +} + +static void mtk_plane_atomic_async_update (struct drm_plane *plane, +struct drm_plane_state *new_state) +{ +struct mtk_plane_state *state =to_mtk_plane_state (plane->state); + + plane->state->crtc_x = new_state->crtc_x; + plane->state->crtc_y = new_state->crtc_y; + plane->state->crtc_h = new_state->crtc_h; + plane->state->crtc_w = new_state->crtc_w; + plane->state->src_x = new_state->src_x; + plane->state->src_y = new_state->src_y; + plane->state->src_h = new_state->src_h; + plane->state->src_w = new_state->src_w; + state->pending.async_update = true; + +mtk_drm_crtc_async_update (new_state->crtc, plane, new_state); +} +static const struct drm_plane_funcs mtk_plane_funcs = { .update_plane = drm_atomic_helper_update_plane, .disable_plane = drm_atomic_helper_disable_plane,@@ -141,6 +186,9 @@ static void mtk_plane_atomic_update(struct drm_plane *plane, state->pending.rotation = plane->state->rotation;wmb ();/* Make sure the above parameters are set before update */ state->pending.dirty = true; + +if (state->pending.async_update) + state->pending.async_dirty = true; } static void mtk_plane_atomic_disable(struct drm_plane *plane,@@ -158,6 +206,8 @@ static const struct drm_plane_helper_funcs mtk_plane_helper_funcs = { .atomic_check = mtk_plane_atomic_check, .atomic_update = mtk_plane_atomic_update, .atomic_disable = mtk_plane_atomic_disable, + .atomic_async_update = mtk_plane_atomic_async_update, + .atomic_async_check = mtk_plane_atomic_async_check, }; int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane,drivers/gpu/drm/mediatek/mtk_drm_plane.h +0
-0
drivers/gpu/drm/mediatek/mtk_drm_plane.h struct mtk_plane_pending_state { · line 29
Quoted 8 lines
drivers/gpu/drm/mediatek/mtk_drm_plane.h +2
-0@@ -22,6 +22,8 @@ struct mtk_plane_pending_state {unsigned int height;unsigned int rotation;bool dirty; +bool async_dirty; +bool async_update; };struct mtk_plane_state {
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
PATCH v2 4/6 drm/mediatek: remove unused external function
In reply to Bibby Hsiehlayer_on and layer_off both are unused external function, remove them from mtk_ddp_comp_funcs structure.
--- drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 2 -- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 16 ---------------- 2 files changed, 18 deletions(-)
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +0 -2
@@ -314,8 +314,6 @@ static const struct mtk_ddp_comp_funcs mtk_disp_ovl_funcs = { .disable_vblank = mtk_ovl_disable_vblank, .supported_rotations = mtk_ovl_supported_rotations, .layer_nr = mtk_ovl_layer_nr, - .layer_on = mtk_ovl_layer_on, - .layer_off = mtk_ovl_layer_off, .layer_check = mtk_ovl_layer_check, .layer_config = mtk_ovl_layer_config, .bgclr_in_on = mtk_ovl_bgclr_in_on,
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +0 -16
@@ -79,8 +79,6 @@ struct mtk_ddp_comp_funcs {void (*disable_vblank)(struct mtk_ddp_comp *comp);unsigned int (*supported_rotations)(struct mtk_ddp_comp *comp);unsigned int (*layer_nr)(struct mtk_ddp_comp *comp); -void (*layer_on)(struct mtk_ddp_comp *comp,unsigned int idx); -void (*layer_off)(struct mtk_ddp_comp *comp,unsigned int idx);int (*layer_check)(struct mtk_ddp_comp *comp,unsigned int idx,struct mtk_plane_state *state);
@@ -151,20 +149,6 @@ static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)return 0 ; } -static inline void mtk_ddp_comp_layer_on (struct mtk_ddp_comp *comp, -unsigned int idx) -{ -if (comp->funcs && comp->funcs->layer_on) - comp->funcs->layer_on (comp, idx); -} - -static inline void mtk_ddp_comp_layer_off (struct mtk_ddp_comp *comp, -unsigned int idx) -{ -if (comp->funcs && comp->funcs->layer_off) - comp->funcs->layer_off (comp, idx); -} -static inline int mtk_ddp_comp_layer_check (struct mtk_ddp_comp *comp,unsigned int idx,struct mtk_plane_state *state)
Signature · 1 line
2.18.0
Re: [PATCH v2 4/6] drm/mediatek: remove unused external function
Hi, Bibby:
Quoted 3 lines · Bibby Hsieh
layer_onandlayer_offboth are unused external function, remove them frommtk_ddp_comp_funcsstructure.
Quoted 43 lines
Signed-off-by Bibby Hsieh <[email protected]>--- drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 2 -- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 16 ---------------- 2 files changed, 18 deletions(-)drivers/gpu/drm/mediatek/mtk_disp_ovl.c +0
-2@@ -314,8 +314,6 @@ static const struct mtk_ddp_comp_funcs mtk_disp_ovl_funcs = { .disable_vblank = mtk_ovl_disable_vblank, .supported_rotations = mtk_ovl_supported_rotations, .layer_nr = mtk_ovl_layer_nr, - .layer_on = mtk_ovl_layer_on, - .layer_off = mtk_ovl_layer_off, .layer_check = mtk_ovl_layer_check, .layer_config = mtk_ovl_layer_config, .bgclr_in_on = mtk_ovl_bgclr_in_on,drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +0
-9@@ -79,8 +79,6 @@ struct mtk_ddp_comp_funcs {void (*disable_vblank)(struct mtk_ddp_comp *comp);unsigned int (*supported_rotations)(struct mtk_ddp_comp *comp);unsigned int (*layer_nr)(struct mtk_ddp_comp *comp); -void (*layer_on)(struct mtk_ddp_comp *comp,unsigned int idx); -void (*layer_off)(struct mtk_ddp_comp *comp,unsigned int idx);int (*layer_check)(struct mtk_ddp_comp *comp,unsigned int idx,struct mtk_plane_state *state);@@ -151,20 +149,6 @@ static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp)return 0 ; } -static inline void mtk_ddp_comp_layer_on (struct mtk_ddp_comp *comp, -unsigned int idx) -{ -if (comp->funcs && comp->funcs->layer_on) - comp->funcs->layer_on (comp, idx); -} -
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h static inline unsigned int mtk_ddp_comp_layer_nr(struct mtk_ddp_comp *comp) · line 154
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +0
-7-static inline void mtk_ddp_comp_layer_off (struct mtk_ddp_comp *comp, -unsigned int idx) -{ -if (comp->funcs && comp->funcs->layer_off) - comp->funcs->layer_off (comp, idx); -} -static inline int mtk_ddp_comp_layer_check (struct mtk_ddp_comp *comp,unsigned int idx,struct mtk_plane_state *state)
_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
PATCH v2 5/6 drm/mediatek: support CMDQ interface in ddp component
In reply to Bibby HsiehThe CMDQ (Command Queue) in MT8183 is used to help update all relevant display controller registers with critical time limation.
This patch add cmdq interface in ddp_comp interface, let all ddp_comp interface can support cpu/cmdq function at the same time.
--- drivers/gpu/drm/mediatek/mtk_disp_color.c | 7 +- drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 65 +++++----- drivers/gpu/drm/mediatek/mtk_disp_rdma.c | 43 ++++--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 8 +- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 136 +++++++++++++++----- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 31 +++-- 6 files changed, 197 insertions(+), 93 deletions(-)
drivers/gpu/drm/mediatek/mtk_disp_color.c +4 -3
@@ -9,6 +9,7 @@#include <linux/of_device.h> #include <linux/of_irq.h> #include <linux/platform_device.h> +#include <linux/soc/mediatek/mtk-cmdq.h> #include "mtk_drm_crtc.h" #include "mtk_drm_ddp_comp.h"
@@ -45,12 +46,12 @@ static inline struct mtk_disp_color *comp_to_color(struct mtk_ddp_comp *comp)static void mtk_color_config (struct mtk_ddp_comp *comp,unsigned int w,unsigned int h,unsigned int vrefresh, -unsigned int bpc) +unsigned int bpc,struct cmdq_pkt *cmdq_pkt) {struct mtk_disp_color *color =comp_to_color (comp); -writel (w, comp->regs +DISP_COLOR_WIDTH (color)); -writel (h, comp->regs +DISP_COLOR_HEIGHT (color)); +mtk_ddp_write (cmdq_pkt, w, comp,DISP_COLOR_WIDTH (color)); +mtk_ddp_write (cmdq_pkt, h, comp,DISP_COLOR_HEIGHT (color)); }static void mtk_color_start (struct mtk_ddp_comp *comp)
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +35 -30
121 lines not on this page · raw message
drivers/gpu/drm/mediatek/mtk_disp_rdma.c +25 -18
84 lines not on this page · raw message
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +4 -4
@@ -304,7 +304,7 @@ static int mtk_crtc_ddp_hw_init(struct mtk_drm_crtc *mtk_crtc)if (prev ==DDP_COMPONENT_OVL0 )mtk_ddp_comp_bgclr_in_on (comp); -mtk_ddp_comp_config (comp, width, height, vrefresh, bpc); +mtk_ddp_comp_config (comp, width, height, vrefresh, bpc,NULL );mtk_ddp_comp_start (comp); }
@@ -319,7 +319,7 @@ static int mtk_crtc_ddp_hw_init(struct mtk_drm_crtc *mtk_crtc) comp =mtk_drm_ddp_comp_for_plane (crtc, plane, &local_layer);if (comp)mtk_ddp_comp_layer_config (comp, local_layer, - plane_state); + plane_state,NULL ); }return 0 ;
@@ -383,7 +383,7 @@ static void mtk_crtc_ddp_config(struct drm_crtc *crtc)if (state->pending_config) {mtk_ddp_comp_config (comp, state->pending_width, state->pending_height, - state->pending_vrefresh,0 ); + state->pending_vrefresh,0 ,NULL ); state->pending_config = false; }
@@ -403,7 +403,7 @@ static void mtk_crtc_ddp_config(struct drm_crtc *crtc)if (comp)mtk_ddp_comp_layer_config (comp, local_layer, - plane_state); + plane_state,NULL ); plane_state->pending.config = false; } mtk_crtc->pending_planes = false;
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +107 -29
201 lines not on this page · raw message
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +22 -9
@@ -69,10 +69,11 @@ enum mtk_ddp_comp_id { };struct mtk_ddp_comp ; - +struct cmdq_pkt ;struct mtk_ddp_comp_funcs {void (*config)(struct mtk_ddp_comp *comp,unsigned int w, -unsigned int h,unsigned int vrefresh,unsigned int bpc); +unsigned int h,unsigned int vrefresh, +unsigned int bpc,struct cmdq_pkt *cmdq_pkt);void (*start)(struct mtk_ddp_comp *comp);void (*stop)(struct mtk_ddp_comp *comp);void (*enable_vblank)(struct mtk_ddp_comp *comp,struct drm_crtc *crtc);
@@ -83,7 +84,8 @@ struct mtk_ddp_comp_funcs {unsigned int idx, struct mtk_plane_state *state);void (*layer_config)(struct mtk_ddp_comp *comp,unsigned int idx, -struct mtk_plane_state *state); +struct mtk_plane_state *state, +struct cmdq_pkt *cmdq_pkt);void (*gamma_set)(struct mtk_ddp_comp *comp,struct drm_crtc_state *state);void (*bgclr_in_on)(struct mtk_ddp_comp *comp);
@@ -97,14 +99,17 @@ struct mtk_ddp_comp {struct device *dev;enum mtk_ddp_comp_id id;const struct mtk_ddp_comp_funcs *funcs; +resource_size_t regs_pa; +u8 subsys; };static inline void mtk_ddp_comp_config (struct mtk_ddp_comp *comp,unsigned int w,unsigned int h, -unsigned int vrefresh,unsigned int bpc) +unsigned int vrefresh,unsigned int bpc, +struct cmdq_pkt *cmdq_pkt) {if (comp->funcs && comp->funcs->config) - comp->funcs->config (comp, w, h, vrefresh, bpc); + comp->funcs->config (comp, w, h, vrefresh, bpc, cmdq_pkt); }static inline void mtk_ddp_comp_start (struct mtk_ddp_comp *comp)
@@ -160,10 +165,11 @@ static inline int mtk_ddp_comp_layer_check(struct mtk_ddp_comp *comp,static inline void mtk_ddp_comp_layer_config (struct mtk_ddp_comp *comp,unsigned int idx, -struct mtk_plane_state *state) +struct mtk_plane_state *state, +struct cmdq_pkt *cmdq_pkt) {if (comp->funcs && comp->funcs->layer_config) - comp->funcs->layer_config (comp, idx, state); + comp->funcs->layer_config (comp, idx, state, cmdq_pkt); } static inline void mtk_ddp_gamma_set(struct mtk_ddp_comp *comp,
@@ -193,6 +199,13 @@ int mtk_ddp_comp_init(struct device *dev, struct device_node *comp_node,int mtk_ddp_comp_register (struct drm_device *drm,struct mtk_ddp_comp *comp);void mtk_ddp_comp_unregister (struct drm_device *drm,struct mtk_ddp_comp *comp);void mtk_dither_set (struct mtk_ddp_comp *comp,unsigned int bpc, -unsigned int CFG ); - +unsigned int CFG ,struct cmdq_pkt *cmdq_pkt); +enum mtk_ddp_comp_type mtk_ddp_comp_get_type (enum mtk_ddp_comp_id comp_id); +void mtk_ddp_write (struct cmdq_pkt *cmdq_pkt,unsigned int value, +struct mtk_ddp_comp *comp,unsigned int offset); +void mtk_ddp_write_relaxed (struct cmdq_pkt *cmdq_pkt,unsigned int value, +struct mtk_ddp_comp *comp,unsigned int offset); +void mtk_ddp_write_mask (struct cmdq_pkt *cmdq_pkt,unsigned int value, +struct mtk_ddp_comp *comp,unsigned int offset, +unsigned int mask);#endif /* MTK_DRM_DDP_COMP_H */
Signature · 1 line
2.18.0
PATCH v2 6/6 drm/mediatek: apply CMDQ control flow
In reply to Bibby HsiehUnlike other SoCs, MT8183 does not have "shadow" registers for performaing an atomic video mode set or page flip at vblank/vsync.
The CMDQ (Commend Queue) in MT8183 is used to help update all relevant display controller registers with critical time limation.
--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 163 +++++++++++++++++------- 1 file changed, 118 insertions(+), 45 deletions(-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +118 -45
@@ -12,6 +12,8 @@#include <drm/drm_plane_helper.h> #include <drm/drm_probe_helper.h> #include <drm/drm_vblank.h> +#include <linux/of_address.h> +#include <linux/soc/mediatek/mtk-cmdq.h> #include "mtk_drm_drv.h" #include "mtk_drm_crtc.h"
@@ -42,11 +44,17 @@ struct mtk_drm_crtc {unsigned int layer_nr;bool pending_planes; +struct cmdq_client *cmdq_client; +u32 cmdq_event; +void __iomem *config_regs;const struct mtk_mmsys_reg_data *mmsys_reg_data;struct mtk_disp_mutex *mutex;unsigned int ddp_comp_nr;struct mtk_ddp_comp **ddp_comp; + +/* lock for cmdq access */ +struct mutex chan_lock; };struct mtk_crtc_state {
@@ -56,6 +64,11 @@ struct mtk_crtc_state {unsigned int pending_width;unsigned int pending_height;unsigned int pending_vrefresh; +struct cmdq_pkt *cmdq_handle; +}; + +struct mtk_cmdq_cb_data { +struct cmdq_pkt *cmdq_handle; };static inline struct mtk_drm_crtc *to_mtk_crtc (struct drm_crtc *c)
@@ -229,6 +242,50 @@ struct mtk_ddp_comp *mtk_drm_ddp_comp_for_plane(struct drm_crtc *crtc,return NULL ; } +#ifdef CONFIG_MTK_CMDQ +static void ddp_cmdq_cb (struct cmdq_cb_data data) +{ +struct mtk_cmdq_cb_data *cb_data = data.data; + +cmdq_pkt_destroy (cb_data->cmdq_handle); +kfree (cb_data); +} + +static void mtk_cmdq_acquire (struct drm_crtc *crtc) +{ +struct mtk_crtc_state *mtk_crtc_state = +to_mtk_crtc_state (crtc->state); +struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc); + +mutex_lock (&mtk_crtc->chan_lock); + mtk_crtc_state->cmdq_handle = +cmdq_pkt_create (mtk_crtc->cmdq_client, +PAGE_SIZE ); +cmdq_pkt_clear_event (mtk_crtc_state->cmdq_handle, + mtk_crtc->cmdq_event); +cmdq_pkt_wfe (mtk_crtc_state->cmdq_handle, mtk_crtc->cmdq_event); +} + +static void mtk_cmdq_release (struct drm_crtc *crtc) +{ +struct mtk_crtc_state *mtk_crtc_state = +to_mtk_crtc_state (crtc->state); +struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc); +struct mtk_cmdq_cb_data *cb_data; + + cb_data =kmalloc (sizeof (*cb_data),GFP_KERNEL ); +if (!cb_data) { +DRM_DEV_ERROR (crtc->dev->dev,"Failed to alloc cb_data\n" ); +return ; + } + + cb_data->cmdq_handle = mtk_crtc_state->cmdq_handle; +cmdq_pkt_flush_async (mtk_crtc_state->cmdq_handle, + ddp_cmdq_cb, cb_data); +mutex_unlock (&mtk_crtc->chan_lock); +} +#endif +static int mtk_crtc_ddp_hw_init (struct mtk_drm_crtc *mtk_crtc) {struct drm_crtc *crtc = &mtk_crtc->base;
@@ -383,7 +440,8 @@ static void mtk_crtc_ddp_config(struct drm_crtc *crtc)if (state->pending_config) {mtk_ddp_comp_config (comp, state->pending_width, state->pending_height, - state->pending_vrefresh,0 ,NULL ); + state->pending_vrefresh,0 , + state->cmdq_handle); state->pending_config = false; }
@@ -403,13 +461,54 @@ static void mtk_crtc_ddp_config(struct drm_crtc *crtc)if (comp)mtk_ddp_comp_layer_config (comp, local_layer, - plane_state,NULL ); + plane_state, + state->cmdq_handle); plane_state->pending.config = false; } mtk_crtc->pending_planes = false; } } +static void mtk_drm_crtc_hw_config (struct mtk_drm_crtc *mtk_crtc) +{ +struct drm_crtc *crtc = &mtk_crtc->base; +struct mtk_drm_private *priv = crtc->dev->dev_private; +unsigned int pending_planes =0 ; +int i; + +for (i =0 ; i < mtk_crtc->layer_nr; i++) { +struct drm_plane *plane = &mtk_crtc->planes[i]; +struct mtk_plane_state *plane_state; + + plane_state =to_mtk_plane_state (plane->state); +if (plane_state->pending.dirty) { + plane_state->pending.config = true; + plane_state->pending.dirty = false; + pending_planes |=BIT (i); + }else if (plane_state->pending.async_dirty) { + plane_state->pending.config = true; + plane_state->pending.async_update = false; + plane_state->pending.async_dirty = false; + pending_planes |=BIT (i); + } + } +if (pending_planes) + mtk_crtc->pending_planes = true; + +if (priv->data->shadow_register) { +mtk_disp_mutex_acquire (mtk_crtc->mutex); +mtk_crtc_ddp_config (crtc); +mtk_disp_mutex_release (mtk_crtc->mutex); + } +#ifdef CONFIG_MTK_CMDQ +if (mtk_crtc->cmdq_client) { +mtk_cmdq_acquire (crtc); +mtk_crtc_ddp_config (crtc); +mtk_cmdq_release (crtc); + } +#endif +} +int mtk_drm_crtc_plane_check (struct drm_crtc *crtc,struct drm_plane *plane,struct mtk_plane_state *state) {
@@ -425,34 +524,15 @@ int mtk_drm_crtc_plane_check(struct drm_crtc *crtc, struct drm_plane *plane,void mtk_drm_crtc_async_update (struct drm_crtc *crtc,struct drm_plane *plane,struct drm_plane_state *new_state) { -struct mtk_drm_private *priv = crtc->dev->dev_private;struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc);const struct drm_plane_helper_funcs *plane_helper_funcs = plane->helper_private; -int i;if (!mtk_crtc->enabled)return ; plane_helper_funcs->atomic_update (plane, new_state); - -for (i =0 ; i < mtk_crtc->layer_nr; i++) { -struct drm_plane *plane = &mtk_crtc->planes[i]; -struct mtk_plane_state *plane_state; - - plane_state =to_mtk_plane_state (plane->state); -if (plane_state->pending.async_dirty) { - plane_state->pending.config = true; - plane_state->pending.async_update = false; - plane_state->pending.async_dirty = false; - } - } - mtk_crtc->pending_planes = true; -if (priv->data->shadow_register) { -mtk_disp_mutex_acquire (mtk_crtc->mutex); -mtk_crtc_ddp_config (crtc); -mtk_disp_mutex_release (mtk_crtc->mutex); - } +mtk_drm_crtc_hw_config (mtk_crtc); } static void mtk_drm_crtc_atomic_enable(struct drm_crtc *crtc,
@@ -536,34 +616,14 @@ static void mtk_drm_crtc_atomic_flush(struct drm_crtc *crtc, struct drm_crtc_state *old_crtc_state) {struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc); -struct mtk_drm_private *priv = crtc->dev->dev_private; -unsigned int pending_planes =0 ;int i;if (mtk_crtc->event) mtk_crtc->pending_needs_vblank = true; -for (i =0 ; i < mtk_crtc->layer_nr; i++) { -struct drm_plane *plane = &mtk_crtc->planes[i]; -struct mtk_plane_state *plane_state; - - plane_state =to_mtk_plane_state (plane->state); -if (plane_state->pending.dirty) { - plane_state->pending.config = true; - plane_state->pending.dirty = false; - pending_planes |=BIT (i); - } - } -if (pending_planes) - mtk_crtc->pending_planes = true;if (crtc->state->color_mgmt_changed)for (i =0 ; i < mtk_crtc->ddp_comp_nr; i++)mtk_ddp_gamma_set (mtk_crtc->ddp_comp[i], crtc->state); - -if (priv->data->shadow_register) { -mtk_disp_mutex_acquire (mtk_crtc->mutex); -mtk_crtc_ddp_config (crtc); -mtk_disp_mutex_release (mtk_crtc->mutex); - } +mtk_drm_crtc_hw_config (mtk_crtc); }static const struct drm_crtc_funcs mtk_crtc_funcs = {
@@ -613,7 +673,7 @@ void mtk_crtc_ddp_irq(struct drm_crtc *crtc, struct mtk_ddp_comp *comp)struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc);struct mtk_drm_private *priv = crtc->dev->dev_private; -if (!priv->data->shadow_register) +if (!priv->data->shadow_register && !mtk_crtc->cmdq_client)mtk_crtc_ddp_config (crtc);mtk_drm_finish_page_flip (mtk_crtc);
@@ -755,6 +815,19 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,drm_mode_crtc_set_gamma_size (&mtk_crtc->base,MTK_LUT_SIZE );drm_crtc_enable_color_mgmt (&mtk_crtc->base,0 , false,MTK_LUT_SIZE ); priv->num_pipes++; - +#ifdef CONFIG_MTK_CMDQ + mtk_crtc->cmdq_client = +cmdq_mbox_create (dev,drm_crtc_index (&mtk_crtc->base), +2000 ); +of_property_read_u32_index (dev->of_node,"mediatek,gce-events" , +drm_crtc_index (&mtk_crtc->base), + &mtk_crtc->cmdq_event); +if (IS_ERR (mtk_crtc->cmdq_client)) { +dev_dbg (dev,"mtk_crtc %d failed to create mailbox client, writing register by CPU now\n" , +drm_crtc_index (&mtk_crtc->base)); + mtk_crtc->cmdq_client =NULL ; + } +mutex_init (&mtk_crtc->chan_lock); +#endif return 0 ; }
Signature · 1 line
2.18.0