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 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.
Original Message:
Usage
=====
After installing these patches, you can create a VKMS device with two displays and a movable overlay like so (this is documented in the patches):
$ modprobe vkms enable_overlay=1 enable_cursor=1 enable_writeback=1 $ mkdir -p /config/ $ mount -t configfs none /config
$ export DRM_PLANE_TYPE_PRIMARY=1 $ export DRM_PLANE_TYPE_CURSOR=2 $ export DRM_PLANE_TYPE_OVERLAY=0
$ mkdir /config/vkms/test
$ mkdir /config/vkms/test/planes/primary $ echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/primary/type
$ mkdir /config/vkms/test/planes/other_primary $ echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/other_primary/type
$ mkdir /config/vkms/test/planes/cursor $ echo $DRM_PLANE_TYPE_CURSOR > /config/vkms/test/planes/cursor/type
$ mkdir /config/vkms/test/planes/overlay $ echo $DRM_PLANE_TYPE_OVERLAY > /config/vkms/test/planes/overlay/type
$ mkdir /config/vkms/test/crtcs/crtc $ mkdir /config/vkms/test/crtcs/crtc_other $ mkdir /config/vkms/test/encoders/encoder $ mkdir /config/vkms/test/connectors/connector
$ ln -s /config/vkms/test/encoders/encoder /config/vkms/test/connectors/connector/possible_encoders $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/encoders/encoder/possible_crtcs/ $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/primary/possible_crtcs/ $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/cursor/possible_crtcs/ $ ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/overlay/possible_crtcs/ $ ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/overlay/possible_crtcs/ $ ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/other_primary/possible_crtcs/
$ echo 1 > /config/vkms/test/enabled
Changes within core VKMS
========================
This introduces a few important changes to the overall structure of VKMS:
- Devices are now memory managed!
- Support for multiple CRTCs and other objects has been added
Since v1
========
- Added DRMM memory management to automatically clean up resources
- Added a param to disable the default device
- Renamed "cards" to "devices" to improve legibility
- Added a lock for the configfs setup handler
- Moved all the new docs into the relevant .c file
- Addressed as many of [email protected] as possible
Testing
=======
- New IGT tests (see gitlab.freedesktop.org/jshargo/igt-gpu-tools/-/merge_requests/1)
- Existing IGT tests (excluding .*suspend.*, including .*kms_flip.*
.*kms_writeback.* .*kms_cursor_crc.*, .*kms_plane.*)
Outro
=====
I'm excited to share these changes, it's my still my first kernel patch and I've been putting a lot of love into these.
PATCH v3 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.rc1.204.g551eb34607-goog
PATCH v3 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 | 101 ++++++++++++--------- 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 | 33 +++---- 7 files changed, 259 insertions(+), 147 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 +59 -42
213 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 +18 -15
@@ -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,23 +133,25 @@ 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 ]; wb_frame_info->cpp = fb->format->cpp[0 ]; + crtc_state->wb_pending = true; +spin_unlock_irq (&vkms_crtc->composer_lock);drm_writeback_queue_job (wb_conn, connector_state); active_wb->pixel_write =get_pixel_write_function (wb_format);drm_rect_init (&wb_frame_info->src,0 ,0 , crtc_width, crtc_height);
@@ -163,9 +165,10 @@ static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = { .atomic_commit = vkms_wb_atomic_commit, }; -int vkms_enable_writeback_connector (struct vkms_device *vkmsdev) +int vkms_enable_writeback_connector (struct vkms_device *vkmsdev, +struct vkms_crtc *vkms_crtc) { -struct drm_writeback_connector *wb = &vkmsdev->output.wb_connector; +struct drm_writeback_connector *wb = &vkms_crtc->wb_connector;drm_connector_helper_add (&wb->base, &vkms_wb_conn_helper_funcs);
Signature · 1 line
2.42.0.rc1.204.g551eb34607-goog
PATCH v3 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.rc1.204.g551eb34607-goog
PATCH v3 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 | 651 +++++++++++++++++++++++++++ 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, 807 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 +651 -0
651 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.rc1.204.g551eb34607-goog
PATCH v3 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 | 2 +- drivers/gpu/drm/vkms/vkms_output.c | 208 ++++++++++++++++++++++----- 5 files changed, 204 insertions(+), 48 deletions(-)
drivers/gpu/drm/vkms/vkms_configfs.c +24 -13
@@ -509,29 +509,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
@@ -280,7 +280,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;
@@ -292,7 +292,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 +1 -1
@@ -250,7 +250,7 @@ void vkms_remove_device(struct vkms_device *vkms_device);/* CRTC */ struct vkms_crtc *vkms_crtc_init (struct vkms_device *vkmsdev,struct drm_plane *primary, -struct drm_plane *cursor); +struct drm_plane *cursor,const char *name);int vkms_output_init (struct vkms_device *vkmsdev);int vkms_output_init_default (struct vkms_device *vkmsdev);
drivers/gpu/drm/vkms/vkms_output.c +176 -32
266 lines not on this page · raw message
Signature · 1 line
2.42.0.rc1.204.g551eb34607-goog
PATCH v3 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.rc1.204.g551eb34607-goog
PATCH v3 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.rc1.204.g551eb34607-goog