From patchwork Fri Oct 31 22:54:36 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Steve Longerbeam X-Patchwork-Id: 5207431 Return-Path: X-Original-To: patchwork-dri-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 05A969F318 for ; Fri, 31 Oct 2014 23:57:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A93EE20120 for ; Fri, 31 Oct 2014 23:56:58 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.kernel.org (Postfix) with ESMTP id 641B520160 for ; Fri, 31 Oct 2014 23:56:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B13056E885; Fri, 31 Oct 2014 16:56:41 -0700 (PDT) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pa0-f49.google.com (mail-pa0-f49.google.com [209.85.220.49]) by gabe.freedesktop.org (Postfix) with ESMTP id 56A636E849 for ; Fri, 31 Oct 2014 15:57:32 -0700 (PDT) Received: by mail-pa0-f49.google.com with SMTP id lj1so8529261pab.22 for ; Fri, 31 Oct 2014 15:57:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=n+o2L7QdRMTKMWMnmxAI1+/erw3dK2PhfQ1fB8VC33M=; b=qH1gItL/dlJn8GN4jRj7AyfS2NvBZjR+mmPyB7Tx6yC/lg/INPU5YtY51yosaB4OxW yBGTPpzMzMgp30zD2FkIepqYk5TkdmDowu/gA8LH973VWY5KluICgPTQXY4lfEWzfRMi 2zeyW2GaUZClOW7clPrfIakXn/VeiI1ze8cPk+glBLNobNsbUL0Mfcn5mKLgwbdI7eBU V8/s7LTdY6l2azOwEymUyPdeWmo4eRHVCfyio9mD3klruxr+F6Z3yJp24aDmYLnM4KeN xQDS8rDy2EQwk8rKXsvpGTrEa7viLNbdQz7xU2+FCIoRl18xmRyDJVkjW36bou15LTw6 Vi6w== X-Received: by 10.70.96.162 with SMTP id dt2mr27758645pdb.29.1414796252205; Fri, 31 Oct 2014 15:57:32 -0700 (PDT) Received: from mothership.mgc.mentorg.com (c-50-152-159-227.hsd1.ca.comcast.net. [50.152.159.227]) by mx.google.com with ESMTPSA id ev8sm10870656pdb.28.2014.10.31.15.57.30 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Fri, 31 Oct 2014 15:57:31 -0700 (PDT) From: Steve Longerbeam X-Google-Original-From: Steve Longerbeam To: dri-devel@lists.freedesktop.org Subject: [PATCH 53/72] drm: implement page flipping support for planes Date: Fri, 31 Oct 2014 15:54:36 -0700 Message-Id: <1414796095-10107-54-git-send-email-steve_longerbeam@mentor.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1414796095-10107-1-git-send-email-steve_longerbeam@mentor.com> References: <1414796095-10107-1-git-send-email-steve_longerbeam@mentor.com> X-Mailman-Approved-At: Fri, 31 Oct 2014 16:56:32 -0700 Cc: Dmitry Eremin-Solenikov X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Spam-Status: No, score=-4.7 required=5.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, T_DKIM_INVALID, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Planes like crtcs would benefit from having page flip event support. With planes page flip it is now possible to synchronize changing a framebuffer used by an overlay (or even cursor) plane with vertical sync events. A page flip in the primary plane is equivalent to a crtc page flip, which suggests this ioctl could deprecate the crtc page flip ioctl at some point in the future. Signed-off-by: Steve Longerbeam Signed-off-by: Dmitry Eremin-Solenikov --- drivers/gpu/drm/drm_crtc.c | 241 +++++++++++++++++++++++++------------------ drivers/gpu/drm/drm_ioctl.c | 1 + include/drm/drm_crtc.h | 11 ++ include/uapi/drm/drm.h | 1 + include/uapi/drm/drm_mode.h | 8 ++ 5 files changed, 164 insertions(+), 98 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index e79c8d3..53b5f87 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -2445,6 +2445,142 @@ int drm_mode_setplane(struct drm_device *dev, void *data, plane_req->src_w, plane_req->src_h); } +int drm_mode_plane_page_flip_ioctl(struct drm_device *dev, + void *data, struct drm_file *file_priv) +{ + struct drm_mode_plane_page_flip *page_flip = data; + struct drm_plane *plane; + struct drm_crtc *crtc; + struct drm_framebuffer *fb = NULL; + struct drm_pending_vblank_event *e = NULL; + unsigned long flags; + bool is_primary; + int ret; + + if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS || + page_flip->reserved != 0) + return -EINVAL; + + if ((page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC) && + !dev->mode_config.async_page_flip) + return -EINVAL; + + plane = drm_plane_find(dev, page_flip->plane_id); + if (!plane) + return -ENOENT; + + is_primary = (plane->type == DRM_PLANE_TYPE_PRIMARY); + + drm_modeset_lock_all(dev); + + if (plane->crtc == NULL || plane->fb == NULL) { + /* The crtc and/or framebuffer is currently unbound, + * presumably due to a hotplug event, that userspace + * has not yet discovered. + */ + ret = -EBUSY; + goto out; + } + crtc = plane->crtc; + + if ((is_primary && crtc->funcs->page_flip == NULL) || + plane->funcs->page_flip == NULL) { + ret = -EINVAL; + goto out; + } + + fb = drm_framebuffer_lookup(dev, page_flip->fb_id); + if (!fb) { + ret = -ENOENT; + goto out; + } + + /* + * If this is the primary plane (equivalent to a crtc page flip), + * verify that the fb is valid for the bound crtc's viewport. + * For overlay or cursor planes, the plane's page_flip op should + * check that the fb is valid. + */ + if (is_primary) { + ret = drm_crtc_check_viewport(crtc, crtc->x, crtc->y, + &crtc->mode, fb); + if (ret) + goto out; + } + + if (plane->fb->pixel_format != fb->pixel_format) { + DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n"); + ret = -EINVAL; + goto out; + } + + if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { + ret = -ENOMEM; + spin_lock_irqsave(&dev->event_lock, flags); + if (file_priv->event_space < sizeof(e->event)) { + spin_unlock_irqrestore(&dev->event_lock, flags); + goto out; + } + file_priv->event_space -= sizeof(e->event); + spin_unlock_irqrestore(&dev->event_lock, flags); + + e = kzalloc(sizeof(*e), GFP_KERNEL); + if (e == NULL) { + spin_lock_irqsave(&dev->event_lock, flags); + file_priv->event_space += sizeof(e->event); + spin_unlock_irqrestore(&dev->event_lock, flags); + goto out; + } + + e->event.base.type = DRM_EVENT_FLIP_COMPLETE; + e->event.base.length = sizeof(e->event); + e->event.user_data = page_flip->user_data; + e->base.event = &e->event.base; + e->base.file_priv = file_priv; + e->base.destroy = + (void (*) (struct drm_pending_event *)) kfree; + } + + plane->old_fb = plane->fb; + + /* for now use crtc page_flip op, if this is the primary plane */ + if (is_primary) + ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags); + else + ret = plane->funcs->page_flip(plane, fb, e, page_flip->flags); + + if (ret) { + if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { + spin_lock_irqsave(&dev->event_lock, flags); + file_priv->event_space += sizeof(e->event); + spin_unlock_irqrestore(&dev->event_lock, flags); + kfree(e); + } + /* Keep the old fb, don't unref it. */ + plane->old_fb = NULL; + } else { + /* + * Warn if the driver hasn't properly updated the plane->fb + * field to reflect that the new framebuffer is now used. + * Failing to do so will screw with the reference counting + * on framebuffers. + */ + WARN_ON(plane->fb != fb); + /* Unref only the old framebuffer. */ + fb = NULL; + } + +out: + if (fb) + drm_framebuffer_unreference(fb); + if (plane->old_fb) + drm_framebuffer_unreference(plane->old_fb); + plane->old_fb = NULL; + drm_modeset_unlock_all(dev); + + return ret; +} + /** * drm_mode_set_config_internal - helper to call ->set_config * @set: modeset config to set @@ -4582,111 +4718,20 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv) { struct drm_mode_crtc_page_flip *page_flip = data; + struct drm_mode_plane_page_flip primary_pf = {0}; struct drm_crtc *crtc; - struct drm_framebuffer *fb = NULL; - struct drm_pending_vblank_event *e = NULL; - unsigned long flags; - int ret = -EINVAL; - - if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS || - page_flip->reserved != 0) - return -EINVAL; - - if ((page_flip->flags & DRM_MODE_PAGE_FLIP_ASYNC) && !dev->mode_config.async_page_flip) - return -EINVAL; crtc = drm_crtc_find(dev, page_flip->crtc_id); if (!crtc) return -ENOENT; - drm_modeset_lock_crtc(crtc); - if (crtc->primary->fb == NULL) { - /* The framebuffer is currently unbound, presumably - * due to a hotplug event, that userspace has not - * yet discovered. - */ - ret = -EBUSY; - goto out; - } - - if (crtc->funcs->page_flip == NULL) - goto out; - - fb = drm_framebuffer_lookup(dev, page_flip->fb_id); - if (!fb) { - ret = -ENOENT; - goto out; - } - - ret = drm_crtc_check_viewport(crtc, crtc->x, crtc->y, &crtc->mode, fb); - if (ret) - goto out; - - if (crtc->primary->fb->pixel_format != fb->pixel_format) { - DRM_DEBUG_KMS("Page flip is not allowed to change frame buffer format.\n"); - ret = -EINVAL; - goto out; - } - - if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { - ret = -ENOMEM; - spin_lock_irqsave(&dev->event_lock, flags); - if (file_priv->event_space < sizeof e->event) { - spin_unlock_irqrestore(&dev->event_lock, flags); - goto out; - } - file_priv->event_space -= sizeof e->event; - spin_unlock_irqrestore(&dev->event_lock, flags); - - e = kzalloc(sizeof *e, GFP_KERNEL); - if (e == NULL) { - spin_lock_irqsave(&dev->event_lock, flags); - file_priv->event_space += sizeof e->event; - spin_unlock_irqrestore(&dev->event_lock, flags); - goto out; - } - - e->event.base.type = DRM_EVENT_FLIP_COMPLETE; - e->event.base.length = sizeof e->event; - e->event.user_data = page_flip->user_data; - e->base.event = &e->event.base; - e->base.file_priv = file_priv; - e->base.destroy = - (void (*) (struct drm_pending_event *)) kfree; - } - - crtc->primary->old_fb = crtc->primary->fb; - ret = crtc->funcs->page_flip(crtc, fb, e, page_flip->flags); - if (ret) { - if (page_flip->flags & DRM_MODE_PAGE_FLIP_EVENT) { - spin_lock_irqsave(&dev->event_lock, flags); - file_priv->event_space += sizeof e->event; - spin_unlock_irqrestore(&dev->event_lock, flags); - kfree(e); - } - /* Keep the old fb, don't unref it. */ - crtc->primary->old_fb = NULL; - } else { - /* - * Warn if the driver hasn't properly updated the crtc->fb - * field to reflect that the new framebuffer is now used. - * Failing to do so will screw with the reference counting - * on framebuffers. - */ - WARN_ON(crtc->primary->fb != fb); - /* Unref only the old framebuffer. */ - fb = NULL; - } + primary_pf.plane_id = crtc->primary->base.id; + primary_pf.fb_id = page_flip->fb_id; + primary_pf.flags = page_flip->flags; + primary_pf.user_data = page_flip->user_data; -out: - if (fb) - drm_framebuffer_unreference(fb); - if (crtc->primary->old_fb) - drm_framebuffer_unreference(crtc->primary->old_fb); - crtc->primary->old_fb = NULL; - drm_modeset_unlock_crtc(crtc); - - return ret; + return drm_mode_plane_page_flip_ioctl(dev, (void *)&primary_pf, + file_priv); } /** diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c index 00587a1..2e60ee3 100644 --- a/drivers/gpu/drm/drm_ioctl.c +++ b/drivers/gpu/drm/drm_ioctl.c @@ -620,6 +620,7 @@ static const struct drm_ioctl_desc drm_ioctls[] = { DRM_IOCTL_DEF(DRM_IOCTL_MODE_OBJ_GETPROPERTIES, drm_mode_obj_get_properties_ioctl, DRM_CONTROL_ALLOW|DRM_UNLOCKED), DRM_IOCTL_DEF(DRM_IOCTL_MODE_OBJ_SETPROPERTY, drm_mode_obj_set_property_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), DRM_IOCTL_DEF(DRM_IOCTL_MODE_CURSOR2, drm_mode_cursor2_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), + DRM_IOCTL_DEF(DRM_IOCTL_MODE_PLANE_PAGE_FLIP, drm_mode_plane_page_flip_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), }; #define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls ) diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index c40070a..26d859b 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -571,6 +571,7 @@ struct drm_connector { * @disable_plane: shut down the plane * @destroy: clean up plane resources * @set_property: called when a property is changed + * @page_flip: initiate a page flip */ struct drm_plane_funcs { int (*update_plane)(struct drm_plane *plane, @@ -585,6 +586,14 @@ struct drm_plane_funcs { int (*set_property)(struct drm_plane *plane, struct drm_property *property, uint64_t val); + + /* + * See comment at drm_crtc_funcs.page_flip + */ + int (*page_flip)(struct drm_plane *plane, + struct drm_framebuffer *fb, + struct drm_pending_vblank_event *event, + uint32_t flags); }; enum drm_plane_type { @@ -1105,6 +1114,8 @@ extern bool drm_detect_monitor_audio(struct edid *edid); extern bool drm_rgb_quant_range_selectable(struct edid *edid); extern int drm_mode_page_flip_ioctl(struct drm_device *dev, void *data, struct drm_file *file_priv); +extern int drm_mode_plane_page_flip_ioctl(struct drm_device *dev, + void *data, struct drm_file *file_priv); extern int drm_add_modes_noedid(struct drm_connector *connector, int hdisplay, int vdisplay); extern void drm_set_preferred_mode(struct drm_connector *connector, diff --git a/include/uapi/drm/drm.h b/include/uapi/drm/drm.h index b0b8556..48d9da6 100644 --- a/include/uapi/drm/drm.h +++ b/include/uapi/drm/drm.h @@ -777,6 +777,7 @@ struct drm_prime_handle { #define DRM_IOCTL_MODE_OBJ_GETPROPERTIES DRM_IOWR(0xB9, struct drm_mode_obj_get_properties) #define DRM_IOCTL_MODE_OBJ_SETPROPERTY DRM_IOWR(0xBA, struct drm_mode_obj_set_property) #define DRM_IOCTL_MODE_CURSOR2 DRM_IOWR(0xBB, struct drm_mode_cursor2) +#define DRM_IOCTL_MODE_PLANE_PAGE_FLIP DRM_IOWR(0xBC, struct drm_mode_plane_page_flip) /** * Device specific ioctls should only be in their respective headers diff --git a/include/uapi/drm/drm_mode.h b/include/uapi/drm/drm_mode.h index a0db2d4a..8d98cd0 100644 --- a/include/uapi/drm/drm_mode.h +++ b/include/uapi/drm/drm_mode.h @@ -488,6 +488,14 @@ struct drm_mode_crtc_page_flip { __u64 user_data; }; +struct drm_mode_plane_page_flip { + __u32 plane_id; + __u32 fb_id; + __u32 flags; + __u32 reserved; + __u64 user_data; +}; + /* create a dumb scanout buffer */ struct drm_mode_create_dumb { uint32_t height;