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>
|
|
|
|
#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
|
|
|
|
|
|
|
static void *gnvs;
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gnvs_assign_cbmc(void)
|
|
|
|
{
|
2020-06-17 12:45:16 +02:00
|
|
|
uint32_t *gnvs_cbmc = gnvs_cbmc_ptr(gnvs);
|
2020-06-17 00:04:44 +02:00
|
|
|
if (gnvs_cbmc)
|
|
|
|
*gnvs_cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE);
|
|
|
|
}
|
|
|
|
|
2020-06-28 15:33:33 +02:00
|
|
|
/* Needs implementation in platform code. */
|
2020-06-17 12:45:16 +02:00
|
|
|
__weak uint32_t *gnvs_cbmc_ptr(struct global_nvs *gnvs_)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
2020-06-17 00:04:44 +02:00
|
|
|
void *gnvs_get_or_create(void)
|
|
|
|
{
|
|
|
|
size_t gnvs_size;
|
|
|
|
|
|
|
|
if (gnvs)
|
|
|
|
return gnvs;
|
|
|
|
|
|
|
|
gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
|
|
|
|
if (gnvs)
|
|
|
|
return gnvs;
|
|
|
|
|
|
|
|
gnvs_size = gnvs_size_of_array();
|
2020-06-17 12:45:16 +02:00
|
|
|
if (!gnvs_size)
|
|
|
|
return NULL;
|
2020-06-17 00:04:44 +02:00
|
|
|
|
2020-12-19 15:19:44 +01:00
|
|
|
/* Match with OpRegion declared in global_nvs.asl. */
|
|
|
|
if (gnvs_size < 0x100)
|
|
|
|
gnvs_size = 0x100;
|
|
|
|
if (gnvs_size > 0x1000)
|
|
|
|
gnvs_size = 0x2000;
|
|
|
|
else if (CONFIG(MAINBOARD_HAS_CHROMEOS))
|
|
|
|
gnvs_size = 0x1000;
|
|
|
|
|
2020-06-17 00:04:44 +02:00
|
|
|
gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, gnvs_size);
|
|
|
|
if (!gnvs)
|
2020-06-17 12:45:16 +02:00
|
|
|
return NULL;
|
2020-06-17 00:04:44 +02:00
|
|
|
|
|
|
|
memset(gnvs, 0, gnvs_size);
|
|
|
|
|
|
|
|
if (CONFIG(CONSOLE_CBMEM))
|
|
|
|
gnvs_assign_cbmc();
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
return gnvs;
|
|
|
|
}
|
|
|
|
|
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("\\");
|
|
|
|
acpigen_write_name_dword("NVSA", (uintptr_t)gnvs);
|
|
|
|
acpigen_pop_len();
|
2020-06-30 10:41:47 +02:00
|
|
|
}
|