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