source: rtems/bsps/shared/shmdr/shmdr-init.c @ 4b28d3c

5
Last change on this file since 4b28d3c was 4b28d3c, checked in by Sebastian Huber <sebastian.huber@…>, on 04/04/18 at 14:39:58

bsps: Move shmdr to bsps

This patch is a part of the BSP source reorganization.

Update #3285.

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