From patchwork Wed Jun 27 21:24:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Haneen Mohammed X-Patchwork-Id: 10493303 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 E943C60325 for ; Thu, 28 Jun 2018 08:23:29 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D27A629EEB for ; Thu, 28 Jun 2018 08:23:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C6BC329EFC; Thu, 28 Jun 2018 08:23:29 +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 6207529EEB for ; Thu, 28 Jun 2018 08:23:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0AB0C6EC7F; Thu, 28 Jun 2018 08:22:56 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x22b.google.com (mail-wm0-x22b.google.com [IPv6:2a00:1450:400c:c09::22b]) by gabe.freedesktop.org (Postfix) with ESMTPS id 205E56E8DD for ; Wed, 27 Jun 2018 21:24:43 +0000 (UTC) Received: by mail-wm0-x22b.google.com with SMTP id v16-v6so7346746wmv.5 for ; Wed, 27 Jun 2018 14:24:43 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=YkbIKvvtblazfCwI1+donEstXvaVrIOYVXHWkLsDVBk=; b=mixStA2QziX91o21w+7ecFr18d6H7mDPSZuJL6pGy5l88/x4NVPovW0JXHj5jeooUu EFwRX58EvDwdKFPxh3nvkG0xLyIfg+55crO3CQiPBaP+PX9GlOOSjRy6Oi2du8ZN/Anf fSyLvB9Byt1JvSxrKVslOS3KA9541U+mcONrH07XiwaxtQ5pDw85DI/jVaAG8IVRKye5 AIhEm6FiTLu5gNFzg0BaZi4LbjCdjB+BXgVsZGEzNmiGfvmf6BrKMkPMmKpFyqcNsfAg YN06jm0eKdPeskkK5aMuz8VwPErgJTc4I0DQ8r0ZePf3vEspbJ38SuMj6zhI1D7X8BLf 2InQ== X-Gm-Message-State: APt69E1gck3jS+2zW66jm2Xs9fW6WGcWM/MXwebi3y2pn4a77wmwpGxD GHMB37icRoQ2lEvwYcqMrZj4h//L X-Google-Smtp-Source: AAOMgpdg3+xdEg/Z1IgNJm6zEyPZ1MoOmYY2ig7DZN/9iOzsUDNs18tI+ThcnGt9BOThVz6+ufBEBg== X-Received: by 2002:a1c:4442:: with SMTP id r63-v6mr5092155wma.128.1530134681330; Wed, 27 Jun 2018 14:24:41 -0700 (PDT) Received: from haneen-vb ([78.180.222.80]) by smtp.gmail.com with ESMTPSA id h7-v6sm3608584wmb.48.2018.06.27.14.24.39 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 27 Jun 2018 14:24:40 -0700 (PDT) Date: Thu, 28 Jun 2018 00:24:35 +0300 From: Haneen Mohammed To: dri-devel@lists.freedesktop.org Subject: [RFC 3/3] drm/vkms: Implement CRC debugfs API Message-ID: <0fa6a92c613087705bd8c6f7131cdaf3b1d0c8c2.1530133610.git.hamohammed.sa@gmail.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.4 (2018-02-28) X-Mailman-Approved-At: Thu, 28 Jun 2018 08:22:06 +0000 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: hamohammed.sa@gmail.com, rodrigosiqueiramelo@gmail.com Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Implement the .set_crc_source() callback. Compute CRC using crc32 on the visible part of the framebuffer. Use work_struct to compute and add CRC at the end of a vblank. Signed-off-by: Haneen Mohammed --- drivers/gpu/drm/vkms/vkms_crtc.c | 76 ++++++++++++++++++++++++++++++++ drivers/gpu/drm/vkms/vkms_drv.h | 16 +++++++ 2 files changed, 92 insertions(+) diff --git a/drivers/gpu/drm/vkms/vkms_crtc.c b/drivers/gpu/drm/vkms/vkms_crtc.c index 73aae129c37d..d78934b76e33 100644 --- a/drivers/gpu/drm/vkms/vkms_crtc.c +++ b/drivers/gpu/drm/vkms/vkms_crtc.c @@ -7,8 +7,78 @@ */ #include "vkms_drv.h" +#include #include #include +#include + +uint32_t _vkms_get_crc(struct drm_framebuffer *fb) +{ + struct drm_gem_object *gem_obj = drm_gem_fb_get_obj(fb, 0); + struct vkms_gem_object *vkms_obj = container_of(gem_obj, + struct vkms_gem_object, + gem); + u32 crc = 0; + int i = 0; + struct drm_plane_state *state = vkms_obj->plane_state; + unsigned int x = state->src.x1 >> 16; + unsigned int y = state->src.y1 >> 16; + unsigned int height = drm_rect_height(&state->src) >> 16; + unsigned int width = drm_rect_width(&state->src) >> 16; + unsigned int cpp = fb->format->cpp[0]; + unsigned int src_offset; + unsigned int size_byte = width * cpp; + void *vaddr = vkms_obj->vaddr; + + if (WARN_ON(!vaddr)) + return crc; + + for (i = y; i < y + height; i++) { + src_offset = fb->offsets[0] + (i * fb->pitches[0]) + (x * cpp); + crc = crc32_le(crc, vaddr + src_offset, size_byte); + } + + return crc; +} + +void vkms_crc_work_handle(struct work_struct *work) +{ + struct vkms_crtc_state *crtc_state = container_of(work, + struct vkms_crtc_state, + crc_workq); + struct drm_crtc *crtc = crtc_state->crtc; + struct drm_framebuffer *fb = (crtc->primary ? crtc->primary->fb : NULL); + + if (crtc_state->crc_enabled && fb) { + u32 crc32 = _vkms_get_crc(fb); + unsigned int n_frame = drm_crtc_accurate_vblank_count(crtc); + + drm_crtc_add_crc_entry(crtc, true, n_frame, &crc32); + } +} + +static int vkms_set_crc_source(struct drm_crtc *crtc, const char *src_name, + size_t *values_cnt) +{ + struct drm_device *dev = crtc->dev; + struct vkms_device *vkms_dev = container_of(dev, + struct vkms_device, + drm); + struct vkms_crtc_state *crtc_state = &vkms_dev->output.crtc_state; + + if (!src_name) { + crtc_state->crc_enabled = false; + } else if (strcmp(src_name, "auto") == 0) { + crtc_state->crc_enabled = true; + } else { + crtc_state->crc_enabled = false; + return -EINVAL; + } + + *values_cnt = 1; + + return 0; +} static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) { @@ -23,6 +93,8 @@ static enum hrtimer_restart vkms_vblank_simulate(struct hrtimer *timer) if (!ret) DRM_ERROR("vkms failure on handling vblank"); + vkms_crc_work_handle(&output->crtc_state.crc_workq); + spin_lock_irqsave(&crtc->dev->event_lock, flags); if (output->event) { drm_crtc_send_vblank_event(crtc, output->event); @@ -46,6 +118,9 @@ static int vkms_enable_vblank(struct drm_crtc *crtc) out->period_ns = ktime_set(0, DEFAULT_VBLANK_NS); hrtimer_start(&out->vblank_hrtimer, out->period_ns, HRTIMER_MODE_ABS); + out->crtc_state.crtc = crtc; + INIT_WORK(&out->crtc_state.crc_workq, vkms_crc_work_handle); + return 0; } @@ -65,6 +140,7 @@ static const struct drm_crtc_funcs vkms_crtc_funcs = { .atomic_destroy_state = drm_atomic_helper_crtc_destroy_state, .enable_vblank = vkms_enable_vblank, .disable_vblank = vkms_disable_vblank, + .set_crc_source = vkms_set_crc_source, }; static int vkms_crtc_atomic_check(struct drm_crtc *crtc, diff --git a/drivers/gpu/drm/vkms/vkms_drv.h b/drivers/gpu/drm/vkms/vkms_drv.h index 300e6a05d473..4a1458731dd7 100644 --- a/drivers/gpu/drm/vkms/vkms_drv.h +++ b/drivers/gpu/drm/vkms/vkms_drv.h @@ -22,6 +22,18 @@ static const u32 vkms_formats[] = { DRM_FORMAT_XRGB8888, }; +/** + * struct vkms_crtc_state + * @crtc: backpointer to the CRTC + * @crc_workq: worker that captures CRCs for each frame + * @crc_enabled: flag to test if crc is enabled + */ +struct vkms_crtc_state { + struct drm_crtc *crtc; + struct work_struct crc_workq; + bool crc_enabled; +}; + struct vkms_output { struct drm_crtc crtc; struct drm_encoder encoder; @@ -29,6 +41,7 @@ struct vkms_output { struct hrtimer vblank_hrtimer; ktime_t period_ns; struct drm_pending_vblank_event *event; + struct vkms_crtc_state crtc_state; }; struct vkms_device { @@ -55,6 +68,9 @@ int vkms_output_init(struct vkms_device *vkmsdev); struct drm_plane *vkms_plane_init(struct vkms_device *vkmsdev); +/* CRC Support */ +void vkms_crc_work_handle(struct work_struct *work); + /* Gem stuff */ struct drm_gem_object *vkms_gem_create(struct drm_device *dev, struct drm_file *file,