source: rtems/c/src/libchip/shmdr/init.c @ 03f2154e

4.104.114.84.9
Last change on this file since 03f2154e was 03f2154e, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 22, 1997 at 5:20:27 PM

headers updated to reflect new style copyright notice as part
of switching to the modified GNU GPL.

  • Property mode set to 100644
File size: 7.2 KB
Line 
1/*  Shm_Initialization
2 *
3 *  This routine is the shared memory communications initerface
4 *  driver initialization routine.
5 *
6 *  Input parameters:  NONE
7 *
8 *  Output parameters: NONE
9 *
10 *  COPYRIGHT (c) 1989-1997.
11 *  On-Line Applications Research Corporation (OAR).
12 *  Copyright assigned to U.S. Government, 1994.
13 *
14 *  The license and distribution terms for this file may in
15 *  the file LICENSE in this distribution or at
16 *  http://www.OARcorp.com/rtems/license.html.
17 *
18 *  $Id$
19 */
20
21#define _SHM_INIT
22
23#include <rtems.h>
24#include <shm.h>
25
26#include <string.h>    /* memset() */
27#include <stdlib.h>    /* malloc() */
28#include <assert.h>
29
30/*
31 * User extension to install MPCI_Fatal as a fatal error
32 * handler extension
33 */
34 
35rtems_extensions_table MPCI_Shm_extensions;
36
37rtems_mpci_entry Shm_Initialization( void )
38
39{
40  rtems_unsigned32         i, all_initialized;
41  rtems_unsigned32         interrupt_cause, interrupt_value;
42  void                    *interrupt_address;
43  Shm_Node_status_control *nscb;
44  rtems_unsigned32         extension_id;    /* for installation of MPCI_Fatal */
45  rtems_unsigned32         remaining_memory;
46/* XXX these should use "public" methods to set their values.... */
47  rtems_configuration_table   *configuration = _Configuration_Table;
48  rtems_multiprocessing_table *mp_configuration = _Configuration_MP_table;
49
50  Shm_RTEMS_Configuration    = configuration;
51  Shm_RTEMS_MP_Configuration = mp_configuration;
52
53  Shm_Local_node    = Shm_RTEMS_MP_Configuration->node;
54  Shm_Maximum_nodes = Shm_RTEMS_MP_Configuration->maximum_nodes;
55
56  Shm_Get_configuration( Shm_Local_node, &Shm_Configuration );
57
58  Shm_Interrupt_table = (Shm_Interrupt_information *) malloc(
59    sizeof(Shm_Interrupt_information) * (Shm_Maximum_nodes + 1)
60  );
61
62  assert( Shm_Interrupt_table );
63
64
65  Shm_Receive_message_count = 0;
66  Shm_Null_message_count    = 0;
67  Shm_Interrupt_count       = 0;
68
69  /*
70   *  Set the Node Status indicators
71   */
72
73  Shm_Pending_initialization = 
74    Shm_Convert(rtems_build_name( 'P', 'E', 'N', 'D' ));
75  Shm_Initialization_complete = 
76    Shm_Convert(rtems_build_name( 'C', 'O', 'M', 'P' ));
77  Shm_Active_node = 
78    Shm_Convert(rtems_build_name( 'A', 'C', 'T', 'V' ));
79
80  /*
81   *  Initialize the constants used by the Locked Queue code.
82   */
83
84  Shm_Locked_queue_End_of_list = Shm_Convert( 0xffffffff );
85  Shm_Locked_queue_Not_on_list = Shm_Convert( 0xfffffffe );
86
87  /*
88   *  Set the base addresses for the:
89   *     + Node Status Table
90   *     + Free Pool and Receive Queues
91   *     + Envelopes
92   */
93
94  Shm_Node_statuses  = (Shm_Node_status_control *) START_NS_CBS;
95  Shm_Locked_queues  = (Shm_Locked_queue_Control *) START_LQ_CBS;
96  Shm_Envelopes      = (Shm_Envelope_control *) START_ENVELOPES;
97
98  /*
99   *  Calculate the maximum number of envelopes which can be
100   *  placed the remaining shared memory.
101   */
102
103  remaining_memory =
104     ((void *)Shm_Configuration->base + Shm_Configuration->length) -
105     ((void *)Shm_Envelopes);
106
107  Shm_Maximum_envelopes = remaining_memory / sizeof( Shm_Envelope_control );
108  Shm_Maximum_envelopes -= 1;
109
110  /*
111   *  Set the pointer to the receive queue for the local node.
112   *  When we receive a node, we will get it from here before
113   *  processing it.
114   */
115
116  Shm_Local_receive_queue  = &Shm_Locked_queues[ Shm_Local_node ];
117  Shm_Local_node_status    = &Shm_Node_statuses[ Shm_Local_node ];
118
119  /*
120   *  Convert local interrupt cause information into the
121   *  neutral format so other nodes will be able to
122   *  understand it.
123   */
124
125  interrupt_address =
126    (void *) Shm_Convert( (rtems_unsigned32)Shm_Configuration->Intr.address );
127  interrupt_value   = Shm_Convert( Shm_Configuration->Intr.value );
128  interrupt_cause   = Shm_Convert( Shm_Configuration->Intr.length );
129
130  if ( Shm_Configuration->poll_intr == POLLED_MODE ) Shm_setclockvec();
131  else                                               Shm_setvec();
132
133  if ( Shm_Is_master_node() ) {
134
135    /*
136     *  Zero out the shared memory area.
137     */
138
139    (void) memset(
140      (void *) Shm_Configuration->base,
141      0,
142      Shm_Configuration->length
143    );
144
145    /*
146     *  Initialize all of the locked queues (the free envelope
147     *  pool and a receive queue per node) and set all of the
148     *  node's status so they will be waiting to initialization
149     *  to complete.
150     */
151
152    Shm_Locked_queue_Initialize( FREE_ENV_CB, FREE_ENV_POOL );
153
154    for ( i=SHM_FIRST_NODE ; i<=Shm_Maximum_nodes ; i++ ) {
155      Shm_Initialize_receive_queue( i );
156
157      Shm_Node_statuses[ i ].status = Shm_Pending_initialization;
158      Shm_Node_statuses[ i ].error  = 0;
159    }
160
161    /*
162     *  Initialize all of the envelopes and place them in the
163     *  free pool.
164     */
165
166    for ( i=0 ; i<Shm_Maximum_envelopes ; i++ ) {
167      Shm_Envelopes[ i ].index = Shm_Convert(i);
168      Shm_Free_envelope( &Shm_Envelopes[ i ] );
169    }
170
171    /*
172     *  Initialize this node's interrupt information in the
173     *  shared area so other nodes can interrupt us.
174     */
175
176    Shm_Local_node_status->int_address = (rtems_unsigned32) interrupt_address;
177    Shm_Local_node_status->int_value   = interrupt_value;
178    Shm_Local_node_status->int_length  = interrupt_cause;
179
180    Shm_Local_node_status->status      = Shm_Initialization_complete;
181
182    /*
183     *  Loop until all nodes have completed initialization.
184     */
185
186    do {
187      all_initialized = 1;
188
189      for ( i = SHM_FIRST_NODE ; i <= Shm_Maximum_nodes ; i++ )
190        if ( Shm_Node_statuses[ i ].status != Shm_Initialization_complete )
191          all_initialized = 0;
192
193    } while ( all_initialized == 0 );
194
195    /*
196     *  Tell the other nodes we think that the system is up.
197     */
198
199    for ( i = SHM_FIRST_NODE ; i <= Shm_Maximum_nodes ; i++ )
200      Shm_Node_statuses[ i ].status = Shm_Active_node;
201
202  } else {   /* is not MASTER node */
203
204    /*
205     *  Initialize the node status for the non-master nodes.
206     *  Because the master node zeroes out memory, it is
207     *  necessary for them to keep putting their values in
208     *  the node status area until the master says they
209     *  should become active.
210     */
211
212    Shm_Local_node_status->status = Shm_Pending_initialization;
213
214    do {
215
216      if ( Shm_Local_node_status->status == Shm_Pending_initialization ) {
217
218        /*
219         *  Initialize this node's interrupt information in the
220         *  shared area so other nodes can interrupt us.
221         */
222
223        Shm_Local_node_status->int_address =
224          (rtems_unsigned32) interrupt_address;
225        Shm_Local_node_status->int_value   = interrupt_value;
226        Shm_Local_node_status->int_length  = interrupt_cause;
227
228        Shm_Local_node_status->status      = Shm_Initialization_complete;
229      }
230    } while ( Shm_Local_node_status->status != Shm_Active_node ) ;
231  }
232
233  /*
234   *  Initialize the Interrupt Information Table
235   */
236
237  for ( i = SHM_FIRST_NODE ; i <= Shm_Maximum_nodes ; i++ ) {
238    nscb = &Shm_Node_statuses[ i ];
239
240    Shm_Interrupt_table[i].address = Shm_Convert_address(
241      (void *)Shm_Convert(((vol_u32) nscb->int_address))
242    );
243    Shm_Interrupt_table[i].value = Shm_Convert( nscb->int_value );
244    Shm_Interrupt_table[i].length = Shm_Convert( nscb->int_length );
245  }
246
247  MPCI_Shm_extensions.fatal = MPCI_Fatal;
248
249  (void) rtems_extension_create(
250    rtems_build_name( 'M', 'P', 'E', 'X' ),
251    &MPCI_Shm_extensions,
252    &extension_id
253  );
254}
Note: See TracBrowser for help on using the repository browser.