Home | History | Annotate | Line # | Download | only in isapnp
isapnpvar.h revision 1.15
      1 /*	$NetBSD: isapnpvar.h,v 1.15 1998/07/31 04:56:55 thorpej Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1996 Christos Zoulas.  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 disclaimer.
     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 Christos Zoulas.
     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 #ifndef _DEV_ISAPNP_ISAPNPVAR_H_
     33 #define _DEV_ISAPNP_ISAPNPVAR_H_
     34 
     35 /*
     36  * ISA Plug and Play register definitions;
     37  * From Plug and Play ISA Specification V1.0a, May 5 1994
     38  */
     39 
     40 /*
     41  * Structures and definitions needed by the machine-dependent header.
     42  */
     43 struct isapnp_softc;
     44 
     45 #if (alpha + arm32 + atari + bebox + i386 != 1)
     46 ERROR: COMPILING FOR UNSUPPORTED MACHINE, OR MORE THAN ONE.
     47 #endif
     48 #if alpha
     49 #include <alpha/isa/isapnp_machdep.h>
     50 #endif
     51 #if arm32
     52 #include <arm32/isa/isapnp_machdep.h>
     53 #endif
     54 #if atari
     55 #include <atari/isa/isapnp_machdep.h>
     56 #endif
     57 #if bebox
     58 #include <bebox/isa/isapnp_machdep.h>
     59 #endif
     60 #if i386
     61 #include <i386/isa/isapnp_machdep.h>
     62 #endif
     63 
     64 #ifndef _KERNEL
     65 
     66 # include <stdlib.h>
     67 # include <string.h>
     68 # include <unistd.h>
     69 
     70 # define ISAPNP_WRITE_ADDR(sc, v) outb(ISAPNP_ADDR, v)
     71 # define ISAPNP_WRITE_DATA(sc, v) outb(ISAPNP_WRDATA, v)
     72 # define ISAPNP_READ_DATA(sc) inb(sc->sc_read_port)
     73 
     74 # define DELAY(us) usleep(us)
     75 # define ISAPNP_MALLOC(a) malloc(a)
     76 # define ISAPNP_FREE(a) free(a)
     77 
     78 # define panic printf
     79 
     80 #else
     81 
     82 /* XXX */
     83 # define memset(a, b, c)	bzero(a, c)
     84 
     85 # define ISAPNP_WRITE_ADDR(sc, v) \
     86     bus_space_write_1(sc->sc_iot, sc->sc_addr_ioh, 0, v)
     87 # define ISAPNP_WRITE_DATA(sc, v) \
     88     bus_space_write_1(sc->sc_iot, sc->sc_wrdata_ioh, 0, v)
     89 # define ISAPNP_READ_DATA(sc) \
     90     bus_space_read_1(sc->sc_iot, sc->sc_read_ioh, 0)
     91 
     92 # define ISAPNP_MALLOC(a) malloc(a, M_DEVBUF, M_WAITOK)
     93 # define ISAPNP_FREE(a) free(a, M_DEVBUF)
     94 
     95 #endif
     96 
     97 #ifdef DEBUG_ISAPNP
     98 # define DPRINTF(a) printf a
     99 #else
    100 # define DPRINTF(a)
    101 #endif
    102 
    103 struct isapnp_softc {
    104 	struct device		sc_dev;
    105 	int			sc_read_port;
    106 	bus_space_tag_t		sc_iot;
    107 	bus_space_tag_t		sc_memt;
    108 	isa_chipset_tag_t	sc_ic;
    109 	bus_dma_tag_t		sc_dmat;
    110 	bus_space_handle_t	sc_addr_ioh;
    111 	bus_space_handle_t	sc_wrdata_ioh;
    112 	bus_space_handle_t	sc_read_ioh;
    113 	bus_space_handle_t	sc_memh;
    114 	u_int8_t		sc_ncards;
    115     	u_int8_t		sc_id[ISAPNP_MAX_CARDS][ISAPNP_SERIAL_SIZE];
    116 };
    117 
    118 struct isapnp_region {
    119 	bus_space_handle_t h;
    120 	u_int32_t base;
    121 
    122 	u_int32_t minbase;
    123 	u_int32_t maxbase;
    124 	u_int32_t length;
    125 	u_int32_t align;
    126 	u_int8_t  flags;
    127 };
    128 
    129 struct isapnp_pin {
    130 	u_int8_t  num;
    131 	u_int8_t  flags:4;
    132 	u_int8_t  type:4;
    133 	u_int16_t bits;
    134 };
    135 
    136 struct isapnp_attach_args {
    137 	bus_space_tag_t ipa_iot;	/* isa i/o space tag */
    138 	bus_space_tag_t ipa_memt;	/* isa mem space tag */
    139 	bus_dma_tag_t	ipa_dmat;	/* isa dma tag */
    140 
    141 	isa_chipset_tag_t ipa_ic;
    142 
    143 	struct isapnp_attach_args *ipa_sibling;
    144 	struct isapnp_attach_args *ipa_child;
    145 
    146 	char	ipa_devident[ISAPNP_MAX_IDENT];
    147 	char	ipa_devlogic[ISAPNP_MAX_DEVCLASS];
    148 	char	ipa_devcompat[ISAPNP_MAX_DEVCLASS];
    149 	char	ipa_devclass[ISAPNP_MAX_DEVCLASS];
    150 
    151 	u_char	ipa_pref;
    152 	u_char	ipa_devnum;
    153 
    154 	u_char	ipa_nio;
    155 	u_char	ipa_nirq;
    156 	u_char	ipa_ndrq;
    157 	u_char	ipa_nmem;
    158 	u_char	ipa_nmem32;
    159 
    160 	struct isapnp_region	ipa_io[ISAPNP_NUM_IO];
    161 	struct isapnp_region	ipa_mem[ISAPNP_NUM_MEM];
    162 	struct isapnp_region	ipa_mem32[ISAPNP_NUM_MEM32];
    163 	struct isapnp_pin	ipa_irq[ISAPNP_NUM_IRQ];
    164 	struct isapnp_pin	ipa_drq[ISAPNP_NUM_DRQ];
    165 };
    166 
    167 static __inline void isapnp_write_reg __P((struct isapnp_softc *, int, u_char));
    168 static __inline u_char isapnp_read_reg __P((struct isapnp_softc *, int));
    169 
    170 static __inline void
    171 isapnp_write_reg(sc, r, v)
    172 	struct isapnp_softc *sc;
    173 	int r;
    174 	u_char v;
    175 {
    176 	ISAPNP_WRITE_ADDR(sc, r);
    177 	ISAPNP_WRITE_DATA(sc, v);
    178 }
    179 
    180 static __inline u_char
    181 isapnp_read_reg(sc, r)
    182 	struct isapnp_softc *sc;
    183 {
    184 	ISAPNP_WRITE_ADDR(sc, r);
    185 	return ISAPNP_READ_DATA(sc);
    186 }
    187 
    188 struct isapnp_attach_args *
    189     isapnp_get_resource __P((struct isapnp_softc *, int));
    190 char *isapnp_id_to_vendor __P((char *, const u_char *));
    191 
    192 int isapnp_config __P((bus_space_tag_t, bus_space_tag_t,
    193     struct isapnp_attach_args *));
    194 void isapnp_unconfig __P((bus_space_tag_t, bus_space_tag_t,
    195     struct isapnp_attach_args *));
    196 #ifdef _KERNEL
    197 struct isapnp_devinfo;
    198 int isapnp_devmatch __P((const struct isapnp_attach_args *,
    199     const struct isapnp_devinfo *));
    200 void isapnp_isa_attach_hook __P((struct isa_softc *));
    201 #endif
    202 
    203 #ifdef DEBUG_ISAPNP
    204 void isapnp_print_mem __P((const char *, const struct isapnp_region *));
    205 void isapnp_print_io __P((const char *, const struct isapnp_region *));
    206 void isapnp_print_irq __P((const char *, const struct isapnp_pin *));
    207 void isapnp_print_drq __P((const char *, const struct isapnp_pin *));
    208 void isapnp_print_dep_start __P((const char *, const u_char));
    209 void isapnp_print_attach __P((const struct isapnp_attach_args *));
    210 void isapnp_get_config __P((struct isapnp_softc *,
    211 	struct isapnp_attach_args *));
    212 void isapnp_print_config __P((const struct isapnp_attach_args *));
    213 #endif
    214 
    215 #endif /* ! _DEV_ISAPNP_ISAPNPVAR_H_ */
    216