]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/include/asm/arch-mx6/hab.h
karo: tx6: cleanup HAB functions
[karo-tx-uboot.git] / arch / arm / include / asm / arch-mx6 / hab.h
1 /*
2  * Copyright (C) 2012 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 typedef enum hab_status {
23         HAB_STS_ANY = 0x00,
24         HAB_FAILURE = 0x33,
25         HAB_WARNING = 0x69,
26         HAB_SUCCESS = 0xf0
27 } hab_status_t;
28
29 /* Security Configuration definitions */
30 typedef 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 } hab_config_t;
35
36 /* State definitions */
37 typedef 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 } hab_state_t;
48
49 typedef 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 } hab_target_t;
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 /* Function prototype description */
70 typedef hab_status_t hab_rvt_entry_t(void);
71
72 typedef hab_status_t hab_rvt_exit_t(void);
73
74 typedef hab_status_t hab_rvt_check_target_t(hab_target_t, const void *,
75                 size_t);
76
77 typedef hab_status_t hab_loader_callback_f_t(void**, size_t*, const void*);
78 typedef void *hab_rvt_authenticate_image_t(uint8_t, ptrdiff_t,
79                 void **, size_t *, hab_loader_callback_f_t);
80
81 typedef hab_status_t hab_rvt_run_dcd_t(const uint8_t *dcd);
82
83 typedef hab_status_t hab_rvt_run_csf_t(const uint8_t *csf, uint8_t cid);
84
85 typedef hab_status_t hab_rvt_assert_t(uint32_t, const void *,
86                 size_t);
87
88 typedef hab_status_t hab_rvt_report_event_t(hab_status_t, uint32_t,
89                 uint8_t* , size_t*);
90
91 typedef hab_status_t hab_rvt_report_status_t(enum hab_config *,
92                 enum hab_state *);
93
94 typedef void hapi_clock_init_t(void);
95
96 #ifdef CONFIG_SOC_MX6SX
97 #define HAB_RVT_BASE                    0x00000100
98 #else
99 #define HAB_RVT_BASE                    0x00000094
100 #endif
101
102 static inline void **hab_rvt_base(void)
103 {
104         uint32_t *base;
105
106         if (((is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D)) &&
107                 soc_rev() >= CHIP_REV_1_5) ||
108                 (is_cpu_type(MXC_CPU_MX6DL) && soc_rev() >= CHIP_REV_1_2) ||
109                 is_cpu_type(MXC_CPU_MX6SOLO))
110                 base = (void *)0x98;
111         else
112                 base = (void *)0x94;
113         if ((*base & 0xff0000ff) != cpu_to_be32(0xdd000041)) {
114                 printf("Invalid RVT @ %p\n", base);
115                 return NULL;
116         }
117         return (void **)base;
118 }
119
120 #define HAB_CID_ROM 0 /**< ROM Caller ID */
121 #define HAB_CID_UBOOT 1 /**< UBOOT Caller ID*/
122 /* ----------- end of HAB API updates ------------*/
123
124 #define hab_rvt_entry_p                                         \
125         ((hab_rvt_entry_t *)hab_rvt_base()[HAB_RVT_ENTRY])
126
127 #define hab_rvt_exit_p                                          \
128         ((hab_rvt_exit_t *)hab_rvt_base()[HAB_RVT_EXIT])
129
130 #define hab_rvt_check_target_p                                  \
131         ((hab_rvt_check_target_t*)hab_rvt_base()[HAB_RVT_CHECK_TARGET])
132
133 #define hab_rvt_authenticate_image_p                            \
134         ((hab_rvt_authenticate_image_t *)hab_rvt_base()[HAB_RVT_AUTHENTICATE_IMAGE])
135
136 #define hab_rvt_run_dcd_p                                       \
137         ((hab_rvt_run_dcd_t*)hab_rvt_base()[HAB_RVT_RUN_DCD])
138
139 #define hab_rvt_run_csf_p                                       \
140         ((hab_rvt_run_csf_t*)hab_rvt_base()[HAB_RVT_RUN_CSF])
141
142 #define hab_rvt_assert_p                                        \
143         ((hab_rvt_assert_t*)hab_rvt_base()[HAB_RVT_ASSERT])
144
145 #define hab_rvt_report_event_p                                  \
146         ((hab_rvt_report_event_t*)hab_rvt_base()[HAB_RVT_REPORT_EVENT])
147
148 #define hab_rvt_report_status_p                                 \
149         ((hab_rvt_report_status_t*)hab_rvt_base()[HAB_RVT_REPORT_STATUS])
150
151 #define HAB_FUNC(n, rt)                                                 \
152 static inline rt hab_rvt_##n(void)                                      \
153 {                                                                       \
154         if (hab_rvt_base() == NULL)                                     \
155                 return (rt)-1;                                          \
156         return hab_rvt_##n##_p();                                       \
157 }                                                                       \
158
159 #define HAB_FUNC1(n, rt, t1)                                            \
160 static inline rt hab_rvt_##n(t1 p1)                                     \
161 {                                                                       \
162         if (hab_rvt_base() == NULL)                                     \
163                 return (rt)-1;                                          \
164         return hab_rvt_##n##_p(p1);                                     \
165 }
166
167 #define HAB_FUNC2(n, rt, t1, t2)                                        \
168 static inline rt hab_rvt_##n(t1 p1, t2 p2)                              \
169 {                                                                       \
170         if (hab_rvt_base() == NULL)                                     \
171                 return (rt)-1;                                          \
172         return hab_rvt_##n##_p(p1, p2);                                 \
173 }
174
175 #define HAB_FUNC3(n, rt, t1, t2, t3)                                    \
176 static inline rt hab_rvt_##n(t1 p1, t2 p2, t3 p3)                       \
177 {                                                                       \
178         if (hab_rvt_base() == NULL)                                     \
179                 return (rt)-1;                                          \
180         return hab_rvt_##n##_p(p1, p2, p3);                             \
181 }
182
183 #define HAB_FUNC4(n, rt, t1, t2, t3, t4)                                \
184 static inline rt hab_rvt_##n(t1 p1, t2 p2, t3 p3, t4 p4)                \
185 {                                                                       \
186         if (hab_rvt_base() == NULL)                                     \
187                 return (rt)-1;                                          \
188         return hab_rvt_##n##_p(p1, p2, p3, p4);                         \
189 }
190
191 #define HAB_FUNC5(n, rt, t1, t2, t3, t4, t5)                            \
192 static inline rt hab_rvt_##n(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5)         \
193 {                                                                       \
194         if (hab_rvt_base() == NULL)                                     \
195                 return (rt)-1;                                          \
196         return hab_rvt_##n##_p(p1, p2, p3, p4, p5);                     \
197 }
198
199 #else /* CONFIG_SECURE_BOOT */
200
201 static inline int get_hab_status(void)
202 {
203         return 0;
204 }
205
206 #endif /* CONFIG_SECURE_BOOT */
207 #endif /* __ARCH_MX6_HAB_H */