From patchwork Wed Dec 12 01:05:50 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 10725417 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7D6C217FE for ; Wed, 12 Dec 2018 01:06:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CDEC2B1DE for ; Wed, 12 Dec 2018 01:06:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 60BA82B45F; Wed, 12 Dec 2018 01:06:28 +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,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 1140B2B1DE for ; Wed, 12 Dec 2018 01:06:28 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 29AD76E4FA; Wed, 12 Dec 2018 01:06:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id AD4886E4FA; Wed, 12 Dec 2018 01:06:25 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 17:06:25 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,343,1539673200"; d="scan'208";a="301400222" Received: from mdroper-desk.fm.intel.com ([10.105.128.10]) by fmsmga006.fm.intel.com with ESMTP; 11 Dec 2018 17:06:25 -0800 From: Matt Roper To: intel-gfx@lists.freedesktop.org Subject: [PATCH 1/2] drm: Add color management LUT validation helpers Date: Tue, 11 Dec 2018 17:05:50 -0800 Message-Id: <20181212010551.6337-2-matthew.d.roper@intel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181212010551.6337-1-matthew.d.roper@intel.com> References: <20181212010551.6337-1-matthew.d.roper@intel.com> 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: Uma Shankar , Swati Sharma , dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Some hardware may place additional restrictions on the gamma/degamma curves described by our LUT properties. E.g., that a gamma curve never decreases or that the red/green/blue channels of a LUT's entries must be equal. Let's add a couple helpers that drivers can use to test that a userspace-provided LUT doesn't violate hardware requirements. Cc: Uma Shankar Cc: Swati Sharma Signed-off-by: Matt Roper Reviewed-by: Brian Starkey --- drivers/gpu/drm/drm_color_mgmt.c | 53 ++++++++++++++++++++++++++++++++++++++++ include/drm/drm_color_mgmt.h | 3 +++ 2 files changed, 56 insertions(+) diff --git a/drivers/gpu/drm/drm_color_mgmt.c b/drivers/gpu/drm/drm_color_mgmt.c index 07dcf47daafe..41e617e34c10 100644 --- a/drivers/gpu/drm/drm_color_mgmt.c +++ b/drivers/gpu/drm/drm_color_mgmt.c @@ -462,3 +462,56 @@ int drm_plane_create_color_properties(struct drm_plane *plane, return 0; } EXPORT_SYMBOL(drm_plane_create_color_properties); + +/** + * drm_color_lut_has_equal_channels - check LUT for equal r/g/b values + * @lut: property blob containing LUT to check + * + * Helper to check whether the entries of a LUT all have equal values for the + * red, green, and blue channels. Some hardware can only be programmed + * with a single value per LUT entry, which is assumed to apply to all + * three color components. + */ +bool drm_color_lut_has_equal_channels(struct drm_property_blob *lut) +{ + struct drm_color_lut *entry; + int i; + + if (!lut) + return true; + + entry = lut->data; + for (i = 0; i < drm_color_lut_size(lut); i++) + if (entry[i].red != entry[i].blue || + entry[i].red != entry[i].green) + return false; + + return true; +} +EXPORT_SYMBOL(drm_color_lut_has_equal_channels); + +/** + * drm_color_lut_is_increasing - check that LUT is always flat/increasing + * @lut: LUT to check + * + * Helper to check whether the entries of a LUT are always flat or increasing + * (never decreasing). + */ +bool drm_color_lut_is_increasing(struct drm_property_blob *lut) +{ + struct drm_color_lut *entry; + int i; + + if (!lut) + return true; + + entry = lut->data; + for (i = 1; i < drm_color_lut_size(lut); i++) + if (entry[i].red < entry[i-1].red || + entry[i].green < entry[i-1].green || + entry[i].blue < entry[i-1].blue) + return false; + + return true; +} +EXPORT_SYMBOL(drm_color_lut_is_increasing); diff --git a/include/drm/drm_color_mgmt.h b/include/drm/drm_color_mgmt.h index 90ef9996d9a4..6c38f5477e29 100644 --- a/include/drm/drm_color_mgmt.h +++ b/include/drm/drm_color_mgmt.h @@ -69,4 +69,7 @@ int drm_plane_create_color_properties(struct drm_plane *plane, u32 supported_ranges, enum drm_color_encoding default_encoding, enum drm_color_range default_range); + +bool drm_color_lut_has_equal_channels(struct drm_property_blob *lut); +bool drm_color_lut_is_increasing(struct drm_property_blob *lut); #endif From patchwork Wed Dec 12 01:05:51 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Roper X-Patchwork-Id: 10725423 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7476517FE for ; Wed, 12 Dec 2018 01:06:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 64D5C2B1DE for ; Wed, 12 Dec 2018 01:06:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5992B2B45F; Wed, 12 Dec 2018 01:06:35 +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,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=unavailable 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 130632B1DE for ; Wed, 12 Dec 2018 01:06:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id C835B6E4FE; Wed, 12 Dec 2018 01:06:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5C0296E4FC; Wed, 12 Dec 2018 01:06:32 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 11 Dec 2018 17:06:31 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,343,1539673200"; d="scan'208";a="301400250" Received: from mdroper-desk.fm.intel.com ([10.105.128.10]) by fmsmga006.fm.intel.com with ESMTP; 11 Dec 2018 17:06:31 -0800 From: Matt Roper To: intel-gfx@lists.freedesktop.org Subject: [PATCH 2/2] drm/i915: Validate userspace-provided color management LUT's Date: Tue, 11 Dec 2018 17:05:51 -0800 Message-Id: <20181212010551.6337-3-matthew.d.roper@intel.com> X-Mailer: git-send-email 2.14.4 In-Reply-To: <20181212010551.6337-1-matthew.d.roper@intel.com> References: <20181212010551.6337-1-matthew.d.roper@intel.com> 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: Uma Shankar , Swati Sharma , dri-devel@lists.freedesktop.org MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP We currently program userspace-provided gamma and degamma LUT's into our hardware without really checking to see whether they satisfy our hardware's rules. We should try to catch tables that are invalid for our hardware early and reject the atomic transaction. All of our platforms that accept a degamma LUT expect that the entries in the LUT are always flat or increasing, never decreasing. Also, our GLK and ICL platforms only accept degamma tables with r=g=b entries; so we should also add the relevant checks for that in anticipation of degamma support landing for those platforms. Cc: Uma Shankar Cc: Swati Sharma Signed-off-by: Matt Roper --- drivers/gpu/drm/i915/intel_color.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/gpu/drm/i915/intel_color.c b/drivers/gpu/drm/i915/intel_color.c index 1d572e83db7f..041bb5d6a6cd 100644 --- a/drivers/gpu/drm/i915/intel_color.c +++ b/drivers/gpu/drm/i915/intel_color.c @@ -610,6 +610,24 @@ int intel_color_check(struct intel_crtc_state *crtc_state) degamma_length = INTEL_INFO(dev_priv)->color.degamma_lut_size; gamma_length = INTEL_INFO(dev_priv)->color.gamma_lut_size; + /* + * GLK and gen11 only accept a single value for red, green, and + * blue in the degamma table. Make sure userspace didn't try to + * pass us something we can't handle. + */ + if (IS_GEMINILAKE(dev_priv) || INTEL_GEN(dev_priv) >= 11) { + if (!drm_color_lut_has_equal_channels(crtc_state->base.degamma_lut)) { + DRM_DEBUG_KMS("All degamma entries must have equal r/g/b\n"); + return -EINVAL; + } + } + + /* All platforms require that the degamma curve be non-decreasing */ + if (!drm_color_lut_is_increasing(crtc_state->base.degamma_lut)) { + DRM_DEBUG_KMS("Degamma curve must never decrease.\n"); + return -EINVAL; + } + /* * We allow both degamma & gamma luts at the right size or * NULL.