Sridhar Parasuram | 4d3f66d | 2015-07-27 15:34:18 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, The Linux Foundation. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are |
| 6 | * met: |
| 7 | * * Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * * Redistributions in binary form must reproduce the above |
| 10 | * copyright notice, this list of conditions and the following |
| 11 | * disclaimer in the documentation and/or other materials provided |
| 12 | * with the distribution. |
| 13 | * * Neither the name of The Linux Foundation nor the names of its |
| 14 | * contributors may be used to endorse or promote products derived |
| 15 | * from this software without specific prior written permission. |
| 16 | |
| 17 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 21 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 24 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 25 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 26 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 27 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 28 | */ |
| 29 | |
| 30 | #ifndef KM_MAIN_H |
| 31 | #define KM_MAIN_H |
| 32 | |
| 33 | #include <sys/types.h> |
| 34 | /** |
| 35 | * Commands supported |
| 36 | */ |
| 37 | #define KEYMASTER_CMD_ID 0x100UL |
| 38 | #define KEYMASTER_UTILS_CMD_ID 0x200UL |
| 39 | |
| 40 | #define UINT32_MAX (0xffffffff) |
| 41 | |
| 42 | typedef enum { |
| 43 | /* |
| 44 | * List the commands supportedin by the hardware. |
| 45 | */ |
Sridhar Parasuram | 843ab54 | 2015-07-27 15:45:28 -0700 | [diff] [blame] | 46 | KEYMASTER_GET_SUPPORTED_ALGORITHMS = (KEYMASTER_CMD_ID + 1UL), |
| 47 | KEYMASTER_GET_SUPPORTED_BLOCK_MODES = (KEYMASTER_CMD_ID + 2UL), |
| 48 | KEYMASTER_GET_SUPPORTED_PADDING_MODES = (KEYMASTER_CMD_ID + 3UL), |
| 49 | KEYMASTER_GET_SUPPORTED_DIGESTS = (KEYMASTER_CMD_ID + 4UL), |
| 50 | KEYMASTER_GET_SUPPORTED_IMPORT_FORMATS = (KEYMASTER_CMD_ID + 5UL), |
| 51 | KEYMASTER_GET_SUPPORTED_EXPORT_FORMATS = (KEYMASTER_CMD_ID + 6UL), |
| 52 | KEYMASTER_ADD_RNG_ENTROPY = (KEYMASTER_CMD_ID + 7UL), |
| 53 | KEYMASTER_GENERATE_KEY = (KEYMASTER_CMD_ID + 8UL), |
| 54 | KEYMASTER_GET_KEY_CHARACTERISTICS = (KEYMASTER_CMD_ID + 9UL), |
| 55 | KEYMASTER_RESCOPE = (KEYMASTER_CMD_ID + 10UL), |
| 56 | KEYMASTER_IMPORT_KEY = (KEYMASTER_CMD_ID + 11UL), |
| 57 | KEYMASTER_EXPORT_KEY = (KEYMASTER_CMD_ID + 12UL), |
| 58 | KEYMASTER_DELETE_KEY = (KEYMASTER_CMD_ID + 13UL), |
| 59 | KEYMASTER_DELETE_ALL_KEYS = (KEYMASTER_CMD_ID + 14UL), |
| 60 | KEYMASTER_BEGIN = (KEYMASTER_CMD_ID + 15UL), |
| 61 | KEYMASTER_GET_OUTPUT_SIZE = (KEYMASTER_CMD_ID + 16UL), |
| 62 | KEYMASTER_UPDATE = (KEYMASTER_CMD_ID + 17UL), |
| 63 | KEYMASTER_FINISH = (KEYMASTER_CMD_ID + 18UL), |
| 64 | KEYMASTER_ABORT = (KEYMASTER_CMD_ID + 19UL), |
| 65 | |
| 66 | KEYMASTER_SET_ROT = (KEYMASTER_UTILS_CMD_ID + 1UL), |
Sridhar Parasuram | 4d3f66d | 2015-07-27 15:34:18 -0700 | [diff] [blame] | 67 | KEYMASTER_READ_LK_DEVICE_STATE = (KEYMASTER_UTILS_CMD_ID + 2UL), |
| 68 | KEYMASTER_WRITE_LK_DEVICE_STATE = (KEYMASTER_UTILS_CMD_ID + 3UL), |
| 69 | KEYMASTER_MILESTONE_CALL = (KEYMASTER_UTILS_CMD_ID + 4UL), |
Sridhar Parasuram | ce1e572 | 2015-09-29 12:13:05 -0700 | [diff] [blame] | 70 | KEYMASTER_SECURE_WRITE_PROTECT = (KEYMASTER_UTILS_CMD_ID + 6UL), |
Sridhar Parasuram | 4d3f66d | 2015-07-27 15:34:18 -0700 | [diff] [blame] | 71 | |
| 72 | KEYMASTER_LAST_CMD_ENTRY = (int)0xFFFFFFFFULL |
| 73 | } keymaster_cmd_t; |
| 74 | |
| 75 | |
| 76 | /* |
| 77 | * Utils Api struct |
| 78 | */ |
Sridhar Parasuram | 843ab54 | 2015-07-27 15:45:28 -0700 | [diff] [blame] | 79 | /** |
| 80 | @brief |
| 81 | Data structure |
| 82 | |
| 83 | @param[in] cmd_id Requested command |
| 84 | @param[in] rot_ofset Offset from the top of the struct. |
| 85 | @param[in] rot_size Size of the ROT |
| 86 | */ |
| 87 | typedef struct _km_set_rot_req_t { |
| 88 | uint32 cmd_id; |
| 89 | uint32 rot_ofset; |
| 90 | uint32 rot_size; |
| 91 | }__attribute__ ((packed)) km_set_rot_req_t; |
| 92 | |
| 93 | /** |
| 94 | @brief |
| 95 | Data structure |
| 96 | |
| 97 | @param[out] status Status of the request |
| 98 | */ |
| 99 | typedef struct _km_set_rot_rsp_t { |
| 100 | int status; |
| 101 | }__attribute__ ((packed)) km_set_rot_rsp_t; |
Sridhar Parasuram | 4d3f66d | 2015-07-27 15:34:18 -0700 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | @brief |
| 105 | Data structure |
| 106 | |
| 107 | @param[in] cmd_id Requested command |
| 108 | @param[in] data information (could be data or a pointer to the memory that holds the data |
| 109 | @param[in] len if data is ptr to some buffer, len indicates length of the buffer |
| 110 | */ |
| 111 | typedef struct send_cmd{ |
| 112 | uint32 cmd_id; |
| 113 | uint32 data; |
| 114 | uint32 len; |
| 115 | } __attribute__ ((packed)) send_cmd_t; |
| 116 | |
| 117 | /* |
| 118 | typedef struct send_cmd_rsp{ |
| 119 | uint32 cmd_id; |
| 120 | uint32 data; |
| 121 | int32 status; |
| 122 | } __attribute__ ((packed)) send_cmd_rsp_t; */ |
| 123 | |
| 124 | /** |
| 125 | @brief |
| 126 | Data structure |
| 127 | |
| 128 | @param[in] cmd_id Requested command |
| 129 | */ |
| 130 | typedef struct _km_set_milestone_req_t { |
| 131 | uint32 cmd_id; |
| 132 | }__attribute__ ((packed)) km_set_milestone_req_t; |
| 133 | |
| 134 | /** |
| 135 | @brief |
| 136 | Data structure |
| 137 | |
| 138 | @param[out] status Status of the request |
| 139 | */ |
| 140 | typedef struct _km_set_milestone_rsp_t { |
| 141 | int status; |
| 142 | }__attribute__ ((packed)) km_set_milestone_rsp_t; |
| 143 | |
Sridhar Parasuram | ed00328 | 2015-07-10 09:50:12 -0700 | [diff] [blame] | 144 | /* |
| 145 | * Structures for delete_all cmd |
| 146 | */ |
| 147 | /* |
| 148 | @brief |
| 149 | Data structure |
| 150 | |
| 151 | @param[in] cmd_id Requested command |
| 152 | */ |
| 153 | typedef struct _key_op_delete_all_req_t { |
| 154 | uint32 cmd_id; |
| 155 | }__attribute__ ((packed)) key_op_delete_all_req_t; |
| 156 | |
| 157 | /* |
| 158 | @brief |
| 159 | Data structure |
| 160 | |
| 161 | @param[out] status Status of the request |
| 162 | */ |
| 163 | typedef struct _key_op_delete_all_rsp_t { |
| 164 | int status; |
| 165 | }__attribute__ ((packed)) key_op_delete_all_rsp_t; |
| 166 | |
Sridhar Parasuram | ce1e572 | 2015-09-29 12:13:05 -0700 | [diff] [blame] | 167 | typedef enum _secure_write_prot_op_t |
| 168 | { |
| 169 | SWP_READ_CONFIG, |
| 170 | SWP_WRITE_CONFIG, |
| 171 | SWP_LAST_CMD_ENTRY = (int)0xFFFFFFFFULL |
| 172 | } secure_write_prot_op_t; |
| 173 | |
| 174 | /* |
| 175 | @brief |
| 176 | Data structure |
| 177 | |
| 178 | @param[in] cmd_id Command ID of the request |
| 179 | @param[in] op Secure write protect operation (enum from secure_write_prot_op_t) |
| 180 | @param[in] swp_write_data_offset Offset of data for SWP operation |
| 181 | @param[in] swp_write_data_len Length of data for SWP operation |
| 182 | */ |
| 183 | |
| 184 | typedef struct _secure_write_prot_req_t |
| 185 | { |
| 186 | uint32 cmd_id; |
| 187 | uint32 op; |
| 188 | uint32 swp_write_data_offset; |
| 189 | uint32 swp_write_data_len; |
| 190 | }__attribute__((packed)) secure_write_prot_req_t; |
| 191 | |
| 192 | /* |
| 193 | @brief |
| 194 | Data structure |
| 195 | |
| 196 | @param[out] status Status of the request |
| 197 | @param[out] swp_read_data_offset Offset of data for SWP operation |
| 198 | @param[out] swp_read_data_len Length of data for SWP operation |
| 199 | */ |
| 200 | |
| 201 | typedef struct _secure_write_prot_rsp_t |
| 202 | { |
| 203 | int status; |
| 204 | uint32 swp_read_data_offset; |
| 205 | uint32 swp_read_data_len; |
| 206 | }__attribute__((packed)) secure_write_prot_rsp_t; |
| 207 | |
Sridhar Parasuram | 4d3f66d | 2015-07-27 15:34:18 -0700 | [diff] [blame] | 208 | #endif /* KM_MAIN_H */ |