Abhi.Singh | c8c5faf | 2024-08-28 14:17:52 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2025, Arm Limited. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | #ifndef TPM2_H |
| 8 | #define TPM2_H |
| 9 | |
| 10 | #include <assert.h> |
| 11 | #include <endian.h> |
| 12 | #include <errno.h> |
| 13 | #include <stdint.h> |
| 14 | |
| 15 | #include <drivers/tpm/tpm2_chip.h> |
| 16 | |
| 17 | /* Return values */ |
| 18 | enum tpm_ret_value { |
| 19 | TPM_SUCCESS = 0, |
| 20 | TPM_ERR_RESPONSE = -1, |
| 21 | TPM_INVALID_PARAM = -2, |
| 22 | TPM_ERR_TIMEOUT = -3, |
| 23 | TPM_ERR_TRANSFER = -4, |
| 24 | }; |
| 25 | |
| 26 | /* |
| 27 | * TPM FIFO register space address offsets |
| 28 | */ |
| 29 | #define TPM_FIFO_REG_ACCESS 0x00 |
| 30 | #define TPM_FIFO_REG_INTR_ENABLE 0x08 |
| 31 | #define TPM_FIFO_REG_INTR_VECTOR 0x0C |
| 32 | #define TPM_FIFO_REG_INTR_STS 0x10 |
| 33 | #define TPM_FIFO_REG_INTF_CAPS 0x14 |
| 34 | #define TPM_FIFO_REG_STATUS 0x18 |
| 35 | #define TPM_FIFO_REG_BURST_COUNT_LO 0x19 |
| 36 | #define TPM_FIFO_REG_BURST_COUNT_HI 0x20 |
| 37 | #define TPM_FIFO_REG_DATA_FIFO 0x24 |
| 38 | #define TPM_FIFO_REG_VENDID 0xF00 |
| 39 | #define TPM_FIFO_REG_DEVID 0xF02 |
| 40 | #define TPM_FIFO_REG_REVID 0xF04 |
| 41 | |
| 42 | #define TPM_ST_NO_SESSIONS U(0x8001) |
| 43 | #define TPM_ST_SESSIONS U(0x8002) |
| 44 | |
| 45 | #define TPM_SU_CLEAR U(0x0000) |
| 46 | #define TPM_SU_STATE U(0x0001) |
| 47 | |
| 48 | #define TPM_MIN_AUTH_SIZE 9 |
| 49 | #define TPM_RS_PW 0x40000009 |
| 50 | #define TPM_ZERO_NONCE_SIZE 0 |
| 51 | #define TPM_ATTRIBUTES_DISABLE 0 |
| 52 | #define TPM_ZERO_HMAC_SIZE 0 |
| 53 | #define TPM_SINGLE_HASH_COUNT 1 |
| 54 | |
| 55 | |
| 56 | #define TPM_CMD_STARTUP U(0x0144) |
| 57 | #define TPM_CMD_PCR_READ U(0x017E) |
| 58 | #define TPM_CMD_PCR_EXTEND U(0x0182) |
| 59 | |
| 60 | #define TPM_RESPONSE_SUCCESS U(0x0000) |
| 61 | |
| 62 | #define TPM_ACCESS_ACTIVE_LOCALITY U(1 << 5) |
| 63 | #define TPM_ACCESS_VALID U(1 << 7) |
| 64 | #define TPM_ACCESS_RELINQUISH_LOCALITY U(1 << 5) |
| 65 | #define TPM_ACCESS_REQUEST_USE U(1 << 1) |
| 66 | #define TPM_ACCESS_REQUEST_PENDING U(1 << 2) |
| 67 | |
| 68 | #define TPM_STAT_VALID U(1 << 7) |
| 69 | #define TPM_STAT_COMMAND_READY U(1 << 6) |
| 70 | #define TPM_STAT_GO U(1 << 5) |
| 71 | #define TPM_STAT_AVAIL U(1 << 4) |
| 72 | #define TPM_STAT_EXPECT U(1 << 3) |
| 73 | |
| 74 | #define TPM_READ_HEADER -1 |
| 75 | |
| 76 | #define TPM_HEADER_SIZE 10 |
| 77 | #define MAX_SIZE_CMDBUF 256 |
| 78 | #define MAX_CMD_DATA (MAX_SIZE_CMDBUF - TPM_HEADER_SIZE) |
| 79 | |
| 80 | #pragma pack(1) |
| 81 | typedef struct tpm_cmd_hdr { |
| 82 | uint16_t tag; |
| 83 | uint32_t cmd_size; |
| 84 | uint32_t cmd_code; |
| 85 | } tpm_cmd_hdr; |
| 86 | |
| 87 | typedef struct tpm_cmd { |
| 88 | tpm_cmd_hdr header; |
| 89 | uint8_t data[MAX_CMD_DATA]; |
| 90 | } tpm_cmd; |
| 91 | #pragma pack() |
| 92 | |
| 93 | int tpm_interface_init(struct tpm_chip_data *chip_data, uint8_t locality); |
| 94 | |
| 95 | int tpm_interface_close(struct tpm_chip_data *chip_data, uint8_t locality); |
| 96 | |
| 97 | int tpm_startup(struct tpm_chip_data *chip_data, uint16_t mode); |
| 98 | |
| 99 | int tpm_pcr_extend(struct tpm_chip_data *chip_data, uint32_t index, |
| 100 | uint16_t algorithm, const uint8_t *digest, |
| 101 | uint32_t digest_len); |
| 102 | |
| 103 | #endif /* TPM2_H */ |