Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 3 | #include <acpi/acpi.h> |
Angel Pons | 52082be | 2020-10-05 12:34:29 +0200 | [diff] [blame] | 4 | #include <arch/mmio.h> |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 5 | #include <bootmem.h> |
Angel Pons | 52082be | 2020-10-05 12:34:29 +0200 | [diff] [blame] | 6 | #include <bootstate.h> |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 7 | #include <cbfs.h> |
Angel Pons | 52082be | 2020-10-05 12:34:29 +0200 | [diff] [blame] | 8 | #include <console/console.h> |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 9 | #include <cpu/intel/common/common.h> |
| 10 | #include <cpu/x86/msr.h> |
Angel Pons | 1133472 | 2020-10-05 16:34:03 +0200 | [diff] [blame] | 11 | #include <cpu/x86/smm.h> |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 12 | #include <device/pci_ops.h> |
Angel Pons | 52082be | 2020-10-05 12:34:29 +0200 | [diff] [blame] | 13 | #include <types.h> |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 14 | |
| 15 | #include "txt.h" |
Angel Pons | ffbb4b2 | 2020-10-15 23:25:58 +0200 | [diff] [blame] | 16 | #include "txt_platform.h" |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 17 | #include "txt_register.h" |
| 18 | #include "txt_getsec.h" |
| 19 | |
| 20 | /* FIXME: Seems to work only on some platforms */ |
| 21 | static void log_ibb_measurements(void) |
| 22 | { |
| 23 | const uint64_t mseg_size = read64((void *)TXT_MSEG_SIZE); |
| 24 | uint64_t mseg_base = read64((void *)TXT_MSEG_BASE); |
| 25 | |
| 26 | if (!mseg_size || !mseg_base || mseg_size <= mseg_base) |
| 27 | return; |
| 28 | /* |
| 29 | * MSEG SIZE and MSEG BASE might contain random values. |
| 30 | * Assume below 4GiB and 8byte aligned. |
| 31 | */ |
| 32 | if (mseg_base & ~0xfffffff8ULL || mseg_size & ~0xfffffff8ULL) |
| 33 | return; |
| 34 | |
| 35 | printk(BIOS_INFO, "TEE-TXT: IBB Hash 0x"); |
| 36 | for (; mseg_base < mseg_size; mseg_base++) |
| 37 | printk(BIOS_INFO, "%02X", read8((void *)(uintptr_t)mseg_base)); |
| 38 | |
| 39 | printk(BIOS_INFO, "\n"); |
| 40 | } |
| 41 | |
| 42 | void bootmem_platform_add_ranges(void) |
| 43 | { |
| 44 | uint64_t status = read64((void *)TXT_SPAD); |
| 45 | |
| 46 | if (status & ACMSTS_TXT_DISABLED) |
| 47 | return; |
| 48 | |
| 49 | /* Chapter 5.5.5 Intel TXT reserved memory */ |
| 50 | bootmem_add_range(TXT_RESERVED_SPACE, |
| 51 | TXT_RESERVED_SPACE_SIZE, |
| 52 | BM_MEM_RESERVED); |
| 53 | |
| 54 | /* Intel TPM decode memory */ |
| 55 | bootmem_add_range(TXT_TPM_DECODE_AREA, |
| 56 | TXT_RESERVED_SPACE - TXT_TPM_DECODE_AREA, |
| 57 | BM_MEM_RESERVED); |
| 58 | |
| 59 | /* Intel TXT public space memory */ |
| 60 | bootmem_add_range(TXT_PUBLIC_SPACE, |
| 61 | TXT_TPM_DECODE_AREA - TXT_PUBLIC_SPACE, |
| 62 | BM_MEM_RESERVED); |
| 63 | |
| 64 | /* Intel TXT private space memory */ |
| 65 | bootmem_add_range(TXT_PRIVATE_SPACE, |
| 66 | TXT_PUBLIC_SPACE - TXT_PRIVATE_SPACE, |
| 67 | BM_MEM_RESERVED); |
| 68 | |
Angel Pons | 463e44b | 2020-10-05 13:58:16 +0200 | [diff] [blame] | 69 | const union dpr_register dpr = { |
| 70 | .raw = read32((void *)TXT_DPR), |
| 71 | }; |
| 72 | |
| 73 | const uint32_t dpr_base = dpr.top - dpr.size * MiB; |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 74 | |
| 75 | /* Chapter 5.5.6 Intel TXT Device Memory */ |
Angel Pons | 463e44b | 2020-10-05 13:58:16 +0200 | [diff] [blame] | 76 | bootmem_add_range(dpr_base, dpr.size * MiB, BM_MEM_RESERVED); |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | static bool get_wake_error_status(void) |
| 80 | { |
| 81 | const uint8_t error = read8((void *)TXT_ESTS); |
| 82 | return !!(error & TXT_ESTS_WAKE_ERROR_STS); |
| 83 | } |
| 84 | |
| 85 | static void check_secrets_txt(void *unused) |
| 86 | { |
| 87 | uint64_t status = read64((void *)TXT_SPAD); |
| 88 | |
| 89 | if (status & ACMSTS_TXT_DISABLED) |
| 90 | return; |
| 91 | |
Arthur Heymans | bccb691 | 2020-11-24 17:37:11 +0100 | [diff] [blame] | 92 | /* |
| 93 | * Check if secrets bit needs to be reset. Only platforms that support |
| 94 | * CONFIG(PLATFORM_HAS_DRAM_CLEAR) will be able to run this code. |
| 95 | * On some platforms FSP-M takes care of the DRAM clearing. |
| 96 | * Assume all memory really was cleared. |
| 97 | * |
| 98 | * TXT will issue a platform reset to come up sober. |
| 99 | */ |
| 100 | if (intel_txt_memory_has_secrets()) { |
| 101 | printk(BIOS_INFO, "TEE-TXT: Wiping TEE...\n"); |
| 102 | intel_txt_run_bios_acm(ACMINPUT_CLEAR_SECRETS); |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 103 | |
Arthur Heymans | bccb691 | 2020-11-24 17:37:11 +0100 | [diff] [blame] | 104 | /* Should never reach this point ... */ |
| 105 | intel_txt_log_acm_error(read32((void *)TXT_BIOSACM_ERRORCODE)); |
| 106 | die("Waiting for platform reset...\n"); |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 107 | } |
| 108 | } |
| 109 | |
| 110 | BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_ENTRY, check_secrets_txt, NULL); |
| 111 | |
| 112 | /** |
| 113 | * Log TXT startup errors, check all bits for TXT, run BIOSACM using |
| 114 | * GETSEC[ENTERACCS]. |
| 115 | * |
| 116 | * If a "TXT reset" is detected or "memory had secrets" is set, then do nothing as |
| 117 | * 1. Running ACMs will cause a TXT-RESET |
| 118 | * 2. Memory will be scrubbed in BS_DEV_INIT |
| 119 | * 3. TXT-RESET will be issued by code above later |
| 120 | * |
| 121 | */ |
| 122 | static void init_intel_txt(void *unused) |
| 123 | { |
| 124 | const uint64_t status = read64((void *)TXT_SPAD); |
| 125 | |
| 126 | if (status & ACMSTS_TXT_DISABLED) |
| 127 | return; |
| 128 | |
| 129 | printk(BIOS_INFO, "TEE-TXT: Initializing TEE...\n"); |
| 130 | |
| 131 | intel_txt_log_spad(); |
| 132 | |
| 133 | if (CONFIG(INTEL_TXT_LOGGING)) { |
| 134 | intel_txt_log_bios_acm_error(); |
| 135 | txt_dump_chipset_info(); |
| 136 | } |
| 137 | |
| 138 | printk(BIOS_INFO, "TEE-TXT: Validate TEE...\n"); |
| 139 | |
| 140 | if (intel_txt_prepare_txt_env()) { |
| 141 | printk(BIOS_ERR, "TEE-TXT: Failed to prepare TXT environment\n"); |
| 142 | return; |
| 143 | } |
| 144 | |
| 145 | /* Check for fatal ACM error and TXT reset */ |
| 146 | if (get_wake_error_status()) { |
| 147 | /* Can't run ACMs with TXT_ESTS_WAKE_ERROR_STS set */ |
| 148 | printk(BIOS_ERR, "TEE-TXT: Fatal BIOS ACM error reported\n"); |
| 149 | return; |
| 150 | } |
| 151 | |
Angel Pons | 8a285fd8 | 2020-10-16 10:49:12 +0200 | [diff] [blame] | 152 | if (CONFIG(INTEL_TXT_TEST_BIOS_ACM_CALLING_CODE)) { |
| 153 | printk(BIOS_INFO, "TEE-TXT: Testing BIOS ACM calling code...\n"); |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 154 | |
Angel Pons | 8a285fd8 | 2020-10-16 10:49:12 +0200 | [diff] [blame] | 155 | /* |
| 156 | * Test BIOS ACM code. |
| 157 | * ACM should do nothing on reserved functions, and return an error code |
| 158 | * in TXT_BIOSACM_ERRORCODE. Tests showed that this is not true. |
| 159 | * Use special function "NOP" that does 'nothing'. |
| 160 | */ |
| 161 | if (intel_txt_run_bios_acm(ACMINPUT_NOP) < 0) { |
| 162 | printk(BIOS_ERR, |
| 163 | "TEE-TXT: Error calling BIOS ACM with NOP function.\n"); |
| 164 | return; |
| 165 | } |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | if (status & (ACMSTS_BIOS_TRUSTED | ACMSTS_IBB_MEASURED)) { |
Angel Pons | e70a3f8 | 2020-10-16 10:58:57 +0200 | [diff] [blame] | 169 | printk(BIOS_INFO, "TEE-TXT: Logging IBB measurements...\n"); |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 170 | log_ibb_measurements(); |
Angel Pons | e70a3f8 | 2020-10-16 10:58:57 +0200 | [diff] [blame] | 171 | } |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 172 | |
Angel Pons | e70a3f8 | 2020-10-16 10:58:57 +0200 | [diff] [blame] | 173 | int s3resume = acpi_is_wakeup_s3(); |
Arthur Heymans | 66dbd9c | 2021-01-06 14:12:47 +0100 | [diff] [blame] | 174 | if (!s3resume && !CONFIG(INTEL_CBNT_SUPPORT)) { |
Angel Pons | e70a3f8 | 2020-10-16 10:58:57 +0200 | [diff] [blame] | 175 | printk(BIOS_INFO, "TEE-TXT: Scheck...\n"); |
| 176 | if (intel_txt_run_bios_acm(ACMINPUT_SCHECK) < 0) { |
| 177 | printk(BIOS_ERR, "TEE-TXT: Error calling BIOS ACM.\n"); |
| 178 | return; |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 179 | } |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | BOOT_STATE_INIT_ENTRY(BS_DEV_INIT, BS_ON_EXIT, init_intel_txt, NULL); |
| 184 | |
| 185 | static void push_sinit_heap(u8 **heap_ptr, void *data, size_t data_length) |
| 186 | { |
| 187 | /* Push size */ |
| 188 | const uint64_t tmp = data_length + 8; |
| 189 | memcpy(*heap_ptr, &tmp, 8); |
| 190 | *heap_ptr += 8; |
| 191 | |
| 192 | if (data_length) { |
| 193 | /* Push data */ |
| 194 | memcpy(*heap_ptr, data, data_length); |
| 195 | *heap_ptr += data_length; |
| 196 | } |
| 197 | } |
| 198 | |
Angel Pons | 8f7e2a3 | 2020-10-16 01:07:18 +0200 | [diff] [blame] | 199 | static void txt_initialize_heap(void) |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 200 | { |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 201 | /* |
| 202 | * BIOS Data Format |
| 203 | * Chapter C.2 |
| 204 | * Intel TXT Software Development Guide (Document: 315168-015) |
| 205 | */ |
| 206 | struct { |
| 207 | struct txt_biosdataregion bdr; |
Angel Pons | 08de7d6 | 2020-10-16 01:01:14 +0200 | [diff] [blame] | 208 | struct txt_bios_spec_ver_element spec; |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 209 | struct txt_heap_acm_element heap_acm; |
| 210 | struct txt_extended_data_element_header end; |
| 211 | } __packed data = {0}; |
| 212 | |
| 213 | /* TPM2.0 requires version 6 of BDT */ |
| 214 | if (CONFIG(TPM2)) |
| 215 | data.bdr.version = 6; |
| 216 | else |
| 217 | data.bdr.version = 5; |
| 218 | |
| 219 | data.bdr.no_logical_procs = dev_count_cpu(); |
| 220 | |
| 221 | void *sinit_base = (void *)(uintptr_t)read64((void *)TXT_SINIT_BASE); |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame] | 222 | data.bdr.bios_sinit_size = cbfs_load(CONFIG_INTEL_TXT_CBFS_SINIT_ACM, |
| 223 | sinit_base, |
| 224 | read64((void *)TXT_SINIT_SIZE)); |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 225 | |
| 226 | if (data.bdr.bios_sinit_size) { |
| 227 | printk(BIOS_INFO, "TEE-TXT: Placing SINIT ACM in memory.\n"); |
| 228 | if (CONFIG(INTEL_TXT_LOGGING)) |
| 229 | txt_dump_acm_info(sinit_base); |
| 230 | } else { |
| 231 | printk(BIOS_ERR, "TEE-TXT: Couldn't locate SINIT ACM in CBFS.\n"); |
| 232 | /* Clear memory */ |
| 233 | memset(sinit_base, 0, read64((void *)TXT_SINIT_SIZE)); |
| 234 | } |
| 235 | |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 236 | /* The following have been removed from BIOS Data Table in version 6 */ |
Julius Werner | 77639e4 | 2021-02-05 16:51:25 -0800 | [diff] [blame] | 237 | size_t policy_len; |
| 238 | void *policy_data = cbfs_map(CONFIG_INTEL_TXT_CBFS_BIOS_POLICY, &policy_len); |
| 239 | if (policy_data) { |
| 240 | /* Point to FIT Type 9 entry in flash */ |
| 241 | data.bdr.lcp_pd_base = (uintptr_t)policy_data; |
| 242 | data.bdr.lcp_pd_size = (uint64_t)policy_len; |
| 243 | cbfs_unmap(policy_data); |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 244 | } else { |
| 245 | printk(BIOS_ERR, "TEE-TXT: Couldn't locate LCP PD Policy in CBFS.\n"); |
| 246 | } |
| 247 | |
| 248 | data.bdr.support_acpi_ppi = 0; |
| 249 | data.bdr.platform_type = 0; |
| 250 | |
Angel Pons | 08de7d6 | 2020-10-16 01:01:14 +0200 | [diff] [blame] | 251 | /* Fill in the version of the used TXT BIOS Specification */ |
| 252 | data.spec.header.type = HEAP_EXTDATA_TYPE_BIOS_SPEC_VER; |
| 253 | data.spec.header.size = sizeof(data.spec); |
| 254 | data.spec.ver_major = 2; |
| 255 | data.spec.ver_minor = 1; |
| 256 | data.spec.ver_revision = 0; |
| 257 | |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 258 | /* Extended elements - ACM addresses */ |
| 259 | data.heap_acm.header.type = HEAP_EXTDATA_TYPE_ACM; |
| 260 | data.heap_acm.header.size = sizeof(data.heap_acm); |
| 261 | if (data.bdr.bios_sinit_size) { |
| 262 | data.heap_acm.num_acms = 2; |
| 263 | data.heap_acm.acm_addrs[1] = (uintptr_t)sinit_base; |
| 264 | } else { |
| 265 | data.heap_acm.num_acms = 1; |
| 266 | } |
| 267 | data.heap_acm.acm_addrs[0] = |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame] | 268 | (uintptr_t)cbfs_map(CONFIG_INTEL_TXT_CBFS_BIOS_ACM, NULL); |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 269 | /* Extended elements - End marker */ |
| 270 | data.end.type = HEAP_EXTDATA_TYPE_END; |
| 271 | data.end.size = sizeof(data.end); |
| 272 | |
| 273 | /* Fill TXT.HEAP.BASE with 4 subregions */ |
| 274 | u8 *heap_struct = (void *)((uintptr_t)read64((void *)TXT_HEAP_BASE)); |
| 275 | |
| 276 | /* BiosData */ |
| 277 | push_sinit_heap(&heap_struct, &data, sizeof(data)); |
| 278 | |
| 279 | /* OsMLEData */ |
| 280 | /* FIXME: Does firmware need to write this? */ |
| 281 | push_sinit_heap(&heap_struct, NULL, 0); |
| 282 | |
| 283 | /* OsSinitData */ |
| 284 | /* FIXME: Does firmware need to write this? */ |
| 285 | push_sinit_heap(&heap_struct, NULL, 0); |
| 286 | |
| 287 | /* SinitMLEData */ |
| 288 | /* FIXME: Does firmware need to write this? */ |
| 289 | push_sinit_heap(&heap_struct, NULL, 0); |
Angel Pons | 8f7e2a3 | 2020-10-16 01:07:18 +0200 | [diff] [blame] | 290 | } |
| 291 | |
Arthur Heymans | fc6cc71 | 2021-02-02 19:00:49 +0100 | [diff] [blame^] | 292 | __weak bool skip_intel_txt_lockdown(void) |
| 293 | { |
| 294 | return false; |
| 295 | } |
| 296 | |
Angel Pons | 8f7e2a3 | 2020-10-16 01:07:18 +0200 | [diff] [blame] | 297 | /** |
| 298 | * Finalize the TXT device. |
| 299 | * |
| 300 | * - Lock TXT register. |
| 301 | * - Protect TSEG using DMA protected regions. |
| 302 | * - Setup TXT regions. |
| 303 | * - Place SINIT ACM in TXT_SINIT memory segment. |
| 304 | * - Fill TXT BIOSDATA region. |
| 305 | */ |
| 306 | static void lockdown_intel_txt(void *unused) |
| 307 | { |
Arthur Heymans | fc6cc71 | 2021-02-02 19:00:49 +0100 | [diff] [blame^] | 308 | if (skip_intel_txt_lockdown()) |
| 309 | return; |
| 310 | |
Angel Pons | 8f7e2a3 | 2020-10-16 01:07:18 +0200 | [diff] [blame] | 311 | const uint64_t status = read64((void *)TXT_SPAD); |
| 312 | |
Angel Pons | 6c4028d | 2020-10-16 11:52:40 +0200 | [diff] [blame] | 313 | uint32_t txt_feature_flags = 0; |
Angel Pons | 8f7e2a3 | 2020-10-16 01:07:18 +0200 | [diff] [blame] | 314 | uintptr_t tseg_base; |
| 315 | size_t tseg_size; |
| 316 | |
| 317 | smm_region(&tseg_base, &tseg_size); |
| 318 | |
| 319 | if (status & ACMSTS_TXT_DISABLED) |
| 320 | return; |
| 321 | |
Angel Pons | 6c4028d | 2020-10-16 11:52:40 +0200 | [diff] [blame] | 322 | /* |
| 323 | * Document Number: 558294 |
| 324 | * Chapter 5.4.3 Detection of Intel TXT Capability |
| 325 | */ |
Angel Pons | 8f7e2a3 | 2020-10-16 01:07:18 +0200 | [diff] [blame] | 326 | |
Angel Pons | 6c4028d | 2020-10-16 11:52:40 +0200 | [diff] [blame] | 327 | if (!getsec_parameter(NULL, NULL, NULL, NULL, NULL, &txt_feature_flags)) |
Angel Pons | 8f7e2a3 | 2020-10-16 01:07:18 +0200 | [diff] [blame] | 328 | return; |
Angel Pons | 6c4028d | 2020-10-16 11:52:40 +0200 | [diff] [blame] | 329 | |
| 330 | /* LockConfig only exists on Intel TXT for Servers */ |
| 331 | if (txt_feature_flags & GETSEC_PARAMS_TXT_EXT_CRTM_SUPPORT) { |
| 332 | printk(BIOS_INFO, "TEE-TXT: Locking TEE...\n"); |
| 333 | |
| 334 | /* Lock TXT config, unlocks TXT_HEAP_BASE */ |
| 335 | if (intel_txt_run_bios_acm(ACMINPUT_LOCK_CONFIG) < 0) { |
| 336 | printk(BIOS_ERR, "TEE-TXT: Failed to lock registers.\n"); |
| 337 | printk(BIOS_ERR, "TEE-TXT: SINIT won't be supported.\n"); |
| 338 | return; |
| 339 | } |
Angel Pons | 8f7e2a3 | 2020-10-16 01:07:18 +0200 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | /* |
| 343 | * Document Number: 558294 |
| 344 | * Chapter 5.5.6.1 DMA Protection Memory Region |
| 345 | */ |
| 346 | |
| 347 | const u8 dpr_capable = !!(read64((void *)TXT_CAPABILITIES) & |
| 348 | TXT_CAPABILITIES_DPR); |
| 349 | printk(BIOS_INFO, "TEE-TXT: DPR capable %x\n", dpr_capable); |
| 350 | |
| 351 | if (dpr_capable) { |
| 352 | /* Verify the DPR settings on the MCH and mirror them to TXT public space */ |
| 353 | union dpr_register dpr = txt_get_chipset_dpr(); |
| 354 | |
| 355 | printk(BIOS_DEBUG, "TEE-TXT: MCH DPR 0x%08x\n", dpr.raw); |
| 356 | |
| 357 | printk(BIOS_DEBUG, "TEE-TXT: MCH DPR base @ 0x%08x size %u MiB\n", |
| 358 | (dpr.top - dpr.size) * MiB, dpr.size); |
| 359 | |
| 360 | // DPR TODO: implement SA_ENABLE_DPR in the intelblocks |
| 361 | |
| 362 | if (!dpr.lock) { |
| 363 | printk(BIOS_ERR, "TEE-TXT: MCH DPR not locked.\n"); |
| 364 | return; |
| 365 | } |
| 366 | |
| 367 | if (!dpr.epm || !dpr.prs) { |
| 368 | printk(BIOS_ERR, "TEE-TXT: MCH DPR protection not active.\n"); |
| 369 | return; |
| 370 | } |
| 371 | |
Arthur Heymans | 9059a89 | 2020-10-23 11:08:41 +0200 | [diff] [blame] | 372 | _Static_assert(CONFIG_INTEL_TXT_HEAP_SIZE + CONFIG_INTEL_TXT_SINIT_SIZE |
| 373 | < CONFIG_INTEL_TXT_DPR_SIZE * MiB, "TXT Heap and Sinit must fit DPR"); |
| 374 | |
Angel Pons | 8f7e2a3 | 2020-10-16 01:07:18 +0200 | [diff] [blame] | 375 | if (dpr.size < CONFIG_INTEL_TXT_DPR_SIZE) { |
| 376 | printk(BIOS_ERR, "TEE-TXT: MCH DPR configured size is too small.\n"); |
| 377 | return; |
| 378 | } |
| 379 | |
| 380 | if (dpr.top * MiB != tseg_base) { |
| 381 | printk(BIOS_ERR, "TEE-TXT: MCH DPR top does not equal TSEG base.\n"); |
| 382 | return; |
| 383 | } |
| 384 | |
| 385 | /* Clear reserved bits */ |
| 386 | dpr.prs = 0; |
| 387 | dpr.epm = 0; |
| 388 | |
| 389 | write64((void *)TXT_DPR, dpr.raw); |
| 390 | |
| 391 | printk(BIOS_INFO, "TEE-TXT: TXT.DPR 0x%08x\n", |
| 392 | read32((void *)TXT_DPR)); |
| 393 | } |
| 394 | |
| 395 | /* |
| 396 | * Document Number: 558294 |
| 397 | * Chapter 5.5.6.3 Intel TXT Heap Memory Region |
| 398 | */ |
Arthur Heymans | 9059a89 | 2020-10-23 11:08:41 +0200 | [diff] [blame] | 399 | write64((void *)TXT_HEAP_SIZE, CONFIG_INTEL_TXT_HEAP_SIZE); |
Angel Pons | 8f7e2a3 | 2020-10-16 01:07:18 +0200 | [diff] [blame] | 400 | write64((void *)TXT_HEAP_BASE, |
| 401 | ALIGN_DOWN(tseg_base - read64((void *)TXT_HEAP_SIZE), 4096)); |
| 402 | |
| 403 | /* |
| 404 | * Document Number: 558294 |
| 405 | * Chapter 5.5.6.2 SINIT Memory Region |
| 406 | */ |
Arthur Heymans | 9059a89 | 2020-10-23 11:08:41 +0200 | [diff] [blame] | 407 | write64((void *)TXT_SINIT_SIZE, CONFIG_INTEL_TXT_SINIT_SIZE); |
Angel Pons | 8f7e2a3 | 2020-10-16 01:07:18 +0200 | [diff] [blame] | 408 | write64((void *)TXT_SINIT_BASE, |
| 409 | ALIGN_DOWN(read64((void *)TXT_HEAP_BASE) - |
| 410 | read64((void *)TXT_SINIT_SIZE), 4096)); |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 411 | |
| 412 | /* |
| 413 | * FIXME: Server-TXT capable platforms need to install an STM in SMM and set up MSEG. |
| 414 | */ |
| 415 | |
| 416 | /** |
| 417 | * Chapter 5.10.1 SMM in the Intel TXT for Servers Environment |
| 418 | * Disable MSEG. |
| 419 | */ |
| 420 | write64((void *)TXT_MSEG_SIZE, 0); |
| 421 | write64((void *)TXT_MSEG_BASE, 0); |
| 422 | |
Angel Pons | c037695 | 2020-10-16 01:12:00 +0200 | [diff] [blame] | 423 | /* Only initialize the heap on regular boots */ |
| 424 | if (!acpi_is_wakeup_s3()) |
| 425 | txt_initialize_heap(); |
Angel Pons | 8f7e2a3 | 2020-10-16 01:07:18 +0200 | [diff] [blame] | 426 | |
Philipp Deppenwiese | 5f9f776 | 2018-11-20 14:22:15 +0100 | [diff] [blame] | 427 | if (CONFIG(INTEL_TXT_LOGGING)) |
| 428 | txt_dump_regions(); |
| 429 | } |
| 430 | |
| 431 | BOOT_STATE_INIT_ENTRY(BS_POST_DEVICE, BS_ON_EXIT, lockdown_intel_txt, NULL); |