2020-06-17 00:04:44 +02:00
|
|
|
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
|
|
|
|
#include <acpi/acpi_gnvs.h>
|
|
|
|
#include <acpi/acpigen.h>
|
|
|
|
#include <cbmem.h>
|
|
|
|
#include <console/console.h>
|
2021-01-11 17:40:37 +01:00
|
|
|
#include <soc/nvs.h>
|
|
|
|
#include <stdint.h>
|
2020-06-17 00:04:44 +02:00
|
|
|
#include <string.h>
|
|
|
|
#include <types.h>
|
2020-12-19 15:19:44 +01:00
|
|
|
#include <vendorcode/google/chromeos/gnvs.h>
|
2020-06-17 00:04:44 +02:00
|
|
|
|
2021-01-11 17:40:37 +01:00
|
|
|
static struct global_nvs *gnvs;
|
2020-06-17 00:04:44 +02:00
|
|
|
|
|
|
|
void *acpi_get_gnvs(void)
|
|
|
|
{
|
|
|
|
if (gnvs)
|
|
|
|
return gnvs;
|
|
|
|
|
|
|
|
gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
|
|
|
|
if (gnvs)
|
|
|
|
return gnvs;
|
|
|
|
|
|
|
|
printk(BIOS_ERR, "Unable to locate Global NVS\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2020-06-28 20:28:54 +02:00
|
|
|
__weak void soc_fill_gnvs(struct global_nvs *gnvs_) { }
|
2020-06-29 01:56:49 +02:00
|
|
|
__weak void mainboard_fill_gnvs(struct global_nvs *gnvs_) { }
|
2020-06-28 20:28:54 +02:00
|
|
|
|
2021-01-11 17:40:37 +01:00
|
|
|
void acpi_create_gnvs(void)
|
2020-06-17 00:04:44 +02:00
|
|
|
{
|
|
|
|
size_t gnvs_size;
|
|
|
|
|
2021-01-11 17:40:37 +01:00
|
|
|
if (cbmem_find(CBMEM_ID_ACPI_GNVS))
|
|
|
|
return;
|
2020-06-17 00:04:44 +02:00
|
|
|
|
2020-12-19 15:19:44 +01:00
|
|
|
/* Match with OpRegion declared in global_nvs.asl. */
|
2021-01-11 17:40:37 +01:00
|
|
|
gnvs_size = sizeof(struct global_nvs);
|
2020-12-19 15:19:44 +01:00
|
|
|
if (gnvs_size < 0x100)
|
|
|
|
gnvs_size = 0x100;
|
2021-01-12 16:46:30 +01:00
|
|
|
if (CONFIG(ACPI_HAS_DEVICE_NVS))
|
2020-12-19 15:19:44 +01:00
|
|
|
gnvs_size = 0x2000;
|
2021-01-12 14:23:25 +01:00
|
|
|
else if (CONFIG(CHROMEOS))
|
2020-12-19 15:19:44 +01:00
|
|
|
gnvs_size = 0x1000;
|
|
|
|
|
2020-06-17 00:04:44 +02:00
|
|
|
gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, gnvs_size);
|
|
|
|
if (!gnvs)
|
2021-01-11 17:40:37 +01:00
|
|
|
return;
|
2020-06-17 00:04:44 +02:00
|
|
|
|
|
|
|
memset(gnvs, 0, gnvs_size);
|
|
|
|
|
|
|
|
if (CONFIG(CONSOLE_CBMEM))
|
2021-01-11 17:40:37 +01:00
|
|
|
gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
|
2020-06-17 00:04:44 +02:00
|
|
|
|
|
|
|
if (CONFIG(CHROMEOS))
|
2020-12-19 15:19:44 +01:00
|
|
|
gnvs_assign_chromeos((u8 *)gnvs + GNVS_CHROMEOS_ACPI_OFFSET);
|
2020-06-17 00:04:44 +02:00
|
|
|
}
|
|
|
|
|
2021-01-12 16:46:30 +01:00
|
|
|
void *acpi_get_device_nvs(void)
|
|
|
|
{
|
|
|
|
return (u8 *)gnvs + GNVS_DEVICE_NVS_OFFSET;
|
|
|
|
}
|
|
|
|
|
2020-06-30 10:41:47 +02:00
|
|
|
void acpi_fill_gnvs(void)
|
|
|
|
{
|
|
|
|
if (!gnvs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
soc_fill_gnvs(gnvs);
|
|
|
|
mainboard_fill_gnvs(gnvs);
|
2020-06-30 10:42:52 +02:00
|
|
|
|
|
|
|
acpigen_write_scope("\\");
|
2021-01-19 13:12:19 +01:00
|
|
|
acpigen_write_name_dword("NVB0", (uintptr_t)gnvs);
|
2021-01-12 14:23:25 +01:00
|
|
|
acpigen_write_name_dword("NVS0", 0x100);
|
2020-06-30 10:42:52 +02:00
|
|
|
acpigen_pop_len();
|
2021-01-12 16:46:30 +01:00
|
|
|
|
2021-01-12 14:23:25 +01:00
|
|
|
if (CONFIG(CHROMEOS)) {
|
|
|
|
acpigen_write_scope("\\");
|
|
|
|
acpigen_write_name_dword("NVB2", (uintptr_t)gnvs + GNVS_CHROMEOS_ACPI_OFFSET);
|
|
|
|
acpigen_write_name_dword("NVS2", 0xf00);
|
|
|
|
acpigen_pop_len();
|
|
|
|
}
|
|
|
|
|
2021-01-12 16:46:30 +01:00
|
|
|
if (CONFIG(ACPI_HAS_DEVICE_NVS)) {
|
|
|
|
acpigen_write_scope("\\");
|
2021-01-19 13:12:19 +01:00
|
|
|
acpigen_write_name_dword("NVB1", (uintptr_t)gnvs + GNVS_DEVICE_NVS_OFFSET);
|
|
|
|
acpigen_write_name_dword("NVS1", 0x1000);
|
2021-01-12 16:46:30 +01:00
|
|
|
acpigen_pop_len();
|
|
|
|
}
|
2020-06-30 10:41:47 +02:00
|
|
|
}
|