Abhimanyu Kapur | b3207fb | 2014-01-27 21:33:23 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved. |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 2 | |
| 3 | * Redistribution and use in source and binary forms, with or without |
| 4 | * modification, are permitted provided that the following conditions are |
| 5 | * met: |
| 6 | * * Redistributions of source code must retain the above copyright |
| 7 | * notice, this list of conditions and the following disclaimer. |
| 8 | * * Redistributions in binary form must reproduce the above |
| 9 | * copyright notice, this list of conditions and the following |
| 10 | * disclaimer in the documentation and/or other materials provided |
| 11 | * with the distribution. |
Siddhartha Agrawal | eb094c5 | 2013-01-28 12:11:43 -0800 | [diff] [blame] | 12 | * * Neither the name of The Linux Foundation nor the names of its |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 13 | * contributors may be used to endorse or promote products derived |
| 14 | * from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED |
| 17 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF |
| 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT |
| 19 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS |
| 20 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 21 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 22 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
| 23 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, |
| 24 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE |
| 25 | * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN |
| 26 | * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | */ |
| 28 | |
| 29 | #ifndef __SCM_H__ |
| 30 | #define __SCM_H__ |
| 31 | |
| 32 | /* 8 Byte SSD magic number (LE) */ |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 33 | #define DECRYPT_MAGIC_0 0x73737A74 |
| 34 | #define DECRYPT_MAGIC_1 0x676D6964 |
| 35 | #define ENCRYPT_MAGIC_0 0x6B647373 |
| 36 | #define ENCRYPT_MAGIC_1 0x676D6973 |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 37 | #define SSD_HEADER_MAGIC_SIZE 8 |
| 38 | #define SSD_HEADER_XML_SIZE 2048 |
sundarajan srinivasan | 6173b87 | 2013-03-13 17:36:48 -0700 | [diff] [blame] | 39 | #define SSD_HEADER_MIN_SIZE 128 |
| 40 | #define MULTIPLICATION_FACTOR 2 |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 41 | |
| 42 | typedef unsigned int uint32; |
| 43 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 44 | typedef struct { |
| 45 | uint32 len; |
| 46 | uint32 buf_offset; |
| 47 | uint32 resp_hdr_offset; |
| 48 | uint32 id; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 49 | } scm_command; |
| 50 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 51 | typedef struct { |
| 52 | uint32 len; |
| 53 | uint32 buf_offset; |
| 54 | uint32 is_complete; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 55 | } scm_response; |
| 56 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 57 | typedef struct { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 58 | uint32 *img_ptr; |
| 59 | uint32 *img_len_ptr; |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 60 | } img_req; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 61 | |
Siddhartha Agrawal | eb094c5 | 2013-01-28 12:11:43 -0800 | [diff] [blame] | 62 | typedef struct { |
| 63 | uint32 id; |
| 64 | uint32 spare; |
| 65 | } tz_secure_cfg; |
| 66 | |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 67 | typedef struct { |
| 68 | uint32 md_len; |
| 69 | uint32* md; |
| 70 | } ssd_parse_md_req; |
| 71 | |
| 72 | typedef struct { |
| 73 | uint32 status; |
| 74 | uint32 md_ctx_id; |
| 75 | uint32* md_end_ptr; |
| 76 | } ssd_parse_md_rsp; |
| 77 | |
| 78 | typedef struct { |
| 79 | uint32 md_ctx_id; |
| 80 | uint32 last_frag; |
| 81 | uint32 frag_len; |
| 82 | uint32 *frag; |
| 83 | } ssd_decrypt_img_frag_req; |
| 84 | |
| 85 | typedef struct { |
| 86 | uint32 status; |
| 87 | } ssd_decrypt_img_frag_rsp; |
| 88 | |
| 89 | typedef struct{ |
| 90 | uint32 feature_id; |
| 91 | } feature_version_req; |
| 92 | |
| 93 | typedef struct{ |
| 94 | uint32 version; |
| 95 | } feature_version_rsp; |
| 96 | |
| 97 | typedef struct{ |
| 98 | uint32 *keystore_ptr; |
| 99 | uint32 keystore_len; |
| 100 | } ssd_protect_keystore_req; |
| 101 | |
| 102 | typedef struct{ |
| 103 | uint32 status; |
| 104 | } ssd_protect_keystore_rsp; |
| 105 | |
Abhimanyu Kapur | b3207fb | 2014-01-27 21:33:23 -0800 | [diff] [blame] | 106 | typedef struct { |
Aparna Mallavarapu | 6875ade | 2014-06-16 22:15:28 +0530 | [diff] [blame^] | 107 | uint32_t config; |
| 108 | uint32_t spare; |
| 109 | } tz_xpu_prot_cmd; |
| 110 | |
| 111 | typedef struct { |
Abhimanyu Kapur | b3207fb | 2014-01-27 21:33:23 -0800 | [diff] [blame] | 112 | uint64_t el1_x0; |
| 113 | uint64_t el1_x1; |
| 114 | uint64_t el1_x2; |
| 115 | uint64_t el1_x3; |
| 116 | uint64_t el1_x4; |
| 117 | uint64_t el1_x5; |
| 118 | uint64_t el1_x6; |
| 119 | uint64_t el1_x7; |
| 120 | uint64_t el1_x8; |
| 121 | uint64_t el1_elr; |
| 122 | } el1_system_param; |
| 123 | |
Maria Yu | beeeeaf | 2014-06-30 13:05:43 +0800 | [diff] [blame] | 124 | struct tz_prng_data { |
| 125 | uint8_t *out_buf; |
| 126 | uint32_t out_buf_size; |
| 127 | }__packed; |
| 128 | |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 129 | /* Service IDs */ |
Aparna Mallavarapu | 68e233f | 2014-03-21 19:18:34 +0530 | [diff] [blame] | 130 | #define SCM_SVC_BOOT 0x01 |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 131 | #define TZBSP_SVC_INFO 0x06 |
| 132 | #define SCM_SVC_SSD 0x07 |
| 133 | #define SVC_MEMORY_PROTECTION 0x0C |
Maria Yu | beeeeaf | 2014-06-30 13:05:43 +0800 | [diff] [blame] | 134 | #define TZ_SVC_CRYPTO 0x0A |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 135 | |
| 136 | /*Service specific command IDs */ |
Aparna Mallavarapu | 6875ade | 2014-06-16 22:15:28 +0530 | [diff] [blame^] | 137 | #define ERR_FATAL_ENABLE 0x0 |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 138 | #define SSD_DECRYPT_ID 0x01 |
| 139 | #define SSD_ENCRYPT_ID 0x02 |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 140 | #define SSD_PROTECT_KEYSTORE_ID 0x05 |
| 141 | #define SSD_PARSE_MD_ID 0x06 |
| 142 | #define SSD_DECRYPT_IMG_FRAG_ID 0x07 |
Aparna Mallavarapu | 68e233f | 2014-03-21 19:18:34 +0530 | [diff] [blame] | 143 | #define WDOG_DEBUG_DISABLE 0x09 |
| 144 | #define SCM_DLOAD_CMD 0x10 |
Aparna Mallavarapu | 6875ade | 2014-06-16 22:15:28 +0530 | [diff] [blame^] | 145 | #define XPU_ERR_FATAL 0xe |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 146 | |
| 147 | #define SECURE_DEVICE_MDSS 0x01 |
| 148 | |
Siddhartha Agrawal | eb094c5 | 2013-01-28 12:11:43 -0800 | [diff] [blame] | 149 | #define IOMMU_SECURE_CFG 0x02 |
| 150 | |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 151 | #define TZ_INFO_GET_FEATURE_ID 0x03 |
| 152 | |
Maria Yu | beeeeaf | 2014-06-30 13:05:43 +0800 | [diff] [blame] | 153 | #define PRNG_CMD_ID 0x01 |
| 154 | |
Aparna Mallavarapu | 68e233f | 2014-03-21 19:18:34 +0530 | [diff] [blame] | 155 | /* Download Mode specific arguments to be passed to TZ */ |
| 156 | #define SCM_EDLOAD_MODE 0x02 |
| 157 | #define SCM_DLOAD_MODE 0x10 |
| 158 | |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 159 | /* SSD parsing status messages from TZ */ |
| 160 | #define SSD_PMD_ENCRYPTED 0 |
| 161 | #define SSD_PMD_NOT_ENCRYPTED 1 |
| 162 | #define SSD_PMD_NO_MD_FOUND 3 |
| 163 | #define SSD_PMD_BUSY 4 |
| 164 | #define SSD_PMD_BAD_MD_PTR_OR_LEN 5 |
| 165 | #define SSD_PMD_PARSING_INCOMPLETE 6 |
| 166 | #define SSD_PMD_PARSING_FAILED 7 |
| 167 | #define SSD_PMD_SETUP_CIPHER_FAILED 8 |
| 168 | |
| 169 | /* Keystore status messages */ |
| 170 | #define TZBSP_SSD_PKS_SUCCESS 0 /**< Successful return. */ |
| 171 | #define TZBSP_SSD_PKS_INVALID_PTR 1 /**< Keystore pointer invalid. */ |
| 172 | #define TZBSP_SSD_PKS_INVALID_LEN 2 /**< Keystore length incorrect. */ |
| 173 | #define TZBSP_SSD_PKS_UNALIGNED_PTR 3 /**< Keystore pointer not word |
| 174 | aligned. */ |
| 175 | #define TZBSP_SSD_PKS_PROTECT_MEM_FAILED 4 /**< Failure when protecting |
| 176 | the keystore memory.*/ |
| 177 | #define TZBSP_SSD_PKS_INVALID_NUM_KEYS 5 /**< Unsupported number of |
| 178 | keys passed. If a valid |
| 179 | pointer to non-secure |
| 180 | memory is passed that |
| 181 | isn't a keystore, this is |
| 182 | a likely return code. */ |
| 183 | #define TZBSP_SSD_PKS_DECRYPT_FAILED 6 /**< The keystore could not be |
| 184 | decrypted. */ |
| 185 | |
| 186 | /* Features in TZ */ |
| 187 | #define TZBSP_FVER_SSD 5 |
| 188 | |
| 189 | #define TZBSP_GET_FEATURE_VERSION(major) ((major >> 22)& 0x3FF) |
Siddhartha Agrawal | eb094c5 | 2013-01-28 12:11:43 -0800 | [diff] [blame] | 190 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 191 | static uint32 smc(uint32 cmd_addr); |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 192 | int decrypt_scm(uint32_t ** img_ptr, uint32_t * img_len_ptr); |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 193 | int decrypt_scm_v2(uint32_t ** img_ptr, uint32_t * img_len_ptr); |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 194 | int encrypt_scm(uint32_t ** img_ptr, uint32_t * img_len_ptr); |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 195 | int scm_svc_version(uint32 * major, uint32 * minor); |
| 196 | int scm_protect_keystore(uint32_t * img_ptr, uint32_t img_len); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 197 | |
Deepa Dinamani | 193874e | 2012-02-07 14:00:04 -0800 | [diff] [blame] | 198 | #define SCM_SVC_FUSE 0x08 |
| 199 | #define SCM_BLOW_SW_FUSE_ID 0x01 |
| 200 | #define SCM_IS_SW_FUSE_BLOWN_ID 0x02 |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 201 | |
Deepa Dinamani | 193874e | 2012-02-07 14:00:04 -0800 | [diff] [blame] | 202 | #define HLOS_IMG_TAMPER_FUSE 0 |
| 203 | |
| 204 | |
| 205 | #define SCM_SVC_CE_CHN_SWITCH_ID 0x04 |
| 206 | #define SCM_CE_CHN_SWITCH_ID 0x02 |
| 207 | |
Amir Samuelov | 4620ad2 | 2013-03-13 11:30:05 +0200 | [diff] [blame] | 208 | #define SCM_SVC_ES 0x10 |
| 209 | #define SCM_SAVE_PARTITION_HASH_ID 0x01 |
| 210 | |
Channagoud Kadabi | 179df0b | 2013-12-12 14:53:31 -0800 | [diff] [blame] | 211 | #define SCM_SVC_PWR 0x9 |
| 212 | #define SCM_IO_DISABLE_PMIC_ARBITER 0x1 |
| 213 | |
Abhimanyu Kapur | b3207fb | 2014-01-27 21:33:23 -0800 | [diff] [blame] | 214 | #define SCM_SVC_MILESTONE_32_64_ID 0x1 |
| 215 | #define SCM_SVC_MILESTONE_CMD_ID 0xf |
| 216 | |
Deepa Dinamani | 193874e | 2012-02-07 14:00:04 -0800 | [diff] [blame] | 217 | enum ap_ce_channel_type { |
| 218 | AP_CE_REGISTER_USE = 0, |
| 219 | AP_CE_ADM_USE = 1 |
| 220 | }; |
| 221 | |
| 222 | /* Apps CE resource. */ |
| 223 | #define TZ_RESOURCE_CE_AP 2 |
| 224 | |
| 225 | uint8_t switch_ce_chn_cmd(enum ap_ce_channel_type channel); |
| 226 | |
| 227 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 228 | void set_tamper_fuse_cmd(); |
| 229 | |
Channagoud Kadabi | 179df0b | 2013-12-12 14:53:31 -0800 | [diff] [blame] | 230 | int scm_halt_pmic_arbiter(); |
Aparna Mallavarapu | 68e233f | 2014-03-21 19:18:34 +0530 | [diff] [blame] | 231 | int scm_call_atomic2(uint32_t svc, uint32_t cmd, uint32_t arg1, uint32_t arg2); |
Channagoud Kadabi | 179df0b | 2013-12-12 14:53:31 -0800 | [diff] [blame] | 232 | |
Abhimanyu Kapur | b3207fb | 2014-01-27 21:33:23 -0800 | [diff] [blame] | 233 | void scm_elexec_call(paddr_t kernel_entry, paddr_t dtb_offset); |
Maria Yu | beeeeaf | 2014-06-30 13:05:43 +0800 | [diff] [blame] | 234 | void *get_canary(); |
Aparna Mallavarapu | 6875ade | 2014-06-16 22:15:28 +0530 | [diff] [blame^] | 235 | /* API to configure XPU violations as fatal */ |
| 236 | int scm_xpu_err_fatal_init(); |
Abhimanyu Kapur | b3207fb | 2014-01-27 21:33:23 -0800 | [diff] [blame] | 237 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 238 | /** |
| 239 | * struct scm_command - one SCM command buffer |
| 240 | * @len: total available memory for command and response |
| 241 | * @buf_offset: start of command buffer |
| 242 | * @resp_hdr_offset: start of response buffer |
| 243 | * @id: command to be executed |
| 244 | * @buf: buffer returned from scm_get_command_buffer() |
| 245 | * |
| 246 | * An SCM command is layed out in memory as follows: |
| 247 | * |
| 248 | * ------------------- <--- struct scm_command |
| 249 | * | command header | |
| 250 | * ------------------- <--- scm_get_command_buffer() |
| 251 | * | command buffer | |
| 252 | * ------------------- <--- struct scm_response and |
| 253 | * | response header | scm_command_to_response() |
| 254 | * ------------------- <--- scm_get_response_buffer() |
| 255 | * | response buffer | |
| 256 | * ------------------- |
| 257 | * |
| 258 | * There can be arbitrary padding between the headers and buffers so |
| 259 | * you should always use the appropriate scm_get_*_buffer() routines |
| 260 | * to access the buffers in a safe manner. |
| 261 | */ |
| 262 | struct scm_command { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 263 | uint32_t len; |
| 264 | uint32_t buf_offset; |
| 265 | uint32_t resp_hdr_offset; |
| 266 | uint32_t id; |
| 267 | uint32_t buf[0]; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 268 | }; |
| 269 | |
| 270 | /** |
| 271 | * struct scm_response - one SCM response buffer |
| 272 | * @len: total available memory for response |
| 273 | * @buf_offset: start of response data relative to start of scm_response |
| 274 | * @is_complete: indicates if the command has finished processing |
| 275 | */ |
| 276 | struct scm_response { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 277 | uint32_t len; |
| 278 | uint32_t buf_offset; |
| 279 | uint32_t is_complete; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 280 | }; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 281 | #endif |