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 | |
Kyösti Mälkki | 37eb24b | 2021-01-11 18:40:37 +0200 | [diff] [blame] | 15 | void acpi_create_gnvs(void) |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 16 | { |
| 17 | size_t gnvs_size; |
| 18 | |
Kyösti Mälkki | 62d6f1f | 2021-01-27 10:13:33 +0200 | [diff] [blame] | 19 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 20 | if (gnvs) |
Kyösti Mälkki | 37eb24b | 2021-01-11 18:40:37 +0200 | [diff] [blame] | 21 | return; |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 22 | |
Kyösti Mälkki | 66c6413 | 2020-12-19 16:19:44 +0200 | [diff] [blame] | 23 | /* Match with OpRegion declared in global_nvs.asl. */ |
Kyösti Mälkki | 37eb24b | 2021-01-11 18:40:37 +0200 | [diff] [blame] | 24 | gnvs_size = sizeof(struct global_nvs); |
Kyösti Mälkki | 66c6413 | 2020-12-19 16:19:44 +0200 | [diff] [blame] | 25 | if (gnvs_size < 0x100) |
| 26 | gnvs_size = 0x100; |
Kyösti Mälkki | 4abc731 | 2021-01-12 17:46:30 +0200 | [diff] [blame] | 27 | if (CONFIG(ACPI_HAS_DEVICE_NVS)) |
Kyösti Mälkki | 66c6413 | 2020-12-19 16:19:44 +0200 | [diff] [blame] | 28 | gnvs_size = 0x2000; |
Kyösti Mälkki | 84d10cc | 2021-02-10 17:53:34 +0200 | [diff] [blame] | 29 | else if (CONFIG(CHROMEOS_NVS)) |
Kyösti Mälkki | 66c6413 | 2020-12-19 16:19:44 +0200 | [diff] [blame] | 30 | gnvs_size = 0x1000; |
| 31 | |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 32 | gnvs = cbmem_add(CBMEM_ID_ACPI_GNVS, gnvs_size); |
| 33 | if (!gnvs) |
Kyösti Mälkki | 37eb24b | 2021-01-11 18:40:37 +0200 | [diff] [blame] | 34 | return; |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 35 | |
| 36 | memset(gnvs, 0, gnvs_size); |
| 37 | |
| 38 | if (CONFIG(CONSOLE_CBMEM)) |
Kyösti Mälkki | 37eb24b | 2021-01-11 18:40:37 +0200 | [diff] [blame] | 39 | gnvs->cbmc = (uintptr_t)cbmem_find(CBMEM_ID_CONSOLE); |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 40 | |
Kyösti Mälkki | 8a1fcf4 | 2021-02-12 18:43:36 +0200 | [diff] [blame] | 41 | if (CONFIG(CHROMEOS_NVS)) { |
| 42 | chromeos_acpi_t *init = (void *)((u8 *)gnvs + GNVS_CHROMEOS_ACPI_OFFSET); |
| 43 | chromeos_init_chromeos_acpi(init); |
| 44 | } |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 45 | } |
| 46 | |
Kyösti Mälkki | 62d6f1f | 2021-01-27 10:13:33 +0200 | [diff] [blame] | 47 | void *acpi_get_gnvs(void) |
| 48 | { |
| 49 | if (gnvs) |
| 50 | return gnvs; |
| 51 | |
| 52 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 53 | if (gnvs) |
| 54 | return gnvs; |
| 55 | |
| 56 | printk(BIOS_ERR, "Unable to locate Global NVS\n"); |
| 57 | return NULL; |
| 58 | } |
| 59 | |
Kyösti Mälkki | 4abc731 | 2021-01-12 17:46:30 +0200 | [diff] [blame] | 60 | void *acpi_get_device_nvs(void) |
| 61 | { |
| 62 | return (u8 *)gnvs + GNVS_DEVICE_NVS_OFFSET; |
| 63 | } |
| 64 | |
Kyösti Mälkki | 62d6f1f | 2021-01-27 10:13:33 +0200 | [diff] [blame] | 65 | /* Implemented under platform. */ |
| 66 | __weak void soc_fill_gnvs(struct global_nvs *gnvs_) { } |
| 67 | __weak void mainboard_fill_gnvs(struct global_nvs *gnvs_) { } |
| 68 | |
| 69 | /* Called from write_acpi_tables() only on normal boot path. */ |
Kyösti Mälkki | 2ab4a96 | 2020-06-30 11:41:47 +0300 | [diff] [blame] | 70 | void acpi_fill_gnvs(void) |
| 71 | { |
Kyösti Mälkki | 2ad598f | 2021-03-16 13:02:34 +0200 | [diff] [blame^] | 72 | const struct opregion gnvs_op = OPREGION("GNVS", SYSTEMMEMORY, (uintptr_t)gnvs, 0x100); |
| 73 | const struct opregion cnvs_op = OPREGION("CNVS", SYSTEMMEMORY, |
| 74 | (uintptr_t)gnvs + GNVS_CHROMEOS_ACPI_OFFSET, 0xf00); |
| 75 | const struct opregion dnvs_op = OPREGION("DNVS", SYSTEMMEMORY, |
| 76 | (uintptr_t)gnvs + GNVS_DEVICE_NVS_OFFSET, 0x1000); |
| 77 | |
Kyösti Mälkki | 2ab4a96 | 2020-06-30 11:41:47 +0300 | [diff] [blame] | 78 | if (!gnvs) |
| 79 | return; |
| 80 | |
| 81 | soc_fill_gnvs(gnvs); |
| 82 | mainboard_fill_gnvs(gnvs); |
Kyösti Mälkki | 91946c5 | 2020-06-30 11:42:52 +0300 | [diff] [blame] | 83 | |
| 84 | acpigen_write_scope("\\"); |
Kyösti Mälkki | 2ad598f | 2021-03-16 13:02:34 +0200 | [diff] [blame^] | 85 | acpigen_write_opregion(&gnvs_op); |
| 86 | |
| 87 | if (CONFIG(CHROMEOS_NVS)) |
| 88 | acpigen_write_opregion(&cnvs_op); |
| 89 | |
| 90 | if (CONFIG(ACPI_HAS_DEVICE_NVS)) |
| 91 | acpigen_write_opregion(&dnvs_op); |
| 92 | |
Kyösti Mälkki | 91946c5 | 2020-06-30 11:42:52 +0300 | [diff] [blame] | 93 | acpigen_pop_len(); |
Kyösti Mälkki | 2ab4a96 | 2020-06-30 11:41:47 +0300 | [diff] [blame] | 94 | } |
Kyösti Mälkki | 4de1a31 | 2021-01-15 05:58:42 +0200 | [diff] [blame] | 95 | |
| 96 | int acpi_reset_gnvs_for_wake(struct global_nvs **gnvs_) |
| 97 | { |
| 98 | if (!gnvs) |
| 99 | return -1; |
| 100 | |
| 101 | /* Set unknown wake source */ |
| 102 | gnvs->pm1i = -1; |
| 103 | gnvs->gpei = -1; |
| 104 | |
| 105 | *gnvs_ = gnvs; |
| 106 | return 0; |
| 107 | } |