source: rtems/cpukit/rtems/src/semmp.c @ 453bb4b

5
Last change on this file since 453bb4b was 453bb4b, checked in by Sebastian Huber <sebastian.huber@…>, on 12/29/19 at 16:43:46

rtems: Fix MPCI initialization

Update #2408.

  • Property mode set to 100644
File size: 8.1 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Semaphore MP Support
5 *  @ingroup ClassicSEM
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2008.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/rtems/semimpl.h>
22#include <rtems/rtems/optionsimpl.h>
23#include <rtems/rtems/statusimpl.h>
24#include <rtems/sysinit.h>
25
26RTEMS_STATIC_ASSERT(
27  sizeof(Semaphore_MP_Packet) <= MP_PACKET_MINIMUM_PACKET_SIZE,
28  Semaphore_MP_Packet
29);
30
31static Semaphore_MP_Packet *_Semaphore_MP_Get_packet( void )
32{
33  return (Semaphore_MP_Packet *) _MPCI_Get_packet();
34}
35
36void _Semaphore_MP_Send_process_packet (
37  Semaphore_MP_Remote_operations  operation,
38  Objects_Id                      semaphore_id,
39  rtems_name                      name,
40  Objects_Id                      proxy_id
41)
42{
43  Semaphore_MP_Packet *the_packet;
44  uint32_t             node;
45
46  switch ( operation ) {
47
48    case SEMAPHORE_MP_ANNOUNCE_CREATE:
49    case SEMAPHORE_MP_ANNOUNCE_DELETE:
50    case SEMAPHORE_MP_EXTRACT_PROXY:
51
52      the_packet                    = _Semaphore_MP_Get_packet();
53      the_packet->Prefix.the_class  = MP_PACKET_SEMAPHORE;
54      the_packet->Prefix.length     = sizeof ( Semaphore_MP_Packet );
55      the_packet->Prefix.to_convert = sizeof ( Semaphore_MP_Packet );
56      the_packet->operation         = operation;
57      the_packet->Prefix.id         = semaphore_id;
58      the_packet->name              = name;
59      the_packet->proxy_id          = proxy_id;
60
61      if ( operation == SEMAPHORE_MP_EXTRACT_PROXY )
62         node = _Objects_Get_node( semaphore_id );
63      else
64         node = MPCI_ALL_NODES;
65
66      _MPCI_Send_process_packet( node, &the_packet->Prefix );
67      break;
68
69    case SEMAPHORE_MP_OBTAIN_REQUEST:
70    case SEMAPHORE_MP_OBTAIN_RESPONSE:
71    case SEMAPHORE_MP_RELEASE_REQUEST:
72    case SEMAPHORE_MP_RELEASE_RESPONSE:
73      break;
74  }
75}
76
77static rtems_status_code _Semaphore_MP_Send_request_packet(
78  Objects_Id                     semaphore_id,
79  rtems_option                   option_set,
80  rtems_interval                 timeout,
81  Semaphore_MP_Remote_operations operation
82)
83{
84  Semaphore_MP_Packet *the_packet;
85  Status_Control       status;
86
87  if ( !_Semaphore_MP_Is_remote( semaphore_id ) ) {
88    return RTEMS_INVALID_ID;
89  }
90
91  switch ( operation ) {
92
93    case SEMAPHORE_MP_OBTAIN_REQUEST:
94    case SEMAPHORE_MP_RELEASE_REQUEST:
95
96      the_packet                    = _Semaphore_MP_Get_packet();
97      the_packet->Prefix.the_class  = MP_PACKET_SEMAPHORE;
98      the_packet->Prefix.length     = sizeof ( Semaphore_MP_Packet );
99      the_packet->Prefix.to_convert = sizeof ( Semaphore_MP_Packet );
100      if ( ! _Options_Is_no_wait(option_set))
101          the_packet->Prefix.timeout = timeout;
102
103      the_packet->operation         = operation;
104      the_packet->Prefix.id         = semaphore_id;
105      the_packet->option_set        = option_set;
106
107      status = _MPCI_Send_request_packet(
108        _Objects_Get_node( semaphore_id ),
109        &the_packet->Prefix,
110        STATES_WAITING_FOR_SEMAPHORE
111      );
112      return _Status_Get( status );
113
114    case SEMAPHORE_MP_ANNOUNCE_CREATE:
115    case SEMAPHORE_MP_ANNOUNCE_DELETE:
116    case SEMAPHORE_MP_EXTRACT_PROXY:
117    case SEMAPHORE_MP_OBTAIN_RESPONSE:
118    case SEMAPHORE_MP_RELEASE_RESPONSE:
119      break;
120
121  }
122  /*
123   *  The following line is included to satisfy compilers which
124   *  produce warnings when a function does not end with a return.
125   */
126  return RTEMS_SUCCESSFUL;
127}
128
129rtems_status_code _Semaphore_MP_Obtain(
130  rtems_id        id,
131  rtems_option    option_set,
132  rtems_interval  timeout
133)
134{
135  return _Semaphore_MP_Send_request_packet(
136    id,
137    option_set,
138    timeout,
139    SEMAPHORE_MP_OBTAIN_REQUEST
140  );
141}
142
143rtems_status_code _Semaphore_MP_Release( rtems_id id )
144{
145  return _Semaphore_MP_Send_request_packet(
146    id,
147    0,
148    MPCI_DEFAULT_TIMEOUT,
149    SEMAPHORE_MP_RELEASE_REQUEST
150  );
151}
152
153static void _Semaphore_MP_Send_response_packet (
154  Semaphore_MP_Remote_operations  operation,
155  Objects_Id                      semaphore_id,
156  Thread_Control                 *the_thread
157)
158{
159  Semaphore_MP_Packet *the_packet;
160
161  switch ( operation ) {
162
163    case SEMAPHORE_MP_OBTAIN_RESPONSE:
164    case SEMAPHORE_MP_RELEASE_RESPONSE:
165
166      the_packet = ( Semaphore_MP_Packet *) the_thread->receive_packet;
167
168/*
169 *  The packet being returned already contains the class, length, and
170 *  to_convert fields, therefore they are not set in this routine.
171 */
172      the_packet->operation = operation;
173      the_packet->Prefix.id = the_packet->Prefix.source_tid;
174
175      _MPCI_Send_response_packet(
176        _Objects_Get_node( the_packet->Prefix.source_tid ),
177        &the_packet->Prefix
178      );
179      break;
180
181    case SEMAPHORE_MP_ANNOUNCE_CREATE:
182    case SEMAPHORE_MP_ANNOUNCE_DELETE:
183    case SEMAPHORE_MP_EXTRACT_PROXY:
184    case SEMAPHORE_MP_OBTAIN_REQUEST:
185    case SEMAPHORE_MP_RELEASE_REQUEST:
186      break;
187
188  }
189}
190
191static void _Semaphore_MP_Process_packet (
192  rtems_packet_prefix  *the_packet_prefix
193)
194{
195  Semaphore_MP_Packet *the_packet;
196  Thread_Control      *the_thread;
197
198  the_packet = (Semaphore_MP_Packet *) the_packet_prefix;
199
200  switch ( the_packet->operation ) {
201
202    case SEMAPHORE_MP_ANNOUNCE_CREATE:
203
204      _Objects_MP_Allocate_and_open(
205        &_Semaphore_Information,
206        the_packet->name,
207        the_packet->Prefix.id,
208        true
209      );
210
211      _MPCI_Return_packet( the_packet_prefix );
212      break;
213
214    case SEMAPHORE_MP_ANNOUNCE_DELETE:
215
216      _Objects_MP_Close( &_Semaphore_Information, the_packet->Prefix.id );
217
218      _MPCI_Return_packet( the_packet_prefix );
219      break;
220
221    case SEMAPHORE_MP_EXTRACT_PROXY:
222
223      the_thread = _Thread_MP_Find_proxy( the_packet->proxy_id );
224
225      if ( ! _Thread_Is_null( the_thread ) )
226        _Thread_queue_Extract( the_thread );
227
228      _MPCI_Return_packet( the_packet_prefix );
229      break;
230
231    case SEMAPHORE_MP_OBTAIN_REQUEST:
232
233      the_packet->Prefix.return_code = rtems_semaphore_obtain(
234        the_packet->Prefix.id,
235        the_packet->option_set,
236        the_packet->Prefix.timeout
237      );
238
239      if ( the_packet->Prefix.return_code != RTEMS_PROXY_BLOCKING )
240        _Semaphore_MP_Send_response_packet(
241           SEMAPHORE_MP_OBTAIN_RESPONSE,
242           the_packet->Prefix.id,
243           _Thread_Executing
244        );
245      break;
246
247    case SEMAPHORE_MP_OBTAIN_RESPONSE:
248    case SEMAPHORE_MP_RELEASE_RESPONSE:
249
250      the_thread = _MPCI_Process_response( the_packet_prefix );
251
252      _MPCI_Return_packet( the_packet_prefix );
253      break;
254
255    case SEMAPHORE_MP_RELEASE_REQUEST:
256
257      the_packet->Prefix.return_code = rtems_semaphore_release(
258        the_packet->Prefix.id
259      );
260
261      _Semaphore_MP_Send_response_packet(
262        SEMAPHORE_MP_RELEASE_RESPONSE,
263        the_packet->Prefix.id,
264        _Thread_Executing
265      );
266      break;
267  }
268}
269
270void _Semaphore_MP_Send_object_was_deleted (
271  Thread_Control *the_proxy,
272  Objects_Id      mp_id
273)
274{
275  the_proxy->receive_packet->return_code = RTEMS_OBJECT_WAS_DELETED;
276
277  _Semaphore_MP_Send_response_packet(
278    SEMAPHORE_MP_OBTAIN_RESPONSE,
279    mp_id,
280    the_proxy
281  );
282
283}
284
285void _Semaphore_MP_Send_extract_proxy (
286  Thread_Control *the_thread,
287  Objects_Id      id
288)
289{
290  _Semaphore_MP_Send_process_packet(
291    SEMAPHORE_MP_EXTRACT_PROXY,
292    id,
293    (rtems_name) 0,
294    the_thread->Object.id
295  );
296
297}
298
299void  _Semaphore_Core_mutex_mp_support (
300  Thread_Control *the_thread,
301  Objects_Id      id
302)
303{
304  the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL;
305
306  _Semaphore_MP_Send_response_packet(
307     SEMAPHORE_MP_OBTAIN_RESPONSE,
308     id,
309     the_thread
310   );
311}
312
313void  _Semaphore_Core_semaphore_mp_support (
314  Thread_Control *the_thread,
315  Objects_Id      id
316)
317{
318  the_thread->receive_packet->return_code = RTEMS_SUCCESSFUL;
319
320  _Semaphore_MP_Send_response_packet(
321     SEMAPHORE_MP_OBTAIN_RESPONSE,
322     id,
323     the_thread
324   );
325}
326
327static void _Semaphore_MP_Initialize( void )
328{
329  _MPCI_Register_packet_processor(
330    MP_PACKET_SEMAPHORE,
331    _Semaphore_MP_Process_packet
332  );
333}
334
335RTEMS_SYSINIT_ITEM(
336  _Semaphore_MP_Initialize,
337  RTEMS_SYSINIT_CLASSIC_SEMAPHORE_MP,
338  RTEMS_SYSINIT_ORDER_MIDDLE
339);
Note: See TracBrowser for help on using the repository browser.