[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20240813105134.17439-6-jose.exposito89@gmail.com>
Date: Tue, 13 Aug 2024 12:44:16 +0200
From: José Expósito <jose.exposito89@...il.com>
To: rodrigosiqueiramelo@...il.com
Cc: melissa.srw@...il.com,
mairacanal@...eup.net,
hamohammed.sa@...il.com,
daniel@...ll.ch,
maarten.lankhorst@...ux.intel.com,
mripard@...nel.org,
tzimmermann@...e.de,
airlied@...il.com,
dri-devel@...ts.freedesktop.org,
linux-kernel@...r.kernel.org,
louis.chauvet@...tlin.com,
José Expósito <jose.exposito89@...il.com>
Subject: [RFC PATCH 05/17] drm/vkms: Use managed memory to create encoders
A future patch will allow to create multiple encoders. Use managed
memory to simplify the code.
Refactor, no functional changes.
Signed-off-by: José Expósito <jose.exposito89@...il.com>
---
drivers/gpu/drm/vkms/vkms_drv.h | 1 -
drivers/gpu/drm/vkms/vkms_output.c | 45 ++++++++++++++++++++----------
2 files changed, 30 insertions(+), 16 deletions(-)
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 3156ff896c33..2466e8b0231f 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -122,7 +122,6 @@ struct vkms_crtc {
struct vkms_config;
struct vkms_output {
- struct drm_encoder encoder;
struct drm_connector connector;
};
diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c
index dcd32bc30e17..15f0b72af325 100644
--- a/drivers/gpu/drm/vkms/vkms_output.c
+++ b/drivers/gpu/drm/vkms/vkms_output.c
@@ -4,6 +4,7 @@
#include "vkms_drv.h"
#include <drm/drm_atomic_helper.h>
#include <drm/drm_edid.h>
+#include <drm/drm_managed.h>
#include <drm/drm_probe_helper.h>
static const struct drm_connector_funcs vkms_connector_funcs = {
@@ -14,10 +15,6 @@ static const struct drm_connector_funcs vkms_connector_funcs = {
.atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
};
-static const struct drm_encoder_funcs vkms_encoder_funcs = {
- .destroy = drm_encoder_cleanup,
-};
-
static int vkms_conn_get_modes(struct drm_connector *connector)
{
int count;
@@ -32,6 +29,31 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
.get_modes = vkms_conn_get_modes,
};
+static struct drm_encoder *vkms_encoder_init(struct vkms_device *vkms_device,
+ uint32_t possible_crtcs)
+{
+ struct drm_encoder *encoder;
+ int ret;
+
+ encoder = drmm_kzalloc(&vkms_device->drm, sizeof(*encoder), GFP_KERNEL);
+ if (!encoder) {
+ DRM_ERROR("Failed to allocate encoder\n");
+ return ERR_PTR(-ENOMEM);
+ }
+
+ ret = drmm_encoder_init(&vkms_device->drm, encoder, NULL,
+ DRM_MODE_ENCODER_VIRTUAL, NULL);
+ if (ret) {
+ DRM_ERROR("Failed to init encoder\n");
+ kfree(encoder);
+ return ERR_PTR(ret);
+ }
+
+ encoder->possible_crtcs = possible_crtcs;
+
+ return encoder;
+}
+
static int vkms_add_overlay_plane(struct vkms_device *vkmsdev, int index)
{
struct vkms_plane *overlay;
@@ -51,7 +73,7 @@ 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_encoder *encoder = &output->encoder;
+ struct drm_encoder *encoder;
struct vkms_crtc *vkms_crtc;
struct vkms_config_crtc *crtc_cfg;
struct vkms_plane *primary, *cursor = NULL;
@@ -101,13 +123,9 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
- ret = drm_encoder_init(dev, encoder, &vkms_encoder_funcs,
- DRM_MODE_ENCODER_VIRTUAL, NULL);
- if (ret) {
- DRM_ERROR("Failed to init encoder\n");
- goto err_encoder;
- }
- encoder->possible_crtcs = 1;
+ encoder = vkms_encoder_init(vkmsdev, BIT(0));
+ if (IS_ERR(encoder))
+ return PTR_ERR(encoder);
ret = drm_connector_attach_encoder(connector, encoder);
if (ret) {
@@ -120,9 +138,6 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
return 0;
err_attach:
- drm_encoder_cleanup(encoder);
-
-err_encoder:
drm_connector_cleanup(connector);
return ret;
--
2.46.0
Powered by blists - more mailing lists