blob: 600b064f2db49d007599689c5c4ab446e4341f02 [file] [log] [blame]
Marc Jones24484842017-05-04 21:17:45 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
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>
19#include <arch/acpi.h>
Marshall Dawson8a906df2017-06-13 14:19:02 -060020#include <bootstate.h>
Marshall Dawsone9b862e2017-09-22 15:14:46 -060021#include <cpu/x86/smm.h>
Marc Jones24484842017-05-04 21:17:45 -060022#include <device/device.h>
23#include <device/pci.h>
24#include <device/pci_ids.h>
25#include <device/pci_ops.h>
26#include <cbmem.h>
Marshall Dawson8a906df2017-06-13 14:19:02 -060027#include <amd_pci_util.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060028#include <soc/southbridge.h>
Marc Jones24484842017-05-04 21:17:45 -060029#include <soc/smi.h>
Marc Jones24484842017-05-04 21:17:45 -060030#include <fchec.h>
Marc Jones24484842017-05-04 21:17:45 -060031
32
33int acpi_get_sleep_type(void)
34{
Marshall Dawsonf9592cc2017-11-09 16:55:31 -070035 return acpi_sleep_from_pm1(inw(pm_acpi_pm_cnt_blk()));
Marc Jones24484842017-05-04 21:17:45 -060036}
37
Marc Jonesdfeb1c42017-08-07 19:08:24 -060038void sb_enable(device_t dev)
Marc Jones24484842017-05-04 21:17:45 -060039{
Marc Jonesdfeb1c42017-08-07 19:08:24 -060040 printk(BIOS_DEBUG, "%s\n", __func__);
Marc Jones24484842017-05-04 21:17:45 -060041}
42
Marc Jonesdfeb1c42017-08-07 19:08:24 -060043static void sb_init_acpi_ports(void)
Marc Jones24484842017-05-04 21:17:45 -060044{
Marshall Dawson91b80412017-09-27 16:44:40 -060045 u32 reg;
46
Marc Jones24484842017-05-04 21:17:45 -060047 /* We use some of these ports in SMM regardless of whether or not
48 * ACPI tables are generated. Enable these ports indiscriminately.
49 */
50
51 pm_write16(PM_EVT_BLK, ACPI_PM_EVT_BLK);
52 pm_write16(PM1_CNT_BLK, ACPI_PM1_CNT_BLK);
53 pm_write16(PM_TMR_BLK, ACPI_PM_TMR_BLK);
54 pm_write16(PM_GPE0_BLK, ACPI_GPE0_BLK);
55 /* CpuControl is in \_PR.CP00, 6 bytes */
56 pm_write16(PM_CPU_CTRL, ACPI_CPU_CONTROL);
57
58 if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER)) {
Marshall Dawsona05fdcb2017-09-27 15:01:37 -060059 /* APMC - SMI Command Port */
Marshall Dawsone9b862e2017-09-22 15:14:46 -060060 pm_write16(PM_ACPI_SMI_CMD, APM_CNT);
Marshall Dawsona05fdcb2017-09-27 15:01:37 -060061 configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI);
Marshall Dawson91b80412017-09-27 16:44:40 -060062
63 /* SMI on SlpTyp requires sending SMI before completion
64 * response of the I/O write. The BKDG also specifies
65 * clearing ForceStpClkRetry for SMI trapping.
66 */
67 reg = pm_read32(PM_PCI_CTRL);
68 reg |= FORCE_SLPSTATE_RETRY;
69 reg &= ~FORCE_STPCLK_RETRY;
70 pm_write32(PM_PCI_CTRL, reg);
71
72 /* Disable SlpTyp feature */
73 reg = pm_read8(PM_RST_CTRL1);
74 reg &= ~SLPTYPE_CONTROL_EN;
75 pm_write8(PM_RST_CTRL1, reg);
76
77 configure_smi(SMITYPE_SLP_TYP, SMI_MODE_SMI);
Marc Jones24484842017-05-04 21:17:45 -060078 } else {
79 pm_write16(PM_ACPI_SMI_CMD, 0);
80 }
81
Marshall Dawson5e2e74f2017-11-10 09:59:56 -070082 /* Decode ACPI registers and enable standard features */
83 pm_write8(PM_ACPI_CONF, PM_ACPI_DECODE_STD |
84 PM_ACPI_GLOBAL_EN |
85 PM_ACPI_RTC_EN_EN |
86 PM_ACPI_TIMER_EN_EN);
Marc Jones24484842017-05-04 21:17:45 -060087}
88
Marc Jonesdfeb1c42017-08-07 19:08:24 -060089void southbridge_init(void *chip_info)
Marc Jones24484842017-05-04 21:17:45 -060090{
Marc Jonesdfeb1c42017-08-07 19:08:24 -060091 sb_init_acpi_ports();
Marc Jones24484842017-05-04 21:17:45 -060092}
93
Marc Jonesdfeb1c42017-08-07 19:08:24 -060094void southbridge_final(void *chip_info)
Marc Jones24484842017-05-04 21:17:45 -060095{
Richard Spiegel38f19402017-09-29 11:39:46 -070096 if (IS_ENABLED(CONFIG_STONEYRIDGE_IMC_FWM)) {
97 agesawrapper_fchecfancontrolservice();
98 if (!IS_ENABLED(CONFIG_ACPI_ENABLE_THERMAL_ZONE))
99 enable_imc_thermal_zone();
100 }
Marc Jones24484842017-05-04 21:17:45 -0600101}
Marshall Dawson8a906df2017-06-13 14:19:02 -0600102
103/*
104 * Update the PCI devices with a valid IRQ number
105 * that is set in the mainboard PCI_IRQ structures.
106 */
107static void set_pci_irqs(void *unused)
108{
109 /* Write PCI_INTR regs 0xC00/0xC01 */
110 write_pci_int_table();
111
112 /* Write IRQs for all devicetree enabled devices */
113 write_pci_cfg_irqs();
114}
115
116/*
117 * Hook this function into the PCI state machine
118 * on entry into BS_DEV_ENABLE.
119 */
120BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL);