blob: 227fb7013624266b145c9a12e10739df0b54ec00 [file] [log] [blame]
Marc Jones24484842017-05-04 21:17:45 -06001/*
2 * This file is part of the coreboot project.
3 *
Marc Jones257db582017-06-18 17:33:30 -06004 * Copyright (C) 2012, 2017 Advanced Micro Devices, Inc.
5 * Copyright (C) 2014 Google Inc.
Marc Jones24484842017-05-04 21:17:45 -06006 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 */
16
17/*
18 * ACPI - create the Fixed ACPI Description Tables (FADT)
19 */
20
21#include <string.h>
22#include <console/console.h>
23#include <arch/acpi.h>
Marc Jones257db582017-06-18 17:33:30 -060024#include <arch/acpigen.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020025#include <device/pci_ops.h>
Marc Jones5ebc8652017-06-19 23:34:04 -060026#include <arch/ioapic.h>
Marshall Dawsone9b862e2017-09-22 15:14:46 -060027#include <cpu/x86/smm.h>
Marc Jones257db582017-06-18 17:33:30 -060028#include <cbmem.h>
Marc Jones24484842017-05-04 21:17:45 -060029#include <device/device.h>
Marc Jones6bfcf662017-08-06 17:42:35 -060030#include <device/pci.h>
Marc Jones257db582017-06-18 17:33:30 -060031#include <soc/acpi.h>
Chris Ching6a35fab2017-10-19 11:45:30 -060032#include <soc/pci_devs.h>
Marc Jonesdfeb1c42017-08-07 19:08:24 -060033#include <soc/southbridge.h>
Patrick Georgi4fbefc52018-10-23 14:35:37 +020034#include <soc/northbridge.h>
Marc Jones257db582017-06-18 17:33:30 -060035#include <soc/nvs.h>
Richard Spiegel93459d62018-05-16 14:08:33 -070036#include <soc/gpio.h>
Elyes HAOUAS26071aa2019-02-15 08:21:33 +010037#include <version.h>
Marc Jones24484842017-05-04 21:17:45 -060038
Marc Jones5ebc8652017-06-19 23:34:04 -060039unsigned long acpi_fill_madt(unsigned long current)
40{
41 /* create all subtables for processors */
42 current = acpi_create_madt_lapics(current);
43
44 /* Write Kern IOAPIC, only one */
45 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current,
46 CONFIG_MAX_CPUS, IO_APIC_ADDR, 0);
47
48 current += acpi_create_madt_ioapic((acpi_madt_ioapic_t *)current,
49 CONFIG_MAX_CPUS+1, IO_APIC2_ADDR, 24);
50
51 /* 0: mean bus 0--->ISA */
52 /* 0: PIC 0 */
53 /* 2: APIC 2 */
54 /* 5 mean: 0101 --> Edge-triggered, Active high */
55 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
56 current, 0, 0, 2, 0);
57 current += acpi_create_madt_irqoverride((acpi_madt_irqoverride_t *)
Marshall Dawsonecce8472018-10-05 15:41:03 -060058 current, 0, 9, 9, 0xf);
Marc Jones5ebc8652017-06-19 23:34:04 -060059
60 /* create all subtables for processors */
61 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current,
62 0xff, 5, 1);
63 /* 1: LINT1 connect to NMI */
64
65 return current;
66}
67
Marc Jones24484842017-05-04 21:17:45 -060068/*
69 * Reference section 5.2.9 Fixed ACPI Description Table (FADT)
70 * in the ACPI 3.0b specification.
71 */
Marshall Dawson4e101ad2017-06-15 12:17:38 -060072void acpi_create_fadt(acpi_fadt_t *fadt, acpi_facs_t *facs, void *dsdt)
Marc Jones24484842017-05-04 21:17:45 -060073{
74 acpi_header_t *header = &(fadt->header);
75
76 printk(BIOS_DEBUG, "pm_base: 0x%04x\n", STONEYRIDGE_ACPI_IO_BASE);
77
78 /* Prepare the header */
79 memset((void *)fadt, 0, sizeof(acpi_fadt_t));
80 memcpy(header->signature, "FACP", 4);
81 header->length = sizeof(acpi_fadt_t);
Marc Jonesf9ea7ed2018-08-22 18:59:26 -060082 header->revision = get_acpi_table_revision(FADT);
Marc Jones24484842017-05-04 21:17:45 -060083 memcpy(header->oem_id, OEM_ID, 6);
84 memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
85 memcpy(header->asl_compiler_id, ASLC, 4);
Elyes HAOUAS26071aa2019-02-15 08:21:33 +010086 header->asl_compiler_revision = asl_revision;
Marc Jones24484842017-05-04 21:17:45 -060087
88 fadt->firmware_ctrl = (u32) facs;
89 fadt->dsdt = (u32) dsdt;
Elyes HAOUAS0d4de2a2019-02-28 13:04:29 +010090 fadt->reserved = 0; /* reserved, should be 0 ACPI 3.0 */
Marc Jones24484842017-05-04 21:17:45 -060091 fadt->preferred_pm_profile = FADT_PM_PROFILE;
Marc Jonesdfeb1c42017-08-07 19:08:24 -060092 fadt->sci_int = 9; /* IRQ 09 - ACPI SCI */
Marc Jones24484842017-05-04 21:17:45 -060093
Julius Wernercd49cce2019-03-05 16:53:33 -080094 if (CONFIG(HAVE_SMI_HANDLER)) {
Marshall Dawsone9b862e2017-09-22 15:14:46 -060095 fadt->smi_cmd = APM_CNT;
96 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
97 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
Marc Jones24484842017-05-04 21:17:45 -060098 fadt->s4bios_req = 0; /* Not supported */
99 fadt->pstate_cnt = 0; /* Not supported */
100 fadt->cst_cnt = 0; /* Not supported */
Richard Spiegele24d7952018-10-26 13:25:01 -0700101 acpi_write32(MMIO_ACPI_PM1_CNT_BLK, 0); /* clear SCI_EN */
Marc Jones24484842017-05-04 21:17:45 -0600102 } else {
103 fadt->smi_cmd = 0; /* disable system management mode */
104 fadt->acpi_enable = 0; /* unused if SMI_CMD = 0 */
105 fadt->acpi_disable = 0; /* unused if SMI_CMD = 0 */
106 fadt->s4bios_req = 0; /* unused if SMI_CMD = 0 */
107 fadt->pstate_cnt = 0; /* unused if SMI_CMD = 0 */
108 fadt->cst_cnt = 0x00; /* unused if SMI_CMD = 0 */
Richard Spiegele24d7952018-10-26 13:25:01 -0700109 acpi_write32(MMIO_ACPI_PM1_CNT_BLK, 1); /* set SCI_EN */
Marc Jones24484842017-05-04 21:17:45 -0600110 }
111
112 fadt->pm1a_evt_blk = ACPI_PM_EVT_BLK;
113 fadt->pm1b_evt_blk = 0x0000;
114 fadt->pm1a_cnt_blk = ACPI_PM1_CNT_BLK;
115 fadt->pm1b_cnt_blk = 0x0000;
116 fadt->pm2_cnt_blk = 0x0000;
117 fadt->pm_tmr_blk = ACPI_PM_TMR_BLK;
118 fadt->gpe0_blk = ACPI_GPE0_BLK;
Marc Jonesdfeb1c42017-08-07 19:08:24 -0600119 fadt->gpe1_blk = 0x0000; /* No gpe1 block */
Marc Jones24484842017-05-04 21:17:45 -0600120
121 fadt->pm1_evt_len = 4; /* 32 bits */
122 fadt->pm1_cnt_len = 2; /* 16 bits */
123 fadt->pm2_cnt_len = 0;
124 fadt->pm_tmr_len = 4; /* 32 bits */
125 fadt->gpe0_blk_len = 8; /* 64 bits */
126 fadt->gpe1_blk_len = 0;
127 fadt->gpe1_base = 0;
128
129 fadt->p_lvl2_lat = ACPI_FADT_C2_NOT_SUPPORTED;
130 fadt->p_lvl3_lat = ACPI_FADT_C3_NOT_SUPPORTED;
131 fadt->flush_size = 0; /* set to 0 if WBINVD is 1 in flags */
132 fadt->flush_stride = 0; /* set to 0 if WBINVD is 1 in flags */
133 fadt->duty_offset = 1; /* CLK_VAL bits 3:1 */
134 fadt->duty_width = 3; /* CLK_VAL bits 3:1 */
135 fadt->day_alrm = 0; /* 0x7d these have to be */
136 fadt->mon_alrm = 0; /* 0x7e added to cmos.layout */
137 fadt->century = 0; /* 0x7f to make rtc alarm work */
138 fadt->iapc_boot_arch = FADT_BOOT_ARCH; /* See table 5-10 */
139 fadt->res2 = 0; /* reserved, MUST be 0 ACPI 3.0 */
140 fadt->flags = ACPI_FADT_WBINVD | /* See table 5-10 ACPI 3.0a spec */
141 ACPI_FADT_C1_SUPPORTED |
142 ACPI_FADT_SLEEP_BUTTON |
143 ACPI_FADT_S4_RTC_WAKE |
144 ACPI_FADT_32BIT_TIMER |
145 ACPI_FADT_RESET_REGISTER |
146 ACPI_FADT_PCI_EXPRESS_WAKE |
147 ACPI_FADT_PLATFORM_CLOCK |
148 ACPI_FADT_S4_RTC_VALID |
149 ACPI_FADT_REMOTE_POWER_ON;
150
151 /* Format is from 5.2.3.1: Generic Address Structure */
152 /* reset_reg: see section 4.7.3.6 ACPI 3.0a spec */
153 /* 8 bit write of value 0x06 to 0xCF9 in IO space */
154 fadt->reset_reg.space_id = ACPI_ADDRESS_SPACE_IO;
155 fadt->reset_reg.bit_width = 8;
156 fadt->reset_reg.bit_offset = 0;
157 fadt->reset_reg.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600158 fadt->reset_reg.addrl = SYS_RESET;
Marc Jones24484842017-05-04 21:17:45 -0600159 fadt->reset_reg.addrh = 0x0;
160
161 fadt->reset_value = 6;
162
Elyes HAOUASf5b974e2018-11-10 20:29:08 +0100163 fadt->ARM_boot_arch = 0; /* MUST be 0 ACPI 3.0 */
164 fadt->FADT_MinorVersion = 0; /* MUST be 0 ACPI 3.0 */
Marc Jones24484842017-05-04 21:17:45 -0600165
166 fadt->x_firmware_ctl_l = 0; /* set to 0 if firmware_ctrl is used */
167 fadt->x_firmware_ctl_h = 0;
168 fadt->x_dsdt_l = (u32) dsdt;
169 fadt->x_dsdt_h = 0;
170
171 fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
172 fadt->x_pm1a_evt_blk.bit_width = 32;
173 fadt->x_pm1a_evt_blk.bit_offset = 0;
174 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
175 fadt->x_pm1a_evt_blk.addrl = ACPI_PM_EVT_BLK;
176 fadt->x_pm1a_evt_blk.addrh = 0x0;
177
178 fadt->x_pm1b_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
179 fadt->x_pm1b_evt_blk.bit_width = 0;
180 fadt->x_pm1b_evt_blk.bit_offset = 0;
181 fadt->x_pm1b_evt_blk.access_size = 0;
182 fadt->x_pm1b_evt_blk.addrl = 0x0;
183 fadt->x_pm1b_evt_blk.addrh = 0x0;
184
185
186 fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
187 fadt->x_pm1a_cnt_blk.bit_width = 16;
188 fadt->x_pm1a_cnt_blk.bit_offset = 0;
189 fadt->x_pm1a_cnt_blk.access_size = 0;
190 fadt->x_pm1a_cnt_blk.addrl = ACPI_PM1_CNT_BLK;
191 fadt->x_pm1a_cnt_blk.addrh = 0x0;
192
193 fadt->x_pm1b_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
194 fadt->x_pm1b_cnt_blk.bit_width = 0;
195 fadt->x_pm1b_cnt_blk.bit_offset = 0;
196 fadt->x_pm1b_cnt_blk.access_size = 0;
197 fadt->x_pm1b_cnt_blk.addrl = 0x0;
198 fadt->x_pm1b_cnt_blk.addrh = 0x0;
199
200 /*
Marshall Dawson4e101ad2017-06-15 12:17:38 -0600201 * Note: Under this current AMD C state implementation, this is no
202 * longer used and should not be reported to OS.
Marc Jones24484842017-05-04 21:17:45 -0600203 */
204 fadt->x_pm2_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
205 fadt->x_pm2_cnt_blk.bit_width = 0;
206 fadt->x_pm2_cnt_blk.bit_offset = 0;
207 fadt->x_pm2_cnt_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
208 fadt->x_pm2_cnt_blk.addrl = 0;
209 fadt->x_pm2_cnt_blk.addrh = 0x0;
210
211
212 fadt->x_pm_tmr_blk.space_id = ACPI_ADDRESS_SPACE_IO;
213 fadt->x_pm_tmr_blk.bit_width = 32;
214 fadt->x_pm_tmr_blk.bit_offset = 0;
215 fadt->x_pm_tmr_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
216 fadt->x_pm_tmr_blk.addrl = ACPI_PM_TMR_BLK;
217 fadt->x_pm_tmr_blk.addrh = 0x0;
218
219
220 fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO;
221 fadt->x_gpe0_blk.bit_width = 64; /* EventStatus + Event Enable */
222 fadt->x_gpe0_blk.bit_offset = 0;
223 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_DWORD_ACCESS;
224 fadt->x_gpe0_blk.addrl = ACPI_GPE0_BLK;
225 fadt->x_gpe0_blk.addrh = 0x0;
226
227
228 fadt->x_gpe1_blk.space_id = ACPI_ADDRESS_SPACE_IO;
229 fadt->x_gpe1_blk.bit_width = 0;
230 fadt->x_gpe1_blk.bit_offset = 0;
231 fadt->x_gpe1_blk.access_size = 0;
232 fadt->x_gpe1_blk.addrl = 0;
233 fadt->x_gpe1_blk.addrh = 0x0;
234
235 header->checksum = acpi_checksum((void *)fadt, sizeof(acpi_fadt_t));
236}
Marc Jones257db582017-06-18 17:33:30 -0600237
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200238void generate_cpu_entries(struct device *device)
Marc Jones6bfcf662017-08-06 17:42:35 -0600239{
Richard Spiegel3f16a0f2018-08-06 11:06:08 -0700240 int cores, cpu;
Marc Jones6bfcf662017-08-06 17:42:35 -0600241
242 /* Stoney Ridge is single node, just report # of cores */
Patrick Georgi4fbefc52018-10-23 14:35:37 +0200243 cores = pci_read_config32(SOC_NB_DEV, NB_CAPABILITIES2) & CMP_CAP_MASK;
244 cores++; /* number of cores is CmpCap+1 */
Marc Jones6bfcf662017-08-06 17:42:35 -0600245
246 printk(BIOS_DEBUG, "ACPI \\_PR report %d core(s)\n", cores);
247
Marc Jonese013df92017-08-23 16:28:02 -0600248 /* Generate BSP \_PR.P000 */
Richard Spiegel3f16a0f2018-08-06 11:06:08 -0700249 acpigen_write_processor(0, ACPI_GPE0_BLK, 6);
Marc Jones6bfcf662017-08-06 17:42:35 -0600250 acpigen_pop_len();
251
Marc Jonese013df92017-08-23 16:28:02 -0600252 /* Generate AP \_PR.Pxxx */
Marc Jones6bfcf662017-08-06 17:42:35 -0600253 for (cpu = 1; cpu < cores; cpu++) {
Richard Spiegel3f16a0f2018-08-06 11:06:08 -0700254 acpigen_write_processor(cpu, 0, 0);
Marc Jones6bfcf662017-08-06 17:42:35 -0600255 acpigen_pop_len();
256 }
257}
258
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200259unsigned long southbridge_write_acpi_tables(struct device *device,
Marc Jones257db582017-06-18 17:33:30 -0600260 unsigned long current,
261 struct acpi_rsdp *rsdp)
262{
263 return acpi_write_hpet(device, current, rsdp);
264}
265
266static void acpi_create_gnvs(struct global_nvs_t *gnvs)
267{
268 /* Clear out GNVS. */
269 memset(gnvs, 0, sizeof(*gnvs));
270
Julius Wernercd49cce2019-03-05 16:53:33 -0800271 if (CONFIG(CONSOLE_CBMEM))
Marc Jones257db582017-06-18 17:33:30 -0600272 gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
273
Julius Wernercd49cce2019-03-05 16:53:33 -0800274 if (CONFIG(CHROMEOS)) {
Marc Jones257db582017-06-18 17:33:30 -0600275 /* Initialize Verified Boot data */
Joel Kitching6fbd8742018-08-23 14:56:25 +0800276 chromeos_init_chromeos_acpi(&gnvs->chromeos);
Marc Jones257db582017-06-18 17:33:30 -0600277 gnvs->chromeos.vbt2 = ACTIVE_ECFW_RO;
278 }
279
280 /* Set unknown wake source */
281 gnvs->pm1i = ~0ULL;
Richard Spiegeldbee8ae2018-05-09 17:34:04 -0700282 gnvs->gpei = ~0ULL;
Marc Jones257db582017-06-18 17:33:30 -0600283
284 /* CPU core count */
285 gnvs->pcnt = dev_count_cpu();
286}
287
Elyes HAOUAS777ccd42018-05-22 10:52:05 +0200288void southbridge_inject_dsdt(struct device *device)
Marc Jones257db582017-06-18 17:33:30 -0600289{
290 struct global_nvs_t *gnvs;
291
292 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
293
294 if (gnvs) {
295 acpi_create_gnvs(gnvs);
Marc Jones257db582017-06-18 17:33:30 -0600296
297 /* Add it to DSDT */
298 acpigen_write_scope("\\");
299 acpigen_write_name_dword("NVSA", (uintptr_t)gnvs);
300 acpigen_pop_len();
301 }
302}
Richard Spiegel93459d62018-05-16 14:08:33 -0700303
304static void acpigen_soc_get_gpio_in_local5(uintptr_t addr)
305{
306 /*
307 * Store (\_SB.GPR2 (addr), Local5)
308 * \_SB.GPR2 is used to read control byte 2 from control register.
309 * / It is defined in gpio_lib.asl.
310 */
311 acpigen_write_store();
312 acpigen_emit_namestring("\\_SB.GPR2");
313 acpigen_write_integer(addr);
314 acpigen_emit_byte(LOCAL5_OP);
315}
316
317static int acpigen_soc_get_gpio_val(unsigned int gpio_num, uint32_t mask)
318{
319 if (gpio_num >= GPIO_TOTAL_PINS) {
320 printk(BIOS_WARNING, "Warning: Pin %d should be smaller than"
321 " %d\n", gpio_num, GPIO_TOTAL_PINS);
322 return -1;
323 }
324 uintptr_t addr = (uintptr_t) gpio_get_address(gpio_num);
325
326 acpigen_soc_get_gpio_in_local5(addr);
327
328 /* If (And (Local5, mask)) */
329 acpigen_write_if_and(LOCAL5_OP, mask);
330
331 /* Store (One, Local0) */
332 acpigen_write_store_ops(ONE_OP, LOCAL0_OP);
333
334 acpigen_pop_len(); /* If */
335
336 /* Else */
337 acpigen_write_else();
338
339 /* Store (Zero, Local0) */
340 acpigen_write_store_ops(ZERO_OP, LOCAL0_OP);
341
342 acpigen_pop_len(); /* Else */
343
344 return 0;
345}
346
347static int acpigen_soc_set_gpio_val(unsigned int gpio_num, uint32_t val)
348{
349 if (gpio_num >= GPIO_TOTAL_PINS) {
350 printk(BIOS_WARNING, "Warning: Pin %d should be smaller than"
351 " %d\n", gpio_num, GPIO_TOTAL_PINS);
352 return -1;
353 }
354 uintptr_t addr = (uintptr_t) gpio_get_address(gpio_num);
355
Kevin Chiud837e662018-07-03 19:13:34 +0800356 /* Store (0x40, Local0) */
357 acpigen_write_store();
358 acpigen_write_integer(GPIO_PIN_OUT);
359 acpigen_emit_byte(LOCAL0_OP);
360
Richard Spiegel93459d62018-05-16 14:08:33 -0700361 acpigen_soc_get_gpio_in_local5(addr);
362
363 if (val) {
364 /* Or (Local5, GPIO_PIN_OUT, Local5) */
Kevin Chiud837e662018-07-03 19:13:34 +0800365 acpigen_write_or(LOCAL5_OP, LOCAL0_OP, LOCAL5_OP);
Richard Spiegel93459d62018-05-16 14:08:33 -0700366 } else {
367 /* Not (GPIO_PIN_OUT, Local6) */
Kevin Chiud837e662018-07-03 19:13:34 +0800368 acpigen_write_not(LOCAL0_OP, LOCAL6_OP);
Richard Spiegel93459d62018-05-16 14:08:33 -0700369
370 /* And (Local5, Local6, Local5) */
371 acpigen_write_and(LOCAL5_OP, LOCAL6_OP, LOCAL5_OP);
372 }
373
374 /*
375 * SB.GPW2 (addr, Local5)
376 * \_SB.GPW2 is used to write control byte in control register
377 * / byte 2. It is defined in gpio_lib.asl.
378 */
379 acpigen_emit_namestring("\\_SB.GPW2");
380 acpigen_write_integer(addr);
381 acpigen_emit_byte(LOCAL5_OP);
382
383 return 0;
384}
385
386int acpigen_soc_read_rx_gpio(unsigned int gpio_num)
387{
388 return acpigen_soc_get_gpio_val(gpio_num, GPIO_PIN_IN);
389}
390
391int acpigen_soc_get_tx_gpio(unsigned int gpio_num)
392{
393 return acpigen_soc_get_gpio_val(gpio_num, GPIO_PIN_OUT);
394}
395
396int acpigen_soc_set_tx_gpio(unsigned int gpio_num)
397{
398 return acpigen_soc_set_gpio_val(gpio_num, 1);
399}
400
401int acpigen_soc_clear_tx_gpio(unsigned int gpio_num)
402{
403 return acpigen_soc_set_gpio_val(gpio_num, 0);
404}