From patchwork Thu Apr 7 09:14:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12804886 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 00019C433F5 for ; Thu, 7 Apr 2022 09:15:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 83F3010E794; Thu, 7 Apr 2022 09:15:11 +0000 (UTC) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3ECAC10E77A; Thu, 7 Apr 2022 09:15:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649322907; x=1680858907; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=KtaYKzrfzuyEFfSaeN3pyE4zQqrO5BqcVt4cGTB0xa8=; b=ccYib3YBQrP3E78zBHd7mSWOITUW+ItDG6pQOVVxbXa6EDaG+zUsEBVe 1G+fZYuoplKK4cETtqdEdHwqyG6EeVRzlGGe5ouwTekvpFucc3QQuTrvR 5HEch/BXpMG+sI5wS1nKgLeA0y3DQp0KK4lSwfvUi5M649cCyOL4MNgaS TmmZqTaQRzv9UIrgYij6TEaiWqck8QNuizMTn3LX34U2VUns4UXqLAYse lLhwaddQ2ewqIAzRQxuoKn/OHPK6x9De9EAi/xzf+s/7Va77u5elvslA2 reCW50BShy195JL/vfxJFtjN9Y55ygK56dbzabwvMyvkxCW4+wuyToEHH w==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="321964159" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="321964159" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:14:49 -0700 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="549945616" Received: from kgibala-mobl.ger.corp.intel.com (HELO localhost) ([10.249.142.48]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:14:47 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Subject: [PATCH 01/12] drm/edid: convert edid_is_zero() to edid_block_is_zero() for blocks Date: Thu, 7 Apr 2022 12:14:27 +0300 Message-Id: <4a5f816a3e0507a447aa2a040623055a4ffa6b3d.1649322799.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" As edid_is_zero() is only ever used on EDID blocks, convert it to edid_block_is_zero() with implicit block size. Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 04e818ecd662..f4da3f92f41b 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1632,9 +1632,9 @@ static int edid_block_tag(const void *_block) return block[0]; } -static bool edid_is_zero(const void *edid, int length) +static bool edid_block_is_zero(const void *edid) { - return !memchr_inv(edid, 0, length); + return !memchr_inv(edid, 0, EDID_LENGTH); } /** @@ -1785,7 +1785,7 @@ bool drm_edid_block_valid(u8 *_block, int block_num, bool print_bad_edid, } if (!valid && print_bad_edid) { - if (edid_is_zero(block, EDID_LENGTH)) { + if (edid_block_is_zero(block)) { pr_notice("EDID block is all zeroes\n"); } else { pr_notice("Raw EDID:\n"); @@ -1942,7 +1942,7 @@ static void connector_bad_edid(struct drm_connector *connector, u8 *block = edid + i * EDID_LENGTH; char prefix[20]; - if (edid_is_zero(block, EDID_LENGTH)) + if (edid_block_is_zero(block)) sprintf(prefix, "\t[%02x] ZERO ", i); else if (!drm_edid_block_valid(block, i, false, NULL)) sprintf(prefix, "\t[%02x] BAD ", i); @@ -2019,7 +2019,7 @@ static struct edid *drm_do_get_edid_base_block(struct drm_connector *connector, goto out; if (drm_edid_block_valid(edid, 0, false, edid_corrupt)) break; - if (try == 0 && edid_is_zero(edid, EDID_LENGTH)) { + if (try == 0 && edid_block_is_zero(edid)) { if (null_edid_counter) (*null_edid_counter)++; goto carp; From patchwork Thu Apr 7 09:14:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12804883 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id DBD5DC433FE for ; Thu, 7 Apr 2022 09:14:57 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D023510E753; Thu, 7 Apr 2022 09:14:56 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 8CA2010E656; Thu, 7 Apr 2022 09:14:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649322895; x=1680858895; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=XaDp3DJV+THGFW/cFPINCIEEAJ5+GOYXCAM3Znv1bZo=; b=K8qCnJH1eStIou/tr/M3B6JpItv2aSsmbSzABCXnH0XfIRheSmFSVh1E UrNNMaoUcqtpp3orNfAOZkr6SlLbLR17APW9XMVw4s4/94/kUo0r091xx 1cuMZbJpAGrKma4w5xr2URshEkRjhx3EjLCaDnFUnAN7NjAER7OaSVcaD K27s/wFl//46Hc96g4XKQlBDQMaCtEGaPuTjTeQmDz/aFlBDbYPDB5hpF 5fL3musTrDowNNO9FREvN2qm8ZncyWmCyK5JljqC2sKfAwF2EWdPvyydF otfh4tm7hRUWyn/zlmv/rleici7DILl8QqkSps31JXZjmlTmNOlzwrkdU Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="248795092" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="248795092" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:14:55 -0700 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="524844615" Received: from kgibala-mobl.ger.corp.intel.com (HELO localhost) ([10.249.142.48]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:14:52 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Subject: [PATCH 02/12] drm/edid: have edid_block_check() detect blocks that are all zero Date: Thu, 7 Apr 2022 12:14:28 +0300 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" We have the check function, have it also detect blocks that are all zero instead of leaving that to callers. Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index f4da3f92f41b..f062d1715ec3 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1671,6 +1671,7 @@ EXPORT_SYMBOL(drm_edid_are_equal); enum edid_block_status { EDID_BLOCK_OK = 0, EDID_BLOCK_NULL, + EDID_BLOCK_ZERO, EDID_BLOCK_HEADER_CORRUPT, EDID_BLOCK_HEADER_REPAIR, EDID_BLOCK_HEADER_FIXED, @@ -1689,15 +1690,23 @@ static enum edid_block_status edid_block_check(const void *_block, if (is_base_block) { int score = drm_edid_header_is_valid(block); - if (score < clamp(edid_fixup, 0, 8)) - return EDID_BLOCK_HEADER_CORRUPT; + if (score < clamp(edid_fixup, 0, 8)) { + if (edid_block_is_zero(block)) + return EDID_BLOCK_ZERO; + else + return EDID_BLOCK_HEADER_CORRUPT; + } if (score < 8) return EDID_BLOCK_HEADER_REPAIR; } - if (edid_block_compute_checksum(block) != edid_block_get_checksum(block)) - return EDID_BLOCK_CHECKSUM; + if (edid_block_compute_checksum(block) != edid_block_get_checksum(block)) { + if (edid_block_is_zero(block)) + return EDID_BLOCK_ZERO; + else + return EDID_BLOCK_CHECKSUM; + } if (is_base_block) { if (block->version != 1) @@ -1785,7 +1794,7 @@ bool drm_edid_block_valid(u8 *_block, int block_num, bool print_bad_edid, } if (!valid && print_bad_edid) { - if (edid_block_is_zero(block)) { + if (status == EDID_BLOCK_ZERO) { pr_notice("EDID block is all zeroes\n"); } else { pr_notice("Raw EDID:\n"); From patchwork Thu Apr 7 09:14:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12804884 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9957C433EF for ; Thu, 7 Apr 2022 09:15:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 62FA210E76A; Thu, 7 Apr 2022 09:15:04 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4CBAA10E765; Thu, 7 Apr 2022 09:15:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649322903; x=1680858903; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=uC4jihYH6UUQHHskgYrA3e2n4aJRK258bFCSVIXhSpQ=; b=Xoc+LqMcnFdGr/L8W+u4lLNMmHH8aaFcIcL0670mx0mjITXDnBYbmIH1 7mKcvLy6bB4RGuCedbhwwvP31p5QYkf90kpSp8WHeQWT4fUzLjmD5zE8d qvFmqIt6/d9V5nYLAInBT4EPirRLx/4IiH8DFZojzR0P7ju+d8Fhm1D5k vrw1nWq9lVJPPjC3fcooE39GnJVdak/dR5ji8NbWGFXzzlu4geaXgFuaZ /LHUTZ1NINULSNRLzspeLgj8hpMnsgkYSzUBuZDxQmMGZqxKREV4f0i4x 2PG5cL4pSRfJ9m85xgPHIllETrsytzyOOp8H8DIx6whpeBNGA4Mwc6SOb w==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="260108545" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="260108545" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:00 -0700 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="722885939" Received: from kgibala-mobl.ger.corp.intel.com (HELO localhost) ([10.249.142.48]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:14:57 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Subject: [PATCH 03/12] drm/edid: refactor EDID block status printing Date: Thu, 7 Apr 2022 12:14:29 +0300 Message-Id: <012d5b007a6a3771540499fb1273882d631887b3.1649322799.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Split out a function to log EDID block status. The printouts get changed slightly. Unfortunately, not all users will have struct drm_device available, so we convert to pr_* debug logging instead of drm device based logging. Signed-off-by: Jani Nikula Reviewed-by: Ville Syrjälä --- drivers/gpu/drm/drm_edid.c | 75 ++++++++++++++++++++++++++------------ 1 file changed, 51 insertions(+), 24 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index f062d1715ec3..3d04d63464ba 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1729,6 +1729,50 @@ static bool edid_block_valid(const void *block, bool base) edid_block_tag(block)); } +static void edid_block_status_print(enum edid_block_status status, + const struct edid *block, + int block_num) +{ + switch (status) { + case EDID_BLOCK_OK: + break; + case EDID_BLOCK_NULL: + pr_debug("EDID block %d pointer is NULL\n", block_num); + break; + case EDID_BLOCK_ZERO: + pr_notice("EDID block %d is all zeroes\n", block_num); + break; + case EDID_BLOCK_HEADER_CORRUPT: + pr_notice("EDID has corrupt header\n"); + break; + case EDID_BLOCK_HEADER_REPAIR: + pr_debug("EDID corrupt header needs repair\n"); + break; + case EDID_BLOCK_HEADER_FIXED: + pr_debug("EDID corrupt header fixed\n"); + break; + case EDID_BLOCK_CHECKSUM: + if (edid_block_status_valid(status, edid_block_tag(block))) { + pr_debug("EDID block %d (tag 0x%02x) checksum is invalid, remainder is %d, ignoring\n", + block_num, edid_block_tag(block), + edid_block_compute_checksum(block)); + } else { + pr_notice("EDID block %d (tag 0x%02x) checksum is invalid, remainder is %d\n", + block_num, edid_block_tag(block), + edid_block_compute_checksum(block)); + } + break; + case EDID_BLOCK_VERSION: + pr_notice("EDID has major version %d, instead of 1\n", + block->version); + break; + default: + pr_debug("EDID block %d unknown edid block status code %d\n", + block_num, status); + break; + } +} + /** * drm_edid_block_valid - Sanity check the EDID block (base or extension) * @raw_edid: pointer to raw EDID block @@ -1775,33 +1819,16 @@ bool drm_edid_block_valid(u8 *_block, int block_num, bool print_bad_edid, *edid_corrupt = true; } + edid_block_status_print(status, block, block_num); + /* Determine whether we can use this block with this status. */ valid = edid_block_status_valid(status, edid_block_tag(block)); - /* Some fairly random status printouts. */ - if (status == EDID_BLOCK_CHECKSUM) { - if (valid) { - DRM_DEBUG("EDID block checksum is invalid, remainder is %d\n", - edid_block_compute_checksum(block)); - DRM_DEBUG("Assuming a KVM switch modified the block but left the original checksum\n"); - } else if (print_bad_edid) { - DRM_NOTE("EDID block checksum is invalid, remainder is %d\n", - edid_block_compute_checksum(block)); - } - } else if (status == EDID_BLOCK_VERSION) { - DRM_NOTE("EDID has major version %d, instead of 1\n", - block->version); - } - - if (!valid && print_bad_edid) { - if (status == EDID_BLOCK_ZERO) { - pr_notice("EDID block is all zeroes\n"); - } else { - pr_notice("Raw EDID:\n"); - print_hex_dump(KERN_NOTICE, - " \t", DUMP_PREFIX_NONE, 16, 1, - block, EDID_LENGTH, false); - } + if (!valid && print_bad_edid && status != EDID_BLOCK_ZERO) { + pr_notice("Raw EDID:\n"); + print_hex_dump(KERN_NOTICE, + " \t", DUMP_PREFIX_NONE, 16, 1, + block, EDID_LENGTH, false); } return valid; From patchwork Thu Apr 7 09:14:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12804885 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 2A245C433F5 for ; Thu, 7 Apr 2022 09:15:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9EAD210E770; Thu, 7 Apr 2022 09:15:07 +0000 (UTC) Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id ECB8810E770; Thu, 7 Apr 2022 09:15:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649322905; x=1680858905; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VNFqobUalKGz3Nxz0yaqjAxpYhLJwV6XArSBkU1xY/s=; b=SogzEjbtQjSdXAGMXtipZEg1PB46+p8sRO75s4ILmzVzsqawaDrplVfp Sqi87JG3udhAO2xT4mOPAVmmI7bz1EHT5PtsW95SAFOAUHzAGI0jUXDCJ JnMNByo5zqEc1U92b0g8kAKNtmuPx4K4XtaLR/LaHpq9PdzaOiv1HBFFf STs9TsST+OOa6N7+Re0+aqxl+wz/1kVewJ9L75G3Y601Y4fNRrqHAMZwI 1fC/qx7gbxCCPQlJGpv5Ftbes4b/OmxRP6zX9cX5V6juLgerlbPH3S0ny eBNIIahO1lr50amLRmUAtvIaf1xI06hsyxwC1oq7DBTnYRU8xHlFOmBG1 Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="260966511" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="260966511" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:04 -0700 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="549946009" Received: from kgibala-mobl.ger.corp.intel.com (HELO localhost) ([10.249.142.48]) by orsmga007-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:02 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Subject: [PATCH 04/12] drm/edid: add a helper to log dump an EDID block Date: Thu, 7 Apr 2022 12:14:30 +0300 Message-Id: <321ad045ec374443793c1cdba5e822c656f2259c.1649322799.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Unify debug log dumping. There's duplication in the error paths for EDID block validity checks, but this should be neglible. Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 3d04d63464ba..8638e54e0879 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1773,6 +1773,23 @@ static void edid_block_status_print(enum edid_block_status status, } } +static void edid_block_dump(const char *level, const void *block, int block_num) +{ + enum edid_block_status status; + char prefix[20]; + + status = edid_block_check(block, block_num == 0); + if (status == EDID_BLOCK_ZERO) + sprintf(prefix, "\t[%02x] ZERO ", block_num); + else if (!edid_block_status_valid(status, edid_block_tag(block))) + sprintf(prefix, "\t[%02x] BAD ", block_num); + else + sprintf(prefix, "\t[%02x] GOOD ", block_num); + + print_hex_dump(level, prefix, DUMP_PREFIX_NONE, 16, 1, + block, EDID_LENGTH, false); +} + /** * drm_edid_block_valid - Sanity check the EDID block (base or extension) * @raw_edid: pointer to raw EDID block @@ -1826,9 +1843,7 @@ bool drm_edid_block_valid(u8 *_block, int block_num, bool print_bad_edid, if (!valid && print_bad_edid && status != EDID_BLOCK_ZERO) { pr_notice("Raw EDID:\n"); - print_hex_dump(KERN_NOTICE, - " \t", DUMP_PREFIX_NONE, 16, 1, - block, EDID_LENGTH, false); + edid_block_dump(KERN_NOTICE, block, block_num); } return valid; @@ -1976,18 +1991,8 @@ static void connector_bad_edid(struct drm_connector *connector, drm_dbg_kms(connector->dev, "%s: EDID is invalid:\n", connector->name); for (i = 0; i < num_blocks; i++) { u8 *block = edid + i * EDID_LENGTH; - char prefix[20]; - - if (edid_block_is_zero(block)) - sprintf(prefix, "\t[%02x] ZERO ", i); - else if (!drm_edid_block_valid(block, i, false, NULL)) - sprintf(prefix, "\t[%02x] BAD ", i); - else - sprintf(prefix, "\t[%02x] GOOD ", i); - print_hex_dump(KERN_DEBUG, - prefix, DUMP_PREFIX_NONE, 16, 1, - block, EDID_LENGTH, false); + edid_block_dump(KERN_DEBUG, block, i); } } From patchwork Thu Apr 7 09:14:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12804887 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 72DCFC433F5 for ; Thu, 7 Apr 2022 09:15:15 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9DF7110E77A; Thu, 7 Apr 2022 09:15:13 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5886110E77A; Thu, 7 Apr 2022 09:15:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649322911; x=1680858911; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Ok0Ew230q5uGIOJPVdfa/ehnWedVE0i+xeWGSuqTsiE=; b=lBl6PcmiNNgVS6kklv0RK/AQx1OShgelrrZK4jH1hhGfp3NWfFpb3pWP iaHmbIywI7M1q5tlcThBi2O2W4aYOHfSJPt76Wy8VTCIPyLSVxF+Zx7u5 jW4Rc6BfoqBUWML0jabDhUl6gNvp8q3X/qBkpbqPfN/03jhxRjI1+Mzn4 BlfNM8cFPiftLGNXJSMifMNRxi6ynz+99/NkyFi+a9qtxI0e87VfIVPwT KM/WYcAe84VI1agtgwZWsjjG1HXfWWbW1CWXcrYY5iYqamKS/dH5y/HMF beCpkhX0mvZfoxXTikyjzcRt+3j9TDrlHXdlYW9bH3CnahSgVeZqj8KaJ w==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="248795150" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="248795150" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:10 -0700 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="658991491" Received: from kgibala-mobl.ger.corp.intel.com (HELO localhost) ([10.249.142.48]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:08 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Subject: [PATCH 05/12] drm/edid: pass struct edid to connector_bad_edid() Date: Thu, 7 Apr 2022 12:14:31 +0300 Message-Id: <13320766ab44588fa27755619fa3b9dc81e91836.1649322799.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Avoid casting here and there, and make it const. Signed-off-by: Jani Nikula Reviewed-by: Ville Syrjälä --- drivers/gpu/drm/drm_edid.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 8638e54e0879..ba54701f91f6 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1967,7 +1967,7 @@ drm_do_probe_ddc_edid(void *data, u8 *buf, unsigned int block, size_t len) } static void connector_bad_edid(struct drm_connector *connector, - u8 *edid, int num_blocks) + const struct edid *edid, int num_blocks) { int i; u8 last_block; @@ -1978,22 +1978,19 @@ static void connector_bad_edid(struct drm_connector *connector, * of 0x7e in the EDID of the _index_ of the last block in the * combined chunk of memory. */ - last_block = edid[0x7e]; + last_block = edid->extensions; /* Calculate real checksum for the last edid extension block data */ if (last_block < num_blocks) connector->real_edid_checksum = - edid_block_compute_checksum(edid + last_block * EDID_LENGTH); + edid_block_compute_checksum(edid + last_block); if (connector->bad_edid_counter++ && !drm_debug_enabled(DRM_UT_KMS)) return; drm_dbg_kms(connector->dev, "%s: EDID is invalid:\n", connector->name); - for (i = 0; i < num_blocks; i++) { - u8 *block = edid + i * EDID_LENGTH; - - edid_block_dump(KERN_DEBUG, block, i); - } + for (i = 0; i < num_blocks; i++) + edid_block_dump(KERN_DEBUG, edid + i, i); } /* Get override or firmware EDID */ @@ -2139,7 +2136,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, } if (invalid_blocks) { - connector_bad_edid(connector, (u8 *)edid, edid->extensions + 1); + connector_bad_edid(connector, edid, edid->extensions + 1); edid = edid_filter_invalid_blocks(edid, invalid_blocks); } From patchwork Thu Apr 7 09:14:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12804888 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7DA76C433F5 for ; Thu, 7 Apr 2022 09:15:21 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3503710E7AC; Thu, 7 Apr 2022 09:15:20 +0000 (UTC) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by gabe.freedesktop.org (Postfix) with ESMTPS id 75C6B10E79B; Thu, 7 Apr 2022 09:15:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649322918; x=1680858918; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=WlseI06oLD1o/3w1z+xz8NZPg8aEkfTpFA8hd3JR7fw=; b=UOI4++HddGLnHLMGsr2GsZ4xHDXAiJo7xZOx1YhYmQzCQOx3ikA7Y1Jr oKvEQMF0LQOgf7ClRfO/eC28Zd4Nh8w0DekmAvjLVfOd4XfLO11aBc69R lUa8NIHcJPvbvc1oEFEeGdIsJbsQ3grMmvwIjDzDAHQ9hvCLM/RB7EMUZ geB5/kGgONXOiHbffFs40M2xILdj22jhQGmt8LKqvvTCyMIEFp6yIuihP C9UoNFKDX/V/0F6YRDaCTK3jG75tsfHH5pP/kazGjaEqitUEZc09zSWCK 1KjlFTiTbqaZOA4AFEh7lojig1A0B1cPA+XcTin7zAsjYYxeZBpKJkEv+ g==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="241865153" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="241865153" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:17 -0700 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="524844767" Received: from kgibala-mobl.ger.corp.intel.com (HELO localhost) ([10.249.142.48]) by orsmga006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:15 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Subject: [PATCH 06/12] drm/edid: add typedef for block read function Date: Thu, 7 Apr 2022 12:14:32 +0300 Message-Id: <94e414efe8d127f3fd0b4fd7948aafbe7be079a9.1649322799.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Make the callback a bit easier on the eye. Signed-off-by: Jani Nikula Reviewed-by: Ville Syrjälä --- drivers/gpu/drm/drm_edid.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index ba54701f91f6..926ffe5cd97e 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2037,10 +2037,11 @@ int drm_add_override_edid_modes(struct drm_connector *connector) } EXPORT_SYMBOL(drm_add_override_edid_modes); +typedef int read_block_fn(void *context, u8 *buf, unsigned int block, size_t len); + static struct edid *drm_do_get_edid_base_block(struct drm_connector *connector, - int (*get_edid_block)(void *data, u8 *buf, unsigned int block, - size_t len), - void *data) + read_block_fn read_block, + void *context) { int *null_edid_counter = connector ? &connector->null_edid_counter : NULL; bool *edid_corrupt = connector ? &connector->edid_corrupt : NULL; @@ -2053,7 +2054,7 @@ static struct edid *drm_do_get_edid_base_block(struct drm_connector *connector, /* base block fetch */ for (try = 0; try < 4; try++) { - if (get_edid_block(data, edid, 0, EDID_LENGTH)) + if (read_block(context, edid, 0, EDID_LENGTH)) goto out; if (drm_edid_block_valid(edid, 0, false, edid_corrupt)) break; @@ -2097,9 +2098,8 @@ static struct edid *drm_do_get_edid_base_block(struct drm_connector *connector, * Return: Pointer to valid EDID or NULL if we couldn't find any. */ struct edid *drm_do_get_edid(struct drm_connector *connector, - int (*get_edid_block)(void *data, u8 *buf, unsigned int block, - size_t len), - void *data) + read_block_fn read_block, + void *context) { int j, invalid_blocks = 0; struct edid *edid, *new, *override; @@ -2108,7 +2108,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, if (override) return override; - edid = drm_do_get_edid_base_block(connector, get_edid_block, data); + edid = drm_do_get_edid_base_block(connector, read_block, context); if (!edid) return NULL; @@ -2125,7 +2125,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, int try; for (try = 0; try < 4; try++) { - if (get_edid_block(data, block, j, EDID_LENGTH)) + if (read_block(context, block, j, EDID_LENGTH)) goto out; if (drm_edid_block_valid(block, j, false, NULL)) break; From patchwork Thu Apr 7 09:14:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12804889 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E7A59C433FE for ; Thu, 7 Apr 2022 09:15:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2C88C10E7B2; Thu, 7 Apr 2022 09:15:24 +0000 (UTC) Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0BFE210E7AB; Thu, 7 Apr 2022 09:15:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649322923; x=1680858923; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=7ua2793r9eRSzOqGh/E5qjHz/9DC8CrOiw6Dp3nSrk0=; b=ibHRMEKyoA31SmbHynS0aQYNT1emQ3Lu/IwFS5KiOi+rvAEYJ6hNu9E3 QKDT4wKtksODPRO0ctduw3/0rCbBXovMT+rYwp6qy/TLyakxUjyV37FE+ p3uM6nzUy3tePvs+wVPqh4k7+MzZuGAnKJ/jdO8rF9H+41ewNl4QpJn0/ ydrguYh3eeBks5fX7cqv3+orLCz6VxtlqzvWlJwVMRVvfk+t+e6pg2R07 QYQiED/N/irYc+4gsLUxJjZPuqQibYM2TLZ7VtYV7GPey/DVOXoCuL48N xBG73iPuynG8e7PaiNHQRJK6sIG29puM+hoz8RDzMXBsNzgtxEnDKLiWu A==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="286251386" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="286251386" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:22 -0700 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="506078184" Received: from kgibala-mobl.ger.corp.intel.com (HELO localhost) ([10.249.142.48]) by orsmga003-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:20 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Subject: [PATCH 07/12] drm/edid: abstract an EDID block read helper Date: Thu, 7 Apr 2022 12:14:33 +0300 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" We have an abstraction for the EDID base block read, yet duplicating the retries and error handling for extension block reads. Introduce a more generic EDID block read helper. Switch to the helper piecemeal, starting with drm_edid_get_panel_id(), which doesn't need or have access to the connector anyway. The subtle change is switching from drm_edid_block_valid() to edid_block_check(). We also status print once, not for every attempt. Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 58 +++++++++++++++++++++++++++++++++----- 1 file changed, 51 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 926ffe5cd97e..162f0a959376 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1670,6 +1670,7 @@ EXPORT_SYMBOL(drm_edid_are_equal); enum edid_block_status { EDID_BLOCK_OK = 0, + EDID_BLOCK_READ_FAIL, EDID_BLOCK_NULL, EDID_BLOCK_ZERO, EDID_BLOCK_HEADER_CORRUPT, @@ -1736,6 +1737,9 @@ static void edid_block_status_print(enum edid_block_status status, switch (status) { case EDID_BLOCK_OK: break; + case EDID_BLOCK_READ_FAIL: + pr_debug("EDID block %d read failed\n", block_num); + break; case EDID_BLOCK_NULL: pr_debug("EDID block %d pointer is NULL\n", block_num); break; @@ -2039,6 +2043,39 @@ EXPORT_SYMBOL(drm_add_override_edid_modes); typedef int read_block_fn(void *context, u8 *buf, unsigned int block, size_t len); +static enum edid_block_status edid_block_read(void *block, unsigned int block_num, + read_block_fn read_block, + void *context) +{ + enum edid_block_status status; + bool is_base_block = block_num == 0; + int try; + + for (try = 0; try < 4; try++) { + if (read_block(context, block, block_num, EDID_LENGTH)) + return EDID_BLOCK_READ_FAIL; + + status = edid_block_check(block, is_base_block); + if (status == EDID_BLOCK_HEADER_REPAIR) { + edid_header_fix(block); + + /* Retry with fixed header, update status if that worked. */ + status = edid_block_check(block, is_base_block); + if (status == EDID_BLOCK_OK) + status = EDID_BLOCK_HEADER_FIXED; + } + + if (edid_block_status_valid(status, edid_block_tag(block))) + break; + + /* Fail early for unrepairable base block all zeros. */ + if (try == 0 && is_base_block && status == EDID_BLOCK_ZERO) + break; + } + + return status; +} + static struct edid *drm_do_get_edid_base_block(struct drm_connector *connector, read_block_fn read_block, void *context) @@ -2237,20 +2274,27 @@ static u32 edid_extract_panel_id(const struct edid *edid) u32 drm_edid_get_panel_id(struct i2c_adapter *adapter) { - const struct edid *edid; - u32 panel_id; - - edid = drm_do_get_edid_base_block(NULL, drm_do_probe_ddc_edid, adapter); + enum edid_block_status status; + void *base_block; + u32 panel_id = 0; /* * There are no manufacturer IDs of 0, so if there is a problem reading * the EDID then we'll just return 0. */ - if (!edid) + + base_block = kmalloc(EDID_LENGTH, GFP_KERNEL); + if (!base_block) return 0; - panel_id = edid_extract_panel_id(edid); - kfree(edid); + status = edid_block_read(base_block, 0, drm_do_probe_ddc_edid, adapter); + + edid_block_status_print(status, base_block, 0); + + if (edid_block_status_valid(status, edid_block_tag(base_block))) + panel_id = edid_extract_panel_id(base_block); + + kfree(base_block); return panel_id; } From patchwork Thu Apr 7 09:14:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12804890 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F286BC433EF for ; Thu, 7 Apr 2022 09:15:30 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B923310E7CD; Thu, 7 Apr 2022 09:15:29 +0000 (UTC) Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by gabe.freedesktop.org (Postfix) with ESMTPS id 81E2710E4A1; Thu, 7 Apr 2022 09:15:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649322928; x=1680858928; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=Zjq4m8ktl35THTgYx3jFnjZtAOYdlwXz42yAjO7fNd8=; b=dSpYPzvIEdLjMoaW3XI0OzU9AlBklvVvEolG5mN0FrAzqHoSIqEs1E5q J430xf8PU+PuhRD8vMMj9O1d5FuV/ONDMVKUvyNrrPk4YilLtRzK8G+cD IjpCRXX9z7Nr/9yNhp0gzVGoS7kfO/Hdb5TUZnYWNSgU/bM2Pr/E/P0RB Wvmi0FPfA3HkYlOwqf6y8CsyPpJPQqjVXJjNMb66WAd3EP8JmjDY0qUUr bgfiZt4+oSJ2FZxjUEyxts3D9d2IB7nqihGrawjYZQtVezIvA32tXW2U9 hrQNdEfavY4MP1jBgoHIWt0qfl54+3ngRq16scOufdO/RIlIUDiDFhmTO A==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="258863883" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="258863883" Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:28 -0700 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="524292488" Received: from kgibala-mobl.ger.corp.intel.com (HELO localhost) ([10.249.142.48]) by orsmga002-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:25 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Subject: [PATCH 08/12] drm/edid: use EDID block read helper in drm_do_get_edid() Date: Thu, 7 Apr 2022 12:14:34 +0300 Message-Id: <05f4f103cda02565c913435e0a2d7bffeca82d44.1649322799.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Convert drm_do_get_edit() from the base block read helper to the generic block read helper. There's quite a bit going on here, as the corrupt and null EDID information is moved back to the caller. As we see, they were not all that clear to begin with, and this change underlines that. Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 62 ++++++++++++++------------------------ 1 file changed, 23 insertions(+), 39 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 162f0a959376..bffb8a599cda 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2076,44 +2076,6 @@ static enum edid_block_status edid_block_read(void *block, unsigned int block_nu return status; } -static struct edid *drm_do_get_edid_base_block(struct drm_connector *connector, - read_block_fn read_block, - void *context) -{ - int *null_edid_counter = connector ? &connector->null_edid_counter : NULL; - bool *edid_corrupt = connector ? &connector->edid_corrupt : NULL; - void *edid; - int try; - - edid = kmalloc(EDID_LENGTH, GFP_KERNEL); - if (edid == NULL) - return NULL; - - /* base block fetch */ - for (try = 0; try < 4; try++) { - if (read_block(context, edid, 0, EDID_LENGTH)) - goto out; - if (drm_edid_block_valid(edid, 0, false, edid_corrupt)) - break; - if (try == 0 && edid_block_is_zero(edid)) { - if (null_edid_counter) - (*null_edid_counter)++; - goto carp; - } - } - if (try == 4) - goto carp; - - return edid; - -carp: - if (connector) - connector_bad_edid(connector, edid, 1); -out: - kfree(edid); - return NULL; -} - /** * drm_do_get_edid - get EDID data using a custom EDID block read function * @connector: connector we're probing @@ -2138,6 +2100,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, read_block_fn read_block, void *context) { + enum edid_block_status status; int j, invalid_blocks = 0; struct edid *edid, *new, *override; @@ -2145,10 +2108,31 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, if (override) return override; - edid = drm_do_get_edid_base_block(connector, read_block, context); + edid = kmalloc(EDID_LENGTH, GFP_KERNEL); if (!edid) return NULL; + status = edid_block_read(edid, 0, read_block, context); + + edid_block_status_print(status, edid, 0); + + if (status == EDID_BLOCK_READ_FAIL) + goto out; + + /* FIXME: Clarify what a corrupt EDID actually means. */ + if (status == EDID_BLOCK_OK || status == EDID_BLOCK_VERSION) + connector->edid_corrupt = false; + else + connector->edid_corrupt = true; + + if (!edid_block_status_valid(status, edid_block_tag(edid))) { + if (status == EDID_BLOCK_ZERO) + connector->null_edid_counter++; + + connector_bad_edid(connector, edid, 1); + goto out; + } + if (edid->extensions == 0) return edid; From patchwork Thu Apr 7 09:14:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12804891 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8D974C433FE for ; Thu, 7 Apr 2022 09:15:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 992EE10E7D4; Thu, 7 Apr 2022 09:15:34 +0000 (UTC) Received: from mga07.intel.com (mga07.intel.com [134.134.136.100]) by gabe.freedesktop.org (Postfix) with ESMTPS id 20AED10E7D4; Thu, 7 Apr 2022 09:15:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649322933; x=1680858933; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1YRG9/E/AgN+IW+J+9Icyvq2eZYsr+QAHV2A3mqYlAM=; b=DkTxI+JQNynDiOoXniknBARIi0HaNPQVbOydcWyGxMLZbLTaDmadNCow 98WG8cZPPxt7xuJg+WqO2nWHHR1QXcrskYSXmwDZmsKAghLoDvBmYzW9h K0URGTBSXpdO85jbwyXVcYq+fvqtV5QdL9V/R1em7Mnh9NAGGB5TGza93 7HTqBa0lBP+/R4ohJrMdsQ+ugvwcsZuzRCV2RoEiE7f5X6MI6v0KoGdk6 RauKDaDYNAZGBkrA9qvRzSQulNlo0LjnwvjzibwxZo4kpGcvwLfVIxadN mbxPuKe9WPzI7Ri3IcTk0jyXlgpIMakBoXBcjfmb2585JBmtL8lOC6BXy A==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="324434459" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="324434459" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:32 -0700 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="722886270" Received: from kgibala-mobl.ger.corp.intel.com (HELO localhost) ([10.249.142.48]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:30 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Subject: [PATCH 09/12] drm/edid: convert extension block read to EDID block read helper Date: Thu, 7 Apr 2022 12:14:35 +0300 Message-Id: <464387f15ebcba39e424a7e15bbf59f0c1ba1717.1649322799.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use the EDID block read helper also for extension block reads, making edid_block_read() the only place with the read retry logic. Note: We observe that drm_do_get_edid() does not use invalid extension blocks to flag the EDID as corrupt. Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index bffb8a599cda..6fa17084af02 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2143,17 +2143,16 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, for (j = 1; j <= edid->extensions; j++) { void *block = edid + j; - int try; - for (try = 0; try < 4; try++) { - if (read_block(context, block, j, EDID_LENGTH)) - goto out; - if (drm_edid_block_valid(block, j, false, NULL)) - break; - } + status = edid_block_read(block, j, read_block, context); - if (try == 4) + edid_block_status_print(status, block, j); + + if (!edid_block_status_valid(status, edid_block_tag(block))) { + if (status == EDID_BLOCK_READ_FAIL) + goto out; invalid_blocks++; + } } if (invalid_blocks) { From patchwork Thu Apr 7 09:14:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12804892 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 354EBC433EF for ; Thu, 7 Apr 2022 09:15:40 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id A6FF410E656; Thu, 7 Apr 2022 09:15:39 +0000 (UTC) Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id C537D10E656; Thu, 7 Apr 2022 09:15:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649322938; x=1680858938; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=JMsibKSc8UGw4kGTSdh4I0s6w2YjnLgecEdqszYwy8k=; b=MfzMtX8i3s0hxb4yKg0UIVW2xCiwbNecMU8XraLv6cpSSx0LUrSK0LDi BUxNopcDpzNV8tFtJD4oMjv6wC6VsDgPxPNWdeXgIVP+KTHVhQMRvaOTC 1c7+sEvcwo3u+LUb/JTU8Odp+wUOfYgX+GbmE8u1HooaEYjXtohrH+tHy 82Z/5a5xucyFTxKYRemYGGFSJQuOQ8iPRp3vpkXZ9gSTzTDu7nJSmJwZK PzuV5DCsT2TfFoVwfawpI0AidyIgodck8kswcClGgdW+EeGWKSn+mgRig Hh0H8MdMmzVLlgti0sYHfUsOR7II9zdltXTVy5LHWuMijZh/F1154jLDl g==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="260108705" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="260108705" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:38 -0700 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="588734796" Received: from kgibala-mobl.ger.corp.intel.com (HELO localhost) ([10.249.142.48]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:36 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Subject: [PATCH 10/12] drm/edid: drop extra local var Date: Thu, 7 Apr 2022 12:14:36 +0300 Message-Id: X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" We don't need override as a variable for anything. Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 6fa17084af02..767639364bd9 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2102,11 +2102,11 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, { enum edid_block_status status; int j, invalid_blocks = 0; - struct edid *edid, *new, *override; + struct edid *edid, *new; - override = drm_get_override_edid(connector); - if (override) - return override; + edid = drm_get_override_edid(connector); + if (edid) + return edid; edid = kmalloc(EDID_LENGTH, GFP_KERNEL); if (!edid) From patchwork Thu Apr 7 09:14:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12804893 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 009F0C433EF for ; Thu, 7 Apr 2022 09:15:46 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 08FF510E908; Thu, 7 Apr 2022 09:15:46 +0000 (UTC) Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id A200E10E80C; Thu, 7 Apr 2022 09:15:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649322944; x=1680858944; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=4DJKvko+TuJAyys4asTSPHd/BN0Z8Xr8iiiI4lM1ZCs=; b=Gr/OC09LCmrENbBP0ULf6F19ySvZ2XNk4JK3UJusxYd1JTOudjs15qzE OnJxbo1tU1972ce7E3jRtEroA6eRgYwM8xaAEavvXujjVDfzxeLJGqgRx xr+xAPshRMjh1h8dU/egXtTadh4OTWz5HkiywgsRU8Iy4h8yBUsTb9PzU vMoagRFuD09d6O775Q3CDfTXjwZycxaOGIJUMvv3HEy/nq1eR+Av3ktUT cNChbEuWXAVcpLEgCcJJXiYsFX2pHOH5XLAS/O5hK2teQH09CaK8dq68Q v0yLJQxbDMI/Dgvx95jYJunY4SYmWqS3drIgOs6Hsr5ZRZZkxs86YdCUH w==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="248795260" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="248795260" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:44 -0700 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="658991687" Received: from kgibala-mobl.ger.corp.intel.com (HELO localhost) ([10.249.142.48]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:41 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Subject: [PATCH 11/12] drm/edid: add single point of return to drm_do_get_edid() Date: Thu, 7 Apr 2022 12:14:37 +0300 Message-Id: <36945cc82b727933ca865c176c435b9419ccf33d.1649322799.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This will be useful in the future. Use fail label for fail exit. Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 767639364bd9..90615e30eaf5 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -2106,7 +2106,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, edid = drm_get_override_edid(connector); if (edid) - return edid; + goto ok; edid = kmalloc(EDID_LENGTH, GFP_KERNEL); if (!edid) @@ -2117,7 +2117,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, edid_block_status_print(status, edid, 0); if (status == EDID_BLOCK_READ_FAIL) - goto out; + goto fail; /* FIXME: Clarify what a corrupt EDID actually means. */ if (status == EDID_BLOCK_OK || status == EDID_BLOCK_VERSION) @@ -2130,15 +2130,15 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, connector->null_edid_counter++; connector_bad_edid(connector, edid, 1); - goto out; + goto fail; } if (edid->extensions == 0) - return edid; + goto ok; new = krealloc(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL); if (!new) - goto out; + goto fail; edid = new; for (j = 1; j <= edid->extensions; j++) { @@ -2150,7 +2150,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, if (!edid_block_status_valid(status, edid_block_tag(block))) { if (status == EDID_BLOCK_READ_FAIL) - goto out; + goto fail; invalid_blocks++; } } @@ -2161,9 +2161,10 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, edid = edid_filter_invalid_blocks(edid, invalid_blocks); } +ok: return edid; -out: +fail: kfree(edid); return NULL; } From patchwork Thu Apr 7 09:14:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jani Nikula X-Patchwork-Id: 12804894 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CBEE1C433FE for ; Thu, 7 Apr 2022 09:15:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 7A51910E936; Thu, 7 Apr 2022 09:15:53 +0000 (UTC) Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5F62910E90C; Thu, 7 Apr 2022 09:15:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1649322952; x=1680858952; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=GDCocADPGy9W8ErEvCBSDhfHLZTsKfBFIsXsxTXRCO0=; b=gx1dGRuFGGvqVvUOFNmchzBFopBd2tI0xURlfgmS0VO3kDxd6zjVYclc ISnGDuJxil0fdjc3ikhsz4r2DPQw4RrSHezG08Kt8g90d9PMJwuT9SoIx BsdF/NzWrabkVTgl9RrZV8l0VIFLCOg4APoKOHQKd+eYMRm9Jf0+XNmyN cui489VtjYkoBxFXurA9W0Y6HHKkKW/O9Psuf6cgHpaG624aAh0k3aIlS H6m7IxIA17ngkL5iULZVFOb6NGOJITNAl+/qkcDO8kz+GEVMXUqJwgSAj e8s/rFVXaLZIn3+6L8mvmkjqvAeVdIH63H6cT2gs5zo6f4HwLtIiX8DSO Q==; X-IronPort-AV: E=McAfee;i="6200,9189,10309"; a="261450505" X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="261450505" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:51 -0700 X-IronPort-AV: E=Sophos;i="5.90,241,1643702400"; d="scan'208";a="570970751" Received: from kgibala-mobl.ger.corp.intel.com (HELO localhost) ([10.249.142.48]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2022 02:15:48 -0700 From: Jani Nikula To: dri-devel@lists.freedesktop.org Subject: [PATCH 12/12] drm/edid: add EDID block count and size helpers Date: Thu, 7 Apr 2022 12:14:38 +0300 Message-Id: <1626a18cffe0ffb47cb2994739f822dd2023435e.1649322799.git.jani.nikula@intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: MIME-Version: 1.0 Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: jani.nikula@intel.com, intel-gfx@lists.freedesktop.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add some helpers to figure out the EDID extension block count, block count, size, pointers to blocks. Unfortunately, we'll need to cast away the const in a few places where we actually need to access the data. Signed-off-by: Jani Nikula --- drivers/gpu/drm/drm_edid.c | 78 +++++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 22 deletions(-) diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c index 90615e30eaf5..53a57ff5f4a1 100644 --- a/drivers/gpu/drm/drm_edid.c +++ b/drivers/gpu/drm/drm_edid.c @@ -1568,6 +1568,38 @@ static const struct drm_display_mode edid_4k_modes[] = { /*** DDC fetch and block validation ***/ +static int edid_extension_block_count(const struct edid *edid) +{ + return edid->extensions; +} + +static int edid_block_count(const struct edid *edid) +{ + return edid_extension_block_count(edid) + 1; +} + +static int edid_size_by_blocks(int num_blocks) +{ + return num_blocks * EDID_LENGTH; +} + +static int edid_size(const struct edid *edid) +{ + return edid_size_by_blocks(edid_block_count(edid)); +} + +static const void *edid_block_data(const struct edid *edid, int index) +{ + BUILD_BUG_ON(sizeof(*edid) != EDID_LENGTH); + + return edid + index; +} + +static const void *edid_extension_block_data(const struct edid *edid, int index) +{ + return edid_block_data(edid, index + 1); +} + static const u8 edid_header[] = { 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }; @@ -1654,8 +1686,8 @@ bool drm_edid_are_equal(const struct edid *edid1, const struct edid *edid2) return false; if (edid1) { - edid1_len = EDID_LENGTH * (1 + edid1->extensions); - edid2_len = EDID_LENGTH * (1 + edid2->extensions); + edid1_len = edid_size(edid1); + edid2_len = edid_size(edid2); if (edid1_len != edid2_len) return false; @@ -1865,14 +1897,16 @@ EXPORT_SYMBOL(drm_edid_block_valid); bool drm_edid_is_valid(struct edid *edid) { int i; - u8 *raw = (u8 *)edid; if (!edid) return false; - for (i = 0; i <= edid->extensions; i++) - if (!drm_edid_block_valid(raw + i * EDID_LENGTH, i, true, NULL)) + for (i = 0; i < edid_block_count(edid); i++) { + void *block = (void *)edid_block_data(edid, i); + + if (!drm_edid_block_valid(block, i, true, NULL)) return false; + } return true; } @@ -1885,13 +1919,13 @@ static struct edid *edid_filter_invalid_blocks(const struct edid *edid, int valid_extensions = edid->extensions - invalid_blocks; int i; - new = kmalloc_array(valid_extensions + 1, EDID_LENGTH, GFP_KERNEL); + new = kmalloc(edid_size_by_blocks(valid_extensions + 1), GFP_KERNEL); if (!new) goto out; dest_block = new; - for (i = 0; i <= edid->extensions; i++) { - const void *block = edid + i; + for (i = 0; i < edid_block_count(edid); i++) { + const void *block = edid_block_data(edid, i); if (edid_block_valid(block, i == 0)) memcpy(dest_block++, block, EDID_LENGTH); @@ -2101,7 +2135,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, void *context) { enum edid_block_status status; - int j, invalid_blocks = 0; + int i, invalid_blocks = 0; struct edid *edid, *new; edid = drm_get_override_edid(connector); @@ -2133,18 +2167,18 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, goto fail; } - if (edid->extensions == 0) + if (!edid_extension_block_count(edid) == 0) goto ok; - new = krealloc(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL); + new = krealloc(edid, edid_size(edid), GFP_KERNEL); if (!new) goto fail; edid = new; - for (j = 1; j <= edid->extensions; j++) { - void *block = edid + j; + for (i = 1; i < edid_block_count(edid); i++) { + void *block = (void *)edid_block_data(edid, i); - status = edid_block_read(block, j, read_block, context); + status = edid_block_read(block, i, read_block, context); edid_block_status_print(status, block, j); @@ -2156,7 +2190,7 @@ struct edid *drm_do_get_edid(struct drm_connector *connector, } if (invalid_blocks) { - connector_bad_edid(connector, edid, edid->extensions + 1); + connector_bad_edid(connector, edid, edid_block_count(edid)); edid = edid_filter_invalid_blocks(edid, invalid_blocks); } @@ -2321,7 +2355,7 @@ EXPORT_SYMBOL(drm_get_edid_switcheroo); */ struct edid *drm_edid_duplicate(const struct edid *edid) { - return kmemdup(edid, (edid->extensions + 1) * EDID_LENGTH, GFP_KERNEL); + return kmemdup(edid, edid_size(edid), GFP_KERNEL); } EXPORT_SYMBOL(drm_edid_duplicate); @@ -2505,8 +2539,8 @@ drm_for_each_detailed_block(const struct edid *edid, detailed_cb *cb, void *clos for (i = 0; i < EDID_DETAILED_TIMINGS; i++) cb(&(edid->detailed_timings[i]), closure); - for (i = 1; i <= edid->extensions; i++) { - const u8 *ext = (const u8 *)edid + (i * EDID_LENGTH); + for (i = 0; i < edid_extension_block_count(edid); i++) { + const u8 *ext = edid_extension_block_data(edid, i); switch (*ext) { case CEA_EXT: @@ -3476,17 +3510,17 @@ const u8 *drm_find_edid_extension(const struct edid *edid, int i; /* No EDID or EDID extensions */ - if (edid == NULL || edid->extensions == 0) + if (!edid || !edid_extension_block_count(edid)) return NULL; /* Find CEA extension */ - for (i = *ext_index; i < edid->extensions; i++) { - edid_ext = (const u8 *)edid + EDID_LENGTH * (i + 1); + for (i = *ext_index; i < edid_extension_block_count(edid); i++) { + edid_ext = edid_extension_block_data(edid, i); if (edid_block_tag(edid_ext) == ext_id) break; } - if (i >= edid->extensions) + if (i >= edid_extension_block_count(edid)) return NULL; *ext_index = i + 1;