4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2010, Intel Corporation.
27 * All rights reserved.
29 * Copyright 2013 Joyent, Inc. All rights reserved.
33 * This file contains the functionality that mimics the boot operations
34 * on SPARC systems or the old boot.bin/multiboot programs on x86 systems.
35 * The x86 kernel now does everything on its own.
38 #include <sys/types.h>
39 #include <sys/bootconf.h>
40 #include <sys/bootsvcs.h>
41 #include <sys/bootinfo.h>
42 #include <sys/multiboot.h>
43 #include <sys/bootvfs.h>
44 #include <sys/bootprops.h>
45 #include <sys/varargs.h>
46 #include <sys/param.h>
47 #include <sys/machparam.h>
48 #include <sys/machsystm.h>
49 #include <sys/archsystm.h>
50 #include <sys/boot_console.h>
51 #include <sys/cmn_err.h>
52 #include <sys/systm.h>
53 #include <sys/promif.h>
54 #include <sys/archsystm.h>
55 #include <sys/x86_archext.h>
57 #include <sys/privregs.h>
58 #include <sys/sysmacros.h>
59 #include <sys/ctype.h>
60 #include <sys/fastboot.h>
62 #include <sys/hypervisor.h>
65 #include <vm/kboot_mmu.h>
66 #include <vm/hat_pte.h>
68 #include <sys/kobj_lex.h>
69 #include <sys/pci_cfgspace_impl.h>
70 #include <sys/fastboot_impl.h>
71 #include <sys/acpi/acconfig.h>
72 #include <sys/acpi/acpi.h>
74 static int have_console
= 0; /* set once primitive console is initialized */
75 static char *boot_args
= "";
80 static uint_t kbm_debug
= 0;
81 #define DBG_MSG(s) { if (kbm_debug) bop_printf(NULL, "%s", s); }
82 #define DBG(x) { if (kbm_debug) \
83 bop_printf(NULL, "%s is %" PRIx64 "\n", #x, (uint64_t)(x)); \
86 #define PUT_STRING(s) { \
88 for (cp = (s); *cp; ++cp) \
92 struct xboot_info
*xbootp
; /* boot info from "glue" code in low memory */
93 bootops_t bootop
; /* simple bootops we'll pass on to kernel */
96 static uintptr_t next_virt
; /* next available virtual address */
97 static paddr_t next_phys
; /* next available physical address from dboot */
98 static paddr_t high_phys
= -(paddr_t
)1; /* last used physical address */
101 * buffer for vsnprintf for console I/O
103 #define BUFFERSIZE 512
104 static char buffer
[BUFFERSIZE
];
106 * stuff to store/report/manipulate boot property settings.
108 typedef struct bootprop
{
109 struct bootprop
*bp_next
;
115 static bootprop_t
*bprops
= NULL
;
116 static char *curr_page
= NULL
; /* ptr to avail bprop memory */
117 static int curr_space
= 0; /* amount of memory at curr_page */
120 start_info_t
*xen_info
;
121 shared_info_t
*HYPERVISOR_shared_info
;
125 * some allocator statistics
127 static ulong_t total_bop_alloc_scratch
= 0;
128 static ulong_t total_bop_alloc_kernel
= 0;
130 static void build_firmware_properties(void);
132 static int early_allocation
= 1;
134 int force_fastreboot
= 0;
135 volatile int fastreboot_onpanic
= 0;
136 int post_fastreboot
= 0;
138 volatile int fastreboot_capable
= 0;
140 volatile int fastreboot_capable
= 1;
144 * Information saved from current boot for fast reboot.
145 * If the information size exceeds what we have allocated, fast reboot
146 * will not be supported.
148 multiboot_info_t saved_mbi
;
149 mb_memory_map_t saved_mmap
[FASTBOOT_SAVED_MMAP_COUNT
];
150 uint8_t saved_drives
[FASTBOOT_SAVED_DRIVES_SIZE
];
151 char saved_cmdline
[FASTBOOT_SAVED_CMDLINE_LEN
];
152 int saved_cmdline_len
= 0;
153 size_t saved_file_size
[FASTBOOT_MAX_FILES_MAP
];
156 * Turn off fastreboot_onpanic to avoid panic loop.
158 char fastreboot_onpanic_cmdline
[FASTBOOT_SAVED_CMDLINE_LEN
];
159 static const char fastreboot_onpanic_args
[] = " -B fastreboot_onpanic=0";
162 * Pointers to where System Resource Affinity Table (SRAT), System Locality
163 * Information Table (SLIT) and Maximum System Capability Table (MSCT)
164 * are mapped into virtual memory
166 ACPI_TABLE_SRAT
*srat_ptr
= NULL
;
167 ACPI_TABLE_SLIT
*slit_ptr
= NULL
;
168 ACPI_TABLE_MSCT
*msct_ptr
= NULL
;
171 * Arbitrary limit on number of localities we handle; if
172 * this limit is raised to more than UINT16_MAX, make sure
173 * process_slit() knows how to handle it.
175 #define SLIT_LOCALITIES_MAX (4096)
177 #define SLIT_NUM_PROPNAME "acpi-slit-localities"
178 #define SLIT_PROPNAME "acpi-slit"
181 * Allocate aligned physical memory at boot time. This allocator allocates
182 * from the highest possible addresses. This avoids exhausting memory that
183 * would be useful for DMA buffers.
186 do_bop_phys_alloc(uint64_t size
, uint64_t align
)
191 struct memlist
*ml
= (struct memlist
*)xbootp
->bi_phys_install
;
194 * Be careful if high memory usage is limited in startup.c
195 * Since there are holes in the low part of the physical address
196 * space we can treat physmem as a pfn (not just a pgcnt) and
197 * get a conservative upper limit.
199 if (physmem
!= 0 && high_phys
> pfn_to_pa(physmem
))
200 high_phys
= pfn_to_pa(physmem
);
203 * find the lowest or highest available memory in physinstalled
204 * On 32 bit avoid physmem above 4Gig if PAE isn't enabled
207 if (xbootp
->bi_use_pae
== 0 && high_phys
> FOUR_GIG
)
208 high_phys
= FOUR_GIG
;
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",
355 prom_panic("unsupported call to BOP_EALLOC()\n");
361 bsetprop(char *name
, int nlen
, void *value
, int vlen
)
368 * align the size to 16 byte boundary
370 size
= sizeof (bootprop_t
) + nlen
+ 1 + vlen
;
371 size
= (size
+ 0xf) & ~0xf;
372 if (size
> curr_space
) {
373 need_size
= (size
+ (MMU_PAGEOFFSET
)) & MMU_PAGEMASK
;
374 curr_page
= do_bsys_alloc(NULL
, 0, need_size
, MMU_PAGESIZE
);
375 curr_space
= need_size
;
379 * use a bootprop_t at curr_page and link into list
381 b
= (bootprop_t
*)curr_page
;
382 curr_page
+= sizeof (bootprop_t
);
383 curr_space
-= sizeof (bootprop_t
);
388 * follow by name and ending zero byte
390 b
->bp_name
= curr_page
;
391 bcopy(name
, curr_page
, nlen
);
394 curr_space
-= nlen
+ 1;
397 * copy in value, but no ending zero byte
399 b
->bp_value
= curr_page
;
402 bcopy(value
, curr_page
, vlen
);
408 * align new values of curr_page, curr_space
410 while (curr_space
& 0xf) {
417 bsetprops(char *name
, char *value
)
419 bsetprop(name
, strlen(name
), value
, strlen(value
) + 1);
423 bsetprop64(char *name
, uint64_t value
)
425 bsetprop(name
, strlen(name
), (void *)&value
, sizeof (value
));
429 bsetpropsi(char *name
, int value
)
433 (void) snprintf(prop_val
, sizeof (prop_val
), "%d", value
);
434 bsetprops(name
, prop_val
);
438 * to find the size of the buffer to allocate
442 do_bsys_getproplen(bootops_t
*bop
, const char *name
)
446 for (b
= bprops
; b
; b
= b
->bp_next
) {
447 if (strcmp(name
, b
->bp_name
) != 0)
455 * get the value associated with this name
459 do_bsys_getprop(bootops_t
*bop
, const char *name
, void *value
)
463 for (b
= bprops
; b
; b
= b
->bp_next
) {
464 if (strcmp(name
, b
->bp_name
) != 0)
466 bcopy(b
->bp_value
, value
, b
->bp_vlen
);
473 * get the name of the next property in succession from the standalone
477 do_bsys_nextprop(bootops_t
*bop
, char *name
)
482 * A null name is a special signal for the 1st boot property
484 if (name
== NULL
|| strlen(name
) == 0) {
487 return (bprops
->bp_name
);
490 for (b
= bprops
; b
; b
= b
->bp_next
) {
491 if (name
!= b
->bp_name
)
502 * Parse numeric value from a string. Understands decimal, hex, octal, - and ~
505 parse_value(char *p
, uint64_t *retval
)
513 if (*p
== '-' || *p
== '~')
520 if (*p
== 'x' || *p
== 'X') {
529 if ('0' <= *p
&& *p
<= '9')
531 else if ('a' <= *p
&& *p
<= 'f')
532 digit
= 10 + *p
- 'a';
533 else if ('A' <= *p
&& *p
<= 'F')
534 digit
= 10 + *p
- 'A';
539 tmp
= tmp
* radix
+ digit
;
544 else if (adjust
== '~')
551 * 2nd part of building the table of boot properties. This includes:
552 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
554 * lines look like one of:
556 * ^# comment till end of line
557 * setprop name 'value'
559 * setprop name "value"
561 * we do single character I/O since this is really just looking at memory
564 boot_prop_finish(void)
574 char *inputdev
; /* these override the command line if serial ports */
581 if (!DOMAIN_IS_INITDOMAIN(xen_info
))
585 DBG_MSG("Opening /boot/solaris/bootenv.rc\n");
586 fd
= BRD_OPEN(bfs_ops
, "/boot/solaris/bootenv.rc", 0);
589 line
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
596 bytes_read
= BRD_READ(bfs_ops
, fd
, line
+ c
, 1);
597 if (bytes_read
== 0) {
608 * ignore comment lines
611 while (ISSPACE(line
[c
]))
613 if (line
[c
] == '#' || line
[c
] == 0)
617 * must have "setprop " or "setprop\t"
619 if (strncmp(line
+ c
, "setprop ", 8) != 0 &&
620 strncmp(line
+ c
, "setprop\t", 8) != 0)
623 while (ISSPACE(line
[c
]))
629 * gather up the property name
633 while (line
[c
] && !ISSPACE(line
[c
]))
637 * gather up the value, if any
641 while (ISSPACE(line
[c
]))
645 while (line
[c
] && !ISSPACE(line
[c
]))
649 if (v_len
>= 2 && value
[0] == value
[v_len
- 1] &&
650 (value
[0] == '\'' || value
[0] == '"')) {
661 * ignore "boot-file" property, it's now meaningless
663 if (strcmp(name
, "boot-file") == 0)
665 if (strcmp(name
, "boot-args") == 0 &&
666 strlen(boot_args
) > 0)
670 * If a property was explicitly set on the command line
671 * it will override a setting in bootenv.rc
673 if (do_bsys_getproplen(NULL
, name
) > 0)
676 bsetprop(name
, n_len
, value
, v_len
+ 1);
680 (void) BRD_CLOSE(bfs_ops
, fd
);
683 * Check if we have to limit the boot time allocator
685 if (do_bsys_getproplen(NULL
, "physmem") != -1 &&
686 do_bsys_getprop(NULL
, "physmem", line
) >= 0 &&
687 parse_value(line
, &lvalue
) != -1) {
688 if (0 < lvalue
&& (lvalue
< physmem
|| physmem
== 0)) {
689 physmem
= (pgcnt_t
)lvalue
;
693 early_allocation
= 0;
696 * check to see if we have to override the default value of the console
700 v_len
= do_bsys_getproplen(NULL
, "input-device");
702 (void) do_bsys_getprop(NULL
, "input-device", inputdev
);
707 outputdev
= inputdev
+ v_len
+ 1;
708 v_len
= do_bsys_getproplen(NULL
, "output-device");
710 (void) do_bsys_getprop(NULL
, "output-device",
714 outputdev
[v_len
] = 0;
716 consoledev
= outputdev
+ v_len
+ 1;
717 v_len
= do_bsys_getproplen(NULL
, "console");
719 (void) do_bsys_getprop(NULL
, "console", consoledev
);
720 if (post_fastreboot
&&
721 strcmp(consoledev
, "graphics") == 0) {
722 bsetprops("console", "text");
723 v_len
= strlen("text");
724 bcopy("text", consoledev
, v_len
);
729 consoledev
[v_len
] = 0;
730 bcons_init2(inputdev
, outputdev
, consoledev
);
733 * Ensure console property exists
734 * If not create it as "hypervisor"
736 v_len
= do_bsys_getproplen(NULL
, "console");
738 bsetprops("console", "hypervisor");
739 inputdev
= outputdev
= consoledev
= "hypervisor";
740 bcons_init2(inputdev
, outputdev
, consoledev
);
743 if (strstr((char *)xbootp
->bi_cmdline
, "prom_debug") || kbm_debug
) {
745 bop_printf(NULL
, "\nBoot properties:\n");
747 while ((name
= do_bsys_nextprop(NULL
, name
)) != NULL
) {
748 bop_printf(NULL
, "\t0x%p %s = ", (void *)name
, name
);
749 (void) do_bsys_getprop(NULL
, name
, value
);
750 v_len
= do_bsys_getproplen(NULL
, name
);
751 bop_printf(NULL
, "len=%d ", v_len
);
753 bop_printf(NULL
, "%s\n", value
);
759 * print formatted output
764 bop_printf(bootops_t
*bop
, const char *fmt
, ...)
768 if (have_console
== 0)
772 (void) vsnprintf(buffer
, BUFFERSIZE
, fmt
, ap
);
778 * Another panic() variant; this one can be used even earlier during boot than
783 bop_panic(const char *fmt
, ...)
788 bop_printf(NULL
, fmt
, ap
);
791 bop_printf(NULL
, "\nPress any key to reboot.\n");
792 (void) bcons_getchar();
793 bop_printf(NULL
, "Resetting...\n");
798 * Do a real mode interrupt BIOS call
800 typedef struct bios_regs
{
801 unsigned short ax
, bx
, cx
, dx
, si
, di
, bp
, es
, ds
;
803 typedef int (*bios_func_t
)(int, bios_regs_t
*);
807 do_bsys_doint(bootops_t
*bop
, int intnum
, struct bop_regs
*rp
)
810 prom_panic("unsupported call to BOP_DOINT()\n");
812 static int firsttime
= 1;
813 bios_func_t bios_func
= (bios_func_t
)(void *)(uintptr_t)0x5000;
817 * The first time we do this, we have to copy the pre-packaged
818 * low memory bios call code image into place.
821 extern char bios_image
[];
822 extern uint32_t bios_size
;
824 bcopy(bios_image
, (void *)bios_func
, bios_size
);
828 br
.ax
= rp
->eax
.word
.ax
;
829 br
.bx
= rp
->ebx
.word
.bx
;
830 br
.cx
= rp
->ecx
.word
.cx
;
831 br
.dx
= rp
->edx
.word
.dx
;
832 br
.bp
= rp
->ebp
.word
.bp
;
833 br
.si
= rp
->esi
.word
.si
;
834 br
.di
= rp
->edi
.word
.di
;
838 DBG_MSG("Doing BIOS call...");
842 rp
->eflags
= bios_func(intnum
, &br
);
845 rp
->eax
.word
.ax
= br
.ax
;
846 rp
->ebx
.word
.bx
= br
.bx
;
847 rp
->ecx
.word
.cx
= br
.cx
;
848 rp
->edx
.word
.dx
= br
.dx
;
849 rp
->ebp
.word
.bp
= br
.bp
;
850 rp
->esi
.word
.si
= br
.si
;
851 rp
->edi
.word
.di
= br
.di
;
857 static struct boot_syscalls bop_sysp
= {
869 static char namebuf
[32];
872 xen_parse_props(char *s
, char *prop_map
[], int n_prop
)
874 char **prop_name
= prop_map
;
879 while ((*cp
!= NULL
) && (*cp
!= ':'))
882 if ((scp
!= cp
) && (*prop_name
!= NULL
)) {
884 bsetprops(*prop_name
, scp
);
890 } while (n_prop
> 0);
893 #define VBDPATHLEN 64
896 * parse the 'xpv-root' property to create properties used by
900 xen_vbdroot_props(char *s
)
902 char vbdpath
[VBDPATHLEN
] = "/xpvd/xdf@";
903 const char lnamefix
[] = "/dev/dsk/c0d";
910 pnp
= vbdpath
+ strlen(vbdpath
);
911 prop_p
= s
+ strlen(lnamefix
);
912 while ((*prop_p
!= '\0') && (*prop_p
!= 's') && (*prop_p
!= 'p'))
913 addr
= addr
* 10 + *prop_p
++ - '0';
914 (void) snprintf(pnp
, VBDPATHLEN
, "%lx", addr
);
915 pnp
= vbdpath
+ strlen(vbdpath
);
918 else if (*prop_p
== 'p')
921 ASSERT(0); /* shouldn't be here */
923 ASSERT(*prop_p
!= '\0');
924 if (ISDIGIT(*prop_p
)) {
925 minor
= *prop_p
- '0';
927 if (ISDIGIT(*prop_p
)) {
928 minor
= minor
* 10 + *prop_p
- '0';
931 /* malformed root path, use 0 as default */
934 ASSERT(minor
< 16); /* at most 16 partitions */
939 bsetprops("fstype", "ufs");
940 bsetprops("bootpath", vbdpath
);
942 DBG_MSG("VBD bootpath set to ");
948 * parse the xpv-nfsroot property to create properties used by
952 xen_nfsroot_props(char *s
)
955 BP_SERVER_IP
, /* server IP address */
956 BP_SERVER_NAME
, /* server hostname */
957 BP_SERVER_PATH
, /* root path */
959 int n_prop
= sizeof (prop_map
) / sizeof (prop_map
[0]);
961 bsetprop("fstype", 6, "nfs", 4);
963 xen_parse_props(s
, prop_map
, n_prop
);
966 * If a server name wasn't specified, use a default.
968 if (do_bsys_getproplen(NULL
, BP_SERVER_NAME
) == -1)
969 bsetprops(BP_SERVER_NAME
, "unknown");
973 * Extract our IP address, etc. from the "xpv-ip" property.
976 xen_ip_props(char *s
)
979 BP_HOST_IP
, /* IP address */
980 NULL
, /* NFS server IP address (ignored in */
981 /* favour of xpv-nfsroot) */
982 BP_ROUTER_IP
, /* IP gateway */
983 BP_SUBNET_MASK
, /* IP subnet mask */
984 "xpv-hostname", /* hostname (ignored) */
985 BP_NETWORK_INTERFACE
, /* interface name */
986 "xpv-hcp", /* host configuration protocol */
988 int n_prop
= sizeof (prop_map
) / sizeof (prop_map
[0]);
989 char ifname
[IFNAMSIZ
];
991 xen_parse_props(s
, prop_map
, n_prop
);
994 * A Linux dom0 administrator expects all interfaces to be
995 * called "ethX", which is not the case here.
997 * If the interface name specified is "eth0", presume that
998 * this is really intended to be "xnf0" (the first domU ->
999 * dom0 interface for this domain).
1001 if ((do_bsys_getprop(NULL
, BP_NETWORK_INTERFACE
, ifname
) == 0) &&
1002 (strcmp("eth0", ifname
) == 0)) {
1003 bsetprops(BP_NETWORK_INTERFACE
, "xnf0");
1005 "network interface name 'eth0' replaced with 'xnf0'\n");
1012 setup_rarp_props(struct sol_netinfo
*sip
)
1014 char buf
[BUFLEN
]; /* to hold ip/mac addrs */
1017 val
= (uint8_t *)&sip
->sn_ciaddr
;
1018 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1019 val
[0], val
[1], val
[2], val
[3]);
1020 bsetprops(BP_HOST_IP
, buf
);
1022 val
= (uint8_t *)&sip
->sn_siaddr
;
1023 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1024 val
[0], val
[1], val
[2], val
[3]);
1025 bsetprops(BP_SERVER_IP
, buf
);
1027 if (sip
->sn_giaddr
!= 0) {
1028 val
= (uint8_t *)&sip
->sn_giaddr
;
1029 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1030 val
[0], val
[1], val
[2], val
[3]);
1031 bsetprops(BP_ROUTER_IP
, buf
);
1034 if (sip
->sn_netmask
!= 0) {
1035 val
= (uint8_t *)&sip
->sn_netmask
;
1036 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1037 val
[0], val
[1], val
[2], val
[3]);
1038 bsetprops(BP_SUBNET_MASK
, buf
);
1041 if (sip
->sn_mactype
!= 4 || sip
->sn_maclen
!= 6) {
1042 bop_printf(NULL
, "unsupported mac type %d, mac len %d\n",
1043 sip
->sn_mactype
, sip
->sn_maclen
);
1045 val
= sip
->sn_macaddr
;
1046 (void) snprintf(buf
, BUFLEN
, "%x:%x:%x:%x:%x:%x",
1047 val
[0], val
[1], val
[2], val
[3], val
[4], val
[5]);
1048 bsetprops(BP_BOOT_MAC
, buf
);
1055 build_panic_cmdline(const char *cmd
, int cmdlen
)
1060 arglen
= sizeof (fastreboot_onpanic_args
);
1062 * If we allready have fastreboot-onpanic set to zero,
1063 * don't add them again.
1065 if ((proplen
= do_bsys_getproplen(NULL
, FASTREBOOT_ONPANIC
)) > 0 &&
1066 proplen
<= sizeof (fastreboot_onpanic_cmdline
)) {
1067 (void) do_bsys_getprop(NULL
, FASTREBOOT_ONPANIC
,
1068 fastreboot_onpanic_cmdline
);
1069 if (FASTREBOOT_ONPANIC_NOTSET(fastreboot_onpanic_cmdline
))
1074 * construct fastreboot_onpanic_cmdline
1076 if (cmdlen
+ arglen
> sizeof (fastreboot_onpanic_cmdline
)) {
1077 DBG_MSG("Command line too long: clearing "
1078 FASTREBOOT_ONPANIC
"\n");
1079 fastreboot_onpanic
= 0;
1081 bcopy(cmd
, fastreboot_onpanic_cmdline
, cmdlen
);
1083 bcopy(fastreboot_onpanic_args
,
1084 fastreboot_onpanic_cmdline
+ cmdlen
, arglen
);
1086 fastreboot_onpanic_cmdline
[cmdlen
] = 0;
1093 * Construct boot command line for Fast Reboot
1096 build_fastboot_cmdline(void)
1098 saved_cmdline_len
= strlen(xbootp
->bi_cmdline
) + 1;
1099 if (saved_cmdline_len
> FASTBOOT_SAVED_CMDLINE_LEN
) {
1100 DBG(saved_cmdline_len
);
1101 DBG_MSG("Command line too long: clearing fastreboot_capable\n");
1102 fastreboot_capable
= 0;
1104 bcopy((void *)(xbootp
->bi_cmdline
), (void *)saved_cmdline
,
1106 saved_cmdline
[saved_cmdline_len
- 1] = '\0';
1107 build_panic_cmdline(saved_cmdline
, saved_cmdline_len
- 1);
1112 * Save memory layout, disk drive information, unix and boot archive sizes for
1116 save_boot_info(multiboot_info_t
*mbi
, struct xboot_info
*xbi
)
1118 struct boot_modules
*modp
;
1121 bcopy(mbi
, &saved_mbi
, sizeof (multiboot_info_t
));
1122 if (mbi
->mmap_length
> sizeof (saved_mmap
)) {
1123 DBG_MSG("mbi->mmap_length too big: clearing "
1124 "fastreboot_capable\n");
1125 fastreboot_capable
= 0;
1127 bcopy((void *)(uintptr_t)mbi
->mmap_addr
, (void *)saved_mmap
,
1131 if ((mbi
->flags
& MB_INFO_DRIVE_INFO
) != 0) {
1132 if (mbi
->drives_length
> sizeof (saved_drives
)) {
1133 DBG(mbi
->drives_length
);
1134 DBG_MSG("mbi->drives_length too big: clearing "
1135 "fastreboot_capable\n");
1136 fastreboot_capable
= 0;
1138 bcopy((void *)(uintptr_t)mbi
->drives_addr
,
1139 (void *)saved_drives
, mbi
->drives_length
);
1142 saved_mbi
.drives_length
= 0;
1143 saved_mbi
.drives_addr
= NULL
;
1147 * Current file sizes. Used by fastboot.c to figure out how much
1148 * memory to reserve for panic reboot.
1149 * Use the module list from the dboot-constructed xboot_info
1150 * instead of the list referenced by the multiboot structure
1151 * because that structure may not be addressable now.
1153 saved_file_size
[FASTBOOT_NAME_UNIX
] = FOUR_MEG
- PAGESIZE
;
1154 for (i
= 0, modp
= (struct boot_modules
*)(uintptr_t)xbi
->bi_modules
;
1155 i
< xbi
->bi_module_cnt
; i
++, modp
++) {
1156 saved_file_size
[FASTBOOT_NAME_BOOTARCHIVE
] += modp
->bm_size
;
1163 * 1st pass at building the table of boot properties. This includes:
1164 * - values set on the command line: -B a=x,b=y,c=z ....
1165 * - known values we just compute (ie. from xbootp)
1166 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
1168 * the grub command line looked like:
1169 * kernel boot-file [-B prop=value[,prop=value]...] [boot-args]
1171 * whoami is the same as boot-file
1174 build_boot_properties(void)
1180 struct boot_modules
*bm
, *rdbm
;
1187 static int stdout_val
= 0;
1188 uchar_t boot_device
;
1190 multiboot_info_t
*mbi
;
1192 struct sol_netinfo
*sip
;
1196 * These have to be done first, so that kobj_mount_root() works
1198 DBG_MSG("Building boot properties\n");
1199 propbuf
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, 0);
1200 DBG((uintptr_t)propbuf
);
1201 if (xbootp
->bi_module_cnt
> 0) {
1202 bm
= xbootp
->bi_modules
;
1204 for (midx
= i
= 0; i
< xbootp
->bi_module_cnt
; i
++) {
1205 if (bm
[i
].bm_type
== BMT_ROOTFS
) {
1209 if (bm
[i
].bm_type
== BMT_HASH
|| bm
[i
].bm_name
== NULL
)
1212 (void) snprintf(modid
, sizeof (modid
),
1213 "module-name-%u", midx
);
1214 bsetprops(modid
, (char *)bm
[i
].bm_name
);
1215 (void) snprintf(modid
, sizeof (modid
),
1216 "module-addr-%u", midx
);
1217 bsetprop64(modid
, (uint64_t)(uintptr_t)bm
[i
].bm_addr
);
1218 (void) snprintf(modid
, sizeof (modid
),
1219 "module-size-%u", midx
);
1220 bsetprop64(modid
, (uint64_t)bm
[i
].bm_size
);
1224 bsetprop64("ramdisk_start",
1225 (uint64_t)(uintptr_t)rdbm
->bm_addr
);
1226 bsetprop64("ramdisk_end",
1227 (uint64_t)(uintptr_t)rdbm
->bm_addr
+ rdbm
->bm_size
);
1232 * If there are any boot time modules or hashes present, then disable
1235 if (xbootp
->bi_module_cnt
> 1) {
1236 fastreboot_disable(FBNS_BOOTMOD
);
1239 DBG_MSG("Parsing command line for boot properties\n");
1240 value
= xbootp
->bi_cmdline
;
1243 * allocate memory to collect boot_args into
1245 boot_arg_len
= strlen(xbootp
->bi_cmdline
) + 1;
1246 boot_args
= do_bsys_alloc(NULL
, NULL
, boot_arg_len
, MMU_PAGESIZE
);
1252 * Xen puts a lot of device information in front of the kernel name
1253 * let's grab them and make them boot properties. The first
1254 * string w/o an "=" in it will be the boot-file property.
1256 (void) strcpy(namebuf
, "xpv-");
1259 * get to next property
1261 while (ISSPACE(*value
))
1267 while (*value
&& !ISSPACE(*value
) && *value
!= '=') {
1270 if (*value
!= '=') { /* no "=" in the property */
1274 name_len
= value
- name
;
1280 while (value
[value_len
] && !ISSPACE(value
[value_len
])) {
1284 * build property name with "xpv-" prefix
1286 if (name_len
+ 4 > 32) { /* skip if name too long */
1290 bcopy(name
, &namebuf
[4], name_len
);
1292 namebuf
[name_len
] = 0;
1293 bcopy(value
, propbuf
, value_len
);
1294 propbuf
[value_len
] = 0;
1295 bsetprops(namebuf
, propbuf
);
1298 * xpv-root is set to the logical disk name of the xen
1299 * VBD when booting from a disk-based filesystem.
1301 if (strcmp(namebuf
, "xpv-root") == 0)
1302 xen_vbdroot_props(propbuf
);
1304 * While we're here, if we have a "xpv-nfsroot" property
1305 * then we need to set "fstype" to "nfs" so we mount
1306 * our root from the nfs server. Also parse the xpv-nfsroot
1307 * property to create the properties that nfs_mountroot will
1308 * need to find the root and mount it.
1310 if (strcmp(namebuf
, "xpv-nfsroot") == 0)
1311 xen_nfsroot_props(propbuf
);
1313 if (strcmp(namebuf
, "xpv-ip") == 0)
1314 xen_ip_props(propbuf
);
1319 while (ISSPACE(*value
))
1322 * value now points at the boot-file
1325 while (value
[value_len
] && !ISSPACE(value
[value_len
]))
1327 if (value_len
> 0) {
1329 bcopy(value
, whoami
, value_len
);
1330 whoami
[value_len
] = 0;
1331 bsetprops("boot-file", whoami
);
1333 * strip leading path stuff from whoami, so running from
1334 * PXE/miniroot makes sense.
1336 if (strstr(whoami
, "/platform/") != NULL
)
1337 whoami
= strstr(whoami
, "/platform/");
1338 bsetprops("whoami", whoami
);
1342 * Values forcibly set boot properties on the command line via -B.
1343 * Allow use of quotes in values. Other stuff goes on kernel
1346 name
= value
+ value_len
;
1347 while (*name
!= 0) {
1349 * anything not " -B" is copied to the command line
1351 if (!ISSPACE(name
[0]) || name
[1] != '-' || name
[2] != 'B') {
1352 boot_args
[boot_arg_len
++] = *name
;
1353 boot_args
[boot_arg_len
] = 0;
1359 * skip the " -B" and following white space
1362 while (ISSPACE(*name
))
1364 while (*name
&& !ISSPACE(*name
)) {
1365 value
= strstr(name
, "=");
1368 name_len
= value
- name
;
1372 for (; ; ++value_len
) {
1373 if (!value
[value_len
])
1377 * is this value quoted?
1379 if (value_len
== 0 &&
1380 (value
[0] == '\'' || value
[0] == '"')) {
1386 * In the quote accept any character,
1387 * but look for ending quote.
1390 if (value
[value_len
] == quoted
)
1396 * a comma or white space ends the value
1398 if (value
[value_len
] == ',' ||
1399 ISSPACE(value
[value_len
]))
1403 if (value_len
== 0) {
1404 bsetprop(name
, name_len
, "true", 5);
1408 if (v
[0] == v
[l
- 1] &&
1409 (v
[0] == '\'' || v
[0] == '"')) {
1413 bcopy(v
, propbuf
, l
);
1415 bsetprop(name
, name_len
, propbuf
,
1418 name
= value
+ value_len
;
1419 while (*name
== ',')
1425 * set boot-args property
1426 * 1275 name is bootargs, so set
1429 bsetprops("boot-args", boot_args
);
1430 bsetprops("bootargs", boot_args
);
1434 * set the BIOS boot device from GRUB
1437 mbi
= xbootp
->bi_mb_info
;
1440 * Build boot command line for Fast Reboot
1442 build_fastboot_cmdline();
1445 * Save various boot information for Fast Reboot
1447 save_boot_info(mbi
, xbootp
);
1449 if (mbi
!= NULL
&& mbi
->flags
& MB_INFO_BOOTDEV
) {
1450 boot_device
= mbi
->boot_device
>> 24;
1451 if (boot_device
== 0x20)
1453 str
[0] = (boot_device
>> 4) + '0';
1454 str
[1] = (boot_device
& 0xf) + '0';
1456 bsetprops("bios-boot-device", str
);
1462 * In the netboot case, drives_info is overloaded with the dhcp ack.
1463 * This is not multiboot compliant and requires special pxegrub!
1465 if (netboot
&& mbi
->drives_length
!= 0) {
1466 sip
= (struct sol_netinfo
*)(uintptr_t)mbi
->drives_addr
;
1467 if (sip
->sn_infotype
== SN_TYPE_BOOTP
)
1468 bsetprop("bootp-response", sizeof ("bootp-response"),
1469 (void *)(uintptr_t)mbi
->drives_addr
,
1470 mbi
->drives_length
);
1471 else if (sip
->sn_infotype
== SN_TYPE_RARP
)
1472 setup_rarp_props(sip
);
1474 bsetprop("stdout", strlen("stdout"),
1475 &stdout_val
, sizeof (stdout_val
));
1479 * more conjured up values for made up things....
1482 bsetprops("mfg-name", "i86xpv");
1483 bsetprops("impl-arch-name", "i86xpv");
1485 bsetprops("mfg-name", "i86pc");
1486 bsetprops("impl-arch-name", "i86pc");
1490 * Build firmware-provided system properties
1492 build_firmware_properties();
1497 * Find out what these are:
1498 * - cpuid_feature_ecx_include
1499 * - cpuid_feature_ecx_exclude
1500 * - cpuid_feature_edx_include
1501 * - cpuid_feature_edx_exclude
1503 * Find out what these are in multiboot:
1511 * Under the Hypervisor, memory usable for DMA may be scarce. One
1512 * very likely large pool of DMA friendly memory is occupied by
1513 * the boot_archive, as it was loaded by grub into low MFNs.
1515 * Here we free up that memory by copying the boot archive to what are
1516 * likely higher MFN pages and then swapping the mfn/pfn mappings.
1518 #define PFN_2GIG 0x80000
1520 relocate_boot_archive(void)
1522 mfn_t max_mfn
= HYPERVISOR_memory_op(XENMEM_maximum_ram_page
, NULL
);
1523 struct boot_modules
*bm
= xbootp
->bi_modules
;
1534 int mmu_update_return
;
1539 * If all MFN's are below 2Gig, don't bother doing this.
1541 if (max_mfn
< PFN_2GIG
)
1543 if (xbootp
->bi_module_cnt
< 1) {
1544 DBG_MSG("no boot_archive!");
1548 DBG_MSG("moving boot_archive to high MFN memory\n");
1549 va
= (uintptr_t)bm
->bm_addr
;
1551 slop
= va
& MMU_PAGEOFFSET
;
1553 va
+= MMU_PAGESIZE
- slop
;
1554 len
-= MMU_PAGESIZE
- slop
;
1556 len
= P2ALIGN(len
, MMU_PAGESIZE
);
1559 * Go through all boot_archive pages, swapping any low MFN pages
1560 * with memory at next_phys.
1564 va_pfn
= mmu_btop(va
- ONE_GIG
);
1565 va_mfn
= mfn_list
[va_pfn
];
1566 if (mfn_list
[va_pfn
] < PFN_2GIG
) {
1567 copy
= kbm_remap_window(next_phys
, 1);
1568 bcopy((void *)va
, copy
, MMU_PAGESIZE
);
1569 copy_pfn
= mmu_btop(next_phys
);
1570 copy_mfn
= mfn_list
[copy_pfn
];
1572 pte
= mfn_to_ma(copy_mfn
) | PT_NOCONSIST
| PT_VALID
;
1573 if (HYPERVISOR_update_va_mapping(va
, pte
,
1574 UVMF_INVLPG
| UVMF_LOCAL
))
1575 bop_panic("relocate_boot_archive(): "
1576 "HYPERVISOR_update_va_mapping() failed");
1578 mfn_list
[va_pfn
] = copy_mfn
;
1579 mfn_list
[copy_pfn
] = va_mfn
;
1581 t
[0].ptr
= mfn_to_ma(copy_mfn
) | MMU_MACHPHYS_UPDATE
;
1583 t
[1].ptr
= mfn_to_ma(va_mfn
) | MMU_MACHPHYS_UPDATE
;
1584 t
[1].val
= copy_pfn
;
1585 if (HYPERVISOR_mmu_update(t
, 2, &mmu_update_return
,
1586 DOMID_SELF
) != 0 || mmu_update_return
!= 2)
1587 bop_panic("relocate_boot_archive(): "
1588 "HYPERVISOR_mmu_update() failed");
1590 next_phys
+= MMU_PAGESIZE
;
1593 len
-= MMU_PAGESIZE
;
1596 DBG_MSG("Relocated pages:\n");
1598 DBG_MSG("Out of total pages:\n");
1605 * Install a temporary IDT that lets us catch errors in the boot time code.
1606 * We shouldn't get any faults at all while this is installed, so we'll
1607 * just generate a traceback and exit.
1610 static const int bcode_sel
= B64CODE_SEL
;
1612 static const int bcode_sel
= B32CODE_SEL
;
1616 * simple description of a stack frame (args are 32 bit only currently)
1618 typedef struct bop_frame
{
1619 struct bop_frame
*old_frame
;
1625 bop_traceback(bop_frame_t
*frame
)
1635 bop_printf(NULL
, "Stack traceback:\n");
1636 for (cnt
= 0; cnt
< 30; ++cnt
) { /* up to 30 frames */
1637 pc
= frame
->retaddr
;
1640 ksym
= kobj_getsymname(pc
, &off
);
1642 bop_printf(NULL
, " %s+%lx", ksym
, off
);
1644 bop_printf(NULL
, " 0x%lx", pc
);
1646 frame
= frame
->old_frame
;
1648 bop_printf(NULL
, "\n");
1652 for (a
= 0; a
< 6; ++a
) { /* try for 6 args */
1653 if ((void *)&frame
->arg
[a
] == (void *)frame
->old_frame
)
1656 bop_printf(NULL
, "(");
1658 bop_printf(NULL
, ",");
1659 bop_printf(NULL
, "0x%lx", frame
->arg
[a
]);
1661 bop_printf(NULL
, ")");
1663 bop_printf(NULL
, "\n");
1668 ulong_t error_code
; /* optional */
1679 bop_trap(ulong_t
*tfp
)
1681 struct trapframe
*tf
= (struct trapframe
*)tfp
;
1682 bop_frame_t fakeframe
;
1683 static int depth
= 0;
1686 * Check for an infinite loop of traps.
1689 bop_panic("Nested trap");
1691 bop_printf(NULL
, "Unexpected trap\n");
1694 * adjust the tf for optional error_code by detecting the code selector
1696 if (tf
->code_seg
!= bcode_sel
)
1697 tf
= (struct trapframe
*)(tfp
- 1);
1699 bop_printf(NULL
, "error code 0x%lx\n",
1700 tf
->error_code
& 0xffffffff);
1702 bop_printf(NULL
, "instruction pointer 0x%lx\n", tf
->inst_ptr
);
1703 bop_printf(NULL
, "code segment 0x%lx\n", tf
->code_seg
& 0xffff);
1704 bop_printf(NULL
, "flags register 0x%lx\n", tf
->flags_reg
);
1706 bop_printf(NULL
, "return %%rsp 0x%lx\n", tf
->stk_ptr
);
1707 bop_printf(NULL
, "return %%ss 0x%lx\n", tf
->stk_seg
& 0xffff);
1710 /* grab %[er]bp pushed by our code from the stack */
1711 fakeframe
.old_frame
= (bop_frame_t
*)*(tfp
- 3);
1712 fakeframe
.retaddr
= (pc_t
)tf
->inst_ptr
;
1713 bop_printf(NULL
, "Attempting stack backtrace:\n");
1714 bop_traceback(&fakeframe
);
1715 bop_panic("unexpected trap in early boot");
1718 extern void bop_trap_handler(void);
1720 static gate_desc_t
*bop_idt
;
1722 static desctbr_t bop_idt_info
;
1729 bop_idt
= (gate_desc_t
*)
1730 do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
1731 bzero(bop_idt
, MMU_PAGESIZE
);
1732 for (t
= 0; t
< NIDT
; ++t
) {
1734 * Note that since boot runs without a TSS, the
1735 * double fault handler cannot use an alternate stack
1736 * (64-bit) or a task gate (32-bit).
1738 set_gatesegd(&bop_idt
[t
], &bop_trap_handler
, bcode_sel
,
1739 SDT_SYSIGT
, TRP_KPL
, 0);
1741 bop_idt_info
.dtr_limit
= (NIDT
* sizeof (gate_desc_t
)) - 1;
1742 bop_idt_info
.dtr_base
= (uintptr_t)bop_idt
;
1743 wr_idtr(&bop_idt_info
);
1745 #endif /* !defined(__xpv) */
1748 * This is where we enter the kernel. It dummies up the boot_ops and
1749 * boot_syscalls vectors and jumps off to _kobj_boot()
1752 _start(struct xboot_info
*xbp
)
1754 bootops_t
*bops
= &bootop
;
1755 extern void _kobj_boot();
1758 * 1st off - initialize the console for any error messages
1762 HYPERVISOR_shared_info
= (void *)xbootp
->bi_shared_info
;
1763 xen_info
= xbootp
->bi_xen_start_info
;
1767 if (*((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) ==
1769 post_fastreboot
= 1;
1770 *((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) = 0;
1774 bcons_init((void *)xbootp
->bi_cmdline
);
1780 if (strstr((char *)xbootp
->bi_cmdline
, "kbm_debug"))
1783 DBG_MSG("\n\n*** Entered Solaris in _start() cmdline is: ");
1784 DBG_MSG((char *)xbootp
->bi_cmdline
);
1788 * physavail is no longer used by startup
1790 bm
.physinstalled
= xbp
->bi_phys_install
;
1791 bm
.pcimem
= xbp
->bi_pcimem
;
1792 bm
.rsvdmem
= xbp
->bi_rsvdmem
;
1793 bm
.physavail
= NULL
;
1796 * initialize the boot time allocator
1798 next_phys
= xbootp
->bi_next_paddr
;
1800 next_virt
= (uintptr_t)xbootp
->bi_next_vaddr
;
1802 DBG_MSG("Initializing boot time memory management...");
1805 xen_platform_parameters_t p
;
1807 /* This call shouldn't fail, dboot already did it once. */
1808 (void) HYPERVISOR_xen_version(XENVER_platform_parameters
, &p
);
1809 mfn_to_pfn_mapping
= (pfn_t
*)(xen_virt_start
= p
.virt_start
);
1810 DBG(xen_virt_start
);
1817 * Fill in the bootops vector
1819 bops
->bsys_version
= BO_VERSION
;
1820 bops
->boot_mem
= &bm
;
1821 bops
->bsys_alloc
= do_bsys_alloc
;
1822 bops
->bsys_free
= do_bsys_free
;
1823 bops
->bsys_getproplen
= do_bsys_getproplen
;
1824 bops
->bsys_getprop
= do_bsys_getprop
;
1825 bops
->bsys_nextprop
= do_bsys_nextprop
;
1826 bops
->bsys_printf
= bop_printf
;
1827 bops
->bsys_doint
= do_bsys_doint
;
1830 * BOP_EALLOC() is no longer needed
1832 bops
->bsys_ealloc
= do_bsys_ealloc
;
1836 * On domain 0 we need to free up some physical memory that is
1837 * usable for DMA. Since GRUB loaded the boot_archive, it is
1838 * sitting in low MFN memory. We'll relocated the boot archive
1839 * pages to high PFN memory.
1841 if (DOMAIN_IS_INITDOMAIN(xen_info
))
1842 relocate_boot_archive();
1847 * Install an IDT to catch early pagefaults (shouldn't have any).
1848 * Also needed for kmdb.
1854 * Start building the boot properties from the command line
1856 DBG_MSG("Initializing boot properties:\n");
1857 build_boot_properties();
1859 if (strstr((char *)xbootp
->bi_cmdline
, "prom_debug") || kbm_debug
) {
1865 value
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
1866 bop_printf(NULL
, "\nBoot properties:\n");
1868 while ((name
= do_bsys_nextprop(NULL
, name
)) != NULL
) {
1869 bop_printf(NULL
, "\t0x%p %s = ", (void *)name
, name
);
1870 (void) do_bsys_getprop(NULL
, name
, value
);
1871 len
= do_bsys_getproplen(NULL
, name
);
1872 bop_printf(NULL
, "len=%d ", len
);
1874 for (cp
= value
; *cp
; ++cp
) {
1875 if (' ' <= *cp
&& *cp
<= '~')
1876 bop_printf(NULL
, "%c", *cp
);
1878 bop_printf(NULL
, "-0x%x-", *cp
);
1880 bop_printf(NULL
, "\n");
1885 * jump into krtld...
1887 _kobj_boot(&bop_sysp
, NULL
, bops
, NULL
);
1893 no_more_alloc(bootops_t
*bop
, caddr_t virthint
, size_t size
, int align
)
1895 panic("Attempt to bsys_alloc() too late\n");
1901 no_more_free(bootops_t
*bop
, caddr_t virt
, size_t size
)
1903 panic("Attempt to bsys_free() too late\n");
1907 bop_no_more_mem(void)
1909 DBG(total_bop_alloc_scratch
);
1910 DBG(total_bop_alloc_kernel
);
1911 bootops
->bsys_alloc
= no_more_alloc
;
1912 bootops
->bsys_free
= no_more_free
;
1917 * Set ACPI firmware properties
1921 vmap_phys(size_t length
, paddr_t pa
)
1928 pa
= pfn_to_pa(xen_assign_pfn(mmu_btop(pa
))) | (pa
& MMU_PAGEOFFSET
);
1930 start
= P2ALIGN(pa
, MMU_PAGESIZE
);
1931 end
= P2ROUNDUP(pa
+ length
, MMU_PAGESIZE
);
1933 va
= (caddr_t
)alloc_vaddr(len
, MMU_PAGESIZE
);
1934 for (page
= 0; page
< len
; page
+= MMU_PAGESIZE
)
1935 kbm_map((uintptr_t)va
+ page
, start
+ page
, 0, 0);
1936 return (va
+ (pa
& MMU_PAGEOFFSET
));
1940 checksum_table(uint8_t *tp
, size_t len
)
1951 valid_rsdp(ACPI_TABLE_RSDP
*rp
)
1954 /* validate the V1.x checksum */
1955 if (checksum_table((uint8_t *)rp
, ACPI_RSDP_CHECKSUM_LENGTH
) != 0)
1958 /* If pre-ACPI 2.0, this is a valid RSDP */
1959 if (rp
->Revision
< 2)
1962 /* validate the V2.x checksum */
1963 if (checksum_table((uint8_t *)rp
, ACPI_RSDP_XCHECKSUM_LENGTH
) != 0)
1970 * Scan memory range for an RSDP;
1971 * see ACPI 3.0 Spec, 5.2.5.1
1973 static ACPI_TABLE_RSDP
*
1974 scan_rsdp(paddr_t start
, paddr_t end
)
1976 ssize_t len
= end
- start
;
1979 ptr
= vmap_phys(len
, start
);
1981 if (strncmp(ptr
, ACPI_SIG_RSDP
, strlen(ACPI_SIG_RSDP
)) == 0 &&
1982 valid_rsdp((ACPI_TABLE_RSDP
*)ptr
))
1983 return ((ACPI_TABLE_RSDP
*)ptr
);
1985 ptr
+= ACPI_RSDP_SCAN_STEP
;
1986 len
-= ACPI_RSDP_SCAN_STEP
;
1993 * Refer to ACPI 3.0 Spec, section 5.2.5.1 to understand this function
1995 static ACPI_TABLE_RSDP
*
1998 ACPI_TABLE_RSDP
*rsdp
;
2003 * Get the EBDA segment and scan the first 1K
2005 ebda_seg
= (uint16_t *)vmap_phys(sizeof (uint16_t),
2006 ACPI_EBDA_PTR_LOCATION
);
2007 ebda_addr
= *ebda_seg
<< 4;
2008 rsdp
= scan_rsdp(ebda_addr
, ebda_addr
+ ACPI_EBDA_WINDOW_SIZE
);
2010 /* if EBDA doesn't contain RSDP, look in BIOS memory */
2011 rsdp
= scan_rsdp(ACPI_HI_RSDP_WINDOW_BASE
,
2012 ACPI_HI_RSDP_WINDOW_BASE
+ ACPI_HI_RSDP_WINDOW_SIZE
);
2016 static ACPI_TABLE_HEADER
*
2017 map_fw_table(paddr_t table_addr
)
2019 ACPI_TABLE_HEADER
*tp
;
2020 size_t len
= MAX(sizeof (*tp
), MMU_PAGESIZE
);
2023 * Map at least a page; if the table is larger than this, remap it
2025 tp
= (ACPI_TABLE_HEADER
*)vmap_phys(len
, table_addr
);
2026 if (tp
->Length
> len
)
2027 tp
= (ACPI_TABLE_HEADER
*)vmap_phys(tp
->Length
, table_addr
);
2031 static ACPI_TABLE_HEADER
*
2032 find_fw_table(char *signature
)
2034 static int revision
= 0;
2035 static ACPI_TABLE_XSDT
*xsdt
;
2038 ACPI_TABLE_RSDP
*rsdp
;
2039 ACPI_TABLE_HEADER
*tp
;
2043 if (strlen(signature
) != ACPI_NAME_SIZE
)
2047 * Reading the ACPI 3.0 Spec, section 5.2.5.3 will help
2048 * understand this code. If we haven't already found the RSDT/XSDT,
2049 * revision will be 0. Find the RSDP and check the revision
2050 * to find out whether to use the RSDT or XSDT. If revision is
2051 * 0 or 1, use the RSDT and set internal revision to 1; if it is 2,
2052 * use the XSDT. If the XSDT address is 0, though, fall back to
2053 * revision 1 and use the RSDT.
2055 if (revision
== 0) {
2056 if ((rsdp
= find_rsdp()) != NULL
) {
2057 revision
= rsdp
->Revision
;
2059 * ACPI 6.0 states that current revision is 2
2060 * from acpi_table_rsdp definition:
2061 * Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+
2068 * Use the XSDT unless BIOS is buggy and
2069 * claims to be rev 2 but has a null XSDT
2072 xsdt_addr
= rsdp
->XsdtPhysicalAddress
;
2077 /* treat RSDP rev 0 as revision 1 internally */
2081 /* use the RSDT for rev 0/1 */
2082 xsdt_addr
= rsdp
->RsdtPhysicalAddress
;
2085 /* unknown revision */
2093 /* cache the XSDT info */
2094 xsdt
= (ACPI_TABLE_XSDT
*)map_fw_table(xsdt_addr
);
2095 len
= (xsdt
->Header
.Length
- sizeof (xsdt
->Header
)) /
2096 ((revision
== 1) ? sizeof (uint32_t) : sizeof (uint64_t));
2100 * Scan the table headers looking for a signature match
2102 for (n
= 0; n
< len
; n
++) {
2103 ACPI_TABLE_RSDT
*rsdt
= (ACPI_TABLE_RSDT
*)xsdt
;
2104 table_addr
= (revision
== 1) ? rsdt
->TableOffsetEntry
[n
] :
2105 xsdt
->TableOffsetEntry
[n
];
2107 if (table_addr
== 0)
2109 tp
= map_fw_table(table_addr
);
2110 if (strncmp(tp
->Signature
, signature
, ACPI_NAME_SIZE
) == 0) {
2118 process_mcfg(ACPI_TABLE_MCFG
*tp
)
2120 ACPI_MCFG_ALLOCATION
*cfg_baap
;
2122 int64_t ecfginfo
[4];
2124 cfg_baap
= (ACPI_MCFG_ALLOCATION
*)((uintptr_t)tp
+ sizeof (*tp
));
2125 cfg_baa_endp
= ((char *)tp
) + tp
->Header
.Length
;
2126 while ((char *)cfg_baap
< cfg_baa_endp
) {
2127 if (cfg_baap
->Address
!= 0 && cfg_baap
->PciSegment
== 0) {
2128 ecfginfo
[0] = cfg_baap
->Address
;
2129 ecfginfo
[1] = cfg_baap
->PciSegment
;
2130 ecfginfo
[2] = cfg_baap
->StartBusNumber
;
2131 ecfginfo
[3] = cfg_baap
->EndBusNumber
;
2132 bsetprop(MCFG_PROPNAME
, strlen(MCFG_PROPNAME
),
2133 ecfginfo
, sizeof (ecfginfo
));
2142 process_madt_entries(ACPI_TABLE_MADT
*tp
, uint32_t *cpu_countp
,
2143 uint32_t *cpu_possible_countp
, uint32_t *cpu_apicid_array
)
2145 ACPI_SUBTABLE_HEADER
*item
, *end
;
2146 uint32_t cpu_count
= 0;
2147 uint32_t cpu_possible_count
= 0;
2150 * Determine number of CPUs and keep track of "final" APIC ID
2151 * for each CPU by walking through ACPI MADT processor list
2153 end
= (ACPI_SUBTABLE_HEADER
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2154 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)tp
+ sizeof (*tp
));
2156 while (item
< end
) {
2157 switch (item
->Type
) {
2158 case ACPI_MADT_TYPE_LOCAL_APIC
: {
2159 ACPI_MADT_LOCAL_APIC
*cpu
=
2160 (ACPI_MADT_LOCAL_APIC
*) item
;
2162 if (cpu
->LapicFlags
& ACPI_MADT_ENABLED
) {
2163 if (cpu_apicid_array
!= NULL
)
2164 cpu_apicid_array
[cpu_count
] = cpu
->Id
;
2167 cpu_possible_count
++;
2170 case ACPI_MADT_TYPE_LOCAL_X2APIC
: {
2171 ACPI_MADT_LOCAL_X2APIC
*cpu
=
2172 (ACPI_MADT_LOCAL_X2APIC
*) item
;
2174 if (cpu
->LapicFlags
& ACPI_MADT_ENABLED
) {
2175 if (cpu_apicid_array
!= NULL
)
2176 cpu_apicid_array
[cpu_count
] =
2180 cpu_possible_count
++;
2185 bop_printf(NULL
, "MADT type %d\n", item
->Type
);
2189 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)item
+ item
->Length
);
2192 *cpu_countp
= cpu_count
;
2193 if (cpu_possible_countp
)
2194 *cpu_possible_countp
= cpu_possible_count
;
2198 process_madt(ACPI_TABLE_MADT
*tp
)
2200 uint32_t cpu_count
= 0;
2201 uint32_t cpu_possible_count
= 0;
2202 uint32_t *cpu_apicid_array
; /* x2APIC ID is 32bit! */
2206 process_madt_entries(tp
, &cpu_count
, &cpu_possible_count
, NULL
);
2208 cpu_apicid_array
= (uint32_t *)do_bsys_alloc(NULL
, NULL
,
2209 cpu_count
* sizeof (*cpu_apicid_array
), MMU_PAGESIZE
);
2210 if (cpu_apicid_array
== NULL
)
2211 bop_panic("Not enough memory for APIC ID array");
2214 process_madt_entries(tp
, NULL
, NULL
, cpu_apicid_array
);
2217 * Make boot property for array of "final" APIC IDs for each
2220 bsetprop(BP_CPU_APICID_ARRAY
, strlen(BP_CPU_APICID_ARRAY
),
2221 cpu_apicid_array
, cpu_count
* sizeof (*cpu_apicid_array
));
2225 * Check whether property plat-max-ncpus is already set.
2227 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2229 * Set plat-max-ncpus to number of maximum possible CPUs given
2230 * in MADT if it hasn't been set.
2231 * There's no formal way to detect max possible CPUs supported
2232 * by platform according to ACPI spec3.0b. So current CPU
2233 * hotplug implementation expects that all possible CPUs will
2234 * have an entry in MADT table and set plat-max-ncpus to number
2235 * of entries in MADT.
2236 * With introducing of ACPI4.0, Maximum System Capability Table
2237 * (MSCT) provides maximum number of CPUs supported by platform.
2238 * If MSCT is unavailable, fall back to old way.
2241 bsetpropsi(PLAT_MAX_NCPUS_NAME
, cpu_possible_count
);
2245 * Set boot property boot-max-ncpus to number of CPUs existing at
2246 * boot time. boot-max-ncpus is mainly used for optimization.
2249 bsetpropsi(BOOT_MAX_NCPUS_NAME
, cpu_count
);
2252 * User-set boot-ncpus overrides firmware count
2254 if (do_bsys_getproplen(NULL
, BOOT_NCPUS_NAME
) >= 0)
2258 * Set boot property boot-ncpus to number of active CPUs given in MADT
2259 * if it hasn't been set yet.
2262 bsetpropsi(BOOT_NCPUS_NAME
, cpu_count
);
2266 process_srat(ACPI_TABLE_SRAT
*tp
)
2268 ACPI_SUBTABLE_HEADER
*item
, *end
;
2270 int proc_num
, mem_num
;
2289 uint64_t maxmem
= 0;
2294 proc_num
= mem_num
= 0;
2295 end
= (ACPI_SUBTABLE_HEADER
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2296 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)tp
+ sizeof (*tp
));
2297 while (item
< end
) {
2298 switch (item
->Type
) {
2299 case ACPI_SRAT_TYPE_CPU_AFFINITY
: {
2300 ACPI_SRAT_CPU_AFFINITY
*cpu
=
2301 (ACPI_SRAT_CPU_AFFINITY
*) item
;
2303 if (!(cpu
->Flags
& ACPI_SRAT_CPU_ENABLED
))
2305 processor
.domain
= cpu
->ProximityDomainLo
;
2306 for (i
= 0; i
< 3; i
++)
2308 cpu
->ProximityDomainHi
[i
] << ((i
+ 1) * 8);
2309 processor
.apic_id
= cpu
->ApicId
;
2310 processor
.sapic_id
= cpu
->LocalSapicEid
;
2311 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2313 bsetprop(prop_name
, strlen(prop_name
), &processor
,
2314 sizeof (processor
));
2318 case ACPI_SRAT_TYPE_MEMORY_AFFINITY
: {
2319 ACPI_SRAT_MEM_AFFINITY
*mem
=
2320 (ACPI_SRAT_MEM_AFFINITY
*)item
;
2322 if (!(mem
->Flags
& ACPI_SRAT_MEM_ENABLED
))
2324 memory
.domain
= mem
->ProximityDomain
;
2325 memory
.addr
= mem
->BaseAddress
;
2326 memory
.length
= mem
->Length
;
2327 memory
.flags
= mem
->Flags
;
2328 (void) snprintf(prop_name
, 30, "acpi-srat-memory-%d",
2330 bsetprop(prop_name
, strlen(prop_name
), &memory
,
2332 if ((mem
->Flags
& ACPI_SRAT_MEM_HOT_PLUGGABLE
) &&
2333 (memory
.addr
+ memory
.length
> maxmem
)) {
2334 maxmem
= memory
.addr
+ memory
.length
;
2339 case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY
: {
2340 ACPI_SRAT_X2APIC_CPU_AFFINITY
*x2cpu
=
2341 (ACPI_SRAT_X2APIC_CPU_AFFINITY
*) item
;
2343 if (!(x2cpu
->Flags
& ACPI_SRAT_CPU_ENABLED
))
2345 x2apic
.domain
= x2cpu
->ProximityDomain
;
2346 x2apic
.x2apic_id
= x2cpu
->ApicId
;
2347 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2349 bsetprop(prop_name
, strlen(prop_name
), &x2apic
,
2356 bop_printf(NULL
, "SRAT type %d\n", item
->Type
);
2360 item
= (ACPI_SUBTABLE_HEADER
*)
2361 (item
->Length
+ (uintptr_t)item
);
2365 * The maximum physical address calculated from the SRAT table is more
2366 * accurate than that calculated from the MSCT table.
2369 plat_dr_physmax
= btop(maxmem
);
2374 process_slit(ACPI_TABLE_SLIT
*tp
)
2378 * Check the number of localities; if it's too huge, we just
2379 * return and locality enumeration code will handle this later,
2382 * Note that the size of the table is the square of the
2383 * number of localities; if the number of localities exceeds
2384 * UINT16_MAX, the table size may overflow an int when being
2385 * passed to bsetprop() below.
2387 if (tp
->LocalityCount
>= SLIT_LOCALITIES_MAX
)
2390 bsetprop(SLIT_NUM_PROPNAME
, strlen(SLIT_NUM_PROPNAME
),
2391 &tp
->LocalityCount
, sizeof (tp
->LocalityCount
));
2392 bsetprop(SLIT_PROPNAME
, strlen(SLIT_PROPNAME
), &tp
->Entry
,
2393 tp
->LocalityCount
* tp
->LocalityCount
);
2396 static ACPI_TABLE_MSCT
*
2397 process_msct(ACPI_TABLE_MSCT
*tp
)
2401 ACPI_MSCT_PROXIMITY
*item
, *end
;
2402 extern uint64_t plat_dr_options
;
2406 end
= (ACPI_MSCT_PROXIMITY
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2407 for (item
= (void *)((uintptr_t)tp
+ tp
->ProximityOffset
);
2409 item
= (void *)(item
->Length
+ (uintptr_t)item
)) {
2411 * Sanity check according to section 5.2.19.1 of ACPI 4.0.
2415 if (item
->Revision
!= 1 || item
->Length
!= 22) {
2417 "?boot: unknown proximity domain structure in MSCT "
2418 "with Revision(%d), Length(%d).\n",
2419 (int)item
->Revision
, (int)item
->Length
);
2421 } else if (item
->RangeStart
> item
->RangeEnd
) {
2423 "?boot: invalid proximity domain structure in MSCT "
2424 "with RangeStart(%u), RangeEnd(%u).\n",
2425 item
->RangeStart
, item
->RangeEnd
);
2427 } else if (item
->RangeStart
!= last_seen
) {
2429 * Items must be organized in ascending order of the
2430 * proximity domain enumerations.
2433 "?boot: invalid proximity domain structure in MSCT,"
2434 " items are not orginized in ascending order.\n");
2439 * If ProcessorCapacity is 0 then there would be no CPUs in this
2442 if (item
->ProcessorCapacity
!= 0) {
2443 proc_num
+= (item
->RangeEnd
- item
->RangeStart
+ 1) *
2444 item
->ProcessorCapacity
;
2447 last_seen
= item
->RangeEnd
- item
->RangeStart
+ 1;
2449 * Break out if all proximity domains have been processed.
2450 * Some BIOSes may have unused items at the end of MSCT table.
2452 if (last_seen
> tp
->MaxProximityDomains
) {
2456 if (last_seen
!= tp
->MaxProximityDomains
+ 1) {
2458 "?boot: invalid proximity domain structure in MSCT, "
2459 "proximity domain count doesn't match.\n");
2464 * Set plat-max-ncpus property if it hasn't been set yet.
2466 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2467 if (proc_num
!= 0) {
2468 bsetpropsi(PLAT_MAX_NCPUS_NAME
, proc_num
);
2473 * Use Maximum Physical Address from the MSCT table as upper limit for
2474 * memory hot-adding by default. It may be overridden by value from
2475 * the SRAT table or the "plat-dr-physmax" boot option.
2477 plat_dr_physmax
= btop(tp
->MaxAddress
+ 1);
2480 * Existence of MSCT implies CPU/memory hotplug-capability for the
2483 plat_dr_options
|= PLAT_DR_FEATURE_CPU
;
2484 plat_dr_options
|= PLAT_DR_FEATURE_MEMORY
;
2491 enumerate_xen_cpus()
2493 processorid_t id
, max_id
;
2496 * User-set boot-ncpus overrides enumeration
2498 if (do_bsys_getproplen(NULL
, BOOT_NCPUS_NAME
) >= 0)
2502 * Probe every possible virtual CPU id and remember the
2503 * highest id present; the count of CPUs is one greater
2504 * than this. This tacitly assumes at least cpu 0 is present.
2507 for (id
= 0; id
< MAX_VIRT_CPUS
; id
++)
2508 if (HYPERVISOR_vcpu_op(VCPUOP_is_up
, id
, NULL
) == 0)
2511 bsetpropsi(BOOT_NCPUS_NAME
, max_id
+1);
2517 build_firmware_properties(void)
2519 ACPI_TABLE_HEADER
*tp
= NULL
;
2522 if ((tp
= find_fw_table(ACPI_SIG_MSCT
)) != NULL
)
2523 msct_ptr
= process_msct((ACPI_TABLE_MSCT
*)tp
);
2527 if ((tp
= find_fw_table(ACPI_SIG_MADT
)) != NULL
)
2528 process_madt((ACPI_TABLE_MADT
*)tp
);
2530 if ((srat_ptr
= (ACPI_TABLE_SRAT
*)
2531 find_fw_table(ACPI_SIG_SRAT
)) != NULL
)
2532 process_srat(srat_ptr
);
2534 if (slit_ptr
= (ACPI_TABLE_SLIT
*)find_fw_table(ACPI_SIG_SLIT
))
2535 process_slit(slit_ptr
);
2537 tp
= find_fw_table(ACPI_SIG_MCFG
);
2539 enumerate_xen_cpus();
2540 if (DOMAIN_IS_INITDOMAIN(xen_info
))
2541 tp
= find_fw_table(ACPI_SIG_MCFG
);
2544 process_mcfg((ACPI_TABLE_MCFG
*)tp
);
2548 * fake up a boot property for deferred early console output
2549 * this is used by both graphical boot and the (developer only)
2550 * USB serial console
2553 defcons_init(size_t size
)
2555 static char *p
= NULL
;
2557 p
= do_bsys_alloc(NULL
, NULL
, size
, MMU_PAGESIZE
);
2559 bsetprop("deferred-console-buf", strlen("deferred-console-buf") + 1,
2566 boot_compinfo(int fd
, struct compinfo
*cbp
)
2569 cbp
->blksize
= MAXBSIZE
;
2573 #define BP_MAX_STRLEN 32
2576 * Get value for given boot property
2579 bootprop_getval(const char *prop_name
, u_longlong_t
*prop_value
)
2582 char str
[BP_MAX_STRLEN
];
2585 boot_prop_len
= BOP_GETPROPLEN(bootops
, prop_name
);
2586 if (boot_prop_len
< 0 || boot_prop_len
> sizeof (str
) ||
2587 BOP_GETPROP(bootops
, prop_name
, str
) < 0 ||
2588 kobj_getvalue(str
, &value
) == -1)
2592 *prop_value
= value
;