Home | History | Annotate | Line # | Download | only in isapnp
isapnpvar.h revision 1.28
      1 /*	$NetBSD: isapnpvar.h,v 1.28 2009/03/15 15:45:48 cegger 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  *
     19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29  * 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 #include <machine/isapnp_machdep.h>
     46 
     47 #ifndef _KERNEL
     48 
     49 # include <stdlib.h>
     50 # include <string.h>
     51 # include <unistd.h>
     52 
     53 # define ISAPNP_WRITE_ADDR(sc, v) outb(ISAPNP_ADDR, v)
     54 # define ISAPNP_WRITE_DATA(sc, v) outb(ISAPNP_WRDATA, v)
     55 # define ISAPNP_READ_DATA(sc) inb(sc->sc_read_port)
     56 
     57 # define DELAY(us) usleep(us)
     58 # define ISAPNP_MALLOC(a) malloc(a)
     59 # define ISAPNP_FREE(a) free(a)
     60 
     61 # define panic printf
     62 
     63 #else
     64 
     65 # define ISAPNP_WRITE_ADDR(sc, v) \
     66     bus_space_write_1(sc->sc_iot, sc->sc_addr_ioh, 0, v)
     67 # define ISAPNP_WRITE_DATA(sc, v) \
     68     bus_space_write_1(sc->sc_iot, sc->sc_wrdata_ioh, 0, v)
     69 # define ISAPNP_READ_DATA(sc) \
     70     bus_space_read_1(sc->sc_iot, sc->sc_read_ioh, 0)
     71 
     72 # define ISAPNP_MALLOC(a) malloc(a, M_DEVBUF, M_WAITOK)
     73 # define ISAPNP_FREE(a) free(a, M_DEVBUF)
     74 
     75 #endif
     76 
     77 #ifdef DEBUG_ISAPNP
     78 # define DPRINTF(a) printf a
     79 #else
     80 # define DPRINTF(a)
     81 #endif
     82 
     83 struct isapnp_softc {
     84 	device_t		sc_dev;
     85 	int			sc_read_port;
     86 	bus_space_tag_t		sc_iot;
     87 	bus_space_tag_t		sc_memt;
     88 	isa_chipset_tag_t	sc_ic;
     89 	bus_dma_tag_t		sc_dmat;
     90 	bus_space_handle_t	sc_addr_ioh;
     91 	bus_space_handle_t	sc_wrdata_ioh;
     92 	bus_space_handle_t	sc_read_ioh;
     93 	bus_space_handle_t	sc_memh;
     94 	u_int8_t		sc_ncards;
     95     	u_int8_t		sc_id[ISAPNP_MAX_CARDS][ISAPNP_SERIAL_SIZE];
     96 };
     97 
     98 struct isapnp_region {
     99 	bus_space_handle_t h;
    100 	u_int32_t base;
    101 
    102 	u_int32_t minbase;
    103 	u_int32_t maxbase;
    104 	u_int32_t length;
    105 	u_int32_t align;
    106 	u_int8_t  flags;
    107 };
    108 
    109 struct isapnp_pin {
    110 	u_int8_t  num;
    111 	u_int8_t  flags:4;
    112 	u_int8_t  type:4;
    113 	u_int16_t bits;
    114 };
    115 
    116 struct isapnp_attach_args {
    117 	bus_space_tag_t ipa_iot;	/* isa i/o space tag */
    118 	bus_space_tag_t ipa_memt;	/* isa mem space tag */
    119 	bus_dma_tag_t	ipa_dmat;	/* isa dma tag */
    120 
    121 	isa_chipset_tag_t ipa_ic;
    122 
    123 	struct isapnp_attach_args *ipa_sibling;
    124 	struct isapnp_attach_args *ipa_child;
    125 
    126 	char	ipa_devident[ISAPNP_MAX_IDENT];
    127 	char	ipa_devlogic[ISAPNP_MAX_DEVCLASS];
    128 	char	ipa_devcompat[ISAPNP_MAX_DEVCLASS];
    129 	char	ipa_devclass[ISAPNP_MAX_DEVCLASS];
    130 
    131 	u_char	ipa_pref;
    132 	u_char	ipa_devnum;
    133 
    134 	u_char	ipa_nio;
    135 	u_char	ipa_nirq;
    136 	u_char	ipa_ndrq;
    137 	u_char	ipa_nmem;
    138 	u_char	ipa_nmem32;
    139 
    140 	struct isapnp_region	ipa_io[ISAPNP_NUM_IO];
    141 	struct isapnp_region	ipa_mem[ISAPNP_NUM_MEM];
    142 	struct isapnp_region	ipa_mem32[ISAPNP_NUM_MEM32];
    143 	struct isapnp_pin	ipa_irq[ISAPNP_NUM_IRQ];
    144 	struct isapnp_pin	ipa_drq[ISAPNP_NUM_DRQ];
    145 };
    146 
    147 static __inline void isapnp_write_reg(struct isapnp_softc *, int, u_char);
    148 static __inline u_char isapnp_read_reg(struct isapnp_softc *, int);
    149 
    150 static __inline void
    151 isapnp_write_reg(struct isapnp_softc *sc, int r, u_char v)
    152 {
    153 	ISAPNP_WRITE_ADDR(sc, r);
    154 	ISAPNP_WRITE_DATA(sc, v);
    155 }
    156 
    157 static __inline u_char
    158 isapnp_read_reg(struct isapnp_softc *sc, int r)
    159 {
    160 	ISAPNP_WRITE_ADDR(sc, r);
    161 	return ISAPNP_READ_DATA(sc);
    162 }
    163 
    164 struct isapnp_attach_args *
    165     isapnp_get_resource(struct isapnp_softc *, int);
    166 char *isapnp_id_to_vendor(char *, const u_char *);
    167 
    168 int isapnp_config(bus_space_tag_t, bus_space_tag_t,
    169     struct isapnp_attach_args *);
    170 void isapnp_unconfig(bus_space_tag_t, bus_space_tag_t,
    171     struct isapnp_attach_args *);
    172 #ifdef _KERNEL
    173 struct isapnp_devinfo;
    174 int isapnp_devmatch(const struct isapnp_attach_args *,
    175     const struct isapnp_devinfo *, int *);
    176 void isapnp_isa_attach_hook(struct isa_softc *);
    177 #endif
    178 
    179 #ifdef DEBUG_ISAPNP
    180 void isapnp_print_mem(const char *, const struct isapnp_region *);
    181 void isapnp_print_io(const char *, const struct isapnp_region *);
    182 void isapnp_print_irq(const char *, const struct isapnp_pin *);
    183 void isapnp_print_drq(const char *, const struct isapnp_pin *);
    184 void isapnp_print_dep_start(const char *, const u_char);
    185 void isapnp_print_attach(const struct isapnp_attach_args *);
    186 void isapnp_get_config(struct isapnp_softc *, struct isapnp_attach_args *);
    187 void isapnp_print_config(const struct isapnp_attach_args *);
    188 #endif
    189 
    190 #endif /* ! _DEV_ISAPNP_ISAPNPVAR_H_ */
    191