OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [lib/] [libbsp/] [shmdr/] [init.c] - Blame information for rev 778

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.