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