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 <arch/io.h>
4 #include <acpi/acpi.h>
5 #include <device/device.h>
6 #include <device/pci.h>
7 #include <device/pci_ops.h>
8 #include <stdint.h>
9 #include <elog.h>
11 #include "pch.h"
12 
13 void pch_log_state(void)
14 {
15  u16 pm1_sts, gen_pmcon_3, tco2_sts;
16  u32 gpe0_sts, gpe0_en;
17  u8 gen_pmcon_2;
18  int i;
19  struct device *lpc = pcidev_on_root(0x1f, 0);
20  if (!lpc)
21  return;
22 
23  pm1_sts = inw(DEFAULT_PMBASE + PM1_STS);
24  gpe0_sts = inl(DEFAULT_PMBASE + GPE0_STS);
25  gpe0_en = inl(DEFAULT_PMBASE + GPE0_EN);
26  tco2_sts = inw(DEFAULT_PMBASE + TCO2_STS);
27  gen_pmcon_2 = pci_read_config8(lpc, GEN_PMCON_2);
28  gen_pmcon_3 = pci_read_config16(lpc, GEN_PMCON_3);
29 
30  /* PWR_FLR Power Failure */
31  if (gen_pmcon_2 & (1 << 0))
33 
34  /* SUS Well Power Failure */
35  if (gen_pmcon_3 & (1 << 14))
37 
38  /* SYS_PWROK Failure */
39  if (gen_pmcon_2 & (1 << 1))
41 
42  /* PWROK Failure */
43  if (gen_pmcon_2 & (1 << 0))
45 
46  /* Second TCO Timeout */
47  if (tco2_sts & (1 << 1))
49 
50  /* Power Button Override */
51  if (pm1_sts & (1 << 11))
53 
54  /* System Reset Status (reset button pushed) */
55  if (gen_pmcon_2 & (1 << 4))
57 
58  /* General Reset Status */
59  if (gen_pmcon_3 & (1 << 9))
61 
62  /* ACPI Wake */
63  if (pm1_sts & (1 << 15))
65  acpi_is_wakeup_s3() ? 3 : 5);
66 
67  /*
68  * Wake sources
69  */
70 
71  /* RTC */
72  if (pm1_sts & (1 << 10))
74 
75  /* PCI Express (TODO: determine wake device) */
76  if (pm1_sts & (1 << 14))
78 
79  /* PME (TODO: determine wake device) */
80  if (gpe0_sts & (1 << 13))
82 
83  /* Internal PME (TODO: determine wake device) */
84  if (gpe0_sts & (1 << 13))
86 
87  /* GPIO 0-15 */
88  for (i = 0; i < 16; i++) {
89  if ((gpe0_sts & (1 << (16+i))) && (gpe0_en & (1 << (16+i))))
91  }
92 
93  /* SMBUS Wake */
94  if (gpe0_sts & (1 << 7))
96 }
#define GPE0_STS(x)
Definition: pm.h:81
#define PM1_STS
Definition: pm.h:12
#define GPE0_EN(x)
Definition: pm.h:99
static int acpi_is_wakeup_s3(void)
Definition: acpi.h:9
#define ELOG_WAKE_SOURCE_RTC
Definition: elog.h:154
#define ELOG_TYPE_RESET_BUTTON
Definition: elog.h:137
#define ELOG_WAKE_SOURCE_PCIE
Definition: elog.h:151
#define ELOG_TYPE_PWROK_FAIL
Definition: elog.h:130
#define ELOG_TYPE_SUS_POWER_FAIL
Definition: elog.h:129
#define ELOG_TYPE_POWER_FAIL
Definition: elog.h:128
#define ELOG_TYPE_SYS_PWROK_FAIL
Definition: elog.h:131
#define ELOG_TYPE_ACPI_WAKE
Definition: elog.h:149
#define ELOG_WAKE_SOURCE_PME
Definition: elog.h:152
#define ELOG_WAKE_SOURCE_GPE
Definition: elog.h:155
#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_TCO_RESET
Definition: elog.h:140
#define ELOG_WAKE_SOURCE_SMBUS
Definition: elog.h:156
u16 inw(u16 port)
u32 inl(u16 port)
DEVTREE_CONST struct device * pcidev_on_root(uint8_t dev, uint8_t fn)
Definition: device_const.c:260
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
static __always_inline u16 pci_read_config16(const struct device *dev, u16 reg)
Definition: pci_ops.h:52
static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg)
Definition: pci_ops.h:46
#define DEFAULT_PMBASE
Definition: iomap.h:14
void pch_log_state(void)
Definition: elog.c:88
#define TCO2_STS
Definition: smbus.h:9
#define GEN_PMCON_3
Definition: lpc.h:63
#define GEN_PMCON_2
Definition: lpc.h:58
uint32_t u32
Definition: stdint.h:51
uint16_t u16
Definition: stdint.h:48
uint8_t u8
Definition: stdint.h:45
Definition: device.h:107