Print this page
NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
    loader: pxe receive cleanup
    9475 libefi: Do not return only if ReceiveFilter
    installboot: should support efi system partition
    8931 boot1.efi: scan all display modes rather than
    loader: spinconsole updates
    loader: gfx experiment to try GOP Blt() function.
    sha1 build test
    loader: add sha1 hash calculation
    common/sha1: update for loader build
    loader: biosdisk rework
    uts: 32-bit kernel FB needs mapping in low memory
    uts: add diag-device
    uts: boot console mirror with diag-device
    uts: enable very early console on ttya
    kmdb: add diag-device as input/output device
    uts: test VGA memory exclusion from mapping
    uts: clear boot mapping and protect boot pages test
    uts: add dboot map debug printf
    uts: need to release FB pages in release_bootstrap()
    uts: add screenmap ioctl
    uts: update sys/queue.h
    loader: add illumos uts/common to include path
    loader: tem/gfx font cleanup
    loader: vbe checks
    uts: gfx_private set KD_TEXT when KD_RESETTEXT is
    uts: gfx 8-bit update
    loader: gfx 8-bit fix
    loader: always set media size from partition.
    uts: MB2 support for 32-bit kernel
    loader: x86 should have tem 80x25
    uts: x86 should have tem 80x25
    uts: font update
    loader: font update
    uts: tem attributes
    loader: tem.c comment added
    uts: use font module
    loader: add font module
    loader: build rules for new font setup
    uts: gfx_private update for new font structure
    uts: early boot update for new font structure
    uts: font update
    uts: font build rules update for new fonts
    uts: tem update to new font structure
    loader: module.c needs to include tem_impl.h
    uts: gfx_private 8x16 font rework
    uts: make font_lookup public
    loader: font rework
    uts: font rework
    9259 libefi: efi_alloc_and_read should check for PMBR
    uts: tem utf-8 support
    loader: implement tem utf-8 support
    loader: tem should be able to display UTF-8
    7784 uts: console input should support utf-8
    7796 uts: ldterm default to utf-8
    uts: do not reset serial console
    uts: set up colors even if tem is not console
    uts: add type for early boot properties
    uts: gfx_private experiment with drm and vga
    uts: gfx_private should use setmode drm callback.
    uts: identify FB types and set up gfx_private based
    loader: replace gop and vesa with framebuffer
    uts: boot needs simple tem to support mdb
    uts: boot_keyboard should emit esc sequences for
    uts: gfx_private FB showuld be written by line
    kmdb: set terminal window size
    uts: gfx_private needs to keep track of early boot FB
    pnglite: move pnglite to usr/src/common
    loader: gfx_fb
    ficl-sys: add gfx primitives
    loader: add illumos.png logo
    ficl: add fb-putimage
    loader: add png support
    loader: add alpha blending for gfx_fb
    loader: use term-drawrect for menu frame
    ficl: add simple gfx words
    uts: provide fb_info via fbgattr dev_specific array.
    uts: gfx_private add alpha blending
    uts: update sys/ascii.h
    uts: tem OSC support (incomplete)
    uts: implement env module support and use data from
    uts: tem get colors from early boot data
    loader: use crc32 from libstand (libz)
    loader: optimize for size
    loader: pass tem info to the environment
    loader: import tem for loader console
    loader: UEFI loader needs to set ISADIR based on
    loader: need UEFI32 support
    8918 loader.efi: add vesa edid support
    uts: tem_safe_pix_clear_prom_output() should only
    uts: tem_safe_pix_clear_entire_screen() should use
    uts: tem_safe_check_first_time() should query cursor
    uts: tem implement cls callback & visual_io v4
    uts: gfx_vgatext use block cursor for vgatext
    uts: gfx_private implement cls callback & visual_io
    uts: gfx_private bitmap framebuffer implementation
    uts: early start frame buffer console support
    uts: font functions should check the input char
    uts: font rendering should support 16/24/32bit depths
    uts: use smallest font as fallback default.
    uts: update terminal dimensions based on selected
    7834 uts: vgatext should use gfx_private
    uts: add spacing property to 8859-1.bdf
    terminfo: add underline for sun-color
    terminfo: sun-color has 16 colors
    uts: add font load callback type
    loader: do not repeat int13 calls with error 0x20 and
    8905 loader: add skein/edonr support
    8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>
Revert "NEX-16819 loader UEFI support"
This reverts commit ec06b9fc617b99234e538bf2e7e4d02a24993e0c.
Reverting due to failures in the zfs-tests and the sharefs-tests
NEX-16819 loader UEFI support
Includes work by Toomas Soome <tsoome@me.com>
Upstream commits:
    loader: pxe receive cleanup
    9475 libefi: Do not return only if ReceiveFilter
    installboot: should support efi system partition
    8931 boot1.efi: scan all display modes rather than
    loader: spinconsole updates
    loader: gfx experiment to try GOP Blt() function.
    sha1 build test
    loader: add sha1 hash calculation
    common/sha1: update for loader build
    loader: biosdisk rework
    uts: 32-bit kernel FB needs mapping in low memory
    uts: add diag-device
    uts: boot console mirror with diag-device
    uts: enable very early console on ttya
    kmdb: add diag-device as input/output device
    uts: test VGA memory exclusion from mapping
    uts: clear boot mapping and protect boot pages test
    uts: add dboot map debug printf
    uts: need to release FB pages in release_bootstrap()
    uts: add screenmap ioctl
    uts: update sys/queue.h
    loader: add illumos uts/common to include path
    loader: tem/gfx font cleanup
    loader: vbe checks
    uts: gfx_private set KD_TEXT when KD_RESETTEXT is
    uts: gfx 8-bit update
    loader: gfx 8-bit fix
    loader: always set media size from partition.
    uts: MB2 support for 32-bit kernel
    loader: x86 should have tem 80x25
    uts: x86 should have tem 80x25
    uts: font update
    loader: font update
    uts: tem attributes
    loader: tem.c comment added
    uts: use font module
    loader: add font module
    loader: build rules for new font setup
    uts: gfx_private update for new font structure
    uts: early boot update for new font structure
    uts: font update
    uts: font build rules update for new fonts
    uts: tem update to new font structure
    loader: module.c needs to include tem_impl.h
    uts: gfx_private 8x16 font rework
    uts: make font_lookup public
    loader: font rework
    uts: font rework
    libefi: efi_alloc_and_read should check for PMBR
    uts: tem utf-8 support
    loader: implement tem utf-8 support
    loader: tem should be able to display UTF-8
    7784 uts: console input should support utf-8
    7796 uts: ldterm default to utf-8
    uts: do not reset serial console
    uts: set up colors even if tem is not console
    uts: add type for early boot properties
    uts: gfx_private experiment with drm and vga
    uts: gfx_private should use setmode drm callback.
    uts: identify FB types and set up gfx_private based
    loader: replace gop and vesa with framebuffer
    uts: boot needs simple tem to support mdb
    uts: boot_keyboard should emit esc sequences for
    uts: gfx_private FB showuld be written by line
    kmdb: set terminal window size
    uts: gfx_private needs to keep track of early boot FB
    pnglite: move pnglite to usr/src/common
    loader: gfx_fb
    ficl-sys: add gfx primitives
    loader: add illumos.png logo
    ficl: add fb-putimage
    loader: add png support
    loader: add alpha blending for gfx_fb
    loader: use term-drawrect for menu frame
    ficl: add simple gfx words
    uts: provide fb_info via fbgattr dev_specific array.
    uts: gfx_private add alpha blending
    uts: update sys/ascii.h
    uts: tem OSC support (incomplete)
    uts: implement env module support and use data from
    uts: tem get colors from early boot data
    loader: use crc32 from libstand (libz)
    loader: optimize for size
    loader: pass tem info to the environment
    loader: import tem for loader console
    loader: UEFI loader needs to set ISADIR based on
    loader: need UEFI32 support
    8918 loader.efi: add vesa edid support
    uts: tem_safe_pix_clear_prom_output() should only
    uts: tem_safe_pix_clear_entire_screen() should use
    uts: tem_safe_check_first_time() should query cursor
    uts: tem implement cls callback & visual_io v4
    uts: gfx_vgatext use block cursor for vgatext
    uts: gfx_private implement cls callback & visual_io
    uts: gfx_private bitmap framebuffer implementation
    uts: early start frame buffer console support
    uts: font functions should check the input char
    uts: font rendering should support 16/24/32bit depths
    uts: use smallest font as fallback default.
    uts: update terminal dimensions based on selected
    7834 uts: vgatext should use gfx_private
    uts: add spacing property to 8859-1.bdf
    terminfo: add underline for sun-color
    terminfo: sun-color has 16 colors
    uts: add font load callback type
    loader: do not repeat int13 calls with error 0x20 and
    8905 loader: add skein/edonr support
    8904 common/crypto: make skein and edonr loader
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Evan Layton <evan.layton@nexenta.com>


  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 


 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*/


 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 {


 697                 }
 698                 name[n_len] = 0;
 699                 if (v_len > 0)
 700                         value[v_len] = 0;
 701                 else
 702                         continue;
 703 
 704                 /*
 705                  * ignore "boot-file" property, it's now meaningless
 706                  */
 707                 if (strcmp(name, "boot-file") == 0)
 708                         continue;
 709                 if (strcmp(name, "boot-args") == 0 &&
 710                     strlen(boot_args) > 0)
 711                         continue;
 712 
 713                 /*
 714                  * If a property was explicitly set on the command line
 715                  * it will override a setting in bootenv.rc
 716                  */
 717                 if (do_bsys_getproplen(NULL, name) > 0)
 718                         continue;
 719 
 720                 bsetprop(name, n_len, value, v_len + 1);
 721         }
 722 done:
 723         if (fd >= 0)
 724                 (void) BRD_CLOSE(bfs_ops, fd);
 725 
 726         /*
 727          * Check if we have to limit the boot time allocator
 728          */
 729         if (do_bsys_getproplen(NULL, "physmem") != -1 &&
 730             do_bsys_getprop(NULL, "physmem", line) >= 0 &&
 731             parse_value(line, &lvalue) != -1) {
 732                 if (0 < lvalue && (lvalue < physmem || physmem == 0)) {
 733                         physmem = (pgcnt_t)lvalue;
 734                         DBG(physmem);
 735                 }
 736         }
 737         early_allocation = 0;
 738 
 739         /*
 740          * check to see if we have to override the default value of the console


 974 
 975         DBG_MSG("VBD bootpath set to ");
 976         DBG_MSG(vbdpath);
 977         DBG_MSG("\n");
 978 }
 979 
 980 /*
 981  * parse the xpv-nfsroot property to create properties used by
 982  * nfs_mountroot.
 983  */
 984 static void
 985 xen_nfsroot_props(char *s)
 986 {
 987         char *prop_map[] = {
 988                 BP_SERVER_IP,   /* server IP address */
 989                 BP_SERVER_NAME, /* server hostname */
 990                 BP_SERVER_PATH, /* root path */
 991         };
 992         int n_prop = sizeof (prop_map) / sizeof (prop_map[0]);
 993 
 994         bsetprop("fstype", 6, "nfs", 4);
 995 
 996         xen_parse_props(s, prop_map, n_prop);
 997 
 998         /*
 999          * If a server name wasn't specified, use a default.
1000          */
1001         if (do_bsys_getproplen(NULL, BP_SERVER_NAME) == -1)
1002                 bsetprops(BP_SERVER_NAME, "unknown");
1003 }
1004 
1005 /*
1006  * Extract our IP address, etc. from the "xpv-ip" property.
1007  */
1008 static void
1009 xen_ip_props(char *s)
1010 {
1011         char *prop_map[] = {
1012                 BP_HOST_IP,             /* IP address */
1013                 NULL,                   /* NFS server IP address (ignored in */
1014                                         /* favour of xpv-nfsroot) */


1340 #ifndef __xpv
1341         static int stdout_val = 0;
1342         uchar_t boot_device;
1343         char str[3];
1344 #endif
1345 
1346         /*
1347          * These have to be done first, so that kobj_mount_root() works
1348          */
1349         DBG_MSG("Building boot properties\n");
1350         propbuf = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, 0);
1351         DBG((uintptr_t)propbuf);
1352         if (xbp->bi_module_cnt > 0) {
1353                 bm = xbp->bi_modules;
1354                 rdbm = NULL;
1355                 for (midx = i = 0; i < xbp->bi_module_cnt; i++) {
1356                         if (bm[i].bm_type == BMT_ROOTFS) {
1357                                 rdbm = &bm[i];
1358                                 continue;
1359                         }
1360                         if (bm[i].bm_type == BMT_HASH || bm[i].bm_name == NULL)


1361                                 continue;
1362 
1363                         if (bm[i].bm_type == BMT_ENV) {
1364                                 if (benv == NULL)
1365                                         benv = &bm[i];
1366                                 else
1367                                         continue;
1368                         }
1369 
1370                         (void) snprintf(modid, sizeof (modid),
1371                             "module-name-%u", midx);
1372                         bsetprops(modid, (char *)bm[i].bm_name);
1373                         (void) snprintf(modid, sizeof (modid),
1374                             "module-addr-%u", midx);
1375                         bsetprop64(modid, (uint64_t)(uintptr_t)bm[i].bm_addr);
1376                         (void) snprintf(modid, sizeof (modid),
1377                             "module-size-%u", midx);
1378                         bsetprop64(modid, (uint64_t)bm[i].bm_size);
1379                         ++midx;
1380                 }


1555 
1556                                 /*
1557                                  * In the quote accept any character,
1558                                  * but look for ending quote.
1559                                  */
1560                                 if (quoted) {
1561                                         if (value[value_len] == quoted)
1562                                                 quoted = 0;
1563                                         continue;
1564                                 }
1565 
1566                                 /*
1567                                  * a comma or white space ends the value
1568                                  */
1569                                 if (value[value_len] == ',' ||
1570                                     ISSPACE(value[value_len]))
1571                                         break;
1572                         }
1573 
1574                         if (value_len == 0) {
1575                                 bsetprop(name, name_len, "true", 5);

1576                         } else {
1577                                 char *v = value;
1578                                 int l = value_len;
1579                                 if (v[0] == v[l - 1] &&
1580                                     (v[0] == '\'' || v[0] == '"')) {
1581                                         ++v;
1582                                         l -= 2;
1583                                 }
1584                                 bcopy(v, propbuf, l);
1585                                 propbuf[l] = '\0';
1586                                 bsetprop(name, name_len, propbuf,
1587                                     l + 1);
1588                         }
1589                         name = value + value_len;
1590                         while (*name == ',')
1591                                 ++name;
1592                 }
1593         }
1594 
1595         /*
1596          * set boot-args property
1597          * 1275 name is bootargs, so set
1598          * that too
1599          */
1600         bsetprops("boot-args", boot_args);
1601         bsetprops("bootargs", boot_args);
1602 
1603         process_boot_environment(benv);
1604 
1605 #ifndef __xpv
1606         /*
1607          * Build boot command line for Fast Reboot


1626                 if (mbi != NULL && mbi->flags & MB_INFO_BOOTDEV) {
1627                         boot_device = mbi->boot_device >> 24;
1628                         if (boot_device == 0x20)
1629                                 netboot++;
1630                         str[0] = (boot_device >> 4) + '0';
1631                         str[1] = (boot_device & 0xf) + '0';
1632                         str[2] = 0;
1633                         bsetprops("bios-boot-device", str);
1634                 } else {
1635                         netboot = 1;
1636                 }
1637 
1638                 /*
1639                  * In the netboot case, drives_info is overloaded with the
1640                  * dhcp ack. This is not multiboot compliant and requires
1641                  * special pxegrub!
1642                  */
1643                 if (netboot && mbi->drives_length != 0) {
1644                         sip = (struct sol_netinfo *)(uintptr_t)mbi->drives_addr;
1645                         if (sip->sn_infotype == SN_TYPE_BOOTP)
1646                                 bsetprop("bootp-response",

1647                                     sizeof ("bootp-response"),
1648                                     (void *)(uintptr_t)mbi->drives_addr,
1649                                     mbi->drives_length);
1650                         else if (sip->sn_infotype == SN_TYPE_RARP)
1651                                 setup_rarp_props(sip);
1652                 }
1653         } else {
1654                 multiboot2_info_header_t *mbi = xbp->bi_mb_info;
1655                 multiboot_tag_bootdev_t *bootdev = NULL;
1656                 multiboot_tag_network_t *netdev = NULL;
1657 
1658                 if (mbi != NULL) {
1659                         bootdev = dboot_multiboot2_find_tag(mbi,
1660                             MULTIBOOT_TAG_TYPE_BOOTDEV);
1661                         netdev = dboot_multiboot2_find_tag(mbi,
1662                             MULTIBOOT_TAG_TYPE_NETWORK);
1663                 }
1664                 if (bootdev != NULL) {
1665                         DBG(bootdev->mb_biosdev);
1666                         boot_device = bootdev->mb_biosdev;
1667                         str[0] = (boot_device >> 4) + '0';
1668                         str[1] = (boot_device & 0xf) + '0';
1669                         str[2] = 0;
1670                         bsetprops("bios-boot-device", str);
1671                 }
1672                 if (netdev != NULL) {
1673                         bsetprop("bootp-response", sizeof ("bootp-response"),

1674                             (void *)(uintptr_t)netdev->mb_dhcpack,
1675                             netdev->mb_size -
1676                             sizeof (multiboot_tag_network_t));
1677                 }
1678         }
1679 
1680         bsetprop("stdout", strlen("stdout"),
1681             &stdout_val, sizeof (stdout_val));
1682 #endif /* __xpv */
1683 
1684         /*
1685          * more conjured up values for made up things....
1686          */
1687 #if defined(__xpv)
1688         bsetprops("mfg-name", "i86xpv");
1689         bsetprops("impl-arch-name", "i86xpv");
1690 #else
1691         bsetprops("mfg-name", "i86pc");
1692         bsetprops("impl-arch-name", "i86pc");
1693 #endif
1694 
1695         /*
1696          * Build firmware-provided system properties
1697          */
1698         build_firmware_properties(xbp);
1699 
1700         /*
1701          * XXPV


2012         bops->bsys_ealloc = do_bsys_ealloc;
2013 
2014 #ifdef __xpv
2015         /*
2016          * On domain 0 we need to free up some physical memory that is
2017          * usable for DMA. Since GRUB loaded the boot_archive, it is
2018          * sitting in low MFN memory. We'll relocated the boot archive
2019          * pages to high PFN memory.
2020          */
2021         if (DOMAIN_IS_INITDOMAIN(xen_info))
2022                 relocate_boot_archive(xbp);
2023 #endif
2024 
2025 #ifndef __xpv
2026         /*
2027          * Install an IDT to catch early pagefaults (shouldn't have any).
2028          * Also needed for kmdb.
2029          */
2030         bop_idt_init();
2031 #endif


2032 
2033         /*
2034          * Start building the boot properties from the command line
2035          */
2036         DBG_MSG("Initializing boot properties:\n");
2037         build_boot_properties(xbp);
2038 
2039         if (find_boot_prop("prom_debug") || kbm_debug) {
2040                 char *value;
2041 
2042                 value = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, MMU_PAGESIZE);
2043                 boot_prop_display(value);
2044         }
2045 
2046         /*
2047          * jump into krtld...
2048          */
2049         _kobj_boot(&bop_sysp, NULL, bops, NULL);
2050 }
2051 


2291                 }
2292         }
2293         return (NULL);
2294 }
2295 
2296 static void
2297 process_mcfg(ACPI_TABLE_MCFG *tp)
2298 {
2299         ACPI_MCFG_ALLOCATION *cfg_baap;
2300         char *cfg_baa_endp;
2301         int64_t ecfginfo[4];
2302 
2303         cfg_baap = (ACPI_MCFG_ALLOCATION *)((uintptr_t)tp + sizeof (*tp));
2304         cfg_baa_endp = ((char *)tp) + tp->Header.Length;
2305         while ((char *)cfg_baap < cfg_baa_endp) {
2306                 if (cfg_baap->Address != 0 && cfg_baap->PciSegment == 0) {
2307                         ecfginfo[0] = cfg_baap->Address;
2308                         ecfginfo[1] = cfg_baap->PciSegment;
2309                         ecfginfo[2] = cfg_baap->StartBusNumber;
2310                         ecfginfo[3] = cfg_baap->EndBusNumber;
2311                         bsetprop(MCFG_PROPNAME, strlen(MCFG_PROPNAME),

2312                             ecfginfo, sizeof (ecfginfo));
2313                         break;
2314                 }
2315                 cfg_baap++;
2316         }
2317 }
2318 
2319 #ifndef __xpv
2320 static void
2321 process_madt_entries(ACPI_TABLE_MADT *tp, uint32_t *cpu_countp,
2322     uint32_t *cpu_possible_countp, uint32_t *cpu_apicid_array)
2323 {
2324         ACPI_SUBTABLE_HEADER *item, *end;
2325         uint32_t cpu_count = 0;
2326         uint32_t cpu_possible_count = 0;
2327 
2328         /*
2329          * Determine number of CPUs and keep track of "final" APIC ID
2330          * for each CPU by walking through ACPI MADT processor list
2331          */


2379         uint32_t cpu_count = 0;
2380         uint32_t cpu_possible_count = 0;
2381         uint32_t *cpu_apicid_array; /* x2APIC ID is 32bit! */
2382 
2383         if (tp != NULL) {
2384                 /* count cpu's */
2385                 process_madt_entries(tp, &cpu_count, &cpu_possible_count, NULL);
2386 
2387                 cpu_apicid_array = (uint32_t *)do_bsys_alloc(NULL, NULL,
2388                     cpu_count * sizeof (*cpu_apicid_array), MMU_PAGESIZE);
2389                 if (cpu_apicid_array == NULL)
2390                         bop_panic("Not enough memory for APIC ID array");
2391 
2392                 /* copy IDs */
2393                 process_madt_entries(tp, NULL, NULL, cpu_apicid_array);
2394 
2395                 /*
2396                  * Make boot property for array of "final" APIC IDs for each
2397                  * CPU
2398                  */
2399                 bsetprop(BP_CPU_APICID_ARRAY, strlen(BP_CPU_APICID_ARRAY),

2400                     cpu_apicid_array, cpu_count * sizeof (*cpu_apicid_array));
2401         }
2402 
2403         /*
2404          * Check whether property plat-max-ncpus is already set.
2405          */
2406         if (do_bsys_getproplen(NULL, PLAT_MAX_NCPUS_NAME) < 0) {
2407                 /*
2408                  * Set plat-max-ncpus to number of maximum possible CPUs given
2409                  * in MADT if it hasn't been set.
2410                  * There's no formal way to detect max possible CPUs supported
2411                  * by platform according to ACPI spec3.0b. So current CPU
2412                  * hotplug implementation expects that all possible CPUs will
2413                  * have an entry in MADT table and set plat-max-ncpus to number
2414                  * of entries in MADT.
2415                  * With introducing of ACPI4.0, Maximum System Capability Table
2416                  * (MSCT) provides maximum number of CPUs supported by platform.
2417                  * If MSCT is unavailable, fall back to old way.
2418                  */
2419                 if (tp != NULL)


2472 
2473         proc_num = mem_num = 0;
2474         end = (ACPI_SUBTABLE_HEADER *)(tp->Header.Length + (uintptr_t)tp);
2475         item = (ACPI_SUBTABLE_HEADER *)((uintptr_t)tp + sizeof (*tp));
2476         while (item < end) {
2477                 switch (item->Type) {
2478                 case ACPI_SRAT_TYPE_CPU_AFFINITY: {
2479                         ACPI_SRAT_CPU_AFFINITY *cpu =
2480                             (ACPI_SRAT_CPU_AFFINITY *) item;
2481 
2482                         if (!(cpu->Flags & ACPI_SRAT_CPU_ENABLED))
2483                                 break;
2484                         processor.domain = cpu->ProximityDomainLo;
2485                         for (i = 0; i < 3; i++)
2486                                 processor.domain +=
2487                                     cpu->ProximityDomainHi[i] << ((i + 1) * 8);
2488                         processor.apic_id = cpu->ApicId;
2489                         processor.sapic_id = cpu->LocalSapicEid;
2490                         (void) snprintf(prop_name, 30, "acpi-srat-processor-%d",
2491                             proc_num);
2492                         bsetprop(prop_name, strlen(prop_name), &processor,

2493                             sizeof (processor));
2494                         proc_num++;
2495                         break;
2496                 }
2497                 case ACPI_SRAT_TYPE_MEMORY_AFFINITY: {
2498                         ACPI_SRAT_MEM_AFFINITY *mem =
2499                             (ACPI_SRAT_MEM_AFFINITY *)item;
2500 
2501                         if (!(mem->Flags & ACPI_SRAT_MEM_ENABLED))
2502                                 break;
2503                         memory.domain = mem->ProximityDomain;
2504                         memory.addr = mem->BaseAddress;
2505                         memory.length = mem->Length;
2506                         memory.flags = mem->Flags;
2507                         (void) snprintf(prop_name, 30, "acpi-srat-memory-%d",
2508                             mem_num);
2509                         bsetprop(prop_name, strlen(prop_name), &memory,

2510                             sizeof (memory));
2511                         if ((mem->Flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) &&
2512                             (memory.addr + memory.length > maxmem)) {
2513                                 maxmem = memory.addr + memory.length;
2514                         }
2515                         mem_num++;
2516                         break;
2517                 }
2518                 case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY: {
2519                         ACPI_SRAT_X2APIC_CPU_AFFINITY *x2cpu =
2520                             (ACPI_SRAT_X2APIC_CPU_AFFINITY *) item;
2521 
2522                         if (!(x2cpu->Flags & ACPI_SRAT_CPU_ENABLED))
2523                                 break;
2524                         x2apic.domain = x2cpu->ProximityDomain;
2525                         x2apic.x2apic_id = x2cpu->ApicId;
2526                         (void) snprintf(prop_name, 30, "acpi-srat-processor-%d",
2527                             proc_num);
2528                         bsetprop(prop_name, strlen(prop_name), &x2apic,

2529                             sizeof (x2apic));
2530                         proc_num++;
2531                         break;
2532                 }
2533                 default:
2534                         if (kbm_debug)
2535                                 bop_printf(NULL, "SRAT type %d\n", item->Type);
2536                         break;
2537                 }
2538 
2539                 item = (ACPI_SUBTABLE_HEADER *)
2540                     (item->Length + (uintptr_t)item);
2541         }
2542 
2543         /*
2544          * The maximum physical address calculated from the SRAT table is more
2545          * accurate than that calculated from the MSCT table.
2546          */
2547         if (maxmem != 0) {
2548                 plat_dr_physmax = btop(maxmem);
2549         }
2550 }
2551 
2552 static void
2553 process_slit(ACPI_TABLE_SLIT *tp)
2554 {
2555 
2556         /*
2557          * Check the number of localities; if it's too huge, we just
2558          * return and locality enumeration code will handle this later,
2559          * if possible.
2560          *
2561          * Note that the size of the table is the square of the
2562          * number of localities; if the number of localities exceeds
2563          * UINT16_MAX, the table size may overflow an int when being
2564          * passed to bsetprop() below.
2565          */
2566         if (tp->LocalityCount >= SLIT_LOCALITIES_MAX)
2567                 return;
2568 
2569         bsetprop(SLIT_NUM_PROPNAME, strlen(SLIT_NUM_PROPNAME),
2570             &tp->LocalityCount, sizeof (tp->LocalityCount));
2571         bsetprop(SLIT_PROPNAME, strlen(SLIT_PROPNAME), &tp->Entry,
2572             tp->LocalityCount * tp->LocalityCount);
2573 }
2574 
2575 static ACPI_TABLE_MSCT *
2576 process_msct(ACPI_TABLE_MSCT *tp)
2577 {
2578         int last_seen = 0;
2579         int proc_num = 0;
2580         ACPI_MSCT_PROXIMITY *item, *end;
2581         extern uint64_t plat_dr_options;
2582 
2583         ASSERT(tp != NULL);
2584 
2585         end = (ACPI_MSCT_PROXIMITY *)(tp->Header.Length + (uintptr_t)tp);
2586         for (item = (void *)((uintptr_t)tp + tp->ProximityOffset);
2587             item < end;
2588             item = (void *)(item->Length + (uintptr_t)item)) {
2589                 /*
2590                  * Sanity check according to section 5.2.19.1 of ACPI 4.0.
2591                  * Revision     1


2743         enumerate_xen_cpus();
2744         if (DOMAIN_IS_INITDOMAIN(xen_info))
2745                 tp = find_fw_table(ACPI_SIG_MCFG);
2746 #endif /* __xpv */
2747         if (tp != NULL)
2748                 process_mcfg((ACPI_TABLE_MCFG *)tp);
2749 }
2750 
2751 /*
2752  * fake up a boot property for deferred early console output
2753  * this is used by both graphical boot and the (developer only)
2754  * USB serial console
2755  */
2756 void *
2757 defcons_init(size_t size)
2758 {
2759         static char *p = NULL;
2760 
2761         p = do_bsys_alloc(NULL, NULL, size, MMU_PAGESIZE);
2762         *p = 0;
2763         bsetprop("deferred-console-buf", strlen("deferred-console-buf") + 1,
2764             &p, sizeof (p));
2765         return (p);
2766 }
2767 
2768 /*ARGSUSED*/
2769 int
2770 boot_compinfo(int fd, struct compinfo *cbp)
2771 {
2772         cbp->iscmp = 0;
2773         cbp->blksize = MAXBSIZE;
2774         return (0);
2775 }
2776 
2777 #define BP_MAX_STRLEN   32
2778 
2779 /*
2780  * Get value for given boot property
2781  */
2782 int
2783 bootprop_getval(const char *prop_name, u_longlong_t *prop_value)
2784 {


  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/framebuffer.h>
  54 #include <sys/cmn_err.h>
  55 #include <sys/systm.h>
  56 #include <sys/promif.h>
  57 #include <sys/archsystm.h>
  58 #include <sys/x86_archext.h>
  59 #include <sys/kobj.h>
  60 #include <sys/privregs.h>
  61 #include <sys/sysmacros.h>
  62 #include <sys/ctype.h>
  63 #include <sys/fastboot.h>
  64 #ifdef __xpv
  65 #include <sys/hypervisor.h>
  66 #include <net/if.h>
  67 #endif
  68 #include <vm/kboot_mmu.h>
  69 #include <vm/hat_pte.h>
  70 #include <sys/kobj.h>
  71 #include <sys/kobj_lex.h>
  72 #include <sys/pci_cfgspace_impl.h>
  73 #include <sys/fastboot_impl.h>
  74 #include <sys/acpi/acconfig.h>
  75 #include <sys/acpi/acpi.h>
  76 #include <sys/ddipropdefs.h>      /* For DDI prop types */
  77 
  78 static int have_console = 0;    /* set once primitive console is initialized */
  79 static char *boot_args = "";
  80 
  81 /*
  82  * Debugging macros
  83  */
  84 static uint_t kbm_debug = 0;
  85 #define DBG_MSG(s)      { if (kbm_debug) bop_printf(NULL, "%s", s); }
  86 #define DBG(x)          { if (kbm_debug)                        \
  87         bop_printf(NULL, "%s is %" PRIx64 "\n", #x, (uint64_t)(x));     \
  88         }
  89 
  90 #define PUT_STRING(s) {                         \
  91         char *cp;                               \
  92         for (cp = (s); *cp; ++cp)               \
  93                 bcons_putchar(*cp);             \
  94         }
  95 
  96 /* callback to boot_fb to set shadow frame buffer */
  97 extern void boot_fb_shadow_init(bootops_t *);
  98 
  99 bootops_t bootop;       /* simple bootops we'll pass on to kernel */
 100 struct bsys_mem bm;
 101 
 102 /*
 103  * Boot info from "glue" code in low memory. xbootp is used by:
 104  *      do_bop_phys_alloc(), do_bsys_alloc() and boot_prop_finish().
 105  */
 106 static struct xboot_info *xbootp;
 107 static uintptr_t next_virt;     /* next available virtual address */
 108 static paddr_t next_phys;       /* next available physical address from dboot */
 109 static paddr_t high_phys = -(paddr_t)1; /* last used physical address */
 110 
 111 /*
 112  * buffer for vsnprintf for console I/O
 113  */
 114 #define BUFFERSIZE      512
 115 static char buffer[BUFFERSIZE];
 116 
 117 /*
 118  * stuff to store/report/manipulate boot property settings.
 119  */
 120 typedef struct bootprop {
 121         struct bootprop *bp_next;
 122         char *bp_name;
 123         int bp_flags;                   /* DDI prop type */
 124         uint_t bp_vlen;                 /* 0 for boolean */
 125         char *bp_value;
 126 } bootprop_t;
 127 
 128 static bootprop_t *bprops = NULL;
 129 static char *curr_page = NULL;          /* ptr to avail bprop memory */
 130 static int curr_space = 0;              /* amount of memory at curr_page */
 131 
 132 #ifdef __xpv
 133 start_info_t *xen_info;
 134 shared_info_t *HYPERVISOR_shared_info;
 135 #endif
 136 
 137 /*
 138  * some allocator statistics
 139  */
 140 static ulong_t total_bop_alloc_scratch = 0;
 141 static ulong_t total_bop_alloc_kernel = 0;
 142 
 143 static void build_firmware_properties(struct xboot_info *);
 144 


 341 do_bsys_free(bootops_t *bop, caddr_t virt, size_t size)
 342 {
 343         bop_printf(NULL, "do_bsys_free(virt=0x%p, size=0x%lx) ignored\n",
 344             (void *)virt, size);
 345 }
 346 
 347 /*
 348  * Old interface
 349  */
 350 /*ARGSUSED*/
 351 static caddr_t
 352 do_bsys_ealloc(bootops_t *bop, caddr_t virthint, size_t size,
 353     int align, int flags)
 354 {
 355         prom_panic("unsupported call to BOP_EALLOC()\n");
 356         return (0);
 357 }
 358 
 359 
 360 static void
 361 bsetprop(int flags, char *name, int nlen, void *value, int vlen)
 362 {
 363         uint_t size;
 364         uint_t need_size;
 365         bootprop_t *b;
 366 
 367         /*
 368          * align the size to 16 byte boundary
 369          */
 370         size = sizeof (bootprop_t) + nlen + 1 + vlen;
 371         size = (size + 0xf) & ~0xf;
 372         if (size > curr_space) {
 373                 need_size = (size + (MMU_PAGEOFFSET)) & MMU_PAGEMASK;
 374                 curr_page = do_bsys_alloc(NULL, 0, need_size, MMU_PAGESIZE);
 375                 curr_space = need_size;
 376         }
 377 
 378         /*
 379          * use a bootprop_t at curr_page and link into list
 380          */
 381         b = (bootprop_t *)curr_page;
 382         curr_page += sizeof (bootprop_t);
 383         curr_space -=  sizeof (bootprop_t);
 384         b->bp_next = bprops;
 385         bprops = b;
 386 
 387         /*
 388          * follow by name and ending zero byte
 389          */
 390         b->bp_name = curr_page;
 391         bcopy(name, curr_page, nlen);
 392         curr_page += nlen;
 393         *curr_page++ = 0;
 394         curr_space -= nlen + 1;
 395 
 396         /*
 397          * set the property type
 398          */
 399         b->bp_flags = flags & DDI_PROP_TYPE_MASK;
 400 
 401         /*
 402          * copy in value, but no ending zero byte
 403          */
 404         b->bp_value = curr_page;
 405         b->bp_vlen = vlen;
 406         if (vlen > 0) {
 407                 bcopy(value, curr_page, vlen);
 408                 curr_page += vlen;
 409                 curr_space -= vlen;
 410         }
 411 
 412         /*
 413          * align new values of curr_page, curr_space
 414          */
 415         while (curr_space & 0xf) {
 416                 ++curr_page;
 417                 --curr_space;
 418         }
 419 }
 420 
 421 static void
 422 bsetprops(char *name, char *value)
 423 {
 424         bsetprop(DDI_PROP_TYPE_STRING, name, strlen(name),
 425             value, strlen(value) + 1);
 426 }
 427 
 428 static void
 429 bsetprop32(char *name, uint32_t value)
 430 {
 431         bsetprop(DDI_PROP_TYPE_INT, name, strlen(name),
 432             (void *)&value, sizeof (value));
 433 }
 434 
 435 static void
 436 bsetprop64(char *name, uint64_t value)
 437 {
 438         bsetprop(DDI_PROP_TYPE_INT64, name, strlen(name),
 439             (void *)&value, sizeof (value));
 440 }
 441 
 442 static void
 443 bsetpropsi(char *name, int value)
 444 {
 445         char prop_val[32];
 446 
 447         (void) snprintf(prop_val, sizeof (prop_val), "%d", value);
 448         bsetprops(name, prop_val);
 449 }
 450 
 451 /*
 452  * to find the type of the value associated with this name
 453  */
 454 /*ARGSUSED*/
 455 int
 456 do_bsys_getproptype(bootops_t *bop, const char *name)
 457 {
 458         bootprop_t *b;
 459 
 460         for (b = bprops; b; b = b->bp_next) {
 461                 if (strcmp(name, b->bp_name) != 0)
 462                         continue;
 463                 return (b->bp_flags);
 464         }
 465         return (-1);
 466 }
 467 
 468 /*
 469  * to find the size of the buffer to allocate
 470  */
 471 /*ARGSUSED*/
 472 int
 473 do_bsys_getproplen(bootops_t *bop, const char *name)
 474 {
 475         bootprop_t *b;
 476 
 477         for (b = bprops; b; b = b->bp_next) {
 478                 if (strcmp(name, b->bp_name) != 0)
 479                         continue;
 480                 return (b->bp_vlen);
 481         }
 482         return (-1);
 483 }
 484 
 485 /*
 486  * get the value associated with this name
 487  */
 488 /*ARGSUSED*/


 588 
 589         for (i = 0; i < size; i++) {
 590                 if (value[i] == '\0')
 591                         return (i != (size - 1));
 592 
 593                 if (!isprint(value[i]))
 594                         return (B_TRUE);
 595         }
 596         return (B_FALSE);
 597 }
 598 
 599 /*
 600  * Print out information about all boot properties.
 601  * buffer is pointer to pre-allocated space to be used as temporary
 602  * space for property values.
 603  */
 604 static void
 605 boot_prop_display(char *buffer)
 606 {
 607         char *name = "";
 608         int i, len, flags, *buf32;
 609         uint64_t *buf64;
 610 
 611         bop_printf(NULL, "\nBoot properties:\n");
 612 
 613         while ((name = do_bsys_nextprop(NULL, name)) != NULL) {
 614                 bop_printf(NULL, "\t0x%p %s = ", (void *)name, name);
 615                 (void) do_bsys_getprop(NULL, name, buffer);
 616                 len = do_bsys_getproplen(NULL, name);
 617                 flags = do_bsys_getproptype(NULL, name);
 618                 bop_printf(NULL, "len=%d ", len);
 619 
 620                 switch (flags) {
 621                 case DDI_PROP_TYPE_INT:
 622                         len = len / sizeof (int);
 623                         buf32 = (int *)buffer;
 624                         for (i = 0; i < len; i++) {
 625                                 bop_printf(NULL, "%08x", buf32[i]);
 626                                 if (i < len - 1)
 627                                         bop_printf(NULL, ".");
 628                         }
 629                         break;
 630                 case DDI_PROP_TYPE_STRING:
 631                         bop_printf(NULL, buffer);
 632                         break;
 633                 case DDI_PROP_TYPE_INT64:
 634                         len = len / sizeof (uint64_t);
 635                         buf64 = (uint64_t *)buffer;
 636                         for (i = 0; i < len; i++) {
 637                                 bop_printf(NULL, "%016" PRIx64, buf64[i]);
 638                                 if (i < len - 1)
 639                                         bop_printf(NULL, ".");
 640                         }
 641                         break;
 642                 default:
 643                         if (!unprintable(buffer, len)) {
 644                                 buffer[len] = 0;
 645                                 bop_printf(NULL, "%s", buffer);
 646                                 break;
 647                         }
 648                         for (i = 0; i < len; i++) {
 649                                 bop_printf(NULL, "%02x", buffer[i] & 0xff);
 650                                 if (i < len - 1)
 651                                         bop_printf(NULL, ".");
 652                         }
 653                         break;
 654                 }
 655                 bop_printf(NULL, "\n");
 656         }
 657 }
 658 
 659 /*
 660  * 2nd part of building the table of boot properties. This includes:
 661  * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
 662  *
 663  * lines look like one of:
 664  * ^$
 665  * ^# comment till end of line
 666  * setprop name 'value'
 667  * setprop name value
 668  * setprop name "value"
 669  *
 670  * we do single character I/O since this is really just looking at memory
 671  */
 672 void
 673 boot_prop_finish(void)
 674 {


 762                 }
 763                 name[n_len] = 0;
 764                 if (v_len > 0)
 765                         value[v_len] = 0;
 766                 else
 767                         continue;
 768 
 769                 /*
 770                  * ignore "boot-file" property, it's now meaningless
 771                  */
 772                 if (strcmp(name, "boot-file") == 0)
 773                         continue;
 774                 if (strcmp(name, "boot-args") == 0 &&
 775                     strlen(boot_args) > 0)
 776                         continue;
 777 
 778                 /*
 779                  * If a property was explicitly set on the command line
 780                  * it will override a setting in bootenv.rc
 781                  */
 782                 if (do_bsys_getproplen(NULL, name) >= 0)
 783                         continue;
 784 
 785                 bsetprops(name, value);
 786         }
 787 done:
 788         if (fd >= 0)
 789                 (void) BRD_CLOSE(bfs_ops, fd);
 790 
 791         /*
 792          * Check if we have to limit the boot time allocator
 793          */
 794         if (do_bsys_getproplen(NULL, "physmem") != -1 &&
 795             do_bsys_getprop(NULL, "physmem", line) >= 0 &&
 796             parse_value(line, &lvalue) != -1) {
 797                 if (0 < lvalue && (lvalue < physmem || physmem == 0)) {
 798                         physmem = (pgcnt_t)lvalue;
 799                         DBG(physmem);
 800                 }
 801         }
 802         early_allocation = 0;
 803 
 804         /*
 805          * check to see if we have to override the default value of the console


1039 
1040         DBG_MSG("VBD bootpath set to ");
1041         DBG_MSG(vbdpath);
1042         DBG_MSG("\n");
1043 }
1044 
1045 /*
1046  * parse the xpv-nfsroot property to create properties used by
1047  * nfs_mountroot.
1048  */
1049 static void
1050 xen_nfsroot_props(char *s)
1051 {
1052         char *prop_map[] = {
1053                 BP_SERVER_IP,   /* server IP address */
1054                 BP_SERVER_NAME, /* server hostname */
1055                 BP_SERVER_PATH, /* root path */
1056         };
1057         int n_prop = sizeof (prop_map) / sizeof (prop_map[0]);
1058 
1059         bsetprops("fstype", "nfs");
1060 
1061         xen_parse_props(s, prop_map, n_prop);
1062 
1063         /*
1064          * If a server name wasn't specified, use a default.
1065          */
1066         if (do_bsys_getproplen(NULL, BP_SERVER_NAME) == -1)
1067                 bsetprops(BP_SERVER_NAME, "unknown");
1068 }
1069 
1070 /*
1071  * Extract our IP address, etc. from the "xpv-ip" property.
1072  */
1073 static void
1074 xen_ip_props(char *s)
1075 {
1076         char *prop_map[] = {
1077                 BP_HOST_IP,             /* IP address */
1078                 NULL,                   /* NFS server IP address (ignored in */
1079                                         /* favour of xpv-nfsroot) */


1405 #ifndef __xpv
1406         static int stdout_val = 0;
1407         uchar_t boot_device;
1408         char str[3];
1409 #endif
1410 
1411         /*
1412          * These have to be done first, so that kobj_mount_root() works
1413          */
1414         DBG_MSG("Building boot properties\n");
1415         propbuf = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, 0);
1416         DBG((uintptr_t)propbuf);
1417         if (xbp->bi_module_cnt > 0) {
1418                 bm = xbp->bi_modules;
1419                 rdbm = NULL;
1420                 for (midx = i = 0; i < xbp->bi_module_cnt; i++) {
1421                         if (bm[i].bm_type == BMT_ROOTFS) {
1422                                 rdbm = &bm[i];
1423                                 continue;
1424                         }
1425                         if (bm[i].bm_type == BMT_HASH ||
1426                             bm[i].bm_type == BMT_FONT ||
1427                             bm[i].bm_name == NULL)
1428                                 continue;
1429 
1430                         if (bm[i].bm_type == BMT_ENV) {
1431                                 if (benv == NULL)
1432                                         benv = &bm[i];
1433                                 else
1434                                         continue;
1435                         }
1436 
1437                         (void) snprintf(modid, sizeof (modid),
1438                             "module-name-%u", midx);
1439                         bsetprops(modid, (char *)bm[i].bm_name);
1440                         (void) snprintf(modid, sizeof (modid),
1441                             "module-addr-%u", midx);
1442                         bsetprop64(modid, (uint64_t)(uintptr_t)bm[i].bm_addr);
1443                         (void) snprintf(modid, sizeof (modid),
1444                             "module-size-%u", midx);
1445                         bsetprop64(modid, (uint64_t)bm[i].bm_size);
1446                         ++midx;
1447                 }


1622 
1623                                 /*
1624                                  * In the quote accept any character,
1625                                  * but look for ending quote.
1626                                  */
1627                                 if (quoted) {
1628                                         if (value[value_len] == quoted)
1629                                                 quoted = 0;
1630                                         continue;
1631                                 }
1632 
1633                                 /*
1634                                  * a comma or white space ends the value
1635                                  */
1636                                 if (value[value_len] == ',' ||
1637                                     ISSPACE(value[value_len]))
1638                                         break;
1639                         }
1640 
1641                         if (value_len == 0) {
1642                                 bsetprop(DDI_PROP_TYPE_ANY, name, name_len,
1643                                     NULL, 0);
1644                         } else {
1645                                 char *v = value;
1646                                 int l = value_len;
1647                                 if (v[0] == v[l - 1] &&
1648                                     (v[0] == '\'' || v[0] == '"')) {
1649                                         ++v;
1650                                         l -= 2;
1651                                 }
1652                                 bcopy(v, propbuf, l);
1653                                 propbuf[l] = '\0';
1654                                 bsetprop(DDI_PROP_TYPE_STRING, name, name_len,
1655                                     propbuf, l + 1);
1656                         }
1657                         name = value + value_len;
1658                         while (*name == ',')
1659                                 ++name;
1660                 }
1661         }
1662 
1663         /*
1664          * set boot-args property
1665          * 1275 name is bootargs, so set
1666          * that too
1667          */
1668         bsetprops("boot-args", boot_args);
1669         bsetprops("bootargs", boot_args);
1670 
1671         process_boot_environment(benv);
1672 
1673 #ifndef __xpv
1674         /*
1675          * Build boot command line for Fast Reboot


1694                 if (mbi != NULL && mbi->flags & MB_INFO_BOOTDEV) {
1695                         boot_device = mbi->boot_device >> 24;
1696                         if (boot_device == 0x20)
1697                                 netboot++;
1698                         str[0] = (boot_device >> 4) + '0';
1699                         str[1] = (boot_device & 0xf) + '0';
1700                         str[2] = 0;
1701                         bsetprops("bios-boot-device", str);
1702                 } else {
1703                         netboot = 1;
1704                 }
1705 
1706                 /*
1707                  * In the netboot case, drives_info is overloaded with the
1708                  * dhcp ack. This is not multiboot compliant and requires
1709                  * special pxegrub!
1710                  */
1711                 if (netboot && mbi->drives_length != 0) {
1712                         sip = (struct sol_netinfo *)(uintptr_t)mbi->drives_addr;
1713                         if (sip->sn_infotype == SN_TYPE_BOOTP)
1714                                 bsetprop(DDI_PROP_TYPE_BYTE,
1715                                     "bootp-response",
1716                                     sizeof ("bootp-response"),
1717                                     (void *)(uintptr_t)mbi->drives_addr,
1718                                     mbi->drives_length);
1719                         else if (sip->sn_infotype == SN_TYPE_RARP)
1720                                 setup_rarp_props(sip);
1721                 }
1722         } else {
1723                 multiboot2_info_header_t *mbi = xbp->bi_mb_info;
1724                 multiboot_tag_bootdev_t *bootdev = NULL;
1725                 multiboot_tag_network_t *netdev = NULL;
1726 
1727                 if (mbi != NULL) {
1728                         bootdev = dboot_multiboot2_find_tag(mbi,
1729                             MULTIBOOT_TAG_TYPE_BOOTDEV);
1730                         netdev = dboot_multiboot2_find_tag(mbi,
1731                             MULTIBOOT_TAG_TYPE_NETWORK);
1732                 }
1733                 if (bootdev != NULL) {
1734                         DBG(bootdev->mb_biosdev);
1735                         boot_device = bootdev->mb_biosdev;
1736                         str[0] = (boot_device >> 4) + '0';
1737                         str[1] = (boot_device & 0xf) + '0';
1738                         str[2] = 0;
1739                         bsetprops("bios-boot-device", str);
1740                 }
1741                 if (netdev != NULL) {
1742                         bsetprop(DDI_PROP_TYPE_BYTE,
1743                             "bootp-response", sizeof ("bootp-response"),
1744                             (void *)(uintptr_t)netdev->mb_dhcpack,
1745                             netdev->mb_size -
1746                             sizeof (multiboot_tag_network_t));
1747                 }
1748         }
1749 
1750         bsetprop32("stdout", stdout_val);

1751 #endif /* __xpv */
1752 
1753         /*
1754          * more conjured up values for made up things....
1755          */
1756 #if defined(__xpv)
1757         bsetprops("mfg-name", "i86xpv");
1758         bsetprops("impl-arch-name", "i86xpv");
1759 #else
1760         bsetprops("mfg-name", "i86pc");
1761         bsetprops("impl-arch-name", "i86pc");
1762 #endif
1763 
1764         /*
1765          * Build firmware-provided system properties
1766          */
1767         build_firmware_properties(xbp);
1768 
1769         /*
1770          * XXPV


2081         bops->bsys_ealloc = do_bsys_ealloc;
2082 
2083 #ifdef __xpv
2084         /*
2085          * On domain 0 we need to free up some physical memory that is
2086          * usable for DMA. Since GRUB loaded the boot_archive, it is
2087          * sitting in low MFN memory. We'll relocated the boot archive
2088          * pages to high PFN memory.
2089          */
2090         if (DOMAIN_IS_INITDOMAIN(xen_info))
2091                 relocate_boot_archive(xbp);
2092 #endif
2093 
2094 #ifndef __xpv
2095         /*
2096          * Install an IDT to catch early pagefaults (shouldn't have any).
2097          * Also needed for kmdb.
2098          */
2099         bop_idt_init();
2100 #endif
2101         /* Set up the shadow fb for framebuffer console */
2102         boot_fb_shadow_init(bops);
2103 
2104         /*
2105          * Start building the boot properties from the command line
2106          */
2107         DBG_MSG("Initializing boot properties:\n");
2108         build_boot_properties(xbp);
2109 
2110         if (find_boot_prop("prom_debug") || kbm_debug) {
2111                 char *value;
2112 
2113                 value = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, MMU_PAGESIZE);
2114                 boot_prop_display(value);
2115         }
2116 
2117         /*
2118          * jump into krtld...
2119          */
2120         _kobj_boot(&bop_sysp, NULL, bops, NULL);
2121 }
2122 


2362                 }
2363         }
2364         return (NULL);
2365 }
2366 
2367 static void
2368 process_mcfg(ACPI_TABLE_MCFG *tp)
2369 {
2370         ACPI_MCFG_ALLOCATION *cfg_baap;
2371         char *cfg_baa_endp;
2372         int64_t ecfginfo[4];
2373 
2374         cfg_baap = (ACPI_MCFG_ALLOCATION *)((uintptr_t)tp + sizeof (*tp));
2375         cfg_baa_endp = ((char *)tp) + tp->Header.Length;
2376         while ((char *)cfg_baap < cfg_baa_endp) {
2377                 if (cfg_baap->Address != 0 && cfg_baap->PciSegment == 0) {
2378                         ecfginfo[0] = cfg_baap->Address;
2379                         ecfginfo[1] = cfg_baap->PciSegment;
2380                         ecfginfo[2] = cfg_baap->StartBusNumber;
2381                         ecfginfo[3] = cfg_baap->EndBusNumber;
2382                         bsetprop(DDI_PROP_TYPE_INT64,
2383                             MCFG_PROPNAME, strlen(MCFG_PROPNAME),
2384                             ecfginfo, sizeof (ecfginfo));
2385                         break;
2386                 }
2387                 cfg_baap++;
2388         }
2389 }
2390 
2391 #ifndef __xpv
2392 static void
2393 process_madt_entries(ACPI_TABLE_MADT *tp, uint32_t *cpu_countp,
2394     uint32_t *cpu_possible_countp, uint32_t *cpu_apicid_array)
2395 {
2396         ACPI_SUBTABLE_HEADER *item, *end;
2397         uint32_t cpu_count = 0;
2398         uint32_t cpu_possible_count = 0;
2399 
2400         /*
2401          * Determine number of CPUs and keep track of "final" APIC ID
2402          * for each CPU by walking through ACPI MADT processor list
2403          */


2451         uint32_t cpu_count = 0;
2452         uint32_t cpu_possible_count = 0;
2453         uint32_t *cpu_apicid_array; /* x2APIC ID is 32bit! */
2454 
2455         if (tp != NULL) {
2456                 /* count cpu's */
2457                 process_madt_entries(tp, &cpu_count, &cpu_possible_count, NULL);
2458 
2459                 cpu_apicid_array = (uint32_t *)do_bsys_alloc(NULL, NULL,
2460                     cpu_count * sizeof (*cpu_apicid_array), MMU_PAGESIZE);
2461                 if (cpu_apicid_array == NULL)
2462                         bop_panic("Not enough memory for APIC ID array");
2463 
2464                 /* copy IDs */
2465                 process_madt_entries(tp, NULL, NULL, cpu_apicid_array);
2466 
2467                 /*
2468                  * Make boot property for array of "final" APIC IDs for each
2469                  * CPU
2470                  */
2471                 bsetprop(DDI_PROP_TYPE_INT,
2472                     BP_CPU_APICID_ARRAY, strlen(BP_CPU_APICID_ARRAY),
2473                     cpu_apicid_array, cpu_count * sizeof (*cpu_apicid_array));
2474         }
2475 
2476         /*
2477          * Check whether property plat-max-ncpus is already set.
2478          */
2479         if (do_bsys_getproplen(NULL, PLAT_MAX_NCPUS_NAME) < 0) {
2480                 /*
2481                  * Set plat-max-ncpus to number of maximum possible CPUs given
2482                  * in MADT if it hasn't been set.
2483                  * There's no formal way to detect max possible CPUs supported
2484                  * by platform according to ACPI spec3.0b. So current CPU
2485                  * hotplug implementation expects that all possible CPUs will
2486                  * have an entry in MADT table and set plat-max-ncpus to number
2487                  * of entries in MADT.
2488                  * With introducing of ACPI4.0, Maximum System Capability Table
2489                  * (MSCT) provides maximum number of CPUs supported by platform.
2490                  * If MSCT is unavailable, fall back to old way.
2491                  */
2492                 if (tp != NULL)


2545 
2546         proc_num = mem_num = 0;
2547         end = (ACPI_SUBTABLE_HEADER *)(tp->Header.Length + (uintptr_t)tp);
2548         item = (ACPI_SUBTABLE_HEADER *)((uintptr_t)tp + sizeof (*tp));
2549         while (item < end) {
2550                 switch (item->Type) {
2551                 case ACPI_SRAT_TYPE_CPU_AFFINITY: {
2552                         ACPI_SRAT_CPU_AFFINITY *cpu =
2553                             (ACPI_SRAT_CPU_AFFINITY *) item;
2554 
2555                         if (!(cpu->Flags & ACPI_SRAT_CPU_ENABLED))
2556                                 break;
2557                         processor.domain = cpu->ProximityDomainLo;
2558                         for (i = 0; i < 3; i++)
2559                                 processor.domain +=
2560                                     cpu->ProximityDomainHi[i] << ((i + 1) * 8);
2561                         processor.apic_id = cpu->ApicId;
2562                         processor.sapic_id = cpu->LocalSapicEid;
2563                         (void) snprintf(prop_name, 30, "acpi-srat-processor-%d",
2564                             proc_num);
2565                         bsetprop(DDI_PROP_TYPE_INT,
2566                             prop_name, strlen(prop_name), &processor,
2567                             sizeof (processor));
2568                         proc_num++;
2569                         break;
2570                 }
2571                 case ACPI_SRAT_TYPE_MEMORY_AFFINITY: {
2572                         ACPI_SRAT_MEM_AFFINITY *mem =
2573                             (ACPI_SRAT_MEM_AFFINITY *)item;
2574 
2575                         if (!(mem->Flags & ACPI_SRAT_MEM_ENABLED))
2576                                 break;
2577                         memory.domain = mem->ProximityDomain;
2578                         memory.addr = mem->BaseAddress;
2579                         memory.length = mem->Length;
2580                         memory.flags = mem->Flags;
2581                         (void) snprintf(prop_name, 30, "acpi-srat-memory-%d",
2582                             mem_num);
2583                         bsetprop(DDI_PROP_TYPE_INT,
2584                             prop_name, strlen(prop_name), &memory,
2585                             sizeof (memory));
2586                         if ((mem->Flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) &&
2587                             (memory.addr + memory.length > maxmem)) {
2588                                 maxmem = memory.addr + memory.length;
2589                         }
2590                         mem_num++;
2591                         break;
2592                 }
2593                 case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY: {
2594                         ACPI_SRAT_X2APIC_CPU_AFFINITY *x2cpu =
2595                             (ACPI_SRAT_X2APIC_CPU_AFFINITY *) item;
2596 
2597                         if (!(x2cpu->Flags & ACPI_SRAT_CPU_ENABLED))
2598                                 break;
2599                         x2apic.domain = x2cpu->ProximityDomain;
2600                         x2apic.x2apic_id = x2cpu->ApicId;
2601                         (void) snprintf(prop_name, 30, "acpi-srat-processor-%d",
2602                             proc_num);
2603                         bsetprop(DDI_PROP_TYPE_INT,
2604                             prop_name, strlen(prop_name), &x2apic,
2605                             sizeof (x2apic));
2606                         proc_num++;
2607                         break;
2608                 }
2609                 default:
2610                         if (kbm_debug)
2611                                 bop_printf(NULL, "SRAT type %d\n", item->Type);
2612                         break;
2613                 }
2614 
2615                 item = (ACPI_SUBTABLE_HEADER *)
2616                     (item->Length + (uintptr_t)item);
2617         }
2618 
2619         /*
2620          * The maximum physical address calculated from the SRAT table is more
2621          * accurate than that calculated from the MSCT table.
2622          */
2623         if (maxmem != 0) {
2624                 plat_dr_physmax = btop(maxmem);
2625         }
2626 }
2627 
2628 static void
2629 process_slit(ACPI_TABLE_SLIT *tp)
2630 {
2631 
2632         /*
2633          * Check the number of localities; if it's too huge, we just
2634          * return and locality enumeration code will handle this later,
2635          * if possible.
2636          *
2637          * Note that the size of the table is the square of the
2638          * number of localities; if the number of localities exceeds
2639          * UINT16_MAX, the table size may overflow an int when being
2640          * passed to bsetprop() below.
2641          */
2642         if (tp->LocalityCount >= SLIT_LOCALITIES_MAX)
2643                 return;
2644 
2645         bsetprop64(SLIT_NUM_PROPNAME, tp->LocalityCount);
2646         bsetprop(DDI_PROP_TYPE_BYTE,
2647             SLIT_PROPNAME, strlen(SLIT_PROPNAME), &tp->Entry,
2648             tp->LocalityCount * tp->LocalityCount);
2649 }
2650 
2651 static ACPI_TABLE_MSCT *
2652 process_msct(ACPI_TABLE_MSCT *tp)
2653 {
2654         int last_seen = 0;
2655         int proc_num = 0;
2656         ACPI_MSCT_PROXIMITY *item, *end;
2657         extern uint64_t plat_dr_options;
2658 
2659         ASSERT(tp != NULL);
2660 
2661         end = (ACPI_MSCT_PROXIMITY *)(tp->Header.Length + (uintptr_t)tp);
2662         for (item = (void *)((uintptr_t)tp + tp->ProximityOffset);
2663             item < end;
2664             item = (void *)(item->Length + (uintptr_t)item)) {
2665                 /*
2666                  * Sanity check according to section 5.2.19.1 of ACPI 4.0.
2667                  * Revision     1


2819         enumerate_xen_cpus();
2820         if (DOMAIN_IS_INITDOMAIN(xen_info))
2821                 tp = find_fw_table(ACPI_SIG_MCFG);
2822 #endif /* __xpv */
2823         if (tp != NULL)
2824                 process_mcfg((ACPI_TABLE_MCFG *)tp);
2825 }
2826 
2827 /*
2828  * fake up a boot property for deferred early console output
2829  * this is used by both graphical boot and the (developer only)
2830  * USB serial console
2831  */
2832 void *
2833 defcons_init(size_t size)
2834 {
2835         static char *p = NULL;
2836 
2837         p = do_bsys_alloc(NULL, NULL, size, MMU_PAGESIZE);
2838         *p = 0;
2839         bsetprop32("deferred-console-buf", (uint32_t)((uintptr_t)&p));

2840         return (p);
2841 }
2842 
2843 /*ARGSUSED*/
2844 int
2845 boot_compinfo(int fd, struct compinfo *cbp)
2846 {
2847         cbp->iscmp = 0;
2848         cbp->blksize = MAXBSIZE;
2849         return (0);
2850 }
2851 
2852 #define BP_MAX_STRLEN   32
2853 
2854 /*
2855  * Get value for given boot property
2856  */
2857 int
2858 bootprop_getval(const char *prop_name, u_longlong_t *prop_value)
2859 {