1 /* $Id: pcmciavar.h,v 1.3 1996/11/28 23:28:17 niklas Exp $ */ 2 /* 3 * Copyright (c) 1995,1996 John T. Kohl. All rights reserved. 4 * Copyright (c) 1993, 1994 Stefan Grefen. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following dipclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by Charles Hannum. 17 * 4. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 * 31 */ 32 /* derived from scsicconf.[ch] writenn by Julian Elischer et al */ 33 34 #ifndef _PCMCIA_PCMCIAVAR_H_ 35 #define _PCMCIA_PCMCIAVAR_H_ 1 36 37 #include <sys/queue.h> 38 #include <sys/select.h> 39 #include <machine/cpu.h> 40 #include <machine/bus.h> 41 42 /* 43 * The following documentation tries to describe the relationship between the 44 * various structures defined in this file: 45 * 46 * each adapter type has a pcmcia_adapter struct. This describes the adapter and 47 * identifies routines that can be called to use the adapter. 48 * each device type has a pcmcia_device struct. This describes the device and 49 * identifies routines that can be called to use the device. 50 * each existing device position (pcmciabus + port) 51 * can be described by a pcmcia_link struct. 52 * Only port positions that actually have devices, have a pcmcia_link 53 * structure assigned. so in effect each device has pcmcia_link struct. 54 * The pcmcia_link structure contains information identifying both the 55 * device driver and the adapter driver for that port on that pcmcia bus, 56 * and can be said to 'link' the two. 57 * each individual pcmcia bus has an array that points to all the pcmcia_link 58 * structs associated with that pcmcia bus. Slots with no device have 59 * a NULL pointer. 60 * each individual device also knows the address of it's own pcmcia_link 61 * structure. 62 * 63 * ------------- 64 * 65 * The key to all this is the pcmcia_link structure which associates all the 66 * other structures with each other in the correct configuration. The 67 * pcmcia_link is the connecting information that allows each part of the 68 * pcmcia system to find the associated other parts. 69 */ 70 71 72 struct pcmcia_link; 73 struct pcmcia_conf; 74 struct pcmcia_adapter; 75 76 /* 77 * These entrypoints are called by the high-end drivers to get services from 78 * whatever low-end drivers they are attached to each adapter type has one of 79 * these statically allocated. 80 */ 81 struct pcmcia_funcs { 82 /* 4 map io range */ 83 int (*pcmcia_map_io) __P((struct pcmcia_link *, u_int, u_int, int)); 84 /* 8 map memory window */ 85 int (*pcmcia_map_mem) __P((struct pcmcia_link *, bus_space_tag_t, 86 caddr_t, u_int, u_int, int)); 87 /*12 map interrupt */ 88 int (*pcmcia_map_intr) __P((struct pcmcia_link *, int, int)); 89 /*16 power on/off etc */ 90 int (*pcmcia_service) __P((struct pcmcia_link *, int, void *, int)); 91 }; 92 93 struct pcmciabus_link { /* Link back to the bus we are on */ 94 /* Bus specific configure */ 95 int (*bus_config) __P((struct pcmcia_link *, struct device *, 96 struct pcmcia_conf *, struct cfdata *)); 97 /* Bus specific unconfigure */ 98 int (*bus_unconfig) __P((struct pcmcia_link *)); 99 /* Bus specific probe */ 100 int (*bus_probe) __P((struct device *, void *, 101 void *, struct pcmcia_link *)); 102 /* Bus specific search */ 103 int (*bus_search) __P((struct device *, void *, cfprint_t)); 104 /* initialize scratch */ 105 int (*bus_init) __P((struct device *, struct cfdata *, 106 void *, struct pcmcia_adapter *, int)); 107 }; 108 #define PCMCIA_BUS_INIT(a,b,c,d,e,f) \ 109 ((*(a)->bus_link->bus_init)((b),(c),(d),(e),(f))) 110 #define PCMCIA_BUS_SEARCH(a,b,c,d) \ 111 ((*(a)->bus_link->bus_search)((b),(c),(d))) 112 #define PCMCIA_BUS_PROBE(a,b,c,d,e) \ 113 ((*(a)->bus_link->bus_probe)((b),(c),(d),(e))) 114 #define PCMCIA_BUS_CONFIG(a,b,c,d,e) \ 115 ((*(a)->bus_link->bus_config)((b),(c),(d),(e))) 116 #define PCMCIA_BUS_UNCONFIG(a,b) \ 117 ((*(a)->bus_link->bus_unconfig)((b))) 118 119 120 /* 121 * One of these goes at the front of each chip controller's softc, right 122 * after the struct device. 123 */ 124 struct pcmcia_adapter { 125 struct pcmcia_funcs *chip_link; 126 struct pcmciabus_link *bus_link; 127 bus_space_tag_t pa_memt; /* mem access handle */ 128 void *adapter_softc; 129 caddr_t scratch_mem; /* pointer to scratch window */ 130 int scratch_memsiz; /* size of scratch window */ 131 bus_space_handle_t scratch_memh;/* bus memory handle */ 132 int scratch_inuse; /* window in use */ 133 int nslots; /* # of slots controlled */ 134 }; 135 136 #define PCMCIA_MAP_ATTR 0x0100 /* for memory only */ 137 #define PCMCIA_MAP_8 0x0100 /* for io only */ 138 #define PCMCIA_MAP_16 0x0200 139 #define PCMCIA_UNMAP 0x0400 140 #define PCMCIA_PHYSICAL_ADDR 0x0800 141 #define PCMCIA_UNMAP_ALL 0x0c00 142 #define PCMCIA_FIXED_WIN 0x1000 143 #define PCMCIA_LAST_WIN 0x0010 144 #define PCMCIA_FIRST_WIN 0x0020 145 #define PCMCIA_ANY_WIN 0x0030 146 147 #define PCMCIA_OP_RESET 0x0000 148 #define PCMCIA_OP_POWER 0x0001 149 #define PCMCIA_OP_STATUS 0x0002 150 #define PCMCIA_OP_GETREGS 0x0003 151 #define PCMCIA_OP_WAIT 0x0004 152 153 #define PCMCIA_POWER_ON 0x0001 154 #define PCMCIA_POWER_5V 0x0002 155 #define PCMCIA_POWER_3V 0x0004 156 #define PCMCIA_POWER_AUTO 0x0008 157 158 #define PCMCIA_CARD_PRESENT 0x0001 159 #define PCMCIA_BATTERY 0x0002 160 #define PCMCIA_WRITE_PROT 0x0004 161 #define PCMCIA_READY 0x0008 162 #define PCMCIA_POWER 0x0010 163 #define PCMCIA_POWER_PP 0x0020 164 #define PCMCIA_CARD_IS_MAPPED 0x1000 165 #define PCMCIA_CARD_INUSE 0x2000 166 167 168 /* 169 * This structure describes the connection between an adapter driver and 170 * a device driver, and is used by each to call services provided by 171 * the other, and to allow generic pcmcia glue code to call these services 172 * as well. 173 */ 174 struct pcmcia_link { 175 u_char pcmciabus; /* the Nth pcmciabus */ 176 u_char slot; /* slot of this dev */ 177 u_char flags; 178 #define CARD_IS_MAPPED 0x01 179 #define PCMCIA_ATTACH 0x02 180 #define PCMCIA_REATTACH 0x04 181 #define PCMCIA_SLOT_INUSE 0x08 182 #define PCMCIA_ATTACH_TYPE (PCMCIA_ATTACH|PCMCIA_REATTACH) 183 #define PCMCIA_SLOT_EVENT 0x80 184 #define PCMCIA_SLOT_OPEN 0x40 185 u_char opennings; 186 187 u_char iowin; 188 u_char memwin; 189 u_char intr; 190 u_char dummy; 191 struct pcmcia_adapter *adapter; /* adapter entry points etc. */ 192 struct pcmciadevs *device; /* device entry points etc. */ 193 struct pcmciabus_softc *bus; /* parent pcmcia bus */ 194 struct device *devp; /* pointer to configured device */ 195 void *fordriver; /* for private use by the driver */ 196 struct selinfo pcmcialink_sel; /* for select users */ 197 }; 198 199 /* 200 * One of these is allocated and filled in for each pcmcia bus. 201 * it holds pointers to allow the pcmcia bus to get to the driver 202 * it also has a template entry which is the prototype struct 203 * supplied by the adapter driver, this is used to initialise 204 * the others, before they have the rest of the fields filled in 205 */ 206 struct pcmciabus_softc { 207 struct device sc_dev; 208 bus_space_tag_t sc_iot; 209 bus_space_tag_t sc_memt; 210 struct pcmcia_link *sc_link[4]; /* up to 4 slots per bus */ 211 struct pcmcia_adapter *sc_driver; 212 }; 213 214 struct pcmcia_conf { 215 int irq_share:1; 216 int irq_level:1; /* 1 level */ 217 int irq_pulse:1; /* 1 pulse */ 218 int irq_vend:1; 219 int irq_iock:1; 220 int irq_berr:1; 221 int irq_nmi:1; 222 int iocard:1; 223 u_char iowin; 224 u_char memwin; 225 u_char irq_num; 226 u_char cfgtype; 227 #define CFGENTRYID 0x20 228 #define CFGENTRYMASK (CFGENTRYID|(CFGENTRYID-1)) 229 #define DOSRESET 0x40 230 int cfg_regmask; 231 int irq_mask; 232 int cfg_off; 233 struct iowin { 234 int start; 235 int len; 236 int flags; 237 }io[4]; 238 struct memwin { 239 int start; 240 int caddr; 241 int len; 242 int flags; 243 }mem[4]; 244 char driver_name[8][4]; /* up to four different functions on a card */ 245 int unitid; 246 int cfgid; 247 }; 248 249 struct pcmcia_device { 250 char *name; 251 int (*pcmcia_config) __P((struct pcmcia_link *, struct device *, 252 struct pcmcia_conf *, struct cfdata *)); 253 int (*pcmcia_probe) __P((struct device *, void *, 254 void *, struct pcmcia_link *)); 255 int (*pcmcia_insert) __P((struct pcmcia_link *, struct device *, 256 struct cfdata *)); 257 int (*pcmcia_remove) __P((struct pcmcia_link *, struct device *)); 258 }; 259 260 #define MAX_CIS_NAMELEN 64 /* version info string len */ 261 262 struct pcmcia_cardinfo { 263 char manufacturer[MAX_CIS_NAMELEN]; 264 char model[MAX_CIS_NAMELEN]; 265 char add_info1[MAX_CIS_NAMELEN]; 266 char add_info2[MAX_CIS_NAMELEN]; 267 }; 268 269 struct pcmciadevs { 270 char *devname; 271 int flags; /* 1 show my comparisons during boot(debug) */ 272 #define PC_SHOWME 0x01 273 char *manufacturer; 274 char *model; 275 char *add_inf1; 276 char *add_inf2; 277 void *param; 278 struct pcmcia_device *dev; 279 }; 280 281 /* 282 * PCMCIA driver attach arguments 283 */ 284 struct pcmcia_attach_args { 285 struct pcmcia_cardinfo *paa_cardinfo; /* card that we're looking at */ 286 struct pcmcia_link *paa_link; /* this nexus */ 287 int paa_bestmatch; /* best match so far */ 288 int paa_matchonly; /* only do matches, don't attach */ 289 void *paa_aux; /* driver specific */ 290 }; 291 292 struct pcmciabus_attach_args { 293 bus_space_tag_t pba_iot; 294 bus_space_tag_t pba_memt; 295 int pba_maddr; 296 int pba_msize; 297 void *pba_aux; /* driver specific */ 298 }; 299 300 #ifdef _KERNEL 301 extern int pcmcia_add_device __P((struct pcmciadevs *)); 302 extern int pcmcia_get_cf __P((struct pcmcia_link *, u_char *, int, int, 303 struct pcmcia_conf *)); 304 extern int pcmcia_targmatch __P((struct device *, struct cfdata *, void *)); 305 #endif 306 307 /* in pcmcia_conf.c, available for user space too: */ 308 extern int pcmcia_get_cisver1 __P((struct pcmcia_link *, u_char *, int, 309 char *, char *, char *, char *)); 310 void parse_cfent __P((u_char *, int, int, struct pcmcia_conf *)); 311 void read_cfg_info __P((u_char *, int, struct pcmcia_conf *)); 312 void pcmcia_getstr __P((char *buf, u_char **, u_char *)); 313 extern int pcmcia_configure __P((struct device *, void *, void *)); 314 extern int pcmcia_register __P((void *, struct pcmciabus_link *, 315 struct pcmcia_funcs *, int)); 316 extern int pcmcia_read_cis __P((struct pcmcia_link *, u_char *, int, int)); 317 extern int pcmcia_strcmp __P((const char *, const char *, int, const char *)); 318 extern int pcmcia_matchvalue __P((const struct pcmcia_cardinfo *, 319 struct pcmciadevs *)); 320 extern int pcmcia_bestvalue __P((struct pcmcia_cardinfo *, 321 struct pcmciadevs *, 322 int, 323 struct pcmciadevs **)); 324 extern int pcmcia_slave_match __P((struct device *, 325 void *, 326 void *aux, 327 struct pcmciadevs *, 328 int)); 329 #endif /* _PCMCIA_PCMCIAVAR_H_ */ 330