2 * This file is part of the coreboot project.
4 * Copyright (C) 2010-2017 Advanced Micro Devices, Inc.
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.
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.
16 #include <console/console.h>
19 #include <bootstate.h>
20 #include <cpu/x86/smm.h>
21 #include <device/device.h>
22 #include <device/pci.h>
23 #include <device/pci_ids.h>
24 #include <device/pci_ops.h>
27 #include <amdblocks/amd_pci_util.h>
28 #include <amdblocks/agesawrapper.h>
29 #include <soc/southbridge.h>
31 #include <soc/amd_pci_int_defs.h>
33 #include <soc/pci_devs.h>
34 #include <agesa_headers.h>
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
44 const 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
}
54 static int is_sata_config(void)
56 return !((CONFIG_STONEYRIDGE_SATA_MODE
== SataNativeIde
)
57 || (CONFIG_STONEYRIDGE_SATA_MODE
== SataLegacyIde
));
60 static inline int sb_sata_enable(void)
62 /* True if IDE or AHCI. */
63 return (CONFIG_STONEYRIDGE_SATA_MODE
== SataNativeIde
) ||
64 (CONFIG_STONEYRIDGE_SATA_MODE
== SataAhci
);
67 static inline int sb_ide_enable(void)
69 /* True if IDE or LEGACY IDE. */
70 return (CONFIG_STONEYRIDGE_SATA_MODE
== SataNativeIde
) ||
71 (CONFIG_STONEYRIDGE_SATA_MODE
== SataLegacyIde
);
74 void SetFchResetParams(FCH_RESET_INTERFACE
*params
)
76 const struct device
*dev
= dev_find_slot(0, SATA_DEVFN
);
77 params
->Xhci0Enable
= IS_ENABLED(CONFIG_STONEYRIDGE_XHCI_ENABLE
);
78 if (dev
&& dev
->enabled
) {
79 params
->SataEnable
= sb_sata_enable();
80 params
->IdeEnable
= sb_ide_enable();
82 params
->SataEnable
= FALSE
;
83 params
->IdeEnable
= FALSE
;
87 void SetFchEnvParams(FCH_INTERFACE
*params
)
89 const struct device
*dev
= dev_find_slot(0, SATA_DEVFN
);
90 params
->AzaliaController
= AzEnable
;
91 params
->SataClass
= CONFIG_STONEYRIDGE_SATA_MODE
;
92 if (dev
&& dev
->enabled
) {
93 params
->SataEnable
= is_sata_config();
94 params
->IdeEnable
= !params
->SataEnable
;
95 params
->SataIdeMode
= (CONFIG_STONEYRIDGE_SATA_MODE
==
98 params
->SataEnable
= FALSE
;
99 params
->IdeEnable
= FALSE
;
100 params
->SataIdeMode
= FALSE
;
104 void SetFchMidParams(FCH_INTERFACE
*params
)
106 SetFchEnvParams(params
);
110 * Table of APIC register index and associated IRQ name. Using IDX_XXX_NAME
111 * provides a visible association with the index, therefore helping
112 * 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.
116 const static struct irq_idx_name irq_association
[] = {
125 { PIRQ_MISC
, "Misc" },
126 { PIRQ_MISC0
, "Misc0" },
127 { PIRQ_MISC1
, "Misc1" },
128 { PIRQ_MISC2
, "Misc2" },
129 { PIRQ_SIRQA
, "Ser IRQ INTA" },
130 { PIRQ_SIRQB
, "Ser IRQ INTB" },
131 { PIRQ_SIRQC
, "Ser IRQ INTC" },
132 { PIRQ_SIRQD
, "Ser IRQ INTD" },
134 { PIRQ_SMBUS
, "SMBUS" },
138 { PIRQ_PMON
, "PerMon" },
140 { PIRQ_SDIO
, "SDIOt" },
141 { 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" },
154 * Structure to simplify code obtaining the total of used wide IO
155 * registers and the size assigned to each.
157 static struct wide_io_ioport_and_bits
{
161 } wio_io_en
[TOTAL_WIDEIO_PORTS
] = {
164 LPC_WIDEIO_GENERIC_PORT
,
165 LPC_ALT_WIDEIO0_ENABLE
169 LPC_WIDEIO1_GENERIC_PORT
,
170 LPC_ALT_WIDEIO1_ENABLE
174 LPC_WIDEIO2_GENERIC_PORT
,
175 LPC_ALT_WIDEIO2_ENABLE
179 const struct irq_idx_name
*sb_get_apic_reg_association(size_t *size
)
181 *size
= ARRAY_SIZE(irq_association
);
182 return irq_association
;
186 * @brief Find the size of a particular wide IO
188 * @param index = index of desired wide IO
190 * @return size of desired wide IO
192 uint16_t sb_wideio_size(int index
)
194 uint32_t enable_register
;
196 uint8_t alternate_register
;
198 if (index
>= TOTAL_WIDEIO_PORTS
)
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
) ?
211 * @brief Identify if any LPC wide IO is covering the IO range
213 * @param start = start of IO range
214 * @param size = size of IO range
216 * @return Index of wide IO covering the range or error
218 int sb_find_wideio_range(uint16_t start
, uint16_t size
)
220 uint32_t enable_register
;
221 int i
, index
= WIDEIO_RANGE_ERROR
;
222 uint16_t end
, current_size
, start_wideio
, end_wideio
;
225 enable_register
= pci_read_config32(SOC_LPC_DEV
,
226 LPC_IO_OR_MEM_DECODE_ENABLE
);
227 for (i
= 0; i
< TOTAL_WIDEIO_PORTS
; i
++) {
228 current_size
= sb_wideio_size(i
);
229 if (current_size
== 0)
231 start_wideio
= pci_read_config16(SOC_LPC_DEV
,
233 end_wideio
= start_wideio
+ current_size
;
234 if ((start
>= start_wideio
) && (end
<= end_wideio
)) {
243 * @brief Program a LPC wide IO to support an IO range
245 * @param start = start of range to be routed through wide IO
246 * @param size = size of range to be routed through wide IO
248 * @return Index of wide IO register used or error
250 int sb_set_wideio_range(uint16_t start
, uint16_t size
)
252 int i
, index
= WIDEIO_RANGE_ERROR
;
253 uint32_t enable_register
;
254 uint8_t alternate_register
;
256 enable_register
= pci_read_config32(SOC_LPC_DEV
,
257 LPC_IO_OR_MEM_DECODE_ENABLE
);
258 alternate_register
= pci_read_config8(SOC_LPC_DEV
,
259 LPC_ALT_WIDEIO_RANGE_ENABLE
);
260 for (i
= 0; i
< TOTAL_WIDEIO_PORTS
; i
++) {
261 if (enable_register
& wio_io_en
[i
].enable
)
264 pci_write_config16(SOC_LPC_DEV
, wio_io_en
[i
].port
, start
);
265 enable_register
|= wio_io_en
[i
].enable
;
266 pci_write_config32(SOC_LPC_DEV
, LPC_IO_OR_MEM_DECODE_ENABLE
,
269 alternate_register
|= wio_io_en
[i
].alt
;
271 alternate_register
&= ~wio_io_en
[i
].alt
;
272 pci_write_config8(SOC_LPC_DEV
,
273 LPC_ALT_WIDEIO_RANGE_ENABLE
,
280 static void power_on_aoac_device(int aoac_device_control_register
)
283 uint8_t *register_pointer
= (uint8_t *)(uintptr_t)AOAC_MMIO_BASE
284 + aoac_device_control_register
;
286 /* Power on the UART and AMBA devices */
287 byte
= read8(register_pointer
);
288 byte
|= FCH_AOAC_PWR_ON_DEV
;
289 write8(register_pointer
, byte
);
292 static bool is_aoac_device_enabled(int aoac_device_status_register
)
295 byte
= read8((uint8_t *)(uintptr_t)AOAC_MMIO_BASE
296 + aoac_device_status_register
);
297 byte
&= (FCH_AOAC_PWR_RST_STATE
| FCH_AOAC_RST_CLK_OK_STATE
);
298 if (byte
== (FCH_AOAC_PWR_RST_STATE
| FCH_AOAC_RST_CLK_OK_STATE
))
304 void enable_aoac_devices(void)
309 for (i
= 0; i
< ARRAY_SIZE(aoac_devs
); i
++)
310 power_on_aoac_device(aoac_devs
[i
].enable
);
312 /* Wait for AOAC devices to indicate power and clock OK */
316 for (i
= 0; i
< ARRAY_SIZE(aoac_devs
); i
++)
317 status
&= is_aoac_device_enabled(aoac_devs
[i
].status
);
321 void sb_pci_port80(void)
325 byte
= pci_read_config8(SOC_LPC_DEV
, LPC_IO_OR_MEM_DEC_EN_HIGH
);
326 byte
&= ~DECODE_IO_PORT_ENABLE4_H
; /* disable lpc port 80 */
327 pci_write_config8(SOC_LPC_DEV
, LPC_IO_OR_MEM_DEC_EN_HIGH
, byte
);
330 void sb_lpc_port80(void)
334 /* Enable LPC controller */
335 outb(PM_LPC_GATING
, PM_INDEX
);
337 byte
|= PM_LPC_ENABLE
;
338 outb(PM_LPC_GATING
, PM_INDEX
);
341 /* Enable port 80 LPC decode in pci function 3 configuration space. */
342 byte
= pci_read_config8(SOC_LPC_DEV
, LPC_IO_OR_MEM_DEC_EN_HIGH
);
343 byte
|= DECODE_IO_PORT_ENABLE4_H
; /* enable port 80 */
344 pci_write_config8(SOC_LPC_DEV
, LPC_IO_OR_MEM_DEC_EN_HIGH
, byte
);
347 void sb_lpc_decode(void)
351 /* Enable I/O decode to LPC bus */
352 tmp
= DECODE_ENABLE_PARALLEL_PORT0
| DECODE_ENABLE_PARALLEL_PORT2
353 | DECODE_ENABLE_PARALLEL_PORT4
| DECODE_ENABLE_SERIAL_PORT0
354 | DECODE_ENABLE_SERIAL_PORT1
| DECODE_ENABLE_SERIAL_PORT2
355 | DECODE_ENABLE_SERIAL_PORT3
| DECODE_ENABLE_SERIAL_PORT4
356 | DECODE_ENABLE_SERIAL_PORT5
| DECODE_ENABLE_SERIAL_PORT6
357 | DECODE_ENABLE_SERIAL_PORT7
| DECODE_ENABLE_AUDIO_PORT0
358 | DECODE_ENABLE_AUDIO_PORT1
| DECODE_ENABLE_AUDIO_PORT2
359 | DECODE_ENABLE_AUDIO_PORT3
| DECODE_ENABLE_MSS_PORT2
360 | DECODE_ENABLE_MSS_PORT3
| DECODE_ENABLE_FDC_PORT0
361 | DECODE_ENABLE_FDC_PORT1
| DECODE_ENABLE_GAME_PORT
362 | DECODE_ENABLE_KBC_PORT
| DECODE_ENABLE_ACPIUC_PORT
363 | DECODE_ENABLE_ADLIB_PORT
;
365 pci_write_config32(SOC_LPC_DEV
, LPC_IO_PORT_DECODE_ENABLE
, tmp
);
368 void sb_acpi_mmio_decode(void)
372 /* Enable ACPI MMIO range 0xfed80000 - 0xfed81fff */
373 outb(PM_ISA_CONTROL
, PM_INDEX
);
376 outb(PM_ISA_CONTROL
, PM_INDEX
);
380 static void sb_enable_cf9_io(void)
382 uint32_t reg
= pm_read32(PM_DECODE_EN
);
384 pm_write32(PM_DECODE_EN
, reg
| CF9_IO_EN
);
387 static void sb_enable_legacy_io(void)
389 uint32_t reg
= pm_read32(PM_DECODE_EN
);
391 pm_write32(PM_DECODE_EN
, reg
| LEGACY_IO_EN
);
394 void sb_clk_output_48Mhz(void)
397 u32
*misc_clk_cntl_1_ptr
= (u32
*)(uintptr_t)(MISC_MMIO_BASE
398 + MISC_MISC_CLK_CNTL_1
);
401 * Enable the X14M_25M_48M_OSC pin and leaving it at it's default so
402 * 48Mhz will be on ball AP13 (FT3b package)
404 ctrl
= read32(misc_clk_cntl_1_ptr
);
406 /* clear the OSCOUT1_ClkOutputEnb to enable the 48 Mhz clock */
407 ctrl
&= ~OSCOUT1_CLK_OUTPUT_ENB
;
408 write32(misc_clk_cntl_1_ptr
, ctrl
);
411 static uintptr_t sb_spibase(void)
415 /* Make sure the base address is predictable */
416 base
= pci_read_config32(SOC_LPC_DEV
, SPIROM_BASE_ADDRESS_REGISTER
);
417 enables
= base
& 0xf;
421 base
= SPI_BASE_ADDRESS
;
422 pci_write_config32(SOC_LPC_DEV
, SPIROM_BASE_ADDRESS_REGISTER
,
423 base
| enables
| SPI_ROM_ENABLE
);
424 /* PCI_COMMAND_MEMORY is read-only and enabled. */
426 return (uintptr_t)base
;
429 void sb_set_spi100(u16 norm
, u16 fast
, u16 alt
, u16 tpm
)
431 uintptr_t base
= sb_spibase();
432 write16((void *)base
+ SPI100_SPEED_CONFIG
,
433 (norm
<< SPI_NORM_SPEED_NEW_SH
) |
434 (fast
<< SPI_FAST_SPEED_NEW_SH
) |
435 (alt
<< SPI_ALT_SPEED_NEW_SH
) |
436 (tpm
<< SPI_TPM_SPEED_NEW_SH
));
437 write16((void *)base
+ SPI100_ENABLE
, SPI_USE_SPI100
);
440 void sb_disable_4dw_burst(void)
442 uintptr_t base
= sb_spibase();
443 write16((void *)base
+ SPI100_HOST_PREF_CONFIG
,
444 read16((void *)base
+ SPI100_HOST_PREF_CONFIG
)
445 & ~SPI_RD4DW_EN_HOST
);
448 void sb_read_mode(u32 mode
)
450 uintptr_t base
= sb_spibase();
451 write32((void *)base
+ SPI_CNTRL0
,
452 (read32((void *)base
+ SPI_CNTRL0
)
453 & ~SPI_READ_MODE_MASK
) | mode
);
457 * Enable FCH to decode TPM associated Memory and IO regions
459 * Enable decoding of TPM cycles defined in TPM 1.2 spec
460 * Enable decoding of legacy TPM addresses: IO addresses 0x7f-
461 * 0x7e and 0xef-0xee.
462 * This function should be called if TPM is connected in any way to the FCH and
463 * conforms to the regions decoded.
464 * Absent any other routing configuration the TPM cycles will be claimed by the
467 void sb_tpm_decode(void)
471 value
= pci_read_config32(SOC_LPC_DEV
, LPC_TRUSTED_PLATFORM_MODULE
);
472 value
|= TPM_12_EN
| TPM_LEGACY_EN
;
473 pci_write_config32(SOC_LPC_DEV
, LPC_TRUSTED_PLATFORM_MODULE
, value
);
477 * Enable FCH to decode TPM associated Memory and IO regions to SPI
479 * This should be used if TPM is connected to SPI bus.
480 * Assumes SPI address space is already configured via a call to sb_spibase().
482 void sb_tpm_decode_spi(void)
484 /* Enable TPM decoding to FCH */
487 /* Route TPM accesses to SPI */
488 u32 spibase
= pci_read_config32(SOC_LPC_DEV
,
489 SPIROM_BASE_ADDRESS_REGISTER
);
490 pci_write_config32(SOC_LPC_DEV
, SPIROM_BASE_ADDRESS_REGISTER
, spibase
495 * Enable 4MB (LPC) ROM access at 0xFFC00000 - 0xFFFFFFFF.
497 * Hardware should enable LPC ROM by pin straps. This function does not
498 * handle the theoretically possible PCI ROM, FWH, or SPI ROM configurations.
500 * The southbridge power-on default is to map 512K ROM space.
503 void sb_enable_rom(void)
508 * Decode variable LPC ROM address ranges 1 and 2.
509 * Bits 3-4 are not defined in any publicly available datasheet
511 reg8
= pci_read_config8(SOC_LPC_DEV
, LPC_IO_OR_MEM_DECODE_ENABLE
);
512 reg8
|= (1 << 3) | (1 << 4);
513 pci_write_config8(SOC_LPC_DEV
, LPC_IO_OR_MEM_DECODE_ENABLE
, reg8
);
516 * LPC ROM address range 1:
517 * Enable LPC ROM range mirroring start at 0x000e(0000).
519 pci_write_config16(SOC_LPC_DEV
, ROM_ADDRESS_RANGE1_START
, 0x000e);
521 /* Enable LPC ROM range mirroring end at 0x000f(ffff). */
522 pci_write_config16(SOC_LPC_DEV
, ROM_ADDRESS_RANGE1_END
, 0x000f);
525 * LPC ROM address range 2:
527 * Enable LPC ROM range start at:
528 * 0xfff8(0000): 512KB
533 pci_write_config16(SOC_LPC_DEV
, ROM_ADDRESS_RANGE2_START
, 0x10000
534 - (CONFIG_COREBOOT_ROMSIZE_KB
>> 6));
536 /* Enable LPC ROM range end at 0xffff(ffff). */
537 pci_write_config16(SOC_LPC_DEV
, ROM_ADDRESS_RANGE2_END
, 0xffff);
540 static void sb_lpc_early_setup(void)
544 /* Enable SPI prefetch */
545 dword
= pci_read_config32(SOC_LPC_DEV
, LPC_ROM_DMA_EC_HOST_CONTROL
);
546 dword
|= SPI_FROM_HOST_PREFETCH_EN
| SPI_FROM_USB_PREFETCH_EN
;
547 pci_write_config32(SOC_LPC_DEV
, LPC_ROM_DMA_EC_HOST_CONTROL
, dword
);
549 if (IS_ENABLED(CONFIG_STONEYRIDGE_LEGACY_FREE
)) {
550 /* Decode SIOs at 2E/2F and 4E/4F */
551 dword
= pci_read_config32(SOC_LPC_DEV
,
552 LPC_IO_OR_MEM_DECODE_ENABLE
);
553 dword
|= DECODE_ALTERNATE_SIO_ENABLE
| DECODE_SIO_ENABLE
;
554 pci_write_config32(SOC_LPC_DEV
,
555 LPC_IO_OR_MEM_DECODE_ENABLE
, dword
);
559 static void setup_spread_spectrum(void)
561 uint16_t rstcfg
= pm_read16(PWR_RESET_CFG
);
563 rstcfg
&= ~TOGGLE_ALL_PWR_GOOD
;
564 pm_write16(PWR_RESET_CFG
, rstcfg
);
566 uint32_t cntl1
= misc_read32(MISC_CLK_CNTL1
);
568 if (cntl1
& CG1PLL_FBDIV_TEST
) {
569 printk(BIOS_DEBUG
, "Spread spectrum is ready\n");
570 misc_write32(MISC_CGPLL_CONFIG1
,
571 misc_read32(MISC_CGPLL_CONFIG1
) |
572 CG1PLL_SPREAD_SPECTRUM_ENABLE
);
577 printk(BIOS_DEBUG
, "Setting up spread spectrum\n");
579 uint32_t cfg6
= misc_read32(MISC_CGPLL_CONFIG6
);
580 cfg6
&= ~CG1PLL_LF_MODE_MASK
;
581 cfg6
|= (0x0F8 << CG1PLL_LF_MODE_SHIFT
) & CG1PLL_LF_MODE_MASK
;
582 misc_write32(MISC_CGPLL_CONFIG6
, cfg6
);
584 uint32_t cfg3
= misc_read32(MISC_CGPLL_CONFIG3
);
585 cfg3
&= ~CG1PLL_REFDIV_MASK
;
586 cfg3
|= (0x003 << CG1PLL_REFDIV_SHIFT
) & CG1PLL_REFDIV_MASK
;
587 cfg3
&= ~CG1PLL_FBDIV_MASK
;
588 cfg3
|= (0x04B << CG1PLL_FBDIV_SHIFT
) & CG1PLL_FBDIV_MASK
;
589 misc_write32(MISC_CGPLL_CONFIG3
, cfg3
);
591 uint32_t cfg5
= misc_read32(MISC_CGPLL_CONFIG5
);
592 cfg5
&= ~CG1PLL_SS_AMOUNT_NFRAC_SLIP_MASK
;
593 cfg5
|= (0x2 << CG1PLL_SS_AMOUNT_NFRAC_SLIP_SHIFT
) & CG1PLL_SS_AMOUNT_NFRAC_SLIP_MASK
;
594 misc_write32(MISC_CGPLL_CONFIG5
, cfg5
);
596 uint32_t cfg4
= misc_read32(MISC_CGPLL_CONFIG4
);
597 cfg4
&= ~CG1PLL_SS_AMOUNT_DSFRAC_MASK
;
598 cfg4
|= (0xD000 << CG1PLL_SS_AMOUNT_DSFRAC_SHIFT
) & CG1PLL_SS_AMOUNT_DSFRAC_MASK
;
599 cfg4
&= ~CG1PLL_SS_STEP_SIZE_DSFRAC_MASK
;
600 cfg4
|= (0x02D5 << CG1PLL_SS_STEP_SIZE_DSFRAC_SHIFT
) & CG1PLL_SS_STEP_SIZE_DSFRAC_MASK
;
601 misc_write32(MISC_CGPLL_CONFIG4
, cfg4
);
603 rstcfg
|= TOGGLE_ALL_PWR_GOOD
;
604 pm_write16(PWR_RESET_CFG
, rstcfg
);
606 cntl1
|= CG1PLL_FBDIV_TEST
;
607 misc_write32(MISC_CLK_CNTL1
, cntl1
);
612 void bootblock_fch_early_init(void)
617 sb_lpc_early_setup();
619 sb_disable_4dw_burst(); /* Must be disabled on CZ(ST) */
620 sb_acpi_mmio_decode();
622 setup_spread_spectrum();
623 sb_enable_legacy_io();
624 enable_aoac_devices();
627 void sb_enable(device_t dev
)
629 printk(BIOS_DEBUG
, "%s\n", __func__
);
632 static void sb_init_acpi_ports(void)
636 /* We use some of these ports in SMM regardless of whether or not
637 * ACPI tables are generated. Enable these ports indiscriminately.
640 pm_write16(PM_EVT_BLK
, ACPI_PM_EVT_BLK
);
641 pm_write16(PM1_CNT_BLK
, ACPI_PM1_CNT_BLK
);
642 pm_write16(PM_TMR_BLK
, ACPI_PM_TMR_BLK
);
643 pm_write16(PM_GPE0_BLK
, ACPI_GPE0_BLK
);
644 /* CpuControl is in \_PR.CP00, 6 bytes */
645 pm_write16(PM_CPU_CTRL
, ACPI_CPU_CONTROL
);
647 if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER
)) {
648 /* APMC - SMI Command Port */
649 pm_write16(PM_ACPI_SMI_CMD
, APM_CNT
);
650 configure_smi(SMITYPE_SMI_CMD_PORT
, SMI_MODE_SMI
);
652 /* SMI on SlpTyp requires sending SMI before completion
653 * response of the I/O write. The BKDG also specifies
654 * clearing ForceStpClkRetry for SMI trapping.
656 reg
= pm_read32(PM_PCI_CTRL
);
657 reg
|= FORCE_SLPSTATE_RETRY
;
658 reg
&= ~FORCE_STPCLK_RETRY
;
659 pm_write32(PM_PCI_CTRL
, reg
);
661 /* Disable SlpTyp feature */
662 reg
= pm_read8(PM_RST_CTRL1
);
663 reg
&= ~SLPTYPE_CONTROL_EN
;
664 pm_write8(PM_RST_CTRL1
, reg
);
666 configure_smi(SMITYPE_SLP_TYP
, SMI_MODE_SMI
);
668 pm_write16(PM_ACPI_SMI_CMD
, 0);
671 /* Decode ACPI registers and enable standard features */
672 pm_write8(PM_ACPI_CONF
, PM_ACPI_DECODE_STD
|
675 PM_ACPI_TIMER_EN_EN
);
678 static void print_num_status_bits(int num_bits
, uint32_t status
,
679 const char *const bit_names
[])
686 for (i
= num_bits
- 1; i
>= 0; i
--) {
687 if (status
& (1 << i
)) {
689 printk(BIOS_DEBUG
, "%s ", bit_names
[i
]);
691 printk(BIOS_DEBUG
, "BIT%d ", i
);
696 static uint16_t reset_pm1_status(void)
698 uint16_t pm1_sts
= inw(ACPI_PM1_STS
);
699 outw(pm1_sts
, ACPI_PM1_STS
);
703 static uint16_t print_pm1_status(uint16_t pm1_sts
)
705 static const char *const pm1_sts_bits
[] = {
718 printk(BIOS_SPEW
, "PM1_STS: ");
719 print_num_status_bits(ARRAY_SIZE(pm1_sts_bits
), pm1_sts
, pm1_sts_bits
);
720 printk(BIOS_SPEW
, "\n");
725 static void sb_log_pm1_status(uint16_t pm1_sts
)
727 if (!IS_ENABLED(CONFIG_ELOG
))
730 if (pm1_sts
& WAK_STS
)
731 elog_add_event_byte(ELOG_TYPE_ACPI_WAKE
,
732 acpi_is_wakeup_s3() ? ACPI_S3
: ACPI_S5
);
734 if (pm1_sts
& PWRBTN_STS
)
735 elog_add_event_wake(ELOG_WAKE_SOURCE_PWRBTN
, 0);
737 if (pm1_sts
& RTC_STS
)
738 elog_add_event_wake(ELOG_WAKE_SOURCE_RTC
, 0);
740 if (pm1_sts
& PCIEXPWAK_STS
)
741 elog_add_event_wake(ELOG_WAKE_SOURCE_PCIE
, 0);
744 static void sb_save_sws(uint16_t pm1_status
)
746 struct soc_power_reg
*sws
;
750 sws
= cbmem_add(CBMEM_ID_POWER_STATE
, sizeof(struct soc_power_reg
));
753 sws
->pm1_sts
= pm1_status
;
754 sws
->pm1_en
= inw(ACPI_PM1_EN
);
755 reg32
= inl(ACPI_GPE0_STS
);
756 outl(ACPI_GPE0_STS
, reg32
);
757 sws
->gpe0_sts
= reg32
;
758 sws
->gpe0_en
= inl(ACPI_GPE0_EN
);
759 reg16
= inw(ACPI_PM1_CNT_BLK
);
761 sws
->wake_from
= reg16
>> SLP_TYP_SHIFT
;
764 static void sb_clear_pm1_status(void)
766 uint16_t pm1_sts
= reset_pm1_status();
768 sb_save_sws(pm1_sts
);
769 sb_log_pm1_status(pm1_sts
);
770 print_pm1_status(pm1_sts
);
773 static int get_index_bit(uint32_t value
, uint16_t limit
)
778 if (limit
>= TOTAL_BITS(uint32_t))
781 /* get a mask of valid bits. Ex limit = 3, set bits 0-2 */
782 t
= (1 << limit
) - 1;
783 if ((value
& t
) == 0)
786 for (i
= 0; i
< limit
; i
++) {
794 static void set_nvs_sws(void *unused
)
796 struct soc_power_reg
*sws
;
797 struct global_nvs_t
*gnvs
;
800 sws
= cbmem_find(CBMEM_ID_POWER_STATE
);
803 gnvs
= cbmem_find(CBMEM_ID_ACPI_GNVS
);
807 index
= get_index_bit(sws
->pm1_sts
& sws
->pm1_en
, PM1_LIMIT
);
813 index
= get_index_bit(sws
->gpe0_sts
& sws
->gpe0_en
, GPE0_LIMIT
);
820 BOOT_STATE_INIT_ENTRY(BS_OS_RESUME
, BS_ON_ENTRY
, set_nvs_sws
, NULL
);
822 void southbridge_init(void *chip_info
)
824 sb_init_acpi_ports();
825 sb_clear_pm1_status();
828 void southbridge_final(void *chip_info
)
830 uint8_t restored_power
= PM_S5_AT_POWER_RECOVERY
;
832 if (IS_ENABLED(CONFIG_MAINBOARD_POWER_RESTORE
))
833 restored_power
= PM_RESTORE_S0_IF_PREV_S0
;
834 pm_write8(PM_RTC_SHADOW
, restored_power
);
838 * Update the PCI devices with a valid IRQ number
839 * that is set in the mainboard PCI_IRQ structures.
841 static void set_pci_irqs(void *unused
)
843 /* Write PCI_INTR regs 0xC00/0xC01 */
844 write_pci_int_table();
846 /* Write IRQs for all devicetree enabled devices */
847 write_pci_cfg_irqs();
851 * Hook this function into the PCI state machine
852 * on entry into BS_DEV_ENABLE.
854 BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE
, BS_ON_ENTRY
, set_pci_irqs
, NULL
);