Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp252700imw; Fri, 15 Jul 2022 02:27:28 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vbsGseY/SpzoFi4pR5OBLNk5mI01qLW7mrt2+kIdbkb/dtmpQaPE3mZaG6nWiCaYQgwz+V X-Received: by 2002:a05:6402:430f:b0:43a:d521:bda with SMTP id m15-20020a056402430f00b0043ad5210bdamr18136728edc.69.1657877247759; Fri, 15 Jul 2022 02:27:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657877247; cv=none; d=google.com; s=arc-20160816; b=bMkzp2CQATt1AIdpyLRl75JnXt/rk0faZt6oxjMhg5WHw4W49PsS0WJ4INpVEBf8Im 1Fzs7/frr+sNVmo6CIGl9QmUPo6hSRzASav/ADPpHFJxzucCUVzHZuonqOzXPKZXv0KP zlOuFBJadxqKv++jjywOgSbDo1Z+cKwV+IS2jdioPdLbR64Ra5YJxU0MVrGNg340+GC+ 7xJ7YekqnzvSbp/kTsAa2cblvG210scuWdlwuBHCpPLUQIwOkBOWOF5SkY1DNyT50C00 tlA39c8duS5KD/DmOdEOXCHncYdw7m4TrcH3K9hhuxkxz/RplxIQS/jKzjrsX4mx2AZ0 urDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=O0y+RYDzrC7BoLfR/XRnKx9SMXds+VC3HVCJ6LoOl6Y=; b=aC0tySVZ8TwjIfIl/yFBVmYQuB5aiZl2bdmYiwga+ZLZOf0/nax//ff4dbPfyymudy mVew68j3YdpvBFA27tNwgu/jFrlBWLHFhNt2qZ6tqU5qj9eBDaJSNuLMXiW6Ov0u2rs4 ri7jzqQPTOIcylg3iCKMy0VamjBhM+Q5xp7KX0fYUw1pQORtwH5gWYw+GqA6cphMGUT7 pHe+gtXLOkn7lNHvVBdA/M/rHrBgDcQR/UVp9YNA180+aO+ydWjVgBTPs7gHCGhEcd0D vIJVKWISZF6MyRf7xlavGpPNZjuNRceO/asnKs9qaog6n3BB11lPsjGOw+qafNVpwxOR lF2w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=Qm4XwUJU; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x2-20020a170906804200b00722d5b8794dsi3891089ejw.308.2022.07.15.02.27.03; Fri, 15 Jul 2022 02:27:27 -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=@gmail.com header.s=20210112 header.b=Qm4XwUJU; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232598AbiGOJZW (ORCPT + 99 others); Fri, 15 Jul 2022 05:25:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229782AbiGOJZR (ORCPT ); Fri, 15 Jul 2022 05:25:17 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C56277A7F for ; Fri, 15 Jul 2022 02:25:08 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id j29-20020a05600c1c1d00b003a2fdafdefbso2667459wms.2 for ; Fri, 15 Jul 2022 02:25:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O0y+RYDzrC7BoLfR/XRnKx9SMXds+VC3HVCJ6LoOl6Y=; b=Qm4XwUJUENq9vRCXlo8fO9Wyue/h3z9hatK/IzT/eH3jIY3TKZ1vnLFbkov9QREoi7 G6hnyQrVVoHZubaFLmKyPFDNQSv8f1RmnlxOpXkr4m/oNTl4xDl2fcDeD3pK993cNfHs 3L65CD7oY/WWo3PbltE/ToUCx6fYPa+KxExKAyUSeo4thChgS+T5o8aP1S7Tp18upCyg jJLwSfL7RqkLFhQD3n1Q4CzqTsS4bMohLzM+ICrb8DhEfyhJaAUqpqjLQf48UeTIWYd5 MTp35PfJ7jagsSCZQxraqTALda8PIc7b4c1s7Ke/TV96dJpLe3FfUykgfbANECZCYt41 yLSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O0y+RYDzrC7BoLfR/XRnKx9SMXds+VC3HVCJ6LoOl6Y=; b=qdsIO9xQUE6rZkCYGuSdbL6ZH7kC5RCcrn3LxTpXbDQYbrVNrHxzJa0LCJYOyvXqj/ 6k6XL+7Kk0ncTU6dk1eRgABBtiV11+x/jzK/Q+HkAYa1yuxTMA11d3mLD5itDG4mxd1/ 6O4V3BPglD4GtIdk7qDXbWEgMLE1o7m1EJlWPGnD4RgQkNXWvgGnaCisXDP07sX55OZI jHp4SHzNwf6h6lEA1++9L6CcwnbwGP9onAlnz9IoSVb+Ljl5bIVrOd614dJh2CtLCFR9 ZLIlLrewiTebW7KDfnX/Uz28gJtJOmLZyFq8uQ1oEFLICo62veReGL21c4cs5Qd89kMH DnEw== X-Gm-Message-State: AJIora9itcGQ0o+h9+e70SptGfjWhx57Xdvl3GGvQ4klU3MuK0bAfA1h ieF1vIjhVdtMx36cJFi2+8E= X-Received: by 2002:a05:600c:4e07:b0:3a1:8548:4dd7 with SMTP id b7-20020a05600c4e0700b003a185484dd7mr19742072wmq.170.1657877106323; Fri, 15 Jul 2022 02:25:06 -0700 (PDT) Received: from fedora.. ([2a01:e0a:1d2:1f90:be95:f3a2:4d99:a3b3]) by smtp.gmail.com with ESMTPSA id h4-20020a1c2104000000b00397402ae674sm8233102wmh.11.2022.07.15.02.25.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Jul 2022 02:25:05 -0700 (PDT) From: Matthieu CHARETTE To: maarten.lankhorst@linux.intel.com, mripard@kernel.org, tzimmermann@suse.de, airlied@linux.ie, daniel@ffwll.ch, andrealmeid@igalia.com Cc: dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, Matthieu CHARETTE Subject: [PATCH] drm: Fix EDID firmware load on resume Date: Fri, 15 Jul 2022 11:22:53 +0200 Message-Id: <20220715092253.17529-1-matthieu.charette@gmail.com> X-Mailer: git-send-email 2.36.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 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. Link: https://gitlab.freedesktop.org/drm/amd/-/issues/2061 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..b54cea3f1107 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 +static inline void +drm_cache_edid_firmware(struct drm_connector *connector); static inline struct edid * drm_load_edid_firmware(struct drm_connector *connector) { -- 2.36.1