From patchwork Fri Jun 23 22:23:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Shargo X-Patchwork-Id: 13291427 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 01C6AEB64D7 for ; Fri, 23 Jun 2023 22:25:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1C30110E6D0; Fri, 23 Jun 2023 22:25:30 +0000 (UTC) Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by gabe.freedesktop.org (Postfix) with ESMTPS id C6D7310E6D0 for ; Fri, 23 Jun 2023 22:25:28 +0000 (UTC) Received: by mail-wr1-x432.google.com with SMTP id ffacd0b85a97d-3128fcd58f3so1269210f8f.1 for ; Fri, 23 Jun 2023 15:25:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687559127; x=1690151127; 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=xDShF6Qfrh0D9ZEbjzdHO4vNlJH6hZ7KH6f6b8K8APA=; b=drspUz+hUGzMT9U5ivf5vWK3qfcNW9c/NVqi/JzyQT+hugXZQsd7ntaPyQuPTMeeh4 ovDjNAMdSzl/dg5pU5Cg0O1vwPivc9Gu+V/D0yQBUDPUrvuPGyt2sJvpHye2WgXMJ/0s obrmq+VEPBLo+u5JNbPPbOHLYKo5d6g57rhqQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687559127; x=1690151127; 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=xDShF6Qfrh0D9ZEbjzdHO4vNlJH6hZ7KH6f6b8K8APA=; b=AB4aSvbStk0JWqrA3/PkRA8IMakzbm72fSl2lup4s7eICy7UCykfJSsgpLDzsNB5V5 3cLkteXJVZW0oVTAnmzdfZtdKW5Bp/mCEqyRhDaA4Ze+mRdgytKBIAE/Y+4Rf13B9kw0 CL3VF0MP+Oaau6ziXZB7yHzhJiHMVsieboWTV02GEazv0rEWhez5ENTO+sUniIz1sXJ7 jEQD2sAX64WbQ6tE2xDwqKKFwikYZleqt0yW3b4cnWUyg+bOaMu+JKTSiRNvO+YmmwBd 2jwLSbv4YU37wuOdmK/JMk3awqQUDRjMtPj+S01SqE96UuoSu7HOKda6QcyS02spb+ME 0H/A== X-Gm-Message-State: AC+VfDwI1r/TxwawArLMbEmMaOjepdMKC8GvGHWTGMBYK2vFr2FgMkGL 8ILpP8eVUCTHMiKedcAzBPswOA== X-Google-Smtp-Source: ACHHUZ7meVCEmPXqJPKja7ki27JkhwCIGc8TspAz4yy4Va7frt40CBBAFpdlXOf1i/+GcsmA+9okQg== X-Received: by 2002:adf:dfca:0:b0:30e:432b:c54 with SMTP id q10-20020adfdfca000000b0030e432b0c54mr17827827wrn.18.1687559126902; Fri, 23 Jun 2023 15:25:26 -0700 (PDT) Received: from big-boopo.mynetworksettings.com (pool-108-46-233-209.nycmny.fios.verizon.net. [108.46.233.209]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4106000000b0030c2e3c7fb3sm453223wrp.101.2023.06.23.15.25.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 15:25:26 -0700 (PDT) From: Jim Shargo To: mairacanal@riseup.net, Daniel Vetter , David Airlie , Haneen Mohammed , Jonathan Corbet , Maarten Lankhorst , Maxime Ripard , Melissa Wen , Rodrigo Siqueira , Thomas Zimmermann Subject: [PATCH v2 1/6] drm/vkms: Back VKMS with DRM memory management instead of static objects Date: Fri, 23 Jun 2023 18:23:43 -0400 Message-ID: <20230623222353.97283-2-jshargo@chromium.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230623222353.97283-1-jshargo@chromium.org> References: <20230623222353.97283-1-jshargo@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: Jim Shargo , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This is a small refactor to make ConfigFS support easier. Once we support ConfigFS, there can be multiple devices instantiated by the driver, and so moving everything into managed memory makes things much easier. This should be a no-op refactor. Signed-off-by: Jim Shargo --- drivers/gpu/drm/vkms/vkms_drv.c | 130 +++++++++++++++-------------- drivers/gpu/drm/vkms/vkms_drv.h | 4 +- drivers/gpu/drm/vkms/vkms_output.c | 6 +- 3 files changed, 72 insertions(+), 68 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index e3c9c9571c8d..f07454fff046 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -9,10 +9,12 @@ * the GPU in DRM API tests. */ +#include #include #include #include +#include #include #include #include @@ -37,8 +39,6 @@ #define DRIVER_MAJOR 1 #define DRIVER_MINOR 0 -static struct vkms_config *default_config; - static bool enable_cursor = true; module_param_named(enable_cursor, enable_cursor, bool, 0444); MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support"); @@ -92,13 +92,13 @@ static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state) static int vkms_config_show(struct seq_file *m, void *data) { - struct drm_debugfs_entry *entry = m->private; - struct drm_device *dev = entry->dev; - struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev); + struct drm_info_node *drm_info = m->private; + struct vkms_device *vkms_device = + drm_device_to_vkms_device(drm_info->minor->dev); - seq_printf(m, "writeback=%d\n", vkmsdev->config->writeback); - seq_printf(m, "cursor=%d\n", vkmsdev->config->cursor); - seq_printf(m, "overlay=%d\n", vkmsdev->config->overlay); + seq_printf(m, "writeback=%d\n", vkms_device->config.writeback); + seq_printf(m, "cursor=%d\n", vkms_device->config.cursor); + seq_printf(m, "overlay=%d\n", vkms_device->config.overlay); return 0; } @@ -155,114 +155,120 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) return vkms_output_init(vkmsdev, 0); } -static int vkms_create(struct vkms_config *config) +static int vkms_platform_probe(struct platform_device *pdev) { int ret; - struct platform_device *pdev; struct vkms_device *vkms_device; + void *grp; - pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); - if (IS_ERR(pdev)) - return PTR_ERR(pdev); - - if (!devres_open_group(&pdev->dev, NULL, GFP_KERNEL)) { - ret = -ENOMEM; - goto out_unregister; + grp = devres_open_group(&pdev->dev, NULL, GFP_KERNEL); + if (!grp) { + return -ENOMEM; } vkms_device = devm_drm_dev_alloc(&pdev->dev, &vkms_driver, struct vkms_device, drm); if (IS_ERR(vkms_device)) { ret = PTR_ERR(vkms_device); - goto out_devres; + goto out_release_group; } + vkms_device->platform = pdev; - vkms_device->config = config; - config->dev = vkms_device; + vkms_device->config.cursor = enable_cursor; + vkms_device->config.writeback = enable_writeback; + vkms_device->config.overlay = enable_overlay; ret = dma_coerce_mask_and_coherent(vkms_device->drm.dev, DMA_BIT_MASK(64)); - if (ret) { DRM_ERROR("Could not initialize DMA support\n"); - goto out_devres; + goto out_release_group; } ret = drm_vblank_init(&vkms_device->drm, 1); if (ret) { DRM_ERROR("Failed to vblank\n"); - goto out_devres; + goto out_release_group; } ret = vkms_modeset_init(vkms_device); - if (ret) - goto out_devres; + if (ret) { + DRM_ERROR("Unable to initialize modesetting\n"); + goto out_release_group; + } drm_debugfs_add_files(&vkms_device->drm, vkms_config_debugfs_list, ARRAY_SIZE(vkms_config_debugfs_list)); ret = drm_dev_register(&vkms_device->drm, 0); - if (ret) - goto out_devres; + if (ret) { + DRM_ERROR("Unable to register device\n"); + return ret; + } drm_fbdev_generic_setup(&vkms_device->drm, 0); + platform_set_drvdata(pdev, vkms_device); + devres_close_group(&pdev->dev, grp); return 0; -out_devres: - devres_release_group(&pdev->dev, NULL); -out_unregister: - platform_device_unregister(pdev); +out_release_group: + devres_release_group(&pdev->dev, grp); return ret; } -static int __init vkms_init(void) +static int vkms_platform_remove(struct platform_device *pdev) { - int ret; - struct vkms_config *config; - - config = kmalloc(sizeof(*config), GFP_KERNEL); - if (!config) - return -ENOMEM; - - default_config = config; + struct vkms_device *vkms_device; - config->cursor = enable_cursor; - config->writeback = enable_writeback; - config->overlay = enable_overlay; + vkms_device = platform_get_drvdata(pdev); + if (!vkms_device) + return 0; - ret = vkms_create(config); - if (ret) - kfree(config); - - return ret; + drm_dev_unregister(&vkms_device->drm); + drm_atomic_helper_shutdown(&vkms_device->drm); + return 0; } -static void vkms_destroy(struct vkms_config *config) +static struct platform_driver vkms_platform_driver = { + .probe = vkms_platform_probe, + .remove = vkms_platform_remove, + .driver.name = DRIVER_NAME, +}; + +static int __init vkms_init(void) { + int ret; struct platform_device *pdev; - if (!config->dev) { - DRM_INFO("vkms_device is NULL.\n"); - return; + ret = platform_driver_register(&vkms_platform_driver); + if (ret) { + DRM_ERROR("Unable to register platform driver\n"); + return ret; } - pdev = config->dev->platform; - - drm_dev_unregister(&config->dev->drm); - drm_atomic_helper_shutdown(&config->dev->drm); - devres_release_group(&pdev->dev, NULL); - platform_device_unregister(pdev); + pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); + if (IS_ERR(pdev)) { + platform_driver_unregister(&vkms_platform_driver); + return PTR_ERR(pdev); + } - config->dev = NULL; + return 0; } static void __exit vkms_exit(void) { - if (default_config->dev) - vkms_destroy(default_config); + struct device *dev; + + while ((dev = platform_find_device_by_driver( + NULL, &vkms_platform_driver.driver))) { + // platform_find_device_by_driver increments the refcount. Drop + // it so we don't leak memory. + put_device(dev); + platform_device_unregister(to_platform_device(dev)); + } - kfree(default_config); + platform_driver_unregister(&vkms_platform_driver); } module_init(vkms_init); diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 5f1a0a44a78c..e87c8aea6fb3 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -114,15 +114,13 @@ struct vkms_config { bool writeback; bool cursor; bool overlay; - /* only set when instantiated */ - struct vkms_device *dev; }; struct vkms_device { struct drm_device drm; struct platform_device *platform; struct vkms_output output; - const struct vkms_config *config; + struct vkms_config config; }; #define drm_crtc_to_vkms_output(target) \ diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index 5ce70dd946aa..963a64cf068b 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -62,7 +62,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index) if (IS_ERR(primary)) return PTR_ERR(primary); - if (vkmsdev->config->overlay) { + if (vkmsdev->config.overlay) { for (n = 0; n < NUM_OVERLAY_PLANES; n++) { ret = vkms_add_overlay_plane(vkmsdev, index, crtc); if (ret) @@ -70,7 +70,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index) } } - if (vkmsdev->config->cursor) { + if (vkmsdev->config.cursor) { cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index); if (IS_ERR(cursor)) return PTR_ERR(cursor); @@ -103,7 +103,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index) goto err_attach; } - if (vkmsdev->config->writeback) { + if (vkmsdev->config.writeback) { writeback = vkms_enable_writeback_connector(vkmsdev); if (writeback) DRM_ERROR("Failed to init writeback connector\n"); From patchwork Fri Jun 23 22:23:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Shargo X-Patchwork-Id: 13291428 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 DF88BEB64DD for ; Fri, 23 Jun 2023 22:25:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4886B10E6D8; Fri, 23 Jun 2023 22:25:35 +0000 (UTC) Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2C4BB10E6D1 for ; Fri, 23 Jun 2023 22:25:33 +0000 (UTC) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3113306a595so1308099f8f.1 for ; Fri, 23 Jun 2023 15:25:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687559131; x=1690151131; 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=FkicQ8f9Of7cZkq4xhOVVHD5gN5SpnuuaR7ZuPIrTSs=; b=oMYSypqf2VIJ4sp9fklYnDaZmzRMSBoEdkyqakXjEZ+7+0mnXYM+RMcxS7Kh7F/eWs 97/rbL9QnULIeg4ohjunGtYZFzhqV4GFPlP+f6B7Ayff87LOr2BvfwcL5JLHkKTVTiY8 a5tpxpqAt48N57oORCql858Y8qrIjmDyrPEUA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687559131; x=1690151131; 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=FkicQ8f9Of7cZkq4xhOVVHD5gN5SpnuuaR7ZuPIrTSs=; b=WZJoIlL4oN0VqGasEglqmXDZ2tf6MhAZuqH8j1OOkEY0hJnU6xsTY+N23qGKYxAtU/ nh/Q7rLPlxkp0qylqel3LL/DzEqgyPxptzMTKOTbhN1PH88fBG5aFjyAPIPKvny1/jwW CcZy9K8ooluNCC9zcyZhj5GLX9Gki4NUpKEYcMavQys83w24EW4/4rPyu1RFMo7OO4fS fFdTih+WWmBkYG/Bd4plXjeKBphPn96oR+CqGFjhCgNrx3W0sQeBUaIpKHClJRfnkcLk DLBA2xz5rMGuCDMezrE0lmD5Qr6hpDLK5tumypdAG7ZBgB67wSy0oiit/hXYp/Tn5KWs AaIg== X-Gm-Message-State: AC+VfDzU75L+M2won+tSecvPZQCKrvPJFxCMT7mLrcH+GifufDPfdAIQ 99gPXI8Lhn4RrRY8++QP4nRm9w== X-Google-Smtp-Source: ACHHUZ556wua0ZP1D126ui6nUhouD1XbUeUyh9F802BRQP2fsSqaNkDmixcgz2T+YqFY43fvbqQ31A== X-Received: by 2002:a5d:67cd:0:b0:311:1ce8:d05b with SMTP id n13-20020a5d67cd000000b003111ce8d05bmr19442456wrw.20.1687559130999; Fri, 23 Jun 2023 15:25:30 -0700 (PDT) Received: from big-boopo.mynetworksettings.com (pool-108-46-233-209.nycmny.fios.verizon.net. [108.46.233.209]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4106000000b0030c2e3c7fb3sm453223wrp.101.2023.06.23.15.25.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 15:25:30 -0700 (PDT) From: Jim Shargo To: mairacanal@riseup.net, Daniel Vetter , David Airlie , Haneen Mohammed , Jonathan Corbet , Maarten Lankhorst , Maxime Ripard , Melissa Wen , Rodrigo Siqueira , Thomas Zimmermann Subject: [PATCH v2 2/6] drm/vkms: Support multiple DRM objects (crtcs, etc.) per VKMS device Date: Fri, 23 Jun 2023 18:23:44 -0400 Message-ID: <20230623222353.97283-3-jshargo@chromium.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230623222353.97283-1-jshargo@chromium.org> References: <20230623222353.97283-1-jshargo@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: Jim Shargo , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This change supports multiple CRTCs, encoders, connectors instead of one of each per device. Since ConfigFS-based devices will support multiple crtcs, it's useful to move all of the writeback/composition data from being per-"output" to being per-CRTC. Since there's still only ever one CRTC, this should be a no-op refactor. Signed-off-by: Jim Shargo --- drivers/gpu/drm/vkms/vkms_composer.c | 28 +++--- drivers/gpu/drm/vkms/vkms_crtc.c | 95 +++++++++++--------- drivers/gpu/drm/vkms/vkms_drv.c | 14 +-- drivers/gpu/drm/vkms/vkms_drv.h | 65 +++++++++----- drivers/gpu/drm/vkms/vkms_output.c | 123 ++++++++++++++++++-------- drivers/gpu/drm/vkms/vkms_plane.c | 44 ++++++--- drivers/gpu/drm/vkms/vkms_writeback.c | 26 +++--- 7 files changed, 252 insertions(+), 143 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c index 1636ce3a79f9..75fa42e0ec07 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -230,13 +230,13 @@ void vkms_composer_worker(struct work_struct *work) composer_work); struct drm_crtc *crtc = crtc_state->base.crtc; struct vkms_writeback_job *active_wb = crtc_state->active_writeback; - struct vkms_output *out = drm_crtc_to_vkms_output(crtc); + struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc); bool crc_pending, wb_pending; u64 frame_start, frame_end; u32 crc32 = 0; int ret; - spin_lock_irq(&out->composer_lock); + spin_lock_irq(&vkms_crtc->composer_lock); frame_start = crtc_state->frame_start; frame_end = crtc_state->frame_end; crc_pending = crtc_state->crc_pending; @@ -244,7 +244,7 @@ void vkms_composer_worker(struct work_struct *work) crtc_state->frame_start = 0; crtc_state->frame_end = 0; crtc_state->crc_pending = false; - spin_unlock_irq(&out->composer_lock); + spin_unlock_irq(&vkms_crtc->composer_lock); /* * We raced with the vblank hrtimer and previous work already computed @@ -262,10 +262,10 @@ void vkms_composer_worker(struct work_struct *work) return; if (wb_pending) { - drm_writeback_signal_completion(&out->wb_connector, 0); - spin_lock_irq(&out->composer_lock); + drm_writeback_signal_completion(&vkms_crtc->wb_connector, 0); + spin_lock_irq(&vkms_crtc->composer_lock); crtc_state->wb_pending = false; - spin_unlock_irq(&out->composer_lock); + spin_unlock_irq(&vkms_crtc->composer_lock); } /* @@ -315,25 +315,25 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *src_name, return 0; } -void vkms_set_composer(struct vkms_output *out, bool enabled) +void vkms_set_composer(struct vkms_crtc *vkms_crtc, bool enabled) { bool old_enabled; if (enabled) - drm_crtc_vblank_get(&out->crtc); + drm_crtc_vblank_get(&vkms_crtc->base); - spin_lock_irq(&out->lock); - old_enabled = out->composer_enabled; - out->composer_enabled = enabled; - spin_unlock_irq(&out->lock); + spin_lock_irq(&vkms_crtc->lock); + old_enabled = vkms_crtc->composer_enabled; + vkms_crtc->composer_enabled = enabled; + spin_unlock_irq(&vkms_crtc->lock); if (old_enabled) - drm_crtc_vblank_put(&out->crtc); + drm_crtc_vblank_put(&vkms_crtc->base); } int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name) { - struct vkms_output *out = drm_crtc_to_vkms_output(crtc); + struct vkms_crtc *out = drm_crtc_to_vkms_crtc(crtc); bool enabled = false; int ret = 0; diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index 515f6772b866..d91e49c53adc 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -11,35 +11,34 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) { - struct vkms_output *output = container_of(timer, struct vkms_output, - vblank_hrtimer); - struct drm_crtc *crtc = &output->crtc; + struct vkms_crtc *vkms_crtc = timer_to_vkms_crtc(timer); + struct drm_crtc *crtc = &vkms_crtc->base; struct vkms_crtc_state *state; u64 ret_overrun; bool ret, fence_cookie; fence_cookie = dma_fence_begin_signalling(); - ret_overrun = hrtimer_forward_now(&output->vblank_hrtimer, - output->period_ns); + ret_overrun = hrtimer_forward_now(&vkms_crtc->vblank_hrtimer, + vkms_crtc->period_ns); if (ret_overrun != 1) pr_warn("%s: vblank timer overrun\n", __func__); - spin_lock(&output->lock); + spin_lock(&vkms_crtc->lock); ret = drm_crtc_handle_vblank(crtc); if (!ret) DRM_ERROR("vkms failure on handling vblank"); - state = output->composer_state; - spin_unlock(&output->lock); + state = vkms_crtc->composer_state; + spin_unlock(&vkms_crtc->lock); - if (state && output->composer_enabled) { + if (state && vkms_crtc->composer_enabled) { u64 frame = drm_crtc_accurate_vblank_count(crtc); /* update frame_start only if a queued vkms_composer_worker() * has read the data */ - spin_lock(&output->composer_lock); + spin_lock(&vkms_crtc->composer_lock); if (!state->crc_pending) state->frame_start = frame; else @@ -47,9 +46,10 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) state->frame_start, frame); state->frame_end = frame; state->crc_pending = true; - spin_unlock(&output->composer_lock); + spin_unlock(&vkms_crtc->composer_lock); - ret = queue_work(output->composer_workq, &state->composer_work); + ret = queue_work(vkms_crtc->composer_workq, + &state->composer_work); if (!ret) DRM_DEBUG_DRIVER("Composer worker already queued\n"); } @@ -62,25 +62,27 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) static int vkms_enable_vblank(struct drm_crtc *crtc) { struct drm_device *dev = crtc->dev; + struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc); unsigned int pipe = drm_crtc_index(crtc); struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; - struct vkms_output *out = drm_crtc_to_vkms_output(crtc); drm_calc_timestamping_constants(crtc, &crtc->mode); - hrtimer_init(&out->vblank_hrtimer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); - out->vblank_hrtimer.function = &vkms_vblank_simulate; - out->period_ns = ktime_set(0, vblank->framedur_ns); - hrtimer_start(&out->vblank_hrtimer, out->period_ns, HRTIMER_MODE_REL); + hrtimer_init(&vkms_crtc->vblank_hrtimer, CLOCK_MONOTONIC, + HRTIMER_MODE_REL); + vkms_crtc->vblank_hrtimer.function = &vkms_vblank_simulate; + vkms_crtc->period_ns = ktime_set(0, vblank->framedur_ns); + hrtimer_start(&vkms_crtc->vblank_hrtimer, vkms_crtc->period_ns, + HRTIMER_MODE_REL); return 0; } static void vkms_disable_vblank(struct drm_crtc *crtc) { - struct vkms_output *out = drm_crtc_to_vkms_output(crtc); + struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc); - hrtimer_cancel(&out->vblank_hrtimer); + hrtimer_cancel(&vkms_crtc->vblank_hrtimer); } static bool vkms_get_vblank_timestamp(struct drm_crtc *crtc, @@ -88,9 +90,8 @@ static bool vkms_get_vblank_timestamp(struct drm_crtc *crtc, bool in_vblank_irq) { struct drm_device *dev = crtc->dev; + struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc); unsigned int pipe = crtc->index; - struct vkms_device *vkmsdev = drm_device_to_vkms_device(dev); - struct vkms_output *output = &vkmsdev->output; struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; if (!READ_ONCE(vblank->enabled)) { @@ -98,7 +99,7 @@ static bool vkms_get_vblank_timestamp(struct drm_crtc *crtc, return true; } - *vblank_time = READ_ONCE(output->vblank_hrtimer.node.expires); + *vblank_time = READ_ONCE(vkms_crtc->vblank_hrtimer.node.expires); if (WARN_ON(*vblank_time == vblank->time)) return true; @@ -110,7 +111,7 @@ static bool vkms_get_vblank_timestamp(struct drm_crtc *crtc, * the vblank core expects. Therefore we need to always correct the * timestampe by one frame. */ - *vblank_time -= output->period_ns; + *vblank_time -= vkms_crtc->period_ns; return true; } @@ -236,18 +237,18 @@ static void vkms_crtc_atomic_disable(struct drm_crtc *crtc, static void vkms_crtc_atomic_begin(struct drm_crtc *crtc, struct drm_atomic_state *state) { - struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc); + struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc); /* This lock is held across the atomic commit to block vblank timer * from scheduling vkms_composer_worker until the composer is updated */ - spin_lock_irq(&vkms_output->lock); + spin_lock_irq(&vkms_crtc->lock); } static void vkms_crtc_atomic_flush(struct drm_crtc *crtc, struct drm_atomic_state *state) { - struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc); + struct vkms_crtc *vkms_crtc = drm_crtc_to_vkms_crtc(crtc); if (crtc->state->event) { spin_lock(&crtc->dev->event_lock); @@ -262,9 +263,9 @@ static void vkms_crtc_atomic_flush(struct drm_crtc *crtc, crtc->state->event = NULL; } - vkms_output->composer_state = to_vkms_crtc_state(crtc->state); + vkms_crtc->composer_state = to_vkms_crtc_state(crtc->state); - spin_unlock_irq(&vkms_output->lock); + spin_unlock_irq(&vkms_crtc->lock); } static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = { @@ -275,27 +276,41 @@ static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = { .atomic_disable = vkms_crtc_atomic_disable, }; -int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, - struct drm_plane *primary, struct drm_plane *cursor) +struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev, + struct drm_plane *primary, + struct drm_plane *cursor) { - struct vkms_output *vkms_out = drm_crtc_to_vkms_output(crtc); + struct drm_device *dev = &vkmsdev->drm; + struct vkms_crtc *vkms_crtc; int ret; - ret = drmm_crtc_init_with_planes(dev, crtc, primary, cursor, + if (vkmsdev->output.num_crtcs >= VKMS_MAX_OUTPUT_OBJECTS) { + return ERR_PTR(-ENOMEM); + } + vkms_crtc = &vkmsdev->output.crtcs[vkmsdev->output.num_crtcs++]; + + ret = drmm_crtc_init_with_planes(dev, &vkms_crtc->base, primary, cursor, &vkms_crtc_funcs, NULL); if (ret) { DRM_ERROR("Failed to init CRTC\n"); - return ret; + goto out_error; } - drm_crtc_helper_add(crtc, &vkms_crtc_helper_funcs); + drm_crtc_helper_add(&vkms_crtc->base, &vkms_crtc_helper_funcs); - spin_lock_init(&vkms_out->lock); - spin_lock_init(&vkms_out->composer_lock); + spin_lock_init(&vkms_crtc->lock); + spin_lock_init(&vkms_crtc->composer_lock); - vkms_out->composer_workq = alloc_ordered_workqueue("vkms_composer", 0); - if (!vkms_out->composer_workq) - return -ENOMEM; + vkms_crtc->composer_workq = alloc_ordered_workqueue("vkms_composer", 0); + if (!vkms_crtc->composer_workq) { + ret = -ENOMEM; + goto out_error; + } + + return vkms_crtc; - return ret; +out_error: + memset(vkms_crtc, 0, sizeof(*vkms_crtc)); + vkmsdev->output.num_crtcs -= 1; + return ERR_PTR(ret); } diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index f07454fff046..aa2bee82b757 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -57,8 +57,8 @@ static void vkms_release(struct drm_device *dev) { struct vkms_device *vkms = drm_device_to_vkms_device(dev); - if (vkms->output.composer_workq) - destroy_workqueue(vkms->output.composer_workq); + for (int i = 0; i < vkms->output.num_crtcs; i++) + destroy_workqueue(vkms->output.crtcs[i].composer_workq); } static void vkms_atomic_commit_tail(struct drm_atomic_state *old_state) @@ -185,15 +185,15 @@ static int vkms_platform_probe(struct platform_device *pdev) goto out_release_group; } - ret = drm_vblank_init(&vkms_device->drm, 1); + ret = vkms_modeset_init(vkms_device); if (ret) { - DRM_ERROR("Failed to vblank\n"); + DRM_ERROR("Unable to initialize modesetting\n"); goto out_release_group; } - ret = vkms_modeset_init(vkms_device); + ret = drm_vblank_init(&vkms_device->drm, vkms_device->output.num_crtcs); if (ret) { - DRM_ERROR("Unable to initialize modesetting\n"); + DRM_ERROR("Failed to vblank\n"); goto out_release_group; } @@ -202,7 +202,7 @@ static int vkms_platform_probe(struct platform_device *pdev) ret = drm_dev_register(&vkms_device->drm, 0); if (ret) { - DRM_ERROR("Unable to register device\n"); + DRM_ERROR("Unable to register device with id %d\n", pdev->id); return ret; } diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index e87c8aea6fb3..4c3274838ec7 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -23,6 +23,9 @@ #define NUM_OVERLAY_PLANES 8 +#define VKMS_MAX_OUTPUT_OBJECTS 16 +#define VKMS_MAX_PLANES (3 * VKMS_MAX_OUTPUT_OBJECTS) + struct vkms_frame_info { struct drm_framebuffer *fb; struct drm_rect src, dst; @@ -65,6 +68,25 @@ struct vkms_plane { struct drm_plane base; }; +struct vkms_crtc { + struct drm_crtc base; + + struct drm_writeback_connector wb_connector; + struct hrtimer vblank_hrtimer; + ktime_t period_ns; + struct drm_pending_vblank_event *event; + /* ordered wq for composer_work */ + struct workqueue_struct *composer_workq; + /* protects concurrent access to composer */ + spinlock_t lock; + + /* protected by @lock */ + bool composer_enabled; + struct vkms_crtc_state *composer_state; + + spinlock_t composer_lock; +}; + /** * vkms_crtc_state - Driver specific CRTC state * @base: base CRTC state @@ -89,23 +111,14 @@ struct vkms_crtc_state { }; struct vkms_output { - struct drm_crtc crtc; - struct drm_encoder encoder; - struct drm_connector connector; - struct drm_writeback_connector wb_connector; - struct hrtimer vblank_hrtimer; - ktime_t period_ns; - struct drm_pending_vblank_event *event; - /* ordered wq for composer_work */ - struct workqueue_struct *composer_workq; - /* protects concurrent access to composer */ - spinlock_t lock; - - /* protected by @lock */ - bool composer_enabled; - struct vkms_crtc_state *composer_state; - - spinlock_t composer_lock; + int num_crtcs; + struct vkms_crtc crtcs[VKMS_MAX_OUTPUT_OBJECTS]; + int num_encoders; + struct drm_encoder encoders[VKMS_MAX_OUTPUT_OBJECTS]; + int num_connectors; + struct drm_connector connectors[VKMS_MAX_OUTPUT_OBJECTS]; + int num_planes; + struct vkms_plane planes[VKMS_MAX_PLANES]; }; struct vkms_device; @@ -123,12 +136,14 @@ struct vkms_device { struct vkms_config config; }; -#define drm_crtc_to_vkms_output(target) \ - container_of(target, struct vkms_output, crtc) +#define drm_crtc_to_vkms_crtc(crtc) container_of(crtc, struct vkms_crtc, base) #define drm_device_to_vkms_device(target) \ container_of(target, struct vkms_device, drm) +#define timer_to_vkms_crtc(timer) \ + container_of(timer, struct vkms_crtc, vblank_hrtimer) + #define to_vkms_crtc_state(target)\ container_of(target, struct vkms_crtc_state, base) @@ -136,13 +151,14 @@ struct vkms_device { container_of(target, struct vkms_plane_state, base.base) /* CRTC */ -int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, - struct drm_plane *primary, struct drm_plane *cursor); +struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev, + struct drm_plane *primary, + struct drm_plane *cursor); int vkms_output_init(struct vkms_device *vkmsdev, int index); struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, - enum drm_plane_type type, int index); + enum drm_plane_type type); /* CRC Support */ const char *const *vkms_get_crc_sources(struct drm_crtc *crtc, @@ -153,10 +169,11 @@ int vkms_verify_crc_source(struct drm_crtc *crtc, const char *source_name, /* Composer Support */ void vkms_composer_worker(struct work_struct *work); -void vkms_set_composer(struct vkms_output *out, bool enabled); +void vkms_set_composer(struct vkms_crtc *vkms_crtc, bool enabled); void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state *plane, int y); /* Writeback */ -int vkms_enable_writeback_connector(struct vkms_device *vkmsdev); +int vkms_enable_writeback_connector(struct vkms_device *vkmsdev, + struct vkms_crtc *vkms_crtc); #endif /* _VKMS_DRV_H_ */ diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index 963a64cf068b..6b4a77780d3c 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -1,9 +1,13 @@ // SPDX-License-Identifier: GPL-2.0+ -#include "vkms_drv.h" #include +#include #include +#include #include +#include + +#include "vkms_drv.h" static const struct drm_connector_funcs vkms_connector_funcs = { .fill_modes = drm_helper_probe_single_connector_modes, @@ -28,74 +32,116 @@ static int vkms_conn_get_modes(struct drm_connector *connector) } static const struct drm_connector_helper_funcs vkms_conn_helper_funcs = { - .get_modes = vkms_conn_get_modes, + .get_modes = vkms_conn_get_modes, }; -static int vkms_add_overlay_plane(struct vkms_device *vkmsdev, int index, - struct drm_crtc *crtc) +static struct drm_connector * +vkms_connector_init(struct vkms_device *vkms_device) { - struct vkms_plane *overlay; + struct drm_connector *connector; + int ret; - overlay = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_OVERLAY, index); - if (IS_ERR(overlay)) - return PTR_ERR(overlay); + if (vkms_device->output.num_connectors >= VKMS_MAX_OUTPUT_OBJECTS) + return ERR_PTR(-ENOMEM); - if (!overlay->base.possible_crtcs) - overlay->base.possible_crtcs = drm_crtc_mask(crtc); + connector = &vkms_device->output + .connectors[vkms_device->output.num_connectors++]; + ret = drm_connector_init(&vkms_device->drm, connector, + &vkms_connector_funcs, + DRM_MODE_CONNECTOR_VIRTUAL); + if (ret) { + memset(connector, 0, sizeof(*connector)); + vkms_device->output.num_connectors -= 1; + return ERR_PTR(ret); + } - return 0; + drm_connector_helper_add(connector, &vkms_conn_helper_funcs); + + return connector; +} + +static struct drm_encoder *vkms_encoder_init(struct vkms_device *vkms_device) +{ + struct drm_encoder *encoder; + int ret; + + if (vkms_device->output.num_encoders >= VKMS_MAX_OUTPUT_OBJECTS) + return ERR_PTR(-ENOMEM); + + encoder = &vkms_device->output + .encoders[vkms_device->output.num_encoders++]; + ret = drm_encoder_init(&vkms_device->drm, encoder, &vkms_encoder_funcs, + DRM_MODE_ENCODER_VIRTUAL, NULL); + if (ret) { + memset(encoder, 0, sizeof(*encoder)); + vkms_device->output.num_encoders -= 1; + return ERR_PTR(ret); + } + return 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_connector *connector = &output->connector; - struct drm_encoder *encoder = &output->encoder; - struct drm_crtc *crtc = &output->crtc; + struct drm_connector *connector; + struct drm_encoder *encoder; + struct vkms_crtc *vkms_crtc; struct vkms_plane *primary, *cursor = NULL; int ret; int writeback; unsigned int n; - primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY, index); + primary = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_PRIMARY); if (IS_ERR(primary)) return PTR_ERR(primary); if (vkmsdev->config.overlay) { for (n = 0; n < NUM_OVERLAY_PLANES; n++) { - ret = vkms_add_overlay_plane(vkmsdev, index, crtc); - if (ret) - return ret; + struct vkms_plane *overlay = vkms_plane_init( + vkmsdev, DRM_PLANE_TYPE_OVERLAY); + if (IS_ERR(overlay)) { + ret = PTR_ERR(overlay); + goto err_planes; + } } } if (vkmsdev->config.cursor) { - cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR, index); - if (IS_ERR(cursor)) - return PTR_ERR(cursor); + cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR); + if (IS_ERR(cursor)) { + ret = PTR_ERR(cursor); + goto err_planes; + } } - ret = vkms_crtc_init(dev, crtc, &primary->base, &cursor->base); - if (ret) - return ret; + vkms_crtc = vkms_crtc_init(vkmsdev, &primary->base, + cursor ? &cursor->base : NULL); + if (IS_ERR(vkms_crtc)) { + DRM_ERROR("Failed to init crtc\n"); + ret = PTR_ERR(vkms_crtc); + goto err_planes; + } - ret = drm_connector_init(dev, connector, &vkms_connector_funcs, - DRM_MODE_CONNECTOR_VIRTUAL); - if (ret) { + for (int i = 0; i < vkmsdev->output.num_planes; i++) { + vkmsdev->output.planes[i].base.possible_crtcs |= + drm_crtc_mask(&vkms_crtc->base); + } + + connector = vkms_connector_init(vkmsdev); + if (IS_ERR(connector)) { DRM_ERROR("Failed to init connector\n"); + ret = PTR_ERR(connector); goto err_connector; } - drm_connector_helper_add(connector, &vkms_conn_helper_funcs); - - ret = drm_encoder_init(dev, encoder, &vkms_encoder_funcs, - DRM_MODE_ENCODER_VIRTUAL, NULL); - if (ret) { + encoder = vkms_encoder_init(vkmsdev); + if (IS_ERR(encoder)) { DRM_ERROR("Failed to init encoder\n"); + ret = PTR_ERR(encoder); goto err_encoder; } - encoder->possible_crtcs = 1; + encoder->possible_crtcs |= drm_crtc_mask(&vkms_crtc->base); ret = drm_connector_attach_encoder(connector, encoder); if (ret) { @@ -104,7 +150,7 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index) } if (vkmsdev->config.writeback) { - writeback = vkms_enable_writeback_connector(vkmsdev); + writeback = vkms_enable_writeback_connector(vkmsdev, vkms_crtc); if (writeback) DRM_ERROR("Failed to init writeback connector\n"); } @@ -120,7 +166,14 @@ int vkms_output_init(struct vkms_device *vkmsdev, int index) drm_connector_cleanup(connector); err_connector: - drm_crtc_cleanup(crtc); + drm_crtc_cleanup(&vkms_crtc->base); + +err_planes: + for (int i = 0; i < output->num_planes; i++) { + drm_plane_cleanup(&output->planes[i].base); + } + + memset(output, 0, sizeof(*output)); return ret; } diff --git a/drivers/gpu/drm/vkms/vkms_plane.c b/drivers/gpu/drm/vkms/vkms_plane.c index e5c625ab8e3e..f69621822c1b 100644 --- a/drivers/gpu/drm/vkms/vkms_plane.c +++ b/drivers/gpu/drm/vkms/vkms_plane.c @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "vkms_drv.h" #include "vkms_formats.h" @@ -65,6 +67,20 @@ static void vkms_plane_destroy_state(struct drm_plane *plane, kfree(vkms_state); } +static void vkms_plane_destroy(struct drm_plane *plane) +{ + struct vkms_plane *vkms_plane = + container_of(plane, struct vkms_plane, base); + + if (plane->state) { + vkms_plane_destroy_state(plane, plane->state); + plane->state = NULL; + } + + drm_plane_cleanup(plane); + memset(vkms_plane, 0, sizeof(struct vkms_plane)); +} + static void vkms_plane_reset(struct drm_plane *plane) { struct vkms_plane_state *vkms_state; @@ -84,11 +100,12 @@ static void vkms_plane_reset(struct drm_plane *plane) } static const struct drm_plane_funcs vkms_plane_funcs = { - .update_plane = drm_atomic_helper_update_plane, - .disable_plane = drm_atomic_helper_disable_plane, - .reset = vkms_plane_reset, + .update_plane = drm_atomic_helper_update_plane, + .disable_plane = drm_atomic_helper_disable_plane, + .destroy = vkms_plane_destroy, + .reset = vkms_plane_reset, .atomic_duplicate_state = vkms_plane_duplicate_state, - .atomic_destroy_state = vkms_plane_destroy_state, + .atomic_destroy_state = vkms_plane_destroy_state, }; static void vkms_plane_atomic_update(struct drm_plane *plane, @@ -198,17 +215,22 @@ static const struct drm_plane_helper_funcs vkms_plane_helper_funcs = { }; struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, - enum drm_plane_type type, int index) + enum drm_plane_type type) { struct drm_device *dev = &vkmsdev->drm; + struct vkms_output *output = &vkmsdev->output; struct vkms_plane *plane; + int ret; - plane = drmm_universal_plane_alloc(dev, struct vkms_plane, base, 1 << index, - &vkms_plane_funcs, - vkms_formats, ARRAY_SIZE(vkms_formats), - NULL, type, NULL); - if (IS_ERR(plane)) - return plane; + if (output->num_planes >= VKMS_MAX_PLANES) + return ERR_PTR(-ENOMEM); + + plane = &output->planes[output->num_planes++]; + ret = drm_universal_plane_init(dev, &plane->base, 0, &vkms_plane_funcs, + vkms_formats, ARRAY_SIZE(vkms_formats), + NULL, type, NULL); + if (ret) + return ERR_PTR(ret); drm_plane_helper_add(&plane->base, &vkms_plane_helper_funcs); diff --git a/drivers/gpu/drm/vkms/vkms_writeback.c b/drivers/gpu/drm/vkms/vkms_writeback.c index 84a51cd281b9..b90bcbd0a0e0 100644 --- a/drivers/gpu/drm/vkms/vkms_writeback.c +++ b/drivers/gpu/drm/vkms/vkms_writeback.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0+ #include +#include #include #include @@ -101,7 +102,8 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector, struct drm_writeback_job *job) { struct vkms_writeback_job *vkmsjob = job->priv; - struct vkms_device *vkmsdev; + struct vkms_crtc *vkms_crtc = + container_of(connector, struct vkms_crtc, wb_connector); if (!job->fb) return; @@ -110,8 +112,7 @@ static void vkms_wb_cleanup_job(struct drm_writeback_connector *connector, drm_framebuffer_put(vkmsjob->wb_frame_info.fb); - vkmsdev = drm_device_to_vkms_device(job->fb->dev); - vkms_set_composer(&vkmsdev->output, false); + vkms_set_composer(vkms_crtc, false); kfree(vkmsjob); } @@ -120,11 +121,11 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn, { struct drm_connector_state *connector_state = drm_atomic_get_new_connector_state(state, conn); - struct vkms_device *vkmsdev = drm_device_to_vkms_device(conn->dev); - struct vkms_output *output = &vkmsdev->output; - struct drm_writeback_connector *wb_conn = &output->wb_connector; + struct vkms_crtc *vkms_crtc = + drm_crtc_to_vkms_crtc(connector_state->crtc); + struct drm_writeback_connector *wb_conn = &vkms_crtc->wb_connector; struct drm_connector_state *conn_state = wb_conn->base.state; - struct vkms_crtc_state *crtc_state = output->composer_state; + struct vkms_crtc_state *crtc_state = vkms_crtc->composer_state; struct drm_framebuffer *fb = connector_state->writeback_job->fb; u16 crtc_height = crtc_state->base.crtc->mode.vdisplay; u16 crtc_width = crtc_state->base.crtc->mode.hdisplay; @@ -135,18 +136,18 @@ static void vkms_wb_atomic_commit(struct drm_connector *conn, if (!conn_state) return; - vkms_set_composer(&vkmsdev->output, true); + vkms_set_composer(vkms_crtc, true); active_wb = conn_state->writeback_job->priv; wb_frame_info = &active_wb->wb_frame_info; - spin_lock_irq(&output->composer_lock); + spin_lock_irq(&vkms_crtc->composer_lock); crtc_state->active_writeback = active_wb; wb_frame_info->offset = fb->offsets[0]; wb_frame_info->pitch = fb->pitches[0]; wb_frame_info->cpp = fb->format->cpp[0]; crtc_state->wb_pending = true; - spin_unlock_irq(&output->composer_lock); + spin_unlock_irq(&vkms_crtc->composer_lock); drm_writeback_queue_job(wb_conn, connector_state); active_wb->wb_write = get_line_to_frame_function(wb_format); drm_rect_init(&wb_frame_info->src, 0, 0, crtc_width, crtc_height); @@ -160,9 +161,10 @@ static const struct drm_connector_helper_funcs vkms_wb_conn_helper_funcs = { .atomic_commit = vkms_wb_atomic_commit, }; -int vkms_enable_writeback_connector(struct vkms_device *vkmsdev) +int vkms_enable_writeback_connector(struct vkms_device *vkmsdev, + struct vkms_crtc *vkms_crtc) { - struct drm_writeback_connector *wb = &vkmsdev->output.wb_connector; + struct drm_writeback_connector *wb = &vkms_crtc->wb_connector; drm_connector_helper_add(&wb->base, &vkms_wb_conn_helper_funcs); From patchwork Fri Jun 23 22:23:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Shargo X-Patchwork-Id: 13291429 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 7528DC001DD for ; Fri, 23 Jun 2023 22:25:42 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 39B8F10E6DC; Fri, 23 Jun 2023 22:25:40 +0000 (UTC) Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4012710E6D7 for ; Fri, 23 Jun 2023 22:25:35 +0000 (UTC) Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-3f8fcaa31c7so15198685e9.3 for ; Fri, 23 Jun 2023 15:25:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687559133; x=1690151133; 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=mKukKTNolk7o3JwLovvGiZSWB7MAEKhSelWOQgYadOg=; b=nMpjrKdcnJ8XhmRMfB91CKOQkjOP9VFD/yB0lnj8RKVvNm+yU85lRkWGQtqRoix7+3 47pIxJVbS1xpdiMdCdKV6hv+q7WMVtM2+ElPY7CbjHDjzOLt22K1p5+ndYZpo0MgD2Bt BGRG2sg6gUwO5FJDdghj8JwU5V3CjwMse3+Vg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687559133; x=1690151133; 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=mKukKTNolk7o3JwLovvGiZSWB7MAEKhSelWOQgYadOg=; b=HQs6VQUvqccGVjw9ckH8GXUjMkivydPf8MOOif0AUGQJF8ZhY8uKxH4eMIMHHSyApK xwJG/snQp8oYHrSyW7CK9Rdi9ha1qjn3JMYNKcsRsxf7EctQ80D7tYCgDqiwETMZDAz3 yrL0LwJ6gM94eZrY+46yeUHSU6OkUyD6+2kbIi25Y+swz3jSAii2/edAG5HDwFTkgGlU liBKj6ukSUVF4lH6MV6NAsSrczpXN7zmifj5wCbJpwWDuB5UbkYzrM5Sq3/GrzM6vaQ8 VcMxxKTaZ8Hs6hy8qaXyIzgxx1PYy9nJbcRE8l7yzOUKmMF+t92Vi2DTu9aTjcqb698Y jg5w== X-Gm-Message-State: AC+VfDxmWhMgtuGp645R9zQmcTRObx/Dh3LyOAaWuuUgp0SjFzzAAtXl pNrL/9m92FvdXihLhLUe85DezA== X-Google-Smtp-Source: ACHHUZ7rsXQXJQmsIskpsoN95A1IWOFJKMU7V7NSVLFldsmXoPhlG5DDcXS3z9jdHUMyzCYrVoS/KQ== X-Received: by 2002:a5d:58d1:0:b0:30f:bcfd:c690 with SMTP id o17-20020a5d58d1000000b0030fbcfdc690mr23643997wrf.38.1687559133379; Fri, 23 Jun 2023 15:25:33 -0700 (PDT) Received: from big-boopo.mynetworksettings.com (pool-108-46-233-209.nycmny.fios.verizon.net. [108.46.233.209]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4106000000b0030c2e3c7fb3sm453223wrp.101.2023.06.23.15.25.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 15:25:33 -0700 (PDT) From: Jim Shargo To: mairacanal@riseup.net, Daniel Vetter , David Airlie , Haneen Mohammed , Jonathan Corbet , Maarten Lankhorst , Maxime Ripard , Melissa Wen , Rodrigo Siqueira , Thomas Zimmermann Subject: [PATCH v2 3/6] drm/vkms: Provide platform data when creating VKMS devices Date: Fri, 23 Jun 2023 18:23:45 -0400 Message-ID: <20230623222353.97283-4-jshargo@chromium.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230623222353.97283-1-jshargo@chromium.org> References: <20230623222353.97283-1-jshargo@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: Jim Shargo , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This is a small refactor to make ConfigFS support easier. This should be a no-op refactor. Signed-off-by: Jim Shargo --- drivers/gpu/drm/vkms/vkms_drv.c | 13 +++++++++++-- drivers/gpu/drm/vkms/vkms_drv.h | 9 ++++++--- drivers/gpu/drm/vkms/vkms_output.c | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index aa2bee82b757..d43121addf66 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -152,12 +152,14 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) dev->mode_config.preferred_depth = 0; dev->mode_config.helper_private = &vkms_mode_config_helpers; - return vkms_output_init(vkmsdev, 0); + return vkmsdev->is_default ? vkms_output_init_default(vkmsdev) : + -ENOSYS; } static int vkms_platform_probe(struct platform_device *pdev) { int ret; + struct vkms_device_setup *vkms_device_setup = pdev->dev.platform_data; struct vkms_device *vkms_device; void *grp; @@ -177,6 +179,7 @@ static int vkms_platform_probe(struct platform_device *pdev) vkms_device->config.cursor = enable_cursor; vkms_device->config.writeback = enable_writeback; vkms_device->config.overlay = enable_overlay; + vkms_device->is_default = vkms_device_setup->is_default; ret = dma_coerce_mask_and_coherent(vkms_device->drm.dev, DMA_BIT_MASK(64)); @@ -240,6 +243,9 @@ static int __init vkms_init(void) { int ret; struct platform_device *pdev; + struct vkms_device_setup vkms_device_setup = { + .is_default = true, + }; ret = platform_driver_register(&vkms_platform_driver); if (ret) { @@ -247,8 +253,11 @@ static int __init vkms_init(void) return ret; } - pdev = platform_device_register_simple(DRIVER_NAME, -1, NULL, 0); + pdev = platform_device_register_data(NULL, DRIVER_NAME, 0, + &vkms_device_setup, + sizeof(vkms_device_setup)); if (IS_ERR(pdev)) { + DRM_ERROR("Unable to register default vkms device\n"); platform_driver_unregister(&vkms_platform_driver); return PTR_ERR(pdev); } diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 4c3274838ec7..84b35aa1dc5a 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -121,17 +121,20 @@ struct vkms_output { struct vkms_plane planes[VKMS_MAX_PLANES]; }; -struct vkms_device; - struct vkms_config { bool writeback; bool cursor; bool overlay; }; +struct vkms_device_setup { + bool is_default; +}; + struct vkms_device { struct drm_device drm; struct platform_device *platform; + bool is_default; struct vkms_output output; struct vkms_config config; }; @@ -155,7 +158,7 @@ struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev, struct drm_plane *primary, struct drm_plane *cursor); -int vkms_output_init(struct vkms_device *vkmsdev, int index); +int vkms_output_init_default(struct vkms_device *vkmsdev); struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, enum drm_plane_type type); diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index 6b4a77780d3c..3b5e272a8b33 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -80,7 +80,7 @@ static struct drm_encoder *vkms_encoder_init(struct vkms_device *vkms_device) return encoder; } -int vkms_output_init(struct vkms_device *vkmsdev, int index) +int vkms_output_init_default(struct vkms_device *vkmsdev) { struct vkms_output *output = &vkmsdev->output; struct drm_device *dev = &vkmsdev->drm; From patchwork Fri Jun 23 22:23:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Shargo X-Patchwork-Id: 13291430 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 523E6EB64D7 for ; Fri, 23 Jun 2023 22:25:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3463310E6D7; Fri, 23 Jun 2023 22:25:40 +0000 (UTC) Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by gabe.freedesktop.org (Postfix) with ESMTPS id BF4D010E6D1 for ; Fri, 23 Jun 2023 22:25:38 +0000 (UTC) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-3f918922954so12610305e9.2 for ; Fri, 23 Jun 2023 15:25:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687559137; x=1690151137; 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=rqUbtFMW/jmB4bWtWPy/9dwRPlA/NBdqkzPUlPdRG/g=; b=iH+eXC4Dh/eDc9yKlipYTpCJ5wrBNd8I0lPIMoi1wTVxa9+eQ1tP2WvuieYEIy535Z 1yDY0DLgQR3Zlz+XYUo59KPlkwmstiyB2q/C16YyGntJNtgv9WyH2cauUcxrCjanibj9 SeLQkQn0kige973/4QNmLPZP6QgZg3ZVYAyYc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687559137; x=1690151137; 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=rqUbtFMW/jmB4bWtWPy/9dwRPlA/NBdqkzPUlPdRG/g=; b=EraAaPWPv2a1WYSXwvDHqTdXKFQOZxS7gTDcwNnuwkkl50QF7paVYGdD2yxA4Wew+K iPhnX8cDaCIv4ZcfIJtMcykZbPT9j63JW8GJOfz73ucclJsTK2xFoa/r6a47bCIzVY7H 62aA/y8BQCsxiMR69gL+cdQZYy9hVRqCVhC1QjD0NCx0EIRp80/0ye6OQutwErNmTq88 i0XXX/OG+hArrJdfAz/+v0tPaqt149uJuFssjjfIAucgCjjoo/lpCb7GhS/9x3Q7Rgp7 +2p3B6PXIpgGWX8JWHrt513U0uRjORurCPZnYts3g4MxuLD4ojfpFubHQQ6NyBMNmCE3 Yn2w== X-Gm-Message-State: AC+VfDw6ShCNmVDnkZioAVDCjTVNGc3rlWiUu2syr0Il1bPOLurqvmwy s7F98DscDuZ9H25tOI2hwj3k3w== X-Google-Smtp-Source: ACHHUZ4q0AlcrgTGeQKGbuT50c0giLfjwZK3Y0uahcuSki4RwQBWGQLKxgAPmrOgAclhfw3z2KZRnA== X-Received: by 2002:adf:cd87:0:b0:313:e1c0:3f5 with SMTP id q7-20020adfcd87000000b00313e1c003f5mr59344wrj.36.1687559136729; Fri, 23 Jun 2023 15:25:36 -0700 (PDT) Received: from big-boopo.mynetworksettings.com (pool-108-46-233-209.nycmny.fios.verizon.net. [108.46.233.209]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4106000000b0030c2e3c7fb3sm453223wrp.101.2023.06.23.15.25.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 15:25:36 -0700 (PDT) From: Jim Shargo To: mairacanal@riseup.net, Daniel Vetter , David Airlie , Haneen Mohammed , Jonathan Corbet , Maarten Lankhorst , Maxime Ripard , Melissa Wen , Rodrigo Siqueira , Thomas Zimmermann Subject: [PATCH v2 4/6] drm/vkms: Add ConfigFS scaffolding to VKMS Date: Fri, 23 Jun 2023 18:23:46 -0400 Message-ID: <20230623222353.97283-5-jshargo@chromium.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230623222353.97283-1-jshargo@chromium.org> References: <20230623222353.97283-1-jshargo@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: Jim Shargo , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This change adds the basic scaffolding for ConfigFS, including setting up the default directories. It does not allow for the registration of configfs-backed devices, which is complex and provided in a follow-up commit. This CL includes docs about using ConfigFS with VKMS, but I'll summarize in brief here as well (assuming ConfigFS is mounted at /config/): To create a new device, you can do so via `mkdir /config/vkms/my-device`. This will create a number of directories and files automatically: /config `-- vkms `-- my-device |-- connectors |-- crtcs |-- encoders |-- planes `-- enabled You can then configure objects by mkdir'ing in each of the directories. When you're satisfied, you can `echo 1 > /config/vkms/my-device/enabled`. This will create a new device according to your configuration. For now, this will fail, but the next change will add support for it. Signed-off-by: Jim Shargo --- Documentation/gpu/vkms.rst | 17 +- drivers/gpu/drm/Kconfig | 1 + drivers/gpu/drm/vkms/Makefile | 1 + drivers/gpu/drm/vkms/vkms_configfs.c | 646 +++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_drv.c | 52 ++- drivers/gpu/drm/vkms/vkms_drv.h | 92 +++- drivers/gpu/drm/vkms/vkms_output.c | 5 + 7 files changed, 799 insertions(+), 15 deletions(-) create mode 100644 drivers/gpu/drm/vkms/vkms_configfs.c diff --git a/Documentation/gpu/vkms.rst b/Documentation/gpu/vkms.rst index ba04ac7c2167..2c342ef0fb7b 100644 --- a/Documentation/gpu/vkms.rst +++ b/Documentation/gpu/vkms.rst @@ -51,6 +51,12 @@ To disable the driver, use :: sudo modprobe -r vkms +Configuration With ConfigFS +=========================== + +.. kernel-doc:: drivers/gpu/drm/vkms/vkms_configfs.c + :doc: ConfigFS Support for VKMS + Testing With IGT ================ @@ -135,22 +141,15 @@ project. Runtime Configuration --------------------- -We want to be able to reconfigure vkms instance without having to reload the -module. Use/Test-cases: +We want to 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 of compositors). -- Configure planes/crtcs/connectors (we'd need some code to have more than 1 of - them first). - - Change output configuration: Plug/unplug screens, change EDID, allow changing the refresh rate. -The currently proposed solution is to expose vkms configuration through -configfs. All existing module options should be supported through configfs -too. - Writeback support ----------------- diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index afb3b2f5f425..71eb913b378f 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -262,6 +262,7 @@ config DRM_VKMS depends on DRM && MMU 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 1b28a6a32948..6b83907ad554 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 000000000000..544024735d19 --- /dev/null +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -0,0 +1,646 @@ +// SPDX-License-Identifier: GPL-2.0+ + +#include +#include +#include + +#include +#include + +#include "vkms_drv.h" + +/** + * DOC: ConfigFS Support for VKMS + * + * VKMS is instrumented with support for configuration via :doc:`ConfigFS + * <../filesystems/configfs>`. + * + * With VKMS installed, you can mount ConfigFS at ``/config/`` like so:: + * + * mkdir -p /config/ + * sudo mount -t configfs none /config + * + * This allows you to configure multiple virtual devices in addition to an + * immutable "default" device created by the driver at initialization time. Note + * that the default device is immutable because we cannot pre-populate ConfigFS + * directories with normal files. + * + * To set up a new device, create a new directory under the VKMS configfs + * directory:: + * + * mkdir /config/vkms/test + * + * With your device created you'll find an new directory ready to be + * configured:: + * + * /config + * `-- vkms + * |-- default + * | `-- enabled + * `-- test + * |-- connectors + * |-- crtcs + * |-- encoders + * |-- planes + * `-- enabled + * + * Each directory you add within the connectors, crtcs, encoders, and planes + * directories will let you configure a new object of that type. Adding new + * objects will automatically create a set of default files and folders you can + * use to configure that object. + * + * For instance, we can set up a two-output device like so:: + * + * DRM_PLANE_TYPE_PRIMARY=1 + * DRM_PLANE_TYPE_CURSOR=2 + * DRM_PLANE_TYPE_OVERLAY=0 + * + * mkdir /config/vkms/test/planes/primary + * echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/primary/type + * + * mkdir /config/vkms/test/planes/other_primary + * echo $DRM_PLANE_TYPE_PRIMARY > /config/vkms/test/planes/other_primary/type + * + * mkdir /config/vkms/test/planes/cursor + * echo $DRM_PLANE_TYPE_CURSOR > /config/vkms/test/planes/cursor/type + * + * mkdir /config/vkms/test/planes/overlay + * echo $DRM_PLANE_TYPE_OVERLAY > /config/vkms/test/planes/overlay/type + * + * mkdir /config/vkms/test/crtcs/crtc + * mkdir /config/vkms/test/crtcs/crtc_other + * mkdir /config/vkms/test/encoders/encoder + * mkdir /config/vkms/test/connectors/connector + * + * You can see that specific attributes, such as ``...//type``, can be + * configured by writing into them. Associating objects together can be done via + * symlinks:: + * + * ln -s /config/vkms/test/encoders/encoder /config/vkms/test/connectors/connector/possible_encoders + * + * ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/encoders/encoder/possible_crtcs/ + * ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/primary/possible_crtcs/ + * ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/cursor/possible_crtcs/ + * ln -s /config/vkms/test/crtcs/crtc /config/vkms/test/planes/overlay/possible_crtcs/ + * + * ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/overlay/possible_crtcs/ + * ln -s /config/vkms/test/crtcs/crtc_other /config/vkms/test/planes/other_primary/possible_crtcs/ + * + * Finally, to enable your configured device, just write 1 to the ``enabled`` + * file:: + * + * echo 1 > /config/vkms/test/enabled + * + * When you're done with the virtual device, you can clean up the device like + * so:: + * + * echo 0 > /config/vkms/test/enabled + * + * rm /config/vkms/test/connectors/connector/possible_encoders/encoder + * rm /config/vkms/test/encoders/encoder/possible_crtcs/crtc + * rm /config/vkms/test/planes/primary/possible_crtcs/crtc + * rm /config/vkms/test/planes/cursor/possible_crtcs/crtc + * rm /config/vkms/test/planes/overlay/possible_crtcs/crtc + * rm /config/vkms/test/planes/overlay/possible_crtcs/crtc_other + * rm /config/vkms/test/planes/other_primary/possible_crtcs/crtc_other + * + * rmdir /config/vkms/test/planes/primary + * rmdir /config/vkms/test/planes/other_primary + * rmdir /config/vkms/test/planes/cursor + * rmdir /config/vkms/test/planes/overlay + * rmdir /config/vkms/test/crtcs/crtc + * rmdir /config/vkms/test/crtcs/crtc_other + * rmdir /config/vkms/test/encoders/encoder + * rmdir /config/vkms/test/connectors/connector + * + * rmdir /config/vkms/test + */ + +/* + * Common helpers (i.e. common sub-groups) + */ + +/* Possible CRTCs, e.g. /config/vkms/device//possible_crtcs/ */ + +static struct config_item_type crtc_type; + +static int possible_crtcs_allow_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_config_links *links = item_to_config_links(src); + struct vkms_config_crtc *crtc; + + if (target->ci_type != &crtc_type) { + DRM_ERROR("Unable to link non-CRTCs.\n"); + return -EINVAL; + } + + crtc = item_to_config_crtc(target); + + if (links->linked_object_bitmap & BIT(crtc->crtc_config_idx)) { + DRM_ERROR( + "Tried to add two symlinks to the same CRTC from the same object\n"); + return -EINVAL; + } + + links->linked_object_bitmap |= BIT(crtc->crtc_config_idx); + + return 0; +} + +static void possible_crtcs_drop_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_config_links *links = item_to_config_links(src); + struct vkms_config_crtc *crtc = item_to_config_crtc(target); + + links->linked_object_bitmap &= ~BIT(crtc->crtc_config_idx); +} + +static struct configfs_item_operations possible_crtcs_item_ops = { + .allow_link = &possible_crtcs_allow_link, + .drop_link = &possible_crtcs_drop_link, +}; + +static struct config_item_type possible_crtcs_group_type = { + .ct_item_ops = &possible_crtcs_item_ops, + .ct_owner = THIS_MODULE, +}; + +static void add_possible_crtcs(struct config_group *parent, + struct config_group *possible_crtcs) +{ + config_group_init_type_name(possible_crtcs, "possible_crtcs", + &possible_crtcs_group_type); + configfs_add_default_group(possible_crtcs, parent); +} + +/* Possible encoders, e.g. /config/vkms/device/connector/possible_encoders/ */ + +static struct config_item_type encoder_type; + +static int possible_encoders_allow_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_config_links *links = item_to_config_links(src); + struct vkms_config_encoder *encoder; + + if (target->ci_type != &encoder_type) { + DRM_ERROR("Unable to link non-encoders.\n"); + return -EINVAL; + } + + encoder = item_to_config_encoder(target); + + if (links->linked_object_bitmap & BIT(encoder->encoder_config_idx)) { + DRM_ERROR( + "Tried to add two symlinks to the same encoder from the same object\n"); + return -EINVAL; + } + + links->linked_object_bitmap |= BIT(encoder->encoder_config_idx); + + return 0; +} + +static void possible_encoders_drop_link(struct config_item *src, + struct config_item *target) +{ + struct vkms_config_links *links = item_to_config_links(src); + struct vkms_config_encoder *encoder = item_to_config_encoder(target); + + links->linked_object_bitmap &= ~BIT(encoder->encoder_config_idx); +} + +static struct configfs_item_operations possible_encoders_item_ops = { + .allow_link = &possible_encoders_allow_link, + .drop_link = &possible_encoders_drop_link, +}; + +static struct config_item_type possible_encoders_group_type = { + .ct_item_ops = &possible_encoders_item_ops, + .ct_owner = THIS_MODULE, +}; + +static void add_possible_encoders(struct config_group *parent, + struct config_group *possible_encoders) +{ + config_group_init_type_name(possible_encoders, "possible_encoders", + &possible_encoders_group_type); + configfs_add_default_group(possible_encoders, parent); +} + +/* + * Individual objects (connectors, crtcs, encoders, planes): + */ + +/* Connector item, e.g. /config/vkms/device/connectors/ID */ + +static struct config_item_type connector_type = { + .ct_owner = THIS_MODULE, +}; + +/* Crtc item, e.g. /config/vkms/device/crtcs/ID */ + +static struct config_item_type crtc_type = { + .ct_owner = THIS_MODULE, +}; + +/* Encoder item, e.g. /config/vkms/device/encoder/ID */ + +static struct config_item_type encoder_type = { + .ct_owner = THIS_MODULE, +}; + +/* Plane item, e.g. /config/vkms/device/planes/ID */ + +static ssize_t plane_type_show(struct config_item *item, char *buf) +{ + struct vkms_config_plane *plane = item_to_config_plane(item); + struct vkms_configfs *configfs = plane_item_to_configfs(item); + enum drm_plane_type plane_type; + + mutex_lock(&configfs->lock); + plane_type = plane->type; + mutex_unlock(&configfs->lock); + + return sprintf(buf, "%u", plane_type); +} + +static ssize_t plane_type_store(struct config_item *item, const char *buf, + size_t len) +{ + struct vkms_config_plane *plane = item_to_config_plane(item); + struct vkms_configfs *configfs = plane_item_to_configfs(item); + int val, ret; + + ret = kstrtouint(buf, 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(&configfs->lock); + plane->type = val; + mutex_unlock(&configfs->lock); + + return len; +} + +CONFIGFS_ATTR(plane_, type); + +static struct configfs_attribute *plane_attrs[] = { + &plane_attr_type, + NULL, +}; + +static struct config_item_type plane_type = { + .ct_attrs = plane_attrs, + .ct_owner = THIS_MODULE, +}; + +/* + * Directory groups, e.g. /config/vkms/device/{planes, crtcs, ...} + */ + +/* Connectors group: /config/vkms/device/connectors/ */ + +static struct config_group *connectors_group_make(struct config_group *group, + const char *name) +{ + struct vkms_config_connector *connector = + kzalloc(sizeof(*connector), GFP_KERNEL); + if (!connector) + return ERR_PTR(-ENOMEM); + + config_group_init_type_name(&connector->config_group, name, + &connector_type); + add_possible_encoders(&connector->config_group, + &connector->possible_encoders.group); + + return &connector->config_group; +} + +static void connectors_group_drop(struct config_group *group, + struct config_item *item) +{ + struct vkms_config_connector *connector = + item_to_config_connector(item); + kfree(connector); +} + +static struct configfs_group_operations connectors_group_ops = { + .make_group = &connectors_group_make, + .drop_item = &connectors_group_drop, +}; + +static struct config_item_type connectors_group_type = { + .ct_group_ops = &connectors_group_ops, + .ct_owner = THIS_MODULE, +}; + +/* CRTCs group: /config/vkms/device/crtcs/ */ + +static struct config_group *crtcs_group_make(struct config_group *group, + const char *name) +{ + struct vkms_configfs *configfs = + container_of(group, struct vkms_configfs, crtcs_group); + unsigned long next_idx; + struct vkms_config_crtc *crtc; + + mutex_lock(&configfs->lock); + + next_idx = find_first_zero_bit(&configfs->allocated_crtcs, + VKMS_MAX_OUTPUT_OBJECTS); + + if (next_idx == VKMS_MAX_OUTPUT_OBJECTS) { + DRM_ERROR("Unable to allocate another CRTC.\n"); + mutex_unlock(&configfs->lock); + return ERR_PTR(-ENOMEM); + } + + crtc = kzalloc(sizeof(*crtc), GFP_KERNEL); + if (!crtc) { + DRM_ERROR("Unable to allocate CRTC.\n"); + mutex_unlock(&configfs->lock); + return ERR_PTR(-ENOMEM); + } + + config_group_init_type_name(&crtc->config_group, name, &crtc_type); + crtc->crtc_config_idx = next_idx; + + set_bit(next_idx, &configfs->allocated_crtcs); + + mutex_unlock(&configfs->lock); + + return &crtc->config_group; +} + +static void crtcs_group_drop(struct config_group *group, + struct config_item *item) +{ + struct vkms_config_crtc *crtc = item_to_config_crtc(item); + kfree(crtc); +} + +static struct configfs_group_operations crtcs_group_ops = { + .make_group = &crtcs_group_make, + .drop_item = &crtcs_group_drop, +}; + +static struct config_item_type crtcs_group_type = { + .ct_group_ops = &crtcs_group_ops, + .ct_owner = THIS_MODULE, +}; + +/* Encoders group: /config/vkms/device/encoders/ */ + +static struct config_group *encoders_group_make(struct config_group *group, + const char *name) +{ + struct vkms_configfs *configfs = + container_of(group, struct vkms_configfs, encoders_group); + unsigned long next_idx; + struct vkms_config_encoder *encoder; + + mutex_lock(&configfs->lock); + + next_idx = find_first_zero_bit(&configfs->allocated_encoders, + VKMS_MAX_OUTPUT_OBJECTS); + + if (next_idx == VKMS_MAX_OUTPUT_OBJECTS) { + DRM_ERROR("Unable to allocate another encoder.\n"); + mutex_unlock(&configfs->lock); + return ERR_PTR(-ENOMEM); + } + + encoder = kzalloc(sizeof(*encoder), GFP_KERNEL); + if (!encoder) { + DRM_ERROR("Unable to allocate encoder.\n"); + mutex_unlock(&configfs->lock); + return ERR_PTR(-ENOMEM); + } + + config_group_init_type_name(&encoder->config_group, name, + &encoder_type); + add_possible_crtcs(&encoder->config_group, + &encoder->possible_crtcs.group); + encoder->encoder_config_idx = next_idx; + set_bit(next_idx, &configfs->allocated_encoders); + + mutex_unlock(&configfs->lock); + + return &encoder->config_group; +} + +static void encoders_group_drop(struct config_group *group, + struct config_item *item) +{ + struct vkms_config_encoder *encoder = item_to_config_encoder(item); + kfree(encoder); +} + +static struct configfs_group_operations encoders_group_ops = { + .make_group = &encoders_group_make, + .drop_item = &encoders_group_drop, +}; + +static struct config_item_type encoders_group_type = { + .ct_group_ops = &encoders_group_ops, + .ct_owner = THIS_MODULE, +}; + +/* Planes group: /config/vkms/device/planes/ */ + +static struct config_group *make_plane_group(struct config_group *group, + const char *name) +{ + struct vkms_config_plane *plane = kzalloc(sizeof(*plane), GFP_KERNEL); + if (!plane) + return ERR_PTR(-ENOMEM); + + config_group_init_type_name(&plane->config_group, name, &plane_type); + add_possible_crtcs(&plane->config_group, &plane->possible_crtcs.group); + + return &plane->config_group; +} + +static void drop_plane_group(struct config_group *group, + struct config_item *item) +{ + struct vkms_config_plane *plane = item_to_config_plane(item); + kfree(plane); +} + +static struct configfs_group_operations plane_group_ops = { + .make_group = &make_plane_group, + .drop_item = &drop_plane_group, +}; + +static struct config_item_type planes_group_type = { + .ct_group_ops = &plane_group_ops, + .ct_owner = THIS_MODULE, +}; + +/* Root directory group, e.g. /config/vkms/device */ + +static ssize_t device_enabled_show(struct config_item *item, char *buf) +{ + struct vkms_configfs *configfs = item_to_configfs(item); + bool is_enabled; + + mutex_lock(&configfs->lock); + is_enabled = configfs->vkms_device != NULL; + mutex_unlock(&configfs->lock); + + return sprintf(buf, "%d", is_enabled); +} + +static ssize_t device_enabled_store(struct config_item *item, const char *buf, + size_t len) +{ + struct vkms_configfs *configfs = item_to_configfs(item); + struct vkms_device *device; + int value, ret; + + ret = kstrtoint(buf, 0, &value); + if (ret) + return ret; + + if (value != 1) + return -EINVAL; + + mutex_lock(&configfs->lock); + + if (configfs->vkms_device) { + mutex_unlock(&configfs->lock); + return len; + } + + device = vkms_add_device(configfs); + mutex_unlock(&configfs->lock); + + if (IS_ERR(device)) + return -PTR_ERR(device); + + return len; +} + +CONFIGFS_ATTR(device_, enabled); + +static ssize_t device_id_show(struct config_item *item, char *buf) +{ + struct vkms_configfs *configfs = item_to_configfs(item); + int id = -1; + + mutex_lock(&configfs->lock); + if (configfs->vkms_device) { + id = configfs->vkms_device->platform->id; + } + mutex_unlock(&configfs->lock); + + return sprintf(buf, "%d", id); +} + +CONFIGFS_ATTR_RO(device_, id); + +static struct configfs_attribute *device_group_attrs[] = { + &device_attr_id, + &device_attr_enabled, + NULL, +}; + +static struct config_item_type device_group_type = { + .ct_attrs = device_group_attrs, + .ct_owner = THIS_MODULE, +}; + +static void vkms_configfs_setup_default_groups(struct vkms_configfs *configfs, + const char *name) +{ + config_group_init_type_name(&configfs->device_group, name, + &device_group_type); + + config_group_init_type_name(&configfs->connectors_group, "connectors", + &connectors_group_type); + configfs_add_default_group(&configfs->connectors_group, + &configfs->device_group); + + config_group_init_type_name(&configfs->crtcs_group, "crtcs", + &crtcs_group_type); + configfs_add_default_group(&configfs->crtcs_group, + &configfs->device_group); + + config_group_init_type_name(&configfs->encoders_group, "encoders", + &encoders_group_type); + configfs_add_default_group(&configfs->encoders_group, + &configfs->device_group); + + config_group_init_type_name(&configfs->planes_group, "planes", + &planes_group_type); + configfs_add_default_group(&configfs->planes_group, + &configfs->device_group); +} + +/* Root directory group and subsystem, e.g. /config/vkms/ */ + +static struct config_group *make_root_group(struct config_group *group, + const char *name) +{ + struct vkms_configfs *configfs = kzalloc(sizeof(*configfs), GFP_KERNEL); + + if (!configfs) + return ERR_PTR(-ENOMEM); + + vkms_configfs_setup_default_groups(configfs, name); + mutex_init(&configfs->lock); + + return &configfs->device_group; +} + +static void drop_root_group(struct config_group *group, + struct config_item *item) +{ + struct vkms_configfs *configfs = item_to_configfs(item); + + mutex_lock(&configfs->lock); + if (configfs->vkms_device) + vkms_remove_device(configfs->vkms_device); + mutex_unlock(&configfs->lock); + + kfree(configfs); +} + +static struct configfs_group_operations root_group_ops = { + .make_group = &make_root_group, + .drop_item = &drop_root_group, +}; + +static struct config_item_type vkms_type = { + .ct_group_ops = &root_group_ops, + .ct_owner = THIS_MODULE, +}; + +static struct configfs_subsystem vkms_subsys = { + .su_group = { + .cg_item = { + .ci_name = "vkms", + .ci_type = &vkms_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_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index d43121addf66..1b5b7143792f 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -9,7 +9,10 @@ * the GPU in DRM API tests. */ +#include #include +#include +#include #include #include #include @@ -152,8 +155,8 @@ static int vkms_modeset_init(struct vkms_device *vkmsdev) dev->mode_config.preferred_depth = 0; dev->mode_config.helper_private = &vkms_mode_config_helpers; - return vkmsdev->is_default ? vkms_output_init_default(vkmsdev) : - -ENOSYS; + return vkmsdev->configfs ? vkms_output_init(vkmsdev) : + vkms_output_init_default(vkmsdev); } static int vkms_platform_probe(struct platform_device *pdev) @@ -165,6 +168,7 @@ static int vkms_platform_probe(struct platform_device *pdev) grp = devres_open_group(&pdev->dev, NULL, GFP_KERNEL); if (!grp) { + DRM_ERROR("Could not open devres group\n"); return -ENOMEM; } @@ -179,7 +183,7 @@ static int vkms_platform_probe(struct platform_device *pdev) vkms_device->config.cursor = enable_cursor; vkms_device->config.writeback = enable_writeback; vkms_device->config.overlay = enable_overlay; - vkms_device->is_default = vkms_device_setup->is_default; + vkms_device->configfs = vkms_device_setup->configfs; ret = dma_coerce_mask_and_coherent(vkms_device->drm.dev, DMA_BIT_MASK(64)); @@ -239,12 +243,43 @@ static struct platform_driver vkms_platform_driver = { .driver.name = DRIVER_NAME, }; +struct vkms_device *vkms_add_device(struct vkms_configfs *configfs) +{ + struct device *dev = NULL; + struct platform_device *pdev; + int max_id = 1; + struct vkms_device_setup vkms_device_setup = { + .configfs = configfs, + }; + + while ((dev = platform_find_device_by_driver( + dev, &vkms_platform_driver.driver))) { + pdev = to_platform_device(dev); + max_id = max(max_id, pdev->id); + } + + pdev = platform_device_register_data(NULL, DRIVER_NAME, max_id + 1, + &vkms_device_setup, + sizeof(vkms_device_setup)); + if (IS_ERR(pdev)) { + DRM_ERROR("Unable to register vkms device'\n"); + return ERR_PTR(PTR_ERR(pdev)); + } + + return platform_get_drvdata(pdev); +} + +void vkms_remove_device(struct vkms_device *vkms_device) +{ + platform_device_unregister(vkms_device->platform); +} + static int __init vkms_init(void) { int ret; struct platform_device *pdev; struct vkms_device_setup vkms_device_setup = { - .is_default = true, + .configfs = NULL, }; ret = platform_driver_register(&vkms_platform_driver); @@ -262,6 +297,13 @@ static int __init vkms_init(void) return PTR_ERR(pdev); } + ret = vkms_init_configfs(); + if (ret) { + DRM_ERROR("Unable to initialize configfs\n"); + platform_device_unregister(pdev); + platform_driver_unregister(&vkms_platform_driver); + } + return 0; } @@ -269,6 +311,8 @@ static void __exit vkms_exit(void) { struct device *dev; + vkms_unregister_configfs(); + while ((dev = platform_find_device_by_driver( NULL, &vkms_platform_driver.driver))) { // platform_find_device_by_driver increments the refcount. Drop diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 84b35aa1dc5a..3634eeeb4548 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 #include #include @@ -10,6 +11,7 @@ #include #include #include +#include #include #define XRES_MIN 10 @@ -127,14 +129,65 @@ struct vkms_config { bool overlay; }; +struct vkms_config_links { + struct config_group group; + unsigned long linked_object_bitmap; +}; + +struct vkms_config_connector { + struct config_group config_group; + struct vkms_config_links possible_encoders; +}; + +struct vkms_config_crtc { + struct config_group config_group; + unsigned long crtc_config_idx; +}; + +struct vkms_config_encoder { + struct config_group config_group; + struct vkms_config_links possible_crtcs; + unsigned long encoder_config_idx; +}; + +struct vkms_config_plane { + struct vkms_configfs *configfs; + struct config_group config_group; + struct vkms_config_links possible_crtcs; + enum drm_plane_type type; +}; + +struct vkms_configfs { + /* Directory group containing connector configs, e.g. /config/vkms/device/ */ + struct config_group device_group; + /* Directory group containing connector configs, e.g. /config/vkms/device/connectors/ */ + struct config_group connectors_group; + /* Directory group containing CRTC configs, e.g. /config/vkms/device/crtcs/ */ + struct config_group crtcs_group; + /* Directory group containing encoder configs, e.g. /config/vkms/device/encoders/ */ + struct config_group encoders_group; + /* Directory group containing plane configs, e.g. /config/vkms/device/planes/ */ + struct config_group planes_group; + + unsigned long allocated_crtcs; + unsigned long allocated_encoders; + + struct mutex lock; + + /* The platform device if this is registered, otherwise NULL */ + struct vkms_device *vkms_device; +}; + struct vkms_device_setup { - bool is_default; + // Is NULL in the case of the default card. + struct vkms_configfs *configfs; }; struct vkms_device { struct drm_device drm; struct platform_device *platform; - bool is_default; + // Is NULL in the case of the default card. + struct vkms_configfs *configfs; struct vkms_output output; struct vkms_config config; }; @@ -153,11 +206,42 @@ struct vkms_device { #define to_vkms_plane_state(target)\ container_of(target, struct vkms_plane_state, base.base) +#define item_to_configfs(item) \ + container_of(to_config_group(item), struct vkms_configfs, device_group) + +#define item_to_config_connector(item) \ + container_of(to_config_group(item), struct vkms_config_connector, \ + config_group) + +#define item_to_config_crtc(item) \ + container_of(to_config_group(item), struct vkms_config_crtc, \ + config_group) + +#define item_to_config_encoder(item) \ + container_of(to_config_group(item), struct vkms_config_encoder, \ + config_group) + +#define item_to_config_plane(item) \ + container_of(to_config_group(item), struct vkms_config_plane, \ + config_group) + +#define item_to_config_links(item) \ + container_of(to_config_group(item), struct vkms_config_links, group) + +#define plane_item_to_configfs(item) \ + container_of(to_config_group(item->ci_parent), struct vkms_configfs, \ + planes_group) + +/* Devices */ +struct vkms_device *vkms_add_device(struct vkms_configfs *configfs); +void vkms_remove_device(struct vkms_device *vkms_device); + /* CRTC */ struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev, struct drm_plane *primary, struct drm_plane *cursor); +int vkms_output_init(struct vkms_device *vkmsdev); int vkms_output_init_default(struct vkms_device *vkmsdev); struct vkms_plane *vkms_plane_init(struct vkms_device *vkmsdev, @@ -179,4 +263,8 @@ void vkms_compose_row(struct line_buffer *stage_buffer, struct vkms_plane_state int vkms_enable_writeback_connector(struct vkms_device *vkmsdev, struct vkms_crtc *vkms_crtc); +/* ConfigFS Support */ +int vkms_init_configfs(void); +void vkms_unregister_configfs(void); + #endif /* _VKMS_DRV_H_ */ diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index 3b5e272a8b33..c9e6c653de19 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -177,3 +177,8 @@ int vkms_output_init_default(struct vkms_device *vkmsdev) return ret; } + +int vkms_output_init(struct vkms_device *vkmsdev) +{ + return -ENOTSUPP; +} From patchwork Fri Jun 23 22:23:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Shargo X-Patchwork-Id: 13291432 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 CC4C6C001DF for ; Fri, 23 Jun 2023 22:25:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2282510E6D5; Fri, 23 Jun 2023 22:25:47 +0000 (UTC) Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by gabe.freedesktop.org (Postfix) with ESMTPS id 938A010E6D5 for ; Fri, 23 Jun 2023 22:25:41 +0000 (UTC) Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-30fcda210cfso1231049f8f.3 for ; Fri, 23 Jun 2023 15:25:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687559139; x=1690151139; 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=FFPPAelyxCPieaG66w0ZiNqoMFR6anlrmZn6wmUJKro=; b=j2lzdYcZZf5HOKXT9olSBqyDHt8uaV5rAXVw5MdLfx1Hx1SAWbAB6+1XA9OfHFByjp j8ATThKloZTkAVWxwb14lNkK/ZJNQkVH1t/xlpcl484jMXwbsqlNf0mwtrgH+j4J2TMb +hIn2ym9KcSgMVydj3cO3kGJfkX+pTpHwKKGA= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687559139; x=1690151139; 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=FFPPAelyxCPieaG66w0ZiNqoMFR6anlrmZn6wmUJKro=; b=S10qKtEOw5peCr7wBCVb/HNI81dSnkuNb8gDkwYIxfFRAEyBHfX9kjKd1i2kSn2ggT fh3mXQVQEaOYW0R+I93UrJVvHfn0ASMhOPFQzp2zEOr8rD4rE2lVii8oMeHsnnZZGA4b URulHUwMXPjsj/xVWQmhhi3lj7lfs7oayVHWTCXSLjc1DcFuh3hZ3wiHmLoRNeUeyGeY Sfl/DsHjUbP86riAYGxPd6Tv2zfHLPYsWDnB64SE3ISme72pW83pnoTt9TXpYmWu9xBw bvZlI8yIfOIjMkVrL9vitV0ftMGqJKrgCQKhx/+PTnR9XceT5AT1Vf6uysMPzSdSElt1 SvTg== X-Gm-Message-State: AC+VfDwWmlSjh8C1zcEm65HPFTbpNKXB/SDuQHRbImCB+B8ioUyTdzAu CmwDXe+4f0NFzPnoNF7p55UFeg== X-Google-Smtp-Source: ACHHUZ6tYnEtdNvw2ixKzIyEGo12HfY+ZANcVmxf/nj0y4P8/u+j4T5f7ArgXw+DICl2JHwQTxgntQ== X-Received: by 2002:adf:f78f:0:b0:30f:cb0e:b283 with SMTP id q15-20020adff78f000000b0030fcb0eb283mr17891878wrp.30.1687559139580; Fri, 23 Jun 2023 15:25:39 -0700 (PDT) Received: from big-boopo.mynetworksettings.com (pool-108-46-233-209.nycmny.fios.verizon.net. [108.46.233.209]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4106000000b0030c2e3c7fb3sm453223wrp.101.2023.06.23.15.25.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 15:25:39 -0700 (PDT) From: Jim Shargo To: mairacanal@riseup.net, Daniel Vetter , David Airlie , Haneen Mohammed , Jonathan Corbet , Maarten Lankhorst , Maxime Ripard , Melissa Wen , Rodrigo Siqueira , Thomas Zimmermann Subject: [PATCH v2 5/6] drm/vkms: Support enabling ConfigFS devices Date: Fri, 23 Jun 2023 18:23:47 -0400 Message-ID: <20230623222353.97283-6-jshargo@chromium.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230623222353.97283-1-jshargo@chromium.org> References: <20230623222353.97283-1-jshargo@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: Jim Shargo , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" VKMS now supports creating and using virtual devices! In addition to the enabling logic, this commit also prevents users from adding new objects once a card is registered. Signed-off-by: Jim Shargo --- drivers/gpu/drm/vkms/vkms_configfs.c | 37 +++-- drivers/gpu/drm/vkms/vkms_crtc.c | 4 +- drivers/gpu/drm/vkms/vkms_drv.c | 3 +- drivers/gpu/drm/vkms/vkms_drv.h | 2 +- drivers/gpu/drm/vkms/vkms_output.c | 201 +++++++++++++++++++++++---- 5 files changed, 202 insertions(+), 45 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_configfs.c b/drivers/gpu/drm/vkms/vkms_configfs.c index 544024735d19..f5eed6d23dcd 100644 --- a/drivers/gpu/drm/vkms/vkms_configfs.c +++ b/drivers/gpu/drm/vkms/vkms_configfs.c @@ -504,29 +504,40 @@ static ssize_t device_enabled_store(struct config_item *item, const char *buf, { struct vkms_configfs *configfs = item_to_configfs(item); struct vkms_device *device; - int value, ret; + int enabled, ret; - ret = kstrtoint(buf, 0, &value); + ret = kstrtoint(buf, 0, &enabled); if (ret) return ret; - if (value != 1) - return -EINVAL; - - mutex_lock(&configfs->lock); - - if (configfs->vkms_device) { + if (enabled == 0) { + mutex_lock(&configfs->lock); + if (configfs->vkms_device) { + vkms_remove_device(configfs->vkms_device); + configfs->vkms_device = NULL; + } mutex_unlock(&configfs->lock); + return len; } - device = vkms_add_device(configfs); - mutex_unlock(&configfs->lock); + if (enabled == 1) { + mutex_lock(&configfs->lock); + if (!configfs->vkms_device) { + device = vkms_add_device(configfs); + if (IS_ERR(device)) { + mutex_unlock(&configfs->lock); + return -PTR_ERR(device); + } + + configfs->vkms_device = device; + } + mutex_unlock(&configfs->lock); - if (IS_ERR(device)) - return -PTR_ERR(device); + return len; + } - return len; + return -EINVAL; } CONFIGFS_ATTR(device_, enabled); diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index d91e49c53adc..5ebb5264f6ef 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -278,7 +278,7 @@ static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = { struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev, struct drm_plane *primary, - struct drm_plane *cursor) + struct drm_plane *cursor, const char *name) { struct drm_device *dev = &vkmsdev->drm; struct vkms_crtc *vkms_crtc; @@ -290,7 +290,7 @@ struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev, vkms_crtc = &vkmsdev->output.crtcs[vkmsdev->output.num_crtcs++]; ret = drmm_crtc_init_with_planes(dev, &vkms_crtc->base, primary, cursor, - &vkms_crtc_funcs, NULL); + &vkms_crtc_funcs, name); if (ret) { DRM_ERROR("Failed to init CRTC\n"); goto out_error; diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 1b5b7143792f..314a04659c5f 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -210,7 +210,7 @@ static int vkms_platform_probe(struct platform_device *pdev) ret = drm_dev_register(&vkms_device->drm, 0); if (ret) { DRM_ERROR("Unable to register device with id %d\n", pdev->id); - return ret; + goto out_release_group; } drm_fbdev_generic_setup(&vkms_device->drm, 0); @@ -256,6 +256,7 @@ struct vkms_device *vkms_add_device(struct vkms_configfs *configfs) dev, &vkms_platform_driver.driver))) { pdev = to_platform_device(dev); max_id = max(max_id, pdev->id); + put_device(dev); } pdev = platform_device_register_data(NULL, DRIVER_NAME, max_id + 1, diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 3634eeeb4548..3d592d085f49 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -239,7 +239,7 @@ void vkms_remove_device(struct vkms_device *vkms_device); /* CRTC */ struct vkms_crtc *vkms_crtc_init(struct vkms_device *vkmsdev, struct drm_plane *primary, - struct drm_plane *cursor); + struct drm_plane *cursor, const char *name); int vkms_output_init(struct vkms_device *vkmsdev); int vkms_output_init_default(struct vkms_device *vkmsdev); diff --git a/drivers/gpu/drm/vkms/vkms_output.c b/drivers/gpu/drm/vkms/vkms_output.c index c9e6c653de19..806ff01954ad 100644 --- a/drivers/gpu/drm/vkms/vkms_output.c +++ b/drivers/gpu/drm/vkms/vkms_output.c @@ -2,8 +2,10 @@ #include #include +#include #include #include +#include #include #include @@ -82,7 +84,6 @@ static struct drm_encoder *vkms_encoder_init(struct vkms_device *vkms_device) int vkms_output_init_default(struct vkms_device *vkmsdev) { - struct vkms_output *output = &vkmsdev->output; struct drm_device *dev = &vkmsdev->drm; struct drm_connector *connector; struct drm_encoder *encoder; @@ -101,8 +102,7 @@ int vkms_output_init_default(struct vkms_device *vkmsdev) struct vkms_plane *overlay = vkms_plane_init( vkmsdev, DRM_PLANE_TYPE_OVERLAY); if (IS_ERR(overlay)) { - ret = PTR_ERR(overlay); - goto err_planes; + return PTR_ERR(overlay); } } } @@ -110,17 +110,16 @@ int vkms_output_init_default(struct vkms_device *vkmsdev) if (vkmsdev->config.cursor) { cursor = vkms_plane_init(vkmsdev, DRM_PLANE_TYPE_CURSOR); if (IS_ERR(cursor)) { - ret = PTR_ERR(cursor); - goto err_planes; + return PTR_ERR(cursor); } } vkms_crtc = vkms_crtc_init(vkmsdev, &primary->base, - cursor ? &cursor->base : NULL); + cursor ? &cursor->base : NULL, + "crtc-default"); if (IS_ERR(vkms_crtc)) { DRM_ERROR("Failed to init crtc\n"); - ret = PTR_ERR(vkms_crtc); - goto err_planes; + return PTR_ERR(vkms_crtc); } for (int i = 0; i < vkmsdev->output.num_planes; i++) { @@ -131,22 +130,20 @@ int vkms_output_init_default(struct vkms_device *vkmsdev) connector = vkms_connector_init(vkmsdev); if (IS_ERR(connector)) { DRM_ERROR("Failed to init connector\n"); - ret = PTR_ERR(connector); - goto err_connector; + return PTR_ERR(connector); } encoder = vkms_encoder_init(vkmsdev); if (IS_ERR(encoder)) { DRM_ERROR("Failed to init encoder\n"); - ret = PTR_ERR(encoder); - goto err_encoder; + return PTR_ERR(encoder); } encoder->possible_crtcs |= drm_crtc_mask(&vkms_crtc->base); ret = drm_connector_attach_encoder(connector, encoder); if (ret) { DRM_ERROR("Failed to attach connector to encoder\n"); - goto err_attach; + return ret; } if (vkmsdev->config.writeback) { @@ -158,27 +155,175 @@ int vkms_output_init_default(struct vkms_device *vkmsdev) drm_mode_config_reset(dev); return 0; +} -err_attach: - drm_encoder_cleanup(encoder); +static bool is_object_linked(struct vkms_config_links *links, unsigned long idx) +{ + return links->linked_object_bitmap & (1 << idx); +} -err_encoder: - drm_connector_cleanup(connector); +int vkms_output_init(struct vkms_device *vkmsdev) +{ + struct drm_device *dev = &vkmsdev->drm; + struct vkms_configfs *configfs = vkmsdev->configfs; + struct vkms_output *output = &vkmsdev->output; + struct plane_map { + struct vkms_config_plane *config_plane; + struct vkms_plane *plane; + } plane_map[VKMS_MAX_PLANES] = { 0 }; + struct encoder_map { + struct vkms_config_encoder *config_encoder; + struct drm_encoder *encoder; + } encoder_map[VKMS_MAX_OUTPUT_OBJECTS] = { 0 }; + struct config_item *item; + int map_idx = 0; + + list_for_each_entry(item, &configfs->planes_group.cg_children, + ci_entry) { + struct vkms_config_plane *config_plane = + item_to_config_plane(item); + struct vkms_plane *plane = + vkms_plane_init(vkmsdev, config_plane->type); + + if (IS_ERR(plane)) { + DRM_ERROR("Unable to init plane from config: %s", + item->ci_name); + return PTR_ERR(plane); + } -err_connector: - drm_crtc_cleanup(&vkms_crtc->base); + plane_map[map_idx].config_plane = config_plane; + plane_map[map_idx].plane = plane; + map_idx += 1; + } -err_planes: - for (int i = 0; i < output->num_planes; i++) { - drm_plane_cleanup(&output->planes[i].base); + map_idx = 0; + list_for_each_entry(item, &configfs->encoders_group.cg_children, + ci_entry) { + struct vkms_config_encoder *config_encoder = + item_to_config_encoder(item); + struct drm_encoder *encoder = vkms_encoder_init(vkmsdev); + + if (IS_ERR(encoder)) { + DRM_ERROR("Failed to init config encoder: %s", + item->ci_name); + return PTR_ERR(encoder); + } + encoder_map[map_idx].config_encoder = config_encoder; + encoder_map[map_idx].encoder = encoder; + map_idx += 1; } - memset(output, 0, sizeof(*output)); + list_for_each_entry(item, &configfs->connectors_group.cg_children, + ci_entry) { + struct vkms_config_connector *config_connector = + item_to_config_connector(item); + struct drm_connector *connector = vkms_connector_init(vkmsdev); - return ret; -} + if (IS_ERR(connector)) { + DRM_ERROR("Failed to init connector from config: %s", + item->ci_name); + return PTR_ERR(connector); + } -int vkms_output_init(struct vkms_device *vkmsdev) -{ - return -ENOTSUPP; + for (int j = 0; j < output->num_connectors; j++) { + struct encoder_map *encoder = &encoder_map[j]; + + if (is_object_linked( + &config_connector->possible_encoders, + encoder->config_encoder + ->encoder_config_idx)) { + drm_connector_attach_encoder(connector, + encoder->encoder); + } + } + } + + list_for_each_entry(item, &configfs->crtcs_group.cg_children, + ci_entry) { + struct vkms_config_crtc *config_crtc = + item_to_config_crtc(item); + struct vkms_crtc *vkms_crtc; + struct drm_plane *primary = NULL, *cursor = NULL; + + for (int j = 0; j < output->num_planes; j++) { + struct plane_map *plane_entry = &plane_map[j]; + struct drm_plane *plane = &plane_entry->plane->base; + + if (!is_object_linked( + &plane_entry->config_plane->possible_crtcs, + config_crtc->crtc_config_idx)) { + continue; + } + + if (plane->type == DRM_PLANE_TYPE_PRIMARY) { + if (primary) { + DRM_WARN( + "Too many primary planes found for crtc %s.", + item->ci_name); + return EINVAL; + } + primary = plane; + } else if (plane->type == DRM_PLANE_TYPE_CURSOR) { + if (cursor) { + DRM_WARN( + "Too many cursor planes found for crtc %s.", + item->ci_name); + return EINVAL; + } + cursor = plane; + } + } + + if (!primary) { + DRM_WARN("No primary plane configured for crtc %s", + item->ci_name); + return EINVAL; + } + + vkms_crtc = + vkms_crtc_init(vkmsdev, primary, cursor, item->ci_name); + if (IS_ERR(vkms_crtc)) { + DRM_WARN("Unable to init crtc from config: %s", + item->ci_name); + return PTR_ERR(vkms_crtc); + } + + for (int j = 0; j < output->num_planes; j++) { + struct plane_map *plane_entry = &plane_map[j]; + + if (!plane_entry->plane) + break; + + if (is_object_linked( + &plane_entry->config_plane->possible_crtcs, + config_crtc->crtc_config_idx)) { + plane_entry->plane->base.possible_crtcs |= + drm_crtc_mask(&vkms_crtc->base); + } + } + + for (int j = 0; j < output->num_encoders; j++) { + struct encoder_map *encoder_entry = &encoder_map[j]; + + if (is_object_linked(&encoder_entry->config_encoder + ->possible_crtcs, + config_crtc->crtc_config_idx)) { + encoder_entry->encoder->possible_crtcs |= + drm_crtc_mask(&vkms_crtc->base); + } + } + + if (vkmsdev->config.writeback) { + int ret = vkms_enable_writeback_connector(vkmsdev, + vkms_crtc); + if (ret) + DRM_WARN( + "Failed to init writeback connector for config crtc: %s. Error code %d", + item->ci_name, ret); + } + } + + drm_mode_config_reset(dev); + + return 0; } From patchwork Fri Jun 23 22:23:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jim Shargo X-Patchwork-Id: 13291431 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 6073EC001E0 for ; Fri, 23 Jun 2023 22:25:48 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 58FDC10E6D6; Fri, 23 Jun 2023 22:25:47 +0000 (UTC) Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by gabe.freedesktop.org (Postfix) with ESMTPS id D7A5F10E6D5 for ; Fri, 23 Jun 2023 22:25:43 +0000 (UTC) Received: by mail-wm1-x32e.google.com with SMTP id 5b1f17b1804b1-3fa79605a3bso11268775e9.0 for ; Fri, 23 Jun 2023 15:25:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1687559142; x=1690151142; 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=XVDfyQp1D2UHXpL1ZVItWp64PNlbA4FYgRcewIHu8Ww=; b=PRuOCVqjhaiUIaUxHpcOBEuD6ZfRhG69YI9VhpRhJBg/QRW8qHokII2mDUDfTkEvKb j5XmH5Dnv+539X4Yu3HnU2WPe9mnfR6Lm4OVBFbS3IvhFBzZ6KHFOqoGVuXxWBd+BoMw LNLpD2UixobZWhUHVRCICdr09zBrDVUX/tFNY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687559142; x=1690151142; 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=XVDfyQp1D2UHXpL1ZVItWp64PNlbA4FYgRcewIHu8Ww=; b=IbRZvOfFqRwR1UwTPH+Zj9hSeWOuXphSkwhhpEhP2ajFnwQz/ygFDaDA5+wdRKiR5U RBS7PC/amlVJ5aFMh5O0v/4/43aJgrHNZ4U02JUYtZi4ULxga85tjTPxSLdas1yek1Ge /uLcoiaMh521eVlOvJ+hxra3iEzgksQBW3/UzIdPzqqPJov0QhH5AquxJTCRrzAjX+Sl 6NF0M1ABnK9uvsZanz4uVtIkWE5b2VpT+LloTH0VRqmidw57rYGzWK+JnvsmNNUvMPE4 TVjxkVTjVAH1yVt8/dNLZLCpURAi7QaLJuykZR6F1HJ+2ytngqePWblQzEsp8KMJ6kYx KeJQ== X-Gm-Message-State: AC+VfDyQZMdQH7c8of5bpOWJVG32Au/qHohIHdLsBxyt7qCnx9SoEA5w mGCcyBm5Vays0o+y0NvDWzucZQ== X-Google-Smtp-Source: ACHHUZ7pe50hzgM5iLC2579qWnSeqdzLoUZ3+Orq7sbVqA9W1K1hggz4Fbs/PlyG3wmdZULYjOJhjA== X-Received: by 2002:a05:600c:138c:b0:3fa:7bf0:7a81 with SMTP id u12-20020a05600c138c00b003fa7bf07a81mr2995293wmf.0.1687559141956; Fri, 23 Jun 2023 15:25:41 -0700 (PDT) Received: from big-boopo.mynetworksettings.com (pool-108-46-233-209.nycmny.fios.verizon.net. [108.46.233.209]) by smtp.gmail.com with ESMTPSA id l6-20020a5d4106000000b0030c2e3c7fb3sm453223wrp.101.2023.06.23.15.25.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Jun 2023 15:25:41 -0700 (PDT) From: Jim Shargo To: mairacanal@riseup.net, Daniel Vetter , David Airlie , Haneen Mohammed , Jonathan Corbet , Maarten Lankhorst , Maxime Ripard , Melissa Wen , Rodrigo Siqueira , Thomas Zimmermann Subject: [PATCH v2 6/6] drm/vkms: Add a module param to enable/disable the default device Date: Fri, 23 Jun 2023 18:23:48 -0400 Message-ID: <20230623222353.97283-7-jshargo@chromium.org> X-Mailer: git-send-email 2.41.0.162.gfafddb0af9-goog In-Reply-To: <20230623222353.97283-1-jshargo@chromium.org> References: <20230623222353.97283-1-jshargo@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: Jim Shargo , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-doc@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" In many testing circumstances, we will want to just create a new device and test against that. If we create a default device, it can be annoying to have to manually select the new device instead of choosing the only one that exists. The param, enable_default, is defaulted to true to maintain backwards compatibility. Signed-off-by: Jim Shargo --- drivers/gpu/drm/vkms/vkms_drv.c | 44 ++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 314a04659c5f..1cb56c090a65 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -42,17 +42,26 @@ #define DRIVER_MAJOR 1 #define DRIVER_MINOR 0 +static bool enable_default_device = true; +module_param_named(enable_default_device, enable_default_device, bool, 0444); +MODULE_PARM_DESC(enable_default_device, + "Enable/Disable creating the default device"); + static bool enable_cursor = true; module_param_named(enable_cursor, enable_cursor, bool, 0444); -MODULE_PARM_DESC(enable_cursor, "Enable/Disable cursor support"); +MODULE_PARM_DESC(enable_cursor, + "Enable/Disable cursor support for the default device"); static bool enable_writeback = true; module_param_named(enable_writeback, enable_writeback, bool, 0444); -MODULE_PARM_DESC(enable_writeback, "Enable/Disable writeback connector support"); +MODULE_PARM_DESC( + enable_writeback, + "Enable/Disable writeback connector support for the default device"); static bool enable_overlay; module_param_named(enable_overlay, enable_overlay, bool, 0444); -MODULE_PARM_DESC(enable_overlay, "Enable/Disable overlay support"); +MODULE_PARM_DESC(enable_overlay, + "Enable/Disable overlay support for the default device"); DEFINE_DRM_GEM_FOPS(vkms_driver_fops); @@ -278,10 +287,7 @@ void vkms_remove_device(struct vkms_device *vkms_device) static int __init vkms_init(void) { int ret; - struct platform_device *pdev; - struct vkms_device_setup vkms_device_setup = { - .configfs = NULL, - }; + struct platform_device *default_pdev = NULL; ret = platform_driver_register(&vkms_platform_driver); if (ret) { @@ -289,19 +295,27 @@ static int __init vkms_init(void) return ret; } - pdev = platform_device_register_data(NULL, DRIVER_NAME, 0, - &vkms_device_setup, - sizeof(vkms_device_setup)); - if (IS_ERR(pdev)) { - DRM_ERROR("Unable to register default vkms device\n"); - platform_driver_unregister(&vkms_platform_driver); - return PTR_ERR(pdev); + if (enable_default_device) { + struct vkms_device_setup vkms_device_setup = { + .configfs = NULL, + }; + + default_pdev = platform_device_register_data( + NULL, DRIVER_NAME, 0, &vkms_device_setup, + sizeof(vkms_device_setup)); + if (IS_ERR(default_pdev)) { + DRM_ERROR("Unable to register default vkms device\n"); + platform_driver_unregister(&vkms_platform_driver); + return PTR_ERR(default_pdev); + } } ret = vkms_init_configfs(); if (ret) { DRM_ERROR("Unable to initialize configfs\n"); - platform_device_unregister(pdev); + if (default_pdev) + platform_device_unregister(default_pdev); + platform_driver_unregister(&vkms_platform_driver); }