From patchwork Tue Jan 21 14:34:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946350 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 69BF8C0218B for ; Tue, 21 Jan 2025 14:38:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EAC8310E5D0; Tue, 21 Jan 2025 14:38:02 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="SXl+6qU4"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by gabe.freedesktop.org (Postfix) with ESMTPS id 812F310E1F7 for ; Tue, 21 Jan 2025 14:38:00 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 428A3C0004; Tue, 21 Jan 2025 14:37:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470279; 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=Kaj2PyzhoEIxwt/S/91A3XIhtvN9PQbzTybix3SaXcU=; b=SXl+6qU4/z2eH9MifpyOT5SE6MhXy4ymdVZ3RjcLUyLjizLJAjIqXenoECxuStk167TVV/ sRx1ynf7GlWKAIJOsh8L4fbS4Qk3GTeuSZVhWAC2RZziPHolwBW6irNtt2W2q4njLu6+Ro Yc+2BE64EGvWc+zBMNtUfi3bMf3AFpYzzu6BOCf22n2CQ1lf4sz43rHvRhyYE2iOwo5NWO kSpDg82v2lftzm1icDSzrf6ksgsGAM5hR3gZTPRwN7Lmct8fbda6S4qVoQ3D2tPEdUQep4 HhT+UZn3Ao5AZOWMnOPX2T+8iVRSGeetY/Fn8lX18T1IKdDUkoSFBffQ+nboRA== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:45 +0100 Subject: [PATCH RFC v3 01/14] drm/vkms: Add vkms_delete/create_device helper MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-1-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1619; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=aKOGcFK92jCXXJZJ34r4ytIeQ4w1Xb8LDJmZmr/WMq0=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7E/wd6Eqj/Edmitu3yXmSZrEses51e+aE56t 9KdPFnZdr6JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xPwAKCRAgrS7GWxAs 4v/RD/0THFZfy4jFDSzocbzsmDlfDscdmaVThix5m6PCN0bNWk/QFdCHBgiLHQK8ui7jQ2yFxw4 DclePhDdxoRoPxMppLAuORAoplO2VW7G/mAQbxHYr71Z+MakfYQYwNLjWe9Vws/fPVOE4ucZvjr 1qL5sRmsL33ehGCfE18f4b4TVKFuWiwroOAohPaldKQAAp7yPUD6/Y7ompwdex+RbhSuRz7cvu8 gfc7nC8NKxw8PlnbowCd0Yd3gKAXFU611WylPgoEP7Jg9wiUThSrcMy1Pu4d3tQEkqEp+RYXybc THt7x4JnQMUSWoBsZdttSvakByFuGkD0JjJCaVfPNIHMkTKeyKQsCDulD3AUBC/ahI89pbs+MQV kXPVIeok3s7UZoWabYF9/xPBOKvcEKvLfNBSOjEEJBICOt6HSjHo3ZAKBGzuzeAG4f5Ne/KPf4K Y2PgbRSfDhyf/lIaOBcDSRK5liSw2+obdc+05MmyjljQXe2WM089DkOvMcu/kR3tfUiR4hQ3SG6 exGbNgHcRzjfYJP8pM90YwkXZyxawVbQyMMkQO/VkKgGpbVGwGIx6htfPBgAZWV8ditrOVPZXGw lrO9nSzzSsCMmXWJkz3lC2j9SjUhWKFEI8PwzGviwXX7x3hI7isq7Ifyt48MEzvxWQYzPccrvA1 R1OOnZc8pdFVU3g== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In preparation for introduction of ConfigFS support, expose the vkms_destroy/create helper to remove a vkms device. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_drv.c | 4 ++-- drivers/gpu/drm/vkms/vkms_drv.h | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 95fde2fbd711fe52a3a3b5a55778f5bc2029beb7..5f1958d59cc4c3102352599eee7a8e139fbb899c 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -150,7 +150,7 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) return vkms_output_init(vkmsdev); } -static int vkms_create(struct vkms_config *config) +int vkms_create(struct vkms_config *config) { int ret; struct platform_device *pdev; @@ -224,7 +224,7 @@ static int __init vkms_init(void) return ret; } -static void vkms_destroy(struct vkms_config *config) +void vkms_destroy(struct vkms_config *config) { struct platform_device *pdev; diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 3a211cdb41bd1003366d9eaa1425e122d885e4a4..28d8c36d1de28aeda4daea7a30db969bc7943d65 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -208,6 +208,9 @@ struct vkms_device { const struct vkms_config *config; }; +int vkms_create(struct vkms_config *config); +void vkms_destroy(struct vkms_config *config); + /* * The following helpers are used to convert a member of a struct into its parent. */ From patchwork Tue Jan 21 14:34:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946354 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 BB88DC0218D for ; Tue, 21 Jan 2025 14:38:10 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 315FA10E5D6; Tue, 21 Jan 2025 14:38:07 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="mUQTOTkk"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by gabe.freedesktop.org (Postfix) with ESMTPS id 97F7010E1F6 for ; Tue, 21 Jan 2025 14:38:01 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 58E29C0006; Tue, 21 Jan 2025 14:37:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470280; 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=C1hkXxAV2soqDPWmw1hIUWOl55m0yvR5CbonYKd+i24=; b=mUQTOTkkozBZjGCY5w6hea7pqIYwFrlsCidrG38FeU3EiTbYZSlqoChwVPqybE5Jc9p7tX bOzOGWzH77DKoC4d7iEUDR8HK3bIR+8AAkjS47OTHnf2xQQppHYfGsF99KOcsxUtnQZjz+ 9gNOlUm9n+eyAWMlQUa4QaVJ0DHvi2zEVoMfyADZO/8HlYs/xVWh4Hy7rdKjDUeMmNqcjr VjViOwYn6x3BQwO4vup9TgP6+0bwBaKKN+amiHyeAZp/0YsrPvGhnhkor30MTAp8uv8dnf 09QuVh+k2uuF5iM9F+5+3g7K8KyzacK86LwJlCAsOwUs1CSRIDhj7iL8jNnBNA== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:46 +0100 Subject: [PATCH RFC v3 02/14] drm/vkms: Cleanup configuration field on device destroy MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-2-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2931; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=XjPMbvB49qIxULw8XBaRu5LGzihS7dS+8w0mN+Lh+9M=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7FAES1qSrK6ELwsn62aRK+NEi7esKLOV8lFn 2KFHOFc3rqJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xQAAKCRAgrS7GWxAs 4kO0EACwhQZIyOf29w1G18PcA+1aS5bdademqeGVxJ4gNM+CggAf7khqSfexcNuTHU97Tv/NeTq 8PHYl6Jqo+3Bjk3qzkdz7LnuK+hlGmwEUkTNqjMSZqdK1hU6+3vS+tFAuwGZ4cVT/7jcNhI1w4D HHiiyNtKVrDF6xgpuy/+o8VVOSAWGGqvLvFdoNTo5JLpnpCD5bmmKdkVl913WwuQ52gzay8FVO3 ujRdSaeZbsI09hYowA1+2wI3Oh0iYiWy9kysosa7g9O3uUfQBrbSROGhIlhxr0POaJbOGBW3VTK QYJ141+YOExPXn1EW8HjxcTfSIMX3X2+nOLZQj6yZcbn5wZWC0+6PIorHs9EOzU3YwPyHMcmvpe aePXg+TBEGmf22Vuj+L2DOr9Jzvurypb2wMob6j4p8DfSdsK0X/QijQcQFHQivz3F3xENiJkXu9 GIek3VWZi0Yh/JDbHE6n99mIK5NyWIR3vCwT3qVrsZyqcNIGcyuWQ9S6lREWAT6IzTn7opfNKf3 sVYVKhRKfLyTNUV/e0EFCpwFfMIIeU3DE3eGeunuMGjGPpyYZzpW/pk0D2P3E3Gf8KgdQUHNf1j PM4qF3oxB+TgQgkdv5st9w2KtSpLxeCFLPnnTRkrQ7g9Hmnn8I7b/WRcWsfzOMQ8oqc/5cl6kv3 MchrAisJBQ8VLAA== 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 avoid having dangling pointers in struct vkms_config, remove all of them when the device is destroyed. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 23 +++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_config.h | 3 ++- drivers/gpu/drm/vkms/vkms_drv.c | 2 +- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index a20644031ce923fad98d486a8bb2ec7859038dcd..8ac9cd52cc00f7c317f2514a73c3d2f3908b085b 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -167,6 +167,29 @@ struct vkms_config_connector *vkms_config_create_connector(struct vkms_config *v return vkms_config_connector; } +void vkms_config_disconnect_dev(struct vkms_config *vkms_config) +{ + struct vkms_config_connector *connector, *tmp_connector; + struct vkms_config_encoder *encoder, *tmp_encoder; + struct vkms_config_plane *plane, *tmp_plane; + struct vkms_config_crtc *crtc, *tmp_crtc; + + vkms_config->dev = NULL; + + list_for_each_entry_safe(connector, tmp_connector, &vkms_config->connectors, link) { + connector->connector = NULL; + } + list_for_each_entry_safe(encoder, tmp_encoder, &vkms_config->encoders, link) { + encoder->encoder = NULL; + } + list_for_each_entry_safe(plane, tmp_plane, &vkms_config->planes, link) { + plane->plane = NULL; + } + list_for_each_entry_safe(crtc, tmp_crtc, &vkms_config->crtcs, link) { + crtc->output = NULL; + } +} + void vkms_config_connector_update_status(struct vkms_config_connector *vkms_config_connector, enum drm_connector_status status) { diff --git a/drivers/gpu/drm/vkms/vkms_config.h b/drivers/gpu/drm/vkms/vkms_config.h index 23f420291cfc0044ccb2be90688d021aab10c1c0..2e5d2aa34a4f039c738cb9ac5642f3c75df36ba7 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -109,10 +109,11 @@ struct vkms_config_connector { char edid_blob[PAGE_SIZE]; int edid_blob_len; - /* Internal usage */ + /* Set only when the device is enabled */ struct drm_connector *connector; }; +void vkms_config_disconnect_dev(struct vkms_config *vkms_config); void vkms_config_connector_update_status(struct vkms_config_connector *vkms_config_connector, enum drm_connector_status status); diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 5f1958d59cc4c3102352599eee7a8e139fbb899c..afbd1fbe00d469bea8367096a3aa0ed07b66ed1a 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -240,7 +240,7 @@ void vkms_destroy(struct vkms_config *config) devres_release_group(&pdev->dev, NULL); platform_device_unregister(pdev); - config->dev = NULL; + vkms_config_disconnect_dev(config); } static void __exit vkms_exit(void) From patchwork Tue Jan 21 14:34:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946351 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 39D2EC0218D for ; Tue, 21 Jan 2025 14:38:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2A65D10E1F7; Tue, 21 Jan 2025 14:38:06 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="YfYXVkTp"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by gabe.freedesktop.org (Postfix) with ESMTPS id B184810E1F7 for ; Tue, 21 Jan 2025 14:38:02 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 73E41C0007; Tue, 21 Jan 2025 14:38:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470281; 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=lhQEZOvn/jMO4/P3BnIFODEDvPs26ENlss6WZdWsqKA=; b=YfYXVkTpYotKFIJGWKVEaIVnZ8qTS5C3Wa7m+3Y9hNzd5AAxs6Z/sq5GySxzVWG54AfHYQ q1tFQZpLCyHUCau5/TzBgmhJuPmXhY5HgpH/+uqut6yHqmLj5AxEJkAUfizJZdS8ZvyafM oCupYSpwlXtICdatAehpER2TQkG48jWPXUGQIk4L61FysI3vFqEbR6j1hZwCOJFRDoXSFD YbLQx+OATlDjbHcBxtcDOwUXlxuNqpi7EiuyacROjF2hWuvAPoS9+EaYMgysoj33Vx1ljb bS8b2pfGVTP7wqj32L/bn/ZSQrINZiA3rjOKtVaMJBsuHW45++9H8z5rukIn8w== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:47 +0100 Subject: [PATCH RFC v3 03/14] drm/vkms: Introduce ConfigFS interface MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-3-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=8290; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=gW5kbPGah9wsQMOt1mWrt49HNN/XFyodHRvOUKhHbho=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7FAVMbLB2XadPXbEWIwLqCqViaEhfA1i5RQX X8T9d7omi2JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xQAAKCRAgrS7GWxAs 4twrD/4s5G9AJAI3vLHGHjDvbcmlL8O05gQHsIC87+mS2R6VOh3cj2Z4pe+biqG9YvuTgX+yZRY C7rM4gJWaVrZMY03Ig22HrE9S/CH5yJsI4u8NdbqRXGhD0aDNff4FsT01Od4uzzzcI3J6aLUuZA kVJSk9wOoYGUet8ZIK9qLaOfDc/YPMO6kRTXljINvoF8jWxnQb2zYsH7rWcBZi/dHHyQICpXifz 7yDXO7BwrelYE/B/2pbTtkQ9o498fyVuLTCJ9JGRj+YYK6JJbDFSQiLePqzYZ9JHsYr5AB6BMXC lY8EsRSvDKRXhezt+EXvG1Z6lb1tZE5moCyNliszzxPC+zPCYES6olSkHknNEIzFec8XV+OGk2I ej4yD3GUSjhVyEa/e2O+rZTsFRyr24Dy3BTRuT6qNcTsuK0esU0SwPHwMbP0CJZbqGuGxknHu8E JE6GDGC6Ju4yOJP7ddXDEmbLXMHTxOyU2Hgfo0iINtvQqWndd5D6ggspoxICP8kxnX1o2NDzCIF v7t3BvHTXClUc6H2TeAQEG8IRSPLOQll3ckPsMt8e5ku/JbwwyzgknpjMDQKOmh8LG48LpkHW7b pqDPPI6021Y5AtoWpHl83iOSQ3hzoKFkVOvCzi0029DiJkf0v307A+zdRsz5gbLO6tfwF1OkCKV 7LGHU3Px6uwKpOw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" VKMS is manly used to test userspace program and its behavior. The current implementation is not very configurable as you can only have one device, with few specific planes. This is the introduction of a basic interface to dynamically create new devices. The new interface is: /config/vkms DEVICE_1 ┗━ enable DEVICE_2 ┗━ enable Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/Kconfig | 1 + drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/vkms_configfs.c | 144 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_configfs.h | 35 +++++++++ drivers/gpu/drm/vkms/vkms_drv.c | 15 +++- 5 files changed, 194 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vkms/Kconfig b/drivers/gpu/drm/vkms/Kconfig index 9def079f685bd30e1df3e4082e4818e402395391..742402dc09b981ee976cd06c4009c08969910556 100644 --- a/drivers/gpu/drm/vkms/Kconfig +++ b/drivers/gpu/drm/vkms/Kconfig @@ -6,6 +6,7 @@ config DRM_VKMS select DRM_CLIENT_SELECTION select DRM_KMS_HELPER select DRM_GEM_SHMEM_HELPER + select CONFIGFS_FS select CRC32 default n help diff --git a/drivers/gpu/drm/vkms/Makefile b/drivers/gpu/drm/vkms/Makefile index b371b5d70ee31e76343c2f09e6dc5a6e74a1c246..1d73b9cf64ff737cef65b82c79cd2e574a04377b 100644 --- a/drivers/gpu/drm/vkms/Makefile +++ b/drivers/gpu/drm/vkms/Makefile @@ -1,5 +1,6 @@ # SPDX-License-Identifier: GPL-2.0-only vkms-y := \ + vkms_configfs.o \ vkms_drv.o \ vkms_plane.o \ vkms_output.o \ diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c new file mode 100644 index 0000000000000000000000000000000000000000..6535672f008401cf1ae008ff2ef74452b2575eab --- /dev/null +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -0,0 +1,144 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include +#include +#include + +#include "vkms_configfs.h" +#include "vkms_drv.h" +#include "vkms_config.h" + +static ssize_t device_enable_show(struct config_item *item, char *page) +{ + return sprintf(page, "%d\n", + config_item_to_vkms_configfs_device(item)->enabled); +} + +static ssize_t device_enable_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_configfs_device *vkms_configfs_device = + config_item_to_vkms_configfs_device(item); + + bool value; + int ret; + + ret = kstrtobool(page, &value); + if (ret) + return -EINVAL; + + mutex_lock(&vkms_configfs_device->lock); + + vkms_configfs_device->enabled = value; + + if (value) + vkms_create(vkms_configfs_device->vkms_config); + else + vkms_destroy(vkms_configfs_device->vkms_config); + + mutex_unlock(&vkms_configfs_device->lock); + + return (ssize_t)count; +} + +CONFIGFS_ATTR(device_, enable); + +static struct configfs_attribute *device_attrs[] = { + &device_attr_enable, + NULL, +}; + +static void device_release(struct config_item *item) +{ + struct vkms_configfs_device *vkms_configfs_device = + config_item_to_vkms_configfs_device(item); + + mutex_destroy(&vkms_configfs_device->lock); + vkms_config_destroy(vkms_configfs_device->vkms_config); + + kfree(vkms_configfs_device); +} + +static struct configfs_item_operations device_item_operations = { + .release = &device_release, +}; + +static const struct config_item_type device_item_type = { + .ct_attrs = device_attrs, + .ct_item_ops = &device_item_operations, + .ct_owner = THIS_MODULE, +}; + +/* Top directory management. Each new directory here is a new device */ +static struct config_group *root_make_group(struct config_group *group, + const char *name) +{ + struct vkms_config_plane *plane; + struct vkms_config_crtc *crtc; + struct vkms_config_encoder *encoder; + struct vkms_configfs_device *configfs = kzalloc(sizeof(*configfs), GFP_KERNEL); + + if (!configfs) + return ERR_PTR(-ENOMEM); + + mutex_init(&configfs->lock); + + configfs->vkms_config = vkms_config_create(); + + if (!configfs->vkms_config) { + kfree(configfs); + return ERR_PTR(-ENOMEM); + } + + plane = vkms_config_create_plane(configfs->vkms_config); + crtc = vkms_config_create_crtc(configfs->vkms_config); + encoder = vkms_config_create_encoder(configfs->vkms_config); + + if (!plane || !crtc || !encoder || + vkms_config_plane_attach_crtc(plane, crtc) || + vkms_config_encoder_attach_crtc(encoder, crtc)) { + vkms_config_destroy(configfs->vkms_config); + kfree(configfs); + return ERR_PTR(-ENOMEM); + } + + plane->type = DRM_PLANE_TYPE_PRIMARY; + + config_group_init_type_name(&configfs->group, name, + &device_item_type); + + return &configfs->group; +} + +static struct configfs_group_operations root_group_operations = { + .make_group = &root_make_group, +}; + +static struct config_item_type root_item_type = { + .ct_group_ops = &root_group_operations, + .ct_owner = THIS_MODULE, +}; + +static struct configfs_subsystem vkms_subsys = { + .su_group = { + .cg_item = { + .ci_name = "vkms", + .ci_type = &root_item_type, + }, + }, + .su_mutex = __MUTEX_INITIALIZER(vkms_subsys.su_mutex), +}; + +int vkms_init_configfs(void) +{ + config_group_init(&vkms_subsys.su_group); + + return configfs_register_subsystem(&vkms_subsys); +} + +void vkms_unregister_configfs(void) +{ + configfs_unregister_subsystem(&vkms_subsys); +} diff --git a/drivers/gpu/drm/vkms/vkms_configfs.h b/drivers/gpu/drm/vkms/vkms_configfs.h new file mode 100644 index 0000000000000000000000000000000000000000..ffacba6607018de44323fb6aa05cc6da8400a9f2 --- /dev/null +++ b/drivers/gpu/drm/vkms/vkms_configfs.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#include +#include + +#ifndef _VKMS_CONFIGFS_H +#define _VKMS_CONFIGFS_H + +/** + * struct vkms_configfs_device - Internal object to manage all the configfs items related to one + * device + * + * @group: Main configfs group for a device + * @platform_device: If a device was created (@enabled = true), stores a pointer to it + * @lock: Mutex used to avoid conflicting edition of @vkms_config + * @enabled: Store if the device was created or not + * @vkms_config: Current vkms configuration, protected by @lock + */ +struct vkms_configfs_device { + struct config_group group; + + struct mutex lock; + bool enabled; + + struct vkms_config *vkms_config; +}; + +#define config_item_to_vkms_configfs_device(item) \ + container_of(to_config_group((item)), struct vkms_configfs_device, group) + +/* ConfigFS Support */ +int vkms_init_configfs(void); +void vkms_unregister_configfs(void); + +#endif /* _VKMS_CONFIGFS_H */ diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index afbd1fbe00d469bea8367096a3aa0ed07b66ed1a..0b1fe3bce1fb370727ff7585e520e5eb64c9c0b6 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -29,6 +29,7 @@ #include "vkms_drv.h" #include "vkms_config.h" +#include "vkms_configfs.h" #include #include @@ -156,7 +157,7 @@ int vkms_create(struct vkms_config *config) struct platform_device *pdev; struct vkms_device *vkms_device; - pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); + pdev = platform_device_register_simple(DRIVER_NAME, PLATFORM_DEVID_AUTO, NULL, 0); if (IS_ERR(pdev)) return PTR_ERR(pdev); @@ -217,9 +218,17 @@ static int __init vkms_init(void) if (IS_ERR(default_config)) return PTR_ERR(default_config); + ret = vkms_init_configfs(); + if (ret) { + DRM_ERROR("Unable to initialize configfs\n"); + vkms_config_destroy(default_config); + } + ret = vkms_create(default_config); - if (ret) + if (ret) { + vkms_unregister_configfs(); vkms_config_destroy(default_config); + } return ret; } @@ -249,6 +258,8 @@ static void __exit vkms_exit(void) vkms_destroy(default_config); vkms_config_destroy(default_config); + + vkms_unregister_configfs(); } module_init(vkms_init); From patchwork Tue Jan 21 14:34:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946353 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 C3DD7C02182 for ; Tue, 21 Jan 2025 14:38:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0936B10E5D4; Tue, 21 Jan 2025 14:38:07 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="WKt6LP3a"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by gabe.freedesktop.org (Postfix) with ESMTPS id B2CE310E1F7 for ; Tue, 21 Jan 2025 14:38:03 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 8D212C0005; Tue, 21 Jan 2025 14:38:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470282; 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=jrolFzl/cwNj6pBXuV7Ptnquue7F1aAIvgVZ76iIXfo=; b=WKt6LP3a2zyySQQ0IqIxjA5eMLBPpp0RKdq5xuYOYTpW2VKHcMDSQ/2jQmMqgJIjwkemEq YUeEq//sUooVxryzuBPYDgx7yq2vfApoDwlevVoSnSoFwqC/VbfJ8tiM0wwvSxXSy1vhbv iHIRQ9vkoE22UqpcvFfHkHobEXyRmpXHKZp/B7y4KCyzuusMSn8MhkO7WIqWCJHle//7GI N0fKqwUV8TMEcdK2ZdSgLrKkSsFkPV9OE2E8RzXYYK7OB7+FjWA84pc5laatWM1WxC2nfM qnp4hIQQDtWwAtK8v6FLPc1RXEllYAGqPW5bhnHS6t+Q8Bg/PvoWSb8UeNGhRQ== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:48 +0100 Subject: [PATCH RFC v3 04/14] drm/vkms: Introduce configfs for plane MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-4-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=8211; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=tLy0ppQooWYGVpXF/b6oB5sVScxG7o0jo9dhHKyatmo=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7FAvgEdt//HFRmy/Fx6KlYu+uMo6LLYN0sbb X8nijZ5Y/6JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xQAAKCRAgrS7GWxAs 4kFHD/0bCWFnIAwUQaABRhGKVLKGkDuiXppjSi8gsELhcR/YyySTGADV/4cwhVqEIBrqlvieJ9+ oXMccMM1N1662hfJZQW9cmz38T2HU9hPCup5uySp5AqKVr57LAgHXPttEFhwRQG+7bA0f1QHdzP L/SCMZLT6ZxDfmBDEHvxYFbvdPZM6T1lED8uzP6EmpZ3MhXhT6WBZC8wHv+XPoakSo8axv07TbF 67aR16g73ULWCQPWURx/jxbrToHwQZuYq77zl71eIwxO9UjJojOJKlw4wzxjOTUi2yvrbW5WG+X 9A38rveoqnoSatZAYCuxFBHzU2qwF0/qwUnyl7rAQ+hsTyGNEV6opBJlG41CD9t7BZl9w1uIsXk YgtdVhmYPBQgvOuQGoF7UWA4ZzYOLKYNloNfD7N1+OGAWH/ohMXC9cZPrzs3u0Akol2p99Z7a4m REIWgy0Kc2EJji/SZQhiplk/0Gf3hlOY6rlDlrc3tx4cakIKYz+tBdpxFV7CHbIvU4bEC4WNr4v ECgHeGgQv33JRUhU2gXBQPs7JlafIi8304Cz530hzO0l3TCUkjNWlSOOQZleTuUFmRYOs9GMqsV L5HTUn1wHVhH6Eus7y+X4gDBEB9b+4c3UFFH6iqPs16sIKJsnyzImVCmcTy2t1d83V6WW2qZT/h K3h6eGhJxyeZKlw== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to test many hardware configuration, introduce a new interface to create and configure planes. The planes are created by creating a directory in the `planes` directory. The type of plane is configured by writing 0 (Overlay), 1 (primary) or 2 (cursor) in the file `type`. As the CRTCs and encoders can't be configured yet, the planes are all atteched to the same CRTC and encoder. The current interface is: /config/vkms DEVICE_1 ┣━ enable ┣━ planes ┃ ┣━ PLANE_1 ┃ ┃ ┣━ type ┃ ┣━ PLANE_2 ┃ ┃ ┗━ type ┃ ┗━ PLANE_3 ┃ ┗━ type DEVICE_2 ┗━ ditto Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 149 ++++++++++++++++++++++++++++++++--- drivers/gpu/drm/vkms/vkms_configfs.h | 20 +++++ 2 files changed, 160 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index 6535672f008401cf1ae008ff2ef74452b2575eab..ee64243396b3e586f76ff0671441c172da022421 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -10,6 +10,138 @@ #include "vkms_drv.h" #include "vkms_config.h" +static ssize_t plane_type_show(struct config_item *item, char *page) +{ + struct vkms_config_plane *plane; + enum drm_plane_type plane_type; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + plane_type = plane->type; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", plane_type); +} + +static ssize_t plane_type_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + enum drm_plane_type val = DRM_PLANE_TYPE_OVERLAY; + struct vkms_config_plane *plane; + int ret; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + if (val != DRM_PLANE_TYPE_PRIMARY && val != DRM_PLANE_TYPE_CURSOR && + val != DRM_PLANE_TYPE_OVERLAY) + return -EINVAL; + + mutex_lock(&vkms_configfs->lock); + if (vkms_configfs->enabled) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + plane->type = val; + + mutex_unlock(&vkms_configfs->lock); + + return count; +} + +CONFIGFS_ATTR(plane_, type); + +static struct configfs_attribute *plane_attrs[] = { + &plane_attr_type, + NULL, +}; + +static void plane_release(struct config_item *item) +{ + struct vkms_configfs_plane *vkms_configfs_plane = plane_item_to_vkms_configfs_plane(item); + + mutex_lock(&vkms_configfs_plane->vkms_configfs_device->lock); + vkms_config_delete_plane(vkms_configfs_plane->vkms_config_plane, + vkms_configfs_plane->vkms_configfs_device->vkms_config); + mutex_unlock(&vkms_configfs_plane->vkms_configfs_device->lock); + + kfree(vkms_configfs_plane); +} + +static struct configfs_item_operations plane_item_operations = { + .release = plane_release, +}; + +static const struct config_item_type subgroup_plane = { + .ct_attrs = plane_attrs, + .ct_item_ops = &plane_item_operations, + .ct_owner = THIS_MODULE, +}; + +static struct config_group *planes_make_group(struct config_group *config_group, + const char *name) +{ + struct vkms_configfs_device *vkms_configfs; + struct vkms_configfs_plane *vkms_configfs_plane; + + vkms_configfs = planes_item_to_vkms_configfs_device(&config_group->cg_item); + vkms_configfs_plane = kzalloc(sizeof(*vkms_configfs_plane), GFP_KERNEL); + + if (!vkms_configfs_plane) + return ERR_PTR(-ENOMEM); + + mutex_lock(&vkms_configfs->lock); + + if (vkms_configfs->enabled) { + kfree(vkms_configfs_plane); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-EINVAL); + } + + vkms_configfs_plane->vkms_config_plane = vkms_config_create_plane(vkms_configfs->vkms_config); + + if (list_count_nodes(&vkms_configfs->vkms_config->planes) == 1) + vkms_configfs_plane->vkms_config_plane->type = DRM_PLANE_TYPE_PRIMARY; + + if (!vkms_configfs_plane->vkms_config_plane || + vkms_config_plane_attach_crtc(vkms_configfs_plane->vkms_config_plane, + vkms_configfs->vkms_config_crtc)) { + kfree(vkms_configfs_plane); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-ENOMEM); + } + + vkms_configfs_plane->vkms_config_plane->name = kzalloc(strlen(name) + 1, GFP_KERNEL); + if (!vkms_configfs_plane->vkms_config_plane->name) { + kfree(vkms_configfs_plane->vkms_config_plane); + kfree(vkms_configfs_plane); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-ENOMEM); + } + strscpy(vkms_configfs_plane->vkms_config_plane->name, name, strlen(name) + 1); + + config_group_init_type_name(&vkms_configfs_plane->group, name, &subgroup_plane); + + vkms_configfs_plane->vkms_configfs_device = vkms_configfs; + mutex_unlock(&vkms_configfs->lock); + + return &vkms_configfs_plane->group; +} + +static struct configfs_group_operations planes_group_operations = { + .make_group = &planes_make_group, +}; + +static const struct config_item_type planes_item_type = { + .ct_group_ops = &planes_group_operations, + .ct_owner = THIS_MODULE, +}; + static ssize_t device_enable_show(struct config_item *item, char *page) { return sprintf(page, "%d\n", @@ -92,23 +224,22 @@ static struct config_group *root_make_group(struct config_group *group, return ERR_PTR(-ENOMEM); } - plane = vkms_config_create_plane(configfs->vkms_config); - crtc = vkms_config_create_crtc(configfs->vkms_config); - encoder = vkms_config_create_encoder(configfs->vkms_config); - - if (!plane || !crtc || !encoder || - vkms_config_plane_attach_crtc(plane, crtc) || - vkms_config_encoder_attach_crtc(encoder, crtc)) { + configfs->vkms_config_crtc = vkms_config_create_crtc(configfs->vkms_config); + configfs->vkms_config_encoder = vkms_config_create_encoder(configfs->vkms_config); + if (!configfs->vkms_config_crtc || !configfs->vkms_config_encoder || + vkms_config_encoder_attach_crtc(configfs->vkms_config_encoder, + configfs->vkms_config_crtc)) { vkms_config_destroy(configfs->vkms_config); kfree(configfs); return ERR_PTR(-ENOMEM); } - plane->type = DRM_PLANE_TYPE_PRIMARY; - config_group_init_type_name(&configfs->group, name, &device_item_type); + config_group_init_type_name(&configfs->plane_group, "planes", &planes_item_type); + configfs_add_default_group(&configfs->plane_group, &configfs->group); + return &configfs->group; } diff --git a/drivers/gpu/drm/vkms/vkms_configfs.h b/drivers/gpu/drm/vkms/vkms_configfs.h index ffacba6607018de44323fb6aa05cc6da8400a9f2..0f3701442691c23e33775fdd072701076d3d9387 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.h +++ b/drivers/gpu/drm/vkms/vkms_configfs.h @@ -19,15 +19,35 @@ struct vkms_configfs_device { struct config_group group; + struct config_group plane_group; + struct mutex lock; bool enabled; struct vkms_config *vkms_config; + struct vkms_config_crtc *vkms_config_crtc; + struct vkms_config_encoder *vkms_config_encoder; +}; + +struct vkms_configfs_plane { + struct config_group group; + + struct vkms_configfs_device *vkms_configfs_device; + struct vkms_config_plane *vkms_config_plane; }; #define config_item_to_vkms_configfs_device(item) \ container_of(to_config_group((item)), struct vkms_configfs_device, group) +#define planes_item_to_vkms_configfs_device(item) \ + config_item_to_vkms_configfs_device((item)->ci_parent) + +#define plane_item_to_vkms_configfs_device(item) \ + planes_item_to_vkms_configfs_device((item)->ci_parent) + +#define plane_item_to_vkms_configfs_plane(item) \ + container_of(to_config_group((item)), struct vkms_configfs_plane, group) + /* ConfigFS Support */ int vkms_init_configfs(void); void vkms_unregister_configfs(void); From patchwork Tue Jan 21 14:34:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946352 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 889A6C0218B for ; Tue, 21 Jan 2025 14:38:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E9C2F10E5D2; Tue, 21 Jan 2025 14:38:06 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="ITEEl9mT"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by gabe.freedesktop.org (Postfix) with ESMTPS id C420410E1F7 for ; Tue, 21 Jan 2025 14:38:04 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 92E21C000C; Tue, 21 Jan 2025 14:38:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470283; 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=h4kdCBDe9xuwsQeWubDH2efG7OBEWc4e+RRIWgqRgXU=; b=ITEEl9mTKsIXw1o9Wuzu4Dfusbn9Mwnv32K26DrWhM4eAVEjgQgT6srKRK0DTbsIx4nrGU rmVXrOVH2X27M2zLH5xw4LqpRimXSvVEHHG6fZ3YXvZSivrf6CJ4FPApzoLoGBnradFQwn Nu7hDP3xrBl2Y7HDrJ9N6czDqNsZn1rQbeaZZyUZWLhw6aWjk2al/V8t2mD6uZ1KyTOoHC jVV8MFwKxKNRc52JIgyvygfI2dyl850+kzkoZEee/3V4J2M9sTpAFep2DgelUD0N2DULVp kCo1LjEJQobejYDkTh/HeSiouccsjLQAGGxpSDFBRGCzlKYQYOZcsYok05YXuA== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:49 +0100 Subject: [PATCH RFC v3 05/14] drm/vkms: Introduce configfs for plane rotation MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-5-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=4695; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=sh1uavbHrltfBc1dqYD1CAI0M6uGSonUFdAxH2yw5fM=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7FBtcEAVABgB9edytn9wLYTtplp3sAj8OdJ1 hEQ9iZm0huJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xQQAKCRAgrS7GWxAs 4sLdEAC4eG769t1R5wWPSUR7hpPE03jOBpieFGxa6TRjI3jz+Zf4RhKSMFd//scQMvo1WMHPUIx NN96abXK5IEcxfiGT98yI1ky561pso9RhgO13hICxl7xBCD3O4rPznhP5tIjDBHfCYjm9da4R3V XzGZWdeoessXjAiG+GvVZ1AaFaVw3MQskJQM+Rrib1OlbGSTZbAXYPVHqpdflAmHnwNRFrqatwz OhWm+4J4oDU+Z81UHbZ5MP0qFoFN4ZQEhe3W0Ba6QnTN4liW7jQwyTYfdIgHL/WOFkT+n5mvcAq jzeXIX2rin8wafeXhqf0nd7eEWMfU3AHp2bje1vENp0odMwGmjA5/6gtgUIXfwrtQ+CCRKu/yNr J9OXumstQCybZlTESzcPqJ/B/FNXOL9Sc+HL3vyVJpseptcA/1AzaZIdkLlfwWiCjXWTiXvmj/u C0jyfmIrohhIMDDSKQNUzCk4jbrLbXs/SEdQCVMw+xGGeCTp8bF2m2ZyI1VJqCSDcut0Xn5B46i n3wYGHnJL/BTsQk5XDPHkyLtKvdDgmiE7ai9MHZ5p7jVUHJDGXaB++q9u4bS4L+ivR1MVJ7UW6B fW08+B3d6IUzEqD2v1hdfJglaEL9R0S3/W47ZvPK9BSxC/ujMDJ3jJOUyqpRpwppbmZr/SlarHO 3C2H9WJ0rMa6kzg== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to test many hardware configuration, introduce a new interface to configure the available rotation per planes. VKMS supports any rotation and reflection, so the userspace can choose any combination. The supported rotations are configured by writing a rotation bitmask to the file `supported_rotations` and the default rotation is chosen by writing a rotation bitmask to `default_rotation`. The current interface is: /config/vkms DEVICE_1 ┣━ enable ┣━ planes ┃ ┗━ PLANE_1 ┃ ┣━ type ┃ ┣━ supported_rotations ┃ ┗━ default_rotation DEVICE_2 ┗━ ditto Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 102 +++++++++++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index ee64243396b3e586f76ff0671441c172da022421..d121cf54e75238bdb582362596a353682cceebd3 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -54,10 +54,112 @@ static ssize_t plane_type_store(struct config_item *item, return count; } +static ssize_t plane_supported_rotations_show(struct config_item *item, char *page) +{ + struct vkms_config_plane *plane; + unsigned int plane_type; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + plane_type = plane->supported_rotations; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", plane_type); +} + +static ssize_t plane_supported_rotations_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_config_plane *plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + int ret, val = 0; + + ret = kstrtouint(page, 0, &val); + if (ret) + return ret; + + /* Should be a supported value */ + if (val & ~(DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK)) + return -EINVAL; + /* Should at least provide one rotation */ + if (!(val & DRM_MODE_ROTATE_MASK)) + return -EINVAL; + + mutex_lock(&vkms_configfs->lock); + + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + + /* Ensures that the default rotation is included in supported rotation */ + if (vkms_configfs->enabled || (val & plane->default_rotation) != plane->default_rotation) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + + plane->supported_rotations = val; + mutex_unlock(&vkms_configfs->lock); + + return count; +} + +static ssize_t plane_default_rotation_show(struct config_item *item, char *page) +{ + unsigned int plane_type; + struct vkms_config_plane *plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + plane_type = plane->default_rotation; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", plane_type); +} + +static ssize_t plane_default_rotation_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_config_plane *plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + int ret, val = 0; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + /* Should be a supported value */ + if (val & ~(DRM_MODE_ROTATE_MASK | DRM_MODE_REFLECT_MASK)) + return -EINVAL; + /* Should at least provide one rotation */ + if ((val & DRM_MODE_ROTATE_MASK) == 0) + return -EINVAL; + /* Should contains only one rotation */ + if (!is_power_of_2(val & DRM_MODE_ROTATE_MASK)) + return -EINVAL; + mutex_lock(&vkms_configfs->lock); + + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + + /* Ensures that the default rotation is included in supported rotation */ + if (vkms_configfs->enabled || + (val & plane->supported_rotations) != val) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + plane->default_rotation = val; + mutex_unlock(&vkms_configfs->lock); + + return count; +} + CONFIGFS_ATTR(plane_, type); +CONFIGFS_ATTR(plane_, supported_rotations); +CONFIGFS_ATTR(plane_, default_rotation); static struct configfs_attribute *plane_attrs[] = { &plane_attr_type, + &plane_attr_supported_rotations, + &plane_attr_default_rotation, NULL, }; From patchwork Tue Jan 21 14:34:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946361 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 02381C0218E for ; Tue, 21 Jan 2025 14:38:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A345C10E5DE; Tue, 21 Jan 2025 14:38:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="OZUUfthM"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by gabe.freedesktop.org (Postfix) with ESMTPS id E9D1110E5D3 for ; Tue, 21 Jan 2025 14:38:06 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id A5FFCC000F; Tue, 21 Jan 2025 14:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470285; 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=VUsKkmGAFs6k8Yn+KqxWP5wqz1X2+AvvPHUTijbIldY=; b=OZUUfthMGXZHtlfNQk2qnnJOTx8NeGoapIoFvEHJro3rAu3j+6hMWkWMuwwxcDSI8lfjiR a+yCR6L1z0jjbObWu+9O7G4pbzcP+YJiTdrLA3nzoXM/NYYeo/+OBsAlw5sK1FNOOn11k3 kFfU4oblQ4tGgEZQfmbZG2pPu/qVyeThmAODvm87ouY+RvZGu0XPGgLYYkW54DbRkjc/+z YlLFFZsiSc8C0Sk8f7oHe2Q+G5lzFMKt5EdoyfiWb32UAvdcG86l+FaRBIyXYQC9HjFBCn Y43nYTTQ5ORLLDmZXpwzmiFFOTmVY0dvZwpdF3UtdTWxy8EQ9G9s9QDuGPAWbA== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:50 +0100 Subject: [PATCH RFC v3 06/14] drm/vkms: Introduce configfs for crtc and encoder MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-6-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=20793; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=l+eBSQS58TyEh0+EXc/PnoVH5DKTBi+3J2IbJZ/0ZN4=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7FBxAvO6RcdtRh8eRbjvyG/FNQ6+TElxc/pk qYmdoNiVhmJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xQQAKCRAgrS7GWxAs 4ppPEACaY7JggZIixLD4jd2ZnwOXkw9/GnzQwXolvny4QuGOfZmg1B1Be0baESuPAiXgIH5NH3B gar3C/f2lI/0amBulx6DN05NBJK2ArYgbtxDf4j0eOFd52SAc9wGhnq7AmhUWyHF1mIeeBu3/bN inb5NNGfauUew0N6OHkN2/M/XlLf4kBMvj9DxhUlhBd+YyI94e2KGsDqnjoSOGF3NMUgxcK9hpD 91rhyid1Ldsxm98vYTJ4NqJpfP944MGwD2WoJVxyMp0hG42tbYPgIqE0o7bzQfp6y6YjXx/yLbc LgoW2i0rfYpR6BtIdgHBidE75e/diQBJL4hB1DwcDPj6wxyua6mP5S4CR5SAcPR39HZazfoyyoH 8Nef2uWH8ztySrY8vnPe5E8i0A9kMm4pLfQoqtJhrj+DsHWJdENGWP01DWsWN24hfZh1KEo9JdU 8AokGOQsWOjRRQq5ZRnzQlxY7VU/W8dHTCYPX8VE8lN6jxh+6U4/+2IMcCaMG4nJ+hsIQ5REHBF edHwOUZBwcZSad2+lYxK9iEIQhdVhzX6M/FcqMrlW/IhqMVef5keFybQUb0r2d64fFJWtwGxAwQ AopWKF6ZoZHnN8HWgeq1hvgV1R/SGhddFfoqKmZb7nnOZnQWBuWxSzWmoXbTPZKF9AeajREuttc olj0MoIOH3Klz0w== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to test many hardware configuration, introduce a new interface to configure CRTCs and encoders. The CRTCs and encoders are created in their own directory. To link the CRTC, symlinks are used in the `possible_crtcs` folders. The current interface is: /config/vkms DEVICE_1 ┣━ enable ┣━ planes ┃ ┗━ PLANE_1 ┃ ┣━ type ┃ ┣━ supported_rotations ┃ ┣━ supported_color_encoding ┃ ┣━ supported_color_ranges ┃ ┣━ default_rotation ┃ ┣━ default_color_encoding ┃ ┣━ default_color_range ┃ ┗━ possible_crtcs ┃ ┗━ >> /config/vkms/DEVICE_1/crtcs/CRTC_1 ┣━ encoders ┃ ┗━ ENCODER_1 ┃ ┗━ possible_crtcs ┃ ┗━ >> /config/vkms/DEVICE_1/crtcs/CRTC_1 ┣━ crtcs ┃ ┗━ CRTC_1 DEVICE_2 ┗━ ditto Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 401 +++++++++++++++++++++++++++++++++-- drivers/gpu/drm/vkms/vkms_configfs.h | 54 ++++- 2 files changed, 434 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index d121cf54e75238bdb582362596a353682cceebd3..9f41506849552960970aa08b9329b4f88d0aa8e7 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -5,6 +5,7 @@ #include #include #include +#include #include "vkms_configfs.h" #include "vkms_drv.h" @@ -185,6 +186,84 @@ static const struct config_item_type subgroup_plane = { .ct_owner = THIS_MODULE, }; +static const struct config_item_type crtc_item_type; +static const struct config_item_type planes_item_type; + +static int possible_crtcs_allow_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_configfs_device *vkms_configfs = plane_possible_crtc_src_item_to_vkms_configfs_device(src); + struct vkms_config_crtc *crtc; + + mutex_lock(&vkms_configfs->lock); + + if (target->ci_type != &crtc_item_type) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + + crtc = crtc_item_to_vkms_configfs_crtc(target)->vkms_config_crtc; + struct vkms_config_plane *plane = plane_possible_crtc_src_item_to_vkms_configfs_plane(src)->vkms_config_plane; + + struct vkms_config_crtc *crtc_entry; + unsigned long idx = 0; + + xa_for_each(&plane->possible_crtcs, idx, crtc_entry) { + if (crtc_entry == crtc) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + } + + if (vkms_config_plane_attach_crtc(plane, crtc)) + return -EINVAL; + + mutex_unlock(&vkms_configfs->lock); + + return 0; +} + +static void possible_crtcs_drop_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_config_crtc *crtc; + struct vkms_configfs_device *vkms_configfs = plane_possible_crtc_src_item_to_vkms_configfs_device(src); + + mutex_lock(&vkms_configfs->lock); + + crtc = crtc_item_to_vkms_configfs_crtc(target)->vkms_config_crtc; + struct vkms_config_plane *plane = plane_possible_crtc_src_item_to_vkms_configfs_plane(src)->vkms_config_plane; + + struct vkms_config_crtc *crtc_entry; + struct vkms_config_plane *plane_entry; + unsigned long crtc_idx = -1; + + xa_for_each(&plane->possible_crtcs, crtc_idx, crtc_entry) { + if (crtc_entry == crtc) + break; + } + unsigned long plane_idx = -1; + + xa_erase(&plane->possible_crtcs, crtc_idx); + xa_for_each(&crtc->possible_planes, plane_idx, plane_entry) { + if (plane_entry == plane) + break; + } + xa_erase(&crtc->possible_planes, plane_idx); + + mutex_unlock(&vkms_configfs->lock); +} + +static struct configfs_item_operations plane_possible_crtcs_item_ops = { + .allow_link = &possible_crtcs_allow_link, + .drop_link = &possible_crtcs_drop_link, +}; + +static struct config_item_type plane_possible_crtcs_group_type = { + .ct_item_ops = &plane_possible_crtcs_item_ops, + .ct_owner = THIS_MODULE, +}; + static struct config_group *planes_make_group(struct config_group *config_group, const char *name) { @@ -209,10 +288,7 @@ static struct config_group *planes_make_group(struct config_group *config_group, if (list_count_nodes(&vkms_configfs->vkms_config->planes) == 1) vkms_configfs_plane->vkms_config_plane->type = DRM_PLANE_TYPE_PRIMARY; - - if (!vkms_configfs_plane->vkms_config_plane || - vkms_config_plane_attach_crtc(vkms_configfs_plane->vkms_config_plane, - vkms_configfs->vkms_config_crtc)) { + if (!vkms_configfs_plane->vkms_config_plane) { kfree(vkms_configfs_plane); mutex_unlock(&vkms_configfs->lock); return ERR_PTR(-ENOMEM); @@ -229,7 +305,12 @@ static struct config_group *planes_make_group(struct config_group *config_group, config_group_init_type_name(&vkms_configfs_plane->group, name, &subgroup_plane); + config_group_init_type_name(&vkms_configfs_plane->possible_crtc_group, "possible_crtcs", + &plane_possible_crtcs_group_type); + configfs_add_default_group(&vkms_configfs_plane->possible_crtc_group, + &vkms_configfs_plane->group); vkms_configfs_plane->vkms_configfs_device = vkms_configfs; + mutex_unlock(&vkms_configfs->lock); return &vkms_configfs_plane->group; @@ -244,6 +325,283 @@ static const struct config_item_type planes_item_type = { .ct_owner = THIS_MODULE, }; +static void crtc_release(struct config_item *item) +{ + struct vkms_configfs_crtc *vkms_configfs_crtc = crtc_item_to_vkms_configfs_crtc(item); + + mutex_lock(&vkms_configfs_crtc->vkms_configfs_device->lock); + vkms_config_delete_crtc(vkms_configfs_crtc->vkms_config_crtc, + vkms_configfs_crtc->vkms_configfs_device->vkms_config); + mutex_unlock(&vkms_configfs_crtc->vkms_configfs_device->lock); + + kfree(vkms_configfs_crtc); +} + +static struct configfs_item_operations crtc_item_operations = { + .release = crtc_release, +}; + +static const struct config_item_type crtc_item_type = { + .ct_owner = THIS_MODULE, + .ct_item_ops = &crtc_item_operations, +}; + +static struct config_group *crtcs_make_group(struct config_group *config_group, + const char *name) +{ + struct config_item *root_item = config_group->cg_item.ci_parent; + struct vkms_configfs_device *vkms_configfs = config_item_to_vkms_configfs_device(root_item); + struct vkms_configfs_crtc *vkms_configfs_crtc; + + vkms_configfs_crtc = kzalloc(sizeof(*vkms_configfs_crtc), GFP_KERNEL); + + if (!vkms_configfs_crtc) + return ERR_PTR(-ENOMEM); + + mutex_lock(&vkms_configfs->lock); + vkms_configfs_crtc->vkms_configfs_device = vkms_configfs; + + if (vkms_configfs->enabled) { + kfree(vkms_configfs_crtc); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-EINVAL); + } + + vkms_configfs_crtc->vkms_config_crtc = vkms_config_create_crtc(vkms_configfs->vkms_config); + + if (!vkms_configfs_crtc->vkms_config_crtc) { + kfree(vkms_configfs_crtc); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-ENOMEM); + } + + vkms_configfs_crtc->vkms_config_crtc->name = kzalloc(strlen(name) + 1, GFP_KERNEL); + if (!vkms_configfs_crtc->vkms_config_crtc->name) { + kfree(vkms_configfs_crtc->vkms_config_crtc); + kfree(vkms_configfs_crtc); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-ENOMEM); + } + + vkms_configfs_crtc->vkms_configfs_device = vkms_configfs; + + strscpy(vkms_configfs_crtc->vkms_config_crtc->name, name, strlen(name) + 1); + config_group_init_type_name(&vkms_configfs_crtc->group, name, + &crtc_item_type); + + mutex_unlock(&vkms_configfs->lock); + + return &vkms_configfs_crtc->group; +} + +static struct configfs_group_operations crtcs_group_operations = { + .make_group = &crtcs_make_group, +}; + +static const struct config_item_type crtcs_item_type = { + .ct_group_ops = &crtcs_group_operations, + .ct_owner = THIS_MODULE, +}; + +static int encoder_possible_crtcs_allow_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_config_crtc *crtc; + struct vkms_configfs_device *vkms_configfs = encoder_possible_crtc_src_item_to_vkms_configfs_device(src); + + mutex_lock(&vkms_configfs->lock); + + if (target->ci_type != &crtc_item_type) { + DRM_ERROR("Unable to link non-CRTCs.\n"); + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + + crtc = crtc_item_to_vkms_configfs_crtc(target)->vkms_config_crtc; + struct vkms_config_encoder *encoder = encoder_possible_crtc_src_item_to_vkms_configfs_encoder(src)->vkms_config_encoder; + + struct vkms_config_crtc *crtc_entry; + unsigned long idx = 0; + + xa_for_each(&encoder->possible_crtcs, idx, crtc_entry) { + if (crtc_entry == crtc) { + pr_err("Tried to add two symlinks to the same CRTC from the same object.\n"); + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + } + + if (vkms_config_encoder_attach_crtc(encoder, crtc)) + return -EINVAL; + + mutex_unlock(&vkms_configfs->lock); + + return 0; +} + +static void encoder_possible_crtcs_drop_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_config_crtc *crtc; + struct vkms_configfs_device *vkms_configfs = encoder_possible_crtc_src_item_to_vkms_configfs_device(src); + + mutex_lock(&vkms_configfs->lock); + + crtc = crtc_item_to_vkms_configfs_crtc(target)->vkms_config_crtc; + struct vkms_config_encoder *encoder = encoder_possible_crtc_src_item_to_vkms_configfs_encoder(src)->vkms_config_encoder; + + struct vkms_config_encoder *encoder_entry; + struct vkms_config_crtc *crtc_entry; + unsigned long encoder_idx = -1; + unsigned long crtc_idx = -1; + + xa_for_each(&encoder->possible_crtcs, crtc_idx, crtc_entry) { + if (crtc_entry == crtc) + break; + } + xa_erase(&encoder->possible_crtcs, crtc_idx); + xa_for_each(&crtc->possible_encoders, encoder_idx, encoder_entry) { + if (encoder_entry == encoder) + break; + } + xa_erase(&crtc->possible_encoders, encoder_idx); + + mutex_unlock(&vkms_configfs->lock); +} + +static struct configfs_item_operations encoder_possible_crtcs_item_operations = { + .allow_link = &encoder_possible_crtcs_allow_link, + .drop_link = &encoder_possible_crtcs_drop_link, +}; + +static struct config_item_type encoder_possible_crtcs_item_type = { + .ct_item_ops = &encoder_possible_crtcs_item_operations, + .ct_owner = THIS_MODULE, +}; + +static void encoder_release(struct config_item *item) +{ + struct vkms_configfs_encoder *vkms_configfs_encoder = encoder_item_to_vkms_configfs_encoder(item); + + mutex_lock(&vkms_configfs_encoder->vkms_configfs_device->lock); + vkms_config_delete_encoder(vkms_configfs_encoder->vkms_config_encoder, + vkms_configfs_encoder->vkms_configfs_device->vkms_config); + mutex_unlock(&vkms_configfs_encoder->vkms_configfs_device->lock); + + kfree(vkms_configfs_encoder); +} + +static struct configfs_item_operations encoder_item_operations = { + .release = encoder_release, +}; + +static const struct config_item_type encoder_item_type = { + .ct_item_ops = &encoder_item_operations, + .ct_owner = THIS_MODULE, +}; + +static struct config_group *encoder_make_group(struct config_group *config_group, + const char *name) +{ + struct vkms_configfs_device *vkms_configfs = encoder_item_to_vkms_configfs_device(&config_group->cg_item); + struct vkms_configfs_encoder *vkms_configfs_encoder; + + vkms_configfs_encoder = kzalloc(sizeof(*vkms_configfs_encoder), GFP_KERNEL); + + if (!vkms_configfs_encoder) + return ERR_PTR(-ENOMEM); + + mutex_lock(&vkms_configfs->lock); + + if (vkms_configfs->enabled) { + kfree(vkms_configfs_encoder); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-EINVAL); + } + + vkms_configfs_encoder->vkms_config_encoder = vkms_config_create_encoder(vkms_configfs->vkms_config); + + if (!vkms_configfs_encoder->vkms_config_encoder) { + kfree(vkms_configfs_encoder); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-ENOMEM); + } + + vkms_configfs_encoder->vkms_config_encoder->name = kzalloc(strlen(name) + 1, GFP_KERNEL); + if (!vkms_configfs_encoder->vkms_config_encoder->name) { + kfree(vkms_configfs_encoder->vkms_config_encoder); + kfree(vkms_configfs_encoder); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-ENOMEM); + } + + strscpy(vkms_configfs_encoder->vkms_config_encoder->name, name, strlen(name) + 1); + config_group_init_type_name(&vkms_configfs_encoder->group, name, + &encoder_item_type); + + config_group_init_type_name(&vkms_configfs_encoder->possible_crtc_group, "possible_crtcs", + &encoder_possible_crtcs_item_type); + configfs_add_default_group(&vkms_configfs_encoder->possible_crtc_group, + &vkms_configfs_encoder->group); + vkms_configfs_encoder->vkms_configfs_device = vkms_configfs; + + mutex_unlock(&vkms_configfs->lock); + + return &vkms_configfs_encoder->group; +} + +static struct configfs_group_operations encoder_group_operations = { + .make_group = &encoder_make_group, +}; + +static const struct config_item_type encoders_item_type = { + .ct_group_ops = &encoder_group_operations, + .ct_owner = THIS_MODULE, +}; + +/** + * configfs_lock_dependencies() - In order to forbid the userspace to delete items when the + * device is enabled, mark all configfs items as dependent + * + * @vkms_configfs_device: Device to lock + */ +static void configfs_lock_dependencies(struct vkms_configfs_device *vkms_configfs_device) +{ + /* Lock the group itself */ + configfs_depend_item_unlocked(vkms_configfs_device->group.cg_subsys, + &vkms_configfs_device->group.cg_item); + /* Lock the planes elements */ + struct config_item *item; + + list_for_each_entry(item, &vkms_configfs_device->plane_group.cg_children, ci_entry) { + configfs_depend_item_unlocked(vkms_configfs_device->plane_group.cg_subsys, + item); + } + list_for_each_entry(item, &vkms_configfs_device->crtc_group.cg_children, ci_entry) { + configfs_depend_item_unlocked(vkms_configfs_device->crtc_group.cg_subsys, + item); + } +} + +/** + * configfs_unlock_dependencies() - Once the device is disable, its configuration can be modified. + * + * @vkms_configfs_device: Device to unlock + */ +static void configfs_unlock_dependencies(struct vkms_configfs_device *vkms_configfs_device) +{ + struct config_item *item; + + configfs_undepend_item_unlocked(&vkms_configfs_device->group.cg_item); + + list_for_each_entry(item, &vkms_configfs_device->plane_group.cg_children, ci_entry) { + configfs_undepend_item_unlocked(item); + } + list_for_each_entry(item, &vkms_configfs_device->crtc_group.cg_children, ci_entry) { + configfs_undepend_item_unlocked(item); + } +} + static ssize_t device_enable_show(struct config_item *item, char *page) { return sprintf(page, "%d\n", @@ -264,13 +622,25 @@ static ssize_t device_enable_store(struct config_item *item, return -EINVAL; mutex_lock(&vkms_configfs_device->lock); + if (vkms_configfs_device->enabled == value) { + mutex_unlock(&vkms_configfs_device->lock); + return (ssize_t)count; + } + + if (value && !vkms_config_is_valid(vkms_configfs_device->vkms_config)) { + mutex_unlock(&vkms_configfs_device->lock); + return -EINVAL; + } vkms_configfs_device->enabled = value; - if (value) + if (value) { + configfs_lock_dependencies(vkms_configfs_device); vkms_create(vkms_configfs_device->vkms_config); - else + } else { + configfs_unlock_dependencies(vkms_configfs_device); vkms_destroy(vkms_configfs_device->vkms_config); + } mutex_unlock(&vkms_configfs_device->lock); @@ -309,9 +679,6 @@ static const struct config_item_type device_item_type = { static struct config_group *root_make_group(struct config_group *group, const char *name) { - struct vkms_config_plane *plane; - struct vkms_config_crtc *crtc; - struct vkms_config_encoder *encoder; struct vkms_configfs_device *configfs = kzalloc(sizeof(*configfs), GFP_KERNEL); if (!configfs) @@ -326,22 +693,18 @@ static struct config_group *root_make_group(struct config_group *group, return ERR_PTR(-ENOMEM); } - configfs->vkms_config_crtc = vkms_config_create_crtc(configfs->vkms_config); - configfs->vkms_config_encoder = vkms_config_create_encoder(configfs->vkms_config); - if (!configfs->vkms_config_crtc || !configfs->vkms_config_encoder || - vkms_config_encoder_attach_crtc(configfs->vkms_config_encoder, - configfs->vkms_config_crtc)) { - vkms_config_destroy(configfs->vkms_config); - kfree(configfs); - return ERR_PTR(-ENOMEM); - } - config_group_init_type_name(&configfs->group, name, &device_item_type); config_group_init_type_name(&configfs->plane_group, "planes", &planes_item_type); configfs_add_default_group(&configfs->plane_group, &configfs->group); + config_group_init_type_name(&configfs->crtc_group, "crtcs", &crtcs_item_type); + configfs_add_default_group(&configfs->crtc_group, &configfs->group); + + config_group_init_type_name(&configfs->encoder_group, "encoders", &encoders_item_type); + configfs_add_default_group(&configfs->encoder_group, &configfs->group); + return &configfs->group; } diff --git a/drivers/gpu/drm/vkms/vkms_configfs.h b/drivers/gpu/drm/vkms/vkms_configfs.h index 0f3701442691c23e33775fdd072701076d3d9387..c033810f86ce467f564a14f74165198f12ea044c 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.h +++ b/drivers/gpu/drm/vkms/vkms_configfs.h @@ -20,34 +20,84 @@ struct vkms_configfs_device { struct config_group group; struct config_group plane_group; + struct config_group crtc_group; + struct config_group encoder_group; struct mutex lock; bool enabled; struct vkms_config *vkms_config; - struct vkms_config_crtc *vkms_config_crtc; - struct vkms_config_encoder *vkms_config_encoder; }; struct vkms_configfs_plane { struct config_group group; + struct config_group possible_crtc_group; struct vkms_configfs_device *vkms_configfs_device; struct vkms_config_plane *vkms_config_plane; }; +struct vkms_configfs_crtc { + struct config_group group; + + struct vkms_configfs_device *vkms_configfs_device; + struct vkms_config_crtc *vkms_config_crtc; +}; + +struct vkms_configfs_encoder { + /* must be first because it is a krefcounted stuff */ + struct config_group group; + + struct config_group possible_crtc_group; + struct vkms_configfs_device *vkms_configfs_device; + struct vkms_config_encoder *vkms_config_encoder; +}; + #define config_item_to_vkms_configfs_device(item) \ container_of(to_config_group((item)), struct vkms_configfs_device, group) #define planes_item_to_vkms_configfs_device(item) \ config_item_to_vkms_configfs_device((item)->ci_parent) +#define encoders_item_to_vkms_configfs_device(item) \ + config_item_to_vkms_configfs_device((item)->ci_parent) + +#define crtc_item_to_vkms_configfs_crtc(item) \ + container_of(to_config_group((item)), struct vkms_configfs_crtc, group) + +#define encoder_item_to_vkms_configfs_encoder(item) \ + container_of(to_config_group((item)), struct vkms_configfs_encoder, group) + #define plane_item_to_vkms_configfs_device(item) \ planes_item_to_vkms_configfs_device((item)->ci_parent) #define plane_item_to_vkms_configfs_plane(item) \ container_of(to_config_group((item)), struct vkms_configfs_plane, group) +#define plane_possible_crtc_src_item_to_vkms_configfs_device(item) \ + plane_item_to_vkms_configfs_device((item)->ci_parent) + +#define plane_possible_crtc_src_item_to_vkms_configfs_plane(item) \ + plane_item_to_vkms_configfs_plane((item)->ci_parent) + +#define crtc_item_to_vkms_configfs_device(item) \ + config_item_to_vkms_configfs_device((item)->ci_parent) + +#define crtc_child_item_to_vkms_configfs_device(item) \ + crtc_item_to_vkms_configfs_device((item)->ci_parent) + +#define encoder_item_to_vkms_configfs_device(item) \ + config_item_to_vkms_configfs_device((item)->ci_parent) + +#define encoder_child_item_to_vkms_configfs_device(item) \ + encoder_item_to_vkms_configfs_device((item)->ci_parent) + +#define encoder_possible_crtc_src_item_to_vkms_configfs_device(item) \ + encoder_child_item_to_vkms_configfs_device((item)->ci_parent) + +#define encoder_possible_crtc_src_item_to_vkms_configfs_encoder(item) \ + encoder_item_to_vkms_configfs_encoder((item)->ci_parent) + /* ConfigFS Support */ int vkms_init_configfs(void); void vkms_unregister_configfs(void); From patchwork Tue Jan 21 14:34:51 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946362 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 CB7FEC02182 for ; Tue, 21 Jan 2025 14:38:20 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A512C10E5DF; Tue, 21 Jan 2025 14:38:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="UvoOkkFl"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by gabe.freedesktop.org (Postfix) with ESMTPS id EB85F10E0E7 for ; Tue, 21 Jan 2025 14:38:07 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id CB2A0C001A; Tue, 21 Jan 2025 14:38:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470286; 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=TWf6dle4oNDqjM0MlplyHH6oLVNF+p+wzk0WWbB5dHo=; b=UvoOkkFlOSZ2j1LU1nfljVlCjXTNvM2Q/MgUi1baYLv1vlLGRgwWCQqqje4A9OE2CBvmqG UXC/t+xqUSDUtF/tbl71Yy0int0IKDnr/QJ7zehxqp7oh12MpsyWhSV+8kE1K+ARO5qJG1 f7emKAmjyAgngUfZ0UUrCXsR+s9AtV0G+LoLn4CjsB3gOZw3/ohtC0tQrBT+YD0ODlC3U/ dpdYv1sKOgMjy8a5sMk5gIeIrr0T5Iaus2a8C3gwXbxQ89JRQ0mOcZZwJ6AP7GPuPkBdSM tXljQ4wuHBF7H+9M7eLJDXgr+jjQHaLGval4SOLHP79GY/1N/2meGr7B6uA5Hg== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:51 +0100 Subject: [PATCH RFC v3 07/14] drm/vkms: Introduce configfs for connectors MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-7-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=11194; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=AXPdAOX6w84f5uQ0orGhE4wWMnbPuB5cHfFnGIy1IJo=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7FBjHdvHbEdQ+rp7D6VShmvPE1X1eTuiRt1q K2UEX18gIGJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xQQAKCRAgrS7GWxAs 4h9REACmj/tpeF0jj9DpSlOe0YnOhoa2Scx0hRiLRc3vFtjAaErshqASM3c3gJ+avS3zB5e+bZj yiWC6758ntHyNEO+WGZwUsKW/y6LSGU9qU8S2AKK0YTm/D5WYHhfTGEp2HiZFnOuBn26DaFDWB4 VFtdcwuyKoKLpfcIIXEys8C3pdUj7iM6YahrWb3hJ/oyh70jXyp6wALH8VeHZXP5OPykXoENT89 /Sy2yuaf9UInr+goNtgsq7Z0Oe/JmvyELiCcVV/0kzsCmt04OrFzkkNTXhdKQ7vr1X7iuel+zn3 zgyj4QH/SmSx3Jq/IhshBmaNi3ln05C3Y2QRou1uRjqCfFw3XQUW1cRZrfH/cTO6l+s8ut940RZ YrEqcxI36QNG+UDfZbA9VIiDtQlKAxPFxcxCbtDenxsyePxfGipvE7NkbZjMO0YfhEM4TK0xnyI tYFrOMYENDrkYpTGdw469Q3JJUaxqfMEmqW0XorL++zzKBz+MOIIvg5D2IVfiCVm3fAqelk9h6b S4KK1cUDLZNHl2KPNSL4plq4aiU/Ph9jq2kDTFgYDkhb+NcHuhC7eU6ykv2Upvwbl2cYwsWfzRP +91paql/AH9IWpLBHxU6oPPHDhF/+4Eor4JvIeX2xK4h+yVVzoV7ho5tFClByFFVxeLUhmcOb5d jyKo5dh9JlmViBQ== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to test many hardware configuration, introduce a new interface to create and configure connectors. The connectors are created by creating a directory in the `connectors` directory. Connectors and encoders can be linked by creating a symlink in the possible_encoders directory. The current interface is: /config/vkms DEVICE_1 ┣━ enable ┣━ planes ┃ ┗━ [...] ┣━ connectors ┃ ┗━ CONNECTOR_1 ┃ ┗━ possible_encoders ┃ ┗━ >> DEVICE_1/encoders/ENCODER_1 ┗━ encoders ┗━ ENCODER_1 Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_config.c | 13 ++++ drivers/gpu/drm/vkms/vkms_config.h | 3 + drivers/gpu/drm/vkms/vkms_configfs.c | 138 +++++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_configfs.h | 23 ++++++ 4 files changed, 177 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_config.c b/drivers/gpu/drm/vkms/vkms_config.c index 8ac9cd52cc00f7c317f2514a73c3d2f3908b085b..cb97bf292b72e9faf0050338fe845a254f691987 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -479,6 +479,19 @@ vkms_config_connector_attach_encoder(struct vkms_config_connector *vkms_config_c return ret; } +void vkms_config_connector_detach_encoder(struct vkms_config_connector *vkms_config_connector, + struct vkms_config_encoder *vkms_config_encoder) +{ + struct vkms_config_encoder *encoder_entry; + unsigned long encoder_idx; + + xa_for_each(&vkms_config_connector->possible_encoders, encoder_idx, encoder_entry) { + if (encoder_entry == vkms_config_encoder) + break; + } + xa_erase(&vkms_config_connector->possible_encoders, encoder_idx); +} + 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 2e5d2aa34a4f039c738cb9ac5642f3c75df36ba7..57cdf5fc2df1a62f57b4588c36ad0a99f63bee2a 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -189,6 +189,9 @@ int __must_check vkms_config_encoder_attach_crtc(struct vkms_config_encoder *vkm int __must_check vkms_config_connector_attach_encoder(struct vkms_config_connector *vkms_config_connector, struct vkms_config_encoder *vkms_config_encoder); +void vkms_config_connector_detach_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 * diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index 9f41506849552960970aa08b9329b4f88d0aa8e7..8bb3223c810dddb7d713ad4b01cece825f9939f6 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -536,6 +536,7 @@ static struct config_group *encoder_make_group(struct config_group *config_group } strscpy(vkms_configfs_encoder->vkms_config_encoder->name, name, strlen(name) + 1); + config_group_init_type_name(&vkms_configfs_encoder->group, name, &encoder_item_type); @@ -559,6 +560,139 @@ static const struct config_item_type encoders_item_type = { .ct_owner = THIS_MODULE, }; +static int connector_possible_encoders_allow_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_config_encoder *vkms_config_encoder; + struct vkms_configfs_device *vkms_configfs = + connector_possible_encoder_src_item_to_vkms_configfs_device + (src); + + mutex_lock(&vkms_configfs->lock); + + if (target->ci_type != &encoder_item_type) { + DRM_ERROR("Unable to link non-CRTCs.\n"); + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + + vkms_config_encoder = encoder_item_to_vkms_configfs_encoder(target) + ->vkms_config_encoder; + struct vkms_config_connector *vkms_config_connector = + connector_possible_encoder_src_item_to_vkms_configfs_connector + (src) + ->vkms_config_connector; + + if (vkms_config_connector_attach_encoder(vkms_config_connector, + vkms_config_encoder)) + return -EINVAL; + + mutex_unlock(&vkms_configfs->lock); + + return 0; +} + +static void connector_possible_encoders_drop_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_config_encoder *vkms_config_encoder; + struct vkms_configfs_device *vkms_configfs = + connector_possible_encoder_src_item_to_vkms_configfs_device(src); + + mutex_lock(&vkms_configfs->lock); + + vkms_config_encoder = encoder_item_to_vkms_configfs_encoder(target)->vkms_config_encoder; + struct vkms_config_connector *vkms_config_connector = + connector_possible_encoder_src_item_to_vkms_configfs_connector(src) + ->vkms_config_connector; + + vkms_config_connector_detach_encoder(vkms_config_connector, vkms_config_encoder); + + mutex_unlock(&vkms_configfs->lock); +} + +static struct configfs_item_operations connector_possible_encoders_item_operations = { + .allow_link = &connector_possible_encoders_allow_link, + .drop_link = &connector_possible_encoders_drop_link, +}; + +static struct config_item_type connector_possible_encoders_item_type = { + .ct_item_ops = &connector_possible_encoders_item_operations, + .ct_owner = THIS_MODULE, +}; + +static void connector_release(struct config_item *item) +{ + struct vkms_configfs_connector *vkms_configfs_connector = + connector_item_to_vkms_configfs_connector(item); + + mutex_lock(&vkms_configfs_connector->vkms_configfs_device->lock); + vkms_config_delete_connector(vkms_configfs_connector->vkms_config_connector); + mutex_unlock(&vkms_configfs_connector->vkms_configfs_device->lock); + + kfree(vkms_configfs_connector); +} + +static struct configfs_item_operations connector_item_operations = { + .release = connector_release, +}; + +static const struct config_item_type connector_item_type = { + .ct_item_ops = &connector_item_operations, + .ct_owner = THIS_MODULE, +}; + +static struct config_group *connector_make_group(struct config_group *config_group, + const char *name) +{ + struct vkms_configfs_device *vkms_configfs = + connector_item_to_vkms_configfs_device(&config_group->cg_item); + struct vkms_configfs_connector *vkms_configfs_connector; + + vkms_configfs_connector = kzalloc(sizeof(*vkms_configfs_connector), GFP_KERNEL); + + if (!vkms_configfs_connector) + return ERR_PTR(-ENOMEM); + + mutex_lock(&vkms_configfs->lock); + + if (vkms_configfs->enabled) { + kfree(vkms_configfs_connector); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-EINVAL); + } + + vkms_configfs_connector->vkms_config_connector = + vkms_config_create_connector(vkms_configfs->vkms_config); + + if (!vkms_configfs_connector->vkms_config_connector) { + kfree(vkms_configfs_connector); + mutex_unlock(&vkms_configfs->lock); + return ERR_PTR(-ENOMEM); + } + + config_group_init_type_name(&vkms_configfs_connector->group, name, &connector_item_type); + + config_group_init_type_name(&vkms_configfs_connector->possible_encoder_group, + "possible_encoders", &connector_possible_encoders_item_type); + configfs_add_default_group(&vkms_configfs_connector->possible_encoder_group, + &vkms_configfs_connector->group); + vkms_configfs_connector->vkms_configfs_device = vkms_configfs; + + mutex_unlock(&vkms_configfs->lock); + + return &vkms_configfs_connector->group; +} + +static struct configfs_group_operations connector_group_operations = { + .make_group = &connector_make_group, +}; + +static const struct config_item_type connectors_item_type = { + .ct_group_ops = &connector_group_operations, + .ct_owner = THIS_MODULE, +}; + /** * configfs_lock_dependencies() - In order to forbid the userspace to delete items when the * device is enabled, mark all configfs items as dependent @@ -705,6 +839,10 @@ static struct config_group *root_make_group(struct config_group *group, config_group_init_type_name(&configfs->encoder_group, "encoders", &encoders_item_type); configfs_add_default_group(&configfs->encoder_group, &configfs->group); + config_group_init_type_name(&configfs->connector_group, "connectors", + &connectors_item_type); + configfs_add_default_group(&configfs->connector_group, &configfs->group); + return &configfs->group; } diff --git a/drivers/gpu/drm/vkms/vkms_configfs.h b/drivers/gpu/drm/vkms/vkms_configfs.h index c033810f86ce467f564a14f74165198f12ea044c..5e13941df3382ed30770e79a0432bf37764d7c59 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.h +++ b/drivers/gpu/drm/vkms/vkms_configfs.h @@ -22,6 +22,7 @@ struct vkms_configfs_device { struct config_group plane_group; struct config_group crtc_group; struct config_group encoder_group; + struct config_group connector_group; struct mutex lock; bool enabled; @@ -53,6 +54,14 @@ struct vkms_configfs_encoder { struct vkms_config_encoder *vkms_config_encoder; }; +struct vkms_configfs_connector { + struct config_group group; + + struct config_group possible_encoder_group; + struct vkms_configfs_device *vkms_configfs_device; + struct vkms_config_connector *vkms_config_connector; +}; + #define config_item_to_vkms_configfs_device(item) \ container_of(to_config_group((item)), struct vkms_configfs_device, group) @@ -68,6 +77,9 @@ struct vkms_configfs_encoder { #define encoder_item_to_vkms_configfs_encoder(item) \ container_of(to_config_group((item)), struct vkms_configfs_encoder, group) +#define connector_item_to_vkms_configfs_connector(item) \ + container_of(to_config_group((item)), struct vkms_configfs_connector, group) + #define plane_item_to_vkms_configfs_device(item) \ planes_item_to_vkms_configfs_device((item)->ci_parent) @@ -89,14 +101,25 @@ struct vkms_configfs_encoder { #define encoder_item_to_vkms_configfs_device(item) \ config_item_to_vkms_configfs_device((item)->ci_parent) +#define connector_item_to_vkms_configfs_device(item) \ + config_item_to_vkms_configfs_device((item)->ci_parent) + #define encoder_child_item_to_vkms_configfs_device(item) \ encoder_item_to_vkms_configfs_device((item)->ci_parent) #define encoder_possible_crtc_src_item_to_vkms_configfs_device(item) \ encoder_child_item_to_vkms_configfs_device((item)->ci_parent) +#define connector_child_item_to_vkms_configfs_device(item) \ + connector_item_to_vkms_configfs_device((item)->ci_parent) + +#define connector_possible_encoder_src_item_to_vkms_configfs_device(item) \ + connector_child_item_to_vkms_configfs_device((item)->ci_parent) + #define encoder_possible_crtc_src_item_to_vkms_configfs_encoder(item) \ encoder_item_to_vkms_configfs_encoder((item)->ci_parent) +#define connector_possible_encoder_src_item_to_vkms_configfs_connector(item) \ + connector_item_to_vkms_configfs_connector((item)->ci_parent) /* ConfigFS Support */ int vkms_init_configfs(void); From patchwork Tue Jan 21 14:34:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946360 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 375E1C0218C for ; Tue, 21 Jan 2025 14:38:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8E5AF10E5DC; Tue, 21 Jan 2025 14:38:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="EieIFKQl"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0F2DB10E0E7 for ; Tue, 21 Jan 2025 14:38:08 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id CED82C0004; Tue, 21 Jan 2025 14:38:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470287; 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=y2AG+SekWjl6u9VvxwoAYEavv+hkp5txg1P7sPS35uA=; b=EieIFKQlKqSF8FUdqvBG60LKKGoLehI54OpbEHNc7VvebPtz3XbkXfIlLhcvZTjabEeLdD GDNHoXeHfJW72ttF6cZG5JUW/sx4yUo+SMHVNredJuOoKeh3IVRYUudviHKARNa3d9MAk3 N1sqHlw8TmkEQtQprOh1F4uwMYBryFGrDGCFXFUWDcza0gWZr0BCP9Xv1VA1G7ltMru2FA /4Ved5mFEEHM2XBsPvaoWPMNRq2GqLgX8+kLWXkSpl9vyYtiVWtRoTz1659Obiw1wwa3kB U6D/7bmqzTpaAhpomxz8S+vxDgiIao065uNgYHYgCGByZi2y+dp53NgkAW5VZw== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:52 +0100 Subject: [PATCH RFC v3 08/14] drm/vkms: Introduce configfs for connector type MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-8-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3441; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=XNwYAF+nVvs1wVarheQorDdkzMZEXBdkjAOYLwB9GdI=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7FCnC9S0p60fBDiN7sXUB98zfJjwfMuBD6p1 Bra96dQ/S+JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xQgAKCRAgrS7GWxAs 4kUrD/90TYiUyzAs5ysi++7EUyOCndV3h6nNDbF4OjsKsblGR6nR8j/cP7UXu8caQFAJO1gWaCF lV+Vo/zfrBwyo03297uHwcNDvKWuC3z5q5pvUKqachUtpKwom6DjxOSMNMpDFs9joiYNBWX4Zci MmtY4MDZORLDPaUkb7eavNTof7iYoBJ4djMHWaLXSRslJ2dExA6r9Nv8MxMxNmpiVNh5m4g6t4S Ftb60xPEyTNNPpzY83SUdKHBpmj2fhoIkv48KI/OlkFub5OW7BcoA6AGeU8sOXrAlOT3NsJTwGn QBGU9e5Va5BQM9owc7R/V8za10iFGXPH161kMmCfKdcZdCbh3IV4/nhSlphCRAYARnbvvS1nMaV 5gTHmkuvxCtALTZVWQdCE4lrkdEmWzswm4WnL8ReVtHBEemmFVlM2oLaWyCzhKgAnMKW5Hej3lm rh3lgWJWblbuLRU7ALw9Tfv8pUiAtqJRvq8lEY4at7NxL8ocjMUta0vNGnGeEryBT60QN0Li+F7 +NrySTImpgDnOad28/pwqvWdB7A0XFzpQBEV2BELKgQ6aeUBERuCsBIKQsm3xk52e8PRsWmxJ45 yK2jT3Doy0eDNShxJQLWJImZefdVg50FZ/TEZKBM3r8QAy3cO7FwB2NdP8mibCBg2AnuqbNSwYS seTfmq271UBGBLQ== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to test many hardware configuration, introduce a new interface to change a connector type. The type of a connector can be changed by editing the file type and by writing the connector type number. The current interface is: /config/vkms DEVICE_1 ┣━ enable ┣━ planes ┃ ┗━ [...] ┣━ connectors ┃ ┗━ CONNECTOR_1 ┃ ┣━ possible_encoders ┃ ┗━ type ┗━ encoders ┗━ [...] Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 71 ++++++++++++++++++++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index 8bb3223c810dddb7d713ad4b01cece825f9939f6..5f416260f209fc98939f8addd175e5c3b8e35353 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -633,12 +633,83 @@ static void connector_release(struct config_item *item) kfree(vkms_configfs_connector); } +static ssize_t connector_type_show(struct config_item *item, char *page) +{ + struct vkms_config_connector *connector; + int connector_type; + struct vkms_configfs_device *vkms_configfs = connector_child_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + connector = connector_item_to_vkms_configfs_connector(item)->vkms_config_connector; + connector_type = connector->type; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", connector_type); +} + +static ssize_t connector_type_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_config_connector *connector; + int val = DRM_MODE_CONNECTOR_VIRTUAL; + struct vkms_configfs_device *vkms_configfs = connector_child_item_to_vkms_configfs_device(item); + int ret; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + switch (val) { + case DRM_MODE_CONNECTOR_Unknown: + case DRM_MODE_CONNECTOR_VGA: + case DRM_MODE_CONNECTOR_DVII: + case DRM_MODE_CONNECTOR_DVID: + case DRM_MODE_CONNECTOR_DVIA: + case DRM_MODE_CONNECTOR_Composite: + case DRM_MODE_CONNECTOR_SVIDEO: + case DRM_MODE_CONNECTOR_LVDS: + case DRM_MODE_CONNECTOR_Component: + case DRM_MODE_CONNECTOR_9PinDIN: + case DRM_MODE_CONNECTOR_DisplayPort: + case DRM_MODE_CONNECTOR_HDMIA: + case DRM_MODE_CONNECTOR_HDMIB: + case DRM_MODE_CONNECTOR_TV: + case DRM_MODE_CONNECTOR_eDP: + case DRM_MODE_CONNECTOR_VIRTUAL: + case DRM_MODE_CONNECTOR_DSI: + case DRM_MODE_CONNECTOR_DPI: + case DRM_MODE_CONNECTOR_SPI: + case DRM_MODE_CONNECTOR_USB: + break; + default: + return -EINVAL; + } + + scoped_guard(mutex, &vkms_configfs->lock) { + if (vkms_configfs->enabled) + return -EINVAL; + + connector = connector_item_to_vkms_configfs_connector(item)->vkms_config_connector; + connector->type = val; + } + + return count; +} + +CONFIGFS_ATTR(connector_, type); + +static struct configfs_attribute *connector_attrs[] = { + &connector_attr_type, + NULL, +}; + static struct configfs_item_operations connector_item_operations = { .release = connector_release, }; static const struct config_item_type connector_item_type = { .ct_item_ops = &connector_item_operations, + .ct_attrs = connector_attrs, .ct_owner = THIS_MODULE, }; From patchwork Tue Jan 21 14:34:53 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946359 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 4FE48C0218B for ; Tue, 21 Jan 2025 14:38:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5F16E10E5D9; Tue, 21 Jan 2025 14:38:15 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="irVH5x98"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0BBEC10E0E7 for ; Tue, 21 Jan 2025 14:38:09 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id DC723C0005; Tue, 21 Jan 2025 14:38:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470288; 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=bQdDURrLCeyHMFocs4AD2ik95r7Ex45a/kM7X1LnMy8=; b=irVH5x98+bMtwaDny2JlkBm4qODiHYgjFtO1jXJsGP44cKmpefxGTZrpLxrvfTGW4f4UgU R2inRfCmwCEd/QaWZZE0w4QmDSEu1ns/lvo3caqVJXjNy8U2PLeiJircFiZ3no/eXQkmes hfLHtJMm4p1JPMbbRRjeteZ+bBSkmb4+3wI1rqTiyxhZyfdl/vIWrwRwbsdEVVxGhi4XyS +LxeHluSkVhGkMBWa7vr1fDRhgaQuMxtETpdC+Cm3yRetepCkGSi1fy/8n1zEfXc2AxMpK XC5Vn5jP4GfivVTHi2dNfU89hgpqMZUGX+w9U5ztg21q/fdI3mdh+x7rJCkboQ== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:53 +0100 Subject: [PATCH RFC v3 09/14] drm/vkms: Introduce configfs for plane format MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-9-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=3805; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=59ocMuZiKn0fV0F1JxnVDqXfFu8e2TcR6P2zV61+WKo=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7FCYoG0GfdRnCp1NhRxufEbP0kgQtojZ6trQ WnNaQybJZeJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xQgAKCRAgrS7GWxAs 4ifCEACsvxKnaceQPUhXik1Yja+4yaFdUZEEoQZoPnSd71bZ9NzbwRLq0RwWErN7byPIxQn/drY UA0ghneMD6Xqi10Evp6N6RhGFNrB8kPCINXccAALnns143YNcn/OAvgSkjjVChelma6fvi/naCq S1XzBTXBjPZ7fd8qyfbu7hAi0P0CS2y2MDU6YAtwKRlxRNpsdtb0Vb4i6Ij6g8Xo0g74v3VIFAx SA3hqnCIHAO5naxeK0lVKANrasRjKkm2vssw1oZiPiepkeWN2V9drpRNkDi7GOehtIl9mdofaO4 ZjLonN52WuKQg4pkchtq8hCfjUDr9lQZ6lqSHnDdT91mnMxCS4TlDXup7qISDeTLkg1/4NxtDXa 6qPUtlCO1Bs+TjYqi5H8gb+s3/Rwgfx7zAyzmbenT0ErF5BJC7WjnLN01Fvj8a/Mn3dbEU1mVBR XZU1th3j4JTRtpBeIm/k6cot41n53JzglhVw514TkBuEYMjjwtguqXTQAZYZw//YMiJ272s5rbe sPdFz0AMy+6ZAeBQAAH2wRxJV9OoiekoLMk9UX+LpvxS6msw4ebw8xQrbcFTOCziPk6g5RpSZqj Cuxsfnm4gNnVFMqIH5+wp1GQzy1dfw3xCYhUpN5Q4eJjgxnbx4wdeNApMjeGTJmGGAPYAH1B9kY nkqXzayyPew2loQ== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to test many hardware configuration, introduce a new interface to configure the available formats per planes. VKMS supports many formats, so the userspace can choose any combination of them. The supported formats are configured by writing in the file supported_formats: - `+*` - Add all available formats - `-*` - Remove all formats - `+` - Add the format (for example `+AR24` to add ARGB8888 format) - `-` - Remove the format The current interface is: /config/vkms DEVICE_1 ┣━ enable ┗━ planes ┗━ PLANE_1 ┗━ supported_formats Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 75 ++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index 5f416260f209fc98939f8addd175e5c3b8e35353..eeb0c1e1b225f2a1a35ac6deb9457b90ba6542e5 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -153,14 +153,89 @@ static ssize_t plane_default_rotation_store(struct config_item *item, return count; } +static ssize_t plane_supported_formats_show(struct config_item *item, char *page) +{ + struct vkms_config_plane *plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + page[0] = '\0'; + + scoped_guard(mutex, &vkms_configfs->lock) + { + for (int i = 0; i < plane->supported_formats_count; i++) { + char tmp[6] = { 0 }; + const ssize_t ret = snprintf(tmp, ARRAY_SIZE(tmp), "%.*s\n", + (int)sizeof(plane->supported_formats[i]), + (char *)&plane->supported_formats[i]); + if (ret < 0) + return ret; + /* Limitation of ConfigFS attributes, an attribute can't be bigger than PAGE_SIZE */ + if (ret + strlen(page) > PAGE_SIZE - 1) + return -ENOMEM; + strncat(page, tmp, ARRAY_SIZE(tmp)); + } + } + + return strlen(page); +} + +static ssize_t plane_supported_formats_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_config_plane *plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + int ret = 0; + int ptr = 0; + + scoped_guard(mutex, &vkms_configfs->lock) + { + while (ptr < count) { + if (page[ptr] == '+') { + char tmp[4] = { ' ', ' ', ' ', ' ' }; + + memcpy(tmp, &page[ptr + 1], min(sizeof(tmp), count - (ptr + 1))); + if (tmp[0] == '*') { + ret = vkms_config_plane_add_all_formats(plane); + if (ret) + return ret; + ptr += 1; + } else { + ret = vkms_config_plane_add_format(plane, *(int *)tmp); + if (ret) + return ret; + ptr += 4; + } + } else if (page[ptr] == '-') { + char tmp[4] = { ' ', ' ', ' ', ' ' }; + + memcpy(tmp, &page[ptr + 1], min(sizeof(tmp), count - (ptr + 1))); + if (tmp[0] == '*') { + vkms_config_plane_remove_all_formats(plane); + ptr += 1; + } else { + vkms_config_plane_remove_format(plane, *(int *)tmp); + + ptr += 4; + } + } + /* Skip anything that is not a + or a - */ + ptr += 1; + } + } + + return count; +} + CONFIGFS_ATTR(plane_, type); CONFIGFS_ATTR(plane_, supported_rotations); CONFIGFS_ATTR(plane_, default_rotation); +CONFIGFS_ATTR(plane_, supported_formats); static struct configfs_attribute *plane_attrs[] = { &plane_attr_type, &plane_attr_supported_rotations, &plane_attr_default_rotation, + &plane_attr_supported_formats, NULL, }; From patchwork Tue Jan 21 14:34:54 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946358 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 99F74C0218D for ; Tue, 21 Jan 2025 14:38:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E90EA10E5D8; Tue, 21 Jan 2025 14:38:15 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="lAzhUjYz"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by gabe.freedesktop.org (Postfix) with ESMTPS id 295A010E5D9 for ; Tue, 21 Jan 2025 14:38:11 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id E5E84C0013; Tue, 21 Jan 2025 14:38:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470289; 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=rT/oqkmtB9cijaiL9lDgfKvYzJqMxUaAub35WR3p/3U=; b=lAzhUjYzdFB7c3mneC/XmAbMwFPac8mbflotUekD5sjC4swrpRZ13sGE/4XZpOjp1CiWPz /3RcUGXhLamIZQGqk7Dl8GYMwLH9KmstFhduko5N4QUe3f0c6iib8IiG79bGUb5X/DN/CP 8hSeS7jlV2zp8PMANQbpM6NRjW9JYPhkXOqI9dG4n7h225nZVvG4tIe36xDcQEhyVHnp2Q +coS9bnlZ3+82rt/ot0kZTJ8IJL3uhCbNW/6qd+qgLNj6Ew2Qr4NAN+rZv2DVU0didUUgj EbeYxYnYy74XMeDiEofwvBGekMAY+eyVI3kPhUlf0feL32GTaBnSGXsGoPOGNQ== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:54 +0100 Subject: [PATCH RFC v3 10/14] drm/vkms: Introduce configfs for device name MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-10-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1415; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=GBQ7JzpZcLe0OOn0aZ2W0MmxaOx2G1PAWm82kEXTnl0=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7FCZ4QKkm3W+y5H+KYypp+zcp4E7kDRYnQdR PVtmAO1qRSJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xQgAKCRAgrS7GWxAs 4kxkD/wP1GcgDe3vWuTqb+9KrdXu+JEiiUVcVAXUZALeFJaUZ868q4DHEQ5iZSNvveTd+A51Be4 CyO6/B1CRIXuIhdrFiNiXcKdWM6r0U1SvmUII2gxJatKXIVNDMg7VA3s45RqG2ZBM4rC/jAcifB 2ElHshy6uL/lKJEVYuYJiBsUI0+0aKmi+Hx9dsn64i406fa9H6kiFCsLu1mu0XbWnP0MU9d3xHV 0I/xS+cuEdigTIvzYRVyECiLbao+dAwE4QT5Xlnc0FMqA1uujpUDJXR94kFBpixSmtPCHVHqLEa +7BYFLGinaLlohYaa+LBwI/zAaonj8elD/WA9/ohndZIp7OK0jtZBP+h/++1nE7cLDvlbCGpPzX NnTBtcCMwpp1Rs+y29jBXXY1hdpYOIqzLh1/6TxMgvvZg8kyRNznESDeq65VSAgF9wrKM4adMl7 Tx77y4k1K+y11OLlCZHKsLNE1JQAtksuf2uhLjcUE++YB3Kf0BE9LDSDQ0IPqBs9Et60CFLLlmh dXq1dmlo0SCgeE+M0u4e3IeA3QPeQ2oNo/WNJ0n6q2BykF+7x6aT4K7W2lbPvAVLu35kFjP0V/C 9Bo7u/SJUHir52ObNoz48yfTZgjAryVkC2doXcoKsXME8SfZdJfyCoZonK0kjMmlEmf+XQF6VKk EwoJ6DNggVW/F3A== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to identify the device once it is enabled, create a file to fetch it. This file can only be read once the device is enabled, and will return the device name, which can later be used to use it. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index eeb0c1e1b225f2a1a35ac6deb9457b90ba6542e5..d0bc6adfdae85b82ca043d318f84fca70840526c 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -927,10 +927,26 @@ static ssize_t device_enable_store(struct config_item *item, return (ssize_t)count; } +static ssize_t device_device_name_show(struct config_item *item, char *page) +{ + struct vkms_configfs_device *configfs_device = config_item_to_vkms_configfs_device(item); + + scoped_guard(mutex, &configfs_device->lock) + { + if (configfs_device->enabled) + return sprintf(page, "%s\n", + dev_name(configfs_device->vkms_config->dev->drm.dev)); + return -EINVAL; + } + return -EINVAL; +} + CONFIGFS_ATTR(device_, enable); +CONFIGFS_ATTR_RO(device_, device_name); static struct configfs_attribute *device_attrs[] = { &device_attr_enable, + &device_attr_device_name, NULL, }; From patchwork Tue Jan 21 14:34:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946355 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 CE2ABC02182 for ; Tue, 21 Jan 2025 14:38:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3F47C10E0E7; Tue, 21 Jan 2025 14:38:15 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="QzFdpQCM"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2504610E0E7 for ; Tue, 21 Jan 2025 14:38:12 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 097B9C0010; Tue, 21 Jan 2025 14:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470290; 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=NX98o/Rl6NdAlU9ltpjlyQYuJMH4YW29knwFHP1bdzM=; b=QzFdpQCMv3l0wUEp1U4LxD58jA6Erl6A/MouEig8+X6WbmZ0gPuSrTgXig8FEKIRYlC0sM u7QImBC2SP/zK3uaHqi1DDNBdp6D4fAalY8cZwgXFAUw/RO7P8nahg4Ac4hg9zcKfyao6t FLTw/KgqWfWuXjWnRGJmeYwtY4vrxgv55Rnh+l8k7NsOPOOUUSRk4A8csR6wPcbWpGYbCh FKbqY7q0I7oQ+AHClYCq9w0+sf7Mi4/PSeDOapr8F7X219HC7IvVmLfyDD//iIZG2rjUIq 88VqKvUzSi/HSpEeNX+BsJZaTTOnyMrLEkEIz9NyutetQCoXtDfU/PWUKkAamA== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:55 +0100 Subject: [PATCH RFC v3 11/14] drm/vkms: Introduce configfs for connector status MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-11-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2230; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=Zf2mHAfhpssSgBnJiUlEoh26cihTH7swHtR1ZXs7sHw=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7FDLcIqxCqEWSNHW+CT+XzDL1Nj/jv83+qH7 lBzQX6T5fiJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xQwAKCRAgrS7GWxAs 4j56EACKu6hjW2ZaKZZyJhC/UtS3JdQsQVgerNiIC8XLQujUBFYbRWgAIScea34TTsKDq+PEIPs hjlT+4+k03kkgQT7jAnPX5Jcp+3RTI1+jBeIKE13EVVngOFFHuD3Z5vCzY/a4/uAvuUviPI3Z3U ucVexo9U0iI6xSCd3OooumAC//xUIj1gRuUVdPnX15q3GLNfcLVhCrUY9fUDXoru8UK8lZi3Vs8 4kozq8nI4XP7Za8Fuy5VfyGQ38W2ulh1Z43DsFTHYMTrm4Ija6IBRvOyYFsYnx1PBVXFYWQNU5j Eqc4MWg95XpE/1E6J9TgyQGiAmXLfGJFsVPE5KHUcCx4cKgc7A2sBiwoTP8lA9VKm6jrjWW402a NqSjZE7kILcL6A/Bpg882AFHPCCa+JpOQMQF6fAPQyqobTaYmeRwKAItsmIAoVRv7rv5XKEoNz5 djMUapp/3hSx8poK6Q9FUjVlg4pKmWY1qfe2KNUtAwl/E2ZbHp6c9wLe36QR9GV4F2vdKCOihTV gijZHtIq3hDQgsjPFiTzkjm1vlyBgT2IRKwiZ3bN5XdSzcRnA3TlDQDsIZqtvFqDd+hTkX7t5Wy j2RJmK922xBX8QiK8sT1Kqg41TduCugY1YEnn+8G9t3YrbGKOy69vKtJf2inM4kzOpEXcrOHxKP oGLy4GU8e69zwfg== 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 connector can be connected and disconnected once a device is created, create a file to allow changing this status. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 45 ++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index d0bc6adfdae85b82ca043d318f84fca70840526c..09d9ac3cb3e25e980473686b7b0d2e66e78cf163 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -771,10 +771,55 @@ static ssize_t connector_type_store(struct config_item *item, return count; } +static ssize_t connector_status_show(struct config_item *item, char *page) +{ + struct vkms_config_connector *connector; + enum drm_connector_status status; + struct vkms_configfs_device *vkms_configfs = connector_child_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + connector = connector_item_to_vkms_configfs_connector(item)->vkms_config_connector; + status = connector->status; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", status); +} + +static ssize_t connector_status_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_config_connector *connector; + enum drm_connector_status status = connector_status_unknown; + struct vkms_configfs_device *vkms_configfs = connector_child_item_to_vkms_configfs_device(item); + int ret; + + ret = kstrtouint(page, 10, &status); + if (ret) + return ret; + + switch (status) { + case connector_status_unknown: + case connector_status_connected: + case connector_status_disconnected: + break; + default: + return -EINVAL; + } + + scoped_guard(mutex, &vkms_configfs->lock) { + connector = connector_item_to_vkms_configfs_connector(item)->vkms_config_connector; + vkms_config_connector_update_status(connector, status); + } + + return count; +} + CONFIGFS_ATTR(connector_, type); +CONFIGFS_ATTR(connector_, status); static struct configfs_attribute *connector_attrs[] = { &connector_attr_type, + &connector_attr_status, NULL, }; From patchwork Tue Jan 21 14:34:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946357 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 5FACDC02182 for ; Tue, 21 Jan 2025 14:38:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 441FA10E5D3; Tue, 21 Jan 2025 14:38:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="QVRz11X+"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4061310E5D5 for ; Tue, 21 Jan 2025 14:38:13 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 096D9C000C; Tue, 21 Jan 2025 14:38:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470292; 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=QuufuVa/g1o21UorwLjFyv4koJbCSFzjFYgF/podHmw=; b=QVRz11X+qDTY9MoeglEk3G4W7VmbPKcUHe+dQeHEeR8pjbIkVNgbXdQ8rZVUPaiQuHmDA6 6xpkCL7sDJr9c0CBMvpDJfsfWTTY0ZDaDSzK3kw+PSFyIzrTLFUW2Tqap6oGkxkr4VOmBF EAZ8rCxXjty3ZTcK6D8KRKKJES57r/vuQNQZaHB+6XISNxrnzwrv2LYRMDWw7b1p8OcQ5K qOpffbPQQeSENifB+OhDDufHRaOFrCdl8hZCqgprhCp5ulm2b4xiWQ2VWh8XFTw1DDTCDF 0mGUItGHsqYnPvwOVxY4KSna1+G+Kl1sMF2EaNO16NizoRKf0Lq43ItE6XCe/Q== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:56 +0100 Subject: [PATCH RFC v3 12/14] drm/vkms: Introduce configfs for connector id MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-12-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=1444; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=l8g6VjX5NCcSXOoIqBvGFqtrZkGAS8ayIn0WYIC8uI8=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7FDsg8CdITBHzn2RQlXGvPE3hRUCY38A9s+T sOm9xG6x3uJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xQwAKCRAgrS7GWxAs 4vbUEADDwBtu3eCQtJYERUFeVWZ0I9XyoMfTHnqewzpop4wPVpqHi9SUkjLtqPdbosEPiivbXSK /5nMC6ZdPCQOoYLF131JbsCtrNOcAbVNPI9C2gjiLlhaJAybfGPPxjmuyCb0k/APbkwLW48RsDu Qty7VD6JUGTXHNB2jjR6pABMfLwlF+BaihSRnN/DcwvAa/BiVSTVKg6NnHO7fTXv69/r6Cor9VV YPyf4X1efjZw8vxMHmuC90mzaHQkFe7jqYhsvbdhcqK0700PDn+A2H9tQPqIbpZGb4N7ydZztiN bPHBpfZA2D3/vhqQ1dAk89uqkuAvWe+22y4HMxrKJZwnlByXh3i5dwrFEC9sDQcVqjBb0AuFNUy s0ExeZnG42x/NA18BSXdxRPieYm49TPvedrmc6tDkB06G2/gKadSw9wrlDGBDRX9RaIAQ1t9C++ KZeeCK8d+U630VUhxnEdben9OUCkdtCom0HAPoizsLLjJZEogT6LlzpgRDSXuGK8r2cf/kek/+N CFnjjtUc+AuNd5K5NC/OMPIJd4UHnfvLkjh4l7giW4VdvXnAiGMHz6IilE6ysU79e12UJ5yHUQM qu2kJq+mRm6IxDLruUpWbVKCfWbZPAp7RF7fUiGxxLIZP++YqDKltVih+dc5S+bLOA9udUJ0afu lHPrOK+fr8f4XPw== 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" A connector can't be identified by a name, so add a configfs file to retrieve its id. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index 09d9ac3cb3e25e980473686b7b0d2e66e78cf163..76f28862c7652fbd9e84c42b60ad818ddee1485b 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -814,12 +814,31 @@ static ssize_t connector_status_store(struct config_item *item, return count; } +static ssize_t connector_id_show(struct config_item *item, char *page) +{ + struct vkms_configfs_device *vkms_configfs = + connector_child_item_to_vkms_configfs_device(item); + struct vkms_config_connector *connector; + + scoped_guard(mutex, &vkms_configfs->lock) + { + connector = connector_item_to_vkms_configfs_connector(item)->vkms_config_connector; + if (vkms_configfs->enabled) + return sprintf(page, "%d\n", + connector->connector->base.id); + return -EINVAL; + } + return -EINVAL; +} + CONFIGFS_ATTR(connector_, type); CONFIGFS_ATTR(connector_, status); +CONFIGFS_ATTR_RO(connector_, id); static struct configfs_attribute *connector_attrs[] = { &connector_attr_type, &connector_attr_status, + &connector_attr_id, NULL, }; From patchwork Tue Jan 21 14:34:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946356 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 02EFFC0218C for ; Tue, 21 Jan 2025 14:38:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3F9EB10E5D5; Tue, 21 Jan 2025 14:38:15 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="YA0i0VLy"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::226]) by gabe.freedesktop.org (Postfix) with ESMTPS id 49BF810E5D5 for ; Tue, 21 Jan 2025 14:38:14 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 1F12CC0011; Tue, 21 Jan 2025 14:38:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470293; 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=OFQ4Ff8PV/nQ3otAFU0pTp2obHz+6vw8l94Fypiq9Co=; b=YA0i0VLysGRnSoxKzQhmCpa0mijD7zPf1oYkPHXO+IVWToEbb4tzJ/1bd7MWhPJL3goZti N5rZMztoL+lZ6NzUjZ/cDBXsD91fTnd6ZeyWYlrRJJ4pzOF2t2OnwzGeOJmhIrMRI7O9cb fQWYgRlAJhTavAyi9kiI/9fWdco/ZOJWGWVLmeJ2nYmdiJKzIHK2ONik9ZnPp1GXhsjdxn E0NCqU9MGqxmZT2eyY7UqgIK4srQQWmfCtGsUakWFOxGLfgxy3LeUakIgDRAkt9dIMQ3iW SRBZaBO9Bs58YK9O5Qj0Lf7LZ0euZqI/ngahWseih21ILqzw9zWFRPhLXGxSTg== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:57 +0100 Subject: [PATCH RFC v3 13/14] drm/vkms: Introduce configfs for connector EDID MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-13-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2441; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=74KM1HCxeJ9rIki3nH8P7Jl+BhT1o7myjLxUUlO3Zbk=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7FDWykG7DumlhiIaLE+2dhJiHi63l/Ckduqy Z+9t7wN3VCJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xQwAKCRAgrS7GWxAs 4pNYEACEbe3iBCi8a1zrun+ZzRhdFpRNewPtswtul3FQp1KopGzpaATQ2+WDAJ4xZLdY5m2YqPy 7hFi5gOTNIWe86KZUqz8AiVVqMLuS01Pn6xgDH08ZIRil+Ui6PAwQ6+QReObyGmMjhhNE0pxmLC N25c7YdyyL7n/UoetL0aFjQBr2KeMCXHNBpw1EW5M2AHsgvPsJwr6S2PurZz2xdhwvSh0mDf22d wPCtkbVicmFGbNK4Yud3//BVg8HPlPvc20lwrpb84XgfdVYCXMAWS7PRXRFb9e1UiRH43YF6gig y4trOq3CPm/ip56uUAgrY+fK8XiTeyfuqee2YcIReZ2yl5kznJxVQx5/ML0TPIFHRKTtGOEiBuJ 7xccnQL2f5u3anIYtKOSKLitC2AOuB+FC6FZWZ+MDWaFRa0+p/h9jn2OzzRG4pZtfFLs19o3+P9 b2T/Ha/k9LlEBkgXiGy82bXBjQNgDhaOeYUFoLzfIZ4OqWysaK/xvfqqONTaXNA6Ib2+jWAJI8Z 5t/Gswqh4THslK8mYZGHFlooJUNqSM9uRoC0Ue8JLFDvpAXl8Sn+DMWM/SaHzWVeWs6r4/bEbiY H1fFO8s/+P7im27LYroNMEohYcs0XCW3gNOepWrSpKT9o/a3M5/SWwSfwscIlxkX2YPkfYQZq4w 7420Vhs3nyqSRgA== 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" Due to limitation of ConfigFS, the max len of EDID is PAGE_SIZE (4kB on x86), it should be sufficient for many tests. One possible evolution is using a ConfigFS blob to allow bigger EDID. The EDID can be changed at any time. As for physical display, you need to trigger an HPD event to refresh the modes. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index 76f28862c7652fbd9e84c42b60ad818ddee1485b..547b76d67c4cd1f9c2fb20e45f0f0583fa03b59a 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -814,6 +814,37 @@ static ssize_t connector_status_store(struct config_item *item, return count; } +static ssize_t connector_edid_show(struct config_item *item, char *page) +{ + struct vkms_config_connector *connector; + struct vkms_configfs_device *vkms_configfs = connector_child_item_to_vkms_configfs_device(item); + + scoped_guard(mutex, &vkms_configfs->lock) + { + connector = connector_item_to_vkms_configfs_connector(item)->vkms_config_connector; + memcpy(page, &connector->edid_blob, connector->edid_blob_len); + return connector->edid_blob_len; + } + + return -EINVAL; +} + +static ssize_t connector_edid_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_configfs_device *vkms_configfs = connector_child_item_to_vkms_configfs_device(item); + + scoped_guard(mutex, &vkms_configfs->lock) + { + struct vkms_config_connector *connector = + connector_item_to_vkms_configfs_connector(item)->vkms_config_connector; + memcpy(&connector->edid_blob, page, count); + connector->edid_blob_len = count; + } + + return count; +} + static ssize_t connector_id_show(struct config_item *item, char *page) { struct vkms_configfs_device *vkms_configfs = @@ -833,12 +864,14 @@ static ssize_t connector_id_show(struct config_item *item, char *page) CONFIGFS_ATTR(connector_, type); CONFIGFS_ATTR(connector_, status); +CONFIGFS_ATTR(connector_, edid); CONFIGFS_ATTR_RO(connector_, id); static struct configfs_attribute *connector_attrs[] = { &connector_attr_type, &connector_attr_status, &connector_attr_id, + &connector_attr_edid, NULL, }; From patchwork Tue Jan 21 14:34:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13946363 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 E2193C0218B for ; Tue, 21 Jan 2025 14:38:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 61CE910E5DA; Tue, 21 Jan 2025 14:38:31 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="SOB8O30Z"; dkim-atps=neutral Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5EBC110E5D7 for ; Tue, 21 Jan 2025 14:38:15 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 27287C0004; Tue, 21 Jan 2025 14:38:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1737470294; 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=u4FW97gmv0h8v6YZVl7BcMluaaWrqGSIDWALmXfXyf4=; b=SOB8O30ZvZMfAg/U/DmPeydfe0P/N0ur4FnUDJvXkScKtOuzHIUOllodl2N/91VPtrB2jE 50Epk2tIkd1EHuqN5+GJRrXX2g78yWPm59SUJAwE46klCbl4QaLP0tcwwuJlSC28bzeSSX 2wVWK8O2rsV9sLAOdDqa0DRp4K74y6MPIfaWgPEzL/lRxd4rw2I5mEWCPF+/5JknbcV3yr cJqiNZOdHsb0SqE62/gtMTBYKCdp3zsLaLZYir3u2Ghwe648Fly2zlAr0Iw/gRSb+IpFBC kdzmBq7jKZg/Lwia13/J/MZ8PzMwSgkppRXsgwr04qLQns4Do6xOmx1M3O/yOg== From: Louis Chauvet Date: Tue, 21 Jan 2025 15:34:58 +0100 Subject: [PATCH RFC v3 14/14] drm/vkms: Introduce configfs for encoder type MIME-Version: 1.0 Message-Id: <20250121-google-config-fs-v3-14-8154a6945142@bootlin.com> References: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> In-Reply-To: <20250121-google-config-fs-v3-0-8154a6945142@bootlin.com> To: Rodrigo Siqueira , Melissa Wen , =?utf-8?q?Ma=C3=ADra_Canal?= , Haneen Mohammed , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Simona Vetter , Simona Vetter Cc: jose.exposito89@gmail.com, dri-devel@lists.freedesktop.org, arthurgrillo@riseup.net, linux-kernel@vger.kernel.org, jeremie.dautheribes@bootlin.com, miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com, seanpaul@google.com, nicolejadeyee@google.com, Louis Chauvet X-Mailer: b4 0.15-dev X-Developer-Signature: v=1; a=openpgp-sha256; l=2882; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=9jSFWvf5VmPPMVhisDd6GJDN4cLc45xFfuqW/qC8DN0=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnj7FE4zPy3IFkf02hziZ05eEyHbNKtEK5j01zy uuW66pNgJCJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ4+xRAAKCRAgrS7GWxAs 4ju4EADVEou2XXCds+pr2DdT2xfJRCFOAA+E8pdOJuAu8ZaDK7KZyiYFAF36LXtEW4sxermIafz PBvPRP/kqAqG1zVw/ywXFB9FtvhD2n8SKl9iXTQxmwxWsw7JbTlyKqzw2dq2eieyfubf2kEht51 79udId+47rWUMYjJOEMNov2W1bdaQxTyMU3S+WmwxZYJGkADW/aZNvO/DO1MNknABfeQwkJf/B/ SUcGFg9ttZsw6G4Ete72Tn1YNttd9dPyeNKC0/2QpWiPqC2tVk/cRCkJ43gmUJQIhQXaYuiZegU L0Q6QTT/okpxv4gEPt6d+KKyGJK8HODkTLIrecVViDf3Ay1jVEP7Yh944KV46V6ye2FdJ8NgvOb QwOItLRTdVUhATQOMOtxdxJ29LDCjwdtov96wgtC/flSHRuXeDxNa7YPX4rPvBVmcqhZ5PjR0fX xgcauGFuHnJFRJQSgn3jue4+Qrp9cpaOpE4qphFTtCjOOJ3+66PjZO/pFDvZbINnlBHLGZ5rnhg MzaZXiCskXfGZjzHJj+33GeO8TqgnfmQ5JfDOOhgwJt3v0c4BzpLGYpqq7cwxu/tLRt0emApb66 nZW5+UBNzYFuzONrs8pvoBhroBnzddreG4fJLnlCXO2zqdyH8cetnF33meogqwQF/BLUFD3sLrr lcre+76Q6NNJd1A== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In order to support multiple configuration, add the possibility to change the encoder type. Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 57 ++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index 547b76d67c4cd1f9c2fb20e45f0f0583fa03b59a..dd4de385dadbdb24647cc59debb0284f94033b4b 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ +#include "drm/drm_mode.h" #include #include #include @@ -544,6 +545,61 @@ static void encoder_possible_crtcs_drop_link(struct config_item *src, mutex_unlock(&vkms_configfs->lock); } +static ssize_t encoder_type_show(struct config_item *item, char *page) +{ + struct vkms_config_encoder *encoder; + char encoder_type = DRM_MODE_ENCODER_NONE; + struct vkms_configfs_device *vkms_configfs = encoder_item_to_vkms_configfs_device(item); + + scoped_guard(mutex, &vkms_configfs->lock) + { + encoder = encoder_item_to_vkms_configfs_encoder(item)->vkms_config_encoder; + encoder_type = encoder->type; + } + + return sprintf(page, "%u", encoder_type); +} + +static ssize_t encoder_type_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_configfs_device *vkms_configfs = encoder_item_to_vkms_configfs_device(item); + int val = DRM_MODE_ENCODER_VIRTUAL; + struct vkms_config_encoder *encoder; + int ret; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + if (val != DRM_MODE_ENCODER_DAC && + val != DRM_MODE_ENCODER_DPI && + val != DRM_MODE_ENCODER_DSI && + val != DRM_MODE_ENCODER_LVDS && + val != DRM_MODE_ENCODER_NONE && + val != DRM_MODE_ENCODER_TMDS && + val != DRM_MODE_ENCODER_TVDAC && + val != DRM_MODE_ENCODER_VIRTUAL) + return -EINVAL; + + scoped_guard(mutex, &vkms_configfs->lock) { + if (vkms_configfs->enabled) + return -EINVAL; + + encoder = encoder_item_to_vkms_configfs_encoder(item)->vkms_config_encoder; + encoder->type = val; + } + + return count; +} + +CONFIGFS_ATTR(encoder_, type); + +static struct configfs_attribute *encoder_attrs[] = { + &encoder_attr_type, + NULL, +}; + static struct configfs_item_operations encoder_possible_crtcs_item_operations = { .allow_link = &encoder_possible_crtcs_allow_link, .drop_link = &encoder_possible_crtcs_drop_link, @@ -572,6 +628,7 @@ static struct configfs_item_operations encoder_item_operations = { static const struct config_item_type encoder_item_type = { .ct_item_ops = &encoder_item_operations, + .ct_attrs = encoder_attrs, .ct_owner = THIS_MODULE, };