karo: tx6: add TXUL support
[karo-tx-uboot.git] / arch / arm / include / asm / arch-mx6 / hab.h
1 /*
2  * Copyright (C) 2012-2015 Freescale Semiconductor, Inc. All Rights Reserved.
3  *
4  * SPDX-License-Identifier:    GPL-2.0+
5  *
6 */
7
8 #ifndef __ARCH_MX6_HAB_H
9 #define __ARCH_MX6_HAB_H
10
11 #ifdef CONFIG_SECURE_BOOT
12
13 #include <linux/types.h>
14 #include <asm/arch/sys_proto.h>
15
16 int get_hab_status(void);
17
18 /* -------- start of HAB API updates ------------*/
19 /* The following are taken from HAB4 SIS */
20
21 /* Status definitions */
22 enum hab_status {
23         HAB_STS_ANY = 0x00,
24         HAB_FAILURE = 0x33,
25         HAB_WARNING = 0x69,
26         HAB_SUCCESS = 0xf0
27 };
28
29 /* Security Configuration definitions */
30 enum hab_config {
31         HAB_CFG_RETURN = 0x33,          /* Field Return IC */
32         HAB_CFG_OPEN = 0xf0,            /* Non-secure IC */
33         HAB_CFG_CLOSED = 0xcc           /* Secure IC */
34 };
35
36 /* State definitions */
37 enum hab_state {
38         HAB_STATE_INITIAL = 0x33,       /* Initialising state (transitory) */
39         HAB_STATE_CHECK = 0x55,         /* Check state (non-secure) */
40         HAB_STATE_NONSECURE = 0x66,     /* Non-secure state */
41         HAB_STATE_TRUSTED = 0x99,       /* Trusted state */
42         HAB_STATE_SECURE = 0xaa,        /* Secure state */
43         HAB_STATE_FAIL_SOFT = 0xcc,     /* Soft fail state */
44         HAB_STATE_FAIL_HARD = 0xff,     /* Hard fail state (terminal) */
45         HAB_STATE_NONE = 0xf0,          /* No security state machine */
46         HAB_STATE_MAX
47 };
48
49 enum hab_target {
50         HAB_TGT_MEMORY = 0x0f, /* Check memory white list */
51         HAB_TGT_PERIPHERAL = 0xf0, /* Check peripheral white list*/
52         HAB_TGT_ANY = 0x55, /**< Check memory & peripheral white list */
53 };
54
55 enum HAB_FUNC_OFFSETS {
56         HAB_RVT_HEADER,
57         HAB_RVT_ENTRY,
58         HAB_RVT_EXIT,
59         HAB_RVT_CHECK_TARGET,
60         HAB_RVT_AUTHENTICATE_IMAGE,
61         HAB_RVT_RUN_DCD,
62         HAB_RVT_RUN_CSF,
63         HAB_RVT_ASSERT,
64         HAB_RVT_REPORT_EVENT,
65         HAB_RVT_REPORT_STATUS,
66         HAB_RVT_FAILSAFE,
67 };
68
69 enum hab_reason {
70         HAB_RSN_ANY = 0x00,             /* Match any reason */
71         HAB_ENG_FAIL = 0x30,            /* Engine failure */
72         HAB_INV_ADDRESS = 0x22,         /* Invalid address: access denied */
73         HAB_INV_ASSERTION = 0x0c,       /* Invalid assertion */
74         HAB_INV_CALL = 0x28,            /* Function called out of sequence */
75         HAB_INV_CERTIFICATE = 0x21,     /* Invalid certificate */
76         HAB_INV_COMMAND = 0x06,         /* Invalid command: command malformed */
77         HAB_INV_CSF = 0x11,             /* Invalid csf */
78         HAB_INV_DCD = 0x27,             /* Invalid dcd */
79         HAB_INV_INDEX = 0x0f,           /* Invalid index: access denied */
80         HAB_INV_IVT = 0x05,             /* Invalid ivt */
81         HAB_INV_KEY = 0x1d,             /* Invalid key */
82         HAB_INV_RETURN = 0x1e,          /* Failed callback function */
83         HAB_INV_SIGNATURE = 0x18,       /* Invalid signature */
84         HAB_INV_SIZE = 0x17,            /* Invalid data size */
85         HAB_MEM_FAIL = 0x2e,            /* Memory failure */
86         HAB_OVR_COUNT = 0x2b,           /* Expired poll count */
87         HAB_OVR_STORAGE = 0x2d,         /* Exhausted storage region */
88         HAB_UNS_ALGORITHM = 0x12,       /* Unsupported algorithm */
89         HAB_UNS_COMMAND = 0x03,         /* Unsupported command */
90         HAB_UNS_ENGINE = 0x0a,          /* Unsupported engine */
91         HAB_UNS_ITEM = 0x24,            /* Unsupported configuration item */
92         HAB_UNS_KEY = 0x1b,             /* Unsupported key type/parameters */
93         HAB_UNS_PROTOCOL = 0x14,        /* Unsupported protocol */
94         HAB_UNS_STATE = 0x09,           /* Unsuitable state */
95         HAB_RSN_MAX
96 };
97
98 enum hab_context {
99         HAB_CTX_ANY = 0x00,             /* Match any context */
100         HAB_CTX_FAB = 0xff,             /* Event logged in hab_fab_test() */
101         HAB_CTX_ENTRY = 0xe1,           /* Event logged in hab_rvt.entry() */
102         HAB_CTX_TARGET = 0x33,          /* Event logged in hab_rvt.check_target() */
103         HAB_CTX_AUTHENTICATE = 0x0a,    /* Logged in hab_rvt.authenticate_image() */
104         HAB_CTX_DCD = 0xdd,             /* Event logged in hab_rvt.run_dcd() */
105         HAB_CTX_CSF = 0xcf,             /* Event logged in hab_rvt.run_csf() */
106         HAB_CTX_COMMAND = 0xc0,         /* Event logged executing csf/dcd command */
107         HAB_CTX_AUT_DAT = 0xdb,         /* Authenticated data block */
108         HAB_CTX_ASSERT = 0xa0,          /* Event logged in hab_rvt.assert() */
109         HAB_CTX_EXIT = 0xee,            /* Event logged in hab_rvt.exit() */
110         HAB_CTX_MAX
111 };
112
113 /*Function prototype description*/
114 typedef enum hab_status hab_rvt_report_event_t(enum hab_status, uint32_t,
115                 uint8_t* , size_t*);
116 typedef enum hab_status hab_rvt_report_status_t(enum hab_config *,
117                 enum hab_state *);
118 typedef enum hab_status hab_loader_callback_f_t(void**, size_t*, const void*);
119 typedef enum hab_status hab_rvt_entry_t(void);
120 typedef enum hab_status hab_rvt_exit_t(void);
121 typedef enum hab_status hab_rvt_check_target_t(enum hab_target, const void *,
122                 size_t);
123
124 typedef void *hab_rvt_authenticate_image_t(uint8_t, ptrdiff_t,
125                 void **, size_t *, hab_loader_callback_f_t);
126
127 typedef enum hab_status hab_rvt_run_dcd_t(const uint8_t *dcd);
128
129 typedef enum hab_status hab_rvt_run_csf_t(const uint8_t *csf, uint8_t cid);
130
131 typedef enum hab_status hab_rvt_assert_t(uint32_t, const void *,
132                 size_t);
133
134 typedef enum hab_status hab_rvt_report_event_t(enum hab_status, uint32_t,
135                 uint8_t* , size_t*);
136
137 typedef enum hab_status hab_rvt_report_status_t(enum hab_config *,
138                 enum hab_state *);
139
140 typedef void hapi_clock_init_t(void);
141
142 #define HAB_ENG_ANY             0x00   /* Select first compatible engine */
143 #define HAB_ENG_SCC             0x03   /* Security controller */
144 #define HAB_ENG_RTIC            0x05   /* Run-time integrity checker */
145 #define HAB_ENG_SAHARA          0x06   /* Crypto accelerator */
146 #define HAB_ENG_CSU             0x0a   /* Central Security Unit */
147 #define HAB_ENG_SRTC            0x0c   /* Secure clock */
148 #define HAB_ENG_DCP             0x1b   /* Data Co-Processor */
149 #define HAB_ENG_CAAM            0x1d   /* CAAM */
150 #define HAB_ENG_SNVS            0x1e   /* Secure Non-Volatile Storage */
151 #define HAB_ENG_OCOTP           0x21   /* Fuse controller */
152 #define HAB_ENG_DTCP            0x22   /* DTCP co-processor */
153 #define HAB_ENG_ROM             0x36   /* Protected ROM area */
154 #define HAB_ENG_HDCP            0x24   /* HDCP co-processor */
155 #define HAB_ENG_RTL             0x77   /* RTL simulation engine */
156 #define HAB_ENG_SW              0xff   /* Software engine */
157
158 static inline void **hab_rvt_base(void)
159 {
160         unsigned long base;
161         int cpu_type = get_cpu_type();
162         int rev = soc_rev();
163         const uint32_t mask = 0xfc0000ff;
164
165         switch (cpu_type) {
166         case MXC_CPU_MX6Q:
167         case MXC_CPU_MX6D:
168                 if (rev >= CHIP_REV_1_5)
169                         base = 0x98UL;
170                 else
171                         base = 0x94UL;
172                 break;
173         case MXC_CPU_MX6DL:
174                 if (rev >= CHIP_REV_1_2)
175                         base = 0x98UL;
176                 else
177                         base = 0x94UL;
178                 break;
179         case MXC_CPU_MX6SOLO:
180                 base = 0x98UL;
181                 break;
182         case MXC_CPU_MX6SX:
183         case MXC_CPU_MX6UL:
184                 base = 0x100UL;
185                 break;
186         default:
187                 printf("Unsupported CPU type: %02x\n", cpu_type);
188                 return NULL;
189         }
190
191         if (((rev = readl(base)) & mask) != cpu_to_be32(0xdd000040)) {
192                 printf("Invalid RVT @ %08lx: %08x:%08x\n",
193                         base, rev, rev & mask);
194                 return NULL;
195         }
196         return (void **)base;
197 }
198
199 #define HAB_CID_ROM 0 /**< ROM Caller ID */
200 #define HAB_CID_UBOOT 1 /**< UBOOT Caller ID*/
201
202 /* ----------- end of HAB API updates ------------*/
203
204 #define hab_rvt_entry_p                                         \
205         ((hab_rvt_entry_t *)hab_rvt_base()[HAB_RVT_ENTRY])
206
207 #define hab_rvt_exit_p                                          \
208         ((hab_rvt_exit_t *)hab_rvt_base()[HAB_RVT_EXIT])
209
210 #define hab_rvt_check_target_p                                  \
211         ((hab_rvt_check_target_t*)hab_rvt_base()[HAB_RVT_CHECK_TARGET])
212
213 #define hab_rvt_authenticate_image_p                            \
214         ((hab_rvt_authenticate_image_t *)hab_rvt_base()[HAB_RVT_AUTHENTICATE_IMAGE])
215
216 #define hab_rvt_run_dcd_p                                       \
217         ((hab_rvt_run_dcd_t*)hab_rvt_base()[HAB_RVT_RUN_DCD])
218
219 #define hab_rvt_run_csf_p                                       \
220         ((hab_rvt_run_csf_t*)hab_rvt_base()[HAB_RVT_RUN_CSF])
221
222 #define hab_rvt_assert_p                                        \
223         ((hab_rvt_assert_t*)hab_rvt_base()[HAB_RVT_ASSERT])
224
225 #define hab_rvt_report_event_p                                  \
226         ((hab_rvt_report_event_t*)hab_rvt_base()[HAB_RVT_REPORT_EVENT])
227
228 #define hab_rvt_report_status_p                                 \
229         ((hab_rvt_report_status_t*)hab_rvt_base()[HAB_RVT_REPORT_STATUS])
230
231 #define HAB_FUNC(n, rt)                                                 \
232 static inline rt hab_rvt_##n(void)                                      \
233 {                                                                       \
234         if (hab_rvt_base() == NULL)                                     \
235                 return (rt)-1;                                          \
236         return hab_rvt_##n##_p();                                       \
237 }                                                                       \
238
239 #define HAB_FUNC1(n, rt, t1)                                            \
240 static inline rt hab_rvt_##n(t1 p1)                                     \
241 {                                                                       \
242         if (hab_rvt_base() == NULL)                                     \
243                 return (rt)-1;                                          \
244         return hab_rvt_##n##_p(p1);                                     \
245 }
246
247 #define HAB_FUNC2(n, rt, t1, t2)                                        \
248 static inline rt hab_rvt_##n(t1 p1, t2 p2)                              \
249 {                                                                       \
250         if (hab_rvt_base() == NULL)                                     \
251                 return (rt)-1;                                          \
252         return hab_rvt_##n##_p(p1, p2);                                 \
253 }
254
255 #define HAB_FUNC3(n, rt, t1, t2, t3)                                    \
256 static inline rt hab_rvt_##n(t1 p1, t2 p2, t3 p3)                       \
257 {                                                                       \
258         if (hab_rvt_base() == NULL)                                     \
259                 return (rt)-1;                                          \
260         return hab_rvt_##n##_p(p1, p2, p3);                             \
261 }
262
263 #define HAB_FUNC4(n, rt, t1, t2, t3, t4)                                \
264 static inline rt hab_rvt_##n(t1 p1, t2 p2, t3 p3, t4 p4)                \
265 {                                                                       \
266         if (hab_rvt_base() == NULL)                                     \
267                 return (rt)-1;                                          \
268         return hab_rvt_##n##_p(p1, p2, p3, p4);                         \
269 }
270
271 #define HAB_FUNC5(n, rt, t1, t2, t3, t4, t5)                            \
272 static inline rt hab_rvt_##n(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5)         \
273 {                                                                       \
274         if (hab_rvt_base() == NULL)                                     \
275                 return (rt)-1;                                          \
276         return hab_rvt_##n##_p(p1, p2, p3, p4, p5);                     \
277 }
278
279 #else /* CONFIG_SECURE_BOOT */
280
281 static inline int get_hab_status(void)
282 {
283         return 0;
284 }
285
286 #endif /* CONFIG_SECURE_BOOT */
287 #endif /* __ARCH_MX6_HAB_H */