Siddhartha Agrawal | eb094c5 | 2013-01-28 12:11:43 -0800 | [diff] [blame^] | 1 | /* Copyright (c) 2011-2013, 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 |
| 39 | |
| 40 | typedef unsigned int uint32; |
| 41 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 42 | typedef struct { |
| 43 | uint32 len; |
| 44 | uint32 buf_offset; |
| 45 | uint32 resp_hdr_offset; |
| 46 | uint32 id; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 47 | } scm_command; |
| 48 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 49 | typedef struct { |
| 50 | uint32 len; |
| 51 | uint32 buf_offset; |
| 52 | uint32 is_complete; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 53 | } scm_response; |
| 54 | |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 55 | typedef struct { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 56 | uint32 *img_ptr; |
| 57 | uint32 *img_len_ptr; |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 58 | } img_req; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 59 | |
Siddhartha Agrawal | eb094c5 | 2013-01-28 12:11:43 -0800 | [diff] [blame^] | 60 | typedef struct { |
| 61 | uint32 id; |
| 62 | uint32 spare; |
| 63 | } tz_secure_cfg; |
| 64 | |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 65 | #define SCM_SVC_SSD 7 |
| 66 | #define SSD_DECRYPT_ID 0x01 |
| 67 | #define SSD_ENCRYPT_ID 0x02 |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 68 | |
Siddhartha Agrawal | eb094c5 | 2013-01-28 12:11:43 -0800 | [diff] [blame^] | 69 | #define SCM_SVC_SSD 0x0C |
| 70 | #define IOMMU_SECURE_CFG 0x02 |
| 71 | |
| 72 | #define SECURE_DEVICE_MDSS 1 |
| 73 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 74 | static uint32 smc(uint32 cmd_addr); |
Neeti Desai | 127b9e0 | 2012-03-20 16:11:23 -0700 | [diff] [blame] | 75 | |
| 76 | int decrypt_scm(uint32_t ** img_ptr, uint32_t * img_len_ptr); |
| 77 | int encrypt_scm(uint32_t ** img_ptr, uint32_t * img_len_ptr); |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 78 | |
Deepa Dinamani | 193874e | 2012-02-07 14:00:04 -0800 | [diff] [blame] | 79 | #define SCM_SVC_FUSE 0x08 |
| 80 | #define SCM_BLOW_SW_FUSE_ID 0x01 |
| 81 | #define SCM_IS_SW_FUSE_BLOWN_ID 0x02 |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 82 | |
Deepa Dinamani | 193874e | 2012-02-07 14:00:04 -0800 | [diff] [blame] | 83 | #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 | |
| 89 | enum ap_ce_channel_type { |
| 90 | AP_CE_REGISTER_USE = 0, |
| 91 | AP_CE_ADM_USE = 1 |
| 92 | }; |
| 93 | |
| 94 | /* Apps CE resource. */ |
| 95 | #define TZ_RESOURCE_CE_AP 2 |
| 96 | |
| 97 | uint8_t switch_ce_chn_cmd(enum ap_ce_channel_type channel); |
| 98 | |
| 99 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 100 | void 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 | */ |
| 126 | struct scm_command { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 127 | uint32_t len; |
| 128 | uint32_t buf_offset; |
| 129 | uint32_t resp_hdr_offset; |
| 130 | uint32_t id; |
| 131 | uint32_t buf[0]; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 132 | }; |
| 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 | */ |
| 140 | struct scm_response { |
Ajay Dudani | b01e506 | 2011-12-03 23:23:42 -0800 | [diff] [blame] | 141 | uint32_t len; |
| 142 | uint32_t buf_offset; |
| 143 | uint32_t is_complete; |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 144 | }; |
| 145 | |
Deepa Dinamani | 193874e | 2012-02-07 14:00:04 -0800 | [diff] [blame] | 146 | |
| 147 | |
Shashank Mittal | 162244e | 2011-08-08 19:01:25 -0700 | [diff] [blame] | 148 | #endif |