Elyes HAOUAS | c4b7027 | 2020-05-13 11:42:12 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
Bora Guvendik | 3a1a037 | 2020-03-09 18:20:07 -0700 | [diff] [blame] | 2 | |
Furquan Shaikh | 76cedd2 | 2020-05-02 10:24:23 -0700 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Bora Guvendik | 3a1a037 | 2020-03-09 18:20:07 -0700 | [diff] [blame] | 4 | #include <baseboard/variants.h> |
Tim Wawrzynczak | d8bff38 | 2020-03-19 12:19:38 -0600 | [diff] [blame] | 5 | #include <baseboard/gpio.h> |
Kyösti Mälkki | be7692a | 2021-11-03 17:54:14 +0200 | [diff] [blame^] | 6 | #include <bootmode.h> |
Bora Guvendik | 3a1a037 | 2020-03-09 18:20:07 -0700 | [diff] [blame] | 7 | #include <boot/coreboot_tables.h> |
| 8 | #include <gpio.h> |
| 9 | #include <soc/gpio.h> |
| 10 | #include <variant/gpio.h> |
| 11 | #include <vendorcode/google/chromeos/chromeos.h> |
| 12 | #include <security/tpm/tss.h> |
| 13 | #include <device/device.h> |
| 14 | #include <intelblocks/pmclib.h> |
| 15 | #include <soc/pmc.h> |
| 16 | #include <soc/pci_devs.h> |
| 17 | |
Bora Guvendik | 3a1a037 | 2020-03-09 18:20:07 -0700 | [diff] [blame] | 18 | enum rec_mode_state { |
| 19 | REC_MODE_UNINITIALIZED, |
| 20 | REC_MODE_NOT_REQUESTED, |
| 21 | REC_MODE_REQUESTED, |
| 22 | }; |
| 23 | |
| 24 | void fill_lb_gpios(struct lb_gpios *gpios) |
| 25 | { |
| 26 | struct lb_gpio chromeos_gpios[] = { |
| 27 | {-1, ACTIVE_HIGH, get_lid_switch(), "lid"}, |
| 28 | {-1, ACTIVE_HIGH, 0, "power"}, |
| 29 | {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"}, |
| 30 | {-1, ACTIVE_HIGH, 0, "EC in RW"}, |
| 31 | }; |
| 32 | lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios)); |
| 33 | } |
| 34 | |
| 35 | static int cros_get_gpio_value(int type) |
| 36 | { |
| 37 | const struct cros_gpio *cros_gpios; |
| 38 | size_t i, num_gpios = 0; |
| 39 | |
| 40 | cros_gpios = variant_cros_gpios(&num_gpios); |
| 41 | |
| 42 | for (i = 0; i < num_gpios; i++) { |
| 43 | const struct cros_gpio *gpio = &cros_gpios[i]; |
| 44 | if (gpio->type == type) { |
| 45 | int state = gpio_get(gpio->gpio_num); |
| 46 | if (gpio->polarity == CROS_GPIO_ACTIVE_LOW) |
| 47 | return !state; |
| 48 | else |
| 49 | return state; |
| 50 | } |
| 51 | } |
| 52 | return 0; |
| 53 | } |
| 54 | |
| 55 | void mainboard_chromeos_acpi_generate(void) |
| 56 | { |
| 57 | const struct cros_gpio *cros_gpios; |
| 58 | size_t num_gpios = 0; |
| 59 | |
| 60 | cros_gpios = variant_cros_gpios(&num_gpios); |
| 61 | |
| 62 | chromeos_acpi_gpio_generate(cros_gpios, num_gpios); |
| 63 | } |
| 64 | |
| 65 | int get_write_protect_state(void) |
| 66 | { |
| 67 | return cros_get_gpio_value(CROS_GPIO_WP); |
| 68 | } |
| 69 | |
| 70 | int get_recovery_mode_switch(void) |
| 71 | { |
| 72 | static enum rec_mode_state saved_rec_mode = REC_MODE_UNINITIALIZED; |
| 73 | enum rec_mode_state state = REC_MODE_NOT_REQUESTED; |
| 74 | uint8_t cr50_state = 0; |
| 75 | |
| 76 | /* Check cached state, since TPM will only tell us the first time */ |
| 77 | if (saved_rec_mode != REC_MODE_UNINITIALIZED) |
| 78 | return saved_rec_mode == REC_MODE_REQUESTED; |
| 79 | |
| 80 | /* |
| 81 | * Read one-time recovery request from cr50 in verstage only since |
| 82 | * the TPM driver won't be set up in time for other stages like romstage |
| 83 | * and the value from the TPM would be wrong anyway since the verstage |
| 84 | * read would have cleared the value on the TPM. |
| 85 | * |
| 86 | * The TPM recovery request is passed between stages through vboot data |
| 87 | * or cbmem depending on stage. |
| 88 | */ |
Julius Werner | 21a4053 | 2020-04-21 16:03:53 -0700 | [diff] [blame] | 89 | if (ENV_SEPARATE_VERSTAGE && |
Bora Guvendik | 3a1a037 | 2020-03-09 18:20:07 -0700 | [diff] [blame] | 90 | tlcl_cr50_get_recovery_button(&cr50_state) == TPM_SUCCESS && |
| 91 | cr50_state) |
| 92 | state = REC_MODE_REQUESTED; |
| 93 | |
| 94 | /* Read state from the GPIO controlled by servo. */ |
| 95 | if (cros_get_gpio_value(CROS_GPIO_REC)) |
| 96 | state = REC_MODE_REQUESTED; |
| 97 | |
| 98 | /* Store the state in case this is called again in verstage. */ |
| 99 | saved_rec_mode = state; |
| 100 | |
| 101 | return state == REC_MODE_REQUESTED; |
| 102 | } |
| 103 | |
| 104 | int get_lid_switch(void) |
| 105 | { |
| 106 | return 1; |
| 107 | } |
| 108 | |
| 109 | void mainboard_prepare_cr50_reset(void) |
| 110 | { |
| 111 | /* Ensure system powers up after CR50 reset */ |
| 112 | if (ENV_RAMSTAGE) |
| 113 | pmc_soc_set_afterg3_en(true); |
| 114 | } |