Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 4 | * Copyright (C) 2010-2017 Advanced Micro Devices, Inc. |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | */ |
| 15 | |
| 16 | #include <console/console.h> |
| 17 | |
| 18 | #include <arch/io.h> |
Marshall Dawson | 8a906df | 2017-06-13 14:19:02 -0600 | [diff] [blame] | 19 | #include <bootstate.h> |
Marshall Dawson | e9b862e | 2017-09-22 15:14:46 -0600 | [diff] [blame] | 20 | #include <cpu/x86/smm.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 21 | #include <device/device.h> |
| 22 | #include <device/pci.h> |
| 23 | #include <device/pci_ids.h> |
| 24 | #include <device/pci_ops.h> |
| 25 | #include <cbmem.h> |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 26 | #include <elog.h> |
Richard Spiegel | 2bbc3dc | 2017-12-06 16:14:58 -0700 | [diff] [blame] | 27 | #include <amdblocks/amd_pci_util.h> |
Richard Spiegel | 7108107 | 2018-07-26 10:51:38 -0700 | [diff] [blame^] | 28 | #include <amdblocks/agesawrapper.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 29 | #include <soc/southbridge.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 30 | #include <soc/smi.h> |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 31 | #include <soc/amd_pci_int_defs.h> |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 32 | #include <delay.h> |
| 33 | #include <soc/pci_devs.h> |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 34 | #include <agesa_headers.h> |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 35 | #include <soc/nvs.h> |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 36 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 37 | /* |
| 38 | * Table of devices that need their AOAC registers enabled and waited |
| 39 | * upon (usually about .55 milliseconds). Instead of individual delays |
| 40 | * waiting for each device to become available, a single delay will be |
Richard Spiegel | 6dfbb59 | 2018-03-15 15:45:44 -0700 | [diff] [blame] | 41 | * executed. |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 42 | */ |
| 43 | const static struct stoneyridge_aoac aoac_devs[] = { |
| 44 | { (FCH_AOAC_D3_CONTROL_UART0 + CONFIG_UART_FOR_CONSOLE * 2), |
| 45 | (FCH_AOAC_D3_STATE_UART0 + CONFIG_UART_FOR_CONSOLE * 2) }, |
| 46 | { FCH_AOAC_D3_CONTROL_AMBA, FCH_AOAC_D3_STATE_AMBA }, |
| 47 | { FCH_AOAC_D3_CONTROL_I2C0, FCH_AOAC_D3_STATE_I2C0 }, |
| 48 | { FCH_AOAC_D3_CONTROL_I2C1, FCH_AOAC_D3_STATE_I2C1 }, |
| 49 | { FCH_AOAC_D3_CONTROL_I2C2, FCH_AOAC_D3_STATE_I2C2 }, |
| 50 | { FCH_AOAC_D3_CONTROL_I2C3, FCH_AOAC_D3_STATE_I2C3 } |
| 51 | }; |
| 52 | |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 53 | static int is_sata_config(void) |
| 54 | { |
| 55 | return !((CONFIG_STONEYRIDGE_SATA_MODE == SataNativeIde) |
| 56 | || (CONFIG_STONEYRIDGE_SATA_MODE == SataLegacyIde)); |
| 57 | } |
| 58 | |
Richard Spiegel | 7ea8e02 | 2018-01-16 14:40:10 -0700 | [diff] [blame] | 59 | static inline int sb_sata_enable(void) |
| 60 | { |
| 61 | /* True if IDE or AHCI. */ |
| 62 | return (CONFIG_STONEYRIDGE_SATA_MODE == SataNativeIde) || |
| 63 | (CONFIG_STONEYRIDGE_SATA_MODE == SataAhci); |
| 64 | } |
| 65 | |
| 66 | static inline int sb_ide_enable(void) |
| 67 | { |
| 68 | /* True if IDE or LEGACY IDE. */ |
| 69 | return (CONFIG_STONEYRIDGE_SATA_MODE == SataNativeIde) || |
| 70 | (CONFIG_STONEYRIDGE_SATA_MODE == SataLegacyIde); |
| 71 | } |
| 72 | |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 73 | void SetFchResetParams(FCH_RESET_INTERFACE *params) |
| 74 | { |
| 75 | params->Xhci0Enable = IS_ENABLED(CONFIG_STONEYRIDGE_XHCI_ENABLE); |
Richard Spiegel | a318d28 | 2018-01-16 13:25:40 -0700 | [diff] [blame] | 76 | params->SataEnable = sb_sata_enable(); |
| 77 | params->IdeEnable = sb_ide_enable(); |
Marshall Dawson | 2942db6 | 2017-12-14 10:00:27 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | void SetFchEnvParams(FCH_INTERFACE *params) |
| 81 | { |
| 82 | params->AzaliaController = AzEnable; |
| 83 | params->SataClass = CONFIG_STONEYRIDGE_SATA_MODE; |
| 84 | params->SataEnable = is_sata_config(); |
| 85 | params->IdeEnable = !params->SataEnable; |
| 86 | params->SataIdeMode = (CONFIG_STONEYRIDGE_SATA_MODE == SataLegacyIde); |
| 87 | } |
| 88 | |
| 89 | void SetFchMidParams(FCH_INTERFACE *params) |
| 90 | { |
| 91 | SetFchEnvParams(params); |
| 92 | } |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 93 | |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 94 | /* |
| 95 | * Table of APIC register index and associated IRQ name. Using IDX_XXX_NAME |
Jonathan Neuschäfer | 5268b76 | 2018-02-12 12:24:25 +0100 | [diff] [blame] | 96 | * provides a visible association with the index, therefore helping |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 97 | * maintainability of table. If a new index/name is defined in |
| 98 | * amd_pci_int_defs.h, just add the pair at the end of this table. |
| 99 | * Order is not important. |
| 100 | */ |
| 101 | const static struct irq_idx_name irq_association[] = { |
Richard Spiegel | e89d444 | 2017-12-08 07:52:42 -0700 | [diff] [blame] | 102 | { PIRQ_A, "INTA#" }, |
| 103 | { PIRQ_B, "INTB#" }, |
| 104 | { PIRQ_C, "INTC#" }, |
| 105 | { PIRQ_D, "INTD#" }, |
| 106 | { PIRQ_E, "INTE#" }, |
| 107 | { PIRQ_F, "INTF#" }, |
| 108 | { PIRQ_G, "INTG#" }, |
| 109 | { PIRQ_H, "INTH#" }, |
| 110 | { PIRQ_MISC, "Misc" }, |
| 111 | { PIRQ_MISC0, "Misc0" }, |
| 112 | { PIRQ_MISC1, "Misc1" }, |
| 113 | { PIRQ_MISC2, "Misc2" }, |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 114 | { PIRQ_SIRQA, "Ser IRQ INTA" }, |
| 115 | { PIRQ_SIRQB, "Ser IRQ INTB" }, |
| 116 | { PIRQ_SIRQC, "Ser IRQ INTC" }, |
| 117 | { PIRQ_SIRQD, "Ser IRQ INTD" }, |
Richard Spiegel | e89d444 | 2017-12-08 07:52:42 -0700 | [diff] [blame] | 118 | { PIRQ_SCI, "SCI" }, |
| 119 | { PIRQ_SMBUS, "SMBUS" }, |
| 120 | { PIRQ_ASF, "ASF" }, |
| 121 | { PIRQ_HDA, "HDA" }, |
| 122 | { PIRQ_FC, "FC" }, |
| 123 | { PIRQ_PMON, "PerMon" }, |
| 124 | { PIRQ_SD, "SD" }, |
| 125 | { PIRQ_SDIO, "SDIOt" }, |
Richard Spiegel | e89d444 | 2017-12-08 07:52:42 -0700 | [diff] [blame] | 126 | { PIRQ_EHCI, "EHCI" }, |
| 127 | { PIRQ_XHCI, "XHCI" }, |
| 128 | { PIRQ_SATA, "SATA" }, |
| 129 | { PIRQ_GPIO, "GPIO" }, |
| 130 | { PIRQ_I2C0, "I2C0" }, |
| 131 | { PIRQ_I2C1, "I2C1" }, |
| 132 | { PIRQ_I2C2, "I2C2" }, |
| 133 | { PIRQ_I2C3, "I2C3" }, |
| 134 | { PIRQ_UART0, "UART0" }, |
| 135 | { PIRQ_UART1, "UART1" }, |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 136 | }; |
| 137 | |
Richard Spiegel | ebf3aa8 | 2017-11-24 07:47:42 -0700 | [diff] [blame] | 138 | /* |
| 139 | * Structure to simplify code obtaining the total of used wide IO |
| 140 | * registers and the size assigned to each. |
| 141 | */ |
| 142 | static struct wide_io_ioport_and_bits { |
| 143 | uint32_t enable; |
| 144 | uint16_t port; |
| 145 | uint8_t alt; |
| 146 | } wio_io_en[TOTAL_WIDEIO_PORTS] = { |
| 147 | { |
| 148 | LPC_WIDEIO0_ENABLE, |
| 149 | LPC_WIDEIO_GENERIC_PORT, |
| 150 | LPC_ALT_WIDEIO0_ENABLE |
| 151 | }, |
| 152 | { |
| 153 | LPC_WIDEIO1_ENABLE, |
| 154 | LPC_WIDEIO1_GENERIC_PORT, |
| 155 | LPC_ALT_WIDEIO1_ENABLE |
| 156 | }, |
| 157 | { |
| 158 | LPC_WIDEIO2_ENABLE, |
| 159 | LPC_WIDEIO2_GENERIC_PORT, |
| 160 | LPC_ALT_WIDEIO2_ENABLE |
| 161 | } |
| 162 | }; |
| 163 | |
Richard Spiegel | 376dc82 | 2017-12-01 08:24:26 -0700 | [diff] [blame] | 164 | const struct irq_idx_name *sb_get_apic_reg_association(size_t *size) |
| 165 | { |
| 166 | *size = ARRAY_SIZE(irq_association); |
| 167 | return irq_association; |
| 168 | } |
| 169 | |
Richard Spiegel | ebf3aa8 | 2017-11-24 07:47:42 -0700 | [diff] [blame] | 170 | /** |
| 171 | * @brief Find the size of a particular wide IO |
| 172 | * |
| 173 | * @param index = index of desired wide IO |
| 174 | * |
| 175 | * @return size of desired wide IO |
| 176 | */ |
| 177 | uint16_t sb_wideio_size(int index) |
| 178 | { |
| 179 | uint32_t enable_register; |
| 180 | uint16_t size = 0; |
| 181 | uint8_t alternate_register; |
| 182 | |
| 183 | if (index >= TOTAL_WIDEIO_PORTS) |
| 184 | return size; |
| 185 | enable_register = pci_read_config32(SOC_LPC_DEV, |
| 186 | LPC_IO_OR_MEM_DECODE_ENABLE); |
| 187 | alternate_register = pci_read_config8(SOC_LPC_DEV, |
| 188 | LPC_ALT_WIDEIO_RANGE_ENABLE); |
| 189 | if (enable_register & wio_io_en[index].enable) |
| 190 | size = (alternate_register & wio_io_en[index].alt) ? |
| 191 | 16 : 512; |
| 192 | return size; |
| 193 | } |
| 194 | |
| 195 | /** |
| 196 | * @brief Identify if any LPC wide IO is covering the IO range |
| 197 | * |
| 198 | * @param start = start of IO range |
| 199 | * @param size = size of IO range |
| 200 | * |
| 201 | * @return Index of wide IO covering the range or error |
| 202 | */ |
| 203 | int sb_find_wideio_range(uint16_t start, uint16_t size) |
| 204 | { |
| 205 | uint32_t enable_register; |
| 206 | int i, index = WIDEIO_RANGE_ERROR; |
| 207 | uint16_t end, current_size, start_wideio, end_wideio; |
| 208 | |
| 209 | end = start + size; |
| 210 | enable_register = pci_read_config32(SOC_LPC_DEV, |
| 211 | LPC_IO_OR_MEM_DECODE_ENABLE); |
| 212 | for (i = 0; i < TOTAL_WIDEIO_PORTS; i++) { |
| 213 | current_size = sb_wideio_size(i); |
| 214 | if (current_size == 0) |
| 215 | continue; |
| 216 | start_wideio = pci_read_config16(SOC_LPC_DEV, |
| 217 | wio_io_en[i].port); |
| 218 | end_wideio = start_wideio + current_size; |
| 219 | if ((start >= start_wideio) && (end <= end_wideio)) { |
| 220 | index = i; |
| 221 | break; |
| 222 | } |
| 223 | } |
| 224 | return index; |
| 225 | } |
| 226 | |
| 227 | /** |
| 228 | * @brief Program a LPC wide IO to support an IO range |
| 229 | * |
| 230 | * @param start = start of range to be routed through wide IO |
| 231 | * @param size = size of range to be routed through wide IO |
| 232 | * |
| 233 | * @return Index of wide IO register used or error |
| 234 | */ |
| 235 | int sb_set_wideio_range(uint16_t start, uint16_t size) |
| 236 | { |
| 237 | int i, index = WIDEIO_RANGE_ERROR; |
| 238 | uint32_t enable_register; |
| 239 | uint8_t alternate_register; |
| 240 | |
| 241 | enable_register = pci_read_config32(SOC_LPC_DEV, |
| 242 | LPC_IO_OR_MEM_DECODE_ENABLE); |
| 243 | alternate_register = pci_read_config8(SOC_LPC_DEV, |
| 244 | LPC_ALT_WIDEIO_RANGE_ENABLE); |
| 245 | for (i = 0; i < TOTAL_WIDEIO_PORTS; i++) { |
| 246 | if (enable_register & wio_io_en[i].enable) |
| 247 | continue; |
| 248 | index = i; |
| 249 | pci_write_config16(SOC_LPC_DEV, wio_io_en[i].port, start); |
| 250 | enable_register |= wio_io_en[i].enable; |
| 251 | pci_write_config32(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE, |
| 252 | enable_register); |
| 253 | if (size <= 16) |
| 254 | alternate_register |= wio_io_en[i].alt; |
| 255 | else |
| 256 | alternate_register &= ~wio_io_en[i].alt; |
| 257 | pci_write_config8(SOC_LPC_DEV, |
| 258 | LPC_ALT_WIDEIO_RANGE_ENABLE, |
| 259 | alternate_register); |
| 260 | break; |
| 261 | } |
| 262 | return index; |
| 263 | } |
| 264 | |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 265 | static void power_on_aoac_device(int aoac_device_control_register) |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 266 | { |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 267 | uint8_t byte; |
| 268 | uint8_t *register_pointer = (uint8_t *)(uintptr_t)AOAC_MMIO_BASE |
| 269 | + aoac_device_control_register; |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 270 | |
| 271 | /* Power on the UART and AMBA devices */ |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 272 | byte = read8(register_pointer); |
| 273 | byte |= FCH_AOAC_PWR_ON_DEV; |
| 274 | write8(register_pointer, byte); |
| 275 | } |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 276 | |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 277 | static bool is_aoac_device_enabled(int aoac_device_status_register) |
| 278 | { |
| 279 | uint8_t byte; |
| 280 | byte = read8((uint8_t *)(uintptr_t)AOAC_MMIO_BASE |
| 281 | + aoac_device_status_register); |
| 282 | byte &= (FCH_AOAC_PWR_RST_STATE | FCH_AOAC_RST_CLK_OK_STATE); |
| 283 | if (byte == (FCH_AOAC_PWR_RST_STATE | FCH_AOAC_RST_CLK_OK_STATE)) |
| 284 | return true; |
| 285 | else |
| 286 | return false; |
| 287 | } |
| 288 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 289 | void enable_aoac_devices(void) |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 290 | { |
| 291 | bool status; |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 292 | int i; |
Garrett Kirkendall | a0ff6fc | 2018-03-06 09:23:47 -0600 | [diff] [blame] | 293 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 294 | for (i = 0; i < ARRAY_SIZE(aoac_devs); i++) |
| 295 | power_on_aoac_device(aoac_devs[i].enable); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 296 | |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 297 | /* Wait for AOAC devices to indicate power and clock OK */ |
| 298 | do { |
| 299 | udelay(100); |
| 300 | status = true; |
| 301 | for (i = 0; i < ARRAY_SIZE(aoac_devs); i++) |
| 302 | status &= is_aoac_device_enabled(aoac_devs[i].status); |
| 303 | } while (!status); |
| 304 | } |
| 305 | |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 306 | void sb_pci_port80(void) |
| 307 | { |
| 308 | u8 byte; |
| 309 | |
| 310 | byte = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH); |
| 311 | byte &= ~DECODE_IO_PORT_ENABLE4_H; /* disable lpc port 80 */ |
| 312 | pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH, byte); |
| 313 | } |
| 314 | |
| 315 | void sb_lpc_port80(void) |
| 316 | { |
| 317 | u8 byte; |
| 318 | |
| 319 | /* Enable LPC controller */ |
| 320 | outb(PM_LPC_GATING, PM_INDEX); |
| 321 | byte = inb(PM_DATA); |
| 322 | byte |= PM_LPC_ENABLE; |
| 323 | outb(PM_LPC_GATING, PM_INDEX); |
| 324 | outb(byte, PM_DATA); |
| 325 | |
| 326 | /* Enable port 80 LPC decode in pci function 3 configuration space. */ |
| 327 | byte = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH); |
| 328 | byte |= DECODE_IO_PORT_ENABLE4_H; /* enable port 80 */ |
| 329 | pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH, byte); |
| 330 | } |
| 331 | |
| 332 | void sb_lpc_decode(void) |
| 333 | { |
| 334 | u32 tmp = 0; |
| 335 | |
| 336 | /* Enable I/O decode to LPC bus */ |
| 337 | tmp = DECODE_ENABLE_PARALLEL_PORT0 | DECODE_ENABLE_PARALLEL_PORT2 |
| 338 | | DECODE_ENABLE_PARALLEL_PORT4 | DECODE_ENABLE_SERIAL_PORT0 |
| 339 | | DECODE_ENABLE_SERIAL_PORT1 | DECODE_ENABLE_SERIAL_PORT2 |
| 340 | | DECODE_ENABLE_SERIAL_PORT3 | DECODE_ENABLE_SERIAL_PORT4 |
| 341 | | DECODE_ENABLE_SERIAL_PORT5 | DECODE_ENABLE_SERIAL_PORT6 |
| 342 | | DECODE_ENABLE_SERIAL_PORT7 | DECODE_ENABLE_AUDIO_PORT0 |
| 343 | | DECODE_ENABLE_AUDIO_PORT1 | DECODE_ENABLE_AUDIO_PORT2 |
| 344 | | DECODE_ENABLE_AUDIO_PORT3 | DECODE_ENABLE_MSS_PORT2 |
| 345 | | DECODE_ENABLE_MSS_PORT3 | DECODE_ENABLE_FDC_PORT0 |
| 346 | | DECODE_ENABLE_FDC_PORT1 | DECODE_ENABLE_GAME_PORT |
| 347 | | DECODE_ENABLE_KBC_PORT | DECODE_ENABLE_ACPIUC_PORT |
| 348 | | DECODE_ENABLE_ADLIB_PORT; |
| 349 | |
| 350 | pci_write_config32(SOC_LPC_DEV, LPC_IO_PORT_DECODE_ENABLE, tmp); |
| 351 | } |
| 352 | |
Garrett Kirkendall | 9858bd2 | 2018-03-07 15:38:14 -0600 | [diff] [blame] | 353 | void sb_acpi_mmio_decode(void) |
| 354 | { |
| 355 | uint8_t byte; |
| 356 | |
| 357 | /* Enable ACPI MMIO range 0xfed80000 - 0xfed81fff */ |
| 358 | outb(PM_ISA_CONTROL, PM_INDEX); |
| 359 | byte = inb(PM_DATA); |
| 360 | byte |= MMIO_EN; |
| 361 | outb(PM_ISA_CONTROL, PM_INDEX); |
| 362 | outb(byte, PM_DATA); |
| 363 | } |
| 364 | |
Raul E Rangel | 5b05823 | 2018-06-28 16:31:45 -0600 | [diff] [blame] | 365 | static void sb_enable_cf9_io(void) |
| 366 | { |
| 367 | uint32_t reg = pm_read32(PM_DECODE_EN); |
| 368 | |
| 369 | pm_write32(PM_DECODE_EN, reg | CF9_IO_EN); |
| 370 | } |
| 371 | |
Raul E Rangel | 9abc3fe | 2018-06-28 16:31:45 -0600 | [diff] [blame] | 372 | static void sb_enable_legacy_io(void) |
| 373 | { |
| 374 | uint32_t reg = pm_read32(PM_DECODE_EN); |
| 375 | |
| 376 | pm_write32(PM_DECODE_EN, reg | LEGACY_IO_EN); |
| 377 | } |
| 378 | |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 379 | void sb_clk_output_48Mhz(void) |
| 380 | { |
| 381 | u32 ctrl; |
Garrett Kirkendall | d255830 | 2018-03-06 09:05:20 -0600 | [diff] [blame] | 382 | u32 *misc_clk_cntl_1_ptr = (u32 *)(uintptr_t)(MISC_MMIO_BASE |
| 383 | + MISC_MISC_CLK_CNTL_1); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 384 | |
| 385 | /* |
| 386 | * Enable the X14M_25M_48M_OSC pin and leaving it at it's default so |
| 387 | * 48Mhz will be on ball AP13 (FT3b package) |
| 388 | */ |
Garrett Kirkendall | d255830 | 2018-03-06 09:05:20 -0600 | [diff] [blame] | 389 | ctrl = read32(misc_clk_cntl_1_ptr); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 390 | |
| 391 | /* clear the OSCOUT1_ClkOutputEnb to enable the 48 Mhz clock */ |
Garrett Kirkendall | d255830 | 2018-03-06 09:05:20 -0600 | [diff] [blame] | 392 | ctrl &= ~OSCOUT1_CLK_OUTPUT_ENB; |
| 393 | write32(misc_clk_cntl_1_ptr, ctrl); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | static uintptr_t sb_spibase(void) |
| 397 | { |
| 398 | u32 base, enables; |
| 399 | |
| 400 | /* Make sure the base address is predictable */ |
| 401 | base = pci_read_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER); |
| 402 | enables = base & 0xf; |
| 403 | base &= ~0x3f; |
| 404 | |
| 405 | if (!base) { |
| 406 | base = SPI_BASE_ADDRESS; |
| 407 | pci_write_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER, |
| 408 | base | enables | SPI_ROM_ENABLE); |
| 409 | /* PCI_COMMAND_MEMORY is read-only and enabled. */ |
| 410 | } |
| 411 | return (uintptr_t)base; |
| 412 | } |
| 413 | |
| 414 | void sb_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm) |
| 415 | { |
| 416 | uintptr_t base = sb_spibase(); |
| 417 | write16((void *)base + SPI100_SPEED_CONFIG, |
| 418 | (norm << SPI_NORM_SPEED_NEW_SH) | |
| 419 | (fast << SPI_FAST_SPEED_NEW_SH) | |
| 420 | (alt << SPI_ALT_SPEED_NEW_SH) | |
| 421 | (tpm << SPI_TPM_SPEED_NEW_SH)); |
| 422 | write16((void *)base + SPI100_ENABLE, SPI_USE_SPI100); |
| 423 | } |
| 424 | |
| 425 | void sb_disable_4dw_burst(void) |
| 426 | { |
| 427 | uintptr_t base = sb_spibase(); |
| 428 | write16((void *)base + SPI100_HOST_PREF_CONFIG, |
| 429 | read16((void *)base + SPI100_HOST_PREF_CONFIG) |
| 430 | & ~SPI_RD4DW_EN_HOST); |
| 431 | } |
| 432 | |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 433 | void sb_read_mode(u32 mode) |
| 434 | { |
| 435 | uintptr_t base = sb_spibase(); |
| 436 | write32((void *)base + SPI_CNTRL0, |
| 437 | (read32((void *)base + SPI_CNTRL0) |
| 438 | & ~SPI_READ_MODE_MASK) | mode); |
| 439 | } |
| 440 | |
Garrett Kirkendall | 6575306 | 2018-03-07 16:12:11 -0600 | [diff] [blame] | 441 | /* |
| 442 | * Enable FCH to decode TPM associated Memory and IO regions |
| 443 | * |
| 444 | * Enable decoding of TPM cycles defined in TPM 1.2 spec |
| 445 | * Enable decoding of legacy TPM addresses: IO addresses 0x7f- |
| 446 | * 0x7e and 0xef-0xee. |
| 447 | * This function should be called if TPM is connected in any way to the FCH and |
| 448 | * conforms to the regions decoded. |
| 449 | * Absent any other routing configuration the TPM cycles will be claimed by the |
| 450 | * LPC bus |
| 451 | */ |
| 452 | void sb_tpm_decode(void) |
| 453 | { |
| 454 | u32 value; |
| 455 | |
| 456 | value = pci_read_config32(SOC_LPC_DEV, LPC_TRUSTED_PLATFORM_MODULE); |
| 457 | value |= TPM_12_EN | TPM_LEGACY_EN; |
| 458 | pci_write_config32(SOC_LPC_DEV, LPC_TRUSTED_PLATFORM_MODULE, value); |
| 459 | } |
| 460 | |
| 461 | /* |
| 462 | * Enable FCH to decode TPM associated Memory and IO regions to SPI |
| 463 | * |
| 464 | * This should be used if TPM is connected to SPI bus. |
| 465 | * Assumes SPI address space is already configured via a call to sb_spibase(). |
| 466 | */ |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 467 | void sb_tpm_decode_spi(void) |
| 468 | { |
Garrett Kirkendall | 6575306 | 2018-03-07 16:12:11 -0600 | [diff] [blame] | 469 | /* Enable TPM decoding to FCH */ |
| 470 | sb_tpm_decode(); |
| 471 | |
| 472 | /* Route TPM accesses to SPI */ |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 473 | u32 spibase = pci_read_config32(SOC_LPC_DEV, |
| 474 | SPIROM_BASE_ADDRESS_REGISTER); |
| 475 | pci_write_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER, spibase |
| 476 | | ROUTE_TPM_2_SPI); |
| 477 | } |
| 478 | |
| 479 | /* |
| 480 | * Enable 4MB (LPC) ROM access at 0xFFC00000 - 0xFFFFFFFF. |
| 481 | * |
| 482 | * Hardware should enable LPC ROM by pin straps. This function does not |
| 483 | * handle the theoretically possible PCI ROM, FWH, or SPI ROM configurations. |
| 484 | * |
| 485 | * The southbridge power-on default is to map 512K ROM space. |
| 486 | * |
| 487 | */ |
| 488 | void sb_enable_rom(void) |
| 489 | { |
| 490 | u8 reg8; |
| 491 | |
| 492 | /* |
| 493 | * Decode variable LPC ROM address ranges 1 and 2. |
| 494 | * Bits 3-4 are not defined in any publicly available datasheet |
| 495 | */ |
| 496 | reg8 = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE); |
| 497 | reg8 |= (1 << 3) | (1 << 4); |
| 498 | pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE, reg8); |
| 499 | |
| 500 | /* |
| 501 | * LPC ROM address range 1: |
| 502 | * Enable LPC ROM range mirroring start at 0x000e(0000). |
| 503 | */ |
| 504 | pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE1_START, 0x000e); |
| 505 | |
| 506 | /* Enable LPC ROM range mirroring end at 0x000f(ffff). */ |
| 507 | pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE1_END, 0x000f); |
| 508 | |
| 509 | /* |
| 510 | * LPC ROM address range 2: |
| 511 | * |
| 512 | * Enable LPC ROM range start at: |
| 513 | * 0xfff8(0000): 512KB |
| 514 | * 0xfff0(0000): 1MB |
| 515 | * 0xffe0(0000): 2MB |
| 516 | * 0xffc0(0000): 4MB |
| 517 | */ |
| 518 | pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE2_START, 0x10000 |
| 519 | - (CONFIG_COREBOOT_ROMSIZE_KB >> 6)); |
| 520 | |
| 521 | /* Enable LPC ROM range end at 0xffff(ffff). */ |
| 522 | pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE2_END, 0xffff); |
| 523 | } |
| 524 | |
Marc Jones | cfb1680 | 2018-04-20 16:27:41 -0600 | [diff] [blame] | 525 | static void sb_lpc_early_setup(void) |
| 526 | { |
| 527 | uint32_t dword; |
| 528 | |
| 529 | /* Enable SPI prefetch */ |
| 530 | dword = pci_read_config32(SOC_LPC_DEV, LPC_ROM_DMA_EC_HOST_CONTROL); |
| 531 | dword |= SPI_FROM_HOST_PREFETCH_EN | SPI_FROM_USB_PREFETCH_EN; |
| 532 | pci_write_config32(SOC_LPC_DEV, LPC_ROM_DMA_EC_HOST_CONTROL, dword); |
| 533 | |
| 534 | if (IS_ENABLED(CONFIG_STONEYRIDGE_LEGACY_FREE)) { |
| 535 | /* Decode SIOs at 2E/2F and 4E/4F */ |
| 536 | dword = pci_read_config32(SOC_LPC_DEV, |
| 537 | LPC_IO_OR_MEM_DECODE_ENABLE); |
| 538 | dword |= DECODE_ALTERNATE_SIO_ENABLE | DECODE_SIO_ENABLE; |
| 539 | pci_write_config32(SOC_LPC_DEV, |
| 540 | LPC_IO_OR_MEM_DECODE_ENABLE, dword); |
| 541 | } |
| 542 | } |
| 543 | |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 544 | void bootblock_fch_early_init(void) |
| 545 | { |
| 546 | sb_enable_rom(); |
| 547 | sb_lpc_port80(); |
| 548 | sb_lpc_decode(); |
Marc Jones | cfb1680 | 2018-04-20 16:27:41 -0600 | [diff] [blame] | 549 | sb_lpc_early_setup(); |
Garrett Kirkendall | 64294eb | 2018-03-16 13:00:46 -0500 | [diff] [blame] | 550 | sb_spibase(); |
Marc Jones | cfb1680 | 2018-04-20 16:27:41 -0600 | [diff] [blame] | 551 | sb_disable_4dw_burst(); /* Must be disabled on CZ(ST) */ |
Garrett Kirkendall | e7513e0d | 2018-03-14 12:01:36 -0500 | [diff] [blame] | 552 | sb_acpi_mmio_decode(); |
Raul E Rangel | 5b05823 | 2018-06-28 16:31:45 -0600 | [diff] [blame] | 553 | sb_enable_cf9_io(); |
Raul E Rangel | 9abc3fe | 2018-06-28 16:31:45 -0600 | [diff] [blame] | 554 | sb_enable_legacy_io(); |
Richard Spiegel | 0e0e93c | 2018-03-13 10:19:51 -0700 | [diff] [blame] | 555 | enable_aoac_devices(); |
Richard Spiegel | bec44f2 | 2017-11-24 07:41:29 -0700 | [diff] [blame] | 556 | } |
| 557 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 558 | void sb_enable(device_t dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 559 | { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 560 | printk(BIOS_DEBUG, "%s\n", __func__); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 561 | } |
| 562 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 563 | static void sb_init_acpi_ports(void) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 564 | { |
Marshall Dawson | 91b8041 | 2017-09-27 16:44:40 -0600 | [diff] [blame] | 565 | u32 reg; |
| 566 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 567 | /* We use some of these ports in SMM regardless of whether or not |
| 568 | * ACPI tables are generated. Enable these ports indiscriminately. |
| 569 | */ |
| 570 | |
| 571 | pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK); |
| 572 | pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK); |
| 573 | pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK); |
| 574 | pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK); |
| 575 | /* CpuControl is in \_PR.CP00, 6 bytes */ |
| 576 | pm_write16(PM_CPU_CTRL, ACPI_CPU_CONTROL); |
| 577 | |
| 578 | if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)) { |
Marshall Dawson | a05fdcb | 2017-09-27 15:01:37 -0600 | [diff] [blame] | 579 | /* APMC - SMI Command Port */ |
Marshall Dawson | e9b862e | 2017-09-22 15:14:46 -0600 | [diff] [blame] | 580 | pm_write16(PM_ACPI_SMI_CMD, APM_CNT); |
Marshall Dawson | a05fdcb | 2017-09-27 15:01:37 -0600 | [diff] [blame] | 581 | configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI); |
Marshall Dawson | 91b8041 | 2017-09-27 16:44:40 -0600 | [diff] [blame] | 582 | |
| 583 | /* SMI on SlpTyp requires sending SMI before completion |
| 584 | * response of the I/O write. The BKDG also specifies |
| 585 | * clearing ForceStpClkRetry for SMI trapping. |
| 586 | */ |
| 587 | reg = pm_read32(PM_PCI_CTRL); |
| 588 | reg |= FORCE_SLPSTATE_RETRY; |
| 589 | reg &= ~FORCE_STPCLK_RETRY; |
| 590 | pm_write32(PM_PCI_CTRL, reg); |
| 591 | |
| 592 | /* Disable SlpTyp feature */ |
| 593 | reg = pm_read8(PM_RST_CTRL1); |
| 594 | reg &= ~SLPTYPE_CONTROL_EN; |
| 595 | pm_write8(PM_RST_CTRL1, reg); |
| 596 | |
| 597 | configure_smi(SMITYPE_SLP_TYP, SMI_MODE_SMI); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 598 | } else { |
| 599 | pm_write16(PM_ACPI_SMI_CMD, 0); |
| 600 | } |
| 601 | |
Marshall Dawson | 5e2e74f | 2017-11-10 09:59:56 -0700 | [diff] [blame] | 602 | /* Decode ACPI registers and enable standard features */ |
| 603 | pm_write8(PM_ACPI_CONF, PM_ACPI_DECODE_STD | |
| 604 | PM_ACPI_GLOBAL_EN | |
| 605 | PM_ACPI_RTC_EN_EN | |
| 606 | PM_ACPI_TIMER_EN_EN); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 607 | } |
| 608 | |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 609 | static void print_num_status_bits(int num_bits, uint32_t status, |
| 610 | const char *const bit_names[]) |
| 611 | { |
| 612 | int i; |
| 613 | |
| 614 | if (!status) |
| 615 | return; |
| 616 | |
| 617 | for (i = num_bits - 1; i >= 0; i--) { |
| 618 | if (status & (1 << i)) { |
| 619 | if (bit_names[i]) |
| 620 | printk(BIOS_DEBUG, "%s ", bit_names[i]); |
| 621 | else |
| 622 | printk(BIOS_DEBUG, "BIT%d ", i); |
| 623 | } |
| 624 | } |
| 625 | } |
| 626 | |
| 627 | static uint16_t reset_pm1_status(void) |
| 628 | { |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 629 | uint16_t pm1_sts = inw(ACPI_PM1_STS); |
| 630 | outw(pm1_sts, ACPI_PM1_STS); |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 631 | return pm1_sts; |
| 632 | } |
| 633 | |
| 634 | static uint16_t print_pm1_status(uint16_t pm1_sts) |
| 635 | { |
| 636 | static const char *const pm1_sts_bits[] = { |
| 637 | [0] = "TMROF", |
| 638 | [4] = "BMSTATUS", |
| 639 | [5] = "GBL", |
| 640 | [8] = "PWRBTN", |
| 641 | [10] = "RTC", |
| 642 | [14] = "PCIEXPWAK", |
| 643 | [15] = "WAK", |
| 644 | }; |
| 645 | |
| 646 | if (!pm1_sts) |
| 647 | return 0; |
| 648 | |
| 649 | printk(BIOS_SPEW, "PM1_STS: "); |
| 650 | print_num_status_bits(ARRAY_SIZE(pm1_sts_bits), pm1_sts, pm1_sts_bits); |
| 651 | printk(BIOS_SPEW, "\n"); |
| 652 | |
| 653 | return pm1_sts; |
| 654 | } |
| 655 | |
| 656 | static void sb_log_pm1_status(uint16_t pm1_sts) |
| 657 | { |
| 658 | if (!IS_ENABLED(CONFIG_ELOG)) |
| 659 | return; |
| 660 | |
Daniel Kurtz | b6fdd22 | 2018-05-24 15:52:45 -0600 | [diff] [blame] | 661 | if (pm1_sts & WAK_STS) |
| 662 | elog_add_event_byte(ELOG_TYPE_ACPI_WAKE, |
| 663 | acpi_is_wakeup_s3() ? ACPI_S3 : ACPI_S5); |
| 664 | |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 665 | if (pm1_sts & PWRBTN_STS) |
| 666 | elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0); |
| 667 | |
| 668 | if (pm1_sts & RTC_STS) |
| 669 | elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0); |
| 670 | |
| 671 | if (pm1_sts & PCIEXPWAK_STS) |
| 672 | elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0); |
| 673 | } |
| 674 | |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 675 | static void sb_save_sws(uint16_t pm1_status) |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 676 | { |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 677 | struct soc_power_reg *sws; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 678 | uint32_t reg32; |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 679 | uint16_t reg16; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 680 | |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 681 | sws = cbmem_add(CBMEM_ID_POWER_STATE, sizeof(struct soc_power_reg)); |
| 682 | if (sws == NULL) |
| 683 | return; |
| 684 | sws->pm1_sts = pm1_status; |
| 685 | sws->pm1_en = inw(ACPI_PM1_EN); |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 686 | reg32 = inl(ACPI_GPE0_STS); |
| 687 | outl(ACPI_GPE0_STS, reg32); |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 688 | sws->gpe0_sts = reg32; |
| 689 | sws->gpe0_en = inl(ACPI_GPE0_EN); |
| 690 | reg16 = inw(ACPI_PM1_CNT_BLK); |
| 691 | reg16 &= SLP_TYP; |
| 692 | sws->wake_from = reg16 >> SLP_TYP_SHIFT; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 693 | } |
| 694 | |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 695 | static void sb_clear_pm1_status(void) |
| 696 | { |
| 697 | uint16_t pm1_sts = reset_pm1_status(); |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 698 | |
| 699 | sb_save_sws(pm1_sts); |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 700 | sb_log_pm1_status(pm1_sts); |
| 701 | print_pm1_status(pm1_sts); |
| 702 | } |
| 703 | |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 704 | static int get_index_bit(uint32_t value, uint16_t limit) |
| 705 | { |
| 706 | uint16_t i; |
| 707 | uint32_t t; |
| 708 | |
Richard Spiegel | ef73cb8 | 2018-06-19 07:40:18 -0700 | [diff] [blame] | 709 | if (limit >= TOTAL_BITS(uint32_t)) |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 710 | return -1; |
| 711 | |
| 712 | /* get a mask of valid bits. Ex limit = 3, set bits 0-2 */ |
| 713 | t = (1 << limit) - 1; |
| 714 | if ((value & t) == 0) |
| 715 | return -1; |
| 716 | t = 1; |
| 717 | for (i = 0; i < limit; i++) { |
| 718 | if (value & t) |
| 719 | break; |
| 720 | t <<= 1; |
| 721 | } |
| 722 | return i; |
| 723 | } |
| 724 | |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 725 | static void set_nvs_sws(void *unused) |
| 726 | { |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 727 | struct soc_power_reg *sws; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 728 | struct global_nvs_t *gnvs; |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 729 | int index; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 730 | |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 731 | sws = cbmem_find(CBMEM_ID_POWER_STATE); |
| 732 | if (sws == NULL) |
| 733 | return; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 734 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 735 | if (gnvs == NULL) |
| 736 | return; |
| 737 | |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 738 | index = get_index_bit(sws->pm1_sts & sws->pm1_en, PM1_LIMIT); |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 739 | if (index < 0) |
| 740 | gnvs->pm1i = ~0ULL; |
| 741 | else |
| 742 | gnvs->pm1i = index; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 743 | |
Richard Spiegel | 35282a0 | 2018-06-14 14:57:54 -0700 | [diff] [blame] | 744 | index = get_index_bit(sws->gpe0_sts & sws->gpe0_en, GPE0_LIMIT); |
Richard Spiegel | 572f498 | 2018-05-25 15:49:33 -0700 | [diff] [blame] | 745 | if (index < 0) |
| 746 | gnvs->gpei = ~0ULL; |
| 747 | else |
| 748 | gnvs->gpei = index; |
Richard Spiegel | dbee8ae | 2018-05-09 17:34:04 -0700 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, set_nvs_sws, NULL); |
| 752 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 753 | void southbridge_init(void *chip_info) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 754 | { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 755 | sb_init_acpi_ports(); |
Marshall Dawson | 70f051f | 2018-03-20 10:27:41 -0600 | [diff] [blame] | 756 | sb_clear_pm1_status(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 757 | } |
| 758 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 759 | void southbridge_final(void *chip_info) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 760 | { |
Richard Spiegel | 6a38914 | 2018-03-05 14:28:10 -0700 | [diff] [blame] | 761 | uint8_t restored_power = PM_S5_AT_POWER_RECOVERY; |
| 762 | |
Richard Spiegel | 6a38914 | 2018-03-05 14:28:10 -0700 | [diff] [blame] | 763 | if (IS_ENABLED(CONFIG_MAINBOARD_POWER_RESTORE)) |
| 764 | restored_power = PM_RESTORE_S0_IF_PREV_S0; |
| 765 | pm_write8(PM_RTC_SHADOW, restored_power); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 766 | } |
Marshall Dawson | 8a906df | 2017-06-13 14:19:02 -0600 | [diff] [blame] | 767 | |
| 768 | /* |
| 769 | * Update the PCI devices with a valid IRQ number |
| 770 | * that is set in the mainboard PCI_IRQ structures. |
| 771 | */ |
| 772 | static void set_pci_irqs(void *unused) |
| 773 | { |
| 774 | /* Write PCI_INTR regs 0xC00/0xC01 */ |
| 775 | write_pci_int_table(); |
| 776 | |
| 777 | /* Write IRQs for all devicetree enabled devices */ |
| 778 | write_pci_cfg_irqs(); |
| 779 | } |
| 780 | |
| 781 | /* |
| 782 | * Hook this function into the PCI state machine |
| 783 | * on entry into BS_DEV_ENABLE. |
| 784 | */ |
| 785 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL); |