Home | History | Annotate | Line # | Download | only in isapnp
isapnpvar.h revision 1.1
      1 /*	$NetBSD: isapnpvar.h,v 1.1 1997/01/16 22:01:05 christos 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 (i386 != 1)
     46 ERROR: COMPILING FOR UNSUPPORTED MACHINE, OR MORE THAN ONE.
     47 #endif
     48 #if i386
     49 #include <i386/isa/isapnp_machdep.h>
     50 #endif
     51 
     52 #ifndef _KERNEL
     53 
     54 # include <string.h>
     55 # include <unistd.h>
     56 # include <stdlib.h>
     57 
     58 # define ISAPNP_WRITE_ADDR(sc, v) outb(ISAPNP_ADDR, v)
     59 # define ISAPNP_WRITE_DATA(sc, v) outb(ISAPNP_WRDATA, v)
     60 # define ISAPNP_READ_DATA(sc) inb(sc->sc_read_port)
     61 
     62 # define DELAY(us) usleep(us)
     63 # define ISAPNP_MALLOC(a) malloc(a)
     64 # define ISAPNP_FREE(a) free(a)
     65 
     66 # define bus_space_map(a, b, c, d, e)	0
     67 # define bus_space_unmap(a, b, c)
     68 # define panic printf
     69 
     70 #else
     71 
     72 /* XXX */
     73 # define memset(a, b, c)	bzero(a, c)
     74 
     75 # define ISAPNP_WRITE_ADDR(sc, v) \
     76     bus_space_write_1(sc->sc_iot, sc->sc_addr_ioh, 0, v)
     77 #define ISAPNP_WRITE_DATA(sc, v) \
     78     bus_space_write_1(sc->sc_iot, sc->sc_wrdata_ioh, 0, v)
     79 #define ISAPNP_READ_DATA(sc) \
     80     bus_space_read_1(sc->sc_iot, sc->sc_read_ioh, 0)
     81 
     82 #define ISAPNP_MALLOC(a) malloc(a, M_DEVBUF, M_WAITOK)
     83 #define ISAPNP_FREE(a)	free(a, M_DEVBUF)
     84 
     85 #endif
     86 
     87 #ifdef DEBUG_ISAPNP
     88 # define DPRINTF(a) printf a
     89 #else
     90 # define DPRINTF(a)
     91 #endif
     92 
     93 struct isapnp_softc {
     94 	struct device		sc_dev;
     95 	int			sc_read_port;
     96 	bus_space_tag_t		sc_iot;
     97 	bus_space_tag_t		sc_memt;
     98 	bus_space_handle_t	sc_addr_ioh;
     99 	bus_space_handle_t	sc_wrdata_ioh;
    100 	bus_space_handle_t	sc_read_ioh;
    101 	bus_space_handle_t	sc_memh;
    102 	u_int8_t		sc_ncards;
    103     	u_int8_t		sc_id[ISAPNP_MAX_CARDS][ISAPNP_SERIAL_SIZE];
    104 };
    105 
    106 struct isapnp_region {
    107 	bus_space_handle_t h;
    108 	u_int32_t base;
    109 
    110 	u_int32_t minbase;
    111 	u_int32_t maxbase;
    112 	u_int32_t length;
    113 	u_int32_t align;
    114 	u_int8_t  flags;
    115 };
    116 
    117 struct isapnp_pin {
    118 	u_int8_t num;
    119 
    120 	u_int16_t bits;
    121 	u_int8_t flags;
    122 };
    123 
    124 struct isapnp_attach_args {
    125 	bus_space_tag_t ipa_iot;	/* isa i/o space tag */
    126 	bus_space_tag_t ipa_memt;	/* isa mem space tag */
    127 
    128 	isa_chipset_tag_t ipa_ic;
    129 
    130 	struct isapnp_attach_args *ipa_next;
    131 
    132 	char	ipa_devident[ISAPNP_MAX_IDENT];
    133 	char	ipa_devlogic[ISAPNP_MAX_DEVCLASS];
    134 	char	ipa_devclass[ISAPNP_MAX_DEVCLASS];
    135 
    136 	u_char	ipa_pref;
    137 	u_char	ipa_devnum;
    138 
    139 	u_char	ipa_nio;
    140 	u_char	ipa_nirq;
    141 	u_char	ipa_ndrq;
    142 	u_char	ipa_nmem;
    143 	u_char	ipa_nmem32;
    144 
    145 	struct isapnp_region	ipa_io[ISAPNP_NUM_IO];
    146 	struct isapnp_region	ipa_mem[ISAPNP_NUM_MEM];
    147 	struct isapnp_region	ipa_mem32[ISAPNP_NUM_MEM32];
    148 	struct isapnp_pin	ipa_irq[ISAPNP_NUM_IRQ];
    149 	struct isapnp_pin	ipa_drq[ISAPNP_NUM_DRQ];
    150 };
    151 
    152 static __inline void isapnp_write_reg __P((struct isapnp_softc *, int, u_char));
    153 static __inline u_char isapnp_read_reg __P((struct isapnp_softc *, int));
    154 
    155 static __inline void
    156 isapnp_write_reg(sc, r, v)
    157 	struct isapnp_softc *sc;
    158 	int r;
    159 	u_char v;
    160 {
    161 	ISAPNP_WRITE_ADDR(sc, r);
    162 	ISAPNP_WRITE_DATA(sc, v);
    163 }
    164 
    165 static __inline u_char
    166 isapnp_read_reg(sc, r)
    167 	struct isapnp_softc *sc;
    168 {
    169 	ISAPNP_WRITE_ADDR(sc, r);
    170 	return ISAPNP_READ_DATA(sc);
    171 }
    172 
    173 struct isapnp_attach_args *
    174     isapnp_get_resource __P((struct isapnp_softc *, int));
    175 char *isapnp_id_to_vendor __P((char *, const u_char *));
    176 
    177 int isapnp_config __P((bus_space_tag_t, bus_space_tag_t,
    178     struct isapnp_attach_args *));
    179 void isapnp_unconfig __P((bus_space_tag_t, bus_space_tag_t,
    180     struct isapnp_attach_args *));
    181 
    182 #ifdef DEBUG_ISAPNP
    183 void isapnp_print_mem __P((const char *, const struct isapnp_region *));
    184 void isapnp_print_io __P((const char *, const struct isapnp_region *));
    185 void isapnp_print_irq __P((const char *, const struct isapnp_pin *));
    186 void isapnp_print_drq __P((const char *, const struct isapnp_pin *));
    187 void isapnp_print_dep_start __P((const char *, const u_char));
    188 void isapnp_print_attach __P((const struct isapnp_attach_args *));
    189 void isapnp_get_config __P((struct isapnp_softc *,
    190 	struct isapnp_attach_args *));
    191 void isapnp_print_config __P((const struct isapnp_attach_args *));
    192 #endif
    193 
    194 #endif /* ! _DEV_ISAPNP_ISAPNPVAR_H_ */
    195