]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/vkms: Set device name from vkms_config
authorJosé Expósito <jose.exposito89@gmail.com>
Tue, 18 Feb 2025 10:12:06 +0000 (11:12 +0100)
committerMaxime Ripard <mripard@kernel.org>
Fri, 7 Mar 2025 09:58:22 +0000 (10:58 +0100)
In order to be able to create multiple devices, the device name needs to
be unique.

Allow to set it in the VKMS configuration.

Reviewed-by: Louis Chauvet <louis.chauvet@bootlin.com>
Signed-off-by: José Expósito <jose.exposito89@gmail.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20250218101214.5790-7-jose.exposito89@gmail.com
Signed-off-by: Maxime Ripard <mripard@kernel.org>
drivers/gpu/drm/vkms/tests/vkms_config_test.c
drivers/gpu/drm/vkms/vkms_config.c
drivers/gpu/drm/vkms/vkms_config.h
drivers/gpu/drm/vkms/vkms_drv.c
drivers/gpu/drm/vkms/vkms_drv.h

index d8644a1e3e181b6bad14ba6a5e5cbf228544975d..92798590051b3e78715958e8ef2df5b77c0473d6 100644 (file)
@@ -15,10 +15,15 @@ struct default_config_case {
 static void vkms_config_test_empty_config(struct kunit *test)
 {
        struct vkms_config *config;
+       const char *dev_name = "test";
 
-       config = vkms_config_create();
+       config = vkms_config_create(dev_name);
        KUNIT_ASSERT_NOT_ERR_OR_NULL(test, config);
 
+       /* The dev_name string and the config have different lifetimes */
+       dev_name = NULL;
+       KUNIT_EXPECT_STREQ(test, vkms_config_get_device_name(config), "test");
+
        vkms_config_destroy(config);
 }
 
index 0af8e6dc0a017e4ea292df5fb37c9376a2569756..9fb08d94a35158f512e657be0cb320e4b975c918 100644 (file)
@@ -8,7 +8,7 @@
 
 #include "vkms_config.h"
 
-struct vkms_config *vkms_config_create(void)
+struct vkms_config *vkms_config_create(const char *dev_name)
 {
        struct vkms_config *config;
 
@@ -16,6 +16,12 @@ struct vkms_config *vkms_config_create(void)
        if (!config)
                return ERR_PTR(-ENOMEM);
 
+       config->dev_name = kstrdup_const(dev_name, GFP_KERNEL);
+       if (!config->dev_name) {
+               kfree(config);
+               return ERR_PTR(-ENOMEM);
+       }
+
        return config;
 }
 EXPORT_SYMBOL_IF_KUNIT(vkms_config_create);
@@ -26,7 +32,7 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor,
 {
        struct vkms_config *config;
 
-       config = vkms_config_create();
+       config = vkms_config_create(DEFAULT_DEVICE_NAME);
        if (IS_ERR(config))
                return config;
 
@@ -40,6 +46,7 @@ EXPORT_SYMBOL_IF_KUNIT(vkms_config_default_create);
 
 void vkms_config_destroy(struct vkms_config *config)
 {
+       kfree_const(config->dev_name);
        kfree(config);
 }
 EXPORT_SYMBOL_IF_KUNIT(vkms_config_destroy);
@@ -49,7 +56,10 @@ 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);
+       const char *dev_name;
 
+       dev_name = vkms_config_get_device_name((struct vkms_config *)vkmsdev->config);
+       seq_printf(m, "dev_name=%s\n", dev_name);
        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);
index d0868750826a38bc8b04a6de4b7ab4c2e2c045b9..fcaa909fb2e00c51c6355bd6e731f41e0c4ba38d 100644 (file)
 /**
  * struct vkms_config - General configuration for VKMS driver
  *
+ * @dev_name: Name of the device
  * @writeback: If true, a writeback buffer can be attached to the CRTC
  * @cursor: If true, a cursor plane is created in the VKMS device
  * @overlay: If true, NUM_OVERLAY_PLANES will be created for the VKMS device
  * @dev: Used to store the current VKMS device. Only set when the device is instantiated.
  */
 struct vkms_config {
+       const char *dev_name;
        bool writeback;
        bool cursor;
        bool overlay;
@@ -24,12 +26,13 @@ struct vkms_config {
 
 /**
  * vkms_config_create() - Create a new VKMS configuration
+ * @dev_name: Name of the device
  *
  * Returns:
  * The new vkms_config or an error. Call vkms_config_destroy() to free the
  * returned configuration.
  */
-struct vkms_config *vkms_config_create(void);
+struct vkms_config *vkms_config_create(const char *dev_name);
 
 /**
  * vkms_config_default_create() - Create the configuration for the default device
@@ -51,6 +54,19 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor,
  */
 void vkms_config_destroy(struct vkms_config *config);
 
+/**
+ * vkms_config_get_device_name() - Return the name of the device
+ * @config: Configuration to get the device name from
+ *
+ * Returns:
+ * The device name. Only valid while @config is valid.
+ */
+static inline const char *
+vkms_config_get_device_name(struct vkms_config *config)
+{
+       return config->dev_name;
+}
+
 /**
  * vkms_config_register_debugfs() - Register a debugfs file to show the device's
  * configuration
index 582d5825f42b94be40ccd7b889481eccdd48fb1e..ba977ef09b2b87d026d6e2a49bae960a50889553 100644 (file)
@@ -151,8 +151,10 @@ static int vkms_create(struct vkms_config *config)
        int ret;
        struct platform_device *pdev;
        struct vkms_device *vkms_device;
+       const char *dev_name;
 
-       pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
+       dev_name = vkms_config_get_device_name(config);
+       pdev = platform_device_register_simple(dev_name, -1, NULL, 0);
        if (IS_ERR(pdev))
                return PTR_ERR(pdev);
 
index af7081c940d6c074dc01cf8180556a3d902e386d..a74a7fc3a056b0244f88bbfb7bd1694e3329026c 100644 (file)
@@ -12,6 +12,8 @@
 #include <drm/drm_encoder.h>
 #include <drm/drm_writeback.h>
 
+#define DEFAULT_DEVICE_NAME "vkms"
+
 #define XRES_MIN    10
 #define YRES_MIN    10