Support IGT in display driver
Subsystems (3)
v5 cover Support IGT in display driver
From: Hsiao Chien Sung <[email protected]>
This series is based on [email protected].
This series adds support for running IGT (Intel GPU Tool) tests with MediaTek display driver. The following changes will be applied:
1. Add a new API for creating GCE thread loop to retrieve CRCs from the hardware component
2. Support hardware CRC calculation in both VDOSYS0 and VDOSYS1
3. Support alpha blending in both VDOSYS0 and VDOSYS1
Changes in v5:
- Add more descriptions to the codes
- Add DRM mode configs to the driver data
- Squash and rearrange the commits
Changes in v4:
- Separate the patch into smaller ones
- Change the title of some patches
- Revert the changes that are not related to the series
Changes in v3:
- Modify the dt-binding document of Mediatek OVL
- Set DRM mode configs accroding to the hardware capabilities
- Replace cmdq_pkt_jump_absolute() with cmdq_pkt_jump()
Changes in v2:
- Simplify CMDQ by adding commands that are currently used only
- Integrate CRC related codes into new APIs for Mixer and OVL to reuse
- Add CPU version CRC retrieval when CMDQ is disabled
Hsiao Chien Sung (13):
soc: mediatek: Disable 9-bit alpha in ETHDR drm/mediatek: Add OVL compatible name for MT8195 drm/mediatek: Add missing plane settings when async update drm/mediatek: Fix errors when reporting rotation capability drm/mediatek: Set DRM mode configs accordingly drm/mediatek: Turn off the layers with zero width or height drm/mediatek: Support alpha blending in display driver drm/mediatek: Support alpha blending in OVL drm/mediatek: Support alpha blending in Mixer drm/mediatek: Support CRC in display driver drm/mediatek: Support CRC in OVL
drm/mediatek: Support CRC in OVL adaptor drm/mediatek: Add comments for the structures
drivers/gpu/drm/mediatek/mtk_disp_drv.h | 7 + drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 320 ++++++++++++++++-- .../gpu/drm/mediatek/mtk_disp_ovl_adaptor.c | 32 +- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 261 +++++++++++++- drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 39 +++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 7 + drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 35 ++ drivers/gpu/drm/mediatek/mtk_drm_drv.c | 27 ++ drivers/gpu/drm/mediatek/mtk_drm_drv.h | 20 ++ drivers/gpu/drm/mediatek/mtk_drm_plane.c | 15 +- drivers/gpu/drm/mediatek/mtk_ethdr.c | 106 +++++- drivers/gpu/drm/mediatek/mtk_ethdr.h | 5 + drivers/soc/mediatek/mtk-mmsys.c | 1 + 13 files changed, 828 insertions(+), 47 deletions(-)
--
2.18.0
PATCH v5 1/13 soc: mediatek: Disable 9-bit alpha in ETHDR
ETHDR 9-bit alpha should be disabled by default,
otherwise alpha blending will not work.
--- drivers/soc/mediatek/mtk-mmsys.c | 1 + 1 file changed, 1 insertion(+)
drivers/soc/mediatek/mtk-mmsys.c +1 -0
@@ -236,6 +236,7 @@ void mtk_mmsys_mixer_in_config(struct device *dev, int idx, bool alpha_sel, u16mtk_mmsys_update_bits (mmsys,MT8195_VDO1_MIXER_IN1_ALPHA + (idx -1 ) *4 , ~0 , alpha <<16 | alpha, cmdq_pkt); +mtk_mmsys_update_bits (mmsys,MT8195_VDO1_HDR_TOP_CFG ,BIT (15 + idx),0 , cmdq_pkt);mtk_mmsys_update_bits (mmsys,MT8195_VDO1_HDR_TOP_CFG ,BIT (19 + idx), alpha_sel << (19 + idx), cmdq_pkt); mtk_mmsys_update_bits(mmsys, MT8195_VDO1_MIXER_IN1_PAD + (idx - 1) * 4,
Signature · 1 line
2.18.0
PATCH v5 2/13 drm/mediatek: Add OVL compatible name for MT8195
In reply to Hsiao Chien SungAdd OVL compatible name for MT8195.
Without this commit, DRM won't work after modifying the device tree.
--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/mediatek/mtk_drm_drv.c +2 -0
@@ -762,6 +762,8 @@ static const struct of_device_id mtk_ddp_comp_dt_ids[] = { .data = (void *)MTK_DISP_OVL }, { .compatible = "mediatek,mt8192-disp-ovl", .data = (void *)MTK_DISP_OVL }, + { .compatible = "mediatek,mt8195-disp-ovl", + .data = (void *)MTK_DISP_OVL }, { .compatible = "mediatek,mt8183-disp-ovl-2l", .data = (void *)MTK_DISP_OVL_2L }, { .compatible = "mediatek,mt8192-disp-ovl-2l",
Signature · 1 line
2.18.0
PATCH v5 3/13 drm/mediatek: Add missing plane settings when async update
In reply to Hsiao Chien SungFix an issue that plane coordinate was not saved when calling async update.
--- drivers/gpu/drm/mediatek/mtk_drm_plane.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/gpu/drm/mediatek/mtk_drm_plane.c +2 -0
@@ -227,6 +227,8 @@ static void mtk_plane_atomic_async_update(struct drm_plane *plane, plane->state->src_y = new_state->src_y; plane->state->src_h = new_state->src_h; plane->state->src_w = new_state->src_w; + plane->state->dst.x1 = new_state->dst.x1; + plane->state->dst.y1 = new_state->dst.y1;mtk_plane_update_new_state (new_state, new_plane_state);swap (plane->state->fb, new_state->fb);
Signature · 1 line
2.18.0
PATCH v5 4/13 drm/mediatek: Fix errors when reporting rotation capability
In reply to Hsiao Chien SungCreate rotation property according to the hardware capability. Since currently OVL of all chips support same rotation, no need to define it in the driver data.
--- drivers/gpu/drm/mediatek/mtk_disp_drv.h | 1 + drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 19 +++++++------------ .../gpu/drm/mediatek/mtk_disp_ovl_adaptor.c | 9 +++++++++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 1 + drivers/gpu/drm/mediatek/mtk_drm_plane.c | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-)
drivers/gpu/drm/mediatek/mtk_disp_drv.h +1 -0
@@ -126,6 +126,7 @@ void mtk_ovl_adaptor_register_vblank_cb(struct device *dev, void (*vblank_cb)(vovoid mtk_ovl_adaptor_unregister_vblank_cb (struct device *dev);void mtk_ovl_adaptor_enable_vblank (struct device *dev);void mtk_ovl_adaptor_disable_vblank (struct device *dev); +unsigned int mtk_ovl_adaptor_supported_rotations (struct device *dev);void mtk_ovl_adaptor_start (struct device *dev);void mtk_ovl_adaptor_stop (struct device *dev);unsigned int mtk_ovl_adaptor_layer_nr (struct device *dev);
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +7 -12
@@ -289,6 +289,10 @@ unsigned int mtk_ovl_layer_nr(struct device *dev)unsigned int mtk_ovl_supported_rotations (struct device *dev) { +/* +* although currently OVL can only do reflection, +* reflect x + reflect y = rotate 180 +*/ return DRM_MODE_ROTATE_0 |DRM_MODE_ROTATE_180 |DRM_MODE_REFLECT_X |DRM_MODE_REFLECT_Y ; }
@@ -297,27 +301,18 @@ int mtk_ovl_layer_check(struct device *dev, unsigned int idx, struct mtk_plane_state *mtk_state) {struct drm_plane_state *state = &mtk_state->base; -unsigned int rotation =0 ; - rotation =drm_rotation_simplify (state->rotation, -DRM_MODE_ROTATE_0 | -DRM_MODE_REFLECT_X | -DRM_MODE_REFLECT_Y ); - rotation &= ~DRM_MODE_ROTATE_0 ; - -/* We can only do reflection, not rotation */ -if ((rotation &DRM_MODE_ROTATE_MASK ) !=0 ) +/* check if any unsupported rotation is set */ +if (state->rotation & ~mtk_ovl_supported_rotations (dev))return -EINVAL ;/* * TODO: Rotating/reflecting YUV buffers is not supported at this time. * Only RGB[AX] variants are supported. */ -if (state->fb->format->is_yuv && rotation !=0 ) +if (state->fb->format->is_yuv && (state->rotation & ~DRM_MODE_ROTATE_0 ))return -EINVAL ; - state->rotation = rotation; -return 0 ; }
drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c +9 -0
@@ -379,6 +379,15 @@ void mtk_ovl_adaptor_register_vblank_cb(struct device *dev, void (*vblank_cb)(vo vblank_cb, vblank_cb_data); } +unsigned int mtk_ovl_adaptor_supported_rotations (struct device *dev) +{ +/* +* should still return DRM_MODE_ROTATE_0 if rotation is not supported, +* or IGT will fail. +*/ +return DRM_MODE_ROTATE_0 ; +} +void mtk_ovl_adaptor_unregister_vblank_cb (struct device *dev) {struct mtk_disp_ovl_adaptor *ovl_adaptor =dev_get_drvdata (dev);
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +1 -0
@@ -417,6 +417,7 @@ static const struct mtk_ddp_comp_funcs ddp_ovl_adaptor = { .get_formats = mtk_ovl_adaptor_get_formats, .get_num_formats = mtk_ovl_adaptor_get_num_formats, .mode_valid = mtk_ovl_adaptor_mode_valid, + .supported_rotations = mtk_ovl_adaptor_supported_rotations, };static const char *const mtk_ddp_comp_stem[MTK_DDP_COMP_TYPE_MAX ] = {
drivers/gpu/drm/mediatek/mtk_drm_plane.c +1 -1
@@ -338,7 +338,7 @@ int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane,return err; } -if (supported_rotations & ~DRM_MODE_ROTATE_0 ) { +if (supported_rotations) { err =drm_plane_create_rotation_property (plane,DRM_MODE_ROTATE_0 , supported_rotations);
Signature · 1 line
2.18.0
Re: [PATCH v5 04/13] drm/mediatek: Fix errors when reporting rotation capability
Hi, Hsiao-chien:
Quoted 77 lines · Hsiao Chien Sung
Create rotation property according to the hardware capability. Since currently OVL of all chips support same rotation, no need to define it in the driver data.
Fixes 84d805753983 ("drm/mediatek: Support reflect-y planerotation")
Reviewed-by: AngeloGioacchino Del Regno <
[email protected]>Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_disp_drv.h | 1 + drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 19 +++++++-------- ---- .../gpu/drm/mediatek/mtk_disp_ovl_adaptor.c | 9 +++++++++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 1 + drivers/gpu/drm/mediatek/mtk_drm_plane.c | 2 +- 5 files changed, 19 insertions(+), 13 deletions(-)drivers/gpu/drm/mediatek/mtk_disp_drv.h +0
-0@@ -126,6 +126,7 @@ void mtk_ovl_adaptor_register_vblank_cb(structdevice *dev, void (*vblank_cb)(vo
voidmtk_ovl_adaptor_unregister_vblank_cb(struct device *dev); voidmtk_ovl_adaptor_enable_vblank(struct device *dev); voidmtk_ovl_adaptor_disable_vblank(struct device *dev);
+unsigned intmtk_ovl_adaptor_supported_rotations(struct device *dev);
voidmtk_ovl_adaptor_start(struct device *dev);
voidmtk_ovl_adaptor_stop(struct device *dev); unsigned intmtk_ovl_adaptor_layer_nr(struct device *dev);drivers/gpu/drm/mediatek/mtk_disp_ovl.c +4
-0@@ -289,6 +289,10 @@ unsigned int mtk_ovl_layer_nr(struct device *dev)unsigned int mtk_ovl_supported_rotations (struct device *dev) { +/* +* although currently OVL can only do reflection, +* reflect x + reflect y = rotate 180 +*/ return DRM_MODE_ROTATE_0 |DRM_MODE_ROTATE_180 |DRM_MODE_REFLECT_X |DRM_MODE_REFLECT_Y ;}
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +2
-9@@ -297,27 +301,18 @@ int mtk_ovl_layer_check(struct device *dev,unsigned int idx, struct mtk_plane_state *mtk_state) { struct drm_plane_state *state = &mtk_state->base; -unsigned int rotation =0 ; - rotation =drm_rotation_simplify (state->rotation, -DRM_MODE_ROTATE_0 | -DRM_MODE_REFLECT_X | -DRM_MODE_REFLECT_Y ); - rotation &= ~DRM_MODE_ROTATE_0 ; - -/* We can only do reflection, not rotation */ -if ((rotation &DRM_MODE_ROTATE_MASK ) !=0 ) +/* check if any unsupported rotation is set */ +if (state->rotation & ~mtk_ovl_supported_rotations (dev))return -EINVAL ;/* * TODO: Rotating/reflecting YUV buffers is not supported at this time.
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +1
-1* Only RGB[AX] variants are supported. */ -if (state->fb->format->is_yuv && rotation !=0 ) + if (state->fb->format->is_yuv && (state->rotation &
Quoted 1 line
~DRM_MODE_ROTATE_0))
You still no explain what you do here.
Quoted 52 lines
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +0
-2return -EINVAL ; - state->rotation = rotation; -return 0 ; }drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c +0
-0@@ -379,6 +379,15 @@ void mtk_ovl_adaptor_register_vblank_cb(structdevice *dev, void (*vblank_cb)(vo
drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c +4
-0vblank_cb, vblank_cb_data); } +unsigned int mtk_ovl_adaptor_supported_rotations (struct device *dev) +{ +/* +* should still return DRM_MODE_ROTATE_0 if rotation is not supported,
drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c +5
-0+* or IGT will fail. +*/ +return DRM_MODE_ROTATE_0 ; +} +void mtk_ovl_adaptor_unregister_vblank_cb (struct device *dev) { struct mtk_disp_ovl_adaptor *ovl_adaptor =
dev_get_drvdata(dev);drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +1
-0@@ -417,6 +417,7 @@ static const struct mtk_ddp_comp_funcs ddp_ovl_adaptor = { .get_formats = mtk_ovl_adaptor_get_formats, .get_num_formats = mtk_ovl_adaptor_get_num_formats, .mode_valid = mtk_ovl_adaptor_mode_valid, + .supported_rotations = mtk_ovl_adaptor_supported_rotations, };static const char * const mtk_ddp_comp_stem[MTK_DDP_COMP_TYPE_MAX] =
{drivers/gpu/drm/mediatek/mtk_drm_plane.c +0
-0
drivers/gpu/drm/mediatek/mtk_drm_plane.c int mtk_plane_init(struct drm_device *dev, struct · line 342
Quoted 6 lines
drivers/gpu/drm/mediatek/mtk_drm_plane.c +1
-1@@ -338,7 +338,7 @@ int mtk_plane_init(struct drm_device *dev, structdrm_plane *plane, return err; } -if (supported_rotations & ~DRM_MODE_ROTATE_0 ) { +if (supported_rotations) {
Try report issue to IGT team.
Regards,
CK
Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_drm_plane.c +0
-0err =drm_plane_create_rotation_property (plane, DRM_MODE_ROTAT
E_0,
supported_rota
tions);
PATCH v5 5/13 drm/mediatek: Set DRM mode configs accordingly
In reply to Hsiao Chien SungSet DRM mode configs limitation according to the hardware capabilities and pass the IGT checks as below:
- The test "graphics.IgtKms.kms_plane" requires a frame buffer with width of 4512 pixels (> 4096).
- The test "graphics.IgtKms.kms_cursor_crc" checks if the cursor size is defined, and run the test with cursor size from 1x1 to 512x512.
Please notice that the test conditions may change as IGT is updated.
--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 25 +++++++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_drv.h | 3 +++ 2 files changed, 28 insertions(+)
drivers/gpu/drm/mediatek/mtk_drm_drv.c +25 -0
@@ -296,6 +296,9 @@ static const struct mtk_mmsys_driver_data mt8188_vdosys0_driver_data = { .conn_routes = mt8188_mtk_ddp_main_routes, .num_conn_routes = ARRAY_SIZE(mt8188_mtk_ddp_main_routes), .mmsys_dev_num = 2, + .max_pitch = GENMASK(15, 0), + .min_width = 1, + .min_height = 1, };static const struct mtk_mmsys_driver_data mt8192_mmsys_driver_data = {
@@ -310,6 +313,9 @@ static const struct mtk_mmsys_driver_data mt8195_vdosys0_driver_data = { .main_path = mt8195_mtk_ddp_main, .main_len = ARRAY_SIZE(mt8195_mtk_ddp_main), .mmsys_dev_num = 2, + .max_pitch = GENMASK(15, 0), + .min_width = 1, + .min_height = 1, };static const struct mtk_mmsys_driver_data mt8195_vdosys1_driver_data = {
@@ -317,6 +323,9 @@ static const struct mtk_mmsys_driver_data mt8195_vdosys1_driver_data = { .ext_len = ARRAY_SIZE(mt8195_mtk_ddp_ext), .mmsys_id = 1, .mmsys_dev_num = 2, + .max_pitch = GENMASK(15, 0), + .min_width = 2, /* 2-pixel align when ethdr is bypassed */ + .min_height = 1, };static const struct of_device_id mtk_drm_of_ids[] = {
@@ -495,6 +504,18 @@ static int mtk_drm_kms_init(struct drm_device *drm)for (j =0 ; j < private->data->mmsys_dev_num; j++) { priv_n = private->all_drm_private[j]; +if (priv_n->data->max_pitch) { +/* Save 4 bytes for the color depth (pitch = width * bpp) */ + drm->mode_config.max_width = priv_n->data->max_pitch >>2 ; + drm->mode_config.max_height = priv_n->data->max_pitch >>2 ; + } + +if (priv_n->data->min_width) + drm->mode_config.min_width = priv_n->data->min_width; + +if (priv_n->data->min_height) + drm->mode_config.min_height = priv_n->data->min_height; +if (i ==CRTC_MAIN && priv_n->data->main_len) { ret = mtk_drm_crtc_create(drm, priv_n->data->main_path, priv_n->data->main_len, j,
@@ -522,6 +543,10 @@ static int mtk_drm_kms_init(struct drm_device *drm) } } +/* IGT will check if the cursor size is configured */ + drm->mode_config.cursor_width = drm->mode_config.max_width; + drm->mode_config.cursor_height = drm->mode_config.max_height; +/* Use OVL device for all DMA memory allocations */ crtc =drm_crtc_from_index (drm,0 );if (crtc)
drivers/gpu/drm/mediatek/mtk_drm_drv.h +3 -0
@@ -46,6 +46,9 @@ struct mtk_mmsys_driver_data {bool shadow_register;unsigned int mmsys_id;unsigned int mmsys_dev_num; + +u32 max_pitch; +int min_width, min_height; };struct mtk_drm_private {
Signature · 1 line
2.18.0
Re: [PATCH v5 05/13] drm/mediatek: Set DRM mode configs accordingly
Hi, Hsiao-chien:
Quoted 70 lines · Hsiao Chien Sung
Set DRM mode configs limitation according to the hardware capabilities
and pass the IGT checks as below:- The test "graphics.IgtKms.kms_plane" requires a frame buffer with width of 4512 pixels (> 4096).
- The test "graphics.IgtKms.kms_cursor_crc" checks if the cursor size is
defined, and run the test with cursor size from 1x1 to 512x512.Please notice that the test conditions may change as IGT is updated.
Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 25 +++++++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_drv.h | 3 +++ 2 files changed, 28 insertions(+)drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-0@@ -296,6 +296,9 @@ static const struct mtk_mmsys_driver_data mt8188_vdosys0_driver_data = { .conn_routes = mt8188_mtk_ddp_main_routes, .num_conn_routes = ARRAY_SIZE(mt8188_mtk_ddp_main_routes), .mmsys_dev_num = 2, + .max_pitch = GENMASK(15, 0), + .min_width = 1, + .min_height = 1, };static const struct
mtk_mmsys_driver_datamt8192_mmsys_driver_data=
{drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-0@@ -310,6 +313,9 @@ static const struct mtk_mmsys_driver_data mt8195_vdosys0_driver_data = { .main_path = mt8195_mtk_ddp_main, .main_len = ARRAY_SIZE(mt8195_mtk_ddp_main), .mmsys_dev_num = 2, + .max_pitch = GENMASK(15, 0), + .min_width = 1, + .min_height = 1, };static const struct
mtk_mmsys_driver_datamt8195_vdosys1_driver_data
= {drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-0@@ -317,6 +323,9 @@ static const struct mtk_mmsys_driver_data mt8195_vdosys1_driver_data = { .ext_len = ARRAY_SIZE(mt8195_mtk_ddp_ext), .mmsys_id = 1, .mmsys_dev_num = 2, + .max_pitch = GENMASK(15, 0), + .min_width = 2, /* 2-pixel align when ethdr is bypassed */ + .min_height = 1, };static const struct
of_device_idmtk_drm_of_ids[] = {drivers/gpu/drm/mediatek/mtk_drm_drv.c +2
-0@@ -495,6 +504,18 @@ static int mtk_drm_kms_init(struct drm_device *drm)for (j =0 ; j < private->data->mmsys_dev_num; j++) { priv_n = private->all_drm_private[j]; +if (priv_n->data->max_pitch) { +/* Save 4 bytes for the color depth (pitch = width * bpp) */
drivers/gpu/drm/mediatek/mtk_drm_drv.c +1
-0+ drm->mode_config.max_width = priv_n-Quoted 1 line
data->max_pitch>> 2;drivers/gpu/drm/mediatek/mtk_drm_drv.c +1
-0+ drm->mode_config.max_height = priv_n-
Quoted 1 line
Quoted 1 line
data->max_pitch>> 2;
I think the term 'pitch' is for width not for height. And I think you should not divide height by 4. So I would like to have priv_n->data-
Quoted 1 line
max_height.
Regards,
CK
Quoted 42 lines
drivers/gpu/drm/mediatek/mtk_drm_drv.c +4
-0+ } + +if (priv_n->data->min_width) + drm->mode_config.min_width = priv_n-Quoted 1 line
data->min_width;drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-0+ +if (priv_n->data->min_height) + drm->mode_config.min_height = priv_n-Quoted 1 line
data->min_height;drivers/gpu/drm/mediatek/mtk_drm_drv.c +1
-0+if (i ==CRTC_MAIN && priv_n->data->main_len) { ret = mtk_drm_crtc_create(drm, priv_n-Quoted 1 line
data->main_path,priv_n->data-
Quoted 1 line
main_len, j,drivers/gpu/drm/mediatek/mtk_drm_drv.c +4
-0@@ -522,6 +543,10 @@ static int mtk_drm_kms_init(struct drm_device *drm) } } +/* IGT will check if the cursor size is configured */ + drm->mode_config.cursor_width = drm->mode_config.max_width; + drm->mode_config.cursor_height = drm->mode_config.max_height; +/* Use OVL device for all DMA memory allocations */ crtc =drm_crtc_from_index (drm,0 );drivers/gpu/drm/mediatek/mtk_drm_drv.c +0
-0if (crtc)drivers/gpu/drm/mediatek/mtk_drm_drv.h +3
-0@@ -46,6 +46,9 @@ struct mtk_mmsys_driver_data {bool shadow_register;unsigned int mmsys_id;unsigned int mmsys_dev_num; + +u32 max_pitch; +int min_width, min_height; };struct mtk_drm_private {
Re: [PATCH v5 05/13] drm/mediatek: Set DRM mode configs accordingly
Hi CK,
Quoted 75 lines · CK Hu (胡俊光)
Hi, Hsiao-chien:
Quoted 72 lines · Hsiao Chien Sung
Set DRM mode configs limitation according to the hardware capabilities
and pass the IGT checks as below:- The test "graphics.IgtKms.kms_plane" requires a frame buffer with width of 4512 pixels (> 4096).
- The test "graphics.IgtKms.kms_cursor_crc" checks if the cursor size
is
defined, and run the test with cursor size from 1x1 to 512x512.Please notice that the test conditions may change as IGT is updated.
Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_drv.c | 25 +++++++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_drv.h | 3 +++ 2 files changed, 28 insertions(+)drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-0@@ -296,6 +296,9 @@ static const struct mtk_mmsys_driver_data mt8188_vdosys0_driver_data = { .conn_routes = mt8188_mtk_ddp_main_routes, .num_conn_routes = ARRAY_SIZE(mt8188_mtk_ddp_main_routes), .mmsys_dev_num = 2, + .max_pitch = GENMASK(15, 0), + .min_width = 1, + .min_height = 1, };static const struct
mtk_mmsys_driver_datamt8192_mmsys_driver_data
=
{drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-0@@ -310,6 +313,9 @@ static const struct mtk_mmsys_driver_data mt8195_vdosys0_driver_data = { .main_path = mt8195_mtk_ddp_main, .main_len = ARRAY_SIZE(mt8195_mtk_ddp_main), .mmsys_dev_num = 2, + .max_pitch = GENMASK(15, 0), + .min_width = 1, + .min_height = 1, };static const struct
mtk_mmsys_driver_datamt8195_vdosys1_driver_data
= {drivers/gpu/drm/mediatek/mtk_drm_drv.c +3
-0@@ -317,6 +323,9 @@ static const struct mtk_mmsys_driver_data mt8195_vdosys1_driver_data = { .ext_len = ARRAY_SIZE(mt8195_mtk_ddp_ext), .mmsys_id = 1, .mmsys_dev_num = 2, + .max_pitch = GENMASK(15, 0), + .min_width = 2, /* 2-pixel align when ethdr is bypassed */ + .min_height = 1, };static const struct
of_device_idmtk_drm_of_ids[] = {drivers/gpu/drm/mediatek/mtk_drm_drv.c +2
-0@@ -495,6 +504,18 @@ static int mtk_drm_kms_init(struct drm_device *drm)for (j =0 ; j < private->data->mmsys_dev_num; j++) { priv_n = private->all_drm_private[j]; +if (priv_n->data->max_pitch) { +/* Save 4 bytes for the color depth (pitch = width * bpp) */
drivers/gpu/drm/mediatek/mtk_drm_drv.c +1
-0+ drm->mode_config.max_width = priv_n-
Quoted 9 lines
Quoted 4 lines
Quoted 1 line
data->max_pitch>> 2;drivers/gpu/drm/mediatek/mtk_drm_drv.c +1
-0+ drm->mode_config.max_height = priv_n-Quoted 1 line
data->max_pitch>> 2;I think the term 'pitch' is for width not for height. And I think you should not divide height by 4. So I would like to have priv_n->data-
Quoted 1 line
max_height.
Got it. Will change another way to implement this part.
I'll remain the orginal logic that set the maximum width/height to 4096 and overwrite it only if the new value is defined in the driver data.
Regards,
Shawn
PATCH v5 6/13 drm/mediatek: Turn off the layers with zero width or height
In reply to Hsiao Chien SungWe found that IGT (Intel GPU Tool) will try to commit layers with zero width or height and lead to undefined behaviors in hardware. Disable the layers in such a situation.
--- drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c | 2 +- drivers/gpu/drm/mediatek/mtk_ethdr.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)
drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c +1 -1
@@ -157,7 +157,7 @@ void mtk_ovl_adaptor_layer_config(struct device *dev, unsigned int idx, merge = ovl_adaptor->ovl_adaptor_comp[OVL_ADAPTOR_MERGE0 + idx]; ethdr = ovl_adaptor->ovl_adaptor_comp[OVL_ADAPTOR_ETHDR0 ]; -if (!pending->enable) { +if (!pending->enable || !pending->width || !pending->height) {mtk_merge_stop_cmdq (merge, cmdq_pkt);mtk_mdp_rdma_stop (rdma_l, cmdq_pkt);mtk_mdp_rdma_stop (rdma_r, cmdq_pkt);
drivers/gpu/drm/mediatek/mtk_ethdr.c +6 -1
@@ -160,7 +160,12 @@ void mtk_ethdr_layer_config(struct device *dev, unsigned int idx,if (idx >=4 )return ; -if (!pending->enable) { +if (!pending->enable || !pending->width || !pending->height) { +/* +* instead of disabling layer with MIX_SRC_CON directly +* set the size to 0 to avoid screen shift due to mixer +* mode switch (hardware behavior) +*/ mtk_ddp_write (cmdq_pkt,0 , &mixer->cmdq_base, mixer->regs,MIX_L_SRC_SIZE (idx));return ; }
Signature · 1 line
2.18.0
Re: [PATCH v5 06/13] drm/mediatek: Turn off the layers with zero width or height
Il 15/02/24 11:11, Hsiao Chien Sung ha scritto:
Quoted 8 lines
We found that IGT (Intel GPU Tool) will try to commit layers with zero width or height and lead to undefined behaviors in hardware. Disable the layers in such a situation.
Fixes 777b7bc86a0a3 ("drm/mediatek: Add ovl_adaptor support for MT8195")Fixes fa97fe71f6f93 ("drm/mediatek: Add ETHDR support for MT8195")Signed-off-by Hsiao Chien Sung <[email protected]>
This commit should be sent separately from this series, as it is fixing things that are not related just to IGT, but also to corner cases in regular non-testing usecases.
In any case, it's not mandatory as that depends on what the maintainer prefers, so it's CK's call anyway.
Besides that,
Quoted 36 lines
--- drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c | 2 +- drivers/gpu/drm/mediatek/mtk_ethdr.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c +1
-1@@ -157,7 +157,7 @@ void mtk_ovl_adaptor_layer_config(struct device *dev, unsigned int idx, merge = ovl_adaptor->ovl_adaptor_comp[OVL_ADAPTOR_MERGE0 + idx]; ethdr = ovl_adaptor->ovl_adaptor_comp[OVL_ADAPTOR_ETHDR0 ]; -if (!pending->enable) { +if (!pending->enable || !pending->width || !pending->height) {mtk_merge_stop_cmdq (merge, cmdq_pkt);mtk_mdp_rdma_stop (rdma_l, cmdq_pkt);mtk_mdp_rdma_stop (rdma_r, cmdq_pkt);drivers/gpu/drm/mediatek/mtk_ethdr.c +6
-1@@ -160,7 +160,12 @@ void mtk_ethdr_layer_config(struct device *dev, unsigned int idx,if (idx >=4 )return ; -if (!pending->enable) { +if (!pending->enable || !pending->width || !pending->height) { +/* +* instead of disabling layer with MIX_SRC_CON directly +* set the size to 0 to avoid screen shift due to mixer +* mode switch (hardware behavior) +*/ mtk_ddp_write (cmdq_pkt,0 , &mixer->cmdq_base, mixer->regs,MIX_L_SRC_SIZE (idx));return ; }
Re: [PATCH v5 06/13] drm/mediatek: Turn off the layers with zero width or height
Quoted 17 lines · AngeloGioacchino Del Regno
Il 15/02/24 11:11, Hsiao Chien Sung ha scritto:
Quoted 9 lines
We found that IGT (Intel GPU Tool) will try to commit layers with zero width or height and lead to undefined behaviors in hardware. Disable the layers in such a situation.
Fixes 777b7bc86a0a3 ("drm/mediatek: Add ovl_adaptor support forMT8195")
Fixes fa97fe71f6f93 ("drm/mediatek: Add ETHDR support for MT8195")Signed-off-by Hsiao Chien Sung <[email protected]>This commit should be sent separately from this series, as it is fixing things
that are not related just to IGT, but also to corner cases in regular non-testing
usecases.
Quoted 8 lines
In any case, it's not mandatory as that depends on what the maintainer prefers,
so it's CK's call anyway.Besides that,
Reviewed-by: AngeloGioacchino Del Regno <
[email protected]>
Got it. Will discuss this with CK.
This bug is found when running IGT test while one of the test item commits a layer with zero width and cuase the device to freeze.
Re: [PATCH v5 06/13] drm/mediatek: Turn off the layers with zero width or height
In reply to Hsiao Chien SungHi, Hsiao-chien:
Quoted 3 lines · Hsiao Chien Sung
We found that IGT (Intel GPU Tool) will try to commit layers with zero width or height and lead to undefined behaviors in hardware. Disable the layers in such a situation.
I have reviewed ovl driver, ovl does not have this limitation, so it's better to point out which hardware has this limitation. That's OK if you have no information.
Regards,
CK
Quoted 48 lines
Fixes 777b7bc86a0a3 ("drm/mediatek: Add ovl_adaptor support forMT8195")
Fixes fa97fe71f6f93 ("drm/mediatek: Add ETHDR support for MT8195")Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c | 2 +- drivers/gpu/drm/mediatek/mtk_ethdr.c | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-)drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c +1
-1@@ -157,7 +157,7 @@ void mtk_ovl_adaptor_layer_config(struct device *dev, unsigned int idx, merge = ovl_adaptor->ovl_adaptor_comp[OVL_ADAPTOR_MERGE0 + idx]; ethdr = ovl_adaptor->ovl_adaptor_comp[OVL_ADAPTOR_ETHDR0 ]; -if (!pending->enable) { +if (!pending->enable || !pending->width || !pending->height) {mtk_merge_stop_cmdq (merge, cmdq_pkt);drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c +0
-0mtk_mdp_rdma_stop (rdma_l, cmdq_pkt);mtk_mdp_rdma_stop (rdma_r, cmdq_pkt);drivers/gpu/drm/mediatek/mtk_ethdr.c +6
-1@@ -160,7 +160,12 @@ void mtk_ethdr_layer_config(struct device *dev, unsigned int idx, if (idx >= 4) return; -if (!pending->enable) { +if (!pending->enable || !pending->width || !pending->height) { +/* +* instead of disabling layer with MIX_SRC_CON directly +* set the size to 0 to avoid screen shift due to mixer +* mode switch (hardware behavior) +*/ mtk_ddp_write (cmdq_pkt,0 , &mixer->cmdq_base, mixer- >regs, MIX_L_SRC_SIZE(idx));drivers/gpu/drm/mediatek/mtk_ethdr.c +0
-0return ; }
Re: [PATCH v5 06/13] drm/mediatek: Turn off the layers with zero width or height
Hi CK,
Quoted 7 lines · CK Hu (胡俊光)
Hi, Hsiao-chien:
Quoted 3 lines · Hsiao Chien Sung
We found that IGT (Intel GPU Tool) will try to commit layers with zero width or height and lead to undefined behaviors in hardware. Disable the layers in such a situation.
Quoted 7 lines
Reviewed-by CK Hu <[email protected]>I have reviewed ovl driver, ovl does not have this limitation, so it's
better to point out which hardware has this limitation. That's OK if you have no information.
Thank you for the confirmation. After checking with the designer, for MT8195/MT8188, the height setting in OVL can be 0 but width cannot, otherwise the hardware could hang. Although we are not sure if other old platforms have the same behavior.
Regards,
Shawn
PATCH v5 7/13 drm/mediatek: Support alpha blending in display driver
In reply to Hsiao Chien SungSupport "Pre-multiplied" and "None" blend mode on MediaTek's chips by adding correct blend mode property when the planes init. Before this patch, only the "Coverage" mode (default) is supported.
For more information, there are three pixel blend modes in DRM driver:
"None", "Pre-multiplied", and "Coverage".
To understand the difference between these modes, let's take a look at the following two approaches to do alpha blending:
1. Straight:
dst.RGB = src.RGB * src.A + dst.RGB * (1 - src.A)
This is straightforward and easy to understand, when the source layer is compositing with the destination layer, it's alpha will affect the result. This is also known as "post-multiplied", or "Coverage" mode.
2. Pre-multiplied:
dst.RGB = src.RGB + dst.RGB * (1 - src.A)
Since the source RGB have already multiplied its alpha, only destination RGB need to multiply it. This is the "Pre-multiplied" mode in DRM.
For the "None" blend mode in DRM, it means the pixel alpha is ignored when compositing the layers, only the constant alpha for the composited layer will take effects.
--- drivers/gpu/drm/mediatek/mtk_drm_plane.c | 11 +++++++++++ 1 file changed, 11 insertions(+)
drivers/gpu/drm/mediatek/mtk_drm_plane.c +11 -0
@@ -346,6 +346,17 @@ int mtk_plane_init(struct drm_device *dev, struct drm_plane *plane,DRM_INFO ("Create rotation property failed\n" ); } + err =drm_plane_create_alpha_property (plane); +if (err) +DRM_ERROR ("failed to create property: alpha\n" ); + + err =drm_plane_create_blend_mode_property (plane, +BIT (DRM_MODE_BLEND_PREMULTI ) | +BIT (DRM_MODE_BLEND_COVERAGE ) | +BIT (DRM_MODE_BLEND_PIXEL_NONE )); +if (err) +DRM_ERROR ("failed to create property: blend_mode\n" ); +drm_plane_helper_add (plane, &mtk_plane_helper_funcs);return 0 ;
Signature · 1 line
2.18.0
Re: [PATCH v5 07/13] drm/mediatek: Support alpha blending in display driver
Il 15/02/24 11:11, Hsiao Chien Sung ha scritto:
Quoted 21 lines
Support "Pre-multiplied" and "None" blend mode on MediaTek's chips by adding correct blend mode property when the planes init. Before this patch, only the "Coverage" mode (default) is supported.
For more information, there are three pixel blend modes in DRM driver:
"None", "Pre-multiplied", and "Coverage".To understand the difference between these modes, let's take a look at the following two approaches to do alpha blending:
1. Straight:
dst.RGB = src.RGB * src.A + dst.RGB * (1 - src.A)
This is straightforward and easy to understand, when the source layer is compositing with the destination layer, it's alpha will affect the result. This is also known as "post-multiplied", or "Coverage" mode.2. Pre-multiplied:
dst.RGB = src.RGB + dst.RGB * (1 - src.A)
Since the source RGB have already multiplied its alpha, only destination RGB need to multiply it. This is the "Pre-multiplied" mode in DRM.
Quoted 6 lines
For the "None" blend mode in DRM, it means the pixel alpha is ignored when compositing the layers, only the constant alpha for the composited layer will take effects.
Signed-off-by Hsiao Chien Sung <[email protected]>Reviewed-by CK Hu <[email protected]>
PATCH v5 8/13 drm/mediatek: Support alpha blending in OVL
In reply to Hsiao Chien SungSupport "Pre-multiplied" and "None" blend mode on MediaTek's chips. Before this patch, only the "Coverage" mode is supported.
Please refer to the description of the commit "drm/mediatek: Support alpha blending in display driver" for more information.
--- drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 83 +++++++++++++++++++++---- 1 file changed, 72 insertions(+), 11 deletions(-)
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +72 -11
@@ -39,6 +39,7 @@#define DISP_REG_OVL_PITCH_MSB (n) (0x0040 + 0x20 * (n))#define OVL_PITCH_MSB_2ND_SUBBUF BIT(16)#define DISP_REG_OVL_PITCH (n) (0x0044 + 0x20 * (n)) +#define OVL_CONST_BLEND BIT(28)#define DISP_REG_OVL_RDMA_CTRL (n) (0x00c0 + 0x20 * (n))#define DISP_REG_OVL_RDMA_GMC (n) (0x00c8 + 0x20 * (n))#define DISP_REG_OVL_ADDR_MT2701 0x0040
@@ -52,13 +53,16 @@#define GMC_THRESHOLD_HIGH ((1 << GMC_THRESHOLD_BITS) / 4)#define GMC_THRESHOLD_LOW ((1 << GMC_THRESHOLD_BITS) / 8) +#define OVL_CON_CLRFMT_MAN BIT(23)#define OVL_CON_BYTE_SWAP BIT(24) -#define OVL_CON_MTX_YUV_TO_RGB (6 << 16) +#define OVL_CON_RGB_SWAP BIT(25)#define OVL_CON_CLRFMT_RGB (1 << 12)#define OVL_CON_CLRFMT_RGBA8888 (2 << 12)#define OVL_CON_CLRFMT_ARGB8888 (3 << 12)#define OVL_CON_CLRFMT_UYVY (4 << 12)#define OVL_CON_CLRFMT_YUYV (5 << 12) +#define OVL_CON_MTX_YUV_TO_RGB (6 << 16) +#define OVL_CON_CLRFMT_PARGB8888 (OVL_CON_CLRFMT_ARGB8888 | OVL_CON_CLRFMT_MAN)#define OVL_CON_CLRFMT_RGB565 (ovl) ((ovl)->data->fmt_rgb565_is_0 ? \ 0 : OVL_CON_CLRFMT_RGB)#define OVL_CON_CLRFMT_RGB888 (ovl) ((ovl)->data->fmt_rgb565_is_0 ? \
@@ -72,6 +76,22 @@#define OVL_CON_VIRT_FLIP BIT(9)#define OVL_CON_HORZ_FLIP BIT(10) +static inline bool is_10bit_rgb (u32 fmt) +{ +switch (fmt) { +case DRM_FORMAT_XRGB2101010 : +case DRM_FORMAT_ARGB2101010 : +case DRM_FORMAT_RGBX1010102 : +case DRM_FORMAT_RGBA1010102 : +case DRM_FORMAT_XBGR2101010 : +case DRM_FORMAT_ABGR2101010 : +case DRM_FORMAT_BGRX1010102 : +case DRM_FORMAT_BGRA1010102 : +return true; + } +return false; +} +static const u32 mt8173_formats[] = {DRM_FORMAT_XRGB8888 ,DRM_FORMAT_ARGB8888 ,
@@ -89,12 +109,20 @@ static const u32 mt8173_formats[] = {static const u32 mt8195_formats[] = {DRM_FORMAT_XRGB8888 ,DRM_FORMAT_ARGB8888 , +DRM_FORMAT_XRGB2101010 ,DRM_FORMAT_ARGB2101010 ,DRM_FORMAT_BGRX8888 ,DRM_FORMAT_BGRA8888 , +DRM_FORMAT_BGRX1010102 ,DRM_FORMAT_BGRA1010102 ,DRM_FORMAT_ABGR8888 ,DRM_FORMAT_XBGR8888 , +DRM_FORMAT_XBGR2101010 , +DRM_FORMAT_ABGR2101010 , +DRM_FORMAT_RGBX8888 , +DRM_FORMAT_RGBA8888 , +DRM_FORMAT_RGBX1010102 , +DRM_FORMAT_RGBA1010102 ,DRM_FORMAT_RGB888 ,DRM_FORMAT_BGR888 ,DRM_FORMAT_RGB565 ,
@@ -254,9 +282,7 @@ static void mtk_ovl_set_bit_depth(struct device *dev, int idx, u32 format, reg =readl (ovl->regs +DISP_REG_OVL_CLRFMT_EXT ); reg &= ~OVL_CON_CLRFMT_BIT_DEPTH_MASK (idx); -if (format ==DRM_FORMAT_RGBA1010102 || - format ==DRM_FORMAT_BGRA1010102 || - format ==DRM_FORMAT_ARGB2101010 ) +if (is_10bit_rgb (format)) bit_depth =OVL_CON_CLRFMT_10_BIT ; reg |=OVL_CON_CLRFMT_BIT_DEPTH (bit_depth, idx);
@@ -274,7 +300,13 @@ void mtk_ovl_config(struct device *dev, unsigned int w,if (w !=0 && h !=0 )mtk_ddp_write_relaxed (cmdq_pkt, h <<16 | w, &ovl->cmdq_reg, ovl->regs,DISP_REG_OVL_ROI_SIZE ); -mtk_ddp_write_relaxed (cmdq_pkt,0x0 , &ovl->cmdq_reg, ovl->regs,DISP_REG_OVL_ROI_BGCLR ); + +/* +* The background color should be opaque black (ARGB), +* otherwise there will be no effect with alpha blend +*/ +mtk_ddp_write_relaxed (cmdq_pkt,0xff000000 , &ovl->cmdq_reg, + ovl->regs,DISP_REG_OVL_ROI_BGCLR );mtk_ddp_write (cmdq_pkt,0x1 , &ovl->cmdq_reg, ovl->regs,DISP_REG_OVL_RST );mtk_ddp_write (cmdq_pkt,0x0 , &ovl->cmdq_reg, ovl->regs,DISP_REG_OVL_RST );
@@ -352,7 +384,8 @@ void mtk_ovl_layer_off(struct device *dev, unsigned int idx, DISP_REG_OVL_RDMA_CTRL(idx)); } -static unsigned int ovl_fmt_convert (struct mtk_disp_ovl *ovl,unsigned int fmt) +static unsigned int ovl_fmt_convert (struct mtk_disp_ovl *ovl,unsigned int fmt, +unsigned int blend_mode) {/* The return value in switch "MEM_MODE_INPUT_FORMAT_XXX" * is defined in mediatek HW data sheet.
@@ -371,17 +404,37 @@ static unsigned int ovl_fmt_convert(struct mtk_disp_ovl *ovl, unsigned int fmt)return OVL_CON_CLRFMT_RGB888 (ovl) |OVL_CON_BYTE_SWAP ;case DRM_FORMAT_RGBX8888 :case DRM_FORMAT_RGBA8888 : +return blend_mode ==DRM_MODE_BLEND_COVERAGE ? +OVL_CON_CLRFMT_ARGB8888 : +OVL_CON_CLRFMT_PARGB8888 ; +case DRM_FORMAT_RGBX1010102 : +case DRM_FORMAT_RGBA1010102 :return OVL_CON_CLRFMT_ARGB8888 ;case DRM_FORMAT_BGRX8888 :case DRM_FORMAT_BGRA8888 : +return OVL_CON_BYTE_SWAP | + (blend_mode ==DRM_MODE_BLEND_COVERAGE ? +OVL_CON_CLRFMT_ARGB8888 : +OVL_CON_CLRFMT_PARGB8888 ); +case DRM_FORMAT_BGRX1010102 :case DRM_FORMAT_BGRA1010102 :return OVL_CON_CLRFMT_ARGB8888 |OVL_CON_BYTE_SWAP ;case DRM_FORMAT_XRGB8888 :case DRM_FORMAT_ARGB8888 : +return blend_mode ==DRM_MODE_BLEND_COVERAGE ? +OVL_CON_CLRFMT_RGBA8888 : +OVL_CON_CLRFMT_PARGB8888 ; +case DRM_FORMAT_XRGB2101010 :case DRM_FORMAT_ARGB2101010 :return OVL_CON_CLRFMT_RGBA8888 ;case DRM_FORMAT_XBGR8888 :case DRM_FORMAT_ABGR8888 : +return OVL_CON_RGB_SWAP | + (blend_mode ==DRM_MODE_BLEND_COVERAGE ? +OVL_CON_CLRFMT_RGBA8888 : +OVL_CON_CLRFMT_PARGB8888 ); +case DRM_FORMAT_XBGR2101010 : +case DRM_FORMAT_ABGR2101010 :return OVL_CON_CLRFMT_RGBA8888 |OVL_CON_BYTE_SWAP ;case DRM_FORMAT_UYVY :return OVL_CON_CLRFMT_UYVY |OVL_CON_MTX_YUV_TO_RGB ;
@@ -403,6 +456,8 @@ void mtk_ovl_layer_config(struct device *dev, unsigned int idx,unsigned int fmt = pending->format;unsigned int offset = (pending->y <<16 ) | pending->x;unsigned int src_size = (pending->height <<16 ) | pending->width; +unsigned int blend_mode = state->base.pixel_blend_mode; +unsigned int ignore_pixel_alpha =0 ;unsigned int con;bool is_afbc = pending->modifier !=DRM_FORMAT_MOD_LINEAR ;union overlay_pitch {
@@ -420,9 +475,15 @@ void mtk_ovl_layer_config(struct device *dev, unsigned int idx,return ; } - con =ovl_fmt_convert (ovl, fmt); -if (state->base.fb && state->base.fb->format->has_alpha) - con |=OVL_CON_AEN |OVL_CON_ALPHA ; + con =ovl_fmt_convert (ovl, fmt, blend_mode); +if (state->base.fb) { + con |=OVL_CON_AEN ; + con |= state->base.alpha &OVL_CON_ALPHA ; + } + +if (blend_mode ==DRM_MODE_BLEND_PIXEL_NONE || + (state->base.fb && !state->base.fb->format->has_alpha)) + ignore_pixel_alpha =OVL_CONST_BLEND ;if (pending->rotation &DRM_MODE_REFLECT_Y ) { con |=OVL_CON_VIRT_FLIP ;
@@ -439,8 +500,8 @@ void mtk_ovl_layer_config(struct device *dev, unsigned int idx,mtk_ddp_write_relaxed (cmdq_pkt, con, &ovl->cmdq_reg, ovl->regs,DISP_REG_OVL_CON (idx)); -mtk_ddp_write_relaxed (cmdq_pkt, overlay_pitch.split_pitch.lsb, &ovl->cmdq_reg, ovl->regs, -DISP_REG_OVL_PITCH (idx)); +mtk_ddp_write_relaxed (cmdq_pkt, overlay_pitch.split_pitch.lsb | ignore_pixel_alpha, + &ovl->cmdq_reg, ovl->regs,DISP_REG_OVL_PITCH (idx));mtk_ddp_write_relaxed (cmdq_pkt, src_size, &ovl->cmdq_reg, ovl->regs,DISP_REG_OVL_SRC_SIZE (idx)); mtk_ddp_write_relaxed(cmdq_pkt, offset, &ovl->cmdq_reg, ovl->regs,
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerRe: [PATCH v5 08/13] drm/mediatek: Support alpha blending in OVL
Il 15/02/24 11:11, Hsiao Chien Sung ha scritto:
Quoted 99 lines
Support "Pre-multiplied" and "None" blend mode on MediaTek's chips. Before this patch, only the "Coverage" mode is supported.
Please refer to the description of the commit "drm/mediatek: Support alpha blending in display driver" for more information.
Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 83 +++++++++++++++++++++---- 1 file changed, 72 insertions(+), 11 deletions(-)drivers/gpu/drm/mediatek/mtk_disp_ovl.c +30
-4@@ -39,6 +39,7 @@#define DISP_REG_OVL_PITCH_MSB (n) (0x0040 + 0x20 * (n))#define OVL_PITCH_MSB_2ND_SUBBUF BIT(16)#define DISP_REG_OVL_PITCH (n) (0x0044 + 0x20 * (n)) +#define OVL_CONST_BLEND BIT(28)#define DISP_REG_OVL_RDMA_CTRL (n) (0x00c0 + 0x20 * (n))#define DISP_REG_OVL_RDMA_GMC (n) (0x00c8 + 0x20 * (n))#define DISP_REG_OVL_ADDR_MT2701 0x0040@@ -52,13 +53,16 @@#define GMC_THRESHOLD_HIGH ((1 << GMC_THRESHOLD_BITS) / 4)#define GMC_THRESHOLD_LOW ((1 << GMC_THRESHOLD_BITS) / 8) +#define OVL_CON_CLRFMT_MAN BIT(23)#define OVL_CON_BYTE_SWAP BIT(24) -#define OVL_CON_MTX_YUV_TO_RGB (6 << 16) +#define OVL_CON_RGB_SWAP BIT(25)#define OVL_CON_CLRFMT_RGB (1 << 12)#define OVL_CON_CLRFMT_RGBA8888 (2 << 12)#define OVL_CON_CLRFMT_ARGB8888 (3 << 12)#define OVL_CON_CLRFMT_UYVY (4 << 12)#define OVL_CON_CLRFMT_YUYV (5 << 12) +#define OVL_CON_MTX_YUV_TO_RGB (6 << 16) +#define OVL_CON_CLRFMT_PARGB8888 (OVL_CON_CLRFMT_ARGB8888 | OVL_CON_CLRFMT_MAN)#define OVL_CON_CLRFMT_RGB565 (ovl) ((ovl)->data->fmt_rgb565_is_0 ? \ 0 : OVL_CON_CLRFMT_RGB)#define OVL_CON_CLRFMT_RGB888 (ovl) ((ovl)->data->fmt_rgb565_is_0 ? \@@ -72,6 +76,22 @@#define OVL_CON_VIRT_FLIP BIT(9)#define OVL_CON_HORZ_FLIP BIT(10) +static inline bool is_10bit_rgb (u32 fmt) +{ +switch (fmt) { +case DRM_FORMAT_XRGB2101010 : +case DRM_FORMAT_ARGB2101010 : +case DRM_FORMAT_RGBX1010102 : +case DRM_FORMAT_RGBA1010102 : +case DRM_FORMAT_XBGR2101010 : +case DRM_FORMAT_ABGR2101010 : +case DRM_FORMAT_BGRX1010102 : +case DRM_FORMAT_BGRA1010102 : +return true; + } +return false; +} +static const u32 mt8173_formats[] = {DRM_FORMAT_XRGB8888 ,DRM_FORMAT_ARGB8888 ,@@ -89,12 +109,20 @@ static const u32 mt8173_formats[] = {static const u32 mt8195_formats[] = {DRM_FORMAT_XRGB8888 ,DRM_FORMAT_ARGB8888 , +DRM_FORMAT_XRGB2101010 ,DRM_FORMAT_ARGB2101010 ,DRM_FORMAT_BGRX8888 ,DRM_FORMAT_BGRA8888 , +DRM_FORMAT_BGRX1010102 ,DRM_FORMAT_BGRA1010102 ,DRM_FORMAT_ABGR8888 ,DRM_FORMAT_XBGR8888 , +DRM_FORMAT_XBGR2101010 , +DRM_FORMAT_ABGR2101010 , +DRM_FORMAT_RGBX8888 , +DRM_FORMAT_RGBA8888 , +DRM_FORMAT_RGBX1010102 , +DRM_FORMAT_RGBA1010102 ,DRM_FORMAT_RGB888 ,DRM_FORMAT_BGR888 ,DRM_FORMAT_RGB565 ,@@ -254,9 +282,7 @@ static void mtk_ovl_set_bit_depth(struct device *dev, int idx, u32 format, reg =readl (ovl->regs +DISP_REG_OVL_CLRFMT_EXT ); reg &= ~OVL_CON_CLRFMT_BIT_DEPTH_MASK (idx); -if (format ==DRM_FORMAT_RGBA1010102 || - format ==DRM_FORMAT_BGRA1010102 || - format ==DRM_FORMAT_ARGB2101010 ) +if (is_10bit_rgb (format)) bit_depth =OVL_CON_CLRFMT_10_BIT ; reg |=OVL_CON_CLRFMT_BIT_DEPTH (bit_depth, idx);@@ -274,7 +300,13 @@ void mtk_ovl_config(struct device *dev, unsigned int w,if (w !=0 && h !=0 )
drivers/gpu/drm/mediatek/mtk_disp_ovl.c void mtk_ovl_config(struct device *dev, unsigned int w, · line 309
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +7
-1mtk_ddp_write_relaxed (cmdq_pkt, h <<16 | w, &ovl->cmdq_reg, ovl->regs,DISP_REG_OVL_ROI_SIZE ); -mtk_ddp_write_relaxed (cmdq_pkt,0x0 , &ovl->cmdq_reg, ovl->regs,DISP_REG_OVL_ROI_BGCLR ); + +/* +* The background color should be opaque black (ARGB), +* otherwise there will be no effect with alpha blend +*/ +mtk_ddp_write_relaxed (cmdq_pkt,0xff000000 , &ovl->cmdq_reg, + ovl->regs,DISP_REG_OVL_ROI_BGCLR );
Multiple (all of?) OVL color registers, like{L0-3,EL0-2}_YUV1BIT_COLOR(x), ROI_BGCLR, L{0-3}_CLR and others do follow this exact layout:
#define OVL_COLOR_ALPHA GENMASK(31, 24)
#define OVL_COLOR_GREEN GENMASK(23, 16)
#define OVL_COLOR_RED GENMASK(15, 8)
#define OVL_COLOR_BLUE GENMASK(7, 0)
...so we can define those as they're valid for multiple registers, and then we can use the definition instead of an apparently random value.
/*
* The background color should be opaque black (ARGB),
* otherwise there will be no effect with alpha blend */
mtk_ddp_write_relaxed(cmdq_pkt, OVL_COLOR_ALPHA, &ovl->cmdq_reg,
ovl->regs, DISP_REG_OVL_ROI_BGCLR);
Everything else looks ok.
Regards,
Angelo
Re: [PATCH v5 08/13] drm/mediatek: Support alpha blending in OVL
Hi Angelo,
Quoted 125 lines · AngeloGioacchino Del Regno
Il 15/02/24 11:11, Hsiao Chien Sung ha scritto:
Quoted 109 lines
Support "Pre-multiplied" and "None" blend mode on MediaTek's chips. Before this patch, only the "Coverage" mode is supported.
Please refer to the description of the commit "drm/mediatek: Support alpha blending in display driver" for more information.
Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 83 +++++++++++++++++++++---- 1 file changed, 72 insertions(+), 11 deletions(-)drivers/gpu/drm/mediatek/mtk_disp_ovl.c +1
-0@@ -39,6 +39,7 @@#define DISP_REG_OVL_PITCH_MSB (n) (0x0040 + 0x20 * (n))#define OVL_PITCH_MSB_2ND_SUBBUF BIT(16)#define DISP_REG_OVL_PITCH (n) (0x0044 + 0x20 * (n)) +#define OVL_CONST_BLEND BIT(28)#define DISP_REG_OVL_RDMA_CTRL (n) (0x00c0 + 0x20 * (n))#define DISP_REG_OVL_RDMA_GMC (n) (0x00c8 + 0x20 * (n))#define DISP_REG_OVL_ADDR_MT2701 0x0040drivers/gpu/drm/mediatek/mtk_disp_ovl.c +4
-1@@ -52,13 +53,16 @@#define GMC_THRESHOLD_HIGH ((1 << GMC_THRESHOLD_BITS) / 4)#define GMC_THRESHOLD_LOW ((1 << GMC_THRESHOLD_BITS) / 8) +#define OVL_CON_CLRFMT_MAN BIT(23)#define OVL_CON_BYTE_SWAP BIT(24) -#define OVL_CON_MTX_YUV_TO_RGB (6 << 16) +#define OVL_CON_RGB_SWAP BIT(25)#define OVL_CON_CLRFMT_RGB (1 << 12)#define OVL_CON_CLRFMT_RGBA8888 (2 << 12)#define OVL_CON_CLRFMT_ARGB8888 (3 << 12)#define OVL_CON_CLRFMT_UYVY (4 << 12)#define OVL_CON_CLRFMT_YUYV (5 << 12) +#define OVL_CON_MTX_YUV_TO_RGB (6 << 16) +#define OVL_CON_CLRFMT_PARGB8888 (OVL_CON_CLRFMT_ARGB8888 | OVL_CON_CLRFMT_MAN)#define OVL_CON_CLRFMT_RGB565 (ovl) ((ovl)->data- >fmt_rgb565_is_0 ? \0 :
OVL_CON_CLRFMT_RGB)
#defineOVL_CON_CLRFMT_RGB888(ovl)((ovl)->data-Quoted 1 line
fmt_rgb565_is_0? \drivers/gpu/drm/mediatek/mtk_disp_ovl.c +25
-3@@ -72,6 +76,22 @@#define OVL_CON_VIRT_FLIP BIT(9)#define OVL_CON_HORZ_FLIP BIT(10) +static inline bool is_10bit_rgb (u32 fmt) +{ +switch (fmt) { +case DRM_FORMAT_XRGB2101010 : +case DRM_FORMAT_ARGB2101010 : +case DRM_FORMAT_RGBX1010102 : +case DRM_FORMAT_RGBA1010102 : +case DRM_FORMAT_XBGR2101010 : +case DRM_FORMAT_ABGR2101010 : +case DRM_FORMAT_BGRX1010102 : +case DRM_FORMAT_BGRA1010102 : +return true; + } +return false; +} +static const u32 mt8173_formats[] = {DRM_FORMAT_XRGB8888 ,DRM_FORMAT_ARGB8888 ,@@ -89,12 +109,20 @@ static const u32 mt8173_formats[] = {static const u32 mt8195_formats[] = {DRM_FORMAT_XRGB8888 ,DRM_FORMAT_ARGB8888 , +DRM_FORMAT_XRGB2101010 ,DRM_FORMAT_ARGB2101010 ,DRM_FORMAT_BGRX8888 ,DRM_FORMAT_BGRA8888 , +DRM_FORMAT_BGRX1010102 ,DRM_FORMAT_BGRA1010102 ,DRM_FORMAT_ABGR8888 ,DRM_FORMAT_XBGR8888 , +DRM_FORMAT_XBGR2101010 , +DRM_FORMAT_ABGR2101010 , +DRM_FORMAT_RGBX8888 , +DRM_FORMAT_RGBA8888 , +DRM_FORMAT_RGBX1010102 , +DRM_FORMAT_RGBA1010102 ,DRM_FORMAT_RGB888 ,DRM_FORMAT_BGR888 ,DRM_FORMAT_RGB565 ,@@ -254,9 +282,7 @@ static void mtk_ovl_set_bit_depth(struct device *dev, int idx, u32 format, reg =readl (ovl->regs +DISP_REG_OVL_CLRFMT_EXT ); reg &= ~OVL_CON_CLRFMT_BIT_DEPTH_MASK (idx); -if (format ==DRM_FORMAT_RGBA1010102 || - format ==DRM_FORMAT_BGRA1010102 || - format ==DRM_FORMAT_ARGB2101010 ) +if (is_10bit_rgb (format)) bit_depth =OVL_CON_CLRFMT_10_BIT ;reg |= OVL_CON_CLRFMT_BIT_DEPTH(bit_depth, idx);drivers/gpu/drm/mediatek/mtk_disp_ovl.c +0
-0@@ -274,7 +300,13 @@ void mtk_ovl_config(struct device *dev, unsigned int w, if (w != 0 && h != 0) mtk_ddp_write_relaxed(cmdq_pkt, h << 16 | w, &ovl- >cmdq_reg, ovl->regs,drivers/gpu/drm/mediatek/mtk_disp_ovl.c void mtk_ovl_config(struct device *dev, · line 312
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +7
-1DISP_REG_OVL_ROI_SIZE); -mtk_ddp_write_relaxed (cmdq_pkt,0x0 , &ovl->cmdq_reg, ovl->regs, DISP_REG_OVL_ROI_BGCLR); + +/* +* The background color should be opaque black (ARGB), +* otherwise there will be no effect with alpha blend +*/ +mtk_ddp_write_relaxed (cmdq_pkt,0xff000000 , &ovl->cmdq_reg, + ovl->regs,DISP_REG_OVL_ROI_BGCLR );Multiple (all of?) OVL color registers, like{L0-3,EL0- 2}_YUV1BIT_COLOR(x),
ROI_BGCLR, L{0-3}_CLR and others do follow this exact layout:
Quoted 8 lines
#define
OVL_COLOR_ALPHAGENMASK(31, 24)
#defineOVL_COLOR_GREENGENMASK(23, 16)
#defineOVL_COLOR_REDGENMASK(15, 8)
#defineOVL_COLOR_BLUEGENMASK(7, 0)...so we can define those as they're valid for multiple registers, and then
we can use the definition instead of an apparently random value.
Got it. Will modify it in the next version.
Quoted 6 lines
/*
* The background color should be opaque black (ARGB),
* otherwise there will be no effect with alpha blend */
mtk_ddp_write_relaxed(cmdq_pkt,OVL_COLOR_ALPHA,&ovl->cmdq_reg,
Quoted 7 lines
ovl->regs, DISP_REG_OVL_ROI_BGCLR);Everything else looks ok.
Regards,
Angelo
Thanks,
Shawn
Re: [PATCH v5 08/13] drm/mediatek: Support alpha blending in OVL
In reply to Hsiao Chien SungHi, Hsiao-chien:
Quoted 6 lines · Hsiao Chien Sung
Support "Pre-multiplied" and "None" blend mode on MediaTek's chips. Before this patch, only the "Coverage" mode is supported.
Please refer to the description of the commit "drm/mediatek: Support alpha blending in display driver" for more information.
Separate this patch into pre-multiplied patch and none patch.
Regards,
CK
Quoted 218 lines
Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 83 +++++++++++++++++++++ ---- 1 file changed, 72 insertions(+), 11 deletions(-)drivers/gpu/drm/mediatek/mtk_disp_ovl.c +1
-0@@ -39,6 +39,7 @@#define DISP_REG_OVL_PITCH_MSB (n) (0x0040 + 0x20 * (n))#define OVL_PITCH_MSB_2ND_SUBBUF BIT(16)#define DISP_REG_OVL_PITCH (n) (0x0044 + 0x20 * (n)) +#define OVL_CONST_BLEND BIT(28)#define DISP_REG_OVL_RDMA_CTRL (n) (0x00c0 + 0x20 * (n))#define DISP_REG_OVL_RDMA_GMC (n) (0x00c8 + 0x20 * (n))#define
DISP_REG_OVL_ADDR_MT27010x0040drivers/gpu/drm/mediatek/mtk_disp_ovl.c +4
-1@@ -52,13 +53,16 @@#define GMC_THRESHOLD_HIGH ((1 << GMC_THRESHOLD_BITS) / 4)#define GMC_THRESHOLD_LOW ((1 << GMC_THRESHOLD_BITS) / 8) +#define OVL_CON_CLRFMT_MAN BIT(23)#define OVL_CON_BYTE_SWAP BIT(24) -#define OVL_CON_MTX_YUV_TO_RGB (6 << 16) +#define OVL_CON_RGB_SWAP BIT(25)#define OVL_CON_CLRFMT_RGB (1 << 12)#define OVL_CON_CLRFMT_RGBA8888 (2 << 12)#define OVL_CON_CLRFMT_ARGB8888 (3 << 12)#define OVL_CON_CLRFMT_UYVY (4 << 12)#define OVL_CON_CLRFMT_YUYV (5 << 12) +#define OVL_CON_MTX_YUV_TO_RGB (6 << 16) +#define OVL_CON_CLRFMT_PARGB8888 (OVL_CON_CLRFMT_ARGB8888 | OVL_CON_CLRFMT_MAN)#define OVL_CON_CLRFMT_RGB565 (ovl) ((ovl)->data->fmt_rgb565_is_0 ? \0 :
OVL_CON_CLRFMT_RGB)
#defineOVL_CON_CLRFMT_RGB888(ovl)((ovl)->data->fmt_rgb565_is_0 ?
\drivers/gpu/drm/mediatek/mtk_disp_ovl.c +25
-3@@ -72,6 +76,22 @@#define OVL_CON_VIRT_FLIP BIT(9)#define OVL_CON_HORZ_FLIP BIT(10) +static inline bool is_10bit_rgb (u32 fmt) +{ +switch (fmt) { +case DRM_FORMAT_XRGB2101010 : +case DRM_FORMAT_ARGB2101010 : +case DRM_FORMAT_RGBX1010102 : +case DRM_FORMAT_RGBA1010102 : +case DRM_FORMAT_XBGR2101010 : +case DRM_FORMAT_ABGR2101010 : +case DRM_FORMAT_BGRX1010102 : +case DRM_FORMAT_BGRA1010102 : +return true; + } +return false; +} +static const u32 mt8173_formats[] = {DRM_FORMAT_XRGB8888 ,DRM_FORMAT_ARGB8888 ,@@ -89,12 +109,20 @@ static const u32 mt8173_formats[] = {static const u32 mt8195_formats[] = {DRM_FORMAT_XRGB8888 ,DRM_FORMAT_ARGB8888 , +DRM_FORMAT_XRGB2101010 ,DRM_FORMAT_ARGB2101010 ,DRM_FORMAT_BGRX8888 ,DRM_FORMAT_BGRA8888 , +DRM_FORMAT_BGRX1010102 ,DRM_FORMAT_BGRA1010102 ,DRM_FORMAT_ABGR8888 ,DRM_FORMAT_XBGR8888 , +DRM_FORMAT_XBGR2101010 , +DRM_FORMAT_ABGR2101010 , +DRM_FORMAT_RGBX8888 , +DRM_FORMAT_RGBA8888 , +DRM_FORMAT_RGBX1010102 , +DRM_FORMAT_RGBA1010102 ,DRM_FORMAT_RGB888 ,DRM_FORMAT_BGR888 ,DRM_FORMAT_RGB565 ,@@ -254,9 +282,7 @@ static void mtk_ovl_set_bit_depth(struct device *dev, int idx, u32 format, reg =readl (ovl->regs +DISP_REG_OVL_CLRFMT_EXT ); reg &= ~OVL_CON_CLRFMT_BIT_DEPTH_MASK (idx); -if (format ==DRM_FORMAT_RGBA1010102 || - format ==DRM_FORMAT_BGRA1010102 || - format ==DRM_FORMAT_ARGB2101010 ) +if (is_10bit_rgb (format)) bit_depth =OVL_CON_CLRFMT_10_BIT ;drivers/gpu/drm/mediatek/mtk_disp_ovl.c +7
-1reg |=OVL_CON_CLRFMT_BIT_DEPTH (bit_depth, idx);@@ -274,7 +300,13 @@ void mtk_ovl_config(struct device *dev, unsigned int w, if (w != 0 && h != 0) mtk_ddp_write_relaxed(cmdq_pkt, h << 16 | w, &ovl- >cmdq_reg, ovl->regs, DISP_REG_OVL_ROI_SIZE); -mtk_ddp_write_relaxed (cmdq_pkt,0x0 , &ovl->cmdq_reg, ovl->regs, DISP_REG_OVL_ROI_BGCLR); + +/* +* The background color should be opaque black (ARGB), +* otherwise there will be no effect with alpha blend +*/ +mtk_ddp_write_relaxed (cmdq_pkt,0xff000000 , &ovl->cmdq_reg, + ovl->regs,DISP_REG_OVL_ROI_BGCLR );mtk_ddp_write(cmdq_pkt,
0x1,&ovl->cmdq_reg,ovl->regs,DISP_REG_OVL_RST);
mtk_ddp_write(cmdq_pkt,0x0,&ovl->cmdq_reg,ovl->regs,DISP_REG_OVL_RST);drivers/gpu/drm/mediatek/mtk_disp_ovl.c +2
-1@@ -352,7 +384,8 @@ void mtk_ovl_layer_off(struct device *dev,unsigned int idx, DISP_REG_OVL_RDMA_CTRL(idx)); } -static unsigned int ovl_fmt_convert(struct mtk_disp_ovl *ovl, unsigned int fmt) +static unsigned int ovl_fmt_convert (struct mtk_disp_ovl *ovl,unsigned int fmt, +unsigned int blend_mode){
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +20
-0/* The return value in switch "MEM_MODE_INPUT_FORMAT_XXX" * is defined in mediatek HW data sheet. @@ -371,17 +404,37 @@ static unsigned int ovl_fmt_convert(struct mtk_disp_ovl *ovl, unsigned int fmt) return OVL_CON_CLRFMT_RGB888(ovl) | OVL_CON_BYTE_SWAP;case DRM_FORMAT_RGBX8888 :case DRM_FORMAT_RGBA8888 : +return blend_mode ==DRM_MODE_BLEND_COVERAGE ? +OVL_CON_CLRFMT_ARGB8888 : +OVL_CON_CLRFMT_PARGB8888 ; +case DRM_FORMAT_RGBX1010102 : +case DRM_FORMAT_RGBA1010102 :return OVL_CON_CLRFMT_ARGB8888 ;case DRM_FORMAT_BGRX8888 :case DRM_FORMAT_BGRA8888 : +return OVL_CON_BYTE_SWAP | + (blend_mode ==DRM_MODE_BLEND_COVERAGE ? +OVL_CON_CLRFMT_ARGB8888 : +OVL_CON_CLRFMT_PARGB8888 ); +case DRM_FORMAT_BGRX1010102 :case DRM_FORMAT_BGRA1010102 :return OVL_CON_CLRFMT_ARGB8888 |OVL_CON_BYTE_SWAP ;case DRM_FORMAT_XRGB8888 :case DRM_FORMAT_ARGB8888 : +return blend_mode ==DRM_MODE_BLEND_COVERAGE ? +OVL_CON_CLRFMT_RGBA8888 : +OVL_CON_CLRFMT_PARGB8888 ; +case DRM_FORMAT_XRGB2101010 :case DRM_FORMAT_ARGB2101010 :return OVL_CON_CLRFMT_RGBA8888 ;case DRM_FORMAT_XBGR8888 :case DRM_FORMAT_ABGR8888 : +return OVL_CON_RGB_SWAP | + (blend_mode ==DRM_MODE_BLEND_COVERAGE ? +OVL_CON_CLRFMT_RGBA8888 : +OVL_CON_CLRFMT_PARGB8888 ); +case DRM_FORMAT_XBGR2101010 : +case DRM_FORMAT_ABGR2101010 :return OVL_CON_CLRFMT_RGBA8888 |OVL_CON_BYTE_SWAP ;case DRM_FORMAT_UYVY :drivers/gpu/drm/mediatek/mtk_disp_ovl.c +2
-0return OVL_CON_CLRFMT_UYVY |OVL_CON_MTX_YUV_TO_RGB ;@@ -403,6 +456,8 @@ void mtk_ovl_layer_config(struct device *dev,unsigned int idx, unsigned int fmt = pending->format;unsigned int offset = (pending->y <<16 ) | pending->x;unsigned int src_size = (pending->height <<16 ) | pending- >width; +unsigned int blend_mode = state->base.pixel_blend_mode; +unsigned int ignore_pixel_alpha =0 ;unsigned int con;drivers/gpu/drm/mediatek/mtk_disp_ovl.c +9
-3bool is_afbc = pending->modifier !=DRM_FORMAT_MOD_LINEAR ;union overlay_pitch {@@ -420,9 +475,15 @@ void mtk_ovl_layer_config(struct device *dev,unsigned int idx, return; } - con =ovl_fmt_convert (ovl, fmt); -if (state->base.fb && state->base.fb->format->has_alpha) - con |=OVL_CON_AEN |OVL_CON_ALPHA ; + con =ovl_fmt_convert (ovl, fmt, blend_mode); +if (state->base.fb) { + con |=OVL_CON_AEN ; + con |= state->base.alpha &OVL_CON_ALPHA ; + } + +if (blend_mode ==DRM_MODE_BLEND_PIXEL_NONE || + (state->base.fb && !state->base.fb->format->has_alpha)) + ignore_pixel_alpha =OVL_CONST_BLEND ;if (pending->rotation &DRM_MODE_REFLECT_Y ) {drivers/gpu/drm/mediatek/mtk_disp_ovl.c +2
-2con |=OVL_CON_VIRT_FLIP ;@@ -439,8 +500,8 @@ void mtk_ovl_layer_config(struct device *dev,unsigned int idx, mtk_ddp_write_relaxed(cmdq_pkt, con, &ovl->cmdq_reg, ovl->regs,DISP_REG_OVL_CON (idx )); -mtk_ddp_write_relaxed (cmdq_pkt, overlay_pitch.split_pitch.lsb, &ovl->cmdq_reg, ovl->regs, -DISP_REG_OVL_PITCH (idx)); + mtk_ddp_write_relaxed(cmdq_pkt, overlay_pitch.split_pitch.lsb | ignore_pixel_alpha, + &ovl->cmdq_reg, ovl->regs,
DISP_REG_OVL_PITCH(idx));
mtk_ddp_write_relaxed(cmdq_pkt,src_size,&ovl->cmdq_reg, ovl-Quoted 1 line
regs,
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +0
-0DISP_REG_OVL_SRC_SIZE(idx)); mtk_ddp_write_relaxed(cmdq_pkt, offset, &ovl->cmdq_reg, ovl-Quoted 1 line
regs,
PATCH v5 9/13 drm/mediatek: Support alpha blending in Mixer
In reply to Hsiao Chien SungSupport "Pre-multiplied" and "None" blend mode on MediaTek's chips. Before this patch, only the "Coverage" mode is supported.
Please refer to the description of the commit "drm/mediatek: Support alpha blending in display driver" for more information.
--- drivers/gpu/drm/mediatek/mtk_ethdr.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)
drivers/gpu/drm/mediatek/mtk_ethdr.c +19 -7
@@ -5,6 +5,7 @@#include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> +#include <drm/drm_blend.h> #include <linux/clk.h> #include <linux/component.h> #include <linux/of_device.h>
@@ -35,6 +36,7 @@#define MIX_SRC_L0_EN BIT(0)#define MIX_L_SRC_CON (n) (0x28 + 0x18 * (n))#define NON_PREMULTI_SOURCE (2 << 12) +#define PREMULTI_SOURCE (3 << 12)#define MIX_L_SRC_SIZE (n) (0x30 + 0x18 * (n))#define MIX_L_SRC_OFFSET (n) (0x34 + 0x18 * (n))#define MIX_FUNC_DCM0 0x120
@@ -153,7 +155,8 @@ void mtk_ethdr_layer_config(struct device *dev, unsigned int idx,struct mtk_plane_pending_state *pending = &state->pending;unsigned int offset = (pending->x &1 ) <<31 | pending->y <<16 | pending->x;unsigned int align_width =ALIGN_DOWN (pending->width,2 ); -unsigned int alpha_con =0 ; +unsigned int mix_con =NON_PREMULTI_SOURCE ; +bool replace_src_a = false;dev_dbg (dev,"%s+ idx:%d" , __func__, idx);
@@ -170,19 +173,28 @@ void mtk_ethdr_layer_config(struct device *dev, unsigned int idx,return ; } -if (state->base.fb && state->base.fb->format->has_alpha) - alpha_con =MIXER_ALPHA_AEN |MIXER_ALPHA ; + mix_con |=MIXER_ALPHA_AEN | (state->base.alpha &MIXER_ALPHA ); -mtk_mmsys_mixer_in_config (priv->mmsys_dev, idx +1 , alpha_con ? false : true, -DEFAULT_9BIT_ALPHA , +if (state->base.pixel_blend_mode !=DRM_MODE_BLEND_COVERAGE ) + mix_con |=PREMULTI_SOURCE ; + +if (state->base.pixel_blend_mode ==DRM_MODE_BLEND_PIXEL_NONE || + (state->base.fb && !state->base.fb->format->has_alpha)) { +/* +* Mixer doesn't support CONST_BLD mode, +* use a trick to make the output equivalent +*/ + replace_src_a = true; + } + +mtk_mmsys_mixer_in_config (priv->mmsys_dev, idx +1 , replace_src_a,MIXER_ALPHA , pending->x &1 ?MIXER_INX_MODE_EVEN_EXTEND :MIXER_INX_MODE_BYPASS , align_width /2 -1 , cmdq_pkt);mtk_ddp_write (cmdq_pkt, pending->height <<16 | align_width, &mixer->cmdq_base, mixer->regs,MIX_L_SRC_SIZE (idx));mtk_ddp_write (cmdq_pkt, offset, &mixer->cmdq_base, mixer->regs,MIX_L_SRC_OFFSET (idx)); -mtk_ddp_write_mask (cmdq_pkt, alpha_con, &mixer->cmdq_base, mixer->regs,MIX_L_SRC_CON (idx), -0x1ff ); +mtk_ddp_write (cmdq_pkt, mix_con, &mixer->cmdq_base, mixer->regs,MIX_L_SRC_CON (idx));mtk_ddp_write_mask (cmdq_pkt,BIT (idx), &mixer->cmdq_base, mixer->regs,MIX_SRC_CON ,BIT (idx)); }
Signature · 1 line
2.18.0
Re: [PATCH v5 09/13] drm/mediatek: Support alpha blending in Mixer
Hi, Hsiao-chien:
Quoted 6 lines · Hsiao Chien Sung
Support "Pre-multiplied" and "None" blend mode on MediaTek's chips. Before this patch, only the "Coverage" mode is supported.
Please refer to the description of the commit "drm/mediatek: Support alpha blending in display driver" for more information.
Separate this patch into pre-multiplied patch and none patch.
Regards,
CK
Quoted 85 lines
Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_ethdr.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-)drivers/gpu/drm/mediatek/mtk_ethdr.c +4
-1@@ -5,6 +5,7 @@#include <drm/drm_fourcc.h> #include <drm/drm_framebuffer.h> +#include <drm/drm_blend.h> #include <linux/clk.h> #include <linux/component.h> #include <linux/of_device.h> @@ -35,6 +36,7 @@#define MIX_SRC_L0_EN BIT(0)#define MIX_L_SRC_CON (n) (0x28 + 0x18 * (n))#define NON_PREMULTI_SOURCE (2 << 12) +#define PREMULTI_SOURCE (3 << 12)#define MIX_L_SRC_SIZE (n) (0x30 + 0x18 * (n))#define MIX_L_SRC_OFFSET (n) (0x34 + 0x18 * (n))#define MIX_FUNC_DCM0 0x120@@ -153,7 +155,8 @@ void mtk_ethdr_layer_config(struct device *dev,unsigned int idx, struct mtk_plane_pending_state *pending = &state->pending;unsigned int offset = (pending->x &1 ) <<31 | pending->y <<16 | pending->x;unsigned int align_width =ALIGN_DOWN (pending->width,2 ); -unsigned int alpha_con =0 ; +unsigned int mix_con =NON_PREMULTI_SOURCE ; +bool replace_src_a = false;drivers/gpu/drm/mediatek/mtk_ethdr.c +5
-4dev_dbg (dev,"%s+ idx:%d" , __func__, idx);@@ -170,19 +173,28 @@ void mtk_ethdr_layer_config(struct device *dev,unsigned int idx, return; } -if (state->base.fb && state->base.fb->format->has_alpha) - alpha_con =MIXER_ALPHA_AEN |MIXER_ALPHA ; + mix_con |=MIXER_ALPHA_AEN | (state->base.alpha &MIXER_ALPHA ); - mtk_mmsys_mixer_in_config(priv->mmsys_dev, idx + 1, alpha_con ? false : true, - DEFAULT_9BIT_ALPHA, +if (state->base.pixel_blend_mode !=DRM_MODE_BLEND_COVERAGE ) + mix_con |=PREMULTI_SOURCE ; + + if (state->base.pixel_blend_mode == DRM_MODE_BLEND_PIXEL_NONE||
drivers/gpu/drm/mediatek/mtk_ethdr.c +9
-0+ (state->base.fb && !state->base.fb->format->has_alpha)) { +/* +* Mixer doesn't support CONST_BLD mode, +* use a trick to make the output equivalent +*/ + replace_src_a = true; + } + + mtk_mmsys_mixer_in_config(priv->mmsys_dev, idx + 1,
replace_src_a,MIXER_ALPHA,
pending->x& 1 ?MIXER_INX_MODE_EVEN_EXTEND:
MIXER_INX_MODE_BYPASS,align_width/
2 - 1,cmdq_pkt);mtk_ddp_write(cmdq_pkt,
pending->height<< 16 |align_width,&mixer->cmdq_base,drivers/gpu/drm/mediatek/mtk_ethdr.c +0
-0mixer->regs, MIX_L_SRC_SIZE(idx)); mtk_ddp_write(cmdq_pkt, offset, &mixer->cmdq_base, mixer->regs,
MIX_L_SRC_OFFSET(idx));drivers/gpu/drm/mediatek/mtk_ethdr.c +0
-1- mtk_ddp_write_mask(cmdq_pkt, alpha_con, &mixer->cmdq_base,
mixer->regs,MIX_L_SRC_CON(idx),drivers/gpu/drm/mediatek/mtk_ethdr.c +1
-1- 0x1ff); + mtk_ddp_write(cmdq_pkt, mix_con, &mixer->cmdq_base, mixer-Quoted 1 line
regs,
MIX_L_SRC_CON(idx));mtk_ddp_write_mask(cmdq_pkt, BIT(idx),
&mixer->cmdq_base,mixer->regs,MIX_SRC_CON,
BIT(idx));
}
PATCH v5 10/13 drm/mediatek: Support CRC in display driver
In reply to Hsiao Chien SungRegister CRC related function pointers to support
CRC retrieval.
--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 239 ++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 39 ++++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 3 + 3 files changed, 281 insertions(+)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +239 -0
@@ -68,6 +68,9 @@ struct mtk_drm_crtc {/* lock for display hardware access */ struct mutex hw_lock;bool config_updating; + +struct mtk_ddp_comp *crc_provider; +unsigned int frames; };struct mtk_crtc_state {
@@ -635,6 +638,14 @@ static void mtk_crtc_ddp_irq(void *data)struct drm_crtc *crtc = data;struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc);struct mtk_drm_private *priv = crtc->dev->dev_private; +struct mtk_ddp_comp *comp = mtk_crtc->crc_provider; + +/* +* crc providers should make sure the crc is always correct +* by resetting it in .crc_read() +*/ +if (crtc->crc.opened) + comp->funcs->crc_read (comp->dev);#if IS_REACHABLE (CONFIG_MTK_CMDQ )if (!priv->data->shadow_register && !mtk_crtc->cmdq_client.chan)
@@ -646,6 +657,24 @@ static void mtk_crtc_ddp_irq(void *data)if (!priv->data->shadow_register)mtk_crtc_ddp_config (crtc,NULL );#endif + +/* +* drm_crtc_add_crc_entry() could take more than 50ms to finish +* put it at the end of the isr +*/ +if (crtc->crc.opened) { +/* +* skip the first crc because the first frame is configured by +* mtk_crtc_ddp_hw_init() when atomic enable +*/ +if (++mtk_crtc->frames >1 ) { +drm_crtc_add_crc_entry (crtc, true, +drm_crtc_vblank_count (crtc), + comp->funcs->crc_entry (comp->dev)); + } + }else { + mtk_crtc->frames =0 ; + }mtk_drm_finish_page_flip (mtk_crtc); }
@@ -704,6 +733,40 @@ static void mtk_drm_crtc_update_output(struct drm_crtc *crtc, } } +static int mtk_drm_crtc_set_crc_source (struct drm_crtc *crtc,const char *src) +{ +if (src &&strcmp (src,"auto" ) !=0 ) { +DRM_ERROR ("%s(crtc-%d): unknown source '%s'\n" , + __func__,drm_crtc_index (crtc), src); +return -EINVAL ; + } +return 0 ; +} + +static int mtk_drm_crtc_verify_crc_source (struct drm_crtc *crtc, +const char *src, +size_t *cnt) +{ +struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc); +struct mtk_ddp_comp *comp = mtk_crtc->crc_provider; + +if (!comp) { +DRM_ERROR ("%s(crtc-%d): no crc provider\n" , + __func__,drm_crtc_index (crtc)); +return -ENOENT ; + } + +if (src &&strcmp (src,"auto" ) !=0 ) { +DRM_ERROR ("%s(crtc-%d): unknown source '%s'\n" , + __func__,drm_crtc_index (crtc), src); +return -EINVAL ; + } + + *cnt = comp->funcs->crc_cnt (comp->dev); + +return 0 ; +} +int mtk_drm_crtc_plane_check (struct drm_crtc *crtc,struct drm_plane *plane,struct mtk_plane_state *state) {
@@ -841,6 +904,8 @@ static const struct drm_crtc_funcs mtk_crtc_funcs = { .atomic_destroy_state = mtk_drm_crtc_destroy_state, .enable_vblank = mtk_drm_crtc_enable_vblank, .disable_vblank = mtk_drm_crtc_disable_vblank, + .set_crc_source = mtk_drm_crtc_set_crc_source, + .verify_crc_source = mtk_drm_crtc_verify_crc_source, };static const struct drm_crtc_helper_funcs mtk_crtc_helper_funcs = {
@@ -1033,6 +1098,11 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,if (comp->funcs->ctm_set) has_ctm = true; + +if (comp->funcs->crc_cnt && + comp->funcs->crc_entry && + comp->funcs->crc_read) + mtk_crtc->crc_provider = comp; } mtk_ddp_comp_register_vblank_cb(comp, mtk_crtc_ddp_irq,
@@ -1137,3 +1207,172 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,return 0 ; } + +void mtk_drm_crc_init (struct mtk_drm_crc *crc, +const u32 *crc_offset_table,size_t crc_count, +u32 reset_offset,u32 reset_mask) +{ + crc->ofs = crc_offset_table; + crc->cnt = crc_count; + crc->rst_ofs = reset_offset; + crc->rst_msk = reset_mask; + crc->va =kcalloc (crc->cnt,sizeof (*crc->va),GFP_KERNEL ); +if (!crc->va) { +DRM_ERROR ("failed to allocate memory for crc\n" ); + crc->cnt =0 ; + } +} + +void mtk_drm_crc_read (struct mtk_drm_crc *crc,void __iomem *reg) +{ +if (!crc->cnt || !crc->ofs || !crc->va) +return ; + +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +/* sync to see the most up-to-date copy of the DMA buffer */ +dma_sync_single_for_cpu (crc->cmdq_client.chan->mbox->dev, + crc->pa, crc->cnt *sizeof (*crc->va), +DMA_FROM_DEVICE ); +#else +/* read crc with cpu for the platforms without cmdq */ + { +u32 n; + +for (n =0 ; n < crc->cnt; n++) + crc->va[n] =readl (reg + crc->ofs[n]); + + n =readl (reg + crc->rst_ofs); + +/* pull reset bit */ + n |= crc->rst_msk; +writel (n, reg + crc->rst_ofs); + +/* release reset bit */ + n &= ~crc->rst_msk; +writel (n, reg + crc->rst_ofs); + } +#endif +} + +void mtk_drm_crc_destroy (struct mtk_drm_crc *crc) +{ +if (!crc->cnt) +return ; + +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +if (crc->pa) { +dma_unmap_single (crc->cmdq_client.chan->mbox->dev, + crc->pa, crc->cnt *sizeof (*crc->va), +DMA_TO_DEVICE ); + crc->pa =0 ; + } +if (crc->cmdq_client.chan) { +mtk_drm_cmdq_pkt_destroy (&crc->cmdq_handle); +mbox_free_channel (crc->cmdq_client.chan); + crc->cmdq_client.chan =NULL ; + } +#endif +kfree (crc->va); + crc->va =NULL ; + crc->cnt =0 ; +} + +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +void mtk_drm_crc_cmdq_create (struct device *dev,struct mtk_drm_crc *crc) +{ +int i; + +if (!crc->cnt) { +dev_warn (dev,"%s: not support\n" , __func__); + goto cleanup; + } + +if (!crc->ofs) { +dev_warn (dev,"%s: not defined\n" , __func__); + goto cleanup; + } + + crc->cmdq_client.client.dev = dev; + crc->cmdq_client.client.tx_block = false; + crc->cmdq_client.client.knows_txdone = true; + crc->cmdq_client.client.rx_callback =NULL ; + crc->cmdq_client.chan =mbox_request_channel (&crc->cmdq_client.client,0 ); +if (IS_ERR (crc->cmdq_client.chan)) { +dev_warn (dev,"%s: failed to create mailbox client\n" , __func__); + crc->cmdq_client.chan =NULL ; + goto cleanup; + } + +if (mtk_drm_cmdq_pkt_create (&crc->cmdq_client, &crc->cmdq_handle,PAGE_SIZE )) { +dev_warn (dev,"%s: failed to create cmdq packet\n" , __func__); + goto cleanup; + } + +if (!crc->va) { +dev_warn (dev,"%s: no memory\n" , __func__); + goto cleanup; + } + +/* map the entry to get a dma address for cmdq to store the crc */ + crc->pa =dma_map_single (crc->cmdq_client.chan->mbox->dev, + crc->va, crc->cnt *sizeof (*crc->va), +DMA_FROM_DEVICE ); + +if (dma_mapping_error (crc->cmdq_client.chan->mbox->dev, crc->pa)) { +dev_err (dev,"%s: failed to map dma\n" , __func__); + goto cleanup; + } + +if (crc->cmdq_event) +cmdq_pkt_wfe (&crc->cmdq_handle, crc->cmdq_event, true); + +for (i =0 ; i < crc->cnt; i++) { +/* put crc to spr1 register */ +cmdq_pkt_read_s (&crc->cmdq_handle, crc->cmdq_reg->subsys, + crc->cmdq_reg->offset + crc->ofs[i], +CMDQ_THR_SPR_IDX1 ); + +/* copy spr1 register to physical address of the crc */ +cmdq_pkt_assign (&crc->cmdq_handle,CMDQ_THR_SPR_IDX0 , +CMDQ_ADDR_HIGH (crc->pa + i *sizeof (*crc->va))); +cmdq_pkt_write_s (&crc->cmdq_handle,CMDQ_THR_SPR_IDX0 , +CMDQ_ADDR_LOW (crc->pa + i *sizeof (*crc->va)), +CMDQ_THR_SPR_IDX1 ); + } +/* reset crc */ +mtk_ddp_write_mask (&crc->cmdq_handle, ~0 , crc->cmdq_reg,0 , + crc->rst_ofs, crc->rst_msk); + +/* clear reset bit */ +mtk_ddp_write_mask (&crc->cmdq_handle,0 , crc->cmdq_reg,0 , + crc->rst_ofs, crc->rst_msk); + +/* jump to head of the cmdq packet */ +cmdq_pkt_jump (&crc->cmdq_handle, crc->cmdq_handle.pa_base); + +return ; +cleanup: +mtk_drm_crc_destroy (crc); +} + +void mtk_drm_crc_cmdq_start (struct mtk_drm_crc *crc) +{ +if (!crc->cmdq_client.chan) +return ; + +dma_sync_single_for_device (crc->cmdq_client.chan->mbox->dev, + crc->cmdq_handle.pa_base, + crc->cmdq_handle.cmd_buf_size, +DMA_TO_DEVICE ); +mbox_send_message (crc->cmdq_client.chan, &crc->cmdq_handle); +mbox_client_txdone (crc->cmdq_client.chan,0 ); +} + +void mtk_drm_crc_cmdq_stop (struct mtk_drm_crc *crc) +{ +if (!crc->cmdq_client.chan) +return ; + +mbox_flush (crc->cmdq_client.chan,2000 ); +} +#endif
drivers/gpu/drm/mediatek/mtk_drm_crtc.h +39 -0
@@ -15,6 +15,45 @@#define MTK_MAX_BPC 10#define MTK_MIN_BPC 3 +/** +* struct mtk_drm_crc - crc related information +* @ofs: register offset of crc +* @rst_ofs: register offset of crc reset +* @rst_msk: register mask of crc reset +* @cnt: count of crc +* @va: pointer to the start of crc array +* @pa: physical address of the crc for gce to access +* @cmdq_event: the event to trigger the cmdq +* @cmdq_reg: address of the register that cmdq is going to access +* @cmdq_client: handler to control cmdq (mbox channel, thread ...etc.) +* @cmdq_handle: cmdq packet to store the commands +*/ +struct mtk_drm_crc { +const u32 *ofs; +u32 rst_ofs; +u32 rst_msk; +size_t cnt; +u32 *va; +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +dma_addr_t pa; +u32 cmdq_event; +struct cmdq_client_reg *cmdq_reg; +struct cmdq_client cmdq_client; +struct cmdq_pkt cmdq_handle; +#endif +}; + +void mtk_drm_crc_init (struct mtk_drm_crc *crc, +const u32 *crc_offset_table,size_t crc_count, +u32 reset_offset,u32 reset_mask); +void mtk_drm_crc_read (struct mtk_drm_crc *crc,void __iomem *reg); +void mtk_drm_crc_destroy (struct mtk_drm_crc *crc); +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +void mtk_drm_crc_cmdq_create (struct device *dev,struct mtk_drm_crc *crc); +void mtk_drm_crc_cmdq_start (struct mtk_drm_crc *crc); +void mtk_drm_crc_cmdq_stop (struct mtk_drm_crc *crc); +#endif +void mtk_drm_crtc_commit (struct drm_crtc *crtc); int mtk_drm_crtc_create(struct drm_device *drm_dev, const unsigned int *path,
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +3 -0
@@ -87,6 +87,9 @@ struct mtk_ddp_comp_funcs {void (*remove)(struct device *dev,struct mtk_mutex *mutex);unsigned int (*encoder_index)(struct device *dev);enum drm_mode_status (*mode_valid)(struct device *dev,const struct drm_display_mode *mode); +size_t (*crc_cnt)(struct device *dev); +u32 *(*crc_entry)(struct device *dev); +void (*crc_read)(struct device *dev); };struct mtk_ddp_comp {
Signature · 1 line
2.18.0
AngeloGioacchino Del Regno
maintainerRe: [PATCH v5 10/13] drm/mediatek: Support CRC in display driver
Il 15/02/24 11:11, Hsiao Chien Sung ha scritto:
Quoted 138 lines
Register CRC related function pointers to support
CRC retrieval.Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 239 ++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 39 ++++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 3 + 3 files changed, 281 insertions(+)drivers/gpu/drm/mediatek/mtk_drm_crtc.c +78
-0@@ -68,6 +68,9 @@ struct mtk_drm_crtc {/* lock for display hardware access */ struct mutex hw_lock;bool config_updating; + +struct mtk_ddp_comp *crc_provider; +unsigned int frames; };struct mtk_crtc_state {@@ -635,6 +638,14 @@ static void mtk_crtc_ddp_irq(void *data)struct drm_crtc *crtc = data;struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc);struct mtk_drm_private *priv = crtc->dev->dev_private; +struct mtk_ddp_comp *comp = mtk_crtc->crc_provider; + +/* +* crc providers should make sure the crc is always correct +* by resetting it in .crc_read() +*/ +if (crtc->crc.opened) + comp->funcs->crc_read (comp->dev);#if IS_REACHABLE (CONFIG_MTK_CMDQ )if (!priv->data->shadow_register && !mtk_crtc->cmdq_client.chan)@@ -646,6 +657,24 @@ static void mtk_crtc_ddp_irq(void *data)if (!priv->data->shadow_register)mtk_crtc_ddp_config (crtc,NULL );#endif + +/* +* drm_crtc_add_crc_entry() could take more than 50ms to finish +* put it at the end of the isr +*/ +if (crtc->crc.opened) { +/* +* skip the first crc because the first frame is configured by +* mtk_crtc_ddp_hw_init() when atomic enable +*/ +if (++mtk_crtc->frames >1 ) { +drm_crtc_add_crc_entry (crtc, true, +drm_crtc_vblank_count (crtc), + comp->funcs->crc_entry (comp->dev)); + } + }else { + mtk_crtc->frames =0 ; + }mtk_drm_finish_page_flip (mtk_crtc); }@@ -704,6 +733,40 @@ static void mtk_drm_crtc_update_output(struct drm_crtc *crtc, } } +static int mtk_drm_crtc_set_crc_source (struct drm_crtc *crtc,const char *src) +{ +if (src &&strcmp (src,"auto" ) !=0 ) { +DRM_ERROR ("%s(crtc-%d): unknown source '%s'\n" , + __func__,drm_crtc_index (crtc), src); +return -EINVAL ; + } +return 0 ; +} + +static int mtk_drm_crtc_verify_crc_source (struct drm_crtc *crtc, +const char *src, +size_t *cnt) +{ +struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc); +struct mtk_ddp_comp *comp = mtk_crtc->crc_provider; + +if (!comp) { +DRM_ERROR ("%s(crtc-%d): no crc provider\n" , + __func__,drm_crtc_index (crtc)); +return -ENOENT ; + } + +if (src &&strcmp (src,"auto" ) !=0 ) { +DRM_ERROR ("%s(crtc-%d): unknown source '%s'\n" , + __func__,drm_crtc_index (crtc), src); +return -EINVAL ; + } + + *cnt = comp->funcs->crc_cnt (comp->dev); + +return 0 ; +} +int mtk_drm_crtc_plane_check (struct drm_crtc *crtc,struct drm_plane *plane,struct mtk_plane_state *state) {@@ -841,6 +904,8 @@ static const struct drm_crtc_funcs mtk_crtc_funcs = { .atomic_destroy_state = mtk_drm_crtc_destroy_state, .enable_vblank = mtk_drm_crtc_enable_vblank, .disable_vblank = mtk_drm_crtc_disable_vblank, + .set_crc_source = mtk_drm_crtc_set_crc_source, + .verify_crc_source = mtk_drm_crtc_verify_crc_source, };static const struct drm_crtc_helper_funcs mtk_crtc_helper_funcs = {@@ -1033,6 +1098,11 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,if (comp->funcs->ctm_set) has_ctm = true; + +if (comp->funcs->crc_cnt && + comp->funcs->crc_entry && + comp->funcs->crc_read) + mtk_crtc->crc_provider = comp; } mtk_ddp_comp_register_vblank_cb(comp, mtk_crtc_ddp_irq,@@ -1137,3 +1207,172 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,return 0 ; } + +void mtk_drm_crc_init (struct mtk_drm_crc *crc, +const u32 *crc_offset_table,size_t crc_count, +u32 reset_offset,u32 reset_mask) +{ + crc->ofs = crc_offset_table; + crc->cnt = crc_count; + crc->rst_ofs = reset_offset;
drivers/gpu/drm/mediatek/mtk_drm_crtc.c int mtk_drm_crtc_create(struct drm_device *drm_dev, · line 1227
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +10
-0+ crc->rst_msk = reset_mask; + crc->va =kcalloc (crc->cnt,sizeof (*crc->va),GFP_KERNEL ); +if (!crc->va) { +DRM_ERROR ("failed to allocate memory for crc\n" ); + crc->cnt =0 ; + } +} + +void mtk_drm_crc_read (struct mtk_drm_crc *crc,void __iomem *reg) +{
u32 n; goes here
drivers/gpu/drm/mediatek/mtk_drm_crtc.c int mtk_drm_crtc_create(struct drm_device *drm_dev, · line 1238
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +11
-0+if (!crc->cnt || !crc->ofs || !crc->va) +return ; + +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +/* sync to see the most up-to-date copy of the DMA buffer */ +dma_sync_single_for_cpu (crc->cmdq_client.chan->mbox->dev, + crc->pa, crc->cnt *sizeof (*crc->va), +DMA_FROM_DEVICE ); +#else +/* read crc with cpu for the platforms without cmdq */ + {
then you don't need the braces.
Regards,
Angelo
Re: [PATCH v5 10/13] drm/mediatek: Support CRC in display driver
Hi Angelo,
Quoted 179 lines · AngeloGioacchino Del Regno
Il 15/02/24 11:11, Hsiao Chien Sung ha scritto:
Quoted 151 lines
Register CRC related function pointers to support
CRC retrieval.Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 239 ++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 39 ++++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 3 + 3 files changed, 281 insertions(+)drivers/gpu/drm/mediatek/mtk_drm_crtc.c +11
-0@@ -68,6 +68,9 @@ struct mtk_drm_crtc {/* lock for display hardware access */ struct mutex hw_lock;bool config_updating; + +struct mtk_ddp_comp *crc_provider; +unsigned int frames; };struct mtk_crtc_state {@@ -635,6 +638,14 @@ static void mtk_crtc_ddp_irq(void *data)struct drm_crtc *crtc = data;struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc);struct mtk_drm_private *priv = crtc->dev->dev_private; +struct mtk_ddp_comp *comp = mtk_crtc->crc_provider; + +/* +* crc providers should make sure the crc is always correct +* by resetting it in .crc_read() +*/ +if (crtc->crc.opened) + comp->funcs->crc_read (comp->dev);#if IS_REACHABLE (CONFIG_MTK_CMDQ ) if (!priv->data->shadow_register && !mtk_crtc-Quoted 1 line
cmdq_client.chan)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +8
-0@@ -646,6 +657,24 @@ static void mtk_crtc_ddp_irq(void *data)if (!priv->data->shadow_register)mtk_crtc_ddp_config (crtc,NULL );#endif + +/* +* drm_crtc_add_crc_entry() could take more than 50ms to finish +* put it at the end of the isr +*/ +if (crtc->crc.opened) { +/* +* skip the first crc because the first frame is configured by
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +5
-0+* mtk_crtc_ddp_hw_init() when atomic enable +*/ +if (++mtk_crtc->frames >1 ) { + drm_crtc_add_crc_entry(crtc, true, + drm_crtc_vblank_count(crtc),
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +1
-0+ comp->funcs-Quoted 1 line
crc_entry(comp->dev));drivers/gpu/drm/mediatek/mtk_drm_crtc.c +38
-0+ } + }else { + mtk_crtc->frames =0 ; + }mtk_drm_finish_page_flip (mtk_crtc); }@@ -704,6 +733,40 @@ static void mtk_drm_crtc_update_output(struct drm_crtc *crtc, } } +static int mtk_drm_crtc_set_crc_source (struct drm_crtc *crtc,const char *src) +{ +if (src &&strcmp (src,"auto" ) !=0 ) { +DRM_ERROR ("%s(crtc-%d): unknown source '%s'\n" , + __func__,drm_crtc_index (crtc), src); +return -EINVAL ; + } +return 0 ; +} + +static int mtk_drm_crtc_verify_crc_source (struct drm_crtc *crtc, +const char *src, +size_t *cnt) +{ +struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc); +struct mtk_ddp_comp *comp = mtk_crtc->crc_provider; + +if (!comp) { +DRM_ERROR ("%s(crtc-%d): no crc provider\n" , + __func__,drm_crtc_index (crtc)); +return -ENOENT ; + } + +if (src &&strcmp (src,"auto" ) !=0 ) { +DRM_ERROR ("%s(crtc-%d): unknown source '%s'\n" , + __func__,drm_crtc_index (crtc), src); +return -EINVAL ; + } + + *cnt = comp->funcs->crc_cnt (comp->dev); + +return 0 ; +} + int mtk_drm_crtc_plane_check(struct drm_crtc *crtc, struct
drm_plane*plane,
structmtk_plane_state*state)
{drivers/gpu/drm/mediatek/mtk_drm_crtc.c +2
-0@@ -841,6 +904,8 @@ static const struct drm_crtc_funcs mtk_crtc_funcs = { .atomic_destroy_state = mtk_drm_crtc_destroy_state, .enable_vblank = mtk_drm_crtc_enable_vblank, .disable_vblank = mtk_drm_crtc_disable_vblank, + .set_crc_source = mtk_drm_crtc_set_crc_source, + .verify_crc_source = mtk_drm_crtc_verify_crc_source, };static const struct
drm_crtc_helper_funcsmtk_crtc_helper_funcs=
{drivers/gpu/drm/mediatek/mtk_drm_crtc.c +5
-0@@ -1033,6 +1098,11 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev, if (comp->funcs->ctm_set) has_ctm = true; + +if (comp->funcs->crc_cnt && + comp->funcs->crc_entry && + comp->funcs->crc_read) + mtk_crtc->crc_provider = comp; }mtk_ddp_comp_register_vblank_cb(comp,
mtk_crtc_ddp_irq,drivers/gpu/drm/mediatek/mtk_drm_crtc.c +8
-0@@ -1137,3 +1207,172 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev, return 0; } + +void mtk_drm_crc_init (struct mtk_drm_crc *crc, +const u32 *crc_offset_table,size_t crc_count, +u32 reset_offset,u32 reset_mask) +{ + crc->ofs = crc_offset_table; + crc->cnt = crc_count; + crc->rst_ofs = reset_offset;drivers/gpu/drm/mediatek/mtk_drm_crtc.c int mtk_drm_crtc_create(struct drm_device · line 1227
Quoted 10 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +10
-0+ crc->rst_msk = reset_mask; + crc->va =kcalloc (crc->cnt,sizeof (*crc->va),GFP_KERNEL ); +if (!crc->va) { +DRM_ERROR ("failed to allocate memory for crc\n" ); + crc->cnt =0 ; + } +} + +void mtk_drm_crc_read (struct mtk_drm_crc *crc,void __iomem *reg) +{u32 n; goes here
drivers/gpu/drm/mediatek/mtk_drm_crtc.c int mtk_drm_crtc_create(struct drm_device *drm_dev, · line 1238
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +11
-0+if (!crc->cnt || !crc->ofs || !crc->va) +return ; + +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +/* sync to see the most up-to-date copy of the DMA buffer */ +dma_sync_single_for_cpu (crc->cmdq_client.chan->mbox->dev, + crc->pa, crc->cnt *sizeof (*crc->va), +DMA_FROM_DEVICE ); +#else +/* read crc with cpu for the platforms without cmdq */ + {then you don't need the braces.
Quoted 3 lines
Regards,
Angelo
The variable n is placed within the braces because when CONFIG_MTK_CMDQ is defined, the variable is not being used and causes a build error.
This is a workaround in order to have only one #if macro in that function for a more clean code.
Thanks,
Shawn
Re: [PATCH v5 10/13] drm/mediatek: Support CRC in display driver
In reply to Hsiao Chien SungQuoted 40 lines · Hsiao Chien Sung
Register CRC related function pointers to support
CRC retrieval.Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 239 ++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 39 ++++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 3 + 3 files changed, 281 insertions(+)drivers/gpu/drm/mediatek/mtk_drm_crtc.c +11
-0@@ -68,6 +68,9 @@ struct mtk_drm_crtc {/* lock for display hardware access */ struct mutex hw_lock;bool config_updating; + +struct mtk_ddp_comp *crc_provider; +unsigned int frames; };struct mtk_crtc_state {@@ -635,6 +638,14 @@ static void mtk_crtc_ddp_irq(void *data)struct drm_crtc *crtc = data;struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc);struct mtk_drm_private *priv = crtc->dev->dev_private; +struct mtk_ddp_comp *comp = mtk_crtc->crc_provider; + +/* +* crc providers should make sure the crc is always correct +* by resetting it in .crc_read() +*/ +if (crtc->crc.opened) + comp->funcs->crc_read (comp->dev);#if IS_REACHABLE (CONFIG_MTK_CMDQ )if (!priv->data->shadow_register && !mtk_crtc->cmdq_client.chan)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c static void mtk_crtc_ddp_irq(void *data) · line 664
Quoted 8 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +5
-0@@ -646,6 +657,24 @@ static void mtk_crtc_ddp_irq(void *data)if (!priv->data->shadow_register)mtk_crtc_ddp_config (crtc,NULL );#endif + +/* +* drm_crtc_add_crc_entry() could take more than 50ms to finish +* put it at the end of the isr +*/
Uh this looks really scary, especially since you put this before the call to drm_crtc_handle_vblank in the function below, which really shouldn't be unecessarily delayed (because that's the one that takes the vblank timestamp).
This sounds like the perfect application for a vblank worker though, so you please look into drm_vblank_work.h. And if that is not useable due to hardware constraint, then please explain in a comment here and in the commit message why you cannot use that and have to roll your own. vblank work really should be your first choice here, because:
- it's designed for expensive vblank work
- it gives you all the flush/cancel_sync functions you need for disabling crc again, and in a race-free implementation. Much better to use common code than to reinvent synchronization wheels in drivers :-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c static void mtk_crtc_ddp_irq(void *data) · line 665
Quoted 1 line
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +1
-0+if (crtc->crc.opened) {
Because this is probably not race-free, so we need something solid here.
Cheers, Sima
Quoted 317 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +222
-0+/* +* skip the first crc because the first frame is configured by +* mtk_crtc_ddp_hw_init() when atomic enable +*/ +if (++mtk_crtc->frames >1 ) { +drm_crtc_add_crc_entry (crtc, true, +drm_crtc_vblank_count (crtc), + comp->funcs->crc_entry (comp->dev)); + } + }else { + mtk_crtc->frames =0 ; + }mtk_drm_finish_page_flip (mtk_crtc); }@@ -704,6 +733,40 @@ static void mtk_drm_crtc_update_output(struct drm_crtc *crtc, } } +static int mtk_drm_crtc_set_crc_source (struct drm_crtc *crtc,const char *src) +{ +if (src &&strcmp (src,"auto" ) !=0 ) { +DRM_ERROR ("%s(crtc-%d): unknown source '%s'\n" , + __func__,drm_crtc_index (crtc), src); +return -EINVAL ; + } +return 0 ; +} + +static int mtk_drm_crtc_verify_crc_source (struct drm_crtc *crtc, +const char *src, +size_t *cnt) +{ +struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc); +struct mtk_ddp_comp *comp = mtk_crtc->crc_provider; + +if (!comp) { +DRM_ERROR ("%s(crtc-%d): no crc provider\n" , + __func__,drm_crtc_index (crtc)); +return -ENOENT ; + } + +if (src &&strcmp (src,"auto" ) !=0 ) { +DRM_ERROR ("%s(crtc-%d): unknown source '%s'\n" , + __func__,drm_crtc_index (crtc), src); +return -EINVAL ; + } + + *cnt = comp->funcs->crc_cnt (comp->dev); + +return 0 ; +} +int mtk_drm_crtc_plane_check (struct drm_crtc *crtc,struct drm_plane *plane,struct mtk_plane_state *state) {@@ -841,6 +904,8 @@ static const struct drm_crtc_funcs mtk_crtc_funcs = { .atomic_destroy_state = mtk_drm_crtc_destroy_state, .enable_vblank = mtk_drm_crtc_enable_vblank, .disable_vblank = mtk_drm_crtc_disable_vblank, + .set_crc_source = mtk_drm_crtc_set_crc_source, + .verify_crc_source = mtk_drm_crtc_verify_crc_source, };static const struct drm_crtc_helper_funcs mtk_crtc_helper_funcs = {@@ -1033,6 +1098,11 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,if (comp->funcs->ctm_set) has_ctm = true; + +if (comp->funcs->crc_cnt && + comp->funcs->crc_entry && + comp->funcs->crc_read) + mtk_crtc->crc_provider = comp; } mtk_ddp_comp_register_vblank_cb(comp, mtk_crtc_ddp_irq,@@ -1137,3 +1207,172 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,return 0 ; } + +void mtk_drm_crc_init (struct mtk_drm_crc *crc, +const u32 *crc_offset_table,size_t crc_count, +u32 reset_offset,u32 reset_mask) +{ + crc->ofs = crc_offset_table; + crc->cnt = crc_count; + crc->rst_ofs = reset_offset; + crc->rst_msk = reset_mask; + crc->va =kcalloc (crc->cnt,sizeof (*crc->va),GFP_KERNEL ); +if (!crc->va) { +DRM_ERROR ("failed to allocate memory for crc\n" ); + crc->cnt =0 ; + } +} + +void mtk_drm_crc_read (struct mtk_drm_crc *crc,void __iomem *reg) +{ +if (!crc->cnt || !crc->ofs || !crc->va) +return ; + +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +/* sync to see the most up-to-date copy of the DMA buffer */ +dma_sync_single_for_cpu (crc->cmdq_client.chan->mbox->dev, + crc->pa, crc->cnt *sizeof (*crc->va), +DMA_FROM_DEVICE ); +#else +/* read crc with cpu for the platforms without cmdq */ + { +u32 n; + +for (n =0 ; n < crc->cnt; n++) + crc->va[n] =readl (reg + crc->ofs[n]); + + n =readl (reg + crc->rst_ofs); + +/* pull reset bit */ + n |= crc->rst_msk; +writel (n, reg + crc->rst_ofs); + +/* release reset bit */ + n &= ~crc->rst_msk; +writel (n, reg + crc->rst_ofs); + } +#endif +} + +void mtk_drm_crc_destroy (struct mtk_drm_crc *crc) +{ +if (!crc->cnt) +return ; + +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +if (crc->pa) { +dma_unmap_single (crc->cmdq_client.chan->mbox->dev, + crc->pa, crc->cnt *sizeof (*crc->va), +DMA_TO_DEVICE ); + crc->pa =0 ; + } +if (crc->cmdq_client.chan) { +mtk_drm_cmdq_pkt_destroy (&crc->cmdq_handle); +mbox_free_channel (crc->cmdq_client.chan); + crc->cmdq_client.chan =NULL ; + } +#endif +kfree (crc->va); + crc->va =NULL ; + crc->cnt =0 ; +} + +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +void mtk_drm_crc_cmdq_create (struct device *dev,struct mtk_drm_crc *crc) +{ +int i; + +if (!crc->cnt) { +dev_warn (dev,"%s: not support\n" , __func__); + goto cleanup; + } + +if (!crc->ofs) { +dev_warn (dev,"%s: not defined\n" , __func__); + goto cleanup; + } + + crc->cmdq_client.client.dev = dev; + crc->cmdq_client.client.tx_block = false; + crc->cmdq_client.client.knows_txdone = true; + crc->cmdq_client.client.rx_callback =NULL ; + crc->cmdq_client.chan =mbox_request_channel (&crc->cmdq_client.client,0 ); +if (IS_ERR (crc->cmdq_client.chan)) { +dev_warn (dev,"%s: failed to create mailbox client\n" , __func__); + crc->cmdq_client.chan =NULL ; + goto cleanup; + } + +if (mtk_drm_cmdq_pkt_create (&crc->cmdq_client, &crc->cmdq_handle,PAGE_SIZE )) { +dev_warn (dev,"%s: failed to create cmdq packet\n" , __func__); + goto cleanup; + } + +if (!crc->va) { +dev_warn (dev,"%s: no memory\n" , __func__); + goto cleanup; + } + +/* map the entry to get a dma address for cmdq to store the crc */ + crc->pa =dma_map_single (crc->cmdq_client.chan->mbox->dev, + crc->va, crc->cnt *sizeof (*crc->va), +DMA_FROM_DEVICE ); + +if (dma_mapping_error (crc->cmdq_client.chan->mbox->dev, crc->pa)) { +dev_err (dev,"%s: failed to map dma\n" , __func__); + goto cleanup; + } + +if (crc->cmdq_event) +cmdq_pkt_wfe (&crc->cmdq_handle, crc->cmdq_event, true); + +for (i =0 ; i < crc->cnt; i++) { +/* put crc to spr1 register */ +cmdq_pkt_read_s (&crc->cmdq_handle, crc->cmdq_reg->subsys, + crc->cmdq_reg->offset + crc->ofs[i], +CMDQ_THR_SPR_IDX1 ); + +/* copy spr1 register to physical address of the crc */ +cmdq_pkt_assign (&crc->cmdq_handle,CMDQ_THR_SPR_IDX0 , +CMDQ_ADDR_HIGH (crc->pa + i *sizeof (*crc->va))); +cmdq_pkt_write_s (&crc->cmdq_handle,CMDQ_THR_SPR_IDX0 , +CMDQ_ADDR_LOW (crc->pa + i *sizeof (*crc->va)), +CMDQ_THR_SPR_IDX1 ); + } +/* reset crc */ +mtk_ddp_write_mask (&crc->cmdq_handle, ~0 , crc->cmdq_reg,0 , + crc->rst_ofs, crc->rst_msk); + +/* clear reset bit */ +mtk_ddp_write_mask (&crc->cmdq_handle,0 , crc->cmdq_reg,0 , + crc->rst_ofs, crc->rst_msk); + +/* jump to head of the cmdq packet */ +cmdq_pkt_jump (&crc->cmdq_handle, crc->cmdq_handle.pa_base); + +return ; +cleanup: +mtk_drm_crc_destroy (crc); +} + +void mtk_drm_crc_cmdq_start (struct mtk_drm_crc *crc) +{ +if (!crc->cmdq_client.chan) +return ; + +dma_sync_single_for_device (crc->cmdq_client.chan->mbox->dev, + crc->cmdq_handle.pa_base, + crc->cmdq_handle.cmd_buf_size, +DMA_TO_DEVICE ); +mbox_send_message (crc->cmdq_client.chan, &crc->cmdq_handle); +mbox_client_txdone (crc->cmdq_client.chan,0 ); +} + +void mtk_drm_crc_cmdq_stop (struct mtk_drm_crc *crc) +{ +if (!crc->cmdq_client.chan) +return ; + +mbox_flush (crc->cmdq_client.chan,2000 ); +} +#endif drivers/gpu/drm/mediatek/mtk_drm_crtc.h +39
-0@@ -15,6 +15,45 @@#define MTK_MAX_BPC 10#define MTK_MIN_BPC 3 +/** +* struct mtk_drm_crc - crc related information +* @ofs: register offset of crc +* @rst_ofs: register offset of crc reset +* @rst_msk: register mask of crc reset +* @cnt: count of crc +* @va: pointer to the start of crc array +* @pa: physical address of the crc for gce to access +* @cmdq_event: the event to trigger the cmdq +* @cmdq_reg: address of the register that cmdq is going to access +* @cmdq_client: handler to control cmdq (mbox channel, thread ...etc.) +* @cmdq_handle: cmdq packet to store the commands +*/ +struct mtk_drm_crc { +const u32 *ofs; +u32 rst_ofs; +u32 rst_msk; +size_t cnt; +u32 *va; +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +dma_addr_t pa; +u32 cmdq_event; +struct cmdq_client_reg *cmdq_reg; +struct cmdq_client cmdq_client; +struct cmdq_pkt cmdq_handle; +#endif +}; + +void mtk_drm_crc_init (struct mtk_drm_crc *crc, +const u32 *crc_offset_table,size_t crc_count, +u32 reset_offset,u32 reset_mask); +void mtk_drm_crc_read (struct mtk_drm_crc *crc,void __iomem *reg); +void mtk_drm_crc_destroy (struct mtk_drm_crc *crc); +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +void mtk_drm_crc_cmdq_create (struct device *dev,struct mtk_drm_crc *crc); +void mtk_drm_crc_cmdq_start (struct mtk_drm_crc *crc); +void mtk_drm_crc_cmdq_stop (struct mtk_drm_crc *crc); +#endif +void mtk_drm_crtc_commit (struct drm_crtc *crtc); int mtk_drm_crtc_create(struct drm_device *drm_dev, const unsigned int *path,drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +3
-0@@ -87,6 +87,9 @@ struct mtk_ddp_comp_funcs {void (*remove)(struct device *dev,struct mtk_mutex *mutex);unsigned int (*encoder_index)(struct device *dev);enum drm_mode_status (*mode_valid)(struct device *dev,const struct drm_display_mode *mode); +size_t (*crc_cnt)(struct device *dev); +u32 *(*crc_entry)(struct device *dev); +void (*crc_read)(struct device *dev); };struct mtk_ddp_comp {Signature · 1 line
2.18.0
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH v5 10/13] drm/mediatek: Support CRC in display driver
Quoted 65 lines · Daniel Vetter
Quoted 40 lines · Hsiao Chien Sung
Register CRC related function pointers to support
CRC retrieval.Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 239 ++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 39 ++++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 3 + 3 files changed, 281 insertions(+)drivers/gpu/drm/mediatek/mtk_drm_crtc.c +11
-0@@ -68,6 +68,9 @@ struct mtk_drm_crtc {/* lock for display hardware access */ struct mutex hw_lock;bool config_updating; + +struct mtk_ddp_comp *crc_provider; +unsigned int frames; };struct mtk_crtc_state {@@ -635,6 +638,14 @@ static void mtk_crtc_ddp_irq(void *data)struct drm_crtc *crtc = data;struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc);struct mtk_drm_private *priv = crtc->dev->dev_private; +struct mtk_ddp_comp *comp = mtk_crtc->crc_provider; + +/* +* crc providers should make sure the crc is always correct +* by resetting it in .crc_read() +*/ +if (crtc->crc.opened) + comp->funcs->crc_read (comp->dev);#if IS_REACHABLE (CONFIG_MTK_CMDQ )if (!priv->data->shadow_register && !mtk_crtc->cmdq_client.chan)drivers/gpu/drm/mediatek/mtk_drm_crtc.c static void mtk_crtc_ddp_irq(void *data) · line 664
Quoted 8 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +5
-0@@ -646,6 +657,24 @@ static void mtk_crtc_ddp_irq(void *data)if (!priv->data->shadow_register)mtk_crtc_ddp_config (crtc,NULL );#endif + +/* +* drm_crtc_add_crc_entry() could take more than 50ms to finish +* put it at the end of the isr +*/ Uh this looks really scary, especially since you put this before the call to
drm_crtc_handle_vblankin the function below, which really shouldn't be unecessarily delayed (because that's the one that takes the vblank timestamp).This sounds like the perfect application for a vblank worker though, so you please look into
drm_vblank_work.h. And if that is not useable due to hardware constraint, then please explain in a comment here and in the commit message why you cannot use that and have to roll your own. vblank work really should be your first choice here, because:
- it's designed for expensive vblank work
- it gives you all the flush/cancel_sync functions you need for disabling crc again, and in a race-free implementation. Much better to use common code than to reinvent synchronization wheels in drivers :-)
Quoted 3 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.c static void mtk_crtc_ddp_irq(void *data) · line 665
Quoted 1 line
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +1
-0+if (crtc->crc.opened) {Because this is probably not race-free, so we need something solid here.
Since it's maybe a bit tricky to see how to use drm_vblank_work:
- in your crtc initialization you also need to setup the crc work with drm_vblank_work_init().
- Your mtk_drm_crtc_set_sourc needs to actually enable the crc by calling drm_vblank_work_schedule for current vblank + 1, so that it immediately starts
- your vblank worker itself needs to again re-arm itself with drm_vblank_work_schedule, again for the very next vblank
- then your set_source also needs to handle the case where you disable the crc again (source == NULL) by calling drm_vblank_work_cancel_sync
- also you probably need to call drm_vblank_work_flush when shutting down the crtc, or you might have use-after-free issues on driver unload. Could probably also just put that in your crtc release function.
No changes to your interrupt handler needed, and also definitely no digging around in drm_crtc->crc data structure without locking - that's entirely internal to the common crc code and drivers must never look into it.
Cheers, Sima
Quoted 324 lines
Quoted 319 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +222
-0+/* +* skip the first crc because the first frame is configured by +* mtk_crtc_ddp_hw_init() when atomic enable +*/ +if (++mtk_crtc->frames >1 ) { +drm_crtc_add_crc_entry (crtc, true, +drm_crtc_vblank_count (crtc), + comp->funcs->crc_entry (comp->dev)); + } + }else { + mtk_crtc->frames =0 ; + }mtk_drm_finish_page_flip (mtk_crtc); }@@ -704,6 +733,40 @@ static void mtk_drm_crtc_update_output(struct drm_crtc *crtc, } } +static int mtk_drm_crtc_set_crc_source (struct drm_crtc *crtc,const char *src) +{ +if (src &&strcmp (src,"auto" ) !=0 ) { +DRM_ERROR ("%s(crtc-%d): unknown source '%s'\n" , + __func__,drm_crtc_index (crtc), src); +return -EINVAL ; + } +return 0 ; +} + +static int mtk_drm_crtc_verify_crc_source (struct drm_crtc *crtc, +const char *src, +size_t *cnt) +{ +struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc); +struct mtk_ddp_comp *comp = mtk_crtc->crc_provider; + +if (!comp) { +DRM_ERROR ("%s(crtc-%d): no crc provider\n" , + __func__,drm_crtc_index (crtc)); +return -ENOENT ; + } + +if (src &&strcmp (src,"auto" ) !=0 ) { +DRM_ERROR ("%s(crtc-%d): unknown source '%s'\n" , + __func__,drm_crtc_index (crtc), src); +return -EINVAL ; + } + + *cnt = comp->funcs->crc_cnt (comp->dev); + +return 0 ; +} +int mtk_drm_crtc_plane_check (struct drm_crtc *crtc,struct drm_plane *plane,struct mtk_plane_state *state) {@@ -841,6 +904,8 @@ static const struct drm_crtc_funcs mtk_crtc_funcs = { .atomic_destroy_state = mtk_drm_crtc_destroy_state, .enable_vblank = mtk_drm_crtc_enable_vblank, .disable_vblank = mtk_drm_crtc_disable_vblank, + .set_crc_source = mtk_drm_crtc_set_crc_source, + .verify_crc_source = mtk_drm_crtc_verify_crc_source, };static const struct drm_crtc_helper_funcs mtk_crtc_helper_funcs = {@@ -1033,6 +1098,11 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,if (comp->funcs->ctm_set) has_ctm = true; + +if (comp->funcs->crc_cnt && + comp->funcs->crc_entry && + comp->funcs->crc_read) + mtk_crtc->crc_provider = comp; } mtk_ddp_comp_register_vblank_cb(comp, mtk_crtc_ddp_irq,@@ -1137,3 +1207,172 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,return 0 ; } + +void mtk_drm_crc_init (struct mtk_drm_crc *crc, +const u32 *crc_offset_table,size_t crc_count, +u32 reset_offset,u32 reset_mask) +{ + crc->ofs = crc_offset_table; + crc->cnt = crc_count; + crc->rst_ofs = reset_offset; + crc->rst_msk = reset_mask; + crc->va =kcalloc (crc->cnt,sizeof (*crc->va),GFP_KERNEL ); +if (!crc->va) { +DRM_ERROR ("failed to allocate memory for crc\n" ); + crc->cnt =0 ; + } +} + +void mtk_drm_crc_read (struct mtk_drm_crc *crc,void __iomem *reg) +{ +if (!crc->cnt || !crc->ofs || !crc->va) +return ; + +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +/* sync to see the most up-to-date copy of the DMA buffer */ +dma_sync_single_for_cpu (crc->cmdq_client.chan->mbox->dev, + crc->pa, crc->cnt *sizeof (*crc->va), +DMA_FROM_DEVICE ); +#else +/* read crc with cpu for the platforms without cmdq */ + { +u32 n; + +for (n =0 ; n < crc->cnt; n++) + crc->va[n] =readl (reg + crc->ofs[n]); + + n =readl (reg + crc->rst_ofs); + +/* pull reset bit */ + n |= crc->rst_msk; +writel (n, reg + crc->rst_ofs); + +/* release reset bit */ + n &= ~crc->rst_msk; +writel (n, reg + crc->rst_ofs); + } +#endif +} + +void mtk_drm_crc_destroy (struct mtk_drm_crc *crc) +{ +if (!crc->cnt) +return ; + +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +if (crc->pa) { +dma_unmap_single (crc->cmdq_client.chan->mbox->dev, + crc->pa, crc->cnt *sizeof (*crc->va), +DMA_TO_DEVICE ); + crc->pa =0 ; + } +if (crc->cmdq_client.chan) { +mtk_drm_cmdq_pkt_destroy (&crc->cmdq_handle); +mbox_free_channel (crc->cmdq_client.chan); + crc->cmdq_client.chan =NULL ; + } +#endif +kfree (crc->va); + crc->va =NULL ; + crc->cnt =0 ; +} + +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +void mtk_drm_crc_cmdq_create (struct device *dev,struct mtk_drm_crc *crc) +{ +int i; + +if (!crc->cnt) { +dev_warn (dev,"%s: not support\n" , __func__); + goto cleanup; + } + +if (!crc->ofs) { +dev_warn (dev,"%s: not defined\n" , __func__); + goto cleanup; + } + + crc->cmdq_client.client.dev = dev; + crc->cmdq_client.client.tx_block = false; + crc->cmdq_client.client.knows_txdone = true; + crc->cmdq_client.client.rx_callback =NULL ; + crc->cmdq_client.chan =mbox_request_channel (&crc->cmdq_client.client,0 ); +if (IS_ERR (crc->cmdq_client.chan)) { +dev_warn (dev,"%s: failed to create mailbox client\n" , __func__); + crc->cmdq_client.chan =NULL ; + goto cleanup; + } + +if (mtk_drm_cmdq_pkt_create (&crc->cmdq_client, &crc->cmdq_handle,PAGE_SIZE )) { +dev_warn (dev,"%s: failed to create cmdq packet\n" , __func__); + goto cleanup; + } + +if (!crc->va) { +dev_warn (dev,"%s: no memory\n" , __func__); + goto cleanup; + } + +/* map the entry to get a dma address for cmdq to store the crc */ + crc->pa =dma_map_single (crc->cmdq_client.chan->mbox->dev, + crc->va, crc->cnt *sizeof (*crc->va), +DMA_FROM_DEVICE ); + +if (dma_mapping_error (crc->cmdq_client.chan->mbox->dev, crc->pa)) { +dev_err (dev,"%s: failed to map dma\n" , __func__); + goto cleanup; + } + +if (crc->cmdq_event) +cmdq_pkt_wfe (&crc->cmdq_handle, crc->cmdq_event, true); + +for (i =0 ; i < crc->cnt; i++) { +/* put crc to spr1 register */ +cmdq_pkt_read_s (&crc->cmdq_handle, crc->cmdq_reg->subsys, + crc->cmdq_reg->offset + crc->ofs[i], +CMDQ_THR_SPR_IDX1 ); + +/* copy spr1 register to physical address of the crc */ +cmdq_pkt_assign (&crc->cmdq_handle,CMDQ_THR_SPR_IDX0 , +CMDQ_ADDR_HIGH (crc->pa + i *sizeof (*crc->va))); +cmdq_pkt_write_s (&crc->cmdq_handle,CMDQ_THR_SPR_IDX0 , +CMDQ_ADDR_LOW (crc->pa + i *sizeof (*crc->va)), +CMDQ_THR_SPR_IDX1 ); + } +/* reset crc */ +mtk_ddp_write_mask (&crc->cmdq_handle, ~0 , crc->cmdq_reg,0 , + crc->rst_ofs, crc->rst_msk); + +/* clear reset bit */ +mtk_ddp_write_mask (&crc->cmdq_handle,0 , crc->cmdq_reg,0 , + crc->rst_ofs, crc->rst_msk); + +/* jump to head of the cmdq packet */ +cmdq_pkt_jump (&crc->cmdq_handle, crc->cmdq_handle.pa_base); + +return ; +cleanup: +mtk_drm_crc_destroy (crc); +} + +void mtk_drm_crc_cmdq_start (struct mtk_drm_crc *crc) +{ +if (!crc->cmdq_client.chan) +return ; + +dma_sync_single_for_device (crc->cmdq_client.chan->mbox->dev, + crc->cmdq_handle.pa_base, + crc->cmdq_handle.cmd_buf_size, +DMA_TO_DEVICE ); +mbox_send_message (crc->cmdq_client.chan, &crc->cmdq_handle); +mbox_client_txdone (crc->cmdq_client.chan,0 ); +} + +void mtk_drm_crc_cmdq_stop (struct mtk_drm_crc *crc) +{ +if (!crc->cmdq_client.chan) +return ; + +mbox_flush (crc->cmdq_client.chan,2000 ); +} +#endif drivers/gpu/drm/mediatek/mtk_drm_crtc.h +39
-0@@ -15,6 +15,45 @@#define MTK_MAX_BPC 10#define MTK_MIN_BPC 3 +/** +* struct mtk_drm_crc - crc related information +* @ofs: register offset of crc +* @rst_ofs: register offset of crc reset +* @rst_msk: register mask of crc reset +* @cnt: count of crc +* @va: pointer to the start of crc array +* @pa: physical address of the crc for gce to access +* @cmdq_event: the event to trigger the cmdq +* @cmdq_reg: address of the register that cmdq is going to access +* @cmdq_client: handler to control cmdq (mbox channel, thread ...etc.) +* @cmdq_handle: cmdq packet to store the commands +*/ +struct mtk_drm_crc { +const u32 *ofs; +u32 rst_ofs; +u32 rst_msk; +size_t cnt; +u32 *va; +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +dma_addr_t pa; +u32 cmdq_event; +struct cmdq_client_reg *cmdq_reg; +struct cmdq_client cmdq_client; +struct cmdq_pkt cmdq_handle; +#endif +}; + +void mtk_drm_crc_init (struct mtk_drm_crc *crc, +const u32 *crc_offset_table,size_t crc_count, +u32 reset_offset,u32 reset_mask); +void mtk_drm_crc_read (struct mtk_drm_crc *crc,void __iomem *reg); +void mtk_drm_crc_destroy (struct mtk_drm_crc *crc); +#if IS_REACHABLE (CONFIG_MTK_CMDQ ) +void mtk_drm_crc_cmdq_create (struct device *dev,struct mtk_drm_crc *crc); +void mtk_drm_crc_cmdq_start (struct mtk_drm_crc *crc); +void mtk_drm_crc_cmdq_stop (struct mtk_drm_crc *crc); +#endif +void mtk_drm_crtc_commit (struct drm_crtc *crtc); int mtk_drm_crtc_create(struct drm_device *drm_dev, const unsigned int *path,drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +3
-0@@ -87,6 +87,9 @@ struct mtk_ddp_comp_funcs {void (*remove)(struct device *dev,struct mtk_mutex *mutex);unsigned int (*encoder_index)(struct device *dev);enum drm_mode_status (*mode_valid)(struct device *dev,const struct drm_display_mode *mode); +size_t (*crc_cnt)(struct device *dev); +u32 *(*crc_entry)(struct device *dev); +void (*crc_read)(struct device *dev); };struct mtk_ddp_comp {Signature · 1 line
2.18.0Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH v5 10/13] drm/mediatek: Support CRC in display driver
Hi Daniel,
Quoted 104 lines · Daniel Vetter
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 7 lines · Daniel Vetter
Quoted 6 lines · Hsiao Chien Sung
Register CRC related function pointers to support
CRC retrieval.Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 239++++++++++++++++++++
Quoted 5 lines
Review
Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 39 ++++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 3 + 3 files changed, 281 insertions(+)(quoted diff) +0
-0
b/drivers/gpu/drm/mediatek/mtk_drm_crtc.cQuoted 26 lines
Quoted 26 lines
index
14cf75fa217f9..6cb1ed419dee7100644drivers/gpu/drm/mediatek/mtk_drm_crtc.c +11
-0@@ -68,6 +68,9 @@ struct mtk_drm_crtc {/* lock for display hardware access */ struct mutexhw_lock ; boolconfig_updating; + +struct mtk_ddp_comp *crc_provider; +unsigned intframes; };struct mtk_crtc_state {@@ -635,6 +638,14 @@ static void mtk_crtc_ddp_irq(void *data)struct drm_crtc *crtc = data;struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc);struct mtk_drm_private *priv = crtc->dev->dev_private; +struct mtk_ddp_comp *comp = mtk_crtc->crc_provider; + +/* +* crc providers should make sure the crc is always correct +* by resetting it in .crc_read() +*/ +if (crtc->crc.opened) +comp->funcs->crc_read (comp->dev);Quoted 13 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.c static void mtk_crtc_ddp_irq(void *data) · line 664
Quoted 11 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +5
-0#if IS_REACHABLE (CONFIG_MTK_CMDQ )if (!priv->data->shadow_register && !mtk_crtc->cmdq_client.chan)@@ -646,6 +657,24 @@ static void mtk_crtc_ddp_irq(void *data)if (!priv->data->shadow_register)mtk_crtc_ddp_config (crtc,NULL );#endif + +/* +* drm_crtc_add_crc_entry() could take more than 50ms to finish +* put it at the end of the isr +*/ Uh this looks really scary, especially since you put this before
the call
Quoted 1 line
to
drm_crtc_handle_vblankin the function below, which reallyshouldn't be
Quoted 4 lines
unecessarily delayed (because that's the one that takes the vblank timestamp).
This sounds like the perfect application for a vblank worker
though, so
Quoted 1 line
you please look into
drm_vblank_work.h. And if that is not useabledue to
Quoted 1 line
hardware constraint, then please explain in a comment here and in
the
Quoted 1 line
commit message why you cannot use that and have to roll your own.
vblank
Quoted 3 lines
work really should be your first choice here, because:
- it's designed for expensive vblank work
- it gives you all the flush/cancel_sync functions you need fordisabling
Quoted 1 line
crc again, and in a race-free implementation. Much better to use
common
Quoted 5 lines
code than to reinvent synchronization wheels in drivers :-)
drivers/gpu/drm/mediatek/mtk_drm_crtc.c static void mtk_crtc_ddp_irq(void *data) · line 665
Quoted 1 line
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +1
-0+if (crtc->crc.opened) {Because this is probably not race-free, so we need something solid
here.
Since it's maybe a bit tricky to see how to use
drm_vblank_work:- in your crtc initialization you also need to setup the crc work with
drm_vblank_work_init().
- Yourmtk_drm_crtc_set_sourcneeds to actually enable the crc by calling
drm_vblank_work_schedulefor current vblank + 1, so that it
immediately
starts
- your vblank worker itself needs to again re-arm itself withdrm_vblank_work_schedule, again for the very next vblank
- then yourset_sourcealso needs to handle the case where you disable the
crc again (source == NULL) by callingdrm_vblank_work_cancel_sync
- also you probably need to calldrm_vblank_work_flushwhen shutting down
the crtc, or you might have use-after-free issues on driver unload. Could probably also just put that in your crtc release function.
Quoted 6 lines
No changes to your interrupt handler needed, and also definitely no digging around in
drm_crtc->crcdata structure without locking - that's
entirely internal to the common crc code and drivers must never look into it.
I am deeply appreciative for the information you have shared. Will try to implement it with DRM_vblank_work APIs.
Sincerely,
Shawn
Re: [PATCH v5 10/13] drm/mediatek: Support CRC in display driver
In reply to Daniel VetterHi Daniel,
Quoted 53 lines · Daniel Vetter
External email : Please do not click links or open attachments until you have verified the sender or the content.
Quoted 6 lines · Hsiao Chien Sung
Register CRC related function pointers to support
CRC retrieval.Signed-off-by Hsiao Chien Sung <[email protected]>--- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 239++++++++++++++++++++
Review
Quoted 5 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.h | 39 ++++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 3 + 3 files changed, 281 insertions(+)(quoted diff) +0
-0
b/drivers/gpu/drm/mediatek/mtk_drm_crtc.cQuoted 36 lines
index
14cf75fa217f9..6cb1ed419dee7100644drivers/gpu/drm/mediatek/mtk_drm_crtc.c +15
-0@@ -68,6 +68,9 @@ struct mtk_drm_crtc {/* lock for display hardware access */ struct mutexhw_lock ; boolconfig_updating; + +struct mtk_ddp_comp *crc_provider; +unsigned intframes; };struct mtk_crtc_state {@@ -635,6 +638,14 @@ static void mtk_crtc_ddp_irq(void *data)struct drm_crtc *crtc = data;struct mtk_drm_crtc *mtk_crtc =to_mtk_crtc (crtc);struct mtk_drm_private *priv = crtc->dev->dev_private; +struct mtk_ddp_comp *comp = mtk_crtc->crc_provider; + +/* +* crc providers should make sure the crc is always correct +* by resetting it in .crc_read() +*/ +if (crtc->crc.opened) +comp->funcs->crc_read (comp->dev);#if IS_REACHABLE (CONFIG_MTK_CMDQ )if (!priv->data->shadow_register && !mtk_crtc->cmdq_client.chan)@@ -646,6 +657,24 @@ static void mtk_crtc_ddp_irq(void *data)if (!priv->data->shadow_register)mtk_crtc_ddp_config (crtc,NULL );#endif + +/* +* drm_crtc_add_crc_entry() could take more than 50ms to finish +* put it at the end of the isr
Quoted 8 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.c static void mtk_crtc_ddp_irq(void *data) · line 664
Quoted 1 line
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +1
-0+*/ Uh this looks really scary, especially since you put this before the call
todrm_crtc_handle_vblankin the function below, which really shouldn't be
unecessarily delayed (because that's the one that takes the vblank timestamp).
Thank you for pointing this out. This kind of expensive works should be deferred to the bottom halve instead of in the interrupt context. This is indeed an issue that was originally to be solved in a future version, but since it may take some time to adjust the flow and verifiy it, I fixed other minor issues and pushed this version so the reviewers could check it first. Will resolve this problem in the next version.
Quoted 16 lines
This sounds like the perfect application for a vblank worker though, so
you please look intodrm_vblank_work.h. And if that is not useable due to
hardware constraint, then please explain in a comment here and in the commit message why you cannot use that and have to roll your own. vblank
work really should be your first choice here, because:
- it's designed for expensive vblank work
- it gives you all the flush/cancel_sync functions you need for disabling
crc again, and in a race-free implementation. Much better to use
common
code than to reinvent synchronization wheels in drivers :-)
Quoted 4 lines
drivers/gpu/drm/mediatek/mtk_drm_crtc.c static void mtk_crtc_ddp_irq(void *data) · line 665
Quoted 1 line
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +1
-0+if (crtc->crc.opened) {Because this is probably not race-free, so we need something solid here.
Thank you very much for the hint :)
Didn't know there is such a useful
tool in DRM.
Will try to integrate the CRC function withdrm_vblank_work.
Cheers, Sima
Quoted 1 line
PATCH v5 11/13 drm/mediatek: Support CRC in OVL
In reply to Hsiao Chien SungWe choose OVL as the CRC generator from other hardware components that are also capable of calculating CRCs, since its frame done event triggers vblanks, it can be used as a signal to know when is safe to retrieve CRC of the frame.
Please note that position of the hardware component that is chosen as CRC generator in the display path is significant. For example, while OVL is the first module in VDOSYS0, its CRC won't be affected by the modules after it, which means effects applied by PQ, Gamma, Dither or any other components after OVL won't be calculated in CRC generation.
--- drivers/gpu/drm/mediatek/mtk_disp_drv.h | 3 + drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 197 +++++++++++++++++++- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 3 + 3 files changed, 193 insertions(+), 10 deletions(-)
drivers/gpu/drm/mediatek/mtk_disp_drv.h +3 -0
@@ -104,6 +104,9 @@ void mtk_ovl_enable_vblank(struct device *dev);void mtk_ovl_disable_vblank (struct device *dev);const u32 *mtk_ovl_get_formats (struct device *dev);size_t mtk_ovl_get_num_formats (struct device *dev); +size_t mtk_ovl_crc_cnt (struct device *dev); +u32 *mtk_ovl_crc_entry (struct device *dev); +void mtk_ovl_crc_read (struct device *dev);void mtk_ovl_adaptor_add_comp (struct device *dev,struct mtk_mutex *mutex);void mtk_ovl_adaptor_remove_comp (struct device *dev,struct mtk_mutex *mutex);
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +187 -10
298 lines not on this page · raw message
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +3 -0
@@ -349,6 +349,9 @@ static const struct mtk_ddp_comp_funcs ddp_ovl = { .clk_enable = mtk_ovl_clk_enable, .clk_disable = mtk_ovl_clk_disable, .config = mtk_ovl_config, + .crc_cnt = mtk_ovl_crc_cnt, + .crc_entry = mtk_ovl_crc_entry, + .crc_read = mtk_ovl_crc_read, .start = mtk_ovl_start, .stop = mtk_ovl_stop, .register_vblank_cb = mtk_ovl_register_vblank_cb,
Signature · 1 line
2.18.0
PATCH v5 12/13 drm/mediatek: Support CRC in OVL adaptor
In reply to Hsiao Chien SungWe choose Mixer as CRC generator in OVL adaptor since its frame done event will trigger vblanks, we can know when is safe to retrieve CRC of the frame.
In OVL adaptor, there's no image procession after Mixer, unlike the OVL in VDOSYS0, Mixer's CRC will include all the effects that are applied to the frame.
--- drivers/gpu/drm/mediatek/mtk_disp_drv.h | 3 + .../gpu/drm/mediatek/mtk_disp_ovl_adaptor.c | 21 +++++++ drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 3 + drivers/gpu/drm/mediatek/mtk_ethdr.c | 62 +++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_ethdr.h | 5 ++ 5 files changed, 94 insertions(+)
drivers/gpu/drm/mediatek/mtk_disp_drv.h +3 -0
@@ -138,6 +138,9 @@ const u32 *mtk_ovl_adaptor_get_formats(struct device *dev);size_t mtk_ovl_adaptor_get_num_formats (struct device *dev);enum drm_mode_status mtk_ovl_adaptor_mode_valid (struct device *dev,const struct drm_display_mode *mode); +size_t mtk_ovl_adaptor_crc_cnt (struct device *dev); +u32 *mtk_ovl_adaptor_crc_entry (struct device *dev); +void mtk_ovl_adaptor_crc_read (struct device *dev);void mtk_rdma_bypass_shadow (struct device *dev);int mtk_rdma_clk_enable (struct device *dev);
drivers/gpu/drm/mediatek/mtk_disp_ovl_adaptor.c +21 -0
@@ -206,6 +206,27 @@ void mtk_ovl_adaptor_layer_config(struct device *dev, unsigned int idx,mtk_ethdr_layer_config (ethdr, idx, state, cmdq_pkt); } +size_t mtk_ovl_adaptor_crc_cnt (struct device *dev) +{ +struct mtk_disp_ovl_adaptor *ovl_adaptor =dev_get_drvdata (dev); + +return mtk_ethdr_crc_cnt (ovl_adaptor->ovl_adaptor_comp[OVL_ADAPTOR_ETHDR0 ]); +} + +u32 *mtk_ovl_adaptor_crc_entry (struct device *dev) +{ +struct mtk_disp_ovl_adaptor *ovl_adaptor =dev_get_drvdata (dev); + +return mtk_ethdr_crc_entry (ovl_adaptor->ovl_adaptor_comp[OVL_ADAPTOR_ETHDR0 ]); +} + +void mtk_ovl_adaptor_crc_read (struct device *dev) +{ +struct mtk_disp_ovl_adaptor *ovl_adaptor =dev_get_drvdata (dev); + +mtk_ethdr_crc_read (ovl_adaptor->ovl_adaptor_comp[OVL_ADAPTOR_ETHDR0 ]); +} +void mtk_ovl_adaptor_config (struct device *dev,unsigned int w,unsigned int h,unsigned int vrefresh,unsigned int bpc,struct cmdq_pkt *cmdq_pkt)
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c +3 -0
@@ -404,6 +404,9 @@ static const struct mtk_ddp_comp_funcs ddp_ovl_adaptor = { .clk_enable = mtk_ovl_adaptor_clk_enable, .clk_disable = mtk_ovl_adaptor_clk_disable, .config = mtk_ovl_adaptor_config, + .crc_cnt = mtk_ovl_adaptor_crc_cnt, + .crc_entry = mtk_ovl_adaptor_crc_entry, + .crc_read = mtk_ovl_adaptor_crc_read, .start = mtk_ovl_adaptor_start, .stop = mtk_ovl_adaptor_stop, .layer_nr = mtk_ovl_adaptor_layer_nr,
drivers/gpu/drm/mediatek/mtk_ethdr.c +62 -0
116 lines not on this page · raw message
drivers/gpu/drm/mediatek/mtk_ethdr.h +5 -0
@@ -22,4 +22,9 @@ void mtk_ethdr_register_vblank_cb(struct device *dev,void mtk_ethdr_unregister_vblank_cb (struct device *dev);void mtk_ethdr_enable_vblank (struct device *dev);void mtk_ethdr_disable_vblank (struct device *dev); + +size_t mtk_ethdr_crc_cnt (struct device *dev); +u32 *mtk_ethdr_crc_entry (struct device *dev); +void mtk_ethdr_crc_read (struct device *dev); +#endif
Signature · 1 line
2.18.0
PATCH v5 13/13 drm/mediatek: Add comments for the structures
In reply to Hsiao Chien SungAdd comments for the structures to improve readability.
--- drivers/gpu/drm/mediatek/mtk_disp_ovl.c | 21 +++++++++++++- drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 22 ++++++++++++-- drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h | 32 +++++++++++++++++++++ drivers/gpu/drm/mediatek/mtk_drm_drv.h | 17 +++++++++++ drivers/gpu/drm/mediatek/mtk_ethdr.c | 11 +++++++ 5 files changed, 99 insertions(+), 4 deletions(-)
drivers/gpu/drm/mediatek/mtk_disp_ovl.c +20 -1
@@ -164,6 +164,20 @@ static const u32 mt8195_ovl_crc_ofs[] = { DISP_REG_OVL_CRC, }; +/** +* struct mtk_disp_ovl_data - ovl driver data +* @addr: offset of the first layer (layer-0) +* @gmc_bits: gmc (gating memory clock) bit masks for adjusting positivity for ovl +* @layer_nr: layer numbers that ovl supports +* @fmt_rgb565_is_0: whether or not rgb565 is represented as 0 +* @smi_id_en: determine if smi needs to be enabled +* @supports_afbc: determine if ovl supports afbc +* @formats: format table that ovl supports +* @num_formats: number of formats that ovl supports +* @supports_clrfmt_ext: whether the ovl supports clear format (for alpha blend) +* @crc_ofs: crc offset table +* @crc_cnt: count of crc registers (could be more than one bank) +*/ struct mtk_disp_ovl_data {unsigned int addr;unsigned int gmc_bits;
@@ -178,10 +192,15 @@ struct mtk_disp_ovl_data {size_t crc_cnt; }; -/* +/** * struct mtk_disp_ovl - DISP_OVL driver structure * @crtc: associated crtc to report vblank events to +* @clk: clock of the ovl +* @regs: base address of the ovl register that can be accessed by cpu +* @cmdq_reg: register related info for cmdq (subsys, offset ...etc.) * @data: platform data +* @vblank_cb: callback function when vblank irq happened +* @vblank_cb_data: data to the callback function * @crc: crc related information */ struct mtk_disp_ovl {
drivers/gpu/drm/mediatek/mtk_drm_crtc.c +19 -3
@@ -28,14 +28,30 @@* struct mtk_drm_crtc - MediaTek specific crtc structure. * @base: crtc object. * @enabled: records whether crtc_enable succeeded +* @pending_needs_vblank: determine if we need to handle vblank event +* @event: the vblank event to handle * @planes: array of 4 drm_plane structures, one for each overlay plane +* @layer_nr: layer numbers that the crtc supports * @pending_planes: whether any plane has pending changes to be applied +* @pending_async_planes: if there is any pending async update +* @cmdq_client: a handler to control cmdq (mbox channel, thread ...etc.) +* @cmdq_handle: cmdq packet to store the commands +* @cmdq_event: cmdq event that the thread is waiting for +* @cmdq_vblank_cnt: vblank count that is dedicated for the cmdq thread +* @cb_blocking_queue: wait queue to determine if cmdq is blocked * @mmsys_dev: pointer to the mmsys device for configuration registers +* @dma_dev: pointer to the dma device (usually rdma) * @mutex: handle to one of the ten disp_mutex streams -* @ddp_comp_nr: number of components in ddp_comp +* @ddp_comp_nr_ori: number of the components excludes the route (origin) +* @max_ddp_comp_nr: maximum number of the components in routes +* @ddp_comp_nr: number of the components in the current path * @ddp_comp: array of pointers the mtk_ddp_comp structures used by this crtc -* -* TODO: Needs update: this header is missing a bunch of member descriptions. +* @conn_route_nr: number of the components in route +* @conn_routes: route to the connector +* @hw_lock: mutex lock to avoid race condition when layer config +* @config_updating: determine if the layer configuration is done +* @crc_provider: get crc provider of the crtc +* @frames: count the frames that are added to crc entry */ struct mtk_drm_crtc {struct drm_crtc base;
drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h +32 -0
@@ -48,6 +48,38 @@ enum mtk_ddp_comp_type {struct mtk_ddp_comp ;struct cmdq_pkt ; + +/* struct mtk_ddp_comp_funcs - function pointers of the ddp components +* @clk_enable: enable the clocks of the component +* @clk_disable: disable the clocks of the component +* @config: configure the component +* @start: start (enable) the component +* @stop: stop (disable) the component +* @register_vblank_cb: to register a callback function when vblank irq occurs +* @unregister_vblank_cb: to unregister the callback function from the vblank irq +* @enable_vblank: enable vblank irq +* @disable_vblank: disable vblank irq +* @supported_rotations: return rotation capability of the component +* @layer_nr: how many layers the component supports +* @layer_check: to check if the state of the layer is valid for the component +* @layer_config: to configure the component according to the state of the layer +* @gamma_set: to set gamma for the component +* @bgclr_in_on: turn on background color +* @bgclr_in_off: turn off background color +* @ctm_set: set color transformation matrix +* @dma_dev_get: return the device that uses direct memory access +* @get_formats: get the format that is currently in use by the component +* @get_num_formats: get number of the formats that the component supports +* @connect: connect the sub modules of the component +* @disconnect: disconnect the sub modules of the component +* @add: add the device to the component (mount them in the mutex) +* @remove: remove the device from the component (unmount them from the mutex) +* @encoder_index: get the encoder index of the component +* @crc: return the start of crc array +* @crc_cnt: how many CRCs the component supports +* @crc_entry: get the pointer to the crc entry +* @crc_read: call this function to read crc from the hardware component +*/ struct mtk_ddp_comp_funcs {int (*power_on)(struct device *dev);void (*power_off)(struct device *dev);
drivers/gpu/drm/mediatek/mtk_drm_drv.h +17 -0
@@ -33,6 +33,23 @@ struct mtk_drm_route {const unsigned int route_ddp; }; +/** +* struct mtk_mmsys_driver_data - capabilities for the mmsys +* @main_path: path of the main display +* @main_len: length of the main display path +* @ext_path: path of the external display +* @ext_len: length of the external display path +* @third_path: path of the third display +* @third_len: length of the third display path +* @conn_routes: routing table of all the possible connectors +* @conn_routes_num: number of the routing table for the connectors +* @shadow_register: whether or not shadow register is enabled +* @mmsys_id: multi-media system ID +* @mmsys_dev_num: number of devices for in the mmsys as a whole +* @max_pitch: maximum pitch in bytes that the mmsys supports +* @min_width: minimum fb pixel width on this device +* @min_height: minimum fb pixel height on this device +*/ struct mtk_mmsys_driver_data {const unsigned int *main_path;unsigned int main_len;
drivers/gpu/drm/mediatek/mtk_ethdr.c +11 -0
@@ -82,6 +82,17 @@ struct mtk_ethdr_comp {struct cmdq_client_reg cmdq_base; }; +/** +* struct mtk_ethdr - ethdr driver data +* @ethdr_comp: components of ethdr(mixer) +* @ethdr_clk: clocks of ethdr components +* @mmsys_dev: mmsys device that ethdr binds to +* @vblank_cb: callback function when vblank irq occurs +* @vblank_cb_data: data fo vblank callback +* @irq: irq that triggers irq handler +* @reset_ctl: reset control of ethdr +* @crc: crc information +*/ struct mtk_ethdr {struct mtk_ethdr_comp ethdr_comp[ETHDR_ID_MAX ];struct clk_bulk_data ethdr_clk[ETHDR_CLK_NUM ];
Signature · 1 line
2.18.0