coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
elog.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #define __SIMPLE_DEVICE__
4 
5 #include <bootstate.h>
6 #include <console/console.h>
7 #include <device/pci_ops.h>
8 #include <stdint.h>
9 #include <elog.h>
10 #include <intelblocks/pmclib.h>
11 #include <intelblocks/xhci.h>
12 #include <soc/pci_devs.h>
13 #include <soc/pm.h>
14 
19 };
20 
21 #define PME_STS_BIT (1 << 15)
22 
24 {
25  size_t i;
26  pci_devfn_t dev;
27  uint16_t val;
28  bool dev_found = false;
29 
30  const struct pme_status_info pme_status_info[] = {
36  /*
37  * The power management control/status register is not
38  * listed in the cannonlake PCH EDS. We have been told
39  * that the PMCS register is at offset 0xCC.
40  */
42  };
43  const struct xhci_wake_info xhci_wake_info[] = {
45  };
46 
47  for (i = 0; i < ARRAY_SIZE(pme_status_info); i++) {
48  dev = pme_status_info[i].dev;
49  if (!dev)
50  continue;
51 
52  val = pci_read_config16(dev, pme_status_info[i].reg_offset);
53 
54  if ((val == 0xFFFF) || !(val & PME_STS_BIT))
55  continue;
56 
57  elog_add_event_wake(pme_status_info[i].elog_event, 0);
58  dev_found = true;
59  }
60 
61  /*
62  * Check the XHCI controllers' USB2 & USB3 ports for wake events. There
63  * are cases (GSMI logging for S0ix clears PME_STS_BIT) where the XHCI
64  * controller's PME_STS_BIT may have already been cleared, so the host
65  * controller wake wouldn't get logged here; therefore, the host
66  * controller wake event is logged before its corresponding port wake
67  * event is logged.
68  */
71 
72  if (!dev_found)
74 }
75 
76 static void pch_log_gpio_gpe(u32 gpe0_sts, u32 gpe0_en, int start)
77 {
78  int i;
79 
80  gpe0_sts &= gpe0_en;
81 
82  for (i = 0; i <= 31; i++) {
83  if (gpe0_sts & (1 << i))
85  }
86 }
87 
88 static void pch_log_wake_source(const struct chipset_power_state *ps)
89 {
90  /* Power Button */
91  if (ps->pm1_sts & PWRBTN_STS)
93 
94  /* RTC */
95  if (ps->pm1_sts & RTC_STS)
97 
98  /* PCI Express (TODO: determine wake device) */
99  if (ps->pm1_sts & PCIEXPWAK_STS)
101 
102  /* PME (TODO: determine wake device) */
103  if (ps->gpe0_sts[GPE_STD] & PME_STS)
105 
106  /* XHCI - "Power Management Event Bus 0" events include XHCI */
107  if (ps->gpe0_sts[GPE_STD] & PME_B0_STS)
109 
110  /* SMBUS Wake */
111  if (ps->gpe0_sts[GPE_STD] & SMB_WAK_STS)
113 
114  /* Log GPIO events in set 1-3 */
118  /* Treat the STD as an extension of GPIO to obtain visibility. */
120 }
121 
122 static void pch_log_power_and_resets(const struct chipset_power_state *ps)
123 {
124  /* Thermal Trip */
127 
128  /* PWR_FLR Power Failure */
129  if (ps->gen_pmcon_a & PWR_FLR)
131 
132  /* SUS Well Power Failure */
133  if (ps->gen_pmcon_a & SUS_PWR_FLR)
135 
136  /* TCO Timeout */
137  if (ps->prev_sleep_state != ACPI_S3 &&
140 
141  /* Power Button Override */
142  if (ps->pm1_sts & PRBTNOR_STS)
144 
145  /* RTC reset */
146  if (ps->gen_pmcon_b & RTC_BATTERY_DEAD)
148 
149  /* Host Reset Status */
150  if (ps->gen_pmcon_a & HOST_RST_STS)
152 
153  /* ACPI Wake Event */
154  if (ps->prev_sleep_state != ACPI_S0)
156 }
157 
158 static void pch_log_state(void *unused)
159 {
161 
162  if (!ps) {
163  printk(BIOS_ERR, "chipset_power_state not found!\n");
164  return;
165  }
166 
167  /* Power and Reset */
169 
170  /* Wake Sources */
171  if (ps->prev_sleep_state > ACPI_S0)
173 }
174 
176 
178 {
179  struct chipset_power_state ps;
181  pch_log_wake_source(&ps);
182 }
#define GPE_63_32
Definition: pm.h:83
#define GPE_31_0
Definition: pm.h:82
#define GPE_STD
Definition: pm.h:85
#define SMB_WAK_STS
Definition: pm.h:95
#define GPE_95_64
Definition: pm.h:84
#define PME_STS
Definition: pm.h:92
#define PRBTNOR_STS
Definition: pm.h:15
#define PME_B0_STS
Definition: pm.h:90
@ BS_DEV_INIT
Definition: bootstate.h:83
@ BS_ON_EXIT
Definition: bootstate.h:96
#define ARRAY_SIZE(a)
Definition: helpers.h:12
#define PWRBTN_STS
Definition: southbridge.h:30
#define PCIEXPWAK_STS
Definition: southbridge.h:28
#define RTC_STS
Definition: southbridge.h:29
#define ELOG_WAKE_SOURCE_RTC
Definition: elog.h:154
#define ELOG_WAKE_SOURCE_PME_GBE
Definition: elog.h:159
#define ELOG_WAKE_SOURCE_PME_WIFI
Definition: elog.h:182
#define ELOG_WAKE_SOURCE_PCIE
Definition: elog.h:151
#define ELOG_TYPE_SUS_POWER_FAIL
Definition: elog.h:129
#define ELOG_TYPE_THERM_TRIP
Definition: elog.h:277
#define ELOG_TYPE_POWER_FAIL
Definition: elog.h:128
#define ELOG_WAKE_SOURCE_PME_CSE
Definition: elog.h:175
#define ELOG_WAKE_SOURCE_PME_XDCI
Definition: elog.h:179
#define ELOG_TYPE_ACPI_WAKE
Definition: elog.h:149
#define ELOG_WAKE_SOURCE_PME
Definition: elog.h:152
#define ELOG_WAKE_SOURCE_PME_SATA
Definition: elog.h:174
#define ELOG_WAKE_SOURCE_GPE
Definition: elog.h:155
#define ELOG_WAKE_SOURCE_PWRBTN
Definition: elog.h:157
#define ELOG_WAKE_SOURCE_PME_INTERNAL
Definition: elog.h:153
#define ELOG_TYPE_POWER_BUTTON_OVERRIDE
Definition: elog.h:134
#define ELOG_TYPE_SYSTEM_RESET
Definition: elog.h:138
#define ELOG_TYPE_RTC_RESET
Definition: elog.h:139
#define ELOG_TYPE_TCO_RESET
Definition: elog.h:140
#define ELOG_WAKE_SOURCE_PME_XHCI
Definition: elog.h:178
#define ELOG_WAKE_SOURCE_PME_HDA
Definition: elog.h:158
#define ELOG_WAKE_SOURCE_SMBUS
Definition: elog.h:156
#define printk(level,...)
Definition: stdlib.h:16
BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY, elog_bs_init, NULL)
int elog_add_event_byte(u8 event_type, u8 data)
Definition: elog.c:868
int elog_add_event_wake(u8 source, u32 instance)
Definition: elog.c:883
int elog_add_event(u8 event_type)
Definition: elog.c:863
@ ACPI_S3
Definition: acpi.h:1383
@ ACPI_S0
Definition: acpi.h:1380
static __always_inline u16 pci_read_config16(const struct device *dev, u16 reg)
Definition: pci_ops.h:52
#define PWR_FLR
Definition: pmc.h:30
#define HOST_RST_STS
Definition: pmc.h:38
#define GBLRST_CAUSE0_THERMTRIP
Definition: pmc.h:132
#define RTC_BATTERY_DEAD
Definition: pmc.h:61
#define SUS_PWR_FLR
Definition: pmc.h:28
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
u32 pci_devfn_t
Definition: pci_type.h:8
void elog_gsmi_cb_platform_log_wake_source(void)
Definition: elog.c:212
#define PCH_DEV_USBOTG
Definition: pci_devs.h:129
#define PCH_DEV_CSE
Definition: pci_devs.h:150
#define PCH_DEV_SATA
Definition: pci_devs.h:159
#define PCH_DEV_HDA
Definition: pci_devs.h:239
#define PCH_DEV_GBE
Definition: pci_devs.h:242
#define PCH_DEVFN_XHCI
Definition: pci_devs.h:124
void pch_log_state(void)
Definition: elog.c:88
#define TCO_STS_SECOND_TO
Definition: smbus.h:10
static void pch_log_pme_internal_wake_source(void)
Definition: elog.c:23
static void pch_log_wake_source(const struct chipset_power_state *ps)
Definition: elog.c:88
static void pch_log_gpio_gpe(u32 gpe0_sts, u32 gpe0_en, int start)
Definition: elog.c:76
#define PME_STS_BIT
Definition: elog.c:21
static void pch_log_power_and_resets(const struct chipset_power_state *ps)
Definition: elog.c:122
#define PCH_DEV_CNViWIFI
Definition: pci_devs.h:70
void pmc_fill_pm_reg_info(struct chipset_power_state *ps)
Definition: pmclib.c:413
struct chipset_power_state * pmc_get_power_state(void)
Definition: pmclib.c:58
bool xhci_update_wake_event(const struct xhci_wake_info *wake_info, size_t wake_info_count)
Definition: elog.c:98
#define NULL
Definition: stddef.h:19
unsigned short uint16_t
Definition: stdint.h:11
unsigned int uint32_t
Definition: stdint.h:14
uint32_t u32
Definition: stdint.h:51
unsigned char uint8_t
Definition: stdint.h:8
uint16_t tco2_sts
Definition: pm.h:146
uint32_t gpe0_en[4]
Definition: pm.h:148
uint32_t prev_sleep_state
Definition: pm.h:153
uint32_t gpe0_sts[4]
Definition: pm.h:147
uint32_t gen_pmcon_b
Definition: pm.h:150
uint16_t pm1_sts
Definition: pm.h:142
uint32_t gblrst_cause[2]
Definition: pm.h:151
uint32_t gen_pmcon_a
Definition: pm.h:149
pci_devfn_t dev
Definition: elog.c:16
uint32_t elog_event
Definition: elog.c:18
uint8_t reg_offset
Definition: elog.c:17
u8 val
Definition: sys.c:300