git: 82d692771239 - main - pci: Clear active PME# and disable PME# generation
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 27 Mar 2025 20:59:48 UTC
The branch main has been updated by jhb: URL: https://cgit.FreeBSD.org/src/commit/?id=82d692771239f1d156a875087dff4cf09f0e8b80 commit 82d692771239f1d156a875087dff4cf09f0e8b80 Author: John Baldwin <jhb@FreeBSD.org> AuthorDate: 2025-03-27 20:53:24 +0000 Commit: John Baldwin <jhb@FreeBSD.org> CommitDate: 2025-03-27 20:53:24 +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 --- 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 8a3c36b0f8aa..7b48a32b5387 100644 --- a/share/man/man9/Makefile +++ b/share/man/man9/Makefile @@ -1790,6 +1790,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 21467a11cb68..e4d546799482 100644 --- a/sys/dev/cardbus/cardbus.c +++ b/sys/dev/cardbus/cardbus.c @@ -212,6 +212,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 ad13e7f9a3a4..4c7ca27d8e64 100644 --- a/sys/dev/pci/pci.c +++ b/sys/dev/pci/pci.c @@ -2936,6 +2936,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. */ @@ -4472,6 +4488,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) @@ -4662,6 +4679,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 c0d54f8e58e0..1f99e9830930 100644 --- a/sys/dev/pci/pcivar.h +++ b/sys/dev/pci/pcivar.h @@ -686,6 +686,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,