]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/i386/i386/bios.c
Add libbearssl
[FreeBSD/FreeBSD.git] / sys / i386 / i386 / bios.c
1 /*-
2  * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3  *
4  * Copyright (c) 1997 Michael Smith
5  * Copyright (c) 1998 Jonathan Lemon
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27  * SUCH DAMAGE.
28  */
29
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
32
33 /*
34  * Code for dealing with the BIOS in x86 PC systems.
35  */
36
37 #include "opt_isa.h"
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/malloc.h>
43 #include <sys/module.h>
44 #include <sys/bus.h>
45 #include <sys/pcpu.h>
46 #include <vm/vm.h>
47 #include <vm/pmap.h>
48 #include <machine/md_var.h>
49 #include <machine/segments.h>
50 #include <machine/stdarg.h>
51 #include <machine/vmparam.h>
52 #include <machine/pc/bios.h>
53 #ifdef DEV_ISA
54 #include <isa/isavar.h>
55 #include <isa/pnpreg.h>
56 #include <isa/pnpvar.h>
57 #endif
58
59 #define BIOS_START      0xe0000
60 #define BIOS_SIZE       0x20000
61
62 /* exported lookup results */
63 struct bios32_SDentry           PCIbios;
64
65 static struct PnPBIOS_table     *PnPBIOStable;
66
67 static u_int                    bios32_SDCI;
68
69 /* start fairly early */
70 static void                     bios32_init(void *junk);
71 SYSINIT(bios32, SI_SUB_CPU, SI_ORDER_ANY, bios32_init, NULL);
72
73 /*
74  * bios32_init
75  *
76  * Locate various bios32 entities.
77  */
78 static void
79 bios32_init(void *junk)
80 {
81     u_long                      sigaddr;
82     struct bios32_SDheader      *sdh;
83     struct PnPBIOS_table        *pt;
84     u_int8_t                    ck, *cv;
85     int                         i;
86     char                        *p;
87     
88     /*
89      * BIOS32 Service Directory, PCI BIOS
90      */
91     
92     /* look for the signature */
93     if ((sigaddr = bios_sigsearch(0, "_32_", 4, 16, 0)) != 0) {
94
95         /* get a virtual pointer to the structure */
96         sdh = (struct bios32_SDheader *)(uintptr_t)BIOS_PADDRTOVADDR(sigaddr);
97         for (cv = (u_int8_t *)sdh, ck = 0, i = 0; i < (sdh->len * 16); i++) {
98             ck += cv[i];
99         }
100         /* If checksum is OK, enable use of the entrypoint */
101         if ((ck == 0) && (BIOS_START <= sdh->entry ) &&
102             (sdh->entry < (BIOS_START + BIOS_SIZE))) {
103             bios32_SDCI = BIOS_PADDRTOVADDR(sdh->entry);
104             if (bootverbose) {
105                 printf("bios32: Found BIOS32 Service Directory header at %p\n", sdh);
106                 printf("bios32: Entry = 0x%x (%x)  Rev = %d  Len = %d\n", 
107                        sdh->entry, bios32_SDCI, sdh->revision, sdh->len);
108             }
109
110             /* Allow user override of PCI BIOS search */
111             if (((p = kern_getenv("machdep.bios.pci")) == NULL) || strcmp(p, "disable")) {
112
113                 /* See if there's a PCI BIOS entrypoint here */
114                 PCIbios.ident.id = 0x49435024;  /* PCI systems should have this */
115                 if (!bios32_SDlookup(&PCIbios) && bootverbose)
116                     printf("pcibios: PCI BIOS entry at 0x%x+0x%x\n", PCIbios.base, PCIbios.entry);
117             }
118             if (p != NULL)
119                     freeenv(p);
120         } else {
121             printf("bios32: Bad BIOS32 Service Directory\n");
122         }
123     }
124
125     /*
126      * PnP BIOS
127      *
128      * Allow user override of PnP BIOS search
129      */
130     if ((((p = kern_getenv("machdep.bios.pnp")) == NULL) || strcmp(p, "disable")) &&
131         ((sigaddr = bios_sigsearch(0, "$PnP", 4, 16, 0)) != 0)) {
132
133         /* get a virtual pointer to the structure */
134         pt = (struct PnPBIOS_table *)(uintptr_t)BIOS_PADDRTOVADDR(sigaddr);
135         for (cv = (u_int8_t *)pt, ck = 0, i = 0; i < pt->len; i++) {
136             ck += cv[i];
137         }
138         /* If checksum is OK, enable use of the entrypoint */
139         if (ck == 0) {
140             PnPBIOStable = pt;
141             if (bootverbose) {
142                 printf("pnpbios: Found PnP BIOS data at %p\n", pt);
143                 printf("pnpbios: Entry = %x:%x  Rev = %d.%d\n", 
144                        pt->pmentrybase, pt->pmentryoffset, pt->version >> 4, pt->version & 0xf);
145                 if ((pt->control & 0x3) == 0x01)
146                     printf("pnpbios: Event flag at %x\n", pt->evflagaddr);
147                 if (pt->oemdevid != 0)
148                     printf("pnpbios: OEM ID %x\n", pt->oemdevid);
149                 
150             }
151         } else {
152             printf("pnpbios: Bad PnP BIOS data checksum\n");
153         }
154     }
155     if (p != NULL)
156             freeenv(p);
157     if (bootverbose) {
158             /* look for other know signatures */
159             printf("Other BIOS signatures found:\n");
160     }
161 }
162
163 /*
164  * bios32_SDlookup
165  *
166  * Query the BIOS32 Service Directory for the service named in (ent),
167  * returns nonzero if the lookup fails.  The caller must fill in
168  * (ent->ident), the remainder are populated on a successful lookup.
169  */
170 int
171 bios32_SDlookup(struct bios32_SDentry *ent)
172 {
173     struct bios_regs args;
174
175     if (bios32_SDCI == 0)
176         return (1);
177
178     args.eax = ent->ident.id;           /* set up arguments */
179     args.ebx = args.ecx = args.edx = 0;
180     bios32(&args, bios32_SDCI, GSEL(GCODE_SEL, SEL_KPL));
181     if ((args.eax & 0xff) == 0) {       /* success? */
182         ent->base = args.ebx;
183         ent->len = args.ecx;
184         ent->entry = args.edx;
185         ent->ventry = BIOS_PADDRTOVADDR(ent->base + ent->entry);
186         return (0);                     /* all OK */
187     }
188     return (1);                         /* failed */
189 }
190
191
192 /*
193  * bios_sigsearch
194  *
195  * Search some or all of the BIOS region for a signature string.
196  *
197  * (start)      Optional offset returned from this function 
198  *              (for searching for multiple matches), or NULL
199  *              to start the search from the base of the BIOS.
200  *              Note that this will be a _physical_ address in
201  *              the range 0xe0000 - 0xfffff.
202  * (sig)        is a pointer to the byte(s) of the signature.
203  * (siglen)     number of bytes in the signature.
204  * (paralen)    signature paragraph (alignment) size.
205  * (sigofs)     offset of the signature within the paragraph.
206  *
207  * Returns the _physical_ address of the found signature, 0 if the
208  * signature was not found.
209  */
210
211 u_int32_t
212 bios_sigsearch(u_int32_t start, u_char *sig, int siglen, int paralen, int sigofs)
213 {
214     u_char      *sp, *end;
215     
216     /* compute the starting address */
217     if ((start >= BIOS_START) && (start <= (BIOS_START + BIOS_SIZE))) {
218         sp = (char *)BIOS_PADDRTOVADDR(start);
219     } else if (start == 0) {
220         sp = (char *)BIOS_PADDRTOVADDR(BIOS_START);
221     } else {
222         return 0;                               /* bogus start address */
223     }
224
225     /* compute the end address */
226     end = (u_char *)BIOS_PADDRTOVADDR(BIOS_START + BIOS_SIZE);
227
228     /* loop searching */
229     while ((sp + sigofs + siglen) < end) {
230         
231         /* compare here */
232         if (!bcmp(sp + sigofs, sig, siglen)) {
233             /* convert back to physical address */
234             return((u_int32_t)BIOS_VADDRTOPADDR(sp));
235         }
236         sp += paralen;
237     }
238     return(0);
239 }
240
241 /*
242  * do not staticize, used by bioscall.s
243  */
244 union {
245     struct {
246         u_short offset;
247         u_short segment;
248     } vec16;
249     struct {
250         u_int   offset;
251         u_short segment;
252     } vec32;
253 } bioscall_vector;                      /* bios jump vector */
254
255 void
256 set_bios_selectors(struct bios_segments *seg, int flags)
257 {
258     struct soft_segment_descriptor ssd = {
259         0,                      /* segment base address (overwritten) */
260         0,                      /* length (overwritten) */
261         SDT_MEMERA,             /* segment type (overwritten) */
262         0,                      /* priority level */
263         1,                      /* descriptor present */
264         0, 0,
265         1,                      /* descriptor size (overwritten) */
266         0                       /* granularity == byte units */
267     };
268     union descriptor *p_gdt;
269
270 #ifdef SMP
271     p_gdt = &gdt[PCPU_GET(cpuid) * NGDT];
272 #else
273     p_gdt = gdt;
274 #endif
275         
276     ssd.ssd_base = seg->code32.base;
277     ssd.ssd_limit = seg->code32.limit;
278     ssdtosd(&ssd, &p_gdt[GBIOSCODE32_SEL].sd);
279
280     ssd.ssd_def32 = 0;
281     if (flags & BIOSCODE_FLAG) {
282         ssd.ssd_base = seg->code16.base;
283         ssd.ssd_limit = seg->code16.limit;
284         ssdtosd(&ssd, &p_gdt[GBIOSCODE16_SEL].sd);
285     }
286
287     ssd.ssd_type = SDT_MEMRWA;
288     if (flags & BIOSDATA_FLAG) {
289         ssd.ssd_base = seg->data.base;
290         ssd.ssd_limit = seg->data.limit;
291         ssdtosd(&ssd, &p_gdt[GBIOSDATA_SEL].sd);
292     }
293
294     if (flags & BIOSUTIL_FLAG) {
295         ssd.ssd_base = seg->util.base;
296         ssd.ssd_limit = seg->util.limit;
297         ssdtosd(&ssd, &p_gdt[GBIOSUTIL_SEL].sd);
298     }
299
300     if (flags & BIOSARGS_FLAG) {
301         ssd.ssd_base = seg->args.base;
302         ssd.ssd_limit = seg->args.limit;
303         ssdtosd(&ssd, &p_gdt[GBIOSARGS_SEL].sd);
304     }
305 }
306
307 extern int vm86pa;
308 extern u_long vm86phystk;
309 extern void bios16_jmp(void);
310
311 /*
312  * this routine is really greedy with selectors, and uses 5:
313  *
314  * 32-bit code selector:        to return to kernel
315  * 16-bit code selector:        for running code
316  *        data selector:        for 16-bit data
317  *        util selector:        extra utility selector
318  *        args selector:        to handle pointers
319  *
320  * the util selector is set from the util16 entry in bios16_args, if a
321  * "U" specifier is seen.
322  *
323  * See <machine/pc/bios.h> for description of format specifiers
324  */
325 int
326 bios16(struct bios_args *args, char *fmt, ...)
327 {
328     char        *p, *stack, *stack_top;
329     va_list     ap;
330     int         flags = BIOSCODE_FLAG | BIOSDATA_FLAG;
331     u_int       i, arg_start, arg_end;
332     void        *bios16_pmap_handle;
333     arg_start = 0xffffffff;
334     arg_end = 0;
335
336     /*
337      * Some BIOS entrypoints attempt to copy the largest-case
338      * argument frame (in order to generalise handling for 
339      * different entry types).  If our argument frame is 
340      * smaller than this, the BIOS will reach off the top of
341      * our constructed stack segment.  Pad the top of the stack
342      * with some garbage to avoid this.
343      */
344     stack = (caddr_t)PAGE_SIZE - 32;
345
346     va_start(ap, fmt);
347     for (p = fmt; p && *p; p++) {
348         switch (*p) {
349         case 'p':                       /* 32-bit pointer */
350             i = va_arg(ap, u_int);
351             arg_start = min(arg_start, i);
352             arg_end = max(arg_end, i);
353             flags |= BIOSARGS_FLAG;
354             stack -= 4;
355             break;
356
357         case 'i':                       /* 32-bit integer */
358             i = va_arg(ap, u_int);
359             stack -= 4;
360             break;
361
362         case 'U':                       /* 16-bit selector */
363             flags |= BIOSUTIL_FLAG;
364             /* FALLTHROUGH */
365         case 'D':                       /* 16-bit selector */
366         case 'C':                       /* 16-bit selector */
367             stack -= 2;
368             break;
369             
370         case 's':                       /* 16-bit integer passed as an int */
371             i = va_arg(ap, int);
372             stack -= 2;
373             break;
374
375         default:
376             va_end(ap);
377             return (EINVAL);
378         }
379     }
380     va_end(ap);
381
382     if (flags & BIOSARGS_FLAG) {
383         if (arg_end - arg_start > ctob(16))
384             return (EACCES);
385         args->seg.args.base = arg_start;
386         args->seg.args.limit = 0xffff;
387     }
388
389     args->seg.code32.base = pmap_pg_frame((u_int)&bios16_jmp);
390     args->seg.code32.limit = 0xffff;    
391
392     bios16_pmap_handle = pmap_bios16_enter();
393
394     stack_top = stack;
395     va_start(ap, fmt);
396     for (p = fmt; p && *p; p++) {
397         switch (*p) {
398         case 'p':                       /* 32-bit pointer */
399             i = va_arg(ap, u_int);
400             *(u_int *)stack = (i - arg_start) |
401                 (GSEL(GBIOSARGS_SEL, SEL_KPL) << 16);
402             stack += 4;
403             break;
404
405         case 'i':                       /* 32-bit integer */
406             i = va_arg(ap, u_int);
407             *(u_int *)stack = i;
408             stack += 4;
409             break;
410
411         case 'U':                       /* 16-bit selector */
412             *(u_short *)stack = GSEL(GBIOSUTIL_SEL, SEL_KPL);
413             stack += 2;
414             break;
415
416         case 'D':                       /* 16-bit selector */
417             *(u_short *)stack = GSEL(GBIOSDATA_SEL, SEL_KPL);
418             stack += 2;
419             break;
420
421         case 'C':                       /* 16-bit selector */
422             *(u_short *)stack = GSEL(GBIOSCODE16_SEL, SEL_KPL);
423             stack += 2;
424             break;
425
426         case 's':                       /* 16-bit integer passed as an int */
427             i = va_arg(ap, int);
428             *(u_short *)stack = i;
429             stack += 2;
430             break;
431
432         default:
433             va_end(ap);
434             return (EINVAL);
435         }
436     }
437     va_end(ap);
438
439     set_bios_selectors(&args->seg, flags);
440     bioscall_vector.vec16.offset = (u_short)args->entry;
441     bioscall_vector.vec16.segment = GSEL(GBIOSCODE16_SEL, SEL_KPL);
442
443     i = bios16_call(&args->r, stack_top);
444     pmap_bios16_leave(bios16_pmap_handle);
445     return (i);
446 }
447
448 int
449 bios_oem_strings(struct bios_oem *oem, u_char *buffer, size_t maxlen)
450 {
451         size_t idx = 0;
452         struct bios_oem_signature *sig;
453         u_int from, to;
454         u_char c, *s, *se, *str, *bios_str;
455         size_t i, off, len, tot;
456
457         if ( !oem || !buffer || maxlen<2 )
458                 return(-1);
459
460         sig = oem->signature;
461         if (!sig)
462                 return(-2);
463
464         from = oem->range.from;
465         to = oem->range.to;
466         if ( (to<=from) || (from<BIOS_START) || (to>(BIOS_START+BIOS_SIZE)) )
467                 return(-3);
468
469         while (sig->anchor != NULL) {
470                 str = sig->anchor;
471                 len = strlen(str);
472                 off = sig->offset;
473                 tot = sig->totlen;
474                 /* make sure offset doesn't go beyond bios area */
475                 if ( (to+off)>(BIOS_START+BIOS_SIZE) ||
476                                         ((from+off)<BIOS_START) ) {
477                         printf("sys/i386/i386/bios.c: sig '%s' "
478                                 "from 0x%0x to 0x%0x offset %d "
479                                 "out of BIOS bounds 0x%0x - 0x%0x\n",
480                                 str, from, to, off,
481                                 BIOS_START, BIOS_START+BIOS_SIZE);
482                         return(-4);
483                 }
484                 /* make sure we don't overrun return buffer */
485                 if (idx + tot > maxlen - 1) {
486                         printf("sys/i386/i386/bios.c: sig '%s' "
487                                 "idx %d + tot %d = %d > maxlen-1 %d\n",
488                                 str, idx, tot, idx+tot, maxlen-1);
489                         return(-5);
490                 }
491                 bios_str = NULL;
492                 s = (u_char *)BIOS_PADDRTOVADDR(from);
493                 se = (u_char *)BIOS_PADDRTOVADDR(to-len);
494                 for (; s<se; s++) {
495                         if (!bcmp(str, s, len)) {
496                                 bios_str = s;
497                                 break;
498                         }
499                 }
500                 /*
501                 *  store pretty version of totlen bytes of bios string with
502                 *  given offset; 0x20 - 0x7E are printable; uniquify spaces
503                 */
504                 if (bios_str) {
505                         for (i=0; i<tot; i++) {
506                                 c = bios_str[i+off];
507                                 if ( (c < 0x20) || (c > 0x7E) )
508                                         c = ' ';
509                                 if (idx == 0) {
510                                         if (c != ' ')
511                                                 buffer[idx++] = c;
512                                 } else if ( (c != ' ') ||
513                                         ((c == ' ') && (buffer[idx-1] != ' ')) )
514                                                 buffer[idx++] = c;
515                         }
516                 }
517                 sig++;
518         }
519         /* remove a final trailing space */
520         if ( (idx > 1) && (buffer[idx-1] == ' ') )
521                 idx--;
522         buffer[idx] = '\0';
523         return (idx);
524 }
525
526 #ifdef DEV_ISA
527 /*
528  * PnP BIOS interface; enumerate devices only known to the system
529  * BIOS and save information about them for later use.
530  */
531
532 struct pnp_sysdev 
533 {
534     u_int16_t   size;
535     u_int8_t    handle;
536     u_int32_t   devid;
537     u_int8_t    type[3];
538     u_int16_t   attrib;
539 #define PNPATTR_NODISABLE       (1<<0)  /* can't be disabled */
540 #define PNPATTR_NOCONFIG        (1<<1)  /* can't be configured */
541 #define PNPATTR_OUTPUT          (1<<2)  /* can be primary output */
542 #define PNPATTR_INPUT           (1<<3)  /* can be primary input */
543 #define PNPATTR_BOOTABLE        (1<<4)  /* can be booted from */
544 #define PNPATTR_DOCK            (1<<5)  /* is a docking station */
545 #define PNPATTR_REMOVEABLE      (1<<6)  /* device is removeable */
546 #define PNPATTR_CONFIG_STATIC   (0)
547 #define PNPATTR_CONFIG_DYNAMIC  (1)
548 #define PNPATTR_CONFIG_DYNONLY  (3)
549 #define PNPATTR_CONFIG(a)       (((a) >> 7) & 0x3)
550     /* device-specific data comes here */
551     u_int8_t    devdata[0];
552 } __packed;
553
554 /* We have to cluster arguments within a 64k range for the bios16 call */
555 struct pnp_sysdevargs
556 {
557     u_int16_t   next;
558     struct pnp_sysdev node;
559 };
560
561 /*
562  * This function is called after the bus has assigned resource
563  * locations for a logical device.
564  */
565 static void
566 pnpbios_set_config(void *arg, struct isa_config *config, int enable)
567 {
568 }
569
570 /*
571  * Quiz the PnP BIOS, build a list of PNP IDs and resource data.
572  */
573 static void
574 pnpbios_identify(driver_t *driver, device_t parent)
575 {
576     struct PnPBIOS_table        *pt = PnPBIOStable;
577     struct bios_args            args;
578     struct pnp_sysdev           *pd;
579     struct pnp_sysdevargs       *pda;
580     u_int16_t                   ndevs, bigdev;
581     int                         error, currdev;
582     u_int8_t                    *devnodebuf, tag;
583     u_int32_t                   *devid, *compid;
584     int                         idx, left;
585     device_t                    dev;
586         
587     /* no PnP BIOS information */
588     if (pt == NULL)
589         return;
590
591     /* Check to see if ACPI is already active. */
592     dev = devclass_get_device(devclass_find("acpi"), 0);
593     if (dev != NULL && device_is_attached(dev)) 
594         return;
595
596     /* get count of PnP devices */
597     bzero(&args, sizeof(args));
598     args.seg.code16.base = BIOS_PADDRTOVADDR(pt->pmentrybase);
599     args.seg.code16.limit = 0xffff;             /* XXX ? */
600     args.seg.data.base = BIOS_PADDRTOVADDR(pt->pmdataseg);
601     args.seg.data.limit = 0xffff;
602     args.entry = pt->pmentryoffset;
603     
604     if ((error = bios16(&args, PNP_COUNT_DEVNODES, &ndevs, &bigdev)) || (args.r.eax & 0xff)) {
605         printf("pnpbios: error %d/%x getting device count/size limit\n", error, args.r.eax);
606         return;
607     }
608     ndevs &= 0xff;                              /* clear high byte garbage */
609     if (bootverbose)
610         printf("pnpbios: %d devices, largest %d bytes\n", ndevs, bigdev);
611
612     devnodebuf = malloc(bigdev + (sizeof(struct pnp_sysdevargs) - sizeof(struct pnp_sysdev)),
613                         M_DEVBUF, M_NOWAIT);
614     if (devnodebuf == NULL) {
615         printf("pnpbios: cannot allocate memory, bailing\n");
616         return;
617     }
618     pda = (struct pnp_sysdevargs *)devnodebuf;
619     pd = &pda->node;
620
621     for (currdev = 0, left = ndevs; (currdev != 0xff) && (left > 0); left--) {
622
623         bzero(pd, bigdev);
624         pda->next = currdev;
625         /* get current configuration */
626         if ((error = bios16(&args, PNP_GET_DEVNODE, &pda->next, &pda->node, 1))) {
627             printf("pnpbios: error %d making BIOS16 call\n", error);
628             break;
629         }
630         if ((error = (args.r.eax & 0xff))) {
631             if (bootverbose)
632                 printf("pnpbios: %s 0x%x fetching node %d\n", error & 0x80 ? "error" : "warning", error, currdev);
633             if (error & 0x80) 
634                 break;
635         }
636         currdev = pda->next;
637         if (pd->size < sizeof(struct pnp_sysdev)) {
638             printf("pnpbios: bogus system node data, aborting scan\n");
639             break;
640         }
641
642         /*
643          * Ignore PICs so that we don't have to worry about the PICs
644          * claiming IRQs to prevent their use.  The PIC drivers
645          * already ensure that invalid IRQs are not used.
646          */
647         if (!strcmp(pnp_eisaformat(pd->devid), "PNP0000"))      /* ISA PIC */
648             continue;
649         if (!strcmp(pnp_eisaformat(pd->devid), "PNP0003"))      /* APIC */
650             continue;
651         
652         /* Add the device and parse its resources */
653         dev = BUS_ADD_CHILD(parent, ISA_ORDER_PNPBIOS, NULL, -1);
654         isa_set_vendorid(dev, pd->devid);
655         isa_set_logicalid(dev, pd->devid);
656         /*
657          * It appears that some PnP BIOS doesn't allow us to re-enable
658          * the embedded system device once it is disabled.  We shall
659          * mark all system device nodes as "cannot be disabled", regardless
660          * of actual settings in the device attribute byte.
661          * XXX
662         isa_set_configattr(dev, 
663             ((pd->attrib & PNPATTR_NODISABLE) ?  0 : ISACFGATTR_CANDISABLE) |
664             ((!(pd->attrib & PNPATTR_NOCONFIG) && 
665                 PNPATTR_CONFIG(pd->attrib) != PNPATTR_CONFIG_STATIC)
666                 ? ISACFGATTR_DYNAMIC : 0));
667          */
668         isa_set_configattr(dev, 
669             (!(pd->attrib & PNPATTR_NOCONFIG) && 
670                 PNPATTR_CONFIG(pd->attrib) != PNPATTR_CONFIG_STATIC)
671                 ? ISACFGATTR_DYNAMIC : 0);
672         isa_set_pnpbios_handle(dev, pd->handle);
673         ISA_SET_CONFIG_CALLBACK(parent, dev, pnpbios_set_config, 0);
674         pnp_parse_resources(dev, &pd->devdata[0],
675             pd->size - sizeof(struct pnp_sysdev), 0);
676         if (!device_get_desc(dev))
677             device_set_desc_copy(dev, pnp_eisaformat(pd->devid));
678
679         /* Find device IDs */
680         devid = &pd->devid;
681         compid = NULL;
682
683         /* look for a compatible device ID too */
684         left = pd->size - sizeof(struct pnp_sysdev);
685         idx = 0;
686         while (idx < left) {
687             tag = pd->devdata[idx++];
688             if (PNP_RES_TYPE(tag) == 0) {
689                 /* Small resource */
690                 switch (PNP_SRES_NUM(tag)) {
691                 case PNP_TAG_COMPAT_DEVICE:
692                     compid = (u_int32_t *)(pd->devdata + idx);
693                     if (bootverbose)
694                         printf("pnpbios: node %d compat ID 0x%08x\n", pd->handle, *compid);
695                     /* FALLTHROUGH */
696                 case PNP_TAG_END:
697                     idx = left;
698                     break;
699                 default:
700                     idx += PNP_SRES_LEN(tag);
701                     break;
702                 }
703             } else
704                 /* Large resource, skip it */
705                 idx += *(u_int16_t *)(pd->devdata + idx) + 2;
706         }
707         if (bootverbose) {
708             printf("pnpbios: handle %d device ID %s (%08x)", 
709                    pd->handle, pnp_eisaformat(*devid), *devid);
710             if (compid != NULL)
711                 printf(" compat ID %s (%08x)",
712                        pnp_eisaformat(*compid), *compid);
713             printf("\n");
714         }
715     }
716 }
717
718 static device_method_t pnpbios_methods[] = {
719         /* Device interface */
720         DEVMETHOD(device_identify,      pnpbios_identify),
721
722         { 0, 0 }
723 };
724
725 static driver_t pnpbios_driver = {
726         "pnpbios",
727         pnpbios_methods,
728         1,                      /* no softc */
729 };
730
731 static devclass_t pnpbios_devclass;
732
733 DRIVER_MODULE(pnpbios, isa, pnpbios_driver, pnpbios_devclass, 0, 0);
734 #endif /* DEV_ISA */