Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp314683pxb; Wed, 24 Feb 2021 02:59:14 -0800 (PST) X-Google-Smtp-Source: ABdhPJyyK+cjTg6S8J7+7hzwBwwCBo394HkLezY1qnWBm5ltwM+Bn+0yj9mV+RxuS2lc49508dXB X-Received: by 2002:a17:906:f113:: with SMTP id gv19mr17311018ejb.379.1614164354336; Wed, 24 Feb 2021 02:59:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614164354; cv=none; d=google.com; s=arc-20160816; b=NOLs8BddgKVxbi6AmBufgqaBQP5vEvh61XwHGVmTUURjislonmXAQjUXpNumlGD3FE nRUVc/qZNA1y40ADpxqULbgBzlmkzoDNOfnVKPEcsFnecMy9vZaOZ/iHGcqDtjZkjIBk qJWyXk/fIFiDEldZIecd2ImJVnNG+Um/dzSpXecqEoyxjWvoce8LBVmwXvF/6H9P0mXj u80Piy06JOQrxvT+sVC5Ax2NMG1db8nTmn3O5OZb4q2nqCjcN/lAGn3R1cDVH7Bd3aRS AL/3EMx0NRo8Fxt1tzHcy9qKUztKlhihxA17Ir4m3BA2Zju/1fDhdv8/gy0jvh1OOSl7 zJhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date:dkim-signature; bh=OZmIVnGmRqkHE37MUl/fX1v3MBrD7OJUk4oQyf7Ar5g=; b=ZT+QVEMba04Kq8pMPBT06C5btkF9HYGM0K5BPyw/Kp8KiSNc7e/6ELHtO5SYslFvwo 2gTai9mfp8q7cuhHV+Y0mfPMCt+SOlmtVVueTzVNa5erVyuwWmwI5XWhIhAXqMrqPAi9 1cA25FI7RrzDDi0weGsQtXLiOKDuKqGj5osrXJCLfG3xbfEqyZZ1hOKuOQQlL27J/lRL 57QxpWpm+jVwOg0uE5I3Y7LkYuw+DWgcMx/vFLPd+AOtKY4Zqsfi3rSZ9X7PMb2Sw3u7 RAd79S/mMLz1+boRNJl0rUi3e7uB8E8X45i78AtNhdo6PP0X3fByBzFrnGRUd6b6NAcS zoPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Fu+y56or; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q16si1068845ejd.199.2021.02.24.02.58.48; Wed, 24 Feb 2021 02:59:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Fu+y56or; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233832AbhBXK4K (ORCPT + 99 others); Wed, 24 Feb 2021 05:56:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37776 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234785AbhBXKzz (ORCPT ); Wed, 24 Feb 2021 05:55:55 -0500 Received: from mail-pg1-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9310AC061786 for ; Wed, 24 Feb 2021 02:55:14 -0800 (PST) Received: by mail-pg1-x52b.google.com with SMTP id o10so1204957pgg.4 for ; Wed, 24 Feb 2021 02:55:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition; bh=OZmIVnGmRqkHE37MUl/fX1v3MBrD7OJUk4oQyf7Ar5g=; b=Fu+y56orWSMafFuHJB2gQRcLudSEvPXsixZHWx3Vzhm2lfXeA7URLfZREhMOQa9sT5 janTkD99fgLif91bCE6c+8aSnxVAgrdZYJ4OuRQvAEkRd6dK/cz9L96Gy5Z5X/2O6Ee2 zaJ/IjrC/aCL+3ObzCALLw9T7D2sydC5HAEgRun1cAy3ylEHZInXS4B86pFHUHj07BeF AMG3PCWCZ90V8FPYhlRgggq6AM5KJ3WSu0yKFZ6oC9zoQt0HQ8w/PH5pUh+o4hnwvGDu Dc8qx9/oe3DohUddBCu3C3x988pov4KHCsHljoU2L01q0/JM4/zRD7arrZm2Vu6wGdCU vTWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=OZmIVnGmRqkHE37MUl/fX1v3MBrD7OJUk4oQyf7Ar5g=; b=sk7fDCB69HJ2Ui5UFb/X2eDC1e/AmEZmLjXrlB1MSo+tk3A/LL52LISDiyyV9jiZHH S17NZEp/ORijOZDTZOThGHL18ZBZqM/N+kvZdK5O8EIYBrF3T8LhLPxWRBUJDpeGFR0A 2reee1mV3mPJVNuyDuxUKzfmVyY9Iuu0JaCP1fpFber3rFxuiRk8ik9TpU8LenspnqmN AN3P4FjOWaSAWDYZKopmtvkTY28mXJJNwd8BBRmEXsrMHSTEWJmoDHQ78MbYVQNm834Y xYKm2kM74XMKacpNn2xMaOBQXjEYGTQbT7KyM9KXZN+7EcEENLP2580efYDiaahlKxDc m3gw== X-Gm-Message-State: AOAM530NHhPViaMxzXd40al/UXvtxwOgGYDit4kIaPPC4aZdgYSnQ5EW rXSzCpoZENFLWc7GzzkQaqQ= X-Received: by 2002:a63:1409:: with SMTP id u9mr27776845pgl.312.1614164114133; Wed, 24 Feb 2021 02:55:14 -0800 (PST) Received: from adolin ([49.207.196.12]) by smtp.gmail.com with ESMTPSA id x2sm2269603pfi.220.2021.02.24.02.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Feb 2021 02:55:13 -0800 (PST) Date: Wed, 24 Feb 2021 16:25:09 +0530 From: Sumera Priyadarsini To: melissa.srw@gmail.com Cc: daniel@ffwll.ch, rodrigosiqueiramelo@gmail.com, hamohammed.sa@gmail.com, airlied@linux.ie, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] drm/vkms: Add support for virtual hardware mode Message-ID: <20210224105509.yzdimgbu2jwe3auf@adolin> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add a virtual hardware or vblank-less mode as a module to enable VKMS to emulate virtual graphic drivers. This mode can be enabled by setting enable_virtual_hw=1 at the time of loading VKMS. A new function vkms_crtc_composer() has been added to bypass the vblank mode and is called directly in the atomic hook in vkms_atomic_begin(). However, some crc captures still use vblanks which causes the crc-based igt tests to crash. Currently, I am unsure about how to approach one-shot implementation of crc reads so I am still working on that. This patch has been tested with the igt tests, kms_writeback, kms_atomic, kms_lease, kms_flip, kms_pipe_get_crc and preserves results except for subtests related to crc reads and skips tests that rely on vertical blanking. This patch must be tested after incorporating the igt-tests patch: https://lists.freedesktop.org/archives/igt-dev/2021-February/029355.html . The patch is based on Rodrigo Siqueira's patch(https://patchwork.freedesktop.org/patch/316851/?series=48469&rev=3) and the ensuing review. Signed-off-by: Sumera Priyadarsini --- drivers/gpu/drm/vkms/vkms_composer.c | 46 ++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_crtc.c | 17 ++++++++-- drivers/gpu/drm/vkms/vkms_drv.c | 18 ++++++++--- drivers/gpu/drm/vkms/vkms_drv.h | 2 ++ 4 files changed, 75 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_composer.c b/drivers/gpu/drm/vkms/vkms_composer.c index 66c6842d70db..7a8aaf5c5555 100644 --- a/drivers/gpu/drm/vkms/vkms_composer.c +++ b/drivers/gpu/drm/vkms/vkms_composer.c @@ -247,6 +247,52 @@ void vkms_composer_worker(struct work_struct *work) drm_crtc_add_crc_entry(crtc, true, frame_start++, &crc32); } +void vkms_crtc_composer(struct vkms_crtc_state *crtc_state) +{ + struct drm_crtc *crtc = crtc_state->base.crtc; + struct vkms_output *out = drm_crtc_to_vkms_output(crtc); + struct vkms_composer *primary_composer = NULL; + struct vkms_composer *cursor_composer = NULL; + void *vaddr_out = NULL; + u32 crc32 = 0; + int ret; + bool wb_pending; + + wb_pending = crtc_state->wb_pending; + + if (crtc_state->num_active_planes >= 1) + primary_composer = crtc_state->active_planes[0]->composer; + + if (crtc_state->num_active_planes == 2) + cursor_composer = crtc_state->active_planes[1]->composer; + + if (!primary_composer) + return; + + if (wb_pending) + vaddr_out = crtc_state->active_writeback; + + ret = compose_planes(&vaddr_out, primary_composer, cursor_composer); + if (ret) { + if (ret == -EINVAL && !wb_pending) + kfree(vaddr_out); + return; + } + + crc32 = compute_crc(vaddr_out, primary_composer); + + if (wb_pending) { + drm_writeback_signal_completion(&out->wb_connector, 0); + spin_lock_irq(&out->composer_lock); + crtc_state->wb_pending = false; + spin_unlock_irq(&out->composer_lock); + } else { + kfree(vaddr_out); + } + + drm_crtc_add_crc_entry(crtc, true, 0, &crc32); +} + static const char * const pipe_crc_sources[] = {"auto"}; const char *const *vkms_get_crc_sources(struct drm_crtc *crtc, diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index 6164349cdf11..38de791a4882 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -224,13 +224,19 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc, static void vkms_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_atomic_state *state) { - drm_crtc_vblank_on(crtc); + struct vkms_device *vkmsdev = drm_device_to_vkms_device(crtc->dev); + + if (!vkmsdev->config->virtual_hw) + drm_crtc_vblank_on(crtc); } static void vkms_crtc_atomic_disable(struct drm_crtc *crtc, struct drm_atomic_state *state) { - drm_crtc_vblank_off(crtc); + struct vkms_device *vkmsdev = drm_device_to_vkms_device(crtc->dev); + + if (!vkmsdev->config->virtual_hw) + drm_crtc_vblank_off(crtc); } static void vkms_crtc_atomic_begin(struct drm_crtc *crtc, @@ -248,8 +254,13 @@ 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_state *vkms_state = to_vkms_crtc_state(crtc->state); + struct vkms_device *vkmsdev = drm_device_to_vkms_device(crtc->dev); + + if (vkmsdev->config->virtual_hw) + vkms_crtc_composer(vkms_state); - if (crtc->state->event) { + if (crtc->state->event && !vkmsdev->config->virtual_hw) { spin_lock(&crtc->dev->event_lock); if (drm_crtc_vblank_get(crtc) != 0) diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index 2173b82606f6..945c4495d62a 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -44,6 +44,11 @@ static bool enable_writeback = true; module_param_named(enable_writeback, enable_writeback, bool, 0444); MODULE_PARM_DESC(enable_writeback, "Enable/Disable writeback connector support"); +static bool enable_virtual_hw = false; +module_param_named(enable_virtual_hw, enable_virtual_hw, bool, 0444); +MODULE_PARM_DESC(enable_virtual_hw, "Enable/Disable virtual hardware mode(virtual \ +hardware mode disables vblank interrupts)"); + DEFINE_DRM_GEM_FOPS(vkms_driver_fops); static void vkms_release(struct drm_device *dev) @@ -159,12 +164,14 @@ static int vkms_create(struct vkms_config *config) goto out_devres; } - vkms_device->drm.irq_enabled = true; + vkms_device->drm.irq_enabled = !vkms_device->config->virtual_hw; - ret = drm_vblank_init(&vkms_device->drm, 1); - if (ret) { - DRM_ERROR("Failed to vblank\n"); - goto out_devres; + if (!vkms_device->config->virtual_hw) { + ret = drm_vblank_init(&vkms_device->drm, 1); + if (ret) { + DRM_ERROR("Failed to vblank\n"); + goto out_devres; + } } ret = vkms_modeset_init(vkms_device); @@ -198,6 +205,7 @@ static int __init vkms_init(void) config->cursor = enable_cursor; config->writeback = enable_writeback; + config->virtual_hw = enable_virtual_hw; return vkms_create(config); } diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 35540c7c4416..d4a45518639c 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -85,6 +85,7 @@ struct vkms_device; struct vkms_config { bool writeback; bool cursor; + bool virtual_hw; /* only set when instantiated */ struct vkms_device *dev; }; @@ -127,6 +128,7 @@ 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_crtc_composer(struct vkms_crtc_state *crtc_state); /* Writeback */ int vkms_enable_writeback_connector(struct vkms_device *vkmsdev); -- 2.25.1