4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2010, Intel Corporation.
27 * All rights reserved.
29 * Copyright 2018 Joyent, Inc. All rights reserved.
33 * This file contains the functionality that mimics the boot operations
34 * on SPARC systems or the old boot.bin/multiboot programs on x86 systems.
35 * The x86 kernel now does everything on its own.
38 #include <sys/types.h>
39 #include <sys/bootconf.h>
40 #include <sys/bootsvcs.h>
41 #include <sys/bootinfo.h>
42 #include <sys/multiboot.h>
43 #include <sys/multiboot2.h>
44 #include <sys/multiboot2_impl.h>
45 #include <sys/bootvfs.h>
46 #include <sys/bootprops.h>
47 #include <sys/varargs.h>
48 #include <sys/param.h>
49 #include <sys/machparam.h>
50 #include <sys/machsystm.h>
51 #include <sys/archsystm.h>
52 #include <sys/boot_console.h>
53 #include <sys/cmn_err.h>
54 #include <sys/systm.h>
55 #include <sys/promif.h>
56 #include <sys/archsystm.h>
57 #include <sys/x86_archext.h>
59 #include <sys/privregs.h>
60 #include <sys/sysmacros.h>
61 #include <sys/ctype.h>
62 #include <sys/fastboot.h>
63 #include <vm/kboot_mmu.h>
64 #include <vm/hat_pte.h>
66 #include <sys/kobj_lex.h>
67 #include <sys/pci_cfgspace_impl.h>
68 #include <sys/fastboot_impl.h>
69 #include <sys/acpi/acconfig.h>
70 #include <sys/acpi/acpi.h>
71 #include <sys/ddipropdefs.h> /* For DDI prop types */
73 static int have_console
= 0; /* set once primitive console is initialized */
74 static char *boot_args
= "";
79 static uint_t kbm_debug
= 0;
80 #define DBG_MSG(s) { if (kbm_debug) bop_printf(NULL, "%s", s); }
81 #define DBG(x) { if (kbm_debug) \
82 bop_printf(NULL, "%s is %" PRIx64 "\n", #x, (uint64_t)(x)); \
85 #define PUT_STRING(s) { \
87 for (cp = (s); *cp; ++cp) \
91 bootops_t bootop
; /* simple bootops we'll pass on to kernel */
95 * Boot info from "glue" code in low memory. xbootp is used by:
96 * do_bop_phys_alloc(), do_bsys_alloc() and boot_prop_finish().
98 static struct xboot_info
*xbootp
;
99 static uintptr_t next_virt
; /* next available virtual address */
100 static paddr_t next_phys
; /* next available physical address from dboot */
101 static paddr_t high_phys
= -(paddr_t
)1; /* last used physical address */
104 * buffer for vsnprintf for console I/O
106 #define BUFFERSIZE 512
107 static char buffer
[BUFFERSIZE
];
110 * stuff to store/report/manipulate boot property settings.
112 typedef struct bootprop
{
113 struct bootprop
*bp_next
;
115 int bp_flags
; /* DDI prop type */
116 uint_t bp_vlen
; /* 0 for boolean */
120 static bootprop_t
*bprops
= NULL
;
121 static char *curr_page
= NULL
; /* ptr to avail bprop memory */
122 static int curr_space
= 0; /* amount of memory at curr_page */
126 * some allocator statistics
128 static ulong_t total_bop_alloc_scratch
= 0;
129 static ulong_t total_bop_alloc_kernel
= 0;
131 static void build_firmware_properties(struct xboot_info
*);
133 static int early_allocation
= 1;
135 int force_fastreboot
= 0;
136 volatile int fastreboot_onpanic
= 0;
137 int post_fastreboot
= 0;
138 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 ACPI_TABLE_SRAT
*srat_ptr
= NULL
;
164 ACPI_TABLE_SLIT
*slit_ptr
= NULL
;
165 ACPI_TABLE_MSCT
*msct_ptr
= NULL
;
168 * Arbitrary limit on number of localities we handle; if
169 * this limit is raised to more than UINT16_MAX, make sure
170 * process_slit() knows how to handle it.
172 #define SLIT_LOCALITIES_MAX (4096)
174 #define SLIT_NUM_PROPNAME "acpi-slit-localities"
175 #define SLIT_PROPNAME "acpi-slit"
178 * Allocate aligned physical memory at boot time. This allocator allocates
179 * from the highest possible addresses. This avoids exhausting memory that
180 * would be useful for DMA buffers.
183 do_bop_phys_alloc(uint64_t size
, uint64_t align
)
188 struct memlist
*ml
= (struct memlist
*)xbootp
->bi_phys_install
;
191 * Be careful if high memory usage is limited in startup.c
192 * Since there are holes in the low part of the physical address
193 * space we can treat physmem as a pfn (not just a pgcnt) and
194 * get a conservative upper limit.
196 if (physmem
!= 0 && high_phys
> pfn_to_pa(physmem
))
197 high_phys
= pfn_to_pa(physmem
);
200 * find the highest available memory in physinstalled
202 size
= P2ROUNDUP(size
, align
);
203 for (; ml
; ml
= ml
->ml_next
) {
204 start
= P2ROUNDUP(ml
->ml_address
, align
);
205 end
= P2ALIGN(ml
->ml_address
+ ml
->ml_size
, align
);
206 if (start
< next_phys
)
207 start
= P2ROUNDUP(next_phys
, align
);
209 end
= P2ALIGN(high_phys
, align
);
213 if (end
- start
< size
)
217 * Early allocations need to use low memory, since
218 * physmem might be further limited by bootenv.rc
220 if (early_allocation
) {
221 if (pa
== 0 || start
< pa
)
229 if (early_allocation
)
230 next_phys
= pa
+ size
;
235 bop_panic("do_bop_phys_alloc(0x%" PRIx64
", 0x%" PRIx64
236 ") Out of memory\n", size
, align
);
241 alloc_vaddr(size_t size
, paddr_t align
)
245 next_virt
= P2ROUNDUP(next_virt
, (uintptr_t)align
);
246 rv
= (uintptr_t)next_virt
;
252 * Allocate virtual memory. The size is always rounded up to a multiple
258 do_bsys_alloc(bootops_t
*bop
, caddr_t virthint
, size_t size
, int align
)
260 paddr_t a
= align
; /* same type as pa for masking */
264 ssize_t s
; /* the aligned size */
266 uint_t is_kernel
= (virthint
!= 0);
268 if (a
< MMU_PAGESIZE
)
271 prom_panic("do_bsys_alloc() incorrect alignment");
272 size
= P2ROUNDUP(size
, MMU_PAGESIZE
);
275 * Use the next aligned virtual address if we weren't given one.
277 if (virthint
== NULL
) {
278 virthint
= (caddr_t
)alloc_vaddr(size
, a
);
279 total_bop_alloc_scratch
+= size
;
281 total_bop_alloc_kernel
+= size
;
285 * allocate the physical memory
287 pa
= do_bop_phys_alloc(size
, a
);
290 * Add the mappings to the page tables, try large pages first.
292 va
= (uintptr_t)virthint
;
295 pgsize
= xbootp
->bi_use_pae
? TWO_MEG
: FOUR_MEG
;
296 if (xbootp
->bi_use_largepage
&& a
== pgsize
) {
297 while (IS_P2ALIGNED(pa
, pgsize
) && IS_P2ALIGNED(va
, pgsize
) &&
299 kbm_map(va
, pa
, level
, is_kernel
);
307 * Map remaining pages use small mappings
310 pgsize
= MMU_PAGESIZE
;
312 kbm_map(va
, pa
, level
, is_kernel
);
321 * Free virtual memory - we'll just ignore these.
325 do_bsys_free(bootops_t
*bop
, caddr_t virt
, size_t size
)
327 bop_printf(NULL
, "do_bsys_free(virt=0x%p, size=0x%lx) ignored\n",
336 do_bsys_ealloc(bootops_t
*bop
, caddr_t virthint
, size_t size
,
337 int align
, int flags
)
339 prom_panic("unsupported call to BOP_EALLOC()\n");
345 bsetprop(int flags
, char *name
, int nlen
, void *value
, int vlen
)
352 * align the size to 16 byte boundary
354 size
= sizeof (bootprop_t
) + nlen
+ 1 + vlen
;
355 size
= (size
+ 0xf) & ~0xf;
356 if (size
> curr_space
) {
357 need_size
= (size
+ (MMU_PAGEOFFSET
)) & MMU_PAGEMASK
;
358 curr_page
= do_bsys_alloc(NULL
, 0, need_size
, MMU_PAGESIZE
);
359 curr_space
= need_size
;
363 * use a bootprop_t at curr_page and link into list
365 b
= (bootprop_t
*)curr_page
;
366 curr_page
+= sizeof (bootprop_t
);
367 curr_space
-= sizeof (bootprop_t
);
372 * follow by name and ending zero byte
374 b
->bp_name
= curr_page
;
375 bcopy(name
, curr_page
, nlen
);
378 curr_space
-= nlen
+ 1;
381 * set the property type
383 b
->bp_flags
= flags
& DDI_PROP_TYPE_MASK
;
386 * copy in value, but no ending zero byte
388 b
->bp_value
= curr_page
;
391 bcopy(value
, curr_page
, vlen
);
397 * align new values of curr_page, curr_space
399 while (curr_space
& 0xf) {
406 bsetprops(char *name
, char *value
)
408 bsetprop(DDI_PROP_TYPE_STRING
, name
, strlen(name
),
409 value
, strlen(value
) + 1);
413 bsetprop32(char *name
, uint32_t value
)
415 bsetprop(DDI_PROP_TYPE_INT
, name
, strlen(name
),
416 (void *)&value
, sizeof (value
));
420 bsetprop64(char *name
, uint64_t value
)
422 bsetprop(DDI_PROP_TYPE_INT64
, name
, strlen(name
),
423 (void *)&value
, sizeof (value
));
427 bsetpropsi(char *name
, int value
)
431 (void) snprintf(prop_val
, sizeof (prop_val
), "%d", value
);
432 bsetprops(name
, prop_val
);
436 * to find the type of the value associated with this name
440 do_bsys_getproptype(bootops_t
*bop
, const char *name
)
444 for (b
= bprops
; b
!= NULL
; b
= b
->bp_next
) {
445 if (strcmp(name
, b
->bp_name
) != 0)
447 return (b
->bp_flags
);
453 * to find the size of the buffer to allocate
457 do_bsys_getproplen(bootops_t
*bop
, const char *name
)
461 for (b
= bprops
; b
; b
= b
->bp_next
) {
462 if (strcmp(name
, b
->bp_name
) != 0)
470 * get the value associated with this name
474 do_bsys_getprop(bootops_t
*bop
, const char *name
, void *value
)
478 for (b
= bprops
; b
; b
= b
->bp_next
) {
479 if (strcmp(name
, b
->bp_name
) != 0)
481 bcopy(b
->bp_value
, value
, b
->bp_vlen
);
488 * get the name of the next property in succession from the standalone
492 do_bsys_nextprop(bootops_t
*bop
, char *name
)
497 * A null name is a special signal for the 1st boot property
499 if (name
== NULL
|| strlen(name
) == 0) {
502 return (bprops
->bp_name
);
505 for (b
= bprops
; b
; b
= b
->bp_next
) {
506 if (name
!= b
->bp_name
)
517 * Parse numeric value from a string. Understands decimal, hex, octal, - and ~
520 parse_value(char *p
, uint64_t *retval
)
528 if (*p
== '-' || *p
== '~')
535 if (*p
== 'x' || *p
== 'X') {
544 if ('0' <= *p
&& *p
<= '9')
546 else if ('a' <= *p
&& *p
<= 'f')
547 digit
= 10 + *p
- 'a';
548 else if ('A' <= *p
&& *p
<= 'F')
549 digit
= 10 + *p
- 'A';
554 tmp
= tmp
* radix
+ digit
;
559 else if (adjust
== '~')
566 unprintable(char *value
, int size
)
570 if (size
<= 0 || value
[0] == '\0')
573 for (i
= 0; i
< size
; i
++) {
574 if (value
[i
] == '\0')
575 return (i
!= (size
- 1));
577 if (!isprint(value
[i
]))
584 * Print out information about all boot properties.
585 * buffer is pointer to pre-allocated space to be used as temporary
586 * space for property values.
589 boot_prop_display(char *buffer
)
592 int i
, len
, flags
, *buf32
;
595 bop_printf(NULL
, "\nBoot properties:\n");
597 while ((name
= do_bsys_nextprop(NULL
, name
)) != NULL
) {
598 bop_printf(NULL
, "\t0x%p %s = ", (void *)name
, name
);
599 (void) do_bsys_getprop(NULL
, name
, buffer
);
600 len
= do_bsys_getproplen(NULL
, name
);
601 flags
= do_bsys_getproptype(NULL
, name
);
602 bop_printf(NULL
, "len=%d ", len
);
605 case DDI_PROP_TYPE_INT
:
606 len
= len
/ sizeof (int);
607 buf32
= (int *)buffer
;
608 for (i
= 0; i
< len
; i
++) {
609 bop_printf(NULL
, "%08x", buf32
[i
]);
611 bop_printf(NULL
, ".");
614 case DDI_PROP_TYPE_STRING
:
615 bop_printf(NULL
, "%s", buffer
);
617 case DDI_PROP_TYPE_INT64
:
618 len
= len
/ sizeof (int64_t);
619 buf64
= (int64_t *)buffer
;
620 for (i
= 0; i
< len
; i
++) {
621 bop_printf(NULL
, "%016" PRIx64
, buf64
[i
]);
623 bop_printf(NULL
, ".");
627 if (!unprintable(buffer
, len
)) {
629 bop_printf(NULL
, "%s", buffer
);
632 for (i
= 0; i
< len
; i
++) {
633 bop_printf(NULL
, "%02x", buffer
[i
] & 0xff);
635 bop_printf(NULL
, ".");
639 bop_printf(NULL
, "\n");
644 * 2nd part of building the table of boot properties. This includes:
645 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
647 * lines look like one of:
649 * ^# comment till end of line
650 * setprop name 'value'
652 * setprop name "value"
654 * we do single character I/O since this is really just looking at memory
657 boot_prop_finish(void)
667 char *inputdev
; /* these override the command line if serial ports */
672 extern int bootrd_debug
;
675 DBG_MSG("Opening /boot/solaris/bootenv.rc\n");
676 fd
= BRD_OPEN(bfs_ops
, "/boot/solaris/bootenv.rc", 0);
679 line
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
686 bytes_read
= BRD_READ(bfs_ops
, fd
, line
+ c
, 1);
687 if (bytes_read
== 0) {
698 * ignore comment lines
701 while (ISSPACE(line
[c
]))
703 if (line
[c
] == '#' || line
[c
] == 0)
707 * must have "setprop " or "setprop\t"
709 if (strncmp(line
+ c
, "setprop ", 8) != 0 &&
710 strncmp(line
+ c
, "setprop\t", 8) != 0)
713 while (ISSPACE(line
[c
]))
719 * gather up the property name
723 while (line
[c
] && !ISSPACE(line
[c
]))
727 * gather up the value, if any
731 while (ISSPACE(line
[c
]))
735 while (line
[c
] && !ISSPACE(line
[c
]))
739 if (v_len
>= 2 && value
[0] == value
[v_len
- 1] &&
740 (value
[0] == '\'' || value
[0] == '"')) {
751 * ignore "boot-file" property, it's now meaningless
753 if (strcmp(name
, "boot-file") == 0)
755 if (strcmp(name
, "boot-args") == 0 &&
756 strlen(boot_args
) > 0)
760 * If a property was explicitly set on the command line
761 * it will override a setting in bootenv.rc
763 if (do_bsys_getproplen(NULL
, name
) >= 0)
766 bsetprops(name
, value
);
770 (void) BRD_CLOSE(bfs_ops
, fd
);
773 * Check if we have to limit the boot time allocator
775 if (do_bsys_getproplen(NULL
, "physmem") != -1 &&
776 do_bsys_getprop(NULL
, "physmem", line
) >= 0 &&
777 parse_value(line
, &lvalue
) != -1) {
778 if (0 < lvalue
&& (lvalue
< physmem
|| physmem
== 0)) {
779 physmem
= (pgcnt_t
)lvalue
;
783 early_allocation
= 0;
786 * Check for bootrd_debug.
788 if (find_boot_prop("bootrd_debug"))
792 * check to see if we have to override the default value of the console
796 v_len
= do_bsys_getproplen(NULL
, "input-device");
798 (void) do_bsys_getprop(NULL
, "input-device", inputdev
);
803 outputdev
= inputdev
+ v_len
+ 1;
804 v_len
= do_bsys_getproplen(NULL
, "output-device");
806 (void) do_bsys_getprop(NULL
, "output-device",
810 outputdev
[v_len
] = 0;
812 consoledev
= outputdev
+ v_len
+ 1;
813 v_len
= do_bsys_getproplen(NULL
, "console");
815 (void) do_bsys_getprop(NULL
, "console", consoledev
);
816 if (post_fastreboot
&&
817 strcmp(consoledev
, "graphics") == 0) {
818 bsetprops("console", "text");
819 v_len
= strlen("text");
820 bcopy("text", consoledev
, v_len
);
825 consoledev
[v_len
] = 0;
826 bcons_init2(inputdev
, outputdev
, consoledev
);
829 * Ensure console property exists
830 * If not create it as "hypervisor"
832 v_len
= do_bsys_getproplen(NULL
, "console");
834 bsetprops("console", "hypervisor");
835 inputdev
= outputdev
= consoledev
= "hypervisor";
836 bcons_init2(inputdev
, outputdev
, consoledev
);
839 if (find_boot_prop("prom_debug") || kbm_debug
)
840 boot_prop_display(line
);
844 * print formatted output
849 bop_printf(bootops_t
*bop
, const char *fmt
, ...)
853 if (have_console
== 0)
857 (void) vsnprintf(buffer
, BUFFERSIZE
, fmt
, ap
);
863 * Another panic() variant; this one can be used even earlier during boot than
868 bop_panic(const char *fmt
, ...)
873 bop_printf(NULL
, fmt
, ap
);
876 bop_printf(NULL
, "\nPress any key to reboot.\n");
877 (void) bcons_getchar();
878 bop_printf(NULL
, "Resetting...\n");
883 * Do a real mode interrupt BIOS call
885 typedef struct bios_regs
{
886 unsigned short ax
, bx
, cx
, dx
, si
, di
, bp
, es
, ds
;
888 typedef int (*bios_func_t
)(int, bios_regs_t
*);
892 do_bsys_doint(bootops_t
*bop
, int intnum
, struct bop_regs
*rp
)
894 static int firsttime
= 1;
895 bios_func_t bios_func
= (bios_func_t
)(void *)(uintptr_t)0x5000;
899 * We're about to disable paging; we shouldn't be PCID enabled.
901 if (getcr4() & CR4_PCIDE
)
902 prom_panic("do_bsys_doint() with PCID enabled\n");
905 * The first time we do this, we have to copy the pre-packaged
906 * low memory bios call code image into place.
909 extern char bios_image
[];
910 extern uint32_t bios_size
;
912 bcopy(bios_image
, (void *)bios_func
, bios_size
);
916 br
.ax
= rp
->eax
.word
.ax
;
917 br
.bx
= rp
->ebx
.word
.bx
;
918 br
.cx
= rp
->ecx
.word
.cx
;
919 br
.dx
= rp
->edx
.word
.dx
;
920 br
.bp
= rp
->ebp
.word
.bp
;
921 br
.si
= rp
->esi
.word
.si
;
922 br
.di
= rp
->edi
.word
.di
;
926 DBG_MSG("Doing BIOS call...");
930 rp
->eflags
= bios_func(intnum
, &br
);
933 rp
->eax
.word
.ax
= br
.ax
;
934 rp
->ebx
.word
.bx
= br
.bx
;
935 rp
->ecx
.word
.cx
= br
.cx
;
936 rp
->edx
.word
.dx
= br
.dx
;
937 rp
->ebp
.word
.bp
= br
.bp
;
938 rp
->esi
.word
.si
= br
.si
;
939 rp
->edi
.word
.di
= br
.di
;
944 static struct boot_syscalls bop_sysp
= {
956 setup_rarp_props(struct sol_netinfo
*sip
)
958 char buf
[BUFLEN
]; /* to hold ip/mac addrs */
961 val
= (uint8_t *)&sip
->sn_ciaddr
;
962 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
963 val
[0], val
[1], val
[2], val
[3]);
964 bsetprops(BP_HOST_IP
, buf
);
966 val
= (uint8_t *)&sip
->sn_siaddr
;
967 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
968 val
[0], val
[1], val
[2], val
[3]);
969 bsetprops(BP_SERVER_IP
, buf
);
971 if (sip
->sn_giaddr
!= 0) {
972 val
= (uint8_t *)&sip
->sn_giaddr
;
973 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
974 val
[0], val
[1], val
[2], val
[3]);
975 bsetprops(BP_ROUTER_IP
, buf
);
978 if (sip
->sn_netmask
!= 0) {
979 val
= (uint8_t *)&sip
->sn_netmask
;
980 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
981 val
[0], val
[1], val
[2], val
[3]);
982 bsetprops(BP_SUBNET_MASK
, buf
);
985 if (sip
->sn_mactype
!= 4 || sip
->sn_maclen
!= 6) {
986 bop_printf(NULL
, "unsupported mac type %d, mac len %d\n",
987 sip
->sn_mactype
, sip
->sn_maclen
);
989 val
= sip
->sn_macaddr
;
990 (void) snprintf(buf
, BUFLEN
, "%x:%x:%x:%x:%x:%x",
991 val
[0], val
[1], val
[2], val
[3], val
[4], val
[5]);
992 bsetprops(BP_BOOT_MAC
, buf
);
998 build_panic_cmdline(const char *cmd
, int cmdlen
)
1003 arglen
= sizeof (fastreboot_onpanic_args
);
1005 * If we allready have fastreboot-onpanic set to zero,
1006 * don't add them again.
1008 if ((proplen
= do_bsys_getproplen(NULL
, FASTREBOOT_ONPANIC
)) > 0 &&
1009 proplen
<= sizeof (fastreboot_onpanic_cmdline
)) {
1010 (void) do_bsys_getprop(NULL
, FASTREBOOT_ONPANIC
,
1011 fastreboot_onpanic_cmdline
);
1012 if (FASTREBOOT_ONPANIC_NOTSET(fastreboot_onpanic_cmdline
))
1017 * construct fastreboot_onpanic_cmdline
1019 if (cmdlen
+ arglen
> sizeof (fastreboot_onpanic_cmdline
)) {
1020 DBG_MSG("Command line too long: clearing "
1021 FASTREBOOT_ONPANIC
"\n");
1022 fastreboot_onpanic
= 0;
1024 bcopy(cmd
, fastreboot_onpanic_cmdline
, cmdlen
);
1026 bcopy(fastreboot_onpanic_args
,
1027 fastreboot_onpanic_cmdline
+ cmdlen
, arglen
);
1029 fastreboot_onpanic_cmdline
[cmdlen
] = 0;
1035 * Construct boot command line for Fast Reboot. The saved_cmdline
1036 * is also reported by "eeprom bootcmd".
1039 build_fastboot_cmdline(struct xboot_info
*xbp
)
1041 saved_cmdline_len
= strlen(xbp
->bi_cmdline
) + 1;
1042 if (saved_cmdline_len
> FASTBOOT_SAVED_CMDLINE_LEN
) {
1043 DBG(saved_cmdline_len
);
1044 DBG_MSG("Command line too long: clearing fastreboot_capable\n");
1045 fastreboot_capable
= 0;
1047 bcopy((void *)(xbp
->bi_cmdline
), (void *)saved_cmdline
,
1049 saved_cmdline
[saved_cmdline_len
- 1] = '\0';
1050 build_panic_cmdline(saved_cmdline
, saved_cmdline_len
- 1);
1055 * Save memory layout, disk drive information, unix and boot archive sizes for
1059 save_boot_info(struct xboot_info
*xbi
)
1061 multiboot_info_t
*mbi
= xbi
->bi_mb_info
;
1062 struct boot_modules
*modp
;
1065 bcopy(mbi
, &saved_mbi
, sizeof (multiboot_info_t
));
1066 if (mbi
->mmap_length
> sizeof (saved_mmap
)) {
1067 DBG_MSG("mbi->mmap_length too big: clearing "
1068 "fastreboot_capable\n");
1069 fastreboot_capable
= 0;
1071 bcopy((void *)(uintptr_t)mbi
->mmap_addr
, (void *)saved_mmap
,
1075 if ((mbi
->flags
& MB_INFO_DRIVE_INFO
) != 0) {
1076 if (mbi
->drives_length
> sizeof (saved_drives
)) {
1077 DBG(mbi
->drives_length
);
1078 DBG_MSG("mbi->drives_length too big: clearing "
1079 "fastreboot_capable\n");
1080 fastreboot_capable
= 0;
1082 bcopy((void *)(uintptr_t)mbi
->drives_addr
,
1083 (void *)saved_drives
, mbi
->drives_length
);
1086 saved_mbi
.drives_length
= 0;
1087 saved_mbi
.drives_addr
= (uintptr_t)NULL
;
1091 * Current file sizes. Used by fastboot.c to figure out how much
1092 * memory to reserve for panic reboot.
1093 * Use the module list from the dboot-constructed xboot_info
1094 * instead of the list referenced by the multiboot structure
1095 * because that structure may not be addressable now.
1097 saved_file_size
[FASTBOOT_NAME_UNIX
] = FOUR_MEG
- PAGESIZE
;
1098 for (i
= 0, modp
= (struct boot_modules
*)(uintptr_t)xbi
->bi_modules
;
1099 i
< xbi
->bi_module_cnt
; i
++, modp
++) {
1100 saved_file_size
[FASTBOOT_NAME_BOOTARCHIVE
] += modp
->bm_size
;
1105 * Import boot environment module variables as properties, applying
1106 * blacklist filter for variables we know we will not use.
1108 * Since the environment can be relatively large, containing many variables
1109 * used only for boot loader purposes, we will use a blacklist based filter.
1110 * To keep the blacklist from growing too large, we use prefix based filtering.
1111 * This is possible because in many cases, the loader variable names are
1112 * using a structured layout.
1114 * We will not overwrite already set properties.
1116 static struct bop_blacklist
{
1117 const char *bl_name
;
1119 } bop_prop_blacklist
[] = {
1120 { "ISADIR", sizeof ("ISADIR") },
1121 { "acpi", sizeof ("acpi") },
1122 { "autoboot_delay", sizeof ("autoboot_delay") },
1123 { "autoboot_delay", sizeof ("autoboot_delay") },
1124 { "beansi_", sizeof ("beansi_") },
1125 { "beastie", sizeof ("beastie") },
1126 { "bemenu", sizeof ("bemenu") },
1127 { "boot.", sizeof ("boot.") },
1128 { "bootenv", sizeof ("bootenv") },
1129 { "currdev", sizeof ("currdev") },
1130 { "dhcp.", sizeof ("dhcp.") },
1131 { "interpret", sizeof ("interpret") },
1132 { "kernel", sizeof ("kernel") },
1133 { "loaddev", sizeof ("loaddev") },
1134 { "loader_", sizeof ("loader_") },
1135 { "module_path", sizeof ("module_path") },
1136 { "nfs.", sizeof ("nfs.") },
1137 { "pcibios", sizeof ("pcibios") },
1138 { "prompt", sizeof ("prompt") },
1139 { "smbios", sizeof ("smbios") },
1140 { "tem", sizeof ("tem") },
1141 { "twiddle_divisor", sizeof ("twiddle_divisor") },
1142 { "zfs_be", sizeof ("zfs_be") },
1146 * Match the name against prefixes in above blacklist. If the match was
1147 * found, this name is blacklisted.
1150 name_is_blacklisted(const char *name
)
1154 n
= sizeof (bop_prop_blacklist
) / sizeof (bop_prop_blacklist
[0]);
1155 for (i
= 0; i
< n
; i
++) {
1156 if (strncmp(bop_prop_blacklist
[i
].bl_name
, name
,
1157 bop_prop_blacklist
[i
].bl_name_len
- 1) == 0) {
1165 process_boot_environment(struct boot_modules
*benv
)
1167 char *env
, *ptr
, *name
, *value
;
1168 uint32_t size
, name_len
, value_len
;
1170 if (benv
== NULL
|| benv
->bm_type
!= BMT_ENV
)
1172 ptr
= env
= benv
->bm_addr
;
1173 size
= benv
->bm_size
;
1177 while (*ptr
!= '=') {
1179 if (ptr
> env
+ size
) /* Something is very wrong. */
1182 name_len
= ptr
- name
;
1183 if (sizeof (buffer
) <= name_len
)
1186 (void) strncpy(buffer
, name
, sizeof (buffer
));
1187 buffer
[name_len
] = '\0';
1192 while ((uintptr_t)ptr
- (uintptr_t)env
< size
) {
1195 value_len
= (uintptr_t)ptr
- (uintptr_t)env
;
1201 /* Did we reach the end of the module? */
1208 /* Is this property already set? */
1209 if (do_bsys_getproplen(NULL
, name
) >= 0)
1212 /* Translate netboot variables */
1213 if (strcmp(name
, "boot.netif.gateway") == 0) {
1214 bsetprops(BP_ROUTER_IP
, value
);
1217 if (strcmp(name
, "boot.netif.hwaddr") == 0) {
1218 bsetprops(BP_BOOT_MAC
, value
);
1221 if (strcmp(name
, "boot.netif.ip") == 0) {
1222 bsetprops(BP_HOST_IP
, value
);
1225 if (strcmp(name
, "boot.netif.netmask") == 0) {
1226 bsetprops(BP_SUBNET_MASK
, value
);
1229 if (strcmp(name
, "boot.netif.server") == 0) {
1230 bsetprops(BP_SERVER_IP
, value
);
1233 if (strcmp(name
, "boot.netif.server") == 0) {
1234 if (do_bsys_getproplen(NULL
, BP_SERVER_IP
) < 0)
1235 bsetprops(BP_SERVER_IP
, value
);
1238 if (strcmp(name
, "boot.nfsroot.server") == 0) {
1239 if (do_bsys_getproplen(NULL
, BP_SERVER_IP
) < 0)
1240 bsetprops(BP_SERVER_IP
, value
);
1243 if (strcmp(name
, "boot.nfsroot.path") == 0) {
1244 bsetprops(BP_SERVER_PATH
, value
);
1248 if (name_is_blacklisted(name
) == B_TRUE
)
1251 /* Create new property. */
1252 bsetprops(name
, value
);
1254 /* Avoid reading past the module end. */
1255 if (size
<= (uintptr_t)ptr
- (uintptr_t)env
)
1257 } while (*ptr
!= '\0');
1261 * 1st pass at building the table of boot properties. This includes:
1262 * - values set on the command line: -B a=x,b=y,c=z ....
1263 * - known values we just compute (ie. from xbp)
1264 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
1266 * the grub command line looked like:
1267 * kernel boot-file [-B prop=value[,prop=value]...] [boot-args]
1269 * whoami is the same as boot-file
1272 build_boot_properties(struct xboot_info
*xbp
)
1278 struct boot_modules
*bm
, *rdbm
, *benv
= NULL
;
1284 static int stdout_val
= 0;
1285 uchar_t boot_device
;
1289 * These have to be done first, so that kobj_mount_root() works
1291 DBG_MSG("Building boot properties\n");
1292 propbuf
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, 0);
1293 DBG((uintptr_t)propbuf
);
1294 if (xbp
->bi_module_cnt
> 0) {
1295 bm
= xbp
->bi_modules
;
1297 for (midx
= i
= 0; i
< xbp
->bi_module_cnt
; i
++) {
1298 if (bm
[i
].bm_type
== BMT_ROOTFS
) {
1302 if (bm
[i
].bm_type
== BMT_HASH
|| bm
[i
].bm_name
== NULL
)
1305 if (bm
[i
].bm_type
== BMT_ENV
) {
1312 (void) snprintf(modid
, sizeof (modid
),
1313 "module-name-%u", midx
);
1314 bsetprops(modid
, (char *)bm
[i
].bm_name
);
1315 (void) snprintf(modid
, sizeof (modid
),
1316 "module-addr-%u", midx
);
1317 bsetprop64(modid
, (uint64_t)(uintptr_t)bm
[i
].bm_addr
);
1318 (void) snprintf(modid
, sizeof (modid
),
1319 "module-size-%u", midx
);
1320 bsetprop64(modid
, (uint64_t)bm
[i
].bm_size
);
1324 bsetprop64("ramdisk_start",
1325 (uint64_t)(uintptr_t)rdbm
->bm_addr
);
1326 bsetprop64("ramdisk_end",
1327 (uint64_t)(uintptr_t)rdbm
->bm_addr
+ rdbm
->bm_size
);
1332 * If there are any boot time modules or hashes present, then disable
1335 if (xbp
->bi_module_cnt
> 1) {
1336 fastreboot_disable(FBNS_BOOTMOD
);
1340 * Disable fast reboot if we're using the Multiboot 2 boot protocol,
1341 * since we don't currently support MB2 info and module relocation.
1342 * Note that fast reboot will have already been disabled if multiple
1343 * modules are present, since the current implementation assumes that
1344 * we only have a single module, the boot_archive.
1346 if (xbp
->bi_mb_version
!= 1) {
1347 fastreboot_disable(FBNS_MULTIBOOT2
);
1350 DBG_MSG("Parsing command line for boot properties\n");
1351 value
= xbp
->bi_cmdline
;
1354 * allocate memory to collect boot_args into
1356 boot_arg_len
= strlen(xbp
->bi_cmdline
) + 1;
1357 boot_args
= do_bsys_alloc(NULL
, NULL
, boot_arg_len
, MMU_PAGESIZE
);
1362 while (ISSPACE(*value
))
1365 * value now points at the boot-file
1368 while (value
[value_len
] && !ISSPACE(value
[value_len
]))
1370 if (value_len
> 0) {
1372 bcopy(value
, whoami
, value_len
);
1373 whoami
[value_len
] = 0;
1374 bsetprops("boot-file", whoami
);
1376 * strip leading path stuff from whoami, so running from
1377 * PXE/miniroot makes sense.
1379 if (strstr(whoami
, "/platform/") != NULL
)
1380 whoami
= strstr(whoami
, "/platform/");
1381 bsetprops("whoami", whoami
);
1385 * Values forcibly set boot properties on the command line via -B.
1386 * Allow use of quotes in values. Other stuff goes on kernel
1389 name
= value
+ value_len
;
1390 while (*name
!= 0) {
1392 * anything not " -B" is copied to the command line
1394 if (!ISSPACE(name
[0]) || name
[1] != '-' || name
[2] != 'B') {
1395 boot_args
[boot_arg_len
++] = *name
;
1396 boot_args
[boot_arg_len
] = 0;
1402 * skip the " -B" and following white space
1405 while (ISSPACE(*name
))
1407 while (*name
&& !ISSPACE(*name
)) {
1408 value
= strstr(name
, "=");
1411 name_len
= value
- name
;
1415 for (; ; ++value_len
) {
1416 if (!value
[value_len
])
1420 * is this value quoted?
1422 if (value_len
== 0 &&
1423 (value
[0] == '\'' || value
[0] == '"')) {
1429 * In the quote accept any character,
1430 * but look for ending quote.
1433 if (value
[value_len
] == quoted
)
1439 * a comma or white space ends the value
1441 if (value
[value_len
] == ',' ||
1442 ISSPACE(value
[value_len
]))
1446 if (value_len
== 0) {
1447 bsetprop(DDI_PROP_TYPE_ANY
, name
, name_len
,
1452 if (v
[0] == v
[l
- 1] &&
1453 (v
[0] == '\'' || v
[0] == '"')) {
1457 bcopy(v
, propbuf
, l
);
1459 bsetprop(DDI_PROP_TYPE_STRING
, name
, name_len
,
1462 name
= value
+ value_len
;
1463 while (*name
== ',')
1469 * set boot-args property
1470 * 1275 name is bootargs, so set
1473 bsetprops("boot-args", boot_args
);
1474 bsetprops("bootargs", boot_args
);
1476 process_boot_environment(benv
);
1479 * Build boot command line for Fast Reboot
1481 build_fastboot_cmdline(xbp
);
1483 if (xbp
->bi_mb_version
== 1) {
1484 multiboot_info_t
*mbi
= xbp
->bi_mb_info
;
1486 struct sol_netinfo
*sip
;
1489 * set the BIOS boot device from GRUB
1494 * Save various boot information for Fast Reboot
1496 save_boot_info(xbp
);
1498 if (mbi
!= NULL
&& mbi
->flags
& MB_INFO_BOOTDEV
) {
1499 boot_device
= mbi
->boot_device
>> 24;
1500 if (boot_device
== 0x20)
1502 str
[0] = (boot_device
>> 4) + '0';
1503 str
[1] = (boot_device
& 0xf) + '0';
1505 bsetprops("bios-boot-device", str
);
1511 * In the netboot case, drives_info is overloaded with the
1512 * dhcp ack. This is not multiboot compliant and requires
1515 if (netboot
&& mbi
->drives_length
!= 0) {
1516 sip
= (struct sol_netinfo
*)(uintptr_t)mbi
->drives_addr
;
1517 if (sip
->sn_infotype
== SN_TYPE_BOOTP
)
1518 bsetprop(DDI_PROP_TYPE_BYTE
,
1520 sizeof ("bootp-response"),
1521 (void *)(uintptr_t)mbi
->drives_addr
,
1522 mbi
->drives_length
);
1523 else if (sip
->sn_infotype
== SN_TYPE_RARP
)
1524 setup_rarp_props(sip
);
1527 multiboot2_info_header_t
*mbi
= xbp
->bi_mb_info
;
1528 multiboot_tag_bootdev_t
*bootdev
= NULL
;
1529 multiboot_tag_network_t
*netdev
= NULL
;
1532 bootdev
= dboot_multiboot2_find_tag(mbi
,
1533 MULTIBOOT_TAG_TYPE_BOOTDEV
);
1534 netdev
= dboot_multiboot2_find_tag(mbi
,
1535 MULTIBOOT_TAG_TYPE_NETWORK
);
1537 if (bootdev
!= NULL
) {
1538 DBG(bootdev
->mb_biosdev
);
1539 boot_device
= bootdev
->mb_biosdev
;
1540 str
[0] = (boot_device
>> 4) + '0';
1541 str
[1] = (boot_device
& 0xf) + '0';
1543 bsetprops("bios-boot-device", str
);
1545 if (netdev
!= NULL
) {
1546 bsetprop(DDI_PROP_TYPE_BYTE
,
1547 "bootp-response", sizeof ("bootp-response"),
1548 (void *)(uintptr_t)netdev
->mb_dhcpack
,
1550 sizeof (multiboot_tag_network_t
));
1554 bsetprop32("stdout", stdout_val
);
1557 * more conjured up values for made up things....
1559 bsetprops("mfg-name", "i86pc");
1560 bsetprops("impl-arch-name", "i86pc");
1563 * Build firmware-provided system properties
1565 build_firmware_properties(xbp
);
1570 * Find out what these are:
1571 * - cpuid_feature_ecx_include
1572 * - cpuid_feature_ecx_exclude
1573 * - cpuid_feature_edx_include
1574 * - cpuid_feature_edx_exclude
1576 * Find out what these are in multiboot:
1584 * simple description of a stack frame (args are 32 bit only currently)
1586 typedef struct bop_frame
{
1587 struct bop_frame
*old_frame
;
1593 bop_traceback(bop_frame_t
*frame
)
1600 bop_printf(NULL
, "Stack traceback:\n");
1601 for (cnt
= 0; cnt
< 30; ++cnt
) { /* up to 30 frames */
1602 pc
= frame
->retaddr
;
1605 ksym
= kobj_getsymname(pc
, &off
);
1607 bop_printf(NULL
, " %s+%lx", ksym
, off
);
1609 bop_printf(NULL
, " 0x%lx", pc
);
1611 frame
= frame
->old_frame
;
1613 bop_printf(NULL
, "\n");
1616 bop_printf(NULL
, "\n");
1621 ulong_t error_code
; /* optional */
1630 bop_trap(ulong_t
*tfp
)
1632 struct trapframe
*tf
= (struct trapframe
*)tfp
;
1633 bop_frame_t fakeframe
;
1634 static int depth
= 0;
1637 * Check for an infinite loop of traps.
1640 bop_panic("Nested trap");
1642 bop_printf(NULL
, "Unexpected trap\n");
1645 * adjust the tf for optional error_code by detecting the code selector
1647 if (tf
->code_seg
!= B64CODE_SEL
)
1648 tf
= (struct trapframe
*)(tfp
- 1);
1650 bop_printf(NULL
, "error code 0x%lx\n",
1651 tf
->error_code
& 0xffffffff);
1653 bop_printf(NULL
, "instruction pointer 0x%lx\n", tf
->inst_ptr
);
1654 bop_printf(NULL
, "code segment 0x%lx\n", tf
->code_seg
& 0xffff);
1655 bop_printf(NULL
, "flags register 0x%lx\n", tf
->flags_reg
);
1656 bop_printf(NULL
, "return %%rsp 0x%lx\n", tf
->stk_ptr
);
1657 bop_printf(NULL
, "return %%ss 0x%lx\n", tf
->stk_seg
& 0xffff);
1659 /* grab %[er]bp pushed by our code from the stack */
1660 fakeframe
.old_frame
= (bop_frame_t
*)*(tfp
- 3);
1661 fakeframe
.retaddr
= (pc_t
)tf
->inst_ptr
;
1662 bop_printf(NULL
, "Attempting stack backtrace:\n");
1663 bop_traceback(&fakeframe
);
1664 bop_panic("unexpected trap in early boot");
1667 extern void bop_trap_handler(void);
1669 static gate_desc_t
*bop_idt
;
1671 static desctbr_t bop_idt_info
;
1674 * Install a temporary IDT that lets us catch errors in the boot time code.
1675 * We shouldn't get any faults at all while this is installed, so we'll
1676 * just generate a traceback and exit.
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 (64-bit).
1691 set_gatesegd(&bop_idt
[t
], &bop_trap_handler
, B64CODE_SEL
,
1692 SDT_SYSIGT
, TRP_KPL
, 0);
1694 bop_idt_info
.dtr_limit
= (NIDT
* sizeof (gate_desc_t
)) - 1;
1695 bop_idt_info
.dtr_base
= (uintptr_t)bop_idt
;
1696 wr_idtr(&bop_idt_info
);
1700 * This is where we enter the kernel. It dummies up the boot_ops and
1701 * boot_syscalls vectors and jumps off to _kobj_boot()
1704 _start(struct xboot_info
*xbp
)
1706 bootops_t
*bops
= &bootop
;
1707 extern void _kobj_boot();
1710 * 1st off - initialize the console for any error messages
1714 if (*((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) ==
1716 post_fastreboot
= 1;
1717 *((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) = 0;
1726 if (find_boot_prop("kbm_debug") != NULL
)
1729 DBG_MSG("\n\n*** Entered Solaris in _start() cmdline is: ");
1730 DBG_MSG((char *)xbp
->bi_cmdline
);
1734 * physavail is no longer used by startup
1736 bm
.physinstalled
= xbp
->bi_phys_install
;
1737 bm
.pcimem
= xbp
->bi_pcimem
;
1738 bm
.rsvdmem
= xbp
->bi_rsvdmem
;
1739 bm
.physavail
= NULL
;
1742 * initialize the boot time allocator
1744 next_phys
= xbp
->bi_next_paddr
;
1746 next_virt
= (uintptr_t)xbp
->bi_next_vaddr
;
1748 DBG_MSG("Initializing boot time memory management...");
1753 * Fill in the bootops vector
1755 bops
->bsys_version
= BO_VERSION
;
1756 bops
->boot_mem
= &bm
;
1757 bops
->bsys_alloc
= do_bsys_alloc
;
1758 bops
->bsys_free
= do_bsys_free
;
1759 bops
->bsys_getproplen
= do_bsys_getproplen
;
1760 bops
->bsys_getprop
= do_bsys_getprop
;
1761 bops
->bsys_nextprop
= do_bsys_nextprop
;
1762 bops
->bsys_printf
= bop_printf
;
1763 bops
->bsys_doint
= do_bsys_doint
;
1766 * BOP_EALLOC() is no longer needed
1768 bops
->bsys_ealloc
= do_bsys_ealloc
;
1772 * Install an IDT to catch early pagefaults (shouldn't have any).
1773 * Also needed for kmdb.
1778 * Start building the boot properties from the command line
1780 DBG_MSG("Initializing boot properties:\n");
1781 build_boot_properties(xbp
);
1783 if (find_boot_prop("prom_debug") || kbm_debug
) {
1786 value
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
1787 boot_prop_display(value
);
1791 * jump into krtld...
1793 _kobj_boot(&bop_sysp
, NULL
, bops
, NULL
);
1799 no_more_alloc(bootops_t
*bop
, caddr_t virthint
, size_t size
, int align
)
1801 panic("Attempt to bsys_alloc() too late\n");
1807 no_more_free(bootops_t
*bop
, caddr_t virt
, size_t size
)
1809 panic("Attempt to bsys_free() too late\n");
1813 bop_no_more_mem(void)
1815 DBG(total_bop_alloc_scratch
);
1816 DBG(total_bop_alloc_kernel
);
1817 bootops
->bsys_alloc
= no_more_alloc
;
1818 bootops
->bsys_free
= no_more_free
;
1823 * Set ACPI firmware properties
1827 vmap_phys(size_t length
, paddr_t pa
)
1833 start
= P2ALIGN(pa
, MMU_PAGESIZE
);
1834 end
= P2ROUNDUP(pa
+ length
, MMU_PAGESIZE
);
1836 va
= (caddr_t
)alloc_vaddr(len
, MMU_PAGESIZE
);
1837 for (page
= 0; page
< len
; page
+= MMU_PAGESIZE
)
1838 kbm_map((uintptr_t)va
+ page
, start
+ page
, 0, 0);
1839 return (va
+ (pa
& MMU_PAGEOFFSET
));
1843 checksum_table(uint8_t *tp
, size_t len
)
1854 valid_rsdp(ACPI_TABLE_RSDP
*rp
)
1857 /* validate the V1.x checksum */
1858 if (checksum_table((uint8_t *)rp
, ACPI_RSDP_CHECKSUM_LENGTH
) != 0)
1861 /* If pre-ACPI 2.0, this is a valid RSDP */
1862 if (rp
->Revision
< 2)
1865 /* validate the V2.x checksum */
1866 if (checksum_table((uint8_t *)rp
, ACPI_RSDP_XCHECKSUM_LENGTH
) != 0)
1873 * Scan memory range for an RSDP;
1874 * see ACPI 3.0 Spec, 5.2.5.1
1876 static ACPI_TABLE_RSDP
*
1877 scan_rsdp(paddr_t start
, paddr_t end
)
1879 ssize_t len
= end
- start
;
1882 ptr
= vmap_phys(len
, start
);
1884 if (strncmp(ptr
, ACPI_SIG_RSDP
, strlen(ACPI_SIG_RSDP
)) == 0 &&
1885 valid_rsdp((ACPI_TABLE_RSDP
*)ptr
))
1886 return ((ACPI_TABLE_RSDP
*)ptr
);
1888 ptr
+= ACPI_RSDP_SCAN_STEP
;
1889 len
-= ACPI_RSDP_SCAN_STEP
;
1896 * Refer to ACPI 3.0 Spec, section 5.2.5.1 to understand this function
1898 static ACPI_TABLE_RSDP
*
1901 ACPI_TABLE_RSDP
*rsdp
;
1902 uint64_t rsdp_val
= 0;
1906 /* check for "acpi-root-tab" property */
1907 if (do_bsys_getproplen(NULL
, "acpi-root-tab") == sizeof (uint64_t)) {
1908 (void) do_bsys_getprop(NULL
, "acpi-root-tab", &rsdp_val
);
1909 if (rsdp_val
!= 0) {
1910 rsdp
= scan_rsdp(rsdp_val
, rsdp_val
+ sizeof (*rsdp
));
1914 "Using RSDP from bootloader: "
1915 "0x%p\n", (void *)rsdp
);
1923 * Get the EBDA segment and scan the first 1K
1925 ebda_seg
= (uint16_t *)vmap_phys(sizeof (uint16_t),
1926 ACPI_EBDA_PTR_LOCATION
);
1927 ebda_addr
= *ebda_seg
<< 4;
1928 rsdp
= scan_rsdp(ebda_addr
, ebda_addr
+ ACPI_EBDA_WINDOW_SIZE
);
1930 /* if EBDA doesn't contain RSDP, look in BIOS memory */
1931 rsdp
= scan_rsdp(ACPI_HI_RSDP_WINDOW_BASE
,
1932 ACPI_HI_RSDP_WINDOW_BASE
+ ACPI_HI_RSDP_WINDOW_SIZE
);
1936 static ACPI_TABLE_HEADER
*
1937 map_fw_table(paddr_t table_addr
)
1939 ACPI_TABLE_HEADER
*tp
;
1940 size_t len
= MAX(sizeof (*tp
), MMU_PAGESIZE
);
1943 * Map at least a page; if the table is larger than this, remap it
1945 tp
= (ACPI_TABLE_HEADER
*)vmap_phys(len
, table_addr
);
1946 if (tp
->Length
> len
)
1947 tp
= (ACPI_TABLE_HEADER
*)vmap_phys(tp
->Length
, table_addr
);
1951 static ACPI_TABLE_HEADER
*
1952 find_fw_table(char *signature
)
1954 static int revision
= 0;
1955 static ACPI_TABLE_XSDT
*xsdt
;
1958 ACPI_TABLE_RSDP
*rsdp
;
1959 ACPI_TABLE_HEADER
*tp
;
1963 if (strlen(signature
) != ACPI_NAME_SIZE
)
1967 * Reading the ACPI 3.0 Spec, section 5.2.5.3 will help
1968 * understand this code. If we haven't already found the RSDT/XSDT,
1969 * revision will be 0. Find the RSDP and check the revision
1970 * to find out whether to use the RSDT or XSDT. If revision is
1971 * 0 or 1, use the RSDT and set internal revision to 1; if it is 2,
1972 * use the XSDT. If the XSDT address is 0, though, fall back to
1973 * revision 1 and use the RSDT.
1975 if (revision
== 0) {
1976 if ((rsdp
= find_rsdp()) != NULL
) {
1977 revision
= rsdp
->Revision
;
1979 * ACPI 6.0 states that current revision is 2
1980 * from acpi_table_rsdp definition:
1981 * Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+
1988 * Use the XSDT unless BIOS is buggy and
1989 * claims to be rev 2 but has a null XSDT
1992 xsdt_addr
= rsdp
->XsdtPhysicalAddress
;
1997 /* treat RSDP rev 0 as revision 1 internally */
2001 /* use the RSDT for rev 0/1 */
2002 xsdt_addr
= rsdp
->RsdtPhysicalAddress
;
2005 /* unknown revision */
2013 /* cache the XSDT info */
2014 xsdt
= (ACPI_TABLE_XSDT
*)map_fw_table(xsdt_addr
);
2015 len
= (xsdt
->Header
.Length
- sizeof (xsdt
->Header
)) /
2016 ((revision
== 1) ? sizeof (uint32_t) : sizeof (uint64_t));
2020 * Scan the table headers looking for a signature match
2022 for (n
= 0; n
< len
; n
++) {
2023 ACPI_TABLE_RSDT
*rsdt
= (ACPI_TABLE_RSDT
*)xsdt
;
2024 table_addr
= (revision
== 1) ? rsdt
->TableOffsetEntry
[n
] :
2025 xsdt
->TableOffsetEntry
[n
];
2027 if (table_addr
== 0)
2029 tp
= map_fw_table(table_addr
);
2030 if (strncmp(tp
->Signature
, signature
, ACPI_NAME_SIZE
) == 0) {
2038 process_mcfg(ACPI_TABLE_MCFG
*tp
)
2040 ACPI_MCFG_ALLOCATION
*cfg_baap
;
2042 int64_t ecfginfo
[4];
2044 cfg_baap
= (ACPI_MCFG_ALLOCATION
*)((uintptr_t)tp
+ sizeof (*tp
));
2045 cfg_baa_endp
= ((char *)tp
) + tp
->Header
.Length
;
2046 while ((char *)cfg_baap
< cfg_baa_endp
) {
2047 if (cfg_baap
->Address
!= 0 && cfg_baap
->PciSegment
== 0) {
2048 ecfginfo
[0] = cfg_baap
->Address
;
2049 ecfginfo
[1] = cfg_baap
->PciSegment
;
2050 ecfginfo
[2] = cfg_baap
->StartBusNumber
;
2051 ecfginfo
[3] = cfg_baap
->EndBusNumber
;
2052 bsetprop(DDI_PROP_TYPE_INT64
,
2053 MCFG_PROPNAME
, strlen(MCFG_PROPNAME
),
2054 ecfginfo
, sizeof (ecfginfo
));
2062 process_madt_entries(ACPI_TABLE_MADT
*tp
, uint32_t *cpu_countp
,
2063 uint32_t *cpu_possible_countp
, uint32_t *cpu_apicid_array
)
2065 ACPI_SUBTABLE_HEADER
*item
, *end
;
2066 uint32_t cpu_count
= 0;
2067 uint32_t cpu_possible_count
= 0;
2070 * Determine number of CPUs and keep track of "final" APIC ID
2071 * for each CPU by walking through ACPI MADT processor list
2073 end
= (ACPI_SUBTABLE_HEADER
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2074 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)tp
+ sizeof (*tp
));
2076 while (item
< end
) {
2077 switch (item
->Type
) {
2078 case ACPI_MADT_TYPE_LOCAL_APIC
: {
2079 ACPI_MADT_LOCAL_APIC
*cpu
=
2080 (ACPI_MADT_LOCAL_APIC
*) item
;
2082 if (cpu
->LapicFlags
& ACPI_MADT_ENABLED
) {
2083 if (cpu_apicid_array
!= NULL
)
2084 cpu_apicid_array
[cpu_count
] = cpu
->Id
;
2087 cpu_possible_count
++;
2090 case ACPI_MADT_TYPE_LOCAL_X2APIC
: {
2091 ACPI_MADT_LOCAL_X2APIC
*cpu
=
2092 (ACPI_MADT_LOCAL_X2APIC
*) item
;
2094 if (cpu
->LapicFlags
& ACPI_MADT_ENABLED
) {
2095 if (cpu_apicid_array
!= NULL
)
2096 cpu_apicid_array
[cpu_count
] =
2100 cpu_possible_count
++;
2105 bop_printf(NULL
, "MADT type %d\n", item
->Type
);
2109 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)item
+ item
->Length
);
2112 *cpu_countp
= cpu_count
;
2113 if (cpu_possible_countp
)
2114 *cpu_possible_countp
= cpu_possible_count
;
2118 process_madt(ACPI_TABLE_MADT
*tp
)
2120 uint32_t cpu_count
= 0;
2121 uint32_t cpu_possible_count
= 0;
2122 uint32_t *cpu_apicid_array
; /* x2APIC ID is 32bit! */
2126 process_madt_entries(tp
, &cpu_count
, &cpu_possible_count
, NULL
);
2128 cpu_apicid_array
= (uint32_t *)do_bsys_alloc(NULL
, NULL
,
2129 cpu_count
* sizeof (*cpu_apicid_array
), MMU_PAGESIZE
);
2130 if (cpu_apicid_array
== NULL
)
2131 bop_panic("Not enough memory for APIC ID array");
2134 process_madt_entries(tp
, NULL
, NULL
, cpu_apicid_array
);
2137 * Make boot property for array of "final" APIC IDs for each
2140 bsetprop(DDI_PROP_TYPE_INT
,
2141 BP_CPU_APICID_ARRAY
, strlen(BP_CPU_APICID_ARRAY
),
2142 cpu_apicid_array
, cpu_count
* sizeof (*cpu_apicid_array
));
2146 * Check whether property plat-max-ncpus is already set.
2148 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2150 * Set plat-max-ncpus to number of maximum possible CPUs given
2151 * in MADT if it hasn't been set.
2152 * There's no formal way to detect max possible CPUs supported
2153 * by platform according to ACPI spec3.0b. So current CPU
2154 * hotplug implementation expects that all possible CPUs will
2155 * have an entry in MADT table and set plat-max-ncpus to number
2156 * of entries in MADT.
2157 * With introducing of ACPI4.0, Maximum System Capability Table
2158 * (MSCT) provides maximum number of CPUs supported by platform.
2159 * If MSCT is unavailable, fall back to old way.
2162 bsetpropsi(PLAT_MAX_NCPUS_NAME
, cpu_possible_count
);
2166 * Set boot property boot-max-ncpus to number of CPUs existing at
2167 * boot time. boot-max-ncpus is mainly used for optimization.
2170 bsetpropsi(BOOT_MAX_NCPUS_NAME
, cpu_count
);
2173 * User-set boot-ncpus overrides firmware count
2175 if (do_bsys_getproplen(NULL
, BOOT_NCPUS_NAME
) >= 0)
2179 * Set boot property boot-ncpus to number of active CPUs given in MADT
2180 * if it hasn't been set yet.
2183 bsetpropsi(BOOT_NCPUS_NAME
, cpu_count
);
2187 process_srat(ACPI_TABLE_SRAT
*tp
)
2189 ACPI_SUBTABLE_HEADER
*item
, *end
;
2191 int proc_num
, mem_num
;
2210 uint64_t maxmem
= 0;
2215 proc_num
= mem_num
= 0;
2216 end
= (ACPI_SUBTABLE_HEADER
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2217 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)tp
+ sizeof (*tp
));
2218 while (item
< end
) {
2219 switch (item
->Type
) {
2220 case ACPI_SRAT_TYPE_CPU_AFFINITY
: {
2221 ACPI_SRAT_CPU_AFFINITY
*cpu
=
2222 (ACPI_SRAT_CPU_AFFINITY
*) item
;
2224 if (!(cpu
->Flags
& ACPI_SRAT_CPU_ENABLED
))
2226 processor
.domain
= cpu
->ProximityDomainLo
;
2227 for (i
= 0; i
< 3; i
++)
2229 cpu
->ProximityDomainHi
[i
] << ((i
+ 1) * 8);
2230 processor
.apic_id
= cpu
->ApicId
;
2231 processor
.sapic_id
= cpu
->LocalSapicEid
;
2232 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2234 bsetprop(DDI_PROP_TYPE_INT
,
2235 prop_name
, strlen(prop_name
), &processor
,
2236 sizeof (processor
));
2240 case ACPI_SRAT_TYPE_MEMORY_AFFINITY
: {
2241 ACPI_SRAT_MEM_AFFINITY
*mem
=
2242 (ACPI_SRAT_MEM_AFFINITY
*)item
;
2244 if (!(mem
->Flags
& ACPI_SRAT_MEM_ENABLED
))
2246 memory
.domain
= mem
->ProximityDomain
;
2247 memory
.addr
= mem
->BaseAddress
;
2248 memory
.length
= mem
->Length
;
2249 memory
.flags
= mem
->Flags
;
2250 (void) snprintf(prop_name
, 30, "acpi-srat-memory-%d",
2252 bsetprop(DDI_PROP_TYPE_INT
,
2253 prop_name
, strlen(prop_name
), &memory
,
2255 if ((mem
->Flags
& ACPI_SRAT_MEM_HOT_PLUGGABLE
) &&
2256 (memory
.addr
+ memory
.length
> maxmem
)) {
2257 maxmem
= memory
.addr
+ memory
.length
;
2262 case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY
: {
2263 ACPI_SRAT_X2APIC_CPU_AFFINITY
*x2cpu
=
2264 (ACPI_SRAT_X2APIC_CPU_AFFINITY
*) item
;
2266 if (!(x2cpu
->Flags
& ACPI_SRAT_CPU_ENABLED
))
2268 x2apic
.domain
= x2cpu
->ProximityDomain
;
2269 x2apic
.x2apic_id
= x2cpu
->ApicId
;
2270 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2272 bsetprop(DDI_PROP_TYPE_INT
,
2273 prop_name
, strlen(prop_name
), &x2apic
,
2280 bop_printf(NULL
, "SRAT type %d\n", item
->Type
);
2284 item
= (ACPI_SUBTABLE_HEADER
*)
2285 (item
->Length
+ (uintptr_t)item
);
2289 * The maximum physical address calculated from the SRAT table is more
2290 * accurate than that calculated from the MSCT table.
2293 plat_dr_physmax
= btop(maxmem
);
2298 process_slit(ACPI_TABLE_SLIT
*tp
)
2302 * Check the number of localities; if it's too huge, we just
2303 * return and locality enumeration code will handle this later,
2306 * Note that the size of the table is the square of the
2307 * number of localities; if the number of localities exceeds
2308 * UINT16_MAX, the table size may overflow an int when being
2309 * passed to bsetprop() below.
2311 if (tp
->LocalityCount
>= SLIT_LOCALITIES_MAX
)
2314 bsetprop64(SLIT_NUM_PROPNAME
, tp
->LocalityCount
);
2315 bsetprop(DDI_PROP_TYPE_BYTE
,
2316 SLIT_PROPNAME
, strlen(SLIT_PROPNAME
), &tp
->Entry
,
2317 tp
->LocalityCount
* tp
->LocalityCount
);
2320 static ACPI_TABLE_MSCT
*
2321 process_msct(ACPI_TABLE_MSCT
*tp
)
2325 ACPI_MSCT_PROXIMITY
*item
, *end
;
2326 extern uint64_t plat_dr_options
;
2330 end
= (ACPI_MSCT_PROXIMITY
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2331 for (item
= (void *)((uintptr_t)tp
+ tp
->ProximityOffset
);
2333 item
= (void *)(item
->Length
+ (uintptr_t)item
)) {
2335 * Sanity check according to section 5.2.19.1 of ACPI 4.0.
2339 if (item
->Revision
!= 1 || item
->Length
!= 22) {
2341 "?boot: unknown proximity domain structure in MSCT "
2342 "with Revision(%d), Length(%d).\n",
2343 (int)item
->Revision
, (int)item
->Length
);
2345 } else if (item
->RangeStart
> item
->RangeEnd
) {
2347 "?boot: invalid proximity domain structure in MSCT "
2348 "with RangeStart(%u), RangeEnd(%u).\n",
2349 item
->RangeStart
, item
->RangeEnd
);
2351 } else if (item
->RangeStart
!= last_seen
) {
2353 * Items must be organized in ascending order of the
2354 * proximity domain enumerations.
2357 "?boot: invalid proximity domain structure in MSCT,"
2358 " items are not orginized in ascending order.\n");
2363 * If ProcessorCapacity is 0 then there would be no CPUs in this
2366 if (item
->ProcessorCapacity
!= 0) {
2367 proc_num
+= (item
->RangeEnd
- item
->RangeStart
+ 1) *
2368 item
->ProcessorCapacity
;
2371 last_seen
= item
->RangeEnd
- item
->RangeStart
+ 1;
2373 * Break out if all proximity domains have been processed.
2374 * Some BIOSes may have unused items at the end of MSCT table.
2376 if (last_seen
> tp
->MaxProximityDomains
) {
2380 if (last_seen
!= tp
->MaxProximityDomains
+ 1) {
2382 "?boot: invalid proximity domain structure in MSCT, "
2383 "proximity domain count doesn't match.\n");
2388 * Set plat-max-ncpus property if it hasn't been set yet.
2390 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2391 if (proc_num
!= 0) {
2392 bsetpropsi(PLAT_MAX_NCPUS_NAME
, proc_num
);
2397 * Use Maximum Physical Address from the MSCT table as upper limit for
2398 * memory hot-adding by default. It may be overridden by value from
2399 * the SRAT table or the "plat-dr-physmax" boot option.
2401 plat_dr_physmax
= btop(tp
->MaxAddress
+ 1);
2404 * Existence of MSCT implies CPU/memory hotplug-capability for the
2407 plat_dr_options
|= PLAT_DR_FEATURE_CPU
;
2408 plat_dr_options
|= PLAT_DR_FEATURE_MEMORY
;
2416 build_firmware_properties(struct xboot_info
*xbp
)
2418 ACPI_TABLE_HEADER
*tp
= NULL
;
2420 if (xbp
->bi_uefi_arch
== XBI_UEFI_ARCH_64
) {
2421 bsetprops("efi-systype", "64");
2422 bsetprop64("efi-systab",
2423 (uint64_t)(uintptr_t)xbp
->bi_uefi_systab
);
2425 bop_printf(NULL
, "64-bit UEFI detected.\n");
2426 } else if (xbp
->bi_uefi_arch
== XBI_UEFI_ARCH_32
) {
2427 bsetprops("efi-systype", "32");
2428 bsetprop64("efi-systab",
2429 (uint64_t)(uintptr_t)xbp
->bi_uefi_systab
);
2431 bop_printf(NULL
, "32-bit UEFI detected.\n");
2434 if (xbp
->bi_acpi_rsdp
!= NULL
) {
2435 bsetprop64("acpi-root-tab",
2436 (uint64_t)(uintptr_t)xbp
->bi_acpi_rsdp
);
2439 if (xbp
->bi_smbios
!= NULL
) {
2440 bsetprop64("smbios-address",
2441 (uint64_t)(uintptr_t)xbp
->bi_smbios
);
2444 if ((tp
= find_fw_table(ACPI_SIG_MSCT
)) != NULL
)
2445 msct_ptr
= process_msct((ACPI_TABLE_MSCT
*)tp
);
2449 if ((tp
= find_fw_table(ACPI_SIG_MADT
)) != NULL
)
2450 process_madt((ACPI_TABLE_MADT
*)tp
);
2452 if ((srat_ptr
= (ACPI_TABLE_SRAT
*)
2453 find_fw_table(ACPI_SIG_SRAT
)) != NULL
)
2454 process_srat(srat_ptr
);
2456 if (slit_ptr
= (ACPI_TABLE_SLIT
*)find_fw_table(ACPI_SIG_SLIT
))
2457 process_slit(slit_ptr
);
2459 tp
= find_fw_table(ACPI_SIG_MCFG
);
2461 process_mcfg((ACPI_TABLE_MCFG
*)tp
);
2465 * fake up a boot property for deferred early console output
2466 * this is used by both graphical boot and the (developer only)
2467 * USB serial console
2470 defcons_init(size_t size
)
2472 static char *p
= NULL
;
2474 p
= do_bsys_alloc(NULL
, NULL
, size
, MMU_PAGESIZE
);
2476 bsetprop32("deferred-console-buf", (uint32_t)((uintptr_t)&p
));
2482 boot_compinfo(int fd
, struct compinfo
*cbp
)
2485 cbp
->blksize
= MAXBSIZE
;
2489 #define BP_MAX_STRLEN 32
2492 * Get value for given boot property
2495 bootprop_getval(const char *prop_name
, u_longlong_t
*prop_value
)
2498 char str
[BP_MAX_STRLEN
];
2501 boot_prop_len
= BOP_GETPROPLEN(bootops
, prop_name
);
2502 if (boot_prop_len
< 0 || boot_prop_len
> sizeof (str
) ||
2503 BOP_GETPROP(bootops
, prop_name
, str
) < 0 ||
2504 kobj_getvalue(str
, &value
) == -1)
2508 *prop_value
= value
;