Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Google Inc. |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 5 | * Copyright (C) 2015 Intel Corp. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; version 2 of |
| 10 | * the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <arch/io.h> |
| 19 | #include <arch/acpi.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 20 | #include <cbmem.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 21 | #include <console/console.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pci_ops.h> |
| 25 | #include <elog.h> |
| 26 | #include <soc/iomap.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 27 | #include <soc/pm.h> |
| 28 | #include <stdint.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 29 | |
| 30 | static void log_power_and_resets(const struct chipset_power_state *ps) |
| 31 | { |
| 32 | if (ps->gen_pmcon1 & PWR_FLR) { |
| 33 | elog_add_event(ELOG_TYPE_POWER_FAIL); |
| 34 | elog_add_event(ELOG_TYPE_PWROK_FAIL); |
| 35 | } |
| 36 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 37 | if (ps->gen_pmcon1 & SUS_PWR_FLR) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 38 | elog_add_event(ELOG_TYPE_SUS_POWER_FAIL); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 39 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 40 | if (ps->gen_pmcon1 & RPS) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 41 | elog_add_event(ELOG_TYPE_RTC_RESET); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 42 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 43 | if (ps->tco_sts & SECOND_TO_STS) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 44 | elog_add_event(ELOG_TYPE_TCO_RESET); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 45 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 46 | if (ps->pm1_sts & PRBTNOR_STS) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 47 | elog_add_event(ELOG_TYPE_POWER_BUTTON_OVERRIDE); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 48 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 49 | if (ps->gen_pmcon1 & SRS) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 50 | elog_add_event(ELOG_TYPE_RESET_BUTTON); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 51 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 52 | if (ps->gen_pmcon1 & GEN_RST_STS) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 53 | elog_add_event(ELOG_TYPE_SYSTEM_RESET); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | static void log_wake_events(const struct chipset_power_state *ps) |
| 57 | { |
| 58 | const uint32_t pcie_wake_mask = PCI_EXP_STS | PCIE_WAKE3_STS | |
| 59 | PCIE_WAKE2_STS | PCIE_WAKE1_STS | |
| 60 | PCIE_WAKE0_STS; |
| 61 | uint32_t gpe0_sts; |
| 62 | uint32_t gpio_mask; |
| 63 | int i; |
| 64 | |
| 65 | /* Mask off disabled events. */ |
| 66 | gpe0_sts = ps->gpe0_sts & ps->gpe0_en; |
| 67 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 68 | if (ps->pm1_sts & WAK_STS) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 69 | elog_add_event_byte(ELOG_TYPE_ACPI_WAKE, |
Aaron Durbin | 1b6196d | 2016-07-13 23:20:26 -0500 | [diff] [blame] | 70 | acpi_is_wakeup_s3() ? ACPI_S3 : ACPI_S5); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 71 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 72 | if (ps->pm1_sts & PWRBTN_STS) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 73 | elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 74 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 75 | if (ps->pm1_sts & RTC_STS) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 76 | elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 77 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 78 | if (gpe0_sts & PME_B0_EN) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 79 | elog_add_event_wake(ELOG_WAKE_SOURCE_PME_INTERNAL, 0); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 80 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 81 | if (gpe0_sts & pcie_wake_mask) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 82 | elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 83 | |
| 84 | gpio_mask = SUS_GPIO_STS0; |
| 85 | i = 0; |
| 86 | while (gpio_mask) { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 87 | if (gpio_mask & gpe0_sts) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 88 | elog_add_event_wake(ELOG_WAKE_SOURCE_GPIO, i); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 89 | gpio_mask <<= 1; |
| 90 | i++; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | void southcluster_log_state(void) |
| 95 | { |
| 96 | struct chipset_power_state *ps = cbmem_find(CBMEM_ID_POWER_STATE); |
| 97 | |
| 98 | if (ps == NULL) { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 99 | printk(BIOS_DEBUG, |
| 100 | "Not logging power state information. Power state not found in cbmem.\n"); |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 101 | return; |
| 102 | } |
| 103 | |
| 104 | log_power_and_resets(ps); |
| 105 | log_wake_events(ps); |
| 106 | } |