1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpi_gnvs.h>
4 #include <acpi/acpi_pm.h>
5 #include <amdblocks/acpi.h>
8 #include <soc/southbridge.h>
11 static int get_index_bit(uint32_t value
, uint16_t limit
)
16 if (limit
> TOTAL_BITS(uint32_t))
19 /* get a mask of valid bits. Ex limit = 3, set bits 0-2 */
20 t
= (1ULL << limit
) - 1;
24 for (i
= 0; i
< limit
; i
++) {
32 static void pm_fill_gnvs(struct global_nvs
*gnvs
, const struct acpi_pm_gpe_state
*state
)
36 index
= get_index_bit(state
->pm1_sts
& state
->pm1_en
, PM1_LIMIT
);
40 index
= get_index_bit(state
->gpe0_sts
& state
->gpe0_en
, GPE0_LIMIT
);
45 static void acpi_save_wake_source(void *unused
)
47 const struct chipset_power_state
*ps
;
48 struct global_nvs
*gnvs
;
50 if (acpi_reset_gnvs_for_wake(&gnvs
) < 0)
52 if (acpi_fetch_pm_state(&ps
, PS_CLAIMER_WAKE
) < 0)
55 pm_fill_gnvs(gnvs
, &ps
->gpe_state
);
58 BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE
, BS_ON_ENTRY
, acpi_save_wake_source
, NULL
);