Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp948715lqs; Wed, 6 Mar 2024 01:28:48 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCUgyabAPrTFIP0yr3TkNOqfAXhEM2JxPcJ2KxswM1+fQaLbGzgjeb2DqHjXb2uGWEdYsrIFMGiq0xmFiFHZC0fzR/hqisfNRbGQesMuOg== X-Google-Smtp-Source: AGHT+IHRc24CBcp1mnoOZHB09CUa/4gkCkv5b4y1vJ2muJ1/svUIwTJQV0EHumUsvhTbXuyMOA3r X-Received: by 2002:a05:6808:a07:b0:3c1:eef0:88d9 with SMTP id n7-20020a0568080a0700b003c1eef088d9mr4190959oij.57.1709717327989; Wed, 06 Mar 2024 01:28:47 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709717327; cv=pass; d=google.com; s=arc-20160816; b=pzjJP0wSa6JcgORaFvGXmGXYKvh65ZkDbuqcSThLAGKvZ0ES2kQD3Y14C52fMTQYPh UVUcVLqMg5D+2ruc742xCqIMgGsdDIh2hwIwwjQOcd+EbKS1qcU6vvwHQv1fZPXjJoQ1 +7Kp7Dd5DDmWu7rZU5h0aLGmiYEC6yxK9a70N0Rw71KNJYaIOvLhX2xRy834vwSOA+ss c4Z5K85NC5cuNvatYP0b32OqXdpzIbs26FJzcQqX6StCnCiesJ88L8QxgPSduGB+oa7l tBgHdiadDNGTAF95v137I484ipv1xyeMFwbnKXXo1sFssnbesTWPK2yEYKEI1Yf7jIQo AKJA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:references:organization:in-reply-to:subject:cc:to :from:dkim-signature; bh=gjMEW9yXD8/5o1usGhK/57tvWFkZkfqJHx5wwWJ81uo=; fh=j8R91R4C7W09DW0hqt3DCC2LgtHqu3BkVbedLMzUihg=; b=xafWSsvOmEz30K3UjswLAEXLUyLVyBE/wHqkW3of+1IYTgE1zFSCMAuuHlMwLHBSqy fGJnWgaHF7fPUTK2ZghCNoDWCwlRBdsigwg94riz8izbZMZX1Cx7Ba76a0b9NHKnP6an jW5H+72xlSuDgQm0DTz7z0Ir+hEVei4hquRFruoMHPcVG7kkOy7nluat1TphwGEtt4Au i3DsTAItjUJeAKP60dgefcqgSkCI2GnfFQ44JmErzQQl1173aele+eDS572Fav1tyh2B QMJ56P3YflnGS9gQvEOvUAji983MQ55N99uJIhW/2e1bdAJjCFWXogqg8uI4Y12lS/Ys LktQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TuaaJn85; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-93610-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93610-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id bx19-20020a056a02051300b005dc85e8a9e1si12463727pgb.45.2024.03.06.01.28.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Mar 2024 01:28:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-93610-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=TuaaJn85; arc=pass (i=1 spf=pass spfdomain=intel.com dkim=pass dkdomain=intel.com dmarc=pass fromdomain=linux.intel.com); spf=pass (google.com: domain of linux-kernel+bounces-93610-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-93610-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 5C60228FA5C for ; Wed, 6 Mar 2024 09:18:01 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DD5B65DF18; Wed, 6 Mar 2024 09:17:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="TuaaJn85" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 23C7C5F54D for ; Wed, 6 Mar 2024 09:17:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.13 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709716628; cv=none; b=HaNNPiU1w/vYZPb2jDS6e6vrtEnMl9wgcH1a4hkGWhsybR13nl4e94USKNIr1OF0BWfmWsuBzrtOmIeZQ9YcTRpQWX4GMVg+OO/OsiAkhkXrc6MGtgCwBQgphbR6NBvapuq2/nOAJScdClag+gyOseZTdhLUlvIXY1yhAZAh4l8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709716628; c=relaxed/simple; bh=IUe3cAnoMPthLD2FcvfY1gDuS5k9Mc7AV8gDfGAWObY=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=RGmBwKq+Zxh5QPTXykApdrc0nF2lFIEiG064y3stm1DHGAGyizpFx30z2Rh18fOMNwWjgpuxjmLVRQJgJBWHR68W0FZB8GNsoCw9tGB4r6+J7MHMawGu6ggTACjfVxiNq07+qosMpDxIt5Aye0wH83S1tOc7WPyCKpLEpDz6P3c= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=TuaaJn85; arc=none smtp.client-ip=192.198.163.13 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1709716627; x=1741252627; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=IUe3cAnoMPthLD2FcvfY1gDuS5k9Mc7AV8gDfGAWObY=; b=TuaaJn85bbZdN6zPtEp5+1CReL9vu9kl5UWdfa1y/ktkRdY1+VYkB3XR 7XBw3Ztn6UUxVtYsBo+8YZszjUZu+mQeQhH9d945So2FGbWTAp2brCiw6 TRBp8k38iQ73lxZGBcL2P0ZBabNPjqVuEh1VA/8eH7v/fKhLXdKhaW8bu ava9oYR1F8bSVxQOckAGa82E8aKEeUAce7Ox+gxuSoGprjftlPYmtqWhj XOp5iQdMZkcf6LwtYlubDeXz+hYoqpLAJO0+E0FOd75yDIEpYO1PM4+MW MKCekUblXhaQIzjsZ4D2VplsoxQVpBHssVCgq0PpeUNVM8BfBpmoT91JC Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11004"; a="7260737" X-IronPort-AV: E=Sophos;i="6.06,207,1705392000"; d="scan'208";a="7260737" Received: from fmviesa006.fm.intel.com ([10.60.135.146]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 01:17:06 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,207,1705392000"; d="scan'208";a="9855181" Received: from rjongalo-mobl2.ger.corp.intel.com (HELO localhost) ([10.252.33.211]) by fmviesa006-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Mar 2024 01:17:02 -0800 From: Jani Nikula To: Hsin-Yi Wang , Dmitry Baryshkov , Douglas Anderson Cc: Neil Armstrong , Jessica Zhang , Sam Ravnborg , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v4 2/5] drm/edid: Add a function to match EDID with identity In-Reply-To: <20240306004347.974304-3-hsinyi@chromium.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20240306004347.974304-1-hsinyi@chromium.org> <20240306004347.974304-3-hsinyi@chromium.org> Date: Wed, 06 Mar 2024 11:16:59 +0200 Message-ID: <87sf13zpmc.fsf@intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain On Tue, 05 Mar 2024, Hsin-Yi Wang wrote: > Create a type drm_edid_ident as the identity of an EDID. Currently it > contains panel id and monitor name. > > Create a function that can match a given EDID and an identity: > 1. Reject if the panel id doesn't match. > 2. If name is not null in identity, try to match it in the detailed timing > blocks. Note that some panel vendors put the monitor name after > EDID_DETAIL_MONITOR_STRING. > > Signed-off-by: Hsin-Yi Wang > --- > v3->v4: > 1. add a type drm_edid_ident > 2. match name -> match identity. Modify function to use edid iterators. > --- > drivers/gpu/drm/drm_edid.c | 76 ++++++++++++++++++++++++++++++++++++++ > include/drm/drm_edid.h | 8 ++++ > 2 files changed, 84 insertions(+) > > diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c > index f9e09f327f81..5e7e69e0e345 100644 > --- a/drivers/gpu/drm/drm_edid.c > +++ b/drivers/gpu/drm/drm_edid.c > @@ -102,6 +102,11 @@ struct detailed_mode_closure { > int modes; > }; > > +struct drm_edid_ident_closure { > + const struct drm_edid_ident *ident; > + bool matched; > +}; More like drm_edid_match_closure. > + > #define LEVEL_DMT 0 > #define LEVEL_GTF 1 > #define LEVEL_GTF2 2 > @@ -5455,6 +5460,77 @@ drm_parse_hdmi_vsdb_audio(struct drm_connector *connector, const u8 *db) > connector->audio_latency[0], connector->audio_latency[1]); > } > > +static void > +match_identity(const struct detailed_timing *timing, void *data) > +{ > + struct drm_edid_ident_closure *closure = data; > + unsigned int i, j; > + const char *str = closure->ident->name; > + unsigned int buflen = strlen(str); > + unsigned int size = ARRAY_SIZE(timing->data.other_data.data.str.str); > + > + if (buflen > size || > + !(is_display_descriptor(timing, EDID_DETAIL_MONITOR_NAME) || > + is_display_descriptor(timing, EDID_DETAIL_MONITOR_STRING))) > + return; > + > + for (i = 0; i < buflen; i++) { > + char c = timing->data.other_data.data.str.str[i]; > + > + if (c != str[i] || c == '\n') > + break; > + } > + > + if (i == buflen) { This will never be true. > + /* Allow trailing white spaces. */ > + for (j = i; j < size; j++) { > + char c = timing->data.other_data.data.str.str[j]; > + > + if (c == '\n') { > + closure->matched = true; > + return; > + } else if (c != ' ') { > + break; > + } > + } > + if (j == size) { > + closure->matched = true; > + return; > + } > + } Please let's use strcmp and friends instead of reinventing our own: const char *name = closure->ident->name; int name_len = strlen(name); const char *desc = timing->data.other_data.data.str.str; int desc_len = ARRAY_SIZE(timing->data.other_data.data.str.str); if (name_len > desc_len) return; if (strncmp(name, desc, name_en)) return; for (i = name_len; i < desc_len; i++) { if (!isspace(desc[i]) && !desc[i]) return; } closure->matched = true; > +} > + > +/** > + * drm_edid_match_identity - match drm_edid with given identity > + * @drm_edid: EDID > + * @ident: the EDID identity to match with > + * > + * Check if the EDID matches with the given identity. > + * > + * Return: True if the given identity matched with EDID, false otherwise. > + */ > +bool drm_edid_match_identity(const struct drm_edid *drm_edid, > + const struct drm_edid_ident *ident) Can we please just call this drm_edid_match()? Is the _identity in the name somehow helpful? > +{ > + if (!drm_edid || edid_extract_panel_id(drm_edid->edid) != ident->panel_id) > + return false; Side note, edid_extract_panel_id() could now be made to take struct drm_edid. > + > + /* Match with name only if it's not NULL. */ > + if (ident->name) { > + struct drm_edid_ident_closure closure = { > + .ident = ident, > + .matched = false, > + }; > + > + drm_for_each_detailed_block(drm_edid, match_identity, &closure); > + > + return closure.matched; > + } > + > + return true; > +} > +EXPORT_SYMBOL(drm_edid_match_identity); > + > static void > monitor_name(const struct detailed_timing *timing, void *data) > { > diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h > index 9686a7cee6a6..01825a8954b6 100644 > --- a/include/drm/drm_edid.h > +++ b/include/drm/drm_edid.h > @@ -312,6 +312,12 @@ struct edid { > u8 checksum; > } __packed; > > +/* EDID matching */ > +struct drm_edid_ident { > + u32 panel_id; > + const char *name; > +}; > + > #define EDID_PRODUCT_ID(e) ((e)->prod_code[0] | ((e)->prod_code[1] << 8)) > > /* Short Audio Descriptor */ > @@ -412,6 +418,8 @@ struct edid *drm_get_edid(struct drm_connector *connector, > struct i2c_adapter *adapter); > const struct drm_edid *drm_edid_read_base_block(struct i2c_adapter *adapter); > u32 drm_edid_get_panel_id(const struct drm_edid *drm_edid); > +bool drm_edid_match_identity(const struct drm_edid *drm_edid, > + const struct drm_edid_ident *ident); > struct edid *drm_get_edid_switcheroo(struct drm_connector *connector, > struct i2c_adapter *adapter); > struct edid *drm_edid_duplicate(const struct edid *edid); -- Jani Nikula, Intel