vcgencmd: Apply ASLR
[platform/adaptation/broadcom/libomxil-vc4.git] / vcfw / vclib / vclib.h
1 /*
2 Copyright (c) 2012, Broadcom Europe Ltd
3 All rights reserved.
4
5 Redistribution and use in source and binary forms, with or without
6 modification, are permitted provided that the following conditions are met:
7     * Redistributions of source code must retain the above copyright
8       notice, this list of conditions and the following disclaimer.
9     * Redistributions in binary form must reproduce the above copyright
10       notice, this list of conditions and the following disclaimer in the
11       documentation and/or other materials provided with the distribution.
12     * Neither the name of the copyright holder nor the
13       names of its contributors may be used to endorse or promote products
14       derived from this software without specific prior written permission.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY
20 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 */
27
28 #ifndef VCFW_VCLIB_H
29 #define VCFW_VCLIB_H
30
31  #ifdef __VIDEOCORE__
32
33 #include "vcfw/rtos/rtos.h"
34 #include "vcfw/logging/logging.h"
35
36 int32_t vclib_vcfw_init( void );
37 int32_t vclib_vcfw_driver_init( void );
38
39 typedef enum {
40    FATAL_RED = 1,
41    FATAL_GREEN,
42    FATAL_BLUE,
43    FATAL_CYAN,
44    FATAL_MAGENTA,
45    FATAL_YELLOW,
46    FATAL_WHITE,
47    FATAL_BLACK,
48
49    FATAL_SUB_RED     = FATAL_RED     << 4,
50    FATAL_SUB_GREEN   = FATAL_GREEN   << 4,
51    FATAL_SUB_BLUE    = FATAL_BLUE    << 4,
52    FATAL_SUB_CYAN    = FATAL_CYAN    << 4,
53    FATAL_SUB_MAGENTA = FATAL_MAGENTA << 4,
54    FATAL_SUB_YELLOW  = FATAL_YELLOW  << 4,
55    FATAL_SUB_WHITE   = FATAL_WHITE   << 4,
56    FATAL_SUB_BLACK   = FATAL_BLACK   << 4,
57 } FATAL_COLOUR;
58
59 void vclib_fatal_fn(FATAL_COLOUR colour);
60   #ifdef FATAL_ASSERTS
61 #define vclib_fatal_assert(x, c) if (x) {} else vclib_fatal_fn(c)
62   #else
63 #define vclib_fatal_assert(x, c) assert(x)
64   #endif
65
66 extern void vclib_init();
67 extern int  vclib_obtain_VRF(int block);
68 extern void vclib_release_VRF(void);
69 extern int  vclib_check_VRF(void);
70
71 #define get_free_mem(pool) (rtos_get_free_mem(pool))
72
73 #define malloc_setpool( external)         rtos_malloc_setpool( external)
74 #define malloc_256bit( size)              rtos_malloc_256bit( size)
75 #define free_256bit(ret)                  rtos_free_256bit(ret)
76 #define realloc_256bit(ret,  size)        rtos_realloc_256bit(ret,  size)
77 #define malloc_external( size)            rtos_malloc_external( size)
78 #define malloc_external_256bit( size)     rtos_malloc_external_256bit( size )
79
80 #define malloc_priority( size,  align,  priority,  description) rtos_prioritymalloc( size,  align,  priority,  description)
81 #define calloc_priority( size,  align,  priority,  description) rtos_prioritycalloc( size,  align,  priority,  description)
82
83 #define vclib_setpriority rtos_setpriority
84 #define vclib_getpriority rtos_getpriority
85
86 #define vclib_prioritymalloc(size, align, priority, description) rtos_prioritymalloc(size, align, priority, description)
87 #define vclib_prioritycalloc(size, align, priority, description) rtos_prioritycalloc(size, align, priority, description)
88
89 #define vclib_priorityfree(buffer) rtos_priorityfree(buffer)
90 #define VCLIB_ALIGN_DEFAULT                  RTOS_ALIGN_DEFAULT
91 #define VCLIB_ALIGN_128BIT                   RTOS_ALIGN_128BIT
92 #define VCLIB_ALIGN_256BIT                   RTOS_ALIGN_256BIT
93 #define VCLIB_ALIGN_AXI                      RTOS_ALIGN_AXI
94 #define VCLIB_ALIGN_512BIT                   RTOS_ALIGN_512BIT
95 #define VCLIB_ALIGN_4KBYTE                   RTOS_ALIGN_4KBYTE
96 #define VCLIB_PRIORITY_INTERNAL              RTOS_PRIORITY_INTERNAL
97 #define VCLIB_PRIORITY_EXTERNAL              RTOS_PRIORITY_EXTERNAL
98 #define VCLIB_PRIORITY_UNIMPORTANT           RTOS_PRIORITY_UNIMPORTANT
99 #define VCLIB_PRIORITY_COHERENT              RTOS_PRIORITY_COHERENT
100 #define VCLIB_PRIORITY_DIRECT                RTOS_PRIORITY_DIRECT
101
102 extern void vclib_save_vrf( unsigned char *vrf_strorage );
103 extern void vclib_restore_vrf( unsigned char *vrf_strorage );
104 extern void vclib_save_quarter_vrf( unsigned char *vrf_strorage );
105 extern void vclib_restore_quarter_vrf( unsigned char *vrf_strorage );
106
107 extern void vclib_cache_flush(void);
108 extern void vclib_dcache_flush(void);
109 extern void vclib_icache_flush(void);
110 extern void vclib_dcache_flush_range(void *start_addr, int length);
111 extern void vclib_l1cache_flush_range(void *start_addr, int length);
112
113 /* Use these function to identify the condition where you don't care if the data is
114  * written back -- if it becomes possible then we save ourselves the bother of
115  * hunting for places where it should be done that way.
116  */
117 extern void vclib_dcache_invalidate_range(void *start_addr, int length);
118 extern void vclib_l1cache_invalidate_range(void *start_addr, int length);
119
120 #define vclib_timer_t RTOS_TIMER_T
121 #define vclib_timer_done_op RTOS_TIMER_DONE_OPERATION_T
122 #define vclib_timer_time_t RTOS_TIMER_TIME_T
123 #define vclib_timer_ticks_t RTOS_TIMER_TICKS_T
124
125 #define vclib_timer_init rtos_timer_init
126 #define vclib_timer_is_running rtos_timer_is_running
127 #define vclib_timer_set rtos_timer_set
128 #define vclib_timer_reset rtos_timer_reset
129 #define vclib_timer_cancel rtos_timer_cancel
130
131 extern int vclib_disableint(void);
132 extern void vclib_restoreint(int sr);
133
134
135 /* Some support for automatic logging. */
136
137 /* Have a macro that is guaranteed to be a simple "assert" even when logging is on. */
138   #ifdef NDEBUG
139 #define simple_assert(cond)
140   #else
141 #define simple_assert(cond) if (cond) {} else _bkpt()
142   #endif
143
144
145 /*********
146 ** HACK!!!!!! Temp function definition (code in cache_flush.s) used to enable the run domain in VCIII
147 **********/
148 extern void vc_enable_run_domain( void );
149
150 #define vclib_memory_is_valid rtos_memory_is_valid
151
152
153 /* Latch events are fast and small event notifications */
154 typedef RTOS_LATCH_T latch_event_t;
155
156 #define latch_event_present() ((latch_event_t)rtos_latch_unlocked())
157
158 #define latch_event_absent() ((latch_event_t)rtos_latch_locked())
159
160
161 #define latch_event_is_present( latch ) (latch_event_present() == *(latch))
162
163   #if defined(__HIGHC__) /* MetaWare tools */
164
165    static inline unsigned vclib_status_register(void)
166    {
167       /* Would have liked use == syntax for assigning a variable to be a register
168       but the compiler issues a warning about that */
169       return _vasm("mov %D,%sr");
170    }
171    static inline int vclib_interrupts_enabled(void)
172    {
173       unsigned sr = vclib_status_register();
174       return !!(sr&(1<<30));
175    }
176
177   #else
178
179    static inline unsigned vclib_status_register(void)
180    {
181       unsigned i;
182       asm("mov %0, sr" : "=r"(i));
183       return i;
184    }
185    static inline int vclib_interrupts_enabled(void)
186    {
187       unsigned sr = vclib_status_register();
188       return !!(sr&(1<<30));
189    }
190
191   #endif
192
193  #endif // defined __VIDEOCORE__
194
195
196 // A few helpful things for windows / standalone Linux
197 # ifndef __VIDEOCORE__
198
199 #  ifdef __GNUC__
200     static inline int vclib_obtain_VRF(int block) { return 1; }
201     static inline void vclib_release_VRF(void) {}
202     static inline int vclib_check_VRF(void) { return 1; }
203 #  else
204 #   define vclib_obtain_VRF(b) (1)
205 #   define vclib_release_VRF()
206 #   define vclib_check_VRF() (1)
207 #  endif
208
209 #  ifdef VIDEOCORE_CODE_IN_SIMULATION
210
211 #   undef abs // prior to including stdlib.h
212 #   include <stdlib.h> // For malloc() et al.
213
214 #   define vclib_dcache_flush_range(start_addr, length)
215
216 #   define VCLIB_ALIGN_DEFAULT   4
217 #   define VCLIB_ALIGN_256BIT    32
218 #   define VCLIB_ALIGN_4KBYTE    4096
219
220 #   define VCLIB_PRIORITY_COHERENT      0
221 #   define VCLIB_PRIORITY_DIRECT        0
222 #   define VCLIB_PRIORITY_UNIMPORTANT   0
223
224 #   define vclib_fatal_assert(x, c) assert(x)
225  
226 #   define vclib_prioritymalloc(size, align, priority, description) \
227            rtos_prioritymalloc((size), (align), (priority), (description))
228 #   define vclib_prioritycalloc(size, align, priority, description) \
229            rtos_prioritycalloc((size), (align), (priority), (description))
230
231 #   define vclib_priorityfree(buffer) rtos_priorityfree((buffer))
232 #   define malloc_256bit(size) rtos_malloc_256bit((size))
233 #   define free_256bit(ret) rtos_free_256bit((ret))
234
235 #  endif
236
237 # endif // !defined(__VIDEOCORE__)
238
239 #endif // defined VCFW_VCLIB_H