source: rtems/c/src/libchip/shmdr/init.c @ ac7d5ef0

4.104.114.84.95
Last change on this file since ac7d5ef0 was ac7d5ef0, checked in by Joel Sherrill <joel.sherrill@…>, on 05/11/95 at 17:39:37

Initial revision

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