1 // SPDX-License-Identifier: BSD-2-Clause
2 /*
3 * Copyright (c) 2022, Linaro Limited
4 */
5
6 #include <drivers/tpm2_chip.h>
7 #include <kernel/tcg.h>
8 #include <tpm2.h>
9
tpm2_tcg_get_pcr_info(uint32_t * selection_mask,uint32_t * active_mask,uint32_t * num_pcr)10 static TEE_Result tpm2_tcg_get_pcr_info(uint32_t *selection_mask,
11 uint32_t *active_mask,
12 uint32_t *num_pcr)
13 {
14 struct tpm2_caps caps = { };
15 enum tpm2_result rc = TPM2_OK;
16
17 rc = tpm2_chip_get_caps(&caps);
18 if (rc)
19 return TEE_ERROR_COMMUNICATION;
20
21 *num_pcr = caps.num_pcrs;
22 *selection_mask = caps.selection_mask;
23 *active_mask = caps.active_mask;
24
25 return TEE_SUCCESS;
26 }
27
tpm2_tcg_pcr_extend(uint8_t pcr_idx,uint16_t alg,void * digest,uint32_t digest_len)28 static TEE_Result tpm2_tcg_pcr_extend(uint8_t pcr_idx, uint16_t alg,
29 void *digest, uint32_t digest_len)
30 {
31 if (tpm2_pcr_extend(pcr_idx, alg, digest, digest_len))
32 return TEE_ERROR_GENERIC;
33
34 return TEE_SUCCESS;
35 }
36
37 static struct tcg_pcr_ops tpm2_tcg_ops = {
38 .pcr_info = tpm2_tcg_get_pcr_info,
39 .pcr_extend = tpm2_tcg_pcr_extend,
40 };
41
tpm2_tcg_register(void)42 TEE_Result tpm2_tcg_register(void)
43 {
44 return register_tcg_pcr_provider(&tpm2_tcg_ops);
45 }
46