1 /* $NetBSD: isapnpdebug.c,v 1.11 2008/04/28 20:23:53 martin Exp $ */
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
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.
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.
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: isapnpdebug.c,v 1.11 2008/04/28 20:23:53 martin Exp $");
37 #include <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
43 #include <dev/isa/isavar.h>
45 #include <dev/isapnp/isapnpreg.h>
46 #include <dev/isapnp/isapnpvar.h>
48 /* isapnp_print_mem():
52 isapnp_print_mem(const char *str
, const struct isapnp_region
*mem
)
54 printf("%sMemory: %s,%sshadowable,decode-%s,%scacheable,%s", str
,
55 (mem
->flags
& ISAPNP_MEMATTR_ROM
) ? "ROM," : "RAM,",
56 (mem
->flags
& ISAPNP_MEMATTR_SHADOWABLE
) ? "" : "non-",
57 (mem
->flags
& ISAPNP_MEMATTR_HIGH_ADDR
) ?
58 "high-addr," : "range-len,",
59 (mem
->flags
& ISAPNP_MEMATTR_CACHEABLE
) ? "" : "non-",
60 (mem
->flags
& ISAPNP_MEMATTR_WRITABLE
) ?
61 "writable," : "read-only,");
63 switch (mem
->flags
& ISAPNP_MEMWIDTH_MASK
) {
64 case ISAPNP_MEMWIDTH_8
:
67 case ISAPNP_MEMWIDTH_16
:
70 case ISAPNP_MEMWIDTH_8_16
:
73 case ISAPNP_MEMWIDTH_32
:
78 printf("min 0x%x, max 0x%x, ", mem
->minbase
, mem
->maxbase
);
79 printf("align 0x%x, length 0x%x\n", mem
->align
, mem
->length
);
87 isapnp_print_io(const char *str
, const struct isapnp_region
*io
)
89 printf("%d %sIO Ports: %d address bits, alignment %d ",
90 io
->length
, str
, (io
->flags
& ISAPNP_IOFLAGS_16
) ? 16 : 10,
93 printf("min 0x%x, max 0x%x\n", io
->minbase
, io
->maxbase
);
97 /* isapnp_print_irq():
101 isapnp_print_irq(const char *str
, const struct isapnp_pin
*irq
)
105 printf("%sIRQ's supported: ", str
);
106 for (i
= 0; i
< 16; i
++)
107 if (irq
->bits
& (1 << i
))
110 if (irq
->flags
& ISAPNP_IRQTYPE_EDGE_PLUS
)
112 if (irq
->flags
& ISAPNP_IRQTYPE_EDGE_MINUS
)
114 if (irq
->flags
& ISAPNP_IRQTYPE_LEVEL_PLUS
)
116 if (irq
->flags
& ISAPNP_IRQTYPE_LEVEL_MINUS
)
121 /* isapnp_print_drq():
125 isapnp_print_drq(const char *str
, const struct isapnp_pin
*drq
)
128 u_char flags
= drq
->flags
;
130 printf("%sDRQ's supported: ", str
);
131 for (i
= 0; i
< 8; i
++)
132 if (drq
->bits
& (1 << i
))
136 switch (flags
& ISAPNP_DMAWIDTH_MASK
) {
137 case ISAPNP_DMAWIDTH_8
:
140 case ISAPNP_DMAWIDTH_8_16
:
143 case ISAPNP_DMAWIDTH_16
:
146 case ISAPNP_DMAWIDTH_RESERVED
:
152 switch (flags
& ISAPNP_DMASPEED_MASK
) {
153 case ISAPNP_DMASPEED_COMPAT
:
156 case ISAPNP_DMASPEED_A
:
159 case ISAPNP_DMASPEED_B
:
162 case ISAPNP_DMASPEED_F
:
167 if (flags
& ISAPNP_DMAATTR_MASK
)
168 printf("Attributes: %s%s%s",
169 (flags
& ISAPNP_DMAATTR_BUS_MASTER
) ? "bus master " : "",
170 (flags
& ISAPNP_DMAATTR_INCR_8
) ? "incr 8 " : "",
171 (flags
& ISAPNP_DMAATTR_INCR_16
) ? "incr 16 " : "");
176 /* isapnp_print_dep_start():
177 * Print a start dependencies tag
180 isapnp_print_dep_start(const char *str
, const u_char pref
)
183 printf("%sconfig: ", str
);
185 case ISAPNP_DEP_PREFERRED
:
186 printf("preferred\n");
189 case ISAPNP_DEP_ACCEPTABLE
:
190 printf("acceptable\n");
193 case ISAPNP_DEP_FUNCTIONAL
:
194 printf("functional\n");
197 case ISAPNP_DEP_UNSET
: /* Used internally */
201 case ISAPNP_DEP_CONFLICTING
: /* Used internally */
202 printf("conflicting\n");
212 isapnp_print_attach(const struct isapnp_attach_args
*pa
)
216 printf("Found <%s, %s, %s, %s> ", pa
->ipa_devident
,
217 pa
->ipa_devlogic
, pa
->ipa_devcompat
, pa
->ipa_devclass
);
218 isapnp_print_dep_start("", pa
->ipa_pref
);
220 for (i
= 0; i
< pa
->ipa_nio
; i
++)
221 isapnp_print_io("", &pa
->ipa_io
[i
]);
223 for (i
= 0; i
< pa
->ipa_nmem
; i
++)
224 isapnp_print_mem("", &pa
->ipa_mem
[i
]);
226 for (i
= 0; i
< pa
->ipa_nirq
; i
++)
227 isapnp_print_irq("", &pa
->ipa_irq
[i
]);
229 for (i
= 0; i
< pa
->ipa_ndrq
; i
++)
230 isapnp_print_drq("", &pa
->ipa_drq
[i
]);
232 for (i
= 0; i
< pa
->ipa_nmem32
; i
++)
233 isapnp_print_mem("", &pa
->ipa_mem32
[i
]);
237 /* isapnp_get_config():
238 * Get the current configuration of the card
241 isapnp_get_config(struct isapnp_softc
*sc
, struct isapnp_attach_args
*pa
)
244 u_char v0
, v1
, v2
, v3
;
245 static u_char isapnp_mem_range
[] = ISAPNP_MEM_DESC
;
246 static u_char isapnp_io_range
[] = ISAPNP_IO_DESC
;
247 static u_char isapnp_irq_range
[] = ISAPNP_IRQ_DESC
;
248 static u_char isapnp_drq_range
[] = ISAPNP_DRQ_DESC
;
249 static u_char isapnp_mem32_range
[] = ISAPNP_MEM32_DESC
;
250 struct isapnp_region
*r
;
251 struct isapnp_pin
*p
;
253 memset(pa
, 0, sizeof(*pa
));
255 for (i
= 0; i
< sizeof(isapnp_io_range
); i
++) {
257 v0
= isapnp_read_reg(sc
,
258 isapnp_io_range
[i
] + ISAPNP_IO_BASE_15_8
);
259 v1
= isapnp_read_reg(sc
,
260 isapnp_io_range
[i
] + ISAPNP_IO_BASE_7_0
);
261 r
->base
= (v0
<< 8) | v1
;
267 for (i
= 0; i
< sizeof(isapnp_mem_range
); i
++) {
269 v0
= isapnp_read_reg(sc
,
270 isapnp_mem_range
[i
] + ISAPNP_MEM_BASE_23_16
);
271 v1
= isapnp_read_reg(sc
,
272 isapnp_mem_range
[i
] + ISAPNP_MEM_BASE_15_8
);
273 r
->base
= (v0
<< 16) | (v1
<< 8);
277 v0
= isapnp_read_reg(sc
,
278 isapnp_mem_range
[i
] + ISAPNP_MEM_LRANGE_23_16
);
279 v1
= isapnp_read_reg(sc
,
280 isapnp_mem_range
[i
] + ISAPNP_MEM_LRANGE_15_8
);
281 r
->length
= (v0
<< 16) | (v1
<< 8);
282 v0
= isapnp_read_reg(sc
,
283 isapnp_mem_range
[i
] + ISAPNP_MEM_CONTROL
);
285 if (v0
& ISAPNP_MEM_CONTROL_LIMIT
)
286 r
->flags
|= ISAPNP_MEMATTR_HIGH_ADDR
;
287 if (v0
& ISAPNP_MEM_CONTROL_16
)
288 r
->flags
|= ISAPNP_MEMWIDTH_16
;
292 for (i
= 0; i
< sizeof(isapnp_irq_range
); i
++) {
293 v0
= isapnp_read_reg(sc
,
294 isapnp_irq_range
[i
] + ISAPNP_IRQ_NUMBER
);
300 switch (v0
& (ISAPNP_IRQ_LEVEL
|ISAPNP_IRQ_HIGH
)) {
301 case ISAPNP_IRQ_LEVEL
|ISAPNP_IRQ_HIGH
:
302 p
->flags
= ISAPNP_IRQTYPE_LEVEL_PLUS
;
304 case ISAPNP_IRQ_HIGH
:
305 p
->flags
= ISAPNP_IRQTYPE_EDGE_PLUS
;
307 case ISAPNP_IRQ_LEVEL
:
308 p
->flags
= ISAPNP_IRQTYPE_LEVEL_MINUS
;
311 p
->flags
= ISAPNP_IRQTYPE_EDGE_MINUS
;
317 for (i
= 0; i
< sizeof(isapnp_drq_range
); i
++) {
318 v0
= isapnp_read_reg(sc
, isapnp_drq_range
[i
]);
326 for (i
= 0; i
< sizeof(isapnp_mem32_range
); i
++) {
327 r
= &pa
->ipa_mem32
[i
];
328 v0
= isapnp_read_reg(sc
,
329 isapnp_mem32_range
[i
] + ISAPNP_MEM32_BASE_31_24
);
330 v1
= isapnp_read_reg(sc
,
331 isapnp_mem32_range
[i
] + ISAPNP_MEM32_BASE_23_16
);
332 v2
= isapnp_read_reg(sc
,
333 isapnp_mem32_range
[i
] + ISAPNP_MEM32_BASE_15_8
);
334 v3
= isapnp_read_reg(sc
,
335 isapnp_mem32_range
[i
] + ISAPNP_MEM32_BASE_7_0
);
336 r
->base
= (v0
<< 24) | (v1
<< 16) | (v2
<< 8) | v3
;
340 v0
= isapnp_read_reg(sc
,
341 isapnp_mem32_range
[i
] + ISAPNP_MEM32_LRANGE_31_24
);
342 v1
= isapnp_read_reg(sc
,
343 isapnp_mem32_range
[i
] + ISAPNP_MEM32_LRANGE_23_16
);
344 v2
= isapnp_read_reg(sc
,
345 isapnp_mem32_range
[i
] + ISAPNP_MEM32_LRANGE_15_8
);
346 v3
= isapnp_read_reg(sc
,
347 isapnp_mem32_range
[i
] + ISAPNP_MEM32_LRANGE_7_0
);
348 r
->length
= (v0
<< 24) | (v1
<< 16) | (v2
<< 8) | v3
;
349 v0
= isapnp_read_reg(sc
,
350 isapnp_mem_range
[i
] + ISAPNP_MEM_CONTROL
);
357 /* isapnp_print_config():
358 * Print the current configuration of the card
361 isapnp_print_config(const struct isapnp_attach_args
*pa
)
364 const struct isapnp_region
*r
;
365 const struct isapnp_pin
*p
;
367 printf("Register configuration:\n");
369 for (i
= 0; i
< pa
->ipa_nio
; i
++) {
371 printf("io[%d]: 0x%x/%d\n", i
, r
->base
, r
->length
);
375 for (i
= 0; i
< pa
->ipa_nmem
; i
++) {
377 printf("mem[%d]: 0x%x/%d\n", i
, r
->base
, r
->length
);
381 for (i
= 0; i
< pa
->ipa_nirq
; i
++) {
383 printf("irq[%d]: %d\n", i
, p
->num
);
387 for (i
= 0; i
< pa
->ipa_ndrq
; i
++) {
389 printf("drq[%d]: %d\n", i
, p
->num
);
393 for (i
= 0; i
< pa
->ipa_nmem32
; i
++) {
394 r
= &pa
->ipa_mem32
[i
];
395 printf("mem32[%d]: 0x%x/%d\n", i
, r
->base
, r
->length
);