15e124724SVadim Bendebury /* 28732b070SChe-liang Chiou * Copyright (c) 2013 The Chromium OS Authors. 3be6c1529SReinhard Pfau * Coypright (c) 2013 Guntermann & Drunck GmbH 45e124724SVadim Bendebury * 51a459660SWolfgang Denk * SPDX-License-Identifier: GPL-2.0+ 65e124724SVadim Bendebury */ 75e124724SVadim Bendebury 88732b070SChe-liang Chiou #ifndef __TPM_H 98732b070SChe-liang Chiou #define __TPM_H 105e124724SVadim Bendebury 118732b070SChe-liang Chiou #include <tis.h> 125e124724SVadim Bendebury 135e124724SVadim Bendebury /* 148732b070SChe-liang Chiou * Here is a partial implementation of TPM commands. Please consult TCG Main 158732b070SChe-liang Chiou * Specification for definitions of TPM commands. 165e124724SVadim Bendebury */ 175e124724SVadim Bendebury 18f255d31fSSimon Glass #define TPM_HEADER_SIZE 10 19f255d31fSSimon Glass 20f255d31fSSimon Glass enum tpm_duration { 21f255d31fSSimon Glass TPM_SHORT = 0, 22f255d31fSSimon Glass TPM_MEDIUM = 1, 23f255d31fSSimon Glass TPM_LONG = 2, 24f255d31fSSimon Glass TPM_UNDEFINED, 25f255d31fSSimon Glass 26f255d31fSSimon Glass TPM_DURATION_COUNT, 27f255d31fSSimon Glass }; 28f255d31fSSimon Glass 298732b070SChe-liang Chiou enum tpm_startup_type { 308732b070SChe-liang Chiou TPM_ST_CLEAR = 0x0001, 318732b070SChe-liang Chiou TPM_ST_STATE = 0x0002, 328732b070SChe-liang Chiou TPM_ST_DEACTIVATED = 0x0003, 338732b070SChe-liang Chiou }; 348732b070SChe-liang Chiou 358732b070SChe-liang Chiou enum tpm_physical_presence { 368732b070SChe-liang Chiou TPM_PHYSICAL_PRESENCE_HW_DISABLE = 0x0200, 378732b070SChe-liang Chiou TPM_PHYSICAL_PRESENCE_CMD_DISABLE = 0x0100, 388732b070SChe-liang Chiou TPM_PHYSICAL_PRESENCE_LIFETIME_LOCK = 0x0080, 398732b070SChe-liang Chiou TPM_PHYSICAL_PRESENCE_HW_ENABLE = 0x0040, 408732b070SChe-liang Chiou TPM_PHYSICAL_PRESENCE_CMD_ENABLE = 0x0020, 418732b070SChe-liang Chiou TPM_PHYSICAL_PRESENCE_NOTPRESENT = 0x0010, 428732b070SChe-liang Chiou TPM_PHYSICAL_PRESENCE_PRESENT = 0x0008, 438732b070SChe-liang Chiou TPM_PHYSICAL_PRESENCE_LOCK = 0x0004, 448732b070SChe-liang Chiou }; 458732b070SChe-liang Chiou 468732b070SChe-liang Chiou enum tpm_nv_index { 478732b070SChe-liang Chiou TPM_NV_INDEX_LOCK = 0xffffffff, 488732b070SChe-liang Chiou TPM_NV_INDEX_0 = 0x00000000, 498732b070SChe-liang Chiou TPM_NV_INDEX_DIR = 0x10000001, 508732b070SChe-liang Chiou }; 518732b070SChe-liang Chiou 52*2132f971SSimon Glass #define TPM_NV_PER_GLOBALLOCK (1U << 15) 53*2132f971SSimon Glass #define TPM_NV_PER_PPWRITE (1U << 0) 54*2132f971SSimon Glass #define TPM_NV_PER_READ_STCLEAR (1U << 31) 55*2132f971SSimon Glass #define TPM_NV_PER_WRITE_STCLEAR (1U << 14) 56*2132f971SSimon Glass 57*2132f971SSimon Glass enum { 58*2132f971SSimon Glass TPM_PUBEK_SIZE = 256, 59*2132f971SSimon Glass }; 60*2132f971SSimon Glass 618732b070SChe-liang Chiou /** 62be6c1529SReinhard Pfau * TPM return codes as defined in the TCG Main specification 63be6c1529SReinhard Pfau * (TPM Main Part 2 Structures; Specification version 1.2) 64be6c1529SReinhard Pfau */ 65be6c1529SReinhard Pfau enum tpm_return_code { 66be6c1529SReinhard Pfau TPM_BASE = 0x00000000, 67be6c1529SReinhard Pfau TPM_NON_FATAL = 0x00000800, 68be6c1529SReinhard Pfau TPM_SUCCESS = TPM_BASE, 69be6c1529SReinhard Pfau /* TPM-defined fatal error codes */ 70be6c1529SReinhard Pfau TPM_AUTHFAIL = TPM_BASE + 1, 71be6c1529SReinhard Pfau TPM_BADINDEX = TPM_BASE + 2, 72be6c1529SReinhard Pfau TPM_BAD_PARAMETER = TPM_BASE + 3, 73be6c1529SReinhard Pfau TPM_AUDITFAILURE = TPM_BASE + 4, 74be6c1529SReinhard Pfau TPM_CLEAR_DISABLED = TPM_BASE + 5, 75be6c1529SReinhard Pfau TPM_DEACTIVATED = TPM_BASE + 6, 76be6c1529SReinhard Pfau TPM_DISABLED = TPM_BASE + 7, 77be6c1529SReinhard Pfau TPM_DISABLED_CMD = TPM_BASE + 8, 78be6c1529SReinhard Pfau TPM_FAIL = TPM_BASE + 9, 79be6c1529SReinhard Pfau TPM_BAD_ORDINAL = TPM_BASE + 10, 80be6c1529SReinhard Pfau TPM_INSTALL_DISABLED = TPM_BASE + 11, 81be6c1529SReinhard Pfau TPM_INVALID_KEYHANDLE = TPM_BASE + 12, 82be6c1529SReinhard Pfau TPM_KEYNOTFOUND = TPM_BASE + 13, 83be6c1529SReinhard Pfau TPM_INAPPROPRIATE_ENC = TPM_BASE + 14, 84be6c1529SReinhard Pfau TPM_MIGRATE_FAIL = TPM_BASE + 15, 85be6c1529SReinhard Pfau TPM_INVALID_PCR_INFO = TPM_BASE + 16, 86be6c1529SReinhard Pfau TPM_NOSPACE = TPM_BASE + 17, 87be6c1529SReinhard Pfau TPM_NOSRK = TPM_BASE + 18, 88be6c1529SReinhard Pfau TPM_NOTSEALED_BLOB = TPM_BASE + 19, 89be6c1529SReinhard Pfau TPM_OWNER_SET = TPM_BASE + 20, 90be6c1529SReinhard Pfau TPM_RESOURCES = TPM_BASE + 21, 91be6c1529SReinhard Pfau TPM_SHORTRANDOM = TPM_BASE + 22, 92be6c1529SReinhard Pfau TPM_SIZE = TPM_BASE + 23, 93be6c1529SReinhard Pfau TPM_WRONGPCRVAL = TPM_BASE + 24, 94be6c1529SReinhard Pfau TPM_BAD_PARAM_SIZE = TPM_BASE + 25, 95be6c1529SReinhard Pfau TPM_SHA_THREAD = TPM_BASE + 26, 96be6c1529SReinhard Pfau TPM_SHA_ERROR = TPM_BASE + 27, 97be6c1529SReinhard Pfau TPM_FAILEDSELFTEST = TPM_BASE + 28, 98be6c1529SReinhard Pfau TPM_AUTH2FAIL = TPM_BASE + 29, 99be6c1529SReinhard Pfau TPM_BADTAG = TPM_BASE + 30, 100be6c1529SReinhard Pfau TPM_IOERROR = TPM_BASE + 31, 101be6c1529SReinhard Pfau TPM_ENCRYPT_ERROR = TPM_BASE + 32, 102be6c1529SReinhard Pfau TPM_DECRYPT_ERROR = TPM_BASE + 33, 103be6c1529SReinhard Pfau TPM_INVALID_AUTHHANDLE = TPM_BASE + 34, 104be6c1529SReinhard Pfau TPM_NO_ENDORSEMENT = TPM_BASE + 35, 105be6c1529SReinhard Pfau TPM_INVALID_KEYUSAGE = TPM_BASE + 36, 106be6c1529SReinhard Pfau TPM_WRONG_ENTITYTYPE = TPM_BASE + 37, 107be6c1529SReinhard Pfau TPM_INVALID_POSTINIT = TPM_BASE + 38, 108be6c1529SReinhard Pfau TPM_INAPPROPRIATE_SIG = TPM_BASE + 39, 109be6c1529SReinhard Pfau TPM_BAD_KEY_PROPERTY = TPM_BASE + 40, 110be6c1529SReinhard Pfau TPM_BAD_MIGRATION = TPM_BASE + 41, 111be6c1529SReinhard Pfau TPM_BAD_SCHEME = TPM_BASE + 42, 112be6c1529SReinhard Pfau TPM_BAD_DATASIZE = TPM_BASE + 43, 113be6c1529SReinhard Pfau TPM_BAD_MODE = TPM_BASE + 44, 114be6c1529SReinhard Pfau TPM_BAD_PRESENCE = TPM_BASE + 45, 115be6c1529SReinhard Pfau TPM_BAD_VERSION = TPM_BASE + 46, 116be6c1529SReinhard Pfau TPM_NO_WRAP_TRANSPORT = TPM_BASE + 47, 117be6c1529SReinhard Pfau TPM_AUDITFAIL_UNSUCCESSFUL = TPM_BASE + 48, 118be6c1529SReinhard Pfau TPM_AUDITFAIL_SUCCESSFUL = TPM_BASE + 49, 119be6c1529SReinhard Pfau TPM_NOTRESETABLE = TPM_BASE + 50, 120be6c1529SReinhard Pfau TPM_NOTLOCAL = TPM_BASE + 51, 121be6c1529SReinhard Pfau TPM_BAD_TYPE = TPM_BASE + 52, 122be6c1529SReinhard Pfau TPM_INVALID_RESOURCE = TPM_BASE + 53, 123be6c1529SReinhard Pfau TPM_NOTFIPS = TPM_BASE + 54, 124be6c1529SReinhard Pfau TPM_INVALID_FAMILY = TPM_BASE + 55, 125be6c1529SReinhard Pfau TPM_NO_NV_PERMISSION = TPM_BASE + 56, 126be6c1529SReinhard Pfau TPM_REQUIRES_SIGN = TPM_BASE + 57, 127be6c1529SReinhard Pfau TPM_KEY_NOTSUPPORTED = TPM_BASE + 58, 128be6c1529SReinhard Pfau TPM_AUTH_CONFLICT = TPM_BASE + 59, 129be6c1529SReinhard Pfau TPM_AREA_LOCKED = TPM_BASE + 60, 130be6c1529SReinhard Pfau TPM_BAD_LOCALITY = TPM_BASE + 61, 131be6c1529SReinhard Pfau TPM_READ_ONLY = TPM_BASE + 62, 132be6c1529SReinhard Pfau TPM_PER_NOWRITE = TPM_BASE + 63, 133be6c1529SReinhard Pfau TPM_FAMILY_COUNT = TPM_BASE + 64, 134be6c1529SReinhard Pfau TPM_WRITE_LOCKED = TPM_BASE + 65, 135be6c1529SReinhard Pfau TPM_BAD_ATTRIBUTES = TPM_BASE + 66, 136be6c1529SReinhard Pfau TPM_INVALID_STRUCTURE = TPM_BASE + 67, 137be6c1529SReinhard Pfau TPM_KEY_OWNER_CONTROL = TPM_BASE + 68, 138be6c1529SReinhard Pfau TPM_BAD_COUNTER = TPM_BASE + 69, 139be6c1529SReinhard Pfau TPM_NOT_FULLWRITE = TPM_BASE + 70, 140be6c1529SReinhard Pfau TPM_CONTEXT_GAP = TPM_BASE + 71, 141be6c1529SReinhard Pfau TPM_MAXNVWRITES = TPM_BASE + 72, 142be6c1529SReinhard Pfau TPM_NOOPERATOR = TPM_BASE + 73, 143be6c1529SReinhard Pfau TPM_RESOURCEMISSING = TPM_BASE + 74, 144be6c1529SReinhard Pfau TPM_DELEGATE_LOCK = TPM_BASE + 75, 145be6c1529SReinhard Pfau TPM_DELEGATE_FAMILY = TPM_BASE + 76, 146be6c1529SReinhard Pfau TPM_DELEGATE_ADMIN = TPM_BASE + 77, 147be6c1529SReinhard Pfau TPM_TRANSPORT_NOTEXCLUSIVE = TPM_BASE + 78, 148be6c1529SReinhard Pfau TPM_OWNER_CONTROL = TPM_BASE + 79, 149be6c1529SReinhard Pfau TPM_DAA_RESOURCES = TPM_BASE + 80, 150be6c1529SReinhard Pfau TPM_DAA_INPUT_DATA0 = TPM_BASE + 81, 151be6c1529SReinhard Pfau TPM_DAA_INPUT_DATA1 = TPM_BASE + 82, 152be6c1529SReinhard Pfau TPM_DAA_ISSUER_SETTINGS = TPM_BASE + 83, 153be6c1529SReinhard Pfau TPM_DAA_TPM_SETTINGS = TPM_BASE + 84, 154be6c1529SReinhard Pfau TPM_DAA_STAGE = TPM_BASE + 85, 155be6c1529SReinhard Pfau TPM_DAA_ISSUER_VALIDITY = TPM_BASE + 86, 156be6c1529SReinhard Pfau TPM_DAA_WRONG_W = TPM_BASE + 87, 157be6c1529SReinhard Pfau TPM_BAD_HANDLE = TPM_BASE + 88, 158be6c1529SReinhard Pfau TPM_BAD_DELEGATE = TPM_BASE + 89, 159be6c1529SReinhard Pfau TPM_BADCONTEXT = TPM_BASE + 90, 160be6c1529SReinhard Pfau TPM_TOOMANYCONTEXTS = TPM_BASE + 91, 161be6c1529SReinhard Pfau TPM_MA_TICKET_SIGNATURE = TPM_BASE + 92, 162be6c1529SReinhard Pfau TPM_MA_DESTINATION = TPM_BASE + 93, 163be6c1529SReinhard Pfau TPM_MA_SOURCE = TPM_BASE + 94, 164be6c1529SReinhard Pfau TPM_MA_AUTHORITY = TPM_BASE + 95, 165be6c1529SReinhard Pfau TPM_PERMANENTEK = TPM_BASE + 97, 166be6c1529SReinhard Pfau TPM_BAD_SIGNATURE = TPM_BASE + 98, 167be6c1529SReinhard Pfau TPM_NOCONTEXTSPACE = TPM_BASE + 99, 168be6c1529SReinhard Pfau /* TPM-defined non-fatal errors */ 169be6c1529SReinhard Pfau TPM_RETRY = TPM_BASE + TPM_NON_FATAL, 170be6c1529SReinhard Pfau TPM_NEEDS_SELFTEST = TPM_BASE + TPM_NON_FATAL + 1, 171be6c1529SReinhard Pfau TPM_DOING_SELFTEST = TPM_BASE + TPM_NON_FATAL + 2, 172be6c1529SReinhard Pfau TPM_DEFEND_LOCK_RUNNING = TPM_BASE + TPM_NON_FATAL + 3, 173be6c1529SReinhard Pfau }; 174be6c1529SReinhard Pfau 175*2132f971SSimon Glass struct tpm_permanent_flags { 176*2132f971SSimon Glass __be16 tag; 177*2132f971SSimon Glass u8 disable; 178*2132f971SSimon Glass u8 ownership; 179*2132f971SSimon Glass u8 deactivated; 180*2132f971SSimon Glass u8 read_pubek; 181*2132f971SSimon Glass u8 disable_owner_clear; 182*2132f971SSimon Glass u8 allow_maintenance; 183*2132f971SSimon Glass u8 physical_presence_lifetime_lock; 184*2132f971SSimon Glass u8 physical_presence_hw_enable; 185*2132f971SSimon Glass u8 physical_presence_cmd_enable; 186*2132f971SSimon Glass u8 cekp_used; 187*2132f971SSimon Glass u8 tpm_post; 188*2132f971SSimon Glass u8 tpm_post_lock; 189*2132f971SSimon Glass u8 fips; 190*2132f971SSimon Glass u8 operator; 191*2132f971SSimon Glass u8 enable_revoke_ek; 192*2132f971SSimon Glass u8 nv_locked; 193*2132f971SSimon Glass u8 read_srk_pub; 194*2132f971SSimon Glass u8 tpm_established; 195*2132f971SSimon Glass u8 maintenance_done; 196*2132f971SSimon Glass u8 disable_full_da_logic_info; 197*2132f971SSimon Glass } __packed; 198*2132f971SSimon Glass 199f255d31fSSimon Glass #ifdef CONFIG_DM_TPM 200f255d31fSSimon Glass 201f255d31fSSimon Glass /* Max buffer size supported by our tpm */ 202f255d31fSSimon Glass #define TPM_DEV_BUFSIZE 1260 203f255d31fSSimon Glass 204f255d31fSSimon Glass /** 205f255d31fSSimon Glass * struct tpm_chip_priv - Information about a TPM, stored by the uclass 206f255d31fSSimon Glass * 207f255d31fSSimon Glass * These values must be set up by the device's probe() method before 208f255d31fSSimon Glass * communcation is attempted. If the device has an xfer() method, this is 209f255d31fSSimon Glass * not needed. There is no need to set up @buf. 210f255d31fSSimon Glass * 211f255d31fSSimon Glass * @duration_ms: Length of each duration type in milliseconds 212f255d31fSSimon Glass * @retry_time_ms: Time to wait before retrying receive 213f255d31fSSimon Glass */ 214f255d31fSSimon Glass struct tpm_chip_priv { 215f255d31fSSimon Glass uint duration_ms[TPM_DURATION_COUNT]; 216f255d31fSSimon Glass uint retry_time_ms; 217f255d31fSSimon Glass u8 buf[TPM_DEV_BUFSIZE + sizeof(u8)]; /* Max buffer size + addr */ 218f255d31fSSimon Glass }; 219f255d31fSSimon Glass 220f255d31fSSimon Glass /** 221f255d31fSSimon Glass * struct tpm_ops - low-level TPM operations 222f255d31fSSimon Glass * 223f255d31fSSimon Glass * These are designed to avoid loops and delays in the driver itself. These 224f255d31fSSimon Glass * should be handled in the uclass. 225f255d31fSSimon Glass * 226f255d31fSSimon Glass * In gneral you should implement everything except xfer(). Where you need 227f255d31fSSimon Glass * complete control of the transfer, then xfer() can be provided and will 228f255d31fSSimon Glass * override the other methods. 229f255d31fSSimon Glass * 230f255d31fSSimon Glass * This interface is for low-level TPM access. It does not understand the 231f255d31fSSimon Glass * concept of localities or the various TPM messages. That interface is 232f255d31fSSimon Glass * defined in the functions later on in this file, but they all translate 233f255d31fSSimon Glass * to bytes which are sent and received. 234f255d31fSSimon Glass */ 235f255d31fSSimon Glass struct tpm_ops { 236f255d31fSSimon Glass /** 237f255d31fSSimon Glass * open() - Request access to locality 0 for the caller 238f255d31fSSimon Glass * 239f255d31fSSimon Glass * After all commands have been completed the caller should call 240f255d31fSSimon Glass * close(). 241f255d31fSSimon Glass * 242f255d31fSSimon Glass * @dev: Device to close 243f255d31fSSimon Glass * @return 0 ok OK, -ve on error 244f255d31fSSimon Glass */ 245f255d31fSSimon Glass int (*open)(struct udevice *dev); 246f255d31fSSimon Glass 247f255d31fSSimon Glass /** 248f255d31fSSimon Glass * close() - Close the current session 249f255d31fSSimon Glass * 250f255d31fSSimon Glass * Releasing the locked locality. Returns 0 on success, -ve 1 on 251f255d31fSSimon Glass * failure (in case lock removal did not succeed). 252f255d31fSSimon Glass * 253f255d31fSSimon Glass * @dev: Device to close 254f255d31fSSimon Glass * @return 0 ok OK, -ve on error 255f255d31fSSimon Glass */ 256f255d31fSSimon Glass int (*close)(struct udevice *dev); 257f255d31fSSimon Glass 258f255d31fSSimon Glass /** 259f255d31fSSimon Glass * get_desc() - Get a text description of the TPM 260f255d31fSSimon Glass * 261f255d31fSSimon Glass * @dev: Device to check 262f255d31fSSimon Glass * @buf: Buffer to put the string 263f255d31fSSimon Glass * @size: Maximum size of buffer 264f255d31fSSimon Glass * @return length of string, or -ENOSPC it no space 265f255d31fSSimon Glass */ 266f255d31fSSimon Glass int (*get_desc)(struct udevice *dev, char *buf, int size); 267f255d31fSSimon Glass 268f255d31fSSimon Glass /** 269f255d31fSSimon Glass * send() - send data to the TPM 270f255d31fSSimon Glass * 271f255d31fSSimon Glass * @dev: Device to talk to 272f255d31fSSimon Glass * @sendbuf: Buffer of the data to send 273f255d31fSSimon Glass * @send_size: Size of the data to send 274f255d31fSSimon Glass * 275f255d31fSSimon Glass * Returns 0 on success or -ve on failure. 276f255d31fSSimon Glass */ 277f255d31fSSimon Glass int (*send)(struct udevice *dev, const uint8_t *sendbuf, 278f255d31fSSimon Glass size_t send_size); 279f255d31fSSimon Glass 280f255d31fSSimon Glass /** 281f255d31fSSimon Glass * recv() - receive a response from the TPM 282f255d31fSSimon Glass * 283f255d31fSSimon Glass * @dev: Device to talk to 284f255d31fSSimon Glass * @recvbuf: Buffer to save the response to 285f255d31fSSimon Glass * @max_size: Maximum number of bytes to receive 286f255d31fSSimon Glass * 287f255d31fSSimon Glass * Returns number of bytes received on success, -EAGAIN if the TPM 288f255d31fSSimon Glass * response is not ready, -EINTR if cancelled, or other -ve value on 289f255d31fSSimon Glass * failure. 290f255d31fSSimon Glass */ 291f255d31fSSimon Glass int (*recv)(struct udevice *dev, uint8_t *recvbuf, size_t max_size); 292f255d31fSSimon Glass 293f255d31fSSimon Glass /** 294f255d31fSSimon Glass * cleanup() - clean up after an operation in progress 295f255d31fSSimon Glass * 296f255d31fSSimon Glass * This is called if receiving times out. The TPM may need to abort 297f255d31fSSimon Glass * the current transaction if it did not complete, and make itself 298f255d31fSSimon Glass * ready for another. 299f255d31fSSimon Glass * 300f255d31fSSimon Glass * @dev: Device to talk to 301f255d31fSSimon Glass */ 302f255d31fSSimon Glass int (*cleanup)(struct udevice *dev); 303f255d31fSSimon Glass 304f255d31fSSimon Glass /** 305f255d31fSSimon Glass * xfer() - send data to the TPM and get response 306f255d31fSSimon Glass * 307f255d31fSSimon Glass * This method is optional. If it exists it is used in preference 308f255d31fSSimon Glass * to send(), recv() and cleanup(). It should handle all aspects of 309f255d31fSSimon Glass * TPM communication for a single transfer. 310f255d31fSSimon Glass * 311f255d31fSSimon Glass * @dev: Device to talk to 312f255d31fSSimon Glass * @sendbuf: Buffer of the data to send 313f255d31fSSimon Glass * @send_size: Size of the data to send 314f255d31fSSimon Glass * @recvbuf: Buffer to save the response to 315f255d31fSSimon Glass * @recv_size: Pointer to the size of the response buffer 316f255d31fSSimon Glass * 317f255d31fSSimon Glass * Returns 0 on success (and places the number of response bytes at 318f255d31fSSimon Glass * recv_size) or -ve on failure. 319f255d31fSSimon Glass */ 320f255d31fSSimon Glass int (*xfer)(struct udevice *dev, const uint8_t *sendbuf, 321f255d31fSSimon Glass size_t send_size, uint8_t *recvbuf, size_t *recv_size); 322f255d31fSSimon Glass }; 323f255d31fSSimon Glass 324f255d31fSSimon Glass #define tpm_get_ops(dev) ((struct tpm_ops *)device_get_ops(dev)) 325f255d31fSSimon Glass 326f255d31fSSimon Glass /** 327f255d31fSSimon Glass * tpm_open() - Request access to locality 0 for the caller 328f255d31fSSimon Glass * 329f255d31fSSimon Glass * After all commands have been completed the caller is supposed to 330f255d31fSSimon Glass * call tpm_close(). 331f255d31fSSimon Glass * 332f255d31fSSimon Glass * Returns 0 on success, -ve on failure. 333f255d31fSSimon Glass */ 334f255d31fSSimon Glass int tpm_open(struct udevice *dev); 335f255d31fSSimon Glass 336f255d31fSSimon Glass /** 337f255d31fSSimon Glass * tpm_close() - Close the current session 338f255d31fSSimon Glass * 339f255d31fSSimon Glass * Releasing the locked locality. Returns 0 on success, -ve 1 on 340f255d31fSSimon Glass * failure (in case lock removal did not succeed). 341f255d31fSSimon Glass */ 342f255d31fSSimon Glass int tpm_close(struct udevice *dev); 343f255d31fSSimon Glass 344f255d31fSSimon Glass /** 345f255d31fSSimon Glass * tpm_get_desc() - Get a text description of the TPM 346f255d31fSSimon Glass * 347f255d31fSSimon Glass * @dev: Device to check 348f255d31fSSimon Glass * @buf: Buffer to put the string 349f255d31fSSimon Glass * @size: Maximum size of buffer 350f255d31fSSimon Glass * @return length of string, or -ENOSPC it no space 351f255d31fSSimon Glass */ 352f255d31fSSimon Glass int tpm_get_desc(struct udevice *dev, char *buf, int size); 353f255d31fSSimon Glass 354f255d31fSSimon Glass /** 355f255d31fSSimon Glass * tpm_xfer() - send data to the TPM and get response 356f255d31fSSimon Glass * 357f255d31fSSimon Glass * This first uses the device's send() method to send the bytes. Then it calls 358f255d31fSSimon Glass * recv() to get the reply. If recv() returns -EAGAIN then it will delay a 359f255d31fSSimon Glass * short time and then call recv() again. 360f255d31fSSimon Glass * 361f255d31fSSimon Glass * Regardless of whether recv() completes successfully, it will then call 362f255d31fSSimon Glass * cleanup() to finish the transaction. 363f255d31fSSimon Glass * 364f255d31fSSimon Glass * Note that the outgoing data is inspected to determine command type 365f255d31fSSimon Glass * (ordinal) and a timeout is used for that command type. 366f255d31fSSimon Glass * 367f255d31fSSimon Glass * @sendbuf - buffer of the data to send 368f255d31fSSimon Glass * @send_size size of the data to send 369f255d31fSSimon Glass * @recvbuf - memory to save the response to 370f255d31fSSimon Glass * @recv_len - pointer to the size of the response buffer 371f255d31fSSimon Glass * 372f255d31fSSimon Glass * Returns 0 on success (and places the number of response bytes at 373f255d31fSSimon Glass * recv_len) or -ve on failure. 374f255d31fSSimon Glass */ 375f255d31fSSimon Glass int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size, 376f255d31fSSimon Glass uint8_t *recvbuf, size_t *recv_size); 377f255d31fSSimon Glass 378f255d31fSSimon Glass #endif /* CONFIG_DM_TPM */ 379f255d31fSSimon Glass 380be6c1529SReinhard Pfau /** 3818732b070SChe-liang Chiou * Initialize TPM device. It must be called before any TPM commands. 3825e124724SVadim Bendebury * 3838732b070SChe-liang Chiou * @return 0 on success, non-0 on error. 3845e124724SVadim Bendebury */ 385c8a8c510SSimon Glass int tpm_init(void); 3865e124724SVadim Bendebury 3878732b070SChe-liang Chiou /** 3888732b070SChe-liang Chiou * Issue a TPM_Startup command. 3895e124724SVadim Bendebury * 3908732b070SChe-liang Chiou * @param mode TPM startup mode 3918732b070SChe-liang Chiou * @return return code of the operation 3925e124724SVadim Bendebury */ 3938732b070SChe-liang Chiou uint32_t tpm_startup(enum tpm_startup_type mode); 3945e124724SVadim Bendebury 3958732b070SChe-liang Chiou /** 3968732b070SChe-liang Chiou * Issue a TPM_SelfTestFull command. 3975e124724SVadim Bendebury * 3988732b070SChe-liang Chiou * @return return code of the operation 3995e124724SVadim Bendebury */ 4008732b070SChe-liang Chiou uint32_t tpm_self_test_full(void); 4015e124724SVadim Bendebury 4028732b070SChe-liang Chiou /** 4038732b070SChe-liang Chiou * Issue a TPM_ContinueSelfTest command. 4048732b070SChe-liang Chiou * 4058732b070SChe-liang Chiou * @return return code of the operation 4068732b070SChe-liang Chiou */ 4078732b070SChe-liang Chiou uint32_t tpm_continue_self_test(void); 4088732b070SChe-liang Chiou 4098732b070SChe-liang Chiou /** 4108732b070SChe-liang Chiou * Issue a TPM_NV_DefineSpace command. The implementation is limited 4118732b070SChe-liang Chiou * to specify TPM_NV_ATTRIBUTES and size of the area. The area index 4128732b070SChe-liang Chiou * could be one of the special value listed in enum tpm_nv_index. 4138732b070SChe-liang Chiou * 4148732b070SChe-liang Chiou * @param index index of the area 4158732b070SChe-liang Chiou * @param perm TPM_NV_ATTRIBUTES of the area 4168732b070SChe-liang Chiou * @param size size of the area 4178732b070SChe-liang Chiou * @return return code of the operation 4188732b070SChe-liang Chiou */ 4198732b070SChe-liang Chiou uint32_t tpm_nv_define_space(uint32_t index, uint32_t perm, uint32_t size); 4208732b070SChe-liang Chiou 4218732b070SChe-liang Chiou /** 4228732b070SChe-liang Chiou * Issue a TPM_NV_ReadValue command. This implementation is limited 4238732b070SChe-liang Chiou * to read the area from offset 0. The area index could be one of 4248732b070SChe-liang Chiou * the special value listed in enum tpm_nv_index. 4258732b070SChe-liang Chiou * 4268732b070SChe-liang Chiou * @param index index of the area 4278732b070SChe-liang Chiou * @param data output buffer of the area contents 4288732b070SChe-liang Chiou * @param count size of output buffer 4298732b070SChe-liang Chiou * @return return code of the operation 4308732b070SChe-liang Chiou */ 4318732b070SChe-liang Chiou uint32_t tpm_nv_read_value(uint32_t index, void *data, uint32_t count); 4328732b070SChe-liang Chiou 4338732b070SChe-liang Chiou /** 4348732b070SChe-liang Chiou * Issue a TPM_NV_WriteValue command. This implementation is limited 4358732b070SChe-liang Chiou * to write the area from offset 0. The area index could be one of 4368732b070SChe-liang Chiou * the special value listed in enum tpm_nv_index. 4378732b070SChe-liang Chiou * 4388732b070SChe-liang Chiou * @param index index of the area 4398732b070SChe-liang Chiou * @param data input buffer to be wrote to the area 4408732b070SChe-liang Chiou * @param length length of data bytes of input buffer 4418732b070SChe-liang Chiou * @return return code of the operation 4428732b070SChe-liang Chiou */ 4438732b070SChe-liang Chiou uint32_t tpm_nv_write_value(uint32_t index, const void *data, uint32_t length); 4448732b070SChe-liang Chiou 4458732b070SChe-liang Chiou /** 4468732b070SChe-liang Chiou * Issue a TPM_Extend command. 4478732b070SChe-liang Chiou * 4488732b070SChe-liang Chiou * @param index index of the PCR 4498732b070SChe-liang Chiou * @param in_digest 160-bit value representing the event to be 4508732b070SChe-liang Chiou * recorded 4518732b070SChe-liang Chiou * @param out_digest 160-bit PCR value after execution of the 4528732b070SChe-liang Chiou * command 4538732b070SChe-liang Chiou * @return return code of the operation 4548732b070SChe-liang Chiou */ 4558732b070SChe-liang Chiou uint32_t tpm_extend(uint32_t index, const void *in_digest, void *out_digest); 4568732b070SChe-liang Chiou 4578732b070SChe-liang Chiou /** 4588732b070SChe-liang Chiou * Issue a TPM_PCRRead command. 4598732b070SChe-liang Chiou * 4608732b070SChe-liang Chiou * @param index index of the PCR 4618732b070SChe-liang Chiou * @param data output buffer for contents of the named PCR 4628732b070SChe-liang Chiou * @param count size of output buffer 4638732b070SChe-liang Chiou * @return return code of the operation 4648732b070SChe-liang Chiou */ 4658732b070SChe-liang Chiou uint32_t tpm_pcr_read(uint32_t index, void *data, size_t count); 4668732b070SChe-liang Chiou 4678732b070SChe-liang Chiou /** 4688732b070SChe-liang Chiou * Issue a TSC_PhysicalPresence command. TPM physical presence flag 4698732b070SChe-liang Chiou * is bit-wise OR'ed of flags listed in enum tpm_physical_presence. 4708732b070SChe-liang Chiou * 4718732b070SChe-liang Chiou * @param presence TPM physical presence flag 4728732b070SChe-liang Chiou * @return return code of the operation 4738732b070SChe-liang Chiou */ 4748732b070SChe-liang Chiou uint32_t tpm_tsc_physical_presence(uint16_t presence); 4758732b070SChe-liang Chiou 4768732b070SChe-liang Chiou /** 4778732b070SChe-liang Chiou * Issue a TPM_ReadPubek command. 4788732b070SChe-liang Chiou * 4798732b070SChe-liang Chiou * @param data output buffer for the public endorsement key 4808732b070SChe-liang Chiou * @param count size of ouput buffer 4818732b070SChe-liang Chiou * @return return code of the operation 4828732b070SChe-liang Chiou */ 4838732b070SChe-liang Chiou uint32_t tpm_read_pubek(void *data, size_t count); 4848732b070SChe-liang Chiou 4858732b070SChe-liang Chiou /** 4868732b070SChe-liang Chiou * Issue a TPM_ForceClear command. 4878732b070SChe-liang Chiou * 4888732b070SChe-liang Chiou * @return return code of the operation 4898732b070SChe-liang Chiou */ 4908732b070SChe-liang Chiou uint32_t tpm_force_clear(void); 4918732b070SChe-liang Chiou 4928732b070SChe-liang Chiou /** 4938732b070SChe-liang Chiou * Issue a TPM_PhysicalEnable command. 4948732b070SChe-liang Chiou * 4958732b070SChe-liang Chiou * @return return code of the operation 4968732b070SChe-liang Chiou */ 4978732b070SChe-liang Chiou uint32_t tpm_physical_enable(void); 4988732b070SChe-liang Chiou 4998732b070SChe-liang Chiou /** 5008732b070SChe-liang Chiou * Issue a TPM_PhysicalDisable command. 5018732b070SChe-liang Chiou * 5028732b070SChe-liang Chiou * @return return code of the operation 5038732b070SChe-liang Chiou */ 5048732b070SChe-liang Chiou uint32_t tpm_physical_disable(void); 5058732b070SChe-liang Chiou 5068732b070SChe-liang Chiou /** 5078732b070SChe-liang Chiou * Issue a TPM_PhysicalSetDeactivated command. 5088732b070SChe-liang Chiou * 5098732b070SChe-liang Chiou * @param state boolean state of the deactivated flag 5108732b070SChe-liang Chiou * @return return code of the operation 5118732b070SChe-liang Chiou */ 5128732b070SChe-liang Chiou uint32_t tpm_physical_set_deactivated(uint8_t state); 5138732b070SChe-liang Chiou 5148732b070SChe-liang Chiou /** 5158732b070SChe-liang Chiou * Issue a TPM_GetCapability command. This implementation is limited 5168732b070SChe-liang Chiou * to query sub_cap index that is 4-byte wide. 5178732b070SChe-liang Chiou * 5188732b070SChe-liang Chiou * @param cap_area partition of capabilities 5198732b070SChe-liang Chiou * @param sub_cap further definition of capability, which is 5208732b070SChe-liang Chiou * limited to be 4-byte wide 5218732b070SChe-liang Chiou * @param cap output buffer for capability information 5228732b070SChe-liang Chiou * @param count size of ouput buffer 5238732b070SChe-liang Chiou * @return return code of the operation 5248732b070SChe-liang Chiou */ 5258732b070SChe-liang Chiou uint32_t tpm_get_capability(uint32_t cap_area, uint32_t sub_cap, 5268732b070SChe-liang Chiou void *cap, size_t count); 5278732b070SChe-liang Chiou 528be6c1529SReinhard Pfau /** 529be6c1529SReinhard Pfau * Issue a TPM_FlushSpecific command for a AUTH ressource. 530be6c1529SReinhard Pfau * 531be6c1529SReinhard Pfau * @param auth_handle handle of the auth session 532be6c1529SReinhard Pfau * @return return code of the operation 533be6c1529SReinhard Pfau */ 534be6c1529SReinhard Pfau uint32_t tpm_terminate_auth_session(uint32_t auth_handle); 535be6c1529SReinhard Pfau 536be6c1529SReinhard Pfau /** 537be6c1529SReinhard Pfau * Issue a TPM_OIAP command to setup an object independant authorization 538be6c1529SReinhard Pfau * session. 539be6c1529SReinhard Pfau * Information about the session is stored internally. 540be6c1529SReinhard Pfau * If there was already an OIAP session active it is terminated and a new 541be6c1529SReinhard Pfau * session is set up. 542be6c1529SReinhard Pfau * 543be6c1529SReinhard Pfau * @param auth_handle pointer to the (new) auth handle or NULL. 544be6c1529SReinhard Pfau * @return return code of the operation 545be6c1529SReinhard Pfau */ 546be6c1529SReinhard Pfau uint32_t tpm_oiap(uint32_t *auth_handle); 547be6c1529SReinhard Pfau 548be6c1529SReinhard Pfau /** 549be6c1529SReinhard Pfau * Ends an active OIAP session. 550be6c1529SReinhard Pfau * 551be6c1529SReinhard Pfau * @return return code of the operation 552be6c1529SReinhard Pfau */ 553be6c1529SReinhard Pfau uint32_t tpm_end_oiap(void); 554be6c1529SReinhard Pfau 555be6c1529SReinhard Pfau /** 556be6c1529SReinhard Pfau * Issue a TPM_LoadKey2 (Auth1) command using an OIAP session for authenticating 557be6c1529SReinhard Pfau * the usage of the parent key. 558be6c1529SReinhard Pfau * 559be6c1529SReinhard Pfau * @param parent_handle handle of the parent key. 560be6c1529SReinhard Pfau * @param key pointer to the key structure (TPM_KEY or TPM_KEY12). 561be6c1529SReinhard Pfau * @param key_length size of the key structure 562be6c1529SReinhard Pfau * @param parent_key_usage_auth usage auth for the parent key 563be6c1529SReinhard Pfau * @param key_handle pointer to the key handle 564be6c1529SReinhard Pfau * @return return code of the operation 565be6c1529SReinhard Pfau */ 566be6c1529SReinhard Pfau uint32_t tpm_load_key2_oiap(uint32_t parent_handle, 567be6c1529SReinhard Pfau const void *key, size_t key_length, 568be6c1529SReinhard Pfau const void *parent_key_usage_auth, 569be6c1529SReinhard Pfau uint32_t *key_handle); 570be6c1529SReinhard Pfau 571be6c1529SReinhard Pfau /** 572be6c1529SReinhard Pfau * Issue a TPM_GetPubKey (Auth1) command using an OIAP session for 573be6c1529SReinhard Pfau * authenticating the usage of the key. 574be6c1529SReinhard Pfau * 575be6c1529SReinhard Pfau * @param key_handle handle of the key 576be6c1529SReinhard Pfau * @param usage_auth usage auth for the key 577be6c1529SReinhard Pfau * @param pubkey pointer to the pub key buffer; may be NULL if the pubkey 578be6c1529SReinhard Pfau * should not be stored. 579be6c1529SReinhard Pfau * @param pubkey_len pointer to the pub key buffer len. On entry: the size of 580be6c1529SReinhard Pfau * the provided pubkey buffer. On successful exit: the size 581be6c1529SReinhard Pfau * of the stored TPM_PUBKEY structure (iff pubkey != NULL). 582be6c1529SReinhard Pfau * @return return code of the operation 583be6c1529SReinhard Pfau */ 584be6c1529SReinhard Pfau uint32_t tpm_get_pub_key_oiap(uint32_t key_handle, const void *usage_auth, 585be6c1529SReinhard Pfau void *pubkey, size_t *pubkey_len); 586be6c1529SReinhard Pfau 587*2132f971SSimon Glass /** 588*2132f971SSimon Glass * Get the TPM permanent flags value 589*2132f971SSimon Glass * 590*2132f971SSimon Glass * @param pflags Place to put permanent flags 591*2132f971SSimon Glass * @return return code of the operation 592*2132f971SSimon Glass */ 593*2132f971SSimon Glass uint32_t tpm_get_permanent_flags(struct tpm_permanent_flags *pflags); 594*2132f971SSimon Glass 595*2132f971SSimon Glass /** 596*2132f971SSimon Glass * Get the TPM permissions 597*2132f971SSimon Glass * 598*2132f971SSimon Glass * @param perm Returns permissions value 599*2132f971SSimon Glass * @return return code of the operation 600*2132f971SSimon Glass */ 601*2132f971SSimon Glass uint32_t tpm_get_permissions(uint32_t index, uint32_t *perm); 602*2132f971SSimon Glass 6038732b070SChe-liang Chiou #endif /* __TPM_H */ 604