blob: b21f034e80185ce4132455aa92c9a818e0e35da1 [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>
10#include <acpi/acpigen.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020011#include <device/pci_ops.h>
Marc Jones5ebc8652017-06-19 23:34:04 -060012#include <arch/ioapic.h>
Marshall Dawsone9b862e2017-09-22 15:14:46 -060013#include <cpu/x86/smm.h>
Marc Jones257db582017-06-18 17:33:30 -060014#include <cbmem.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{
Marc Jones24484842017-05-04 21:17:45 -060062 printk(BIOS_DEBUG, "pm_base: 0x%04x\n", STONEYRIDGE_ACPI_IO_BASE);
63
Kyösti Mälkki4a09b972020-06-02 12:10:57 +030064 fadt->preferred_pm_profile = PM_UNSPECIFIED;
Marc Jonesdfeb1c42017-08-07 19:08:24 -060065 fadt->sci_int = 9; /* IRQ 09 - ACPI SCI */
Marc Jones24484842017-05-04 21:17:45 -060066
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +030067 if (permanent_smi_handler()) {
Marshall Dawsone9b862e2017-09-22 15:14:46 -060068 fadt->smi_cmd = APM_CNT;
69 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
70 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
Marc Jones24484842017-05-04 21:17:45 -060071 }
72
73 fadt->pm1a_evt_blk = ACPI_PM_EVT_BLK;
74 fadt->pm1b_evt_blk = 0x0000;
75 fadt->pm1a_cnt_blk = ACPI_PM1_CNT_BLK;
76 fadt->pm1b_cnt_blk = 0x0000;
77 fadt->pm2_cnt_blk = 0x0000;
78 fadt->pm_tmr_blk = ACPI_PM_TMR_BLK;
79 fadt->gpe0_blk = ACPI_GPE0_BLK;
Marc Jonesdfeb1c42017-08-07 19:08:24 -060080 fadt->gpe1_blk = 0x0000; /* No gpe1 block */
Marc Jones24484842017-05-04 21:17:45 -060081
82 fadt->pm1_evt_len = 4; /* 32 bits */
83 fadt->pm1_cnt_len = 2; /* 16 bits */
84 fadt->pm2_cnt_len = 0;
85 fadt->pm_tmr_len = 4; /* 32 bits */
86 fadt->gpe0_blk_len = 8; /* 64 bits */
87 fadt->gpe1_blk_len = 0;
88 fadt->gpe1_base = 0;
89
90 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
91 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
92 fadt->flush_size = 0; /* set to 0 if WBINVD is 1 in flags */
93 fadt->flush_stride = 0; /* set to 0 if WBINVD is 1 in flags */
94 fadt->duty_offset = 1; /* CLK_VAL bits 3:1 */
95 fadt->duty_width = 3; /* CLK_VAL bits 3:1 */
96 fadt->day_alrm = 0; /* 0x7d these have to be */
97 fadt->mon_alrm = 0; /* 0x7e added to cmos.layout */
98 fadt->century = 0; /* 0x7f to make rtc alarm work */
99 fadt->iapc_boot_arch = FADT_BOOT_ARCH; /* See table 5-10 */
100 fadt->res2 = 0; /* reserved, MUST be 0 ACPI 3.0 */
101 fadt->flags = ACPI_FADT_WBINVD | /* See table 5-10 ACPI 3.0a spec */
102 ACPI_FADT_C1_SUPPORTED |
103 ACPI_FADT_SLEEP_BUTTON |
104 ACPI_FADT_S4_RTC_WAKE |
105 ACPI_FADT_32BIT_TIMER |
106 ACPI_FADT_RESET_REGISTER |
107 ACPI_FADT_PCI_EXPRESS_WAKE |
108 ACPI_FADT_PLATFORM_CLOCK |
109 ACPI_FADT_S4_RTC_VALID |
110 ACPI_FADT_REMOTE_POWER_ON;
111
112 /* Format is from 5.2.3.1: Generic Address Structure */
113 /* reset_reg: see section 4.7.3.6 ACPI 3.0a spec */
114 /* 8 bit write of value 0x06 to 0xCF9 in IO space */
115 fadt->reset_reg.space_id = ACPI_ADDRESS_SPACE_IO;
116 fadt->reset_reg.bit_width = 8;
117 fadt->reset_reg.bit_offset = 0;
118 fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600119 fadt->reset_reg.addrl = SYS_RESET;
Marc Jones24484842017-05-04 21:17:45 -0600120 fadt->reset_reg.addrh = 0x0;
121
122 fadt->reset_value = 6;
123
Elyes HAOUASf5b974e2018-11-10 20:29:08 +0100124 fadt->ARM_boot_arch = 0; /* MUST be 0 ACPI 3.0 */
125 fadt->FADT_MinorVersion = 0; /* MUST be 0 ACPI 3.0 */
Marc Jones24484842017-05-04 21:17:45 -0600126
127 fadt->x_firmware_ctl_l = 0; /* set to 0 if firmware_ctrl is used */
128 fadt->x_firmware_ctl_h = 0;
Marc Jones24484842017-05-04 21:17:45 -0600129
130 fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
131 fadt->x_pm1a_evt_blk.bit_width = 32;
132 fadt->x_pm1a_evt_blk.bit_offset = 0;
133 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
134 fadt->x_pm1a_evt_blk.addrl = ACPI_PM_EVT_BLK;
135 fadt->x_pm1a_evt_blk.addrh = 0x0;
136
137 fadt->x_pm1b_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
138 fadt->x_pm1b_evt_blk.bit_width = 0;
139 fadt->x_pm1b_evt_blk.bit_offset = 0;
140 fadt->x_pm1b_evt_blk.access_size = 0;
141 fadt->x_pm1b_evt_blk.addrl = 0x0;
142 fadt->x_pm1b_evt_blk.addrh = 0x0;
143
144
145 fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
146 fadt->x_pm1a_cnt_blk.bit_width = 16;
147 fadt->x_pm1a_cnt_blk.bit_offset = 0;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100148 fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
Marc Jones24484842017-05-04 21:17:45 -0600149 fadt->x_pm1a_cnt_blk.addrl = ACPI_PM1_CNT_BLK;
150 fadt->x_pm1a_cnt_blk.addrh = 0x0;
151
152 fadt->x_pm1b_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
153 fadt->x_pm1b_cnt_blk.bit_width = 0;
154 fadt->x_pm1b_cnt_blk.bit_offset = 0;
155 fadt->x_pm1b_cnt_blk.access_size = 0;
156 fadt->x_pm1b_cnt_blk.addrl = 0x0;
157 fadt->x_pm1b_cnt_blk.addrh = 0x0;
158
159 /*
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600160 * Note: Under this current AMD C state implementation, this is no
161 * longer used and should not be reported to OS.
Marc Jones24484842017-05-04 21:17:45 -0600162 */
163 fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
164 fadt->x_pm2_cnt_blk.bit_width = 0;
165 fadt->x_pm2_cnt_blk.bit_offset = 0;
166 fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
167 fadt->x_pm2_cnt_blk.addrl = 0;
168 fadt->x_pm2_cnt_blk.addrh = 0x0;
169
170
171 fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO;
172 fadt->x_pm_tmr_blk.bit_width = 32;
173 fadt->x_pm_tmr_blk.bit_offset = 0;
174 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
175 fadt->x_pm_tmr_blk.addrl = ACPI_PM_TMR_BLK;
176 fadt->x_pm_tmr_blk.addrh = 0x0;
177
178
179 fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO;
180 fadt->x_gpe0_blk.bit_width = 64; /* EventStatus + Event Enable */
181 fadt->x_gpe0_blk.bit_offset = 0;
182 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
183 fadt->x_gpe0_blk.addrl = ACPI_GPE0_BLK;
184 fadt->x_gpe0_blk.addrh = 0x0;
185
186
187 fadt->x_gpe1_blk.space_id = ACPI_ADDRESS_SPACE_IO;
188 fadt->x_gpe1_blk.bit_width = 0;
189 fadt->x_gpe1_blk.bit_offset = 0;
190 fadt->x_gpe1_blk.access_size = 0;
191 fadt->x_gpe1_blk.addrl = 0;
192 fadt->x_gpe1_blk.addrh = 0x0;
Marc Jones24484842017-05-04 21:17:45 -0600193}
Marc Jones257db582017-06-18 17:33:30 -0600194
Furquan Shaikh7536a392020-04-24 21:59:21 -0700195void generate_cpu_entries(const struct device *device)
Marc Jones6bfcf662017-08-06 17:42:35 -0600196{
Richard Spiegel3f16a0f2018-08-06 11:06:08 -0700197 int cores, cpu;
Marc Jones6bfcf662017-08-06 17:42:35 -0600198
199 /* Stoney Ridge is single node, just report # of cores */
Patrick Georgi4fbefc52018-10-23 14:35:37 +0200200 cores = pci_read_config32(SOC_NB_DEV, NB_CAPABILITIES2) & CMP_CAP_MASK;
201 cores++; /* number of cores is CmpCap+1 */
Marc Jones6bfcf662017-08-06 17:42:35 -0600202
Michał Żygowski9550e972020-03-20 13:56:46 +0100203 printk(BIOS_DEBUG, "ACPI \\_SB report %d core(s)\n", cores);
Marc Jones6bfcf662017-08-06 17:42:35 -0600204
Michał Żygowski9550e972020-03-20 13:56:46 +0100205 /* Generate BSP \_SB.P000 */
Richard Spiegel3f16a0f2018-08-06 11:06:08 -0700206 acpigen_write_processor(0, ACPI_GPE0_BLK, 6);
Marc Jones6bfcf662017-08-06 17:42:35 -0600207 acpigen_pop_len();
208
Michał Żygowski9550e972020-03-20 13:56:46 +0100209 /* Generate AP \_SB.Pxxx */
Marc Jones6bfcf662017-08-06 17:42:35 -0600210 for (cpu = 1; cpu < cores; cpu++) {
Richard Spiegel3f16a0f2018-08-06 11:06:08 -0700211 acpigen_write_processor(cpu, 0, 0);
Marc Jones6bfcf662017-08-06 17:42:35 -0600212 acpigen_pop_len();
213 }
214}
215
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700216unsigned long southbridge_write_acpi_tables(const struct device *device,
Marc Jones257db582017-06-18 17:33:30 -0600217 unsigned long current,
218 struct acpi_rsdp *rsdp)
219{
220 return acpi_write_hpet(device, current, rsdp);
221}
222
223static void acpi_create_gnvs(struct global_nvs_t *gnvs)
224{
225 /* Clear out GNVS. */
226 memset(gnvs, 0, sizeof(*gnvs));
227
Julius Wernercd49cce2019-03-05 16:53:33 -0800228 if (CONFIG(CONSOLE_CBMEM))
Marc Jones257db582017-06-18 17:33:30 -0600229 gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
230
Julius Wernercd49cce2019-03-05 16:53:33 -0800231 if (CONFIG(CHROMEOS)) {
Marc Jones257db582017-06-18 17:33:30 -0600232 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +0800233 chromeos_init_chromeos_acpi(&gnvs->chromeos);
Marc Jones257db582017-06-18 17:33:30 -0600234 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
235 }
236
237 /* Set unknown wake source */
238 gnvs->pm1i = ~0ULL;
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700239 gnvs->gpei = ~0ULL;
Marc Jones257db582017-06-18 17:33:30 -0600240
241 /* CPU core count */
242 gnvs->pcnt = dev_count_cpu();
243}
244
Furquan Shaikh338fd9a2020-04-24 22:57:05 -0700245void southbridge_inject_dsdt(const struct device *device)
Marc Jones257db582017-06-18 17:33:30 -0600246{
247 struct global_nvs_t *gnvs;
248
249 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
250
251 if (gnvs) {
252 acpi_create_gnvs(gnvs);
Marc Jones257db582017-06-18 17:33:30 -0600253
254 /* Add it to DSDT */
255 acpigen_write_scope("\\");
256 acpigen_write_name_dword("NVSA", (uintptr_t)gnvs);
257 acpigen_pop_len();
258 }
259}
Richard Spiegel93459d62018-05-16 14:08:33 -0700260
261static void acpigen_soc_get_gpio_in_local5(uintptr_t addr)
262{
263 /*
264 * Store (\_SB.GPR2 (addr), Local5)
265 * \_SB.GPR2 is used to read control byte 2 from control register.
266 * / It is defined in gpio_lib.asl.
267 */
268 acpigen_write_store();
269 acpigen_emit_namestring("\\_SB.GPR2");
270 acpigen_write_integer(addr);
271 acpigen_emit_byte(LOCAL5_OP);
272}
273
274static int acpigen_soc_get_gpio_val(unsigned int gpio_num, uint32_t mask)
275{
Marshall Dawson251d3052019-05-02 17:27:57 -0600276 if (gpio_num >= SOC_GPIO_TOTAL_PINS) {
Richard Spiegel93459d62018-05-16 14:08:33 -0700277 printk(BIOS_WARNING, "Warning: Pin %d should be smaller than"
Marshall Dawson251d3052019-05-02 17:27:57 -0600278 " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS);
Richard Spiegel93459d62018-05-16 14:08:33 -0700279 return -1;
280 }
281 uintptr_t addr = (uintptr_t) gpio_get_address(gpio_num);
282
283 acpigen_soc_get_gpio_in_local5(addr);
284
285 /* If (And (Local5, mask)) */
286 acpigen_write_if_and(LOCAL5_OP, mask);
287
288 /* Store (One, Local0) */
289 acpigen_write_store_ops(ONE_OP, LOCAL0_OP);
290
291 acpigen_pop_len(); /* If */
292
293 /* Else */
294 acpigen_write_else();
295
296 /* Store (Zero, Local0) */
297 acpigen_write_store_ops(ZERO_OP, LOCAL0_OP);
298
299 acpigen_pop_len(); /* Else */
300
301 return 0;
302}
303
304static int acpigen_soc_set_gpio_val(unsigned int gpio_num, uint32_t val)
305{
Marshall Dawson251d3052019-05-02 17:27:57 -0600306 if (gpio_num >= SOC_GPIO_TOTAL_PINS) {
Richard Spiegel93459d62018-05-16 14:08:33 -0700307 printk(BIOS_WARNING, "Warning: Pin %d should be smaller than"
Marshall Dawson251d3052019-05-02 17:27:57 -0600308 " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS);
Richard Spiegel93459d62018-05-16 14:08:33 -0700309 return -1;
310 }
311 uintptr_t addr = (uintptr_t) gpio_get_address(gpio_num);
312
Kevin Chiud837e662018-07-03 19:13:34 +0800313 /* Store (0x40, Local0) */
314 acpigen_write_store();
315 acpigen_write_integer(GPIO_PIN_OUT);
316 acpigen_emit_byte(LOCAL0_OP);
317
Richard Spiegel93459d62018-05-16 14:08:33 -0700318 acpigen_soc_get_gpio_in_local5(addr);
319
320 if (val) {
321 /* Or (Local5, GPIO_PIN_OUT, Local5) */
Kevin Chiud837e662018-07-03 19:13:34 +0800322 acpigen_write_or(LOCAL5_OP, LOCAL0_OP, LOCAL5_OP);
Richard Spiegel93459d62018-05-16 14:08:33 -0700323 } else {
324 /* Not (GPIO_PIN_OUT, Local6) */
Kevin Chiud837e662018-07-03 19:13:34 +0800325 acpigen_write_not(LOCAL0_OP, LOCAL6_OP);
Richard Spiegel93459d62018-05-16 14:08:33 -0700326
327 /* And (Local5, Local6, Local5) */
328 acpigen_write_and(LOCAL5_OP, LOCAL6_OP, LOCAL5_OP);
329 }
330
331 /*
332 * SB.GPW2 (addr, Local5)
333 * \_SB.GPW2 is used to write control byte in control register
334 * / byte 2. It is defined in gpio_lib.asl.
335 */
336 acpigen_emit_namestring("\\_SB.GPW2");
337 acpigen_write_integer(addr);
338 acpigen_emit_byte(LOCAL5_OP);
339
340 return 0;
341}
342
343int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
344{
345 return acpigen_soc_get_gpio_val(gpio_num, GPIO_PIN_IN);
346}
347
348int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
349{
350 return acpigen_soc_get_gpio_val(gpio_num, GPIO_PIN_OUT);
351}
352
353int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
354{
355 return acpigen_soc_set_gpio_val(gpio_num, 1);
356}
357
358int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
359{
360 return acpigen_soc_set_gpio_val(gpio_num, 0);
361}