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.
27 * Copyright (c) 2010, Intel Corporation.
28 * All rights reserved.
32 * This file contains the functionality that mimics the boot operations
33 * on SPARC systems or the old boot.bin/multiboot programs on x86 systems.
34 * The x86 kernel now does everything on its own.
37 #include <sys/types.h>
38 #include <sys/bootconf.h>
39 #include <sys/bootsvcs.h>
40 #include <sys/bootinfo.h>
41 #include <sys/multiboot.h>
42 #include <sys/bootvfs.h>
43 #include <sys/bootprops.h>
44 #include <sys/varargs.h>
45 #include <sys/param.h>
46 #include <sys/machparam.h>
47 #include <sys/machsystm.h>
48 #include <sys/archsystm.h>
49 #include <sys/boot_console.h>
50 #include <sys/cmn_err.h>
51 #include <sys/systm.h>
52 #include <sys/promif.h>
53 #include <sys/archsystm.h>
54 #include <sys/x86_archext.h>
56 #include <sys/privregs.h>
57 #include <sys/sysmacros.h>
58 #include <sys/ctype.h>
59 #include <sys/fastboot.h>
61 #include <sys/hypervisor.h>
64 #include <vm/kboot_mmu.h>
65 #include <vm/hat_pte.h>
67 #include <sys/kobj_lex.h>
68 #include <sys/pci_cfgspace_impl.h>
71 static int have_console
= 0; /* set once primitive console is initialized */
72 static char *boot_args
= "";
77 static uint_t kbm_debug
= 0;
78 #define DBG_MSG(s) { if (kbm_debug) bop_printf(NULL, "%s", s); }
79 #define DBG(x) { if (kbm_debug) \
80 bop_printf(NULL, "%s is %" PRIx64 "\n", #x, (uint64_t)(x)); \
83 #define PUT_STRING(s) { \
85 for (cp = (s); *cp; ++cp) \
89 struct xboot_info
*xbootp
; /* boot info from "glue" code in low memory */
90 bootops_t bootop
; /* simple bootops we'll pass on to kernel */
93 static uintptr_t next_virt
; /* next available virtual address */
94 static paddr_t next_phys
; /* next available physical address from dboot */
95 static paddr_t high_phys
= -(paddr_t
)1; /* last used physical address */
98 * buffer for vsnprintf for console I/O
100 #define BUFFERSIZE 256
101 static char buffer
[BUFFERSIZE
];
103 * stuff to store/report/manipulate boot property settings.
105 typedef struct bootprop
{
106 struct bootprop
*bp_next
;
112 static bootprop_t
*bprops
= NULL
;
113 static char *curr_page
= NULL
; /* ptr to avail bprop memory */
114 static int curr_space
= 0; /* amount of memory at curr_page */
117 start_info_t
*xen_info
;
118 shared_info_t
*HYPERVISOR_shared_info
;
122 * some allocator statistics
124 static ulong_t total_bop_alloc_scratch
= 0;
125 static ulong_t total_bop_alloc_kernel
= 0;
127 static void build_firmware_properties(void);
129 static int early_allocation
= 1;
131 int force_fastreboot
= 0;
132 volatile int fastreboot_onpanic
= 0;
133 int post_fastreboot
= 0;
135 volatile int fastreboot_capable
= 0;
137 volatile int fastreboot_capable
= 1;
141 * Information saved from current boot for fast reboot.
142 * If the information size exceeds what we have allocated, fast reboot
143 * will not be supported.
145 multiboot_info_t saved_mbi
;
146 mb_memory_map_t saved_mmap
[FASTBOOT_SAVED_MMAP_COUNT
];
147 uint8_t saved_drives
[FASTBOOT_SAVED_DRIVES_SIZE
];
148 char saved_cmdline
[FASTBOOT_SAVED_CMDLINE_LEN
];
149 int saved_cmdline_len
= 0;
150 size_t saved_file_size
[FASTBOOT_MAX_FILES_MAP
];
153 * Turn off fastreboot_onpanic to avoid panic loop.
155 char fastreboot_onpanic_cmdline
[FASTBOOT_SAVED_CMDLINE_LEN
];
156 static const char fastreboot_onpanic_args
[] = " -B fastreboot_onpanic=0";
159 * Pointers to where System Resource Affinity Table (SRAT), System Locality
160 * Information Table (SLIT) and Maximum System Capability Table (MSCT)
161 * are mapped into virtual memory
163 struct srat
*srat_ptr
= NULL
;
164 struct slit
*slit_ptr
= NULL
;
165 struct msct
*msct_ptr
= NULL
;
168 * Allocate aligned physical memory at boot time. This allocator allocates
169 * from the highest possible addresses. This avoids exhausting memory that
170 * would be useful for DMA buffers.
173 do_bop_phys_alloc(uint64_t size
, uint64_t align
)
178 struct memlist
*ml
= (struct memlist
*)xbootp
->bi_phys_install
;
181 * Be careful if high memory usage is limited in startup.c
182 * Since there are holes in the low part of the physical address
183 * space we can treat physmem as a pfn (not just a pgcnt) and
184 * get a conservative upper limit.
186 if (physmem
!= 0 && high_phys
> pfn_to_pa(physmem
))
187 high_phys
= pfn_to_pa(physmem
);
190 * find the lowest or highest available memory in physinstalled
191 * On 32 bit avoid physmem above 4Gig if PAE isn't enabled
194 if (xbootp
->bi_use_pae
== 0 && high_phys
> FOUR_GIG
)
195 high_phys
= FOUR_GIG
;
199 * find the highest available memory in physinstalled
201 size
= P2ROUNDUP(size
, align
);
202 for (; ml
; ml
= ml
->ml_next
) {
203 start
= P2ROUNDUP(ml
->ml_address
, align
);
204 end
= P2ALIGN(ml
->ml_address
+ ml
->ml_size
, align
);
205 if (start
< next_phys
)
206 start
= P2ROUNDUP(next_phys
, align
);
208 end
= P2ALIGN(high_phys
, align
);
212 if (end
- start
< size
)
216 * Early allocations need to use low memory, since
217 * physmem might be further limited by bootenv.rc
219 if (early_allocation
) {
220 if (pa
== 0 || start
< pa
)
228 if (early_allocation
)
229 next_phys
= pa
+ size
;
234 bop_panic("do_bop_phys_alloc(0x%" PRIx64
", 0x%" PRIx64
235 ") Out of memory\n", size
, align
);
240 alloc_vaddr(size_t size
, paddr_t align
)
244 next_virt
= P2ROUNDUP(next_virt
, (uintptr_t)align
);
245 rv
= (uintptr_t)next_virt
;
251 * Allocate virtual memory. The size is always rounded up to a multiple
257 do_bsys_alloc(bootops_t
*bop
, caddr_t virthint
, size_t size
, int align
)
259 paddr_t a
= align
; /* same type as pa for masking */
263 ssize_t s
; /* the aligned size */
265 uint_t is_kernel
= (virthint
!= 0);
267 if (a
< MMU_PAGESIZE
)
270 prom_panic("do_bsys_alloc() incorrect alignment");
271 size
= P2ROUNDUP(size
, MMU_PAGESIZE
);
274 * Use the next aligned virtual address if we weren't given one.
276 if (virthint
== NULL
) {
277 virthint
= (caddr_t
)alloc_vaddr(size
, a
);
278 total_bop_alloc_scratch
+= size
;
280 total_bop_alloc_kernel
+= size
;
284 * allocate the physical memory
286 pa
= do_bop_phys_alloc(size
, a
);
289 * Add the mappings to the page tables, try large pages first.
291 va
= (uintptr_t)virthint
;
294 pgsize
= xbootp
->bi_use_pae
? TWO_MEG
: FOUR_MEG
;
295 if (xbootp
->bi_use_largepage
&& a
== pgsize
) {
296 while (IS_P2ALIGNED(pa
, pgsize
) && IS_P2ALIGNED(va
, pgsize
) &&
298 kbm_map(va
, pa
, level
, is_kernel
);
306 * Map remaining pages use small mappings
309 pgsize
= MMU_PAGESIZE
;
311 kbm_map(va
, pa
, level
, is_kernel
);
320 * Free virtual memory - we'll just ignore these.
324 do_bsys_free(bootops_t
*bop
, caddr_t virt
, size_t size
)
326 bop_printf(NULL
, "do_bsys_free(virt=0x%p, size=0x%lx) ignored\n",
342 prom_panic("unsupported call to BOP_EALLOC()\n");
348 bsetprop(char *name
, int nlen
, void *value
, int vlen
)
355 * align the size to 16 byte boundary
357 size
= sizeof (bootprop_t
) + nlen
+ 1 + vlen
;
358 size
= (size
+ 0xf) & ~0xf;
359 if (size
> curr_space
) {
360 need_size
= (size
+ (MMU_PAGEOFFSET
)) & MMU_PAGEMASK
;
361 curr_page
= do_bsys_alloc(NULL
, 0, need_size
, MMU_PAGESIZE
);
362 curr_space
= need_size
;
366 * use a bootprop_t at curr_page and link into list
368 b
= (bootprop_t
*)curr_page
;
369 curr_page
+= sizeof (bootprop_t
);
370 curr_space
-= sizeof (bootprop_t
);
375 * follow by name and ending zero byte
377 b
->bp_name
= curr_page
;
378 bcopy(name
, curr_page
, nlen
);
381 curr_space
-= nlen
+ 1;
384 * copy in value, but no ending zero byte
386 b
->bp_value
= curr_page
;
389 bcopy(value
, curr_page
, vlen
);
395 * align new values of curr_page, curr_space
397 while (curr_space
& 0xf) {
404 bsetprops(char *name
, char *value
)
406 bsetprop(name
, strlen(name
), value
, strlen(value
) + 1);
410 bsetprop64(char *name
, uint64_t value
)
412 bsetprop(name
, strlen(name
), (void *)&value
, sizeof (value
));
416 bsetpropsi(char *name
, int value
)
420 (void) snprintf(prop_val
, sizeof (prop_val
), "%d", value
);
421 bsetprops(name
, prop_val
);
425 * to find the size of the buffer to allocate
429 do_bsys_getproplen(bootops_t
*bop
, const char *name
)
433 for (b
= bprops
; b
; b
= b
->bp_next
) {
434 if (strcmp(name
, b
->bp_name
) != 0)
442 * get the value associated with this name
446 do_bsys_getprop(bootops_t
*bop
, const char *name
, void *value
)
450 for (b
= bprops
; b
; b
= b
->bp_next
) {
451 if (strcmp(name
, b
->bp_name
) != 0)
453 bcopy(b
->bp_value
, value
, b
->bp_vlen
);
460 * get the name of the next property in succession from the standalone
464 do_bsys_nextprop(bootops_t
*bop
, char *name
)
469 * A null name is a special signal for the 1st boot property
471 if (name
== NULL
|| strlen(name
) == 0) {
474 return (bprops
->bp_name
);
477 for (b
= bprops
; b
; b
= b
->bp_next
) {
478 if (name
!= b
->bp_name
)
489 * Parse numeric value from a string. Understands decimal, hex, octal, - and ~
492 parse_value(char *p
, uint64_t *retval
)
500 if (*p
== '-' || *p
== '~')
507 if (*p
== 'x' || *p
== 'X') {
516 if ('0' <= *p
&& *p
<= '9')
518 else if ('a' <= *p
&& *p
<= 'f')
519 digit
= 10 + *p
- 'a';
520 else if ('A' <= *p
&& *p
<= 'F')
521 digit
= 10 + *p
- 'A';
526 tmp
= tmp
* radix
+ digit
;
531 else if (adjust
== '~')
538 * 2nd part of building the table of boot properties. This includes:
539 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
541 * lines look like one of:
543 * ^# comment till end of line
544 * setprop name 'value'
546 * setprop name "value"
548 * we do single character I/O since this is really just looking at memory
551 boot_prop_finish(void)
561 char *inputdev
; /* these override the command line if serial ports */
568 if (!DOMAIN_IS_INITDOMAIN(xen_info
))
572 DBG_MSG("Opening /boot/solaris/bootenv.rc\n");
573 fd
= BRD_OPEN(bfs_ops
, "/boot/solaris/bootenv.rc", 0);
576 line
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
583 bytes_read
= BRD_READ(bfs_ops
, fd
, line
+ c
, 1);
584 if (bytes_read
== 0) {
595 * ignore comment lines
598 while (ISSPACE(line
[c
]))
600 if (line
[c
] == '#' || line
[c
] == 0)
604 * must have "setprop " or "setprop\t"
606 if (strncmp(line
+ c
, "setprop ", 8) != 0 &&
607 strncmp(line
+ c
, "setprop\t", 8) != 0)
610 while (ISSPACE(line
[c
]))
616 * gather up the property name
620 while (line
[c
] && !ISSPACE(line
[c
]))
624 * gather up the value, if any
628 while (ISSPACE(line
[c
]))
632 while (line
[c
] && !ISSPACE(line
[c
]))
636 if (v_len
>= 2 && value
[0] == value
[v_len
- 1] &&
637 (value
[0] == '\'' || value
[0] == '"')) {
648 * ignore "boot-file" property, it's now meaningless
650 if (strcmp(name
, "boot-file") == 0)
652 if (strcmp(name
, "boot-args") == 0 &&
653 strlen(boot_args
) > 0)
657 * If a property was explicitly set on the command line
658 * it will override a setting in bootenv.rc
660 if (do_bsys_getproplen(NULL
, name
) > 0)
663 bsetprop(name
, n_len
, value
, v_len
+ 1);
667 BRD_CLOSE(bfs_ops
, fd
);
670 * Check if we have to limit the boot time allocator
672 if (do_bsys_getproplen(NULL
, "physmem") != -1 &&
673 do_bsys_getprop(NULL
, "physmem", line
) >= 0 &&
674 parse_value(line
, &lvalue
) != -1) {
675 if (0 < lvalue
&& (lvalue
< physmem
|| physmem
== 0)) {
676 physmem
= (pgcnt_t
)lvalue
;
680 early_allocation
= 0;
683 * check to see if we have to override the default value of the console
687 v_len
= do_bsys_getproplen(NULL
, "input-device");
689 (void) do_bsys_getprop(NULL
, "input-device", inputdev
);
694 outputdev
= inputdev
+ v_len
+ 1;
695 v_len
= do_bsys_getproplen(NULL
, "output-device");
697 (void) do_bsys_getprop(NULL
, "output-device",
701 outputdev
[v_len
] = 0;
703 consoledev
= outputdev
+ v_len
+ 1;
704 v_len
= do_bsys_getproplen(NULL
, "console");
706 (void) do_bsys_getprop(NULL
, "console", consoledev
);
707 if (post_fastreboot
&&
708 strcmp(consoledev
, "graphics") == 0) {
709 bsetprops("console", "text");
710 v_len
= strlen("text");
711 bcopy("text", consoledev
, v_len
);
716 consoledev
[v_len
] = 0;
717 bcons_init2(inputdev
, outputdev
, consoledev
);
720 * Ensure console property exists
721 * If not create it as "hypervisor"
723 v_len
= do_bsys_getproplen(NULL
, "console");
725 bsetprops("console", "hypervisor");
726 inputdev
= outputdev
= consoledev
= "hypervisor";
727 bcons_init2(inputdev
, outputdev
, consoledev
);
730 if (strstr((char *)xbootp
->bi_cmdline
, "prom_debug") || kbm_debug
) {
732 bop_printf(NULL
, "\nBoot properties:\n");
734 while ((name
= do_bsys_nextprop(NULL
, name
)) != NULL
) {
735 bop_printf(NULL
, "\t0x%p %s = ", (void *)name
, name
);
736 (void) do_bsys_getprop(NULL
, name
, value
);
737 v_len
= do_bsys_getproplen(NULL
, name
);
738 bop_printf(NULL
, "len=%d ", v_len
);
740 bop_printf(NULL
, "%s\n", value
);
746 * print formatted output
751 bop_printf(bootops_t
*bop
, const char *fmt
, ...)
755 if (have_console
== 0)
759 (void) vsnprintf(buffer
, BUFFERSIZE
, fmt
, ap
);
765 * Another panic() variant; this one can be used even earlier during boot than
770 bop_panic(const char *fmt
, ...)
775 bop_printf(NULL
, fmt
, ap
);
778 bop_printf(NULL
, "\nPress any key to reboot.\n");
779 (void) bcons_getchar();
780 bop_printf(NULL
, "Resetting...\n");
785 * Do a real mode interrupt BIOS call
787 typedef struct bios_regs
{
788 unsigned short ax
, bx
, cx
, dx
, si
, di
, bp
, es
, ds
;
790 typedef int (*bios_func_t
)(int, bios_regs_t
*);
794 do_bsys_doint(bootops_t
*bop
, int intnum
, struct bop_regs
*rp
)
797 prom_panic("unsupported call to BOP_DOINT()\n");
799 static int firsttime
= 1;
800 bios_func_t bios_func
= (bios_func_t
)(void *)(uintptr_t)0x5000;
804 * The first time we do this, we have to copy the pre-packaged
805 * low memory bios call code image into place.
808 extern char bios_image
[];
809 extern uint32_t bios_size
;
811 bcopy(bios_image
, (void *)bios_func
, bios_size
);
815 br
.ax
= rp
->eax
.word
.ax
;
816 br
.bx
= rp
->ebx
.word
.bx
;
817 br
.cx
= rp
->ecx
.word
.cx
;
818 br
.dx
= rp
->edx
.word
.dx
;
819 br
.bp
= rp
->ebp
.word
.bp
;
820 br
.si
= rp
->esi
.word
.si
;
821 br
.di
= rp
->edi
.word
.di
;
825 DBG_MSG("Doing BIOS call...");
829 rp
->eflags
= bios_func(intnum
, &br
);
832 rp
->eax
.word
.ax
= br
.ax
;
833 rp
->ebx
.word
.bx
= br
.bx
;
834 rp
->ecx
.word
.cx
= br
.cx
;
835 rp
->edx
.word
.dx
= br
.dx
;
836 rp
->ebp
.word
.bp
= br
.bp
;
837 rp
->esi
.word
.si
= br
.si
;
838 rp
->edi
.word
.di
= br
.di
;
844 static struct boot_syscalls bop_sysp
= {
856 static char namebuf
[32];
859 xen_parse_props(char *s
, char *prop_map
[], int n_prop
)
861 char **prop_name
= prop_map
;
866 while ((*cp
!= NULL
) && (*cp
!= ':'))
869 if ((scp
!= cp
) && (*prop_name
!= NULL
)) {
871 bsetprops(*prop_name
, scp
);
877 } while (n_prop
> 0);
880 #define VBDPATHLEN 64
883 * parse the 'xpv-root' property to create properties used by
887 xen_vbdroot_props(char *s
)
889 char vbdpath
[VBDPATHLEN
] = "/xpvd/xdf@";
890 const char lnamefix
[] = "/dev/dsk/c0d";
897 pnp
= vbdpath
+ strlen(vbdpath
);
898 prop_p
= s
+ strlen(lnamefix
);
899 while ((*prop_p
!= '\0') && (*prop_p
!= 's') && (*prop_p
!= 'p'))
900 addr
= addr
* 10 + *prop_p
++ - '0';
901 (void) snprintf(pnp
, VBDPATHLEN
, "%lx", addr
);
902 pnp
= vbdpath
+ strlen(vbdpath
);
905 else if (*prop_p
== 'p')
908 ASSERT(0); /* shouldn't be here */
910 ASSERT(*prop_p
!= '\0');
911 if (ISDIGIT(*prop_p
)) {
912 minor
= *prop_p
- '0';
914 if (ISDIGIT(*prop_p
)) {
915 minor
= minor
* 10 + *prop_p
- '0';
918 /* malformed root path, use 0 as default */
921 ASSERT(minor
< 16); /* at most 16 partitions */
926 bsetprops("fstype", "ufs");
927 bsetprops("bootpath", vbdpath
);
929 DBG_MSG("VBD bootpath set to ");
935 * parse the xpv-nfsroot property to create properties used by
939 xen_nfsroot_props(char *s
)
942 BP_SERVER_IP
, /* server IP address */
943 BP_SERVER_NAME
, /* server hostname */
944 BP_SERVER_PATH
, /* root path */
946 int n_prop
= sizeof (prop_map
) / sizeof (prop_map
[0]);
948 bsetprop("fstype", 6, "nfs", 4);
950 xen_parse_props(s
, prop_map
, n_prop
);
953 * If a server name wasn't specified, use a default.
955 if (do_bsys_getproplen(NULL
, BP_SERVER_NAME
) == -1)
956 bsetprops(BP_SERVER_NAME
, "unknown");
960 * Extract our IP address, etc. from the "xpv-ip" property.
963 xen_ip_props(char *s
)
966 BP_HOST_IP
, /* IP address */
967 NULL
, /* NFS server IP address (ignored in */
968 /* favour of xpv-nfsroot) */
969 BP_ROUTER_IP
, /* IP gateway */
970 BP_SUBNET_MASK
, /* IP subnet mask */
971 "xpv-hostname", /* hostname (ignored) */
972 BP_NETWORK_INTERFACE
, /* interface name */
973 "xpv-hcp", /* host configuration protocol */
975 int n_prop
= sizeof (prop_map
) / sizeof (prop_map
[0]);
976 char ifname
[IFNAMSIZ
];
978 xen_parse_props(s
, prop_map
, n_prop
);
981 * A Linux dom0 administrator expects all interfaces to be
982 * called "ethX", which is not the case here.
984 * If the interface name specified is "eth0", presume that
985 * this is really intended to be "xnf0" (the first domU ->
986 * dom0 interface for this domain).
988 if ((do_bsys_getprop(NULL
, BP_NETWORK_INTERFACE
, ifname
) == 0) &&
989 (strcmp("eth0", ifname
) == 0)) {
990 bsetprops(BP_NETWORK_INTERFACE
, "xnf0");
992 "network interface name 'eth0' replaced with 'xnf0'\n");
999 setup_rarp_props(struct sol_netinfo
*sip
)
1001 char buf
[BUFLEN
]; /* to hold ip/mac addrs */
1004 val
= (uint8_t *)&sip
->sn_ciaddr
;
1005 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1006 val
[0], val
[1], val
[2], val
[3]);
1007 bsetprops(BP_HOST_IP
, buf
);
1009 val
= (uint8_t *)&sip
->sn_siaddr
;
1010 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1011 val
[0], val
[1], val
[2], val
[3]);
1012 bsetprops(BP_SERVER_IP
, buf
);
1014 if (sip
->sn_giaddr
!= 0) {
1015 val
= (uint8_t *)&sip
->sn_giaddr
;
1016 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1017 val
[0], val
[1], val
[2], val
[3]);
1018 bsetprops(BP_ROUTER_IP
, buf
);
1021 if (sip
->sn_netmask
!= 0) {
1022 val
= (uint8_t *)&sip
->sn_netmask
;
1023 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
1024 val
[0], val
[1], val
[2], val
[3]);
1025 bsetprops(BP_SUBNET_MASK
, buf
);
1028 if (sip
->sn_mactype
!= 4 || sip
->sn_maclen
!= 6) {
1029 bop_printf(NULL
, "unsupported mac type %d, mac len %d\n",
1030 sip
->sn_mactype
, sip
->sn_maclen
);
1032 val
= sip
->sn_macaddr
;
1033 (void) snprintf(buf
, BUFLEN
, "%x:%x:%x:%x:%x:%x",
1034 val
[0], val
[1], val
[2], val
[3], val
[4], val
[5]);
1035 bsetprops(BP_BOOT_MAC
, buf
);
1042 build_panic_cmdline(const char *cmd
, int cmdlen
)
1047 arglen
= sizeof (fastreboot_onpanic_args
);
1049 * If we allready have fastreboot-onpanic set to zero,
1050 * don't add them again.
1052 if ((proplen
= do_bsys_getproplen(NULL
, FASTREBOOT_ONPANIC
)) > 0 &&
1053 proplen
<= sizeof (fastreboot_onpanic_cmdline
)) {
1054 (void) do_bsys_getprop(NULL
, FASTREBOOT_ONPANIC
,
1055 fastreboot_onpanic_cmdline
);
1056 if (FASTREBOOT_ONPANIC_NOTSET(fastreboot_onpanic_cmdline
))
1061 * construct fastreboot_onpanic_cmdline
1063 if (cmdlen
+ arglen
> sizeof (fastreboot_onpanic_cmdline
)) {
1064 DBG_MSG("Command line too long: clearing "
1065 FASTREBOOT_ONPANIC
"\n");
1066 fastreboot_onpanic
= 0;
1068 bcopy(cmd
, fastreboot_onpanic_cmdline
, cmdlen
);
1070 bcopy(fastreboot_onpanic_args
,
1071 fastreboot_onpanic_cmdline
+ cmdlen
, arglen
);
1073 fastreboot_onpanic_cmdline
[cmdlen
] = 0;
1080 * Construct boot command line for Fast Reboot
1083 build_fastboot_cmdline(void)
1085 saved_cmdline_len
= strlen(xbootp
->bi_cmdline
) + 1;
1086 if (saved_cmdline_len
> FASTBOOT_SAVED_CMDLINE_LEN
) {
1087 DBG(saved_cmdline_len
);
1088 DBG_MSG("Command line too long: clearing fastreboot_capable\n");
1089 fastreboot_capable
= 0;
1091 bcopy((void *)(xbootp
->bi_cmdline
), (void *)saved_cmdline
,
1093 saved_cmdline
[saved_cmdline_len
- 1] = '\0';
1094 build_panic_cmdline(saved_cmdline
, saved_cmdline_len
- 1);
1099 * Save memory layout, disk drive information, unix and boot archive sizes for
1103 save_boot_info(multiboot_info_t
*mbi
, struct xboot_info
*xbi
)
1105 struct boot_modules
*modp
;
1108 bcopy(mbi
, &saved_mbi
, sizeof (multiboot_info_t
));
1109 if (mbi
->mmap_length
> sizeof (saved_mmap
)) {
1110 DBG_MSG("mbi->mmap_length too big: clearing "
1111 "fastreboot_capable\n");
1112 fastreboot_capable
= 0;
1114 bcopy((void *)(uintptr_t)mbi
->mmap_addr
, (void *)saved_mmap
,
1118 if ((mbi
->flags
& MB_INFO_DRIVE_INFO
) != 0) {
1119 if (mbi
->drives_length
> sizeof (saved_drives
)) {
1120 DBG(mbi
->drives_length
);
1121 DBG_MSG("mbi->drives_length too big: clearing "
1122 "fastreboot_capable\n");
1123 fastreboot_capable
= 0;
1125 bcopy((void *)(uintptr_t)mbi
->drives_addr
,
1126 (void *)saved_drives
, mbi
->drives_length
);
1129 saved_mbi
.drives_length
= 0;
1130 saved_mbi
.drives_addr
= NULL
;
1134 * Current file sizes. Used by fastboot.c to figure out how much
1135 * memory to reserve for panic reboot.
1136 * Use the module list from the dboot-constructed xboot_info
1137 * instead of the list referenced by the multiboot structure
1138 * because that structure may not be addressable now.
1140 saved_file_size
[FASTBOOT_NAME_UNIX
] = FOUR_MEG
- PAGESIZE
;
1141 for (i
= 0, modp
= (struct boot_modules
*)(uintptr_t)xbi
->bi_modules
;
1142 i
< xbi
->bi_module_cnt
; i
++, modp
++) {
1143 saved_file_size
[FASTBOOT_NAME_BOOTARCHIVE
] += modp
->bm_size
;
1150 * 1st pass at building the table of boot properties. This includes:
1151 * - values set on the command line: -B a=x,b=y,c=z ....
1152 * - known values we just compute (ie. from xbootp)
1153 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
1155 * the grub command line looked like:
1156 * kernel boot-file [-B prop=value[,prop=value]...] [boot-args]
1158 * whoami is the same as boot-file
1161 build_boot_properties(void)
1167 struct boot_modules
*bm
;
1172 static int stdout_val
= 0;
1173 uchar_t boot_device
;
1175 multiboot_info_t
*mbi
;
1177 struct sol_netinfo
*sip
;
1181 * These have to be done first, so that kobj_mount_root() works
1183 DBG_MSG("Building boot properties\n");
1184 propbuf
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, 0);
1185 DBG((uintptr_t)propbuf
);
1186 if (xbootp
->bi_module_cnt
> 0) {
1187 bm
= xbootp
->bi_modules
;
1188 bsetprop64("ramdisk_start", (uint64_t)(uintptr_t)bm
->bm_addr
);
1189 bsetprop64("ramdisk_end", (uint64_t)(uintptr_t)bm
->bm_addr
+
1193 DBG_MSG("Parsing command line for boot properties\n");
1194 value
= xbootp
->bi_cmdline
;
1197 * allocate memory to collect boot_args into
1199 boot_arg_len
= strlen(xbootp
->bi_cmdline
) + 1;
1200 boot_args
= do_bsys_alloc(NULL
, NULL
, boot_arg_len
, MMU_PAGESIZE
);
1206 * Xen puts a lot of device information in front of the kernel name
1207 * let's grab them and make them boot properties. The first
1208 * string w/o an "=" in it will be the boot-file property.
1210 (void) strcpy(namebuf
, "xpv-");
1213 * get to next property
1215 while (ISSPACE(*value
))
1221 while (*value
&& !ISSPACE(*value
) && *value
!= '=') {
1224 if (*value
!= '=') { /* no "=" in the property */
1228 name_len
= value
- name
;
1234 while (value
[value_len
] && !ISSPACE(value
[value_len
])) {
1238 * build property name with "xpv-" prefix
1240 if (name_len
+ 4 > 32) { /* skip if name too long */
1244 bcopy(name
, &namebuf
[4], name_len
);
1246 namebuf
[name_len
] = 0;
1247 bcopy(value
, propbuf
, value_len
);
1248 propbuf
[value_len
] = 0;
1249 bsetprops(namebuf
, propbuf
);
1252 * xpv-root is set to the logical disk name of the xen
1253 * VBD when booting from a disk-based filesystem.
1255 if (strcmp(namebuf
, "xpv-root") == 0)
1256 xen_vbdroot_props(propbuf
);
1258 * While we're here, if we have a "xpv-nfsroot" property
1259 * then we need to set "fstype" to "nfs" so we mount
1260 * our root from the nfs server. Also parse the xpv-nfsroot
1261 * property to create the properties that nfs_mountroot will
1262 * need to find the root and mount it.
1264 if (strcmp(namebuf
, "xpv-nfsroot") == 0)
1265 xen_nfsroot_props(propbuf
);
1267 if (strcmp(namebuf
, "xpv-ip") == 0)
1268 xen_ip_props(propbuf
);
1273 while (ISSPACE(*value
))
1276 * value now points at the boot-file
1279 while (value
[value_len
] && !ISSPACE(value
[value_len
]))
1281 if (value_len
> 0) {
1283 bcopy(value
, whoami
, value_len
);
1284 whoami
[value_len
] = 0;
1285 bsetprops("boot-file", whoami
);
1287 * strip leading path stuff from whoami, so running from
1288 * PXE/miniroot makes sense.
1290 if (strstr(whoami
, "/platform/") != NULL
)
1291 whoami
= strstr(whoami
, "/platform/");
1292 bsetprops("whoami", whoami
);
1296 * Values forcibly set boot properties on the command line via -B.
1297 * Allow use of quotes in values. Other stuff goes on kernel
1300 name
= value
+ value_len
;
1301 while (*name
!= 0) {
1303 * anything not " -B" is copied to the command line
1305 if (!ISSPACE(name
[0]) || name
[1] != '-' || name
[2] != 'B') {
1306 boot_args
[boot_arg_len
++] = *name
;
1307 boot_args
[boot_arg_len
] = 0;
1313 * skip the " -B" and following white space
1316 while (ISSPACE(*name
))
1318 while (*name
&& !ISSPACE(*name
)) {
1319 value
= strstr(name
, "=");
1322 name_len
= value
- name
;
1326 for (; ; ++value_len
) {
1327 if (!value
[value_len
])
1331 * is this value quoted?
1333 if (value_len
== 0 &&
1334 (value
[0] == '\'' || value
[0] == '"')) {
1340 * In the quote accept any character,
1341 * but look for ending quote.
1344 if (value
[value_len
] == quoted
)
1350 * a comma or white space ends the value
1352 if (value
[value_len
] == ',' ||
1353 ISSPACE(value
[value_len
]))
1357 if (value_len
== 0) {
1358 bsetprop(name
, name_len
, "true", 5);
1362 if (v
[0] == v
[l
- 1] &&
1363 (v
[0] == '\'' || v
[0] == '"')) {
1367 bcopy(v
, propbuf
, l
);
1369 bsetprop(name
, name_len
, propbuf
,
1372 name
= value
+ value_len
;
1373 while (*name
== ',')
1379 * set boot-args property
1380 * 1275 name is bootargs, so set
1383 bsetprops("boot-args", boot_args
);
1384 bsetprops("bootargs", boot_args
);
1388 * set the BIOS boot device from GRUB
1391 mbi
= xbootp
->bi_mb_info
;
1394 * Build boot command line for Fast Reboot
1396 build_fastboot_cmdline();
1399 * Save various boot information for Fast Reboot
1401 save_boot_info(mbi
, xbootp
);
1403 if (mbi
!= NULL
&& mbi
->flags
& MB_INFO_BOOTDEV
) {
1404 boot_device
= mbi
->boot_device
>> 24;
1405 if (boot_device
== 0x20)
1407 str
[0] = (boot_device
>> 4) + '0';
1408 str
[1] = (boot_device
& 0xf) + '0';
1410 bsetprops("bios-boot-device", str
);
1416 * In the netboot case, drives_info is overloaded with the dhcp ack.
1417 * This is not multiboot compliant and requires special pxegrub!
1419 if (netboot
&& mbi
->drives_length
!= 0) {
1420 sip
= (struct sol_netinfo
*)(uintptr_t)mbi
->drives_addr
;
1421 if (sip
->sn_infotype
== SN_TYPE_BOOTP
)
1422 bsetprop("bootp-response", sizeof ("bootp-response"),
1423 (void *)(uintptr_t)mbi
->drives_addr
,
1424 mbi
->drives_length
);
1425 else if (sip
->sn_infotype
== SN_TYPE_RARP
)
1426 setup_rarp_props(sip
);
1428 bsetprop("stdout", strlen("stdout"),
1429 &stdout_val
, sizeof (stdout_val
));
1433 * more conjured up values for made up things....
1436 bsetprops("mfg-name", "i86xpv");
1437 bsetprops("impl-arch-name", "i86xpv");
1439 bsetprops("mfg-name", "i86pc");
1440 bsetprops("impl-arch-name", "i86pc");
1444 * Build firmware-provided system properties
1446 build_firmware_properties();
1451 * Find out what these are:
1452 * - cpuid_feature_ecx_include
1453 * - cpuid_feature_ecx_exclude
1454 * - cpuid_feature_edx_include
1455 * - cpuid_feature_edx_exclude
1457 * Find out what these are in multiboot:
1465 * Under the Hypervisor, memory usable for DMA may be scarce. One
1466 * very likely large pool of DMA friendly memory is occupied by
1467 * the boot_archive, as it was loaded by grub into low MFNs.
1469 * Here we free up that memory by copying the boot archive to what are
1470 * likely higher MFN pages and then swapping the mfn/pfn mappings.
1472 #define PFN_2GIG 0x80000
1474 relocate_boot_archive(void)
1476 mfn_t max_mfn
= HYPERVISOR_memory_op(XENMEM_maximum_ram_page
, NULL
);
1477 struct boot_modules
*bm
= xbootp
->bi_modules
;
1488 int mmu_update_return
;
1493 * If all MFN's are below 2Gig, don't bother doing this.
1495 if (max_mfn
< PFN_2GIG
)
1497 if (xbootp
->bi_module_cnt
< 1) {
1498 DBG_MSG("no boot_archive!");
1502 DBG_MSG("moving boot_archive to high MFN memory\n");
1503 va
= (uintptr_t)bm
->bm_addr
;
1505 slop
= va
& MMU_PAGEOFFSET
;
1507 va
+= MMU_PAGESIZE
- slop
;
1508 len
-= MMU_PAGESIZE
- slop
;
1510 len
= P2ALIGN(len
, MMU_PAGESIZE
);
1513 * Go through all boot_archive pages, swapping any low MFN pages
1514 * with memory at next_phys.
1518 va_pfn
= mmu_btop(va
- ONE_GIG
);
1519 va_mfn
= mfn_list
[va_pfn
];
1520 if (mfn_list
[va_pfn
] < PFN_2GIG
) {
1521 copy
= kbm_remap_window(next_phys
, 1);
1522 bcopy((void *)va
, copy
, MMU_PAGESIZE
);
1523 copy_pfn
= mmu_btop(next_phys
);
1524 copy_mfn
= mfn_list
[copy_pfn
];
1526 pte
= mfn_to_ma(copy_mfn
) | PT_NOCONSIST
| PT_VALID
;
1527 if (HYPERVISOR_update_va_mapping(va
, pte
,
1528 UVMF_INVLPG
| UVMF_LOCAL
))
1529 bop_panic("relocate_boot_archive(): "
1530 "HYPERVISOR_update_va_mapping() failed");
1532 mfn_list
[va_pfn
] = copy_mfn
;
1533 mfn_list
[copy_pfn
] = va_mfn
;
1535 t
[0].ptr
= mfn_to_ma(copy_mfn
) | MMU_MACHPHYS_UPDATE
;
1537 t
[1].ptr
= mfn_to_ma(va_mfn
) | MMU_MACHPHYS_UPDATE
;
1538 t
[1].val
= copy_pfn
;
1539 if (HYPERVISOR_mmu_update(t
, 2, &mmu_update_return
,
1540 DOMID_SELF
) != 0 || mmu_update_return
!= 2)
1541 bop_panic("relocate_boot_archive(): "
1542 "HYPERVISOR_mmu_update() failed");
1544 next_phys
+= MMU_PAGESIZE
;
1547 len
-= MMU_PAGESIZE
;
1550 DBG_MSG("Relocated pages:\n");
1552 DBG_MSG("Out of total pages:\n");
1559 * Install a temporary IDT that lets us catch errors in the boot time code.
1560 * We shouldn't get any faults at all while this is installed, so we'll
1561 * just generate a traceback and exit.
1564 static const int bcode_sel
= B64CODE_SEL
;
1566 static const int bcode_sel
= B32CODE_SEL
;
1570 * simple description of a stack frame (args are 32 bit only currently)
1572 typedef struct bop_frame
{
1573 struct bop_frame
*old_frame
;
1579 bop_traceback(bop_frame_t
*frame
)
1589 bop_printf(NULL
, "Stack traceback:\n");
1590 for (cnt
= 0; cnt
< 30; ++cnt
) { /* up to 30 frames */
1591 pc
= frame
->retaddr
;
1594 ksym
= kobj_getsymname(pc
, &off
);
1596 bop_printf(NULL
, " %s+%lx", ksym
, off
);
1598 bop_printf(NULL
, " 0x%lx", pc
);
1600 frame
= frame
->old_frame
;
1602 bop_printf(NULL
, "\n");
1606 for (a
= 0; a
< 6; ++a
) { /* try for 6 args */
1607 if ((void *)&frame
->arg
[a
] == (void *)frame
->old_frame
)
1610 bop_printf(NULL
, "(");
1612 bop_printf(NULL
, ",");
1613 bop_printf(NULL
, "0x%lx", frame
->arg
[a
]);
1615 bop_printf(NULL
, ")");
1617 bop_printf(NULL
, "\n");
1622 ulong_t error_code
; /* optional */
1633 bop_trap(ulong_t
*tfp
)
1635 struct trapframe
*tf
= (struct trapframe
*)tfp
;
1636 bop_frame_t fakeframe
;
1637 static int depth
= 0;
1640 * Check for an infinite loop of traps.
1643 bop_panic("Nested trap");
1645 bop_printf(NULL
, "Unexpected trap\n");
1648 * adjust the tf for optional error_code by detecting the code selector
1650 if (tf
->code_seg
!= bcode_sel
)
1651 tf
= (struct trapframe
*)(tfp
- 1);
1653 bop_printf(NULL
, "error code 0x%lx\n",
1654 tf
->error_code
& 0xffffffff);
1656 bop_printf(NULL
, "instruction pointer 0x%lx\n", tf
->inst_ptr
);
1657 bop_printf(NULL
, "code segment 0x%lx\n", tf
->code_seg
& 0xffff);
1658 bop_printf(NULL
, "flags register 0x%lx\n", tf
->flags_reg
);
1660 bop_printf(NULL
, "return %%rsp 0x%lx\n", tf
->stk_ptr
);
1661 bop_printf(NULL
, "return %%ss 0x%lx\n", tf
->stk_seg
& 0xffff);
1664 /* grab %[er]bp pushed by our code from the stack */
1665 fakeframe
.old_frame
= (bop_frame_t
*)*(tfp
- 3);
1666 fakeframe
.retaddr
= (pc_t
)tf
->inst_ptr
;
1667 bop_printf(NULL
, "Attempting stack backtrace:\n");
1668 bop_traceback(&fakeframe
);
1669 bop_panic("unexpected trap in early boot");
1672 extern void bop_trap_handler(void);
1674 static gate_desc_t
*bop_idt
;
1676 static desctbr_t bop_idt_info
;
1683 bop_idt
= (gate_desc_t
*)
1684 do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
1685 bzero(bop_idt
, MMU_PAGESIZE
);
1686 for (t
= 0; t
< NIDT
; ++t
) {
1688 * Note that since boot runs without a TSS, the
1689 * double fault handler cannot use an alternate stack
1690 * (64-bit) or a task gate (32-bit).
1692 set_gatesegd(&bop_idt
[t
], &bop_trap_handler
, bcode_sel
,
1693 SDT_SYSIGT
, TRP_KPL
, 0);
1695 bop_idt_info
.dtr_limit
= (NIDT
* sizeof (gate_desc_t
)) - 1;
1696 bop_idt_info
.dtr_base
= (uintptr_t)bop_idt
;
1697 wr_idtr(&bop_idt_info
);
1699 #endif /* !defined(__xpv) */
1702 * This is where we enter the kernel. It dummies up the boot_ops and
1703 * boot_syscalls vectors and jumps off to _kobj_boot()
1706 _start(struct xboot_info
*xbp
)
1708 bootops_t
*bops
= &bootop
;
1709 extern void _kobj_boot();
1712 * 1st off - initialize the console for any error messages
1716 HYPERVISOR_shared_info
= (void *)xbootp
->bi_shared_info
;
1717 xen_info
= xbootp
->bi_xen_start_info
;
1721 if (*((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) ==
1723 post_fastreboot
= 1;
1724 *((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) = 0;
1728 bcons_init((void *)xbootp
->bi_cmdline
);
1734 if (strstr((char *)xbootp
->bi_cmdline
, "kbm_debug"))
1737 DBG_MSG("\n\n*** Entered Solaris in _start() cmdline is: ");
1738 DBG_MSG((char *)xbootp
->bi_cmdline
);
1742 * physavail is no longer used by startup
1744 bm
.physinstalled
= xbp
->bi_phys_install
;
1745 bm
.pcimem
= xbp
->bi_pcimem
;
1746 bm
.rsvdmem
= xbp
->bi_rsvdmem
;
1747 bm
.physavail
= NULL
;
1750 * initialize the boot time allocator
1752 next_phys
= xbootp
->bi_next_paddr
;
1754 next_virt
= (uintptr_t)xbootp
->bi_next_vaddr
;
1756 DBG_MSG("Initializing boot time memory management...");
1759 xen_platform_parameters_t p
;
1761 /* This call shouldn't fail, dboot already did it once. */
1762 (void) HYPERVISOR_xen_version(XENVER_platform_parameters
, &p
);
1763 mfn_to_pfn_mapping
= (pfn_t
*)(xen_virt_start
= p
.virt_start
);
1764 DBG(xen_virt_start
);
1771 * Fill in the bootops vector
1773 bops
->bsys_version
= BO_VERSION
;
1774 bops
->boot_mem
= &bm
;
1775 bops
->bsys_alloc
= do_bsys_alloc
;
1776 bops
->bsys_free
= do_bsys_free
;
1777 bops
->bsys_getproplen
= do_bsys_getproplen
;
1778 bops
->bsys_getprop
= do_bsys_getprop
;
1779 bops
->bsys_nextprop
= do_bsys_nextprop
;
1780 bops
->bsys_printf
= bop_printf
;
1781 bops
->bsys_doint
= do_bsys_doint
;
1784 * BOP_EALLOC() is no longer needed
1786 bops
->bsys_ealloc
= do_bsys_ealloc
;
1790 * On domain 0 we need to free up some physical memory that is
1791 * usable for DMA. Since GRUB loaded the boot_archive, it is
1792 * sitting in low MFN memory. We'll relocated the boot archive
1793 * pages to high PFN memory.
1795 if (DOMAIN_IS_INITDOMAIN(xen_info
))
1796 relocate_boot_archive();
1801 * Install an IDT to catch early pagefaults (shouldn't have any).
1802 * Also needed for kmdb.
1808 * Start building the boot properties from the command line
1810 DBG_MSG("Initializing boot properties:\n");
1811 build_boot_properties();
1813 if (strstr((char *)xbootp
->bi_cmdline
, "prom_debug") || kbm_debug
) {
1819 value
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
1820 bop_printf(NULL
, "\nBoot properties:\n");
1822 while ((name
= do_bsys_nextprop(NULL
, name
)) != NULL
) {
1823 bop_printf(NULL
, "\t0x%p %s = ", (void *)name
, name
);
1824 (void) do_bsys_getprop(NULL
, name
, value
);
1825 len
= do_bsys_getproplen(NULL
, name
);
1826 bop_printf(NULL
, "len=%d ", len
);
1828 for (cp
= value
; *cp
; ++cp
) {
1829 if (' ' <= *cp
&& *cp
<= '~')
1830 bop_printf(NULL
, "%c", *cp
);
1832 bop_printf(NULL
, "-0x%x-", *cp
);
1834 bop_printf(NULL
, "\n");
1839 * jump into krtld...
1841 _kobj_boot(&bop_sysp
, NULL
, bops
, NULL
);
1847 no_more_alloc(bootops_t
*bop
, caddr_t virthint
, size_t size
, int align
)
1849 panic("Attempt to bsys_alloc() too late\n");
1855 no_more_free(bootops_t
*bop
, caddr_t virt
, size_t size
)
1857 panic("Attempt to bsys_free() too late\n");
1861 bop_no_more_mem(void)
1863 DBG(total_bop_alloc_scratch
);
1864 DBG(total_bop_alloc_kernel
);
1865 bootops
->bsys_alloc
= no_more_alloc
;
1866 bootops
->bsys_free
= no_more_free
;
1871 * Set ACPI firmware properties
1875 vmap_phys(size_t length
, paddr_t pa
)
1882 pa
= pfn_to_pa(xen_assign_pfn(mmu_btop(pa
))) | (pa
& MMU_PAGEOFFSET
);
1884 start
= P2ALIGN(pa
, MMU_PAGESIZE
);
1885 end
= P2ROUNDUP(pa
+ length
, MMU_PAGESIZE
);
1887 va
= (caddr_t
)alloc_vaddr(len
, MMU_PAGESIZE
);
1888 for (page
= 0; page
< len
; page
+= MMU_PAGESIZE
)
1889 kbm_map((uintptr_t)va
+ page
, start
+ page
, 0, 0);
1890 return (va
+ (pa
& MMU_PAGEOFFSET
));
1894 checksum_table(uint8_t *tp
, size_t len
)
1905 valid_rsdp(struct rsdp
*rp
)
1908 /* validate the V1.x checksum */
1909 if (checksum_table((uint8_t *)&rp
->v1
, sizeof (struct rsdp_v1
)) != 0)
1912 /* If pre-ACPI 2.0, this is a valid RSDP */
1913 if (rp
->v1
.revision
< 2)
1916 /* validate the V2.x checksum */
1917 if (checksum_table((uint8_t *)rp
, sizeof (struct rsdp
)) != 0)
1924 * Scan memory range for an RSDP;
1925 * see ACPI 3.0 Spec, 5.2.5.1
1927 static struct rsdp
*
1928 scan_rsdp(paddr_t start
, paddr_t end
)
1930 size_t len
= end
- start
+ 1;
1933 ptr
= vmap_phys(len
, start
);
1935 if (strncmp(ptr
, ACPI_RSDP_SIG
, ACPI_RSDP_SIG_LEN
) == 0)
1936 if (valid_rsdp((struct rsdp
*)ptr
))
1937 return ((struct rsdp
*)ptr
);
1946 * Refer to ACPI 3.0 Spec, section 5.2.5.1 to understand this function
1948 static struct rsdp
*
1955 * Get the EBDA segment and scan the first 1K
1957 ebda_seg
= (uint16_t *)vmap_phys(sizeof (uint16_t), ACPI_EBDA_SEG_ADDR
);
1958 ebda_addr
= *ebda_seg
<< 4;
1959 rsdp
= scan_rsdp(ebda_addr
, ebda_addr
+ ACPI_EBDA_LEN
- 1);
1961 /* if EBDA doesn't contain RSDP, look in BIOS memory */
1962 rsdp
= scan_rsdp(0xe0000, 0xfffff);
1966 static struct table_header
*
1967 map_fw_table(paddr_t table_addr
)
1969 struct table_header
*tp
;
1970 size_t len
= MAX(sizeof (struct table_header
), MMU_PAGESIZE
);
1973 * Map at least a page; if the table is larger than this, remap it
1975 tp
= (struct table_header
*)vmap_phys(len
, table_addr
);
1977 tp
= (struct table_header
*)vmap_phys(tp
->len
, table_addr
);
1981 static struct table_header
*
1982 find_fw_table(char *signature
)
1984 static int revision
= 0;
1985 static struct xsdt
*xsdt
;
1989 struct table_header
*tp
;
1993 if (strlen(signature
) != ACPI_TABLE_SIG_LEN
)
1997 * Reading the ACPI 3.0 Spec, section 5.2.5.3 will help
1998 * understand this code. If we haven't already found the RSDT/XSDT,
1999 * revision will be 0. Find the RSDP and check the revision
2000 * to find out whether to use the RSDT or XSDT. If revision is
2001 * 0 or 1, use the RSDT and set internal revision to 1; if it is 2,
2002 * use the XSDT. If the XSDT address is 0, though, fall back to
2003 * revision 1 and use the RSDT.
2005 if (revision
== 0) {
2006 if ((rsdp
= (struct rsdp
*)find_rsdp()) != NULL
) {
2007 revision
= rsdp
->v1
.revision
;
2011 * Use the XSDT unless BIOS is buggy and
2012 * claims to be rev 2 but has a null XSDT
2015 xsdt_addr
= rsdp
->xsdt
;
2020 /* treat RSDP rev 0 as revision 1 internally */
2024 /* use the RSDT for rev 0/1 */
2025 xsdt_addr
= rsdp
->v1
.rsdt
;
2028 /* unknown revision */
2036 /* cache the XSDT info */
2037 xsdt
= (struct xsdt
*)map_fw_table(xsdt_addr
);
2038 len
= (xsdt
->hdr
.len
- sizeof (xsdt
->hdr
)) /
2039 ((revision
== 1) ? sizeof (uint32_t) : sizeof (uint64_t));
2043 * Scan the table headers looking for a signature match
2045 for (n
= 0; n
< len
; n
++) {
2046 table_addr
= (revision
== 1) ? xsdt
->p
.r
[n
] : xsdt
->p
.x
[n
];
2047 if (table_addr
== 0)
2049 tp
= map_fw_table(table_addr
);
2050 if (strncmp(tp
->sig
, signature
, ACPI_TABLE_SIG_LEN
) == 0) {
2058 process_mcfg(struct mcfg
*tp
)
2060 struct cfg_base_addr_alloc
*cfg_baap
;
2062 int64_t ecfginfo
[4];
2064 cfg_baap
= tp
->CfgBaseAddrAllocList
;
2065 cfg_baa_endp
= ((char *)tp
) + tp
->Length
;
2066 while ((char *)cfg_baap
< cfg_baa_endp
) {
2067 if (cfg_baap
->base_addr
!= 0 && cfg_baap
->segment
== 0) {
2068 ecfginfo
[0] = cfg_baap
->base_addr
;
2069 ecfginfo
[1] = cfg_baap
->segment
;
2070 ecfginfo
[2] = cfg_baap
->start_bno
;
2071 ecfginfo
[3] = cfg_baap
->end_bno
;
2072 bsetprop(MCFG_PROPNAME
, strlen(MCFG_PROPNAME
),
2073 ecfginfo
, sizeof (ecfginfo
));
2082 process_madt(struct madt
*tp
)
2084 struct madt_processor
*cpu
, *end
;
2085 uint32_t cpu_count
= 0;
2086 uint32_t cpu_possible_count
= 0;
2087 uint8_t cpu_apicid_array
[UINT8_MAX
+ 1];
2091 * Determine number of CPUs and keep track of "final" APIC ID
2092 * for each CPU by walking through ACPI MADT processor list
2094 end
= (struct madt_processor
*)(tp
->hdr
.len
+ (uintptr_t)tp
);
2097 if (cpu
->type
== MADT_PROCESSOR
) {
2098 if (cpu
->flags
& 1) {
2099 if (cpu_count
< UINT8_MAX
)
2100 cpu_apicid_array
[cpu_count
] =
2104 cpu_possible_count
++;
2107 cpu
= (struct madt_processor
*)
2108 (cpu
->len
+ (uintptr_t)cpu
);
2112 * Make boot property for array of "final" APIC IDs for each
2115 bsetprop(BP_CPU_APICID_ARRAY
, strlen(BP_CPU_APICID_ARRAY
),
2116 cpu_apicid_array
, cpu_count
* sizeof (uint8_t));
2120 * Check whehter property plat-max-ncpus is already set.
2122 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2124 * Set plat-max-ncpus to number of maximum possible CPUs given
2125 * in MADT if it hasn't been set.
2126 * There's no formal way to detect max possible CPUs supported
2127 * by platform according to ACPI spec3.0b. So current CPU
2128 * hotplug implementation expects that all possible CPUs will
2129 * have an entry in MADT table and set plat-max-ncpus to number
2130 * of entries in MADT.
2131 * With introducing of ACPI4.0, Maximum System Capability Table
2132 * (MSCT) provides maximum number of CPUs supported by platform.
2133 * If MSCT is unavailable, fall back to old way.
2136 bsetpropsi(PLAT_MAX_NCPUS_NAME
, cpu_possible_count
);
2140 * Set boot property boot-max-ncpus to number of CPUs existing at
2141 * boot time. boot-max-ncpus is mainly used for optimization.
2144 bsetpropsi(BOOT_MAX_NCPUS_NAME
, cpu_count
);
2147 * User-set boot-ncpus overrides firmware count
2149 if (do_bsys_getproplen(NULL
, BOOT_NCPUS_NAME
) >= 0)
2153 * Set boot property boot-ncpus to number of active CPUs given in MADT
2154 * if it hasn't been set yet.
2157 bsetpropsi(BOOT_NCPUS_NAME
, cpu_count
);
2161 process_srat(struct srat
*tp
)
2163 struct srat_item
*item
, *end
;
2165 int proc_num
, mem_num
;
2184 uint64_t maxmem
= 0;
2189 proc_num
= mem_num
= 0;
2190 end
= (struct srat_item
*)(tp
->hdr
.len
+ (uintptr_t)tp
);
2192 while (item
< end
) {
2193 switch (item
->type
) {
2194 case SRAT_PROCESSOR
:
2195 if (!(item
->i
.p
.flags
& SRAT_ENABLED
))
2197 processor
.domain
= item
->i
.p
.domain1
;
2198 for (i
= 0; i
< 3; i
++)
2200 item
->i
.p
.domain2
[i
] << ((i
+ 1) * 8);
2201 processor
.apic_id
= item
->i
.p
.apic_id
;
2202 processor
.sapic_id
= item
->i
.p
.local_sapic_eid
;
2203 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2205 bsetprop(prop_name
, strlen(prop_name
), &processor
,
2206 sizeof (processor
));
2210 if (!(item
->i
.m
.flags
& SRAT_ENABLED
))
2212 memory
.domain
= item
->i
.m
.domain
;
2213 memory
.addr
= item
->i
.m
.base_addr
;
2214 memory
.length
= item
->i
.m
.len
;
2215 memory
.flags
= item
->i
.m
.flags
;
2216 (void) snprintf(prop_name
, 30, "acpi-srat-memory-%d",
2218 bsetprop(prop_name
, strlen(prop_name
), &memory
,
2220 if ((item
->i
.m
.flags
& SRAT_HOT_PLUG
) &&
2221 (memory
.addr
+ memory
.length
> maxmem
)) {
2222 maxmem
= memory
.addr
+ memory
.length
;
2227 if (!(item
->i
.xp
.flags
& SRAT_ENABLED
))
2229 x2apic
.domain
= item
->i
.xp
.domain
;
2230 x2apic
.x2apic_id
= item
->i
.xp
.x2apic_id
;
2231 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2233 bsetprop(prop_name
, strlen(prop_name
), &x2apic
,
2239 item
= (struct srat_item
*)
2240 (item
->len
+ (caddr_t
)item
);
2244 * The maximum physical address calculated from the SRAT table is more
2245 * accurate than that calculated from the MSCT table.
2248 plat_dr_physmax
= btop(maxmem
);
2253 process_slit(struct slit
*tp
)
2257 * Check the number of localities; if it's too huge, we just
2258 * return and locality enumeration code will handle this later,
2261 * Note that the size of the table is the square of the
2262 * number of localities; if the number of localities exceeds
2263 * UINT16_MAX, the table size may overflow an int when being
2264 * passed to bsetprop() below.
2266 if (tp
->number
>= SLIT_LOCALITIES_MAX
)
2269 bsetprop(SLIT_NUM_PROPNAME
, strlen(SLIT_NUM_PROPNAME
), &tp
->number
,
2270 sizeof (tp
->number
));
2271 bsetprop(SLIT_PROPNAME
, strlen(SLIT_PROPNAME
), &tp
->entry
,
2272 tp
->number
* tp
->number
);
2275 static struct msct
*
2276 process_msct(struct msct
*tp
)
2280 struct msct_proximity_domain
*item
, *end
;
2281 extern uint64_t plat_dr_options
;
2285 end
= (void *)(tp
->hdr
.len
+ (uintptr_t)tp
);
2286 for (item
= (void *)((uintptr_t)tp
+ tp
->proximity_domain_offset
);
2288 item
= (void *)(item
->length
+ (uintptr_t)item
)) {
2290 * Sanity check according to section 5.2.19.1 of ACPI 4.0.
2294 if (item
->revision
!= 1 || item
->length
!= 22) {
2296 "?boot: unknown proximity domain structure in MSCT "
2297 "with rev(%d), len(%d).\n",
2298 (int)item
->revision
, (int)item
->length
);
2300 } else if (item
->domain_min
> item
->domain_max
) {
2302 "?boot: invalid proximity domain structure in MSCT "
2303 "with domain_min(%u), domain_max(%u).\n",
2304 item
->domain_min
, item
->domain_max
);
2306 } else if (item
->domain_min
!= last_seen
) {
2308 * Items must be organized in ascending order of the
2309 * proximity domain enumerations.
2312 "?boot: invalid proximity domain structure in MSCT,"
2313 " items are not orginized in ascending order.\n");
2318 * If processor_max is 0 then there would be no CPUs in this
2321 if (item
->processor_max
!= 0) {
2322 proc_num
+= (item
->domain_max
- item
->domain_min
+ 1) *
2323 item
->processor_max
;
2326 last_seen
= item
->domain_max
- item
->domain_min
+ 1;
2328 * Break out if all proximity domains have been processed.
2329 * Some BIOSes may have unused items at the end of MSCT table.
2331 if (last_seen
> tp
->maximum_proximity_domains
) {
2335 if (last_seen
!= tp
->maximum_proximity_domains
+ 1) {
2337 "?boot: invalid proximity domain structure in MSCT, "
2338 "proximity domain count doesn't match.\n");
2343 * Set plat-max-ncpus property if it hasn't been set yet.
2345 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2346 if (proc_num
!= 0) {
2347 bsetpropsi(PLAT_MAX_NCPUS_NAME
, proc_num
);
2352 * Use Maximum Physical Address from the MSCT table as upper limit for
2353 * memory hot-adding by default. It may be overridden by value from
2354 * the SRAT table or the "plat-dr-physmax" boot option.
2356 plat_dr_physmax
= btop(tp
->maximum_physical_address
+ 1);
2359 * Existence of MSCT implies CPU/memory hotplug-capability for the
2362 plat_dr_options
|= PLAT_DR_FEATURE_CPU
;
2363 plat_dr_options
|= PLAT_DR_FEATURE_MEMORY
;
2370 enumerate_xen_cpus()
2372 processorid_t id
, max_id
;
2375 * User-set boot-ncpus overrides enumeration
2377 if (do_bsys_getproplen(NULL
, BOOT_NCPUS_NAME
) >= 0)
2381 * Probe every possible virtual CPU id and remember the
2382 * highest id present; the count of CPUs is one greater
2383 * than this. This tacitly assumes at least cpu 0 is present.
2386 for (id
= 0; id
< MAX_VIRT_CPUS
; id
++)
2387 if (HYPERVISOR_vcpu_op(VCPUOP_is_up
, id
, NULL
) == 0)
2390 bsetpropsi(BOOT_NCPUS_NAME
, max_id
+1);
2396 build_firmware_properties(void)
2398 struct table_header
*tp
= NULL
;
2401 if ((msct_ptr
= (struct msct
*)find_fw_table("MSCT")) != NULL
)
2402 msct_ptr
= process_msct(msct_ptr
);
2404 if ((tp
= find_fw_table("APIC")) != NULL
)
2405 process_madt((struct madt
*)tp
);
2407 if ((srat_ptr
= (struct srat
*)find_fw_table("SRAT")) != NULL
)
2408 process_srat(srat_ptr
);
2410 if (slit_ptr
= (struct slit
*)find_fw_table("SLIT"))
2411 process_slit(slit_ptr
);
2413 tp
= find_fw_table("MCFG");
2415 enumerate_xen_cpus();
2416 if (DOMAIN_IS_INITDOMAIN(xen_info
))
2417 tp
= find_fw_table("MCFG");
2420 process_mcfg((struct mcfg
*)tp
);
2424 * fake up a boot property for deferred early console output
2425 * this is used by both graphical boot and the (developer only)
2426 * USB serial console
2429 defcons_init(size_t size
)
2431 static char *p
= NULL
;
2433 p
= do_bsys_alloc(NULL
, NULL
, size
, MMU_PAGESIZE
);
2435 bsetprop("deferred-console-buf", strlen("deferred-console-buf") + 1,
2442 boot_compinfo(int fd
, struct compinfo
*cbp
)
2445 cbp
->blksize
= MAXBSIZE
;
2449 #define BP_MAX_STRLEN 32
2452 * Get value for given boot property
2455 bootprop_getval(const char *prop_name
, u_longlong_t
*prop_value
)
2458 char str
[BP_MAX_STRLEN
];
2461 boot_prop_len
= BOP_GETPROPLEN(bootops
, prop_name
);
2462 if (boot_prop_len
< 0 || boot_prop_len
> sizeof (str
) ||
2463 BOP_GETPROP(bootops
, prop_name
, str
) < 0 ||
2464 kobj_getvalue(str
, &value
) == -1)
2468 *prop_value
= value
;