1 /* $OpenBSD: isavar.h,v 1.57 2011/07/08 08:26:41 jsg Exp $ */ 2 /* $NetBSD: isavar.h,v 1.26 1997/06/06 23:43:57 thorpej Exp $ */ 3 4 /*- 5 * Copyright (c) 1997 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility, 10 * NASA Ames Research Center. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 1. Redistributions of source code must retain the above copyright 16 * notice, this list of conditions and the following disclaimer. 17 * 2. Redistributions in binary form must reproduce the above copyright 18 * notice, this list of conditions and the following disclaimer in the 19 * documentation and/or other materials provided with the distribution. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 23 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 24 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 25 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 31 * POSSIBILITY OF SUCH DAMAGE. 32 */ 33 34 /* 35 * Copyright (c) 1996 Christos Zoulas. All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, this list of conditions and the following disclaimer. 42 * 2. Redistributions in binary form must reproduce the above copyright 43 * notice, this list of conditions and the following disclaimer in the 44 * documentation and/or other materials provided with the distribution. 45 * 3. All advertising materials mentioning features or use of this software 46 * must display the following acknowledgement: 47 * This product includes software developed by Christos Zoulas. 48 * 4. The name of the author may not be used to endorse or promote products 49 * derived from this software without specific prior written permission. 50 * 51 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 52 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 53 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 54 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 55 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 56 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 60 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 61 */ 62 63 /* 64 * Copyright (c) 1995 Chris G. Demetriou 65 * Copyright (c) 1992 Berkeley Software Design, Inc. 66 * All rights reserved. 67 * 68 * Redistribution and use in source and binary forms, with or without 69 * modification, are permitted provided that the following conditions 70 * are met: 71 * 1. Redistributions of source code must retain the above copyright 72 * notice, this list of conditions and the following disclaimer. 73 * 2. Redistributions in binary form must reproduce the above copyright 74 * notice, this list of conditions and the following disclaimer in the 75 * documentation and/or other materials provided with the distribution. 76 * 3. All advertising materials mentioning features or use of this software 77 * must display the following acknowledgement: 78 * This product includes software developed by Berkeley Software 79 * Design, Inc. 80 * 4. The name of Berkeley Software Design must not be used to endorse 81 * or promote products derived from this software without specific 82 * prior written permission. 83 * 84 * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN, INC. ``AS IS'' AND 85 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 86 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 87 * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN, INC. BE LIABLE 88 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 89 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 90 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 91 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 92 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 93 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 94 * SUCH DAMAGE. 95 * 96 * BSDI Id: isavar.h,v 1.5 1992/12/01 18:06:00 karels Exp 97 */ 98 99 #ifndef _DEV_ISA_ISAVAR_H_ 100 #define _DEV_ISA_ISAVAR_H_ 101 102 /* 103 * Definitions for ISA and ISA PnP autoconfiguration. 104 */ 105 106 #include <sys/queue.h> 107 #include <machine/bus.h> 108 109 #ifndef NISADMA 110 #include "isadma.h" 111 #endif 112 113 /* 114 * Structures and definitions needed by the machine-dependent header. 115 */ 116 struct isabus_attach_args; 117 118 #if defined(__alpha__) 119 #include <alpha/isa/isa_machdep.h> 120 #elif defined(__hp300__) 121 #include <hp300/dev/isa_machdep.h> 122 #elif defined(__i386__) 123 #include <i386/isa/isa_machdep.h> 124 #elif defined(__powerpc__) 125 #include <powerpc/isa/isa_machdep.h> 126 #else 127 #include <machine/isa_machdep.h> 128 #endif 129 130 #include "isapnp.h" 131 132 #if NISAPNP > 0 133 /* 134 * Structures and definitions needed by the machine-dependent header. 135 */ 136 struct isapnp_softc; 137 138 #if defined(__alpha__) 139 #include <alpha/isa/isapnp_machdep.h> 140 #elif defined(__i386__) 141 #include <i386/isa/isapnp_machdep.h> 142 #else 143 #error COMPILING ISAPNP FOR UNSUPPORTED MACHINE. 144 #endif 145 #endif /* NISAPNP */ 146 147 # define ISAPNP_WRITE_ADDR(sc, v) \ 148 bus_space_write_1(sc->sc_iot, sc->sc_addr_ioh, 0, v) 149 # define ISAPNP_WRITE_DATA(sc, v) \ 150 bus_space_write_1(sc->sc_iot, sc->sc_wrdata_ioh, 0, v) 151 # define ISAPNP_READ_DATA(sc) \ 152 bus_space_read_1(sc->sc_iot, sc->sc_read_ioh, 0) 153 154 # define ISAPNP_CLONE_SETUP(dest, src) \ 155 do { \ 156 bzero((dest), sizeof(*(dest))); \ 157 (dest)->ia_ic = (src)->ia_ic; \ 158 } while (0) 159 160 #ifndef _DEV_ISA_ISAPNPREG_H_ 161 /* 162 * `reg' defines needed only for these structures. 163 */ 164 #define ISAPNP_MAX_CARDS 8 165 #define ISAPNP_MAX_IDENT 32 166 #define ISAPNP_MAX_DEVCLASS 16 167 #define ISAPNP_SERIAL_SIZE 9 168 169 #define ISAPNP_NUM_MEM 4 170 #define ISAPNP_NUM_IO 8 171 #define ISAPNP_NUM_IRQ 16 172 #define ISAPNP_NUM_DRQ 8 173 #define ISAPNP_NUM_MEM32 4 174 #endif /* _DEV_ISA_ISAPNPREG_H_ */ 175 176 /* 177 * ISA PnP-specific structures. 178 */ 179 struct isapnp_softc { 180 struct device sc_dev; 181 TAILQ_HEAD(, isadev) 182 sc_subdevs; /* list of all children */ 183 184 bus_space_tag_t sc_iot; /* isa io space tag */ 185 bus_space_tag_t sc_memt; /* isa mem space tag */ 186 #if NISADMA > 0 187 bus_dma_tag_t sc_dmat; /* isa DMA tag */ 188 #endif /* NISADMA > 0 */ 189 190 int sc_read_port; 191 bus_space_handle_t sc_addr_ioh; 192 bus_space_handle_t sc_wrdata_ioh; 193 bus_space_handle_t sc_read_ioh; 194 bus_space_handle_t sc_memh; 195 u_int8_t sc_ncards; 196 u_int8_t sc_id[ISAPNP_MAX_CARDS][ISAPNP_SERIAL_SIZE]; 197 }; 198 199 struct isapnp_region { 200 bus_space_handle_t h; 201 u_int32_t base; 202 203 u_int32_t minbase; 204 u_int32_t maxbase; 205 u_int32_t length; 206 u_int32_t align; 207 u_int8_t flags; 208 }; 209 210 struct isapnp_pin { 211 int16_t num; 212 u_int8_t flags:4; 213 u_int8_t type:4; 214 u_int16_t bits; 215 }; 216 217 struct isapnp_knowndev { 218 const char pnpid[8]; 219 const char driver[5]; 220 }; 221 222 /* 223 * ISA bus attach arguments 224 */ 225 struct isabus_attach_args { 226 char *iba_busname; /* XXX should be common */ 227 bus_space_tag_t iba_iot; /* isa i/o space tag */ 228 bus_space_tag_t iba_memt; /* isa mem space tag */ 229 #if NISADMA > 0 230 bus_dma_tag_t iba_dmat; /* isa DMA tag */ 231 #endif 232 isa_chipset_tag_t iba_ic; 233 }; 234 235 /* 236 * ISA/ISA PnP shared driver attach arguments 237 */ 238 struct isa_attach_args { 239 struct device *ia_isa; /* isa device */ 240 bus_space_tag_t ia_iot; /* isa i/o space tag */ 241 bus_space_tag_t ia_memt; /* isa mem space tag */ 242 #if NISADMA > 0 243 bus_dma_tag_t ia_dmat; /* DMA tag */ 244 #endif 245 bus_space_handle_t ia_delaybah; /* i/o handle for `delay port' */ 246 247 isa_chipset_tag_t ia_ic; 248 249 /* 250 * ISA PnP configuration support. `ipa_' prefixes are used to denote 251 * PnP specific members of this structure. 252 */ 253 struct isa_attach_args *ipa_sibling; 254 struct isa_attach_args *ipa_child; 255 256 char ipa_devident[ISAPNP_MAX_IDENT]; 257 char ipa_devlogic[ISAPNP_MAX_DEVCLASS]; 258 char ipa_devcompat[ISAPNP_MAX_DEVCLASS]; 259 char ipa_devclass[ISAPNP_MAX_DEVCLASS]; 260 261 u_char ipa_pref; 262 u_char ipa_devnum; 263 264 u_char ipa_nio; 265 u_char ipa_nirq; 266 u_char ipa_ndrq; 267 u_char ipa_nmem; 268 u_char ipa_nmem32; 269 270 struct isapnp_region ipa_io[ISAPNP_NUM_IO]; 271 struct isapnp_region ipa_mem[ISAPNP_NUM_MEM]; 272 struct isapnp_region ipa_mem32[ISAPNP_NUM_MEM32]; 273 struct isapnp_pin ipa_irq[ISAPNP_NUM_IRQ]; 274 struct isapnp_pin ipa_drq[ISAPNP_NUM_DRQ]; 275 276 /* 277 * Compatibility defines for ISA drivers. 278 */ 279 #define ia_iobase ipa_io[0].base 280 #define ia_iosize ipa_io[0].length 281 #define ia_ioh ipa_io[0].h 282 #define ia_irq ipa_irq[0].num 283 #define ia_drq ipa_drq[0].num 284 #define ia_drq2 ipa_drq[1].num 285 #define ia_maddr ipa_mem[0].base 286 #define ia_msize ipa_mem[0].length 287 #define ia_memh ipa_mem[0].h 288 289 void *ia_aux; /* driver specific */ 290 }; 291 292 #define IOBASEUNK -1 /* i/o address is unknown */ 293 #define IRQUNK -1 /* interrupt request line is unknown */ 294 #define DRQUNK -1 /* DMA request line is unknown */ 295 #define MADDRUNK -1 /* shared memory address is unknown */ 296 297 /* 298 * Per-device ISA variables 299 */ 300 struct isadev { 301 struct device *id_dev; /* back pointer to generic */ 302 TAILQ_ENTRY(isadev) 303 id_bchain; /* bus chain */ 304 }; 305 306 /* 307 * ISA master bus 308 */ 309 struct isa_softc { 310 struct device sc_dev; /* base device */ 311 TAILQ_HEAD(, isadev) 312 sc_subdevs; /* list of all children */ 313 314 bus_space_tag_t sc_iot; /* isa io space tag */ 315 bus_space_tag_t sc_memt; /* isa mem space tag */ 316 #if NISADMA > 0 317 bus_dma_tag_t sc_dmat; /* isa DMA tag */ 318 #endif /* NISADMA > 0 */ 319 320 isa_chipset_tag_t sc_ic; 321 322 #if NISADMA > 0 323 /* 324 * Bitmap representing the DRQ channels available 325 * for ISA. 326 */ 327 int sc_drqmap; 328 #define sc_drq sc_drqmap /* XXX compatibility mode */ 329 330 bus_space_handle_t sc_dma1h; /* i/o handle for DMA controller #1 */ 331 bus_space_handle_t sc_dma2h; /* i/o handle for DMA controller #2 */ 332 bus_space_handle_t sc_dmapgh; /* i/o handle for DMA page registers */ 333 334 /* 335 * DMA maps used for the 8 DMA channels. 336 */ 337 bus_dmamap_t sc_dmamaps[8]; 338 bus_size_t sc_dmalength[8]; 339 340 int sc_dmareads; /* state for isa_dmadone() */ 341 int sc_dmafinished; /* DMA completion state */ 342 #endif /* NISADMA > 0 */ 343 344 /* 345 * This i/o handle is used to map port 0x84, which is 346 * read to provide a 1.25us delay. This access handle 347 * is mapped in isaattach(), and exported to drivers 348 * via isa_attach_args. 349 */ 350 bus_space_handle_t sc_delaybah; 351 }; 352 353 #define ISA_DRQ_ISFREE(isadev, drq) \ 354 ((((struct isa_softc *)(isadev))->sc_drqmap & (1 << (drq))) == 0) 355 356 #define ISA_DRQ_ALLOC(isadev, drq) \ 357 ((struct isa_softc *)(isadev))->sc_drqmap |= (1 << (drq)) 358 359 #define ISA_DRQ_FREE(isadev, drq) \ 360 ((struct isa_softc *)(isadev))->sc_drqmap &= ~(1 << (drq)) 361 362 #define cf_iobase cf_loc[0] 363 #define cf_iosize cf_loc[1] 364 #define cf_maddr cf_loc[2] 365 #define cf_msize cf_loc[3] 366 #define cf_irq cf_loc[4] 367 #define cf_drq cf_loc[5] 368 #define cf_drq2 cf_loc[6] 369 370 /* 371 * ISA interrupt handler manipulation. 372 * 373 * To establish an ISA interrupt handler, a driver calls isa_intr_establish() 374 * with the interrupt number, type, level, function, and function argument of 375 * the interrupt it wants to handle. Isa_intr_establish() returns an opaque 376 * handle to an event descriptor if it succeeds, and invokes panic() if it 377 * fails. (XXX It should return NULL, then drivers should handle that, but 378 * what should they do?) Interrupt handlers should return 0 for "interrupt 379 * not for me", 1 for "I took care of it", or -1 for "I guess it was mine, 380 * but I wasn't expecting it." 381 * 382 * To remove an interrupt handler, the driver calls isa_intr_disestablish() 383 * with the handle returned by isa_intr_establish() for that handler. 384 */ 385 386 /* ISA interrupt sharing types */ 387 char *isa_intr_typename(int type); 388 389 void isascan(struct device *parent, void *match); 390 int isaprint(void *, const char *); 391 392 /* 393 * Some ISA devices (e.g. on a VLB) can perform 32-bit DMA. This 394 * flag is passed to bus_dmamap_create() to indicate that fact. 395 */ 396 #define ISABUS_DMA_32BIT BUS_DMA_BUS1 397 398 /* 399 * ISA PnP prototypes and support macros. 400 */ 401 static __inline void isapnp_write_reg(struct isapnp_softc *, int, u_char); 402 static __inline u_char isapnp_read_reg(struct isapnp_softc *, int); 403 404 static __inline void 405 isapnp_write_reg(struct isapnp_softc *sc, int r, u_char v) 406 { 407 ISAPNP_WRITE_ADDR(sc, r); 408 ISAPNP_WRITE_DATA(sc, v); 409 } 410 411 static __inline u_char 412 isapnp_read_reg(struct isapnp_softc *sc, int r) 413 { 414 ISAPNP_WRITE_ADDR(sc, r); 415 return ISAPNP_READ_DATA(sc); 416 } 417 418 struct isa_attach_args * 419 isapnp_get_resource(struct isapnp_softc *, int, struct isa_attach_args *); 420 char *isapnp_id_to_vendor(char *, const u_char *); 421 422 int isapnp_config(bus_space_tag_t, bus_space_tag_t, 423 struct isa_attach_args *); 424 void isapnp_unconfig(bus_space_tag_t, bus_space_tag_t, 425 struct isa_attach_args *); 426 427 void isapnp_isa_attach_hook(struct isa_softc *); 428 #ifdef DEBUG_ISAPNP 429 void isapnp_print_mem(const char *, const struct isapnp_region *); 430 void isapnp_print_io(const char *, const struct isapnp_region *); 431 void isapnp_print_irq(const char *, const struct isapnp_pin *); 432 void isapnp_print_drq(const char *, const struct isapnp_pin *); 433 void isapnp_print_dep_start(const char *, const u_char); 434 void isapnp_print_attach(const struct isa_attach_args *); 435 void isapnp_get_config(struct isapnp_softc *, 436 struct isa_attach_args *); 437 void isapnp_print_config(const struct isa_attach_args *); 438 #endif /* DEBUG_ISAPNP */ 439 #endif /* _DEV_ISA_ISAVAR_H_ */ 440