soc/intel/alderlake: Add ADL-P 4+4 with 28W TDP
[coreboot.git] / src / acpi / gnvs.c
blobd1bbb019cc90b6806100426afeed353f95a896ce
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;
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)
42 if (gnvs)
43 return gnvs;
45 gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
46 if (gnvs)
47 return gnvs;
49 printk(BIOS_ERR, "Unable to locate Global NVS\n");
50 return NULL;
53 void *acpi_get_device_nvs(void)
55 return dnvs;
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,
69 size_of_dnvs());
71 if (!gnvs)
72 return;
74 soc_fill_gnvs(gnvs);
75 mainboard_fill_gnvs(gnvs);
77 acpigen_write_scope("\\");
78 acpigen_write_opregion(&gnvs_op);
79 if (dnvs)
80 acpigen_write_opregion(&dnvs_op);
81 acpigen_pop_len();
84 int acpi_reset_gnvs_for_wake(struct global_nvs **gnvs_)
86 if (!gnvs)
87 return -1;
89 /* Set unknown wake source */
90 gnvs->pm1i = -1;
91 gnvs->gpei = -1;
93 *gnvs_ = gnvs;
94 return 0;