1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 * 26 * Copyright (c) 2010, Intel Corporation. 27 * All rights reserved. 28 * 29 * Copyright 2018 Joyent, Inc. All rights reserved. 30 */ 31 32 /* 33 * This file contains the functionality that mimics the boot operations 34 * on SPARC systems or the old boot.bin/multiboot programs on x86 systems. 35 * The x86 kernel now does everything on its own. 36 */ 37 38 #include <sys/types.h> 39 #include <sys/bootconf.h> 40 #include <sys/bootsvcs.h> 41 #include <sys/bootinfo.h> 42 #include <sys/multiboot.h> 43 #include <sys/multiboot2.h> 44 #include <sys/multiboot2_impl.h> 45 #include <sys/bootvfs.h> 46 #include <sys/bootprops.h> 47 #include <sys/varargs.h> 48 #include <sys/param.h> 49 #include <sys/machparam.h> 50 #include <sys/machsystm.h> 51 #include <sys/archsystm.h> 52 #include <sys/boot_console.h> 53 #include <sys/cmn_err.h> 54 #include <sys/systm.h> 55 #include <sys/promif.h> 56 #include <sys/archsystm.h> 57 #include <sys/x86_archext.h> 58 #include <sys/kobj.h> 59 #include <sys/privregs.h> 60 #include <sys/sysmacros.h> 61 #include <sys/ctype.h> 62 #include <sys/fastboot.h> 63 #ifdef __xpv 64 #include <sys/hypervisor.h> 65 #include <net/if.h> 66 #endif 67 #include <vm/kboot_mmu.h> 68 #include <vm/hat_pte.h> 69 #include <sys/kobj.h> 70 #include <sys/kobj_lex.h> 71 #include <sys/pci_cfgspace_impl.h> 72 #include <sys/fastboot_impl.h> 73 #include <sys/acpi/acconfig.h> 74 #include <sys/acpi/acpi.h> 75 76 static int have_console = 0; /* set once primitive console is initialized */ 77 static char *boot_args = ""; 78 79 /* 80 * Debugging macros 81 */ 82 static uint_t kbm_debug = 0; 83 #define DBG_MSG(s) { if (kbm_debug) bop_printf(NULL, "%s", s); } 84 #define DBG(x) { if (kbm_debug) \ 85 bop_printf(NULL, "%s is %" PRIx64 "\n", #x, (uint64_t)(x)); \ 86 } 87 88 #define PUT_STRING(s) { \ 89 char *cp; \ 90 for (cp = (s); *cp; ++cp) \ 91 bcons_putchar(*cp); \ 92 } 93 94 bootops_t bootop; /* simple bootops we'll pass on to kernel */ 95 struct bsys_mem bm; 96 97 /* 98 * Boot info from "glue" code in low memory. xbootp is used by: 99 * do_bop_phys_alloc(), do_bsys_alloc() and boot_prop_finish(). 100 */ 101 static struct xboot_info *xbootp; 102 static uintptr_t next_virt; /* next available virtual address */ 103 static paddr_t next_phys; /* next available physical address from dboot */ 104 static paddr_t high_phys = -(paddr_t)1; /* last used physical address */ 105 106 /* 107 * buffer for vsnprintf for console I/O 108 */ 109 #define BUFFERSIZE 512 110 static char buffer[BUFFERSIZE]; 111 112 /* 113 * stuff to store/report/manipulate boot property settings. 114 */ 115 typedef struct bootprop { 116 struct bootprop *bp_next; 117 char *bp_name; 118 uint_t bp_vlen; 119 char *bp_value; 120 } bootprop_t; 121 122 static bootprop_t *bprops = NULL; 123 static char *curr_page = NULL; /* ptr to avail bprop memory */ 124 static int curr_space = 0; /* amount of memory at curr_page */ 125 126 #ifdef __xpv 127 start_info_t *xen_info; 128 shared_info_t *HYPERVISOR_shared_info; 129 #endif 130 131 /* 132 * some allocator statistics 133 */ 134 static ulong_t total_bop_alloc_scratch = 0; 135 static ulong_t total_bop_alloc_kernel = 0; 136 137 static void build_firmware_properties(struct xboot_info *); 138 139 static int early_allocation = 1; 140 141 int force_fastreboot = 0; 142 volatile int fastreboot_onpanic = 0; 143 int post_fastreboot = 0; 144 #ifdef __xpv 145 volatile int fastreboot_capable = 0; 146 #else 147 volatile int fastreboot_capable = 1; 148 #endif 149 150 /* 151 * Information saved from current boot for fast reboot. 152 * If the information size exceeds what we have allocated, fast reboot 153 * will not be supported. 154 */ 155 multiboot_info_t saved_mbi; 156 mb_memory_map_t saved_mmap[FASTBOOT_SAVED_MMAP_COUNT]; 157 uint8_t saved_drives[FASTBOOT_SAVED_DRIVES_SIZE]; 158 char saved_cmdline[FASTBOOT_SAVED_CMDLINE_LEN]; 159 int saved_cmdline_len = 0; 160 size_t saved_file_size[FASTBOOT_MAX_FILES_MAP]; 161 162 /* 163 * Turn off fastreboot_onpanic to avoid panic loop. 164 */ 165 char fastreboot_onpanic_cmdline[FASTBOOT_SAVED_CMDLINE_LEN]; 166 static const char fastreboot_onpanic_args[] = " -B fastreboot_onpanic=0"; 167 168 /* 169 * Pointers to where System Resource Affinity Table (SRAT), System Locality 170 * Information Table (SLIT) and Maximum System Capability Table (MSCT) 171 * are mapped into virtual memory 172 */ 173 ACPI_TABLE_SRAT *srat_ptr = NULL; 174 ACPI_TABLE_SLIT *slit_ptr = NULL; 175 ACPI_TABLE_MSCT *msct_ptr = NULL; 176 177 /* 178 * Arbitrary limit on number of localities we handle; if 179 * this limit is raised to more than UINT16_MAX, make sure 180 * process_slit() knows how to handle it. 181 */ 182 #define SLIT_LOCALITIES_MAX (4096) 183 184 #define SLIT_NUM_PROPNAME "acpi-slit-localities" 185 #define SLIT_PROPNAME "acpi-slit" 186 187 /* 188 * Allocate aligned physical memory at boot time. This allocator allocates 189 * from the highest possible addresses. This avoids exhausting memory that 190 * would be useful for DMA buffers. 191 */ 192 paddr_t 193 do_bop_phys_alloc(uint64_t size, uint64_t align) 194 { 195 paddr_t pa = 0; 196 paddr_t start; 197 paddr_t end; 198 struct memlist *ml = (struct memlist *)xbootp->bi_phys_install; 199 200 /* 201 * Be careful if high memory usage is limited in startup.c 202 * Since there are holes in the low part of the physical address 203 * space we can treat physmem as a pfn (not just a pgcnt) and 204 * get a conservative upper limit. 205 */ 206 if (physmem != 0 && high_phys > pfn_to_pa(physmem)) 207 high_phys = pfn_to_pa(physmem); 208 209 /* 210 * find the highest available memory in physinstalled 211 */ 212 size = P2ROUNDUP(size, align); 213 for (; ml; ml = ml->ml_next) { 214 start = P2ROUNDUP(ml->ml_address, align); 215 end = P2ALIGN(ml->ml_address + ml->ml_size, align); 216 if (start < next_phys) 217 start = P2ROUNDUP(next_phys, align); 218 if (end > high_phys) 219 end = P2ALIGN(high_phys, align); 220 221 if (end <= start) 222 continue; 223 if (end - start < size) 224 continue; 225 226 /* 227 * Early allocations need to use low memory, since 228 * physmem might be further limited by bootenv.rc 229 */ 230 if (early_allocation) { 231 if (pa == 0 || start < pa) 232 pa = start; 233 } else { 234 if (end - size > pa) 235 pa = end - size; 236 } 237 } 238 if (pa != 0) { 239 if (early_allocation) 240 next_phys = pa + size; 241 else 242 high_phys = pa; 243 return (pa); 244 } 245 bop_panic("do_bop_phys_alloc(0x%" PRIx64 ", 0x%" PRIx64 246 ") Out of memory\n", size, align); 247 /*NOTREACHED*/ 248 } 249 250 uintptr_t 251 alloc_vaddr(size_t size, paddr_t align) 252 { 253 uintptr_t rv; 254 255 next_virt = P2ROUNDUP(next_virt, (uintptr_t)align); 256 rv = (uintptr_t)next_virt; 257 next_virt += size; 258 return (rv); 259 } 260 261 /* 262 * Allocate virtual memory. The size is always rounded up to a multiple 263 * of base pagesize. 264 */ 265 266 /*ARGSUSED*/ 267 static caddr_t 268 do_bsys_alloc(bootops_t *bop, caddr_t virthint, size_t size, int align) 269 { 270 paddr_t a = align; /* same type as pa for masking */ 271 uint_t pgsize; 272 paddr_t pa; 273 uintptr_t va; 274 ssize_t s; /* the aligned size */ 275 uint_t level; 276 uint_t is_kernel = (virthint != 0); 277 278 if (a < MMU_PAGESIZE) 279 a = MMU_PAGESIZE; 280 else if (!ISP2(a)) 281 prom_panic("do_bsys_alloc() incorrect alignment"); 282 size = P2ROUNDUP(size, MMU_PAGESIZE); 283 284 /* 285 * Use the next aligned virtual address if we weren't given one. 286 */ 287 if (virthint == NULL) { 288 virthint = (caddr_t)alloc_vaddr(size, a); 289 total_bop_alloc_scratch += size; 290 } else { 291 total_bop_alloc_kernel += size; 292 } 293 294 /* 295 * allocate the physical memory 296 */ 297 pa = do_bop_phys_alloc(size, a); 298 299 /* 300 * Add the mappings to the page tables, try large pages first. 301 */ 302 va = (uintptr_t)virthint; 303 s = size; 304 level = 1; 305 pgsize = xbootp->bi_use_pae ? TWO_MEG : FOUR_MEG; 306 if (xbootp->bi_use_largepage && a == pgsize) { 307 while (IS_P2ALIGNED(pa, pgsize) && IS_P2ALIGNED(va, pgsize) && 308 s >= pgsize) { 309 kbm_map(va, pa, level, is_kernel); 310 va += pgsize; 311 pa += pgsize; 312 s -= pgsize; 313 } 314 } 315 316 /* 317 * Map remaining pages use small mappings 318 */ 319 level = 0; 320 pgsize = MMU_PAGESIZE; 321 while (s > 0) { 322 kbm_map(va, pa, level, is_kernel); 323 va += pgsize; 324 pa += pgsize; 325 s -= pgsize; 326 } 327 return (virthint); 328 } 329 330 /* 331 * Free virtual memory - we'll just ignore these. 332 */ 333 /*ARGSUSED*/ 334 static void 335 do_bsys_free(bootops_t *bop, caddr_t virt, size_t size) 336 { 337 bop_printf(NULL, "do_bsys_free(virt=0x%p, size=0x%lx) ignored\n", 338 (void *)virt, size); 339 } 340 341 /* 342 * Old interface 343 */ 344 /*ARGSUSED*/ 345 static caddr_t 346 do_bsys_ealloc(bootops_t *bop, caddr_t virthint, size_t size, 347 int align, int flags) 348 { 349 prom_panic("unsupported call to BOP_EALLOC()\n"); 350 return (0); 351 } 352 353 354 static void 355 bsetprop(char *name, int nlen, void *value, int vlen) 356 { 357 uint_t size; 358 uint_t need_size; 359 bootprop_t *b; 360 361 /* 362 * align the size to 16 byte boundary 363 */ 364 size = sizeof (bootprop_t) + nlen + 1 + vlen; 365 size = (size + 0xf) & ~0xf; 366 if (size > curr_space) { 367 need_size = (size + (MMU_PAGEOFFSET)) & MMU_PAGEMASK; 368 curr_page = do_bsys_alloc(NULL, 0, need_size, MMU_PAGESIZE); 369 curr_space = need_size; 370 } 371 372 /* 373 * use a bootprop_t at curr_page and link into list 374 */ 375 b = (bootprop_t *)curr_page; 376 curr_page += sizeof (bootprop_t); 377 curr_space -= sizeof (bootprop_t); 378 b->bp_next = bprops; 379 bprops = b; 380 381 /* 382 * follow by name and ending zero byte 383 */ 384 b->bp_name = curr_page; 385 bcopy(name, curr_page, nlen); 386 curr_page += nlen; 387 *curr_page++ = 0; 388 curr_space -= nlen + 1; 389 390 /* 391 * copy in value, but no ending zero byte 392 */ 393 b->bp_value = curr_page; 394 b->bp_vlen = vlen; 395 if (vlen > 0) { 396 bcopy(value, curr_page, vlen); 397 curr_page += vlen; 398 curr_space -= vlen; 399 } 400 401 /* 402 * align new values of curr_page, curr_space 403 */ 404 while (curr_space & 0xf) { 405 ++curr_page; 406 --curr_space; 407 } 408 } 409 410 static void 411 bsetprops(char *name, char *value) 412 { 413 bsetprop(name, strlen(name), value, strlen(value) + 1); 414 } 415 416 static void 417 bsetprop64(char *name, uint64_t value) 418 { 419 bsetprop(name, strlen(name), (void *)&value, sizeof (value)); 420 } 421 422 static void 423 bsetpropsi(char *name, int value) 424 { 425 char prop_val[32]; 426 427 (void) snprintf(prop_val, sizeof (prop_val), "%d", value); 428 bsetprops(name, prop_val); 429 } 430 431 /* 432 * to find the size of the buffer to allocate 433 */ 434 /*ARGSUSED*/ 435 int 436 do_bsys_getproplen(bootops_t *bop, const char *name) 437 { 438 bootprop_t *b; 439 440 for (b = bprops; b; b = b->bp_next) { 441 if (strcmp(name, b->bp_name) != 0) 442 continue; 443 return (b->bp_vlen); 444 } 445 return (-1); 446 } 447 448 /* 449 * get the value associated with this name 450 */ 451 /*ARGSUSED*/ 452 int 453 do_bsys_getprop(bootops_t *bop, const char *name, void *value) 454 { 455 bootprop_t *b; 456 457 for (b = bprops; b; b = b->bp_next) { 458 if (strcmp(name, b->bp_name) != 0) 459 continue; 460 bcopy(b->bp_value, value, b->bp_vlen); 461 return (0); 462 } 463 return (-1); 464 } 465 466 /* 467 * get the name of the next property in succession from the standalone 468 */ 469 /*ARGSUSED*/ 470 static char * 471 do_bsys_nextprop(bootops_t *bop, char *name) 472 { 473 bootprop_t *b; 474 475 /* 476 * A null name is a special signal for the 1st boot property 477 */ 478 if (name == NULL || strlen(name) == 0) { 479 if (bprops == NULL) 480 return (NULL); 481 return (bprops->bp_name); 482 } 483 484 for (b = bprops; b; b = b->bp_next) { 485 if (name != b->bp_name) 486 continue; 487 b = b->bp_next; 488 if (b == NULL) 489 return (NULL); 490 return (b->bp_name); 491 } 492 return (NULL); 493 } 494 495 /* 496 * Parse numeric value from a string. Understands decimal, hex, octal, - and ~ 497 */ 498 static int 499 parse_value(char *p, uint64_t *retval) 500 { 501 int adjust = 0; 502 uint64_t tmp = 0; 503 int digit; 504 int radix = 10; 505 506 *retval = 0; 507 if (*p == '-' || *p == '~') 508 adjust = *p++; 509 510 if (*p == '0') { 511 ++p; 512 if (*p == 0) 513 return (0); 514 if (*p == 'x' || *p == 'X') { 515 radix = 16; 516 ++p; 517 } else { 518 radix = 8; 519 ++p; 520 } 521 } 522 while (*p) { 523 if ('0' <= *p && *p <= '9') 524 digit = *p - '0'; 525 else if ('a' <= *p && *p <= 'f') 526 digit = 10 + *p - 'a'; 527 else if ('A' <= *p && *p <= 'F') 528 digit = 10 + *p - 'A'; 529 else 530 return (-1); 531 if (digit >= radix) 532 return (-1); 533 tmp = tmp * radix + digit; 534 ++p; 535 } 536 if (adjust == '-') 537 tmp = -tmp; 538 else if (adjust == '~') 539 tmp = ~tmp; 540 *retval = tmp; 541 return (0); 542 } 543 544 static boolean_t 545 unprintable(char *value, int size) 546 { 547 int i; 548 549 if (size <= 0 || value[0] == '\0') 550 return (B_TRUE); 551 552 for (i = 0; i < size; i++) { 553 if (value[i] == '\0') 554 return (i != (size - 1)); 555 556 if (!isprint(value[i])) 557 return (B_TRUE); 558 } 559 return (B_FALSE); 560 } 561 562 /* 563 * Print out information about all boot properties. 564 * buffer is pointer to pre-allocated space to be used as temporary 565 * space for property values. 566 */ 567 static void 568 boot_prop_display(char *buffer) 569 { 570 char *name = ""; 571 int i, len; 572 573 bop_printf(NULL, "\nBoot properties:\n"); 574 575 while ((name = do_bsys_nextprop(NULL, name)) != NULL) { 576 bop_printf(NULL, "\t0x%p %s = ", (void *)name, name); 577 (void) do_bsys_getprop(NULL, name, buffer); 578 len = do_bsys_getproplen(NULL, name); 579 bop_printf(NULL, "len=%d ", len); 580 if (!unprintable(buffer, len)) { 581 buffer[len] = 0; 582 bop_printf(NULL, "%s\n", buffer); 583 continue; 584 } 585 for (i = 0; i < len; i++) { 586 bop_printf(NULL, "%02x", buffer[i] & 0xff); 587 if (i < len - 1) 588 bop_printf(NULL, "."); 589 } 590 bop_printf(NULL, "\n"); 591 } 592 } 593 594 /* 595 * 2nd part of building the table of boot properties. This includes: 596 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values) 597 * 598 * lines look like one of: 599 * ^$ 600 * ^# comment till end of line 601 * setprop name 'value' 602 * setprop name value 603 * setprop name "value" 604 * 605 * we do single character I/O since this is really just looking at memory 606 */ 607 void 608 boot_prop_finish(void) 609 { 610 int fd; 611 char *line; 612 int c; 613 int bytes_read; 614 char *name; 615 int n_len; 616 char *value; 617 int v_len; 618 char *inputdev; /* these override the command line if serial ports */ 619 char *outputdev; 620 char *consoledev; 621 uint64_t lvalue; 622 int use_xencons = 0; 623 extern int bootrd_debug; 624 625 #ifdef __xpv 626 if (!DOMAIN_IS_INITDOMAIN(xen_info)) 627 use_xencons = 1; 628 #endif /* __xpv */ 629 630 DBG_MSG("Opening /boot/solaris/bootenv.rc\n"); 631 fd = BRD_OPEN(bfs_ops, "/boot/solaris/bootenv.rc", 0); 632 DBG(fd); 633 634 line = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, MMU_PAGESIZE); 635 while (fd >= 0) { 636 637 /* 638 * get a line 639 */ 640 for (c = 0; ; ++c) { 641 bytes_read = BRD_READ(bfs_ops, fd, line + c, 1); 642 if (bytes_read == 0) { 643 if (c == 0) 644 goto done; 645 break; 646 } 647 if (line[c] == '\n') 648 break; 649 } 650 line[c] = 0; 651 652 /* 653 * ignore comment lines 654 */ 655 c = 0; 656 while (ISSPACE(line[c])) 657 ++c; 658 if (line[c] == '#' || line[c] == 0) 659 continue; 660 661 /* 662 * must have "setprop " or "setprop\t" 663 */ 664 if (strncmp(line + c, "setprop ", 8) != 0 && 665 strncmp(line + c, "setprop\t", 8) != 0) 666 continue; 667 c += 8; 668 while (ISSPACE(line[c])) 669 ++c; 670 if (line[c] == 0) 671 continue; 672 673 /* 674 * gather up the property name 675 */ 676 name = line + c; 677 n_len = 0; 678 while (line[c] && !ISSPACE(line[c])) 679 ++n_len, ++c; 680 681 /* 682 * gather up the value, if any 683 */ 684 value = ""; 685 v_len = 0; 686 while (ISSPACE(line[c])) 687 ++c; 688 if (line[c] != 0) { 689 value = line + c; 690 while (line[c] && !ISSPACE(line[c])) 691 ++v_len, ++c; 692 } 693 694 if (v_len >= 2 && value[0] == value[v_len - 1] && 695 (value[0] == '\'' || value[0] == '"')) { 696 ++value; 697 v_len -= 2; 698 } 699 name[n_len] = 0; 700 if (v_len > 0) 701 value[v_len] = 0; 702 else 703 continue; 704 705 /* 706 * ignore "boot-file" property, it's now meaningless 707 */ 708 if (strcmp(name, "boot-file") == 0) 709 continue; 710 if (strcmp(name, "boot-args") == 0 && 711 strlen(boot_args) > 0) 712 continue; 713 714 /* 715 * If a property was explicitly set on the command line 716 * it will override a setting in bootenv.rc 717 */ 718 if (do_bsys_getproplen(NULL, name) > 0) 719 continue; 720 721 bsetprop(name, n_len, value, v_len + 1); 722 } 723 done: 724 if (fd >= 0) 725 (void) BRD_CLOSE(bfs_ops, fd); 726 727 /* 728 * Check if we have to limit the boot time allocator 729 */ 730 if (do_bsys_getproplen(NULL, "physmem") != -1 && 731 do_bsys_getprop(NULL, "physmem", line) >= 0 && 732 parse_value(line, &lvalue) != -1) { 733 if (0 < lvalue && (lvalue < physmem || physmem == 0)) { 734 physmem = (pgcnt_t)lvalue; 735 DBG(physmem); 736 } 737 } 738 early_allocation = 0; 739 740 /* 741 * Check for bootrd_debug. 742 */ 743 if (find_boot_prop("bootrd_debug")) 744 bootrd_debug = 1; 745 746 /* 747 * check to see if we have to override the default value of the console 748 */ 749 if (!use_xencons) { 750 inputdev = line; 751 v_len = do_bsys_getproplen(NULL, "input-device"); 752 if (v_len > 0) 753 (void) do_bsys_getprop(NULL, "input-device", inputdev); 754 else 755 v_len = 0; 756 inputdev[v_len] = 0; 757 758 outputdev = inputdev + v_len + 1; 759 v_len = do_bsys_getproplen(NULL, "output-device"); 760 if (v_len > 0) 761 (void) do_bsys_getprop(NULL, "output-device", 762 outputdev); 763 else 764 v_len = 0; 765 outputdev[v_len] = 0; 766 767 consoledev = outputdev + v_len + 1; 768 v_len = do_bsys_getproplen(NULL, "console"); 769 if (v_len > 0) { 770 (void) do_bsys_getprop(NULL, "console", consoledev); 771 if (post_fastreboot && 772 strcmp(consoledev, "graphics") == 0) { 773 bsetprops("console", "text"); 774 v_len = strlen("text"); 775 bcopy("text", consoledev, v_len); 776 } 777 } else { 778 v_len = 0; 779 } 780 consoledev[v_len] = 0; 781 bcons_init2(inputdev, outputdev, consoledev); 782 } else { 783 /* 784 * Ensure console property exists 785 * If not create it as "hypervisor" 786 */ 787 v_len = do_bsys_getproplen(NULL, "console"); 788 if (v_len < 0) 789 bsetprops("console", "hypervisor"); 790 inputdev = outputdev = consoledev = "hypervisor"; 791 bcons_init2(inputdev, outputdev, consoledev); 792 } 793 794 if (find_boot_prop("prom_debug") || kbm_debug) 795 boot_prop_display(line); 796 } 797 798 /* 799 * print formatted output 800 */ 801 /*PRINTFLIKE2*/ 802 /*ARGSUSED*/ 803 void 804 bop_printf(bootops_t *bop, const char *fmt, ...) 805 { 806 va_list ap; 807 808 if (have_console == 0) 809 return; 810 811 va_start(ap, fmt); 812 (void) vsnprintf(buffer, BUFFERSIZE, fmt, ap); 813 va_end(ap); 814 PUT_STRING(buffer); 815 } 816 817 /* 818 * Another panic() variant; this one can be used even earlier during boot than 819 * prom_panic(). 820 */ 821 /*PRINTFLIKE1*/ 822 void 823 bop_panic(const char *fmt, ...) 824 { 825 va_list ap; 826 827 va_start(ap, fmt); 828 bop_printf(NULL, fmt, ap); 829 va_end(ap); 830 831 bop_printf(NULL, "\nPress any key to reboot.\n"); 832 (void) bcons_getchar(); 833 bop_printf(NULL, "Resetting...\n"); 834 pc_reset(); 835 } 836 837 /* 838 * Do a real mode interrupt BIOS call 839 */ 840 typedef struct bios_regs { 841 unsigned short ax, bx, cx, dx, si, di, bp, es, ds; 842 } bios_regs_t; 843 typedef int (*bios_func_t)(int, bios_regs_t *); 844 845 /*ARGSUSED*/ 846 static void 847 do_bsys_doint(bootops_t *bop, int intnum, struct bop_regs *rp) 848 { 849 #if defined(__xpv) 850 prom_panic("unsupported call to BOP_DOINT()\n"); 851 #else /* __xpv */ 852 static int firsttime = 1; 853 bios_func_t bios_func = (bios_func_t)(void *)(uintptr_t)0x5000; 854 bios_regs_t br; 855 856 /* 857 * We're about to disable paging; we shouldn't be PCID enabled. 858 */ 859 if (getcr4() & CR4_PCIDE) 860 prom_panic("do_bsys_doint() with PCID enabled\n"); 861 862 /* 863 * The first time we do this, we have to copy the pre-packaged 864 * low memory bios call code image into place. 865 */ 866 if (firsttime) { 867 extern char bios_image[]; 868 extern uint32_t bios_size; 869 870 bcopy(bios_image, (void *)bios_func, bios_size); 871 firsttime = 0; 872 } 873 874 br.ax = rp->eax.word.ax; 875 br.bx = rp->ebx.word.bx; 876 br.cx = rp->ecx.word.cx; 877 br.dx = rp->edx.word.dx; 878 br.bp = rp->ebp.word.bp; 879 br.si = rp->esi.word.si; 880 br.di = rp->edi.word.di; 881 br.ds = rp->ds; 882 br.es = rp->es; 883 884 DBG_MSG("Doing BIOS call..."); 885 DBG(br.ax); 886 DBG(br.bx); 887 DBG(br.dx); 888 rp->eflags = bios_func(intnum, &br); 889 DBG_MSG("done\n"); 890 891 rp->eax.word.ax = br.ax; 892 rp->ebx.word.bx = br.bx; 893 rp->ecx.word.cx = br.cx; 894 rp->edx.word.dx = br.dx; 895 rp->ebp.word.bp = br.bp; 896 rp->esi.word.si = br.si; 897 rp->edi.word.di = br.di; 898 rp->ds = br.ds; 899 rp->es = br.es; 900 #endif /* __xpv */ 901 } 902 903 static struct boot_syscalls bop_sysp = { 904 bcons_getchar, 905 bcons_putchar, 906 bcons_ischar, 907 }; 908 909 static char *whoami; 910 911 #define BUFLEN 64 912 913 #if defined(__xpv) 914 915 static char namebuf[32]; 916 917 static void 918 xen_parse_props(char *s, char *prop_map[], int n_prop) 919 { 920 char **prop_name = prop_map; 921 char *cp = s, *scp; 922 923 do { 924 scp = cp; 925 while ((*cp != NULL) && (*cp != ':')) 926 cp++; 927 928 if ((scp != cp) && (*prop_name != NULL)) { 929 *cp = NULL; 930 bsetprops(*prop_name, scp); 931 } 932 933 cp++; 934 prop_name++; 935 n_prop--; 936 } while (n_prop > 0); 937 } 938 939 #define VBDPATHLEN 64 940 941 /* 942 * parse the 'xpv-root' property to create properties used by 943 * ufs_mountroot. 944 */ 945 static void 946 xen_vbdroot_props(char *s) 947 { 948 char vbdpath[VBDPATHLEN] = "/xpvd/xdf@"; 949 const char lnamefix[] = "/dev/dsk/c0d"; 950 char *pnp; 951 char *prop_p; 952 char mi; 953 short minor; 954 long addr = 0; 955 956 pnp = vbdpath + strlen(vbdpath); 957 prop_p = s + strlen(lnamefix); 958 while ((*prop_p != '\0') && (*prop_p != 's') && (*prop_p != 'p')) 959 addr = addr * 10 + *prop_p++ - '0'; 960 (void) snprintf(pnp, VBDPATHLEN, "%lx", addr); 961 pnp = vbdpath + strlen(vbdpath); 962 if (*prop_p == 's') 963 mi = 'a'; 964 else if (*prop_p == 'p') 965 mi = 'q'; 966 else 967 ASSERT(0); /* shouldn't be here */ 968 prop_p++; 969 ASSERT(*prop_p != '\0'); 970 if (ISDIGIT(*prop_p)) { 971 minor = *prop_p - '0'; 972 prop_p++; 973 if (ISDIGIT(*prop_p)) { 974 minor = minor * 10 + *prop_p - '0'; 975 } 976 } else { 977 /* malformed root path, use 0 as default */ 978 minor = 0; 979 } 980 ASSERT(minor < 16); /* at most 16 partitions */ 981 mi += minor; 982 *pnp++ = ':'; 983 *pnp++ = mi; 984 *pnp++ = '\0'; 985 bsetprops("fstype", "ufs"); 986 bsetprops("bootpath", vbdpath); 987 988 DBG_MSG("VBD bootpath set to "); 989 DBG_MSG(vbdpath); 990 DBG_MSG("\n"); 991 } 992 993 /* 994 * parse the xpv-nfsroot property to create properties used by 995 * nfs_mountroot. 996 */ 997 static void 998 xen_nfsroot_props(char *s) 999 { 1000 char *prop_map[] = { 1001 BP_SERVER_IP, /* server IP address */ 1002 BP_SERVER_NAME, /* server hostname */ 1003 BP_SERVER_PATH, /* root path */ 1004 }; 1005 int n_prop = sizeof (prop_map) / sizeof (prop_map[0]); 1006 1007 bsetprop("fstype", 6, "nfs", 4); 1008 1009 xen_parse_props(s, prop_map, n_prop); 1010 1011 /* 1012 * If a server name wasn't specified, use a default. 1013 */ 1014 if (do_bsys_getproplen(NULL, BP_SERVER_NAME) == -1) 1015 bsetprops(BP_SERVER_NAME, "unknown"); 1016 } 1017 1018 /* 1019 * Extract our IP address, etc. from the "xpv-ip" property. 1020 */ 1021 static void 1022 xen_ip_props(char *s) 1023 { 1024 char *prop_map[] = { 1025 BP_HOST_IP, /* IP address */ 1026 NULL, /* NFS server IP address (ignored in */ 1027 /* favour of xpv-nfsroot) */ 1028 BP_ROUTER_IP, /* IP gateway */ 1029 BP_SUBNET_MASK, /* IP subnet mask */ 1030 "xpv-hostname", /* hostname (ignored) */ 1031 BP_NETWORK_INTERFACE, /* interface name */ 1032 "xpv-hcp", /* host configuration protocol */ 1033 }; 1034 int n_prop = sizeof (prop_map) / sizeof (prop_map[0]); 1035 char ifname[IFNAMSIZ]; 1036 1037 xen_parse_props(s, prop_map, n_prop); 1038 1039 /* 1040 * A Linux dom0 administrator expects all interfaces to be 1041 * called "ethX", which is not the case here. 1042 * 1043 * If the interface name specified is "eth0", presume that 1044 * this is really intended to be "xnf0" (the first domU -> 1045 * dom0 interface for this domain). 1046 */ 1047 if ((do_bsys_getprop(NULL, BP_NETWORK_INTERFACE, ifname) == 0) && 1048 (strcmp("eth0", ifname) == 0)) { 1049 bsetprops(BP_NETWORK_INTERFACE, "xnf0"); 1050 bop_printf(NULL, 1051 "network interface name 'eth0' replaced with 'xnf0'\n"); 1052 } 1053 } 1054 1055 #else /* __xpv */ 1056 1057 static void 1058 setup_rarp_props(struct sol_netinfo *sip) 1059 { 1060 char buf[BUFLEN]; /* to hold ip/mac addrs */ 1061 uint8_t *val; 1062 1063 val = (uint8_t *)&sip->sn_ciaddr; 1064 (void) snprintf(buf, BUFLEN, "%d.%d.%d.%d", 1065 val[0], val[1], val[2], val[3]); 1066 bsetprops(BP_HOST_IP, buf); 1067 1068 val = (uint8_t *)&sip->sn_siaddr; 1069 (void) snprintf(buf, BUFLEN, "%d.%d.%d.%d", 1070 val[0], val[1], val[2], val[3]); 1071 bsetprops(BP_SERVER_IP, buf); 1072 1073 if (sip->sn_giaddr != 0) { 1074 val = (uint8_t *)&sip->sn_giaddr; 1075 (void) snprintf(buf, BUFLEN, "%d.%d.%d.%d", 1076 val[0], val[1], val[2], val[3]); 1077 bsetprops(BP_ROUTER_IP, buf); 1078 } 1079 1080 if (sip->sn_netmask != 0) { 1081 val = (uint8_t *)&sip->sn_netmask; 1082 (void) snprintf(buf, BUFLEN, "%d.%d.%d.%d", 1083 val[0], val[1], val[2], val[3]); 1084 bsetprops(BP_SUBNET_MASK, buf); 1085 } 1086 1087 if (sip->sn_mactype != 4 || sip->sn_maclen != 6) { 1088 bop_printf(NULL, "unsupported mac type %d, mac len %d\n", 1089 sip->sn_mactype, sip->sn_maclen); 1090 } else { 1091 val = sip->sn_macaddr; 1092 (void) snprintf(buf, BUFLEN, "%x:%x:%x:%x:%x:%x", 1093 val[0], val[1], val[2], val[3], val[4], val[5]); 1094 bsetprops(BP_BOOT_MAC, buf); 1095 } 1096 } 1097 1098 #endif /* __xpv */ 1099 1100 static void 1101 build_panic_cmdline(const char *cmd, int cmdlen) 1102 { 1103 int proplen; 1104 size_t arglen; 1105 1106 arglen = sizeof (fastreboot_onpanic_args); 1107 /* 1108 * If we allready have fastreboot-onpanic set to zero, 1109 * don't add them again. 1110 */ 1111 if ((proplen = do_bsys_getproplen(NULL, FASTREBOOT_ONPANIC)) > 0 && 1112 proplen <= sizeof (fastreboot_onpanic_cmdline)) { 1113 (void) do_bsys_getprop(NULL, FASTREBOOT_ONPANIC, 1114 fastreboot_onpanic_cmdline); 1115 if (FASTREBOOT_ONPANIC_NOTSET(fastreboot_onpanic_cmdline)) 1116 arglen = 1; 1117 } 1118 1119 /* 1120 * construct fastreboot_onpanic_cmdline 1121 */ 1122 if (cmdlen + arglen > sizeof (fastreboot_onpanic_cmdline)) { 1123 DBG_MSG("Command line too long: clearing " 1124 FASTREBOOT_ONPANIC "\n"); 1125 fastreboot_onpanic = 0; 1126 } else { 1127 bcopy(cmd, fastreboot_onpanic_cmdline, cmdlen); 1128 if (arglen != 1) 1129 bcopy(fastreboot_onpanic_args, 1130 fastreboot_onpanic_cmdline + cmdlen, arglen); 1131 else 1132 fastreboot_onpanic_cmdline[cmdlen] = 0; 1133 } 1134 } 1135 1136 1137 #ifndef __xpv 1138 /* 1139 * Construct boot command line for Fast Reboot. The saved_cmdline 1140 * is also reported by "eeprom bootcmd". 1141 */ 1142 static void 1143 build_fastboot_cmdline(struct xboot_info *xbp) 1144 { 1145 saved_cmdline_len = strlen(xbp->bi_cmdline) + 1; 1146 if (saved_cmdline_len > FASTBOOT_SAVED_CMDLINE_LEN) { 1147 DBG(saved_cmdline_len); 1148 DBG_MSG("Command line too long: clearing fastreboot_capable\n"); 1149 fastreboot_capable = 0; 1150 } else { 1151 bcopy((void *)(xbp->bi_cmdline), (void *)saved_cmdline, 1152 saved_cmdline_len); 1153 saved_cmdline[saved_cmdline_len - 1] = '\0'; 1154 build_panic_cmdline(saved_cmdline, saved_cmdline_len - 1); 1155 } 1156 } 1157 1158 /* 1159 * Save memory layout, disk drive information, unix and boot archive sizes for 1160 * Fast Reboot. 1161 */ 1162 static void 1163 save_boot_info(struct xboot_info *xbi) 1164 { 1165 multiboot_info_t *mbi = xbi->bi_mb_info; 1166 struct boot_modules *modp; 1167 int i; 1168 1169 bcopy(mbi, &saved_mbi, sizeof (multiboot_info_t)); 1170 if (mbi->mmap_length > sizeof (saved_mmap)) { 1171 DBG_MSG("mbi->mmap_length too big: clearing " 1172 "fastreboot_capable\n"); 1173 fastreboot_capable = 0; 1174 } else { 1175 bcopy((void *)(uintptr_t)mbi->mmap_addr, (void *)saved_mmap, 1176 mbi->mmap_length); 1177 } 1178 1179 if ((mbi->flags & MB_INFO_DRIVE_INFO) != 0) { 1180 if (mbi->drives_length > sizeof (saved_drives)) { 1181 DBG(mbi->drives_length); 1182 DBG_MSG("mbi->drives_length too big: clearing " 1183 "fastreboot_capable\n"); 1184 fastreboot_capable = 0; 1185 } else { 1186 bcopy((void *)(uintptr_t)mbi->drives_addr, 1187 (void *)saved_drives, mbi->drives_length); 1188 } 1189 } else { 1190 saved_mbi.drives_length = 0; 1191 saved_mbi.drives_addr = NULL; 1192 } 1193 1194 /* 1195 * Current file sizes. Used by fastboot.c to figure out how much 1196 * memory to reserve for panic reboot. 1197 * Use the module list from the dboot-constructed xboot_info 1198 * instead of the list referenced by the multiboot structure 1199 * because that structure may not be addressable now. 1200 */ 1201 saved_file_size[FASTBOOT_NAME_UNIX] = FOUR_MEG - PAGESIZE; 1202 for (i = 0, modp = (struct boot_modules *)(uintptr_t)xbi->bi_modules; 1203 i < xbi->bi_module_cnt; i++, modp++) { 1204 saved_file_size[FASTBOOT_NAME_BOOTARCHIVE] += modp->bm_size; 1205 } 1206 } 1207 #endif /* __xpv */ 1208 1209 /* 1210 * Import boot environment module variables as properties, applying 1211 * blacklist filter for variables we know we will not use. 1212 * 1213 * Since the environment can be relatively large, containing many variables 1214 * used only for boot loader purposes, we will use a blacklist based filter. 1215 * To keep the blacklist from growing too large, we use prefix based filtering. 1216 * This is possible because in many cases, the loader variable names are 1217 * using a structured layout. 1218 * 1219 * We will not overwrite already set properties. 1220 */ 1221 static struct bop_blacklist { 1222 const char *bl_name; 1223 int bl_name_len; 1224 } bop_prop_blacklist[] = { 1225 { "ISADIR", sizeof ("ISADIR") }, 1226 { "acpi", sizeof ("acpi") }, 1227 { "autoboot_delay", sizeof ("autoboot_delay") }, 1228 { "autoboot_delay", sizeof ("autoboot_delay") }, 1229 { "beansi_", sizeof ("beansi_") }, 1230 { "beastie", sizeof ("beastie") }, 1231 { "bemenu", sizeof ("bemenu") }, 1232 { "boot.", sizeof ("boot.") }, 1233 { "bootenv", sizeof ("bootenv") }, 1234 { "currdev", sizeof ("currdev") }, 1235 { "dhcp.", sizeof ("dhcp.") }, 1236 { "interpret", sizeof ("interpret") }, 1237 { "kernel", sizeof ("kernel") }, 1238 { "loaddev", sizeof ("loaddev") }, 1239 { "loader_", sizeof ("loader_") }, 1240 { "module_path", sizeof ("module_path") }, 1241 { "nfs.", sizeof ("nfs.") }, 1242 { "pcibios", sizeof ("pcibios") }, 1243 { "prompt", sizeof ("prompt") }, 1244 { "smbios", sizeof ("smbios") }, 1245 { "tem", sizeof ("tem") }, 1246 { "twiddle_divisor", sizeof ("twiddle_divisor") }, 1247 { "zfs_be", sizeof ("zfs_be") }, 1248 }; 1249 1250 /* 1251 * Match the name against prefixes in above blacklist. If the match was 1252 * found, this name is blacklisted. 1253 */ 1254 static boolean_t 1255 name_is_blacklisted(const char *name) 1256 { 1257 int i, n; 1258 1259 n = sizeof (bop_prop_blacklist) / sizeof (bop_prop_blacklist[0]); 1260 for (i = 0; i < n; i++) { 1261 if (strncmp(bop_prop_blacklist[i].bl_name, name, 1262 bop_prop_blacklist[i].bl_name_len - 1) == 0) { 1263 return (B_TRUE); 1264 } 1265 } 1266 return (B_FALSE); 1267 } 1268 1269 static void 1270 process_boot_environment(struct boot_modules *benv) 1271 { 1272 char *env, *ptr, *name, *value; 1273 uint32_t size, name_len, value_len; 1274 1275 if (benv == NULL || benv->bm_type != BMT_ENV) 1276 return; 1277 ptr = env = benv->bm_addr; 1278 size = benv->bm_size; 1279 do { 1280 name = ptr; 1281 /* find '=' */ 1282 while (*ptr != '=') { 1283 ptr++; 1284 if (ptr > env + size) /* Something is very wrong. */ 1285 return; 1286 } 1287 name_len = ptr - name; 1288 if (sizeof (buffer) <= name_len) 1289 continue; 1290 1291 (void) strncpy(buffer, name, sizeof (buffer)); 1292 buffer[name_len] = '\0'; 1293 name = buffer; 1294 1295 value_len = 0; 1296 value = ++ptr; 1297 while ((uintptr_t)ptr - (uintptr_t)env < size) { 1298 if (*ptr == '\0') { 1299 ptr++; 1300 value_len = (uintptr_t)ptr - (uintptr_t)env; 1301 break; 1302 } 1303 ptr++; 1304 } 1305 1306 /* Did we reach the end of the module? */ 1307 if (value_len == 0) 1308 return; 1309 1310 if (*value == '\0') 1311 continue; 1312 1313 /* Is this property already set? */ 1314 if (do_bsys_getproplen(NULL, name) >= 0) 1315 continue; 1316 1317 if (name_is_blacklisted(name) == B_TRUE) 1318 continue; 1319 1320 /* Create new property. */ 1321 bsetprops(name, value); 1322 1323 /* Avoid reading past the module end. */ 1324 if (size <= (uintptr_t)ptr - (uintptr_t)env) 1325 return; 1326 } while (*ptr != '\0'); 1327 } 1328 1329 /* 1330 * 1st pass at building the table of boot properties. This includes: 1331 * - values set on the command line: -B a=x,b=y,c=z .... 1332 * - known values we just compute (ie. from xbp) 1333 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values) 1334 * 1335 * the grub command line looked like: 1336 * kernel boot-file [-B prop=value[,prop=value]...] [boot-args] 1337 * 1338 * whoami is the same as boot-file 1339 */ 1340 static void 1341 build_boot_properties(struct xboot_info *xbp) 1342 { 1343 char *name; 1344 int name_len; 1345 char *value; 1346 int value_len; 1347 struct boot_modules *bm, *rdbm, *benv = NULL; 1348 char *propbuf; 1349 int quoted = 0; 1350 int boot_arg_len; 1351 uint_t i, midx; 1352 char modid[32]; 1353 #ifndef __xpv 1354 static int stdout_val = 0; 1355 uchar_t boot_device; 1356 char str[3]; 1357 #endif 1358 1359 /* 1360 * These have to be done first, so that kobj_mount_root() works 1361 */ 1362 DBG_MSG("Building boot properties\n"); 1363 propbuf = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, 0); 1364 DBG((uintptr_t)propbuf); 1365 if (xbp->bi_module_cnt > 0) { 1366 bm = xbp->bi_modules; 1367 rdbm = NULL; 1368 for (midx = i = 0; i < xbp->bi_module_cnt; i++) { 1369 if (bm[i].bm_type == BMT_ROOTFS) { 1370 rdbm = &bm[i]; 1371 continue; 1372 } 1373 if (bm[i].bm_type == BMT_HASH || bm[i].bm_name == NULL) 1374 continue; 1375 1376 if (bm[i].bm_type == BMT_ENV) { 1377 if (benv == NULL) 1378 benv = &bm[i]; 1379 else 1380 continue; 1381 } 1382 1383 (void) snprintf(modid, sizeof (modid), 1384 "module-name-%u", midx); 1385 bsetprops(modid, (char *)bm[i].bm_name); 1386 (void) snprintf(modid, sizeof (modid), 1387 "module-addr-%u", midx); 1388 bsetprop64(modid, (uint64_t)(uintptr_t)bm[i].bm_addr); 1389 (void) snprintf(modid, sizeof (modid), 1390 "module-size-%u", midx); 1391 bsetprop64(modid, (uint64_t)bm[i].bm_size); 1392 ++midx; 1393 } 1394 if (rdbm != NULL) { 1395 bsetprop64("ramdisk_start", 1396 (uint64_t)(uintptr_t)rdbm->bm_addr); 1397 bsetprop64("ramdisk_end", 1398 (uint64_t)(uintptr_t)rdbm->bm_addr + rdbm->bm_size); 1399 } 1400 } 1401 1402 /* 1403 * If there are any boot time modules or hashes present, then disable 1404 * fast reboot. 1405 */ 1406 if (xbp->bi_module_cnt > 1) { 1407 fastreboot_disable(FBNS_BOOTMOD); 1408 } 1409 1410 #ifndef __xpv 1411 /* 1412 * Disable fast reboot if we're using the Multiboot 2 boot protocol, 1413 * since we don't currently support MB2 info and module relocation. 1414 * Note that fast reboot will have already been disabled if multiple 1415 * modules are present, since the current implementation assumes that 1416 * we only have a single module, the boot_archive. 1417 */ 1418 if (xbp->bi_mb_version != 1) { 1419 fastreboot_disable(FBNS_MULTIBOOT2); 1420 } 1421 #endif 1422 1423 DBG_MSG("Parsing command line for boot properties\n"); 1424 value = xbp->bi_cmdline; 1425 1426 /* 1427 * allocate memory to collect boot_args into 1428 */ 1429 boot_arg_len = strlen(xbp->bi_cmdline) + 1; 1430 boot_args = do_bsys_alloc(NULL, NULL, boot_arg_len, MMU_PAGESIZE); 1431 boot_args[0] = 0; 1432 boot_arg_len = 0; 1433 1434 #ifdef __xpv 1435 /* 1436 * Xen puts a lot of device information in front of the kernel name 1437 * let's grab them and make them boot properties. The first 1438 * string w/o an "=" in it will be the boot-file property. 1439 */ 1440 (void) strcpy(namebuf, "xpv-"); 1441 for (;;) { 1442 /* 1443 * get to next property 1444 */ 1445 while (ISSPACE(*value)) 1446 ++value; 1447 name = value; 1448 /* 1449 * look for an "=" 1450 */ 1451 while (*value && !ISSPACE(*value) && *value != '=') { 1452 value++; 1453 } 1454 if (*value != '=') { /* no "=" in the property */ 1455 value = name; 1456 break; 1457 } 1458 name_len = value - name; 1459 value_len = 0; 1460 /* 1461 * skip over the "=" 1462 */ 1463 value++; 1464 while (value[value_len] && !ISSPACE(value[value_len])) { 1465 ++value_len; 1466 } 1467 /* 1468 * build property name with "xpv-" prefix 1469 */ 1470 if (name_len + 4 > 32) { /* skip if name too long */ 1471 value += value_len; 1472 continue; 1473 } 1474 bcopy(name, &namebuf[4], name_len); 1475 name_len += 4; 1476 namebuf[name_len] = 0; 1477 bcopy(value, propbuf, value_len); 1478 propbuf[value_len] = 0; 1479 bsetprops(namebuf, propbuf); 1480 1481 /* 1482 * xpv-root is set to the logical disk name of the xen 1483 * VBD when booting from a disk-based filesystem. 1484 */ 1485 if (strcmp(namebuf, "xpv-root") == 0) 1486 xen_vbdroot_props(propbuf); 1487 /* 1488 * While we're here, if we have a "xpv-nfsroot" property 1489 * then we need to set "fstype" to "nfs" so we mount 1490 * our root from the nfs server. Also parse the xpv-nfsroot 1491 * property to create the properties that nfs_mountroot will 1492 * need to find the root and mount it. 1493 */ 1494 if (strcmp(namebuf, "xpv-nfsroot") == 0) 1495 xen_nfsroot_props(propbuf); 1496 1497 if (strcmp(namebuf, "xpv-ip") == 0) 1498 xen_ip_props(propbuf); 1499 value += value_len; 1500 } 1501 #endif 1502 1503 while (ISSPACE(*value)) 1504 ++value; 1505 /* 1506 * value now points at the boot-file 1507 */ 1508 value_len = 0; 1509 while (value[value_len] && !ISSPACE(value[value_len])) 1510 ++value_len; 1511 if (value_len > 0) { 1512 whoami = propbuf; 1513 bcopy(value, whoami, value_len); 1514 whoami[value_len] = 0; 1515 bsetprops("boot-file", whoami); 1516 /* 1517 * strip leading path stuff from whoami, so running from 1518 * PXE/miniroot makes sense. 1519 */ 1520 if (strstr(whoami, "/platform/") != NULL) 1521 whoami = strstr(whoami, "/platform/"); 1522 bsetprops("whoami", whoami); 1523 } 1524 1525 /* 1526 * Values forcibly set boot properties on the command line via -B. 1527 * Allow use of quotes in values. Other stuff goes on kernel 1528 * command line. 1529 */ 1530 name = value + value_len; 1531 while (*name != 0) { 1532 /* 1533 * anything not " -B" is copied to the command line 1534 */ 1535 if (!ISSPACE(name[0]) || name[1] != '-' || name[2] != 'B') { 1536 boot_args[boot_arg_len++] = *name; 1537 boot_args[boot_arg_len] = 0; 1538 ++name; 1539 continue; 1540 } 1541 1542 /* 1543 * skip the " -B" and following white space 1544 */ 1545 name += 3; 1546 while (ISSPACE(*name)) 1547 ++name; 1548 while (*name && !ISSPACE(*name)) { 1549 value = strstr(name, "="); 1550 if (value == NULL) 1551 break; 1552 name_len = value - name; 1553 ++value; 1554 value_len = 0; 1555 quoted = 0; 1556 for (; ; ++value_len) { 1557 if (!value[value_len]) 1558 break; 1559 1560 /* 1561 * is this value quoted? 1562 */ 1563 if (value_len == 0 && 1564 (value[0] == '\'' || value[0] == '"')) { 1565 quoted = value[0]; 1566 ++value_len; 1567 } 1568 1569 /* 1570 * In the quote accept any character, 1571 * but look for ending quote. 1572 */ 1573 if (quoted) { 1574 if (value[value_len] == quoted) 1575 quoted = 0; 1576 continue; 1577 } 1578 1579 /* 1580 * a comma or white space ends the value 1581 */ 1582 if (value[value_len] == ',' || 1583 ISSPACE(value[value_len])) 1584 break; 1585 } 1586 1587 if (value_len == 0) { 1588 bsetprop(name, name_len, "true", 5); 1589 } else { 1590 char *v = value; 1591 int l = value_len; 1592 if (v[0] == v[l - 1] && 1593 (v[0] == '\'' || v[0] == '"')) { 1594 ++v; 1595 l -= 2; 1596 } 1597 bcopy(v, propbuf, l); 1598 propbuf[l] = '\0'; 1599 bsetprop(name, name_len, propbuf, 1600 l + 1); 1601 } 1602 name = value + value_len; 1603 while (*name == ',') 1604 ++name; 1605 } 1606 } 1607 1608 /* 1609 * set boot-args property 1610 * 1275 name is bootargs, so set 1611 * that too 1612 */ 1613 bsetprops("boot-args", boot_args); 1614 bsetprops("bootargs", boot_args); 1615 1616 process_boot_environment(benv); 1617 1618 #ifndef __xpv 1619 /* 1620 * Build boot command line for Fast Reboot 1621 */ 1622 build_fastboot_cmdline(xbp); 1623 1624 if (xbp->bi_mb_version == 1) { 1625 multiboot_info_t *mbi = xbp->bi_mb_info; 1626 int netboot; 1627 struct sol_netinfo *sip; 1628 1629 /* 1630 * set the BIOS boot device from GRUB 1631 */ 1632 netboot = 0; 1633 1634 /* 1635 * Save various boot information for Fast Reboot 1636 */ 1637 save_boot_info(xbp); 1638 1639 if (mbi != NULL && mbi->flags & MB_INFO_BOOTDEV) { 1640 boot_device = mbi->boot_device >> 24; 1641 if (boot_device == 0x20) 1642 netboot++; 1643 str[0] = (boot_device >> 4) + '0'; 1644 str[1] = (boot_device & 0xf) + '0'; 1645 str[2] = 0; 1646 bsetprops("bios-boot-device", str); 1647 } else { 1648 netboot = 1; 1649 } 1650 1651 /* 1652 * In the netboot case, drives_info is overloaded with the 1653 * dhcp ack. This is not multiboot compliant and requires 1654 * special pxegrub! 1655 */ 1656 if (netboot && mbi->drives_length != 0) { 1657 sip = (struct sol_netinfo *)(uintptr_t)mbi->drives_addr; 1658 if (sip->sn_infotype == SN_TYPE_BOOTP) 1659 bsetprop("bootp-response", 1660 sizeof ("bootp-response"), 1661 (void *)(uintptr_t)mbi->drives_addr, 1662 mbi->drives_length); 1663 else if (sip->sn_infotype == SN_TYPE_RARP) 1664 setup_rarp_props(sip); 1665 } 1666 } else { 1667 multiboot2_info_header_t *mbi = xbp->bi_mb_info; 1668 multiboot_tag_bootdev_t *bootdev = NULL; 1669 multiboot_tag_network_t *netdev = NULL; 1670 1671 if (mbi != NULL) { 1672 bootdev = dboot_multiboot2_find_tag(mbi, 1673 MULTIBOOT_TAG_TYPE_BOOTDEV); 1674 netdev = dboot_multiboot2_find_tag(mbi, 1675 MULTIBOOT_TAG_TYPE_NETWORK); 1676 } 1677 if (bootdev != NULL) { 1678 DBG(bootdev->mb_biosdev); 1679 boot_device = bootdev->mb_biosdev; 1680 str[0] = (boot_device >> 4) + '0'; 1681 str[1] = (boot_device & 0xf) + '0'; 1682 str[2] = 0; 1683 bsetprops("bios-boot-device", str); 1684 } 1685 if (netdev != NULL) { 1686 bsetprop("bootp-response", sizeof ("bootp-response"), 1687 (void *)(uintptr_t)netdev->mb_dhcpack, 1688 netdev->mb_size - 1689 sizeof (multiboot_tag_network_t)); 1690 } 1691 } 1692 1693 bsetprop("stdout", strlen("stdout"), 1694 &stdout_val, sizeof (stdout_val)); 1695 #endif /* __xpv */ 1696 1697 /* 1698 * more conjured up values for made up things.... 1699 */ 1700 #if defined(__xpv) 1701 bsetprops("mfg-name", "i86xpv"); 1702 bsetprops("impl-arch-name", "i86xpv"); 1703 #else 1704 bsetprops("mfg-name", "i86pc"); 1705 bsetprops("impl-arch-name", "i86pc"); 1706 #endif 1707 1708 /* 1709 * Build firmware-provided system properties 1710 */ 1711 build_firmware_properties(xbp); 1712 1713 /* 1714 * XXPV 1715 * 1716 * Find out what these are: 1717 * - cpuid_feature_ecx_include 1718 * - cpuid_feature_ecx_exclude 1719 * - cpuid_feature_edx_include 1720 * - cpuid_feature_edx_exclude 1721 * 1722 * Find out what these are in multiboot: 1723 * - netdev-path 1724 * - fstype 1725 */ 1726 } 1727 1728 #ifdef __xpv 1729 /* 1730 * Under the Hypervisor, memory usable for DMA may be scarce. One 1731 * very likely large pool of DMA friendly memory is occupied by 1732 * the boot_archive, as it was loaded by grub into low MFNs. 1733 * 1734 * Here we free up that memory by copying the boot archive to what are 1735 * likely higher MFN pages and then swapping the mfn/pfn mappings. 1736 */ 1737 #define PFN_2GIG 0x80000 1738 static void 1739 relocate_boot_archive(struct xboot_info *xbp) 1740 { 1741 mfn_t max_mfn = HYPERVISOR_memory_op(XENMEM_maximum_ram_page, NULL); 1742 struct boot_modules *bm = xbp->bi_modules; 1743 uintptr_t va; 1744 pfn_t va_pfn; 1745 mfn_t va_mfn; 1746 caddr_t copy; 1747 pfn_t copy_pfn; 1748 mfn_t copy_mfn; 1749 size_t len; 1750 int slop; 1751 int total = 0; 1752 int relocated = 0; 1753 int mmu_update_return; 1754 mmu_update_t t[2]; 1755 x86pte_t pte; 1756 1757 /* 1758 * If all MFN's are below 2Gig, don't bother doing this. 1759 */ 1760 if (max_mfn < PFN_2GIG) 1761 return; 1762 if (xbp->bi_module_cnt < 1) { 1763 DBG_MSG("no boot_archive!"); 1764 return; 1765 } 1766 1767 DBG_MSG("moving boot_archive to high MFN memory\n"); 1768 va = (uintptr_t)bm->bm_addr; 1769 len = bm->bm_size; 1770 slop = va & MMU_PAGEOFFSET; 1771 if (slop) { 1772 va += MMU_PAGESIZE - slop; 1773 len -= MMU_PAGESIZE - slop; 1774 } 1775 len = P2ALIGN(len, MMU_PAGESIZE); 1776 1777 /* 1778 * Go through all boot_archive pages, swapping any low MFN pages 1779 * with memory at next_phys. 1780 */ 1781 while (len != 0) { 1782 ++total; 1783 va_pfn = mmu_btop(va - ONE_GIG); 1784 va_mfn = mfn_list[va_pfn]; 1785 if (mfn_list[va_pfn] < PFN_2GIG) { 1786 copy = kbm_remap_window(next_phys, 1); 1787 bcopy((void *)va, copy, MMU_PAGESIZE); 1788 copy_pfn = mmu_btop(next_phys); 1789 copy_mfn = mfn_list[copy_pfn]; 1790 1791 pte = mfn_to_ma(copy_mfn) | PT_NOCONSIST | PT_VALID; 1792 if (HYPERVISOR_update_va_mapping(va, pte, 1793 UVMF_INVLPG | UVMF_LOCAL)) 1794 bop_panic("relocate_boot_archive(): " 1795 "HYPERVISOR_update_va_mapping() failed"); 1796 1797 mfn_list[va_pfn] = copy_mfn; 1798 mfn_list[copy_pfn] = va_mfn; 1799 1800 t[0].ptr = mfn_to_ma(copy_mfn) | MMU_MACHPHYS_UPDATE; 1801 t[0].val = va_pfn; 1802 t[1].ptr = mfn_to_ma(va_mfn) | MMU_MACHPHYS_UPDATE; 1803 t[1].val = copy_pfn; 1804 if (HYPERVISOR_mmu_update(t, 2, &mmu_update_return, 1805 DOMID_SELF) != 0 || mmu_update_return != 2) 1806 bop_panic("relocate_boot_archive(): " 1807 "HYPERVISOR_mmu_update() failed"); 1808 1809 next_phys += MMU_PAGESIZE; 1810 ++relocated; 1811 } 1812 len -= MMU_PAGESIZE; 1813 va += MMU_PAGESIZE; 1814 } 1815 DBG_MSG("Relocated pages:\n"); 1816 DBG(relocated); 1817 DBG_MSG("Out of total pages:\n"); 1818 DBG(total); 1819 } 1820 #endif /* __xpv */ 1821 1822 #if !defined(__xpv) 1823 /* 1824 * simple description of a stack frame (args are 32 bit only currently) 1825 */ 1826 typedef struct bop_frame { 1827 struct bop_frame *old_frame; 1828 pc_t retaddr; 1829 long arg[1]; 1830 } bop_frame_t; 1831 1832 void 1833 bop_traceback(bop_frame_t *frame) 1834 { 1835 pc_t pc; 1836 int cnt; 1837 char *ksym; 1838 ulong_t off; 1839 1840 bop_printf(NULL, "Stack traceback:\n"); 1841 for (cnt = 0; cnt < 30; ++cnt) { /* up to 30 frames */ 1842 pc = frame->retaddr; 1843 if (pc == 0) 1844 break; 1845 ksym = kobj_getsymname(pc, &off); 1846 if (ksym) 1847 bop_printf(NULL, " %s+%lx", ksym, off); 1848 else 1849 bop_printf(NULL, " 0x%lx", pc); 1850 1851 frame = frame->old_frame; 1852 if (frame == 0) { 1853 bop_printf(NULL, "\n"); 1854 break; 1855 } 1856 bop_printf(NULL, "\n"); 1857 } 1858 } 1859 1860 struct trapframe { 1861 ulong_t error_code; /* optional */ 1862 ulong_t inst_ptr; 1863 ulong_t code_seg; 1864 ulong_t flags_reg; 1865 ulong_t stk_ptr; 1866 ulong_t stk_seg; 1867 }; 1868 1869 void 1870 bop_trap(ulong_t *tfp) 1871 { 1872 struct trapframe *tf = (struct trapframe *)tfp; 1873 bop_frame_t fakeframe; 1874 static int depth = 0; 1875 1876 /* 1877 * Check for an infinite loop of traps. 1878 */ 1879 if (++depth > 2) 1880 bop_panic("Nested trap"); 1881 1882 bop_printf(NULL, "Unexpected trap\n"); 1883 1884 /* 1885 * adjust the tf for optional error_code by detecting the code selector 1886 */ 1887 if (tf->code_seg != B64CODE_SEL) 1888 tf = (struct trapframe *)(tfp - 1); 1889 else 1890 bop_printf(NULL, "error code 0x%lx\n", 1891 tf->error_code & 0xffffffff); 1892 1893 bop_printf(NULL, "instruction pointer 0x%lx\n", tf->inst_ptr); 1894 bop_printf(NULL, "code segment 0x%lx\n", tf->code_seg & 0xffff); 1895 bop_printf(NULL, "flags register 0x%lx\n", tf->flags_reg); 1896 bop_printf(NULL, "return %%rsp 0x%lx\n", tf->stk_ptr); 1897 bop_printf(NULL, "return %%ss 0x%lx\n", tf->stk_seg & 0xffff); 1898 1899 /* grab %[er]bp pushed by our code from the stack */ 1900 fakeframe.old_frame = (bop_frame_t *)*(tfp - 3); 1901 fakeframe.retaddr = (pc_t)tf->inst_ptr; 1902 bop_printf(NULL, "Attempting stack backtrace:\n"); 1903 bop_traceback(&fakeframe); 1904 bop_panic("unexpected trap in early boot"); 1905 } 1906 1907 extern void bop_trap_handler(void); 1908 1909 static gate_desc_t *bop_idt; 1910 1911 static desctbr_t bop_idt_info; 1912 1913 /* 1914 * Install a temporary IDT that lets us catch errors in the boot time code. 1915 * We shouldn't get any faults at all while this is installed, so we'll 1916 * just generate a traceback and exit. 1917 */ 1918 static void 1919 bop_idt_init(void) 1920 { 1921 int t; 1922 1923 bop_idt = (gate_desc_t *) 1924 do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, MMU_PAGESIZE); 1925 bzero(bop_idt, MMU_PAGESIZE); 1926 for (t = 0; t < NIDT; ++t) { 1927 /* 1928 * Note that since boot runs without a TSS, the 1929 * double fault handler cannot use an alternate stack (64-bit). 1930 */ 1931 set_gatesegd(&bop_idt[t], &bop_trap_handler, B64CODE_SEL, 1932 SDT_SYSIGT, TRP_KPL, 0); 1933 } 1934 bop_idt_info.dtr_limit = (NIDT * sizeof (gate_desc_t)) - 1; 1935 bop_idt_info.dtr_base = (uintptr_t)bop_idt; 1936 wr_idtr(&bop_idt_info); 1937 } 1938 #endif /* !defined(__xpv) */ 1939 1940 /* 1941 * This is where we enter the kernel. It dummies up the boot_ops and 1942 * boot_syscalls vectors and jumps off to _kobj_boot() 1943 */ 1944 void 1945 _start(struct xboot_info *xbp) 1946 { 1947 bootops_t *bops = &bootop; 1948 extern void _kobj_boot(); 1949 1950 /* 1951 * 1st off - initialize the console for any error messages 1952 */ 1953 xbootp = xbp; 1954 #ifdef __xpv 1955 HYPERVISOR_shared_info = (void *)xbp->bi_shared_info; 1956 xen_info = xbp->bi_xen_start_info; 1957 #endif 1958 1959 #ifndef __xpv 1960 if (*((uint32_t *)(FASTBOOT_SWTCH_PA + FASTBOOT_STACK_OFFSET)) == 1961 FASTBOOT_MAGIC) { 1962 post_fastreboot = 1; 1963 *((uint32_t *)(FASTBOOT_SWTCH_PA + FASTBOOT_STACK_OFFSET)) = 0; 1964 } 1965 #endif 1966 1967 bcons_init(xbp); 1968 have_console = 1; 1969 1970 /* 1971 * enable debugging 1972 */ 1973 if (find_boot_prop("kbm_debug") != NULL) 1974 kbm_debug = 1; 1975 1976 DBG_MSG("\n\n*** Entered Solaris in _start() cmdline is: "); 1977 DBG_MSG((char *)xbp->bi_cmdline); 1978 DBG_MSG("\n\n\n"); 1979 1980 /* 1981 * physavail is no longer used by startup 1982 */ 1983 bm.physinstalled = xbp->bi_phys_install; 1984 bm.pcimem = xbp->bi_pcimem; 1985 bm.rsvdmem = xbp->bi_rsvdmem; 1986 bm.physavail = NULL; 1987 1988 /* 1989 * initialize the boot time allocator 1990 */ 1991 next_phys = xbp->bi_next_paddr; 1992 DBG(next_phys); 1993 next_virt = (uintptr_t)xbp->bi_next_vaddr; 1994 DBG(next_virt); 1995 DBG_MSG("Initializing boot time memory management..."); 1996 #ifdef __xpv 1997 { 1998 xen_platform_parameters_t p; 1999 2000 /* This call shouldn't fail, dboot already did it once. */ 2001 (void) HYPERVISOR_xen_version(XENVER_platform_parameters, &p); 2002 mfn_to_pfn_mapping = (pfn_t *)(xen_virt_start = p.virt_start); 2003 DBG(xen_virt_start); 2004 } 2005 #endif 2006 kbm_init(xbp); 2007 DBG_MSG("done\n"); 2008 2009 /* 2010 * Fill in the bootops vector 2011 */ 2012 bops->bsys_version = BO_VERSION; 2013 bops->boot_mem = &bm; 2014 bops->bsys_alloc = do_bsys_alloc; 2015 bops->bsys_free = do_bsys_free; 2016 bops->bsys_getproplen = do_bsys_getproplen; 2017 bops->bsys_getprop = do_bsys_getprop; 2018 bops->bsys_nextprop = do_bsys_nextprop; 2019 bops->bsys_printf = bop_printf; 2020 bops->bsys_doint = do_bsys_doint; 2021 2022 /* 2023 * BOP_EALLOC() is no longer needed 2024 */ 2025 bops->bsys_ealloc = do_bsys_ealloc; 2026 2027 #ifdef __xpv 2028 /* 2029 * On domain 0 we need to free up some physical memory that is 2030 * usable for DMA. Since GRUB loaded the boot_archive, it is 2031 * sitting in low MFN memory. We'll relocated the boot archive 2032 * pages to high PFN memory. 2033 */ 2034 if (DOMAIN_IS_INITDOMAIN(xen_info)) 2035 relocate_boot_archive(xbp); 2036 #endif 2037 2038 #ifndef __xpv 2039 /* 2040 * Install an IDT to catch early pagefaults (shouldn't have any). 2041 * Also needed for kmdb. 2042 */ 2043 bop_idt_init(); 2044 #endif 2045 2046 /* 2047 * Start building the boot properties from the command line 2048 */ 2049 DBG_MSG("Initializing boot properties:\n"); 2050 build_boot_properties(xbp); 2051 2052 if (find_boot_prop("prom_debug") || kbm_debug) { 2053 char *value; 2054 2055 value = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, MMU_PAGESIZE); 2056 boot_prop_display(value); 2057 } 2058 2059 /* 2060 * jump into krtld... 2061 */ 2062 _kobj_boot(&bop_sysp, NULL, bops, NULL); 2063 } 2064 2065 2066 /*ARGSUSED*/ 2067 static caddr_t 2068 no_more_alloc(bootops_t *bop, caddr_t virthint, size_t size, int align) 2069 { 2070 panic("Attempt to bsys_alloc() too late\n"); 2071 return (NULL); 2072 } 2073 2074 /*ARGSUSED*/ 2075 static void 2076 no_more_free(bootops_t *bop, caddr_t virt, size_t size) 2077 { 2078 panic("Attempt to bsys_free() too late\n"); 2079 } 2080 2081 void 2082 bop_no_more_mem(void) 2083 { 2084 DBG(total_bop_alloc_scratch); 2085 DBG(total_bop_alloc_kernel); 2086 bootops->bsys_alloc = no_more_alloc; 2087 bootops->bsys_free = no_more_free; 2088 } 2089 2090 2091 /* 2092 * Set ACPI firmware properties 2093 */ 2094 2095 static caddr_t 2096 vmap_phys(size_t length, paddr_t pa) 2097 { 2098 paddr_t start, end; 2099 caddr_t va; 2100 size_t len, page; 2101 2102 #ifdef __xpv 2103 pa = pfn_to_pa(xen_assign_pfn(mmu_btop(pa))) | (pa & MMU_PAGEOFFSET); 2104 #endif 2105 start = P2ALIGN(pa, MMU_PAGESIZE); 2106 end = P2ROUNDUP(pa + length, MMU_PAGESIZE); 2107 len = end - start; 2108 va = (caddr_t)alloc_vaddr(len, MMU_PAGESIZE); 2109 for (page = 0; page < len; page += MMU_PAGESIZE) 2110 kbm_map((uintptr_t)va + page, start + page, 0, 0); 2111 return (va + (pa & MMU_PAGEOFFSET)); 2112 } 2113 2114 static uint8_t 2115 checksum_table(uint8_t *tp, size_t len) 2116 { 2117 uint8_t sum = 0; 2118 2119 while (len-- > 0) 2120 sum += *tp++; 2121 2122 return (sum); 2123 } 2124 2125 static int 2126 valid_rsdp(ACPI_TABLE_RSDP *rp) 2127 { 2128 2129 /* validate the V1.x checksum */ 2130 if (checksum_table((uint8_t *)rp, ACPI_RSDP_CHECKSUM_LENGTH) != 0) 2131 return (0); 2132 2133 /* If pre-ACPI 2.0, this is a valid RSDP */ 2134 if (rp->Revision < 2) 2135 return (1); 2136 2137 /* validate the V2.x checksum */ 2138 if (checksum_table((uint8_t *)rp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0) 2139 return (0); 2140 2141 return (1); 2142 } 2143 2144 /* 2145 * Scan memory range for an RSDP; 2146 * see ACPI 3.0 Spec, 5.2.5.1 2147 */ 2148 static ACPI_TABLE_RSDP * 2149 scan_rsdp(paddr_t start, paddr_t end) 2150 { 2151 ssize_t len = end - start; 2152 caddr_t ptr; 2153 2154 ptr = vmap_phys(len, start); 2155 while (len > 0) { 2156 if (strncmp(ptr, ACPI_SIG_RSDP, strlen(ACPI_SIG_RSDP)) == 0 && 2157 valid_rsdp((ACPI_TABLE_RSDP *)ptr)) 2158 return ((ACPI_TABLE_RSDP *)ptr); 2159 2160 ptr += ACPI_RSDP_SCAN_STEP; 2161 len -= ACPI_RSDP_SCAN_STEP; 2162 } 2163 2164 return (NULL); 2165 } 2166 2167 /* 2168 * Refer to ACPI 3.0 Spec, section 5.2.5.1 to understand this function 2169 */ 2170 static ACPI_TABLE_RSDP * 2171 find_rsdp() 2172 { 2173 ACPI_TABLE_RSDP *rsdp; 2174 uint64_t rsdp_val = 0; 2175 uint16_t *ebda_seg; 2176 paddr_t ebda_addr; 2177 2178 /* check for "acpi-root-tab" property */ 2179 if (do_bsys_getproplen(NULL, "acpi-root-tab") == sizeof (uint64_t)) { 2180 (void) do_bsys_getprop(NULL, "acpi-root-tab", &rsdp_val); 2181 if (rsdp_val != 0) { 2182 rsdp = scan_rsdp(rsdp_val, rsdp_val + sizeof (*rsdp)); 2183 if (rsdp != NULL) { 2184 if (kbm_debug) { 2185 bop_printf(NULL, 2186 "Using RSDP from bootloader: " 2187 "0x%p\n", (void *)rsdp); 2188 } 2189 return (rsdp); 2190 } 2191 } 2192 } 2193 2194 /* 2195 * Get the EBDA segment and scan the first 1K 2196 */ 2197 ebda_seg = (uint16_t *)vmap_phys(sizeof (uint16_t), 2198 ACPI_EBDA_PTR_LOCATION); 2199 ebda_addr = *ebda_seg << 4; 2200 rsdp = scan_rsdp(ebda_addr, ebda_addr + ACPI_EBDA_WINDOW_SIZE); 2201 if (rsdp == NULL) 2202 /* if EBDA doesn't contain RSDP, look in BIOS memory */ 2203 rsdp = scan_rsdp(ACPI_HI_RSDP_WINDOW_BASE, 2204 ACPI_HI_RSDP_WINDOW_BASE + ACPI_HI_RSDP_WINDOW_SIZE); 2205 return (rsdp); 2206 } 2207 2208 static ACPI_TABLE_HEADER * 2209 map_fw_table(paddr_t table_addr) 2210 { 2211 ACPI_TABLE_HEADER *tp; 2212 size_t len = MAX(sizeof (*tp), MMU_PAGESIZE); 2213 2214 /* 2215 * Map at least a page; if the table is larger than this, remap it 2216 */ 2217 tp = (ACPI_TABLE_HEADER *)vmap_phys(len, table_addr); 2218 if (tp->Length > len) 2219 tp = (ACPI_TABLE_HEADER *)vmap_phys(tp->Length, table_addr); 2220 return (tp); 2221 } 2222 2223 static ACPI_TABLE_HEADER * 2224 find_fw_table(char *signature) 2225 { 2226 static int revision = 0; 2227 static ACPI_TABLE_XSDT *xsdt; 2228 static int len; 2229 paddr_t xsdt_addr; 2230 ACPI_TABLE_RSDP *rsdp; 2231 ACPI_TABLE_HEADER *tp; 2232 paddr_t table_addr; 2233 int n; 2234 2235 if (strlen(signature) != ACPI_NAME_SIZE) 2236 return (NULL); 2237 2238 /* 2239 * Reading the ACPI 3.0 Spec, section 5.2.5.3 will help 2240 * understand this code. If we haven't already found the RSDT/XSDT, 2241 * revision will be 0. Find the RSDP and check the revision 2242 * to find out whether to use the RSDT or XSDT. If revision is 2243 * 0 or 1, use the RSDT and set internal revision to 1; if it is 2, 2244 * use the XSDT. If the XSDT address is 0, though, fall back to 2245 * revision 1 and use the RSDT. 2246 */ 2247 if (revision == 0) { 2248 if ((rsdp = find_rsdp()) != NULL) { 2249 revision = rsdp->Revision; 2250 /* 2251 * ACPI 6.0 states that current revision is 2 2252 * from acpi_table_rsdp definition: 2253 * Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+ 2254 */ 2255 if (revision > 2) 2256 revision = 2; 2257 switch (revision) { 2258 case 2: 2259 /* 2260 * Use the XSDT unless BIOS is buggy and 2261 * claims to be rev 2 but has a null XSDT 2262 * address 2263 */ 2264 xsdt_addr = rsdp->XsdtPhysicalAddress; 2265 if (xsdt_addr != 0) 2266 break; 2267 /* FALLTHROUGH */ 2268 case 0: 2269 /* treat RSDP rev 0 as revision 1 internally */ 2270 revision = 1; 2271 /* FALLTHROUGH */ 2272 case 1: 2273 /* use the RSDT for rev 0/1 */ 2274 xsdt_addr = rsdp->RsdtPhysicalAddress; 2275 break; 2276 default: 2277 /* unknown revision */ 2278 revision = 0; 2279 break; 2280 } 2281 } 2282 if (revision == 0) 2283 return (NULL); 2284 2285 /* cache the XSDT info */ 2286 xsdt = (ACPI_TABLE_XSDT *)map_fw_table(xsdt_addr); 2287 len = (xsdt->Header.Length - sizeof (xsdt->Header)) / 2288 ((revision == 1) ? sizeof (uint32_t) : sizeof (uint64_t)); 2289 } 2290 2291 /* 2292 * Scan the table headers looking for a signature match 2293 */ 2294 for (n = 0; n < len; n++) { 2295 ACPI_TABLE_RSDT *rsdt = (ACPI_TABLE_RSDT *)xsdt; 2296 table_addr = (revision == 1) ? rsdt->TableOffsetEntry[n] : 2297 xsdt->TableOffsetEntry[n]; 2298 2299 if (table_addr == 0) 2300 continue; 2301 tp = map_fw_table(table_addr); 2302 if (strncmp(tp->Signature, signature, ACPI_NAME_SIZE) == 0) { 2303 return (tp); 2304 } 2305 } 2306 return (NULL); 2307 } 2308 2309 static void 2310 process_mcfg(ACPI_TABLE_MCFG *tp) 2311 { 2312 ACPI_MCFG_ALLOCATION *cfg_baap; 2313 char *cfg_baa_endp; 2314 int64_t ecfginfo[4]; 2315 2316 cfg_baap = (ACPI_MCFG_ALLOCATION *)((uintptr_t)tp + sizeof (*tp)); 2317 cfg_baa_endp = ((char *)tp) + tp->Header.Length; 2318 while ((char *)cfg_baap < cfg_baa_endp) { 2319 if (cfg_baap->Address != 0 && cfg_baap->PciSegment == 0) { 2320 ecfginfo[0] = cfg_baap->Address; 2321 ecfginfo[1] = cfg_baap->PciSegment; 2322 ecfginfo[2] = cfg_baap->StartBusNumber; 2323 ecfginfo[3] = cfg_baap->EndBusNumber; 2324 bsetprop(MCFG_PROPNAME, strlen(MCFG_PROPNAME), 2325 ecfginfo, sizeof (ecfginfo)); 2326 break; 2327 } 2328 cfg_baap++; 2329 } 2330 } 2331 2332 #ifndef __xpv 2333 static void 2334 process_madt_entries(ACPI_TABLE_MADT *tp, uint32_t *cpu_countp, 2335 uint32_t *cpu_possible_countp, uint32_t *cpu_apicid_array) 2336 { 2337 ACPI_SUBTABLE_HEADER *item, *end; 2338 uint32_t cpu_count = 0; 2339 uint32_t cpu_possible_count = 0; 2340 2341 /* 2342 * Determine number of CPUs and keep track of "final" APIC ID 2343 * for each CPU by walking through ACPI MADT processor list 2344 */ 2345 end = (ACPI_SUBTABLE_HEADER *)(tp->Header.Length + (uintptr_t)tp); 2346 item = (ACPI_SUBTABLE_HEADER *)((uintptr_t)tp + sizeof (*tp)); 2347 2348 while (item < end) { 2349 switch (item->Type) { 2350 case ACPI_MADT_TYPE_LOCAL_APIC: { 2351 ACPI_MADT_LOCAL_APIC *cpu = 2352 (ACPI_MADT_LOCAL_APIC *) item; 2353 2354 if (cpu->LapicFlags & ACPI_MADT_ENABLED) { 2355 if (cpu_apicid_array != NULL) 2356 cpu_apicid_array[cpu_count] = cpu->Id; 2357 cpu_count++; 2358 } 2359 cpu_possible_count++; 2360 break; 2361 } 2362 case ACPI_MADT_TYPE_LOCAL_X2APIC: { 2363 ACPI_MADT_LOCAL_X2APIC *cpu = 2364 (ACPI_MADT_LOCAL_X2APIC *) item; 2365 2366 if (cpu->LapicFlags & ACPI_MADT_ENABLED) { 2367 if (cpu_apicid_array != NULL) 2368 cpu_apicid_array[cpu_count] = 2369 cpu->LocalApicId; 2370 cpu_count++; 2371 } 2372 cpu_possible_count++; 2373 break; 2374 } 2375 default: 2376 if (kbm_debug) 2377 bop_printf(NULL, "MADT type %d\n", item->Type); 2378 break; 2379 } 2380 2381 item = (ACPI_SUBTABLE_HEADER *)((uintptr_t)item + item->Length); 2382 } 2383 if (cpu_countp) 2384 *cpu_countp = cpu_count; 2385 if (cpu_possible_countp) 2386 *cpu_possible_countp = cpu_possible_count; 2387 } 2388 2389 static void 2390 process_madt(ACPI_TABLE_MADT *tp) 2391 { 2392 uint32_t cpu_count = 0; 2393 uint32_t cpu_possible_count = 0; 2394 uint32_t *cpu_apicid_array; /* x2APIC ID is 32bit! */ 2395 2396 if (tp != NULL) { 2397 /* count cpu's */ 2398 process_madt_entries(tp, &cpu_count, &cpu_possible_count, NULL); 2399 2400 cpu_apicid_array = (uint32_t *)do_bsys_alloc(NULL, NULL, 2401 cpu_count * sizeof (*cpu_apicid_array), MMU_PAGESIZE); 2402 if (cpu_apicid_array == NULL) 2403 bop_panic("Not enough memory for APIC ID array"); 2404 2405 /* copy IDs */ 2406 process_madt_entries(tp, NULL, NULL, cpu_apicid_array); 2407 2408 /* 2409 * Make boot property for array of "final" APIC IDs for each 2410 * CPU 2411 */ 2412 bsetprop(BP_CPU_APICID_ARRAY, strlen(BP_CPU_APICID_ARRAY), 2413 cpu_apicid_array, cpu_count * sizeof (*cpu_apicid_array)); 2414 } 2415 2416 /* 2417 * Check whether property plat-max-ncpus is already set. 2418 */ 2419 if (do_bsys_getproplen(NULL, PLAT_MAX_NCPUS_NAME) < 0) { 2420 /* 2421 * Set plat-max-ncpus to number of maximum possible CPUs given 2422 * in MADT if it hasn't been set. 2423 * There's no formal way to detect max possible CPUs supported 2424 * by platform according to ACPI spec3.0b. So current CPU 2425 * hotplug implementation expects that all possible CPUs will 2426 * have an entry in MADT table and set plat-max-ncpus to number 2427 * of entries in MADT. 2428 * With introducing of ACPI4.0, Maximum System Capability Table 2429 * (MSCT) provides maximum number of CPUs supported by platform. 2430 * If MSCT is unavailable, fall back to old way. 2431 */ 2432 if (tp != NULL) 2433 bsetpropsi(PLAT_MAX_NCPUS_NAME, cpu_possible_count); 2434 } 2435 2436 /* 2437 * Set boot property boot-max-ncpus to number of CPUs existing at 2438 * boot time. boot-max-ncpus is mainly used for optimization. 2439 */ 2440 if (tp != NULL) 2441 bsetpropsi(BOOT_MAX_NCPUS_NAME, cpu_count); 2442 2443 /* 2444 * User-set boot-ncpus overrides firmware count 2445 */ 2446 if (do_bsys_getproplen(NULL, BOOT_NCPUS_NAME) >= 0) 2447 return; 2448 2449 /* 2450 * Set boot property boot-ncpus to number of active CPUs given in MADT 2451 * if it hasn't been set yet. 2452 */ 2453 if (tp != NULL) 2454 bsetpropsi(BOOT_NCPUS_NAME, cpu_count); 2455 } 2456 2457 static void 2458 process_srat(ACPI_TABLE_SRAT *tp) 2459 { 2460 ACPI_SUBTABLE_HEADER *item, *end; 2461 int i; 2462 int proc_num, mem_num; 2463 #pragma pack(1) 2464 struct { 2465 uint32_t domain; 2466 uint32_t apic_id; 2467 uint32_t sapic_id; 2468 } processor; 2469 struct { 2470 uint32_t domain; 2471 uint32_t x2apic_id; 2472 } x2apic; 2473 struct { 2474 uint32_t domain; 2475 uint64_t addr; 2476 uint64_t length; 2477 uint32_t flags; 2478 } memory; 2479 #pragma pack() 2480 char prop_name[30]; 2481 uint64_t maxmem = 0; 2482 2483 if (tp == NULL) 2484 return; 2485 2486 proc_num = mem_num = 0; 2487 end = (ACPI_SUBTABLE_HEADER *)(tp->Header.Length + (uintptr_t)tp); 2488 item = (ACPI_SUBTABLE_HEADER *)((uintptr_t)tp + sizeof (*tp)); 2489 while (item < end) { 2490 switch (item->Type) { 2491 case ACPI_SRAT_TYPE_CPU_AFFINITY: { 2492 ACPI_SRAT_CPU_AFFINITY *cpu = 2493 (ACPI_SRAT_CPU_AFFINITY *) item; 2494 2495 if (!(cpu->Flags & ACPI_SRAT_CPU_ENABLED)) 2496 break; 2497 processor.domain = cpu->ProximityDomainLo; 2498 for (i = 0; i < 3; i++) 2499 processor.domain += 2500 cpu->ProximityDomainHi[i] << ((i + 1) * 8); 2501 processor.apic_id = cpu->ApicId; 2502 processor.sapic_id = cpu->LocalSapicEid; 2503 (void) snprintf(prop_name, 30, "acpi-srat-processor-%d", 2504 proc_num); 2505 bsetprop(prop_name, strlen(prop_name), &processor, 2506 sizeof (processor)); 2507 proc_num++; 2508 break; 2509 } 2510 case ACPI_SRAT_TYPE_MEMORY_AFFINITY: { 2511 ACPI_SRAT_MEM_AFFINITY *mem = 2512 (ACPI_SRAT_MEM_AFFINITY *)item; 2513 2514 if (!(mem->Flags & ACPI_SRAT_MEM_ENABLED)) 2515 break; 2516 memory.domain = mem->ProximityDomain; 2517 memory.addr = mem->BaseAddress; 2518 memory.length = mem->Length; 2519 memory.flags = mem->Flags; 2520 (void) snprintf(prop_name, 30, "acpi-srat-memory-%d", 2521 mem_num); 2522 bsetprop(prop_name, strlen(prop_name), &memory, 2523 sizeof (memory)); 2524 if ((mem->Flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) && 2525 (memory.addr + memory.length > maxmem)) { 2526 maxmem = memory.addr + memory.length; 2527 } 2528 mem_num++; 2529 break; 2530 } 2531 case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY: { 2532 ACPI_SRAT_X2APIC_CPU_AFFINITY *x2cpu = 2533 (ACPI_SRAT_X2APIC_CPU_AFFINITY *) item; 2534 2535 if (!(x2cpu->Flags & ACPI_SRAT_CPU_ENABLED)) 2536 break; 2537 x2apic.domain = x2cpu->ProximityDomain; 2538 x2apic.x2apic_id = x2cpu->ApicId; 2539 (void) snprintf(prop_name, 30, "acpi-srat-processor-%d", 2540 proc_num); 2541 bsetprop(prop_name, strlen(prop_name), &x2apic, 2542 sizeof (x2apic)); 2543 proc_num++; 2544 break; 2545 } 2546 default: 2547 if (kbm_debug) 2548 bop_printf(NULL, "SRAT type %d\n", item->Type); 2549 break; 2550 } 2551 2552 item = (ACPI_SUBTABLE_HEADER *) 2553 (item->Length + (uintptr_t)item); 2554 } 2555 2556 /* 2557 * The maximum physical address calculated from the SRAT table is more 2558 * accurate than that calculated from the MSCT table. 2559 */ 2560 if (maxmem != 0) { 2561 plat_dr_physmax = btop(maxmem); 2562 } 2563 } 2564 2565 static void 2566 process_slit(ACPI_TABLE_SLIT *tp) 2567 { 2568 2569 /* 2570 * Check the number of localities; if it's too huge, we just 2571 * return and locality enumeration code will handle this later, 2572 * if possible. 2573 * 2574 * Note that the size of the table is the square of the 2575 * number of localities; if the number of localities exceeds 2576 * UINT16_MAX, the table size may overflow an int when being 2577 * passed to bsetprop() below. 2578 */ 2579 if (tp->LocalityCount >= SLIT_LOCALITIES_MAX) 2580 return; 2581 2582 bsetprop(SLIT_NUM_PROPNAME, strlen(SLIT_NUM_PROPNAME), 2583 &tp->LocalityCount, sizeof (tp->LocalityCount)); 2584 bsetprop(SLIT_PROPNAME, strlen(SLIT_PROPNAME), &tp->Entry, 2585 tp->LocalityCount * tp->LocalityCount); 2586 } 2587 2588 static ACPI_TABLE_MSCT * 2589 process_msct(ACPI_TABLE_MSCT *tp) 2590 { 2591 int last_seen = 0; 2592 int proc_num = 0; 2593 ACPI_MSCT_PROXIMITY *item, *end; 2594 extern uint64_t plat_dr_options; 2595 2596 ASSERT(tp != NULL); 2597 2598 end = (ACPI_MSCT_PROXIMITY *)(tp->Header.Length + (uintptr_t)tp); 2599 for (item = (void *)((uintptr_t)tp + tp->ProximityOffset); 2600 item < end; 2601 item = (void *)(item->Length + (uintptr_t)item)) { 2602 /* 2603 * Sanity check according to section 5.2.19.1 of ACPI 4.0. 2604 * Revision 1 2605 * Length 22 2606 */ 2607 if (item->Revision != 1 || item->Length != 22) { 2608 cmn_err(CE_CONT, 2609 "?boot: unknown proximity domain structure in MSCT " 2610 "with Revision(%d), Length(%d).\n", 2611 (int)item->Revision, (int)item->Length); 2612 return (NULL); 2613 } else if (item->RangeStart > item->RangeEnd) { 2614 cmn_err(CE_CONT, 2615 "?boot: invalid proximity domain structure in MSCT " 2616 "with RangeStart(%u), RangeEnd(%u).\n", 2617 item->RangeStart, item->RangeEnd); 2618 return (NULL); 2619 } else if (item->RangeStart != last_seen) { 2620 /* 2621 * Items must be organized in ascending order of the 2622 * proximity domain enumerations. 2623 */ 2624 cmn_err(CE_CONT, 2625 "?boot: invalid proximity domain structure in MSCT," 2626 " items are not orginized in ascending order.\n"); 2627 return (NULL); 2628 } 2629 2630 /* 2631 * If ProcessorCapacity is 0 then there would be no CPUs in this 2632 * domain. 2633 */ 2634 if (item->ProcessorCapacity != 0) { 2635 proc_num += (item->RangeEnd - item->RangeStart + 1) * 2636 item->ProcessorCapacity; 2637 } 2638 2639 last_seen = item->RangeEnd - item->RangeStart + 1; 2640 /* 2641 * Break out if all proximity domains have been processed. 2642 * Some BIOSes may have unused items at the end of MSCT table. 2643 */ 2644 if (last_seen > tp->MaxProximityDomains) { 2645 break; 2646 } 2647 } 2648 if (last_seen != tp->MaxProximityDomains + 1) { 2649 cmn_err(CE_CONT, 2650 "?boot: invalid proximity domain structure in MSCT, " 2651 "proximity domain count doesn't match.\n"); 2652 return (NULL); 2653 } 2654 2655 /* 2656 * Set plat-max-ncpus property if it hasn't been set yet. 2657 */ 2658 if (do_bsys_getproplen(NULL, PLAT_MAX_NCPUS_NAME) < 0) { 2659 if (proc_num != 0) { 2660 bsetpropsi(PLAT_MAX_NCPUS_NAME, proc_num); 2661 } 2662 } 2663 2664 /* 2665 * Use Maximum Physical Address from the MSCT table as upper limit for 2666 * memory hot-adding by default. It may be overridden by value from 2667 * the SRAT table or the "plat-dr-physmax" boot option. 2668 */ 2669 plat_dr_physmax = btop(tp->MaxAddress + 1); 2670 2671 /* 2672 * Existence of MSCT implies CPU/memory hotplug-capability for the 2673 * platform. 2674 */ 2675 plat_dr_options |= PLAT_DR_FEATURE_CPU; 2676 plat_dr_options |= PLAT_DR_FEATURE_MEMORY; 2677 2678 return (tp); 2679 } 2680 2681 #else /* __xpv */ 2682 static void 2683 enumerate_xen_cpus() 2684 { 2685 processorid_t id, max_id; 2686 2687 /* 2688 * User-set boot-ncpus overrides enumeration 2689 */ 2690 if (do_bsys_getproplen(NULL, BOOT_NCPUS_NAME) >= 0) 2691 return; 2692 2693 /* 2694 * Probe every possible virtual CPU id and remember the 2695 * highest id present; the count of CPUs is one greater 2696 * than this. This tacitly assumes at least cpu 0 is present. 2697 */ 2698 max_id = 0; 2699 for (id = 0; id < MAX_VIRT_CPUS; id++) 2700 if (HYPERVISOR_vcpu_op(VCPUOP_is_up, id, NULL) == 0) 2701 max_id = id; 2702 2703 bsetpropsi(BOOT_NCPUS_NAME, max_id+1); 2704 2705 } 2706 #endif /* __xpv */ 2707 2708 /*ARGSUSED*/ 2709 static void 2710 build_firmware_properties(struct xboot_info *xbp) 2711 { 2712 ACPI_TABLE_HEADER *tp = NULL; 2713 2714 #ifndef __xpv 2715 if (xbp->bi_uefi_arch == XBI_UEFI_ARCH_64) { 2716 bsetprops("efi-systype", "64"); 2717 bsetprop64("efi-systab", 2718 (uint64_t)(uintptr_t)xbp->bi_uefi_systab); 2719 if (kbm_debug) 2720 bop_printf(NULL, "64-bit UEFI detected.\n"); 2721 } else if (xbp->bi_uefi_arch == XBI_UEFI_ARCH_32) { 2722 bsetprops("efi-systype", "32"); 2723 bsetprop64("efi-systab", 2724 (uint64_t)(uintptr_t)xbp->bi_uefi_systab); 2725 if (kbm_debug) 2726 bop_printf(NULL, "32-bit UEFI detected.\n"); 2727 } 2728 2729 if (xbp->bi_acpi_rsdp != NULL) { 2730 bsetprop64("acpi-root-tab", 2731 (uint64_t)(uintptr_t)xbp->bi_acpi_rsdp); 2732 } 2733 2734 if (xbp->bi_smbios != NULL) { 2735 bsetprop64("smbios-address", 2736 (uint64_t)(uintptr_t)xbp->bi_smbios); 2737 } 2738 2739 if ((tp = find_fw_table(ACPI_SIG_MSCT)) != NULL) 2740 msct_ptr = process_msct((ACPI_TABLE_MSCT *)tp); 2741 else 2742 msct_ptr = NULL; 2743 2744 if ((tp = find_fw_table(ACPI_SIG_MADT)) != NULL) 2745 process_madt((ACPI_TABLE_MADT *)tp); 2746 2747 if ((srat_ptr = (ACPI_TABLE_SRAT *) 2748 find_fw_table(ACPI_SIG_SRAT)) != NULL) 2749 process_srat(srat_ptr); 2750 2751 if (slit_ptr = (ACPI_TABLE_SLIT *)find_fw_table(ACPI_SIG_SLIT)) 2752 process_slit(slit_ptr); 2753 2754 tp = find_fw_table(ACPI_SIG_MCFG); 2755 #else /* __xpv */ 2756 enumerate_xen_cpus(); 2757 if (DOMAIN_IS_INITDOMAIN(xen_info)) 2758 tp = find_fw_table(ACPI_SIG_MCFG); 2759 #endif /* __xpv */ 2760 if (tp != NULL) 2761 process_mcfg((ACPI_TABLE_MCFG *)tp); 2762 } 2763 2764 /* 2765 * fake up a boot property for deferred early console output 2766 * this is used by both graphical boot and the (developer only) 2767 * USB serial console 2768 */ 2769 void * 2770 defcons_init(size_t size) 2771 { 2772 static char *p = NULL; 2773 2774 p = do_bsys_alloc(NULL, NULL, size, MMU_PAGESIZE); 2775 *p = 0; 2776 bsetprop("deferred-console-buf", strlen("deferred-console-buf") + 1, 2777 &p, sizeof (p)); 2778 return (p); 2779 } 2780 2781 /*ARGSUSED*/ 2782 int 2783 boot_compinfo(int fd, struct compinfo *cbp) 2784 { 2785 cbp->iscmp = 0; 2786 cbp->blksize = MAXBSIZE; 2787 return (0); 2788 } 2789 2790 #define BP_MAX_STRLEN 32 2791 2792 /* 2793 * Get value for given boot property 2794 */ 2795 int 2796 bootprop_getval(const char *prop_name, u_longlong_t *prop_value) 2797 { 2798 int boot_prop_len; 2799 char str[BP_MAX_STRLEN]; 2800 u_longlong_t value; 2801 2802 boot_prop_len = BOP_GETPROPLEN(bootops, prop_name); 2803 if (boot_prop_len < 0 || boot_prop_len > sizeof (str) || 2804 BOP_GETPROP(bootops, prop_name, str) < 0 || 2805 kobj_getvalue(str, &value) == -1) 2806 return (-1); 2807 2808 if (prop_value) 2809 *prop_value = value; 2810 2811 return (0); 2812 } 2813