1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <console/console.h>
4 #include <cpu/x86/msr.h>
5 #include <cpu/intel/msr.h>
6 #include <device/mmio.h>
8 #include <security/intel/txt/txt.h>
12 #define LOG(...) printk(BIOS_INFO, "CBnT: " __VA_ARGS__)
16 uint64_t nem_enabled
: 1;
17 uint64_t tpm_type
: 2;
18 uint64_t tpm_success
: 1;
20 uint64_t measured_boot
: 1;
21 uint64_t verified_boot
: 1;
33 _Static_assert(sizeof(union sacm_info
) == sizeof(uint64_t), "Wrong size of sacm_info");
35 static const char *const tpm_type
[] = {
42 union cbnt_bootstatus
{
45 uint64_t bios_trusted
: 1;
46 uint64_t txt_dis_pol
: 1;
47 uint64_t btg_startup_err
: 1;
53 _Static_assert(sizeof(union cbnt_bootstatus
) == sizeof(uint64_t),
54 "Wrong size of cbnt_bootstatus");
56 union cbnt_errorcode
{
60 uint32_t external
: 1;
67 uint32_t minor_invalid
: 1;
70 uint32_t external
: 1;
76 _Static_assert(sizeof(union cbnt_errorcode
) == sizeof(uint32_t),
77 "Wrong size of cbnt_errorcode");
79 union cbnt_biosacm_errorcode
{
84 uint32_t minor_invalid
: 1;
87 uint32_t external
: 1;
94 uint32_t acm_started
: 1;
102 _Static_assert(sizeof(union cbnt_biosacm_errorcode
) == sizeof(uint32_t),
103 "Wrong size of cbnt_biosacm_errorcode");
106 static const char *decode_err_type(uint8_t type
)
110 return "BIOS ACM Error";
112 return "SINIT ACM Error";
114 return "Boot Guard Error";
120 void intel_cbnt_log_registers(void)
122 const union sacm_info acm_info
= { .msr
= rdmsr(MSR_BOOT_GUARD_SACM_INFO
) };
123 LOG("SACM INFO MSR (0x13A) raw: 0x%016llx\n", acm_info
.raw
);
124 LOG(" NEM status: %u\n", acm_info
.nem_enabled
);
125 LOG(" TPM type: %s\n", tpm_type
[acm_info
.tpm_type
]);
126 LOG(" TPM success: %u\n", acm_info
.tpm_success
);
127 LOG(" FACB: %u\n", acm_info
.facb
);
128 LOG(" measured boot: %u\n", acm_info
.measured_boot
);
129 LOG(" verified boot: %u\n", acm_info
.verified_boot
);
130 LOG(" revoked: %u\n", acm_info
.revoked
);
131 LOG(" BtG capable: %u\n", acm_info
.btg_cap
);
132 LOG(" TXT capable: %u\n", acm_info
.txt_cap
);
134 const union cbnt_bootstatus btsts
= {
135 .raw
= read64p(CBNT_BOOTSTATUS
),
137 LOG("BOOTSTATUS (0xA0) raw: 0x%016llx\n", btsts
.raw
);
138 LOG(" Bios trusted: %u\n", btsts
.bios_trusted
);
139 LOG(" TXT disabled by policy: %u\n", btsts
.txt_dis_pol
);
140 LOG(" Bootguard startup error: %u\n", btsts
.btg_startup_err
);
141 LOG(" TXT ucode or ACM error: %u\n", btsts
.txt_err
);
142 LOG(" TXT measurement type 7: %u\n", btsts
.type7
);
144 const union cbnt_errorcode err
= {
145 .raw
= read32p(CBNT_ERRORCODE
),
147 LOG("ERRORCODE (0x30) raw: 0x%08x\n", err
.raw
);
148 /* It looks like the hardware does not set the txt error bit properly */
149 const bool txt_err_valid
= btsts
.txt_err
|| true;
150 if (txt_err_valid
&& !btsts
.txt_dis_pol
) {
151 if (err
.microcode
.valid
&& !err
.microcode
.external
) {
152 LOG("ERRORCODE is ucode error\n");
154 intel_txt_processor_error_type(err
.microcode
.type
));
155 } else if (err
.sinit
.valid
&& err
.sinit
.external
) {
156 LOG("ERRORCODE is SINIT error\n");
157 const char *type
= decode_err_type(err
.sinit
.ac_type
);
158 LOG(" AC Module Type: %s\n", type
);
159 LOG(" class: 0x%x\n", err
.sinit
.class);
160 LOG(" major: 0x%x\n", err
.sinit
.major
);
161 if (!err
.sinit
.minor_invalid
)
162 LOG(" minor: 0x%x\n", err
.sinit
.minor
);
164 } else if (txt_err_valid
&& btsts
.txt_dis_pol
) {
165 LOG("TXT disabled in Policy\n");
168 const union cbnt_biosacm_errorcode biosacm_err
= {
169 .raw
= read32p(CBNT_BIOSACM_ERRORCODE
),
171 LOG("BIOSACM_ERRORCODE (0x328) raw: 0x%08x\n", biosacm_err
.raw
);
172 if (txt_err_valid
&& biosacm_err
.txt
.valid
) {
173 LOG("BIOSACM_ERRORCODE: TXT ucode or ACM error\n");
174 const char *type
= decode_err_type(biosacm_err
.txt
.ac_type
);
175 LOG(" AC Module Type: %s\n", type
);
176 LOG(" class: 0x%x\n", biosacm_err
.txt
.class);
177 LOG(" major: 0x%x\n", biosacm_err
.txt
.major
);
178 if (!biosacm_err
.txt
.minor_invalid
)
179 LOG(" minor: 0x%x\n", biosacm_err
.txt
.minor
);
180 LOG(" External: 0x%x\n", biosacm_err
.txt
.external
);
183 if (btsts
.btg_startup_err
&& biosacm_err
.btg
.valid
) {
184 LOG("BIOSACM_ERRORCODE: Bootguard error\n");
185 const char *type
= decode_err_type(biosacm_err
.btg
.ac_type
);
186 LOG(" AC Module Type: %s\n", type
);
187 LOG(" class: 0x%x\n", biosacm_err
.btg
.class);
188 LOG(" error: 0x%x\n", biosacm_err
.btg
.error
);
189 LOG(" ACM started: %u\n", biosacm_err
.btg
.acm_started
);
190 LOG(" KMID: 0x%x\n", biosacm_err
.btg
.km_id
);
191 LOG(" BootPolicies: 0x%x\n", biosacm_err
.btg
.bp
);