From patchwork Tue Jan 21 10:55:25 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946161 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 C9BF6C02182 for ; Tue, 21 Jan 2025 10:55:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 48C1410E560; Tue, 21 Jan 2025 10:55:40 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="NHQJxeRV"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::222]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7B20C10E560 for ; Tue, 21 Jan 2025 10:55:37 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 31C6040007; Tue, 21 Jan 2025 10:55:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456935; 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=iMm1JXHZ3IwcVSCGDPx/XjO13zJJ9xnGIZllfHmkiI4=; b=NHQJxeRVdeAdw2pFDUzwZzA/7Ic9eZZJ/3x/Jp/mn9+II0mjgEnknqOGaMuHRDp3es1fY5 yk2GoHMSpXA47qL5baQxr3PeIua6+6nUpn1jplUoZamPq8tBHZHvdsU52OUd/KdsZJq4oc sUFrKiBNykNYxcSbUdS+IVf76HHEDkj4iXyvEuIkKcqM4N25CtNPX1uQtfkGX3k7wU+oDg gTGyXis5a9+c4wEWqkiO6P7eJagyZF4fW+RQj5jqF7C1RE5J+whvwBR47WjR9C2MYibCOt g9y8vKeQo18X1FELbKGxRYfdvrfzPM6sbf9y6dEET9LAnnuFJaC2k0/AwH0Rcw== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:25 +0100 Subject: [PATCH v3 01/16] drm/vkms: Extract vkms_config header MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-1-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet , =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=8128; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=gsiygt2fQ2wFhE4Zgg0i+3O3oWlk+bFZUumT4XOlZdU=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30g6NBG9iIYnfgkAqQcgl2ahLsblntO0kYLg uADuzIq/ImJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499IAAKCRAgrS7GWxAs 4vIjEADWTC/tkJ09rL1yhXV4EtBcUc1C7MisH33176VJijVlQvUrjpZRP9p1c36hE1r7+T8VrdW 5tzXG5sTrl5e2WvYKYPEd1WVUS8Osy2JioVBKO6ARpPQ7cvlw9hEIsRLBuD0C03buoPwAHwSn2d hUUUc4qAaFoJ34Fbzv5nfKdu026fzvhJDFw3HZPkhybba64JUQ+N8cUPdWDQkhG3azusTLhKTdR TEbrpU2jcFBkAkxpQybuMEPaD+xvfOKi/usAHcg/6z2DeSdLlV6eDyAMmXAcezdtFeCyJ6W5u/e 5rlIje062Sl4tNTgRTHcGTUQVeCSPKCb78yaOE2qD+9xnLggu6wcDc8+VvOXmLSGRImVmkvOmt6 k4jtnacc/cY8BuUCsrQIGjOAmrleIw8jI34OZgiyBJAqv9UjOiWhCAEqlg6iuWlPkh14mYjVwQc zQQic5LhloXOdL8u/DSzj3rWii7niM06gTQOwMDoKKCKCR9trs5mY3PXykLtTsoMuYd+NurXzo/ +t7jNj3MjwPzxOubtzpi4WuCeAlQ80FH6wrg1/cbEskA7/RDxM+ykude4vgzgozV5aXEmgyTop6 5HL5ZeFqx6kQrwVLIE3TB34VjEOYm3e6xNmFy/54b1rBJ4QRakM9JmgZSWDodTxYuNVxdhQ7XVI OvZlmuesN5Ap0aA== 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" Creating 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. Signed-off-by: Louis Chauvet [Changes: Cherry picked and conflict solve] Signed-off-by: José Expósito --- drivers/gpu/drm/vkms/Makefile | 3 ++- drivers/gpu/drm/vkms/vkms_config.c | 48 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 32 +++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_drv.c | 41 +++++++++----------------------- drivers/gpu/drm/vkms/vkms_drv.h | 15 +----------- drivers/gpu/drm/vkms/vkms_output.c | 1 + 6 files changed, 95 insertions(+), 45 deletions(-) diff --git a/drivers/gpu/drm/vkms/Makefile b/drivers/gpu/drm/vkms/Makefile index 1b28a6a32948b557867dda51d2ccfdea687a2b62..b371b5d70ee31e76343c2f09e6dc5a6e74a1c246 100644 --- a/drivers/gpu/drm/vkms/Makefile +++ b/drivers/gpu/drm/vkms/Makefile @@ -6,6 +6,7 @@ vkms-y := \ vkms_formats.o \ vkms_crtc.o \ vkms_composer.o \ - vkms_writeback.o + vkms_writeback.o \ + vkms_config.o obj-$(CONFIG_DRM_VKMS) += vkms.o diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c new file mode 100644 index 0000000000000000000000000000000000000000..76355174a6ca54b880218c2bd458c8339a3dabaa --- /dev/null +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -0,0 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include + +#include "vkms_config.h" +#include "vkms_drv.h" + +struct vkms_config *vkms_config_create(void) +{ + struct vkms_config *config; + + config = kzalloc(sizeof(*config), GFP_KERNEL); + if (!config) + return ERR_PTR(-ENOMEM); + + 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) +{ + 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 }, +}; + +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)); +} diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h new file mode 100644 index 0000000000000000000000000000000000000000..b284831738743f6d7c452be03f917a7d3975d173 --- /dev/null +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#ifndef _VKMS_CONFIG_H +#define _VKMS_CONFIG_H + +#include +#include "vkms_drv.h" + +/** + * 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 instancied. + */ +struct vkms_config { + bool writeback; + bool cursor; + bool overlay; + struct vkms_device *dev; +}; + +/** + * vkms_config_register_debugfs() - Register the debugfs file to display current configuration + */ +void vkms_config_register_debugfs(struct vkms_device *vkms_device); + +struct vkms_config *vkms_config_create(void); +void vkms_config_destroy(struct vkms_config *config); + +#endif //_VKMS_CONFIG_H diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 7c142bfc3bd9de9556621db3e7f570dc0a4fab3a..6b0e5fd0e26f04359b0d10252496c52b15d83896 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -28,6 +28,7 @@ #include #include "vkms_drv.h" +#include "vkms_config.h" #include #include @@ -81,22 +82,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, @@ -208,8 +193,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) @@ -229,21 +213,18 @@ static int vkms_create(struct vkms_config *config) static int __init vkms_init(void) { int ret; - struct vkms_config *config; - - config = kmalloc(sizeof(*config), GFP_KERNEL); - if (!config) - return -ENOMEM; - default_config = config; + default_config = vkms_config_create(); + if (IS_ERR(default_config)) + return PTR_ERR(default_config); - config->cursor = enable_cursor; - config->writeback = enable_writeback; - config->overlay = enable_overlay; + default_config->cursor = enable_cursor; + default_config->writeback = enable_writeback; + default_config->overlay = enable_overlay; - ret = vkms_create(config); + ret = vkms_create(default_config); if (ret) - kfree(config); + vkms_config_destroy(default_config); return ret; } @@ -272,7 +253,7 @@ static void __exit vkms_exit(void) if (default_config->dev) vkms_destroy(default_config); - kfree(default_config); + vkms_config_destroy(default_config); } module_init(vkms_init); diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index abbb652be2b5389f96cec78837117ceb9acef656..af7081c940d6c074dc01cf8180556a3d902e386d 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -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 diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index 22f0d678af3ac8177e43c4ea730af3f2109de5f3..78e389d832c16e4dbaccda34fbf3215f34adeadf 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ #include "vkms_drv.h" +#include "vkms_config.h" #include #include #include From patchwork Tue Jan 21 10:55:26 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946164 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 1959FC02182 for ; Tue, 21 Jan 2025 10:55:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6EF8910E564; Tue, 21 Jan 2025 10:55:45 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="CvHhwFQ8"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::222]) by gabe.freedesktop.org (Postfix) with ESMTPS id 09D0910E560 for ; Tue, 21 Jan 2025 10:55:37 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 06E6940004; Tue, 21 Jan 2025 10:55:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456936; 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=W86h+/A1r0cJ9xJo5orIgxe7yVfofGkp//jbkB7pOdY=; b=CvHhwFQ8IhKkuH54OCA0UmIPkSv0YmixipS8YZkLX6+bBqKsDiWkZc7hmyPZ04NiPFRxEm IdFDPfBOI/3dFAhUbkdwvmKDCTxhmZlmQVW5atdyClRSJpGdkJqpUcRwLY+o/48obBIDcY WrjP838DRYLMafn0sLxhcyc6TOGv4E79T8Lp/tV6YKTbwiAG0cXM+4P9dcE3vr6/rx1AZz WTSJGzQtDjgy0xTtoXQ7ap2veWs2sdsD9XqNDxlbBxNOcsivh/gOLYq6JvskehZ+ZVcVn/ p9T+3qroB9ChspkoySoGTxhv+v0BL2lWyRH3IkKbBK9pw+xetvM8YXwdM0ZVng== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:26 +0100 Subject: [PATCH v3 02/16] drm/vkms: Add a validation function for vkms configuration MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-2-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1917; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=GzP6lw0znHG7/h4ORxGII88qWMwWVl3of4Ml1+pfkbs=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30gBsz2xuZl79HQIoPEKNngLva+g6jikqMvA waCE0ZohGuJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499IAAKCRAgrS7GWxAs 4iJUEACMgQy2eaWZOPpfAXofkQ+sj1bIW1juq2Vj4XfLOLcCFuUEi1zc5P9agQ4BYSj6OpWH4Tz xrQpHcYE1u2IjslnZ8Zx1FLCDq975N84sw3CYh/b37trNfzZg6m36uIuuQQkSxTJUmqxkKbHQ2M rpkww5vZmIFx8VtOwifbSjJ0cYB4nSEcE0PYlail/jjzJ7uB39iEFWaY8AGsXvtEsCJtswQZQjI cw3Mytd0edh2pWtStu/xLuvorhHjkQrA8SQbNHEuOgfH+S94CnR8d0ApvXSUotWCwKhPduo6j1w V7vKLlUbEcOusPhLvUXGq+WJU+g6EOnbHLHaG1Jncti7yxnRLrdz3uMFSc8OQIQ+/vrmiyheSvB cOiatRwGotkTXnB9TzNQoMLq6v59XKrgjZSDH8aP1r/SFgMdHlNYARVzBxcpn8YYxHTSE16vRYI IpTTnSCKlY2sjTmfnNRXMryaIXxrpokOavQ5FmQsPiuTUB95oJ06cpMB3uO3Ar8aA9e3kKb+Q6C P8lXPPtadhH0EPGEXRKhW4mCAgjRxX9fQKU+0xlEzj4c7LDC7Dh0KCAkr4XXsel52swnXsVdMDa fFRaFx5RnMi4UPXaNBcgNAn6lClXQWpFFt+R6aBR+QrRjGlzVxKvaSJ8VHI5AGfA7GDOY2I4yDV myQ6mZb40buluVw== 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" As the configuration will be used by userspace, add a validator to avoid creating a broken DRM device Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 6 ++++++ drivers/gpu/drm/vkms/vkms_config.h | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index 76355174a6ca54b880218c2bd458c8339a3dabaa..8d5c1429e6e196ef46c95c6ae73330bc4be2be39 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -24,6 +24,12 @@ void vkms_config_destroy(struct vkms_config *config) } EXPORT_SYMBOL_IF_KUNIT(vkms_config_destroy); +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) { struct drm_debugfs_entry *entry = m->private; diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index b284831738743f6d7c452be03f917a7d3975d173..df571dd67352ca90fb47bd937fb9f11ceb95fcb2 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -29,4 +29,17 @@ void vkms_config_register_debugfs(struct vkms_device *vkms_device); struct vkms_config *vkms_config_create(void); void vkms_config_destroy(struct vkms_config *config); +/** + * vkms_config_is_valid() - Validate a configuration + * + * Check if all the property defined in the configuration are valids. This will return false for + * example if: + * - no or many primary planes are present; + * - the default rotation of a plane is not in its supported rotation; + * - a CRTC don't have any encoder... + * + * @vkms_config: Configuration to validate + */ +bool vkms_config_is_valid(struct vkms_config *vkms_config); + #endif //_VKMS_CONFIG_H From patchwork Tue Jan 21 10:55:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946162 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 79846C0218B for ; Tue, 21 Jan 2025 10:55:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E1D7110E567; Tue, 21 Jan 2025 10:55:40 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="P/jaPthX"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id D118710E560 for ; Tue, 21 Jan 2025 10:55:38 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id D1FDE4000F; Tue, 21 Jan 2025 10:55:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456937; 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=QY2VyBBaFCg4V5NH0VvIOmrVaSzP7xHEB7taYLc6l2Q=; b=P/jaPthX4Z6bejPohEQwyPKNN5XTEEMxoMZJOhLTEAFjltQHukTJzNrLjjr9J4N3yUSaD6 cNj2K+L/OCSGR2y/1E84I8FD5H7k5ae/xaQg5Sb/Zn/ACe0mRZFyXU1riFg584EojWVTTa uwiBqwkd7DMlKT6S846HIFU9ERgo5RhqDS+0UGy/gtCmXRQ6El5LT2sul5v3X5meKScRNh aZBhoy7oRDQDXSwisft64Wrqk9MjsBHfy184yvftLQOjnxxNFPOOwdun28X8SeyvPI4/zs udRqI7lh9MJ6aU9EJVWSVVkh0nnsAx6CoDMoEvK64u2J9H4NhWm/bMiSiXjndg== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:27 +0100 Subject: [PATCH v3 03/16] drm/vkms: Move default_config creation to its own function MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-3-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet , =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3031; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=EY/waz6vmQDdmJlBI0i2XUrbsOqJqUD3UKiquIiszZQ=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30grWnw6mZQ800QBx7yDI03LVzU2Yvvpx2MT CP4U9NOt9OJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499IAAKCRAgrS7GWxAs 4pweEACcSgc7mKwr/I4I2tjewKg7N1ABhjz8kTK0koX4vkBTX/3pKd7uu0wMRiPiEJyoRmbJlEO SuQATAVzGCrz93paugDDZK0g3sJYc0MOBwBdDeT9mKBaLzoDbbTwB1nbObthMfo1s+AF97ytoaM UY3RoG2NNuPH4XpiLfdp+/HWePJez507abkCBnf6JRjmvmQroZ2uIffIoJmTDjphhdipS2zTfAi zWKxb9s1AT5x58Iuro9PArLEPnFoK3K5SmM8WZw7m9AQ8KWPvyhzhOy3v5fi6TFBltiUJazZUpm JOac8EgBPjgQfqTDnRTT2FBExpuNt88JomGICEbo8pIuv5o26TVRxtzQjqSKBive3AwWtAe/R8r W4xBupjrfpOmInXZC55B12yr3r9ADhgKcruC5yhxOVpjacBxRLxcx29iVKpKVsqEgYw08XDTukd L1R2s5tPaCs4r1qDBrWoN1F7GKBoNaNTsmfVhKjRJ8w9Ee0Io2+q/e2PXv3bETJD6Q7OHQubRPR tlNpLx8CDX9uXPMsV+L7M6Vp761kozCIqJm2+EESoS9dC6MITkDBLyv8+fDCcDF0AXfBKfqc/m3 DXPjtY6thcXFYYMxR7sD4pGnzOCKuq9NuAaubHElVRITesdqsefN4qm2g3QyoSNRLDuOW+LsAJT wM1stNVj3FhM10g== 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" Extract the initialization of the default configuration to a function. Refactor, no functional changes. Signed-off-by: Louis Chauvet [Changes: Cherry pick and solve conflicts] Signed-off-by: José Expósito --- drivers/gpu/drm/vkms/vkms_config.c | 15 +++++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 9 +++++++++ drivers/gpu/drm/vkms/vkms_drv.c | 7 +------ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index 8d5c1429e6e196ef46c95c6ae73330bc4be2be39..e7c7f46303e8ce4c9de68878668b855ac0fc5d2e 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -18,6 +18,21 @@ struct vkms_config *vkms_config_create(void) } EXPORT_SYMBOL_IF_KUNIT(vkms_config_create); +struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable_overlay, + bool enable_cursor) +{ + struct vkms_config *vkms_config = vkms_config_create(); + + if (IS_ERR(vkms_config)) + return vkms_config; + + vkms_config->writeback = enable_writeback; + vkms_config->overlay = enable_overlay; + vkms_config->cursor = enable_cursor; + + return vkms_config; +} + void vkms_config_destroy(struct vkms_config *config) { kfree(config); diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index df571dd67352ca90fb47bd937fb9f11ceb95fcb2..2afb795586c6924a46dd4ba777bf22a4f51cddda 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -42,4 +42,13 @@ void vkms_config_destroy(struct vkms_config *config); */ bool vkms_config_is_valid(struct vkms_config *vkms_config); +/** + * vkms_config_alloc_default() - Allocate the configuration for the default device + * @enable_writeback: Enable the writeback connector for this configuration + * @enable_overlay: Create some overlay planes + * @enable_cursor: Create a cursor plane + */ +struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable_overlay, + bool enable_cursor); + #endif //_VKMS_CONFIG_H diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 6b0e5fd0e26f04359b0d10252496c52b15d83896..4440549c3084a341d03ec66119ba7998012bd662 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -213,15 +213,10 @@ static int vkms_create(struct vkms_config *config) static int __init vkms_init(void) { int ret; - - default_config = vkms_config_create(); + default_config = vkms_config_alloc_default(enable_writeback, enable_overlay, enable_cursor); if (IS_ERR(default_config)) return PTR_ERR(default_config); - default_config->cursor = enable_cursor; - default_config->writeback = enable_writeback; - default_config->overlay = enable_overlay; - ret = vkms_create(default_config); if (ret) vkms_config_destroy(default_config); From patchwork Tue Jan 21 10:55:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946163 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 EF20FC0218B for ; Tue, 21 Jan 2025 10:55:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6C91510E562; Tue, 21 Jan 2025 10:55:44 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="GxZwv7SR"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::222]) by gabe.freedesktop.org (Postfix) with ESMTPS id ADC2810E560 for ; Tue, 21 Jan 2025 10:55:39 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id B7CD54000B; Tue, 21 Jan 2025 10:55:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456938; 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=EZ4+dULwJeZLEDWGar2fFPRnYCtGxTs/GQ44jM9HSvo=; b=GxZwv7SRqMSlSIBidrGEocrNihB8C4kI706FuM/CdIM5z3611VCKNpxo823q3JPE+26jCP qD4pbQTJxL9fY2IZzjyTp2wU16IBMbeUaROHSJ84HFqPGBrEmV9+x/zUOvBAMQxIzgDUA5 SDJQvL4TfAeZtszNG8Y5zhsJ+vMxcluibp4a5nypkytSJtgjPG/g2NCfjp1RTfWDr2UExL BsTs7HSnL6XbYxQywV36S2Pyqvyrp4QYZNEMlXTutDWbRnGMcUQ8GKu+O0GK04ciuwhrtV VEeuG/rjhVIV5JevoETrPUROarkE7zaQ6pmXeuaP3HhtPlkLE8fqp0kEwP9kzQ== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:28 +0100 Subject: [PATCH v3 04/16] drm/vkms: Introduce config for plane MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-4-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=11421; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=EkmyO2LSexOkTJzOOyicuZnPgcN7tBbD7ESxmkXrUAk=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30hAYAZBrKZVxfxqvE8/lqtyPJZy0eqpQ0Pa r2pggxNh/iJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499IQAKCRAgrS7GWxAs 4kQ6D/9LuRl2K7ZAxkclQV2nJOhZC3bg7/SVcHEXPMUceIerO9ksRyrYOHgZMc4AQavNMPZoxvr +nVDeorKPnvaPWzBOSLxB5v9RGcY/JAqqYJJGS1S9+tpa83yxhE7bZSkAGNBvoOBxBO/UM10V3O DpCAxnvFxxITPBdLXpA6fAQ6GGMdjRaFItIC/vnc/oRsIkybnggx2h3hUELVfORO0L/ywraZogS XnFVhwqqf1ZY0midG8nsdeYvADVozyiHhFZe4WB3tXfHR/RAHTxvxwWiDbRTOAF+XkPtyQb01MY EDxRWLFf5H/KqXSsna8itVQ+54wk+aMYWFeDwyRkR81e4gzvRJNkfKuDPlDJ62qwrM5C8rE0YXq c8d9l7+ymxLi9VRX8N38AYeAOYE4nZRCnFX0kvbwvsEchqNyc0ZH/hkAafVROI0BEcAVFXLBZpR 9Szh1ldEzdC0tKbKqUOAUdp1n0zRTEYO3GC6gvbZaPXxq7MIyCk26HeLIBcILjGLItc9dYRipM3 ggsLsPa00eBEzLJSe3mdrxTBppHp8a/YumwXgn79lNYHIrbM49jVz5G9wo9B21ghaqB4qpMNbl6 60a8WZdKGXKp0/rgH/g7tel7UV11rFJoWJKwnE7+mNC0FDTQ0m8PWdbqSujosLzKssgCqxi5fBf vil4LzCe6X2YP+A== 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" The current vkms driver only allows the usage of one primary, eight overlays and one cursor plane. This new configuration structure aims to make the configuration more flexible. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 92 ++++++++++++++++++++++++++++++++++++-- drivers/gpu/drm/vkms/vkms_config.h | 43 +++++++++++++++++- drivers/gpu/drm/vkms/vkms_drv.h | 3 +- drivers/gpu/drm/vkms/vkms_output.c | 37 +++++---------- drivers/gpu/drm/vkms/vkms_plane.c | 5 ++- 5 files changed, 145 insertions(+), 35 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index e7c7f46303e8ce4c9de68878668b855ac0fc5d2e..495056ce988ab32738701f00c94c709457aefbd3 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -14,6 +14,8 @@ struct vkms_config *vkms_config_create(void) if (!config) return ERR_PTR(-ENOMEM); + INIT_LIST_HEAD(&config->planes); + return config; } EXPORT_SYMBOL_IF_KUNIT(vkms_config_create); @@ -21,26 +23,105 @@ EXPORT_SYMBOL_IF_KUNIT(vkms_config_create); struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable_overlay, bool enable_cursor) { + struct vkms_config_plane *plane; struct vkms_config *vkms_config = vkms_config_create(); if (IS_ERR(vkms_config)) return vkms_config; vkms_config->writeback = enable_writeback; - vkms_config->overlay = enable_overlay; - vkms_config->cursor = enable_cursor; + plane = vkms_config_create_plane(vkms_config); + if (!plane) + goto err_alloc; + + plane->type = DRM_PLANE_TYPE_PRIMARY; + + if (enable_overlay) { + for (int i = 0; i < NUM_OVERLAY_PLANES; i++) { + plane = vkms_config_create_plane(vkms_config); + if (!plane) + goto err_alloc; + plane->type = DRM_PLANE_TYPE_OVERLAY; + } + } + if (enable_cursor) { + plane = vkms_config_create_plane(vkms_config); + if (!plane) + goto err_alloc; + plane->type = DRM_PLANE_TYPE_CURSOR; + } return vkms_config; + +err_alloc: + vkms_config_destroy(vkms_config); + return ERR_PTR(-ENOMEM); +} + +struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *vkms_config) +{ + if (!vkms_config) + return NULL; + + struct vkms_config_plane *vkms_config_overlay = kzalloc(sizeof(*vkms_config_overlay), + GFP_KERNEL); + + if (!vkms_config_overlay) + return NULL; + + vkms_config_overlay->type = DRM_PLANE_TYPE_OVERLAY; + + list_add(&vkms_config_overlay->link, &vkms_config->planes); + + return vkms_config_overlay; +} +EXPORT_SYMBOL_IF_KUNIT(vkms_config_create_plane); + +void vkms_config_delete_plane(struct vkms_config_plane *vkms_config_overlay) +{ + if (!vkms_config_overlay) + return; + list_del(&vkms_config_overlay->link); + kfree(vkms_config_overlay); } void vkms_config_destroy(struct vkms_config *config) { + struct vkms_config_plane *vkms_config_plane, *tmp_plane; + + list_for_each_entry_safe(vkms_config_plane, tmp_plane, &config->planes, link) { + vkms_config_delete_plane(vkms_config_plane); + } + kfree(config); } EXPORT_SYMBOL_IF_KUNIT(vkms_config_destroy); bool vkms_config_is_valid(struct vkms_config *config) { + struct vkms_config_plane *config_plane; + + bool has_cursor = false; + bool has_primary = false; + + list_for_each_entry(config_plane, &config->planes, link) { + if (config_plane->type == DRM_PLANE_TYPE_PRIMARY) { + // Multiple primary planes for only one CRTC + if (has_primary) + return false; + has_primary = true; + } + if (config_plane->type == DRM_PLANE_TYPE_CURSOR) { + // Multiple cursor planes for only one CRTC + if (has_cursor) + return false; + has_cursor = true; + } + } + + if (!has_primary) + return false; + return true; } EXPORT_SYMBOL_IF_KUNIT(vkms_config_is_valid); @@ -50,10 +131,13 @@ 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); + struct vkms_config_plane *config_plane; 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); + list_for_each_entry(config_plane, &vkmsdev->config->planes, link) { + seq_puts(m, "plane:\n"); + seq_printf(m, "\ttype: %d\n", config_plane->type); + } return 0; } diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index 2afb795586c6924a46dd4ba777bf22a4f51cddda..ac99f1df6d9a17bd7040a1e7a6acce14cd8fd9d0 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -10,8 +10,8 @@ * 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 + * @planes: List of planes configured for this device. They are created by the function + * vkms_config_create_plane(). * @dev: Used to store the current vkms device. Only set when the device is instancied. */ struct vkms_config { @@ -19,6 +19,27 @@ struct vkms_config { bool cursor; bool overlay; struct vkms_device *dev; + + struct list_head planes; +}; + +/** + * struct vkms_config_plane + * + * @link: Link to the others planes + * @type: Type of the plane. The creator of configuration needs to ensures that at least one + * plane is primary. + * @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; }; /** @@ -42,6 +63,24 @@ void vkms_config_destroy(struct vkms_config *config); */ bool vkms_config_is_valid(struct vkms_config *vkms_config); +/** + * vkms_config_create_plane() - Create a plane configuration + * + * This will allocate and add a new plane to @vkms_config. This plane will have by default the + * maximum supported values. + * @vkms_config: Configuration where to insert new plane + */ +struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *vkms_config); + +/** + * vkms_config_delete_plane() - Remove a plane configuration and frees its memory + * + * This will delete a plane configuration from the parent configuration. This will NOT + * cleanup and frees the vkms_plane that can be stored in @vkms_config_plane. + * @vkms_config_plane: Plane configuration to cleanup + */ +void vkms_config_delete_plane(struct vkms_config_plane *vkms_config_plane); + /** * vkms_config_alloc_default() - Allocate the configuration for the default device * @enable_writeback: Enable the writeback connector for this configuration diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index af7081c940d6c074dc01cf8180556a3d902e386d..1b5add9536f503fe224425b924c14a5217bb09b1 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -190,6 +190,7 @@ struct vkms_output { }; struct vkms_config; +struct vkms_config_plane; /** * struct vkms_device - Description of a VKMS device @@ -246,7 +247,7 @@ int vkms_output_init(struct vkms_device *vkmsdev); * @type: type of plane to initialize */ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, - enum drm_plane_type type); + struct vkms_config_plane *config); /* CRC Support */ const char *const *vkms_get_crc_sources(struct drm_crtc *crtc, diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index 78e389d832c16e4dbaccda34fbf3215f34adeadf..cf385f676ef7f45633b4ed69a8047c87fad95dbd 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -31,30 +31,14 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { int vkms_output_init(struct vkms_device *vkmsdev) { + struct vkms_config_plane *config_plane; struct drm_device *dev = &vkmsdev->drm; struct drm_connector *connector; struct drm_encoder *encoder; struct vkms_output *output; - struct vkms_plane *primary, *overlay, *cursor = NULL; + struct vkms_plane *primary, *cursor = NULL; int ret; int writeback; - unsigned int n; - - /* - * 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); - - if (vkmsdev->config->cursor) { - cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR); - if (IS_ERR(cursor)) - return PTR_ERR(cursor); - } output = vkms_crtc_init(dev, &primary->base, cursor ? &cursor->base : NULL); @@ -63,15 +47,16 @@ 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); + list_for_each_entry(config_plane, &vkmsdev->config->planes, link) { + config_plane->plane = vkms_plane_init(vkmsdev, config_plane); + if (IS_ERR(config_plane->plane)) { + ret = PTR_ERR(config_plane->plane); + return ret; } + if (config_plane->type == DRM_PLANE_TYPE_PRIMARY) + primary = config_plane->plane; + else if (config_plane->type == DRM_PLANE_TYPE_CURSOR) + cursor = config_plane->plane; } connector = drmm_kzalloc(dev, sizeof(*connector), GFP_KERNEL); diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index e2fce471870f1899f2ccb66b339ce8c4332cc287..4663002c9c54030ff6243631a2a1cff26415e7a3 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -11,6 +11,7 @@ #include "vkms_drv.h" #include "vkms_formats.h" +#include "vkms_config.h" static const u32 vkms_formats[] = { DRM_FORMAT_ARGB8888, @@ -187,7 +188,7 @@ static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = { }; struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, - enum drm_plane_type type) + struct vkms_config_plane *config) { struct drm_device *dev = &vkmsdev->drm; struct vkms_plane *plane; @@ -195,7 +196,7 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 0, &vkms_plane_funcs, vkms_formats, ARRAY_SIZE(vkms_formats), - NULL, type, NULL); + NULL, config->type, NULL); if (IS_ERR(plane)) return plane; From patchwork Tue Jan 21 10:55:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946170 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 A5879C0218C for ; Tue, 21 Jan 2025 10:55:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B39E810E578; Tue, 21 Jan 2025 10:55:54 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="FYPXFg02"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::222]) by gabe.freedesktop.org (Postfix) with ESMTPS id 80ED610E562 for ; Tue, 21 Jan 2025 10:55:40 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 86F494000D; Tue, 21 Jan 2025 10:55:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456939; 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=rZcwtHI8+1dN0/SLlMiTp/ryUEVBiLmGMxRlYoqZrlY=; b=FYPXFg02iu2Ko0nmZ5ic6AtIaw4B0AW5gf6aTSjp1iu1jZVeQo8RxES7m964HAeTzkK/EI EzOuvDRpicBAIGwcvtqiDYHQeHze5Td/BZ6N0pz6z7LNj/W9iIEOwdbDcGkGHU1qvtgbxV FazmloIRlNNwitemAqTM1ql41iE4/DqXfw+x6Su1nouK74pXJ8VfAH+80MKtgiCFBvpBra ni/Ual+NPaag7U4MnL0NzFjf6R7zMjP74LK5HGkW5XLA3tU1rH4ytyJOPUtfTsAvnXUlYm yiE3OsKdMQ4RatbwupctUzc/1fOm5m6aEgZwVUxQk9iLXsBDfHfuKAwgw02WJQ== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:29 +0100 Subject: [PATCH v3 05/16] drm/vkms: Introduce config for plane name MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-5-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3777; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=Q4JNIVSGM6yjHh69qGFrGrMv69I5kWOImsa10E9crF0=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30h2HpIbZERw8CtbNtFiLzBfLqQ8xZm0cw6w aflIInxFj6JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499IQAKCRAgrS7GWxAs 4uLHEADBRT60MdbXTR1tHRt5DffiwnkpywTA9dt1W3puJIOduUacC+1GBFZMRE96TrEuUfZspsj AgRmot0GxCVtaByEjjimRDX2eG8kSR9Irt0WiMPDzqsMWCwfa/tdqSX07x+6Xr0xbvHNNgu3BDu qsAVBe+kKgnPODJ8ilJ2U+mhK8JJDMMVzXwd8p6V33l87B0iU4ktAJAbZzZh7BOHYv898aomv5e y/LdGm9uKt5M9jfdBTR8GVsDfBpMshBaeBdc25pwr1QG1uWwAdYCdUvCGQWJDtXFlEU9jM336oy Jgs+Mo2F7pK+ZR5/uj+d+yvLQ+8MJVxbl39FCHWmATYSFLlJODLsgZdSSnczgjETdTKaBIsjFzc y+GFZc3amrWXwKh6ju2TLH4IJssJwSs+m7BJvusv6p1P4CsdchD4HzAqOQm++SLV6dse8bSFwyQ 0IDH5GvvG61lUuzz0sDBKm4RGIJdxIfrYwNjairdoPjMpuCrRpBsU2Ra8Ukpn9kj3bYNxeI93Ub LMWqeuJgm/H+pAKVzZrkFXUJH6k9fZPbQV7oBpmTWgFpMk36hSj0sFvGs4tctnsrbE2VIAqjleg b9G+RYftkVcYNPASi/fR92p4trgVY/SVlpqxVM60k4hpNWKSjr01EdKMDi8W6qShtjd/mdOhLkI y072mZyrOqfuvng== 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" As a plane will be a folder in ConfigFS, add name configuration for plane so it will reflect the folder name. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 14 ++++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 2 ++ drivers/gpu/drm/vkms/vkms_plane.c | 2 +- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index 495056ce988ab32738701f00c94c709457aefbd3..0caa6bfccb5e409efa37ea48a52299e0dc132728 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -36,6 +36,10 @@ struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable goto err_alloc; plane->type = DRM_PLANE_TYPE_PRIMARY; + plane->name = kzalloc(sizeof("primary"), GFP_KERNEL); + if (!plane->name) + goto err_alloc; + sprintf(plane->name, "primary"); if (enable_overlay) { for (int i = 0; i < NUM_OVERLAY_PLANES; i++) { @@ -43,6 +47,10 @@ struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable if (!plane) goto err_alloc; plane->type = DRM_PLANE_TYPE_OVERLAY; + plane->name = kzalloc(10, GFP_KERNEL); + if (!plane->name) + goto err_alloc; + snprintf(plane->name, 10, "plane-%d", i); } } if (enable_cursor) { @@ -50,6 +58,10 @@ struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable if (!plane) goto err_alloc; plane->type = DRM_PLANE_TYPE_CURSOR; + plane->name = kzalloc(sizeof("cursor"), GFP_KERNEL); + if (!plane->name) + goto err_alloc; + sprintf(plane->name, "cursor"); } return vkms_config; @@ -82,6 +94,7 @@ void vkms_config_delete_plane(struct vkms_config_plane *vkms_config_overlay) if (!vkms_config_overlay) return; list_del(&vkms_config_overlay->link); + kfree(vkms_config_overlay->name); kfree(vkms_config_overlay); } @@ -136,6 +149,7 @@ static int vkms_config_show(struct seq_file *m, void *data) seq_printf(m, "writeback=%d\n", vkmsdev->config->writeback); list_for_each_entry(config_plane, &vkmsdev->config->planes, link) { seq_puts(m, "plane:\n"); + seq_printf(m, "\tname: %s\n", config_plane->name); seq_printf(m, "\ttype: %d\n", config_plane->type); } diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index ac99f1df6d9a17bd7040a1e7a6acce14cd8fd9d0..3e70bce8d4f7b06f44ec79b3a3d8e6897f9a44c7 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -27,6 +27,7 @@ struct vkms_config { * struct vkms_config_plane * * @link: Link to the others planes + * @name: Name of the plane * @type: Type of the plane. The creator of configuration needs to ensures that at least one * plane is primary. * @plane: Internal usage. This pointer should never be considered as valid. It can be used to @@ -36,6 +37,7 @@ struct vkms_config { struct vkms_config_plane { struct list_head link; + char *name; enum drm_plane_type type; /* Internal usage */ diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index 4663002c9c54030ff6243631a2a1cff26415e7a3..b3a9a42476ef340986c8961f076236d76a7c73e3 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -196,7 +196,7 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 0, &vkms_plane_funcs, vkms_formats, ARRAY_SIZE(vkms_formats), - NULL, config->type, NULL); + NULL, config->type, config->name); if (IS_ERR(plane)) return plane; From patchwork Tue Jan 21 10:55:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946169 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 3161DC02182 for ; Tue, 21 Jan 2025 10:55:55 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6C87410E575; Tue, 21 Jan 2025 10:55:54 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="nYZFc3d6"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::222]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5EFBA10E562 for ; Tue, 21 Jan 2025 10:55:41 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 5B06440010; Tue, 21 Jan 2025 10:55:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456940; 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=HqcY0DyYtlO489ogTF+qU/dH02tuwjudbhOD1uwQSKo=; b=nYZFc3d66EUYFVln8sqGE2eOnY75Ptngj4UMTlAAfiTHwfn8GzB03e/XXDBaSWuzhUpiRo 3ZiLx6ZaETlaMl8LnmVV8IxM/QPPj423IKQZYHVcxl7mctFWL1KDvQ76Gk9yfeWenrKy05 ml3Hwx9tU8+PVrVvWprnUKAUDzJ4fOKUb2Ua9m4j2vQHtWcNBCFGyd/BFm0NLbRrE5r4ZI TRW22oDBcBU55/Zer+1sFGKlE8B2Jb06U9D4XiqIQhvHmrM5z67YHrzzP+sRWMxWhjYB2w OElb4DcF+bGnEl2pq91rwRh/uH/iN67l6PEngg/AkmycMH2G8IGZfjD/ZnvWmw== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:30 +0100 Subject: [PATCH v3 06/16] drm/vkms: Introduce config for plane rotation MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-6-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3836; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=/+tB6p8BZyzbvr8BpDgZBRbkRtslJ2ufkBFxa/NbvvQ=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30h3+PgIgWWW6uszuYC0FX9x5fswGz4iDZE/ KPg8ENAeMeJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499IQAKCRAgrS7GWxAs 4sd5D/452OUg4UptAlh29AkMOVyxmnuupUTNypqsPf5EUrqQeLlcIe1dhD0B7L5h7h8dLeRrkwy ldMmQ7niZ3C3qj9TXHWNz2/sHShyk5/uWShDqaFj1in4JOmawaUnUHHNTv/I0PSU5paexqdXSGx 5cMYG67o6L1PEKy4DMJiLXZfms0+e1PGOzJ5umYjwnUNiQNLrellR7vp3yqLxOqdK7nSj2RPhXD zVNAlTeDpMGODZqQC+su7y3lUPXqk2V8QFitWjPU4BXOaDbX5uU4uh4P/DAtd9WCOwAsZH21ySx aN14Tr1npS2Dt/W488H/Ml7jbveWuHpSXlLaOlQyGmsK7SI5EXoB1z/OIaTrfrS2QYIX9DCaR4D /btt0PrbApNtMJukEqlvvLtV2n8BXnlWQaBN1A8BKwLb2tfu5VG/dJzI17e16obM2DqHDuq5yHt ZtpJLldpJBzCdxaHyC9HyWd0m7OCfJpl3WLBsvcXqAyOYDT+yKtgAMVvMzajP5+FRBdqPN/lvh8 sOck0uuI/f0GaaI6DO+Fr3dVZyhEFAvCqfadJMix7iGMr1tB6JrPxilAgz7zqPSjQ1d92VVlsPz IVaNFeK6yOiW4Gsb0UnfAenZ0SJr/4iqKL9Yeb141tx4Mj6vJCU2kxNIF1GuMtZJAPhshOAxR7d dCDFuoHvVQEiI4Q== 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 driver supports all the rotation on planes, but for testing it can be useful to only advertise few of them. This new configuration interface will allow configuring the rotation per planes. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 9 +++++++++ drivers/gpu/drm/vkms/vkms_config.h | 4 ++++ drivers/gpu/drm/vkms/vkms_plane.c | 5 +++-- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index 0caa6bfccb5e409efa37ea48a52299e0dc132728..c7a39cde8cfbcd0ff4f5ae137cfb709b7a2240e2 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -82,6 +82,8 @@ struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *vkms_conf return NULL; vkms_config_overlay->type = DRM_PLANE_TYPE_OVERLAY; + vkms_config_overlay->supported_rotations = DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK; + vkms_config_overlay->default_rotation = DRM_MODE_ROTATE_0; list_add(&vkms_config_overlay->link, &vkms_config->planes); @@ -118,6 +120,11 @@ bool vkms_config_is_valid(struct vkms_config *config) bool has_primary = false; list_for_each_entry(config_plane, &config->planes, link) { + // Default rotation not in supported rotations + if ((config_plane->default_rotation & config_plane->supported_rotations) != + config_plane->default_rotation) + return false; + if (config_plane->type == DRM_PLANE_TYPE_PRIMARY) { // Multiple primary planes for only one CRTC if (has_primary) @@ -151,6 +158,8 @@ static int vkms_config_show(struct seq_file *m, void *data) seq_puts(m, "plane:\n"); seq_printf(m, "\tname: %s\n", config_plane->name); seq_printf(m, "\ttype: %d\n", config_plane->type); + seq_printf(m, "\tsupported rotations: 0x%x\n", config_plane->supported_rotations); + seq_printf(m, "\tdefault rotation: 0x%x\n", config_plane->default_rotation); } return 0; diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index 3e70bce8d4f7b06f44ec79b3a3d8e6897f9a44c7..fd5e0df11647f145d53e71a1b6a244951af3ec0d 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -30,6 +30,8 @@ struct vkms_config { * @name: Name of the plane * @type: Type of the plane. The creator of configuration needs to ensures that at least one * plane is primary. + * @default_rotation: Default rotation that should be used by this plane + * @supported_rotation: Rotation that this plane will support * @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. @@ -39,6 +41,8 @@ struct vkms_config_plane { char *name; enum drm_plane_type type; + unsigned int default_rotation; + unsigned int supported_rotations; /* Internal usage */ struct vkms_plane *plane; diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index b3a9a42476ef340986c8961f076236d76a7c73e3..c23ac8687dedaa956cfd6622321f1026521ff13f 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -202,8 +202,9 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, drm_plane_helper_add(&plane->base, &vkms_plane_helper_funcs); - drm_plane_create_rotation_property(&plane->base, DRM_MODE_ROTATE_0, - DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK); + drm_plane_create_rotation_property(&plane->base, + config->default_rotation, + config->supported_rotations); return plane; } From patchwork Tue Jan 21 10:55:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946166 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 08249C0218D for ; Tue, 21 Jan 2025 10:55:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B834510E56C; Tue, 21 Jan 2025 10:55:45 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="eW/p3WW8"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::222]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3323310E562 for ; Tue, 21 Jan 2025 10:55:42 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 3AC2C40013; Tue, 21 Jan 2025 10:55:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456940; 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=FTu86rxGrThTu/st6dZ2/+QAyKkenwOIl4BGnYWjBLU=; b=eW/p3WW8rPrcBEAC5cCCMLB07ZjJvNwtumgKCTxzHj+CsMPBk7UsKlqzynm/wj08UcSjeo oRmOMvDtdBL5j2tBqEKkp9WW9xaP2+c4nStYQoUUDA75jSKpqJOLUqTFTzeOHnhPXD3oNI dq5UxNko1K6MtyA1oy/bzOG6oyp+NH7sVIWRYoi67mHMcD32vBTifIBNdDUCMFIY6spLA4 GRN6l/sJOM7VRPK9QdDO4WYZ/E/vkJ0pWxYYvYX8GF9hoV3qefqRdLGqkD7Izb11CMqf6l VTNWMtQfmyD+NzzjlXHBJ5rLei/PET0pktgE9AJmSSFxRING7lHGekEYIwta+Q== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:31 +0100 Subject: [PATCH v3 07/16] drm/vkms: Introduce config for CRTCs and encoders MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-7-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=24741; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=w4xbkLBcLkFtKggQbw+D/3PysKtGax5BrrOgJn99Iyo=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30idgX8gZx7o8GvZwO5CO6VnDiI9veZy3P5S 6MRefYPTb6JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499IgAKCRAgrS7GWxAs 4l5SEAC3lX8EHuOTA3yoEoRY4u+ELjeNwVu3jo0qGBQcu446cH2X+x++Zo43RhRDK84QUUVmATx 76l+bxoWntaH8ZFAQuhztsfkIbpO2olsqmB2qwCkAXMQ8jcbFROxsIduhcijeBiH6/63ZSf/jZf GrROyJFZUwrqUOTB00r8i/HCd0vjuILLPSMBL2SO7GIL0O0IHCpj+Nx7wq6mxrhM+xLIZWM2GSn 7uDFS4Jgk/BQ/XQWrzgmCJnP6XjgKCj1sEt8TMaMYWGx/0mKPV/WR1xYfXImARzq0jwYrWzZwdF 87ZXt3JidtngyXAhOS9S4WEcWxDD3Nze40ah/tobLZoMq/EibQSDycdn860A+ufDFK/fl/QWBgk yZ2EJN+ASxflg3o/IBOUShnIlEPKr9ezWAHyaQvQTMOxT+ggV38sh5Q/WvWbnTrutdOu1XfctHE 26nxTNithRAexC4vQsRnOd5VhGCYpG4eF9FXwMXTSim525a4Bdw3TNEaPV7iBbCFcsFMrYymY8P iH9ep2i3nl+JihVyg/PzrTbmGoDfnMUlkBUSlXm2QVpt2Rs9/BvgMtgV8lLC4pNCAQajghT0upt 6kDXsK5IFjHpUlPhK0ndkKeZtKpd1w07VPmu/gbocLcnrAEEdJzk6uhD8U9nserpar8JMID6JMV coeyyODq5D5e8zQ== 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" The current VKMS driver can only uses one CRTC and one encoder. This patch introduce in the same time CRTC and encoders as they are tighly linked. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 269 +++++++++++++++++++++++++++++++++---- drivers/gpu/drm/vkms/vkms_config.h | 104 +++++++++++++- drivers/gpu/drm/vkms/vkms_crtc.c | 8 +- drivers/gpu/drm/vkms/vkms_drv.h | 7 +- drivers/gpu/drm/vkms/vkms_output.c | 88 ++++++------ 5 files changed, 401 insertions(+), 75 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index c7a39cde8cfbcd0ff4f5ae137cfb709b7a2240e2..314d252aa9b6ed1772c8ef597bd9c6b08145723e 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -15,6 +15,8 @@ struct vkms_config *vkms_config_create(void) return ERR_PTR(-ENOMEM); INIT_LIST_HEAD(&config->planes); + INIT_LIST_HEAD(&config->crtcs); + INIT_LIST_HEAD(&config->encoders); return config; } @@ -24,12 +26,24 @@ struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable bool enable_cursor) { struct vkms_config_plane *plane; + struct vkms_config_encoder *encoder; + struct vkms_config_crtc *crtc; struct vkms_config *vkms_config = vkms_config_create(); if (IS_ERR(vkms_config)) return vkms_config; - vkms_config->writeback = enable_writeback; + crtc = vkms_config_create_crtc(vkms_config); + if (!crtc) + goto err_alloc; + crtc->writeback = enable_writeback; + + encoder = vkms_config_create_encoder(vkms_config); + if (!encoder) + goto err_alloc; + + if (vkms_config_encoder_attach_crtc(encoder, crtc)) + goto err_alloc; plane = vkms_config_create_plane(vkms_config); if (!plane) @@ -41,6 +55,9 @@ struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable goto err_alloc; sprintf(plane->name, "primary"); + if (vkms_config_plane_attach_crtc(plane, crtc)) + goto err_alloc; + if (enable_overlay) { for (int i = 0; i < NUM_OVERLAY_PLANES; i++) { plane = vkms_config_create_plane(vkms_config); @@ -51,6 +68,9 @@ struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable if (!plane->name) goto err_alloc; snprintf(plane->name, 10, "plane-%d", i); + + if (vkms_config_plane_attach_crtc(plane, crtc)) + goto err_alloc; } } if (enable_cursor) { @@ -62,6 +82,9 @@ struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable if (!plane->name) goto err_alloc; sprintf(plane->name, "cursor"); + + if (vkms_config_plane_attach_crtc(plane, crtc)) + goto err_alloc; } return vkms_config; @@ -84,6 +107,7 @@ struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *vkms_conf vkms_config_overlay->type = DRM_PLANE_TYPE_OVERLAY; vkms_config_overlay->supported_rotations = DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK; vkms_config_overlay->default_rotation = DRM_MODE_ROTATE_0; + xa_init_flags(&vkms_config_overlay->possible_crtcs, XA_FLAGS_ALLOC); list_add(&vkms_config_overlay->link, &vkms_config->planes); @@ -91,33 +115,195 @@ struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *vkms_conf } EXPORT_SYMBOL_IF_KUNIT(vkms_config_create_plane); -void vkms_config_delete_plane(struct vkms_config_plane *vkms_config_overlay) +struct vkms_config_crtc *vkms_config_create_crtc(struct vkms_config *vkms_config) { - if (!vkms_config_overlay) + if (!vkms_config) + return NULL; + + struct vkms_config_crtc *vkms_config_crtc = kzalloc(sizeof(*vkms_config_crtc), + GFP_KERNEL); + + if (!vkms_config_crtc) + return NULL; + + list_add(&vkms_config_crtc->link, &vkms_config->crtcs); + xa_init_flags(&vkms_config_crtc->possible_planes, XA_FLAGS_ALLOC); + xa_init_flags(&vkms_config_crtc->possible_encoders, XA_FLAGS_ALLOC); + + return vkms_config_crtc; +} +EXPORT_SYMBOL_IF_KUNIT(vkms_config_create_crtc); + +struct vkms_config_encoder *vkms_config_create_encoder(struct vkms_config *vkms_config) +{ + if (!vkms_config) + return NULL; + + struct vkms_config_encoder *vkms_config_encoder = kzalloc(sizeof(*vkms_config_encoder), + GFP_KERNEL); + + if (!vkms_config_encoder) + return NULL; + + list_add(&vkms_config_encoder->link, &vkms_config->encoders); + xa_init_flags(&vkms_config_encoder->possible_crtcs, XA_FLAGS_ALLOC); + + return vkms_config_encoder; +} +EXPORT_SYMBOL_IF_KUNIT(vkms_config_create_encoder); + +void vkms_config_delete_plane(struct vkms_config_plane *vkms_config_plane, + struct vkms_config *vkms_config) +{ + struct vkms_config_crtc *crtc_config; + struct vkms_config_plane *plane; + + if (!vkms_config_plane) + return; + list_del(&vkms_config_plane->link); + xa_destroy(&vkms_config_plane->possible_crtcs); + + list_for_each_entry(crtc_config, &vkms_config->crtcs, link) { + unsigned long idx = 0; + + xa_for_each(&crtc_config->possible_planes, idx, plane) { + if (plane == vkms_config_plane) + xa_erase(&crtc_config->possible_planes, idx); + } + } + + kfree(vkms_config_plane->name); + kfree(vkms_config_plane); +} +EXPORT_SYMBOL_IF_KUNIT(vkms_config_delete_plane); + +void vkms_config_delete_crtc(struct vkms_config_crtc *vkms_config_crtc, + struct vkms_config *vkms_config) +{ + struct vkms_config_crtc *crtc_config; + struct vkms_config_plane *plane_config; + struct vkms_config_encoder *encoder_config; + + if (!vkms_config_crtc) + return; + list_del(&vkms_config_crtc->link); + xa_destroy(&vkms_config_crtc->possible_planes); + xa_destroy(&vkms_config_crtc->possible_encoders); + + list_for_each_entry(plane_config, &vkms_config->planes, link) { + unsigned long idx = 0; + + xa_for_each(&plane_config->possible_crtcs, idx, crtc_config) { + if (crtc_config == vkms_config_crtc) + xa_erase(&plane_config->possible_crtcs, idx); + } + } + + list_for_each_entry(encoder_config, &vkms_config->encoders, link) { + unsigned long idx = 0; + + xa_for_each(&encoder_config->possible_crtcs, idx, crtc_config) { + if (crtc_config == vkms_config_crtc) + xa_erase(&encoder_config->possible_crtcs, idx); + } + } + + kfree(vkms_config_crtc); +} + +void vkms_config_delete_encoder(struct vkms_config_encoder *vkms_config_encoder, + struct vkms_config *vkms_config) +{ + if (!vkms_config_encoder) return; - list_del(&vkms_config_overlay->link); - kfree(vkms_config_overlay->name); - kfree(vkms_config_overlay); + list_del(&vkms_config_encoder->link); + xa_destroy(&vkms_config_encoder->possible_crtcs); + + struct vkms_config_crtc *crtc_config; + struct vkms_config_encoder *encoder; + + list_for_each_entry(crtc_config, &vkms_config->crtcs, link) { + unsigned long idx = 0; + + xa_for_each(&crtc_config->possible_encoders, idx, encoder) { + if (encoder == vkms_config_encoder) + xa_erase(&crtc_config->possible_encoders, idx); + } + } + + kfree(vkms_config_encoder); } void vkms_config_destroy(struct vkms_config *config) { struct vkms_config_plane *vkms_config_plane, *tmp_plane; + struct vkms_config_encoder *vkms_config_encoder, *tmp_encoder; + struct vkms_config_crtc *vkms_config_crtc, *tmp_crtc; list_for_each_entry_safe(vkms_config_plane, tmp_plane, &config->planes, link) { - vkms_config_delete_plane(vkms_config_plane); + vkms_config_delete_plane(vkms_config_plane, config); + } + list_for_each_entry_safe(vkms_config_encoder, tmp_encoder, &config->encoders, link) { + vkms_config_delete_encoder(vkms_config_encoder, config); + } + list_for_each_entry_safe(vkms_config_crtc, tmp_crtc, &config->crtcs, link) { + vkms_config_delete_crtc(vkms_config_crtc, config); } kfree(config); } EXPORT_SYMBOL_IF_KUNIT(vkms_config_destroy); +int __must_check vkms_config_plane_attach_crtc(struct vkms_config_plane *vkms_config_plane, + struct vkms_config_crtc *vkms_config_crtc) +{ + u32 crtc_idx, encoder_idx; + int ret; + + ret = xa_alloc(&vkms_config_plane->possible_crtcs, &crtc_idx, vkms_config_crtc, + xa_limit_32b, GFP_KERNEL); + if (ret) + return ret; + + ret = xa_alloc(&vkms_config_crtc->possible_planes, &encoder_idx, vkms_config_plane, + xa_limit_32b, GFP_KERNEL); + if (ret) { + xa_erase(&vkms_config_plane->possible_crtcs, crtc_idx); + return ret; + } + + return ret; +} +EXPORT_SYMBOL_IF_KUNIT(vkms_config_plane_attach_crtc); + +int __must_check vkms_config_encoder_attach_crtc(struct vkms_config_encoder *vkms_config_encoder, + struct vkms_config_crtc *vkms_config_crtc) +{ + u32 crtc_idx, encoder_idx; + int ret; + + ret = xa_alloc(&vkms_config_encoder->possible_crtcs, &crtc_idx, vkms_config_crtc, + xa_limit_32b, GFP_KERNEL); + if (ret) + return ret; + + ret = xa_alloc(&vkms_config_crtc->possible_encoders, &encoder_idx, vkms_config_encoder, + xa_limit_32b, GFP_KERNEL); + if (ret) { + xa_erase(&vkms_config_encoder->possible_crtcs, crtc_idx); + return ret; + } + + return ret; +} +EXPORT_SYMBOL_IF_KUNIT(vkms_config_encoder_attach_crtc); + bool vkms_config_is_valid(struct vkms_config *config) { struct vkms_config_plane *config_plane; - bool has_cursor = false; - bool has_primary = false; + struct vkms_config_crtc *config_crtc; + struct vkms_config_encoder *config_encoder; list_for_each_entry(config_plane, &config->planes, link) { // Default rotation not in supported rotations @@ -125,22 +311,47 @@ bool vkms_config_is_valid(struct vkms_config *config) config_plane->default_rotation) return false; - if (config_plane->type == DRM_PLANE_TYPE_PRIMARY) { - // Multiple primary planes for only one CRTC - if (has_primary) - return false; - has_primary = true; - } - if (config_plane->type == DRM_PLANE_TYPE_CURSOR) { - // Multiple cursor planes for only one CRTC - if (has_cursor) - return false; - has_cursor = true; - } + // No CRTC linked to this plane + if (xa_empty(&config_plane->possible_crtcs)) + return false; + } + + list_for_each_entry(config_encoder, &config->encoders, link) { + // No CRTC linked to this encoder + if (xa_empty(&config_encoder->possible_crtcs)) + return false; } - if (!has_primary) - return false; + list_for_each_entry(config_crtc, &config->crtcs, link) { + bool has_primary = false; + bool has_cursor = false; + unsigned long idx = 0; + + // No encoder attached to this CRTC + if (xa_empty(&config_crtc->possible_encoders)) + return false; + + xa_for_each(&config_crtc->possible_planes, idx, config_plane) { + if (config_plane->type == DRM_PLANE_TYPE_PRIMARY) { + // Multiple primary planes for only one CRTC + if (has_primary) + return false; + + has_primary = true; + } + if (config_plane->type == DRM_PLANE_TYPE_CURSOR) { + // Multiple cursor planes for only one CRTC + if (has_cursor) + return false; + + has_cursor = true; + } + } + + // No primary plane for this CRTC + if (!has_primary) + return false; + } return true; } @@ -152,8 +363,9 @@ static int vkms_config_show(struct seq_file *m, void *data) struct drm_device *dev = entry->dev; struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev); struct vkms_config_plane *config_plane; + struct vkms_config_crtc *config_crtc; + struct vkms_config_encoder *config_encoder; - seq_printf(m, "writeback=%d\n", vkmsdev->config->writeback); list_for_each_entry(config_plane, &vkmsdev->config->planes, link) { seq_puts(m, "plane:\n"); seq_printf(m, "\tname: %s\n", config_plane->name); @@ -162,6 +374,15 @@ static int vkms_config_show(struct seq_file *m, void *data) seq_printf(m, "\tdefault rotation: 0x%x\n", config_plane->default_rotation); } + list_for_each_entry(config_encoder, &vkmsdev->config->encoders, link) { + seq_puts(m, "encoder:\n"); + } + + list_for_each_entry(config_crtc, &vkmsdev->config->crtcs, link) { + seq_puts(m, "crtc:\n"); + seq_printf(m, "\twriteback: %d\n", config_crtc->writeback); + } + return 0; } diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index fd5e0df11647f145d53e71a1b6a244951af3ec0d..90ced83f5eb6dae5ccc14c37169606d833ba355a 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -9,18 +9,59 @@ /** * struct vkms_config - General configuration for VKMS driver * - * @writeback: If true, a writeback buffer can be attached to the CRTC * @planes: List of planes configured for this device. They are created by the function * vkms_config_create_plane(). + * @crtcs: List of crtcs configured for this device. They are created by the function + * vkms_config_create_crtc(). + * @encoders: List of encoders configured for this device. They are created by the function + * vkms_config_create_encoder(). * @dev: Used to store the current vkms device. Only set when the device is instancied. */ struct vkms_config { - bool writeback; - bool cursor; - bool overlay; struct vkms_device *dev; struct list_head planes; + struct list_head crtcs; + struct list_head encoders; +}; + +/** + * struct vkms_config_crtc + * + * @link: Link to the others CRTCs + * @possible_planes: List of planes that can be used with this CRTC + * @possible_encoders: List of encoders that can be used with this 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; + struct xarray possible_planes; + struct xarray possible_encoders; + + /* Internal usage */ + struct vkms_output *output; +}; + +/** + * struct vkms_config_encoder + * + * @link: Link to the others encoders + * @possible_crtcs: List of CRTC 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 configuration and must be managed by other means. + */ +struct vkms_config_encoder { + struct list_head link; + + struct xarray possible_crtcs; + + /* Internal usage */ + struct drm_encoder *encoder; }; /** @@ -32,6 +73,7 @@ struct vkms_config { * plane is primary. * @default_rotation: Default rotation that should be used by this plane * @supported_rotation: Rotation that this plane will support + * @possible_crtcs: List of CRTC that can be used with this plane. * @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. @@ -44,6 +86,7 @@ struct vkms_config_plane { unsigned int default_rotation; unsigned int supported_rotations; + struct xarray possible_crtcs; /* Internal usage */ struct vkms_plane *plane; }; @@ -78,14 +121,63 @@ bool vkms_config_is_valid(struct vkms_config *vkms_config); */ struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *vkms_config); +/** + * vkms_config_create_crtc() - Create a crtc configuration + * + * This will allocate and add a new crtc configuration to @vkms_config. + * @vkms_config: Configuration where to insert new crtc configuration + */ +struct vkms_config_crtc *vkms_config_create_crtc(struct vkms_config *vkms_config); + +/** + * vkms_config_create_encoder() - Create an encoder configuration + * + * This will allocate and add a new encoder configuration to @vkms_config. + * @vkms_config: Configuration where to insert new encoder configuration + */ +struct vkms_config_encoder *vkms_config_create_encoder(struct vkms_config *vkms_config); + +int __must_check vkms_config_plane_attach_crtc(struct vkms_config_plane *vkms_config_plane, + struct vkms_config_crtc *vkms_config_crtc); +int __must_check vkms_config_encoder_attach_crtc(struct vkms_config_encoder *vkms_config_encoder, + struct vkms_config_crtc *vkms_config_crtc); + /** * vkms_config_delete_plane() - Remove a plane configuration and frees its memory * * This will delete a plane configuration from the parent configuration. This will NOT - * cleanup and frees the vkms_plane that can be stored in @vkms_config_plane. + * cleanup and frees the vkms_plane that can be stored in @vkms_config_plane. It will also remove + * any reference to this plane in @vkms_config. + * * @vkms_config_plane: Plane configuration to cleanup + * @vkms_config: Parent configuration + */ +void vkms_config_delete_plane(struct vkms_config_plane *vkms_config_plane, + struct vkms_config *vkms_config); +/** + * vkms_config_delete_crtc() - Remove a CRTC configuration and frees its memory + * + * This will delete a CRTC configuration from the parent configuration. This will NOT + * cleanup and frees the vkms_crtc that can be stored in @vkms_config_crtc. It will also remove + * any reference to this CRTC in @vkms_config. + * + * @vkms_config_crtc: Plane configuration to cleanup + * @vkms_config: Parent configuration + */ +void vkms_config_delete_crtc(struct vkms_config_crtc *vkms_config_crtc, + struct vkms_config *vkms_config); +/** + * vkms_config_delete_encoder() - Remove an encoder configuration and frees its memory + * + * This will delete an encoder configuration from the parent configuration. This will NOT + * cleanup and frees the vkms_encoder that can be stored in @vkms_config_encoder. It will also + * remove any reference to this CRTC in @vkms_config. + * + * @vkms_config_encoder: Plane configuration to cleanup + * @vkms_config: Parent configuration */ -void vkms_config_delete_plane(struct vkms_config_plane *vkms_config_plane); +void vkms_config_delete_encoder(struct vkms_config_encoder *vkms_config_encoder, + struct vkms_config *vkms_config); /** * vkms_config_alloc_default() - Allocate the configuration for the default device diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index cf229aec71c3f03bb1306095e8dd44d63f80cd2a..f4da196fd7774ee1dcc5148e6420186f1384b3fa 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -9,6 +9,7 @@ #include #include "vkms_drv.h" +#include "vkms_config.h" static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) { @@ -269,9 +270,12 @@ static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = { .atomic_disable = vkms_crtc_atomic_disable, }; -struct vkms_output *vkms_crtc_init(struct drm_device *dev, struct drm_plane *primary, - struct drm_plane *cursor) +struct vkms_output *vkms_crtc_init(struct vkms_device *vkms_device, + struct drm_plane *primary, + struct drm_plane *cursor, + struct vkms_config_crtc *config) { + struct drm_device *dev = &vkms_device->drm; struct vkms_output *vkms_out; struct drm_crtc *crtc; int ret; diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 1b5add9536f503fe224425b924c14a5217bb09b1..3a211cdb41bd1003366d9eaa1425e122d885e4a4 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -191,6 +191,8 @@ struct vkms_output { struct vkms_config; struct vkms_config_plane; +struct vkms_config_crtc; +struct vkms_config_encoder; /** * struct vkms_device - Description of a VKMS device @@ -229,9 +231,10 @@ struct vkms_device { * @primary: primary plane to attach to the CRTC * @cursor: plane to attach to the CRTC */ -struct vkms_output *vkms_crtc_init(struct drm_device *dev, +struct vkms_output *vkms_crtc_init(struct vkms_device *vkms_device, struct drm_plane *primary, - struct drm_plane *cursor); + struct drm_plane *cursor, + struct vkms_config_crtc *config); /** * vkms_output_init() - Initialize all sub-components needed for a VKMS device. diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index cf385f676ef7f45633b4ed69a8047c87fad95dbd..dab949c983a5991696baf937f948c0f78710d6e1 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -31,21 +31,13 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { int vkms_output_init(struct vkms_device *vkmsdev) { - struct vkms_config_plane *config_plane; + struct vkms_config_encoder *config_encoder; struct drm_device *dev = &vkmsdev->drm; + struct vkms_config_plane *config_plane; + struct vkms_config_crtc *config_crtc; struct drm_connector *connector; - struct drm_encoder *encoder; - struct vkms_output *output; - struct vkms_plane *primary, *cursor = NULL; + unsigned long idx; int ret; - int writeback; - - output = vkms_crtc_init(dev, &primary->base, - cursor ? &cursor->base : NULL); - if (IS_ERR(output)) { - DRM_ERROR("Failed to allocate CRTC\n"); - return PTR_ERR(output); - } list_for_each_entry(config_plane, &vkmsdev->config->planes, link) { config_plane->plane = vkms_plane_init(vkmsdev, config_plane); @@ -53,10 +45,30 @@ int vkms_output_init(struct vkms_device *vkmsdev) ret = PTR_ERR(config_plane->plane); return ret; } - if (config_plane->type == DRM_PLANE_TYPE_PRIMARY) - primary = config_plane->plane; - else if (config_plane->type == DRM_PLANE_TYPE_CURSOR) - cursor = config_plane->plane; + } + + list_for_each_entry(config_crtc, &vkmsdev->config->crtcs, link) { + struct drm_plane *primary = NULL, *cursor = NULL; + + xa_for_each(&config_crtc->possible_planes, idx, config_plane) { + if (config_plane->type == DRM_PLANE_TYPE_PRIMARY) + primary = &config_plane->plane->base; + else if (config_plane->type == DRM_PLANE_TYPE_CURSOR) + cursor = &config_plane->plane->base; + } + + config_crtc->output = vkms_crtc_init(vkmsdev, primary, cursor, config_crtc); + + if (IS_ERR(config_crtc->output)) { + ret = PTR_ERR(config_crtc->output); + return ret; + } + } + + list_for_each_entry(config_crtc, &vkmsdev->config->crtcs, link) { + xa_for_each(&config_crtc->possible_planes, idx, config_plane) { + config_plane->plane->base.possible_crtcs |= drm_crtc_mask(&config_crtc->output->crtc); + } } connector = drmm_kzalloc(dev, sizeof(*connector), GFP_KERNEL); @@ -74,31 +86,25 @@ int vkms_output_init(struct vkms_device *vkmsdev) drm_connector_helper_add(connector, &vkms_conn_helper_funcs); - 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; - } - encoder->possible_crtcs = drm_crtc_mask(&output->crtc); - - /* Attach the encoder and the connector */ - ret = drm_connector_attach_encoder(connector, encoder); - if (ret) { - DRM_ERROR("Failed to attach connector to encoder\n"); - return ret; - } - - /* Initialize the writeback component */ - if (vkmsdev->config->writeback) { - writeback = vkms_enable_writeback_connector(vkmsdev, output); - if (writeback) - DRM_ERROR("Failed to init writeback connector\n"); + list_for_each_entry(config_encoder, &vkmsdev->config->encoders, link) { + config_encoder->encoder = drmm_kzalloc(dev, sizeof(*config_encoder->encoder), + GFP_KERNEL); + if (!config_encoder->encoder) + return -ENOMEM; + ret = drmm_encoder_init(dev, config_encoder->encoder, NULL, + DRM_MODE_ENCODER_VIRTUAL, NULL); + if (ret) { + DRM_ERROR("Failed to init encoder\n"); + return ret; + } + xa_for_each(&config_encoder->possible_crtcs, idx, config_crtc) { + config_encoder->encoder->possible_crtcs |= drm_crtc_mask(&config_crtc->output->crtc); + } + if (IS_ERR(config_encoder->encoder)) + return PTR_ERR(config_encoder->encoder); + ret = drm_connector_attach_encoder(connector, config_encoder->encoder); + if (ret) + return ret; } drm_mode_config_reset(dev); From patchwork Tue Jan 21 10:55:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946167 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 DB0B0C02182 for ; Tue, 21 Jan 2025 10:55:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 614B310E56A; Tue, 21 Jan 2025 10:55:46 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="NIgS5wJf"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id EE0A810E562 for ; Tue, 21 Jan 2025 10:55:42 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 0A6024000C; Tue, 21 Jan 2025 10:55:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456941; 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=hpHf/dwE0ZFFls51Bfsr0/QR2MdI2uzLK7K8SI5Chk0=; b=NIgS5wJf8+4ka0S7w5XSrbZf+5/e8dD+ZmeVw/4Ofz5Fq8AE3MB22jsRb6gmxCzstYj5Tu /og+wJSfUwGCn91NZHF+M6vMobtV+V0oQW/WxWZzXrx/ii1qr3s57mTlculvHfOtPvvvsT qEhrNHECXiCxLXG+IVKGraFyriO9BGmJ6X1sp7fTLIzF7ibHj5yYm6RjqJ0lC+ahTNfxPw LTxHfiJoC9s1PZVJGmkUhQr3/SRc7dsb1rIARhpp3gdKhfRca7DWThFHg12D4nPuNeO6Ws z8sLBDiTsT6G/vh6681TptM/Hzf1xC8WAPFyqbD3vGR1rNBNzQ6UXzVAkeOhqw== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:32 +0100 Subject: [PATCH v3 08/16] drm/vkms: Introduce config for encoder name MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-8-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3130; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=hBqs3tcNYjsGtdjYrUbEjbluYX3zYTivRwT1laGCLWs=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30iwWiCWpiA7IotEeVHBG+4ErUzPTXa0GFOI vDNbU5XmFCJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499IgAKCRAgrS7GWxAs 4nZyD/0fD///+Rp86wfp90OOJwepFumkX6T0mcTez8UYlyxQBCjLDImP12ivDJJIBz5omzKk1G2 MOdgl388XUkKm2k1qINmZic8rDb9pCsua/Gm7Hs6k+Hcjt452wgAd9aZcN/sMmhgCI+R+u+rBqZ LYydIDbZHhu+drz1OZiioe/ZpIXY1RKpEXLy4+5x0hIIwUhiOChcES0ye16uhu3kSSaj9aInssl fb/e93+Nx/wvNEgB4/mrIixMOAcNkt95kc8GUHJv0afro1mcxHQazcHFHa09mEud/LIe9rTzs6e JLnf+l715rtmYs/ZYWiMNPSXG0GPqN4DSnGIfuf0T3gv+e+Is7arXz95zpnApIneu6gudm5GEVn jRjkGn28mVwGnAUfuZnE3qKMjsMAdumRbJy+XHntGrV1bcJSQXBV8akDnvOha0JYrDGnm4tNko4 pFrtshAOnSNSQAbrJxz2ViMP+/OHeLw4v388aBB5EAn7cyL2SWieTKLEtnXGVGAisArg1jk+mmm XXCvJhRgZj/nSO/+oar262oF5nsNF0eS3Cdj4cU5ONFL+d/LzlEDPQl30zMrh82ciz33r17mxcL F/cLUBxke3ZipYKdBEr/yQmq6bFqhJmwqQ5EnB5kiva9NSPjCBn3B2n3OpmR4sk+9Q6aNs7Abg3 sfy2xdWhQZKUBjg== 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" As an encoder will be a directory in ConfigFS, add the configuration for encoder name so we will be able to reflect the configfs directory name in the drm name. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 6 ++++++ drivers/gpu/drm/vkms/vkms_config.h | 2 ++ drivers/gpu/drm/vkms/vkms_output.c | 2 +- 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index 314d252aa9b6ed1772c8ef597bd9c6b08145723e..8c88af745eb208a52f58fbf5def3f16c29d31063 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -41,6 +41,10 @@ struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable encoder = vkms_config_create_encoder(vkms_config); if (!encoder) goto err_alloc; + encoder->name = kzalloc(sizeof("Main Encoder"), GFP_KERNEL); + if (!encoder->name) + goto err_alloc; + sprintf(encoder->name, "Main Encoder"); if (vkms_config_encoder_attach_crtc(encoder, crtc)) goto err_alloc; @@ -231,6 +235,7 @@ void vkms_config_delete_encoder(struct vkms_config_encoder *vkms_config_encoder, } } + kfree(vkms_config_encoder->name); kfree(vkms_config_encoder); } @@ -376,6 +381,7 @@ static int vkms_config_show(struct seq_file *m, void *data) list_for_each_entry(config_encoder, &vkmsdev->config->encoders, link) { seq_puts(m, "encoder:\n"); + seq_printf(m, "\tname: %s\n", config_encoder->name); } list_for_each_entry(config_crtc, &vkmsdev->config->crtcs, link) { diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index 90ced83f5eb6dae5ccc14c37169606d833ba355a..874d631f8895c47eca6eba8bfe20b56b88966b67 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -50,6 +50,7 @@ struct vkms_config_crtc { * struct vkms_config_encoder * * @link: Link to the others encoders + * @name: Name of the encoder * @possible_crtcs: List of CRTC 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 @@ -58,6 +59,7 @@ struct vkms_config_crtc { struct vkms_config_encoder { struct list_head link; + char *name; struct xarray possible_crtcs; /* Internal usage */ diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index dab949c983a5991696baf937f948c0f78710d6e1..fd641fa750f20b1a95994acc2778a74942125fd9 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -92,7 +92,7 @@ int vkms_output_init(struct vkms_device *vkmsdev) if (!config_encoder->encoder) return -ENOMEM; ret = drmm_encoder_init(dev, config_encoder->encoder, NULL, - DRM_MODE_ENCODER_VIRTUAL, NULL); + DRM_MODE_ENCODER_VIRTUAL, config_encoder->name); if (ret) { DRM_ERROR("Failed to init encoder\n"); return ret; From patchwork Tue Jan 21 10:55:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946165 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 0999BC0218C for ; Tue, 21 Jan 2025 10:55:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E05EC10E56D; Tue, 21 Jan 2025 10:55:45 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="AhIakmnX"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id C82E510E562 for ; Tue, 21 Jan 2025 10:55:43 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id D345940015; Tue, 21 Jan 2025 10:55:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456942; 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=roVOu8bJHELSDbob9WYzi+I7LS1qlkprNDsb4qlKyIY=; b=AhIakmnXB1WOqDAMQyJoe1hMJlH8SiICaY44XPzgkE73SwmGAIxLR+4ChfWxryOKu5rSkx 4JJiI35Ewct1JWJ8yuaDu5nuCYtaWVWO2UrvPWTVcaPFXxshrECWcGVjyip1kY07cTriAC JgUnHyLFd/MM1bAbbg+T7up4hYPQemd6nSlbX2DibtaP0XDBqWHEW6dzCErO3JW7qQQ4Kf exdBL5pKVGNTdBlPy3Aw+PNNUX24DcGHLHVyphpUw3/t8fkMTGn+NVVboN/mCY5sQ42tJp /GBvAQgr+zZ3svxI/LQU0sFrZME8rnA9TcRI4044eP9d28+VP+Ml1C5nahPYoQ== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:33 +0100 Subject: [PATCH v3 09/16] drm/vkms: Introduce config for CRTC name MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-9-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2746; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=Hg4byqydaR4gdFBvGZisOfOByyHA174ZUU2M0mdzfJw=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30i31CkbGfjxau+9M889MNtvUJXe7xDQGf4o XQnWurJg8WJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499IgAKCRAgrS7GWxAs 4gJrEACsppOUxfTK8hg17CsbWctsIaeO8/PnXZR181531IGwLYVm4vPQD2I6oHQcpbV9e9013rs tu2FGk7Yoe1blGvIP5DuTiibhJXjwVBfDDMEhGriwULMAyIMbKqUZD1jeQ9RD85J/Was3zjGRKz qQoclRjgNrVMxHqatnzu16kENTGv5HZ5oWNQvDq9EATpxwnTfNHG4UY6U2oMGdxG4KHg5O2rW4b c7RlCoIRY++Uzf/+AS6gLMWPMyjJ1iK1UradMar5uJuteI0XjEHpqgjdM+73iUWM3QIiUbqOZEX VsZ/XOkrX22V8Dj6sBFEl9PyzuomBwx/z2AzlUGPFWRk/wOJwel/7iXt2QcT3LExqJVMOSSeDgk sFReXlxa2n233sS6bqoRBiKnbnNsmvqj86Z2j6dSnzhR1EN4b1WizxkfazfD2d/CpPd7GLhYhjN 7qk47yUSLA46Cz7JV3BmKZlczp4Ckeb+qn9s40nc5g76tK2KSLjX/uqgLcCNW7+H0CewJPXPDx0 lVFkNlAYSNVkgCBjEb2SfQwKr87CmFdBpYwr9Re7sqFfQCa84WCuzmm+mkL98prRRkMnWrh6eoB Pvr603cMyuIa1Bmq+OyPVN6dPKEZ099mxblcRRoVY1H8sanvBzMEGQo2FOINQmK7BUJKi2Nh+5R RA1wjx0yU9VHw6w== 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" As a CRTC will be a directory in ConfigFS, add the name configuration for CRTC name so we will be able to reflect the configfs directory name in the drm name. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 5 +++++ drivers/gpu/drm/vkms/vkms_config.h | 2 ++ drivers/gpu/drm/vkms/vkms_crtc.c | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index 8c88af745eb208a52f58fbf5def3f16c29d31063..b610d37b675efaea7ca717f08e525beaf18d8d9e 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -37,6 +37,10 @@ struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable if (!crtc) goto err_alloc; crtc->writeback = enable_writeback; + crtc->name = kzalloc(sizeof("Main CRTC"), GFP_KERNEL); + if (!crtc->name) + goto err_alloc; + sprintf(crtc->name, "Main CRTC"); encoder = vkms_config_create_encoder(vkms_config); if (!encoder) @@ -212,6 +216,7 @@ void vkms_config_delete_crtc(struct vkms_config_crtc *vkms_config_crtc, } } + kfree(vkms_config_crtc->name); kfree(vkms_config_crtc); } diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index 874d631f8895c47eca6eba8bfe20b56b88966b67..efe984113fb664ff38a68b3be90063c366bb2892 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -29,6 +29,7 @@ struct vkms_config { * struct vkms_config_crtc * * @link: Link to the others CRTCs + * @name: Name of the CRTC * @possible_planes: List of planes that can be used with this CRTC * @possible_encoders: List of encoders that can be used with this CRTC * @crtc: Internal usage. This pointer should never be considered as valid. It can be used to @@ -38,6 +39,7 @@ struct vkms_config { struct vkms_config_crtc { struct list_head link; + char *name; bool writeback; struct xarray possible_planes; struct xarray possible_encoders; diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index f4da196fd7774ee1dcc5148e6420186f1384b3fa..0c795de19db5359f968cb0c0a396626deb3f8e27 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -282,7 +282,7 @@ struct vkms_output *vkms_crtc_init(struct vkms_device *vkms_device, vkms_out = drmm_crtc_alloc_with_planes(dev, struct vkms_output, crtc, primary, cursor, - &vkms_crtc_funcs, NULL); + &vkms_crtc_funcs, config->name); if (IS_ERR(vkms_out)) { DRM_DEV_ERROR(dev->dev, "Failed to init CRTC\n"); return vkms_out; From patchwork Tue Jan 21 10:55:34 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946173 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 2237FC0218D for ; Tue, 21 Jan 2025 10:55:58 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3EF0610E568; Tue, 21 Jan 2025 10:55:55 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="JUyIfvh0"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::222]) by gabe.freedesktop.org (Postfix) with ESMTPS id A9D2C10E564 for ; Tue, 21 Jan 2025 10:55:44 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id AB25440017; Tue, 21 Jan 2025 10:55:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456943; 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=pyoz6hGAiMXFfiBD2XG/lRALUOk86qPhSdruGkc+xRY=; b=JUyIfvh0nvn/aj8byXQJUYYj/x1+eLENlzwYKfWJQf1lB4waOxhzFSRm+sbJQBbGKqWJdu FUHel23dlpdnjk56WAaapODry/vy8i5+TdEKo0og1VVffjQMXPMNt2hwwm6dVk4ou7KQC9 9rBgiTOXsI9+Ppo1zlar4jjo7A3F8DBf4PdBUWzQwKoPmwWF2f2K65WSDBipoy+CPSu7zv To5kgjD2A4Qv/jdHmdJQu9gxVYxu8FmlhAsQQcTTGYHXp9FhCDEDnq01n0eYAXiwhCxPoZ Gc3YKa1Z9+Hl0/9brllmuTIGm92ggQ3AMESTcUs6TzexMdAZL/1TNfxg7qXB6g== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:34 +0100 Subject: [PATCH v3 10/16] drm/vkms: Add test for config structure MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-10-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=7076; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=TdAiaY7K4To7ayPwrxgH2o4ItNXyv04HwPf+t0hDlXQ=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30je8wQP1UMU1zQ0+mMW3sui59CBDtI5FAeb JOM9mVrelWJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499IwAKCRAgrS7GWxAs 4uwYD/9I3wgiqhK37VvX20c28qoVmmFQ5I6h07ZoZqBqLp9vSsTe6wDM1xpHY9EXF7AgO5MuCAZ WwVpA9O4n3fkEyzddS7j8A57yNkNqEG72ouafiFBdNTQhuoNNoBfFYAtDJsVL6NPtSjIbNrY4xu tZx1JoeXdWkYgpL+ginfuS2g7qCGys/Nx8B3fsiFJOZ+3YCGV43SloMdafZd/+o/cZoQk/g5AIU LfZtwj1aE+dGOMpob5Eey70NspNzpYWeZz+ET8YP2d7Gt/A6HZDpBaZCc/V1zMXIMsiPW4sO6DN 9d1ARtv6pyw4g4PTf9vE/pRif2LImT73U9KSU4z1WazuNVBCvBUlU2jDfLinNLPYgyVP6NijKu9 ZLRuhEcTSObBvUPOnJKXSaMWCRii8iT0EMXTbZEJcAem1LOH/+m4/fVXigsOml30wSKk5jojwZ9 D2K+pTxvzlJFQFNhLV/s8LpjXpgjksFsZSYokSnCK1Srhva+dgKhAsqHxkj0gAHxZBW6ernRZdd iUVjM5EZUAdykDuis3IFT6VWOiE4egg7f+N/jhMPkTh0MOzue/OOvI2Lv0DN5sf8ez6AyJmPa5j e1WU0vMbgF7UtGLCxBxv++dlepjwlpxKY1DkJO/qiozMsJHKVKrTqzJPVV3uAkYtQzcZE43BR7I 2eG8ekubFXKEPXA== 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" The config structure is a bit complex in term of memory management. Add basic test to avoid breaking it in the future. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/tests/Makefile | 3 + drivers/gpu/drm/vkms/tests/vkms_config_test.c | 137 ++++++++++++++++++++++++++ 2 files changed, 140 insertions(+) diff --git a/drivers/gpu/drm/vkms/tests/Makefile b/drivers/gpu/drm/vkms/tests/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..b78371d08aa9531a5151225cc33e34452225832c --- /dev/null +++ b/drivers/gpu/drm/vkms/tests/Makefile @@ -0,0 +1,3 @@ +# SPDX-License-Identifier: GPL-2.0-only + +obj-$(CONFIG_DRM_VKMS_KUNIT_TESTS) += vkms_config_test.o diff --git a/drivers/gpu/drm/vkms/tests/vkms_config_test.c b/drivers/gpu/drm/vkms/tests/vkms_config_test.c new file mode 100644 index 0000000000000000000000000000000000000000..f7a2b8ecd4e1f791e9abc86659ef459e3ea8be43 --- /dev/null +++ b/drivers/gpu/drm/vkms/tests/vkms_config_test.c @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include + +#include "../vkms_config.h" + +MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING"); + +static void vkms_config_test_basic_allocation(struct kunit *test) +{ + struct vkms_config *config = vkms_config_create(); + + KUNIT_EXPECT_TRUE_MSG(test, list_empty(&config->encoders), + "Encoder list is not empty after allocation"); + KUNIT_EXPECT_TRUE_MSG(test, list_empty(&config->crtcs), + "CRTC list is not empty after allocation"); + KUNIT_EXPECT_TRUE_MSG(test, list_empty(&config->planes), + "Plane list is not empty after allocation"); + + vkms_config_destroy(config); +} + +static void vkms_config_test_simple_config(struct kunit *test) +{ + struct vkms_config *config = vkms_config_create(); + + struct vkms_config_plane *plane_1 = vkms_config_create_plane(config); + struct vkms_config_plane *plane_2 = vkms_config_create_plane(config); + struct vkms_config_crtc *crtc = vkms_config_create_crtc(config); + struct vkms_config_encoder *encoder = vkms_config_create_encoder(config); + + KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config)); + KUNIT_EXPECT_EQ(test, list_count_nodes(&config->planes), 2); + KUNIT_EXPECT_EQ(test, list_count_nodes(&config->crtcs), 1); + KUNIT_EXPECT_EQ(test, list_count_nodes(&config->encoders), 1); + + plane_1->type = DRM_PLANE_TYPE_PRIMARY; + plane_2->type = DRM_PLANE_TYPE_CURSOR; + + KUNIT_EXPECT_EQ(test, vkms_config_plane_attach_crtc(plane_1, crtc), 0); + KUNIT_EXPECT_EQ(test, vkms_config_plane_attach_crtc(plane_2, crtc), 0); + KUNIT_EXPECT_EQ(test, vkms_config_encoder_attach_crtc(encoder, crtc), 0); + + KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config)); + + vkms_config_delete_plane(plane_1, config); + KUNIT_EXPECT_EQ(test, list_count_nodes(&config->planes), 1); + KUNIT_EXPECT_EQ(test, list_count_nodes(&config->crtcs), 1); + KUNIT_EXPECT_EQ(test, list_count_nodes(&config->encoders), 1); + + KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config)); + + plane_2->type = DRM_PLANE_TYPE_PRIMARY; + + KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config)); + + vkms_config_destroy(config); +} + +static void vkms_config_test_complex_config(struct kunit *test) +{ + struct vkms_config *config = vkms_config_create(); + + struct vkms_config_plane *plane_1 = vkms_config_create_plane(config); + struct vkms_config_plane *plane_2 = vkms_config_create_plane(config); + struct vkms_config_plane *plane_3 = vkms_config_create_plane(config); + struct vkms_config_plane *plane_4 = vkms_config_create_plane(config); + struct vkms_config_plane *plane_5 = vkms_config_create_plane(config); + struct vkms_config_plane *plane_6 = vkms_config_create_plane(config); + struct vkms_config_plane *plane_7 = vkms_config_create_plane(config); + struct vkms_config_plane *plane_8 = vkms_config_create_plane(config); + struct vkms_config_crtc *crtc_1 = vkms_config_create_crtc(config); + struct vkms_config_crtc *crtc_2 = vkms_config_create_crtc(config); + struct vkms_config_encoder *encoder_1 = vkms_config_create_encoder(config); + struct vkms_config_encoder *encoder_2 = vkms_config_create_encoder(config); + struct vkms_config_encoder *encoder_3 = vkms_config_create_encoder(config); + struct vkms_config_encoder *encoder_4 = vkms_config_create_encoder(config); + + KUNIT_EXPECT_FALSE(test, vkms_config_is_valid(config)); + KUNIT_EXPECT_EQ(test, list_count_nodes(&config->planes), 8); + KUNIT_EXPECT_EQ(test, list_count_nodes(&config->crtcs), 2); + KUNIT_EXPECT_EQ(test, list_count_nodes(&config->encoders), 4); + + plane_1->type = DRM_PLANE_TYPE_PRIMARY; + plane_2->type = DRM_PLANE_TYPE_CURSOR; + plane_3->type = DRM_PLANE_TYPE_OVERLAY; + plane_4->type = DRM_PLANE_TYPE_OVERLAY; + plane_5->type = DRM_PLANE_TYPE_PRIMARY; + plane_6->type = DRM_PLANE_TYPE_CURSOR; + plane_7->type = DRM_PLANE_TYPE_OVERLAY; + plane_8->type = DRM_PLANE_TYPE_OVERLAY; + + KUNIT_EXPECT_EQ(test, vkms_config_plane_attach_crtc(plane_1, crtc_1), 0); + KUNIT_EXPECT_EQ(test, vkms_config_plane_attach_crtc(plane_2, crtc_1), 0); + KUNIT_EXPECT_EQ(test, vkms_config_plane_attach_crtc(plane_3, crtc_1), 0); + KUNIT_EXPECT_EQ(test, vkms_config_plane_attach_crtc(plane_4, crtc_1), 0); + KUNIT_EXPECT_EQ(test, vkms_config_plane_attach_crtc(plane_5, crtc_2), 0); + KUNIT_EXPECT_EQ(test, vkms_config_plane_attach_crtc(plane_6, crtc_2), 0); + KUNIT_EXPECT_EQ(test, vkms_config_plane_attach_crtc(plane_7, crtc_2), 0); + KUNIT_EXPECT_EQ(test, vkms_config_plane_attach_crtc(plane_8, crtc_2), 0); + KUNIT_EXPECT_EQ(test, vkms_config_plane_attach_crtc(plane_3, crtc_2), 0); + KUNIT_EXPECT_EQ(test, vkms_config_plane_attach_crtc(plane_4, crtc_2), 0); + + KUNIT_EXPECT_EQ(test, vkms_config_encoder_attach_crtc(encoder_1, crtc_1), 0); + KUNIT_EXPECT_EQ(test, vkms_config_encoder_attach_crtc(encoder_2, crtc_1), 0); + KUNIT_EXPECT_EQ(test, vkms_config_encoder_attach_crtc(encoder_3, crtc_1), 0); + KUNIT_EXPECT_EQ(test, vkms_config_encoder_attach_crtc(encoder_3, crtc_2), 0); + KUNIT_EXPECT_EQ(test, vkms_config_encoder_attach_crtc(encoder_4, crtc_2), 0); + + KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config)); + + vkms_config_delete_plane(plane_4, config); + KUNIT_EXPECT_EQ(test, list_count_nodes(&config->planes), 7); + KUNIT_EXPECT_EQ(test, list_count_nodes(&config->crtcs), 2); + KUNIT_EXPECT_EQ(test, list_count_nodes(&config->encoders), 4); + + KUNIT_EXPECT_TRUE(test, vkms_config_is_valid(config)); + + vkms_config_destroy(config); +} + +static struct kunit_case vkms_config_test_cases[] = { + KUNIT_CASE(vkms_config_test_basic_allocation), + KUNIT_CASE(vkms_config_test_simple_config), + KUNIT_CASE(vkms_config_test_complex_config), + {} +}; + +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"); From patchwork Tue Jan 21 10:55:35 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946171 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 995A8C0218E for ; Tue, 21 Jan 2025 10:55:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C5B7B10E56E; Tue, 21 Jan 2025 10:55:54 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="lFRaJ9Om"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7D30810E56A for ; Tue, 21 Jan 2025 10:55:45 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 7CB5C4001C; Tue, 21 Jan 2025 10:55:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456944; 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=du+BQI+l9q7ygbfpvfGPCKoCBhL48XqdxVvlgJEXA80=; b=lFRaJ9OmVqgzWR+TKy7yM+pSo8kANhNUvGxkuNojaaHdAJcD3+lAUXGIXwnLRlx25yTIf1 9NJrXxeUT53c7olDlIL26XGLaEj9ly10nRM+l4tSkwte5nICzygUxuKKUqVXALv2XHE8rB niN7wMyBfY4YT8/+E/VsrRf1/bgukAIW0Br7qTSiz9wgYX9Rq7puAFVABP5o+PPHWoTNwa YVsd79mPhpcLMCtxRZ29KOS0E4KmIbJhbz0VMCkYp3YWkhaLNZDNxTYgvInt4xFAsSOjDL JFN7oiBTf2V8qPbqCGXcdosKMYrNF7dEmVZl8UyxfrgByF25qlLTRU4g+kaPLg== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:35 +0100 Subject: [PATCH v3 11/16] drm/vkms: Introduce config for connector MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-11-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=10467; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=Ec8VCg8FajLht2MC2ecamJeS/m6TZJ/YugMNGs3Cd4w=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30j0jvVviskv8VOH+Q307axMxuYyabot0AB2 YyijR7PMryJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499IwAKCRAgrS7GWxAs 4jPrEACm/H9Cqh6QXJPrs6l8M7k0PerzMmLj+TfGxRTMBnmlhI6ES3clRvQRT4AJATsPiPtu8x4 fqkBSL0dBwG2tK72RsbowKE5pHbqGzu15BpHWg05P1lYOGL0ZUmbsyXDHL/qaWT1bo3lqm1+My8 BaS1i2+htuyXII5/Y2nRHQ6OkxT1Rp4yO3dBDlWHjpogJbJECW9nF/4MN6ZrFwSs7XrKjCcJAuq UHmyi/gESce31sfHkqvoab2dP2Q07wc9N+GcCF3FJuzBT28dIBcCQNT6mDFgC1uEuZDlQ4/YKm/ VWxnm9LkIgqsfrOPqmQf8eU7m+MC+0NNBXLg7X+RN1Jv5bGCoZzelWiqCbthFi8LPazN++Yk+JI jcpXv+KNva8jAHnEoNmf9T9QESq8GoTBJnt2wilBok3gXaq4wJ40lGBCkREE7gwlm39n/MEjFYH WXrB+ytfTyojJDSwp8SlLQtufNDvpCzyBMyXp4DUP8niKMvp5du12H+OZH1hpB/nNJUQWhQT12H dFlYpl9xuqbzEbgUqSi8kNtkG4YiMg2dXLa2+/Ce7AkzHQJzTaLWRtE1D9KBUqGNiWnFtzY17Rz yZSBQ22d/ZBTeJc3KNbtuKtOIMsKgIZ6MtuwTT+lWMBMvgwN0ZSRA67FA+fEeTT2tBV/CTrvLK1 0CqLIGUWsgvqhng== 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" The current vkms driver only allows the usage of one connector, possibly with a writeback connector. This new configuration structure aims to make the configuration more flexible. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 62 +++++++++++++++++++++++++++++++++++++- drivers/gpu/drm/vkms/vkms_config.h | 18 +++++++++-- drivers/gpu/drm/vkms/vkms_drv.c | 2 +- drivers/gpu/drm/vkms/vkms_output.c | 37 ++++++++++++----------- 4 files changed, 98 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index b610d37b675efaea7ca717f08e525beaf18d8d9e..f1f02c66755f9660b48dfa5cb786afa1e6ae553b 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -17,6 +17,7 @@ struct vkms_config *vkms_config_create(void) INIT_LIST_HEAD(&config->planes); INIT_LIST_HEAD(&config->crtcs); INIT_LIST_HEAD(&config->encoders); + INIT_LIST_HEAD(&config->connectors); return config; } @@ -28,6 +29,7 @@ struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable struct vkms_config_plane *plane; struct vkms_config_encoder *encoder; struct vkms_config_crtc *crtc; + struct vkms_config_connector *connector; struct vkms_config *vkms_config = vkms_config_create(); if (IS_ERR(vkms_config)) @@ -53,6 +55,12 @@ struct vkms_config *vkms_config_alloc_default(bool enable_writeback, bool enable if (vkms_config_encoder_attach_crtc(encoder, crtc)) goto err_alloc; + connector = vkms_config_create_connector(vkms_config); + if (!connector) + goto err_alloc; + if (vkms_config_connector_attach_encoder(connector, encoder)) + goto err_alloc; + plane = vkms_config_create_plane(vkms_config); if (!plane) goto err_alloc; @@ -123,6 +131,23 @@ struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *vkms_conf } EXPORT_SYMBOL_IF_KUNIT(vkms_config_create_plane); +struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *vkms_config) +{ + if (!vkms_config) + return NULL; + + struct vkms_config_connector *vkms_config_connector = + kzalloc(sizeof(*vkms_config_connector), GFP_KERNEL); + + if (!vkms_config_connector) + return NULL; + + list_add(&vkms_config_connector->link, &vkms_config->connectors); + xa_init_flags(&vkms_config_connector->possible_encoders, XA_FLAGS_ALLOC); + + return vkms_config_connector; +} + struct vkms_config_crtc *vkms_config_create_crtc(struct vkms_config *vkms_config) { if (!vkms_config) @@ -220,6 +245,15 @@ void vkms_config_delete_crtc(struct vkms_config_crtc *vkms_config_crtc, kfree(vkms_config_crtc); } +void vkms_config_delete_connector(struct vkms_config_connector *vkms_config_conector) +{ + if (!vkms_config_conector) + return; + list_del(&vkms_config_conector->link); + + kfree(vkms_config_conector); +} + void vkms_config_delete_encoder(struct vkms_config_encoder *vkms_config_encoder, struct vkms_config *vkms_config) { @@ -240,6 +274,17 @@ void vkms_config_delete_encoder(struct vkms_config_encoder *vkms_config_encoder, } } + struct vkms_config_connector *connector_config; + + list_for_each_entry(connector_config, &vkms_config->connectors, link) { + unsigned long idx = 0; + + xa_for_each(&connector_config->possible_encoders, idx, encoder) { + if (encoder == vkms_config_encoder) + xa_erase(&connector_config->possible_encoders, idx); + } + } + kfree(vkms_config_encoder->name); kfree(vkms_config_encoder); } @@ -249,7 +294,7 @@ void vkms_config_destroy(struct vkms_config *config) struct vkms_config_plane *vkms_config_plane, *tmp_plane; struct vkms_config_encoder *vkms_config_encoder, *tmp_encoder; struct vkms_config_crtc *vkms_config_crtc, *tmp_crtc; - + struct vkms_config_connector *vkms_config_connector, *tmp_connector; list_for_each_entry_safe(vkms_config_plane, tmp_plane, &config->planes, link) { vkms_config_delete_plane(vkms_config_plane, config); } @@ -259,6 +304,9 @@ void vkms_config_destroy(struct vkms_config *config) list_for_each_entry_safe(vkms_config_crtc, tmp_crtc, &config->crtcs, link) { vkms_config_delete_crtc(vkms_config_crtc, config); } + list_for_each_entry_safe(vkms_config_connector, tmp_connector, &config->connectors, link) { + vkms_config_delete_connector(vkms_config_connector); + } kfree(config); } @@ -308,6 +356,18 @@ int __must_check vkms_config_encoder_attach_crtc(struct vkms_config_encoder *vkm } EXPORT_SYMBOL_IF_KUNIT(vkms_config_encoder_attach_crtc); +int __must_check +vkms_config_connector_attach_encoder(struct vkms_config_connector *vkms_config_connector, + struct vkms_config_encoder *vkms_config_encoder) +{ + u32 encoder_idx; + int ret; + + ret = xa_alloc(&vkms_config_connector->possible_encoders, &encoder_idx, vkms_config_encoder, + xa_limit_32b, GFP_KERNEL); + return ret; +} + bool vkms_config_is_valid(struct vkms_config *config) { struct vkms_config_plane *config_plane; diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index efe984113fb664ff38a68b3be90063c366bb2892..584d015d6b8f420d82b2cfe38c991e93ad8288f3 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -23,6 +23,7 @@ struct vkms_config { struct list_head planes; struct list_head crtcs; struct list_head encoders; + struct list_head connectors; }; /** @@ -95,6 +96,15 @@ struct vkms_config_plane { struct vkms_plane *plane; }; +struct vkms_config_connector { + struct list_head link; + + struct xarray possible_encoders; + + /* Internal usage */ + struct drm_connector *connector; +}; + /** * vkms_config_register_debugfs() - Register the debugfs file to display current configuration */ @@ -125,6 +135,8 @@ bool vkms_config_is_valid(struct vkms_config *vkms_config); */ struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *vkms_config); +struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *vkms_config); + /** * vkms_config_create_crtc() - Create a crtc configuration * @@ -145,7 +157,9 @@ int __must_check vkms_config_plane_attach_crtc(struct vkms_config_plane *vkms_co struct vkms_config_crtc *vkms_config_crtc); int __must_check vkms_config_encoder_attach_crtc(struct vkms_config_encoder *vkms_config_encoder, struct vkms_config_crtc *vkms_config_crtc); - +int __must_check +vkms_config_connector_attach_encoder(struct vkms_config_connector *vkms_config_connector, + struct vkms_config_encoder *vkms_config_encoder); /** * vkms_config_delete_plane() - Remove a plane configuration and frees its memory * @@ -182,7 +196,7 @@ void vkms_config_delete_crtc(struct vkms_config_crtc *vkms_config_crtc, */ void vkms_config_delete_encoder(struct vkms_config_encoder *vkms_config_encoder, struct vkms_config *vkms_config); - +void vkms_config_delete_connector(struct vkms_config_connector *vkms_config_conector); /** * vkms_config_alloc_default() - Allocate the configuration for the default device * @enable_writeback: Enable the writeback connector for this configuration diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 4440549c3084a341d03ec66119ba7998012bd662..95fde2fbd711fe52a3a3b5a55778f5bc2029beb7 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -183,7 +183,7 @@ 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, list_count_nodes(&config->crtcs)); if (ret) { DRM_ERROR("Failed to vblank\n"); goto out_devres; diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index fd641fa750f20b1a95994acc2778a74942125fd9..146ce254a027c662ae275dd2ec0024a46fa8119d 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -35,7 +35,7 @@ int vkms_output_init(struct vkms_device *vkmsdev) struct drm_device *dev = &vkmsdev->drm; struct vkms_config_plane *config_plane; struct vkms_config_crtc *config_crtc; - struct drm_connector *connector; + struct vkms_config_connector *config_connector; unsigned long idx; int ret; @@ -71,21 +71,6 @@ int vkms_output_init(struct vkms_device *vkmsdev) } } - connector = drmm_kzalloc(dev, sizeof(*connector), GFP_KERNEL); - if (!connector) { - DRM_ERROR("Failed to allocate connector\n"); - return -ENOMEM; - } - - ret = drmm_connector_init(dev, connector, &vkms_connector_funcs, - DRM_MODE_CONNECTOR_VIRTUAL, NULL); - if (ret) { - DRM_ERROR("Failed to init connector\n"); - return ret; - } - - drm_connector_helper_add(connector, &vkms_conn_helper_funcs); - list_for_each_entry(config_encoder, &vkmsdev->config->encoders, link) { config_encoder->encoder = drmm_kzalloc(dev, sizeof(*config_encoder->encoder), GFP_KERNEL); @@ -97,14 +82,32 @@ int vkms_output_init(struct vkms_device *vkmsdev) DRM_ERROR("Failed to init encoder\n"); return ret; } + xa_for_each(&config_encoder->possible_crtcs, idx, config_crtc) { config_encoder->encoder->possible_crtcs |= drm_crtc_mask(&config_crtc->output->crtc); } if (IS_ERR(config_encoder->encoder)) return PTR_ERR(config_encoder->encoder); - ret = drm_connector_attach_encoder(connector, config_encoder->encoder); + } + + list_for_each_entry(config_connector, &vkmsdev->config->connectors, link) { + config_connector->connector = drmm_kzalloc(&vkmsdev->drm, + sizeof(*config_connector->connector), + GFP_KERNEL); + if (!config_connector->connector) + return -ENOMEM; + ret = drmm_connector_init(&vkmsdev->drm, config_connector->connector, + &vkms_connector_funcs, DRM_MODE_CONNECTOR_VIRTUAL, NULL); if (ret) return ret; + drm_connector_helper_add(config_connector->connector, &vkms_conn_helper_funcs); + + xa_for_each(&config_connector->possible_encoders, idx, config_encoder) { + ret = drm_connector_attach_encoder(config_connector->connector, + config_encoder->encoder); + if (ret) + return ret; + } } drm_mode_config_reset(dev); From patchwork Tue Jan 21 10:55:36 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946168 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 83CE1C0218B for ; Tue, 21 Jan 2025 10:55:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 05ECD10E570; Tue, 21 Jan 2025 10:55:54 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="UbOwfMjO"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::222]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7586710E569 for ; Tue, 21 Jan 2025 10:55:46 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 5FB5F4001B; Tue, 21 Jan 2025 10:55:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456945; 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=wA6XdpN3w5XidNwrdB+1bIHakVyQR6K7aeCy8o0KAhk=; b=UbOwfMjOj1H8WUJOX6Cchr+oRXVeraHWobWnsSJVI2IEYsxRo8PEr7iDfek+1n1zeRHehH DiY+Agg6Cz0aX+Som/ZabxIV354hk3OWanx1GZoxwLxhYA2tVX+xwaAluolESJaXyzajSJ hqbg9vynfUynFTVpq8SdbQV8P3svpEBSMQ7V8LN7rekLnddRf7h5HeurSDp/3Oc9Yw+KOn AFfV7lxjSIdUv/DGVvu9vJktg5GHFRU52cr8X8WnkCVn93rBf8/jASlIJTYfd0ByqVrk9p 1fl+QXXWC5XNfEYaeThfUNmcYMTpowcAGTChKGUSqWB/lO+IkaOOru2f0K+ycQ== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:36 +0100 Subject: [PATCH v3 12/16] drm/vkms: Introduce config for connector type MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-12-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2145; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=Fn4dj3/bZMFWIay4+pa2CTqCgY7/s9nwUyzsXJExpVw=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30juZQ5Qw22v5jOxelR1ueR3t+Hw7fFpXVhh bPvee+Ed3+JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499IwAKCRAgrS7GWxAs 4iLpEACYpTsZIhY6OljFqcgGCHhCJNW0jY7Ua7JNV91CEh8tc3cUKIHRxmRx4jUJb3BIScKEVLe ez8QxIOWhV6xFbyfTN0HzKebsPSbdAnuawMgZaRlCh7b8piQqNhUmCS5UtSfeBqBX0J+aRj5ejs Wpfe4JNP4OTDijmhYg1w9Oulwj4roTHdxSjR31QNf0O0TsA32n2Ov943u4mD05hjxXxmQBkbi50 1yRcfktW76NuHpCHHrecL6kVDshD3vRUqs7DZvEklRZ+ApgYXtnJpC2RCOTDgOvJon5ajvKbBjy UuAUEZZ3kgXDuIM9i/GBDlRATQwepdIibQtKghozeqXtmmIqtFMQPOvwInqGLHwBzpxOmkAfjr1 dttoOWvnZiKs3oafvmY8Bvaf/wyVu5KKTJajs1tgRqYI0wE8o2WvSMPR8jqSlWvuk3ihMQyxsD7 7PSjrLo7CkFdUHHbQMJ3UUu5qj7Q+n2/UC808WYjOkglzq1o4UXU+GP+cWW54EBL1nAerAThcY4 YnJO/clL+NQLl3NVtFUDrVpIw4ochEDD0KmIbNU4sIGtx6idctv8yUGfNWqyLQzKsQmsHd1S8yK FbvBcAQ3GIbzik8Zui+XjbOXxViXHt+xBbUr+7SayoiHMKj1pBd/6ErEMwVKAH9uws6rKUo1ZZJ fHm3lrPWiQNhkrg== 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 allow emulation of different kind of connector, make the connector type configurable. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 1 + drivers/gpu/drm/vkms/vkms_config.h | 1 + drivers/gpu/drm/vkms/vkms_output.c | 2 +- 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index f1f02c66755f9660b48dfa5cb786afa1e6ae553b..d2006d7b47f9cf21487659cc3eacb6272d1904b0 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -144,6 +144,7 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *v list_add(&vkms_config_connector->link, &vkms_config->connectors); xa_init_flags(&vkms_config_connector->possible_encoders, XA_FLAGS_ALLOC); + vkms_config_connector->type = DRM_MODE_CONNECTOR_VIRTUAL; return vkms_config_connector; } diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index 584d015d6b8f420d82b2cfe38c991e93ad8288f3..18b8978b7b7b58c45fcf11f7130883013e34d8ed 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -100,6 +100,7 @@ struct vkms_config_connector { struct list_head link; struct xarray possible_encoders; + int type; /* Internal usage */ struct drm_connector *connector; diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index 146ce254a027c662ae275dd2ec0024a46fa8119d..50aa802da479e5ba383e5db49dc2c7c6981f0bef 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -97,7 +97,7 @@ int vkms_output_init(struct vkms_device *vkmsdev) if (!config_connector->connector) return -ENOMEM; ret = drmm_connector_init(&vkmsdev->drm, config_connector->connector, - &vkms_connector_funcs, DRM_MODE_CONNECTOR_VIRTUAL, NULL); + &vkms_connector_funcs, config_connector->type, NULL); if (ret) return ret; drm_connector_helper_add(config_connector->connector, &vkms_conn_helper_funcs); From patchwork Tue Jan 21 10:55:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946175 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 25BEBC0218B for ; Tue, 21 Jan 2025 10:56:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9952810E579; Tue, 21 Jan 2025 10:56:07 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="S9ABhWYN"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4CEEB10E569 for ; Tue, 21 Jan 2025 10:55:47 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 4561D40014; Tue, 21 Jan 2025 10:55:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456946; 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=zrhjQpaQ55YrHpQkyvKf+ibT04fOK5Z827Lbs+9fVjk=; b=S9ABhWYNNUjp7F9oeqrd/YJrfO/rtyc6CuqVrMVdKx2g8U3MpI+5tKprgJTrVYt8jLxNyE iHALQhz/cW1TPSf/cjAHMlooUEU/Hpdg3HJUIq4Mw2SwRl/yTRA4FwsqfKcbz48nMCVEkP 3+URsT+dPQrWET3zPGzrYcgNferAwfiAHhCOi4opp5Yqny4YreJwcTIAA7SvX+RKUdM9+r 7O0NY4S8V1u4o9OFtO09fGRGQzxyF2Q3PHYJE06tuhsnmbV3YFUg9KbvrjDRZCikD4n3Mp mw1RL4tOsQ9XOm4XCUAwxBOnLLAnMi0Lt81E0iXFTX4+F/PXeJuTWq6hWB5qVg== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:37 +0100 Subject: [PATCH v3 13/16] drm/vkms: Introduce config for plane format MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-13-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=7086; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=h96AJuJMB79BMqsqKf6GU0WV5220NzQmB3PmvQBpvsc=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30kOUinOxpvtaAABqCz3/FHRvtsIgSbPkAvC XdwK5gpmmyJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499JAAKCRAgrS7GWxAs 4r0iEACGNeA9KNoTBMse1hScH39dgs4KjB385HbFPLPE/oTo/lX3qZVrxKzDxc4X85MSNPkWu5s pzL1Mdx0aB0draukmE/uzqE+Se8AaDspTHASTvE5E1KKpUsTJIJqF6aqa3+gzSwlj0EQWBwEu4x j6YWZXO60EYFvBgMISkx0Jcms7B8pKlvw44JkVttEWICqzTbB9eiT27JplJa6xpUaQvm0zUVqP4 YQfDrakP21khB27Ts9NW+egwRD2fSfKxM/wITqa7zhMb+/pvMuwvPnm8Krn/WXgRchS9c85ZNvT pXweFoKQ4jqhKIO5CmdK5WoJQ/+wlDY13DmB7XQFDdts6yfm4chVzmaY6sBHxDYDhK3nhsYMVsm R2Qn5k/1wFPkHqIiki0NcZhX5TnK185plQlPc3j7enhO8hlpC7r+BsRMutGoCdPB3FPo3UGSCM1 0TMkdItCeEO/kuItNndDD4O9650kLAWc83Vv1ixbmaqPbHOGFpPlpAHuEcovpIkGhoBBazQfTol 9103QeDSatoAXIPb8Brj0zzgzClo29A8ry6WxnIq52lSr3ea+VO5KsShRTZOPrlGon9Gu77zdCl stBYoSWrR1QdwpZ+YPR8iBs1LFn7qPDv/7dBjORdQHGaCu3R9IleGSffRiehUWDT6VKwglrabOQ 3J3ImF8e9Ob6RCg== 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 driver supports all the pixel formats for planes, but for testing it can be useful to only advertise few of them. This new configuration interface will allow configuring the pixel format per planes. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 75 ++++++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 19 ++++++++++ drivers/gpu/drm/vkms/vkms_plane.c | 13 ++----- 3 files changed, 97 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index d2006d7b47f9cf21487659cc3eacb6272d1904b0..57e211e48a90d3a4d7f8677c40a2b35d44b847e5 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -6,6 +6,14 @@ #include "vkms_config.h" #include "vkms_drv.h" +static const u32 vkms_supported_plane_formats[] = { + DRM_FORMAT_ARGB8888, + DRM_FORMAT_XRGB8888, + DRM_FORMAT_XRGB16161616, + DRM_FORMAT_ARGB16161616, + DRM_FORMAT_RGB565, +}; + struct vkms_config *vkms_config_create(void) { struct vkms_config *config; @@ -120,6 +128,13 @@ struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *vkms_conf if (!vkms_config_overlay) return NULL; + vkms_config_overlay->supported_formats = NULL; + + if (vkms_config_plane_add_all_formats(vkms_config_overlay)) { + kfree(vkms_config_overlay); + return NULL; + } + vkms_config_overlay->type = DRM_PLANE_TYPE_OVERLAY; vkms_config_overlay->supported_rotations = DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK; vkms_config_overlay->default_rotation = DRM_MODE_ROTATE_0; @@ -186,6 +201,65 @@ struct vkms_config_encoder *vkms_config_create_encoder(struct vkms_config *vkms_ } EXPORT_SYMBOL_IF_KUNIT(vkms_config_create_encoder); +int __must_check vkms_config_plane_add_all_formats(struct vkms_config_plane *vkms_config_plane) +{ + u32 *ret = krealloc_array(vkms_config_plane->supported_formats, + ARRAY_SIZE(vkms_supported_plane_formats), + sizeof(uint32_t), GFP_KERNEL); + if (!ret) + return -ENOMEM; + vkms_config_plane->supported_formats = ret; + + memcpy(vkms_config_plane->supported_formats, vkms_supported_plane_formats, + sizeof(vkms_supported_plane_formats)); + vkms_config_plane->supported_formats_count = ARRAY_SIZE(vkms_supported_plane_formats); + return 0; +} + +int __must_check vkms_config_plane_add_format(struct vkms_config_plane *vkms_config_plane, + u32 drm_format) +{ + bool found = false; + + for (int i = 0; i < ARRAY_SIZE(vkms_supported_plane_formats); i++) { + if (vkms_supported_plane_formats[i] == drm_format) + found = true; + } + + if (!found) + return -EINVAL; + for (unsigned int i = 0; i < vkms_config_plane->supported_formats_count; i++) { + if (vkms_config_plane->supported_formats[i] == drm_format) + return 0; + } + u32 *new_ptr = krealloc_array(vkms_config_plane->supported_formats, + vkms_config_plane->supported_formats_count + 1, + sizeof(*vkms_config_plane->supported_formats), GFP_KERNEL); + if (!new_ptr) + return -ENOMEM; + + vkms_config_plane->supported_formats = new_ptr; + vkms_config_plane->supported_formats[vkms_config_plane->supported_formats_count] = drm_format; + vkms_config_plane->supported_formats_count++; + + return 0; +} + +void vkms_config_plane_remove_all_formats(struct vkms_config_plane *vkms_config_plane) +{ + vkms_config_plane->supported_formats_count = 0; +} + +void vkms_config_plane_remove_format(struct vkms_config_plane *vkms_config_plane, u32 drm_format) +{ + for (unsigned int i = 0; i < vkms_config_plane->supported_formats_count; i++) { + if (vkms_config_plane->supported_formats[i] == drm_format) { + vkms_config_plane->supported_formats[i] = vkms_config_plane->supported_formats[vkms_config_plane->supported_formats_count - 1]; + vkms_config_plane->supported_formats_count--; + } + } +} + void vkms_config_delete_plane(struct vkms_config_plane *vkms_config_plane, struct vkms_config *vkms_config) { @@ -206,6 +280,7 @@ void vkms_config_delete_plane(struct vkms_config_plane *vkms_config_plane, } } + kfree(vkms_config_plane->supported_formats); kfree(vkms_config_plane->name); kfree(vkms_config_plane); } diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index 18b8978b7b7b58c45fcf11f7130883013e34d8ed..72bfaadd4322f9e1607a6b9425fb8aaf8bd9d5f6 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -90,6 +90,8 @@ struct vkms_config_plane { enum drm_plane_type type; unsigned int default_rotation; unsigned int supported_rotations; + u32 *supported_formats; + unsigned int supported_formats_count; struct xarray possible_crtcs; /* Internal usage */ @@ -136,6 +138,23 @@ bool vkms_config_is_valid(struct vkms_config *vkms_config); */ struct vkms_config_plane *vkms_config_create_plane(struct vkms_config *vkms_config); +/** vkms_config_plane_add_format - Add a format to the list of supported format of a plane + * + * The passed drm_format can already be present in the list. This may fail if the allocation of a + * bigger array fails. + * + * @vkms_config_plane: Plane to add the format to + * @drm_format: Format to add to this plane + * + * Returns: 0 on success, -ENOMEM if array allocation fails, -EINVAL if the format is not supported + * by VKMS + */ +int __must_check vkms_config_plane_add_format(struct vkms_config_plane *vkms_config_plane, + u32 drm_format); +int __must_check vkms_config_plane_add_all_formats(struct vkms_config_plane *vkms_config_plane); +void vkms_config_plane_remove_format(struct vkms_config_plane *vkms_config_plane, u32 drm_format); +void vkms_config_plane_remove_all_formats(struct vkms_config_plane *vkms_config_plane); + struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *vkms_config); /** diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index c23ac8687dedaa956cfd6622321f1026521ff13f..e7ad161fd3d3f2d0bdaf63a4df86d6a2e91230c1 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -13,14 +13,6 @@ #include "vkms_formats.h" #include "vkms_config.h" -static const u32 vkms_formats[] = { - DRM_FORMAT_ARGB8888, - DRM_FORMAT_XRGB8888, - DRM_FORMAT_XRGB16161616, - DRM_FORMAT_ARGB16161616, - DRM_FORMAT_RGB565 -}; - static struct drm_plane_state * vkms_plane_duplicate_state(struct drm_plane *plane) { @@ -195,8 +187,9 @@ struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 0, &vkms_plane_funcs, - vkms_formats, ARRAY_SIZE(vkms_formats), - NULL, config->type, config->name); + config->supported_formats, + config->supported_formats_count, NULL, config->type, + config->name); if (IS_ERR(plane)) return plane; From patchwork Tue Jan 21 10:55:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946174 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 B2932C02182 for ; Tue, 21 Jan 2025 10:56:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 316AF10E577; Tue, 21 Jan 2025 10:56:05 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="gbt9y2aa"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1FF6C10E569 for ; Tue, 21 Jan 2025 10:55:47 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 308E74000C; Tue, 21 Jan 2025 10:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456946; 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=uTZN2ccLO8iHkJaWPvHiGP/G3x0f/RdchrD/cM6uvTc=; b=gbt9y2aaUBbg0u4p68quQZRxyqRDaoex7my43fmxqB/BUMYZ7snkjJNUYjPl0CUrogyGqY VR+vpaPnwvEZCIBdycbIRzO5Xrf/y8YB4CFFtuFCcj2/LPyRVCaoPMGuKtb6pV3qW3Qlva desJFaLJKEE9WjC2Jo2KjbSeuh780DD6Lc5aGr/jnioFINcDAgv8wo4y5bF7MzuqiZeuBz 7Nld15cQH9lXj5AhAzqSIu7lzApp/fnd+KFC4TWTz0yPCNRB7onECV9VD8f5F/ErMXaaVc o+ILNMI6iuVQmBNELBd5SD4HZC285zcqkkEXFwCzolLRu+xGwfEJw9QcKdJ7zQ== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:38 +0100 Subject: [PATCH v3 14/16] drm/vkms: Introduce config for connector status MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-14-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet , =?utf-8?b?Sm9zw6kgRXhww7NzaXRv?= X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4015; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=O4QgJ2Fxi9tAm7ZgS3BUqW2s6EgHDl+aw7VV+hrKKCs=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30kuiLTjyfXsm2ZmH1U4GR8M/JS3UZy1Dtv1 VsybfhQzbaJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499JAAKCRAgrS7GWxAs 4kAdEACt8P4dkhyu7fb/aUlE4ka6uoZRYDKBVry9icsMW0aGF0RGN8mmomT1JRhRBY+w9iJKQYL YFyNJn1WT97pM935da1+9NwroZr18B/j1pKvuURvsuorDrigsPmX8UzhehbZdbfaQ3nSxIXOpjq bjuoT7URFRPQakzjMHmGGrEe4P5OHRkLRKS25oEi1b2UfKYGIi1pZ1fJxyHUpTwBuXJjKumtf0j 4SfPciEb2fWEh7S30TcPSxrPy3bdj0pRIo1EkC0vX9jpfkI/5ZbUhETdokhhZLoRKD3BVjwUx1v xJNHDIeDA0Ql+gJQTwsTVJXnaUl8RLWR8icNew6frLQyKioncmtYLVPt6JD4IGLAwawYLJba+ms Q4Ryx+6xp0RWxSIc0dYGKN5mpF319WNn88SEou8DroxcRJGpRatYFEI8jAZrn5UyhrMFkWEmDBz goCwsfalNqvOCNbPsmxMomB6ZDz11sU7QwvjHbJ0YL1aIyBodJ0oiZTxHXpoF9bix9SoeJnEyYj SQsp1pYgv3eyetliJIZ1eGL7/DAOmpzK5I49s+RQI93SNvnVP0+u9bwDLTJr5dYx6QwRMVMnMHl mIgm2QGm0XLeotPNMPH61NLbs6X9dJWBPWxlT4X3tBI2A7iN5hRntQSKy9M4VZQ91b6HiNeITiY UGXe3kBy71Ca1Tg== 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 driver does not currently support connector hotpluging. Add an option to change the connector status once a device is created. Signed-off-by: José Expósito [adpated it for my implementation] Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 10 ++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 4 ++++ drivers/gpu/drm/vkms/vkms_output.c | 24 ++++++++++++++++++++++++ 3 files changed, 38 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index 57e211e48a90d3a4d7f8677c40a2b35d44b847e5..5eba4284269d058f12f78ddba96cb40215e85f72 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -2,6 +2,7 @@ #include #include +#include #include "vkms_config.h" #include "vkms_drv.h" @@ -160,10 +161,19 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *v list_add(&vkms_config_connector->link, &vkms_config->connectors); xa_init_flags(&vkms_config_connector->possible_encoders, XA_FLAGS_ALLOC); vkms_config_connector->type = DRM_MODE_CONNECTOR_VIRTUAL; + vkms_config_connector->status = connector_status_unknown; return vkms_config_connector; } +void vkms_config_connector_update_status(struct vkms_config_connector *vkms_config_connector, + enum drm_connector_status status) +{ + vkms_config_connector->status = status; + if (vkms_config_connector->connector) + drm_kms_helper_hotplug_event(vkms_config_connector->connector->dev); +} + struct vkms_config_crtc *vkms_config_create_crtc(struct vkms_config *vkms_config) { if (!vkms_config) diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index 72bfaadd4322f9e1607a6b9425fb8aaf8bd9d5f6..8e0c9b753821f75f10b3090743905471d0abac36 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -103,11 +103,15 @@ struct vkms_config_connector { struct xarray possible_encoders; int type; + enum drm_connector_status status; /* Internal usage */ struct drm_connector *connector; }; +void vkms_config_connector_update_status(struct vkms_config_connector *vkms_config_connector, + enum drm_connector_status status); + /** * vkms_config_register_debugfs() - Register the debugfs file to display current configuration */ diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index 50aa802da479e5ba383e5db49dc2c7c6981f0bef..75d90df44da3b6dd3ed3ae104a6bc6d51c9bf089 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -7,9 +7,33 @@ #include #include +static struct vkms_config_connector *vkms_config_connector_from_vkms_connector(struct drm_connector *connector) +{ + struct vkms_device *vkms_device = drm_device_to_vkms_device(connector->dev); + struct vkms_config_connector *connector_cfg; + + list_for_each_entry(connector_cfg, &vkms_device->config->connectors, link) { + if (connector_cfg->connector == connector) + return connector_cfg; + } + return NULL; +} + +static enum drm_connector_status vkms_connector_detect(struct drm_connector *connector, bool force) +{ + enum drm_connector_status status = connector->status; + struct vkms_config_connector *connector_cfg = vkms_config_connector_from_vkms_connector(connector); + + if (connector_cfg) + status = connector_cfg->status; + + return status; +} + static const struct drm_connector_funcs vkms_connector_funcs = { .fill_modes = drm_helper_probe_single_connector_modes, .reset = drm_atomic_helper_connector_reset, + .detect = vkms_connector_detect, .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; From patchwork Tue Jan 21 10:55:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946172 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 4958BC0218B for ; Tue, 21 Jan 2025 10:55:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0A9CD10E569; Tue, 21 Jan 2025 10:55:55 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="GW4f/gHd"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id E54B910E56F for ; Tue, 21 Jan 2025 10:55:48 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 040F740015; Tue, 21 Jan 2025 10:55:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456947; 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=1L45snXRbo8coOmjDH+6FXlXlk9PA0CwtvqQLbt7rxQ=; b=GW4f/gHdOK3yjoD9kr9eALv9YxBAaKoLe8FhaaRafTQfuEY6SnDnvCpF8LzIvJY6m2G6U5 DoLH1ybWkP7rwng93UDyB1F61Avtc5Y7HwN75Hzcx7kSzguKm/kILrY7m9EJkl6lHj3NkI Bok9VU+hvE6R2NI0TnvCdIwUW2vMYD4dwBRDDg3mTUdJnZgw6ajoEPjuo99b3IwnN6a0XB enUgK+ViwQ7hvZwVLr23nr0oEvBf6DPafu7PAVfWltEggk3/w6hVLkI4+hpZdvNXMPot05 ok/p6FZVnd/lGKXf22m9FRzWv13BjBIBQ5Bd/2Cq/MSVkUmjubW7xFn71F2Qbw== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:39 +0100 Subject: [PATCH v3 15/16] drm/vkms: Introduce config for connector EDID MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-15-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3463; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=k1HVDWUOwoXCv+se/NTmEAQUM+zoChcbWYjKvCcZaew=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30kDvjlXFSbzyU+ash4NXe6sjMOPFGWhSwba e+CaHeF4g+JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499JAAKCRAgrS7GWxAs 4puAD/44Yw/tgydOJHNi1VVc25eEPMS3H7phu/LGDSkZZwBegXhBxedOIB5ksgxQlkrdl2bDBVN 2jdFEpl+GbVqfZWbeIRxTRWISIDPgmVG8Qq0uR3ZIJEg7hBuoRFkWrAJ033CnpHgMf+tYb73s9L Vh80BZiNjkdY4DMu/DLejfYOqbS9C1rsnH+MdMlq9o+vjImJaNfF6/itye4pWLLxZUB2raNHRlg tLdhlH5pMjSj86eOoADpAWMOp44YRGHSxXd772UThhthXegfojVuqpwinrWUEBD2hKbMovCJLRt naPJ2cxEtaBJ8xgM6IYtFXeUETiY2FHkUQ7SikMm2dSHSWwT3hqdbSiLAzsbNrFUGXeS2p8Z5GO vkY6Nrp0DYuAWzREYYi7s4mlRAm0bPKFuFyUx2toZWZh/OA5HfP3JBCp+7vvI4muCscHyRfdWG9 nBsX96WFeZHEtQRBrONrXbXNrsm5tm6u42KKvPKlSb1yKoJneGQ4WkXZvsX7kLEVuT3nl77YplR p/7npq2p0gg67IgJ9IZ2IwL/ls2IgQT368yizx3psMQ5pDfYw+tmP2YtfWz9U9nryOW+wftlkoL EnVs/X/ZtnW+DvmwT/E4G4WStjSwwsuhiU0q8sfiQ2HWTO1+ybaiSo4HrC2AyCOlkLazcV0Rxlg F3dPgu1JFdaZ/jA== 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 properly test the EDID reading without using the DRM override, add an option to configure the EDID for a connector. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 1 + drivers/gpu/drm/vkms/vkms_config.h | 2 ++ drivers/gpu/drm/vkms/vkms_output.c | 37 ++++++++++++++++++++++++++++++++++--- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index 5eba4284269d058f12f78ddba96cb40215e85f72..3e8883298e73e75fb16ac05e449a7ee8fac72935 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -162,6 +162,7 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *v xa_init_flags(&vkms_config_connector->possible_encoders, XA_FLAGS_ALLOC); vkms_config_connector->type = DRM_MODE_CONNECTOR_VIRTUAL; vkms_config_connector->status = connector_status_unknown; + vkms_config_connector->edid_blob_len = 0; return vkms_config_connector; } diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index 8e0c9b753821f75f10b3090743905471d0abac36..6844ca8523decd51116fb36f98ed40a09bc2284b 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -104,6 +104,8 @@ struct vkms_config_connector { struct xarray possible_encoders; int type; enum drm_connector_status status; + char edid_blob[PAGE_SIZE]; + int edid_blob_len; /* Internal usage */ struct drm_connector *connector; diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index 75d90df44da3b6dd3ed3ae104a6bc6d51c9bf089..8f7df59aa2c1517eb78e9b94b8611b15431fd234 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -38,13 +38,44 @@ static const struct drm_connector_funcs vkms_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; +static int vkms_connector_read_block(void *context, u8 *buf, unsigned int block, size_t len) +{ + struct vkms_config_connector *config = context; + + if (block * len + len > config->edid_blob_len) + return 1; + memcpy(buf, &config->edid_blob[block * len], len); + return 0; +} + static int vkms_conn_get_modes(struct drm_connector *connector) { + const struct drm_edid *drm_edid = NULL; int count; + struct vkms_config_connector *connector_cfg; + struct vkms_device *vkmsdev = drm_device_to_vkms_device(connector->dev); + struct vkms_config_connector *context = NULL; + + list_for_each_entry(connector_cfg, &vkmsdev->config->connectors, link) { + if (connector_cfg->connector == connector) { + context = connector_cfg; + break; + } + } + if (context) + drm_edid = drm_edid_read_custom(connector, vkms_connector_read_block, context); + + /* + * Unconditionally update the connector. If the EDID was read + * successfully, fill in the connector information derived from the + * EDID. Otherwise, if the EDID is NULL, clear the connector + * information. + */ + drm_edid_connector_update(connector, drm_edid); + + count = drm_edid_connector_add_modes(connector); - /* Use the default modes list from DRM */ - count = drm_add_modes_noedid(connector, XRES_MAX, YRES_MAX); - drm_set_preferred_mode(connector, XRES_DEF, YRES_DEF); + drm_edid_free(drm_edid); return count; } From patchwork Tue Jan 21 10:55:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946176 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 C8B01C02182 for ; Tue, 21 Jan 2025 10:56:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3F3CB10E57B; Tue, 21 Jan 2025 10:56:08 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="ZwAaceVd"; dkim-atps=neutral Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id BAC5A10E573 for ; Tue, 21 Jan 2025 10:55:49 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id C0D4D40012; Tue, 21 Jan 2025 10:55:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737456948; 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=Ubw63Fe9Yhv72/NM7/4903dvfCHgNHv426Pizoj94N8=; b=ZwAaceVdWyZTFSwk0cvfv/gj3c7yuj8phaj5B4PCSSsWSkZFs3YRbVaeRaKEiJO+rWMinY veB/mtY6R6AYhyUztLdDgCjve4n2sC8ZkjULcMF9peEgHIyb4FAEcdf0ml/JF0B2gVbFCb MVY9Dcswl5HHdgsVHbYkGnKl0CnR+l0tp1q2GoExIT8wu04kwLEFb+E1qerAXr+sPMWvKZ bT02hSM8m6+xxXx3nBMQxGihSRN7+EeCqAuVb6xNNK2pIQbYJz4U494PPGubvcnpz9awS+ 5/IsjKm8Q9A1i1Z4q43HWwZBQL0eqRAQjDprmCff1zJ0dzuNcb7ES6TA+W4aBQ== From: Louis Chauvet Date: Tue, 21 Jan 2025 11:55:40 +0100 Subject: [PATCH v3 16/16] drm/vkms: Introduce config for encoder type MIME-Version: 1.0 Message-Id: <20250121-google-remove-crtc-index-from-parameter-v3-16-cac00a3c3544@bootlin.com> References: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> In-Reply-To: <20250121-google-remove-crtc-index-from-parameter-v3-0-cac00a3c3544@bootlin.com> To: =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Simona Vetter , Melissa Wen , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie Cc: arthurgrillo@riseup.net, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2577; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=3Uxt9AsZYAsifD+dZG6PItmtjDqqXrCvkT981nanQ+w=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj30l/cLzvUD0vqUSYIoiv/uUEhKQ58HtXMtFb Bg6Gpo1m+6JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ499JQAKCRAgrS7GWxAs 4jynD/95nJtbOf6oHrZj1qKPB36gxyDHT74VRdzt2fqdRx3QvRJ1Y58YzbTZrYOvFWxEsjRsWtk miJTeujVuw9LKoDhjNxIa0Al1r9qR9B7cIarf+J9oIduoh4ZooJOCDR0WKxCYbOYSs0w4LqjT8b iu9R3q9J8ILNutmOoK23aIQC+sMxq0UP7s5fPzed8IW/XnxV9McqLPkI+GCHAeJvum9KUbRtWna gUhJ7sH/ZX3WjKk2VnF1H446ocQfvQYF1fNbfAHTyxRHtTILrFGjjG3M1l1QC7EFg1fFL5uicv1 lF4eQ5XAIsuyjOyB9M7Bv1KB99QiUfSAFZohfUSBwf19k+V757KRIlAaVWXdin3KWe8TXaS3AYo 7/l+Aa3P9+Wn3CQTM2rGwmX+YSlh7WGt+KtHeGL9ZRHTy9goUZZvAaF6kw8WblTPZX8lsq1MbBc aTooO/vyl2IXxdxByQvtkWKio/50wrmqnvm+FNlTdYqOI31kDlUgYaqm+eUXqjNNY22KOgUuIub IGl8qCXowIomGr0FyaIVXSRHgCq0C9O6Wsjz3XHxfmpx/ypKYIb00O+X8ZNKWp37ro+4JPMAfbV c6f+mOSFnE4fEV/LDCXQy/rsv0l2ICLCG1iH7Xw/I1yYgW5wHA3L2SMR30/WcHFt/iu0+y1TnYy N0x/HNTUXck029g== 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 allow emulation of different kind of encoders, make the encoder type configurable. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 1 + drivers/gpu/drm/vkms/vkms_config.h | 2 ++ drivers/gpu/drm/vkms/vkms_output.c | 2 +- 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index 3e8883298e73e75fb16ac05e449a7ee8fac72935..a20644031ce923fad98d486a8bb2ec7859038dcd 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -205,6 +205,7 @@ struct vkms_config_encoder *vkms_config_create_encoder(struct vkms_config *vkms_ if (!vkms_config_encoder) return NULL; + vkms_config_encoder->type = DRM_MODE_ENCODER_VIRTUAL; list_add(&vkms_config_encoder->link, &vkms_config->encoders); xa_init_flags(&vkms_config_encoder->possible_crtcs, XA_FLAGS_ALLOC); diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index 6844ca8523decd51116fb36f98ed40a09bc2284b..23f420291cfc0044ccb2be90688d021aab10c1c0 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -55,6 +55,7 @@ struct vkms_config_crtc { * @link: Link to the others encoders * @name: Name of the encoder * @possible_crtcs: List of CRTC that can be used with this encoder + * @type: Type of encoder, see drm_mode.h, DRM_MODE_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 configuration and must be managed by other means. @@ -64,6 +65,7 @@ struct vkms_config_encoder { char *name; struct xarray possible_crtcs; + char type; /* Internal usage */ struct drm_encoder *encoder; diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index 8f7df59aa2c1517eb78e9b94b8611b15431fd234..a48625e879f59a33e18e636cafcdc7f841a0ff1f 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -132,7 +132,7 @@ int vkms_output_init(struct vkms_device *vkmsdev) if (!config_encoder->encoder) return -ENOMEM; ret = drmm_encoder_init(dev, config_encoder->encoder, NULL, - DRM_MODE_ENCODER_VIRTUAL, config_encoder->name); + config_encoder->type, config_encoder->name); if (ret) { DRM_ERROR("Failed to init encoder\n"); return ret;