drivers/wifi: Remove unnecessary data structure copy
[coreboot2.git] / src / vendorcode / google / chromeos / gnvs.c
blob3d66aa3f79d3cc8761ac8a85c435d41540026ec8
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpi.h>
4 #include <acpi/acpigen.h>
5 #include <bootstate.h>
6 #include <types.h>
7 #include <string.h>
8 #include <stdlib.h>
9 #include <cbfs.h>
10 #include <cbmem.h>
11 #include <console/console.h>
12 #include <ec/google/chromeec/ec.h>
13 #include <fmap.h>
14 #include <security/vboot/vbnv.h>
15 #include <security/vboot/vboot_common.h>
16 #include <smbios.h>
18 #include "chromeos.h"
19 #include "gnvs.h"
21 static struct chromeos_acpi *chromeos_acpi;
23 static size_t chromeos_vpd_region(const char *region, uintptr_t *base)
25 struct region_device vpd;
27 if (fmap_locate_area_as_rdev(region, &vpd))
28 return 0;
30 *base = (uintptr_t)rdev_mmap_full(&vpd);
32 return region_device_sz(&vpd);
35 static void chromeos_init_chromeos_acpi(void *unused)
37 size_t vpd_size;
38 uintptr_t vpd_base = 0;
40 chromeos_acpi = cbmem_add(CBMEM_ID_ACPI_CNVS, sizeof(struct chromeos_acpi));
41 if (!chromeos_acpi)
42 return;
44 /* Retain CNVS contents on S3 resume path. */
45 if (acpi_is_wakeup_s3())
46 return;
48 vpd_size = chromeos_vpd_region("RO_VPD", &vpd_base);
49 if (vpd_size && vpd_base) {
50 chromeos_acpi->vpd_ro_base = vpd_base;
51 chromeos_acpi->vpd_ro_size = vpd_size;
54 vpd_size = chromeos_vpd_region("RW_VPD", &vpd_base);
55 if (vpd_size && vpd_base) {
56 chromeos_acpi->vpd_rw_base = vpd_base;
57 chromeos_acpi->vpd_rw_size = vpd_size;
61 BOOT_STATE_INIT_ENTRY(BS_PRE_DEVICE, BS_ON_EXIT, chromeos_init_chromeos_acpi, NULL);
63 void chromeos_set_me_hash(u32 *hash, int len)
65 if ((len*sizeof(u32)) > sizeof(chromeos_acpi->mehh))
66 return;
68 /* Copy to NVS. */
69 if (chromeos_acpi)
70 memcpy(chromeos_acpi->mehh, hash, len*sizeof(u32));
73 void chromeos_set_ramoops(void *ram_oops, size_t size)
75 if (!chromeos_acpi)
76 return;
78 printk(BIOS_DEBUG, "Ramoops buffer: 0x%zx@%p.\n", size, ram_oops);
79 chromeos_acpi->ramoops_base = (uintptr_t)ram_oops;
80 chromeos_acpi->ramoops_len = size;
83 void smbios_type0_bios_version(uintptr_t address)
85 if (!chromeos_acpi)
86 return;
87 /* Location of smbios_type0.bios_version() string filled with spaces. */
88 chromeos_acpi->vbt10 = address;
91 void acpi_fill_cnvs(void)
93 const struct opregion cnvs_op = OPREGION("CNVS", SYSTEMMEMORY, (uintptr_t)chromeos_acpi,
94 sizeof(*chromeos_acpi));
96 if (!chromeos_acpi)
97 return;
99 acpigen_write_scope("\\");
100 acpigen_write_opregion(&cnvs_op);
101 acpigen_pop_len();
103 chromeos_acpi_gpio_generate();