From patchwork Tue Sep 4 16:35:56 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rob Clark X-Patchwork-Id: 11166 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 8433C23E00 for ; Tue, 4 Sep 2012 16:36:13 +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 593FDA18153 for ; Tue, 4 Sep 2012 16:35:22 +0000 (UTC) Received: by ieak11 with SMTP id k11so4953734iea.11 for ; Tue, 04 Sep 2012 09:36:12 -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=vxM+vkHFrkPynIvgxVV7USGNn1FlBE4mH4cx4V/UA8c=; b=Nr5qRaUzKSSSVSpcmOoLjJIcKhe08ZbutLpuFt+59ot5QSSHdVzi/G24u4eBoHoYkw 2f+VXkOBjlg2JnXxyt3Ldg90CQv57gTRVTGSQylx0WIOMuSbHMzng6A0pZMrbnUQjNrz ImU+IIMlg9PbwKiT6lW8XXFYdQe+T9AaLjrDqcUKgelQR/svR5eqzZ4Y8UVPlRgWNyLO Zd/Y74MCGf8lBIoEyxHmNgFPZ/5LeGn0a96EENlv4EKUPz/DUv8BLmEneTbMOr9KMJoM azMeAA090Q5QVaN+6TGJtFOQViidHtuLeXP7xiJHCFrHRoMrpx4RcPimwQEDmyIdthXH kpgg== Received: by 10.50.191.227 with SMTP id hb3mr4816242igc.43.1346776572279; Tue, 04 Sep 2012 09:36:12 -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.184.232 with SMTP id ex8csp201134igc; Tue, 4 Sep 2012 09:36:11 -0700 (PDT) Received: by 10.236.190.163 with SMTP id e23mr18512452yhn.36.1346776571093; Tue, 04 Sep 2012 09:36:11 -0700 (PDT) Received: from mail-gh0-f178.google.com (mail-gh0-f178.google.com [209.85.160.178]) by mx.google.com with ESMTPS id g20si6211026ani.182.2012.09.04.09.36.08 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 04 Sep 2012 09:36:11 -0700 (PDT) Received-SPF: pass (google.com: domain of robdclark@gmail.com designates 209.85.160.178 as permitted sender) client-ip=209.85.160.178; Authentication-Results: mx.google.com; spf=pass (google.com: domain of robdclark@gmail.com designates 209.85.160.178 as permitted sender) smtp.mail=robdclark@gmail.com; dkim=pass header.i=@gmail.com Received: by ghbf1 with SMTP id f1so1290621ghb.37 for ; Tue, 04 Sep 2012 09:36:08 -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=vxM+vkHFrkPynIvgxVV7USGNn1FlBE4mH4cx4V/UA8c=; b=fq6L/wU8/A3fa2os2nuApU8BkKRGVjxzO0aLTzreAyi/N0LJWAXRbfb18OtALa2Rzc 4KrmZlFJ5GP89/NyUsyCV8OJaJunlBIqr1KhHQxj1U13wGVjWWPNrOr/b/Eb9RC5btRM 47tYRZ+sPb29iUnkRKPQeD4hns+iNrp5rwNPNrhQyQ38Sp8fdYr7NcHY4MlGQbsbE5wW Xd/8JBGGh2acSYqpvld9609RLJWNTmddLhtdN6w+u/GxI2CUarvO47QkWyyNyVk/W/s5 AC1d4Cj+S47DVRRXucuKk0WFljbzFSnrKzZU/l2/yDoVtvSwLVU0ub2ZNb5dssMJxVvq 0XAA== Received: by 10.236.161.165 with SMTP id w25mr18920016yhk.22.1346776568681; Tue, 04 Sep 2012 09:36:08 -0700 (PDT) Received: from localhost (ppp-70-129-131-42.dsl.rcsntx.swbell.net. [70.129.131.42]) by mx.google.com with ESMTPS id v8sm30657606yhi.15.2012.09.04.09.36.06 (version=TLSv1/SSLv3 cipher=OTHER); Tue, 04 Sep 2012 09:36:07 -0700 (PDT) Sender: Rob Clark From: Rob Clark To: dri-devel@lists.freedesktop.org, linux-omap@vger.kernel.org Cc: patches@linaro.org, Greg KH , Tomi Valkeinen , Andy Gross , =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= , Rob Clark Subject: [PATCH 1/2] drm: support for rotated scanout Date: Tue, 4 Sep 2012 11:35:56 -0500 Message-Id: <1346776556-13098-1-git-send-email-rob.clark@linaro.org> X-Mailer: git-send-email 1.7.9.5 X-Gm-Message-State: ALoCoQkR66z5mXHUDRH5Atq/sRGR/Ushhvi6zekQSZtglNJS1mn1mLKDbaNX/7KNVs9J5jQCwt1I From: Rob Clark For drivers that can support rotated scanout, the extra parameter checking in drm-core, while nice, tends to get confused. To solve this drivers can set the crtc or plane invert_dimensions field so that the dimension checking takes into account the rotation that the driver is performing. v1: original v2: remove invert_dimensions from plane, at Ville's suggestion. Userspace can give rotated src coordinates, so invert_dimensions is not required for planes. Signed-off-by: Rob Clark Reviewed-by: Ville Syrjälä --- drivers/gpu/drm/drm_crtc.c | 46 +++++++++++++++++++++++++++++--------------- include/drm/drm_crtc.h | 5 +++++ 2 files changed, 35 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 08a7aa7..901de9a 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -377,6 +377,7 @@ int drm_crtc_init(struct drm_device *dev, struct drm_crtc *crtc, crtc->dev = dev; crtc->funcs = funcs; + crtc->invert_dimensions = false; mutex_lock(&dev->mode_config.mutex); @@ -1852,6 +1853,7 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, DRM_DEBUG_KMS("[CRTC:%d]\n", crtc->base.id); if (crtc_req->mode_valid) { + int hdisplay, vdisplay; /* If we have a mode we need a framebuffer. */ /* If we pass -1, set the mode with the currently bound fb */ if (crtc_req->fb_id == -1) { @@ -1887,14 +1889,20 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); - if (mode->hdisplay > fb->width || - mode->vdisplay > fb->height || - crtc_req->x > fb->width - mode->hdisplay || - crtc_req->y > fb->height - mode->vdisplay) { - DRM_DEBUG_KMS("Invalid CRTC viewport %ux%u+%u+%u for fb size %ux%u.\n", - mode->hdisplay, mode->vdisplay, - crtc_req->x, crtc_req->y, - fb->width, fb->height); + hdisplay = mode->hdisplay; + vdisplay = mode->vdisplay; + + if (crtc->invert_dimensions) + swap(hdisplay, vdisplay); + + if (hdisplay > fb->width || + vdisplay > fb->height || + crtc_req->x > fb->width - hdisplay || + crtc_req->y > fb->height - vdisplay) { + DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n", + fb->width, fb->height, + hdisplay, vdisplay, crtc_req->x, crtc_req->y, + crtc->invert_dimensions ? " (inverted)" : ""); ret = -ENOSPC; goto out; } @@ -3489,6 +3497,7 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, struct drm_framebuffer *fb; struct drm_pending_vblank_event *e = NULL; unsigned long flags; + int hdisplay, vdisplay; int ret = -EINVAL; if (page_flip->flags & ~DRM_MODE_PAGE_FLIP_FLAGS || @@ -3518,14 +3527,19 @@ int drm_mode_page_flip_ioctl(struct drm_device *dev, goto out; fb = obj_to_fb(obj); - if (crtc->mode.hdisplay > fb->width || - crtc->mode.vdisplay > fb->height || - crtc->x > fb->width - crtc->mode.hdisplay || - crtc->y > fb->height - crtc->mode.vdisplay) { - DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d.\n", - fb->width, fb->height, - crtc->mode.hdisplay, crtc->mode.vdisplay, - crtc->x, crtc->y); + hdisplay = crtc->mode.hdisplay; + vdisplay = crtc->mode.vdisplay; + + if (crtc->invert_dimensions) + swap(hdisplay, vdisplay); + + if (hdisplay > fb->width || + vdisplay > fb->height || + crtc->x > fb->width - hdisplay || + crtc->y > fb->height - vdisplay) { + DRM_DEBUG_KMS("Invalid fb size %ux%u for CRTC viewport %ux%u+%d+%d%s.\n", + fb->width, fb->height, hdisplay, vdisplay, crtc->x, crtc->y, + crtc->invert_dimensions ? " (inverted)" : ""); ret = -ENOSPC; goto out; } diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h index ced3625..7ba9b39 100644 --- a/include/drm/drm_crtc.h +++ b/include/drm/drm_crtc.h @@ -358,6 +358,9 @@ struct drm_crtc_funcs { * @enabled: is this CRTC enabled? * @mode: current mode timings * @hwmode: mode timings as programmed to hw regs + * @invert_dimensions: for purposes of error checking crtc vs fb sizes, + * invert the width/height of the crtc. This is used if the driver + * is performing 90 or 270 degree rotated scanout * @x: x position on screen * @y: y position on screen * @funcs: CRTC control functions @@ -391,6 +394,8 @@ struct drm_crtc { */ struct drm_display_mode hwmode; + bool invert_dimensions; + int x, y; const struct drm_crtc_funcs *funcs;