Adds support for ConfigFS to VKMS!
v6 cover Adds support for ConfigFS to VKMS!
Since Jim is busy with other work and I'm working on some things that rely on this, I've taken up the task of doing the iterations. I've addressed the comments as best I can (those replies are to each individual change) and here is the patch set to go with those.
I added my own signoff to each commit, but I've left jshargo@ as the author of all the commits he wrote. I'm sure there is still more to address and the ICT tests that were writtein parallel to this may also need some additions, but I'm hoping we're in a good enough state to get this in and iterate from there soon.
Since V6:
========
rmdirs for documentation examples
fix crtc mask for writebacks
Since V5:
========
Fixed some bad merge conflicts and locking behaviours as well as clarified some documentation, should be good to go now :)
Since V4:
========
Fixed up some documentation as suggested by Marius
Fixed up some bad locking as suggested by Marius
Small fixes here and there (most have email responses to previous chain emails)
Since V3:
========
I've added hotplug support in the latest patch. This has been reviewed some and the notes from that review are addressed here as well.
Relevant/Utilizing work:
=======================
I've built a while test framework based on this as proof it functions (though I'm sure there may be lingering bugs!). You can check that out on crrev.com if you are interested and need to get started yourself (but be aware of any licensing that may differ from the kernel itself! Make sure you understand the license:
https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/tast-tests/LICENSE
That said, you can see the changes in review on the crrev gerrit:
https://chromium-review.googlesource.com/c/chromiumos/platform/tast-tests/+/4666669
Outro:
=====
I really appreciate everyone's input and tolerance in getting these changes in. Jim's first patch series was this, and other than some small cleanups and documentation, taking over it is also mine.
Thank you everyone :)
Brandon Pollack (1):
drm/vkms Add hotplug support via configfs to VKMS.
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 | 20 +- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/vkms_composer.c | 30 +- drivers/gpu/drm/vkms/vkms_configfs.c | 723 ++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_crtc.c | 102 ++-- drivers/gpu/drm/vkms/vkms_drv.c | 206 +++++--- drivers/gpu/drm/vkms/vkms_drv.h | 182 +++++-- drivers/gpu/drm/vkms/vkms_output.c | 404 ++++++++++++-- drivers/gpu/drm/vkms/vkms_plane.c | 44 +- drivers/gpu/drm/vkms/vkms_writeback.c | 42 +- 11 files changed, 1514 insertions(+), 241 deletions(-) create mode 100644 drivers/gpu/drm/vkms/vkms_configfs.c
Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
PATCH v6 1/7 drm/vkms: Back VKMS with DRM memory management instead of static objects
From: Jim Shargo <[email protected]>
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 | 128 +++++++++++++++-------------- drivers/gpu/drm/vkms/vkms_drv.h | 4 +- drivers/gpu/drm/vkms/vkms_output.c | 6 +- 3 files changed, 71 insertions(+), 67 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.c +67 -61
@@ -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" );
@@ -96,9 +96,9 @@ static int vkms_config_show(struct seq_file *m, void *data)struct drm_device *dev = entry->dev;struct vkms_device *vkmsdev =drm_device_to_vkms_device (dev); -seq_printf (m,"writeback=%d\n" , vkmsdev->config->writeback); -seq_printf (m,"cursor=%d\n" , vkmsdev->config->cursor); -seq_printf (m,"overlay=%d\n" , vkmsdev->config->overlay); +seq_printf (m,"writeback=%d\n" , vkmsdev->config.writeback); +seq_printf (m,"cursor=%d\n" , vkmsdev->config.cursor); +seq_printf (m,"overlay=%d\n" , vkmsdev->config.overlay);return 0 ; }
@@ -166,121 +166,127 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) dev->mode_config.cursor_height =512 ;/* FIXME: There's a confusion between bpp and depth between this and * fbdev helpers. We have to go with 0, meaning "pick the default", -* which ix XRGB8888 in all cases. */ +* which ix XRGB8888 in all cases. +*/ dev->mode_config.preferred_depth =0 ; dev->mode_config.helper_private = &vkms_mode_config_helpers;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 with id %d\n" , pdev->id); + goto out_release_group; + }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
@@ -124,15 +124,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
@@ -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.42.0.rc2.253.gd59a3bf2b4-goog
PATCH v6 2/7 drm/vkms: Support multiple DRM objects (crtcs, etc.) per VKMS device
In reply to Brandon PollackFrom: Jim Shargo <[email protected]>
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 | 30 +++---- drivers/gpu/drm/vkms/vkms_crtc.c | 100 ++++++++++++--------- drivers/gpu/drm/vkms/vkms_drv.c | 12 +-- drivers/gpu/drm/vkms/vkms_drv.h | 70 +++++++++------ drivers/gpu/drm/vkms/vkms_output.c | 122 ++++++++++++++++++-------- drivers/gpu/drm/vkms/vkms_plane.c | 38 ++++++-- drivers/gpu/drm/vkms/vkms_writeback.c | 42 ++++----- 7 files changed, 261 insertions(+), 153 deletions(-)
drivers/gpu/drm/vkms/vkms_composer.c +15 -15
@@ -300,13 +300,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;
@@ -330,7 +330,7 @@ void vkms_composer_worker(struct work_struct *work) crtc_state->gamma_lut.base =NULL ; } -spin_unlock_irq (&out->composer_lock); +spin_unlock_irq (&vkms_crtc->composer_lock);/* * We raced with the vblank hrtimer and previous work already computed
@@ -348,10 +348,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); }/*
@@ -401,30 +401,30 @@ 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); -mutex_lock (&out->enabled_lock); - old_enabled = out->composer_enabled; - out->composer_enabled = enabled; +mutex_lock (&vkms_crtc->enabled_lock); + old_enabled = vkms_crtc->composer_enabled; + vkms_crtc->composer_enabled = enabled;/* the composition wasn't enabled, so unlock the lock to make sure the lock * will be balanced even if we have a failed commit */ -if (!out->composer_enabled) -mutex_unlock (&out->enabled_lock); +if (!vkms_crtc->composer_enabled) +mutex_unlock (&vkms_crtc->enabled_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 +58 -42
211 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_drv.c +6 -6
@@ -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)
@@ -203,15 +203,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.h +44 -26
117 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_output.c +87 -35
184 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_plane.c +30 -8
@@ -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;
@@ -86,9 +102,10 @@ 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, + .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 +21 -21
87 lines not on this page · raw message
Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
PATCH v6 4/7 drm/vkms: Add ConfigFS scaffolding to VKMS
In reply to Brandon PollackFrom: Jim Shargo <[email protected]>
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 | 18 +- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/vkms_configfs.c | 650 +++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_drv.c | 56 ++- drivers/gpu/drm/vkms/vkms_drv.h | 92 +++- drivers/gpu/drm/vkms/vkms_output.c | 5 + 7 files changed, 806 insertions(+), 17 deletions(-) create mode 100644 drivers/gpu/drm/vkms/vkms_configfs.c
Documentation/gpu/vkms.rst +9 -9
@@ -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,16 @@ project. Runtime Configuration --------------------- -We want to be able to reconfigure vkms instance without having to reload the -module. Use/Test-cases: +We want to be able to manipulate 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
@@ -284,6 +284,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
@@ -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 +650 -0
650 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_drv.c +50 -6
105 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
@@ -176,3 +176,8 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)return ret; } + +int vkms_output_init (struct vkms_device *vkmsdev) +{ +return -EOPNOTSUPP ; +}
Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
PATCH v6 5/7 drm/vkms: Support enabling ConfigFS devices
In reply to Brandon PollackFrom: Jim Shargo <[email protected]>
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 | 1 + drivers/gpu/drm/vkms/vkms_drv.h | 4 +- drivers/gpu/drm/vkms/vkms_output.c | 282 +++++++++++++++++++++++---- drivers/gpu/drm/vkms/vkms_plane.c | 10 +- 6 files changed, 282 insertions(+), 56 deletions(-)
drivers/gpu/drm/vkms/vkms_configfs.c +24 -13
@@ -508,29 +508,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
@@ -279,7 +279,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;
@@ -291,7 +291,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 +1 -0
@@ -275,6 +275,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 +2 -2
@@ -250,13 +250,13 @@ 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);struct vkms_plane *vkms_plane_init (struct vkms_device *vkmsdev, -enum drm_plane_type type); +enum drm_plane_type type,char * name, ...);/* CRC Support */ const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,
drivers/gpu/drm/vkms/vkms_output.c +245 -37
357 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_plane.c +8 -2
@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0+ #include <linux/iosys-map.h> +#include <linux/stdarg.h> #include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h>
@@ -215,20 +216,25 @@ 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) +enum drm_plane_type type,char *name, ...) {struct drm_device *dev = &vkmsdev->drm;struct vkms_output *output = &vkmsdev->output;struct vkms_plane *plane; +va_list va;int ret;if (output->num_planes >=VKMS_MAX_PLANES )return ERR_PTR (-ENOMEM ); plane = &output->planes[output->num_planes++]; + +va_start (va, name); ret =drm_universal_plane_init (dev, &plane->base,0 , &vkms_plane_funcs, vkms_formats,ARRAY_SIZE (vkms_formats), -NULL , type,NULL ); +NULL , type, name, va); +va_end (va); +if (ret)return ERR_PTR (ret);
Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
PATCH v6 3/7 drm/vkms: Provide platform data when creating VKMS devices
In reply to Brandon PollackFrom: Jim Shargo <[email protected]>
This is a small refactor to make ConfigFS support easier. This should be a no-op refactor.
--- drivers/gpu/drm/vkms/vkms_drv.c | 14 ++++++++++++-- drivers/gpu/drm/vkms/vkms_drv.h | 9 ++++++--- drivers/gpu/drm/vkms/vkms_output.c | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.c +12 -2
@@ -9,6 +9,7 @@* the GPU in DRM API tests. */ +#include "asm-generic/errno-base.h" #include <linux/device.h> #include <linux/module.h> #include <linux/platform_device.h>
@@ -171,12 +172,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) : + -EINVAL ; }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;
@@ -195,6 +198,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 ));
@@ -258,6 +262,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) {
@@ -265,8 +272,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
@@ -132,17 +132,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; };
@@ -166,7 +169,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
@@ -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.42.0.rc2.253.gd59a3bf2b4-goog
PATCH v6 6/7 drm/vkms: Add a module param to enable/disable the default device
In reply to Brandon PollackFrom: Jim Shargo <[email protected]>
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 | 45 ++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 15 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.c +30 -15
@@ -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);
@@ -99,6 +108,7 @@ static int vkms_config_show(struct seq_file *m, void *data)struct drm_device *dev = entry->dev;struct vkms_device *vkmsdev =drm_device_to_vkms_device (dev); +seq_printf (m,"default_device=%d\n" , enable_default_device);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);
@@ -297,10 +307,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) {
@@ -308,19 +315,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.42.0.rc2.253.gd59a3bf2b4-goog
PATCH v6 7/7 drm/vkms Add hotplug support via configfs to VKMS.
In reply to Brandon PollackThis 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).
--- Documentation/gpu/vkms.rst | 2 +- drivers/gpu/drm/vkms/vkms_configfs.c | 68 ++++++++++++++++++++++++++-- drivers/gpu/drm/vkms/vkms_drv.h | 11 +++++ drivers/gpu/drm/vkms/vkms_output.c | 47 ++++++++++++++++++- 4 files changed, 123 insertions(+), 5 deletions(-)
Documentation/gpu/vkms.rst +1 -1
@@ -145,7 +145,7 @@ We want to be able to manipulate 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 +65 -3
116 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_drv.h +11 -0
@@ -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>
@@ -147,7 +148,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 {
@@ -220,6 +223,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)
@@ -279,4 +286,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
Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
Hi Brandon,
You can now add https://lists.freedesktop.org/archives/igt-dev/2023-September/060717.html
as part of this series.
Quoted 84 lines · Brandon Pollack
Since Jim is busy with other work and I'm working on some things that rely on this, I've taken up the task of doing the iterations. I've addressed the comments as best I can (those replies are to each individual change) and here is the patch set to go with those.
I added my own signoff to each commit, but I've left jshargo@ as the author of all the commits he wrote. I'm sure there is still more to address and the ICT tests that were writtein parallel to this may also need some additions, but I'm hoping we're in a good enough state to get this in and iterate from there soon.
Since V6:
========
rmdirs for documentation examples
fix crtc mask for writebacksSince V5:
========
Fixed some bad merge conflicts and locking behaviours as well as clarified some documentation, should be good to go now :)Since V4:
========
Fixed up some documentation as suggested by Marius
Fixed up some bad locking as suggested by Marius
Small fixes here and there (most have email responses to previous chain emails)Since V3:
========
I've added hotplug support in the latest patch. This has been reviewed some and the notes from that review are addressed here as well.Relevant/Utilizing work:
=======================
I've built a while test framework based on this as proof it functions (though I'm sure there may be lingering bugs!). You can check that out on crrev.com if you are interested and need to get started yourself (but be aware of any licensing that may differ from the kernel itself! Make sure you understand the license:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/tast-tests/LICENSE
That said, you can see the changes in review on the crrev gerrit:
https://chromium-review.googlesource.com/c/chromiumos/platform/tast-tests/+/4666669
Outro:
=====
I really appreciate everyone's input and tolerance in getting these changes in. Jim's first patch series was this, and other than some small cleanups and documentation, taking over it is also mine.Thank you everyone :)
Brandon Pollack (1):
drm/vkms Add hotplug support via configfs to VKMS.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 deviceDocumentation/gpu/vkms.rst | 20 +- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/vkms_composer.c | 30 +- drivers/gpu/drm/vkms/vkms_configfs.c | 723 ++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_crtc.c | 102 ++-- drivers/gpu/drm/vkms/vkms_drv.c | 206 +++++--- drivers/gpu/drm/vkms/vkms_drv.h | 182 +++++-- drivers/gpu/drm/vkms/vkms_output.c | 404 ++++++++++++-- drivers/gpu/drm/vkms/vkms_plane.c | 44 +- drivers/gpu/drm/vkms/vkms_writeback.c | 42 +- 11 files changed, 1514 insertions(+), 241 deletions(-) create mode 100644 drivers/gpu/drm/vkms/vkms_configfs.cSignature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
Re: [PATCH v6 2/7] drm/vkms: Support multiple DRM objects (crtcs, etc.) per VKMS device
In reply to Brandon PollackHi Brandon,
Small nit-pick at the end.
Quoted 849 lines · Brandon Pollack
From: Jim Shargo <[email protected]>
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.
Signed-off-by Jim Shargo <[email protected]>Signed-off-by Brandon Pollack <[email protected]>--- drivers/gpu/drm/vkms/vkms_composer.c | 30 +++---- drivers/gpu/drm/vkms/vkms_crtc.c | 100 ++++++++++++--------- drivers/gpu/drm/vkms/vkms_drv.c | 12 +-- drivers/gpu/drm/vkms/vkms_drv.h | 70 +++++++++------ drivers/gpu/drm/vkms/vkms_output.c | 122 ++++++++++++++++++-------- drivers/gpu/drm/vkms/vkms_plane.c | 38 ++++++-- drivers/gpu/drm/vkms/vkms_writeback.c | 42 ++++----- 7 files changed, 261 insertions(+), 153 deletions(-)drivers/gpu/drm/vkms/vkms_composer.c +15
-15@@ -300,13 +300,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;@@ -330,7 +330,7 @@ void vkms_composer_worker(struct work_struct *work) crtc_state->gamma_lut.base =NULL ; } -spin_unlock_irq (&out->composer_lock); +spin_unlock_irq (&vkms_crtc->composer_lock);/* * We raced with the vblank hrtimer and previous work already computed @@ -348,10 +348,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); }/* @@ -401,30 +401,30 @@ 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); -mutex_lock (&out->enabled_lock); - old_enabled = out->composer_enabled; - out->composer_enabled = enabled; +mutex_lock (&vkms_crtc->enabled_lock); + old_enabled = vkms_crtc->composer_enabled; + vkms_crtc->composer_enabled = enabled;/* the composition wasn't enabled, so unlock the lock to make sure the lock * will be balanced even if we have a failed commit */ -if (!out->composer_enabled) -mutex_unlock (&out->enabled_lock); +if (!vkms_crtc->composer_enabled) +mutex_unlock (&vkms_crtc->enabled_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 +58
-42@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0+ +#include "linux/mutex.h" #include <linux/dma-fence.h> #include <drm/drm_atomic.h> @@ -11,17 +12,16 @@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, composer_enabled; 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__);@@ -29,9 +29,9 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer)if (!ret)DRM_ERROR ("vkms failure on handling vblank" ); - state = output->composer_state; - composer_enabled = output->composer_enabled; -mutex_unlock (&output->enabled_lock); + state = vkms_crtc->composer_state; + composer_enabled = vkms_crtc->composer_enabled; +mutex_unlock (&vkms_crtc->enabled_lock);if (state && composer_enabled) {u64 frame =drm_crtc_accurate_vblank_count (crtc);@@ -39,7 +39,7 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer)/* 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 +47,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 +63,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 +91,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 +100,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 +112,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 +238,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 +264,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,31 +277,45 @@ 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); -drm_mode_crtc_set_gamma_size (crtc,VKMS_LUT_SIZE ); -drm_crtc_enable_color_mgmt (crtc,0 , false,VKMS_LUT_SIZE ); +drm_mode_crtc_set_gamma_size (&vkms_crtc->base,VKMS_LUT_SIZE ); +drm_crtc_enable_color_mgmt (&vkms_crtc->base,0 , false,VKMS_LUT_SIZE ); -spin_lock_init (&vkms_out->lock); -spin_lock_init (&vkms_out->composer_lock); -mutex_init (&vkms_out->enabled_lock); +spin_lock_init (&vkms_crtc->lock); +spin_lock_init (&vkms_crtc->composer_lock); +mutex_init (&vkms_crtc->enabled_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 +6
-6@@ -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)@@ -203,15 +203,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.h +44
-26@@ -23,6 +23,10 @@#define NUM_OVERLAY_PLANES 8 + +#define VKMS_MAX_OUTPUT_OBJECTS 16 +#define VKMS_MAX_PLANES (3 * VKMS_MAX_OUTPUT_OBJECTS) +#define VKMS_LUT_SIZE 256struct vkms_frame_info {@@ -66,6 +70,27 @@ 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; +/* guarantees that if the composer is enabled, a job will be queued */ +struct mutex enabled_lock; + +/* protected by @enabled_lock */ +bool composer_enabled; +struct vkms_crtc_state *composer_state; + +spinlock_t composer_lock; +}; +struct vkms_color_lut {struct drm_color_lut *base;size_t lut_length;@@ -97,25 +122,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; -/* guarantees that if the composer is enabled, a job will be queued */ -struct mutex enabled_lock; - -/* protected by @enabled_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 ;@@ -133,12 +147,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)@@ -146,13 +162,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,@@ -163,11 +180,12 @@ 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);void vkms_writeback_row (struct vkms_writeback_job *wb,const struct line_buffer *src_buffer,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 +87
-35@@ -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,13 @@ 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 +30
-8@@ -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;@@ -86,9 +102,10 @@ 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, + .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 +16
-16@@ -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> @@ -102,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 ;@@ -111,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); }@@ -121,11 +122,10 @@ 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 drm_connector_state *conn_state = wb_conn->base.state; -struct vkms_crtc_state *crtc_state = output->composer_state; +struct vkms_crtc *vkms_crtc = +drm_crtc_to_vkms_crtc (connector_state->crtc); +struct drm_writeback_connector *wb_conn = &vkms_crtc->wb_connector; +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;@@ -133,18 +133,18 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn,struct vkms_frame_info *wb_frame_info;u32 wb_format = fb->format->format; -if (!conn_state) +if (!connector_state)return ; -vkms_set_composer (&vkmsdev->output, true); +vkms_set_composer (vkms_crtc, true); - active_wb = conn_state->writeback_job->priv; + active_wb = connector_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 (&output->composer_lock); +spin_unlock_irq (&vkms_crtc->composer_lock); wb_frame_info->offset = fb->offsets[0 ]; wb_frame_info->pitch = fb->pitches[0 ];@@ -163,16 +163,16 @@ 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); - return drm_writeback_connector_init(&vkmsdev->drm, wb,
drivers/gpu/drm/vkms/vkms_writeback.c static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = { · line 177
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_writeback.c +5
-5- &vkms_wb_connector_funcs, - &vkms_wb_encoder_helper_funcs, - vkms_wb_formats, -ARRAY_SIZE (vkms_wb_formats), - 1); +return drm_writeback_connector_init ( + &vkmsdev->drm, wb, &vkms_wb_connector_funcs, + &vkms_wb_encoder_helper_funcs, vkms_wb_formats, +ARRAY_SIZE (vkms_wb_formats), +BIT (drm_crtc_index (&vkms_crtc->base)));
Which is what drm_crtc_mask() does right?
Quoted 4 lines
drivers/gpu/drm/vkms/vkms_writeback.c +0
-0}Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
Re: [PATCH v6 7/7] drm/vkms Add hotplug support via configfs to VKMS.
In reply to Brandon PollackHello!
Thanks for the patch.
Quoted 10 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).
Are these tests going to be added in igt?
I was just wondering if it requires any special thing for drm ci:
https://lists.freedesktop.org/archives/dri-devel/2023-September/423719.html
(btw, it would be awesome of you could test your changes with drm ci :)
Regards,
Helen
Quoted 279 lines
Signed-off-by Brandon Pollack <[email protected]>--- Documentation/gpu/vkms.rst | 2 +- drivers/gpu/drm/vkms/vkms_configfs.c | 68 ++++++++++++++++++++++++++-- drivers/gpu/drm/vkms/vkms_drv.h | 11 +++++ drivers/gpu/drm/vkms/vkms_output.c | 47 ++++++++++++++++++- 4 files changed, 123 insertions(+), 5 deletions(-)Documentation/gpu/vkms.rst +1
-1@@ -145,7 +145,7 @@ We want to be able to manipulate 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 changingdrivers/gpu/drm/vkms/vkms_configfs.c +65
-3@@ -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> @@ -40,6 +41,7 @@* `-- vkms * `-- test * |-- connectors +* `-- connected * |-- crtcs * |-- encoders * |-- planes @@ -89,6 +91,14 @@* * 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 +* +* One can verify that this is worked using the `modetest` utility or the +* equivalent for your platform. +* * When you're done with the virtual device, you can clean up the device like * so:: * @@ -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) +return ret; + +if (val !=1 && val !=0 ) +return -EINVAL ; + +mutex_lock (&configfs->lock); + connector->connected = val; +if (!connector->connector) { +pr_info ("VKMS Device %s is not yet enabled, connector will be enabled on start" , + configfs->device_group.cg_item.ci_name); + } +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; }@@ -500,7 +562,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,@@ -557,7 +619,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@@ -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> @@ -147,7 +148,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 {@@ -220,6 +223,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)@@ -279,4 +286,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@@ -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, };@@ -280,12 +325,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_encoders; j++) {struct encoder_map *encoder = &encoder_map[j];
Re: [PATCH v6 7/7] drm/vkms Add hotplug support via configfs to VKMS.
Sorry, these tests are actually running in the chromeOS infrastructure environment! A similar test can be written in IGT (and I think is in the other chain that Marius published)
Quoted 307 lines · Helen Koike
Hello!
Thanks for the patch.
Quoted 10 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).
Are these tests going to be added in igt?
I was just wondering if it requires any special thing for drm ci:
https://lists.freedesktop.org/archives/dri-devel/2023-September/423719.html
(btw, it would be awesome of you could test your changes with drm ci :)
Regards,
HelenQuoted 279 lines
Signed-off-by Brandon Pollack <[email protected]>--- Documentation/gpu/vkms.rst | 2 +- drivers/gpu/drm/vkms/vkms_configfs.c | 68 ++++++++++++++++++++++++++-- drivers/gpu/drm/vkms/vkms_drv.h | 11 +++++ drivers/gpu/drm/vkms/vkms_output.c | 47 ++++++++++++++++++- 4 files changed, 123 insertions(+), 5 deletions(-)Documentation/gpu/vkms.rst +1
-1@@ -145,7 +145,7 @@ We want to be able to manipulate 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 changingdrivers/gpu/drm/vkms/vkms_configfs.c +65
-3@@ -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> @@ -40,6 +41,7 @@* `-- vkms * `-- test * |-- connectors +* `-- connected * |-- crtcs * |-- encoders * |-- planes @@ -89,6 +91,14 @@* * 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 +* +* One can verify that this is worked using the `modetest` utility or the +* equivalent for your platform. +* * When you're done with the virtual device, you can clean up the device like * so:: * @@ -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) +return ret; + +if (val !=1 && val !=0 ) +return -EINVAL ; + +mutex_lock (&configfs->lock); + connector->connected = val; +if (!connector->connector) { +pr_info ("VKMS Device %s is not yet enabled, connector will be enabled on start" , + configfs->device_group.cg_item.ci_name); + } +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; }@@ -500,7 +562,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,@@ -557,7 +619,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@@ -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> @@ -147,7 +148,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 {@@ -220,6 +223,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)@@ -279,4 +286,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@@ -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, };@@ -280,12 +325,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_encoders; j++) {struct encoder_map *encoder = &encoder_map[j];
Re: [PATCH v6 1/7] drm/vkms: Back VKMS with DRM memory management instead of static objects
In reply to Brandon PollackQuoted 11 lines · Brandon Pollack
From: Jim Shargo <[email protected]>
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.
Signed-off-by Jim Shargo <[email protected]>Signed-off-by Brandon Pollack <[email protected]>
Ok a few things on more the design of this all:
- This patch switches vkms over to be a real platform driver with probe/remove hooks. Fine with me, but would need to be split out and properly justified with some reason.
Also if we do this, we don't need our own devres group anymore, that's redundant.
- Now on the actual configfs prep work, the issue is that configfs and drm_device have independent lifetimes, and we cannot have links between the two. The configfs structures might have shorter lifetime thatn the vkms_device (and there's no refcounting on configfs afaict), which means we cannot have a backpointer from vkms_device to configfs. We can only rely on configfs being around during the probe/init code, thanks to the configfs mutex.
This is why the refactoring to use vkms_config was done, so that configfs becomes a two-step process: 1. convert the configfs data into a struct vkms_config 2. initialize the vkms device using that stand-alone vkms_config.
Now I understand that this is quite a bit of work, but I think it would also lead to somewhat more robust code (stuff like the lifetime bugs in the connector hotplug patch become impossible). So before we go into details, we need to make a decision whether we stick with the vkms_config design, or whether we just have two separate paths: a) default device setup and b) configfs dynamic setup. Imo this also needs an ack from Maíra.
- If we stick with the split approach then we need a few changes.
- The vkms_device->configfs backpointer needs to go, it's fundamentally busted. Instead I think it's best we pass the configfs pointer around directly during init time.
- I think we should clearly split the default and configfs paths with explicit suffixes in the relevant functions (like vkms_output_init_default/configfs) and explicitly passing parameters around.
- the vkms_config design doesn't have a use anymore, imo we should simplify the _default() paths to again just look at the module parameters. But only if we go the route of having split setup paths.
- Data that's only relevant for one or the other paths needs to be removed from global structures. This would be vkms_config and vkms_output in vkms_device (the latter is left around, which is very confusing since the configfs path doesn't use that at all).
- Going with a real platform driver means passing arguments to probe/init becomes tricky. Using the platform data seems like a good approach, but we must ensure that we clear that again when we remove the platform_device. Note that with a real driver userspace can unbind/rebind the driver through sysfs, which means we must keep the configfs pointer valid until the device is removed, to make sure that these subsequent re-probe calls still work. These complications are also the reasons why I think we should only switch to a real platform driver if there's a reason, a lot of things become a lot more complicated and dynamic and tricky with this.
Also this means that driver code could try to look at configfs even after probe/init is finished, which is buggy but would mostly work (unless you really carefully race hotunplug against other driver code). So potential for some tricky bugs. That's why I think we should explicitly pass the configfs pointer as a function parameter and only grab it from the platform_data in ->probe once (and put a comment there why this is really tricky).
Anyway before we proceed I think we need consensus on these 2 design questions.
-Sima
Quoted 284 lines
--- drivers/gpu/drm/vkms/vkms_drv.c | 128 +++++++++++++++-------------- drivers/gpu/drm/vkms/vkms_drv.h | 4 +- drivers/gpu/drm/vkms/vkms_output.c | 6 +- 3 files changed, 71 insertions(+), 67 deletions(-)drivers/gpu/drm/vkms/vkms_drv.c +67
-61@@ -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" );@@ -96,9 +96,9 @@ static int vkms_config_show(struct seq_file *m, void *data)struct drm_device *dev = entry->dev;struct vkms_device *vkmsdev =drm_device_to_vkms_device (dev); -seq_printf (m,"writeback=%d\n" , vkmsdev->config->writeback); -seq_printf (m,"cursor=%d\n" , vkmsdev->config->cursor); -seq_printf (m,"overlay=%d\n" , vkmsdev->config->overlay); +seq_printf (m,"writeback=%d\n" , vkmsdev->config.writeback); +seq_printf (m,"cursor=%d\n" , vkmsdev->config.cursor); +seq_printf (m,"overlay=%d\n" , vkmsdev->config.overlay);return 0 ; }@@ -166,121 +166,127 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) dev->mode_config.cursor_height =512 ;/* FIXME: There's a confusion between bpp and depth between this and * fbdev helpers. We have to go with 0, meaning "pick the default", -* which ix XRGB8888 in all cases. */ +* which ix XRGB8888 in all cases. +*/ dev->mode_config.preferred_depth =0 ; dev->mode_config.helper_private = &vkms_mode_config_helpers;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 with id %d\n" , pdev->id); + goto out_release_group; + }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@@ -124,15 +124,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@@ -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.42.0.rc2.253.gd59a3bf2b4-goog
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH v6 2/7] drm/vkms: Support multiple DRM objects (crtcs, etc.) per VKMS device
In reply to Brandon PollackQuoted 39 lines · Brandon Pollack
From: Jim Shargo <[email protected]>
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.
Signed-off-by Jim Shargo <[email protected]>Signed-off-by Brandon Pollack <[email protected]>drivers/gpu/drm/vkms/vkms_drv.h +21
-0+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; +/* guarantees that if the composer is enabled, a job will be queued */ +struct mutex enabled_lock; + +/* protected by @enabled_lock */ +bool composer_enabled; +struct vkms_crtc_state *composer_state; + +spinlock_t composer_lock; +}; +struct vkms_color_lut {struct drm_color_lut *base;size_t lut_length;
drivers/gpu/drm/vkms/vkms_drv.h struct vkms_crtc_state { · line 124
Quoted 3 lines
drivers/gpu/drm/vkms/vkms_drv.h +0
-0@@ -97,25 +122,14 @@ struct vkms_crtc_state { };struct vkms_output {
I think this structure doesn't make sense anymore. If I didn't misread then it's really only needed as a temporary structure during the default vkms_output_init code anymore, and for that case I think we should just completely delete it. Since vkms is now using drmm_ there's really not need to track all our kms objects again ourselves.
With that this patch essentially becomes "creat vkms_crtc" (which moves all the composer releated data from vkms_output to this new structure) and then maybe a 2nd patch which deletes the leftovers of vkms_output.
Quoted 11 lines
drivers/gpu/drm/vkms/vkms_drv.h +0
-11-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;
drivers/gpu/drm/vkms/vkms_drv.h struct vkms_crtc_state { · line 126
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_drv.h +2
-8-/* guarantees that if the composer is enabled, a job will be queued */ -struct mutex enabled_lock; - -/* protected by @enabled_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 ];
Uh can we please directly use the DRM limits here for these? I guess this is because you have static arrays, but vkms really shouldn't need it's own arrays to keep track of what drm already keeps track of.
Using DRM limits also means we can rely on the drm validation code instead of having to duplicate that code in the vkms configfs validation functions.
-Sima
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH v6 3/7] drm/vkms: Provide platform data when creating VKMS devices
In reply to Brandon PollackQuoted 7 lines · Brandon Pollack
From: Jim Shargo <[email protected]>
This is a small refactor to make ConfigFS support easier. This should be a no-op refactor.
Signed-off-by Jim Shargo <[email protected]>Signed-off-by Brandon Pollack <[email protected]>
This should be part of the series to switch over to a real platform driver, since we only need that with that design and not with the current setup/init code.
-Sima
Quoted 117 lines
--- drivers/gpu/drm/vkms/vkms_drv.c | 14 ++++++++++++-- drivers/gpu/drm/vkms/vkms_drv.h | 9 ++++++--- drivers/gpu/drm/vkms/vkms_output.c | 2 +- 3 files changed, 19 insertions(+), 6 deletions(-)drivers/gpu/drm/vkms/vkms_drv.c +12
-2@@ -9,6 +9,7 @@* the GPU in DRM API tests. */ +#include "asm-generic/errno-base.h" #include <linux/device.h> #include <linux/module.h> #include <linux/platform_device.h> @@ -171,12 +172,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) : + -EINVAL ; }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;@@ -195,6 +198,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 ));@@ -258,6 +262,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) {@@ -265,8 +272,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@@ -132,17 +132,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; };@@ -166,7 +169,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@@ -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.42.0.rc2.253.gd59a3bf2b4-goog
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH v6 4/7] drm/vkms: Add ConfigFS scaffolding to VKMS
In reply to Brandon PollackQuoted 26 lines · Brandon Pollack
From: Jim Shargo <[email protected]>
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 `-- enabledYou can then configure objects by mkdir'ing in each of the directories.
Quoted 7 lines
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.
Signed-off-by Jim Shargo <[email protected]>Signed-off-by Brandon Pollack <[email protected]>
A bunch of comments on locking/lifetime issues below, they should apply irrespective of whether we'll go with a split setup code or use struct vkms_config for configfs too.
Quoted 168 lines
--- Documentation/gpu/vkms.rst | 18 +- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/vkms_configfs.c | 650 +++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_drv.c | 56 ++- drivers/gpu/drm/vkms/vkms_drv.h | 92 +++- drivers/gpu/drm/vkms/vkms_output.c | 5 + 7 files changed, 806 insertions(+), 17 deletions(-) create mode 100644 drivers/gpu/drm/vkms/vkms_configfs.cDocumentation/gpu/vkms.rst +9
-9@@ -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,16 @@ project. Runtime Configuration --------------------- -We want to be able to reconfigure vkms instance without having to reload the -module. Use/Test-cases: +We want to be able to manipulate 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@@ -284,6 +284,7 @@ config DRM_VKMS depends on DRM && MMU select DRM_KMS_HELPER select DRM_GEM_SHMEM_HELPER + select CONFIGFS_FS select CRC32 default n helpdrivers/gpu/drm/vkms/Makefile +1
-0@@ -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 +85
-0@@ -0,0 +1,650 @@ +// 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. Note +* that the default device which can be enabled in the module params with:: +* +* modprobe vkms default_device=1 +* +* 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:: +* +* /config +* `-- vkms +* `-- test +* |-- connectors +* |-- crtcs +* |-- encoders +* |-- planes +* `-- enabled +* +* 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/crtcs/crtc +* mkdir /config/vkms/test/crtcs/crtc_other +* +* mkdir /config/vkms/test/encoders/encoder +* mkdir /config/vkms/test/encoders/encoder_other +* +* mkdir /config/vkms/test/connectors/connector +* mkdir /config/vkms/test/connectors/connector_other +* +* 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/encoders/encoder_other /config/vkms/test/connectors/connector_other/possible_encoders +* +* ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/primary/possible_crtcs/ +* ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/other_primary/possible_crtcs/ +* +* ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/encoders/encoder/possible_crtcs/ +* ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/encoders/encoder_other/possible_crtcs/
drivers/gpu/drm/vkms/vkms_configfs.c line 95
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_configfs.c new file +10
-0+* +* 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
So I'm not sure whether this is a bright idea, because it makes the lifetim fun even more fun. I think a cleaner approach would be if we only allow enabled to change once from 0 to 1, and once that's happened the only way to remove the driver/device is by deleting the entire configfs instance directory. You pretty much have that code here already.
Quoted 252 lines
drivers/gpu/drm/vkms/vkms_configfs.c new file +252
-0+* +* 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/encoders/encoder_other +* rmdir /config/vkms/test/connectors/connector +* rmdir /config/vkms/test/connectors/connector_other +* +* rmdir /config/vkms/test +*/ + +/* +* Common helpers (i.e. common sub-groups) +*/ + +/* Possible CRTCs, e.g. /config/vkms/device/<object>/possible_crtcs/<symlink> */ + +static struct config_item_type crtc_type; + +static int possible_crtcs_allow_link (struct config_item *src, +struct config_item *target) +{ +struct vkms_config_links *links =item_to_config_links (src); +struct vkms_config_crtc *crtc; + +if (target->ci_type != &crtc_type) { +DRM_ERROR ("Unable to link non-CRTCs.\n" ); +return -EINVAL ; + } + + crtc =item_to_config_crtc (target); + +if (links->linked_object_bitmap &BIT (crtc->crtc_config_idx)) { +DRM_ERROR ( +"Tried to add two symlinks to the same CRTC from the same object\n" ); +return -EINVAL ; + } + + links->linked_object_bitmap |=BIT (crtc->crtc_config_idx); + +return 0 ; +} + +static void possible_crtcs_drop_link (struct config_item *src, +struct config_item *target) +{ +struct vkms_config_links *links =item_to_config_links (src); +struct vkms_config_crtc *crtc =item_to_config_crtc (target); + + links->linked_object_bitmap &= ~BIT (crtc->crtc_config_idx); +} + +static struct configfs_item_operations possible_crtcs_item_ops = { + .allow_link = &possible_crtcs_allow_link, + .drop_link = &possible_crtcs_drop_link, +}; + +static struct config_item_type possible_crtcs_group_type = { + .ct_item_ops = &possible_crtcs_item_ops, + .ct_owner =THIS_MODULE , +}; + +static void add_possible_crtcs (struct config_group *parent, +struct config_group *possible_crtcs) +{ +config_group_init_type_name (possible_crtcs,"possible_crtcs" , + &possible_crtcs_group_type); +configfs_add_default_group (possible_crtcs, parent); +} + +/* Possible encoders, e.g. /config/vkms/device/connector/possible_encoders/<symlink> */ + +static struct config_item_type encoder_type; + +static int possible_encoders_allow_link (struct config_item *src, +struct config_item *target) +{ +struct vkms_config_links *links =item_to_config_links (src); +struct vkms_config_encoder *encoder; + +if (target->ci_type != &encoder_type) { +DRM_ERROR ("Unable to link non-encoders.\n" ); +return -EINVAL ; + } + + encoder =item_to_config_encoder (target); + +if (links->linked_object_bitmap &BIT (encoder->encoder_config_idx)) { +DRM_ERROR ( +"Tried to add two symlinks to the same encoder from the same object\n" ); +return -EINVAL ; + } + + links->linked_object_bitmap |=BIT (encoder->encoder_config_idx); + +return 0 ; +} + +static void possible_encoders_drop_link (struct config_item *src, +struct config_item *target) +{ +struct vkms_config_links *links =item_to_config_links (src); +struct vkms_config_encoder *encoder =item_to_config_encoder (target); + + links->linked_object_bitmap &= ~BIT (encoder->encoder_config_idx); +} + +static struct configfs_item_operations possible_encoders_item_ops = { + .allow_link = &possible_encoders_allow_link, + .drop_link = &possible_encoders_drop_link, +}; + +static struct config_item_type possible_encoders_group_type = { + .ct_item_ops = &possible_encoders_item_ops, + .ct_owner =THIS_MODULE , +}; + +static void add_possible_encoders (struct config_group *parent, +struct config_group *possible_encoders) +{ +config_group_init_type_name (possible_encoders,"possible_encoders" , + &possible_encoders_group_type); +configfs_add_default_group (possible_encoders, parent); +} + +/* +* Individual objects (connectors, crtcs, encoders, planes): +*/ + +/* Connector item, e.g. /config/vkms/device/connectors/ID */ + +static struct config_item_type connector_type = { + .ct_owner =THIS_MODULE , +}; + +/* Crtc item, e.g. /config/vkms/device/crtcs/ID */ + +static struct config_item_type crtc_type = { + .ct_owner =THIS_MODULE , +}; + +/* Encoder item, e.g. /config/vkms/device/encoder/ID */ + +static struct config_item_type encoder_type = { + .ct_owner =THIS_MODULE , +}; + +/* Plane item, e.g. /config/vkms/device/planes/ID */ + +static ssize_t plane_type_show (struct config_item *item,char *buf) +{ +struct vkms_config_plane *plane =item_to_config_plane (item); +struct vkms_configfs *configfs =plane_item_to_configfs (item); +enum drm_plane_type plane_type; + +mutex_lock (&configfs->lock); + plane_type = plane->type; +mutex_unlock (&configfs->lock); + +return sprintf (buf,"%u" , plane_type); +} + +static ssize_t plane_type_store (struct config_item *item,const char *buf, +size_t len) +{ +struct vkms_config_plane *plane =item_to_config_plane (item); +struct vkms_configfs *configfs =plane_item_to_configfs (item); +int val, ret; + + ret =kstrtouint (buf,10 , &val); +if (ret) +return ret; + +if (val !=DRM_PLANE_TYPE_PRIMARY && val !=DRM_PLANE_TYPE_CURSOR && + val !=DRM_PLANE_TYPE_OVERLAY ) +return -EINVAL ; + +mutex_lock (&configfs->lock); + plane->type = val; +mutex_unlock (&configfs->lock); + +return len; +} + +CONFIGFS_ATTR (plane_, type); + +static struct configfs_attribute *plane_attrs[] = { + &plane_attr_type, +NULL , +}; + +static struct config_item_type plane_type = { + .ct_attrs = plane_attrs, + .ct_owner =THIS_MODULE , +}; + +/* +* Directory groups, e.g. /config/vkms/device/{planes, crtcs, ...} +*/ + +/* Connectors group: /config/vkms/device/connectors/ */ + +static struct config_group *connectors_group_make (struct config_group *group, +const char *name) +{ +struct vkms_config_connector *connector = +kzalloc (sizeof (*connector),GFP_KERNEL ); +if (!connector) +return ERR_PTR (-ENOMEM ); + +config_group_init_type_name (&connector->config_group, name, + &connector_type); +add_possible_encoders (&connector->config_group, + &connector->possible_encoders.group); + +return &connector->config_group; +} + +static void connectors_group_drop (struct config_group *group, +struct config_item *item) +{ +struct vkms_config_connector *connector = +item_to_config_connector (item); +kfree (connector); +} + +static struct configfs_group_operations connectors_group_ops = { + .make_group = &connectors_group_make, + .drop_item = &connectors_group_drop, +}; + +static struct config_item_type connectors_group_type = { + .ct_group_ops = &connectors_group_ops, + .ct_owner =THIS_MODULE , +}; + +/* CRTCs group: /config/vkms/device/crtcs/ */ + +static struct config_group *crtcs_group_make (struct config_group *group, +const char *name)
drivers/gpu/drm/vkms/vkms_configfs.c line 357
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_configfs.c new file +10
-0+{ +struct vkms_configfs *configfs = + container_of(group, struct vkms_configfs, crtcs_group); +unsigned long next_idx; +struct vkms_config_crtc *crtc; + +mutex_lock (&configfs->lock); + + next_idx =find_first_zero_bit (&configfs->allocated_crtcs, +VKMS_MAX_OUTPUT_OBJECTS );
Uh I think it'd be best to use an xarray here like drm does, but I'm also not super sure we really need this. Can we not just walk all the links to check for duplicates when adding a new one instead?
Having our own tracking in vkms on top of the id allocation drm does already anyway is a bit iffy. Similar to how vkms duplicating the object book-keeping in its own arrays is also a bit awkward, just more potential for bugs if the book-keeping diverges.
Quoted 349 lines
drivers/gpu/drm/vkms/vkms_configfs.c new file +293
-0+ +if (next_idx ==VKMS_MAX_OUTPUT_OBJECTS ) { +DRM_ERROR ("Unable to allocate another CRTC.\n" ); +mutex_unlock (&configfs->lock); +return ERR_PTR (-ENOMEM ); + } + + crtc =kzalloc (sizeof (*crtc),GFP_KERNEL ); +if (!crtc) { +DRM_ERROR ("Unable to allocate CRTC.\n" ); +mutex_unlock (&configfs->lock); +return ERR_PTR (-ENOMEM ); + } + +config_group_init_type_name (&crtc->config_group, name, &crtc_type); + crtc->crtc_config_idx = next_idx; + +set_bit (next_idx, &configfs->allocated_crtcs); + +mutex_unlock (&configfs->lock); + +return &crtc->config_group; +} + +static void crtcs_group_drop (struct config_group *group, +struct config_item *item) +{ +struct vkms_config_crtc *crtc =item_to_config_crtc (item); + +kfree (crtc); +} + +static struct configfs_group_operations crtcs_group_ops = { + .make_group = &crtcs_group_make, + .drop_item = &crtcs_group_drop, +}; + +static struct config_item_type crtcs_group_type = { + .ct_group_ops = &crtcs_group_ops, + .ct_owner =THIS_MODULE , +}; + +/* Encoders group: /config/vkms/device/encoders/ */ + +static struct config_group *encoders_group_make (struct config_group *group, +const char *name) +{ +struct vkms_configfs *configfs = + container_of(group, struct vkms_configfs, encoders_group); +unsigned long next_idx; +struct vkms_config_encoder *encoder; + +mutex_lock (&configfs->lock); + + next_idx =find_first_zero_bit (&configfs->allocated_encoders, +VKMS_MAX_OUTPUT_OBJECTS ); + +if (next_idx ==VKMS_MAX_OUTPUT_OBJECTS ) { +DRM_ERROR ("Unable to allocate another encoder.\n" ); +mutex_unlock (&configfs->lock); +return ERR_PTR (-ENOMEM ); + } + + encoder =kzalloc (sizeof (*encoder),GFP_KERNEL ); +if (!encoder) { +DRM_ERROR ("Unable to allocate encoder.\n" ); +mutex_unlock (&configfs->lock); +return ERR_PTR (-ENOMEM ); + } + +config_group_init_type_name (&encoder->config_group, name, + &encoder_type); +add_possible_crtcs (&encoder->config_group, + &encoder->possible_crtcs.group); + encoder->encoder_config_idx = next_idx; +set_bit (next_idx, &configfs->allocated_encoders); + +mutex_unlock (&configfs->lock); + +return &encoder->config_group; +} + +static void encoders_group_drop (struct config_group *group, +struct config_item *item) +{ +struct vkms_config_encoder *encoder =item_to_config_encoder (item); + +kfree (encoder); +} + +static struct configfs_group_operations encoders_group_ops = { + .make_group = &encoders_group_make, + .drop_item = &encoders_group_drop, +}; + +static struct config_item_type encoders_group_type = { + .ct_group_ops = &encoders_group_ops, + .ct_owner =THIS_MODULE , +}; + +/* Planes group: /config/vkms/device/planes/ */ + +static struct config_group *make_plane_group (struct config_group *group, +const char *name) +{ +struct vkms_config_plane *plane =kzalloc (sizeof (*plane),GFP_KERNEL ); + +if (!plane) +return ERR_PTR (-ENOMEM ); + +config_group_init_type_name (&plane->config_group, name, &plane_type); +add_possible_crtcs (&plane->config_group, &plane->possible_crtcs.group); + +return &plane->config_group; +} + +static void drop_plane_group (struct config_group *group, +struct config_item *item) +{ +struct vkms_config_plane *plane =item_to_config_plane (item); + +kfree (plane); +} + +static struct configfs_group_operations plane_group_ops = { + .make_group = &make_plane_group, + .drop_item = &drop_plane_group, +}; + +static struct config_item_type planes_group_type = { + .ct_group_ops = &plane_group_ops, + .ct_owner =THIS_MODULE , +}; + +/* Root directory group, e.g. /config/vkms/device */ + +static ssize_t device_enabled_show (struct config_item *item,char *buf) +{ +struct vkms_configfs *configfs =item_to_configfs (item); +bool is_enabled; + +mutex_lock (&configfs->lock); + is_enabled = configfs->vkms_device !=NULL ; +mutex_unlock (&configfs->lock); + +return sprintf (buf,"%d" , is_enabled); +} + +static ssize_t device_enabled_store (struct config_item *item,const char *buf, +size_t len) +{ +struct vkms_configfs *configfs =item_to_configfs (item); +struct vkms_device *device; +int value, ret; + + ret =kstrtoint (buf,0 , &value); +if (ret) +return ret; + +if (value !=1 ) +return -EINVAL ; + +mutex_lock (&configfs->lock); + +if (configfs->vkms_device) { +mutex_unlock (&configfs->lock); +return len; + } + + device =vkms_add_device (configfs); +mutex_unlock (&configfs->lock); + +if (IS_ERR (device)) +return -PTR_ERR (device); + +return len; +} + +CONFIGFS_ATTR (device_, enabled); + +static ssize_t device_id_show (struct config_item *item,char *buf) +{ +struct vkms_configfs *configfs =item_to_configfs (item); +int id =-1 ; + +mutex_lock (&configfs->lock); +if (configfs->vkms_device) + id = configfs->vkms_device->platform->id; + +mutex_unlock (&configfs->lock); + +return sprintf (buf,"%d" , id); +} + +CONFIGFS_ATTR_RO (device_, id); + +static struct configfs_attribute *device_group_attrs[] = { + &device_attr_id, + &device_attr_enabled, +NULL , +}; + +static struct config_item_type device_group_type = { + .ct_attrs = device_group_attrs, + .ct_owner =THIS_MODULE , +}; + +static void vkms_configfs_setup_default_groups (struct vkms_configfs *configfs, +const char *name) +{ +config_group_init_type_name (&configfs->device_group, name, + &device_group_type); + +config_group_init_type_name (&configfs->connectors_group,"connectors" , + &connectors_group_type); +configfs_add_default_group (&configfs->connectors_group, + &configfs->device_group); + +config_group_init_type_name (&configfs->crtcs_group,"crtcs" , + &crtcs_group_type); +configfs_add_default_group (&configfs->crtcs_group, + &configfs->device_group); + +config_group_init_type_name (&configfs->encoders_group,"encoders" , + &encoders_group_type); +configfs_add_default_group (&configfs->encoders_group, + &configfs->device_group); + +config_group_init_type_name (&configfs->planes_group,"planes" , + &planes_group_type); +configfs_add_default_group (&configfs->planes_group, + &configfs->device_group); +} + +/* Root directory group and subsystem, e.g. /config/vkms/ */ + +static struct config_group *make_root_group (struct config_group *group, +const char *name) +{ +struct vkms_configfs *configfs =kzalloc (sizeof (*configfs),GFP_KERNEL ); + +if (!configfs) +return ERR_PTR (-ENOMEM ); + +vkms_configfs_setup_default_groups (configfs, name); +mutex_init (&configfs->lock); + +return &configfs->device_group; +} + +static void drop_root_group (struct config_group *group, +struct config_item *item) +{ +struct vkms_configfs *configfs =item_to_configfs (item); + +mutex_lock (&configfs->lock); +if (configfs->vkms_device) +vkms_remove_device (configfs->vkms_device); +mutex_unlock (&configfs->lock); + +kfree (configfs); +} + +static struct configfs_group_operations root_group_ops = { + .make_group = &make_root_group, + .drop_item = &drop_root_group, +}; + +static struct config_item_type vkms_type = { + .ct_group_ops = &root_group_ops, + .ct_owner =THIS_MODULE , +}; + +static struct configfs_subsystem vkms_subsys = { + .su_group = { + .cg_item = { + .ci_name ="vkms" , + .ci_type = &vkms_type, + }, + }, + .su_mutex =__MUTEX_INITIALIZER (vkms_subsys.su_mutex), +}; + +int vkms_init_configfs (void ) +{ +config_group_init (&vkms_subsys.su_group); +return configfs_register_subsystem (&vkms_subsys); +} + +void vkms_unregister_configfs (void ) +{ +configfs_unregister_subsystem (&vkms_subsys); +}drivers/gpu/drm/vkms/vkms_drv.c +13
-5@@ -9,8 +9,10 @@* the GPU in DRM API tests. */ -#include "asm-generic/errno-base.h" +#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> @@ -172,8 +174,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) : - -EINVAL ; +return vkmsdev->configfs ?vkms_output_init (vkmsdev) : +vkms_output_init_default (vkmsdev); }static int vkms_platform_probe (struct platform_device *pdev)@@ -184,8 +186,10 @@ static int vkms_platform_probe(struct platform_device *pdev)void *grp; grp =devres_open_group (&pdev->dev,NULL ,GFP_KERNEL ); -if (!grp) +if (!grp) { +DRM_ERROR ("Could not open devres group\n" );return -ENOMEM ; + } vkms_device =devm_drm_dev_alloc (&pdev->dev, &vkms_driver, struct vkms_device, drm);@@ -198,7 +202,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 ));@@ -258,12 +262,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;
drivers/gpu/drm/vkms/vkms_drv.c static struct platform_driver vkms_platform_driver = { · line 278
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_drv.c +10
-0+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); + }
Uh this is both a layering violation (digging around in platform internals) and doesn't have enough locking. I think much better if we just have our own xarray for allocating these. For locking we should be able to reuse the confifgfs_subsystem.su_mutex, so just needs another configfs_assert_subsystem_locked instead.
Quoted 5 lines
drivers/gpu/drm/vkms/vkms_drv.c +5
-0+ + pdev =platform_device_register_data (NULL ,DRIVER_NAME , max_id +1 , + &vkms_device_setup, +sizeof (vkms_device_setup)); +if (IS_ERR (pdev)) {
drivers/gpu/drm/vkms/vkms_drv.c static struct platform_driver vkms_platform_driver = { · line 293
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_drv.c +10
-0+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);
We must nuke the platform_data here, because after this point there's nothing guaranteeing that the configfs pointers will survive. -Sima
Quoted 93 lines
drivers/gpu/drm/vkms/vkms_drv.c +12
-1+} +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);@@ -281,6 +316,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 ; }@@ -288,6 +330,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 +36
-0@@ -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@@ -138,14 +140,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/ */
drivers/gpu/drm/vkms/vkms_drv.h struct vkms_config { · line 186
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_drv.h +10
-0+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;
So this doesn't work, because it doesn't protect against against concurent add/removal of items to groups and other changes. Instead we need to rely on configfs_subsystem.su_mutex. To make this work cleanly I think we should do the following:
- Add a configfs_assert_subsystem_locked wrapped to configfs.h, so that we have a nicely abstracted lockdep check using lockdep_assert_held.
Than use that locking assert everywhere you currently have a mutex_lock(vkms_configfs->lock). Note that you have quiet a few missing places (since really everything we do needs that lock), I'd focus on adding it to important helper functions like the xarray wrappers for allocating ids (if we do those).
- Then for walking the various lists (both here and in the next patch) we should also add proper wrapper macros to configfs.h, which both do the right upcasting and also have the lockdep assert.
Quoted 88 lines
drivers/gpu/drm/vkms/vkms_drv.h +44
-2+ +/* 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; };@@ -164,11 +217,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,@@ -191,4 +275,8 @@ void vkms_writeback_row(struct vkms_writeback_job *wb, const struct line_bufferint 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@@ -176,3 +176,8 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)return ret; } + +int vkms_output_init (struct vkms_device *vkmsdev) +{ +return -EOPNOTSUPP ; +}Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH v6 5/7] drm/vkms: Support enabling ConfigFS devices
In reply to Brandon PollackQuoted 250 lines · Brandon Pollack
From: Jim Shargo <[email protected]>
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.
Signed-off-by Jim Shargo <[email protected]>Signed-off-by Brandon Pollack <[email protected]>--- drivers/gpu/drm/vkms/vkms_configfs.c | 37 ++-- drivers/gpu/drm/vkms/vkms_crtc.c | 4 +- drivers/gpu/drm/vkms/vkms_drv.c | 1 + drivers/gpu/drm/vkms/vkms_drv.h | 4 +- drivers/gpu/drm/vkms/vkms_output.c | 282 +++++++++++++++++++++++---- drivers/gpu/drm/vkms/vkms_plane.c | 10 +- 6 files changed, 282 insertions(+), 56 deletions(-)drivers/gpu/drm/vkms/vkms_configfs.c +24
-13@@ -508,29 +508,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@@ -279,7 +279,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;@@ -291,7 +291,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 +1
-0@@ -275,6 +275,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 +2
-2@@ -250,13 +250,13 @@ 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);struct vkms_plane *vkms_plane_init (struct vkms_device *vkmsdev, -enum drm_plane_type type); +enum drm_plane_type type,char * name, ...);/* CRC Support */ const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,drivers/gpu/drm/vkms/vkms_output.c +23
-24@@ -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> @@ -60,7 +62,8 @@ vkms_connector_init(struct vkms_device *vkms_device)return connector; } -static struct drm_encoder *vkms_encoder_init (struct vkms_device *vkms_device) +static struct drm_encoder *vkms_encoder_init (struct vkms_device *vkms_device, +char *name) {struct drm_encoder *encoder;int ret;@@ -71,7 +74,7 @@ static struct drm_encoder *vkms_encoder_init(struct vkms_device *vkms_device) 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 ); +DRM_MODE_ENCODER_VIRTUAL , name);if (ret) {memset (encoder,0 ,sizeof (*encoder)); vkms_device->output.num_encoders -=1 ;@@ -82,7 +85,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;@@ -92,35 +94,34 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)int writeback;unsigned int n; - primary =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_PRIMARY ); + primary =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_PRIMARY , +"default-primary-plane" );if (IS_ERR (primary))return PTR_ERR (primary);if (vkmsdev->config.overlay) {for (n =0 ; n <NUM_OVERLAY_PLANES ; n++) { -struct vkms_plane *overlay =vkms_plane_init ( - vkmsdev,DRM_PLANE_TYPE_OVERLAY ); -if (IS_ERR (overlay)) { - ret =PTR_ERR (overlay); - goto err_planes; - } +struct vkms_plane *overlay = +vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_OVERLAY , +"default-overlay-plane-%d" , n); +if (IS_ERR (overlay)) +return PTR_ERR (overlay); } }if (vkmsdev->config.cursor) { - cursor =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_CURSOR ); -if (IS_ERR (cursor)) { - ret =PTR_ERR (cursor); - goto err_planes; - } + cursor =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_CURSOR , +"default-cursor-plane" ); +if (IS_ERR (cursor)) +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 +132,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); + encoder =vkms_encoder_init (vkmsdev,"encoder-default" );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) {
drivers/gpu/drm/vkms/vkms_output.c int vkms_output_init_default(struct vkms_device *vkmsdev) · line 166
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_output.c +1
-5@@ -158,26 +157,235 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)drm_mode_config_reset (dev);return 0 ; +} -err_attach: -drm_encoder_cleanup (encoder); - -err_encoder: -drm_connector_cleanup (connector);
Removing the calls to drm_*_cleanup here is a bugfix for Maíra's patches to switch over to drmm_. Please split these fixes out, properly reference the commit that introduced the issue so that we can merge that through -fixes and cc: stable.
Quoted 9 lines
drivers/gpu/drm/vkms/vkms_output.c +6
-2+static bool is_object_linked (struct vkms_config_links *links,unsigned long idx) +{ +return links->linked_object_bitmap & (1 << idx); +} -err_connector: -drm_crtc_cleanup (&vkms_crtc->base); +/** +* validate_vkms_configfs_no_dangling_objects - warn on unused objects in vkms
drivers/gpu/drm/vkms/vkms_output.c int vkms_output_init_default(struct vkms_device *vkmsdev) · line 178
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_output.c +10
-0+* configfs. +* @vkmsdev: vkms device +* +* This gives slightly more visible warning messaging to the user before the drm +* system finds the configuration invalid and prints it's debug information. In +* this case the user may have accidentally not included some links, or the user +* could be testing this faulty configuration. +*/ +static void +validate_vkms_configfs_no_dangling_objects (struct vkms_device *vkmsdev)
Please no separate vkms_configfs validation. Instead we should improve the drm checks as much as needed. If the issue is that the error output aren't meaningful enough, then I think vkms configfs code should drop some drm log lines that connect the configfs item names to the drm names every time we either create a kms object or when we add a link to a mask.
This way drivers overall will benefit from improved validation, not just vkms.
Quoted 44 lines
drivers/gpu/drm/vkms/vkms_output.c +37
-4+{ +struct vkms_configfs *configfs = vkmsdev->configfs; +struct config_item *item; + +// 1. Planes +list_for_each_entry (item, &configfs->planes_group.cg_children, + ci_entry) { +struct vkms_config_plane *config_plane = +item_to_config_plane (item); +if (config_plane->possible_crtcs.linked_object_bitmap ==0 ) +DRM_WARN ( +"Vkms configfs created plane %s has no linked crtcs" , + item->ci_name); + } -err_planes: -for (int i =0 ; i < output->num_planes; i++) -drm_plane_cleanup (&output->planes[i].base); +// 2. connectors +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->possible_encoders.linked_object_bitmap == +0 ) { +DRM_WARN ( +"Vkms configfs created connector %s has no linked encoders" , + item->ci_name); + } + } -memset (output,0 ,sizeof (*output)); +// 3. encoders +list_for_each_entry (item, &configfs->encoders_group.cg_children, + ci_entry) { +struct vkms_config_encoder *config_encoder = +item_to_config_encoder (item); +if (config_encoder->possible_crtcs.linked_object_bitmap ==0 ) { +DRM_WARN ( +"Vkms configfs created encoder %s has no linked crtcs" , + item->ci_name); + } + }
drivers/gpu/drm/vkms/vkms_output.c int vkms_output_init_default(struct vkms_device *vkmsdev) · line 226
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_output.c +4
-2-return ret; +// 4. crtcs only require a primary plane to function, this is checked during +// output initialization and returns an error. }int vkms_output_init (struct vkms_device *vkmsdev) { -return -EOPNOTSUPP ; +struct drm_device *dev = &vkmsdev->drm; +struct vkms_configfs *configfs = vkmsdev->configfs;
Just dropping there here again, I think it'd be cleaner to explicitly pass the configfs pointer around since it's not guaranteed to outlive struct vkms_device. And we must not ever store it in there.
Cheers, Sima
Quoted 142 lines
drivers/gpu/drm/vkms/vkms_output.c +142
-0+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 ; + +// Ensure configfs has no unused objects, and warn if so. +validate_vkms_configfs_no_dangling_objects (vkmsdev); + +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, item->ci_name); + +if (IS_ERR (plane)) { +DRM_ERROR ("Unable to init plane from config: %s" , + item->ci_name); +return PTR_ERR (plane); + } + + plane_map[map_idx].config_plane = config_plane; + plane_map[map_idx].plane = plane; + map_idx +=1 ; + } + + 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, item->ci_name); + +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; + encoder_map[map_idx].encoder = encoder; + map_idx +=1 ; + } + +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); + +if (IS_ERR (connector)) { +DRM_ERROR ("Failed to init connector from config: %s" , + item->ci_name); +return PTR_ERR (connector); + } + +for (int j =0 ; j < output->num_encoders; j++) { +struct encoder_map *encoder = &encoder_map[j]; + +if (is_object_linked ( + &config_connector->possible_encoders, + encoder->config_encoder + ->encoder_config_idx)) { +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];
drivers/gpu/drm/vkms/vkms_output.c int vkms_output_init_default(struct vkms_device *vkmsdev) · line 378
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_output.c +10
-0+ +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); + } + } + +if (vkmsdev->config.writeback) {
This mixes the default setup code (that uses vkms_config) with the configfs paths, which I think is really not a good idea. This is why I think we should have a very strict split here. Alternatively if we go with using struct vkms_config for configfs too, then I think we must not use the module options to fill in the missing parameters that configfs does not yet support.
The reason is that configfs is uapi (yay!), so if we make a mess here just because it's easier to get things going, we'll bake that mess in forever. Instead I think it'd be best if we just disable writeback support for the initial configfs work.
For properly enabling writeback I think we need a new configfs group for just writeback connectors, since those are fairly special (like you cannot ever hotplug them, they're always there).
Quoted 56 lines
drivers/gpu/drm/vkms/vkms_output.c +12
-0+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); + } + } + +drm_mode_config_reset (dev); + +return 0 ; }drivers/gpu/drm/vkms/vkms_plane.c +8
-2@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0+ #include <linux/iosys-map.h> +#include <linux/stdarg.h> #include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> @@ -215,20 +216,25 @@ 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) +enum drm_plane_type type,char *name, ...) {struct drm_device *dev = &vkmsdev->drm;struct vkms_output *output = &vkmsdev->output;struct vkms_plane *plane; +va_list va;int ret;if (output->num_planes >=VKMS_MAX_PLANES )return ERR_PTR (-ENOMEM ); plane = &output->planes[output->num_planes++]; + +va_start (va, name); ret =drm_universal_plane_init (dev, &plane->base,0 , &vkms_plane_funcs, vkms_formats,ARRAY_SIZE (vkms_formats), -NULL , type,NULL ); +NULL , type, name, va); +va_end (va); +if (ret)return ERR_PTR (ret);Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH v6 7/7] drm/vkms Add hotplug support via configfs to VKMS.
In reply to Brandon PollackQuoted 52 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).
Signed-off-by Brandon Pollack <[email protected]>--- Documentation/gpu/vkms.rst | 2 +- drivers/gpu/drm/vkms/vkms_configfs.c | 68 ++++++++++++++++++++++++++-- drivers/gpu/drm/vkms/vkms_drv.h | 11 +++++ drivers/gpu/drm/vkms/vkms_output.c | 47 ++++++++++++++++++- 4 files changed, 123 insertions(+), 5 deletions(-)Documentation/gpu/vkms.rst +1
-1@@ -145,7 +145,7 @@ We want to be able to manipulate 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 changingdrivers/gpu/drm/vkms/vkms_configfs.c +2
-0@@ -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> @@ -40,6 +41,7 @@* `-- vkms * `-- test * |-- connectors +* `-- connected * |-- crtcs * |-- encoders * |-- planes
drivers/gpu/drm/vkms/vkms_configfs.c line 97
Quoted 7 lines
drivers/gpu/drm/vkms/vkms_configfs.c +4
-0@@ -89,6 +91,14 @@* * 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
I think it'd be really good if we allow all connector status values, including unknown. It's not very common, which is why most compositors utterly fail at handling it in a reasonable way.
Quoted 40 lines
drivers/gpu/drm/vkms/vkms_configfs.c +33
-0+* +* One can verify that this is worked using the `modetest` utility or the +* equivalent for your platform. +* * When you're done with the virtual device, you can clean up the device like * so:: * @@ -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) +return ret; + +if (val !=1 && val !=0 ) +return -EINVAL ; +
drivers/gpu/drm/vkms/vkms_configfs.c static void add_possible_encoders(struct config_group *parent, · line 287
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_configfs.c +10
-0+mutex_lock (&configfs->lock); + connector->connected = val; +if (!connector->connector) { +pr_info ("VKMS Device %s is not yet enabled, connector will be enabled on start" , + configfs->device_group.cg_item.ci_name); + } +mutex_unlock (&configfs->lock); + +if (connector->connector) +drm_kms_helper_hotplug_event (connector->connector->dev);
Ok a few lifetime bugs here:
- Calling drm_kms_helper_hotplug_event after you unluck means all the drm stuff might have disappeared meanwhile. Oops.
- It is worse, because switching to configfs_subsystem.su_mutex will not prevent the race, because the vkms_device can disappear independently (by manually unbinding the driver in sysfs) at least with the real platform driver approach. This is another reason why I'm not sure having a real platform driver with probe/remove hooks is a good idea.
- Furthermore the drm_connector might also disappear.
I think the way to properly fix this is:
- configfs needs to hold a reference of it's on to the drm_device in vkms_device.
- it needs to call a vkms function to update the connector hotplug status with only the configfs obj idx. That function then needs to find the right drm_connector using the drm_connector_iter functions (which will sort out any lifetime/locking issues) until is has the right one, and then update the connector status.
No matter what, we cannot have a backpointer from any drm object to configfs, that doesn't work correctly.
-Sima
Quoted 183 lines
drivers/gpu/drm/vkms/vkms_configfs.c +16
-3+ +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; }@@ -500,7 +562,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,@@ -557,7 +619,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@@ -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> @@ -147,7 +148,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 {@@ -220,6 +223,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)@@ -279,4 +286,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@@ -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, };@@ -280,12 +325,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_encoders; j++) {struct encoder_map *encoder = &encoder_map[j];Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Re: [PATCH v6 5/7] drm/vkms: Support enabling ConfigFS devices
In reply to Brandon PollackQuoted 6 lines · Brandon Pollack
From: Jim Shargo <[email protected]>
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.
I forgot one comment ... I tried to look around really hard, but I'm not seeing any code which prevents changes to immutable state once the device is created?
Note that if we go with the design where you can only change enabled from 0 to 1 once it really doesn't matter much whether we block changes afterwards, since they do not have any impact at all. But it would still be nice, since for connector hotplug support we must make sure that the encoders and all that stay around as-is.
Otoh there's no way to prevent dropping a config_item, so maybe we just have to life with the fact that configfs is a lot more mutable than the underlying drm objects. In that case I'd much prefer we switch over to the model where you can only enable a configfs device instance once, otherwise it's really confusing.
-Sima
Quoted 535 lines
Signed-off-by Jim Shargo <[email protected]>Signed-off-by Brandon Pollack <[email protected]>--- drivers/gpu/drm/vkms/vkms_configfs.c | 37 ++-- drivers/gpu/drm/vkms/vkms_crtc.c | 4 +- drivers/gpu/drm/vkms/vkms_drv.c | 1 + drivers/gpu/drm/vkms/vkms_drv.h | 4 +- drivers/gpu/drm/vkms/vkms_output.c | 282 +++++++++++++++++++++++---- drivers/gpu/drm/vkms/vkms_plane.c | 10 +- 6 files changed, 282 insertions(+), 56 deletions(-)drivers/gpu/drm/vkms/vkms_configfs.c +24
-13@@ -508,29 +508,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@@ -279,7 +279,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;@@ -291,7 +291,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 +1
-0@@ -275,6 +275,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 +2
-2@@ -250,13 +250,13 @@ 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);struct vkms_plane *vkms_plane_init (struct vkms_device *vkmsdev, -enum drm_plane_type type); +enum drm_plane_type type,char * name, ...);/* CRC Support */ const char *const *vkms_get_crc_sources(struct drm_crtc *crtc,drivers/gpu/drm/vkms/vkms_output.c +245
-37@@ -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> @@ -60,7 +62,8 @@ vkms_connector_init(struct vkms_device *vkms_device)return connector; } -static struct drm_encoder *vkms_encoder_init (struct vkms_device *vkms_device) +static struct drm_encoder *vkms_encoder_init (struct vkms_device *vkms_device, +char *name) {struct drm_encoder *encoder;int ret;@@ -71,7 +74,7 @@ static struct drm_encoder *vkms_encoder_init(struct vkms_device *vkms_device) 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 ); +DRM_MODE_ENCODER_VIRTUAL , name);if (ret) {memset (encoder,0 ,sizeof (*encoder)); vkms_device->output.num_encoders -=1 ;@@ -82,7 +85,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;@@ -92,35 +94,34 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)int writeback;unsigned int n; - primary =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_PRIMARY ); + primary =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_PRIMARY , +"default-primary-plane" );if (IS_ERR (primary))return PTR_ERR (primary);if (vkmsdev->config.overlay) {for (n =0 ; n <NUM_OVERLAY_PLANES ; n++) { -struct vkms_plane *overlay =vkms_plane_init ( - vkmsdev,DRM_PLANE_TYPE_OVERLAY ); -if (IS_ERR (overlay)) { - ret =PTR_ERR (overlay); - goto err_planes; - } +struct vkms_plane *overlay = +vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_OVERLAY , +"default-overlay-plane-%d" , n); +if (IS_ERR (overlay)) +return PTR_ERR (overlay); } }if (vkmsdev->config.cursor) { - cursor =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_CURSOR ); -if (IS_ERR (cursor)) { - ret =PTR_ERR (cursor); - goto err_planes; - } + cursor =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_CURSOR , +"default-cursor-plane" ); +if (IS_ERR (cursor)) +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 +132,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); + encoder =vkms_encoder_init (vkmsdev,"encoder-default" );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,26 +157,235 @@ int vkms_output_init_default(struct vkms_device *vkmsdev)drm_mode_config_reset (dev);return 0 ; +} -err_attach: -drm_encoder_cleanup (encoder); - -err_encoder: -drm_connector_cleanup (connector); +static bool is_object_linked (struct vkms_config_links *links,unsigned long idx) +{ +return links->linked_object_bitmap & (1 << idx); +} -err_connector: -drm_crtc_cleanup (&vkms_crtc->base); +/** +* validate_vkms_configfs_no_dangling_objects - warn on unused objects in vkms +* configfs. +* @vkmsdev: vkms device +* +* This gives slightly more visible warning messaging to the user before the drm +* system finds the configuration invalid and prints it's debug information. In +* this case the user may have accidentally not included some links, or the user +* could be testing this faulty configuration. +*/ +static void +validate_vkms_configfs_no_dangling_objects (struct vkms_device *vkmsdev) +{ +struct vkms_configfs *configfs = vkmsdev->configfs; +struct config_item *item; + +// 1. Planes +list_for_each_entry (item, &configfs->planes_group.cg_children, + ci_entry) { +struct vkms_config_plane *config_plane = +item_to_config_plane (item); +if (config_plane->possible_crtcs.linked_object_bitmap ==0 ) +DRM_WARN ( +"Vkms configfs created plane %s has no linked crtcs" , + item->ci_name); + } -err_planes: -for (int i =0 ; i < output->num_planes; i++) -drm_plane_cleanup (&output->planes[i].base); +// 2. connectors +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->possible_encoders.linked_object_bitmap == +0 ) { +DRM_WARN ( +"Vkms configfs created connector %s has no linked encoders" , + item->ci_name); + } + } -memset (output,0 ,sizeof (*output)); +// 3. encoders +list_for_each_entry (item, &configfs->encoders_group.cg_children, + ci_entry) { +struct vkms_config_encoder *config_encoder = +item_to_config_encoder (item); +if (config_encoder->possible_crtcs.linked_object_bitmap ==0 ) { +DRM_WARN ( +"Vkms configfs created encoder %s has no linked crtcs" , + item->ci_name); + } + } -return ret; +// 4. crtcs only require a primary plane to function, this is checked during +// output initialization and returns an error. }int vkms_output_init (struct vkms_device *vkmsdev) { -return -EOPNOTSUPP ; +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 ; + +// Ensure configfs has no unused objects, and warn if so. +validate_vkms_configfs_no_dangling_objects (vkmsdev); + +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, item->ci_name); + +if (IS_ERR (plane)) { +DRM_ERROR ("Unable to init plane from config: %s" , + item->ci_name); +return PTR_ERR (plane); + } + + plane_map[map_idx].config_plane = config_plane; + plane_map[map_idx].plane = plane; + map_idx +=1 ; + } + + 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, item->ci_name); + +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; + encoder_map[map_idx].encoder = encoder; + map_idx +=1 ; + } + +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); + +if (IS_ERR (connector)) { +DRM_ERROR ("Failed to init connector from config: %s" , + item->ci_name); +return PTR_ERR (connector); + } + +for (int j =0 ; j < output->num_encoders; j++) { +struct encoder_map *encoder = &encoder_map[j]; + +if (is_object_linked ( + &config_connector->possible_encoders, + encoder->config_encoder + ->encoder_config_idx)) { +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); + } + } + +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); + } + } + +drm_mode_config_reset (dev); + +return 0 ; }drivers/gpu/drm/vkms/vkms_plane.c +8
-2@@ -1,6 +1,7 @@// SPDX-License-Identifier: GPL-2.0+ #include <linux/iosys-map.h> +#include <linux/stdarg.h> #include <drm/drm_atomic.h> #include <drm/drm_atomic_helper.h> @@ -215,20 +216,25 @@ 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) +enum drm_plane_type type,char *name, ...) {struct drm_device *dev = &vkmsdev->drm;struct vkms_output *output = &vkmsdev->output;struct vkms_plane *plane; +va_list va;int ret;if (output->num_planes >=VKMS_MAX_PLANES )return ERR_PTR (-ENOMEM ); plane = &output->planes[output->num_planes++]; + +va_start (va, name); ret =drm_universal_plane_init (dev, &plane->base,0 , &vkms_plane_funcs, vkms_formats,ARRAY_SIZE (vkms_formats), -NULL , type,NULL ); +NULL , type, name, va); +va_end (va); +if (ret)return ERR_PTR (ret);Signature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 45 lines · Brandon Pollack
Since Jim is busy with other work and I'm working on some things that rely on this, I've taken up the task of doing the iterations. I've addressed the comments as best I can (those replies are to each individual change) and here is the patch set to go with those.
I added my own signoff to each commit, but I've left jshargo@ as the author of all the commits he wrote. I'm sure there is still more to address and the ICT tests that were writtein parallel to this may also need some additions, but I'm hoping we're in a good enough state to get this in and iterate from there soon.
Since V6:
========
rmdirs for documentation examples
fix crtc mask for writebacksSince V5:
========
Fixed some bad merge conflicts and locking behaviours as well as clarified some documentation, should be good to go now :)Since V4:
========
Fixed up some documentation as suggested by Marius
Fixed up some bad locking as suggested by Marius
Small fixes here and there (most have email responses to previous chain emails)Since V3:
========
I've added hotplug support in the latest patch. This has been reviewed some and the notes from that review are addressed here as well.Relevant/Utilizing work:
=======================
I've built a while test framework based on this as proof it functions (though I'm sure there may be lingering bugs!). You can check that out on crrev.com if you are interested and need to get started yourself (but be aware of any licensing that may differ from the kernel itself! Make sure you understand the license:https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/platform/tast-tests/LICENSE
That said, you can see the changes in review on the crrev gerrit:
Quoted 7 lines
https://chromium-review.googlesource.com/c/chromiumos/platform/tast-tests/+/4666669
Outro:
=====
I really appreciate everyone's input and tolerance in getting these changes in. Jim's first patch series was this, and other than some small cleanups and documentation, taking over it is also mine.
Sorry for not having looked at this earlier. I think overall it's looking good, mostly just a bunch of comments on lifetime/locking questions.
I'm also wondering a bit how much we want to go overboard with igt tests, since the lifetime fun is quite big here. I think at least some basic tests that trying to do nasty things like unbind the driver in sysfs and then try to use configfs, or keeping the vkms_device alive with an open fd and removing the configfs directory would be really good.
One thing that's a bit tricky is that configfs is considered uapi, so must be stable forever. And I think that's actually the right thing for us, since we want compositors and other projects to use this for their testing. So unlike igt tests using special debugfs interfaces, which are ok to be very tightly coupled to kernel releases
Cheers, Sima
Quoted 32 lines
Thank you everyone :)
Brandon Pollack (1):
drm/vkms Add hotplug support via configfs to VKMS.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 deviceDocumentation/gpu/vkms.rst | 20 +- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/vkms_composer.c | 30 +- drivers/gpu/drm/vkms/vkms_configfs.c | 723 ++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_crtc.c | 102 ++-- drivers/gpu/drm/vkms/vkms_drv.c | 206 +++++--- drivers/gpu/drm/vkms/vkms_drv.h | 182 +++++-- drivers/gpu/drm/vkms/vkms_output.c | 404 ++++++++++++-- drivers/gpu/drm/vkms/vkms_plane.c | 44 +- drivers/gpu/drm/vkms/vkms_writeback.c | 42 +- 11 files changed, 1514 insertions(+), 241 deletions(-) create mode 100644 drivers/gpu/drm/vkms/vkms_configfs.cSignature · 1 line
2.42.0.rc2.253.gd59a3bf2b4-goog
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Hi everyone,
I wasn't aware of these patches, but I'm really glad they are getting some attention, thanks a lot for your review Sima.
Given that it's been a while since the patches were emailed, I'm not sure if the original authors of the patches could implement your comments. If not, I can work on it. Please let me know.
I'm working on a Mutter feature that'd greatly benefit from this uapi and I'm sure other compositors would find it useful.
I'll start working on a new version in a few days if nobody else is already working on it.
Best wishes,
José Expósito
Sima--thanks SO MUCH for going through with everything leaving a detailed review. I am excited to go through your feedback.
It makes me extremely happy to see these patches get people excited.
They've bounced between a few people, and I recently asked to take them over again from the folks who were most recently looking at them but haven't since had capacity to revisit them. I'd love to contribute more but I am currently pretty swamped and I probably couldn't realistically make too much headway before the middle of June.
José--if you've got capacity and interest, I'd love to see this work get in! Thanks!! Please let me know your timeline and if you want to split anything up or have any questions, I'd love to help if possible. But most important to me is seeing the community benefit from the feature.
And (in case it got lost in the shuffle of all these patches) the IGT tests really make it much easier to develop this thing. Marius has posted the most recent patches:
https://lore.kernel.org/igt-dev/?q=configfs
Thanks!
-- Jim
Quoted 18 lines · José Expósito
Hi everyone,
I wasn't aware of these patches, but I'm really glad they are getting some attention, thanks a lot for your review Sima.
Given that it's been a while since the patches were emailed, I'm not sure if the original authors of the patches could implement your comments. If not, I can work on it. Please let me know.
I'm working on a Mutter feature that'd greatly benefit from this uapi and I'm sure other compositors would find it useful.
I'll start working on a new version in a few days if nobody else is already working on it.
Best wishes,
José Expósito
Louis Chauvet
maintainerQuoted 22 lines · Jim Shargo
Sima--thanks SO MUCH for going through with everything leaving a detailed review. I am excited to go through your feedback.
It makes me extremely happy to see these patches get people excited.
They've bounced between a few people, and I recently asked to take them over again from the folks who were most recently looking at them but haven't since had capacity to revisit them. I'd love to contribute more but I am currently pretty swamped and I probably couldn't realistically make too much headway before the middle of June.
José--if you've got capacity and interest, I'd love to see this work get in! Thanks!! Please let me know your timeline and if you want to split anything up or have any questions, I'd love to help if possible. But most important to me is seeing the community benefit from the feature.
And (in case it got lost in the shuffle of all these patches) the IGT tests really make it much easier to develop this thing. Marius has posted the most recent patches:
https://lore.kernel.org/igt-dev/?q=configfs
Quoted 24 lines
Thanks!
-- JimQuoted 18 lines · José Expósito
Hi everyone,
I wasn't aware of these patches, but I'm really glad they are getting some attention, thanks a lot for your review Sima.
Given that it's been a while since the patches were emailed, I'm not sure if the original authors of the patches could implement your comments. If not, I can work on it. Please let me know.
I'm working on a Mutter feature that'd greatly benefit from this uapi and I'm sure other compositors would find it useful.
I'll start working on a new version in a few days if nobody else is already working on it.
Best wishes,
José Expósito
Hi all!
Very nice to see other people working on this subject. As the series seemed inactive, I started two weeks ago to rebase it on top of [1]. I also started some work to use drmm_* helpers instead of using lists in vkms. I currently struggle with a deadlock during rmmod.
I need to clean my commits, but I can share a WIP version.
Maybe we can discuss a bit the comment from Daniel (split init between default/configfs, use or not a real platform device...)
For the split, I think the first solution (struct vkms_config) can be easier to understand and to implement, for two reasons:
- No need to distinguish between the "default" and the "configfs" devices in the VKMS "core". All is managed with only one struct vkms_config.
- Most of the lifetime issue should be gone. The only thing to synchronize is passing this vkms_config from ConfigFS to VKMS.
The drawback of this is that it can become difficult to do the "runtime" configuration (today only hotplug, but I plan to add more complex stuff like DP emulation, EDID selection, MST support...). Those configuration must be done "at runtime" and will require a strong synchronization with the vkms "core".
Maybe we can distinguish between the "creation" and the "runtime configuration", in two different configFS directory? Once a device is created, it is moved to the "enabled" directory and will have a different set of attribute (connection status, current EDID...)
For the platform driver part, it seems logic to me to use a "real" platform driver and a platform device for each pipeline, but I don't have the experience to tell if this is a good idea or not.
[1]: https://lore.kernel.org/dri-devel/[email protected]/
Thanks,
Louis Chauvet
Signature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 48 lines · Louis Chauvet
Quoted 22 lines · Jim Shargo
Sima--thanks SO MUCH for going through with everything leaving a detailed review. I am excited to go through your feedback.
It makes me extremely happy to see these patches get people excited.
They've bounced between a few people, and I recently asked to take them over again from the folks who were most recently looking at them but haven't since had capacity to revisit them. I'd love to contribute more but I am currently pretty swamped and I probably couldn't realistically make too much headway before the middle of June.
José--if you've got capacity and interest, I'd love to see this work get in! Thanks!! Please let me know your timeline and if you want to split anything up or have any questions, I'd love to help if possible. But most important to me is seeing the community benefit from the feature.
And (in case it got lost in the shuffle of all these patches) the IGT tests really make it much easier to develop this thing. Marius has posted the most recent patches:
https://lore.kernel.org/igt-dev/?q=configfsQuoted 24 lines
Thanks!
-- JimQuoted 18 lines · José Expósito
Hi everyone,
I wasn't aware of these patches, but I'm really glad they are getting some attention, thanks a lot for your review Sima.
Given that it's been a while since the patches were emailed, I'm not sure if the original authors of the patches could implement your comments. If not, I can work on it. Please let me know.
I'm working on a Mutter feature that'd greatly benefit from this uapi and I'm sure other compositors would find it useful.
I'll start working on a new version in a few days if nobody else is already working on it.
Best wishes,
José Expósito
Quoted 8 lines
Hi all!
Very nice to see other people working on this subject. As the series seemed inactive, I started two weeks ago to rebase it on top of [1]. I also started some work to use drmm_* helpers instead of using lists in vkms. I currently struggle with a deadlock during rmmod.
I need to clean my commits, but I can share a WIP version.
Hi Louis,
If you could share a RFC/WIP series it would be awesome!
Since you are already working on the kernel patches (and I guess IGT?), I'll start working on a libdrm high level API to interact with VKMS from user-space on top of your patches. I'll share a link as soon as I have a draft PR.
Quoted 9 lines
Maybe we can discuss a bit the comment from Daniel (split init between default/configfs, use or not a real platform device...)
For the split, I think the first solution (struct
vkms_config) can be easier to understand and to implement, for two reasons:
- No need to distinguish between the "default" and the "configfs" devices in the VKMS "core". All is managed with only one structvkms_config.
- Most of the lifetime issue should be gone. The only thing to synchronize is passing thisvkms_configfrom ConfigFS to VKMS.
I agree, this seems like the easiest solution.
Quoted 10 lines
The drawback of this is that it can become difficult to do the "runtime" configuration (today only hotplug, but I plan to add more complex stuff like DP emulation, EDID selection, MST support...). Those configuration must be done "at runtime" and will require a strong synchronization with the vkms "core".
Maybe we can distinguish between the "creation" and the "runtime configuration", in two different configFS directory? Once a device is created, it is moved to the "enabled" directory and will have a different set of attribute (connection status, current EDID...)
Once the device is enabled (i.e, echo 1 > /config/vkms/my-device/enabled), would it make sense to use sysfs instead of another configfs directory? The advantage is that with sysfs the kernel controls the lifetime of the objects and I think it *might* simplify the code, but I'll need to write a proof of concept to see if this works.
Quoted 3 lines
For the platform driver part, it seems logic to me to use a "real" platform driver and a platform device for each pipeline, but I don't have the experience to tell if this is a good idea or not.
I'm afraid I don't know which approach could work better. Trusting Sima and Maíra on this one.
Jose
Quoted 9 lines
[1]: https://lore.kernel.org/dri-devel/[email protected]/
Thanks,
Louis ChauvetSignature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Hi all,
Quoted 58 lines · José Expósito
Quoted 48 lines · Louis Chauvet
Quoted 22 lines · Jim Shargo
Sima--thanks SO MUCH for going through with everything leaving a detailed review. I am excited to go through your feedback.
It makes me extremely happy to see these patches get people excited.
They've bounced between a few people, and I recently asked to take them over again from the folks who were most recently looking at them but haven't since had capacity to revisit them. I'd love to contribute more but I am currently pretty swamped and I probably couldn't realistically make too much headway before the middle of June.
José--if you've got capacity and interest, I'd love to see this work get in! Thanks!! Please let me know your timeline and if you want to split anything up or have any questions, I'd love to help if possible. But most important to me is seeing the community benefit from the feature.
And (in case it got lost in the shuffle of all these patches) the IGT tests really make it much easier to develop this thing. Marius has posted the most recent patches:
https://lore.kernel.org/igt-dev/?q=configfsQuoted 24 lines
Thanks!
-- JimQuoted 18 lines · José Expósito
Hi everyone,
I wasn't aware of these patches, but I'm really glad they are getting some attention, thanks a lot for your review Sima.
Given that it's been a while since the patches were emailed, I'm not sure if the original authors of the patches could implement your comments. If not, I can work on it. Please let me know.
I'm working on a Mutter feature that'd greatly benefit from this uapi and I'm sure other compositors would find it useful.
I'll start working on a new version in a few days if nobody else is already working on it.
Best wishes,
José ExpósitoQuoted 8 lines
Hi all!
Very nice to see other people working on this subject. As the series seemed inactive, I started two weeks ago to rebase it on top of [1]. I also started some work to use drmm_* helpers instead of using lists in vkms. I currently struggle with a deadlock during rmmod.
I need to clean my commits, but I can share a WIP version.
Quoted 8 lines
Hi Louis,
If you could share a RFC/WIP series it would be awesome!
Since you are already working on the kernel patches (and I guess IGT?), I'll start working on a libdrm high level API to interact with VKMS from user-space on top of your patches. I'll share a link as soon as I have a draft PR.
Just out of curiosity what API would that be? These should fairly simple that they can be configured from a shell script (mount/mkdir/rm/echo/umount). Believe should be easy enough to test stuff with bunch scripts like that.
Perphas landing the I-G-T tests first (assuming we're settled on how exactly this would work) might be of greated help to get a green lit the kernel driver side? Skip if vkms/configfs/something else that tells us VKMS doesn't have ConfigFS eneabled, and run it when that is on.
The lastest iteration was shared by Jim at
https://lore.kernel.org/igt-dev/[email protected]/
That way sub-sequent BAT CI would pick up issues, and can also used independently by Louis. Should also divide the work-load evenly with Louis focusing on the just the driver. Happy to review and test it.
Quoted 24 lines
Quoted 10 lines
Maybe we can discuss a bit the comment from Daniel (split init between default/configfs, use or not a real platform device...)
For the split, I think the first solution (struct
vkms_config) can be easier to understand and to implement, for two reasons:
- No need to distinguish between the "default" and the "configfs" devices in the VKMS "core". All is managed with only one structvkms_config.
- Most of the lifetime issue should be gone. The only thing to synchronize is passing thisvkms_configfrom ConfigFS to VKMS.I agree, this seems like the easiest solution.
Quoted 10 lines
The drawback of this is that it can become difficult to do the "runtime" configuration (today only hotplug, but I plan to add more complex stuff like DP emulation, EDID selection, MST support...). Those configuration must be done "at runtime" and will require a strong synchronization with the vkms "core".
Maybe we can distinguish between the "creation" and the "runtime configuration", in two different configFS directory? Once a device is created, it is moved to the "enabled" directory and will have a different set of attribute (connection status, current EDID...)
Quoted 5 lines
Once the device is enabled (i.e,
echo 1 > /config/vkms/my-device/enabled), would it make sense to use sysfs instead of another configfs directory? The advantage is that with sysfs the kernel controls the lifetime of the objects and I think it *might* simplify the code, but I'll need to write a proof of concept to see if this works.
Can indeed sysfs be used similar to ConfigFS? To me it sounds like sysfs is a view into a kernel objects, mostly for viewing and slight modifications but not manipulating, adding/removing, on the fly, various things. Sort of see it the other way around, device enabled with sysfs but configuration happens through ConfigFS. At least from a user-space pov.
Quoted 19 lines
Quoted 4 lines
For the platform driver part, it seems logic to me to use a "real" platform driver and a platform device for each pipeline, but I don't have the experience to tell if this is a good idea or not.
I'm afraid I don't know which approach could work better. Trusting Sima and Maíra on this one.
Jose
Quoted 9 lines
[1]: https://lore.kernel.org/dri-devel/[email protected]/
Thanks,
Louis ChauvetSignature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 69 lines · Marius Vlad
Hi all,
Quoted 58 lines · José Expósito
Quoted 48 lines · Louis Chauvet
Quoted 22 lines · Jim Shargo
Sima--thanks SO MUCH for going through with everything leaving a detailed review. I am excited to go through your feedback.
It makes me extremely happy to see these patches get people excited.
They've bounced between a few people, and I recently asked to take them over again from the folks who were most recently looking at them but haven't since had capacity to revisit them. I'd love to contribute more but I am currently pretty swamped and I probably couldn't realistically make too much headway before the middle of June.
José--if you've got capacity and interest, I'd love to see this work get in! Thanks!! Please let me know your timeline and if you want to split anything up or have any questions, I'd love to help if possible. But most important to me is seeing the community benefit from the feature.
And (in case it got lost in the shuffle of all these patches) the IGT tests really make it much easier to develop this thing. Marius has posted the most recent patches:
https://lore.kernel.org/igt-dev/?q=configfsQuoted 24 lines
Thanks!
-- JimQuoted 18 lines · José Expósito
Hi everyone,
I wasn't aware of these patches, but I'm really glad they are getting some attention, thanks a lot for your review Sima.
Given that it's been a while since the patches were emailed, I'm not sure if the original authors of the patches could implement your comments. If not, I can work on it. Please let me know.
I'm working on a Mutter feature that'd greatly benefit from this uapi and I'm sure other compositors would find it useful.
I'll start working on a new version in a few days if nobody else is already working on it.
Best wishes,
José ExpósitoQuoted 8 lines
Hi all!
Very nice to see other people working on this subject. As the series seemed inactive, I started two weeks ago to rebase it on top of [1]. I also started some work to use drmm_* helpers instead of using lists in vkms. I currently struggle with a deadlock during rmmod.
I need to clean my commits, but I can share a WIP version.
Quoted 8 lines
Hi Louis,
If you could share a RFC/WIP series it would be awesome!
Since you are already working on the kernel patches (and I guess IGT?), I'll start working on a libdrm high level API to interact with VKMS from user-space on top of your patches. I'll share a link as soon as I have a draft PR.
Quoted 4 lines
Just out of curiosity what API would that be? These should fairly simple that they can be configured from a shell script (mount/mkdir/rm/echo/umount). Believe should be easy enough to test stuff with bunch scripts like that.
My plan is to add a very thin C API around mkdir/rmdir/etc.
It is true that VKMS can be configure easily using a bash script; however, compositors with test suites written in C (or with bindings to libdrm) would have to write similar wrappers around the mkdir/rmdir/etc calls.
I think that it could be beneficial for them to have a shared wrapper available in libdrm.
Quoted 65 lines
Perphas landing the I-G-T tests first (assuming we're settled on how exactly this would work) might be of greated help to get a green lit the kernel driver side? Skip if vkms/configfs/something else that tells us VKMS doesn't have ConfigFS eneabled, and run it when that is on.
The lastest iteration was shared by Jim at
https://lore.kernel.org/igt-dev/[email protected]/That way sub-sequent BAT CI would pick up issues, and can also used independently by Louis. Should also divide the work-load evenly with Louis focusing on the just the driver. Happy to review and test it.
Quoted 24 lines
Quoted 10 lines
Maybe we can discuss a bit the comment from Daniel (split init between default/configfs, use or not a real platform device...)
For the split, I think the first solution (struct
vkms_config) can be easier to understand and to implement, for two reasons:
- No need to distinguish between the "default" and the "configfs" devices in the VKMS "core". All is managed with only one structvkms_config.
- Most of the lifetime issue should be gone. The only thing to synchronize is passing thisvkms_configfrom ConfigFS to VKMS.I agree, this seems like the easiest solution.
Quoted 10 lines
The drawback of this is that it can become difficult to do the "runtime" configuration (today only hotplug, but I plan to add more complex stuff like DP emulation, EDID selection, MST support...). Those configuration must be done "at runtime" and will require a strong synchronization with the vkms "core".
Maybe we can distinguish between the "creation" and the "runtime configuration", in two different configFS directory? Once a device is created, it is moved to the "enabled" directory and will have a different set of attribute (connection status, current EDID...)
Quoted 5 lines
Once the device is enabled (i.e,
echo 1 > /config/vkms/my-device/enabled), would it make sense to use sysfs instead of another configfs directory? The advantage is that with sysfs the kernel controls the lifetime of the objects and I think it *might* simplify the code, but I'll need to write a proof of concept to see if this works.Can indeed sysfs be used similar to ConfigFS? To me it sounds like sysfs is a view into a kernel objects, mostly for viewing and slight modifications but not manipulating, adding/removing, on the fly, various things. Sort of see it the other way around, device enabled with sysfs but configuration happens through ConfigFS. At least from a user-space pov.
Quoted 19 lines
Quoted 4 lines
For the platform driver part, it seems logic to me to use a "real" platform driver and a platform device for each pipeline, but I don't have the experience to tell if this is a good idea or not.
I'm afraid I don't know which approach could work better. Trusting Sima and Maíra on this one.
Jose
Quoted 9 lines
[1]: https://lore.kernel.org/dri-devel/[email protected]/
Thanks,
Louis ChauvetSignature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Louis Chauvet
maintainerQuoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hi Louis,
If you could share a RFC/WIP series it would be awesome!
Hi all!
I just uploaded my WIP series to github here [1]. Most of the work is extracted from the current ConfigFS series, I just splitted and completed what was done. I also tried to take in account the comments from Sima.
All commits should compile and modprobe/rmmod/kms_plane should not crashing. The commits are not totaly clean, but it should be only cosmetic stuff (formatting in the wrong commit for example). The commit messages are not written yet, but the title should be sufficient to understand the content of each commit.
This is how I plan to split this work in series: (hash may change over time, I will force push to clean commits)
Some preparation stuff (no functionnal change):
256d7045ec70 drm/vkms: Formatting and typo fix cc2de5004c42 drm/vkms: Rename index to possible_crtc a74cefc87b9c drm/vkms: Add documentation
More preparation to split everything properly (no functionnal change):
ad2d0b07558f drm/vkms: Properly extract vkms_formats header f9639cca2d43 drm/vkms: Extract vkms_writeback header 7edda8012b44 drm/vkms: Extract vkms_plane header ced09ed9d0f7 drm/vkms: Rename macro to avoid confusion 9f00e4823529 drm/vkms: Extract vkms_crtc header b510e480ed92 drm/vkms: Extract vkms_composer header
Switch all the vkms object to managed (this part need a careful review, I am new with DRM, so I probably did some error):
ddef3c09ead6 drm/vkms: Switch to managed for connector 8859cad0e192 drm/vkms: Switch to managed for encoder d2b8d93fb684 drm/vkms: Switch to managed for crtc d1ad316b0f0d drm/vkms: Rename all vkms_crtc instance to be consistent
Temporaly remove debugfs entry, I plan to remove this commit:
079d875c015e drm/vkms: remove debugfs entry about the current vkms configuration
Clean up vkms_device and unlink vkms_config from vkms_device.
c782dbe9edc3 drm/vkms: Remove vkms_config from vkms_device
8a27c13634a3 drm/vkms: Remove (useles?) group
8fb24e1cdf88 drm/vkms: Introduce directly the default device as global/Remove default vkms config
More cleanup:
2572d90723ac drm/vkms: Remove possible crtc from parameters
Switching to platform driver (same thing, it is my first time, I probably messed up things):
63be09e05760 drm/vkms: Use a real platform driver 5f4cf18b07d3 drm/vkms: Extract device driver in its own file
The configFS implementation itself. It only allows to create/enable/delete a device:
b34651685f2e drm/vkms: Introduce configfs
Those commits were a POC to confirm that it works. They need to be replaced by the "real" configuration (creation&link of crtc/connector/planes...)
dd55451ccef2 drm/vkms: Make overlay configurable with configfs 9dca357f1ee3 drm/vkms: Make cursor configurable with configfs bd721f41fad9 drm/vkms: Make writeback configurable with configfs
Kind regards,
Louis Chauvet
[1]: https://github.com/Fomys/linux/tree/b4/new-configfs
Quoted 85 lines
Quoted 9 lines
Quoted 4 lines
Since you are already working on the kernel patches (and I guess IGT?), I'll start working on a libdrm high level API to interact with VKMS from user-space on top of your patches. I'll share a link as soon as I have a draft PR.
Just out of curiosity what API would that be? These should fairly simple that they can be configured from a shell script (mount/mkdir/rm/echo/umount). Believe should be easy enough to test stuff with bunch scripts like that.
My plan is to add a very thin C API around mkdir/rmdir/etc.
It is true that VKMS can be configure easily using a bash script; however, compositors with test suites written in C (or with bindings to libdrm) would have to write similar wrappers around the mkdir/rmdir/etc calls.
I think that it could be beneficial for them to have a shared wrapper available in libdrm.Quoted 65 lines
Perphas landing the I-G-T tests first (assuming we're settled on how exactly this would work) might be of greated help to get a green lit the kernel driver side? Skip if vkms/configfs/something else that tells us VKMS doesn't have ConfigFS eneabled, and run it when that is on.
The lastest iteration was shared by Jim at
https://lore.kernel.org/igt-dev/[email protected]/That way sub-sequent BAT CI would pick up issues, and can also used independently by Louis. Should also divide the work-load evenly with Louis focusing on the just the driver. Happy to review and test it.
Quoted 24 lines
Quoted 10 lines
Maybe we can discuss a bit the comment from Daniel (split init between default/configfs, use or not a real platform device...)
For the split, I think the first solution (struct
vkms_config) can be easier to understand and to implement, for two reasons:
- No need to distinguish between the "default" and the "configfs" devices in the VKMS "core". All is managed with only one structvkms_config.
- Most of the lifetime issue should be gone. The only thing to synchronize is passing thisvkms_configfrom ConfigFS to VKMS.I agree, this seems like the easiest solution.
Quoted 10 lines
The drawback of this is that it can become difficult to do the "runtime" configuration (today only hotplug, but I plan to add more complex stuff like DP emulation, EDID selection, MST support...). Those configuration must be done "at runtime" and will require a strong synchronization with the vkms "core".
Maybe we can distinguish between the "creation" and the "runtime configuration", in two different configFS directory? Once a device is created, it is moved to the "enabled" directory and will have a different set of attribute (connection status, current EDID...)
Quoted 5 lines
Once the device is enabled (i.e,
echo 1 > /config/vkms/my-device/enabled), would it make sense to use sysfs instead of another configfs directory? The advantage is that with sysfs the kernel controls the lifetime of the objects and I think it *might* simplify the code, but I'll need to write a proof of concept to see if this works.Can indeed sysfs be used similar to ConfigFS? To me it sounds like sysfs is a view into a kernel objects, mostly for viewing and slight modifications but not manipulating, adding/removing, on the fly, various things. Sort of see it the other way around, device enabled with sysfs but configuration happens through ConfigFS. At least from a user-space pov.
Quoted 19 lines
Quoted 4 lines
For the platform driver part, it seems logic to me to use a "real" platform driver and a platform device for each pipeline, but I don't have the experience to tell if this is a good idea or not.
I'm afraid I don't know which approach could work better. Trusting Sima and Maíra on this one.
Jose
Quoted 9 lines
[1]: https://lore.kernel.org/dri-devel/[email protected]/
Thanks,
Louis ChauvetSignature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Signature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
Quoted 58 lines · José Expósito
Quoted 48 lines · Louis Chauvet
Quoted 22 lines · Jim Shargo
Sima--thanks SO MUCH for going through with everything leaving a detailed review. I am excited to go through your feedback.
It makes me extremely happy to see these patches get people excited.
They've bounced between a few people, and I recently asked to take them over again from the folks who were most recently looking at them but haven't since had capacity to revisit them. I'd love to contribute more but I am currently pretty swamped and I probably couldn't realistically make too much headway before the middle of June.
José--if you've got capacity and interest, I'd love to see this work get in! Thanks!! Please let me know your timeline and if you want to split anything up or have any questions, I'd love to help if possible. But most important to me is seeing the community benefit from the feature.
And (in case it got lost in the shuffle of all these patches) the IGT tests really make it much easier to develop this thing. Marius has posted the most recent patches:
https://lore.kernel.org/igt-dev/?q=configfsQuoted 24 lines
Thanks!
-- JimQuoted 18 lines · José Expósito
Hi everyone,
I wasn't aware of these patches, but I'm really glad they are getting some attention, thanks a lot for your review Sima.
Given that it's been a while since the patches were emailed, I'm not sure if the original authors of the patches could implement your comments. If not, I can work on it. Please let me know.
I'm working on a Mutter feature that'd greatly benefit from this uapi and I'm sure other compositors would find it useful.
I'll start working on a new version in a few days if nobody else is already working on it.
Best wishes,
José ExpósitoQuoted 8 lines
Hi all!
Very nice to see other people working on this subject. As the series seemed inactive, I started two weeks ago to rebase it on top of [1]. I also started some work to use drmm_* helpers instead of using lists in vkms. I currently struggle with a deadlock during rmmod.
I need to clean my commits, but I can share a WIP version.
Quoted 8 lines
Hi Louis,
If you could share a RFC/WIP series it would be awesome!
Since you are already working on the kernel patches (and I guess IGT?), I'll start working on a libdrm high level API to interact with VKMS from user-space on top of your patches. I'll share a link as soon as I have a draft PR.
Great to see all the enthusiasm here, this is awesome.
Note that I'm out of office for two weeks next week, so if I miss any patches please ping me again (sima in #dri-devel on oftc tends to work best) when I'm back.
Quoted 23 lines
Quoted 9 lines
Maybe we can discuss a bit the comment from Daniel (split init between default/configfs, use or not a real platform device...)
For the split, I think the first solution (struct
vkms_config) can be easier to understand and to implement, for two reasons:
- No need to distinguish between the "default" and the "configfs" devices in the VKMS "core". All is managed with only one structvkms_config.
- Most of the lifetime issue should be gone. The only thing to synchronize is passing thisvkms_configfrom ConfigFS to VKMS.I agree, this seems like the easiest solution.
Quoted 10 lines
The drawback of this is that it can become difficult to do the "runtime" configuration (today only hotplug, but I plan to add more complex stuff like DP emulation, EDID selection, MST support...). Those configuration must be done "at runtime" and will require a strong synchronization with the vkms "core".
Maybe we can distinguish between the "creation" and the "runtime configuration", in two different configFS directory? Once a device is created, it is moved to the "enabled" directory and will have a different set of attribute (connection status, current EDID...)
Quoted 5 lines
Once the device is enabled (i.e,
echo 1 > /config/vkms/my-device/enabled), would it make sense to use sysfs instead of another configfs directory? The advantage is that with sysfs the kernel controls the lifetime of the objects and I think it *might* simplify the code, but I'll need to write a proof of concept to see if this works.
sysfs is very opinionated about lifetime, so we might actually make this more complicated. Plus for the only thing we can hotplug (connectors) we already have sysfs directories, so there could be a lifetime/name fight between the sysfs interfaces to prepare a hotplugged connector, and the connector sysfs files which are part of the existing uapi.
Also the second issue I'm seeing is that we're mixing up testing/configuration apis with the generic uapi that should hold for every kms driver. This could make the code in igt testcase or for driving compositor end-to-end testcases a lot more confusing. I think separation would be better.
The third point I'm seeing is that connectors can be created both before we create the device, and at runtime. If we have two totally separate interfaces for this, we might end up with needless code duplication.
But it's a complex topic, I think it does make sense to give sysfs some serious thought. But maybe as part of the vkms driver directory, and not in the drm_device chardev directories. So we could have some separation that way maybe?
Quoted 6 lines
Quoted 3 lines
For the platform driver part, it seems logic to me to use a "real" platform driver and a platform device for each pipeline, but I don't have the experience to tell if this is a good idea or not.
I'm afraid I don't know which approach could work better. Trusting Sima and Maíra on this one.
As I've said, I'm not opposed to a switch. I just think it's an orthogonal issue to the configfs and should be separately justified.
We're trying hard to get away from kms userspace sneaking too much under the hood of the driver, and have gone a long way from the o.g. drm days where "everything is pci" was encoded into uapi. So from that pov I kinda like the fact that vkms is special and fairly free-floating.
But maybe userspace does want to be able to test their device enumeration more like a real device, so if vkms currently sticks out there that would be a really good reason to change things and make it look more like a real driver/device.
Cheers, Sima
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation http://blog.ffwll.ch
Quoted 24 lines · Louis Chauvet
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Hi Louis,
If you could share a RFC/WIP series it would be awesome!
Hi all!
I just uploaded my WIP series to github here [1]. Most of the work is extracted from the current ConfigFS series, I just splitted and completed what was done. I also tried to take in account the comments from Sima.
All commits should compile and
modprobe/rmmod/kms_planeshould not crashing. The commits are not totaly clean, but it should be only cosmetic stuff (formatting in the wrong commit for example). The commit messages are not written yet, but the title should be sufficient to understand the content of each commit.This is how I plan to split this work in series: (hash may change over time, I will force push to clean commits)
Some preparation stuff (no functionnal change):
256d7045ec70drm/vkms: Formatting and typo fixcc2de5004c42drm/vkms: Rename index topossible_crtca74cefc87b9cdrm/vkms: Add documentation
Quoted 7 lines
More preparation to split everything properly (no functionnal change):
ad2d0b07558fdrm/vkms: Properly extractvkms_formatsheaderf9639cca2d43drm/vkms: Extractvkms_writebackheader7edda8012b44drm/vkms: Extractvkms_planeheaderced09ed9d0f7drm/vkms: Rename macro to avoid confusion9f00e4823529drm/vkms: Extractvkms_crtcheaderb510e480ed92drm/vkms: Extractvkms_composerheader
Thanks for all your work Louis!!
I reviewed the first 9 patches and added a few comments on your GitHub fork.
I think that this first batch of patches is independent of the VKMS ConfigFS work and, if you want, you could send it as it is.
To try to make your work a bit easier, I applied the suggested fixes and rebased on top of "upstream-drm-misc-next" your patches.
You can find them here:
https://github.com/JoseExposito/linux/commits/patch-vkms-header-refactor/
Quoted 25 lines
Switch all the vkms object to managed (this part need a careful review, I am new with DRM, so I probably did some error):
ddef3c09ead6drm/vkms: Switch to managed for connector8859cad0e192drm/vkms: Switch to managed for encoderd2b8d93fb684drm/vkms: Switch to managed for crtcd1ad316b0f0ddrm/vkms: Rename allvkms_crtcinstance to be consistentTemporaly remove debugfs entry, I plan to remove this commit:
079d875c015edrm/vkms: remove debugfs entry about the current vkms configurationClean up
vkms_deviceand unlinkvkms_configfromvkms_device.
c782dbe9edc3drm/vkms: Removevkms_configfromvkms_device
8a27c13634a3drm/vkms: Remove (useles?) group
8fb24e1cdf88drm/vkms: Introduce directly the default device as global/Remove default vkms configMore cleanup:
2572d90723acdrm/vkms: Remove possible crtc from parametersSwitching to platform driver (same thing, it is my first time, I probably messed up things):
63be09e05760drm/vkms: Use a real platform driver5f4cf18b07d3drm/vkms: Extract device driver in its own fileThe configFS implementation itself. It only allows to create/enable/delete a device:
Quoted 7 lines
b34651685f2e drm/vkms: Introduce configfsThose commits were a POC to confirm that it works. They need to be replaced by the "real" configuration (creation&link of crtc/connector/planes...)
dd55451ccef2drm/vkms: Make overlay configurable with configfs9dca357f1ee3drm/vkms: Make cursor configurable with configfsbd721f41fad9drm/vkms: Make writeback configurable with configfs
I'm still testing/understanding these patches.
I'll keep adding review comments :)
Best wishes,
José Expósito
Quoted 96 lines
Kind regards,
Louis Chauvet[1]: https://github.com/Fomys/linux/tree/b4/new-configfs
Quoted 85 lines
Quoted 9 lines
Quoted 4 lines
Since you are already working on the kernel patches (and I guess IGT?), I'll start working on a libdrm high level API to interact with VKMS from user-space on top of your patches. I'll share a link as soon as I have a draft PR.
Just out of curiosity what API would that be? These should fairly simple that they can be configured from a shell script (mount/mkdir/rm/echo/umount). Believe should be easy enough to test stuff with bunch scripts like that.
My plan is to add a very thin C API around mkdir/rmdir/etc.
It is true that VKMS can be configure easily using a bash script; however, compositors with test suites written in C (or with bindings to libdrm) would have to write similar wrappers around the mkdir/rmdir/etc calls.
I think that it could be beneficial for them to have a shared wrapper available in libdrm.Quoted 65 lines
Perphas landing the I-G-T tests first (assuming we're settled on how exactly this would work) might be of greated help to get a green lit the kernel driver side? Skip if vkms/configfs/something else that tells us VKMS doesn't have ConfigFS eneabled, and run it when that is on.
The lastest iteration was shared by Jim at
https://lore.kernel.org/igt-dev/[email protected]/That way sub-sequent BAT CI would pick up issues, and can also used independently by Louis. Should also divide the work-load evenly with Louis focusing on the just the driver. Happy to review and test it.
Quoted 24 lines
Quoted 10 lines
Maybe we can discuss a bit the comment from Daniel (split init between default/configfs, use or not a real platform device...)
For the split, I think the first solution (struct
vkms_config) can be easier to understand and to implement, for two reasons:
- No need to distinguish between the "default" and the "configfs" devices in the VKMS "core". All is managed with only one structvkms_config.
- Most of the lifetime issue should be gone. The only thing to synchronize is passing thisvkms_configfrom ConfigFS to VKMS.I agree, this seems like the easiest solution.
Quoted 10 lines
The drawback of this is that it can become difficult to do the "runtime" configuration (today only hotplug, but I plan to add more complex stuff like DP emulation, EDID selection, MST support...). Those configuration must be done "at runtime" and will require a strong synchronization with the vkms "core".
Maybe we can distinguish between the "creation" and the "runtime configuration", in two different configFS directory? Once a device is created, it is moved to the "enabled" directory and will have a different set of attribute (connection status, current EDID...)
Quoted 5 lines
Once the device is enabled (i.e,
echo 1 > /config/vkms/my-device/enabled), would it make sense to use sysfs instead of another configfs directory? The advantage is that with sysfs the kernel controls the lifetime of the objects and I think it *might* simplify the code, but I'll need to write a proof of concept to see if this works.Can indeed sysfs be used similar to ConfigFS? To me it sounds like sysfs is a view into a kernel objects, mostly for viewing and slight modifications but not manipulating, adding/removing, on the fly, various things. Sort of see it the other way around, device enabled with sysfs but configuration happens through ConfigFS. At least from a user-space pov.
Quoted 19 lines
Quoted 4 lines
For the platform driver part, it seems logic to me to use a "real" platform driver and a platform device for each pipeline, but I don't have the experience to tell if this is a good idea or not.
I'm afraid I don't know which approach could work better. Trusting Sima and Maíra on this one.
Jose
Quoted 9 lines
[1]: https://lore.kernel.org/dri-devel/[email protected]/
Thanks,
Louis ChauvetSignature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.comSignature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com