4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
26 * Copyright (c) 2010, Intel Corporation.
27 * All rights reserved.
29 * Copyright 2013 Joyent, Inc. All rights reserved.
33 * This file contains the functionality that mimics the boot operations
34 * on SPARC systems or the old boot.bin/multiboot programs on x86 systems.
35 * The x86 kernel now does everything on its own.
38 #include <sys/types.h>
39 #include <sys/bootconf.h>
40 #include <sys/bootsvcs.h>
41 #include <sys/bootinfo.h>
42 #include <sys/multiboot.h>
43 #include <sys/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>
72 static int have_console
= 0; /* set once primitive console is initialized */
73 static char *boot_args
= "";
78 static uint_t kbm_debug
= 0;
79 #define DBG_MSG(s) { if (kbm_debug) bop_printf(NULL, "%s", s); }
80 #define DBG(x) { if (kbm_debug) \
81 bop_printf(NULL, "%s is %" PRIx64 "\n", #x, (uint64_t)(x)); \
84 #define PUT_STRING(s) { \
86 for (cp = (s); *cp; ++cp) \
90 bootops_t bootop
; /* simple bootops we'll pass on to kernel */
94 * Boot info from "glue" code in low memory. xbootp is used by:
95 * do_bop_phys_alloc(), do_bsys_alloc() and boot_prop_finish().
97 static struct xboot_info
*xbootp
;
98 static uintptr_t next_virt
; /* next available virtual address */
99 static paddr_t next_phys
; /* next available physical address from dboot */
100 static paddr_t high_phys
= -(paddr_t
)1; /* last used physical address */
103 * buffer for vsnprintf for console I/O
105 #define BUFFERSIZE 512
106 static char buffer
[BUFFERSIZE
];
109 * stuff to store/report/manipulate boot property settings.
111 typedef struct bootprop
{
112 struct bootprop
*bp_next
;
118 static bootprop_t
*bprops
= NULL
;
119 static char *curr_page
= NULL
; /* ptr to avail bprop memory */
120 static int curr_space
= 0; /* amount of memory at curr_page */
124 * some allocator statistics
126 static ulong_t total_bop_alloc_scratch
= 0;
127 static ulong_t total_bop_alloc_kernel
= 0;
129 static void build_firmware_properties(struct xboot_info
*);
131 static int early_allocation
= 1;
133 int force_fastreboot
= 0;
134 volatile int fastreboot_onpanic
= 0;
135 int post_fastreboot
= 0;
136 volatile int fastreboot_capable
= 1;
139 * Information saved from current boot for fast reboot.
140 * If the information size exceeds what we have allocated, fast reboot
141 * will not be supported.
143 multiboot_info_t saved_mbi
;
144 mb_memory_map_t saved_mmap
[FASTBOOT_SAVED_MMAP_COUNT
];
145 uint8_t saved_drives
[FASTBOOT_SAVED_DRIVES_SIZE
];
146 char saved_cmdline
[FASTBOOT_SAVED_CMDLINE_LEN
];
147 int saved_cmdline_len
= 0;
148 size_t saved_file_size
[FASTBOOT_MAX_FILES_MAP
];
151 * Turn off fastreboot_onpanic to avoid panic loop.
153 char fastreboot_onpanic_cmdline
[FASTBOOT_SAVED_CMDLINE_LEN
];
154 static const char fastreboot_onpanic_args
[] = " -B fastreboot_onpanic=0";
157 * Pointers to where System Resource Affinity Table (SRAT), System Locality
158 * Information Table (SLIT) and Maximum System Capability Table (MSCT)
159 * are mapped into virtual memory
161 ACPI_TABLE_SRAT
*srat_ptr
= NULL
;
162 ACPI_TABLE_SLIT
*slit_ptr
= NULL
;
163 ACPI_TABLE_MSCT
*msct_ptr
= NULL
;
166 * Arbitrary limit on number of localities we handle; if
167 * this limit is raised to more than UINT16_MAX, make sure
168 * process_slit() knows how to handle it.
170 #define SLIT_LOCALITIES_MAX (4096)
172 #define SLIT_NUM_PROPNAME "acpi-slit-localities"
173 #define SLIT_PROPNAME "acpi-slit"
176 * Allocate aligned physical memory at boot time. This allocator allocates
177 * from the highest possible addresses. This avoids exhausting memory that
178 * would be useful for DMA buffers.
181 do_bop_phys_alloc(uint64_t size
, uint64_t align
)
186 struct memlist
*ml
= (struct memlist
*)xbootp
->bi_phys_install
;
189 * Be careful if high memory usage is limited in startup.c
190 * Since there are holes in the low part of the physical address
191 * space we can treat physmem as a pfn (not just a pgcnt) and
192 * get a conservative upper limit.
194 if (physmem
!= 0 && high_phys
> pfn_to_pa(physmem
))
195 high_phys
= pfn_to_pa(physmem
);
198 * find the lowest or highest available memory in physinstalled
199 * On 32 bit avoid physmem above 4Gig if PAE isn't enabled
202 if (xbootp
->bi_use_pae
== 0 && high_phys
> FOUR_GIG
)
203 high_phys
= FOUR_GIG
;
207 * find the highest available memory in physinstalled
209 size
= P2ROUNDUP(size
, align
);
210 for (; ml
; ml
= ml
->ml_next
) {
211 start
= P2ROUNDUP(ml
->ml_address
, align
);
212 end
= P2ALIGN(ml
->ml_address
+ ml
->ml_size
, align
);
213 if (start
< next_phys
)
214 start
= P2ROUNDUP(next_phys
, align
);
216 end
= P2ALIGN(high_phys
, align
);
220 if (end
- start
< size
)
224 * Early allocations need to use low memory, since
225 * physmem might be further limited by bootenv.rc
227 if (early_allocation
) {
228 if (pa
== 0 || start
< pa
)
236 if (early_allocation
)
237 next_phys
= pa
+ size
;
242 bop_panic("do_bop_phys_alloc(0x%" PRIx64
", 0x%" PRIx64
243 ") Out of memory\n", size
, align
);
248 alloc_vaddr(size_t size
, paddr_t align
)
252 next_virt
= P2ROUNDUP(next_virt
, (uintptr_t)align
);
253 rv
= (uintptr_t)next_virt
;
259 * Allocate virtual memory. The size is always rounded up to a multiple
265 do_bsys_alloc(bootops_t
*bop
, caddr_t virthint
, size_t size
, int align
)
267 paddr_t a
= align
; /* same type as pa for masking */
271 ssize_t s
; /* the aligned size */
273 uint_t is_kernel
= (virthint
!= 0);
275 if (a
< MMU_PAGESIZE
)
278 prom_panic("do_bsys_alloc() incorrect alignment");
279 size
= P2ROUNDUP(size
, MMU_PAGESIZE
);
282 * Use the next aligned virtual address if we weren't given one.
284 if (virthint
== NULL
) {
285 virthint
= (caddr_t
)alloc_vaddr(size
, a
);
286 total_bop_alloc_scratch
+= size
;
288 total_bop_alloc_kernel
+= size
;
292 * allocate the physical memory
294 pa
= do_bop_phys_alloc(size
, a
);
297 * Add the mappings to the page tables, try large pages first.
299 va
= (uintptr_t)virthint
;
302 pgsize
= xbootp
->bi_use_pae
? TWO_MEG
: FOUR_MEG
;
303 if (xbootp
->bi_use_largepage
&& a
== pgsize
) {
304 while (IS_P2ALIGNED(pa
, pgsize
) && IS_P2ALIGNED(va
, pgsize
) &&
306 kbm_map(va
, pa
, level
, is_kernel
);
314 * Map remaining pages use small mappings
317 pgsize
= MMU_PAGESIZE
;
319 kbm_map(va
, pa
, level
, is_kernel
);
328 * Free virtual memory - we'll just ignore these.
332 do_bsys_free(bootops_t
*bop
, caddr_t virt
, size_t size
)
334 bop_printf(NULL
, "do_bsys_free(virt=0x%p, size=0x%lx) ignored\n",
343 do_bsys_ealloc(bootops_t
*bop
, caddr_t virthint
, size_t size
,
344 int align
, int flags
)
346 prom_panic("unsupported call to BOP_EALLOC()\n");
352 bsetprop(char *name
, int nlen
, void *value
, int vlen
)
359 * align the size to 16 byte boundary
361 size
= sizeof (bootprop_t
) + nlen
+ 1 + vlen
;
362 size
= (size
+ 0xf) & ~0xf;
363 if (size
> curr_space
) {
364 need_size
= (size
+ (MMU_PAGEOFFSET
)) & MMU_PAGEMASK
;
365 curr_page
= do_bsys_alloc(NULL
, 0, need_size
, MMU_PAGESIZE
);
366 curr_space
= need_size
;
370 * use a bootprop_t at curr_page and link into list
372 b
= (bootprop_t
*)curr_page
;
373 curr_page
+= sizeof (bootprop_t
);
374 curr_space
-= sizeof (bootprop_t
);
379 * follow by name and ending zero byte
381 b
->bp_name
= curr_page
;
382 bcopy(name
, curr_page
, nlen
);
385 curr_space
-= nlen
+ 1;
388 * copy in value, but no ending zero byte
390 b
->bp_value
= curr_page
;
393 bcopy(value
, curr_page
, vlen
);
399 * align new values of curr_page, curr_space
401 while (curr_space
& 0xf) {
408 bsetprops(char *name
, char *value
)
410 bsetprop(name
, strlen(name
), value
, strlen(value
) + 1);
414 bsetprop64(char *name
, uint64_t value
)
416 bsetprop(name
, strlen(name
), (void *)&value
, sizeof (value
));
420 bsetpropsi(char *name
, int value
)
424 (void) snprintf(prop_val
, sizeof (prop_val
), "%d", value
);
425 bsetprops(name
, prop_val
);
429 * to find the size of the buffer to allocate
433 do_bsys_getproplen(bootops_t
*bop
, const char *name
)
437 for (b
= bprops
; b
; b
= b
->bp_next
) {
438 if (strcmp(name
, b
->bp_name
) != 0)
446 * get the value associated with this name
450 do_bsys_getprop(bootops_t
*bop
, const char *name
, void *value
)
454 for (b
= bprops
; b
; b
= b
->bp_next
) {
455 if (strcmp(name
, b
->bp_name
) != 0)
457 bcopy(b
->bp_value
, value
, b
->bp_vlen
);
464 * get the name of the next property in succession from the standalone
468 do_bsys_nextprop(bootops_t
*bop
, char *name
)
473 * A null name is a special signal for the 1st boot property
475 if (name
== NULL
|| strlen(name
) == 0) {
478 return (bprops
->bp_name
);
481 for (b
= bprops
; b
; b
= b
->bp_next
) {
482 if (name
!= b
->bp_name
)
493 * Parse numeric value from a string. Understands decimal, hex, octal, - and ~
496 parse_value(char *p
, uint64_t *retval
)
504 if (*p
== '-' || *p
== '~')
511 if (*p
== 'x' || *p
== 'X') {
520 if ('0' <= *p
&& *p
<= '9')
522 else if ('a' <= *p
&& *p
<= 'f')
523 digit
= 10 + *p
- 'a';
524 else if ('A' <= *p
&& *p
<= 'F')
525 digit
= 10 + *p
- 'A';
530 tmp
= tmp
* radix
+ digit
;
535 else if (adjust
== '~')
542 unprintable(char *value
, int size
)
546 if (size
<= 0 || value
[0] == '\0')
549 for (i
= 0; i
< size
; i
++) {
550 if (value
[i
] == '\0')
551 return (i
!= (size
- 1));
553 if (!isprint(value
[i
]))
560 * Print out information about all boot properties.
561 * buffer is pointer to pre-allocated space to be used as temporary
562 * space for property values.
565 boot_prop_display(char *buffer
)
570 bop_printf(NULL
, "\nBoot properties:\n");
572 while ((name
= do_bsys_nextprop(NULL
, name
)) != NULL
) {
573 bop_printf(NULL
, "\t0x%p %s = ", (void *)name
, name
);
574 (void) do_bsys_getprop(NULL
, name
, buffer
);
575 len
= do_bsys_getproplen(NULL
, name
);
576 bop_printf(NULL
, "len=%d ", len
);
577 if (!unprintable(buffer
, len
)) {
579 bop_printf(NULL
, "%s\n", buffer
);
582 for (i
= 0; i
< len
; i
++) {
583 bop_printf(NULL
, "%02x", buffer
[i
] & 0xff);
585 bop_printf(NULL
, ".");
587 bop_printf(NULL
, "\n");
592 * 2nd part of building the table of boot properties. This includes:
593 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
595 * lines look like one of:
597 * ^# comment till end of line
598 * setprop name 'value'
600 * setprop name "value"
602 * we do single character I/O since this is really just looking at memory
605 boot_prop_finish(void)
615 char *inputdev
; /* these override the command line if serial ports */
622 DBG_MSG("Opening /boot/solaris/bootenv.rc\n");
623 fd
= BRD_OPEN(bfs_ops
, "/boot/solaris/bootenv.rc", 0);
626 line
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
633 bytes_read
= BRD_READ(bfs_ops
, fd
, line
+ c
, 1);
634 if (bytes_read
== 0) {
645 * ignore comment lines
648 while (ISSPACE(line
[c
]))
650 if (line
[c
] == '#' || line
[c
] == 0)
654 * must have "setprop " or "setprop\t"
656 if (strncmp(line
+ c
, "setprop ", 8) != 0 &&
657 strncmp(line
+ c
, "setprop\t", 8) != 0)
660 while (ISSPACE(line
[c
]))
666 * gather up the property name
670 while (line
[c
] && !ISSPACE(line
[c
]))
674 * gather up the value, if any
678 while (ISSPACE(line
[c
]))
682 while (line
[c
] && !ISSPACE(line
[c
]))
686 if (v_len
>= 2 && value
[0] == value
[v_len
- 1] &&
687 (value
[0] == '\'' || value
[0] == '"')) {
698 * ignore "boot-file" property, it's now meaningless
700 if (strcmp(name
, "boot-file") == 0)
702 if (strcmp(name
, "boot-args") == 0 &&
703 strlen(boot_args
) > 0)
707 * If a property was explicitly set on the command line
708 * it will override a setting in bootenv.rc
710 if (do_bsys_getproplen(NULL
, name
) > 0)
713 bsetprop(name
, n_len
, value
, v_len
+ 1);
717 (void) BRD_CLOSE(bfs_ops
, fd
);
720 * Check if we have to limit the boot time allocator
722 if (do_bsys_getproplen(NULL
, "physmem") != -1 &&
723 do_bsys_getprop(NULL
, "physmem", line
) >= 0 &&
724 parse_value(line
, &lvalue
) != -1) {
725 if (0 < lvalue
&& (lvalue
< physmem
|| physmem
== 0)) {
726 physmem
= (pgcnt_t
)lvalue
;
730 early_allocation
= 0;
733 * check to see if we have to override the default value of the console
737 v_len
= do_bsys_getproplen(NULL
, "input-device");
739 (void) do_bsys_getprop(NULL
, "input-device", inputdev
);
744 outputdev
= inputdev
+ v_len
+ 1;
745 v_len
= do_bsys_getproplen(NULL
, "output-device");
747 (void) do_bsys_getprop(NULL
, "output-device",
751 outputdev
[v_len
] = 0;
753 consoledev
= outputdev
+ v_len
+ 1;
754 v_len
= do_bsys_getproplen(NULL
, "console");
756 (void) do_bsys_getprop(NULL
, "console", consoledev
);
757 if (post_fastreboot
&&
758 strcmp(consoledev
, "graphics") == 0) {
759 bsetprops("console", "text");
760 v_len
= strlen("text");
761 bcopy("text", consoledev
, v_len
);
766 consoledev
[v_len
] = 0;
767 bcons_init2(inputdev
, outputdev
, consoledev
);
770 * Ensure console property exists
771 * If not create it as "hypervisor"
773 v_len
= do_bsys_getproplen(NULL
, "console");
775 bsetprops("console", "hypervisor");
776 inputdev
= outputdev
= consoledev
= "hypervisor";
777 bcons_init2(inputdev
, outputdev
, consoledev
);
780 if (find_boot_prop("prom_debug") || kbm_debug
)
781 boot_prop_display(line
);
785 * print formatted output
790 bop_printf(bootops_t
*bop
, const char *fmt
, ...)
794 if (have_console
== 0)
798 (void) vsnprintf(buffer
, BUFFERSIZE
, fmt
, ap
);
804 * Another panic() variant; this one can be used even earlier during boot than
809 bop_panic(const char *fmt
, ...)
814 bop_printf(NULL
, fmt
, ap
);
817 bop_printf(NULL
, "\nPress any key to reboot.\n");
818 (void) bcons_getchar();
819 bop_printf(NULL
, "Resetting...\n");
824 * Do a real mode interrupt BIOS call
826 typedef struct bios_regs
{
827 unsigned short ax
, bx
, cx
, dx
, si
, di
, bp
, es
, ds
;
829 typedef int (*bios_func_t
)(int, bios_regs_t
*);
833 do_bsys_doint(bootops_t
*bop
, int intnum
, struct bop_regs
*rp
)
835 static int firsttime
= 1;
836 bios_func_t bios_func
= (bios_func_t
)(void *)(uintptr_t)0x5000;
840 * The first time we do this, we have to copy the pre-packaged
841 * low memory bios call code image into place.
844 extern char bios_image
[];
845 extern uint32_t bios_size
;
847 bcopy(bios_image
, (void *)bios_func
, bios_size
);
851 br
.ax
= rp
->eax
.word
.ax
;
852 br
.bx
= rp
->ebx
.word
.bx
;
853 br
.cx
= rp
->ecx
.word
.cx
;
854 br
.dx
= rp
->edx
.word
.dx
;
855 br
.bp
= rp
->ebp
.word
.bp
;
856 br
.si
= rp
->esi
.word
.si
;
857 br
.di
= rp
->edi
.word
.di
;
861 DBG_MSG("Doing BIOS call...");
865 rp
->eflags
= bios_func(intnum
, &br
);
868 rp
->eax
.word
.ax
= br
.ax
;
869 rp
->ebx
.word
.bx
= br
.bx
;
870 rp
->ecx
.word
.cx
= br
.cx
;
871 rp
->edx
.word
.dx
= br
.dx
;
872 rp
->ebp
.word
.bp
= br
.bp
;
873 rp
->esi
.word
.si
= br
.si
;
874 rp
->edi
.word
.di
= br
.di
;
879 static struct boot_syscalls bop_sysp
= {
891 setup_rarp_props(struct sol_netinfo
*sip
)
893 char buf
[BUFLEN
]; /* to hold ip/mac addrs */
896 val
= (uint8_t *)&sip
->sn_ciaddr
;
897 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
898 val
[0], val
[1], val
[2], val
[3]);
899 bsetprops(BP_HOST_IP
, buf
);
901 val
= (uint8_t *)&sip
->sn_siaddr
;
902 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
903 val
[0], val
[1], val
[2], val
[3]);
904 bsetprops(BP_SERVER_IP
, buf
);
906 if (sip
->sn_giaddr
!= 0) {
907 val
= (uint8_t *)&sip
->sn_giaddr
;
908 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
909 val
[0], val
[1], val
[2], val
[3]);
910 bsetprops(BP_ROUTER_IP
, buf
);
913 if (sip
->sn_netmask
!= 0) {
914 val
= (uint8_t *)&sip
->sn_netmask
;
915 (void) snprintf(buf
, BUFLEN
, "%d.%d.%d.%d",
916 val
[0], val
[1], val
[2], val
[3]);
917 bsetprops(BP_SUBNET_MASK
, buf
);
920 if (sip
->sn_mactype
!= 4 || sip
->sn_maclen
!= 6) {
921 bop_printf(NULL
, "unsupported mac type %d, mac len %d\n",
922 sip
->sn_mactype
, sip
->sn_maclen
);
924 val
= sip
->sn_macaddr
;
925 (void) snprintf(buf
, BUFLEN
, "%x:%x:%x:%x:%x:%x",
926 val
[0], val
[1], val
[2], val
[3], val
[4], val
[5]);
927 bsetprops(BP_BOOT_MAC
, buf
);
933 build_panic_cmdline(const char *cmd
, int cmdlen
)
938 arglen
= sizeof (fastreboot_onpanic_args
);
940 * If we allready have fastreboot-onpanic set to zero,
941 * don't add them again.
943 if ((proplen
= do_bsys_getproplen(NULL
, FASTREBOOT_ONPANIC
)) > 0 &&
944 proplen
<= sizeof (fastreboot_onpanic_cmdline
)) {
945 (void) do_bsys_getprop(NULL
, FASTREBOOT_ONPANIC
,
946 fastreboot_onpanic_cmdline
);
947 if (FASTREBOOT_ONPANIC_NOTSET(fastreboot_onpanic_cmdline
))
952 * construct fastreboot_onpanic_cmdline
954 if (cmdlen
+ arglen
> sizeof (fastreboot_onpanic_cmdline
)) {
955 DBG_MSG("Command line too long: clearing "
956 FASTREBOOT_ONPANIC
"\n");
957 fastreboot_onpanic
= 0;
959 bcopy(cmd
, fastreboot_onpanic_cmdline
, cmdlen
);
961 bcopy(fastreboot_onpanic_args
,
962 fastreboot_onpanic_cmdline
+ cmdlen
, arglen
);
964 fastreboot_onpanic_cmdline
[cmdlen
] = 0;
970 * Construct boot command line for Fast Reboot. The saved_cmdline
971 * is also reported by "eeprom bootcmd".
974 build_fastboot_cmdline(struct xboot_info
*xbp
)
976 saved_cmdline_len
= strlen(xbp
->bi_cmdline
) + 1;
977 if (saved_cmdline_len
> FASTBOOT_SAVED_CMDLINE_LEN
) {
978 DBG(saved_cmdline_len
);
979 DBG_MSG("Command line too long: clearing fastreboot_capable\n");
980 fastreboot_capable
= 0;
982 bcopy((void *)(xbp
->bi_cmdline
), (void *)saved_cmdline
,
984 saved_cmdline
[saved_cmdline_len
- 1] = '\0';
985 build_panic_cmdline(saved_cmdline
, saved_cmdline_len
- 1);
990 * Save memory layout, disk drive information, unix and boot archive sizes for
994 save_boot_info(struct xboot_info
*xbi
)
996 multiboot_info_t
*mbi
= xbi
->bi_mb_info
;
997 struct boot_modules
*modp
;
1000 bcopy(mbi
, &saved_mbi
, sizeof (multiboot_info_t
));
1001 if (mbi
->mmap_length
> sizeof (saved_mmap
)) {
1002 DBG_MSG("mbi->mmap_length too big: clearing "
1003 "fastreboot_capable\n");
1004 fastreboot_capable
= 0;
1006 bcopy((void *)(uintptr_t)mbi
->mmap_addr
, (void *)saved_mmap
,
1010 if ((mbi
->flags
& MB_INFO_DRIVE_INFO
) != 0) {
1011 if (mbi
->drives_length
> sizeof (saved_drives
)) {
1012 DBG(mbi
->drives_length
);
1013 DBG_MSG("mbi->drives_length too big: clearing "
1014 "fastreboot_capable\n");
1015 fastreboot_capable
= 0;
1017 bcopy((void *)(uintptr_t)mbi
->drives_addr
,
1018 (void *)saved_drives
, mbi
->drives_length
);
1021 saved_mbi
.drives_length
= 0;
1022 saved_mbi
.drives_addr
= (uintptr_t)NULL
;
1026 * Current file sizes. Used by fastboot.c to figure out how much
1027 * memory to reserve for panic reboot.
1028 * Use the module list from the dboot-constructed xboot_info
1029 * instead of the list referenced by the multiboot structure
1030 * because that structure may not be addressable now.
1032 saved_file_size
[FASTBOOT_NAME_UNIX
] = FOUR_MEG
- PAGESIZE
;
1033 for (i
= 0, modp
= (struct boot_modules
*)(uintptr_t)xbi
->bi_modules
;
1034 i
< xbi
->bi_module_cnt
; i
++, modp
++) {
1035 saved_file_size
[FASTBOOT_NAME_BOOTARCHIVE
] += modp
->bm_size
;
1040 * Import boot environment module variables as properties, applying
1041 * blacklist filter for variables we know we will not use.
1043 * Since the environment can be relatively large, containing many variables
1044 * used only for boot loader purposes, we will use a blacklist based filter.
1045 * To keep the blacklist from growing too large, we use prefix based filtering.
1046 * This is possible because in many cases, the loader variable names are
1047 * using a structured layout.
1049 * We will not overwrite already set properties.
1051 static struct bop_blacklist
{
1052 const char *bl_name
;
1054 } bop_prop_blacklist
[] = {
1055 { "ISADIR", sizeof ("ISADIR") },
1056 { "acpi", sizeof ("acpi") },
1057 { "autoboot_delay", sizeof ("autoboot_delay") },
1058 { "autoboot_delay", sizeof ("autoboot_delay") },
1059 { "beansi_", sizeof ("beansi_") },
1060 { "beastie", sizeof ("beastie") },
1061 { "bemenu", sizeof ("bemenu") },
1062 { "boot.", sizeof ("boot.") },
1063 { "bootenv", sizeof ("bootenv") },
1064 { "currdev", sizeof ("currdev") },
1065 { "dhcp.", sizeof ("dhcp.") },
1066 { "interpret", sizeof ("interpret") },
1067 { "kernel", sizeof ("kernel") },
1068 { "loaddev", sizeof ("loaddev") },
1069 { "loader_", sizeof ("loader_") },
1070 { "module_path", sizeof ("module_path") },
1071 { "nfs.", sizeof ("nfs.") },
1072 { "pcibios", sizeof ("pcibios") },
1073 { "prompt", sizeof ("prompt") },
1074 { "smbios", sizeof ("smbios") },
1075 { "tem", sizeof ("tem") },
1076 { "twiddle_divisor", sizeof ("twiddle_divisor") },
1077 { "zfs_be", sizeof ("zfs_be") },
1081 * Match the name against prefixes in above blacklist. If the match was
1082 * found, this name is blacklisted.
1085 name_is_blacklisted(const char *name
)
1089 n
= sizeof (bop_prop_blacklist
) / sizeof (bop_prop_blacklist
[0]);
1090 for (i
= 0; i
< n
; i
++) {
1091 if (strncmp(bop_prop_blacklist
[i
].bl_name
, name
,
1092 bop_prop_blacklist
[i
].bl_name_len
- 1) == 0) {
1100 process_boot_environment(struct boot_modules
*benv
)
1102 char *env
, *ptr
, *name
, *value
;
1103 uint32_t size
, name_len
, value_len
;
1105 if (benv
== NULL
|| benv
->bm_type
!= BMT_ENV
)
1107 ptr
= env
= benv
->bm_addr
;
1108 size
= benv
->bm_size
;
1112 while (*ptr
!= '=') {
1114 if (ptr
> env
+ size
) /* Something is very wrong. */
1117 name_len
= ptr
- name
;
1118 if (sizeof (buffer
) <= name_len
)
1121 (void) strncpy(buffer
, name
, sizeof (buffer
));
1122 buffer
[name_len
] = '\0';
1127 while ((uintptr_t)ptr
- (uintptr_t)env
< size
) {
1130 value_len
= (uintptr_t)ptr
- (uintptr_t)env
;
1136 /* Did we reach the end of the module? */
1143 /* Is this property already set? */
1144 if (do_bsys_getproplen(NULL
, name
) >= 0)
1147 if (name_is_blacklisted(name
) == B_TRUE
)
1150 /* Create new property. */
1151 bsetprops(name
, value
);
1153 /* Avoid reading past the module end. */
1154 if (size
<= (uintptr_t)ptr
- (uintptr_t)env
)
1156 } while (*ptr
!= '\0');
1160 * 1st pass at building the table of boot properties. This includes:
1161 * - values set on the command line: -B a=x,b=y,c=z ....
1162 * - known values we just compute (ie. from xbp)
1163 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
1165 * the grub command line looked like:
1166 * kernel boot-file [-B prop=value[,prop=value]...] [boot-args]
1168 * whoami is the same as boot-file
1171 build_boot_properties(struct xboot_info
*xbp
)
1177 struct boot_modules
*bm
, *rdbm
, *benv
= NULL
;
1183 static int stdout_val
= 0;
1184 uchar_t boot_device
;
1188 * These have to be done first, so that kobj_mount_root() works
1190 DBG_MSG("Building boot properties\n");
1191 propbuf
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, 0);
1192 DBG((uintptr_t)propbuf
);
1193 if (xbp
->bi_module_cnt
> 0) {
1194 bm
= xbp
->bi_modules
;
1196 for (midx
= i
= 0; i
< xbp
->bi_module_cnt
; i
++) {
1197 if (bm
[i
].bm_type
== BMT_ROOTFS
) {
1201 if (bm
[i
].bm_type
== BMT_HASH
|| bm
[i
].bm_name
== NULL
)
1204 if (bm
[i
].bm_type
== BMT_ENV
) {
1211 (void) snprintf(modid
, sizeof (modid
),
1212 "module-name-%u", midx
);
1213 bsetprops(modid
, (char *)bm
[i
].bm_name
);
1214 (void) snprintf(modid
, sizeof (modid
),
1215 "module-addr-%u", midx
);
1216 bsetprop64(modid
, (uint64_t)(uintptr_t)bm
[i
].bm_addr
);
1217 (void) snprintf(modid
, sizeof (modid
),
1218 "module-size-%u", midx
);
1219 bsetprop64(modid
, (uint64_t)bm
[i
].bm_size
);
1223 bsetprop64("ramdisk_start",
1224 (uint64_t)(uintptr_t)rdbm
->bm_addr
);
1225 bsetprop64("ramdisk_end",
1226 (uint64_t)(uintptr_t)rdbm
->bm_addr
+ rdbm
->bm_size
);
1231 * If there are any boot time modules or hashes present, then disable
1234 if (xbp
->bi_module_cnt
> 1) {
1235 fastreboot_disable(FBNS_BOOTMOD
);
1239 * Disable fast reboot if we're using the Multiboot 2 boot protocol,
1240 * since we don't currently support MB2 info and module relocation.
1241 * Note that fast reboot will have already been disabled if multiple
1242 * modules are present, since the current implementation assumes that
1243 * we only have a single module, the boot_archive.
1245 if (xbp
->bi_mb_version
!= 1) {
1246 fastreboot_disable(FBNS_MULTIBOOT2
);
1249 DBG_MSG("Parsing command line for boot properties\n");
1250 value
= xbp
->bi_cmdline
;
1253 * allocate memory to collect boot_args into
1255 boot_arg_len
= strlen(xbp
->bi_cmdline
) + 1;
1256 boot_args
= do_bsys_alloc(NULL
, NULL
, boot_arg_len
, MMU_PAGESIZE
);
1261 while (ISSPACE(*value
))
1264 * value now points at the boot-file
1267 while (value
[value_len
] && !ISSPACE(value
[value_len
]))
1269 if (value_len
> 0) {
1271 bcopy(value
, whoami
, value_len
);
1272 whoami
[value_len
] = 0;
1273 bsetprops("boot-file", whoami
);
1275 * strip leading path stuff from whoami, so running from
1276 * PXE/miniroot makes sense.
1278 if (strstr(whoami
, "/platform/") != NULL
)
1279 whoami
= strstr(whoami
, "/platform/");
1280 bsetprops("whoami", whoami
);
1284 * Values forcibly set boot properties on the command line via -B.
1285 * Allow use of quotes in values. Other stuff goes on kernel
1288 name
= value
+ value_len
;
1289 while (*name
!= 0) {
1291 * anything not " -B" is copied to the command line
1293 if (!ISSPACE(name
[0]) || name
[1] != '-' || name
[2] != 'B') {
1294 boot_args
[boot_arg_len
++] = *name
;
1295 boot_args
[boot_arg_len
] = 0;
1301 * skip the " -B" and following white space
1304 while (ISSPACE(*name
))
1306 while (*name
&& !ISSPACE(*name
)) {
1307 value
= strstr(name
, "=");
1310 name_len
= value
- name
;
1314 for (; ; ++value_len
) {
1315 if (!value
[value_len
])
1319 * is this value quoted?
1321 if (value_len
== 0 &&
1322 (value
[0] == '\'' || value
[0] == '"')) {
1328 * In the quote accept any character,
1329 * but look for ending quote.
1332 if (value
[value_len
] == quoted
)
1338 * a comma or white space ends the value
1340 if (value
[value_len
] == ',' ||
1341 ISSPACE(value
[value_len
]))
1345 if (value_len
== 0) {
1346 bsetprop(name
, name_len
, "true", 5);
1350 if (v
[0] == v
[l
- 1] &&
1351 (v
[0] == '\'' || v
[0] == '"')) {
1355 bcopy(v
, propbuf
, l
);
1357 bsetprop(name
, name_len
, propbuf
,
1360 name
= value
+ value_len
;
1361 while (*name
== ',')
1367 * set boot-args property
1368 * 1275 name is bootargs, so set
1371 bsetprops("boot-args", boot_args
);
1372 bsetprops("bootargs", boot_args
);
1374 process_boot_environment(benv
);
1377 * Build boot command line for Fast Reboot
1379 build_fastboot_cmdline(xbp
);
1381 if (xbp
->bi_mb_version
== 1) {
1382 multiboot_info_t
*mbi
= xbp
->bi_mb_info
;
1384 struct sol_netinfo
*sip
;
1387 * set the BIOS boot device from GRUB
1392 * Save various boot information for Fast Reboot
1394 save_boot_info(xbp
);
1396 if (mbi
!= NULL
&& mbi
->flags
& MB_INFO_BOOTDEV
) {
1397 boot_device
= mbi
->boot_device
>> 24;
1398 if (boot_device
== 0x20)
1400 str
[0] = (boot_device
>> 4) + '0';
1401 str
[1] = (boot_device
& 0xf) + '0';
1403 bsetprops("bios-boot-device", str
);
1409 * In the netboot case, drives_info is overloaded with the
1410 * dhcp ack. This is not multiboot compliant and requires
1413 if (netboot
&& mbi
->drives_length
!= 0) {
1414 sip
= (struct sol_netinfo
*)(uintptr_t)mbi
->drives_addr
;
1415 if (sip
->sn_infotype
== SN_TYPE_BOOTP
)
1416 bsetprop("bootp-response",
1417 sizeof ("bootp-response"),
1418 (void *)(uintptr_t)mbi
->drives_addr
,
1419 mbi
->drives_length
);
1420 else if (sip
->sn_infotype
== SN_TYPE_RARP
)
1421 setup_rarp_props(sip
);
1424 multiboot2_info_header_t
*mbi
= xbp
->bi_mb_info
;
1425 multiboot_tag_bootdev_t
*bootdev
= NULL
;
1426 multiboot_tag_network_t
*netdev
= NULL
;
1429 bootdev
= dboot_multiboot2_find_tag(mbi
,
1430 MULTIBOOT_TAG_TYPE_BOOTDEV
);
1431 netdev
= dboot_multiboot2_find_tag(mbi
,
1432 MULTIBOOT_TAG_TYPE_NETWORK
);
1434 if (bootdev
!= NULL
) {
1435 DBG(bootdev
->mb_biosdev
);
1436 boot_device
= bootdev
->mb_biosdev
;
1437 str
[0] = (boot_device
>> 4) + '0';
1438 str
[1] = (boot_device
& 0xf) + '0';
1440 bsetprops("bios-boot-device", str
);
1442 if (netdev
!= NULL
) {
1443 bsetprop("bootp-response", sizeof ("bootp-response"),
1444 (void *)(uintptr_t)netdev
->mb_dhcpack
,
1446 sizeof (multiboot_tag_network_t
));
1450 bsetprop("stdout", strlen("stdout"),
1451 &stdout_val
, sizeof (stdout_val
));
1454 * more conjured up values for made up things....
1456 bsetprops("mfg-name", "i86pc");
1457 bsetprops("impl-arch-name", "i86pc");
1460 * Build firmware-provided system properties
1462 build_firmware_properties(xbp
);
1467 * Find out what these are:
1468 * - cpuid_feature_ecx_include
1469 * - cpuid_feature_ecx_exclude
1470 * - cpuid_feature_edx_include
1471 * - cpuid_feature_edx_exclude
1473 * Find out what these are in multiboot:
1481 * Install a temporary IDT that lets us catch errors in the boot time code.
1482 * We shouldn't get any faults at all while this is installed, so we'll
1483 * just generate a traceback and exit.
1486 static const int bcode_sel
= B64CODE_SEL
;
1488 static const int bcode_sel
= B32CODE_SEL
;
1492 * simple description of a stack frame (args are 32 bit only currently)
1494 typedef struct bop_frame
{
1495 struct bop_frame
*old_frame
;
1501 bop_traceback(bop_frame_t
*frame
)
1511 bop_printf(NULL
, "Stack traceback:\n");
1512 for (cnt
= 0; cnt
< 30; ++cnt
) { /* up to 30 frames */
1513 pc
= frame
->retaddr
;
1516 ksym
= kobj_getsymname(pc
, &off
);
1518 bop_printf(NULL
, " %s+%lx", ksym
, off
);
1520 bop_printf(NULL
, " 0x%lx", pc
);
1522 frame
= frame
->old_frame
;
1524 bop_printf(NULL
, "\n");
1528 for (a
= 0; a
< 6; ++a
) { /* try for 6 args */
1529 if ((void *)&frame
->arg
[a
] == (void *)frame
->old_frame
)
1532 bop_printf(NULL
, "(");
1534 bop_printf(NULL
, ",");
1535 bop_printf(NULL
, "0x%lx", frame
->arg
[a
]);
1537 bop_printf(NULL
, ")");
1539 bop_printf(NULL
, "\n");
1544 ulong_t error_code
; /* optional */
1555 bop_trap(ulong_t
*tfp
)
1557 struct trapframe
*tf
= (struct trapframe
*)tfp
;
1558 bop_frame_t fakeframe
;
1559 static int depth
= 0;
1562 * Check for an infinite loop of traps.
1565 bop_panic("Nested trap");
1567 bop_printf(NULL
, "Unexpected trap\n");
1570 * adjust the tf for optional error_code by detecting the code selector
1572 if (tf
->code_seg
!= bcode_sel
)
1573 tf
= (struct trapframe
*)(tfp
- 1);
1575 bop_printf(NULL
, "error code 0x%lx\n",
1576 tf
->error_code
& 0xffffffff);
1578 bop_printf(NULL
, "instruction pointer 0x%lx\n", tf
->inst_ptr
);
1579 bop_printf(NULL
, "code segment 0x%lx\n", tf
->code_seg
& 0xffff);
1580 bop_printf(NULL
, "flags register 0x%lx\n", tf
->flags_reg
);
1582 bop_printf(NULL
, "return %%rsp 0x%lx\n", tf
->stk_ptr
);
1583 bop_printf(NULL
, "return %%ss 0x%lx\n", tf
->stk_seg
& 0xffff);
1586 /* grab %[er]bp pushed by our code from the stack */
1587 fakeframe
.old_frame
= (bop_frame_t
*)*(tfp
- 3);
1588 fakeframe
.retaddr
= (pc_t
)tf
->inst_ptr
;
1589 bop_printf(NULL
, "Attempting stack backtrace:\n");
1590 bop_traceback(&fakeframe
);
1591 bop_panic("unexpected trap in early boot");
1594 extern void bop_trap_handler(void);
1596 static gate_desc_t
*bop_idt
;
1598 static desctbr_t bop_idt_info
;
1605 bop_idt
= (gate_desc_t
*)
1606 do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
1607 bzero(bop_idt
, MMU_PAGESIZE
);
1608 for (t
= 0; t
< NIDT
; ++t
) {
1610 * Note that since boot runs without a TSS, the
1611 * double fault handler cannot use an alternate stack
1612 * (64-bit) or a task gate (32-bit).
1614 set_gatesegd(&bop_idt
[t
], &bop_trap_handler
, bcode_sel
,
1615 SDT_SYSIGT
, TRP_KPL
, 0);
1617 bop_idt_info
.dtr_limit
= (NIDT
* sizeof (gate_desc_t
)) - 1;
1618 bop_idt_info
.dtr_base
= (uintptr_t)bop_idt
;
1619 wr_idtr(&bop_idt_info
);
1623 * This is where we enter the kernel. It dummies up the boot_ops and
1624 * boot_syscalls vectors and jumps off to _kobj_boot()
1627 _start(struct xboot_info
*xbp
)
1629 bootops_t
*bops
= &bootop
;
1630 extern void _kobj_boot();
1633 * 1st off - initialize the console for any error messages
1637 if (*((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) ==
1639 post_fastreboot
= 1;
1640 *((uint32_t *)(FASTBOOT_SWTCH_PA
+ FASTBOOT_STACK_OFFSET
)) = 0;
1649 if (find_boot_prop("kbm_debug") != NULL
)
1652 DBG_MSG("\n\n*** Entered Solaris in _start() cmdline is: ");
1653 DBG_MSG((char *)xbp
->bi_cmdline
);
1657 * physavail is no longer used by startup
1659 bm
.physinstalled
= xbp
->bi_phys_install
;
1660 bm
.pcimem
= xbp
->bi_pcimem
;
1661 bm
.rsvdmem
= xbp
->bi_rsvdmem
;
1662 bm
.physavail
= NULL
;
1665 * initialize the boot time allocator
1667 next_phys
= xbp
->bi_next_paddr
;
1669 next_virt
= (uintptr_t)xbp
->bi_next_vaddr
;
1671 DBG_MSG("Initializing boot time memory management...");
1676 * Fill in the bootops vector
1678 bops
->bsys_version
= BO_VERSION
;
1679 bops
->boot_mem
= &bm
;
1680 bops
->bsys_alloc
= do_bsys_alloc
;
1681 bops
->bsys_free
= do_bsys_free
;
1682 bops
->bsys_getproplen
= do_bsys_getproplen
;
1683 bops
->bsys_getprop
= do_bsys_getprop
;
1684 bops
->bsys_nextprop
= do_bsys_nextprop
;
1685 bops
->bsys_printf
= bop_printf
;
1686 bops
->bsys_doint
= do_bsys_doint
;
1689 * BOP_EALLOC() is no longer needed
1691 bops
->bsys_ealloc
= do_bsys_ealloc
;
1695 * Install an IDT to catch early pagefaults (shouldn't have any).
1696 * Also needed for kmdb.
1701 * Start building the boot properties from the command line
1703 DBG_MSG("Initializing boot properties:\n");
1704 build_boot_properties(xbp
);
1706 if (find_boot_prop("prom_debug") || kbm_debug
) {
1709 value
= do_bsys_alloc(NULL
, NULL
, MMU_PAGESIZE
, MMU_PAGESIZE
);
1710 boot_prop_display(value
);
1714 * jump into krtld...
1716 _kobj_boot(&bop_sysp
, NULL
, bops
, NULL
);
1722 no_more_alloc(bootops_t
*bop
, caddr_t virthint
, size_t size
, int align
)
1724 panic("Attempt to bsys_alloc() too late\n");
1730 no_more_free(bootops_t
*bop
, caddr_t virt
, size_t size
)
1732 panic("Attempt to bsys_free() too late\n");
1736 bop_no_more_mem(void)
1738 DBG(total_bop_alloc_scratch
);
1739 DBG(total_bop_alloc_kernel
);
1740 bootops
->bsys_alloc
= no_more_alloc
;
1741 bootops
->bsys_free
= no_more_free
;
1746 * Set ACPI firmware properties
1750 vmap_phys(size_t length
, paddr_t pa
)
1756 start
= P2ALIGN(pa
, MMU_PAGESIZE
);
1757 end
= P2ROUNDUP(pa
+ length
, MMU_PAGESIZE
);
1759 va
= (caddr_t
)alloc_vaddr(len
, MMU_PAGESIZE
);
1760 for (page
= 0; page
< len
; page
+= MMU_PAGESIZE
)
1761 kbm_map((uintptr_t)va
+ page
, start
+ page
, 0, 0);
1762 return (va
+ (pa
& MMU_PAGEOFFSET
));
1766 checksum_table(uint8_t *tp
, size_t len
)
1777 valid_rsdp(ACPI_TABLE_RSDP
*rp
)
1780 /* validate the V1.x checksum */
1781 if (checksum_table((uint8_t *)rp
, ACPI_RSDP_CHECKSUM_LENGTH
) != 0)
1784 /* If pre-ACPI 2.0, this is a valid RSDP */
1785 if (rp
->Revision
< 2)
1788 /* validate the V2.x checksum */
1789 if (checksum_table((uint8_t *)rp
, ACPI_RSDP_XCHECKSUM_LENGTH
) != 0)
1796 * Scan memory range for an RSDP;
1797 * see ACPI 3.0 Spec, 5.2.5.1
1799 static ACPI_TABLE_RSDP
*
1800 scan_rsdp(paddr_t start
, paddr_t end
)
1802 ssize_t len
= end
- start
;
1805 ptr
= vmap_phys(len
, start
);
1807 if (strncmp(ptr
, ACPI_SIG_RSDP
, strlen(ACPI_SIG_RSDP
)) == 0 &&
1808 valid_rsdp((ACPI_TABLE_RSDP
*)ptr
))
1809 return ((ACPI_TABLE_RSDP
*)ptr
);
1811 ptr
+= ACPI_RSDP_SCAN_STEP
;
1812 len
-= ACPI_RSDP_SCAN_STEP
;
1819 * Refer to ACPI 3.0 Spec, section 5.2.5.1 to understand this function
1821 static ACPI_TABLE_RSDP
*
1824 ACPI_TABLE_RSDP
*rsdp
;
1825 uint64_t rsdp_val
= 0;
1829 /* check for "acpi-root-tab" property */
1830 if (do_bsys_getproplen(NULL
, "acpi-root-tab") == sizeof (uint64_t)) {
1831 (void) do_bsys_getprop(NULL
, "acpi-root-tab", &rsdp_val
);
1832 if (rsdp_val
!= 0) {
1833 rsdp
= scan_rsdp(rsdp_val
, rsdp_val
+ sizeof (*rsdp
));
1837 "Using RSDP from bootloader: "
1838 "0x%p\n", (void *)rsdp
);
1846 * Get the EBDA segment and scan the first 1K
1848 ebda_seg
= (uint16_t *)vmap_phys(sizeof (uint16_t),
1849 ACPI_EBDA_PTR_LOCATION
);
1850 ebda_addr
= *ebda_seg
<< 4;
1851 rsdp
= scan_rsdp(ebda_addr
, ebda_addr
+ ACPI_EBDA_WINDOW_SIZE
);
1853 /* if EBDA doesn't contain RSDP, look in BIOS memory */
1854 rsdp
= scan_rsdp(ACPI_HI_RSDP_WINDOW_BASE
,
1855 ACPI_HI_RSDP_WINDOW_BASE
+ ACPI_HI_RSDP_WINDOW_SIZE
);
1859 static ACPI_TABLE_HEADER
*
1860 map_fw_table(paddr_t table_addr
)
1862 ACPI_TABLE_HEADER
*tp
;
1863 size_t len
= MAX(sizeof (*tp
), MMU_PAGESIZE
);
1866 * Map at least a page; if the table is larger than this, remap it
1868 tp
= (ACPI_TABLE_HEADER
*)vmap_phys(len
, table_addr
);
1869 if (tp
->Length
> len
)
1870 tp
= (ACPI_TABLE_HEADER
*)vmap_phys(tp
->Length
, table_addr
);
1874 static ACPI_TABLE_HEADER
*
1875 find_fw_table(char *signature
)
1877 static int revision
= 0;
1878 static ACPI_TABLE_XSDT
*xsdt
;
1881 ACPI_TABLE_RSDP
*rsdp
;
1882 ACPI_TABLE_HEADER
*tp
;
1886 if (strlen(signature
) != ACPI_NAME_SIZE
)
1890 * Reading the ACPI 3.0 Spec, section 5.2.5.3 will help
1891 * understand this code. If we haven't already found the RSDT/XSDT,
1892 * revision will be 0. Find the RSDP and check the revision
1893 * to find out whether to use the RSDT or XSDT. If revision is
1894 * 0 or 1, use the RSDT and set internal revision to 1; if it is 2,
1895 * use the XSDT. If the XSDT address is 0, though, fall back to
1896 * revision 1 and use the RSDT.
1898 if (revision
== 0) {
1899 if ((rsdp
= find_rsdp()) != NULL
) {
1900 revision
= rsdp
->Revision
;
1902 * ACPI 6.0 states that current revision is 2
1903 * from acpi_table_rsdp definition:
1904 * Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+
1911 * Use the XSDT unless BIOS is buggy and
1912 * claims to be rev 2 but has a null XSDT
1915 xsdt_addr
= rsdp
->XsdtPhysicalAddress
;
1920 /* treat RSDP rev 0 as revision 1 internally */
1924 /* use the RSDT for rev 0/1 */
1925 xsdt_addr
= rsdp
->RsdtPhysicalAddress
;
1928 /* unknown revision */
1936 /* cache the XSDT info */
1937 xsdt
= (ACPI_TABLE_XSDT
*)map_fw_table(xsdt_addr
);
1938 len
= (xsdt
->Header
.Length
- sizeof (xsdt
->Header
)) /
1939 ((revision
== 1) ? sizeof (uint32_t) : sizeof (uint64_t));
1943 * Scan the table headers looking for a signature match
1945 for (n
= 0; n
< len
; n
++) {
1946 ACPI_TABLE_RSDT
*rsdt
= (ACPI_TABLE_RSDT
*)xsdt
;
1947 table_addr
= (revision
== 1) ? rsdt
->TableOffsetEntry
[n
] :
1948 xsdt
->TableOffsetEntry
[n
];
1950 if (table_addr
== 0)
1952 tp
= map_fw_table(table_addr
);
1953 if (strncmp(tp
->Signature
, signature
, ACPI_NAME_SIZE
) == 0) {
1961 process_mcfg(ACPI_TABLE_MCFG
*tp
)
1963 ACPI_MCFG_ALLOCATION
*cfg_baap
;
1965 int64_t ecfginfo
[4];
1967 cfg_baap
= (ACPI_MCFG_ALLOCATION
*)((uintptr_t)tp
+ sizeof (*tp
));
1968 cfg_baa_endp
= ((char *)tp
) + tp
->Header
.Length
;
1969 while ((char *)cfg_baap
< cfg_baa_endp
) {
1970 if (cfg_baap
->Address
!= 0 && cfg_baap
->PciSegment
== 0) {
1971 ecfginfo
[0] = cfg_baap
->Address
;
1972 ecfginfo
[1] = cfg_baap
->PciSegment
;
1973 ecfginfo
[2] = cfg_baap
->StartBusNumber
;
1974 ecfginfo
[3] = cfg_baap
->EndBusNumber
;
1975 bsetprop(MCFG_PROPNAME
, strlen(MCFG_PROPNAME
),
1976 ecfginfo
, sizeof (ecfginfo
));
1984 process_madt_entries(ACPI_TABLE_MADT
*tp
, uint32_t *cpu_countp
,
1985 uint32_t *cpu_possible_countp
, uint32_t *cpu_apicid_array
)
1987 ACPI_SUBTABLE_HEADER
*item
, *end
;
1988 uint32_t cpu_count
= 0;
1989 uint32_t cpu_possible_count
= 0;
1992 * Determine number of CPUs and keep track of "final" APIC ID
1993 * for each CPU by walking through ACPI MADT processor list
1995 end
= (ACPI_SUBTABLE_HEADER
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
1996 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)tp
+ sizeof (*tp
));
1998 while (item
< end
) {
1999 switch (item
->Type
) {
2000 case ACPI_MADT_TYPE_LOCAL_APIC
: {
2001 ACPI_MADT_LOCAL_APIC
*cpu
=
2002 (ACPI_MADT_LOCAL_APIC
*) item
;
2004 if (cpu
->LapicFlags
& ACPI_MADT_ENABLED
) {
2005 if (cpu_apicid_array
!= NULL
)
2006 cpu_apicid_array
[cpu_count
] = cpu
->Id
;
2009 cpu_possible_count
++;
2012 case ACPI_MADT_TYPE_LOCAL_X2APIC
: {
2013 ACPI_MADT_LOCAL_X2APIC
*cpu
=
2014 (ACPI_MADT_LOCAL_X2APIC
*) item
;
2016 if (cpu
->LapicFlags
& ACPI_MADT_ENABLED
) {
2017 if (cpu_apicid_array
!= NULL
)
2018 cpu_apicid_array
[cpu_count
] =
2022 cpu_possible_count
++;
2027 bop_printf(NULL
, "MADT type %d\n", item
->Type
);
2031 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)item
+ item
->Length
);
2034 *cpu_countp
= cpu_count
;
2035 if (cpu_possible_countp
)
2036 *cpu_possible_countp
= cpu_possible_count
;
2040 process_madt(ACPI_TABLE_MADT
*tp
)
2042 uint32_t cpu_count
= 0;
2043 uint32_t cpu_possible_count
= 0;
2044 uint32_t *cpu_apicid_array
; /* x2APIC ID is 32bit! */
2048 process_madt_entries(tp
, &cpu_count
, &cpu_possible_count
, NULL
);
2050 cpu_apicid_array
= (uint32_t *)do_bsys_alloc(NULL
, NULL
,
2051 cpu_count
* sizeof (*cpu_apicid_array
), MMU_PAGESIZE
);
2052 if (cpu_apicid_array
== NULL
)
2053 bop_panic("Not enough memory for APIC ID array");
2056 process_madt_entries(tp
, NULL
, NULL
, cpu_apicid_array
);
2059 * Make boot property for array of "final" APIC IDs for each
2062 bsetprop(BP_CPU_APICID_ARRAY
, strlen(BP_CPU_APICID_ARRAY
),
2063 cpu_apicid_array
, cpu_count
* sizeof (*cpu_apicid_array
));
2067 * Check whether property plat-max-ncpus is already set.
2069 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2071 * Set plat-max-ncpus to number of maximum possible CPUs given
2072 * in MADT if it hasn't been set.
2073 * There's no formal way to detect max possible CPUs supported
2074 * by platform according to ACPI spec3.0b. So current CPU
2075 * hotplug implementation expects that all possible CPUs will
2076 * have an entry in MADT table and set plat-max-ncpus to number
2077 * of entries in MADT.
2078 * With introducing of ACPI4.0, Maximum System Capability Table
2079 * (MSCT) provides maximum number of CPUs supported by platform.
2080 * If MSCT is unavailable, fall back to old way.
2083 bsetpropsi(PLAT_MAX_NCPUS_NAME
, cpu_possible_count
);
2087 * Set boot property boot-max-ncpus to number of CPUs existing at
2088 * boot time. boot-max-ncpus is mainly used for optimization.
2091 bsetpropsi(BOOT_MAX_NCPUS_NAME
, cpu_count
);
2094 * User-set boot-ncpus overrides firmware count
2096 if (do_bsys_getproplen(NULL
, BOOT_NCPUS_NAME
) >= 0)
2100 * Set boot property boot-ncpus to number of active CPUs given in MADT
2101 * if it hasn't been set yet.
2104 bsetpropsi(BOOT_NCPUS_NAME
, cpu_count
);
2108 process_srat(ACPI_TABLE_SRAT
*tp
)
2110 ACPI_SUBTABLE_HEADER
*item
, *end
;
2112 int proc_num
, mem_num
;
2131 uint64_t maxmem
= 0;
2136 proc_num
= mem_num
= 0;
2137 end
= (ACPI_SUBTABLE_HEADER
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2138 item
= (ACPI_SUBTABLE_HEADER
*)((uintptr_t)tp
+ sizeof (*tp
));
2139 while (item
< end
) {
2140 switch (item
->Type
) {
2141 case ACPI_SRAT_TYPE_CPU_AFFINITY
: {
2142 ACPI_SRAT_CPU_AFFINITY
*cpu
=
2143 (ACPI_SRAT_CPU_AFFINITY
*) item
;
2145 if (!(cpu
->Flags
& ACPI_SRAT_CPU_ENABLED
))
2147 processor
.domain
= cpu
->ProximityDomainLo
;
2148 for (i
= 0; i
< 3; i
++)
2150 cpu
->ProximityDomainHi
[i
] << ((i
+ 1) * 8);
2151 processor
.apic_id
= cpu
->ApicId
;
2152 processor
.sapic_id
= cpu
->LocalSapicEid
;
2153 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2155 bsetprop(prop_name
, strlen(prop_name
), &processor
,
2156 sizeof (processor
));
2160 case ACPI_SRAT_TYPE_MEMORY_AFFINITY
: {
2161 ACPI_SRAT_MEM_AFFINITY
*mem
=
2162 (ACPI_SRAT_MEM_AFFINITY
*)item
;
2164 if (!(mem
->Flags
& ACPI_SRAT_MEM_ENABLED
))
2166 memory
.domain
= mem
->ProximityDomain
;
2167 memory
.addr
= mem
->BaseAddress
;
2168 memory
.length
= mem
->Length
;
2169 memory
.flags
= mem
->Flags
;
2170 (void) snprintf(prop_name
, 30, "acpi-srat-memory-%d",
2172 bsetprop(prop_name
, strlen(prop_name
), &memory
,
2174 if ((mem
->Flags
& ACPI_SRAT_MEM_HOT_PLUGGABLE
) &&
2175 (memory
.addr
+ memory
.length
> maxmem
)) {
2176 maxmem
= memory
.addr
+ memory
.length
;
2181 case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY
: {
2182 ACPI_SRAT_X2APIC_CPU_AFFINITY
*x2cpu
=
2183 (ACPI_SRAT_X2APIC_CPU_AFFINITY
*) item
;
2185 if (!(x2cpu
->Flags
& ACPI_SRAT_CPU_ENABLED
))
2187 x2apic
.domain
= x2cpu
->ProximityDomain
;
2188 x2apic
.x2apic_id
= x2cpu
->ApicId
;
2189 (void) snprintf(prop_name
, 30, "acpi-srat-processor-%d",
2191 bsetprop(prop_name
, strlen(prop_name
), &x2apic
,
2198 bop_printf(NULL
, "SRAT type %d\n", item
->Type
);
2202 item
= (ACPI_SUBTABLE_HEADER
*)
2203 (item
->Length
+ (uintptr_t)item
);
2207 * The maximum physical address calculated from the SRAT table is more
2208 * accurate than that calculated from the MSCT table.
2211 plat_dr_physmax
= btop(maxmem
);
2216 process_slit(ACPI_TABLE_SLIT
*tp
)
2220 * Check the number of localities; if it's too huge, we just
2221 * return and locality enumeration code will handle this later,
2224 * Note that the size of the table is the square of the
2225 * number of localities; if the number of localities exceeds
2226 * UINT16_MAX, the table size may overflow an int when being
2227 * passed to bsetprop() below.
2229 if (tp
->LocalityCount
>= SLIT_LOCALITIES_MAX
)
2232 bsetprop(SLIT_NUM_PROPNAME
, strlen(SLIT_NUM_PROPNAME
),
2233 &tp
->LocalityCount
, sizeof (tp
->LocalityCount
));
2234 bsetprop(SLIT_PROPNAME
, strlen(SLIT_PROPNAME
), &tp
->Entry
,
2235 tp
->LocalityCount
* tp
->LocalityCount
);
2238 static ACPI_TABLE_MSCT
*
2239 process_msct(ACPI_TABLE_MSCT
*tp
)
2243 ACPI_MSCT_PROXIMITY
*item
, *end
;
2244 extern uint64_t plat_dr_options
;
2248 end
= (ACPI_MSCT_PROXIMITY
*)(tp
->Header
.Length
+ (uintptr_t)tp
);
2249 for (item
= (void *)((uintptr_t)tp
+ tp
->ProximityOffset
);
2251 item
= (void *)(item
->Length
+ (uintptr_t)item
)) {
2253 * Sanity check according to section 5.2.19.1 of ACPI 4.0.
2257 if (item
->Revision
!= 1 || item
->Length
!= 22) {
2259 "?boot: unknown proximity domain structure in MSCT "
2260 "with Revision(%d), Length(%d).\n",
2261 (int)item
->Revision
, (int)item
->Length
);
2263 } else if (item
->RangeStart
> item
->RangeEnd
) {
2265 "?boot: invalid proximity domain structure in MSCT "
2266 "with RangeStart(%u), RangeEnd(%u).\n",
2267 item
->RangeStart
, item
->RangeEnd
);
2269 } else if (item
->RangeStart
!= last_seen
) {
2271 * Items must be organized in ascending order of the
2272 * proximity domain enumerations.
2275 "?boot: invalid proximity domain structure in MSCT,"
2276 " items are not orginized in ascending order.\n");
2281 * If ProcessorCapacity is 0 then there would be no CPUs in this
2284 if (item
->ProcessorCapacity
!= 0) {
2285 proc_num
+= (item
->RangeEnd
- item
->RangeStart
+ 1) *
2286 item
->ProcessorCapacity
;
2289 last_seen
= item
->RangeEnd
- item
->RangeStart
+ 1;
2291 * Break out if all proximity domains have been processed.
2292 * Some BIOSes may have unused items at the end of MSCT table.
2294 if (last_seen
> tp
->MaxProximityDomains
) {
2298 if (last_seen
!= tp
->MaxProximityDomains
+ 1) {
2300 "?boot: invalid proximity domain structure in MSCT, "
2301 "proximity domain count doesn't match.\n");
2306 * Set plat-max-ncpus property if it hasn't been set yet.
2308 if (do_bsys_getproplen(NULL
, PLAT_MAX_NCPUS_NAME
) < 0) {
2309 if (proc_num
!= 0) {
2310 bsetpropsi(PLAT_MAX_NCPUS_NAME
, proc_num
);
2315 * Use Maximum Physical Address from the MSCT table as upper limit for
2316 * memory hot-adding by default. It may be overridden by value from
2317 * the SRAT table or the "plat-dr-physmax" boot option.
2319 plat_dr_physmax
= btop(tp
->MaxAddress
+ 1);
2322 * Existence of MSCT implies CPU/memory hotplug-capability for the
2325 plat_dr_options
|= PLAT_DR_FEATURE_CPU
;
2326 plat_dr_options
|= PLAT_DR_FEATURE_MEMORY
;
2334 build_firmware_properties(struct xboot_info
*xbp
)
2336 ACPI_TABLE_HEADER
*tp
= NULL
;
2338 if (xbp
->bi_uefi_arch
== XBI_UEFI_ARCH_64
) {
2339 bsetprops("efi-systype", "64");
2340 bsetprop64("efi-systab",
2341 (uint64_t)(uintptr_t)xbp
->bi_uefi_systab
);
2343 bop_printf(NULL
, "64-bit UEFI detected.\n");
2344 } else if (xbp
->bi_uefi_arch
== XBI_UEFI_ARCH_32
) {
2345 bsetprops("efi-systype", "32");
2346 bsetprop64("efi-systab",
2347 (uint64_t)(uintptr_t)xbp
->bi_uefi_systab
);
2349 bop_printf(NULL
, "32-bit UEFI detected.\n");
2352 if (xbp
->bi_acpi_rsdp
!= NULL
) {
2353 bsetprop64("acpi-root-tab",
2354 (uint64_t)(uintptr_t)xbp
->bi_acpi_rsdp
);
2357 if (xbp
->bi_smbios
!= NULL
) {
2358 bsetprop64("smbios-address",
2359 (uint64_t)(uintptr_t)xbp
->bi_smbios
);
2362 if ((tp
= find_fw_table(ACPI_SIG_MSCT
)) != NULL
)
2363 msct_ptr
= process_msct((ACPI_TABLE_MSCT
*)tp
);
2367 if ((tp
= find_fw_table(ACPI_SIG_MADT
)) != NULL
)
2368 process_madt((ACPI_TABLE_MADT
*)tp
);
2370 if ((srat_ptr
= (ACPI_TABLE_SRAT
*)
2371 find_fw_table(ACPI_SIG_SRAT
)) != NULL
)
2372 process_srat(srat_ptr
);
2374 if (slit_ptr
= (ACPI_TABLE_SLIT
*)find_fw_table(ACPI_SIG_SLIT
))
2375 process_slit(slit_ptr
);
2377 tp
= find_fw_table(ACPI_SIG_MCFG
);
2379 process_mcfg((ACPI_TABLE_MCFG
*)tp
);
2383 * fake up a boot property for deferred early console output
2384 * this is used by both graphical boot and the (developer only)
2385 * USB serial console
2388 defcons_init(size_t size
)
2390 static char *p
= NULL
;
2392 p
= do_bsys_alloc(NULL
, NULL
, size
, MMU_PAGESIZE
);
2394 bsetprop("deferred-console-buf", strlen("deferred-console-buf") + 1,
2401 boot_compinfo(int fd
, struct compinfo
*cbp
)
2404 cbp
->blksize
= MAXBSIZE
;
2408 #define BP_MAX_STRLEN 32
2411 * Get value for given boot property
2414 bootprop_getval(const char *prop_name
, u_longlong_t
*prop_value
)
2417 char str
[BP_MAX_STRLEN
];
2420 boot_prop_len
= BOP_GETPROPLEN(bootops
, prop_name
);
2421 if (boot_prop_len
< 0 || boot_prop_len
> sizeof (str
) ||
2422 BOP_GETPROP(bootops
, prop_name
, str
) < 0 ||
2423 kobj_getvalue(str
, &value
) == -1)
2427 *prop_value
= value
;