]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/include/asm/arch-mx5/hab.h
Merge branch 'karo-tx-uboot' into kc-merge
[karo-tx-uboot.git] / arch / arm / include / asm / arch-mx5 / 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_MX5_HAB_H
9 #define __ARCH_MX5_HAB_H
10
11 #ifdef CONFIG_SECURE_BOOT
12
13 #include <linux/types.h>
14
15 int get_hab_status(void);
16
17 /* -------- start of HAB API updates ------------*/
18 /* The following are taken from HAB4 SIS */
19
20 /* Status definitions */
21 typedef enum hab_status {
22         HAB_STS_ANY = 0x00,
23         HAB_FAILURE = 0x33,
24         HAB_WARNING = 0x69,
25         HAB_SUCCESS = 0xf0
26 } hab_status_t;
27
28 /* Security Configuration definitions */
29 typedef enum hab_config {
30         HAB_CFG_RETURN = 0x33, /**< Field Return IC */
31         HAB_CFG_OPEN = 0xf0, /**< Non-secure IC */
32         HAB_CFG_CLOSED = 0xcc /**< Secure IC */
33 } hab_config_t;
34
35 /* State definitions */
36 typedef enum hab_state {
37         HAB_STATE_INITIAL = 0x33, /**< Initialising state (transitory) */
38         HAB_STATE_CHECK = 0x55, /**< Check state (non-secure) */
39         HAB_STATE_NONSECURE = 0x66, /**< Non-secure state */
40         HAB_STATE_TRUSTED = 0x99, /**< Trusted state */
41         HAB_STATE_SECURE = 0xaa, /**< Secure state */
42         HAB_STATE_FAIL_SOFT = 0xcc, /**< Soft fail state */
43         HAB_STATE_FAIL_HARD = 0xff, /**< Hard fail state (terminal) */
44         HAB_STATE_NONE = 0xf0, /**< No security state machine */
45         HAB_STATE_MAX
46 } hab_state_t;
47
48 typedef enum hab_target {
49         HAB_TGT_MEMORY = 0x0f, /* Check memory white list */
50         HAB_TGT_PERIPHERAL = 0xf0, /* Check peripheral white list*/
51 } hab_target_t;
52
53 enum HAB_FUNC_OFFSETS {
54         HAB_RVT_HEADER,
55         HAB_RVT_ENTRY,
56         HAB_RVT_EXIT,
57         HAB_RVT_CHECK_TARGET,
58         HAB_RVT_AUTHENTICATE_IMAGE,
59         HAB_RVT_RUN_DCD,
60         HAB_RVT_RUN_CSF,
61         HAB_RVT_ASSERT,
62         HAB_RVT_REPORT_EVENT,
63         HAB_RVT_REPORT_STATUS,
64         HAB_RVT_FAILSAFE,
65 };
66
67 /* Function prototype description */
68 typedef hab_status_t hab_rvt_entry_t(void);
69
70 typedef hab_status_t hab_rvt_exit_t(void);
71
72 typedef hab_status_t hab_rvt_check_target_t(hab_target_t, const void *,
73                 size_t);
74
75 typedef hab_status_t hab_loader_callback_f_t(void**, size_t*, const void*);
76 typedef void *hab_rvt_authenticate_image_t(uint8_t, ptrdiff_t,
77                 void **, size_t *, hab_loader_callback_f_t);
78
79 typedef hab_status_t hab_rvt_assert_t(uint32_t, const void *,
80                 size_t);
81
82 typedef hab_status_t hab_rvt_report_event_t(hab_status_t, uint32_t,
83                 uint8_t* , size_t*);
84
85 typedef hab_status_t hab_rvt_report_status_t(enum hab_config *,
86                 enum hab_state *);
87
88 typedef void hapi_clock_init_t(void);
89
90 #define HAB_RVT_BASE                    0x00000094
91
92 static inline void **hab_rvt_base(void)
93 {
94         uint32_t *base = (void *)0x94;
95
96         if ((*base & 0xff0000ff) != cpu_to_be32(0xdd000040)) {
97                 printf("Invalid RVT @ %p\n", base);
98                 hang();
99         }
100         return (void **)base;
101 }
102
103 #define HAB_CID_ROM 0 /**< ROM Caller ID */
104 #define HAB_CID_UBOOT 1 /**< UBOOT Caller ID*/
105 /* ----------- end of HAB API updates ------------*/
106
107 #define hab_rvt_entry_p                                         \
108         ((hab_rvt_entry_t *)hab_rvt_base()[HAB_RVT_ENTRY])
109
110 #define hab_rvt_exit_p                                          \
111         ((hab_rvt_exit_t *)hab_rvt_base()[HAB_RVT_EXIT])
112
113 #define hab_rvt_check_target_p                                  \
114         ((hab_rvt_check_target_t*)hab_rvt_base()[HAB_RVT_CHECK_TARGET])
115
116 #define hab_rvt_authenticate_image_p                            \
117         ((hab_rvt_authenticate_image_t *)hab_rvt_base()[HAB_RVT_AUTHENTICATE_IMAGE])
118
119 #define hab_rvt_assert_p                                        \
120         ((hab_rvt_assert_t*)hab_rvt_base()[HAB_RVT_ASSERT])
121
122 #define hab_rvt_report_event_p                                  \
123         ((hab_rvt_report_event_t*)hab_rvt_base()[HAB_RVT_REPORT_EVENT])
124
125 #define hab_rvt_report_status_p                                 \
126         ((hab_rvt_report_status_t*)hab_rvt_base()[HAB_RVT_REPORT_STATUS])
127
128 #define HAB_FUNC(n, rt)                                                 \
129 static inline rt hab_rvt_##n(void)                                      \
130 {                                                                       \
131         if (hab_rvt_base() == NULL)                                     \
132                 return (rt)-1;                                          \
133         return hab_rvt_##n##_p();                                       \
134 }                                                                       \
135
136 #define HAB_FUNC2(n, rt, t1, t2)                                        \
137 static inline rt hab_rvt_##n(t1 p1, t2 p2)                              \
138 {                                                                       \
139         if (hab_rvt_base() == NULL)                                     \
140                 return (rt)-1;                                          \
141         return hab_rvt_##n##_p(p1, p2);                                 \
142 }
143
144 #define HAB_FUNC3(n, rt, t1, t2, t3)                                    \
145 static inline rt hab_rvt_##n(t1 p1, t2 p2, t3 p3)                       \
146 {                                                                       \
147         if (hab_rvt_base() == NULL)                                     \
148                 return (rt)-1;                                          \
149         return hab_rvt_##n##_p(p1, p2, p3);                             \
150 }
151
152 #define HAB_FUNC4(n, rt, t1, t2, t3, t4)                                \
153 static inline rt hab_rvt_##n(t1 p1, t2 p2, t3 p3, t4 p4)                \
154 {                                                                       \
155         if (hab_rvt_base() == NULL)                                     \
156                 return (rt)-1;                                          \
157         return hab_rvt_##n##_p(p1, p2, p3, p4);                         \
158 }
159
160 #define HAB_FUNC5(n, rt, t1, t2, t3, t4, t5)                            \
161 static inline rt hab_rvt_##n(t1 p1, t2 p2, t3 p3, t4 p4, t5 p5)         \
162 {                                                                       \
163         if (hab_rvt_base() == NULL)                                     \
164                 return (rt)-1;                                          \
165         return hab_rvt_##n##_p(p1, p2, p3, p4, p5);                     \
166 }
167
168 #else /* CONFIG_SECURE_BOOT */
169
170 static inline int get_hab_status(void)
171 {
172         return 0;
173 }
174
175 #endif /* CONFIG_SECURE_BOOT */
176 #endif /* __ARCH_MX5_HAB_H */