blob: 1a264f5a4f50c76a881bf9b5cf63067abbdd9c20 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Marc Jones24484842017-05-04 21:17:45 -06002
3/*
4 * ACPI - create the Fixed ACPI Description Tables (FADT)
5 */
6
Marc Jones24484842017-05-04 21:17:45 -06007#include <console/console.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07008#include <acpi/acpi.h>
9#include <acpi/acpigen.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020010#include <device/pci_ops.h>
Marc Jones5ebc8652017-06-19 23:34:04 -060011#include <arch/ioapic.h>
Felix Held69a957f2021-06-17 15:48:25 +020012#include <arch/smp/mpspec.h>
Marshall Dawsone9b862e2017-09-22 15:14:46 -060013#include <cpu/x86/smm.h>
Marc Jones24484842017-05-04 21:17:45 -060014#include <device/device.h>
Marc Jones6bfcf662017-08-06 17:42:35 -060015#include <device/pci.h>
Elyes Haouas5e2602a2023-01-14 05:46:25 +010016#include <gpio.h>
Marshall Dawson69486ca2019-05-02 12:03:45 -060017#include <amdblocks/acpimmio.h>
Marshall Dawson4ee83b22019-05-03 11:44:22 -060018#include <amdblocks/acpi.h>
Felix Held15024e02023-02-16 20:34:46 +010019#include <amdblocks/cpu.h>
Felix Held604ffa62021-02-12 00:43:20 +010020#include <amdblocks/ioapic.h>
Marc Jones257db582017-06-18 17:33:30 -060021#include <soc/acpi.h>
Chris Ching6a35fab2017-10-19 11:45:30 -060022#include <soc/pci_devs.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060023#include <soc/southbridge.h>
Patrick Georgi4fbefc52018-10-23 14:35:37 +020024#include <soc/northbridge.h>
Elyes HAOUAS26071aa2019-02-15 08:21:33 +010025#include <version.h>
Marc Jones24484842017-05-04 21:17:45 -060026
Marc Jones5ebc8652017-06-19 23:34:04 -060027unsigned long acpi_fill_madt(unsigned long current)
28{
29 /* create all subtables for processors */
Kyösti Mälkki66b5e1b2022-11-12 21:13:45 +020030 current = acpi_create_madt_lapics_with_nmis(current);
Marc Jones5ebc8652017-06-19 23:34:04 -060031
32 /* Write Kern IOAPIC, only one */
Kyösti Mälkki2e65e9c2021-06-16 11:00:40 +030033 current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC_ADDR);
Marc Jones5ebc8652017-06-19 23:34:04 -060034
Kyösti Mälkki2e65e9c2021-06-16 11:00:40 +030035 current += acpi_create_madt_ioapic_from_hw((acpi_madt_ioapic_t *)current, IO_APIC2_ADDR);
Marc Jones5ebc8652017-06-19 23:34:04 -060036
Felix Held69a957f2021-06-17 15:48:25 +020037 /* PIT is connected to legacy IRQ 0, but IOAPIC GSI 2 */
38 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)current,
39 MP_BUS_ISA, 0, 2,
40 MP_IRQ_TRIGGER_DEFAULT | MP_IRQ_POLARITY_DEFAULT);
41 /* SCI IRQ type override */
42 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)current,
Felix Held1a148752023-02-27 21:07:26 +010043 MP_BUS_ISA, ACPI_SCI_IRQ, ACPI_SCI_IRQ,
Felix Held69a957f2021-06-17 15:48:25 +020044 MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
Marc Jones5ebc8652017-06-19 23:34:04 -060045
Marc Jones5ebc8652017-06-19 23:34:04 -060046 return current;
47}
48
Marc Jones24484842017-05-04 21:17:45 -060049/*
50 * Reference section 5.2.9 Fixed ACPI Description Table (FADT)
51 * in the ACPI 3.0b specification.
52 */
Kyösti Mälkki61ef71b2020-05-30 18:54:39 +030053void acpi_fill_fadt(acpi_fadt_t *fadt)
Marc Jones24484842017-05-04 21:17:45 -060054{
Felix Held2f8228d2021-02-05 01:03:45 +010055 printk(BIOS_DEBUG, "pm_base: 0x%04x\n", ACPI_IO_BASE);
Marc Jones24484842017-05-04 21:17:45 -060056
Felix Held1a148752023-02-27 21:07:26 +010057 fadt->sci_int = ACPI_SCI_IRQ;
Marc Jones24484842017-05-04 21:17:45 -060058
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +030059 if (permanent_smi_handler()) {
Marshall Dawsone9b862e2017-09-22 15:14:46 -060060 fadt->smi_cmd = APM_CNT;
61 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
62 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
Marc Jones24484842017-05-04 21:17:45 -060063 }
64
65 fadt->pm1a_evt_blk = ACPI_PM_EVT_BLK;
Marc Jones24484842017-05-04 21:17:45 -060066 fadt->pm1a_cnt_blk = ACPI_PM1_CNT_BLK;
Marc Jones24484842017-05-04 21:17:45 -060067 fadt->pm_tmr_blk = ACPI_PM_TMR_BLK;
68 fadt->gpe0_blk = ACPI_GPE0_BLK;
Marc Jones24484842017-05-04 21:17:45 -060069
70 fadt->pm1_evt_len = 4; /* 32 bits */
71 fadt->pm1_cnt_len = 2; /* 16 bits */
Marc Jones24484842017-05-04 21:17:45 -060072 fadt->pm_tmr_len = 4; /* 32 bits */
73 fadt->gpe0_blk_len = 8; /* 64 bits */
Marc Jones24484842017-05-04 21:17:45 -060074
Felix Held164c5ed2022-10-18 00:11:48 +020075 fill_fadt_extended_pm_regs(fadt);
76
Felix Held54c80e12023-02-21 17:59:42 +010077 /* p_lvl2_lat and p_lvl3_lat match what the AGESA code does, but those values are
78 overridden by the _CST packages in the PSTATE SSDT. */
Marc Jones24484842017-05-04 21:17:45 -060079 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
80 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
Marc Jones24484842017-05-04 21:17:45 -060081 fadt->duty_offset = 1; /* CLK_VAL bits 3:1 */
82 fadt->duty_width = 3; /* CLK_VAL bits 3:1 */
Felix Held72b92c92021-11-18 20:41:40 +010083 fadt->day_alrm = RTC_DATE_ALARM;
Marc Jones24484842017-05-04 21:17:45 -060084 fadt->iapc_boot_arch = FADT_BOOT_ARCH; /* See table 5-10 */
Angel Ponsa208c6c2020-07-13 00:02:34 +020085 fadt->flags |= ACPI_FADT_WBINVD | /* See table 5-10 ACPI 3.0a spec */
Marc Jones24484842017-05-04 21:17:45 -060086 ACPI_FADT_C1_SUPPORTED |
87 ACPI_FADT_SLEEP_BUTTON |
88 ACPI_FADT_S4_RTC_WAKE |
89 ACPI_FADT_32BIT_TIMER |
Marc Jones24484842017-05-04 21:17:45 -060090 ACPI_FADT_PCI_EXPRESS_WAKE |
91 ACPI_FADT_PLATFORM_CLOCK |
92 ACPI_FADT_S4_RTC_VALID |
93 ACPI_FADT_REMOTE_POWER_ON;
Marc Jones24484842017-05-04 21:17:45 -060094}
Marc Jones257db582017-06-18 17:33:30 -060095
Felix Held3ee74532023-03-07 02:57:54 +010096const acpi_cstate_t cstate_cfg_table[] = {
97 [0] = {
98 .ctype = 1,
99 .latency = 1,
100 .power = 0,
101 },
102 [1] = {
103 .ctype = 2,
104 .latency = 400,
105 .power = 0,
106 },
107};
108
109const acpi_cstate_t *get_cstate_config_data(size_t *size)
110{
111 *size = ARRAY_SIZE(cstate_cfg_table);
112 return cstate_cfg_table;
113}
114
Furquan Shaikh7536a392020-04-24 21:59:21 -0700115void generate_cpu_entries(const struct device *device)
Marc Jones6bfcf662017-08-06 17:42:35 -0600116{
Felix Held15024e02023-02-16 20:34:46 +0100117 int cpu;
118 const int cores = get_cpu_count();
Marc Jones6bfcf662017-08-06 17:42:35 -0600119
Michał Żygowski9550e972020-03-20 13:56:46 +0100120 printk(BIOS_DEBUG, "ACPI \\_SB report %d core(s)\n", cores);
Marc Jones6bfcf662017-08-06 17:42:35 -0600121
Felix Held12ec7902023-01-28 04:23:21 +0100122 /* Generate \_SB.Pxxx */
123 for (cpu = 0; cpu < cores; cpu++) {
124 acpigen_write_processor_device(cpu);
125 acpigen_write_processor_device_end();
Marc Jones6bfcf662017-08-06 17:42:35 -0600126 }
Kyösti Mälkkida321d82021-01-27 20:22:33 +0200127
Felix Held91d006c2022-03-02 15:16:17 +0100128 acpigen_write_processor_package("PPKG", 0, cores);
Marc Jones6bfcf662017-08-06 17:42:35 -0600129}