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