Merge commit '9276b3991ba20d5a5660887ba81b0bc7bed25a0c'
[unleashed.git] / arch / x86 / kernel / platform / i86pc / os / fakebop.c
blobe5834d8a28ccd95739b2fb353423d280176beffe
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
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>
58 #include <sys/kobj.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>
65 #include <sys/kobj.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 = "";
76 * Debugging macros
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) { \
85 char *cp; \
86 for (cp = (s); *cp; ++cp) \
87 bcons_putchar(*cp); \
90 bootops_t bootop; /* simple bootops we'll pass on to kernel */
91 struct bsys_mem bm;
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;
113 char *bp_name;
114 uint_t bp_vlen;
115 char *bp_value;
116 } bootprop_t;
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.
180 paddr_t
181 do_bop_phys_alloc(uint64_t size, uint64_t align)
183 paddr_t pa = 0;
184 paddr_t start;
185 paddr_t end;
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
201 #if defined(__i386)
202 if (xbootp->bi_use_pae == 0 && high_phys > FOUR_GIG)
203 high_phys = FOUR_GIG;
204 #endif
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);
215 if (end > high_phys)
216 end = P2ALIGN(high_phys, align);
218 if (end <= start)
219 continue;
220 if (end - start < size)
221 continue;
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)
229 pa = start;
230 } else {
231 if (end - size > pa)
232 pa = end - size;
235 if (pa != 0) {
236 if (early_allocation)
237 next_phys = pa + size;
238 else
239 high_phys = pa;
240 return (pa);
242 bop_panic("do_bop_phys_alloc(0x%" PRIx64 ", 0x%" PRIx64
243 ") Out of memory\n", size, align);
244 /*NOTREACHED*/
247 uintptr_t
248 alloc_vaddr(size_t size, paddr_t align)
250 uintptr_t rv;
252 next_virt = P2ROUNDUP(next_virt, (uintptr_t)align);
253 rv = (uintptr_t)next_virt;
254 next_virt += size;
255 return (rv);
259 * Allocate virtual memory. The size is always rounded up to a multiple
260 * of base pagesize.
263 /*ARGSUSED*/
264 static caddr_t
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 */
268 uint_t pgsize;
269 paddr_t pa;
270 uintptr_t va;
271 ssize_t s; /* the aligned size */
272 uint_t level;
273 uint_t is_kernel = (virthint != 0);
275 if (a < MMU_PAGESIZE)
276 a = MMU_PAGESIZE;
277 else if (!ISP2(a))
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;
287 } else {
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;
300 s = size;
301 level = 1;
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) &&
305 s >= pgsize) {
306 kbm_map(va, pa, level, is_kernel);
307 va += pgsize;
308 pa += pgsize;
309 s -= pgsize;
314 * Map remaining pages use small mappings
316 level = 0;
317 pgsize = MMU_PAGESIZE;
318 while (s > 0) {
319 kbm_map(va, pa, level, is_kernel);
320 va += pgsize;
321 pa += pgsize;
322 s -= pgsize;
324 return (virthint);
328 * Free virtual memory - we'll just ignore these.
330 /*ARGSUSED*/
331 static void
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",
335 (void *)virt, size);
339 * Old interface
341 /*ARGSUSED*/
342 static caddr_t
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");
347 return (0);
351 static void
352 bsetprop(char *name, int nlen, void *value, int vlen)
354 uint_t size;
355 uint_t need_size;
356 bootprop_t *b;
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);
375 b->bp_next = bprops;
376 bprops = b;
379 * follow by name and ending zero byte
381 b->bp_name = curr_page;
382 bcopy(name, curr_page, nlen);
383 curr_page += nlen;
384 *curr_page++ = 0;
385 curr_space -= nlen + 1;
388 * copy in value, but no ending zero byte
390 b->bp_value = curr_page;
391 b->bp_vlen = vlen;
392 if (vlen > 0) {
393 bcopy(value, curr_page, vlen);
394 curr_page += vlen;
395 curr_space -= vlen;
399 * align new values of curr_page, curr_space
401 while (curr_space & 0xf) {
402 ++curr_page;
403 --curr_space;
407 static void
408 bsetprops(char *name, char *value)
410 bsetprop(name, strlen(name), value, strlen(value) + 1);
413 static void
414 bsetprop64(char *name, uint64_t value)
416 bsetprop(name, strlen(name), (void *)&value, sizeof (value));
419 static void
420 bsetpropsi(char *name, int value)
422 char prop_val[32];
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
431 /*ARGSUSED*/
433 do_bsys_getproplen(bootops_t *bop, const char *name)
435 bootprop_t *b;
437 for (b = bprops; b; b = b->bp_next) {
438 if (strcmp(name, b->bp_name) != 0)
439 continue;
440 return (b->bp_vlen);
442 return (-1);
446 * get the value associated with this name
448 /*ARGSUSED*/
450 do_bsys_getprop(bootops_t *bop, const char *name, void *value)
452 bootprop_t *b;
454 for (b = bprops; b; b = b->bp_next) {
455 if (strcmp(name, b->bp_name) != 0)
456 continue;
457 bcopy(b->bp_value, value, b->bp_vlen);
458 return (0);
460 return (-1);
464 * get the name of the next property in succession from the standalone
466 /*ARGSUSED*/
467 static char *
468 do_bsys_nextprop(bootops_t *bop, char *name)
470 bootprop_t *b;
473 * A null name is a special signal for the 1st boot property
475 if (name == NULL || strlen(name) == 0) {
476 if (bprops == NULL)
477 return (NULL);
478 return (bprops->bp_name);
481 for (b = bprops; b; b = b->bp_next) {
482 if (name != b->bp_name)
483 continue;
484 b = b->bp_next;
485 if (b == NULL)
486 return (NULL);
487 return (b->bp_name);
489 return (NULL);
493 * Parse numeric value from a string. Understands decimal, hex, octal, - and ~
495 static int
496 parse_value(char *p, uint64_t *retval)
498 int adjust = 0;
499 uint64_t tmp = 0;
500 int digit;
501 int radix = 10;
503 *retval = 0;
504 if (*p == '-' || *p == '~')
505 adjust = *p++;
507 if (*p == '0') {
508 ++p;
509 if (*p == 0)
510 return (0);
511 if (*p == 'x' || *p == 'X') {
512 radix = 16;
513 ++p;
514 } else {
515 radix = 8;
516 ++p;
519 while (*p) {
520 if ('0' <= *p && *p <= '9')
521 digit = *p - '0';
522 else if ('a' <= *p && *p <= 'f')
523 digit = 10 + *p - 'a';
524 else if ('A' <= *p && *p <= 'F')
525 digit = 10 + *p - 'A';
526 else
527 return (-1);
528 if (digit >= radix)
529 return (-1);
530 tmp = tmp * radix + digit;
531 ++p;
533 if (adjust == '-')
534 tmp = -tmp;
535 else if (adjust == '~')
536 tmp = ~tmp;
537 *retval = tmp;
538 return (0);
541 static boolean_t
542 unprintable(char *value, int size)
544 int i;
546 if (size <= 0 || value[0] == '\0')
547 return (B_TRUE);
549 for (i = 0; i < size; i++) {
550 if (value[i] == '\0')
551 return (i != (size - 1));
553 if (!isprint(value[i]))
554 return (B_TRUE);
556 return (B_FALSE);
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.
564 static void
565 boot_prop_display(char *buffer)
567 char *name = "";
568 int i, len;
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)) {
578 buffer[len] = 0;
579 bop_printf(NULL, "%s\n", buffer);
580 continue;
582 for (i = 0; i < len; i++) {
583 bop_printf(NULL, "%02x", buffer[i] & 0xff);
584 if (i < len - 1)
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:
596 * ^$
597 * ^# comment till end of line
598 * setprop name 'value'
599 * setprop name value
600 * setprop name "value"
602 * we do single character I/O since this is really just looking at memory
604 void
605 boot_prop_finish(void)
607 int fd;
608 char *line;
609 int c;
610 int bytes_read;
611 char *name;
612 int n_len;
613 char *value;
614 int v_len;
615 char *inputdev; /* these override the command line if serial ports */
616 char *outputdev;
617 char *consoledev;
618 uint64_t lvalue;
619 int use_xencons = 0;
622 DBG_MSG("Opening /boot/solaris/bootenv.rc\n");
623 fd = BRD_OPEN(bfs_ops, "/boot/solaris/bootenv.rc", 0);
624 DBG(fd);
626 line = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, MMU_PAGESIZE);
627 while (fd >= 0) {
630 * get a line
632 for (c = 0; ; ++c) {
633 bytes_read = BRD_READ(bfs_ops, fd, line + c, 1);
634 if (bytes_read == 0) {
635 if (c == 0)
636 goto done;
637 break;
639 if (line[c] == '\n')
640 break;
642 line[c] = 0;
645 * ignore comment lines
647 c = 0;
648 while (ISSPACE(line[c]))
649 ++c;
650 if (line[c] == '#' || line[c] == 0)
651 continue;
654 * must have "setprop " or "setprop\t"
656 if (strncmp(line + c, "setprop ", 8) != 0 &&
657 strncmp(line + c, "setprop\t", 8) != 0)
658 continue;
659 c += 8;
660 while (ISSPACE(line[c]))
661 ++c;
662 if (line[c] == 0)
663 continue;
666 * gather up the property name
668 name = line + c;
669 n_len = 0;
670 while (line[c] && !ISSPACE(line[c]))
671 ++n_len, ++c;
674 * gather up the value, if any
676 value = "";
677 v_len = 0;
678 while (ISSPACE(line[c]))
679 ++c;
680 if (line[c] != 0) {
681 value = line + c;
682 while (line[c] && !ISSPACE(line[c]))
683 ++v_len, ++c;
686 if (v_len >= 2 && value[0] == value[v_len - 1] &&
687 (value[0] == '\'' || value[0] == '"')) {
688 ++value;
689 v_len -= 2;
691 name[n_len] = 0;
692 if (v_len > 0)
693 value[v_len] = 0;
694 else
695 continue;
698 * ignore "boot-file" property, it's now meaningless
700 if (strcmp(name, "boot-file") == 0)
701 continue;
702 if (strcmp(name, "boot-args") == 0 &&
703 strlen(boot_args) > 0)
704 continue;
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)
711 continue;
713 bsetprop(name, n_len, value, v_len + 1);
715 done:
716 if (fd >= 0)
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;
727 DBG(physmem);
730 early_allocation = 0;
733 * check to see if we have to override the default value of the console
735 if (!use_xencons) {
736 inputdev = line;
737 v_len = do_bsys_getproplen(NULL, "input-device");
738 if (v_len > 0)
739 (void) do_bsys_getprop(NULL, "input-device", inputdev);
740 else
741 v_len = 0;
742 inputdev[v_len] = 0;
744 outputdev = inputdev + v_len + 1;
745 v_len = do_bsys_getproplen(NULL, "output-device");
746 if (v_len > 0)
747 (void) do_bsys_getprop(NULL, "output-device",
748 outputdev);
749 else
750 v_len = 0;
751 outputdev[v_len] = 0;
753 consoledev = outputdev + v_len + 1;
754 v_len = do_bsys_getproplen(NULL, "console");
755 if (v_len > 0) {
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);
763 } else {
764 v_len = 0;
766 consoledev[v_len] = 0;
767 bcons_init2(inputdev, outputdev, consoledev);
768 } else {
770 * Ensure console property exists
771 * If not create it as "hypervisor"
773 v_len = do_bsys_getproplen(NULL, "console");
774 if (v_len < 0)
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
787 /*PRINTFLIKE2*/
788 /*ARGSUSED*/
789 void
790 bop_printf(bootops_t *bop, const char *fmt, ...)
792 va_list ap;
794 if (have_console == 0)
795 return;
797 va_start(ap, fmt);
798 (void) vsnprintf(buffer, BUFFERSIZE, fmt, ap);
799 va_end(ap);
800 PUT_STRING(buffer);
804 * Another panic() variant; this one can be used even earlier during boot than
805 * prom_panic().
807 /*PRINTFLIKE1*/
808 void
809 bop_panic(const char *fmt, ...)
811 va_list ap;
813 va_start(ap, fmt);
814 bop_printf(NULL, fmt, ap);
815 va_end(ap);
817 bop_printf(NULL, "\nPress any key to reboot.\n");
818 (void) bcons_getchar();
819 bop_printf(NULL, "Resetting...\n");
820 pc_reset();
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;
828 } bios_regs_t;
829 typedef int (*bios_func_t)(int, bios_regs_t *);
831 /*ARGSUSED*/
832 static void
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;
837 bios_regs_t br;
840 * The first time we do this, we have to copy the pre-packaged
841 * low memory bios call code image into place.
843 if (firsttime) {
844 extern char bios_image[];
845 extern uint32_t bios_size;
847 bcopy(bios_image, (void *)bios_func, bios_size);
848 firsttime = 0;
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;
858 br.ds = rp->ds;
859 br.es = rp->es;
861 DBG_MSG("Doing BIOS call...");
862 DBG(br.ax);
863 DBG(br.bx);
864 DBG(br.dx);
865 rp->eflags = bios_func(intnum, &br);
866 DBG_MSG("done\n");
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;
875 rp->ds = br.ds;
876 rp->es = br.es;
879 static struct boot_syscalls bop_sysp = {
880 bcons_getchar,
881 bcons_putchar,
882 bcons_ischar,
885 static char *whoami;
887 #define BUFLEN 64
890 static void
891 setup_rarp_props(struct sol_netinfo *sip)
893 char buf[BUFLEN]; /* to hold ip/mac addrs */
894 uint8_t *val;
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);
923 } else {
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);
932 static void
933 build_panic_cmdline(const char *cmd, int cmdlen)
935 int proplen;
936 size_t arglen;
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))
948 arglen = 1;
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;
958 } else {
959 bcopy(cmd, fastreboot_onpanic_cmdline, cmdlen);
960 if (arglen != 1)
961 bcopy(fastreboot_onpanic_args,
962 fastreboot_onpanic_cmdline + cmdlen, arglen);
963 else
964 fastreboot_onpanic_cmdline[cmdlen] = 0;
970 * Construct boot command line for Fast Reboot. The saved_cmdline
971 * is also reported by "eeprom bootcmd".
973 static void
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;
981 } else {
982 bcopy((void *)(xbp->bi_cmdline), (void *)saved_cmdline,
983 saved_cmdline_len);
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
991 * Fast Reboot.
993 static void
994 save_boot_info(struct xboot_info *xbi)
996 multiboot_info_t *mbi = xbi->bi_mb_info;
997 struct boot_modules *modp;
998 int i;
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;
1005 } else {
1006 bcopy((void *)(uintptr_t)mbi->mmap_addr, (void *)saved_mmap,
1007 mbi->mmap_length);
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;
1016 } else {
1017 bcopy((void *)(uintptr_t)mbi->drives_addr,
1018 (void *)saved_drives, mbi->drives_length);
1020 } else {
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;
1053 int bl_name_len;
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.
1084 static boolean_t
1085 name_is_blacklisted(const char *name)
1087 int i, n;
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) {
1093 return (B_TRUE);
1096 return (B_FALSE);
1099 static void
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)
1106 return;
1107 ptr = env = benv->bm_addr;
1108 size = benv->bm_size;
1109 do {
1110 name = ptr;
1111 /* find '=' */
1112 while (*ptr != '=') {
1113 ptr++;
1114 if (ptr > env + size) /* Something is very wrong. */
1115 return;
1117 name_len = ptr - name;
1118 if (sizeof (buffer) <= name_len)
1119 continue;
1121 (void) strncpy(buffer, name, sizeof (buffer));
1122 buffer[name_len] = '\0';
1123 name = buffer;
1125 value_len = 0;
1126 value = ++ptr;
1127 while ((uintptr_t)ptr - (uintptr_t)env < size) {
1128 if (*ptr == '\0') {
1129 ptr++;
1130 value_len = (uintptr_t)ptr - (uintptr_t)env;
1131 break;
1133 ptr++;
1136 /* Did we reach the end of the module? */
1137 if (value_len == 0)
1138 return;
1140 if (*value == '\0')
1141 continue;
1143 /* Is this property already set? */
1144 if (do_bsys_getproplen(NULL, name) >= 0)
1145 continue;
1147 if (name_is_blacklisted(name) == B_TRUE)
1148 continue;
1150 /* Create new property. */
1151 bsetprops(name, value);
1153 /* Avoid reading past the module end. */
1154 if (size <= (uintptr_t)ptr - (uintptr_t)env)
1155 return;
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
1170 static void
1171 build_boot_properties(struct xboot_info *xbp)
1173 char *name;
1174 int name_len;
1175 char *value;
1176 int value_len;
1177 struct boot_modules *bm, *rdbm, *benv = NULL;
1178 char *propbuf;
1179 int quoted = 0;
1180 int boot_arg_len;
1181 uint_t i, midx;
1182 char modid[32];
1183 static int stdout_val = 0;
1184 uchar_t boot_device;
1185 char str[3];
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;
1195 rdbm = NULL;
1196 for (midx = i = 0; i < xbp->bi_module_cnt; i++) {
1197 if (bm[i].bm_type == BMT_ROOTFS) {
1198 rdbm = &bm[i];
1199 continue;
1201 if (bm[i].bm_type == BMT_HASH || bm[i].bm_name == NULL)
1202 continue;
1204 if (bm[i].bm_type == BMT_ENV) {
1205 if (benv == NULL)
1206 benv = &bm[i];
1207 else
1208 continue;
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);
1220 ++midx;
1222 if (rdbm != NULL) {
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
1232 * fast reboot.
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);
1257 boot_args[0] = 0;
1258 boot_arg_len = 0;
1261 while (ISSPACE(*value))
1262 ++value;
1264 * value now points at the boot-file
1266 value_len = 0;
1267 while (value[value_len] && !ISSPACE(value[value_len]))
1268 ++value_len;
1269 if (value_len > 0) {
1270 whoami = propbuf;
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
1286 * command line.
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;
1296 ++name;
1297 continue;
1301 * skip the " -B" and following white space
1303 name += 3;
1304 while (ISSPACE(*name))
1305 ++name;
1306 while (*name && !ISSPACE(*name)) {
1307 value = strstr(name, "=");
1308 if (value == NULL)
1309 break;
1310 name_len = value - name;
1311 ++value;
1312 value_len = 0;
1313 quoted = 0;
1314 for (; ; ++value_len) {
1315 if (!value[value_len])
1316 break;
1319 * is this value quoted?
1321 if (value_len == 0 &&
1322 (value[0] == '\'' || value[0] == '"')) {
1323 quoted = value[0];
1324 ++value_len;
1328 * In the quote accept any character,
1329 * but look for ending quote.
1331 if (quoted) {
1332 if (value[value_len] == quoted)
1333 quoted = 0;
1334 continue;
1338 * a comma or white space ends the value
1340 if (value[value_len] == ',' ||
1341 ISSPACE(value[value_len]))
1342 break;
1345 if (value_len == 0) {
1346 bsetprop(name, name_len, "true", 5);
1347 } else {
1348 char *v = value;
1349 int l = value_len;
1350 if (v[0] == v[l - 1] &&
1351 (v[0] == '\'' || v[0] == '"')) {
1352 ++v;
1353 l -= 2;
1355 bcopy(v, propbuf, l);
1356 propbuf[l] = '\0';
1357 bsetprop(name, name_len, propbuf,
1358 l + 1);
1360 name = value + value_len;
1361 while (*name == ',')
1362 ++name;
1367 * set boot-args property
1368 * 1275 name is bootargs, so set
1369 * that too
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;
1383 int netboot;
1384 struct sol_netinfo *sip;
1387 * set the BIOS boot device from GRUB
1389 netboot = 0;
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)
1399 netboot++;
1400 str[0] = (boot_device >> 4) + '0';
1401 str[1] = (boot_device & 0xf) + '0';
1402 str[2] = 0;
1403 bsetprops("bios-boot-device", str);
1404 } else {
1405 netboot = 1;
1409 * In the netboot case, drives_info is overloaded with the
1410 * dhcp ack. This is not multiboot compliant and requires
1411 * special pxegrub!
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);
1423 } else {
1424 multiboot2_info_header_t *mbi = xbp->bi_mb_info;
1425 multiboot_tag_bootdev_t *bootdev = NULL;
1426 multiboot_tag_network_t *netdev = NULL;
1428 if (mbi != 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';
1439 str[2] = 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,
1445 netdev->mb_size -
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);
1465 * XXPV
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:
1474 * - netdev-path
1475 * - fstype
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.
1485 #ifdef __amd64
1486 static const int bcode_sel = B64CODE_SEL;
1487 #else
1488 static const int bcode_sel = B32CODE_SEL;
1489 #endif
1492 * simple description of a stack frame (args are 32 bit only currently)
1494 typedef struct bop_frame {
1495 struct bop_frame *old_frame;
1496 pc_t retaddr;
1497 long arg[1];
1498 } bop_frame_t;
1500 void
1501 bop_traceback(bop_frame_t *frame)
1503 pc_t pc;
1504 int cnt;
1505 char *ksym;
1506 ulong_t off;
1507 #if defined(__i386)
1508 int a;
1509 #endif
1511 bop_printf(NULL, "Stack traceback:\n");
1512 for (cnt = 0; cnt < 30; ++cnt) { /* up to 30 frames */
1513 pc = frame->retaddr;
1514 if (pc == 0)
1515 break;
1516 ksym = kobj_getsymname(pc, &off);
1517 if (ksym)
1518 bop_printf(NULL, " %s+%lx", ksym, off);
1519 else
1520 bop_printf(NULL, " 0x%lx", pc);
1522 frame = frame->old_frame;
1523 if (frame == 0) {
1524 bop_printf(NULL, "\n");
1525 break;
1527 #if defined(__i386)
1528 for (a = 0; a < 6; ++a) { /* try for 6 args */
1529 if ((void *)&frame->arg[a] == (void *)frame->old_frame)
1530 break;
1531 if (a == 0)
1532 bop_printf(NULL, "(");
1533 else
1534 bop_printf(NULL, ",");
1535 bop_printf(NULL, "0x%lx", frame->arg[a]);
1537 bop_printf(NULL, ")");
1538 #endif
1539 bop_printf(NULL, "\n");
1543 struct trapframe {
1544 ulong_t error_code; /* optional */
1545 ulong_t inst_ptr;
1546 ulong_t code_seg;
1547 ulong_t flags_reg;
1548 #ifdef __amd64
1549 ulong_t stk_ptr;
1550 ulong_t stk_seg;
1551 #endif
1554 void
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.
1564 if (++depth > 2)
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);
1574 else
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);
1581 #ifdef __amd64
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);
1584 #endif
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;
1600 static void
1601 bop_idt_init(void)
1603 int t;
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()
1626 void
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
1635 xbootp = xbp;
1637 if (*((uint32_t *)(FASTBOOT_SWTCH_PA + FASTBOOT_STACK_OFFSET)) ==
1638 FASTBOOT_MAGIC) {
1639 post_fastreboot = 1;
1640 *((uint32_t *)(FASTBOOT_SWTCH_PA + FASTBOOT_STACK_OFFSET)) = 0;
1643 bcons_init(xbp);
1644 have_console = 1;
1647 * enable debugging
1649 if (find_boot_prop("kbm_debug") != NULL)
1650 kbm_debug = 1;
1652 DBG_MSG("\n\n*** Entered Solaris in _start() cmdline is: ");
1653 DBG_MSG((char *)xbp->bi_cmdline);
1654 DBG_MSG("\n\n\n");
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;
1668 DBG(next_phys);
1669 next_virt = (uintptr_t)xbp->bi_next_vaddr;
1670 DBG(next_virt);
1671 DBG_MSG("Initializing boot time memory management...");
1672 kbm_init(xbp);
1673 DBG_MSG("done\n");
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.
1698 bop_idt_init();
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) {
1707 char *value;
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);
1720 /*ARGSUSED*/
1721 static caddr_t
1722 no_more_alloc(bootops_t *bop, caddr_t virthint, size_t size, int align)
1724 panic("Attempt to bsys_alloc() too late\n");
1725 return (NULL);
1728 /*ARGSUSED*/
1729 static void
1730 no_more_free(bootops_t *bop, caddr_t virt, size_t size)
1732 panic("Attempt to bsys_free() too late\n");
1735 void
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
1749 static caddr_t
1750 vmap_phys(size_t length, paddr_t pa)
1752 paddr_t start, end;
1753 caddr_t va;
1754 size_t len, page;
1756 start = P2ALIGN(pa, MMU_PAGESIZE);
1757 end = P2ROUNDUP(pa + length, MMU_PAGESIZE);
1758 len = end - start;
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));
1765 static uint8_t
1766 checksum_table(uint8_t *tp, size_t len)
1768 uint8_t sum = 0;
1770 while (len-- > 0)
1771 sum += *tp++;
1773 return (sum);
1776 static int
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)
1782 return (0);
1784 /* If pre-ACPI 2.0, this is a valid RSDP */
1785 if (rp->Revision < 2)
1786 return (1);
1788 /* validate the V2.x checksum */
1789 if (checksum_table((uint8_t *)rp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0)
1790 return (0);
1792 return (1);
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;
1803 caddr_t ptr;
1805 ptr = vmap_phys(len, start);
1806 while (len > 0) {
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;
1815 return (NULL);
1819 * Refer to ACPI 3.0 Spec, section 5.2.5.1 to understand this function
1821 static ACPI_TABLE_RSDP *
1822 find_rsdp()
1824 ACPI_TABLE_RSDP *rsdp;
1825 uint64_t rsdp_val = 0;
1826 uint16_t *ebda_seg;
1827 paddr_t ebda_addr;
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));
1834 if (rsdp != NULL) {
1835 if (kbm_debug) {
1836 bop_printf(NULL,
1837 "Using RSDP from bootloader: "
1838 "0x%p\n", (void *)rsdp);
1840 return (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);
1852 if (rsdp == NULL)
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);
1856 return (rsdp);
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);
1871 return (tp);
1874 static ACPI_TABLE_HEADER *
1875 find_fw_table(char *signature)
1877 static int revision = 0;
1878 static ACPI_TABLE_XSDT *xsdt;
1879 static int len;
1880 paddr_t xsdt_addr;
1881 ACPI_TABLE_RSDP *rsdp;
1882 ACPI_TABLE_HEADER *tp;
1883 paddr_t table_addr;
1884 int n;
1886 if (strlen(signature) != ACPI_NAME_SIZE)
1887 return (NULL);
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+
1906 if (revision > 2)
1907 revision = 2;
1908 switch (revision) {
1909 case 2:
1911 * Use the XSDT unless BIOS is buggy and
1912 * claims to be rev 2 but has a null XSDT
1913 * address
1915 xsdt_addr = rsdp->XsdtPhysicalAddress;
1916 if (xsdt_addr != 0)
1917 break;
1918 /* FALLTHROUGH */
1919 case 0:
1920 /* treat RSDP rev 0 as revision 1 internally */
1921 revision = 1;
1922 /* FALLTHROUGH */
1923 case 1:
1924 /* use the RSDT for rev 0/1 */
1925 xsdt_addr = rsdp->RsdtPhysicalAddress;
1926 break;
1927 default:
1928 /* unknown revision */
1929 revision = 0;
1930 break;
1933 if (revision == 0)
1934 return (NULL);
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)
1951 continue;
1952 tp = map_fw_table(table_addr);
1953 if (strncmp(tp->Signature, signature, ACPI_NAME_SIZE) == 0) {
1954 return (tp);
1957 return (NULL);
1960 static void
1961 process_mcfg(ACPI_TABLE_MCFG *tp)
1963 ACPI_MCFG_ALLOCATION *cfg_baap;
1964 char *cfg_baa_endp;
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));
1977 break;
1979 cfg_baap++;
1983 static void
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;
2007 cpu_count++;
2009 cpu_possible_count++;
2010 break;
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] =
2019 cpu->LocalApicId;
2020 cpu_count++;
2022 cpu_possible_count++;
2023 break;
2025 default:
2026 if (kbm_debug)
2027 bop_printf(NULL, "MADT type %d\n", item->Type);
2028 break;
2031 item = (ACPI_SUBTABLE_HEADER *)((uintptr_t)item + item->Length);
2033 if (cpu_countp)
2034 *cpu_countp = cpu_count;
2035 if (cpu_possible_countp)
2036 *cpu_possible_countp = cpu_possible_count;
2039 static void
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! */
2046 if (tp != NULL) {
2047 /* count cpu's */
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");
2055 /* copy IDs */
2056 process_madt_entries(tp, NULL, NULL, cpu_apicid_array);
2059 * Make boot property for array of "final" APIC IDs for each
2060 * CPU
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.
2082 if (tp != NULL)
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.
2090 if (tp != NULL)
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)
2097 return;
2100 * Set boot property boot-ncpus to number of active CPUs given in MADT
2101 * if it hasn't been set yet.
2103 if (tp != NULL)
2104 bsetpropsi(BOOT_NCPUS_NAME, cpu_count);
2107 static void
2108 process_srat(ACPI_TABLE_SRAT *tp)
2110 ACPI_SUBTABLE_HEADER *item, *end;
2111 int i;
2112 int proc_num, mem_num;
2113 #pragma pack(1)
2114 struct {
2115 uint32_t domain;
2116 uint32_t apic_id;
2117 uint32_t sapic_id;
2118 } processor;
2119 struct {
2120 uint32_t domain;
2121 uint32_t x2apic_id;
2122 } x2apic;
2123 struct {
2124 uint32_t domain;
2125 uint64_t addr;
2126 uint64_t length;
2127 uint32_t flags;
2128 } memory;
2129 #pragma pack()
2130 char prop_name[30];
2131 uint64_t maxmem = 0;
2133 if (tp == NULL)
2134 return;
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))
2146 break;
2147 processor.domain = cpu->ProximityDomainLo;
2148 for (i = 0; i < 3; i++)
2149 processor.domain +=
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",
2154 proc_num);
2155 bsetprop(prop_name, strlen(prop_name), &processor,
2156 sizeof (processor));
2157 proc_num++;
2158 break;
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))
2165 break;
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",
2171 mem_num);
2172 bsetprop(prop_name, strlen(prop_name), &memory,
2173 sizeof (memory));
2174 if ((mem->Flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) &&
2175 (memory.addr + memory.length > maxmem)) {
2176 maxmem = memory.addr + memory.length;
2178 mem_num++;
2179 break;
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))
2186 break;
2187 x2apic.domain = x2cpu->ProximityDomain;
2188 x2apic.x2apic_id = x2cpu->ApicId;
2189 (void) snprintf(prop_name, 30, "acpi-srat-processor-%d",
2190 proc_num);
2191 bsetprop(prop_name, strlen(prop_name), &x2apic,
2192 sizeof (x2apic));
2193 proc_num++;
2194 break;
2196 default:
2197 if (kbm_debug)
2198 bop_printf(NULL, "SRAT type %d\n", item->Type);
2199 break;
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.
2210 if (maxmem != 0) {
2211 plat_dr_physmax = btop(maxmem);
2215 static void
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,
2222 * if possible.
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)
2230 return;
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)
2241 int last_seen = 0;
2242 int proc_num = 0;
2243 ACPI_MSCT_PROXIMITY *item, *end;
2244 extern uint64_t plat_dr_options;
2246 ASSERT(tp != NULL);
2248 end = (ACPI_MSCT_PROXIMITY *)(tp->Header.Length + (uintptr_t)tp);
2249 for (item = (void *)((uintptr_t)tp + tp->ProximityOffset);
2250 item < end;
2251 item = (void *)(item->Length + (uintptr_t)item)) {
2253 * Sanity check according to section 5.2.19.1 of ACPI 4.0.
2254 * Revision 1
2255 * Length 22
2257 if (item->Revision != 1 || item->Length != 22) {
2258 cmn_err(CE_CONT,
2259 "?boot: unknown proximity domain structure in MSCT "
2260 "with Revision(%d), Length(%d).\n",
2261 (int)item->Revision, (int)item->Length);
2262 return (NULL);
2263 } else if (item->RangeStart > item->RangeEnd) {
2264 cmn_err(CE_CONT,
2265 "?boot: invalid proximity domain structure in MSCT "
2266 "with RangeStart(%u), RangeEnd(%u).\n",
2267 item->RangeStart, item->RangeEnd);
2268 return (NULL);
2269 } else if (item->RangeStart != last_seen) {
2271 * Items must be organized in ascending order of the
2272 * proximity domain enumerations.
2274 cmn_err(CE_CONT,
2275 "?boot: invalid proximity domain structure in MSCT,"
2276 " items are not orginized in ascending order.\n");
2277 return (NULL);
2281 * If ProcessorCapacity is 0 then there would be no CPUs in this
2282 * domain.
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) {
2295 break;
2298 if (last_seen != tp->MaxProximityDomains + 1) {
2299 cmn_err(CE_CONT,
2300 "?boot: invalid proximity domain structure in MSCT, "
2301 "proximity domain count doesn't match.\n");
2302 return (NULL);
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
2323 * platform.
2325 plat_dr_options |= PLAT_DR_FEATURE_CPU;
2326 plat_dr_options |= PLAT_DR_FEATURE_MEMORY;
2328 return (tp);
2332 /*ARGSUSED*/
2333 static void
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);
2342 if (kbm_debug)
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);
2348 if (kbm_debug)
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);
2364 else
2365 msct_ptr = NULL;
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);
2378 if (tp != NULL)
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
2387 void *
2388 defcons_init(size_t size)
2390 static char *p = NULL;
2392 p = do_bsys_alloc(NULL, NULL, size, MMU_PAGESIZE);
2393 *p = 0;
2394 bsetprop("deferred-console-buf", strlen("deferred-console-buf") + 1,
2395 &p, sizeof (p));
2396 return (p);
2399 /*ARGSUSED*/
2401 boot_compinfo(int fd, struct compinfo *cbp)
2403 cbp->iscmp = 0;
2404 cbp->blksize = MAXBSIZE;
2405 return (0);
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)
2416 int boot_prop_len;
2417 char str[BP_MAX_STRLEN];
2418 u_longlong_t value;
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)
2424 return (-1);
2426 if (prop_value)
2427 *prop_value = value;
2429 return (0);