source: rtems/cpukit/score/include/rtems/score/smpimpl.h @ 26c142e5

4.115
Last change on this file since 26c142e5 was 26c142e5, checked in by Sebastian Huber <sebastian.huber@…>, on 04/17/15 at 10:05:16

score: Refactor SMP cache manager support

  • Property mode set to 100644
File size: 6.7 KB
Line 
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
27extern "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 multicast action.
56 *
57 * @see _SMP_Send_message().
58 */
59#define SMP_MESSAGE_MULTICAST_ACTION 0x4UL
60
61/**
62 * @brief SMP fatal codes.
63 */
64typedef 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
74static 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 */
117void _SMP_Start_multitasking_on_secondary_processor( void )
118  RTEMS_COMPILER_NO_RETURN_ATTRIBUTE;
119
120typedef void ( *SMP_Test_message_handler )( Per_CPU_Control *cpu_self );
121
122extern 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 */
130static 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 Processes all pending multicast actions.
139 */
140void _SMP_Multicast_actions_process( void );
141
142/**
143 * @brief Interrupt handler for inter-processor interrupts.
144 */
145static inline void _SMP_Inter_processor_interrupt_handler( void )
146{
147  Per_CPU_Control *cpu_self = _Per_CPU_Get();
148
149  if ( _Atomic_Load_ulong( &cpu_self->message, ATOMIC_ORDER_RELAXED ) != 0 ) {
150    unsigned long message = _Atomic_Exchange_ulong(
151      &cpu_self->message,
152      0UL,
153      ATOMIC_ORDER_RELAXED
154    );
155
156    if ( ( message & SMP_MESSAGE_SHUTDOWN ) != 0 ) {
157      _SMP_Fatal( SMP_FATAL_SHUTDOWN_RESPONSE );
158      /* does not continue past here */
159    }
160
161    if ( ( message & SMP_MESSAGE_TEST ) != 0 ) {
162      ( *_SMP_Test_message_handler )( cpu_self );
163    }
164
165    if ( ( message & SMP_MESSAGE_MULTICAST_ACTION ) != 0 ) {
166      _SMP_Multicast_actions_process();
167    }
168  }
169}
170
171/**
172 *  @brief Returns true, if the processor with the specified index should be
173 *  started.
174 *
175 *  @param[in] cpu_index The processor index.
176 *
177 *  @retval true The processor should be started.
178 *  @retval false Otherwise.
179 */
180bool _SMP_Should_start_processor( uint32_t cpu_index );
181
182/**
183 *  @brief Sends a SMP message to a processor.
184 *
185 *  The target processor may be the sending processor.
186 *
187 *  @param[in] cpu_index The target processor of the message.
188 *  @param[in] message The message.
189 */
190void _SMP_Send_message( uint32_t cpu_index, unsigned long message );
191
192/**
193 *  @brief Request of others CPUs.
194 *
195 *  This method is invoked by RTEMS when it needs to make a request
196 *  of the other CPUs.  It should be implemented using some type of
197 *  interprocessor interrupt. CPUs not including the originating
198 *  CPU should receive the message.
199 *
200 *  @param [in] message is message to send
201 */
202void _SMP_Send_message_broadcast(
203  unsigned long message
204);
205
206/**
207 *  @brief Sends a SMP message to a set of processors.
208 *
209 *  The sending processor may be part of the set.
210 *
211 *  @param[in] setsize The size of the set of target processors of the message.
212 *  @param[in] cpus The set of target processors of the message.
213 *  @param[in] message The message.
214 */
215void _SMP_Send_message_multicast(
216  const size_t setsize,
217  const cpu_set_t *cpus,
218  unsigned long message
219);
220
221typedef void ( *SMP_Multicast_action_handler )( void *arg );
222
223/**
224 *  @brief Initiates a SMP multicast action to a set of processors.
225 *
226 *  The current processor may be part of the set.
227 *
228 *  @param[in] setsize The size of the set of target processors of the message.
229 *  @param[in] cpus The set of target processors of the message.
230 *  @param[in] handler The multicast action handler.
231 *  @param[in] arg The multicast action argument.
232 */
233void _SMP_Multicast_action(
234  const size_t setsize,
235  const cpu_set_t *cpus,
236  SMP_Multicast_action_handler handler,
237  void *arg
238);
239
240#endif /* defined( RTEMS_SMP ) */
241
242/**
243 * @brief Requests a multitasking start on all configured and available
244 * processors.
245 */
246#if defined( RTEMS_SMP )
247  void _SMP_Request_start_multitasking( void );
248#else
249  #define _SMP_Request_start_multitasking() \
250    do { } while ( 0 )
251#endif
252
253/**
254 * @brief Requests a shutdown of all processors.
255 *
256 * This function is a part of the system termination procedure.
257 *
258 * @see _Terminate().
259 */
260#if defined( RTEMS_SMP )
261  void _SMP_Request_shutdown( void );
262#else
263  #define _SMP_Request_shutdown() \
264    do { } while ( 0 )
265#endif
266
267/** @} */
268
269#ifdef __cplusplus
270}
271#endif
272
273#endif
274/* end of include file */
Note: See TracBrowser for help on using the repository browser.