From patchwork Fri Jan 12 06:21:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Nautiyal, Ankit K" X-Patchwork-Id: 10159657 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 172116029B for ; Fri, 12 Jan 2018 06:25:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 043D428802 for ; Fri, 12 Jan 2018 06:25:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECD5628814; Fri, 12 Jan 2018 06:25:47 +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=-4.2 required=2.0 tests=BAYES_00, 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 3DF8E28802 for ; Fri, 12 Jan 2018 06:25:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B748E6E706; Fri, 12 Jan 2018 06:25:45 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 698736E706 for ; Fri, 12 Jan 2018 06:25:44 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga103.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Jan 2018 22:25:43 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,347,1511856000"; d="scan'208";a="166167652" Received: from ankit-desktop.iind.intel.com ([10.223.161.14]) by orsmga004.jf.intel.com with ESMTP; 11 Jan 2018 22:25:40 -0800 From: "Nautiyal, Ankit K" To: dri-devel@lists.freedesktop.org Subject: [PATCH v3 5/8] drm: Handle aspect ratio info in atomic and legacy modeset paths Date: Fri, 12 Jan 2018 11:51:33 +0530 Message-Id: <1515738096-16892-6-git-send-email-ankit.k.nautiyal@intel.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1515738096-16892-1-git-send-email-ankit.k.nautiyal@intel.com> References: <1515738096-16892-1-git-send-email-ankit.k.nautiyal@intel.com> Cc: Ankit Nautiyal 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-Virus-Scanned: ClamAV using ClamSMTP From: Ankit Nautiyal If the user mode does not support aspect-ratio, and requests for a modeset, then the flag bits representing aspect ratio in the given user-mode must be rejected. Similarly, while preparing a user-mode from kernel mode, the aspect-ratio info must not be given, if aspect-ratio is not supported by the user. This patch: 1. adds a new bit field aspect_ratio_allowed in drm_atomic_state, which is set only if the aspect-ratio is supported by the user. 2. discards the aspect-ratio info from the user mode while preparing kernel mode structure, during modeset, if the user does not support aspect ratio. 3. avoids setting the aspect-ratio info in user-mode, while converting user-mode from the kernel-mode. Signed-off-by: Ankit Nautiyal V3: Addressed review comments from Ville: -Do not corrupt the current crtc state by updating aspect ratio on the fly. --- drivers/gpu/drm/drm_atomic.c | 61 +++++++++++++++++++++++++++++++++++++++++--- drivers/gpu/drm/drm_crtc.c | 19 ++++++++++++++ include/drm/drm_atomic.h | 2 ++ 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 69ff763..39313e2 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -316,6 +316,35 @@ static s32 __user *get_out_fence_for_crtc(struct drm_atomic_state *state, return fence_ptr; } +/** + * drm_atomic_allow_aspect_ratio_for_kmode + * @state: the crtc state + * @mode: kernel-internal mode, which is used to create a duplicate mode, + * with updated picture aspect ratio. + * + * Allow the aspect ratio info in the kernel mode only if aspect ratio is + * supported. + * + * RETURNS: + * kernel-internal mode with updated picture aspect ratio value. + */ + +struct drm_display_mode* +drm_atomic_allow_aspect_ratio_for_kmode(struct drm_crtc_state *state, + const struct drm_display_mode *mode) +{ + struct drm_atomic_state *atomic_state = state->state; + struct drm_display_mode *ar_kmode; + + ar_kmode = drm_mode_duplicate(state->crtc->dev, mode); + /* + * If aspect ratio is not supported, set the picture aspect ratio as + * NONE. + */ + if (atomic_state && !atomic_state->allow_aspect_ratio) + ar_kmode->picture_aspect_ratio = HDMI_PICTURE_ASPECT_NONE; + return ar_kmode; +} /** * drm_atomic_set_mode_for_crtc - set mode for CRTC @@ -341,7 +370,10 @@ int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state, state->mode_blob = NULL; if (mode) { - drm_mode_convert_to_umode(&umode, mode); + struct drm_display_mode *ar_mode; + + ar_mode = drm_atomic_allow_aspect_ratio_for_kmode(state, mode); + drm_mode_convert_to_umode(&umode, ar_mode); state->mode_blob = drm_property_create_blob(state->crtc->dev, sizeof(umode), @@ -349,10 +381,11 @@ int drm_atomic_set_mode_for_crtc(struct drm_crtc_state *state, if (IS_ERR(state->mode_blob)) return PTR_ERR(state->mode_blob); - drm_mode_copy(&state->mode, mode); + drm_mode_copy(&state->mode, ar_mode); state->enable = true; DRM_DEBUG_ATOMIC("Set [MODE:%s] for CRTC state %p\n", - mode->name, state); + ar_mode->name, state); + drm_mode_destroy(state->crtc->dev, ar_mode); } else { memset(&state->mode, 0, sizeof(state->mode)); state->enable = false; @@ -436,6 +469,25 @@ drm_atomic_replace_property_blob_from_id(struct drm_device *dev, } /** + * drm_atomic_allow_aspect_ratio_for_umode + * @state: the crtc state + * @umode: userspace mode, whose aspect ratio flag bits are to be updated. + * + * Allow the aspect ratio info in the userspace mode only if aspect ratio is + * supported. + */ +void +drm_atomic_allow_aspect_ratio_for_umode(struct drm_crtc_state *state, + struct drm_mode_modeinfo *umode) +{ + struct drm_atomic_state *atomic_state = state->state; + + /* Reset the aspect ratio flags if aspect ratio is not supported */ + if (atomic_state && !atomic_state->allow_aspect_ratio) + umode->flags &= (~DRM_MODE_FLAG_PIC_AR_MASK); +} + +/** * drm_atomic_crtc_set_property - set property on CRTC * @crtc: the drm CRTC to set a property on * @state: the state object to update with the new property value @@ -464,6 +516,9 @@ int drm_atomic_crtc_set_property(struct drm_crtc *crtc, else if (property == config->prop_mode_id) { struct drm_property_blob *mode = drm_property_lookup_blob(dev, val); + drm_atomic_allow_aspect_ratio_for_umode(state, + (struct drm_mode_modeinfo *) + mode->data); ret = drm_atomic_set_mode_prop_for_crtc(state, mode); drm_property_blob_put(mode); return ret; diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index f0556e6..a2d34fa 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -425,6 +425,13 @@ int drm_mode_getcrtc(struct drm_device *dev, drm_modeset_lock(&crtc->mutex, NULL); if (crtc->state) { if (crtc->state->enable) { + /* + * If the aspect-ratio is not required by the, + * userspace, do not set the aspect-ratio flags. + */ + if (!file_priv->aspect_ratio_allowed) + crtc->state->mode.picture_aspect_ratio = + HDMI_PICTURE_ASPECT_NONE; drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->state->mode); crtc_resp->mode_valid = 1; @@ -435,6 +442,13 @@ int drm_mode_getcrtc(struct drm_device *dev, crtc_resp->x = crtc->x; crtc_resp->y = crtc->y; if (crtc->enabled) { + /* + * If the aspect-ratio is not required by the, + * userspace, do not set the aspect-ratio flags. + */ + if (!file_priv->aspect_ratio_allowed) + crtc->mode.picture_aspect_ratio = + HDMI_PICTURE_ASPECT_NONE; drm_mode_convert_to_umode(&crtc_resp->mode, &crtc->mode); crtc_resp->mode_valid = 1; @@ -610,6 +624,11 @@ int drm_mode_setcrtc(struct drm_device *dev, void *data, goto out; } + /* If the user does not ask for aspect ratio, reset the aspect + * ratio bits in the usermode. + */ + if (!file_priv->aspect_ratio_allowed) + crtc_req->mode.flags &= (~DRM_MODE_FLAG_PIC_AR_MASK); ret = drm_mode_convert_umode(mode, &crtc_req->mode); if (ret) { DRM_DEBUG_KMS("Invalid mode\n"); diff --git a/include/drm/drm_atomic.h b/include/drm/drm_atomic.h index 1c27526..130dad9 100644 --- a/include/drm/drm_atomic.h +++ b/include/drm/drm_atomic.h @@ -237,6 +237,7 @@ struct __drm_private_objs_state { * @ref: count of all references to this state (will not be freed until zero) * @dev: parent DRM device * @allow_modeset: allow full modeset + * @allow_aspect_ratio: allow the aspect ratio info to be passes to user * @legacy_cursor_update: hint to enforce legacy cursor IOCTL semantics * @async_update: hint for asynchronous plane update * @planes: pointer to array of structures with per-plane data @@ -256,6 +257,7 @@ struct drm_atomic_state { struct drm_device *dev; bool allow_modeset : 1; + bool allow_aspect_ratio : 1; bool legacy_cursor_update : 1; bool async_update : 1; struct __drm_planes_state *planes;