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 2018 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 highest available memory in physinstalled
212 size
= P2ROUNDUP(size
, align
);
213 for (; ml
; ml
= ml
->ml_next
) {
214 start
= P2ROUNDUP(ml
->ml_address
, align
);
215 end
= P2ALIGN(ml
->ml_address
+ ml
->ml_size
, align
);
216 if (start
< next_phys
)
217 start
= P2ROUNDUP(next_phys
, align
);
219 end
= P2ALIGN(high_phys
, align
);
223 if (end
- start
< size
)
227 * Early allocations need to use low memory, since
228 * physmem might be further limited by bootenv.rc
230 if (early_allocation
) {
231 if (pa
== 0 || start
< pa
)
239 if (early_allocation
)
240 next_phys
= pa
+ size
;
245 bop_panic("do_bop_phys_alloc(0x%" PRIx64
", 0x%" PRIx64
246 ") Out of memory\n", size
, align
);
251 alloc_vaddr(size_t size
, paddr_t align
)
255 next_virt
= P2ROUNDUP(next_virt
, (uintptr_t)align
);
256 rv
= (uintptr_t)next_virt
;
262 * Allocate virtual memory. The size is always rounded up to a multiple
268 do_bsys_alloc(bootops_t
*bop
, caddr_t virthint
, size_t size
, int align
)
270 paddr_t a
= align
; /* same type as pa for masking */
274 ssize_t s
; /* the aligned size */
276 uint_t is_kernel
= (virthint
!= 0);
278 if (a
< MMU_PAGESIZE
)
281 prom_panic("do_bsys_alloc() incorrect alignment");
282 size
= P2ROUNDUP(size
, MMU_PAGESIZE
);
285 * Use the next aligned virtual address if we weren't given one.
287 if (virthint
== NULL
) {
288 virthint
= (caddr_t
)alloc_vaddr(size
, a
);
289 total_bop_alloc_scratch
+= size
;
291 total_bop_alloc_kernel
+= size
;
295 * allocate the physical memory
297 pa
= do_bop_phys_alloc(size
, a
);
300 * Add the mappings to the page tables, try large pages first.
302 va
= (uintptr_t)virthint
;
305 pgsize
= xbootp
->bi_use_pae
? TWO_MEG
: FOUR_MEG
;
306 if (xbootp
->bi_use_largepage
&& a
== pgsize
) {
307 while (IS_P2ALIGNED(pa
, pgsize
) && IS_P2ALIGNED(va
, pgsize
) &&
309 kbm_map(va
, pa
, level
, is_kernel
);
317 * Map remaining pages use small mappings
320 pgsize
= MMU_PAGESIZE
;
322 kbm_map(va
, pa
, level
, is_kernel
);
331 * Free virtual memory - we'll just ignore these.
335 do_bsys_free(bootops_t
*bop
, caddr_t virt
, size_t size
)
337 bop_printf(NULL
, "do_bsys_free(virt=0x%p, size=0x%lx) ignored\n",
346 do_bsys_ealloc(bootops_t
*bop
, caddr_t virthint
, size_t size
,
347 int align
, int flags
)
349 prom_panic("unsupported call to BOP_EALLOC()\n");
355 bsetprop(char *name
, int nlen
, void *value
, int vlen
)
362 * align the size to 16 byte boundary
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
;
373 * use a bootprop_t at curr_page and link into list
375 b
= (bootprop_t
*)curr_page
;
376 curr_page
+= sizeof (bootprop_t
);
377 curr_space
-= sizeof (bootprop_t
);
382 * follow by name and ending zero byte
384 b
->bp_name
= curr_page
;
385 bcopy(name
, curr_page
, nlen
);
388 curr_space
-= nlen
+ 1;
391 * copy in value, but no ending zero byte
393 b
->bp_value
= curr_page
;
396 bcopy(value
, curr_page
, vlen
);
402 * align new values of curr_page, curr_space
404 while (curr_space
& 0xf) {
411 bsetprops(char *name
, char *value
)
413 bsetprop(name
, strlen(name
), value
, strlen(value
) + 1);
417 bsetprop64(char *name
, uint64_t value
)
419 bsetprop(name
, strlen(name
), (void *)&value
, sizeof (value
));
423 bsetpropsi(char *name
, int value
)
427 (void) snprintf(prop_val
, sizeof (prop_val
), "%d", value
);
428 bsetprops(name
, prop_val
);
432 * to find the size of the buffer to allocate
436 do_bsys_getproplen(bootops_t
*bop
, const char *name
)
440 for (b
= bprops
; b
; b
= b
->bp_next
) {
441 if (strcmp(name
, b
->bp_name
) != 0)
449 * get the value associated with this name
453 do_bsys_getprop(bootops_t
*bop
, const char *name
, void *value
)
457 for (b
= bprops
; b
; b
= b
->bp_next
) {
458 if (strcmp(name
, b
->bp_name
) != 0)
460 bcopy(b
->bp_value
, value
, b
->bp_vlen
);
467 * get the name of the next property in succession from the standalone
471 do_bsys_nextprop(bootops_t
*bop
, char *name
)
476 * A null name is a special signal for the 1st boot property
478 if (name
== NULL
|| strlen(name
) == 0) {
481 return (bprops
->bp_name
);
484 for (b
= bprops
; b
; b
= b
->bp_next
) {
485 if (name
!= b
->bp_name
)
496 * Parse numeric value from a string. Understands decimal, hex, octal, - and ~
499 parse_value(char *p
, uint64_t *retval
)
507 if (*p
== '-' || *p
== '~')
514 if (*p
== 'x' || *p
== 'X') {
523 if ('0' <= *p
&& *p
<= '9')
525 else if ('a' <= *p
&& *p
<= 'f')
526 digit
= 10 + *p
- 'a';
527 else if ('A' <= *p
&& *p
<= 'F')
528 digit
= 10 + *p
- 'A';
533 tmp
= tmp
* radix
+ digit
;
538 else if (adjust
== '~')
545 unprintable(char *value
, int size
)
549 if (size
<= 0 || value
[0] == '\0')
552 for (i
= 0; i
< size
; i
++) {
553 if (value
[i
] == '\0')
554 return (i
!= (size
- 1));
556 if (!isprint(value
[i
]))
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.
568 boot_prop_display(char *buffer
)
573 bop_printf(NULL
, "\nBoot properties:\n");
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
)) {
582 bop_printf(NULL
, "%s\n", buffer
);
585 for (i
= 0; i
< len
; i
++) {
586 bop_printf(NULL
, "%02x", buffer
[i
] & 0xff);
588 bop_printf(NULL
, ".");
590 bop_printf(NULL
, "\n");
595 * 2nd part of building the table of boot properties. This includes:
596 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
598 * lines look like one of:
600 * ^# comment till end of line
601 * setprop name 'value'
603 * setprop name "value"
605 * we do single character I/O since this is really just looking at memory
608 boot_prop_finish(void)
618 char *inputdev
; /* these override the command line if serial ports */
625 if (!DOMAIN_IS_INITDOMAIN(xen_info
))
629 DBG_MSG("Opening /boot/solaris/bootenv.rc\n");
630 fd
= BRD_OPEN(bfs_ops
, "/boot/solaris/bootenv.rc", 0);
633 line
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
640 bytes_read
= BRD_READ(bfs_ops
, fd
, line
+ c
, 1);
641 if (bytes_read
== 0) {
652 * ignore comment lines
655 while (ISSPACE(line
[c
]))
657 if (line
[c
] == '#' || line
[c
] == 0)
661 * must have "setprop " or "setprop\t"
663 if (strncmp(line
+ c
, "setprop ", 8) != 0 &&
664 strncmp(line
+ c
, "setprop\t", 8) != 0)
667 while (ISSPACE(line
[c
]))
673 * gather up the property name
677 while (line
[c
] && !ISSPACE(line
[c
]))
681 * gather up the value, if any
685 while (ISSPACE(line
[c
]))
689 while (line
[c
] && !ISSPACE(line
[c
]))
693 if (v_len
>= 2 && value
[0] == value
[v_len
- 1] &&
694 (value
[0] == '\'' || value
[0] == '"')) {
705 * ignore "boot-file" property, it's now meaningless
707 if (strcmp(name
, "boot-file") == 0)
709 if (strcmp(name
, "boot-args") == 0 &&
710 strlen(boot_args
) > 0)
714 * If a property was explicitly set on the command line
715 * it will override a setting in bootenv.rc
717 if (do_bsys_getproplen(NULL
, name
) > 0)
720 bsetprop(name
, n_len
, value
, v_len
+ 1);
724 (void) BRD_CLOSE(bfs_ops
, fd
);
727 * Check if we have to limit the boot time allocator
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
;
737 early_allocation
= 0;
740 * check to see if we have to override the default value of the console
744 v_len
= do_bsys_getproplen(NULL
, "input-device");
746 (void) do_bsys_getprop(NULL
, "input-device", inputdev
);
751 outputdev
= inputdev
+ v_len
+ 1;
752 v_len
= do_bsys_getproplen(NULL
, "output-device");
754 (void) do_bsys_getprop(NULL
, "output-device",
758 outputdev
[v_len
] = 0;
760 consoledev
= outputdev
+ v_len
+ 1;
761 v_len
= do_bsys_getproplen(NULL
, "console");
763 (void) do_bsys_getprop(NULL
, "console", consoledev
);
764 if (post_fastreboot
&&
765 strcmp(consoledev
, "graphics") == 0) {
766 bsetprops("console", "text");
767 v_len
= strlen("text");
768 bcopy("text", consoledev
, v_len
);
773 consoledev
[v_len
] = 0;
774 bcons_init2(inputdev
, outputdev
, consoledev
);
777 * Ensure console property exists
778 * If not create it as "hypervisor"
780 v_len
= do_bsys_getproplen(NULL
, "console");
782 bsetprops("console", "hypervisor");
783 inputdev
= outputdev
= consoledev
= "hypervisor";
784 bcons_init2(inputdev
, outputdev
, consoledev
);
787 if (find_boot_prop("prom_debug") || kbm_debug
)
788 boot_prop_display(line
);
792 * print formatted output
797 bop_printf(bootops_t
*bop
, const char *fmt
, ...)
801 if (have_console
== 0)
805 (void) vsnprintf(buffer
, BUFFERSIZE
, fmt
, ap
);
811 * Another panic() variant; this one can be used even earlier during boot than
816 bop_panic(const char *fmt
, ...)
821 bop_printf(NULL
, fmt
, ap
);
824 bop_printf(NULL
, "\nPress any key to reboot.\n");
825 (void) bcons_getchar();
826 bop_printf(NULL
, "Resetting...\n");
831 * Do a real mode interrupt BIOS call
833 typedef struct bios_regs
{
834 unsigned short ax
, bx
, cx
, dx
, si
, di
, bp
, es
, ds
;
836 typedef int (*bios_func_t
)(int, bios_regs_t
*);
840 do_bsys_doint(bootops_t
*bop
, int intnum
, struct bop_regs
*rp
)
843 prom_panic("unsupported call to BOP_DOINT()\n");
845 static int firsttime
= 1;
846 bios_func_t bios_func
= (bios_func_t
)(void *)(uintptr_t)0x5000;
850 * We're about to disable paging; we shouldn't be PCID enabled.
852 if (getcr4() & CR4_PCIDE
)
853 prom_panic("do_bsys_doint() with PCID enabled\n");
856 * The first time we do this, we have to copy the pre-packaged
857 * low memory bios call code image into place.
860 extern char bios_image
[];
861 extern uint32_t bios_size
;
863 bcopy(bios_image
, (void *)bios_func
, bios_size
);
867 br
.ax
= rp
->eax
.word
.ax
;
868 br
.bx
= rp
->ebx
.word
.bx
;
869 br
.cx
= rp
->ecx
.word
.cx
;
870 br
.dx
= rp
->edx
.word
.dx
;
871 br
.bp
= rp
->ebp
.word
.bp
;
872 br
.si
= rp
->esi
.word
.si
;
873 br
.di
= rp
->edi
.word
.di
;
877 DBG_MSG("Doing BIOS call...");
881 rp
->eflags
= bios_func(intnum
, &br
);
884 rp
->eax
.word
.ax
= br
.ax
;
885 rp
->ebx
.word
.bx
= br
.bx
;
886 rp
->ecx
.word
.cx
= br
.cx
;
887 rp
->edx
.word
.dx
= br
.dx
;
888 rp
->ebp
.word
.bp
= br
.bp
;
889 rp
->esi
.word
.si
= br
.si
;
890 rp
->edi
.word
.di
= br
.di
;
896 static struct boot_syscalls bop_sysp
= {
908 static char namebuf
[32];
911 xen_parse_props(char *s
, char *prop_map
[], int n_prop
)
913 char **prop_name
= prop_map
;
918 while ((*cp
!= NULL
) && (*cp
!= ':'))
921 if ((scp
!= cp
) && (*prop_name
!= NULL
)) {
923 bsetprops(*prop_name
, scp
);
929 } while (n_prop
> 0);
932 #define VBDPATHLEN 64
935 * parse the 'xpv-root' property to create properties used by
939 xen_vbdroot_props(char *s
)
941 char vbdpath
[VBDPATHLEN
] = "/xpvd/xdf@";
942 const char lnamefix
[] = "/dev/dsk/c0d";
949 pnp
= vbdpath
+ strlen(vbdpath
);
950 prop_p
= s
+ strlen(lnamefix
);
951 while ((*prop_p
!= '\0') && (*prop_p
!= 's') && (*prop_p
!= 'p'))
952 addr
= addr
* 10 + *prop_p
++ - '0';
953 (void) snprintf(pnp
, VBDPATHLEN
, "%lx", addr
);
954 pnp
= vbdpath
+ strlen(vbdpath
);
957 else if (*prop_p
== 'p')
960 ASSERT(0); /* shouldn't be here */
962 ASSERT(*prop_p
!= '\0');
963 if (ISDIGIT(*prop_p
)) {
964 minor
= *prop_p
- '0';
966 if (ISDIGIT(*prop_p
)) {
967 minor
= minor
* 10 + *prop_p
- '0';
970 /* malformed root path, use 0 as default */
973 ASSERT(minor
< 16); /* at most 16 partitions */
978 bsetprops("fstype", "ufs");
979 bsetprops("bootpath", vbdpath
);
981 DBG_MSG("VBD bootpath set to ");
987 * parse the xpv-nfsroot property to create properties used by
991 xen_nfsroot_props(char *s
)
994 BP_SERVER_IP
, /* server IP address */
995 BP_SERVER_NAME
, /* server hostname */
996 BP_SERVER_PATH
, /* root path */
998 int n_prop
= sizeof (prop_map
) / sizeof (prop_map
[0]);
1000 bsetprop("fstype", 6, "nfs", 4);
1002 xen_parse_props(s
, prop_map
, n_prop
);
1005 * If a server name wasn't specified, use a default.
1007 if (do_bsys_getproplen(NULL
, BP_SERVER_NAME
) == -1)
1008 bsetprops(BP_SERVER_NAME
, "unknown");
1012 * Extract our IP address, etc. from the "xpv-ip" property.
1015 xen_ip_props(char *s
)
1017 char *prop_map
[] = {
1018 BP_HOST_IP
, /* IP address */
1019 NULL
, /* NFS server IP address (ignored in */
1020 /* favour of xpv-nfsroot) */
1021 BP_ROUTER_IP
, /* IP gateway */
1022 BP_SUBNET_MASK
, /* IP subnet mask */
1023 "xpv-hostname", /* hostname (ignored) */
1024 BP_NETWORK_INTERFACE
, /* interface name */
1025 "xpv-hcp", /* host configuration protocol */
1027 int n_prop
= sizeof (prop_map
) / sizeof (prop_map
[0]);
1028 char ifname
[IFNAMSIZ
];
1030 xen_parse_props(s
, prop_map
, n_prop
);
1033 * A Linux dom0 administrator expects all interfaces to be
1034 * called "ethX", which is not the case here.
1036 * If the interface name specified is "eth0", presume that
1037 * this is really intended to be "xnf0" (the first domU ->
1038 * dom0 interface for this domain).
1040 if ((do_bsys_getprop(NULL
, BP_NETWORK_INTERFACE
, ifname
) == 0) &&
1041 (strcmp("eth0", ifname
) == 0)) {
1042 bsetprops(BP_NETWORK_INTERFACE
, "xnf0");
1044 "network interface name 'eth0' replaced with 'xnf0'\n");
1051 setup_rarp_props(struct sol_netinfo
*sip
)
1053 char buf
[BUFLEN
]; /* to hold ip/mac addrs */
1056 val
= (uint8_t *)&sip
->sn_ciaddr
;
1057 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1058 val
[0], val
[1], val
[2], val
[3]);
1059 bsetprops(BP_HOST_IP
, buf
);
1061 val
= (uint8_t *)&sip
->sn_siaddr
;
1062 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1063 val
[0], val
[1], val
[2], val
[3]);
1064 bsetprops(BP_SERVER_IP
, buf
);
1066 if (sip
->sn_giaddr
!= 0) {
1067 val
= (uint8_t *)&sip
->sn_giaddr
;
1068 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1069 val
[0], val
[1], val
[2], val
[3]);
1070 bsetprops(BP_ROUTER_IP
, buf
);
1073 if (sip
->sn_netmask
!= 0) {
1074 val
= (uint8_t *)&sip
->sn_netmask
;
1075 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1076 val
[0], val
[1], val
[2], val
[3]);
1077 bsetprops(BP_SUBNET_MASK
, buf
);
1080 if (sip
->sn_mactype
!= 4 || sip
->sn_maclen
!= 6) {
1081 bop_printf(NULL
, "unsupported mac type %d, mac len %d\n",
1082 sip
->sn_mactype
, sip
->sn_maclen
);
1084 val
= sip
->sn_macaddr
;
1085 (void) snprintf(buf
, BUFLEN
, "%x:%x:%x:%x:%x:%x",
1086 val
[0], val
[1], val
[2], val
[3], val
[4], val
[5]);
1087 bsetprops(BP_BOOT_MAC
, buf
);
1094 build_panic_cmdline(const char *cmd
, int cmdlen
)
1099 arglen
= sizeof (fastreboot_onpanic_args
);
1101 * If we allready have fastreboot-onpanic set to zero,
1102 * don't add them again.
1104 if ((proplen
= do_bsys_getproplen(NULL
, FASTREBOOT_ONPANIC
)) > 0 &&
1105 proplen
<= sizeof (fastreboot_onpanic_cmdline
)) {
1106 (void) do_bsys_getprop(NULL
, FASTREBOOT_ONPANIC
,
1107 fastreboot_onpanic_cmdline
);
1108 if (FASTREBOOT_ONPANIC_NOTSET(fastreboot_onpanic_cmdline
))
1113 * construct fastreboot_onpanic_cmdline
1115 if (cmdlen
+ arglen
> sizeof (fastreboot_onpanic_cmdline
)) {
1116 DBG_MSG("Command line too long: clearing "
1117 FASTREBOOT_ONPANIC
"\n");
1118 fastreboot_onpanic
= 0;
1120 bcopy(cmd
, fastreboot_onpanic_cmdline
, cmdlen
);
1122 bcopy(fastreboot_onpanic_args
,
1123 fastreboot_onpanic_cmdline
+ cmdlen
, arglen
);
1125 fastreboot_onpanic_cmdline
[cmdlen
] = 0;
1132 * Construct boot command line for Fast Reboot. The saved_cmdline
1133 * is also reported by "eeprom bootcmd".
1136 build_fastboot_cmdline(struct xboot_info
*xbp
)
1138 saved_cmdline_len
= strlen(xbp
->bi_cmdline
) + 1;
1139 if (saved_cmdline_len
> FASTBOOT_SAVED_CMDLINE_LEN
) {
1140 DBG(saved_cmdline_len
);
1141 DBG_MSG("Command line too long: clearing fastreboot_capable\n");
1142 fastreboot_capable
= 0;
1144 bcopy((void *)(xbp
->bi_cmdline
), (void *)saved_cmdline
,
1146 saved_cmdline
[saved_cmdline_len
- 1] = '\0';
1147 build_panic_cmdline(saved_cmdline
, saved_cmdline_len
- 1);
1152 * Save memory layout, disk drive information, unix and boot archive sizes for
1156 save_boot_info(struct xboot_info
*xbi
)
1158 multiboot_info_t
*mbi
= xbi
->bi_mb_info
;
1159 struct boot_modules
*modp
;
1162 bcopy(mbi
, &saved_mbi
, sizeof (multiboot_info_t
));
1163 if (mbi
->mmap_length
> sizeof (saved_mmap
)) {
1164 DBG_MSG("mbi->mmap_length too big: clearing "
1165 "fastreboot_capable\n");
1166 fastreboot_capable
= 0;
1168 bcopy((void *)(uintptr_t)mbi
->mmap_addr
, (void *)saved_mmap
,
1172 if ((mbi
->flags
& MB_INFO_DRIVE_INFO
) != 0) {
1173 if (mbi
->drives_length
> sizeof (saved_drives
)) {
1174 DBG(mbi
->drives_length
);
1175 DBG_MSG("mbi->drives_length too big: clearing "
1176 "fastreboot_capable\n");
1177 fastreboot_capable
= 0;
1179 bcopy((void *)(uintptr_t)mbi
->drives_addr
,
1180 (void *)saved_drives
, mbi
->drives_length
);
1183 saved_mbi
.drives_length
= 0;
1184 saved_mbi
.drives_addr
= NULL
;
1188 * Current file sizes. Used by fastboot.c to figure out how much
1189 * memory to reserve for panic reboot.
1190 * Use the module list from the dboot-constructed xboot_info
1191 * instead of the list referenced by the multiboot structure
1192 * because that structure may not be addressable now.
1194 saved_file_size
[FASTBOOT_NAME_UNIX
] = FOUR_MEG
- PAGESIZE
;
1195 for (i
= 0, modp
= (struct boot_modules
*)(uintptr_t)xbi
->bi_modules
;
1196 i
< xbi
->bi_module_cnt
; i
++, modp
++) {
1197 saved_file_size
[FASTBOOT_NAME_BOOTARCHIVE
] += modp
->bm_size
;
1203 * Import boot environment module variables as properties, applying
1204 * blacklist filter for variables we know we will not use.
1206 * Since the environment can be relatively large, containing many variables
1207 * used only for boot loader purposes, we will use a blacklist based filter.
1208 * To keep the blacklist from growing too large, we use prefix based filtering.
1209 * This is possible because in many cases, the loader variable names are
1210 * using a structured layout.
1212 * We will not overwrite already set properties.
1214 static struct bop_blacklist
{
1215 const char *bl_name
;
1217 } bop_prop_blacklist
[] = {
1218 { "ISADIR", sizeof ("ISADIR") },
1219 { "acpi", sizeof ("acpi") },
1220 { "autoboot_delay", sizeof ("autoboot_delay") },
1221 { "autoboot_delay", sizeof ("autoboot_delay") },
1222 { "beansi_", sizeof ("beansi_") },
1223 { "beastie", sizeof ("beastie") },
1224 { "bemenu", sizeof ("bemenu") },
1225 { "boot.", sizeof ("boot.") },
1226 { "bootenv", sizeof ("bootenv") },
1227 { "currdev", sizeof ("currdev") },
1228 { "dhcp.", sizeof ("dhcp.") },
1229 { "interpret", sizeof ("interpret") },
1230 { "kernel", sizeof ("kernel") },
1231 { "loaddev", sizeof ("loaddev") },
1232 { "loader_", sizeof ("loader_") },
1233 { "module_path", sizeof ("module_path") },
1234 { "nfs.", sizeof ("nfs.") },
1235 { "pcibios", sizeof ("pcibios") },
1236 { "prompt", sizeof ("prompt") },
1237 { "smbios", sizeof ("smbios") },
1238 { "tem", sizeof ("tem") },
1239 { "twiddle_divisor", sizeof ("twiddle_divisor") },
1240 { "zfs_be", sizeof ("zfs_be") },
1244 * Match the name against prefixes in above blacklist. If the match was
1245 * found, this name is blacklisted.
1248 name_is_blacklisted(const char *name
)
1252 n
= sizeof (bop_prop_blacklist
) / sizeof (bop_prop_blacklist
[0]);
1253 for (i
= 0; i
< n
; i
++) {
1254 if (strncmp(bop_prop_blacklist
[i
].bl_name
, name
,
1255 bop_prop_blacklist
[i
].bl_name_len
- 1) == 0) {
1263 process_boot_environment(struct boot_modules
*benv
)
1265 char *env
, *ptr
, *name
, *value
;
1266 uint32_t size
, name_len
, value_len
;
1268 if (benv
== NULL
|| benv
->bm_type
!= BMT_ENV
)
1270 ptr
= env
= benv
->bm_addr
;
1271 size
= benv
->bm_size
;
1275 while (*ptr
!= '=') {
1277 if (ptr
> env
+ size
) /* Something is very wrong. */
1280 name_len
= ptr
- name
;
1281 if (sizeof (buffer
) <= name_len
)
1284 (void) strncpy(buffer
, name
, sizeof (buffer
));
1285 buffer
[name_len
] = '\0';
1290 while ((uintptr_t)ptr
- (uintptr_t)env
< size
) {
1293 value_len
= (uintptr_t)ptr
- (uintptr_t)env
;
1299 /* Did we reach the end of the module? */
1306 /* Is this property already set? */
1307 if (do_bsys_getproplen(NULL
, name
) >= 0)
1310 if (name_is_blacklisted(name
) == B_TRUE
)
1313 /* Create new property. */
1314 bsetprops(name
, value
);
1316 /* Avoid reading past the module end. */
1317 if (size
<= (uintptr_t)ptr
- (uintptr_t)env
)
1319 } while (*ptr
!= '\0');
1323 * 1st pass at building the table of boot properties. This includes:
1324 * - values set on the command line: -B a=x,b=y,c=z ....
1325 * - known values we just compute (ie. from xbp)
1326 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
1328 * the grub command line looked like:
1329 * kernel boot-file [-B prop=value[,prop=value]...] [boot-args]
1331 * whoami is the same as boot-file
1334 build_boot_properties(struct xboot_info
*xbp
)
1340 struct boot_modules
*bm
, *rdbm
, *benv
= NULL
;
1347 static int stdout_val
= 0;
1348 uchar_t boot_device
;
1353 * These have to be done first, so that kobj_mount_root() works
1355 DBG_MSG("Building boot properties\n");
1356 propbuf
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, 0);
1357 DBG((uintptr_t)propbuf
);
1358 if (xbp
->bi_module_cnt
> 0) {
1359 bm
= xbp
->bi_modules
;
1361 for (midx
= i
= 0; i
< xbp
->bi_module_cnt
; i
++) {
1362 if (bm
[i
].bm_type
== BMT_ROOTFS
) {
1366 if (bm
[i
].bm_type
== BMT_HASH
|| bm
[i
].bm_name
== NULL
)
1369 if (bm
[i
].bm_type
== BMT_ENV
) {
1376 (void) snprintf(modid
, sizeof (modid
),
1377 "module-name-%u", midx
);
1378 bsetprops(modid
, (char *)bm
[i
].bm_name
);
1379 (void) snprintf(modid
, sizeof (modid
),
1380 "module-addr-%u", midx
);
1381 bsetprop64(modid
, (uint64_t)(uintptr_t)bm
[i
].bm_addr
);
1382 (void) snprintf(modid
, sizeof (modid
),
1383 "module-size-%u", midx
);
1384 bsetprop64(modid
, (uint64_t)bm
[i
].bm_size
);
1388 bsetprop64("ramdisk_start",
1389 (uint64_t)(uintptr_t)rdbm
->bm_addr
);
1390 bsetprop64("ramdisk_end",
1391 (uint64_t)(uintptr_t)rdbm
->bm_addr
+ rdbm
->bm_size
);
1396 * If there are any boot time modules or hashes present, then disable
1399 if (xbp
->bi_module_cnt
> 1) {
1400 fastreboot_disable(FBNS_BOOTMOD
);
1405 * Disable fast reboot if we're using the Multiboot 2 boot protocol,
1406 * since we don't currently support MB2 info and module relocation.
1407 * Note that fast reboot will have already been disabled if multiple
1408 * modules are present, since the current implementation assumes that
1409 * we only have a single module, the boot_archive.
1411 if (xbp
->bi_mb_version
!= 1) {
1412 fastreboot_disable(FBNS_MULTIBOOT2
);
1416 DBG_MSG("Parsing command line for boot properties\n");
1417 value
= xbp
->bi_cmdline
;
1420 * allocate memory to collect boot_args into
1422 boot_arg_len
= strlen(xbp
->bi_cmdline
) + 1;
1423 boot_args
= do_bsys_alloc(NULL
, NULL
, boot_arg_len
, MMU_PAGESIZE
);
1429 * Xen puts a lot of device information in front of the kernel name
1430 * let's grab them and make them boot properties. The first
1431 * string w/o an "=" in it will be the boot-file property.
1433 (void) strcpy(namebuf
, "xpv-");
1436 * get to next property
1438 while (ISSPACE(*value
))
1444 while (*value
&& !ISSPACE(*value
) && *value
!= '=') {
1447 if (*value
!= '=') { /* no "=" in the property */
1451 name_len
= value
- name
;
1457 while (value
[value_len
] && !ISSPACE(value
[value_len
])) {
1461 * build property name with "xpv-" prefix
1463 if (name_len
+ 4 > 32) { /* skip if name too long */
1467 bcopy(name
, &namebuf
[4], name_len
);
1469 namebuf
[name_len
] = 0;
1470 bcopy(value
, propbuf
, value_len
);
1471 propbuf
[value_len
] = 0;
1472 bsetprops(namebuf
, propbuf
);
1475 * xpv-root is set to the logical disk name of the xen
1476 * VBD when booting from a disk-based filesystem.
1478 if (strcmp(namebuf
, "xpv-root") == 0)
1479 xen_vbdroot_props(propbuf
);
1481 * While we're here, if we have a "xpv-nfsroot" property
1482 * then we need to set "fstype" to "nfs" so we mount
1483 * our root from the nfs server. Also parse the xpv-nfsroot
1484 * property to create the properties that nfs_mountroot will
1485 * need to find the root and mount it.
1487 if (strcmp(namebuf
, "xpv-nfsroot") == 0)
1488 xen_nfsroot_props(propbuf
);
1490 if (strcmp(namebuf
, "xpv-ip") == 0)
1491 xen_ip_props(propbuf
);
1496 while (ISSPACE(*value
))
1499 * value now points at the boot-file
1502 while (value
[value_len
] && !ISSPACE(value
[value_len
]))
1504 if (value_len
> 0) {
1506 bcopy(value
, whoami
, value_len
);
1507 whoami
[value_len
] = 0;
1508 bsetprops("boot-file", whoami
);
1510 * strip leading path stuff from whoami, so running from
1511 * PXE/miniroot makes sense.
1513 if (strstr(whoami
, "/platform/") != NULL
)
1514 whoami
= strstr(whoami
, "/platform/");
1515 bsetprops("whoami", whoami
);
1519 * Values forcibly set boot properties on the command line via -B.
1520 * Allow use of quotes in values. Other stuff goes on kernel
1523 name
= value
+ value_len
;
1524 while (*name
!= 0) {
1526 * anything not " -B" is copied to the command line
1528 if (!ISSPACE(name
[0]) || name
[1] != '-' || name
[2] != 'B') {
1529 boot_args
[boot_arg_len
++] = *name
;
1530 boot_args
[boot_arg_len
] = 0;
1536 * skip the " -B" and following white space
1539 while (ISSPACE(*name
))
1541 while (*name
&& !ISSPACE(*name
)) {
1542 value
= strstr(name
, "=");
1545 name_len
= value
- name
;
1549 for (; ; ++value_len
) {
1550 if (!value
[value_len
])
1554 * is this value quoted?
1556 if (value_len
== 0 &&
1557 (value
[0] == '\'' || value
[0] == '"')) {
1563 * In the quote accept any character,
1564 * but look for ending quote.
1567 if (value
[value_len
] == quoted
)
1573 * a comma or white space ends the value
1575 if (value
[value_len
] == ',' ||
1576 ISSPACE(value
[value_len
]))
1580 if (value_len
== 0) {
1581 bsetprop(name
, name_len
, "true", 5);
1585 if (v
[0] == v
[l
- 1] &&
1586 (v
[0] == '\'' || v
[0] == '"')) {
1590 bcopy(v
, propbuf
, l
);
1592 bsetprop(name
, name_len
, propbuf
,
1595 name
= value
+ value_len
;
1596 while (*name
== ',')
1602 * set boot-args property
1603 * 1275 name is bootargs, so set
1606 bsetprops("boot-args", boot_args
);
1607 bsetprops("bootargs", boot_args
);
1609 process_boot_environment(benv
);
1613 * Build boot command line for Fast Reboot
1615 build_fastboot_cmdline(xbp
);
1617 if (xbp
->bi_mb_version
== 1) {
1618 multiboot_info_t
*mbi
= xbp
->bi_mb_info
;
1620 struct sol_netinfo
*sip
;
1623 * set the BIOS boot device from GRUB
1628 * Save various boot information for Fast Reboot
1630 save_boot_info(xbp
);
1632 if (mbi
!= NULL
&& mbi
->flags
& MB_INFO_BOOTDEV
) {
1633 boot_device
= mbi
->boot_device
>> 24;
1634 if (boot_device
== 0x20)
1636 str
[0] = (boot_device
>> 4) + '0';
1637 str
[1] = (boot_device
& 0xf) + '0';
1639 bsetprops("bios-boot-device", str
);
1645 * In the netboot case, drives_info is overloaded with the
1646 * dhcp ack. This is not multiboot compliant and requires
1649 if (netboot
&& mbi
->drives_length
!= 0) {
1650 sip
= (struct sol_netinfo
*)(uintptr_t)mbi
->drives_addr
;
1651 if (sip
->sn_infotype
== SN_TYPE_BOOTP
)
1652 bsetprop("bootp-response",
1653 sizeof ("bootp-response"),
1654 (void *)(uintptr_t)mbi
->drives_addr
,
1655 mbi
->drives_length
);
1656 else if (sip
->sn_infotype
== SN_TYPE_RARP
)
1657 setup_rarp_props(sip
);
1660 multiboot2_info_header_t
*mbi
= xbp
->bi_mb_info
;
1661 multiboot_tag_bootdev_t
*bootdev
= NULL
;
1662 multiboot_tag_network_t
*netdev
= NULL
;
1665 bootdev
= dboot_multiboot2_find_tag(mbi
,
1666 MULTIBOOT_TAG_TYPE_BOOTDEV
);
1667 netdev
= dboot_multiboot2_find_tag(mbi
,
1668 MULTIBOOT_TAG_TYPE_NETWORK
);
1670 if (bootdev
!= NULL
) {
1671 DBG(bootdev
->mb_biosdev
);
1672 boot_device
= bootdev
->mb_biosdev
;
1673 str
[0] = (boot_device
>> 4) + '0';
1674 str
[1] = (boot_device
& 0xf) + '0';
1676 bsetprops("bios-boot-device", str
);
1678 if (netdev
!= NULL
) {
1679 bsetprop("bootp-response", sizeof ("bootp-response"),
1680 (void *)(uintptr_t)netdev
->mb_dhcpack
,
1682 sizeof (multiboot_tag_network_t
));
1686 bsetprop("stdout", strlen("stdout"),
1687 &stdout_val
, sizeof (stdout_val
));
1691 * more conjured up values for made up things....
1694 bsetprops("mfg-name", "i86xpv");
1695 bsetprops("impl-arch-name", "i86xpv");
1697 bsetprops("mfg-name", "i86pc");
1698 bsetprops("impl-arch-name", "i86pc");
1702 * Build firmware-provided system properties
1704 build_firmware_properties(xbp
);
1709 * Find out what these are:
1710 * - cpuid_feature_ecx_include
1711 * - cpuid_feature_ecx_exclude
1712 * - cpuid_feature_edx_include
1713 * - cpuid_feature_edx_exclude
1715 * Find out what these are in multiboot:
1723 * Under the Hypervisor, memory usable for DMA may be scarce. One
1724 * very likely large pool of DMA friendly memory is occupied by
1725 * the boot_archive, as it was loaded by grub into low MFNs.
1727 * Here we free up that memory by copying the boot archive to what are
1728 * likely higher MFN pages and then swapping the mfn/pfn mappings.
1730 #define PFN_2GIG 0x80000
1732 relocate_boot_archive(struct xboot_info
*xbp
)
1734 mfn_t max_mfn
= HYPERVISOR_memory_op(XENMEM_maximum_ram_page
, NULL
);
1735 struct boot_modules
*bm
= xbp
->bi_modules
;
1746 int mmu_update_return
;
1751 * If all MFN's are below 2Gig, don't bother doing this.
1753 if (max_mfn
< PFN_2GIG
)
1755 if (xbp
->bi_module_cnt
< 1) {
1756 DBG_MSG("no boot_archive!");
1760 DBG_MSG("moving boot_archive to high MFN memory\n");
1761 va
= (uintptr_t)bm
->bm_addr
;
1763 slop
= va
& MMU_PAGEOFFSET
;
1765 va
+= MMU_PAGESIZE
- slop
;
1766 len
-= MMU_PAGESIZE
- slop
;
1768 len
= P2ALIGN(len
, MMU_PAGESIZE
);
1771 * Go through all boot_archive pages, swapping any low MFN pages
1772 * with memory at next_phys.
1776 va_pfn
= mmu_btop(va
- ONE_GIG
);
1777 va_mfn
= mfn_list
[va_pfn
];
1778 if (mfn_list
[va_pfn
] < PFN_2GIG
) {
1779 copy
= kbm_remap_window(next_phys
, 1);
1780 bcopy((void *)va
, copy
, MMU_PAGESIZE
);
1781 copy_pfn
= mmu_btop(next_phys
);
1782 copy_mfn
= mfn_list
[copy_pfn
];
1784 pte
= mfn_to_ma(copy_mfn
) | PT_NOCONSIST
| PT_VALID
;
1785 if (HYPERVISOR_update_va_mapping(va
, pte
,
1786 UVMF_INVLPG
| UVMF_LOCAL
))
1787 bop_panic("relocate_boot_archive(): "
1788 "HYPERVISOR_update_va_mapping() failed");
1790 mfn_list
[va_pfn
] = copy_mfn
;
1791 mfn_list
[copy_pfn
] = va_mfn
;
1793 t
[0].ptr
= mfn_to_ma(copy_mfn
) | MMU_MACHPHYS_UPDATE
;
1795 t
[1].ptr
= mfn_to_ma(va_mfn
) | MMU_MACHPHYS_UPDATE
;
1796 t
[1].val
= copy_pfn
;
1797 if (HYPERVISOR_mmu_update(t
, 2, &mmu_update_return
,
1798 DOMID_SELF
) != 0 || mmu_update_return
!= 2)
1799 bop_panic("relocate_boot_archive(): "
1800 "HYPERVISOR_mmu_update() failed");
1802 next_phys
+= MMU_PAGESIZE
;
1805 len
-= MMU_PAGESIZE
;
1808 DBG_MSG("Relocated pages:\n");
1810 DBG_MSG("Out of total pages:\n");
1817 * simple description of a stack frame (args are 32 bit only currently)
1819 typedef struct bop_frame
{
1820 struct bop_frame
*old_frame
;
1826 bop_traceback(bop_frame_t
*frame
)
1833 bop_printf(NULL
, "Stack traceback:\n");
1834 for (cnt
= 0; cnt
< 30; ++cnt
) { /* up to 30 frames */
1835 pc
= frame
->retaddr
;
1838 ksym
= kobj_getsymname(pc
, &off
);
1840 bop_printf(NULL
, " %s+%lx", ksym
, off
);
1842 bop_printf(NULL
, " 0x%lx", pc
);
1844 frame
= frame
->old_frame
;
1846 bop_printf(NULL
, "\n");
1849 bop_printf(NULL
, "\n");
1854 ulong_t error_code
; /* optional */
1863 bop_trap(ulong_t
*tfp
)
1865 struct trapframe
*tf
= (struct trapframe
*)tfp
;
1866 bop_frame_t fakeframe
;
1867 static int depth
= 0;
1870 * Check for an infinite loop of traps.
1873 bop_panic("Nested trap");
1875 bop_printf(NULL
, "Unexpected trap\n");
1878 * adjust the tf for optional error_code by detecting the code selector
1880 if (tf
->code_seg
!= B64CODE_SEL
)
1881 tf
= (struct trapframe
*)(tfp
- 1);
1883 bop_printf(NULL
, "error code 0x%lx\n",
1884 tf
->error_code
& 0xffffffff);
1886 bop_printf(NULL
, "instruction pointer 0x%lx\n", tf
->inst_ptr
);
1887 bop_printf(NULL
, "code segment 0x%lx\n", tf
->code_seg
& 0xffff);
1888 bop_printf(NULL
, "flags register 0x%lx\n", tf
->flags_reg
);
1889 bop_printf(NULL
, "return %%rsp 0x%lx\n", tf
->stk_ptr
);
1890 bop_printf(NULL
, "return %%ss 0x%lx\n", tf
->stk_seg
& 0xffff);
1892 /* grab %[er]bp pushed by our code from the stack */
1893 fakeframe
.old_frame
= (bop_frame_t
*)*(tfp
- 3);
1894 fakeframe
.retaddr
= (pc_t
)tf
->inst_ptr
;
1895 bop_printf(NULL
, "Attempting stack backtrace:\n");
1896 bop_traceback(&fakeframe
);
1897 bop_panic("unexpected trap in early boot");
1900 extern void bop_trap_handler(void);
1902 static gate_desc_t
*bop_idt
;
1904 static desctbr_t bop_idt_info
;
1907 * Install a temporary IDT that lets us catch errors in the boot time code.
1908 * We shouldn't get any faults at all while this is installed, so we'll
1909 * just generate a traceback and exit.
1916 bop_idt
= (gate_desc_t
*)
1917 do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
1918 bzero(bop_idt
, MMU_PAGESIZE
);
1919 for (t
= 0; t
< NIDT
; ++t
) {
1921 * Note that since boot runs without a TSS, the
1922 * double fault handler cannot use an alternate stack (64-bit).
1924 set_gatesegd(&bop_idt
[t
], &bop_trap_handler
, B64CODE_SEL
,
1925 SDT_SYSIGT
, TRP_KPL
, 0);
1927 bop_idt_info
.dtr_limit
= (NIDT
* sizeof (gate_desc_t
)) - 1;
1928 bop_idt_info
.dtr_base
= (uintptr_t)bop_idt
;
1929 wr_idtr(&bop_idt_info
);
1931 #endif /* !defined(__xpv) */
1934 * This is where we enter the kernel. It dummies up the boot_ops and
1935 * boot_syscalls vectors and jumps off to _kobj_boot()
1938 _start(struct xboot_info
*xbp
)
1940 bootops_t
*bops
= &bootop
;
1941 extern void _kobj_boot();
1944 * 1st off - initialize the console for any error messages
1948 HYPERVISOR_shared_info
= (void *)xbp
->bi_shared_info
;
1949 xen_info
= xbp
->bi_xen_start_info
;
1953 if (*((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) ==
1955 post_fastreboot
= 1;
1956 *((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) = 0;
1966 if (find_boot_prop("kbm_debug") != NULL
)
1969 DBG_MSG("\n\n*** Entered Solaris in _start() cmdline is: ");
1970 DBG_MSG((char *)xbp
->bi_cmdline
);
1974 * physavail is no longer used by startup
1976 bm
.physinstalled
= xbp
->bi_phys_install
;
1977 bm
.pcimem
= xbp
->bi_pcimem
;
1978 bm
.rsvdmem
= xbp
->bi_rsvdmem
;
1979 bm
.physavail
= NULL
;
1982 * initialize the boot time allocator
1984 next_phys
= xbp
->bi_next_paddr
;
1986 next_virt
= (uintptr_t)xbp
->bi_next_vaddr
;
1988 DBG_MSG("Initializing boot time memory management...");
1991 xen_platform_parameters_t p
;
1993 /* This call shouldn't fail, dboot already did it once. */
1994 (void) HYPERVISOR_xen_version(XENVER_platform_parameters
, &p
);
1995 mfn_to_pfn_mapping
= (pfn_t
*)(xen_virt_start
= p
.virt_start
);
1996 DBG(xen_virt_start
);
2003 * Fill in the bootops vector
2005 bops
->bsys_version
= BO_VERSION
;
2006 bops
->boot_mem
= &bm
;
2007 bops
->bsys_alloc
= do_bsys_alloc
;
2008 bops
->bsys_free
= do_bsys_free
;
2009 bops
->bsys_getproplen
= do_bsys_getproplen
;
2010 bops
->bsys_getprop
= do_bsys_getprop
;
2011 bops
->bsys_nextprop
= do_bsys_nextprop
;
2012 bops
->bsys_printf
= bop_printf
;
2013 bops
->bsys_doint
= do_bsys_doint
;
2016 * BOP_EALLOC() is no longer needed
2018 bops
->bsys_ealloc
= do_bsys_ealloc
;
2022 * On domain 0 we need to free up some physical memory that is
2023 * usable for DMA. Since GRUB loaded the boot_archive, it is
2024 * sitting in low MFN memory. We'll relocated the boot archive
2025 * pages to high PFN memory.
2027 if (DOMAIN_IS_INITDOMAIN(xen_info
))
2028 relocate_boot_archive(xbp
);
2033 * Install an IDT to catch early pagefaults (shouldn't have any).
2034 * Also needed for kmdb.
2040 * Start building the boot properties from the command line
2042 DBG_MSG("Initializing boot properties:\n");
2043 build_boot_properties(xbp
);
2045 if (find_boot_prop("prom_debug") || kbm_debug
) {
2048 value
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
2049 boot_prop_display(value
);
2053 * jump into krtld...
2055 _kobj_boot(&bop_sysp
, NULL
, bops
, NULL
);
2061 no_more_alloc(bootops_t
*bop
, caddr_t virthint
, size_t size
, int align
)
2063 panic("Attempt to bsys_alloc() too late\n");
2069 no_more_free(bootops_t
*bop
, caddr_t virt
, size_t size
)
2071 panic("Attempt to bsys_free() too late\n");
2075 bop_no_more_mem(void)
2077 DBG(total_bop_alloc_scratch
);
2078 DBG(total_bop_alloc_kernel
);
2079 bootops
->bsys_alloc
= no_more_alloc
;
2080 bootops
->bsys_free
= no_more_free
;
2085 * Set ACPI firmware properties
2089 vmap_phys(size_t length
, paddr_t pa
)
2096 pa
= pfn_to_pa(xen_assign_pfn(mmu_btop(pa
))) | (pa
& MMU_PAGEOFFSET
);
2098 start
= P2ALIGN(pa
, MMU_PAGESIZE
);
2099 end
= P2ROUNDUP(pa
+ length
, MMU_PAGESIZE
);
2101 va
= (caddr_t
)alloc_vaddr(len
, MMU_PAGESIZE
);
2102 for (page
= 0; page
< len
; page
+= MMU_PAGESIZE
)
2103 kbm_map((uintptr_t)va
+ page
, start
+ page
, 0, 0);
2104 return (va
+ (pa
& MMU_PAGEOFFSET
));
2108 checksum_table(uint8_t *tp
, size_t len
)
2119 valid_rsdp(ACPI_TABLE_RSDP
*rp
)
2122 /* validate the V1.x checksum */
2123 if (checksum_table((uint8_t *)rp
, ACPI_RSDP_CHECKSUM_LENGTH
) != 0)
2126 /* If pre-ACPI 2.0, this is a valid RSDP */
2127 if (rp
->Revision
< 2)
2130 /* validate the V2.x checksum */
2131 if (checksum_table((uint8_t *)rp
, ACPI_RSDP_XCHECKSUM_LENGTH
) != 0)
2138 * Scan memory range for an RSDP;
2139 * see ACPI 3.0 Spec, 5.2.5.1
2141 static ACPI_TABLE_RSDP
*
2142 scan_rsdp(paddr_t start
, paddr_t end
)
2144 ssize_t len
= end
- start
;
2147 ptr
= vmap_phys(len
, start
);
2149 if (strncmp(ptr
, ACPI_SIG_RSDP
, strlen(ACPI_SIG_RSDP
)) == 0 &&
2150 valid_rsdp((ACPI_TABLE_RSDP
*)ptr
))
2151 return ((ACPI_TABLE_RSDP
*)ptr
);
2153 ptr
+= ACPI_RSDP_SCAN_STEP
;
2154 len
-= ACPI_RSDP_SCAN_STEP
;
2161 * Refer to ACPI 3.0 Spec, section 5.2.5.1 to understand this function
2163 static ACPI_TABLE_RSDP
*
2166 ACPI_TABLE_RSDP
*rsdp
;
2167 uint64_t rsdp_val
= 0;
2171 /* check for "acpi-root-tab" property */
2172 if (do_bsys_getproplen(NULL
, "acpi-root-tab") == sizeof (uint64_t)) {
2173 (void) do_bsys_getprop(NULL
, "acpi-root-tab", &rsdp_val
);
2174 if (rsdp_val
!= 0) {
2175 rsdp
= scan_rsdp(rsdp_val
, rsdp_val
+ sizeof (*rsdp
));
2179 "Using RSDP from bootloader: "
2180 "0x%p\n", (void *)rsdp
);
2188 * Get the EBDA segment and scan the first 1K
2190 ebda_seg
= (uint16_t *)vmap_phys(sizeof (uint16_t),
2191 ACPI_EBDA_PTR_LOCATION
);
2192 ebda_addr
= *ebda_seg
<< 4;
2193 rsdp
= scan_rsdp(ebda_addr
, ebda_addr
+ ACPI_EBDA_WINDOW_SIZE
);
2195 /* if EBDA doesn't contain RSDP, look in BIOS memory */
2196 rsdp
= scan_rsdp(ACPI_HI_RSDP_WINDOW_BASE
,
2197 ACPI_HI_RSDP_WINDOW_BASE
+ ACPI_HI_RSDP_WINDOW_SIZE
);
2201 static ACPI_TABLE_HEADER
*
2202 map_fw_table(paddr_t table_addr
)
2204 ACPI_TABLE_HEADER
*tp
;
2205 size_t len
= MAX(sizeof (*tp
), MMU_PAGESIZE
);
2208 * Map at least a page; if the table is larger than this, remap it
2210 tp
= (ACPI_TABLE_HEADER
*)vmap_phys(len
, table_addr
);
2211 if (tp
->Length
> len
)
2212 tp
= (ACPI_TABLE_HEADER
*)vmap_phys(tp
->Length
, table_addr
);
2216 static ACPI_TABLE_HEADER
*
2217 find_fw_table(char *signature
)
2219 static int revision
= 0;
2220 static ACPI_TABLE_XSDT
*xsdt
;
2223 ACPI_TABLE_RSDP
*rsdp
;
2224 ACPI_TABLE_HEADER
*tp
;
2228 if (strlen(signature
) != ACPI_NAME_SIZE
)
2232 * Reading the ACPI 3.0 Spec, section 5.2.5.3 will help
2233 * understand this code. If we haven't already found the RSDT/XSDT,
2234 * revision will be 0. Find the RSDP and check the revision
2235 * to find out whether to use the RSDT or XSDT. If revision is
2236 * 0 or 1, use the RSDT and set internal revision to 1; if it is 2,
2237 * use the XSDT. If the XSDT address is 0, though, fall back to
2238 * revision 1 and use the RSDT.
2240 if (revision
== 0) {
2241 if ((rsdp
= find_rsdp()) != NULL
) {
2242 revision
= rsdp
->Revision
;
2244 * ACPI 6.0 states that current revision is 2
2245 * from acpi_table_rsdp definition:
2246 * Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+
2253 * Use the XSDT unless BIOS is buggy and
2254 * claims to be rev 2 but has a null XSDT
2257 xsdt_addr
= rsdp
->XsdtPhysicalAddress
;
2262 /* treat RSDP rev 0 as revision 1 internally */
2266 /* use the RSDT for rev 0/1 */
2267 xsdt_addr
= rsdp
->RsdtPhysicalAddress
;
2270 /* unknown revision */
2278 /* cache the XSDT info */
2279 xsdt
= (ACPI_TABLE_XSDT
*)map_fw_table(xsdt_addr
);
2280 len
= (xsdt
->Header
.Length
- sizeof (xsdt
->Header
)) /
2281 ((revision
== 1) ? sizeof (uint32_t) : sizeof (uint64_t));
2285 * Scan the table headers looking for a signature match
2287 for (n
= 0; n
< len
; n
++) {
2288 ACPI_TABLE_RSDT
*rsdt
= (ACPI_TABLE_RSDT
*)xsdt
;
2289 table_addr
= (revision
== 1) ? rsdt
->TableOffsetEntry
[n
] :
2290 xsdt
->TableOffsetEntry
[n
];
2292 if (table_addr
== 0)
2294 tp
= map_fw_table(table_addr
);
2295 if (strncmp(tp
->Signature
, signature
, ACPI_NAME_SIZE
) == 0) {
2303 process_mcfg(ACPI_TABLE_MCFG
*tp
)
2305 ACPI_MCFG_ALLOCATION
*cfg_baap
;
2307 int64_t ecfginfo
[4];
2309 cfg_baap
= (ACPI_MCFG_ALLOCATION
*)((uintptr_t)tp
+ sizeof (*tp
));
2310 cfg_baa_endp
= ((char *)tp
) + tp
->Header
.Length
;
2311 while ((char *)cfg_baap
< cfg_baa_endp
) {
2312 if (cfg_baap
->Address
!= 0 && cfg_baap
->PciSegment
== 0) {
2313 ecfginfo
[0] = cfg_baap
->Address
;
2314 ecfginfo
[1] = cfg_baap
->PciSegment
;
2315 ecfginfo
[2] = cfg_baap
->StartBusNumber
;
2316 ecfginfo
[3] = cfg_baap
->EndBusNumber
;
2317 bsetprop(MCFG_PROPNAME
, strlen(MCFG_PROPNAME
),
2318 ecfginfo
, sizeof (ecfginfo
));
2327 process_madt_entries(ACPI_TABLE_MADT
*tp
, uint32_t *cpu_countp
,
2328 uint32_t *cpu_possible_countp
, uint32_t *cpu_apicid_array
)
2330 ACPI_SUBTABLE_HEADER
*item
, *end
;
2331 uint32_t cpu_count
= 0;
2332 uint32_t cpu_possible_count
= 0;
2335 * Determine number of CPUs and keep track of "final" APIC ID
2336 * for each CPU by walking through ACPI MADT processor list
2338 end
= (ACPI_SUBTABLE_HEADER
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2339 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)tp
+ sizeof (*tp
));
2341 while (item
< end
) {
2342 switch (item
->Type
) {
2343 case ACPI_MADT_TYPE_LOCAL_APIC
: {
2344 ACPI_MADT_LOCAL_APIC
*cpu
=
2345 (ACPI_MADT_LOCAL_APIC
*) item
;
2347 if (cpu
->LapicFlags
& ACPI_MADT_ENABLED
) {
2348 if (cpu_apicid_array
!= NULL
)
2349 cpu_apicid_array
[cpu_count
] = cpu
->Id
;
2352 cpu_possible_count
++;
2355 case ACPI_MADT_TYPE_LOCAL_X2APIC
: {
2356 ACPI_MADT_LOCAL_X2APIC
*cpu
=
2357 (ACPI_MADT_LOCAL_X2APIC
*) item
;
2359 if (cpu
->LapicFlags
& ACPI_MADT_ENABLED
) {
2360 if (cpu_apicid_array
!= NULL
)
2361 cpu_apicid_array
[cpu_count
] =
2365 cpu_possible_count
++;
2370 bop_printf(NULL
, "MADT type %d\n", item
->Type
);
2374 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)item
+ item
->Length
);
2377 *cpu_countp
= cpu_count
;
2378 if (cpu_possible_countp
)
2379 *cpu_possible_countp
= cpu_possible_count
;
2383 process_madt(ACPI_TABLE_MADT
*tp
)
2385 uint32_t cpu_count
= 0;
2386 uint32_t cpu_possible_count
= 0;
2387 uint32_t *cpu_apicid_array
; /* x2APIC ID is 32bit! */
2391 process_madt_entries(tp
, &cpu_count
, &cpu_possible_count
, NULL
);
2393 cpu_apicid_array
= (uint32_t *)do_bsys_alloc(NULL
, NULL
,
2394 cpu_count
* sizeof (*cpu_apicid_array
), MMU_PAGESIZE
);
2395 if (cpu_apicid_array
== NULL
)
2396 bop_panic("Not enough memory for APIC ID array");
2399 process_madt_entries(tp
, NULL
, NULL
, cpu_apicid_array
);
2402 * Make boot property for array of "final" APIC IDs for each
2405 bsetprop(BP_CPU_APICID_ARRAY
, strlen(BP_CPU_APICID_ARRAY
),
2406 cpu_apicid_array
, cpu_count
* sizeof (*cpu_apicid_array
));
2410 * Check whether property plat-max-ncpus is already set.
2412 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2414 * Set plat-max-ncpus to number of maximum possible CPUs given
2415 * in MADT if it hasn't been set.
2416 * There's no formal way to detect max possible CPUs supported
2417 * by platform according to ACPI spec3.0b. So current CPU
2418 * hotplug implementation expects that all possible CPUs will
2419 * have an entry in MADT table and set plat-max-ncpus to number
2420 * of entries in MADT.
2421 * With introducing of ACPI4.0, Maximum System Capability Table
2422 * (MSCT) provides maximum number of CPUs supported by platform.
2423 * If MSCT is unavailable, fall back to old way.
2426 bsetpropsi(PLAT_MAX_NCPUS_NAME
, cpu_possible_count
);
2430 * Set boot property boot-max-ncpus to number of CPUs existing at
2431 * boot time. boot-max-ncpus is mainly used for optimization.
2434 bsetpropsi(BOOT_MAX_NCPUS_NAME
, cpu_count
);
2437 * User-set boot-ncpus overrides firmware count
2439 if (do_bsys_getproplen(NULL
, BOOT_NCPUS_NAME
) >= 0)
2443 * Set boot property boot-ncpus to number of active CPUs given in MADT
2444 * if it hasn't been set yet.
2447 bsetpropsi(BOOT_NCPUS_NAME
, cpu_count
);
2451 process_srat(ACPI_TABLE_SRAT
*tp
)
2453 ACPI_SUBTABLE_HEADER
*item
, *end
;
2455 int proc_num
, mem_num
;
2474 uint64_t maxmem
= 0;
2479 proc_num
= mem_num
= 0;
2480 end
= (ACPI_SUBTABLE_HEADER
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2481 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)tp
+ sizeof (*tp
));
2482 while (item
< end
) {
2483 switch (item
->Type
) {
2484 case ACPI_SRAT_TYPE_CPU_AFFINITY
: {
2485 ACPI_SRAT_CPU_AFFINITY
*cpu
=
2486 (ACPI_SRAT_CPU_AFFINITY
*) item
;
2488 if (!(cpu
->Flags
& ACPI_SRAT_CPU_ENABLED
))
2490 processor
.domain
= cpu
->ProximityDomainLo
;
2491 for (i
= 0; i
< 3; i
++)
2493 cpu
->ProximityDomainHi
[i
] << ((i
+ 1) * 8);
2494 processor
.apic_id
= cpu
->ApicId
;
2495 processor
.sapic_id
= cpu
->LocalSapicEid
;
2496 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2498 bsetprop(prop_name
, strlen(prop_name
), &processor
,
2499 sizeof (processor
));
2503 case ACPI_SRAT_TYPE_MEMORY_AFFINITY
: {
2504 ACPI_SRAT_MEM_AFFINITY
*mem
=
2505 (ACPI_SRAT_MEM_AFFINITY
*)item
;
2507 if (!(mem
->Flags
& ACPI_SRAT_MEM_ENABLED
))
2509 memory
.domain
= mem
->ProximityDomain
;
2510 memory
.addr
= mem
->BaseAddress
;
2511 memory
.length
= mem
->Length
;
2512 memory
.flags
= mem
->Flags
;
2513 (void) snprintf(prop_name
, 30, "acpi-srat-memory-%d",
2515 bsetprop(prop_name
, strlen(prop_name
), &memory
,
2517 if ((mem
->Flags
& ACPI_SRAT_MEM_HOT_PLUGGABLE
) &&
2518 (memory
.addr
+ memory
.length
> maxmem
)) {
2519 maxmem
= memory
.addr
+ memory
.length
;
2524 case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY
: {
2525 ACPI_SRAT_X2APIC_CPU_AFFINITY
*x2cpu
=
2526 (ACPI_SRAT_X2APIC_CPU_AFFINITY
*) item
;
2528 if (!(x2cpu
->Flags
& ACPI_SRAT_CPU_ENABLED
))
2530 x2apic
.domain
= x2cpu
->ProximityDomain
;
2531 x2apic
.x2apic_id
= x2cpu
->ApicId
;
2532 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2534 bsetprop(prop_name
, strlen(prop_name
), &x2apic
,
2541 bop_printf(NULL
, "SRAT type %d\n", item
->Type
);
2545 item
= (ACPI_SUBTABLE_HEADER
*)
2546 (item
->Length
+ (uintptr_t)item
);
2550 * The maximum physical address calculated from the SRAT table is more
2551 * accurate than that calculated from the MSCT table.
2554 plat_dr_physmax
= btop(maxmem
);
2559 process_slit(ACPI_TABLE_SLIT
*tp
)
2563 * Check the number of localities; if it's too huge, we just
2564 * return and locality enumeration code will handle this later,
2567 * Note that the size of the table is the square of the
2568 * number of localities; if the number of localities exceeds
2569 * UINT16_MAX, the table size may overflow an int when being
2570 * passed to bsetprop() below.
2572 if (tp
->LocalityCount
>= SLIT_LOCALITIES_MAX
)
2575 bsetprop(SLIT_NUM_PROPNAME
, strlen(SLIT_NUM_PROPNAME
),
2576 &tp
->LocalityCount
, sizeof (tp
->LocalityCount
));
2577 bsetprop(SLIT_PROPNAME
, strlen(SLIT_PROPNAME
), &tp
->Entry
,
2578 tp
->LocalityCount
* tp
->LocalityCount
);
2581 static ACPI_TABLE_MSCT
*
2582 process_msct(ACPI_TABLE_MSCT
*tp
)
2586 ACPI_MSCT_PROXIMITY
*item
, *end
;
2587 extern uint64_t plat_dr_options
;
2591 end
= (ACPI_MSCT_PROXIMITY
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2592 for (item
= (void *)((uintptr_t)tp
+ tp
->ProximityOffset
);
2594 item
= (void *)(item
->Length
+ (uintptr_t)item
)) {
2596 * Sanity check according to section 5.2.19.1 of ACPI 4.0.
2600 if (item
->Revision
!= 1 || item
->Length
!= 22) {
2602 "?boot: unknown proximity domain structure in MSCT "
2603 "with Revision(%d), Length(%d).\n",
2604 (int)item
->Revision
, (int)item
->Length
);
2606 } else if (item
->RangeStart
> item
->RangeEnd
) {
2608 "?boot: invalid proximity domain structure in MSCT "
2609 "with RangeStart(%u), RangeEnd(%u).\n",
2610 item
->RangeStart
, item
->RangeEnd
);
2612 } else if (item
->RangeStart
!= last_seen
) {
2614 * Items must be organized in ascending order of the
2615 * proximity domain enumerations.
2618 "?boot: invalid proximity domain structure in MSCT,"
2619 " items are not orginized in ascending order.\n");
2624 * If ProcessorCapacity is 0 then there would be no CPUs in this
2627 if (item
->ProcessorCapacity
!= 0) {
2628 proc_num
+= (item
->RangeEnd
- item
->RangeStart
+ 1) *
2629 item
->ProcessorCapacity
;
2632 last_seen
= item
->RangeEnd
- item
->RangeStart
+ 1;
2634 * Break out if all proximity domains have been processed.
2635 * Some BIOSes may have unused items at the end of MSCT table.
2637 if (last_seen
> tp
->MaxProximityDomains
) {
2641 if (last_seen
!= tp
->MaxProximityDomains
+ 1) {
2643 "?boot: invalid proximity domain structure in MSCT, "
2644 "proximity domain count doesn't match.\n");
2649 * Set plat-max-ncpus property if it hasn't been set yet.
2651 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2652 if (proc_num
!= 0) {
2653 bsetpropsi(PLAT_MAX_NCPUS_NAME
, proc_num
);
2658 * Use Maximum Physical Address from the MSCT table as upper limit for
2659 * memory hot-adding by default. It may be overridden by value from
2660 * the SRAT table or the "plat-dr-physmax" boot option.
2662 plat_dr_physmax
= btop(tp
->MaxAddress
+ 1);
2665 * Existence of MSCT implies CPU/memory hotplug-capability for the
2668 plat_dr_options
|= PLAT_DR_FEATURE_CPU
;
2669 plat_dr_options
|= PLAT_DR_FEATURE_MEMORY
;
2676 enumerate_xen_cpus()
2678 processorid_t id
, max_id
;
2681 * User-set boot-ncpus overrides enumeration
2683 if (do_bsys_getproplen(NULL
, BOOT_NCPUS_NAME
) >= 0)
2687 * Probe every possible virtual CPU id and remember the
2688 * highest id present; the count of CPUs is one greater
2689 * than this. This tacitly assumes at least cpu 0 is present.
2692 for (id
= 0; id
< MAX_VIRT_CPUS
; id
++)
2693 if (HYPERVISOR_vcpu_op(VCPUOP_is_up
, id
, NULL
) == 0)
2696 bsetpropsi(BOOT_NCPUS_NAME
, max_id
+1);
2703 build_firmware_properties(struct xboot_info
*xbp
)
2705 ACPI_TABLE_HEADER
*tp
= NULL
;
2708 if (xbp
->bi_uefi_arch
== XBI_UEFI_ARCH_64
) {
2709 bsetprops("efi-systype", "64");
2710 bsetprop64("efi-systab",
2711 (uint64_t)(uintptr_t)xbp
->bi_uefi_systab
);
2713 bop_printf(NULL
, "64-bit UEFI detected.\n");
2714 } else if (xbp
->bi_uefi_arch
== XBI_UEFI_ARCH_32
) {
2715 bsetprops("efi-systype", "32");
2716 bsetprop64("efi-systab",
2717 (uint64_t)(uintptr_t)xbp
->bi_uefi_systab
);
2719 bop_printf(NULL
, "32-bit UEFI detected.\n");
2722 if (xbp
->bi_acpi_rsdp
!= NULL
) {
2723 bsetprop64("acpi-root-tab",
2724 (uint64_t)(uintptr_t)xbp
->bi_acpi_rsdp
);
2727 if (xbp
->bi_smbios
!= NULL
) {
2728 bsetprop64("smbios-address",
2729 (uint64_t)(uintptr_t)xbp
->bi_smbios
);
2732 if ((tp
= find_fw_table(ACPI_SIG_MSCT
)) != NULL
)
2733 msct_ptr
= process_msct((ACPI_TABLE_MSCT
*)tp
);
2737 if ((tp
= find_fw_table(ACPI_SIG_MADT
)) != NULL
)
2738 process_madt((ACPI_TABLE_MADT
*)tp
);
2740 if ((srat_ptr
= (ACPI_TABLE_SRAT
*)
2741 find_fw_table(ACPI_SIG_SRAT
)) != NULL
)
2742 process_srat(srat_ptr
);
2744 if (slit_ptr
= (ACPI_TABLE_SLIT
*)find_fw_table(ACPI_SIG_SLIT
))
2745 process_slit(slit_ptr
);
2747 tp
= find_fw_table(ACPI_SIG_MCFG
);
2749 enumerate_xen_cpus();
2750 if (DOMAIN_IS_INITDOMAIN(xen_info
))
2751 tp
= find_fw_table(ACPI_SIG_MCFG
);
2754 process_mcfg((ACPI_TABLE_MCFG
*)tp
);
2758 * fake up a boot property for deferred early console output
2759 * this is used by both graphical boot and the (developer only)
2760 * USB serial console
2763 defcons_init(size_t size
)
2765 static char *p
= NULL
;
2767 p
= do_bsys_alloc(NULL
, NULL
, size
, MMU_PAGESIZE
);
2769 bsetprop("deferred-console-buf", strlen("deferred-console-buf") + 1,
2776 boot_compinfo(int fd
, struct compinfo
*cbp
)
2779 cbp
->blksize
= MAXBSIZE
;
2783 #define BP_MAX_STRLEN 32
2786 * Get value for given boot property
2789 bootprop_getval(const char *prop_name
, u_longlong_t
*prop_value
)
2792 char str
[BP_MAX_STRLEN
];
2795 boot_prop_len
= BOP_GETPROPLEN(bootops
, prop_name
);
2796 if (boot_prop_len
< 0 || boot_prop_len
> sizeof (str
) ||
2797 BOP_GETPROP(bootops
, prop_name
, str
) < 0 ||
2798 kobj_getvalue(str
, &value
) == -1)
2802 *prop_value
= value
;