1 /* Copyright 2015 The ChromiumOS Authors 2 * Use of this source code is governed by a BSD-style license that can be 3 * found in the LICENSE file. 4 */ 5 6 /* 7 * This defines the interface functions for TPM SPI Hardware Protocol. The SPI 8 * controller reads or writes between 1 and 64 bytes to a register designated by 9 * a 24-bit address. There is no provision for error reporting at this level. 10 */ 11 12 #ifndef __CROS_EC_TPM_REGISTERS_H 13 #define __CROS_EC_TPM_REGISTERS_H 14 15 #include <stdint.h> 16 17 #include "common.h" 18 19 /* The SPI controller is writing data into a TPM register. */ 20 void tpm_register_put(uint32_t regaddr, const uint8_t *data, 21 uint32_t data_size); 22 23 /* The SPI controller is reading data from a TPM register. */ 24 void tpm_register_get(uint32_t regaddr, uint8_t *dest, uint32_t data_size); 25 26 /* Get the current value of the burst size field of the status register. */ 27 size_t tpm_get_burst_size(void); 28 29 /* 30 * Register functions to start and stop TPM communications layer. The 31 * communications layer should be kept down while TPM is being reset. 32 */ 33 typedef void (*interface_control_func)(void); 34 void tpm_register_interface(interface_control_func interface_start, 35 interface_control_func interface_stop); 36 37 /* 38 * This requests the TPM task to reset itself. 39 * 40 * If wait_until_done is false, it returns EC_SUCCESS immediately. Otherwise it 41 * returns EC_SUCCESS after the reset has completed, or an error code on 42 * failure. 43 * 44 * If wipe_nvmem_first is true, the caller is expected to keep the rest of the 45 * system in reset until TPM wipeout is completed. 46 */ 47 int tpm_reset_request(int wait_until_done, int wipe_nvmem_first); 48 49 /* Returns True if successive TPM_RST_L pulses are being debounced. */ 50 int tpm_reset_in_progress(void); 51 52 /* 53 * Tell the TPM task to re-enable nvmem commits. 54 * 55 * NOTE: This function is NOT to be used freely, but only meant to be used in 56 * exceptional cases such as unlocking the console following a TPM wipe. 57 */ 58 void tpm_reinstate_nvmem_commits(void); 59 60 /* 61 * To be called by functions running on the TPM task context. Returns 62 * EC_SUCCESS on successful reset. 63 */ 64 int tpm_sync_reset(int wipe_first); 65 66 /* 67 * It shuts down the tpm interface, until next tpm reset event. 68 */ 69 void tpm_stop(void); 70 71 /* 72 * This structure describes the header of all commands and responses sent and 73 * received over TPM FIFO. 74 * 75 * Note that all fields are stored in the network (big endian) byte order. 76 */ 77 78 struct tpm_cmd_header { 79 uint16_t tag; 80 uint32_t size; 81 uint32_t command_code; 82 uint16_t subcommand_code; /* Not a standard field. */ 83 } __packed; 84 85 /* 86 * This function allows to process a TPM command coming from elsewhere, not 87 * from the communications interface. 88 * 89 * A common use case would be making cryptographic calculation on task 90 * contexts where stack the size is not large enough, for instance console 91 * commands. This function will block to let the TPM task a chance to run to 92 * execute the command and return the result in the same buffer. 93 * 94 * @param tpmh pointer to a buffer containing a marshalled TPM command, if it 95 * arrived over the communications channel. One of the header 96 * fields defines the command size. 97 * 98 * @param buffer_size the size of the buffer pointed to by tpmh - tells the 99 * TPM task how much room there is to store the response. 100 * 101 * Command execution result is reported in the response body. 102 * 103 * The extension command handler will consider all these commands to come from 104 * the USB interface, since the only current users for this are console 105 * commands. 106 */ 107 void tpm_alt_extension(struct tpm_cmd_header *tpmh, size_t buffer_size); 108 109 /* 110 * The only TPM2 commands we care about on the driver level, see 111 * crosbug.com/p/55667 for detals. 112 */ 113 #define TPM2_PCR_Extend 0x00000182 114 #define TPM2_PCR_Read 0x0000017e 115 #define TPM2_Startup 0x00000144 116 117 /* TPM mode */ 118 enum tpm_modes { 119 TPM_MODE_ENABLED_TENTATIVE = 0, 120 TPM_MODE_ENABLED = 1, 121 TPM_MODE_DISABLED = 2, 122 TPM_MODE_MAX, 123 }; 124 125 /* 126 * This function returns the current TPM_MODE value. 127 */ 128 enum tpm_modes get_tpm_mode(void); 129 130 #endif /* __CROS_EC_TPM_REGISTERS_H */ 131