blob: 934a92f7c5744ec6997bd4e9c0a15a1a56747e55 [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/msr.h>
18#include <intelblocks/pmclib.h>
Duncan Laurie93bbd412017-11-11 20:03:29 -080019#include <intelblocks/uart.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070020#include <soc/gpio.h>
21#include <soc/iomap.h>
22#include <soc/nvs.h>
23#include <soc/pm.h>
Elyes HAOUASa1e22b82019-03-18 22:49:36 +010024#include <string.h>
Shaunak Sahabd427802017-07-18 00:19:33 -070025
Michael Niewöhnered21df62020-09-19 00:08:45 +020026#define CPUID_6_EAX_ISST (1 << 7)
27
Julien Viard de Galbertcf2b72f2018-04-05 11:24:45 +020028__attribute__((weak)) unsigned long acpi_fill_mcfg(unsigned long current)
Shaunak Sahabd427802017-07-18 00:19:33 -070029{
30 /* PCI Segment Group 0, Start Bus Number 0, End Bus Number is 255 */
31 current += acpi_create_mcfg_mmconfig((void *)current,
32 CONFIG_MMCONF_BASE_ADDRESS, 0, 0,
Duncan Lauriefd50b7c2018-03-02 14:47:11 -080033 (CONFIG_SA_PCIEX_LENGTH >> 20) - 1);
Shaunak Sahabd427802017-07-18 00:19:33 -070034 return current;
35}
36
37static int acpi_sci_irq(void)
38{
39 int sci_irq = 9;
40 uint32_t scis;
41
42 scis = soc_read_sci_irq_select();
43 scis &= SCI_IRQ_SEL;
44 scis >>= SCI_IRQ_ADJUST;
45
46 /* Determine how SCI is routed. */
47 switch (scis) {
48 case SCIS_IRQ9:
49 case SCIS_IRQ10:
50 case SCIS_IRQ11:
51 sci_irq = scis - SCIS_IRQ9 + 9;
52 break;
53 case SCIS_IRQ20:
54 case SCIS_IRQ21:
55 case SCIS_IRQ22:
56 case SCIS_IRQ23:
57 sci_irq = scis - SCIS_IRQ20 + 20;
58 break;
59 default:
60 printk(BIOS_DEBUG, "Invalid SCI route! Defaulting to IRQ9.\n");
61 sci_irq = 9;
62 break;
63 }
64
65 printk(BIOS_DEBUG, "SCI is IRQ%d\n", sci_irq);
66 return sci_irq;
67}
68
69static unsigned long acpi_madt_irq_overrides(unsigned long current)
70{
71 int sci = acpi_sci_irq();
72 uint16_t flags = MP_IRQ_TRIGGER_LEVEL;
73
74 /* INT_SRC_OVR */
75 current += acpi_create_madt_irqoverride((void *)current, 0, 0, 2, 0);
76
77 flags |= soc_madt_sci_irq_polarity(sci);
78
79 /* SCI */
80 current +=
81 acpi_create_madt_irqoverride((void *)current, 0, sci, sci, flags);
82
Michael Niewöhner14512f92020-11-23 15:53:28 +010083 /* NMI */
84 current += acpi_create_madt_lapic_nmi((acpi_madt_lapic_nmi_t *)current, 0xff, 5, 1);
85
Shaunak Sahabd427802017-07-18 00:19:33 -070086 return current;
87}
88
Marc Jones847043c2020-12-02 11:24:00 -070089__weak const struct madt_ioapic_info *soc_get_ioapic_info(size_t *entries)
90{
91 *entries = 0;
92 return NULL;
93}
94
Shaunak Sahabd427802017-07-18 00:19:33 -070095unsigned long acpi_fill_madt(unsigned long current)
96{
Marc Jones847043c2020-12-02 11:24:00 -070097 const struct madt_ioapic_info *ioapic_table;
98 size_t ioapic_entries;
99
Shaunak Sahabd427802017-07-18 00:19:33 -0700100 /* Local APICs */
101 current = acpi_create_madt_lapics(current);
102
103 /* IOAPIC */
Marc Jones847043c2020-12-02 11:24:00 -0700104 ioapic_table = soc_get_ioapic_info(&ioapic_entries);
105 if (ioapic_entries) {
106 for (int i = 0; i < ioapic_entries; i++) {
107 current += acpi_create_madt_ioapic(
108 (void *)current,
109 ioapic_table[i].id,
110 ioapic_table[i].addr,
111 ioapic_table[i].gsi_base);
112 }
113 } else {
114 /* Default SOC IOAPIC entry */
115 current += acpi_create_madt_ioapic((void *)current, 2, IO_APIC_ADDR, 0);
116 }
Shaunak Sahabd427802017-07-18 00:19:33 -0700117
118 return acpi_madt_irq_overrides(current);
119}
120
Shaunak Sahabd427802017-07-18 00:19:33 -0700121void acpi_fill_fadt(acpi_fadt_t *fadt)
122{
123 const uint16_t pmbase = ACPI_BASE_ADDRESS;
124
Marc Jonesf9ea7ed2018-08-22 18:59:26 -0600125 fadt->header.revision = get_acpi_table_revision(FADT);
Shaunak Sahabd427802017-07-18 00:19:33 -0700126
127 fadt->sci_int = acpi_sci_irq();
Kyösti Mälkkic328a682019-11-23 07:23:40 +0200128
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +0300129 if (permanent_smi_handler()) {
Kyösti Mälkkic328a682019-11-23 07:23:40 +0200130 fadt->smi_cmd = APM_CNT;
131 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
132 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
133 }
Shaunak Sahabd427802017-07-18 00:19:33 -0700134
135 fadt->pm1a_evt_blk = pmbase + PM1_STS;
Shaunak Sahabd427802017-07-18 00:19:33 -0700136 fadt->pm1a_cnt_blk = pmbase + PM1_CNT;
Shaunak Sahabd427802017-07-18 00:19:33 -0700137
138 fadt->gpe0_blk = pmbase + GPE0_STS(0);
139
140 fadt->pm1_evt_len = 4;
141 fadt->pm1_cnt_len = 2;
142
143 /* GPE0 STS/EN pairs each 32 bits wide. */
144 fadt->gpe0_blk_len = 2 * GPE0_REG_MAX * sizeof(uint32_t);
145
Shaunak Sahabd427802017-07-18 00:19:33 -0700146 fadt->duty_offset = 1;
147 fadt->day_alrm = 0xd;
148
Angel Ponsa208c6c2020-07-13 00:02:34 +0200149 fadt->flags |= ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED |
150 ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON |
Angel Pons79572e42020-07-13 00:17:43 +0200151 ACPI_FADT_SEALED_CASE | ACPI_FADT_S4_RTC_WAKE |
152 ACPI_FADT_PLATFORM_CLOCK;
Shaunak Sahabd427802017-07-18 00:19:33 -0700153
Elyes HAOUAS04071f42020-07-20 17:05:24 +0200154 fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Shaunak Sahabd427802017-07-18 00:19:33 -0700155 fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8;
156 fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS;
Angel Pons12a4d052020-07-14 01:31:27 +0200157 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100158
Elyes HAOUAS04071f42020-07-20 17:05:24 +0200159 fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Shaunak Sahabd427802017-07-18 00:19:33 -0700160 fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8;
161 fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100162 fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
Shaunak Sahabd427802017-07-18 00:19:33 -0700163
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100164 /*
165 * Windows 10 requires x_gpe0_blk to be set starting with FADT revision 5.
166 * The bit_width field intentionally overflows here.
167 * The OSPM can instead use the values in `fadt->gpe0_blk{,_len}`, which
168 * seems to work fine on Linux 5.0 and Windows 10.
169 */
170 fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO;
171 fadt->x_gpe0_blk.bit_width = fadt->gpe0_blk_len * 8;
172 fadt->x_gpe0_blk.bit_offset = 0;
Angel Ponsa23aff32020-06-21 20:47:54 +0200173 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100174 fadt->x_gpe0_blk.addrl = fadt->gpe0_blk;
175 fadt->x_gpe0_blk.addrh = 0;
Shaunak Sahabd427802017-07-18 00:19:33 -0700176}
177
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700178unsigned long southbridge_write_acpi_tables(const struct device *device,
Shaunak Sahabd427802017-07-18 00:19:33 -0700179 unsigned long current,
180 struct acpi_rsdp *rsdp)
181{
Marc Jones5258f4f2020-12-02 11:29:09 -0700182 if (CONFIG(SOC_INTEL_COMMON_BLOCK_UART)) {
183 current = acpi_write_dbg2_pci_uart(rsdp, current,
184 uart_get_device(),
185 ACPI_ACCESS_SIZE_DWORD_ACCESS);
186 }
187
Shaunak Sahabd427802017-07-18 00:19:33 -0700188 return acpi_write_hpet(device, current, rsdp);
189}
190
Aaron Durbin64031672018-04-21 14:45:32 -0600191__weak
Shaunak Sahabd427802017-07-18 00:19:33 -0700192uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
193 const struct chipset_power_state *ps)
194{
195 return generic_pm1_en;
196}
197
Julius Wernercd49cce2019-03-05 16:53:33 -0800198#if CONFIG(SOC_INTEL_COMMON_ACPI_WAKE_SOURCE)
Shaunak Sahabd427802017-07-18 00:19:33 -0700199/*
200 * Save wake source information for calculating ACPI _SWS values
201 *
202 * @pm1: PM1_STS register with only enabled events set
203 * @gpe0: GPE0_STS registers with only enabled events set
204 *
205 * return the number of registers in the gpe0 array or -1 if nothing
206 * is provided by this function.
207 */
208
209static int acpi_fill_wake(uint32_t *pm1, uint32_t **gpe0)
210{
211 struct chipset_power_state *ps;
212 static uint32_t gpe0_sts[GPE0_REG_MAX];
213 uint32_t pm1_en;
214 int i;
215
216 ps = cbmem_find(CBMEM_ID_POWER_STATE);
217 if (ps == NULL)
218 return -1;
219
220 /*
221 * PM1_EN to check the basic wake events which can happen through
222 * powerbtn or any other wake source like lidopen, key board press etc.
223 */
224 pm1_en = ps->pm1_en;
225
226 pm1_en = acpi_fill_soc_wake(pm1_en, ps);
227
228 *pm1 = ps->pm1_sts & pm1_en;
229
230 /* Mask off GPE0 status bits that are not enabled */
231 *gpe0 = &gpe0_sts[0];
232 for (i = 0; i < GPE0_REG_MAX; i++)
233 gpe0_sts[i] = ps->gpe0_sts[i] & ps->gpe0_en[i];
234
235 return GPE0_REG_MAX;
236}
Julien Viard de Galbertcf2b72f2018-04-05 11:24:45 +0200237#endif
Shaunak Sahabd427802017-07-18 00:19:33 -0700238
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300239__weak void acpi_create_gnvs(struct global_nvs *gnvs)
Shaunak Sahabd427802017-07-18 00:19:33 -0700240{
241}
242
Furquan Shaikh338fd9a2020-04-24 22:57:05 -0700243void southbridge_inject_dsdt(const struct device *device)
Shaunak Sahabd427802017-07-18 00:19:33 -0700244{
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300245 struct global_nvs *gnvs;
Shaunak Sahabd427802017-07-18 00:19:33 -0700246
247 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
248 if (!gnvs) {
249 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
250 if (gnvs)
251 memset(gnvs, 0, sizeof(*gnvs));
252 }
253
254 if (gnvs) {
255 acpi_create_gnvs(gnvs);
Shaunak Sahabd427802017-07-18 00:19:33 -0700256 /* And tell SMI about it */
Kyösti Mälkkic3c55212020-06-17 10:34:26 +0300257 apm_control(APM_CNT_GNVS_UPDATE);
Shaunak Sahabd427802017-07-18 00:19:33 -0700258
259 /* Add it to DSDT. */
260 acpigen_write_scope("\\");
261 acpigen_write_name_dword("NVSA", (uintptr_t) gnvs);
262 acpigen_pop_len();
263 }
264}
265
Marc Jonesa81703c2020-12-18 10:44:47 -0700266int common_calculate_power_ratio(int tdp, int p1_ratio, int ratio)
Shaunak Sahabd427802017-07-18 00:19:33 -0700267{
268 u32 m;
269 u32 power;
270
271 /*
272 * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
273 *
274 * Power = (ratio / p1_ratio) * m * tdp
275 */
276
277 m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
278 m = (m * m) / 1000;
279
280 power = ((ratio * 100000 / p1_ratio) / 100);
281 power *= (m / 100) * (tdp / 1000);
282 power /= 1000;
283
284 return power;
285}
286
287static int get_cores_per_package(void)
288{
289 struct cpuinfo_x86 c;
290 struct cpuid_result result;
291 int cores = 1;
292
293 get_fms(&c, cpuid_eax(1));
294 if (c.x86 != 6)
295 return 1;
296
297 result = cpuid_ext(0xb, 1);
298 cores = result.ebx & 0xff;
299
300 return cores;
301}
302
303static void generate_c_state_entries(void)
304{
305 acpi_cstate_t *c_state_map;
306 size_t entries;
307
308 c_state_map = soc_get_cstate_map(&entries);
309
310 /* Generate C-state tables */
311 acpigen_write_CST_package(c_state_map, entries);
312}
313
314void generate_p_state_entries(int core, int cores_per_package)
315{
316 int ratio_min, ratio_max, ratio_turbo, ratio_step;
317 int coord_type, power_max, num_entries;
318 int ratio, power, clock, clock_max;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100319 bool turbo;
Shaunak Sahabd427802017-07-18 00:19:33 -0700320
321 coord_type = cpu_get_coord_type();
322 ratio_min = cpu_get_min_ratio();
323 ratio_max = cpu_get_max_ratio();
324 clock_max = (ratio_max * cpu_get_bus_clock()) / KHz;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100325 turbo = (get_turbo_state() == TURBO_ENABLED);
Shaunak Sahabd427802017-07-18 00:19:33 -0700326
327 /* Calculate CPU TDP in mW */
328 power_max = cpu_get_power_max();
329
330 /* Write _PCT indicating use of FFixedHW */
331 acpigen_write_empty_PCT();
332
333 /* Write _PPC with no limit on supported P-state */
334 acpigen_write_PPC_NVS();
335 /* Write PSD indicating configured coordination type */
336 acpigen_write_PSD_package(core, 1, coord_type);
337
338 /* Add P-state entries in _PSS table */
339 acpigen_write_name("_PSS");
340
341 /* Determine ratio points */
342 ratio_step = PSS_RATIO_STEP;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100343 do {
Shaunak Sahabd427802017-07-18 00:19:33 -0700344 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100345 if (((ratio_max - ratio_min) % ratio_step) > 0)
346 num_entries += 1;
347 if (turbo)
348 num_entries += 1;
349 if (num_entries > PSS_MAX_ENTRIES)
350 ratio_step += 1;
351 } while (num_entries > PSS_MAX_ENTRIES);
352
353 /* _PSS package count depends on Turbo */
354 acpigen_write_package(num_entries);
Shaunak Sahabd427802017-07-18 00:19:33 -0700355
356 /* P[T] is Turbo state if enabled */
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100357 if (turbo) {
Shaunak Sahabd427802017-07-18 00:19:33 -0700358 ratio_turbo = cpu_get_max_turbo_ratio();
359
360 /* Add entry for Turbo ratio */
361 acpigen_write_PSS_package(clock_max + 1, /* MHz */
362 power_max, /* mW */
363 PSS_LATENCY_TRANSITION,/* lat1 */
364 PSS_LATENCY_BUSMASTER,/* lat2 */
365 ratio_turbo << 8, /* control */
366 ratio_turbo << 8); /* status */
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100367 num_entries -= 1;
Shaunak Sahabd427802017-07-18 00:19:33 -0700368 }
369
370 /* First regular entry is max non-turbo ratio */
371 acpigen_write_PSS_package(clock_max, /* MHz */
372 power_max, /* mW */
373 PSS_LATENCY_TRANSITION,/* lat1 */
374 PSS_LATENCY_BUSMASTER,/* lat2 */
375 ratio_max << 8, /* control */
376 ratio_max << 8); /* status */
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100377 num_entries -= 1;
Shaunak Sahabd427802017-07-18 00:19:33 -0700378
379 /* Generate the remaining entries */
380 for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
381 ratio >= ratio_min; ratio -= ratio_step) {
382
383 /* Calculate power at this ratio */
Marc Jonesa81703c2020-12-18 10:44:47 -0700384 power = common_calculate_power_ratio(power_max, ratio_max, ratio);
Shaunak Sahabd427802017-07-18 00:19:33 -0700385 clock = (ratio * cpu_get_bus_clock()) / KHz;
386
387 acpigen_write_PSS_package(clock, /* MHz */
388 power, /* mW */
389 PSS_LATENCY_TRANSITION,/* lat1 */
390 PSS_LATENCY_BUSMASTER,/* lat2 */
391 ratio << 8, /* control */
392 ratio << 8); /* status */
393 }
394 /* Fix package length */
395 acpigen_pop_len();
396}
397
Julien Viard de Galbert595202c2018-03-29 14:01:01 +0200398__attribute__ ((weak)) acpi_tstate_t *soc_get_tss_table(int *entries)
Shaunak Sahabd427802017-07-18 00:19:33 -0700399{
400 *entries = 0;
401 return NULL;
402}
403
404void generate_t_state_entries(int core, int cores_per_package)
405{
406 acpi_tstate_t *soc_tss_table;
407 int entries;
408
409 soc_tss_table = soc_get_tss_table(&entries);
410 if (entries == 0)
411 return;
412
413 /* Indicate SW_ALL coordination for T-states */
414 acpigen_write_TSD_package(core, cores_per_package, SW_ALL);
415
416 /* Indicate FixedHW so OS will use MSR */
417 acpigen_write_empty_PTC();
418
419 /* Set NVS controlled T-state limit */
420 acpigen_write_TPC("\\TLVL");
421
422 /* Write TSS table for MSR access */
423 acpigen_write_TSS_package(entries, soc_tss_table);
424}
425
Michael Niewöhnered21df62020-09-19 00:08:45 +0200426static void generate_cppc_entries(int core_id)
427{
428 if (!(CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_CPPC) &&
429 cpuid_eax(6) & CPUID_6_EAX_ISST))
430 return;
431
432 /* Generate GCPC package in first logical core */
433 if (core_id == 0) {
434 struct cppc_config cppc_config;
435 cpu_init_cppc_config(&cppc_config, CPPC_VERSION_2);
436 acpigen_write_CPPC_package(&cppc_config);
437 }
438
439 /* Write _CPC entry for each logical core */
440 acpigen_write_CPPC_method();
441}
442
Aaron Durbin64031672018-04-21 14:45:32 -0600443__weak void soc_power_states_generation(int core_id,
Shaunak Sahabd427802017-07-18 00:19:33 -0700444 int cores_per_package)
445{
446}
447
Furquan Shaikh7536a392020-04-24 21:59:21 -0700448void generate_cpu_entries(const struct device *device)
Shaunak Sahabd427802017-07-18 00:19:33 -0700449{
450 int core_id, cpu_id, pcontrol_blk = ACPI_BASE_ADDRESS;
451 int plen = 6;
452 int totalcores = dev_count_cpu();
453 int cores_per_package = get_cores_per_package();
454 int numcpus = totalcores / cores_per_package;
455
456 printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n",
457 numcpus, cores_per_package);
458
459 for (cpu_id = 0; cpu_id < numcpus; cpu_id++) {
460 for (core_id = 0; core_id < cores_per_package; core_id++) {
461 if (core_id > 0) {
462 pcontrol_blk = 0;
463 plen = 0;
464 }
465
Christian Walterbe3979c2019-12-18 15:07:59 +0100466 /* Generate processor \_SB.CPUx */
Shaunak Sahabd427802017-07-18 00:19:33 -0700467 acpigen_write_processor((cpu_id) * cores_per_package +
468 core_id, pcontrol_blk, plen);
469
470 /* Generate C-state tables */
471 generate_c_state_entries();
472
Michael Niewöhnered21df62020-09-19 00:08:45 +0200473 generate_cppc_entries(core_id);
474
Shaunak Sahabd427802017-07-18 00:19:33 -0700475 /* Soc specific power states generation */
476 soc_power_states_generation(core_id, cores_per_package);
477
478 acpigen_pop_len();
479 }
480 }
Arthur Heymans0ac555e2018-11-28 12:25:54 +0100481 /* PPKG is usually used for thermal management
482 of the first and only package. */
483 acpigen_write_processor_package("PPKG", 0, cores_per_package);
484
485 /* Add a method to notify processor nodes */
486 acpigen_write_processor_cnot(cores_per_package);
Shaunak Sahabd427802017-07-18 00:19:33 -0700487}
488
Julius Wernercd49cce2019-03-05 16:53:33 -0800489#if CONFIG(SOC_INTEL_COMMON_ACPI_WAKE_SOURCE)
Shaunak Sahabd427802017-07-18 00:19:33 -0700490/* Save wake source data for ACPI _SWS methods in NVS */
491static void acpi_save_wake_source(void *unused)
492{
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300493 struct global_nvs *gnvs = acpi_get_gnvs();
Shaunak Sahabd427802017-07-18 00:19:33 -0700494 uint32_t pm1, *gpe0;
495 int gpe_reg, gpe_reg_count;
496 int reg_size = sizeof(uint32_t) * 8;
497
498 if (!gnvs)
499 return;
500
501 gnvs->pm1i = -1;
502 gnvs->gpei = -1;
503
504 gpe_reg_count = acpi_fill_wake(&pm1, &gpe0);
505 if (gpe_reg_count < 0)
506 return;
507
508 /* Scan for first set bit in PM1 */
509 for (gnvs->pm1i = 0; gnvs->pm1i < reg_size; gnvs->pm1i++) {
510 if (pm1 & 1)
511 break;
512 pm1 >>= 1;
513 }
514
515 /* If unable to determine then return -1 */
516 if (gnvs->pm1i >= 16)
517 gnvs->pm1i = -1;
518
519 /* Scan for first set bit in GPE registers */
520 for (gpe_reg = 0; gpe_reg < gpe_reg_count; gpe_reg++) {
521 uint32_t gpe = gpe0[gpe_reg];
522 int start = gpe_reg * reg_size;
523 int end = start + reg_size;
524
525 if (gpe == 0) {
526 if (!gnvs->gpei)
527 gnvs->gpei = end;
528 continue;
529 }
530
531 for (gnvs->gpei = start; gnvs->gpei < end; gnvs->gpei++) {
532 if (gpe & 1)
533 break;
534 gpe >>= 1;
535 }
536 }
537
538 /* If unable to determine then return -1 */
539 if (gnvs->gpei >= gpe_reg_count * reg_size)
540 gnvs->gpei = -1;
541
542 printk(BIOS_DEBUG, "ACPI _SWS is PM1 Index %lld GPE Index %lld\n",
543 (long long)gnvs->pm1i, (long long)gnvs->gpei);
544}
545
546BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, acpi_save_wake_source, NULL);
547
548#endif