Miquel Raynal | ff32245 | 2018-05-15 11:57:08 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2018 Bootlin |
| 4 | * Author: Miquel Raynal <miquel.raynal@bootlin.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <tpm-common.h> |
| 10 | #include <tpm-v2.h> |
| 11 | #include "tpm-utils.h" |
Miquel Raynal | 1922df2 | 2018-05-15 11:57:12 +0200 | [diff] [blame] | 12 | |
| 13 | u32 tpm2_startup(enum tpm2_startup_types mode) |
| 14 | { |
| 15 | const u8 command_v2[12] = { |
| 16 | tpm_u16(TPM2_ST_NO_SESSIONS), |
| 17 | tpm_u32(12), |
| 18 | tpm_u32(TPM2_CC_STARTUP), |
| 19 | tpm_u16(mode), |
| 20 | }; |
| 21 | int ret; |
| 22 | |
| 23 | /* |
| 24 | * Note TPM2_Startup command will return RC_SUCCESS the first time, |
| 25 | * but will return RC_INITIALIZE otherwise. |
| 26 | */ |
| 27 | ret = tpm_sendrecv_command(command_v2, NULL, NULL); |
| 28 | if (ret && ret != TPM2_RC_INITIALIZE) |
| 29 | return ret; |
| 30 | |
| 31 | return 0; |
| 32 | } |
Miquel Raynal | 2dc6d97 | 2018-05-15 11:57:13 +0200 | [diff] [blame^] | 33 | |
| 34 | u32 tpm2_self_test(enum tpm2_yes_no full_test) |
| 35 | { |
| 36 | const u8 command_v2[12] = { |
| 37 | tpm_u16(TPM2_ST_NO_SESSIONS), |
| 38 | tpm_u32(11), |
| 39 | tpm_u32(TPM2_CC_SELF_TEST), |
| 40 | full_test, |
| 41 | }; |
| 42 | |
| 43 | return tpm_sendrecv_command(command_v2, NULL, NULL); |
| 44 | } |