drm/vkms: Allow to configure device
Subsystems (4)
v2 cover drm/vkms: Allow to configure device
Hi everyone,
In preparation for ConfigFS support, a flexible way to configure VKMS device(s) is required.
This series adds the required APIs to create a configuration, the code changes required to apply it and KUnit test validating the changes.
Louis Chauvet and I are working on ConfigFS support. In this series I tried to merge his changes [1] with mine [2].
I kept his Signed-off-by to reflect that, even if I show up as the author of some/most of the patches, this was a joint effort.
I'll send the the ConfigFS code [3] and its IGT tests [4] code this or next week. Meanwhile, the IGT tests also exercise this series and can be used for additional test coverage.
Best wishes,
José Expósito
[1] https://patchwork.kernel.org/project/dri-devel/cover/20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com/
[2] https://patchwork.kernel.org/project/dri-devel/cover/[email protected]/
[3] https://github.com/JoseExposito/linux/commits/patch-vkms-configfs/
[4] https://gitlab.freedesktop.org/jexposit/igt-gpu-tools/-/commits/vkms-configfs
Changes in v2:
- Applied review comments by Louis Chauvet (thanks!!):
- Added Co-developped-by tags where required
- Split the first patch in 2: vkms_connector.h/c creation and struct vkms_connector creation
- Fixes a user after free/double free bug. The bug is already present
in drm-misc-next and the fix could be merged independently
- Implemented for_each macros for the config
- Other naming fixes
- Link to v1: https://lore.kernel.org/all/[email protected]/
José Expósito (14):
drm/vkms: Fix use after free and double free on init error drm/vkms: Extract vkms_connector header drm/vkms: Create vkms_connector struct
drm/vkms: Add KUnit test scaffolding
drm/vkms: Extract vkms_config header
drm/vkms: Move default_config creation to its own function drm/vkms: Set device name from vkms_config drm/vkms: Allow to configure multiple planes drm/vkms: Allow to configure multiple CRTCs drm/vkms: Allow to attach planes and CRTCs drm/vkms: Allow to configure multiple encoders drm/vkms: Allow to attach encoders and CRTCs drm/vkms: Allow to configure multiple connectors drm/vkms: Allow to attach connectors and encoders
Louis Chauvet (1):
drm/vkms: Add a validation function for VKMS configuration
.clang-format | 7 + drivers/gpu/drm/vkms/Kconfig | 15 + drivers/gpu/drm/vkms/Makefile | 5 +- drivers/gpu/drm/vkms/tests/.kunitconfig | 4 + drivers/gpu/drm/vkms/tests/Makefile | 3 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 826 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.c | 606 +++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 429 +++++++++ drivers/gpu/drm/vkms/vkms_connector.c | 61 ++ drivers/gpu/drm/vkms/vkms_connector.h | 26 + drivers/gpu/drm/vkms/vkms_drv.c | 60 +- drivers/gpu/drm/vkms/vkms_drv.h | 19 +- drivers/gpu/drm/vkms/vkms_output.c | 176 ++-- 13 files changed, 2089 insertions(+), 148 deletions(-) create mode 100644 drivers/gpu/drm/vkms/tests/.kunitconfig create mode 100644 drivers/gpu/drm/vkms/tests/Makefile create mode 100644 drivers/gpu/drm/vkms/tests/vkms_config_test.c create mode 100644 drivers/gpu/drm/vkms/vkms_config.c create mode 100644 drivers/gpu/drm/vkms/vkms_config.h create mode 100644 drivers/gpu/drm/vkms/vkms_connector.c create mode 100644 drivers/gpu/drm/vkms/vkms_connector.h
Signature · 1 line
2.48.1
PATCH v2 1/15 drm/vkms: Fix use after free and double free on init error
If the driver initialization fails, the vkms_exit() function might access an uninitialized or freed default_config pointer and it might double free it.
Fix both possible errors by initializing default_config only when the driver initialization succeeded.
--- drivers/gpu/drm/vkms/vkms_drv.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)
drivers/gpu/drm/vkms/vkms_drv.c +9 -6
@@ -235,17 +235,19 @@ static int __init vkms_init(void)if (!config)return -ENOMEM ; - default_config = config; - config->cursor = enable_cursor; config->writeback = enable_writeback; config->overlay = enable_overlay; ret =vkms_create (config); -if (ret) +if (ret) {kfree (config); +return ret; + } -return ret; + default_config = config; + +return 0 ; }static void vkms_destroy (struct vkms_config *config)
@@ -269,9 +271,10 @@ static void vkms_destroy(struct vkms_config *config) static void __exit vkms_exit(void) { -if (default_config->dev) -vkms_destroy (default_config); +if (!default_config) +return ; +vkms_destroy (default_config);kfree (default_config); }
Signature · 1 line
2.48.1
Thomas Zimmermann
maintainerRe: [PATCH v2 01/15] drm/vkms: Fix use after free and double free on init error
Hi
Am 11.02.25 um 12:08 schrieb José Expósito:
Quoted 6 lines
If the driver initialization fails, the
vkms_exit()function might access an uninitialized or freeddefault_configpointer and it might double free it.Fix both possible errors by initializing
default_configonly when the driver initialization succeeded.
Could you send this patch separately, so that it can go into drm-misc-fixes quickly?
Best regards
Thomas
Quoted 50 lines
Reported-by Louis Chauvet <[email protected]>Fixes 2df7af93fdad ("drm/vkms: Add vkms_config type")Signed-off-by José Expósito <[email protected]>--- drivers/gpu/drm/vkms/vkms_drv.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/gpu/drm/vkms/vkms_drv.c +9
-6@@ -235,17 +235,19 @@ static int __init vkms_init(void)if (!config)return -ENOMEM ; - default_config = config; - config->cursor = enable_cursor; config->writeback = enable_writeback; config->overlay = enable_overlay; ret =vkms_create (config); -if (ret) +if (ret) {kfree (config); +return ret; + } -return ret; + default_config = config; + +return 0 ; }static void vkms_destroy (struct vkms_config *config)@@ -269,9 +271,10 @@ static void vkms_destroy(struct vkms_config *config) static void __exit vkms_exit(void) { -if (default_config->dev) -vkms_destroy (default_config); +if (!default_config) +return ; +vkms_destroy (default_config);kfree (default_config); }
Signature · 7 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
Re: [PATCH v2 01/15] drm/vkms: Fix use after free and double free on init error
Hi Thomas,
Quoted 7 lines · Thomas Zimmermann
Hi
Am 11.02.25 um 12:08 schrieb José Expósito:
Quoted 4 lines
If the driver initialization fails, the
vkms_exit()function might access an uninitialized or freeddefault_configpointer and it might double free it.
Quoted 5 lines
Quoted 2 lines
Fix both possible errors by initializing
default_configonly when the driver initialization succeeded.Could you send this patch separately, so that it can go into drm-misc-fixes quickly?
Sure, I just sent it as a separate patch.
Thanks,
Jose
Quoted 56 lines
Best regards
ThomasQuoted 43 lines
Reported-by Louis Chauvet <[email protected]>Fixes 2df7af93fdad ("drm/vkms: Add vkms_config type")Signed-off-by José Expósito <[email protected]>--- drivers/gpu/drm/vkms/vkms_drv.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-)drivers/gpu/drm/vkms/vkms_drv.c +9
-6@@ -235,17 +235,19 @@ static int __init vkms_init(void)if (!config)return -ENOMEM ; - default_config = config; - config->cursor = enable_cursor; config->writeback = enable_writeback; config->overlay = enable_overlay; ret =vkms_create (config); -if (ret) +if (ret) {kfree (config); +return ret; + } -return ret; + default_config = config; + +return 0 ; }static void vkms_destroy (struct vkms_config *config)@@ -269,9 +271,10 @@ static void vkms_destroy(struct vkms_config *config) static void __exit vkms_exit(void) { -if (default_config->dev) -vkms_destroy (default_config); +if (!default_config) +return ; +vkms_destroy (default_config);kfree (default_config); }Signature · 7 lines
-- Thomas Zimmermann Graphics Driver Developer SUSE Software Solutions Germany GmbH Frankenstrasse 146, 90461 Nuernberg, Germany GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman HRB 36809 (AG Nuernberg)
PATCH v2 2/15 drm/vkms: Extract vkms_connector header
In reply to José ExpósitoUp until now, the logic to manage connectors was in vkms_output.c.
Since more options will be added to connectors in the future, extract the code to its own file.
Refactor, no functional changes.
--- drivers/gpu/drm/vkms/Makefile | 3 +- drivers/gpu/drm/vkms/vkms_connector.c | 50 +++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_connector.h | 17 +++++++++ drivers/gpu/drm/vkms/vkms_output.c | 41 +++------------------- 4 files changed, 73 insertions(+), 38 deletions(-) create mode 100644 drivers/gpu/drm/vkms/vkms_connector.c create mode 100644 drivers/gpu/drm/vkms/vkms_connector.h
drivers/gpu/drm/vkms/Makefile +2 -1
@@ -6,6 +6,7 @@ vkms-y := \ vkms_formats.o \ vkms_crtc.o \ vkms_composer.o \ - vkms_writeback.o + vkms_writeback.o \ + vkms_connector.o obj-$(CONFIG_DRM_VKMS) += vkms.o
drivers/gpu/drm/vkms/vkms_connector.c new file +50 -0
50 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_connector.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _VKMS_CONNECTOR_H_ +#define _VKMS_CONNECTOR_H_ + +#include "vkms_drv.h" + +/** +* vkms_connector_init() - Initialize a connector +* @vkmsdev: VKMS device containing the connector +* +* Returns: +* The connector or an error on failure. +*/ +struct drm_connector *vkms_connector_init (struct vkms_device *vkmsdev); + +#endif /* _VKMS_CONNECTOR_H_ */
drivers/gpu/drm/vkms/vkms_output.c +4 -37
57 lines not on this page · raw message
Signature · 1 line
2.48.1
PATCH v2 3/15 drm/vkms: Create vkms_connector struct
In reply to José ExpósitoCreate a structure wrapping the drm_connector.
--- drivers/gpu/drm/vkms/vkms_connector.c | 8 ++++---- drivers/gpu/drm/vkms/vkms_connector.h | 11 ++++++++++- drivers/gpu/drm/vkms/vkms_output.c | 4 ++-- 3 files changed, 16 insertions(+), 7 deletions(-)
drivers/gpu/drm/vkms/vkms_connector.c +4 -4
@@ -29,22 +29,22 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { .get_modes = vkms_conn_get_modes, }; -struct drm_connector *vkms_connector_init (struct vkms_device *vkmsdev) +struct vkms_connector *vkms_connector_init (struct vkms_device *vkmsdev) {struct drm_device *dev = &vkmsdev->drm; -struct drm_connector *connector; +struct vkms_connector *connector;int ret; connector =drmm_kzalloc (dev,sizeof (*connector),GFP_KERNEL );if (!connector)return ERR_PTR (-ENOMEM ); - ret =drmm_connector_init (dev, connector, &vkms_connector_funcs, + ret =drmm_connector_init (dev, &connector->base, &vkms_connector_funcs,DRM_MODE_CONNECTOR_VIRTUAL ,NULL );if (ret)return ERR_PTR (ret); -drm_connector_helper_add (connector, &vkms_conn_helper_funcs); +drm_connector_helper_add (&connector->base, &vkms_conn_helper_funcs);return connector; }
drivers/gpu/drm/vkms/vkms_connector.h +10 -1
@@ -5,6 +5,15 @@#include "vkms_drv.h" +/** +* struct vkms_connector - VKMS custom type wrapping around the DRM connector +* +* @drm: Base DRM connector +*/ +struct vkms_connector { +struct drm_connector base; +}; +/** * vkms_connector_init() - Initialize a connector * @vkmsdev: VKMS device containing the connector
@@ -12,6 +21,6 @@* Returns: * The connector or an error on failure. */ -struct drm_connector *vkms_connector_init (struct vkms_device *vkmsdev); +struct vkms_connector *vkms_connector_init (struct vkms_device *vkmsdev);#endif /* _VKMS_CONNECTOR_H_ */
drivers/gpu/drm/vkms/vkms_output.c +2 -2
@@ -7,7 +7,7 @@int vkms_output_init (struct vkms_device *vkmsdev) {struct drm_device *dev = &vkmsdev->drm; -struct drm_connector *connector; +struct vkms_connector *connector;struct drm_encoder *encoder;struct vkms_output *output;struct vkms_plane *primary, *overlay, *cursor =NULL ;
@@ -69,7 +69,7 @@ int vkms_output_init(struct vkms_device *vkmsdev) encoder->possible_crtcs =drm_crtc_mask (&output->crtc);/* Attach the encoder and the connector */ - ret =drm_connector_attach_encoder (connector, encoder); + ret =drm_connector_attach_encoder (&connector->base, encoder);if (ret) {DRM_ERROR ("Failed to attach connector to encoder\n" );return ret;
Signature · 1 line
2.48.1
PATCH v2 4/15 drm/vkms: Add KUnit test scaffolding
In reply to José ExpósitoAdd the required boilerplate to start creating KUnit test.
To run the tests:
$ ./tools/testing/kunit/kunit.py run \
--kunitconfig=drivers/gpu/drm/vkms/tests--- drivers/gpu/drm/vkms/Kconfig | 15 +++++++++++++++ drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/tests/.kunitconfig | 4 ++++ drivers/gpu/drm/vkms/tests/Makefile | 3 +++ drivers/gpu/drm/vkms/tests/vkms_config_test.c | 19 +++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 drivers/gpu/drm/vkms/tests/.kunitconfig create mode 100644 drivers/gpu/drm/vkms/tests/Makefile create mode 100644 drivers/gpu/drm/vkms/tests/vkms_config_test.c
drivers/gpu/drm/vkms/Kconfig +15 -0
@@ -14,3 +14,18 @@ config DRM_VKMS a VKMS. If M is selected the module will be called vkms. + +config DRM_VKMS_KUNIT_TESTS + tristate "KUnit tests for VKMS." if !KUNIT_ALL_TESTS + depends on DRM_VKMS && KUNIT + default KUNIT_ALL_TESTS + help + This builds unit tests for VKMS. This option is not useful for + distributions or general kernels, but only for kernel + developers working on VKMS. + + For more information on KUnit and unit tests in general, + please refer to the KUnit documentation in + Documentation/dev-tools/kunit/. + + If in doubt, say "N".
drivers/gpu/drm/vkms/Makefile +1 -0
@@ -10,3 +10,4 @@ vkms-y := \ vkms_connector.o obj-$(CONFIG_DRM_VKMS) += vkms.o +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) += tests/
drivers/gpu/drm/vkms/tests/.kunitconfig new file +4 -0
@@ -0,0 +1,4 @@ +CONFIG_KUNIT=y +CONFIG_DRM=y +CONFIG_DRM_VKMS=y +CONFIG_DRM_VKMS_KUNIT_TESTS=y
drivers/gpu/drm/vkms/tests/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) += vkms_config_test.o
drivers/gpu/drm/vkms/tests/vkms_config_test.c new file +19 -0
@@ -0,0 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include <kunit/test.h> + +MODULE_IMPORT_NS ("EXPORTED_FOR_KUNIT_TESTING" ); + +static struct kunit_case vkms_config_test_cases[] = { + {} +}; + +static struct kunit_suite vkms_config_test_suite = { + .name ="vkms-config" , + .test_cases = vkms_config_test_cases, +}; + +kunit_test_suite (vkms_config_test_suite); + +MODULE_LICENSE ("GPL" ); +MODULE_DESCRIPTION ("Kunit test for vkms config utility" );
Signature · 1 line
2.48.1
Re: [PATCH v2 04/15] drm/vkms: Add KUnit test scaffolding
Quoted 28 lines · José Expósito
Add the required boilerplate to start creating KUnit test.
To run the tests:
$ ./tools/testing/kunit/kunit.py run \ --kunitconfig=drivers/gpu/drm/vkms/testsCo-developed-by Arthur Grillo <[email protected]>Signed-off-by Arthur Grillo <[email protected]>Co-developed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Signed-off-by José Expósito <[email protected]>--- drivers/gpu/drm/vkms/Kconfig | 15 +++++++++++++++ drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/tests/.kunitconfig | 4 ++++ drivers/gpu/drm/vkms/tests/Makefile | 3 +++ drivers/gpu/drm/vkms/tests/vkms_config_test.c | 19 +++++++++++++++++++ 5 files changed, 42 insertions(+) create mode 100644 drivers/gpu/drm/vkms/tests/.kunitconfig create mode 100644 drivers/gpu/drm/vkms/tests/Makefile create mode 100644 drivers/gpu/drm/vkms/tests/vkms_config_test.cdrivers/gpu/drm/vkms/Kconfig +0
-0
drivers/gpu/drm/vkms/Kconfig config DRM_VKMS · line 19
Quoted 6 lines
drivers/gpu/drm/vkms/Kconfig +3
-0@@ -14,3 +14,18 @@ config DRM_VKMS a VKMS. If M is selected the module will be called vkms. + +config DRM_VKMS_KUNIT_TESTS + tristate "KUnit tests for VKMS." if !KUNIT_ALL_TESTS
If there is a v3, can you remove the dot?
With or without this:
Thanks,
Louis Chauvet
PATCH v2 5/15 drm/vkms: Extract vkms_config header
In reply to José ExpósitoCreating a new vkms_config structure will be more complex once we start adding more options.
Extract the vkms_config structure to its own header and source files and add functions to create and delete a vkms_config and to initialize debugfs.
Refactor, no functional changes.
--- drivers/gpu/drm/vkms/Makefile | 3 +- drivers/gpu/drm/vkms/tests/vkms_config_test.c | 13 +++++ drivers/gpu/drm/vkms/vkms_config.c | 47 +++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 47 +++++++++++++++++++ drivers/gpu/drm/vkms/vkms_drv.c | 34 +++----------- drivers/gpu/drm/vkms/vkms_drv.h | 15 +----- drivers/gpu/drm/vkms/vkms_output.c | 1 + 7 files changed, 118 insertions(+), 42 deletions(-) create mode 100644 drivers/gpu/drm/vkms/vkms_config.c create mode 100644 drivers/gpu/drm/vkms/vkms_config.h
drivers/gpu/drm/vkms/Makefile +2 -1
@@ -7,7 +7,8 @@ vkms-y := \ vkms_crtc.o \ vkms_composer.o \ vkms_writeback.o \ - vkms_connector.o + vkms_connector.o \ + vkms_config.o obj-$(CONFIG_DRM_VKMS) += vkms.o obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) += tests/
drivers/gpu/drm/vkms/tests/vkms_config_test.c +13 -0
@@ -2,9 +2,22 @@#include <kunit/test.h> +#include "../vkms_config.h" +MODULE_IMPORT_NS ("EXPORTED_FOR_KUNIT_TESTING" ); +static void vkms_config_test_empty_config (struct kunit *test) +{ +struct vkms_config *config; + + config =vkms_config_create (); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + +vkms_config_destroy (config); +} +static struct kunit_case vkms_config_test_cases[] = { +KUNIT_CASE (vkms_config_test_empty_config), {} };
drivers/gpu/drm/vkms/vkms_config.c new file +47 -0
47 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.h new file +47 -0
47 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_drv.c +7 -27
@@ -27,11 +27,9 @@#include <drm/drm_gem_shmem_helper.h> #include <drm/drm_vblank.h> +#include "vkms_config.h" #include "vkms_drv.h" -#include <drm/drm_print.h> -#include <drm/drm_debugfs.h> -#define DRIVER_NAME "vkms"#define DRIVER_DESC "Virtual Kernel Mode Setting"#define DRIVER_MAJOR 1
@@ -81,23 +79,6 @@ static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state)drm_atomic_helper_cleanup_planes (dev, old_state); } -static int vkms_config_show (struct seq_file *m,void *data) -{ -struct drm_debugfs_entry *entry = m->private; -struct drm_device *dev = entry->dev; -struct vkms_device *vkmsdev =drm_device_to_vkms_device (dev); - -seq_printf (m,"writeback=%d\n" , vkmsdev->config->writeback); -seq_printf (m,"cursor=%d\n" , vkmsdev->config->cursor); -seq_printf (m,"overlay=%d\n" , vkmsdev->config->overlay); - -return 0 ; -} - -static const struct drm_debugfs_info vkms_config_debugfs_list[] = { - {"vkms_config" , vkms_config_show,0 }, -}; -static const struct drm_driver vkms_driver = { .driver_features =DRIVER_MODESET |DRIVER_ATOMIC |DRIVER_GEM , .fops = &vkms_driver_fops,
@@ -208,8 +189,7 @@ static int vkms_create(struct vkms_config *config)if (ret) goto out_devres; -drm_debugfs_add_files (&vkms_device->drm, vkms_config_debugfs_list, -ARRAY_SIZE (vkms_config_debugfs_list)); +vkms_config_register_debugfs (vkms_device); ret =drm_dev_register (&vkms_device->drm,0 );if (ret)
@@ -231,9 +211,9 @@ static int __init vkms_init(void)int ret;struct vkms_config *config; - config =kmalloc (sizeof (*config),GFP_KERNEL ); -if (!config) -return -ENOMEM ; + config =vkms_config_create (); +if (IS_ERR (config)) +return PTR_ERR (config); config->cursor = enable_cursor; config->writeback = enable_writeback;
@@ -241,7 +221,7 @@ static int __init vkms_init(void) ret =vkms_create (config);if (ret) { -kfree (config); +vkms_config_destroy (config);return ret; }
@@ -275,7 +255,7 @@ static void __exit vkms_exit(void)return ;vkms_destroy (default_config); -kfree (default_config); +vkms_config_destroy (default_config); }module_init (vkms_init);
drivers/gpu/drm/vkms/vkms_drv.h +1 -14
@@ -189,20 +189,7 @@ struct vkms_output {spinlock_t composer_lock; }; -/** -* struct vkms_config - General configuration for VKMS driver -* -* @writeback: If true, a writeback buffer can be attached to the CRTC -* @cursor: If true, a cursor plane is created in the VKMS device -* @overlay: If true, NUM_OVERLAY_PLANES will be created for the VKMS device -* @dev: Used to store the current VKMS device. Only set when the device is instantiated. -*/ -struct vkms_config { -bool writeback; -bool cursor; -bool overlay; -struct vkms_device *dev; -}; +struct vkms_config ;/** * struct vkms_device - Description of a VKMS device
drivers/gpu/drm/vkms/vkms_output.c +1 -0
@@ -1,5 +1,6 @@// SPDX-License-Identifier: GPL-2.0+ +#include "vkms_config.h" #include "vkms_connector.h" #include "vkms_drv.h" #include <drm/drm_managed.h>
Signature · 1 line
2.48.1
Re: [PATCH v2 05/15] drm/vkms: Extract vkms_config header
Quoted 7 lines · José Expósito
Creating a new
vkms_configstructure will be more complex once we start adding more options.Extract the
vkms_configstructure to its own header and source files and add functions to create and delete avkms_configand to initialize debugfs.
Quoted 5 lines
Refactor, no functional changes.
Co-developed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Signed-off-by José Expósito <[email protected]>
This does not build in module, can you add this in the next version?
drivers/gpu/drm/vkms/vkms_config.c +3 -0
@@ -4,6 +4,7 @@#include <drm/drm_print.h> #include <drm/drm_debugfs.h> +#include <kunit/visibility.h> #include "vkms_config.h"
@@ -17,11 +18,13 @@ struct vkms_config *vkms_config_create(void)return config; } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_create);void vkms_config_destroy (struct vkms_config *config) {kfree (config); } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_destroy);static int vkms_config_show (struct seq_file *m,void *data) {
With this:
Re: [PATCH v2 05/15] drm/vkms: Extract vkms_config header
Quoted 8 lines · Louis Chauvet
Quoted 7 lines · José Expósito
Creating a new
vkms_configstructure will be more complex once we start adding more options.Extract the
vkms_configstructure to its own header and source files and add functions to create and delete avkms_configand to initialize debugfs.
Quoted 7 lines
Quoted 5 lines
Refactor, no functional changes.
Co-developed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Signed-off-by José Expósito <[email protected]>This does not build in module, can you add this in the next version?
Interesting. I have "CONFIG_DRM_VKMS=m" in my config and it compiles here.
What do you have as module? CONFIG_DRM_VKMS_KUNIT_TESTS=m?
I'll rebuild every patch to make sure there are no errors.
Thanks for the heads up!
Jose
Quoted 30 lines
drivers/gpu/drm/vkms/vkms_config.c +3
-0@@ -4,6 +4,7 @@#include <drm/drm_print.h> #include <drm/drm_debugfs.h> +#include <kunit/visibility.h> #include "vkms_config.h" @@ -17,11 +18,13 @@ struct vkms_config *vkms_config_create(void)return config; } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_create);void vkms_config_destroy (struct vkms_config *config) {kfree (config); } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_destroy);static int vkms_config_show (struct seq_file *m,void *data) {With this:
Reviewed-by Louis Chauvet <[email protected]>
Louis Chauvet
maintainerRe: [PATCH v2 05/15] drm/vkms: Extract vkms_config header
Le 13/02/2025 à 16:36, José Expósito a écrit :
Quoted 15 lines · Louis Chauvet
Quoted 14 lines · José Expósito
Quoted 12 lines
Creating a new
vkms_configstructure will be more complex once we start adding more options.Extract the
vkms_configstructure to its own header and source files and add functions to create and delete avkms_configand to initialize debugfs.Refactor, no functional changes.
Co-developed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Signed-off-by José Expósito <[email protected]>
Quoted 5 lines
Quoted 1 line
This does not build in module, can you add this in the next version?
Interesting. I have "
CONFIG_DRM_VKMS=m" in my config and it compiles here.What do you have as module?
CONFIG_DRM_VKMS_KUNIT_TESTS=m?
Yes sorry, I forgot to say it was for kunit tests. I just saw your other mail, thank you for the fix on all patches!
Louis Chauvet
Quoted 35 lines
I'll rebuild every patch to make sure there are no errors.
Thanks for the heads up!
JoseQuoted 30 lines
drivers/gpu/drm/vkms/vkms_config.c +3
-0@@ -4,6 +4,7 @@#include <drm/drm_print.h> #include <drm/drm_debugfs.h> +#include <kunit/visibility.h> #include "vkms_config.h" @@ -17,11 +18,13 @@ struct vkms_config *vkms_config_create(void)return config; } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_create);void vkms_config_destroy (struct vkms_config *config) {kfree (config); } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_destroy);static int vkms_config_show (struct seq_file *m,void *data) {With this:
Reviewed-by Louis Chauvet <[email protected]>
Signature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH v2 6/15 drm/vkms: Move default_config creation to its own function
In reply to José ExpósitoExtract the initialization of the default configuration to a function. Refactor, no functional changes.
--- drivers/gpu/drm/vkms/tests/vkms_config_test.c | 38 +++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.c | 17 +++++++++ drivers/gpu/drm/vkms/vkms_config.h | 14 +++++++ drivers/gpu/drm/vkms/vkms_drv.c | 6 +-- 4 files changed, 70 insertions(+), 5 deletions(-)
drivers/gpu/drm/vkms/tests/vkms_config_test.c +38 -0
@@ -6,6 +6,12 @@MODULE_IMPORT_NS ("EXPORTED_FOR_KUNIT_TESTING" ); +struct default_config_case { +bool enable_cursor; +bool enable_writeback; +bool enable_overlay; +}; +static void vkms_config_test_empty_config (struct kunit *test) {struct vkms_config *config;
@@ -16,8 +22,40 @@ static void vkms_config_test_empty_config(struct kunit *test)vkms_config_destroy (config); } +static struct default_config_case default_config_cases[] = { + { false, false, false }, + { true, false, false }, + { true, true, false }, + { true, false, true }, + { false, true, false }, + { false, true, true }, + { false, false, true }, + { true, true, true }, +}; + +KUNIT_ARRAY_PARAM (default_config, default_config_cases,NULL ); + +static void vkms_config_test_default_config (struct kunit *test) +{ +const struct default_config_case *params = test->param_value; +struct vkms_config *config; + + config =vkms_config_default_create (params->enable_cursor, + params->enable_writeback, + params->enable_overlay); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + +KUNIT_EXPECT_EQ (test, config->cursor, params->enable_cursor); +KUNIT_EXPECT_EQ (test, config->writeback, params->enable_writeback); +KUNIT_EXPECT_EQ (test, config->overlay, params->enable_overlay); + +vkms_config_destroy (config); +} +static struct kunit_case vkms_config_test_cases[] = {KUNIT_CASE (vkms_config_test_empty_config), +KUNIT_CASE_PARAM (vkms_config_test_default_config, + default_config_gen_params), {} };
drivers/gpu/drm/vkms/vkms_config.c +17 -0
@@ -18,6 +18,23 @@ struct vkms_config *vkms_config_create(void)return config; } +struct vkms_config *vkms_config_default_create (bool enable_cursor, +bool enable_writeback, +bool enable_overlay) +{ +struct vkms_config *config; + + config =vkms_config_create (); +if (IS_ERR (config)) +return config; + + config->cursor = enable_cursor; + config->writeback = enable_writeback; + config->overlay = enable_overlay; + +return config; +} +void vkms_config_destroy (struct vkms_config *config) {kfree (config);
drivers/gpu/drm/vkms/vkms_config.h +14 -0
@@ -31,6 +31,20 @@ struct vkms_config {*/ struct vkms_config *vkms_config_create (void ); +/** +* vkms_config_default_create() - Create the configuration for the default device +* @enable_cursor: Create or not a cursor plane +* @enable_writeback: Create or not a writeback connector +* @enable_overlay: Create or not overlay planes +* +* Returns: +* The default vkms_config or an error. Call vkms_config_destroy() to free the +* returned configuration. +*/ +struct vkms_config *vkms_config_default_create (bool enable_cursor, +bool enable_writeback, +bool enable_overlay); +/** * vkms_config_destroy() - Free a VKMS configuration * @config: vkms_config to free
drivers/gpu/drm/vkms/vkms_drv.c +1 -5
@@ -211,14 +211,10 @@ static int __init vkms_init(void)int ret;struct vkms_config *config; - config =vkms_config_create (); + config =vkms_config_default_create (enable_cursor, enable_writeback, enable_overlay);if (IS_ERR (config))return PTR_ERR (config); - config->cursor = enable_cursor; - config->writeback = enable_writeback; - config->overlay = enable_overlay; - ret =vkms_create (config);if (ret) {vkms_config_destroy (config);
Signature · 1 line
2.48.1
Louis Chauvet
maintainerRe: [PATCH v2 06/15] drm/vkms: Move default_config creation to its own function
Quoted 7 lines · José Expósito
Extract the initialization of the default configuration to a function. Refactor, no functional changes.
Reviewed-by Louis Chauvet <[email protected]>Co-developed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Signed-off-by José Expósito <[email protected]>
I just tested to build vkms in module, and it does not works. Can you add this for the next iteration?
drivers/gpu/drm/vkms/vkms_config.c +1 -0
@@ -36,6 +36,7 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor,return config; } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_default_create);void vkms_config_destroy (struct vkms_config *config) {
Thanks,
Louis Chauvet
PATCH v2 7/15 drm/vkms: Set device name from vkms_config
In reply to José ExpósitoIn order to be able to create multiple devices, the device name needs to be unique.
Allow to set it in the VKMS configuration.
--- drivers/gpu/drm/vkms/tests/vkms_config_test.c | 7 ++++++- drivers/gpu/drm/vkms/vkms_config.c | 14 ++++++++++++-- drivers/gpu/drm/vkms/vkms_config.h | 18 +++++++++++++++++- drivers/gpu/drm/vkms/vkms_drv.c | 4 +++- drivers/gpu/drm/vkms/vkms_drv.h | 2 ++ 5 files changed, 40 insertions(+), 5 deletions(-)
drivers/gpu/drm/vkms/tests/vkms_config_test.c +6 -1
@@ -15,10 +15,15 @@ struct default_config_case {static void vkms_config_test_empty_config (struct kunit *test) {struct vkms_config *config; +const char *dev_name ="test" ; - config =vkms_config_create (); + config =vkms_config_create (dev_name);KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); +/* The dev_name string and the config have different lifetimes */ + dev_name =NULL ; +KUNIT_EXPECT_STREQ (test,vkms_config_get_device_name (config),"test" ); +vkms_config_destroy (config); }
drivers/gpu/drm/vkms/vkms_config.c +12 -2
@@ -7,7 +7,7 @@#include "vkms_config.h" -struct vkms_config *vkms_config_create (void ) +struct vkms_config *vkms_config_create (const char *dev_name) {struct vkms_config *config;
@@ -15,6 +15,12 @@ struct vkms_config *vkms_config_create(void)if (!config)return ERR_PTR (-ENOMEM ); + config->dev_name =kstrdup_const (dev_name,GFP_KERNEL ); +if (!config->dev_name) { +kfree (config); +return ERR_PTR (-ENOMEM ); + } +return config; }
@@ -24,7 +30,7 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor, {struct vkms_config *config; - config =vkms_config_create (); + config =vkms_config_create (DEFAULT_DEVICE_NAME );if (IS_ERR (config))return config;
@@ -37,6 +43,7 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor,void vkms_config_destroy (struct vkms_config *config) { +kfree_const (config->dev_name);kfree (config); }
@@ -45,7 +52,10 @@ static int vkms_config_show(struct seq_file *m, void *data)struct drm_debugfs_entry *entry = m->private;struct drm_device *dev = entry->dev;struct vkms_device *vkmsdev =drm_device_to_vkms_device (dev); +const char *dev_name; + dev_name =vkms_config_get_device_name ((struct vkms_config *)vkmsdev->config); +seq_printf (m,"dev_name=%s\n" , dev_name);seq_printf (m,"writeback=%d\n" , vkmsdev->config->writeback);seq_printf (m,"cursor=%d\n" , vkmsdev->config->cursor);seq_printf (m,"overlay=%d\n" , vkmsdev->config->overlay);
drivers/gpu/drm/vkms/vkms_config.h +17 -1
@@ -10,12 +10,14 @@/** * struct vkms_config - General configuration for VKMS driver * +* @dev_name: Name of the device * @writeback: If true, a writeback buffer can be attached to the CRTC * @cursor: If true, a cursor plane is created in the VKMS device * @overlay: If true, NUM_OVERLAY_PLANES will be created for the VKMS device * @dev: Used to store the current VKMS device. Only set when the device is instantiated. */ struct vkms_config { +const char *dev_name;bool writeback;bool cursor;bool overlay;
@@ -24,12 +26,13 @@ struct vkms_config {/** * vkms_config_create() - Create a new VKMS configuration +* @dev_name: Name of the device * * Returns: * The new vkms_config or an error. Call vkms_config_destroy() to free the * returned configuration. */ -struct vkms_config *vkms_config_create (void ); +struct vkms_config *vkms_config_create (const char *dev_name);/** * vkms_config_default_create() - Create the configuration for the default device
@@ -51,6 +54,19 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor,*/ void vkms_config_destroy (struct vkms_config *config); +/** +* vkms_config_get_device_name() - Return the name of the device +* @config: Configuration to get the device name from +* +* Returns: +* The device name. Only valid while @config is valid. +*/ +static inline const char * +vkms_config_get_device_name (struct vkms_config *config) +{ +return config->dev_name; +} +/** * vkms_config_register_debugfs() - Register a debugfs file to show the device's * configuration
drivers/gpu/drm/vkms/vkms_drv.c +3 -1
@@ -151,8 +151,10 @@ static int vkms_create(struct vkms_config *config)int ret;struct platform_device *pdev;struct vkms_device *vkms_device; +const char *dev_name; - pdev =platform_device_register_simple (DRIVER_NAME ,-1 ,NULL ,0 ); + dev_name =vkms_config_get_device_name (config); + pdev =platform_device_register_simple (dev_name,-1 ,NULL ,0 );if (IS_ERR (pdev))return PTR_ERR (pdev);
drivers/gpu/drm/vkms/vkms_drv.h +2 -0
@@ -12,6 +12,8 @@#include <drm/drm_encoder.h> #include <drm/drm_writeback.h> +#define DEFAULT_DEVICE_NAME "vkms" +#define XRES_MIN 10#define YRES_MIN 10
Signature · 1 line
2.48.1
PATCH v2 8/15 drm/vkms: Add a validation function for VKMS configuration
In reply to José ExpósitoFrom: Louis Chauvet <[email protected]>
As the configuration will be used by userspace, add a validator to avoid creating a broken DRM device.
For the moment, the function always returns true, but rules will be added in future patches.
--- drivers/gpu/drm/vkms/tests/vkms_config_test.c | 2 ++ drivers/gpu/drm/vkms/vkms_config.c | 5 +++++ drivers/gpu/drm/vkms/vkms_config.h | 10 ++++++++++ drivers/gpu/drm/vkms/vkms_drv.h | 2 +- drivers/gpu/drm/vkms/vkms_output.c | 3 +++ 5 files changed, 21 insertions(+), 1 deletion(-)
drivers/gpu/drm/vkms/tests/vkms_config_test.c +2 -0
@@ -54,6 +54,8 @@ static void vkms_config_test_default_config(struct kunit *test)KUNIT_EXPECT_EQ (test, config->writeback, params->enable_writeback);KUNIT_EXPECT_EQ (test, config->overlay, params->enable_overlay); +KUNIT_EXPECT_TRUE (test,vkms_config_is_valid (config)); +vkms_config_destroy (config); }
drivers/gpu/drm/vkms/vkms_config.c +5 -0
@@ -47,6 +47,11 @@ void vkms_config_destroy(struct vkms_config *config)kfree (config); } +bool vkms_config_is_valid (struct vkms_config *config) +{ +return true; +} +static int vkms_config_show (struct seq_file *m,void *data) {struct drm_debugfs_entry *entry = m->private;
drivers/gpu/drm/vkms/vkms_config.h +10 -0
@@ -67,6 +67,16 @@ vkms_config_get_device_name(struct vkms_config *config)return config->dev_name; } +/** +* vkms_config_is_valid() - Validate a configuration +* @config: Configuration to validate +* +* Returns: +* Whether the configuration is valid or not. +* For example, a configuration without primary planes is not valid. +*/ +bool vkms_config_is_valid (struct vkms_config *config); +/** * vkms_config_register_debugfs() - Register a debugfs file to show the device's * configuration
drivers/gpu/drm/vkms/vkms_drv.h +1 -1
@@ -204,7 +204,7 @@ struct vkms_config;struct vkms_device {struct drm_device drm;struct platform_device *platform; -const struct vkms_config *config; +struct vkms_config *config; };/*
drivers/gpu/drm/vkms/vkms_output.c +3 -0
@@ -16,6 +16,9 @@ int vkms_output_init(struct vkms_device *vkmsdev)int writeback;unsigned int n; +if (!vkms_config_is_valid (vkmsdev->config)) +return -EINVAL ; +/* * Initialize used plane. One primary plane is required to perform the composition. *
Signature · 1 line
2.48.1
Louis Chauvet
maintainerRe: [PATCH v2 08/15] drm/vkms: Add a validation function for VKMS configuration
Quoted 5 lines · José Expósito
From: Louis Chauvet <[email protected]>
As the configuration will be used by userspace, add a validator to avoid creating a broken DRM device.
Quoted 7 lines
For the moment, the function always returns true, but rules will be added in future patches.
Reviewed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Co-developed-by José Expósito <[email protected]>Signed-off-by José Expósito <[email protected]>
The compilation is broken when building as module:
drivers/gpu/drm/vkms/vkms_config.c +1 -0
@@ -55,6 +55,7 @@ bool vkms_config_is_valid(struct vkms_config *config) {return true; } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_is_valid);static int vkms_config_show (struct seq_file *m,void *data) {
Quoted 45 lines
--- drivers/gpu/drm/vkms/tests/vkms_config_test.c | 2 ++ drivers/gpu/drm/vkms/vkms_config.c | 5 +++++ drivers/gpu/drm/vkms/vkms_config.h | 10 ++++++++++ drivers/gpu/drm/vkms/vkms_drv.h | 2 +- drivers/gpu/drm/vkms/vkms_output.c | 3 +++ 5 files changed, 21 insertions(+), 1 deletion(-)drivers/gpu/drm/vkms/tests/vkms_config_test.c +2
-0@@ -54,6 +54,8 @@ static void vkms_config_test_default_config(struct kunit *test)KUNIT_EXPECT_EQ (test, config->writeback, params->enable_writeback);KUNIT_EXPECT_EQ (test, config->overlay, params->enable_overlay); +KUNIT_EXPECT_TRUE (test,vkms_config_is_valid (config)); +vkms_config_destroy (config); }drivers/gpu/drm/vkms/vkms_config.c +5
-0@@ -47,6 +47,11 @@ void vkms_config_destroy(struct vkms_config *config)kfree (config); } +bool vkms_config_is_valid (struct vkms_config *config) +{ +return true; +} +static int vkms_config_show (struct seq_file *m,void *data) {struct drm_debugfs_entry *entry = m->private;drivers/gpu/drm/vkms/vkms_config.h +0
-0@@ -67,6 +67,16 @@ vkms_config_get_device_name(struct vkms_config *config)return config->dev_name; }
drivers/gpu/drm/vkms/vkms_config.h vkms_config_get_device_name(struct vkms_config *config) · line 79
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_config.h +10
-0+/** +* vkms_config_is_valid() - Validate a configuration +* @config: Configuration to validate +* +* Returns: +* Whether the configuration is valid or not. +* For example, a configuration without primary planes is not valid. +*/ +bool vkms_config_is_valid (struct vkms_config *config); +
I think here we can take a const pointer.
drivers/gpu/drm/vkms/vkms_drv.h struct vkms_config; · line 207
Quoted 13 lines
drivers/gpu/drm/vkms/vkms_config.h +0
-0/** * vkms_config_register_debugfs() - Register a debugfs file to show the device's * configuration drivers/gpu/drm/vkms/vkms_drv.h +1
-1@@ -204,7 +204,7 @@ struct vkms_config;struct vkms_device {struct drm_device drm;struct platform_device *platform; -const struct vkms_config *config; +struct vkms_config *config;
So we can keep a const pointer here (for me the device should never modify vkms_config)
Quoted 20 lines
drivers/gpu/drm/vkms/vkms_drv.h +0
-0};/* drivers/gpu/drm/vkms/vkms_output.c +3
-0@@ -16,6 +16,9 @@ int vkms_output_init(struct vkms_device *vkmsdev)int writeback;unsigned int n; +if (!vkms_config_is_valid (vkmsdev->config)) +return -EINVAL ; +/* * Initialize used plane. One primary plane is required to perform the composition. * Signature · 1 line
2.48.1
Re: [PATCH v2 08/15] drm/vkms: Add a validation function for VKMS configuration
Quoted 22 lines · Louis Chauvet
Quoted 5 lines · José Expósito
From: Louis Chauvet <[email protected]>
As the configuration will be used by userspace, add a validator to avoid creating a broken DRM device.
Quoted 7 lines
For the moment, the function always returns true, but rules will be added in future patches.
Reviewed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Co-developed-by José Expósito <[email protected]>Signed-off-by José Expósito <[email protected]>The compilation is broken when building as module:
drivers/gpu/drm/vkms/vkms_config.c +0
-0
drivers/gpu/drm/vkms/vkms_config.c bool vkms_config_is_valid(struct vkms_config *config) · line 58
Quoted 4 lines
drivers/gpu/drm/vkms/vkms_config.c +1
-0@@ -55,6 +55,7 @@ bool vkms_config_is_valid(struct vkms_config *config) {return true; } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_is_valid);
Fixed the issue in all patches, thanks!
Quoted 23 lines
Quoted 10 lines
[...]
drivers/gpu/drm/vkms/vkms_config.h +0
-0@@ -67,6 +67,16 @@ vkms_config_get_device_name(struct vkms_config *config)return config->dev_name; }drivers/gpu/drm/vkms/vkms_config.h vkms_config_get_device_name(struct vkms_config *config) · line 79
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_config.h +10
-0+/** +* vkms_config_is_valid() - Validate a configuration +* @config: Configuration to validate +* +* Returns: +* Whether the configuration is valid or not. +* For example, a configuration without primary planes is not valid. +*/ +bool vkms_config_is_valid (struct vkms_config *config); +I think here we can take a const pointer.
Quoted 16 lines
drivers/gpu/drm/vkms/vkms_drv.h struct vkms_config; · line 207
Quoted 13 lines
drivers/gpu/drm/vkms/vkms_config.h +0
-0/** * vkms_config_register_debugfs() - Register a debugfs file to show the device's * configuration drivers/gpu/drm/vkms/vkms_drv.h +1
-1@@ -204,7 +204,7 @@ struct vkms_config;struct vkms_device {struct drm_device drm;struct platform_device *platform; -const struct vkms_config *config; +struct vkms_config *config;So we can keep a const pointer here (for me the device should never modify
vkms_config)
I tryed keeping the const pointer, but, since list_count_nodes() is used in several valid_* functions and it takes a non-const pointer, it causes warnings.
We can fix them with a cast:
n_planes = list_count_nodes((struct list_head *)&config->planes);
But I feel that keeping the "const" creates more issues than it solves.
Anyway, if you prefer this pointer to be const, I will change it in v3.
Jose
Quoted 20 lines
Quoted 20 lines
drivers/gpu/drm/vkms/vkms_drv.h +0
-0};/* drivers/gpu/drm/vkms/vkms_output.c +3
-0@@ -16,6 +16,9 @@ int vkms_output_init(struct vkms_device *vkmsdev)int writeback;unsigned int n; +if (!vkms_config_is_valid (vkmsdev->config)) +return -EINVAL ; +/* * Initialize used plane. One primary plane is required to perform the composition. * Signature · 1 line
2.48.1
Louis Chauvet
maintainerRe: [PATCH v2 08/15] drm/vkms: Add a validation function for VKMS configuration
Le 14/02/2025 à 16:53, José Expósito a écrit :
Quoted 70 lines · Louis Chauvet
Quoted 22 lines · José Expósito
Quoted 5 lines
From: Louis Chauvet <[email protected]>
As the configuration will be used by userspace, add a validator to avoid creating a broken DRM device.
Quoted 7 lines
For the moment, the function always returns true, but rules will be added in future patches.
Reviewed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Co-developed-by José Expósito <[email protected]>Signed-off-by José Expósito <[email protected]>The compilation is broken when building as module:
drivers/gpu/drm/vkms/vkms_config.c +0
-0drivers/gpu/drm/vkms/vkms_config.c bool vkms_config_is_valid(struct vkms_config *config) · line 58
Quoted 4 lines
drivers/gpu/drm/vkms/vkms_config.c +1
-0@@ -55,6 +55,7 @@ bool vkms_config_is_valid(struct vkms_config *config) {return true; } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_is_valid);Fixed the issue in all patches, thanks!
Quoted 23 lines
Quoted 10 lines
[...]
drivers/gpu/drm/vkms/vkms_config.h +0
-0@@ -67,6 +67,16 @@ vkms_config_get_device_name(struct vkms_config *config)return config->dev_name; }drivers/gpu/drm/vkms/vkms_config.h vkms_config_get_device_name(struct vkms_config *config) · line 79
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_config.h +10
-0+/** +* vkms_config_is_valid() - Validate a configuration +* @config: Configuration to validate +* +* Returns: +* Whether the configuration is valid or not. +* For example, a configuration without primary planes is not valid. +*/ +bool vkms_config_is_valid (struct vkms_config *config); +I think here we can take a const pointer.
Quoted 16 lines
drivers/gpu/drm/vkms/vkms_drv.h struct vkms_config; · line 207
Quoted 13 lines
drivers/gpu/drm/vkms/vkms_config.h +0
-0/** * vkms_config_register_debugfs() - Register a debugfs file to show the device's * configuration drivers/gpu/drm/vkms/vkms_drv.h +1
-1@@ -204,7 +204,7 @@ struct vkms_config;struct vkms_device {struct drm_device drm;struct platform_device *platform; -const struct vkms_config *config; +struct vkms_config *config;So we can keep a const pointer here (for me the device should never modify
vkms_config)
Quoted 3 lines
I tryed keeping the const pointer, but, since
list_count_nodes()is used in several valid_* functions and it takes a non-const pointer, it causes warnings.
I did not see this issue, and obviously no casting is better!
But I don't understand why list_count_node needs a non-const pointer. I just compile-tested an allyesconfig with a const parameter, it seems to works without issue (no warning, at least on x86_64, I just started some build on other architectures to check most of the drivers).
I will submit a patch next week to make the list_count_nodes parameter const.
Quoted 7 lines
We can fix them with a cast:
n_planes = list_count_nodes((struct list_head *)&config->planes);But I feel that keeping the "const" creates more issues than it solves.
Anyway, if you prefer this pointer to be const, I will change it in v3.
Please use a const pointer + cast, and we will remove it once the list_count_nodes patch is merged.
Thanks,
Louis Chauvet
Quoted 22 lines
Jose
Quoted 20 lines
Quoted 20 lines
drivers/gpu/drm/vkms/vkms_drv.h +0
-0};/* drivers/gpu/drm/vkms/vkms_output.c +3
-0@@ -16,6 +16,9 @@ int vkms_output_init(struct vkms_device *vkmsdev)int writeback;unsigned int n; +if (!vkms_config_is_valid (vkmsdev->config)) +return -EINVAL ; +/* * Initialize used plane. One primary plane is required to perform the composition. * Signature · 1 line
2.48.1
Signature · 3 lines
Louis Chauvet, Bootlin Embedded Linux and Kernel engineering https://bootlin.com
PATCH v2 9/15 drm/vkms: Allow to configure multiple planes
In reply to José ExpósitoAdd a list of planes to vkms_config and create as many planes as configured during output initialization.
For backwards compatibility, add one primary plane and, if configured, one cursor plane and NUM_OVERLAY_PLANES planes to the default configuration.
--- .clang-format | 1 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 140 +++++++++++++++++- drivers/gpu/drm/vkms/vkms_config.c | 124 +++++++++++++++- drivers/gpu/drm/vkms/vkms_config.h | 73 ++++++++- drivers/gpu/drm/vkms/vkms_output.c | 42 ++---- 5 files changed, 344 insertions(+), 36 deletions(-)
.clang-format +1 -0
@@ -690,6 +690,7 @@ ForEachMacros: - 'v4l2_m2m_for_each_src_buf' - 'v4l2_m2m_for_each_src_buf_safe' - 'virtio_device_for_each_vq' + - 'vkms_config_for_each_plane' - 'while_for_each_ftrace_op' - 'xa_for_each' - 'xa_for_each_marked'
drivers/gpu/drm/vkms/tests/vkms_config_test.c +138 -2
166 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.c +120 -4
167 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.h +69 -4
97 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_output.c +16 -26
61 lines not on this page · raw message
Signature · 1 line
2.48.1
Louis Chauvet
maintainerRe: [PATCH v2 09/15] drm/vkms: Allow to configure multiple planes
Quoted 10 lines · José Expósito
Add a list of planes to
vkms_configand create as many planes as configured during output initialization.For backwards compatibility, add one primary plane and, if configured, one cursor plane and
NUM_OVERLAY_PLANESplanes to the default configuration.Co-developed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Signed-off-by José Expósito <[email protected]>
Build is broken as module:
drivers/gpu/drm/vkms/vkms_config.c +2 -0
@@ -192,9 +192,11 @@ struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *config)return plane_cfg; } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_create_plane);void vkms_config_destroy_plane (struct vkms_config_plane *plane_cfg) {list_del (&plane_cfg->link);kfree (plane_cfg); } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_destroy_plane);
Quoted 13 lines
--- .clang-format | 1 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 140 +++++++++++++++++- drivers/gpu/drm/vkms/vkms_config.c | 124 +++++++++++++++- drivers/gpu/drm/vkms/vkms_config.h | 73 ++++++++- drivers/gpu/drm/vkms/vkms_output.c | 42 ++---- 5 files changed, 344 insertions(+), 36 deletions(-).clang-format +0
-0
.clang-format ForEachMacros: · line 696
Quoted 7 lines
.clang-format +1
-0@@ -690,6 +690,7 @@ ForEachMacros: - 'v4l2_m2m_for_each_src_buf' - 'v4l2_m2m_for_each_src_buf_safe' - 'virtio_device_for_each_vq' + - 'vkms_config_for_each_plane' - 'while_for_each_ftrace_op' - 'xa_for_each' - 'xa_for_each_marked'
I did not know about this, perfect!
Quoted 25 lines
drivers/gpu/drm/vkms/tests/vkms_config_test.c +8
-0@@ -24,6 +24,10 @@ static void vkms_config_test_empty_config(struct kunit *test) dev_name =NULL ;KUNIT_EXPECT_STREQ (test,vkms_config_get_device_name (config),"test" ); +KUNIT_EXPECT_TRUE (test,list_empty (&config->planes)); + +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); +vkms_config_destroy (config); }@@ -44,16 +48,145 @@ static void vkms_config_test_default_config(struct kunit *test) {const struct default_config_case *params = test->param_value;struct vkms_config *config; +struct vkms_config_plane *plane_cfg; +int n_primaries =0 ; +int n_cursors =0 ; +int n_overlays =0 ; config = vkms_config_default_create(params->enable_cursor,
drivers/gpu/drm/vkms/tests/vkms_config_test.c static void vkms_config_test_default_config(struct kunit *test) · line 64
Quoted 10 lines
drivers/gpu/drm/vkms/tests/vkms_config_test.c +2
-2params->enable_writeback, params->enable_overlay);KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); -KUNIT_EXPECT_EQ (test, config->cursor, params->enable_cursor);KUNIT_EXPECT_EQ (test, config->writeback, params->enable_writeback); -KUNIT_EXPECT_EQ (test, config->overlay, params->enable_overlay); +/* Planes */ +list_for_each_entry (plane_cfg, &config->planes, link) {
Why you don't use vkms_config_for_each_plane here?
Quoted 199 lines
drivers/gpu/drm/vkms/tests/vkms_config_test.c +128
-0+switch (vkms_config_plane_get_type (plane_cfg)) { +case DRM_PLANE_TYPE_PRIMARY : + n_primaries++; +break ; +case DRM_PLANE_TYPE_CURSOR : + n_cursors++; +break ; +case DRM_PLANE_TYPE_OVERLAY : + n_overlays++; +break ; +default : +KUNIT_FAIL_AND_ABORT (test,"Unknown plane type" ); + } + } +KUNIT_EXPECT_EQ (test, n_primaries,1 ); +KUNIT_EXPECT_EQ (test, n_cursors, params->enable_cursor ?1 :0 ); +KUNIT_EXPECT_EQ (test, n_overlays, params->enable_overlay ?8 :0 ); + +KUNIT_EXPECT_TRUE (test,vkms_config_is_valid (config)); + +vkms_config_destroy (config); +} + +static void vkms_config_test_get_planes (struct kunit *test) +{ +struct vkms_config *config; +struct vkms_config_plane *plane_cfg; +struct vkms_config_plane *plane_cfg1, *plane_cfg2; +int n_planes =0 ; + + config =vkms_config_create ("test" ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + +vkms_config_for_each_plane (config, plane_cfg) + n_planes++; +KUNIT_ASSERT_EQ (test, n_planes,0 ); + + plane_cfg1 =vkms_config_create_plane (config); +vkms_config_for_each_plane (config, plane_cfg) { + n_planes++; +if (plane_cfg != plane_cfg1) +KUNIT_FAIL (test,"Unexpected plane" ); + } +KUNIT_ASSERT_EQ (test, n_planes,1 ); + n_planes =0 ; + + plane_cfg2 =vkms_config_create_plane (config); +vkms_config_for_each_plane (config, plane_cfg) { + n_planes++; +if (plane_cfg != plane_cfg1 && plane_cfg != plane_cfg2) +KUNIT_FAIL (test,"Unexpected plane" ); + } +KUNIT_ASSERT_EQ (test, n_planes,2 ); + n_planes =0 ; + +vkms_config_destroy_plane (plane_cfg1); +vkms_config_for_each_plane (config, plane_cfg) { + n_planes++; +if (plane_cfg != plane_cfg2) +KUNIT_FAIL (test,"Unexpected plane" ); + } +KUNIT_ASSERT_EQ (test, n_planes,1 ); + +vkms_config_destroy (config); +} + +static void vkms_config_test_invalid_plane_number (struct kunit *test) +{ +struct vkms_config *config; +struct vkms_config_plane *plane_cfg; +int n; + + config =vkms_config_default_create (false, false, false); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + +/* Invalid: No planes */ + plane_cfg =list_first_entry (&config->planes,typeof (*plane_cfg), link); +vkms_config_destroy_plane (plane_cfg); +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +/* Invalid: Too many planes */ +for (n =0 ; n <=32 ; n++) +vkms_config_create_plane (config); + +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +vkms_config_destroy (config); +} + +static void vkms_config_test_valid_plane_type (struct kunit *test) +{ +struct vkms_config *config; +struct vkms_config_plane *plane_cfg; + + config =vkms_config_default_create (false, false, false); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + + plane_cfg =list_first_entry (&config->planes,typeof (*plane_cfg), link); +vkms_config_destroy_plane (plane_cfg); + +/* Invalid: No primary plane */ + plane_cfg =vkms_config_create_plane (config); +vkms_config_plane_set_type (plane_cfg,DRM_PLANE_TYPE_OVERLAY ); +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +/* Invalid: Multiple primary planes */ + plane_cfg =vkms_config_create_plane (config); +vkms_config_plane_set_type (plane_cfg,DRM_PLANE_TYPE_PRIMARY ); + plane_cfg =vkms_config_create_plane (config); +vkms_config_plane_set_type (plane_cfg,DRM_PLANE_TYPE_PRIMARY ); +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +/* Valid: One primary plane */ +vkms_config_destroy_plane (plane_cfg); +KUNIT_EXPECT_TRUE (test,vkms_config_is_valid (config)); + +/* Invalid: Multiple cursor planes */ + plane_cfg =vkms_config_create_plane (config); +vkms_config_plane_set_type (plane_cfg,DRM_PLANE_TYPE_CURSOR ); + plane_cfg =vkms_config_create_plane (config); +vkms_config_plane_set_type (plane_cfg,DRM_PLANE_TYPE_CURSOR ); +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +/* Valid: One primary and one cursor plane */ +vkms_config_destroy_plane (plane_cfg);KUNIT_EXPECT_TRUE (test,vkms_config_is_valid (config));vkms_config_destroy (config);@@ -63,6 +196,9 @@ static struct kunit_case vkms_config_test_cases[] = {KUNIT_CASE (vkms_config_test_empty_config),KUNIT_CASE_PARAM (vkms_config_test_default_config, default_config_gen_params), +KUNIT_CASE (vkms_config_test_get_planes), +KUNIT_CASE (vkms_config_test_invalid_plane_number), + KUNIT_CASE(vkms_config_test_valid_plane_type), {} };drivers/gpu/drm/vkms/vkms_config.c +32
-2@@ -21,6 +21,8 @@ struct vkms_config *vkms_config_create(const char *dev_name)return ERR_PTR (-ENOMEM ); } +INIT_LIST_HEAD (&config->planes); +return config; }@@ -29,26 +31,114 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor, bool enable_overlay) {struct vkms_config *config; +struct vkms_config_plane *plane_cfg; +int n; config =vkms_config_create (DEFAULT_DEVICE_NAME );if (IS_ERR (config))return config; - config->cursor = enable_cursor; config->writeback = enable_writeback; - config->overlay = enable_overlay; + + plane_cfg =vkms_config_create_plane (config); +if (IS_ERR (plane_cfg)) + goto err_alloc; +vkms_config_plane_set_type (plane_cfg,DRM_PLANE_TYPE_PRIMARY ); + +if (enable_overlay) { +for (n =0 ; n <NUM_OVERLAY_PLANES ; n++) { + plane_cfg =vkms_config_create_plane (config); +if (IS_ERR (plane_cfg)) + goto err_alloc; +vkms_config_plane_set_type (plane_cfg, +DRM_PLANE_TYPE_OVERLAY ); + } + } + +if (enable_cursor) { + plane_cfg =vkms_config_create_plane (config); +if (IS_ERR (plane_cfg)) + goto err_alloc; +vkms_config_plane_set_type (plane_cfg,DRM_PLANE_TYPE_CURSOR ); + }return config; + +err_alloc: +vkms_config_destroy (config); +return ERR_PTR (-ENOMEM ); }void vkms_config_destroy (struct vkms_config *config) { +struct vkms_config_plane *plane_cfg, *plane_tmp; +
drivers/gpu/drm/vkms/vkms_config.c struct vkms_config *vkms_config_default_create(bool enable_cursor, · line 85
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_config.c +6
-0+list_for_each_entry_safe (plane_cfg, plane_tmp, &config->planes, link) +vkms_config_destroy_plane (plane_cfg); +kfree_const (config->dev_name);kfree (config); } +static bool valid_plane_number (struct vkms_config *config) +{ +struct drm_device *dev = &config->dev->drm;
I think config->dev is not always set at this point. Can you change to
config->dev ? config->dev->drm : NULL
Quoted 4 lines
drivers/gpu/drm/vkms/vkms_config.c +4
-0+size_t n_planes; + + n_planes =list_count_nodes (&config->planes); +if (n_planes <=0 || n_planes >=32 ) {
drivers/gpu/drm/vkms/vkms_config.c struct vkms_config *vkms_config_default_create(bool enable_cursor, · line 99
Quoted 10 lines
drivers/gpu/drm/vkms/vkms_config.c +10
-0+drm_info (dev,"The number of planes must be between 1 and 31\n" ); +return false; + } + +return true; +} + +static bool valid_plane_type (struct vkms_config *config) +{ +struct drm_device *dev = &config->dev->drm;
ditto
Quoted 264 lines
drivers/gpu/drm/vkms/vkms_config.c +68
-2+struct vkms_config_plane *plane_cfg; +bool has_primary_plane = false; +bool has_cursor_plane = false; + +vkms_config_for_each_plane (config, plane_cfg) { +enum drm_plane_type type; + + type =vkms_config_plane_get_type (plane_cfg); + +if (type ==DRM_PLANE_TYPE_PRIMARY ) { +if (has_primary_plane) { +drm_info (dev,"Multiple primary planes\n" ); +return false; + } + + has_primary_plane = true; + }else if (type ==DRM_PLANE_TYPE_CURSOR ) { +if (has_cursor_plane) { +drm_info (dev,"Multiple cursor planes\n" ); +return false; + } + + has_cursor_plane = true; + } + } + +if (!has_primary_plane) { +drm_info (dev,"Primary plane not found\n" ); +return false; + } + +return true; +} +bool vkms_config_is_valid (struct vkms_config *config) { +if (!valid_plane_number (config)) +return false; + +if (!valid_plane_type (config)) +return false; +return true; }@@ -58,12 +148,17 @@ 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);const char *dev_name; +struct vkms_config_plane *plane_cfg; dev_name =vkms_config_get_device_name ((struct vkms_config *)vkmsdev->config);seq_printf (m,"dev_name=%s\n" , dev_name);seq_printf (m,"writeback=%d\n" , vkmsdev->config->writeback); -seq_printf (m,"cursor=%d\n" , vkmsdev->config->cursor); -seq_printf (m,"overlay=%d\n" , vkmsdev->config->overlay); + +vkms_config_for_each_plane (vkmsdev->config, plane_cfg) { +seq_puts (m,"plane:\n" ); +seq_printf (m,"\ttype=%d\n" , +vkms_config_plane_get_type (plane_cfg)); + }return 0 ; }@@ -77,3 +172,24 @@ void vkms_config_register_debugfs(struct vkms_device *vkms_device)drm_debugfs_add_files (&vkms_device->drm, vkms_config_debugfs_list,ARRAY_SIZE (vkms_config_debugfs_list)); } + +struct vkms_config_plane *vkms_config_create_plane (struct vkms_config *config) +{ +struct vkms_config_plane *plane_cfg; + + plane_cfg =kzalloc (sizeof (*plane_cfg),GFP_KERNEL ); +if (!plane_cfg) +return ERR_PTR (-ENOMEM ); + +vkms_config_plane_set_type (plane_cfg,DRM_PLANE_TYPE_OVERLAY ); + +list_add_tail (&plane_cfg->link, &config->planes); + +return plane_cfg; +} + +void vkms_config_destroy_plane (struct vkms_config_plane *plane_cfg) +{ +list_del (&plane_cfg->link); +kfree (plane_cfg); +}drivers/gpu/drm/vkms/vkms_config.h +69
-4@@ -3,6 +3,7 @@#ifndef _VKMS_CONFIG_H_#define _VKMS_CONFIG_H_ +#include <linux/list.h> #include <linux/types.h> #include "vkms_drv.h" @@ -12,18 +13,44 @@* * @dev_name: Name of the device * @writeback: If true, a writeback buffer can be attached to the CRTC -* @cursor: If true, a cursor plane is created in the VKMS device -* @overlay: If true, NUM_OVERLAY_PLANES will be created for the VKMS device +* @planes: List of planes configured for the device * @dev: Used to store the current VKMS device. Only set when the device is instantiated. */ struct vkms_config {const char *dev_name;bool writeback; -bool cursor; -bool overlay; +struct list_head planes;struct vkms_device *dev; }; +/** +* struct vkms_config_plane +* +* @link: Link to the others planes in vkms_config +* @type: Type of the plane. The creator of configuration needs to ensures that +* at least one primary plane is present. +* @plane: Internal usage. This pointer should never be considered as valid. +* It can be used to store a temporary reference to a VKMS plane during +* device creation. This pointer is not managed by the configuration and +* must be managed by other means. +*/ +struct vkms_config_plane { +struct list_head link; + +enum drm_plane_type type; + +/* Internal usage */ +struct vkms_plane *plane; +}; + +/** +* vkms_config_for_each_plane - Iterate over the vkms_config planes +* @config: &struct vkms_config pointer +* @plane_cfg: &struct vkms_config_plane pointer used as cursor +*/ +#define vkms_config_for_each_plane (config, plane_cfg) \ + list_for_each_entry((plane_cfg), &(config)->planes, link) +/** * vkms_config_create() - Create a new VKMS configuration * @dev_name: Name of the device @@ -84,4 +111,42 @@ bool vkms_config_is_valid(struct vkms_config *config);*/ void vkms_config_register_debugfs (struct vkms_device *vkms_device); +/** +* vkms_config_create_plane() - Add a new plane configuration +* @config: Configuration to add the plane to +* +* Returns: +* The new plane configuration or an error. Call vkms_config_destroy_plane() to +* free the returned plane configuration. +*/ +struct vkms_config_plane *vkms_config_create_plane (struct vkms_config *config); + +/** +* vkms_config_destroy_plane() - Remove and free a plane configuration +* @plane_cfg: Plane configuration to destroy +*/ +void vkms_config_destroy_plane (struct vkms_config_plane *plane_cfg); + +/** +* vkms_config_plane_type() - Return the plane type +* @plane_cfg: Plane to get the type from +*/ +static inline enum drm_plane_type +vkms_config_plane_get_type (struct vkms_config_plane *plane_cfg) +{ +return plane_cfg->type; +} + +/** +* vkms_config_plane_set_type() - Set the plane type +* @plane_cfg: Plane to set the type to +* @type: New plane type +*/ +static inline void +vkms_config_plane_set_type (struct vkms_config_plane *plane_cfg, +enum drm_plane_type type) +{ + plane_cfg->type = type; +} +#endif /* _VKMS_CONFIG_H_ */ drivers/gpu/drm/vkms/vkms_output.c +16
-26@@ -11,28 +11,29 @@ int vkms_output_init(struct vkms_device *vkmsdev)struct vkms_connector *connector;struct drm_encoder *encoder;struct vkms_output *output; -struct vkms_plane *primary, *overlay, *cursor =NULL ; +struct vkms_plane *primary =NULL , *cursor =NULL ; +struct vkms_config_plane *plane_cfg;int ret;int writeback; -unsigned int n;if (!vkms_config_is_valid (vkmsdev->config))return -EINVAL ; -/* -* Initialize used plane. One primary plane is required to perform the composition. -* -* The overlay and cursor planes are not mandatory, but can be used to perform complex -* composition. -*/ - primary =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_PRIMARY ); -if (IS_ERR (primary)) -return PTR_ERR (primary); +vkms_config_for_each_plane (vkmsdev->config, plane_cfg) { +enum drm_plane_type type; -if (vkmsdev->config->cursor) { - cursor =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_CURSOR ); -if (IS_ERR (cursor)) -return PTR_ERR (cursor); + type =vkms_config_plane_get_type (plane_cfg); + + plane_cfg->plane =vkms_plane_init (vkmsdev, type); +if (IS_ERR (plane_cfg->plane)) { +DRM_DEV_ERROR (dev->dev,"Failed to init vkms plane\n" ); +return PTR_ERR (plane_cfg->plane); + } + +if (type ==DRM_PLANE_TYPE_PRIMARY ) + primary = plane_cfg->plane; +else if (type ==DRM_PLANE_TYPE_CURSOR ) + cursor = plane_cfg->plane; } output = vkms_crtc_init(dev, &primary->base,@@ -42,17 +43,6 @@ int vkms_output_init(struct vkms_device *vkmsdev)return PTR_ERR (output); } -if (vkmsdev->config->overlay) { -for (n =0 ; n <NUM_OVERLAY_PLANES ; n++) { - overlay =vkms_plane_init (vkmsdev,DRM_PLANE_TYPE_OVERLAY ); -if (IS_ERR (overlay)) { -DRM_DEV_ERROR (dev->dev,"Failed to init vkms plane\n" ); -return PTR_ERR (overlay); - } - overlay->base.possible_crtcs =drm_crtc_mask (&output->crtc); - } - } - connector =vkms_connector_init (vkmsdev);if (IS_ERR (connector)) {DRM_ERROR ("Failed to init connector\n" );Signature · 1 line
2.48.1
PATCH v2 10/15 drm/vkms: Allow to configure multiple CRTCs
In reply to José ExpósitoAdd a list of CRTCs to vkms_config and helper functions to add and remove as many CRTCs as wanted.
For backwards compatibility, add one CRTC to the default configuration.
A future patch will allow to attach planes and CRTCs, but for the moment there are no changes in the way the output is configured.
--- .clang-format | 1 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 73 ++++++++++++++++- drivers/gpu/drm/vkms/vkms_config.c | 60 +++++++++++++- drivers/gpu/drm/vkms/vkms_config.h | 78 +++++++++++++++++++ drivers/gpu/drm/vkms/vkms_drv.c | 3 +- 5 files changed, 209 insertions(+), 6 deletions(-)
.clang-format +1 -0
@@ -690,6 +690,7 @@ ForEachMacros: - 'v4l2_m2m_for_each_src_buf' - 'v4l2_m2m_for_each_src_buf_safe' - 'virtio_device_for_each_vq' + - 'vkms_config_for_each_crtc' - 'vkms_config_for_each_plane' - 'while_for_each_ftrace_op' - 'xa_for_each'
drivers/gpu/drm/vkms/tests/vkms_config_test.c +71 -2
116 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.c +57 -3
122 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.h +78 -0
112 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_drv.c +2 -1
@@ -181,7 +181,8 @@ static int vkms_create(struct vkms_config *config) goto out_devres; } - ret =drm_vblank_init (&vkms_device->drm,1 ); + ret =drm_vblank_init (&vkms_device->drm, +vkms_config_get_num_crtcs (config));if (ret) {DRM_ERROR ("Failed to vblank\n" ); goto out_devres;
Signature · 1 line
2.48.1
Louis Chauvet
maintainerRe: [PATCH v2 10/15] drm/vkms: Allow to configure multiple CRTCs
Quoted 11 lines · José Expósito
Add a list of CRTCs to
vkms_configand helper functions to add and remove as many CRTCs as wanted.For backwards compatibility, add one CRTC to the default configuration.
A future patch will allow to attach planes and CRTCs, but for the moment there are no changes in the way the output is configured.
Co-developed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Signed-off-by José Expósito <[email protected]>
Build broken as module:
drivers/gpu/drm/vkms/vkms_config.c +2 -0
@@ -247,6 +247,7 @@ struct vkms_config_crtc *vkms_config_create_crtc(struct vkms_config *config)return crtc_cfg; } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_create_crtc);void vkms_config_destroy_crtc (struct vkms_config *config,struct vkms_config_crtc *crtc_cfg)
@@ -254,3 +255,4 @@ void vkms_config_destroy_crtc(struct vkms_config *config,list_del (&crtc_cfg->link);kfree (crtc_cfg); } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_destroy_crtc);
Quoted 50 lines
--- .clang-format | 1 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 73 ++++++++++++++++- drivers/gpu/drm/vkms/vkms_config.c | 60 +++++++++++++- drivers/gpu/drm/vkms/vkms_config.h | 78 +++++++++++++++++++ drivers/gpu/drm/vkms/vkms_drv.c | 3 +- 5 files changed, 209 insertions(+), 6 deletions(-).clang-format +1
-0@@ -690,6 +690,7 @@ ForEachMacros: - 'v4l2_m2m_for_each_src_buf' - 'v4l2_m2m_for_each_src_buf_safe' - 'virtio_device_for_each_vq' + - 'vkms_config_for_each_crtc' - 'vkms_config_for_each_plane' - 'while_for_each_ftrace_op' - 'xa_for_each'drivers/gpu/drm/vkms/tests/vkms_config_test.c +2
-2@@ -25,6 +25,7 @@ static void vkms_config_test_empty_config(struct kunit *test)KUNIT_EXPECT_STREQ (test,vkms_config_get_device_name (config),"test" );KUNIT_EXPECT_TRUE (test,list_empty (&config->planes)); +KUNIT_EXPECT_TRUE (test,list_empty (&config->crtcs));KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config));@@ -49,6 +50,7 @@ static void vkms_config_test_default_config(struct kunit *test)const struct default_config_case *params = test->param_value;struct vkms_config *config;struct vkms_config_plane *plane_cfg; +struct vkms_config_crtc *crtc_cfg;int n_primaries =0 ;int n_cursors =0 ;int n_overlays =0 ;@@ -58,8 +60,6 @@ static void vkms_config_test_default_config(struct kunit *test) params->enable_overlay);KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); -KUNIT_EXPECT_EQ (test, config->writeback, params->enable_writeback); -/* Planes */ list_for_each_entry (plane_cfg, &config->planes, link) {switch (vkms_config_plane_get_type (plane_cfg)) {
drivers/gpu/drm/vkms/tests/vkms_config_test.c static void vkms_config_test_default_config(struct kunit *test) · line 86
Quoted 7 lines
drivers/gpu/drm/vkms/tests/vkms_config_test.c +4
-0@@ -80,6 +80,13 @@ static void vkms_config_test_default_config(struct kunit *test)KUNIT_EXPECT_EQ (test, n_cursors, params->enable_cursor ?1 :0 );KUNIT_EXPECT_EQ (test, n_overlays, params->enable_overlay ?8 :0 ); +/* CRTCs */ + crtc_cfg =list_first_entry (&config->crtcs,typeof (*crtc_cfg), link); + +KUNIT_EXPECT_EQ (test,list_count_nodes (&config->crtcs),1 );
Can you switch the two lines? First test we only have one crtc, then get it.
Quoted 348 lines
drivers/gpu/drm/vkms/tests/vkms_config_test.c +65
-0+KUNIT_EXPECT_EQ (test,vkms_config_crtc_get_writeback (crtc_cfg), + params->enable_writeback); +KUNIT_EXPECT_TRUE (test,vkms_config_is_valid (config));vkms_config_destroy (config);@@ -128,6 +135,43 @@ static void vkms_config_test_get_planes(struct kunit *test)vkms_config_destroy (config); } +static void vkms_config_test_get_crtcs (struct kunit *test) +{ +struct vkms_config *config; +struct vkms_config_crtc *crtc_cfg; +struct vkms_config_crtc *crtc_cfg1, *crtc_cfg2; + + config =vkms_config_create ("test" ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + +KUNIT_ASSERT_EQ (test,vkms_config_get_num_crtcs (config),0 ); +vkms_config_for_each_crtc (config, crtc_cfg) +KUNIT_FAIL (test,"Unexpected CRTC" ); + + crtc_cfg1 =vkms_config_create_crtc (config); +KUNIT_ASSERT_EQ (test,vkms_config_get_num_crtcs (config),1 ); +vkms_config_for_each_crtc (config, crtc_cfg) { +if (crtc_cfg != crtc_cfg1) +KUNIT_FAIL (test,"Unexpected CRTC" ); + } + + crtc_cfg2 =vkms_config_create_crtc (config); +KUNIT_ASSERT_EQ (test,vkms_config_get_num_crtcs (config),2 ); +vkms_config_for_each_crtc (config, crtc_cfg) { +if (crtc_cfg != crtc_cfg1 && crtc_cfg != crtc_cfg2) +KUNIT_FAIL (test,"Unexpected CRTC" ); + } + +vkms_config_destroy_crtc (config, crtc_cfg2); +KUNIT_ASSERT_EQ (test,vkms_config_get_num_crtcs (config),1 ); +vkms_config_for_each_crtc (config, crtc_cfg) { +if (crtc_cfg != crtc_cfg1) +KUNIT_FAIL (test,"Unexpected CRTC" ); + } + +vkms_config_destroy (config); +} +static void vkms_config_test_invalid_plane_number (struct kunit *test) {struct vkms_config *config;@@ -192,13 +236,38 @@ static void vkms_config_test_valid_plane_type(struct kunit *test)vkms_config_destroy (config); } +static void vkms_config_test_invalid_crtc_number (struct kunit *test) +{ +struct vkms_config *config; +struct vkms_config_crtc *crtc_cfg; +int n; + + config =vkms_config_default_create (false, false, false); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + +/* Invalid: No CRTCs */ + crtc_cfg =list_first_entry (&config->crtcs,typeof (*crtc_cfg), link); +vkms_config_destroy_crtc (config, crtc_cfg); +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +/* Invalid: Too many CRTCs */ +for (n =0 ; n <=32 ; n++) +vkms_config_create_crtc (config); + +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +vkms_config_destroy (config); +} +static struct kunit_case vkms_config_test_cases[] = {KUNIT_CASE (vkms_config_test_empty_config),KUNIT_CASE_PARAM (vkms_config_test_default_config, default_config_gen_params),KUNIT_CASE (vkms_config_test_get_planes), +KUNIT_CASE (vkms_config_test_get_crtcs),KUNIT_CASE (vkms_config_test_invalid_plane_number),KUNIT_CASE (vkms_config_test_valid_plane_type), +KUNIT_CASE (vkms_config_test_invalid_crtc_number), {} };drivers/gpu/drm/vkms/vkms_config.c +57
-3@@ -22,6 +22,7 @@ struct vkms_config *vkms_config_create(const char *dev_name) }INIT_LIST_HEAD (&config->planes); +INIT_LIST_HEAD (&config->crtcs);return config; }@@ -32,19 +33,23 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor, {struct vkms_config *config;struct vkms_config_plane *plane_cfg; +struct vkms_config_crtc *crtc_cfg;int n; config =vkms_config_create (DEFAULT_DEVICE_NAME );if (IS_ERR (config))return config; - config->writeback = enable_writeback; - plane_cfg =vkms_config_create_plane (config);if (IS_ERR (plane_cfg)) goto err_alloc;vkms_config_plane_set_type (plane_cfg,DRM_PLANE_TYPE_PRIMARY ); + crtc_cfg =vkms_config_create_crtc (config); +if (IS_ERR (crtc_cfg)) + goto err_alloc; +vkms_config_crtc_set_writeback (crtc_cfg, enable_writeback); +if (enable_overlay) {for (n =0 ; n <NUM_OVERLAY_PLANES ; n++) { plane_cfg =vkms_config_create_plane (config);@@ -72,10 +77,14 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor,void vkms_config_destroy (struct vkms_config *config) {struct vkms_config_plane *plane_cfg, *plane_tmp; +struct vkms_config_crtc *crtc_cfg, *crtc_tmp;list_for_each_entry_safe (plane_cfg, plane_tmp, &config->planes, link)vkms_config_destroy_plane (plane_cfg); +list_for_each_entry_safe (crtc_cfg, crtc_tmp, &config->crtcs, link) +vkms_config_destroy_crtc (config, crtc_cfg); +kfree_const (config->dev_name);kfree (config); }@@ -131,11 +140,28 @@ static bool valid_plane_type(struct vkms_config *config)return true; } +static bool valid_crtc_number (struct vkms_config *config) +{ +struct drm_device *dev = &config->dev->drm; +size_t n_crtcs; + + n_crtcs =list_count_nodes (&config->crtcs); +if (n_crtcs <=0 || n_crtcs >=32 ) { +drm_info (dev,"The number of CRTCs must be between 1 and 31\n" ); +return false; + } + +return true; +} +bool vkms_config_is_valid (struct vkms_config *config) {if (!valid_plane_number (config))return false; +if (!valid_crtc_number (config)) +return false; +if (!valid_plane_type (config))return false;@@ -149,10 +175,10 @@ static int vkms_config_show(struct seq_file *m, void *data)struct vkms_device *vkmsdev =drm_device_to_vkms_device (dev);const char *dev_name;struct vkms_config_plane *plane_cfg; +struct vkms_config_crtc *crtc_cfg; dev_name =vkms_config_get_device_name ((struct vkms_config *)vkmsdev->config);seq_printf (m,"dev_name=%s\n" , dev_name); -seq_printf (m,"writeback=%d\n" , vkmsdev->config->writeback);vkms_config_for_each_plane (vkmsdev->config, plane_cfg) {seq_puts (m,"plane:\n" );@@ -160,6 +186,12 @@ static int vkms_config_show(struct seq_file *m, void *data) vkms_config_plane_get_type(plane_cfg)); } +vkms_config_for_each_crtc (vkmsdev->config, crtc_cfg) { +seq_puts (m,"crtc:\n" ); +seq_printf (m,"\twriteback=%d\n" , +vkms_config_crtc_get_writeback (crtc_cfg)); + } +return 0 ; }@@ -193,3 +225,25 @@ void vkms_config_destroy_plane(struct vkms_config_plane *plane_cfg)list_del (&plane_cfg->link);kfree (plane_cfg); } + +struct vkms_config_crtc *vkms_config_create_crtc (struct vkms_config *config) +{ +struct vkms_config_crtc *crtc_cfg; + + crtc_cfg =kzalloc (sizeof (*crtc_cfg),GFP_KERNEL ); +if (!crtc_cfg) +return ERR_PTR (-ENOMEM ); + +vkms_config_crtc_set_writeback (crtc_cfg, false); + +list_add_tail (&crtc_cfg->link, &config->crtcs); + +return crtc_cfg; +} + +void vkms_config_destroy_crtc (struct vkms_config *config, +struct vkms_config_crtc *crtc_cfg) +{ +list_del (&crtc_cfg->link); +kfree (crtc_cfg); +}drivers/gpu/drm/vkms/vkms_config.h +78
-0@@ -14,12 +14,14 @@* @dev_name: Name of the device * @writeback: If true, a writeback buffer can be attached to the CRTC * @planes: List of planes configured for the device +* @crtcs: List of CRTCs configured for the device * @dev: Used to store the current VKMS device. Only set when the device is instantiated. */ struct vkms_config {const char *dev_name;bool writeback;struct list_head planes; +struct list_head crtcs;struct vkms_device *dev; };@@ -43,6 +45,25 @@ struct vkms_config_plane {struct vkms_plane *plane; }; +/** +* struct vkms_config_crtc +* +* @link: Link to the others CRTCs in vkms_config +* @writeback: If true, a writeback buffer can be attached to the CRTC +* @crtc: Internal usage. This pointer should never be considered as valid. +* It can be used to store a temporary reference to a VKMS CRTC during +* device creation. This pointer is not managed by the configuration and +* must be managed by other means. +*/ +struct vkms_config_crtc { +struct list_head link; + +bool writeback; + +/* Internal usage */ +struct vkms_output *crtc; +}; +/** * vkms_config_for_each_plane - Iterate over the vkms_config planes * @config: &struct vkms_config pointer @@ -51,6 +72,14 @@ struct vkms_config_plane {#define vkms_config_for_each_plane (config, plane_cfg) \ list_for_each_entry((plane_cfg), &(config)->planes, link) +/** +* vkms_config_for_each_crtc - Iterate over the vkms_config CRTCs +* @config: &struct vkms_config pointer +* @crtc_cfg: &struct vkms_config_crtc pointer used as cursor +*/ +#define vkms_config_for_each_crtc (config, crtc_cfg) \ + list_for_each_entry((crtc_cfg), &(config)->crtcs, link) +/** * vkms_config_create() - Create a new VKMS configuration * @dev_name: Name of the device @@ -94,6 +123,15 @@ vkms_config_get_device_name(struct vkms_config *config)return config->dev_name; } +/** +* vkms_config_get_num_crtcs() - Return the number of CRTCs in the configuration +* @config: Configuration to get the number of CRTCs from +*/ +static inline size_t vkms_config_get_num_crtcs (struct vkms_config *config) +{ +return list_count_nodes (&config->crtcs); +} +/** * vkms_config_is_valid() - Validate a configuration * @config: Configuration to validate @@ -149,4 +187,44 @@ vkms_config_plane_set_type(struct vkms_config_plane *plane_cfg, plane_cfg->type = type; } +/** +* vkms_config_create_crtc() - Add a new CRTC configuration +* @config: Configuration to add the CRTC to +* +* Returns: +* The new CRTC configuration or an error. Call vkms_config_destroy_crtc() to +* free the returned CRTC configuration. +*/ +struct vkms_config_crtc *vkms_config_create_crtc (struct vkms_config *config); + +/** +* vkms_config_destroy_crtc() - Remove and free a CRTC configuration +* @config: Configuration to remove the CRTC from +* @crtc_cfg: CRTC configuration to destroy +*/ +void vkms_config_destroy_crtc (struct vkms_config *config, +struct vkms_config_crtc *crtc_cfg); + +/** +* vkms_config_crtc_get_writeback() - If a writeback connector will be created +* @crtc_cfg: CRTC with or without a writeback connector +*/ +static inline bool +vkms_config_crtc_get_writeback (struct vkms_config_crtc *crtc_cfg) +{ +return crtc_cfg->writeback; +} + +/** +* vkms_config_crtc_set_writeback() - If a writeback connector will be created +* @crtc_cfg: Target CRTC +* @writeback: Enable or disable the writeback connector +*/ +static inline void +vkms_config_crtc_set_writeback (struct vkms_config_crtc *crtc_cfg, +bool writeback) +{ + crtc_cfg->writeback = writeback; +} +#endif /* _VKMS_CONFIG_H_ */ drivers/gpu/drm/vkms/vkms_drv.c +0
-0
drivers/gpu/drm/vkms/vkms_drv.c static int vkms_create(struct vkms_config *config) · line 185
Quoted 6 lines
drivers/gpu/drm/vkms/vkms_drv.c +2
-1@@ -181,7 +181,8 @@ static int vkms_create(struct vkms_config *config) goto out_devres; } - ret =drm_vblank_init (&vkms_device->drm,1 ); + ret =drm_vblank_init (&vkms_device->drm, +vkms_config_get_num_crtcs (config));
See my comment on v2, I think we should keep 1 at this point.
Quoted 6 lines
drivers/gpu/drm/vkms/vkms_drv.c +0
-0if (ret) {DRM_ERROR ("Failed to vblank\n" ); goto out_devres;Signature · 1 line
2.48.1
PATCH v2 11/15 drm/vkms: Allow to attach planes and CRTCs
In reply to José ExpósitoAdd a list of possible CRTCs to the plane configuration and helpers to attach, detach and get the primary and cursor planes attached to a CRTC.
Now that the default configuration has its planes and CRTC correctly attached, configure the output following the configuration.
--- .clang-format | 1 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 188 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.c | 147 ++++++++++++-- drivers/gpu/drm/vkms/vkms_config.h | 59 +++++- drivers/gpu/drm/vkms/vkms_output.c | 51 +++-- 5 files changed, 411 insertions(+), 35 deletions(-)
.clang-format +1 -0
@@ -692,6 +692,7 @@ ForEachMacros: - 'virtio_device_for_each_vq' - 'vkms_config_for_each_crtc' - 'vkms_config_for_each_plane' + - 'vkms_config_plane_for_each_possible_crtc' - 'while_for_each_ftrace_op' - 'xa_for_each' - 'xa_for_each_marked'
drivers/gpu/drm/vkms/tests/vkms_config_test.c +188 -0
243 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.c +133 -14
227 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.h +57 -2
105 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_output.c +32 -19
79 lines not on this page · raw message
Signature · 1 line
2.48.1
PATCH v2 12/15 drm/vkms: Allow to configure multiple encoders
In reply to José ExpósitoAdd a list of encoders to vkms_config and helper functions to add and remove as many encoders as wanted.
For backwards compatibility, add one encoder to the default configuration.
A future patch will allow to attach encoders and CRTCs, but for the moment there are no changes in the way the output is configured.
--- .clang-format | 1 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 73 +++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.c | 51 +++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 44 +++++++++++ 4 files changed, 169 insertions(+)
.clang-format +1 -0
@@ -691,6 +691,7 @@ ForEachMacros: - 'v4l2_m2m_for_each_src_buf_safe' - 'virtio_device_for_each_vq' - 'vkms_config_for_each_crtc' + - 'vkms_config_for_each_encoder' - 'vkms_config_for_each_plane' - 'vkms_config_plane_for_each_possible_crtc' - 'while_for_each_ftrace_op'
drivers/gpu/drm/vkms/tests/vkms_config_test.c +73 -0
107 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.c +51 -0
108 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.h +44 -0
72 lines not on this page · raw message
Signature · 1 line
2.48.1
Louis Chauvet
maintainerRe: [PATCH v2 12/15] drm/vkms: Allow to configure multiple encoders
Quoted 6 lines · José Expósito
Add a list of encoders to
vkms_configand helper functions to add and remove as many encoders as wanted.For backwards compatibility, add one encoder to the default configuration.
Quoted 6 lines
A future patch will allow to attach encoders and CRTCs, but for the moment there are no changes in the way the output is configured.
Co-developed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Signed-off-by José Expósito <[email protected]>
The module build is broken:
drivers/gpu/drm/vkms/vkms_config.c +2 -0
@@ -423,6 +423,7 @@ struct vkms_config_encoder *vkms_config_create_encoder(struct vkms_config *confireturn encoder_cfg; } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_create_encoder);void vkms_config_destroy_encoder (struct vkms_config *config,struct vkms_config_encoder *encoder_cfg)
@@ -430,3 +431,4 @@ void vkms_config_destroy_encoder(struct vkms_config *config,list_del (&encoder_cfg->link);kfree (encoder_cfg); } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_destroy_encoder);
Quoted 185 lines
--- .clang-format | 1 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 73 +++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.c | 51 +++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 44 +++++++++++ 4 files changed, 169 insertions(+).clang-format +1
-0@@ -691,6 +691,7 @@ ForEachMacros: - 'v4l2_m2m_for_each_src_buf_safe' - 'virtio_device_for_each_vq' - 'vkms_config_for_each_crtc' + - 'vkms_config_for_each_encoder' - 'vkms_config_for_each_plane' - 'vkms_config_plane_for_each_possible_crtc' - 'while_for_each_ftrace_op'drivers/gpu/drm/vkms/tests/vkms_config_test.c +73
-0@@ -26,6 +26,7 @@ static void vkms_config_test_empty_config(struct kunit *test)KUNIT_EXPECT_TRUE (test,list_empty (&config->planes));KUNIT_EXPECT_TRUE (test,list_empty (&config->crtcs)); +KUNIT_EXPECT_TRUE (test,list_empty (&config->encoders));KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config));@@ -99,6 +100,9 @@ static void vkms_config_test_default_config(struct kunit *test)KUNIT_EXPECT_EQ (test, n_possible_crtcs,1 ); } +/* Encoders */ +KUNIT_EXPECT_EQ (test,list_count_nodes (&config->encoders),1 ); +KUNIT_EXPECT_TRUE (test,vkms_config_is_valid (config));vkms_config_destroy (config);@@ -184,6 +188,50 @@ static void vkms_config_test_get_crtcs(struct kunit *test)vkms_config_destroy (config); } +static void vkms_config_test_get_encoders (struct kunit *test) +{ +struct vkms_config *config; +struct vkms_config_encoder *encoder_cfg; +struct vkms_config_encoder *encoder_cfg1, *encoder_cfg2; +int n_encoders =0 ; + + config =vkms_config_create ("test" ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + +vkms_config_for_each_encoder (config, encoder_cfg) + n_encoders++; +KUNIT_ASSERT_EQ (test, n_encoders,0 ); + + encoder_cfg1 =vkms_config_create_encoder (config); +vkms_config_for_each_encoder (config, encoder_cfg) { + n_encoders++; +if (encoder_cfg != encoder_cfg1) +KUNIT_FAIL (test,"Unexpected encoder" ); + } +KUNIT_ASSERT_EQ (test, n_encoders,1 ); + n_encoders =0 ; + + encoder_cfg2 =vkms_config_create_encoder (config); +vkms_config_for_each_encoder (config, encoder_cfg) { + n_encoders++; +if (encoder_cfg != encoder_cfg1 && encoder_cfg != encoder_cfg2) +KUNIT_FAIL (test,"Unexpected encoder" ); + } +KUNIT_ASSERT_EQ (test, n_encoders,2 ); + n_encoders =0 ; + +vkms_config_destroy_encoder (config, encoder_cfg2); +vkms_config_for_each_encoder (config, encoder_cfg) { + n_encoders++; +if (encoder_cfg != encoder_cfg1) +KUNIT_FAIL (test,"Unexpected encoder" ); + } +KUNIT_ASSERT_EQ (test, n_encoders,1 ); + n_encoders =0 ; + +vkms_config_destroy (config); +} +static void vkms_config_test_invalid_plane_number (struct kunit *test) {struct vkms_config *config;@@ -319,6 +367,29 @@ static void vkms_config_test_invalid_crtc_number(struct kunit *test)vkms_config_destroy (config); } +static void vkms_config_test_invalid_encoder_number (struct kunit *test) +{ +struct vkms_config *config; +struct vkms_config_encoder *encoder_cfg; +int n; + + config =vkms_config_default_create (false, false, false); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + +/* Invalid: No encoders */ + encoder_cfg =list_first_entry (&config->encoders,typeof (*encoder_cfg), link); +vkms_config_destroy_encoder (config, encoder_cfg); +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +/* Invalid: Too many encoders */ +for (n =0 ; n <=32 ; n++) +vkms_config_create_encoder (config); + +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +vkms_config_destroy (config); +} +static void vkms_config_test_plane_attach_crtc (struct kunit *test) {struct vkms_config *config;@@ -450,10 +521,12 @@ static struct kunit_case vkms_config_test_cases[] = { default_config_gen_params),KUNIT_CASE (vkms_config_test_get_planes),KUNIT_CASE (vkms_config_test_get_crtcs), +KUNIT_CASE (vkms_config_test_get_encoders),KUNIT_CASE (vkms_config_test_invalid_plane_number),KUNIT_CASE (vkms_config_test_valid_plane_type),KUNIT_CASE (vkms_config_test_valid_plane_possible_crtcs),KUNIT_CASE (vkms_config_test_invalid_crtc_number), +KUNIT_CASE (vkms_config_test_invalid_encoder_number),KUNIT_CASE (vkms_config_test_plane_attach_crtc), KUNIT_CASE(vkms_config_test_plane_get_possible_crtcs), {}drivers/gpu/drm/vkms/vkms_config.c +10
-0@@ -23,6 +23,7 @@ struct vkms_config *vkms_config_create(const char *dev_name)INIT_LIST_HEAD (&config->planes);INIT_LIST_HEAD (&config->crtcs); +INIT_LIST_HEAD (&config->encoders);return config; }@@ -34,6 +35,7 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor,struct vkms_config *config;struct vkms_config_plane *plane_cfg;struct vkms_config_crtc *crtc_cfg; +struct vkms_config_encoder *encoder_cfg;int n; config =vkms_config_create (DEFAULT_DEVICE_NAME );@@ -78,6 +80,10 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor, goto err_alloc; } + encoder_cfg =vkms_config_create_encoder (config); +if (IS_ERR (encoder_cfg)) + goto err_alloc; +return config; err_alloc:@@ -89,6 +95,7 @@ void vkms_config_destroy(struct vkms_config *config) {struct vkms_config_plane *plane_cfg, *plane_tmp;struct vkms_config_crtc *crtc_cfg, *crtc_tmp; +struct vkms_config_encoder *encoder_cfg, *encoder_tmp;list_for_each_entry_safe (plane_cfg, plane_tmp, &config->planes, link)vkms_config_destroy_plane (plane_cfg);@@ -96,6 +103,9 @@ void vkms_config_destroy(struct vkms_config *config)list_for_each_entry_safe (crtc_cfg, crtc_tmp, &config->crtcs, link)vkms_config_destroy_crtc (config, crtc_cfg); +list_for_each_entry_safe (encoder_cfg, encoder_tmp, &config->encoders, link) +vkms_config_destroy_encoder (config, encoder_cfg); +kfree_const (config->dev_name);kfree (config); }
drivers/gpu/drm/vkms/vkms_config.c static bool valid_crtc_number(struct vkms_config *config) · line 203
Quoted 6 lines
drivers/gpu/drm/vkms/vkms_config.c +3
-0@@ -188,6 +198,20 @@ static bool valid_crtc_number(struct vkms_config *config)return true; } +static bool valid_encoder_number (struct vkms_config *config) +{ +struct drm_device *dev = &config->dev->drm;
Ditto, dev may not be set yet.
Quoted 149 lines
drivers/gpu/drm/vkms/vkms_config.c +38
-0+size_t n_encoders; + + n_encoders =list_count_nodes (&config->encoders); +if (n_encoders <=0 || n_encoders >=32 ) { +drm_info (dev,"The number of encoders must be between 1 and 31\n" ); +return false; + } + +return true; +} +bool vkms_config_is_valid (struct vkms_config *config) {struct vkms_config_crtc *crtc_cfg;@@ -198,6 +222,9 @@ bool vkms_config_is_valid(struct vkms_config *config)if (!valid_crtc_number (config))return false; +if (!valid_encoder_number (config)) +return false; +if (!valid_plane_possible_crtcs (config))return false;@@ -217,6 +244,7 @@ static int vkms_config_show(struct seq_file *m, void *data)const char *dev_name;struct vkms_config_plane *plane_cfg;struct vkms_config_crtc *crtc_cfg; +struct vkms_config_encoder *encoder_cfg; dev_name =vkms_config_get_device_name ((struct vkms_config *)vkmsdev->config);seq_printf (m,"dev_name=%s\n" , dev_name);@@ -233,6 +261,9 @@ static int vkms_config_show(struct seq_file *m, void *data) vkms_config_crtc_get_writeback(crtc_cfg)); } +vkms_config_for_each_encoder (vkmsdev->config, encoder_cfg) +seq_puts (m,"encoder\n" ); +return 0 ; }@@ -366,3 +397,23 @@ struct vkms_config_plane *vkms_config_crtc_cursor_plane(const struct vkms_config {return vkms_config_crtc_get_plane (config, crtc_cfg,DRM_PLANE_TYPE_CURSOR ); } + +struct vkms_config_encoder *vkms_config_create_encoder (struct vkms_config *config) +{ +struct vkms_config_encoder *encoder_cfg; + + encoder_cfg =kzalloc (sizeof (*encoder_cfg),GFP_KERNEL ); +if (!encoder_cfg) +return ERR_PTR (-ENOMEM ); + +list_add_tail (&encoder_cfg->link, &config->encoders); + +return encoder_cfg; +} + +void vkms_config_destroy_encoder (struct vkms_config *config, +struct vkms_config_encoder *encoder_cfg) +{ +list_del (&encoder_cfg->link); +kfree (encoder_cfg); +}drivers/gpu/drm/vkms/vkms_config.h +44
-0@@ -15,12 +15,14 @@* @dev_name: Name of the device * @planes: List of planes configured for the device * @crtcs: List of CRTCs configured for the device +* @encoders: List of encoders configured for the device * @dev: Used to store the current VKMS device. Only set when the device is instantiated. */ struct vkms_config {const char *dev_name;struct list_head planes;struct list_head crtcs; +struct list_head encoders;struct vkms_device *dev; };@@ -65,6 +67,22 @@ struct vkms_config_crtc {struct vkms_output *crtc; }; +/** +* struct vkms_config_encoder +* +* @link: Link to the others encoders in vkms_config +* @encoder: Internal usage. This pointer should never be considered as valid. +* It can be used to store a temporary reference to a VKMS encoder +* during device creation. This pointer is not managed by the +* configuration and must be managed by other means. +*/ +struct vkms_config_encoder { +struct list_head link; + +/* Internal usage */ +struct drm_encoder *encoder; +}; +/** * vkms_config_for_each_plane - Iterate over the vkms_config planes * @config: &struct vkms_config pointer @@ -81,6 +99,14 @@ struct vkms_config_crtc {#define vkms_config_for_each_crtc (config, crtc_cfg) \ list_for_each_entry((crtc_cfg), &(config)->crtcs, link) +/** +* vkms_config_for_each_encoder - Iterate over the vkms_config encoders +* @config: &struct vkms_config pointer +* @encoder_cfg: &struct vkms_config_encoder pointer used as cursor +*/ +#define vkms_config_for_each_encoder (config, encoder_cfg) \ + list_for_each_entry((encoder_cfg), &(config)->encoders, link) +/** * vkms_config_plane_for_each_possible_crtc - Iterate over the vkms_config_plane * possible CRTCs @@ -282,4 +308,22 @@ struct vkms_config_plane *vkms_config_crtc_primary_plane(const struct vkms_confistruct vkms_config_plane *vkms_config_crtc_cursor_plane (const struct vkms_config *config,struct vkms_config_crtc *crtc_cfg); +/** +* vkms_config_create_encoder() - Add a new encoder configuration +* @config: Configuration to add the encoder to +* +* Returns: +* The new encoder configuration or an error. Call vkms_config_destroy_encoder() +* to free the returned encoder configuration. +*/ +struct vkms_config_encoder *vkms_config_create_encoder (struct vkms_config *config); + +/** +* vkms_config_destroy_encoder() - Remove and free a encoder configuration +* @config: Configuration to remove the encoder from +* @encoder_cfg: Encoder configuration to destroy +*/ +void vkms_config_destroy_encoder (struct vkms_config *config, +struct vkms_config_encoder *encoder_cfg); +#endif /* _VKMS_CONFIG_H_ */ Signature · 1 line
2.48.1
PATCH v2 13/15 drm/vkms: Allow to attach encoders and CRTCs
In reply to José ExpósitoAdd a list of possible CRTCs to the encoder configuration and helpers to attach and detach them.
Now that the default configuration has its encoder and CRTC correctly attached, configure the output following the configuration.
--- .clang-format | 1 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 115 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.c | 77 ++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 29 +++++ drivers/gpu/drm/vkms/vkms_output.c | 49 +++++--- 5 files changed, 251 insertions(+), 20 deletions(-)
.clang-format +1 -0
@@ -693,6 +693,7 @@ ForEachMacros: - 'vkms_config_for_each_crtc' - 'vkms_config_for_each_encoder' - 'vkms_config_for_each_plane' + - 'vkms_config_encoder_for_each_possible_crtc' - 'vkms_config_plane_for_each_possible_crtc' - 'while_for_each_ftrace_op' - 'xa_for_each'
drivers/gpu/drm/vkms/tests/vkms_config_test.c +115 -0
147 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.c +77 -0
117 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.h +29 -0
@@ -71,6 +71,7 @@ struct vkms_config_crtc {* struct vkms_config_encoder * * @link: Link to the others encoders in vkms_config +* @possible_crtcs: Array of CRTCs that can be used with this encoder * @encoder: Internal usage. This pointer should never be considered as valid. * It can be used to store a temporary reference to a VKMS encoder * during device creation. This pointer is not managed by the
@@ -79,6 +80,8 @@ struct vkms_config_crtc {struct vkms_config_encoder {struct list_head link; +struct xarray possible_crtcs; +/* Internal usage */ struct drm_encoder *encoder; };
@@ -117,6 +120,16 @@ struct vkms_config_encoder {#define vkms_config_plane_for_each_possible_crtc (plane_cfg, idx, possible_crtc) \ xa_for_each(&(plane_cfg)->possible_crtcs, idx, (possible_crtc)) +/** +* vkms_config_encoder_for_each_possible_crtc - Iterate over the +* vkms_config_encoder possible CRTCs +* @encoder_cfg: &struct vkms_config_encoder pointer +* @idx: Index of the cursor +* @possible_crtc: &struct vkms_config_crtc pointer used as cursor +*/ +#define vkms_config_encoder_for_each_possible_crtc (encoder_cfg, idx, possible_crtc) \ + xa_for_each(&(encoder_cfg)->possible_crtcs, idx, (possible_crtc)) +/** * vkms_config_create() - Create a new VKMS configuration * @dev_name: Name of the device
@@ -326,4 +339,20 @@ struct vkms_config_encoder *vkms_config_create_encoder(struct vkms_config *confivoid vkms_config_destroy_encoder (struct vkms_config *config,struct vkms_config_encoder *encoder_cfg); +/** +* vkms_config_encoder_attach_crtc - Attach a encoder to a CRTC +* @encoder_cfg: Encoder to attach +* @crtc_cfg: CRTC to attach @encoder_cfg to +*/ +int __must_check vkms_config_encoder_attach_crtc (struct vkms_config_encoder *encoder_cfg, +struct vkms_config_crtc *crtc_cfg); + +/** +* vkms_config_encoder_detach_crtc - Detach a encoder from a CRTC +* @encoder_cfg: Encoder to detach +* @crtc_cfg: CRTC to detach @encoder_cfg from +*/ +void vkms_config_encoder_detach_crtc (struct vkms_config_encoder *encoder_cfg, +struct vkms_config_crtc *crtc_cfg); +#endif /* _VKMS_CONFIG_H_ */
drivers/gpu/drm/vkms/vkms_output.c +29 -20
70 lines not on this page · raw message
Signature · 1 line
2.48.1
Louis Chauvet
maintainerRe: [PATCH v2 13/15] drm/vkms: Allow to attach encoders and CRTCs
Quoted 9 lines · José Expósito
Add a list of possible CRTCs to the encoder configuration and helpers to attach and detach them.
Now that the default configuration has its encoder and CRTC correctly attached, configure the output following the configuration.
Co-developed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Signed-off-by José Expósito <[email protected]>
Build is broken when compiling VKMS as a module:
drivers/gpu/drm/vkms/vkms_config.c +2 -0
@@ -497,6 +497,7 @@ int __must_check vkms_config_encoder_attach_crtc(struct vkms_config_encoder *encreturn xa_alloc (&encoder_cfg->possible_crtcs, &crtc_idx, crtc_cfg, xa_limit_32b,GFP_KERNEL ); } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_encoder_attach_crtc);void vkms_config_encoder_detach_crtc (struct vkms_config_encoder *encoder_cfg,struct vkms_config_crtc *crtc_cfg)
@@ -509,3 +510,4 @@ void vkms_config_encoder_detach_crtc(struct vkms_config_encoder *encoder_cfg,xa_erase (&encoder_cfg->possible_crtcs, idx); } } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_encoder_detach_crtc);
Quoted 191 lines
--- .clang-format | 1 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 115 ++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.c | 77 ++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 29 +++++ drivers/gpu/drm/vkms/vkms_output.c | 49 +++++--- 5 files changed, 251 insertions(+), 20 deletions(-).clang-format +1
-0@@ -693,6 +693,7 @@ ForEachMacros: - 'vkms_config_for_each_crtc' - 'vkms_config_for_each_encoder' - 'vkms_config_for_each_plane' + - 'vkms_config_encoder_for_each_possible_crtc' - 'vkms_config_plane_for_each_possible_crtc' - 'while_for_each_ftrace_op' - 'xa_for_each'drivers/gpu/drm/vkms/tests/vkms_config_test.c +115
-0@@ -260,6 +260,7 @@ static void vkms_config_test_valid_plane_type(struct kunit *test)struct vkms_config *config;struct vkms_config_plane *plane_cfg;struct vkms_config_crtc *crtc_cfg; +struct vkms_config_encoder *encoder_cfg;int err; config =vkms_config_default_create (false, false, false);@@ -313,6 +314,9 @@ static void vkms_config_test_valid_plane_type(struct kunit *test)/* Invalid: Second CRTC without primary plane */ crtc_cfg =vkms_config_create_crtc (config); + encoder_cfg =vkms_config_create_encoder (config); + err =vkms_config_encoder_attach_crtc (encoder_cfg, crtc_cfg); +KUNIT_EXPECT_EQ (test, err,0 );KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config));/* Valid: Second CRTC with a primary plane */ @@ -390,6 +394,51 @@ static void vkms_config_test_invalid_encoder_number(struct kunit *test)vkms_config_destroy (config); } +static void vkms_config_test_valid_encoder_possible_crtcs (struct kunit *test) +{ +struct vkms_config *config; +struct vkms_config_plane *plane_cfg; +struct vkms_config_crtc *crtc_cfg1, *crtc_cfg2; +struct vkms_config_encoder *encoder_cfg; +int err; + + config =vkms_config_default_create (false, false, false); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + + crtc_cfg1 =list_first_entry (&config->crtcs,typeof (*crtc_cfg1), link); + +/* Invalid: Encoder without a possible CRTC */ + encoder_cfg =vkms_config_create_encoder (config); +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +/* Valid: Second CRTC with shared encoder */ + crtc_cfg2 =vkms_config_create_crtc (config); + + plane_cfg =vkms_config_create_plane (config); +vkms_config_plane_set_type (plane_cfg,DRM_PLANE_TYPE_PRIMARY ); + err =vkms_config_plane_attach_crtc (plane_cfg, crtc_cfg2); +KUNIT_EXPECT_EQ (test, err,0 ); + + err =vkms_config_encoder_attach_crtc (encoder_cfg, crtc_cfg1); +KUNIT_EXPECT_EQ (test, err,0 ); + + err =vkms_config_encoder_attach_crtc (encoder_cfg, crtc_cfg2); +KUNIT_EXPECT_EQ (test, err,0 ); + +KUNIT_EXPECT_TRUE (test,vkms_config_is_valid (config)); + +/* Invalid: Second CRTC without encoders */ +vkms_config_encoder_detach_crtc (encoder_cfg, crtc_cfg2); +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +/* Valid: First CRTC with 2 possible encoder */ +vkms_config_destroy_plane (plane_cfg); +vkms_config_destroy_crtc (config, crtc_cfg2); +KUNIT_EXPECT_TRUE (test,vkms_config_is_valid (config)); + +vkms_config_destroy (config); +} +static void vkms_config_test_plane_attach_crtc (struct kunit *test) {struct vkms_config *config;@@ -515,6 +564,70 @@ static void vkms_config_test_plane_get_possible_crtcs(struct kunit *test)vkms_config_destroy (config); } +static void vkms_config_test_encoder_get_possible_crtcs (struct kunit *test) +{ +struct vkms_config *config; +struct vkms_config_encoder *encoder_cfg1, *encoder_cfg2; +struct vkms_config_crtc *crtc_cfg1, *crtc_cfg2; +struct vkms_config_crtc *possible_crtc; +unsigned long idx =0 ; +int n_crtcs =0 ; +int err; + + config =vkms_config_create ("test" ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + + encoder_cfg1 =vkms_config_create_encoder (config); + encoder_cfg2 =vkms_config_create_encoder (config); + crtc_cfg1 =vkms_config_create_crtc (config); + crtc_cfg2 =vkms_config_create_crtc (config); + +/* No possible CRTCs */ +vkms_config_encoder_for_each_possible_crtc (encoder_cfg1, idx, possible_crtc) +KUNIT_FAIL (test,"Unexpected possible CRTC" ); + +vkms_config_encoder_for_each_possible_crtc (encoder_cfg2, idx, possible_crtc) +KUNIT_FAIL (test,"Unexpected possible CRTC" ); + +/* Encoder 1 attached to CRTC 1 and 2 */ + err =vkms_config_encoder_attach_crtc (encoder_cfg1, crtc_cfg1); +KUNIT_EXPECT_EQ (test, err,0 ); + err =vkms_config_encoder_attach_crtc (encoder_cfg1, crtc_cfg2); +KUNIT_EXPECT_EQ (test, err,0 ); + +vkms_config_encoder_for_each_possible_crtc (encoder_cfg1, idx, possible_crtc) { + n_crtcs++; +if (possible_crtc != crtc_cfg1 && possible_crtc != crtc_cfg2) +KUNIT_FAIL (test,"Unexpected possible CRTC" ); + } +KUNIT_ASSERT_EQ (test, n_crtcs,2 ); + n_crtcs =0 ; + +vkms_config_encoder_for_each_possible_crtc (encoder_cfg2, idx, possible_crtc) +KUNIT_FAIL (test,"Unexpected possible CRTC" ); + +/* Encoder 1 attached to CRTC 1 and encoder 2 to CRTC 2 */ +vkms_config_encoder_detach_crtc (encoder_cfg1, crtc_cfg2); +vkms_config_encoder_for_each_possible_crtc (encoder_cfg1, idx, possible_crtc) { + n_crtcs++; +if (possible_crtc != crtc_cfg1) +KUNIT_FAIL (test,"Unexpected possible CRTC" ); + } +KUNIT_ASSERT_EQ (test, n_crtcs,1 ); + n_crtcs =0 ; + + err =vkms_config_encoder_attach_crtc (encoder_cfg2, crtc_cfg2); +KUNIT_EXPECT_EQ (test, err,0 ); +vkms_config_encoder_for_each_possible_crtc (encoder_cfg2, idx, possible_crtc) { + n_crtcs++; +if (possible_crtc != crtc_cfg2) +KUNIT_FAIL (test,"Unexpected possible CRTC" ); + } +KUNIT_ASSERT_EQ (test, n_crtcs,1 ); + +vkms_config_destroy (config); +} +static struct kunit_case vkms_config_test_cases[] = {KUNIT_CASE (vkms_config_test_empty_config), KUNIT_CASE_PARAM(vkms_config_test_default_config,@@ -527,8 +640,10 @@ static struct kunit_case vkms_config_test_cases[] = {KUNIT_CASE (vkms_config_test_valid_plane_possible_crtcs),KUNIT_CASE (vkms_config_test_invalid_crtc_number),KUNIT_CASE (vkms_config_test_invalid_encoder_number), +KUNIT_CASE (vkms_config_test_valid_encoder_possible_crtcs),KUNIT_CASE (vkms_config_test_plane_attach_crtc),KUNIT_CASE (vkms_config_test_plane_get_possible_crtcs), + KUNIT_CASE(vkms_config_test_encoder_get_possible_crtcs), {} };drivers/gpu/drm/vkms/vkms_config.c +3
-0@@ -84,6 +84,9 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor,if (IS_ERR (encoder_cfg)) goto err_alloc; +if (vkms_config_encoder_attach_crtc (encoder_cfg, crtc_cfg)) + goto err_alloc; +return config; err_alloc:
drivers/gpu/drm/vkms/vkms_config.c static bool valid_encoder_number(struct vkms_config *config) · line 220
Quoted 6 lines
drivers/gpu/drm/vkms/vkms_config.c +3
-0@@ -212,6 +215,42 @@ static bool valid_encoder_number(struct vkms_config *config)return true; } +static bool valid_encoder_possible_crtcs (struct vkms_config *config) +{ +struct drm_device *dev = &config->dev->drm;
Ditto
Quoted 244 lines
drivers/gpu/drm/vkms/vkms_config.c +71
-0+struct vkms_config_crtc *crtc_cfg; +struct vkms_config_encoder *encoder_cfg; + +vkms_config_for_each_encoder (config, encoder_cfg) { +if (xa_empty (&encoder_cfg->possible_crtcs)) { +drm_info (dev,"All encoders must have at least one possible CRTC\n" ); +return false; + } + } + +vkms_config_for_each_crtc (config, crtc_cfg) { +bool crtc_has_encoder = false; + +vkms_config_for_each_encoder (config, encoder_cfg) { +struct vkms_config_crtc *possible_crtc; +unsigned long idx =0 ; + +vkms_config_encoder_for_each_possible_crtc (encoder_cfg, + idx, possible_crtc) { +if (possible_crtc == crtc_cfg) + crtc_has_encoder = true; + } + } + +if (!crtc_has_encoder) { +drm_info (dev,"All CRTCs must have at least one possible encoder\n" ); +return false; + } + } + +return true; +} +bool vkms_config_is_valid (struct vkms_config *config) {struct vkms_config_crtc *crtc_cfg;@@ -233,6 +272,9 @@ bool vkms_config_is_valid(struct vkms_config *config)return false; } +if (!valid_encoder_possible_crtcs (config)) +return false; +return true; }@@ -347,10 +389,14 @@ void vkms_config_destroy_crtc(struct vkms_config *config, struct vkms_config_crtc *crtc_cfg) {struct vkms_config_plane *plane_cfg; +struct vkms_config_encoder *encoder_cfg;vkms_config_for_each_plane (config, plane_cfg)vkms_config_plane_detach_crtc (plane_cfg, crtc_cfg); +vkms_config_for_each_encoder (config, encoder_cfg) +vkms_config_encoder_detach_crtc (encoder_cfg, crtc_cfg); +list_del (&crtc_cfg->link);kfree (crtc_cfg); }@@ -406,6 +452,8 @@ struct vkms_config_encoder *vkms_config_create_encoder(struct vkms_config *confiif (!encoder_cfg)return ERR_PTR (-ENOMEM ); +xa_init_flags (&encoder_cfg->possible_crtcs,XA_FLAGS_ALLOC ); +list_add_tail (&encoder_cfg->link, &config->encoders);return encoder_cfg;@@ -414,6 +462,35 @@ struct vkms_config_encoder *vkms_config_create_encoder(struct vkms_config *confivoid vkms_config_destroy_encoder (struct vkms_config *config,struct vkms_config_encoder *encoder_cfg) { +xa_destroy (&encoder_cfg->possible_crtcs);list_del (&encoder_cfg->link);kfree (encoder_cfg); } + +int __must_check vkms_config_encoder_attach_crtc (struct vkms_config_encoder *encoder_cfg, +struct vkms_config_crtc *crtc_cfg) +{ +struct vkms_config_crtc *possible_crtc; +unsigned long idx =0 ; +u32 crtc_idx =0 ; + +vkms_config_encoder_for_each_possible_crtc (encoder_cfg, idx, possible_crtc) { +if (possible_crtc == crtc_cfg) +return -EINVAL ; + } + +return xa_alloc (&encoder_cfg->possible_crtcs, &crtc_idx, crtc_cfg, + xa_limit_32b,GFP_KERNEL ); +} + +void vkms_config_encoder_detach_crtc (struct vkms_config_encoder *encoder_cfg, +struct vkms_config_crtc *crtc_cfg) +{ +struct vkms_config_crtc *possible_crtc; +unsigned long idx =0 ; + +vkms_config_encoder_for_each_possible_crtc (encoder_cfg, idx, possible_crtc) { +if (possible_crtc == crtc_cfg) +xa_erase (&encoder_cfg->possible_crtcs, idx); + } +}drivers/gpu/drm/vkms/vkms_config.h +29
-0@@ -71,6 +71,7 @@ struct vkms_config_crtc {* struct vkms_config_encoder * * @link: Link to the others encoders in vkms_config +* @possible_crtcs: Array of CRTCs that can be used with this encoder * @encoder: Internal usage. This pointer should never be considered as valid. * It can be used to store a temporary reference to a VKMS encoder * during device creation. This pointer is not managed by the @@ -79,6 +80,8 @@ struct vkms_config_crtc {struct vkms_config_encoder {struct list_head link; +struct xarray possible_crtcs; +/* Internal usage */ struct drm_encoder *encoder; };@@ -117,6 +120,16 @@ struct vkms_config_encoder {#define vkms_config_plane_for_each_possible_crtc (plane_cfg, idx, possible_crtc) \ xa_for_each(&(plane_cfg)->possible_crtcs, idx, (possible_crtc)) +/** +* vkms_config_encoder_for_each_possible_crtc - Iterate over the +* vkms_config_encoder possible CRTCs +* @encoder_cfg: &struct vkms_config_encoder pointer +* @idx: Index of the cursor +* @possible_crtc: &struct vkms_config_crtc pointer used as cursor +*/ +#define vkms_config_encoder_for_each_possible_crtc (encoder_cfg, idx, possible_crtc) \ + xa_for_each(&(encoder_cfg)->possible_crtcs, idx, (possible_crtc)) +/** * vkms_config_create() - Create a new VKMS configuration * @dev_name: Name of the device @@ -326,4 +339,20 @@ struct vkms_config_encoder *vkms_config_create_encoder(struct vkms_config *confivoid vkms_config_destroy_encoder (struct vkms_config *config,struct vkms_config_encoder *encoder_cfg); +/** +* vkms_config_encoder_attach_crtc - Attach a encoder to a CRTC +* @encoder_cfg: Encoder to attach +* @crtc_cfg: CRTC to attach @encoder_cfg to +*/ +int __must_check vkms_config_encoder_attach_crtc (struct vkms_config_encoder *encoder_cfg, +struct vkms_config_crtc *crtc_cfg); + +/** +* vkms_config_encoder_detach_crtc - Detach a encoder from a CRTC +* @encoder_cfg: Encoder to detach +* @crtc_cfg: CRTC to detach @encoder_cfg from +*/ +void vkms_config_encoder_detach_crtc (struct vkms_config_encoder *encoder_cfg, +struct vkms_config_crtc *crtc_cfg); +#endif /* _VKMS_CONFIG_H_ */ drivers/gpu/drm/vkms/vkms_output.c +29
-20@@ -9,9 +9,9 @@ int vkms_output_init(struct vkms_device *vkmsdev) {struct drm_device *dev = &vkmsdev->drm;struct vkms_connector *connector; -struct drm_encoder *encoder;struct vkms_config_plane *plane_cfg;struct vkms_config_crtc *crtc_cfg; +struct vkms_config_encoder *encoder_cfg;int ret;int writeback;@@ -61,32 +61,41 @@ int vkms_output_init(struct vkms_device *vkmsdev) } } +vkms_config_for_each_encoder (vkmsdev->config, encoder_cfg) { +struct vkms_config_crtc *possible_crtc; +unsigned long idx =0 ; + + encoder_cfg->encoder =drmm_kzalloc (dev,sizeof (*encoder_cfg->encoder),GFP_KERNEL ); +if (!encoder_cfg->encoder) { +DRM_ERROR ("Failed to allocate encoder\n" ); +return -ENOMEM ; + } + ret =drmm_encoder_init (dev, encoder_cfg->encoder,NULL , +DRM_MODE_ENCODER_VIRTUAL ,NULL ); +if (ret) { +DRM_ERROR ("Failed to init encoder\n" ); +return ret; + } + +vkms_config_encoder_for_each_possible_crtc (encoder_cfg, idx, possible_crtc) { + encoder_cfg->encoder->possible_crtcs |= +drm_crtc_mask (&possible_crtc->crtc->crtc); + } + } + connector =vkms_connector_init (vkmsdev);if (IS_ERR (connector)) {DRM_ERROR ("Failed to init connector\n" );return PTR_ERR (connector); } - encoder =drmm_kzalloc (dev,sizeof (*encoder),GFP_KERNEL ); -if (!encoder) { -DRM_ERROR ("Failed to allocate encoder\n" ); -return -ENOMEM ; - } - ret =drmm_encoder_init (dev, encoder,NULL , -DRM_MODE_ENCODER_VIRTUAL ,NULL ); -if (ret) { -DRM_ERROR ("Failed to init encoder\n" ); -return ret; - } - -vkms_config_for_each_crtc (vkmsdev->config, crtc_cfg) - encoder->possible_crtcs =drm_crtc_mask (&crtc_cfg->crtc->crtc); -/* Attach the encoder and the connector */ - ret =drm_connector_attach_encoder (&connector->base, encoder); -if (ret) { -DRM_ERROR ("Failed to attach connector to encoder\n" ); -return ret; +vkms_config_for_each_encoder (vkmsdev->config, encoder_cfg) { + ret =drm_connector_attach_encoder (&connector->base, encoder_cfg->encoder); +if (ret) { +DRM_ERROR ("Failed to attach connector to encoder\n" ); +return ret; + } }drm_mode_config_reset (dev);Signature · 1 line
2.48.1
PATCH v2 14/15 drm/vkms: Allow to configure multiple connectors
In reply to José ExpósitoAdd a list of connectors to vkms_config and helper functions to add and remove as many connectors as wanted.
For backwards compatibility, add one enabled connector to the default configuration.
A future patch will allow to attach connectors and encoders, but for the moment there are no changes in the way the output is configured.
--- .clang-format | 1 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 74 +++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.c | 50 +++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 42 +++++++++++ drivers/gpu/drm/vkms/vkms_connector.c | 11 +++ 5 files changed, 178 insertions(+)
.clang-format +1 -0
@@ -690,6 +690,7 @@ ForEachMacros: - 'v4l2_m2m_for_each_src_buf' - 'v4l2_m2m_for_each_src_buf_safe' - 'virtio_device_for_each_vq' + - 'vkms_config_for_each_connector' - 'vkms_config_for_each_crtc' - 'vkms_config_for_each_encoder' - 'vkms_config_for_each_plane'
drivers/gpu/drm/vkms/tests/vkms_config_test.c +74 -0
110 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.c +50 -0
107 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.h +42 -0
70 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_connector.c +11 -0
@@ -25,8 +25,19 @@ static int vkms_conn_get_modes(struct drm_connector *connector)return count; } +static struct drm_encoder *vkms_conn_best_encoder (struct drm_connector *connector) +{ +struct drm_encoder *encoder; + +drm_connector_for_each_possible_encoder (connector, encoder) +return encoder; + +return NULL ; +} +static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { .get_modes = vkms_conn_get_modes, + .best_encoder = vkms_conn_best_encoder, };struct vkms_connector *vkms_connector_init (struct vkms_device *vkmsdev)
Signature · 1 line
2.48.1
Louis Chauvet
maintainerRe: [PATCH v2 14/15] drm/vkms: Allow to configure multiple connectors
Quoted 6 lines · José Expósito
Add a list of connectors to
vkms_configand helper functions to add and remove as many connectors as wanted.For backwards compatibility, add one enabled connector to the default configuration.
Quoted 6 lines
A future patch will allow to attach connectors and encoders, but for the moment there are no changes in the way the output is configured.
Co-developed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Signed-off-by José Expósito <[email protected]>
Compilation as module is broken:
drivers/gpu/drm/vkms/vkms_config.c +2 -0
@@ -555,9 +555,11 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *creturn connector_cfg; } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_create_connector);void vkms_config_destroy_connector (struct vkms_config_connector *connector_cfg) {list_del (&connector_cfg->link);kfree (connector_cfg); } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_destroy_connector);
Quoted 366 lines
--- .clang-format | 1 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 74 +++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.c | 50 +++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 42 +++++++++++ drivers/gpu/drm/vkms/vkms_connector.c | 11 +++ 5 files changed, 178 insertions(+).clang-format +1
-0@@ -690,6 +690,7 @@ ForEachMacros: - 'v4l2_m2m_for_each_src_buf' - 'v4l2_m2m_for_each_src_buf_safe' - 'virtio_device_for_each_vq' + - 'vkms_config_for_each_connector' - 'vkms_config_for_each_crtc' - 'vkms_config_for_each_encoder' - 'vkms_config_for_each_plane'drivers/gpu/drm/vkms/tests/vkms_config_test.c +74
-0@@ -27,6 +27,7 @@ static void vkms_config_test_empty_config(struct kunit *test)KUNIT_EXPECT_TRUE (test,list_empty (&config->planes));KUNIT_EXPECT_TRUE (test,list_empty (&config->crtcs));KUNIT_EXPECT_TRUE (test,list_empty (&config->encoders)); +KUNIT_EXPECT_TRUE (test,list_empty (&config->connectors));KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config));@@ -103,6 +104,9 @@ static void vkms_config_test_default_config(struct kunit *test)/* Encoders */ KUNIT_EXPECT_EQ (test,list_count_nodes (&config->encoders),1 ); +/* Connectors */ +KUNIT_EXPECT_EQ (test,list_count_nodes (&config->connectors),1 ); +KUNIT_EXPECT_TRUE (test,vkms_config_is_valid (config));vkms_config_destroy (config);@@ -232,6 +236,51 @@ static void vkms_config_test_get_encoders(struct kunit *test)vkms_config_destroy (config); } +static void vkms_config_test_get_connectors (struct kunit *test) +{ +struct vkms_config *config; +struct vkms_config_connector *connector_cfg; +struct vkms_config_connector *connector_cfg1, *connector_cfg2; +int n_connectors =0 ; + + config =vkms_config_create ("test" ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + +vkms_config_for_each_connector (config, connector_cfg) + n_connectors++; +KUNIT_ASSERT_EQ (test, n_connectors,0 ); + + connector_cfg1 =vkms_config_create_connector (config); +vkms_config_for_each_connector (config, connector_cfg) { + n_connectors++; +if (connector_cfg != connector_cfg1) +KUNIT_FAIL (test,"Unexpected connector" ); + } +KUNIT_ASSERT_EQ (test, n_connectors,1 ); + n_connectors =0 ; + + connector_cfg2 =vkms_config_create_connector (config); +vkms_config_for_each_connector (config, connector_cfg) { + n_connectors++; +if (connector_cfg != connector_cfg1 && + connector_cfg != connector_cfg2) +KUNIT_FAIL (test,"Unexpected connector" ); + } +KUNIT_ASSERT_EQ (test, n_connectors,2 ); + n_connectors =0 ; + +vkms_config_destroy_connector (connector_cfg2); +vkms_config_for_each_connector (config, connector_cfg) { + n_connectors++; +if (connector_cfg != connector_cfg1) +KUNIT_FAIL (test,"Unexpected connector" ); + } +KUNIT_ASSERT_EQ (test, n_connectors,1 ); + n_connectors =0 ; + +vkms_config_destroy (config); +} +static void vkms_config_test_invalid_plane_number (struct kunit *test) {struct vkms_config *config;@@ -439,6 +488,29 @@ static void vkms_config_test_valid_encoder_possible_crtcs(struct kunit *test)vkms_config_destroy (config); } +static void vkms_config_test_invalid_connector_number (struct kunit *test) +{ +struct vkms_config *config; +struct vkms_config_connector *connector_cfg; +int n; + + config =vkms_config_default_create (false, false, false); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + +/* Invalid: No connectors */ + connector_cfg =list_first_entry (&config->connectors,typeof (*connector_cfg), link); +vkms_config_destroy_connector (connector_cfg); +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +/* Invalid: Too many connectors */ +for (n =0 ; n <=32 ; n++) + connector_cfg =vkms_config_create_connector (config); + +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +vkms_config_destroy (config); +} +static void vkms_config_test_plane_attach_crtc (struct kunit *test) {struct vkms_config *config;@@ -635,12 +707,14 @@ static struct kunit_case vkms_config_test_cases[] = {KUNIT_CASE (vkms_config_test_get_planes),KUNIT_CASE (vkms_config_test_get_crtcs),KUNIT_CASE (vkms_config_test_get_encoders), +KUNIT_CASE (vkms_config_test_get_connectors),KUNIT_CASE (vkms_config_test_invalid_plane_number),KUNIT_CASE (vkms_config_test_valid_plane_type),KUNIT_CASE (vkms_config_test_valid_plane_possible_crtcs),KUNIT_CASE (vkms_config_test_invalid_crtc_number),KUNIT_CASE (vkms_config_test_invalid_encoder_number),KUNIT_CASE (vkms_config_test_valid_encoder_possible_crtcs), +KUNIT_CASE (vkms_config_test_invalid_connector_number),KUNIT_CASE (vkms_config_test_plane_attach_crtc),KUNIT_CASE (vkms_config_test_plane_get_possible_crtcs), KUNIT_CASE(vkms_config_test_encoder_get_possible_crtcs),drivers/gpu/drm/vkms/vkms_config.c +50
-0@@ -24,6 +24,7 @@ struct vkms_config *vkms_config_create(const char *dev_name)INIT_LIST_HEAD (&config->planes);INIT_LIST_HEAD (&config->crtcs);INIT_LIST_HEAD (&config->encoders); +INIT_LIST_HEAD (&config->connectors);return config; }@@ -36,6 +37,7 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor,struct vkms_config_plane *plane_cfg;struct vkms_config_crtc *crtc_cfg;struct vkms_config_encoder *encoder_cfg; +struct vkms_config_connector *connector_cfg;int n; config =vkms_config_create (DEFAULT_DEVICE_NAME );@@ -87,6 +89,10 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor,if (vkms_config_encoder_attach_crtc (encoder_cfg, crtc_cfg)) goto err_alloc; + connector_cfg =vkms_config_create_connector (config); +if (IS_ERR (connector_cfg)) + goto err_alloc; +return config; err_alloc:@@ -99,6 +105,7 @@ void vkms_config_destroy(struct vkms_config *config)struct vkms_config_plane *plane_cfg, *plane_tmp;struct vkms_config_crtc *crtc_cfg, *crtc_tmp;struct vkms_config_encoder *encoder_cfg, *encoder_tmp; +struct vkms_config_connector *connector_cfg, *connector_tmp;list_for_each_entry_safe (plane_cfg, plane_tmp, &config->planes, link)vkms_config_destroy_plane (plane_cfg);@@ -109,6 +116,9 @@ void vkms_config_destroy(struct vkms_config *config)list_for_each_entry_safe (encoder_cfg, encoder_tmp, &config->encoders, link)vkms_config_destroy_encoder (config, encoder_cfg); +list_for_each_entry_safe (connector_cfg, connector_tmp, &config->connectors, link) +vkms_config_destroy_connector (connector_cfg); +kfree_const (config->dev_name);kfree (config); }@@ -251,6 +261,20 @@ static bool valid_encoder_possible_crtcs(struct vkms_config *config)return true; } +static bool valid_connector_number (struct vkms_config *config) +{ +struct drm_device *dev = &config->dev->drm; +size_t n_connectors; + + n_connectors =list_count_nodes (&config->connectors); +if (n_connectors <=0 || n_connectors >=32 ) { +drm_info (dev,"The number of connectors must be between 1 and 31\n" ); +return false; + } + +return true; +} +bool vkms_config_is_valid (struct vkms_config *config) {struct vkms_config_crtc *crtc_cfg;@@ -264,6 +288,9 @@ bool vkms_config_is_valid(struct vkms_config *config)if (!valid_encoder_number (config))return false; +if (!valid_connector_number (config)) +return false; +if (!valid_plane_possible_crtcs (config))return false;@@ -287,6 +314,7 @@ static int vkms_config_show(struct seq_file *m, void *data)struct vkms_config_plane *plane_cfg;struct vkms_config_crtc *crtc_cfg;struct vkms_config_encoder *encoder_cfg; +struct vkms_config_connector *connector_cfg; dev_name =vkms_config_get_device_name ((struct vkms_config *)vkmsdev->config);seq_printf (m,"dev_name=%s\n" , dev_name);@@ -306,6 +334,9 @@ static int vkms_config_show(struct seq_file *m, void *data)vkms_config_for_each_encoder (vkmsdev->config, encoder_cfg)seq_puts (m,"encoder\n" ); +vkms_config_for_each_connector (vkmsdev->config, connector_cfg) +seq_puts (m,"connector\n" ); +return 0 ; }@@ -494,3 +525,22 @@ void vkms_config_encoder_detach_crtc(struct vkms_config_encoder *encoder_cfg,xa_erase (&encoder_cfg->possible_crtcs, idx); } } + +struct vkms_config_connector *vkms_config_create_connector (struct vkms_config *config) +{ +struct vkms_config_connector *connector_cfg; + + connector_cfg =kzalloc (sizeof (*connector_cfg),GFP_KERNEL ); +if (!connector_cfg) +return ERR_PTR (-ENOMEM ); + +list_add_tail (&connector_cfg->link, &config->connectors); + +return connector_cfg; +} + +void vkms_config_destroy_connector (struct vkms_config_connector *connector_cfg) +{ +list_del (&connector_cfg->link); +kfree (connector_cfg); +}drivers/gpu/drm/vkms/vkms_config.h +42
-0@@ -16,6 +16,7 @@* @planes: List of planes configured for the device * @crtcs: List of CRTCs configured for the device * @encoders: List of encoders configured for the device +* @connectors: List of connectors configured for the device * @dev: Used to store the current VKMS device. Only set when the device is instantiated. */ struct vkms_config {@@ -23,6 +24,7 @@ struct vkms_config {struct list_head planes;struct list_head crtcs;struct list_head encoders; +struct list_head connectors;struct vkms_device *dev; };@@ -86,6 +88,22 @@ struct vkms_config_encoder {struct drm_encoder *encoder; }; +/** +* struct vkms_config_connector +* +* @link: Link to the others connector in vkms_config +* @connector: Internal usage. This pointer should never be considered as valid. +* It can be used to store a temporary reference to a VKMS connector +* during device creation. This pointer is not managed by the +* configuration and must be managed by other means. +*/ +struct vkms_config_connector { +struct list_head link; + +/* Internal usage */ +struct vkms_connector *connector; +}; +/** * vkms_config_for_each_plane - Iterate over the vkms_config planes * @config: &struct vkms_config pointer @@ -110,6 +128,14 @@ struct vkms_config_encoder {#define vkms_config_for_each_encoder (config, encoder_cfg) \ list_for_each_entry((encoder_cfg), &(config)->encoders, link) +/** +* vkms_config_for_each_connector - Iterate over the vkms_config connectors +* @config: &struct vkms_config pointer +* @connector_cfg: &struct vkms_config_connector pointer used as cursor +*/ +#define vkms_config_for_each_connector (config, connector_cfg) \ + list_for_each_entry((connector_cfg), &(config)->connectors, link) +/** * vkms_config_plane_for_each_possible_crtc - Iterate over the vkms_config_plane * possible CRTCs @@ -355,4 +381,20 @@ int __must_check vkms_config_encoder_attach_crtc(struct vkms_config_encoder *encvoid vkms_config_encoder_detach_crtc (struct vkms_config_encoder *encoder_cfg,struct vkms_config_crtc *crtc_cfg); +/** +* vkms_config_create_connector() - Add a new connector configuration +* @config: Configuration to add the connector to +* +* Returns: +* The new connector configuration or an error. Call +* vkms_config_destroy_connector() to free the returned connector configuration. +*/ +struct vkms_config_connector *vkms_config_create_connector (struct vkms_config *config); + +/** +* vkms_config_destroy_connector() - Remove and free a connector configuration +* @connector_cfg: Connector configuration to destroy +*/ +void vkms_config_destroy_connector (struct vkms_config_connector *connector_cfg); +#endif /* _VKMS_CONFIG_H_ */ drivers/gpu/drm/vkms/vkms_connector.c +11
-0@@ -25,8 +25,19 @@ static int vkms_conn_get_modes(struct drm_connector *connector)return count; } +static struct drm_encoder *vkms_conn_best_encoder (struct drm_connector *connector) +{ +struct drm_encoder *encoder; + +drm_connector_for_each_possible_encoder (connector, encoder) +return encoder; + +return NULL ; +} +static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { .get_modes = vkms_conn_get_modes, + .best_encoder = vkms_conn_best_encoder, };struct vkms_connector *vkms_connector_init (struct vkms_device *vkmsdev)Signature · 1 line
2.48.1
PATCH v2 15/15 drm/vkms: Allow to attach connectors and encoders
In reply to José ExpósitoAdd a list of possible encoders to the connector configuration and helpers to attach and detach them.
Now that the default configuration has its connector and encoder correctly, configure the output following the configuration.
--- .clang-format | 1 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 94 +++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.c | 60 ++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 29 ++++++ drivers/gpu/drm/vkms/vkms_output.c | 33 ++++--- 5 files changed, 204 insertions(+), 13 deletions(-)
.clang-format +1 -0
@@ -694,6 +694,7 @@ ForEachMacros: - 'vkms_config_for_each_crtc' - 'vkms_config_for_each_encoder' - 'vkms_config_for_each_plane' + - 'vkms_config_connector_for_each_possible_encoder' - 'vkms_config_encoder_for_each_possible_crtc' - 'vkms_config_plane_for_each_possible_crtc' - 'while_for_each_ftrace_op'
drivers/gpu/drm/vkms/tests/vkms_config_test.c +94 -0
115 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.c +60 -0
96 lines not on this page · raw message
drivers/gpu/drm/vkms/vkms_config.h +29 -0
@@ -92,6 +92,7 @@ struct vkms_config_encoder {* struct vkms_config_connector * * @link: Link to the others connector in vkms_config +* @possible_encoders: Array of encoders that can be used with this connector * @connector: Internal usage. This pointer should never be considered as valid. * It can be used to store a temporary reference to a VKMS connector * during device creation. This pointer is not managed by the
@@ -100,6 +101,8 @@ struct vkms_config_encoder {struct vkms_config_connector {struct list_head link; +struct xarray possible_encoders; +/* Internal usage */ struct vkms_connector *connector; };
@@ -156,6 +159,16 @@ struct vkms_config_connector {#define vkms_config_encoder_for_each_possible_crtc (encoder_cfg, idx, possible_crtc) \ xa_for_each(&(encoder_cfg)->possible_crtcs, idx, (possible_crtc)) +/** +* vkms_config_connector_for_each_possible_encoder - Iterate over the +* vkms_config_connector possible encoders +* @connector_cfg: &struct vkms_config_connector pointer +* @idx: Index of the cursor +* @possible_encoder: &struct vkms_config_encoder pointer used as cursor +*/ +#define vkms_config_connector_for_each_possible_encoder (connector_cfg, idx, possible_encoder) \ + xa_for_each(&(connector_cfg)->possible_encoders, idx, (possible_encoder)) +/** * vkms_config_create() - Create a new VKMS configuration * @dev_name: Name of the device
@@ -397,4 +410,20 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *c*/ void vkms_config_destroy_connector (struct vkms_config_connector *connector_cfg); +/** +* vkms_config_connector_attach_encoder - Attach a connector to an encoder +* @connector_cfg: Connector to attach +* @encoder_cfg: Encoder to attach @connector_cfg to +*/ +int __must_check vkms_config_connector_attach_encoder (struct vkms_config_connector *connector_cfg, +struct vkms_config_encoder *encoder_cfg); + +/** +* vkms_config_connector_detach_encoder - Detach a connector from an encoder +* @connector_cfg: Connector to detach +* @encoder_cfg: Encoder to detach @connector_cfg from +*/ +void vkms_config_connector_detach_encoder (struct vkms_config_connector *connector_cfg, +struct vkms_config_encoder *encoder_cfg); +#endif /* _VKMS_CONFIG_H_ */
drivers/gpu/drm/vkms/vkms_output.c +20 -13
@@ -8,10 +8,10 @@int vkms_output_init (struct vkms_device *vkmsdev) {struct drm_device *dev = &vkmsdev->drm; -struct vkms_connector *connector;struct vkms_config_plane *plane_cfg;struct vkms_config_crtc *crtc_cfg;struct vkms_config_encoder *encoder_cfg; +struct vkms_config_connector *connector_cfg;int ret;int writeback;
@@ -83,22 +83,29 @@ int vkms_output_init(struct vkms_device *vkmsdev) } } - connector =vkms_connector_init (vkmsdev); -if (IS_ERR (connector)) { -DRM_ERROR ("Failed to init connector\n" ); -return PTR_ERR (connector); - } +vkms_config_for_each_connector (vkmsdev->config, connector_cfg) { +struct vkms_config_encoder *possible_encoder; +unsigned long idx =0 ; -/* Attach the encoder and the connector */ -vkms_config_for_each_encoder (vkmsdev->config, encoder_cfg) { - ret =drm_connector_attach_encoder (&connector->base, encoder_cfg->encoder); -if (ret) { -DRM_ERROR ("Failed to attach connector to encoder\n" ); -return ret; + connector_cfg->connector =vkms_connector_init (vkmsdev); +if (IS_ERR (connector_cfg->connector)) { +DRM_ERROR ("Failed to init connector\n" ); +return PTR_ERR (connector_cfg->connector); + } + +vkms_config_connector_for_each_possible_encoder (connector_cfg, + idx, + possible_encoder) { + ret =drm_connector_attach_encoder (&connector_cfg->connector->base, + possible_encoder->encoder); +if (ret) { +DRM_ERROR ("Failed to attach connector to encoder\n" ); +return ret; + } } }drm_mode_config_reset (dev); -return ret; +return 0 ; }
Signature · 1 line
2.48.1
Louis Chauvet
maintainerRe: [PATCH v2 15/15] drm/vkms: Allow to attach connectors and encoders
Quoted 9 lines · José Expósito
Add a list of possible encoders to the connector configuration and helpers to attach and detach them.
Now that the default configuration has its connector and encoder correctly, configure the output following the configuration.
Co-developed-by Louis Chauvet <[email protected]>Signed-off-by Louis Chauvet <[email protected]>Signed-off-by José Expósito <[email protected]>
The compilation is broken as module:
drivers/gpu/drm/vkms/vkms_config.c +2 -0
@@ -610,6 +610,7 @@ int __must_check vkms_config_connector_attach_encoder(struct vkms_config_connectreturn xa_alloc (&connector_cfg->possible_encoders, &encoder_idx, encoder_cfg, xa_limit_32b,GFP_KERNEL ); } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_connector_attach_encoder);void vkms_config_connector_detach_encoder (struct vkms_config_connector *connector_cfg,struct vkms_config_encoder *encoder_cfg)
@@ -623,3 +624,4 @@ void vkms_config_connector_detach_encoder(struct vkms_config_connector *connectoxa_erase (&connector_cfg->possible_encoders, idx); } } +EXPORT_SYMBOL_IF_KUNIT (vkms_config_connector_detach_encoder);
Quoted 368 lines
--- .clang-format | 1 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 94 +++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.c | 60 ++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 29 ++++++ drivers/gpu/drm/vkms/vkms_output.c | 33 ++++--- 5 files changed, 204 insertions(+), 13 deletions(-).clang-format +1
-0@@ -694,6 +694,7 @@ ForEachMacros: - 'vkms_config_for_each_crtc' - 'vkms_config_for_each_encoder' - 'vkms_config_for_each_plane' + - 'vkms_config_connector_for_each_possible_encoder' - 'vkms_config_encoder_for_each_possible_crtc' - 'vkms_config_plane_for_each_possible_crtc' - 'while_for_each_ftrace_op'drivers/gpu/drm/vkms/tests/vkms_config_test.c +94
-0@@ -511,6 +511,27 @@ static void vkms_config_test_invalid_connector_number(struct kunit *test)vkms_config_destroy (config); } +static void vkms_config_test_valid_connector_possible_encoders (struct kunit *test) +{ +struct vkms_config *config; +struct vkms_config_encoder *encoder_cfg; +struct vkms_config_connector *connector_cfg; + + config =vkms_config_default_create (false, false, false); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + + encoder_cfg =list_first_entry (&config->encoders, +typeof (*encoder_cfg), link); + connector_cfg =list_first_entry (&config->connectors, +typeof (*connector_cfg), link); + +/* Invalid: Connector without a possible encoder */ +vkms_config_connector_detach_encoder (connector_cfg, encoder_cfg); +KUNIT_EXPECT_FALSE (test,vkms_config_is_valid (config)); + +vkms_config_destroy (config); +} +static void vkms_config_test_plane_attach_crtc (struct kunit *test) {struct vkms_config *config;@@ -700,6 +721,77 @@ static void vkms_config_test_encoder_get_possible_crtcs(struct kunit *test)vkms_config_destroy (config); } +static void vkms_config_test_connector_get_possible_encoders (struct kunit *test) +{ +struct vkms_config *config; +struct vkms_config_connector *connector_cfg1, *connector_cfg2; +struct vkms_config_encoder *encoder_cfg1, *encoder_cfg2; +struct vkms_config_encoder *possible_encoder; +unsigned long idx =0 ; +int n_encoders =0 ; +int err; + + config =vkms_config_create ("test" ); +KUNIT_ASSERT_NOT_ERR_OR_NULL (test, config); + + connector_cfg1 =vkms_config_create_connector (config); + connector_cfg2 =vkms_config_create_connector (config); + encoder_cfg1 =vkms_config_create_encoder (config); + encoder_cfg2 =vkms_config_create_encoder (config); + +/* No possible encoders */ +vkms_config_connector_for_each_possible_encoder (connector_cfg1, idx, + possible_encoder) +KUNIT_FAIL (test,"Unexpected possible encoder" ); + +vkms_config_connector_for_each_possible_encoder (connector_cfg2, idx, + possible_encoder) +KUNIT_FAIL (test,"Unexpected possible encoder" ); + +/* Connector 1 attached to encoders 1 and 2 */ + err =vkms_config_connector_attach_encoder (connector_cfg1, encoder_cfg1); +KUNIT_EXPECT_EQ (test, err,0 ); + err =vkms_config_connector_attach_encoder (connector_cfg1, encoder_cfg2); +KUNIT_EXPECT_EQ (test, err,0 ); + +vkms_config_connector_for_each_possible_encoder (connector_cfg1, idx, + possible_encoder) { + n_encoders++; +if (possible_encoder != encoder_cfg1 && + possible_encoder != encoder_cfg2) +KUNIT_FAIL (test,"Unexpected possible encoder" ); + } +KUNIT_ASSERT_EQ (test, n_encoders,2 ); + n_encoders =0 ; + +vkms_config_connector_for_each_possible_encoder (connector_cfg2, idx, + possible_encoder) +KUNIT_FAIL (test,"Unexpected possible encoder" ); + +/* Connector 1 attached to encoder 1 and connector 2 to encoder 2 */ +vkms_config_connector_detach_encoder (connector_cfg1, encoder_cfg2); +vkms_config_connector_for_each_possible_encoder (connector_cfg1, idx, + possible_encoder) { + n_encoders++; +if (possible_encoder != encoder_cfg1) +KUNIT_FAIL (test,"Unexpected possible encoder" ); + } +KUNIT_ASSERT_EQ (test, n_encoders,1 ); + n_encoders =0 ; + + err =vkms_config_connector_attach_encoder (connector_cfg2, encoder_cfg2); +KUNIT_EXPECT_EQ (test, err,0 ); +vkms_config_connector_for_each_possible_encoder (connector_cfg2, idx, + possible_encoder) { + n_encoders++; +if (possible_encoder != encoder_cfg2) +KUNIT_FAIL (test,"Unexpected possible encoder" ); + } +KUNIT_ASSERT_EQ (test, n_encoders,1 ); + +vkms_config_destroy (config); +} +static struct kunit_case vkms_config_test_cases[] = {KUNIT_CASE (vkms_config_test_empty_config), KUNIT_CASE_PARAM(vkms_config_test_default_config,@@ -715,9 +807,11 @@ static struct kunit_case vkms_config_test_cases[] = {KUNIT_CASE (vkms_config_test_invalid_encoder_number),KUNIT_CASE (vkms_config_test_valid_encoder_possible_crtcs),KUNIT_CASE (vkms_config_test_invalid_connector_number), +KUNIT_CASE (vkms_config_test_valid_connector_possible_encoders),KUNIT_CASE (vkms_config_test_plane_attach_crtc),KUNIT_CASE (vkms_config_test_plane_get_possible_crtcs),KUNIT_CASE (vkms_config_test_encoder_get_possible_crtcs), + KUNIT_CASE(vkms_config_test_connector_get_possible_encoders), {} };drivers/gpu/drm/vkms/vkms_config.c +60
-0@@ -93,6 +93,9 @@ struct vkms_config *vkms_config_default_create(bool enable_cursor,if (IS_ERR (connector_cfg)) goto err_alloc; +if (vkms_config_connector_attach_encoder (connector_cfg, encoder_cfg)) + goto err_alloc; +return config; err_alloc:@@ -275,6 +278,22 @@ static bool valid_connector_number(struct vkms_config *config)return true; } +static bool valid_connector_possible_encoders (struct vkms_config *config) +{ +struct drm_device *dev = &config->dev->drm; +struct vkms_config_connector *connector_cfg; + +vkms_config_for_each_connector (config, connector_cfg) { +if (xa_empty (&connector_cfg->possible_encoders)) { +drm_info (dev, +"All connectors must have at least one possible encoder\n" ); +return false; + } + } + +return true; +} +bool vkms_config_is_valid (struct vkms_config *config) {struct vkms_config_crtc *crtc_cfg;@@ -302,6 +321,9 @@ bool vkms_config_is_valid(struct vkms_config *config)if (!valid_encoder_possible_crtcs (config))return false; +if (!valid_connector_possible_encoders (config)) +return false; +return true; }@@ -493,6 +515,11 @@ struct vkms_config_encoder *vkms_config_create_encoder(struct vkms_config *confivoid vkms_config_destroy_encoder (struct vkms_config *config,struct vkms_config_encoder *encoder_cfg) { +struct vkms_config_connector *connector_cfg; + +vkms_config_for_each_connector (config, connector_cfg) +vkms_config_connector_detach_encoder (connector_cfg, encoder_cfg); +xa_destroy (&encoder_cfg->possible_crtcs);list_del (&encoder_cfg->link);kfree (encoder_cfg);@@ -534,6 +561,8 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *cif (!connector_cfg)return ERR_PTR (-ENOMEM ); +xa_init_flags (&connector_cfg->possible_encoders,XA_FLAGS_ALLOC ); +list_add_tail (&connector_cfg->link, &config->connectors);return connector_cfg;@@ -541,6 +570,37 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *cvoid vkms_config_destroy_connector (struct vkms_config_connector *connector_cfg) { +xa_destroy (&connector_cfg->possible_encoders);list_del (&connector_cfg->link);kfree (connector_cfg); } + +int __must_check vkms_config_connector_attach_encoder (struct vkms_config_connector *connector_cfg, +struct vkms_config_encoder *encoder_cfg) +{ +struct vkms_config_encoder *possible_encoder; +unsigned long idx =0 ; +u32 encoder_idx =0 ; + +vkms_config_connector_for_each_possible_encoder (connector_cfg, idx, + possible_encoder) { +if (possible_encoder == encoder_cfg) +return -EINVAL ; + } + +return xa_alloc (&connector_cfg->possible_encoders, &encoder_idx, + encoder_cfg, xa_limit_32b,GFP_KERNEL ); +} + +void vkms_config_connector_detach_encoder (struct vkms_config_connector *connector_cfg, +struct vkms_config_encoder *encoder_cfg) +{ +struct vkms_config_encoder *possible_encoder; +unsigned long idx =0 ; + +vkms_config_connector_for_each_possible_encoder (connector_cfg, idx, + possible_encoder) { +if (possible_encoder == encoder_cfg) +xa_erase (&connector_cfg->possible_encoders, idx); + } +}drivers/gpu/drm/vkms/vkms_config.h +29
-0@@ -92,6 +92,7 @@ struct vkms_config_encoder {* struct vkms_config_connector * * @link: Link to the others connector in vkms_config +* @possible_encoders: Array of encoders that can be used with this connector * @connector: Internal usage. This pointer should never be considered as valid. * It can be used to store a temporary reference to a VKMS connector * during device creation. This pointer is not managed by the @@ -100,6 +101,8 @@ struct vkms_config_encoder {struct vkms_config_connector {struct list_head link; +struct xarray possible_encoders; +/* Internal usage */ struct vkms_connector *connector; };@@ -156,6 +159,16 @@ struct vkms_config_connector {#define vkms_config_encoder_for_each_possible_crtc (encoder_cfg, idx, possible_crtc) \ xa_for_each(&(encoder_cfg)->possible_crtcs, idx, (possible_crtc)) +/** +* vkms_config_connector_for_each_possible_encoder - Iterate over the +* vkms_config_connector possible encoders +* @connector_cfg: &struct vkms_config_connector pointer +* @idx: Index of the cursor +* @possible_encoder: &struct vkms_config_encoder pointer used as cursor +*/ +#define vkms_config_connector_for_each_possible_encoder (connector_cfg, idx, possible_encoder) \ + xa_for_each(&(connector_cfg)->possible_encoders, idx, (possible_encoder)) +/** * vkms_config_create() - Create a new VKMS configuration * @dev_name: Name of the device @@ -397,4 +410,20 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *c*/ void vkms_config_destroy_connector (struct vkms_config_connector *connector_cfg); +/** +* vkms_config_connector_attach_encoder - Attach a connector to an encoder +* @connector_cfg: Connector to attach +* @encoder_cfg: Encoder to attach @connector_cfg to +*/ +int __must_check vkms_config_connector_attach_encoder (struct vkms_config_connector *connector_cfg, +struct vkms_config_encoder *encoder_cfg); + +/** +* vkms_config_connector_detach_encoder - Detach a connector from an encoder +* @connector_cfg: Connector to detach +* @encoder_cfg: Encoder to detach @connector_cfg from +*/ +void vkms_config_connector_detach_encoder (struct vkms_config_connector *connector_cfg, +struct vkms_config_encoder *encoder_cfg); +#endif /* _VKMS_CONFIG_H_ */ drivers/gpu/drm/vkms/vkms_output.c +20
-13@@ -8,10 +8,10 @@int vkms_output_init (struct vkms_device *vkmsdev) {struct drm_device *dev = &vkmsdev->drm; -struct vkms_connector *connector;struct vkms_config_plane *plane_cfg;struct vkms_config_crtc *crtc_cfg;struct vkms_config_encoder *encoder_cfg; +struct vkms_config_connector *connector_cfg;int ret;int writeback;@@ -83,22 +83,29 @@ int vkms_output_init(struct vkms_device *vkmsdev) } } - connector =vkms_connector_init (vkmsdev); -if (IS_ERR (connector)) { -DRM_ERROR ("Failed to init connector\n" ); -return PTR_ERR (connector); - } +vkms_config_for_each_connector (vkmsdev->config, connector_cfg) { +struct vkms_config_encoder *possible_encoder; +unsigned long idx =0 ; -/* Attach the encoder and the connector */ -vkms_config_for_each_encoder (vkmsdev->config, encoder_cfg) { - ret =drm_connector_attach_encoder (&connector->base, encoder_cfg->encoder); -if (ret) { -DRM_ERROR ("Failed to attach connector to encoder\n" ); -return ret; + connector_cfg->connector =vkms_connector_init (vkmsdev); +if (IS_ERR (connector_cfg->connector)) { +DRM_ERROR ("Failed to init connector\n" ); +return PTR_ERR (connector_cfg->connector); + } + +vkms_config_connector_for_each_possible_encoder (connector_cfg, + idx, + possible_encoder) { + ret =drm_connector_attach_encoder (&connector_cfg->connector->base, + possible_encoder->encoder); +if (ret) { +DRM_ERROR ("Failed to attach connector to encoder\n" ); +return ret; + } } }drm_mode_config_reset (dev); -return ret; +return 0 ; }Signature · 1 line
2.48.1