device: Move pci_dev_is_wake_source function

Move this function to pci_ops.c, which is already included in the smm
build. This is required to use this function in elog functionality,
which is called from SMM.

Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org>
Change-Id: Ie5583c04366c9a16bc1b00a6892d39eeafe5da49
Reviewed-on: https://review.coreboot.org/c/coreboot/+/47260
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Furquan Shaikh <furquan@google.com>
Reviewed-by: Karthik Ramasubramanian <kramasub@google.com>
This commit is contained in:
Tim Wawrzynczak 2020-11-05 14:38:51 -07:00 committed by Patrick Georgi
parent 3d4513e7c8
commit 8a1ad13822
4 changed files with 26 additions and 27 deletions

View File

@ -1648,21 +1648,3 @@ void pci_dev_disable_bus_master(const struct device *dev)
pci_update_config16(dev, PCI_COMMAND, ~PCI_COMMAND_MASTER, 0x0); pci_update_config16(dev, PCI_COMMAND, ~PCI_COMMAND_MASTER, 0x0);
} }
#endif #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);
}

View File

@ -78,3 +78,21 @@ void __noreturn pcidev_die(void)
{ {
die("PCI: dev is NULL!\n"); die("PCI: dev is NULL!\n");
} }
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_s_read_config16(PCI_BDF(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);
}

View File

@ -79,15 +79,6 @@ void pci_bus_enable_resources(struct device *dev);
void pci_bus_reset(struct bus *bus); void pci_bus_reset(struct bus *bus);
struct device *pci_probe_dev(struct device *dev, struct bus *bus, struct device *pci_probe_dev(struct device *dev, struct bus *bus,
unsigned int devfn); 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.
*
* Returns true if PCI device is wake source, false otherwise.
*/
bool pci_dev_is_wake_source(const struct device *dev);
void do_pci_scan_bridge(struct device *dev, void do_pci_scan_bridge(struct device *dev,
void (*do_scan_bus)(struct bus *bus, void (*do_scan_bus)(struct bus *bus,
unsigned int min_devfn, unsigned int max_devfn)); unsigned int min_devfn, unsigned int max_devfn));

View File

@ -209,4 +209,12 @@ u16 pci_find_capability(const struct device *dev, u16 cap)
return pci_s_find_capability(PCI_BDF(dev), cap); return pci_s_find_capability(PCI_BDF(dev), cap);
} }
/*
* 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.
*
* Returns true if PCI device is wake source, false otherwise.
*/
bool pci_dev_is_wake_source(const struct device *dev);
#endif /* PCI_OPS_H */ #endif /* PCI_OPS_H */