Skip to contentSkip to conversation

Adds support for ConfigFS to VKMS!

PATCH In review Jim Shargo 5 participants 26 messages Jun 23, 2023 – Aug 18, 2023

Subsystems (4)
lore
Share & tools
lore

Jim Shargo

author
#0 lore raw

v2 cover Adds support for ConfigFS to VKMS!

Intro
=====

At long last, we're back!

This patchset adds basic ConfigFS support to VKMS, allowing users to build new DRM devices with user-defined DRM objects and object relationships by creating, writing, and symlinking files.

Usage
=====

After installing these patches, you can create a VKMS device with two displays and a movable overlay like so (this is documented in the patches):

  $ modprobe vkms enable_overlay=1 enable_cursor=1 enable_writeback=1
  $ mkdir -p /config/
  $ mount -t configfs none /config
  $ export DRM_PLANE_TYPE_PRIMARY=1
  $ export DRM_PLANE_TYPE_CURSOR=2
  $ export DRM_PLANE_TYPE_OVERLAY=0
  $ mkdir /config/vkms/test
  $ mkdir /config/vkms/test/planes/primary
  $ echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/primary/type
  $ mkdir /config/vkms/test/planes/other_primary
  $ echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/other_primary/type
  $ mkdir /config/vkms/test/planes/cursor
  $ echo $DRM_PLANE_TYPE_CURSOR > /config/vkms/test/planes/cursor/type
  $ mkdir /config/vkms/test/planes/overlay
  $ echo $DRM_PLANE_TYPE_OVERLAY > /config/vkms/test/planes/overlay/type
  $ mkdir /config/vkms/test/crtcs/crtc
  $ mkdir /config/vkms/test/crtcs/crtc_other
  $ mkdir /config/vkms/test/encoders/encoder
  $ mkdir /config/vkms/test/connectors/connector
  $ ln -s /config/vkms/test/encoders/encoder /config/vkms/test/connectors/connector/possible_encoders
  $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/encoders/encoder/possible_crtcs/
  $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/primary/possible_crtcs/
  $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/cursor/possible_crtcs/
  $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/overlay/possible_crtcs/
  $ ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/overlay/possible_crtcs/
  $ ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/other_primary/possible_crtcs/
  $ echo 1 > /config/vkms/test/enabled

Changes within core VKMS
========================

This introduces a few important changes to the overall structure of VKMS:

- Devices are now memory managed!
- Support for multiple CRTCs and other objects has been added

Since v1
========

- Added DRMM memory management to automatically clean up resources
- Added a param to disable the default device
- Renamed "cards" to "devices" to improve legibility
- Added a lock for the configfs setup handler
- Moved all the new docs into the relevant .c file
- Addressed as many of [email protected] as possible

Testing
=======

- New IGT tests (see gitlab.freedesktop.org/jshargo/igt-gpu-tools/-/merge_requests/1)
- Existing IGT tests (excluding .*suspend.*, including .*kms_flip.*

    .*kms_writeback.* .*kms_cursor_crc.*, .*kms_plane.*)

Outro
=====

I'm excited to share these changes, it's my still my first kernel patch and I've been putting a lot of love into these.

Jim Shargo (6):
drm/vkms: Back VKMS with DRM memory management instead of static
objects
drm/vkms: Support multiple DRM objects (crtcs, etc.) per VKMS device drm/vkms: Provide platform data when creating VKMS devices drm/vkms: Add ConfigFS scaffolding to VKMS
drm/vkms: Support enabling ConfigFS devices
drm/vkms: Add a module param to enable/disable the default device

 Documentation/gpu/vkms.rst            |  17 +-
 drivers/gpu/drm/Kconfig               |   1 +
 drivers/gpu/drm/vkms/Makefile         |   1 +
 drivers/gpu/drm/vkms/vkms_composer.c  |  28 +-
 drivers/gpu/drm/vkms/vkms_configfs.c  | 657 ++++++++++++++++++++++++++
 drivers/gpu/drm/vkms/vkms_crtc.c      |  97 ++--
 drivers/gpu/drm/vkms/vkms_drv.c       | 208 +++++---
 drivers/gpu/drm/vkms/vkms_drv.h       | 166 +++++--
 drivers/gpu/drm/vkms/vkms_output.c    | 299 ++++++++++--
 drivers/gpu/drm/vkms/vkms_plane.c     |  44 +-
 drivers/gpu/drm/vkms/vkms_writeback.c |  26 +-
 11 files changed, 1312 insertions(+), 232 deletions(-)
 create mode 100644 drivers/gpu/drm/vkms/vkms_configfs.c
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
author
#1 lore raw

PATCH v2 1/6 drm/vkms: Back VKMS with DRM memory management instead of static objects

This is a small refactor to make ConfigFS support easier. Once we support ConfigFS, there can be multiple devices instantiated by the driver, and so moving everything into managed memory makes things much easier.

This should be a no-op refactor.

---
 drivers/gpu/drm/vkms/vkms_drv.c    | 130 +++++++++++++++--------------
 drivers/gpu/drm/vkms/vkms_drv.h    |   4 +-
 drivers/gpu/drm/vkms/vkms_output.c |   6 +-
 3 files changed, 72 insertions(+), 68 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.c +68 -62
index e3c9c9571c8d..f07454fff046 100644
@@ -9,10 +9,12 @@
  * the GPU in DRM API tests.
  */
 
+#include <linux/device.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
 #include <linux/dma-mapping.h>
 
+#include <drm/drm_device.h>
 #include <drm/drm_gem.h>
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
@@ -37,8 +39,6 @@
 #define DRIVER_MAJOR	1
 #define DRIVER_MINOR	0
 
-static struct vkms_config *default_config;
-
 static bool enable_cursor = true;
 module_param_named(enable_cursor, enable_cursor, bool, 0444);
 MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");
@@ -92,13 +92,13 @@ static void vkms_atomic_commit_tail(struct drm_atomic_state *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);
+	struct drm_info_node *drm_info = m->private;
+	struct vkms_device *vkms_device =
+		drm_device_to_vkms_device(drm_info->minor->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);
+	seq_printf(m, "writeback=%d\n", vkms_device->config.writeback);
+	seq_printf(m, "cursor=%d\n", vkms_device->config.cursor);
+	seq_printf(m, "overlay=%d\n", vkms_device->config.overlay);
 
 	return 0;
 }
@@ -155,114 +155,120 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev)
 	return vkms_output_init(vkmsdev, 0);
 }
 
-static int vkms_create(struct vkms_config *config)
+static int vkms_platform_probe(struct platform_device *pdev)
 {
 	int ret;
-	struct platform_device *pdev;
 	struct vkms_device *vkms_device;
+	void *grp;
 
-	pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
-	if (IS_ERR(pdev))
-		return PTR_ERR(pdev);
-
-	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) {
-		ret = -ENOMEM;
-		goto out_unregister;
+	grp = devres_open_group(&pdev->dev, NULL, GFP_KERNEL);
+	if (!grp) {
+		return -ENOMEM;
 	}
 
 	vkms_device = devm_drm_dev_alloc(&pdev->dev, &vkms_driver,
 					 struct vkms_device, drm);
 	if (IS_ERR(vkms_device)) {
 		ret = PTR_ERR(vkms_device);
-		goto out_devres;
+		goto out_release_group;
 	}
+
 	vkms_device->platform = pdev;
-	vkms_device->config = config;
-	config->dev = vkms_device;
+	vkms_device->config.cursor = enable_cursor;
+	vkms_device->config.writeback = enable_writeback;
+	vkms_device->config.overlay = enable_overlay;
 
 	ret = dma_coerce_mask_and_coherent(vkms_device->drm.dev,
 					   DMA_BIT_MASK(64));
-
 	if (ret) {
 		DRM_ERROR("Could not initialize DMA support\n");
-		goto out_devres;
+		goto out_release_group;
 	}
 
 	ret = drm_vblank_init(&vkms_device->drm, 1);
 	if (ret) {
 		DRM_ERROR("Failed to vblank\n");
-		goto out_devres;
+		goto out_release_group;
 	}
 
 	ret = vkms_modeset_init(vkms_device);
-	if (ret)
-		goto out_devres;
+	if (ret) {
+		DRM_ERROR("Unable to initialize modesetting\n");
+		goto out_release_group;
+	}
 
 	drm_debugfs_add_files(&vkms_device->drm, vkms_config_debugfs_list,
 			      ARRAY_SIZE(vkms_config_debugfs_list));
 
 	ret = drm_dev_register(&vkms_device->drm, 0);
-	if (ret)
-		goto out_devres;
+	if (ret) {
+		DRM_ERROR("Unable to register device\n");
+		return ret;
+	}
 
 	drm_fbdev_generic_setup(&vkms_device->drm, 0);
+	platform_set_drvdata(pdev, vkms_device);
+	devres_close_group(&pdev->dev, grp);
 
 	return 0;
 
-out_devres:
-	devres_release_group(&pdev->dev, NULL);
-out_unregister:
-	platform_device_unregister(pdev);
+out_release_group:
+	devres_release_group(&pdev->dev, grp);
 	return ret;
 }
 
-static int __init vkms_init(void)
+static int vkms_platform_remove(struct platform_device *pdev)
 {
-	int ret;
-	struct vkms_config *config;
-
-	config = kmalloc(sizeof(*config), GFP_KERNEL);
-	if (!config)
-		return -ENOMEM;
-
-	default_config = config;
+	struct vkms_device *vkms_device;
 
-	config->cursor = enable_cursor;
-	config->writeback = enable_writeback;
-	config->overlay = enable_overlay;
+	vkms_device = platform_get_drvdata(pdev);
+	if (!vkms_device)
+		return 0;
 
-	ret = vkms_create(config);
-	if (ret)
-		kfree(config);
-
-	return ret;
+	drm_dev_unregister(&vkms_device->drm);
+	drm_atomic_helper_shutdown(&vkms_device->drm);
+	return 0;
 }
 
-static void vkms_destroy(struct vkms_config *config)
+static struct platform_driver vkms_platform_driver = {
+	.probe = vkms_platform_probe,
+	.remove = vkms_platform_remove,
+	.driver.name = DRIVER_NAME,
+};
+
+static int __init vkms_init(void)
 {
+	int ret;
 	struct platform_device *pdev;
 
-	if (!config->dev) {
-		DRM_INFO("vkms_device is NULL.\n");
-		return;
+	ret = platform_driver_register(&vkms_platform_driver);
+	if (ret) {
+		DRM_ERROR("Unable to register platform driver\n");
+		return ret;
 	}
 
-	pdev = config->dev->platform;
-
-	drm_dev_unregister(&config->dev->drm);
-	drm_atomic_helper_shutdown(&config->dev->drm);
-	devres_release_group(&pdev->dev, NULL);
-	platform_device_unregister(pdev);
+	pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
+	if (IS_ERR(pdev)) {
+		platform_driver_unregister(&vkms_platform_driver);
+		return PTR_ERR(pdev);
+	}
 
-	config->dev = NULL;
+	return 0;
 }
 
 static void __exit vkms_exit(void)
 {
-	if (default_config->dev)
-		vkms_destroy(default_config);
+	struct device *dev;
+
+	while ((dev = platform_find_device_by_driver(
+			NULL, &vkms_platform_driver.driver))) {
+		// platform_find_device_by_driver increments the refcount. Drop 
+		// it so we don't leak memory.
+		put_device(dev);
+		platform_device_unregister(to_platform_device(dev));
+	}
 
-	kfree(default_config);
+	platform_driver_unregister(&vkms_platform_driver);
 }
 
 module_init(vkms_init);
drivers/gpu/drm/vkms/vkms_drv.h +1 -3
index 5f1a0a44a78c..e87c8aea6fb3 100644
@@ -114,15 +114,13 @@ struct vkms_config {
 	bool writeback;
 	bool cursor;
 	bool overlay;
-	/* only set when instantiated */
-	struct vkms_device *dev;
 };
 
 struct vkms_device {
 	struct drm_device drm;
 	struct platform_device *platform;
 	struct vkms_output output;
-	const struct vkms_config *config;
+	struct vkms_config config;
 };
 
 #define drm_crtc_to_vkms_output(target) \
drivers/gpu/drm/vkms/vkms_output.c +3 -3
index 5ce70dd946aa..963a64cf068b 100644
@@ -62,7 +62,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
 	if (IS_ERR(primary))
 		return PTR_ERR(primary);
 
-	if (vkmsdev->config->overlay) {
+	if (vkmsdev->config.overlay) {
 		for (n = 0; n < NUM_OVERLAY_PLANES; n++) {
 			ret = vkms_add_overlay_plane(vkmsdev, index, crtc);
 			if (ret)
@@ -70,7 +70,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
 		}
 	}
 
-	if (vkmsdev->config->cursor) {
+	if (vkmsdev->config.cursor) {
 		cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index);
 		if (IS_ERR(cursor))
 			return PTR_ERR(cursor);
@@ -103,7 +103,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
 		goto err_attach;
 	}
 
-	if (vkmsdev->config->writeback) {
+	if (vkmsdev->config.writeback) {
 		writeback = vkms_enable_writeback_connector(vkmsdev);
 		if (writeback)
 			DRM_ERROR("Failed to init writeback connector\n");
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#2 lore raw

Re: [PATCH v2 1/6] drm/vkms: Back VKMS with DRM memory management instead of static objects

Hi Jim,

Thanks for working on this great feature for the VKMS!

Quoted 41 lines · Jim Shargo

This is a small refactor to make ConfigFS support easier. Once we support ConfigFS, there can be multiple devices instantiated by the driver, and so moving everything into managed memory makes things much easier.

This should be a no-op refactor.

---
  drivers/gpu/drm/vkms/vkms_drv.c    | 130 +++++++++++++++--------------
  drivers/gpu/drm/vkms/vkms_drv.h    |   4 +-
  drivers/gpu/drm/vkms/vkms_output.c |   6 +-
  3 files changed, 72 insertions(+), 68 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.c +2 -2
index e3c9c9571c8d..f07454fff046 100644
@@ -9,10 +9,12 @@
   * the GPU in DRM API tests.
   */
 
+#include <linux/device.h>
  #include <linux/module.h>
  #include <linux/platform_device.h>
  #include <linux/dma-mapping.h>
 
+#include <drm/drm_device.h>
  #include <drm/drm_gem.h>
  #include <drm/drm_atomic.h>
  #include <drm/drm_atomic_helper.h>
@@ -37,8 +39,6 @@
  #define DRIVER_MAJOR	1
  #define DRIVER_MINOR	0
 
-static struct vkms_config *default_config;
-
  static bool enable_cursor = true;
  module_param_named(enable_cursor, enable_cursor, bool, 0444);
  MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");

drivers/gpu/drm/vkms/vkms_drv.c static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state) · line 95

Quoted 7 lines
drivers/gpu/drm/vkms/vkms_drv.c +1 -3
@@ -92,13 +92,13 @@ static void vkms_atomic_commit_tail(struct drm_atomic_state *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);
+	struct drm_info_node *drm_info = m->private;

The VKMS already moved to the new DRM debugfs interface, there is no need to move back to the old interface. I believe you should keep using struct drm_debugfs_entry.

Also, that's probably the reason why the vkms_config file is not being properly updated:

[root@fedora ~]# modprobe vkms enable_overlay=1 enable_cursor=1 enable_writeback=1 [root@fedora ~]# cd /sys/kernel/debug/dri/0
[root@fedora 0]# cat vkms_config
writeback=0
cursor=0
overlay=0

Quoted 74 lines
drivers/gpu/drm/vkms/vkms_drv.c +21 -20
+	struct vkms_device *vkms_device =
+		drm_device_to_vkms_device(drm_info->minor->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);
+	seq_printf(m, "writeback=%d\n", vkms_device->config.writeback);
+	seq_printf(m, "cursor=%d\n", vkms_device->config.cursor);
+	seq_printf(m, "overlay=%d\n", vkms_device->config.overlay);
 
  	return 0;
  }
@@ -155,114 +155,120 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev)
  	return vkms_output_init(vkmsdev, 0);
  }
 
-static int vkms_create(struct vkms_config *config)
+static int vkms_platform_probe(struct platform_device *pdev)
  {
  	int ret;
-	struct platform_device *pdev;
  	struct vkms_device *vkms_device;
+	void *grp;
 
-	pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
-	if (IS_ERR(pdev))
-		return PTR_ERR(pdev);
-
-	if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) {
-		ret = -ENOMEM;
-		goto out_unregister;
+	grp = devres_open_group(&pdev->dev, NULL, GFP_KERNEL);
+	if (!grp) {
+		return -ENOMEM;
  	}
 
  	vkms_device = devm_drm_dev_alloc(&pdev->dev, &vkms_driver,
  					 struct vkms_device, drm);
  	if (IS_ERR(vkms_device)) {
  		ret = PTR_ERR(vkms_device);
-		goto out_devres;
+		goto out_release_group;
  	}
+
  	vkms_device->platform = pdev;
-	vkms_device->config = config;
-	config->dev = vkms_device;
+	vkms_device->config.cursor = enable_cursor;
+	vkms_device->config.writeback = enable_writeback;
+	vkms_device->config.overlay = enable_overlay;
 
  	ret = dma_coerce_mask_and_coherent(vkms_device->drm.dev,
  					   DMA_BIT_MASK(64));
-
  	if (ret) {
  		DRM_ERROR("Could not initialize DMA support\n");
-		goto out_devres;
+		goto out_release_group;
  	}
 
  	ret = drm_vblank_init(&vkms_device->drm, 1);
  	if (ret) {
  		DRM_ERROR("Failed to vblank\n");
-		goto out_devres;
+		goto out_release_group;
  	}
 
  	ret = vkms_modeset_init(vkms_device);
-	if (ret)
-		goto out_devres;
+	if (ret) {
+		DRM_ERROR("Unable to initialize modesetting\n");
+		goto out_release_group;
+	}

drivers/gpu/drm/vkms/vkms_drv.c static int vkms_modeset_init(struct vkms_device *vkmsdev) · line 206

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_drv.c +3 -2
 
  	drm_debugfs_add_files(&vkms_device->drm, vkms_config_debugfs_list,
  			      ARRAY_SIZE(vkms_config_debugfs_list));
 
  	ret = drm_dev_register(&vkms_device->drm, 0);
-	if (ret)
-		goto out_devres;
+	if (ret) {
+		DRM_ERROR("Unable to register device\n");
+		return ret;

Shouldn't you go to out_release_group inside of just returning?

Best Regards,
- Maíra

Quoted 155 lines
drivers/gpu/drm/vkms/vkms_drv.c +41 -35
+	}
 
  	drm_fbdev_generic_setup(&vkms_device->drm, 0);
+	platform_set_drvdata(pdev, vkms_device);
+	devres_close_group(&pdev->dev, grp);
 
  	return 0;
 
-out_devres:
-	devres_release_group(&pdev->dev, NULL);
-out_unregister:
-	platform_device_unregister(pdev);
+out_release_group:
+	devres_release_group(&pdev->dev, grp);
  	return ret;
  }
 
-static int __init vkms_init(void)
+static int vkms_platform_remove(struct platform_device *pdev)
  {
-	int ret;
-	struct vkms_config *config;
-
-	config = kmalloc(sizeof(*config), GFP_KERNEL);
-	if (!config)
-		return -ENOMEM;
-
-	default_config = config;
+	struct vkms_device *vkms_device;
 
-	config->cursor = enable_cursor;
-	config->writeback = enable_writeback;
-	config->overlay = enable_overlay;
+	vkms_device = platform_get_drvdata(pdev);
+	if (!vkms_device)
+		return 0;
 
-	ret = vkms_create(config);
-	if (ret)
-		kfree(config);
-
-	return ret;
+	drm_dev_unregister(&vkms_device->drm);
+	drm_atomic_helper_shutdown(&vkms_device->drm);
+	return 0;
  }
 
-static void vkms_destroy(struct vkms_config *config)
+static struct platform_driver vkms_platform_driver = {
+	.probe = vkms_platform_probe,
+	.remove = vkms_platform_remove,
+	.driver.name = DRIVER_NAME,
+};
+
+static int __init vkms_init(void)
  {
+	int ret;
  	struct platform_device *pdev;
 
-	if (!config->dev) {
-		DRM_INFO("vkms_device is NULL.\n");
-		return;
+	ret = platform_driver_register(&vkms_platform_driver);
+	if (ret) {
+		DRM_ERROR("Unable to register platform driver\n");
+		return ret;
  	}
 
-	pdev = config->dev->platform;
-
-	drm_dev_unregister(&config->dev->drm);
-	drm_atomic_helper_shutdown(&config->dev->drm);
-	devres_release_group(&pdev->dev, NULL);
-	platform_device_unregister(pdev);
+	pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
+	if (IS_ERR(pdev)) {
+		platform_driver_unregister(&vkms_platform_driver);
+		return PTR_ERR(pdev);
+	}
 
-	config->dev = NULL;
+	return 0;
  }
 
  static void __exit vkms_exit(void)
  {
-	if (default_config->dev)
-		vkms_destroy(default_config);
+	struct device *dev;
+
+	while ((dev = platform_find_device_by_driver(
+			NULL, &vkms_platform_driver.driver))) {
+		// platform_find_device_by_driver increments the refcount. Drop
+		// it so we don't leak memory.
+		put_device(dev);
+		platform_device_unregister(to_platform_device(dev));
+	}
 
-	kfree(default_config);
+	platform_driver_unregister(&vkms_platform_driver);
  }
 
  module_init(vkms_init);
drivers/gpu/drm/vkms/vkms_drv.h +1 -3
index 5f1a0a44a78c..e87c8aea6fb3 100644
@@ -114,15 +114,13 @@ struct vkms_config {
  	bool writeback;
  	bool cursor;
  	bool overlay;
-	/* only set when instantiated */
-	struct vkms_device *dev;
  };
 
  struct vkms_device {
  	struct drm_device drm;
  	struct platform_device *platform;
  	struct vkms_output output;
-	const struct vkms_config *config;
+	struct vkms_config config;
  };
 
  #define drm_crtc_to_vkms_output(target) \
drivers/gpu/drm/vkms/vkms_output.c +3 -3
index 5ce70dd946aa..963a64cf068b 100644
@@ -62,7 +62,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
  	if (IS_ERR(primary))
  		return PTR_ERR(primary);
 
-	if (vkmsdev->config->overlay) {
+	if (vkmsdev->config.overlay) {
  		for (n = 0; n < NUM_OVERLAY_PLANES; n++) {
  			ret = vkms_add_overlay_plane(vkmsdev, index, crtc);
  			if (ret)
@@ -70,7 +70,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
  		}
  	}
 
-	if (vkmsdev->config->cursor) {
+	if (vkmsdev->config.cursor) {
  		cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index);
  		if (IS_ERR(cursor))
  			return PTR_ERR(cursor);
@@ -103,7 +103,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
  		goto err_attach;
  	}
 
-	if (vkmsdev->config->writeback) {
+	if (vkmsdev->config.writeback) {
  		writeback = vkms_enable_writeback_connector(vkmsdev);
  		if (writeback)
  			DRM_ERROR("Failed to init writeback connector\n");
author
#3 lore raw

PATCH v2 2/6 drm/vkms: Support multiple DRM objects (crtcs, etc.) per VKMS device

In reply to Jim Shargo

This change supports multiple CRTCs, encoders, connectors instead of one of each per device.

Since ConfigFS-based devices will support multiple crtcs, it's useful to move all of the writeback/composition data from being per-"output" to being per-CRTC.

Since there's still only ever one CRTC, this should be a no-op refactor.

---
 drivers/gpu/drm/vkms/vkms_composer.c  |  28 +++---
 drivers/gpu/drm/vkms/vkms_crtc.c      |  95 +++++++++++---------
 drivers/gpu/drm/vkms/vkms_drv.c       |  14 +--
 drivers/gpu/drm/vkms/vkms_drv.h       |  65 +++++++++-----
 drivers/gpu/drm/vkms/vkms_output.c    | 123 ++++++++++++++++++--------
 drivers/gpu/drm/vkms/vkms_plane.c     |  44 ++++++---
 drivers/gpu/drm/vkms/vkms_writeback.c |  26 +++---
 7 files changed, 252 insertions(+), 143 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +14 -14
index 1636ce3a79f9..75fa42e0ec07 100644
@@ -230,13 +230,13 @@ void vkms_composer_worker(struct work_struct *work)
 						composer_work);
 	struct drm_crtc *crtc = crtc_state->base.crtc;
 	struct vkms_writeback_job *active_wb = crtc_state->active_writeback;
-	struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
 	bool crc_pending, wb_pending;
 	u64 frame_start, frame_end;
 	u32 crc32 = 0;
 	int ret;
 
-	spin_lock_irq(&out->composer_lock);
+	spin_lock_irq(&vkms_crtc->composer_lock);
 	frame_start = crtc_state->frame_start;
 	frame_end = crtc_state->frame_end;
 	crc_pending = crtc_state->crc_pending;
@@ -244,7 +244,7 @@ void vkms_composer_worker(struct work_struct *work)
 	crtc_state->frame_start = 0;
 	crtc_state->frame_end = 0;
 	crtc_state->crc_pending = false;
-	spin_unlock_irq(&out->composer_lock);
+	spin_unlock_irq(&vkms_crtc->composer_lock);
 
 	/*
 	 * We raced with the vblank hrtimer and previous work already computed
@@ -262,10 +262,10 @@ void vkms_composer_worker(struct work_struct *work)
 		return;
 
 	if (wb_pending) {
-		drm_writeback_signal_completion(&out->wb_connector, 0);
-		spin_lock_irq(&out->composer_lock);
+		drm_writeback_signal_completion(&vkms_crtc->wb_connector, 0);
+		spin_lock_irq(&vkms_crtc->composer_lock);
 		crtc_state->wb_pending = false;
-		spin_unlock_irq(&out->composer_lock);
+		spin_unlock_irq(&vkms_crtc->composer_lock);
 	}
 
 	/*
@@ -315,25 +315,25 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *src_name,
 	return 0;
 }
 
-void vkms_set_composer(struct vkms_output *out, bool enabled)
+void vkms_set_composer(struct vkms_crtc *vkms_crtc, bool enabled)
 {
 	bool old_enabled;
 
 	if (enabled)
-		drm_crtc_vblank_get(&out->crtc);
+		drm_crtc_vblank_get(&vkms_crtc->base);
 
-	spin_lock_irq(&out->lock);
-	old_enabled = out->composer_enabled;
-	out->composer_enabled = enabled;
-	spin_unlock_irq(&out->lock);
+	spin_lock_irq(&vkms_crtc->lock);
+	old_enabled = vkms_crtc->composer_enabled;
+	vkms_crtc->composer_enabled = enabled;
+	spin_unlock_irq(&vkms_crtc->lock);
 
 	if (old_enabled)
-		drm_crtc_vblank_put(&out->crtc);
+		drm_crtc_vblank_put(&vkms_crtc->base);
 }
 
 int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name)
 {
-	struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
+	struct vkms_crtc *out = drm_crtc_to_vkms_crtc(crtc);
 	bool enabled = false;
 	int ret = 0;
 
drivers/gpu/drm/vkms/vkms_crtc.c +55 -40

201 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_drv.c +7 -7
index f07454fff046..aa2bee82b757 100644
@@ -57,8 +57,8 @@ static void vkms_release(struct drm_device *dev)
 {
 	struct vkms_device *vkms = drm_device_to_vkms_device(dev);
 
-	if (vkms->output.composer_workq)
-		destroy_workqueue(vkms->output.composer_workq);
+	for (int i = 0; i < vkms->output.num_crtcs; i++)
+		destroy_workqueue(vkms->output.crtcs[i].composer_workq);
 }
 
 static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state)
@@ -185,15 +185,15 @@ static int vkms_platform_probe(struct platform_device *pdev)
 		goto out_release_group;
 	}
 
-	ret = drm_vblank_init(&vkms_device->drm, 1);
+	ret = vkms_modeset_init(vkms_device);
 	if (ret) {
-		DRM_ERROR("Failed to vblank\n");
+		DRM_ERROR("Unable to initialize modesetting\n");
 		goto out_release_group;
 	}
 
-	ret = vkms_modeset_init(vkms_device);
+	ret = drm_vblank_init(&vkms_device->drm, vkms_device->output.num_crtcs);
 	if (ret) {
-		DRM_ERROR("Unable to initialize modesetting\n");
+		DRM_ERROR("Failed to vblank\n");
 		goto out_release_group;
 	}
 
@@ -202,7 +202,7 @@ static int vkms_platform_probe(struct platform_device *pdev)
 
 	ret = drm_dev_register(&vkms_device->drm, 0);
 	if (ret) {
-		DRM_ERROR("Unable to register device\n");
+		DRM_ERROR("Unable to register device with id %d\n", pdev->id);
 		return ret;
 	}
 
drivers/gpu/drm/vkms/vkms_drv.h +41 -24

111 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_output.c +88 -35

185 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_plane.c +33 -11

73 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_writeback.c +14 -12
index 84a51cd281b9..b90bcbd0a0e0 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 
 #include <linux/iosys-map.h>
+#include <linux/kernel.h>
 
 #include <drm/drm_atomic.h>
 #include <drm/drm_edid.h>
@@ -101,7 +102,8 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector,
 				struct drm_writeback_job *job)
 {
 	struct vkms_writeback_job *vkmsjob = job->priv;
-	struct vkms_device *vkmsdev;
+	struct vkms_crtc *vkms_crtc =
+		container_of(connector, struct vkms_crtc, wb_connector);
 
 	if (!job->fb)
 		return;
@@ -110,8 +112,7 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector,
 
 	drm_framebuffer_put(vkmsjob->wb_frame_info.fb);
 
-	vkmsdev = drm_device_to_vkms_device(job->fb->dev);
-	vkms_set_composer(&vkmsdev->output, false);
+	vkms_set_composer(vkms_crtc, false);
 	kfree(vkmsjob);
 }
 
@@ -120,11 +121,11 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,
 {
 	struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state,
 											 conn);
-	struct vkms_device *vkmsdev = drm_device_to_vkms_device(conn->dev);
-	struct vkms_output *output = &vkmsdev->output;
-	struct drm_writeback_connector *wb_conn = &output->wb_connector;
+	struct vkms_crtc *vkms_crtc =
+		drm_crtc_to_vkms_crtc(connector_state->crtc);
+	struct drm_writeback_connector *wb_conn = &vkms_crtc->wb_connector;
 	struct drm_connector_state *conn_state = wb_conn->base.state;
-	struct vkms_crtc_state *crtc_state = output->composer_state;
+	struct vkms_crtc_state *crtc_state = vkms_crtc->composer_state;
 	struct drm_framebuffer *fb = connector_state->writeback_job->fb;
 	u16 crtc_height = crtc_state->base.crtc->mode.vdisplay;
 	u16 crtc_width = crtc_state->base.crtc->mode.hdisplay;
@@ -135,18 +136,18 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,
 	if (!conn_state)
 		return;
 
-	vkms_set_composer(&vkmsdev->output, true);
+	vkms_set_composer(vkms_crtc, true);
 
 	active_wb = conn_state->writeback_job->priv;
 	wb_frame_info = &active_wb->wb_frame_info;
 
-	spin_lock_irq(&output->composer_lock);
+	spin_lock_irq(&vkms_crtc->composer_lock);
 	crtc_state->active_writeback = active_wb;
 	wb_frame_info->offset = fb->offsets[0];
 	wb_frame_info->pitch = fb->pitches[0];
 	wb_frame_info->cpp = fb->format->cpp[0];
 	crtc_state->wb_pending = true;
-	spin_unlock_irq(&output->composer_lock);
+	spin_unlock_irq(&vkms_crtc->composer_lock);
 	drm_writeback_queue_job(wb_conn, connector_state);
 	active_wb->wb_write = get_line_to_frame_function(wb_format);
 	drm_rect_init(&wb_frame_info->src, 0, 0, crtc_width, crtc_height);
@@ -160,9 +161,10 @@ static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = {
 	.atomic_commit = vkms_wb_atomic_commit,
 };
 
-int vkms_enable_writeback_connector(struct vkms_device *vkmsdev)
+int vkms_enable_writeback_connector(struct vkms_device *vkmsdev,
+				    struct vkms_crtc *vkms_crtc)
 {
-	struct drm_writeback_connector *wb = &vkmsdev->output.wb_connector;
+	struct drm_writeback_connector *wb = &vkms_crtc->wb_connector;
 
 	drm_connector_helper_add(&wb->base, &vkms_wb_conn_helper_funcs);
 
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#4 lore raw

Re: [PATCH v2 2/6] drm/vkms: Support multiple DRM objects (crtcs, etc.) per VKMS device

Hi Jim,

Quoted 316 lines · Jim Shargo

This change supports multiple CRTCs, encoders, connectors instead of one of each per device.

Since ConfigFS-based devices will support multiple crtcs, it's useful to move all of the writeback/composition data from being per-"output" to being per-CRTC.

Since there's still only ever one CRTC, this should be a no-op refactor.

---
  drivers/gpu/drm/vkms/vkms_composer.c  |  28 +++---
  drivers/gpu/drm/vkms/vkms_crtc.c      |  95 +++++++++++---------
  drivers/gpu/drm/vkms/vkms_drv.c       |  14 +--
  drivers/gpu/drm/vkms/vkms_drv.h       |  65 +++++++++-----
  drivers/gpu/drm/vkms/vkms_output.c    | 123 ++++++++++++++++++--------
  drivers/gpu/drm/vkms/vkms_plane.c     |  44 ++++++---
  drivers/gpu/drm/vkms/vkms_writeback.c |  26 +++---
  7 files changed, 252 insertions(+), 143 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +14 -14
index 1636ce3a79f9..75fa42e0ec07 100644
@@ -230,13 +230,13 @@ void vkms_composer_worker(struct work_struct *work)
  						composer_work);
  	struct drm_crtc *crtc = crtc_state->base.crtc;
  	struct vkms_writeback_job *active_wb = crtc_state->active_writeback;
-	struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
  	bool crc_pending, wb_pending;
  	u64 frame_start, frame_end;
  	u32 crc32 = 0;
  	int ret;
 
-	spin_lock_irq(&out->composer_lock);
+	spin_lock_irq(&vkms_crtc->composer_lock);
  	frame_start = crtc_state->frame_start;
  	frame_end = crtc_state->frame_end;
  	crc_pending = crtc_state->crc_pending;
@@ -244,7 +244,7 @@ void vkms_composer_worker(struct work_struct *work)
  	crtc_state->frame_start = 0;
  	crtc_state->frame_end = 0;
  	crtc_state->crc_pending = false;
-	spin_unlock_irq(&out->composer_lock);
+	spin_unlock_irq(&vkms_crtc->composer_lock);
 
  	/*
  	 * We raced with the vblank hrtimer and previous work already computed
@@ -262,10 +262,10 @@ void vkms_composer_worker(struct work_struct *work)
  		return;
 
  	if (wb_pending) {
-		drm_writeback_signal_completion(&out->wb_connector, 0);
-		spin_lock_irq(&out->composer_lock);
+		drm_writeback_signal_completion(&vkms_crtc->wb_connector, 0);
+		spin_lock_irq(&vkms_crtc->composer_lock);
  		crtc_state->wb_pending = false;
-		spin_unlock_irq(&out->composer_lock);
+		spin_unlock_irq(&vkms_crtc->composer_lock);
  	}
 
  	/*
@@ -315,25 +315,25 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *src_name,
  	return 0;
  }
 
-void vkms_set_composer(struct vkms_output *out, bool enabled)
+void vkms_set_composer(struct vkms_crtc *vkms_crtc, bool enabled)
  {
  	bool old_enabled;
 
  	if (enabled)
-		drm_crtc_vblank_get(&out->crtc);
+		drm_crtc_vblank_get(&vkms_crtc->base);
 
-	spin_lock_irq(&out->lock);
-	old_enabled = out->composer_enabled;
-	out->composer_enabled = enabled;
-	spin_unlock_irq(&out->lock);
+	spin_lock_irq(&vkms_crtc->lock);
+	old_enabled = vkms_crtc->composer_enabled;
+	vkms_crtc->composer_enabled = enabled;
+	spin_unlock_irq(&vkms_crtc->lock);
 
  	if (old_enabled)
-		drm_crtc_vblank_put(&out->crtc);
+		drm_crtc_vblank_put(&vkms_crtc->base);
  }
 
  int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name)
  {
-	struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
+	struct vkms_crtc *out = drm_crtc_to_vkms_crtc(crtc);
  	bool enabled = false;
  	int ret = 0;
 
drivers/gpu/drm/vkms/vkms_crtc.c +55 -40
index 515f6772b866..d91e49c53adc 100644
@@ -11,35 +11,34 @@
 
  static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer)
  {
-	struct vkms_output *output = container_of(timer, struct vkms_output,
-						  vblank_hrtimer);
-	struct drm_crtc *crtc = &output->crtc;
+	struct vkms_crtc *vkms_crtc = timer_to_vkms_crtc(timer);
+	struct drm_crtc *crtc = &vkms_crtc->base;
  	struct vkms_crtc_state *state;
  	u64 ret_overrun;
  	bool ret, fence_cookie;
 
  	fence_cookie = dma_fence_begin_signalling();
 
-	ret_overrun = hrtimer_forward_now(&output->vblank_hrtimer,
-					  output->period_ns);
+	ret_overrun = hrtimer_forward_now(&vkms_crtc->vblank_hrtimer,
+					  vkms_crtc->period_ns);
  	if (ret_overrun != 1)
  		pr_warn("%s: vblank timer overrun\n", __func__);
 
-	spin_lock(&output->lock);
+	spin_lock(&vkms_crtc->lock);
  	ret = drm_crtc_handle_vblank(crtc);
  	if (!ret)
  		DRM_ERROR("vkms failure on handling vblank");
 
-	state = output->composer_state;
-	spin_unlock(&output->lock);
+	state = vkms_crtc->composer_state;
+	spin_unlock(&vkms_crtc->lock);
 
-	if (state && output->composer_enabled) {
+	if (state && vkms_crtc->composer_enabled) {
  		u64 frame = drm_crtc_accurate_vblank_count(crtc);
 
  		/* update frame_start only if a queued vkms_composer_worker()
  		 * has read the data
  		 */
-		spin_lock(&output->composer_lock);
+		spin_lock(&vkms_crtc->composer_lock);
  		if (!state->crc_pending)
  			state->frame_start = frame;
  		else
@@ -47,9 +46,10 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer)
  					 state->frame_start, frame);
  		state->frame_end = frame;
  		state->crc_pending = true;
-		spin_unlock(&output->composer_lock);
+		spin_unlock(&vkms_crtc->composer_lock);
 
-		ret = queue_work(output->composer_workq, &state->composer_work);
+		ret = queue_work(vkms_crtc->composer_workq,
+				 &state->composer_work);
  		if (!ret)
  			DRM_DEBUG_DRIVER("Composer worker already queued\n");
  	}
@@ -62,25 +62,27 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer)
  static int vkms_enable_vblank(struct drm_crtc *crtc)
  {
  	struct drm_device *dev = crtc->dev;
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
  	unsigned int pipe = drm_crtc_index(crtc);
  	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
-	struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
 
  	drm_calc_timestamping_constants(crtc, &crtc->mode);
 
-	hrtimer_init(&out->vblank_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-	out->vblank_hrtimer.function = &vkms_vblank_simulate;
-	out->period_ns = ktime_set(0, vblank->framedur_ns);
-	hrtimer_start(&out->vblank_hrtimer, out->period_ns, HRTIMER_MODE_REL);
+	hrtimer_init(&vkms_crtc->vblank_hrtimer, CLOCK_MONOTONIC,
+		     HRTIMER_MODE_REL);
+	vkms_crtc->vblank_hrtimer.function = &vkms_vblank_simulate;
+	vkms_crtc->period_ns = ktime_set(0, vblank->framedur_ns);
+	hrtimer_start(&vkms_crtc->vblank_hrtimer, vkms_crtc->period_ns,
+		      HRTIMER_MODE_REL);
 
  	return 0;
  }
 
  static void vkms_disable_vblank(struct drm_crtc *crtc)
  {
-	struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
 
-	hrtimer_cancel(&out->vblank_hrtimer);
+	hrtimer_cancel(&vkms_crtc->vblank_hrtimer);
  }
 
  static bool vkms_get_vblank_timestamp(struct drm_crtc *crtc,
@@ -88,9 +90,8 @@ static bool vkms_get_vblank_timestamp(struct drm_crtc *crtc,
  				      bool in_vblank_irq)
  {
  	struct drm_device *dev = crtc->dev;
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
  	unsigned int pipe = crtc->index;
-	struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev);
-	struct vkms_output *output = &vkmsdev->output;
  	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
 
  	if (!READ_ONCE(vblank->enabled)) {
@@ -98,7 +99,7 @@ static bool vkms_get_vblank_timestamp(struct drm_crtc *crtc,
  		return true;
  	}
 
-	*vblank_time = READ_ONCE(output->vblank_hrtimer.node.expires);
+	*vblank_time = READ_ONCE(vkms_crtc->vblank_hrtimer.node.expires);
 
  	if (WARN_ON(*vblank_time == vblank->time))
  		return true;
@@ -110,7 +111,7 @@ static bool vkms_get_vblank_timestamp(struct drm_crtc *crtc,
  	 * the vblank core expects. Therefore we need to always correct the
  	 * timestampe by one frame.
  	 */
-	*vblank_time -= output->period_ns;
+	*vblank_time -= vkms_crtc->period_ns;
 
  	return true;
  }
@@ -236,18 +237,18 @@ static void vkms_crtc_atomic_disable(struct drm_crtc *crtc,
  static void vkms_crtc_atomic_begin(struct drm_crtc *crtc,
  				   struct drm_atomic_state *state)
  {
-	struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
 
  	/* This lock is held across the atomic commit to block vblank timer
  	 * from scheduling vkms_composer_worker until the composer is updated
  	 */
-	spin_lock_irq(&vkms_output->lock);
+	spin_lock_irq(&vkms_crtc->lock);
  }
 
  static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
  				   struct drm_atomic_state *state)
  {
-	struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
 
  	if (crtc->state->event) {
  		spin_lock(&crtc->dev->event_lock);
@@ -262,9 +263,9 @@ static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
  		crtc->state->event = NULL;
  	}
 
-	vkms_output->composer_state = to_vkms_crtc_state(crtc->state);
+	vkms_crtc->composer_state = to_vkms_crtc_state(crtc->state);
 
-	spin_unlock_irq(&vkms_output->lock);
+	spin_unlock_irq(&vkms_crtc->lock);
  }
 
  static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = {
@@ -275,27 +276,41 @@ static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = {
  	.atomic_disable	= vkms_crtc_atomic_disable,
  };
 
-int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
-		   struct drm_plane *primary, struct drm_plane *cursor)
+struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
+				 struct drm_plane *primary,
+				 struct drm_plane *cursor)
  {
-	struct vkms_output *vkms_out = drm_crtc_to_vkms_output(crtc);
+	struct drm_device *dev = &vkmsdev->drm;
+	struct vkms_crtc *vkms_crtc;
  	int ret;
 
-	ret = drmm_crtc_init_with_planes(dev, crtc, primary, cursor,
+	if (vkmsdev->output.num_crtcs >= VKMS_MAX_OUTPUT_OBJECTS) {
+		return ERR_PTR(-ENOMEM);
+	}
+	vkms_crtc = &vkmsdev->output.crtcs[vkmsdev->output.num_crtcs++];
+
+	ret = drmm_crtc_init_with_planes(dev, &vkms_crtc->base, primary, cursor,
  					 &vkms_crtc_funcs, NULL);
  	if (ret) {
  		DRM_ERROR("Failed to init CRTC\n");
-		return ret;
+		goto out_error;
  	}
 
-	drm_crtc_helper_add(crtc, &vkms_crtc_helper_funcs);
+	drm_crtc_helper_add(&vkms_crtc->base, &vkms_crtc_helper_funcs);
 
-	spin_lock_init(&vkms_out->lock);
-	spin_lock_init(&vkms_out->composer_lock);
+	spin_lock_init(&vkms_crtc->lock);
+	spin_lock_init(&vkms_crtc->composer_lock);
 
-	vkms_out->composer_workq = alloc_ordered_workqueue("vkms_composer", 0);
-	if (!vkms_out->composer_workq)
-		return -ENOMEM;
+	vkms_crtc->composer_workq = alloc_ordered_workqueue("vkms_composer", 0);
+	if (!vkms_crtc->composer_workq) {
+		ret = -ENOMEM;
+		goto out_error;
+	}
+
+	return vkms_crtc;
 
-	return ret;
+out_error:
+	memset(vkms_crtc, 0, sizeof(*vkms_crtc));
+	vkmsdev->output.num_crtcs -= 1;
+	return ERR_PTR(ret);
  }
drivers/gpu/drm/vkms/vkms_drv.c +0 -0
index f07454fff046..aa2bee82b757 100644

drivers/gpu/drm/vkms/vkms_drv.c static void vkms_release(struct drm_device *dev) · line 61

Quoted 7 lines
drivers/gpu/drm/vkms/vkms_drv.c +2 -2
@@ -57,8 +57,8 @@ static void vkms_release(struct drm_device *dev)
  {
  	struct vkms_device *vkms = drm_device_to_vkms_device(dev);
 
-	if (vkms->output.composer_workq)
-		destroy_workqueue(vkms->output.composer_workq);
+	for (int i = 0; i < vkms->output.num_crtcs; i++)
+		destroy_workqueue(vkms->output.crtcs[i].composer_workq);

Is there no need to check if vkms->output.crtcs[i].composer_workq is NULL?

Quoted 24 lines
drivers/gpu/drm/vkms/vkms_drv.c +4 -4
  }
 
  static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state)
@@ -185,15 +185,15 @@ static int vkms_platform_probe(struct platform_device *pdev)
  		goto out_release_group;
  	}
 
-	ret = drm_vblank_init(&vkms_device->drm, 1);
+	ret = vkms_modeset_init(vkms_device);
  	if (ret) {
-		DRM_ERROR("Failed to vblank\n");
+		DRM_ERROR("Unable to initialize modesetting\n");
  		goto out_release_group;
  	}
 
-	ret = vkms_modeset_init(vkms_device);
+	ret = drm_vblank_init(&vkms_device->drm, vkms_device->output.num_crtcs);
  	if (ret) {
-		DRM_ERROR("Unable to initialize modesetting\n");
+		DRM_ERROR("Failed to vblank\n");
  		goto out_release_group;
  	}
 

drivers/gpu/drm/vkms/vkms_drv.c static int vkms_platform_probe(struct platform_device *pdev) · line 205

Quoted 5 lines
drivers/gpu/drm/vkms/vkms_drv.c +1 -1
@@ -202,7 +202,7 @@ static int vkms_platform_probe(struct platform_device *pdev)
 
  	ret = drm_dev_register(&vkms_device->drm, 0);
  	if (ret) {
-		DRM_ERROR("Unable to register device\n");
+		DRM_ERROR("Unable to register device with id %d\n", pdev->id);

I believe this belongs to the first patch.

Quoted 43 lines
drivers/gpu/drm/vkms/vkms_drv.c +0 -0
  		return ret;
  	}
 
drivers/gpu/drm/vkms/vkms_drv.h +22 -0
index e87c8aea6fb3..4c3274838ec7 100644
@@ -23,6 +23,9 @@
 
  #define NUM_OVERLAY_PLANES 8
 
+#define VKMS_MAX_OUTPUT_OBJECTS 16
+#define VKMS_MAX_PLANES (3 * VKMS_MAX_OUTPUT_OBJECTS)
+
  struct vkms_frame_info {
  	struct drm_framebuffer *fb;
  	struct drm_rect src, dst;
@@ -65,6 +68,25 @@ struct vkms_plane {
  	struct drm_plane base;
  };
 
+struct vkms_crtc {
+	struct drm_crtc base;
+
+	struct drm_writeback_connector wb_connector;
+	struct hrtimer vblank_hrtimer;
+	ktime_t period_ns;
+	struct drm_pending_vblank_event *event;
+	/* ordered wq for composer_work */
+	struct workqueue_struct *composer_workq;
+	/* protects concurrent access to composer */
+	spinlock_t lock;
+
+	/* protected by @lock */
+	bool composer_enabled;
+	struct vkms_crtc_state *composer_state;
+
+	spinlock_t composer_lock;
+};
+
  /**
   * vkms_crtc_state - Driver specific CRTC state
   * @base: base CRTC state

[...]

Quoted 35 lines
drivers/gpu/drm/vkms/vkms_plane.c +16 -0
index e5c625ab8e3e..f69621822c1b 100644
@@ -8,6 +8,8 @@
  #include <drm/drm_fourcc.h>
  #include <drm/drm_gem_atomic_helper.h>
  #include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_plane.h>
+#include <drm/drm_plane_helper.h>
 
  #include "vkms_drv.h"
  #include "vkms_formats.h"
@@ -65,6 +67,20 @@ static void vkms_plane_destroy_state(struct drm_plane *plane,
  	kfree(vkms_state);
  }
 
+static void vkms_plane_destroy(struct drm_plane *plane)
+{
+	struct vkms_plane *vkms_plane =
+		container_of(plane, struct vkms_plane, base);
+
+	if (plane->state) {
+		vkms_plane_destroy_state(plane, plane->state);
+		plane->state = NULL;
+	}
+
+	drm_plane_cleanup(plane);
+	memset(vkms_plane, 0, sizeof(struct vkms_plane));
+}
+
  static void vkms_plane_reset(struct drm_plane *plane)
  {
  	struct vkms_plane_state *vkms_state;

drivers/gpu/drm/vkms/vkms_plane.c static void vkms_plane_reset(struct drm_plane *plane) · line 89

Quoted 6 lines
drivers/gpu/drm/vkms/vkms_plane.c +0 -3
@@ -84,11 +100,12 @@ static void vkms_plane_reset(struct drm_plane *plane)
  }
 
  static const struct drm_plane_funcs vkms_plane_funcs = {
-	.update_plane		= drm_atomic_helper_update_plane,
-	.disable_plane		= drm_atomic_helper_disable_plane,
-	.reset			= vkms_plane_reset,

I believe that there is no need to change this lines.

Quoted 25 lines
drivers/gpu/drm/vkms/vkms_plane.c +8 -5
+	.update_plane = drm_atomic_helper_update_plane,
+	.disable_plane = drm_atomic_helper_disable_plane,
+	.destroy = vkms_plane_destroy,
+	.reset = vkms_plane_reset,
  	.atomic_duplicate_state = vkms_plane_duplicate_state,
-	.atomic_destroy_state	= vkms_plane_destroy_state,
+	.atomic_destroy_state = vkms_plane_destroy_state,
  };
 
  static void vkms_plane_atomic_update(struct drm_plane *plane,
@@ -198,17 +215,22 @@ static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = {
  };
 
  struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
-				   enum drm_plane_type type, int index)
+				   enum drm_plane_type type)
  {
  	struct drm_device *dev = &vkmsdev->drm;
+	struct vkms_output *output = &vkmsdev->output;
  	struct vkms_plane *plane;
+	int ret;
 
-	plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 1 << index,
-					   &vkms_plane_funcs,
-					   vkms_formats, ARRAY_SIZE(vkms_formats),

drivers/gpu/drm/vkms/vkms_plane.c static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = { · line 231

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_plane.c +7 -3
-					   NULL, type, NULL);
-	if (IS_ERR(plane))
-		return plane;
+	if (output->num_planes >= VKMS_MAX_PLANES)
+		return ERR_PTR(-ENOMEM);
+
+	plane = &output->planes[output->num_planes++];
+	ret = drm_universal_plane_init(dev, &plane->base, 0, &vkms_plane_funcs,
+				       vkms_formats, ARRAY_SIZE(vkms_formats),
+				       NULL, type, NULL);

Wouldn't be possible to use drmm_universal_plane_alloc?

Best Regards,
- Maíra

Quoted 88 lines
drivers/gpu/drm/vkms/vkms_plane.c +2 -0
+	if (ret)
+		return ERR_PTR(ret);
 
  	drm_plane_helper_add(&plane->base, &vkms_plane_helper_funcs);
 
drivers/gpu/drm/vkms/vkms_writeback.c +14 -12
index 84a51cd281b9..b90bcbd0a0e0 100644
@@ -1,6 +1,7 @@
  // SPDX-License-Identifier: GPL-2.0+
 
  #include <linux/iosys-map.h>
+#include <linux/kernel.h>
 
  #include <drm/drm_atomic.h>
  #include <drm/drm_edid.h>
@@ -101,7 +102,8 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector,
  				struct drm_writeback_job *job)
  {
  	struct vkms_writeback_job *vkmsjob = job->priv;
-	struct vkms_device *vkmsdev;
+	struct vkms_crtc *vkms_crtc =
+		container_of(connector, struct vkms_crtc, wb_connector);
 
  	if (!job->fb)
  		return;
@@ -110,8 +112,7 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector,
 
  	drm_framebuffer_put(vkmsjob->wb_frame_info.fb);
 
-	vkmsdev = drm_device_to_vkms_device(job->fb->dev);
-	vkms_set_composer(&vkmsdev->output, false);
+	vkms_set_composer(vkms_crtc, false);
  	kfree(vkmsjob);
  }
 
@@ -120,11 +121,11 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,
  {
  	struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state,
  											 conn);
-	struct vkms_device *vkmsdev = drm_device_to_vkms_device(conn->dev);
-	struct vkms_output *output = &vkmsdev->output;
-	struct drm_writeback_connector *wb_conn = &output->wb_connector;
+	struct vkms_crtc *vkms_crtc =
+		drm_crtc_to_vkms_crtc(connector_state->crtc);
+	struct drm_writeback_connector *wb_conn = &vkms_crtc->wb_connector;
  	struct drm_connector_state *conn_state = wb_conn->base.state;
-	struct vkms_crtc_state *crtc_state = output->composer_state;
+	struct vkms_crtc_state *crtc_state = vkms_crtc->composer_state;
  	struct drm_framebuffer *fb = connector_state->writeback_job->fb;
  	u16 crtc_height = crtc_state->base.crtc->mode.vdisplay;
  	u16 crtc_width = crtc_state->base.crtc->mode.hdisplay;
@@ -135,18 +136,18 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,
  	if (!conn_state)
  		return;
 
-	vkms_set_composer(&vkmsdev->output, true);
+	vkms_set_composer(vkms_crtc, true);
 
  	active_wb = conn_state->writeback_job->priv;
  	wb_frame_info = &active_wb->wb_frame_info;
 
-	spin_lock_irq(&output->composer_lock);
+	spin_lock_irq(&vkms_crtc->composer_lock);
  	crtc_state->active_writeback = active_wb;
  	wb_frame_info->offset = fb->offsets[0];
  	wb_frame_info->pitch = fb->pitches[0];
  	wb_frame_info->cpp = fb->format->cpp[0];
  	crtc_state->wb_pending = true;
-	spin_unlock_irq(&output->composer_lock);
+	spin_unlock_irq(&vkms_crtc->composer_lock);
  	drm_writeback_queue_job(wb_conn, connector_state);
  	active_wb->wb_write = get_line_to_frame_function(wb_format);
  	drm_rect_init(&wb_frame_info->src, 0, 0, crtc_width, crtc_height);
@@ -160,9 +161,10 @@ static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = {
  	.atomic_commit = vkms_wb_atomic_commit,
  };
 
-int vkms_enable_writeback_connector(struct vkms_device *vkmsdev)
+int vkms_enable_writeback_connector(struct vkms_device *vkmsdev,
+				    struct vkms_crtc *vkms_crtc)
  {
-	struct drm_writeback_connector *wb = &vkmsdev->output.wb_connector;
+	struct drm_writeback_connector *wb = &vkms_crtc->wb_connector;
 
  	drm_connector_helper_add(&wb->base, &vkms_wb_conn_helper_funcs);
 
#5 lore raw

Re: [PATCH v2 2/6] drm/vkms: Support multiple DRM objects (crtcs, etc.) per VKMS device

In reply to Jim Shargo

Hi,

See below some comments about vkms_wb_atomic_commit().

Quoted 783 lines · Jim Shargo

This change supports multiple CRTCs, encoders, connectors instead of one of each per device.

Since ConfigFS-based devices will support multiple crtcs, it's useful to move all of the writeback/composition data from being per-"output" to being per-CRTC.

Since there's still only ever one CRTC, this should be a no-op refactor.

---
 drivers/gpu/drm/vkms/vkms_composer.c  |  28 +++---
 drivers/gpu/drm/vkms/vkms_crtc.c      |  95 +++++++++++---------
 drivers/gpu/drm/vkms/vkms_drv.c       |  14 +--
 drivers/gpu/drm/vkms/vkms_drv.h       |  65 +++++++++-----
 drivers/gpu/drm/vkms/vkms_output.c    | 123 ++++++++++++++++++--------
 drivers/gpu/drm/vkms/vkms_plane.c     |  44 ++++++---
 drivers/gpu/drm/vkms/vkms_writeback.c |  26 +++---
 7 files changed, 252 insertions(+), 143 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +14 -14
index 1636ce3a79f9..75fa42e0ec07 100644
@@ -230,13 +230,13 @@ void vkms_composer_worker(struct work_struct *work)
 						composer_work);
 	struct drm_crtc *crtc = crtc_state->base.crtc;
 	struct vkms_writeback_job *active_wb = crtc_state->active_writeback;
-	struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
 	bool crc_pending, wb_pending;
 	u64 frame_start, frame_end;
 	u32 crc32 = 0;
 	int ret;
 
-	spin_lock_irq(&out->composer_lock);
+	spin_lock_irq(&vkms_crtc->composer_lock);
 	frame_start = crtc_state->frame_start;
 	frame_end = crtc_state->frame_end;
 	crc_pending = crtc_state->crc_pending;
@@ -244,7 +244,7 @@ void vkms_composer_worker(struct work_struct *work)
 	crtc_state->frame_start = 0;
 	crtc_state->frame_end = 0;
 	crtc_state->crc_pending = false;
-	spin_unlock_irq(&out->composer_lock);
+	spin_unlock_irq(&vkms_crtc->composer_lock);
 
 	/*
 	 * We raced with the vblank hrtimer and previous work already computed
@@ -262,10 +262,10 @@ void vkms_composer_worker(struct work_struct *work)
 		return;
 
 	if (wb_pending) {
-		drm_writeback_signal_completion(&out->wb_connector, 0);
-		spin_lock_irq(&out->composer_lock);
+		drm_writeback_signal_completion(&vkms_crtc->wb_connector, 0);
+		spin_lock_irq(&vkms_crtc->composer_lock);
 		crtc_state->wb_pending = false;
-		spin_unlock_irq(&out->composer_lock);
+		spin_unlock_irq(&vkms_crtc->composer_lock);
 	}
 
 	/*
@@ -315,25 +315,25 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *src_name,
 	return 0;
 }
 
-void vkms_set_composer(struct vkms_output *out, bool enabled)
+void vkms_set_composer(struct vkms_crtc *vkms_crtc, bool enabled)
 {
 	bool old_enabled;
 
 	if (enabled)
-		drm_crtc_vblank_get(&out->crtc);
+		drm_crtc_vblank_get(&vkms_crtc->base);
 
-	spin_lock_irq(&out->lock);
-	old_enabled = out->composer_enabled;
-	out->composer_enabled = enabled;
-	spin_unlock_irq(&out->lock);
+	spin_lock_irq(&vkms_crtc->lock);
+	old_enabled = vkms_crtc->composer_enabled;
+	vkms_crtc->composer_enabled = enabled;
+	spin_unlock_irq(&vkms_crtc->lock);
 
 	if (old_enabled)
-		drm_crtc_vblank_put(&out->crtc);
+		drm_crtc_vblank_put(&vkms_crtc->base);
 }
 
 int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name)
 {
-	struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
+	struct vkms_crtc *out = drm_crtc_to_vkms_crtc(crtc);
 	bool enabled = false;
 	int ret = 0;
 
drivers/gpu/drm/vkms/vkms_crtc.c +55 -40
index 515f6772b866..d91e49c53adc 100644
@@ -11,35 +11,34 @@
 
 static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer)
 {
-	struct vkms_output *output = container_of(timer, struct vkms_output,
-						  vblank_hrtimer);
-	struct drm_crtc *crtc = &output->crtc;
+	struct vkms_crtc *vkms_crtc = timer_to_vkms_crtc(timer);
+	struct drm_crtc *crtc = &vkms_crtc->base;
 	struct vkms_crtc_state *state;
 	u64 ret_overrun;
 	bool ret, fence_cookie;
 
 	fence_cookie = dma_fence_begin_signalling();
 
-	ret_overrun = hrtimer_forward_now(&output->vblank_hrtimer,
-					  output->period_ns);
+	ret_overrun = hrtimer_forward_now(&vkms_crtc->vblank_hrtimer,
+					  vkms_crtc->period_ns);
 	if (ret_overrun != 1)
 		pr_warn("%s: vblank timer overrun\n", __func__);
 
-	spin_lock(&output->lock);
+	spin_lock(&vkms_crtc->lock);
 	ret = drm_crtc_handle_vblank(crtc);
 	if (!ret)
 		DRM_ERROR("vkms failure on handling vblank");
 
-	state = output->composer_state;
-	spin_unlock(&output->lock);
+	state = vkms_crtc->composer_state;
+	spin_unlock(&vkms_crtc->lock);
 
-	if (state && output->composer_enabled) {
+	if (state && vkms_crtc->composer_enabled) {
 		u64 frame = drm_crtc_accurate_vblank_count(crtc);
 
 		/* update frame_start only if a queued vkms_composer_worker()
 		 * has read the data
 		 */
-		spin_lock(&output->composer_lock);
+		spin_lock(&vkms_crtc->composer_lock);
 		if (!state->crc_pending)
 			state->frame_start = frame;
 		else
@@ -47,9 +46,10 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer)
 					 state->frame_start, frame);
 		state->frame_end = frame;
 		state->crc_pending = true;
-		spin_unlock(&output->composer_lock);
+		spin_unlock(&vkms_crtc->composer_lock);
 
-		ret = queue_work(output->composer_workq, &state->composer_work);
+		ret = queue_work(vkms_crtc->composer_workq,
+				 &state->composer_work);
 		if (!ret)
 			DRM_DEBUG_DRIVER("Composer worker already queued\n");
 	}
@@ -62,25 +62,27 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer)
 static int vkms_enable_vblank(struct drm_crtc *crtc)
 {
 	struct drm_device *dev = crtc->dev;
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
 	unsigned int pipe = drm_crtc_index(crtc);
 	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
-	struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
 
 	drm_calc_timestamping_constants(crtc, &crtc->mode);
 
-	hrtimer_init(&out->vblank_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
-	out->vblank_hrtimer.function = &vkms_vblank_simulate;
-	out->period_ns = ktime_set(0, vblank->framedur_ns);
-	hrtimer_start(&out->vblank_hrtimer, out->period_ns, HRTIMER_MODE_REL);
+	hrtimer_init(&vkms_crtc->vblank_hrtimer, CLOCK_MONOTONIC,
+		     HRTIMER_MODE_REL);
+	vkms_crtc->vblank_hrtimer.function = &vkms_vblank_simulate;
+	vkms_crtc->period_ns = ktime_set(0, vblank->framedur_ns);
+	hrtimer_start(&vkms_crtc->vblank_hrtimer, vkms_crtc->period_ns,
+		      HRTIMER_MODE_REL);
 
 	return 0;
 }
 
 static void vkms_disable_vblank(struct drm_crtc *crtc)
 {
-	struct vkms_output *out = drm_crtc_to_vkms_output(crtc);
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
 
-	hrtimer_cancel(&out->vblank_hrtimer);
+	hrtimer_cancel(&vkms_crtc->vblank_hrtimer);
 }
 
 static bool vkms_get_vblank_timestamp(struct drm_crtc *crtc,
@@ -88,9 +90,8 @@ static bool vkms_get_vblank_timestamp(struct drm_crtc *crtc,
 				      bool in_vblank_irq)
 {
 	struct drm_device *dev = crtc->dev;
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
 	unsigned int pipe = crtc->index;
-	struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev);
-	struct vkms_output *output = &vkmsdev->output;
 	struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
 
 	if (!READ_ONCE(vblank->enabled)) {
@@ -98,7 +99,7 @@ static bool vkms_get_vblank_timestamp(struct drm_crtc *crtc,
 		return true;
 	}
 
-	*vblank_time = READ_ONCE(output->vblank_hrtimer.node.expires);
+	*vblank_time = READ_ONCE(vkms_crtc->vblank_hrtimer.node.expires);
 
 	if (WARN_ON(*vblank_time == vblank->time))
 		return true;
@@ -110,7 +111,7 @@ static bool vkms_get_vblank_timestamp(struct drm_crtc *crtc,
 	 * the vblank core expects. Therefore we need to always correct the
 	 * timestampe by one frame.
 	 */
-	*vblank_time -= output->period_ns;
+	*vblank_time -= vkms_crtc->period_ns;
 
 	return true;
 }
@@ -236,18 +237,18 @@ static void vkms_crtc_atomic_disable(struct drm_crtc *crtc,
 static void vkms_crtc_atomic_begin(struct drm_crtc *crtc,
 				   struct drm_atomic_state *state)
 {
-	struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
 
 	/* This lock is held across the atomic commit to block vblank timer
 	 * from scheduling vkms_composer_worker until the composer is updated
 	 */
-	spin_lock_irq(&vkms_output->lock);
+	spin_lock_irq(&vkms_crtc->lock);
 }
 
 static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
 				   struct drm_atomic_state *state)
 {
-	struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc);
+	struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc);
 
 	if (crtc->state->event) {
 		spin_lock(&crtc->dev->event_lock);
@@ -262,9 +263,9 @@ static void vkms_crtc_atomic_flush(struct drm_crtc *crtc,
 		crtc->state->event = NULL;
 	}
 
-	vkms_output->composer_state = to_vkms_crtc_state(crtc->state);
+	vkms_crtc->composer_state = to_vkms_crtc_state(crtc->state);
 
-	spin_unlock_irq(&vkms_output->lock);
+	spin_unlock_irq(&vkms_crtc->lock);
 }
 
 static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = {
@@ -275,27 +276,41 @@ static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = {
 	.atomic_disable	= vkms_crtc_atomic_disable,
 };
 
-int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
-		   struct drm_plane *primary, struct drm_plane *cursor)
+struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
+				 struct drm_plane *primary,
+				 struct drm_plane *cursor)
 {
-	struct vkms_output *vkms_out = drm_crtc_to_vkms_output(crtc);
+	struct drm_device *dev = &vkmsdev->drm;
+	struct vkms_crtc *vkms_crtc;
 	int ret;
 
-	ret = drmm_crtc_init_with_planes(dev, crtc, primary, cursor,
+	if (vkmsdev->output.num_crtcs >= VKMS_MAX_OUTPUT_OBJECTS) {
+		return ERR_PTR(-ENOMEM);
+	}
+	vkms_crtc = &vkmsdev->output.crtcs[vkmsdev->output.num_crtcs++];
+
+	ret = drmm_crtc_init_with_planes(dev, &vkms_crtc->base, primary, cursor,
 					 &vkms_crtc_funcs, NULL);
 	if (ret) {
 		DRM_ERROR("Failed to init CRTC\n");
-		return ret;
+		goto out_error;
 	}
 
-	drm_crtc_helper_add(crtc, &vkms_crtc_helper_funcs);
+	drm_crtc_helper_add(&vkms_crtc->base, &vkms_crtc_helper_funcs);
 
-	spin_lock_init(&vkms_out->lock);
-	spin_lock_init(&vkms_out->composer_lock);
+	spin_lock_init(&vkms_crtc->lock);
+	spin_lock_init(&vkms_crtc->composer_lock);
 
-	vkms_out->composer_workq = alloc_ordered_workqueue("vkms_composer", 0);
-	if (!vkms_out->composer_workq)
-		return -ENOMEM;
+	vkms_crtc->composer_workq = alloc_ordered_workqueue("vkms_composer", 0);
+	if (!vkms_crtc->composer_workq) {
+		ret = -ENOMEM;
+		goto out_error;
+	}
+
+	return vkms_crtc;
 
-	return ret;
+out_error:
+	memset(vkms_crtc, 0, sizeof(*vkms_crtc));
+	vkmsdev->output.num_crtcs -= 1;
+	return ERR_PTR(ret);
 }
drivers/gpu/drm/vkms/vkms_drv.c +7 -7
index f07454fff046..aa2bee82b757 100644
@@ -57,8 +57,8 @@ static void vkms_release(struct drm_device *dev)
 {
 	struct vkms_device *vkms = drm_device_to_vkms_device(dev);
 
-	if (vkms->output.composer_workq)
-		destroy_workqueue(vkms->output.composer_workq);
+	for (int i = 0; i < vkms->output.num_crtcs; i++)
+		destroy_workqueue(vkms->output.crtcs[i].composer_workq);
 }
 
 static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state)
@@ -185,15 +185,15 @@ static int vkms_platform_probe(struct platform_device *pdev)
 		goto out_release_group;
 	}
 
-	ret = drm_vblank_init(&vkms_device->drm, 1);
+	ret = vkms_modeset_init(vkms_device);
 	if (ret) {
-		DRM_ERROR("Failed to vblank\n");
+		DRM_ERROR("Unable to initialize modesetting\n");
 		goto out_release_group;
 	}
 
-	ret = vkms_modeset_init(vkms_device);
+	ret = drm_vblank_init(&vkms_device->drm, vkms_device->output.num_crtcs);
 	if (ret) {
-		DRM_ERROR("Unable to initialize modesetting\n");
+		DRM_ERROR("Failed to vblank\n");
 		goto out_release_group;
 	}
 
@@ -202,7 +202,7 @@ static int vkms_platform_probe(struct platform_device *pdev)
 
 	ret = drm_dev_register(&vkms_device->drm, 0);
 	if (ret) {
-		DRM_ERROR("Unable to register device\n");
+		DRM_ERROR("Unable to register device with id %d\n", pdev->id);
 		return ret;
 	}
 
drivers/gpu/drm/vkms/vkms_drv.h +41 -24
index e87c8aea6fb3..4c3274838ec7 100644
@@ -23,6 +23,9 @@
 
 #define NUM_OVERLAY_PLANES 8
 
+#define VKMS_MAX_OUTPUT_OBJECTS 16
+#define VKMS_MAX_PLANES (3 * VKMS_MAX_OUTPUT_OBJECTS)
+
 struct vkms_frame_info {
 	struct drm_framebuffer *fb;
 	struct drm_rect src, dst;
@@ -65,6 +68,25 @@ struct vkms_plane {
 	struct drm_plane base;
 };
 
+struct vkms_crtc {
+	struct drm_crtc base;
+
+	struct drm_writeback_connector wb_connector;
+	struct hrtimer vblank_hrtimer;
+	ktime_t period_ns;
+	struct drm_pending_vblank_event *event;
+	/* ordered wq for composer_work */
+	struct workqueue_struct *composer_workq;
+	/* protects concurrent access to composer */
+	spinlock_t lock;
+
+	/* protected by @lock */
+	bool composer_enabled;
+	struct vkms_crtc_state *composer_state;
+
+	spinlock_t composer_lock;
+};
+
 /**
  * vkms_crtc_state - Driver specific CRTC state
  * @base: base CRTC state
@@ -89,23 +111,14 @@ struct vkms_crtc_state {
 };
 
 struct vkms_output {
-	struct drm_crtc crtc;
-	struct drm_encoder encoder;
-	struct drm_connector connector;
-	struct drm_writeback_connector wb_connector;
-	struct hrtimer vblank_hrtimer;
-	ktime_t period_ns;
-	struct drm_pending_vblank_event *event;
-	/* ordered wq for composer_work */
-	struct workqueue_struct *composer_workq;
-	/* protects concurrent access to composer */
-	spinlock_t lock;
-
-	/* protected by @lock */
-	bool composer_enabled;
-	struct vkms_crtc_state *composer_state;
-
-	spinlock_t composer_lock;
+	int num_crtcs;
+	struct vkms_crtc crtcs[VKMS_MAX_OUTPUT_OBJECTS];
+	int num_encoders;
+	struct drm_encoder encoders[VKMS_MAX_OUTPUT_OBJECTS];
+	int num_connectors;
+	struct drm_connector connectors[VKMS_MAX_OUTPUT_OBJECTS];
+	int num_planes;
+	struct vkms_plane planes[VKMS_MAX_PLANES];
 };
 
 struct vkms_device;
@@ -123,12 +136,14 @@ struct vkms_device {
 	struct vkms_config config;
 };
 
-#define drm_crtc_to_vkms_output(target) \
-	container_of(target, struct vkms_output, crtc)
+#define drm_crtc_to_vkms_crtc(crtc) container_of(crtc, struct vkms_crtc, base)
 
 #define drm_device_to_vkms_device(target) \
 	container_of(target, struct vkms_device, drm)
 
+#define timer_to_vkms_crtc(timer) \
+	container_of(timer, struct vkms_crtc, vblank_hrtimer)
+
 #define to_vkms_crtc_state(target)\
 	container_of(target, struct vkms_crtc_state, base)
 
@@ -136,13 +151,14 @@ struct vkms_device {
 	container_of(target, struct vkms_plane_state, base.base)
 
 /* CRTC */
-int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc,
-		   struct drm_plane *primary, struct drm_plane *cursor);
+struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
+				 struct drm_plane *primary,
+				 struct drm_plane *cursor);
 
 int vkms_output_init(struct vkms_device *vkmsdev, int index);
 
 struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
-				   enum drm_plane_type type, int index);
+				   enum drm_plane_type type);
 
 /* CRC Support */
 const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
@@ -153,10 +169,11 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name,
 
 /* Composer Support */
 void vkms_composer_worker(struct work_struct *work);
-void vkms_set_composer(struct vkms_output *out, bool enabled);
+void vkms_set_composer(struct vkms_crtc *vkms_crtc, bool enabled);
 void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state *plane, int y);
 
 /* Writeback */
-int vkms_enable_writeback_connector(struct vkms_device *vkmsdev);
+int vkms_enable_writeback_connector(struct vkms_device *vkmsdev,
+				    struct vkms_crtc *vkms_crtc);
 
 #endif /* _VKMS_DRV_H_ */
drivers/gpu/drm/vkms/vkms_output.c +88 -35
index 963a64cf068b..6b4a77780d3c 100644
@@ -1,9 +1,13 @@
 // SPDX-License-Identifier: GPL-2.0+
 
-#include "vkms_drv.h"
 #include <drm/drm_atomic_helper.h>
+#include <drm/drm_connector.h>
 #include <drm/drm_edid.h>
+#include <drm/drm_encoder.h>
 #include <drm/drm_probe_helper.h>
+#include <drm/drm_simple_kms_helper.h>
+
+#include "vkms_drv.h"
 
 static const struct drm_connector_funcs vkms_connector_funcs = {
 	.fill_modes = drm_helper_probe_single_connector_modes,
@@ -28,74 +32,116 @@ static int vkms_conn_get_modes(struct drm_connector *connector)
 }
 
 static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = {
-	.get_modes    = vkms_conn_get_modes,
+	.get_modes = vkms_conn_get_modes,
 };
 
-static int vkms_add_overlay_plane(struct vkms_device *vkmsdev, int index,
-				  struct drm_crtc *crtc)
+static struct drm_connector *
+vkms_connector_init(struct vkms_device *vkms_device)
 {
-	struct vkms_plane *overlay;
+	struct drm_connector *connector;
+	int ret;
 
-	overlay = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_OVERLAY, index);
-	if (IS_ERR(overlay))
-		return PTR_ERR(overlay);
+	if (vkms_device->output.num_connectors >= VKMS_MAX_OUTPUT_OBJECTS)
+		return ERR_PTR(-ENOMEM);
 
-	if (!overlay->base.possible_crtcs)
-		overlay->base.possible_crtcs = drm_crtc_mask(crtc);
+	connector = &vkms_device->output
+			     .connectors[vkms_device->output.num_connectors++];
+	ret = drm_connector_init(&vkms_device->drm, connector,
+				 &vkms_connector_funcs,
+				 DRM_MODE_CONNECTOR_VIRTUAL);
+	if (ret) {
+		memset(connector, 0, sizeof(*connector));
+		vkms_device->output.num_connectors -= 1;
+		return ERR_PTR(ret);
+	}
 
-	return 0;
+	drm_connector_helper_add(connector, &vkms_conn_helper_funcs);
+
+	return connector;
+}
+
+static struct drm_encoder *vkms_encoder_init(struct vkms_device *vkms_device)
+{
+	struct drm_encoder *encoder;
+	int ret;
+
+	if (vkms_device->output.num_encoders >= VKMS_MAX_OUTPUT_OBJECTS)
+		return ERR_PTR(-ENOMEM);
+
+	encoder = &vkms_device->output
+			   .encoders[vkms_device->output.num_encoders++];
+	ret = drm_encoder_init(&vkms_device->drm, encoder, &vkms_encoder_funcs,
+			       DRM_MODE_ENCODER_VIRTUAL, NULL);
+	if (ret) {
+		memset(encoder, 0, sizeof(*encoder));
+		vkms_device->output.num_encoders -= 1;
+		return ERR_PTR(ret);
+	}
+	return 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_connector *connector = &output->connector;
-	struct drm_encoder *encoder = &output->encoder;
-	struct drm_crtc *crtc = &output->crtc;
+	struct drm_connector *connector;
+	struct drm_encoder *encoder;
+	struct vkms_crtc *vkms_crtc;
 	struct vkms_plane *primary, *cursor = NULL;
 	int ret;
 	int writeback;
 	unsigned int n;
 
-	primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index);
+	primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY);
 	if (IS_ERR(primary))
 		return PTR_ERR(primary);
 
 	if (vkmsdev->config.overlay) {
 		for (n = 0; n < NUM_OVERLAY_PLANES; n++) {
-			ret = vkms_add_overlay_plane(vkmsdev, index, crtc);
-			if (ret)
-				return ret;
+			struct vkms_plane *overlay = vkms_plane_init(
+				vkmsdev, DRM_PLANE_TYPE_OVERLAY);
+			if (IS_ERR(overlay)) {
+				ret = PTR_ERR(overlay);
+				goto err_planes;
+			}
 		}
 	}
 
 	if (vkmsdev->config.cursor) {
-		cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index);
-		if (IS_ERR(cursor))
-			return PTR_ERR(cursor);
+		cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR);
+		if (IS_ERR(cursor)) {
+			ret = PTR_ERR(cursor);
+			goto err_planes;
+		}
 	}
 
-	ret = vkms_crtc_init(dev, crtc, &primary->base, &cursor->base);
-	if (ret)
-		return ret;
+	vkms_crtc = vkms_crtc_init(vkmsdev, &primary->base,
+				   cursor ? &cursor->base : NULL);
+	if (IS_ERR(vkms_crtc)) {
+		DRM_ERROR("Failed to init crtc\n");
+		ret = PTR_ERR(vkms_crtc);
+		goto err_planes;
+	}
 
-	ret = drm_connector_init(dev, connector, &vkms_connector_funcs,
-				 DRM_MODE_CONNECTOR_VIRTUAL);
-	if (ret) {
+	for (int i = 0; i < vkmsdev->output.num_planes; i++) {
+		vkmsdev->output.planes[i].base.possible_crtcs |=
+			drm_crtc_mask(&vkms_crtc->base);
+	}
+
+	connector = vkms_connector_init(vkmsdev);
+	if (IS_ERR(connector)) {
 		DRM_ERROR("Failed to init connector\n");
+		ret = PTR_ERR(connector);
 		goto err_connector;
 	}
 
-	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) {
+	encoder = vkms_encoder_init(vkmsdev);
+	if (IS_ERR(encoder)) {
 		DRM_ERROR("Failed to init encoder\n");
+		ret = PTR_ERR(encoder);
 		goto err_encoder;
 	}
-	encoder->possible_crtcs = 1;
+	encoder->possible_crtcs |= drm_crtc_mask(&vkms_crtc->base);
 
 	ret = drm_connector_attach_encoder(connector, encoder);
 	if (ret) {
@@ -104,7 +150,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
 	}
 
 	if (vkmsdev->config.writeback) {
-		writeback = vkms_enable_writeback_connector(vkmsdev);
+		writeback = vkms_enable_writeback_connector(vkmsdev, vkms_crtc);
 		if (writeback)
 			DRM_ERROR("Failed to init writeback connector\n");
 	}
@@ -120,7 +166,14 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index)
 	drm_connector_cleanup(connector);
 
 err_connector:
-	drm_crtc_cleanup(crtc);
+	drm_crtc_cleanup(&vkms_crtc->base);
+
+err_planes:
+	for (int i = 0; i < output->num_planes; i++) {
+		drm_plane_cleanup(&output->planes[i].base);
+	}
+
+	memset(output, 0, sizeof(*output));
 
 	return ret;
 }
drivers/gpu/drm/vkms/vkms_plane.c +33 -11
index e5c625ab8e3e..f69621822c1b 100644
@@ -8,6 +8,8 @@
 #include <drm/drm_fourcc.h>
 #include <drm/drm_gem_atomic_helper.h>
 #include <drm/drm_gem_framebuffer_helper.h>
+#include <drm/drm_plane.h>
+#include <drm/drm_plane_helper.h>
 
 #include "vkms_drv.h"
 #include "vkms_formats.h"
@@ -65,6 +67,20 @@ static void vkms_plane_destroy_state(struct drm_plane *plane,
 	kfree(vkms_state);
 }
 
+static void vkms_plane_destroy(struct drm_plane *plane)
+{
+	struct vkms_plane *vkms_plane =
+		container_of(plane, struct vkms_plane, base);
+
+	if (plane->state) {
+		vkms_plane_destroy_state(plane, plane->state);
+		plane->state = NULL;
+	}
+
+	drm_plane_cleanup(plane);
+	memset(vkms_plane, 0, sizeof(struct vkms_plane));
+}
+
 static void vkms_plane_reset(struct drm_plane *plane)
 {
 	struct vkms_plane_state *vkms_state;
@@ -84,11 +100,12 @@ static void vkms_plane_reset(struct drm_plane *plane)
 }
 
 static const struct drm_plane_funcs vkms_plane_funcs = {
-	.update_plane		= drm_atomic_helper_update_plane,
-	.disable_plane		= drm_atomic_helper_disable_plane,
-	.reset			= vkms_plane_reset,
+	.update_plane = drm_atomic_helper_update_plane,
+	.disable_plane = drm_atomic_helper_disable_plane,
+	.destroy = vkms_plane_destroy,
+	.reset = vkms_plane_reset,
 	.atomic_duplicate_state = vkms_plane_duplicate_state,
-	.atomic_destroy_state	= vkms_plane_destroy_state,
+	.atomic_destroy_state = vkms_plane_destroy_state,
 };
 
 static void vkms_plane_atomic_update(struct drm_plane *plane,
@@ -198,17 +215,22 @@ static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = {
 };
 
 struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
-				   enum drm_plane_type type, int index)
+				   enum drm_plane_type type)
 {
 	struct drm_device *dev = &vkmsdev->drm;
+	struct vkms_output *output = &vkmsdev->output;
 	struct vkms_plane *plane;
+	int ret;
 
-	plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 1 << index,
-					   &vkms_plane_funcs,
-					   vkms_formats, ARRAY_SIZE(vkms_formats),
-					   NULL, type, NULL);
-	if (IS_ERR(plane))
-		return plane;
+	if (output->num_planes >= VKMS_MAX_PLANES)
+		return ERR_PTR(-ENOMEM);
+
+	plane = &output->planes[output->num_planes++];
+	ret = drm_universal_plane_init(dev, &plane->base, 0, &vkms_plane_funcs,
+				       vkms_formats, ARRAY_SIZE(vkms_formats),
+				       NULL, type, NULL);
+	if (ret)
+		return ERR_PTR(ret);
 
 	drm_plane_helper_add(&plane->base, &vkms_plane_helper_funcs);
 
drivers/gpu/drm/vkms/vkms_writeback.c +4 -3
index 84a51cd281b9..b90bcbd0a0e0 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 
 #include <linux/iosys-map.h>
+#include <linux/kernel.h>
 
 #include <drm/drm_atomic.h>
 #include <drm/drm_edid.h>
@@ -101,7 +102,8 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector,
 				struct drm_writeback_job *job)
 {
 	struct vkms_writeback_job *vkmsjob = job->priv;
-	struct vkms_device *vkmsdev;
+	struct vkms_crtc *vkms_crtc =
+		container_of(connector, struct vkms_crtc, wb_connector);
 
 	if (!job->fb)
 		return;
@@ -110,8 +112,7 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector,
 
 	drm_framebuffer_put(vkmsjob->wb_frame_info.fb);
 
-	vkmsdev = drm_device_to_vkms_device(job->fb->dev);
-	vkms_set_composer(&vkmsdev->output, false);
+	vkms_set_composer(vkms_crtc, false);
 	kfree(vkmsjob);
 }
 

drivers/gpu/drm/vkms/vkms_writeback.c static void vkms_wb_atomic_commit(struct drm_connector *conn, · line 127

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_writeback.c +3 -3
@@ -120,11 +121,11 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,
 {
 	struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state,
 											 conn);
-	struct vkms_device *vkmsdev = drm_device_to_vkms_device(conn->dev);
-	struct vkms_output *output = &vkmsdev->output;
-	struct drm_writeback_connector *wb_conn = &output->wb_connector;
+	struct vkms_crtc *vkms_crtc =
+		drm_crtc_to_vkms_crtc(connector_state->crtc);
+	struct drm_writeback_connector *wb_conn = &vkms_crtc->wb_connector;
 	struct drm_connector_state *conn_state = wb_conn->base.state;

No longer needed.

drivers/gpu/drm/vkms/vkms_writeback.c static void vkms_wb_atomic_commit(struct drm_connector *conn,

Quoted 6 lines
drivers/gpu/drm/vkms/vkms_writeback.c +1 -1
-	struct vkms_crtc_state *crtc_state = output->composer_state;
+	struct vkms_crtc_state *crtc_state = vkms_crtc->composer_state;
 	struct drm_framebuffer *fb = connector_state->writeback_job->fb;
 	u16 crtc_height = crtc_state->base.crtc->mode.vdisplay;
 	u16 crtc_width = crtc_state->base.crtc->mode.hdisplay;
@@ -135,18 +136,18 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,

This should be connector_state.

drivers/gpu/drm/vkms/vkms_writeback.c static void vkms_wb_atomic_commit(struct drm_connector *conn, · line 141

Quoted 7 lines
drivers/gpu/drm/vkms/vkms_writeback.c +1 -1
 	if (!conn_state)
 		return;
 
-	vkms_set_composer(&vkmsdev->output, true);
+	vkms_set_composer(vkms_crtc, true);
 
 	active_wb = conn_state->writeback_job->priv;

Same here, use connector_state, rather than conn_state.

Quoted 30 lines
drivers/gpu/drm/vkms/vkms_writeback.c +5 -4
 	wb_frame_info = &active_wb->wb_frame_info;
 
-	spin_lock_irq(&output->composer_lock);
+	spin_lock_irq(&vkms_crtc->composer_lock);
 	crtc_state->active_writeback = active_wb;
 	wb_frame_info->offset = fb->offsets[0];
 	wb_frame_info->pitch = fb->pitches[0];
 	wb_frame_info->cpp = fb->format->cpp[0];
 	crtc_state->wb_pending = true;
-	spin_unlock_irq(&output->composer_lock);
+	spin_unlock_irq(&vkms_crtc->composer_lock);
 	drm_writeback_queue_job(wb_conn, connector_state);
 	active_wb->wb_write = get_line_to_frame_function(wb_format);
 	drm_rect_init(&wb_frame_info->src, 0, 0, crtc_width, crtc_height);
@@ -160,9 +161,10 @@ static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = {
 	.atomic_commit = vkms_wb_atomic_commit,
 };
 
-int vkms_enable_writeback_connector(struct vkms_device *vkmsdev)
+int vkms_enable_writeback_connector(struct vkms_device *vkmsdev,
+				    struct vkms_crtc *vkms_crtc)
 {
-	struct drm_writeback_connector *wb = &vkmsdev->output.wb_connector;
+	struct drm_writeback_connector *wb = &vkms_crtc->wb_connector;
 
 	drm_connector_helper_add(&wb->base, &vkms_wb_conn_helper_funcs);
 
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#6 lore raw

Re: [PATCH v2 2/6] drm/vkms: Support multiple DRM objects (crtcs, etc.) per VKMS device

Thanks for taking the time, everyone! Sorry it took so long, we had some internal shuffling etc going on and I was building out what we needed these chagnes for in the first place, this will be the first of a few replies followed by a new version of the series to be sent out.

First up is a respons to Maria, Marius to follow.

---

Maria,

drivers/gpu/drm/vkms/vkms_drv.c static void vkms_release(struct drm_device *dev) · line 61

Quoted 4 lines
drivers/gpu/drm/vkms/vkms_drv.c +2 -2
-	if (vkms->output.composer_workq)
-		destroy_workqueue(vkms->output.composer_workq);
+	for (int i = 0; i < vkms->output.num_crtcs; i++)
+		destroy_workqueue(vkms->output.crtcs[i].composer_workq);

I don't believe there is any need for a null check. If you look in the crtc_init, it is zero'd before returning any errors and that is the only place it is set. I don't believe that release can be called by an interrupt/async (and if it did it would need a mutex/lock anyway).

drivers/gpu/drm/vkms/vkms_plane.c static void vkms_plane_reset(struct drm_plane *plane) · line 89

Quoted 5 lines
  static const struct drm_plane_funcs vkms_plane_funcs = {
drivers/gpu/drm/vkms/vkms_plane.c +0 -3
-	.update_plane		= drm_atomic_helper_update_plane,
-	.disable_plane		= drm_atomic_helper_disable_plane,
-	.reset			= vkms_plane_reset,

Yeah these do seem weirdly formatted on devices that don't treat tabs well. The default formatter on my editor has a few suggestions for this file, but they are all optional. I'll send an extra patch that formats stuff and see what people think, but ill make it seperate after all this is done. For now I reverted this.

Quoted 11 lines

drivers/gpu/drm/vkms/vkms_plane.c static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = { · line 231

Quoted 9 lines
drivers/gpu/drm/vkms/vkms_plane.c +7 -2
-	if (IS_ERR(plane))
-		return plane;
+	if (output->num_planes >= VKMS_MAX_PLANES)
+		return ERR_PTR(-ENOMEM);
+
+	plane = &output->planes[output->num_planes++];
+	ret = drm_universal_plane_init(dev, &plane->base, 0, &vkms_plane_funcs,
+				       vkms_formats, ARRAY_SIZE(vkms_formats),
+				       NULL, type, NULL);

Wouldn't be possible to use drmm_universal_plane_alloc?

Maybe, but the *_init pattern allows these things to be inline in the struct as they are now, and consistent with the other drm kernel objects in the vkms_output struct. There are also a few other places we could use drmm, surely, but to limit the scope/risk why don't we do that as a followup?

---

Marius,

Yeah those values could safely be completely removed. Good catch :)

#7 lore raw

Re: [PATCH v2 2/6] drm/vkms: Support multiple DRM objects (crtcs, etc.) per VKMS device

Silly addition but I need to apologize for mispelling somone's name in my reply.

Maira, please accept my sincere apology.

Quoted 50 lines · Brandon Pollack

Thanks for taking the time, everyone! Sorry it took so long, we had some internal shuffling etc going on and I was building out what we needed these chagnes for in the first place, this will be the first of a few replies followed by a new version of the series to be sent out.

First up is a respons to Maria, Marius to follow.

---

Maria,

drivers/gpu/drm/vkms/vkms_drv.c static void vkms_release(struct drm_device *dev) · line 61

Quoted 4 lines
drivers/gpu/drm/vkms/vkms_drv.c +2 -2
-	if (vkms->output.composer_workq)
-		destroy_workqueue(vkms->output.composer_workq);
+	for (int i = 0; i < vkms->output.num_crtcs; i++)
+		destroy_workqueue(vkms->output.crtcs[i].composer_workq);

I don't believe there is any need for a null check. If you look in the crtc_init, it is zero'd before returning any errors and that is the only place it is set. I don't believe that release can be called by an interrupt/async (and if it did it would need a mutex/lock anyway).

drivers/gpu/drm/vkms/vkms_plane.c static void vkms_plane_reset(struct drm_plane *plane) · line 89

Quoted 4 lines
   static const struct drm_plane_funcs vkms_plane_funcs = {
drivers/gpu/drm/vkms/vkms_plane.c +0 -3
-	.update_plane		= drm_atomic_helper_update_plane,
-	.disable_plane		= drm_atomic_helper_disable_plane,
-	.reset			= vkms_plane_reset,

Yeah these do seem weirdly formatted on devices that don't treat tabs well. The default formatter on my editor has a few suggestions for this file, but they are all optional. I'll send an extra patch that formats stuff and see what people think, but ill make it seperate after all this is done. For now I reverted this.

Quoted 10 lines

drivers/gpu/drm/vkms/vkms_plane.c static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = { · line 231

Quoted 9 lines
drivers/gpu/drm/vkms/vkms_plane.c +7 -2
-	if (IS_ERR(plane))
-		return plane;
+	if (output->num_planes >= VKMS_MAX_PLANES)
+		return ERR_PTR(-ENOMEM);
+
+	plane = &output->planes[output->num_planes++];
+	ret = drm_universal_plane_init(dev, &plane->base, 0, &vkms_plane_funcs,
+				       vkms_formats, ARRAY_SIZE(vkms_formats),
+				       NULL, type, NULL);

Wouldn't be possible to use drmm_universal_plane_alloc?

Maybe, but the *_init pattern allows these things to be inline in the struct as they are now, and consistent with the other drm kernel objects in the vkms_output struct. There are also a few other places we could use drmm, surely, but to limit the scope/risk why don't we do that as a followup?

---

Marius,

Yeah those values could safely be completely removed. Good catch :)

author
#8 lore raw

PATCH v2 3/6 drm/vkms: Provide platform data when creating VKMS devices

In reply to Jim Shargo

This is a small refactor to make ConfigFS support easier. This should be a no-op refactor.

---
 drivers/gpu/drm/vkms/vkms_drv.c    | 13 +++++++++++--
 drivers/gpu/drm/vkms/vkms_drv.h    |  9 ++++++---
 drivers/gpu/drm/vkms/vkms_output.c |  2 +-
 3 files changed, 18 insertions(+), 6 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.c +11 -2
index aa2bee82b757..d43121addf66 100644
@@ -152,12 +152,14 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev)
 	dev->mode_config.preferred_depth = 0;
 	dev->mode_config.helper_private = &vkms_mode_config_helpers;
 
-	return vkms_output_init(vkmsdev, 0);
+	return vkmsdev->is_default ? vkms_output_init_default(vkmsdev) :
+				     -ENOSYS;
 }
 
 static int vkms_platform_probe(struct platform_device *pdev)
 {
 	int ret;
+	struct vkms_device_setup *vkms_device_setup = pdev->dev.platform_data;
 	struct vkms_device *vkms_device;
 	void *grp;
 
@@ -177,6 +179,7 @@ static int vkms_platform_probe(struct platform_device *pdev)
 	vkms_device->config.cursor = enable_cursor;
 	vkms_device->config.writeback = enable_writeback;
 	vkms_device->config.overlay = enable_overlay;
+	vkms_device->is_default = vkms_device_setup->is_default;
 
 	ret = dma_coerce_mask_and_coherent(vkms_device->drm.dev,
 					   DMA_BIT_MASK(64));
@@ -240,6 +243,9 @@ static int __init vkms_init(void)
 {
 	int ret;
 	struct platform_device *pdev;
+	struct vkms_device_setup vkms_device_setup = {
+		.is_default = true,
+	};
 
 	ret = platform_driver_register(&vkms_platform_driver);
 	if (ret) {
@@ -247,8 +253,11 @@ static int __init vkms_init(void)
 		return ret;
 	}
 
-	pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0);
+	pdev = platform_device_register_data(NULL, DRIVER_NAME, 0,
+					     &vkms_device_setup,
+					     sizeof(vkms_device_setup));
 	if (IS_ERR(pdev)) {
+		DRM_ERROR("Unable to register default vkms device\n");
 		platform_driver_unregister(&vkms_platform_driver);
 		return PTR_ERR(pdev);
 	}
drivers/gpu/drm/vkms/vkms_drv.h +6 -3
index 4c3274838ec7..84b35aa1dc5a 100644
@@ -121,17 +121,20 @@ struct vkms_output {
 	struct vkms_plane planes[VKMS_MAX_PLANES];
 };
 
-struct vkms_device;
-
 struct vkms_config {
 	bool writeback;
 	bool cursor;
 	bool overlay;
 };
 
+struct vkms_device_setup {
+	bool is_default;
+};
+
 struct vkms_device {
 	struct drm_device drm;
 	struct platform_device *platform;
+	bool is_default;
 	struct vkms_output output;
 	struct vkms_config config;
 };
@@ -155,7 +158,7 @@ struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
 				 struct drm_plane *primary,
 				 struct drm_plane *cursor);
 
-int vkms_output_init(struct vkms_device *vkmsdev, int index);
+int vkms_output_init_default(struct vkms_device *vkmsdev);
 
 struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
 				   enum drm_plane_type type);
drivers/gpu/drm/vkms/vkms_output.c +1 -1
index 6b4a77780d3c..3b5e272a8b33 100644
@@ -80,7 +80,7 @@ static struct drm_encoder *vkms_encoder_init(struct vkms_device *vkms_device)
 	return encoder;
 }
 
-int vkms_output_init(struct vkms_device *vkmsdev, int index)
+int vkms_output_init_default(struct vkms_device *vkmsdev)
 {
 	struct vkms_output *output = &vkmsdev->output;
 	struct drm_device *dev = &vkmsdev->drm;
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
author
#9 lore raw

PATCH v2 4/6 drm/vkms: Add ConfigFS scaffolding to VKMS

In reply to Jim Shargo

This change adds the basic scaffolding for ConfigFS, including setting up the default directories. It does not allow for the registration of configfs-backed devices, which is complex and provided in a follow-up commit.

This CL includes docs about using ConfigFS with VKMS, but I'll summarize in brief here as well (assuming ConfigFS is mounted at /config/):

To create a new device, you can do so via `mkdir
/config/vkms/my-device`.

This will create a number of directories and files automatically:

	/config
	`-- vkms
	    `-- my-device
		|-- connectors
		|-- crtcs
		|-- encoders
		|-- planes
		`-- enabled

You can then configure objects by mkdir'ing in each of the directories.

When you're satisfied, you can echo 1 > /config/vkms/my-device/enabled. This will create a new device according to your configuration.

For now, this will fail, but the next change will add support for it.

---
 Documentation/gpu/vkms.rst           |  17 +-
 drivers/gpu/drm/Kconfig              |   1 +
 drivers/gpu/drm/vkms/Makefile        |   1 +
 drivers/gpu/drm/vkms/vkms_configfs.c | 646 +++++++++++++++++++++++++++
 drivers/gpu/drm/vkms/vkms_drv.c      |  52 ++-
 drivers/gpu/drm/vkms/vkms_drv.h      |  92 +++-
 drivers/gpu/drm/vkms/vkms_output.c   |   5 +
 7 files changed, 799 insertions(+), 15 deletions(-)
 create mode 100644 drivers/gpu/drm/vkms/vkms_configfs.c
Documentation/gpu/vkms.rst +8 -9
index ba04ac7c2167..2c342ef0fb7b 100644
@@ -51,6 +51,12 @@ To disable the driver, use ::
 
   sudo modprobe -r vkms
 
+Configuration With ConfigFS
+===========================
+
+.. kernel-doc:: drivers/gpu/drm/vkms/vkms_configfs.c
+   :doc: ConfigFS Support for VKMS
+
 Testing With IGT
 ================
 
@@ -135,22 +141,15 @@ project.
 Runtime Configuration
 ---------------------
 
-We want to be able to reconfigure vkms instance without having to reload the
-module. Use/Test-cases:
+We want to vkms instances without having to reload the module. Such 
+configuration can be added as extensions to vkms's ConfigFS support. Use-cases:
 
 - Hotplug/hotremove connectors on the fly (to be able to test DP MST handling
   of compositors).
 
-- Configure planes/crtcs/connectors (we'd need some code to have more than 1 of
-  them first).
-
 - Change output configuration: Plug/unplug screens, change EDID, allow changing
   the refresh rate.
 
-The currently proposed solution is to expose vkms configuration through
-configfs. All existing module options should be supported through configfs
-too.
-
 Writeback support
 -----------------
 
drivers/gpu/drm/Kconfig +1 -0
index afb3b2f5f425..71eb913b378f 100644
@@ -262,6 +262,7 @@ config DRM_VKMS
 	depends on DRM && MMU
 	select DRM_KMS_HELPER
 	select DRM_GEM_SHMEM_HELPER
+	select CONFIGFS_FS
 	select CRC32
 	default n
 	help
drivers/gpu/drm/vkms/Makefile +1 -0
index 1b28a6a32948..6b83907ad554 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 vkms-y := \
+	vkms_configfs.o \
 	vkms_drv.o \
 	vkms_plane.o \
 	vkms_output.o \
drivers/gpu/drm/vkms/vkms_configfs.c new file +646 -0

646 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_drv.c +48 -4

100 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_drv.h +90 -2

131 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_output.c +5 -0
index 3b5e272a8b33..c9e6c653de19 100644
@@ -177,3 +177,8 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)
 
 	return ret;
 }
+
+int vkms_output_init(struct vkms_device *vkmsdev)
+{
+	return -ENOTSUPP;
+}
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#10 lore raw

Re: [PATCH v2 4/6] drm/vkms: Add ConfigFS scaffolding to VKMS

Hi Jim,

Quoted 59 lines · Jim Shargo

This change adds the basic scaffolding for ConfigFS, including setting up the default directories. It does not allow for the registration of configfs-backed devices, which is complex and provided in a follow-up commit.

This CL includes docs about using ConfigFS with VKMS, but I'll summarize in brief here as well (assuming ConfigFS is mounted at /config/):

To create a new device, you can do so via `mkdir
/config/vkms/my-device`.

This will create a number of directories and files automatically:

	/config
	`-- vkms
	    `-- my-device
		|-- connectors
		|-- crtcs
		|-- encoders
		|-- planes
		`-- enabled

You can then configure objects by mkdir'ing in each of the directories.

When you're satisfied, you can echo 1 > /config/vkms/my-device/enabled. This will create a new device according to your configuration.

For now, this will fail, but the next change will add support for it.

---
  Documentation/gpu/vkms.rst           |  17 +-
  drivers/gpu/drm/Kconfig              |   1 +
  drivers/gpu/drm/vkms/Makefile        |   1 +
  drivers/gpu/drm/vkms/vkms_configfs.c | 646 +++++++++++++++++++++++++++
  drivers/gpu/drm/vkms/vkms_drv.c      |  52 ++-
  drivers/gpu/drm/vkms/vkms_drv.h      |  92 +++-
  drivers/gpu/drm/vkms/vkms_output.c   |   5 +
  7 files changed, 799 insertions(+), 15 deletions(-)

create mode 100644 drivers/gpu/drm/vkms/vkms_configfs.c

Documentation/gpu/vkms.rst +6 -0
index ba04ac7c2167..2c342ef0fb7b 100644
@@ -51,6 +51,12 @@ To disable the driver, use ::
 
    sudo modprobe -r vkms
 
+Configuration With ConfigFS
+===========================
+
+.. kernel-doc:: drivers/gpu/drm/vkms/vkms_configfs.c
+   :doc: ConfigFS Support for VKMS
+
  Testing With IGT
  ================
 

Documentation/gpu/vkms.rst project. · line 144

Quoted 6 lines
Documentation/gpu/vkms.rst +1 -2
@@ -135,22 +141,15 @@ project.
  Runtime Configuration
  ---------------------
 
-We want to be able to reconfigure vkms instance without having to reload the
-module. Use/Test-cases:
+We want to vkms instances without having to reload the module. Such

I believe that there is a verb missing here.

Quoted 82 lines
Documentation/gpu/vkms.rst +1 -7
+configuration can be added as extensions to vkms's ConfigFS support. Use-cases:
 
  - Hotplug/hotremove connectors on the fly (to be able to test DP MST handling
    of compositors).
 
-- Configure planes/crtcs/connectors (we'd need some code to have more than 1 of
-  them first).
-
  - Change output configuration: Plug/unplug screens, change EDID, allow changing
    the refresh rate.
 
-The currently proposed solution is to expose vkms configuration through
-configfs. All existing module options should be supported through configfs
-too.
-
  Writeback support
  -----------------
 
drivers/gpu/drm/Kconfig +1 -0
index afb3b2f5f425..71eb913b378f 100644
@@ -262,6 +262,7 @@ config DRM_VKMS
  	depends on DRM && MMU
  	select DRM_KMS_HELPER
  	select DRM_GEM_SHMEM_HELPER
+	select CONFIGFS_FS
  	select CRC32
  	default n
  	help
drivers/gpu/drm/vkms/Makefile +1 -0
index 1b28a6a32948..6b83907ad554 100644
@@ -1,5 +1,6 @@
  # SPDX-License-Identifier: GPL-2.0-only
  vkms-y := \
+	vkms_configfs.o \
  	vkms_drv.o \
  	vkms_plane.o \
  	vkms_output.o \
drivers/gpu/drm/vkms/vkms_configfs.c new file +35 -0
new file mode 100644
index 000000000000..544024735d19
@@ -0,0 +1,646 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <linux/configfs.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+
+#include <drm/drm_plane.h>
+#include <drm/drm_print.h>
+
+#include "vkms_drv.h"
+
+/**
+ * DOC: ConfigFS Support for VKMS
+ *
+ * VKMS is instrumented with support for configuration via :doc:`ConfigFS
+ * <../filesystems/configfs>`.
+ *
+ * With VKMS installed, you can mount ConfigFS at ``/config/`` like so::
+ *
+ *   mkdir -p /config/
+ *   sudo mount -t configfs none /config
+ *
+ * This allows you to configure multiple virtual devices in addition to an
+ * immutable "default" device created by the driver at initialization time. Note
+ * that the default device is immutable because we cannot pre-populate ConfigFS
+ * directories with normal files.
+ *
+ * To set up a new device, create a new directory under the VKMS configfs
+ * directory::
+ *
+ *   mkdir /config/vkms/test
+ *
+ * With your device created you'll find an new directory ready to be
+ * configured::
+ *

drivers/gpu/drm/vkms/vkms_configfs.c line 45

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_configfs.c new file +10 -0
+ *   /config
+ *   `-- vkms
+ *       |-- default
+ *       |   `-- enabled
+ *       `-- test
+ *           |-- connectors
+ *           |-- crtcs
+ *           |-- encoders
+ *           |-- planes
+ *           `-- enabled

I followed this steps and ended up with the following tree:

[root@fedora config]# tree vkms
vkms

└── test
    ├── connectors
    ├── crtcs
    ├── enabled
    ├── encoders
    ├── id
    └── planes

I'm not sure if I did something wrong or if the folder "default" really shouldn't show. If the folder "default" shouldn't show, it would be nice to remove it from the docs.

Quoted 74 lines
drivers/gpu/drm/vkms/vkms_configfs.c new file +74 -0
+ *
+ * Each directory you add within the connectors, crtcs, encoders, and planes
+ * directories will let you configure a new object of that type. Adding new
+ * objects will automatically create a set of default files and folders you can
+ * use to configure that object.
+ *
+ * For instance, we can set up a two-output device like so::
+ *
+ *   DRM_PLANE_TYPE_PRIMARY=1
+ *   DRM_PLANE_TYPE_CURSOR=2
+ *   DRM_PLANE_TYPE_OVERLAY=0
+ *
+ *   mkdir /config/vkms/test/planes/primary
+ *   echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/primary/type
+ *
+ *   mkdir /config/vkms/test/planes/other_primary
+ *   echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/other_primary/type
+ *
+ *   mkdir /config/vkms/test/planes/cursor
+ *   echo $DRM_PLANE_TYPE_CURSOR > /config/vkms/test/planes/cursor/type
+ *
+ *   mkdir /config/vkms/test/planes/overlay
+ *   echo $DRM_PLANE_TYPE_OVERLAY > /config/vkms/test/planes/overlay/type
+ *
+ *   mkdir /config/vkms/test/crtcs/crtc
+ *   mkdir /config/vkms/test/crtcs/crtc_other
+ *   mkdir /config/vkms/test/encoders/encoder
+ *   mkdir /config/vkms/test/connectors/connector
+ *
+ * You can see that specific attributes, such as ``.../<plane>/type``, can be
+ * configured by writing into them. Associating objects together can be done via
+ * symlinks::
+ *
+ *   ln -s /config/vkms/test/encoders/encoder /config/vkms/test/connectors/connector/possible_encoders
+ *
+ *   ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/encoders/encoder/possible_crtcs/
+ *   ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/primary/possible_crtcs/
+ *   ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/cursor/possible_crtcs/
+ *   ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/overlay/possible_crtcs/
+ *
+ *   ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/overlay/possible_crtcs/
+ *   ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/other_primary/possible_crtcs/
+ *
+ * Finally, to enable your configured device, just write 1 to the ``enabled``
+ * file::
+ *
+ *   echo 1 > /config/vkms/test/enabled
+ *
+ * When you're done with the virtual device, you can clean up the device like
+ * so::
+ *
+ *   echo 0 > /config/vkms/test/enabled
+ *
+ *   rm /config/vkms/test/connectors/connector/possible_encoders/encoder
+ *   rm /config/vkms/test/encoders/encoder/possible_crtcs/crtc
+ *   rm /config/vkms/test/planes/primary/possible_crtcs/crtc
+ *   rm /config/vkms/test/planes/cursor/possible_crtcs/crtc
+ *   rm /config/vkms/test/planes/overlay/possible_crtcs/crtc
+ *   rm /config/vkms/test/planes/overlay/possible_crtcs/crtc_other
+ *   rm /config/vkms/test/planes/other_primary/possible_crtcs/crtc_other
+ *
+ *   rmdir /config/vkms/test/planes/primary
+ *   rmdir /config/vkms/test/planes/other_primary
+ *   rmdir /config/vkms/test/planes/cursor
+ *   rmdir /config/vkms/test/planes/overlay
+ *   rmdir /config/vkms/test/crtcs/crtc
+ *   rmdir /config/vkms/test/crtcs/crtc_other
+ *   rmdir /config/vkms/test/encoders/encoder
+ *   rmdir /config/vkms/test/connectors/connector
+ *
+ *   rmdir /config/vkms/test
+ */
+
+/*

[...]

Quoted 16 lines
drivers/gpu/drm/vkms/vkms_drv.c +3 -0
index d43121addf66..1b5b7143792f 100644
@@ -9,7 +9,10 @@
   * the GPU in DRM API tests.
   */
 
+#include <linux/configfs.h>
  #include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/err.h>
  #include <linux/module.h>
  #include <linux/platform_device.h>
  #include <linux/dma-mapping.h>

drivers/gpu/drm/vkms/vkms_drv.c static int vkms_modeset_init(struct vkms_device *vkmsdev) · line 156

Quoted 5 lines
drivers/gpu/drm/vkms/vkms_drv.c +0 -2
@@ -152,8 +155,8 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev)
  	dev->mode_config.preferred_depth = 0;
  	dev->mode_config.helper_private = &vkms_mode_config_helpers;
 
-	return vkmsdev->is_default ? vkms_output_init_default(vkmsdev) :
-				     -ENOSYS;

Is this middle step really needed?

Best Regards,
- Maíra

Quoted 243 lines
drivers/gpu/drm/vkms/vkms_drv.c +45 -2
+	return vkmsdev->configfs ? vkms_output_init(vkmsdev) :
+				   vkms_output_init_default(vkmsdev);
  }
 
  static int vkms_platform_probe(struct platform_device *pdev)
@@ -165,6 +168,7 @@ static int vkms_platform_probe(struct platform_device *pdev)
 
  	grp = devres_open_group(&pdev->dev, NULL, GFP_KERNEL);
  	if (!grp) {
+		DRM_ERROR("Could not open devres group\n");
  		return -ENOMEM;
  	}
 
@@ -179,7 +183,7 @@ static int vkms_platform_probe(struct platform_device *pdev)
  	vkms_device->config.cursor = enable_cursor;
  	vkms_device->config.writeback = enable_writeback;
  	vkms_device->config.overlay = enable_overlay;
-	vkms_device->is_default = vkms_device_setup->is_default;
+	vkms_device->configfs = vkms_device_setup->configfs;
 
  	ret = dma_coerce_mask_and_coherent(vkms_device->drm.dev,
  					   DMA_BIT_MASK(64));
@@ -239,12 +243,43 @@ static struct platform_driver vkms_platform_driver = {
  	.driver.name = DRIVER_NAME,
  };
 
+struct vkms_device *vkms_add_device(struct vkms_configfs *configfs)
+{
+	struct device *dev = NULL;
+	struct platform_device *pdev;
+	int max_id = 1;
+	struct vkms_device_setup vkms_device_setup = {
+		.configfs = configfs,
+	};
+
+	while ((dev = platform_find_device_by_driver(
+			dev, &vkms_platform_driver.driver))) {
+		pdev = to_platform_device(dev);
+		max_id = max(max_id, pdev->id);
+	}
+
+	pdev = platform_device_register_data(NULL, DRIVER_NAME, max_id + 1,
+					     &vkms_device_setup,
+					     sizeof(vkms_device_setup));
+	if (IS_ERR(pdev)) {
+		DRM_ERROR("Unable to register vkms device'\n");
+		return ERR_PTR(PTR_ERR(pdev));
+	}
+
+	return platform_get_drvdata(pdev);
+}
+
+void vkms_remove_device(struct vkms_device *vkms_device)
+{
+	platform_device_unregister(vkms_device->platform);
+}
+
  static int __init vkms_init(void)
  {
  	int ret;
  	struct platform_device *pdev;
  	struct vkms_device_setup vkms_device_setup = {
-		.is_default = true,
+		.configfs = NULL,
  	};
 
  	ret = platform_driver_register(&vkms_platform_driver);
@@ -262,6 +297,13 @@ static int __init vkms_init(void)
  		return PTR_ERR(pdev);
  	}
 
+	ret = vkms_init_configfs();
+	if (ret) {
+		DRM_ERROR("Unable to initialize configfs\n");
+		platform_device_unregister(pdev);
+		platform_driver_unregister(&vkms_platform_driver);
+	}
+
  	return 0;
  }
 
@@ -269,6 +311,8 @@ static void __exit vkms_exit(void)
  {
  	struct device *dev;
 
+	vkms_unregister_configfs();
+
  	while ((dev = platform_find_device_by_driver(
  			NULL, &vkms_platform_driver.driver))) {
  		// platform_find_device_by_driver increments the refcount. Drop
drivers/gpu/drm/vkms/vkms_drv.h +90 -2
index 84b35aa1dc5a..3634eeeb4548 100644
@@ -3,6 +3,7 @@
  #ifndef _VKMS_DRV_H_
  #define _VKMS_DRV_H_
 
+#include <linux/configfs.h>
  #include <linux/hrtimer.h>
 
  #include <drm/drm.h>
@@ -10,6 +11,7 @@
  #include <drm/drm_gem.h>
  #include <drm/drm_gem_atomic_helper.h>
  #include <drm/drm_encoder.h>
+#include <drm/drm_plane.h>
  #include <drm/drm_writeback.h>
 
  #define XRES_MIN    10
@@ -127,14 +129,65 @@ struct vkms_config {
  	bool overlay;
  };
 
+struct vkms_config_links {
+	struct config_group group;
+	unsigned long linked_object_bitmap;
+};
+
+struct vkms_config_connector {
+	struct config_group config_group;
+	struct vkms_config_links possible_encoders;
+};
+
+struct vkms_config_crtc {
+	struct config_group config_group;
+	unsigned long crtc_config_idx;
+};
+
+struct vkms_config_encoder {
+	struct config_group config_group;
+	struct vkms_config_links possible_crtcs;
+	unsigned long encoder_config_idx;
+};
+
+struct vkms_config_plane {
+	struct vkms_configfs *configfs;
+	struct config_group config_group;
+	struct vkms_config_links possible_crtcs;
+	enum drm_plane_type type;
+};
+
+struct vkms_configfs {
+	/* Directory group containing connector configs, e.g. /config/vkms/device/ */
+	struct config_group device_group;
+	/* Directory group containing connector configs, e.g. /config/vkms/device/connectors/ */
+	struct config_group connectors_group;
+	/* Directory group containing CRTC configs, e.g. /config/vkms/device/crtcs/ */
+	struct config_group crtcs_group;
+	/* Directory group containing encoder configs, e.g. /config/vkms/device/encoders/ */
+	struct config_group encoders_group;
+	/* Directory group containing plane configs, e.g. /config/vkms/device/planes/ */
+	struct config_group planes_group;
+
+	unsigned long allocated_crtcs;
+	unsigned long allocated_encoders;
+
+	struct mutex lock;
+
+	/* The platform device if this is registered, otherwise NULL */
+	struct vkms_device *vkms_device;
+};
+
  struct vkms_device_setup {
-	bool is_default;
+	// Is NULL in the case of the default card.
+	struct vkms_configfs *configfs;
  };
 
  struct vkms_device {
  	struct drm_device drm;
  	struct platform_device *platform;
-	bool is_default;
+	// Is NULL in the case of the default card.
+	struct vkms_configfs *configfs;
  	struct vkms_output output;
  	struct vkms_config config;
  };
@@ -153,11 +206,42 @@ struct vkms_device {
  #define to_vkms_plane_state(target)\
  	container_of(target, struct vkms_plane_state, base.base)
 
+#define item_to_configfs(item) \
+	container_of(to_config_group(item), struct vkms_configfs, device_group)
+
+#define item_to_config_connector(item)                                    \
+	container_of(to_config_group(item), struct vkms_config_connector, \
+		     config_group)
+
+#define item_to_config_crtc(item)                                    \
+	container_of(to_config_group(item), struct vkms_config_crtc, \
+		     config_group)
+
+#define item_to_config_encoder(item)                                    \
+	container_of(to_config_group(item), struct vkms_config_encoder, \
+		     config_group)
+
+#define item_to_config_plane(item)                                    \
+	container_of(to_config_group(item), struct vkms_config_plane, \
+		     config_group)
+
+#define item_to_config_links(item) \
+	container_of(to_config_group(item), struct vkms_config_links, group)
+
+#define plane_item_to_configfs(item)                                         \
+	container_of(to_config_group(item->ci_parent), struct vkms_configfs, \
+		     planes_group)
+
+/* Devices */
+struct vkms_device *vkms_add_device(struct vkms_configfs *configfs);
+void vkms_remove_device(struct vkms_device *vkms_device);
+
  /* CRTC */
  struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
  				 struct drm_plane *primary,
  				 struct drm_plane *cursor);
 
+int vkms_output_init(struct vkms_device *vkmsdev);
  int vkms_output_init_default(struct vkms_device *vkmsdev);
 
  struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev,
@@ -179,4 +263,8 @@ void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state
  int vkms_enable_writeback_connector(struct vkms_device *vkmsdev,
  				    struct vkms_crtc *vkms_crtc);
 
+/* ConfigFS Support */
+int vkms_init_configfs(void);
+void vkms_unregister_configfs(void);
+
  #endif /* _VKMS_DRV_H_ */
drivers/gpu/drm/vkms/vkms_output.c +5 -0
index 3b5e272a8b33..c9e6c653de19 100644
@@ -177,3 +177,8 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)
 
  	return ret;
  }
+
+int vkms_output_init(struct vkms_device *vkmsdev)
+{
+	return -ENOTSUPP;
+}
#11 lore raw

Re: [PATCH v2 4/6] drm/vkms: Add ConfigFS scaffolding to VKMS

In reply to Jim Shargo
kernel test robot noticed the following build warnings:

Hi Jim,

kernel test robot noticed the following build warnings:

[auto build test WARNING on drm-misc/drm-misc-next]
[also build test WARNING on drm-intel/for-linux-next next-20230627] [cannot apply to drm-intel/for-linux-next-fixes drm-tip/drm-tip linus/master v6.4] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Jim-Shargo/drm-vkms-Back-VKMS-with-DRM-memory-management-instead-of-static-objects/20230624-062659
base:   git://anongit.freedesktop.org/drm/drm-misc drm-misc-next
patch link:    https://lore.kernel.org/r/20230623222353.97283-5-jshargo%40chromium.org
patch subject: [PATCH v2 4/6] drm/vkms: Add ConfigFS scaffolding to VKMS
config: xtensa-randconfig-r052-20230627 (https://download.01.org/0day-ci/archive/20230628/[email protected]/config)
compiler: xtensa-linux-gcc (GCC) 12.3.0
reproduce: (https://download.01.org/0day-ci/archive/20230628/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

cocci warnings: (new ones prefixed by >>)

>> drivers/gpu/drm/vkms/vkms_drv.c:266:9-16: WARNING: ERR_CAST can be used with pdev
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
author
#12 lore raw

PATCH v2 5/6 drm/vkms: Support enabling ConfigFS devices

In reply to Jim Shargo

VKMS now supports creating and using virtual devices!

In addition to the enabling logic, this commit also prevents users from adding new objects once a card is registered.

---
 drivers/gpu/drm/vkms/vkms_configfs.c |  37 +++--
 drivers/gpu/drm/vkms/vkms_crtc.c     |   4 +-
 drivers/gpu/drm/vkms/vkms_drv.c      |   3 +-
 drivers/gpu/drm/vkms/vkms_drv.h      |   2 +-
 drivers/gpu/drm/vkms/vkms_output.c   | 201 +++++++++++++++++++++++----
 5 files changed, 202 insertions(+), 45 deletions(-)
drivers/gpu/drm/vkms/vkms_configfs.c +24 -13
index 544024735d19..f5eed6d23dcd 100644
@@ -504,29 +504,40 @@ static ssize_t device_enabled_store(struct config_item *item, const char *buf,
 {
 	struct vkms_configfs *configfs = item_to_configfs(item);
 	struct vkms_device *device;
-	int value, ret;
+	int enabled, ret;
 
-	ret = kstrtoint(buf, 0, &value);
+	ret = kstrtoint(buf, 0, &enabled);
 	if (ret)
 		return ret;
 
-	if (value != 1)
-		return -EINVAL;
-
-	mutex_lock(&configfs->lock);
-
-	if (configfs->vkms_device) {
+	if (enabled == 0) {
+		mutex_lock(&configfs->lock);
+		if (configfs->vkms_device) {
+			vkms_remove_device(configfs->vkms_device);
+			configfs->vkms_device = NULL;
+		}
 		mutex_unlock(&configfs->lock);
+
 		return len;
 	}
 
-	device = vkms_add_device(configfs);
-	mutex_unlock(&configfs->lock);
+	if (enabled == 1) {
+		mutex_lock(&configfs->lock);
+		if (!configfs->vkms_device) {
+			device = vkms_add_device(configfs);
+			if (IS_ERR(device)) {
+				mutex_unlock(&configfs->lock);
+				return -PTR_ERR(device);
+			}
+
+			configfs->vkms_device = device;
+		}
+		mutex_unlock(&configfs->lock);
 
-	if (IS_ERR(device))
-		return -PTR_ERR(device);
+		return len;
+	}
 
-	return len;
+	return -EINVAL;
 }
 
 CONFIGFS_ATTR(device_, enabled);
drivers/gpu/drm/vkms/vkms_crtc.c +2 -2
index d91e49c53adc..5ebb5264f6ef 100644
@@ -278,7 +278,7 @@ static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = {
 
 struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
 				 struct drm_plane *primary,
-				 struct drm_plane *cursor)
+				 struct drm_plane *cursor, const char *name)
 {
 	struct drm_device *dev = &vkmsdev->drm;
 	struct vkms_crtc *vkms_crtc;
@@ -290,7 +290,7 @@ struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
 	vkms_crtc = &vkmsdev->output.crtcs[vkmsdev->output.num_crtcs++];
 
 	ret = drmm_crtc_init_with_planes(dev, &vkms_crtc->base, primary, cursor,
-					 &vkms_crtc_funcs, NULL);
+					 &vkms_crtc_funcs, name);
 	if (ret) {
 		DRM_ERROR("Failed to init CRTC\n");
 		goto out_error;
drivers/gpu/drm/vkms/vkms_drv.c +2 -1
index 1b5b7143792f..314a04659c5f 100644
@@ -210,7 +210,7 @@ static int vkms_platform_probe(struct platform_device *pdev)
 	ret = drm_dev_register(&vkms_device->drm, 0);
 	if (ret) {
 		DRM_ERROR("Unable to register device with id %d\n", pdev->id);
-		return ret;
+		goto out_release_group;
 	}
 
 	drm_fbdev_generic_setup(&vkms_device->drm, 0);
@@ -256,6 +256,7 @@ struct vkms_device *vkms_add_device(struct vkms_configfs *configfs)
 			dev, &vkms_platform_driver.driver))) {
 		pdev = to_platform_device(dev);
 		max_id = max(max_id, pdev->id);
+		put_device(dev);
 	}
 
 	pdev = platform_device_register_data(NULL, DRIVER_NAME, max_id + 1,
drivers/gpu/drm/vkms/vkms_drv.h +1 -1
index 3634eeeb4548..3d592d085f49 100644
@@ -239,7 +239,7 @@ void vkms_remove_device(struct vkms_device *vkms_device);
 /* CRTC */
 struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
 				 struct drm_plane *primary,
-				 struct drm_plane *cursor);
+				 struct drm_plane *cursor, const char *name);
 
 int vkms_output_init(struct vkms_device *vkmsdev);
 int vkms_output_init_default(struct vkms_device *vkmsdev);
drivers/gpu/drm/vkms/vkms_output.c +173 -28

262 lines not on this page · raw message

Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#13 lore raw

Re: [PATCH v2 5/6] drm/vkms: Support enabling ConfigFS devices

Hi,

See below some minor comments:

Quoted 266 lines · Jim Shargo

VKMS now supports creating and using virtual devices!

In addition to the enabling logic, this commit also prevents users from adding new objects once a card is registered.

---
 drivers/gpu/drm/vkms/vkms_configfs.c |  37 +++--
 drivers/gpu/drm/vkms/vkms_crtc.c     |   4 +-
 drivers/gpu/drm/vkms/vkms_drv.c      |   3 +-
 drivers/gpu/drm/vkms/vkms_drv.h      |   2 +-
 drivers/gpu/drm/vkms/vkms_output.c   | 201 +++++++++++++++++++++++----
 5 files changed, 202 insertions(+), 45 deletions(-)
drivers/gpu/drm/vkms/vkms_configfs.c +24 -13
index 544024735d19..f5eed6d23dcd 100644
@@ -504,29 +504,40 @@ static ssize_t device_enabled_store(struct config_item *item, const char *buf,
 {
 	struct vkms_configfs *configfs = item_to_configfs(item);
 	struct vkms_device *device;
-	int value, ret;
+	int enabled, ret;
 
-	ret = kstrtoint(buf, 0, &value);
+	ret = kstrtoint(buf, 0, &enabled);
 	if (ret)
 		return ret;
 
-	if (value != 1)
-		return -EINVAL;
-
-	mutex_lock(&configfs->lock);
-
-	if (configfs->vkms_device) {
+	if (enabled == 0) {
+		mutex_lock(&configfs->lock);
+		if (configfs->vkms_device) {
+			vkms_remove_device(configfs->vkms_device);
+			configfs->vkms_device = NULL;
+		}
 		mutex_unlock(&configfs->lock);
+
 		return len;
 	}
 
-	device = vkms_add_device(configfs);
-	mutex_unlock(&configfs->lock);
+	if (enabled == 1) {
+		mutex_lock(&configfs->lock);
+		if (!configfs->vkms_device) {
+			device = vkms_add_device(configfs);
+			if (IS_ERR(device)) {
+				mutex_unlock(&configfs->lock);
+				return -PTR_ERR(device);
+			}
+
+			configfs->vkms_device = device;
+		}
+		mutex_unlock(&configfs->lock);
 
-	if (IS_ERR(device))
-		return -PTR_ERR(device);
+		return len;
+	}
 
-	return len;
+	return -EINVAL;
 }
 
 CONFIGFS_ATTR(device_, enabled);
drivers/gpu/drm/vkms/vkms_crtc.c +2 -2
index d91e49c53adc..5ebb5264f6ef 100644
@@ -278,7 +278,7 @@ static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = {
 
 struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
 				 struct drm_plane *primary,
-				 struct drm_plane *cursor)
+				 struct drm_plane *cursor, const char *name)
 {
 	struct drm_device *dev = &vkmsdev->drm;
 	struct vkms_crtc *vkms_crtc;
@@ -290,7 +290,7 @@ struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
 	vkms_crtc = &vkmsdev->output.crtcs[vkmsdev->output.num_crtcs++];
 
 	ret = drmm_crtc_init_with_planes(dev, &vkms_crtc->base, primary, cursor,
-					 &vkms_crtc_funcs, NULL);
+					 &vkms_crtc_funcs, name);
 	if (ret) {
 		DRM_ERROR("Failed to init CRTC\n");
 		goto out_error;
drivers/gpu/drm/vkms/vkms_drv.c +2 -1
index 1b5b7143792f..314a04659c5f 100644
@@ -210,7 +210,7 @@ static int vkms_platform_probe(struct platform_device *pdev)
 	ret = drm_dev_register(&vkms_device->drm, 0);
 	if (ret) {
 		DRM_ERROR("Unable to register device with id %d\n", pdev->id);
-		return ret;
+		goto out_release_group;
 	}
 
 	drm_fbdev_generic_setup(&vkms_device->drm, 0);
@@ -256,6 +256,7 @@ struct vkms_device *vkms_add_device(struct vkms_configfs *configfs)
 			dev, &vkms_platform_driver.driver))) {
 		pdev = to_platform_device(dev);
 		max_id = max(max_id, pdev->id);
+		put_device(dev);
 	}
 
 	pdev = platform_device_register_data(NULL, DRIVER_NAME, max_id + 1,
drivers/gpu/drm/vkms/vkms_drv.h +1 -1
index 3634eeeb4548..3d592d085f49 100644
@@ -239,7 +239,7 @@ void vkms_remove_device(struct vkms_device *vkms_device);
 /* CRTC */
 struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
 				 struct drm_plane *primary,
-				 struct drm_plane *cursor);
+				 struct drm_plane *cursor, const char *name);
 
 int vkms_output_init(struct vkms_device *vkmsdev);
 int vkms_output_init_default(struct vkms_device *vkmsdev);
drivers/gpu/drm/vkms/vkms_output.c +50 -22
index c9e6c653de19..806ff01954ad 100644
@@ -2,8 +2,10 @@
 
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_connector.h>
+#include <drm/drm_crtc.h>
 #include <drm/drm_edid.h>
 #include <drm/drm_encoder.h>
+#include <drm/drm_plane.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_simple_kms_helper.h>
 
@@ -82,7 +84,6 @@ static struct drm_encoder *vkms_encoder_init(struct vkms_device *vkms_device)
 
 int vkms_output_init_default(struct vkms_device *vkmsdev)
 {
-	struct vkms_output *output = &vkmsdev->output;
 	struct drm_device *dev = &vkmsdev->drm;
 	struct drm_connector *connector;
 	struct drm_encoder *encoder;
@@ -101,8 +102,7 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)
 			struct vkms_plane *overlay = vkms_plane_init(
 				vkmsdev, DRM_PLANE_TYPE_OVERLAY);
 			if (IS_ERR(overlay)) {
-				ret = PTR_ERR(overlay);
-				goto err_planes;
+				return PTR_ERR(overlay);
 			}
 		}
 	}
@@ -110,17 +110,16 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)
 	if (vkmsdev->config.cursor) {
 		cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR);
 		if (IS_ERR(cursor)) {
-			ret = PTR_ERR(cursor);
-			goto err_planes;
+			return PTR_ERR(cursor);
 		}
 	}
 
 	vkms_crtc = vkms_crtc_init(vkmsdev, &primary->base,
-				   cursor ? &cursor->base : NULL);
+				   cursor ? &cursor->base : NULL,
+				   "crtc-default");
 	if (IS_ERR(vkms_crtc)) {
 		DRM_ERROR("Failed to init crtc\n");
-		ret = PTR_ERR(vkms_crtc);
-		goto err_planes;
+		return PTR_ERR(vkms_crtc);
 	}
 
 	for (int i = 0; i < vkmsdev->output.num_planes; i++) {
@@ -131,22 +130,20 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)
 	connector = vkms_connector_init(vkmsdev);
 	if (IS_ERR(connector)) {
 		DRM_ERROR("Failed to init connector\n");
-		ret = PTR_ERR(connector);
-		goto err_connector;
+		return PTR_ERR(connector);
 	}
 
 	encoder = vkms_encoder_init(vkmsdev);
 	if (IS_ERR(encoder)) {
 		DRM_ERROR("Failed to init encoder\n");
-		ret = PTR_ERR(encoder);
-		goto err_encoder;
+		return PTR_ERR(encoder);
 	}
 	encoder->possible_crtcs |= drm_crtc_mask(&vkms_crtc->base);
 
 	ret = drm_connector_attach_encoder(connector, encoder);
 	if (ret) {
 		DRM_ERROR("Failed to attach connector to encoder\n");
-		goto err_attach;
+		return ret;
 	}
 
 	if (vkmsdev->config.writeback) {
@@ -158,27 +155,175 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)
 	drm_mode_config_reset(dev);
 
 	return 0;
+}
 
-err_attach:
-	drm_encoder_cleanup(encoder);
+static bool is_object_linked(struct vkms_config_links *links, unsigned long idx)
+{
+	return links->linked_object_bitmap & (1 << idx);
+}
 
-err_encoder:
-	drm_connector_cleanup(connector);
+int vkms_output_init(struct vkms_device *vkmsdev)
+{
+	struct drm_device *dev = &vkmsdev->drm;
+	struct vkms_configfs *configfs = vkmsdev->configfs;
+	struct vkms_output *output = &vkmsdev->output;
+	struct plane_map {
+		struct vkms_config_plane *config_plane;
+		struct vkms_plane *plane;
+	} plane_map[VKMS_MAX_PLANES] = { 0 };
+	struct encoder_map {
+		struct vkms_config_encoder *config_encoder;
+		struct drm_encoder *encoder;
+	} encoder_map[VKMS_MAX_OUTPUT_OBJECTS] = { 0 };
+	struct config_item *item;
+	int map_idx = 0;
+
+	list_for_each_entry(item, &configfs->planes_group.cg_children,
+			    ci_entry) {
+		struct vkms_config_plane *config_plane =
+			item_to_config_plane(item);
+		struct vkms_plane *plane =
+			vkms_plane_init(vkmsdev, config_plane->type);
+
+		if (IS_ERR(plane)) {
+			DRM_ERROR("Unable to init plane from config: %s",
+				  item->ci_name);
+			return PTR_ERR(plane);
+		}
 
-err_connector:
-	drm_crtc_cleanup(&vkms_crtc->base);
+		plane_map[map_idx].config_plane = config_plane;
+		plane_map[map_idx].plane = plane;
+		map_idx += 1;
+	}
 
-err_planes:
-	for (int i = 0; i < output->num_planes; i++) {
-		drm_plane_cleanup(&output->planes[i].base);
+	map_idx = 0;
+	list_for_each_entry(item, &configfs->encoders_group.cg_children,
+			    ci_entry) {

drivers/gpu/drm/vkms/vkms_output.c int vkms_output_init_default(struct vkms_device *vkmsdev) · line 211

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_output.c +10 -0
+		struct vkms_config_encoder *config_encoder =
+			item_to_config_encoder(item);
+		struct drm_encoder *encoder = vkms_encoder_init(vkmsdev);
+
+		if (IS_ERR(encoder)) {
+			DRM_ERROR("Failed to init config encoder: %s",
+				  item->ci_name);
+			return PTR_ERR(encoder);
+		}
+		encoder_map[map_idx].config_encoder = config_encoder;

A two connector configuration without an encoder would have the potential of blowing up if we don't create a second_encoder.

Quoted 19 lines
drivers/gpu/drm/vkms/vkms_output.c +12 -3
+		encoder_map[map_idx].encoder = encoder;
+		map_idx += 1;
 	}
 
-	memset(output, 0, sizeof(*output));
+	list_for_each_entry(item, &configfs->connectors_group.cg_children,
+			    ci_entry) {
+		struct vkms_config_connector *config_connector =
+			item_to_config_connector(item);
+		struct drm_connector *connector = vkms_connector_init(vkmsdev);
 
-	return ret;
-}
+		if (IS_ERR(connector)) {
+			DRM_ERROR("Failed to init connector from config: %s",
+				  item->ci_name);
+			return PTR_ERR(connector);
+		}
 

drivers/gpu/drm/vkms/vkms_output.c int vkms_output_init_default(struct vkms_device *vkmsdev) · line 234

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_output.c +7 -3
-int vkms_output_init(struct vkms_device *vkmsdev)
-{
-	return -ENOTSUPP;
+		for (int j = 0; j < output->num_connectors; j++) {
+			struct encoder_map *encoder = &encoder_map[j];
+
+			if (is_object_linked(
+				    &config_connector->possible_encoders,
+				    encoder->config_encoder
+					    ->encoder_config_idx)) {

Here encoder->config_encoder for two connectors but a single encoder will give back a empty encoder.

Quoted 80 lines
drivers/gpu/drm/vkms/vkms_output.c +80 -0
+				drm_connector_attach_encoder(connector,
+							     encoder->encoder);
+			}
+		}
+	}
+
+	list_for_each_entry(item, &configfs->crtcs_group.cg_children,
+			    ci_entry) {
+		struct vkms_config_crtc *config_crtc =
+			item_to_config_crtc(item);
+		struct vkms_crtc *vkms_crtc;
+		struct drm_plane *primary = NULL, *cursor = NULL;
+
+		for (int j = 0; j < output->num_planes; j++) {
+			struct plane_map *plane_entry = &plane_map[j];
+			struct drm_plane *plane = &plane_entry->plane->base;
+
+			if (!is_object_linked(
+				    &plane_entry->config_plane->possible_crtcs,
+				    config_crtc->crtc_config_idx)) {
+				continue;
+			}
+
+			if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
+				if (primary) {
+					DRM_WARN(
+						"Too many primary planes found for crtc %s.",
+						item->ci_name);
+					return EINVAL;
+				}
+				primary = plane;
+			} else if (plane->type == DRM_PLANE_TYPE_CURSOR) {
+				if (cursor) {
+					DRM_WARN(
+						"Too many cursor planes found for crtc %s.",
+						item->ci_name);
+					return EINVAL;
+				}
+				cursor = plane;
+			}
+		}
+
+		if (!primary) {
+			DRM_WARN("No primary plane configured for crtc %s",
+				 item->ci_name);
+			return EINVAL;
+		}
+
+		vkms_crtc =
+			vkms_crtc_init(vkmsdev, primary, cursor, item->ci_name);
+		if (IS_ERR(vkms_crtc)) {
+			DRM_WARN("Unable to init crtc from config: %s",
+				 item->ci_name);
+			return PTR_ERR(vkms_crtc);
+		}
+
+		for (int j = 0; j < output->num_planes; j++) {
+			struct plane_map *plane_entry = &plane_map[j];
+
+			if (!plane_entry->plane)
+				break;
+
+			if (is_object_linked(
+				    &plane_entry->config_plane->possible_crtcs,
+				    config_crtc->crtc_config_idx)) {
+				plane_entry->plane->base.possible_crtcs |=
+					drm_crtc_mask(&vkms_crtc->base);
+			}
+		}
+
+		for (int j = 0; j < output->num_encoders; j++) {
+			struct encoder_map *encoder_entry = &encoder_map[j];
+
+			if (is_object_linked(&encoder_entry->config_encoder
+						      ->possible_crtcs,
+					     config_crtc->crtc_config_idx)) {
+				encoder_entry->encoder->possible_crtcs |=
+					drm_crtc_mask(&vkms_crtc->base);
+			}
+		}

drivers/gpu/drm/vkms/vkms_output.c int vkms_output_init_default(struct vkms_device *vkmsdev) · line 324

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_output.c +10 -0
+
+		if (vkmsdev->config.writeback) {
+			int ret = vkms_enable_writeback_connector(vkmsdev,
+								  vkms_crtc);
+			if (ret)
+				DRM_WARN(
+					"Failed to init writeback connector for config crtc: %s. Error code %d",
+					item->ci_name, ret);
+		}
+	}

I think we might be needing here a test for missing symlinks - invalid configurations, like unused crtcs, encoders, connectors. I suppose anything that's not matched with is_object_linked(), such we avoid invalid configuration found by drm_mode_config_validate() and inform users about missing them.

An example here would be to create a second encoder, connector, crtc and not symlink them to their possible_encoders,possible_crtcs mask. An i-g-t test for this very thing would be needed to stress different kind of combinations.

Quoted 8 lines
drivers/gpu/drm/vkms/vkms_output.c +4 -0
+
+	drm_mode_config_reset(dev);
+
+	return 0;
 }
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#14 lore raw

Re: [PATCH v2 5/6] drm/vkms: Support enabling ConfigFS devices

Quoted 275 lines · Marius Vlad

Hi,

See below some minor comments:

Quoted 270 lines · Jim Shargo

VKMS now supports creating and using virtual devices!

In addition to the enabling logic, this commit also prevents users from adding new objects once a card is registered.

---
  drivers/gpu/drm/vkms/vkms_configfs.c |  37 +++--
  drivers/gpu/drm/vkms/vkms_crtc.c     |   4 +-
  drivers/gpu/drm/vkms/vkms_drv.c      |   3 +-
  drivers/gpu/drm/vkms/vkms_drv.h      |   2 +-
  drivers/gpu/drm/vkms/vkms_output.c   | 201 +++++++++++++++++++++++----
  5 files changed, 202 insertions(+), 45 deletions(-)
drivers/gpu/drm/vkms/vkms_configfs.c +24 -13
index 544024735d19..f5eed6d23dcd 100644
@@ -504,29 +504,40 @@ static ssize_t device_enabled_store(struct config_item *item, const char *buf,
  {
  	struct vkms_configfs *configfs = item_to_configfs(item);
  	struct vkms_device *device;
-	int value, ret;
+	int enabled, ret;
 
-	ret = kstrtoint(buf, 0, &value);
+	ret = kstrtoint(buf, 0, &enabled);
  	if (ret)
  		return ret;
 
-	if (value != 1)
-		return -EINVAL;
-
-	mutex_lock(&configfs->lock);
-
-	if (configfs->vkms_device) {
+	if (enabled == 0) {
+		mutex_lock(&configfs->lock);
+		if (configfs->vkms_device) {
+			vkms_remove_device(configfs->vkms_device);
+			configfs->vkms_device = NULL;
+		}
  		mutex_unlock(&configfs->lock);
+
  		return len;
  	}
 
-	device = vkms_add_device(configfs);
-	mutex_unlock(&configfs->lock);
+	if (enabled == 1) {
+		mutex_lock(&configfs->lock);
+		if (!configfs->vkms_device) {
+			device = vkms_add_device(configfs);
+			if (IS_ERR(device)) {
+				mutex_unlock(&configfs->lock);
+				return -PTR_ERR(device);
+			}
+
+			configfs->vkms_device = device;
+		}
+		mutex_unlock(&configfs->lock);
 
-	if (IS_ERR(device))
-		return -PTR_ERR(device);
+		return len;
+	}
 
-	return len;
+	return -EINVAL;
  }
 
  CONFIGFS_ATTR(device_, enabled);
drivers/gpu/drm/vkms/vkms_crtc.c +2 -2
index d91e49c53adc..5ebb5264f6ef 100644
@@ -278,7 +278,7 @@ static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = {
 
  struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
  				 struct drm_plane *primary,
-				 struct drm_plane *cursor)
+				 struct drm_plane *cursor, const char *name)
  {
  	struct drm_device *dev = &vkmsdev->drm;
  	struct vkms_crtc *vkms_crtc;
@@ -290,7 +290,7 @@ struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
  	vkms_crtc = &vkmsdev->output.crtcs[vkmsdev->output.num_crtcs++];
 
  	ret = drmm_crtc_init_with_planes(dev, &vkms_crtc->base, primary, cursor,
-					 &vkms_crtc_funcs, NULL);
+					 &vkms_crtc_funcs, name);
  	if (ret) {
  		DRM_ERROR("Failed to init CRTC\n");
  		goto out_error;
drivers/gpu/drm/vkms/vkms_drv.c +2 -1
index 1b5b7143792f..314a04659c5f 100644
@@ -210,7 +210,7 @@ static int vkms_platform_probe(struct platform_device *pdev)
  	ret = drm_dev_register(&vkms_device->drm, 0);
  	if (ret) {
  		DRM_ERROR("Unable to register device with id %d\n", pdev->id);
-		return ret;
+		goto out_release_group;
  	}
 
  	drm_fbdev_generic_setup(&vkms_device->drm, 0);
@@ -256,6 +256,7 @@ struct vkms_device *vkms_add_device(struct vkms_configfs *configfs)
  			dev, &vkms_platform_driver.driver))) {
  		pdev = to_platform_device(dev);
  		max_id = max(max_id, pdev->id);
+		put_device(dev);
  	}
 
  	pdev = platform_device_register_data(NULL, DRIVER_NAME, max_id + 1,
drivers/gpu/drm/vkms/vkms_drv.h +1 -1
index 3634eeeb4548..3d592d085f49 100644
@@ -239,7 +239,7 @@ void vkms_remove_device(struct vkms_device *vkms_device);
  /* CRTC */
  struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
  				 struct drm_plane *primary,
-				 struct drm_plane *cursor);
+				 struct drm_plane *cursor, const char *name);
 
  int vkms_output_init(struct vkms_device *vkmsdev);
  int vkms_output_init_default(struct vkms_device *vkmsdev);
drivers/gpu/drm/vkms/vkms_output.c +54 -22
index c9e6c653de19..806ff01954ad 100644
@@ -2,8 +2,10 @@
 
  #include <drm/drm_atomic_helper.h>
  #include <drm/drm_connector.h>
+#include <drm/drm_crtc.h>
  #include <drm/drm_edid.h>
  #include <drm/drm_encoder.h>
+#include <drm/drm_plane.h>
  #include <drm/drm_probe_helper.h>
  #include <drm/drm_simple_kms_helper.h>
 
@@ -82,7 +84,6 @@ static struct drm_encoder *vkms_encoder_init(struct vkms_device *vkms_device)
 
  int vkms_output_init_default(struct vkms_device *vkmsdev)
  {
-	struct vkms_output *output = &vkmsdev->output;
  	struct drm_device *dev = &vkmsdev->drm;
  	struct drm_connector *connector;
  	struct drm_encoder *encoder;
@@ -101,8 +102,7 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)
  			struct vkms_plane *overlay = vkms_plane_init(
  				vkmsdev, DRM_PLANE_TYPE_OVERLAY);
  			if (IS_ERR(overlay)) {
-				ret = PTR_ERR(overlay);
-				goto err_planes;
+				return PTR_ERR(overlay);
  			}
  		}
  	}
@@ -110,17 +110,16 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)
  	if (vkmsdev->config.cursor) {
  		cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR);
  		if (IS_ERR(cursor)) {
-			ret = PTR_ERR(cursor);
-			goto err_planes;
+			return PTR_ERR(cursor);
  		}
  	}
 
  	vkms_crtc = vkms_crtc_init(vkmsdev, &primary->base,
-				   cursor ? &cursor->base : NULL);
+				   cursor ? &cursor->base : NULL,
+				   "crtc-default");
  	if (IS_ERR(vkms_crtc)) {
  		DRM_ERROR("Failed to init crtc\n");
-		ret = PTR_ERR(vkms_crtc);
-		goto err_planes;
+		return PTR_ERR(vkms_crtc);
  	}
 
  	for (int i = 0; i < vkmsdev->output.num_planes; i++) {
@@ -131,22 +130,20 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)
  	connector = vkms_connector_init(vkmsdev);
  	if (IS_ERR(connector)) {
  		DRM_ERROR("Failed to init connector\n");
-		ret = PTR_ERR(connector);
-		goto err_connector;
+		return PTR_ERR(connector);
  	}
 
  	encoder = vkms_encoder_init(vkmsdev);
  	if (IS_ERR(encoder)) {
  		DRM_ERROR("Failed to init encoder\n");
-		ret = PTR_ERR(encoder);
-		goto err_encoder;
+		return PTR_ERR(encoder);
  	}
  	encoder->possible_crtcs |= drm_crtc_mask(&vkms_crtc->base);
 
  	ret = drm_connector_attach_encoder(connector, encoder);
  	if (ret) {
  		DRM_ERROR("Failed to attach connector to encoder\n");
-		goto err_attach;
+		return ret;
  	}
 
  	if (vkmsdev->config.writeback) {
@@ -158,27 +155,175 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)
  	drm_mode_config_reset(dev);
 
  	return 0;
+}
 
-err_attach:
-	drm_encoder_cleanup(encoder);
+static bool is_object_linked(struct vkms_config_links *links, unsigned long idx)
+{
+	return links->linked_object_bitmap & (1 << idx);
+}
 
-err_encoder:
-	drm_connector_cleanup(connector);
+int vkms_output_init(struct vkms_device *vkmsdev)
+{
+	struct drm_device *dev = &vkmsdev->drm;
+	struct vkms_configfs *configfs = vkmsdev->configfs;
+	struct vkms_output *output = &vkmsdev->output;
+	struct plane_map {
+		struct vkms_config_plane *config_plane;
+		struct vkms_plane *plane;
+	} plane_map[VKMS_MAX_PLANES] = { 0 };
+	struct encoder_map {
+		struct vkms_config_encoder *config_encoder;
+		struct drm_encoder *encoder;
+	} encoder_map[VKMS_MAX_OUTPUT_OBJECTS] = { 0 };
+	struct config_item *item;
+	int map_idx = 0;
+
+	list_for_each_entry(item, &configfs->planes_group.cg_children,
+			    ci_entry) {
+		struct vkms_config_plane *config_plane =
+			item_to_config_plane(item);
+		struct vkms_plane *plane =
+			vkms_plane_init(vkmsdev, config_plane->type);
+
+		if (IS_ERR(plane)) {
+			DRM_ERROR("Unable to init plane from config: %s",
+				  item->ci_name);
+			return PTR_ERR(plane);
+		}
 
-err_connector:
-	drm_crtc_cleanup(&vkms_crtc->base);
+		plane_map[map_idx].config_plane = config_plane;
+		plane_map[map_idx].plane = plane;
+		map_idx += 1;
+	}
 
-err_planes:
-	for (int i = 0; i < output->num_planes; i++) {
-		drm_plane_cleanup(&output->planes[i].base);
+	map_idx = 0;
+	list_for_each_entry(item, &configfs->encoders_group.cg_children,
+			    ci_entry) {
+		struct vkms_config_encoder *config_encoder =
+			item_to_config_encoder(item);
+		struct drm_encoder *encoder = vkms_encoder_init(vkmsdev);
+
Quoted 8 lines

drivers/gpu/drm/vkms/vkms_output.c int vkms_output_init_default(struct vkms_device *vkmsdev) · line 211

Quoted 6 lines
drivers/gpu/drm/vkms/vkms_output.c +6 -0
+		if (IS_ERR(encoder)) {
+			DRM_ERROR("Failed to init config encoder: %s",
+				  item->ci_name);
+			return PTR_ERR(encoder);
+		}
+		encoder_map[map_idx].config_encoder = config_encoder;

A two connector configuration without an encoder would have the potential of blowing up if we don't create a second_encoder.

What a catch!!! I tested this and sure enough BOOM!

Switched to limiting based on output->num_encoders as it should be.

Quoted 127 lines
Quoted 19 lines
drivers/gpu/drm/vkms/vkms_output.c +12 -3
+		encoder_map[map_idx].encoder = encoder;
+		map_idx += 1;
  	}
 
-	memset(output, 0, sizeof(*output));
+	list_for_each_entry(item, &configfs->connectors_group.cg_children,
+			    ci_entry) {
+		struct vkms_config_connector *config_connector =
+			item_to_config_connector(item);
+		struct drm_connector *connector = vkms_connector_init(vkmsdev);
 
-	return ret;
-}
+		if (IS_ERR(connector)) {
+			DRM_ERROR("Failed to init connector from config: %s",
+				  item->ci_name);
+			return PTR_ERR(connector);
+		}
 

drivers/gpu/drm/vkms/vkms_output.c int vkms_output_init_default(struct vkms_device *vkmsdev) · line 234

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_output.c +7 -3
-int vkms_output_init(struct vkms_device *vkmsdev)
-{
-	return -ENOTSUPP;
+		for (int j = 0; j < output->num_connectors; j++) {
+			struct encoder_map *encoder = &encoder_map[j];
+
+			if (is_object_linked(
+				    &config_connector->possible_encoders,
+				    encoder->config_encoder
+					    ->encoder_config_idx)) {

Here encoder->config_encoder for two connectors but a single encoder will give back a empty encoder.

Quoted 80 lines
drivers/gpu/drm/vkms/vkms_output.c +80 -0
+				drm_connector_attach_encoder(connector,
+							     encoder->encoder);
+			}
+		}
+	}
+
+	list_for_each_entry(item, &configfs->crtcs_group.cg_children,
+			    ci_entry) {
+		struct vkms_config_crtc *config_crtc =
+			item_to_config_crtc(item);
+		struct vkms_crtc *vkms_crtc;
+		struct drm_plane *primary = NULL, *cursor = NULL;
+
+		for (int j = 0; j < output->num_planes; j++) {
+			struct plane_map *plane_entry = &plane_map[j];
+			struct drm_plane *plane = &plane_entry->plane->base;
+
+			if (!is_object_linked(
+				    &plane_entry->config_plane->possible_crtcs,
+				    config_crtc->crtc_config_idx)) {
+				continue;
+			}
+
+			if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
+				if (primary) {
+					DRM_WARN(
+						"Too many primary planes found for crtc %s.",
+						item->ci_name);
+					return EINVAL;
+				}
+				primary = plane;
+			} else if (plane->type == DRM_PLANE_TYPE_CURSOR) {
+				if (cursor) {
+					DRM_WARN(
+						"Too many cursor planes found for crtc %s.",
+						item->ci_name);
+					return EINVAL;
+				}
+				cursor = plane;
+			}
+		}
+
+		if (!primary) {
+			DRM_WARN("No primary plane configured for crtc %s",
+				 item->ci_name);
+			return EINVAL;
+		}
+
+		vkms_crtc =
+			vkms_crtc_init(vkmsdev, primary, cursor, item->ci_name);
+		if (IS_ERR(vkms_crtc)) {
+			DRM_WARN("Unable to init crtc from config: %s",
+				 item->ci_name);
+			return PTR_ERR(vkms_crtc);
+		}
+
+		for (int j = 0; j < output->num_planes; j++) {
+			struct plane_map *plane_entry = &plane_map[j];
+
+			if (!plane_entry->plane)
+				break;
+
+			if (is_object_linked(
+				    &plane_entry->config_plane->possible_crtcs,
+				    config_crtc->crtc_config_idx)) {
+				plane_entry->plane->base.possible_crtcs |=
+					drm_crtc_mask(&vkms_crtc->base);
+			}
+		}
+
+		for (int j = 0; j < output->num_encoders; j++) {
+			struct encoder_map *encoder_entry = &encoder_map[j];
+
+			if (is_object_linked(&encoder_entry->config_encoder
+						      ->possible_crtcs,
+					     config_crtc->crtc_config_idx)) {
+				encoder_entry->encoder->possible_crtcs |=
+					drm_crtc_mask(&vkms_crtc->base);
+			}
+		}

drivers/gpu/drm/vkms/vkms_output.c int vkms_output_init_default(struct vkms_device *vkmsdev) · line 324

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_output.c +10 -0
+
+		if (vkmsdev->config.writeback) {
+			int ret = vkms_enable_writeback_connector(vkmsdev,
+								  vkms_crtc);
+			if (ret)
+				DRM_WARN(
+					"Failed to init writeback connector for config crtc: %s. Error code %d",
+					item->ci_name, ret);
+		}
+	}

I think we might be needing here a test for missing symlinks - invalid configurations, like unused crtcs, encoders, connectors. I suppose anything that's not matched with is_object_linked(), such we avoid invalid configuration found by drm_mode_config_validate() and inform users about missing them.

Quoted 4 lines

An example here would be to create a second encoder, connector, crtc and not symlink them to their possible_encoders,possible_crtcs mask. An i-g-t test for this very thing would be needed to stress different kind of combinations.

I wonder about this.  Shouldn't a user be free to create dangling files to simulate some scenario?

I could see a further development to publish a warning in the log, but disallowing it seems overly restrictive.

Either way we could accomplish this pretty easily by adding a flag to each vkms object in the form of bool is_linked and set it when we detect it's linked.  Then at the end iterate through all planes, encoders, connectors, crtcs that can be linked and if they are not just publish a warning saying

kwarn: "crtc/plane/encoder $NAME is created but unlinked"

IGT tests to test that that was done make sense to me.

Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/vkms/vkms_output.c +4 -0
+
+	drm_mode_config_reset(dev);
+
+	return 0;
  }
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#15 lore raw

Re: [PATCH v2 5/6] drm/vkms: Support enabling ConfigFS devices

Hi,

Seem my comments below.

Quoted 404 lines · Brandon Ross Pollack
Quoted 264 lines · Marius Vlad

Hi,

See below some minor comments:

Quoted 259 lines · Jim Shargo

VKMS now supports creating and using virtual devices!

In addition to the enabling logic, this commit also prevents users from adding new objects once a card is registered.

---
  drivers/gpu/drm/vkms/vkms_configfs.c |  37 +++-- drivers/gpu/drm/vkms/vkms_crtc.c     |   4 +- drivers/gpu/drm/vkms/vkms_drv.c      |   3 +- drivers/gpu/drm/vkms/vkms_drv.h      |   2 +- drivers/gpu/drm/vkms/vkms_output.c   | 201 +++++++++++++++++++++++----

  5 files changed, 202 insertions(+), 45 deletions(-)
drivers/gpu/drm/vkms/vkms_configfs.c +24 -13
index 544024735d19..f5eed6d23dcd 100644
@@ -504,29 +504,40 @@ static ssize_t device_enabled_store(struct 
 config_item *item, const char *buf,
   {
       struct vkms_configfs *configfs = item_to_configfs(item);
       struct vkms_device *device;
-    int value, ret;
+    int enabled, ret;
-    ret = kstrtoint(buf, 0, &value);
+    ret = kstrtoint(buf, 0, &enabled);
       if (ret)
           return ret;
-    if (value != 1)
-        return -EINVAL;
-
-    mutex_lock(&configfs->lock);
-
-    if (configfs->vkms_device) {
+    if (enabled == 0) {
+        mutex_lock(&configfs->lock);
+        if (configfs->vkms_device) {
+            vkms_remove_device(configfs->vkms_device);
+            configfs->vkms_device = NULL;
+        }
           mutex_unlock(&configfs->lock);
+
           return len;
       }
-    device = vkms_add_device(configfs);
-    mutex_unlock(&configfs->lock);
+    if (enabled == 1) {
+        mutex_lock(&configfs->lock);
+        if (!configfs->vkms_device) {
+            device = vkms_add_device(configfs);
+            if (IS_ERR(device)) {
+                mutex_unlock(&configfs->lock);
+                return -PTR_ERR(device);
+            }
+
+            configfs->vkms_device = device;
+        }
+        mutex_unlock(&configfs->lock);
-    if (IS_ERR(device))
-        return -PTR_ERR(device);
+        return len;
+    }
-    return len;
+    return -EINVAL;
   }
   CONFIGFS_ATTR(device_, enabled);
drivers/gpu/drm/vkms/vkms_crtc.c +2 -2
index d91e49c53adc..5ebb5264f6ef 100644
@@ -278,7 +278,7 @@ static const struct drm_crtc_helper_funcs 
 vkms_crtc_helper_funcs = {
   struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
                    struct drm_plane *primary,
-                 struct drm_plane *cursor)
+                 struct drm_plane *cursor, const char *name)
   {
       struct drm_device *dev = &vkmsdev->drm;
       struct vkms_crtc *vkms_crtc;
@@ -290,7 +290,7 @@ struct vkms_crtc *vkms_crtc_init(struct 
 vkms_device *vkmsdev,
       vkms_crtc = &vkmsdev->output.crtcs[vkmsdev->output.num_crtcs++];
       ret = drmm_crtc_init_with_planes(dev, &vkms_crtc->base, primary, cursor,
-                     &vkms_crtc_funcs, NULL);
+                     &vkms_crtc_funcs, name);
       if (ret) {
           DRM_ERROR("Failed to init CRTC\n");
           goto out_error;
drivers/gpu/drm/vkms/vkms_drv.c +2 -1
index 1b5b7143792f..314a04659c5f 100644
@@ -210,7 +210,7 @@ static int vkms_platform_probe(struct 
 platform_device *pdev)
       ret = drm_dev_register(&vkms_device->drm, 0);
       if (ret) {
           DRM_ERROR("Unable to register device with id %d\n", pdev->id);
-        return ret;
+        goto out_release_group;
       }
       drm_fbdev_generic_setup(&vkms_device->drm, 0);
@@ -256,6 +256,7 @@ struct vkms_device *vkms_add_device(struct 
 vkms_configfs *configfs)
               dev, &vkms_platform_driver.driver))) {
           pdev = to_platform_device(dev);
           max_id = max(max_id, pdev->id);
+        put_device(dev);
       }

      pdev = platform_device_register_data(NULL, DRIVER_NAME, max_id
+ 1,

drivers/gpu/drm/vkms/vkms_drv.h +1 -1
index 3634eeeb4548..3d592d085f49 100644
@@ -239,7 +239,7 @@ void vkms_remove_device(struct vkms_device 
 *vkms_device);
   /* CRTC */
   struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev,
                    struct drm_plane *primary,
-                 struct drm_plane *cursor);
+                 struct drm_plane *cursor, const char *name);
   int vkms_output_init(struct vkms_device *vkmsdev);
   int vkms_output_init_default(struct vkms_device *vkmsdev);
drivers/gpu/drm/vkms/vkms_output.c +2 -1
index c9e6c653de19..806ff01954ad 100644
@@ -2,8 +2,10 @@
   #include <drm/drm_atomic_helper.h>
   #include <drm/drm_connector.h>
+#include <drm/drm_crtc.h>
   #include <drm/drm_edid.h>
   #include <drm/drm_encoder.h>
+#include <drm/drm_plane.h>
   #include <drm/drm_probe_helper.h>
   #include <drm/drm_simple_kms_helper.h>
@@ -82,7 +84,6 @@ static struct drm_encoder *vkms_encoder_init(struct 
 vkms_device *vkms_device)
   int vkms_output_init_default(struct vkms_device *vkmsdev)
   {
-    struct vkms_output *output = &vkmsdev->output;
       struct drm_device *dev = &vkmsdev->drm;
       struct drm_connector *connector;
       struct drm_encoder *encoder;
@@ -101,8 +102,7 @@ int vkms_output_init_default(struct vkms_device 
 *vkmsdev)

              struct vkms_plane *overlay = vkms_plane_init( vkmsdev, DRM_PLANE_TYPE_OVERLAY); if (IS_ERR(overlay)) {
-                ret = PTR_ERR(overlay);
-                goto err_planes;
+                return PTR_ERR(overlay);
              }
          }
      }

drivers/gpu/drm/vkms/vkms_output.c +51 -19
@@ -110,17 +110,16 @@ int vkms_output_init_default(struct vkms_device 
 *vkmsdev)
       if (vkmsdev->config.cursor) {
           cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR);
           if (IS_ERR(cursor)) {
-            ret = PTR_ERR(cursor);
-            goto err_planes;
+            return PTR_ERR(cursor);
           }
       }
       vkms_crtc = vkms_crtc_init(vkmsdev, &primary->base,
-                   cursor ? &cursor->base : NULL);
+                   cursor ? &cursor->base : NULL,
+                   "crtc-default");
       if (IS_ERR(vkms_crtc)) {
           DRM_ERROR("Failed to init crtc\n");
-        ret = PTR_ERR(vkms_crtc);
-        goto err_planes;
+        return PTR_ERR(vkms_crtc);
       }
       for (int i = 0; i < vkmsdev->output.num_planes; i++) {
@@ -131,22 +130,20 @@ int vkms_output_init_default(struct vkms_device 
 *vkmsdev)
       connector = vkms_connector_init(vkmsdev);
       if (IS_ERR(connector)) {
           DRM_ERROR("Failed to init connector\n");
-        ret = PTR_ERR(connector);
-        goto err_connector;
+        return PTR_ERR(connector);
       }
       encoder = vkms_encoder_init(vkmsdev);
       if (IS_ERR(encoder)) {
           DRM_ERROR("Failed to init encoder\n");
-        ret = PTR_ERR(encoder);
-        goto err_encoder;
+        return PTR_ERR(encoder);
       }
       encoder->possible_crtcs |= drm_crtc_mask(&vkms_crtc->base);
       ret = drm_connector_attach_encoder(connector, encoder);
       if (ret) {
           DRM_ERROR("Failed to attach connector to encoder\n");
-        goto err_attach;
+        return ret;
       }
       if (vkmsdev->config.writeback) {
@@ -158,27 +155,175 @@ int vkms_output_init_default(struct 
 vkms_device *vkmsdev)
       drm_mode_config_reset(dev);
       return 0;
+}
-err_attach:
-    drm_encoder_cleanup(encoder);
+static bool is_object_linked(struct vkms_config_links *links, 
 unsigned long idx)
+{
+    return links->linked_object_bitmap & (1 << idx);
+}
-err_encoder:
-    drm_connector_cleanup(connector);
+int vkms_output_init(struct vkms_device *vkmsdev)
+{
+    struct drm_device *dev = &vkmsdev->drm;
+    struct vkms_configfs *configfs = vkmsdev->configfs;
+    struct vkms_output *output = &vkmsdev->output;
+    struct plane_map {
+        struct vkms_config_plane *config_plane;
+        struct vkms_plane *plane;
+    } plane_map[VKMS_MAX_PLANES] = { 0 };
+    struct encoder_map {
+        struct vkms_config_encoder *config_encoder;
+        struct drm_encoder *encoder;
+    } encoder_map[VKMS_MAX_OUTPUT_OBJECTS] = { 0 };
+    struct config_item *item;
+    int map_idx = 0;
+
+    list_for_each_entry(item, &configfs->planes_group.cg_children,
+                ci_entry) {
+        struct vkms_config_plane *config_plane =
+            item_to_config_plane(item);
+        struct vkms_plane *plane =
+            vkms_plane_init(vkmsdev, config_plane->type);
+
+        if (IS_ERR(plane)) {
+            DRM_ERROR("Unable to init plane from config: %s",
+                  item->ci_name);
+            return PTR_ERR(plane);
+        }
-err_connector:
-    drm_crtc_cleanup(&vkms_crtc->base);
+        plane_map[map_idx].config_plane = config_plane;
+        plane_map[map_idx].plane = plane;
+        map_idx += 1;
+    }
-err_planes:
-    for (int i = 0; i < output->num_planes; i++) {
-        drm_plane_cleanup(&output->planes[i].base);
+    map_idx = 0;
+    list_for_each_entry(item, &configfs->encoders_group.cg_children,
+                ci_entry) {
+        struct vkms_config_encoder *config_encoder =
+            item_to_config_encoder(item);
+        struct drm_encoder *encoder = vkms_encoder_init(vkmsdev);
+
Quoted 8 lines

drivers/gpu/drm/vkms/vkms_output.c int vkms_output_init_default(struct vkms_device *vkmsdev) · line 211

Quoted 6 lines
drivers/gpu/drm/vkms/vkms_output.c +6 -0
+        if (IS_ERR(encoder)) {
+            DRM_ERROR("Failed to init config encoder: %s",
+                  item->ci_name);
+            return PTR_ERR(encoder);
+        }
+        encoder_map[map_idx].config_encoder = config_encoder;

A two connector configuration without an encoder would have the potential of blowing up if we don't create a second_encoder.

What a catch!!! I tested this and sure enough BOOM!

Switched to limiting based on output->num_encoders as it should be.

Quoted 125 lines
Quoted 16 lines
drivers/gpu/drm/vkms/vkms_output.c +12 -3
+        encoder_map[map_idx].encoder = encoder;
+        map_idx += 1;
       }
-    memset(output, 0, sizeof(*output));
+    list_for_each_entry(item, &configfs->connectors_group.cg_children,
+                ci_entry) {
+        struct vkms_config_connector *config_connector =
+            item_to_config_connector(item);
+        struct drm_connector *connector = vkms_connector_init(vkmsdev);
-    return ret;
-}
+        if (IS_ERR(connector)) {
+            DRM_ERROR("Failed to init connector from config: %s",
+                  item->ci_name);
+            return PTR_ERR(connector);
+        }

drivers/gpu/drm/vkms/vkms_output.c int vkms_output_init_default(struct vkms_device *vkmsdev) · line 234

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_output.c +7 -3
-int vkms_output_init(struct vkms_device *vkmsdev)
-{
-    return -ENOTSUPP;
+        for (int j = 0; j < output->num_connectors; j++) {
+            struct encoder_map *encoder = &encoder_map[j];
+
+            if (is_object_linked(
+                    &config_connector->possible_encoders,
+                    encoder->config_encoder
+                        ->encoder_config_idx)) {

Here encoder->config_encoder for two connectors but a single encoder will give back a empty encoder.

Quoted 81 lines
drivers/gpu/drm/vkms/vkms_output.c +81 -0
+                drm_connector_attach_encoder(connector,
+                                 encoder->encoder);
+            }
+        }
+    }
+
+    list_for_each_entry(item, &configfs->crtcs_group.cg_children,
+                ci_entry) {
+        struct vkms_config_crtc *config_crtc =
+            item_to_config_crtc(item);
+        struct vkms_crtc *vkms_crtc;
+        struct drm_plane *primary = NULL, *cursor = NULL;
+
+        for (int j = 0; j < output->num_planes; j++) {
+            struct plane_map *plane_entry = &plane_map[j];
+            struct drm_plane *plane = &plane_entry->plane->base;
+
+            if (!is_object_linked(
+                    &plane_entry->config_plane->possible_crtcs,
+                    config_crtc->crtc_config_idx)) {
+                continue;
+            }
+
+            if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
+                if (primary) {
+                    DRM_WARN(
+                        "Too many primary planes found for crtc %s.",
+                        item->ci_name);
+                    return EINVAL;
+                }
+                primary = plane;
+            } else if (plane->type == DRM_PLANE_TYPE_CURSOR) {
+                if (cursor) {
+                    DRM_WARN(
+                        "Too many cursor planes found for crtc %s.",
+                        item->ci_name);
+                    return EINVAL;
+                }
+                cursor = plane;
+            }
+        }
+
+        if (!primary) {
+            DRM_WARN("No primary plane configured for crtc %s",
+                 item->ci_name);
+            return EINVAL;
+        }
+
+        vkms_crtc =
+            vkms_crtc_init(vkmsdev, primary, cursor, item->ci_name);
+        if (IS_ERR(vkms_crtc)) {
+            DRM_WARN("Unable to init crtc from config: %s",
+                 item->ci_name);
+            return PTR_ERR(vkms_crtc);
+        }
+
+        for (int j = 0; j < output->num_planes; j++) {
+            struct plane_map *plane_entry = &plane_map[j];
+
+            if (!plane_entry->plane)
+                break;
+
+            if (is_object_linked(
+                    &plane_entry->config_plane->possible_crtcs,
+                    config_crtc->crtc_config_idx)) {
+                plane_entry->plane->base.possible_crtcs |=
+                    drm_crtc_mask(&vkms_crtc->base);
+            }
+        }
+
+        for (int j = 0; j < output->num_encoders; j++) {
+            struct encoder_map *encoder_entry = &encoder_map[j];
+
+            if (is_object_linked(&encoder_entry->config_encoder
+                              ->possible_crtcs,
+                         config_crtc->crtc_config_idx)) {
+                encoder_entry->encoder->possible_crtcs |=
+                    drm_crtc_mask(&vkms_crtc->base);
+            }
+        }
+

drivers/gpu/drm/vkms/vkms_output.c int vkms_output_init_default(struct vkms_device *vkmsdev) · line 324

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_output.c +9 -0
+        if (vkmsdev->config.writeback) {
+            int ret = vkms_enable_writeback_connector(vkmsdev,
+                                  vkms_crtc);
+            if (ret)
+                DRM_WARN(
+                    "Failed to init writeback connector for config 
 crtc: %s. Error code %d",
+                    item->ci_name, ret);
+        }
+    }

I think we might be needing here a test for missing symlinks - invalid configurations, like unused crtcs, encoders, connectors. I suppose anything that's not matched with is_object_linked(), such we avoid invalid configuration found by drm_mode_config_validate() and inform users about missing them.

Quoted 6 lines
Quoted 4 lines

An example here would be to create a second encoder, connector, crtc and not symlink them to their possible_encoders,possible_crtcs mask. An i-g-t test for this very thing would be needed to stress different kind of combinations.

I wonder about this.  Shouldn't a user be free to create dangling files to simulate some scenario?

Problem is we end up with invalid pipelines which would be invalided by drm_mode_config_validate(), further more leading to kernel warns/errors. That seems to be case now. If the system is still usable -- while still having these missing bits, and possibly inform the user about an invalid pipeline would be ideal.

Quoted 2 lines

I could see a further development to publish a warning in the log, but disallowing it seems overly restrictive.

Sure, I think ideally this should be the case, if we can do that in the first place, given that we operate on a transaction model, only when enable it we go over all items that were created/added by the user. Dangling or not, my impression is that these invalid bits need to be dropped entirely when submitted back to the DRM helpers.

If the user configures 3 pipelines, two correctly, and one not, still allow those two pipelines to work and inform that it might have an invalid one, rather than invalidating the entire config, I think that's the point.

Quoted 4 lines

Either way we could accomplish this pretty easily by adding a flag to each vkms object in the form of bool is_linked and set it when we detect it's linked.  Then at the end iterate through all planes, encoders, connectors, crtcs that can be linked and if they are not just publish a warning saying

kwarn: "crtc/plane/encoder $NAME is created but unlinked"

Yeah, that would be really good.

Quoted 11 lines

IGT tests to test that that was done make sense to me.

Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/vkms/vkms_output.c +4 -0
+
+    drm_mode_config_reset(dev);
+
+    return 0;
   }
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
author
#16 lore raw

PATCH v2 6/6 drm/vkms: Add a module param to enable/disable the default device

In reply to Jim Shargo

In many testing circumstances, we will want to just create a new device and test against that. If we create a default device, it can be annoying to have to manually select the new device instead of choosing the only one that exists.

The param, enable_default, is defaulted to true to maintain backwards compatibility.

---
 drivers/gpu/drm/vkms/vkms_drv.c | 44 ++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 15 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.c +29 -15
index 314a04659c5f..1cb56c090a65 100644
@@ -42,17 +42,26 @@
 #define DRIVER_MAJOR	1
 #define DRIVER_MINOR	0
 
+static bool enable_default_device = true;
+module_param_named(enable_default_device, enable_default_device, bool, 0444);
+MODULE_PARM_DESC(enable_default_device,
+		 "Enable/Disable creating the default device");
+
 static bool enable_cursor = true;
 module_param_named(enable_cursor, enable_cursor, bool, 0444);
-MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");
+MODULE_PARM_DESC(enable_cursor,
+		 "Enable/Disable cursor support for the default device");
 
 static bool enable_writeback = true;
 module_param_named(enable_writeback, enable_writeback, bool, 0444);
-MODULE_PARM_DESC(enable_writeback, "Enable/Disable writeback connector support");
+MODULE_PARM_DESC(
+	enable_writeback,
+	"Enable/Disable writeback connector support for the default device");
 
 static bool enable_overlay;
 module_param_named(enable_overlay, enable_overlay, bool, 0444);
-MODULE_PARM_DESC(enable_overlay, "Enable/Disable overlay support");
+MODULE_PARM_DESC(enable_overlay,
+		 "Enable/Disable overlay support for the default device");
 
 DEFINE_DRM_GEM_FOPS(vkms_driver_fops);
 
@@ -278,10 +287,7 @@ void vkms_remove_device(struct vkms_device *vkms_device)
 static int __init vkms_init(void)
 {
 	int ret;
-	struct platform_device *pdev;
-	struct vkms_device_setup vkms_device_setup = {
-		.configfs = NULL,
-	};
+	struct platform_device *default_pdev = NULL;
 
 	ret = platform_driver_register(&vkms_platform_driver);
 	if (ret) {
@@ -289,19 +295,27 @@ static int __init vkms_init(void)
 		return ret;
 	}
 
-	pdev = platform_device_register_data(NULL, DRIVER_NAME, 0,
-					     &vkms_device_setup,
-					     sizeof(vkms_device_setup));
-	if (IS_ERR(pdev)) {
-		DRM_ERROR("Unable to register default vkms device\n");
-		platform_driver_unregister(&vkms_platform_driver);
-		return PTR_ERR(pdev);
+	if (enable_default_device) {
+		struct vkms_device_setup vkms_device_setup = {
+			.configfs = NULL,
+		};
+
+		default_pdev = platform_device_register_data(
+			NULL, DRIVER_NAME, 0, &vkms_device_setup,
+			sizeof(vkms_device_setup));
+		if (IS_ERR(default_pdev)) {
+			DRM_ERROR("Unable to register default vkms device\n");
+			platform_driver_unregister(&vkms_platform_driver);
+			return PTR_ERR(default_pdev);
+		}
 	}
 
 	ret = vkms_init_configfs();
 	if (ret) {
 		DRM_ERROR("Unable to initialize configfs\n");
-		platform_device_unregister(pdev);
+		if (default_pdev)
+			platform_device_unregister(default_pdev);
+
 		platform_driver_unregister(&vkms_platform_driver);
 	}
 
Signature · 1 line
2.41.0.162.gfafddb0af9-goog
#17 lore raw

Re: [PATCH v2 6/6] drm/vkms: Add a module param to enable/disable the default device

Hi Jim,

Quoted 18 lines · Jim Shargo

In many testing circumstances, we will want to just create a new device and test against that. If we create a default device, it can be annoying to have to manually select the new device instead of choosing the only one that exists.

The param, enable_default, is defaulted to true to maintain backwards compatibility.

---
  drivers/gpu/drm/vkms/vkms_drv.c | 44 ++++++++++++++++++++++-----------
  1 file changed, 29 insertions(+), 15 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.c +0 -0
index 314a04659c5f..1cb56c090a65 100644

drivers/gpu/drm/vkms/vkms_drv.c line 48

Quoted 7 lines
drivers/gpu/drm/vkms/vkms_drv.c +4 -0
@@ -42,17 +42,26 @@
  #define DRIVER_MAJOR	1
  #define DRIVER_MINOR	0
 
+static bool enable_default_device = true;
+module_param_named(enable_default_device, enable_default_device, bool, 0444);
+MODULE_PARM_DESC(enable_default_device,
+		 "Enable/Disable creating the default device");

Wouldn't be better to just call it "enable_default"?

Also, could you add this parameter to vkms_config debugfs file?

Best Regards,
- Maíra

Quoted 70 lines
drivers/gpu/drm/vkms/vkms_drv.c +25 -15
+
  static bool enable_cursor = true;
  module_param_named(enable_cursor, enable_cursor, bool, 0444);
-MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");
+MODULE_PARM_DESC(enable_cursor,
+		 "Enable/Disable cursor support for the default device");
 
  static bool enable_writeback = true;
  module_param_named(enable_writeback, enable_writeback, bool, 0444);
-MODULE_PARM_DESC(enable_writeback, "Enable/Disable writeback connector support");
+MODULE_PARM_DESC(
+	enable_writeback,
+	"Enable/Disable writeback connector support for the default device");
 
  static bool enable_overlay;
  module_param_named(enable_overlay, enable_overlay, bool, 0444);
-MODULE_PARM_DESC(enable_overlay, "Enable/Disable overlay support");
+MODULE_PARM_DESC(enable_overlay,
+		 "Enable/Disable overlay support for the default device");
 
  DEFINE_DRM_GEM_FOPS(vkms_driver_fops);
 
@@ -278,10 +287,7 @@ void vkms_remove_device(struct vkms_device *vkms_device)
  static int __init vkms_init(void)
  {
  	int ret;
-	struct platform_device *pdev;
-	struct vkms_device_setup vkms_device_setup = {
-		.configfs = NULL,
-	};
+	struct platform_device *default_pdev = NULL;
 
  	ret = platform_driver_register(&vkms_platform_driver);
  	if (ret) {
@@ -289,19 +295,27 @@ static int __init vkms_init(void)
  		return ret;
  	}
 
-	pdev = platform_device_register_data(NULL, DRIVER_NAME, 0,
-					     &vkms_device_setup,
-					     sizeof(vkms_device_setup));
-	if (IS_ERR(pdev)) {
-		DRM_ERROR("Unable to register default vkms device\n");
-		platform_driver_unregister(&vkms_platform_driver);
-		return PTR_ERR(pdev);
+	if (enable_default_device) {
+		struct vkms_device_setup vkms_device_setup = {
+			.configfs = NULL,
+		};
+
+		default_pdev = platform_device_register_data(
+			NULL, DRIVER_NAME, 0, &vkms_device_setup,
+			sizeof(vkms_device_setup));
+		if (IS_ERR(default_pdev)) {
+			DRM_ERROR("Unable to register default vkms device\n");
+			platform_driver_unregister(&vkms_platform_driver);
+			return PTR_ERR(default_pdev);
+		}
  	}
 
  	ret = vkms_init_configfs();
  	if (ret) {
  		DRM_ERROR("Unable to initialize configfs\n");
-		platform_device_unregister(pdev);
+		if (default_pdev)
+			platform_device_unregister(default_pdev);
+
  		platform_driver_unregister(&vkms_platform_driver);
  	}
 
#18 lore raw

Re: [PATCH v2 6/6] drm/vkms: Add a module param to enable/disable the default device

Quoted 16 lines · Maira Canal

Hi Jim,

Quoted 13 lines · Jim Shargo

In many testing circumstances, we will want to just create a new device and test against that. If we create a default device, it can be annoying to have to manually select the new device instead of choosing the only one that exists.

The param, enable_default, is defaulted to true to maintain backwards compatibility.

---
  drivers/gpu/drm/vkms/vkms_drv.c | 44 ++++++++++++++++++++++-----------

  1 file changed, 29 insertions(+), 15 deletions(-)
Quoted 14 lines

drivers/gpu/drm/vkms/vkms_drv.c line 48

Quoted 12 lines
drivers/gpu/drm/vkms/vkms_drv.c +3 -0
index 314a04659c5f..1cb56c090a65 100644
@@ -42,17 +42,26 @@
   #define DRIVER_MAJOR    1
   #define DRIVER_MINOR    0
   +static bool enable_default_device = true;
+module_param_named(enable_default_device, enable_default_device, 
 bool, 0444);
+MODULE_PARM_DESC(enable_default_device,
+         "Enable/Disable creating the default device");

Wouldn't be better to just call it "enable_default"?

At the risk of being annoyingly pedantic, I actually like the original name better because it makes it clear it is an entire device and setup,

including the planes/encoders/connectors/crtcs needed and connecting them as necessary etc.  I just feel "device" here makes it clearer what is the default thing.

Quoted 2 lines

Also, could you add this parameter to vkms_config debugfs file?

But of course! This is the last comment before I send out the new series.

Thank you so much for your time, looking forward to the next round of comments.

Quoted 238 lines

Best Regards,
- Maíra

Quoted 54 lines
drivers/gpu/drm/vkms/vkms_drv.c +8 -3
+
   static bool enable_cursor = true;
   module_param_named(enable_cursor, enable_cursor, bool, 0444);
-MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");
+MODULE_PARM_DESC(enable_cursor,
+         "Enable/Disable cursor support for the default device");
     static bool enable_writeback = true;
   module_param_named(enable_writeback, enable_writeback, bool, 0444);
-MODULE_PARM_DESC(enable_writeback, "Enable/Disable writeback 
 connector support");
+MODULE_PARM_DESC(
+    enable_writeback,
+    "Enable/Disable writeback connector support for the default 
 device");
     static bool enable_overlay;
   module_param_named(enable_overlay, enable_overlay, bool, 0444);
-MODULE_PARM_DESC(enable_overlay, "Enable/Disable overlay support");
+MODULE_PARM_DESC(enable_overlay,
+         "Enable/Disable overlay support for the default device");
     DEFINE_DRM_GEM_FOPS(vkms_driver_fops);
   @@ -278,10 +287,7 @@ void vkms_remove_device(struct vkms_device *vkms_device)

  static int __init vkms_init(void)
  {
      int ret;
-    struct platform_device *pdev;
-    struct vkms_device_setup vkms_device_setup = { -        .configfs = NULL,
-    };
+    struct platform_device *default_pdev = NULL; ret = platform_driver_register(&vkms_platform_driver); if (ret) {

drivers/gpu/drm/vkms/vkms_drv.c +13 -6
@@ -289,19 +295,27 @@ static int __init vkms_init(void)
           return ret;
       }
   -    pdev = platform_device_register_data(NULL, DRIVER_NAME, 0,
-                         &vkms_device_setup,
-                         sizeof(vkms_device_setup));
-    if (IS_ERR(pdev)) {
-        DRM_ERROR("Unable to register default vkms device\n");
-        platform_driver_unregister(&vkms_platform_driver);
-        return PTR_ERR(pdev);
+    if (enable_default_device) {
+        struct vkms_device_setup vkms_device_setup = {
+            .configfs = NULL,
+        };
+
+        default_pdev = platform_device_register_data(
+            NULL, DRIVER_NAME, 0, &vkms_device_setup,
+            sizeof(vkms_device_setup));
+        if (IS_ERR(default_pdev)) {
+            DRM_ERROR("Unable to register default vkms device\n");
+ platform_driver_unregister(&vkms_platform_driver);
+            return PTR_ERR(default_pdev);
+        }

drivers/gpu/drm/vkms/vkms_drv.c static int __init vkms_init(void) · line 319

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_drv.c +3 -1
       }
         ret = vkms_init_configfs();
       if (ret) {
           DRM_ERROR("Unable to initialize configfs\n");
-        platform_device_unregister(pdev);
+        if (default_pdev)
+            platform_device_unregister(default_pdev);
+
           platform_driver_unregister(&vkms_platform_driver);
       }

From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <[email protected]>
X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org
Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested)
    by smtp.lore.kernel.org (Postfix) with ESMTPS id AB561C0015E
    for <[email protected]>; Sun, 25 Jun 2023 18:04:15 +0000 (UTC)
Received: from gabe.freedesktop.org (localhost [127.0.0.1])
    by gabe.freedesktop.org (Postfix) with ESMTP id D153310E18C;
    Sun, 25 Jun 2023 18:04:14 +0000 (UTC)
Received: from mx1.riseup.net (mx1.riseup.net [198.252.153.129])
by gabe.freedesktop.org (Postfix) with ESMTPS id C6BE910E187
for <[email protected]>; Sun, 25 Jun 2023 18:04:12 +0000 (UTC)
Received: from fews01-sea.riseup.net (fews01-sea-pn.riseup.net [10.0.1.109]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested)
by mx1.riseup.net (Postfix) with ESMTPS id 4QpzPl6CHTzDrNy;
Sun, 25 Jun 2023 18:04:11 +0000 (UTC)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=riseup.net; s=squak; t=1687716252; bh=3cOd9Tulf+RLZ2R/lGuVfEdERy8xqZ4HHWjkWZv3FAs=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=lXentHTOo29YwgA/Q5WAgBBEUsl5DTqsmOJd4wsjxBgZocgZ/PG9hmyBm6a2IjvcQ jSPI26UWubdYOe7kngWhcU0/oO570ofVUyrxiNgiJQfcscdp5bpwrskBKK4yXdJc0q 2YM4+n0xeBBSr2pFLMDwbOsLDvaGUK77nSPcbPXQ=
X-Riseup-User-ID: 7EBE90DED2258EE1CA830B796CBA05FD63338D890F31F4C1BCCCB27A6DA77A56
Received: from [127.0.0.1] (localhost [127.0.0.1])
by fews01-sea.riseup.net (Postfix) with ESMTPSA id 4QpzPg4YpbzJntB; Sun, 25 Jun 2023 18:04:07 +0000 (UTC)
Message-ID: <[email protected]>
Date: Sun, 25 Jun 2023 15:04:05 -0300
MIME-Version: 1.0
Subject: Re: [PATCH v2 6/6] drm/vkms: Add a module param to enable/disable the default device
Content-Language: en-US
To: Jim Shargo <[email protected]>, Daniel Vetter <[email protected]>, David Airlie <[email protected]>, Haneen Mohammed <[email protected]>, Jonathan Corbet <[email protected]>,
Maarten Lankhorst <[email protected]>,
Maxime Ripard <[email protected]>, Melissa Wen <[email protected]>, Rodrigo Siqueira <[email protected]>,
Thomas Zimmermann <[email protected]>
References: <[email protected]> <[email protected]>
From: Maira Canal <[email protected]>
In-Reply-To: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-BeenThere: [email protected]
X-Mailman-Version: 2.1.29
Precedence: list
List-Id: Direct Rendering Infrastructure - Development <dri-devel.lists.freedesktop.org>
List-Unsubscribe: <https://lists.freedesktop.org/mailman/options/dri-devel>,
<mailto:[email protected]?subject=unsubscribe>
List-Archive: <https://lists.freedesktop.org/archives/dri-devel>
List-Post: <mailto:[email protected]>
List-Help: <mailto:[email protected]?subject=help>
List-Subscribe: <https://lists.freedesktop.org/mailman/listinfo/dri-devel>,
<mailto:[email protected]?subject=subscribe>
Cc: [email protected], [email protected], [email protected]
Errors-To: [email protected]
Sender: "dri-devel" <[email protected]>

Hi Jim,

Quoted 18 lines · Jim Shargo

In many testing circumstances, we will want to just create a new device and test against that. If we create a default device, it can be annoying to have to manually select the new device instead of choosing the only one that exists.

The param, enable_default, is defaulted to true to maintain backwards compatibility.

---
  drivers/gpu/drm/vkms/vkms_drv.c | 44 ++++++++++++++++++++++-----------

  1 file changed, 29 insertions(+), 15 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.c +0 -0
index 314a04659c5f..1cb56c090a65 100644

drivers/gpu/drm/vkms/vkms_drv.c line 48

Quoted 7 lines
drivers/gpu/drm/vkms/vkms_drv.c +3 -0
@@ -42,17 +42,26 @@
   #define DRIVER_MAJOR    1
   #define DRIVER_MINOR    0
   +static bool enable_default_device = true;
+module_param_named(enable_default_device, enable_default_device, 
 bool, 0444);
+MODULE_PARM_DESC(enable_default_device,
+         "Enable/Disable creating the default device");

Wouldn't be better to just call it "enable_default"?

Also, could you add this parameter to vkms_config debugfs file?

Best Regards,
- Maíra

Quoted 64 lines
drivers/gpu/drm/vkms/vkms_drv.c +8 -3
+
   static bool enable_cursor = true;
   module_param_named(enable_cursor, enable_cursor, bool, 0444);
-MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support");
+MODULE_PARM_DESC(enable_cursor,
+         "Enable/Disable cursor support for the default device");
     static bool enable_writeback = true;
   module_param_named(enable_writeback, enable_writeback, bool, 0444);
-MODULE_PARM_DESC(enable_writeback, "Enable/Disable writeback 
 connector support");
+MODULE_PARM_DESC(
+    enable_writeback,
+    "Enable/Disable writeback connector support for the default 
 device");
     static bool enable_overlay;
   module_param_named(enable_overlay, enable_overlay, bool, 0444);
-MODULE_PARM_DESC(enable_overlay, "Enable/Disable overlay support");
+MODULE_PARM_DESC(enable_overlay,
+         "Enable/Disable overlay support for the default device");
     DEFINE_DRM_GEM_FOPS(vkms_driver_fops);
   @@ -278,10 +287,7 @@ void vkms_remove_device(struct vkms_device *vkms_device)

  static int __init vkms_init(void)
  {
      int ret;
-    struct platform_device *pdev;
-    struct vkms_device_setup vkms_device_setup = { -        .configfs = NULL,
-    };
+    struct platform_device *default_pdev = NULL; ret = platform_driver_register(&vkms_platform_driver); if (ret) {

drivers/gpu/drm/vkms/vkms_drv.c +16 -7
@@ -289,19 +295,27 @@ static int __init vkms_init(void)
           return ret;
       }
   -    pdev = platform_device_register_data(NULL, DRIVER_NAME, 0,
-                         &vkms_device_setup,
-                         sizeof(vkms_device_setup));
-    if (IS_ERR(pdev)) {
-        DRM_ERROR("Unable to register default vkms device\n");
-        platform_driver_unregister(&vkms_platform_driver);
-        return PTR_ERR(pdev);
+    if (enable_default_device) {
+        struct vkms_device_setup vkms_device_setup = {
+            .configfs = NULL,
+        };
+
+        default_pdev = platform_device_register_data(
+            NULL, DRIVER_NAME, 0, &vkms_device_setup,
+            sizeof(vkms_device_setup));
+        if (IS_ERR(default_pdev)) {
+            DRM_ERROR("Unable to register default vkms device\n");
+ platform_driver_unregister(&vkms_platform_driver);
+            return PTR_ERR(default_pdev);
+        }
       }
         ret = vkms_init_configfs();
       if (ret) {
           DRM_ERROR("Unable to initialize configfs\n");
-        platform_device_unregister(pdev);
+        if (default_pdev)
+            platform_device_unregister(default_pdev);
+
           platform_driver_unregister(&vkms_platform_driver);
       }
#19 lore raw

PATCH 1/1 drm/vkms Add hotplug support via configfs to VKMS.

In reply to Jim Shargo

This change adds the ability to read or write a "1" or a "0" to the newly added "connected" attribute of a connector in the vkms entry in configfs.

A write will trigger a call to drm_kms_helper_hotplug_event, causing a hotplug uevent.

With this we can write virtualized multidisplay tests that involve hotplugging displays (eg recompositing windows when a monitor is turned off).

---

This is a first attempt and I am sure I could use some feedback. I have this working locally and I'm continuing to develop the test framework around this prototype, but I'm ready to switch gears back to addressing your feedback!

This is also only my second patch ever to the kernel, so if my patch sending process is a little strange or I'm missing something feedback is appreciated.

I also am basing these off of jshargo's not yet submitted configFS changes so I added an in-reply-to to that series. Not sure if that is alright.

---
 Documentation/gpu/vkms.rst            |  2 +-
 drivers/gpu/drm/vkms/vkms_configfs.c  | 96 ++++++++++++++++++++++-----
 drivers/gpu/drm/vkms/vkms_drv.h       | 11 +++
 drivers/gpu/drm/vkms/vkms_output.c    | 47 ++++++++++++-
 drivers/gpu/drm/vkms/vkms_writeback.c |  2 +-
 5 files changed, 138 insertions(+), 20 deletions(-)
Documentation/gpu/vkms.rst +1 -1
index 2c342ef0fb7b..1eaae9f48693 100644
@@ -144,7 +144,7 @@ Runtime Configuration
 We want to vkms instances without having to reload the module. Such 
 configuration can be added as extensions to vkms's ConfigFS support. Use-cases:
 
-- Hotplug/hotremove connectors on the fly (to be able to test DP MST handling
+- Hotremove connectors on the fly (to be able to test DP MST handling
   of compositors).
 
 - Change output configuration: Plug/unplug screens, change EDID, allow changing
drivers/gpu/drm/vkms/vkms_configfs.c +79 -17

181 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_drv.h +11 -0
index 8f476ef4009b..7b9b189511c2 100644
@@ -3,6 +3,7 @@
 #ifndef _VKMS_DRV_H_
 #define _VKMS_DRV_H_
 
+#include "drm/drm_connector.h"
 #include <linux/configfs.h>
 #include <linux/hrtimer.h>
 
@@ -135,7 +136,9 @@ struct vkms_config_links {
 
 struct vkms_config_connector {
 	struct config_group config_group;
+	struct drm_connector *connector;
 	struct vkms_config_links possible_encoders;
+	bool connected;
 };
 
 struct vkms_config_crtc {
@@ -208,6 +211,10 @@ struct vkms_device {
 #define item_to_configfs(item) \
 	container_of(to_config_group(item), struct vkms_configfs, device_group)
 
+#define connector_item_to_configfs(item)                                     \
+	container_of(to_config_group(item->ci_parent), struct vkms_configfs, \
+		     connectors_group)
+
 #define item_to_config_connector(item)                                    \
 	container_of(to_config_group(item), struct vkms_config_connector, \
 		     config_group)
@@ -267,4 +274,8 @@ int vkms_enable_writeback_connector(struct vkms_device *vkmsdev,
 int vkms_init_configfs(void);
 void vkms_unregister_configfs(void);
 
+/* Connector hotplugging */
+enum drm_connector_status vkms_connector_detect(struct drm_connector *connector,
+						bool force);
+
 #endif /* _VKMS_DRV_H_ */
drivers/gpu/drm/vkms/vkms_output.c +46 -1

79 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_writeback.c +1 -1
index a77d9a6c9b74..47449979c564 100644
@@ -145,7 +145,7 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,
 	spin_lock_irq(&vkms_crtc->composer_lock);
 	crtc_state->active_writeback = active_wb;
 	crtc_state->wb_pending = true;
-	spin_unlock_irq(&output->composer_lock);
+	spin_unlock_irq(&vkms_crtc->composer_lock);
 
 	wb_frame_info->offset = fb->offsets[0];
 	wb_frame_info->pitch = fb->pitches[0];
Signature · 1 line
2.41.0.255.g8b1d071c50-goog
author
#20 lore raw

Re: [PATCH] drm/vkms Add hotplug support via configfs to VKMS.

Yay! Glad to see the configfs stuff being extended!

Overall I don't see anything of major concern. Great stuff!

I'd be curious about how the IGT tests would look for this. Creating before and after registration would be sufficient until removal is added.

Quoted 130 lines · Brandon Pollack

This change adds the ability to read or write a "1" or a "0" to the newly added "connected" attribute of a connector in the vkms entry in configfs.

A write will trigger a call to drm_kms_helper_hotplug_event, causing a hotplug uevent.

With this we can write virtualized multidisplay tests that involve hotplugging displays (eg recompositing windows when a monitor is turned off).

---

This is a first attempt and I am sure I could use some feedback. I have this working locally and I'm continuing to develop the test framework around this prototype, but I'm ready to switch gears back to addressing your feedback!

This is also only my second patch ever to the kernel, so if my patch sending process is a little strange or I'm missing something feedback is appreciated.

I also am basing these off of jshargo's not yet submitted configFS changes so I added an in-reply-to to that series. Not sure if that is alright.

---
 Documentation/gpu/vkms.rst            |  2 +-
 drivers/gpu/drm/vkms/vkms_configfs.c  | 96 ++++++++++++++++++++++-----
 drivers/gpu/drm/vkms/vkms_drv.h       | 11 +++
 drivers/gpu/drm/vkms/vkms_output.c    | 47 ++++++++++++-
 drivers/gpu/drm/vkms/vkms_writeback.c |  2 +-
 5 files changed, 138 insertions(+), 20 deletions(-)
Documentation/gpu/vkms.rst +1 -1
index 2c342ef0fb7b..1eaae9f48693 100644
@@ -144,7 +144,7 @@ Runtime Configuration
 We want to vkms instances without having to reload the module. Such
 configuration can be added as extensions to vkms's ConfigFS support. Use-cases:
 
-- Hotplug/hotremove connectors on the fly (to be able to test DP MST handling
+- Hotremove connectors on the fly (to be able to test DP MST handling
   of compositors).
 
 - Change output configuration: Plug/unplug screens, change EDID, allow changing
drivers/gpu/drm/vkms/vkms_configfs.c +14 -12
index f5eed6d23dcd..84cdb8d02ee7 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 
+#include "drm/drm_probe_helper.h"
 #include <linux/configfs.h>
 #include <linux/mutex.h>
 #include <linux/platform_device.h>
@@ -30,7 +31,7 @@
  *
  *   mkdir /config/vkms/test
  *
- * With your device created you'll find an new directory ready to be
+ * With your device created you'll find an new directory ready to be
  * configured::
  *
  *   /config
@@ -39,6 +40,7 @@
  *       |   `-- enabled
  *       `-- test
  *           |-- connectors
+ *                `-- connected
  *           |-- crtcs
  *           |-- encoders
  *           |-- planes
@@ -48,25 +50,25 @@
  * directories will let you configure a new object of that type. Adding new
  * objects will automatically create a set of default files and folders you can
  * use to configure that object.
- *
+ *
  * For instance, we can set up a two-output device like so::
- *
+ *
  *   DRM_PLANE_TYPE_PRIMARY=1
  *   DRM_PLANE_TYPE_CURSOR=2
  *   DRM_PLANE_TYPE_OVERLAY=0
- *
+ *
  *   mkdir /config/vkms/test/planes/primary
  *   echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/primary/type
- *
+ *
  *   mkdir /config/vkms/test/planes/other_primary
  *   echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/other_primary/type
- *
+ *
  *   mkdir /config/vkms/test/planes/cursor
  *   echo $DRM_PLANE_TYPE_CURSOR > /config/vkms/test/planes/cursor/type
- *
+ *
  *   mkdir /config/vkms/test/planes/overlay
  *   echo $DRM_PLANE_TYPE_OVERLAY > /config/vkms/test/planes/overlay/type
- *
+ *
  *   mkdir /config/vkms/test/crtcs/crtc
  *   mkdir /config/vkms/test/crtcs/crtc_other
  *   mkdir /config/vkms/test/encoders/encoder
@@ -75,25 +77,33 @@
  * You can see that specific attributes, such as ``.../<plane>/type``, can be
  * configured by writing into them. Associating objects together can be done via
  * symlinks::
- *
+ *
  *   ln -s /config/vkms/test/encoders/encoder /config/vkms/test/connectors/connector/possible_encoders
- *
+ *
  *   ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/encoders/encoder/possible_crtcs/
  *   ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/primary/possible_crtcs/
  *   ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/cursor/possible_crtcs/
  *   ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/overlay/possible_crtcs/
- *
+ *
  *   ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/overlay/possible_crtcs/
  *   ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/other_primary/possible_crtcs/
- *
+ *
  * Finally, to enable your configured device, just write 1 to the ``enabled``

drivers/gpu/drm/vkms/vkms_configfs.c line 100

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_configfs.c +6 -1
  * file::
- *
+ *
  *   echo 1 > /config/vkms/test/enabled
  *
+ * By default no display is "connected" so to connect a connector you'll also
+ * have to write 1 to a connectors "connected" attribute::
+ *
+ *   echo 1 > /config/vkms/test/connectors/connector/connected
+ *

[nit] I think it'd be nice to note in the docs that this can be set before enabling

drivers/gpu/drm/vkms/vkms_configfs.c line 101

Quoted 1 line
drivers/gpu/drm/vkms/vkms_configfs.c +1 -0
+ * One an verify that this is worked using the `modetest` utility or the

can

Quoted 37 lines
drivers/gpu/drm/vkms/vkms_configfs.c +27 -1
+ * equivalent for your platform.
+ *
  * When you're done with the virtual device, you can clean up the device like
  * so::
- *
+ *
  *   echo 0 > /config/vkms/test/enabled
  *
  *   rm /config/vkms/test/connectors/connector/possible_encoders/encoder
@@ -236,7 +246,58 @@ static void add_possible_encoders(struct config_group *parent,
 
 /*  Connector item, e.g. /config/vkms/device/connectors/ID */
 
+static ssize_t connector_connected_show(struct config_item *item, char *buf)
+{
+       struct vkms_config_connector *connector =
+               item_to_config_connector(item);
+       struct vkms_configfs *configfs = connector_item_to_configfs(item);
+       bool connected = false;
+
+       mutex_lock(&configfs->lock);
+       connected = connector->connected;
+       mutex_unlock(&configfs->lock);
+
+       return sprintf(buf, "%d\n", connected);
+}
+
+static ssize_t connector_connected_store(struct config_item *item,
+                                        const char *buf, size_t len)
+{
+       struct vkms_config_connector *connector =
+               item_to_config_connector(item);
+       struct vkms_configfs *configfs = connector_item_to_configfs(item);
+       int val, ret;
+
+       ret = kstrtouint(buf, 10, &val);
+       if (ret)

drivers/gpu/drm/vkms/vkms_configfs.c static void add_possible_encoders(struct config_group *parent, · line 282

Quoted 10 lines
drivers/gpu/drm/vkms/vkms_configfs.c +10 -0
+               return ret;
+
+       if (val != 1 && val != 0)
+               return -EINVAL;
+
+       mutex_lock(&configfs->lock);
+       connector->connected = val;
+       if (!connector->connector) {
+               pr_warn("VKMS Device %s is not yet enabled, connector will be enabled on start",
+                       configfs->device_group.cg_item.ci_name);

IMO I don't think that this rises to warning, since many usecases might set it by default. INFO if anything?

This also slightly changes the behavior of the API--configs that would have been connected in the past now aren't. The changes aren't merged yet, so IDK how much of an actual concern that is for now.

Quoted 201 lines
drivers/gpu/drm/vkms/vkms_configfs.c +21 -3
+       }
+       mutex_unlock(&configfs->lock);
+
+       if (connector->connector)
+               drm_kms_helper_hotplug_event(connector->connector->dev);
+
+       return len;
+}
+
+CONFIGFS_ATTR(connector_, connected);
+
+static struct configfs_attribute *connector_attrs[] = {
+       &connector_attr_connected,
+       NULL,
+};
+
 static struct config_item_type connector_type = {
+       .ct_attrs = connector_attrs,
        .ct_owner = THIS_MODULE,
 };
 
@@ -264,7 +325,7 @@ static ssize_t plane_type_show(struct config_item *item, char *buf)
        plane_type = plane->type;
        mutex_unlock(&configfs->lock);
 
-       return sprintf(buf, "%u", plane_type);
+       return sprintf(buf, "%u\n", plane_type);
 }
 
 static ssize_t plane_type_store(struct config_item *item, const char *buf,
@@ -319,6 +380,7 @@ static struct config_group *connectors_group_make(struct config_group *group,
                                    &connector_type);
        add_possible_encoders(&connector->config_group,
                              &connector->possible_encoders.group);
+       connector->connected = false;
 
        return &connector->config_group;
 }
@@ -496,7 +558,7 @@ static ssize_t device_enabled_show(struct config_item *item, char *buf)
        is_enabled = configfs->vkms_device != NULL;
        mutex_unlock(&configfs->lock);
 
-       return sprintf(buf, "%d", is_enabled);
+       return sprintf(buf, "%d\n", is_enabled);
 }
 
 static ssize_t device_enabled_store(struct config_item *item, const char *buf,
@@ -553,7 +615,7 @@ static ssize_t device_id_show(struct config_item *item, char *buf)
        }
        mutex_unlock(&configfs->lock);
 
-       return sprintf(buf, "%d", id);
+       return sprintf(buf, "%d\n", id);
 }
 
 CONFIGFS_ATTR_RO(device_, id);
drivers/gpu/drm/vkms/vkms_drv.h +11 -0
index 8f476ef4009b..7b9b189511c2 100644
@@ -3,6 +3,7 @@
 #ifndef _VKMS_DRV_H_
 #define _VKMS_DRV_H_
 
+#include "drm/drm_connector.h"
 #include <linux/configfs.h>
 #include <linux/hrtimer.h>
 
@@ -135,7 +136,9 @@ struct vkms_config_links {
 
 struct vkms_config_connector {
        struct config_group config_group;
+       struct drm_connector *connector;
        struct vkms_config_links possible_encoders;
+       bool connected;
 };
 
 struct vkms_config_crtc {
@@ -208,6 +211,10 @@ struct vkms_device {
 #define item_to_configfs(item) \
        container_of(to_config_group(item), struct vkms_configfs, device_group)
 
+#define connector_item_to_configfs(item)                                     \
+       container_of(to_config_group(item->ci_parent), struct vkms_configfs, \
+                    connectors_group)
+
 #define item_to_config_connector(item)                                    \
        container_of(to_config_group(item), struct vkms_config_connector, \
                     config_group)
@@ -267,4 +274,8 @@ int vkms_enable_writeback_connector(struct vkms_device *vkmsdev,
 int vkms_init_configfs(void);
 void vkms_unregister_configfs(void);
 
+/* Connector hotplugging */
+enum drm_connector_status vkms_connector_detect(struct drm_connector *connector,
+                                               bool force);
+
 #endif /* _VKMS_DRV_H_ */
drivers/gpu/drm/vkms/vkms_output.c +46 -1
index 806ff01954ad..28a50d2149f5 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0+
 
+#include <drm/drm_print.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_connector.h>
 #include <drm/drm_crtc.h>
@@ -8,10 +9,12 @@
 #include <drm/drm_plane.h>
 #include <drm/drm_probe_helper.h>
 #include <drm/drm_simple_kms_helper.h>
+#include <linux/printk.h>
 
 #include "vkms_drv.h"
 
 static const struct drm_connector_funcs vkms_connector_funcs = {
+       .detect = vkms_connector_detect,
        .fill_modes = drm_helper_probe_single_connector_modes,
        .destroy = drm_connector_cleanup,
        .reset = drm_atomic_helper_connector_reset,
@@ -19,6 +22,48 @@ static const struct drm_connector_funcs vkms_connector_funcs = {
        .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
 };
 
+static const struct vkms_config_connector *
+find_config_for_connector(struct drm_connector *connector)
+{
+       struct vkms_device *vkms = drm_device_to_vkms_device(connector->dev);
+       struct vkms_configfs *configfs = vkms->configfs;
+       struct config_item *item;
+
+       if (!configfs) {
+               pr_info("Default connector has no configfs entry");
+               return NULL;
+       }
+
+       list_for_each_entry(item, &configfs->connectors_group.cg_children,
+                           ci_entry) {
+               struct vkms_config_connector *config_connector =
+                       item_to_config_connector(item);
+               if (config_connector->connector == connector)
+                       return config_connector;
+       }
+
+       pr_warn("Could not find config to match connector %s, but configfs was initialized",
+               connector->name);
+
+       return NULL;
+}
+
+enum drm_connector_status vkms_connector_detect(struct drm_connector *connector,
+                                               bool force)
+{
+       enum drm_connector_status status = connector_status_connected;
+       const struct vkms_config_connector *config_connector =
+               find_config_for_connector(connector);
+
+       if (!config_connector)
+               return connector_status_connected;
+
+       if (!config_connector->connected)
+               status = connector_status_disconnected;
+
+       return status;
+}
+
 static const struct drm_encoder_funcs vkms_encoder_funcs = {
        .destroy = drm_encoder_cleanup,
 };
@@ -218,12 +263,12 @@ int vkms_output_init(struct vkms_device *vkmsdev)
                struct vkms_config_connector *config_connector =
                        item_to_config_connector(item);
                struct drm_connector *connector = vkms_connector_init(vkmsdev);
-
                if (IS_ERR(connector)) {
                        DRM_ERROR("Failed to init connector from config: %s",
                                  item->ci_name);
                        return PTR_ERR(connector);
                }
+               config_connector->connector = connector;
 
                for (int j = 0; j < output->num_connectors; j++) {
                        struct encoder_map *encoder = &encoder_map[j];
drivers/gpu/drm/vkms/vkms_writeback.c +1 -2
index a77d9a6c9b74..47449979c564 100644
@@ -145,7 +145,7 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,
        spin_lock_irq(&vkms_crtc->composer_lock);
        crtc_state->active_writeback = active_wb;
        crtc_state->wb_pending = true;
-       spin_unlock_irq(&output->composer_lock);
+       spin_unlock_irq(&vkms_crtc->composer_lock);
 
        wb_frame_info->offset = fb->offsets[0];
        wb_frame_info->pitch = fb->pitches[0];
--

2.41.0.255.g8b1d071c50-goog

#21 lore raw

PATCH v2 1/1 drm/vkms Add hotplug support via configfs to VKMS.

In reply to Jim Shargo

This change adds the ability to read or write a "1" or a "0" to the newly added "connected" attribute of a connector in the vkms entry in configfs.

A write will trigger a call to drm_kms_helper_hotplug_event, causing a hotplug uevent.

With this we can write virtualized multidisplay tests that involve hotplugging displays (eg recompositing windows when a monitor is turned off).

---

This is a first attempt and I am sure I could use some feedback. I have this working locally and I'm continuing to develop the test framework around this prototype, but I'm ready to switch gears back to addressing your feedback!

This is also only my second patch ever to the kernel, so if my patch sending process is a little strange or I'm missing something feedback is appreciated.

I also am basing these off of jshargo's not yet submitted configFS changes so I added an in-reply-to to that series. Not sure if that is alright.

---
 Documentation/gpu/vkms.rst            |  2 +-
 drivers/gpu/drm/vkms/vkms_configfs.c  | 96 ++++++++++++++++++++++-----
 drivers/gpu/drm/vkms/vkms_drv.h       | 11 +++
 drivers/gpu/drm/vkms/vkms_output.c    | 47 ++++++++++++-
 drivers/gpu/drm/vkms/vkms_writeback.c |  2 +-
 5 files changed, 138 insertions(+), 20 deletions(-)
Documentation/gpu/vkms.rst +1 -1
index 2c342ef0fb7b..1eaae9f48693 100644
@@ -144,7 +144,7 @@ Runtime Configuration
 We want to vkms instances without having to reload the module. Such 
 configuration can be added as extensions to vkms's ConfigFS support. Use-cases:
 
-- Hotplug/hotremove connectors on the fly (to be able to test DP MST handling
+- Hotremove connectors on the fly (to be able to test DP MST handling
   of compositors).
 
 - Change output configuration: Plug/unplug screens, change EDID, allow changing
drivers/gpu/drm/vkms/vkms_configfs.c +79 -17

181 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_drv.h +11 -0
index 8f476ef4009b..7b9b189511c2 100644
@@ -3,6 +3,7 @@
 #ifndef _VKMS_DRV_H_
 #define _VKMS_DRV_H_
 
+#include "drm/drm_connector.h"
 #include <linux/configfs.h>
 #include <linux/hrtimer.h>
 
@@ -135,7 +136,9 @@ struct vkms_config_links {
 
 struct vkms_config_connector {
 	struct config_group config_group;
+	struct drm_connector *connector;
 	struct vkms_config_links possible_encoders;
+	bool connected;
 };
 
 struct vkms_config_crtc {
@@ -208,6 +211,10 @@ struct vkms_device {
 #define item_to_configfs(item) \
 	container_of(to_config_group(item), struct vkms_configfs, device_group)
 
+#define connector_item_to_configfs(item)                                     \
+	container_of(to_config_group(item->ci_parent), struct vkms_configfs, \
+		     connectors_group)
+
 #define item_to_config_connector(item)                                    \
 	container_of(to_config_group(item), struct vkms_config_connector, \
 		     config_group)
@@ -267,4 +274,8 @@ int vkms_enable_writeback_connector(struct vkms_device *vkmsdev,
 int vkms_init_configfs(void);
 void vkms_unregister_configfs(void);
 
+/* Connector hotplugging */
+enum drm_connector_status vkms_connector_detect(struct drm_connector *connector,
+						bool force);
+
 #endif /* _VKMS_DRV_H_ */
drivers/gpu/drm/vkms/vkms_output.c +46 -1

79 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_writeback.c +1 -1
index a77d9a6c9b74..47449979c564 100644
@@ -145,7 +145,7 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,
 	spin_lock_irq(&vkms_crtc->composer_lock);
 	crtc_state->active_writeback = active_wb;
 	crtc_state->wb_pending = true;
-	spin_unlock_irq(&output->composer_lock);
+	spin_unlock_irq(&vkms_crtc->composer_lock);
 
 	wb_frame_info->offset = fb->offsets[0];
 	wb_frame_info->pitch = fb->pitches[0];
Signature · 1 line
2.41.0.390.g38632f3daf-goog
#23 lore raw

PATCH 1/1 Initial backport of vkms changes from 6.4, including jshargo and brpols configs changes

In reply to Jim Shargo

WIP: Need to run all tast criticals and test the multidisplay tests that are WIP.

BUG=b:283357160
TEST=Booted on a betty-arc-r device and ran autologin.py -a
Change-Id: I13cef8cf019744813f51cfffed3d7ccb987834e8

Change-Id: Iae7d788bc4725dfdca044204fa1af27a5a1ec5a8

---
 drivers/gpu/drm/vkms/Makefile         |   1 +
 drivers/gpu/drm/vkms/vkms_composer.c  |  74 ++-
 drivers/gpu/drm/vkms/vkms_configfs.c  | 719 ++++++++++++++++++++++++++
 drivers/gpu/drm/vkms/vkms_crtc.c      |  98 ++--
 drivers/gpu/drm/vkms/vkms_drv.c       | 227 ++++----
 drivers/gpu/drm/vkms/vkms_drv.h       | 191 +++++--
 drivers/gpu/drm/vkms/vkms_formats.c   | 298 +++++------
 drivers/gpu/drm/vkms/vkms_formats.h   |   4 +-
 drivers/gpu/drm/vkms/vkms_output.c    | 351 +++++++++++--
 drivers/gpu/drm/vkms/vkms_plane.c     | 102 ++--
 drivers/gpu/drm/vkms/vkms_writeback.c |  33 +-
 include/drm/drm_fixed.h               |   7 +
 12 files changed, 1638 insertions(+), 467 deletions(-)
 create mode 100644 drivers/gpu/drm/vkms/vkms_configfs.c
drivers/gpu/drm/vkms/Makefile +1 -0
index 1b28a6a32948..6b83907ad554 100644
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0-only
 vkms-y := \
+	vkms_configfs.o \
 	vkms_drv.o \
 	vkms_plane.o \
 	vkms_output.o \
drivers/gpu/drm/vkms/vkms_composer.c +50 -24

172 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_configfs.c new file +719 -0

719 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_crtc.c +56 -42

209 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_drv.c +140 -87

336 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_drv.h +155 -36

274 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_formats.c +138 -160

365 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_formats.h +2 -2
index 43b7c1979018..cf59c2ed8e9a 100644
@@ -5,8 +5,8 @@
 
 #include "vkms_drv.h"
 
-void *get_frame_to_line_function(u32 format);
+void *get_pixel_conversion_function(u32 format);
 
-void *get_line_to_frame_function(u32 format);
+void *get_pixel_write_function(u32 format);
 
 #endif /* _VKMS_FORMATS_H_ */
drivers/gpu/drm/vkms/vkms_output.c +299 -52

420 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_plane.c +51 -51

176 lines not on this page · raw message

drivers/gpu/drm/vkms/vkms_writeback.c +20 -13
index 84a51cd281b9..47449979c564 100644
@@ -1,6 +1,7 @@
 // SPDX-License-Identifier: GPL-2.0+
 
 #include <linux/iosys-map.h>
+#include <linux/kernel.h>
 
 #include <drm/drm_atomic.h>
 #include <drm/drm_edid.h>
@@ -15,6 +16,7 @@
 #include "vkms_formats.h"
 
 static const u32 vkms_wb_formats[] = {
+	DRM_FORMAT_ARGB8888,
 	DRM_FORMAT_XRGB8888,
 	DRM_FORMAT_XRGB16161616,
 	DRM_FORMAT_ARGB16161616,
@@ -101,7 +103,8 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector,
 				struct drm_writeback_job *job)
 {
 	struct vkms_writeback_job *vkmsjob = job->priv;
-	struct vkms_device *vkmsdev;
+	struct vkms_crtc *vkms_crtc =
+		container_of(connector, struct vkms_crtc, wb_connector);
 
 	if (!job->fb)
 		return;
@@ -110,8 +113,7 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector,
 
 	drm_framebuffer_put(vkmsjob->wb_frame_info.fb);
 
-	vkmsdev = drm_device_to_vkms_device(job->fb->dev);
-	vkms_set_composer(&vkmsdev->output, false);
+	vkms_set_composer(vkms_crtc, false);
 	kfree(vkmsjob);
 }
 
@@ -120,11 +122,11 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,
 {
 	struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state,
 											 conn);
-	struct vkms_device *vkmsdev = drm_device_to_vkms_device(conn->dev);
-	struct vkms_output *output = &vkmsdev->output;
-	struct drm_writeback_connector *wb_conn = &output->wb_connector;
+	struct vkms_crtc *vkms_crtc =
+		drm_crtc_to_vkms_crtc(connector_state->crtc);
+	struct drm_writeback_connector *wb_conn = &vkms_crtc->wb_connector;
 	struct drm_connector_state *conn_state = wb_conn->base.state;
-	struct vkms_crtc_state *crtc_state = output->composer_state;
+	struct vkms_crtc_state *crtc_state = vkms_crtc->composer_state;
 	struct drm_framebuffer *fb = connector_state->writeback_job->fb;
 	u16 crtc_height = crtc_state->base.crtc->mode.vdisplay;
 	u16 crtc_width = crtc_state->base.crtc->mode.hdisplay;
@@ -135,20 +137,24 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,
 	if (!conn_state)
 		return;
 
-	vkms_set_composer(&vkmsdev->output, true);
+	vkms_set_composer(vkms_crtc, true);
 
 	active_wb = conn_state->writeback_job->priv;
 	wb_frame_info = &active_wb->wb_frame_info;
 
-	spin_lock_irq(&output->composer_lock);
+	spin_lock_irq(&vkms_crtc->composer_lock);
 	crtc_state->active_writeback = active_wb;
+	crtc_state->wb_pending = true;
+	spin_unlock_irq(&vkms_crtc->composer_lock);
+
 	wb_frame_info->offset = fb->offsets[0];
 	wb_frame_info->pitch = fb->pitches[0];
 	wb_frame_info->cpp = fb->format->cpp[0];
+
 	crtc_state->wb_pending = true;
-	spin_unlock_irq(&output->composer_lock);
+	spin_unlock_irq(&vkms_crtc->composer_lock);
 	drm_writeback_queue_job(wb_conn, connector_state);
-	active_wb->wb_write = get_line_to_frame_function(wb_format);
+	active_wb->pixel_write = get_pixel_write_function(wb_format);
 	drm_rect_init(&wb_frame_info->src, 0, 0, crtc_width, crtc_height);
 	drm_rect_init(&wb_frame_info->dst, 0, 0, crtc_width, crtc_height);
 }
@@ -160,9 +166,10 @@ static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = {
 	.atomic_commit = vkms_wb_atomic_commit,
 };
 
-int vkms_enable_writeback_connector(struct vkms_device *vkmsdev)
+int vkms_enable_writeback_connector(struct vkms_device *vkmsdev,
+				    struct vkms_crtc *vkms_crtc)
 {
-	struct drm_writeback_connector *wb = &vkmsdev->output.wb_connector;
+	struct drm_writeback_connector *wb = &vkms_crtc->wb_connector;
 
 	drm_connector_helper_add(&wb->base, &vkms_wb_conn_helper_funcs);
 
include/drm/drm_fixed.h +7 -0
index 553210c02ee0..6ea339d5de08 100644
@@ -25,6 +25,7 @@
 #ifndef DRM_FIXED_H
 #define DRM_FIXED_H
 
+#include <linux/kernel.h>
 #include <linux/math64.h>
 
 typedef union dfixed {
@@ -70,6 +71,7 @@ static inline u32 dfixed_div(fixed20_12 A, fixed20_12 B)
 }
 
 #define DRM_FIXED_POINT		32
+#define DRM_FIXED_POINT_HALF	16
 #define DRM_FIXED_ONE		(1ULL << DRM_FIXED_POINT)
 #define DRM_FIXED_DECIMAL_MASK	(DRM_FIXED_ONE - 1)
 #define DRM_FIXED_DIGITS_MASK	(~DRM_FIXED_DECIMAL_MASK)
@@ -86,6 +88,11 @@ static inline int drm_fixp2int(s64 a)
 	return ((s64)a) >> DRM_FIXED_POINT;
 }
 
+static inline int drm_fixp2int_round(s64 a)
+{
+	return drm_fixp2int(a + (1 << (DRM_FIXED_POINT_HALF - 1)));
+}
+
 static inline int drm_fixp2int_ceil(s64 a)
 {
 	if (a > 0)
Signature · 1 line
2.41.0.640.ga95def55d0-goog
#24 lore raw
In reply to Jim Shargo

Some of these comments have been sitting for a while.  Would it be ok if [email protected] and myself picked these up and did an iteration so we could also get https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/ submitted?  These will enable a lot of virtual multi display testing in linux! :)

Quoted 108 lines · Jim Shargo

Intro
=====

At long last, we're back!

This patchset adds basic ConfigFS support to VKMS, allowing users to build new DRM devices with user-defined DRM objects and object relationships by creating, writing, and symlinking files.

Usageubmitted
=====

After installing these patches, you can create a VKMS device with two displays and a movable overlay like so (this is documented in the patches):

   $ modprobe vkms enable_overlay=1 enable_cursor=1 enable_writeback=1
   $ mkdir -p /config/
   $ mount -t configfs none /config
   $ export DRM_PLANE_TYPE_PRIMARY=1
   $ export DRM_PLANE_TYPE_CURSOR=2
   $ export DRM_PLANE_TYPE_OVERLAY=0
   $ mkdir /config/vkms/test
   $ mkdir /config/vkms/test/planes/primary
   $ echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/primary/type
   $ mkdir /config/vkms/test/planes/other_primary
   $ echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/other_primary/type
   $ mkdir /config/vkms/test/planes/cursor
   $ echo $DRM_PLANE_TYPE_CURSOR > /config/vkms/test/planes/cursor/type
   $ mkdir /config/vkms/test/planes/overlay
   $ echo $DRM_PLANE_TYPE_OVERLAY > /config/vkms/test/planes/overlay/type
   $ mkdir /config/vkms/test/crtcs/crtc
   $ mkdir /config/vkms/test/crtcs/crtc_other
   $ mkdir /config/vkms/test/encoders/encoder
   $ mkdir /config/vkms/test/connectors/connector
   $ ln -s /config/vkms/test/encoders/encoder /config/vkms/test/connectors/connector/possible_encoders
   $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/encoders/encoder/possible_crtcs/
   $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/primary/possible_crtcs/
   $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/cursor/possible_crtcs/
   $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/overlay/possible_crtcs/
   $ ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/overlay/possible_crtcs/
   $ ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/other_primary/possible_crtcs/
   $ echo 1 > /config/vkms/test/enabled

Changes within core VKMS
========================

This introduces a few important changes to the overall structure of VKMS:

- Devices are now memory managed!
- Support for multiple CRTCs and other objects has been added

Since v1
========

- Added DRMM memory management to automatically clean up resources
- Added a param to disable the default device
- Renamed "cards" to "devices" to improve legibility
- Added a lock for the configfs setup handler
- Moved all the new docs into the relevant .c file
- Addressed as many of [email protected] as possible

Testing
=======

- New IGT tests (see gitlab.freedesktop.org/jshargo/igt-gpu-tools/-/merge_requests/1)
- Existing IGT tests (excluding .*suspend.*, including .*kms_flip.*

     .*kms_writeback.* .*kms_cursor_crc.*, .*kms_plane.*)

Outro
=====

I'm excited to share these changes, it's my still my first kernel patch and I've been putting a lot of love into these.

Jim Shargo (6):
drm/vkms: Back VKMS with DRM memory management instead of static
objects
drm/vkms: Support multiple DRM objects (crtcs, etc.) per VKMS device drm/vkms: Provide platform data when creating VKMS devices drm/vkms: Add ConfigFS scaffolding to VKMS
drm/vkms: Support enabling ConfigFS devices
drm/vkms: Add a module param to enable/disable the default device

  Documentation/gpu/vkms.rst            |  17 +-
  drivers/gpu/drm/Kconfig               |   1 +
  drivers/gpu/drm/vkms/Makefile         |   1 +
  drivers/gpu/drm/vkms/vkms_composer.c  |  28 +-
  drivers/gpu/drm/vkms/vkms_configfs.c  | 657 ++++++++++++++++++++++++++
  drivers/gpu/drm/vkms/vkms_crtc.c      |  97 ++--
  drivers/gpu/drm/vkms/vkms_drv.c       | 208 +++++---
  drivers/gpu/drm/vkms/vkms_drv.h       | 166 +++++--
  drivers/gpu/drm/vkms/vkms_output.c    | 299 ++++++++++--
  drivers/gpu/drm/vkms/vkms_plane.c     |  44 +-
  drivers/gpu/drm/vkms/vkms_writeback.c |  26 +-
  11 files changed, 1312 insertions(+), 232 deletions(-)

create mode 100644 drivers/gpu/drm/vkms/vkms_configfs.c

#25 lore raw

Hi Brandon,

Is Jim Shargo no longer able to follow-up with these anymore? Can you reach out to him? Maybe he's on holiday/vacation at this point?

If you decide to follow-up we need a v3 -- and possibly a few more, but I'd just focus on getting the ConfigFS infrastructure in, addressing current comments, re-base on top of drm-misc as they do not apply anymore, and further polishing the patches.

After that gets in, I'd then focus of getting on expanding on it and getting hot-plug. You'd need also some i-g-t tests for that.

There's also bunch of i-g-t tests sitting in a MR but those need to be posted to [email protected] rather than on gitlab. We'd need that in as well.

Quoted 115 lines · Brandon Ross Pollack

Some of these comments have been sitting for a while.  Would it be ok if
[email protected] and myself picked these up and did an iteration so we
could also get https://patchwork.kernel.org/project/dri-devel/patch/[email protected]/
submitted?  These will enable a lot of virtual multi display testing in
linux! :)

Quoted 108 lines · Jim Shargo

Intro
=====

At long last, we're back!

This patchset adds basic ConfigFS support to VKMS, allowing users to build new DRM devices with user-defined DRM objects and object relationships by creating, writing, and symlinking files.

Usageubmitted
=====

After installing these patches, you can create a VKMS device with two displays and a movable overlay like so (this is documented in the patches):

   $ modprobe vkms enable_overlay=1 enable_cursor=1 enable_writeback=1
   $ mkdir -p /config/
   $ mount -t configfs none /config
   $ export DRM_PLANE_TYPE_PRIMARY=1
   $ export DRM_PLANE_TYPE_CURSOR=2
   $ export DRM_PLANE_TYPE_OVERLAY=0
   $ mkdir /config/vkms/test
   $ mkdir /config/vkms/test/planes/primary
   $ echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/primary/type
   $ mkdir /config/vkms/test/planes/other_primary
   $ echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/other_primary/type
   $ mkdir /config/vkms/test/planes/cursor
   $ echo $DRM_PLANE_TYPE_CURSOR > /config/vkms/test/planes/cursor/type
   $ mkdir /config/vkms/test/planes/overlay
   $ echo $DRM_PLANE_TYPE_OVERLAY > /config/vkms/test/planes/overlay/type
   $ mkdir /config/vkms/test/crtcs/crtc
   $ mkdir /config/vkms/test/crtcs/crtc_other
   $ mkdir /config/vkms/test/encoders/encoder
   $ mkdir /config/vkms/test/connectors/connector
   $ ln -s /config/vkms/test/encoders/encoder /config/vkms/test/connectors/connector/possible_encoders
   $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/encoders/encoder/possible_crtcs/
   $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/primary/possible_crtcs/
   $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/cursor/possible_crtcs/
   $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/overlay/possible_crtcs/
   $ ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/overlay/possible_crtcs/
   $ ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/other_primary/possible_crtcs/
   $ echo 1 > /config/vkms/test/enabled

Changes within core VKMS
========================

This introduces a few important changes to the overall structure of VKMS:

- Devices are now memory managed!
- Support for multiple CRTCs and other objects has been added

Since v1
========

- Added DRMM memory management to automatically clean up resources
- Added a param to disable the default device
- Renamed "cards" to "devices" to improve legibility
- Added a lock for the configfs setup handler
- Moved all the new docs into the relevant .c file
- Addressed as many of [email protected] as possible

Testing
=======

- New IGT tests (see gitlab.freedesktop.org/jshargo/igt-gpu-tools/-/merge_requests/1)
- Existing IGT tests (excluding .*suspend.*, including .*kms_flip.*

     .*kms_writeback.* .*kms_cursor_crc.*, .*kms_plane.*)

Outro
=====

I'm excited to share these changes, it's my still my first kernel patch and I've been putting a lot of love into these.

Jim Shargo (6):
drm/vkms: Back VKMS with DRM memory management instead of static
objects
drm/vkms: Support multiple DRM objects (crtcs, etc.) per VKMS device drm/vkms: Provide platform data when creating VKMS devices drm/vkms: Add ConfigFS scaffolding to VKMS
drm/vkms: Support enabling ConfigFS devices
drm/vkms: Add a module param to enable/disable the default device

  Documentation/gpu/vkms.rst            |  17 +-
  drivers/gpu/drm/Kconfig               |   1 +
  drivers/gpu/drm/vkms/Makefile         |   1 +
  drivers/gpu/drm/vkms/vkms_composer.c  |  28 +-
  drivers/gpu/drm/vkms/vkms_configfs.c  | 657 ++++++++++++++++++++++++++
  drivers/gpu/drm/vkms/vkms_crtc.c      |  97 ++--
  drivers/gpu/drm/vkms/vkms_drv.c       | 208 +++++---
  drivers/gpu/drm/vkms/vkms_drv.h       | 166 +++++--
  drivers/gpu/drm/vkms/vkms_output.c    | 299 ++++++++++--
  drivers/gpu/drm/vkms/vkms_plane.c     |  44 +-
  drivers/gpu/drm/vkms/vkms_writeback.c |  26 +-
  11 files changed, 1312 insertions(+), 232 deletions(-)

create mode 100644 drivers/gpu/drm/vkms/vkms_configfs.c