lijuang | c76a763 | 2017-12-07 14:37:56 +0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2017, 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 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 32 | #include <reboot.h> |
| 33 | |
Channagoud Kadabi | dd85e7f | 2014-08-05 19:58:37 -0700 | [diff] [blame] | 34 | /* ARM SCM format support related flags */ |
| 35 | #define SIP_SVC_CALLS 0x02000000 |
| 36 | #define MAKE_SIP_SCM_CMD(svc_id, cmd_id) ((((svc_id << 8) | (cmd_id)) & 0xFFFF) | SIP_SVC_CALLS) |
| 37 | #define MAKE_SCM_VAR_ARGS(num_args, t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, ...) (\ |
| 38 | (((t0) & 0xff) << 4) | \ |
| 39 | (((t1) & 0xff) << 6) | \ |
| 40 | (((t2) & 0xff) << 8) | \ |
| 41 | (((t3) & 0xff) << 10) | \ |
| 42 | (((t4) & 0xff) << 12) | \ |
| 43 | (((t5) & 0xff) << 14) | \ |
| 44 | (((t6) & 0xff) << 16) | \ |
| 45 | (((t7) & 0xff) << 18) | \ |
| 46 | (((t8) & 0xff) << 20) | \ |
| 47 | (((t9) & 0xff) << 22) | \ |
| 48 | (num_args & 0xffff)) |
| 49 | #define MAKE_SCM_ARGS(...) MAKE_SCM_VAR_ARGS(__VA_ARGS__, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) |
| 50 | #define SCM_ATOMIC_BIT BIT(31) |
| 51 | #define SCM_MAX_ARG_LEN 5 |
| 52 | #define SCM_INDIR_MAX_LEN 10 |
| 53 | |
| 54 | enum |
| 55 | { |
| 56 | SMC_PARAM_TYPE_VALUE = 0, |
| 57 | SMC_PARAM_TYPE_BUFFER_READ, |
| 58 | SMC_PARAM_TYPE_BUFFER_READWRITE, |
| 59 | SMC_PARAM_TYPE_BUFFER_VALIDATION, |
| 60 | } scm_arg_type; |
| 61 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 62 | /* 8 Byte SSD magic number (LE) */ |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 63 | #define DECRYPT_MAGIC_0 0x73737A74 |
| 64 | #define DECRYPT_MAGIC_1 0x676D6964 |
| 65 | #define ENCRYPT_MAGIC_0 0x6B647373 |
| 66 | #define ENCRYPT_MAGIC_1 0x676D6973 |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 67 | #define SSD_HEADER_MAGIC_SIZE 8 |
| 68 | #define SSD_HEADER_XML_SIZE 2048 |
sundarajan srinivasan | 6173b87 | 2013-03-13 17:36:48 -0700 | [diff] [blame] | 69 | #define SSD_HEADER_MIN_SIZE 128 |
| 70 | #define MULTIPLICATION_FACTOR 2 |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 71 | |
| 72 | typedef unsigned int uint32; |
| 73 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 74 | typedef struct { |
| 75 | uint32 len; |
| 76 | uint32 buf_offset; |
| 77 | uint32 resp_hdr_offset; |
| 78 | uint32 id; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 79 | } scm_command; |
| 80 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 81 | typedef struct { |
| 82 | uint32 len; |
| 83 | uint32 buf_offset; |
| 84 | uint32 is_complete; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 85 | } scm_response; |
| 86 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 87 | typedef struct { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 88 | uint32 *img_ptr; |
| 89 | uint32 *img_len_ptr; |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 90 | } img_req; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 91 | |
Siddhartha Agrawal | eb094c5 | 2013-01-28 12:11:43 -0800 | [diff] [blame] | 92 | typedef struct { |
| 93 | uint32 id; |
| 94 | uint32 spare; |
| 95 | } tz_secure_cfg; |
| 96 | |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 97 | typedef struct { |
| 98 | uint32 md_len; |
| 99 | uint32* md; |
| 100 | } ssd_parse_md_req; |
| 101 | |
| 102 | typedef struct { |
| 103 | uint32 status; |
| 104 | uint32 md_ctx_id; |
| 105 | uint32* md_end_ptr; |
| 106 | } ssd_parse_md_rsp; |
| 107 | |
| 108 | typedef struct { |
| 109 | uint32 md_ctx_id; |
| 110 | uint32 last_frag; |
| 111 | uint32 frag_len; |
| 112 | uint32 *frag; |
| 113 | } ssd_decrypt_img_frag_req; |
| 114 | |
| 115 | typedef struct { |
| 116 | uint32 status; |
| 117 | } ssd_decrypt_img_frag_rsp; |
| 118 | |
| 119 | typedef struct{ |
| 120 | uint32 feature_id; |
| 121 | } feature_version_req; |
| 122 | |
| 123 | typedef struct{ |
| 124 | uint32 version; |
| 125 | } feature_version_rsp; |
| 126 | |
| 127 | typedef struct{ |
Amit Blay | bdfabc6 | 2015-01-29 22:04:13 +0200 | [diff] [blame] | 128 | uint32 *status_ptr; |
| 129 | uint32 status_len; |
| 130 | } get_secure_state_req; |
| 131 | |
| 132 | typedef struct{ |
| 133 | uint32 status_low; |
| 134 | uint32 status_high; |
| 135 | } get_secure_state_rsp; |
| 136 | |
| 137 | typedef struct{ |
| 138 | uint32 row_address; |
| 139 | uint32 addr_type; |
| 140 | uint32 *row_data; |
| 141 | uint32 *qfprom_api_status; |
| 142 | } qfprom_read_row_req; |
| 143 | |
| 144 | typedef struct{ |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 145 | uint32 *keystore_ptr; |
| 146 | uint32 keystore_len; |
| 147 | } ssd_protect_keystore_req; |
| 148 | |
| 149 | typedef struct{ |
| 150 | uint32 status; |
| 151 | } ssd_protect_keystore_rsp; |
| 152 | |
Abhimanyu Kapur | b3207fb | 2014-01-27 21:33:23 -0800 | [diff] [blame] | 153 | typedef struct { |
Aparna Mallavarapu | 6875ade | 2014-06-16 22:15:28 +0530 | [diff] [blame] | 154 | uint32_t config; |
| 155 | uint32_t spare; |
| 156 | } tz_xpu_prot_cmd; |
| 157 | |
| 158 | typedef struct { |
Abhimanyu Kapur | b3207fb | 2014-01-27 21:33:23 -0800 | [diff] [blame] | 159 | uint64_t el1_x0; |
| 160 | uint64_t el1_x1; |
| 161 | uint64_t el1_x2; |
| 162 | uint64_t el1_x3; |
| 163 | uint64_t el1_x4; |
| 164 | uint64_t el1_x5; |
| 165 | uint64_t el1_x6; |
| 166 | uint64_t el1_x7; |
| 167 | uint64_t el1_x8; |
| 168 | uint64_t el1_elr; |
| 169 | } el1_system_param; |
| 170 | |
Maria Yu | beeeeaf | 2014-06-30 13:05:43 +0800 | [diff] [blame] | 171 | struct tz_prng_data { |
| 172 | uint8_t *out_buf; |
| 173 | uint32_t out_buf_size; |
Maria Yu | d3aec50 | 2014-12-23 16:58:47 +0800 | [diff] [blame] | 174 | }__PACKED; |
Maria Yu | beeeeaf | 2014-06-30 13:05:43 +0800 | [diff] [blame] | 175 | |
Amit Blay | fe23ee2 | 2015-01-09 19:09:51 +0200 | [diff] [blame] | 176 | typedef struct { |
| 177 | uint8_t *in_buf; |
| 178 | uint32_t in_buf_size; |
| 179 | uint8_t *out_buf; |
| 180 | uint32_t out_buf_size; |
| 181 | uint32_t direction; |
| 182 | } mdtp_cipher_dip_req; |
| 183 | |
Channagoud Kadabi | dd85e7f | 2014-08-05 19:58:37 -0700 | [diff] [blame] | 184 | /* SCM support as per ARM spec */ |
| 185 | /* |
| 186 | * Structure to define the argument for scm call |
| 187 | * x0: is the command ID |
| 188 | * x1: Number of argument & type of arguments |
| 189 | * : Type can be any of |
| 190 | * : SMC_PARAM_TYPE_VALUE 0 |
| 191 | * : SMC_PARAM_TYPE_BUFFER_READ 1 |
| 192 | * : SMC_PARAM_TYPE_BUFFER_READWRITE 2 |
| 193 | * : SMC_PARAM_TYPE_BUFFER_VALIDATION 3 |
| 194 | * @Note: Number of argument count starts from X2. |
| 195 | * x2-x4: Arguments |
| 196 | * X5[10]: if the number of argument is more, an indirect |
| 197 | * : list can be passed here. |
| 198 | */ |
| 199 | typedef struct { |
| 200 | uint32_t x0;/* command ID details as per ARMv8 spec : |
| 201 | 0:7 command, 8:15 service id |
| 202 | 0x02000000: SIP calls |
| 203 | 30: SMC32 or SMC64 |
| 204 | 31: Standard or fast calls*/ |
| 205 | uint32_t x1; /* # of args and attributes for buffers |
| 206 | * 0-3: arg # |
| 207 | * 4-5: type of arg1 |
| 208 | * 6-7: type of arg2 |
| 209 | * : |
| 210 | * : |
| 211 | * 20-21: type of arg8 |
| 212 | * 22-23: type of arg9 |
| 213 | */ |
| 214 | uint32_t x2; /* Param1 */ |
| 215 | uint32_t x3; /* Param2 */ |
| 216 | uint32_t x4; /* Param3 */ |
| 217 | uint32_t x5[10]; /* Indirect parameter list */ |
| 218 | uint32_t atomic; /* To indicate if its standard or fast call */ |
| 219 | } scmcall_arg; |
| 220 | |
| 221 | /* Return value for the SCM call: |
| 222 | * SCM call returns values in register if its less than |
| 223 | * 12 bytes, anything greater need to be input buffer + input len |
| 224 | * arguments |
| 225 | */ |
| 226 | typedef struct |
| 227 | { |
| 228 | uint32_t x1; |
| 229 | uint32_t x2; |
| 230 | uint32_t x3; |
| 231 | } scmcall_ret; |
| 232 | |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 233 | /* Service IDs */ |
Aparna Mallavarapu | 68e233f | 2014-03-21 19:18:34 +0530 | [diff] [blame] | 234 | #define SCM_SVC_BOOT 0x01 |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 235 | #define TZBSP_SVC_INFO 0x06 |
| 236 | #define SCM_SVC_SSD 0x07 |
| 237 | #define SVC_MEMORY_PROTECTION 0x0C |
Maria Yu | beeeeaf | 2014-06-30 13:05:43 +0800 | [diff] [blame] | 238 | #define TZ_SVC_CRYPTO 0x0A |
Channagoud Kadabi | dd85e7f | 2014-08-05 19:58:37 -0700 | [diff] [blame] | 239 | #define SCM_SVC_INFO 0x06 |
Channagoud Kadabi | 6479ce3 | 2015-06-17 17:30:40 -0700 | [diff] [blame] | 240 | #define TZ_SVC_DLOAD_MODE 0x3 |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 241 | |
| 242 | /*Service specific command IDs */ |
Aparna Mallavarapu | 6875ade | 2014-06-16 22:15:28 +0530 | [diff] [blame] | 243 | #define ERR_FATAL_ENABLE 0x0 |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 244 | #define SSD_DECRYPT_ID 0x01 |
| 245 | #define SSD_ENCRYPT_ID 0x02 |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 246 | #define SSD_PROTECT_KEYSTORE_ID 0x05 |
| 247 | #define SSD_PARSE_MD_ID 0x06 |
| 248 | #define SSD_DECRYPT_IMG_FRAG_ID 0x07 |
Aparna Mallavarapu | 68e233f | 2014-03-21 19:18:34 +0530 | [diff] [blame] | 249 | #define WDOG_DEBUG_DISABLE 0x09 |
| 250 | #define SCM_DLOAD_CMD 0x10 |
Aparna Mallavarapu | 6875ade | 2014-06-16 22:15:28 +0530 | [diff] [blame] | 251 | #define XPU_ERR_FATAL 0xe |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 252 | |
| 253 | #define SECURE_DEVICE_MDSS 0x01 |
| 254 | |
Siddhartha Agrawal | eb094c5 | 2013-01-28 12:11:43 -0800 | [diff] [blame] | 255 | #define IOMMU_SECURE_CFG 0x02 |
| 256 | |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 257 | #define TZ_INFO_GET_FEATURE_ID 0x03 |
Amit Blay | bdfabc6 | 2015-01-29 22:04:13 +0200 | [diff] [blame] | 258 | #define TZ_INFO_GET_SECURE_STATE 0x04 |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 259 | |
Maria Yu | beeeeaf | 2014-06-30 13:05:43 +0800 | [diff] [blame] | 260 | #define PRNG_CMD_ID 0x01 |
Channagoud Kadabi | dd85e7f | 2014-08-05 19:58:37 -0700 | [diff] [blame] | 261 | #define IS_CALL_AVAIL_CMD 0x01 |
Aparna Mallavarapu | 246c30b | 2014-12-11 12:07:51 +0530 | [diff] [blame] | 262 | #define IS_SECURE_BOOT_ENABLED 0x04 |
Maria Yu | beeeeaf | 2014-06-30 13:05:43 +0800 | [diff] [blame] | 263 | |
Aparna Mallavarapu | 68e233f | 2014-03-21 19:18:34 +0530 | [diff] [blame] | 264 | /* Download Mode specific arguments to be passed to TZ */ |
Lijuan Gao | f1286fb | 2015-01-29 19:47:28 +0800 | [diff] [blame] | 265 | #define SCM_EDLOAD_MODE 0x01 |
Aparna Mallavarapu | 68e233f | 2014-03-21 19:18:34 +0530 | [diff] [blame] | 266 | #define SCM_DLOAD_MODE 0x10 |
| 267 | |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 268 | /* SSD parsing status messages from TZ */ |
| 269 | #define SSD_PMD_ENCRYPTED 0 |
| 270 | #define SSD_PMD_NOT_ENCRYPTED 1 |
| 271 | #define SSD_PMD_NO_MD_FOUND 3 |
| 272 | #define SSD_PMD_BUSY 4 |
| 273 | #define SSD_PMD_BAD_MD_PTR_OR_LEN 5 |
| 274 | #define SSD_PMD_PARSING_INCOMPLETE 6 |
| 275 | #define SSD_PMD_PARSING_FAILED 7 |
| 276 | #define SSD_PMD_SETUP_CIPHER_FAILED 8 |
| 277 | |
| 278 | /* Keystore status messages */ |
| 279 | #define TZBSP_SSD_PKS_SUCCESS 0 /**< Successful return. */ |
| 280 | #define TZBSP_SSD_PKS_INVALID_PTR 1 /**< Keystore pointer invalid. */ |
| 281 | #define TZBSP_SSD_PKS_INVALID_LEN 2 /**< Keystore length incorrect. */ |
| 282 | #define TZBSP_SSD_PKS_UNALIGNED_PTR 3 /**< Keystore pointer not word |
| 283 | aligned. */ |
| 284 | #define TZBSP_SSD_PKS_PROTECT_MEM_FAILED 4 /**< Failure when protecting |
| 285 | the keystore memory.*/ |
| 286 | #define TZBSP_SSD_PKS_INVALID_NUM_KEYS 5 /**< Unsupported number of |
| 287 | keys passed. If a valid |
| 288 | pointer to non-secure |
| 289 | memory is passed that |
| 290 | isn't a keystore, this is |
| 291 | a likely return code. */ |
| 292 | #define TZBSP_SSD_PKS_DECRYPT_FAILED 6 /**< The keystore could not be |
| 293 | decrypted. */ |
| 294 | |
| 295 | /* Features in TZ */ |
| 296 | #define TZBSP_FVER_SSD 5 |
| 297 | |
| 298 | #define TZBSP_GET_FEATURE_VERSION(major) ((major >> 22)& 0x3FF) |
Siddhartha Agrawal | eb094c5 | 2013-01-28 12:11:43 -0800 | [diff] [blame] | 299 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 300 | static uint32 smc(uint32 cmd_addr); |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 301 | int decrypt_scm(uint32_t ** img_ptr, uint32_t * img_len_ptr); |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 302 | 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] | 303 | int encrypt_scm(uint32_t ** img_ptr, uint32_t * img_len_ptr); |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 304 | int scm_svc_version(uint32 * major, uint32 * minor); |
Amit Blay | bdfabc6 | 2015-01-29 22:04:13 +0200 | [diff] [blame] | 305 | |
| 306 | /** |
| 307 | * Check security status on the device. Returns the security check result. |
| 308 | * Bit value 0 means the check passing, and bit value 1 means the check failing. |
| 309 | * |
| 310 | * @state_low[out] : lower 32 bits of the state: |
| 311 | * Bit 0: secboot enabling check failed |
| 312 | * Bit 1: Sec HW key is not programmed |
| 313 | * Bit 2: debug disable check failed |
| 314 | * Bit 3: Anti-rollback check failed |
| 315 | * Bit 4: fuse config check failed |
| 316 | * Bit 5: rpmb fuse check failed |
| 317 | * @state_high[out] : highr 32 bits of the state. |
| 318 | * |
| 319 | * Returns 0 on success, negative on failure. |
| 320 | */ |
| 321 | int scm_svc_get_secure_state(uint32_t *state_low, uint32_t *state_high); |
| 322 | |
sundarajan srinivasan | 4dfd4f7 | 2013-02-27 14:13:09 -0800 | [diff] [blame] | 323 | int scm_protect_keystore(uint32_t * img_ptr, uint32_t img_len); |
Dinesh K Garg | 6bbbb70 | 2015-01-30 11:13:31 -0800 | [diff] [blame] | 324 | int |
| 325 | scm_call(uint32_t svc_id, uint32_t cmd_id, const void *cmd_buf, |
| 326 | size_t cmd_len, void *resp_buf, size_t resp_len); |
| 327 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 328 | |
Deepa Dinamani | 193874e | 2012-02-07 14:00:04 -0800 | [diff] [blame] | 329 | #define SCM_SVC_FUSE 0x08 |
| 330 | #define SCM_BLOW_SW_FUSE_ID 0x01 |
| 331 | #define SCM_IS_SW_FUSE_BLOWN_ID 0x02 |
Amit Blay | bdfabc6 | 2015-01-29 22:04:13 +0200 | [diff] [blame] | 332 | #define SCM_QFPROM_READ_ROW_ID 0x05 |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 333 | |
Deepa Dinamani | 193874e | 2012-02-07 14:00:04 -0800 | [diff] [blame] | 334 | #define HLOS_IMG_TAMPER_FUSE 0 |
Monika Singh | 9825746 | 2018-06-06 11:28:49 +0530 | [diff] [blame^] | 335 | #define WINSECAPP_LOADED_FUSE 1 /**< Used by the WinSec application to prevent reloading. */ |
| 336 | #define UEFISECAPP_LOADED_FUSE 2 /**< Used by UefiSecApp to prevent |
| 337 | reloading. */ |
| 338 | #define OEM_FUSE_1 3 /**< Reserved fuse bit for OEMs. */ |
| 339 | #define OEM_FUSE_2 4 /**< Reserved fuse bit for OEMs. */ |
| 340 | #define OEM_FUSE_3 5 /**< Reserved fuse bit for OEMs. */ |
| 341 | #define OEM_FUSE_4 6 /**< Reserved fuse bit for OEMs. */ |
| 342 | #define OEM_FUSE_5 7 /**< Reserved fuse bit for OEMs. */ |
| 343 | #define OEM_FUSE_6 8 /**< Reserved fuse bit for OEMs. */ |
| 344 | #define OEM_FUSE_7 9 /**< Reserved fuse bit for OEMs. */ |
| 345 | #define OEM_FUSE_8 10 /**< Reserved fuse bit for OEMs. */ |
| 346 | #define HLOS_BL_MILESTONE_FUSE 11 /**< Used to notify the bootloader milestone call.*/ |
| 347 | #define HLOS_TAMPER_NOTIFY_FUSE 12 /**< Used to notify TZ that HLOS has been tampered.*/ |
| 348 | #define NUM_SW_FUSES 13 /**< Number of supported software fuses. |
| 349 | @newpage */ |
Deepa Dinamani | 193874e | 2012-02-07 14:00:04 -0800 | [diff] [blame] | 350 | |
| 351 | #define SCM_SVC_CE_CHN_SWITCH_ID 0x04 |
| 352 | #define SCM_CE_CHN_SWITCH_ID 0x02 |
| 353 | |
Amir Samuelov | 4620ad2 | 2013-03-13 11:30:05 +0200 | [diff] [blame] | 354 | #define SCM_SVC_ES 0x10 |
| 355 | #define SCM_SAVE_PARTITION_HASH_ID 0x01 |
| 356 | |
Amit Blay | fe23ee2 | 2015-01-09 19:09:51 +0200 | [diff] [blame] | 357 | #define SCM_SVC_MDTP 0x12 |
| 358 | #define SCM_MDTP_CIPHER_DIP 0x01 |
| 359 | |
Channagoud Kadabi | 179df0b | 2013-12-12 14:53:31 -0800 | [diff] [blame] | 360 | #define SCM_SVC_PWR 0x9 |
| 361 | #define SCM_IO_DISABLE_PMIC_ARBITER 0x1 |
Aparna Mallavarapu | 664ea77 | 2015-02-24 18:44:33 +0530 | [diff] [blame] | 362 | #define SCM_IO_DISABLE_PMIC_ARBITER1 0x2 |
Channagoud Kadabi | 179df0b | 2013-12-12 14:53:31 -0800 | [diff] [blame] | 363 | |
Abhimanyu Kapur | b3207fb | 2014-01-27 21:33:23 -0800 | [diff] [blame] | 364 | #define SCM_SVC_MILESTONE_32_64_ID 0x1 |
| 365 | #define SCM_SVC_MILESTONE_CMD_ID 0xf |
Dinesh K Garg | 6bbbb70 | 2015-01-30 11:13:31 -0800 | [diff] [blame] | 366 | #define SCM_SVC_TZSCHEDULER 0xFC |
Abhimanyu Kapur | b3207fb | 2014-01-27 21:33:23 -0800 | [diff] [blame] | 367 | |
Deepa Dinamani | 193874e | 2012-02-07 14:00:04 -0800 | [diff] [blame] | 368 | enum ap_ce_channel_type { |
| 369 | AP_CE_REGISTER_USE = 0, |
| 370 | AP_CE_ADM_USE = 1 |
| 371 | }; |
| 372 | |
| 373 | /* Apps CE resource. */ |
| 374 | #define TZ_RESOURCE_CE_AP 2 |
| 375 | |
Aparna Mallavarapu | 246c30b | 2014-12-11 12:07:51 +0530 | [diff] [blame] | 376 | /* Secure IO Service IDs */ |
| 377 | #define SCM_IO_READ 0x1 |
| 378 | #define SCM_IO_WRITE 0x2 |
| 379 | #define SCM_SVC_IO 0x5 |
| 380 | |
Deepa Dinamani | 193874e | 2012-02-07 14:00:04 -0800 | [diff] [blame] | 381 | uint8_t switch_ce_chn_cmd(enum ap_ce_channel_type channel); |
| 382 | |
Amit Blay | fe23ee2 | 2015-01-09 19:09:51 +0200 | [diff] [blame] | 383 | /** |
| 384 | * Encrypt or Decrypt a Data Integrity Partition (DIP) structure using a |
| 385 | * HW derived key. The DIP is used for storing integrity information for |
| 386 | * Mobile Device Theft Protection (MDTP) service. |
| 387 | * |
| 388 | * @in_buf[in] : Pointer to plain text buffer. |
| 389 | * @in_buf_size[in] : Plain text buffer size. |
| 390 | * @out_buf[in] : Pointer to encrypted buffer. |
| 391 | * @out_buf_size[in] : Encrypted buffer size. |
| 392 | * @direction[in] : 0 for ENCRYPTION, 1 for DECRYPTION. |
| 393 | * |
| 394 | * Returns 0 on success, negative on failure. |
| 395 | */ |
| 396 | int mdtp_cipher_dip_cmd(uint8_t *in_buf, uint32_t in_buf_size, uint8_t *out_buf, |
| 397 | uint32_t out_buf_size, uint32_t direction); |
Deepa Dinamani | 193874e | 2012-02-07 14:00:04 -0800 | [diff] [blame] | 398 | |
Monika Singh | 9825746 | 2018-06-06 11:28:49 +0530 | [diff] [blame^] | 399 | uint32_t set_tamper_fuse_cmd(uint32_t fuse_id); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 400 | |
Amit Blay | bdfabc6 | 2015-01-29 22:04:13 +0200 | [diff] [blame] | 401 | /** |
| 402 | * Reads the row data of the specified QFPROM row address. |
| 403 | * |
| 404 | * @row_address[in] : Row address in the QFPROM region to read. |
| 405 | * @addr_type[in] : Raw or corrected address. |
| 406 | * @row_data[in] : Pointer to the data to be read. |
| 407 | * @qfprom_api_status[out] : Status of the read operation. |
| 408 | * |
| 409 | * Returns Any errors while reading data from the specified |
| 410 | * Returns 0 on success, negative on failure. |
| 411 | */ |
| 412 | int qfprom_read_row_cmd(uint32_t row_address, uint32_t addr_type, uint32_t *row_data, uint32_t *qfprom_api_status); |
| 413 | |
Channagoud Kadabi | 179df0b | 2013-12-12 14:53:31 -0800 | [diff] [blame] | 414 | int scm_halt_pmic_arbiter(); |
Aparna Mallavarapu | 68e233f | 2014-03-21 19:18:34 +0530 | [diff] [blame] | 415 | int scm_call_atomic2(uint32_t svc, uint32_t cmd, uint32_t arg1, uint32_t arg2); |
vijay kumar | 4f4405f | 2014-08-08 11:49:53 +0530 | [diff] [blame] | 416 | int restore_secure_cfg(uint32_t id); |
Channagoud Kadabi | 179df0b | 2013-12-12 14:53:31 -0800 | [diff] [blame] | 417 | |
Abhimanyu Kapur | b3207fb | 2014-01-27 21:33:23 -0800 | [diff] [blame] | 418 | void scm_elexec_call(paddr_t kernel_entry, paddr_t dtb_offset); |
lijuang | c76a763 | 2017-12-07 14:37:56 +0800 | [diff] [blame] | 419 | int scm_random(uintptr_t * rbuf, uint32_t r_len); |
Channagoud Kadabi | efdeb8a | 2015-09-23 11:52:20 -0700 | [diff] [blame] | 420 | uintptr_t get_canary(); |
Aparna Mallavarapu | 6875ade | 2014-06-16 22:15:28 +0530 | [diff] [blame] | 421 | /* API to configure XPU violations as fatal */ |
| 422 | int scm_xpu_err_fatal_init(); |
Abhimanyu Kapur | b3207fb | 2014-01-27 21:33:23 -0800 | [diff] [blame] | 423 | |
Channagoud Kadabi | dd85e7f | 2014-08-05 19:58:37 -0700 | [diff] [blame] | 424 | /* APIs to support ARM scm standard |
| 425 | * Takes arguments : x0-x5 and returns result |
| 426 | * in x0-x3*/ |
| 427 | uint32_t scm_call2(scmcall_arg *arg, scmcall_ret *ret); |
| 428 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 429 | /** |
| 430 | * struct scm_command - one SCM command buffer |
| 431 | * @len: total available memory for command and response |
| 432 | * @buf_offset: start of command buffer |
| 433 | * @resp_hdr_offset: start of response buffer |
| 434 | * @id: command to be executed |
| 435 | * @buf: buffer returned from scm_get_command_buffer() |
| 436 | * |
| 437 | * An SCM command is layed out in memory as follows: |
| 438 | * |
| 439 | * ------------------- <--- struct scm_command |
| 440 | * | command header | |
| 441 | * ------------------- <--- scm_get_command_buffer() |
| 442 | * | command buffer | |
| 443 | * ------------------- <--- struct scm_response and |
| 444 | * | response header | scm_command_to_response() |
| 445 | * ------------------- <--- scm_get_response_buffer() |
| 446 | * | response buffer | |
| 447 | * ------------------- |
| 448 | * |
| 449 | * There can be arbitrary padding between the headers and buffers so |
| 450 | * you should always use the appropriate scm_get_*_buffer() routines |
| 451 | * to access the buffers in a safe manner. |
| 452 | */ |
| 453 | struct scm_command { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 454 | uint32_t len; |
| 455 | uint32_t buf_offset; |
| 456 | uint32_t resp_hdr_offset; |
| 457 | uint32_t id; |
| 458 | uint32_t buf[0]; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 459 | }; |
| 460 | |
| 461 | /** |
| 462 | * struct scm_response - one SCM response buffer |
| 463 | * @len: total available memory for response |
| 464 | * @buf_offset: start of response data relative to start of scm_response |
| 465 | * @is_complete: indicates if the command has finished processing |
| 466 | */ |
| 467 | struct scm_response { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 468 | uint32_t len; |
| 469 | uint32_t buf_offset; |
| 470 | uint32_t is_complete; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 471 | }; |
Channagoud Kadabi | dd85e7f | 2014-08-05 19:58:37 -0700 | [diff] [blame] | 472 | /* Perform any scm init needed before making scm calls |
| 473 | * Used for checking if armv8 SCM support present |
| 474 | */ |
| 475 | void scm_init(); |
Aparna Mallavarapu | 246c30b | 2014-12-11 12:07:51 +0530 | [diff] [blame] | 476 | bool is_secure_boot_enable(); |
Dinesh K Garg | 6bbbb70 | 2015-01-30 11:13:31 -0800 | [diff] [blame] | 477 | |
| 478 | /* Is armv8 supported */ |
| 479 | bool is_scm_armv8_support(); |
Channagoud Kadabi | b2e080f | 2015-03-27 18:29:10 -0700 | [diff] [blame] | 480 | |
lijuang | 395b5e6 | 2015-11-19 17:39:44 +0800 | [diff] [blame] | 481 | int scm_dload_mode(enum reboot_reason mode); |
Channagoud Kadabi | 6479ce3 | 2015-06-17 17:30:40 -0700 | [diff] [blame] | 482 | int scm_device_enter_dload(); |
Aparna Mallavarapu | da91ea9 | 2015-07-10 12:03:46 +0530 | [diff] [blame] | 483 | int scm_call2_atomic(uint32_t svc, uint32_t cmd, uint32_t arg1, uint32_t arg2); |
| 484 | uint32_t scm_io_write(uint32_t address, uint32_t val); |
Channagoud Kadabi | 77f46a3 | 2015-08-05 16:13:13 -0700 | [diff] [blame] | 485 | int is_scm_call_available(uint32_t svc_id, uint32_t cmd_id); |
lijuang | 1cff838 | 2016-01-11 17:56:54 +0800 | [diff] [blame] | 486 | int scm_disable_sdi(); |
Monika Singh | 9825746 | 2018-06-06 11:28:49 +0530 | [diff] [blame^] | 487 | bool allow_set_fuse(uint32_t version); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 488 | #endif |