blob: 562df08a524f2a3ed528a52186f8dca0ac70af6a [file] [log] [blame]
Lee Leahyb0005132015-05-12 18:19:47 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2014 Google Inc.
Lee Leahy1d14b3e2015-05-12 18:23:27 -07005 * Copyright (C) 2015 Intel Corporation.
Lee Leahyb0005132015-05-12 18:19:47 -07006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
Lee Leahyb0005132015-05-12 18:19:47 -070015 */
16
17#include <bootstate.h>
18#include <cbmem.h>
19#include <console/console.h>
20#include <stdint.h>
21#include <elog.h>
Lee Leahyb0005132015-05-12 18:19:47 -070022#include <soc/pm.h>
Barnali Sarkar0dddcd72016-08-02 17:49:56 +053023#include <soc/smbus.h>
Lee Leahyb0005132015-05-12 18:19:47 -070024
25static void pch_log_gpio_gpe(u32 gpe0_sts, u32 gpe0_en, int start)
26{
27 int i;
28
29 gpe0_sts &= gpe0_en;
30
31 for (i = 0; i <= 31; i++) {
32 if (gpe0_sts & (1 << i))
33 elog_add_event_wake(ELOG_WAKE_SOURCE_GPIO, i + start);
34 }
35}
36
37static void pch_log_wake_source(struct chipset_power_state *ps)
38{
39 /* Power Button */
40 if (ps->pm1_sts & PWRBTN_STS)
41 elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0);
42
43 /* RTC */
44 if (ps->pm1_sts & RTC_STS)
45 elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0);
46
47 /* PCI Express (TODO: determine wake device) */
48 if (ps->pm1_sts & PCIEXPWAK_STS)
49 elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0);
50
51 /* PME (TODO: determine wake device) */
52 if (ps->gpe0_sts[GPE_STD] & PME_STS)
53 elog_add_event_wake(ELOG_WAKE_SOURCE_PME, 0);
54
55 /* Internal PME (TODO: determine wake device) */
56 if (ps->gpe0_sts[GPE_STD] & PME_B0_STS)
57 elog_add_event_wake(ELOG_WAKE_SOURCE_PME_INTERNAL, 0);
58
59 /* SMBUS Wake */
60 if (ps->gpe0_sts[GPE_STD] & SMB_WAK_STS)
61 elog_add_event_wake(ELOG_WAKE_SOURCE_SMBUS, 0);
62
Lee Leahyb0005132015-05-12 18:19:47 -070063 /* Log GPIO events in set 1-3 */
64 pch_log_gpio_gpe(ps->gpe0_sts[GPE_31_0], ps->gpe0_en[GPE_31_0], 0);
65 pch_log_gpio_gpe(ps->gpe0_sts[GPE_63_32], ps->gpe0_en[GPE_63_32], 32);
Aaron Durbin7f788492015-07-24 17:10:31 -050066 pch_log_gpio_gpe(ps->gpe0_sts[GPE_95_64], ps->gpe0_en[GPE_95_64], 64);
67 /* Treat the STD as an extension of GPIO to obtain visibility. */
68 pch_log_gpio_gpe(ps->gpe0_sts[GPE_STD], ps->gpe0_en[GPE_STD], 96);
Lee Leahyb0005132015-05-12 18:19:47 -070069}
70
71static void pch_log_power_and_resets(struct chipset_power_state *ps)
72{
Duncan Laurie63f8c0a2015-12-10 01:00:54 -080073 /* Thermal Trip */
74 if (ps->gblrst_cause[0] & GBLRST_CAUSE0_THERMTRIP)
75 elog_add_event(ELOG_TYPE_THERM_TRIP);
Lee Leahyb0005132015-05-12 18:19:47 -070076
77 /* PWR_FLR Power Failure */
Lee Leahy1d14b3e2015-05-12 18:23:27 -070078 if (ps->gen_pmcon_b & PWR_FLR)
Lee Leahyb0005132015-05-12 18:19:47 -070079 elog_add_event(ELOG_TYPE_POWER_FAIL);
80
81 /* SUS Well Power Failure */
Duncan Laurieac2cbd02017-03-07 19:22:24 -080082 if (ps->gen_pmcon_b & SUS_PWR_FLR) {
83 /* Do not log SUS_PWR_FLR if waking from deep Sx */
84 if (!(ps->prev_sleep_state == ACPI_S3 && deep_s3_enabled()) &&
85 !(ps->prev_sleep_state == ACPI_S5 && deep_s5_enabled()))
86 elog_add_event(ELOG_TYPE_SUS_POWER_FAIL);
87 }
Lee Leahyb0005132015-05-12 18:19:47 -070088
Lee Leahyb0005132015-05-12 18:19:47 -070089 /* TCO Timeout */
Aaron Durbine0a49142016-07-13 23:20:51 -050090 if (ps->prev_sleep_state != ACPI_S3 &&
Lee Leahyb0005132015-05-12 18:19:47 -070091 ps->tco2_sts & TCO2_STS_SECOND_TO)
92 elog_add_event(ELOG_TYPE_TCO_RESET);
93
94 /* Power Button Override */
95 if (ps->pm1_sts & PRBTNOR_STS)
96 elog_add_event(ELOG_TYPE_POWER_BUTTON_OVERRIDE);
97
98 /* RTC reset */
Lee Leahy1d14b3e2015-05-12 18:23:27 -070099 if (ps->gen_pmcon_b & RTC_BATTERY_DEAD)
Lee Leahyb0005132015-05-12 18:19:47 -0700100 elog_add_event(ELOG_TYPE_RTC_RESET);
101
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700102 /* Host Reset Status */
103 if (ps->gen_pmcon_b & HOST_RST_STS)
Lee Leahyb0005132015-05-12 18:19:47 -0700104 elog_add_event(ELOG_TYPE_SYSTEM_RESET);
105
106 /* ACPI Wake Event */
Aaron Durbine0a49142016-07-13 23:20:51 -0500107 if (ps->prev_sleep_state != ACPI_S0)
Lee Leahyb0005132015-05-12 18:19:47 -0700108 elog_add_event_byte(ELOG_TYPE_ACPI_WAKE, ps->prev_sleep_state);
109}
110
111static void pch_log_state(void *unused)
112{
113 struct chipset_power_state *ps = cbmem_find(CBMEM_ID_POWER_STATE);
114
115 if (ps == NULL) {
Lee Leahy1d14b3e2015-05-12 18:23:27 -0700116 printk(BIOS_ERR,
117 "Not logging power state information. Power state not found in cbmem.\n");
Lee Leahyb0005132015-05-12 18:19:47 -0700118 return;
119 }
120
121 /* Power and Reset */
122 pch_log_power_and_resets(ps);
123
124 /* Wake Sources */
Duncan Lauried68e0472016-03-01 17:01:35 -0800125 if (ps->prev_sleep_state > 0)
126 pch_log_wake_source(ps);
Lee Leahyb0005132015-05-12 18:19:47 -0700127}
128
Duncan Laurieac2cbd02017-03-07 19:22:24 -0800129BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, pch_log_state, NULL);