Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <acpi/acpi_gnvs.h> |
| 4 | #include <acpi/acpigen.h> |
| 5 | #include <cbmem.h> |
| 6 | #include <console/console.h> |
| 7 | #include <string.h> |
| 8 | #include <types.h> |
| 9 | |
| 10 | static void *gnvs; |
| 11 | |
| 12 | void *acpi_get_gnvs(void) |
| 13 | { |
| 14 | if (gnvs) |
| 15 | return gnvs; |
| 16 | |
| 17 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 18 | if (gnvs) |
| 19 | return gnvs; |
| 20 | |
| 21 | printk(BIOS_ERR, "Unable to locate Global NVS\n"); |
| 22 | return NULL; |
| 23 | } |
| 24 | |
| 25 | static void gnvs_assign_cbmc(void) |
| 26 | { |
Kyösti Mälkki | e0183d6 | 2020-06-17 13:45:16 +0300 | [diff] [blame] | 27 | uint32_t *gnvs_cbmc = gnvs_cbmc_ptr(gnvs); |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 28 | if (gnvs_cbmc) |
| 29 | *gnvs_cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE); |
| 30 | } |
| 31 | |
Kyösti Mälkki | 3139c8d | 2020-06-28 16:33:33 +0300 | [diff] [blame] | 32 | /* Needs implementation in platform code. */ |
Kyösti Mälkki | e0183d6 | 2020-06-17 13:45:16 +0300 | [diff] [blame] | 33 | __weak uint32_t *gnvs_cbmc_ptr(struct global_nvs *gnvs_) |
| 34 | { |
| 35 | return NULL; |
| 36 | } |
| 37 | |
Kyösti Mälkki | 4b4e995 | 2020-06-28 21:28:54 +0300 | [diff] [blame] | 38 | __weak void soc_fill_gnvs(struct global_nvs *gnvs_) { } |
Kyösti Mälkki | a9766c7 | 2020-06-29 02:56:49 +0300 | [diff] [blame] | 39 | __weak void mainboard_fill_gnvs(struct global_nvs *gnvs_) { } |
Kyösti Mälkki | 4b4e995 | 2020-06-28 21:28:54 +0300 | [diff] [blame] | 40 | |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 41 | void *gnvs_get_or_create(void) |
| 42 | { |
| 43 | size_t gnvs_size; |
| 44 | |
| 45 | if (gnvs) |
| 46 | return gnvs; |
| 47 | |
| 48 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 49 | if (gnvs) |
| 50 | return gnvs; |
| 51 | |
| 52 | gnvs_size = gnvs_size_of_array(); |
Kyösti Mälkki | e0183d6 | 2020-06-17 13:45:16 +0300 | [diff] [blame] | 53 | if (!gnvs_size) |
| 54 | return NULL; |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 55 | |
| 56 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, gnvs_size); |
| 57 | if (!gnvs) |
Kyösti Mälkki | e0183d6 | 2020-06-17 13:45:16 +0300 | [diff] [blame] | 58 | return NULL; |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 59 | |
| 60 | memset(gnvs, 0, gnvs_size); |
| 61 | |
| 62 | if (CONFIG(CONSOLE_CBMEM)) |
| 63 | gnvs_assign_cbmc(); |
| 64 | |
| 65 | if (CONFIG(CHROMEOS)) |
| 66 | gnvs_assign_chromeos(); |
| 67 | |
| 68 | return gnvs; |
| 69 | } |
| 70 | |
| 71 | void acpi_inject_nvsa(void) |
| 72 | { |
Kyösti Mälkki | e0183d6 | 2020-06-17 13:45:16 +0300 | [diff] [blame] | 73 | if (!gnvs) |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 74 | return; |
| 75 | |
| 76 | acpigen_write_scope("\\"); |
Kyösti Mälkki | e0183d6 | 2020-06-17 13:45:16 +0300 | [diff] [blame] | 77 | acpigen_write_name_dword("NVSA", (uintptr_t)gnvs); |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 78 | acpigen_pop_len(); |
| 79 | } |
Kyösti Mälkki | 2ab4a96 | 2020-06-30 11:41:47 +0300 | [diff] [blame^] | 80 | |
| 81 | void acpi_fill_gnvs(void) |
| 82 | { |
| 83 | if (!gnvs) |
| 84 | return; |
| 85 | |
| 86 | soc_fill_gnvs(gnvs); |
| 87 | mainboard_fill_gnvs(gnvs); |
| 88 | } |