Home | History | Annotate | Line # | Download | only in isapnp
isapnpvar.h revision 1.17
      1 /*	$NetBSD: isapnpvar.h,v 1.17 1998/10/01 00:42:37 jonathan Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Christos Zoulas.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #ifndef _DEV_ISAPNP_ISAPNPVAR_H_
     40 #define _DEV_ISAPNP_ISAPNPVAR_H_
     41 
     42 /*
     43  * ISA Plug and Play register definitions;
     44  * From Plug and Play ISA Specification V1.0a, May 5 1994
     45  */
     46 
     47 /*
     48  * Structures and definitions needed by the machine-dependent header.
     49  */
     50 struct isapnp_softc;
     51 
     52 #if (alpha + arc + arm32 + atari + bebox + i386 != 1)
     53 ERROR: COMPILING FOR UNSUPPORTED MACHINE, OR MORE THAN ONE.
     54 #endif
     55 #if alpha
     56 #include <alpha/isa/isapnp_machdep.h>
     57 #endif
     58 #if arc
     59 #include <arc/isa/isapnp_machdep.h>
     60 #endif
     61 #if arm32
     62 #include <arm32/isa/isapnp_machdep.h>
     63 #endif
     64 #if atari
     65 #include <atari/isa/isapnp_machdep.h>
     66 #endif
     67 #if bebox
     68 #include <bebox/isa/isapnp_machdep.h>
     69 #endif
     70 #if i386
     71 #include <i386/isa/isapnp_machdep.h>
     72 #endif
     73 
     74 #ifndef _KERNEL
     75 
     76 # include <stdlib.h>
     77 # include <string.h>
     78 # include <unistd.h>
     79 
     80 # define ISAPNP_WRITE_ADDR(sc, v) outb(ISAPNP_ADDR, v)
     81 # define ISAPNP_WRITE_DATA(sc, v) outb(ISAPNP_WRDATA, v)
     82 # define ISAPNP_READ_DATA(sc) inb(sc->sc_read_port)
     83 
     84 # define DELAY(us) usleep(us)
     85 # define ISAPNP_MALLOC(a) malloc(a)
     86 # define ISAPNP_FREE(a) free(a)
     87 
     88 # define panic printf
     89 
     90 #else
     91 
     92 /* XXX */
     93 # define memset(a, b, c)	bzero(a, c)
     94 
     95 # define ISAPNP_WRITE_ADDR(sc, v) \
     96     bus_space_write_1(sc->sc_iot, sc->sc_addr_ioh, 0, v)
     97 # define ISAPNP_WRITE_DATA(sc, v) \
     98     bus_space_write_1(sc->sc_iot, sc->sc_wrdata_ioh, 0, v)
     99 # define ISAPNP_READ_DATA(sc) \
    100     bus_space_read_1(sc->sc_iot, sc->sc_read_ioh, 0)
    101 
    102 # define ISAPNP_MALLOC(a) malloc(a, M_DEVBUF, M_WAITOK)
    103 # define ISAPNP_FREE(a) free(a, M_DEVBUF)
    104 
    105 #endif
    106 
    107 #ifdef DEBUG_ISAPNP
    108 # define DPRINTF(a) printf a
    109 #else
    110 # define DPRINTF(a)
    111 #endif
    112 
    113 struct isapnp_softc {
    114 	struct device		sc_dev;
    115 	int			sc_read_port;
    116 	bus_space_tag_t		sc_iot;
    117 	bus_space_tag_t		sc_memt;
    118 	isa_chipset_tag_t	sc_ic;
    119 	bus_dma_tag_t		sc_dmat;
    120 	bus_space_handle_t	sc_addr_ioh;
    121 	bus_space_handle_t	sc_wrdata_ioh;
    122 	bus_space_handle_t	sc_read_ioh;
    123 	bus_space_handle_t	sc_memh;
    124 	u_int8_t		sc_ncards;
    125     	u_int8_t		sc_id[ISAPNP_MAX_CARDS][ISAPNP_SERIAL_SIZE];
    126 };
    127 
    128 struct isapnp_region {
    129 	bus_space_handle_t h;
    130 	u_int32_t base;
    131 
    132 	u_int32_t minbase;
    133 	u_int32_t maxbase;
    134 	u_int32_t length;
    135 	u_int32_t align;
    136 	u_int8_t  flags;
    137 };
    138 
    139 struct isapnp_pin {
    140 	u_int8_t  num;
    141 	u_int8_t  flags:4;
    142 	u_int8_t  type:4;
    143 	u_int16_t bits;
    144 };
    145 
    146 struct isapnp_attach_args {
    147 	bus_space_tag_t ipa_iot;	/* isa i/o space tag */
    148 	bus_space_tag_t ipa_memt;	/* isa mem space tag */
    149 	bus_dma_tag_t	ipa_dmat;	/* isa dma tag */
    150 
    151 	isa_chipset_tag_t ipa_ic;
    152 
    153 	struct isapnp_attach_args *ipa_sibling;
    154 	struct isapnp_attach_args *ipa_child;
    155 
    156 	char	ipa_devident[ISAPNP_MAX_IDENT];
    157 	char	ipa_devlogic[ISAPNP_MAX_DEVCLASS];
    158 	char	ipa_devcompat[ISAPNP_MAX_DEVCLASS];
    159 	char	ipa_devclass[ISAPNP_MAX_DEVCLASS];
    160 
    161 	u_char	ipa_pref;
    162 	u_char	ipa_devnum;
    163 
    164 	u_char	ipa_nio;
    165 	u_char	ipa_nirq;
    166 	u_char	ipa_ndrq;
    167 	u_char	ipa_nmem;
    168 	u_char	ipa_nmem32;
    169 
    170 	struct isapnp_region	ipa_io[ISAPNP_NUM_IO];
    171 	struct isapnp_region	ipa_mem[ISAPNP_NUM_MEM];
    172 	struct isapnp_region	ipa_mem32[ISAPNP_NUM_MEM32];
    173 	struct isapnp_pin	ipa_irq[ISAPNP_NUM_IRQ];
    174 	struct isapnp_pin	ipa_drq[ISAPNP_NUM_DRQ];
    175 };
    176 
    177 static __inline void isapnp_write_reg __P((struct isapnp_softc *, int, u_char));
    178 static __inline u_char isapnp_read_reg __P((struct isapnp_softc *, int));
    179 
    180 static __inline void
    181 isapnp_write_reg(sc, r, v)
    182 	struct isapnp_softc *sc;
    183 	int r;
    184 	u_char v;
    185 {
    186 	ISAPNP_WRITE_ADDR(sc, r);
    187 	ISAPNP_WRITE_DATA(sc, v);
    188 }
    189 
    190 static __inline u_char
    191 isapnp_read_reg(sc, r)
    192 	struct isapnp_softc *sc;
    193 {
    194 	ISAPNP_WRITE_ADDR(sc, r);
    195 	return ISAPNP_READ_DATA(sc);
    196 }
    197 
    198 struct isapnp_attach_args *
    199     isapnp_get_resource __P((struct isapnp_softc *, int));
    200 char *isapnp_id_to_vendor __P((char *, const u_char *));
    201 
    202 int isapnp_config __P((bus_space_tag_t, bus_space_tag_t,
    203     struct isapnp_attach_args *));
    204 void isapnp_unconfig __P((bus_space_tag_t, bus_space_tag_t,
    205     struct isapnp_attach_args *));
    206 #ifdef _KERNEL
    207 struct isapnp_devinfo;
    208 int isapnp_devmatch __P((const struct isapnp_attach_args *,
    209     const struct isapnp_devinfo *));
    210 void isapnp_isa_attach_hook __P((struct isa_softc *));
    211 #endif
    212 
    213 #ifdef DEBUG_ISAPNP
    214 void isapnp_print_mem __P((const char *, const struct isapnp_region *));
    215 void isapnp_print_io __P((const char *, const struct isapnp_region *));
    216 void isapnp_print_irq __P((const char *, const struct isapnp_pin *));
    217 void isapnp_print_drq __P((const char *, const struct isapnp_pin *));
    218 void isapnp_print_dep_start __P((const char *, const u_char));
    219 void isapnp_print_attach __P((const struct isapnp_attach_args *));
    220 void isapnp_get_config __P((struct isapnp_softc *,
    221 	struct isapnp_attach_args *));
    222 void isapnp_print_config __P((const struct isapnp_attach_args *));
    223 #endif
    224 
    225 #endif /* ! _DEV_ISAPNP_ISAPNPVAR_H_ */
    226