Angel Pons | 16f6aa8 | 2020-04-05 15:47:21 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 2 | |
| 3 | #include <bootstate.h> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 4 | #include <console/console.h> |
Tim Wawrzynczak | 8a78f59 | 2020-11-03 13:16:27 -0700 | [diff] [blame] | 5 | #include <device/pci_ops.h> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 6 | #include <elog.h> |
| 7 | #include <intelblocks/pmclib.h> |
Karthikeyan Ramasubramanian | fa9e8f9 | 2020-11-04 22:22:46 -0700 | [diff] [blame] | 8 | #include <intelblocks/xhci.h> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 9 | #include <soc/pci_devs.h> |
| 10 | #include <soc/pm.h> |
Tim Wawrzynczak | 8a78f59 | 2020-11-03 13:16:27 -0700 | [diff] [blame] | 11 | #include <types.h> |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 12 | |
Karthikeyan Ramasubramanian | fa9e8f9 | 2020-11-04 22:22:46 -0700 | [diff] [blame] | 13 | struct pme_map { |
Tim Wawrzynczak | b1623f2 | 2021-04-30 13:47:04 -0600 | [diff] [blame] | 14 | unsigned int devfn; |
Karthikeyan Ramasubramanian | fa9e8f9 | 2020-11-04 22:22:46 -0700 | [diff] [blame] | 15 | unsigned int wake_source; |
| 16 | }; |
| 17 | |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 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)) |
Aaron Durbin | aa90203 | 2020-08-17 09:37:13 -0600 | [diff] [blame] | 26 | elog_add_event_wake(ELOG_WAKE_SOURCE_GPE, i + start); |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 27 | } |
| 28 | } |
| 29 | |
Tim Wawrzynczak | 8a78f59 | 2020-11-03 13:16:27 -0700 | [diff] [blame] | 30 | static void pch_log_rp_wake_source(void) |
| 31 | { |
| 32 | size_t i; |
Tim Wawrzynczak | 8a78f59 | 2020-11-03 13:16:27 -0700 | [diff] [blame] | 33 | |
| 34 | const struct pme_map pme_map[] = { |
| 35 | { PCH_DEVFN_PCIE1, ELOG_WAKE_SOURCE_PME_PCIE1 }, |
| 36 | { PCH_DEVFN_PCIE2, ELOG_WAKE_SOURCE_PME_PCIE2 }, |
| 37 | { PCH_DEVFN_PCIE3, ELOG_WAKE_SOURCE_PME_PCIE3 }, |
| 38 | { PCH_DEVFN_PCIE4, ELOG_WAKE_SOURCE_PME_PCIE4 }, |
| 39 | { PCH_DEVFN_PCIE5, ELOG_WAKE_SOURCE_PME_PCIE5 }, |
| 40 | { PCH_DEVFN_PCIE6, ELOG_WAKE_SOURCE_PME_PCIE6 }, |
| 41 | { PCH_DEVFN_PCIE7, ELOG_WAKE_SOURCE_PME_PCIE7 }, |
| 42 | { PCH_DEVFN_PCIE8, ELOG_WAKE_SOURCE_PME_PCIE8 }, |
| 43 | { PCH_DEVFN_PCIE9, ELOG_WAKE_SOURCE_PME_PCIE9 }, |
| 44 | { PCH_DEVFN_PCIE10, ELOG_WAKE_SOURCE_PME_PCIE10 }, |
| 45 | { PCH_DEVFN_PCIE11, ELOG_WAKE_SOURCE_PME_PCIE11 }, |
| 46 | { PCH_DEVFN_PCIE12, ELOG_WAKE_SOURCE_PME_PCIE12 }, |
| 47 | }; |
| 48 | |
| 49 | for (i = 0; i < MIN(CONFIG_MAX_ROOT_PORTS, ARRAY_SIZE(pme_map)); ++i) { |
Tim Wawrzynczak | 93982c3 | 2021-04-29 09:45:59 -0600 | [diff] [blame] | 50 | if (pci_dev_is_wake_source(PCI_DEV(0, PCI_SLOT(pme_map[i].devfn), |
| 51 | PCI_FUNC(pme_map[i].devfn)))) |
Tim Wawrzynczak | 8a78f59 | 2020-11-03 13:16:27 -0700 | [diff] [blame] | 52 | elog_add_event_wake(pme_map[i].wake_source, 0); |
| 53 | } |
| 54 | } |
| 55 | |
Karthikeyan Ramasubramanian | fa9e8f9 | 2020-11-04 22:22:46 -0700 | [diff] [blame] | 56 | static void pch_log_pme_internal_wake_source(void) |
| 57 | { |
Karthikeyan Ramasubramanian | fa9e8f9 | 2020-11-04 22:22:46 -0700 | [diff] [blame] | 58 | const struct pme_map ipme_map[] = { |
Tim Wawrzynczak | a7b60e7 | 2020-11-10 09:57:19 -0700 | [diff] [blame] | 59 | { PCH_DEVFN_HDA, ELOG_WAKE_SOURCE_PME_HDA }, |
| 60 | { PCH_DEVFN_GBE, ELOG_WAKE_SOURCE_PME_GBE }, |
| 61 | { PCH_DEVFN_SATA, ELOG_WAKE_SOURCE_PME_SATA }, |
| 62 | { PCH_DEVFN_CSE, ELOG_WAKE_SOURCE_PME_CSE }, |
| 63 | { PCH_DEVFN_USBOTG, ELOG_WAKE_SOURCE_PME_XDCI }, |
| 64 | { PCH_DEVFN_CNVI_WIFI, ELOG_WAKE_SOURCE_PME_WIFI }, |
| 65 | { SA_DEVFN_TCSS_XDCI, ELOG_WAKE_SOURCE_PME_TCSS_XDCI }, |
Karthikeyan Ramasubramanian | fa9e8f9 | 2020-11-04 22:22:46 -0700 | [diff] [blame] | 66 | }; |
Tim Wawrzynczak | 56fcfb5 | 2020-11-10 13:39:37 -0700 | [diff] [blame] | 67 | const struct xhci_wake_info xhci_wake_info[] = { |
| 68 | { PCH_DEVFN_XHCI, ELOG_WAKE_SOURCE_PME_XHCI }, |
| 69 | { SA_DEVFN_TCSS_XHCI, ELOG_WAKE_SOURCE_PME_TCSS_XHCI }, |
| 70 | }; |
| 71 | bool dev_found = false; |
| 72 | size_t i; |
Karthikeyan Ramasubramanian | fa9e8f9 | 2020-11-04 22:22:46 -0700 | [diff] [blame] | 73 | |
| 74 | for (i = 0; i < ARRAY_SIZE(ipme_map); i++) { |
Tim Wawrzynczak | 93982c3 | 2021-04-29 09:45:59 -0600 | [diff] [blame] | 75 | if (pci_dev_is_wake_source(PCI_DEV(0, PCI_SLOT(ipme_map[i].devfn), |
| 76 | PCI_FUNC(ipme_map[i].devfn)))) { |
Tim Wawrzynczak | 56fcfb5 | 2020-11-10 13:39:37 -0700 | [diff] [blame] | 77 | elog_add_event_wake(ipme_map[i].wake_source, 0); |
Karthikeyan Ramasubramanian | fa9e8f9 | 2020-11-04 22:22:46 -0700 | [diff] [blame] | 78 | dev_found = true; |
| 79 | } |
| 80 | } |
| 81 | |
Tim Wawrzynczak | a7b60e7 | 2020-11-10 09:57:19 -0700 | [diff] [blame] | 82 | /* Check Thunderbolt ports */ |
| 83 | for (i = 0; i < NUM_TBT_FUNCTIONS; i++) { |
Tim Wawrzynczak | 93982c3 | 2021-04-29 09:45:59 -0600 | [diff] [blame] | 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)))) { |
Tim Wawrzynczak | a7b60e7 | 2020-11-10 09:57:19 -0700 | [diff] [blame] | 86 | elog_add_event_wake(ELOG_WAKE_SOURCE_PME_TBT, i); |
| 87 | dev_found = true; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /* Check DMA devices */ |
| 92 | for (i = 0; i < NUM_TCSS_DMA_FUNCTIONS; i++) { |
Tim Wawrzynczak | 93982c3 | 2021-04-29 09:45:59 -0600 | [diff] [blame] | 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)))) { |
Tim Wawrzynczak | a7b60e7 | 2020-11-10 09:57:19 -0700 | [diff] [blame] | 95 | elog_add_event_wake(ELOG_WAKE_SOURCE_PME_TCSS_DMA, i); |
| 96 | dev_found = true; |
| 97 | } |
| 98 | } |
| 99 | |
Karthikeyan Ramasubramanian | fa9e8f9 | 2020-11-04 22:22:46 -0700 | [diff] [blame] | 100 | /* |
Tim Wawrzynczak | 56fcfb5 | 2020-11-10 13:39:37 -0700 | [diff] [blame] | 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. |
Karthikeyan Ramasubramanian | fa9e8f9 | 2020-11-04 22:22:46 -0700 | [diff] [blame] | 107 | */ |
Tim Wawrzynczak | 56fcfb5 | 2020-11-10 13:39:37 -0700 | [diff] [blame] | 108 | dev_found |= xhci_update_wake_event(xhci_wake_info, |
| 109 | ARRAY_SIZE(xhci_wake_info)); |
Karthikeyan Ramasubramanian | fa9e8f9 | 2020-11-04 22:22:46 -0700 | [diff] [blame] | 110 | |
| 111 | if (!dev_found) |
| 112 | elog_add_event_wake(ELOG_WAKE_SOURCE_PME_INTERNAL, 0); |
| 113 | } |
| 114 | |
Kyösti Mälkki | 6b43055 | 2021-01-22 07:52:43 +0200 | [diff] [blame] | 115 | static void pch_log_wake_source(const struct chipset_power_state *ps) |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 116 | { |
| 117 | /* Power Button */ |
| 118 | if (ps->pm1_sts & PWRBTN_STS) |
| 119 | elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0); |
| 120 | |
| 121 | /* RTC */ |
| 122 | if (ps->pm1_sts & RTC_STS) |
| 123 | elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0); |
| 124 | |
| 125 | /* PCI Express (TODO: determine wake device) */ |
| 126 | if (ps->pm1_sts & PCIEXPWAK_STS) |
Tim Wawrzynczak | 8a78f59 | 2020-11-03 13:16:27 -0700 | [diff] [blame] | 127 | pch_log_rp_wake_source(); |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 128 | |
| 129 | /* PME (TODO: determine wake device) */ |
| 130 | if (ps->gpe0_sts[GPE_STD] & PME_STS) |
| 131 | elog_add_event_wake(ELOG_WAKE_SOURCE_PME, 0); |
| 132 | |
Karthikeyan Ramasubramanian | fa9e8f9 | 2020-11-04 22:22:46 -0700 | [diff] [blame] | 133 | /* Internal PME */ |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 134 | if (ps->gpe0_sts[GPE_STD] & PME_B0_STS) |
Karthikeyan Ramasubramanian | fa9e8f9 | 2020-11-04 22:22:46 -0700 | [diff] [blame] | 135 | pch_log_pme_internal_wake_source(); |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 136 | |
| 137 | /* SMBUS Wake */ |
| 138 | if (ps->gpe0_sts[GPE_STD] & SMB_WAK_STS) |
| 139 | elog_add_event_wake(ELOG_WAKE_SOURCE_SMBUS, 0); |
| 140 | |
| 141 | /* Log GPIO events in set 1-3 */ |
| 142 | pch_log_gpio_gpe(ps->gpe0_sts[GPE_31_0], ps->gpe0_en[GPE_31_0], 0); |
| 143 | pch_log_gpio_gpe(ps->gpe0_sts[GPE_63_32], ps->gpe0_en[GPE_63_32], 32); |
| 144 | pch_log_gpio_gpe(ps->gpe0_sts[GPE_95_64], ps->gpe0_en[GPE_95_64], 64); |
| 145 | /* Treat the STD as an extension of GPIO to obtain visibility. */ |
| 146 | pch_log_gpio_gpe(ps->gpe0_sts[GPE_STD], ps->gpe0_en[GPE_STD], 96); |
| 147 | } |
| 148 | |
Kyösti Mälkki | 6b43055 | 2021-01-22 07:52:43 +0200 | [diff] [blame] | 149 | static void pch_log_power_and_resets(const struct chipset_power_state *ps) |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 150 | { |
| 151 | /* Thermal Trip */ |
| 152 | if (ps->gblrst_cause[0] & GBLRST_CAUSE0_THERMTRIP) |
| 153 | elog_add_event(ELOG_TYPE_THERM_TRIP); |
| 154 | |
derek.huang | bebb2a1 | 2020-05-04 18:09:36 +0800 | [diff] [blame] | 155 | /* CSME-Initiated Host Reset with power down */ |
| 156 | if (ps->hpr_cause0 & HPR_CAUSE0_MI_HRPD) |
| 157 | elog_add_event(ELOG_TYPE_MI_HRPD); |
| 158 | |
| 159 | /* CSME-Initiated Host Reset with power cycle */ |
| 160 | if (ps->hpr_cause0 & HPR_CAUSE0_MI_HRPC) |
| 161 | elog_add_event(ELOG_TYPE_MI_HRPC); |
| 162 | |
| 163 | /* CSME-Initiated Host Reset without power cycle */ |
| 164 | if (ps->hpr_cause0 & HPR_CAUSE0_MI_HR) |
| 165 | elog_add_event(ELOG_TYPE_MI_HR); |
| 166 | |
Subrata Banik | 91e89c5 | 2019-11-01 18:30:01 +0530 | [diff] [blame] | 167 | /* PWR_FLR Power Failure */ |
| 168 | if (ps->gen_pmcon_a & PWR_FLR) |
| 169 | elog_add_event(ELOG_TYPE_POWER_FAIL); |
| 170 | |
| 171 | /* SUS Well Power Failure */ |
| 172 | if (ps->gen_pmcon_a & SUS_PWR_FLR) |
| 173 | elog_add_event(ELOG_TYPE_SUS_POWER_FAIL); |
| 174 | |
| 175 | /* TCO Timeout */ |
| 176 | if (ps->prev_sleep_state != ACPI_S3 && |
| 177 | ps->tco2_sts & TCO_STS_SECOND_TO) |
| 178 | elog_add_event(ELOG_TYPE_TCO_RESET); |
| 179 | |
| 180 | /* Power Button Override */ |
| 181 | if (ps->pm1_sts & PRBTNOR_STS) |
| 182 | elog_add_event(ELOG_TYPE_POWER_BUTTON_OVERRIDE); |
| 183 | |
| 184 | /* RTC reset */ |
| 185 | if (ps->gen_pmcon_b & RTC_BATTERY_DEAD) |
| 186 | elog_add_event(ELOG_TYPE_RTC_RESET); |
| 187 | |
| 188 | /* Host Reset Status */ |
| 189 | if (ps->gen_pmcon_a & HOST_RST_STS) |
| 190 | elog_add_event(ELOG_TYPE_SYSTEM_RESET); |
| 191 | |
| 192 | /* ACPI Wake Event */ |
| 193 | if (ps->prev_sleep_state != ACPI_S0) |
| 194 | elog_add_event_byte(ELOG_TYPE_ACPI_WAKE, ps->prev_sleep_state); |
| 195 | } |
| 196 | |
| 197 | static void pch_log_state(void *unused) |
| 198 | { |
| 199 | struct chipset_power_state *ps = pmc_get_power_state(); |
| 200 | |
| 201 | if (!ps) { |
| 202 | printk(BIOS_ERR, "chipset_power_state not found!\n"); |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | /* Power and Reset */ |
| 207 | pch_log_power_and_resets(ps); |
| 208 | |
| 209 | /* Wake Sources */ |
| 210 | if (ps->prev_sleep_state > ACPI_S0) |
| 211 | pch_log_wake_source(ps); |
| 212 | } |
| 213 | |
| 214 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, pch_log_state, NULL); |
| 215 | |
| 216 | void elog_gsmi_cb_platform_log_wake_source(void) |
| 217 | { |
| 218 | struct chipset_power_state ps; |
| 219 | pmc_fill_pm_reg_info(&ps); |
| 220 | pch_log_wake_source(&ps); |
| 221 | } |