blob: 6ca7d348b15e0419e9d9b2c6c949e0c5a8069098 [file] [log] [blame]
Siddhartha Agrawaleb094c52013-01-28 12:11:43 -08001/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Shashank Mittal162244e2011-08-08 19:01:25 -07002
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 Agrawaleb094c52013-01-28 12:11:43 -080012 * * Neither the name of The Linux Foundation nor the names of its
Shashank Mittal162244e2011-08-08 19:01:25 -070013 * 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 Desai127b9e02012-03-20 16:11:23 -070033#define DECRYPT_MAGIC_0 0x73737A74
34#define DECRYPT_MAGIC_1 0x676D6964
35#define ENCRYPT_MAGIC_0 0x6B647373
36#define ENCRYPT_MAGIC_1 0x676D6973
Shashank Mittal162244e2011-08-08 19:01:25 -070037#define SSD_HEADER_MAGIC_SIZE 8
38#define SSD_HEADER_XML_SIZE 2048
sundarajan srinivasan6173b872013-03-13 17:36:48 -070039#define SSD_HEADER_MIN_SIZE 128
40#define MULTIPLICATION_FACTOR 2
Shashank Mittal162244e2011-08-08 19:01:25 -070041
42typedef unsigned int uint32;
43
Ajay Dudanib01e5062011-12-03 23:23:42 -080044typedef struct {
45 uint32 len;
46 uint32 buf_offset;
47 uint32 resp_hdr_offset;
48 uint32 id;
Shashank Mittal162244e2011-08-08 19:01:25 -070049} scm_command;
50
Ajay Dudanib01e5062011-12-03 23:23:42 -080051typedef struct {
52 uint32 len;
53 uint32 buf_offset;
54 uint32 is_complete;
Shashank Mittal162244e2011-08-08 19:01:25 -070055} scm_response;
56
Ajay Dudanib01e5062011-12-03 23:23:42 -080057typedef struct {
Ajay Dudanib01e5062011-12-03 23:23:42 -080058 uint32 *img_ptr;
59 uint32 *img_len_ptr;
Neeti Desai127b9e02012-03-20 16:11:23 -070060} img_req;
Shashank Mittal162244e2011-08-08 19:01:25 -070061
Siddhartha Agrawaleb094c52013-01-28 12:11:43 -080062typedef struct {
63 uint32 id;
64 uint32 spare;
65} tz_secure_cfg;
66
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -080067typedef struct {
68 uint32 md_len;
69 uint32* md;
70} ssd_parse_md_req;
71
72typedef struct {
73 uint32 status;
74 uint32 md_ctx_id;
75 uint32* md_end_ptr;
76} ssd_parse_md_rsp;
77
78typedef struct {
79 uint32 md_ctx_id;
80 uint32 last_frag;
81 uint32 frag_len;
82 uint32 *frag;
83} ssd_decrypt_img_frag_req;
84
85typedef struct {
86 uint32 status;
87} ssd_decrypt_img_frag_rsp;
88
89typedef struct{
90 uint32 feature_id;
91} feature_version_req;
92
93typedef struct{
94 uint32 version;
95} feature_version_rsp;
96
97typedef struct{
98 uint32 *keystore_ptr;
99 uint32 keystore_len;
100} ssd_protect_keystore_req;
101
102typedef struct{
103 uint32 status;
104} ssd_protect_keystore_rsp;
105
Maria Yud7826ef2014-06-30 13:05:43 +0800106struct tz_prng_data {
107 uint8_t *out_buf;
108 uint32_t out_buf_size;
109}__packed;
110
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800111/* Service IDs */
112#define TZBSP_SVC_INFO 0x06
113#define SCM_SVC_SSD 0x07
114#define SVC_MEMORY_PROTECTION 0x0C
Maria Yud7826ef2014-06-30 13:05:43 +0800115#define TZ_SVC_CRYPTO 0x0A
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800116
117/*Service specific command IDs */
Neeti Desai127b9e02012-03-20 16:11:23 -0700118#define SSD_DECRYPT_ID 0x01
119#define SSD_ENCRYPT_ID 0x02
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800120#define SSD_PROTECT_KEYSTORE_ID 0x05
121#define SSD_PARSE_MD_ID 0x06
122#define SSD_DECRYPT_IMG_FRAG_ID 0x07
Shashank Mittal162244e2011-08-08 19:01:25 -0700123
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800124
125#define SECURE_DEVICE_MDSS 0x01
126
Siddhartha Agrawaleb094c52013-01-28 12:11:43 -0800127#define IOMMU_SECURE_CFG 0x02
128
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800129#define TZ_INFO_GET_FEATURE_ID 0x03
Sridhar Parasuramd0443e22015-08-29 09:56:03 -0700130#define IS_SECURE_BOOT_ENABLED 0x04
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800131
Maria Yud7826ef2014-06-30 13:05:43 +0800132#define PRNG_CMD_ID 0x01
133
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800134/* SSD parsing status messages from TZ */
135#define SSD_PMD_ENCRYPTED 0
136#define SSD_PMD_NOT_ENCRYPTED 1
137#define SSD_PMD_NO_MD_FOUND 3
138#define SSD_PMD_BUSY 4
139#define SSD_PMD_BAD_MD_PTR_OR_LEN 5
140#define SSD_PMD_PARSING_INCOMPLETE 6
141#define SSD_PMD_PARSING_FAILED 7
142#define SSD_PMD_SETUP_CIPHER_FAILED 8
143
144/* Keystore status messages */
145#define TZBSP_SSD_PKS_SUCCESS 0 /**< Successful return. */
146#define TZBSP_SSD_PKS_INVALID_PTR 1 /**< Keystore pointer invalid. */
147#define TZBSP_SSD_PKS_INVALID_LEN 2 /**< Keystore length incorrect. */
148#define TZBSP_SSD_PKS_UNALIGNED_PTR 3 /**< Keystore pointer not word
149 aligned. */
150#define TZBSP_SSD_PKS_PROTECT_MEM_FAILED 4 /**< Failure when protecting
151 the keystore memory.*/
152#define TZBSP_SSD_PKS_INVALID_NUM_KEYS 5 /**< Unsupported number of
153 keys passed. If a valid
154 pointer to non-secure
155 memory is passed that
156 isn't a keystore, this is
157 a likely return code. */
158#define TZBSP_SSD_PKS_DECRYPT_FAILED 6 /**< The keystore could not be
159 decrypted. */
160
161/* Features in TZ */
162#define TZBSP_FVER_SSD 5
163
164#define TZBSP_GET_FEATURE_VERSION(major) ((major >> 22)& 0x3FF)
Siddhartha Agrawaleb094c52013-01-28 12:11:43 -0800165
Shashank Mittal162244e2011-08-08 19:01:25 -0700166static uint32 smc(uint32 cmd_addr);
Neeti Desai127b9e02012-03-20 16:11:23 -0700167int decrypt_scm(uint32_t ** img_ptr, uint32_t * img_len_ptr);
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800168int decrypt_scm_v2(uint32_t ** img_ptr, uint32_t * img_len_ptr);
Neeti Desai127b9e02012-03-20 16:11:23 -0700169int encrypt_scm(uint32_t ** img_ptr, uint32_t * img_len_ptr);
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800170int scm_svc_version(uint32 * major, uint32 * minor);
171int scm_protect_keystore(uint32_t * img_ptr, uint32_t img_len);
Shashank Mittal162244e2011-08-08 19:01:25 -0700172
Deepa Dinamani193874e2012-02-07 14:00:04 -0800173#define SCM_SVC_FUSE 0x08
174#define SCM_BLOW_SW_FUSE_ID 0x01
175#define SCM_IS_SW_FUSE_BLOWN_ID 0x02
Shashank Mittal162244e2011-08-08 19:01:25 -0700176
Deepa Dinamani193874e2012-02-07 14:00:04 -0800177#define HLOS_IMG_TAMPER_FUSE 0
178
179
180#define SCM_SVC_CE_CHN_SWITCH_ID 0x04
181#define SCM_CE_CHN_SWITCH_ID 0x02
182
Amir Samuelov4620ad22013-03-13 11:30:05 +0200183#define SCM_SVC_ES 0x10
184#define SCM_SAVE_PARTITION_HASH_ID 0x01
185
Channagoud Kadabi70375042013-12-12 14:53:31 -0800186#define SCM_SVC_PWR 0x9
187#define SCM_IO_DISABLE_PMIC_ARBITER 0x1
188
Sridhar Parasuramd0443e22015-08-29 09:56:03 -0700189#define SCM_SVC_TZSCHEDULER 0xFC
190
Deepa Dinamani193874e2012-02-07 14:00:04 -0800191enum ap_ce_channel_type {
192AP_CE_REGISTER_USE = 0,
193AP_CE_ADM_USE = 1
194};
195
196/* Apps CE resource. */
197#define TZ_RESOURCE_CE_AP 2
198
199uint8_t switch_ce_chn_cmd(enum ap_ce_channel_type channel);
200
201
Shashank Mittal162244e2011-08-08 19:01:25 -0700202void set_tamper_fuse_cmd();
203
Channagoud Kadabi70375042013-12-12 14:53:31 -0800204int scm_halt_pmic_arbiter();
205
Maria Yud7826ef2014-06-30 13:05:43 +0800206void *get_canary();
207
Shashank Mittal162244e2011-08-08 19:01:25 -0700208/**
209 * struct scm_command - one SCM command buffer
210 * @len: total available memory for command and response
211 * @buf_offset: start of command buffer
212 * @resp_hdr_offset: start of response buffer
213 * @id: command to be executed
214 * @buf: buffer returned from scm_get_command_buffer()
215 *
216 * An SCM command is layed out in memory as follows:
217 *
218 * ------------------- <--- struct scm_command
219 * | command header |
220 * ------------------- <--- scm_get_command_buffer()
221 * | command buffer |
222 * ------------------- <--- struct scm_response and
223 * | response header | scm_command_to_response()
224 * ------------------- <--- scm_get_response_buffer()
225 * | response buffer |
226 * -------------------
227 *
228 * There can be arbitrary padding between the headers and buffers so
229 * you should always use the appropriate scm_get_*_buffer() routines
230 * to access the buffers in a safe manner.
231 */
232struct scm_command {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800233 uint32_t len;
234 uint32_t buf_offset;
235 uint32_t resp_hdr_offset;
236 uint32_t id;
237 uint32_t buf[0];
Shashank Mittal162244e2011-08-08 19:01:25 -0700238};
239
240/**
241 * struct scm_response - one SCM response buffer
242 * @len: total available memory for response
243 * @buf_offset: start of response data relative to start of scm_response
244 * @is_complete: indicates if the command has finished processing
245 */
246struct scm_response {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800247 uint32_t len;
248 uint32_t buf_offset;
249 uint32_t is_complete;
Shashank Mittal162244e2011-08-08 19:01:25 -0700250};
251
Deepa Dinamani193874e2012-02-07 14:00:04 -0800252
253
Shashank Mittal162244e2011-08-08 19:01:25 -0700254#endif