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.
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.
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]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2010, Intel Corporation.
27 * All rights reserved.
29 * Copyright 2013 Joyent, Inc. All rights reserved.
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.
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>
59 #include <sys/privregs.h>
60 #include <sys/sysmacros.h>
61 #include <sys/ctype.h>
62 #include <sys/fastboot.h>
64 #include <sys/hypervisor.h>
67 #include <vm/kboot_mmu.h>
68 #include <vm/hat_pte.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>
76 static int have_console
= 0; /* set once primitive console is initialized */
77 static char *boot_args
= "";
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)); \
88 #define PUT_STRING(s) { \
90 for (cp = (s); *cp; ++cp) \
94 bootops_t bootop
; /* simple bootops we'll pass on to kernel */
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().
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 */
107 * buffer for vsnprintf for console I/O
109 #define BUFFERSIZE 512
110 static char buffer
[BUFFERSIZE
];
113 * stuff to store/report/manipulate boot property settings.
115 typedef struct bootprop
{
116 struct bootprop
*bp_next
;
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 */
127 start_info_t
*xen_info
;
128 shared_info_t
*HYPERVISOR_shared_info
;
132 * some allocator statistics
134 static ulong_t total_bop_alloc_scratch
= 0;
135 static ulong_t total_bop_alloc_kernel
= 0;
137 static void build_firmware_properties(struct xboot_info
*);
139 static int early_allocation
= 1;
141 int force_fastreboot
= 0;
142 volatile int fastreboot_onpanic
= 0;
143 int post_fastreboot
= 0;
145 volatile int fastreboot_capable
= 0;
147 volatile int fastreboot_capable
= 1;
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.
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
];
163 * Turn off fastreboot_onpanic to avoid panic loop.
165 char fastreboot_onpanic_cmdline
[FASTBOOT_SAVED_CMDLINE_LEN
];
166 static const char fastreboot_onpanic_args
[] = " -B fastreboot_onpanic=0";
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
173 ACPI_TABLE_SRAT
*srat_ptr
= NULL
;
174 ACPI_TABLE_SLIT
*slit_ptr
= NULL
;
175 ACPI_TABLE_MSCT
*msct_ptr
= NULL
;
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.
182 #define SLIT_LOCALITIES_MAX (4096)
184 #define SLIT_NUM_PROPNAME "acpi-slit-localities"
185 #define SLIT_PROPNAME "acpi-slit"
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.
193 do_bop_phys_alloc(uint64_t size
, uint64_t align
)
198 struct memlist
*ml
= (struct memlist
*)xbootp
->bi_phys_install
;
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.
206 if (physmem
!= 0 && high_phys
> pfn_to_pa(physmem
))
207 high_phys
= pfn_to_pa(physmem
);
210 * find the lowest or highest available memory in physinstalled
211 * On 32 bit avoid physmem above 4Gig if PAE isn't enabled
214 if (xbootp
->bi_use_pae
== 0 && high_phys
> FOUR_GIG
)
215 high_phys
= FOUR_GIG
;
219 * find the highest available memory in physinstalled
221 size
= P2ROUNDUP(size
, align
);
222 for (; ml
; ml
= ml
->ml_next
) {
223 start
= P2ROUNDUP(ml
->ml_address
, align
);
224 end
= P2ALIGN(ml
->ml_address
+ ml
->ml_size
, align
);
225 if (start
< next_phys
)
226 start
= P2ROUNDUP(next_phys
, align
);
228 end
= P2ALIGN(high_phys
, align
);
232 if (end
- start
< size
)
236 * Early allocations need to use low memory, since
237 * physmem might be further limited by bootenv.rc
239 if (early_allocation
) {
240 if (pa
== 0 || start
< pa
)
248 if (early_allocation
)
249 next_phys
= pa
+ size
;
254 bop_panic("do_bop_phys_alloc(0x%" PRIx64
", 0x%" PRIx64
255 ") Out of memory\n", size
, align
);
260 alloc_vaddr(size_t size
, paddr_t align
)
264 next_virt
= P2ROUNDUP(next_virt
, (uintptr_t)align
);
265 rv
= (uintptr_t)next_virt
;
271 * Allocate virtual memory. The size is always rounded up to a multiple
277 do_bsys_alloc(bootops_t
*bop
, caddr_t virthint
, size_t size
, int align
)
279 paddr_t a
= align
; /* same type as pa for masking */
283 ssize_t s
; /* the aligned size */
285 uint_t is_kernel
= (virthint
!= 0);
287 if (a
< MMU_PAGESIZE
)
290 prom_panic("do_bsys_alloc() incorrect alignment");
291 size
= P2ROUNDUP(size
, MMU_PAGESIZE
);
294 * Use the next aligned virtual address if we weren't given one.
296 if (virthint
== NULL
) {
297 virthint
= (caddr_t
)alloc_vaddr(size
, a
);
298 total_bop_alloc_scratch
+= size
;
300 total_bop_alloc_kernel
+= size
;
304 * allocate the physical memory
306 pa
= do_bop_phys_alloc(size
, a
);
309 * Add the mappings to the page tables, try large pages first.
311 va
= (uintptr_t)virthint
;
314 pgsize
= xbootp
->bi_use_pae
? TWO_MEG
: FOUR_MEG
;
315 if (xbootp
->bi_use_largepage
&& a
== pgsize
) {
316 while (IS_P2ALIGNED(pa
, pgsize
) && IS_P2ALIGNED(va
, pgsize
) &&
318 kbm_map(va
, pa
, level
, is_kernel
);
326 * Map remaining pages use small mappings
329 pgsize
= MMU_PAGESIZE
;
331 kbm_map(va
, pa
, level
, is_kernel
);
340 * Free virtual memory - we'll just ignore these.
344 do_bsys_free(bootops_t
*bop
, caddr_t virt
, size_t size
)
346 bop_printf(NULL
, "do_bsys_free(virt=0x%p, size=0x%lx) ignored\n",
355 do_bsys_ealloc(bootops_t
*bop
, caddr_t virthint
, size_t size
,
356 int align
, int flags
)
358 prom_panic("unsupported call to BOP_EALLOC()\n");
364 bsetprop(char *name
, int nlen
, void *value
, int vlen
)
371 * align the size to 16 byte boundary
373 size
= sizeof (bootprop_t
) + nlen
+ 1 + vlen
;
374 size
= (size
+ 0xf) & ~0xf;
375 if (size
> curr_space
) {
376 need_size
= (size
+ (MMU_PAGEOFFSET
)) & MMU_PAGEMASK
;
377 curr_page
= do_bsys_alloc(NULL
, 0, need_size
, MMU_PAGESIZE
);
378 curr_space
= need_size
;
382 * use a bootprop_t at curr_page and link into list
384 b
= (bootprop_t
*)curr_page
;
385 curr_page
+= sizeof (bootprop_t
);
386 curr_space
-= sizeof (bootprop_t
);
391 * follow by name and ending zero byte
393 b
->bp_name
= curr_page
;
394 bcopy(name
, curr_page
, nlen
);
397 curr_space
-= nlen
+ 1;
400 * copy in value, but no ending zero byte
402 b
->bp_value
= curr_page
;
405 bcopy(value
, curr_page
, vlen
);
411 * align new values of curr_page, curr_space
413 while (curr_space
& 0xf) {
420 bsetprops(char *name
, char *value
)
422 bsetprop(name
, strlen(name
), value
, strlen(value
) + 1);
426 bsetprop64(char *name
, uint64_t value
)
428 bsetprop(name
, strlen(name
), (void *)&value
, sizeof (value
));
432 bsetpropsi(char *name
, int value
)
436 (void) snprintf(prop_val
, sizeof (prop_val
), "%d", value
);
437 bsetprops(name
, prop_val
);
441 * to find the size of the buffer to allocate
445 do_bsys_getproplen(bootops_t
*bop
, const char *name
)
449 for (b
= bprops
; b
; b
= b
->bp_next
) {
450 if (strcmp(name
, b
->bp_name
) != 0)
458 * get the value associated with this name
462 do_bsys_getprop(bootops_t
*bop
, const char *name
, void *value
)
466 for (b
= bprops
; b
; b
= b
->bp_next
) {
467 if (strcmp(name
, b
->bp_name
) != 0)
469 bcopy(b
->bp_value
, value
, b
->bp_vlen
);
476 * get the name of the next property in succession from the standalone
480 do_bsys_nextprop(bootops_t
*bop
, char *name
)
485 * A null name is a special signal for the 1st boot property
487 if (name
== NULL
|| strlen(name
) == 0) {
490 return (bprops
->bp_name
);
493 for (b
= bprops
; b
; b
= b
->bp_next
) {
494 if (name
!= b
->bp_name
)
505 * Parse numeric value from a string. Understands decimal, hex, octal, - and ~
508 parse_value(char *p
, uint64_t *retval
)
516 if (*p
== '-' || *p
== '~')
523 if (*p
== 'x' || *p
== 'X') {
532 if ('0' <= *p
&& *p
<= '9')
534 else if ('a' <= *p
&& *p
<= 'f')
535 digit
= 10 + *p
- 'a';
536 else if ('A' <= *p
&& *p
<= 'F')
537 digit
= 10 + *p
- 'A';
542 tmp
= tmp
* radix
+ digit
;
547 else if (adjust
== '~')
554 unprintable(char *value
, int size
)
558 if (size
<= 0 || value
[0] == '\0')
561 for (i
= 0; i
< size
; i
++) {
562 if (value
[i
] == '\0')
563 return (i
!= (size
- 1));
565 if (!isprint(value
[i
]))
572 * Print out information about all boot properties.
573 * buffer is pointer to pre-allocated space to be used as temporary
574 * space for property values.
577 boot_prop_display(char *buffer
)
582 bop_printf(NULL
, "\nBoot properties:\n");
584 while ((name
= do_bsys_nextprop(NULL
, name
)) != NULL
) {
585 bop_printf(NULL
, "\t0x%p %s = ", (void *)name
, name
);
586 (void) do_bsys_getprop(NULL
, name
, buffer
);
587 len
= do_bsys_getproplen(NULL
, name
);
588 bop_printf(NULL
, "len=%d ", len
);
589 if (!unprintable(buffer
, len
)) {
591 bop_printf(NULL
, "%s\n", buffer
);
594 for (i
= 0; i
< len
; i
++) {
595 bop_printf(NULL
, "%02x", buffer
[i
] & 0xff);
597 bop_printf(NULL
, ".");
599 bop_printf(NULL
, "\n");
604 * 2nd part of building the table of boot properties. This includes:
605 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
607 * lines look like one of:
609 * ^# comment till end of line
610 * setprop name 'value'
612 * setprop name "value"
614 * we do single character I/O since this is really just looking at memory
617 boot_prop_finish(void)
627 char *inputdev
; /* these override the command line if serial ports */
634 if (!DOMAIN_IS_INITDOMAIN(xen_info
))
638 DBG_MSG("Opening /boot/solaris/bootenv.rc\n");
639 fd
= BRD_OPEN(bfs_ops
, "/boot/solaris/bootenv.rc", 0);
642 line
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
649 bytes_read
= BRD_READ(bfs_ops
, fd
, line
+ c
, 1);
650 if (bytes_read
== 0) {
661 * ignore comment lines
664 while (ISSPACE(line
[c
]))
666 if (line
[c
] == '#' || line
[c
] == 0)
670 * must have "setprop " or "setprop\t"
672 if (strncmp(line
+ c
, "setprop ", 8) != 0 &&
673 strncmp(line
+ c
, "setprop\t", 8) != 0)
676 while (ISSPACE(line
[c
]))
682 * gather up the property name
686 while (line
[c
] && !ISSPACE(line
[c
]))
690 * gather up the value, if any
694 while (ISSPACE(line
[c
]))
698 while (line
[c
] && !ISSPACE(line
[c
]))
702 if (v_len
>= 2 && value
[0] == value
[v_len
- 1] &&
703 (value
[0] == '\'' || value
[0] == '"')) {
714 * ignore "boot-file" property, it's now meaningless
716 if (strcmp(name
, "boot-file") == 0)
718 if (strcmp(name
, "boot-args") == 0 &&
719 strlen(boot_args
) > 0)
723 * If a property was explicitly set on the command line
724 * it will override a setting in bootenv.rc
726 if (do_bsys_getproplen(NULL
, name
) > 0)
729 bsetprop(name
, n_len
, value
, v_len
+ 1);
733 (void) BRD_CLOSE(bfs_ops
, fd
);
736 * Check if we have to limit the boot time allocator
738 if (do_bsys_getproplen(NULL
, "physmem") != -1 &&
739 do_bsys_getprop(NULL
, "physmem", line
) >= 0 &&
740 parse_value(line
, &lvalue
) != -1) {
741 if (0 < lvalue
&& (lvalue
< physmem
|| physmem
== 0)) {
742 physmem
= (pgcnt_t
)lvalue
;
746 early_allocation
= 0;
749 * check to see if we have to override the default value of the console
753 v_len
= do_bsys_getproplen(NULL
, "input-device");
755 (void) do_bsys_getprop(NULL
, "input-device", inputdev
);
760 outputdev
= inputdev
+ v_len
+ 1;
761 v_len
= do_bsys_getproplen(NULL
, "output-device");
763 (void) do_bsys_getprop(NULL
, "output-device",
767 outputdev
[v_len
] = 0;
769 consoledev
= outputdev
+ v_len
+ 1;
770 v_len
= do_bsys_getproplen(NULL
, "console");
772 (void) do_bsys_getprop(NULL
, "console", consoledev
);
773 if (post_fastreboot
&&
774 strcmp(consoledev
, "graphics") == 0) {
775 bsetprops("console", "text");
776 v_len
= strlen("text");
777 bcopy("text", consoledev
, v_len
);
782 consoledev
[v_len
] = 0;
783 bcons_init2(inputdev
, outputdev
, consoledev
);
786 * Ensure console property exists
787 * If not create it as "hypervisor"
789 v_len
= do_bsys_getproplen(NULL
, "console");
791 bsetprops("console", "hypervisor");
792 inputdev
= outputdev
= consoledev
= "hypervisor";
793 bcons_init2(inputdev
, outputdev
, consoledev
);
796 if (find_boot_prop("prom_debug") || kbm_debug
)
797 boot_prop_display(line
);
801 * print formatted output
806 bop_printf(bootops_t
*bop
, const char *fmt
, ...)
810 if (have_console
== 0)
814 (void) vsnprintf(buffer
, BUFFERSIZE
, fmt
, ap
);
820 * Another panic() variant; this one can be used even earlier during boot than
825 bop_panic(const char *fmt
, ...)
830 bop_printf(NULL
, fmt
, ap
);
833 bop_printf(NULL
, "\nPress any key to reboot.\n");
834 (void) bcons_getchar();
835 bop_printf(NULL
, "Resetting...\n");
840 * Do a real mode interrupt BIOS call
842 typedef struct bios_regs
{
843 unsigned short ax
, bx
, cx
, dx
, si
, di
, bp
, es
, ds
;
845 typedef int (*bios_func_t
)(int, bios_regs_t
*);
849 do_bsys_doint(bootops_t
*bop
, int intnum
, struct bop_regs
*rp
)
852 prom_panic("unsupported call to BOP_DOINT()\n");
854 static int firsttime
= 1;
855 bios_func_t bios_func
= (bios_func_t
)(void *)(uintptr_t)0x5000;
859 * The first time we do this, we have to copy the pre-packaged
860 * low memory bios call code image into place.
863 extern char bios_image
[];
864 extern uint32_t bios_size
;
866 bcopy(bios_image
, (void *)bios_func
, bios_size
);
870 br
.ax
= rp
->eax
.word
.ax
;
871 br
.bx
= rp
->ebx
.word
.bx
;
872 br
.cx
= rp
->ecx
.word
.cx
;
873 br
.dx
= rp
->edx
.word
.dx
;
874 br
.bp
= rp
->ebp
.word
.bp
;
875 br
.si
= rp
->esi
.word
.si
;
876 br
.di
= rp
->edi
.word
.di
;
880 DBG_MSG("Doing BIOS call...");
884 rp
->eflags
= bios_func(intnum
, &br
);
887 rp
->eax
.word
.ax
= br
.ax
;
888 rp
->ebx
.word
.bx
= br
.bx
;
889 rp
->ecx
.word
.cx
= br
.cx
;
890 rp
->edx
.word
.dx
= br
.dx
;
891 rp
->ebp
.word
.bp
= br
.bp
;
892 rp
->esi
.word
.si
= br
.si
;
893 rp
->edi
.word
.di
= br
.di
;
899 static struct boot_syscalls bop_sysp
= {
911 static char namebuf
[32];
914 xen_parse_props(char *s
, char *prop_map
[], int n_prop
)
916 char **prop_name
= prop_map
;
921 while ((*cp
!= NULL
) && (*cp
!= ':'))
924 if ((scp
!= cp
) && (*prop_name
!= NULL
)) {
926 bsetprops(*prop_name
, scp
);
932 } while (n_prop
> 0);
935 #define VBDPATHLEN 64
938 * parse the 'xpv-root' property to create properties used by
942 xen_vbdroot_props(char *s
)
944 char vbdpath
[VBDPATHLEN
] = "/xpvd/xdf@";
945 const char lnamefix
[] = "/dev/dsk/c0d";
952 pnp
= vbdpath
+ strlen(vbdpath
);
953 prop_p
= s
+ strlen(lnamefix
);
954 while ((*prop_p
!= '\0') && (*prop_p
!= 's') && (*prop_p
!= 'p'))
955 addr
= addr
* 10 + *prop_p
++ - '0';
956 (void) snprintf(pnp
, VBDPATHLEN
, "%lx", addr
);
957 pnp
= vbdpath
+ strlen(vbdpath
);
960 else if (*prop_p
== 'p')
963 ASSERT(0); /* shouldn't be here */
965 ASSERT(*prop_p
!= '\0');
966 if (ISDIGIT(*prop_p
)) {
967 minor
= *prop_p
- '0';
969 if (ISDIGIT(*prop_p
)) {
970 minor
= minor
* 10 + *prop_p
- '0';
973 /* malformed root path, use 0 as default */
976 ASSERT(minor
< 16); /* at most 16 partitions */
981 bsetprops("fstype", "ufs");
982 bsetprops("bootpath", vbdpath
);
984 DBG_MSG("VBD bootpath set to ");
990 * parse the xpv-nfsroot property to create properties used by
994 xen_nfsroot_props(char *s
)
997 BP_SERVER_IP
, /* server IP address */
998 BP_SERVER_NAME
, /* server hostname */
999 BP_SERVER_PATH
, /* root path */
1001 int n_prop
= sizeof (prop_map
) / sizeof (prop_map
[0]);
1003 bsetprop("fstype", 6, "nfs", 4);
1005 xen_parse_props(s
, prop_map
, n_prop
);
1008 * If a server name wasn't specified, use a default.
1010 if (do_bsys_getproplen(NULL
, BP_SERVER_NAME
) == -1)
1011 bsetprops(BP_SERVER_NAME
, "unknown");
1015 * Extract our IP address, etc. from the "xpv-ip" property.
1018 xen_ip_props(char *s
)
1020 char *prop_map
[] = {
1021 BP_HOST_IP
, /* IP address */
1022 NULL
, /* NFS server IP address (ignored in */
1023 /* favour of xpv-nfsroot) */
1024 BP_ROUTER_IP
, /* IP gateway */
1025 BP_SUBNET_MASK
, /* IP subnet mask */
1026 "xpv-hostname", /* hostname (ignored) */
1027 BP_NETWORK_INTERFACE
, /* interface name */
1028 "xpv-hcp", /* host configuration protocol */
1030 int n_prop
= sizeof (prop_map
) / sizeof (prop_map
[0]);
1031 char ifname
[IFNAMSIZ
];
1033 xen_parse_props(s
, prop_map
, n_prop
);
1036 * A Linux dom0 administrator expects all interfaces to be
1037 * called "ethX", which is not the case here.
1039 * If the interface name specified is "eth0", presume that
1040 * this is really intended to be "xnf0" (the first domU ->
1041 * dom0 interface for this domain).
1043 if ((do_bsys_getprop(NULL
, BP_NETWORK_INTERFACE
, ifname
) == 0) &&
1044 (strcmp("eth0", ifname
) == 0)) {
1045 bsetprops(BP_NETWORK_INTERFACE
, "xnf0");
1047 "network interface name 'eth0' replaced with 'xnf0'\n");
1054 setup_rarp_props(struct sol_netinfo
*sip
)
1056 char buf
[BUFLEN
]; /* to hold ip/mac addrs */
1059 val
= (uint8_t *)&sip
->sn_ciaddr
;
1060 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1061 val
[0], val
[1], val
[2], val
[3]);
1062 bsetprops(BP_HOST_IP
, buf
);
1064 val
= (uint8_t *)&sip
->sn_siaddr
;
1065 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1066 val
[0], val
[1], val
[2], val
[3]);
1067 bsetprops(BP_SERVER_IP
, buf
);
1069 if (sip
->sn_giaddr
!= 0) {
1070 val
= (uint8_t *)&sip
->sn_giaddr
;
1071 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1072 val
[0], val
[1], val
[2], val
[3]);
1073 bsetprops(BP_ROUTER_IP
, buf
);
1076 if (sip
->sn_netmask
!= 0) {
1077 val
= (uint8_t *)&sip
->sn_netmask
;
1078 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1079 val
[0], val
[1], val
[2], val
[3]);
1080 bsetprops(BP_SUBNET_MASK
, buf
);
1083 if (sip
->sn_mactype
!= 4 || sip
->sn_maclen
!= 6) {
1084 bop_printf(NULL
, "unsupported mac type %d, mac len %d\n",
1085 sip
->sn_mactype
, sip
->sn_maclen
);
1087 val
= sip
->sn_macaddr
;
1088 (void) snprintf(buf
, BUFLEN
, "%x:%x:%x:%x:%x:%x",
1089 val
[0], val
[1], val
[2], val
[3], val
[4], val
[5]);
1090 bsetprops(BP_BOOT_MAC
, buf
);
1097 build_panic_cmdline(const char *cmd
, int cmdlen
)
1102 arglen
= sizeof (fastreboot_onpanic_args
);
1104 * If we allready have fastreboot-onpanic set to zero,
1105 * don't add them again.
1107 if ((proplen
= do_bsys_getproplen(NULL
, FASTREBOOT_ONPANIC
)) > 0 &&
1108 proplen
<= sizeof (fastreboot_onpanic_cmdline
)) {
1109 (void) do_bsys_getprop(NULL
, FASTREBOOT_ONPANIC
,
1110 fastreboot_onpanic_cmdline
);
1111 if (FASTREBOOT_ONPANIC_NOTSET(fastreboot_onpanic_cmdline
))
1116 * construct fastreboot_onpanic_cmdline
1118 if (cmdlen
+ arglen
> sizeof (fastreboot_onpanic_cmdline
)) {
1119 DBG_MSG("Command line too long: clearing "
1120 FASTREBOOT_ONPANIC
"\n");
1121 fastreboot_onpanic
= 0;
1123 bcopy(cmd
, fastreboot_onpanic_cmdline
, cmdlen
);
1125 bcopy(fastreboot_onpanic_args
,
1126 fastreboot_onpanic_cmdline
+ cmdlen
, arglen
);
1128 fastreboot_onpanic_cmdline
[cmdlen
] = 0;
1135 * Construct boot command line for Fast Reboot. The saved_cmdline
1136 * is also reported by "eeprom bootcmd".
1139 build_fastboot_cmdline(struct xboot_info
*xbp
)
1141 saved_cmdline_len
= strlen(xbp
->bi_cmdline
) + 1;
1142 if (saved_cmdline_len
> FASTBOOT_SAVED_CMDLINE_LEN
) {
1143 DBG(saved_cmdline_len
);
1144 DBG_MSG("Command line too long: clearing fastreboot_capable\n");
1145 fastreboot_capable
= 0;
1147 bcopy((void *)(xbp
->bi_cmdline
), (void *)saved_cmdline
,
1149 saved_cmdline
[saved_cmdline_len
- 1] = '\0';
1150 build_panic_cmdline(saved_cmdline
, saved_cmdline_len
- 1);
1155 * Save memory layout, disk drive information, unix and boot archive sizes for
1159 save_boot_info(struct xboot_info
*xbi
)
1161 multiboot_info_t
*mbi
= xbi
->bi_mb_info
;
1162 struct boot_modules
*modp
;
1165 bcopy(mbi
, &saved_mbi
, sizeof (multiboot_info_t
));
1166 if (mbi
->mmap_length
> sizeof (saved_mmap
)) {
1167 DBG_MSG("mbi->mmap_length too big: clearing "
1168 "fastreboot_capable\n");
1169 fastreboot_capable
= 0;
1171 bcopy((void *)(uintptr_t)mbi
->mmap_addr
, (void *)saved_mmap
,
1175 if ((mbi
->flags
& MB_INFO_DRIVE_INFO
) != 0) {
1176 if (mbi
->drives_length
> sizeof (saved_drives
)) {
1177 DBG(mbi
->drives_length
);
1178 DBG_MSG("mbi->drives_length too big: clearing "
1179 "fastreboot_capable\n");
1180 fastreboot_capable
= 0;
1182 bcopy((void *)(uintptr_t)mbi
->drives_addr
,
1183 (void *)saved_drives
, mbi
->drives_length
);
1186 saved_mbi
.drives_length
= 0;
1187 saved_mbi
.drives_addr
= NULL
;
1191 * Current file sizes. Used by fastboot.c to figure out how much
1192 * memory to reserve for panic reboot.
1193 * Use the module list from the dboot-constructed xboot_info
1194 * instead of the list referenced by the multiboot structure
1195 * because that structure may not be addressable now.
1197 saved_file_size
[FASTBOOT_NAME_UNIX
] = FOUR_MEG
- PAGESIZE
;
1198 for (i
= 0, modp
= (struct boot_modules
*)(uintptr_t)xbi
->bi_modules
;
1199 i
< xbi
->bi_module_cnt
; i
++, modp
++) {
1200 saved_file_size
[FASTBOOT_NAME_BOOTARCHIVE
] += modp
->bm_size
;
1206 * Import boot environment module variables as properties, applying
1207 * blacklist filter for variables we know we will not use.
1209 * Since the environment can be relatively large, containing many variables
1210 * used only for boot loader purposes, we will use a blacklist based filter.
1211 * To keep the blacklist from growing too large, we use prefix based filtering.
1212 * This is possible because in many cases, the loader variable names are
1213 * using a structured layout.
1215 * We will not overwrite already set properties.
1217 static struct bop_blacklist
{
1218 const char *bl_name
;
1220 } bop_prop_blacklist
[] = {
1221 { "ISADIR", sizeof ("ISADIR") },
1222 { "acpi", sizeof ("acpi") },
1223 { "autoboot_delay", sizeof ("autoboot_delay") },
1224 { "autoboot_delay", sizeof ("autoboot_delay") },
1225 { "beansi_", sizeof ("beansi_") },
1226 { "beastie", sizeof ("beastie") },
1227 { "bemenu", sizeof ("bemenu") },
1228 { "boot.", sizeof ("boot.") },
1229 { "bootenv", sizeof ("bootenv") },
1230 { "currdev", sizeof ("currdev") },
1231 { "dhcp.", sizeof ("dhcp.") },
1232 { "interpret", sizeof ("interpret") },
1233 { "kernel", sizeof ("kernel") },
1234 { "loaddev", sizeof ("loaddev") },
1235 { "loader_", sizeof ("loader_") },
1236 { "module_path", sizeof ("module_path") },
1237 { "nfs.", sizeof ("nfs.") },
1238 { "pcibios", sizeof ("pcibios") },
1239 { "prompt", sizeof ("prompt") },
1240 { "smbios", sizeof ("smbios") },
1241 { "tem", sizeof ("tem") },
1242 { "twiddle_divisor", sizeof ("twiddle_divisor") },
1243 { "zfs_be", sizeof ("zfs_be") },
1247 * Match the name against prefixes in above blacklist. If the match was
1248 * found, this name is blacklisted.
1251 name_is_blacklisted(const char *name
)
1255 n
= sizeof (bop_prop_blacklist
) / sizeof (bop_prop_blacklist
[0]);
1256 for (i
= 0; i
< n
; i
++) {
1257 if (strncmp(bop_prop_blacklist
[i
].bl_name
, name
,
1258 bop_prop_blacklist
[i
].bl_name_len
- 1) == 0) {
1266 process_boot_environment(struct boot_modules
*benv
)
1268 char *env
, *ptr
, *name
, *value
;
1269 uint32_t size
, name_len
, value_len
;
1271 if (benv
== NULL
|| benv
->bm_type
!= BMT_ENV
)
1273 ptr
= env
= benv
->bm_addr
;
1274 size
= benv
->bm_size
;
1278 while (*ptr
!= '=') {
1280 if (ptr
> env
+ size
) /* Something is very wrong. */
1283 name_len
= ptr
- name
;
1284 if (sizeof (buffer
) <= name_len
)
1287 (void) strncpy(buffer
, name
, sizeof (buffer
));
1288 buffer
[name_len
] = '\0';
1293 while ((uintptr_t)ptr
- (uintptr_t)env
< size
) {
1296 value_len
= (uintptr_t)ptr
- (uintptr_t)env
;
1302 /* Did we reach the end of the module? */
1309 /* Is this property already set? */
1310 if (do_bsys_getproplen(NULL
, name
) >= 0)
1313 if (name_is_blacklisted(name
) == B_TRUE
)
1316 /* Create new property. */
1317 bsetprops(name
, value
);
1319 /* Avoid reading past the module end. */
1320 if (size
<= (uintptr_t)ptr
- (uintptr_t)env
)
1322 } while (*ptr
!= '\0');
1326 * 1st pass at building the table of boot properties. This includes:
1327 * - values set on the command line: -B a=x,b=y,c=z ....
1328 * - known values we just compute (ie. from xbp)
1329 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
1331 * the grub command line looked like:
1332 * kernel boot-file [-B prop=value[,prop=value]...] [boot-args]
1334 * whoami is the same as boot-file
1337 build_boot_properties(struct xboot_info
*xbp
)
1343 struct boot_modules
*bm
, *rdbm
, *benv
= NULL
;
1350 static int stdout_val
= 0;
1351 uchar_t boot_device
;
1356 * These have to be done first, so that kobj_mount_root() works
1358 DBG_MSG("Building boot properties\n");
1359 propbuf
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, 0);
1360 DBG((uintptr_t)propbuf
);
1361 if (xbp
->bi_module_cnt
> 0) {
1362 bm
= xbp
->bi_modules
;
1364 for (midx
= i
= 0; i
< xbp
->bi_module_cnt
; i
++) {
1365 if (bm
[i
].bm_type
== BMT_ROOTFS
) {
1369 if (bm
[i
].bm_type
== BMT_HASH
|| bm
[i
].bm_name
== NULL
)
1372 if (bm
[i
].bm_type
== BMT_ENV
) {
1379 (void) snprintf(modid
, sizeof (modid
),
1380 "module-name-%u", midx
);
1381 bsetprops(modid
, (char *)bm
[i
].bm_name
);
1382 (void) snprintf(modid
, sizeof (modid
),
1383 "module-addr-%u", midx
);
1384 bsetprop64(modid
, (uint64_t)(uintptr_t)bm
[i
].bm_addr
);
1385 (void) snprintf(modid
, sizeof (modid
),
1386 "module-size-%u", midx
);
1387 bsetprop64(modid
, (uint64_t)bm
[i
].bm_size
);
1391 bsetprop64("ramdisk_start",
1392 (uint64_t)(uintptr_t)rdbm
->bm_addr
);
1393 bsetprop64("ramdisk_end",
1394 (uint64_t)(uintptr_t)rdbm
->bm_addr
+ rdbm
->bm_size
);
1399 * If there are any boot time modules or hashes present, then disable
1402 if (xbp
->bi_module_cnt
> 1) {
1403 fastreboot_disable(FBNS_BOOTMOD
);
1408 * Disable fast reboot if we're using the Multiboot 2 boot protocol,
1409 * since we don't currently support MB2 info and module relocation.
1410 * Note that fast reboot will have already been disabled if multiple
1411 * modules are present, since the current implementation assumes that
1412 * we only have a single module, the boot_archive.
1414 if (xbp
->bi_mb_version
!= 1) {
1415 fastreboot_disable(FBNS_MULTIBOOT2
);
1419 DBG_MSG("Parsing command line for boot properties\n");
1420 value
= xbp
->bi_cmdline
;
1423 * allocate memory to collect boot_args into
1425 boot_arg_len
= strlen(xbp
->bi_cmdline
) + 1;
1426 boot_args
= do_bsys_alloc(NULL
, NULL
, boot_arg_len
, MMU_PAGESIZE
);
1432 * Xen puts a lot of device information in front of the kernel name
1433 * let's grab them and make them boot properties. The first
1434 * string w/o an "=" in it will be the boot-file property.
1436 (void) strcpy(namebuf
, "xpv-");
1439 * get to next property
1441 while (ISSPACE(*value
))
1447 while (*value
&& !ISSPACE(*value
) && *value
!= '=') {
1450 if (*value
!= '=') { /* no "=" in the property */
1454 name_len
= value
- name
;
1460 while (value
[value_len
] && !ISSPACE(value
[value_len
])) {
1464 * build property name with "xpv-" prefix
1466 if (name_len
+ 4 > 32) { /* skip if name too long */
1470 bcopy(name
, &namebuf
[4], name_len
);
1472 namebuf
[name_len
] = 0;
1473 bcopy(value
, propbuf
, value_len
);
1474 propbuf
[value_len
] = 0;
1475 bsetprops(namebuf
, propbuf
);
1478 * xpv-root is set to the logical disk name of the xen
1479 * VBD when booting from a disk-based filesystem.
1481 if (strcmp(namebuf
, "xpv-root") == 0)
1482 xen_vbdroot_props(propbuf
);
1484 * While we're here, if we have a "xpv-nfsroot" property
1485 * then we need to set "fstype" to "nfs" so we mount
1486 * our root from the nfs server. Also parse the xpv-nfsroot
1487 * property to create the properties that nfs_mountroot will
1488 * need to find the root and mount it.
1490 if (strcmp(namebuf
, "xpv-nfsroot") == 0)
1491 xen_nfsroot_props(propbuf
);
1493 if (strcmp(namebuf
, "xpv-ip") == 0)
1494 xen_ip_props(propbuf
);
1499 while (ISSPACE(*value
))
1502 * value now points at the boot-file
1505 while (value
[value_len
] && !ISSPACE(value
[value_len
]))
1507 if (value_len
> 0) {
1509 bcopy(value
, whoami
, value_len
);
1510 whoami
[value_len
] = 0;
1511 bsetprops("boot-file", whoami
);
1513 * strip leading path stuff from whoami, so running from
1514 * PXE/miniroot makes sense.
1516 if (strstr(whoami
, "/platform/") != NULL
)
1517 whoami
= strstr(whoami
, "/platform/");
1518 bsetprops("whoami", whoami
);
1522 * Values forcibly set boot properties on the command line via -B.
1523 * Allow use of quotes in values. Other stuff goes on kernel
1526 name
= value
+ value_len
;
1527 while (*name
!= 0) {
1529 * anything not " -B" is copied to the command line
1531 if (!ISSPACE(name
[0]) || name
[1] != '-' || name
[2] != 'B') {
1532 boot_args
[boot_arg_len
++] = *name
;
1533 boot_args
[boot_arg_len
] = 0;
1539 * skip the " -B" and following white space
1542 while (ISSPACE(*name
))
1544 while (*name
&& !ISSPACE(*name
)) {
1545 value
= strstr(name
, "=");
1548 name_len
= value
- name
;
1552 for (; ; ++value_len
) {
1553 if (!value
[value_len
])
1557 * is this value quoted?
1559 if (value_len
== 0 &&
1560 (value
[0] == '\'' || value
[0] == '"')) {
1566 * In the quote accept any character,
1567 * but look for ending quote.
1570 if (value
[value_len
] == quoted
)
1576 * a comma or white space ends the value
1578 if (value
[value_len
] == ',' ||
1579 ISSPACE(value
[value_len
]))
1583 if (value_len
== 0) {
1584 bsetprop(name
, name_len
, "true", 5);
1588 if (v
[0] == v
[l
- 1] &&
1589 (v
[0] == '\'' || v
[0] == '"')) {
1593 bcopy(v
, propbuf
, l
);
1595 bsetprop(name
, name_len
, propbuf
,
1598 name
= value
+ value_len
;
1599 while (*name
== ',')
1605 * set boot-args property
1606 * 1275 name is bootargs, so set
1609 bsetprops("boot-args", boot_args
);
1610 bsetprops("bootargs", boot_args
);
1612 process_boot_environment(benv
);
1616 * Build boot command line for Fast Reboot
1618 build_fastboot_cmdline(xbp
);
1620 if (xbp
->bi_mb_version
== 1) {
1621 multiboot_info_t
*mbi
= xbp
->bi_mb_info
;
1623 struct sol_netinfo
*sip
;
1626 * set the BIOS boot device from GRUB
1631 * Save various boot information for Fast Reboot
1633 save_boot_info(xbp
);
1635 if (mbi
!= NULL
&& mbi
->flags
& MB_INFO_BOOTDEV
) {
1636 boot_device
= mbi
->boot_device
>> 24;
1637 if (boot_device
== 0x20)
1639 str
[0] = (boot_device
>> 4) + '0';
1640 str
[1] = (boot_device
& 0xf) + '0';
1642 bsetprops("bios-boot-device", str
);
1648 * In the netboot case, drives_info is overloaded with the
1649 * dhcp ack. This is not multiboot compliant and requires
1652 if (netboot
&& mbi
->drives_length
!= 0) {
1653 sip
= (struct sol_netinfo
*)(uintptr_t)mbi
->drives_addr
;
1654 if (sip
->sn_infotype
== SN_TYPE_BOOTP
)
1655 bsetprop("bootp-response",
1656 sizeof ("bootp-response"),
1657 (void *)(uintptr_t)mbi
->drives_addr
,
1658 mbi
->drives_length
);
1659 else if (sip
->sn_infotype
== SN_TYPE_RARP
)
1660 setup_rarp_props(sip
);
1663 multiboot2_info_header_t
*mbi
= xbp
->bi_mb_info
;
1664 multiboot_tag_bootdev_t
*bootdev
= NULL
;
1665 multiboot_tag_network_t
*netdev
= NULL
;
1668 bootdev
= dboot_multiboot2_find_tag(mbi
,
1669 MULTIBOOT_TAG_TYPE_BOOTDEV
);
1670 netdev
= dboot_multiboot2_find_tag(mbi
,
1671 MULTIBOOT_TAG_TYPE_NETWORK
);
1673 if (bootdev
!= NULL
) {
1674 DBG(bootdev
->mb_biosdev
);
1675 boot_device
= bootdev
->mb_biosdev
;
1676 str
[0] = (boot_device
>> 4) + '0';
1677 str
[1] = (boot_device
& 0xf) + '0';
1679 bsetprops("bios-boot-device", str
);
1681 if (netdev
!= NULL
) {
1682 bsetprop("bootp-response", sizeof ("bootp-response"),
1683 (void *)(uintptr_t)netdev
->mb_dhcpack
,
1685 sizeof (multiboot_tag_network_t
));
1689 bsetprop("stdout", strlen("stdout"),
1690 &stdout_val
, sizeof (stdout_val
));
1694 * more conjured up values for made up things....
1697 bsetprops("mfg-name", "i86xpv");
1698 bsetprops("impl-arch-name", "i86xpv");
1700 bsetprops("mfg-name", "i86pc");
1701 bsetprops("impl-arch-name", "i86pc");
1705 * Build firmware-provided system properties
1707 build_firmware_properties(xbp
);
1712 * Find out what these are:
1713 * - cpuid_feature_ecx_include
1714 * - cpuid_feature_ecx_exclude
1715 * - cpuid_feature_edx_include
1716 * - cpuid_feature_edx_exclude
1718 * Find out what these are in multiboot:
1726 * Under the Hypervisor, memory usable for DMA may be scarce. One
1727 * very likely large pool of DMA friendly memory is occupied by
1728 * the boot_archive, as it was loaded by grub into low MFNs.
1730 * Here we free up that memory by copying the boot archive to what are
1731 * likely higher MFN pages and then swapping the mfn/pfn mappings.
1733 #define PFN_2GIG 0x80000
1735 relocate_boot_archive(struct xboot_info
*xbp
)
1737 mfn_t max_mfn
= HYPERVISOR_memory_op(XENMEM_maximum_ram_page
, NULL
);
1738 struct boot_modules
*bm
= xbp
->bi_modules
;
1749 int mmu_update_return
;
1754 * If all MFN's are below 2Gig, don't bother doing this.
1756 if (max_mfn
< PFN_2GIG
)
1758 if (xbp
->bi_module_cnt
< 1) {
1759 DBG_MSG("no boot_archive!");
1763 DBG_MSG("moving boot_archive to high MFN memory\n");
1764 va
= (uintptr_t)bm
->bm_addr
;
1766 slop
= va
& MMU_PAGEOFFSET
;
1768 va
+= MMU_PAGESIZE
- slop
;
1769 len
-= MMU_PAGESIZE
- slop
;
1771 len
= P2ALIGN(len
, MMU_PAGESIZE
);
1774 * Go through all boot_archive pages, swapping any low MFN pages
1775 * with memory at next_phys.
1779 va_pfn
= mmu_btop(va
- ONE_GIG
);
1780 va_mfn
= mfn_list
[va_pfn
];
1781 if (mfn_list
[va_pfn
] < PFN_2GIG
) {
1782 copy
= kbm_remap_window(next_phys
, 1);
1783 bcopy((void *)va
, copy
, MMU_PAGESIZE
);
1784 copy_pfn
= mmu_btop(next_phys
);
1785 copy_mfn
= mfn_list
[copy_pfn
];
1787 pte
= mfn_to_ma(copy_mfn
) | PT_NOCONSIST
| PT_VALID
;
1788 if (HYPERVISOR_update_va_mapping(va
, pte
,
1789 UVMF_INVLPG
| UVMF_LOCAL
))
1790 bop_panic("relocate_boot_archive(): "
1791 "HYPERVISOR_update_va_mapping() failed");
1793 mfn_list
[va_pfn
] = copy_mfn
;
1794 mfn_list
[copy_pfn
] = va_mfn
;
1796 t
[0].ptr
= mfn_to_ma(copy_mfn
) | MMU_MACHPHYS_UPDATE
;
1798 t
[1].ptr
= mfn_to_ma(va_mfn
) | MMU_MACHPHYS_UPDATE
;
1799 t
[1].val
= copy_pfn
;
1800 if (HYPERVISOR_mmu_update(t
, 2, &mmu_update_return
,
1801 DOMID_SELF
) != 0 || mmu_update_return
!= 2)
1802 bop_panic("relocate_boot_archive(): "
1803 "HYPERVISOR_mmu_update() failed");
1805 next_phys
+= MMU_PAGESIZE
;
1808 len
-= MMU_PAGESIZE
;
1811 DBG_MSG("Relocated pages:\n");
1813 DBG_MSG("Out of total pages:\n");
1820 * Install a temporary IDT that lets us catch errors in the boot time code.
1821 * We shouldn't get any faults at all while this is installed, so we'll
1822 * just generate a traceback and exit.
1825 static const int bcode_sel
= B64CODE_SEL
;
1827 static const int bcode_sel
= B32CODE_SEL
;
1831 * simple description of a stack frame (args are 32 bit only currently)
1833 typedef struct bop_frame
{
1834 struct bop_frame
*old_frame
;
1840 bop_traceback(bop_frame_t
*frame
)
1850 bop_printf(NULL
, "Stack traceback:\n");
1851 for (cnt
= 0; cnt
< 30; ++cnt
) { /* up to 30 frames */
1852 pc
= frame
->retaddr
;
1855 ksym
= kobj_getsymname(pc
, &off
);
1857 bop_printf(NULL
, " %s+%lx", ksym
, off
);
1859 bop_printf(NULL
, " 0x%lx", pc
);
1861 frame
= frame
->old_frame
;
1863 bop_printf(NULL
, "\n");
1867 for (a
= 0; a
< 6; ++a
) { /* try for 6 args */
1868 if ((void *)&frame
->arg
[a
] == (void *)frame
->old_frame
)
1871 bop_printf(NULL
, "(");
1873 bop_printf(NULL
, ",");
1874 bop_printf(NULL
, "0x%lx", frame
->arg
[a
]);
1876 bop_printf(NULL
, ")");
1878 bop_printf(NULL
, "\n");
1883 ulong_t error_code
; /* optional */
1894 bop_trap(ulong_t
*tfp
)
1896 struct trapframe
*tf
= (struct trapframe
*)tfp
;
1897 bop_frame_t fakeframe
;
1898 static int depth
= 0;
1901 * Check for an infinite loop of traps.
1904 bop_panic("Nested trap");
1906 bop_printf(NULL
, "Unexpected trap\n");
1909 * adjust the tf for optional error_code by detecting the code selector
1911 if (tf
->code_seg
!= bcode_sel
)
1912 tf
= (struct trapframe
*)(tfp
- 1);
1914 bop_printf(NULL
, "error code 0x%lx\n",
1915 tf
->error_code
& 0xffffffff);
1917 bop_printf(NULL
, "instruction pointer 0x%lx\n", tf
->inst_ptr
);
1918 bop_printf(NULL
, "code segment 0x%lx\n", tf
->code_seg
& 0xffff);
1919 bop_printf(NULL
, "flags register 0x%lx\n", tf
->flags_reg
);
1921 bop_printf(NULL
, "return %%rsp 0x%lx\n", tf
->stk_ptr
);
1922 bop_printf(NULL
, "return %%ss 0x%lx\n", tf
->stk_seg
& 0xffff);
1925 /* grab %[er]bp pushed by our code from the stack */
1926 fakeframe
.old_frame
= (bop_frame_t
*)*(tfp
- 3);
1927 fakeframe
.retaddr
= (pc_t
)tf
->inst_ptr
;
1928 bop_printf(NULL
, "Attempting stack backtrace:\n");
1929 bop_traceback(&fakeframe
);
1930 bop_panic("unexpected trap in early boot");
1933 extern void bop_trap_handler(void);
1935 static gate_desc_t
*bop_idt
;
1937 static desctbr_t bop_idt_info
;
1944 bop_idt
= (gate_desc_t
*)
1945 do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
1946 bzero(bop_idt
, MMU_PAGESIZE
);
1947 for (t
= 0; t
< NIDT
; ++t
) {
1949 * Note that since boot runs without a TSS, the
1950 * double fault handler cannot use an alternate stack
1951 * (64-bit) or a task gate (32-bit).
1953 set_gatesegd(&bop_idt
[t
], &bop_trap_handler
, bcode_sel
,
1954 SDT_SYSIGT
, TRP_KPL
, 0);
1956 bop_idt_info
.dtr_limit
= (NIDT
* sizeof (gate_desc_t
)) - 1;
1957 bop_idt_info
.dtr_base
= (uintptr_t)bop_idt
;
1958 wr_idtr(&bop_idt_info
);
1960 #endif /* !defined(__xpv) */
1963 * This is where we enter the kernel. It dummies up the boot_ops and
1964 * boot_syscalls vectors and jumps off to _kobj_boot()
1967 _start(struct xboot_info
*xbp
)
1969 bootops_t
*bops
= &bootop
;
1970 extern void _kobj_boot();
1973 * 1st off - initialize the console for any error messages
1977 HYPERVISOR_shared_info
= (void *)xbp
->bi_shared_info
;
1978 xen_info
= xbp
->bi_xen_start_info
;
1982 if (*((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) ==
1984 post_fastreboot
= 1;
1985 *((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) = 0;
1995 if (find_boot_prop("kbm_debug") != NULL
)
1998 DBG_MSG("\n\n*** Entered Solaris in _start() cmdline is: ");
1999 DBG_MSG((char *)xbp
->bi_cmdline
);
2003 * physavail is no longer used by startup
2005 bm
.physinstalled
= xbp
->bi_phys_install
;
2006 bm
.pcimem
= xbp
->bi_pcimem
;
2007 bm
.rsvdmem
= xbp
->bi_rsvdmem
;
2008 bm
.physavail
= NULL
;
2011 * initialize the boot time allocator
2013 next_phys
= xbp
->bi_next_paddr
;
2015 next_virt
= (uintptr_t)xbp
->bi_next_vaddr
;
2017 DBG_MSG("Initializing boot time memory management...");
2020 xen_platform_parameters_t p
;
2022 /* This call shouldn't fail, dboot already did it once. */
2023 (void) HYPERVISOR_xen_version(XENVER_platform_parameters
, &p
);
2024 mfn_to_pfn_mapping
= (pfn_t
*)(xen_virt_start
= p
.virt_start
);
2025 DBG(xen_virt_start
);
2032 * Fill in the bootops vector
2034 bops
->bsys_version
= BO_VERSION
;
2035 bops
->boot_mem
= &bm
;
2036 bops
->bsys_alloc
= do_bsys_alloc
;
2037 bops
->bsys_free
= do_bsys_free
;
2038 bops
->bsys_getproplen
= do_bsys_getproplen
;
2039 bops
->bsys_getprop
= do_bsys_getprop
;
2040 bops
->bsys_nextprop
= do_bsys_nextprop
;
2041 bops
->bsys_printf
= bop_printf
;
2042 bops
->bsys_doint
= do_bsys_doint
;
2045 * BOP_EALLOC() is no longer needed
2047 bops
->bsys_ealloc
= do_bsys_ealloc
;
2051 * On domain 0 we need to free up some physical memory that is
2052 * usable for DMA. Since GRUB loaded the boot_archive, it is
2053 * sitting in low MFN memory. We'll relocated the boot archive
2054 * pages to high PFN memory.
2056 if (DOMAIN_IS_INITDOMAIN(xen_info
))
2057 relocate_boot_archive(xbp
);
2062 * Install an IDT to catch early pagefaults (shouldn't have any).
2063 * Also needed for kmdb.
2069 * Start building the boot properties from the command line
2071 DBG_MSG("Initializing boot properties:\n");
2072 build_boot_properties(xbp
);
2074 if (find_boot_prop("prom_debug") || kbm_debug
) {
2077 value
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
2078 boot_prop_display(value
);
2082 * jump into krtld...
2084 _kobj_boot(&bop_sysp
, NULL
, bops
, NULL
);
2090 no_more_alloc(bootops_t
*bop
, caddr_t virthint
, size_t size
, int align
)
2092 panic("Attempt to bsys_alloc() too late\n");
2098 no_more_free(bootops_t
*bop
, caddr_t virt
, size_t size
)
2100 panic("Attempt to bsys_free() too late\n");
2104 bop_no_more_mem(void)
2106 DBG(total_bop_alloc_scratch
);
2107 DBG(total_bop_alloc_kernel
);
2108 bootops
->bsys_alloc
= no_more_alloc
;
2109 bootops
->bsys_free
= no_more_free
;
2114 * Set ACPI firmware properties
2118 vmap_phys(size_t length
, paddr_t pa
)
2125 pa
= pfn_to_pa(xen_assign_pfn(mmu_btop(pa
))) | (pa
& MMU_PAGEOFFSET
);
2127 start
= P2ALIGN(pa
, MMU_PAGESIZE
);
2128 end
= P2ROUNDUP(pa
+ length
, MMU_PAGESIZE
);
2130 va
= (caddr_t
)alloc_vaddr(len
, MMU_PAGESIZE
);
2131 for (page
= 0; page
< len
; page
+= MMU_PAGESIZE
)
2132 kbm_map((uintptr_t)va
+ page
, start
+ page
, 0, 0);
2133 return (va
+ (pa
& MMU_PAGEOFFSET
));
2137 checksum_table(uint8_t *tp
, size_t len
)
2148 valid_rsdp(ACPI_TABLE_RSDP
*rp
)
2151 /* validate the V1.x checksum */
2152 if (checksum_table((uint8_t *)rp
, ACPI_RSDP_CHECKSUM_LENGTH
) != 0)
2155 /* If pre-ACPI 2.0, this is a valid RSDP */
2156 if (rp
->Revision
< 2)
2159 /* validate the V2.x checksum */
2160 if (checksum_table((uint8_t *)rp
, ACPI_RSDP_XCHECKSUM_LENGTH
) != 0)
2167 * Scan memory range for an RSDP;
2168 * see ACPI 3.0 Spec, 5.2.5.1
2170 static ACPI_TABLE_RSDP
*
2171 scan_rsdp(paddr_t start
, paddr_t end
)
2173 ssize_t len
= end
- start
;
2176 ptr
= vmap_phys(len
, start
);
2178 if (strncmp(ptr
, ACPI_SIG_RSDP
, strlen(ACPI_SIG_RSDP
)) == 0 &&
2179 valid_rsdp((ACPI_TABLE_RSDP
*)ptr
))
2180 return ((ACPI_TABLE_RSDP
*)ptr
);
2182 ptr
+= ACPI_RSDP_SCAN_STEP
;
2183 len
-= ACPI_RSDP_SCAN_STEP
;
2190 * Refer to ACPI 3.0 Spec, section 5.2.5.1 to understand this function
2192 static ACPI_TABLE_RSDP
*
2195 ACPI_TABLE_RSDP
*rsdp
;
2196 uint64_t rsdp_val
= 0;
2200 /* check for "acpi-root-tab" property */
2201 if (do_bsys_getproplen(NULL
, "acpi-root-tab") == sizeof (uint64_t)) {
2202 (void) do_bsys_getprop(NULL
, "acpi-root-tab", &rsdp_val
);
2203 if (rsdp_val
!= 0) {
2204 rsdp
= scan_rsdp(rsdp_val
, rsdp_val
+ sizeof (*rsdp
));
2208 "Using RSDP from bootloader: "
2209 "0x%p\n", (void *)rsdp
);
2217 * Get the EBDA segment and scan the first 1K
2219 ebda_seg
= (uint16_t *)vmap_phys(sizeof (uint16_t),
2220 ACPI_EBDA_PTR_LOCATION
);
2221 ebda_addr
= *ebda_seg
<< 4;
2222 rsdp
= scan_rsdp(ebda_addr
, ebda_addr
+ ACPI_EBDA_WINDOW_SIZE
);
2224 /* if EBDA doesn't contain RSDP, look in BIOS memory */
2225 rsdp
= scan_rsdp(ACPI_HI_RSDP_WINDOW_BASE
,
2226 ACPI_HI_RSDP_WINDOW_BASE
+ ACPI_HI_RSDP_WINDOW_SIZE
);
2230 static ACPI_TABLE_HEADER
*
2231 map_fw_table(paddr_t table_addr
)
2233 ACPI_TABLE_HEADER
*tp
;
2234 size_t len
= MAX(sizeof (*tp
), MMU_PAGESIZE
);
2237 * Map at least a page; if the table is larger than this, remap it
2239 tp
= (ACPI_TABLE_HEADER
*)vmap_phys(len
, table_addr
);
2240 if (tp
->Length
> len
)
2241 tp
= (ACPI_TABLE_HEADER
*)vmap_phys(tp
->Length
, table_addr
);
2245 static ACPI_TABLE_HEADER
*
2246 find_fw_table(char *signature
)
2248 static int revision
= 0;
2249 static ACPI_TABLE_XSDT
*xsdt
;
2252 ACPI_TABLE_RSDP
*rsdp
;
2253 ACPI_TABLE_HEADER
*tp
;
2257 if (strlen(signature
) != ACPI_NAME_SIZE
)
2261 * Reading the ACPI 3.0 Spec, section 5.2.5.3 will help
2262 * understand this code. If we haven't already found the RSDT/XSDT,
2263 * revision will be 0. Find the RSDP and check the revision
2264 * to find out whether to use the RSDT or XSDT. If revision is
2265 * 0 or 1, use the RSDT and set internal revision to 1; if it is 2,
2266 * use the XSDT. If the XSDT address is 0, though, fall back to
2267 * revision 1 and use the RSDT.
2269 if (revision
== 0) {
2270 if ((rsdp
= find_rsdp()) != NULL
) {
2271 revision
= rsdp
->Revision
;
2273 * ACPI 6.0 states that current revision is 2
2274 * from acpi_table_rsdp definition:
2275 * Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+
2282 * Use the XSDT unless BIOS is buggy and
2283 * claims to be rev 2 but has a null XSDT
2286 xsdt_addr
= rsdp
->XsdtPhysicalAddress
;
2291 /* treat RSDP rev 0 as revision 1 internally */
2295 /* use the RSDT for rev 0/1 */
2296 xsdt_addr
= rsdp
->RsdtPhysicalAddress
;
2299 /* unknown revision */
2307 /* cache the XSDT info */
2308 xsdt
= (ACPI_TABLE_XSDT
*)map_fw_table(xsdt_addr
);
2309 len
= (xsdt
->Header
.Length
- sizeof (xsdt
->Header
)) /
2310 ((revision
== 1) ? sizeof (uint32_t) : sizeof (uint64_t));
2314 * Scan the table headers looking for a signature match
2316 for (n
= 0; n
< len
; n
++) {
2317 ACPI_TABLE_RSDT
*rsdt
= (ACPI_TABLE_RSDT
*)xsdt
;
2318 table_addr
= (revision
== 1) ? rsdt
->TableOffsetEntry
[n
] :
2319 xsdt
->TableOffsetEntry
[n
];
2321 if (table_addr
== 0)
2323 tp
= map_fw_table(table_addr
);
2324 if (strncmp(tp
->Signature
, signature
, ACPI_NAME_SIZE
) == 0) {
2332 process_mcfg(ACPI_TABLE_MCFG
*tp
)
2334 ACPI_MCFG_ALLOCATION
*cfg_baap
;
2336 int64_t ecfginfo
[4];
2338 cfg_baap
= (ACPI_MCFG_ALLOCATION
*)((uintptr_t)tp
+ sizeof (*tp
));
2339 cfg_baa_endp
= ((char *)tp
) + tp
->Header
.Length
;
2340 while ((char *)cfg_baap
< cfg_baa_endp
) {
2341 if (cfg_baap
->Address
!= 0 && cfg_baap
->PciSegment
== 0) {
2342 ecfginfo
[0] = cfg_baap
->Address
;
2343 ecfginfo
[1] = cfg_baap
->PciSegment
;
2344 ecfginfo
[2] = cfg_baap
->StartBusNumber
;
2345 ecfginfo
[3] = cfg_baap
->EndBusNumber
;
2346 bsetprop(MCFG_PROPNAME
, strlen(MCFG_PROPNAME
),
2347 ecfginfo
, sizeof (ecfginfo
));
2356 process_madt_entries(ACPI_TABLE_MADT
*tp
, uint32_t *cpu_countp
,
2357 uint32_t *cpu_possible_countp
, uint32_t *cpu_apicid_array
)
2359 ACPI_SUBTABLE_HEADER
*item
, *end
;
2360 uint32_t cpu_count
= 0;
2361 uint32_t cpu_possible_count
= 0;
2364 * Determine number of CPUs and keep track of "final" APIC ID
2365 * for each CPU by walking through ACPI MADT processor list
2367 end
= (ACPI_SUBTABLE_HEADER
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2368 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)tp
+ sizeof (*tp
));
2370 while (item
< end
) {
2371 switch (item
->Type
) {
2372 case ACPI_MADT_TYPE_LOCAL_APIC
: {
2373 ACPI_MADT_LOCAL_APIC
*cpu
=
2374 (ACPI_MADT_LOCAL_APIC
*) item
;
2376 if (cpu
->LapicFlags
& ACPI_MADT_ENABLED
) {
2377 if (cpu_apicid_array
!= NULL
)
2378 cpu_apicid_array
[cpu_count
] = cpu
->Id
;
2381 cpu_possible_count
++;
2384 case ACPI_MADT_TYPE_LOCAL_X2APIC
: {
2385 ACPI_MADT_LOCAL_X2APIC
*cpu
=
2386 (ACPI_MADT_LOCAL_X2APIC
*) item
;
2388 if (cpu
->LapicFlags
& ACPI_MADT_ENABLED
) {
2389 if (cpu_apicid_array
!= NULL
)
2390 cpu_apicid_array
[cpu_count
] =
2394 cpu_possible_count
++;
2399 bop_printf(NULL
, "MADT type %d\n", item
->Type
);
2403 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)item
+ item
->Length
);
2406 *cpu_countp
= cpu_count
;
2407 if (cpu_possible_countp
)
2408 *cpu_possible_countp
= cpu_possible_count
;
2412 process_madt(ACPI_TABLE_MADT
*tp
)
2414 uint32_t cpu_count
= 0;
2415 uint32_t cpu_possible_count
= 0;
2416 uint32_t *cpu_apicid_array
; /* x2APIC ID is 32bit! */
2420 process_madt_entries(tp
, &cpu_count
, &cpu_possible_count
, NULL
);
2422 cpu_apicid_array
= (uint32_t *)do_bsys_alloc(NULL
, NULL
,
2423 cpu_count
* sizeof (*cpu_apicid_array
), MMU_PAGESIZE
);
2424 if (cpu_apicid_array
== NULL
)
2425 bop_panic("Not enough memory for APIC ID array");
2428 process_madt_entries(tp
, NULL
, NULL
, cpu_apicid_array
);
2431 * Make boot property for array of "final" APIC IDs for each
2434 bsetprop(BP_CPU_APICID_ARRAY
, strlen(BP_CPU_APICID_ARRAY
),
2435 cpu_apicid_array
, cpu_count
* sizeof (*cpu_apicid_array
));
2439 * Check whether property plat-max-ncpus is already set.
2441 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2443 * Set plat-max-ncpus to number of maximum possible CPUs given
2444 * in MADT if it hasn't been set.
2445 * There's no formal way to detect max possible CPUs supported
2446 * by platform according to ACPI spec3.0b. So current CPU
2447 * hotplug implementation expects that all possible CPUs will
2448 * have an entry in MADT table and set plat-max-ncpus to number
2449 * of entries in MADT.
2450 * With introducing of ACPI4.0, Maximum System Capability Table
2451 * (MSCT) provides maximum number of CPUs supported by platform.
2452 * If MSCT is unavailable, fall back to old way.
2455 bsetpropsi(PLAT_MAX_NCPUS_NAME
, cpu_possible_count
);
2459 * Set boot property boot-max-ncpus to number of CPUs existing at
2460 * boot time. boot-max-ncpus is mainly used for optimization.
2463 bsetpropsi(BOOT_MAX_NCPUS_NAME
, cpu_count
);
2466 * User-set boot-ncpus overrides firmware count
2468 if (do_bsys_getproplen(NULL
, BOOT_NCPUS_NAME
) >= 0)
2472 * Set boot property boot-ncpus to number of active CPUs given in MADT
2473 * if it hasn't been set yet.
2476 bsetpropsi(BOOT_NCPUS_NAME
, cpu_count
);
2480 process_srat(ACPI_TABLE_SRAT
*tp
)
2482 ACPI_SUBTABLE_HEADER
*item
, *end
;
2484 int proc_num
, mem_num
;
2503 uint64_t maxmem
= 0;
2508 proc_num
= mem_num
= 0;
2509 end
= (ACPI_SUBTABLE_HEADER
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2510 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)tp
+ sizeof (*tp
));
2511 while (item
< end
) {
2512 switch (item
->Type
) {
2513 case ACPI_SRAT_TYPE_CPU_AFFINITY
: {
2514 ACPI_SRAT_CPU_AFFINITY
*cpu
=
2515 (ACPI_SRAT_CPU_AFFINITY
*) item
;
2517 if (!(cpu
->Flags
& ACPI_SRAT_CPU_ENABLED
))
2519 processor
.domain
= cpu
->ProximityDomainLo
;
2520 for (i
= 0; i
< 3; i
++)
2522 cpu
->ProximityDomainHi
[i
] << ((i
+ 1) * 8);
2523 processor
.apic_id
= cpu
->ApicId
;
2524 processor
.sapic_id
= cpu
->LocalSapicEid
;
2525 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2527 bsetprop(prop_name
, strlen(prop_name
), &processor
,
2528 sizeof (processor
));
2532 case ACPI_SRAT_TYPE_MEMORY_AFFINITY
: {
2533 ACPI_SRAT_MEM_AFFINITY
*mem
=
2534 (ACPI_SRAT_MEM_AFFINITY
*)item
;
2536 if (!(mem
->Flags
& ACPI_SRAT_MEM_ENABLED
))
2538 memory
.domain
= mem
->ProximityDomain
;
2539 memory
.addr
= mem
->BaseAddress
;
2540 memory
.length
= mem
->Length
;
2541 memory
.flags
= mem
->Flags
;
2542 (void) snprintf(prop_name
, 30, "acpi-srat-memory-%d",
2544 bsetprop(prop_name
, strlen(prop_name
), &memory
,
2546 if ((mem
->Flags
& ACPI_SRAT_MEM_HOT_PLUGGABLE
) &&
2547 (memory
.addr
+ memory
.length
> maxmem
)) {
2548 maxmem
= memory
.addr
+ memory
.length
;
2553 case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY
: {
2554 ACPI_SRAT_X2APIC_CPU_AFFINITY
*x2cpu
=
2555 (ACPI_SRAT_X2APIC_CPU_AFFINITY
*) item
;
2557 if (!(x2cpu
->Flags
& ACPI_SRAT_CPU_ENABLED
))
2559 x2apic
.domain
= x2cpu
->ProximityDomain
;
2560 x2apic
.x2apic_id
= x2cpu
->ApicId
;
2561 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2563 bsetprop(prop_name
, strlen(prop_name
), &x2apic
,
2570 bop_printf(NULL
, "SRAT type %d\n", item
->Type
);
2574 item
= (ACPI_SUBTABLE_HEADER
*)
2575 (item
->Length
+ (uintptr_t)item
);
2579 * The maximum physical address calculated from the SRAT table is more
2580 * accurate than that calculated from the MSCT table.
2583 plat_dr_physmax
= btop(maxmem
);
2588 process_slit(ACPI_TABLE_SLIT
*tp
)
2592 * Check the number of localities; if it's too huge, we just
2593 * return and locality enumeration code will handle this later,
2596 * Note that the size of the table is the square of the
2597 * number of localities; if the number of localities exceeds
2598 * UINT16_MAX, the table size may overflow an int when being
2599 * passed to bsetprop() below.
2601 if (tp
->LocalityCount
>= SLIT_LOCALITIES_MAX
)
2604 bsetprop(SLIT_NUM_PROPNAME
, strlen(SLIT_NUM_PROPNAME
),
2605 &tp
->LocalityCount
, sizeof (tp
->LocalityCount
));
2606 bsetprop(SLIT_PROPNAME
, strlen(SLIT_PROPNAME
), &tp
->Entry
,
2607 tp
->LocalityCount
* tp
->LocalityCount
);
2610 static ACPI_TABLE_MSCT
*
2611 process_msct(ACPI_TABLE_MSCT
*tp
)
2615 ACPI_MSCT_PROXIMITY
*item
, *end
;
2616 extern uint64_t plat_dr_options
;
2620 end
= (ACPI_MSCT_PROXIMITY
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2621 for (item
= (void *)((uintptr_t)tp
+ tp
->ProximityOffset
);
2623 item
= (void *)(item
->Length
+ (uintptr_t)item
)) {
2625 * Sanity check according to section 5.2.19.1 of ACPI 4.0.
2629 if (item
->Revision
!= 1 || item
->Length
!= 22) {
2631 "?boot: unknown proximity domain structure in MSCT "
2632 "with Revision(%d), Length(%d).\n",
2633 (int)item
->Revision
, (int)item
->Length
);
2635 } else if (item
->RangeStart
> item
->RangeEnd
) {
2637 "?boot: invalid proximity domain structure in MSCT "
2638 "with RangeStart(%u), RangeEnd(%u).\n",
2639 item
->RangeStart
, item
->RangeEnd
);
2641 } else if (item
->RangeStart
!= last_seen
) {
2643 * Items must be organized in ascending order of the
2644 * proximity domain enumerations.
2647 "?boot: invalid proximity domain structure in MSCT,"
2648 " items are not orginized in ascending order.\n");
2653 * If ProcessorCapacity is 0 then there would be no CPUs in this
2656 if (item
->ProcessorCapacity
!= 0) {
2657 proc_num
+= (item
->RangeEnd
- item
->RangeStart
+ 1) *
2658 item
->ProcessorCapacity
;
2661 last_seen
= item
->RangeEnd
- item
->RangeStart
+ 1;
2663 * Break out if all proximity domains have been processed.
2664 * Some BIOSes may have unused items at the end of MSCT table.
2666 if (last_seen
> tp
->MaxProximityDomains
) {
2670 if (last_seen
!= tp
->MaxProximityDomains
+ 1) {
2672 "?boot: invalid proximity domain structure in MSCT, "
2673 "proximity domain count doesn't match.\n");
2678 * Set plat-max-ncpus property if it hasn't been set yet.
2680 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2681 if (proc_num
!= 0) {
2682 bsetpropsi(PLAT_MAX_NCPUS_NAME
, proc_num
);
2687 * Use Maximum Physical Address from the MSCT table as upper limit for
2688 * memory hot-adding by default. It may be overridden by value from
2689 * the SRAT table or the "plat-dr-physmax" boot option.
2691 plat_dr_physmax
= btop(tp
->MaxAddress
+ 1);
2694 * Existence of MSCT implies CPU/memory hotplug-capability for the
2697 plat_dr_options
|= PLAT_DR_FEATURE_CPU
;
2698 plat_dr_options
|= PLAT_DR_FEATURE_MEMORY
;
2705 enumerate_xen_cpus()
2707 processorid_t id
, max_id
;
2710 * User-set boot-ncpus overrides enumeration
2712 if (do_bsys_getproplen(NULL
, BOOT_NCPUS_NAME
) >= 0)
2716 * Probe every possible virtual CPU id and remember the
2717 * highest id present; the count of CPUs is one greater
2718 * than this. This tacitly assumes at least cpu 0 is present.
2721 for (id
= 0; id
< MAX_VIRT_CPUS
; id
++)
2722 if (HYPERVISOR_vcpu_op(VCPUOP_is_up
, id
, NULL
) == 0)
2725 bsetpropsi(BOOT_NCPUS_NAME
, max_id
+1);
2732 build_firmware_properties(struct xboot_info
*xbp
)
2734 ACPI_TABLE_HEADER
*tp
= NULL
;
2737 if (xbp
->bi_acpi_rsdp
!= NULL
) {
2738 bsetprop64("acpi-root-tab",
2739 (uint64_t)(uintptr_t)xbp
->bi_acpi_rsdp
);
2742 if (xbp
->bi_smbios
!= NULL
) {
2743 bsetprop64("smbios-address",
2744 (uint64_t)(uintptr_t)xbp
->bi_smbios
);
2747 if ((tp
= find_fw_table(ACPI_SIG_MSCT
)) != NULL
)
2748 msct_ptr
= process_msct((ACPI_TABLE_MSCT
*)tp
);
2752 if ((tp
= find_fw_table(ACPI_SIG_MADT
)) != NULL
)
2753 process_madt((ACPI_TABLE_MADT
*)tp
);
2755 if ((srat_ptr
= (ACPI_TABLE_SRAT
*)
2756 find_fw_table(ACPI_SIG_SRAT
)) != NULL
)
2757 process_srat(srat_ptr
);
2759 if (slit_ptr
= (ACPI_TABLE_SLIT
*)find_fw_table(ACPI_SIG_SLIT
))
2760 process_slit(slit_ptr
);
2762 tp
= find_fw_table(ACPI_SIG_MCFG
);
2764 enumerate_xen_cpus();
2765 if (DOMAIN_IS_INITDOMAIN(xen_info
))
2766 tp
= find_fw_table(ACPI_SIG_MCFG
);
2769 process_mcfg((ACPI_TABLE_MCFG
*)tp
);
2773 * fake up a boot property for deferred early console output
2774 * this is used by both graphical boot and the (developer only)
2775 * USB serial console
2778 defcons_init(size_t size
)
2780 static char *p
= NULL
;
2782 p
= do_bsys_alloc(NULL
, NULL
, size
, MMU_PAGESIZE
);
2784 bsetprop("deferred-console-buf", strlen("deferred-console-buf") + 1,
2791 boot_compinfo(int fd
, struct compinfo
*cbp
)
2794 cbp
->blksize
= MAXBSIZE
;
2798 #define BP_MAX_STRLEN 32
2801 * Get value for given boot property
2804 bootprop_getval(const char *prop_name
, u_longlong_t
*prop_value
)
2807 char str
[BP_MAX_STRLEN
];
2810 boot_prop_len
= BOP_GETPROPLEN(bootops
, prop_name
);
2811 if (boot_prop_len
< 0 || boot_prop_len
> sizeof (str
) ||
2812 BOP_GETPROP(bootops
, prop_name
, str
) < 0 ||
2813 kobj_getvalue(str
, &value
) == -1)
2817 *prop_value
= value
;