1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup RTEMSScoreSMPImpl |
---|
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/score/processormask.h> |
---|
24 | #include <rtems/fatal.h> |
---|
25 | #include <rtems/rtems/cache.h> |
---|
26 | |
---|
27 | #ifdef __cplusplus |
---|
28 | extern "C" { |
---|
29 | #endif |
---|
30 | |
---|
31 | /** |
---|
32 | * @addtogroup RTEMSScoreSMP |
---|
33 | * |
---|
34 | * This defines the interface of the SuperCore SMP support. |
---|
35 | * |
---|
36 | * @{ |
---|
37 | */ |
---|
38 | |
---|
39 | /** |
---|
40 | * @brief SMP message to request a processor shutdown. |
---|
41 | * |
---|
42 | * @see _SMP_Send_message(). |
---|
43 | */ |
---|
44 | #define SMP_MESSAGE_SHUTDOWN 0x1UL |
---|
45 | |
---|
46 | /** |
---|
47 | * @brief SMP message to perform per-processor jobs. |
---|
48 | * |
---|
49 | * @see _SMP_Send_message(). |
---|
50 | */ |
---|
51 | #define SMP_MESSAGE_PERFORM_JOBS 0x2UL |
---|
52 | |
---|
53 | /** |
---|
54 | * @brief SMP fatal codes. |
---|
55 | */ |
---|
56 | typedef enum { |
---|
57 | SMP_FATAL_BOOT_PROCESSOR_NOT_ASSIGNED_TO_SCHEDULER, |
---|
58 | SMP_FATAL_MANDATORY_PROCESSOR_NOT_PRESENT, |
---|
59 | SMP_FATAL_MULTITASKING_START_ON_INVALID_PROCESSOR, |
---|
60 | SMP_FATAL_MULTITASKING_START_ON_UNASSIGNED_PROCESSOR, |
---|
61 | SMP_FATAL_SHUTDOWN, |
---|
62 | SMP_FATAL_SHUTDOWN_RESPONSE, |
---|
63 | SMP_FATAL_START_OF_MANDATORY_PROCESSOR_FAILED, |
---|
64 | SMP_FATAL_SCHEDULER_PIN_OR_UNPIN_NOT_SUPPORTED, |
---|
65 | SMP_FATAL_WRONG_CPU_STATE_TO_PERFORM_JOBS |
---|
66 | } SMP_Fatal_code; |
---|
67 | |
---|
68 | /** |
---|
69 | * @brief Terminates with the given code. |
---|
70 | * |
---|
71 | * @param code The code for the termination. |
---|
72 | */ |
---|
73 | static inline void _SMP_Fatal( SMP_Fatal_code code ) |
---|
74 | { |
---|
75 | _Terminate( RTEMS_FATAL_SOURCE_SMP, code ); |
---|
76 | } |
---|
77 | |
---|
78 | /** |
---|
79 | * @brief Initializes SMP Handler |
---|
80 | * |
---|
81 | * This method initialize the SMP Handler. |
---|
82 | */ |
---|
83 | #if defined( RTEMS_SMP ) |
---|
84 | void _SMP_Handler_initialize( void ); |
---|
85 | #else |
---|
86 | #define _SMP_Handler_initialize() \ |
---|
87 | do { } while ( 0 ) |
---|
88 | #endif |
---|
89 | |
---|
90 | #if defined( RTEMS_SMP ) |
---|
91 | |
---|
92 | /** |
---|
93 | * @brief Set of online processors. |
---|
94 | * |
---|
95 | * A processor is online if was started during system initialization. In this |
---|
96 | * case its corresponding bit in the mask is set. |
---|
97 | * |
---|
98 | * @see _SMP_Handler_initialize(). |
---|
99 | */ |
---|
100 | extern Processor_mask _SMP_Online_processors; |
---|
101 | |
---|
102 | /** |
---|
103 | * @brief Performs high-level initialization of a secondary processor and runs |
---|
104 | * the application threads. |
---|
105 | * |
---|
106 | * The low-level initialization code must call this function to hand over the |
---|
107 | * control of this processor to RTEMS. Interrupts must be disabled. It must |
---|
108 | * be possible to send inter-processor interrupts to this processor. Since |
---|
109 | * interrupts are disabled the inter-processor interrupt delivery is postponed |
---|
110 | * until interrupts are enabled the first time. Interrupts are enabled during |
---|
111 | * the execution begin of threads in case they have interrupt level zero (this |
---|
112 | * is the default). |
---|
113 | * |
---|
114 | * The pre-requisites for the call to this function are |
---|
115 | * - disabled interrupts, |
---|
116 | * - delivery of inter-processor interrupts is possible, |
---|
117 | * - a valid stack pointer and enough stack space, |
---|
118 | * - a valid code memory, and |
---|
119 | * - a valid BSS section. |
---|
120 | * |
---|
121 | * This function must not be called by the main processor. The main processor |
---|
122 | * uses _Thread_Start_multitasking() instead. |
---|
123 | * |
---|
124 | * This function does not return to the caller. |
---|
125 | * |
---|
126 | * @param cpu_self The current processor control. |
---|
127 | */ |
---|
128 | void _SMP_Start_multitasking_on_secondary_processor( |
---|
129 | Per_CPU_Control *cpu_self |
---|
130 | ) RTEMS_NO_RETURN; |
---|
131 | |
---|
132 | /** |
---|
133 | * @brief Interrupts handler for inter-processor interrupts. |
---|
134 | * |
---|
135 | * @param[in, out] cpu_self The cpu control for the operation. |
---|
136 | * |
---|
137 | * @return The received message. |
---|
138 | */ |
---|
139 | static inline long unsigned _SMP_Inter_processor_interrupt_handler( |
---|
140 | Per_CPU_Control *cpu_self |
---|
141 | ) |
---|
142 | { |
---|
143 | unsigned long message; |
---|
144 | |
---|
145 | /* |
---|
146 | * In the common case the inter-processor interrupt is issued to carry out a |
---|
147 | * thread dispatch. |
---|
148 | */ |
---|
149 | cpu_self->dispatch_necessary = true; |
---|
150 | |
---|
151 | message = _Atomic_Exchange_ulong( |
---|
152 | &cpu_self->message, |
---|
153 | 0, |
---|
154 | ATOMIC_ORDER_ACQUIRE |
---|
155 | ); |
---|
156 | |
---|
157 | if ( RTEMS_PREDICT_FALSE( message != 0 ) ) { |
---|
158 | if ( ( message & SMP_MESSAGE_SHUTDOWN ) != 0 ) { |
---|
159 | _SMP_Fatal( SMP_FATAL_SHUTDOWN_RESPONSE ); |
---|
160 | /* does not continue past here */ |
---|
161 | } |
---|
162 | |
---|
163 | if ( ( message & SMP_MESSAGE_PERFORM_JOBS ) != 0 ) { |
---|
164 | _Per_CPU_Perform_jobs( cpu_self ); |
---|
165 | } |
---|
166 | } |
---|
167 | |
---|
168 | return message; |
---|
169 | } |
---|
170 | |
---|
171 | /** |
---|
172 | * @brief Checks if the processor with the specified index should be started. |
---|
173 | * |
---|
174 | * @param cpu_index The processor index. |
---|
175 | * |
---|
176 | * @retval true The processor should be started. |
---|
177 | * @retval false The processor should not be started. |
---|
178 | */ |
---|
179 | bool _SMP_Should_start_processor( uint32_t cpu_index ); |
---|
180 | |
---|
181 | /** |
---|
182 | * @brief Sends an SMP message to a processor. |
---|
183 | * |
---|
184 | * The target processor may be the sending processor. |
---|
185 | * |
---|
186 | * @param cpu_index The target processor of the message. |
---|
187 | * @param message The message to send. |
---|
188 | */ |
---|
189 | void _SMP_Send_message( uint32_t cpu_index, unsigned long message ); |
---|
190 | |
---|
191 | /** |
---|
192 | * @brief Sends an SMP message to all other online processors. |
---|
193 | * |
---|
194 | * @param message The message to send. |
---|
195 | */ |
---|
196 | void _SMP_Send_message_broadcast( |
---|
197 | unsigned long message |
---|
198 | ); |
---|
199 | |
---|
200 | /** |
---|
201 | * @brief Sends an SMP message to a set of processors. |
---|
202 | * |
---|
203 | * The sending processor may be part of the set. |
---|
204 | * |
---|
205 | * @param targets The set of processors to send the message. |
---|
206 | * @param message The message to send. |
---|
207 | */ |
---|
208 | void _SMP_Send_message_multicast( |
---|
209 | const Processor_mask *targets, |
---|
210 | unsigned long message |
---|
211 | ); |
---|
212 | |
---|
213 | typedef void ( *SMP_Action_handler )( void *arg ); |
---|
214 | |
---|
215 | /** |
---|
216 | * @brief Initiates an SMP multicast action to the set of target processors. |
---|
217 | * |
---|
218 | * The current processor may be part of the set. The caller must ensure that |
---|
219 | * no thread dispatch can happen during the call of this function, otherwise |
---|
220 | * the behaviour is undefined. In case a target processor is in a wrong state |
---|
221 | * to process per-processor jobs, then this function results in an |
---|
222 | * SMP_FATAL_WRONG_CPU_STATE_TO_PERFORM_JOBS fatal SMP error. |
---|
223 | * |
---|
224 | * @param targets The set of target processors for the action. |
---|
225 | * @param handler The multicast action handler. |
---|
226 | * @param arg The multicast action argument. |
---|
227 | */ |
---|
228 | void _SMP_Multicast_action( |
---|
229 | const Processor_mask *targets, |
---|
230 | SMP_Action_handler handler, |
---|
231 | void *arg |
---|
232 | ); |
---|
233 | |
---|
234 | /** |
---|
235 | * @brief Initiates an SMP multicast action to the set of all online |
---|
236 | * processors. |
---|
237 | * |
---|
238 | * Simply calls _SMP_Multicast_action() with _SMP_Get_online_processors() as |
---|
239 | * the target processor set. |
---|
240 | * |
---|
241 | * @param handler The multicast action handler. |
---|
242 | * @param arg The multicast action argument. |
---|
243 | */ |
---|
244 | void _SMP_Broadcast_action( |
---|
245 | SMP_Action_handler handler, |
---|
246 | void *arg |
---|
247 | ); |
---|
248 | |
---|
249 | /** |
---|
250 | * @brief Initiates an SMP multicast action to the set of all online |
---|
251 | * processors excluding the current processor. |
---|
252 | * |
---|
253 | * Simply calls _SMP_Multicast_action() with _SMP_Get_online_processors() as |
---|
254 | * the target processor set excluding the current processor. |
---|
255 | * |
---|
256 | * @param handler The multicast action handler. |
---|
257 | * @param arg The multicast action argument. |
---|
258 | */ |
---|
259 | void _SMP_Othercast_action( |
---|
260 | SMP_Action_handler handler, |
---|
261 | void *arg |
---|
262 | ); |
---|
263 | |
---|
264 | #endif /* defined( RTEMS_SMP ) */ |
---|
265 | |
---|
266 | /** |
---|
267 | * @brief Requests a multitasking start on all configured and available |
---|
268 | * processors. |
---|
269 | */ |
---|
270 | #if defined( RTEMS_SMP ) |
---|
271 | void _SMP_Request_start_multitasking( void ); |
---|
272 | #else |
---|
273 | #define _SMP_Request_start_multitasking() \ |
---|
274 | do { } while ( 0 ) |
---|
275 | #endif |
---|
276 | |
---|
277 | /** |
---|
278 | * @brief Requests a shutdown of all processors. |
---|
279 | * |
---|
280 | * This function is a part of the system termination procedure. |
---|
281 | * |
---|
282 | * @see _Terminate(). |
---|
283 | */ |
---|
284 | #if defined( RTEMS_SMP ) |
---|
285 | void _SMP_Request_shutdown( void ); |
---|
286 | #else |
---|
287 | #define _SMP_Request_shutdown() \ |
---|
288 | do { } while ( 0 ) |
---|
289 | #endif |
---|
290 | |
---|
291 | /** |
---|
292 | * @brief Gets all online processors |
---|
293 | * |
---|
294 | * @return The processor mask with all online processors. |
---|
295 | */ |
---|
296 | RTEMS_INLINE_ROUTINE const Processor_mask *_SMP_Get_online_processors( void ) |
---|
297 | { |
---|
298 | #if defined(RTEMS_SMP) |
---|
299 | return &_SMP_Online_processors; |
---|
300 | #else |
---|
301 | return &_Processor_mask_The_one_and_only; |
---|
302 | #endif |
---|
303 | } |
---|
304 | |
---|
305 | /** @} */ |
---|
306 | |
---|
307 | #ifdef __cplusplus |
---|
308 | } |
---|
309 | #endif |
---|
310 | |
---|
311 | #endif |
---|
312 | /* end of include file */ |
---|