mb/google/nissa/var/pujjo: Add new supported memory part
[coreboot2.git] / src / acpi / gnvs.c
blob1e5d746e59656593fdd66715a8b7af0759a8bb81
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpi_gnvs.h>
4 #include <acpi/acpigen.h>
5 #include <bootstate.h>
6 #include <cbmem.h>
7 #include <console/console.h>
8 #include <soc/nvs.h>
9 #include <string.h>
10 #include <types.h>
12 static struct global_nvs *gnvs;
13 static void *dnvs;
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);
21 if (gnvs)
22 return;
24 /* Allocate for both GNVS and DNVS OpRegions. */
25 gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, gnvs_size + dnvs_size);
26 if (!gnvs)
27 return;
29 memset(gnvs, 0, gnvs_size + dnvs_size);
31 if (dnvs_size)
32 dnvs = (char *)gnvs + gnvs_size;
35 BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT, acpi_create_gnvs, NULL);
37 void *acpi_get_gnvs(void)
39 if (gnvs)
40 return gnvs;
42 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
43 if (gnvs)
44 return gnvs;
46 printk(BIOS_ERR, "Unable to locate Global NVS\n");
47 return NULL;
50 void *acpi_get_device_nvs(void)
52 return dnvs;
55 /* Implemented under platform. */
56 __weak void soc_fill_gnvs(struct global_nvs *gnvs_) { }
57 __weak void mainboard_fill_gnvs(struct global_nvs *gnvs_) { }
58 __weak size_t size_of_dnvs(void) { return 0; }
60 /* Called from write_acpi_tables() only on normal boot path. */
61 void acpi_fill_gnvs(void)
63 const struct opregion gnvs_op = OPREGION("GNVS", SYSTEMMEMORY, (uintptr_t)gnvs,
64 sizeof(struct global_nvs));
65 const struct opregion dnvs_op = OPREGION("DNVS", SYSTEMMEMORY, (uintptr_t)dnvs,
66 size_of_dnvs());
68 if (!gnvs)
69 return;
71 soc_fill_gnvs(gnvs);
72 mainboard_fill_gnvs(gnvs);
74 acpigen_write_scope("\\");
75 acpigen_write_opregion(&gnvs_op);
76 if (dnvs)
77 acpigen_write_opregion(&dnvs_op);
78 acpigen_pop_len();
81 int acpi_reset_gnvs_for_wake(struct global_nvs **gnvs_)
83 if (!gnvs)
84 return -1;
86 /* Set unknown wake source */
87 gnvs->pm1i = -1;
88 gnvs->gpei = -1;
90 *gnvs_ = gnvs;
91 return 0;