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 #include <bootstate.h>
4 #include <console/console.h>
5 #include <device/pci_ops.h>
6 #include <elog.h>
7 #include <intelblocks/pmclib.h>
8 #include <intelblocks/xhci.h>
9 #include <soc/pci_devs.h>
10 #include <soc/pm.h>
11 #include <types.h>
12 
13 struct pme_map {
14  unsigned int devfn;
15  unsigned int wake_source;
16 };
17 
18 static void pch_log_gpio_gpe(u32 gpe0_sts, u32 gpe0_en, int start)
19 {
20  int i;
21 
22  gpe0_sts &= gpe0_en;
23 
24  for (i = 0; i <= 31; i++) {
25  if (gpe0_sts & (1 << i))
27  }
28 }
29 
30 static void pch_log_rp_wake_source(void)
31 {
32  size_t i;
33 
34  const struct pme_map pme_map[] = {
47  };
48 
49  for (i = 0; i < MIN(CONFIG_MAX_ROOT_PORTS, ARRAY_SIZE(pme_map)); ++i) {
51  PCI_FUNC(pme_map[i].devfn))))
53  }
54 }
55 
57 {
58  const struct pme_map ipme_map[] = {
66  };
67  const struct xhci_wake_info xhci_wake_info[] = {
70  };
71  bool dev_found = false;
72  size_t i;
73 
74  for (i = 0; i < ARRAY_SIZE(ipme_map); i++) {
75  if (pci_dev_is_wake_source(PCI_DEV(0, PCI_SLOT(ipme_map[i].devfn),
76  PCI_FUNC(ipme_map[i].devfn)))) {
77  elog_add_event_wake(ipme_map[i].wake_source, 0);
78  dev_found = true;
79  }
80  }
81 
82  /* Check Thunderbolt ports */
83  for (i = 0; i < NUM_TBT_FUNCTIONS; i++) {
84  const unsigned int devfn = SA_DEVFN_TBT(i);
85  if (pci_dev_is_wake_source(PCI_DEV(0, PCI_SLOT(devfn), PCI_FUNC(devfn)))) {
87  dev_found = true;
88  }
89  }
90 
91  /* Check DMA devices */
92  for (i = 0; i < NUM_TCSS_DMA_FUNCTIONS; i++) {
93  const unsigned int devfn = SA_DEVFN_TCSS_DMA(i);
94  if (pci_dev_is_wake_source(PCI_DEV(0, PCI_SLOT(devfn), PCI_FUNC(devfn)))) {
96  dev_found = true;
97  }
98  }
99 
100  /*
101  * Check the XHCI controllers' USB2 & USB3 ports for wake events. There
102  * are cases (GSMI logging for S0ix clears PME_STS_BIT) where the XHCI
103  * controller's PME_STS_BIT may have already been cleared, so the host
104  * controller wake wouldn't get logged here; therefore, the host
105  * controller wake event is logged before its corresponding port wake
106  * event is logged.
107  */
110 
111  if (!dev_found)
113 }
114 
115 static void pch_log_wake_source(const struct chipset_power_state *ps)
116 {
117  /* Power Button */
118  if (ps->pm1_sts & PWRBTN_STS)
120 
121  /* RTC */
122  if (ps->pm1_sts & RTC_STS)
124 
125  /* PCI Express (TODO: determine wake device) */
126  if (ps->pm1_sts & PCIEXPWAK_STS)
128 
129  /* PME (TODO: determine wake device) */
130  if (ps->gpe0_sts[GPE_STD] & PME_STS)
132 
133  /* Internal PME */
134  if (ps->gpe0_sts[GPE_STD] & PME_B0_STS)
136 
137  /* SMBUS Wake */
138  if (ps->gpe0_sts[GPE_STD] & SMB_WAK_STS)
140 
141  /* Log GPIO events in set 1-3 */
145  /* Treat the STD as an extension of GPIO to obtain visibility. */
147 }
148 
149 static void pch_log_power_and_resets(const struct chipset_power_state *ps)
150 {
151  /* Thermal Trip */
154 
155  /* CSME-Initiated Host Reset with power down */
156  if (ps->hpr_cause0 & HPR_CAUSE0_MI_HRPD)
158 
159  /* CSME-Initiated Host Reset with power cycle */
160  if (ps->hpr_cause0 & HPR_CAUSE0_MI_HRPC)
162 
163  /* CSME-Initiated Host Reset without power cycle */
164  if (ps->hpr_cause0 & HPR_CAUSE0_MI_HR)
166 
167  /* PWR_FLR Power Failure */
168  if (ps->gen_pmcon_a & PWR_FLR)
170 
171  /* SUS Well Power Failure */
172  if (ps->gen_pmcon_a & SUS_PWR_FLR)
174 
175  /* TCO Timeout */
176  if (ps->prev_sleep_state != ACPI_S3 &&
179 
180  /* Power Button Override */
181  if (ps->pm1_sts & PRBTNOR_STS)
183 
184  /* RTC reset */
185  if (ps->gen_pmcon_b & RTC_BATTERY_DEAD)
187 
188  /* Host Reset Status */
189  if (ps->gen_pmcon_a & HOST_RST_STS)
191 
192  /* ACPI Wake Event */
193  if (ps->prev_sleep_state != ACPI_S0)
195 }
196 
197 static void pch_log_state(void *unused)
198 {
200 
201  if (!ps) {
202  printk(BIOS_ERR, "chipset_power_state not found!\n");
203  return;
204  }
205 
206  /* Power and Reset */
208 
209  /* Wake Sources */
210  if (ps->prev_sleep_state > ACPI_S0)
212 }
213 
215 
217 {
218  struct chipset_power_state ps;
220  pch_log_wake_source(&ps);
221 }
#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 MIN(a, b)
Definition: helpers.h:37
#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_PME_PCIE2
Definition: elog.h:163
#define ELOG_WAKE_SOURCE_RTC
Definition: elog.h:154
#define ELOG_WAKE_SOURCE_PME_TCSS_XHCI
Definition: elog.h:197
#define ELOG_TYPE_MI_HRPC
Definition: elog.h:305
#define ELOG_WAKE_SOURCE_PME_GBE
Definition: elog.h:159
#define ELOG_WAKE_SOURCE_PME_WIFI
Definition: elog.h:182
#define ELOG_WAKE_SOURCE_PME_TBT
Definition: elog.h:196
#define ELOG_WAKE_SOURCE_PME_PCIE7
Definition: elog.h:168
#define ELOG_WAKE_SOURCE_PME_PCIE5
Definition: elog.h:166
#define ELOG_WAKE_SOURCE_PME_PCIE10
Definition: elog.h:171
#define ELOG_TYPE_MI_HR
Definition: elog.h:306
#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_TCSS_XDCI
Definition: elog.h:198
#define ELOG_WAKE_SOURCE_PME_CSE
Definition: elog.h:175
#define ELOG_WAKE_SOURCE_PME_PCIE11
Definition: elog.h:172
#define ELOG_WAKE_SOURCE_PME_TCSS_DMA
Definition: elog.h:199
#define ELOG_WAKE_SOURCE_PME_XDCI
Definition: elog.h:179
#define ELOG_TYPE_MI_HRPD
Definition: elog.h:304
#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_WAKE_SOURCE_PME_PCIE1
Definition: elog.h:162
#define ELOG_TYPE_SYSTEM_RESET
Definition: elog.h:138
#define ELOG_WAKE_SOURCE_PME_PCIE9
Definition: elog.h:170
#define ELOG_WAKE_SOURCE_PME_PCIE3
Definition: elog.h:164
#define ELOG_TYPE_RTC_RESET
Definition: elog.h:139
#define ELOG_WAKE_SOURCE_PME_PCIE6
Definition: elog.h:167
#define ELOG_TYPE_TCO_RESET
Definition: elog.h:140
#define ELOG_WAKE_SOURCE_PME_XHCI
Definition: elog.h:178
#define ELOG_WAKE_SOURCE_PME_PCIE8
Definition: elog.h:169
#define ELOG_WAKE_SOURCE_PME_PCIE4
Definition: elog.h:165
#define ELOG_WAKE_SOURCE_PME_HDA
Definition: elog.h:158
#define ELOG_WAKE_SOURCE_SMBUS
Definition: elog.h:156
#define ELOG_WAKE_SOURCE_PME_PCIE12
Definition: elog.h:173
#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
#define PWR_FLR
Definition: pmc.h:30
#define HPR_CAUSE0_MI_HR
Definition: pmc.h:137
#define HPR_CAUSE0_MI_HRPC
Definition: pmc.h:136
#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 HPR_CAUSE0_MI_HRPD
Definition: pmc.h:135
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
#define PCI_FUNC(devfn)
Definition: pci_def.h:550
#define PCI_SLOT(devfn)
Definition: pci_def.h:549
bool pci_dev_is_wake_source(pci_devfn_t dev)
Definition: pci_ops.c:82
#define PCI_DEV(SEGBUS, DEV, FN)
Definition: pci_type.h:14
void elog_gsmi_cb_platform_log_wake_source(void)
Definition: elog.c:212
#define PCH_DEVFN_PCIE12
Definition: pci_devs.h:197
#define PCH_DEVFN_PCIE2
Definition: pci_devs.h:177
#define PCH_DEVFN_PCIE11
Definition: pci_devs.h:196
#define PCH_DEVFN_PCIE5
Definition: pci_devs.h:180
#define PCH_DEVFN_PCIE9
Definition: pci_devs.h:194
#define SA_DEVFN_TCSS_XDCI
Definition: pci_devs.h:71
#define PCH_DEVFN_USBOTG
Definition: pci_devs.h:125
#define PCH_DEVFN_SATA
Definition: pci_devs.h:158
#define SA_DEVFN_TCSS_XHCI
Definition: pci_devs.h:70
#define NUM_TCSS_DMA_FUNCTIONS
Definition: pci_devs.h:68
#define SA_DEVFN_TCSS_DMA(x)
Definition: pci_devs.h:69
#define PCH_DEVFN_GBE
Definition: pci_devs.h:221
#define PCH_DEVFN_XHCI
Definition: pci_devs.h:124
#define PCH_DEVFN_HDA
Definition: pci_devs.h:218
#define SA_DEVFN_TBT(x)
Definition: pci_devs.h:48
#define PCH_DEVFN_PCIE6
Definition: pci_devs.h:181
#define PCH_DEVFN_PCIE3
Definition: pci_devs.h:178
#define PCH_DEVFN_PCIE7
Definition: pci_devs.h:182
#define PCH_DEVFN_PCIE4
Definition: pci_devs.h:179
#define NUM_TBT_FUNCTIONS
Definition: pci_devs.h:49
#define PCH_DEVFN_PCIE10
Definition: pci_devs.h:195
#define PCH_DEVFN_PCIE8
Definition: pci_devs.h:183
#define PCH_DEVFN_CNVI_WIFI
Definition: pci_devs.h:127
#define PCH_DEVFN_PCIE1
Definition: pci_devs.h:176
#define PCH_DEVFN_CSE
Definition: pci_devs.h:144
void pch_log_state(void)
Definition: elog.c:88
#define TCO_STS_SECOND_TO
Definition: smbus.h:10
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
static void pch_log_pme_internal_wake_source(void)
Definition: elog.c:56
static void pch_log_wake_source(const struct chipset_power_state *ps)
Definition: elog.c:115
static void pch_log_gpio_gpe(u32 gpe0_sts, u32 gpe0_en, int start)
Definition: elog.c:18
static void pch_log_rp_wake_source(void)
Definition: elog.c:30
static void pch_log_power_and_resets(const struct chipset_power_state *ps)
Definition: elog.c:149
#define NULL
Definition: stddef.h:19
uint32_t u32
Definition: stdint.h:51
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
uint32_t hpr_cause0
Definition: pm.h:152
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
Definition: elog.c:13
unsigned int devfn
Definition: elog.c:14
unsigned int wake_source
Definition: elog.c:15