intel/skylake: Implement native Cache-as-RAM (CAR)
[coreboot.git] / src / include / antirollback.h
blob5ba36f7e654c52868e31666776971a3ebb58fe48
1 /* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
2 * Use of this source code is governed by a BSD-style license that can be
3 * found in the LICENSE file.
5 * Functions for querying, manipulating and locking rollback indices
6 * stored in the TPM NVRAM.
7 */
9 #ifndef ANTIROLLBACK_H_
10 #define ANTIROLLBACK_H_
12 #include "tpm_lite/tss_constants.h"
14 struct vb2_context;
15 enum vb2_pcr_digest;
17 /* TPM NVRAM location indices. */
18 #define FIRMWARE_NV_INDEX 0x1007
19 #define KERNEL_NV_INDEX 0x1008
20 /* This is just an opaque space for backup purposes */
21 #define BACKUP_NV_INDEX 0x1009
23 /* Structure definitions for TPM spaces */
25 /* Flags for firmware space */
28 * Last boot was developer mode. TPM ownership is cleared when transitioning
29 * to/from developer mode.
31 #define FLAG_LAST_BOOT_DEVELOPER 0x01
33 /* All functions return TPM_SUCCESS (zero) if successful, non-zero if error */
35 uint32_t antirollback_read_space_firmware(struct vb2_context *ctx);
37 /**
38 * Write may be called if the versions change.
40 uint32_t antirollback_write_space_firmware(struct vb2_context *ctx);
42 /**
43 * Lock must be called.
45 uint32_t antirollback_lock_space_firmware(void);
47 /****************************************************************************/
50 * The following functions are internal apis, listed here for use by unit tests
51 * only.
54 /**
55 * Ask vboot for a digest and extend a TPM PCR with it.
57 uint32_t tpm_extend_pcr(struct vb2_context *ctx, int pcr,
58 enum vb2_pcr_digest which_digest);
60 /**
61 * Issue a TPM_Clear and reenable/reactivate the TPM.
63 uint32_t tpm_clear_and_reenable(void);
65 /**
66 * Like tlcl_write(), but checks for write errors due to hitting the 64-write
67 * limit and clears the TPM when that happens. This can only happen when the
68 * TPM is unowned, so it is OK to clear it (and we really have no choice).
69 * This is not expected to happen frequently, but it could happen.
71 uint32_t safe_write(uint32_t index, const void *data, uint32_t length);
73 /**
74 * Similarly to safe_write(), this ensures we don't fail a DefineSpace because
75 * we hit the TPM write limit. This is even less likely to happen than with
76 * writes because we only define spaces once at initialization, but we'd rather
77 * be paranoid about this.
79 uint32_t safe_define_space(uint32_t index, uint32_t perm, uint32_t size);
81 /**
82 * Perform one-time initializations.
84 * Create the NVRAM spaces, and set their initial values as needed. Sets the
85 * nvLocked bit and ensures the physical presence command is enabled and
86 * locked.
88 uint32_t factory_initialize_tpm(struct vb2_context *ctx);
90 /**
91 * Start the TPM and establish the root of trust for the antirollback mechanism.
93 uint32_t setup_tpm(struct vb2_context *ctx);
95 #endif /* ANTIROLLBACK_H_ */