Initial import from FreeBSD RELENG_4:
[games.git] / usr.sbin / pccard / pccardd / cardd.h
1 /*
2  * Copyright (c) 1995 Andrew McRae.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  * 3. The name of the author may not be used to endorse or promote products
13  *    derived from this software without specific prior written permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD: src/usr.sbin/pccard/pccardd/cardd.h,v 1.18.2.6 2001/05/23 21:56:40 dmlb Exp $
27  *
28  *      Common include file for PCMCIA daemon
29  */
30 #include <bitstring.h>
31
32 #include <pccard/cardinfo.h>
33 #include <pccard/cis.h>
34
35 #include "readcis.h"
36
37 #ifndef EXTERN
38 #define EXTERN extern
39 #endif
40
41 struct cmd {
42         struct cmd *next;
43         char   *line;           /* Command line */
44         int     macro;          /* Contains macros */
45 };
46
47 struct card_config {
48         struct card_config *next;
49         unsigned char index_type;
50         unsigned char index;
51         struct driver *driver;
52         int     irq;
53         int     flags;
54         char    inuse;
55 };
56
57 struct ether {
58         struct ether *next;
59         int     type;
60         int     value;
61 };
62
63 #define ETHTYPE_GENERIC         0
64 #define ETHTYPE_ATTR2           1
65
66 struct card {
67         struct card *next;
68         char   *manuf;
69         char   *version;
70         char   *add_info1;
71         char   *add_info2;
72         u_char  func_id;
73         int     deftype;
74         struct ether *ether;            /* For net cards, ether at offset */
75         int     reset_time;             /* Reset time */
76         int     iosize;                 /* I/O window size (ignore location) */
77         struct card_config *config;     /* List of configs */
78         struct cmd *insert;             /* Insert commands */
79         struct cmd *remove;             /* Remove commands */
80         char   *logstr;                 /* String for logger */
81 };
82
83 struct driver {
84         struct driver *next;
85         char   *name;
86         char   *kernel;                 /* Kernel driver base name */
87         int     unit;                   /* Unit of driver */
88         /*
89          * The rest of the structure is allocated dynamically.
90          * Once allocated, it stays allocated.
91          */
92         struct card *card;              /* Current card, if any */
93         struct card_config *config;     /* Config back ptr */
94         unsigned int mem;               /* Allocated host address (if any) */
95         int     inuse;
96 };
97
98 /*
99  *      Defines one allocation block i.e a starting address
100  *      and size. Used for either memory or I/O ports
101  */
102 struct allocblk {
103         struct allocblk *next;
104         int     addr;                   /* Address */
105         int     size;                   /* Size */
106         int     flags;                  /* Flags for block */
107         int     cardaddr;               /* Card address */
108 };
109 /*
110  *      Slot structure - data held for each slot.
111  */
112 struct slot {
113         struct slot *next;
114         int     fd;
115         int     mask;
116         int     slot;
117         char   *name;
118         enum cardstate state;
119         struct cis *cis;
120         struct card *card;              /* Current card */
121         struct card_config *config;     /* Current configuration */
122         struct cis_config *card_config;
123         char    devname[16];
124         unsigned char eaddr[6];         /* If any */
125         struct allocblk io;             /* I/O block spec */
126         struct allocblk mem;            /* Memory block spec */
127         int     irq;                    /* Irq value */
128         int     flags;                  /* Resource assignment flags */
129 };
130
131 /*
132  * Slot resource assignment/configuration flags
133  */
134 #define IO_ASSIGNED     0x1
135 #define MEM_ASSIGNED    0x2
136 #define IRQ_ASSIGNED    0x4
137 #define EADDR_CONFIGED  0x8
138 #define WL_CONFIGED     0x10
139 #define AFLAGS  (IO_ASSIGNED | MEM_ASSIGNED | IRQ_ASSIGNED)
140 #define CFLAGS  (EADDR_CONFIGED | WL_CONFIGED)
141
142 EXTERN struct slot *slots, *current_slot;
143 EXTERN int slen;
144
145 EXTERN struct allocblk *pool_ioblks;            /* I/O blocks in the pool */
146 EXTERN struct allocblk *pool_mem;               /* Memory in the pool */
147 EXTERN int     pool_irq[16];                    /* IRQ allocations */
148 EXTERN int     irq_init[16];                    /* initial IRQ allocations */
149 EXTERN struct driver *drivers;                  /* List of drivers */
150 EXTERN struct card *cards;
151 EXTERN struct card *last_card;
152 EXTERN bitstr_t *mem_avail;
153 EXTERN bitstr_t *mem_init;
154 EXTERN bitstr_t *io_avail;
155 EXTERN bitstr_t *io_init;
156 EXTERN int pccard_init_sleep;                   /* Time to sleep on init */
157 EXTERN int use_kern_irq;
158 EXTERN int debug_level;
159
160 /* cardd.c functions */
161 void             dump_config_file(void);
162 struct slot     *readslots(void);
163 void             slot_change(struct slot *);
164
165 /* util.c functions */
166 unsigned long    alloc_memory(int);
167 int              bit_fns(bitstr_t *, int, int, int, int);
168 void             die(char *);
169 void             execute(struct cmd *, struct slot *);
170 void             logmsg(const char *, ...);
171 void             log_setup(void);
172 void             logerr(char *);
173 char            *newstr();
174 void             reset_slot(struct slot *);
175 void            *xmalloc(int);
176
177 /* file.c functions */
178 void             readfile(char *);
179
180 /* server.c functions */
181 void             set_socket(int);
182 void             stat_changed(struct slot *);
183 void             process_client(void);
184
185 #define IOPORTS 0x400
186 #define MEMUNIT 0x1000
187 #define MEMSTART 0xA0000
188 #define MEMEND  0x100000
189 #define MEMBLKS ((MEMEND-MEMSTART)/MEMUNIT)
190 #define MEM2BIT(x) (((x)-MEMSTART)/MEMUNIT)
191 #define BIT2MEM(x) (((x)*MEMUNIT)+MEMSTART)
192
193 #define MAXINCLUDES     10
194 #define MAXERRORS       10
195
196 /*
197  * Config index types
198  */
199 #define NORMAL_INDEX    0
200 #define DEFAULT_INDEX   1
201 #define AUTO_INDEX      2
202
203 #define DT_VERS 0
204 #define DT_FUNC 1