From patchwork Mon Jun 25 17:19:22 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rodrigo Siqueira X-Patchwork-Id: 10487031 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 022FD6023A for ; Mon, 25 Jun 2018 17:19:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D94BF2859A for ; Mon, 25 Jun 2018 17:19:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CD7D2285A4; Mon, 25 Jun 2018 17:19:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM, MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5A7D62859A for ; Mon, 25 Jun 2018 17:19:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8635289AC6; Mon, 25 Jun 2018 17:19:29 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-qt0-x243.google.com (mail-qt0-x243.google.com [IPv6:2607:f8b0:400d:c0d::243]) by gabe.freedesktop.org (Postfix) with ESMTPS id F2E4489AC6 for ; Mon, 25 Jun 2018 17:19:27 +0000 (UTC) Received: by mail-qt0-x243.google.com with SMTP id o9-v6so12637472qtp.3 for ; Mon, 25 Jun 2018 10:19:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=sbZAXRle6KiVAqqroy69FpzdJwzTzcJT5x/mqlv8cAI=; b=XrJJ3ekbdAsl2LmTo0Ph3tJjaL+g/JkncdS5fZPzIV8Cig4sQRW/ecWq4ZSbmJlHGG v4s6Oj0qb29Tirt9htsUpumPaZa04k0YmG6Kd0YZAFYY7X6byM34qLxsp04QsI82L3Do 7E3FS4/hFs+ACKec8xBEXOydD9tyzHc+XCPARLuuLOELmvE6vQwHnPBPyJp5Pi/7L1i1 /b6xHloa3WDaTejuHekUAhv2nrZmNpSuJNzbvhN1jTMXt6sOeYhS+CZfl75GdBK1R39f nuE5EZWhZALZmk4/5CWdVEuDQ0o41RFgDsHPh7pb4RZy+jI/PJPdkEhkUDOuhP9iakrX TH2g== X-Gm-Message-State: APt69E2twi7bPgS/0fuunBT33euBekDjv0sv1Q1S1E3Oar2ASXsup8pF u59mWeEodglW+jibQMvrCucsHA== X-Google-Smtp-Source: ADUXVKJhVdx46b/U2D39Cj7J+rUUH6dBIOqf2C42f8jErF9jc5nWE+2sPfohNQxU4EwZbKKXospB5Q== X-Received: by 2002:ac8:3fcd:: with SMTP id v13-v6mr6959356qtk.250.1529947166899; Mon, 25 Jun 2018 10:19:26 -0700 (PDT) Received: from smtp.gmail.com ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id m128-v6sm11232924qkd.33.2018.06.25.10.19.24 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 25 Jun 2018 10:19:26 -0700 (PDT) Date: Mon, 25 Jun 2018 14:19:22 -0300 From: Rodrigo Siqueira To: Gustavo Padovan , Sean Paul , Daniel Vetter , Haneen Mohammed Subject: [PATCH] drm/vkms: Add vblank events simulated by hrtimers Message-ID: <20180625171922.5ofev566kghxxxwu@smtp.gmail.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: NeoMutt/20180512 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dri-devel@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP This commit adds regular vblank events simulated through hrtimers, which is a feature required by VKMS to mimic real hardware. In this sense, this commit adopts a default frequency of 60Hz for vblank interval. Finally, this commit implements handlers for some of the atomic and vblank hooks. Signed-off-by: Rodrigo Siqueira --- Note: - This patch depends on the patchset "drm/vkms: Updates to meet basic kms_flip requirements" link: https://lists.freedesktop.org/archives/dri-devel/2018-June/180823.html drivers/gpu/drm/vkms/vkms_crtc.c | 90 +++++++++++++++++++++++++++++++- drivers/gpu/drm/vkms/vkms_drv.c | 6 +++ drivers/gpu/drm/vkms/vkms_drv.h | 9 ++++ 3 files changed, 103 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index 84cc05506b09..73aae129c37d 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -10,6 +10,52 @@ #include #include +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; + unsigned long flags; + int ret_overrun; + bool ret; + + ret = drm_crtc_handle_vblank(&output->crtc); + if (!ret) + DRM_ERROR("vkms failure on handling vblank"); + + spin_lock_irqsave(&crtc->dev->event_lock, flags); + if (output->event) { + drm_crtc_send_vblank_event(crtc, output->event); + drm_crtc_vblank_put(crtc); + output->event = NULL; + } + spin_unlock_irqrestore(&crtc->dev->event_lock, flags); + + ret_overrun = hrtimer_forward_now(&output->vblank_hrtimer, + output->period_ns); + + return HRTIMER_RESTART; +} + +static int vkms_enable_vblank(struct drm_crtc *crtc) +{ + struct vkms_output *out = drm_crtc_to_vkms_output(crtc); + + hrtimer_init(&out->vblank_hrtimer, CLOCK_REALTIME, HRTIMER_MODE_ABS); + out->vblank_hrtimer.function = &vkms_vblank_simulate; + out->period_ns = ktime_set(0, DEFAULT_VBLANK_NS); + hrtimer_start(&out->vblank_hrtimer, out->period_ns, HRTIMER_MODE_ABS); + + return 0; +} + +static void vkms_disable_vblank(struct drm_crtc *crtc) +{ + struct vkms_output *out = drm_crtc_to_vkms_output(crtc); + + hrtimer_cancel(&out->vblank_hrtimer); +} + static const struct drm_crtc_funcs vkms_crtc_funcs = { .set_config = drm_atomic_helper_set_config, .destroy = drm_crtc_cleanup, @@ -17,6 +63,8 @@ static const struct drm_crtc_funcs vkms_crtc_funcs = { .reset = drm_atomic_helper_crtc_reset, .atomic_duplicate_state = drm_atomic_helper_crtc_duplicate_state, .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, + .enable_vblank = vkms_enable_vblank, + .disable_vblank = vkms_disable_vblank, }; static int vkms_crtc_atomic_check(struct drm_crtc *crtc, @@ -27,12 +75,50 @@ static int vkms_crtc_atomic_check(struct drm_crtc *crtc, static void vkms_crtc_atomic_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state) +{ + drm_crtc_vblank_on(crtc); +} + +static void vkms_crtc_atomic_begin(struct drm_crtc *crtc, + struct drm_crtc_state *old_s) +{ + struct vkms_output *vkms_output = drm_crtc_to_vkms_output(crtc); + + if (crtc->state->event) { + crtc->state->event->pipe = drm_crtc_index(crtc); + WARN_ON(drm_crtc_vblank_get(crtc) != 0); + + vkms_output->event = crtc->state->event; + crtc->state->event = NULL; + } +} + +static void vkms_crtc_atomic_flush(struct drm_crtc *crtc, + struct drm_crtc_state *old_crtc_state) +{ + struct drm_pending_vblank_event *event = crtc->state->event; + + if (!event) + return; + + crtc->state->event = NULL; + + spin_lock_irq(&crtc->dev->event_lock); + if (drm_crtc_vblank_get(crtc)) + drm_crtc_send_vblank_event(crtc, event); + spin_unlock_irq(&crtc->dev->event_lock); +} + +static void vkms_crtc_commit(struct drm_crtc *crtc) { } static const struct drm_crtc_helper_funcs vkms_crtc_helper_funcs = { - .atomic_check = vkms_crtc_atomic_check, - .atomic_enable = vkms_crtc_atomic_enable, + .atomic_check = vkms_crtc_atomic_check, + .atomic_enable = vkms_crtc_atomic_enable, + .atomic_flush = vkms_crtc_atomic_flush, + .atomic_begin = vkms_crtc_atomic_begin, + .commit = vkms_crtc_commit, }; int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, diff --git a/drivers/gpu/drm/vkms/vkms_drv.c b/drivers/gpu/drm/vkms/vkms_drv.c index fe93f8c17997..c56d66d9ec56 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.c +++ b/drivers/gpu/drm/vkms/vkms_drv.c @@ -102,6 +102,12 @@ static int __init vkms_init(void) goto out_fini; } + ret = drm_vblank_init(&vkms_device->drm, 1); + if (ret) { + DRM_ERROR("Failed to vblank\n"); + goto out_fini; + } + ret = vkms_modeset_init(vkms_device); if (ret) goto out_unregister; diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 76f1720f81a5..f115e7d1ae03 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -5,6 +5,7 @@ #include #include #include +#include #define XRES_MIN 32 #define YRES_MIN 32 @@ -15,6 +16,8 @@ #define XRES_MAX 8192 #define YRES_MAX 8192 +#define DEFAULT_VBLANK_NS 16666666 + static const u32 vkms_formats[] = { DRM_FORMAT_XRGB8888, }; @@ -23,6 +26,9 @@ struct vkms_output { struct drm_crtc crtc; struct drm_encoder encoder; struct drm_connector connector; + struct hrtimer vblank_hrtimer; + ktime_t period_ns; + struct drm_pending_vblank_event *event; }; struct vkms_device { @@ -37,6 +43,9 @@ struct vkms_gem_object { struct page **pages; }; +#define drm_crtc_to_vkms_output(target) \ + container_of(target, struct vkms_output, crtc) + int vkms_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, struct drm_plane *primary, struct drm_plane *cursor);