blob: af3bf1292a1813ea71676ac10c973a95a86bba9b [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
7#include <string.h>
8#include <console/console.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -07009#include <acpi/acpi.h>
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +030010#include <acpi/acpi_gnvs.h>
Furquan Shaikh76cedd22020-05-02 10:24:23 -070011#include <acpi/acpigen.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020012#include <device/pci_ops.h>
Marc Jones5ebc8652017-06-19 23:34:04 -060013#include <arch/ioapic.h>
Marshall Dawsone9b862e2017-09-22 15:14:46 -060014#include <cpu/x86/smm.h>
Marc Jones24484842017-05-04 21:17:45 -060015#include <device/device.h>
Marc Jones6bfcf662017-08-06 17:42:35 -060016#include <device/pci.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>
Marc Jones257db582017-06-18 17:33:30 -060019#include <soc/acpi.h>
Chris Ching6a35fab2017-10-19 11:45:30 -060020#include <soc/pci_devs.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060021#include <soc/southbridge.h>
Patrick Georgi4fbefc52018-10-23 14:35:37 +020022#include <soc/northbridge.h>
Marc Jones257db582017-06-18 17:33:30 -060023#include <soc/nvs.h>
Richard Spiegel93459d62018-05-16 14:08:33 -070024#include <soc/gpio.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 */
30 current = acpi_create_madt_lapics(current);
31
32 /* Write Kern IOAPIC, only one */
33 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current,
34 CONFIG_MAX_CPUS, IO_APIC_ADDR, 0);
35
36 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current,
37 CONFIG_MAX_CPUS+1, IO_APIC2_ADDR, 24);
38
39 /* 0: mean bus 0--->ISA */
40 /* 0: PIC 0 */
41 /* 2: APIC 2 */
42 /* 5 mean: 0101 --> Edge-triggered, Active high */
43 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
44 current, 0, 0, 2, 0);
45 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
Marshall Dawsonecce8472018-10-05 15:41:03 -060046 current, 0, 9, 9, 0xf);
Marc Jones5ebc8652017-06-19 23:34:04 -060047
48 /* create all subtables for processors */
49 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current,
50 0xff, 5, 1);
51 /* 1: LINT1 connect to NMI */
52
53 return current;
54}
55
Marc Jones24484842017-05-04 21:17:45 -060056/*
57 * Reference section 5.2.9 Fixed ACPI Description Table (FADT)
58 * in the ACPI 3.0b specification.
59 */
Kyösti Mälkki61ef71b2020-05-30 18:54:39 +030060void acpi_fill_fadt(acpi_fadt_t *fadt)
Marc Jones24484842017-05-04 21:17:45 -060061{
Felix Held2f8228d2021-02-05 01:03:45 +010062 printk(BIOS_DEBUG, "pm_base: 0x%04x\n", ACPI_IO_BASE);
Marc Jones24484842017-05-04 21:17:45 -060063
Marc Jonesdfeb1c42017-08-07 19:08:24 -060064 fadt->sci_int = 9; /* IRQ 09 - ACPI SCI */
Marc Jones24484842017-05-04 21:17:45 -060065
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +030066 if (permanent_smi_handler()) {
Marshall Dawsone9b862e2017-09-22 15:14:46 -060067 fadt->smi_cmd = APM_CNT;
68 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
69 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
Marc Jones24484842017-05-04 21:17:45 -060070 }
71
72 fadt->pm1a_evt_blk = ACPI_PM_EVT_BLK;
Marc Jones24484842017-05-04 21:17:45 -060073 fadt->pm1a_cnt_blk = ACPI_PM1_CNT_BLK;
Marc Jones24484842017-05-04 21:17:45 -060074 fadt->pm_tmr_blk = ACPI_PM_TMR_BLK;
75 fadt->gpe0_blk = ACPI_GPE0_BLK;
Marc Jones24484842017-05-04 21:17:45 -060076
77 fadt->pm1_evt_len = 4; /* 32 bits */
78 fadt->pm1_cnt_len = 2; /* 16 bits */
Marc Jones24484842017-05-04 21:17:45 -060079 fadt->pm_tmr_len = 4; /* 32 bits */
80 fadt->gpe0_blk_len = 8; /* 64 bits */
Marc Jones24484842017-05-04 21:17:45 -060081
82 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
83 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
Marc Jones24484842017-05-04 21:17:45 -060084 fadt->duty_offset = 1; /* CLK_VAL bits 3:1 */
85 fadt->duty_width = 3; /* CLK_VAL bits 3:1 */
86 fadt->day_alrm = 0; /* 0x7d these have to be */
87 fadt->mon_alrm = 0; /* 0x7e added to cmos.layout */
88 fadt->century = 0; /* 0x7f to make rtc alarm work */
89 fadt->iapc_boot_arch = FADT_BOOT_ARCH; /* See table 5-10 */
90 fadt->res2 = 0; /* reserved, MUST be 0 ACPI 3.0 */
Angel Ponsa208c6c2020-07-13 00:02:34 +020091 fadt->flags |= ACPI_FADT_WBINVD | /* See table 5-10 ACPI 3.0a spec */
Marc Jones24484842017-05-04 21:17:45 -060092 ACPI_FADT_C1_SUPPORTED |
93 ACPI_FADT_SLEEP_BUTTON |
94 ACPI_FADT_S4_RTC_WAKE |
95 ACPI_FADT_32BIT_TIMER |
Marc Jones24484842017-05-04 21:17:45 -060096 ACPI_FADT_PCI_EXPRESS_WAKE |
97 ACPI_FADT_PLATFORM_CLOCK |
98 ACPI_FADT_S4_RTC_VALID |
99 ACPI_FADT_REMOTE_POWER_ON;
100
Elyes HAOUASf5b974e2018-11-10 20:29:08 +0100101 fadt->ARM_boot_arch = 0; /* MUST be 0 ACPI 3.0 */
102 fadt->FADT_MinorVersion = 0; /* MUST be 0 ACPI 3.0 */
Marc Jones24484842017-05-04 21:17:45 -0600103
104 fadt->x_firmware_ctl_l = 0; /* set to 0 if firmware_ctrl is used */
105 fadt->x_firmware_ctl_h = 0;
Marc Jones24484842017-05-04 21:17:45 -0600106
107 fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
108 fadt->x_pm1a_evt_blk.bit_width = 32;
109 fadt->x_pm1a_evt_blk.bit_offset = 0;
110 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
111 fadt->x_pm1a_evt_blk.addrl = ACPI_PM_EVT_BLK;
112 fadt->x_pm1a_evt_blk.addrh = 0x0;
113
Marc Jones24484842017-05-04 21:17:45 -0600114 fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
115 fadt->x_pm1a_cnt_blk.bit_width = 16;
116 fadt->x_pm1a_cnt_blk.bit_offset = 0;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100117 fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
Marc Jones24484842017-05-04 21:17:45 -0600118 fadt->x_pm1a_cnt_blk.addrl = ACPI_PM1_CNT_BLK;
119 fadt->x_pm1a_cnt_blk.addrh = 0x0;
120
Marc Jones24484842017-05-04 21:17:45 -0600121 fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO;
122 fadt->x_pm_tmr_blk.bit_width = 32;
123 fadt->x_pm_tmr_blk.bit_offset = 0;
124 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
125 fadt->x_pm_tmr_blk.addrl = ACPI_PM_TMR_BLK;
126 fadt->x_pm_tmr_blk.addrh = 0x0;
127
Marc Jones24484842017-05-04 21:17:45 -0600128 fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO;
129 fadt->x_gpe0_blk.bit_width = 64; /* EventStatus + Event Enable */
130 fadt->x_gpe0_blk.bit_offset = 0;
Angel Ponsa23aff32020-06-21 20:47:54 +0200131 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Marc Jones24484842017-05-04 21:17:45 -0600132 fadt->x_gpe0_blk.addrl = ACPI_GPE0_BLK;
133 fadt->x_gpe0_blk.addrh = 0x0;
Marc Jones24484842017-05-04 21:17:45 -0600134}
Marc Jones257db582017-06-18 17:33:30 -0600135
Furquan Shaikh7536a392020-04-24 21:59:21 -0700136void generate_cpu_entries(const struct device *device)
Marc Jones6bfcf662017-08-06 17:42:35 -0600137{
Richard Spiegel3f16a0f2018-08-06 11:06:08 -0700138 int cores, cpu;
Marc Jones6bfcf662017-08-06 17:42:35 -0600139
140 /* Stoney Ridge is single node, just report # of cores */
Patrick Georgi4fbefc52018-10-23 14:35:37 +0200141 cores = pci_read_config32(SOC_NB_DEV, NB_CAPABILITIES2) & CMP_CAP_MASK;
142 cores++; /* number of cores is CmpCap+1 */
Marc Jones6bfcf662017-08-06 17:42:35 -0600143
Michał Żygowski9550e972020-03-20 13:56:46 +0100144 printk(BIOS_DEBUG, "ACPI \\_SB report %d core(s)\n", cores);
Marc Jones6bfcf662017-08-06 17:42:35 -0600145
Michał Żygowski9550e972020-03-20 13:56:46 +0100146 /* Generate BSP \_SB.P000 */
Richard Spiegel3f16a0f2018-08-06 11:06:08 -0700147 acpigen_write_processor(0, ACPI_GPE0_BLK, 6);
Marc Jones6bfcf662017-08-06 17:42:35 -0600148 acpigen_pop_len();
149
Michał Żygowski9550e972020-03-20 13:56:46 +0100150 /* Generate AP \_SB.Pxxx */
Marc Jones6bfcf662017-08-06 17:42:35 -0600151 for (cpu = 1; cpu < cores; cpu++) {
Richard Spiegel3f16a0f2018-08-06 11:06:08 -0700152 acpigen_write_processor(cpu, 0, 0);
Marc Jones6bfcf662017-08-06 17:42:35 -0600153 acpigen_pop_len();
154 }
Kyösti Mälkkida321d82021-01-27 20:22:33 +0200155
156 acpigen_write_scope("\\");
157 acpigen_write_name_integer("PCNT", cores);
158 acpigen_pop_len();
Marc Jones6bfcf662017-08-06 17:42:35 -0600159}
160
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700161unsigned long southbridge_write_acpi_tables(const struct device *device,
Marc Jones257db582017-06-18 17:33:30 -0600162 unsigned long current,
163 struct acpi_rsdp *rsdp)
164{
165 return acpi_write_hpet(device, current, rsdp);
166}
167
Kyösti Mälkkie1ff3cd2020-06-29 03:17:05 +0300168void soc_fill_gnvs(struct global_nvs *gnvs)
Marc Jones257db582017-06-18 17:33:30 -0600169{
Marc Jones257db582017-06-18 17:33:30 -0600170 /* Set unknown wake source */
171 gnvs->pm1i = ~0ULL;
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700172 gnvs->gpei = ~0ULL;
Marc Jones257db582017-06-18 17:33:30 -0600173}
174
Richard Spiegel93459d62018-05-16 14:08:33 -0700175static void acpigen_soc_get_gpio_in_local5(uintptr_t addr)
176{
177 /*
178 * Store (\_SB.GPR2 (addr), Local5)
179 * \_SB.GPR2 is used to read control byte 2 from control register.
180 * / It is defined in gpio_lib.asl.
181 */
182 acpigen_write_store();
183 acpigen_emit_namestring("\\_SB.GPR2");
184 acpigen_write_integer(addr);
185 acpigen_emit_byte(LOCAL5_OP);
186}
187
188static int acpigen_soc_get_gpio_val(unsigned int gpio_num, uint32_t mask)
189{
Marshall Dawson251d3052019-05-02 17:27:57 -0600190 if (gpio_num >= SOC_GPIO_TOTAL_PINS) {
Richard Spiegel93459d62018-05-16 14:08:33 -0700191 printk(BIOS_WARNING, "Warning: Pin %d should be smaller than"
Marshall Dawson251d3052019-05-02 17:27:57 -0600192 " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS);
Richard Spiegel93459d62018-05-16 14:08:33 -0700193 return -1;
194 }
Kyösti Mälkki39bd46f2020-06-18 19:18:21 +0300195 uintptr_t addr = gpio_get_address(gpio_num);
Richard Spiegel93459d62018-05-16 14:08:33 -0700196
197 acpigen_soc_get_gpio_in_local5(addr);
198
199 /* If (And (Local5, mask)) */
200 acpigen_write_if_and(LOCAL5_OP, mask);
201
202 /* Store (One, Local0) */
203 acpigen_write_store_ops(ONE_OP, LOCAL0_OP);
204
205 acpigen_pop_len(); /* If */
206
207 /* Else */
208 acpigen_write_else();
209
210 /* Store (Zero, Local0) */
211 acpigen_write_store_ops(ZERO_OP, LOCAL0_OP);
212
213 acpigen_pop_len(); /* Else */
214
215 return 0;
216}
217
218static int acpigen_soc_set_gpio_val(unsigned int gpio_num, uint32_t val)
219{
Marshall Dawson251d3052019-05-02 17:27:57 -0600220 if (gpio_num >= SOC_GPIO_TOTAL_PINS) {
Richard Spiegel93459d62018-05-16 14:08:33 -0700221 printk(BIOS_WARNING, "Warning: Pin %d should be smaller than"
Marshall Dawson251d3052019-05-02 17:27:57 -0600222 " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS);
Richard Spiegel93459d62018-05-16 14:08:33 -0700223 return -1;
224 }
Kyösti Mälkki39bd46f2020-06-18 19:18:21 +0300225 uintptr_t addr = gpio_get_address(gpio_num);
Richard Spiegel93459d62018-05-16 14:08:33 -0700226
Kevin Chiud837e662018-07-03 19:13:34 +0800227 /* Store (0x40, Local0) */
228 acpigen_write_store();
229 acpigen_write_integer(GPIO_PIN_OUT);
230 acpigen_emit_byte(LOCAL0_OP);
231
Richard Spiegel93459d62018-05-16 14:08:33 -0700232 acpigen_soc_get_gpio_in_local5(addr);
233
234 if (val) {
235 /* Or (Local5, GPIO_PIN_OUT, Local5) */
Kevin Chiud837e662018-07-03 19:13:34 +0800236 acpigen_write_or(LOCAL5_OP, LOCAL0_OP, LOCAL5_OP);
Richard Spiegel93459d62018-05-16 14:08:33 -0700237 } else {
238 /* Not (GPIO_PIN_OUT, Local6) */
Kevin Chiud837e662018-07-03 19:13:34 +0800239 acpigen_write_not(LOCAL0_OP, LOCAL6_OP);
Richard Spiegel93459d62018-05-16 14:08:33 -0700240
241 /* And (Local5, Local6, Local5) */
242 acpigen_write_and(LOCAL5_OP, LOCAL6_OP, LOCAL5_OP);
243 }
244
245 /*
246 * SB.GPW2 (addr, Local5)
247 * \_SB.GPW2 is used to write control byte in control register
248 * / byte 2. It is defined in gpio_lib.asl.
249 */
250 acpigen_emit_namestring("\\_SB.GPW2");
251 acpigen_write_integer(addr);
252 acpigen_emit_byte(LOCAL5_OP);
253
254 return 0;
255}
256
257int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
258{
259 return acpigen_soc_get_gpio_val(gpio_num, GPIO_PIN_IN);
260}
261
262int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
263{
264 return acpigen_soc_get_gpio_val(gpio_num, GPIO_PIN_OUT);
265}
266
267int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
268{
269 return acpigen_soc_set_gpio_val(gpio_num, 1);
270}
271
272int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
273{
274 return acpigen_soc_set_gpio_val(gpio_num, 0);
275}