git: b5bc47f1e1ab - stable/14 - pci: Clear active PME# and disable PME# generation
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 29 Apr 2025 18:30:47 UTC
The branch stable/14 has been updated by jhb:
URL: https://cgit.FreeBSD.org/src/commit/?id=b5bc47f1e1ab31086c1bf2e68944ea0331059c2c
commit b5bc47f1e1ab31086c1bf2e68944ea0331059c2c
Author: John Baldwin <jhb@FreeBSD.org>
AuthorDate: 2025-03-27 20:53:24 +0000
Commit: John Baldwin <jhb@FreeBSD.org>
CommitDate: 2025-04-29 14:44:25 +0000
pci: Clear active PME# and disable PME# generation
The PCI power management specification requires that the OS clear any
pending PME# interrupt and generation of PME# interrupts during
"initial operating system load". Note that clearing a pending PME#
interrupt requires writing a 1 to the Read/Write-Clear PME bit in the
power management status register. To handle the boot time case, clear
PME# state in pci_read_cap() when scanning new PCI devices. This
should also cover hotplug devices.
In addition, clear this state on every PCI device after resume from
sleep in pci_resume_child before invoking the driver's DEVICE_RESUME
method.
Reviewed by: imp
Differential Revision: https://reviews.freebsd.org/D49222
(cherry picked from commit 82d692771239f1d156a875087dff4cf09f0e8b80)
---
share/man/man9/Makefile | 1 +
share/man/man9/pci.9 | 8 ++++++++
sys/dev/cardbus/cardbus.c | 1 +
sys/dev/pci/pci.c | 18 ++++++++++++++++++
sys/dev/pci/pcivar.h | 1 +
5 files changed, 29 insertions(+)
diff --git a/share/man/man9/Makefile b/share/man/man9/Makefile
index 3ee1d2bb0108..dcaf1d4ac5ed 100644
--- a/share/man/man9/Makefile
+++ b/share/man/man9/Makefile
@@ -1781,6 +1781,7 @@ MLINKS+=panic.9 vpanic.9 \
panic.9 KERNEL_PANICKED.9
MLINKS+=pci.9 pci_alloc_msi.9 \
pci.9 pci_alloc_msix.9 \
+ pci.9 pci_clear_pme.9 \
pci.9 pci_disable_busmaster.9 \
pci.9 pci_disable_io.9 \
pci.9 pci_enable_busmaster.9 \
diff --git a/share/man/man9/pci.9 b/share/man/man9/pci.9
index 3c3e54bf8760..0f3fc92c23e7 100644
--- a/share/man/man9/pci.9
+++ b/share/man/man9/pci.9
@@ -30,6 +30,7 @@
.Nm pci ,
.Nm pci_alloc_msi ,
.Nm pci_alloc_msix ,
+.Nm pci_clear_pme ,
.Nm pci_disable_busmaster ,
.Nm pci_disable_io ,
.Nm pci_enable_busmaster ,
@@ -81,6 +82,8 @@
.Fn pci_alloc_msi "device_t dev" "int *count"
.Ft int
.Fn pci_alloc_msix "device_t dev" "int *count"
+.Ft void
+.Fn pci_clear_pme "device_t dev"
.Ft int
.Fn pci_disable_busmaster "device_t dev"
.Ft int
@@ -670,6 +673,11 @@ then the function will fail with
.Er EOPNOTSUPP .
.Pp
The
+.Fn pci_clear_pme
+function is used to clear any pending PME# signal and disable generation
+of power management events.
+.Pp
+The
.Fn pci_iov_attach
function is used to advertise that the given device
.Pq and associated device driver
diff --git a/sys/dev/cardbus/cardbus.c b/sys/dev/cardbus/cardbus.c
index 261e9a5205ae..8dd543c68677 100644
--- a/sys/dev/cardbus/cardbus.c
+++ b/sys/dev/cardbus/cardbus.c
@@ -223,6 +223,7 @@ cardbus_attach_card(device_t cbdev)
DEVPRINTF((cbdev, "Warning: Bogus CIS ignored\n"));
pci_cfg_save(dinfo->pci.cfg.dev, &dinfo->pci, 0);
pci_cfg_restore(dinfo->pci.cfg.dev, &dinfo->pci);
+ pci_clear_pme(child);
cardbus_device_setup_regs(&dinfo->pci.cfg);
pci_add_resources(cbdev, child, 1, dinfo->mprefetchable);
pci_print_verbose(&dinfo->pci);
diff --git a/sys/dev/pci/pci.c b/sys/dev/pci/pci.c
index 7107fbe4884b..a99c34271f96 100644
--- a/sys/dev/pci/pci.c
+++ b/sys/dev/pci/pci.c
@@ -2921,6 +2921,22 @@ pci_get_powerstate_method(device_t dev, device_t child)
return (result);
}
+/* Clear any active PME# and disable PME# generation. */
+void
+pci_clear_pme(device_t dev)
+{
+ struct pci_devinfo *dinfo = device_get_ivars(dev);
+ pcicfgregs *cfg = &dinfo->cfg;
+ uint16_t status;
+
+ if (cfg->pp.pp_cap != 0) {
+ status = pci_read_config(dev, dinfo->cfg.pp.pp_status, 2);
+ status &= ~PCIM_PSTAT_PMEENABLE;
+ status |= PCIM_PSTAT_PME;
+ pci_write_config(dev, dinfo->cfg.pp.pp_status, status, 2);
+ }
+}
+
/*
* Some convenience functions for PCI device drivers.
*/
@@ -4466,6 +4482,7 @@ pci_add_child(device_t bus, struct pci_devinfo *dinfo)
resource_list_init(&dinfo->resources);
pci_cfg_save(dev, dinfo, 0);
pci_cfg_restore(dev, dinfo);
+ pci_clear_pme(dev);
pci_print_verbose(dinfo);
pci_add_resources(bus, dev, 0, 0);
if (pci_enable_mps_tune)
@@ -4665,6 +4682,7 @@ pci_resume_child(device_t dev, device_t child)
dinfo = device_get_ivars(child);
pci_cfg_restore(child, dinfo);
+ pci_clear_pme(child);
if (!device_is_attached(child))
pci_cfg_save(child, dinfo, 1);
diff --git a/sys/dev/pci/pcivar.h b/sys/dev/pci/pcivar.h
index 888159d59c1a..d365b9132069 100644
--- a/sys/dev/pci/pcivar.h
+++ b/sys/dev/pci/pcivar.h
@@ -685,6 +685,7 @@ void pci_restore_state(device_t dev);
void pci_save_state(device_t dev);
int pci_set_max_read_req(device_t dev, int size);
int pci_power_reset(device_t dev);
+void pci_clear_pme(device_t dev);
uint32_t pcie_read_config(device_t dev, int reg, int width);
void pcie_write_config(device_t dev, int reg, uint32_t value, int width);
uint32_t pcie_adjust_config(device_t dev, int reg, uint32_t mask,