From patchwork Wed Aug 14 15:15:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13763638 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7D398C531DD for ; Wed, 14 Aug 2024 15:16:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BD57810E4C5; Wed, 14 Aug 2024 15:16:05 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="EtDRzC5+"; dkim-atps=neutral Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9221310E497 for ; Wed, 14 Aug 2024 15:16:02 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 768286000A; Wed, 14 Aug 2024 15:16:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723648561; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1Wko6E4xauEKtnSS+VtA8L9zWLyLrg2+6EVQu8Spj3Y=; b=EtDRzC5+Ss9Oq+2KQNkKy8at1k40UMvePEDL2U66dQBb3+Y/2umeU+6Ky5yGt44JHToADt W/xXuK8YiRbkcV8TG7EhBAFlxfSUN8oV7nVDlUCWOD4wyA84msi4Zx9/CLbSCYNW5839Kc ZV4lWJm60PtlS6NEibbEYXFcuaoUjVa7M4XirybCgCIdLHgFltCHEt3Is/1Xd2NxEzp4lp B47rUNrPMmtvCxyccAeJmAWbrgztW9eI+iPrBifmVsercwtOYskISrQC23V0QKV7bWbP+m FjuqYtXnzpXqY7g9ZkmKUUqmaCrcOUr4JAg/HMpReen8zytzXftUzS0VHBGGOQ== From: Louis Chauvet Date: Wed, 14 Aug 2024 17:15:48 +0200 Subject: [PATCH RFC 1/7] drm/vkms: Add vkms_delete/create_device helper MIME-Version: 1.0 Message-Id: <20240814-google-config-fs-v1-1-8363181907a6@bootlin.com> References: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> In-Reply-To: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1505; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=KBDfEXrg7EsnVFW5hE1grE5/QDKpIdyCTzXK1gODbho=; b=kA0DAAgBIK0uxlsQLOIByyZiAGa8yi2jOTyL9U67CP+cMHFwbfrbUNg9XtS1i7neBOhqybYoC okCMwQAAQgAHRYhBE+PuD++eDwxDFBZBCCtLsZbECziBQJmvMotAAoJECCtLsZbECzi1GkP/2jx 3MbwfaNkXhRdgz1oHQ1pLPqJoCaEIJ8M4VnLuC07CWSvDeF2zPxhTYWVhAdXP25nf1esGS7pvSF KryjPMVcZNn1OPWNiROOaQSAw8Zz7jiFP/kOXYOX4HFf5RHwN9JYglq3CdS5PP3K0g6xiLd3bEI SEPCDzS05qaA5Jnra13fxzVclYKKfUVuP5Zcbg0jFYOv6a7XEakTaDtgKYntE49dHuBOrQaOHoy JBHw1Rf7/mLTT2VlDqD82zC59Htq9FYAxH+U9iU+EwrFoCC2FV1bLM8DvUjow8UI8no6ecNwrYU aIzUkpn1Xkib/vKME+gbf9tIFLU4ecfJorqbMKy7cLCjLLbiO0HA3l5lVfgWJZKwN1Xz8T75tlg LfZf1ay3ytAzVyxk6pcLMUBYRDmjiQYayyMFNfGgedt+uSOwku806dh/IowEgIKhKK6JJxwBLfW 701uC0HIEbQaiNrmp1ONZKB9pTcy0R4FqGdNrOD3zUbSHzA8N/UQV1ZbUn7zX8h4zAZz7LzdaRP s6+ksDvZfvHoyptgfR2oRXNyfgF5GyAneD1LQrIUhoKDI/guVRGXDqwWGldhw20mfncAVUTRFwf +8tHiqcAdQ3JLkuwE9eoXAepS87ayXzdmSc1Qp5OqP5acrcIOei/0SE7yBzwn7Cf89Bi9XuDBq9 iXc/u X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In preparation for introduction of ConfigFS support, expose the vkms_destroy/create helper to remove a vkms device. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_drv.c | 4 ++-- drivers/gpu/drm/vkms/vkms_drv.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index cd3920270905..9ea379f4338f 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -264,7 +264,7 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) return vkms_output_init(vkmsdev); } -static int vkms_create(struct vkms_config *config) +int vkms_create(struct vkms_config *config) { int ret; struct platform_device *pdev; @@ -331,7 +331,7 @@ static int __init vkms_init(void) return ret; } -static void vkms_destroy(struct vkms_config *config) +void vkms_destroy(struct vkms_config *config) { struct platform_device *pdev; diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 64574695f655..0e62c6b6bdbc 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -41,6 +41,9 @@ struct vkms_device { const struct vkms_config *config; }; +int vkms_create(struct vkms_config *config); +void vkms_destroy(struct vkms_config *config); + /* * The following helpers are used to convert a member of a struct into its parent. */ From patchwork Wed Aug 14 15:15:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13763637 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0314FC52D7D for ; Wed, 14 Aug 2024 15:16:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9F69210E4C4; Wed, 14 Aug 2024 15:16:05 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="f2+rjyMf"; dkim-atps=neutral Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 72D5810E497 for ; Wed, 14 Aug 2024 15:16:03 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 5D3626000B; Wed, 14 Aug 2024 15:16:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723648562; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8AQ78HzLONhDO3dQgXuU0bOwsL1VtElUuiVHAP3BCbs=; b=f2+rjyMfOPAez9QvdJoHwWhObt07jzULSbChy+avi+6inh5V3CtDlOJZHDUgW8unUm31yf FJMJQaZI2MZKdaLGG6GZ9TeXN7jL3w3uS75Zx5rrRZ95yD4QDgB+8J9laILG3W6rhwhoiw fNLIzmZZgx2DLFoWoYgsIYxKSeLHu4LxP84niosECe0+jvZcQPtLMKyFPFLbnRyQCMIrHB 6JDGczZJdPzDjvBQ8KmR2hVltVonGbAwv1zlJ0cnfMZvE3ShKQfXQPrQ+d8tXpWTVAeXOE AfLE4R/Pnae0g8whHJxVt8+DkaXhMZWniFfAKJvLIUu0ucIiOWfzuO4cb2K8dA== From: Louis Chauvet Date: Wed, 14 Aug 2024 17:15:49 +0200 Subject: [PATCH RFC 2/7] drm/vkms: Introduce ConfigFS interface MIME-Version: 1.0 Message-Id: <20240814-google-config-fs-v1-2-8363181907a6@bootlin.com> References: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> In-Reply-To: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=8006; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=ocjr/5bqUg2swyfu92asLp4bqmPVBLRlfv+QzOrgZMI=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmvMot6Hu5CCL0I0a8AwlDdMqi1xSKyFaAl68VM Y93JU955U2JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZrzKLQAKCRAgrS7GWxAs 4pHgD/4sHulyaNE7aXKDCnU+V9JLoKyvc0HrCt2WBhmLRw3oxNUVOZItGLy1i2Cpqo/97bD6KLh DlJqwU9NWDD87+dFVwTtH4mCq9HKt63N/7WI0xT0+WKFo/AjV6QdHjFKA2wllUWhKBE5f127byU G6CLLZVKP05wRrw+odYWp8TgNPjii4FnNP2N2WN96FJbQWQLv6zqJWemscTPEo3Gdnf603c8Zm9 lGaxyOy2c1rEOWuPfuOlP/dpJVw5u1xzw4cQdqOlEKVP987sSaSJN0vJ9wH7nKSALNIF6nyj6t6 l/uxQ3c4kVJd3b+QjD0er1ygNUF325EYZX0sZLkerB5IUwE/Fgqzt32o2fhJy5Eeelf9yHT8K0o 3poIoA3RtM6eHMG1yC/EsW3Ua+uUJxnxevoplZeqmks1xEPFJJQOSvhN39++HQem/C4oTctc6O1 w7xnIFML03q9X1f1Bgey/KqXySn20LJG2QvBCcybVha/9PlvEyL5IuYb2J10V9Ehv4wpAyxuI15 jOyLzYrSIxH+SENo0FEE0IoUS0uNwb3PoJ4NPRFe3pgnT7j4GBGvDexU4fwhLoQoDgFqSAUBUIG N1wAuTvFiFnoKi2o0vdr2/4ENpW5rRG+lCSCKSUECYLaQ8w3puQAL0B2aLq2KEiixXwqSOOZpnK F7aSgXCh8qs4oPg== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" VKMS is manly used to test userspace program and its behavior. The current implementation is not very configurable as you can only have one device, with few specific planes. This is the introduction of a basic interface to dynamically create new devices. The new interface is: /config/vkms DEVICE_1 ┗━ enable DEVICE_2 ┗━ enable Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/Kconfig | 1 + drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/vkms_configfs.c | 144 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_configfs.h | 35 +++++++++ drivers/gpu/drm/vkms/vkms_drv.c | 15 +++- 5 files changed, 194 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vkms/Kconfig b/drivers/gpu/drm/vkms/Kconfig index 59c4a32adb9d..8dddc9ba2e33 100644 --- a/drivers/gpu/drm/vkms/Kconfig +++ b/drivers/gpu/drm/vkms/Kconfig @@ -5,6 +5,7 @@ config DRM_VKMS depends on DRM && MMU select DRM_KMS_HELPER select DRM_GEM_SHMEM_HELPER + select CONFIGFS_FS select CRC32 default n help diff --git a/drivers/gpu/drm/vkms/Makefile b/drivers/gpu/drm/vkms/Makefile index 2b6db5870b97..9ecf6bc4779f 100644 --- a/drivers/gpu/drm/vkms/Makefile +++ b/drivers/gpu/drm/vkms/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only vkms-y := \ + vkms_configfs.o \ vkms_drv.o \ vkms_plane.o \ vkms_output.o \ diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c new file mode 100644 index 000000000000..6535672f0084 --- /dev/null +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include +#include + +#include "vkms_configfs.h" +#include "vkms_drv.h" +#include "vkms_config.h" + +static ssize_t device_enable_show(struct config_item *item, char *page) +{ + return sprintf(page, "%d\n", + config_item_to_vkms_configfs_device(item)->enabled); +} + +static ssize_t device_enable_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_configfs_device *vkms_configfs_device = + config_item_to_vkms_configfs_device(item); + + bool value; + int ret; + + ret = kstrtobool(page, &value); + if (ret) + return -EINVAL; + + mutex_lock(&vkms_configfs_device->lock); + + vkms_configfs_device->enabled = value; + + if (value) + vkms_create(vkms_configfs_device->vkms_config); + else + vkms_destroy(vkms_configfs_device->vkms_config); + + mutex_unlock(&vkms_configfs_device->lock); + + return (ssize_t)count; +} + +CONFIGFS_ATTR(device_, enable); + +static struct configfs_attribute *device_attrs[] = { + &device_attr_enable, + NULL, +}; + +static void device_release(struct config_item *item) +{ + struct vkms_configfs_device *vkms_configfs_device = + config_item_to_vkms_configfs_device(item); + + mutex_destroy(&vkms_configfs_device->lock); + vkms_config_destroy(vkms_configfs_device->vkms_config); + + kfree(vkms_configfs_device); +} + +static struct configfs_item_operations device_item_operations = { + .release = &device_release, +}; + +static const struct config_item_type device_item_type = { + .ct_attrs = device_attrs, + .ct_item_ops = &device_item_operations, + .ct_owner = THIS_MODULE, +}; + +/* Top directory management. Each new directory here is a new device */ +static struct config_group *root_make_group(struct config_group *group, + const char *name) +{ + struct vkms_config_plane *plane; + struct vkms_config_crtc *crtc; + struct vkms_config_encoder *encoder; + struct vkms_configfs_device *configfs = kzalloc(sizeof(*configfs), GFP_KERNEL); + + if (!configfs) + return ERR_PTR(-ENOMEM); + + mutex_init(&configfs->lock); + + configfs->vkms_config = vkms_config_create(); + + if (!configfs->vkms_config) { + kfree(configfs); + return ERR_PTR(-ENOMEM); + } + + plane = vkms_config_create_plane(configfs->vkms_config); + crtc = vkms_config_create_crtc(configfs->vkms_config); + encoder = vkms_config_create_encoder(configfs->vkms_config); + + if (!plane || !crtc || !encoder || + vkms_config_plane_attach_crtc(plane, crtc) || + vkms_config_encoder_attach_crtc(encoder, crtc)) { + vkms_config_destroy(configfs->vkms_config); + kfree(configfs); + return ERR_PTR(-ENOMEM); + } + + plane->type = DRM_PLANE_TYPE_PRIMARY; + + config_group_init_type_name(&configfs->group, name, + &device_item_type); + + return &configfs->group; +} + +static struct configfs_group_operations root_group_operations = { + .make_group = &root_make_group, +}; + +static struct config_item_type root_item_type = { + .ct_group_ops = &root_group_operations, + .ct_owner = THIS_MODULE, +}; + +static struct configfs_subsystem vkms_subsys = { + .su_group = { + .cg_item = { + .ci_name = "vkms", + .ci_type = &root_item_type, + }, + }, + .su_mutex = __MUTEX_INITIALIZER(vkms_subsys.su_mutex), +}; + +int vkms_init_configfs(void) +{ + config_group_init(&vkms_subsys.su_group); + + return configfs_register_subsystem(&vkms_subsys); +} + +void vkms_unregister_configfs(void) +{ + configfs_unregister_subsystem(&vkms_subsys); +} diff --git a/drivers/gpu/drm/vkms/vkms_configfs.h b/drivers/gpu/drm/vkms/vkms_configfs.h new file mode 100644 index 000000000000..3de89c9c552c --- /dev/null +++ b/drivers/gpu/drm/vkms/vkms_configfs.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#include +#include + +#ifndef _VKMS_CONFIGFS_H +#define _VKMS_CONFIGFS_H + +/** + * struct vkms_configfs_device - Internal object to manage all the configfs items related to one + * device + * + * @group: Main configfs group for a device + * @platform_device: If a device was created (@enabled = true), stores a pointer to it + * @lock: Mutex used to avoid conflicting edition of @vkms_config + * @enabled: Store if the device was created or not + * @vkms_config: Current vkms configuration + */ +struct vkms_configfs_device { + struct config_group group; + + struct mutex lock; + bool enabled; + + struct vkms_config *vkms_config; +}; + +#define config_item_to_vkms_configfs_device(item) \ + container_of(to_config_group((item)), struct vkms_configfs_device, group) + +/* ConfigFS Support */ +int vkms_init_configfs(void); +void vkms_unregister_configfs(void); + +#endif /* _VKMS_CONFIGFS_H */ diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 9ea379f4338f..e0ae21bcd590 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -29,6 +29,7 @@ #include "vkms_drv.h" #include "vkms_crtc.h" #include "vkms_config.h" +#include "vkms_configfs.h" #include #include @@ -270,7 +271,7 @@ int vkms_create(struct vkms_config *config) struct platform_device *pdev; struct vkms_device *vkms_device; - pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); + pdev = platform_device_register_simple(DRIVER_NAME, PLATFORM_DEVID_AUTO, NULL, 0); if (IS_ERR(pdev)) return PTR_ERR(pdev); @@ -324,9 +325,17 @@ static int __init vkms_init(void) if (IS_ERR(default_config)) return PTR_ERR(default_config); + ret = vkms_init_configfs(); + if (ret) { + DRM_ERROR("Unable to initialize configfs\n"); + vkms_config_destroy(default_config); + } + ret = vkms_create(default_config); - if (ret) + if (ret) { + vkms_unregister_configfs(); vkms_config_destroy(default_config); + } return ret; } @@ -355,6 +364,8 @@ static void __exit vkms_exit(void) vkms_destroy(default_config); vkms_config_destroy(default_config); + + vkms_unregister_configfs(); } module_init(vkms_init); From patchwork Wed Aug 14 15:15:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13763640 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A338C52D7B for ; Wed, 14 Aug 2024 15:16:11 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D595910E4C7; Wed, 14 Aug 2024 15:16:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="EtuqU+ZC"; dkim-atps=neutral Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 85D1710E4C3 for ; Wed, 14 Aug 2024 15:16:04 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 4404C60008; Wed, 14 Aug 2024 15:16:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723648563; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZSSEgzALF4vKg2vfhWBicyXqHvP7DH7+pYpffglePVI=; b=EtuqU+ZCI0MFdbb4XG9fUUr4MQ8e8M40+Kha7Yr1/kRxiySy1JFGbBh7dpC+39NQrqfBbs 6YDfi9+8YtscWovdbYaokMEIGaw35s7z4NeBK0a6E5blNJ2otC95BHMttV9iNdYYcKyRqy IARBIN5P+8xcYoCL+apBtjNUiXTfwOIzKCetNZiFlrzq6aweMwbzyIFz3HbDblviEszoRr pMLhSTcu2nDvsgx6oBHzKXNuPu6WYxVUdU565p8nth98e2yWUBS4F6zxlOJlxVQYOLS2kC gd2fTV83kczTlnEX98aLvlIXPUcXzJIgp12si1jJwl4Zex0GGNSjpArrPWMlGw== From: Louis Chauvet Date: Wed, 14 Aug 2024 17:15:50 +0200 Subject: [PATCH RFC 3/7] drm/vkms: Introduce basic plane creation MIME-Version: 1.0 Message-Id: <20240814-google-config-fs-v1-3-8363181907a6@bootlin.com> References: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> In-Reply-To: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=8099; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=DduqiiGFYxBlqSALvxd1rM9Lg73G3P3lQ2WXyodDEaI=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmvMotIhbMMn4mRP4Tt8n2zOCfXPzOAvj3CK+wN XVNXvSr0aKJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZrzKLQAKCRAgrS7GWxAs 4oADEACjOB/BnPSAOQwNfu9YApO7ChB6o/nmEKUe58Kh4aZ4Lz8T4vi4oIuWIOw9nWySAE2z7P4 kv7pTn6gaemRhPQw4ry4PoHDuKbH/ovNk9kb/tJqAk8NQQw1Wjc31njo4Hbc62Kwpc/5GgAGWxn pgRYwPaVikfo7NZ89m0W77YNRnCzj3uj2nbeAyj3DgX0/kX8d8Lo3jAHo0AZKteWa9dDTRJKw86 E/lICj5vaPdkutJrqp1Bvlvy42AA++Jjp1cxZe2OND9ljJV49TIWAN7G8fowFAsqdlt+jkenfPB os/Bwj68RtkJYff/cEuwkjDmt2DmthaqZ5372rmbfuWwdpnRhwk/R6OMIEZkHtb3bbJNwB3MdbJ LfhtUiewEh3O86E1F5ydfPReOMMk56N7HjhiIV9q9goCFGsF89HaZvWNSwYvEx/pX0SOI6HqBAr 8cHvmWkC4a6Xicv8s8qRQBPdpzkHPt4DPQQI4Ic1HNBUL3znA4iGMRSPafI0oN23rFcLC2P6oNw wNPhD1O8HKbqzq8A+r7p8RbG8nF7QeHurAbq1mEyhB6aO4q21C2+KOeo7YLm+Eg8dSKUDd2Z6NN m+nC42lgrCMYXVzZgfLz6783af0PWiDdpIwkkhDhKSLIzORf4uQBuZYW75g4pg4u/BTr+c85VQB Ea5Y7c9qIPKQEyw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to test many hardware configuration, introduce a new interface to create and configure planes. The planes are created by creating a directory in the `planes` directory. The type of plane is configured by writing 0 (Overlay), 1 (primary) or 2 (cursor) in the file `type`. As the CRTCs and encoders can't be configured yet, the planes are all atteched to the same CRTC and encoder. The current interface is: /config/vkms DEVICE_1 ┣━ enable ┣━ planes ┃ ┣━ PLANE_1 ┃ ┃ ┣━ type ┃ ┣━ PLANE_2 ┃ ┃ ┗━ type ┃ ┗━ PLANE_3 ┃ ┗━ type DEVICE_2 ┗━ ditto Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 149 ++++++++++++++++++++++++++++++++--- drivers/gpu/drm/vkms/vkms_configfs.h | 20 +++++ 2 files changed, 160 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index 6535672f0084..ee64243396b3 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -10,6 +10,138 @@ #include "vkms_drv.h" #include "vkms_config.h" +static ssize_t plane_type_show(struct config_item *item, char *page) +{ + struct vkms_config_plane *plane; + enum drm_plane_type plane_type; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + plane_type = plane->type; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", plane_type); +} + +static ssize_t plane_type_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + enum drm_plane_type val = DRM_PLANE_TYPE_OVERLAY; + struct vkms_config_plane *plane; + int ret; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + if (val != DRM_PLANE_TYPE_PRIMARY && val != DRM_PLANE_TYPE_CURSOR && + val != DRM_PLANE_TYPE_OVERLAY) + return -EINVAL; + + mutex_lock(&vkms_configfs->lock); + if (vkms_configfs->enabled) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + plane->type = val; + + mutex_unlock(&vkms_configfs->lock); + + return count; +} + +CONFIGFS_ATTR(plane_, type); + +static struct configfs_attribute *plane_attrs[] = { + &plane_attr_type, + NULL, +}; + +static void plane_release(struct config_item *item) +{ + struct vkms_configfs_plane *vkms_configfs_plane = plane_item_to_vkms_configfs_plane(item); + + mutex_lock(&vkms_configfs_plane->vkms_configfs_device->lock); + vkms_config_delete_plane(vkms_configfs_plane->vkms_config_plane, + vkms_configfs_plane->vkms_configfs_device->vkms_config); + mutex_unlock(&vkms_configfs_plane->vkms_configfs_device->lock); + + kfree(vkms_configfs_plane); +} + +static struct configfs_item_operations plane_item_operations = { + .release = plane_release, +}; + +static const struct config_item_type subgroup_plane = { + .ct_attrs = plane_attrs, + .ct_item_ops = &plane_item_operations, + .ct_owner = THIS_MODULE, +}; + +static struct config_group *planes_make_group(struct config_group *config_group, + const char *name) +{ + struct vkms_configfs_device *vkms_configfs; + struct vkms_configfs_plane *vkms_configfs_plane; + + vkms_configfs = planes_item_to_vkms_configfs_device(&config_group->cg_item); + vkms_configfs_plane = kzalloc(sizeof(*vkms_configfs_plane), GFP_KERNEL); + + if (!vkms_configfs_plane) + return ERR_PTR(-ENOMEM); + + mutex_lock(&vkms_configfs->lock); + + if (vkms_configfs->enabled) { + kfree(vkms_configfs_plane); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-EINVAL); + } + + vkms_configfs_plane->vkms_config_plane = vkms_config_create_plane(vkms_configfs->vkms_config); + + if (list_count_nodes(&vkms_configfs->vkms_config->planes) == 1) + vkms_configfs_plane->vkms_config_plane->type = DRM_PLANE_TYPE_PRIMARY; + + if (!vkms_configfs_plane->vkms_config_plane || + vkms_config_plane_attach_crtc(vkms_configfs_plane->vkms_config_plane, + vkms_configfs->vkms_config_crtc)) { + kfree(vkms_configfs_plane); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-ENOMEM); + } + + vkms_configfs_plane->vkms_config_plane->name = kzalloc(strlen(name) + 1, GFP_KERNEL); + if (!vkms_configfs_plane->vkms_config_plane->name) { + kfree(vkms_configfs_plane->vkms_config_plane); + kfree(vkms_configfs_plane); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-ENOMEM); + } + strscpy(vkms_configfs_plane->vkms_config_plane->name, name, strlen(name) + 1); + + config_group_init_type_name(&vkms_configfs_plane->group, name, &subgroup_plane); + + vkms_configfs_plane->vkms_configfs_device = vkms_configfs; + mutex_unlock(&vkms_configfs->lock); + + return &vkms_configfs_plane->group; +} + +static struct configfs_group_operations planes_group_operations = { + .make_group = &planes_make_group, +}; + +static const struct config_item_type planes_item_type = { + .ct_group_ops = &planes_group_operations, + .ct_owner = THIS_MODULE, +}; + static ssize_t device_enable_show(struct config_item *item, char *page) { return sprintf(page, "%d\n", @@ -92,23 +224,22 @@ static struct config_group *root_make_group(struct config_group *group, return ERR_PTR(-ENOMEM); } - plane = vkms_config_create_plane(configfs->vkms_config); - crtc = vkms_config_create_crtc(configfs->vkms_config); - encoder = vkms_config_create_encoder(configfs->vkms_config); - - if (!plane || !crtc || !encoder || - vkms_config_plane_attach_crtc(plane, crtc) || - vkms_config_encoder_attach_crtc(encoder, crtc)) { + configfs->vkms_config_crtc = vkms_config_create_crtc(configfs->vkms_config); + configfs->vkms_config_encoder = vkms_config_create_encoder(configfs->vkms_config); + if (!configfs->vkms_config_crtc || !configfs->vkms_config_encoder || + vkms_config_encoder_attach_crtc(configfs->vkms_config_encoder, + configfs->vkms_config_crtc)) { vkms_config_destroy(configfs->vkms_config); kfree(configfs); return ERR_PTR(-ENOMEM); } - plane->type = DRM_PLANE_TYPE_PRIMARY; - config_group_init_type_name(&configfs->group, name, &device_item_type); + config_group_init_type_name(&configfs->plane_group, "planes", &planes_item_type); + configfs_add_default_group(&configfs->plane_group, &configfs->group); + return &configfs->group; } diff --git a/drivers/gpu/drm/vkms/vkms_configfs.h b/drivers/gpu/drm/vkms/vkms_configfs.h index 3de89c9c552c..6dc4d34a9e44 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.h +++ b/drivers/gpu/drm/vkms/vkms_configfs.h @@ -19,15 +19,35 @@ struct vkms_configfs_device { struct config_group group; + struct config_group plane_group; + struct mutex lock; bool enabled; struct vkms_config *vkms_config; + struct vkms_config_crtc *vkms_config_crtc; + struct vkms_config_encoder *vkms_config_encoder; +}; + +struct vkms_configfs_plane { + struct config_group group; + + struct vkms_configfs_device *vkms_configfs_device; + struct vkms_config_plane *vkms_config_plane; }; #define config_item_to_vkms_configfs_device(item) \ container_of(to_config_group((item)), struct vkms_configfs_device, group) +#define planes_item_to_vkms_configfs_device(item) \ + config_item_to_vkms_configfs_device((item)->ci_parent) + +#define plane_item_to_vkms_configfs_device(item) \ + planes_item_to_vkms_configfs_device((item)->ci_parent) + +#define plane_item_to_vkms_configfs_plane(item) \ + container_of(to_config_group((item)), struct vkms_configfs_plane, group) + /* ConfigFS Support */ int vkms_init_configfs(void); void vkms_unregister_configfs(void); From patchwork Wed Aug 14 15:15:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13763642 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 16D7DC52D7D for ; Wed, 14 Aug 2024 15:16:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C428B10E4C3; Wed, 14 Aug 2024 15:16:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="ODBNCsvg"; dkim-atps=neutral Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7838410E4C3 for ; Wed, 14 Aug 2024 15:16:05 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 3B76F6000D; Wed, 14 Aug 2024 15:16:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723648564; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RKjlHe9xFxfKxkmQ2Xrvh2exVCHwikpOquCsWlg3HDk=; b=ODBNCsvgax6yadluuow6Hg23ozJQ0kMLzixXu1PjpmhkBGCY256ZffVGuyDTdZHq4EXtmV vVZcfHB4MRqzAywvLKaRur/uRH/hYEWkQMAZTXZU89+xRnwEdsFLXOQv19BgIAI6OIz0Z/ Gh+VmHZLG6I7nBfCbv4C2RdKvLuxzb0iLQBt7CaEJ7zpTet9w+mjHZ9hLjHxLg/BQZoULa LiEk4Pgs4K/06wITfIz6jiCa9323304Vwh5MoMi5jHO1YDkNY7VovzmuZ4A63SyrgH4/YU hPQ8Vzq3ZWCIdydU6FaZorIVVp0ybtngc+tkW0LmwyTLW+cH5JI72wBHOoqBnQ== From: Louis Chauvet Date: Wed, 14 Aug 2024 17:15:51 +0200 Subject: [PATCH RFC 4/7] drm/vkms: Introduce plane rotation in ConfigFS MIME-Version: 1.0 Message-Id: <20240814-google-config-fs-v1-4-8363181907a6@bootlin.com> References: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> In-Reply-To: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4639; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=VisPuok/AC9dpwIcNrP7vfKY6K/NAxXvu5xl6hEogsw=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmvMot6Va9baCE8ZVJTTulVVVkuGAfsR922jQtf fjv3hnXzCSJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZrzKLQAKCRAgrS7GWxAs 4jOZEACpZr0rF5dsoICC5hL0prJ53A10//5QCw9paKJ69iorMAdRkHTI53o8aAktLw7+VIhpuNn ouXlySYWierxeqoLOEz1G4424diN9mat2NE32BTPNq49GVd9M7h0JYV0H4z3Vm81TNl5mY/UGJT rn1gRrudMq75osD6OsxAQuYNvLJpUG03U99fzxdD2eSTtTV4keuF7HfCAgT302yDDKEHX2KLDSW JLpkerC/NANLjnBeOSQhw0K8aM5vozABMpehA7Rac5oahlQQm8XbSsKZ1YMviFgep3JEN9rBGXJ vXln1usnX7El9cJKDQ0CdXEoShJCfFvTRl1gH26hi3nwd3kNegUMRwl653r0nCJpHA/3mWXCuxC JII7AAPhaLwsD1jpd00dKkhmtwxQe0nzdgwVaJ01PN9K730Am/jpzpfOiuWifZ1WO2PUqTIcOqc rod249sXgbg8dRgWVS6FuPhwRieDt/JH7U6ehzHbXbPUYRC07ZgfrhI1bELg6/hqr3iv7UTb40e mbl1HO0AffYdaSI6Hpgpzb53HoARS6ZoaYJL1i7k2AMlyAELasbARbgzGQLzrQWU4kS5Mdalz8p kaWPKHq2bxhgJ1Bxeo4ZALX5aj9ab+7IkwboB2uu+mBa6wXs5cLlVsUu0P9tO54t3ehRe61uAL+ Szp0ej3Qge39ULg== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to test many hardware configuration, introduce a new interface to configure the available rotation per planes. VKMS supports any rotation and reflection, so the userspace can choose any combination. The supported rotations are configured by writing a rotation bitmask to the file `supported_rotations` and the default rotation is chosen by writing a rotation bitmask to `default_rotation`. The current interface is: /config/vkms DEVICE_1 ┣━ enable ┣━ planes ┃ ┗━ PLANE_1 ┃ ┣━ type ┃ ┣━ supported_rotations ┃ ┗━ default_rotation DEVICE_2 ┗━ ditto Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 102 +++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index ee64243396b3..d121cf54e752 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -54,10 +54,112 @@ static ssize_t plane_type_store(struct config_item *item, return count; } +static ssize_t plane_supported_rotations_show(struct config_item *item, char *page) +{ + struct vkms_config_plane *plane; + unsigned int plane_type; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + plane_type = plane->supported_rotations; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", plane_type); +} + +static ssize_t plane_supported_rotations_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_config_plane *plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + int ret, val = 0; + + ret = kstrtouint(page, 0, &val); + if (ret) + return ret; + + /* Should be a supported value */ + if (val & ~(DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK)) + return -EINVAL; + /* Should at least provide one rotation */ + if (!(val & DRM_MODE_ROTATE_MASK)) + return -EINVAL; + + mutex_lock(&vkms_configfs->lock); + + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + + /* Ensures that the default rotation is included in supported rotation */ + if (vkms_configfs->enabled || (val & plane->default_rotation) != plane->default_rotation) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + + plane->supported_rotations = val; + mutex_unlock(&vkms_configfs->lock); + + return count; +} + +static ssize_t plane_default_rotation_show(struct config_item *item, char *page) +{ + unsigned int plane_type; + struct vkms_config_plane *plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + plane_type = plane->default_rotation; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", plane_type); +} + +static ssize_t plane_default_rotation_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_config_plane *plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + int ret, val = 0; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + /* Should be a supported value */ + if (val & ~(DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK)) + return -EINVAL; + /* Should at least provide one rotation */ + if ((val & DRM_MODE_ROTATE_MASK) == 0) + return -EINVAL; + /* Should contains only one rotation */ + if (!is_power_of_2(val & DRM_MODE_ROTATE_MASK)) + return -EINVAL; + mutex_lock(&vkms_configfs->lock); + + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + + /* Ensures that the default rotation is included in supported rotation */ + if (vkms_configfs->enabled || + (val & plane->supported_rotations) != val) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + plane->default_rotation = val; + mutex_unlock(&vkms_configfs->lock); + + return count; +} + CONFIGFS_ATTR(plane_, type); +CONFIGFS_ATTR(plane_, supported_rotations); +CONFIGFS_ATTR(plane_, default_rotation); static struct configfs_attribute *plane_attrs[] = { &plane_attr_type, + &plane_attr_supported_rotations, + &plane_attr_default_rotation, NULL, }; From patchwork Wed Aug 14 15:15:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13763641 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CD8C4C531DE for ; Wed, 14 Aug 2024 15:16:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5F44B10E4C8; Wed, 14 Aug 2024 15:16:09 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="ohIAGA8F"; dkim-atps=neutral Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3EDFD10E4C3 for ; Wed, 14 Aug 2024 15:16:06 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 333B060007; Wed, 14 Aug 2024 15:16:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723648565; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UDmGLaOI4YxgN9O9B/IDiZjMLxVVtDfIXivTYF6tc+8=; b=ohIAGA8FNN+8tEtC8aZhBFSVIgxRixUT9unp227YPPLXnyyN5aznqEfT/tFMlBFS+xpAwQ rpQcazgN09e505m4F9Eu12SNb1QaSj/hDWc8AhQcNItgVH6PcVpD3wVBhXmN2L6DQH40i0 rg5hIp6expPjAeJ4daCn5Vu5ohzK02NfJTMkzGw72MgSXDVem5hPqHjPfQgN7NiX9EeSoA ZYziUVmk3L/8z0yN1CjwB5CSkNfUkImwSyXhW56nm9xokl/xml+/yxk7A6CRS5dOotRzBe ZZJnGJ/4bMlKDm7mDrINryWkqmg3GE6UP3XxG/ywZmPsHmEWpfORorYWc5cFlg== From: Louis Chauvet Date: Wed, 14 Aug 2024 17:15:52 +0200 Subject: [PATCH RFC 5/7] drm/vkms: Add color encoding to ConfigFS MIME-Version: 1.0 Message-Id: <20240814-google-config-fs-v1-5-8363181907a6@bootlin.com> References: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> In-Reply-To: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=5372; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=J/CrkUPTSbciCxHTSvcXfOPmoAO3X4cKNlwq2Imz+Iw=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmvMoufAdtJ//ZKjEqR6xQiaH3lweIyo4Lkazql hbbGxsInEaJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZrzKLgAKCRAgrS7GWxAs 4mPOD/0cXvM+XmKaEH539iSdAFe2WgPT81FqczRW/O9nurF7UYpBEuP71/0sIZFsqoWUjqGlPd9 /a7ISp54UaZZ2FYhaYBPQxBLcsv0nuhaj4BIfE/nnLzKn9xiWDWJLfSq8SU3hItQ4ngecPMnEe+ /ju0hiloEql++XXgKZOlKF4iodqjAjRA7YHsrcE0/u22uua47WDVeXvb4prfRDlrbOGiCZmsei1 tL9lcg9oC5xSw7+je9C+zaHOqRp72ETGKV7A7hZSXOo6emzUhh+j1nhUkxJabiGqag7Jzfq5jwo BisY7QaBWHktjWhwsiIqQhIX48eBqRN7L1cQR6h4prUGv7nbARdI54+cSVT53VOSMx9VFhJMqw4 jBmLM1GVDN/rCszFIn4yjL0t9AJewLd31wB4rBe5Jv5GOAgNYz0PzH+2LMfTw8bRbhUqThaRKuR 40F2x/OWC97qJMGkgM9eG3PJewrd+bmrhJMKXbaZNunwuBOkRM97KsZjp3d+E+nHbawX/Ce5B4Q s37+Uf+QRt/maIzLJKIbS4+ukPw7PAVtcMZh7Bt99A0coCuah49WAdh/37+DCbQtg/JZmOMqFwO pqldk+OIqxFRf9TFjRKXJOg7hy5mRsO2yunNvTueD7fazfaXsBezXw3mlDt8T3XYv2ASIRpyDQD zF2UnWc8yin6Ljw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to test many hardware configuration, introduce a new interface to configure the available color encoding per planes. VKMS supports multiple color encoding, so the userspace can choose any combination. The supported color encoding are configured by writing a color encoding bitmask to the file `supported_color_encoding` and the default color encoding is chosen by writing a color encoding bitmask to `default_color_encoding`. The current interface is: /config/vkms DEVICE_1 ┣━ enable ┣━ planes ┃ ┗━ PLANE_1 ┃ ┣━ type ┃ ┣━ supported_rotations ┃ ┣━ supported_color_encoding ┃ ┣━ default_rotation ┃ ┗━ default_color_encoding DEVICE_2 ┗━ ditto Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 107 +++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index d121cf54e752..a3dab5986882 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -152,14 +152,121 @@ static ssize_t plane_default_rotation_store(struct config_item *item, return count; } +static ssize_t plane_supported_color_encoding_show(struct config_item *item, char *page) +{ + struct vkms_config_plane *plane; + unsigned int supported_color_encoding; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + supported_color_encoding = plane->supported_color_encoding; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", supported_color_encoding); +} + +static ssize_t plane_supported_color_encoding_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + struct vkms_config_plane *plane; + int ret, val = 0; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + /* Should be a supported value */ + if (val & ~(BIT(DRM_COLOR_YCBCR_BT601) | + BIT(DRM_COLOR_YCBCR_BT709) | + BIT(DRM_COLOR_YCBCR_BT2020))) + return -EINVAL; + /* Should at least provide one color range */ + if ((val & (BIT(DRM_COLOR_YCBCR_BT601) | + BIT(DRM_COLOR_YCBCR_BT709) | + BIT(DRM_COLOR_YCBCR_BT2020))) == 0) + return -EINVAL; + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + + /* Ensures that the default rotation is included in supported rotation */ + if (vkms_configfs->enabled || (val & plane->default_color_encoding) != + plane->default_color_encoding) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + plane->supported_color_encoding = val; + mutex_unlock(&vkms_configfs->lock); + + return count; +} + +/* Plane default_color_encoding : vkms//planes//default_color_encoding */ + +static ssize_t plane_default_color_encoding_show(struct config_item *item, char *page) +{ + struct vkms_config_plane *plane; + unsigned int default_color_encoding; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + default_color_encoding = plane->default_color_encoding; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", default_color_encoding); +} + +static ssize_t plane_default_color_encoding_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_config_plane *plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + int ret, val = 0; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + /* Should be a supported value */ + if (val & ~(BIT(DRM_COLOR_YCBCR_BT601) | + BIT(DRM_COLOR_YCBCR_BT709) | + BIT(DRM_COLOR_YCBCR_BT2020))) + return -EINVAL; + /* Should at least provide one color range */ + if ((val & (BIT(DRM_COLOR_YCBCR_BT601) | + BIT(DRM_COLOR_YCBCR_BT709) | + BIT(DRM_COLOR_YCBCR_BT2020))) == 0) + return -EINVAL; + mutex_lock(&vkms_configfs->lock); + + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + + /* Ensures that the default rotation is included in supported rotation */ + if (vkms_configfs->enabled || (val & plane->supported_color_encoding) != val) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + plane->default_color_encoding = val; + mutex_unlock(&vkms_configfs->lock); + + return count; +} + CONFIGFS_ATTR(plane_, type); CONFIGFS_ATTR(plane_, supported_rotations); CONFIGFS_ATTR(plane_, default_rotation); +CONFIGFS_ATTR(plane_, supported_color_encoding); +CONFIGFS_ATTR(plane_, default_color_encoding); static struct configfs_attribute *plane_attrs[] = { &plane_attr_type, &plane_attr_supported_rotations, &plane_attr_default_rotation, + &plane_attr_supported_color_encoding, + &plane_attr_default_color_encoding, NULL, }; From patchwork Wed Aug 14 15:15:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13763639 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DC910C3DA4A for ; Wed, 14 Aug 2024 15:16:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B8F1C10E4C6; Wed, 14 Aug 2024 15:16:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="BkPNgfIj"; dkim-atps=neutral Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4ED3710E4C3 for ; Wed, 14 Aug 2024 15:16:07 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 1C2496000C; Wed, 14 Aug 2024 15:16:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723648566; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ZtHdgw9McHanJ5bgqEq9uSdi74niZL2dpQLUKRPjzOU=; b=BkPNgfIj7lzx08jG3e3/K2pbTyUPcF5iXTw/ho9ACTIoCqF+yUCGEvjOsOzEfMbPoyYwrs 1inTWqg9LmvtK/SmG71dQD2apILkJvqMOOJ9HkwPoYvENWjyypWZrV0Uk5l1HpwJlYkjGQ sEJgRjICurqGYHXC1ifVNKmYMk/D5+97cVMRNUu9DH332tGSosjP0E4SQ0ioF/GjJOc6Rd u9vGowgFnsyTNC3Bb/5DsjDaF9zgoAZIFCF7c1wj2UnOskekTCW5dJzNXdhdcMMSpomNp1 SKP+kVmuXQOP9x9zN3EsZGx7kDzrnlvMgh1l0eLrd0ZXqpX1j+9q/sOOmqi4Dw== From: Louis Chauvet Date: Wed, 14 Aug 2024 17:15:53 +0200 Subject: [PATCH RFC 6/7] drm/vkms: Add color range in ConfigFS MIME-Version: 1.0 Message-Id: <20240814-google-config-fs-v1-6-8363181907a6@bootlin.com> References: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> In-Reply-To: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=5517; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=UwfWjkDRUSPTIpDVCjvKIClHTrQ+CQ4DCl4x+NwGblw=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmvMouw1bQlgtzsLxesTAO9Pp5Dmg7I7dl32SPZ QU6egIGqXyJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZrzKLgAKCRAgrS7GWxAs 4iMxEACrdScEUMyOO/jJ053MWzOFSgbEYepGRtExWLtPPnm9+5AUUKkcnsG1OhvPaQUt01+mdqq IQGZGP1OWrUnQT+QeRmyASiJMXXL5TeHtKYZiP+5zPa5WMQH684PVwWiGcx8Sg9awp/o2fG+gUu OB+L9quTbAZOJ0HQLeBWplv3/9UiNnRJ7I8IG8zVeWnYSZxaqwvEAVxMe2C8zJnx0z6HFyLv+cL w/5/7Nq5f+PvYDsLRQUf2/islVyD+O1lWcA9A49ufCNiTJTwyaPgz+dkq0NBReQOHxlAIsPoPwt /6z1FR7jLss/VPtL0ISd52wmjJ5dUw4ZgnJsIcfV8W+aiBbSV83ZjPGOjUqM2Ih97JcMYWMV6jD Ehp3wkiIx2o1oAPoT6if4WuuQFw5OAE1N6d604mFBdv7gFFYQz8Y3pqu6FBA8xqLOj9+8+DfhuO IDtiwAU77SzsmTiSWfeV2EOT/oyPDxT3ZnzNkT4uCBLNloP2YYqRrjziezrfYzWxuElpYLq+hqL 0YA5E7ms3NHmXY1y/c1omia8ybwK9uGzMWr2jFxD2ZYW6iExhNhl5ueQ5gUVJuDAqIADMsdBNuU yuMaHIZWMGuc7TlJlnlPtwIYYl5wkzcWsE6vtTPegaiwNLmLeGAUZVqR8+/n5YwXfZYAFkXQDBO AVmX7eTU1ya6gAg== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to test many hardware configuration, introduce a new interface to configure the available color ranges per planes. VKMS supports multiple color ranges, so the userspace can choose any combination. The supported color ranges are configured by writing a color range bitmask to the file `supported_color_ranges` and the default color range is chosen by writing a color encoding bitmask to `default_color_range`. The current interface is: /config/vkms DEVICE_1 ┣━ enable ┣━ planes ┃ ┗━ PLANE_1 ┃ ┣━ type ┃ ┣━ supported_rotations ┃ ┣━ supported_color_encoding ┃ ┣━ supported_color_ranges ┃ ┣━ default_rotation ┃ ┣━ default_color_encoding ┃ ┗━ default_color_range DEVICE_2 ┗━ ditto Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 103 +++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index a3dab5986882..aabc83283626 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -152,6 +152,105 @@ static ssize_t plane_default_rotation_store(struct config_item *item, return count; } +static ssize_t plane_color_range_show(struct config_item *item, char *page) +{ + struct vkms_config_plane *plane; + unsigned int plane_type; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + plane_type = plane->supported_color_range; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", plane_type); +} + +static ssize_t plane_color_range_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_config_plane *plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + int ret, val = 0; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + /* Should be a supported value */ + if (val & ~(BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) | + BIT(DRM_COLOR_YCBCR_FULL_RANGE))) + return -EINVAL; + /* Should at least provide one color range */ + if ((val & (BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) | + BIT(DRM_COLOR_YCBCR_FULL_RANGE))) == 0) + return -EINVAL; + + mutex_lock(&vkms_configfs->lock); + + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + + /* Ensures that the default rotation is included in supported rotation */ + if (vkms_configfs->enabled || (val & plane->default_color_range) != + plane->default_color_range) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + plane->supported_color_range = val; + mutex_unlock(&vkms_configfs->lock); + + return count; +} + +static ssize_t plane_default_color_range_show(struct config_item *item, char *page) +{ + struct vkms_config_plane *plane; + unsigned int plane_type; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + plane_type = plane->default_color_range; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", plane_type); +} + +static ssize_t plane_default_color_range_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_config_plane *plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + int ret, val = 0; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + /* Should be a supported value */ + if (val & ~(BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) | + BIT(DRM_COLOR_YCBCR_FULL_RANGE))) + return -EINVAL; + /* Should at least provide one color range */ + if ((val & (BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) | + BIT(DRM_COLOR_YCBCR_FULL_RANGE))) == 0) + return -EINVAL; + + mutex_lock(&vkms_configfs->lock); + + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + + /* Ensures that the default rotation is included in supported rotation */ + if (vkms_configfs->enabled || (val & plane->supported_color_range) != val) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + plane->default_color_range = val; + mutex_unlock(&vkms_configfs->lock); + + return count; +} + static ssize_t plane_supported_color_encoding_show(struct config_item *item, char *page) { struct vkms_config_plane *plane; @@ -258,6 +357,8 @@ static ssize_t plane_default_color_encoding_store(struct config_item *item, CONFIGFS_ATTR(plane_, type); CONFIGFS_ATTR(plane_, supported_rotations); CONFIGFS_ATTR(plane_, default_rotation); +CONFIGFS_ATTR(plane_, color_range); +CONFIGFS_ATTR(plane_, default_color_range); CONFIGFS_ATTR(plane_, supported_color_encoding); CONFIGFS_ATTR(plane_, default_color_encoding); @@ -265,6 +366,8 @@ static struct configfs_attribute *plane_attrs[] = { &plane_attr_type, &plane_attr_supported_rotations, &plane_attr_default_rotation, + &plane_attr_color_range, + &plane_attr_default_color_range, &plane_attr_supported_color_encoding, &plane_attr_default_color_encoding, NULL, From patchwork Wed Aug 14 15:15:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13763643 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 93293C3DA4A for ; Wed, 14 Aug 2024 15:16:13 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C404310E4CA; Wed, 14 Aug 2024 15:16:09 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="SsBxRMZe"; dkim-atps=neutral Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3FE2F10E4C3 for ; Wed, 14 Aug 2024 15:16:08 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 11DFD6000F; Wed, 14 Aug 2024 15:16:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1723648566; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=MaTjbXPWIRzTBUyMwGINxQZs0jxBhFozYAqNlfR9KmE=; b=SsBxRMZeqybDYVbztyYH4dC0904IXI5pGf3Zek9POFDl7Gc0UCb26WxeGymfKTLW4y0raX LNnM+dNFsRNlDvDsDFc7lxBdqYOBqRRgOom8oArZx/2LWX1Dt/1ziMY3QRBsLu4P7x2B1y +3Mbmlo42Xv+w1SPhm8BMsqYqss5J6qfTZ4kQvfFFVH4KG0xGOhBuXrT4yAOL/gbwu7C4H 9of4JjNV3q0w0dG1iV8GW2CkjDSw+xtfncM3B/t5FL+TKvLKcOnqCc3jLJtGfAKr9SQUni OSoT50hwwmEcZpOVhnK4zGkNdGihGZe4D6ejSYaynoYoMhlTQjdVQUEkM+Ul4g== From: Louis Chauvet Date: Wed, 14 Aug 2024 17:15:54 +0200 Subject: [PATCH RFC 7/7] drm/vkms: Add crtc and encoder configuration in ConfigFS MIME-Version: 1.0 Message-Id: <20240814-google-config-fs-v1-7-8363181907a6@bootlin.com> References: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> In-Reply-To: <20240814-google-config-fs-v1-0-8363181907a6@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Daniel Vetter , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=20727; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=Nsg/uRD+2tjnA4hgI+v/8HLJQELciWuCytDhk8mD3jU=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBmvMou5lkcipOcd3X60wbj02dn6IJsw43+YyCPo OTYFDBKcm2JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZrzKLgAKCRAgrS7GWxAs 4jy7EADPULHBS5PfvafU7PC+e5LcX8M5CHKAKAYljEYw6wPtj5bxnxmhOV+sWtOBkrFfFR5NIaC 3p8xiX0jqF983y2ba5igzN1Ve2zbSAwK+jUqeicVaSKccOUk0kxCSy243eMj2lNLiNaSmJHcpy5 rCXziLHYLf+bcKWgLnj2sK1/YJx6weKz4AiP7Utw4HCjG9GIhEIKYjqtHzirO50GKVstW6wsVt8 4hKloy3PlK70mlFtk5tYiW9PR99navIbYCT9PX4cIj/kW5ZaeSiTdXFsW2KF+R1i36Y9VeXo7YJ bIp4xA47DxraExl1/13yBZSQ4Uqxmq4LUhbSG6oGSIPCIIOMIeRmBlDZStcY/eW1CmNT4oCTWas L8ytWqGx+Q7AY+40TdqiumJVIPDHe++xXgDeyo1BDWrI3pUYokASwI2b9D/t58KbNfTBJUpfnIz LiVRCz7JTwROHWbBH8aRCr85GIWX4YIc829IUPy864oYd8tMXqepxP4MT24YxLW2hJ82H8T6ATy GNhTcmfP0EH3eHbnco+8yR8Sb1KfzQtnawJ3iOqayWL+Ky0rx1yGM4jijIRcaFHU07ip8l3t5E3 KweQ7qq65+sfeInmokMmPY0fIM4G6ZkudN7oG9NV8x79GBhrZvvaaHaJqWYQNhLgVuzZESu9g6R e/WPAAVust5wlxw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to test many hardware configuration, introduce a new interface to configure CRTCs and encoders. The CRTCs and encoders are created in their own directory. To link the CRTC, symlinks are used in the `possible_crtcs` folders. The current interface is: /config/vkms DEVICE_1 ┣━ enable ┣━ planes ┃ ┗━ PLANE_1 ┃ ┣━ type ┃ ┣━ supported_rotations ┃ ┣━ supported_color_encoding ┃ ┣━ supported_color_ranges ┃ ┣━ default_rotation ┃ ┣━ default_color_encoding ┃ ┣━ default_color_range ┃ ┗━ possible_crtcs ┃ ┗━ >> /config/vkms/DEVICE_1/crtcs/CRTC_1 ┣━ encoders ┃ ┗━ ENCODER_1 ┃ ┗━ possible_crtcs ┃ ┗━ >> /config/vkms/DEVICE_1/crtcs/CRTC_1 ┣━ crtcs ┃ ┗━ CRTC_1 DEVICE_2 ┗━ ditto Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 404 +++++++++++++++++++++++++++++++++-- drivers/gpu/drm/vkms/vkms_configfs.h | 54 ++++- 2 files changed, 437 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index aabc83283626..50628ec91b9a 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "vkms_configfs.h" #include "vkms_drv.h" @@ -394,6 +395,83 @@ static const struct config_item_type subgroup_plane = { .ct_item_ops = &plane_item_operations, .ct_owner = THIS_MODULE, }; +static const struct config_item_type crtc_item_type; +static const struct config_item_type planes_item_type; + +static int possible_crtcs_allow_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_configfs_device *vkms_configfs = plane_possible_crtc_src_item_to_vkms_configfs_device(src); + struct vkms_config_crtc *crtc; + + mutex_lock(&vkms_configfs->lock); + + if (target->ci_type != &crtc_item_type) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + + crtc = crtc_item_to_vkms_configfs_crtc(target)->vkms_config_crtc; + struct vkms_config_plane *plane = plane_possible_crtc_src_item_to_vkms_configfs_plane(src)->vkms_config_plane; + + struct vkms_config_crtc *crtc_entry; + unsigned long idx = 0; + + xa_for_each(&plane->possible_crtcs, idx, crtc_entry) { + if (crtc_entry == crtc) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + } + + if (vkms_config_plane_attach_crtc(plane, crtc)) + return -EINVAL; + + mutex_unlock(&vkms_configfs->lock); + + return 0; +} + +static void possible_crtcs_drop_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_config_crtc *crtc; + struct vkms_configfs_device *vkms_configfs = plane_possible_crtc_src_item_to_vkms_configfs_device(src); + + mutex_lock(&vkms_configfs->lock); + + crtc = crtc_item_to_vkms_configfs_crtc(target)->vkms_config_crtc; + struct vkms_config_plane *plane = plane_possible_crtc_src_item_to_vkms_configfs_plane(src)->vkms_config_plane; + + struct vkms_config_crtc *crtc_entry; + struct vkms_config_plane *plane_entry; + unsigned long crtc_idx = -1; + + xa_for_each(&plane->possible_crtcs, crtc_idx, crtc_entry) { + if (crtc_entry == crtc) + break; + } + unsigned long plane_idx = -1; + + xa_erase(&plane->possible_crtcs, crtc_idx); + xa_for_each(&crtc->possible_planes, plane_idx, plane_entry) { + if (plane_entry == plane) + break; + } + xa_erase(&crtc->possible_planes, plane_idx); + + mutex_unlock(&vkms_configfs->lock); +} + +static struct configfs_item_operations plane_possible_crtcs_item_ops = { + .allow_link = &possible_crtcs_allow_link, + .drop_link = &possible_crtcs_drop_link, +}; + +static struct config_item_type plane_possible_crtcs_group_type = { + .ct_item_ops = &plane_possible_crtcs_item_ops, + .ct_owner = THIS_MODULE, +}; static struct config_group *planes_make_group(struct config_group *config_group, const char *name) @@ -419,10 +497,7 @@ static struct config_group *planes_make_group(struct config_group *config_group, if (list_count_nodes(&vkms_configfs->vkms_config->planes) == 1) vkms_configfs_plane->vkms_config_plane->type = DRM_PLANE_TYPE_PRIMARY; - - if (!vkms_configfs_plane->vkms_config_plane || - vkms_config_plane_attach_crtc(vkms_configfs_plane->vkms_config_plane, - vkms_configfs->vkms_config_crtc)) { + if (!vkms_configfs_plane->vkms_config_plane) { kfree(vkms_configfs_plane); mutex_unlock(&vkms_configfs->lock); return ERR_PTR(-ENOMEM); @@ -439,7 +514,12 @@ static struct config_group *planes_make_group(struct config_group *config_group, config_group_init_type_name(&vkms_configfs_plane->group, name, &subgroup_plane); + config_group_init_type_name(&vkms_configfs_plane->possible_crtc_group, "possible_crtcs", + &plane_possible_crtcs_group_type); + configfs_add_default_group(&vkms_configfs_plane->possible_crtc_group, + &vkms_configfs_plane->group); vkms_configfs_plane->vkms_configfs_device = vkms_configfs; + mutex_unlock(&vkms_configfs->lock); return &vkms_configfs_plane->group; @@ -454,6 +534,287 @@ static const struct config_item_type planes_item_type = { .ct_owner = THIS_MODULE, }; +static void crtc_release(struct config_item *item) +{ + struct vkms_configfs_crtc *vkms_configfs_crtc = crtc_item_to_vkms_configfs_crtc(item); + + mutex_lock(&vkms_configfs_crtc->vkms_configfs_device->lock); + vkms_config_delete_crtc(vkms_configfs_crtc->vkms_config_crtc, + vkms_configfs_crtc->vkms_configfs_device->vkms_config); + mutex_unlock(&vkms_configfs_crtc->vkms_configfs_device->lock); + + kfree(vkms_configfs_crtc); +} + +static struct configfs_item_operations crtc_item_operations = { + .release = crtc_release, +}; + +static const struct config_item_type crtc_item_type = { + .ct_owner = THIS_MODULE, + .ct_item_ops = &crtc_item_operations, +}; + +static struct config_group *crtcs_make_group(struct config_group *config_group, + const char *name) +{ + struct config_item *root_item = config_group->cg_item.ci_parent; + struct vkms_configfs_device *vkms_configfs = config_item_to_vkms_configfs_device(root_item); + struct vkms_configfs_crtc *vkms_configfs_crtc; + + vkms_configfs_crtc = kzalloc(sizeof(*vkms_configfs_crtc), GFP_KERNEL); + + if (!vkms_configfs_crtc) + return ERR_PTR(-ENOMEM); + + mutex_lock(&vkms_configfs->lock); + vkms_configfs_crtc->vkms_configfs_device = vkms_configfs; + + if (vkms_configfs->enabled) { + kfree(vkms_configfs_crtc); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-EINVAL); + } + + vkms_configfs_crtc->vkms_config_crtc = vkms_config_create_crtc(vkms_configfs->vkms_config); + + if (!vkms_configfs_crtc->vkms_config_crtc) { + kfree(vkms_configfs_crtc); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-ENOMEM); + } + + vkms_configfs_crtc->vkms_config_crtc->name = kzalloc(strlen(name) + 1, GFP_KERNEL); + if (!vkms_configfs_crtc->vkms_config_crtc->name) { + kfree(vkms_configfs_crtc->vkms_config_crtc); + kfree(vkms_configfs_crtc); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-ENOMEM); + } + + vkms_configfs_crtc->vkms_configfs_device = vkms_configfs; + + strscpy(vkms_configfs_crtc->vkms_config_crtc->name, name, strlen(name) + 1); + config_group_init_type_name(&vkms_configfs_crtc->group, name, + &crtc_item_type); + + + mutex_unlock(&vkms_configfs->lock); + + return &vkms_configfs_crtc->group; +} + + +static struct configfs_group_operations crtcs_group_operations = { + .make_group = &crtcs_make_group, +}; + + +static const struct config_item_type crtcs_item_type = { + .ct_group_ops = &crtcs_group_operations, + .ct_owner = THIS_MODULE, +}; + +static int encoder_possible_crtcs_allow_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_config_crtc *crtc; + struct vkms_configfs_device *vkms_configfs = encoder_possible_crtc_src_item_to_vkms_configfs_device(src); + + mutex_lock(&vkms_configfs->lock); + + if (target->ci_type != &crtc_item_type) { + DRM_ERROR("Unable to link non-CRTCs.\n"); + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + + crtc = crtc_item_to_vkms_configfs_crtc(target)->vkms_config_crtc; + struct vkms_config_encoder *encoder = encoder_possible_crtc_src_item_to_vkms_configfs_encoder(src)->vkms_config_encoder; + + struct vkms_config_crtc *crtc_entry; + unsigned long idx = 0; + + xa_for_each(&encoder->possible_crtcs, idx, crtc_entry) { + if (crtc_entry == crtc) { + pr_err("Tried to add two symlinks to the same CRTC from the same object.\n"); + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + } + + if (vkms_config_encoder_attach_crtc(encoder, crtc)) + return -EINVAL; + + mutex_unlock(&vkms_configfs->lock); + + return 0; +} + +static void encoder_possible_crtcs_drop_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_config_crtc *crtc; + struct vkms_configfs_device *vkms_configfs = encoder_possible_crtc_src_item_to_vkms_configfs_device(src); + + mutex_lock(&vkms_configfs->lock); + + crtc = crtc_item_to_vkms_configfs_crtc(target)->vkms_config_crtc; + struct vkms_config_encoder *encoder = encoder_possible_crtc_src_item_to_vkms_configfs_encoder(src)->vkms_config_encoder; + + struct vkms_config_encoder *encoder_entry; + struct vkms_config_crtc *crtc_entry; + unsigned long encoder_idx = -1; + unsigned long crtc_idx = -1; + + xa_for_each(&encoder->possible_crtcs, crtc_idx, crtc_entry) { + if (crtc_entry == crtc) + break; + } + xa_erase(&encoder->possible_crtcs, crtc_idx); + xa_for_each(&crtc->possible_encoders, encoder_idx, encoder_entry) { + if (encoder_entry == encoder) + break; + } + xa_erase(&crtc->possible_encoders, encoder_idx); + + mutex_unlock(&vkms_configfs->lock); +} + +static struct configfs_item_operations encoder_possible_crtcs_item_operations = { + .allow_link = &encoder_possible_crtcs_allow_link, + .drop_link = &encoder_possible_crtcs_drop_link, +}; + +static struct config_item_type encoder_possible_crtcs_item_type = { + .ct_item_ops = &encoder_possible_crtcs_item_operations, + .ct_owner = THIS_MODULE, +}; + +static void encoder_release(struct config_item *item) +{ + struct vkms_configfs_encoder *vkms_configfs_encoder = encoder_item_to_vkms_configfs_encoder(item); + + mutex_lock(&vkms_configfs_encoder->vkms_configfs_device->lock); + vkms_config_delete_encoder(vkms_configfs_encoder->vkms_config_encoder, vkms_configfs_encoder->vkms_configfs_device->vkms_config); + mutex_unlock(&vkms_configfs_encoder->vkms_configfs_device->lock); + + kfree(vkms_configfs_encoder); +} + +static struct configfs_item_operations encoder_item_operations = { + .release = encoder_release, +}; + +static const struct config_item_type encoder_item_type = { + .ct_item_ops = &encoder_item_operations, + .ct_owner = THIS_MODULE, +}; + +static struct config_group *encoder_make_group(struct config_group *config_group, + const char *name) +{ + struct vkms_configfs_device *vkms_configfs = encoder_item_to_vkms_configfs_device(&config_group->cg_item); + struct vkms_configfs_encoder *vkms_configfs_encoder; + + vkms_configfs_encoder = kzalloc(sizeof(*vkms_configfs_encoder), GFP_KERNEL); + + if (!vkms_configfs_encoder) + return ERR_PTR(-ENOMEM); + + mutex_lock(&vkms_configfs->lock); + + if (vkms_configfs->enabled) { + kfree(vkms_configfs_encoder); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-EINVAL); + } + + vkms_configfs_encoder->vkms_config_encoder = vkms_config_create_encoder( + vkms_configfs->vkms_config); + + if (!vkms_configfs_encoder->vkms_config_encoder) { + kfree(vkms_configfs_encoder); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-ENOMEM); + } + + vkms_configfs_encoder->vkms_config_encoder->name = kzalloc(strlen(name) + 1, GFP_KERNEL); + if (!vkms_configfs_encoder->vkms_config_encoder->name) { + kfree(vkms_configfs_encoder->vkms_config_encoder); + kfree(vkms_configfs_encoder); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-ENOMEM); + } + + strscpy(vkms_configfs_encoder->vkms_config_encoder->name, name, strlen(name) + 1); + config_group_init_type_name(&vkms_configfs_encoder->group, name, + &encoder_item_type); + + config_group_init_type_name(&vkms_configfs_encoder->possible_crtc_group, "possible_crtcs", + &encoder_possible_crtcs_item_type); + configfs_add_default_group(&vkms_configfs_encoder->possible_crtc_group, + &vkms_configfs_encoder->group); + vkms_configfs_encoder->vkms_configfs_device = vkms_configfs; + + mutex_unlock(&vkms_configfs->lock); + + return &vkms_configfs_encoder->group; +} + +static struct configfs_group_operations encoder_group_operations = { + .make_group = &encoder_make_group, +}; + +static const struct config_item_type encoders_item_type = { + .ct_group_ops = &encoder_group_operations, + .ct_owner = THIS_MODULE, +}; + +/** + * configfs_lock_dependencies() - In order to forbid the userspace to delete items when the + * device is enabled, mark all configfs items as dependent + * + * @vkms_configfs_device - Device to lock + */ +static void configfs_lock_dependencies(struct vkms_configfs_device *vkms_configfs_device) +{ + /* Lock the group itself */ + configfs_depend_item_unlocked(vkms_configfs_device->group.cg_subsys, + &vkms_configfs_device->group.cg_item); + /* Lock the planes elements */ + struct config_item *item; + + list_for_each_entry(item, &vkms_configfs_device->plane_group.cg_children, ci_entry) { + configfs_depend_item_unlocked(vkms_configfs_device->plane_group.cg_subsys, + item); + } + list_for_each_entry(item, &vkms_configfs_device->crtc_group.cg_children, ci_entry) { + configfs_depend_item_unlocked(vkms_configfs_device->crtc_group.cg_subsys, + item); + } +} + +/** + * configfs_unlock_dependencies() - Once the device is disable, its configuration can be modified. + * + * @vkms_configfs_device - Device to unlock + */ +static void configfs_unlock_dependencies(struct vkms_configfs_device *vkms_configfs_device) +{ + struct config_item *item; + + configfs_undepend_item_unlocked(&vkms_configfs_device->group.cg_item); + + list_for_each_entry(item, &vkms_configfs_device->plane_group.cg_children, ci_entry) { + configfs_undepend_item_unlocked(item); + } + list_for_each_entry(item, &vkms_configfs_device->crtc_group.cg_children, ci_entry) { + configfs_undepend_item_unlocked(item); + } +} + + static ssize_t device_enable_show(struct config_item *item, char *page) { return sprintf(page, "%d\n", @@ -474,13 +835,25 @@ static ssize_t device_enable_store(struct config_item *item, return -EINVAL; mutex_lock(&vkms_configfs_device->lock); + if (vkms_configfs_device->enabled == value) { + mutex_unlock(&vkms_configfs_device->lock); + return (ssize_t) count; + } + + if (value && !vkms_config_is_valid(vkms_configfs_device->vkms_config)) { + mutex_unlock(&vkms_configfs_device->lock); + return -EINVAL; + } vkms_configfs_device->enabled = value; - if (value) + if (value) { + configfs_lock_dependencies(vkms_configfs_device); vkms_create(vkms_configfs_device->vkms_config); - else + } else { + configfs_unlock_dependencies(vkms_configfs_device); vkms_destroy(vkms_configfs_device->vkms_config); + } mutex_unlock(&vkms_configfs_device->lock); @@ -519,9 +892,6 @@ static const struct config_item_type device_item_type = { static struct config_group *root_make_group(struct config_group *group, const char *name) { - struct vkms_config_plane *plane; - struct vkms_config_crtc *crtc; - struct vkms_config_encoder *encoder; struct vkms_configfs_device *configfs = kzalloc(sizeof(*configfs), GFP_KERNEL); if (!configfs) @@ -536,22 +906,18 @@ static struct config_group *root_make_group(struct config_group *group, return ERR_PTR(-ENOMEM); } - configfs->vkms_config_crtc = vkms_config_create_crtc(configfs->vkms_config); - configfs->vkms_config_encoder = vkms_config_create_encoder(configfs->vkms_config); - if (!configfs->vkms_config_crtc || !configfs->vkms_config_encoder || - vkms_config_encoder_attach_crtc(configfs->vkms_config_encoder, - configfs->vkms_config_crtc)) { - vkms_config_destroy(configfs->vkms_config); - kfree(configfs); - return ERR_PTR(-ENOMEM); - } - config_group_init_type_name(&configfs->group, name, &device_item_type); config_group_init_type_name(&configfs->plane_group, "planes", &planes_item_type); configfs_add_default_group(&configfs->plane_group, &configfs->group); + config_group_init_type_name(&configfs->crtc_group, "crtcs", &crtcs_item_type); + configfs_add_default_group(&configfs->crtc_group, &configfs->group); + + config_group_init_type_name(&configfs->encoder_group, "encoders", &encoders_item_type); + configfs_add_default_group(&configfs->encoder_group, &configfs->group); + return &configfs->group; } diff --git a/drivers/gpu/drm/vkms/vkms_configfs.h b/drivers/gpu/drm/vkms/vkms_configfs.h index 6dc4d34a9e44..df743e0107f4 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.h +++ b/drivers/gpu/drm/vkms/vkms_configfs.h @@ -20,34 +20,84 @@ struct vkms_configfs_device { struct config_group group; struct config_group plane_group; + struct config_group crtc_group; + struct config_group encoder_group; struct mutex lock; bool enabled; struct vkms_config *vkms_config; - struct vkms_config_crtc *vkms_config_crtc; - struct vkms_config_encoder *vkms_config_encoder; }; struct vkms_configfs_plane { struct config_group group; + struct config_group possible_crtc_group; struct vkms_configfs_device *vkms_configfs_device; struct vkms_config_plane *vkms_config_plane; }; +struct vkms_configfs_crtc { + struct config_group group; + + struct vkms_configfs_device *vkms_configfs_device; + struct vkms_config_crtc *vkms_config_crtc; +}; + +struct vkms_configfs_encoder { + /* must be first because it is a krefcounted stuff */ + struct config_group group; + + struct config_group possible_crtc_group; + struct vkms_configfs_device *vkms_configfs_device; + struct vkms_config_encoder *vkms_config_encoder; +}; + #define config_item_to_vkms_configfs_device(item) \ container_of(to_config_group((item)), struct vkms_configfs_device, group) #define planes_item_to_vkms_configfs_device(item) \ config_item_to_vkms_configfs_device((item)->ci_parent) +#define encoders_item_to_vkms_configfs_device(item) \ + config_item_to_vkms_configfs_device((item)->ci_parent) + +#define crtc_item_to_vkms_configfs_crtc(item) \ + container_of(to_config_group((item)), struct vkms_configfs_crtc, group) + +#define encoder_item_to_vkms_configfs_encoder(item) \ + container_of(to_config_group((item)), struct vkms_configfs_encoder, group) + #define plane_item_to_vkms_configfs_device(item) \ planes_item_to_vkms_configfs_device((item)->ci_parent) #define plane_item_to_vkms_configfs_plane(item) \ container_of(to_config_group((item)), struct vkms_configfs_plane, group) +#define plane_possible_crtc_src_item_to_vkms_configfs_device(item) \ + plane_item_to_vkms_configfs_device((item)->ci_parent) + +#define plane_possible_crtc_src_item_to_vkms_configfs_plane(item) \ + plane_item_to_vkms_configfs_plane((item)->ci_parent) + +#define crtc_item_to_vkms_configfs_device(item) \ + config_item_to_vkms_configfs_device((item)->ci_parent) + +#define crtc_child_item_to_vkms_configfs_device(item) \ + crtc_item_to_vkms_configfs_device((item)->ci_parent) + +#define encoder_item_to_vkms_configfs_device(item) \ + config_item_to_vkms_configfs_device((item)->ci_parent) + +#define encoder_child_item_to_vkms_configfs_device(item) \ + encoder_item_to_vkms_configfs_device((item)->ci_parent) + +#define encoder_possible_crtc_src_item_to_vkms_configfs_device(item) \ + encoder_child_item_to_vkms_configfs_device((item)->ci_parent) + +#define encoder_possible_crtc_src_item_to_vkms_configfs_encoder(item) \ + encoder_item_to_vkms_configfs_encoder((item)->ci_parent) + /* ConfigFS Support */ int vkms_init_configfs(void); void vkms_unregister_configfs(void);