1 /***************************************************************************** 2 * Copyright (c) 2015-2020 IBM Corporation 3 * All rights reserved. 4 * This program and the accompanying materials 5 * are made available under the terms of the BSD License 6 * which accompanies this distribution, and is available at 7 * http://www.opensource.org/licenses/bsd-license.php 8 * 9 * Contributors: 10 * IBM Corporation - initial implementation 11 *****************************************************************************/ 12 13 #ifndef TPM_DRIVERS_H 14 #define TPM_DRIVERS_H 15 16 #include <stdint.h> 17 #include <stdbool.h> 18 #include <unistd.h> 19 20 #include "tcgbios_int.h" 21 22 enum tpm_duration_type { 23 TPM_DURATION_TYPE_SHORT = 0, 24 TPM_DURATION_TYPE_MEDIUM, 25 TPM_DURATION_TYPE_LONG, 26 }; 27 28 /* firmware driver states */ 29 typedef enum { 30 VTPM_DRV_STATE_INVALID = 0, 31 VTPM_DRV_STATE_INIT_CALLED = 1, 32 VTPM_DRV_STATE_REG_CRQ = 2, 33 VTPM_DRV_STATE_WAIT_INIT = 3, 34 VTPM_DRV_STATE_SEND_INIT = 4, 35 VTPM_DRV_STATE_FAILURE = 5, 36 VTPM_DRV_STATE_WAIT_INIT_COMP = 6, 37 VTPM_DRV_STATE_SEND_INIT_COMP = 7, 38 VTPM_DRV_STATE_SEND_GET_VERSION = 8, 39 VTPM_DRV_STATE_WAIT_VERSION = 9, 40 VTPM_DRV_STATE_CHECK_VERSION = 10, 41 VTPM_DRV_STATE_SEND_BUFSIZE_REQ = 11, 42 VTPM_DRV_STATE_WAIT_BUFSIZE = 12, 43 VTPM_DRV_STATE_ALLOC_RTCE_BUF = 13, 44 VTPM_DRV_STATE_SEND_TPM_CMD = 14, 45 VTPM_DRV_STATE_WAIT_TPM_RSP = 15, 46 } vtpm_drv_state; 47 48 /* firmware driver errors */ 49 typedef enum { 50 VTPM_DRV_ERROR_NO_FAILURE = -1, 51 VTPM_DRV_ERROR_NOT_FOUND_TIMEOUT = 0, 52 VTPM_DRV_ERROR_UNEXPECTED_REG_ERROR = 1, 53 VTPM_DRV_ERROR_PARTNER_FAILED = 2, 54 VTPM_DRV_ERROR_UNEXPECTED_TSP_ERROR = 3, 55 VTPM_DRV_ERROR_TPM_PROTOCOL_ERROR = 4, 56 VTPM_DRV_ERROR_WAIT_TIMEOUT = 5, 57 VTPM_DRV_ERROR_UNEXPECTED_SEND_ERROR = 6, 58 VTPM_DRV_ERROR_CRQ_OPEN_FAIL = 7, 59 VTPM_DRV_ERROR_BAD_STATE = 8, 60 VTPM_DRV_ERROR_TPM_FAIL = 9, 61 VTPM_DRV_ERROR_TPM_CRQ_ERROR = 10, 62 VTPM_DRV_ERROR_BAD_VERSION = 11, 63 VTPM_DRV_ERROR_BAD_RTCE_SIZE = 12, 64 VTPM_DRV_ERROR_SML_FAILURE = 13, 65 VTPM_DRV_ERROR_SML_HANDED_OVER = 14, 66 } vtpm_drv_error; 67 68 /* the max. buffer size by the external TPM is 4k */ 69 #define PAPR_VTPM_MAX_BUFFER_SIZE 4096 70 71 /* exported functions */ 72 bool spapr_is_vtpm_present(void); 73 void spapr_vtpm_finalize(void); 74 vtpm_drv_error spapr_vtpm_get_error(void); 75 void spapr_vtpm_set_error(vtpm_drv_error errcode); 76 77 struct tpm_req_header; 78 int spapr_transmit(uint8_t locty, struct tpm_req_header *req, 79 void *respbuffer, uint32_t *respbufferlen, 80 enum tpm_duration_type to_t); 81 82 #endif /* TPM_DRIVERS_H */ 83