1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpi_gnvs.h>
4 #include <acpi/acpigen.h>
7 #include <console/console.h>
12 static struct global_nvs
*gnvs
;
15 static void acpi_create_gnvs(void *unused
)
17 const size_t gnvs_size
= ALIGN_UP(sizeof(struct global_nvs
), sizeof(uint64_t));
18 const size_t dnvs_size
= ALIGN_UP(size_of_dnvs(), sizeof(uint64_t));
20 gnvs
= cbmem_find(CBMEM_ID_ACPI_GNVS
);
24 /* Allocate for both GNVS and DNVS OpRegions. */
25 gnvs
= cbmem_add(CBMEM_ID_ACPI_GNVS
, gnvs_size
+ dnvs_size
);
29 memset(gnvs
, 0, gnvs_size
+ dnvs_size
);
32 dnvs
= (char *)gnvs
+ gnvs_size
;
34 if (CONFIG(CONSOLE_CBMEM
))
35 gnvs
->cbmc
= (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE
);
38 BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE
, BS_ON_EXIT
, acpi_create_gnvs
, NULL
);
40 void *acpi_get_gnvs(void)
45 gnvs
= cbmem_find(CBMEM_ID_ACPI_GNVS
);
49 printk(BIOS_ERR
, "Unable to locate Global NVS\n");
53 void *acpi_get_device_nvs(void)
58 /* Implemented under platform. */
59 __weak
void soc_fill_gnvs(struct global_nvs
*gnvs_
) { }
60 __weak
void mainboard_fill_gnvs(struct global_nvs
*gnvs_
) { }
61 __weak
size_t size_of_dnvs(void) { return 0; }
63 /* Called from write_acpi_tables() only on normal boot path. */
64 void acpi_fill_gnvs(void)
66 const struct opregion gnvs_op
= OPREGION("GNVS", SYSTEMMEMORY
, (uintptr_t)gnvs
,
67 sizeof(struct global_nvs
));
68 const struct opregion dnvs_op
= OPREGION("DNVS", SYSTEMMEMORY
, (uintptr_t)dnvs
,
75 mainboard_fill_gnvs(gnvs
);
77 acpigen_write_scope("\\");
78 acpigen_write_opregion(&gnvs_op
);
80 acpigen_write_opregion(&dnvs_op
);
84 int acpi_reset_gnvs_for_wake(struct global_nvs
**gnvs_
)
89 /* Set unknown wake source */