diff options
author | Furquan Shaikh <furquan@google.com> | 2020-10-03 16:23:55 -0700 |
---|---|---|
committer | Furquan Shaikh <furquan@google.com> | 2020-10-11 02:13:17 +0000 |
commit | 494f319be78dc08c72d58cdd94bf09213b48238c (patch) | |
tree | a01aed9b05a1a35a9e57f88b111ca5746cc73166 /src/device | |
parent | 35a77428b2b3c24ac7e68b3961f866044dcea800 (diff) |
pci_device: Add a helper function for determining if PCI device is wake source
This change adds a helper function `pci_dev_is_wake_source()` that
checks PME_STATUS and PME_ENABLE bits in PM control and status
register to determine if the given device is the source of wake.
BUG=b:169802515
BRANCH=zork
Change-Id: I06e9530b568543ab2f05a4f38dc5c3a527ff391e
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/46030
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Rob Barnes <robbarnes@google.com>
Reviewed-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Diffstat (limited to 'src/device')
-rw-r--r-- | src/device/pci_device.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/device/pci_device.c b/src/device/pci_device.c index 8a6f123969..ce3e50967a 100644 --- a/src/device/pci_device.c +++ b/src/device/pci_device.c @@ -1643,3 +1643,21 @@ void pci_dev_disable_bus_master(const struct device *dev) pci_update_config16(dev, PCI_COMMAND, ~PCI_COMMAND_MASTER, 0x0); } #endif + +bool pci_dev_is_wake_source(const struct device *dev) +{ + unsigned int pm_cap; + uint16_t pmcs; + + if (dev->path.type != DEVICE_PATH_PCI) + return false; + + pm_cap = pci_find_capability(dev, PCI_CAP_ID_PM); + if (!pm_cap) + return false; + + pmcs = pci_read_config16(dev, pm_cap + PCI_PM_CTRL); + + /* PCI Device is a wake source if PME_ENABLE and PME_STATUS are set in PMCS register. */ + return (pmcs & PCI_PM_CTRL_PME_ENABLE) && (pmcs & PCI_PM_CTRL_PME_STATUS); +} |