2 Copyright (c) 2012, Broadcom Europe Ltd
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.
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.
33 #include "vcfw/rtos/rtos.h"
34 #include "vcfw/logging/logging.h"
36 int32_t vclib_vcfw_init( void );
37 int32_t vclib_vcfw_driver_init( void );
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,
59 void vclib_fatal_fn(FATAL_COLOUR colour);
61 #define vclib_fatal_assert(x, c) if (x) {} else vclib_fatal_fn(c)
63 #define vclib_fatal_assert(x, c) assert(x)
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);
71 #define get_free_mem(pool) (rtos_get_free_mem(pool))
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 )
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)
83 #define vclib_setpriority rtos_setpriority
84 #define vclib_getpriority rtos_getpriority
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)
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
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 );
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);
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.
117 extern void vclib_dcache_invalidate_range(void *start_addr, int length);
118 extern void vclib_l1cache_invalidate_range(void *start_addr, int length);
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
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
131 extern int vclib_disableint(void);
132 extern void vclib_restoreint(int sr);
135 /* Some support for automatic logging. */
137 /* Have a macro that is guaranteed to be a simple "assert" even when logging is on. */
139 #define simple_assert(cond)
141 #define simple_assert(cond) if (cond) {} else _bkpt()
146 ** HACK!!!!!! Temp function definition (code in cache_flush.s) used to enable the run domain in VCIII
148 extern void vc_enable_run_domain( void );
150 #define vclib_memory_is_valid rtos_memory_is_valid
153 /* Latch events are fast and small event notifications */
154 typedef RTOS_LATCH_T latch_event_t;
156 #define latch_event_present() ((latch_event_t)rtos_latch_unlocked())
158 #define latch_event_absent() ((latch_event_t)rtos_latch_locked())
161 #define latch_event_is_present( latch ) (latch_event_present() == *(latch))
163 #if defined(__HIGHC__) /* MetaWare tools */
165 static inline unsigned vclib_status_register(void)
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");
171 static inline int vclib_interrupts_enabled(void)
173 unsigned sr = vclib_status_register();
174 return !!(sr&(1<<30));
179 static inline unsigned vclib_status_register(void)
182 asm("mov %0, sr" : "=r"(i));
185 static inline int vclib_interrupts_enabled(void)
187 unsigned sr = vclib_status_register();
188 return !!(sr&(1<<30));
193 #endif // defined __VIDEOCORE__
196 // A few helpful things for windows / standalone Linux
197 # ifndef __VIDEOCORE__
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; }
204 # define vclib_obtain_VRF(b) (1)
205 # define vclib_release_VRF()
206 # define vclib_check_VRF() (1)
209 # ifdef VIDEOCORE_CODE_IN_SIMULATION
211 # undef abs // prior to including stdlib.h
212 # include <stdlib.h> // For malloc() et al.
214 # define vclib_dcache_flush_range(start_addr, length)
216 # define VCLIB_ALIGN_DEFAULT 4
217 # define VCLIB_ALIGN_256BIT 32
218 # define VCLIB_ALIGN_4KBYTE 4096
220 # define VCLIB_PRIORITY_COHERENT 0
221 # define VCLIB_PRIORITY_DIRECT 0
222 # define VCLIB_PRIORITY_UNIMPORTANT 0
224 # define vclib_fatal_assert(x, c) assert(x)
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))
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))
237 # endif // !defined(__VIDEOCORE__)
239 #endif // defined VCFW_VCLIB_H