[ac7d5ef0] | 1 | /* Shm_Initialization |
---|
| 2 | * |
---|
| 3 | * This routine is the shared memory communications initerface |
---|
| 4 | * driver initialization routine. |
---|
| 5 | * |
---|
[3a4ae6c] | 6 | * Input parameters: NONE |
---|
[ac7d5ef0] | 7 | * |
---|
| 8 | * Output parameters: NONE |
---|
| 9 | * |
---|
| 10 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * All rights assigned to U.S. Government, 1994. |
---|
| 13 | * |
---|
| 14 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
| 15 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
| 16 | * notice must appear in all copies of this file and its derivatives. |
---|
| 17 | * |
---|
| 18 | * $Id$ |
---|
| 19 | */ |
---|
| 20 | |
---|
| 21 | #define _SHM_INIT |
---|
| 22 | |
---|
| 23 | #include <rtems.h> |
---|
[12f86efd] | 24 | #include <shm.h> |
---|
| 25 | |
---|
| 26 | #include <string.h> /* memset() */ |
---|
[ac7d5ef0] | 27 | |
---|
| 28 | /* |
---|
[12f86efd] | 29 | * User extension to install MPCI_Fatal as a fatal error |
---|
| 30 | * handler extension |
---|
[ac7d5ef0] | 31 | */ |
---|
[12f86efd] | 32 | |
---|
[ac7d5ef0] | 33 | rtems_extensions_table MPCI_Shm_extensions; |
---|
| 34 | |
---|
[3a4ae6c] | 35 | rtems_mpci_entry Shm_Initialization( void ) |
---|
[ac7d5ef0] | 36 | |
---|
| 37 | { |
---|
[12f86efd] | 38 | rtems_unsigned32 i, all_initialized; |
---|
[ac7d5ef0] | 39 | rtems_unsigned32 interrupt_cause, interrupt_value; |
---|
| 40 | void *interrupt_address; |
---|
| 41 | Shm_Node_status_control *nscb; |
---|
| 42 | rtems_unsigned32 extension_id; /* for installation of MPCI_Fatal */ |
---|
| 43 | rtems_unsigned32 remaining_memory; |
---|
[3a4ae6c] | 44 | /* XXX these should use "public" methods to set their values.... */ |
---|
| 45 | rtems_configuration_table *configuration = _Configuration_Table; |
---|
| 46 | rtems_multiprocessing_table *mp_configuration = _Configuration_MP_table; |
---|
[ac7d5ef0] | 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 | |
---|
[12f86efd] | 54 | Shm_Get_configuration( Shm_Local_node, &Shm_Configuration ); |
---|
[ac7d5ef0] | 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 | |
---|
[12f86efd] | 64 | Shm_Pending_initialization = |
---|
| 65 | Shm_Convert(rtems_build_name( 'P', 'E', 'N', 'D' )); |
---|
| 66 | Shm_Initialization_complete = |
---|
| 67 | Shm_Convert(rtems_build_name( 'C', 'O', 'M', 'P' )); |
---|
| 68 | Shm_Active_node = |
---|
| 69 | Shm_Convert(rtems_build_name( 'A', 'C', 'T', 'V' )); |
---|
[ac7d5ef0] | 70 | |
---|
| 71 | /* |
---|
| 72 | * Initialize the constants used by the Locked Queue code. |
---|
| 73 | */ |
---|
| 74 | |
---|
| 75 | Shm_Locked_queue_End_of_list = Shm_Convert( 0xffffffff ); |
---|
| 76 | Shm_Locked_queue_Not_on_list = Shm_Convert( 0xfffffffe ); |
---|
| 77 | |
---|
| 78 | /* |
---|
| 79 | * Set the base addresses for the: |
---|
| 80 | * + Node Status Table |
---|
| 81 | * + Free Pool and Receive Queues |
---|
| 82 | * + Envelopes |
---|
| 83 | */ |
---|
| 84 | |
---|
| 85 | Shm_Node_statuses = (Shm_Node_status_control *) START_NS_CBS; |
---|
| 86 | Shm_Locked_queues = (Shm_Locked_queue_Control *) START_LQ_CBS; |
---|
| 87 | Shm_Envelopes = (Shm_Envelope_control *) START_ENVELOPES; |
---|
| 88 | |
---|
| 89 | /* |
---|
| 90 | * Calculate the maximum number of envelopes which can be |
---|
| 91 | * placed the remaining shared memory. |
---|
| 92 | */ |
---|
| 93 | |
---|
| 94 | remaining_memory = |
---|
| 95 | ((void *)Shm_Configuration->base + Shm_Configuration->length) - |
---|
| 96 | ((void *)Shm_Envelopes); |
---|
| 97 | |
---|
| 98 | Shm_Maximum_envelopes = remaining_memory / sizeof( Shm_Envelope_control ); |
---|
| 99 | Shm_Maximum_envelopes -= 1; |
---|
| 100 | |
---|
| 101 | /* |
---|
| 102 | * Set the pointer to the receive queue for the local node. |
---|
| 103 | * When we receive a node, we will get it from here before |
---|
| 104 | * processing it. |
---|
| 105 | */ |
---|
| 106 | |
---|
| 107 | Shm_Local_receive_queue = &Shm_Locked_queues[ Shm_Local_node ]; |
---|
| 108 | Shm_Local_node_status = &Shm_Node_statuses[ Shm_Local_node ]; |
---|
| 109 | |
---|
| 110 | /* |
---|
| 111 | * Convert local interrupt cause information into the |
---|
| 112 | * neutral format so other nodes will be able to |
---|
| 113 | * understand it. |
---|
| 114 | */ |
---|
| 115 | |
---|
| 116 | interrupt_address = |
---|
| 117 | (void *) Shm_Convert( (rtems_unsigned32)Shm_Configuration->Intr.address ); |
---|
| 118 | interrupt_value = Shm_Convert( Shm_Configuration->Intr.value ); |
---|
| 119 | interrupt_cause = Shm_Convert( Shm_Configuration->Intr.length ); |
---|
| 120 | |
---|
| 121 | if ( Shm_Configuration->poll_intr == POLLED_MODE ) Shm_setclockvec(); |
---|
| 122 | else Shm_setvec(); |
---|
| 123 | |
---|
| 124 | if ( Shm_Is_master_node() ) { |
---|
| 125 | |
---|
| 126 | /* |
---|
| 127 | * Zero out the shared memory area. |
---|
| 128 | */ |
---|
| 129 | |
---|
[12f86efd] | 130 | (void) memset( |
---|
| 131 | (void *) Shm_Configuration->base, |
---|
| 132 | 0, |
---|
| 133 | Shm_Configuration->length |
---|
| 134 | ); |
---|
[ac7d5ef0] | 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 | |
---|
[12f86efd] | 177 | do { |
---|
[ac7d5ef0] | 178 | all_initialized = 1; |
---|
| 179 | |
---|
| 180 | for ( i = SHM_FIRST_NODE ; i <= Shm_Maximum_nodes ; i++ ) |
---|
| 181 | if ( Shm_Node_statuses[ i ].status != Shm_Initialization_complete ) |
---|
| 182 | all_initialized = 0; |
---|
[12f86efd] | 183 | |
---|
| 184 | } while ( all_initialized == 0 ); |
---|
[ac7d5ef0] | 185 | |
---|
| 186 | /* |
---|
| 187 | * Tell the other nodes we think that the system is up. |
---|
| 188 | */ |
---|
| 189 | |
---|
| 190 | for ( i = SHM_FIRST_NODE ; i <= Shm_Maximum_nodes ; i++ ) |
---|
| 191 | Shm_Node_statuses[ i ].status = Shm_Active_node; |
---|
| 192 | |
---|
| 193 | } else { /* is not MASTER node */ |
---|
| 194 | |
---|
| 195 | /* |
---|
| 196 | * Initialize the node status for the non-master nodes. |
---|
| 197 | * Because the master node zeroes out memory, it is |
---|
| 198 | * necessary for them to keep putting their values in |
---|
| 199 | * the node status area until the master says they |
---|
| 200 | * should become active. |
---|
| 201 | */ |
---|
| 202 | |
---|
| 203 | Shm_Local_node_status->status = Shm_Pending_initialization; |
---|
| 204 | |
---|
| 205 | do { |
---|
| 206 | |
---|
| 207 | if ( Shm_Local_node_status->status == Shm_Pending_initialization ) { |
---|
| 208 | |
---|
| 209 | /* |
---|
| 210 | * Initialize this node's interrupt information in the |
---|
| 211 | * shared area so other nodes can interrupt us. |
---|
| 212 | */ |
---|
| 213 | |
---|
| 214 | Shm_Local_node_status->int_address = |
---|
| 215 | (rtems_unsigned32) interrupt_address; |
---|
| 216 | Shm_Local_node_status->int_value = interrupt_value; |
---|
| 217 | Shm_Local_node_status->int_length = interrupt_cause; |
---|
| 218 | |
---|
| 219 | Shm_Local_node_status->status = Shm_Initialization_complete; |
---|
| 220 | } |
---|
| 221 | } while ( Shm_Local_node_status->status != Shm_Active_node ) ; |
---|
| 222 | } |
---|
| 223 | |
---|
| 224 | /* |
---|
| 225 | * Initialize the Interrupt Information Table |
---|
| 226 | */ |
---|
| 227 | |
---|
| 228 | for ( i = SHM_FIRST_NODE ; i <= Shm_Maximum_nodes ; i++ ) { |
---|
| 229 | nscb = &Shm_Node_statuses[ i ]; |
---|
| 230 | |
---|
| 231 | Shm_Interrupt_table[i].address = Shm_Convert_address( |
---|
| 232 | (void *)Shm_Convert(((vol_u32) nscb->int_address)) |
---|
| 233 | ); |
---|
| 234 | Shm_Interrupt_table[i].value = Shm_Convert( nscb->int_value ); |
---|
| 235 | Shm_Interrupt_table[i].length = Shm_Convert( nscb->int_length ); |
---|
| 236 | } |
---|
| 237 | |
---|
| 238 | MPCI_Shm_extensions.fatal = MPCI_Fatal; |
---|
[37f4c2d] | 239 | |
---|
[ac7d5ef0] | 240 | (void) rtems_extension_create( |
---|
| 241 | rtems_build_name( 'M', 'P', 'E', 'X' ), |
---|
| 242 | &MPCI_Shm_extensions, |
---|
| 243 | &extension_id |
---|
| 244 | ); |
---|
| 245 | } |
---|