OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [exec/] [score/] [src/] [mpci.c] - Blame information for rev 587

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*
2
 *  Multiprocessing Communications Interface (MPCI) Handler
3
 *
4
 *
5
 *  COPYRIGHT (c) 1989-1999.
6
 *  On-Line Applications Research Corporation (OAR).
7
 *
8
 *  The license and distribution terms for this file may be
9
 *  found in the file LICENSE in this distribution or at
10
 *  http://www.OARcorp.com/rtems/license.html.
11
 *
12
 *  $Id: mpci.c,v 1.2 2001-09-27 11:59:34 chris Exp $
13
 */
14
 
15
#include <rtems/system.h>
16
#include <rtems/score/cpu.h>
17
#include <rtems/score/interr.h>
18
#if defined(RTEMS_MULTIPROCESSING)
19
#include <rtems/score/mpci.h>
20
#include <rtems/score/mppkt.h>
21
#endif
22
#include <rtems/score/states.h>
23
#include <rtems/score/thread.h>
24
#include <rtems/score/threadq.h>
25
#include <rtems/score/tqdata.h>
26
#include <rtems/score/watchdog.h>
27
#include <rtems/score/sysstate.h>
28
 
29
#include <rtems/score/coresem.h>
30
 
31
/*PAGE
32
 *
33
 *  _MPCI_Handler_initialization
34
 *
35
 *  This subprogram performs the initialization necessary for this handler.
36
 */
37
 
38
void _MPCI_Handler_initialization(
39
  MPCI_Control            *users_mpci_table,
40
  unsigned32               timeout_status
41
)
42
{
43
  CORE_semaphore_Attributes    attributes;
44
 
45
  if ( _System_state_Is_multiprocessing && !users_mpci_table )
46
    _Internal_error_Occurred(
47
      INTERNAL_ERROR_CORE,
48
      TRUE,
49
      INTERNAL_ERROR_NO_MPCI
50
    );
51
 
52
  _MPCI_table = users_mpci_table;
53
 
54
  if ( !_System_state_Is_multiprocessing )
55
    return;
56
 
57
  /*
58
   *  Register the MP Process Packet routine.
59
   */
60
 
61
  _MPCI_Register_packet_processor(
62
    MP_PACKET_MPCI_INTERNAL,
63
    _MPCI_Internal_packets_Process_packet
64
  );
65
 
66
  /*
67
   *  Create the counting semaphore used by the MPCI Receive Server.
68
   */
69
 
70
  attributes.discipline = CORE_SEMAPHORE_DISCIPLINES_FIFO;
71
 
72
  _CORE_semaphore_Initialize(
73
    &_MPCI_Semaphore,
74
    OBJECTS_NO_CLASS,         /* free floating semaphore */
75
    &attributes,              /* the_semaphore_attributes */
76
    0,                        /* initial_value */
77
    NULL                      /* proxy_extract_callout */
78
  );
79
 
80
  _Thread_queue_Initialize(
81
    &_MPCI_Remote_blocked_threads,
82
    OBJECTS_NO_CLASS,
83
    THREAD_QUEUE_DISCIPLINE_FIFO,
84
    STATES_WAITING_FOR_RPC_REPLY,
85
    NULL,
86
    timeout_status
87
  );
88
}
89
 
90
/*PAGE
91
 *
92
 *  _MPCI_Create_server
93
 *
94
 *  This subprogram creates the MPCI receive server.
95
 */
96
 
97
char *_MPCI_Internal_name = "MPCI";
98
 
99
void _MPCI_Create_server( void )
100
{
101
 
102
  if ( !_System_state_Is_multiprocessing )
103
    return;
104
 
105
  /*
106
   *  Initialize the MPCI Receive Server
107
   */
108
 
109
  _MPCI_Receive_server_tcb = _Thread_Internal_allocate();
110
 
111
  _Thread_Initialize(
112
    &_Thread_Internal_information,
113
    _MPCI_Receive_server_tcb,
114
    NULL,        /* allocate the stack */
115
    MPCI_RECEIVE_SERVER_STACK_SIZE,
116
    CPU_ALL_TASKS_ARE_FP,
117
    PRIORITY_MINIMUM,
118
    FALSE,       /* no preempt */
119
    THREAD_CPU_BUDGET_ALGORITHM_NONE,
120
    NULL,        /* no budget algorithm callout */
121
    0,           /* all interrupts enabled */
122
    _MPCI_Internal_name
123
  );
124
 
125
  _Thread_Start(
126
    _MPCI_Receive_server_tcb,
127
    THREAD_START_NUMERIC,
128
    (void *) _MPCI_Receive_server,
129
    NULL,
130
 
131
  );
132
}
133
 
134
/*PAGE
135
 *
136
 *  _MPCI_Initialization
137
 *
138
 *  This subprogram initializes the MPCI driver by
139
 *  invoking the user provided MPCI initialization callout.
140
 */
141
 
142
void _MPCI_Initialization ( void )
143
{
144
  (*_MPCI_table->initialization)();
145
}
146
 
147
/*PAGE
148
 *
149
 *  _MPCI_Register_packet_processor
150
 *
151
 *  This routine registers the MPCI packet processor for the
152
 *  designated object class.
153
 */
154
 
155
void _MPCI_Register_packet_processor(
156
  MP_packet_Classes      the_class,
157
  MPCI_Packet_processor  the_packet_processor
158
 
159
)
160
{
161
  _MPCI_Packet_processors[ the_class ] = the_packet_processor;
162
}
163
 
164
/*PAGE
165
 *
166
 *  _MPCI_Get_packet
167
 *
168
 *  This subprogram obtains a packet by invoking the user provided
169
 *  MPCI get packet callout.
170
 */
171
 
172
MP_packet_Prefix *_MPCI_Get_packet ( void )
173
{
174
  MP_packet_Prefix  *the_packet;
175
 
176
  (*_MPCI_table->get_packet)( &the_packet );
177
 
178
  if ( the_packet == NULL )
179
    _Internal_error_Occurred(
180
      INTERNAL_ERROR_CORE,
181
      TRUE,
182
      INTERNAL_ERROR_OUT_OF_PACKETS
183
    );
184
 
185
  /*
186
   *  Put in a default timeout that will be used for
187
   *  all packets that do not otherwise have a timeout.
188
   */
189
 
190
  the_packet->timeout = MPCI_DEFAULT_TIMEOUT;
191
 
192
  return the_packet;
193
}
194
 
195
/*PAGE
196
 *
197
 *  _MPCI_Return_packet
198
 *
199
 *  This subprogram returns a packet by invoking the user provided
200
 *  MPCI return packet callout.
201
 */
202
 
203
void _MPCI_Return_packet (
204
  MP_packet_Prefix   *the_packet
205
)
206
{
207
  (*_MPCI_table->return_packet)( the_packet );
208
}
209
 
210
/*PAGE
211
 *
212
 *  _MPCI_Send_process_packet
213
 *
214
 *  This subprogram sends a process packet by invoking the user provided
215
 *  MPCI send callout.
216
 */
217
 
218
void _MPCI_Send_process_packet (
219
  unsigned32          destination,
220
  MP_packet_Prefix   *the_packet
221
)
222
{
223
  the_packet->source_tid = _Thread_Executing->Object.id;
224
  the_packet->to_convert =
225
     ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) /
226
       sizeof(unsigned32);
227
 
228
  (*_MPCI_table->send_packet)( destination, the_packet );
229
}
230
 
231
/*PAGE
232
 *
233
 *  _MPCI_Send_request_packet
234
 *
235
 *  This subprogram sends a request packet by invoking the user provided
236
 *  MPCI send callout.
237
 */
238
 
239
unsigned32 _MPCI_Send_request_packet (
240
  unsigned32          destination,
241
  MP_packet_Prefix   *the_packet,
242
  States_Control      extra_state
243
)
244
{
245
  the_packet->source_tid      = _Thread_Executing->Object.id;
246
  the_packet->source_priority = _Thread_Executing->current_priority;
247
  the_packet->to_convert =
248
     ( the_packet->to_convert - sizeof(MP_packet_Prefix) ) /
249
       sizeof(unsigned32);
250
 
251
  _Thread_Executing->Wait.id = the_packet->id;
252
 
253
  _Thread_Executing->Wait.queue = &_MPCI_Remote_blocked_threads;
254
 
255
  _Thread_Disable_dispatch();
256
 
257
    (*_MPCI_table->send_packet)( destination, the_packet );
258
 
259
    _Thread_queue_Enter_critical_section( &_MPCI_Remote_blocked_threads );
260
 
261
    /*
262
     *  See if we need a default timeout
263
     */
264
 
265
    if (the_packet->timeout == MPCI_DEFAULT_TIMEOUT)
266
        the_packet->timeout = _MPCI_table->default_timeout;
267
 
268
    _Thread_queue_Enqueue( &_MPCI_Remote_blocked_threads, the_packet->timeout );
269
 
270
    _Thread_Executing->current_state =
271
      _States_Set( extra_state, _Thread_Executing->current_state );
272
 
273
  _Thread_Enable_dispatch();
274
 
275
  return _Thread_Executing->Wait.return_code;
276
}
277
 
278
/*PAGE
279
 *
280
 *  _MPCI_Send_response_packet
281
 *
282
 *  This subprogram sends a response packet by invoking the user provided
283
 *  MPCI send callout.
284
 */
285
 
286
void _MPCI_Send_response_packet (
287
  unsigned32          destination,
288
  MP_packet_Prefix   *the_packet
289
)
290
{
291
  the_packet->source_tid = _Thread_Executing->Object.id;
292
 
293
  (*_MPCI_table->send_packet)( destination, the_packet );
294
}
295
 
296
/*PAGE
297
 *
298
 *  _MPCI_Receive_packet
299
 *
300
 *  This subprogram receives a packet by invoking the user provided
301
 *  MPCI receive callout.
302
 */
303
 
304
MP_packet_Prefix  *_MPCI_Receive_packet ( void )
305
{
306
  MP_packet_Prefix  *the_packet;
307
 
308
  (*_MPCI_table->receive_packet)( &the_packet );
309
 
310
  return the_packet;
311
}
312
 
313
/*PAGE
314
 *
315
 *  _MPCI_Process_response
316
 *
317
 *  This subprogram obtains a packet by invoking the user provided
318
 *  MPCI get packet callout.
319
 */
320
 
321
Thread_Control *_MPCI_Process_response (
322
  MP_packet_Prefix  *the_packet
323
)
324
{
325
  Thread_Control    *the_thread;
326
  Objects_Locations  location;
327
 
328
  the_thread = _Thread_Get( the_packet->id, &location );
329
  switch ( location ) {
330
    case OBJECTS_ERROR:
331
    case OBJECTS_REMOTE:
332
      the_thread = NULL;          /* IMPOSSIBLE */
333
      break;
334
    case OBJECTS_LOCAL:
335
      _Thread_queue_Extract( &_MPCI_Remote_blocked_threads, the_thread );
336
      the_thread->Wait.return_code = the_packet->return_code;
337
      _Thread_Unnest_dispatch();
338
    break;
339
  }
340
 
341
  return the_thread;
342
}
343
 
344
/*PAGE
345
 *
346
 *  _MPCI_Receive_server
347
 *
348
 */
349
 
350
Thread _MPCI_Receive_server(
351
  unsigned32 ignored
352
)
353
{
354
 
355
  MP_packet_Prefix         *the_packet;
356
  MPCI_Packet_processor     the_function;
357
  Thread_Control           *executing;
358
 
359
  executing = _Thread_Executing;
360
 
361
  for ( ; ; ) {
362
 
363
    executing->receive_packet = NULL;
364
 
365
    _Thread_Disable_dispatch();
366
    _CORE_semaphore_Seize( &_MPCI_Semaphore, 0, TRUE, WATCHDOG_NO_TIMEOUT );
367
    _Thread_Enable_dispatch();
368
 
369
    for ( ; ; ) {
370
      the_packet = _MPCI_Receive_packet();
371
 
372
      if ( !the_packet )
373
        break;
374
 
375
      executing->receive_packet = the_packet;
376
 
377
      if ( !_Mp_packet_Is_valid_packet_class ( the_packet->the_class ) )
378
        break;
379
 
380
      the_function = _MPCI_Packet_processors[ the_packet->the_class ];
381
 
382
      if ( !the_function )
383
        _Internal_error_Occurred(
384
          INTERNAL_ERROR_CORE,
385
          TRUE,
386
          INTERNAL_ERROR_BAD_PACKET
387
        );
388
 
389
        (*the_function)( the_packet );
390
    }
391
  }
392
}
393
 
394
/*PAGE
395
 *
396
 *  _MPCI_Announce
397
 *
398
 */
399
 
400
void _MPCI_Announce ( void )
401
{
402
  _Thread_Disable_dispatch();
403
  (void) _CORE_semaphore_Surrender( &_MPCI_Semaphore, 0, 0 );
404
  _Thread_Enable_dispatch();
405
}
406
 
407
/*PAGE
408
 *
409
 *  _MPCI_Internal_packets_Send_process_packet
410
 *
411
 */
412
 
413
void _MPCI_Internal_packets_Send_process_packet (
414
   MPCI_Internal_Remote_operations operation
415
)
416
{
417
  MPCI_Internal_packet *the_packet;
418
 
419
  switch ( operation ) {
420
 
421
    case MPCI_PACKETS_SYSTEM_VERIFY:
422
 
423
      the_packet                    = _MPCI_Internal_packets_Get_packet();
424
      the_packet->Prefix.the_class  = MP_PACKET_MPCI_INTERNAL;
425
      the_packet->Prefix.length     = sizeof ( MPCI_Internal_packet );
426
      the_packet->Prefix.to_convert = sizeof ( MPCI_Internal_packet );
427
      the_packet->operation         = operation;
428
 
429
      the_packet->maximum_nodes = _Objects_Maximum_nodes;
430
 
431
      the_packet->maximum_global_objects = _Objects_MP_Maximum_global_objects;
432
 
433
      _MPCI_Send_process_packet( MPCI_ALL_NODES, &the_packet->Prefix );
434
      break;
435
  }
436
}
437
 
438
/*PAGE
439
 *
440
 *  _MPCI_Internal_packets_Send_request_packet
441
 *
442
 *  This subprogram is not needed since there are no request
443
 *  packets to be sent by this manager.
444
 *
445
 */
446
 
447
/*PAGE
448
 *
449
 *  _MPCI_Internal_packets_Send_response_packet
450
 *
451
 *  This subprogram is not needed since there are no response
452
 *  packets to be sent by this manager.
453
 *
454
 */
455
 
456
/*PAGE
457
 *
458
 *
459
 *  _MPCI_Internal_packets_Process_packet
460
 *
461
 */
462
 
463
void _MPCI_Internal_packets_Process_packet (
464
  MP_packet_Prefix  *the_packet_prefix
465
)
466
{
467
  MPCI_Internal_packet *the_packet;
468
  unsigned32                  maximum_nodes;
469
  unsigned32                  maximum_global_objects;
470
 
471
  the_packet = (MPCI_Internal_packet *) the_packet_prefix;
472
 
473
  switch ( the_packet->operation ) {
474
 
475
    case MPCI_PACKETS_SYSTEM_VERIFY:
476
 
477
      maximum_nodes          = the_packet->maximum_nodes;
478
      maximum_global_objects = the_packet->maximum_global_objects;
479
      if ( maximum_nodes != _Objects_Maximum_nodes ||
480
           maximum_global_objects != _Objects_MP_Maximum_global_objects ) {
481
 
482
        _MPCI_Return_packet( the_packet_prefix );
483
 
484
        _Internal_error_Occurred(
485
          INTERNAL_ERROR_CORE,
486
          TRUE,
487
          INTERNAL_ERROR_INCONSISTENT_MP_INFORMATION
488
        );
489
      }
490
 
491
      _MPCI_Return_packet( the_packet_prefix );
492
 
493
      break;
494
  }
495
}
496
 
497
/*PAGE
498
 *
499
 *  _MPCI_Internal_packets_Send_object_was_deleted
500
 *
501
 *  This subprogram is not needed since there are no objects
502
 *  deleted by this manager.
503
 *
504
 */
505
 
506
/*PAGE
507
 *
508
 *  _MPCI_Internal_packets_Send_extract_proxy
509
 *
510
 *  This subprogram is not needed since there are no objects
511
 *  deleted by this manager.
512
 *
513
 */
514
 
515
/*PAGE
516
 *
517
 *  _MPCI_Internal_packets_Get_packet
518
 *
519
 */
520
 
521
MPCI_Internal_packet *_MPCI_Internal_packets_Get_packet ( void )
522
{
523
  return ( (MPCI_Internal_packet *) _MPCI_Get_packet() );
524
}
525
 
526
/* end of file */

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.