[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 | * |
---|
[08311cc3] | 10 | * COPYRIGHT (c) 1989-1999. |
---|
[ac7d5ef0] | 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * |
---|
[98e4ebf5] | 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
[4e89a12] | 15 | * http://www.rtems.com/license/LICENSE. |
---|
[ac7d5ef0] | 16 | * |
---|
| 17 | * $Id$ |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #define _SHM_INIT |
---|
| 21 | |
---|
| 22 | #include <rtems.h> |
---|
[48bfd992] | 23 | #include <shm_driver.h> |
---|
[12f86efd] | 24 | |
---|
| 25 | #include <string.h> /* memset() */ |
---|
[f5674938] | 26 | #include <stdlib.h> /* malloc() */ |
---|
| 27 | #include <assert.h> |
---|
[ac7d5ef0] | 28 | |
---|
| 29 | /* |
---|
[12f86efd] | 30 | * User extension to install MPCI_Fatal as a fatal error |
---|
| 31 | * handler extension |
---|
[ac7d5ef0] | 32 | */ |
---|
[a3d3d9a] | 33 | |
---|
[ac7d5ef0] | 34 | rtems_extensions_table MPCI_Shm_extensions; |
---|
| 35 | |
---|
[534c893] | 36 | /* |
---|
| 37 | * MP configuration table from confdefs.h |
---|
| 38 | */ |
---|
| 39 | |
---|
[3a4ae6c] | 40 | rtems_mpci_entry Shm_Initialization( void ) |
---|
[ac7d5ef0] | 41 | |
---|
| 42 | { |
---|
[534c893] | 43 | uint32_t i, all_initialized; |
---|
| 44 | uint32_t interrupt_cause, interrupt_value; |
---|
[ac7d5ef0] | 45 | void *interrupt_address; |
---|
| 46 | Shm_Node_status_control *nscb; |
---|
[534c893] | 47 | uint32_t extension_id; /* for installation of MPCI_Fatal */ |
---|
| 48 | uint32_t remaining_memory; |
---|
| 49 | uint32_t local_node; |
---|
[ac7d5ef0] | 50 | |
---|
[534c893] | 51 | local_node = _Configuration_MP_table->node; |
---|
[ac7d5ef0] | 52 | |
---|
[534c893] | 53 | Shm_Get_configuration( local_node, &Shm_Configuration ); |
---|
[ac7d5ef0] | 54 | |
---|
[f5674938] | 55 | Shm_Interrupt_table = (Shm_Interrupt_information *) malloc( |
---|
[534c893] | 56 | sizeof(Shm_Interrupt_information) * (SHM_MAXIMUM_NODES + 1) |
---|
[f5674938] | 57 | ); |
---|
| 58 | |
---|
| 59 | assert( Shm_Interrupt_table ); |
---|
| 60 | |
---|
[ac7d5ef0] | 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 | |
---|
[a3d3d9a] | 69 | Shm_Pending_initialization = |
---|
[12f86efd] | 70 | Shm_Convert(rtems_build_name( 'P', 'E', 'N', 'D' )); |
---|
[a3d3d9a] | 71 | Shm_Initialization_complete = |
---|
[12f86efd] | 72 | Shm_Convert(rtems_build_name( 'C', 'O', 'M', 'P' )); |
---|
[a3d3d9a] | 73 | Shm_Active_node = |
---|
[12f86efd] | 74 | Shm_Convert(rtems_build_name( 'A', 'C', 'T', 'V' )); |
---|
[ac7d5ef0] | 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 | |
---|
[534c893] | 112 | Shm_Local_receive_queue = &Shm_Locked_queues[ local_node ]; |
---|
| 113 | Shm_Local_node_status = &Shm_Node_statuses[ local_node ]; |
---|
[ac7d5ef0] | 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 = |
---|
[509fec9c] | 122 | (void *) Shm_Convert( (uint32_t)Shm_Configuration->Intr.address ); |
---|
[ac7d5ef0] | 123 | interrupt_value = Shm_Convert( Shm_Configuration->Intr.value ); |
---|
| 124 | interrupt_cause = Shm_Convert( Shm_Configuration->Intr.length ); |
---|
| 125 | |
---|
[5c980d0] | 126 | if ( Shm_Configuration->poll_intr == POLLED_MODE ) Shm_install_timer(); |
---|
[ac7d5ef0] | 127 | else Shm_setvec(); |
---|
| 128 | |
---|
| 129 | if ( Shm_Is_master_node() ) { |
---|
| 130 | |
---|
| 131 | /* |
---|
| 132 | * Zero out the shared memory area. |
---|
| 133 | */ |
---|
| 134 | |
---|
[12f86efd] | 135 | (void) memset( |
---|
| 136 | (void *) Shm_Configuration->base, |
---|
| 137 | 0, |
---|
| 138 | Shm_Configuration->length |
---|
| 139 | ); |
---|
[ac7d5ef0] | 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 | |
---|
[534c893] | 150 | for ( i=SHM_FIRST_NODE ; i<=SHM_MAXIMUM_NODES ; i++ ) { |
---|
[ac7d5ef0] | 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 | |
---|
[509fec9c] | 172 | Shm_Local_node_status->int_address = (uint32_t) interrupt_address; |
---|
[ac7d5ef0] | 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 | |
---|
[12f86efd] | 182 | do { |
---|
[ac7d5ef0] | 183 | all_initialized = 1; |
---|
| 184 | |
---|
[534c893] | 185 | for ( i = SHM_FIRST_NODE ; i <= SHM_MAXIMUM_NODES ; i++ ) |
---|
[ac7d5ef0] | 186 | if ( Shm_Node_statuses[ i ].status != Shm_Initialization_complete ) |
---|
| 187 | all_initialized = 0; |
---|
[12f86efd] | 188 | |
---|
| 189 | } while ( all_initialized == 0 ); |
---|
[ac7d5ef0] | 190 | |
---|
| 191 | /* |
---|
| 192 | * Tell the other nodes we think that the system is up. |
---|
| 193 | */ |
---|
| 194 | |
---|
[534c893] | 195 | for ( i = SHM_FIRST_NODE ; i <= SHM_MAXIMUM_NODES ; i++ ) |
---|
[ac7d5ef0] | 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 = |
---|
[509fec9c] | 220 | (uint32_t) interrupt_address; |
---|
[ac7d5ef0] | 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 | |
---|
[534c893] | 233 | for ( i = SHM_FIRST_NODE ; i <= SHM_MAXIMUM_NODES ; i++ ) { |
---|
[ac7d5ef0] | 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; |
---|
[37f4c2d] | 244 | |
---|
[ac7d5ef0] | 245 | (void) rtems_extension_create( |
---|
| 246 | rtems_build_name( 'M', 'P', 'E', 'X' ), |
---|
| 247 | &MPCI_Shm_extensions, |
---|
| 248 | &extension_id |
---|
| 249 | ); |
---|
| 250 | } |
---|