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>
|
|
|
|
|
2021-01-11 17:40:37 +01:00
|
|
|
static struct global_nvs *gnvs;
|
2021-03-16 18:02:26 +01:00
|
|
|
static void *dnvs;
|
2020-06-17 00:04:44 +02:00
|
|
|
|
2021-01-11 17:40:37 +01:00
|
|
|
void acpi_create_gnvs(void)
|
2020-06-17 00:04:44 +02:00
|
|
|
{
|
2021-03-16 18:02:26 +01:00
|
|
|
const size_t gnvs_size = ALIGN_UP(sizeof(struct global_nvs), sizeof(uint64_t));
|
|
|
|
const size_t dnvs_size = ALIGN_UP(size_of_dnvs(), sizeof(uint64_t));
|
2020-06-17 00:04:44 +02:00
|
|
|
|
2021-01-27 09:13:33 +01:00
|
|
|
gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS);
|
|
|
|
if (gnvs)
|
2021-01-11 17:40:37 +01:00
|
|
|
return;
|
2020-06-17 00:04:44 +02:00
|
|
|
|
2021-03-16 18:02:26 +01:00
|
|
|
/* Allocate for both GNVS and DNVS OpRegions. */
|
|
|
|
gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, gnvs_size + dnvs_size);
|
2020-06-17 00:04:44 +02:00
|
|
|
if (!gnvs)
|
2021-01-11 17:40:37 +01:00
|
|
|
return;
|
2020-06-17 00:04:44 +02:00
|
|
|
|
2021-03-16 18:02:26 +01:00
|
|
|
memset(gnvs, 0, gnvs_size + dnvs_size);
|
|
|
|
|
|
|
|
if (dnvs_size)
|
|
|
|
dnvs = (char *)gnvs + gnvs_size;
|
2020-06-17 00:04:44 +02:00
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-01-27 09:13:33 +01: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;
|
|
|
|
}
|
|
|
|
|
2021-01-12 16:46:30 +01:00
|
|
|
void *acpi_get_device_nvs(void)
|
|
|
|
{
|
2021-03-16 18:02:26 +01:00
|
|
|
return dnvs;
|
2021-01-12 16:46:30 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 09:13:33 +01:00
|
|
|
/* Implemented under platform. */
|
|
|
|
__weak void soc_fill_gnvs(struct global_nvs *gnvs_) { }
|
|
|
|
__weak void mainboard_fill_gnvs(struct global_nvs *gnvs_) { }
|
2021-03-16 18:02:26 +01:00
|
|
|
__weak size_t size_of_dnvs(void) { return 0; }
|
2021-01-27 09:13:33 +01:00
|
|
|
|
|
|
|
/* Called from write_acpi_tables() only on normal boot path. */
|
2020-06-30 10:41:47 +02:00
|
|
|
void acpi_fill_gnvs(void)
|
|
|
|
{
|
2021-03-16 18:02:26 +01:00
|
|
|
const struct opregion gnvs_op = OPREGION("GNVS", SYSTEMMEMORY, (uintptr_t)gnvs,
|
|
|
|
sizeof(struct global_nvs));
|
|
|
|
const struct opregion dnvs_op = OPREGION("DNVS", SYSTEMMEMORY, (uintptr_t)dnvs,
|
|
|
|
size_of_dnvs());
|
2021-03-16 12:02:34 +01:00
|
|
|
|
2020-06-30 10:41:47 +02:00
|
|
|
if (!gnvs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
soc_fill_gnvs(gnvs);
|
|
|
|
mainboard_fill_gnvs(gnvs);
|
2020-06-30 10:42:52 +02:00
|
|
|
|
|
|
|
acpigen_write_scope("\\");
|
2021-03-16 12:02:34 +01:00
|
|
|
acpigen_write_opregion(&gnvs_op);
|
2021-03-16 18:02:26 +01:00
|
|
|
if (dnvs)
|
2021-03-16 12:02:34 +01:00
|
|
|
acpigen_write_opregion(&dnvs_op);
|
|
|
|
acpigen_pop_len();
|
2020-06-30 10:41:47 +02:00
|
|
|
}
|
2021-01-15 04:58:42 +01:00
|
|
|
|
|
|
|
int acpi_reset_gnvs_for_wake(struct global_nvs **gnvs_)
|
|
|
|
{
|
|
|
|
if (!gnvs)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
/* Set unknown wake source */
|
|
|
|
gnvs->pm1i = -1;
|
|
|
|
gnvs->gpei = -1;
|
|
|
|
|
|
|
|
*gnvs_ = gnvs;
|
|
|
|
return 0;
|
|
|
|
}
|