Skip to content

Commit 360c400

Browse files
kawasakiij-intel
authored andcommitted
p2sb: Do not scan and remove the P2SB device when it is unhidden
When drivers access P2SB device resources, it calls p2sb_bar(). Before the commit 5913320 ("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 5913320 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) <danielwa@cisco.com> Closes: https://lore.kernel.org/lkml/ZzTI+biIUTvFT6NC@goliath/ [1] Fixes: 5913320 ("platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe") Signed-off-by: Shin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Link: https://lore.kernel.org/r/20241128002836.373745-5-shinichiro.kawasaki@wdc.com Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com> Signed-off-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
1 parent 0286070 commit 360c400

File tree

1 file changed

+33
-9
lines changed

1 file changed

+33
-9
lines changed

drivers/platform/x86/p2sb.c

Lines changed: 33 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,8 @@ static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn)
101101
/*
102102
* The BIOS prevents the P2SB device from being enumerated by the PCI
103103
* subsystem, so we need to unhide and hide it back to lookup the BAR.
104-
* Unhide the P2SB device here, if needed.
105104
*/
106-
if (p2sb_hidden_by_bios)
107-
pci_bus_write_config_dword(bus, devfn, P2SBC, 0);
105+
pci_bus_write_config_dword(bus, devfn, P2SBC, 0);
108106

109107
/* Scan the P2SB device and cache its BAR0 */
110108
p2sb_scan_and_cache_devfn(bus, devfn);
@@ -113,9 +111,7 @@ static int p2sb_scan_and_cache(struct pci_bus *bus, unsigned int devfn)
113111
if (devfn == P2SB_DEVFN_GOLDMONT)
114112
p2sb_scan_and_cache_devfn(bus, SPI_DEVFN_GOLDMONT);
115113

116-
/* Hide the P2SB device, if it was hidden */
117-
if (p2sb_hidden_by_bios)
118-
pci_bus_write_config_dword(bus, devfn, P2SBC, P2SBC_HIDE);
114+
pci_bus_write_config_dword(bus, devfn, P2SBC, P2SBC_HIDE);
119115

120116
if (!p2sb_valid_resource(&p2sb_resources[PCI_FUNC(devfn)].res))
121117
return -ENOENT;
@@ -142,7 +138,7 @@ static int p2sb_cache_resources(void)
142138
u32 value = P2SBC_HIDE;
143139
struct pci_bus *bus;
144140
u16 class;
145-
int ret;
141+
int ret = 0;
146142

147143
/* Get devfn for P2SB device itself */
148144
p2sb_get_devfn(&devfn_p2sb);
@@ -168,7 +164,12 @@ static int p2sb_cache_resources(void)
168164
pci_bus_read_config_dword(bus, devfn_p2sb, P2SBC, &value);
169165
p2sb_hidden_by_bios = value & P2SBC_HIDE;
170166

171-
ret = p2sb_scan_and_cache(bus, devfn_p2sb);
167+
/*
168+
* If the BIOS does not hide the P2SB device then its resources
169+
* are accesilble. Cache them only if the P2SB device is hidden.
170+
*/
171+
if (p2sb_hidden_by_bios)
172+
ret = p2sb_scan_and_cache(bus, devfn_p2sb);
172173

173174
pci_unlock_rescan_remove();
174175

@@ -191,6 +192,26 @@ static int p2sb_read_from_cache(struct pci_bus *bus, unsigned int devfn,
191192
return 0;
192193
}
193194

195+
static int p2sb_read_from_dev(struct pci_bus *bus, unsigned int devfn,
196+
struct resource *mem)
197+
{
198+
struct pci_dev *pdev;
199+
int ret = 0;
200+
201+
pdev = pci_get_slot(bus, devfn);
202+
if (!pdev)
203+
return -ENODEV;
204+
205+
if (p2sb_valid_resource(pci_resource_n(pdev, 0)))
206+
p2sb_read_bar0(pdev, mem);
207+
else
208+
ret = -ENOENT;
209+
210+
pci_dev_put(pdev);
211+
212+
return ret;
213+
}
214+
194215
/**
195216
* p2sb_bar - Get Primary to Sideband (P2SB) bridge device BAR
196217
* @bus: PCI bus to communicate with
@@ -214,7 +235,10 @@ int p2sb_bar(struct pci_bus *bus, unsigned int devfn, struct resource *mem)
214235
if (!devfn)
215236
p2sb_get_devfn(&devfn);
216237

217-
return p2sb_read_from_cache(bus, devfn, mem);
238+
if (p2sb_hidden_by_bios)
239+
return p2sb_read_from_cache(bus, devfn, mem);
240+
241+
return p2sb_read_from_dev(bus, devfn, mem);
218242
}
219243
EXPORT_SYMBOL_GPL(p2sb_bar);
220244

0 commit comments

Comments
 (0)