[PATCH 1/2] drm/vkms: Add enable/disable functions per connector
From: Rodrigo Siqueira
Date: Sun Jun 30 2019 - 23:24:21 EST
Currently, virtual and writeback connectors have the code responsible
for initialization and cleanup spread around different places in vkms.
This patch creates an enable and disable function per connector which
allows vkms to hotplug connectors easily.
Signed-off-by: Rodrigo Siqueira <rodrigosiqueiramelo@xxxxxxxxx>
---
drivers/gpu/drm/vkms/vkms_drv.h | 5 ++
drivers/gpu/drm/vkms/vkms_output.c | 84 +++++++++++++++++----------
drivers/gpu/drm/vkms/vkms_writeback.c | 31 ++++++++--
3 files changed, 83 insertions(+), 37 deletions(-)
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 9ff2cd4ebf81..a1ca5c658355 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -152,7 +152,12 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name,
/* Composer Support */
void vkms_composer_worker(struct work_struct *work);
+/* Virtual connector */
+int enable_virtual_connector(struct vkms_device *vkmsdev);
+void disable_virtual_connector(struct vkms_device *vkmsdev);
+
/* Writeback */
int enable_writeback_connector(struct vkms_device *vkmsdev);
+void disable_writeback_connector(struct vkms_device *connector);
#endif /* _VKMS_DRV_H_ */
diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c
index aea1d4410864..26ecab52e82e 100644
--- a/drivers/gpu/drm/vkms/vkms_output.c
+++ b/drivers/gpu/drm/vkms/vkms_output.c
@@ -6,6 +6,7 @@
static void vkms_connector_destroy(struct drm_connector *connector)
{
+ drm_connector_unregister(connector);
drm_connector_cleanup(connector);
}
@@ -35,37 +36,19 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
.get_modes = vkms_conn_get_modes,
};
-int vkms_output_init(struct vkms_device *vkmsdev, int index)
+int enable_virtual_connector(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 drm_plane *primary, *cursor = NULL;
+ struct drm_device *dev = &vkmsdev->drm;
int ret;
- primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
- if (IS_ERR(primary))
- return PTR_ERR(primary);
-
- if (enable_cursor) {
- cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index);
- if (IS_ERR(cursor)) {
- ret = PTR_ERR(cursor);
- goto err_cursor;
- }
- }
-
- ret = vkms_crtc_init(dev, crtc, primary, cursor);
- if (ret)
- goto err_crtc;
-
ret = drm_connector_init(dev, connector, &vkms_connector_funcs,
DRM_MODE_CONNECTOR_VIRTUAL);
if (ret) {
DRM_ERROR("Failed to init connector\n");
- goto err_connector;
+ return ret;
}
drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
@@ -84,17 +67,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
goto err_attach;
}
- if (enable_writeback) {
- ret = enable_writeback_connector(vkmsdev);
- if (!ret) {
- output->composer_enabled = true;
- DRM_INFO("Writeback connector enabled");
- } else {
- DRM_ERROR("Failed to init writeback connector\n");
- }
- }
-
- drm_mode_config_reset(dev);
+ drm_connector_register(connector);
return 0;
@@ -104,6 +77,53 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
err_encoder:
drm_connector_cleanup(connector);
+ return ret;
+}
+
+void disable_virtual_connector(struct vkms_device *vkmsdev)
+{
+ struct vkms_output *output = &vkmsdev->output;
+
+ drm_connector_unregister(&output->connector);
+ drm_connector_cleanup(&output->connector);
+ drm_encoder_cleanup(&output->encoder);
+}
+
+int vkms_output_init(struct vkms_device *vkmsdev, int index)
+{
+ struct vkms_output *output = &vkmsdev->output;
+ struct drm_device *dev = &vkmsdev->drm;
+ struct drm_crtc *crtc = &output->crtc;
+ struct drm_plane *primary, *cursor = NULL;
+ int ret;
+
+ primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
+ if (IS_ERR(primary))
+ return PTR_ERR(primary);
+
+ if (enable_cursor) {
+ cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index);
+ if (IS_ERR(cursor)) {
+ ret = PTR_ERR(cursor);
+ goto err_cursor;
+ }
+ }
+
+ ret = vkms_crtc_init(dev, crtc, primary, cursor);
+ if (ret)
+ goto err_crtc;
+
+ ret = enable_virtual_connector(vkmsdev);
+ if (ret)
+ goto err_connector;
+
+ if (enable_writeback)
+ enable_writeback_connector(vkmsdev);
+
+ drm_mode_config_reset(dev);
+
+ return 0;
+
err_connector:
drm_crtc_cleanup(crtc);
diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c
index 34dad37a0236..6a3f37d60c1d 100644
--- a/drivers/gpu/drm/vkms/vkms_writeback.c
+++ b/drivers/gpu/drm/vkms/vkms_writeback.c
@@ -125,17 +125,38 @@ static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = {
.atomic_commit = vkms_wb_atomic_commit,
};
+void disable_writeback_connector(struct vkms_device *vkmsdev)
+{
+ struct vkms_output *output = &vkmsdev->output;
+
+ output->composer_enabled = false;
+ drm_connector_unregister(&output->wb_connector.base);
+ drm_connector_cleanup(&output->wb_connector.base);
+ drm_encoder_cleanup(&output->wb_connector.encoder);
+}
+
int enable_writeback_connector(struct vkms_device *vkmsdev)
{
struct drm_writeback_connector *wb = &vkmsdev->output.wb_connector;
+ int ret;
vkmsdev->output.wb_connector.encoder.possible_crtcs = 1;
drm_connector_helper_add(&wb->base, &vkms_wb_conn_helper_funcs);
- return drm_writeback_connector_init(&vkmsdev->drm, wb,
- &vkms_wb_connector_funcs,
- &vkms_wb_encoder_helper_funcs,
- vkms_wb_formats,
- ARRAY_SIZE(vkms_wb_formats));
+ ret = drm_writeback_connector_init(&vkmsdev->drm, wb,
+ &vkms_wb_connector_funcs,
+ &vkms_wb_encoder_helper_funcs,
+ vkms_wb_formats,
+ ARRAY_SIZE(vkms_wb_formats));
+ if (!ret) {
+ vkmsdev->output.composer_enabled = true;
+ DRM_INFO("Writeback connector enabled");
+ } else {
+ DRM_ERROR("Failed to init writeback connector\n");
+ }
+
+ drm_connector_register(&wb->base);
+
+ return ret;
}
--
2.21.0