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> |
Kyösti Mälkki | 37eb24b | 2021-01-11 18:40:37 +0200 | [diff] [blame^] | 7 | #include <soc/nvs.h> |
| 8 | #include <stdint.h> |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 9 | #include <string.h> |
| 10 | #include <types.h> |
Kyösti Mälkki | 66c6413 | 2020-12-19 16:19:44 +0200 | [diff] [blame] | 11 | #include <vendorcode/google/chromeos/gnvs.h> |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 12 | |
Kyösti Mälkki | 37eb24b | 2021-01-11 18:40:37 +0200 | [diff] [blame^] | 13 | static struct global_nvs *gnvs; |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 14 | |
| 15 | void *acpi_get_gnvs(void) |
| 16 | { |
| 17 | if (gnvs) |
| 18 | return gnvs; |
| 19 | |
| 20 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 21 | if (gnvs) |
| 22 | return gnvs; |
| 23 | |
| 24 | printk(BIOS_ERR, "Unable to locate Global NVS\n"); |
| 25 | return NULL; |
| 26 | } |
| 27 | |
Kyösti Mälkki | 4b4e995 | 2020-06-28 21:28:54 +0300 | [diff] [blame] | 28 | __weak void soc_fill_gnvs(struct global_nvs *gnvs_) { } |
Kyösti Mälkki | a9766c7 | 2020-06-29 02:56:49 +0300 | [diff] [blame] | 29 | __weak void mainboard_fill_gnvs(struct global_nvs *gnvs_) { } |
Kyösti Mälkki | 4b4e995 | 2020-06-28 21:28:54 +0300 | [diff] [blame] | 30 | |
Kyösti Mälkki | 37eb24b | 2021-01-11 18:40:37 +0200 | [diff] [blame^] | 31 | void acpi_create_gnvs(void) |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 32 | { |
| 33 | size_t gnvs_size; |
| 34 | |
Kyösti Mälkki | 37eb24b | 2021-01-11 18:40:37 +0200 | [diff] [blame^] | 35 | if (cbmem_find(CBMEM_ID_ACPI_GNVS)) |
| 36 | return; |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 37 | |
Kyösti Mälkki | 66c6413 | 2020-12-19 16:19:44 +0200 | [diff] [blame] | 38 | /* Match with OpRegion declared in global_nvs.asl. */ |
Kyösti Mälkki | 37eb24b | 2021-01-11 18:40:37 +0200 | [diff] [blame^] | 39 | gnvs_size = sizeof(struct global_nvs); |
Kyösti Mälkki | 66c6413 | 2020-12-19 16:19:44 +0200 | [diff] [blame] | 40 | if (gnvs_size < 0x100) |
| 41 | gnvs_size = 0x100; |
| 42 | if (gnvs_size > 0x1000) |
| 43 | gnvs_size = 0x2000; |
| 44 | else if (CONFIG(MAINBOARD_HAS_CHROMEOS)) |
| 45 | gnvs_size = 0x1000; |
| 46 | |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 47 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, gnvs_size); |
| 48 | if (!gnvs) |
Kyösti Mälkki | 37eb24b | 2021-01-11 18:40:37 +0200 | [diff] [blame^] | 49 | return; |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 50 | |
| 51 | memset(gnvs, 0, gnvs_size); |
| 52 | |
| 53 | if (CONFIG(CONSOLE_CBMEM)) |
Kyösti Mälkki | 37eb24b | 2021-01-11 18:40:37 +0200 | [diff] [blame^] | 54 | gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE); |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 55 | |
| 56 | if (CONFIG(CHROMEOS)) |
Kyösti Mälkki | 66c6413 | 2020-12-19 16:19:44 +0200 | [diff] [blame] | 57 | gnvs_assign_chromeos((u8 *)gnvs + GNVS_CHROMEOS_ACPI_OFFSET); |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 58 | } |
| 59 | |
Kyösti Mälkki | 2ab4a96 | 2020-06-30 11:41:47 +0300 | [diff] [blame] | 60 | void acpi_fill_gnvs(void) |
| 61 | { |
| 62 | if (!gnvs) |
| 63 | return; |
| 64 | |
| 65 | soc_fill_gnvs(gnvs); |
| 66 | mainboard_fill_gnvs(gnvs); |
Kyösti Mälkki | 91946c5 | 2020-06-30 11:42:52 +0300 | [diff] [blame] | 67 | |
| 68 | acpigen_write_scope("\\"); |
| 69 | acpigen_write_name_dword("NVSA", (uintptr_t)gnvs); |
| 70 | acpigen_pop_len(); |
Kyösti Mälkki | 2ab4a96 | 2020-06-30 11:41:47 +0300 | [diff] [blame] | 71 | } |