eisa_machdep.c revision 1.4.4.2 1 1.4.4.2 bouyer /* $NetBSD: eisa_machdep.c,v 1.4.4.2 2000/11/20 19:56:46 bouyer Exp $ */
2 1.4.4.2 bouyer
3 1.4.4.2 bouyer /*-
4 1.4.4.2 bouyer * Copyright (c) 2000 The NetBSD Foundation, Inc.
5 1.4.4.2 bouyer * All rights reserved.
6 1.4.4.2 bouyer *
7 1.4.4.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.4.4.2 bouyer * by Jason R. Thorpe.
9 1.4.4.2 bouyer *
10 1.4.4.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.4.4.2 bouyer * modification, are permitted provided that the following conditions
12 1.4.4.2 bouyer * are met:
13 1.4.4.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.4.4.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.4.4.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.4.4.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.4.4.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.4.4.2 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.4.4.2 bouyer * must display the following acknowledgement:
20 1.4.4.2 bouyer * This product includes software developed by the NetBSD
21 1.4.4.2 bouyer * Foundation, Inc. and its contributors.
22 1.4.4.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.4.4.2 bouyer * contributors may be used to endorse or promote products derived
24 1.4.4.2 bouyer * from this software without specific prior written permission.
25 1.4.4.2 bouyer *
26 1.4.4.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.4.4.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.4.4.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.4.4.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.4.4.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.4.4.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.4.4.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.4.4.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.4.4.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.4.4.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.4.4.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.4.4.2 bouyer */
38 1.4.4.2 bouyer
39 1.4.4.2 bouyer #include <sys/cdefs.h>
40 1.4.4.2 bouyer
41 1.4.4.2 bouyer __KERNEL_RCSID(0, "$NetBSD: eisa_machdep.c,v 1.4.4.2 2000/11/20 19:56:46 bouyer Exp $");
42 1.4.4.2 bouyer
43 1.4.4.2 bouyer #include <sys/param.h>
44 1.4.4.2 bouyer #include <sys/systm.h>
45 1.4.4.2 bouyer #include <sys/device.h>
46 1.4.4.2 bouyer #include <sys/malloc.h>
47 1.4.4.2 bouyer #include <sys/queue.h>
48 1.4.4.2 bouyer
49 1.4.4.2 bouyer #include <machine/intr.h>
50 1.4.4.2 bouyer #include <machine/rpb.h>
51 1.4.4.2 bouyer
52 1.4.4.2 bouyer #include <dev/eisa/eisareg.h>
53 1.4.4.2 bouyer #include <dev/eisa/eisavar.h>
54 1.4.4.2 bouyer
55 1.4.4.2 bouyer #define EISA_SLOT_HEADER_SIZE 31
56 1.4.4.2 bouyer #define EISA_SLOT_INFO_OFFSET 20
57 1.4.4.2 bouyer
58 1.4.4.2 bouyer #define EISA_FUNC_INFO_OFFSET 34
59 1.4.4.2 bouyer #define EISA_CONFIG_BLOCK_SIZE 320
60 1.4.4.2 bouyer
61 1.4.4.2 bouyer #define ECUF_TYPE_STRING 0x01
62 1.4.4.2 bouyer #define ECUF_MEM_ENTRY 0x02
63 1.4.4.2 bouyer #define ECUF_IRQ_ENTRY 0x04
64 1.4.4.2 bouyer #define ECUF_DMA_ENTRY 0x08
65 1.4.4.2 bouyer #define ECUF_IO_ENTRY 0x10
66 1.4.4.2 bouyer #define ECUF_INIT_ENTRY 0x20
67 1.4.4.2 bouyer #define ECUF_DISABLED 0x80
68 1.4.4.2 bouyer
69 1.4.4.2 bouyer #define ECUF_SELECTIONS_SIZE 26
70 1.4.4.2 bouyer #define ECUF_TYPE_STRING_SIZE 80
71 1.4.4.2 bouyer #define ECUF_MEM_ENTRY_SIZE 7
72 1.4.4.2 bouyer #define ECUF_IRQ_ENTRY_SIZE 2
73 1.4.4.2 bouyer #define ECUF_DMA_ENTRY_SIZE 2
74 1.4.4.2 bouyer #define ECUF_IO_ENTRY_SIZE 3
75 1.4.4.2 bouyer #define ECUF_INIT_ENTRY_SIZE 60
76 1.4.4.2 bouyer
77 1.4.4.2 bouyer #define ECUF_MEM_ENTRY_CNT 9
78 1.4.4.2 bouyer #define ECUF_IRQ_ENTRY_CNT 7
79 1.4.4.2 bouyer #define ECUF_DMA_ENTRY_CNT 4
80 1.4.4.2 bouyer #define ECUF_IO_ENTRY_CNT 20
81 1.4.4.2 bouyer
82 1.4.4.2 bouyer /*
83 1.4.4.2 bouyer * EISA configuration space, as set up by the ECU, may be sparse.
84 1.4.4.2 bouyer */
85 1.4.4.2 bouyer bus_size_t eisa_config_stride;
86 1.4.4.2 bouyer paddr_t eisa_config_addr; /* defaults to 0 */
87 1.4.4.2 bouyer paddr_t eisa_config_header_addr;
88 1.4.4.2 bouyer
89 1.4.4.2 bouyer struct ecu_mem {
90 1.4.4.2 bouyer SIMPLEQ_ENTRY(ecu_mem) ecum_list;
91 1.4.4.2 bouyer struct eisa_cfg_mem ecum_mem;
92 1.4.4.2 bouyer };
93 1.4.4.2 bouyer
94 1.4.4.2 bouyer struct ecu_irq {
95 1.4.4.2 bouyer SIMPLEQ_ENTRY(ecu_irq) ecui_list;
96 1.4.4.2 bouyer struct eisa_cfg_irq ecui_irq;
97 1.4.4.2 bouyer };
98 1.4.4.2 bouyer
99 1.4.4.2 bouyer struct ecu_dma {
100 1.4.4.2 bouyer SIMPLEQ_ENTRY(ecu_dma) ecud_list;
101 1.4.4.2 bouyer struct eisa_cfg_dma ecud_dma;
102 1.4.4.2 bouyer };
103 1.4.4.2 bouyer
104 1.4.4.2 bouyer struct ecu_io {
105 1.4.4.2 bouyer SIMPLEQ_ENTRY(ecu_io) ecuio_list;
106 1.4.4.2 bouyer struct eisa_cfg_io ecuio_io;
107 1.4.4.2 bouyer };
108 1.4.4.2 bouyer
109 1.4.4.2 bouyer struct ecu_func {
110 1.4.4.2 bouyer SIMPLEQ_ENTRY(ecu_func) ecuf_list;
111 1.4.4.2 bouyer int ecuf_funcno;
112 1.4.4.2 bouyer u_int32_t ecuf_id;
113 1.4.4.2 bouyer u_int16_t ecuf_slot_info;
114 1.4.4.2 bouyer u_int16_t ecuf_cfg_ext;
115 1.4.4.2 bouyer u_int8_t ecuf_selections[ECUF_SELECTIONS_SIZE];
116 1.4.4.2 bouyer u_int8_t ecuf_func_info;
117 1.4.4.2 bouyer u_int8_t ecuf_type_string[ECUF_TYPE_STRING_SIZE];
118 1.4.4.2 bouyer u_int8_t ecuf_init[ECUF_INIT_ENTRY_SIZE];
119 1.4.4.2 bouyer SIMPLEQ_HEAD(, ecu_mem) ecuf_mem;
120 1.4.4.2 bouyer SIMPLEQ_HEAD(, ecu_irq) ecuf_irq;
121 1.4.4.2 bouyer SIMPLEQ_HEAD(, ecu_dma) ecuf_dma;
122 1.4.4.2 bouyer SIMPLEQ_HEAD(, ecu_io) ecuf_io;
123 1.4.4.2 bouyer };
124 1.4.4.2 bouyer
125 1.4.4.2 bouyer struct ecu_data {
126 1.4.4.2 bouyer SIMPLEQ_ENTRY(ecu_data) ecud_list;
127 1.4.4.2 bouyer int ecud_slot;
128 1.4.4.2 bouyer u_int8_t ecud_eisaid[EISA_IDSTRINGLEN];
129 1.4.4.2 bouyer u_int32_t ecud_offset;
130 1.4.4.2 bouyer
131 1.4.4.2 bouyer /* General slot info. */
132 1.4.4.2 bouyer u_int8_t ecud_slot_info;
133 1.4.4.2 bouyer u_int16_t ecud_ecu_major_rev;
134 1.4.4.2 bouyer u_int16_t ecud_ecu_minor_rev;
135 1.4.4.2 bouyer u_int16_t ecud_cksum;
136 1.4.4.2 bouyer u_int16_t ecud_ndevfuncs;
137 1.4.4.2 bouyer u_int8_t ecud_funcinfo;
138 1.4.4.2 bouyer u_int32_t ecud_comp_id;
139 1.4.4.2 bouyer
140 1.4.4.2 bouyer /* The functions */
141 1.4.4.2 bouyer SIMPLEQ_HEAD(, ecu_func) ecud_funcs;
142 1.4.4.2 bouyer };
143 1.4.4.2 bouyer
144 1.4.4.2 bouyer SIMPLEQ_HEAD(, ecu_data) ecu_data_list =
145 1.4.4.2 bouyer SIMPLEQ_HEAD_INITIALIZER(ecu_data_list);
146 1.4.4.2 bouyer
147 1.4.4.2 bouyer static void
148 1.4.4.2 bouyer ecuf_init(struct ecu_func *ecuf)
149 1.4.4.2 bouyer {
150 1.4.4.2 bouyer
151 1.4.4.2 bouyer memset(ecuf, 0, sizeof(*ecuf));
152 1.4.4.2 bouyer SIMPLEQ_INIT(&ecuf->ecuf_mem);
153 1.4.4.2 bouyer SIMPLEQ_INIT(&ecuf->ecuf_irq);
154 1.4.4.2 bouyer SIMPLEQ_INIT(&ecuf->ecuf_dma);
155 1.4.4.2 bouyer SIMPLEQ_INIT(&ecuf->ecuf_io);
156 1.4.4.2 bouyer }
157 1.4.4.2 bouyer
158 1.4.4.2 bouyer static void
159 1.4.4.2 bouyer eisa_parse_mem(struct ecu_func *ecuf, u_int8_t *dp)
160 1.4.4.2 bouyer {
161 1.4.4.2 bouyer struct ecu_mem *ecum;
162 1.4.4.2 bouyer int i;
163 1.4.4.2 bouyer
164 1.4.4.2 bouyer for (i = 0; i < ECUF_MEM_ENTRY_CNT; i++) {
165 1.4.4.2 bouyer ecum = malloc(sizeof(*ecum), M_DEVBUF, M_WAITOK);
166 1.4.4.2 bouyer
167 1.4.4.2 bouyer ecum->ecum_mem.ecm_isram = dp[0] & 0x1;
168 1.4.4.2 bouyer ecum->ecum_mem.ecm_unitsize = dp[1] & 0x3;
169 1.4.4.2 bouyer ecum->ecum_mem.ecm_decode = (dp[1] >> 2) & 0x3;
170 1.4.4.2 bouyer ecum->ecum_mem.ecm_addr =
171 1.4.4.2 bouyer (dp[2] | (dp[3] << 8) | (dp[4] << 16)) << 8;
172 1.4.4.2 bouyer ecum->ecum_mem.ecm_size = (dp[5] | (dp[6] << 8)) << 10;
173 1.4.4.2 bouyer if (ecum->ecum_mem.ecm_size == 0)
174 1.4.4.2 bouyer ecum->ecum_mem.ecm_size = (1 << 26);
175 1.4.4.2 bouyer SIMPLEQ_INSERT_TAIL(&ecuf->ecuf_mem, ecum, ecum_list);
176 1.4.4.2 bouyer
177 1.4.4.2 bouyer #if 0
178 1.4.4.2 bouyer printf("MEM 0x%lx 0x%lx %d %d %d\n",
179 1.4.4.2 bouyer ecum->ecum_mem.ecm_addr, ecum->ecum_mem.ecm_size,
180 1.4.4.2 bouyer ecum->ecum_mem.ecm_isram, ecum->ecum_mem.ecm_unitsize,
181 1.4.4.2 bouyer ecum->ecum_mem.ecm_decode);
182 1.4.4.2 bouyer #endif
183 1.4.4.2 bouyer
184 1.4.4.2 bouyer if ((dp[0] & 0x80) == 0)
185 1.4.4.2 bouyer break;
186 1.4.4.2 bouyer dp += ECUF_MEM_ENTRY_SIZE;
187 1.4.4.2 bouyer }
188 1.4.4.2 bouyer }
189 1.4.4.2 bouyer
190 1.4.4.2 bouyer static void
191 1.4.4.2 bouyer eisa_parse_irq(struct ecu_func *ecuf, u_int8_t *dp)
192 1.4.4.2 bouyer {
193 1.4.4.2 bouyer struct ecu_irq *ecui;
194 1.4.4.2 bouyer int i;
195 1.4.4.2 bouyer
196 1.4.4.2 bouyer for (i = 0; i < ECUF_IRQ_ENTRY_CNT; i++) {
197 1.4.4.2 bouyer ecui = malloc(sizeof(*ecui), M_DEVBUF, M_WAITOK);
198 1.4.4.2 bouyer
199 1.4.4.2 bouyer ecui->ecui_irq.eci_irq = dp[0] & 0xf;
200 1.4.4.2 bouyer ecui->ecui_irq.eci_ist = (dp[0] & 0x20) ? IST_LEVEL : IST_EDGE;
201 1.4.4.2 bouyer ecui->ecui_irq.eci_shared = (dp[0] & 0x40) ? 1 : 0;
202 1.4.4.2 bouyer SIMPLEQ_INSERT_TAIL(&ecuf->ecuf_irq, ecui, ecui_list);
203 1.4.4.2 bouyer
204 1.4.4.2 bouyer #if 0
205 1.4.4.2 bouyer printf("IRQ %d %s%s\n", ecui->eci_irq.ecui_irq,
206 1.4.4.2 bouyer ecui->eci_irq.ecui_ist == IST_LEVEL ? "level" : "edge",
207 1.4.4.2 bouyer ecui->eci_irq.ecui_shared ? " shared" : "");
208 1.4.4.2 bouyer #endif
209 1.4.4.2 bouyer
210 1.4.4.2 bouyer if ((dp[0] & 0x80) == 0)
211 1.4.4.2 bouyer break;
212 1.4.4.2 bouyer dp += ECUF_IRQ_ENTRY_SIZE;
213 1.4.4.2 bouyer }
214 1.4.4.2 bouyer }
215 1.4.4.2 bouyer
216 1.4.4.2 bouyer static void
217 1.4.4.2 bouyer eisa_parse_dma(struct ecu_func *ecuf, u_int8_t *dp)
218 1.4.4.2 bouyer {
219 1.4.4.2 bouyer struct ecu_dma *ecud;
220 1.4.4.2 bouyer int i;
221 1.4.4.2 bouyer
222 1.4.4.2 bouyer for (i = 0; i < ECUF_DMA_ENTRY_CNT; i++) {
223 1.4.4.2 bouyer ecud = malloc(sizeof(*ecud), M_DEVBUF, M_WAITOK);
224 1.4.4.2 bouyer
225 1.4.4.2 bouyer ecud->ecud_dma.ecd_drq = dp[0] & 0x7;
226 1.4.4.2 bouyer ecud->ecud_dma.ecd_shared = dp[0] & 0x40;
227 1.4.4.2 bouyer ecud->ecud_dma.ecd_size = (dp[1] >> 2) & 0x3;
228 1.4.4.2 bouyer ecud->ecud_dma.ecd_timing = (dp[1] >> 4) & 0x3;
229 1.4.4.2 bouyer SIMPLEQ_INSERT_TAIL(&ecuf->ecuf_dma, ecud, ecud_list);
230 1.4.4.2 bouyer
231 1.4.4.2 bouyer #if 0
232 1.4.4.2 bouyer printf("DRQ %d%s %d %d\n", ecud->ecud_dma.ecd_drq,
233 1.4.4.2 bouyer ecud->ecud_dma.ecd_shared ? " shared" : "",
234 1.4.4.2 bouyer ecud->ecud_dma.ecd_size, ecud->ecud_dma.ecd_timing);
235 1.4.4.2 bouyer #endif
236 1.4.4.2 bouyer
237 1.4.4.2 bouyer if ((dp[0] & 0x80) == 0)
238 1.4.4.2 bouyer break;
239 1.4.4.2 bouyer dp += ECUF_DMA_ENTRY_SIZE;
240 1.4.4.2 bouyer }
241 1.4.4.2 bouyer }
242 1.4.4.2 bouyer
243 1.4.4.2 bouyer static void
244 1.4.4.2 bouyer eisa_parse_io(struct ecu_func *ecuf, u_int8_t *dp)
245 1.4.4.2 bouyer {
246 1.4.4.2 bouyer struct ecu_io *ecuio;
247 1.4.4.2 bouyer int i;
248 1.4.4.2 bouyer
249 1.4.4.2 bouyer for (i = 0; i < ECUF_IO_ENTRY_CNT; i++) {
250 1.4.4.2 bouyer ecuio = malloc(sizeof(*ecuio), M_DEVBUF, M_WAITOK);
251 1.4.4.2 bouyer
252 1.4.4.2 bouyer ecuio->ecuio_io.ecio_addr = dp[1] | (dp[2] << 8);
253 1.4.4.2 bouyer ecuio->ecuio_io.ecio_size = (dp[0] & 0x1f) + 1;
254 1.4.4.2 bouyer ecuio->ecuio_io.ecio_shared = (dp[0] & 0x40) ? 1 : 0;
255 1.4.4.2 bouyer
256 1.4.4.2 bouyer #if 0
257 1.4.4.2 bouyer printf("IO 0x%lx 0x%lx%s\n", ecuio->ecuio_io.ecio_addr,
258 1.4.4.2 bouyer ecuio->ecuio_io.ecio_size,
259 1.4.4.2 bouyer ecuio->ecuio_io.ecio_shared ? " shared" : "");
260 1.4.4.2 bouyer #endif
261 1.4.4.2 bouyer
262 1.4.4.2 bouyer if ((dp[0] & 0x80) == 0)
263 1.4.4.2 bouyer break;
264 1.4.4.2 bouyer dp += ECUF_IO_ENTRY_SIZE;
265 1.4.4.2 bouyer }
266 1.4.4.2 bouyer }
267 1.4.4.2 bouyer
268 1.4.4.2 bouyer static void
269 1.4.4.2 bouyer eisa_read_config_bytes(paddr_t addr, void *buf, size_t count)
270 1.4.4.2 bouyer {
271 1.4.4.2 bouyer const u_int8_t *src = (const u_int8_t *)ALPHA_PHYS_TO_K0SEG(addr);
272 1.4.4.2 bouyer u_int8_t *dst = buf;
273 1.4.4.2 bouyer
274 1.4.4.2 bouyer for (; count != 0; count--) {
275 1.4.4.2 bouyer *dst++ = *src;
276 1.4.4.2 bouyer src += eisa_config_stride;
277 1.4.4.2 bouyer }
278 1.4.4.2 bouyer }
279 1.4.4.2 bouyer
280 1.4.4.2 bouyer static void
281 1.4.4.2 bouyer eisa_read_config_word(paddr_t addr, u_int32_t *valp)
282 1.4.4.2 bouyer {
283 1.4.4.2 bouyer const u_int8_t *src = (const u_int8_t *)ALPHA_PHYS_TO_K0SEG(addr);
284 1.4.4.2 bouyer u_int32_t val = 0;
285 1.4.4.2 bouyer int i;
286 1.4.4.2 bouyer
287 1.4.4.2 bouyer for (i = 0; i < sizeof(val); i++) {
288 1.4.4.2 bouyer val |= (u_int)(*src << (i * 8));
289 1.4.4.2 bouyer src += eisa_config_stride;
290 1.4.4.2 bouyer }
291 1.4.4.2 bouyer
292 1.4.4.2 bouyer *valp = val;
293 1.4.4.2 bouyer }
294 1.4.4.2 bouyer
295 1.4.4.2 bouyer static size_t
296 1.4.4.2 bouyer eisa_uncompress(void *cbufp, void *ucbufp, size_t count)
297 1.4.4.2 bouyer {
298 1.4.4.2 bouyer const u_int8_t *cbuf = cbufp;
299 1.4.4.2 bouyer u_int8_t *ucbuf = ucbufp;
300 1.4.4.2 bouyer u_int zeros = 0;
301 1.4.4.2 bouyer
302 1.4.4.2 bouyer while (count--) {
303 1.4.4.2 bouyer if (zeros) {
304 1.4.4.2 bouyer zeros--;
305 1.4.4.2 bouyer *ucbuf++ = '\0';
306 1.4.4.2 bouyer } else if (*cbuf == '\0') {
307 1.4.4.2 bouyer *ucbuf++ = *cbuf++;
308 1.4.4.2 bouyer zeros = *cbuf++ - 1;
309 1.4.4.2 bouyer } else
310 1.4.4.2 bouyer *ucbuf++ = *cbuf++;
311 1.4.4.2 bouyer }
312 1.4.4.2 bouyer
313 1.4.4.2 bouyer return ((size_t)cbuf - (size_t)cbufp);
314 1.4.4.2 bouyer }
315 1.4.4.2 bouyer
316 1.4.4.2 bouyer void
317 1.4.4.2 bouyer eisa_init()
318 1.4.4.2 bouyer {
319 1.4.4.2 bouyer struct ecu_data *ecud;
320 1.4.4.2 bouyer paddr_t cfgaddr;
321 1.4.4.2 bouyer u_int32_t offset;
322 1.4.4.2 bouyer u_int8_t eisaid[EISA_IDSTRINGLEN];
323 1.4.4.2 bouyer u_int8_t *cdata, *data;
324 1.4.4.2 bouyer u_int8_t *cdp, *dp;
325 1.4.4.2 bouyer struct ecu_func *ecuf;
326 1.4.4.2 bouyer int i, func;
327 1.4.4.2 bouyer
328 1.4.4.2 bouyer /*
329 1.4.4.2 bouyer * Locate EISA configuration space.
330 1.4.4.2 bouyer */
331 1.4.4.2 bouyer if (hwrpb->rpb_condat_off == 0UL ||
332 1.4.4.2 bouyer (hwrpb->rpb_condat_off >> 63) != 0) {
333 1.4.4.2 bouyer printf(": WARNING: no EISA configuration space");
334 1.4.4.2 bouyer return;
335 1.4.4.2 bouyer }
336 1.4.4.2 bouyer
337 1.4.4.2 bouyer if (eisa_config_header_addr) {
338 1.4.4.2 bouyer printf("\n");
339 1.4.4.2 bouyer panic("eisa_init: EISA config space already initialized");
340 1.4.4.2 bouyer }
341 1.4.4.2 bouyer
342 1.4.4.2 bouyer eisa_config_header_addr = hwrpb->rpb_condat_off;
343 1.4.4.2 bouyer #if 0
344 1.4.4.2 bouyer printf("\nEISA config header at 0x%lx\n", eisa_config_header_addr);
345 1.4.4.2 bouyer #endif
346 1.4.4.2 bouyer if (eisa_config_stride == 0)
347 1.4.4.2 bouyer eisa_config_stride = 1;
348 1.4.4.2 bouyer
349 1.4.4.2 bouyer /*
350 1.4.4.2 bouyer * Read the slot headers, and allocate config structures for
351 1.4.4.2 bouyer * valid slots.
352 1.4.4.2 bouyer */
353 1.4.4.2 bouyer for (cfgaddr = eisa_config_header_addr, i = 0; i < 16 /* XXX */; i++) {
354 1.4.4.2 bouyer eisa_read_config_bytes(cfgaddr, eisaid, sizeof(eisaid));
355 1.4.4.2 bouyer eisaid[EISA_IDSTRINGLEN - 1] = '\0'; /* sanity */
356 1.4.4.2 bouyer cfgaddr += sizeof(eisaid) * eisa_config_stride;
357 1.4.4.2 bouyer eisa_read_config_word(cfgaddr, &offset);
358 1.4.4.2 bouyer cfgaddr += sizeof(offset) * eisa_config_stride;
359 1.4.4.2 bouyer
360 1.4.4.2 bouyer if (offset != 0) {
361 1.4.4.2 bouyer #if 0
362 1.4.4.2 bouyer printf("SLOT %d: offset 0x%08x eisaid %s\n",
363 1.4.4.2 bouyer i, offset, eisaid);
364 1.4.4.2 bouyer #endif
365 1.4.4.2 bouyer ecud = malloc(sizeof(*ecud), M_DEVBUF, M_WAITOK);
366 1.4.4.2 bouyer memset(ecud, 0, sizeof(*ecud));
367 1.4.4.2 bouyer
368 1.4.4.2 bouyer SIMPLEQ_INIT(&ecud->ecud_funcs);
369 1.4.4.2 bouyer
370 1.4.4.2 bouyer ecud->ecud_slot = i;
371 1.4.4.2 bouyer memcpy(ecud->ecud_eisaid, eisaid, sizeof(eisaid));
372 1.4.4.2 bouyer ecud->ecud_offset = offset;
373 1.4.4.2 bouyer SIMPLEQ_INSERT_TAIL(&ecu_data_list, ecud, ecud_list);
374 1.4.4.2 bouyer }
375 1.4.4.2 bouyer }
376 1.4.4.2 bouyer
377 1.4.4.2 bouyer /*
378 1.4.4.2 bouyer * Now traverse the valid slots and read the info.
379 1.4.4.2 bouyer */
380 1.4.4.2 bouyer
381 1.4.4.2 bouyer cdata = malloc(512, M_TEMP, M_WAITOK);
382 1.4.4.2 bouyer data = malloc(512, M_TEMP, M_WAITOK);
383 1.4.4.2 bouyer
384 1.4.4.2 bouyer for (ecud = SIMPLEQ_FIRST(&ecu_data_list); ecud != NULL;
385 1.4.4.2 bouyer ecud = SIMPLEQ_NEXT(ecud, ecud_list)) {
386 1.4.4.2 bouyer cfgaddr = eisa_config_addr + ecud->ecud_offset;
387 1.4.4.2 bouyer eisa_read_config_bytes(cfgaddr, &cdata[0], 1);
388 1.4.4.2 bouyer cfgaddr += eisa_config_stride;
389 1.4.4.2 bouyer
390 1.4.4.2 bouyer for (i = 1; ; cfgaddr += eisa_config_stride, i++) {
391 1.4.4.2 bouyer eisa_read_config_bytes(cfgaddr, &cdata[i], 1);
392 1.4.4.2 bouyer if (cdata[i - 1] == 0 && cdata[i] == 0)
393 1.4.4.2 bouyer break;
394 1.4.4.2 bouyer }
395 1.4.4.2 bouyer i++; /* index -> length */
396 1.4.4.2 bouyer
397 1.4.4.2 bouyer #if 0
398 1.4.4.2 bouyer printf("SLOT %d compressed data length %d:",
399 1.4.4.2 bouyer ecud->ecud_slot, i);
400 1.4.4.2 bouyer {
401 1.4.4.2 bouyer int j;
402 1.4.4.2 bouyer
403 1.4.4.2 bouyer for (j = 0; j < i; j++) {
404 1.4.4.2 bouyer if ((j % 16) == 0)
405 1.4.4.2 bouyer printf("\n");
406 1.4.4.2 bouyer printf("0x%02x ", cdata[j]);
407 1.4.4.2 bouyer }
408 1.4.4.2 bouyer printf("\n");
409 1.4.4.2 bouyer }
410 1.4.4.2 bouyer #endif
411 1.4.4.2 bouyer
412 1.4.4.2 bouyer cdp = cdata;
413 1.4.4.2 bouyer dp = data;
414 1.4.4.2 bouyer
415 1.4.4.2 bouyer /* Uncompress the slot header. */
416 1.4.4.2 bouyer cdp += eisa_uncompress(cdp, dp, EISA_SLOT_HEADER_SIZE);
417 1.4.4.2 bouyer #if 0
418 1.4.4.2 bouyer printf("SLOT %d uncompressed header data:",
419 1.4.4.2 bouyer ecud->ecud_slot);
420 1.4.4.2 bouyer {
421 1.4.4.2 bouyer int j;
422 1.4.4.2 bouyer
423 1.4.4.2 bouyer for (j = 0; j < EISA_SLOT_HEADER_SIZE; j++) {
424 1.4.4.2 bouyer if ((j % 16) == 0)
425 1.4.4.2 bouyer printf("\n");
426 1.4.4.2 bouyer printf("0x%02x ", dp[j]);
427 1.4.4.2 bouyer }
428 1.4.4.2 bouyer printf("\n");
429 1.4.4.2 bouyer }
430 1.4.4.2 bouyer #endif
431 1.4.4.2 bouyer
432 1.4.4.2 bouyer dp = &data[EISA_SLOT_INFO_OFFSET];
433 1.4.4.2 bouyer ecud->ecud_slot_info = *dp++;
434 1.4.4.2 bouyer ecud->ecud_ecu_major_rev = *dp++;
435 1.4.4.2 bouyer ecud->ecud_ecu_minor_rev = *dp++;
436 1.4.4.2 bouyer memcpy(&ecud->ecud_cksum, dp, sizeof(ecud->ecud_cksum));
437 1.4.4.2 bouyer dp += sizeof(ecud->ecud_cksum);
438 1.4.4.2 bouyer ecud->ecud_ndevfuncs = *dp++;
439 1.4.4.2 bouyer ecud->ecud_funcinfo = *dp++;
440 1.4.4.2 bouyer memcpy(&ecud->ecud_comp_id, dp, sizeof(ecud->ecud_comp_id));
441 1.4.4.2 bouyer dp += sizeof(ecud->ecud_comp_id);
442 1.4.4.2 bouyer
443 1.4.4.2 bouyer #if 0
444 1.4.4.2 bouyer printf("SLOT %d: ndevfuncs %d\n", ecud->ecud_slot,
445 1.4.4.2 bouyer ecud->ecud_ndevfuncs);
446 1.4.4.2 bouyer #endif
447 1.4.4.2 bouyer
448 1.4.4.2 bouyer for (func = 0; func < ecud->ecud_ndevfuncs; func++) {
449 1.4.4.2 bouyer dp = data;
450 1.4.4.2 bouyer cdp += eisa_uncompress(cdp, dp, EISA_CONFIG_BLOCK_SIZE);
451 1.4.4.2 bouyer #if 0
452 1.4.4.2 bouyer printf("SLOT %d:%d uncompressed data:",
453 1.4.4.2 bouyer ecud->ecud_slot, func);
454 1.4.4.2 bouyer {
455 1.4.4.2 bouyer int j;
456 1.4.4.2 bouyer
457 1.4.4.2 bouyer for (j = 0; i < EISA_CONFIG_BLOCK_SIZE; j++) {
458 1.4.4.2 bouyer if ((j % 16) == 0)
459 1.4.4.2 bouyer printf("\n");
460 1.4.4.2 bouyer printf("0x%02x ", dp[j]);
461 1.4.4.2 bouyer }
462 1.4.4.2 bouyer printf("\n");
463 1.4.4.2 bouyer }
464 1.4.4.2 bouyer #endif
465 1.4.4.2 bouyer
466 1.4.4.2 bouyer /* Skip disabled functions. */
467 1.4.4.2 bouyer if (dp[EISA_FUNC_INFO_OFFSET] & ECUF_DISABLED) {
468 1.4.4.2 bouyer #if 0
469 1.4.4.2 bouyer printf("SLOT %d:%d disabled\n",
470 1.4.4.2 bouyer ecud->ecud_slot, func);
471 1.4.4.2 bouyer #endif
472 1.4.4.2 bouyer continue;
473 1.4.4.2 bouyer }
474 1.4.4.2 bouyer
475 1.4.4.2 bouyer ecuf = malloc(sizeof(*ecuf), M_DEVBUF, M_WAITOK);
476 1.4.4.2 bouyer ecuf_init(ecuf);
477 1.4.4.2 bouyer ecuf->ecuf_funcno = func;
478 1.4.4.2 bouyer SIMPLEQ_INSERT_TAIL(&ecud->ecud_funcs, ecuf,
479 1.4.4.2 bouyer ecuf_list);
480 1.4.4.2 bouyer
481 1.4.4.2 bouyer memcpy(&ecuf->ecuf_id, dp, sizeof(ecuf->ecuf_id));
482 1.4.4.2 bouyer dp += sizeof(ecuf->ecuf_id);
483 1.4.4.2 bouyer
484 1.4.4.2 bouyer memcpy(&ecuf->ecuf_slot_info, dp,
485 1.4.4.2 bouyer sizeof(ecuf->ecuf_slot_info));
486 1.4.4.2 bouyer dp += sizeof(ecuf->ecuf_slot_info);
487 1.4.4.2 bouyer
488 1.4.4.2 bouyer memcpy(&ecuf->ecuf_cfg_ext, dp,
489 1.4.4.2 bouyer sizeof(ecuf->ecuf_cfg_ext));
490 1.4.4.2 bouyer dp += sizeof(ecuf->ecuf_cfg_ext);
491 1.4.4.2 bouyer
492 1.4.4.2 bouyer memcpy(&ecuf->ecuf_selections, dp,
493 1.4.4.2 bouyer sizeof(ecuf->ecuf_selections));
494 1.4.4.2 bouyer dp += sizeof(ecuf->ecuf_selections);
495 1.4.4.2 bouyer
496 1.4.4.2 bouyer memcpy(&ecuf->ecuf_func_info, dp,
497 1.4.4.2 bouyer sizeof(ecuf->ecuf_func_info));
498 1.4.4.2 bouyer dp += sizeof(ecuf->ecuf_func_info);
499 1.4.4.2 bouyer
500 1.4.4.2 bouyer if (ecuf->ecuf_func_info & ECUF_TYPE_STRING)
501 1.4.4.2 bouyer memcpy(ecuf->ecuf_type_string, dp,
502 1.4.4.2 bouyer sizeof(ecuf->ecuf_type_string));
503 1.4.4.2 bouyer dp += sizeof(ecuf->ecuf_type_string);
504 1.4.4.2 bouyer
505 1.4.4.2 bouyer if (ecuf->ecuf_func_info & ECUF_MEM_ENTRY)
506 1.4.4.2 bouyer eisa_parse_mem(ecuf, dp);
507 1.4.4.2 bouyer dp += ECUF_MEM_ENTRY_SIZE * ECUF_MEM_ENTRY_CNT;
508 1.4.4.2 bouyer
509 1.4.4.2 bouyer if (ecuf->ecuf_func_info & ECUF_IRQ_ENTRY)
510 1.4.4.2 bouyer eisa_parse_irq(ecuf, dp);
511 1.4.4.2 bouyer dp += ECUF_IRQ_ENTRY_SIZE * ECUF_IRQ_ENTRY_CNT;
512 1.4.4.2 bouyer
513 1.4.4.2 bouyer if (ecuf->ecuf_func_info & ECUF_DMA_ENTRY)
514 1.4.4.2 bouyer eisa_parse_dma(ecuf, dp);
515 1.4.4.2 bouyer dp += ECUF_DMA_ENTRY_SIZE * ECUF_DMA_ENTRY_CNT;
516 1.4.4.2 bouyer
517 1.4.4.2 bouyer if (ecuf->ecuf_func_info & ECUF_IO_ENTRY)
518 1.4.4.2 bouyer eisa_parse_io(ecuf, dp);
519 1.4.4.2 bouyer dp += ECUF_IO_ENTRY_SIZE * ECUF_IO_ENTRY_CNT;
520 1.4.4.2 bouyer
521 1.4.4.2 bouyer if (ecuf->ecuf_func_info & ECUF_INIT_ENTRY)
522 1.4.4.2 bouyer memcpy(ecuf->ecuf_init, dp,
523 1.4.4.2 bouyer sizeof(ecuf->ecuf_init));
524 1.4.4.2 bouyer dp += sizeof(ecuf->ecuf_init);
525 1.4.4.2 bouyer }
526 1.4.4.2 bouyer }
527 1.4.4.2 bouyer
528 1.4.4.2 bouyer free(cdata, M_TEMP);
529 1.4.4.2 bouyer free(data, M_TEMP);
530 1.4.4.2 bouyer }
531 1.4.4.2 bouyer
532 1.4.4.2 bouyer static struct ecu_data *
533 1.4.4.2 bouyer eisa_lookup_data(int slot)
534 1.4.4.2 bouyer {
535 1.4.4.2 bouyer struct ecu_data *ecud;
536 1.4.4.2 bouyer
537 1.4.4.2 bouyer for (ecud = SIMPLEQ_FIRST(&ecu_data_list); ecud != NULL;
538 1.4.4.2 bouyer ecud = SIMPLEQ_NEXT(ecud, ecud_list)) {
539 1.4.4.2 bouyer if (ecud->ecud_slot == slot)
540 1.4.4.2 bouyer return (ecud);
541 1.4.4.2 bouyer }
542 1.4.4.2 bouyer return (NULL);
543 1.4.4.2 bouyer }
544 1.4.4.2 bouyer
545 1.4.4.2 bouyer static struct ecu_func *
546 1.4.4.2 bouyer eisa_lookup_func(int slot, int func)
547 1.4.4.2 bouyer {
548 1.4.4.2 bouyer struct ecu_data *ecud;
549 1.4.4.2 bouyer struct ecu_func *ecuf;
550 1.4.4.2 bouyer
551 1.4.4.2 bouyer ecud = eisa_lookup_data(slot);
552 1.4.4.2 bouyer if (ecud == NULL)
553 1.4.4.2 bouyer return (NULL);
554 1.4.4.2 bouyer
555 1.4.4.2 bouyer for (ecuf = SIMPLEQ_FIRST(&ecud->ecud_funcs); ecuf != NULL;
556 1.4.4.2 bouyer ecuf = SIMPLEQ_NEXT(ecuf, ecuf_list)) {
557 1.4.4.2 bouyer if (ecuf->ecuf_funcno == func)
558 1.4.4.2 bouyer return (ecuf);
559 1.4.4.2 bouyer }
560 1.4.4.2 bouyer return (NULL);
561 1.4.4.2 bouyer }
562 1.4.4.2 bouyer
563 1.4.4.2 bouyer int
564 1.4.4.2 bouyer eisa_conf_read_mem(eisa_chipset_tag_t ec, int slot, int func, int entry,
565 1.4.4.2 bouyer struct eisa_cfg_mem *dp)
566 1.4.4.2 bouyer {
567 1.4.4.2 bouyer struct ecu_func *ecuf;
568 1.4.4.2 bouyer struct ecu_mem *ecum;
569 1.4.4.2 bouyer
570 1.4.4.2 bouyer ecuf = eisa_lookup_func(slot, func);
571 1.4.4.2 bouyer if (ecuf == NULL)
572 1.4.4.2 bouyer return (ENOENT);
573 1.4.4.2 bouyer
574 1.4.4.2 bouyer for (ecum = SIMPLEQ_FIRST(&ecuf->ecuf_mem); ecum != NULL;
575 1.4.4.2 bouyer ecum = SIMPLEQ_NEXT(ecum, ecum_list)) {
576 1.4.4.2 bouyer if (entry-- == 0)
577 1.4.4.2 bouyer break;
578 1.4.4.2 bouyer }
579 1.4.4.2 bouyer if (ecum == NULL)
580 1.4.4.2 bouyer return (ENOENT);
581 1.4.4.2 bouyer
582 1.4.4.2 bouyer *dp = ecum->ecum_mem;
583 1.4.4.2 bouyer return (0);
584 1.4.4.2 bouyer }
585 1.4.4.2 bouyer
586 1.4.4.2 bouyer int
587 1.4.4.2 bouyer eisa_conf_read_irq(eisa_chipset_tag_t ec, int slot, int func, int entry,
588 1.4.4.2 bouyer struct eisa_cfg_irq *dp)
589 1.4.4.2 bouyer {
590 1.4.4.2 bouyer struct ecu_func *ecuf;
591 1.4.4.2 bouyer struct ecu_irq *ecui;
592 1.4.4.2 bouyer
593 1.4.4.2 bouyer ecuf = eisa_lookup_func(slot, func);
594 1.4.4.2 bouyer if (ecuf == NULL)
595 1.4.4.2 bouyer return (ENOENT);
596 1.4.4.2 bouyer
597 1.4.4.2 bouyer for (ecui = SIMPLEQ_FIRST(&ecuf->ecuf_irq); ecui != NULL;
598 1.4.4.2 bouyer ecui = SIMPLEQ_NEXT(ecui, ecui_list)) {
599 1.4.4.2 bouyer if (entry-- == 0)
600 1.4.4.2 bouyer break;
601 1.4.4.2 bouyer }
602 1.4.4.2 bouyer if (ecui == NULL)
603 1.4.4.2 bouyer return (ENOENT);
604 1.4.4.2 bouyer
605 1.4.4.2 bouyer *dp = ecui->ecui_irq;
606 1.4.4.2 bouyer return (0);
607 1.4.4.2 bouyer }
608 1.4.4.2 bouyer
609 1.4.4.2 bouyer int
610 1.4.4.2 bouyer eisa_conf_read_dma(eisa_chipset_tag_t ec, int slot, int func, int entry,
611 1.4.4.2 bouyer struct eisa_cfg_dma *dp)
612 1.4.4.2 bouyer {
613 1.4.4.2 bouyer struct ecu_func *ecuf;
614 1.4.4.2 bouyer struct ecu_dma *ecud;
615 1.4.4.2 bouyer
616 1.4.4.2 bouyer ecuf = eisa_lookup_func(slot, func);
617 1.4.4.2 bouyer if (ecuf == NULL)
618 1.4.4.2 bouyer return (ENOENT);
619 1.4.4.2 bouyer
620 1.4.4.2 bouyer for (ecud = SIMPLEQ_FIRST(&ecuf->ecuf_dma); ecud != NULL;
621 1.4.4.2 bouyer ecud = SIMPLEQ_NEXT(ecud, ecud_list)) {
622 1.4.4.2 bouyer if (entry-- == 0)
623 1.4.4.2 bouyer break;
624 1.4.4.2 bouyer }
625 1.4.4.2 bouyer if (ecud == NULL)
626 1.4.4.2 bouyer return (ENOENT);
627 1.4.4.2 bouyer
628 1.4.4.2 bouyer *dp = ecud->ecud_dma;
629 1.4.4.2 bouyer return (0);
630 1.4.4.2 bouyer }
631 1.4.4.2 bouyer
632 1.4.4.2 bouyer int
633 1.4.4.2 bouyer eisa_conf_read_io(eisa_chipset_tag_t ec, int slot, int func, int entry,
634 1.4.4.2 bouyer struct eisa_cfg_io *dp)
635 1.4.4.2 bouyer {
636 1.4.4.2 bouyer struct ecu_func *ecuf;
637 1.4.4.2 bouyer struct ecu_io *ecuio;
638 1.4.4.2 bouyer
639 1.4.4.2 bouyer ecuf = eisa_lookup_func(slot, func);
640 1.4.4.2 bouyer if (ecuf == NULL)
641 1.4.4.2 bouyer return (ENOENT);
642 1.4.4.2 bouyer
643 1.4.4.2 bouyer for (ecuio = SIMPLEQ_FIRST(&ecuf->ecuf_io); ecuio != NULL;
644 1.4.4.2 bouyer ecuio = SIMPLEQ_NEXT(ecuio, ecuio_list)) {
645 1.4.4.2 bouyer if (entry-- == 0)
646 1.4.4.2 bouyer break;
647 1.4.4.2 bouyer }
648 1.4.4.2 bouyer if (ecuio == NULL)
649 1.4.4.2 bouyer return (ENOENT);
650 1.4.4.2 bouyer
651 1.4.4.2 bouyer *dp = ecuio->ecuio_io;
652 1.4.4.2 bouyer return (0);
653 1.4.4.2 bouyer }
654