summaryrefslogtreecommitdiffstats
path: root/src/mainboard/google/sarien/chromeos.c
blob: 8cdd15c769bded551539d27a31874ed665f3eca7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/* SPDX-License-Identifier: GPL-2.0-only */

#include <bootmode.h>
#include <boot/coreboot_tables.h>
#include <gpio.h>
#include <soc/gpio.h>
#include <variant/gpio.h>
#include <types.h>
#include <vendorcode/google/chromeos/chromeos.h>
#include <security/tpm/tss.h>
#include <device/device.h>
#include <intelblocks/pmclib.h>

enum rec_mode_state {
	REC_MODE_UNINITIALIZED,
	REC_MODE_NOT_REQUESTED,
	REC_MODE_REQUESTED,
};

void fill_lb_gpios(struct lb_gpios *gpios)
{
	struct lb_gpio chromeos_gpios[] = {
		{-1, ACTIVE_HIGH, get_lid_switch(), "lid"},
		{-1, ACTIVE_HIGH, 0, "power"},
		{-1, ACTIVE_HIGH, gfx_get_init_done(), "oprom"},
		{-1, ACTIVE_HIGH, 0, "EC in RW"},
	};
	lb_add_gpios(gpios, chromeos_gpios, ARRAY_SIZE(chromeos_gpios));
}

int get_write_protect_state(void)
{
	return gpio_get(GPP_E15);
}

static bool raw_get_recovery_mode_switch(void)
{
	return !gpio_get(GPP_E8);
}


int get_recovery_mode_switch(void)
{
	static enum rec_mode_state saved_rec_mode = REC_MODE_UNINITIALIZED;
	enum rec_mode_state state = REC_MODE_NOT_REQUESTED;
	uint8_t cr50_state = 0;

	/* Check cached state, since TPM will only tell us the first time */
	if (saved_rec_mode != REC_MODE_UNINITIALIZED)
		return saved_rec_mode == REC_MODE_REQUESTED;

	/*
	 * Read one-time recovery request from cr50 in verstage only since
	 * the TPM driver won't be set up in time for other stages like romstage
	 * and the value from the TPM would be wrong anyway since the verstage
	 * read would have cleared the value on the TPM.
	 *
	 * The TPM recovery request is passed between stages through vboot data
	 * or cbmem depending on stage.
	 */
	if (ENV_SEPARATE_VERSTAGE &&
	    tlcl_cr50_get_recovery_button(&cr50_state) == TPM_SUCCESS &&
	    cr50_state)
		state = REC_MODE_REQUESTED;

	/* Read state from the GPIO controlled by servo. */
	if (raw_get_recovery_mode_switch())
		state = REC_MODE_REQUESTED;

	/* Store the state in case this is called again in verstage. */
	saved_rec_mode = state;

	return state == REC_MODE_REQUESTED;
}

int get_lid_switch(void)
{
	return 1;
}

void mainboard_prepare_cr50_reset(void)
{
	/* Ensure system powers up after CR50 reset */
	if (ENV_RAMSTAGE)
		pmc_soc_set_afterg3_en(true);
}

int get_ec_is_trusted(void)
{
	/* Do not have a Chrome EC involved in entering recovery mode;
	   Always return trusted. */
	return 1;
}