mirror of
https://github.com/opnsense/src.git
synced 2026-02-18 18:20:26 -05:00
pci: Add helper routines to manage PME in device drivers
pci_has_pm is a quick check that returns true if a PCI device supports the power management capability. pci_enable_pme can be used in DEVICE_SUSPEND driver methods to enable PME# during suspend. Reviewed by: Krzysztof Galazka <krzysztof.galazka@intel.com>x Differential Revision: https://reviews.freebsd.org/D49250 (cherry picked from commit e5cbf0e881fa1851912be77c62aa7ab17f844c3d)
This commit is contained in:
parent
b5bc47f1e1
commit
b8b5dbdb93
4 changed files with 46 additions and 1 deletions
|
|
@ -1786,6 +1786,7 @@ MLINKS+=pci.9 pci_alloc_msi.9 \
|
|||
pci.9 pci_disable_io.9 \
|
||||
pci.9 pci_enable_busmaster.9 \
|
||||
pci.9 pci_enable_io.9 \
|
||||
pci.9 pci_enable_pme.9 \
|
||||
pci.9 pci_find_bsf.9 \
|
||||
pci.9 pci_find_cap.9 \
|
||||
pci.9 pci_find_dbsf.9 \
|
||||
|
|
@ -1798,6 +1799,7 @@ MLINKS+=pci.9 pci_alloc_msi.9 \
|
|||
pci.9 pci_get_powerstate.9 \
|
||||
pci.9 pci_get_vpd_ident.9 \
|
||||
pci.9 pci_get_vpd_readonly.9 \
|
||||
pci.9 pci_has_pm.9 \
|
||||
pci.9 pci_iov_attach.9 \
|
||||
pci.9 pci_iov_attach_name.9 \
|
||||
pci.9 pci_iov_detach.9 \
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@
|
|||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.Dd May 20, 2021
|
||||
.Dd March 27, 2025
|
||||
.Dt PCI 9
|
||||
.Os
|
||||
.Sh NAME
|
||||
|
|
@ -35,6 +35,7 @@
|
|||
.Nm pci_disable_io ,
|
||||
.Nm pci_enable_busmaster ,
|
||||
.Nm pci_enable_io ,
|
||||
.Nm pci_enable_pme ,
|
||||
.Nm pci_find_bsf ,
|
||||
.Nm pci_find_cap ,
|
||||
.Nm pci_find_dbsf ,
|
||||
|
|
@ -51,6 +52,7 @@
|
|||
.Nm pci_get_powerstate ,
|
||||
.Nm pci_get_vpd_ident ,
|
||||
.Nm pci_get_vpd_readonly ,
|
||||
.Nm pci_has_pm ,
|
||||
.Nm pci_iov_attach ,
|
||||
.Nm pci_iov_attach_name ,
|
||||
.Nm pci_iov_detach ,
|
||||
|
|
@ -92,6 +94,8 @@
|
|||
.Fn pci_enable_busmaster "device_t dev"
|
||||
.Ft int
|
||||
.Fn pci_enable_io "device_t dev" "int space"
|
||||
.Ft void
|
||||
.Fn pci_enable_pme "device_t dev"
|
||||
.Ft device_t
|
||||
.Fn pci_find_bsf "uint8_t bus" "uint8_t slot" "uint8_t func"
|
||||
.Ft int
|
||||
|
|
@ -124,6 +128,8 @@
|
|||
.Fn pci_get_vpd_ident "device_t dev" "const char **identptr"
|
||||
.Ft int
|
||||
.Fn pci_get_vpd_readonly "device_t dev" "const char *kw" "const char **vptr"
|
||||
.Ft bool
|
||||
.Fn pci_has_pm "device_t dev"
|
||||
.Ft int
|
||||
.Fn pci_msi_count "device_t dev"
|
||||
.Ft int
|
||||
|
|
@ -358,6 +364,12 @@ When no more instances are located
|
|||
returns an error.
|
||||
.Pp
|
||||
The
|
||||
.Fn pci_has_pm
|
||||
function returns true if
|
||||
.Fa dev
|
||||
supports power management.
|
||||
.Pp
|
||||
The
|
||||
.Fn pci_find_extcap
|
||||
function is used to locate the first instance of a PCI-express
|
||||
extended capability register set for the device
|
||||
|
|
@ -678,6 +690,11 @@ function is used to clear any pending PME# signal and disable generation
|
|||
of power management events.
|
||||
.Pp
|
||||
The
|
||||
.Fn pci_enable_pme
|
||||
function is used to enable generation of power management events before
|
||||
suspending a device.
|
||||
.Pp
|
||||
The
|
||||
.Fn pci_iov_attach
|
||||
function is used to advertise that the given device
|
||||
.Pq and associated device driver
|
||||
|
|
|
|||
|
|
@ -2937,6 +2937,30 @@ pci_clear_pme(device_t dev)
|
|||
}
|
||||
}
|
||||
|
||||
/* Clear any active PME# and enable PME# generation. */
|
||||
void
|
||||
pci_enable_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_PME | PCIM_PSTAT_PMEENABLE;
|
||||
pci_write_config(dev, dinfo->cfg.pp.pp_status, status, 2);
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
pci_has_pm(device_t dev)
|
||||
{
|
||||
struct pci_devinfo *dinfo = device_get_ivars(dev);
|
||||
pcicfgregs *cfg = &dinfo->cfg;
|
||||
|
||||
return (cfg->pp.pp_cap != 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* Some convenience functions for PCI device drivers.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -686,6 +686,8 @@ 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);
|
||||
void pci_enable_pme(device_t dev);
|
||||
bool pci_has_pm(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,
|
||||
|
|
|
|||
Loading…
Reference in a new issue