Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
| 2 | /* |
Ilias Apalodimas | f4e0590 | 2020-11-11 11:18:10 +0200 | [diff] [blame] | 3 | * Defines APIs and structures that allow software to interact with a |
| 4 | * TPM2 device |
| 5 | * |
| 6 | * Copyright (c) 2020 Linaro |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 7 | * Copyright (c) 2018 Bootlin |
Ilias Apalodimas | f4e0590 | 2020-11-11 11:18:10 +0200 | [diff] [blame] | 8 | * |
| 9 | * https://trustedcomputinggroup.org/resource/tss-overview-common-structures-specification/ |
| 10 | * |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 11 | * Author: Miquel Raynal <miquel.raynal@bootlin.com> |
| 12 | */ |
| 13 | |
| 14 | #ifndef __TPM_V2_H |
| 15 | #define __TPM_V2_H |
| 16 | |
| 17 | #include <tpm-common.h> |
| 18 | |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 19 | struct udevice; |
| 20 | |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 21 | #define TPM2_DIGEST_LEN 32 |
| 22 | |
Ilias Apalodimas | cae28ef | 2020-11-30 11:47:39 +0200 | [diff] [blame] | 23 | #define TPM2_SHA1_DIGEST_SIZE 20 |
| 24 | #define TPM2_SHA256_DIGEST_SIZE 32 |
| 25 | #define TPM2_SHA384_DIGEST_SIZE 48 |
| 26 | #define TPM2_SHA512_DIGEST_SIZE 64 |
| 27 | #define TPM2_SM3_256_DIGEST_SIZE 32 |
| 28 | |
Ilias Apalodimas | f4e0590 | 2020-11-11 11:18:10 +0200 | [diff] [blame] | 29 | #define TPM2_MAX_PCRS 32 |
| 30 | #define TPM2_PCR_SELECT_MAX ((TPM2_MAX_PCRS + 7) / 8) |
| 31 | #define TPM2_MAX_CAP_BUFFER 1024 |
| 32 | #define TPM2_MAX_TPM_PROPERTIES ((TPM2_MAX_CAP_BUFFER - sizeof(u32) /* TPM2_CAP */ - \ |
| 33 | sizeof(u32)) / sizeof(struct tpms_tagged_property)) |
| 34 | |
Simon Glass | ca31f07 | 2021-07-18 14:18:03 -0600 | [diff] [blame] | 35 | #define TPM2_HDR_LEN 10 |
| 36 | |
Ilias Apalodimas | f4e0590 | 2020-11-11 11:18:10 +0200 | [diff] [blame] | 37 | /* |
| 38 | * We deviate from this draft of the specification by increasing the value of |
| 39 | * TPM2_NUM_PCR_BANKS from 3 to 16 to ensure compatibility with TPM2 |
| 40 | * implementations that have enabled a larger than typical number of PCR |
| 41 | * banks. This larger value for TPM2_NUM_PCR_BANKS is expected to be included |
| 42 | * in a future revision of the specification. |
| 43 | */ |
| 44 | #define TPM2_NUM_PCR_BANKS 16 |
| 45 | |
| 46 | /* Definition of (UINT32) TPM2_CAP Constants */ |
| 47 | #define TPM2_CAP_PCRS 0x00000005U |
| 48 | #define TPM2_CAP_TPM_PROPERTIES 0x00000006U |
| 49 | |
| 50 | /* Definition of (UINT32) TPM2_PT Constants */ |
| 51 | #define TPM2_PT_GROUP (u32)(0x00000100) |
| 52 | #define TPM2_PT_FIXED (u32)(TPM2_PT_GROUP * 1) |
| 53 | #define TPM2_PT_MANUFACTURER (u32)(TPM2_PT_FIXED + 5) |
| 54 | #define TPM2_PT_PCR_COUNT (u32)(TPM2_PT_FIXED + 18) |
| 55 | #define TPM2_PT_MAX_COMMAND_SIZE (u32)(TPM2_PT_FIXED + 30) |
| 56 | #define TPM2_PT_MAX_RESPONSE_SIZE (u32)(TPM2_PT_FIXED + 31) |
| 57 | |
| 58 | /* TPMS_TAGGED_PROPERTY Structure */ |
| 59 | struct tpms_tagged_property { |
| 60 | u32 property; |
| 61 | u32 value; |
| 62 | } __packed; |
| 63 | |
| 64 | /* TPMS_PCR_SELECTION Structure */ |
| 65 | struct tpms_pcr_selection { |
| 66 | u16 hash; |
| 67 | u8 size_of_select; |
| 68 | u8 pcr_select[TPM2_PCR_SELECT_MAX]; |
| 69 | } __packed; |
| 70 | |
| 71 | /* TPML_PCR_SELECTION Structure */ |
| 72 | struct tpml_pcr_selection { |
| 73 | u32 count; |
| 74 | struct tpms_pcr_selection selection[TPM2_NUM_PCR_BANKS]; |
| 75 | } __packed; |
| 76 | |
| 77 | /* TPML_TAGGED_TPM_PROPERTY Structure */ |
| 78 | struct tpml_tagged_tpm_property { |
| 79 | u32 count; |
| 80 | struct tpms_tagged_property tpm_property[TPM2_MAX_TPM_PROPERTIES]; |
| 81 | } __packed; |
| 82 | |
| 83 | /* TPMU_CAPABILITIES Union */ |
| 84 | union tpmu_capabilities { |
| 85 | /* |
| 86 | * Non exhaustive. Only added the structs needed for our |
| 87 | * current code |
| 88 | */ |
| 89 | struct tpml_pcr_selection assigned_pcr; |
| 90 | struct tpml_tagged_tpm_property tpm_properties; |
| 91 | } __packed; |
| 92 | |
| 93 | /* TPMS_CAPABILITY_DATA Structure */ |
| 94 | struct tpms_capability_data { |
| 95 | u32 capability; |
| 96 | union tpmu_capabilities data; |
| 97 | } __packed; |
| 98 | |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 99 | /** |
Ilias Apalodimas | cae28ef | 2020-11-30 11:47:39 +0200 | [diff] [blame] | 100 | * Definition of TPMU_HA Union |
| 101 | */ |
Eddie James | 90b6c86 | 2023-10-24 10:43:47 -0500 | [diff] [blame] | 102 | union tpmu_ha { |
Ilias Apalodimas | cae28ef | 2020-11-30 11:47:39 +0200 | [diff] [blame] | 103 | u8 sha1[TPM2_SHA1_DIGEST_SIZE]; |
| 104 | u8 sha256[TPM2_SHA256_DIGEST_SIZE]; |
| 105 | u8 sm3_256[TPM2_SM3_256_DIGEST_SIZE]; |
| 106 | u8 sha384[TPM2_SHA384_DIGEST_SIZE]; |
| 107 | u8 sha512[TPM2_SHA512_DIGEST_SIZE]; |
| 108 | } __packed; |
| 109 | |
| 110 | /** |
| 111 | * Definition of TPMT_HA Structure |
| 112 | * |
| 113 | * @hash_alg: Hash algorithm defined in enum tpm2_algorithms |
| 114 | * @digest: Digest value for a given algorithm |
| 115 | */ |
| 116 | struct tpmt_ha { |
| 117 | u16 hash_alg; |
Eddie James | 90b6c86 | 2023-10-24 10:43:47 -0500 | [diff] [blame] | 118 | union tpmu_ha digest; |
Ilias Apalodimas | cae28ef | 2020-11-30 11:47:39 +0200 | [diff] [blame] | 119 | } __packed; |
| 120 | |
| 121 | /** |
| 122 | * Definition of TPML_DIGEST_VALUES Structure |
| 123 | * |
| 124 | * @count: Number of algorithms supported by hardware |
| 125 | * @digests: struct for algorithm id and hash value |
| 126 | */ |
| 127 | struct tpml_digest_values { |
| 128 | u32 count; |
| 129 | struct tpmt_ha digests[TPM2_NUM_PCR_BANKS]; |
| 130 | } __packed; |
| 131 | |
| 132 | /** |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 133 | * TPM2 Structure Tags for command/response buffers. |
| 134 | * |
| 135 | * @TPM2_ST_NO_SESSIONS: the command does not need an authentication. |
| 136 | * @TPM2_ST_SESSIONS: the command needs an authentication. |
| 137 | */ |
| 138 | enum tpm2_structures { |
| 139 | TPM2_ST_NO_SESSIONS = 0x8001, |
| 140 | TPM2_ST_SESSIONS = 0x8002, |
| 141 | }; |
| 142 | |
| 143 | /** |
| 144 | * TPM2 type of boolean. |
| 145 | */ |
| 146 | enum tpm2_yes_no { |
| 147 | TPMI_YES = 1, |
| 148 | TPMI_NO = 0, |
| 149 | }; |
| 150 | |
| 151 | /** |
| 152 | * TPM2 startup values. |
| 153 | * |
| 154 | * @TPM2_SU_CLEAR: reset the internal state. |
| 155 | * @TPM2_SU_STATE: restore saved state (if any). |
| 156 | */ |
| 157 | enum tpm2_startup_types { |
| 158 | TPM2_SU_CLEAR = 0x0000, |
| 159 | TPM2_SU_STATE = 0x0001, |
| 160 | }; |
| 161 | |
| 162 | /** |
| 163 | * TPM2 permanent handles. |
| 164 | * |
| 165 | * @TPM2_RH_OWNER: refers to the 'owner' hierarchy. |
| 166 | * @TPM2_RS_PW: indicates a password. |
| 167 | * @TPM2_RH_LOCKOUT: refers to the 'lockout' hierarchy. |
| 168 | * @TPM2_RH_ENDORSEMENT: refers to the 'endorsement' hierarchy. |
| 169 | * @TPM2_RH_PLATFORM: refers to the 'platform' hierarchy. |
| 170 | */ |
| 171 | enum tpm2_handles { |
| 172 | TPM2_RH_OWNER = 0x40000001, |
| 173 | TPM2_RS_PW = 0x40000009, |
| 174 | TPM2_RH_LOCKOUT = 0x4000000A, |
| 175 | TPM2_RH_ENDORSEMENT = 0x4000000B, |
| 176 | TPM2_RH_PLATFORM = 0x4000000C, |
| 177 | }; |
| 178 | |
| 179 | /** |
| 180 | * TPM2 command codes used at the beginning of a buffer, gives the command. |
| 181 | * |
| 182 | * @TPM2_CC_STARTUP: TPM2_Startup(). |
| 183 | * @TPM2_CC_SELF_TEST: TPM2_SelfTest(). |
| 184 | * @TPM2_CC_CLEAR: TPM2_Clear(). |
| 185 | * @TPM2_CC_CLEARCONTROL: TPM2_ClearControl(). |
| 186 | * @TPM2_CC_HIERCHANGEAUTH: TPM2_HierarchyChangeAuth(). |
| 187 | * @TPM2_CC_PCR_SETAUTHPOL: TPM2_PCR_SetAuthPolicy(). |
| 188 | * @TPM2_CC_DAM_RESET: TPM2_DictionaryAttackLockReset(). |
| 189 | * @TPM2_CC_DAM_PARAMETERS: TPM2_DictionaryAttackParameters(). |
| 190 | * @TPM2_CC_GET_CAPABILITY: TPM2_GetCapibility(). |
Dhananjay Phadke | 7a2cf2e | 2020-06-04 16:43:59 -0700 | [diff] [blame] | 191 | * @TPM2_CC_GET_RANDOM: TPM2_GetRandom(). |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 192 | * @TPM2_CC_PCR_READ: TPM2_PCR_Read(). |
| 193 | * @TPM2_CC_PCR_EXTEND: TPM2_PCR_Extend(). |
| 194 | * @TPM2_CC_PCR_SETAUTHVAL: TPM2_PCR_SetAuthValue(). |
| 195 | */ |
| 196 | enum tpm2_command_codes { |
| 197 | TPM2_CC_STARTUP = 0x0144, |
| 198 | TPM2_CC_SELF_TEST = 0x0143, |
Simon Glass | 77759db | 2021-02-06 14:23:42 -0700 | [diff] [blame] | 199 | TPM2_CC_HIER_CONTROL = 0x0121, |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 200 | TPM2_CC_CLEAR = 0x0126, |
| 201 | TPM2_CC_CLEARCONTROL = 0x0127, |
| 202 | TPM2_CC_HIERCHANGEAUTH = 0x0129, |
Simon Glass | 713c58a | 2021-02-06 14:23:39 -0700 | [diff] [blame] | 203 | TPM2_CC_NV_DEFINE_SPACE = 0x012a, |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 204 | TPM2_CC_PCR_SETAUTHPOL = 0x012C, |
Simon Glass | 3d930ed | 2021-02-06 14:23:40 -0700 | [diff] [blame] | 205 | TPM2_CC_NV_WRITE = 0x0137, |
Simon Glass | e9d3d59 | 2021-02-06 14:23:41 -0700 | [diff] [blame] | 206 | TPM2_CC_NV_WRITELOCK = 0x0138, |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 207 | TPM2_CC_DAM_RESET = 0x0139, |
| 208 | TPM2_CC_DAM_PARAMETERS = 0x013A, |
Simon Glass | 5ff3f16 | 2018-10-01 11:55:17 -0600 | [diff] [blame] | 209 | TPM2_CC_NV_READ = 0x014E, |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 210 | TPM2_CC_GET_CAPABILITY = 0x017A, |
Dhananjay Phadke | 7a2cf2e | 2020-06-04 16:43:59 -0700 | [diff] [blame] | 211 | TPM2_CC_GET_RANDOM = 0x017B, |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 212 | TPM2_CC_PCR_READ = 0x017E, |
| 213 | TPM2_CC_PCR_EXTEND = 0x0182, |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 214 | TPM2_CC_PCR_SETAUTHVAL = 0x0183, |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 215 | }; |
| 216 | |
| 217 | /** |
| 218 | * TPM2 return codes. |
| 219 | */ |
| 220 | enum tpm2_return_codes { |
| 221 | TPM2_RC_SUCCESS = 0x0000, |
| 222 | TPM2_RC_BAD_TAG = 0x001E, |
| 223 | TPM2_RC_FMT1 = 0x0080, |
| 224 | TPM2_RC_HASH = TPM2_RC_FMT1 + 0x0003, |
| 225 | TPM2_RC_VALUE = TPM2_RC_FMT1 + 0x0004, |
| 226 | TPM2_RC_SIZE = TPM2_RC_FMT1 + 0x0015, |
| 227 | TPM2_RC_BAD_AUTH = TPM2_RC_FMT1 + 0x0022, |
| 228 | TPM2_RC_HANDLE = TPM2_RC_FMT1 + 0x000B, |
| 229 | TPM2_RC_VER1 = 0x0100, |
| 230 | TPM2_RC_INITIALIZE = TPM2_RC_VER1 + 0x0000, |
| 231 | TPM2_RC_FAILURE = TPM2_RC_VER1 + 0x0001, |
| 232 | TPM2_RC_DISABLED = TPM2_RC_VER1 + 0x0020, |
| 233 | TPM2_RC_AUTH_MISSING = TPM2_RC_VER1 + 0x0025, |
| 234 | TPM2_RC_COMMAND_CODE = TPM2_RC_VER1 + 0x0043, |
| 235 | TPM2_RC_AUTHSIZE = TPM2_RC_VER1 + 0x0044, |
| 236 | TPM2_RC_AUTH_CONTEXT = TPM2_RC_VER1 + 0x0045, |
Simon Glass | 77759db | 2021-02-06 14:23:42 -0700 | [diff] [blame] | 237 | TPM2_RC_NV_DEFINED = TPM2_RC_VER1 + 0x004c, |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 238 | TPM2_RC_NEEDS_TEST = TPM2_RC_VER1 + 0x0053, |
| 239 | TPM2_RC_WARN = 0x0900, |
| 240 | TPM2_RC_TESTING = TPM2_RC_WARN + 0x000A, |
| 241 | TPM2_RC_REFERENCE_H0 = TPM2_RC_WARN + 0x0010, |
| 242 | TPM2_RC_LOCKOUT = TPM2_RC_WARN + 0x0021, |
| 243 | }; |
| 244 | |
| 245 | /** |
| 246 | * TPM2 algorithms. |
| 247 | */ |
| 248 | enum tpm2_algorithms { |
Ilias Apalodimas | f4e0590 | 2020-11-11 11:18:10 +0200 | [diff] [blame] | 249 | TPM2_ALG_SHA1 = 0x04, |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 250 | TPM2_ALG_XOR = 0x0A, |
| 251 | TPM2_ALG_SHA256 = 0x0B, |
| 252 | TPM2_ALG_SHA384 = 0x0C, |
| 253 | TPM2_ALG_SHA512 = 0x0D, |
| 254 | TPM2_ALG_NULL = 0x10, |
Ilias Apalodimas | f4e0590 | 2020-11-11 11:18:10 +0200 | [diff] [blame] | 255 | TPM2_ALG_SM3_256 = 0x12, |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 256 | }; |
| 257 | |
Tim Harvey | 6ea1e05 | 2024-05-25 13:00:48 -0700 | [diff] [blame] | 258 | /** |
| 259 | * struct digest_info - details of supported digests |
| 260 | * |
| 261 | * @hash_name: hash name |
| 262 | * @hash_alg: hash algorithm id |
| 263 | * @hash_mask: hash registry mask |
| 264 | * @hash_len: hash digest length |
| 265 | */ |
| 266 | struct digest_info { |
| 267 | const char *hash_name; |
| 268 | u16 hash_alg; |
| 269 | u32 hash_mask; |
| 270 | u16 hash_len; |
Raymond Mao | 4315812 | 2024-12-24 08:01:07 -0800 | [diff] [blame] | 271 | bool supported; |
Tim Harvey | 6ea1e05 | 2024-05-25 13:00:48 -0700 | [diff] [blame] | 272 | }; |
| 273 | |
| 274 | /* Algorithm Registry */ |
| 275 | #define TCG2_BOOT_HASH_ALG_SHA1 0x00000001 |
| 276 | #define TCG2_BOOT_HASH_ALG_SHA256 0x00000002 |
| 277 | #define TCG2_BOOT_HASH_ALG_SHA384 0x00000004 |
| 278 | #define TCG2_BOOT_HASH_ALG_SHA512 0x00000008 |
| 279 | #define TCG2_BOOT_HASH_ALG_SM3_256 0x00000010 |
| 280 | |
| 281 | static const struct digest_info hash_algo_list[] = { |
| 282 | { |
| 283 | "sha1", |
| 284 | TPM2_ALG_SHA1, |
| 285 | TCG2_BOOT_HASH_ALG_SHA1, |
| 286 | TPM2_SHA1_DIGEST_SIZE, |
Raymond Mao | 4315812 | 2024-12-24 08:01:07 -0800 | [diff] [blame] | 287 | #if IS_ENABLED(CONFIG_SHA1) |
| 288 | true, |
| 289 | #else |
| 290 | false, |
Ilias Apalodimas | 1e665f9 | 2024-06-23 14:48:18 +0300 | [diff] [blame] | 291 | #endif |
Raymond Mao | 4315812 | 2024-12-24 08:01:07 -0800 | [diff] [blame] | 292 | }, |
Tim Harvey | 6ea1e05 | 2024-05-25 13:00:48 -0700 | [diff] [blame] | 293 | { |
| 294 | "sha256", |
| 295 | TPM2_ALG_SHA256, |
| 296 | TCG2_BOOT_HASH_ALG_SHA256, |
| 297 | TPM2_SHA256_DIGEST_SIZE, |
Raymond Mao | 4315812 | 2024-12-24 08:01:07 -0800 | [diff] [blame] | 298 | #if IS_ENABLED(CONFIG_SHA256) |
| 299 | true, |
| 300 | #else |
| 301 | false, |
Ilias Apalodimas | 1e665f9 | 2024-06-23 14:48:18 +0300 | [diff] [blame] | 302 | #endif |
Raymond Mao | 4315812 | 2024-12-24 08:01:07 -0800 | [diff] [blame] | 303 | }, |
Tim Harvey | 6ea1e05 | 2024-05-25 13:00:48 -0700 | [diff] [blame] | 304 | { |
| 305 | "sha384", |
| 306 | TPM2_ALG_SHA384, |
| 307 | TCG2_BOOT_HASH_ALG_SHA384, |
| 308 | TPM2_SHA384_DIGEST_SIZE, |
Raymond Mao | 4315812 | 2024-12-24 08:01:07 -0800 | [diff] [blame] | 309 | #if IS_ENABLED(CONFIG_SHA384) |
| 310 | true, |
| 311 | #else |
| 312 | false, |
Ilias Apalodimas | 1e665f9 | 2024-06-23 14:48:18 +0300 | [diff] [blame] | 313 | #endif |
Raymond Mao | 4315812 | 2024-12-24 08:01:07 -0800 | [diff] [blame] | 314 | }, |
Tim Harvey | 6ea1e05 | 2024-05-25 13:00:48 -0700 | [diff] [blame] | 315 | { |
| 316 | "sha512", |
| 317 | TPM2_ALG_SHA512, |
| 318 | TCG2_BOOT_HASH_ALG_SHA512, |
| 319 | TPM2_SHA512_DIGEST_SIZE, |
Raymond Mao | 4315812 | 2024-12-24 08:01:07 -0800 | [diff] [blame] | 320 | #if IS_ENABLED(CONFIG_SHA512) |
| 321 | true, |
| 322 | #else |
| 323 | false, |
Ilias Apalodimas | 1e665f9 | 2024-06-23 14:48:18 +0300 | [diff] [blame] | 324 | #endif |
Raymond Mao | 4315812 | 2024-12-24 08:01:07 -0800 | [diff] [blame] | 325 | }, |
Tim Harvey | 6ea1e05 | 2024-05-25 13:00:48 -0700 | [diff] [blame] | 326 | }; |
Eddie James | 8ed7bb3 | 2023-10-24 10:43:49 -0500 | [diff] [blame] | 327 | |
Simon Glass | b4ebd1f | 2018-11-23 21:29:34 -0700 | [diff] [blame] | 328 | /* NV index attributes */ |
| 329 | enum tpm_index_attrs { |
| 330 | TPMA_NV_PPWRITE = 1UL << 0, |
| 331 | TPMA_NV_OWNERWRITE = 1UL << 1, |
| 332 | TPMA_NV_AUTHWRITE = 1UL << 2, |
| 333 | TPMA_NV_POLICYWRITE = 1UL << 3, |
| 334 | TPMA_NV_COUNTER = 1UL << 4, |
| 335 | TPMA_NV_BITS = 1UL << 5, |
| 336 | TPMA_NV_EXTEND = 1UL << 6, |
| 337 | TPMA_NV_POLICY_DELETE = 1UL << 10, |
| 338 | TPMA_NV_WRITELOCKED = 1UL << 11, |
| 339 | TPMA_NV_WRITEALL = 1UL << 12, |
| 340 | TPMA_NV_WRITEDEFINE = 1UL << 13, |
| 341 | TPMA_NV_WRITE_STCLEAR = 1UL << 14, |
| 342 | TPMA_NV_GLOBALLOCK = 1UL << 15, |
| 343 | TPMA_NV_PPREAD = 1UL << 16, |
| 344 | TPMA_NV_OWNERREAD = 1UL << 17, |
| 345 | TPMA_NV_AUTHREAD = 1UL << 18, |
| 346 | TPMA_NV_POLICYREAD = 1UL << 19, |
| 347 | TPMA_NV_NO_DA = 1UL << 25, |
| 348 | TPMA_NV_ORDERLY = 1UL << 26, |
| 349 | TPMA_NV_CLEAR_STCLEAR = 1UL << 27, |
| 350 | TPMA_NV_READLOCKED = 1UL << 28, |
| 351 | TPMA_NV_WRITTEN = 1UL << 29, |
| 352 | TPMA_NV_PLATFORMCREATE = 1UL << 30, |
| 353 | TPMA_NV_READ_STCLEAR = 1UL << 31, |
| 354 | |
| 355 | TPMA_NV_MASK_READ = TPMA_NV_PPREAD | TPMA_NV_OWNERREAD | |
| 356 | TPMA_NV_AUTHREAD | TPMA_NV_POLICYREAD, |
| 357 | TPMA_NV_MASK_WRITE = TPMA_NV_PPWRITE | TPMA_NV_OWNERWRITE | |
| 358 | TPMA_NV_AUTHWRITE | TPMA_NV_POLICYWRITE, |
| 359 | }; |
| 360 | |
Simon Glass | e1ed0ec | 2020-02-06 09:55:03 -0700 | [diff] [blame] | 361 | enum { |
| 362 | TPM_ACCESS_VALID = 1 << 7, |
| 363 | TPM_ACCESS_ACTIVE_LOCALITY = 1 << 5, |
| 364 | TPM_ACCESS_REQUEST_PENDING = 1 << 2, |
| 365 | TPM_ACCESS_REQUEST_USE = 1 << 1, |
| 366 | TPM_ACCESS_ESTABLISHMENT = 1 << 0, |
| 367 | }; |
| 368 | |
| 369 | enum { |
| 370 | TPM_STS_FAMILY_SHIFT = 26, |
| 371 | TPM_STS_FAMILY_MASK = 0x3 << TPM_STS_FAMILY_SHIFT, |
| 372 | TPM_STS_FAMILY_TPM2 = 1 << TPM_STS_FAMILY_SHIFT, |
| 373 | TPM_STS_RESE_TESTABLISMENT_BIT = 1 << 25, |
| 374 | TPM_STS_COMMAND_CANCEL = 1 << 24, |
| 375 | TPM_STS_BURST_COUNT_SHIFT = 8, |
| 376 | TPM_STS_BURST_COUNT_MASK = 0xffff << TPM_STS_BURST_COUNT_SHIFT, |
| 377 | TPM_STS_VALID = 1 << 7, |
| 378 | TPM_STS_COMMAND_READY = 1 << 6, |
| 379 | TPM_STS_GO = 1 << 5, |
| 380 | TPM_STS_DATA_AVAIL = 1 << 4, |
| 381 | TPM_STS_DATA_EXPECT = 1 << 3, |
| 382 | TPM_STS_SELF_TEST_DONE = 1 << 2, |
| 383 | TPM_STS_RESPONSE_RETRY = 1 << 1, |
Ilias Apalodimas | 97f5e2d | 2021-11-09 09:02:17 +0200 | [diff] [blame] | 384 | TPM_STS_READ_ZERO = 0x23 |
Simon Glass | e1ed0ec | 2020-02-06 09:55:03 -0700 | [diff] [blame] | 385 | }; |
| 386 | |
| 387 | enum { |
| 388 | TPM_CMD_COUNT_OFFSET = 2, |
| 389 | TPM_CMD_ORDINAL_OFFSET = 6, |
| 390 | TPM_MAX_BUF_SIZE = 1260, |
| 391 | }; |
| 392 | |
Simon Glass | 3d930ed | 2021-02-06 14:23:40 -0700 | [diff] [blame] | 393 | enum { |
| 394 | /* Secure storage for firmware settings */ |
| 395 | TPM_HT_PCR = 0, |
| 396 | TPM_HT_NV_INDEX, |
| 397 | TPM_HT_HMAC_SESSION, |
| 398 | TPM_HT_POLICY_SESSION, |
| 399 | |
| 400 | HR_SHIFT = 24, |
| 401 | HR_PCR = TPM_HT_PCR << HR_SHIFT, |
| 402 | HR_HMAC_SESSION = TPM_HT_HMAC_SESSION << HR_SHIFT, |
| 403 | HR_POLICY_SESSION = TPM_HT_POLICY_SESSION << HR_SHIFT, |
| 404 | HR_NV_INDEX = TPM_HT_NV_INDEX << HR_SHIFT, |
| 405 | }; |
| 406 | |
Miquel Raynal | 65a1a6c | 2018-05-15 11:57:12 +0200 | [diff] [blame] | 407 | /** |
| 408 | * Issue a TPM2_Startup command. |
| 409 | * |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 410 | * @dev TPM device |
Miquel Raynal | 65a1a6c | 2018-05-15 11:57:12 +0200 | [diff] [blame] | 411 | * @mode TPM startup mode |
| 412 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 413 | * Return: code of the operation |
Miquel Raynal | 65a1a6c | 2018-05-15 11:57:12 +0200 | [diff] [blame] | 414 | */ |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 415 | u32 tpm2_startup(struct udevice *dev, enum tpm2_startup_types mode); |
Miquel Raynal | 65a1a6c | 2018-05-15 11:57:12 +0200 | [diff] [blame] | 416 | |
Miquel Raynal | 39c7608 | 2018-05-15 11:57:13 +0200 | [diff] [blame] | 417 | /** |
| 418 | * Issue a TPM2_SelfTest command. |
| 419 | * |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 420 | * @dev TPM device |
Miquel Raynal | 39c7608 | 2018-05-15 11:57:13 +0200 | [diff] [blame] | 421 | * @full_test Asking to perform all tests or only the untested ones |
| 422 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 423 | * Return: code of the operation |
Miquel Raynal | 39c7608 | 2018-05-15 11:57:13 +0200 | [diff] [blame] | 424 | */ |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 425 | u32 tpm2_self_test(struct udevice *dev, enum tpm2_yes_no full_test); |
Miquel Raynal | 39c7608 | 2018-05-15 11:57:13 +0200 | [diff] [blame] | 426 | |
Miquel Raynal | 8df6f8d | 2018-05-15 11:57:14 +0200 | [diff] [blame] | 427 | /** |
| 428 | * Issue a TPM2_Clear command. |
| 429 | * |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 430 | * @dev TPM device |
Miquel Raynal | 8df6f8d | 2018-05-15 11:57:14 +0200 | [diff] [blame] | 431 | * @handle Handle |
| 432 | * @pw Password |
| 433 | * @pw_sz Length of the password |
| 434 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 435 | * Return: code of the operation |
Miquel Raynal | 8df6f8d | 2018-05-15 11:57:14 +0200 | [diff] [blame] | 436 | */ |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 437 | u32 tpm2_clear(struct udevice *dev, u32 handle, const char *pw, |
| 438 | const ssize_t pw_sz); |
Miquel Raynal | 8df6f8d | 2018-05-15 11:57:14 +0200 | [diff] [blame] | 439 | |
Miquel Raynal | 14d7235 | 2018-05-15 11:57:15 +0200 | [diff] [blame] | 440 | /** |
Simon Glass | 713c58a | 2021-02-06 14:23:39 -0700 | [diff] [blame] | 441 | * Issue a TPM_NV_DefineSpace command |
| 442 | * |
| 443 | * This allows a space to be defined with given attributes and policy |
| 444 | * |
| 445 | * @dev TPM device |
| 446 | * @space_index index of the area |
| 447 | * @space_size size of area in bytes |
| 448 | * @nv_attributes TPM_NV_ATTRIBUTES of the area |
| 449 | * @nv_policy policy to use |
| 450 | * @nv_policy_size size of the policy |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 451 | * Return: return code of the operation |
Simon Glass | 713c58a | 2021-02-06 14:23:39 -0700 | [diff] [blame] | 452 | */ |
| 453 | u32 tpm2_nv_define_space(struct udevice *dev, u32 space_index, |
| 454 | size_t space_size, u32 nv_attributes, |
| 455 | const u8 *nv_policy, size_t nv_policy_size); |
| 456 | |
| 457 | /** |
Miquel Raynal | 14d7235 | 2018-05-15 11:57:15 +0200 | [diff] [blame] | 458 | * Issue a TPM2_PCR_Extend command. |
| 459 | * |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 460 | * @dev TPM device |
Miquel Raynal | 14d7235 | 2018-05-15 11:57:15 +0200 | [diff] [blame] | 461 | * @index Index of the PCR |
Ilias Apalodimas | 7f59c71 | 2020-11-26 23:07:22 +0200 | [diff] [blame] | 462 | * @algorithm Algorithm used, defined in 'enum tpm2_algorithms' |
Miquel Raynal | 14d7235 | 2018-05-15 11:57:15 +0200 | [diff] [blame] | 463 | * @digest Value representing the event to be recorded |
Ilias Apalodimas | 7f59c71 | 2020-11-26 23:07:22 +0200 | [diff] [blame] | 464 | * @digest_len len of the hash |
Miquel Raynal | 14d7235 | 2018-05-15 11:57:15 +0200 | [diff] [blame] | 465 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 466 | * Return: code of the operation |
Miquel Raynal | 14d7235 | 2018-05-15 11:57:15 +0200 | [diff] [blame] | 467 | */ |
Ilias Apalodimas | 7f59c71 | 2020-11-26 23:07:22 +0200 | [diff] [blame] | 468 | u32 tpm2_pcr_extend(struct udevice *dev, u32 index, u32 algorithm, |
| 469 | const u8 *digest, u32 digest_len); |
Miquel Raynal | 14d7235 | 2018-05-15 11:57:15 +0200 | [diff] [blame] | 470 | |
Miquel Raynal | 4c1a585 | 2018-05-15 11:57:16 +0200 | [diff] [blame] | 471 | /** |
Simon Glass | 3d930ed | 2021-02-06 14:23:40 -0700 | [diff] [blame] | 472 | * Read data from the secure storage |
| 473 | * |
| 474 | * @dev TPM device |
| 475 | * @index Index of data to read |
| 476 | * @data Place to put data |
| 477 | * @count Number of bytes of data |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 478 | * Return: code of the operation |
Simon Glass | 3d930ed | 2021-02-06 14:23:40 -0700 | [diff] [blame] | 479 | */ |
| 480 | u32 tpm2_nv_read_value(struct udevice *dev, u32 index, void *data, u32 count); |
| 481 | |
| 482 | /** |
| 483 | * Write data to the secure storage |
| 484 | * |
| 485 | * @dev TPM device |
| 486 | * @index Index of data to write |
| 487 | * @data Data to write |
| 488 | * @count Number of bytes of data |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 489 | * Return: code of the operation |
Simon Glass | 3d930ed | 2021-02-06 14:23:40 -0700 | [diff] [blame] | 490 | */ |
| 491 | u32 tpm2_nv_write_value(struct udevice *dev, u32 index, const void *data, |
| 492 | u32 count); |
| 493 | |
| 494 | /** |
Miquel Raynal | 4c1a585 | 2018-05-15 11:57:16 +0200 | [diff] [blame] | 495 | * Issue a TPM2_PCR_Read command. |
| 496 | * |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 497 | * @dev TPM device |
Miquel Raynal | 4c1a585 | 2018-05-15 11:57:16 +0200 | [diff] [blame] | 498 | * @idx Index of the PCR |
| 499 | * @idx_min_sz Minimum size in bytes of the pcrSelect array |
Ruchika Gupta | 686bedb | 2021-11-29 13:09:45 +0530 | [diff] [blame] | 500 | * @algorithm Algorithm used, defined in 'enum tpm2_algorithms' |
Miquel Raynal | 4c1a585 | 2018-05-15 11:57:16 +0200 | [diff] [blame] | 501 | * @data Output buffer for contents of the named PCR |
Ruchika Gupta | 686bedb | 2021-11-29 13:09:45 +0530 | [diff] [blame] | 502 | * @digest_len len of the data |
Miquel Raynal | 4c1a585 | 2018-05-15 11:57:16 +0200 | [diff] [blame] | 503 | * @updates Optional out parameter: number of updates for this PCR |
| 504 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 505 | * Return: code of the operation |
Miquel Raynal | 4c1a585 | 2018-05-15 11:57:16 +0200 | [diff] [blame] | 506 | */ |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 507 | u32 tpm2_pcr_read(struct udevice *dev, u32 idx, unsigned int idx_min_sz, |
Ruchika Gupta | 686bedb | 2021-11-29 13:09:45 +0530 | [diff] [blame] | 508 | u16 algorithm, void *data, u32 digest_len, |
| 509 | unsigned int *updates); |
Miquel Raynal | 4c1a585 | 2018-05-15 11:57:16 +0200 | [diff] [blame] | 510 | |
Miquel Raynal | 2e52c06 | 2018-05-15 11:57:17 +0200 | [diff] [blame] | 511 | /** |
| 512 | * Issue a TPM2_GetCapability command. This implementation is limited |
| 513 | * to query property index that is 4-byte wide. |
| 514 | * |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 515 | * @dev TPM device |
Miquel Raynal | 2e52c06 | 2018-05-15 11:57:17 +0200 | [diff] [blame] | 516 | * @capability Partition of capabilities |
| 517 | * @property Further definition of capability, limited to be 4 bytes wide |
| 518 | * @buf Output buffer for capability information |
| 519 | * @prop_count Size of output buffer |
| 520 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 521 | * Return: code of the operation |
Miquel Raynal | 2e52c06 | 2018-05-15 11:57:17 +0200 | [diff] [blame] | 522 | */ |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 523 | u32 tpm2_get_capability(struct udevice *dev, u32 capability, u32 property, |
| 524 | void *buf, size_t prop_count); |
Miquel Raynal | 2e52c06 | 2018-05-15 11:57:17 +0200 | [diff] [blame] | 525 | |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 526 | /** |
Eddie James | 8ed7bb3 | 2023-10-24 10:43:49 -0500 | [diff] [blame] | 527 | * tpm2_get_pcr_info() - get the supported, active PCRs and number of banks |
| 528 | * |
| 529 | * @dev: TPM device |
Ilias Apalodimas | cb35661 | 2024-06-23 14:48:17 +0300 | [diff] [blame] | 530 | * @pcrs: struct tpml_pcr_selection of available PCRs |
Eddie James | 8ed7bb3 | 2023-10-24 10:43:49 -0500 | [diff] [blame] | 531 | * |
| 532 | * @return 0 on success, code of operation or negative errno on failure |
| 533 | */ |
Ilias Apalodimas | cb35661 | 2024-06-23 14:48:17 +0300 | [diff] [blame] | 534 | int tpm2_get_pcr_info(struct udevice *dev, struct tpml_pcr_selection *pcrs); |
Eddie James | 8ed7bb3 | 2023-10-24 10:43:49 -0500 | [diff] [blame] | 535 | |
| 536 | /** |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 537 | * Issue a TPM2_DictionaryAttackLockReset command. |
| 538 | * |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 539 | * @dev TPM device |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 540 | * @pw Password |
| 541 | * @pw_sz Length of the password |
| 542 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 543 | * Return: code of the operation |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 544 | */ |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 545 | u32 tpm2_dam_reset(struct udevice *dev, const char *pw, const ssize_t pw_sz); |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 546 | |
| 547 | /** |
| 548 | * Issue a TPM2_DictionaryAttackParameters command. |
| 549 | * |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 550 | * @dev TPM device |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 551 | * @pw Password |
| 552 | * @pw_sz Length of the password |
| 553 | * @max_tries Count of authorizations before lockout |
| 554 | * @recovery_time Time before decrementation of the failure count |
| 555 | * @lockout_recovery Time to wait after a lockout |
| 556 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 557 | * Return: code of the operation |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 558 | */ |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 559 | u32 tpm2_dam_parameters(struct udevice *dev, const char *pw, |
| 560 | const ssize_t pw_sz, unsigned int max_tries, |
| 561 | unsigned int recovery_time, |
Miquel Raynal | 228e990 | 2018-05-15 11:57:18 +0200 | [diff] [blame] | 562 | unsigned int lockout_recovery); |
| 563 | |
Miquel Raynal | 05d7be3 | 2018-05-15 11:57:19 +0200 | [diff] [blame] | 564 | /** |
| 565 | * Issue a TPM2_HierarchyChangeAuth command. |
| 566 | * |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 567 | * @dev TPM device |
Miquel Raynal | 05d7be3 | 2018-05-15 11:57:19 +0200 | [diff] [blame] | 568 | * @handle Handle |
| 569 | * @newpw New password |
| 570 | * @newpw_sz Length of the new password |
| 571 | * @oldpw Old password |
| 572 | * @oldpw_sz Length of the old password |
| 573 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 574 | * Return: code of the operation |
Miquel Raynal | 05d7be3 | 2018-05-15 11:57:19 +0200 | [diff] [blame] | 575 | */ |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 576 | int tpm2_change_auth(struct udevice *dev, u32 handle, const char *newpw, |
| 577 | const ssize_t newpw_sz, const char *oldpw, |
| 578 | const ssize_t oldpw_sz); |
Miquel Raynal | 05d7be3 | 2018-05-15 11:57:19 +0200 | [diff] [blame] | 579 | |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 580 | /** |
| 581 | * Issue a TPM_PCR_SetAuthPolicy command. |
| 582 | * |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 583 | * @dev TPM device |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 584 | * @pw Platform password |
| 585 | * @pw_sz Length of the password |
| 586 | * @index Index of the PCR |
| 587 | * @digest New key to access the PCR |
| 588 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 589 | * Return: code of the operation |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 590 | */ |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 591 | u32 tpm2_pcr_setauthpolicy(struct udevice *dev, const char *pw, |
| 592 | const ssize_t pw_sz, u32 index, const char *key); |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 593 | |
| 594 | /** |
| 595 | * Issue a TPM_PCR_SetAuthValue command. |
| 596 | * |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 597 | * @dev TPM device |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 598 | * @pw Platform password |
| 599 | * @pw_sz Length of the password |
| 600 | * @index Index of the PCR |
| 601 | * @digest New key to access the PCR |
| 602 | * @key_sz Length of the new key |
| 603 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 604 | * Return: code of the operation |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 605 | */ |
Simon Glass | 8ceca1d | 2018-11-18 14:22:27 -0700 | [diff] [blame] | 606 | u32 tpm2_pcr_setauthvalue(struct udevice *dev, const char *pw, |
| 607 | const ssize_t pw_sz, u32 index, const char *key, |
| 608 | const ssize_t key_sz); |
Miquel Raynal | 0b864f6 | 2018-05-15 11:57:20 +0200 | [diff] [blame] | 609 | |
Dhananjay Phadke | 7a2cf2e | 2020-06-04 16:43:59 -0700 | [diff] [blame] | 610 | /** |
| 611 | * Issue a TPM2_GetRandom command. |
| 612 | * |
| 613 | * @dev TPM device |
| 614 | * @param data output buffer for the random bytes |
| 615 | * @param count size of output buffer |
| 616 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 617 | * Return: return code of the operation |
Dhananjay Phadke | 7a2cf2e | 2020-06-04 16:43:59 -0700 | [diff] [blame] | 618 | */ |
| 619 | u32 tpm2_get_random(struct udevice *dev, void *data, u32 count); |
| 620 | |
Simon Glass | e9d3d59 | 2021-02-06 14:23:41 -0700 | [diff] [blame] | 621 | /** |
| 622 | * Lock data in the TPM |
| 623 | * |
| 624 | * Once locked the data cannot be written until after a reboot |
| 625 | * |
| 626 | * @dev TPM device |
| 627 | * @index Index of data to lock |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 628 | * Return: code of the operation |
Simon Glass | e9d3d59 | 2021-02-06 14:23:41 -0700 | [diff] [blame] | 629 | */ |
| 630 | u32 tpm2_write_lock(struct udevice *dev, u32 index); |
| 631 | |
Simon Glass | 77759db | 2021-02-06 14:23:42 -0700 | [diff] [blame] | 632 | /** |
| 633 | * Disable access to any platform data |
| 634 | * |
| 635 | * This can be called to close off access to the firmware data in the data, |
| 636 | * before calling the kernel. |
| 637 | * |
| 638 | * @dev TPM device |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 639 | * Return: code of the operation |
Simon Glass | 77759db | 2021-02-06 14:23:42 -0700 | [diff] [blame] | 640 | */ |
| 641 | u32 tpm2_disable_platform_hierarchy(struct udevice *dev); |
| 642 | |
Masahisa Kojima | 06ef6b6 | 2021-11-04 22:59:16 +0900 | [diff] [blame] | 643 | /** |
| 644 | * submit user specified data to the TPM and get response |
| 645 | * |
| 646 | * @dev TPM device |
| 647 | * @sendbuf: Buffer of the data to send |
| 648 | * @recvbuf: Buffer to save the response to |
| 649 | * @recv_size: Pointer to the size of the response buffer |
| 650 | * |
Heinrich Schuchardt | 47b4c02 | 2022-01-19 18:05:50 +0100 | [diff] [blame] | 651 | * Return: code of the operation |
Masahisa Kojima | 06ef6b6 | 2021-11-04 22:59:16 +0900 | [diff] [blame] | 652 | */ |
| 653 | u32 tpm2_submit_command(struct udevice *dev, const u8 *sendbuf, |
| 654 | u8 *recvbuf, size_t *recv_size); |
| 655 | |
Simon Glass | 3f7a73a | 2022-08-30 21:05:37 -0600 | [diff] [blame] | 656 | /** |
| 657 | * tpm_cr50_report_state() - Report the Cr50 internal state |
| 658 | * |
| 659 | * @dev: TPM device |
| 660 | * @vendor_cmd: Vendor command number to send |
| 661 | * @vendor_subcmd: Vendor sub-command number to send |
| 662 | * @recvbuf: Buffer to save the response to |
| 663 | * @recv_size: Pointer to the size of the response buffer |
| 664 | * Return: result of the operation |
| 665 | */ |
| 666 | u32 tpm2_report_state(struct udevice *dev, uint vendor_cmd, uint vendor_subcmd, |
| 667 | u8 *recvbuf, size_t *recv_size); |
| 668 | |
Simon Glass | 3564b8e | 2022-08-30 21:05:38 -0600 | [diff] [blame] | 669 | /** |
| 670 | * tpm2_enable_nvcommits() - Tell TPM to commit NV data immediately |
| 671 | * |
| 672 | * For Chromium OS verified boot, we may reboot or reset at different times, |
| 673 | * possibly leaving non-volatile data unwritten by the TPM. |
| 674 | * |
| 675 | * This vendor command is used to indicate that non-volatile data should be |
| 676 | * written to its store immediately. |
| 677 | * |
| 678 | * @dev TPM device |
| 679 | * @vendor_cmd: Vendor command number to send |
| 680 | * @vendor_subcmd: Vendor sub-command number to send |
| 681 | * Return: result of the operation |
| 682 | */ |
| 683 | u32 tpm2_enable_nvcommits(struct udevice *dev, uint vendor_cmd, |
| 684 | uint vendor_subcmd); |
| 685 | |
Ilias Apalodimas | 42d7bdf | 2023-01-25 12:18:36 +0200 | [diff] [blame] | 686 | /** |
| 687 | * tpm2_auto_start() - start up the TPM and perform selftests. |
| 688 | * If a testable function has not been tested and is |
| 689 | * requested the TPM2 will return TPM_RC_NEEDS_TEST. |
| 690 | * |
| 691 | * @param dev TPM device |
| 692 | * Return: TPM2_RC_TESTING, if TPM2 self-test is in progress. |
| 693 | * TPM2_RC_SUCCESS, if testing of all functions is complete without |
| 694 | * functional failures. |
| 695 | * TPM2_RC_FAILURE, if any test failed. |
| 696 | * TPM2_RC_INITIALIZE, if the TPM has not gone through the Startup |
| 697 | * sequence |
| 698 | |
| 699 | */ |
| 700 | u32 tpm2_auto_start(struct udevice *dev); |
| 701 | |
Tim Harvey | 6ea1e05 | 2024-05-25 13:00:48 -0700 | [diff] [blame] | 702 | /** |
| 703 | * tpm2_name_to_algorithm() - Return an algorithm id given a supported |
| 704 | * algorithm name |
| 705 | * |
| 706 | * @name: algorithm name |
| 707 | * Return: enum tpm2_algorithms or -EINVAL |
| 708 | */ |
| 709 | enum tpm2_algorithms tpm2_name_to_algorithm(const char *name); |
| 710 | |
| 711 | /** |
| 712 | * tpm2_algorithm_name() - Return an algorithm name string for a |
| 713 | * supported algorithm id |
| 714 | * |
| 715 | * @algorithm_id: algorithm defined in enum tpm2_algorithms |
| 716 | * Return: algorithm name string or "" |
| 717 | */ |
| 718 | const char *tpm2_algorithm_name(enum tpm2_algorithms); |
| 719 | |
Ilias Apalodimas | cb35661 | 2024-06-23 14:48:17 +0300 | [diff] [blame] | 720 | /** |
Raymond Mao | 4315812 | 2024-12-24 08:01:07 -0800 | [diff] [blame] | 721 | * tpm2_algorithm_supported() - Check if the algorithm supported by U-Boot |
| 722 | * |
| 723 | * @algorithm_id: algorithm defined in enum tpm2_algorithms |
| 724 | * Return: true if supported, otherwise false |
| 725 | */ |
| 726 | bool tpm2_algorithm_supported(enum tpm2_algorithms algo); |
| 727 | |
| 728 | /** |
Ilias Apalodimas | 1e665f9 | 2024-06-23 14:48:18 +0300 | [diff] [blame] | 729 | * tpm2_algorithm_to_len() - Return an algorithm length for supported algorithm id |
| 730 | * |
| 731 | * @algorithm_id: algorithm defined in enum tpm2_algorithms |
| 732 | * Return: len or 0 if not supported |
| 733 | */ |
| 734 | u16 tpm2_algorithm_to_len(enum tpm2_algorithms algo); |
| 735 | |
| 736 | /* |
| 737 | * When measured boot is enabled via EFI or bootX commands all the algorithms |
| 738 | * above are selected by our Kconfigs. Due to U-Boots nature of being small there |
| 739 | * are cases where we need some functionality from the TPM -- e.g storage or RNG |
| 740 | * but we don't want to support measurements. |
| 741 | * |
| 742 | * The choice of hash algorithms are determined by the platform and the TPM |
| 743 | * configuration. Failing to cap a PCR in a bank which the platform left |
| 744 | * active is a security vulnerability. It permits the unsealing of secrets |
| 745 | * if an attacker can replay a good set of measurements into an unused bank. |
| 746 | * |
| 747 | * On top of that a previous stage bootloader (e.g TF-A), migh pass an eventlog |
| 748 | * since it doesn't have a TPM driver, which U-Boot needs to replace. The algorit h |
| 749 | * choice is a compile time option in that case and we need to make sure we conform. |
| 750 | * |
| 751 | * Add a variable here that sums the supported algorithms U-Boot was compiled |
| 752 | * with so we can refuse to do measurements if we don't support all of them |
| 753 | */ |
| 754 | |
| 755 | /** |
Ilias Apalodimas | d788b06 | 2024-12-24 08:01:05 -0800 | [diff] [blame] | 756 | * tpm2_check_active_banks() - Check if the active PCR banks are supported by |
| 757 | * our configuration |
Ilias Apalodimas | 1e665f9 | 2024-06-23 14:48:18 +0300 | [diff] [blame] | 758 | * |
| 759 | * @dev: TPM device |
| 760 | * Return: true if allowed |
| 761 | */ |
Ilias Apalodimas | d788b06 | 2024-12-24 08:01:05 -0800 | [diff] [blame] | 762 | bool tpm2_check_active_banks(struct udevice *dev); |
Ilias Apalodimas | 1e665f9 | 2024-06-23 14:48:18 +0300 | [diff] [blame] | 763 | |
| 764 | /** |
Ilias Apalodimas | 9465f7a | 2024-12-24 08:01:04 -0800 | [diff] [blame] | 765 | * tpm2_is_active_bank() - check the pcr_select. If at least one of the PCRs |
| 766 | * supports the algorithm add it on the active ones |
Ilias Apalodimas | cb35661 | 2024-06-23 14:48:17 +0300 | [diff] [blame] | 767 | * |
| 768 | * @selection: PCR selection structure |
| 769 | * Return: True if the algorithm is active |
| 770 | */ |
Ilias Apalodimas | 9465f7a | 2024-12-24 08:01:04 -0800 | [diff] [blame] | 771 | bool tpm2_is_active_bank(struct tpms_pcr_selection *selection); |
Ilias Apalodimas | cb35661 | 2024-06-23 14:48:17 +0300 | [diff] [blame] | 772 | |
Ilias Apalodimas | 7b1e522 | 2024-12-24 08:01:08 -0800 | [diff] [blame^] | 773 | /** |
| 774 | * tpm2_print_active_banks() - Print the active TPM PCRs |
| 775 | * |
| 776 | * @dev: TPM device |
| 777 | */ |
| 778 | void tpm2_print_active_banks(struct udevice *dev); |
| 779 | |
Miquel Raynal | f3b4350 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 780 | #endif /* __TPM_V2_H */ |