drm/vkms: Remove index parameter from init_vkms_output
Louis Chauvet
maintainerPATCH v3 1/1 drm/vkms: Remove index parameter from init_vkms_output
VKMS currently supports only one CRTC, so it make no sense to have this index configurable. To avoid issues, replace this hardcoded index by drm_crtc_mask when applicable.
There is no need to manually set a crtc mask on primary and cursor plane as it is automatically set by drmm_crtc_alloc_with_planes.
In addition, this will remove the use of an uninitialized structure in vkms_add_overlay_plane. This currently works by chance because two things:
- vkms_plane_init always set a possible_crtcs value, so the problematic branch is never used;
- drm_crtc_mask on an kzalloc'd drm_crtc returns BIT(0), and the VKMS CRTC always have this id.
---
Changes in v3:
- Rebased on drm-misc-next
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- Applied comments from José
- Link to v1: https://lore.kernel.org/r/[email protected]
--- drivers/gpu/drm/vkms/vkms_drv.c | 2 +- drivers/gpu/drm/vkms/vkms_drv.h | 8 ++----- drivers/gpu/drm/vkms/vkms_output.c | 49 +++++++++++++------------------------- drivers/gpu/drm/vkms/vkms_plane.c | 4 ++-- 4 files changed, 21 insertions(+), 42 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.c +1 -1
@@ -174,7 +174,7 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) dev->mode_config.preferred_depth =0 ; dev->mode_config.helper_private = &vkms_mode_config_helpers; -return vkms_output_init (vkmsdev,0 ); +return vkms_output_init (vkmsdev); }static int vkms_create (struct vkms_config *config)
drivers/gpu/drm/vkms/vkms_drv.h +2 -6
@@ -212,21 +212,17 @@ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,* vkms_output_init() - Initialize all sub-components needed for a VKMS device. * * @vkmsdev: VKMS device to initialize -* @index: CRTC which can be attached to the planes. The caller must ensure that -* @index is positive and less or equals to 31. */ -int vkms_output_init (struct vkms_device *vkmsdev,int index); +int vkms_output_init (struct vkms_device *vkmsdev);/** * vkms_plane_init() - Initialize a plane * * @vkmsdev: VKMS device containing the plane * @type: type of plane to initialize -* @index: CRTC which can be attached to the plane. The caller must ensure that -* @index is positive and less or equals to 31. */ struct vkms_plane *vkms_plane_init (struct vkms_device *vkmsdev, -enum drm_plane_type type,int index); +enum drm_plane_type type);/* CRC Support */ const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
drivers/gpu/drm/vkms/vkms_output.c +16 -33
85 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_plane.c +2 -2
@@ -198,12 +198,12 @@ static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = { };struct vkms_plane *vkms_plane_init (struct vkms_device *vkmsdev, -enum drm_plane_type type,int index) +enum drm_plane_type type) {struct drm_device *dev = &vkmsdev->drm;struct vkms_plane *plane; - plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 1 << index, + plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 0, &vkms_plane_funcs, vkms_formats,ARRAY_SIZE (vkms_formats),NULL , type,NULL );
---
base-commit: 7d2faa8dbb7055a115fe0cd6068d7090094a573d
change-id: 20240906-vkms-remove-index-3a6e04c38e02
Best regards,
Signature · 1 line
Louis Chauvet <[email protected]>
Louis Chauvet
maintainerQuoted 7 lines · Louis Chauvet
VKMS currently supports only one CRTC, so it make no sense to have this index configurable. To avoid issues, replace this hardcoded index by
drm_crtc_maskwhen applicable.There is no need to manually set a crtc mask on primary and cursor plane as it is automatically set by
drmm_crtc_alloc_with_planes.
Quoted 8 lines
In addition, this will remove the use of an uninitialized structure in
vkms_add_overlay_plane. This currently works by chance because two things:
-vkms_plane_initalways set apossible_crtcsvalue, so the problematic branch is never used;
-drm_crtc_maskon an kzalloc'ddrm_crtcreturns BIT(0), and the VKMS CRTC always have this id.Signed-off-by Louis Chauvet <[email protected]>
Hi Maíra, José,
You told me "LGTM" for the v2, but without leaving a Acked/Reviewed-by, should I add them? Or maybe you prefer to formally send them now?
Thanks,
Louis Chauvet
Quoted 176 lines
---
Changes in v3:
- Rebased on drm-misc-next
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- Applied comments from José
- Link to v1: https://lore.kernel.org/r/[email protected]--- drivers/gpu/drm/vkms/vkms_drv.c | 2 +- drivers/gpu/drm/vkms/vkms_drv.h | 8 ++----- drivers/gpu/drm/vkms/vkms_output.c | 49 +++++++++++++------------------------- drivers/gpu/drm/vkms/vkms_plane.c | 4 ++-- 4 files changed, 21 insertions(+), 42 deletions(-)drivers/gpu/drm/vkms/vkms_drv.c +1
-1@@ -174,7 +174,7 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) dev->mode_config.preferred_depth =0 ; dev->mode_config.helper_private = &vkms_mode_config_helpers; -return vkms_output_init (vkmsdev,0 ); +return vkms_output_init (vkmsdev); }static int vkms_create (struct vkms_config *config)drivers/gpu/drm/vkms/vkms_drv.h +2
-6@@ -212,21 +212,17 @@ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,* vkms_output_init() - Initialize all sub-components needed for a VKMS device. * * @vkmsdev: VKMS device to initialize -* @index: CRTC which can be attached to the planes. The caller must ensure that -* @index is positive and less or equals to 31. */ -int vkms_output_init (struct vkms_device *vkmsdev,int index); +int vkms_output_init (struct vkms_device *vkmsdev);/** * vkms_plane_init() - Initialize a plane * * @vkmsdev: VKMS device containing the plane * @type: type of plane to initialize -* @index: CRTC which can be attached to the plane. The caller must ensure that -* @index is positive and less or equals to 31. */ struct vkms_plane *vkms_plane_init (struct vkms_device *vkmsdev, -enum drm_plane_type type,int index); +enum drm_plane_type type);/* CRC Support */ const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,drivers/gpu/drm/vkms/vkms_output.c +16
-33@@ -32,29 +32,14 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { .get_modes = vkms_conn_get_modes, }; -static int vkms_add_overlay_plane (struct vkms_device *vkmsdev,int index, -struct drm_crtc *crtc) -{ -struct vkms_plane *overlay; - - overlay =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_OVERLAY , index); -if (IS_ERR (overlay)) -return PTR_ERR (overlay); - -if (!overlay->base.possible_crtcs) - overlay->base.possible_crtcs =drm_crtc_mask (crtc); - -return 0 ; -} - -int vkms_output_init (struct vkms_device *vkmsdev,int index) +int vkms_output_init (struct vkms_device *vkmsdev) {struct vkms_output *output = &vkmsdev->output;struct drm_device *dev = &vkmsdev->drm;struct drm_connector *connector = &output->connector;struct drm_encoder *encoder = &output->encoder;struct drm_crtc *crtc = &output->crtc; -struct vkms_plane *primary, *cursor =NULL ; +struct vkms_plane *primary, *overlay, *cursor =NULL ;int ret;int writeback;unsigned int n;@@ -65,29 +50,31 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)* The overlay and cursor planes are not mandatory, but can be used to perform complex * composition. */ - primary =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_PRIMARY , index); + primary =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_PRIMARY );if (IS_ERR (primary))return PTR_ERR (primary); -if (vkmsdev->config->overlay) { -for (n =0 ; n <NUM_OVERLAY_PLANES ; n++) { - ret =vkms_add_overlay_plane (vkmsdev, index, crtc); -if (ret) -return ret; - } - } -if (vkmsdev->config->cursor) { - cursor =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_CURSOR , index); + cursor =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_CURSOR );if (IS_ERR (cursor))return PTR_ERR (cursor); } -/* [1]: Allocation of a CRTC, its index will be BIT(0) = 1 */ ret =vkms_crtc_init (dev, crtc, &primary->base, &cursor->base);if (ret)return ret; +if (vkmsdev->config->overlay) { +for (n =0 ; n <NUM_OVERLAY_PLANES ; n++) { + overlay =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_OVERLAY ); +if (IS_ERR (overlay)) { +DRM_DEV_ERROR (dev->dev,"Failed to init vkms plane\n" ); +return PTR_ERR (overlay); + } + overlay->base.possible_crtcs =drm_crtc_mask (crtc); + } + } + ret =drm_connector_init (dev, connector, &vkms_connector_funcs,DRM_MODE_CONNECTOR_VIRTUAL );if (ret) {@@ -103,11 +90,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)DRM_ERROR ("Failed to init encoder\n" ); goto err_encoder; } -/* -* This is a hardcoded value to select crtc for the encoder. -* BIT(0) here designate the first registered CRTC, the one allocated in [1] -*/ - encoder->possible_crtcs =BIT (0 ); + encoder->possible_crtcs =drm_crtc_mask (crtc); ret =drm_connector_attach_encoder (connector, encoder);if (ret) {drivers/gpu/drm/vkms/vkms_plane.c +2
-3@@ -198,12 +198,12 @@ static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = { };struct vkms_plane *vkms_plane_init (struct vkms_device *vkmsdev, -enum drm_plane_type type,int index) +enum drm_plane_type type) {struct drm_device *dev = &vkmsdev->drm;struct vkms_plane *plane; - plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 1 << index, + plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 0, &vkms_plane_funcs, vkms_formats,ARRAY_SIZE (vkms_formats),NULL , type,NULL ); ---base-commit:
7d2faa8dbb7055a115fe0cd6068d7090094a573d
change-id: 20240906-vkms-remove-index-3a6e04c38e02Best regards,
Signature · 1 line
Louis Chauvet <[email protected]>
José Expósito
Reviewed-byQuoted 15 lines · Louis Chauvet
Quoted 14 lines · Louis Chauvet
VKMS currently supports only one CRTC, so it make no sense to have this index configurable. To avoid issues, replace this hardcoded index by
drm_crtc_maskwhen applicable.There is no need to manually set a crtc mask on primary and cursor plane as it is automatically set by
drmm_crtc_alloc_with_planes.In addition, this will remove the use of an uninitialized structure in
vkms_add_overlay_plane. This currently works by chance because two things:
-vkms_plane_initalways set apossible_crtcsvalue, so the problematic branch is never used;
-drm_crtc_maskon an kzalloc'ddrm_crtcreturns BIT(0), and the VKMS CRTC always have this id.
Quoted 6 lines
Quoted 1 line
Signed-off-by Louis Chauvet <[email protected]>Hi Maíra, José,
You told me "LGTM" for the v2, but without leaving a Acked/Reviewed-by, should I add them? Or maybe you prefer to formally send them now?
Yes, feel free to add:
Thanks for rebasing the patch and fixing the conflict!
Jose
Quoted 179 lines
Thanks,
Louis ChauvetQuoted 176 lines
---
Changes in v3:
- Rebased on drm-misc-next
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- Applied comments from José
- Link to v1: https://lore.kernel.org/r/[email protected]--- drivers/gpu/drm/vkms/vkms_drv.c | 2 +- drivers/gpu/drm/vkms/vkms_drv.h | 8 ++----- drivers/gpu/drm/vkms/vkms_output.c | 49 +++++++++++++------------------------- drivers/gpu/drm/vkms/vkms_plane.c | 4 ++-- 4 files changed, 21 insertions(+), 42 deletions(-)drivers/gpu/drm/vkms/vkms_drv.c +1
-1@@ -174,7 +174,7 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) dev->mode_config.preferred_depth =0 ; dev->mode_config.helper_private = &vkms_mode_config_helpers; -return vkms_output_init (vkmsdev,0 ); +return vkms_output_init (vkmsdev); }static int vkms_create (struct vkms_config *config)drivers/gpu/drm/vkms/vkms_drv.h +2
-6@@ -212,21 +212,17 @@ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,* vkms_output_init() - Initialize all sub-components needed for a VKMS device. * * @vkmsdev: VKMS device to initialize -* @index: CRTC which can be attached to the planes. The caller must ensure that -* @index is positive and less or equals to 31. */ -int vkms_output_init (struct vkms_device *vkmsdev,int index); +int vkms_output_init (struct vkms_device *vkmsdev);/** * vkms_plane_init() - Initialize a plane * * @vkmsdev: VKMS device containing the plane * @type: type of plane to initialize -* @index: CRTC which can be attached to the plane. The caller must ensure that -* @index is positive and less or equals to 31. */ struct vkms_plane *vkms_plane_init (struct vkms_device *vkmsdev, -enum drm_plane_type type,int index); +enum drm_plane_type type);/* CRC Support */ const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,drivers/gpu/drm/vkms/vkms_output.c +16
-33@@ -32,29 +32,14 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { .get_modes = vkms_conn_get_modes, }; -static int vkms_add_overlay_plane (struct vkms_device *vkmsdev,int index, -struct drm_crtc *crtc) -{ -struct vkms_plane *overlay; - - overlay =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_OVERLAY , index); -if (IS_ERR (overlay)) -return PTR_ERR (overlay); - -if (!overlay->base.possible_crtcs) - overlay->base.possible_crtcs =drm_crtc_mask (crtc); - -return 0 ; -} - -int vkms_output_init (struct vkms_device *vkmsdev,int index) +int vkms_output_init (struct vkms_device *vkmsdev) {struct vkms_output *output = &vkmsdev->output;struct drm_device *dev = &vkmsdev->drm;struct drm_connector *connector = &output->connector;struct drm_encoder *encoder = &output->encoder;struct drm_crtc *crtc = &output->crtc; -struct vkms_plane *primary, *cursor =NULL ; +struct vkms_plane *primary, *overlay, *cursor =NULL ;int ret;int writeback;unsigned int n;@@ -65,29 +50,31 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)* The overlay and cursor planes are not mandatory, but can be used to perform complex * composition. */ - primary =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_PRIMARY , index); + primary =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_PRIMARY );if (IS_ERR (primary))return PTR_ERR (primary); -if (vkmsdev->config->overlay) { -for (n =0 ; n <NUM_OVERLAY_PLANES ; n++) { - ret =vkms_add_overlay_plane (vkmsdev, index, crtc); -if (ret) -return ret; - } - } -if (vkmsdev->config->cursor) { - cursor =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_CURSOR , index); + cursor =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_CURSOR );if (IS_ERR (cursor))return PTR_ERR (cursor); } -/* [1]: Allocation of a CRTC, its index will be BIT(0) = 1 */ ret =vkms_crtc_init (dev, crtc, &primary->base, &cursor->base);if (ret)return ret; +if (vkmsdev->config->overlay) { +for (n =0 ; n <NUM_OVERLAY_PLANES ; n++) { + overlay =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_OVERLAY ); +if (IS_ERR (overlay)) { +DRM_DEV_ERROR (dev->dev,"Failed to init vkms plane\n" ); +return PTR_ERR (overlay); + } + overlay->base.possible_crtcs =drm_crtc_mask (crtc); + } + } + ret =drm_connector_init (dev, connector, &vkms_connector_funcs,DRM_MODE_CONNECTOR_VIRTUAL );if (ret) {@@ -103,11 +90,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)DRM_ERROR ("Failed to init encoder\n" ); goto err_encoder; } -/* -* This is a hardcoded value to select crtc for the encoder. -* BIT(0) here designate the first registered CRTC, the one allocated in [1] -*/ - encoder->possible_crtcs =BIT (0 ); + encoder->possible_crtcs =drm_crtc_mask (crtc); ret =drm_connector_attach_encoder (connector, encoder);if (ret) {drivers/gpu/drm/vkms/vkms_plane.c +2
-3@@ -198,12 +198,12 @@ static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = { };struct vkms_plane *vkms_plane_init (struct vkms_device *vkmsdev, -enum drm_plane_type type,int index) +enum drm_plane_type type) {struct drm_device *dev = &vkmsdev->drm;struct vkms_plane *plane; - plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 1 << index, + plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 0, &vkms_plane_funcs, vkms_formats,ARRAY_SIZE (vkms_formats),NULL , type,NULL ); ---base-commit:
7d2faa8dbb7055a115fe0cd6068d7090094a573d
change-id: 20240906-vkms-remove-index-3a6e04c38e02Best regards,
Signature · 1 line
Louis Chauvet <[email protected]>
Maíra Canal
Reviewed-byQuoted 15 lines · Louis Chauvet
Quoted 14 lines · Louis Chauvet
VKMS currently supports only one CRTC, so it make no sense to have this index configurable. To avoid issues, replace this hardcoded index by
drm_crtc_maskwhen applicable.There is no need to manually set a crtc mask on primary and cursor plane as it is automatically set by
drmm_crtc_alloc_with_planes.In addition, this will remove the use of an uninitialized structure in
vkms_add_overlay_plane. This currently works by chance because two things:
-vkms_plane_initalways set apossible_crtcsvalue, so the problematic branch is never used;
-drm_crtc_maskon an kzalloc'ddrm_crtcreturns BIT(0), and the VKMS CRTC always have this id.
Quoted 6 lines
Quoted 1 line
Signed-off-by Louis Chauvet <[email protected]>Hi Maíra, José,
You told me "LGTM" for the v2, but without leaving a Acked/Reviewed-by, should I add them? Or maybe you prefer to formally send them now?
Best Regards,
- Maíra
Quoted 180 lines
Thanks,
Louis ChauvetQuoted 176 lines
---
Changes in v3:
- Rebased on drm-misc-next
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- Applied comments from José
- Link to v1: https://lore.kernel.org/r/[email protected]--- drivers/gpu/drm/vkms/vkms_drv.c | 2 +- drivers/gpu/drm/vkms/vkms_drv.h | 8 ++----- drivers/gpu/drm/vkms/vkms_output.c | 49 +++++++++++++------------------------- drivers/gpu/drm/vkms/vkms_plane.c | 4 ++-- 4 files changed, 21 insertions(+), 42 deletions(-)drivers/gpu/drm/vkms/vkms_drv.c +1
-1@@ -174,7 +174,7 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) dev->mode_config.preferred_depth =0 ; dev->mode_config.helper_private = &vkms_mode_config_helpers; -return vkms_output_init (vkmsdev,0 ); +return vkms_output_init (vkmsdev); }static int vkms_create (struct vkms_config *config)drivers/gpu/drm/vkms/vkms_drv.h +2
-6@@ -212,21 +212,17 @@ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,* vkms_output_init() - Initialize all sub-components needed for a VKMS device. * * @vkmsdev: VKMS device to initialize -* @index: CRTC which can be attached to the planes. The caller must ensure that -* @index is positive and less or equals to 31. */ -int vkms_output_init (struct vkms_device *vkmsdev,int index); +int vkms_output_init (struct vkms_device *vkmsdev);/** * vkms_plane_init() - Initialize a plane * * @vkmsdev: VKMS device containing the plane * @type: type of plane to initialize -* @index: CRTC which can be attached to the plane. The caller must ensure that -* @index is positive and less or equals to 31. */ struct vkms_plane *vkms_plane_init (struct vkms_device *vkmsdev, -enum drm_plane_type type,int index); +enum drm_plane_type type);/* CRC Support */ const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,drivers/gpu/drm/vkms/vkms_output.c +16
-33@@ -32,29 +32,14 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { .get_modes = vkms_conn_get_modes, }; -static int vkms_add_overlay_plane (struct vkms_device *vkmsdev,int index, -struct drm_crtc *crtc) -{ -struct vkms_plane *overlay; - - overlay =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_OVERLAY , index); -if (IS_ERR (overlay)) -return PTR_ERR (overlay); - -if (!overlay->base.possible_crtcs) - overlay->base.possible_crtcs =drm_crtc_mask (crtc); - -return 0 ; -} - -int vkms_output_init (struct vkms_device *vkmsdev,int index) +int vkms_output_init (struct vkms_device *vkmsdev) {struct vkms_output *output = &vkmsdev->output;struct drm_device *dev = &vkmsdev->drm;struct drm_connector *connector = &output->connector;struct drm_encoder *encoder = &output->encoder;struct drm_crtc *crtc = &output->crtc; -struct vkms_plane *primary, *cursor =NULL ; +struct vkms_plane *primary, *overlay, *cursor =NULL ;int ret;int writeback;unsigned int n;@@ -65,29 +50,31 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)* The overlay and cursor planes are not mandatory, but can be used to perform complex * composition. */ - primary =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_PRIMARY , index); + primary =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_PRIMARY );if (IS_ERR (primary))return PTR_ERR (primary); -if (vkmsdev->config->overlay) { -for (n =0 ; n <NUM_OVERLAY_PLANES ; n++) { - ret =vkms_add_overlay_plane (vkmsdev, index, crtc); -if (ret) -return ret; - } - } -if (vkmsdev->config->cursor) { - cursor =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_CURSOR , index); + cursor =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_CURSOR );if (IS_ERR (cursor))return PTR_ERR (cursor); } -/* [1]: Allocation of a CRTC, its index will be BIT(0) = 1 */ ret =vkms_crtc_init (dev, crtc, &primary->base, &cursor->base);if (ret)return ret; +if (vkmsdev->config->overlay) { +for (n =0 ; n <NUM_OVERLAY_PLANES ; n++) { + overlay =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_OVERLAY ); +if (IS_ERR (overlay)) { +DRM_DEV_ERROR (dev->dev,"Failed to init vkms plane\n" ); +return PTR_ERR (overlay); + } + overlay->base.possible_crtcs =drm_crtc_mask (crtc); + } + } + ret =drm_connector_init (dev, connector, &vkms_connector_funcs,DRM_MODE_CONNECTOR_VIRTUAL );if (ret) {@@ -103,11 +90,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)DRM_ERROR ("Failed to init encoder\n" ); goto err_encoder; } -/* -* This is a hardcoded value to select crtc for the encoder. -* BIT(0) here designate the first registered CRTC, the one allocated in [1] -*/ - encoder->possible_crtcs =BIT (0 ); + encoder->possible_crtcs =drm_crtc_mask (crtc); ret =drm_connector_attach_encoder (connector, encoder);if (ret) {drivers/gpu/drm/vkms/vkms_plane.c +2
-3@@ -198,12 +198,12 @@ static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = { };struct vkms_plane *vkms_plane_init (struct vkms_device *vkmsdev, -enum drm_plane_type type,int index) +enum drm_plane_type type) {struct drm_device *dev = &vkmsdev->drm;struct vkms_plane *plane; - plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 1 << index, + plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 0, &vkms_plane_funcs, vkms_formats,ARRAY_SIZE (vkms_formats),NULL , type,NULL ); ---base-commit:
7d2faa8dbb7055a115fe0cd6068d7090094a573d
change-id: 20240906-vkms-remove-index-3a6e04c38e02Best regards,
Signature · 1 line
Louis Chauvet <[email protected]>
Louis Chauvet
maintainerQuoted 7 lines · Louis Chauvet
VKMS currently supports only one CRTC, so it make no sense to have this index configurable. To avoid issues, replace this hardcoded index by
drm_crtc_maskwhen applicable.There is no need to manually set a crtc mask on primary and cursor plane as it is automatically set by
drmm_crtc_alloc_with_planes.
Quoted 8 lines
In addition, this will remove the use of an uninitialized structure in
vkms_add_overlay_plane. This currently works by chance because two things:
-vkms_plane_initalways set apossible_crtcsvalue, so the problematic branch is never used;
-drm_crtc_maskon an kzalloc'ddrm_crtcreturns BIT(0), and the VKMS CRTC always have this id.Signed-off-by Louis Chauvet <[email protected]>
Applied on drm-misc-next:
https://gitlab.freedesktop.org/drm/misc/kernel/-/commit/12e755103f2404fa87bd1d7af93100ec45b43feb
Quoted 176 lines
---
Changes in v3:
- Rebased on drm-misc-next
- Link to v2: https://lore.kernel.org/r/[email protected]Changes in v2:
- Applied comments from José
- Link to v1: https://lore.kernel.org/r/[email protected]--- drivers/gpu/drm/vkms/vkms_drv.c | 2 +- drivers/gpu/drm/vkms/vkms_drv.h | 8 ++----- drivers/gpu/drm/vkms/vkms_output.c | 49 +++++++++++++------------------------- drivers/gpu/drm/vkms/vkms_plane.c | 4 ++-- 4 files changed, 21 insertions(+), 42 deletions(-)drivers/gpu/drm/vkms/vkms_drv.c +1
-1@@ -174,7 +174,7 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) dev->mode_config.preferred_depth =0 ; dev->mode_config.helper_private = &vkms_mode_config_helpers; -return vkms_output_init (vkmsdev,0 ); +return vkms_output_init (vkmsdev); }static int vkms_create (struct vkms_config *config)drivers/gpu/drm/vkms/vkms_drv.h +2
-6@@ -212,21 +212,17 @@ int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,* vkms_output_init() - Initialize all sub-components needed for a VKMS device. * * @vkmsdev: VKMS device to initialize -* @index: CRTC which can be attached to the planes. The caller must ensure that -* @index is positive and less or equals to 31. */ -int vkms_output_init (struct vkms_device *vkmsdev,int index); +int vkms_output_init (struct vkms_device *vkmsdev);/** * vkms_plane_init() - Initialize a plane * * @vkmsdev: VKMS device containing the plane * @type: type of plane to initialize -* @index: CRTC which can be attached to the plane. The caller must ensure that -* @index is positive and less or equals to 31. */ struct vkms_plane *vkms_plane_init (struct vkms_device *vkmsdev, -enum drm_plane_type type,int index); +enum drm_plane_type type);/* CRC Support */ const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,drivers/gpu/drm/vkms/vkms_output.c +16
-33@@ -32,29 +32,14 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { .get_modes = vkms_conn_get_modes, }; -static int vkms_add_overlay_plane (struct vkms_device *vkmsdev,int index, -struct drm_crtc *crtc) -{ -struct vkms_plane *overlay; - - overlay =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_OVERLAY , index); -if (IS_ERR (overlay)) -return PTR_ERR (overlay); - -if (!overlay->base.possible_crtcs) - overlay->base.possible_crtcs =drm_crtc_mask (crtc); - -return 0 ; -} - -int vkms_output_init (struct vkms_device *vkmsdev,int index) +int vkms_output_init (struct vkms_device *vkmsdev) {struct vkms_output *output = &vkmsdev->output;struct drm_device *dev = &vkmsdev->drm;struct drm_connector *connector = &output->connector;struct drm_encoder *encoder = &output->encoder;struct drm_crtc *crtc = &output->crtc; -struct vkms_plane *primary, *cursor =NULL ; +struct vkms_plane *primary, *overlay, *cursor =NULL ;int ret;int writeback;unsigned int n;@@ -65,29 +50,31 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)* The overlay and cursor planes are not mandatory, but can be used to perform complex * composition. */ - primary =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_PRIMARY , index); + primary =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_PRIMARY );if (IS_ERR (primary))return PTR_ERR (primary); -if (vkmsdev->config->overlay) { -for (n =0 ; n <NUM_OVERLAY_PLANES ; n++) { - ret =vkms_add_overlay_plane (vkmsdev, index, crtc); -if (ret) -return ret; - } - } -if (vkmsdev->config->cursor) { - cursor =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_CURSOR , index); + cursor =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_CURSOR );if (IS_ERR (cursor))return PTR_ERR (cursor); } -/* [1]: Allocation of a CRTC, its index will be BIT(0) = 1 */ ret =vkms_crtc_init (dev, crtc, &primary->base, &cursor->base);if (ret)return ret; +if (vkmsdev->config->overlay) { +for (n =0 ; n <NUM_OVERLAY_PLANES ; n++) { + overlay =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_OVERLAY ); +if (IS_ERR (overlay)) { +DRM_DEV_ERROR (dev->dev,"Failed to init vkms plane\n" ); +return PTR_ERR (overlay); + } + overlay->base.possible_crtcs =drm_crtc_mask (crtc); + } + } + ret =drm_connector_init (dev, connector, &vkms_connector_funcs,DRM_MODE_CONNECTOR_VIRTUAL );if (ret) {@@ -103,11 +90,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)DRM_ERROR ("Failed to init encoder\n" ); goto err_encoder; } -/* -* This is a hardcoded value to select crtc for the encoder. -* BIT(0) here designate the first registered CRTC, the one allocated in [1] -*/ - encoder->possible_crtcs =BIT (0 ); + encoder->possible_crtcs =drm_crtc_mask (crtc); ret =drm_connector_attach_encoder (connector, encoder);if (ret) {drivers/gpu/drm/vkms/vkms_plane.c +2
-3@@ -198,12 +198,12 @@ static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = { };struct vkms_plane *vkms_plane_init (struct vkms_device *vkmsdev, -enum drm_plane_type type,int index) +enum drm_plane_type type) {struct drm_device *dev = &vkmsdev->drm;struct vkms_plane *plane; - plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 1 << index, + plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 0, &vkms_plane_funcs, vkms_formats,ARRAY_SIZE (vkms_formats),NULL , type,NULL ); ---base-commit:
7d2faa8dbb7055a115fe0cd6068d7090094a573d
change-id: 20240906-vkms-remove-index-3a6e04c38e02Best regards,
Signature · 1 line
Louis Chauvet <[email protected]>