blob: eb4188219b929e26418504b9c668a5bcd47a09d3 [file] [log] [blame]
Marc Jones24484842017-05-04 21:17:45 -06001/*
2 * This file is part of the coreboot project.
3 *
Richard Spiegel376dc822017-12-01 08:24:26 -07004 * Copyright (C) 2010-2017 Advanced Micro Devices, Inc.
Marc Jones24484842017-05-04 21:17:45 -06005 *
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 Dawson8a906df2017-06-13 14:19:02 -060019#include <bootstate.h>
Marshall Dawsone9b862e2017-09-22 15:14:46 -060020#include <cpu/x86/smm.h>
Marc Jones24484842017-05-04 21:17:45 -060021#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 Dawson70f051f2018-03-20 10:27:41 -060026#include <elog.h>
Richard Spiegel2bbc3dc2017-12-06 16:14:58 -070027#include <amdblocks/amd_pci_util.h>
Richard Spiegel71081072018-07-26 10:51:38 -070028#include <amdblocks/agesawrapper.h>
Nico Huber73c11192018-10-06 18:20:47 +020029#include <amdblocks/reset.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060030#include <soc/southbridge.h>
Marc Jones24484842017-05-04 21:17:45 -060031#include <soc/smi.h>
Richard Spiegel376dc822017-12-01 08:24:26 -070032#include <soc/amd_pci_int_defs.h>
Richard Spiegelbec44f22017-11-24 07:41:29 -070033#include <delay.h>
34#include <soc/pci_devs.h>
Marshall Dawson2942db62017-12-14 10:00:27 -070035#include <agesa_headers.h>
Richard Spiegeldbee8ae2018-05-09 17:34:04 -070036#include <soc/nvs.h>
Marshall Dawson2942db62017-12-14 10:00:27 -070037
Richard Spiegel0e0e93c2018-03-13 10:19:51 -070038/*
39 * Table of devices that need their AOAC registers enabled and waited
40 * upon (usually about .55 milliseconds). Instead of individual delays
41 * waiting for each device to become available, a single delay will be
Richard Spiegel6dfbb592018-03-15 15:45:44 -070042 * executed.
Richard Spiegel0e0e93c2018-03-13 10:19:51 -070043 */
44const static struct stoneyridge_aoac aoac_devs[] = {
45 { (FCH_AOAC_D3_CONTROL_UART0 + CONFIG_UART_FOR_CONSOLE * 2),
46 (FCH_AOAC_D3_STATE_UART0 + CONFIG_UART_FOR_CONSOLE * 2) },
47 { FCH_AOAC_D3_CONTROL_AMBA, FCH_AOAC_D3_STATE_AMBA },
48 { FCH_AOAC_D3_CONTROL_I2C0, FCH_AOAC_D3_STATE_I2C0 },
49 { FCH_AOAC_D3_CONTROL_I2C1, FCH_AOAC_D3_STATE_I2C1 },
50 { FCH_AOAC_D3_CONTROL_I2C2, FCH_AOAC_D3_STATE_I2C2 },
51 { FCH_AOAC_D3_CONTROL_I2C3, FCH_AOAC_D3_STATE_I2C3 }
52};
53
Marshall Dawson2942db62017-12-14 10:00:27 -070054static int is_sata_config(void)
55{
Richard Spiegelbdd272a2018-10-16 13:53:05 -070056 return !((SataNativeIde == CONFIG_STONEYRIDGE_SATA_MODE)
57 || (SataLegacyIde == CONFIG_STONEYRIDGE_SATA_MODE));
Marshall Dawson2942db62017-12-14 10:00:27 -070058}
59
Richard Spiegel7ea8e022018-01-16 14:40:10 -070060static inline int sb_sata_enable(void)
61{
62 /* True if IDE or AHCI. */
Richard Spiegelbdd272a2018-10-16 13:53:05 -070063 return (SataNativeIde == CONFIG_STONEYRIDGE_SATA_MODE) ||
64 (SataAhci == CONFIG_STONEYRIDGE_SATA_MODE);
Richard Spiegel7ea8e022018-01-16 14:40:10 -070065}
66
67static inline int sb_ide_enable(void)
68{
69 /* True if IDE or LEGACY IDE. */
Richard Spiegelbdd272a2018-10-16 13:53:05 -070070 return (SataNativeIde == CONFIG_STONEYRIDGE_SATA_MODE) ||
71 (SataLegacyIde == CONFIG_STONEYRIDGE_SATA_MODE);
Richard Spiegel7ea8e022018-01-16 14:40:10 -070072}
73
Marshall Dawson2942db62017-12-14 10:00:27 -070074void SetFchResetParams(FCH_RESET_INTERFACE *params)
75{
Kyösti Mälkkie7377552018-06-21 16:20:55 +030076 const struct device *dev = pcidev_path_on_root(SATA_DEVFN);
Marshall Dawson2942db62017-12-14 10:00:27 -070077 params->Xhci0Enable = IS_ENABLED(CONFIG_STONEYRIDGE_XHCI_ENABLE);
Richard Spiegelbb18b432018-08-03 10:37:28 -070078 if (dev && dev->enabled) {
79 params->SataEnable = sb_sata_enable();
80 params->IdeEnable = sb_ide_enable();
81 } else {
82 params->SataEnable = FALSE;
83 params->IdeEnable = FALSE;
84 }
Marshall Dawson2942db62017-12-14 10:00:27 -070085}
86
87void SetFchEnvParams(FCH_INTERFACE *params)
88{
Kyösti Mälkkie7377552018-06-21 16:20:55 +030089 const struct device *dev = pcidev_path_on_root(SATA_DEVFN);
Marshall Dawson2942db62017-12-14 10:00:27 -070090 params->AzaliaController = AzEnable;
91 params->SataClass = CONFIG_STONEYRIDGE_SATA_MODE;
Richard Spiegelbb18b432018-08-03 10:37:28 -070092 if (dev && dev->enabled) {
93 params->SataEnable = is_sata_config();
94 params->IdeEnable = !params->SataEnable;
95 params->SataIdeMode = (CONFIG_STONEYRIDGE_SATA_MODE ==
96 SataLegacyIde);
97 } else {
98 params->SataEnable = FALSE;
99 params->IdeEnable = FALSE;
100 params->SataIdeMode = FALSE;
101 }
Marshall Dawson2942db62017-12-14 10:00:27 -0700102}
103
104void SetFchMidParams(FCH_INTERFACE *params)
105{
106 SetFchEnvParams(params);
107}
Marc Jones24484842017-05-04 21:17:45 -0600108
Richard Spiegel376dc822017-12-01 08:24:26 -0700109/*
110 * Table of APIC register index and associated IRQ name. Using IDX_XXX_NAME
Jonathan Neuschäfer5268b762018-02-12 12:24:25 +0100111 * provides a visible association with the index, therefore helping
Richard Spiegel376dc822017-12-01 08:24:26 -0700112 * maintainability of table. If a new index/name is defined in
113 * amd_pci_int_defs.h, just add the pair at the end of this table.
114 * Order is not important.
115 */
116const static struct irq_idx_name irq_association[] = {
Richard Spiegele89d4442017-12-08 07:52:42 -0700117 { PIRQ_A, "INTA#" },
118 { PIRQ_B, "INTB#" },
119 { PIRQ_C, "INTC#" },
120 { PIRQ_D, "INTD#" },
121 { PIRQ_E, "INTE#" },
122 { PIRQ_F, "INTF#" },
123 { PIRQ_G, "INTG#" },
124 { PIRQ_H, "INTH#" },
125 { PIRQ_MISC, "Misc" },
126 { PIRQ_MISC0, "Misc0" },
127 { PIRQ_MISC1, "Misc1" },
128 { PIRQ_MISC2, "Misc2" },
Richard Spiegel376dc822017-12-01 08:24:26 -0700129 { PIRQ_SIRQA, "Ser IRQ INTA" },
130 { PIRQ_SIRQB, "Ser IRQ INTB" },
131 { PIRQ_SIRQC, "Ser IRQ INTC" },
132 { PIRQ_SIRQD, "Ser IRQ INTD" },
Richard Spiegele89d4442017-12-08 07:52:42 -0700133 { PIRQ_SCI, "SCI" },
134 { PIRQ_SMBUS, "SMBUS" },
135 { PIRQ_ASF, "ASF" },
136 { PIRQ_HDA, "HDA" },
137 { PIRQ_FC, "FC" },
138 { PIRQ_PMON, "PerMon" },
139 { PIRQ_SD, "SD" },
140 { PIRQ_SDIO, "SDIOt" },
Richard Spiegele89d4442017-12-08 07:52:42 -0700141 { PIRQ_EHCI, "EHCI" },
142 { PIRQ_XHCI, "XHCI" },
143 { PIRQ_SATA, "SATA" },
144 { PIRQ_GPIO, "GPIO" },
145 { PIRQ_I2C0, "I2C0" },
146 { PIRQ_I2C1, "I2C1" },
147 { PIRQ_I2C2, "I2C2" },
148 { PIRQ_I2C3, "I2C3" },
149 { PIRQ_UART0, "UART0" },
150 { PIRQ_UART1, "UART1" },
Richard Spiegel376dc822017-12-01 08:24:26 -0700151};
152
Richard Spiegelebf3aa82017-11-24 07:47:42 -0700153/*
154 * Structure to simplify code obtaining the total of used wide IO
155 * registers and the size assigned to each.
156 */
157static struct wide_io_ioport_and_bits {
158 uint32_t enable;
159 uint16_t port;
160 uint8_t alt;
161} wio_io_en[TOTAL_WIDEIO_PORTS] = {
162 {
163 LPC_WIDEIO0_ENABLE,
164 LPC_WIDEIO_GENERIC_PORT,
165 LPC_ALT_WIDEIO0_ENABLE
166 },
167 {
168 LPC_WIDEIO1_ENABLE,
169 LPC_WIDEIO1_GENERIC_PORT,
170 LPC_ALT_WIDEIO1_ENABLE
171 },
172 {
173 LPC_WIDEIO2_ENABLE,
174 LPC_WIDEIO2_GENERIC_PORT,
175 LPC_ALT_WIDEIO2_ENABLE
176 }
177};
178
Richard Spiegel376dc822017-12-01 08:24:26 -0700179const struct irq_idx_name *sb_get_apic_reg_association(size_t *size)
180{
181 *size = ARRAY_SIZE(irq_association);
182 return irq_association;
183}
184
Richard Spiegelebf3aa82017-11-24 07:47:42 -0700185/**
186 * @brief Find the size of a particular wide IO
187 *
188 * @param index = index of desired wide IO
189 *
190 * @return size of desired wide IO
191 */
192uint16_t sb_wideio_size(int index)
193{
194 uint32_t enable_register;
195 uint16_t size = 0;
196 uint8_t alternate_register;
197
198 if (index >= TOTAL_WIDEIO_PORTS)
199 return size;
200 enable_register = pci_read_config32(SOC_LPC_DEV,
201 LPC_IO_OR_MEM_DECODE_ENABLE);
202 alternate_register = pci_read_config8(SOC_LPC_DEV,
203 LPC_ALT_WIDEIO_RANGE_ENABLE);
204 if (enable_register & wio_io_en[index].enable)
205 size = (alternate_register & wio_io_en[index].alt) ?
206 16 : 512;
207 return size;
208}
209
210/**
211 * @brief Identify if any LPC wide IO is covering the IO range
212 *
213 * @param start = start of IO range
214 * @param size = size of IO range
215 *
216 * @return Index of wide IO covering the range or error
217 */
218int sb_find_wideio_range(uint16_t start, uint16_t size)
219{
Richard Spiegelebf3aa82017-11-24 07:47:42 -0700220 int i, index = WIDEIO_RANGE_ERROR;
221 uint16_t end, current_size, start_wideio, end_wideio;
222
223 end = start + size;
Richard Spiegelebf3aa82017-11-24 07:47:42 -0700224 for (i = 0; i < TOTAL_WIDEIO_PORTS; i++) {
225 current_size = sb_wideio_size(i);
226 if (current_size == 0)
227 continue;
228 start_wideio = pci_read_config16(SOC_LPC_DEV,
229 wio_io_en[i].port);
230 end_wideio = start_wideio + current_size;
231 if ((start >= start_wideio) && (end <= end_wideio)) {
232 index = i;
233 break;
234 }
235 }
236 return index;
237}
238
239/**
240 * @brief Program a LPC wide IO to support an IO range
241 *
242 * @param start = start of range to be routed through wide IO
243 * @param size = size of range to be routed through wide IO
244 *
245 * @return Index of wide IO register used or error
246 */
247int sb_set_wideio_range(uint16_t start, uint16_t size)
248{
249 int i, index = WIDEIO_RANGE_ERROR;
250 uint32_t enable_register;
251 uint8_t alternate_register;
252
253 enable_register = pci_read_config32(SOC_LPC_DEV,
254 LPC_IO_OR_MEM_DECODE_ENABLE);
255 alternate_register = pci_read_config8(SOC_LPC_DEV,
256 LPC_ALT_WIDEIO_RANGE_ENABLE);
257 for (i = 0; i < TOTAL_WIDEIO_PORTS; i++) {
258 if (enable_register & wio_io_en[i].enable)
259 continue;
260 index = i;
261 pci_write_config16(SOC_LPC_DEV, wio_io_en[i].port, start);
262 enable_register |= wio_io_en[i].enable;
263 pci_write_config32(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE,
264 enable_register);
265 if (size <= 16)
266 alternate_register |= wio_io_en[i].alt;
267 else
268 alternate_register &= ~wio_io_en[i].alt;
269 pci_write_config8(SOC_LPC_DEV,
270 LPC_ALT_WIDEIO_RANGE_ENABLE,
271 alternate_register);
272 break;
273 }
274 return index;
275}
276
Garrett Kirkendalla0ff6fc2018-03-06 09:23:47 -0600277static void power_on_aoac_device(int aoac_device_control_register)
Richard Spiegelbec44f22017-11-24 07:41:29 -0700278{
Garrett Kirkendalla0ff6fc2018-03-06 09:23:47 -0600279 uint8_t byte;
280 uint8_t *register_pointer = (uint8_t *)(uintptr_t)AOAC_MMIO_BASE
281 + aoac_device_control_register;
Richard Spiegelbec44f22017-11-24 07:41:29 -0700282
283 /* Power on the UART and AMBA devices */
Garrett Kirkendalla0ff6fc2018-03-06 09:23:47 -0600284 byte = read8(register_pointer);
285 byte |= FCH_AOAC_PWR_ON_DEV;
286 write8(register_pointer, byte);
287}
Richard Spiegelbec44f22017-11-24 07:41:29 -0700288
Garrett Kirkendalla0ff6fc2018-03-06 09:23:47 -0600289static bool is_aoac_device_enabled(int aoac_device_status_register)
290{
291 uint8_t byte;
292 byte = read8((uint8_t *)(uintptr_t)AOAC_MMIO_BASE
293 + aoac_device_status_register);
294 byte &= (FCH_AOAC_PWR_RST_STATE | FCH_AOAC_RST_CLK_OK_STATE);
295 if (byte == (FCH_AOAC_PWR_RST_STATE | FCH_AOAC_RST_CLK_OK_STATE))
296 return true;
297 else
298 return false;
299}
300
Richard Spiegel0e0e93c2018-03-13 10:19:51 -0700301void enable_aoac_devices(void)
Garrett Kirkendalla0ff6fc2018-03-06 09:23:47 -0600302{
303 bool status;
Richard Spiegel0e0e93c2018-03-13 10:19:51 -0700304 int i;
Garrett Kirkendalla0ff6fc2018-03-06 09:23:47 -0600305
Richard Spiegel0e0e93c2018-03-13 10:19:51 -0700306 for (i = 0; i < ARRAY_SIZE(aoac_devs); i++)
307 power_on_aoac_device(aoac_devs[i].enable);
Richard Spiegelbec44f22017-11-24 07:41:29 -0700308
Richard Spiegel0e0e93c2018-03-13 10:19:51 -0700309 /* Wait for AOAC devices to indicate power and clock OK */
310 do {
311 udelay(100);
312 status = true;
313 for (i = 0; i < ARRAY_SIZE(aoac_devs); i++)
314 status &= is_aoac_device_enabled(aoac_devs[i].status);
315 } while (!status);
316}
317
Richard Spiegelbec44f22017-11-24 07:41:29 -0700318void sb_pci_port80(void)
319{
320 u8 byte;
321
322 byte = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH);
323 byte &= ~DECODE_IO_PORT_ENABLE4_H; /* disable lpc port 80 */
324 pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH, byte);
325}
326
327void sb_lpc_port80(void)
328{
329 u8 byte;
330
331 /* Enable LPC controller */
332 outb(PM_LPC_GATING, PM_INDEX);
333 byte = inb(PM_DATA);
334 byte |= PM_LPC_ENABLE;
335 outb(PM_LPC_GATING, PM_INDEX);
336 outb(byte, PM_DATA);
337
338 /* Enable port 80 LPC decode in pci function 3 configuration space. */
339 byte = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH);
340 byte |= DECODE_IO_PORT_ENABLE4_H; /* enable port 80 */
341 pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DEC_EN_HIGH, byte);
342}
343
344void sb_lpc_decode(void)
345{
346 u32 tmp = 0;
347
348 /* Enable I/O decode to LPC bus */
349 tmp = DECODE_ENABLE_PARALLEL_PORT0 | DECODE_ENABLE_PARALLEL_PORT2
350 | DECODE_ENABLE_PARALLEL_PORT4 | DECODE_ENABLE_SERIAL_PORT0
351 | DECODE_ENABLE_SERIAL_PORT1 | DECODE_ENABLE_SERIAL_PORT2
352 | DECODE_ENABLE_SERIAL_PORT3 | DECODE_ENABLE_SERIAL_PORT4
353 | DECODE_ENABLE_SERIAL_PORT5 | DECODE_ENABLE_SERIAL_PORT6
354 | DECODE_ENABLE_SERIAL_PORT7 | DECODE_ENABLE_AUDIO_PORT0
355 | DECODE_ENABLE_AUDIO_PORT1 | DECODE_ENABLE_AUDIO_PORT2
356 | DECODE_ENABLE_AUDIO_PORT3 | DECODE_ENABLE_MSS_PORT2
357 | DECODE_ENABLE_MSS_PORT3 | DECODE_ENABLE_FDC_PORT0
358 | DECODE_ENABLE_FDC_PORT1 | DECODE_ENABLE_GAME_PORT
359 | DECODE_ENABLE_KBC_PORT | DECODE_ENABLE_ACPIUC_PORT
360 | DECODE_ENABLE_ADLIB_PORT;
361
362 pci_write_config32(SOC_LPC_DEV, LPC_IO_PORT_DECODE_ENABLE, tmp);
363}
364
Garrett Kirkendall9858bd22018-03-07 15:38:14 -0600365void sb_acpi_mmio_decode(void)
366{
367 uint8_t byte;
368
369 /* Enable ACPI MMIO range 0xfed80000 - 0xfed81fff */
370 outb(PM_ISA_CONTROL, PM_INDEX);
371 byte = inb(PM_DATA);
372 byte |= MMIO_EN;
373 outb(PM_ISA_CONTROL, PM_INDEX);
374 outb(byte, PM_DATA);
375}
376
Raul E Rangel5b058232018-06-28 16:31:45 -0600377static void sb_enable_cf9_io(void)
378{
379 uint32_t reg = pm_read32(PM_DECODE_EN);
380
381 pm_write32(PM_DECODE_EN, reg | CF9_IO_EN);
382}
383
Raul E Rangel9abc3fe2018-06-28 16:31:45 -0600384static void sb_enable_legacy_io(void)
385{
386 uint32_t reg = pm_read32(PM_DECODE_EN);
387
388 pm_write32(PM_DECODE_EN, reg | LEGACY_IO_EN);
389}
390
Richard Spiegelbec44f22017-11-24 07:41:29 -0700391void sb_clk_output_48Mhz(void)
392{
393 u32 ctrl;
Garrett Kirkendalld2558302018-03-06 09:05:20 -0600394 u32 *misc_clk_cntl_1_ptr = (u32 *)(uintptr_t)(MISC_MMIO_BASE
Richard Spiegel62052212018-10-17 13:32:58 -0700395 + MISC_CLK_CNTL1);
Richard Spiegelbec44f22017-11-24 07:41:29 -0700396
397 /*
398 * Enable the X14M_25M_48M_OSC pin and leaving it at it's default so
399 * 48Mhz will be on ball AP13 (FT3b package)
400 */
Garrett Kirkendalld2558302018-03-06 09:05:20 -0600401 ctrl = read32(misc_clk_cntl_1_ptr);
Richard Spiegelbec44f22017-11-24 07:41:29 -0700402
403 /* clear the OSCOUT1_ClkOutputEnb to enable the 48 Mhz clock */
Garrett Kirkendalld2558302018-03-06 09:05:20 -0600404 ctrl &= ~OSCOUT1_CLK_OUTPUT_ENB;
405 write32(misc_clk_cntl_1_ptr, ctrl);
Richard Spiegelbec44f22017-11-24 07:41:29 -0700406}
407
408static uintptr_t sb_spibase(void)
409{
410 u32 base, enables;
411
412 /* Make sure the base address is predictable */
413 base = pci_read_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER);
Patrick Georgi4fbefc52018-10-23 14:35:37 +0200414 enables = base & SPI_PRESERVE_BITS;
415 base &= ~(SPI_PRESERVE_BITS | SPI_BASE_RESERVED);
Richard Spiegelbec44f22017-11-24 07:41:29 -0700416
417 if (!base) {
418 base = SPI_BASE_ADDRESS;
419 pci_write_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER,
420 base | enables | SPI_ROM_ENABLE);
421 /* PCI_COMMAND_MEMORY is read-only and enabled. */
422 }
423 return (uintptr_t)base;
424}
425
426void sb_set_spi100(u16 norm, u16 fast, u16 alt, u16 tpm)
427{
428 uintptr_t base = sb_spibase();
Richard Spiegel9f25e9d2018-10-29 08:01:53 -0700429 write16((void *)(base + SPI100_SPEED_CONFIG),
Richard Spiegelbec44f22017-11-24 07:41:29 -0700430 (norm << SPI_NORM_SPEED_NEW_SH) |
431 (fast << SPI_FAST_SPEED_NEW_SH) |
432 (alt << SPI_ALT_SPEED_NEW_SH) |
433 (tpm << SPI_TPM_SPEED_NEW_SH));
Richard Spiegel9f25e9d2018-10-29 08:01:53 -0700434 write16((void *)(base + SPI100_ENABLE), SPI_USE_SPI100);
Richard Spiegelbec44f22017-11-24 07:41:29 -0700435}
436
437void sb_disable_4dw_burst(void)
438{
439 uintptr_t base = sb_spibase();
Richard Spiegel9f25e9d2018-10-29 08:01:53 -0700440 write16((void *)(base + SPI100_HOST_PREF_CONFIG),
441 read16((void *)(base + SPI100_HOST_PREF_CONFIG))
Richard Spiegelbec44f22017-11-24 07:41:29 -0700442 & ~SPI_RD4DW_EN_HOST);
443}
444
Richard Spiegelbec44f22017-11-24 07:41:29 -0700445void sb_read_mode(u32 mode)
446{
447 uintptr_t base = sb_spibase();
Richard Spiegel9f25e9d2018-10-29 08:01:53 -0700448 write32((void *)(base + SPI_CNTRL0),
449 (read32((void *)(base + SPI_CNTRL0))
Richard Spiegelbec44f22017-11-24 07:41:29 -0700450 & ~SPI_READ_MODE_MASK) | mode);
451}
452
Garrett Kirkendall65753062018-03-07 16:12:11 -0600453/*
454 * Enable FCH to decode TPM associated Memory and IO regions
455 *
456 * Enable decoding of TPM cycles defined in TPM 1.2 spec
457 * Enable decoding of legacy TPM addresses: IO addresses 0x7f-
458 * 0x7e and 0xef-0xee.
459 * This function should be called if TPM is connected in any way to the FCH and
460 * conforms to the regions decoded.
461 * Absent any other routing configuration the TPM cycles will be claimed by the
462 * LPC bus
463 */
464void sb_tpm_decode(void)
465{
466 u32 value;
467
468 value = pci_read_config32(SOC_LPC_DEV, LPC_TRUSTED_PLATFORM_MODULE);
469 value |= TPM_12_EN | TPM_LEGACY_EN;
470 pci_write_config32(SOC_LPC_DEV, LPC_TRUSTED_PLATFORM_MODULE, value);
471}
472
473/*
474 * Enable FCH to decode TPM associated Memory and IO regions to SPI
475 *
476 * This should be used if TPM is connected to SPI bus.
477 * Assumes SPI address space is already configured via a call to sb_spibase().
478 */
Richard Spiegelbec44f22017-11-24 07:41:29 -0700479void sb_tpm_decode_spi(void)
480{
Garrett Kirkendall65753062018-03-07 16:12:11 -0600481 /* Enable TPM decoding to FCH */
482 sb_tpm_decode();
483
484 /* Route TPM accesses to SPI */
Richard Spiegelbec44f22017-11-24 07:41:29 -0700485 u32 spibase = pci_read_config32(SOC_LPC_DEV,
486 SPIROM_BASE_ADDRESS_REGISTER);
487 pci_write_config32(SOC_LPC_DEV, SPIROM_BASE_ADDRESS_REGISTER, spibase
488 | ROUTE_TPM_2_SPI);
489}
490
491/*
492 * Enable 4MB (LPC) ROM access at 0xFFC00000 - 0xFFFFFFFF.
493 *
494 * Hardware should enable LPC ROM by pin straps. This function does not
495 * handle the theoretically possible PCI ROM, FWH, or SPI ROM configurations.
496 *
497 * The southbridge power-on default is to map 512K ROM space.
498 *
499 */
500void sb_enable_rom(void)
501{
502 u8 reg8;
503
504 /*
505 * Decode variable LPC ROM address ranges 1 and 2.
506 * Bits 3-4 are not defined in any publicly available datasheet
507 */
508 reg8 = pci_read_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE);
509 reg8 |= (1 << 3) | (1 << 4);
510 pci_write_config8(SOC_LPC_DEV, LPC_IO_OR_MEM_DECODE_ENABLE, reg8);
511
512 /*
513 * LPC ROM address range 1:
514 * Enable LPC ROM range mirroring start at 0x000e(0000).
515 */
516 pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE1_START, 0x000e);
517
518 /* Enable LPC ROM range mirroring end at 0x000f(ffff). */
519 pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE1_END, 0x000f);
520
521 /*
522 * LPC ROM address range 2:
523 *
524 * Enable LPC ROM range start at:
525 * 0xfff8(0000): 512KB
526 * 0xfff0(0000): 1MB
527 * 0xffe0(0000): 2MB
528 * 0xffc0(0000): 4MB
529 */
530 pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE2_START, 0x10000
531 - (CONFIG_COREBOOT_ROMSIZE_KB >> 6));
532
533 /* Enable LPC ROM range end at 0xffff(ffff). */
534 pci_write_config16(SOC_LPC_DEV, ROM_ADDRESS_RANGE2_END, 0xffff);
535}
536
Marc Jonescfb16802018-04-20 16:27:41 -0600537static void sb_lpc_early_setup(void)
538{
539 uint32_t dword;
540
541 /* Enable SPI prefetch */
542 dword = pci_read_config32(SOC_LPC_DEV, LPC_ROM_DMA_EC_HOST_CONTROL);
543 dword |= SPI_FROM_HOST_PREFETCH_EN | SPI_FROM_USB_PREFETCH_EN;
544 pci_write_config32(SOC_LPC_DEV, LPC_ROM_DMA_EC_HOST_CONTROL, dword);
545
546 if (IS_ENABLED(CONFIG_STONEYRIDGE_LEGACY_FREE)) {
547 /* Decode SIOs at 2E/2F and 4E/4F */
548 dword = pci_read_config32(SOC_LPC_DEV,
549 LPC_IO_OR_MEM_DECODE_ENABLE);
550 dword |= DECODE_ALTERNATE_SIO_ENABLE | DECODE_SIO_ENABLE;
551 pci_write_config32(SOC_LPC_DEV,
552 LPC_IO_OR_MEM_DECODE_ENABLE, dword);
553 }
554}
555
Raul E Rangel79053412018-08-06 10:40:02 -0600556static void setup_spread_spectrum(int *reboot)
Raul E Rangel6b0fc802018-08-02 15:56:34 -0600557{
558 uint16_t rstcfg = pm_read16(PWR_RESET_CFG);
559
560 rstcfg &= ~TOGGLE_ALL_PWR_GOOD;
561 pm_write16(PWR_RESET_CFG, rstcfg);
562
563 uint32_t cntl1 = misc_read32(MISC_CLK_CNTL1);
564
565 if (cntl1 & CG1PLL_FBDIV_TEST) {
566 printk(BIOS_DEBUG, "Spread spectrum is ready\n");
567 misc_write32(MISC_CGPLL_CONFIG1,
568 misc_read32(MISC_CGPLL_CONFIG1) |
569 CG1PLL_SPREAD_SPECTRUM_ENABLE);
570
571 return;
572 }
573
574 printk(BIOS_DEBUG, "Setting up spread spectrum\n");
575
576 uint32_t cfg6 = misc_read32(MISC_CGPLL_CONFIG6);
577 cfg6 &= ~CG1PLL_LF_MODE_MASK;
Marshall Dawsonecce8472018-10-05 15:41:03 -0600578 cfg6 |= (0x0f8 << CG1PLL_LF_MODE_SHIFT) & CG1PLL_LF_MODE_MASK;
Raul E Rangel6b0fc802018-08-02 15:56:34 -0600579 misc_write32(MISC_CGPLL_CONFIG6, cfg6);
580
581 uint32_t cfg3 = misc_read32(MISC_CGPLL_CONFIG3);
582 cfg3 &= ~CG1PLL_REFDIV_MASK;
583 cfg3 |= (0x003 << CG1PLL_REFDIV_SHIFT) & CG1PLL_REFDIV_MASK;
584 cfg3 &= ~CG1PLL_FBDIV_MASK;
Marshall Dawsonecce8472018-10-05 15:41:03 -0600585 cfg3 |= (0x04b << CG1PLL_FBDIV_SHIFT) & CG1PLL_FBDIV_MASK;
Raul E Rangel6b0fc802018-08-02 15:56:34 -0600586 misc_write32(MISC_CGPLL_CONFIG3, cfg3);
587
588 uint32_t cfg5 = misc_read32(MISC_CGPLL_CONFIG5);
Marshall Dawsonedba21e2018-10-05 19:01:52 -0600589 cfg5 &= ~SS_AMOUNT_NFRAC_SLIP_MASK;
590 cfg5 |= (0x2 << SS_AMOUNT_NFRAC_SLIP_SHIFT) & SS_AMOUNT_NFRAC_SLIP_MASK;
Raul E Rangel6b0fc802018-08-02 15:56:34 -0600591 misc_write32(MISC_CGPLL_CONFIG5, cfg5);
592
593 uint32_t cfg4 = misc_read32(MISC_CGPLL_CONFIG4);
Marshall Dawsonedba21e2018-10-05 19:01:52 -0600594 cfg4 &= ~SS_AMOUNT_DSFRAC_MASK;
595 cfg4 |= (0xd000 << SS_AMOUNT_DSFRAC_SHIFT) & SS_AMOUNT_DSFRAC_MASK;
596 cfg4 &= ~SS_STEP_SIZE_DSFRAC_MASK;
597 cfg4 |= (0x02d5 << SS_STEP_SIZE_DSFRAC_SHIFT)
598 & SS_STEP_SIZE_DSFRAC_MASK;
Raul E Rangel6b0fc802018-08-02 15:56:34 -0600599 misc_write32(MISC_CGPLL_CONFIG4, cfg4);
600
601 rstcfg |= TOGGLE_ALL_PWR_GOOD;
602 pm_write16(PWR_RESET_CFG, rstcfg);
603
604 cntl1 |= CG1PLL_FBDIV_TEST;
605 misc_write32(MISC_CLK_CNTL1, cntl1);
606
Raul E Rangel79053412018-08-06 10:40:02 -0600607 *reboot = 1;
608}
609
610static void setup_misc(int *reboot)
611{
612 /* Undocumented register */
613 uint32_t reg = misc_read32(0x50);
614 if (!(reg & BIT(16))) {
615 reg |= BIT(16);
616
617 misc_write32(0x50, reg);
618 *reboot = 1;
619 }
Raul E Rangel6b0fc802018-08-02 15:56:34 -0600620}
621
Raul E Rangeld820f4b82018-08-13 10:39:03 -0600622/* Before console init */
Richard Spiegelbec44f22017-11-24 07:41:29 -0700623void bootblock_fch_early_init(void)
624{
Raul E Rangel79053412018-08-06 10:40:02 -0600625 int reboot = 0;
626
Richard Spiegelbec44f22017-11-24 07:41:29 -0700627 sb_enable_rom();
628 sb_lpc_port80();
629 sb_lpc_decode();
Marc Jonescfb16802018-04-20 16:27:41 -0600630 sb_lpc_early_setup();
Garrett Kirkendall64294eb2018-03-16 13:00:46 -0500631 sb_spibase();
Marc Jonescfb16802018-04-20 16:27:41 -0600632 sb_disable_4dw_burst(); /* Must be disabled on CZ(ST) */
Garrett Kirkendalle7513e0d2018-03-14 12:01:36 -0500633 sb_acpi_mmio_decode();
Raul E Rangel5b058232018-06-28 16:31:45 -0600634 sb_enable_cf9_io();
Raul E Rangel79053412018-08-06 10:40:02 -0600635 setup_spread_spectrum(&reboot);
636 setup_misc(&reboot);
637
638 if (reboot)
Nico Huber73c11192018-10-06 18:20:47 +0200639 warm_reset();
Raul E Rangel79053412018-08-06 10:40:02 -0600640
Raul E Rangel9abc3fe2018-06-28 16:31:45 -0600641 sb_enable_legacy_io();
Richard Spiegel0e0e93c2018-03-13 10:19:51 -0700642 enable_aoac_devices();
Richard Spiegelbec44f22017-11-24 07:41:29 -0700643}
644
Edward Hillcc680342018-08-10 16:20:02 -0600645static void print_num_status_bits(int num_bits, uint32_t status,
646 const char *const bit_names[])
647{
648 int i;
649
650 if (!status)
651 return;
652
653 for (i = num_bits - 1; i >= 0; i--) {
654 if (status & (1 << i)) {
655 if (bit_names[i])
656 printk(BIOS_DEBUG, "%s ", bit_names[i]);
657 else
658 printk(BIOS_DEBUG, "BIT%d ", i);
659 }
660 }
661}
662
663static void sb_print_pmxc0_status(void)
664{
665 /* PMxC0 S5/Reset Status shows the source of previous reset. */
666 uint32_t pmxc0_status = pm_read32(PM_RST_STATUS);
667
Edward Hill917b4002018-10-02 14:17:19 -0600668 static const char *const pmxc0_status_bits[32] = {
Edward Hillcc680342018-08-10 16:20:02 -0600669 [0] = "ThermalTrip",
670 [1] = "FourSecondPwrBtn",
671 [2] = "Shutdown",
672 [3] = "ThermalTripFromTemp",
673 [4] = "RemotePowerDownFromASF",
674 [5] = "ShutDownFan0",
675 [16] = "UserRst",
676 [17] = "SoftPciRst",
677 [18] = "DoInit",
678 [19] = "DoReset",
679 [20] = "DoFullReset",
680 [21] = "SleepReset",
681 [22] = "KbReset",
682 [23] = "LtReset",
683 [24] = "FailBootRst",
684 [25] = "WatchdogIssueReset",
685 [26] = "RemoteResetFromASF",
686 [27] = "SyncFlood",
687 [28] = "HangReset",
688 [29] = "EcWatchdogRst",
Edward Hillcc680342018-08-10 16:20:02 -0600689 };
690
Edward Hill917b4002018-10-02 14:17:19 -0600691 printk(BIOS_DEBUG, "PMxC0 STATUS: 0x%x ", pmxc0_status);
Edward Hillcc680342018-08-10 16:20:02 -0600692 print_num_status_bits(ARRAY_SIZE(pmxc0_status_bits), pmxc0_status,
693 pmxc0_status_bits);
Edward Hill917b4002018-10-02 14:17:19 -0600694 printk(BIOS_DEBUG, "\n");
Edward Hillcc680342018-08-10 16:20:02 -0600695}
696
Raul E Rangeld820f4b82018-08-13 10:39:03 -0600697/* After console init */
Edward Hillcc680342018-08-10 16:20:02 -0600698void bootblock_fch_init(void)
699{
700 sb_print_pmxc0_status();
701}
Raul E Rangeld820f4b82018-08-13 10:39:03 -0600702
Elyes HAOUASc5ad2672018-12-05 10:58:34 +0100703void sb_enable(struct device *dev)
Marc Jones24484842017-05-04 21:17:45 -0600704{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600705 printk(BIOS_DEBUG, "%s\n", __func__);
Marc Jones24484842017-05-04 21:17:45 -0600706}
707
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600708static void sb_init_acpi_ports(void)
Marc Jones24484842017-05-04 21:17:45 -0600709{
Marshall Dawson91b80412017-09-27 16:44:40 -0600710 u32 reg;
711
Marc Jones24484842017-05-04 21:17:45 -0600712 /* We use some of these ports in SMM regardless of whether or not
713 * ACPI tables are generated. Enable these ports indiscriminately.
714 */
715
716 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
717 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
718 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
719 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
720 /* CpuControl is in \_PR.CP00, 6 bytes */
721 pm_write16(PM_CPU_CTRL, ACPI_CPU_CONTROL);
722
723 if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)) {
Marshall Dawsona05fdcb2017-09-27 15:01:37 -0600724 /* APMC - SMI Command Port */
Marshall Dawsone9b862e2017-09-22 15:14:46 -0600725 pm_write16(PM_ACPI_SMI_CMD, APM_CNT);
Marshall Dawsona05fdcb2017-09-27 15:01:37 -0600726 configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI);
Marshall Dawson91b80412017-09-27 16:44:40 -0600727
728 /* SMI on SlpTyp requires sending SMI before completion
729 * response of the I/O write. The BKDG also specifies
730 * clearing ForceStpClkRetry for SMI trapping.
731 */
732 reg = pm_read32(PM_PCI_CTRL);
733 reg |= FORCE_SLPSTATE_RETRY;
734 reg &= ~FORCE_STPCLK_RETRY;
735 pm_write32(PM_PCI_CTRL, reg);
736
737 /* Disable SlpTyp feature */
738 reg = pm_read8(PM_RST_CTRL1);
739 reg &= ~SLPTYPE_CONTROL_EN;
740 pm_write8(PM_RST_CTRL1, reg);
741
742 configure_smi(SMITYPE_SLP_TYP, SMI_MODE_SMI);
Marc Jones24484842017-05-04 21:17:45 -0600743 } else {
744 pm_write16(PM_ACPI_SMI_CMD, 0);
745 }
746
Marshall Dawson5e2e74f2017-11-10 09:59:56 -0700747 /* Decode ACPI registers and enable standard features */
748 pm_write8(PM_ACPI_CONF, PM_ACPI_DECODE_STD |
749 PM_ACPI_GLOBAL_EN |
750 PM_ACPI_RTC_EN_EN |
751 PM_ACPI_TIMER_EN_EN);
Marc Jones24484842017-05-04 21:17:45 -0600752}
753
Marshall Dawson70f051f2018-03-20 10:27:41 -0600754static uint16_t reset_pm1_status(void)
755{
Richard Spiegele24d7952018-10-26 13:25:01 -0700756 uint16_t pm1_sts = acpi_read16(MMIO_ACPI_PM1_STS);
757 acpi_write16(MMIO_ACPI_PM1_STS, pm1_sts);
Marshall Dawson70f051f2018-03-20 10:27:41 -0600758 return pm1_sts;
759}
760
761static uint16_t print_pm1_status(uint16_t pm1_sts)
762{
Edward Hill917b4002018-10-02 14:17:19 -0600763 static const char *const pm1_sts_bits[16] = {
Marshall Dawson70f051f2018-03-20 10:27:41 -0600764 [0] = "TMROF",
765 [4] = "BMSTATUS",
766 [5] = "GBL",
767 [8] = "PWRBTN",
768 [10] = "RTC",
769 [14] = "PCIEXPWAK",
770 [15] = "WAK",
771 };
772
773 if (!pm1_sts)
774 return 0;
775
Edward Hill917b4002018-10-02 14:17:19 -0600776 printk(BIOS_DEBUG, "PM1_STS: ");
Marshall Dawson70f051f2018-03-20 10:27:41 -0600777 print_num_status_bits(ARRAY_SIZE(pm1_sts_bits), pm1_sts, pm1_sts_bits);
Edward Hill917b4002018-10-02 14:17:19 -0600778 printk(BIOS_DEBUG, "\n");
Marshall Dawson70f051f2018-03-20 10:27:41 -0600779
780 return pm1_sts;
781}
782
783static void sb_log_pm1_status(uint16_t pm1_sts)
784{
785 if (!IS_ENABLED(CONFIG_ELOG))
786 return;
787
Daniel Kurtzb6fdd222018-05-24 15:52:45 -0600788 if (pm1_sts & WAK_STS)
789 elog_add_event_byte(ELOG_TYPE_ACPI_WAKE,
790 acpi_is_wakeup_s3() ? ACPI_S3 : ACPI_S5);
791
Marshall Dawson70f051f2018-03-20 10:27:41 -0600792 if (pm1_sts & PWRBTN_STS)
793 elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN, 0);
794
795 if (pm1_sts & RTC_STS)
796 elog_add_event_wake(ELOG_WAKE_SOURCE_RTC, 0);
797
798 if (pm1_sts & PCIEXPWAK_STS)
799 elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE, 0);
800}
801
Richard Spiegel572f4982018-05-25 15:49:33 -0700802static void sb_save_sws(uint16_t pm1_status)
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700803{
Richard Spiegel35282a02018-06-14 14:57:54 -0700804 struct soc_power_reg *sws;
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700805 uint32_t reg32;
Richard Spiegel35282a02018-06-14 14:57:54 -0700806 uint16_t reg16;
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700807
Richard Spiegel35282a02018-06-14 14:57:54 -0700808 sws = cbmem_add(CBMEM_ID_POWER_STATE, sizeof(struct soc_power_reg));
809 if (sws == NULL)
810 return;
811 sws->pm1_sts = pm1_status;
Richard Spiegele24d7952018-10-26 13:25:01 -0700812 sws->pm1_en = acpi_read16(MMIO_ACPI_PM1_EN);
813 reg32 = acpi_read32(MMIO_ACPI_GPE0_STS);
814 acpi_write32(MMIO_ACPI_GPE0_STS, reg32);
Richard Spiegel35282a02018-06-14 14:57:54 -0700815 sws->gpe0_sts = reg32;
Richard Spiegele24d7952018-10-26 13:25:01 -0700816 sws->gpe0_en = acpi_read32(MMIO_ACPI_GPE0_EN);
817 reg16 = acpi_read16(MMIO_ACPI_PM1_CNT_BLK);
Richard Spiegel35282a02018-06-14 14:57:54 -0700818 reg16 &= SLP_TYP;
819 sws->wake_from = reg16 >> SLP_TYP_SHIFT;
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700820}
821
Marshall Dawson70f051f2018-03-20 10:27:41 -0600822static void sb_clear_pm1_status(void)
823{
824 uint16_t pm1_sts = reset_pm1_status();
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700825
826 sb_save_sws(pm1_sts);
Marshall Dawson70f051f2018-03-20 10:27:41 -0600827 sb_log_pm1_status(pm1_sts);
828 print_pm1_status(pm1_sts);
829}
830
Richard Spiegel572f4982018-05-25 15:49:33 -0700831static int get_index_bit(uint32_t value, uint16_t limit)
832{
833 uint16_t i;
834 uint32_t t;
835
Richard Spiegelef73cb82018-06-19 07:40:18 -0700836 if (limit >= TOTAL_BITS(uint32_t))
Richard Spiegel572f4982018-05-25 15:49:33 -0700837 return -1;
838
839 /* get a mask of valid bits. Ex limit = 3, set bits 0-2 */
840 t = (1 << limit) - 1;
841 if ((value & t) == 0)
842 return -1;
843 t = 1;
844 for (i = 0; i < limit; i++) {
845 if (value & t)
846 break;
847 t <<= 1;
848 }
849 return i;
850}
851
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700852static void set_nvs_sws(void *unused)
853{
Richard Spiegel35282a02018-06-14 14:57:54 -0700854 struct soc_power_reg *sws;
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700855 struct global_nvs_t *gnvs;
Richard Spiegel572f4982018-05-25 15:49:33 -0700856 int index;
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700857
Richard Spiegel35282a02018-06-14 14:57:54 -0700858 sws = cbmem_find(CBMEM_ID_POWER_STATE);
859 if (sws == NULL)
860 return;
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700861 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
862 if (gnvs == NULL)
863 return;
864
Richard Spiegel35282a02018-06-14 14:57:54 -0700865 index = get_index_bit(sws->pm1_sts & sws->pm1_en, PM1_LIMIT);
Richard Spiegel572f4982018-05-25 15:49:33 -0700866 if (index < 0)
867 gnvs->pm1i = ~0ULL;
868 else
869 gnvs->pm1i = index;
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700870
Richard Spiegel35282a02018-06-14 14:57:54 -0700871 index = get_index_bit(sws->gpe0_sts & sws->gpe0_en, GPE0_LIMIT);
Richard Spiegel572f4982018-05-25 15:49:33 -0700872 if (index < 0)
873 gnvs->gpei = ~0ULL;
874 else
875 gnvs->gpei = index;
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700876}
877
878BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, set_nvs_sws, NULL);
879
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600880void southbridge_init(void *chip_info)
Marc Jones24484842017-05-04 21:17:45 -0600881{
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600882 sb_init_acpi_ports();
Marshall Dawson70f051f2018-03-20 10:27:41 -0600883 sb_clear_pm1_status();
Marc Jones24484842017-05-04 21:17:45 -0600884}
885
Marshall Dawson1d9a46b2018-09-26 16:23:41 -0600886static void set_sb_final_nvs(void)
887{
888 uintptr_t amdfw_rom;
889 uintptr_t xhci_fw;
890 uintptr_t fwaddr;
891 size_t fwsize;
Richard Spiegel41baf0c2018-10-22 13:57:18 -0700892 const struct device *sd, *sata;
Marshall Dawson1d9a46b2018-09-26 16:23:41 -0600893
894 struct global_nvs_t *gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
895 if (gnvs == NULL)
896 return;
897
898 gnvs->aoac.ic0e = is_aoac_device_enabled(FCH_AOAC_D3_STATE_I2C0);
899 gnvs->aoac.ic1e = is_aoac_device_enabled(FCH_AOAC_D3_STATE_I2C1);
900 gnvs->aoac.ic2e = is_aoac_device_enabled(FCH_AOAC_D3_STATE_I2C2);
901 gnvs->aoac.ic3e = is_aoac_device_enabled(FCH_AOAC_D3_STATE_I2C3);
902 gnvs->aoac.ut0e = is_aoac_device_enabled(FCH_AOAC_D3_STATE_UART0);
903 gnvs->aoac.ut1e = is_aoac_device_enabled(FCH_AOAC_D3_STATE_UART1);
904 gnvs->aoac.ehce = is_aoac_device_enabled(FCH_AOAC_D3_STATE_USB2);
905 gnvs->aoac.xhce = is_aoac_device_enabled(FCH_AOAC_D3_STATE_USB3);
906 /* Rely on these being in sync with devicetree */
Kyösti Mälkkie7377552018-06-21 16:20:55 +0300907 sd = pcidev_path_on_root(SD_DEVFN);
Marshall Dawson1d9a46b2018-09-26 16:23:41 -0600908 gnvs->aoac.st_e = sd && sd->enabled ? 1 : 0;
Kyösti Mälkkie7377552018-06-21 16:20:55 +0300909 sata = pcidev_path_on_root(SATA_DEVFN);
Marshall Dawson1d9a46b2018-09-26 16:23:41 -0600910 gnvs->aoac.sd_e = sata && sata->enabled ? 1 : 0;
911 gnvs->aoac.espi = 1;
912
913 amdfw_rom = 0x20000 - (0x80000 << CONFIG_AMD_FWM_POSITION_INDEX);
914 xhci_fw = read32((void *)(amdfw_rom + XHCI_FW_SIG_OFFSET));
915
916 fwaddr = 2 + read16((void *)(xhci_fw + XHCI_FW_ADDR_OFFSET
917 + XHCI_FW_BOOTRAM_SIZE));
918 fwsize = read16((void *)(xhci_fw + XHCI_FW_SIZE_OFFSET
919 + XHCI_FW_BOOTRAM_SIZE));
920 gnvs->fw00 = 0;
921 gnvs->fw01 = ((32 * KiB) << 16) + 0;
922 gnvs->fw02 = fwaddr + XHCI_FW_BOOTRAM_SIZE;
923 gnvs->fw03 = fwsize << 16;
924
Marshall Dawson1d9a46b2018-09-26 16:23:41 -0600925 gnvs->eh10 = pci_read_config32(SOC_EHCI1_DEV, PCI_BASE_ADDRESS_0)
926 & ~PCI_BASE_ADDRESS_MEM_ATTR_MASK;
927}
928
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600929void southbridge_final(void *chip_info)
Marc Jones24484842017-05-04 21:17:45 -0600930{
Richard Spiegel6a389142018-03-05 14:28:10 -0700931 uint8_t restored_power = PM_S5_AT_POWER_RECOVERY;
932
Richard Spiegel6a389142018-03-05 14:28:10 -0700933 if (IS_ENABLED(CONFIG_MAINBOARD_POWER_RESTORE))
934 restored_power = PM_RESTORE_S0_IF_PREV_S0;
935 pm_write8(PM_RTC_SHADOW, restored_power);
Marshall Dawson1d9a46b2018-09-26 16:23:41 -0600936
937 set_sb_final_nvs();
Marc Jones24484842017-05-04 21:17:45 -0600938}
Marshall Dawson8a906df2017-06-13 14:19:02 -0600939
940/*
941 * Update the PCI devices with a valid IRQ number
942 * that is set in the mainboard PCI_IRQ structures.
943 */
944static void set_pci_irqs(void *unused)
945{
946 /* Write PCI_INTR regs 0xC00/0xC01 */
947 write_pci_int_table();
948
949 /* Write IRQs for all devicetree enabled devices */
950 write_pci_cfg_irqs();
951}
952
953/*
954 * Hook this function into the PCI state machine
955 * on entry into BS_DEV_ENABLE.
956 */
957BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);