blob: 1b9c0cafa42196d74de418bb5ab13dee06e2bb97 [file] [log] [blame]
Angel Ponsae593872020-04-04 18:50:57 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Martin Roth5c354b92019-04-22 14:55:16 -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>
Martin Roth5c354b92019-04-22 14:55:16 -060012#include <device/pci_ops.h>
13#include <arch/ioapic.h>
Raul E Rangel93b62e62020-01-31 12:53:45 -070014#include <arch/smp/mpspec.h>
Martin Roth5c354b92019-04-22 14:55:16 -060015#include <cpu/x86/smm.h>
16#include <cbmem.h>
17#include <device/device.h>
18#include <device/pci.h>
19#include <amdblocks/acpimmio.h>
20#include <amdblocks/acpi.h>
21#include <soc/acpi.h>
22#include <soc/pci_devs.h>
Marshall Dawson34c30562019-07-16 15:18:00 -060023#include <soc/cpu.h>
Martin Roth5c354b92019-04-22 14:55:16 -060024#include <soc/southbridge.h>
Martin Roth5c354b92019-04-22 14:55:16 -060025#include <soc/nvs.h>
26#include <soc/gpio.h>
27#include <version.h>
Raul E Rangel93b62e62020-01-31 12:53:45 -070028#include "chip.h"
Martin Roth5c354b92019-04-22 14:55:16 -060029
Raul E Rangel94acba82020-05-07 15:12:20 -060030unsigned long acpi_fill_mcfg(unsigned long current)
31{
32
33 current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *)current,
34 CONFIG_MMCONF_BASE_ADDRESS,
35 0,
36 0,
Aaron Durbin4a3a73c2020-06-12 16:44:50 -060037 CONFIG_MMCONF_BUS_NUMBER - 1);
Raul E Rangel94acba82020-05-07 15:12:20 -060038
39 return current;
40}
41
Martin Roth5c354b92019-04-22 14:55:16 -060042unsigned long acpi_fill_madt(unsigned long current)
43{
Raul E Rangel93b62e62020-01-31 12:53:45 -070044 const struct soc_amd_picasso_config *cfg = config_of_soc();
45 unsigned int i;
46 uint8_t irq;
47 uint8_t flags;
48
Martin Roth5c354b92019-04-22 14:55:16 -060049 /* create all subtables for processors */
50 current = acpi_create_madt_lapics(current);
51
52 /* Write Kern IOAPIC, only one */
53 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current,
54 CONFIG_MAX_CPUS, IO_APIC_ADDR, 0);
55
Martin Roth5c354b92019-04-22 14:55:16 -060056 /* 0: mean bus 0--->ISA */
57 /* 0: PIC 0 */
58 /* 2: APIC 2 */
59 /* 5 mean: 0101 --> Edge-triggered, Active high */
60 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
61 current, 0, 0, 2, 0);
Raul E Rangel93b62e62020-01-31 12:53:45 -070062 current += acpi_create_madt_irqoverride(
63 (acpi_madt_irqoverride_t *)current, 0, 9, 9,
64 MP_IRQ_TRIGGER_LEVEL | MP_IRQ_POLARITY_LOW);
65
66 for (i = 0; i < ARRAY_SIZE(cfg->irq_override); ++i) {
67 irq = cfg->irq_override[i].irq;
68 flags = cfg->irq_override[i].flags;
69
70 if (!flags)
71 continue;
72
73 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)current, 0,
74 irq, irq, flags);
75 }
Martin Roth5c354b92019-04-22 14:55:16 -060076
77 /* create all subtables for processors */
78 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current,
79 0xff, 5, 1);
80 /* 1: LINT1 connect to NMI */
81
82 return current;
83}
84
85/*
86 * Reference section 5.2.9 Fixed ACPI Description Table (FADT)
87 * in the ACPI 3.0b specification.
88 */
Kyösti Mälkki61ef71b2020-05-30 18:54:39 +030089void acpi_fill_fadt(acpi_fadt_t *fadt)
Martin Roth5c354b92019-04-22 14:55:16 -060090{
Martin Rotheca8faa2019-12-01 16:49:19 -070091 const struct soc_amd_picasso_config *cfg = config_of_soc();
92
Marshall Dawsonbc4c9032019-06-11 12:18:20 -060093 printk(BIOS_DEBUG, "pm_base: 0x%04x\n", PICASSO_ACPI_IO_BASE);
Martin Roth5c354b92019-04-22 14:55:16 -060094
Martin Roth5c354b92019-04-22 14:55:16 -060095 fadt->sci_int = 9; /* IRQ 09 - ACPI SCI */
96
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +030097 if (permanent_smi_handler()) {
Martin Roth5c354b92019-04-22 14:55:16 -060098 fadt->smi_cmd = APM_CNT;
99 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
100 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
Martin Roth5c354b92019-04-22 14:55:16 -0600101 }
102
103 fadt->pm1a_evt_blk = ACPI_PM_EVT_BLK;
Martin Roth5c354b92019-04-22 14:55:16 -0600104 fadt->pm1a_cnt_blk = ACPI_PM1_CNT_BLK;
Martin Roth5c354b92019-04-22 14:55:16 -0600105 fadt->pm_tmr_blk = ACPI_PM_TMR_BLK;
106 fadt->gpe0_blk = ACPI_GPE0_BLK;
Martin Roth5c354b92019-04-22 14:55:16 -0600107
108 fadt->pm1_evt_len = 4; /* 32 bits */
109 fadt->pm1_cnt_len = 2; /* 16 bits */
Martin Roth5c354b92019-04-22 14:55:16 -0600110 fadt->pm_tmr_len = 4; /* 32 bits */
111 fadt->gpe0_blk_len = 8; /* 64 bits */
Martin Roth5c354b92019-04-22 14:55:16 -0600112
113 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
114 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
Martin Roth5c354b92019-04-22 14:55:16 -0600115 fadt->duty_offset = 1; /* CLK_VAL bits 3:1 */
116 fadt->duty_width = 3; /* CLK_VAL bits 3:1 */
Raul E Rangel041fcf52020-08-12 12:13:35 -0600117 fadt->day_alrm = 0x0d;
118 fadt->mon_alrm = 0;
119 fadt->century = 0x32;
Martin Rotheca8faa2019-12-01 16:49:19 -0700120 fadt->iapc_boot_arch = cfg->fadt_boot_arch; /* legacy free default */
Martin Roth5c354b92019-04-22 14:55:16 -0600121 fadt->res2 = 0; /* reserved, MUST be 0 ACPI 3.0 */
Martin Rotheca8faa2019-12-01 16:49:19 -0700122 fadt->flags |= ACPI_FADT_WBINVD | /* See table 5-34 ACPI 6.3 spec */
123 ACPI_FADT_C1_SUPPORTED |
124 ACPI_FADT_S4_RTC_WAKE |
125 ACPI_FADT_32BIT_TIMER |
126 ACPI_FADT_PCI_EXPRESS_WAKE |
127 ACPI_FADT_PLATFORM_CLOCK |
128 ACPI_FADT_S4_RTC_VALID |
129 ACPI_FADT_REMOTE_POWER_ON;
130 fadt->flags |= cfg->fadt_flags; /* additional board-specific flags */
Martin Roth5c354b92019-04-22 14:55:16 -0600131
Martin Roth5c354b92019-04-22 14:55:16 -0600132 fadt->ARM_boot_arch = 0; /* MUST be 0 ACPI 3.0 */
133 fadt->FADT_MinorVersion = 0; /* MUST be 0 ACPI 3.0 */
134
135 fadt->x_firmware_ctl_l = 0; /* set to 0 if firmware_ctrl is used */
136 fadt->x_firmware_ctl_h = 0;
Martin Roth5c354b92019-04-22 14:55:16 -0600137
138 fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
139 fadt->x_pm1a_evt_blk.bit_width = 32;
140 fadt->x_pm1a_evt_blk.bit_offset = 0;
141 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
142 fadt->x_pm1a_evt_blk.addrl = ACPI_PM_EVT_BLK;
143 fadt->x_pm1a_evt_blk.addrh = 0x0;
144
Martin Roth5c354b92019-04-22 14:55:16 -0600145 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;
Martin Roth5c354b92019-04-22 14:55:16 -0600149 fadt->x_pm1a_cnt_blk.addrl = ACPI_PM1_CNT_BLK;
150 fadt->x_pm1a_cnt_blk.addrh = 0x0;
151
Martin Roth5c354b92019-04-22 14:55:16 -0600152
153 fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO;
154 fadt->x_pm_tmr_blk.bit_width = 32;
155 fadt->x_pm_tmr_blk.bit_offset = 0;
156 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
157 fadt->x_pm_tmr_blk.addrl = ACPI_PM_TMR_BLK;
158 fadt->x_pm_tmr_blk.addrh = 0x0;
159
160
161 fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO;
162 fadt->x_gpe0_blk.bit_width = 64; /* EventStatus + Event Enable */
163 fadt->x_gpe0_blk.bit_offset = 0;
Angel Ponsa23aff32020-06-21 20:47:54 +0200164 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Martin Roth5c354b92019-04-22 14:55:16 -0600165 fadt->x_gpe0_blk.addrl = ACPI_GPE0_BLK;
166 fadt->x_gpe0_blk.addrh = 0x0;
Martin Roth5c354b92019-04-22 14:55:16 -0600167}
168
Furquan Shaikh7536a392020-04-24 21:59:21 -0700169void generate_cpu_entries(const struct device *device)
Martin Roth5c354b92019-04-22 14:55:16 -0600170{
171 int cores, cpu;
172
Marshall Dawson34c30562019-07-16 15:18:00 -0600173 cores = get_cpu_count();
Michał Żygowski9550e972020-03-20 13:56:46 +0100174 printk(BIOS_DEBUG, "ACPI \\_SB report %d core(s)\n", cores);
Martin Roth5c354b92019-04-22 14:55:16 -0600175
Michał Żygowski9550e972020-03-20 13:56:46 +0100176 /* Generate BSP \_SB.P000 */
Martin Roth5c354b92019-04-22 14:55:16 -0600177 acpigen_write_processor(0, ACPI_GPE0_BLK, 6);
178 acpigen_pop_len();
179
Michał Żygowski9550e972020-03-20 13:56:46 +0100180 /* Generate AP \_SB.Pxxx */
Martin Roth5c354b92019-04-22 14:55:16 -0600181 for (cpu = 1; cpu < cores; cpu++) {
182 acpigen_write_processor(cpu, 0, 0);
183 acpigen_pop_len();
184 }
185}
186
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700187unsigned long southbridge_write_acpi_tables(const struct device *device,
Martin Roth5c354b92019-04-22 14:55:16 -0600188 unsigned long current,
189 struct acpi_rsdp *rsdp)
190{
191 return acpi_write_hpet(device, current, rsdp);
192}
193
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300194void acpi_create_gnvs(struct global_nvs *gnvs)
Martin Roth5c354b92019-04-22 14:55:16 -0600195{
196 /* Clear out GNVS. */
197 memset(gnvs, 0, sizeof(*gnvs));
198
199 if (CONFIG(CONSOLE_CBMEM))
200 gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
201
202 if (CONFIG(CHROMEOS)) {
203 /* Initialize Verified Boot data */
204 chromeos_init_chromeos_acpi(&gnvs->chromeos);
205 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
206 }
207
208 /* Set unknown wake source */
209 gnvs->pm1i = ~0ULL;
210 gnvs->gpei = ~0ULL;
211
212 /* CPU core count */
213 gnvs->pcnt = dev_count_cpu();
214}
215
Furquan Shaikh338fd9a2020-04-24 22:57:05 -0700216void southbridge_inject_dsdt(const struct device *device)
Martin Roth5c354b92019-04-22 14:55:16 -0600217{
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300218 struct global_nvs *gnvs;
Martin Roth5c354b92019-04-22 14:55:16 -0600219
220 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
221
222 if (gnvs) {
223 acpi_create_gnvs(gnvs);
224
225 /* Add it to DSDT */
226 acpigen_write_scope("\\");
227 acpigen_write_name_dword("NVSA", (uintptr_t)gnvs);
228 acpigen_pop_len();
229 }
230}
231
232static void acpigen_soc_get_gpio_in_local5(uintptr_t addr)
233{
234 /*
235 * Store (\_SB.GPR2 (addr), Local5)
236 * \_SB.GPR2 is used to read control byte 2 from control register.
237 * / It is defined in gpio_lib.asl.
238 */
239 acpigen_write_store();
240 acpigen_emit_namestring("\\_SB.GPR2");
241 acpigen_write_integer(addr);
242 acpigen_emit_byte(LOCAL5_OP);
243}
244
245static int acpigen_soc_get_gpio_val(unsigned int gpio_num, uint32_t mask)
246{
247 if (gpio_num >= SOC_GPIO_TOTAL_PINS) {
248 printk(BIOS_WARNING, "Warning: Pin %d should be smaller than"
249 " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS);
250 return -1;
251 }
Kyösti Mälkki39bd46f2020-06-18 19:18:21 +0300252 uintptr_t addr = gpio_get_address(gpio_num);
Martin Roth5c354b92019-04-22 14:55:16 -0600253
254 acpigen_soc_get_gpio_in_local5(addr);
255
256 /* If (And (Local5, mask)) */
257 acpigen_write_if_and(LOCAL5_OP, mask);
258
259 /* Store (One, Local0) */
260 acpigen_write_store_ops(ONE_OP, LOCAL0_OP);
261
262 acpigen_pop_len(); /* If */
263
264 /* Else */
265 acpigen_write_else();
266
267 /* Store (Zero, Local0) */
268 acpigen_write_store_ops(ZERO_OP, LOCAL0_OP);
269
270 acpigen_pop_len(); /* Else */
271
272 return 0;
273}
274
275static int acpigen_soc_set_gpio_val(unsigned int gpio_num, uint32_t val)
276{
277 if (gpio_num >= SOC_GPIO_TOTAL_PINS) {
278 printk(BIOS_WARNING, "Warning: Pin %d should be smaller than"
279 " %d\n", gpio_num, SOC_GPIO_TOTAL_PINS);
280 return -1;
281 }
Kyösti Mälkki39bd46f2020-06-18 19:18:21 +0300282 uintptr_t addr = gpio_get_address(gpio_num);
Martin Roth5c354b92019-04-22 14:55:16 -0600283
284 /* Store (0x40, Local0) */
285 acpigen_write_store();
286 acpigen_write_integer(GPIO_PIN_OUT);
287 acpigen_emit_byte(LOCAL0_OP);
288
289 acpigen_soc_get_gpio_in_local5(addr);
290
291 if (val) {
292 /* Or (Local5, GPIO_PIN_OUT, Local5) */
293 acpigen_write_or(LOCAL5_OP, LOCAL0_OP, LOCAL5_OP);
294 } else {
295 /* Not (GPIO_PIN_OUT, Local6) */
296 acpigen_write_not(LOCAL0_OP, LOCAL6_OP);
297
298 /* And (Local5, Local6, Local5) */
299 acpigen_write_and(LOCAL5_OP, LOCAL6_OP, LOCAL5_OP);
300 }
301
302 /*
303 * SB.GPW2 (addr, Local5)
304 * \_SB.GPW2 is used to write control byte in control register
305 * / byte 2. It is defined in gpio_lib.asl.
306 */
307 acpigen_emit_namestring("\\_SB.GPW2");
308 acpigen_write_integer(addr);
309 acpigen_emit_byte(LOCAL5_OP);
310
311 return 0;
312}
313
314int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
315{
316 return acpigen_soc_get_gpio_val(gpio_num, GPIO_PIN_IN);
317}
318
319int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
320{
321 return acpigen_soc_get_gpio_val(gpio_num, GPIO_PIN_OUT);
322}
323
324int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
325{
326 return acpigen_soc_set_gpio_val(gpio_num, 1);
327}
328
329int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
330{
331 return acpigen_soc_set_gpio_val(gpio_num, 0);
332}