public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "José Expósito" <jose.exposito89@gmail.com>
To: rodrigosiqueiramelo@gmail.com
Cc: melissa.srw@gmail.com, mairacanal@riseup.net,
	hamohammed.sa@gmail.com, daniel@ffwll.ch,
	maarten.lankhorst@linux.intel.com, mripard@kernel.org,
	tzimmermann@suse.de, airlied@gmail.com,
	dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org,
	louis.chauvet@bootlin.com,
	"José Expósito" <jose.exposito89@gmail.com>
Subject: [RFC PATCH 01/17] drm/vkms: Extract vkms_config header
Date: Tue, 13 Aug 2024 12:44:12 +0200	[thread overview]
Message-ID: <20240813105134.17439-2-jose.exposito89@gmail.com> (raw)
In-Reply-To: <20240813105134.17439-1-jose.exposito89@gmail.com>

Creating a new vkms_config structure will be more complex once we
start adding more options.

Extract the vkms_config structure to its own header and source files
and add functions to create and delete a vkms_config and to initialize
debugfs.

Refactor, no functional changes.

Signed-off-by: José Expósito <jose.exposito89@gmail.com>
---
 drivers/gpu/drm/vkms/Makefile      |  3 +-
 drivers/gpu/drm/vkms/vkms_config.c | 48 ++++++++++++++++++++++++++++++
 drivers/gpu/drm/vkms/vkms_config.h | 25 ++++++++++++++++
 drivers/gpu/drm/vkms/vkms_drv.c    | 34 +++++----------------
 drivers/gpu/drm/vkms/vkms_drv.h    | 10 +------
 drivers/gpu/drm/vkms/vkms_output.c |  1 +
 6 files changed, 84 insertions(+), 37 deletions(-)
 create mode 100644 drivers/gpu/drm/vkms/vkms_config.c
 create mode 100644 drivers/gpu/drm/vkms/vkms_config.h

diff --git a/drivers/gpu/drm/vkms/Makefile b/drivers/gpu/drm/vkms/Makefile
index 1b28a6a32948..b371b5d70ee3 100644
--- a/drivers/gpu/drm/vkms/Makefile
+++ b/drivers/gpu/drm/vkms/Makefile
@@ -6,6 +6,7 @@ vkms-y := \
 	vkms_formats.o \
 	vkms_crtc.o \
 	vkms_composer.o \
-	vkms_writeback.o
+	vkms_writeback.o \
+	vkms_config.o
 
 obj-$(CONFIG_DRM_VKMS) += vkms.o
diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c
new file mode 100644
index 000000000000..c58eda76c238
--- /dev/null
+++ b/drivers/gpu/drm/vkms/vkms_config.c
@@ -0,0 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <linux/slab.h>
+
+#include <drm/drm_print.h>
+#include <drm/drm_debugfs.h>
+
+#include "vkms_config.h"
+#include "vkms_drv.h"
+
+struct vkms_config *vkms_config_create(void)
+{
+	struct vkms_config *config;
+
+	config = kzalloc(sizeof(*config), GFP_KERNEL);
+	if (!config)
+		return ERR_PTR(-ENOMEM);
+
+	return config;
+}
+
+void vkms_config_destroy(struct vkms_config *config)
+{
+	kfree(config);
+}
+
+static int vkms_config_show(struct seq_file *m, void *data)
+{
+	struct drm_debugfs_entry *entry = m->private;
+	struct drm_device *dev = entry->dev;
+	struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev);
+
+	seq_printf(m, "writeback=%d\n", vkmsdev->config->writeback);
+	seq_printf(m, "cursor=%d\n", vkmsdev->config->cursor);
+	seq_printf(m, "overlay=%d\n", vkmsdev->config->overlay);
+
+	return 0;
+}
+
+static const struct drm_debugfs_info vkms_config_debugfs_list[] = {
+	{ "vkms_config", vkms_config_show, 0 },
+};
+
+void vkms_config_debugfs_init(struct vkms_device *vkms_device)
+{
+	drm_debugfs_add_files(&vkms_device->drm, vkms_config_debugfs_list,
+			      ARRAY_SIZE(vkms_config_debugfs_list));
+}
diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h
new file mode 100644
index 000000000000..65da8cd6ff96
--- /dev/null
+++ b/drivers/gpu/drm/vkms/vkms_config.h
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+
+#ifndef _VKMS_CONFIG_H_
+#define _VKMS_CONFIG_H_
+
+#include <linux/types.h>
+
+struct vkms_device;
+
+struct vkms_config {
+	bool writeback;
+	bool cursor;
+	bool overlay;
+	/* only set when instantiated */
+	struct vkms_device *dev;
+};
+
+/* VKMS Config */
+struct vkms_config *vkms_config_create(void);
+void vkms_config_destroy(struct vkms_config *config);
+
+/* DebugFS */
+void vkms_config_debugfs_init(struct vkms_device *vkms_device);
+
+#endif /* _VKMS_CONFIG_H_ */
diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c
index 8dc9dc13896e..6bf462985731 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.c
+++ b/drivers/gpu/drm/vkms/vkms_drv.c
@@ -26,11 +26,9 @@
 #include <drm/drm_gem_shmem_helper.h>
 #include <drm/drm_vblank.h>
 
+#include "vkms_config.h"
 #include "vkms_drv.h"
 
-#include <drm/drm_print.h>
-#include <drm/drm_debugfs.h>
-
 #define DRIVER_NAME	"vkms"
 #define DRIVER_DESC	"Virtual Kernel Mode Setting"
 #define DRIVER_DATE	"20180514"
@@ -90,23 +88,6 @@ static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state)
 	drm_atomic_helper_cleanup_planes(dev, old_state);
 }
 
-static int vkms_config_show(struct seq_file *m, void *data)
-{
-	struct drm_debugfs_entry *entry = m->private;
-	struct drm_device *dev = entry->dev;
-	struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev);
-
-	seq_printf(m, "writeback=%d\n", vkmsdev->config->writeback);
-	seq_printf(m, "cursor=%d\n", vkmsdev->config->cursor);
-	seq_printf(m, "overlay=%d\n", vkmsdev->config->overlay);
-
-	return 0;
-}
-
-static const struct drm_debugfs_info vkms_config_debugfs_list[] = {
-	{ "vkms_config", vkms_config_show, 0 },
-};
-
 static const struct drm_driver vkms_driver = {
 	.driver_features	= DRIVER_MODESET | DRIVER_ATOMIC | DRIVER_GEM,
 	.release		= vkms_release,
@@ -216,8 +197,7 @@ static int vkms_create(struct vkms_config *config)
 	if (ret)
 		goto out_devres;
 
-	drm_debugfs_add_files(&vkms_device->drm, vkms_config_debugfs_list,
-			      ARRAY_SIZE(vkms_config_debugfs_list));
+	vkms_config_debugfs_init(vkms_device);
 
 	ret = drm_dev_register(&vkms_device->drm, 0);
 	if (ret)
@@ -239,9 +219,9 @@ static int __init vkms_init(void)
 	int ret;
 	struct vkms_config *config;
 
-	config = kmalloc(sizeof(*config), GFP_KERNEL);
-	if (!config)
-		return -ENOMEM;
+	config = vkms_config_create();
+	if (IS_ERR(config))
+		return PTR_ERR(config);
 
 	default_config = config;
 
@@ -251,7 +231,7 @@ static int __init vkms_init(void)
 
 	ret = vkms_create(config);
 	if (ret)
-		kfree(config);
+		vkms_config_destroy(config);
 
 	return ret;
 }
@@ -280,7 +260,7 @@ static void __exit vkms_exit(void)
 	if (default_config->dev)
 		vkms_destroy(default_config);
 
-	kfree(default_config);
+	vkms_config_destroy(default_config);
 }
 
 module_init(vkms_init);
diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h
index 5e46ea5b96dc..5c523ca27f22 100644
--- a/drivers/gpu/drm/vkms/vkms_drv.h
+++ b/drivers/gpu/drm/vkms/vkms_drv.h
@@ -115,15 +115,7 @@ struct vkms_output {
 	spinlock_t composer_lock;
 };
 
-struct vkms_device;
-
-struct vkms_config {
-	bool writeback;
-	bool cursor;
-	bool overlay;
-	/* only set when instantiated */
-	struct vkms_device *dev;
-};
+struct vkms_config;
 
 struct vkms_device {
 	struct drm_device drm;
diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c
index 5ce70dd946aa..afe3945c1962 100644
--- a/drivers/gpu/drm/vkms/vkms_output.c
+++ b/drivers/gpu/drm/vkms/vkms_output.c
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 
+#include "vkms_config.h"
 #include "vkms_drv.h"
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_edid.h>
-- 
2.46.0


  reply	other threads:[~2024-08-13 10:51 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-13 10:44 [RFC PATCH 00/17] VKMS: Add configfs support José Expósito
2024-08-13 10:44 ` José Expósito [this message]
2024-08-13 10:44 ` [RFC PATCH 02/17] drm/vkms: Move default_config creation to its own function José Expósito
2024-08-13 10:44 ` [RFC PATCH 03/17] drm/vkms: Set device name from vkms_config José Expósito
2024-08-13 17:58   ` Louis Chauvet
2024-08-13 10:44 ` [RFC PATCH 04/17] drm/vkms: Allow to configure multiple CRTCs José Expósito
2024-08-13 17:58   ` Louis Chauvet
2024-08-13 10:44 ` [RFC PATCH 05/17] drm/vkms: Use managed memory to create encoders José Expósito
2024-08-13 17:58   ` Louis Chauvet
2024-08-13 10:44 ` [RFC PATCH 06/17] drm/vkms: Allow to configure multiple encoders José Expósito
2024-08-13 17:58   ` Louis Chauvet
2024-08-13 10:44 ` [RFC PATCH 07/17] drm/vkms: Use managed memory to create connectors José Expósito
2024-08-13 17:58   ` Louis Chauvet
2024-08-13 10:44 ` [RFC PATCH 08/17] drm/vkms: Allow to configure multiple connectors José Expósito
2024-08-13 17:58   ` Louis Chauvet
2024-08-13 10:44 ` [RFC PATCH 09/17] drm/vkms: Allow to configure multiple overlay planes José Expósito
2024-08-13 17:58   ` Louis Chauvet
2024-08-13 10:44 ` [RFC PATCH 10/17] drm/vkms: Allow to change connector status José Expósito
2024-08-13 17:58   ` Louis Chauvet
2024-08-13 10:44 ` [RFC PATCH 11/17] drm/vkms: Add and remove VKMS instances via configfs José Expósito
2024-08-13 17:58   ` Louis Chauvet
2024-08-13 10:44 ` [RFC PATCH 12/17] drm/vkms: Allow to configure multiple CRTCs " José Expósito
2024-08-13 17:58   ` Louis Chauvet
2024-08-13 10:44 ` [RFC PATCH 13/17] drm/vkms: Allow to configure multiple encoders " José Expósito
2024-08-13 17:58   ` Louis Chauvet
2024-08-13 10:44 ` [RFC PATCH 14/17] drm/vkms: Allow to configure multiple encoders José Expósito
2024-08-13 17:59   ` Louis Chauvet
2024-08-13 10:44 ` [RFC PATCH 15/17] drm/vkms: Allow to configure multiple planes via configfs José Expósito
2024-08-13 17:59   ` Louis Chauvet
2024-08-13 10:44 ` [RFC PATCH 16/17] drm/vkms: Allow to configure the default device creation José Expósito
2024-08-13 10:44 ` [RFC PATCH 17/17] drm/vkms: Remove completed task from the TODO list José Expósito
2024-08-13 17:58 ` [RFC PATCH 00/17] VKMS: Add configfs support Louis Chauvet
2024-08-20 15:52   ` José Expósito
2024-08-14  9:10 ` Daniel Stone
2024-08-20 16:03   ` José Expósito

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240813105134.17439-2-jose.exposito89@gmail.com \
    --to=jose.exposito89@gmail.com \
    --cc=airlied@gmail.com \
    --cc=daniel@ffwll.ch \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=hamohammed.sa@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=louis.chauvet@bootlin.com \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mairacanal@riseup.net \
    --cc=melissa.srw@gmail.com \
    --cc=mripard@kernel.org \
    --cc=rodrigosiqueiramelo@gmail.com \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox