Furquan Shaikh has uploaded this change for review.

View Change

pci_device: Add a helper function for logging PCI device as wake source

This change adds a helper function `pci_dev_log_wake()` 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 and logs it in
eventlog if CONFIG_ELOG is selected. The caller is expected to pass in
the source_id and instance that will be passed into
`elog_add_event_wake()`.

BUG=b:169802515
BRANCH=zork

Change-Id: I06e9530b568543ab2f05a4f38dc5c3a527ff391e
Signed-off-by: Furquan Shaikh <furquan@google.com>
---
M src/device/pci_device.c
M src/include/device/pci.h
2 files changed, 33 insertions(+), 0 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/30/46030/1
diff --git a/src/device/pci_device.c b/src/device/pci_device.c
index 8a6f123..06e1228 100644
--- a/src/device/pci_device.c
+++ b/src/device/pci_device.c
@@ -20,6 +20,7 @@
#include <device/pcix.h>
#include <device/pciexp.h>
#include <device/hypertransport.h>
+#include <elog.h>
#include <pc80/i8259.h>
#include <security/vboot/vbnv.h>
#include <timestamp.h>
@@ -1643,3 +1644,28 @@
pci_update_config16(dev, PCI_COMMAND, ~PCI_COMMAND_MASTER, 0x0);
}
#endif
+
+void pci_dev_log_wake(const struct device *dev, uint8_t source_id, uint32_t instance)
+{
+ unsigned int pm_cap;
+ uint16_t pmcs;
+
+ if (!CONFIG(ELOG))
+ return;
+
+ if (dev->path.type != DEVICE_PATH_PCI)
+ return;
+
+ pm_cap = pci_find_capability(dev, PCI_CAP_ID_PM);
+ if (!pm_cap)
+ return;
+
+ pmcs = pci_read_config16(dev, pm_cap + PCI_PM_CTRL);
+ if (!(pmcs & PCI_PM_CTRL_PME_ENABLE))
+ return;
+
+ if (!(pmcs & PCI_PM_CTRL_PME_STATUS))
+ return;
+
+ elog_add_event_wake(source_id, instance);
+}
diff --git a/src/include/device/pci.h b/src/include/device/pci.h
index 6e28cb7..87702e2 100644
--- a/src/include/device/pci.h
+++ b/src/include/device/pci.h
@@ -80,6 +80,13 @@
struct device *pci_probe_dev(struct device *dev, struct bus *bus,
unsigned int devfn);

+/*
+ * Determine if the given PCI device is the source of wake from sleep by checking PME_STATUS and
+ * PME_ENABLE bits in PM control and status register and log the given source_id and instance in
+ * elog.
+ */
+void pci_dev_log_wake(const struct device *dev, uint8_t source_id, uint32_t instance);
+
void do_pci_scan_bridge(struct device *dev,
void (*do_scan_bus)(struct bus *bus,
unsigned int min_devfn, unsigned int max_devfn));

To view, visit change 46030. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-Change-Id: I06e9530b568543ab2f05a4f38dc5c3a527ff391e
Gerrit-Change-Number: 46030
Gerrit-PatchSet: 1
Gerrit-Owner: Furquan Shaikh <furquan@google.com>
Gerrit-MessageType: newchange