[PATCH i-g-t 21/39] lib/vkms: Create VKMS device from static config

Louis Chauvet louis.chauvet at bootlin.com
Thu Feb 27 14:30:28 UTC 2025



Le 18/02/2025 à 17:49, José Expósito a écrit :
> In order to make the process of creating new VKMS devices as simple as
> possible and in a declarative way, create a set of structures
> representing a VKMS device configuration and a function that reads them
> and applies the configuration.
> 
> In addition, add a test using this new function that checks that
> creating a device without planes fails.
> 
> Signed-off-by: José Expósito <jose.exposito89 at gmail.com>
> ---
>   lib/igt_vkms.c             | 88 ++++++++++++++++++++++++++++++++++++++
>   lib/igt_vkms.h             | 43 +++++++++++++++++++
>   tests/vkms/vkms_configfs.c | 40 +++++++++++++++++
>   3 files changed, 171 insertions(+)
> 
> diff --git a/lib/igt_vkms.c b/lib/igt_vkms.c
> index 1fcb93c94..4c44efec9 100644
> --- a/lib/igt_vkms.c
> +++ b/lib/igt_vkms.c
> @@ -253,6 +253,94 @@ igt_vkms_t *igt_vkms_device_create(const char *name)
>   	return dev;
>   }
>   
> +/**
> + * igt_vkms_device_create_from_config:
> + * @cfg: Device configuration
> + *
> + * Create a VKMS device and set all the parameters specified by the
> + * configuration.
> + */
> +igt_vkms_t *igt_vkms_device_create_from_config(igt_vkms_config_t *cfg)
> +{
> +	igt_vkms_t *dev;
> +	igt_vkms_plane_config_t *plane;
> +	igt_vkms_crtc_config_t *crtc;
> +	igt_vkms_encoder_config_t *encoder;
> +	igt_vkms_connector_config_t *connector;
> +	const char *name;
> +	int n, i;
> +
> +	igt_debug("Creating device from configuration:\n");
> +	igt_debug("\t- Device name: %s\n", cfg->device_name);
> +
> +	dev = igt_vkms_device_create(cfg->device_name);
> +	if (!dev)
> +		return NULL;
> +
> +	for (n = 0; (crtc = &cfg->crtcs[n])->name; n++) {
> +		igt_debug("\t- CRTC %d:\n", n);
> +		igt_debug("\t\t- name: %s\n", crtc->name);
> +		igt_debug("\t\t- writeback: %d\n", crtc->writeback);
> +
> +		igt_vkms_device_add_crtc(dev, crtc->name);
> +		igt_vkms_crtc_set_writeback_enabled(dev, crtc->name,
> +						    crtc->writeback);
> +	}
> +
> +	for (n = 0; (plane = &cfg->planes[n])->name; n++) {
> +		igt_debug("\t- Plane %d:\n", n);
> +		igt_debug("\t\t- name: %s\n", plane->name);
> +		igt_debug("\t\t- type: %d\n", plane->type);
> +		igt_debug("\t\t- possible_crtcs:\n");
> +
> +		igt_vkms_device_add_plane(dev, plane->name);
> +		igt_vkms_plane_set_type(dev, plane->name, plane->type);
> +
> +		for (i = 0; (name = plane->possible_crtcs[i]); i++) {
> +			igt_debug("\t\t\t- %s\n", name);
> +
> +			igt_vkms_plane_attach_crtc(dev, plane->name, name);
> +		}
> +	}
> +
> +	for (n = 0; (encoder = &cfg->encoders[n])->name; n++) {
> +		igt_debug("\t- Encoder %d:\n", n);
> +		igt_debug("\t\t- name: %s\n", encoder->name);
> +		igt_debug("\t\t- possible_crtcs:\n");
> +
> +		igt_vkms_device_add_encoder(dev, encoder->name);
> +
> +		for (i = 0; (name = encoder->possible_crtcs[i]); i++) {
> +			igt_debug("\t\t\t- %s\n", name);
> +
> +			igt_vkms_encoder_attach_crtc(dev, encoder->name, name);
> +		}
> +	}
> +
> +	for (n = 0; (connector = &cfg->connectors[n])->name; n++) {
> +		if (connector->status == 0)
> +			connector->status = DRM_MODE_CONNECTED;
> +
> +		igt_debug("\t- Connector %d:\n", n);
> +		igt_debug("\t\t- name: %s\n", connector->name);
> +		igt_debug("\t\t- status: %d\n", connector->status);
> +		igt_debug("\t\t- possible_encoders:\n");
> +
> +		igt_vkms_device_add_connector(dev, connector->name);
> +		igt_vkms_connector_set_status(dev, connector->name,
> +					      connector->status);
> +
> +		for (i = 0; (name = connector->possible_encoders[i]); i++) {
> +			igt_debug("\t\t\t- %s\n", name);
> +
> +			igt_vkms_connector_attach_encoder(dev, connector->name,
> +							  name);
> +		}
> +	}
> +
> +	return dev;
> +}
> +
>   static int detach_pipeline_items(const char *path, const struct stat *info,
>   				 const int typeflag, struct FTW *pathinfo)
>   {
> diff --git a/lib/igt_vkms.h b/lib/igt_vkms.h
> index 1ef62125f..79edabe81 100644
> --- a/lib/igt_vkms.h
> +++ b/lib/igt_vkms.h
> @@ -10,6 +10,8 @@
>   
>   #include <stdbool.h>
>   
> +#define VKMS_MAX_PIPELINE_ITEMS	40
> +
>   /**
>    * igt_vkms_t:
>    * @path: VKMS root directory inside configfs mounted directory
> @@ -20,9 +22,50 @@ typedef struct igt_vkms {
>   	char *path;
>   } igt_vkms_t;
>   
> +typedef struct igt_vkms_crtc_config {
> +	const char *name;
> +	bool writeback; /* Default: false */
> +} igt_vkms_crtc_config_t;
> +
> +typedef struct igt_vkms_plane_config {
> +	const char *name;
> +	int type; /* Default: DRM_PLANE_TYPE_OVERLAY */
> +	const char *possible_crtcs[VKMS_MAX_PIPELINE_ITEMS];
> +} igt_vkms_plane_config_t;
> +
> +typedef struct igt_vkms_encoder_config {
> +	const char *name;
> +	const char *possible_crtcs[VKMS_MAX_PIPELINE_ITEMS];
> +} igt_vkms_encoder_config_t;
> +
> +typedef struct igt_vkms_connector_config {
> +	const char *name;
> +	int status; /* Default: DRM_MODE_CONNECTED */
> +	const char *possible_encoders[VKMS_MAX_PIPELINE_ITEMS];
> +} igt_vkms_connector_config_t;
> +
> +/**
> + * igt_vkms_config_t:
> + * @device_name: Device name
> + * @planes: NULL terminated list of plane configurations
> + * @crtcs: NULL terminated list of CRTC configurations
> + * @encoders: NULL terminated list of encoders configurations
> + * @connectors: NULL terminated list of connector configurations
> + *
> + * Structure used to create a VKMS device from a static configuration.
> + */
> +typedef struct igt_vkms_config {
> +	const char *device_name;
> +	igt_vkms_plane_config_t planes[VKMS_MAX_PIPELINE_ITEMS];
> +	igt_vkms_crtc_config_t crtcs[VKMS_MAX_PIPELINE_ITEMS];
> +	igt_vkms_encoder_config_t encoders[VKMS_MAX_PIPELINE_ITEMS];
> +	igt_vkms_connector_config_t connectors[VKMS_MAX_PIPELINE_ITEMS];
> +} igt_vkms_config_t;
> +
>   void igt_require_vkms_configfs(void);
>   
>   igt_vkms_t *igt_vkms_device_create(const char *name);
> +igt_vkms_t *igt_vkms_device_create_from_config(igt_vkms_config_t *cfg);
>   void igt_vkms_device_destroy(igt_vkms_t *dev);
>   void igt_vkms_destroy_all_devices(void);
>   
> diff --git a/tests/vkms/vkms_configfs.c b/tests/vkms/vkms_configfs.c
> index 87d660fff..47cfa475f 100644
> --- a/tests/vkms/vkms_configfs.c
> +++ b/tests/vkms/vkms_configfs.c
> @@ -748,6 +748,45 @@ static void test_enable_no_pipeline_items(void)
>   	igt_vkms_device_destroy(dev);
>   }
>   
> +/**
> + * SUBTEST: enable-no-planes
> + * Description: Try to enable a VKMS device without adding planes and test that
> + *              it fails.
> + */
> +
> +static void test_enable_no_planes(void)
> +{
> +	igt_vkms_t *dev;
> +
> +	igt_vkms_config_t cfg = {
> +		.device_name = __func__,
> +		.planes = { {} },
> +		.crtcs = {
> +			{ .name = "crtc0" },
> +			{ .name = "crtc1" },
> +		},
> +		.encoders = {
> +			{ .name = "encoder0", .possible_crtcs = { "crtc0" } },
> +			{ .name = "encoder1", .possible_crtcs = { "crtc1" } },
> +		},
> +		.connectors = {
> +			{
> +				.name = "connector0",
> +				.possible_encoders = { "encoder0", "encoder1" },
> +			},
> +		},
> +	};
> +
> +	dev = igt_vkms_device_create_from_config(&cfg);
> +	igt_assert(dev);
> +
> +	igt_vkms_device_set_enabled(dev, true);

I just though about it, maybe it could be nice to have a 
/my-vkms/config-valid, that returns the status of the current configuration.
No need to add it to your current vkms-configfs series, I can do it later.

Reviewed-by: Louis Chauvet <louis.chauvet at bootlin.com>

> +	igt_assert(!igt_vkms_device_is_enabled(dev));
> +	igt_assert(!device_exists(__func__));
> +
> +	igt_vkms_device_destroy(dev);
> +}
> +
>   igt_main
>   {
>   	struct {
> @@ -771,6 +810,7 @@ igt_main
>   		{ "attach-encoder-to-crtc", test_attach_encoder_to_crtc },
>   		{ "attach-connector-to-encoder", test_attach_connector_to_encoder },
>   		{ "enable-no-pipeline-items", test_enable_no_pipeline_items },
> +		{ "enable-no-planes", test_enable_no_planes },
>   	};
>   
>   	igt_fixture {

-- 
Louis Chauvet, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com



More information about the igt-dev mailing list