xref: /netbsd/sys/dev/isapnp/isapnpvar.h (revision bcb6c9c7)
1 /*	$NetBSD: isapnpvar.h,v 1.29 2022/09/25 17:20:03 thorpej 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 # include <sys/malloc.h>
66 
67 # define ISAPNP_WRITE_ADDR(sc, v) \
68     bus_space_write_1(sc->sc_iot, sc->sc_addr_ioh, 0, v)
69 # define ISAPNP_WRITE_DATA(sc, v) \
70     bus_space_write_1(sc->sc_iot, sc->sc_wrdata_ioh, 0, v)
71 # define ISAPNP_READ_DATA(sc) \
72     bus_space_read_1(sc->sc_iot, sc->sc_read_ioh, 0)
73 
74 # define ISAPNP_MALLOC(a) malloc(a, M_DEVBUF, M_WAITOK)
75 # define ISAPNP_FREE(a) free(a, M_DEVBUF)
76 
77 #endif
78 
79 #ifdef DEBUG_ISAPNP
80 # define DPRINTF(a) printf a
81 #else
82 # define DPRINTF(a)
83 #endif
84 
85 struct isapnp_softc {
86 	device_t		sc_dev;
87 	int			sc_read_port;
88 	bus_space_tag_t		sc_iot;
89 	bus_space_tag_t		sc_memt;
90 	isa_chipset_tag_t	sc_ic;
91 	bus_dma_tag_t		sc_dmat;
92 	bus_space_handle_t	sc_addr_ioh;
93 	bus_space_handle_t	sc_wrdata_ioh;
94 	bus_space_handle_t	sc_read_ioh;
95 	bus_space_handle_t	sc_memh;
96 	u_int8_t		sc_ncards;
97     	u_int8_t		sc_id[ISAPNP_MAX_CARDS][ISAPNP_SERIAL_SIZE];
98 };
99 
100 struct isapnp_region {
101 	bus_space_handle_t h;
102 	u_int32_t base;
103 
104 	u_int32_t minbase;
105 	u_int32_t maxbase;
106 	u_int32_t length;
107 	u_int32_t align;
108 	u_int8_t  flags;
109 };
110 
111 struct isapnp_pin {
112 	u_int8_t  num;
113 	u_int8_t  flags:4;
114 	u_int8_t  type:4;
115 	u_int16_t bits;
116 };
117 
118 struct isapnp_attach_args {
119 	bus_space_tag_t ipa_iot;	/* isa i/o space tag */
120 	bus_space_tag_t ipa_memt;	/* isa mem space tag */
121 	bus_dma_tag_t	ipa_dmat;	/* isa dma tag */
122 
123 	isa_chipset_tag_t ipa_ic;
124 
125 	struct isapnp_attach_args *ipa_sibling;
126 	struct isapnp_attach_args *ipa_child;
127 
128 	char	ipa_devident[ISAPNP_MAX_IDENT];
129 	char	ipa_devlogic[ISAPNP_MAX_DEVCLASS];
130 	char	ipa_devcompat[ISAPNP_MAX_DEVCLASS];
131 	char	ipa_devclass[ISAPNP_MAX_DEVCLASS];
132 
133 	u_char	ipa_pref;
134 	u_char	ipa_devnum;
135 
136 	u_char	ipa_nio;
137 	u_char	ipa_nirq;
138 	u_char	ipa_ndrq;
139 	u_char	ipa_nmem;
140 	u_char	ipa_nmem32;
141 
142 	struct isapnp_region	ipa_io[ISAPNP_NUM_IO];
143 	struct isapnp_region	ipa_mem[ISAPNP_NUM_MEM];
144 	struct isapnp_region	ipa_mem32[ISAPNP_NUM_MEM32];
145 	struct isapnp_pin	ipa_irq[ISAPNP_NUM_IRQ];
146 	struct isapnp_pin	ipa_drq[ISAPNP_NUM_DRQ];
147 };
148 
149 static __inline void isapnp_write_reg(struct isapnp_softc *, int, u_char);
150 static __inline u_char isapnp_read_reg(struct isapnp_softc *, int);
151 
152 static __inline void
isapnp_write_reg(struct isapnp_softc * sc,int r,u_char v)153 isapnp_write_reg(struct isapnp_softc *sc, int r, u_char v)
154 {
155 	ISAPNP_WRITE_ADDR(sc, r);
156 	ISAPNP_WRITE_DATA(sc, v);
157 }
158 
159 static __inline u_char
isapnp_read_reg(struct isapnp_softc * sc,int r)160 isapnp_read_reg(struct isapnp_softc *sc, int r)
161 {
162 	ISAPNP_WRITE_ADDR(sc, r);
163 	return ISAPNP_READ_DATA(sc);
164 }
165 
166 struct isapnp_attach_args *
167     isapnp_get_resource(struct isapnp_softc *, int);
168 char *isapnp_id_to_vendor(char *, const u_char *);
169 
170 int isapnp_config(bus_space_tag_t, bus_space_tag_t,
171     struct isapnp_attach_args *);
172 void isapnp_unconfig(bus_space_tag_t, bus_space_tag_t,
173     struct isapnp_attach_args *);
174 #ifdef _KERNEL
175 struct isapnp_devinfo;
176 int isapnp_devmatch(const struct isapnp_attach_args *,
177     const struct isapnp_devinfo *, int *);
178 void isapnp_isa_attach_hook(struct isa_softc *);
179 #endif
180 
181 #ifdef DEBUG_ISAPNP
182 void isapnp_print_mem(const char *, const struct isapnp_region *);
183 void isapnp_print_io(const char *, const struct isapnp_region *);
184 void isapnp_print_irq(const char *, const struct isapnp_pin *);
185 void isapnp_print_drq(const char *, const struct isapnp_pin *);
186 void isapnp_print_dep_start(const char *, const u_char);
187 void isapnp_print_attach(const struct isapnp_attach_args *);
188 void isapnp_get_config(struct isapnp_softc *, struct isapnp_attach_args *);
189 void isapnp_print_config(const struct isapnp_attach_args *);
190 #endif
191 
192 #endif /* ! _DEV_ISAPNP_ISAPNPVAR_H_ */
193