Unverified Commit 360c400d authored by Shin'ichiro Kawasaki's avatar Shin'ichiro Kawasaki Committed by Ilpo Järvinen
Browse files

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 5913320e ("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 5913320e 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: default avatarDaniel Walker (danielwa) <danielwa@cisco.com>
Closes: https://lore.kernel.org/lkml/ZzTI+biIUTvFT6NC@goliath/

 [1]
Fixes: 5913320e ("platform/x86: p2sb: Allow p2sb_bar() calls during PCI device probe")
Signed-off-by: default avatarShin'ichiro Kawasaki <shinichiro.kawasaki@wdc.com>
Reviewed-by: default avatarHans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20241128002836.373745-5-shinichiro.kawasaki@wdc.com


Reviewed-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
Signed-off-by: default avatarIlpo Järvinen <ilpo.jarvinen@linux.intel.com>
parent 0286070c
Loading
Loading
Loading
Loading
+33 −9
Original line number Diff line number Diff line
@@ -101,9 +101,7 @@ 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 */
@@ -113,8 +111,6 @@ 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))
@@ -142,7 +138,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);
@@ -168,6 +164,11 @@ static int p2sb_cache_resources(void)
	pci_bus_read_config_dword(bus, devfn_p2sb, P2SBC, &value);
	p2sb_hidden_by_bios = value & P2SBC_HIDE;

	/*
	 * 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();
@@ -191,6 +192,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
@@ -214,7 +235,10 @@ int p2sb_bar(struct pci_bus *bus, unsigned int devfn, struct resource *mem)
	if (!devfn)
		p2sb_get_devfn(&devfn);

	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);