From patchwork Fri Aug 18 07:29:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Brandon Ross Pollack X-Patchwork-Id: 13357406 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 5FD1FC678DC for ; Fri, 18 Aug 2023 07:35:39 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DADA810E489; Fri, 18 Aug 2023 07:35:37 +0000 (UTC) Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9227710E484 for ; Fri, 18 Aug 2023 07:35:35 +0000 (UTC) Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-68890d565b5so507049b3a.2 for ; Fri, 18 Aug 2023 00:35:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1692344135; x=1692948935; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FzLJdSBIukkN4qhyMEizJxafwoMrq+VDIPmKVmy8agI=; b=KRGjOJK4oHgsYbkMGBvnw4IUikwfYSOyDgEXgUkWzK3pcqjHJYyz6hS+oYoWLslGP9 e+Agbsdpza1A4IqTEStenN5HTnt7YPJcLlU1Mm1E3WBkA2cPZUB9u5SnQNkyCqAKhmBG O7LtAYEsryDWK4WJC9sNsS6T++LQqrW+XOmII= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692344135; x=1692948935; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FzLJdSBIukkN4qhyMEizJxafwoMrq+VDIPmKVmy8agI=; b=ViNkYtjp6CyGtUsd3HYRl1vmqVonWAm0uk/ndMFOQB+Qg+ABBCjbYKfSRfE2XU+2dE 937FepFgEJLH1DqPHd8LeyYDgbWOBuplSo88W2oWMbyF0WU0nfnJOqZE4rP0284549yK sbx7mdNOVx4uKjK9A0nKkTeHLRmQy6yjCJlsmPoJEQXheavpDovEaQynkgBRBu7Jp/ij J59zb5Oqn06ytiLOEbYu+4oQZTXNPZANjLXw4FzRyZ92rYs79J3uZZSWwAPSijhhRL7i 6c2VYmjY0pqPDwmFsxksCBpoX0nFHWU2S4kT/OmEHst+RvS8C2uqM7ny63dNVz/evu2H BA0Q== X-Gm-Message-State: AOJu0YzsQ7SiPejvuUnzRJBKitxu69A+3JTkeTnbr9IH7Gy+kCyS6v/Z 4c9dI6hrf7/1DvDkqjc1pi7pU/UoHJk9BC5kvprR3A== X-Google-Smtp-Source: AGHT+IF2G2zTWZkjSABWdi5lrQI4ybZAgwkLvsLm8x2j8kezmlumYTjzfd5WuogoWO4ECdzdQIZHJw== X-Received: by 2002:a05:6a21:3b45:b0:147:c29e:4c33 with SMTP id zy5-20020a056a213b4500b00147c29e4c33mr1213947pzb.61.1692344135112; Fri, 18 Aug 2023 00:35:35 -0700 (PDT) Received: from datalore.c.googlers.com.com (148.175.199.104.bc.googleusercontent.com. [104.199.175.148]) by smtp.gmail.com with ESMTPSA id c2-20020a62e802000000b00686fe7b7b48sm906041pfi.121.2023.08.18.00.35.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Aug 2023 00:35:34 -0700 (PDT) From: Brandon Pollack To: marius.vlad@collabora.com, jshargo@chromium.org Subject: [PATCH v3 7/7] drm/vkms Add hotplug support via configfs to VKMS. Date: Fri, 18 Aug 2023 07:29:32 +0000 Message-ID: <20230818073411.3414628-9-brpol@chromium.org> X-Mailer: git-send-email 2.42.0.rc1.204.g551eb34607-goog In-Reply-To: <20230818073411.3414628-2-brpol@chromium.org> References: <20230818073411.3414628-2-brpol@chromium.org> MIME-Version: 1.0 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: , Cc: hamohammed.sa@gmail.com, rodrigosiqueiramelo@gmail.com, linux-doc@vger.kernel.org, hirono@chromium.org, mduggan@chromium.org, corbet@lwn.net, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, melissa.srw@gmail.com, mairacanal@riseup.net, mripard@kernel.org, tzimmermann@suse.de, Brandon Pollack Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This change adds the ability to read or write a "1" or a "0" to the newly added "connected" attribute of a connector in the vkms entry in configfs. A write will trigger a call to drm_kms_helper_hotplug_event, causing a hotplug uevent. With this we can write virtualized multidisplay tests that involve hotplugging displays (eg recompositing windows when a monitor is turned off). Signed-off-by: Brandon Pollack --- Documentation/gpu/vkms.rst | 2 +- drivers/gpu/drm/vkms/vkms_configfs.c | 68 ++++++++++++++++++++++++++-- drivers/gpu/drm/vkms/vkms_drv.h | 11 +++++ drivers/gpu/drm/vkms/vkms_output.c | 47 ++++++++++++++++++- 4 files changed, 123 insertions(+), 5 deletions(-) diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst index c3875bf66dba..7f715097539c 100644 --- a/Documentation/gpu/vkms.rst +++ b/Documentation/gpu/vkms.rst @@ -145,7 +145,7 @@ We want to be able to manipulate vkms instances without having to reload the module. Such configuration can be added as extensions to vkms's ConfigFS support. Use-cases: -- Hotplug/hotremove connectors on the fly (to be able to test DP MST handling +- Hotremove connectors on the fly (to be able to test DP MST handling of compositors). - Change output configuration: Plug/unplug screens, change EDID, allow changing diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index d9c48ab3d760..94a78780af09 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_probe_helper.h" #include #include #include @@ -40,6 +41,7 @@ * `-- vkms * `-- test * |-- connectors + * `-- connected * |-- crtcs * |-- encoders * |-- planes @@ -92,6 +94,14 @@ * * echo 1 > /config/vkms/test/enabled * + * By default no display is "connected" so to connect a connector you'll also + * have to write 1 to a connectors "connected" attribute:: + * + * echo 1 > /config/vkms/test/connectors/connector/connected + * + * One can verify that this is worked using the `modetest` utility or the + * equivalent for your platform. + * * When you're done with the virtual device, you can clean up the device like * so:: * @@ -237,7 +247,58 @@ static void add_possible_encoders(struct config_group *parent, /* Connector item, e.g. /config/vkms/device/connectors/ID */ +static ssize_t connector_connected_show(struct config_item *item, char *buf) +{ + struct vkms_config_connector *connector = + item_to_config_connector(item); + struct vkms_configfs *configfs = connector_item_to_configfs(item); + bool connected = false; + + mutex_lock(&configfs->lock); + connected = connector->connected; + mutex_unlock(&configfs->lock); + + return sprintf(buf, "%d\n", connected); +} + +static ssize_t connector_connected_store(struct config_item *item, + const char *buf, size_t len) +{ + struct vkms_config_connector *connector = + item_to_config_connector(item); + struct vkms_configfs *configfs = connector_item_to_configfs(item); + int val, ret; + + ret = kstrtouint(buf, 10, &val); + if (ret) + return ret; + + if (val != 1 && val != 0) + return -EINVAL; + + mutex_lock(&configfs->lock); + connector->connected = val; + if (!connector->connector) { + pr_info("VKMS Device %s is not yet enabled, connector will be enabled on start", + configfs->device_group.cg_item.ci_name); + } + mutex_unlock(&configfs->lock); + + if (connector->connector) + drm_kms_helper_hotplug_event(connector->connector->dev); + + return len; +} + +CONFIGFS_ATTR(connector_, connected); + +static struct configfs_attribute *connector_attrs[] = { + &connector_attr_connected, + NULL, +}; + static struct config_item_type connector_type = { + .ct_attrs = connector_attrs, .ct_owner = THIS_MODULE, }; @@ -265,7 +326,7 @@ static ssize_t plane_type_show(struct config_item *item, char *buf) plane_type = plane->type; mutex_unlock(&configfs->lock); - return sprintf(buf, "%u", plane_type); + return sprintf(buf, "%u\n", plane_type); } static ssize_t plane_type_store(struct config_item *item, const char *buf, @@ -320,6 +381,7 @@ static struct config_group *connectors_group_make(struct config_group *group, &connector_type); add_possible_encoders(&connector->config_group, &connector->possible_encoders.group); + connector->connected = false; return &connector->config_group; } @@ -501,7 +563,7 @@ static ssize_t device_enabled_show(struct config_item *item, char *buf) is_enabled = configfs->vkms_device != NULL; mutex_unlock(&configfs->lock); - return sprintf(buf, "%d", is_enabled); + return sprintf(buf, "%d\n", is_enabled); } static ssize_t device_enabled_store(struct config_item *item, const char *buf, @@ -558,7 +620,7 @@ static ssize_t device_id_show(struct config_item *item, char *buf) mutex_unlock(&configfs->lock); - return sprintf(buf, "%d", id); + return sprintf(buf, "%d\n", id); } CONFIGFS_ATTR_RO(device_, id); diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 9f1465b06055..a6947c24276b 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -3,6 +3,7 @@ #ifndef _VKMS_DRV_H_ #define _VKMS_DRV_H_ +#include "drm/drm_connector.h" #include #include @@ -147,7 +148,9 @@ struct vkms_config_links { struct vkms_config_connector { struct config_group config_group; + struct drm_connector *connector; struct vkms_config_links possible_encoders; + bool connected; }; struct vkms_config_crtc { @@ -220,6 +223,10 @@ struct vkms_device { #define item_to_configfs(item) \ container_of(to_config_group(item), struct vkms_configfs, device_group) +#define connector_item_to_configfs(item) \ + container_of(to_config_group(item->ci_parent), struct vkms_configfs, \ + connectors_group) + #define item_to_config_connector(item) \ container_of(to_config_group(item), struct vkms_config_connector, \ config_group) @@ -279,4 +286,8 @@ int vkms_enable_writeback_connector(struct vkms_device *vkmsdev, int vkms_init_configfs(void); void vkms_unregister_configfs(void); +/* Connector hotplugging */ +enum drm_connector_status vkms_connector_detect(struct drm_connector *connector, + bool force); + #endif /* _VKMS_DRV_H_ */ diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index 512f147d41b8..5b23bdf7fb81 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0+ +#include #include #include #include @@ -8,10 +9,12 @@ #include #include #include +#include #include "vkms_drv.h" static const struct drm_connector_funcs vkms_connector_funcs = { + .detect = vkms_connector_detect, .fill_modes = drm_helper_probe_single_connector_modes, .destroy = drm_connector_cleanup, .reset = drm_atomic_helper_connector_reset, @@ -19,6 +22,48 @@ static const struct drm_connector_funcs vkms_connector_funcs = { .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, }; +static const struct vkms_config_connector * +find_config_for_connector(struct drm_connector *connector) +{ + struct vkms_device *vkms = drm_device_to_vkms_device(connector->dev); + struct vkms_configfs *configfs = vkms->configfs; + struct config_item *item; + + if (!configfs) { + pr_info("Default connector has no configfs entry"); + return NULL; + } + + list_for_each_entry(item, &configfs->connectors_group.cg_children, + ci_entry) { + struct vkms_config_connector *config_connector = + item_to_config_connector(item); + if (config_connector->connector == connector) + return config_connector; + } + + pr_warn("Could not find config to match connector %s, but configfs was initialized", + connector->name); + + return NULL; +} + +enum drm_connector_status vkms_connector_detect(struct drm_connector *connector, + bool force) +{ + enum drm_connector_status status = connector_status_connected; + const struct vkms_config_connector *config_connector = + find_config_for_connector(connector); + + if (!config_connector) + return connector_status_connected; + + if (!config_connector->connected) + status = connector_status_disconnected; + + return status; +} + static const struct drm_encoder_funcs vkms_encoder_funcs = { .destroy = drm_encoder_cleanup, }; @@ -216,12 +261,12 @@ int vkms_output_init(struct vkms_device *vkmsdev) struct vkms_config_connector *config_connector = item_to_config_connector(item); struct drm_connector *connector = vkms_connector_init(vkmsdev); - if (IS_ERR(connector)) { DRM_ERROR("Failed to init connector from config: %s", item->ci_name); return PTR_ERR(connector); } + config_connector->connector = connector; for (int j = 0; j < output->num_encoders; j++) { struct encoder_map *encoder = &encoder_map[j];