blob: d21772944652a271244773d5e018c9b5377ac215 [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
89unsigned long acpi_fill_madt(unsigned long current)
90{
91 /* Local APICs */
92 current = acpi_create_madt_lapics(current);
93
94 /* IOAPIC */
95 current += acpi_create_madt_ioapic((void *)current, 2, IO_APIC_ADDR, 0);
96
97 return acpi_madt_irq_overrides(current);
98}
99
Shaunak Sahabd427802017-07-18 00:19:33 -0700100void acpi_fill_fadt(acpi_fadt_t *fadt)
101{
102 const uint16_t pmbase = ACPI_BASE_ADDRESS;
103
Marc Jonesf9ea7ed2018-08-22 18:59:26 -0600104 fadt->header.revision = get_acpi_table_revision(FADT);
Shaunak Sahabd427802017-07-18 00:19:33 -0700105
106 fadt->sci_int = acpi_sci_irq();
Kyösti Mälkkic328a682019-11-23 07:23:40 +0200107
Kyösti Mälkki0a9e72e2019-08-11 01:22:28 +0300108 if (permanent_smi_handler()) {
Kyösti Mälkkic328a682019-11-23 07:23:40 +0200109 fadt->smi_cmd = APM_CNT;
110 fadt->acpi_enable = APM_CNT_ACPI_ENABLE;
111 fadt->acpi_disable = APM_CNT_ACPI_DISABLE;
112 }
Shaunak Sahabd427802017-07-18 00:19:33 -0700113
114 fadt->pm1a_evt_blk = pmbase + PM1_STS;
Shaunak Sahabd427802017-07-18 00:19:33 -0700115 fadt->pm1a_cnt_blk = pmbase + PM1_CNT;
Shaunak Sahabd427802017-07-18 00:19:33 -0700116
117 fadt->gpe0_blk = pmbase + GPE0_STS(0);
118
119 fadt->pm1_evt_len = 4;
120 fadt->pm1_cnt_len = 2;
121
122 /* GPE0 STS/EN pairs each 32 bits wide. */
123 fadt->gpe0_blk_len = 2 * GPE0_REG_MAX * sizeof(uint32_t);
124
Shaunak Sahabd427802017-07-18 00:19:33 -0700125 fadt->duty_offset = 1;
126 fadt->day_alrm = 0xd;
127
Angel Ponsa208c6c2020-07-13 00:02:34 +0200128 fadt->flags |= ACPI_FADT_WBINVD | ACPI_FADT_C1_SUPPORTED |
129 ACPI_FADT_C2_MP_SUPPORTED | ACPI_FADT_SLEEP_BUTTON |
Angel Pons79572e42020-07-13 00:17:43 +0200130 ACPI_FADT_SEALED_CASE | ACPI_FADT_S4_RTC_WAKE |
131 ACPI_FADT_PLATFORM_CLOCK;
Shaunak Sahabd427802017-07-18 00:19:33 -0700132
Elyes HAOUAS04071f42020-07-20 17:05:24 +0200133 fadt->x_pm1a_evt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Shaunak Sahabd427802017-07-18 00:19:33 -0700134 fadt->x_pm1a_evt_blk.bit_width = fadt->pm1_evt_len * 8;
135 fadt->x_pm1a_evt_blk.addrl = pmbase + PM1_STS;
Angel Pons12a4d052020-07-14 01:31:27 +0200136 fadt->x_pm1a_evt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100137
Elyes HAOUAS04071f42020-07-20 17:05:24 +0200138 fadt->x_pm1a_cnt_blk.space_id = ACPI_ADDRESS_SPACE_IO;
Shaunak Sahabd427802017-07-18 00:19:33 -0700139 fadt->x_pm1a_cnt_blk.bit_width = fadt->pm1_cnt_len * 8;
140 fadt->x_pm1a_cnt_blk.addrl = pmbase + PM1_CNT;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100141 fadt->x_pm1a_cnt_blk.access_size = ACPI_ACCESS_SIZE_WORD_ACCESS;
Shaunak Sahabd427802017-07-18 00:19:33 -0700142
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100143 /*
144 * Windows 10 requires x_gpe0_blk to be set starting with FADT revision 5.
145 * The bit_width field intentionally overflows here.
146 * The OSPM can instead use the values in `fadt->gpe0_blk{,_len}`, which
147 * seems to work fine on Linux 5.0 and Windows 10.
148 */
149 fadt->x_gpe0_blk.space_id = ACPI_ADDRESS_SPACE_IO;
150 fadt->x_gpe0_blk.bit_width = fadt->gpe0_blk_len * 8;
151 fadt->x_gpe0_blk.bit_offset = 0;
Angel Ponsa23aff32020-06-21 20:47:54 +0200152 fadt->x_gpe0_blk.access_size = ACPI_ACCESS_SIZE_BYTE_ACCESS;
Patrick Rudolphc02bda02020-02-28 10:19:41 +0100153 fadt->x_gpe0_blk.addrl = fadt->gpe0_blk;
154 fadt->x_gpe0_blk.addrh = 0;
Shaunak Sahabd427802017-07-18 00:19:33 -0700155}
156
Furquan Shaikh0f007d82020-04-24 06:41:18 -0700157unsigned long southbridge_write_acpi_tables(const struct device *device,
Shaunak Sahabd427802017-07-18 00:19:33 -0700158 unsigned long current,
159 struct acpi_rsdp *rsdp)
160{
Marc Jones5258f4f2020-12-02 11:29:09 -0700161 if (CONFIG(SOC_INTEL_COMMON_BLOCK_UART)) {
162 current = acpi_write_dbg2_pci_uart(rsdp, current,
163 uart_get_device(),
164 ACPI_ACCESS_SIZE_DWORD_ACCESS);
165 }
166
Shaunak Sahabd427802017-07-18 00:19:33 -0700167 return acpi_write_hpet(device, current, rsdp);
168}
169
Aaron Durbin64031672018-04-21 14:45:32 -0600170__weak
Shaunak Sahabd427802017-07-18 00:19:33 -0700171uint32_t acpi_fill_soc_wake(uint32_t generic_pm1_en,
172 const struct chipset_power_state *ps)
173{
174 return generic_pm1_en;
175}
176
Julius Wernercd49cce2019-03-05 16:53:33 -0800177#if CONFIG(SOC_INTEL_COMMON_ACPI_WAKE_SOURCE)
Shaunak Sahabd427802017-07-18 00:19:33 -0700178/*
179 * Save wake source information for calculating ACPI _SWS values
180 *
181 * @pm1: PM1_STS register with only enabled events set
182 * @gpe0: GPE0_STS registers with only enabled events set
183 *
184 * return the number of registers in the gpe0 array or -1 if nothing
185 * is provided by this function.
186 */
187
188static int acpi_fill_wake(uint32_t *pm1, uint32_t **gpe0)
189{
190 struct chipset_power_state *ps;
191 static uint32_t gpe0_sts[GPE0_REG_MAX];
192 uint32_t pm1_en;
193 int i;
194
195 ps = cbmem_find(CBMEM_ID_POWER_STATE);
196 if (ps == NULL)
197 return -1;
198
199 /*
200 * PM1_EN to check the basic wake events which can happen through
201 * powerbtn or any other wake source like lidopen, key board press etc.
202 */
203 pm1_en = ps->pm1_en;
204
205 pm1_en = acpi_fill_soc_wake(pm1_en, ps);
206
207 *pm1 = ps->pm1_sts & pm1_en;
208
209 /* Mask off GPE0 status bits that are not enabled */
210 *gpe0 = &gpe0_sts[0];
211 for (i = 0; i < GPE0_REG_MAX; i++)
212 gpe0_sts[i] = ps->gpe0_sts[i] & ps->gpe0_en[i];
213
214 return GPE0_REG_MAX;
215}
Julien Viard de Galbertcf2b72f2018-04-05 11:24:45 +0200216#endif
Shaunak Sahabd427802017-07-18 00:19:33 -0700217
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300218__weak void acpi_create_gnvs(struct global_nvs *gnvs)
Shaunak Sahabd427802017-07-18 00:19:33 -0700219{
220}
221
Furquan Shaikh338fd9a2020-04-24 22:57:05 -0700222void southbridge_inject_dsdt(const struct device *device)
Shaunak Sahabd427802017-07-18 00:19:33 -0700223{
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300224 struct global_nvs *gnvs;
Shaunak Sahabd427802017-07-18 00:19:33 -0700225
226 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
227 if (!gnvs) {
228 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, sizeof(*gnvs));
229 if (gnvs)
230 memset(gnvs, 0, sizeof(*gnvs));
231 }
232
233 if (gnvs) {
234 acpi_create_gnvs(gnvs);
Shaunak Sahabd427802017-07-18 00:19:33 -0700235 /* And tell SMI about it */
Kyösti Mälkkic3c55212020-06-17 10:34:26 +0300236 apm_control(APM_CNT_GNVS_UPDATE);
Shaunak Sahabd427802017-07-18 00:19:33 -0700237
238 /* Add it to DSDT. */
239 acpigen_write_scope("\\");
240 acpigen_write_name_dword("NVSA", (uintptr_t) gnvs);
241 acpigen_pop_len();
242 }
243}
244
245static int calculate_power(int tdp, int p1_ratio, int ratio)
246{
247 u32 m;
248 u32 power;
249
250 /*
251 * M = ((1.1 - ((p1_ratio - ratio) * 0.00625)) / 1.1) ^ 2
252 *
253 * Power = (ratio / p1_ratio) * m * tdp
254 */
255
256 m = (110000 - ((p1_ratio - ratio) * 625)) / 11;
257 m = (m * m) / 1000;
258
259 power = ((ratio * 100000 / p1_ratio) / 100);
260 power *= (m / 100) * (tdp / 1000);
261 power /= 1000;
262
263 return power;
264}
265
266static int get_cores_per_package(void)
267{
268 struct cpuinfo_x86 c;
269 struct cpuid_result result;
270 int cores = 1;
271
272 get_fms(&c, cpuid_eax(1));
273 if (c.x86 != 6)
274 return 1;
275
276 result = cpuid_ext(0xb, 1);
277 cores = result.ebx & 0xff;
278
279 return cores;
280}
281
282static void generate_c_state_entries(void)
283{
284 acpi_cstate_t *c_state_map;
285 size_t entries;
286
287 c_state_map = soc_get_cstate_map(&entries);
288
289 /* Generate C-state tables */
290 acpigen_write_CST_package(c_state_map, entries);
291}
292
293void generate_p_state_entries(int core, int cores_per_package)
294{
295 int ratio_min, ratio_max, ratio_turbo, ratio_step;
296 int coord_type, power_max, num_entries;
297 int ratio, power, clock, clock_max;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100298 bool turbo;
Shaunak Sahabd427802017-07-18 00:19:33 -0700299
300 coord_type = cpu_get_coord_type();
301 ratio_min = cpu_get_min_ratio();
302 ratio_max = cpu_get_max_ratio();
303 clock_max = (ratio_max * cpu_get_bus_clock()) / KHz;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100304 turbo = (get_turbo_state() == TURBO_ENABLED);
Shaunak Sahabd427802017-07-18 00:19:33 -0700305
306 /* Calculate CPU TDP in mW */
307 power_max = cpu_get_power_max();
308
309 /* Write _PCT indicating use of FFixedHW */
310 acpigen_write_empty_PCT();
311
312 /* Write _PPC with no limit on supported P-state */
313 acpigen_write_PPC_NVS();
314 /* Write PSD indicating configured coordination type */
315 acpigen_write_PSD_package(core, 1, coord_type);
316
317 /* Add P-state entries in _PSS table */
318 acpigen_write_name("_PSS");
319
320 /* Determine ratio points */
321 ratio_step = PSS_RATIO_STEP;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100322 do {
Shaunak Sahabd427802017-07-18 00:19:33 -0700323 num_entries = ((ratio_max - ratio_min) / ratio_step) + 1;
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100324 if (((ratio_max - ratio_min) % ratio_step) > 0)
325 num_entries += 1;
326 if (turbo)
327 num_entries += 1;
328 if (num_entries > PSS_MAX_ENTRIES)
329 ratio_step += 1;
330 } while (num_entries > PSS_MAX_ENTRIES);
331
332 /* _PSS package count depends on Turbo */
333 acpigen_write_package(num_entries);
Shaunak Sahabd427802017-07-18 00:19:33 -0700334
335 /* P[T] is Turbo state if enabled */
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100336 if (turbo) {
Shaunak Sahabd427802017-07-18 00:19:33 -0700337 ratio_turbo = cpu_get_max_turbo_ratio();
338
339 /* Add entry for Turbo ratio */
340 acpigen_write_PSS_package(clock_max + 1, /* MHz */
341 power_max, /* mW */
342 PSS_LATENCY_TRANSITION,/* lat1 */
343 PSS_LATENCY_BUSMASTER,/* lat2 */
344 ratio_turbo << 8, /* control */
345 ratio_turbo << 8); /* status */
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100346 num_entries -= 1;
Shaunak Sahabd427802017-07-18 00:19:33 -0700347 }
348
349 /* First regular entry is max non-turbo ratio */
350 acpigen_write_PSS_package(clock_max, /* MHz */
351 power_max, /* mW */
352 PSS_LATENCY_TRANSITION,/* lat1 */
353 PSS_LATENCY_BUSMASTER,/* lat2 */
354 ratio_max << 8, /* control */
355 ratio_max << 8); /* status */
Julien Viard de Galbertc2540a92018-11-06 09:28:03 +0100356 num_entries -= 1;
Shaunak Sahabd427802017-07-18 00:19:33 -0700357
358 /* Generate the remaining entries */
359 for (ratio = ratio_min + ((num_entries - 1) * ratio_step);
360 ratio >= ratio_min; ratio -= ratio_step) {
361
362 /* Calculate power at this ratio */
363 power = calculate_power(power_max, ratio_max, ratio);
364 clock = (ratio * cpu_get_bus_clock()) / KHz;
365
366 acpigen_write_PSS_package(clock, /* MHz */
367 power, /* mW */
368 PSS_LATENCY_TRANSITION,/* lat1 */
369 PSS_LATENCY_BUSMASTER,/* lat2 */
370 ratio << 8, /* control */
371 ratio << 8); /* status */
372 }
373 /* Fix package length */
374 acpigen_pop_len();
375}
376
Julien Viard de Galbert595202c2018-03-29 14:01:01 +0200377__attribute__ ((weak)) acpi_tstate_t *soc_get_tss_table(int *entries)
Shaunak Sahabd427802017-07-18 00:19:33 -0700378{
379 *entries = 0;
380 return NULL;
381}
382
383void generate_t_state_entries(int core, int cores_per_package)
384{
385 acpi_tstate_t *soc_tss_table;
386 int entries;
387
388 soc_tss_table = soc_get_tss_table(&entries);
389 if (entries == 0)
390 return;
391
392 /* Indicate SW_ALL coordination for T-states */
393 acpigen_write_TSD_package(core, cores_per_package, SW_ALL);
394
395 /* Indicate FixedHW so OS will use MSR */
396 acpigen_write_empty_PTC();
397
398 /* Set NVS controlled T-state limit */
399 acpigen_write_TPC("\\TLVL");
400
401 /* Write TSS table for MSR access */
402 acpigen_write_TSS_package(entries, soc_tss_table);
403}
404
Michael Niewöhnered21df62020-09-19 00:08:45 +0200405static void generate_cppc_entries(int core_id)
406{
407 if (!(CONFIG(SOC_INTEL_COMMON_BLOCK_ACPI_CPPC) &&
408 cpuid_eax(6) & CPUID_6_EAX_ISST))
409 return;
410
411 /* Generate GCPC package in first logical core */
412 if (core_id == 0) {
413 struct cppc_config cppc_config;
414 cpu_init_cppc_config(&cppc_config, CPPC_VERSION_2);
415 acpigen_write_CPPC_package(&cppc_config);
416 }
417
418 /* Write _CPC entry for each logical core */
419 acpigen_write_CPPC_method();
420}
421
Aaron Durbin64031672018-04-21 14:45:32 -0600422__weak void soc_power_states_generation(int core_id,
Shaunak Sahabd427802017-07-18 00:19:33 -0700423 int cores_per_package)
424{
425}
426
Furquan Shaikh7536a392020-04-24 21:59:21 -0700427void generate_cpu_entries(const struct device *device)
Shaunak Sahabd427802017-07-18 00:19:33 -0700428{
429 int core_id, cpu_id, pcontrol_blk = ACPI_BASE_ADDRESS;
430 int plen = 6;
431 int totalcores = dev_count_cpu();
432 int cores_per_package = get_cores_per_package();
433 int numcpus = totalcores / cores_per_package;
434
435 printk(BIOS_DEBUG, "Found %d CPU(s) with %d core(s) each.\n",
436 numcpus, cores_per_package);
437
438 for (cpu_id = 0; cpu_id < numcpus; cpu_id++) {
439 for (core_id = 0; core_id < cores_per_package; core_id++) {
440 if (core_id > 0) {
441 pcontrol_blk = 0;
442 plen = 0;
443 }
444
Christian Walterbe3979c2019-12-18 15:07:59 +0100445 /* Generate processor \_SB.CPUx */
Shaunak Sahabd427802017-07-18 00:19:33 -0700446 acpigen_write_processor((cpu_id) * cores_per_package +
447 core_id, pcontrol_blk, plen);
448
449 /* Generate C-state tables */
450 generate_c_state_entries();
451
Michael Niewöhnered21df62020-09-19 00:08:45 +0200452 generate_cppc_entries(core_id);
453
Shaunak Sahabd427802017-07-18 00:19:33 -0700454 /* Soc specific power states generation */
455 soc_power_states_generation(core_id, cores_per_package);
456
457 acpigen_pop_len();
458 }
459 }
Arthur Heymans0ac555e2018-11-28 12:25:54 +0100460 /* PPKG is usually used for thermal management
461 of the first and only package. */
462 acpigen_write_processor_package("PPKG", 0, cores_per_package);
463
464 /* Add a method to notify processor nodes */
465 acpigen_write_processor_cnot(cores_per_package);
Shaunak Sahabd427802017-07-18 00:19:33 -0700466}
467
Julius Wernercd49cce2019-03-05 16:53:33 -0800468#if CONFIG(SOC_INTEL_COMMON_ACPI_WAKE_SOURCE)
Shaunak Sahabd427802017-07-18 00:19:33 -0700469/* Save wake source data for ACPI _SWS methods in NVS */
470static void acpi_save_wake_source(void *unused)
471{
Kyösti Mälkki0c1dd9c2020-06-17 23:37:49 +0300472 struct global_nvs *gnvs = acpi_get_gnvs();
Shaunak Sahabd427802017-07-18 00:19:33 -0700473 uint32_t pm1, *gpe0;
474 int gpe_reg, gpe_reg_count;
475 int reg_size = sizeof(uint32_t) * 8;
476
477 if (!gnvs)
478 return;
479
480 gnvs->pm1i = -1;
481 gnvs->gpei = -1;
482
483 gpe_reg_count = acpi_fill_wake(&pm1, &gpe0);
484 if (gpe_reg_count < 0)
485 return;
486
487 /* Scan for first set bit in PM1 */
488 for (gnvs->pm1i = 0; gnvs->pm1i < reg_size; gnvs->pm1i++) {
489 if (pm1 & 1)
490 break;
491 pm1 >>= 1;
492 }
493
494 /* If unable to determine then return -1 */
495 if (gnvs->pm1i >= 16)
496 gnvs->pm1i = -1;
497
498 /* Scan for first set bit in GPE registers */
499 for (gpe_reg = 0; gpe_reg < gpe_reg_count; gpe_reg++) {
500 uint32_t gpe = gpe0[gpe_reg];
501 int start = gpe_reg * reg_size;
502 int end = start + reg_size;
503
504 if (gpe == 0) {
505 if (!gnvs->gpei)
506 gnvs->gpei = end;
507 continue;
508 }
509
510 for (gnvs->gpei = start; gnvs->gpei < end; gnvs->gpei++) {
511 if (gpe & 1)
512 break;
513 gpe >>= 1;
514 }
515 }
516
517 /* If unable to determine then return -1 */
518 if (gnvs->gpei >= gpe_reg_count * reg_size)
519 gnvs->gpei = -1;
520
521 printk(BIOS_DEBUG, "ACPI _SWS is PM1 Index %lld GPE Index %lld\n",
522 (long long)gnvs->pm1i, (long long)gnvs->gpei);
523}
524
525BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, acpi_save_wake_source, NULL);
526
527#endif