blob: a317e0360798c9f2aa814807d2b818f9da6bc0e5 [file] [log] [blame]
Miquel Raynalff322452018-05-15 11:57:08 +02001// 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 Raynal1922df22018-05-15 11:57:12 +020012
13u32 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 Raynal2dc6d972018-05-15 11:57:13 +020033
34u32 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}