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