From patchwork Mon Jul 1 03:24:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11024741 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 440D6746 for ; Mon, 1 Jul 2019 03:24:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3452D2849B for ; Mon, 1 Jul 2019 03:24:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 26DD8284C9; Mon, 1 Jul 2019 03:24:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id AFA8C2849B for ; Mon, 1 Jul 2019 03:24:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B12C088EF2; Mon, 1 Jul 2019 03:24:16 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x842.google.com (mail-qt1-x842.google.com [IPv6:2607:f8b0:4864:20::842]) by gabe.freedesktop.org (Postfix) with ESMTPS id D1EF489D77 for ; Mon, 1 Jul 2019 03:24:15 +0000 (UTC) Received: by mail-qt1-x842.google.com with SMTP id x47so13122842qtk.11 for ; Sun, 30 Jun 2019 20:24:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=K3NuKdFEgq5BVV5xPgHvrMD/faP4K7WOl8ZJ9WIj/Xk=; b=JvcZOhxIm6cABy43zx3B7sAfBiXCEGkRtivXzpb8UWH6Oa7kF7bbNvWuElzqCoeqnr YJEnutAHmFxoZDolKj+C5EXt0+ORZASPfzPmg6/29ZRojofOrCB2GQDGb4cy5uJGoe5q duA9bMWo8MLUHIvvoPT0gYLgEdRk1gYSqP5bF5jFoTgtpLnRUZrq+pMOyaJwS2RRzEd2 oA7MVxtn0ggXhXc3iAPos07xsUToh5cRVKkXHCwhDI56WcG5JtnVeEu0N5/cCKIu3aQK 5WTPtcjNghSLRJa+HrGHTX62/LRREnnHhF2ssHeXGqksa8MSgPkHzlAFvGKWAMwtd7HN 0Y3Q== X-Gm-Message-State: APjAAAW9dzGisept4cui5Vi2j/L8991jWzZQMvm9rXKYWPyanM0Fsehl 3qMngA/RCi3lqFlZD5TJIwY= X-Google-Smtp-Source: APXvYqzoNHdmQbwyteQnjItCSSCXAPmKX7z63t8UiKZy+sQ9oeM6hrklQWS1C2vZ3eHIPWlgspHSDw== X-Received: by 2002:a05:6214:10c5:: with SMTP id r5mr18310561qvs.224.1561951454954; Sun, 30 Jun 2019 20:24:14 -0700 (PDT) Received: from smtp.gmail.com ([187.121.151.22]) by smtp.gmail.com with ESMTPSA id f19sm667745qtq.5.2019.06.30.20.24.12 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 30 Jun 2019 20:24:14 -0700 (PDT) Date: Mon, 1 Jul 2019 00:24:10 -0300 From: Rodrigo Siqueira To: Daniel Vetter , Haneen Mohammed , David Airlie , Simon Ser Subject: [PATCH 1/2] drm/vkms: Add enable/disable functions per connector Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=K3NuKdFEgq5BVV5xPgHvrMD/faP4K7WOl8ZJ9WIj/Xk=; b=IvWQhGsm+FpCtynl/Y11txgTCNs/79JiJ3qwpzrawy3ctdoxx71HYmtq5iuDvf3HjM XVahi85PQv/zWxtzctSAZ0W8gplW2mEHBS7NgoZb8BrP4MyRLqt0Eri1Njxp1IKAj7gr BWCLifrNNigi87hshqwmhgyLgn4XwfpjI9xt3LGhCgaemkICwhk7RmT+mvZnDMyExooo bMhJEaM8154joJ1MB7ZqvPNV5yBmqWdwFJcQKDAA8wLjtr3lHuaSJEeQIzV0Di+KKT8A HXMQfwrDmgcqHXcecfeTnYpgzyxXhjoCQvucC5f9RC9K/TSpyqThOvE+CcDfMZhUUOY1 THbA== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Currently, virtual and writeback connectors have the code responsible for initialization and cleanup spread around different places in vkms. This patch creates an enable and disable function per connector which allows vkms to hotplug connectors easily. Signed-off-by: Rodrigo Siqueira --- drivers/gpu/drm/vkms/vkms_drv.h | 5 ++ drivers/gpu/drm/vkms/vkms_output.c | 84 +++++++++++++++++---------- drivers/gpu/drm/vkms/vkms_writeback.c | 31 ++++++++-- 3 files changed, 83 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 9ff2cd4ebf81..a1ca5c658355 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -152,7 +152,12 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name, /* Composer Support */ void vkms_composer_worker(struct work_struct *work); +/* Virtual connector */ +int enable_virtual_connector(struct vkms_device *vkmsdev); +void disable_virtual_connector(struct vkms_device *vkmsdev); + /* Writeback */ int enable_writeback_connector(struct vkms_device *vkmsdev); +void disable_writeback_connector(struct vkms_device *connector); #endif /* _VKMS_DRV_H_ */ diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index aea1d4410864..26ecab52e82e 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -6,6 +6,7 @@ static void vkms_connector_destroy(struct drm_connector *connector) { + drm_connector_unregister(connector); drm_connector_cleanup(connector); } @@ -35,37 +36,19 @@ static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { .get_modes = vkms_conn_get_modes, }; -int vkms_output_init(struct vkms_device *vkmsdev, int index) +int enable_virtual_connector(struct vkms_device *vkmsdev) { struct vkms_output *output = &vkmsdev->output; - struct drm_device *dev = &vkmsdev->drm; struct drm_connector *connector = &output->connector; struct drm_encoder *encoder = &output->encoder; - struct drm_crtc *crtc = &output->crtc; - struct drm_plane *primary, *cursor = NULL; + struct drm_device *dev = &vkmsdev->drm; int ret; - primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index); - if (IS_ERR(primary)) - return PTR_ERR(primary); - - if (enable_cursor) { - cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index); - if (IS_ERR(cursor)) { - ret = PTR_ERR(cursor); - goto err_cursor; - } - } - - ret = vkms_crtc_init(dev, crtc, primary, cursor); - if (ret) - goto err_crtc; - ret = drm_connector_init(dev, connector, &vkms_connector_funcs, DRM_MODE_CONNECTOR_VIRTUAL); if (ret) { DRM_ERROR("Failed to init connector\n"); - goto err_connector; + return ret; } drm_connector_helper_add(connector, &vkms_conn_helper_funcs); @@ -84,17 +67,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index) goto err_attach; } - if (enable_writeback) { - ret = enable_writeback_connector(vkmsdev); - if (!ret) { - output->composer_enabled = true; - DRM_INFO("Writeback connector enabled"); - } else { - DRM_ERROR("Failed to init writeback connector\n"); - } - } - - drm_mode_config_reset(dev); + drm_connector_register(connector); return 0; @@ -104,6 +77,53 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index) err_encoder: drm_connector_cleanup(connector); + return ret; +} + +void disable_virtual_connector(struct vkms_device *vkmsdev) +{ + struct vkms_output *output = &vkmsdev->output; + + drm_connector_unregister(&output->connector); + drm_connector_cleanup(&output->connector); + drm_encoder_cleanup(&output->encoder); +} + +int vkms_output_init(struct vkms_device *vkmsdev, int index) +{ + struct vkms_output *output = &vkmsdev->output; + struct drm_device *dev = &vkmsdev->drm; + struct drm_crtc *crtc = &output->crtc; + struct drm_plane *primary, *cursor = NULL; + int ret; + + primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index); + if (IS_ERR(primary)) + return PTR_ERR(primary); + + if (enable_cursor) { + cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index); + if (IS_ERR(cursor)) { + ret = PTR_ERR(cursor); + goto err_cursor; + } + } + + ret = vkms_crtc_init(dev, crtc, primary, cursor); + if (ret) + goto err_crtc; + + ret = enable_virtual_connector(vkmsdev); + if (ret) + goto err_connector; + + if (enable_writeback) + enable_writeback_connector(vkmsdev); + + drm_mode_config_reset(dev); + + return 0; + err_connector: drm_crtc_cleanup(crtc); diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c index 34dad37a0236..6a3f37d60c1d 100644 --- a/drivers/gpu/drm/vkms/vkms_writeback.c +++ b/drivers/gpu/drm/vkms/vkms_writeback.c @@ -125,17 +125,38 @@ static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = { .atomic_commit = vkms_wb_atomic_commit, }; +void disable_writeback_connector(struct vkms_device *vkmsdev) +{ + struct vkms_output *output = &vkmsdev->output; + + output->composer_enabled = false; + drm_connector_unregister(&output->wb_connector.base); + drm_connector_cleanup(&output->wb_connector.base); + drm_encoder_cleanup(&output->wb_connector.encoder); +} + int enable_writeback_connector(struct vkms_device *vkmsdev) { struct drm_writeback_connector *wb = &vkmsdev->output.wb_connector; + int ret; vkmsdev->output.wb_connector.encoder.possible_crtcs = 1; drm_connector_helper_add(&wb->base, &vkms_wb_conn_helper_funcs); - return drm_writeback_connector_init(&vkmsdev->drm, wb, - &vkms_wb_connector_funcs, - &vkms_wb_encoder_helper_funcs, - vkms_wb_formats, - ARRAY_SIZE(vkms_wb_formats)); + ret = drm_writeback_connector_init(&vkmsdev->drm, wb, + &vkms_wb_connector_funcs, + &vkms_wb_encoder_helper_funcs, + vkms_wb_formats, + ARRAY_SIZE(vkms_wb_formats)); + if (!ret) { + vkmsdev->output.composer_enabled = true; + DRM_INFO("Writeback connector enabled"); + } else { + DRM_ERROR("Failed to init writeback connector\n"); + } + + drm_connector_register(&wb->base); + + return ret; } From patchwork Mon Jul 1 03:24:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 11024745 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4C6471398 for ; Mon, 1 Jul 2019 03:24:44 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3BAF42849B for ; Mon, 1 Jul 2019 03:24:44 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2F5CB284C9; Mon, 1 Jul 2019 03:24:44 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9AF502849B for ; Mon, 1 Jul 2019 03:24:43 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B860589715; Mon, 1 Jul 2019 03:24:42 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt1-x844.google.com (mail-qt1-x844.google.com [IPv6:2607:f8b0:4864:20::844]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1F13189715 for ; Mon, 1 Jul 2019 03:24:41 +0000 (UTC) Received: by mail-qt1-x844.google.com with SMTP id m29so13190727qtu.1 for ; Sun, 30 Jun 2019 20:24:41 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=TBkGIpZDTRWUqhge/wC7uC1qGZRr0i17gzx2p4IYZwY=; b=JOlIihjTYEzvbxntgIUjkpsgPnF4LSVHQrX9qp+NCOCuKiF0Fon47qJN/lHQa6eERk WHgHBDSoHRESm+7XVT1zSRbE3FhNosxCJ9STO6Lc6wHt9f/zjdh6tBFM1J3ZPzyL/HQI 88HfUfjo36sPk1HX/KhAApy6PUjUxVtkzSXNieCIxsribofUFU5UHhJe7CqnHqBNpLBb 29wE+Qx83uzeSVqUXHJw2ek4DrpPCu2AsJ3sUEqv0wYxw6gZklCCd6LWAAaQTy5Y8I9Q bvvy7Bchz7kuNX+dVbgX7f6v5DIdQiERMiTHGIOJEj7dp16CTcO+uTRnnqU0XwF/fVhw Kw/w== X-Gm-Message-State: APjAAAWZUtAd0wLydk4VR6Z2QD9Zu0kChvFc8iUOUlS0nLCxDd3jBqBb nzFTjZaEytcEvf0OvpTm+wQ= X-Google-Smtp-Source: APXvYqzTygIW3Zvf1UugDAWJd6BU2aigSwWo22zGT0E2LGG8WIzpV5rgihga//zrTeHm6VlkC7OdVw== X-Received: by 2002:ad4:5283:: with SMTP id v3mr19343701qvr.207.1561951480157; Sun, 30 Jun 2019 20:24:40 -0700 (PDT) Received: from smtp.gmail.com ([187.121.151.22]) by smtp.gmail.com with ESMTPSA id g53sm5172840qtk.65.2019.06.30.20.24.37 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 30 Jun 2019 20:24:39 -0700 (PDT) Date: Mon, 1 Jul 2019 00:24:35 -0300 From: Rodrigo Siqueira To: Daniel Vetter , Haneen Mohammed , David Airlie , Simon Ser Subject: [PATCH 2/2] drm/vkms: Introduce configfs for enabling/disabling connectors Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=TBkGIpZDTRWUqhge/wC7uC1qGZRr0i17gzx2p4IYZwY=; b=JzzYNO6MunIO3mqHv0ndJxirDJcdQSSuFy9YMsqQ/p0d88m+Jx3kE6huuOS0bPQqCK Tc0oTqzZ8bf/By2K9MFrBZ4119RgZRvIPe7Ynk9jq/wNgYeV3SqqM14z+BjeqbEnqOCL DiAHD3aLJVxmRdzSVdvMFPJKaPWRtgQyaNELNte+fDfGr+V0+i2PgnNHqde7GMykF0J5 QFrp3oh/qCy30tElf9dXyswsUbOyZyP4AIRtLx89hgBtsfbOjLubvZhTdRw+LZICHJpY B+pWWQol1kQbuVNsgEE1S72iMIqqeT4U8pIy7nZiXRcN7q8UOLg9E8HtfzyboaFuIzSP vCDw== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This patch introduces an implementation of vkms subsystems through configfs; we want to be able to reconfigure vkms instance without having to reload the module. This commit adds the primary support for configfs by allowing vkms to expose the ability to enable/disable its connectors. Signed-off-by: Rodrigo Siqueira --- drivers/gpu/drm/vkms/Makefile | 3 +- drivers/gpu/drm/vkms/vkms_configfs.c | 229 +++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_drv.c | 6 + drivers/gpu/drm/vkms/vkms_drv.h | 12 ++ 4 files changed, 249 insertions(+), 1 deletion(-) create mode 100644 drivers/gpu/drm/vkms/vkms_configfs.c diff --git a/drivers/gpu/drm/vkms/Makefile b/drivers/gpu/drm/vkms/Makefile index 333d3cead0e3..f90c016cd9fe 100644 --- a/drivers/gpu/drm/vkms/Makefile +++ b/drivers/gpu/drm/vkms/Makefile @@ -6,6 +6,7 @@ vkms-y := \ vkms_crtc.o \ vkms_gem.o \ vkms_composer.o \ - vkms_writeback.o + vkms_writeback.o \ + vkms_configfs.o obj-$(CONFIG_DRM_VKMS) += vkms.o diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c new file mode 100644 index 000000000000..5d1a30517cca --- /dev/null +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -0,0 +1,229 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include "vkms_drv.h" + +static struct config_group *connector_group; +static struct vkms_device *vkms_device; + +static char *available_connectors[] = { + "Virtual", + "Writeback", +}; + +struct connectors_fs { + struct config_item item; + bool enable; +}; + +static int enable_connector(const char *name) +{ + int ret = 0; + + if (!strcmp(name, "Writeback")) + ret = enable_writeback_connector(vkms_device); + else if (!strcmp(name, "Virtual")) + ret = enable_virtual_connector(vkms_device); + + if (ret) + return ret; + + drm_mode_config_reset(&vkms_device->drm); + return 0; +} + +static void disable_connector(const char *name) +{ + if (!strcmp(name, "Writeback")) + disable_writeback_connector(vkms_device); + else if (!strcmp(name, "Virtual")) + disable_virtual_connector(vkms_device); +} + +static inline struct connectors_fs *to_conn_item(struct config_item *item) +{ + return item ? container_of(item, struct connectors_fs, item) : NULL; +} + +static ssize_t conn_fs_enable_show(struct config_item *item, char *page) +{ + struct connectors_fs *conn_item = to_conn_item(item); + + return sprintf(page, "%d\n", conn_item->enable); +} + +static ssize_t conn_fs_enable_store(struct config_item *item, + const char *page, size_t count) +{ + struct connectors_fs *conn_item = to_conn_item(item); + char *p = (char *)page; + unsigned int enable; + int ret; + + ret = kstrtouint(p, 10, &enable); + if (ret) + return -EINVAL; + + if (enable > 1) + return -EINVAL; + + if (enable == conn_item->enable) + return count; + + if (enable) { + ret = enable_connector(item->ci_name); + if (ret) + return ret; + } else { + disable_connector(item->ci_name); + } + + conn_item->enable = enable ? true : false; + return count; +} + +CONFIGFS_ATTR(conn_fs_, enable); + +static struct configfs_attribute *connectors_fs_attrs[] = { + &conn_fs_attr_enable, + NULL, +}; + +static void connectors_fs_release(struct config_item *item) +{ + kfree(to_conn_item(item)); +} + +static struct configfs_item_operations connectors_fs_ops = { + .release = connectors_fs_release, +}; + +static const struct config_item_type connectors_fs_type = { + .ct_item_ops = &connectors_fs_ops, + .ct_attrs = connectors_fs_attrs, + .ct_owner = THIS_MODULE, +}; + +static struct config_item *make_connector_item(struct config_group *group, + const char *name) +{ + struct connectors_fs *conn_item; + int i, ret, total_conn = ARRAY_SIZE(available_connectors); + + for (i = 0; i < total_conn; i++) + if (!strcmp(name, available_connectors[i])) + break; + + if (i == total_conn) + return ERR_PTR(-EINVAL); + + ret = enable_connector(name); + if (ret) + return ERR_PTR(ret); + + conn_item = kzalloc(sizeof(*conn_item), GFP_KERNEL); + if (!conn_item) + return ERR_PTR(-ENOMEM); + + config_item_init_type_name(&conn_item->item, name, + &connectors_fs_type); + + conn_item->enable = true; + + return &conn_item->item; +} + +static void drop_connector_item(struct config_group *group, + struct config_item *item) +{ + char *name = item->ci_name; + + disable_connector(name); + + config_item_put(item); +} + +static struct configfs_group_operations connector_group_ops = { + .make_item = make_connector_item, + .drop_item = drop_connector_item, +}; + +static const struct config_item_type connector_type = { + .ct_group_ops = &connector_group_ops, + .ct_owner = THIS_MODULE, +}; + +static const struct config_item_type vkms_subsystem_type = { + .ct_owner = THIS_MODULE, +}; + +static struct configfs_subsystem vkms_subsystem = { + .su_group = { + .cg_item = { + .ci_namebuf = "vkms", + .ci_type = &vkms_subsystem_type, + }, + }, + .su_mutex = __MUTEX_INITIALIZER(vkms_subsystem.su_mutex), +}; + +static void init_default_conn_configfs(struct config_group *root) +{ + struct vkms_config_state *config_state = &vkms_device->config_state; + int i, ret; + + connector_group = configfs_register_default_group(root, "connectors", + &connector_type); + if (IS_ERR(connector_group)) { + ret = PTR_ERR(connector_group); + pr_err("Error %d while registering functions group\n", ret); + return; + } + + for (i = 0; i < ARRAY_SIZE(available_connectors); i++) { + struct config_group *group = config_state->connectors[i]; + + if (!strcmp(available_connectors[i], "Writeback") && + !enable_writeback) + continue; + + group = configfs_register_default_group(connector_group, + available_connectors[i], + &connectors_fs_type); + if (IS_ERR(connector_group)) { + ret = PTR_ERR(config_state->connectors[i]); + DRM_ERROR("Error %d while trying to register %s\n", + ret, available_connectors[i]); + continue; + } + + to_conn_item(&group->cg_item)->enable = true; + } +} + +int vkms_configfs_init(struct vkms_device *vkmsdev) +{ + struct config_group *root = &vkms_subsystem.su_group; + int ret; + + vkms_device = vkmsdev; + + config_group_init(root); + ret = configfs_register_subsystem(&vkms_subsystem); + if (ret) { + pr_err("Error %d while registering subsystem %s\n", ret, + root->cg_item.ci_namebuf); + goto err; + } + + init_default_conn_configfs(root); + + return 0; + +err: + return ret; +} + +void vkms_configfs_exit(void) +{ + configfs_unregister_subsystem(&vkms_subsystem); +} diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 152d7de24a76..a930a5a52ce4 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -166,6 +166,10 @@ static int __init vkms_init(void) if (ret) goto out_fini; + ret = vkms_configfs_init(vkms_device); + if (ret) + DRM_ERROR("Could not initialize configfs"); + ret = drm_dev_register(&vkms_device->drm, 0); if (ret) goto out_fini; @@ -194,6 +198,8 @@ static void __exit vkms_exit(void) drm_dev_put(&vkms_device->drm); kfree(vkms_device); + + vkms_configfs_exit(); } module_init(vkms_init); diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index a1ca5c658355..c811bc192606 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -9,6 +9,7 @@ #include #include #include +#include #define XRES_MIN 20 #define YRES_MIN 20 @@ -83,10 +84,17 @@ struct vkms_output { spinlock_t composer_lock; }; +#define MAX_CONN_CONFIGFS 10 + +struct vkms_config_state { + struct config_group *connectors[MAX_CONN_CONFIGFS]; +}; + struct vkms_device { struct drm_device drm; struct platform_device *platform; struct vkms_output output; + struct vkms_config_state config_state; }; struct vkms_gem_object { @@ -160,4 +168,8 @@ void disable_virtual_connector(struct vkms_device *vkmsdev); int enable_writeback_connector(struct vkms_device *vkmsdev); void disable_writeback_connector(struct vkms_device *connector); +/* Configfs */ +int vkms_configfs_init(struct vkms_device *vkmsdev); +void vkms_configfs_exit(void); + #endif /* _VKMS_DRV_H_ */