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