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 | ae7ac8a | 2021-01-12 15:23:25 +0200 | [diff] [blame] | 29 | else if (CONFIG(CHROMEOS)) |
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 | |
| 41 | if (CONFIG(CHROMEOS)) |
Kyösti Mälkki | 66c6413 | 2020-12-19 16:19:44 +0200 | [diff] [blame] | 42 | gnvs_assign_chromeos((u8 *)gnvs + GNVS_CHROMEOS_ACPI_OFFSET); |
Kyösti Mälkki | e37459e | 2020-06-17 01:04:44 +0300 | [diff] [blame] | 43 | } |
| 44 | |
Kyösti Mälkki | 62d6f1f | 2021-01-27 10:13:33 +0200 | [diff] [blame] | 45 | void *acpi_get_gnvs(void) |
| 46 | { |
| 47 | if (gnvs) |
| 48 | return gnvs; |
| 49 | |
| 50 | gnvs = cbmem_find(CBMEM_ID_ACPI_GNVS); |
| 51 | if (gnvs) |
| 52 | return gnvs; |
| 53 | |
| 54 | printk(BIOS_ERR, "Unable to locate Global NVS\n"); |
| 55 | return NULL; |
| 56 | } |
| 57 | |
Kyösti Mälkki | 4abc731 | 2021-01-12 17:46:30 +0200 | [diff] [blame] | 58 | void *acpi_get_device_nvs(void) |
| 59 | { |
| 60 | return (u8 *)gnvs + GNVS_DEVICE_NVS_OFFSET; |
| 61 | } |
| 62 | |
Kyösti Mälkki | 62d6f1f | 2021-01-27 10:13:33 +0200 | [diff] [blame] | 63 | /* Implemented under platform. */ |
| 64 | __weak void soc_fill_gnvs(struct global_nvs *gnvs_) { } |
| 65 | __weak void mainboard_fill_gnvs(struct global_nvs *gnvs_) { } |
| 66 | |
| 67 | /* Called from write_acpi_tables() only on normal boot path. */ |
Kyösti Mälkki | 2ab4a96 | 2020-06-30 11:41:47 +0300 | [diff] [blame] | 68 | void acpi_fill_gnvs(void) |
| 69 | { |
| 70 | if (!gnvs) |
| 71 | return; |
| 72 | |
| 73 | soc_fill_gnvs(gnvs); |
| 74 | mainboard_fill_gnvs(gnvs); |
Kyösti Mälkki | 91946c5 | 2020-06-30 11:42:52 +0300 | [diff] [blame] | 75 | |
| 76 | acpigen_write_scope("\\"); |
Kyösti Mälkki | fa5f9b5 | 2021-01-19 14:12:19 +0200 | [diff] [blame] | 77 | acpigen_write_name_dword("NVB0", (uintptr_t)gnvs); |
Kyösti Mälkki | ae7ac8a | 2021-01-12 15:23:25 +0200 | [diff] [blame] | 78 | acpigen_write_name_dword("NVS0", 0x100); |
Kyösti Mälkki | 91946c5 | 2020-06-30 11:42:52 +0300 | [diff] [blame] | 79 | acpigen_pop_len(); |
Kyösti Mälkki | 4abc731 | 2021-01-12 17:46:30 +0200 | [diff] [blame] | 80 | |
Kyösti Mälkki | ae7ac8a | 2021-01-12 15:23:25 +0200 | [diff] [blame] | 81 | if (CONFIG(CHROMEOS)) { |
| 82 | acpigen_write_scope("\\"); |
| 83 | acpigen_write_name_dword("NVB2", (uintptr_t)gnvs + GNVS_CHROMEOS_ACPI_OFFSET); |
| 84 | acpigen_write_name_dword("NVS2", 0xf00); |
| 85 | acpigen_pop_len(); |
| 86 | } |
| 87 | |
Kyösti Mälkki | 4abc731 | 2021-01-12 17:46:30 +0200 | [diff] [blame] | 88 | if (CONFIG(ACPI_HAS_DEVICE_NVS)) { |
| 89 | acpigen_write_scope("\\"); |
Kyösti Mälkki | fa5f9b5 | 2021-01-19 14:12:19 +0200 | [diff] [blame] | 90 | acpigen_write_name_dword("NVB1", (uintptr_t)gnvs + GNVS_DEVICE_NVS_OFFSET); |
| 91 | acpigen_write_name_dword("NVS1", 0x1000); |
Kyösti Mälkki | 4abc731 | 2021-01-12 17:46:30 +0200 | [diff] [blame] | 92 | acpigen_pop_len(); |
| 93 | } |
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 | } |