source: rtems/c/src/libchip/shmdr/init.c @ 12f86efd

4.104.114.84.9
Last change on this file since 12f86efd was 12f86efd, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 11, 1995 at 2:23:49 PM

minor clean up -- switched to memset for zero'ing SHM

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