[637df35] | 1 | /* void Shm_get_config( localnode, &shmcfg ) |
---|
| 2 | * |
---|
| 3 | * This routine initializes, if necessary, and returns a pointer |
---|
| 4 | * to the Shared Memory Configuration Table for the UNIX |
---|
| 5 | * simulator. |
---|
| 6 | * |
---|
| 7 | * INPUT PARAMETERS: |
---|
| 8 | * localnode - local node number |
---|
| 9 | * shmcfg - address of pointer to SHM Config Table |
---|
| 10 | * |
---|
| 11 | * OUTPUT PARAMETERS: |
---|
| 12 | * *shmcfg - pointer to SHM Config Table |
---|
| 13 | * |
---|
[aa9f194] | 14 | * NOTES: This driver is capable of supporting a practically unlimited |
---|
| 15 | * number of nodes. |
---|
[637df35] | 16 | * |
---|
| 17 | * COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994. |
---|
| 18 | * On-Line Applications Research Corporation (OAR). |
---|
| 19 | * All rights assigned to U.S. Government, 1994. |
---|
| 20 | * |
---|
| 21 | * This material may be reproduced by or for the U.S. Government pursuant |
---|
| 22 | * to the copyright license under the clause at DFARS 252.227-7013. This |
---|
| 23 | * notice must appear in all copies of this file and its derivatives. |
---|
| 24 | * |
---|
| 25 | * $Id$ |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | #include <rtems.h> |
---|
| 29 | |
---|
| 30 | #include <shm.h> |
---|
| 31 | #include <bsp.h> |
---|
| 32 | |
---|
[ad3bf667] | 33 | #include <sys/types.h> |
---|
[637df35] | 34 | #include <stdio.h> |
---|
| 35 | #include <errno.h> |
---|
| 36 | #include <unistd.h> |
---|
[aa9f194] | 37 | #include <stdlib.h> |
---|
[637df35] | 38 | #include <sys/ipc.h> |
---|
| 39 | #include <sys/shm.h> |
---|
| 40 | #include <sys/sem.h> |
---|
| 41 | |
---|
| 42 | shm_config_table BSP_shm_cfgtbl; |
---|
| 43 | |
---|
| 44 | int semid; |
---|
| 45 | |
---|
| 46 | void Shm_Cause_interrupt_unix( |
---|
| 47 | rtems_unsigned32 node |
---|
| 48 | ); |
---|
| 49 | |
---|
[aa9f194] | 50 | void fix_semaphores( void ) |
---|
[637df35] | 51 | { |
---|
| 52 | rtems_unsigned32 maximum_nodes; |
---|
| 53 | int i; |
---|
[aa9f194] | 54 | |
---|
[637df35] | 55 | int shmid; |
---|
| 56 | char *shm_addr; |
---|
| 57 | key_t shm_key; |
---|
| 58 | key_t sem_key; |
---|
| 59 | int status; |
---|
[aa9f194] | 60 | int shm_size; |
---|
[637df35] | 61 | |
---|
[aa9f194] | 62 | if (getenv("RTEMS_SHM_KEY")) |
---|
| 63 | shm_key = strtol(getenv("RTEMS_SHM_KEY"), 0, 0); |
---|
| 64 | else |
---|
| 65 | #ifdef RTEMS_SHM_KEY |
---|
| 66 | shm_key = RTEMS_SHM_KEY; |
---|
| 67 | #else |
---|
| 68 | shm_key = 0xa000; |
---|
| 69 | #endif |
---|
| 70 | |
---|
| 71 | if (getenv("RTEMS_SHM_SIZE")) |
---|
| 72 | shm_size = strtol(getenv("RTEMS_SHM_SIZE"), 0, 0); |
---|
| 73 | else |
---|
| 74 | #ifdef RTEMS_SHM_SIZE |
---|
| 75 | shm_size = RTEMS_SHM_SIZE; |
---|
| 76 | #else |
---|
| 77 | shm_size = 64 * KILOBYTE; |
---|
| 78 | #endif |
---|
| 79 | |
---|
| 80 | if (getenv("RTEMS_SHM_SEMAPHORE_KEY")) |
---|
| 81 | sem_key = strtol(getenv("RTEMS_SHM_SEMAPHORE_KEY"), 0, 0); |
---|
| 82 | else |
---|
| 83 | #ifdef RTEMS_SHM_SEMAPHORE_KEY |
---|
| 84 | sem_key = RTEMS_SHM_SEMAPHORE_KEY; |
---|
| 85 | #else |
---|
| 86 | sem_key = 0xa001; |
---|
| 87 | #endif |
---|
[637df35] | 88 | |
---|
[aa9f194] | 89 | shmid = shmget(shm_key, shm_size, IPC_CREAT | 0660); |
---|
[637df35] | 90 | if ( shmid == -1 ) { |
---|
[aa9f194] | 91 | fix_syscall_errno(); /* in case of newlib */ |
---|
[637df35] | 92 | perror( "shmget" ); |
---|
[aa9f194] | 93 | rtems_fatal_error_occurred(RTEMS_UNSATISFIED); |
---|
[637df35] | 94 | } |
---|
| 95 | |
---|
| 96 | shm_addr = shmat(shmid, (char *)0, SHM_RND); |
---|
| 97 | if ( shm_addr == (void *)-1 ) { |
---|
[aa9f194] | 98 | fix_syscall_errno(); /* in case of newlib */ |
---|
[637df35] | 99 | perror( "shmat" ); |
---|
[aa9f194] | 100 | rtems_fatal_error_occurred(RTEMS_UNSATISFIED); |
---|
[637df35] | 101 | } |
---|
| 102 | |
---|
| 103 | maximum_nodes = Shm_RTEMS_MP_Configuration->maximum_nodes; |
---|
| 104 | semid = semget(sem_key, maximum_nodes + 1, IPC_CREAT | 0660); |
---|
| 105 | if ( semid == -1 ) { |
---|
[aa9f194] | 106 | fix_syscall_errno(); /* in case of newlib */ |
---|
[637df35] | 107 | perror( "semget" ); |
---|
[aa9f194] | 108 | rtems_fatal_error_occurred(RTEMS_UNSATISFIED); |
---|
[637df35] | 109 | } |
---|
| 110 | |
---|
| 111 | if ( Shm_Is_master_node() ) { |
---|
| 112 | for ( i=0 ; i <= maximum_nodes ; i++ ) { |
---|
[aa9f194] | 113 | |
---|
| 114 | #if defined(solaris2) |
---|
| 115 | union semun { |
---|
| 116 | int val; |
---|
| 117 | struct semid_ds *buf; |
---|
| 118 | ushort *array; |
---|
| 119 | } help; |
---|
| 120 | |
---|
| 121 | help.val = 1; |
---|
| 122 | semctl( semid, i, SETVAL, help ); |
---|
| 123 | #endif |
---|
| 124 | #if defined(hpux) |
---|
| 125 | semctl( semid, i, SETVAL, 1 ); |
---|
| 126 | #endif |
---|
| 127 | |
---|
| 128 | fix_syscall_errno(); /* in case of newlib */ |
---|
[637df35] | 129 | if ( status == -1 ) { |
---|
| 130 | fprintf( stderr, "Sem init failed %d\n", errno ); fflush( stderr ); |
---|
[aa9f194] | 131 | rtems_fatal_error_occurred(RTEMS_UNSATISFIED); |
---|
[637df35] | 132 | } |
---|
| 133 | } |
---|
| 134 | } |
---|
| 135 | |
---|
| 136 | BSP_shm_cfgtbl.base = (vol_u32 *)shm_addr; |
---|
[aa9f194] | 137 | BSP_shm_cfgtbl.length = shm_size; |
---|
| 138 | } |
---|
| 139 | |
---|
| 140 | void Shm_Get_configuration( |
---|
| 141 | rtems_unsigned32 localnode, |
---|
| 142 | shm_config_table **shmcfg |
---|
| 143 | ) |
---|
| 144 | { |
---|
| 145 | fix_semaphores(); |
---|
| 146 | |
---|
[637df35] | 147 | BSP_shm_cfgtbl.format = SHM_BIG; |
---|
| 148 | |
---|
| 149 | BSP_shm_cfgtbl.cause_intr = Shm_Cause_interrupt_unix; |
---|
| 150 | |
---|
| 151 | #ifdef NEUTRAL_BIG |
---|
| 152 | BSP_shm_cfgtbl.convert = NULL_CONVERT; |
---|
| 153 | #else |
---|
| 154 | BSP_shm_cfgtbl.convert = CPU_swap_u32; |
---|
| 155 | #endif |
---|
| 156 | |
---|
[aa9f194] | 157 | #ifdef INTERRUPT_EXTERNAL_MPCI |
---|
| 158 | BSP_shm_cfgtbl.poll_intr = INTR_MODE; |
---|
| 159 | BSP_shm_cfgtbl.Intr.address = (vol_u32 *) getpid(); /* process id */ |
---|
| 160 | BSP_shm_cfgtbl.Intr.value = INTERRUPT_EXTERNAL_MPCI; /* signal to send */ |
---|
| 161 | BSP_shm_cfgtbl.Intr.length = LONG; |
---|
| 162 | #else |
---|
[637df35] | 163 | BSP_shm_cfgtbl.poll_intr = POLLED_MODE; |
---|
| 164 | BSP_shm_cfgtbl.Intr.address = NO_INTERRUPT; |
---|
| 165 | BSP_shm_cfgtbl.Intr.value = NO_INTERRUPT; |
---|
| 166 | BSP_shm_cfgtbl.Intr.length = NO_INTERRUPT; |
---|
| 167 | #endif |
---|
| 168 | |
---|
| 169 | *shmcfg = &BSP_shm_cfgtbl; |
---|
| 170 | } |
---|