From patchwork Fri Oct 12 23:57:12 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 12194 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 8553723E29 for ; Fri, 12 Oct 2012 23:57:22 +0000 (UTC) Received: from mail-ie0-f180.google.com (mail-ie0-f180.google.com [209.85.223.180]) by fiordland.canonical.com (Postfix) with ESMTP id 18176A182C7 for ; Fri, 12 Oct 2012 23:57:21 +0000 (UTC) Received: by mail-ie0-f180.google.com with SMTP id e10so5474890iej.11 for ; Fri, 12 Oct 2012 16:57:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :dkim-signature:sender:from:to:cc:subject:date:message-id:x-mailer :x-gm-message-state; bh=WFyaBZIGk6CQTGsX5J/nDu5bXqeQroMyDMyVimewwZQ=; b=UZsV/aI0csP5ExoOJqTTr47UZFDbJqJ2TGR6H0yue2LXm4hawSxb9f3PqJl0U9FqrW dzNkU7OaUEx01Mdl0AEuHxgdeELILwGHi/W2wgW4TeTrsWfPOFTLop0oATrvNEkObdp/ ESqn2BxnxuvLzlks9atlRJRVp/vme5uyVZ+adnFmyOrIx0Av1ULuXcyctF29Fbs2+8Eo i0PW/i4Z/L21mQ4RZn5NxJyFPKGi4UiVDjUMbRBWLFFIo7riwzR9nUavpXmblYjzspei mf8rrhcBMZbJds5MwHjOiQ8ONHnizL5vYsQ8rQxB8XhgXiv8bCVbsk72UA+n86mtlKyy 27nQ== Received: by 10.50.87.134 with SMTP id ay6mr3528607igb.70.1350086241443; Fri, 12 Oct 2012 16:57:21 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.50.67.148 with SMTP id n20csp270519igt; Fri, 12 Oct 2012 16:57:20 -0700 (PDT) Received: by 10.60.10.67 with SMTP id g3mr4719356oeb.51.1350086240581; Fri, 12 Oct 2012 16:57:20 -0700 (PDT) Received: from mail-oa0-f50.google.com (mail-oa0-f50.google.com [209.85.219.50]) by mx.google.com with ESMTPS id d7si15931oea.27.2012.10.12.16.57.20 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 12 Oct 2012 16:57:20 -0700 (PDT) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.219.50 as permitted sender) client-ip=209.85.219.50; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.219.50 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by mail-oa0-f50.google.com with SMTP id n16so4185192oag.37 for ; Fri, 12 Oct 2012 16:57:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:x-mailer; bh=WFyaBZIGk6CQTGsX5J/nDu5bXqeQroMyDMyVimewwZQ=; b=PPxvIPv11w9yYIaCj6w3VPoMmwdzOaHpuXhaeXNnuxpJyNyOpmN3f1T9fxgaewBhgv CPR0qalZ4IQndaaVoz1ZOEVQyhQIcbKQVveTX+aILSLNmleQ0L12AiKnt8ni46kodn4g U5nbhCYRR62aymdHPfbmZYH05PXiOJDLTTQMrxu24t2TqHnDe0C8/ePUzphZ9NpAi6db hGc/dwIdIH7cbaK8fhaGayPz9VnFKU/zH4ZSm74jqJvUa/QNpnhWvoIPTuDXnW+e8WEf 6P7G7xaru/CFawHINlwPg2RTbprpIOEBGPAj6EXXe6p+U0khvBHS6V5JsIuBnsQ3ZtW9 c6jQ== Received: by 10.60.26.98 with SMTP id k2mr4724284oeg.34.1350086240285; Fri, 12 Oct 2012 16:57:20 -0700 (PDT) Received: from localhost (ppp-70-129-143-201.dsl.rcsntx.swbell.net. [70.129.143.201]) by mx.google.com with ESMTPS id h13sm8123090obp.2.2012.10.12.16.57.18 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 12 Oct 2012 16:57:19 -0700 (PDT) Sender: Rob Clark From: Rob Clark To: dri-devel@lists.freedesktop.org Cc: patches@linaro.org, airlied@linux.ie, daniel.vetter@ffwll.ch, bskeggs@redhat.com, inki.dae@samsung.com, laurent.pinchart@ideasonboard.com, s.hauer@pengutronix.de, gregkh@linuxfoundation.org, marcin.slusarz@gmail.com, Rob Clark Subject: [PATCH 0/11] drm: add drm_send_vblank_event() helper (v4) Date: Fri, 12 Oct 2012 18:57:12 -0500 Message-Id: <1350086233-12426-1-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQldlvzWGmGyKPIZXlEpRdr0z7G9RB5Qatl7+MJhJFCsZnB04tKdoaQV0DhRTdRK0kBEgXL7 From: Rob Clark A helper that drivers can use to send vblank event after a pageflip. If the driver doesn't support proper vblank irq based time/seqn then just pass -1 for the pipe # to get do_gettimestamp() behavior (since there are a lot of drivers that don't use drm_vblank_count_and_time()) Also an internal send_vblank_event() helper for the various other code paths within drm_irq that also need to send vblank events. v1: original v2: add back 'vblwait->reply.sequence = seq' which should not have been deleted v3: add WARN_ON() in case lock is not held and comments v4: use WARN_ON_SMP() instead to fix issue with !SMP && !DEBUG_SPINLOCK as pointed out by Marcin Slusarz Signed-off-by: Rob Clark --- drivers/gpu/drm/drm_irq.c | 74 +++++++++++++++++++++++++++++++-------------- include/drm/drmP.h | 2 ++ 2 files changed, 54 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/drm_irq.c b/drivers/gpu/drm/drm_irq.c index 076c4a8..9bdcfd5 100644 --- a/drivers/gpu/drm/drm_irq.c +++ b/drivers/gpu/drm/drm_irq.c @@ -802,6 +802,46 @@ u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc, } EXPORT_SYMBOL(drm_vblank_count_and_time); +static void send_vblank_event(struct drm_device *dev, + struct drm_pending_vblank_event *e, + unsigned long seq, struct timeval *now) +{ + WARN_ON_SMP(!spin_is_locked(&dev->event_lock)); + e->event.sequence = seq; + e->event.tv_sec = now->tv_sec; + e->event.tv_usec = now->tv_usec; + + list_add_tail(&e->base.link, + &e->base.file_priv->event_list); + wake_up_interruptible(&e->base.file_priv->event_wait); + trace_drm_vblank_event_delivered(e->base.pid, e->pipe, + e->event.sequence); +} + +/** + * drm_send_vblank_event - helper to send vblank event after pageflip + * @dev: DRM device + * @crtc: CRTC in question + * @e: the event to send + * + * Updates sequence # and timestamp on event, and sends it to userspace. + * Caller must hold event lock. + */ +void drm_send_vblank_event(struct drm_device *dev, int crtc, + struct drm_pending_vblank_event *e) +{ + struct timeval now; + unsigned int seq; + if (crtc >= 0) { + seq = drm_vblank_count_and_time(dev, crtc, &now); + } else { + seq = 0; + do_gettimeofday(&now); + } + send_vblank_event(dev, e, seq, &now); +} +EXPORT_SYMBOL(drm_send_vblank_event); + /** * drm_update_vblank_count - update the master vblank counter * @dev: DRM device @@ -936,6 +976,13 @@ void drm_vblank_put(struct drm_device *dev, int crtc) } EXPORT_SYMBOL(drm_vblank_put); +/** + * drm_vblank_off - disable vblank events on a CRTC + * @dev: DRM device + * @crtc: CRTC in question + * + * Caller must hold event lock. + */ void drm_vblank_off(struct drm_device *dev, int crtc) { struct drm_pending_vblank_event *e, *t; @@ -955,15 +1002,9 @@ void drm_vblank_off(struct drm_device *dev, int crtc) DRM_DEBUG("Sending premature vblank event on disable: \ wanted %d, current %d\n", e->event.sequence, seq); - - e->event.sequence = seq; - e->event.tv_sec = now.tv_sec; - e->event.tv_usec = now.tv_usec; + list_del(&e->base.link); drm_vblank_put(dev, e->pipe); - list_move_tail(&e->base.link, &e->base.file_priv->event_list); - wake_up_interruptible(&e->base.file_priv->event_wait); - trace_drm_vblank_event_delivered(e->base.pid, e->pipe, - e->event.sequence); + send_vblank_event(dev, e, seq, &now); } spin_unlock_irqrestore(&dev->vbl_lock, irqflags); @@ -1107,15 +1148,9 @@ static int drm_queue_vblank_event(struct drm_device *dev, int pipe, e->event.sequence = vblwait->request.sequence; if ((seq - vblwait->request.sequence) <= (1 << 23)) { - e->event.sequence = seq; - e->event.tv_sec = now.tv_sec; - e->event.tv_usec = now.tv_usec; drm_vblank_put(dev, pipe); - list_add_tail(&e->base.link, &e->base.file_priv->event_list); - wake_up_interruptible(&e->base.file_priv->event_wait); + send_vblank_event(dev, e, seq, &now); vblwait->reply.sequence = seq; - trace_drm_vblank_event_delivered(current->pid, pipe, - vblwait->request.sequence); } else { /* drm_handle_vblank_events will call drm_vblank_put */ list_add_tail(&e->base.link, &dev->vblank_event_list); @@ -1256,14 +1291,9 @@ static void drm_handle_vblank_events(struct drm_device *dev, int crtc) DRM_DEBUG("vblank event on %d, current %d\n", e->event.sequence, seq); - e->event.sequence = seq; - e->event.tv_sec = now.tv_sec; - e->event.tv_usec = now.tv_usec; + list_del(&e->base.link); drm_vblank_put(dev, e->pipe); - list_move_tail(&e->base.link, &e->base.file_priv->event_list); - wake_up_interruptible(&e->base.file_priv->event_wait); - trace_drm_vblank_event_delivered(e->base.pid, e->pipe, - e->event.sequence); + send_vblank_event(dev, e, seq, &now); } spin_unlock_irqrestore(&dev->event_lock, flags); diff --git a/include/drm/drmP.h b/include/drm/drmP.h index 05af0e7..ee8f927 100644 --- a/include/drm/drmP.h +++ b/include/drm/drmP.h @@ -1437,6 +1437,8 @@ extern int drm_vblank_wait(struct drm_device *dev, unsigned int *vbl_seq); extern u32 drm_vblank_count(struct drm_device *dev, int crtc); extern u32 drm_vblank_count_and_time(struct drm_device *dev, int crtc, struct timeval *vblanktime); +extern void drm_send_vblank_event(struct drm_device *dev, int crtc, + struct drm_pending_vblank_event *e); extern bool drm_handle_vblank(struct drm_device *dev, int crtc); extern int drm_vblank_get(struct drm_device *dev, int crtc); extern void drm_vblank_put(struct drm_device *dev, int crtc);