Debian Codegraph @

src/soc/amd/common/block/psp/ftpm.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <amdblocks/psp.h>
4 #include <console/console.h>
5 #include <device/mmio.h>
6
7 #include "psp_def.h"
8
9 uintptr_t psp_ftpm_base_address(void)
10 {
11 const uintptr_t psp_base = get_psp_mmio_base();
12 if (!psp_base)
13 return 0;
14
15 /* TPM MMIO space starts 0xA0 bytes before MBOX */
16 return psp_base + CONFIG_PSPV2_MBOX_CMD_OFFSET - 0xA0;
17 }
18
19 /*
20 * psp_ftpm_is_active
21 *
22 * Checks that fTPM CRB interface is available and active.
23 */
24 bool psp_ftpm_is_active(void)
25 {
26 uint32_t caps = 0;
27
28 /* PSP must report fTPM capability support */
29 if (psp_get_ftpm_capabilties(&caps) != CB_SUCCESS)
30 return false;
31
32 if (!(caps & MBOX_FTPM_CAP_TPM_SUPPORTED))
33 return false;
34
35 /* Must have valid MMIO base address */
36 if (!psp_ftpm_base_address())
37 return false;
38
39 return true;
40 }
41
42 /*
43 * psp_ftpm_needs_recovery
44 *
45 * Checks the PSP and returns the necessary recovery actions
46 * to be taken. Recovery actions involve erasing parts of the SPI flash
47 * and might possibly erase TPM secrets, preventing unsealing of
48 * the OS.
49 *
50 * @psp_rpmc_nvram The PSP_RPMC_NVRAM FMAP regions must be cleared
51 * @psp_nvram The PSP_NVRAM FMAP regions must be cleared
52 * @psp_dir The fTPM driver in the PSP directory is missing or corrupted
53 */
54 void psp_ftpm_needs_recovery(bool *psp_rpmc_nvram,
55 bool *psp_nvram,
56 bool *psp_dir)
57 {
58 uint32_t psp_caps;
59 uint32_t caps;
60
61 *psp_rpmc_nvram = false;
62 *psp_nvram = false;
63 *psp_dir = false;
64
65 if (psp_get_psp_capabilities(&psp_caps) != CB_SUCCESS) {
66 printk(BIOS_ERR, "FTPM: Failed to get PSP capabilities\n");
67 return;
68 }
69
70 if (psp_get_ftpm_capabilties(&caps) != CB_SUCCESS) {
71 printk(BIOS_ERR, "FTPM: Failed to get fTPM capabilities\n");
72 return;
73 }
74
75 if ((psp_caps & 0x5) == 0x4) {
76 printk(BIOS_WARNING, "FTPM: PSP_RPMC_NVRAM region corrupted.\n");
77 *psp_rpmc_nvram = true;
78 *psp_nvram = true;
79 }
80
81 if (caps & MBOX_FTPM_CAP_TPM_REQ_FACTORY_RESET) {
82 printk(BIOS_WARNING, "FTPM: PSP_NVRAM region corrupted.\n");
83 *psp_nvram = true;
84 }
85
86 if (caps & MBOX_FTPM_CAP_FTPM_NEED_RECOVER)
87 *psp_dir = true;
88 }