1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup ScoreSMPImpl |
---|
5 | * |
---|
6 | * @brief SuperCore SMP Implementation |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * COPYRIGHT (c) 1989-2011. |
---|
11 | * On-Line Applications Research Corporation (OAR). |
---|
12 | * |
---|
13 | * The license and distribution terms for this file may be |
---|
14 | * found in the file LICENSE in this distribution or at |
---|
15 | * http://www.rtems.org/license/LICENSE. |
---|
16 | */ |
---|
17 | |
---|
18 | #ifndef _RTEMS_SCORE_SMPIMPL_H |
---|
19 | #define _RTEMS_SCORE_SMPIMPL_H |
---|
20 | |
---|
21 | #include <rtems/score/smp.h> |
---|
22 | #include <rtems/score/percpu.h> |
---|
23 | #include <rtems/fatal.h> |
---|
24 | #include <rtems/rtems/cache.h> |
---|
25 | |
---|
26 | #ifdef __cplusplus |
---|
27 | extern "C" { |
---|
28 | #endif |
---|
29 | |
---|
30 | /** |
---|
31 | * @defgroup ScoreSMP SMP Support |
---|
32 | * |
---|
33 | * @ingroup Score |
---|
34 | * |
---|
35 | * This defines the interface of the SuperCore SMP support. |
---|
36 | * |
---|
37 | * @{ |
---|
38 | */ |
---|
39 | |
---|
40 | /** |
---|
41 | * @brief SMP message to request a processor shutdown. |
---|
42 | * |
---|
43 | * @see _SMP_Send_message(). |
---|
44 | */ |
---|
45 | #define SMP_MESSAGE_SHUTDOWN 0x1UL |
---|
46 | |
---|
47 | /** |
---|
48 | * @brief SMP message to request a test handler invocation. |
---|
49 | * |
---|
50 | * @see _SMP_Send_message(). |
---|
51 | */ |
---|
52 | #define SMP_MESSAGE_TEST 0x2UL |
---|
53 | |
---|
54 | /** |
---|
55 | * @brief SMP message to request a cache manager invocation. |
---|
56 | * |
---|
57 | * @see _SMP_Send_message(). |
---|
58 | */ |
---|
59 | #define SMP_MESSAGE_CACHE_MANAGER 0x4UL |
---|
60 | |
---|
61 | /** |
---|
62 | * @brief SMP fatal codes. |
---|
63 | */ |
---|
64 | typedef enum { |
---|
65 | SMP_FATAL_BOOT_PROCESSOR_NOT_ASSIGNED_TO_SCHEDULER, |
---|
66 | SMP_FATAL_MANDATORY_PROCESSOR_NOT_PRESENT, |
---|
67 | SMP_FATAL_MULTITASKING_START_ON_INVALID_PROCESSOR, |
---|
68 | SMP_FATAL_MULTITASKING_START_ON_UNASSIGNED_PROCESSOR, |
---|
69 | SMP_FATAL_SHUTDOWN, |
---|
70 | SMP_FATAL_SHUTDOWN_RESPONSE, |
---|
71 | SMP_FATAL_START_OF_MANDATORY_PROCESSOR_FAILED |
---|
72 | } SMP_Fatal_code; |
---|
73 | |
---|
74 | static inline void _SMP_Fatal( SMP_Fatal_code code ) |
---|
75 | { |
---|
76 | _Terminate( RTEMS_FATAL_SOURCE_SMP, false, code ); |
---|
77 | } |
---|
78 | |
---|
79 | /** |
---|
80 | * @brief Initialize SMP Handler |
---|
81 | * |
---|
82 | * This method initialize the SMP Handler. |
---|
83 | */ |
---|
84 | #if defined( RTEMS_SMP ) |
---|
85 | void _SMP_Handler_initialize( void ); |
---|
86 | #else |
---|
87 | #define _SMP_Handler_initialize() \ |
---|
88 | do { } while ( 0 ) |
---|
89 | #endif |
---|
90 | |
---|
91 | #if defined( RTEMS_SMP ) |
---|
92 | |
---|
93 | /** |
---|
94 | * @brief Performs high-level initialization of a secondary processor and runs |
---|
95 | * the application threads. |
---|
96 | * |
---|
97 | * The low-level initialization code must call this function to hand over the |
---|
98 | * control of this processor to RTEMS. Interrupts must be disabled. It must |
---|
99 | * be possible to send inter-processor interrupts to this processor. Since |
---|
100 | * interrupts are disabled the inter-processor interrupt delivery is postponed |
---|
101 | * until interrupts are enabled the first time. Interrupts are enabled during |
---|
102 | * the execution begin of threads in case they have interrupt level zero (this |
---|
103 | * is the default). |
---|
104 | * |
---|
105 | * The pre-requisites for the call to this function are |
---|
106 | * - disabled interrupts, |
---|
107 | * - delivery of inter-processor interrupts is possible, |
---|
108 | * - a valid stack pointer and enough stack space, |
---|
109 | * - a valid code memory, and |
---|
110 | * - a valid BSS section. |
---|
111 | * |
---|
112 | * This function must not be called by the main processor. The main processor |
---|
113 | * uses _Thread_Start_multitasking() instead. |
---|
114 | * |
---|
115 | * This function does not return to the caller. |
---|
116 | */ |
---|
117 | void _SMP_Start_multitasking_on_secondary_processor( void ) |
---|
118 | RTEMS_COMPILER_NO_RETURN_ATTRIBUTE; |
---|
119 | |
---|
120 | typedef void ( *SMP_Test_message_handler )( Per_CPU_Control *cpu_self ); |
---|
121 | |
---|
122 | extern SMP_Test_message_handler _SMP_Test_message_handler; |
---|
123 | |
---|
124 | /** |
---|
125 | * @brief Sets the handler for test messages. |
---|
126 | * |
---|
127 | * This handler can be used to test the inter-processor interrupt |
---|
128 | * implementation. |
---|
129 | */ |
---|
130 | static inline void _SMP_Set_test_message_handler( |
---|
131 | SMP_Test_message_handler handler |
---|
132 | ) |
---|
133 | { |
---|
134 | _SMP_Test_message_handler = handler; |
---|
135 | } |
---|
136 | |
---|
137 | /** |
---|
138 | * @brief Handles cache invalidation/flush requests from a remote processor. |
---|
139 | * |
---|
140 | */ |
---|
141 | void _SMP_Cache_manager_message_handler( void ); |
---|
142 | |
---|
143 | /** |
---|
144 | * @brief Interrupt handler for inter-processor interrupts. |
---|
145 | */ |
---|
146 | static inline void _SMP_Inter_processor_interrupt_handler( void ) |
---|
147 | { |
---|
148 | Per_CPU_Control *cpu_self = _Per_CPU_Get(); |
---|
149 | |
---|
150 | if ( _Atomic_Load_ulong( &cpu_self->message, ATOMIC_ORDER_RELAXED ) != 0 ) { |
---|
151 | unsigned long message = _Atomic_Exchange_ulong( |
---|
152 | &cpu_self->message, |
---|
153 | 0UL, |
---|
154 | ATOMIC_ORDER_RELAXED |
---|
155 | ); |
---|
156 | |
---|
157 | if ( ( message & SMP_MESSAGE_SHUTDOWN ) != 0 ) { |
---|
158 | _SMP_Fatal( SMP_FATAL_SHUTDOWN_RESPONSE ); |
---|
159 | /* does not continue past here */ |
---|
160 | } |
---|
161 | |
---|
162 | if ( ( message & SMP_MESSAGE_TEST ) != 0 ) { |
---|
163 | ( *_SMP_Test_message_handler )( cpu_self ); |
---|
164 | } |
---|
165 | |
---|
166 | if ( ( message & SMP_MESSAGE_CACHE_MANAGER ) != 0 ) { |
---|
167 | _SMP_Cache_manager_message_handler(); |
---|
168 | } |
---|
169 | |
---|
170 | } |
---|
171 | } |
---|
172 | |
---|
173 | /** |
---|
174 | * @brief Returns true, if the processor with the specified index should be |
---|
175 | * started. |
---|
176 | * |
---|
177 | * @param[in] cpu_index The processor index. |
---|
178 | * |
---|
179 | * @retval true The processor should be started. |
---|
180 | * @retval false Otherwise. |
---|
181 | */ |
---|
182 | bool _SMP_Should_start_processor( uint32_t cpu_index ); |
---|
183 | |
---|
184 | /** |
---|
185 | * @brief Sends a SMP message to a processor. |
---|
186 | * |
---|
187 | * The target processor may be the sending processor. |
---|
188 | * |
---|
189 | * @param[in] cpu_index The target processor of the message. |
---|
190 | * @param[in] message The message. |
---|
191 | */ |
---|
192 | void _SMP_Send_message( uint32_t cpu_index, unsigned long message ); |
---|
193 | |
---|
194 | /** |
---|
195 | * @brief Request of others CPUs. |
---|
196 | * |
---|
197 | * This method is invoked by RTEMS when it needs to make a request |
---|
198 | * of the other CPUs. It should be implemented using some type of |
---|
199 | * interprocessor interrupt. CPUs not including the originating |
---|
200 | * CPU should receive the message. |
---|
201 | * |
---|
202 | * @param [in] message is message to send |
---|
203 | */ |
---|
204 | void _SMP_Send_message_broadcast( |
---|
205 | unsigned long message |
---|
206 | ); |
---|
207 | |
---|
208 | /** |
---|
209 | * @brief Sends a SMP message to a set of processors. |
---|
210 | * |
---|
211 | * The sending processor may be part of the set. |
---|
212 | * |
---|
213 | * @param[in] setsize The size of the set of target processors of the message. |
---|
214 | * @param[in] cpus The set of target processors of the message. |
---|
215 | * @param[in] message The message. |
---|
216 | */ |
---|
217 | void _SMP_Send_message_multicast( |
---|
218 | const size_t setsize, |
---|
219 | const cpu_set_t *cpus, |
---|
220 | unsigned long message |
---|
221 | ); |
---|
222 | |
---|
223 | #endif /* defined( RTEMS_SMP ) */ |
---|
224 | |
---|
225 | /** |
---|
226 | * @brief Requests a multitasking start on all configured and available |
---|
227 | * processors. |
---|
228 | */ |
---|
229 | #if defined( RTEMS_SMP ) |
---|
230 | void _SMP_Request_start_multitasking( void ); |
---|
231 | #else |
---|
232 | #define _SMP_Request_start_multitasking() \ |
---|
233 | do { } while ( 0 ) |
---|
234 | #endif |
---|
235 | |
---|
236 | /** |
---|
237 | * @brief Requests a shutdown of all processors. |
---|
238 | * |
---|
239 | * This function is a part of the system termination procedure. |
---|
240 | * |
---|
241 | * @see _Terminate(). |
---|
242 | */ |
---|
243 | #if defined( RTEMS_SMP ) |
---|
244 | void _SMP_Request_shutdown( void ); |
---|
245 | #else |
---|
246 | #define _SMP_Request_shutdown() \ |
---|
247 | do { } while ( 0 ) |
---|
248 | #endif |
---|
249 | |
---|
250 | /** @} */ |
---|
251 | |
---|
252 | #ifdef __cplusplus |
---|
253 | } |
---|
254 | #endif |
---|
255 | |
---|
256 | #endif |
---|
257 | /* end of include file */ |
---|