source: rtems/c/src/lib/libbsp/unix/posix/shmsupp/getcfg.c @ 637df35

4.104.114.84.95
Last change on this file since 637df35 was 637df35, checked in by Joel Sherrill <joel.sherrill@…>, on 07/12/95 at 19:47:25

Ada95, gnat, go32

  • Property mode set to 100644
File size: 3.6 KB
Line 
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 *
14 *  NOTES:  The MP interrupt used is the Runway bus' ability to directly
15 *          address the control registers of up to four CPUs and cause
16 *          interrupts on them.
17 *
18 *          The following table illustrates the configuration limitations:
19 *
20 *                                   BUS     MAX
21 *                          MODE    ENDIAN  NODES
22 *                        ========= ====== =======
23 *                         POLLED    BIG    2+
24 *                        INTERRUPT  BIG    2..4
25 *
26 *  COPYRIGHT (c) 1989, 1990, 1991, 1992, 1993, 1994.
27 *  On-Line Applications Research Corporation (OAR).
28 *  All rights assigned to U.S. Government, 1994.
29 *
30 *  This material may be reproduced by or for the U.S. Government pursuant
31 *  to the copyright license under the clause at DFARS 252.227-7013.  This
32 *  notice must appear in all copies of this file and its derivatives.
33 *
34 *  $Id$
35 */
36
37#include <rtems.h>
38
39#include <shm.h>
40#include <bsp.h>
41
42#include <stdio.h>
43#include <errno.h>
44#include <unistd.h>
45#include <sys/types.h>
46#include <sys/ipc.h>
47#include <sys/shm.h>
48#include <sys/sem.h>
49
50#define INTERRUPT 0        /* can be interrupt or polling */
51#define POLLING   1
52
53shm_config_table BSP_shm_cfgtbl;
54
55int              semid;
56
57void Shm_Cause_interrupt_unix(
58  rtems_unsigned32 node
59);
60
61void Shm_Get_configuration(
62  rtems_unsigned32   localnode,
63  shm_config_table **shmcfg
64)
65{
66    rtems_unsigned32 maximum_nodes;
67    int          i;
68    int          shmid;
69    char        *shm_addr;
70    key_t        shm_key;
71    key_t        sem_key;
72    struct sembuf  sb;
73    int          status;
74
75    shm_key = 0xa000;
76
77    shmid = shmget(shm_key, 16 * KILOBYTE, IPC_CREAT | 0660);
78    if ( shmid == -1 ) {
79       perror( "shmget" );
80       exit( 0 );
81    }
82
83    shm_addr = shmat(shmid, (char *)0, SHM_RND);
84    if ( shm_addr == (void *)-1 ) {
85       perror( "shmat" );
86       exit( 0 );
87    }
88
89    sem_key = 0xa001;
90
91    maximum_nodes = Shm_RTEMS_MP_Configuration->maximum_nodes;
92    semid = semget(sem_key, maximum_nodes + 1, IPC_CREAT | 0660);
93    if ( semid == -1 ) {
94       perror( "semget" );
95       exit( 0 );
96    }
97
98    if ( Shm_Is_master_node() ) {
99      for ( i=0 ; i <= maximum_nodes ; i++ ) {
100        sb.sem_op  = 1;
101        sb.sem_num = i;
102        sb.sem_flg = 0;
103        status = semop( semid, &sb, 1 );
104        if ( status == -1 ) {
105          fprintf( stderr, "Sem init failed %d\n", errno ); fflush( stderr );
106          exit( 0 );
107        }
108      }
109    }
110
111    BSP_shm_cfgtbl.base         = (vol_u32 *)shm_addr;
112    BSP_shm_cfgtbl.length       = 16 * KILOBYTE;
113    BSP_shm_cfgtbl.format       = SHM_BIG;
114
115    BSP_shm_cfgtbl.cause_intr   = Shm_Cause_interrupt_unix;
116
117#ifdef NEUTRAL_BIG
118    BSP_shm_cfgtbl.convert      = NULL_CONVERT;
119#else
120    BSP_shm_cfgtbl.convert      = CPU_swap_u32;
121#endif
122
123#if ( POLLING == 1 )
124    BSP_shm_cfgtbl.poll_intr    = POLLED_MODE;
125    BSP_shm_cfgtbl.Intr.address = NO_INTERRUPT;
126    BSP_shm_cfgtbl.Intr.value   = NO_INTERRUPT;
127    BSP_shm_cfgtbl.Intr.length  = NO_INTERRUPT;
128#else
129    BSP_shm_cfgtbl.poll_intr    = INTR_MODE;
130    BSP_shm_cfgtbl.Intr.address = 0;    /* process id? */
131    BSP_shm_cfgtbl.Intr.value   = 0;    /* signal to send? */
132    BSP_shm_cfgtbl.Intr.length  = LONG;
133#endif
134
135    *shmcfg = &BSP_shm_cfgtbl;
136}
Note: See TracBrowser for help on using the repository browser.