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  size_t i;
59  bool dev_found = false;
60 
61  const struct pme_map ipme_map[] = {
68  };
69  const struct xhci_wake_info xhci_wake_info[] = {
71  };
72 
73  for (i = 0; i < ARRAY_SIZE(ipme_map); i++) {
74  if (pci_dev_is_wake_source(PCI_DEV(0, PCI_SLOT(ipme_map[i].devfn),
75  PCI_FUNC(ipme_map[i].devfn)))) {
76  elog_add_event_wake(ipme_map[i].wake_source, 0);
77  dev_found = true;
78  }
79  }
80 
81  /*
82  * Check the XHCI controllers' USB2 & USB3 ports for wake events. There
83  * are cases (GSMI logging for S0ix clears PME_STS_BIT) where the XHCI
84  * controller's PME_STS_BIT may have already been cleared, so the host
85  * controller wake wouldn't get logged here; therefore, the host
86  * controller wake event is logged before its corresponding port wake
87  * event is logged.
88  */
91 
92  if (!dev_found)
94 }
95 
96 static void pch_log_wake_source(const struct chipset_power_state *ps)
97 {
98  /* Power Button */
99  if (ps->pm1_sts & PWRBTN_STS)
101 
102  /* RTC */
103  if (ps->pm1_sts & RTC_STS)
105 
106  /* PCI Express */
107  if (ps->pm1_sts & PCIEXPWAK_STS)
109 
110  /* PME (TODO: determine wake device) */
111  if (ps->gpe0_sts[GPE_STD] & PME_STS)
113 
114  /* Internal PME */
115  if (ps->gpe0_sts[GPE_STD] & PME_B0_STS)
117 
118  /* SMBUS Wake */
119  if (ps->gpe0_sts[GPE_STD] & SMB_WAK_STS)
121 
122  /* Log GPIO events in set 1-3 */
126  /* Treat the STD as an extension of GPIO to obtain visibility. */
128 }
129 
130 static void pch_log_power_and_resets(const struct chipset_power_state *ps)
131 {
132  /* Thermal Trip */
135 
136  /* PWR_FLR Power Failure */
137  if (ps->gen_pmcon_a & PWR_FLR)
139 
140  /* SUS Well Power Failure */
141  if (ps->gen_pmcon_a & SUS_PWR_FLR)
143 
144  /* TCO Timeout */
145  if (ps->prev_sleep_state != ACPI_S3 &&
148 
149  /* Power Button Override */
150  if (ps->pm1_sts & PRBTNOR_STS)
152 
153  /* RTC reset */
154  if (ps->gen_pmcon_b & RTC_BATTERY_DEAD)
156 
157  /* Host Reset Status */
158  if (ps->gen_pmcon_a & HOST_RST_STS)
160 
161  /* ACPI Wake Event */
162  if (ps->prev_sleep_state != ACPI_S0)
164 }
165 
166 static void pch_log_state(void *unused)
167 {
169 
170  if (!ps) {
171  printk(BIOS_ERR, "chipset_power_state not found!\n");
172  return;
173  }
174 
175  /* Power and Reset */
177 
178  /* Wake Sources */
179  if (ps->prev_sleep_state > ACPI_S0)
181 }
182 
184 
186 {
187  struct chipset_power_state ps;
189  pch_log_wake_source(&ps);
190 }
#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_GBE
Definition: elog.h:159
#define ELOG_WAKE_SOURCE_PME_WIFI
Definition: elog.h:182
#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_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_PCIE11
Definition: elog.h:172
#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_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 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
#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 PCH_DEVFN_USBOTG
Definition: pci_devs.h:125
#define PCH_DEVFN_SATA
Definition: pci_devs.h:158
#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 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 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:96
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:130
#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
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