blob: e3e72fddd4a1e2ec48371be08491f2cf361253a9 [file] [log] [blame]
Patrick Georgiac959032020-05-05 22:49:26 +02001/* SPDX-License-Identifier: GPL-2.0-or-later */
Elyes HAOUASa1e22b82019-03-18 22:49:36 +01002
Furquan Shaikh76cedd22020-05-02 10:24:23 -07003#include <acpi/acpigen.h>
Michael Niewöhnered21df62020-09-19 00:08:45 +02004#include <arch/cpu.h>
Shaunak Sahabd427802017-07-18 00:19:33 -07005#include <arch/ioapic.h>
6#include <arch/smp/mpspec.h>
7#include <bootstate.h>
8#include <cbmem.h>
Patrick Rudolphf677d172018-10-01 19:17:11 +02009#include <cf9_reset.h>
Kyösti Mälkki5daa1d32020-06-14 12:01:58 +030010#include <acpi/acpi_gnvs.h>
Elyes HAOUAS20eaef02019-03-29 17:45:28 +010011#include <console/console.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070012#include <cpu/intel/turbo.h>
Michael Niewöhnered21df62020-09-19 00:08:45 +020013#include <cpu/intel/common/common.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070014#include <cpu/x86/smm.h>
15#include <intelblocks/acpi.h>
Marc Jones1403b912020-12-02 14:35:27 -070016#include <intelblocks/lpc_lib.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070017#include <intelblocks/pmclib.h>
Duncan Laurie93bbd412017-11-11 20:03:29 -080018#include <intelblocks/uart.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070019#include <soc/gpio.h>
20#include <soc/iomap.h>
21#include <soc/nvs.h>
22#include <soc/pm.h>
Elyes HAOUASa1e22b82019-03-18 22:49:36 +010023#include <string.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070024
Michael Niewöhnered21df62020-09-19 00:08:45 +020025#define CPUID_6_EAX_ISST (1 << 7)
26
Julien Viard de Galbertcf2b72f2018-04-05 11:24:45 +020027__attribute__((weak)) unsigned long acpi_fill_mcfg(unsigned long current)
Shaunak Sahabd427802017-07-18 00:19:33 -070028{
29 /* PCI Segment Group 0, Start Bus Number 0, End Bus Number is 255 */
30 current += acpi_create_mcfg_mmconfig((void *)current,
31 CONFIG_MMCONF_BASE_ADDRESS, 0, 0,
Duncan Lauriefd50b7c2018-03-02 14:47:11 -080032 (CONFIG_SA_PCIEX_LENGTH >> 20) - 1);
Shaunak Sahabd427802017-07-18 00:19:33 -070033 return current;
34}
35
36static int acpi_sci_irq(void)
37{
38 int sci_irq = 9;
39 uint32_t scis;
40
41 scis = soc_read_sci_irq_select();
42 scis &= SCI_IRQ_SEL;
43 scis >>= SCI_IRQ_ADJUST;
44
45 /* Determine how SCI is routed. */
46 switch (scis) {
47 case SCIS_IRQ9:
48 case SCIS_IRQ10:
49 case SCIS_IRQ11:
50 sci_irq = scis - SCIS_IRQ9 + 9;
51 break;
52 case SCIS_IRQ20:
53 case SCIS_IRQ21:
54 case SCIS_IRQ22:
55 case SCIS_IRQ23:
56 sci_irq = scis - SCIS_IRQ20 + 20;
57 break;
58 default:
59 printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ9.\n");
60 sci_irq = 9;
61 break;
62 }
63
64 printk(BIOS_DEBUG, "SCI is IRQ%d\n", sci_irq);
65 return sci_irq;
66}
67
68static unsigned long acpi_madt_irq_overrides(unsigned long current)
69{
70 int sci = acpi_sci_irq();
71 uint16_t flags = MP_IRQ_TRIGGER_LEVEL;
72
73 /* INT_SRC_OVR */
74 current += acpi_create_madt_irqoverride((void *)current, 0, 0, 2, 0);
75
76 flags |= soc_madt_sci_irq_polarity(sci);
77
78 /* SCI */
79 current +=
80 acpi_create_madt_irqoverride((void *)current, 0, sci, sci, flags);
81
Michael Niewöhner14512f92020-11-23 15:53:28 +010082 /* NMI */
83 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 0xff, 5, 1);
84
Shaunak Sahabd427802017-07-18 00:19:33 -070085 return current;
86}
87
Marc Jones847043c2020-12-02 11:24:00 -070088__weak const struct madt_ioapic_info *soc_get_ioapic_info(size_t *entries)
89{
90 *entries = 0;
91 return NULL;
92}
93
Shaunak Sahabd427802017-07-18 00:19:33 -070094unsigned long acpi_fill_madt(unsigned long current)
95{
Marc Jones847043c2020-12-02 11:24:00 -070096 const struct madt_ioapic_info *ioapic_table;
97 size_t ioapic_entries;
98
Shaunak Sahabd427802017-07-18 00:19:33 -070099 /* Local APICs */
100 current = acpi_create_madt_lapics(current);
101
102 /* IOAPIC */
Marc Jones847043c2020-12-02 11:24:00 -0700103 ioapic_table = soc_get_ioapic_info(&ioapic_entries);
104 if (ioapic_entries) {
105 for (int i = 0; i < ioapic_entries; i++) {
106 current += acpi_create_madt_ioapic(
107 (void *)current,
108 ioapic_table[i].id,
109 ioapic_table[i].addr,
110 ioapic_table[i].gsi_base);
111 }
112 } else {
113 /* Default SOC IOAPIC entry */
114 current += acpi_create_madt_ioapic((void *)current, 2, IO_APIC_ADDR, 0);
115 }
Shaunak Sahabd427802017-07-18 00:19:33 -0700116
117 return acpi_madt_irq_overrides(current);
118}
119
Shaunak Sahabd427802017-07-18 00:19:33 -0700120void acpi_fill_fadt(acpi_fadt_t *fadt)
121{
122 const uint16_t pmbase = ACPI_BASE_ADDRESS;
123
Marc Jonesf9ea7ed2018-08-22 18:59:26 -0600124 fadt->header.revision = get_acpi_table_revision(FADT);
Shaunak Sahabd427802017-07-18 00:19:33 -0700125
126 fadt->sci_int = acpi_sci_irq();
Kyösti Mälkkic328a682019-11-23 07:23:40 +0200127
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +0300128 if (permanent_smi_handler()) {
Kyösti Mälkkic328a682019-11-23 07:23:40 +0200129 fadt->smi_cmd = APM_CNT;
130 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
131 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
132 }
Shaunak Sahabd427802017-07-18 00:19:33 -0700133
134 fadt->pm1a_evt_blk = pmbase + PM1_STS;
Shaunak Sahabd427802017-07-18 00:19:33 -0700135 fadt->pm1a_cnt_blk = pmbase + PM1_CNT;
Shaunak Sahabd427802017-07-18 00:19:33 -0700136
137 fadt->gpe0_blk = pmbase + GPE0_STS(0);
138
139 fadt->pm1_evt_len = 4;
140 fadt->pm1_cnt_len = 2;
141
142 /* GPE0 STS/EN pairs each 32 bits wide. */
143 fadt->gpe0_blk_len = 2 * GPE0_REG_MAX * sizeof(uint32_t);
144
Shaunak Sahabd427802017-07-18 00:19:33 -0700145 fadt->duty_offset = 1;
146 fadt->day_alrm = 0xd;
147
Angel Ponsa208c6c2020-07-13 00:02:34 +0200148 fadt->flags |= ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED |
149 ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON |
Angel Pons79572e42020-07-13 00:17:43 +0200150 ACPI_FADT_SEALED_CASE | ACPI_FADT_S4_RTC_WAKE |
151 ACPI_FADT_PLATFORM_CLOCK;
Shaunak Sahabd427802017-07-18 00:19:33 -0700152
Elyes HAOUAS04071f42020-07-20 17:05:24 +0200153 fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Shaunak Sahabd427802017-07-18 00:19:33 -0700154 fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8;
155 fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS;
Angel Pons12a4d052020-07-14 01:31:27 +0200156 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100157
Elyes HAOUAS04071f42020-07-20 17:05:24 +0200158 fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Shaunak Sahabd427802017-07-18 00:19:33 -0700159 fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8;
160 fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100161 fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
Shaunak Sahabd427802017-07-18 00:19:33 -0700162
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100163 /*
164 * Windows 10 requires x_gpe0_blk to be set starting with FADT revision 5.
165 * The bit_width field intentionally overflows here.
166 * The OSPM can instead use the values in `fadt->gpe0_blk{,_len}`, which
167 * seems to work fine on Linux 5.0 and Windows 10.
168 */
169 fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO;
170 fadt->x_gpe0_blk.bit_width = fadt->gpe0_blk_len * 8;
171 fadt->x_gpe0_blk.bit_offset = 0;
Angel Ponsa23aff32020-06-21 20:47:54 +0200172 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100173 fadt->x_gpe0_blk.addrl = fadt->gpe0_blk;
174 fadt->x_gpe0_blk.addrh = 0;
Shaunak Sahabd427802017-07-18 00:19:33 -0700175}
176
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700177unsigned long southbridge_write_acpi_tables(const struct device *device,
Shaunak Sahabd427802017-07-18 00:19:33 -0700178 unsigned long current,
179 struct acpi_rsdp *rsdp)
180{
Marc Jones5258f4f2020-12-02 11:29:09 -0700181 if (CONFIG(SOC_INTEL_COMMON_BLOCK_UART)) {
182 current = acpi_write_dbg2_pci_uart(rsdp, current,
183 uart_get_device(),
184 ACPI_ACCESS_SIZE_DWORD_ACCESS);
185 }
186
Shaunak Sahabd427802017-07-18 00:19:33 -0700187 return acpi_write_hpet(device, current, rsdp);
188}
189
Aaron Durbin64031672018-04-21 14:45:32 -0600190__weak
Shaunak Sahabd427802017-07-18 00:19:33 -0700191uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
192 const struct chipset_power_state *ps)
193{
194 return generic_pm1_en;
195}
196
Julius Wernercd49cce2019-03-05 16:53:33 -0800197#if CONFIG(SOC_INTEL_COMMON_ACPI_WAKE_SOURCE)
Shaunak Sahabd427802017-07-18 00:19:33 -0700198/*
199 * Save wake source information for calculating ACPI _SWS values
200 *
201 * @pm1: PM1_STS register with only enabled events set
202 * @gpe0: GPE0_STS registers with only enabled events set
203 *
204 * return the number of registers in the gpe0 array or -1 if nothing
205 * is provided by this function.
206 */
207
208static int acpi_fill_wake(uint32_t *pm1, uint32_t **gpe0)
209{
210 struct chipset_power_state *ps;
211 static uint32_t gpe0_sts[GPE0_REG_MAX];
212 uint32_t pm1_en;
213 int i;
214
215 ps = cbmem_find(CBMEM_ID_POWER_STATE);
216 if (ps == NULL)
217 return -1;
218
219 /*
220 * PM1_EN to check the basic wake events which can happen through
221 * powerbtn or any other wake source like lidopen, key board press etc.
222 */
223 pm1_en = ps->pm1_en;
224
225 pm1_en = acpi_fill_soc_wake(pm1_en, ps);
226
227 *pm1 = ps->pm1_sts & pm1_en;
228
229 /* Mask off GPE0 status bits that are not enabled */
230 *gpe0 = &gpe0_sts[0];
231 for (i = 0; i < GPE0_REG_MAX; i++)
232 gpe0_sts[i] = ps->gpe0_sts[i] & ps->gpe0_en[i];
233
234 return GPE0_REG_MAX;
235}
Julien Viard de Galbertcf2b72f2018-04-05 11:24:45 +0200236#endif
Shaunak Sahabd427802017-07-18 00:19:33 -0700237
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300238__weak void acpi_create_gnvs(struct global_nvs *gnvs)
Shaunak Sahabd427802017-07-18 00:19:33 -0700239{
240}
241
Furquan Shaikh338fd9a2020-04-24 22:57:05 -0700242void southbridge_inject_dsdt(const struct device *device)
Shaunak Sahabd427802017-07-18 00:19:33 -0700243{
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300244 struct global_nvs *gnvs;
Shaunak Sahabd427802017-07-18 00:19:33 -0700245
246 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
247 if (!gnvs) {
248 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
249 if (gnvs)
250 memset(gnvs, 0, sizeof(*gnvs));
251 }
252
253 if (gnvs) {
254 acpi_create_gnvs(gnvs);
Shaunak Sahabd427802017-07-18 00:19:33 -0700255 /* And tell SMI about it */
Kyösti Mälkkic3c55212020-06-17 10:34:26 +0300256 apm_control(APM_CNT_GNVS_UPDATE);
Shaunak Sahabd427802017-07-18 00:19:33 -0700257
258 /* Add it to DSDT. */
259 acpigen_write_scope("\\");
260 acpigen_write_name_dword("NVSA", (uintptr_t) gnvs);
261 acpigen_pop_len();
262 }
263}
264
Marc Jonesa81703c2020-12-18 10:44:47 -0700265int common_calculate_power_ratio(int tdp, int p1_ratio, int ratio)
Shaunak Sahabd427802017-07-18 00:19:33 -0700266{
267 u32 m;
268 u32 power;
269
270 /*
271 * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
272 *
273 * Power = (ratio / p1_ratio) * m * tdp
274 */
275
276 m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
277 m = (m * m) / 1000;
278
279 power = ((ratio * 100000 / p1_ratio) / 100);
280 power *= (m / 100) * (tdp / 1000);
281 power /= 1000;
282
283 return power;
284}
285
Shaunak Sahabd427802017-07-18 00:19:33 -0700286static void generate_c_state_entries(void)
287{
288 acpi_cstate_t *c_state_map;
289 size_t entries;
290
291 c_state_map = soc_get_cstate_map(&entries);
292
293 /* Generate C-state tables */
294 acpigen_write_CST_package(c_state_map, entries);
295}
296
297void generate_p_state_entries(int core, int cores_per_package)
298{
299 int ratio_min, ratio_max, ratio_turbo, ratio_step;
300 int coord_type, power_max, num_entries;
301 int ratio, power, clock, clock_max;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100302 bool turbo;
Shaunak Sahabd427802017-07-18 00:19:33 -0700303
304 coord_type = cpu_get_coord_type();
305 ratio_min = cpu_get_min_ratio();
306 ratio_max = cpu_get_max_ratio();
307 clock_max = (ratio_max * cpu_get_bus_clock()) / KHz;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100308 turbo = (get_turbo_state() == TURBO_ENABLED);
Shaunak Sahabd427802017-07-18 00:19:33 -0700309
310 /* Calculate CPU TDP in mW */
311 power_max = cpu_get_power_max();
312
313 /* Write _PCT indicating use of FFixedHW */
314 acpigen_write_empty_PCT();
315
316 /* Write _PPC with no limit on supported P-state */
317 acpigen_write_PPC_NVS();
318 /* Write PSD indicating configured coordination type */
319 acpigen_write_PSD_package(core, 1, coord_type);
320
321 /* Add P-state entries in _PSS table */
322 acpigen_write_name("_PSS");
323
324 /* Determine ratio points */
325 ratio_step = PSS_RATIO_STEP;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100326 do {
Shaunak Sahabd427802017-07-18 00:19:33 -0700327 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100328 if (((ratio_max - ratio_min) % ratio_step) > 0)
329 num_entries += 1;
330 if (turbo)
331 num_entries += 1;
332 if (num_entries > PSS_MAX_ENTRIES)
333 ratio_step += 1;
334 } while (num_entries > PSS_MAX_ENTRIES);
335
336 /* _PSS package count depends on Turbo */
337 acpigen_write_package(num_entries);
Shaunak Sahabd427802017-07-18 00:19:33 -0700338
339 /* P[T] is Turbo state if enabled */
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100340 if (turbo) {
Shaunak Sahabd427802017-07-18 00:19:33 -0700341 ratio_turbo = cpu_get_max_turbo_ratio();
342
343 /* Add entry for Turbo ratio */
344 acpigen_write_PSS_package(clock_max + 1, /* MHz */
345 power_max, /* mW */
346 PSS_LATENCY_TRANSITION,/* lat1 */
347 PSS_LATENCY_BUSMASTER,/* lat2 */
348 ratio_turbo << 8, /* control */
349 ratio_turbo << 8); /* status */
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100350 num_entries -= 1;
Shaunak Sahabd427802017-07-18 00:19:33 -0700351 }
352
353 /* First regular entry is max non-turbo ratio */
354 acpigen_write_PSS_package(clock_max, /* MHz */
355 power_max, /* mW */
356 PSS_LATENCY_TRANSITION,/* lat1 */
357 PSS_LATENCY_BUSMASTER,/* lat2 */
358 ratio_max << 8, /* control */
359 ratio_max << 8); /* status */
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100360 num_entries -= 1;
Shaunak Sahabd427802017-07-18 00:19:33 -0700361
362 /* Generate the remaining entries */
363 for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
364 ratio >= ratio_min; ratio -= ratio_step) {
365
366 /* Calculate power at this ratio */
Marc Jonesa81703c2020-12-18 10:44:47 -0700367 power = common_calculate_power_ratio(power_max, ratio_max, ratio);
Shaunak Sahabd427802017-07-18 00:19:33 -0700368 clock = (ratio * cpu_get_bus_clock()) / KHz;
369
370 acpigen_write_PSS_package(clock, /* MHz */
371 power, /* mW */
372 PSS_LATENCY_TRANSITION,/* lat1 */
373 PSS_LATENCY_BUSMASTER,/* lat2 */
374 ratio << 8, /* control */
375 ratio << 8); /* status */
376 }
377 /* Fix package length */
378 acpigen_pop_len();
379}
380
Julien Viard de Galbert595202c2018-03-29 14:01:01 +0200381__attribute__ ((weak)) acpi_tstate_t *soc_get_tss_table(int *entries)
Shaunak Sahabd427802017-07-18 00:19:33 -0700382{
383 *entries = 0;
384 return NULL;
385}
386
387void generate_t_state_entries(int core, int cores_per_package)
388{
389 acpi_tstate_t *soc_tss_table;
390 int entries;
391
392 soc_tss_table = soc_get_tss_table(&entries);
393 if (entries == 0)
394 return;
395
396 /* Indicate SW_ALL coordination for T-states */
397 acpigen_write_TSD_package(core, cores_per_package, SW_ALL);
398
399 /* Indicate FixedHW so OS will use MSR */
400 acpigen_write_empty_PTC();
401
402 /* Set NVS controlled T-state limit */
403 acpigen_write_TPC("\\TLVL");
404
405 /* Write TSS table for MSR access */
406 acpigen_write_TSS_package(entries, soc_tss_table);
407}
408
Michael Niewöhnered21df62020-09-19 00:08:45 +0200409static void generate_cppc_entries(int core_id)
410{
411 if (!(CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_CPPC) &&
412 cpuid_eax(6) & CPUID_6_EAX_ISST))
413 return;
414
415 /* Generate GCPC package in first logical core */
416 if (core_id == 0) {
417 struct cppc_config cppc_config;
418 cpu_init_cppc_config(&cppc_config, CPPC_VERSION_2);
419 acpigen_write_CPPC_package(&cppc_config);
420 }
421
422 /* Write _CPC entry for each logical core */
423 acpigen_write_CPPC_method();
424}
425
Aaron Durbin64031672018-04-21 14:45:32 -0600426__weak void soc_power_states_generation(int core_id,
Shaunak Sahabd427802017-07-18 00:19:33 -0700427 int cores_per_package)
428{
429}
430
Furquan Shaikh7536a392020-04-24 21:59:21 -0700431void generate_cpu_entries(const struct device *device)
Shaunak Sahabd427802017-07-18 00:19:33 -0700432{
433 int core_id, cpu_id, pcontrol_blk = ACPI_BASE_ADDRESS;
434 int plen = 6;
435 int totalcores = dev_count_cpu();
Patrick Rudolph7a66ffb2020-12-17 14:42:29 +0100436 unsigned int num_virt;
437 unsigned int num_phys;
Shaunak Sahabd427802017-07-18 00:19:33 -0700438
Patrick Rudolph7a66ffb2020-12-17 14:42:29 +0100439 cpu_read_topology(&num_phys, &num_virt);
440
441 int numcpus = totalcores / num_virt;
442
443 printk(BIOS_DEBUG, "Found %d CPU(s) with %d/%d physical/logical core(s) each.\n",
444 numcpus, num_phys, num_virt);
Shaunak Sahabd427802017-07-18 00:19:33 -0700445
446 for (cpu_id = 0; cpu_id < numcpus; cpu_id++) {
Patrick Rudolph7a66ffb2020-12-17 14:42:29 +0100447 for (core_id = 0; core_id < num_virt; core_id++) {
Shaunak Sahabd427802017-07-18 00:19:33 -0700448 if (core_id > 0) {
449 pcontrol_blk = 0;
450 plen = 0;
451 }
452
Christian Walterbe3979c2019-12-18 15:07:59 +0100453 /* Generate processor \_SB.CPUx */
Patrick Rudolph7a66ffb2020-12-17 14:42:29 +0100454 acpigen_write_processor((cpu_id) * num_virt +
Shaunak Sahabd427802017-07-18 00:19:33 -0700455 core_id, pcontrol_blk, plen);
456
457 /* Generate C-state tables */
458 generate_c_state_entries();
459
Michael Niewöhnered21df62020-09-19 00:08:45 +0200460 generate_cppc_entries(core_id);
461
Shaunak Sahabd427802017-07-18 00:19:33 -0700462 /* Soc specific power states generation */
Patrick Rudolph7a66ffb2020-12-17 14:42:29 +0100463 soc_power_states_generation(core_id, num_virt);
Shaunak Sahabd427802017-07-18 00:19:33 -0700464
465 acpigen_pop_len();
466 }
467 }
Arthur Heymans0ac555e2018-11-28 12:25:54 +0100468 /* PPKG is usually used for thermal management
469 of the first and only package. */
Patrick Rudolph7a66ffb2020-12-17 14:42:29 +0100470 acpigen_write_processor_package("PPKG", 0, num_virt);
Arthur Heymans0ac555e2018-11-28 12:25:54 +0100471
472 /* Add a method to notify processor nodes */
Patrick Rudolph7a66ffb2020-12-17 14:42:29 +0100473 acpigen_write_processor_cnot(num_virt);
Shaunak Sahabd427802017-07-18 00:19:33 -0700474}
475
Julius Wernercd49cce2019-03-05 16:53:33 -0800476#if CONFIG(SOC_INTEL_COMMON_ACPI_WAKE_SOURCE)
Shaunak Sahabd427802017-07-18 00:19:33 -0700477/* Save wake source data for ACPI _SWS methods in NVS */
478static void acpi_save_wake_source(void *unused)
479{
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300480 struct global_nvs *gnvs = acpi_get_gnvs();
Shaunak Sahabd427802017-07-18 00:19:33 -0700481 uint32_t pm1, *gpe0;
482 int gpe_reg, gpe_reg_count;
483 int reg_size = sizeof(uint32_t) * 8;
484
485 if (!gnvs)
486 return;
487
488 gnvs->pm1i = -1;
489 gnvs->gpei = -1;
490
491 gpe_reg_count = acpi_fill_wake(&pm1, &gpe0);
492 if (gpe_reg_count < 0)
493 return;
494
495 /* Scan for first set bit in PM1 */
496 for (gnvs->pm1i = 0; gnvs->pm1i < reg_size; gnvs->pm1i++) {
497 if (pm1 & 1)
498 break;
499 pm1 >>= 1;
500 }
501
502 /* If unable to determine then return -1 */
503 if (gnvs->pm1i >= 16)
504 gnvs->pm1i = -1;
505
506 /* Scan for first set bit in GPE registers */
507 for (gpe_reg = 0; gpe_reg < gpe_reg_count; gpe_reg++) {
508 uint32_t gpe = gpe0[gpe_reg];
509 int start = gpe_reg * reg_size;
510 int end = start + reg_size;
511
512 if (gpe == 0) {
513 if (!gnvs->gpei)
514 gnvs->gpei = end;
515 continue;
516 }
517
518 for (gnvs->gpei = start; gnvs->gpei < end; gnvs->gpei++) {
519 if (gpe & 1)
520 break;
521 gpe >>= 1;
522 }
523 }
524
525 /* If unable to determine then return -1 */
526 if (gnvs->gpei >= gpe_reg_count * reg_size)
527 gnvs->gpei = -1;
528
529 printk(BIOS_DEBUG, "ACPI _SWS is PM1 Index %lld GPE Index %lld\n",
530 (long long)gnvs->pm1i, (long long)gnvs->gpei);
531}
532
533BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, acpi_save_wake_source, NULL);
534
535#endif