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>
75 #include <sys/ddipropdefs.h> /* For DDI prop types */
77 static int have_console
= 0; /* set once primitive console is initialized */
78 static char *boot_args
= "";
83 static uint_t kbm_debug
= 0;
84 #define DBG_MSG(s) { if (kbm_debug) bop_printf(NULL, "%s", s); }
85 #define DBG(x) { if (kbm_debug) \
86 bop_printf(NULL, "%s is %" PRIx64 "\n", #x, (uint64_t)(x)); \
89 #define PUT_STRING(s) { \
91 for (cp = (s); *cp; ++cp) \
95 bootops_t bootop
; /* simple bootops we'll pass on to kernel */
99 * Boot info from "glue" code in low memory. xbootp is used by:
100 * do_bop_phys_alloc(), do_bsys_alloc() and boot_prop_finish().
102 static struct xboot_info
*xbootp
;
103 static uintptr_t next_virt
; /* next available virtual address */
104 static paddr_t next_phys
; /* next available physical address from dboot */
105 static paddr_t high_phys
= -(paddr_t
)1; /* last used physical address */
108 * buffer for vsnprintf for console I/O
110 #define BUFFERSIZE 512
111 static char buffer
[BUFFERSIZE
];
114 * stuff to store/report/manipulate boot property settings.
116 typedef struct bootprop
{
117 struct bootprop
*bp_next
;
119 int bp_flags
; /* DDI prop type */
120 uint_t bp_vlen
; /* 0 for boolean */
124 static bootprop_t
*bprops
= NULL
;
125 static char *curr_page
= NULL
; /* ptr to avail bprop memory */
126 static int curr_space
= 0; /* amount of memory at curr_page */
129 start_info_t
*xen_info
;
130 shared_info_t
*HYPERVISOR_shared_info
;
134 * some allocator statistics
136 static ulong_t total_bop_alloc_scratch
= 0;
137 static ulong_t total_bop_alloc_kernel
= 0;
139 static void build_firmware_properties(struct xboot_info
*);
141 static int early_allocation
= 1;
143 int force_fastreboot
= 0;
144 volatile int fastreboot_onpanic
= 0;
145 int post_fastreboot
= 0;
147 volatile int fastreboot_capable
= 0;
149 volatile int fastreboot_capable
= 1;
153 * Information saved from current boot for fast reboot.
154 * If the information size exceeds what we have allocated, fast reboot
155 * will not be supported.
157 multiboot_info_t saved_mbi
;
158 mb_memory_map_t saved_mmap
[FASTBOOT_SAVED_MMAP_COUNT
];
159 uint8_t saved_drives
[FASTBOOT_SAVED_DRIVES_SIZE
];
160 char saved_cmdline
[FASTBOOT_SAVED_CMDLINE_LEN
];
161 int saved_cmdline_len
= 0;
162 size_t saved_file_size
[FASTBOOT_MAX_FILES_MAP
];
165 * Turn off fastreboot_onpanic to avoid panic loop.
167 char fastreboot_onpanic_cmdline
[FASTBOOT_SAVED_CMDLINE_LEN
];
168 static const char fastreboot_onpanic_args
[] = " -B fastreboot_onpanic=0";
171 * Pointers to where System Resource Affinity Table (SRAT), System Locality
172 * Information Table (SLIT) and Maximum System Capability Table (MSCT)
173 * are mapped into virtual memory
175 ACPI_TABLE_SRAT
*srat_ptr
= NULL
;
176 ACPI_TABLE_SLIT
*slit_ptr
= NULL
;
177 ACPI_TABLE_MSCT
*msct_ptr
= NULL
;
180 * Arbitrary limit on number of localities we handle; if
181 * this limit is raised to more than UINT16_MAX, make sure
182 * process_slit() knows how to handle it.
184 #define SLIT_LOCALITIES_MAX (4096)
186 #define SLIT_NUM_PROPNAME "acpi-slit-localities"
187 #define SLIT_PROPNAME "acpi-slit"
190 * Allocate aligned physical memory at boot time. This allocator allocates
191 * from the highest possible addresses. This avoids exhausting memory that
192 * would be useful for DMA buffers.
195 do_bop_phys_alloc(uint64_t size
, uint64_t align
)
200 struct memlist
*ml
= (struct memlist
*)xbootp
->bi_phys_install
;
203 * Be careful if high memory usage is limited in startup.c
204 * Since there are holes in the low part of the physical address
205 * space we can treat physmem as a pfn (not just a pgcnt) and
206 * get a conservative upper limit.
208 if (physmem
!= 0 && high_phys
> pfn_to_pa(physmem
))
209 high_phys
= pfn_to_pa(physmem
);
212 * find the highest available memory in physinstalled
214 size
= P2ROUNDUP(size
, align
);
215 for (; ml
; ml
= ml
->ml_next
) {
216 start
= P2ROUNDUP(ml
->ml_address
, align
);
217 end
= P2ALIGN(ml
->ml_address
+ ml
->ml_size
, align
);
218 if (start
< next_phys
)
219 start
= P2ROUNDUP(next_phys
, align
);
221 end
= P2ALIGN(high_phys
, align
);
225 if (end
- start
< size
)
229 * Early allocations need to use low memory, since
230 * physmem might be further limited by bootenv.rc
232 if (early_allocation
) {
233 if (pa
== 0 || start
< pa
)
241 if (early_allocation
)
242 next_phys
= pa
+ size
;
247 bop_panic("do_bop_phys_alloc(0x%" PRIx64
", 0x%" PRIx64
248 ") Out of memory\n", size
, align
);
253 alloc_vaddr(size_t size
, paddr_t align
)
257 next_virt
= P2ROUNDUP(next_virt
, (uintptr_t)align
);
258 rv
= (uintptr_t)next_virt
;
264 * Allocate virtual memory. The size is always rounded up to a multiple
270 do_bsys_alloc(bootops_t
*bop
, caddr_t virthint
, size_t size
, int align
)
272 paddr_t a
= align
; /* same type as pa for masking */
276 ssize_t s
; /* the aligned size */
278 uint_t is_kernel
= (virthint
!= 0);
280 if (a
< MMU_PAGESIZE
)
283 prom_panic("do_bsys_alloc() incorrect alignment");
284 size
= P2ROUNDUP(size
, MMU_PAGESIZE
);
287 * Use the next aligned virtual address if we weren't given one.
289 if (virthint
== NULL
) {
290 virthint
= (caddr_t
)alloc_vaddr(size
, a
);
291 total_bop_alloc_scratch
+= size
;
293 total_bop_alloc_kernel
+= size
;
297 * allocate the physical memory
299 pa
= do_bop_phys_alloc(size
, a
);
302 * Add the mappings to the page tables, try large pages first.
304 va
= (uintptr_t)virthint
;
307 pgsize
= xbootp
->bi_use_pae
? TWO_MEG
: FOUR_MEG
;
308 if (xbootp
->bi_use_largepage
&& a
== pgsize
) {
309 while (IS_P2ALIGNED(pa
, pgsize
) && IS_P2ALIGNED(va
, pgsize
) &&
311 kbm_map(va
, pa
, level
, is_kernel
);
319 * Map remaining pages use small mappings
322 pgsize
= MMU_PAGESIZE
;
324 kbm_map(va
, pa
, level
, is_kernel
);
333 * Free virtual memory - we'll just ignore these.
337 do_bsys_free(bootops_t
*bop
, caddr_t virt
, size_t size
)
339 bop_printf(NULL
, "do_bsys_free(virt=0x%p, size=0x%lx) ignored\n",
348 do_bsys_ealloc(bootops_t
*bop
, caddr_t virthint
, size_t size
,
349 int align
, int flags
)
351 prom_panic("unsupported call to BOP_EALLOC()\n");
357 bsetprop(int flags
, char *name
, int nlen
, void *value
, int vlen
)
364 * align the size to 16 byte boundary
366 size
= sizeof (bootprop_t
) + nlen
+ 1 + vlen
;
367 size
= (size
+ 0xf) & ~0xf;
368 if (size
> curr_space
) {
369 need_size
= (size
+ (MMU_PAGEOFFSET
)) & MMU_PAGEMASK
;
370 curr_page
= do_bsys_alloc(NULL
, 0, need_size
, MMU_PAGESIZE
);
371 curr_space
= need_size
;
375 * use a bootprop_t at curr_page and link into list
377 b
= (bootprop_t
*)curr_page
;
378 curr_page
+= sizeof (bootprop_t
);
379 curr_space
-= sizeof (bootprop_t
);
384 * follow by name and ending zero byte
386 b
->bp_name
= curr_page
;
387 bcopy(name
, curr_page
, nlen
);
390 curr_space
-= nlen
+ 1;
393 * set the property type
395 b
->bp_flags
= flags
& DDI_PROP_TYPE_MASK
;
398 * copy in value, but no ending zero byte
400 b
->bp_value
= curr_page
;
403 bcopy(value
, curr_page
, vlen
);
409 * align new values of curr_page, curr_space
411 while (curr_space
& 0xf) {
418 bsetprops(char *name
, char *value
)
420 bsetprop(DDI_PROP_TYPE_STRING
, name
, strlen(name
),
421 value
, strlen(value
) + 1);
425 bsetprop32(char *name
, uint32_t value
)
427 bsetprop(DDI_PROP_TYPE_INT
, name
, strlen(name
),
428 (void *)&value
, sizeof (value
));
432 bsetprop64(char *name
, uint64_t value
)
434 bsetprop(DDI_PROP_TYPE_INT64
, name
, strlen(name
),
435 (void *)&value
, sizeof (value
));
439 bsetpropsi(char *name
, int value
)
443 (void) snprintf(prop_val
, sizeof (prop_val
), "%d", value
);
444 bsetprops(name
, prop_val
);
448 * to find the type of the value associated with this name
452 do_bsys_getproptype(bootops_t
*bop
, const char *name
)
456 for (b
= bprops
; b
!= NULL
; b
= b
->bp_next
) {
457 if (strcmp(name
, b
->bp_name
) != 0)
459 return (b
->bp_flags
);
465 * to find the size of the buffer to allocate
469 do_bsys_getproplen(bootops_t
*bop
, const char *name
)
473 for (b
= bprops
; b
; b
= b
->bp_next
) {
474 if (strcmp(name
, b
->bp_name
) != 0)
482 * get the value associated with this name
486 do_bsys_getprop(bootops_t
*bop
, const char *name
, void *value
)
490 for (b
= bprops
; b
; b
= b
->bp_next
) {
491 if (strcmp(name
, b
->bp_name
) != 0)
493 bcopy(b
->bp_value
, value
, b
->bp_vlen
);
500 * get the name of the next property in succession from the standalone
504 do_bsys_nextprop(bootops_t
*bop
, char *name
)
509 * A null name is a special signal for the 1st boot property
511 if (name
== NULL
|| strlen(name
) == 0) {
514 return (bprops
->bp_name
);
517 for (b
= bprops
; b
; b
= b
->bp_next
) {
518 if (name
!= b
->bp_name
)
529 * Parse numeric value from a string. Understands decimal, hex, octal, - and ~
532 parse_value(char *p
, uint64_t *retval
)
540 if (*p
== '-' || *p
== '~')
547 if (*p
== 'x' || *p
== 'X') {
556 if ('0' <= *p
&& *p
<= '9')
558 else if ('a' <= *p
&& *p
<= 'f')
559 digit
= 10 + *p
- 'a';
560 else if ('A' <= *p
&& *p
<= 'F')
561 digit
= 10 + *p
- 'A';
566 tmp
= tmp
* radix
+ digit
;
571 else if (adjust
== '~')
578 unprintable(char *value
, int size
)
582 if (size
<= 0 || value
[0] == '\0')
585 for (i
= 0; i
< size
; i
++) {
586 if (value
[i
] == '\0')
587 return (i
!= (size
- 1));
589 if (!isprint(value
[i
]))
596 * Print out information about all boot properties.
597 * buffer is pointer to pre-allocated space to be used as temporary
598 * space for property values.
601 boot_prop_display(char *buffer
)
604 int i
, len
, flags
, *buf32
;
607 bop_printf(NULL
, "\nBoot properties:\n");
609 while ((name
= do_bsys_nextprop(NULL
, name
)) != NULL
) {
610 bop_printf(NULL
, "\t0x%p %s = ", (void *)name
, name
);
611 (void) do_bsys_getprop(NULL
, name
, buffer
);
612 len
= do_bsys_getproplen(NULL
, name
);
613 flags
= do_bsys_getproptype(NULL
, name
);
614 bop_printf(NULL
, "len=%d ", len
);
617 case DDI_PROP_TYPE_INT
:
618 len
= len
/ sizeof (int);
619 buf32
= (int *)buffer
;
620 for (i
= 0; i
< len
; i
++) {
621 bop_printf(NULL
, "%08x", buf32
[i
]);
623 bop_printf(NULL
, ".");
626 case DDI_PROP_TYPE_STRING
:
627 bop_printf(NULL
, "%s", buffer
);
629 case DDI_PROP_TYPE_INT64
:
630 len
= len
/ sizeof (int64_t);
631 buf64
= (int64_t *)buffer
;
632 for (i
= 0; i
< len
; i
++) {
633 bop_printf(NULL
, "%016" PRIx64
, buf64
[i
]);
635 bop_printf(NULL
, ".");
639 if (!unprintable(buffer
, len
)) {
641 bop_printf(NULL
, "%s", buffer
);
644 for (i
= 0; i
< len
; i
++) {
645 bop_printf(NULL
, "%02x", buffer
[i
] & 0xff);
647 bop_printf(NULL
, ".");
651 bop_printf(NULL
, "\n");
656 * 2nd part of building the table of boot properties. This includes:
657 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
659 * lines look like one of:
661 * ^# comment till end of line
662 * setprop name 'value'
664 * setprop name "value"
666 * we do single character I/O since this is really just looking at memory
669 boot_prop_finish(void)
679 char *inputdev
; /* these override the command line if serial ports */
684 extern int bootrd_debug
;
687 if (!DOMAIN_IS_INITDOMAIN(xen_info
))
691 DBG_MSG("Opening /boot/solaris/bootenv.rc\n");
692 fd
= BRD_OPEN(bfs_ops
, "/boot/solaris/bootenv.rc", 0);
695 line
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
702 bytes_read
= BRD_READ(bfs_ops
, fd
, line
+ c
, 1);
703 if (bytes_read
== 0) {
714 * ignore comment lines
717 while (ISSPACE(line
[c
]))
719 if (line
[c
] == '#' || line
[c
] == 0)
723 * must have "setprop " or "setprop\t"
725 if (strncmp(line
+ c
, "setprop ", 8) != 0 &&
726 strncmp(line
+ c
, "setprop\t", 8) != 0)
729 while (ISSPACE(line
[c
]))
735 * gather up the property name
739 while (line
[c
] && !ISSPACE(line
[c
]))
743 * gather up the value, if any
747 while (ISSPACE(line
[c
]))
751 while (line
[c
] && !ISSPACE(line
[c
]))
755 if (v_len
>= 2 && value
[0] == value
[v_len
- 1] &&
756 (value
[0] == '\'' || value
[0] == '"')) {
767 * ignore "boot-file" property, it's now meaningless
769 if (strcmp(name
, "boot-file") == 0)
771 if (strcmp(name
, "boot-args") == 0 &&
772 strlen(boot_args
) > 0)
776 * If a property was explicitly set on the command line
777 * it will override a setting in bootenv.rc
779 if (do_bsys_getproplen(NULL
, name
) >= 0)
782 bsetprops(name
, value
);
786 (void) BRD_CLOSE(bfs_ops
, fd
);
789 * Check if we have to limit the boot time allocator
791 if (do_bsys_getproplen(NULL
, "physmem") != -1 &&
792 do_bsys_getprop(NULL
, "physmem", line
) >= 0 &&
793 parse_value(line
, &lvalue
) != -1) {
794 if (0 < lvalue
&& (lvalue
< physmem
|| physmem
== 0)) {
795 physmem
= (pgcnt_t
)lvalue
;
799 early_allocation
= 0;
802 * Check for bootrd_debug.
804 if (find_boot_prop("bootrd_debug"))
808 * check to see if we have to override the default value of the console
812 v_len
= do_bsys_getproplen(NULL
, "input-device");
814 (void) do_bsys_getprop(NULL
, "input-device", inputdev
);
819 outputdev
= inputdev
+ v_len
+ 1;
820 v_len
= do_bsys_getproplen(NULL
, "output-device");
822 (void) do_bsys_getprop(NULL
, "output-device",
826 outputdev
[v_len
] = 0;
828 consoledev
= outputdev
+ v_len
+ 1;
829 v_len
= do_bsys_getproplen(NULL
, "console");
831 (void) do_bsys_getprop(NULL
, "console", consoledev
);
832 if (post_fastreboot
&&
833 strcmp(consoledev
, "graphics") == 0) {
834 bsetprops("console", "text");
835 v_len
= strlen("text");
836 bcopy("text", consoledev
, v_len
);
841 consoledev
[v_len
] = 0;
842 bcons_init2(inputdev
, outputdev
, consoledev
);
845 * Ensure console property exists
846 * If not create it as "hypervisor"
848 v_len
= do_bsys_getproplen(NULL
, "console");
850 bsetprops("console", "hypervisor");
851 inputdev
= outputdev
= consoledev
= "hypervisor";
852 bcons_init2(inputdev
, outputdev
, consoledev
);
855 if (find_boot_prop("prom_debug") || kbm_debug
)
856 boot_prop_display(line
);
860 * print formatted output
865 bop_printf(bootops_t
*bop
, const char *fmt
, ...)
869 if (have_console
== 0)
873 (void) vsnprintf(buffer
, BUFFERSIZE
, fmt
, ap
);
879 * Another panic() variant; this one can be used even earlier during boot than
884 bop_panic(const char *fmt
, ...)
889 bop_printf(NULL
, fmt
, ap
);
892 bop_printf(NULL
, "\nPress any key to reboot.\n");
893 (void) bcons_getchar();
894 bop_printf(NULL
, "Resetting...\n");
899 * Do a real mode interrupt BIOS call
901 typedef struct bios_regs
{
902 unsigned short ax
, bx
, cx
, dx
, si
, di
, bp
, es
, ds
;
904 typedef int (*bios_func_t
)(int, bios_regs_t
*);
908 do_bsys_doint(bootops_t
*bop
, int intnum
, struct bop_regs
*rp
)
911 prom_panic("unsupported call to BOP_DOINT()\n");
913 static int firsttime
= 1;
914 bios_func_t bios_func
= (bios_func_t
)(void *)(uintptr_t)0x5000;
918 * We're about to disable paging; we shouldn't be PCID enabled.
920 if (getcr4() & CR4_PCIDE
)
921 prom_panic("do_bsys_doint() with PCID enabled\n");
924 * The first time we do this, we have to copy the pre-packaged
925 * low memory bios call code image into place.
928 extern char bios_image
[];
929 extern uint32_t bios_size
;
931 bcopy(bios_image
, (void *)bios_func
, bios_size
);
935 br
.ax
= rp
->eax
.word
.ax
;
936 br
.bx
= rp
->ebx
.word
.bx
;
937 br
.cx
= rp
->ecx
.word
.cx
;
938 br
.dx
= rp
->edx
.word
.dx
;
939 br
.bp
= rp
->ebp
.word
.bp
;
940 br
.si
= rp
->esi
.word
.si
;
941 br
.di
= rp
->edi
.word
.di
;
945 DBG_MSG("Doing BIOS call...");
949 rp
->eflags
= bios_func(intnum
, &br
);
952 rp
->eax
.word
.ax
= br
.ax
;
953 rp
->ebx
.word
.bx
= br
.bx
;
954 rp
->ecx
.word
.cx
= br
.cx
;
955 rp
->edx
.word
.dx
= br
.dx
;
956 rp
->ebp
.word
.bp
= br
.bp
;
957 rp
->esi
.word
.si
= br
.si
;
958 rp
->edi
.word
.di
= br
.di
;
964 static struct boot_syscalls bop_sysp
= {
976 static char namebuf
[32];
979 xen_parse_props(char *s
, char *prop_map
[], int n_prop
)
981 char **prop_name
= prop_map
;
986 while ((*cp
!= NULL
) && (*cp
!= ':'))
989 if ((scp
!= cp
) && (*prop_name
!= NULL
)) {
991 bsetprops(*prop_name
, scp
);
997 } while (n_prop
> 0);
1000 #define VBDPATHLEN 64
1003 * parse the 'xpv-root' property to create properties used by
1007 xen_vbdroot_props(char *s
)
1009 char vbdpath
[VBDPATHLEN
] = "/xpvd/xdf@";
1010 const char lnamefix
[] = "/dev/dsk/c0d";
1017 pnp
= vbdpath
+ strlen(vbdpath
);
1018 prop_p
= s
+ strlen(lnamefix
);
1019 while ((*prop_p
!= '\0') && (*prop_p
!= 's') && (*prop_p
!= 'p'))
1020 addr
= addr
* 10 + *prop_p
++ - '0';
1021 (void) snprintf(pnp
, VBDPATHLEN
, "%lx", addr
);
1022 pnp
= vbdpath
+ strlen(vbdpath
);
1025 else if (*prop_p
== 'p')
1028 ASSERT(0); /* shouldn't be here */
1030 ASSERT(*prop_p
!= '\0');
1031 if (ISDIGIT(*prop_p
)) {
1032 minor
= *prop_p
- '0';
1034 if (ISDIGIT(*prop_p
)) {
1035 minor
= minor
* 10 + *prop_p
- '0';
1038 /* malformed root path, use 0 as default */
1041 ASSERT(minor
< 16); /* at most 16 partitions */
1046 bsetprops("fstype", "ufs");
1047 bsetprops("bootpath", vbdpath
);
1049 DBG_MSG("VBD bootpath set to ");
1055 * parse the xpv-nfsroot property to create properties used by
1059 xen_nfsroot_props(char *s
)
1061 char *prop_map
[] = {
1062 BP_SERVER_IP
, /* server IP address */
1063 BP_SERVER_NAME
, /* server hostname */
1064 BP_SERVER_PATH
, /* root path */
1066 int n_prop
= sizeof (prop_map
) / sizeof (prop_map
[0]);
1068 bsetprops("fstype", "nfs");
1070 xen_parse_props(s
, prop_map
, n_prop
);
1073 * If a server name wasn't specified, use a default.
1075 if (do_bsys_getproplen(NULL
, BP_SERVER_NAME
) == -1)
1076 bsetprops(BP_SERVER_NAME
, "unknown");
1080 * Extract our IP address, etc. from the "xpv-ip" property.
1083 xen_ip_props(char *s
)
1085 char *prop_map
[] = {
1086 BP_HOST_IP
, /* IP address */
1087 NULL
, /* NFS server IP address (ignored in */
1088 /* favour of xpv-nfsroot) */
1089 BP_ROUTER_IP
, /* IP gateway */
1090 BP_SUBNET_MASK
, /* IP subnet mask */
1091 "xpv-hostname", /* hostname (ignored) */
1092 BP_NETWORK_INTERFACE
, /* interface name */
1093 "xpv-hcp", /* host configuration protocol */
1095 int n_prop
= sizeof (prop_map
) / sizeof (prop_map
[0]);
1096 char ifname
[IFNAMSIZ
];
1098 xen_parse_props(s
, prop_map
, n_prop
);
1101 * A Linux dom0 administrator expects all interfaces to be
1102 * called "ethX", which is not the case here.
1104 * If the interface name specified is "eth0", presume that
1105 * this is really intended to be "xnf0" (the first domU ->
1106 * dom0 interface for this domain).
1108 if ((do_bsys_getprop(NULL
, BP_NETWORK_INTERFACE
, ifname
) == 0) &&
1109 (strcmp("eth0", ifname
) == 0)) {
1110 bsetprops(BP_NETWORK_INTERFACE
, "xnf0");
1112 "network interface name 'eth0' replaced with 'xnf0'\n");
1119 setup_rarp_props(struct sol_netinfo
*sip
)
1121 char buf
[BUFLEN
]; /* to hold ip/mac addrs */
1124 val
= (uint8_t *)&sip
->sn_ciaddr
;
1125 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1126 val
[0], val
[1], val
[2], val
[3]);
1127 bsetprops(BP_HOST_IP
, buf
);
1129 val
= (uint8_t *)&sip
->sn_siaddr
;
1130 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1131 val
[0], val
[1], val
[2], val
[3]);
1132 bsetprops(BP_SERVER_IP
, buf
);
1134 if (sip
->sn_giaddr
!= 0) {
1135 val
= (uint8_t *)&sip
->sn_giaddr
;
1136 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1137 val
[0], val
[1], val
[2], val
[3]);
1138 bsetprops(BP_ROUTER_IP
, buf
);
1141 if (sip
->sn_netmask
!= 0) {
1142 val
= (uint8_t *)&sip
->sn_netmask
;
1143 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1144 val
[0], val
[1], val
[2], val
[3]);
1145 bsetprops(BP_SUBNET_MASK
, buf
);
1148 if (sip
->sn_mactype
!= 4 || sip
->sn_maclen
!= 6) {
1149 bop_printf(NULL
, "unsupported mac type %d, mac len %d\n",
1150 sip
->sn_mactype
, sip
->sn_maclen
);
1152 val
= sip
->sn_macaddr
;
1153 (void) snprintf(buf
, BUFLEN
, "%x:%x:%x:%x:%x:%x",
1154 val
[0], val
[1], val
[2], val
[3], val
[4], val
[5]);
1155 bsetprops(BP_BOOT_MAC
, buf
);
1162 build_panic_cmdline(const char *cmd
, int cmdlen
)
1167 arglen
= sizeof (fastreboot_onpanic_args
);
1169 * If we allready have fastreboot-onpanic set to zero,
1170 * don't add them again.
1172 if ((proplen
= do_bsys_getproplen(NULL
, FASTREBOOT_ONPANIC
)) > 0 &&
1173 proplen
<= sizeof (fastreboot_onpanic_cmdline
)) {
1174 (void) do_bsys_getprop(NULL
, FASTREBOOT_ONPANIC
,
1175 fastreboot_onpanic_cmdline
);
1176 if (FASTREBOOT_ONPANIC_NOTSET(fastreboot_onpanic_cmdline
))
1181 * construct fastreboot_onpanic_cmdline
1183 if (cmdlen
+ arglen
> sizeof (fastreboot_onpanic_cmdline
)) {
1184 DBG_MSG("Command line too long: clearing "
1185 FASTREBOOT_ONPANIC
"\n");
1186 fastreboot_onpanic
= 0;
1188 bcopy(cmd
, fastreboot_onpanic_cmdline
, cmdlen
);
1190 bcopy(fastreboot_onpanic_args
,
1191 fastreboot_onpanic_cmdline
+ cmdlen
, arglen
);
1193 fastreboot_onpanic_cmdline
[cmdlen
] = 0;
1200 * Construct boot command line for Fast Reboot. The saved_cmdline
1201 * is also reported by "eeprom bootcmd".
1204 build_fastboot_cmdline(struct xboot_info
*xbp
)
1206 saved_cmdline_len
= strlen(xbp
->bi_cmdline
) + 1;
1207 if (saved_cmdline_len
> FASTBOOT_SAVED_CMDLINE_LEN
) {
1208 DBG(saved_cmdline_len
);
1209 DBG_MSG("Command line too long: clearing fastreboot_capable\n");
1210 fastreboot_capable
= 0;
1212 bcopy((void *)(xbp
->bi_cmdline
), (void *)saved_cmdline
,
1214 saved_cmdline
[saved_cmdline_len
- 1] = '\0';
1215 build_panic_cmdline(saved_cmdline
, saved_cmdline_len
- 1);
1220 * Save memory layout, disk drive information, unix and boot archive sizes for
1224 save_boot_info(struct xboot_info
*xbi
)
1226 multiboot_info_t
*mbi
= xbi
->bi_mb_info
;
1227 struct boot_modules
*modp
;
1230 bcopy(mbi
, &saved_mbi
, sizeof (multiboot_info_t
));
1231 if (mbi
->mmap_length
> sizeof (saved_mmap
)) {
1232 DBG_MSG("mbi->mmap_length too big: clearing "
1233 "fastreboot_capable\n");
1234 fastreboot_capable
= 0;
1236 bcopy((void *)(uintptr_t)mbi
->mmap_addr
, (void *)saved_mmap
,
1240 if ((mbi
->flags
& MB_INFO_DRIVE_INFO
) != 0) {
1241 if (mbi
->drives_length
> sizeof (saved_drives
)) {
1242 DBG(mbi
->drives_length
);
1243 DBG_MSG("mbi->drives_length too big: clearing "
1244 "fastreboot_capable\n");
1245 fastreboot_capable
= 0;
1247 bcopy((void *)(uintptr_t)mbi
->drives_addr
,
1248 (void *)saved_drives
, mbi
->drives_length
);
1251 saved_mbi
.drives_length
= 0;
1252 saved_mbi
.drives_addr
= NULL
;
1256 * Current file sizes. Used by fastboot.c to figure out how much
1257 * memory to reserve for panic reboot.
1258 * Use the module list from the dboot-constructed xboot_info
1259 * instead of the list referenced by the multiboot structure
1260 * because that structure may not be addressable now.
1262 saved_file_size
[FASTBOOT_NAME_UNIX
] = FOUR_MEG
- PAGESIZE
;
1263 for (i
= 0, modp
= (struct boot_modules
*)(uintptr_t)xbi
->bi_modules
;
1264 i
< xbi
->bi_module_cnt
; i
++, modp
++) {
1265 saved_file_size
[FASTBOOT_NAME_BOOTARCHIVE
] += modp
->bm_size
;
1271 * Import boot environment module variables as properties, applying
1272 * blacklist filter for variables we know we will not use.
1274 * Since the environment can be relatively large, containing many variables
1275 * used only for boot loader purposes, we will use a blacklist based filter.
1276 * To keep the blacklist from growing too large, we use prefix based filtering.
1277 * This is possible because in many cases, the loader variable names are
1278 * using a structured layout.
1280 * We will not overwrite already set properties.
1282 static struct bop_blacklist
{
1283 const char *bl_name
;
1285 } bop_prop_blacklist
[] = {
1286 { "ISADIR", sizeof ("ISADIR") },
1287 { "acpi", sizeof ("acpi") },
1288 { "autoboot_delay", sizeof ("autoboot_delay") },
1289 { "autoboot_delay", sizeof ("autoboot_delay") },
1290 { "beansi_", sizeof ("beansi_") },
1291 { "beastie", sizeof ("beastie") },
1292 { "bemenu", sizeof ("bemenu") },
1293 { "boot.", sizeof ("boot.") },
1294 { "bootenv", sizeof ("bootenv") },
1295 { "currdev", sizeof ("currdev") },
1296 { "dhcp.", sizeof ("dhcp.") },
1297 { "interpret", sizeof ("interpret") },
1298 { "kernel", sizeof ("kernel") },
1299 { "loaddev", sizeof ("loaddev") },
1300 { "loader_", sizeof ("loader_") },
1301 { "module_path", sizeof ("module_path") },
1302 { "nfs.", sizeof ("nfs.") },
1303 { "pcibios", sizeof ("pcibios") },
1304 { "prompt", sizeof ("prompt") },
1305 { "smbios", sizeof ("smbios") },
1306 { "tem", sizeof ("tem") },
1307 { "twiddle_divisor", sizeof ("twiddle_divisor") },
1308 { "zfs_be", sizeof ("zfs_be") },
1312 * Match the name against prefixes in above blacklist. If the match was
1313 * found, this name is blacklisted.
1316 name_is_blacklisted(const char *name
)
1320 n
= sizeof (bop_prop_blacklist
) / sizeof (bop_prop_blacklist
[0]);
1321 for (i
= 0; i
< n
; i
++) {
1322 if (strncmp(bop_prop_blacklist
[i
].bl_name
, name
,
1323 bop_prop_blacklist
[i
].bl_name_len
- 1) == 0) {
1331 process_boot_environment(struct boot_modules
*benv
)
1333 char *env
, *ptr
, *name
, *value
;
1334 uint32_t size
, name_len
, value_len
;
1336 if (benv
== NULL
|| benv
->bm_type
!= BMT_ENV
)
1338 ptr
= env
= benv
->bm_addr
;
1339 size
= benv
->bm_size
;
1343 while (*ptr
!= '=') {
1345 if (ptr
> env
+ size
) /* Something is very wrong. */
1348 name_len
= ptr
- name
;
1349 if (sizeof (buffer
) <= name_len
)
1352 (void) strncpy(buffer
, name
, sizeof (buffer
));
1353 buffer
[name_len
] = '\0';
1358 while ((uintptr_t)ptr
- (uintptr_t)env
< size
) {
1361 value_len
= (uintptr_t)ptr
- (uintptr_t)env
;
1367 /* Did we reach the end of the module? */
1374 /* Is this property already set? */
1375 if (do_bsys_getproplen(NULL
, name
) >= 0)
1378 /* Translate netboot variables */
1379 if (strcmp(name
, "boot.netif.gateway") == 0) {
1380 bsetprops(BP_ROUTER_IP
, value
);
1383 if (strcmp(name
, "boot.netif.hwaddr") == 0) {
1384 bsetprops(BP_BOOT_MAC
, value
);
1387 if (strcmp(name
, "boot.netif.ip") == 0) {
1388 bsetprops(BP_HOST_IP
, value
);
1391 if (strcmp(name
, "boot.netif.netmask") == 0) {
1392 bsetprops(BP_SUBNET_MASK
, value
);
1395 if (strcmp(name
, "boot.netif.server") == 0) {
1396 bsetprops(BP_SERVER_IP
, value
);
1399 if (strcmp(name
, "boot.netif.server") == 0) {
1400 if (do_bsys_getproplen(NULL
, BP_SERVER_IP
) < 0)
1401 bsetprops(BP_SERVER_IP
, value
);
1404 if (strcmp(name
, "boot.nfsroot.server") == 0) {
1405 if (do_bsys_getproplen(NULL
, BP_SERVER_IP
) < 0)
1406 bsetprops(BP_SERVER_IP
, value
);
1409 if (strcmp(name
, "boot.nfsroot.path") == 0) {
1410 bsetprops(BP_SERVER_PATH
, value
);
1414 if (name_is_blacklisted(name
) == B_TRUE
)
1417 /* Create new property. */
1418 bsetprops(name
, value
);
1420 /* Avoid reading past the module end. */
1421 if (size
<= (uintptr_t)ptr
- (uintptr_t)env
)
1423 } while (*ptr
!= '\0');
1427 * 1st pass at building the table of boot properties. This includes:
1428 * - values set on the command line: -B a=x,b=y,c=z ....
1429 * - known values we just compute (ie. from xbp)
1430 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
1432 * the grub command line looked like:
1433 * kernel boot-file [-B prop=value[,prop=value]...] [boot-args]
1435 * whoami is the same as boot-file
1438 build_boot_properties(struct xboot_info
*xbp
)
1444 struct boot_modules
*bm
, *rdbm
, *benv
= NULL
;
1451 static int stdout_val
= 0;
1452 uchar_t boot_device
;
1457 * These have to be done first, so that kobj_mount_root() works
1459 DBG_MSG("Building boot properties\n");
1460 propbuf
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, 0);
1461 DBG((uintptr_t)propbuf
);
1462 if (xbp
->bi_module_cnt
> 0) {
1463 bm
= xbp
->bi_modules
;
1465 for (midx
= i
= 0; i
< xbp
->bi_module_cnt
; i
++) {
1466 if (bm
[i
].bm_type
== BMT_ROOTFS
) {
1470 if (bm
[i
].bm_type
== BMT_HASH
|| bm
[i
].bm_name
== NULL
)
1473 if (bm
[i
].bm_type
== BMT_ENV
) {
1480 (void) snprintf(modid
, sizeof (modid
),
1481 "module-name-%u", midx
);
1482 bsetprops(modid
, (char *)bm
[i
].bm_name
);
1483 (void) snprintf(modid
, sizeof (modid
),
1484 "module-addr-%u", midx
);
1485 bsetprop64(modid
, (uint64_t)(uintptr_t)bm
[i
].bm_addr
);
1486 (void) snprintf(modid
, sizeof (modid
),
1487 "module-size-%u", midx
);
1488 bsetprop64(modid
, (uint64_t)bm
[i
].bm_size
);
1492 bsetprop64("ramdisk_start",
1493 (uint64_t)(uintptr_t)rdbm
->bm_addr
);
1494 bsetprop64("ramdisk_end",
1495 (uint64_t)(uintptr_t)rdbm
->bm_addr
+ rdbm
->bm_size
);
1500 * If there are any boot time modules or hashes present, then disable
1503 if (xbp
->bi_module_cnt
> 1) {
1504 fastreboot_disable(FBNS_BOOTMOD
);
1509 * Disable fast reboot if we're using the Multiboot 2 boot protocol,
1510 * since we don't currently support MB2 info and module relocation.
1511 * Note that fast reboot will have already been disabled if multiple
1512 * modules are present, since the current implementation assumes that
1513 * we only have a single module, the boot_archive.
1515 if (xbp
->bi_mb_version
!= 1) {
1516 fastreboot_disable(FBNS_MULTIBOOT2
);
1520 DBG_MSG("Parsing command line for boot properties\n");
1521 value
= xbp
->bi_cmdline
;
1524 * allocate memory to collect boot_args into
1526 boot_arg_len
= strlen(xbp
->bi_cmdline
) + 1;
1527 boot_args
= do_bsys_alloc(NULL
, NULL
, boot_arg_len
, MMU_PAGESIZE
);
1533 * Xen puts a lot of device information in front of the kernel name
1534 * let's grab them and make them boot properties. The first
1535 * string w/o an "=" in it will be the boot-file property.
1537 (void) strcpy(namebuf
, "xpv-");
1540 * get to next property
1542 while (ISSPACE(*value
))
1548 while (*value
&& !ISSPACE(*value
) && *value
!= '=') {
1551 if (*value
!= '=') { /* no "=" in the property */
1555 name_len
= value
- name
;
1561 while (value
[value_len
] && !ISSPACE(value
[value_len
])) {
1565 * build property name with "xpv-" prefix
1567 if (name_len
+ 4 > 32) { /* skip if name too long */
1571 bcopy(name
, &namebuf
[4], name_len
);
1573 namebuf
[name_len
] = 0;
1574 bcopy(value
, propbuf
, value_len
);
1575 propbuf
[value_len
] = 0;
1576 bsetprops(namebuf
, propbuf
);
1579 * xpv-root is set to the logical disk name of the xen
1580 * VBD when booting from a disk-based filesystem.
1582 if (strcmp(namebuf
, "xpv-root") == 0)
1583 xen_vbdroot_props(propbuf
);
1585 * While we're here, if we have a "xpv-nfsroot" property
1586 * then we need to set "fstype" to "nfs" so we mount
1587 * our root from the nfs server. Also parse the xpv-nfsroot
1588 * property to create the properties that nfs_mountroot will
1589 * need to find the root and mount it.
1591 if (strcmp(namebuf
, "xpv-nfsroot") == 0)
1592 xen_nfsroot_props(propbuf
);
1594 if (strcmp(namebuf
, "xpv-ip") == 0)
1595 xen_ip_props(propbuf
);
1600 while (ISSPACE(*value
))
1603 * value now points at the boot-file
1606 while (value
[value_len
] && !ISSPACE(value
[value_len
]))
1608 if (value_len
> 0) {
1610 bcopy(value
, whoami
, value_len
);
1611 whoami
[value_len
] = 0;
1612 bsetprops("boot-file", whoami
);
1614 * strip leading path stuff from whoami, so running from
1615 * PXE/miniroot makes sense.
1617 if (strstr(whoami
, "/platform/") != NULL
)
1618 whoami
= strstr(whoami
, "/platform/");
1619 bsetprops("whoami", whoami
);
1623 * Values forcibly set boot properties on the command line via -B.
1624 * Allow use of quotes in values. Other stuff goes on kernel
1627 name
= value
+ value_len
;
1628 while (*name
!= 0) {
1630 * anything not " -B" is copied to the command line
1632 if (!ISSPACE(name
[0]) || name
[1] != '-' || name
[2] != 'B') {
1633 boot_args
[boot_arg_len
++] = *name
;
1634 boot_args
[boot_arg_len
] = 0;
1640 * skip the " -B" and following white space
1643 while (ISSPACE(*name
))
1645 while (*name
&& !ISSPACE(*name
)) {
1646 value
= strstr(name
, "=");
1649 name_len
= value
- name
;
1653 for (; ; ++value_len
) {
1654 if (!value
[value_len
])
1658 * is this value quoted?
1660 if (value_len
== 0 &&
1661 (value
[0] == '\'' || value
[0] == '"')) {
1667 * In the quote accept any character,
1668 * but look for ending quote.
1671 if (value
[value_len
] == quoted
)
1677 * a comma or white space ends the value
1679 if (value
[value_len
] == ',' ||
1680 ISSPACE(value
[value_len
]))
1684 if (value_len
== 0) {
1685 bsetprop(DDI_PROP_TYPE_ANY
, name
, name_len
,
1690 if (v
[0] == v
[l
- 1] &&
1691 (v
[0] == '\'' || v
[0] == '"')) {
1695 bcopy(v
, propbuf
, l
);
1697 bsetprop(DDI_PROP_TYPE_STRING
, name
, name_len
,
1700 name
= value
+ value_len
;
1701 while (*name
== ',')
1707 * set boot-args property
1708 * 1275 name is bootargs, so set
1711 bsetprops("boot-args", boot_args
);
1712 bsetprops("bootargs", boot_args
);
1714 process_boot_environment(benv
);
1718 * Build boot command line for Fast Reboot
1720 build_fastboot_cmdline(xbp
);
1722 if (xbp
->bi_mb_version
== 1) {
1723 multiboot_info_t
*mbi
= xbp
->bi_mb_info
;
1725 struct sol_netinfo
*sip
;
1728 * set the BIOS boot device from GRUB
1733 * Save various boot information for Fast Reboot
1735 save_boot_info(xbp
);
1737 if (mbi
!= NULL
&& mbi
->flags
& MB_INFO_BOOTDEV
) {
1738 boot_device
= mbi
->boot_device
>> 24;
1739 if (boot_device
== 0x20)
1741 str
[0] = (boot_device
>> 4) + '0';
1742 str
[1] = (boot_device
& 0xf) + '0';
1744 bsetprops("bios-boot-device", str
);
1750 * In the netboot case, drives_info is overloaded with the
1751 * dhcp ack. This is not multiboot compliant and requires
1754 if (netboot
&& mbi
->drives_length
!= 0) {
1755 sip
= (struct sol_netinfo
*)(uintptr_t)mbi
->drives_addr
;
1756 if (sip
->sn_infotype
== SN_TYPE_BOOTP
)
1757 bsetprop(DDI_PROP_TYPE_BYTE
,
1759 sizeof ("bootp-response"),
1760 (void *)(uintptr_t)mbi
->drives_addr
,
1761 mbi
->drives_length
);
1762 else if (sip
->sn_infotype
== SN_TYPE_RARP
)
1763 setup_rarp_props(sip
);
1766 multiboot2_info_header_t
*mbi
= xbp
->bi_mb_info
;
1767 multiboot_tag_bootdev_t
*bootdev
= NULL
;
1768 multiboot_tag_network_t
*netdev
= NULL
;
1771 bootdev
= dboot_multiboot2_find_tag(mbi
,
1772 MULTIBOOT_TAG_TYPE_BOOTDEV
);
1773 netdev
= dboot_multiboot2_find_tag(mbi
,
1774 MULTIBOOT_TAG_TYPE_NETWORK
);
1776 if (bootdev
!= NULL
) {
1777 DBG(bootdev
->mb_biosdev
);
1778 boot_device
= bootdev
->mb_biosdev
;
1779 str
[0] = (boot_device
>> 4) + '0';
1780 str
[1] = (boot_device
& 0xf) + '0';
1782 bsetprops("bios-boot-device", str
);
1784 if (netdev
!= NULL
) {
1785 bsetprop(DDI_PROP_TYPE_BYTE
,
1786 "bootp-response", sizeof ("bootp-response"),
1787 (void *)(uintptr_t)netdev
->mb_dhcpack
,
1789 sizeof (multiboot_tag_network_t
));
1793 bsetprop32("stdout", stdout_val
);
1797 * more conjured up values for made up things....
1800 bsetprops("mfg-name", "i86xpv");
1801 bsetprops("impl-arch-name", "i86xpv");
1803 bsetprops("mfg-name", "i86pc");
1804 bsetprops("impl-arch-name", "i86pc");
1808 * Build firmware-provided system properties
1810 build_firmware_properties(xbp
);
1815 * Find out what these are:
1816 * - cpuid_feature_ecx_include
1817 * - cpuid_feature_ecx_exclude
1818 * - cpuid_feature_edx_include
1819 * - cpuid_feature_edx_exclude
1821 * Find out what these are in multiboot:
1829 * Under the Hypervisor, memory usable for DMA may be scarce. One
1830 * very likely large pool of DMA friendly memory is occupied by
1831 * the boot_archive, as it was loaded by grub into low MFNs.
1833 * Here we free up that memory by copying the boot archive to what are
1834 * likely higher MFN pages and then swapping the mfn/pfn mappings.
1836 #define PFN_2GIG 0x80000
1838 relocate_boot_archive(struct xboot_info
*xbp
)
1840 mfn_t max_mfn
= HYPERVISOR_memory_op(XENMEM_maximum_ram_page
, NULL
);
1841 struct boot_modules
*bm
= xbp
->bi_modules
;
1852 int mmu_update_return
;
1857 * If all MFN's are below 2Gig, don't bother doing this.
1859 if (max_mfn
< PFN_2GIG
)
1861 if (xbp
->bi_module_cnt
< 1) {
1862 DBG_MSG("no boot_archive!");
1866 DBG_MSG("moving boot_archive to high MFN memory\n");
1867 va
= (uintptr_t)bm
->bm_addr
;
1869 slop
= va
& MMU_PAGEOFFSET
;
1871 va
+= MMU_PAGESIZE
- slop
;
1872 len
-= MMU_PAGESIZE
- slop
;
1874 len
= P2ALIGN(len
, MMU_PAGESIZE
);
1877 * Go through all boot_archive pages, swapping any low MFN pages
1878 * with memory at next_phys.
1882 va_pfn
= mmu_btop(va
- ONE_GIG
);
1883 va_mfn
= mfn_list
[va_pfn
];
1884 if (mfn_list
[va_pfn
] < PFN_2GIG
) {
1885 copy
= kbm_remap_window(next_phys
, 1);
1886 bcopy((void *)va
, copy
, MMU_PAGESIZE
);
1887 copy_pfn
= mmu_btop(next_phys
);
1888 copy_mfn
= mfn_list
[copy_pfn
];
1890 pte
= mfn_to_ma(copy_mfn
) | PT_NOCONSIST
| PT_VALID
;
1891 if (HYPERVISOR_update_va_mapping(va
, pte
,
1892 UVMF_INVLPG
| UVMF_LOCAL
))
1893 bop_panic("relocate_boot_archive(): "
1894 "HYPERVISOR_update_va_mapping() failed");
1896 mfn_list
[va_pfn
] = copy_mfn
;
1897 mfn_list
[copy_pfn
] = va_mfn
;
1899 t
[0].ptr
= mfn_to_ma(copy_mfn
) | MMU_MACHPHYS_UPDATE
;
1901 t
[1].ptr
= mfn_to_ma(va_mfn
) | MMU_MACHPHYS_UPDATE
;
1902 t
[1].val
= copy_pfn
;
1903 if (HYPERVISOR_mmu_update(t
, 2, &mmu_update_return
,
1904 DOMID_SELF
) != 0 || mmu_update_return
!= 2)
1905 bop_panic("relocate_boot_archive(): "
1906 "HYPERVISOR_mmu_update() failed");
1908 next_phys
+= MMU_PAGESIZE
;
1911 len
-= MMU_PAGESIZE
;
1914 DBG_MSG("Relocated pages:\n");
1916 DBG_MSG("Out of total pages:\n");
1923 * simple description of a stack frame (args are 32 bit only currently)
1925 typedef struct bop_frame
{
1926 struct bop_frame
*old_frame
;
1932 bop_traceback(bop_frame_t
*frame
)
1939 bop_printf(NULL
, "Stack traceback:\n");
1940 for (cnt
= 0; cnt
< 30; ++cnt
) { /* up to 30 frames */
1941 pc
= frame
->retaddr
;
1944 ksym
= kobj_getsymname(pc
, &off
);
1946 bop_printf(NULL
, " %s+%lx", ksym
, off
);
1948 bop_printf(NULL
, " 0x%lx", pc
);
1950 frame
= frame
->old_frame
;
1952 bop_printf(NULL
, "\n");
1955 bop_printf(NULL
, "\n");
1960 ulong_t error_code
; /* optional */
1969 bop_trap(ulong_t
*tfp
)
1971 struct trapframe
*tf
= (struct trapframe
*)tfp
;
1972 bop_frame_t fakeframe
;
1973 static int depth
= 0;
1976 * Check for an infinite loop of traps.
1979 bop_panic("Nested trap");
1981 bop_printf(NULL
, "Unexpected trap\n");
1984 * adjust the tf for optional error_code by detecting the code selector
1986 if (tf
->code_seg
!= B64CODE_SEL
)
1987 tf
= (struct trapframe
*)(tfp
- 1);
1989 bop_printf(NULL
, "error code 0x%lx\n",
1990 tf
->error_code
& 0xffffffff);
1992 bop_printf(NULL
, "instruction pointer 0x%lx\n", tf
->inst_ptr
);
1993 bop_printf(NULL
, "code segment 0x%lx\n", tf
->code_seg
& 0xffff);
1994 bop_printf(NULL
, "flags register 0x%lx\n", tf
->flags_reg
);
1995 bop_printf(NULL
, "return %%rsp 0x%lx\n", tf
->stk_ptr
);
1996 bop_printf(NULL
, "return %%ss 0x%lx\n", tf
->stk_seg
& 0xffff);
1998 /* grab %[er]bp pushed by our code from the stack */
1999 fakeframe
.old_frame
= (bop_frame_t
*)*(tfp
- 3);
2000 fakeframe
.retaddr
= (pc_t
)tf
->inst_ptr
;
2001 bop_printf(NULL
, "Attempting stack backtrace:\n");
2002 bop_traceback(&fakeframe
);
2003 bop_panic("unexpected trap in early boot");
2006 extern void bop_trap_handler(void);
2008 static gate_desc_t
*bop_idt
;
2010 static desctbr_t bop_idt_info
;
2013 * Install a temporary IDT that lets us catch errors in the boot time code.
2014 * We shouldn't get any faults at all while this is installed, so we'll
2015 * just generate a traceback and exit.
2022 bop_idt
= (gate_desc_t
*)
2023 do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
2024 bzero(bop_idt
, MMU_PAGESIZE
);
2025 for (t
= 0; t
< NIDT
; ++t
) {
2027 * Note that since boot runs without a TSS, the
2028 * double fault handler cannot use an alternate stack (64-bit).
2030 set_gatesegd(&bop_idt
[t
], &bop_trap_handler
, B64CODE_SEL
,
2031 SDT_SYSIGT
, TRP_KPL
, 0);
2033 bop_idt_info
.dtr_limit
= (NIDT
* sizeof (gate_desc_t
)) - 1;
2034 bop_idt_info
.dtr_base
= (uintptr_t)bop_idt
;
2035 wr_idtr(&bop_idt_info
);
2037 #endif /* !defined(__xpv) */
2040 * This is where we enter the kernel. It dummies up the boot_ops and
2041 * boot_syscalls vectors and jumps off to _kobj_boot()
2044 _start(struct xboot_info
*xbp
)
2046 bootops_t
*bops
= &bootop
;
2047 extern void _kobj_boot();
2050 * 1st off - initialize the console for any error messages
2054 HYPERVISOR_shared_info
= (void *)xbp
->bi_shared_info
;
2055 xen_info
= xbp
->bi_xen_start_info
;
2059 if (*((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) ==
2061 post_fastreboot
= 1;
2062 *((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) = 0;
2072 if (find_boot_prop("kbm_debug") != NULL
)
2075 DBG_MSG("\n\n*** Entered Solaris in _start() cmdline is: ");
2076 DBG_MSG((char *)xbp
->bi_cmdline
);
2080 * physavail is no longer used by startup
2082 bm
.physinstalled
= xbp
->bi_phys_install
;
2083 bm
.pcimem
= xbp
->bi_pcimem
;
2084 bm
.rsvdmem
= xbp
->bi_rsvdmem
;
2085 bm
.physavail
= NULL
;
2088 * initialize the boot time allocator
2090 next_phys
= xbp
->bi_next_paddr
;
2092 next_virt
= (uintptr_t)xbp
->bi_next_vaddr
;
2094 DBG_MSG("Initializing boot time memory management...");
2097 xen_platform_parameters_t p
;
2099 /* This call shouldn't fail, dboot already did it once. */
2100 (void) HYPERVISOR_xen_version(XENVER_platform_parameters
, &p
);
2101 mfn_to_pfn_mapping
= (pfn_t
*)(xen_virt_start
= p
.virt_start
);
2102 DBG(xen_virt_start
);
2109 * Fill in the bootops vector
2111 bops
->bsys_version
= BO_VERSION
;
2112 bops
->boot_mem
= &bm
;
2113 bops
->bsys_alloc
= do_bsys_alloc
;
2114 bops
->bsys_free
= do_bsys_free
;
2115 bops
->bsys_getproplen
= do_bsys_getproplen
;
2116 bops
->bsys_getprop
= do_bsys_getprop
;
2117 bops
->bsys_nextprop
= do_bsys_nextprop
;
2118 bops
->bsys_printf
= bop_printf
;
2119 bops
->bsys_doint
= do_bsys_doint
;
2122 * BOP_EALLOC() is no longer needed
2124 bops
->bsys_ealloc
= do_bsys_ealloc
;
2128 * On domain 0 we need to free up some physical memory that is
2129 * usable for DMA. Since GRUB loaded the boot_archive, it is
2130 * sitting in low MFN memory. We'll relocated the boot archive
2131 * pages to high PFN memory.
2133 if (DOMAIN_IS_INITDOMAIN(xen_info
))
2134 relocate_boot_archive(xbp
);
2139 * Install an IDT to catch early pagefaults (shouldn't have any).
2140 * Also needed for kmdb.
2146 * Start building the boot properties from the command line
2148 DBG_MSG("Initializing boot properties:\n");
2149 build_boot_properties(xbp
);
2151 if (find_boot_prop("prom_debug") || kbm_debug
) {
2154 value
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
2155 boot_prop_display(value
);
2159 * jump into krtld...
2161 _kobj_boot(&bop_sysp
, NULL
, bops
, NULL
);
2167 no_more_alloc(bootops_t
*bop
, caddr_t virthint
, size_t size
, int align
)
2169 panic("Attempt to bsys_alloc() too late\n");
2175 no_more_free(bootops_t
*bop
, caddr_t virt
, size_t size
)
2177 panic("Attempt to bsys_free() too late\n");
2181 bop_no_more_mem(void)
2183 DBG(total_bop_alloc_scratch
);
2184 DBG(total_bop_alloc_kernel
);
2185 bootops
->bsys_alloc
= no_more_alloc
;
2186 bootops
->bsys_free
= no_more_free
;
2191 * Set ACPI firmware properties
2195 vmap_phys(size_t length
, paddr_t pa
)
2202 pa
= pfn_to_pa(xen_assign_pfn(mmu_btop(pa
))) | (pa
& MMU_PAGEOFFSET
);
2204 start
= P2ALIGN(pa
, MMU_PAGESIZE
);
2205 end
= P2ROUNDUP(pa
+ length
, MMU_PAGESIZE
);
2207 va
= (caddr_t
)alloc_vaddr(len
, MMU_PAGESIZE
);
2208 for (page
= 0; page
< len
; page
+= MMU_PAGESIZE
)
2209 kbm_map((uintptr_t)va
+ page
, start
+ page
, 0, 0);
2210 return (va
+ (pa
& MMU_PAGEOFFSET
));
2214 checksum_table(uint8_t *tp
, size_t len
)
2225 valid_rsdp(ACPI_TABLE_RSDP
*rp
)
2228 /* validate the V1.x checksum */
2229 if (checksum_table((uint8_t *)rp
, ACPI_RSDP_CHECKSUM_LENGTH
) != 0)
2232 /* If pre-ACPI 2.0, this is a valid RSDP */
2233 if (rp
->Revision
< 2)
2236 /* validate the V2.x checksum */
2237 if (checksum_table((uint8_t *)rp
, ACPI_RSDP_XCHECKSUM_LENGTH
) != 0)
2244 * Scan memory range for an RSDP;
2245 * see ACPI 3.0 Spec, 5.2.5.1
2247 static ACPI_TABLE_RSDP
*
2248 scan_rsdp(paddr_t start
, paddr_t end
)
2250 ssize_t len
= end
- start
;
2253 ptr
= vmap_phys(len
, start
);
2255 if (strncmp(ptr
, ACPI_SIG_RSDP
, strlen(ACPI_SIG_RSDP
)) == 0 &&
2256 valid_rsdp((ACPI_TABLE_RSDP
*)ptr
))
2257 return ((ACPI_TABLE_RSDP
*)ptr
);
2259 ptr
+= ACPI_RSDP_SCAN_STEP
;
2260 len
-= ACPI_RSDP_SCAN_STEP
;
2267 * Refer to ACPI 3.0 Spec, section 5.2.5.1 to understand this function
2269 static ACPI_TABLE_RSDP
*
2272 ACPI_TABLE_RSDP
*rsdp
;
2273 uint64_t rsdp_val
= 0;
2277 /* check for "acpi-root-tab" property */
2278 if (do_bsys_getproplen(NULL
, "acpi-root-tab") == sizeof (uint64_t)) {
2279 (void) do_bsys_getprop(NULL
, "acpi-root-tab", &rsdp_val
);
2280 if (rsdp_val
!= 0) {
2281 rsdp
= scan_rsdp(rsdp_val
, rsdp_val
+ sizeof (*rsdp
));
2285 "Using RSDP from bootloader: "
2286 "0x%p\n", (void *)rsdp
);
2294 * Get the EBDA segment and scan the first 1K
2296 ebda_seg
= (uint16_t *)vmap_phys(sizeof (uint16_t),
2297 ACPI_EBDA_PTR_LOCATION
);
2298 ebda_addr
= *ebda_seg
<< 4;
2299 rsdp
= scan_rsdp(ebda_addr
, ebda_addr
+ ACPI_EBDA_WINDOW_SIZE
);
2301 /* if EBDA doesn't contain RSDP, look in BIOS memory */
2302 rsdp
= scan_rsdp(ACPI_HI_RSDP_WINDOW_BASE
,
2303 ACPI_HI_RSDP_WINDOW_BASE
+ ACPI_HI_RSDP_WINDOW_SIZE
);
2307 static ACPI_TABLE_HEADER
*
2308 map_fw_table(paddr_t table_addr
)
2310 ACPI_TABLE_HEADER
*tp
;
2311 size_t len
= MAX(sizeof (*tp
), MMU_PAGESIZE
);
2314 * Map at least a page; if the table is larger than this, remap it
2316 tp
= (ACPI_TABLE_HEADER
*)vmap_phys(len
, table_addr
);
2317 if (tp
->Length
> len
)
2318 tp
= (ACPI_TABLE_HEADER
*)vmap_phys(tp
->Length
, table_addr
);
2322 static ACPI_TABLE_HEADER
*
2323 find_fw_table(char *signature
)
2325 static int revision
= 0;
2326 static ACPI_TABLE_XSDT
*xsdt
;
2329 ACPI_TABLE_RSDP
*rsdp
;
2330 ACPI_TABLE_HEADER
*tp
;
2334 if (strlen(signature
) != ACPI_NAME_SIZE
)
2338 * Reading the ACPI 3.0 Spec, section 5.2.5.3 will help
2339 * understand this code. If we haven't already found the RSDT/XSDT,
2340 * revision will be 0. Find the RSDP and check the revision
2341 * to find out whether to use the RSDT or XSDT. If revision is
2342 * 0 or 1, use the RSDT and set internal revision to 1; if it is 2,
2343 * use the XSDT. If the XSDT address is 0, though, fall back to
2344 * revision 1 and use the RSDT.
2346 if (revision
== 0) {
2347 if ((rsdp
= find_rsdp()) != NULL
) {
2348 revision
= rsdp
->Revision
;
2350 * ACPI 6.0 states that current revision is 2
2351 * from acpi_table_rsdp definition:
2352 * Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+
2359 * Use the XSDT unless BIOS is buggy and
2360 * claims to be rev 2 but has a null XSDT
2363 xsdt_addr
= rsdp
->XsdtPhysicalAddress
;
2368 /* treat RSDP rev 0 as revision 1 internally */
2372 /* use the RSDT for rev 0/1 */
2373 xsdt_addr
= rsdp
->RsdtPhysicalAddress
;
2376 /* unknown revision */
2384 /* cache the XSDT info */
2385 xsdt
= (ACPI_TABLE_XSDT
*)map_fw_table(xsdt_addr
);
2386 len
= (xsdt
->Header
.Length
- sizeof (xsdt
->Header
)) /
2387 ((revision
== 1) ? sizeof (uint32_t) : sizeof (uint64_t));
2391 * Scan the table headers looking for a signature match
2393 for (n
= 0; n
< len
; n
++) {
2394 ACPI_TABLE_RSDT
*rsdt
= (ACPI_TABLE_RSDT
*)xsdt
;
2395 table_addr
= (revision
== 1) ? rsdt
->TableOffsetEntry
[n
] :
2396 xsdt
->TableOffsetEntry
[n
];
2398 if (table_addr
== 0)
2400 tp
= map_fw_table(table_addr
);
2401 if (strncmp(tp
->Signature
, signature
, ACPI_NAME_SIZE
) == 0) {
2409 process_mcfg(ACPI_TABLE_MCFG
*tp
)
2411 ACPI_MCFG_ALLOCATION
*cfg_baap
;
2413 int64_t ecfginfo
[4];
2415 cfg_baap
= (ACPI_MCFG_ALLOCATION
*)((uintptr_t)tp
+ sizeof (*tp
));
2416 cfg_baa_endp
= ((char *)tp
) + tp
->Header
.Length
;
2417 while ((char *)cfg_baap
< cfg_baa_endp
) {
2418 if (cfg_baap
->Address
!= 0 && cfg_baap
->PciSegment
== 0) {
2419 ecfginfo
[0] = cfg_baap
->Address
;
2420 ecfginfo
[1] = cfg_baap
->PciSegment
;
2421 ecfginfo
[2] = cfg_baap
->StartBusNumber
;
2422 ecfginfo
[3] = cfg_baap
->EndBusNumber
;
2423 bsetprop(DDI_PROP_TYPE_INT64
,
2424 MCFG_PROPNAME
, strlen(MCFG_PROPNAME
),
2425 ecfginfo
, sizeof (ecfginfo
));
2434 process_madt_entries(ACPI_TABLE_MADT
*tp
, uint32_t *cpu_countp
,
2435 uint32_t *cpu_possible_countp
, uint32_t *cpu_apicid_array
)
2437 ACPI_SUBTABLE_HEADER
*item
, *end
;
2438 uint32_t cpu_count
= 0;
2439 uint32_t cpu_possible_count
= 0;
2442 * Determine number of CPUs and keep track of "final" APIC ID
2443 * for each CPU by walking through ACPI MADT processor list
2445 end
= (ACPI_SUBTABLE_HEADER
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2446 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)tp
+ sizeof (*tp
));
2448 while (item
< end
) {
2449 switch (item
->Type
) {
2450 case ACPI_MADT_TYPE_LOCAL_APIC
: {
2451 ACPI_MADT_LOCAL_APIC
*cpu
=
2452 (ACPI_MADT_LOCAL_APIC
*) item
;
2454 if (cpu
->LapicFlags
& ACPI_MADT_ENABLED
) {
2455 if (cpu_apicid_array
!= NULL
)
2456 cpu_apicid_array
[cpu_count
] = cpu
->Id
;
2459 cpu_possible_count
++;
2462 case ACPI_MADT_TYPE_LOCAL_X2APIC
: {
2463 ACPI_MADT_LOCAL_X2APIC
*cpu
=
2464 (ACPI_MADT_LOCAL_X2APIC
*) item
;
2466 if (cpu
->LapicFlags
& ACPI_MADT_ENABLED
) {
2467 if (cpu_apicid_array
!= NULL
)
2468 cpu_apicid_array
[cpu_count
] =
2472 cpu_possible_count
++;
2477 bop_printf(NULL
, "MADT type %d\n", item
->Type
);
2481 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)item
+ item
->Length
);
2484 *cpu_countp
= cpu_count
;
2485 if (cpu_possible_countp
)
2486 *cpu_possible_countp
= cpu_possible_count
;
2490 process_madt(ACPI_TABLE_MADT
*tp
)
2492 uint32_t cpu_count
= 0;
2493 uint32_t cpu_possible_count
= 0;
2494 uint32_t *cpu_apicid_array
; /* x2APIC ID is 32bit! */
2498 process_madt_entries(tp
, &cpu_count
, &cpu_possible_count
, NULL
);
2500 cpu_apicid_array
= (uint32_t *)do_bsys_alloc(NULL
, NULL
,
2501 cpu_count
* sizeof (*cpu_apicid_array
), MMU_PAGESIZE
);
2502 if (cpu_apicid_array
== NULL
)
2503 bop_panic("Not enough memory for APIC ID array");
2506 process_madt_entries(tp
, NULL
, NULL
, cpu_apicid_array
);
2509 * Make boot property for array of "final" APIC IDs for each
2512 bsetprop(DDI_PROP_TYPE_INT
,
2513 BP_CPU_APICID_ARRAY
, strlen(BP_CPU_APICID_ARRAY
),
2514 cpu_apicid_array
, cpu_count
* sizeof (*cpu_apicid_array
));
2518 * Check whether property plat-max-ncpus is already set.
2520 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2522 * Set plat-max-ncpus to number of maximum possible CPUs given
2523 * in MADT if it hasn't been set.
2524 * There's no formal way to detect max possible CPUs supported
2525 * by platform according to ACPI spec3.0b. So current CPU
2526 * hotplug implementation expects that all possible CPUs will
2527 * have an entry in MADT table and set plat-max-ncpus to number
2528 * of entries in MADT.
2529 * With introducing of ACPI4.0, Maximum System Capability Table
2530 * (MSCT) provides maximum number of CPUs supported by platform.
2531 * If MSCT is unavailable, fall back to old way.
2534 bsetpropsi(PLAT_MAX_NCPUS_NAME
, cpu_possible_count
);
2538 * Set boot property boot-max-ncpus to number of CPUs existing at
2539 * boot time. boot-max-ncpus is mainly used for optimization.
2542 bsetpropsi(BOOT_MAX_NCPUS_NAME
, cpu_count
);
2545 * User-set boot-ncpus overrides firmware count
2547 if (do_bsys_getproplen(NULL
, BOOT_NCPUS_NAME
) >= 0)
2551 * Set boot property boot-ncpus to number of active CPUs given in MADT
2552 * if it hasn't been set yet.
2555 bsetpropsi(BOOT_NCPUS_NAME
, cpu_count
);
2559 process_srat(ACPI_TABLE_SRAT
*tp
)
2561 ACPI_SUBTABLE_HEADER
*item
, *end
;
2563 int proc_num
, mem_num
;
2582 uint64_t maxmem
= 0;
2587 proc_num
= mem_num
= 0;
2588 end
= (ACPI_SUBTABLE_HEADER
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2589 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)tp
+ sizeof (*tp
));
2590 while (item
< end
) {
2591 switch (item
->Type
) {
2592 case ACPI_SRAT_TYPE_CPU_AFFINITY
: {
2593 ACPI_SRAT_CPU_AFFINITY
*cpu
=
2594 (ACPI_SRAT_CPU_AFFINITY
*) item
;
2596 if (!(cpu
->Flags
& ACPI_SRAT_CPU_ENABLED
))
2598 processor
.domain
= cpu
->ProximityDomainLo
;
2599 for (i
= 0; i
< 3; i
++)
2601 cpu
->ProximityDomainHi
[i
] << ((i
+ 1) * 8);
2602 processor
.apic_id
= cpu
->ApicId
;
2603 processor
.sapic_id
= cpu
->LocalSapicEid
;
2604 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2606 bsetprop(DDI_PROP_TYPE_INT
,
2607 prop_name
, strlen(prop_name
), &processor
,
2608 sizeof (processor
));
2612 case ACPI_SRAT_TYPE_MEMORY_AFFINITY
: {
2613 ACPI_SRAT_MEM_AFFINITY
*mem
=
2614 (ACPI_SRAT_MEM_AFFINITY
*)item
;
2616 if (!(mem
->Flags
& ACPI_SRAT_MEM_ENABLED
))
2618 memory
.domain
= mem
->ProximityDomain
;
2619 memory
.addr
= mem
->BaseAddress
;
2620 memory
.length
= mem
->Length
;
2621 memory
.flags
= mem
->Flags
;
2622 (void) snprintf(prop_name
, 30, "acpi-srat-memory-%d",
2624 bsetprop(DDI_PROP_TYPE_INT
,
2625 prop_name
, strlen(prop_name
), &memory
,
2627 if ((mem
->Flags
& ACPI_SRAT_MEM_HOT_PLUGGABLE
) &&
2628 (memory
.addr
+ memory
.length
> maxmem
)) {
2629 maxmem
= memory
.addr
+ memory
.length
;
2634 case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY
: {
2635 ACPI_SRAT_X2APIC_CPU_AFFINITY
*x2cpu
=
2636 (ACPI_SRAT_X2APIC_CPU_AFFINITY
*) item
;
2638 if (!(x2cpu
->Flags
& ACPI_SRAT_CPU_ENABLED
))
2640 x2apic
.domain
= x2cpu
->ProximityDomain
;
2641 x2apic
.x2apic_id
= x2cpu
->ApicId
;
2642 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2644 bsetprop(DDI_PROP_TYPE_INT
,
2645 prop_name
, strlen(prop_name
), &x2apic
,
2652 bop_printf(NULL
, "SRAT type %d\n", item
->Type
);
2656 item
= (ACPI_SUBTABLE_HEADER
*)
2657 (item
->Length
+ (uintptr_t)item
);
2661 * The maximum physical address calculated from the SRAT table is more
2662 * accurate than that calculated from the MSCT table.
2665 plat_dr_physmax
= btop(maxmem
);
2670 process_slit(ACPI_TABLE_SLIT
*tp
)
2674 * Check the number of localities; if it's too huge, we just
2675 * return and locality enumeration code will handle this later,
2678 * Note that the size of the table is the square of the
2679 * number of localities; if the number of localities exceeds
2680 * UINT16_MAX, the table size may overflow an int when being
2681 * passed to bsetprop() below.
2683 if (tp
->LocalityCount
>= SLIT_LOCALITIES_MAX
)
2686 bsetprop64(SLIT_NUM_PROPNAME
, tp
->LocalityCount
);
2687 bsetprop(DDI_PROP_TYPE_BYTE
,
2688 SLIT_PROPNAME
, strlen(SLIT_PROPNAME
), &tp
->Entry
,
2689 tp
->LocalityCount
* tp
->LocalityCount
);
2692 static ACPI_TABLE_MSCT
*
2693 process_msct(ACPI_TABLE_MSCT
*tp
)
2697 ACPI_MSCT_PROXIMITY
*item
, *end
;
2698 extern uint64_t plat_dr_options
;
2702 end
= (ACPI_MSCT_PROXIMITY
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2703 for (item
= (void *)((uintptr_t)tp
+ tp
->ProximityOffset
);
2705 item
= (void *)(item
->Length
+ (uintptr_t)item
)) {
2707 * Sanity check according to section 5.2.19.1 of ACPI 4.0.
2711 if (item
->Revision
!= 1 || item
->Length
!= 22) {
2713 "?boot: unknown proximity domain structure in MSCT "
2714 "with Revision(%d), Length(%d).\n",
2715 (int)item
->Revision
, (int)item
->Length
);
2717 } else if (item
->RangeStart
> item
->RangeEnd
) {
2719 "?boot: invalid proximity domain structure in MSCT "
2720 "with RangeStart(%u), RangeEnd(%u).\n",
2721 item
->RangeStart
, item
->RangeEnd
);
2723 } else if (item
->RangeStart
!= last_seen
) {
2725 * Items must be organized in ascending order of the
2726 * proximity domain enumerations.
2729 "?boot: invalid proximity domain structure in MSCT,"
2730 " items are not orginized in ascending order.\n");
2735 * If ProcessorCapacity is 0 then there would be no CPUs in this
2738 if (item
->ProcessorCapacity
!= 0) {
2739 proc_num
+= (item
->RangeEnd
- item
->RangeStart
+ 1) *
2740 item
->ProcessorCapacity
;
2743 last_seen
= item
->RangeEnd
- item
->RangeStart
+ 1;
2745 * Break out if all proximity domains have been processed.
2746 * Some BIOSes may have unused items at the end of MSCT table.
2748 if (last_seen
> tp
->MaxProximityDomains
) {
2752 if (last_seen
!= tp
->MaxProximityDomains
+ 1) {
2754 "?boot: invalid proximity domain structure in MSCT, "
2755 "proximity domain count doesn't match.\n");
2760 * Set plat-max-ncpus property if it hasn't been set yet.
2762 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2763 if (proc_num
!= 0) {
2764 bsetpropsi(PLAT_MAX_NCPUS_NAME
, proc_num
);
2769 * Use Maximum Physical Address from the MSCT table as upper limit for
2770 * memory hot-adding by default. It may be overridden by value from
2771 * the SRAT table or the "plat-dr-physmax" boot option.
2773 plat_dr_physmax
= btop(tp
->MaxAddress
+ 1);
2776 * Existence of MSCT implies CPU/memory hotplug-capability for the
2779 plat_dr_options
|= PLAT_DR_FEATURE_CPU
;
2780 plat_dr_options
|= PLAT_DR_FEATURE_MEMORY
;
2787 enumerate_xen_cpus()
2789 processorid_t id
, max_id
;
2792 * User-set boot-ncpus overrides enumeration
2794 if (do_bsys_getproplen(NULL
, BOOT_NCPUS_NAME
) >= 0)
2798 * Probe every possible virtual CPU id and remember the
2799 * highest id present; the count of CPUs is one greater
2800 * than this. This tacitly assumes at least cpu 0 is present.
2803 for (id
= 0; id
< MAX_VIRT_CPUS
; id
++)
2804 if (HYPERVISOR_vcpu_op(VCPUOP_is_up
, id
, NULL
) == 0)
2807 bsetpropsi(BOOT_NCPUS_NAME
, max_id
+1);
2814 build_firmware_properties(struct xboot_info
*xbp
)
2816 ACPI_TABLE_HEADER
*tp
= NULL
;
2819 if (xbp
->bi_uefi_arch
== XBI_UEFI_ARCH_64
) {
2820 bsetprops("efi-systype", "64");
2821 bsetprop64("efi-systab",
2822 (uint64_t)(uintptr_t)xbp
->bi_uefi_systab
);
2824 bop_printf(NULL
, "64-bit UEFI detected.\n");
2825 } else if (xbp
->bi_uefi_arch
== XBI_UEFI_ARCH_32
) {
2826 bsetprops("efi-systype", "32");
2827 bsetprop64("efi-systab",
2828 (uint64_t)(uintptr_t)xbp
->bi_uefi_systab
);
2830 bop_printf(NULL
, "32-bit UEFI detected.\n");
2833 if (xbp
->bi_acpi_rsdp
!= NULL
) {
2834 bsetprop64("acpi-root-tab",
2835 (uint64_t)(uintptr_t)xbp
->bi_acpi_rsdp
);
2838 if (xbp
->bi_smbios
!= NULL
) {
2839 bsetprop64("smbios-address",
2840 (uint64_t)(uintptr_t)xbp
->bi_smbios
);
2843 if ((tp
= find_fw_table(ACPI_SIG_MSCT
)) != NULL
)
2844 msct_ptr
= process_msct((ACPI_TABLE_MSCT
*)tp
);
2848 if ((tp
= find_fw_table(ACPI_SIG_MADT
)) != NULL
)
2849 process_madt((ACPI_TABLE_MADT
*)tp
);
2851 if ((srat_ptr
= (ACPI_TABLE_SRAT
*)
2852 find_fw_table(ACPI_SIG_SRAT
)) != NULL
)
2853 process_srat(srat_ptr
);
2855 if (slit_ptr
= (ACPI_TABLE_SLIT
*)find_fw_table(ACPI_SIG_SLIT
))
2856 process_slit(slit_ptr
);
2858 tp
= find_fw_table(ACPI_SIG_MCFG
);
2860 enumerate_xen_cpus();
2861 if (DOMAIN_IS_INITDOMAIN(xen_info
))
2862 tp
= find_fw_table(ACPI_SIG_MCFG
);
2865 process_mcfg((ACPI_TABLE_MCFG
*)tp
);
2869 * fake up a boot property for deferred early console output
2870 * this is used by both graphical boot and the (developer only)
2871 * USB serial console
2874 defcons_init(size_t size
)
2876 static char *p
= NULL
;
2878 p
= do_bsys_alloc(NULL
, NULL
, size
, MMU_PAGESIZE
);
2880 bsetprop32("deferred-console-buf", (uint32_t)((uintptr_t)&p
));
2886 boot_compinfo(int fd
, struct compinfo
*cbp
)
2889 cbp
->blksize
= MAXBSIZE
;
2893 #define BP_MAX_STRLEN 32
2896 * Get value for given boot property
2899 bootprop_getval(const char *prop_name
, u_longlong_t
*prop_value
)
2902 char str
[BP_MAX_STRLEN
];
2905 boot_prop_len
= BOP_GETPROPLEN(bootops
, prop_name
);
2906 if (boot_prop_len
< 0 || boot_prop_len
> sizeof (str
) ||
2907 BOP_GETPROP(bootops
, prop_name
, str
) < 0 ||
2908 kobj_getvalue(str
, &value
) == -1)
2912 *prop_value
= value
;