Message ID | 20240813105134.17439-8-jose.exposito89@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | VKMS: Add configfs support | expand |
Le 13/08/24 - 12:44, José Expósito a écrit : > A future patch will allow to create multiple connectors. Use managed > memory to simplify the code. > > Refactor, no functional changes. > > Signed-off-by: José Expósito <jose.exposito89@gmail.com> > --- > drivers/gpu/drm/vkms/vkms_drv.h | 5 --- > drivers/gpu/drm/vkms/vkms_output.c | 53 +++++++++++++++++------------- > 2 files changed, 31 insertions(+), 27 deletions(-) > > diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h > index 2466e8b0231f..cac37d21654a 100644 > --- a/drivers/gpu/drm/vkms/vkms_drv.h > +++ b/drivers/gpu/drm/vkms/vkms_drv.h > @@ -121,14 +121,9 @@ struct vkms_crtc { > > struct vkms_config; > > -struct vkms_output { > - struct drm_connector connector; > -}; > - > struct vkms_device { > struct drm_device drm; > struct platform_device *platform; > - struct vkms_output output; > struct list_head crtcs; > const struct vkms_config *config; > }; > diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c > index 7afe37aea52d..4413cf88afc7 100644 > --- a/drivers/gpu/drm/vkms/vkms_output.c > +++ b/drivers/gpu/drm/vkms/vkms_output.c > @@ -9,7 +9,6 @@ > > static const struct drm_connector_funcs vkms_connector_funcs = { > .fill_modes = drm_helper_probe_single_connector_modes, > - .destroy = drm_connector_cleanup, > .reset = drm_atomic_helper_connector_reset, > .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, > .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, > @@ -29,6 +28,33 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { > .get_modes = vkms_conn_get_modes, > }; > > +static struct drm_connector *vkms_connector_init(struct vkms_device *vkms_device, > + uint32_t possible_encoders) > +{ > + struct drm_connector *connector; > + int ret; > + > + connector = drmm_kzalloc(&vkms_device->drm, sizeof(*connector), GFP_KERNEL); > + if (!connector) { > + DRM_ERROR("Failed to allocate connector\n"); > + return ERR_PTR(-ENOMEM); > + } > + > + ret = drmm_connector_init(&vkms_device->drm, connector, > + &vkms_connector_funcs, > + DRM_MODE_CONNECTOR_VIRTUAL, NULL); > + if (ret) { > + DRM_ERROR("Failed to init connector\n"); > + kfree(connector); Again, connector is allocated with drmm_kzalloc, so drmm_kfree or nothing. > + return ERR_PTR(ret); > + } > + > + connector->possible_encoders = possible_encoders; > + drm_connector_helper_add(connector, &vkms_conn_helper_funcs); > + > + return connector; > +} > + > static struct drm_encoder *vkms_encoder_init(struct vkms_device *vkms_device, > uint32_t possible_crtcs, > unsigned int index) > @@ -72,9 +98,8 @@ static int vkms_add_overlay_plane(struct vkms_device *vkmsdev, int index) > > int vkms_output_init(struct vkms_device *vkmsdev, int index) > { > - struct vkms_output *output = &vkmsdev->output; > struct drm_device *dev = &vkmsdev->drm; > - struct drm_connector *connector = &output->connector; > + struct drm_connector *connector; > struct drm_encoder *encoder; > struct vkms_config_encoder *encoder_cfg; > struct vkms_crtc *vkms_crtc; > @@ -117,14 +142,9 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index) > } > } > > - ret = drm_connector_init(dev, connector, &vkms_connector_funcs, > - DRM_MODE_CONNECTOR_VIRTUAL); > - if (ret) { > - DRM_ERROR("Failed to init connector\n"); > - return ret; > - } > - > - drm_connector_helper_add(connector, &vkms_conn_helper_funcs); > + connector = vkms_connector_init(vkmsdev, BIT(index)); As for CRTC, you can create multiple encoder but connector is always attached to the first? I assume this is intentionnal? Maybe you can attach it to all the created encoders? > + if (IS_ERR(connector)) > + return PTR_ERR(connector); > > list_for_each_entry(encoder_cfg, &vkmsdev->config->encoders, list) { > encoder = vkms_encoder_init(vkmsdev, encoder_cfg->possible_crtcs, > @@ -133,18 +153,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index) > return PTR_ERR(encoder); > } > > - ret = drm_connector_attach_encoder(connector, encoder); > - if (ret) { > - DRM_ERROR("Failed to attach connector to encoder\n"); > - goto err_attach; > - } > - The encoder is not attached to the connector? > drm_mode_config_reset(dev); > > return 0; > - > -err_attach: > - drm_connector_cleanup(connector); > - > - return ret; > } > -- > 2.46.0 >
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 2466e8b0231f..cac37d21654a 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -121,14 +121,9 @@ struct vkms_crtc { struct vkms_config; -struct vkms_output { - struct drm_connector connector; -}; - struct vkms_device { struct drm_device drm; struct platform_device *platform; - struct vkms_output output; struct list_head crtcs; const struct vkms_config *config; }; diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index 7afe37aea52d..4413cf88afc7 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -9,7 +9,6 @@ static const struct drm_connector_funcs vkms_connector_funcs = { .fill_modes = drm_helper_probe_single_connector_modes, - .destroy = drm_connector_cleanup, .reset = drm_atomic_helper_connector_reset, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, @@ -29,6 +28,33 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { .get_modes = vkms_conn_get_modes, }; +static struct drm_connector *vkms_connector_init(struct vkms_device *vkms_device, + uint32_t possible_encoders) +{ + struct drm_connector *connector; + int ret; + + connector = drmm_kzalloc(&vkms_device->drm, sizeof(*connector), GFP_KERNEL); + if (!connector) { + DRM_ERROR("Failed to allocate connector\n"); + return ERR_PTR(-ENOMEM); + } + + ret = drmm_connector_init(&vkms_device->drm, connector, + &vkms_connector_funcs, + DRM_MODE_CONNECTOR_VIRTUAL, NULL); + if (ret) { + DRM_ERROR("Failed to init connector\n"); + kfree(connector); + return ERR_PTR(ret); + } + + connector->possible_encoders = possible_encoders; + drm_connector_helper_add(connector, &vkms_conn_helper_funcs); + + return connector; +} + static struct drm_encoder *vkms_encoder_init(struct vkms_device *vkms_device, uint32_t possible_crtcs, unsigned int index) @@ -72,9 +98,8 @@ static int vkms_add_overlay_plane(struct vkms_device *vkmsdev, int index) int vkms_output_init(struct vkms_device *vkmsdev, int index) { - struct vkms_output *output = &vkmsdev->output; struct drm_device *dev = &vkmsdev->drm; - struct drm_connector *connector = &output->connector; + struct drm_connector *connector; struct drm_encoder *encoder; struct vkms_config_encoder *encoder_cfg; struct vkms_crtc *vkms_crtc; @@ -117,14 +142,9 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index) } } - ret = drm_connector_init(dev, connector, &vkms_connector_funcs, - DRM_MODE_CONNECTOR_VIRTUAL); - if (ret) { - DRM_ERROR("Failed to init connector\n"); - return ret; - } - - drm_connector_helper_add(connector, &vkms_conn_helper_funcs); + connector = vkms_connector_init(vkmsdev, BIT(index)); + if (IS_ERR(connector)) + return PTR_ERR(connector); list_for_each_entry(encoder_cfg, &vkmsdev->config->encoders, list) { encoder = vkms_encoder_init(vkmsdev, encoder_cfg->possible_crtcs, @@ -133,18 +153,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index) return PTR_ERR(encoder); } - ret = drm_connector_attach_encoder(connector, encoder); - if (ret) { - DRM_ERROR("Failed to attach connector to encoder\n"); - goto err_attach; - } - drm_mode_config_reset(dev); return 0; - -err_attach: - drm_connector_cleanup(connector); - - return ret; }
A future patch will allow to create multiple connectors. Use managed memory to simplify the code. Refactor, no functional changes. Signed-off-by: José Expósito <jose.exposito89@gmail.com> --- drivers/gpu/drm/vkms/vkms_drv.h | 5 --- drivers/gpu/drm/vkms/vkms_output.c | 53 +++++++++++++++++------------- 2 files changed, 31 insertions(+), 27 deletions(-)