Debian Codegraph @

src/mainboard/google/drallion/chromeos.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <bootmode.h>
4 #include <boot/coreboot_tables.h>
5 #include <gpio.h>
6 #include <variant/gpio.h>
7 #include <types.h>
8 #include <vendorcode/google/chromeos/chromeos.h>
9 #include <security/tpm/tss.h>
10 #include <device/device.h>
11 #include <intelblocks/pmclib.h>
12 #include <soc/pmc.h>
13 #include <soc/pci_devs.h>
14
15 enum rec_mode_state {
16 REC_MODE_UNINITIALIZED,
17 REC_MODE_NOT_REQUESTED,
18 REC_MODE_REQUESTED,
19 };
20
21 void fill_lb_gpios(struct lb_gpios *gpios)
22 {
23 struct lb_gpio chromeos_gpios[] = {
24 {-1, ACTIVE_HIGH, get_lid_switch(), "lid"},
25 {-1, ACTIVE_HIGH, 0, "power"},
26 {-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
27 {-1, ACTIVE_HIGH, 0, "EC in RW"},
28 };
29 lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
30 }
31
32 int get_write_protect_state(void)
33 {
34 return gpio_get(GPP_E15);
35 }
36
37 static bool raw_get_recovery_mode_switch(void)
38 {
39 return !gpio_get(GPP_E8);
40 }
41
42
43 int get_recovery_mode_switch(void)
44 {
45 static enum rec_mode_state saved_rec_mode = REC_MODE_UNINITIALIZED;
46 enum rec_mode_state state = REC_MODE_NOT_REQUESTED;
47 uint8_t cr50_state = 0;
48
49 /* Check cached state, since TPM will only tell us the first time */
50 if (saved_rec_mode != REC_MODE_UNINITIALIZED)
51 return saved_rec_mode == REC_MODE_REQUESTED;
52
53 /*
54 * Read one-time recovery request from cr50 in verstage only since
55 * the TPM driver won't be set up in time for other stages like romstage
56 * and the value from the TPM would be wrong anyway since the verstage
57 * read would have cleared the value on the TPM.
58 *
59 * The TPM recovery request is passed between stages through vboot data
60 * or cbmem depending on stage.
61 */
62 if (ENV_SEPARATE_VERSTAGE &&
63 tlcl_cr50_get_recovery_button(&cr50_state) == TPM_SUCCESS &&
64 cr50_state)
65 state = REC_MODE_REQUESTED;
66
67 /* Read state from the GPIO controlled by servo. */
68 if (raw_get_recovery_mode_switch())
69 state = REC_MODE_REQUESTED;
70
71 /* Store the state in case this is called again in verstage. */
72 saved_rec_mode = state;
73
74 return state == REC_MODE_REQUESTED;
75 }
76
77 int get_lid_switch(void)
78 {
79 return 1;
80 }
81
82 void mainboard_prepare_cr50_reset(void)
83 {
84 #if ENV_RAMSTAGE
85 /* Ensure system powers up after CR50 reset */
86 pmc_soc_set_afterg3_en(true);
87 #endif
88 }
89
90 int get_ec_is_trusted(void)
91 {
92 /* Do not have a Chrome EC involved in entering recovery mode;
93 Always return trusted. */
94 return 1;
95 }