blob: 26e203ec20ef42c83e5b4d6bda68c5a9347948d7 [file] [log] [blame]
Siddhartha Agrawaleb094c52013-01-28 12:11:43 -08001/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Deepa Dinamani904f8f82012-12-05 16:35:01 -08002 *
Shashank Mittal162244e2011-08-08 19:01:25 -07003 * Redistribution and use in source and binary forms, with or without
4 * modification, are permitted provided that the following conditions are
5 * met:
Deepa Dinamani904f8f82012-12-05 16:35:01 -08006 * * 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.
12 * * Neither the name of The Linux Foundation nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
Shashank Mittal162244e2011-08-08 19:01:25 -070015 *
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#include <stdlib.h>
30#include <string.h>
31#include <err.h>
Neeti Desai127b9e02012-03-20 16:11:23 -070032#include <arch/ops.h>
Shashank Mittal162244e2011-08-08 19:01:25 -070033#include "scm.h"
34
35#pragma GCC optimize ("O0")
36
37/* From Linux Kernel asm/system.h */
38#define __asmeq(x, y) ".ifnc " x "," y " ; .err ; .endif\n\t"
39
40#ifndef offsetof
41# define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
42#endif
43
44/**
45 * alloc_scm_command() - Allocate an SCM command
46 * @cmd_size: size of the command buffer
47 * @resp_size: size of the response buffer
48 *
49 * Allocate an SCM command, including enough room for the command
50 * and response headers as well as the command and response buffers.
51 *
52 * Returns a valid &scm_command on success or %NULL if the allocation fails.
53 */
54static struct scm_command *alloc_scm_command(size_t cmd_size, size_t resp_size)
55{
56 struct scm_command *cmd;
57 size_t len = sizeof(*cmd) + sizeof(struct scm_response) + cmd_size +
Ajay Dudanib01e5062011-12-03 23:23:42 -080058 resp_size;
Shashank Mittal162244e2011-08-08 19:01:25 -070059
Deepa Dinamani904f8f82012-12-05 16:35:01 -080060 cmd = memalign(CACHE_LINE, ROUNDUP(len, CACHE_LINE));
Ajay Dudanib01e5062011-12-03 23:23:42 -080061 if (cmd) {
Shashank Mittal162244e2011-08-08 19:01:25 -070062 cmd->len = len;
63 cmd->buf_offset = offsetof(struct scm_command, buf);
64 cmd->resp_hdr_offset = cmd->buf_offset + cmd_size;
65 }
66 return cmd;
67}
68
69/**
70 * free_scm_command() - Free an SCM command
71 * @cmd: command to free
72 *
73 * Free an SCM command.
74 */
75static inline void free_scm_command(struct scm_command *cmd)
76{
77 free(cmd);
78}
79
80/**
81 * scm_command_to_response() - Get a pointer to a scm_response
82 * @cmd: command
83 *
84 * Returns a pointer to a response for a command.
85 */
Ajay Dudanib01e5062011-12-03 23:23:42 -080086static inline struct scm_response *scm_command_to_response(const struct
87 scm_command *cmd)
Shashank Mittal162244e2011-08-08 19:01:25 -070088{
89 return (void *)cmd + cmd->resp_hdr_offset;
90}
91
92/**
93 * scm_get_command_buffer() - Get a pointer to a command buffer
94 * @cmd: command
95 *
96 * Returns a pointer to the command buffer of a command.
97 */
98static inline void *scm_get_command_buffer(const struct scm_command *cmd)
99{
100 return (void *)cmd->buf;
101}
102
103/**
104 * scm_get_response_buffer() - Get a pointer to a response buffer
105 * @rsp: response
106 *
107 * Returns a pointer to a response buffer of a response.
108 */
109static inline void *scm_get_response_buffer(const struct scm_response *rsp)
110{
111 return (void *)rsp + rsp->buf_offset;
112}
113
114static uint32_t smc(uint32_t cmd_addr)
115{
116 uint32_t context_id;
117 register uint32_t r0 __asm__("r0") = 1;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800118 register uint32_t r1 __asm__("r1") = (uint32_t) & context_id;
Shashank Mittal162244e2011-08-08 19:01:25 -0700119 register uint32_t r2 __asm__("r2") = cmd_addr;
Ajay Dudanib01e5062011-12-03 23:23:42 -0800120 __asm__("1:smc #0 @ switch to secure world\n" "cmp r0, #1 \n" "beq 1b \n": "=r"(r0): "r"(r0), "r"(r1), "r"(r2):"r3", "cc");
Shashank Mittal162244e2011-08-08 19:01:25 -0700121 return r0;
122}
123
124/**
125 * scm_call() - Send an SCM command
126 * @svc_id: service identifier
127 * @cmd_id: command identifier
128 * @cmd_buf: command buffer
129 * @cmd_len: length of the command buffer
130 * @resp_buf: response buffer
131 * @resp_len: length of the response buffer
132 *
133 * Sends a command to the SCM and waits for the command to finish processing.
134 */
Ajay Dudanib01e5062011-12-03 23:23:42 -0800135int
136scm_call(uint32_t svc_id, uint32_t cmd_id, const void *cmd_buf,
137 size_t cmd_len, void *resp_buf, size_t resp_len)
Shashank Mittal162244e2011-08-08 19:01:25 -0700138{
139 int ret;
140 struct scm_command *cmd;
141 struct scm_response *rsp;
Neeti Desai127b9e02012-03-20 16:11:23 -0700142 uint8_t *resp_ptr;
Shashank Mittal162244e2011-08-08 19:01:25 -0700143
144 cmd = alloc_scm_command(cmd_len, resp_len);
145 if (!cmd)
146 return ERR_NO_MEMORY;
147
148 cmd->id = (svc_id << 10) | cmd_id;
149 if (cmd_buf)
150 memcpy(scm_get_command_buffer(cmd), cmd_buf, cmd_len);
151
Neeti Desai127b9e02012-03-20 16:11:23 -0700152 /* Flush command to main memory for TZ */
153 arch_clean_invalidate_cache_range((addr_t) cmd, cmd->len);
154
Ajay Dudanib01e5062011-12-03 23:23:42 -0800155 ret = smc((uint32_t) cmd);
Shashank Mittal162244e2011-08-08 19:01:25 -0700156 if (ret)
157 goto out;
158
Ajay Dudanib01e5062011-12-03 23:23:42 -0800159 if (resp_len) {
Shashank Mittal162244e2011-08-08 19:01:25 -0700160 rsp = scm_command_to_response(cmd);
161
Neeti Desai127b9e02012-03-20 16:11:23 -0700162 do
163 {
164 /* Need to invalidate before each check since TZ will update
165 * the response complete flag in main memory.
166 */
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800167 arch_invalidate_cache_range((addr_t) rsp, sizeof(*rsp));
Neeti Desai127b9e02012-03-20 16:11:23 -0700168 } while (!rsp->is_complete);
169
170
171 resp_ptr = scm_get_response_buffer(rsp);
172
173 /* Invalidate any cached response data */
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800174 arch_invalidate_cache_range((addr_t) resp_ptr, resp_len);
Shashank Mittal162244e2011-08-08 19:01:25 -0700175
176 if (resp_buf)
Neeti Desai127b9e02012-03-20 16:11:23 -0700177 memcpy(resp_buf, resp_ptr, resp_len);
Shashank Mittal162244e2011-08-08 19:01:25 -0700178 }
Ajay Dudanib01e5062011-12-03 23:23:42 -0800179 out:
Shashank Mittal162244e2011-08-08 19:01:25 -0700180 free_scm_command(cmd);
181 return ret;
182}
183
Siddhartha Agrawaleb094c52013-01-28 12:11:43 -0800184int restore_secure_cfg(uint32_t id)
185{
186 int ret, scm_ret = 0;
187 tz_secure_cfg secure_cfg;
188
Siddhartha Agrawald4648892013-02-17 18:16:18 -0800189 secure_cfg.id = id;
Siddhartha Agrawaleb094c52013-01-28 12:11:43 -0800190 secure_cfg.spare = 0;
191
sundarajan srinivasanc2dee742013-02-21 11:31:36 -0800192 ret = scm_call(SVC_MEMORY_PROTECTION, IOMMU_SECURE_CFG, &secure_cfg, sizeof(secure_cfg),
Siddhartha Agrawaleb094c52013-01-28 12:11:43 -0800193 &scm_ret, sizeof(scm_ret));
194
195 if (ret || scm_ret) {
196 dprintf(CRITICAL, "Secure Config failed\n");
197 ret = 1;
198 } else
199 ret = 0;
200
201 return ret;
202
203}
204
Neeti Desai127b9e02012-03-20 16:11:23 -0700205/* SCM Encrypt Command */
206int encrypt_scm(uint32_t ** img_ptr, uint32_t * img_len_ptr)
Shashank Mittal162244e2011-08-08 19:01:25 -0700207{
Neeti Desai127b9e02012-03-20 16:11:23 -0700208 int ret;
209 img_req cmd;
Shashank Mittal162244e2011-08-08 19:01:25 -0700210
Neeti Desai127b9e02012-03-20 16:11:23 -0700211 cmd.img_ptr = (uint32*) img_ptr;
212 cmd.img_len_ptr = img_len_ptr;
Shashank Mittal162244e2011-08-08 19:01:25 -0700213
Neeti Desai127b9e02012-03-20 16:11:23 -0700214 /* Image data is operated upon by TZ, which accesses only the main memory.
215 * It must be flushed/invalidated before and after TZ call.
216 */
217 arch_clean_invalidate_cache_range((addr_t) *img_ptr, *img_len_ptr);
Shashank Mittal162244e2011-08-08 19:01:25 -0700218
Neeti Desai127b9e02012-03-20 16:11:23 -0700219 ret = scm_call(SCM_SVC_SSD, SSD_ENCRYPT_ID, &cmd, sizeof(cmd), NULL, 0);
Shashank Mittal162244e2011-08-08 19:01:25 -0700220
Neeti Desai127b9e02012-03-20 16:11:23 -0700221 /* Values at img_ptr and img_len_ptr are updated by TZ. Must be invalidated
222 * before we use them.
Amol Jadi55e58da2011-11-17 14:03:34 -0800223 */
224 arch_clean_invalidate_cache_range((addr_t) img_ptr, sizeof(img_ptr));
Neeti Desai127b9e02012-03-20 16:11:23 -0700225 arch_clean_invalidate_cache_range((addr_t) img_len_ptr, sizeof(img_len_ptr));
Amol Jadi55e58da2011-11-17 14:03:34 -0800226
Neeti Desai127b9e02012-03-20 16:11:23 -0700227 /* Invalidate the updated image data */
228 arch_clean_invalidate_cache_range((addr_t) *img_ptr, *img_len_ptr);
Amol Jadi55e58da2011-11-17 14:03:34 -0800229
Shashank Mittal162244e2011-08-08 19:01:25 -0700230 return ret;
231}
232
Neeti Desai127b9e02012-03-20 16:11:23 -0700233/* SCM Decrypt Command */
234int decrypt_scm(uint32_t ** img_ptr, uint32_t * img_len_ptr)
235{
236 int ret;
237 img_req cmd;
238
239 cmd.img_ptr = (uint32*) img_ptr;
240 cmd.img_len_ptr = img_len_ptr;
241
242 /* Image data is operated upon by TZ, which accesses only the main memory.
243 * It must be flushed/invalidated before and after TZ call.
244 */
245 arch_clean_invalidate_cache_range((addr_t) *img_ptr, *img_len_ptr);
246
247 ret = scm_call(SCM_SVC_SSD, SSD_DECRYPT_ID, &cmd, sizeof(cmd), NULL, 0);
248
249 /* Values at img_ptr and img_len_ptr are updated by TZ. Must be invalidated
250 * before we use them.
251 */
252 arch_clean_invalidate_cache_range((addr_t) img_ptr, sizeof(img_ptr));
253 arch_clean_invalidate_cache_range((addr_t) img_len_ptr, sizeof(img_len_ptr));
254
255 /* Invalidate the updated image data */
256 arch_clean_invalidate_cache_range((addr_t) *img_ptr, *img_len_ptr);
257
258 return ret;
259}
260
261
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800262static int ssd_image_is_encrypted(uint32_t ** img_ptr, uint32_t * img_len_ptr, uint32 * ctx_id)
263{
sundarajan srinivasan6173b872013-03-13 17:36:48 -0700264 int ret = 0;
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800265 ssd_parse_md_req parse_req;
266 ssd_parse_md_rsp parse_rsp;
sundarajan srinivasan6173b872013-03-13 17:36:48 -0700267 int prev_len = 0;
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800268
sundarajan srinivasan6173b872013-03-13 17:36:48 -0700269 /* Populate meta-data ptr. Here md_len is the meta-data length.
270 * The Code below follows a growing length approach. First send
271 * min(img_len_ptr,SSD_HEADER_MIN_SIZE) say 128 bytes for example.
272 * If parse_rsp.status = PARSING_INCOMPLETE we send md_len = 256.
273 * If subsequent status = PARSING_INCOMPLETE we send md_len = 512,
274 * 1024bytes and so on until we get an valid response(rsp.status) from TZ*/
275
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800276 parse_req.md = (uint32*)*img_ptr;
sundarajan srinivasan6173b872013-03-13 17:36:48 -0700277 parse_req.md_len = ((*img_len_ptr) >= SSD_HEADER_MIN_SIZE) ? SSD_HEADER_MIN_SIZE : (*img_len_ptr);
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800278
sundarajan srinivasan6173b872013-03-13 17:36:48 -0700279 arch_clean_invalidate_cache_range((addr_t) *img_ptr, parse_req.md_len);
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800280
sundarajan srinivasan6173b872013-03-13 17:36:48 -0700281 do
282 {
283 ret = scm_call(SCM_SVC_SSD,
284 SSD_PARSE_MD_ID,
285 &parse_req,
286 sizeof(parse_req),
287 &parse_rsp,
288 sizeof(parse_rsp));
289
290 if(!ret && (parse_rsp.status == SSD_PMD_PARSING_INCOMPLETE))
291 {
292 prev_len = parse_req.md_len;
293
294 parse_req.md_len *= MULTIPLICATION_FACTOR;
295
296 arch_clean_invalidate_cache_range((addr_t) *(img_ptr + prev_len),
297 (parse_req.md_len - prev_len) );
298
299 continue;
300 }
301 else
302 break;
303
304 } while(true);
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800305
306 if(!ret)
307 {
308 if(parse_rsp.status == SSD_PMD_ENCRYPTED)
309 {
310 *ctx_id = parse_rsp.md_ctx_id;
Sundarajan Srinivasaneb6d2202013-06-04 14:24:10 -0700311 *img_len_ptr = *img_len_ptr - ((uint8_t*)parse_rsp.md_end_ptr - (uint8_t*)*img_ptr);
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800312 *img_ptr = (uint32_t*)parse_rsp.md_end_ptr;
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800313 }
Sundarajan Srinivasaneb6d2202013-06-04 14:24:10 -0700314
315 ret = parse_rsp.status;
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800316 }
sundarajan srinivasan6173b872013-03-13 17:36:48 -0700317 else
318 {
319 dprintf(CRITICAL,"ssd_image_is_encrypted call failed");
320
321 ASSERT(ret == 0);
322 }
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800323
324 return ret;
325}
326
327int decrypt_scm_v2(uint32_t ** img_ptr, uint32_t * img_len_ptr)
328{
329 int ret = 0;
330 uint32 ctx_id = 0;
331 ssd_decrypt_img_frag_req decrypt_req;
332 ssd_decrypt_img_frag_rsp decrypt_rsp;
333
Sundarajan Srinivasaneb6d2202013-06-04 14:24:10 -0700334 ret = ssd_image_is_encrypted(img_ptr,img_len_ptr,&ctx_id);
335 switch(ret)
sundarajan srinivasan6173b872013-03-13 17:36:48 -0700336 {
Sundarajan Srinivasaneb6d2202013-06-04 14:24:10 -0700337 case SSD_PMD_ENCRYPTED:
338 /* Image data is operated upon by TZ, which accesses only the main memory.
339 * It must be flushed/invalidated before and after TZ call.
340 */
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800341
Sundarajan Srinivasaneb6d2202013-06-04 14:24:10 -0700342 arch_clean_invalidate_cache_range((addr_t) *img_ptr, *img_len_ptr);
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800343
Sundarajan Srinivasaneb6d2202013-06-04 14:24:10 -0700344 /*decrypt the image here*/
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800345
Sundarajan Srinivasaneb6d2202013-06-04 14:24:10 -0700346 decrypt_req.md_ctx_id = ctx_id;
347 decrypt_req.last_frag = 1;
348 decrypt_req.frag_len = *img_len_ptr;
349 decrypt_req.frag = *img_ptr;
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800350
Sundarajan Srinivasaneb6d2202013-06-04 14:24:10 -0700351 ret = scm_call(SCM_SVC_SSD,
352 SSD_DECRYPT_IMG_FRAG_ID,
353 &decrypt_req,
354 sizeof(decrypt_req),
355 &decrypt_rsp,
356 sizeof(decrypt_rsp));
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800357
Sundarajan Srinivasaneb6d2202013-06-04 14:24:10 -0700358 if(!ret){
359 ret = decrypt_rsp.status;
360 }
sundarajan srinivasan6173b872013-03-13 17:36:48 -0700361
Sundarajan Srinivasaneb6d2202013-06-04 14:24:10 -0700362 /* Values at img_ptr and img_len_ptr are updated by TZ. Must be invalidated
363 * before we use them.
364 */
365 arch_invalidate_cache_range((addr_t) img_ptr, sizeof(img_ptr));
366 arch_invalidate_cache_range((addr_t) img_len_ptr, sizeof(img_len_ptr));
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800367
Sundarajan Srinivasaneb6d2202013-06-04 14:24:10 -0700368 /* Invalidate the updated image data */
369 arch_invalidate_cache_range((addr_t) *img_ptr, *img_len_ptr);
sundarajan srinivasan6173b872013-03-13 17:36:48 -0700370
Sundarajan Srinivasaneb6d2202013-06-04 14:24:10 -0700371 break;
372
373 case SSD_PMD_NOT_ENCRYPTED:
374 case SSD_PMD_NO_MD_FOUND:
375 ret = 0;
376 break;
377
378 case SSD_PMD_BUSY:
379 case SSD_PMD_BAD_MD_PTR_OR_LEN:
380 case SSD_PMD_PARSING_INCOMPLETE:
381 case SSD_PMD_PARSING_FAILED:
382 case SSD_PMD_SETUP_CIPHER_FAILED:
383 dprintf(CRITICAL,"decrypt_scm_v2: failed status %d\n",ret);
384 break;
385
386 default:
387 dprintf(CRITICAL,"decrypt_scm_v2: case default: failed status %d\n",ret);
388 break;
sundarajan srinivasan6173b872013-03-13 17:36:48 -0700389 }
sundarajan srinivasan4dfd4f72013-02-27 14:13:09 -0800390 return ret;
391}
392
393int scm_svc_version(uint32 * major, uint32 * minor)
394{
395 feature_version_req feature_req;
396 feature_version_rsp feature_rsp;
397 int ret = 0;
398
399 feature_req.feature_id = TZBSP_FVER_SSD;
400
401 ret = scm_call(TZBSP_SVC_INFO,
402 TZ_INFO_GET_FEATURE_ID,
403 &feature_req,
404 sizeof(feature_req),
405 &feature_rsp,
406 sizeof(feature_rsp));
407 if(!ret)
408 *major = TZBSP_GET_FEATURE_VERSION(feature_rsp.version);
409
410 return ret;
411}
412
413int scm_protect_keystore(uint32_t * img_ptr, uint32_t img_len)
414{
415 int ret=0;
416 ssd_protect_keystore_req protect_req;
417 ssd_protect_keystore_rsp protect_rsp;
418
419 protect_req.keystore_ptr = img_ptr;
420 protect_req.keystore_len = img_len;
421
422 arch_clean_invalidate_cache_range((addr_t) img_ptr, img_len);
423
424 ret = scm_call(SCM_SVC_SSD,
425 SSD_PROTECT_KEYSTORE_ID,
426 &protect_req,
427 sizeof(protect_req),
428 &protect_rsp,
429 sizeof(protect_rsp));
430 if(!ret)
431 {
432 if(protect_rsp.status == TZBSP_SSD_PKS_SUCCESS)
433 dprintf(INFO,"Successfully loaded the keystore ");
434 else
435 {
436 dprintf(INFO,"Loading keystore failed status %d ",protect_rsp.status);
437 ret = protect_rsp.status;
438 }
439 }
440 else
441 dprintf(INFO,"scm_call failed ");
442
443 return ret;
444}
445
Shashank Mittal162244e2011-08-08 19:01:25 -0700446void set_tamper_fuse_cmd()
447{
448 uint32_t svc_id;
449 uint32_t cmd_id;
450 void *cmd_buf;
451 size_t cmd_len;
452 void *resp_buf = NULL;
453 size_t resp_len = 0;
454
455 uint32_t fuse_id = HLOS_IMG_TAMPER_FUSE;
456 cmd_buf = (void *)&fuse_id;
457 cmd_len = sizeof(fuse_id);
458
Ajay Dudanib01e5062011-12-03 23:23:42 -0800459 /*no response */
Shashank Mittal162244e2011-08-08 19:01:25 -0700460 resp_buf = NULL;
461 resp_len = 0;
462
463 svc_id = SCM_SVC_FUSE;
464 cmd_id = SCM_BLOW_SW_FUSE_ID;
465
466 scm_call(svc_id, cmd_id, cmd_buf, cmd_len, resp_buf, resp_len);
467 return;
468}
469
470uint8_t get_tamper_fuse_cmd()
471{
472 uint32_t svc_id;
473 uint32_t cmd_id;
474 void *cmd_buf;
475 size_t cmd_len;
476 size_t resp_len = 0;
477 uint8_t resp_buf;
478
479 uint32_t fuse_id = HLOS_IMG_TAMPER_FUSE;
480 cmd_buf = (void *)&fuse_id;
481 cmd_len = sizeof(fuse_id);
482
Ajay Dudanib01e5062011-12-03 23:23:42 -0800483 /*response */
Shashank Mittal162244e2011-08-08 19:01:25 -0700484 resp_len = sizeof(resp_buf);
485
486 svc_id = SCM_SVC_FUSE;
487 cmd_id = SCM_IS_SW_FUSE_BLOWN_ID;
488
489 scm_call(svc_id, cmd_id, cmd_buf, cmd_len, &resp_buf, resp_len);
490 return resp_buf;
491}
Deepa Dinamani193874e2012-02-07 14:00:04 -0800492
Amir Samuelov4620ad22013-03-13 11:30:05 +0200493#define SHA256_DIGEST_LENGTH (256/8)
494/*
495 * struct qseecom_save_partition_hash_req
496 * @partition_id - partition id.
497 * @digest[SHA256_DIGEST_LENGTH] - sha256 digest.
498 */
499struct qseecom_save_partition_hash_req {
500 uint32_t partition_id; /* in */
501 uint8_t digest[SHA256_DIGEST_LENGTH]; /* in */
502};
503
504
505void save_kernel_hash_cmd(void *digest)
506{
507 uint32_t svc_id;
508 uint32_t cmd_id;
509 void *cmd_buf;
510 size_t cmd_len;
511 void *resp_buf = NULL;
512 size_t resp_len = 0;
513 struct qseecom_save_partition_hash_req req;
514
515 /*no response */
516 resp_buf = NULL;
517 resp_len = 0;
518
519 req.partition_id = 0; /* kernel */
520 memcpy(req.digest, digest, sizeof(req.digest));
521
522 svc_id = SCM_SVC_ES;
523 cmd_id = SCM_SAVE_PARTITION_HASH_ID;
524 cmd_buf = (void *)&req;
525 cmd_len = sizeof(req);
526
527 scm_call(svc_id, cmd_id, cmd_buf, cmd_len, resp_buf, resp_len);
528}
529
Deepa Dinamani193874e2012-02-07 14:00:04 -0800530/*
531 * Switches the CE1 channel between ADM and register usage.
532 * channel : AP_CE_REGISTER_USE, CE1 uses register interface
533 * : AP_CE_ADM_USE, CE1 uses ADM interface
534 */
535uint8_t switch_ce_chn_cmd(enum ap_ce_channel_type channel)
536{
537 uint32_t svc_id;
538 uint32_t cmd_id;
539 void *cmd_buf;
540 size_t cmd_len;
541 size_t resp_len = 0;
542 uint8_t resp_buf;
543
544 struct {
545 uint32_t resource;
546 uint32_t chn_id;
547 }__PACKED switch_ce_chn_buf;
548
549 switch_ce_chn_buf.resource = TZ_RESOURCE_CE_AP;
550 switch_ce_chn_buf.chn_id = channel;
551 cmd_buf = (void *)&switch_ce_chn_buf;
552 cmd_len = sizeof(switch_ce_chn_buf);
553
554 /*response */
555 resp_len = sizeof(resp_buf);
556
557 svc_id = SCM_SVC_CE_CHN_SWITCH_ID;
558 cmd_id = SCM_CE_CHN_SWITCH_ID;
559
560 scm_call(svc_id, cmd_id, cmd_buf, cmd_len, &resp_buf, resp_len);
561 return resp_buf;
562}
563