Print this page
12220 loader multi-console shouldn't override bootenv.rc
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/i86pc/os/fakebop.c
+++ new/usr/src/uts/i86pc/os/fakebop.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
24 24 * Use is subject to license terms.
25 25 *
26 26 * Copyright (c) 2010, Intel Corporation.
27 27 * All rights reserved.
28 28 *
29 29 * Copyright 2020 Joyent, Inc.
30 30 */
31 31
32 32 /*
33 33 * This file contains the functionality that mimics the boot operations
34 34 * on SPARC systems or the old boot.bin/multiboot programs on x86 systems.
35 35 * The x86 kernel now does everything on its own.
36 36 */
37 37
38 38 #include <sys/types.h>
39 39 #include <sys/bootconf.h>
40 40 #include <sys/bootsvcs.h>
41 41 #include <sys/bootinfo.h>
42 42 #include <sys/multiboot.h>
43 43 #include <sys/multiboot2.h>
44 44 #include <sys/multiboot2_impl.h>
45 45 #include <sys/bootvfs.h>
46 46 #include <sys/bootprops.h>
47 47 #include <sys/varargs.h>
48 48 #include <sys/param.h>
49 49 #include <sys/machparam.h>
50 50 #include <sys/machsystm.h>
51 51 #include <sys/archsystm.h>
52 52 #include <sys/boot_console.h>
53 53 #include <sys/framebuffer.h>
54 54 #include <sys/cmn_err.h>
55 55 #include <sys/systm.h>
56 56 #include <sys/promif.h>
57 57 #include <sys/archsystm.h>
58 58 #include <sys/x86_archext.h>
59 59 #include <sys/kobj.h>
60 60 #include <sys/privregs.h>
61 61 #include <sys/sysmacros.h>
62 62 #include <sys/ctype.h>
63 63 #include <sys/fastboot.h>
64 64 #ifdef __xpv
65 65 #include <sys/hypervisor.h>
66 66 #include <net/if.h>
67 67 #endif
68 68 #include <vm/kboot_mmu.h>
69 69 #include <vm/hat_pte.h>
70 70 #include <sys/kobj.h>
71 71 #include <sys/kobj_lex.h>
72 72 #include <sys/pci_cfgspace_impl.h>
73 73 #include <sys/fastboot_impl.h>
74 74 #include <sys/acpi/acconfig.h>
75 75 #include <sys/acpi/acpi.h>
76 76 #include <sys/ddipropdefs.h> /* For DDI prop types */
77 77
78 78 static int have_console = 0; /* set once primitive console is initialized */
79 79 static char *boot_args = "";
80 80
81 81 /*
82 82 * Debugging macros
83 83 */
84 84 static uint_t kbm_debug = 0;
85 85 #define DBG_MSG(s) { if (kbm_debug) bop_printf(NULL, "%s", s); }
86 86 #define DBG(x) { if (kbm_debug) \
87 87 bop_printf(NULL, "%s is %" PRIx64 "\n", #x, (uint64_t)(x)); \
88 88 }
89 89
90 90 #define PUT_STRING(s) { \
91 91 char *cp; \
92 92 for (cp = (s); *cp; ++cp) \
93 93 bcons_putchar(*cp); \
↓ open down ↓ |
93 lines elided |
↑ open up ↑ |
94 94 }
95 95
96 96 /* callback to boot_fb to set shadow frame buffer */
97 97 extern void boot_fb_shadow_init(bootops_t *);
98 98
99 99 bootops_t bootop; /* simple bootops we'll pass on to kernel */
100 100 struct bsys_mem bm;
101 101
102 102 /*
103 103 * Boot info from "glue" code in low memory. xbootp is used by:
104 - * do_bop_phys_alloc(), do_bsys_alloc() and boot_prop_finish().
104 + * do_bop_phys_alloc(), do_bsys_alloc() and read_bootenvrc().
105 105 */
106 106 static struct xboot_info *xbootp;
107 107 static uintptr_t next_virt; /* next available virtual address */
108 108 static paddr_t next_phys; /* next available physical address from dboot */
109 109 static paddr_t high_phys = -(paddr_t)1; /* last used physical address */
110 110
111 111 /*
112 112 * buffer for vsnprintf for console I/O
113 113 */
114 114 #define BUFFERSIZE 512
115 115 static char buffer[BUFFERSIZE];
116 116
117 117 /*
118 118 * stuff to store/report/manipulate boot property settings.
119 119 */
120 120 typedef struct bootprop {
121 121 struct bootprop *bp_next;
122 122 char *bp_name;
123 123 int bp_flags; /* DDI prop type */
124 124 uint_t bp_vlen; /* 0 for boolean */
125 125 char *bp_value;
126 126 } bootprop_t;
127 127
128 128 static bootprop_t *bprops = NULL;
129 129 static char *curr_page = NULL; /* ptr to avail bprop memory */
130 130 static int curr_space = 0; /* amount of memory at curr_page */
131 131
132 132 #ifdef __xpv
133 133 start_info_t *xen_info;
134 134 shared_info_t *HYPERVISOR_shared_info;
135 135 #endif
136 136
137 137 /*
138 138 * some allocator statistics
139 139 */
140 140 static ulong_t total_bop_alloc_scratch = 0;
141 141 static ulong_t total_bop_alloc_kernel = 0;
142 142
143 143 static void build_firmware_properties(struct xboot_info *);
144 144
145 145 static int early_allocation = 1;
146 146
147 147 int force_fastreboot = 0;
148 148 volatile int fastreboot_onpanic = 0;
149 149 int post_fastreboot = 0;
150 150 #ifdef __xpv
151 151 volatile int fastreboot_capable = 0;
152 152 #else
153 153 volatile int fastreboot_capable = 1;
154 154 #endif
155 155
156 156 /*
157 157 * Information saved from current boot for fast reboot.
158 158 * If the information size exceeds what we have allocated, fast reboot
159 159 * will not be supported.
160 160 */
161 161 multiboot_info_t saved_mbi;
162 162 mb_memory_map_t saved_mmap[FASTBOOT_SAVED_MMAP_COUNT];
163 163 uint8_t saved_drives[FASTBOOT_SAVED_DRIVES_SIZE];
164 164 char saved_cmdline[FASTBOOT_SAVED_CMDLINE_LEN];
165 165 int saved_cmdline_len = 0;
166 166 size_t saved_file_size[FASTBOOT_MAX_FILES_MAP];
167 167
168 168 /*
169 169 * Turn off fastreboot_onpanic to avoid panic loop.
170 170 */
171 171 char fastreboot_onpanic_cmdline[FASTBOOT_SAVED_CMDLINE_LEN];
172 172 static const char fastreboot_onpanic_args[] = " -B fastreboot_onpanic=0";
173 173
174 174 /*
175 175 * Pointers to where System Resource Affinity Table (SRAT), System Locality
176 176 * Information Table (SLIT) and Maximum System Capability Table (MSCT)
177 177 * are mapped into virtual memory
178 178 */
179 179 ACPI_TABLE_SRAT *srat_ptr = NULL;
180 180 ACPI_TABLE_SLIT *slit_ptr = NULL;
181 181 ACPI_TABLE_MSCT *msct_ptr = NULL;
182 182
183 183 /*
184 184 * Arbitrary limit on number of localities we handle; if
185 185 * this limit is raised to more than UINT16_MAX, make sure
186 186 * process_slit() knows how to handle it.
187 187 */
188 188 #define SLIT_LOCALITIES_MAX (4096)
189 189
190 190 #define SLIT_NUM_PROPNAME "acpi-slit-localities"
191 191 #define SLIT_PROPNAME "acpi-slit"
192 192
193 193 /*
194 194 * Allocate aligned physical memory at boot time. This allocator allocates
195 195 * from the highest possible addresses. This avoids exhausting memory that
196 196 * would be useful for DMA buffers.
197 197 */
198 198 paddr_t
199 199 do_bop_phys_alloc(uint64_t size, uint64_t align)
200 200 {
201 201 paddr_t pa = 0;
202 202 paddr_t start;
203 203 paddr_t end;
204 204 struct memlist *ml = (struct memlist *)xbootp->bi_phys_install;
205 205
206 206 /*
207 207 * Be careful if high memory usage is limited in startup.c
208 208 * Since there are holes in the low part of the physical address
209 209 * space we can treat physmem as a pfn (not just a pgcnt) and
210 210 * get a conservative upper limit.
211 211 */
212 212 if (physmem != 0 && high_phys > pfn_to_pa(physmem))
213 213 high_phys = pfn_to_pa(physmem);
214 214
215 215 /*
216 216 * find the highest available memory in physinstalled
217 217 */
218 218 size = P2ROUNDUP(size, align);
219 219 for (; ml; ml = ml->ml_next) {
220 220 start = P2ROUNDUP(ml->ml_address, align);
221 221 end = P2ALIGN(ml->ml_address + ml->ml_size, align);
222 222 if (start < next_phys)
223 223 start = P2ROUNDUP(next_phys, align);
224 224 if (end > high_phys)
225 225 end = P2ALIGN(high_phys, align);
226 226
227 227 if (end <= start)
228 228 continue;
229 229 if (end - start < size)
230 230 continue;
231 231
232 232 /*
233 233 * Early allocations need to use low memory, since
234 234 * physmem might be further limited by bootenv.rc
235 235 */
236 236 if (early_allocation) {
237 237 if (pa == 0 || start < pa)
238 238 pa = start;
239 239 } else {
240 240 if (end - size > pa)
241 241 pa = end - size;
242 242 }
243 243 }
244 244 if (pa != 0) {
245 245 if (early_allocation)
246 246 next_phys = pa + size;
247 247 else
248 248 high_phys = pa;
249 249 return (pa);
250 250 }
251 251 bop_panic("do_bop_phys_alloc(0x%" PRIx64 ", 0x%" PRIx64
252 252 ") Out of memory\n", size, align);
253 253 /*NOTREACHED*/
254 254 }
255 255
256 256 uintptr_t
257 257 alloc_vaddr(size_t size, paddr_t align)
258 258 {
259 259 uintptr_t rv;
260 260
261 261 next_virt = P2ROUNDUP(next_virt, (uintptr_t)align);
262 262 rv = (uintptr_t)next_virt;
263 263 next_virt += size;
264 264 return (rv);
265 265 }
266 266
267 267 /*
268 268 * Allocate virtual memory. The size is always rounded up to a multiple
269 269 * of base pagesize.
270 270 */
271 271
272 272 /*ARGSUSED*/
273 273 static caddr_t
274 274 do_bsys_alloc(bootops_t *bop, caddr_t virthint, size_t size, int align)
275 275 {
276 276 paddr_t a = align; /* same type as pa for masking */
277 277 uint_t pgsize;
278 278 paddr_t pa;
279 279 uintptr_t va;
280 280 ssize_t s; /* the aligned size */
281 281 uint_t level;
282 282 uint_t is_kernel = (virthint != 0);
283 283
284 284 if (a < MMU_PAGESIZE)
285 285 a = MMU_PAGESIZE;
286 286 else if (!ISP2(a))
287 287 prom_panic("do_bsys_alloc() incorrect alignment");
288 288 size = P2ROUNDUP(size, MMU_PAGESIZE);
289 289
290 290 /*
291 291 * Use the next aligned virtual address if we weren't given one.
292 292 */
293 293 if (virthint == NULL) {
294 294 virthint = (caddr_t)alloc_vaddr(size, a);
295 295 total_bop_alloc_scratch += size;
296 296 } else {
297 297 total_bop_alloc_kernel += size;
298 298 }
299 299
300 300 /*
301 301 * allocate the physical memory
302 302 */
303 303 pa = do_bop_phys_alloc(size, a);
304 304
305 305 /*
306 306 * Add the mappings to the page tables, try large pages first.
307 307 */
308 308 va = (uintptr_t)virthint;
309 309 s = size;
310 310 level = 1;
311 311 pgsize = xbootp->bi_use_pae ? TWO_MEG : FOUR_MEG;
312 312 if (xbootp->bi_use_largepage && a == pgsize) {
313 313 while (IS_P2ALIGNED(pa, pgsize) && IS_P2ALIGNED(va, pgsize) &&
314 314 s >= pgsize) {
315 315 kbm_map(va, pa, level, is_kernel);
316 316 va += pgsize;
317 317 pa += pgsize;
318 318 s -= pgsize;
319 319 }
320 320 }
321 321
322 322 /*
323 323 * Map remaining pages use small mappings
324 324 */
325 325 level = 0;
326 326 pgsize = MMU_PAGESIZE;
327 327 while (s > 0) {
328 328 kbm_map(va, pa, level, is_kernel);
329 329 va += pgsize;
330 330 pa += pgsize;
331 331 s -= pgsize;
332 332 }
333 333 return (virthint);
334 334 }
335 335
336 336 /*
337 337 * Free virtual memory - we'll just ignore these.
338 338 */
339 339 /*ARGSUSED*/
340 340 static void
341 341 do_bsys_free(bootops_t *bop, caddr_t virt, size_t size)
342 342 {
343 343 bop_printf(NULL, "do_bsys_free(virt=0x%p, size=0x%lx) ignored\n",
344 344 (void *)virt, size);
345 345 }
346 346
347 347 /*
348 348 * Old interface
349 349 */
350 350 /*ARGSUSED*/
351 351 static caddr_t
352 352 do_bsys_ealloc(bootops_t *bop, caddr_t virthint, size_t size,
353 353 int align, int flags)
354 354 {
355 355 prom_panic("unsupported call to BOP_EALLOC()\n");
356 356 return (0);
357 357 }
358 358
359 359
360 360 static void
361 361 bsetprop(int flags, char *name, int nlen, void *value, int vlen)
362 362 {
363 363 uint_t size;
364 364 uint_t need_size;
365 365 bootprop_t *b;
366 366
367 367 /*
368 368 * align the size to 16 byte boundary
369 369 */
370 370 size = sizeof (bootprop_t) + nlen + 1 + vlen;
371 371 size = (size + 0xf) & ~0xf;
372 372 if (size > curr_space) {
373 373 need_size = (size + (MMU_PAGEOFFSET)) & MMU_PAGEMASK;
374 374 curr_page = do_bsys_alloc(NULL, 0, need_size, MMU_PAGESIZE);
375 375 curr_space = need_size;
376 376 }
377 377
378 378 /*
379 379 * use a bootprop_t at curr_page and link into list
380 380 */
381 381 b = (bootprop_t *)curr_page;
382 382 curr_page += sizeof (bootprop_t);
383 383 curr_space -= sizeof (bootprop_t);
384 384 b->bp_next = bprops;
385 385 bprops = b;
386 386
387 387 /*
388 388 * follow by name and ending zero byte
389 389 */
390 390 b->bp_name = curr_page;
391 391 bcopy(name, curr_page, nlen);
392 392 curr_page += nlen;
393 393 *curr_page++ = 0;
394 394 curr_space -= nlen + 1;
395 395
396 396 /*
397 397 * set the property type
398 398 */
399 399 b->bp_flags = flags & DDI_PROP_TYPE_MASK;
400 400
401 401 /*
402 402 * copy in value, but no ending zero byte
403 403 */
404 404 b->bp_value = curr_page;
405 405 b->bp_vlen = vlen;
406 406 if (vlen > 0) {
407 407 bcopy(value, curr_page, vlen);
408 408 curr_page += vlen;
409 409 curr_space -= vlen;
410 410 }
411 411
412 412 /*
413 413 * align new values of curr_page, curr_space
414 414 */
415 415 while (curr_space & 0xf) {
416 416 ++curr_page;
417 417 --curr_space;
418 418 }
419 419 }
420 420
421 421 static void
422 422 bsetprops(char *name, char *value)
423 423 {
424 424 bsetprop(DDI_PROP_TYPE_STRING, name, strlen(name),
425 425 value, strlen(value) + 1);
426 426 }
427 427
428 428 static void
429 429 bsetprop32(char *name, uint32_t value)
430 430 {
431 431 bsetprop(DDI_PROP_TYPE_INT, name, strlen(name),
432 432 (void *)&value, sizeof (value));
433 433 }
434 434
435 435 static void
436 436 bsetprop64(char *name, uint64_t value)
437 437 {
438 438 bsetprop(DDI_PROP_TYPE_INT64, name, strlen(name),
439 439 (void *)&value, sizeof (value));
440 440 }
441 441
442 442 static void
443 443 bsetpropsi(char *name, int value)
444 444 {
445 445 char prop_val[32];
446 446
447 447 (void) snprintf(prop_val, sizeof (prop_val), "%d", value);
448 448 bsetprops(name, prop_val);
449 449 }
450 450
451 451 /*
452 452 * to find the type of the value associated with this name
453 453 */
454 454 /*ARGSUSED*/
455 455 int
456 456 do_bsys_getproptype(bootops_t *bop, const char *name)
457 457 {
458 458 bootprop_t *b;
459 459
460 460 for (b = bprops; b != NULL; b = b->bp_next) {
461 461 if (strcmp(name, b->bp_name) != 0)
462 462 continue;
463 463 return (b->bp_flags);
464 464 }
465 465 return (-1);
466 466 }
467 467
468 468 /*
469 469 * to find the size of the buffer to allocate
470 470 */
471 471 /*ARGSUSED*/
472 472 int
473 473 do_bsys_getproplen(bootops_t *bop, const char *name)
474 474 {
475 475 bootprop_t *b;
476 476
477 477 for (b = bprops; b; b = b->bp_next) {
478 478 if (strcmp(name, b->bp_name) != 0)
479 479 continue;
480 480 return (b->bp_vlen);
481 481 }
482 482 return (-1);
483 483 }
484 484
485 485 /*
486 486 * get the value associated with this name
487 487 */
488 488 /*ARGSUSED*/
489 489 int
490 490 do_bsys_getprop(bootops_t *bop, const char *name, void *value)
491 491 {
492 492 bootprop_t *b;
493 493
494 494 for (b = bprops; b; b = b->bp_next) {
495 495 if (strcmp(name, b->bp_name) != 0)
496 496 continue;
497 497 bcopy(b->bp_value, value, b->bp_vlen);
498 498 return (0);
499 499 }
500 500 return (-1);
501 501 }
502 502
503 503 /*
504 504 * get the name of the next property in succession from the standalone
505 505 */
506 506 /*ARGSUSED*/
507 507 static char *
508 508 do_bsys_nextprop(bootops_t *bop, char *name)
509 509 {
510 510 bootprop_t *b;
511 511
512 512 /*
513 513 * A null name is a special signal for the 1st boot property
514 514 */
515 515 if (name == NULL || strlen(name) == 0) {
516 516 if (bprops == NULL)
517 517 return (NULL);
518 518 return (bprops->bp_name);
519 519 }
520 520
521 521 for (b = bprops; b; b = b->bp_next) {
522 522 if (name != b->bp_name)
523 523 continue;
524 524 b = b->bp_next;
525 525 if (b == NULL)
526 526 return (NULL);
527 527 return (b->bp_name);
528 528 }
529 529 return (NULL);
530 530 }
531 531
532 532 /*
533 533 * Parse numeric value from a string. Understands decimal, hex, octal, - and ~
534 534 */
535 535 static int
536 536 parse_value(char *p, uint64_t *retval)
537 537 {
538 538 int adjust = 0;
539 539 uint64_t tmp = 0;
540 540 int digit;
541 541 int radix = 10;
542 542
543 543 *retval = 0;
544 544 if (*p == '-' || *p == '~')
545 545 adjust = *p++;
546 546
547 547 if (*p == '0') {
548 548 ++p;
549 549 if (*p == 0)
550 550 return (0);
551 551 if (*p == 'x' || *p == 'X') {
552 552 radix = 16;
553 553 ++p;
554 554 } else {
555 555 radix = 8;
556 556 ++p;
557 557 }
558 558 }
559 559 while (*p) {
560 560 if ('0' <= *p && *p <= '9')
561 561 digit = *p - '0';
562 562 else if ('a' <= *p && *p <= 'f')
563 563 digit = 10 + *p - 'a';
564 564 else if ('A' <= *p && *p <= 'F')
565 565 digit = 10 + *p - 'A';
566 566 else
567 567 return (-1);
568 568 if (digit >= radix)
569 569 return (-1);
570 570 tmp = tmp * radix + digit;
571 571 ++p;
572 572 }
573 573 if (adjust == '-')
574 574 tmp = -tmp;
575 575 else if (adjust == '~')
576 576 tmp = ~tmp;
577 577 *retval = tmp;
578 578 return (0);
579 579 }
580 580
581 581 static boolean_t
582 582 unprintable(char *value, int size)
583 583 {
584 584 int i;
585 585
586 586 if (size <= 0 || value[0] == '\0')
587 587 return (B_TRUE);
588 588
589 589 for (i = 0; i < size; i++) {
590 590 if (value[i] == '\0')
591 591 return (i != (size - 1));
592 592
593 593 if (!isprint(value[i]))
594 594 return (B_TRUE);
595 595 }
596 596 return (B_FALSE);
597 597 }
598 598
599 599 /*
600 600 * Print out information about all boot properties.
601 601 * buffer is pointer to pre-allocated space to be used as temporary
602 602 * space for property values.
603 603 */
604 604 static void
605 605 boot_prop_display(char *buffer)
606 606 {
607 607 char *name = "";
608 608 int i, len, flags, *buf32;
609 609 int64_t *buf64;
610 610
611 611 bop_printf(NULL, "\nBoot properties:\n");
612 612
613 613 while ((name = do_bsys_nextprop(NULL, name)) != NULL) {
614 614 bop_printf(NULL, "\t0x%p %s = ", (void *)name, name);
615 615 (void) do_bsys_getprop(NULL, name, buffer);
616 616 len = do_bsys_getproplen(NULL, name);
617 617 flags = do_bsys_getproptype(NULL, name);
618 618 bop_printf(NULL, "len=%d ", len);
619 619
620 620 switch (flags) {
621 621 case DDI_PROP_TYPE_INT:
622 622 len = len / sizeof (int);
623 623 buf32 = (int *)buffer;
624 624 for (i = 0; i < len; i++) {
625 625 bop_printf(NULL, "%08x", buf32[i]);
626 626 if (i < len - 1)
627 627 bop_printf(NULL, ".");
628 628 }
629 629 break;
630 630 case DDI_PROP_TYPE_STRING:
631 631 bop_printf(NULL, "%s", buffer);
632 632 break;
633 633 case DDI_PROP_TYPE_INT64:
634 634 len = len / sizeof (int64_t);
635 635 buf64 = (int64_t *)buffer;
636 636 for (i = 0; i < len; i++) {
637 637 bop_printf(NULL, "%016" PRIx64, buf64[i]);
638 638 if (i < len - 1)
639 639 bop_printf(NULL, ".");
640 640 }
641 641 break;
642 642 default:
643 643 if (!unprintable(buffer, len)) {
644 644 buffer[len] = 0;
645 645 bop_printf(NULL, "%s", buffer);
646 646 break;
647 647 }
648 648 for (i = 0; i < len; i++) {
649 649 bop_printf(NULL, "%02x", buffer[i] & 0xff);
650 650 if (i < len - 1)
651 651 bop_printf(NULL, ".");
652 652 }
653 653 break;
654 654 }
655 655 bop_printf(NULL, "\n");
656 656 }
657 657 }
658 658
659 659 /*
660 660 * 2nd part of building the table of boot properties. This includes:
661 661 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
662 662 *
↓ open down ↓ |
548 lines elided |
↑ open up ↑ |
663 663 * lines look like one of:
664 664 * ^$
665 665 * ^# comment till end of line
666 666 * setprop name 'value'
667 667 * setprop name value
668 668 * setprop name "value"
669 669 *
670 670 * we do single character I/O since this is really just looking at memory
671 671 */
672 672 void
673 -boot_prop_finish(void)
673 +read_bootenvrc(void)
674 674 {
675 675 int fd;
676 676 char *line;
677 677 int c;
678 678 int bytes_read;
679 679 char *name;
680 680 int n_len;
681 681 char *value;
682 682 int v_len;
683 683 char *inputdev; /* these override the command line if serial ports */
684 684 char *outputdev;
685 685 char *consoledev;
686 686 uint64_t lvalue;
687 687 int use_xencons = 0;
688 688 extern int bootrd_debug;
689 689
690 690 #ifdef __xpv
691 691 if (!DOMAIN_IS_INITDOMAIN(xen_info))
692 692 use_xencons = 1;
693 693 #endif /* __xpv */
694 694
695 695 DBG_MSG("Opening /boot/solaris/bootenv.rc\n");
696 696 fd = BRD_OPEN(bfs_ops, "/boot/solaris/bootenv.rc", 0);
697 697 DBG(fd);
698 698
699 699 line = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, MMU_PAGESIZE);
700 700 while (fd >= 0) {
701 701
702 702 /*
703 703 * get a line
704 704 */
705 705 for (c = 0; ; ++c) {
706 706 bytes_read = BRD_READ(bfs_ops, fd, line + c, 1);
707 707 if (bytes_read == 0) {
708 708 if (c == 0)
709 709 goto done;
710 710 break;
711 711 }
712 712 if (line[c] == '\n')
713 713 break;
714 714 }
715 715 line[c] = 0;
716 716
717 717 /*
718 718 * ignore comment lines
719 719 */
720 720 c = 0;
721 721 while (ISSPACE(line[c]))
722 722 ++c;
723 723 if (line[c] == '#' || line[c] == 0)
724 724 continue;
725 725
726 726 /*
727 727 * must have "setprop " or "setprop\t"
728 728 */
729 729 if (strncmp(line + c, "setprop ", 8) != 0 &&
730 730 strncmp(line + c, "setprop\t", 8) != 0)
731 731 continue;
732 732 c += 8;
733 733 while (ISSPACE(line[c]))
734 734 ++c;
735 735 if (line[c] == 0)
736 736 continue;
737 737
738 738 /*
739 739 * gather up the property name
740 740 */
741 741 name = line + c;
742 742 n_len = 0;
743 743 while (line[c] && !ISSPACE(line[c]))
744 744 ++n_len, ++c;
745 745
746 746 /*
747 747 * gather up the value, if any
748 748 */
749 749 value = "";
750 750 v_len = 0;
751 751 while (ISSPACE(line[c]))
752 752 ++c;
753 753 if (line[c] != 0) {
754 754 value = line + c;
755 755 while (line[c] && !ISSPACE(line[c]))
756 756 ++v_len, ++c;
757 757 }
758 758
759 759 if (v_len >= 2 && value[0] == value[v_len - 1] &&
760 760 (value[0] == '\'' || value[0] == '"')) {
761 761 ++value;
762 762 v_len -= 2;
763 763 }
764 764 name[n_len] = 0;
765 765 if (v_len > 0)
766 766 value[v_len] = 0;
767 767 else
768 768 continue;
769 769
770 770 /*
↓ open down ↓ |
87 lines elided |
↑ open up ↑ |
771 771 * ignore "boot-file" property, it's now meaningless
772 772 */
773 773 if (strcmp(name, "boot-file") == 0)
774 774 continue;
775 775 if (strcmp(name, "boot-args") == 0 &&
776 776 strlen(boot_args) > 0)
777 777 continue;
778 778
779 779 /*
780 780 * If a property was explicitly set on the command line
781 - * it will override a setting in bootenv.rc
781 + * it will override a setting in bootenv.rc. We make an
782 + * exception for a property from the bootloader such as:
783 + *
784 + * console="text,ttya,ttyb,ttyc,ttyd"
785 + *
786 + * In such a case, picking the first value here (as
787 + * lookup_console_devices() does) is at best a guess; if
788 + * bootenv.rc has a value, it's probably better.
782 789 */
783 - if (do_bsys_getproplen(NULL, name) >= 0)
790 + if (strcmp(name, "console") == 0) {
791 + char propval[BP_MAX_STRLEN] = "";
792 +
793 + if (do_bsys_getprop(NULL, name, propval) == -1 ||
794 + strchr(propval, ',') != NULL)
795 + bsetprops(name, value);
784 796 continue;
797 + }
785 798
786 - bsetprops(name, value);
799 + if (do_bsys_getproplen(NULL, name) == -1)
800 + bsetprops(name, value);
787 801 }
788 802 done:
789 803 if (fd >= 0)
790 804 (void) BRD_CLOSE(bfs_ops, fd);
791 805
806 +
792 807 /*
793 808 * Check if we have to limit the boot time allocator
794 809 */
795 810 if (do_bsys_getproplen(NULL, "physmem") != -1 &&
796 811 do_bsys_getprop(NULL, "physmem", line) >= 0 &&
797 812 parse_value(line, &lvalue) != -1) {
798 813 if (0 < lvalue && (lvalue < physmem || physmem == 0)) {
799 814 physmem = (pgcnt_t)lvalue;
800 815 DBG(physmem);
801 816 }
802 817 }
803 818 early_allocation = 0;
804 819
805 820 /*
806 821 * Check for bootrd_debug.
807 822 */
808 823 if (find_boot_prop("bootrd_debug"))
809 824 bootrd_debug = 1;
810 825
811 826 /*
812 827 * check to see if we have to override the default value of the console
813 828 */
814 829 if (!use_xencons) {
815 830 inputdev = line;
816 831 v_len = do_bsys_getproplen(NULL, "input-device");
817 832 if (v_len > 0)
818 833 (void) do_bsys_getprop(NULL, "input-device", inputdev);
819 834 else
820 835 v_len = 0;
821 836 inputdev[v_len] = 0;
822 837
823 838 outputdev = inputdev + v_len + 1;
824 839 v_len = do_bsys_getproplen(NULL, "output-device");
825 840 if (v_len > 0)
826 841 (void) do_bsys_getprop(NULL, "output-device",
827 842 outputdev);
828 843 else
829 844 v_len = 0;
830 845 outputdev[v_len] = 0;
831 846
832 847 consoledev = outputdev + v_len + 1;
833 848 v_len = do_bsys_getproplen(NULL, "console");
834 849 if (v_len > 0) {
835 850 (void) do_bsys_getprop(NULL, "console", consoledev);
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
836 851 if (post_fastreboot &&
837 852 strcmp(consoledev, "graphics") == 0) {
838 853 bsetprops("console", "text");
839 854 v_len = strlen("text");
840 855 bcopy("text", consoledev, v_len);
841 856 }
842 857 } else {
843 858 v_len = 0;
844 859 }
845 860 consoledev[v_len] = 0;
846 - bcons_init2(inputdev, outputdev, consoledev);
861 + bcons_post_bootenvrc(inputdev, outputdev, consoledev);
847 862 } else {
848 863 /*
849 864 * Ensure console property exists
850 865 * If not create it as "hypervisor"
851 866 */
852 867 v_len = do_bsys_getproplen(NULL, "console");
853 868 if (v_len < 0)
854 869 bsetprops("console", "hypervisor");
855 870 inputdev = outputdev = consoledev = "hypervisor";
856 - bcons_init2(inputdev, outputdev, consoledev);
871 + bcons_post_bootenvrc(inputdev, outputdev, consoledev);
857 872 }
858 873
859 874 if (find_boot_prop("prom_debug") || kbm_debug)
860 875 boot_prop_display(line);
861 876 }
862 877
863 878 /*
864 879 * print formatted output
865 880 */
866 881 /*ARGSUSED*/
867 882 void
868 883 vbop_printf(void *ptr, const char *fmt, va_list ap)
869 884 {
870 885 if (have_console == 0)
871 886 return;
872 887
873 888 (void) vsnprintf(buffer, BUFFERSIZE, fmt, ap);
874 889 PUT_STRING(buffer);
875 890 }
876 891
877 892 /*PRINTFLIKE2*/
878 893 void
879 894 bop_printf(void *bop, const char *fmt, ...)
880 895 {
881 896 va_list ap;
882 897
883 898 va_start(ap, fmt);
884 899 vbop_printf(bop, fmt, ap);
885 900 va_end(ap);
886 901 }
887 902
888 903 /*
889 904 * Another panic() variant; this one can be used even earlier during boot than
890 905 * prom_panic().
891 906 */
892 907 /*PRINTFLIKE1*/
893 908 void
894 909 bop_panic(const char *fmt, ...)
895 910 {
896 911 va_list ap;
897 912
898 913 va_start(ap, fmt);
899 914 bop_printf(NULL, fmt, ap);
900 915 va_end(ap);
901 916
902 917 bop_printf(NULL, "\nPress any key to reboot.\n");
903 918 (void) bcons_getchar();
904 919 bop_printf(NULL, "Resetting...\n");
905 920 pc_reset();
906 921 }
907 922
908 923 /*
909 924 * Do a real mode interrupt BIOS call
910 925 */
911 926 typedef struct bios_regs {
912 927 unsigned short ax, bx, cx, dx, si, di, bp, es, ds;
913 928 } bios_regs_t;
914 929 typedef int (*bios_func_t)(int, bios_regs_t *);
915 930
916 931 /*ARGSUSED*/
917 932 static void
918 933 do_bsys_doint(bootops_t *bop, int intnum, struct bop_regs *rp)
919 934 {
920 935 #if defined(__xpv)
921 936 prom_panic("unsupported call to BOP_DOINT()\n");
922 937 #else /* __xpv */
923 938 static int firsttime = 1;
924 939 bios_func_t bios_func = (bios_func_t)(void *)(uintptr_t)0x5000;
925 940 bios_regs_t br;
926 941
927 942 /*
928 943 * We're about to disable paging; we shouldn't be PCID enabled.
929 944 */
930 945 if (getcr4() & CR4_PCIDE)
931 946 prom_panic("do_bsys_doint() with PCID enabled\n");
932 947
933 948 /*
934 949 * The first time we do this, we have to copy the pre-packaged
935 950 * low memory bios call code image into place.
936 951 */
937 952 if (firsttime) {
938 953 extern char bios_image[];
939 954 extern uint32_t bios_size;
940 955
941 956 bcopy(bios_image, (void *)bios_func, bios_size);
942 957 firsttime = 0;
943 958 }
944 959
945 960 br.ax = rp->eax.word.ax;
946 961 br.bx = rp->ebx.word.bx;
947 962 br.cx = rp->ecx.word.cx;
948 963 br.dx = rp->edx.word.dx;
949 964 br.bp = rp->ebp.word.bp;
950 965 br.si = rp->esi.word.si;
951 966 br.di = rp->edi.word.di;
952 967 br.ds = rp->ds;
953 968 br.es = rp->es;
954 969
955 970 DBG_MSG("Doing BIOS call...");
956 971 DBG(br.ax);
957 972 DBG(br.bx);
958 973 DBG(br.dx);
959 974 rp->eflags = bios_func(intnum, &br);
960 975 DBG_MSG("done\n");
961 976
962 977 rp->eax.word.ax = br.ax;
963 978 rp->ebx.word.bx = br.bx;
964 979 rp->ecx.word.cx = br.cx;
965 980 rp->edx.word.dx = br.dx;
966 981 rp->ebp.word.bp = br.bp;
967 982 rp->esi.word.si = br.si;
968 983 rp->edi.word.di = br.di;
969 984 rp->ds = br.ds;
970 985 rp->es = br.es;
971 986 #endif /* __xpv */
972 987 }
973 988
974 989 static struct boot_syscalls bop_sysp = {
975 990 bcons_getchar,
976 991 bcons_putchar,
977 992 bcons_ischar,
978 993 };
979 994
980 995 static char *whoami;
981 996
982 997 #define BUFLEN 64
983 998
984 999 #if defined(__xpv)
985 1000
986 1001 static char namebuf[32];
987 1002
988 1003 static void
989 1004 xen_parse_props(char *s, char *prop_map[], int n_prop)
990 1005 {
991 1006 char **prop_name = prop_map;
992 1007 char *cp = s, *scp;
993 1008
994 1009 do {
995 1010 scp = cp;
996 1011 while ((*cp != '\0') && (*cp != ':'))
997 1012 cp++;
998 1013
999 1014 if ((scp != cp) && (*prop_name != NULL)) {
1000 1015 *cp = '\0';
1001 1016 bsetprops(*prop_name, scp);
1002 1017 }
1003 1018
1004 1019 cp++;
1005 1020 prop_name++;
1006 1021 n_prop--;
1007 1022 } while (n_prop > 0);
1008 1023 }
1009 1024
1010 1025 #define VBDPATHLEN 64
1011 1026
1012 1027 /*
1013 1028 * parse the 'xpv-root' property to create properties used by
1014 1029 * ufs_mountroot.
1015 1030 */
1016 1031 static void
1017 1032 xen_vbdroot_props(char *s)
1018 1033 {
1019 1034 char vbdpath[VBDPATHLEN] = "/xpvd/xdf@";
1020 1035 const char lnamefix[] = "/dev/dsk/c0d";
1021 1036 char *pnp;
1022 1037 char *prop_p;
1023 1038 char mi;
1024 1039 short minor;
1025 1040 long addr = 0;
1026 1041
1027 1042 pnp = vbdpath + strlen(vbdpath);
1028 1043 prop_p = s + strlen(lnamefix);
1029 1044 while ((*prop_p != '\0') && (*prop_p != 's') && (*prop_p != 'p'))
1030 1045 addr = addr * 10 + *prop_p++ - '0';
1031 1046 (void) snprintf(pnp, VBDPATHLEN, "%lx", addr);
1032 1047 pnp = vbdpath + strlen(vbdpath);
1033 1048 if (*prop_p == 's')
1034 1049 mi = 'a';
1035 1050 else if (*prop_p == 'p')
1036 1051 mi = 'q';
1037 1052 else
1038 1053 ASSERT(0); /* shouldn't be here */
1039 1054 prop_p++;
1040 1055 ASSERT(*prop_p != '\0');
1041 1056 if (ISDIGIT(*prop_p)) {
1042 1057 minor = *prop_p - '0';
1043 1058 prop_p++;
1044 1059 if (ISDIGIT(*prop_p)) {
1045 1060 minor = minor * 10 + *prop_p - '0';
1046 1061 }
1047 1062 } else {
1048 1063 /* malformed root path, use 0 as default */
1049 1064 minor = 0;
1050 1065 }
1051 1066 ASSERT(minor < 16); /* at most 16 partitions */
1052 1067 mi += minor;
1053 1068 *pnp++ = ':';
1054 1069 *pnp++ = mi;
1055 1070 *pnp++ = '\0';
1056 1071 bsetprops("fstype", "ufs");
1057 1072 bsetprops("bootpath", vbdpath);
1058 1073
1059 1074 DBG_MSG("VBD bootpath set to ");
1060 1075 DBG_MSG(vbdpath);
1061 1076 DBG_MSG("\n");
1062 1077 }
1063 1078
1064 1079 /*
1065 1080 * parse the xpv-nfsroot property to create properties used by
1066 1081 * nfs_mountroot.
1067 1082 */
1068 1083 static void
1069 1084 xen_nfsroot_props(char *s)
1070 1085 {
1071 1086 char *prop_map[] = {
1072 1087 BP_SERVER_IP, /* server IP address */
1073 1088 BP_SERVER_NAME, /* server hostname */
1074 1089 BP_SERVER_PATH, /* root path */
1075 1090 };
1076 1091 int n_prop = sizeof (prop_map) / sizeof (prop_map[0]);
1077 1092
1078 1093 bsetprops("fstype", "nfs");
1079 1094
1080 1095 xen_parse_props(s, prop_map, n_prop);
1081 1096
1082 1097 /*
1083 1098 * If a server name wasn't specified, use a default.
1084 1099 */
1085 1100 if (do_bsys_getproplen(NULL, BP_SERVER_NAME) == -1)
1086 1101 bsetprops(BP_SERVER_NAME, "unknown");
1087 1102 }
1088 1103
1089 1104 /*
1090 1105 * Extract our IP address, etc. from the "xpv-ip" property.
1091 1106 */
1092 1107 static void
1093 1108 xen_ip_props(char *s)
1094 1109 {
1095 1110 char *prop_map[] = {
1096 1111 BP_HOST_IP, /* IP address */
1097 1112 NULL, /* NFS server IP address (ignored in */
1098 1113 /* favour of xpv-nfsroot) */
1099 1114 BP_ROUTER_IP, /* IP gateway */
1100 1115 BP_SUBNET_MASK, /* IP subnet mask */
1101 1116 "xpv-hostname", /* hostname (ignored) */
1102 1117 BP_NETWORK_INTERFACE, /* interface name */
1103 1118 "xpv-hcp", /* host configuration protocol */
1104 1119 };
1105 1120 int n_prop = sizeof (prop_map) / sizeof (prop_map[0]);
1106 1121 char ifname[IFNAMSIZ];
1107 1122
1108 1123 xen_parse_props(s, prop_map, n_prop);
1109 1124
1110 1125 /*
1111 1126 * A Linux dom0 administrator expects all interfaces to be
1112 1127 * called "ethX", which is not the case here.
1113 1128 *
1114 1129 * If the interface name specified is "eth0", presume that
1115 1130 * this is really intended to be "xnf0" (the first domU ->
1116 1131 * dom0 interface for this domain).
1117 1132 */
1118 1133 if ((do_bsys_getprop(NULL, BP_NETWORK_INTERFACE, ifname) == 0) &&
1119 1134 (strcmp("eth0", ifname) == 0)) {
1120 1135 bsetprops(BP_NETWORK_INTERFACE, "xnf0");
1121 1136 bop_printf(NULL,
1122 1137 "network interface name 'eth0' replaced with 'xnf0'\n");
1123 1138 }
1124 1139 }
1125 1140
1126 1141 #else /* __xpv */
1127 1142
1128 1143 static void
1129 1144 setup_rarp_props(struct sol_netinfo *sip)
1130 1145 {
1131 1146 char buf[BUFLEN]; /* to hold ip/mac addrs */
1132 1147 uint8_t *val;
1133 1148
1134 1149 val = (uint8_t *)&sip->sn_ciaddr;
1135 1150 (void) snprintf(buf, BUFLEN, "%d.%d.%d.%d",
1136 1151 val[0], val[1], val[2], val[3]);
1137 1152 bsetprops(BP_HOST_IP, buf);
1138 1153
1139 1154 val = (uint8_t *)&sip->sn_siaddr;
1140 1155 (void) snprintf(buf, BUFLEN, "%d.%d.%d.%d",
1141 1156 val[0], val[1], val[2], val[3]);
1142 1157 bsetprops(BP_SERVER_IP, buf);
1143 1158
1144 1159 if (sip->sn_giaddr != 0) {
1145 1160 val = (uint8_t *)&sip->sn_giaddr;
1146 1161 (void) snprintf(buf, BUFLEN, "%d.%d.%d.%d",
1147 1162 val[0], val[1], val[2], val[3]);
1148 1163 bsetprops(BP_ROUTER_IP, buf);
1149 1164 }
1150 1165
1151 1166 if (sip->sn_netmask != 0) {
1152 1167 val = (uint8_t *)&sip->sn_netmask;
1153 1168 (void) snprintf(buf, BUFLEN, "%d.%d.%d.%d",
1154 1169 val[0], val[1], val[2], val[3]);
1155 1170 bsetprops(BP_SUBNET_MASK, buf);
1156 1171 }
1157 1172
1158 1173 if (sip->sn_mactype != 4 || sip->sn_maclen != 6) {
1159 1174 bop_printf(NULL, "unsupported mac type %d, mac len %d\n",
1160 1175 sip->sn_mactype, sip->sn_maclen);
1161 1176 } else {
1162 1177 val = sip->sn_macaddr;
1163 1178 (void) snprintf(buf, BUFLEN, "%x:%x:%x:%x:%x:%x",
1164 1179 val[0], val[1], val[2], val[3], val[4], val[5]);
1165 1180 bsetprops(BP_BOOT_MAC, buf);
1166 1181 }
1167 1182 }
1168 1183
1169 1184 #endif /* __xpv */
1170 1185
1171 1186 static void
1172 1187 build_panic_cmdline(const char *cmd, int cmdlen)
1173 1188 {
1174 1189 int proplen;
1175 1190 size_t arglen;
1176 1191
1177 1192 arglen = sizeof (fastreboot_onpanic_args);
1178 1193 /*
1179 1194 * If we allready have fastreboot-onpanic set to zero,
1180 1195 * don't add them again.
1181 1196 */
1182 1197 if ((proplen = do_bsys_getproplen(NULL, FASTREBOOT_ONPANIC)) > 0 &&
1183 1198 proplen <= sizeof (fastreboot_onpanic_cmdline)) {
1184 1199 (void) do_bsys_getprop(NULL, FASTREBOOT_ONPANIC,
1185 1200 fastreboot_onpanic_cmdline);
1186 1201 if (FASTREBOOT_ONPANIC_NOTSET(fastreboot_onpanic_cmdline))
1187 1202 arglen = 1;
1188 1203 }
1189 1204
1190 1205 /*
1191 1206 * construct fastreboot_onpanic_cmdline
1192 1207 */
1193 1208 if (cmdlen + arglen > sizeof (fastreboot_onpanic_cmdline)) {
1194 1209 DBG_MSG("Command line too long: clearing "
1195 1210 FASTREBOOT_ONPANIC "\n");
1196 1211 fastreboot_onpanic = 0;
1197 1212 } else {
1198 1213 bcopy(cmd, fastreboot_onpanic_cmdline, cmdlen);
1199 1214 if (arglen != 1)
1200 1215 bcopy(fastreboot_onpanic_args,
1201 1216 fastreboot_onpanic_cmdline + cmdlen, arglen);
1202 1217 else
1203 1218 fastreboot_onpanic_cmdline[cmdlen] = 0;
1204 1219 }
1205 1220 }
1206 1221
1207 1222
1208 1223 #ifndef __xpv
1209 1224 /*
1210 1225 * Construct boot command line for Fast Reboot. The saved_cmdline
1211 1226 * is also reported by "eeprom bootcmd".
1212 1227 */
1213 1228 static void
1214 1229 build_fastboot_cmdline(struct xboot_info *xbp)
1215 1230 {
1216 1231 saved_cmdline_len = strlen(xbp->bi_cmdline) + 1;
1217 1232 if (saved_cmdline_len > FASTBOOT_SAVED_CMDLINE_LEN) {
1218 1233 DBG(saved_cmdline_len);
1219 1234 DBG_MSG("Command line too long: clearing fastreboot_capable\n");
1220 1235 fastreboot_capable = 0;
1221 1236 } else {
1222 1237 bcopy((void *)(xbp->bi_cmdline), (void *)saved_cmdline,
1223 1238 saved_cmdline_len);
1224 1239 saved_cmdline[saved_cmdline_len - 1] = '\0';
1225 1240 build_panic_cmdline(saved_cmdline, saved_cmdline_len - 1);
1226 1241 }
1227 1242 }
1228 1243
1229 1244 /*
1230 1245 * Save memory layout, disk drive information, unix and boot archive sizes for
1231 1246 * Fast Reboot.
1232 1247 */
1233 1248 static void
1234 1249 save_boot_info(struct xboot_info *xbi)
1235 1250 {
1236 1251 multiboot_info_t *mbi = xbi->bi_mb_info;
1237 1252 struct boot_modules *modp;
1238 1253 int i;
1239 1254
1240 1255 bcopy(mbi, &saved_mbi, sizeof (multiboot_info_t));
1241 1256 if (mbi->mmap_length > sizeof (saved_mmap)) {
1242 1257 DBG_MSG("mbi->mmap_length too big: clearing "
1243 1258 "fastreboot_capable\n");
1244 1259 fastreboot_capable = 0;
1245 1260 } else {
1246 1261 bcopy((void *)(uintptr_t)mbi->mmap_addr, (void *)saved_mmap,
1247 1262 mbi->mmap_length);
1248 1263 }
1249 1264
1250 1265 if ((mbi->flags & MB_INFO_DRIVE_INFO) != 0) {
1251 1266 if (mbi->drives_length > sizeof (saved_drives)) {
1252 1267 DBG(mbi->drives_length);
1253 1268 DBG_MSG("mbi->drives_length too big: clearing "
1254 1269 "fastreboot_capable\n");
1255 1270 fastreboot_capable = 0;
1256 1271 } else {
1257 1272 bcopy((void *)(uintptr_t)mbi->drives_addr,
1258 1273 (void *)saved_drives, mbi->drives_length);
1259 1274 }
1260 1275 } else {
1261 1276 saved_mbi.drives_length = 0;
1262 1277 saved_mbi.drives_addr = 0;
1263 1278 }
1264 1279
1265 1280 /*
1266 1281 * Current file sizes. Used by fastboot.c to figure out how much
1267 1282 * memory to reserve for panic reboot.
1268 1283 * Use the module list from the dboot-constructed xboot_info
1269 1284 * instead of the list referenced by the multiboot structure
1270 1285 * because that structure may not be addressable now.
1271 1286 */
1272 1287 saved_file_size[FASTBOOT_NAME_UNIX] = FOUR_MEG - PAGESIZE;
1273 1288 for (i = 0, modp = (struct boot_modules *)(uintptr_t)xbi->bi_modules;
1274 1289 i < xbi->bi_module_cnt; i++, modp++) {
1275 1290 saved_file_size[FASTBOOT_NAME_BOOTARCHIVE] += modp->bm_size;
1276 1291 }
1277 1292 }
1278 1293 #endif /* __xpv */
1279 1294
1280 1295 /*
1281 1296 * Import boot environment module variables as properties, applying
1282 1297 * blacklist filter for variables we know we will not use.
1283 1298 *
1284 1299 * Since the environment can be relatively large, containing many variables
1285 1300 * used only for boot loader purposes, we will use a blacklist based filter.
1286 1301 * To keep the blacklist from growing too large, we use prefix based filtering.
1287 1302 * This is possible because in many cases, the loader variable names are
1288 1303 * using a structured layout.
1289 1304 *
1290 1305 * We will not overwrite already set properties.
1291 1306 *
1292 1307 * Note that the menu items in particular can contain characters not
1293 1308 * well-handled as bootparams, such as spaces, brackets, and the like, so that's
1294 1309 * another reason.
1295 1310 */
1296 1311 static struct bop_blacklist {
1297 1312 const char *bl_name;
1298 1313 int bl_name_len;
1299 1314 } bop_prop_blacklist[] = {
1300 1315 { "ISADIR", sizeof ("ISADIR") },
1301 1316 { "acpi", sizeof ("acpi") },
1302 1317 { "autoboot_delay", sizeof ("autoboot_delay") },
1303 1318 { "beansi_", sizeof ("beansi_") },
1304 1319 { "beastie", sizeof ("beastie") },
1305 1320 { "bemenu", sizeof ("bemenu") },
1306 1321 { "boot.", sizeof ("boot.") },
1307 1322 { "bootenv", sizeof ("bootenv") },
1308 1323 { "currdev", sizeof ("currdev") },
1309 1324 { "dhcp.", sizeof ("dhcp.") },
1310 1325 { "interpret", sizeof ("interpret") },
1311 1326 { "kernel", sizeof ("kernel") },
1312 1327 { "loaddev", sizeof ("loaddev") },
1313 1328 { "loader_", sizeof ("loader_") },
1314 1329 { "mainansi_", sizeof ("mainansi_") },
1315 1330 { "mainmenu_", sizeof ("mainmenu_") },
1316 1331 { "maintoggled_", sizeof ("maintoggled_") },
1317 1332 { "menu_timeout_command", sizeof ("menu_timeout_command") },
1318 1333 { "menuset_", sizeof ("menuset_") },
1319 1334 { "module_path", sizeof ("module_path") },
1320 1335 { "nfs.", sizeof ("nfs.") },
1321 1336 { "optionsansi_", sizeof ("optionsansi_") },
1322 1337 { "optionsmenu_", sizeof ("optionsmenu_") },
1323 1338 { "optionstoggled_", sizeof ("optionstoggled_") },
1324 1339 { "pcibios", sizeof ("pcibios") },
1325 1340 { "prompt", sizeof ("prompt") },
1326 1341 { "smbios", sizeof ("smbios") },
1327 1342 { "tem", sizeof ("tem") },
1328 1343 { "twiddle_divisor", sizeof ("twiddle_divisor") },
1329 1344 { "zfs_be", sizeof ("zfs_be") },
1330 1345 };
1331 1346
1332 1347 /*
1333 1348 * Match the name against prefixes in above blacklist. If the match was
1334 1349 * found, this name is blacklisted.
1335 1350 */
1336 1351 static boolean_t
1337 1352 name_is_blacklisted(const char *name)
1338 1353 {
1339 1354 int i, n;
1340 1355
1341 1356 n = sizeof (bop_prop_blacklist) / sizeof (bop_prop_blacklist[0]);
1342 1357 for (i = 0; i < n; i++) {
1343 1358 if (strncmp(bop_prop_blacklist[i].bl_name, name,
1344 1359 bop_prop_blacklist[i].bl_name_len - 1) == 0) {
1345 1360 return (B_TRUE);
1346 1361 }
1347 1362 }
1348 1363 return (B_FALSE);
1349 1364 }
1350 1365
1351 1366 static void
1352 1367 process_boot_environment(struct boot_modules *benv)
1353 1368 {
1354 1369 char *env, *ptr, *name, *value;
1355 1370 uint32_t size, name_len, value_len;
1356 1371
1357 1372 if (benv == NULL || benv->bm_type != BMT_ENV)
1358 1373 return;
1359 1374 ptr = env = benv->bm_addr;
1360 1375 size = benv->bm_size;
1361 1376 do {
1362 1377 name = ptr;
1363 1378 /* find '=' */
1364 1379 while (*ptr != '=') {
1365 1380 ptr++;
1366 1381 if (ptr > env + size) /* Something is very wrong. */
1367 1382 return;
1368 1383 }
1369 1384 name_len = ptr - name;
1370 1385 if (sizeof (buffer) <= name_len)
1371 1386 continue;
1372 1387
1373 1388 (void) strncpy(buffer, name, sizeof (buffer));
1374 1389 buffer[name_len] = '\0';
1375 1390 name = buffer;
1376 1391
1377 1392 value_len = 0;
1378 1393 value = ++ptr;
1379 1394 while ((uintptr_t)ptr - (uintptr_t)env < size) {
1380 1395 if (*ptr == '\0') {
1381 1396 ptr++;
1382 1397 value_len = (uintptr_t)ptr - (uintptr_t)env;
1383 1398 break;
1384 1399 }
1385 1400 ptr++;
1386 1401 }
1387 1402
1388 1403 /* Did we reach the end of the module? */
1389 1404 if (value_len == 0)
1390 1405 return;
1391 1406
1392 1407 if (*value == '\0')
1393 1408 continue;
1394 1409
1395 1410 /* Is this property already set? */
1396 1411 if (do_bsys_getproplen(NULL, name) >= 0)
1397 1412 continue;
1398 1413
1399 1414 /* Translate netboot variables */
1400 1415 if (strcmp(name, "boot.netif.gateway") == 0) {
1401 1416 bsetprops(BP_ROUTER_IP, value);
1402 1417 continue;
1403 1418 }
1404 1419 if (strcmp(name, "boot.netif.hwaddr") == 0) {
1405 1420 bsetprops(BP_BOOT_MAC, value);
1406 1421 continue;
1407 1422 }
1408 1423 if (strcmp(name, "boot.netif.ip") == 0) {
1409 1424 bsetprops(BP_HOST_IP, value);
1410 1425 continue;
1411 1426 }
1412 1427 if (strcmp(name, "boot.netif.netmask") == 0) {
1413 1428 bsetprops(BP_SUBNET_MASK, value);
1414 1429 continue;
1415 1430 }
1416 1431 if (strcmp(name, "boot.netif.server") == 0) {
1417 1432 bsetprops(BP_SERVER_IP, value);
1418 1433 continue;
1419 1434 }
1420 1435 if (strcmp(name, "boot.netif.server") == 0) {
1421 1436 if (do_bsys_getproplen(NULL, BP_SERVER_IP) < 0)
1422 1437 bsetprops(BP_SERVER_IP, value);
1423 1438 continue;
1424 1439 }
1425 1440 if (strcmp(name, "boot.nfsroot.server") == 0) {
1426 1441 if (do_bsys_getproplen(NULL, BP_SERVER_IP) < 0)
1427 1442 bsetprops(BP_SERVER_IP, value);
1428 1443 continue;
1429 1444 }
1430 1445 if (strcmp(name, "boot.nfsroot.path") == 0) {
1431 1446 bsetprops(BP_SERVER_PATH, value);
1432 1447 continue;
1433 1448 }
1434 1449
1435 1450 if (name_is_blacklisted(name) == B_TRUE)
1436 1451 continue;
1437 1452
1438 1453 /* Create new property. */
1439 1454 bsetprops(name, value);
1440 1455
1441 1456 /* Avoid reading past the module end. */
1442 1457 if (size <= (uintptr_t)ptr - (uintptr_t)env)
1443 1458 return;
1444 1459 } while (*ptr != '\0');
1445 1460 }
1446 1461
1447 1462 /*
1448 1463 * 1st pass at building the table of boot properties. This includes:
1449 1464 * - values set on the command line: -B a=x,b=y,c=z ....
1450 1465 * - known values we just compute (ie. from xbp)
1451 1466 * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
1452 1467 *
1453 1468 * the grub command line looked like:
1454 1469 * kernel boot-file [-B prop=value[,prop=value]...] [boot-args]
1455 1470 *
1456 1471 * whoami is the same as boot-file
1457 1472 */
1458 1473 static void
1459 1474 build_boot_properties(struct xboot_info *xbp)
1460 1475 {
1461 1476 char *name;
1462 1477 int name_len;
1463 1478 char *value;
1464 1479 int value_len;
1465 1480 struct boot_modules *bm, *rdbm, *benv = NULL;
1466 1481 char *propbuf;
1467 1482 int quoted = 0;
1468 1483 int boot_arg_len;
1469 1484 uint_t i, midx;
1470 1485 char modid[32];
1471 1486 #ifndef __xpv
1472 1487 static int stdout_val = 0;
1473 1488 uchar_t boot_device;
1474 1489 char str[3];
1475 1490 #endif
1476 1491
1477 1492 /*
1478 1493 * These have to be done first, so that kobj_mount_root() works
1479 1494 */
1480 1495 DBG_MSG("Building boot properties\n");
1481 1496 propbuf = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, 0);
1482 1497 DBG((uintptr_t)propbuf);
1483 1498 if (xbp->bi_module_cnt > 0) {
1484 1499 bm = xbp->bi_modules;
1485 1500 rdbm = NULL;
1486 1501 for (midx = i = 0; i < xbp->bi_module_cnt; i++) {
1487 1502 if (bm[i].bm_type == BMT_ROOTFS) {
1488 1503 rdbm = &bm[i];
1489 1504 continue;
1490 1505 }
1491 1506 if (bm[i].bm_type == BMT_HASH ||
1492 1507 bm[i].bm_type == BMT_FONT ||
1493 1508 bm[i].bm_name == NULL)
1494 1509 continue;
1495 1510
1496 1511 if (bm[i].bm_type == BMT_ENV) {
1497 1512 if (benv == NULL)
1498 1513 benv = &bm[i];
1499 1514 else
1500 1515 continue;
1501 1516 }
1502 1517
1503 1518 (void) snprintf(modid, sizeof (modid),
1504 1519 "module-name-%u", midx);
1505 1520 bsetprops(modid, (char *)bm[i].bm_name);
1506 1521 (void) snprintf(modid, sizeof (modid),
1507 1522 "module-addr-%u", midx);
1508 1523 bsetprop64(modid, (uint64_t)(uintptr_t)bm[i].bm_addr);
1509 1524 (void) snprintf(modid, sizeof (modid),
1510 1525 "module-size-%u", midx);
1511 1526 bsetprop64(modid, (uint64_t)bm[i].bm_size);
1512 1527 ++midx;
1513 1528 }
1514 1529 if (rdbm != NULL) {
1515 1530 bsetprop64("ramdisk_start",
1516 1531 (uint64_t)(uintptr_t)rdbm->bm_addr);
1517 1532 bsetprop64("ramdisk_end",
1518 1533 (uint64_t)(uintptr_t)rdbm->bm_addr + rdbm->bm_size);
1519 1534 }
1520 1535 }
1521 1536
1522 1537 /*
1523 1538 * If there are any boot time modules or hashes present, then disable
1524 1539 * fast reboot.
1525 1540 */
1526 1541 if (xbp->bi_module_cnt > 1) {
1527 1542 fastreboot_disable(FBNS_BOOTMOD);
1528 1543 }
1529 1544
1530 1545 #ifndef __xpv
1531 1546 /*
1532 1547 * Disable fast reboot if we're using the Multiboot 2 boot protocol,
1533 1548 * since we don't currently support MB2 info and module relocation.
1534 1549 * Note that fast reboot will have already been disabled if multiple
1535 1550 * modules are present, since the current implementation assumes that
1536 1551 * we only have a single module, the boot_archive.
1537 1552 */
1538 1553 if (xbp->bi_mb_version != 1) {
1539 1554 fastreboot_disable(FBNS_MULTIBOOT2);
1540 1555 }
1541 1556 #endif
1542 1557
1543 1558 DBG_MSG("Parsing command line for boot properties\n");
1544 1559 value = xbp->bi_cmdline;
1545 1560
1546 1561 /*
1547 1562 * allocate memory to collect boot_args into
1548 1563 */
1549 1564 boot_arg_len = strlen(xbp->bi_cmdline) + 1;
1550 1565 boot_args = do_bsys_alloc(NULL, NULL, boot_arg_len, MMU_PAGESIZE);
1551 1566 boot_args[0] = 0;
1552 1567 boot_arg_len = 0;
1553 1568
1554 1569 #ifdef __xpv
1555 1570 /*
1556 1571 * Xen puts a lot of device information in front of the kernel name
1557 1572 * let's grab them and make them boot properties. The first
1558 1573 * string w/o an "=" in it will be the boot-file property.
1559 1574 */
1560 1575 (void) strcpy(namebuf, "xpv-");
1561 1576 for (;;) {
1562 1577 /*
1563 1578 * get to next property
1564 1579 */
1565 1580 while (ISSPACE(*value))
1566 1581 ++value;
1567 1582 name = value;
1568 1583 /*
1569 1584 * look for an "="
1570 1585 */
1571 1586 while (*value && !ISSPACE(*value) && *value != '=') {
1572 1587 value++;
1573 1588 }
1574 1589 if (*value != '=') { /* no "=" in the property */
1575 1590 value = name;
1576 1591 break;
1577 1592 }
1578 1593 name_len = value - name;
1579 1594 value_len = 0;
1580 1595 /*
1581 1596 * skip over the "="
1582 1597 */
1583 1598 value++;
1584 1599 while (value[value_len] && !ISSPACE(value[value_len])) {
1585 1600 ++value_len;
1586 1601 }
1587 1602 /*
1588 1603 * build property name with "xpv-" prefix
1589 1604 */
1590 1605 if (name_len + 4 > 32) { /* skip if name too long */
1591 1606 value += value_len;
1592 1607 continue;
1593 1608 }
1594 1609 bcopy(name, &namebuf[4], name_len);
1595 1610 name_len += 4;
1596 1611 namebuf[name_len] = 0;
1597 1612 bcopy(value, propbuf, value_len);
1598 1613 propbuf[value_len] = 0;
1599 1614 bsetprops(namebuf, propbuf);
1600 1615
1601 1616 /*
1602 1617 * xpv-root is set to the logical disk name of the xen
1603 1618 * VBD when booting from a disk-based filesystem.
1604 1619 */
1605 1620 if (strcmp(namebuf, "xpv-root") == 0)
1606 1621 xen_vbdroot_props(propbuf);
1607 1622 /*
1608 1623 * While we're here, if we have a "xpv-nfsroot" property
1609 1624 * then we need to set "fstype" to "nfs" so we mount
1610 1625 * our root from the nfs server. Also parse the xpv-nfsroot
1611 1626 * property to create the properties that nfs_mountroot will
1612 1627 * need to find the root and mount it.
1613 1628 */
1614 1629 if (strcmp(namebuf, "xpv-nfsroot") == 0)
1615 1630 xen_nfsroot_props(propbuf);
1616 1631
1617 1632 if (strcmp(namebuf, "xpv-ip") == 0)
1618 1633 xen_ip_props(propbuf);
1619 1634 value += value_len;
1620 1635 }
1621 1636 #endif
1622 1637
1623 1638 while (ISSPACE(*value))
1624 1639 ++value;
1625 1640 /*
1626 1641 * value now points at the boot-file
1627 1642 */
1628 1643 value_len = 0;
1629 1644 while (value[value_len] && !ISSPACE(value[value_len]))
1630 1645 ++value_len;
1631 1646 if (value_len > 0) {
1632 1647 whoami = propbuf;
1633 1648 bcopy(value, whoami, value_len);
1634 1649 whoami[value_len] = 0;
1635 1650 bsetprops("boot-file", whoami);
1636 1651 /*
1637 1652 * strip leading path stuff from whoami, so running from
1638 1653 * PXE/miniroot makes sense.
1639 1654 */
1640 1655 if (strstr(whoami, "/platform/") != NULL)
1641 1656 whoami = strstr(whoami, "/platform/");
1642 1657 bsetprops("whoami", whoami);
1643 1658 }
1644 1659
1645 1660 /*
1646 1661 * Values forcibly set boot properties on the command line via -B.
1647 1662 * Allow use of quotes in values. Other stuff goes on kernel
1648 1663 * command line.
1649 1664 */
1650 1665 name = value + value_len;
1651 1666 while (*name != 0) {
1652 1667 /*
1653 1668 * anything not " -B" is copied to the command line
1654 1669 */
1655 1670 if (!ISSPACE(name[0]) || name[1] != '-' || name[2] != 'B') {
1656 1671 boot_args[boot_arg_len++] = *name;
1657 1672 boot_args[boot_arg_len] = 0;
1658 1673 ++name;
1659 1674 continue;
1660 1675 }
1661 1676
1662 1677 /*
1663 1678 * skip the " -B" and following white space
1664 1679 */
1665 1680 name += 3;
1666 1681 while (ISSPACE(*name))
1667 1682 ++name;
1668 1683 while (*name && !ISSPACE(*name)) {
1669 1684 value = strstr(name, "=");
1670 1685 if (value == NULL)
1671 1686 break;
1672 1687 name_len = value - name;
1673 1688 ++value;
1674 1689 value_len = 0;
1675 1690 quoted = 0;
1676 1691 for (; ; ++value_len) {
1677 1692 if (!value[value_len])
1678 1693 break;
1679 1694
1680 1695 /*
1681 1696 * is this value quoted?
1682 1697 */
1683 1698 if (value_len == 0 &&
1684 1699 (value[0] == '\'' || value[0] == '"')) {
1685 1700 quoted = value[0];
1686 1701 ++value_len;
1687 1702 }
1688 1703
1689 1704 /*
1690 1705 * In the quote accept any character,
1691 1706 * but look for ending quote.
1692 1707 */
1693 1708 if (quoted) {
1694 1709 if (value[value_len] == quoted)
1695 1710 quoted = 0;
1696 1711 continue;
1697 1712 }
1698 1713
1699 1714 /*
1700 1715 * a comma or white space ends the value
1701 1716 */
1702 1717 if (value[value_len] == ',' ||
1703 1718 ISSPACE(value[value_len]))
1704 1719 break;
1705 1720 }
1706 1721
1707 1722 if (value_len == 0) {
1708 1723 bsetprop(DDI_PROP_TYPE_ANY, name, name_len,
1709 1724 NULL, 0);
1710 1725 } else {
1711 1726 char *v = value;
1712 1727 int l = value_len;
1713 1728 if (v[0] == v[l - 1] &&
1714 1729 (v[0] == '\'' || v[0] == '"')) {
1715 1730 ++v;
1716 1731 l -= 2;
1717 1732 }
1718 1733 bcopy(v, propbuf, l);
1719 1734 propbuf[l] = '\0';
1720 1735 bsetprop(DDI_PROP_TYPE_STRING, name, name_len,
1721 1736 propbuf, l + 1);
1722 1737 }
1723 1738 name = value + value_len;
1724 1739 while (*name == ',')
1725 1740 ++name;
1726 1741 }
1727 1742 }
1728 1743
1729 1744 /*
1730 1745 * set boot-args property
1731 1746 * 1275 name is bootargs, so set
1732 1747 * that too
1733 1748 */
1734 1749 bsetprops("boot-args", boot_args);
1735 1750 bsetprops("bootargs", boot_args);
1736 1751
1737 1752 process_boot_environment(benv);
1738 1753
1739 1754 #ifndef __xpv
1740 1755 /*
1741 1756 * Build boot command line for Fast Reboot
1742 1757 */
1743 1758 build_fastboot_cmdline(xbp);
1744 1759
1745 1760 if (xbp->bi_mb_version == 1) {
1746 1761 multiboot_info_t *mbi = xbp->bi_mb_info;
1747 1762 int netboot;
1748 1763 struct sol_netinfo *sip;
1749 1764
1750 1765 /*
1751 1766 * set the BIOS boot device from GRUB
1752 1767 */
1753 1768 netboot = 0;
1754 1769
1755 1770 /*
1756 1771 * Save various boot information for Fast Reboot
1757 1772 */
1758 1773 save_boot_info(xbp);
1759 1774
1760 1775 if (mbi != NULL && mbi->flags & MB_INFO_BOOTDEV) {
1761 1776 boot_device = mbi->boot_device >> 24;
1762 1777 if (boot_device == 0x20)
1763 1778 netboot++;
1764 1779 str[0] = (boot_device >> 4) + '0';
1765 1780 str[1] = (boot_device & 0xf) + '0';
1766 1781 str[2] = 0;
1767 1782 bsetprops("bios-boot-device", str);
1768 1783 } else {
1769 1784 netboot = 1;
1770 1785 }
1771 1786
1772 1787 /*
1773 1788 * In the netboot case, drives_info is overloaded with the
1774 1789 * dhcp ack. This is not multiboot compliant and requires
1775 1790 * special pxegrub!
1776 1791 */
1777 1792 if (netboot && mbi->drives_length != 0) {
1778 1793 sip = (struct sol_netinfo *)(uintptr_t)mbi->drives_addr;
1779 1794 if (sip->sn_infotype == SN_TYPE_BOOTP)
1780 1795 bsetprop(DDI_PROP_TYPE_BYTE,
1781 1796 "bootp-response",
1782 1797 sizeof ("bootp-response"),
1783 1798 (void *)(uintptr_t)mbi->drives_addr,
1784 1799 mbi->drives_length);
1785 1800 else if (sip->sn_infotype == SN_TYPE_RARP)
1786 1801 setup_rarp_props(sip);
1787 1802 }
1788 1803 } else {
1789 1804 multiboot2_info_header_t *mbi = xbp->bi_mb_info;
1790 1805 multiboot_tag_bootdev_t *bootdev = NULL;
1791 1806 multiboot_tag_network_t *netdev = NULL;
1792 1807
1793 1808 if (mbi != NULL) {
1794 1809 bootdev = dboot_multiboot2_find_tag(mbi,
1795 1810 MULTIBOOT_TAG_TYPE_BOOTDEV);
1796 1811 netdev = dboot_multiboot2_find_tag(mbi,
1797 1812 MULTIBOOT_TAG_TYPE_NETWORK);
1798 1813 }
1799 1814 if (bootdev != NULL) {
1800 1815 DBG(bootdev->mb_biosdev);
1801 1816 boot_device = bootdev->mb_biosdev;
1802 1817 str[0] = (boot_device >> 4) + '0';
1803 1818 str[1] = (boot_device & 0xf) + '0';
1804 1819 str[2] = 0;
1805 1820 bsetprops("bios-boot-device", str);
1806 1821 }
1807 1822 if (netdev != NULL) {
1808 1823 bsetprop(DDI_PROP_TYPE_BYTE,
1809 1824 "bootp-response", sizeof ("bootp-response"),
1810 1825 (void *)(uintptr_t)netdev->mb_dhcpack,
1811 1826 netdev->mb_size -
1812 1827 sizeof (multiboot_tag_network_t));
1813 1828 }
1814 1829 }
1815 1830
1816 1831 bsetprop32("stdout", stdout_val);
1817 1832 #endif /* __xpv */
1818 1833
1819 1834 /*
1820 1835 * more conjured up values for made up things....
1821 1836 */
1822 1837 #if defined(__xpv)
1823 1838 bsetprops("mfg-name", "i86xpv");
1824 1839 bsetprops("impl-arch-name", "i86xpv");
1825 1840 #else
1826 1841 bsetprops("mfg-name", "i86pc");
1827 1842 bsetprops("impl-arch-name", "i86pc");
1828 1843 #endif
1829 1844
1830 1845 /*
1831 1846 * Build firmware-provided system properties
1832 1847 */
1833 1848 build_firmware_properties(xbp);
1834 1849
1835 1850 /*
1836 1851 * XXPV
1837 1852 *
1838 1853 * Find out what these are:
1839 1854 * - cpuid_feature_ecx_include
1840 1855 * - cpuid_feature_ecx_exclude
1841 1856 * - cpuid_feature_edx_include
1842 1857 * - cpuid_feature_edx_exclude
1843 1858 *
1844 1859 * Find out what these are in multiboot:
1845 1860 * - netdev-path
1846 1861 * - fstype
1847 1862 */
1848 1863 }
1849 1864
1850 1865 #ifdef __xpv
1851 1866 /*
1852 1867 * Under the Hypervisor, memory usable for DMA may be scarce. One
1853 1868 * very likely large pool of DMA friendly memory is occupied by
1854 1869 * the boot_archive, as it was loaded by grub into low MFNs.
1855 1870 *
1856 1871 * Here we free up that memory by copying the boot archive to what are
1857 1872 * likely higher MFN pages and then swapping the mfn/pfn mappings.
1858 1873 */
1859 1874 #define PFN_2GIG 0x80000
1860 1875 static void
1861 1876 relocate_boot_archive(struct xboot_info *xbp)
1862 1877 {
1863 1878 mfn_t max_mfn = HYPERVISOR_memory_op(XENMEM_maximum_ram_page, NULL);
1864 1879 struct boot_modules *bm = xbp->bi_modules;
1865 1880 uintptr_t va;
1866 1881 pfn_t va_pfn;
1867 1882 mfn_t va_mfn;
1868 1883 caddr_t copy;
1869 1884 pfn_t copy_pfn;
1870 1885 mfn_t copy_mfn;
1871 1886 size_t len;
1872 1887 int slop;
1873 1888 int total = 0;
1874 1889 int relocated = 0;
1875 1890 int mmu_update_return;
1876 1891 mmu_update_t t[2];
1877 1892 x86pte_t pte;
1878 1893
1879 1894 /*
1880 1895 * If all MFN's are below 2Gig, don't bother doing this.
1881 1896 */
1882 1897 if (max_mfn < PFN_2GIG)
1883 1898 return;
1884 1899 if (xbp->bi_module_cnt < 1) {
1885 1900 DBG_MSG("no boot_archive!");
1886 1901 return;
1887 1902 }
1888 1903
1889 1904 DBG_MSG("moving boot_archive to high MFN memory\n");
1890 1905 va = (uintptr_t)bm->bm_addr;
1891 1906 len = bm->bm_size;
1892 1907 slop = va & MMU_PAGEOFFSET;
1893 1908 if (slop) {
1894 1909 va += MMU_PAGESIZE - slop;
1895 1910 len -= MMU_PAGESIZE - slop;
1896 1911 }
1897 1912 len = P2ALIGN(len, MMU_PAGESIZE);
1898 1913
1899 1914 /*
1900 1915 * Go through all boot_archive pages, swapping any low MFN pages
1901 1916 * with memory at next_phys.
1902 1917 */
1903 1918 while (len != 0) {
1904 1919 ++total;
1905 1920 va_pfn = mmu_btop(va - ONE_GIG);
1906 1921 va_mfn = mfn_list[va_pfn];
1907 1922 if (mfn_list[va_pfn] < PFN_2GIG) {
1908 1923 copy = kbm_remap_window(next_phys, 1);
1909 1924 bcopy((void *)va, copy, MMU_PAGESIZE);
1910 1925 copy_pfn = mmu_btop(next_phys);
1911 1926 copy_mfn = mfn_list[copy_pfn];
1912 1927
1913 1928 pte = mfn_to_ma(copy_mfn) | PT_NOCONSIST | PT_VALID;
1914 1929 if (HYPERVISOR_update_va_mapping(va, pte,
1915 1930 UVMF_INVLPG | UVMF_LOCAL))
1916 1931 bop_panic("relocate_boot_archive(): "
1917 1932 "HYPERVISOR_update_va_mapping() failed");
1918 1933
1919 1934 mfn_list[va_pfn] = copy_mfn;
1920 1935 mfn_list[copy_pfn] = va_mfn;
1921 1936
1922 1937 t[0].ptr = mfn_to_ma(copy_mfn) | MMU_MACHPHYS_UPDATE;
1923 1938 t[0].val = va_pfn;
1924 1939 t[1].ptr = mfn_to_ma(va_mfn) | MMU_MACHPHYS_UPDATE;
1925 1940 t[1].val = copy_pfn;
1926 1941 if (HYPERVISOR_mmu_update(t, 2, &mmu_update_return,
1927 1942 DOMID_SELF) != 0 || mmu_update_return != 2)
1928 1943 bop_panic("relocate_boot_archive(): "
1929 1944 "HYPERVISOR_mmu_update() failed");
1930 1945
1931 1946 next_phys += MMU_PAGESIZE;
1932 1947 ++relocated;
1933 1948 }
1934 1949 len -= MMU_PAGESIZE;
1935 1950 va += MMU_PAGESIZE;
1936 1951 }
1937 1952 DBG_MSG("Relocated pages:\n");
1938 1953 DBG(relocated);
1939 1954 DBG_MSG("Out of total pages:\n");
1940 1955 DBG(total);
1941 1956 }
1942 1957 #endif /* __xpv */
1943 1958
1944 1959 #if !defined(__xpv)
1945 1960 /*
1946 1961 * simple description of a stack frame (args are 32 bit only currently)
1947 1962 */
1948 1963 typedef struct bop_frame {
1949 1964 struct bop_frame *old_frame;
1950 1965 pc_t retaddr;
1951 1966 long arg[1];
1952 1967 } bop_frame_t;
1953 1968
1954 1969 void
1955 1970 bop_traceback(bop_frame_t *frame)
1956 1971 {
1957 1972 pc_t pc;
1958 1973 int cnt;
1959 1974 char *ksym;
1960 1975 ulong_t off;
1961 1976
1962 1977 bop_printf(NULL, "Stack traceback:\n");
1963 1978 for (cnt = 0; cnt < 30; ++cnt) { /* up to 30 frames */
1964 1979 pc = frame->retaddr;
1965 1980 if (pc == 0)
1966 1981 break;
1967 1982 ksym = kobj_getsymname(pc, &off);
1968 1983 if (ksym)
1969 1984 bop_printf(NULL, " %s+%lx", ksym, off);
1970 1985 else
1971 1986 bop_printf(NULL, " 0x%lx", pc);
1972 1987
1973 1988 frame = frame->old_frame;
1974 1989 if (frame == 0) {
1975 1990 bop_printf(NULL, "\n");
1976 1991 break;
1977 1992 }
1978 1993 bop_printf(NULL, "\n");
1979 1994 }
1980 1995 }
1981 1996
1982 1997 struct trapframe {
1983 1998 ulong_t error_code; /* optional */
1984 1999 ulong_t inst_ptr;
1985 2000 ulong_t code_seg;
1986 2001 ulong_t flags_reg;
1987 2002 ulong_t stk_ptr;
1988 2003 ulong_t stk_seg;
1989 2004 };
1990 2005
1991 2006 void
1992 2007 bop_trap(ulong_t *tfp)
1993 2008 {
1994 2009 struct trapframe *tf = (struct trapframe *)tfp;
1995 2010 bop_frame_t fakeframe;
1996 2011 static int depth = 0;
1997 2012
1998 2013 /*
1999 2014 * Check for an infinite loop of traps.
2000 2015 */
2001 2016 if (++depth > 2)
2002 2017 bop_panic("Nested trap");
2003 2018
2004 2019 bop_printf(NULL, "Unexpected trap\n");
2005 2020
2006 2021 /*
2007 2022 * adjust the tf for optional error_code by detecting the code selector
2008 2023 */
2009 2024 if (tf->code_seg != B64CODE_SEL)
2010 2025 tf = (struct trapframe *)(tfp - 1);
2011 2026 else
2012 2027 bop_printf(NULL, "error code 0x%lx\n",
2013 2028 tf->error_code & 0xffffffff);
2014 2029
2015 2030 bop_printf(NULL, "instruction pointer 0x%lx\n", tf->inst_ptr);
2016 2031 bop_printf(NULL, "code segment 0x%lx\n", tf->code_seg & 0xffff);
2017 2032 bop_printf(NULL, "flags register 0x%lx\n", tf->flags_reg);
2018 2033 bop_printf(NULL, "return %%rsp 0x%lx\n", tf->stk_ptr);
2019 2034 bop_printf(NULL, "return %%ss 0x%lx\n", tf->stk_seg & 0xffff);
2020 2035 bop_printf(NULL, "%%cr2 0x%lx\n", getcr2());
2021 2036
2022 2037 /* grab %[er]bp pushed by our code from the stack */
2023 2038 fakeframe.old_frame = (bop_frame_t *)*(tfp - 3);
2024 2039 fakeframe.retaddr = (pc_t)tf->inst_ptr;
2025 2040 bop_printf(NULL, "Attempting stack backtrace:\n");
2026 2041 bop_traceback(&fakeframe);
2027 2042 bop_panic("unexpected trap in early boot");
2028 2043 }
2029 2044
2030 2045 extern void bop_trap_handler(void);
2031 2046
2032 2047 static gate_desc_t *bop_idt;
2033 2048
2034 2049 static desctbr_t bop_idt_info;
2035 2050
2036 2051 /*
2037 2052 * Install a temporary IDT that lets us catch errors in the boot time code.
2038 2053 * We shouldn't get any faults at all while this is installed, so we'll
2039 2054 * just generate a traceback and exit.
2040 2055 */
2041 2056 static void
2042 2057 bop_idt_init(void)
2043 2058 {
2044 2059 int t;
2045 2060
2046 2061 bop_idt = (gate_desc_t *)
2047 2062 do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, MMU_PAGESIZE);
2048 2063 bzero(bop_idt, MMU_PAGESIZE);
2049 2064 for (t = 0; t < NIDT; ++t) {
2050 2065 /*
2051 2066 * Note that since boot runs without a TSS, the
2052 2067 * double fault handler cannot use an alternate stack (64-bit).
2053 2068 */
2054 2069 set_gatesegd(&bop_idt[t], &bop_trap_handler, B64CODE_SEL,
2055 2070 SDT_SYSIGT, TRP_KPL, 0);
2056 2071 }
2057 2072 bop_idt_info.dtr_limit = (NIDT * sizeof (gate_desc_t)) - 1;
2058 2073 bop_idt_info.dtr_base = (uintptr_t)bop_idt;
2059 2074 wr_idtr(&bop_idt_info);
2060 2075 }
2061 2076 #endif /* !defined(__xpv) */
2062 2077
2063 2078 /*
2064 2079 * This is where we enter the kernel. It dummies up the boot_ops and
2065 2080 * boot_syscalls vectors and jumps off to _kobj_boot()
2066 2081 */
2067 2082 void
2068 2083 _start(struct xboot_info *xbp)
2069 2084 {
2070 2085 bootops_t *bops = &bootop;
2071 2086 extern void _kobj_boot();
2072 2087
2073 2088 /*
2074 2089 * 1st off - initialize the console for any error messages
2075 2090 */
2076 2091 xbootp = xbp;
2077 2092 #ifdef __xpv
2078 2093 HYPERVISOR_shared_info = (void *)xbp->bi_shared_info;
2079 2094 xen_info = xbp->bi_xen_start_info;
2080 2095 #endif
2081 2096
2082 2097 #ifndef __xpv
2083 2098 if (*((uint32_t *)(FASTBOOT_SWTCH_PA + FASTBOOT_STACK_OFFSET)) ==
2084 2099 FASTBOOT_MAGIC) {
2085 2100 post_fastreboot = 1;
2086 2101 *((uint32_t *)(FASTBOOT_SWTCH_PA + FASTBOOT_STACK_OFFSET)) = 0;
2087 2102 }
2088 2103 #endif
2089 2104
2090 2105 bcons_init(xbp);
2091 2106 have_console = 1;
2092 2107
2093 2108 /*
2094 2109 * enable debugging
2095 2110 */
2096 2111 if (find_boot_prop("kbm_debug") != NULL)
2097 2112 kbm_debug = 1;
2098 2113
2099 2114 DBG_MSG("\n\n*** Entered Solaris in _start() cmdline is: ");
2100 2115 DBG_MSG((char *)xbp->bi_cmdline);
2101 2116 DBG_MSG("\n\n\n");
2102 2117
2103 2118 /*
2104 2119 * physavail is no longer used by startup
2105 2120 */
2106 2121 bm.physinstalled = xbp->bi_phys_install;
2107 2122 bm.pcimem = xbp->bi_pcimem;
2108 2123 bm.rsvdmem = xbp->bi_rsvdmem;
2109 2124 bm.physavail = NULL;
2110 2125
2111 2126 /*
2112 2127 * initialize the boot time allocator
2113 2128 */
2114 2129 next_phys = xbp->bi_next_paddr;
2115 2130 DBG(next_phys);
2116 2131 next_virt = (uintptr_t)xbp->bi_next_vaddr;
2117 2132 DBG(next_virt);
2118 2133 DBG_MSG("Initializing boot time memory management...");
2119 2134 #ifdef __xpv
2120 2135 {
2121 2136 xen_platform_parameters_t p;
2122 2137
2123 2138 /* This call shouldn't fail, dboot already did it once. */
2124 2139 (void) HYPERVISOR_xen_version(XENVER_platform_parameters, &p);
2125 2140 mfn_to_pfn_mapping = (pfn_t *)(xen_virt_start = p.virt_start);
2126 2141 DBG(xen_virt_start);
2127 2142 }
2128 2143 #endif
2129 2144 kbm_init(xbp);
2130 2145 DBG_MSG("done\n");
2131 2146
2132 2147 /*
2133 2148 * Fill in the bootops vector
2134 2149 */
2135 2150 bops->bsys_version = BO_VERSION;
2136 2151 bops->boot_mem = &bm;
2137 2152 bops->bsys_alloc = do_bsys_alloc;
2138 2153 bops->bsys_free = do_bsys_free;
2139 2154 bops->bsys_getproplen = do_bsys_getproplen;
2140 2155 bops->bsys_getprop = do_bsys_getprop;
2141 2156 bops->bsys_nextprop = do_bsys_nextprop;
2142 2157 bops->bsys_printf = bop_printf;
2143 2158 bops->bsys_doint = do_bsys_doint;
2144 2159
2145 2160 /*
2146 2161 * BOP_EALLOC() is no longer needed
2147 2162 */
2148 2163 bops->bsys_ealloc = do_bsys_ealloc;
2149 2164
2150 2165 #ifdef __xpv
2151 2166 /*
2152 2167 * On domain 0 we need to free up some physical memory that is
2153 2168 * usable for DMA. Since GRUB loaded the boot_archive, it is
2154 2169 * sitting in low MFN memory. We'll relocated the boot archive
2155 2170 * pages to high PFN memory.
2156 2171 */
2157 2172 if (DOMAIN_IS_INITDOMAIN(xen_info))
2158 2173 relocate_boot_archive(xbp);
2159 2174 #endif
2160 2175
2161 2176 #ifndef __xpv
2162 2177 /*
2163 2178 * Install an IDT to catch early pagefaults (shouldn't have any).
2164 2179 * Also needed for kmdb.
2165 2180 */
2166 2181 bop_idt_init();
2167 2182 #endif
2168 2183 /* Set up the shadow fb for framebuffer console */
2169 2184 boot_fb_shadow_init(bops);
2170 2185
2171 2186 /*
2172 2187 * Start building the boot properties from the command line
2173 2188 */
2174 2189 DBG_MSG("Initializing boot properties:\n");
2175 2190 build_boot_properties(xbp);
2176 2191
2177 2192 if (find_boot_prop("prom_debug") || kbm_debug) {
2178 2193 char *value;
2179 2194
2180 2195 value = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, MMU_PAGESIZE);
2181 2196 boot_prop_display(value);
2182 2197 }
2183 2198
2184 2199 /*
2185 2200 * jump into krtld...
2186 2201 */
2187 2202 _kobj_boot(&bop_sysp, NULL, bops, NULL);
2188 2203 }
2189 2204
2190 2205
2191 2206 /*ARGSUSED*/
2192 2207 static caddr_t
2193 2208 no_more_alloc(bootops_t *bop, caddr_t virthint, size_t size, int align)
2194 2209 {
2195 2210 panic("Attempt to bsys_alloc() too late\n");
2196 2211 return (NULL);
2197 2212 }
2198 2213
2199 2214 /*ARGSUSED*/
2200 2215 static void
2201 2216 no_more_free(bootops_t *bop, caddr_t virt, size_t size)
2202 2217 {
2203 2218 panic("Attempt to bsys_free() too late\n");
2204 2219 }
2205 2220
2206 2221 void
2207 2222 bop_no_more_mem(void)
2208 2223 {
2209 2224 DBG(total_bop_alloc_scratch);
2210 2225 DBG(total_bop_alloc_kernel);
2211 2226 bootops->bsys_alloc = no_more_alloc;
2212 2227 bootops->bsys_free = no_more_free;
2213 2228 }
2214 2229
2215 2230
2216 2231 /*
2217 2232 * Set ACPI firmware properties
2218 2233 */
2219 2234
2220 2235 static caddr_t
2221 2236 vmap_phys(size_t length, paddr_t pa)
2222 2237 {
2223 2238 paddr_t start, end;
2224 2239 caddr_t va;
2225 2240 size_t len, page;
2226 2241
2227 2242 #ifdef __xpv
2228 2243 pa = pfn_to_pa(xen_assign_pfn(mmu_btop(pa))) | (pa & MMU_PAGEOFFSET);
2229 2244 #endif
2230 2245 start = P2ALIGN(pa, MMU_PAGESIZE);
2231 2246 end = P2ROUNDUP(pa + length, MMU_PAGESIZE);
2232 2247 len = end - start;
2233 2248 va = (caddr_t)alloc_vaddr(len, MMU_PAGESIZE);
2234 2249 for (page = 0; page < len; page += MMU_PAGESIZE)
2235 2250 kbm_map((uintptr_t)va + page, start + page, 0, 0);
2236 2251 return (va + (pa & MMU_PAGEOFFSET));
2237 2252 }
2238 2253
2239 2254 static uint8_t
2240 2255 checksum_table(uint8_t *tp, size_t len)
2241 2256 {
2242 2257 uint8_t sum = 0;
2243 2258
2244 2259 while (len-- > 0)
2245 2260 sum += *tp++;
2246 2261
2247 2262 return (sum);
2248 2263 }
2249 2264
2250 2265 static int
2251 2266 valid_rsdp(ACPI_TABLE_RSDP *rp)
2252 2267 {
2253 2268
2254 2269 /* validate the V1.x checksum */
2255 2270 if (checksum_table((uint8_t *)rp, ACPI_RSDP_CHECKSUM_LENGTH) != 0)
2256 2271 return (0);
2257 2272
2258 2273 /* If pre-ACPI 2.0, this is a valid RSDP */
2259 2274 if (rp->Revision < 2)
2260 2275 return (1);
2261 2276
2262 2277 /* validate the V2.x checksum */
2263 2278 if (checksum_table((uint8_t *)rp, ACPI_RSDP_XCHECKSUM_LENGTH) != 0)
2264 2279 return (0);
2265 2280
2266 2281 return (1);
2267 2282 }
2268 2283
2269 2284 /*
2270 2285 * Scan memory range for an RSDP;
2271 2286 * see ACPI 3.0 Spec, 5.2.5.1
2272 2287 */
2273 2288 static ACPI_TABLE_RSDP *
2274 2289 scan_rsdp(paddr_t *paddrp, size_t len)
2275 2290 {
2276 2291 paddr_t paddr = *paddrp;
2277 2292 caddr_t ptr;
2278 2293
2279 2294 ptr = vmap_phys(len, paddr);
2280 2295
2281 2296 while (len > 0) {
2282 2297 if (strncmp(ptr, ACPI_SIG_RSDP, strlen(ACPI_SIG_RSDP)) == 0 &&
2283 2298 valid_rsdp((ACPI_TABLE_RSDP *)ptr)) {
2284 2299 *paddrp = paddr;
2285 2300 return ((ACPI_TABLE_RSDP *)ptr);
2286 2301 }
2287 2302
2288 2303 ptr += ACPI_RSDP_SCAN_STEP;
2289 2304 paddr += ACPI_RSDP_SCAN_STEP;
2290 2305 len -= ACPI_RSDP_SCAN_STEP;
2291 2306 }
2292 2307
2293 2308 return (NULL);
2294 2309 }
2295 2310
2296 2311 /*
2297 2312 * Locate the ACPI RSDP. We search in a particular order:
2298 2313 *
2299 2314 * - If the bootloader told us the location of the RSDP (via the EFI system
2300 2315 * table), try that first.
2301 2316 * - Otherwise, look in the EBDA and BIOS memory as per ACPI 5.2.5.1 (legacy
2302 2317 * case).
2303 2318 * - Finally, our bootloader may have a copy of the RSDP in its info: this might
2304 2319 * get freed after boot, so we always prefer to find the original RSDP first.
2305 2320 *
2306 2321 * Once found, we set acpi-root-tab property (a physical address) for the
2307 2322 * benefit of acpica, acpidump etc.
2308 2323 */
2309 2324
2310 2325 static ACPI_TABLE_RSDP *
2311 2326 find_rsdp(struct xboot_info *xbp)
2312 2327 {
2313 2328 ACPI_TABLE_RSDP *rsdp = NULL;
2314 2329 paddr_t paddr = 0;
2315 2330
2316 2331 if (do_bsys_getproplen(NULL, "acpi-root-tab") == sizeof (uint64_t)) {
2317 2332 (void) do_bsys_getprop(NULL, "acpi-root-tab", &paddr);
2318 2333 rsdp = scan_rsdp(&paddr, sizeof (*rsdp));
2319 2334 }
2320 2335
2321 2336 #ifndef __xpv
2322 2337 if (rsdp == NULL && xbp->bi_acpi_rsdp != NULL) {
2323 2338 paddr = (uintptr_t)xbp->bi_acpi_rsdp;
2324 2339 rsdp = scan_rsdp(&paddr, sizeof (*rsdp));
2325 2340 }
2326 2341 #endif
2327 2342
2328 2343 if (rsdp == NULL) {
2329 2344 uint16_t *ebda_seg = (uint16_t *)vmap_phys(sizeof (uint16_t),
2330 2345 ACPI_EBDA_PTR_LOCATION);
2331 2346 paddr = *ebda_seg << 4;
2332 2347 rsdp = scan_rsdp(&paddr, ACPI_EBDA_WINDOW_SIZE);
2333 2348 }
2334 2349
2335 2350 if (rsdp == NULL) {
2336 2351 paddr = ACPI_HI_RSDP_WINDOW_BASE;
2337 2352 rsdp = scan_rsdp(&paddr, ACPI_HI_RSDP_WINDOW_SIZE);
2338 2353 }
2339 2354
2340 2355 #ifndef __xpv
2341 2356 if (rsdp == NULL && xbp->bi_acpi_rsdp_copy != NULL) {
2342 2357 paddr = (uintptr_t)xbp->bi_acpi_rsdp_copy;
2343 2358 rsdp = scan_rsdp(&paddr, sizeof (*rsdp));
2344 2359 }
2345 2360 #endif
2346 2361
2347 2362 if (rsdp == NULL) {
2348 2363 bop_printf(NULL, "no RSDP found!\n");
2349 2364 return (NULL);
2350 2365 }
2351 2366
2352 2367 if (kbm_debug)
2353 2368 bop_printf(NULL, "RSDP found at physical 0x%lx\n", paddr);
2354 2369
2355 2370 if (do_bsys_getproplen(NULL, "acpi-root-tab") != sizeof (uint64_t))
2356 2371 bsetprop64("acpi-root-tab", paddr);
2357 2372
2358 2373 return (rsdp);
2359 2374 }
2360 2375
2361 2376 static ACPI_TABLE_HEADER *
2362 2377 map_fw_table(paddr_t table_addr)
2363 2378 {
2364 2379 ACPI_TABLE_HEADER *tp;
2365 2380 size_t len = MAX(sizeof (*tp), MMU_PAGESIZE);
2366 2381
2367 2382 /*
2368 2383 * Map at least a page; if the table is larger than this, remap it
2369 2384 */
2370 2385 tp = (ACPI_TABLE_HEADER *)vmap_phys(len, table_addr);
2371 2386 if (tp->Length > len)
2372 2387 tp = (ACPI_TABLE_HEADER *)vmap_phys(tp->Length, table_addr);
2373 2388 return (tp);
2374 2389 }
2375 2390
2376 2391 static ACPI_TABLE_HEADER *
2377 2392 find_fw_table(ACPI_TABLE_RSDP *rsdp, char *signature)
2378 2393 {
2379 2394 static int revision = 0;
2380 2395 static ACPI_TABLE_XSDT *xsdt;
2381 2396 static int len;
2382 2397 paddr_t xsdt_addr;
2383 2398 ACPI_TABLE_HEADER *tp;
2384 2399 paddr_t table_addr;
2385 2400 int n;
2386 2401
2387 2402 if (strlen(signature) != ACPI_NAME_SIZE)
2388 2403 return (NULL);
2389 2404
2390 2405 /*
2391 2406 * Reading the ACPI 3.0 Spec, section 5.2.5.3 will help
2392 2407 * understand this code. If we haven't already found the RSDT/XSDT,
2393 2408 * revision will be 0. Find the RSDP and check the revision
2394 2409 * to find out whether to use the RSDT or XSDT. If revision is
2395 2410 * 0 or 1, use the RSDT and set internal revision to 1; if it is 2,
2396 2411 * use the XSDT. If the XSDT address is 0, though, fall back to
2397 2412 * revision 1 and use the RSDT.
2398 2413 */
2399 2414 if (revision == 0) {
2400 2415 if (rsdp == NULL)
2401 2416 return (NULL);
2402 2417
2403 2418 revision = rsdp->Revision;
2404 2419 /*
2405 2420 * ACPI 6.0 states that current revision is 2
2406 2421 * from acpi_table_rsdp definition:
2407 2422 * Must be (0) for ACPI 1.0 or (2) for ACPI 2.0+
2408 2423 */
2409 2424 if (revision > 2)
2410 2425 revision = 2;
2411 2426 switch (revision) {
2412 2427 case 2:
2413 2428 /*
2414 2429 * Use the XSDT unless BIOS is buggy and
2415 2430 * claims to be rev 2 but has a null XSDT
2416 2431 * address
2417 2432 */
2418 2433 xsdt_addr = rsdp->XsdtPhysicalAddress;
2419 2434 if (xsdt_addr != 0)
2420 2435 break;
2421 2436 /* FALLTHROUGH */
2422 2437 case 0:
2423 2438 /* treat RSDP rev 0 as revision 1 internally */
2424 2439 revision = 1;
2425 2440 /* FALLTHROUGH */
2426 2441 case 1:
2427 2442 /* use the RSDT for rev 0/1 */
2428 2443 xsdt_addr = rsdp->RsdtPhysicalAddress;
2429 2444 break;
2430 2445 default:
2431 2446 /* unknown revision */
2432 2447 revision = 0;
2433 2448 break;
2434 2449 }
2435 2450
2436 2451 if (revision == 0)
2437 2452 return (NULL);
2438 2453
2439 2454 /* cache the XSDT info */
2440 2455 xsdt = (ACPI_TABLE_XSDT *)map_fw_table(xsdt_addr);
2441 2456 len = (xsdt->Header.Length - sizeof (xsdt->Header)) /
2442 2457 ((revision == 1) ? sizeof (uint32_t) : sizeof (uint64_t));
2443 2458 }
2444 2459
2445 2460 /*
2446 2461 * Scan the table headers looking for a signature match
2447 2462 */
2448 2463 for (n = 0; n < len; n++) {
2449 2464 ACPI_TABLE_RSDT *rsdt = (ACPI_TABLE_RSDT *)xsdt;
2450 2465 table_addr = (revision == 1) ? rsdt->TableOffsetEntry[n] :
2451 2466 xsdt->TableOffsetEntry[n];
2452 2467
2453 2468 if (table_addr == 0)
2454 2469 continue;
2455 2470 tp = map_fw_table(table_addr);
2456 2471 if (strncmp(tp->Signature, signature, ACPI_NAME_SIZE) == 0) {
2457 2472 return (tp);
2458 2473 }
2459 2474 }
2460 2475 return (NULL);
2461 2476 }
2462 2477
2463 2478 static void
2464 2479 process_mcfg(ACPI_TABLE_MCFG *tp)
2465 2480 {
2466 2481 ACPI_MCFG_ALLOCATION *cfg_baap;
2467 2482 char *cfg_baa_endp;
2468 2483 int64_t ecfginfo[4];
2469 2484
2470 2485 cfg_baap = (ACPI_MCFG_ALLOCATION *)((uintptr_t)tp + sizeof (*tp));
2471 2486 cfg_baa_endp = ((char *)tp) + tp->Header.Length;
2472 2487 while ((char *)cfg_baap < cfg_baa_endp) {
2473 2488 if (cfg_baap->Address != 0 && cfg_baap->PciSegment == 0) {
2474 2489 ecfginfo[0] = cfg_baap->Address;
2475 2490 ecfginfo[1] = cfg_baap->PciSegment;
2476 2491 ecfginfo[2] = cfg_baap->StartBusNumber;
2477 2492 ecfginfo[3] = cfg_baap->EndBusNumber;
2478 2493 bsetprop(DDI_PROP_TYPE_INT64,
2479 2494 MCFG_PROPNAME, strlen(MCFG_PROPNAME),
2480 2495 ecfginfo, sizeof (ecfginfo));
2481 2496 break;
2482 2497 }
2483 2498 cfg_baap++;
2484 2499 }
2485 2500 }
2486 2501
2487 2502 #ifndef __xpv
2488 2503 static void
2489 2504 process_madt_entries(ACPI_TABLE_MADT *tp, uint32_t *cpu_countp,
2490 2505 uint32_t *cpu_possible_countp, uint32_t *cpu_apicid_array)
2491 2506 {
2492 2507 ACPI_SUBTABLE_HEADER *item, *end;
2493 2508 uint32_t cpu_count = 0;
2494 2509 uint32_t cpu_possible_count = 0;
2495 2510
2496 2511 /*
2497 2512 * Determine number of CPUs and keep track of "final" APIC ID
2498 2513 * for each CPU by walking through ACPI MADT processor list
2499 2514 */
2500 2515 end = (ACPI_SUBTABLE_HEADER *)(tp->Header.Length + (uintptr_t)tp);
2501 2516 item = (ACPI_SUBTABLE_HEADER *)((uintptr_t)tp + sizeof (*tp));
2502 2517
2503 2518 while (item < end) {
2504 2519 switch (item->Type) {
2505 2520 case ACPI_MADT_TYPE_LOCAL_APIC: {
2506 2521 ACPI_MADT_LOCAL_APIC *cpu =
2507 2522 (ACPI_MADT_LOCAL_APIC *) item;
2508 2523
2509 2524 if (cpu->LapicFlags & ACPI_MADT_ENABLED) {
2510 2525 if (cpu_apicid_array != NULL)
2511 2526 cpu_apicid_array[cpu_count] = cpu->Id;
2512 2527 cpu_count++;
2513 2528 }
2514 2529 cpu_possible_count++;
2515 2530 break;
2516 2531 }
2517 2532 case ACPI_MADT_TYPE_LOCAL_X2APIC: {
2518 2533 ACPI_MADT_LOCAL_X2APIC *cpu =
2519 2534 (ACPI_MADT_LOCAL_X2APIC *) item;
2520 2535
2521 2536 if (cpu->LapicFlags & ACPI_MADT_ENABLED) {
2522 2537 if (cpu_apicid_array != NULL)
2523 2538 cpu_apicid_array[cpu_count] =
2524 2539 cpu->LocalApicId;
2525 2540 cpu_count++;
2526 2541 }
2527 2542 cpu_possible_count++;
2528 2543 break;
2529 2544 }
2530 2545 default:
2531 2546 if (kbm_debug)
2532 2547 bop_printf(NULL, "MADT type %d\n", item->Type);
2533 2548 break;
2534 2549 }
2535 2550
2536 2551 item = (ACPI_SUBTABLE_HEADER *)((uintptr_t)item + item->Length);
2537 2552 }
2538 2553 if (cpu_countp)
2539 2554 *cpu_countp = cpu_count;
2540 2555 if (cpu_possible_countp)
2541 2556 *cpu_possible_countp = cpu_possible_count;
2542 2557 }
2543 2558
2544 2559 static void
2545 2560 process_madt(ACPI_TABLE_MADT *tp)
2546 2561 {
2547 2562 uint32_t cpu_count = 0;
2548 2563 uint32_t cpu_possible_count = 0;
2549 2564 uint32_t *cpu_apicid_array; /* x2APIC ID is 32bit! */
2550 2565
2551 2566 if (tp != NULL) {
2552 2567 /* count cpu's */
2553 2568 process_madt_entries(tp, &cpu_count, &cpu_possible_count, NULL);
2554 2569
2555 2570 cpu_apicid_array = (uint32_t *)do_bsys_alloc(NULL, NULL,
2556 2571 cpu_count * sizeof (*cpu_apicid_array), MMU_PAGESIZE);
2557 2572 if (cpu_apicid_array == NULL)
2558 2573 bop_panic("Not enough memory for APIC ID array");
2559 2574
2560 2575 /* copy IDs */
2561 2576 process_madt_entries(tp, NULL, NULL, cpu_apicid_array);
2562 2577
2563 2578 /*
2564 2579 * Make boot property for array of "final" APIC IDs for each
2565 2580 * CPU
2566 2581 */
2567 2582 bsetprop(DDI_PROP_TYPE_INT,
2568 2583 BP_CPU_APICID_ARRAY, strlen(BP_CPU_APICID_ARRAY),
2569 2584 cpu_apicid_array, cpu_count * sizeof (*cpu_apicid_array));
2570 2585 }
2571 2586
2572 2587 /*
2573 2588 * Check whether property plat-max-ncpus is already set.
2574 2589 */
2575 2590 if (do_bsys_getproplen(NULL, PLAT_MAX_NCPUS_NAME) < 0) {
2576 2591 /*
2577 2592 * Set plat-max-ncpus to number of maximum possible CPUs given
2578 2593 * in MADT if it hasn't been set.
2579 2594 * There's no formal way to detect max possible CPUs supported
2580 2595 * by platform according to ACPI spec3.0b. So current CPU
2581 2596 * hotplug implementation expects that all possible CPUs will
2582 2597 * have an entry in MADT table and set plat-max-ncpus to number
2583 2598 * of entries in MADT.
2584 2599 * With introducing of ACPI4.0, Maximum System Capability Table
2585 2600 * (MSCT) provides maximum number of CPUs supported by platform.
2586 2601 * If MSCT is unavailable, fall back to old way.
2587 2602 */
2588 2603 if (tp != NULL)
2589 2604 bsetpropsi(PLAT_MAX_NCPUS_NAME, cpu_possible_count);
2590 2605 }
2591 2606
2592 2607 /*
2593 2608 * Set boot property boot-max-ncpus to number of CPUs existing at
2594 2609 * boot time. boot-max-ncpus is mainly used for optimization.
2595 2610 */
2596 2611 if (tp != NULL)
2597 2612 bsetpropsi(BOOT_MAX_NCPUS_NAME, cpu_count);
2598 2613
2599 2614 /*
2600 2615 * User-set boot-ncpus overrides firmware count
2601 2616 */
2602 2617 if (do_bsys_getproplen(NULL, BOOT_NCPUS_NAME) >= 0)
2603 2618 return;
2604 2619
2605 2620 /*
2606 2621 * Set boot property boot-ncpus to number of active CPUs given in MADT
2607 2622 * if it hasn't been set yet.
2608 2623 */
2609 2624 if (tp != NULL)
2610 2625 bsetpropsi(BOOT_NCPUS_NAME, cpu_count);
2611 2626 }
2612 2627
2613 2628 static void
2614 2629 process_srat(ACPI_TABLE_SRAT *tp)
2615 2630 {
2616 2631 ACPI_SUBTABLE_HEADER *item, *end;
2617 2632 int i;
2618 2633 int proc_num, mem_num;
2619 2634 #pragma pack(1)
2620 2635 struct {
2621 2636 uint32_t domain;
2622 2637 uint32_t apic_id;
2623 2638 uint32_t sapic_id;
2624 2639 } processor;
2625 2640 struct {
2626 2641 uint32_t domain;
2627 2642 uint32_t x2apic_id;
2628 2643 } x2apic;
2629 2644 struct {
2630 2645 uint32_t domain;
2631 2646 uint64_t addr;
2632 2647 uint64_t length;
2633 2648 uint32_t flags;
2634 2649 } memory;
2635 2650 #pragma pack()
2636 2651 char prop_name[30];
2637 2652 uint64_t maxmem = 0;
2638 2653
2639 2654 if (tp == NULL)
2640 2655 return;
2641 2656
2642 2657 proc_num = mem_num = 0;
2643 2658 end = (ACPI_SUBTABLE_HEADER *)(tp->Header.Length + (uintptr_t)tp);
2644 2659 item = (ACPI_SUBTABLE_HEADER *)((uintptr_t)tp + sizeof (*tp));
2645 2660 while (item < end) {
2646 2661 switch (item->Type) {
2647 2662 case ACPI_SRAT_TYPE_CPU_AFFINITY: {
2648 2663 ACPI_SRAT_CPU_AFFINITY *cpu =
2649 2664 (ACPI_SRAT_CPU_AFFINITY *) item;
2650 2665
2651 2666 if (!(cpu->Flags & ACPI_SRAT_CPU_ENABLED))
2652 2667 break;
2653 2668 processor.domain = cpu->ProximityDomainLo;
2654 2669 for (i = 0; i < 3; i++)
2655 2670 processor.domain +=
2656 2671 cpu->ProximityDomainHi[i] << ((i + 1) * 8);
2657 2672 processor.apic_id = cpu->ApicId;
2658 2673 processor.sapic_id = cpu->LocalSapicEid;
2659 2674 (void) snprintf(prop_name, 30, "acpi-srat-processor-%d",
2660 2675 proc_num);
2661 2676 bsetprop(DDI_PROP_TYPE_INT,
2662 2677 prop_name, strlen(prop_name), &processor,
2663 2678 sizeof (processor));
2664 2679 proc_num++;
2665 2680 break;
2666 2681 }
2667 2682 case ACPI_SRAT_TYPE_MEMORY_AFFINITY: {
2668 2683 ACPI_SRAT_MEM_AFFINITY *mem =
2669 2684 (ACPI_SRAT_MEM_AFFINITY *)item;
2670 2685
2671 2686 if (!(mem->Flags & ACPI_SRAT_MEM_ENABLED))
2672 2687 break;
2673 2688 memory.domain = mem->ProximityDomain;
2674 2689 memory.addr = mem->BaseAddress;
2675 2690 memory.length = mem->Length;
2676 2691 memory.flags = mem->Flags;
2677 2692 (void) snprintf(prop_name, 30, "acpi-srat-memory-%d",
2678 2693 mem_num);
2679 2694 bsetprop(DDI_PROP_TYPE_INT,
2680 2695 prop_name, strlen(prop_name), &memory,
2681 2696 sizeof (memory));
2682 2697 if ((mem->Flags & ACPI_SRAT_MEM_HOT_PLUGGABLE) &&
2683 2698 (memory.addr + memory.length > maxmem)) {
2684 2699 maxmem = memory.addr + memory.length;
2685 2700 }
2686 2701 mem_num++;
2687 2702 break;
2688 2703 }
2689 2704 case ACPI_SRAT_TYPE_X2APIC_CPU_AFFINITY: {
2690 2705 ACPI_SRAT_X2APIC_CPU_AFFINITY *x2cpu =
2691 2706 (ACPI_SRAT_X2APIC_CPU_AFFINITY *) item;
2692 2707
2693 2708 if (!(x2cpu->Flags & ACPI_SRAT_CPU_ENABLED))
2694 2709 break;
2695 2710 x2apic.domain = x2cpu->ProximityDomain;
2696 2711 x2apic.x2apic_id = x2cpu->ApicId;
2697 2712 (void) snprintf(prop_name, 30, "acpi-srat-processor-%d",
2698 2713 proc_num);
2699 2714 bsetprop(DDI_PROP_TYPE_INT,
2700 2715 prop_name, strlen(prop_name), &x2apic,
2701 2716 sizeof (x2apic));
2702 2717 proc_num++;
2703 2718 break;
2704 2719 }
2705 2720 default:
2706 2721 if (kbm_debug)
2707 2722 bop_printf(NULL, "SRAT type %d\n", item->Type);
2708 2723 break;
2709 2724 }
2710 2725
2711 2726 item = (ACPI_SUBTABLE_HEADER *)
2712 2727 (item->Length + (uintptr_t)item);
2713 2728 }
2714 2729
2715 2730 /*
2716 2731 * The maximum physical address calculated from the SRAT table is more
2717 2732 * accurate than that calculated from the MSCT table.
2718 2733 */
2719 2734 if (maxmem != 0) {
2720 2735 plat_dr_physmax = btop(maxmem);
2721 2736 }
2722 2737 }
2723 2738
2724 2739 static void
2725 2740 process_slit(ACPI_TABLE_SLIT *tp)
2726 2741 {
2727 2742
2728 2743 /*
2729 2744 * Check the number of localities; if it's too huge, we just
2730 2745 * return and locality enumeration code will handle this later,
2731 2746 * if possible.
2732 2747 *
2733 2748 * Note that the size of the table is the square of the
2734 2749 * number of localities; if the number of localities exceeds
2735 2750 * UINT16_MAX, the table size may overflow an int when being
2736 2751 * passed to bsetprop() below.
2737 2752 */
2738 2753 if (tp->LocalityCount >= SLIT_LOCALITIES_MAX)
2739 2754 return;
2740 2755
2741 2756 bsetprop64(SLIT_NUM_PROPNAME, tp->LocalityCount);
2742 2757 bsetprop(DDI_PROP_TYPE_BYTE,
2743 2758 SLIT_PROPNAME, strlen(SLIT_PROPNAME), &tp->Entry,
2744 2759 tp->LocalityCount * tp->LocalityCount);
2745 2760 }
2746 2761
2747 2762 static ACPI_TABLE_MSCT *
2748 2763 process_msct(ACPI_TABLE_MSCT *tp)
2749 2764 {
2750 2765 int last_seen = 0;
2751 2766 int proc_num = 0;
2752 2767 ACPI_MSCT_PROXIMITY *item, *end;
2753 2768 extern uint64_t plat_dr_options;
2754 2769
2755 2770 ASSERT(tp != NULL);
2756 2771
2757 2772 end = (ACPI_MSCT_PROXIMITY *)(tp->Header.Length + (uintptr_t)tp);
2758 2773 for (item = (void *)((uintptr_t)tp + tp->ProximityOffset);
2759 2774 item < end;
2760 2775 item = (void *)(item->Length + (uintptr_t)item)) {
2761 2776 /*
2762 2777 * Sanity check according to section 5.2.19.1 of ACPI 4.0.
2763 2778 * Revision 1
2764 2779 * Length 22
2765 2780 */
2766 2781 if (item->Revision != 1 || item->Length != 22) {
2767 2782 cmn_err(CE_CONT,
2768 2783 "?boot: unknown proximity domain structure in MSCT "
2769 2784 "with Revision(%d), Length(%d).\n",
2770 2785 (int)item->Revision, (int)item->Length);
2771 2786 return (NULL);
2772 2787 } else if (item->RangeStart > item->RangeEnd) {
2773 2788 cmn_err(CE_CONT,
2774 2789 "?boot: invalid proximity domain structure in MSCT "
2775 2790 "with RangeStart(%u), RangeEnd(%u).\n",
2776 2791 item->RangeStart, item->RangeEnd);
2777 2792 return (NULL);
2778 2793 } else if (item->RangeStart != last_seen) {
2779 2794 /*
2780 2795 * Items must be organized in ascending order of the
2781 2796 * proximity domain enumerations.
2782 2797 */
2783 2798 cmn_err(CE_CONT,
2784 2799 "?boot: invalid proximity domain structure in MSCT,"
2785 2800 " items are not orginized in ascending order.\n");
2786 2801 return (NULL);
2787 2802 }
2788 2803
2789 2804 /*
2790 2805 * If ProcessorCapacity is 0 then there would be no CPUs in this
2791 2806 * domain.
2792 2807 */
2793 2808 if (item->ProcessorCapacity != 0) {
2794 2809 proc_num += (item->RangeEnd - item->RangeStart + 1) *
2795 2810 item->ProcessorCapacity;
2796 2811 }
2797 2812
2798 2813 last_seen = item->RangeEnd - item->RangeStart + 1;
2799 2814 /*
2800 2815 * Break out if all proximity domains have been processed.
2801 2816 * Some BIOSes may have unused items at the end of MSCT table.
2802 2817 */
2803 2818 if (last_seen > tp->MaxProximityDomains) {
2804 2819 break;
2805 2820 }
2806 2821 }
2807 2822 if (last_seen != tp->MaxProximityDomains + 1) {
2808 2823 cmn_err(CE_CONT,
2809 2824 "?boot: invalid proximity domain structure in MSCT, "
2810 2825 "proximity domain count doesn't match.\n");
2811 2826 return (NULL);
2812 2827 }
2813 2828
2814 2829 /*
2815 2830 * Set plat-max-ncpus property if it hasn't been set yet.
2816 2831 */
2817 2832 if (do_bsys_getproplen(NULL, PLAT_MAX_NCPUS_NAME) < 0) {
2818 2833 if (proc_num != 0) {
2819 2834 bsetpropsi(PLAT_MAX_NCPUS_NAME, proc_num);
2820 2835 }
2821 2836 }
2822 2837
2823 2838 /*
2824 2839 * Use Maximum Physical Address from the MSCT table as upper limit for
2825 2840 * memory hot-adding by default. It may be overridden by value from
2826 2841 * the SRAT table or the "plat-dr-physmax" boot option.
2827 2842 */
2828 2843 plat_dr_physmax = btop(tp->MaxAddress + 1);
2829 2844
2830 2845 /*
2831 2846 * Existence of MSCT implies CPU/memory hotplug-capability for the
2832 2847 * platform.
2833 2848 */
2834 2849 plat_dr_options |= PLAT_DR_FEATURE_CPU;
2835 2850 plat_dr_options |= PLAT_DR_FEATURE_MEMORY;
2836 2851
2837 2852 return (tp);
2838 2853 }
2839 2854
2840 2855 #else /* __xpv */
2841 2856 static void
2842 2857 enumerate_xen_cpus()
2843 2858 {
2844 2859 processorid_t id, max_id;
2845 2860
2846 2861 /*
2847 2862 * User-set boot-ncpus overrides enumeration
2848 2863 */
2849 2864 if (do_bsys_getproplen(NULL, BOOT_NCPUS_NAME) >= 0)
2850 2865 return;
2851 2866
2852 2867 /*
2853 2868 * Probe every possible virtual CPU id and remember the
2854 2869 * highest id present; the count of CPUs is one greater
2855 2870 * than this. This tacitly assumes at least cpu 0 is present.
2856 2871 */
2857 2872 max_id = 0;
2858 2873 for (id = 0; id < MAX_VIRT_CPUS; id++)
2859 2874 if (HYPERVISOR_vcpu_op(VCPUOP_is_up, id, NULL) == 0)
2860 2875 max_id = id;
2861 2876
2862 2877 bsetpropsi(BOOT_NCPUS_NAME, max_id+1);
2863 2878
2864 2879 }
2865 2880 #endif /* __xpv */
2866 2881
2867 2882 /*ARGSUSED*/
2868 2883 static void
2869 2884 build_firmware_properties(struct xboot_info *xbp)
2870 2885 {
2871 2886 ACPI_TABLE_HEADER *tp = NULL;
2872 2887 ACPI_TABLE_RSDP *rsdp;
2873 2888
2874 2889 #ifndef __xpv
2875 2890 if (xbp->bi_uefi_arch == XBI_UEFI_ARCH_64) {
2876 2891 bsetprops("efi-systype", "64");
2877 2892 bsetprop64("efi-systab",
2878 2893 (uint64_t)(uintptr_t)xbp->bi_uefi_systab);
2879 2894 if (kbm_debug)
2880 2895 bop_printf(NULL, "64-bit UEFI detected.\n");
2881 2896 } else if (xbp->bi_uefi_arch == XBI_UEFI_ARCH_32) {
2882 2897 bsetprops("efi-systype", "32");
2883 2898 bsetprop64("efi-systab",
2884 2899 (uint64_t)(uintptr_t)xbp->bi_uefi_systab);
2885 2900 if (kbm_debug)
2886 2901 bop_printf(NULL, "32-bit UEFI detected.\n");
2887 2902 }
2888 2903
2889 2904 if (xbp->bi_smbios != NULL) {
2890 2905 bsetprop64("smbios-address",
2891 2906 (uint64_t)(uintptr_t)xbp->bi_smbios);
2892 2907 }
2893 2908
2894 2909 rsdp = find_rsdp(xbp);
2895 2910
2896 2911 if ((tp = find_fw_table(rsdp, ACPI_SIG_MSCT)) != NULL)
2897 2912 msct_ptr = process_msct((ACPI_TABLE_MSCT *)tp);
2898 2913 else
2899 2914 msct_ptr = NULL;
2900 2915
2901 2916 if ((tp = find_fw_table(rsdp, ACPI_SIG_MADT)) != NULL)
2902 2917 process_madt((ACPI_TABLE_MADT *)tp);
2903 2918
2904 2919 if ((srat_ptr = (ACPI_TABLE_SRAT *)
2905 2920 find_fw_table(rsdp, ACPI_SIG_SRAT)) != NULL)
2906 2921 process_srat(srat_ptr);
2907 2922
2908 2923 if (slit_ptr = (ACPI_TABLE_SLIT *)find_fw_table(rsdp, ACPI_SIG_SLIT))
2909 2924 process_slit(slit_ptr);
2910 2925
2911 2926 tp = find_fw_table(rsdp, ACPI_SIG_MCFG);
2912 2927 #else /* __xpv */
2913 2928 enumerate_xen_cpus();
2914 2929 if (DOMAIN_IS_INITDOMAIN(xen_info))
2915 2930 tp = find_fw_table(rsdp, ACPI_SIG_MCFG);
2916 2931 #endif /* __xpv */
2917 2932 if (tp != NULL)
2918 2933 process_mcfg((ACPI_TABLE_MCFG *)tp);
2919 2934 }
2920 2935
2921 2936 /*
2922 2937 * fake up a boot property for deferred early console output
2923 2938 * this is used by both graphical boot and the (developer only)
2924 2939 * USB serial console
2925 2940 */
2926 2941 void *
2927 2942 defcons_init(size_t size)
2928 2943 {
2929 2944 static char *p = NULL;
2930 2945
2931 2946 p = do_bsys_alloc(NULL, NULL, size, MMU_PAGESIZE);
2932 2947 *p = 0;
2933 2948 bsetprop32("deferred-console-buf", (uint32_t)((uintptr_t)&p));
2934 2949 return (p);
2935 2950 }
2936 2951
2937 2952 /*ARGSUSED*/
2938 2953 int
2939 2954 boot_compinfo(int fd, struct compinfo *cbp)
2940 2955 {
2941 2956 cbp->iscmp = 0;
2942 2957 cbp->blksize = MAXBSIZE;
2943 2958 return (0);
2944 2959 }
2945 2960
2946 2961 /*
2947 2962 * Get an integer value for given boot property
2948 2963 */
2949 2964 int
2950 2965 bootprop_getval(const char *prop_name, u_longlong_t *prop_value)
2951 2966 {
2952 2967 int boot_prop_len;
2953 2968 char str[BP_MAX_STRLEN];
2954 2969 u_longlong_t value;
2955 2970
2956 2971 boot_prop_len = BOP_GETPROPLEN(bootops, prop_name);
2957 2972 if (boot_prop_len < 0 || boot_prop_len >= sizeof (str) ||
2958 2973 BOP_GETPROP(bootops, prop_name, str) < 0 ||
2959 2974 kobj_getvalue(str, &value) == -1)
2960 2975 return (-1);
2961 2976
2962 2977 if (prop_value)
2963 2978 *prop_value = value;
2964 2979
2965 2980 return (0);
2966 2981 }
2967 2982
2968 2983 int
2969 2984 bootprop_getstr(const char *prop_name, char *buf, size_t buflen)
2970 2985 {
2971 2986 int boot_prop_len = BOP_GETPROPLEN(bootops, prop_name);
2972 2987
2973 2988 if (boot_prop_len < 0 || boot_prop_len >= buflen ||
2974 2989 BOP_GETPROP(bootops, prop_name, buf) < 0)
2975 2990 return (-1);
2976 2991
2977 2992 return (0);
2978 2993 }
↓ open down ↓ |
2112 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX