From patchwork Thu Nov 28 00:28:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shinichiro Kawasaki X-Patchwork-Id: 13887453 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (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 92F26DDAB for ; Thu, 28 Nov 2024 00:28:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732753721; cv=none; b=BK3cJ6XvoDPtZeWkFf6T5oPjKcXYdKc5VhCB8JmXVHXo5rCoEmKye62HrQaoBKjAUukxoLJYaCq/GMeHXqdv8+mcVp39RffVynwWLRranmX+s46CGslHq9Ks3zcvtlBZnJg9MxzbjwsUoIZCn7R2jAkppu39IiI5pZE0TQUR+Wo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732753721; c=relaxed/simple; bh=H360zmVqItcd2atbk96/Y/SuSRUPcE+upBz7d7vhzCw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=g6cYkewXoWO0qBMarQZkDm4k1l3TDLCZfggk4KdIEM9CjbllQz6GemGIUcB3l1lKzzC2baqJuPp1CFZ538IpxyBKxPTQ63A12nAvfmJB21jSr9+3VRuIqs21L9HEVpu8cWQmuMiyrzM4YXADA9H9ESoSkbKT+bTlfFLKD+BjwpY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=nxNI4Dpj; arc=none smtp.client-ip=216.71.153.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="nxNI4Dpj" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1732753720; x=1764289720; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=H360zmVqItcd2atbk96/Y/SuSRUPcE+upBz7d7vhzCw=; b=nxNI4DpjbvbHZ+JTq/qFO71ClKHEamms/V26rkxAD7iaO2X2p149zPl2 QfYhPbRpASWr2q0y6tVHfimIXv0Zxrn1fCxi2qsTdJPIA4c0INRHmh3US cpqo+g5Lqp9Uf28zo7k5pEWtBfVu42YD6zqy1ta1uJFu2hfJLaujMlAuu MH9UKO3extTguqSOI4H6n3g6R+EQ6gf0gEacyqq+Uc+j3ZB3BTRTw52I3 hWVR+vM1MPmhKLCj2B5aGj2bwOFpZYnJosSXrmSJcz9pKuR8eqkTul1PL ykhS6FMAiTehaebgTgW5ew9uTjopSMQOb8PxuoRlYGwlKZyu7hMV8Jl20 w==; X-CSE-ConnectionGUID: B8/wyn7qTHijCozoEIBv0Q== X-CSE-MsgGUID: m0E9k/rhTYmabYfT8iBqwA== X-IronPort-AV: E=Sophos;i="6.12,190,1728921600"; d="scan'208";a="32605712" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Nov 2024 08:28:39 +0800 IronPort-SDR: 6747aa9a_2gE9F9hWocMW2h74drOKFJo7WR4cnn8kl7Nds/l6aH7vrCl Sj2jJuvzz0o/kb8DsohZt1AcFy6HsPocOjmpphA== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Nov 2024 15:26:18 -0800 WDCIronportException: Internal Received: from unknown (HELO shindev.ssa.fujisawa.hgst.com) ([10.149.66.30]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Nov 2024 16:28:38 -0800 From: Shin'ichiro Kawasaki To: platform-driver-x86@vger.kernel.org, Hans de Goede , Andy Shevchenko Cc: ilpo.jarvinen@linux.intel.com, danielwa@cisco.com, Shin'ichiro Kawasaki Subject: [PATCH v4 1/4] p2sb: Factor out p2sb_read_from_cache() Date: Thu, 28 Nov 2024 09:28:33 +0900 Message-ID: <20241128002836.373745-2-shinichiro.kawasaki@wdc.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241128002836.373745-1-shinichiro.kawasaki@wdc.com> References: <20241128002836.373745-1-shinichiro.kawasaki@wdc.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To prepare for the following fix, factor out the code to read the P2SB resource from the cache to the new function p2sb_read_from_cache(). Signed-off-by: Shin'ichiro Kawasaki Reviewed-by: Hans de Goede --- drivers/platform/x86/p2sb.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/drivers/platform/x86/p2sb.c b/drivers/platform/x86/p2sb.c index 31f38309b389..aa34b8a69bc1 100644 --- a/drivers/platform/x86/p2sb.c +++ b/drivers/platform/x86/p2sb.c @@ -171,6 +171,22 @@ static int p2sb_cache_resources(void) return ret; } +static int p2sb_read_from_cache(struct pci_bus *bus, unsigned int devfn, + struct resource *mem) +{ + struct p2sb_res_cache *cache = &p2sb_resources[PCI_FUNC(devfn)]; + + if (cache->bus_dev_id != bus->dev.id) + return -ENODEV; + + if (!p2sb_valid_resource(&cache->res)) + return -ENOENT; + + memcpy(mem, &cache->res, sizeof(*mem)); + + return 0; +} + /** * p2sb_bar - Get Primary to Sideband (P2SB) bridge device BAR * @bus: PCI bus to communicate with @@ -187,8 +203,6 @@ static int p2sb_cache_resources(void) */ int p2sb_bar(struct pci_bus *bus, unsigned int devfn, struct resource *mem) { - struct p2sb_res_cache *cache; - bus = p2sb_get_bus(bus); if (!bus) return -ENODEV; @@ -196,15 +210,7 @@ int p2sb_bar(struct pci_bus *bus, unsigned int devfn, struct resource *mem) if (!devfn) p2sb_get_devfn(&devfn); - cache = &p2sb_resources[PCI_FUNC(devfn)]; - if (cache->bus_dev_id != bus->dev.id) - return -ENODEV; - - if (!p2sb_valid_resource(&cache->res)) - return -ENOENT; - - memcpy(mem, &cache->res, sizeof(*mem)); - return 0; + return p2sb_read_from_cache(bus, devfn, mem); } EXPORT_SYMBOL_GPL(p2sb_bar); From patchwork Thu Nov 28 00:28:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shinichiro Kawasaki X-Patchwork-Id: 13887454 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (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 42DE18F64 for ; Thu, 28 Nov 2024 00:28:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732753721; cv=none; b=ULmxfExaK5vMd94tz2WcaUGp/c0tKa2/sESj4wmI2wGdWAWd3Nm0LWZDA0g3Xonj3mP6UQ1ZsGC1ytD9BPXS3MxfyOxW0+vVl2UgsEGznlsgIXVITzdLMdssw4GoBOShSuVmjDOZSgH3yxaKdCuz9gpto+pEOwKgaV9ZNQ3mlcM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732753721; c=relaxed/simple; bh=xCOEMF2Sh/NT04znjzWMhJmjRlVobjhxjRKkKX0ZD6c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WoJzqBXH/VHWeRmQlF1RoNsz7uCMoDfdAH+1pqayam6vU/8p1cVAeSP0inwVexpk5R0gJt1RuVvxqd8FtxDPatTtPmGLYYvpELbOxQllmFkWgR74xDeE3ig1WG064+//o1EgpB8h1XKMTdCgsVWq+Yh75OFvk3LxDEFiNAu6yow= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=luPEq8Xc; arc=none smtp.client-ip=216.71.153.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="luPEq8Xc" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1732753720; x=1764289720; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=xCOEMF2Sh/NT04znjzWMhJmjRlVobjhxjRKkKX0ZD6c=; b=luPEq8XcQ/lmqV/HJsqyppWecDTAv5p2mv4ccpX/rkZBE+9plnJ2lqhc 76GfEbGpEKKqpMApihY9jTFg1sUFzuHmKQwJRhLPLfuPHl/6L725Nt+w/ cK6/nCwMW260+RQ0XzNQeugZce3a4N9TuuENj1meiYHffjB+NzI5NRuvy IZ7dpD7RmlQ/LdBqm54oB0U0baFzLiWlkT4fxPhcJzYdwrQa/fJVL5psv K8SB3xjrQsqjLfQbm1hv/qBNorXSx7Jjk9nHecD2dH/Zpijp1Bog9UVsr 37aADHiRRvi4FhHVmok/RRzmICxSPJ2LAMGe28VFuUKA/dENEz7czTNKa Q==; X-CSE-ConnectionGUID: orvgEYTtTgOLmIm+180Z3g== X-CSE-MsgGUID: SLy1PDcNQw2MeMVwQm+02w== X-IronPort-AV: E=Sophos;i="6.12,190,1728921600"; d="scan'208";a="32605714" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Nov 2024 08:28:40 +0800 IronPort-SDR: 6747aa9b_/aMirHOsDEWtXiGlDyHwbwfdrWWiLw35vuw8X4AOuamzjz2 IeuXSkY6xE4IZ6BE6kRf53PbuOwflnrfpVvOsow== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Nov 2024 15:26:20 -0800 WDCIronportException: Internal Received: from unknown (HELO shindev.ssa.fujisawa.hgst.com) ([10.149.66.30]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Nov 2024 16:28:39 -0800 From: Shin'ichiro Kawasaki To: platform-driver-x86@vger.kernel.org, Hans de Goede , Andy Shevchenko Cc: ilpo.jarvinen@linux.intel.com, danielwa@cisco.com, Shin'ichiro Kawasaki Subject: [PATCH v4 2/4] p2sb: Introduce the global flag p2sb_hidden_by_bios Date: Thu, 28 Nov 2024 09:28:34 +0900 Message-ID: <20241128002836.373745-3-shinichiro.kawasaki@wdc.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241128002836.373745-1-shinichiro.kawasaki@wdc.com> References: <20241128002836.373745-1-shinichiro.kawasaki@wdc.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To prepare for the following fix, introduce the global flag p2sb_hidden_by_bios. Check if the BIOS hides the P2SB device and store the result in the flag. This allows to refer to the check result across functions. Signed-off-by: Shin'ichiro Kawasaki Reviewed-by: Hans de Goede --- drivers/platform/x86/p2sb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/platform/x86/p2sb.c b/drivers/platform/x86/p2sb.c index aa34b8a69bc1..273ac90c8fbd 100644 --- a/drivers/platform/x86/p2sb.c +++ b/drivers/platform/x86/p2sb.c @@ -42,6 +42,7 @@ struct p2sb_res_cache { }; static struct p2sb_res_cache p2sb_resources[NR_P2SB_RES_CACHE]; +static bool p2sb_hidden_by_bios; static void p2sb_get_devfn(unsigned int *devfn) { @@ -157,13 +158,14 @@ static int p2sb_cache_resources(void) * Unhide the P2SB device here, if needed. */ pci_bus_read_config_dword(bus, devfn_p2sb, P2SBC, &value); - if (value & P2SBC_HIDE) + p2sb_hidden_by_bios = value & P2SBC_HIDE; + if (p2sb_hidden_by_bios) pci_bus_write_config_dword(bus, devfn_p2sb, P2SBC, 0); ret = p2sb_scan_and_cache(bus, devfn_p2sb); /* Hide the P2SB device, if it was hidden */ - if (value & P2SBC_HIDE) + if (p2sb_hidden_by_bios) pci_bus_write_config_dword(bus, devfn_p2sb, P2SBC, P2SBC_HIDE); pci_unlock_rescan_remove(); From patchwork Thu Nov 28 00:28:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shinichiro Kawasaki X-Patchwork-Id: 13887455 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (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 94FA7A93D for ; Thu, 28 Nov 2024 00:28:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732753723; cv=none; b=iTBqshHwLC2JmalsilNlLZGXGf6L1cs+SyWQjddQZ9fAG/sUuCTZxcE3apJg/JYQw1Xw4i03DKoQe4hkUgEVHGF99c3Nn78HaDuqriTolBopikVjQjK48LHWowYrjW5gHz8pRhifLawhVdEfn2zXfO6Fp3XhbHvOx4c4361/2Jw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732753723; c=relaxed/simple; bh=zCQ71AJkoGwyIGw5aiYqYzPtxk04vVSfm1rrz2UuMSo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=MEnkhCfwXj82fqZIx7O4LdIVXI2UlU9zrapkQoRjIovEbqErrymkhYebk7snD3O3t32LeUCO3Vm0s8rZNMa+C7cEbRlWBP6DadJxZACcrdaOX0qZqK79h5JxILYteP/lRj+vo6O6k/JjBXPzyjqIEaQJ52wF6lNcSfwWp4jlFG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=j0K6Ewkh; arc=none smtp.client-ip=216.71.153.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="j0K6Ewkh" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1732753722; x=1764289722; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=zCQ71AJkoGwyIGw5aiYqYzPtxk04vVSfm1rrz2UuMSo=; b=j0K6EwkhTaQjHiJPBzxws6090RUzPM/kAmo5d53DcszyOQpgaAoMj6pK 4n9+M12vFCjpaka/t4ZRjxJJbFergzzwnEjdReUgz9CHtKdzxaX8GXwsQ gAGwoZOA45+rvgPK6azdOCnRNsD64m+9qb1MeGjiAXZZAYgB82HsV7fjA TfbdvfvV0BDfTUwVfa2AK7tjJfTUhzkdUGsSiZSC4lzED/XVepQO32mXG ZjXDAcvb/A+q/nAm7NtITfryyblT9Y6apnmYNDzVetD91UZRfpLpjD/xS K822grjur01cPtdOykFf20e0IS9jcEPoaT2H2EdeVxEJUj27sY7IjgoLb Q==; X-CSE-ConnectionGUID: MB0lAfYHTUuKNtb3W0PX2A== X-CSE-MsgGUID: NGP8xd4kT4+9CUSebjGDig== X-IronPort-AV: E=Sophos;i="6.12,190,1728921600"; d="scan'208";a="32605720" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Nov 2024 08:28:42 +0800 IronPort-SDR: 6747aa9c_g0y8soBEdRck+NHfKtUMTIxLpnEq+uc8+t/XWddhYeo+Ut/ 0xM6vYz5qt7jCJ5iNFUtdW1Junqg2qPrJh90W5w== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Nov 2024 15:26:21 -0800 WDCIronportException: Internal Received: from unknown (HELO shindev.ssa.fujisawa.hgst.com) ([10.149.66.30]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Nov 2024 16:28:40 -0800 From: Shin'ichiro Kawasaki To: platform-driver-x86@vger.kernel.org, Hans de Goede , Andy Shevchenko Cc: ilpo.jarvinen@linux.intel.com, danielwa@cisco.com, Shin'ichiro Kawasaki Subject: [PATCH v4 3/4] p2sb: Move P2SB hide and unhide code to p2sb_scan_and_cache() Date: Thu, 28 Nov 2024 09:28:35 +0900 Message-ID: <20241128002836.373745-4-shinichiro.kawasaki@wdc.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241128002836.373745-1-shinichiro.kawasaki@wdc.com> References: <20241128002836.373745-1-shinichiro.kawasaki@wdc.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To prepare for the following fix, move the code to hide and unhide the P2SB device from p2sb_cache_resources() to p2sb_scan_and_cache(). Signed-off-by: Shin'ichiro Kawasaki Reviewed-by: Hans de Goede --- drivers/platform/x86/p2sb.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/drivers/platform/x86/p2sb.c b/drivers/platform/x86/p2sb.c index 273ac90c8fbd..0bc6b21c4c20 100644 --- a/drivers/platform/x86/p2sb.c +++ b/drivers/platform/x86/p2sb.c @@ -97,6 +97,14 @@ static void p2sb_scan_and_cache_devfn(struct pci_bus *bus, unsigned int devfn) static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn) { + /* + * The BIOS prevents the P2SB device from being enumerated by the PCI + * subsystem, so we need to unhide and hide it back to lookup the BAR. + * Unhide the P2SB device here, if needed. + */ + if (p2sb_hidden_by_bios) + pci_bus_write_config_dword(bus, devfn, P2SBC, 0); + /* Scan the P2SB device and cache its BAR0 */ p2sb_scan_and_cache_devfn(bus, devfn); @@ -104,6 +112,10 @@ static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn) if (devfn == P2SB_DEVFN_GOLDMONT) p2sb_scan_and_cache_devfn(bus, SPI_DEVFN_GOLDMONT); + /* Hide the P2SB device, if it was hidden */ + if (p2sb_hidden_by_bios) + pci_bus_write_config_dword(bus, devfn, P2SBC, P2SBC_HIDE); + if (!p2sb_valid_resource(&p2sb_resources[PCI_FUNC(devfn)].res)) return -ENOENT; @@ -152,22 +164,11 @@ static int p2sb_cache_resources(void) */ pci_lock_rescan_remove(); - /* - * The BIOS prevents the P2SB device from being enumerated by the PCI - * subsystem, so we need to unhide and hide it back to lookup the BAR. - * Unhide the P2SB device here, if needed. - */ pci_bus_read_config_dword(bus, devfn_p2sb, P2SBC, &value); p2sb_hidden_by_bios = value & P2SBC_HIDE; - if (p2sb_hidden_by_bios) - pci_bus_write_config_dword(bus, devfn_p2sb, P2SBC, 0); ret = p2sb_scan_and_cache(bus, devfn_p2sb); - /* Hide the P2SB device, if it was hidden */ - if (p2sb_hidden_by_bios) - pci_bus_write_config_dword(bus, devfn_p2sb, P2SBC, P2SBC_HIDE); - pci_unlock_rescan_remove(); return ret; From patchwork Thu Nov 28 00:28:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shinichiro Kawasaki X-Patchwork-Id: 13887456 Received: from esa3.hgst.iphmx.com (esa3.hgst.iphmx.com [216.71.153.141]) (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 C47938F64 for ; Thu, 28 Nov 2024 00:28:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=216.71.153.141 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732753724; cv=none; b=O1RwKOaZXdnbJX7rw9sHrjd9CNG5JtBpQjRIxscmsrw8p9rgHTPGwqPR6utzvj7afRK6nEjvVMQt00Zpl6hXI4sm1ic+vnL0ORrQskAFMbgiEn3X/kXxpcyJHLSsACP8+1OQHSlIRKAYEQeFM18CqSzDPHu4lCvqMEegQjXtUD4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732753724; c=relaxed/simple; bh=VNtbFFkcpnDe7mxxpCDHubJfS44qlBtPRva34M+zs20=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=qEDcvgJLawHdFtcV6zO1wDJpMQSYz83LzMU0eHGkDBI3g8dEeaVmGfiHU9V/RFbq2ft+XKVvqcPQDE3ZJICgBQXlbMWRh6G1BLUyNm5k/sy5FoMy9M2OjIXgur2D9adsnuHHNOI3NnKYKjvyVw6YIKU4aekfcwasKCQkgmcUls4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com; spf=pass smtp.mailfrom=wdc.com; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b=cQQErOjP; arc=none smtp.client-ip=216.71.153.141 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=wdc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=wdc.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=wdc.com header.i=@wdc.com header.b="cQQErOjP" DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1732753723; x=1764289723; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=VNtbFFkcpnDe7mxxpCDHubJfS44qlBtPRva34M+zs20=; b=cQQErOjPnMhA7oCQ1UfilLHXWq7DyBE0eZRxLT4sJTlmDcCtRWzMurYJ x2FjPsGbl0ye8BV6IulPVrWlVWhteEOFrfVSpEPqdyIdRpEHJg76UW0LM S2kr8xhixHxZZYsQZj263cjQKE/9VHoJm2WFwmVA/W49BIwQzgJmGIpT2 pTiYDevaLnfAjvm//uOh3hUdEuP2aTjIftUcbXOimH6QyIgSw0oJ9AHPr pramdfLMEC/RCEfLe2pjujtaWLZddIRZucyo9vki/tX3+S2J9HARUxt2x r+4kBDFCuwl3skl5NGupD9lzT1TYjnzCNmAuGXbHVbX5iiSddYTd1smU6 g==; X-CSE-ConnectionGUID: MjMKdDeaQ9Wn1DHy9s/vGQ== X-CSE-MsgGUID: 1eBkyGX8RQiwc5OpaQaeZg== X-IronPort-AV: E=Sophos;i="6.12,190,1728921600"; d="scan'208";a="32605721" Received: from uls-op-cesaip02.wdc.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 28 Nov 2024 08:28:43 +0800 IronPort-SDR: 6747aa9e_BGNRx+Q2zmn49/AekFnlOBorf3gn8NXHep0vz69TSaKhgXO iIFYcryWsN8rLuEj3n6bl9osx/x7FkZKInViJ/A== Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES128-GCM-SHA256; 27 Nov 2024 15:26:22 -0800 WDCIronportException: Internal Received: from unknown (HELO shindev.ssa.fujisawa.hgst.com) ([10.149.66.30]) by uls-op-cesaip01.wdc.com with ESMTP; 27 Nov 2024 16:28:42 -0800 From: Shin'ichiro Kawasaki To: platform-driver-x86@vger.kernel.org, Hans de Goede , Andy Shevchenko Cc: ilpo.jarvinen@linux.intel.com, danielwa@cisco.com, Shin'ichiro Kawasaki Subject: [PATCH v4 4/4] p2sb: Do not scan and remove the P2SB device when it is unhidden Date: Thu, 28 Nov 2024 09:28:36 +0900 Message-ID: <20241128002836.373745-5-shinichiro.kawasaki@wdc.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241128002836.373745-1-shinichiro.kawasaki@wdc.com> References: <20241128002836.373745-1-shinichiro.kawasaki@wdc.com> Precedence: bulk X-Mailing-List: platform-driver-x86@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 When drivers access P2SB device resources, it calls p2sb_bar(). Before the commit 5913320eb0b3 ("platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe"), p2sb_bar() obtained the resources and then called pci_stop_and_remove_bus_device() for clean up. Then the P2SB device disappeared. The commit 5913320eb0b3 introduced the P2SB device resource cache feature in the boot process. During the resource cache, pci_stop_and_remove_bus_device() is called for the P2SB device, then the P2SB device disappears regardless of whether p2sb_bar() is called or not. Such P2SB device disappearance caused a confusion [1]. To avoid the confusion, avoid the pci_stop_and_remove_bus_device() call when the BIOS does not hide the P2SB device. For that purpose, cache the P2SB device resources only if the BIOS hides the P2SB device. Call p2sb_scan_and_cache() only if p2sb_hidden_by_bios is true. This allows removing two branches from p2sb_scan_and_cache(). When p2sb_bar() is called, get the resources from the cache if the P2SB device is hidden. Otherwise, read the resources from the unhidden P2SB device. Reported-by: "Daniel Walker (danielwa)" Closes: https://lore.kernel.org/lkml/ZzTI+biIUTvFT6NC@goliath/ [1] Fixes: 5913320eb0b3 ("platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe") Signed-off-by: Shin'ichiro Kawasaki Reviewed-by: Hans de Goede --- drivers/platform/x86/p2sb.c | 42 +++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 9 deletions(-) diff --git a/drivers/platform/x86/p2sb.c b/drivers/platform/x86/p2sb.c index 0bc6b21c4c20..c56650b9ff96 100644 --- a/drivers/platform/x86/p2sb.c +++ b/drivers/platform/x86/p2sb.c @@ -100,10 +100,8 @@ static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn) /* * The BIOS prevents the P2SB device from being enumerated by the PCI * subsystem, so we need to unhide and hide it back to lookup the BAR. - * Unhide the P2SB device here, if needed. */ - if (p2sb_hidden_by_bios) - pci_bus_write_config_dword(bus, devfn, P2SBC, 0); + pci_bus_write_config_dword(bus, devfn, P2SBC, 0); /* Scan the P2SB device and cache its BAR0 */ p2sb_scan_and_cache_devfn(bus, devfn); @@ -112,9 +110,7 @@ static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn) if (devfn == P2SB_DEVFN_GOLDMONT) p2sb_scan_and_cache_devfn(bus, SPI_DEVFN_GOLDMONT); - /* Hide the P2SB device, if it was hidden */ - if (p2sb_hidden_by_bios) - pci_bus_write_config_dword(bus, devfn, P2SBC, P2SBC_HIDE); + pci_bus_write_config_dword(bus, devfn, P2SBC, P2SBC_HIDE); if (!p2sb_valid_resource(&p2sb_resources[PCI_FUNC(devfn)].res)) return -ENOENT; @@ -141,7 +137,7 @@ static int p2sb_cache_resources(void) u32 value = P2SBC_HIDE; struct pci_bus *bus; u16 class; - int ret; + int ret = 0; /* Get devfn for P2SB device itself */ p2sb_get_devfn(&devfn_p2sb); @@ -167,7 +163,12 @@ static int p2sb_cache_resources(void) pci_bus_read_config_dword(bus, devfn_p2sb, P2SBC, &value); p2sb_hidden_by_bios = value & P2SBC_HIDE; - ret = p2sb_scan_and_cache(bus, devfn_p2sb); + /* + * If the BIOS does not hide the P2SB device then its resources + * are accesilble. Cache them only if the P2SB device is hidden. + */ + if (p2sb_hidden_by_bios) + ret = p2sb_scan_and_cache(bus, devfn_p2sb); pci_unlock_rescan_remove(); @@ -190,6 +191,26 @@ static int p2sb_read_from_cache(struct pci_bus *bus, unsigned int devfn, return 0; } +static int p2sb_read_from_dev(struct pci_bus *bus, unsigned int devfn, + struct resource *mem) +{ + struct pci_dev *pdev; + int ret = 0; + + pdev = pci_get_slot(bus, devfn); + if (!pdev) + return -ENODEV; + + if (p2sb_valid_resource(pci_resource_n(pdev, 0))) + p2sb_read_bar0(pdev, mem); + else + ret = -ENOENT; + + pci_dev_put(pdev); + + return ret; +} + /** * p2sb_bar - Get Primary to Sideband (P2SB) bridge device BAR * @bus: PCI bus to communicate with @@ -213,7 +234,10 @@ int p2sb_bar(struct pci_bus *bus, unsigned int devfn, struct resource *mem) if (!devfn) p2sb_get_devfn(&devfn); - return p2sb_read_from_cache(bus, devfn, mem); + if (p2sb_hidden_by_bios) + return p2sb_read_from_cache(bus, devfn, mem); + + return p2sb_read_from_dev(bus, devfn, mem); } EXPORT_SYMBOL_GPL(p2sb_bar);