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