blob: 418574b58c9cce1395ac296e383ef77acd9e5e47 [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
39
40typedef unsigned int uint32;
41
Ajay Dudanib01e5062011-12-03 23:23:42 -080042typedef struct {
43 uint32 len;
44 uint32 buf_offset;
45 uint32 resp_hdr_offset;
46 uint32 id;
Shashank Mittal162244e2011-08-08 19:01:25 -070047} scm_command;
48
Ajay Dudanib01e5062011-12-03 23:23:42 -080049typedef struct {
50 uint32 len;
51 uint32 buf_offset;
52 uint32 is_complete;
Shashank Mittal162244e2011-08-08 19:01:25 -070053} scm_response;
54
Ajay Dudanib01e5062011-12-03 23:23:42 -080055typedef struct {
Ajay Dudanib01e5062011-12-03 23:23:42 -080056 uint32 *img_ptr;
57 uint32 *img_len_ptr;
Neeti Desai127b9e02012-03-20 16:11:23 -070058} img_req;
Shashank Mittal162244e2011-08-08 19:01:25 -070059
Siddhartha Agrawaleb094c52013-01-28 12:11:43 -080060typedef struct {
61 uint32 id;
62 uint32 spare;
63} tz_secure_cfg;
64
Neeti Desai127b9e02012-03-20 16:11:23 -070065#define SCM_SVC_SSD 7
66#define SSD_DECRYPT_ID 0x01
67#define SSD_ENCRYPT_ID 0x02
Shashank Mittal162244e2011-08-08 19:01:25 -070068
Siddhartha Agrawaleb094c52013-01-28 12:11:43 -080069#define SCM_SVC_SSD 0x0C
70#define IOMMU_SECURE_CFG 0x02
71
72#define SECURE_DEVICE_MDSS 1
73
Shashank Mittal162244e2011-08-08 19:01:25 -070074static uint32 smc(uint32 cmd_addr);
Neeti Desai127b9e02012-03-20 16:11:23 -070075
76int decrypt_scm(uint32_t ** img_ptr, uint32_t * img_len_ptr);
77int encrypt_scm(uint32_t ** img_ptr, uint32_t * img_len_ptr);
Shashank Mittal162244e2011-08-08 19:01:25 -070078
Deepa Dinamani193874e2012-02-07 14:00:04 -080079#define SCM_SVC_FUSE 0x08
80#define SCM_BLOW_SW_FUSE_ID 0x01
81#define SCM_IS_SW_FUSE_BLOWN_ID 0x02
Shashank Mittal162244e2011-08-08 19:01:25 -070082
Deepa Dinamani193874e2012-02-07 14:00:04 -080083#define HLOS_IMG_TAMPER_FUSE 0
84
85
86#define SCM_SVC_CE_CHN_SWITCH_ID 0x04
87#define SCM_CE_CHN_SWITCH_ID 0x02
88
89enum ap_ce_channel_type {
90AP_CE_REGISTER_USE = 0,
91AP_CE_ADM_USE = 1
92};
93
94/* Apps CE resource. */
95#define TZ_RESOURCE_CE_AP 2
96
97uint8_t switch_ce_chn_cmd(enum ap_ce_channel_type channel);
98
99
Shashank Mittal162244e2011-08-08 19:01:25 -0700100void set_tamper_fuse_cmd();
101
102/**
103 * struct scm_command - one SCM command buffer
104 * @len: total available memory for command and response
105 * @buf_offset: start of command buffer
106 * @resp_hdr_offset: start of response buffer
107 * @id: command to be executed
108 * @buf: buffer returned from scm_get_command_buffer()
109 *
110 * An SCM command is layed out in memory as follows:
111 *
112 * ------------------- <--- struct scm_command
113 * | command header |
114 * ------------------- <--- scm_get_command_buffer()
115 * | command buffer |
116 * ------------------- <--- struct scm_response and
117 * | response header | scm_command_to_response()
118 * ------------------- <--- scm_get_response_buffer()
119 * | response buffer |
120 * -------------------
121 *
122 * There can be arbitrary padding between the headers and buffers so
123 * you should always use the appropriate scm_get_*_buffer() routines
124 * to access the buffers in a safe manner.
125 */
126struct scm_command {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800127 uint32_t len;
128 uint32_t buf_offset;
129 uint32_t resp_hdr_offset;
130 uint32_t id;
131 uint32_t buf[0];
Shashank Mittal162244e2011-08-08 19:01:25 -0700132};
133
134/**
135 * struct scm_response - one SCM response buffer
136 * @len: total available memory for response
137 * @buf_offset: start of response data relative to start of scm_response
138 * @is_complete: indicates if the command has finished processing
139 */
140struct scm_response {
Ajay Dudanib01e5062011-12-03 23:23:42 -0800141 uint32_t len;
142 uint32_t buf_offset;
143 uint32_t is_complete;
Shashank Mittal162244e2011-08-08 19:01:25 -0700144};
145
Deepa Dinamani193874e2012-02-07 14:00:04 -0800146
147
Shashank Mittal162244e2011-08-08 19:01:25 -0700148#endif