Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp5016135rwb; Mon, 8 Aug 2022 10:36:18 -0700 (PDT) X-Google-Smtp-Source: AA6agR4G3Khod4Hhz71eNwrFfkLakORi7NMiny/LCqvErYeehJ6+yuMRCthLTSUXiIwCatk+v094 X-Received: by 2002:a63:4b1b:0:b0:41d:548f:8e29 with SMTP id y27-20020a634b1b000000b0041d548f8e29mr7566395pga.77.1659980178233; Mon, 08 Aug 2022 10:36:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659980178; cv=none; d=google.com; s=arc-20160816; b=aClDS9khyqhSl+MOgN3dAIgTFY6hnslSmJ6iWZtphiBrqKHT3QCiuTIm+VKcBLdtdj XwwMDQANUBXxE+eqwHx9aU9h2h258lZFxdaUuE4/y07khkXdmZhOBl/aqOE+u3XrOgSg c1LFtTvHhG8uqhipItOi3jchSto97mAXC1b0PDNFUb2qV9J1TJZH7LSCUxKlR4zENvE4 +orl6IJHSmk4jD2m0749rRMfA1e4zsYsMf2nSOAUIDzCvgl6Z69mkuz40aTdIhk/b5Eb JMPJ+7a3SimT8tUKNkkD+UwKe7mwa02BvQjAX+1/OLm4F5R6B+rdoa0VfIqfrPLN2bSj g6Cw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:message-id:date:references :organization:in-reply-to:subject:cc:to:from:dkim-signature; bh=p8ZuG0K1cpa32BaR+CSDJveCtQgDXVUyd2qX1Y6GJ0A=; b=hSa4w723lR78MNVbM6GXg98qPuEvOKF9loHkRxbvuc6PKfCPpg7gxlCux0xupokmS8 IxrAz++tcSmfsaIWVET9WYOr2c3RAoRj0Y7PyunAaGyDxzC4DOONYRtxhAh+lB4ER1cR mSfxQ2FRJ/9xvo01XXCHAe77aHjd0WNWUtpKZNBtM77jNjsYm7TXrlb4v+qWY1b5VWXu qUCm9/axRhrUpzudMRk5kUFRh/i660pB6IqedCLgXUbMFF2dTvtdtT/NyYi0ze9MD1Dy TCmC6BJfNVfu7FDwSRzetqAXE6zYU62DTf1ukxTeHZJn8CDkP5qGH+izHh9xRLwcmUIO YUfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lyp0WK5e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f65-20020a623844000000b0050cfb4ff72dsi3667139pfa.52.2022.08.08.10.36.04; Mon, 08 Aug 2022 10:36:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=lyp0WK5e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234943AbiHHRTK (ORCPT + 99 others); Mon, 8 Aug 2022 13:19:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233696AbiHHRTI (ORCPT ); Mon, 8 Aug 2022 13:19:08 -0400 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52AA19582 for ; Mon, 8 Aug 2022 10:19:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1659979146; x=1691515146; h=from:to:cc:subject:in-reply-to:references:date: message-id:mime-version; bh=2M0Gift2bIkEpuyV+QSRuLQemKZWmk9fMTillQXnu7w=; b=lyp0WK5eVHA1Bc/+2z2HPhiAxCht6nNTMytXntYgiPLGgFM4s/1cUMwC AAqjQJ6T7T6l3NJr3TyBEyyr6EgpQUqvHc81Atulehtv0vPP5Yl+N2LrQ Aux7GZ2KNKI8RRW65Z1E7mhw6QbEBkmSXc4Bwi2bIt5KCOw+/qIPDtKkS GI4tmLH6TmEohBwc23uY+2eKkDEmcTmF71HPkzCCS/MMHxAwKxeTXJqeE k/82s80Dr1JTgW82rt+uB+adE3zvlTNwzwkdvdUQX4+iyUjHODB4JeCWA e68zmqocTwIS15E1Zl0rAwV/RMaQyFoeL7f41cLgoQbZPgxVdOAw7eQ4K Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10433"; a="291885080" X-IronPort-AV: E=Sophos;i="5.93,222,1654585200"; d="scan'208";a="291885080" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Aug 2022 10:19:05 -0700 X-IronPort-AV: E=Sophos;i="5.93,222,1654585200"; d="scan'208";a="664048967" Received: from ograu-mobl.ger.corp.intel.com (HELO localhost) ([10.252.63.143]) by fmsmga008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 08 Aug 2022 10:19:03 -0700 From: Jani Nikula To: Matthieu CHARETTE Cc: lkp@intel.com, kbuild-all@lists.01.org, tzimmermann@suse.de, airlied@linux.ie, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, andrealmeid@igalia.com Subject: Re: [PATCH] drm: Fix EDID firmware load on resume In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo References: <202207172035.mtErdlaw-lkp@intel.com> <20220727074152.43059-1-matthieu.charette@gmail.com> <87wnbqen2f.fsf@intel.com> Date: Mon, 08 Aug 2022 20:19:01 +0300 Message-ID: <87edxqodq2.fsf@intel.com> MIME-Version: 1.0 Content-Type: text/plain X-Spam-Status: No, score=-4.9 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 08 Aug 2022, Matthieu CHARETTE wrote: > Sorry, What do you mean? You cache with one name at connector init time, but the name specified using drm.edid_firmware may be changed whenever, to cause the next EDID read to use a different EDID firmware. BR, Jani. > > Matthieu > > On Tue, Aug 2 2022 at 05:29:12 PM +0300, Jani Nikula > wrote: >> On Wed, 27 Jul 2022, Matthieu CHARETTE > > wrote: >>> Loading an EDID using drm.edid_firmware parameter makes resume to >>> fail >>> after firmware cache is being cleaned. This is because edid_load() >>> use a >>> temporary device to request the firmware. This cause the EDID >>> firmware >>> not to be cached from suspend. And, requesting the EDID firmware >>> return >>> an error during resume. >>> So the request_firmware() call should use a permanent device for >>> each >>> connector. Also, we should cache the EDID even if no monitor is >>> connected, in case it's plugged while suspended. >> >> AFAICT this breaks changing drm.edid_firmware runtime. >> >> BR, >> Jani. >> >>> >>> Link: >>> Signed-off-by: Matthieu CHARETTE >> > >>> --- >>> drivers/gpu/drm/drm_connector.c | 9 ++++ >>> drivers/gpu/drm/drm_edid_load.c | 81 >>> ++++++++++++++++++++++++++++----- >>> include/drm/drm_connector.h | 12 +++++ >>> include/drm/drm_edid.h | 3 ++ >>> 4 files changed, 94 insertions(+), 11 deletions(-) >>> >>> diff --git a/drivers/gpu/drm/drm_connector.c >>> b/drivers/gpu/drm/drm_connector.c >>> index 1c48d162c77e..e8819ebf1c4b 100644 >>> --- a/drivers/gpu/drm/drm_connector.c >>> +++ b/drivers/gpu/drm/drm_connector.c >>> @@ -31,6 +31,7 @@ >>> #include >>> #include >>> >>> +#include >>> #include >>> >>> #include "drm_crtc_internal.h" >>> @@ -289,6 +290,9 @@ int drm_connector_init(struct drm_device *dev, >>> >>> drm_connector_get_cmdline_mode(connector); >>> >>> + connector->edid_load_pdev = NULL; >>> + drm_cache_edid_firmware(connector); >>> + >>> /* We should add connectors at the end to avoid upsetting the >>> connector >>> * index too much. >>> */ >>> @@ -473,6 +477,11 @@ void drm_connector_cleanup(struct >>> drm_connector *connector) >>> connector->tile_group = NULL; >>> } >>> >>> + if (connector->edid_load_pdev) { >>> + platform_device_unregister(connector->edid_load_pdev); >>> + connector->edid_load_pdev = NULL; >>> + } >>> + >>> list_for_each_entry_safe(mode, t, &connector->probed_modes, head) >>> drm_mode_remove(connector, mode); >>> >>> diff --git a/drivers/gpu/drm/drm_edid_load.c >>> b/drivers/gpu/drm/drm_edid_load.c >>> index 37d8ba3ddb46..5a82be9917ec 100644 >>> --- a/drivers/gpu/drm/drm_edid_load.c >>> +++ b/drivers/gpu/drm/drm_edid_load.c >>> @@ -167,6 +167,19 @@ static int edid_size(const u8 *edid, int >>> data_size) >>> return (edid[0x7e] + 1) * EDID_LENGTH; >>> } >>> >>> +static struct platform_device *edid_pdev(const char >>> *connector_name) >>> +{ >>> + struct platform_device *pdev = >>> platform_device_register_simple(connector_name, -1, NULL, 0); >>> + >>> + if (IS_ERR(pdev)) { >>> + DRM_ERROR("Failed to register EDID firmware platform device " >>> + "for connector \"%s\"\n", connector_name); >>> + return ERR_CAST(pdev); >>> + } >>> + >>> + return pdev; >>> +} >>> + >>> static void *edid_load(struct drm_connector *connector, const char >>> *name, >>> const char *connector_name) >>> { >>> @@ -182,18 +195,17 @@ static void *edid_load(struct drm_connector >>> *connector, const char *name, >>> fwdata = generic_edid[builtin]; >>> fwsize = sizeof(generic_edid[builtin]); >>> } else { >>> - struct platform_device *pdev; >>> + struct platform_device *pdev = connector->edid_load_pdev; >>> int err; >>> >>> - pdev = platform_device_register_simple(connector_name, -1, NULL, >>> 0); >>> - if (IS_ERR(pdev)) { >>> - DRM_ERROR("Failed to register EDID firmware platform device " >>> - "for connector \"%s\"\n", connector_name); >>> - return ERR_CAST(pdev); >>> + if (WARN_ON(!pdev)) { >>> + pdev = edid_pdev(connector_name); >>> + if (IS_ERR(pdev)) >>> + return ERR_CAST(pdev); >>> + connector->edid_load_pdev = pdev; >>> } >>> >>> err = request_firmware(&fw, name, &pdev->dev); >>> - platform_device_unregister(pdev); >>> if (err) { >>> DRM_ERROR("Requesting EDID firmware \"%s\" failed (err=%d)\n", >>> name, err); >>> @@ -263,11 +275,9 @@ static void *edid_load(struct drm_connector >>> *connector, const char *name, >>> return edid; >>> } >>> >>> -struct edid *drm_load_edid_firmware(struct drm_connector >>> *connector) >>> +static char *edid_name(const char *connector_name) >>> { >>> - const char *connector_name = connector->name; >>> char *edidname, *last, *colon, *fwstr, *edidstr, *fallback = NULL; >>> - struct edid *edid; >>> >>> if (edid_firmware[0] == '\0') >>> return ERR_PTR(-ENOENT); >>> @@ -310,8 +320,57 @@ struct edid *drm_load_edid_firmware(struct >>> drm_connector *connector) >>> if (*last == '\n') >>> *last = '\0'; >>> >>> - edid = edid_load(connector, edidname, connector_name); >>> + edidname = kstrdup(edidname, GFP_KERNEL); >>> + if (!edidname) { >>> + kfree(fwstr); >>> + return ERR_PTR(-ENOMEM); >>> + } >>> + >>> kfree(fwstr); >>> + return edidname; >>> +} >>> + >>> +void drm_cache_edid_firmware(struct drm_connector *connector) >>> +{ >>> + const char *connector_name = connector->name; >>> + const char *edidname = edid_name(connector_name); >>> + struct platform_device *pdev; >>> + int err; >>> + >>> + if (IS_ERR(edidname)) >>> + return; >>> + >>> + if (match_string(generic_edid_name, GENERIC_EDIDS, edidname) >= >>> 0) { >>> + kfree(edidname); >>> + return; >>> + } >>> + >>> + pdev = edid_pdev(connector_name); >>> + if (IS_ERR(pdev)) { >>> + kfree(edidname); >>> + return; >>> + } >>> + connector->edid_load_pdev = pdev; >>> + >>> + err = firmware_request_cache(&pdev->dev, edidname); >>> + if (err) >>> + DRM_ERROR("Requesting EDID firmware cache \"%s\" failed >>> (err=%d)\n", >>> + edidname, err); >>> + >>> + kfree(edidname); >>> +} >>> + >>> +struct edid *drm_load_edid_firmware(struct drm_connector >>> *connector) >>> +{ >>> + const char *connector_name = connector->name; >>> + const char *edidname = edid_name(connector_name); >>> + struct edid *edid; >>> + >>> + if (IS_ERR(edidname)) >>> + return ERR_CAST(edidname); >>> + >>> + edid = edid_load(connector, edidname, connector_name); >>> + kfree(edidname); >>> >>> return edid; >>> } >>> diff --git a/include/drm/drm_connector.h >>> b/include/drm/drm_connector.h >>> index 3ac4bf87f257..47c84741517e 100644 >>> --- a/include/drm/drm_connector.h >>> +++ b/include/drm/drm_connector.h >>> @@ -1573,6 +1573,18 @@ struct drm_connector { >>> */ >>> struct i2c_adapter *ddc; >>> >>> + /** >>> + * @edid_load_pdev: Platform device for loading EDID via firmware. >>> + * >>> + * The platform device is registered in drm_connector_init() in >>> case a >>> + * custom EDID firmware is used with `edid_firmware` parameter. >>> Otherwise, >>> + * it is set to NULL. >>> + * >>> + * Platform device is unregistered in drm_connector_cleanup() if >>> it >>> + * is not NULL. >>> + */ >>> + struct platform_device *edid_load_pdev; >>> + >>> /** >>> * @null_edid_counter: track sinks that give us all zeros for the >>> EDID. >>> * Needed to workaround some HW bugs where we get all 0s >>> diff --git a/include/drm/drm_edid.h b/include/drm/drm_edid.h >>> index b2756753370b..e907c928a35d 100644 >>> --- a/include/drm/drm_edid.h >>> +++ b/include/drm/drm_edid.h >>> @@ -378,10 +378,13 @@ int drm_av_sync_delay(struct drm_connector >>> *connector, >>> const struct drm_display_mode *mode); >>> >>> #ifdef CONFIG_DRM_LOAD_EDID_FIRMWARE >>> +void drm_cache_edid_firmware(struct drm_connector *connector); >>> struct edid *drm_load_edid_firmware(struct drm_connector >>> *connector); >>> int __drm_set_edid_firmware_path(const char *path); >>> int __drm_get_edid_firmware_path(char *buf, size_t bufsize); >>> #else >>> +inline void >>> +drm_cache_edid_firmware(struct drm_connector *connector); >>> static inline struct edid * >>> drm_load_edid_firmware(struct drm_connector *connector) >>> { >> >> -- >> Jani Nikula, Intel Open Source Graphics Center > -- Jani Nikula, Intel Open Source Graphics Center