Received: by 2002:ab2:3141:0:b0:1ed:23cc:44d1 with SMTP id i1csp2094707lqg; Mon, 4 Mar 2024 12:38:34 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCV+/yMJO+GrsYt7mSn8YU/IeHy9qHiHCwTYTq2pCzazcon1VIvpQz93ZOBjswKGJ7HQS6M475l2gK3A1yugV7bbd8A7M7l8PQuY2SlG9A== X-Google-Smtp-Source: AGHT+IEvpok9h0+reyIbqc4obE+CdMnC9NLGA8284/tR9cWQbtbwQvEiqvgFjB5RK1O11+oKI4nl X-Received: by 2002:a0c:fd6a:0:b0:690:4d7:f936 with SMTP id k10-20020a0cfd6a000000b0069004d7f936mr10484340qvs.1.1709584714368; Mon, 04 Mar 2024 12:38:34 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709584714; cv=pass; d=google.com; s=arc-20160816; b=OIMnUvOYLQT6+brVLhdpH91vNZW9GGiIevNhOywIxnVKodUm/U9utaX+CaU5OnU2z0 7u0h06nbYfmI6tGu7Cc32t7hZ0LVFQT7rc7rEKwIU8Sdb5LE/idXC7ma/ufyt7ZXfY82 X6NOSGdY88gIjeR2wJAvYj+8b6fsfP6snR9TmSGZOMQhD4DXyc5Nxco5oC57cXHs0d8s Z3eGdXKwVh26d5NuUXNxnVmJ1jIt7DoCdTGp56v55nWFNQiYK6xmN/NjMLTWrDvlDOq7 /xwKnFx65g/xV2xnpcsuflqrwbhvWkK9gvshdbIfqlZZ2Poj+DEOLe3Y65d8oshvR8/t uqSQ== 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=tIbWm4uW2TFWNIhXDrVr4j3MGL1m45x9RwTuGU7yZOg=; fh=Tns/Yx0QOKMWasyhWYWUTQsFDQNVGk+y/aSyF+BBrjE=; b=L7h33kPGAUmWkPBAkWGlF6LHZVZu62/TAntBT8zzYxSii0YsJnvLWBttZRaYwpqziD 7HU+br3Wa1Umm5l06yK3iVPxHp68GA2aboF14MQfMshUzbEwhOeofIXhrJ+FzutQxMTg gtXgVcZaVB+c93B6OccmoiEPjW0WzVTELSjEkvsm7V8ra25h2nwA4Ppw8WFltWHuJ/dm UcGhKnhcB9a32lXqY0Fjq1C+/Fh2ivWl0dCgCkLm8LejLPGWYff92uxENdtQvaUuAAw+ qSiGq7usbYZ2L+Qv3DLolzB7qENEMYKSFejcNU9FkyBNn5yPBzTo9djdp9yszWGCggdY IwQg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BnIfYEF2; 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-91246-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91246-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id p13-20020a05621421ed00b0068ffe75615csi10612904qvj.269.2024.03.04.12.38.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Mar 2024 12:38:34 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-91246-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=BnIfYEF2; 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-91246-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-91246-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 ny.mirrors.kernel.org (Postfix) with ESMTPS id D858D1C21B57 for ; Mon, 4 Mar 2024 20:38:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C384C9475; Mon, 4 Mar 2024 20:38:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="BnIfYEF2" Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.7]) (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 4E3546FA9 for ; Mon, 4 Mar 2024 20:38:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.7 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709584706; cv=none; b=C3VonknMZSPg9CBo1sKc5oHAICwGnkP9bmCCt1FZmD6IwIhrNk0T98RaNv3MYCnBdQa/FlJgcISNe1VsQYI541T0Yx7s4GGSFKGmLI9WpoNz6wCt7p2OdGtSXii5NPgQn01nFlyNxkN9rnMtghNBNqSsygE6Bb/ZWZFT5WM6Ny4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709584706; c=relaxed/simple; bh=hADy2w2RsgZzbmD0YhXh1NuyAvvGzzITpAmpZ5GBokM=; h=From:To:Cc:Subject:In-Reply-To:References:Date:Message-ID: MIME-Version:Content-Type; b=Ru1/pNUGErIZVBQtXAshGgyLdIj167UM/7LKtHFZuAM4Tnct8tzRi7ZLc59TeR5N2VlI8hGrU0KGi+KltpSwVuN/Q/Wss9mkzjR24Nrheg/qvgqJlrsIHGrpYDiXmSzhqLmTADaMQNXwMQk7iH6+KIh22UE9MzfXVcndicT2wlo= 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=BnIfYEF2; arc=none smtp.client-ip=192.198.163.7 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=1709584704; x=1741120704; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=hADy2w2RsgZzbmD0YhXh1NuyAvvGzzITpAmpZ5GBokM=; b=BnIfYEF2QSkbUAGk/yahK0QFKG1+uBozxZakCdhdk0PtBG0EAENaZPC9 d1htwz/t3gS7h4h0YVyLGoR7qpF8aSnazvQsZ1uPz0KHI504PDoewSE+c YwzHBzTXti3FRrPCbPlLRAqzT0nTXi3nKAhd6DDfCZm8doActmlNekEE0 fwHHWAk0ZAlf6W8lerWzYzLMi8jNDK8j8rIX2racgsjp5PbkNPA3sXlLg ByErdxEH4i8xA3KnTt5KUMT6/P2g3rQQ9KuJsAJ4qPhKtXBz5avxjTw48 e6gkJGfUiGZ0uxHKqrK/0pbSLb/NKV3Je9AKfXm4aTfnfDPJPs18/LxsZ Q==; X-IronPort-AV: E=McAfee;i="6600,9927,11003"; a="29528147" X-IronPort-AV: E=Sophos;i="6.06,204,1705392000"; d="scan'208";a="29528147" Received: from orviesa006.jf.intel.com ([10.64.159.146]) by fmvoesa101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 12:38:23 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,204,1705392000"; d="scan'208";a="9539229" Received: from syakovle-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.51.3]) by orviesa006-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Mar 2024 12:38:19 -0800 From: Jani Nikula To: Hsin-Yi Wang , 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, Dmitry Baryshkov Subject: Re: [PATCH v3 2/4] drm/edid: Add a function to check monitor string In-Reply-To: <20240304195214.14563-3-hsinyi@chromium.org> Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <20240304195214.14563-1-hsinyi@chromium.org> <20240304195214.14563-3-hsinyi@chromium.org> Date: Mon, 04 Mar 2024 22:38:07 +0200 Message-ID: <87a5nd4tsg.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 Mon, 04 Mar 2024, Hsin-Yi Wang wrote: > Add a function to check if the EDID base block contains a given string. > > One of the use cases is fetching panel from a list of panel names, since > some panel vendors put the monitor name after EDID_DETAIL_MONITOR_STRING > instead of EDID_DETAIL_MONITOR_NAME. > > Signed-off-by: Hsin-Yi Wang > --- > v2->v3: move string matching to drm_edid > --- > drivers/gpu/drm/drm_edid.c | 49 ++++++++++++++++++++++++++++++++++++++ > include/drm/drm_edid.h | 1 + > 2 files changed, 50 insertions(+) > > diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c > index 13454bc64ca2..fcdc2bd143dd 100644 > --- a/drivers/gpu/drm/drm_edid.c > +++ b/drivers/gpu/drm/drm_edid.c > @@ -2789,6 +2789,55 @@ u32 drm_edid_get_panel_id(struct edid_base_block *base_block) > } > EXPORT_SYMBOL(drm_edid_get_panel_id); > > +/** > + * drm_edid_has_monitor_string - Check if a EDID base block has certain string. > + * @base_block: EDID base block to check. > + * @str: pointer to a character array to hold the string to be checked. > + * > + * Check if the detailed timings section of a EDID base block has the given > + * string. > + * > + * Return: True if the EDID base block contains the string, false otherwise. > + */ > +bool drm_edid_has_monitor_string(struct edid_base_block *base_block, const char *str) > +{ > + unsigned int i, j, k, buflen = strlen(str); > + > + for (i = 0; i < EDID_DETAILED_TIMINGS; i++) { > + struct detailed_timing *timing = &base_block->edid.detailed_timings[i]; > + unsigned int size = ARRAY_SIZE(timing->data.other_data.data.str.str); > + > + if (buflen > size || timing->pixel_clock != 0 || > + timing->data.other_data.pad1 != 0 || > + (timing->data.other_data.type != EDID_DETAIL_MONITOR_NAME && > + timing->data.other_data.type != EDID_DETAIL_MONITOR_STRING)) > + continue; > + > + for (j = 0; j < buflen; j++) { > + char c = timing->data.other_data.data.str.str[j]; > + > + if (c != str[j] || c == '\n') > + break; > + } > + > + if (j == buflen) { > + /* Allow trailing white spaces. */ > + for (k = j; k < size; k++) { > + char c = timing->data.other_data.data.str.str[k]; > + > + if (c == '\n') > + return true; > + else if (c != ' ') > + break; > + } > + if (k == size) > + return true; > + } > + } > + > + return false; > +} > + So we've put a lot of effort into converting from struct edid to struct drm_edid, passing that around in drm_edid.c, with the allocation size it provides, and generally cleaning stuff up. I'm not at all happy to see *another* struct added just for the base block, and detailed timing iteration as well as monitor name parsing duplicated. With struct drm_edid you can actually return an EDID that only has the base block and size 128, even if the EDID indicates more extensions. Because the whole thing is *designed* to handle that gracefully. The allocated size matters, not what the blob originating outside of the kernel tells you. What I'm thinking is: - Add some struct drm_edid_ident or similar. Add all the information that's needed to identify a panel there. I guess initially that's panel_id and name. struct drm_edid_ident { u32 panel_id; const char *name; }; - Add function: bool drm_edid_match(const struct drm_edid *drm_edid, const struct drm_edid_ident *ident); Check if stuff in ident matches drm_edid. You can use and extend the existing drm_edid based iteration etc. in drm_edid.c. Straightforward. The fields in ident can trivially be extended later, and the stuff can be useful for other drivers and quirks etc. - Restructure struct edp_panel_entry to contain struct drm_edid_ident. Change the iteration of edp_panels array to use drm_edid_match() on the array elements and the edid. - Add a function to read the EDID base block *but* make it return const struct drm_edid *. Add warnings in the comments that it's only for panel and for transition until it switches to reading full EDIDs. const struct drm_edid *drm_edid_read_base_block(struct i2c_adapter *adapter); This is the *only* hackish part of the whole thing, and it's nicely isolated. For the most part you can use drm_edid_get_panel_id() code for this, just return the blob wrapped in a struct drm_edid envelope. - Remove function: u32 drm_edid_get_panel_id(struct i2c_adapter *adapter); - Refactor edid_quirk_list to use the same id struct and match function and mechanism within drm_edid.c (can be follow-up too). - Once you change the panel code to read the whole EDID using drm_edid_read family of functions in the future, you don't have to change *anything* about the iteration or matching or anything, because it's already passing struct drm_edid around. I hope this covers everything. BR, Jani. > /** > * drm_edid_get_base_block - Get a panel's EDID base block > * @adapter: I2C adapter to use for DDC > diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h > index 2455d6ab2221..248ddb0a6b5d 100644 > --- a/include/drm/drm_edid.h > +++ b/include/drm/drm_edid.h > @@ -416,6 +416,7 @@ struct edid *drm_get_edid(struct drm_connector *connector, > struct i2c_adapter *adapter); > struct edid_base_block *drm_edid_get_base_block(struct i2c_adapter *adapter); > u32 drm_edid_get_panel_id(struct edid_base_block *base_block); > +bool drm_edid_has_monitor_string(struct edid_base_block *base_block, const char *str); > 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