From patchwork Fri Nov 22 17:38:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883477 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 AF0C4E69185 for ; Fri, 22 Nov 2024 17:39:00 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0678310EC29; Fri, 22 Nov 2024 17:39:00 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="TvYfvOqT"; 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 AB90D10E1DD for ; Fri, 22 Nov 2024 17:38:58 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 5CBD2C0005; Fri, 22 Nov 2024 17:38:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297137; 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=FBkM1WMn2Ucut+MxptAqo72bzc6IetcnqSt6Z29iw1I=; b=TvYfvOqT+LpCytteXXJNt06lkYZbEGRUjKc6UmCPnhs+aOtDAtaJgE/fYIMhBi3i7ULsDm OOXicL7vllKFSf0pD8bsOsFzaYxgUvwYWIqQpkkwgVIefd/0bYUfd4WW35StebJIzdAp1C qpiwoJcV2W6+zKuuGv87zHPLjZz/Vf6geyNPAq2rIRPnCPcOX6pQ4i1JKuCd+qSAYBWWuj oFJKivG0cca+5mUXtZPPWisZYNjV47UptCNNcaFFp+VlgA8lQ8tx3ZtWDg6xdx3zqPjt00 899n7yTUXkLlZh0oFkDRJ7iiCh1TOlWBkxqfmHSEMBxoZ5OrLwM2E3Q5lE7O8g== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:27 +0100 Subject: [PATCH RFC v2 01/16] drm/vkms: Add vkms_delete/create_device helper MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-1-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=arFPfBvkyojFw2UpPJF4s2GkOllumMgZfpsQfgBfcuE=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGpCQj8Jt9fbd6PpIlfJ2MZdP1Sg5XKYX29J OQFgYT93d2JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBqQAKCRAgrS7GWxAs 4obYEACwzMhDfuO1In8gQEcRttWndvFngdxSb4RmW7W/ZRR9C7+qpQpyBErmwQ2RRllmXBVsFmG cINoA29G4KxnR/V6J2Ve8GDjFxnid5EnbnVQbbExbUSQlxv7W88KpU7cEPfRkvmlLz4fvETSMeN eUI+Wo7yxdDm1W2qHbK6hVKZ5E9s82X0+qruP54DWzUOsv10FrzkFYqkJ0YUb8w2VQAp7DDr6Zb uXs6tsyT6jgDYCRvVlA+46FhbTocRI5MMJA84jj4F5vLhvrlO1GjpPWxRejQ6FBuWutuiNfUVLM ornYXmJhWxkR41w+TIlXYuWDlLzd0LLcbQp7c2UeCpq7AYzjN9tykHDZOzufR+jRFlTaw1e9NJa GkuIvNkoaiOLr75xnJr4GQRe2865VET7FDM3FCNigHCP02sJBocQR6/fD8/BbjdoJkPBkm1x7Gg foAf0k+pVtVk4LBVBhUcVvD5G7aEJ7VMwDwEYYskIrqHtpvS8I856vACGfDdqWjdvmqfl/CM2xE eHSvdrpwFGYhT6KwdqMbp18lVMWyRF4/XE8xTSTIa/KdlUW3Q7wkiU4COpznfD5YnyaVsgsAMK3 os1zOraueJOhRnUdTa48fYExpEFdZ1jv1/liOnnHurbj76C7s6z3x7HxEM8o1v5iq1JjBgNGutN E1AkicuK+SaDTLg== 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 eb6fd570b4549639f6818ff63fb334f2a461b23d..2db393f5782eb26a5aa469a4774b2e19c886ee7e 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -152,7 +152,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; @@ -226,7 +226,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 a772bf4168e11730c6ee2e3c79abce3a6351203f..5521d59f775170d828dea734b4ed3d177debdd0d 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -231,6 +231,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 Fri Nov 22 17:38:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883480 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 2A007E69183 for ; Fri, 22 Nov 2024 17:39:06 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 768D910EC40; Fri, 22 Nov 2024 17:39:04 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="AR9XbNNA"; 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 9A51410E1DD for ; Fri, 22 Nov 2024 17:38:59 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 64108C0009; Fri, 22 Nov 2024 17:38:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297138; 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=+JIvAjvsKfMMqoQ/DDIqtqiqCN3QonaGjVg5xDbExiM=; b=AR9XbNNAtUhmpdCYZ54mayzqLmtJMIZePEkoc1rBwJf8z/by16E6N1+p5vvPLV6AuSKWEi FJi+WUIVieWD74xhipWK1/p2Ef9LuV1457BT3FU62WHPThCpdt/i63J9Zf4bM1axNrzYIc y6Esx8D1fXXkxpqsdrHF9r2eA6fenFqmeClZQiThQhjfYqBd29fAWM7Xefw00oWZvW8fzj Le2ofrvZpUMOFrWbFG+IGeQvfZxjK4KaswT/BYsRfP6M12iSlFZU8xtdl1XM0Oc9Dbx3L+ vySwCHE4AOg+tlweXINBIQxxyMhblJuLezcQ5R3IK4ddmUaubJOS+vsOzhmqBA== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:28 +0100 Subject: [PATCH RFC v2 02/16] drm/vkms: Cleanup configuration field on device destroy MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-2-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=2929; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=qkqGvXdE+RYqqpCJhtuKm5uZqampj5EK592AfaLuMxY=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGpqhTRcF3pCxMiUMLvZ4SK62LF7gVbIsWcq GVik7bwlK2JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBqQAKCRAgrS7GWxAs 4oSyEACH2huQsRPxrNntm4efoX6jA9LzcdBB3qe4XV2avjFhSjZCyHKKYHidnBZm+gHE5sm5+xi 0HlvVZbPYCE7dbfL/nAXvbdbCj9PtYGT6w79eyeCMYmsnos3D9EPyi+dBTpAbUzAw5HLgLyeTCP SEdm7wkboOGvtRlmLz0hFJQcP+/SOIKD2tTjbbe6+ucO5HtwejSmudD4nahWexcAVD2PNsTOknS e2AWW73DftMkGpTWepyFXZZ5hMS1Jcd0WPdWJcjDqNrE2rKNGSipE8wPsVFHHR+uq6eKtk02WPa AiPtMLGTqx93yOBNnCdIwEMPsq1BkfCbBtevtkFk6eXgv2W/U4s7wH/7FBmyCvNOQFWX/UxmkiC fGYcMvdi6NQ0mDogecj+RcuHcsLHrgb0f4m0VpQmCdH/zstsszwu7YyJOylSCrsTH1hNE+3oYhg ifqkP8oeM8rPNpTzCcnAN9PF3hFrXHmGpfmu6Sh6DcmhkIst4/n7E4MmeNoGK3Oo35OGTBKuUN/ kLMhA32Tfv26kZAlJ7iQorQRe690yYsVAf8ZvE9PnYIi7NKhLPOlDtQPCRBhH/T0U5HvLRY4s88 Ay3zRD4rlIvLQVIaO4QmDIRSpgGTODSs4d2nKVKFQV4tOk7CUMf8ZRgnfm9Ef9wgDFS+1ME3+PK zL9HsGX4dkhKQBw== 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 26280ad223208a978c44ef9c6c6eaadf1756818d..9a461a0481c2a20d6d48f1aa9649843ad1b7d13d 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -204,6 +204,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->crtc = 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 c6fe0573abd899e4b44b5ad390ff72e12664973f..529d9c99f3c406d49dc7f3689a84c3dd775399a9 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -117,10 +117,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 2db393f5782eb26a5aa469a4774b2e19c886ee7e..8ffbd5fc65350ba03f870726b669d189f62bad6f 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -242,7 +242,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 Fri Nov 22 17:38:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883481 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 5E8ABE69186 for ; Fri, 22 Nov 2024 17:39:07 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 71B1D10EC3F; Fri, 22 Nov 2024 17:39:04 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="Zv0BUU4d"; 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 A8D0810E1DD for ; Fri, 22 Nov 2024 17:39:00 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 76AF6C0003; Fri, 22 Nov 2024 17:38:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297139; 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=0C9YB1veERoN1gqcAKiUSPViHEGCVo6K+wlUcDmmo2k=; b=Zv0BUU4doGx9xPSRM62Q01p4dZfoOeqWk4OL2qtEm+si61zlht9tfZzcXTFVnM62M/MlV4 gqDYalvL3dzqkKUyD0JnLZcztanPSl/MBV+6nLkVOtajhWtIV61aLezzeoFvvu8Aq8vGZe 3ADHCnNn3Uk7qLjRxEzcZEJM8kQ9O7PZyxdHqlzXH6vEec/qUBGP78bbAkq77PnMHvBmGZ R7lP+sWbqZ5UJJc2TyqfsgiebMObDCrhIkKsRdNEyg7C65AKRHXm8emxbnjDq9Yv9cYUZJ aZc5LC3NfQ2zq3ohBWlLcG92Eo6Xg569LGOPzlhrqBDcd+RQoHLWVGyz7Zz81w== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:29 +0100 Subject: [PATCH RFC v2 03/16] drm/vkms: Introduce ConfigFS interface MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-3-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=8270; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=TVSRHX+oI96zpI0b9tInVblON27/3sZGP4z6jTdwubU=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGpRy5p4p1cpaQTueHayo7ir3p76af9N7PKt yT+xwoR9vCJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBqQAKCRAgrS7GWxAs 4mIdD/9BT4PZaJ4VqeZPyeIFvyzeUYT8SvBDaqSDtc9I+iVnsW3tkRJDpeOUwPWXKXJhuXMy+X7 DnGzwcEoEwE3cRkExJC8N08uv9AbdHkUHi9yuUi7AtIHzVoe5v8YXU0YnkFb6/ccyPZfoav9bGt spP050RQYbicevndKX3SfGb2uwGHngYYF0I/H4fYQQDy+5LZfGFAXo2wbCGwBacK/DinpNmhM4G bLgyz+oe45BBiDDrmIjeZcO8OMwIIktDS5fl4Kj1rCBHuOoKw/MN/r/q6gGHhULxjmhKcDwyKev De09rJ1Bx3KPzYsRaT4EffgcUUAm5w6PX5zh5clO4/LvSmS7xhQsYWOtBhQudr3YQLV1WXQpHWO auQNunVySDwdJbWEVewbYKULIy5jSslCHnL8aFOL8Rlx4ZjcWoagVGq+rpaoPpjhzgXn8V3o6nS PbUYCCBe+ETU+ksb8ZTBQQEfUsslgZJqfyZsDNpeSodAw/Hrsy8Lzo1JgC0gb8E3CGcgwheNCtX fnHlgGBJx6IOHjE1Oub1uUPBfUnH1vAAvna42rBJeinHwCEtR6ej67ghNW+8b3BgvrlulEcVsY+ HuxctkVAtr5y0davFVRY/HWukx+cAJ6ZMuOwqEUSRy9JfEln91NEriN4NJA6pJZxLO4lNl2fnu3 gwnksaA0aCFNN+w== 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 d4665e913de7702fbd5c0f047876dad9715c690a..71fe9124bf18dd5b17b0989077e1cf1f8f1ee963 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 2b6db5870b977f6e5013982af89a48aec6c11983..9ecf6bc4779f81cac2677a3595c0bf4ebd1448bd 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..3de89c9c552c6603396f38a98ad35263f04bce26 --- /dev/null +++ b/drivers/gpu/drm/vkms/vkms_configfs.h @@ -0,0 +1,35 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ + +#include +#include + +#ifndef _VKMS_CONFIGFS_H +#define _VKMS_CONFIGFS_H + +/** + * struct vkms_configfs_device - Internal object to manage all the configfs items related to one + * device + * + * @group: Main configfs group for a device + * @platform_device: If a device was created (@enabled = true), stores a pointer to it + * @lock: Mutex used to avoid conflicting edition of @vkms_config + * @enabled: Store if the device was created or not + * @vkms_config: Current vkms configuration + */ +struct vkms_configfs_device { + struct config_group group; + + struct mutex lock; + bool enabled; + + struct vkms_config *vkms_config; +}; + +#define config_item_to_vkms_configfs_device(item) \ + container_of(to_config_group((item)), struct vkms_configfs_device, group) + +/* ConfigFS Support */ +int vkms_init_configfs(void); +void vkms_unregister_configfs(void); + +#endif /* _VKMS_CONFIGFS_H */ diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 8ffbd5fc65350ba03f870726b669d189f62bad6f..cdf51df78802cd096b71cfc76678a9ebdd06df1a 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 @@ -158,7 +159,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); @@ -219,9 +220,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; } @@ -251,6 +260,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 Fri Nov 22 17:38:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883484 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 2D529E69187 for ; Fri, 22 Nov 2024 17:39:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8427D10EC41; Fri, 22 Nov 2024 17:39:05 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="XHLm6lKy"; 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 C43B310E1DD for ; Fri, 22 Nov 2024 17:39:01 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 893BEC0004; Fri, 22 Nov 2024 17:38:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297140; 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=5J8/1qIVEDgIv2xfQh9Kc681w0PsuNe7kBPqYu98OwA=; b=XHLm6lKydp86udKEjYAIhXJLWEegcN7GLr3g6X38pZGiQY+zPTHZUqBcxpGdZCxG81vOa4 MKuKlbfxMyVOIIAYFFaJTc0uMKLygAr+zCsfaLDO2Iznpx1gYqInluU50H1e5CNFw9UIRc PUxcYoY+ZBGYVXi6LgzuuzHt0Lpda6KfDLxLhzn5+l8uMheSd6rDHSU0B0t+TOWQxfuVym iaNP/1yoPMf9DdQTXHTRg3+oeGQiVSxOp2b1zrmCrVP+MHHw8klIHnVzCP+fzBBhojSXLp 6ioiEgoudjPB3mTiQkkfp0He4/7vTpHNU0Kce99SfUvmmxJ/74CJ2v0dbrucfQ== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:30 +0100 Subject: [PATCH RFC v2 04/16] drm/vkms: Introduce configfs for plane MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-4-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=usRPIC9dVvBKQW8H9D4zLMZm/e80qaVYBx0ziInZwU0=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGq2IGl9SOkWOMRuhoWxTsY2gJrG3pDHLL5D Qd5VRQzCVGJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBqgAKCRAgrS7GWxAs 4qrQD/wOFmEr7vWk8UFB8KSo+JvNCP92X9ut8wmCMB7Y8mo8vBtjRDxdBoksZtzbnG4XFIv21Yu 3xropWVcyZsB2P20SLAK9wKn9D26m9+65giJo5xgwQY+ZY7JPuDRfGySzQ8/UhzL9i10x3w4UB7 ryvTrYQkjraMCxdh3WO7/7b1MGA8N711UdYlpVjqzwZbuQiRDuAbhzoIMomlfSvqX16QC1e9s5C Hqp1VYPXOenolG7bmPQg8Jl2U+m7vCtdCnD1WvyJNR+b8Ry6O18VhVWrbLXnZAIARoUzqBE58Tb t+LgsJWGxrBDl/vdT7OkKEVPnrpchYq1ANAl/tFa8qV3O4N4Axt82los9aDxShkSOe55oQBb6Fd jW6W8Cw/LQ/YSIJpdAdVu6nnVNDFQUu+3A9YtpMlCANf8tYgVpNaKOyab9fGSfKRYz6WXavBpms LNGq8lEkLC6ay9N5Dq5t5JFB/ggRTHUFH6duLpPXlmXMoJcNa3o+6u7ZCjleGdcm8CKgJrwUT9f wfg3vqw4Kxy978kLtDZq8m3ditRHusfHa/cSk1JWhHXpGcy3+TVlp/WCyfZiiaDY0lv75S1UlcE b1b/b/WnfLb39EPkfypA18KyWEUjaK/isE8/oCdBJpjTB4WyWHhWrnfhcTXOAN8J611nK2Tf+RR WvjcJGJNmUlkZpg== 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 3de89c9c552c6603396f38a98ad35263f04bce26..6dc4d34a9e44ed4beb115ad3c86b759e28f5d0ef 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 Fri Nov 22 17:38:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883479 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 BD25BE69186 for ; Fri, 22 Nov 2024 17:39:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 08D5410EC39; Fri, 22 Nov 2024 17:39:04 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="oMz1yEI1"; 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 059E610E1DD for ; Fri, 22 Nov 2024 17:39:02 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id A8AE7C000A; Fri, 22 Nov 2024 17:39:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297141; 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=dOsGcq1tgnZ8J3YdAQwSil2grZlMHMu/LuOePC1ySMQ=; b=oMz1yEI1hls94RmSiM9sPRDlBjlxb/3MRRkxg+zJc/BWsu3CH8hNbDAsQQHwl9XaoC+GJa Ff3up5EP9hOATAmI38KKN6+OIAavhfUdEzUSJR88NmXhbE5PW5BEfaJXg2dQdlqyJJwnyl nhLPDchLjPWRR5b/c2R+YidAN05CUqwKmMBUeFB+rEjfAT2pRw0WcM7YPYTTGG0YLvbDOb O4zesuafKOOh+a5b8ZzlV3u2KJRH2awDOBNR8wt4oSVfuJ09jGik+/tjR1pVLLyYfY5Nrs GLYVyhTcZKnYI4sKhdkAcCTAe9ATY6gYbedxSy3E0UNQa0fhl4ea/0waP4rlkA== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:31 +0100 Subject: [PATCH RFC v2 05/16] drm/vkms: Introduce configfs for plane rotation MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-5-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=ZvvsaZwGqFsLr0ChkQtKz12Rpe5AImIeJhO57DvpCUU=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGqV1JFvAcJ+p3yD1XW/GaJZSLJi4ZgXZ9D2 YfnhbLMTkGJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBqgAKCRAgrS7GWxAs 4pIYEADWRI5sKoMv/PlWUSS52nO5VAVtM2FtMi7dn1xxvD46lfriigR6KbhMiaGCGzA1z/vF0qG NKX0m5eOeqg5EQCey32+HmjEENRTu11dWUGoSg1Qz/D1eXvyu7kR8l8XOikldJINKBpYPXr2OOG a/PQhC7gwJdyg/gTV5yu+bHIRhu7QLRYWXkw6O3gL1not86PPglBroB7WxrT5aseD2X1F7Gu53I hWCm/MP69/bmMxmvAoBxmsV1M2Lqi14qVFVu9gYjGCzTvB+jFzk+GEmli32AfiW71cEnm+hlDnL oX0hhK5WtblFvUMEv0SB/mygrCNdx7w+3tnGrjke6aKPpf/J7HR4n8cFtIThqOzE+0PeF9x0MnF sofuoOQMsekiMLTsen21odN9amU+eUsHgujfD/Tn5B2hR5YemE8rquwzUcCjoIorlmtCxqbm1eZ 6XZZ7kdmlJXM1pMFhp/Fiy5HLR7k4ygxvBltTK98djUTVO9ai0DKChalBI7wQcvYHHr9Slh4VRh IIbhWuHASCJ4z4Mi8+OMGE8QgsJZMsIT06NBbyvuNuZhuqkHPBX64icDkVLoTEBRorkZ4XLcomy X3FG81nc2ej04ToYFX3lPSCAf6mDzrRC8W0IGYjUkzCiNZjQoFegpBCKzCD1pX7rpmYH2m1/Tbo 6DXA2HLtOceepig== 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 Fri Nov 22 17:38:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883482 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 515D3E69185 for ; Fri, 22 Nov 2024 17:39:08 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1677F10E1DD; Fri, 22 Nov 2024 17:39:05 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="P4Fm/RC0"; 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 E7BBD10E1DD for ; Fri, 22 Nov 2024 17:39:03 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id B79B0C0006; Fri, 22 Nov 2024 17:39:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297142; 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=Kt8qlZY/tj6GEp78aj6VZ1os0+2NQYLUu/22uYDQn5g=; b=P4Fm/RC03RKOkMSp/B7FO/rxBabGkPz4UZdZdR/bRr69Nlisj3LGxd5uhE3D4JdRHCdBYh nOHDVxjZ73lBBtHgOHC4epHFH6QSqit1vPwhJgWLdhCuwzW+WLWZ4QdceBBUWD5SvMcLtF +6efdHk7fkLrtIaFe78KvaI0OWOyXANU7sr3BMIUSLzgBSIXf0Ro82V7seH+7uidCfLkwE Kyd+foOIPGN0i0jygsSosnZNfEFQBVlWaTa3pavK/lvRp7tNY4SwGitMTq2SP4J4EMawUa 2F1BSH9uC36/fJzDuk8sHbdQadHoRI9fNx3UCTWG2ANumM2pdPtfZs1jK8HlvQ== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:32 +0100 Subject: [PATCH RFC v2 06/16] drm/vkms: Introduce configfs for plane color encoding MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-6-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=5428; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=wcIJm3kHeSigFQ99DWfHwW++s/RteRtZ9KRl09b10LU=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGqSNwW8YghQk9G6o21hTr/TYaHzLenBo6X6 AX6vtQ6elyJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBqgAKCRAgrS7GWxAs 4iO6D/9ZRsaSOR4MzlK0s9EsmZ8hPpg3JYY4pqDgh/VXZarxHUb4ka3fknzuArnJZPXNFvWo2Lg Lor4XIf5p1KTT35chmNGCu6uEXF5r4tj+zgL37PXlBJR7pBZbSiiG5VzDieE8WfDaZWQ4ntEFXc 0z0eXg1VLK5b8tKakGpuMYLdWurOuYZhIK1OORyeFAup3JYLgkXSx+Zu6m8yggitZxGkcLtZdAZ +eGSUk9iteWuyN4aeJ3B9in4FKVPjDj7cx5L1PmrA7CkYQ2mTEpJwRbjcqCrWq9eOIhqypsvqEr ChKFrrhNGimhKle7jnNd6fyd9VvmPaXzbqW6xxHBCXvz10cDqGadamCbayRjlaGmSENFnpcoXSZ svjsszxI366EmTB3TgU7tNWG6g6NBBVSYRYjeOZln69LI2DEVPdCCsNAeTWn8jlsVXUMWMX+bN5 hSgfhV71gVCrJXjN1KSJNb1tvUhnnn7DLlUX23z2Q8PQOjsarxoQVkZ1lfGZK0+qXssdlaZ7V7u o+ifEjzD23Hy+2hKNu+ogiZToOWJ2EFdOWXDNFIdykYzs5btPod/SmlZfh3EL9A5rOuaF8iUU8n UX0ErgfQLxactyYk1oRho+QlutWjWf0zLRsQ0/O8hGosMTku4VepxeDq/9vHUKK6EVFGb3I1BMl m/MhI0BVFWZ8D0w== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to test many hardware configuration, introduce a new interface to configure the available color encoding per planes. VKMS supports multiple color encoding, so the userspace can choose any combination. The supported color encoding are configured by writing a color encoding bitmask to the file `supported_color_encoding` and the default color encoding is chosen by writing a color encoding bitmask to `default_color_encoding`. The current interface is: /config/vkms DEVICE_1 ┣━ enable ┣━ planes ┃ ┗━ PLANE_1 ┃ ┣━ type ┃ ┣━ supported_rotations ┃ ┣━ supported_color_encoding ┃ ┣━ default_rotation ┃ ┗━ default_color_encoding DEVICE_2 ┗━ ditto Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 107 +++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index d121cf54e75238bdb582362596a353682cceebd3..a3dab59868829266adfe8192c5089cda2044c050 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -152,14 +152,121 @@ static ssize_t plane_default_rotation_store(struct config_item *item, return count; } +static ssize_t plane_supported_color_encoding_show(struct config_item *item, char *page) +{ + struct vkms_config_plane *plane; + unsigned int supported_color_encoding; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + supported_color_encoding = plane->supported_color_encoding; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", supported_color_encoding); +} + +static ssize_t plane_supported_color_encoding_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + struct vkms_config_plane *plane; + int ret, val = 0; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + /* Should be a supported value */ + if (val & ~(BIT(DRM_COLOR_YCBCR_BT601) | + BIT(DRM_COLOR_YCBCR_BT709) | + BIT(DRM_COLOR_YCBCR_BT2020))) + return -EINVAL; + /* Should at least provide one color range */ + if ((val & (BIT(DRM_COLOR_YCBCR_BT601) | + BIT(DRM_COLOR_YCBCR_BT709) | + BIT(DRM_COLOR_YCBCR_BT2020))) == 0) + return -EINVAL; + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + + /* Ensures that the default rotation is included in supported rotation */ + if (vkms_configfs->enabled || (val & plane->default_color_encoding) != + plane->default_color_encoding) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + plane->supported_color_encoding = val; + mutex_unlock(&vkms_configfs->lock); + + return count; +} + +/* Plane default_color_encoding : vkms//planes//default_color_encoding */ + +static ssize_t plane_default_color_encoding_show(struct config_item *item, char *page) +{ + struct vkms_config_plane *plane; + unsigned int default_color_encoding; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + default_color_encoding = plane->default_color_encoding; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", default_color_encoding); +} + +static ssize_t plane_default_color_encoding_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_config_plane *plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + int ret, val = 0; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + /* Should be a supported value */ + if (val & ~(BIT(DRM_COLOR_YCBCR_BT601) | + BIT(DRM_COLOR_YCBCR_BT709) | + BIT(DRM_COLOR_YCBCR_BT2020))) + return -EINVAL; + /* Should at least provide one color range */ + if ((val & (BIT(DRM_COLOR_YCBCR_BT601) | + BIT(DRM_COLOR_YCBCR_BT709) | + BIT(DRM_COLOR_YCBCR_BT2020))) == 0) + return -EINVAL; + mutex_lock(&vkms_configfs->lock); + + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + + /* Ensures that the default rotation is included in supported rotation */ + if (vkms_configfs->enabled || (val & plane->supported_color_encoding) != val) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + plane->default_color_encoding = val; + mutex_unlock(&vkms_configfs->lock); + + return count; +} + CONFIGFS_ATTR(plane_, type); CONFIGFS_ATTR(plane_, supported_rotations); CONFIGFS_ATTR(plane_, default_rotation); +CONFIGFS_ATTR(plane_, supported_color_encoding); +CONFIGFS_ATTR(plane_, default_color_encoding); static struct configfs_attribute *plane_attrs[] = { &plane_attr_type, &plane_attr_supported_rotations, &plane_attr_default_rotation, + &plane_attr_supported_color_encoding, + &plane_attr_default_color_encoding, NULL, }; From patchwork Fri Nov 22 17:38:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883483 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 EFAABE69188 for ; Fri, 22 Nov 2024 17:39:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1589310EC43; Fri, 22 Nov 2024 17:39:07 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="dCCmuCze"; 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 1A43E10EC3C for ; Fri, 22 Nov 2024 17:39:04 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id C14E6C000D; Fri, 22 Nov 2024 17:39:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297143; 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=5gTDNrB6XitmE4T+aS2E6vxEsV3E+1SNA41vUDvIuVQ=; b=dCCmuCzeLx8SxWss10bpqaQGyPbq4VP03W3A8N73IyhZXhoZ0sa1BUwdWuZ3CT7J51/G4j F4mKvn2uSGDP8WkVuP+a3DW/R9suxMilaul+jzxbUdRtkyuVXwKoC4J80wWGic7RSDS4we EpwiKPDoD5c6RIVvncN53qgPKySwzPeLHKPiAJLlt2jJTabcVvpF0QHZJTCRLMec9sNwtS T5hbF5SNdgz/2nHBtnFx1RL6GNwEG5hPKLvJjAul5GskR/NSeUhNgrcrgUCVPpOpsnF5gB WDwqT1yVVOATsuMH15yNwnKE+ZQoIUBFyMVnk0PMjwCkl4dYITpicOtdc7d5Yg== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:33 +0100 Subject: [PATCH RFC v2 07/16] drm/vkms: Introduce configfs for plane color range MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-7-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=5573; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=i8E2F83sag4K7/D42ANd9mcZg4fMKlUl/lF3IvPXT6M=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGrqhjyajHbpqYX8tyBXHzWkLE5kKRkLVANP vJz8Jq3WhCJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBqwAKCRAgrS7GWxAs 4i4QEACkrGkbPPF5wa62Gww4gsNaKa5golQMfPiqiRQRpfEml2bGjXOIMZj1Itl7Sp73745Vy9+ lHPO6ei0v3KpkaSiYDSPebhLwxY9qpEzLZF+Foj4bEggNCSAeuM9Wc/pzucrb1H4za8RMU1Sw1w mp7/5b4Xl78Zr/jQaQBRQQWgkv6y8aX/IHRXUl5gmL8viwFwDkvMVLhUzRnbi+oO4YXf827t1Xh KFX051GZi/tqYrPLS51ed5QBBWav3Rjh7Rbqfnrq6na19h4s3JlQFd0z6c+70dYhsDgdL9HJkg4 Ryo3G0Mlg6RC0HlPwNyqXfqQGyM7qqyVnDAoTT8IEiE8VXcpk7IdJVe5bP69YeURqvKRf9SMLFn Nda5OREpsJrxVgpOcDBgDS0t5qNEqlS3tj4XHDGPkZxrEisAjSR0o8WjdzPHze5GT2Zhbc7OwtU eq3ovmn8InKzNJanmYTs+qWQR2Dbx5dcwaaU5uBZfqZUeEfrOIk2IYx95qwrozfv9N4k0Pkc65p atULXY1KC2iZ8k/khqoMy6ZmhJcdnjoZY/6X7Io7jsi3jNyyj1Wd7G0AxbTFZdN2rGiHkdKl0xI jTn44iHxJAswpOFxNCxgqZr58rp8llasuJVR2j5D6ENFS1q6AUiiy/f8jgUT6bWY3BfCOjuJre/ B2whOanvIwnZZXg== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" To allows the userspace to test many hardware configuration, introduce a new interface to configure the available color ranges per planes. VKMS supports multiple color ranges, so the userspace can choose any combination. The supported color ranges are configured by writing a color range bitmask to the file `supported_color_ranges` and the default color range is chosen by writing a color encoding bitmask to `default_color_range`. The current interface is: /config/vkms DEVICE_1 ┣━ enable ┣━ planes ┃ ┗━ PLANE_1 ┃ ┣━ type ┃ ┣━ supported_rotations ┃ ┣━ supported_color_encoding ┃ ┣━ supported_color_ranges ┃ ┣━ default_rotation ┃ ┣━ default_color_encoding ┃ ┗━ default_color_range DEVICE_2 ┗━ ditto Signed-off-by: Louis Chauvet --- drivers/gpu/drm/vkms/vkms_configfs.c | 103 +++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index a3dab59868829266adfe8192c5089cda2044c050..aabc832836266668c8adc60d7d5284ee1f385f31 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -152,6 +152,105 @@ static ssize_t plane_default_rotation_store(struct config_item *item, return count; } +static ssize_t plane_color_range_show(struct config_item *item, char *page) +{ + struct vkms_config_plane *plane; + unsigned int plane_type; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + plane_type = plane->supported_color_range; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", plane_type); +} + +static ssize_t plane_color_range_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_config_plane *plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + int ret, val = 0; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + /* Should be a supported value */ + if (val & ~(BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) | + BIT(DRM_COLOR_YCBCR_FULL_RANGE))) + return -EINVAL; + /* Should at least provide one color range */ + if ((val & (BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) | + BIT(DRM_COLOR_YCBCR_FULL_RANGE))) == 0) + return -EINVAL; + + mutex_lock(&vkms_configfs->lock); + + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + + /* Ensures that the default rotation is included in supported rotation */ + if (vkms_configfs->enabled || (val & plane->default_color_range) != + plane->default_color_range) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + plane->supported_color_range = val; + mutex_unlock(&vkms_configfs->lock); + + return count; +} + +static ssize_t plane_default_color_range_show(struct config_item *item, char *page) +{ + struct vkms_config_plane *plane; + unsigned int plane_type; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + + mutex_lock(&vkms_configfs->lock); + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + plane_type = plane->default_color_range; + mutex_unlock(&vkms_configfs->lock); + + return sprintf(page, "%u", plane_type); +} + +static ssize_t plane_default_color_range_store(struct config_item *item, + const char *page, size_t count) +{ + struct vkms_config_plane *plane; + struct vkms_configfs_device *vkms_configfs = plane_item_to_vkms_configfs_device(item); + int ret, val = 0; + + ret = kstrtouint(page, 10, &val); + if (ret) + return ret; + + /* Should be a supported value */ + if (val & ~(BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) | + BIT(DRM_COLOR_YCBCR_FULL_RANGE))) + return -EINVAL; + /* Should at least provide one color range */ + if ((val & (BIT(DRM_COLOR_YCBCR_LIMITED_RANGE) | + BIT(DRM_COLOR_YCBCR_FULL_RANGE))) == 0) + return -EINVAL; + + mutex_lock(&vkms_configfs->lock); + + plane = plane_item_to_vkms_configfs_plane(item)->vkms_config_plane; + + /* Ensures that the default rotation is included in supported rotation */ + if (vkms_configfs->enabled || (val & plane->supported_color_range) != val) { + mutex_unlock(&vkms_configfs->lock); + return -EINVAL; + } + plane->default_color_range = val; + mutex_unlock(&vkms_configfs->lock); + + return count; +} + static ssize_t plane_supported_color_encoding_show(struct config_item *item, char *page) { struct vkms_config_plane *plane; @@ -258,6 +357,8 @@ static ssize_t plane_default_color_encoding_store(struct config_item *item, CONFIGFS_ATTR(plane_, type); CONFIGFS_ATTR(plane_, supported_rotations); CONFIGFS_ATTR(plane_, default_rotation); +CONFIGFS_ATTR(plane_, color_range); +CONFIGFS_ATTR(plane_, default_color_range); CONFIGFS_ATTR(plane_, supported_color_encoding); CONFIGFS_ATTR(plane_, default_color_encoding); @@ -265,6 +366,8 @@ static struct configfs_attribute *plane_attrs[] = { &plane_attr_type, &plane_attr_supported_rotations, &plane_attr_default_rotation, + &plane_attr_color_range, + &plane_attr_default_color_range, &plane_attr_supported_color_encoding, &plane_attr_default_color_encoding, NULL, From patchwork Fri Nov 22 17:38:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883489 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 5AA74E69186 for ; Fri, 22 Nov 2024 17:39:18 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C099F10EC46; Fri, 22 Nov 2024 17:39:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="cTd+yms5"; 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 1180610EC42 for ; Fri, 22 Nov 2024 17:39:05 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id D2B97C000B; Fri, 22 Nov 2024 17:39:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297144; 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=RiHV4kTKs+4HZbVoCDeGNcEDP2FhnDWM5/2UYTHeIhA=; b=cTd+yms53lU7DPAk9LIt/dj+nz2yHT/HgoVAC6lEh8gS7fSJS56glc/FexImHqhyVOrciK 9L/TBzfs+SMiohz4oI1KWErSl6i+hsgZHT2ZkptttYuGPoD4uTY5IZvHHuMIYPATQjgy1e 68pfM+Psx2GKIBmpuy752BDne0zqX+a5TUk9sz89lpX68/BD6OrhIXqFUKpONUNWS56pBS gReHETFiX+JW49rnyITYz6wmE4q3EMCNNj5MtqT7gz7f8us9dtByIqEs7xs/GyE1e+nuYs XMgdZOmxJ/bqX62TMf3OaeQ/pdOXfUw1H4uGx+zakX2JbwtH1BCpCGP7gIG4cA== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:34 +0100 Subject: [PATCH RFC v2 08/16] drm/vkms: Introduce configfs for crtc and encoder MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-8-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=gndkOG5m3vc2al8lf41sf/N19K1uU2teEn3f/2c0XLA=; b=kA0DAAgBIK0uxlsQLOIByyZiAGdAwauhW9GXc+VgMJcWeEyVtrK3f4d0fVGCWazJvjI8b0cka YkCMwQAAQgAHRYhBE+PuD++eDwxDFBZBCCtLsZbECziBQJnQMGrAAoJECCtLsZbECziH74P/jrB rCfYxiGHlp32cXrEii22DsE9zdMXG3o9EFq3fv+Cb7a0FqU4CU7k5DIPhUUb1qkuhQ6V3pmrJyA ZEBvhNepel+Yc+hGlTL0CwPXsS7sPXq0jH+yiyYiqt0hVRXNnWg+2mEy1QfPOLZUuxsWefPTZ6m HFA9kiL6A8gQw+qIV1dUhrHhQmj5F+3I9mnTBkTo+eelj3NrRs9fomw5qOnxB9Ixd1uBmzCvide jgLb0n70Ou+Pw7i1szXnHeZHtsjXLaT7tuhFbutHKPhnRxGIHI7kJfPHpDh6DVEPCU6a2U/jFpe jsbFbuGp9IEz6aLILRfqdJ+kqbYuFedCe26VfXXz+qIXRHSpOibPdLYtieA69TT/kQXBQIPLsU0 cZM2ixl0gPOeYrC87/5FEi4+Ec+ff04yhJiEYrEzxhWjoysAONeYe8ybkPi4/L5CJ88SxhtBtO/ ENj8VsUpWxkMsq+oJSVvnUtKbB0tebloy9bFKsyzmbRsvZhGe4cWBc10nXTGnfS9D/XSwjfeFWi M5v7nIyC7cgcyjB6RB89cx0LV4KISzPmkt025FYw9SvS7yV37PByjgc1jo06snW2AkXy5V0fMBA bun4W3BzJI3gmSBPBftpLW2+eViXic8Po53blcWFRwFdGfC1ldtflTN3cZ52xMBAujCvcHqmc8T tciVJ 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 aabc832836266668c8adc60d7d5284ee1f385f31..a410c9be4f2bbf7b2651245747eb357fcf32d1f2 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" @@ -395,6 +396,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) { @@ -419,10 +498,7 @@ static struct config_group *planes_make_group(struct config_group *config_group, if (list_count_nodes(&vkms_configfs->vkms_config->planes) == 1) vkms_configfs_plane->vkms_config_plane->type = DRM_PLANE_TYPE_PRIMARY; - - if (!vkms_configfs_plane->vkms_config_plane || - vkms_config_plane_attach_crtc(vkms_configfs_plane->vkms_config_plane, - vkms_configfs->vkms_config_crtc)) { + if (!vkms_configfs_plane->vkms_config_plane) { kfree(vkms_configfs_plane); mutex_unlock(&vkms_configfs->lock); return ERR_PTR(-ENOMEM); @@ -439,7 +515,12 @@ static struct config_group *planes_make_group(struct config_group *config_group, config_group_init_type_name(&vkms_configfs_plane->group, name, &subgroup_plane); + config_group_init_type_name(&vkms_configfs_plane->possible_crtc_group, "possible_crtcs", + &plane_possible_crtcs_group_type); + configfs_add_default_group(&vkms_configfs_plane->possible_crtc_group, + &vkms_configfs_plane->group); vkms_configfs_plane->vkms_configfs_device = vkms_configfs; + mutex_unlock(&vkms_configfs->lock); return &vkms_configfs_plane->group; @@ -454,6 +535,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", @@ -474,13 +832,25 @@ static ssize_t device_enable_store(struct config_item *item, return -EINVAL; mutex_lock(&vkms_configfs_device->lock); + if (vkms_configfs_device->enabled == value) { + mutex_unlock(&vkms_configfs_device->lock); + return (ssize_t)count; + } + + if (value && !vkms_config_is_valid(vkms_configfs_device->vkms_config)) { + mutex_unlock(&vkms_configfs_device->lock); + return -EINVAL; + } vkms_configfs_device->enabled = value; - if (value) + if (value) { + configfs_lock_dependencies(vkms_configfs_device); vkms_create(vkms_configfs_device->vkms_config); - else + } else { + configfs_unlock_dependencies(vkms_configfs_device); vkms_destroy(vkms_configfs_device->vkms_config); + } mutex_unlock(&vkms_configfs_device->lock); @@ -519,9 +889,6 @@ static const struct config_item_type device_item_type = { static struct config_group *root_make_group(struct config_group *group, const char *name) { - struct vkms_config_plane *plane; - struct vkms_config_crtc *crtc; - struct vkms_config_encoder *encoder; struct vkms_configfs_device *configfs = kzalloc(sizeof(*configfs), GFP_KERNEL); if (!configfs) @@ -536,22 +903,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 6dc4d34a9e44ed4beb115ad3c86b759e28f5d0ef..df743e0107f40cd10433bdb638108d266f9c83a6 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 Fri Nov 22 17:38:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883486 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 A7BF7E69183 for ; Fri, 22 Nov 2024 17:39:16 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2511F10EC3C; Fri, 22 Nov 2024 17:39:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="DTD5y8Gb"; 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 214E810EC44 for ; Fri, 22 Nov 2024 17:39:06 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id E84B0C000C; Fri, 22 Nov 2024 17:39:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297145; 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=w2tUcZCiDuzBFgWGZXjM+4g83n0WmsqwJbmcETj8nFo=; b=DTD5y8GbwL9K6kQuwfRPHQVKVRAPP5haF1SIG/FRzH4Y9Mw8GmHTEtjvMKQcPitP2Ht60r zj0vMV9SY06LfQ7GraLUGYpZn4zlWoiCiHX0tcmZZ1rZmK72RQqBlduwr6IoJjkjoZaI7Z G0vMf048xT9IwUCacuPt/G0PThJuE/nXGPuMu+Bi+cIb0SbNV0MckFggMwJ4N9/VeGuDH5 D4ktWm8v7CeoaCOwHsWpacbWOmPo5kQsRsmnFhB7oPTuWXHoi9cBXmsAe4G4tWrL/sPRAN JX7/n290M4NEviiRVgubKziajleASs3OuT9SJyRPK8Sk7BZndSDnvfCHyylUzg== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:35 +0100 Subject: [PATCH RFC v2 09/16] drm/vkms: Introduce configfs for connectors MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-9-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=10534; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=xZC3t90mdHVS6dkEWImmPKHG3JzR8IbQbcP4Irr/elA=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGrSK3zM6IRyqZm6zWh4Mw0Q3GHUg+jcJFCA AqndrmJVRGJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBqwAKCRAgrS7GWxAs 4gWbD/9kN9HN2dqv6GfOV8Ft8gef3hY710UuM5iSarXg5RxViYZ20NtnYHvowB1gBM4f+az9DhH mqiuisjn2UuB0SFXFYk3Bpjk+4SZ8n37cK86S8ybrN9TbvLO0P2ie2YDZT/pw0xAZU3DWOaijRJ Ftco9iTrWJWsVL85Ajah8C4MQaF6t9VuF3MnKR4KAU35P58sh/HOMD2NMDfVrTdNQXjjiRfFJVS wPqRcoST7H6GXgbmhB3nOwU4u5RqsmuGUvL9zONh+VBSSrL9s6/KFQaFp7TLbqoDcv9Jw57p1Yk eAJmwujzJG1GBmpZxUypoPhn/AAz6qHfUkMukSPPIQo2Uz2R6j4Nueuxhe9EwTZwzxeN7KKMJg4 kSu29c1f2Mn2Vt1GiT9RJv4Sjvoo0U9jO5+rwrMAP71vvjD0HhFL8PF578unpOwAbIooqijOeUM Tbs6ICkeD7YQccg1hbEO/w9+IDL7gXjtNAykCwCoVRFqF8kQh1gprhpoeveJqQoNoehF4IEbE0i eX5Q3xOsEZCA18Xzem+1ketSD+koaog7tP7c6KRun9yd0zvDSEt9Hfsm86SYRvN7QnRlJAoYqnS e+lMO0NmFuzk/gmdR26dXvMfZBDhcqgTOMUSE5L7hDcQJ0B/Rui7xHG0oSM5Hq2LFu1AZK5S4Of OgbZ7Db1OOUqozQ== 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" 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 9a461a0481c2a20d6d48f1aa9649843ad1b7d13d..da99785ec89f0c6a7fe1a71fd2e6f5944c844aa9 100644 --- a/drivers/gpu/drm/vkms/vkms_config.c +++ b/drivers/gpu/drm/vkms/vkms_config.c @@ -516,6 +516,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 529d9c99f3c406d49dc7f3689a84c3dd775399a9..b1d80185216798cc9fc06e7d1cd0c423b7275185 100644 --- a/drivers/gpu/drm/vkms/vkms_config.h +++ b/drivers/gpu/drm/vkms/vkms_config.h @@ -197,6 +197,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 a410c9be4f2bbf7b2651245747eb357fcf32d1f2..94c288514172b88d06c2b74e36569c6d55383782 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -746,6 +746,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); @@ -769,6 +770,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 @@ -915,6 +1049,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 df743e0107f40cd10433bdb638108d266f9c83a6..12c0fdefb813387515d144519479c242b7ef6728 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 Fri Nov 22 17:38:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883485 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 25A75E69185 for ; Fri, 22 Nov 2024 17:39:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6C9C910EC3E; Fri, 22 Nov 2024 17:39:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="Se1wBB0C"; 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 2A27710EC42 for ; Fri, 22 Nov 2024 17:39:08 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 039FCC000E; Fri, 22 Nov 2024 17:39:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297146; 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=6erMn2IUOhaxEwt1K1wXIPBMHYHP3JAfl2LkVCXhdgw=; b=Se1wBB0CfL05V039gAnQwVm4ysoe/oNJA4y2USukCRo4WWyDO0tTasCJyHeI9yJzeYl4AO HvLx5L/slO0m7Sy4meq+HXVzdeIFhGXGnDC2BbCu/oGPPopuayTGKiYLgaE4AXkwOHkXyD PPTOpjTr99dDUTvRvBNI14g4uJq997IiZVIVrQMDAfi/xBF0jh2J4y4fhAKnR0XMXhrbkW h8v9d446GamA+dF6yhERLyyjupCB9e/9LzHav/SdqZ3dYbjQqj7gdtGvw5mnsMzj0+EZNU pe/uX6/QJ1D99qtgLo6UtKANbwf6Bj8i/LgZx6R5fw6Plv+p97xjkJF6LBY6/g== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:36 +0100 Subject: [PATCH RFC v2 10/16] drm/vkms: Introduce configfs for connector type MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-10-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=2904; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=Rr7dRz6qR+bWqme3mPmuGeLQenp1Ju5aXzM4IVaRvVU=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGsquDFewtGtygWdwqthIx4WNhQNyLz4q6EC vzWJQaAfVyJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBrAAKCRAgrS7GWxAs 4h+1EADN//gYSaiCxSp2uNlRbSG7UAsk7EJDgaI5v/2RAxGi12o78+6I6P1YjTt/Jt+TVcKuJsK I4jnRlRs7IM3hR+KDcNT4dlXpaNsZrzSBGleFoIDDNJ5lkcCDGl3yEjFCzvJvWagSdcmFgoOYBW 390QSXepY0uSjUDT1D/gT4OLbpuKI/rUzDJ+eh/GAkE9uhTy16PP7ftacrxrEjO6P9MFtamcHrn +XrpYJlKBQ8gPTbwN9Ce3cfJptBbuampjRh8LIGR953phBUQNx+/CVFHpVTGncD90OwmVwz+DHh SFbm3tERLDNqxZlH/gpSdPk63m/6wnhcUHfgC+6C30M4U+hPH5LCosNdty+yO84sScuylmPOOMz ETJFuMFUz8xdWN2bgKsgEfUltxyMdc42fgzAuSqaAoKaHeLa7tYT/U2rvKL1QzS1h2/j42/6USf zPde0uvshSVLgy0KIwYWD6ggPOG0xTY+OkgSSxdLwWW3PKHaFn912B3bmDExgMvcanLka+5ntfo lk3ZYg0XG15dd69udv1jQGiWLsiYBTZIygTjIc2Ck30txq3/kHSJYZC03s1IX8gytciOCNXrYO4 TnQFQnLfR4L2RW6UykrRe3loJGLpIVvcXK8+bXrFmUsA2oFruwvGuuFK2yq+2QbVGpARoBCZUd9 GTcawk692SaFeMQ== 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" 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 94c288514172b88d06c2b74e36569c6d55383782..ef9a00c41b7b030d0d60ffe078809f9799539f40 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -843,12 +843,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 Fri Nov 22 17:38:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883488 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 0B7BAE69188 for ; Fri, 22 Nov 2024 17:39:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 31A4410EC44; Fri, 22 Nov 2024 17:39:17 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="E8437X3l"; 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 53E0910EC3E for ; Fri, 22 Nov 2024 17:39:09 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 0C40CC0005; Fri, 22 Nov 2024 17:39:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297148; 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=K62+SyNAzYsmI5c6NH75SjeRnt+jsy02BCREo3E62AI=; b=E8437X3la9DzCtXncDoexxcOl8LIzcMhtBe76IrN7n9mIaF6hCIoYqX4m1iDUtSxJGTpuP UWzPzD3aqeaDtgLeZX31zK2XJfLSE1Q8ALG2oul00+ZVZVPZx5A7pbz9kCazS1zWCK2p09 yCbjEOylzLZGLHNOBVLBOEHBBkFjm/s37m76Y+C+RqqJA/20Z9A8clOZU3oPiNsr39m2zS d8YIXWNhc71p2xVRClXAoL5LIVZJEoyO+EKjJ+SxCQXhpedyoFjdD3RXmgHFEhrqvXH7O5 mz+WqruK0a5xyxuCR4LlQR2B01DTXhi42MmD1cWfbtItQAQqwrxOd0wJ3b7SjA== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:37 +0100 Subject: [PATCH RFC v2 11/16] drm/vkms: Introduce configfs for plane format MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-11-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=3475; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=nyn61gEI5cxIOk33UuCcsn0hzoPdV29oV/sQS13cyvI=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGs9X5jLX7eybIjcC7XVZ18awx4EhJYJMnWY 6PdjgkwcQ6JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBrAAKCRAgrS7GWxAs 4hbkD/0U2jCG6Ed34iwiN4ftzEyVwtGeWnJQmV0/BDVHJn3DI3puBiTg6UgxBCJ2lg77X42jQrQ GAA8Wlx86qg++zbemn9ADIWJy5zQWF0ZmPlHD+OUU4J6zcBnpQiHL95MTw4AsH4UoC4+kfd+5NJ OlhgARcvWzDnrARtwWmX/jclGUe6mJcUzb1ORToQ53bdjD0jnT0rXTxtT8kH0/7eefLY/7ABTqa n3YXrf3jxjLGGkMXYe5X7RxZQHj+a9iATWRtzaSsb9lgbnz59P2MizS0nAHY7iNXV8XWxzqJ/X7 O/cGMrS7ur9uHy8rOkRVBJSdbpE/h0Fy167V83kyaExWQ7h2I0cMlnBWabmj8LQxRuAHnHGkQzB wF+m1DBfvOPWTtRXcYBYBxdsvEK0+uV9b1jrb15t+1CYo8Ncvnf84wzIuajc/T9l1NoDi0oBzwI QmwXxTxypKmouZnxkwSvS0c93AOqR+W2yXYk7sbAHPRYSYQxIDy78k5Ah/LMP1ekFwYfvksXZMZ dyv4h/KNv83bOKWT18wTCUTWQWGJ/8ODOeAXJwRAptc43pSPsJ83O7f6KfkKtQyjDRVxmlAGnKI X9LTicWpKeiQFIazCBsHgeLMq9lM+qrpniWeMbX0D9JmCkCTEDf6d9LGle5ZrtlDO4pXn9emC7e BbRC6Uj+4H84CIQ== 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" 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 ef9a00c41b7b030d0d60ffe078809f9799539f40..a1ddf25ab6f882ae1857bc82fb4b4a425b6d287d 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -355,6 +355,79 @@ static ssize_t plane_default_color_encoding_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); @@ -362,6 +435,7 @@ CONFIGFS_ATTR(plane_, color_range); CONFIGFS_ATTR(plane_, default_color_range); CONFIGFS_ATTR(plane_, supported_color_encoding); CONFIGFS_ATTR(plane_, default_color_encoding); +CONFIGFS_ATTR(plane_, supported_formats); static struct configfs_attribute *plane_attrs[] = { &plane_attr_type, @@ -371,6 +445,7 @@ static struct configfs_attribute *plane_attrs[] = { &plane_attr_default_color_range, &plane_attr_supported_color_encoding, &plane_attr_default_color_encoding, + &plane_attr_supported_formats, NULL, }; From patchwork Fri Nov 22 17:38:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883487 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 7D4EDE69187 for ; Fri, 22 Nov 2024 17:39:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B589E10EC45; Fri, 22 Nov 2024 17:39:16 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="PFJEXr5k"; 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 5F54910EC42 for ; Fri, 22 Nov 2024 17:39:10 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 1517CC0006; Fri, 22 Nov 2024 17:39:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297149; 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=Umi/Nc0PaCWgnTJXdvq5nC0lHTLO/Dv+MccW98xmYjM=; b=PFJEXr5kYMEyByoavROrDhb0QDrLNCjVyLbE7LUU7lnPfwm0P+87zn6m8y6Km7rikB3g0+ BdbVx9roantQbqNNznAIOhmbW/SW7kMvTDnqdgCZlfPBLrUr1CGwIKjCYRdPXI+u/hd0s5 gCeKxG0/b2vKU1LtE0dV/2WAi6tP5s3IUKUaRRhSZ9DEFnup4h7PJ8V1szDf7ztlf3Owkx yglaM7PKamqxBMQkPPmfOqVso9Uu4Tcb5g0+djN2Ki+i9UhpRXhI/6fZbvuxFD136e5uGp 6meWwerB39UwS0N7275f5liOx1dI6q5BP9jtAdYJwEk2WELOlzu54v7WJeXLGA== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:38 +0100 Subject: [PATCH RFC v2 12/16] drm/vkms: Introduce configfs for device name MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-12-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=1192; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=1Ri0TOTViTXTQHPBy7TMsfMxJ4cY55t/DcvCkNIQR34=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGslsy21ABH21B13Q+YvwSq1A/MGbJKgsbL2 zLJCX8MK66JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBrAAKCRAgrS7GWxAs 4tFmD/9L9XzU8tBSrGH5ErZur/taVRSe5Xv6FAgtgK3bckxOAuYLrjP+gVleufcFAYJDHBavEMn pnevD0nL7Gu5Zx4qOdwoNTdmR9+RcQIyJ9Dk5Dhw012UsLylzGFj2Nlc2tNti91gQ0xOapijn7D Pf4fmVYGwHyli+GSDcRzCia2ELSZcIv5h/rxrWP+onsV8bt971/tUYsYQYNt0cIAFlzXplkBrQH jVEa1Ot9NrfFSNQM8+RHbIFAGfxkZBGLlUawvRJbTKaRe67dnBjaub074puL4b0eVPDQXHVCrfZ QkU6q+6xOcI/16HiL3cY7vms/FnXuZZMyU00EFLWEbxDeGxjSdHiNzxRtr3rkMusqk1bApnKo8y MRUuwObaBXCGDJrqqIdqDAZvRAJ9SvcWEnIi8/j3uQgZyeKj3UFaFiNDY2EeLtdP7hp8HfL4xoa RetgJ/GEXfi/XVoQGqIyi5GIBGrJ0LHgnPXSNsC+U7RfHmUhnD/8R1t8y9SzE5TB3fVCP1TsS46 gDa6CFoQK9u1TwkP2IYBClditq2iYRL2MgDP8EyVxy7QTmyobZspogsXChWzDTAi2YbNTkKOsoz FnOHj/qLmsdRJ+3v1M8zbGjO81D9j4kjmUoczUuzuVPcaskkEM9TjQDx9Iv1FqoQJhZZBhgkIwr TcVf9UySYfuV4zg== 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" 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 a1ddf25ab6f882ae1857bc82fb4b4a425b6d287d..dede56a8a2c1e866734f9c979c76977370907680 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -1137,10 +1137,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 Fri Nov 22 17:38:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883492 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 3A4DAE69183 for ; Fri, 22 Nov 2024 17:39:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8A83210EC49; Fri, 22 Nov 2024 17:39:27 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="CfAQ1TW0"; 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 6EAF510EC3C for ; Fri, 22 Nov 2024 17:39:11 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 1F79FC0003; Fri, 22 Nov 2024 17:39:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297150; 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=v8thBcBK5C6IbsTmxWfKXHXaUB+CSMrPfQq04FH+0t8=; b=CfAQ1TW0Q1ROrEt6DAiB67Fu3NqfJKA4dqgDSGwgI+P81dIWI2+SbTejTZmtl9QnnZer3Z Tto5f0kfxP06yQw4WhmvmvPBsKTPuov4djrunGrGdcH+ugyCN38trd+AD+KNI8GUF+eVfI Ajitdcm6zkAUn/aODMaY/BAoQd39NU2QnZ3Io1WfOhgySzbUv91viGHlosRJfWrEfOn4mU AwqbNXq2xh0zycFiaD+wIoichtdeQeNXpuEQPJOkiCQBQZ6OPewIPdGW0ieMCFBc7Kv2EQ yNwja6p3YFfwh6PTV1qOIeCtGp2wzRR30wlVOQxKGBMxyAFnAxsI/+FJn1NLAg== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:39 +0100 Subject: [PATCH RFC v2 13/16] drm/vkms: Introduce configfs for connector status MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-13-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=2106; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=EeP4OvWfDdFh1jcT0ibCxJNe0wB91SXrC/2Q6j0zaEg=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGtqkK3jIjpQEEKwk9EtqikKRJdy4QXJv2/K 52HeXYM83aJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBrQAKCRAgrS7GWxAs 4ufzEAC2Hf7lYezF+S7ZklJyoGhgiB3eFl5ugvA5ACC9i1aSaQZlyDy7+pJG1IKXm1cRMCCgldX 6zpjNV16M5hnjBA6N09IT8Oe4mLg2Gvbxzc8q1FoFyT21a6X/pyb6cj1yNU/EpM8OJo3F5kgL+E Cfrr4gu9gjzs3O+3Smbd5XGU0fAwDZku0hfBrpdChTCiOgIdI4MBnepqIJh/P1yfoPqQVsjevj0 T8OqMXydIbNTSAyFTO6h7yCo4L1o+5tdUkCmp35Wybg66lFPpF+LgjWtJDIWAQoIzi+e1KglpDH CbYS7HJk6ZwBGttWzmoYDPaR1c+b9MQCOz3ASBpwALPozxO37Dpu77panFIOtY69R6aJKTumXWB 3rvg33DAjiPiuqws+OJ8AUtdyO94IdqQHG/Nv4EHkXyGfClJDIGjDIlOSMPFjf/wqD0CsFxGcaz dVho6QWL0xLCVHWQ/+4ObzRqSERLk8vCPDV4soXNP1vlN1ITzndRB/iLE5xcW618fuMmL3NMQdo /F+nj8UjTlvbuLoivHjp2vLdhKwlege752qFV4gTnYdvsJvOzhQOup7DFdDcRhGCpL7Kw3e+ZQE Mh0znW083dorv39KkuqKvmHnkQfcJo02j2AYSGQw8t0GREAb8vzt5DK6SoGt+OQWouhQ5sMvj/T OHOkuyX5iXt+b0A== 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" 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 dede56a8a2c1e866734f9c979c76977370907680..6412a8b7b1066f2d3dca1135ebd7fbaed84027b6 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -981,10 +981,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 Fri Nov 22 17:38:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883491 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 CD0E7E69185 for ; Fri, 22 Nov 2024 17:39:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5257E10EC42; Fri, 22 Nov 2024 17:39:27 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="Usyx0A4v"; 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 83D8110EC3C for ; Fri, 22 Nov 2024 17:39:12 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 31F7EC000D; Fri, 22 Nov 2024 17:39:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297151; 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=nMqLuA+rZ/4gFP2XNx/8C49wN8GArbQTKi0IJlMNfEQ=; b=Usyx0A4v8yBH7Rbu7wIt4EYY8McdMpyBFm7dQKAY2xzEgdv0I0sxEd9vk1e6TXfwJ5UhjG Htsdhm7lRiuml5K6mL/ScS/PNiG4FbUXxb9jDQ7262Wj5IdgkPDxwrhT88HVx5gsJl1k57 hAAZxlV3SWLgVhl49d9pqhEEBrmZs0bQ/H6R14eg5Vailmc0Oe0wumk95g9FaoYlrbs/hP hjZGctOPeUI/e+f1mTe4/v98uvm8GhOWKCnSa1xbb/LQZV74+nuUHG2cdtNMPceitLmlxt ilBlMAXVKJvMyplYMH1GNecaoIaJ9KXX//vng7HOzWOlVm5exz3M9R0PpumJxg== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:40 +0100 Subject: [PATCH RFC v2 14/16] drm/vkms: Introduce configfs for connector id MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-14-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=1356; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=Ak6KiDGMT+uVa/iGS4P6tHXkjicg6KDsPjq2kkKpBa4=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGt7sY+29SrtKAQmgKn/H1r5ehthOdZWj8NG NQQZHYPI9yJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBrQAKCRAgrS7GWxAs 4jmoD/0Y8xtjPKgTjQtAJGwbywUgY8/P9a7KgjoPkcBXNEl7cg8stwaKxBn5cBjGoMB/W0Ddxo+ LWjgOMpwhKIp2H2hj+gGiCPPm+qP0HKAqefqe4CuepOC+LwSrLaSKPzJLT2f295clqyjIZlWvVK 949y9TlvfBkuQVV45X07y2Z+cKqNj6O9JqLsgIbWIpFkXnJi8CRfOgXOARftCmWKWovGm/7Ji+s KnN6QaZj5P0E7huvkuWw/8+09RAfwIKPIJ+Zi8HKxU0kkpRqcVKuDnEsCmvGC9AC6bWV3mX5mEJ wsbtDlK5fAHxoXBxC6nKgkGQf/d0qqUi+cssWoVklvqcX7NHUzH9v2am7Zw2DkL7c8Gbp2yoCe/ c1v1WnPcpRQfaXQUuOAY3C0CGixMYx5KE2RIPnKVwko228c5qcMdjsa7Ey9Bf2ZlWlZtBTjtcMZ 3i076hZCyoIuPCcZ3se6P9MTzbcvr8kDRVpVluDr+evzJUBVMlFTqVwgszAci1NohmOEQKKra7u LiqmfecVyS1co65QnV+gh+SV/2y3RPr8j7KL5elyExeVy8ThjVBQxtyGI/vXx3QUDCmqtVcJnFt wP5koB+RI+WVNrfPrHfiJ0mfslnc88b5MEdLjLAoAaPapCxFhcQDoAzoV4cAlSvAkj5EUUD/NcI 1VPRXS9pGLom1kw== 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" 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 6412a8b7b1066f2d3dca1135ebd7fbaed84027b6..45738707f1f6c11b561e695fe0aef245d946b418 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -1024,12 +1024,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 Fri Nov 22 17:38:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883493 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 7597DE69186 for ; Fri, 22 Nov 2024 17:39:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9E45510EC4A; Fri, 22 Nov 2024 17:39:27 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="OEKaV7j/"; 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 79A1B10EC3C for ; Fri, 22 Nov 2024 17:39:13 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 48D99C0007; Fri, 22 Nov 2024 17:39:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297152; 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=8XbqLTDSSiPRq89qPf8jbVunz5efAkAkeZ2X6gdPmdU=; b=OEKaV7j/K4xyhJwKfW2H+7gCpInP+awZcPi51/Uz+kEgkz9Snch8ul6PCzNRMbPBBqjCa5 LlofQK1qkBspbZpXjgjM8rUaZ+SPzgevuak/5DmQU0nkVqxlEfY2Jub7uPdfe6ZL0n5FAq pDjtvXBP+Y2CXS5r6H05yG8UD4wzNOAjytQm9D57Q/XxyXLQKwnRNYP70DC5apIJ9SvY6S +7GnlLjuW3JfKGFlbGfCKdZ8g2EuU7ej8ZKCe2uLhwyLlyuPy7rIHSn1fh1yUgRnD4NUI6 NQqgSZPzFx6aFPjgz3Gch2kxeNDpUdQ4TCAiZf0qYWaZDCAmlPQYDi6OikLBcw== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:41 +0100 Subject: [PATCH RFC v2 15/16] drm/vkms: Introduce configfs for connector EDID MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-15-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=2445; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=3UBaLkaY10Xs7sZjf6PzQZCdjAZrwE6GT25BhYncrBA=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGtqTlMBrBheWpxj7pFke2IGncV8tyIsCCMR 4AxF4NxJ9KJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBrQAKCRAgrS7GWxAs 4nKjD/oDjX73fI4s2L+Svp0K35LDMJ0dmks+PkoMoeYh8nRgqmR29f3CHABHdc+9E53zcCfUkGn r6LaDDjrsTaXuJqIUGB982UphbrZ10mZHuFyHnYkxvTq77Rv2fUr6+AJTCtm7DWzLiR/3HXy9T4 +Qk0K/Ev7AWXlXJhAFGZXxG8qk/yC6aStT4sLjLH3f+6P1BANv+BwtDaRWYt2VvGRK9MMzbBwsL 0GjXc3rqEwxaVr2l4XruQGVlcMIZgHps0xDOUiJwBInq39iGi92vE8QBx7ebFZwLUrhFjimP1Aw jaEoLEPmoeLcvZctxKD+LySa5OlzQLXoKSg4z+xaB2s+1ZsgwCOdbMzYzuyKnRt8m/3/rdJEoKb bNwyxf4aY4A222aQ7etbJoZer8t6DjSgRQn2nmpb34vIKATkW+pJkWylROTlJNT8KLlJZI9WlCN B8mCjWjVw0mC90HANX1Vv4uf7NLO7dhqGXrGaj2KcEQfiAHXOS0c2Ffz8TvUp2MiJFdHHnaUV6M xX91gT46xJxmpQ8wTdwrv03o4UIaEFlnPCg7JRRV+fTM4N3czlmPed3DrQvKWQ29SDQ+mfEb9AK pUp2YP8jKPXsgTLX5KYNJ98/v4UiMzNO6CSmG7OluUBXzXqXdngCOMR2aSAHYHlESO6dpDiGYs5 YB0kgobqiS7XpZg== 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 45738707f1f6c11b561e695fe0aef245d946b418..55bd0b9a31d35eca49c67a2fe2d58e3ea84367a4 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -1024,6 +1024,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 = @@ -1043,12 +1074,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 Fri Nov 22 17:38:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Louis Chauvet X-Patchwork-Id: 13883490 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 CB43AE69183 for ; Fri, 22 Nov 2024 17:39:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5214610EC47; Fri, 22 Nov 2024 17:39:17 +0000 (UTC) Authentication-Results: gabe.freedesktop.org; dkim=pass (2048-bit key; unprotected) header.d=bootlin.com header.i=@bootlin.com header.b="JHPUpjeO"; 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 A891C10EC3C for ; Fri, 22 Nov 2024 17:39:14 +0000 (UTC) Received: by mail.gandi.net (Postfix) with ESMTPSA id 5E794C0004; Fri, 22 Nov 2024 17:39:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1732297153; 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=hj9CwfeF6o027ybdXGATpTDOE50up/2fWiEDIVtzBEo=; b=JHPUpjeOmNysKwvgoFCW3gpDKU/eyvgfKJ0Jm7a2aCZNSCwxjG3i7C/Jd2G8GSz8HTfIcv dQBb9nKUWh/U4f93b8UBsROF/ZucALGGBxbE2FO0AbBRpMVTiRrn0C7qEZH3vvAQEqTPaz U8TeR5esWWyppbNkvI1P2um47fYNira8NjIQ4RbqBpjsgqgThI9QFWTUT/t82RIXQflX04 3y+Ajz2gEOXvk+8h8WVU01V20E71r6+jNN1VBN4hjCeejixrFylh/sZHT/exVZN34oo/Jd DJnllg7bP4kyhttXw8l5uh0v1goyy0xSdLqnRKoHsAsAqHlFXmsiRnYw7ZJIIA== From: Louis Chauvet Date: Fri, 22 Nov 2024 18:38:42 +0100 Subject: [PATCH RFC v2 16/16] drm/vkms: Introduce configfs for encoder type MIME-Version: 1.0 Message-Id: <20241122-google-config-fs-v2-16-4b7e6f183320@bootlin.com> References: <20241122-google-config-fs-v2-0-4b7e6f183320@bootlin.com> In-Reply-To: <20241122-google-config-fs-v2-0-4b7e6f183320@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=2786; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=K0YQanDFtYen2DYvGJHhkjozmdVGaLCxqx1SSXyopZA=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBnQMGuJ1BDzmEtq5eT075LQQL8d81HB/aWBkdha FVABvV8GR2JAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZ0DBrgAKCRAgrS7GWxAs 4qXxD/429dAuBnACRdzBaEm+ouQkpW+dMVI3KD9lrqBlRBtegC6/94d8Y7O21FGTM78OFd8UGwW hzf69hnWzzu7FCcur1ftoA1Jk2PG8QFTtnjhaIIftQDQdj3sJIMHF3uSHtsJLjbcKsmWATSPLsB 6OZDpGUl1n76s3tGY+BnZAtHZ5wW1D3mfQ7wRD0uV3rzlDTCvRHh5bK08LlGJnmOI7fjWrMsDre QmGNL1j5En2npXMDcA6EVS4KSxUzMH51XRUfcaqgP58y3cCIBXwh+rL02oY2/09fXCVtQtbQ9tH iUu1r8MoN8KEW3vuvxxkMaB/4fGuf4AU3iXIsAsyAtrJljYRSaZxkvEnND8Ni4B7KS7P84fQvBy 5RWUHiZQsVQFhj2EhK3tOQUPMNLRKbCXou379F9CvYZTfTduWW2Tsd5RGU4msakVXu4ujgwTCyK FZR1YyNfZNTwpGRwyhHBquMml53+TdtzDY2IWv08hArd0oTM68YJeY5jLsO1tk7i3Ln9jnjFJP5 ScvkEQpuVif9btjiMZg9ESJNS38BohIjtxA0uyMiLccgPJql/qyjepQaSaou+4TpWAsKrXCI8lb eLKrWcyfRMBPngmrefzjcPV+y9wCG5JK/RFk5vZDCk3QJOKPsjpxf4V/+tpVT3m+SHkB/rolhjF C3XSmww+EN8yyPA== 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" 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 55bd0b9a31d35eca49c67a2fe2d58e3ea84367a4..bfd3c3a0851b2cc76da52b8a190511f22d3f9fbc 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 @@ -754,6 +755,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, @@ -782,6 +838,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, };