Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 1 | /* |
| 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 Dawson | 8a906df | 2017-06-13 14:19:02 -0600 | [diff] [blame] | 20 | #include <bootstate.h> |
Marshall Dawson | e9b862e | 2017-09-22 15:14:46 -0600 | [diff] [blame] | 21 | #include <cpu/x86/smm.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 22 | #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 Dawson | 8a906df | 2017-06-13 14:19:02 -0600 | [diff] [blame] | 27 | #include <amd_pci_util.h> |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 28 | #include <soc/southbridge.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 29 | #include <soc/smi.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 30 | #include <fchec.h> |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 31 | |
| 32 | |
| 33 | int acpi_get_sleep_type(void) |
| 34 | { |
Marshall Dawson | f9592cc | 2017-11-09 16:55:31 -0700 | [diff] [blame] | 35 | return acpi_sleep_from_pm1(inw(pm_acpi_pm_cnt_blk())); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 36 | } |
| 37 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 38 | void sb_enable(device_t dev) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 39 | { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 40 | printk(BIOS_DEBUG, "%s\n", __func__); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 41 | } |
| 42 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 43 | static void sb_init_acpi_ports(void) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 44 | { |
Marshall Dawson | 91b8041 | 2017-09-27 16:44:40 -0600 | [diff] [blame^] | 45 | u32 reg; |
| 46 | |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 47 | /* 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 Dawson | a05fdcb | 2017-09-27 15:01:37 -0600 | [diff] [blame] | 59 | /* APMC - SMI Command Port */ |
Marshall Dawson | e9b862e | 2017-09-22 15:14:46 -0600 | [diff] [blame] | 60 | pm_write16(PM_ACPI_SMI_CMD, APM_CNT); |
Marshall Dawson | a05fdcb | 2017-09-27 15:01:37 -0600 | [diff] [blame] | 61 | configure_smi(SMITYPE_SMI_CMD_PORT, SMI_MODE_SMI); |
Marshall Dawson | 91b8041 | 2017-09-27 16:44:40 -0600 | [diff] [blame^] | 62 | |
| 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 Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 78 | } else { |
| 79 | pm_write16(PM_ACPI_SMI_CMD, 0); |
| 80 | } |
| 81 | |
Marshall Dawson | 5e2e74f | 2017-11-10 09:59:56 -0700 | [diff] [blame] | 82 | /* 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 Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 87 | } |
| 88 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 89 | void southbridge_init(void *chip_info) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 90 | { |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 91 | sb_init_acpi_ports(); |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 92 | } |
| 93 | |
Marc Jones | dfeb1c4 | 2017-08-07 19:08:24 -0600 | [diff] [blame] | 94 | void southbridge_final(void *chip_info) |
Marc Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 95 | { |
Richard Spiegel | 38f1940 | 2017-09-29 11:39:46 -0700 | [diff] [blame] | 96 | 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 Jones | 2448484 | 2017-05-04 21:17:45 -0600 | [diff] [blame] | 101 | } |
Marshall Dawson | 8a906df | 2017-06-13 14:19:02 -0600 | [diff] [blame] | 102 | |
| 103 | /* |
| 104 | * Update the PCI devices with a valid IRQ number |
| 105 | * that is set in the mainboard PCI_IRQ structures. |
| 106 | */ |
| 107 | static 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 | */ |
| 120 | BOOT_STATE_INIT_ENTRY(BS_DEV_ENABLE, BS_ON_ENTRY, set_pci_irqs, NULL); |