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

4.104.11
Last change on this file since dd9cc9f7 was 534c893, checked in by Joel Sherrill <joel.sherrill@…>, on Dec 18, 2008 at 5:15:51 PM

2008-12-18 Joel Sherrill <joel.sherrill@…>

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