Print this page
9709 Remove support for BZIP2 from dump
Reviewed by: Sanjay Nadkarni <sanjay.nadkarni@nexenta.com>
Reviewed by: Yuri Pankov <yuri.pankov@nexenta.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/i86pc/os/machdep.c
+++ new/usr/src/uts/i86pc/os/machdep.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
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
24 + * Copyright 2018 Nexenta Systems, Inc. All rights reserved.
24 25 * Copyright 2017, Joyent, Inc.
25 26 */
26 27 /*
27 28 * Copyright (c) 2010, Intel Corporation.
28 29 * All rights reserved.
29 30 */
30 31
31 32 #include <sys/types.h>
32 33 #include <sys/t_lock.h>
33 34 #include <sys/param.h>
34 35 #include <sys/segments.h>
35 36 #include <sys/sysmacros.h>
36 37 #include <sys/signal.h>
37 38 #include <sys/systm.h>
38 39 #include <sys/user.h>
39 40 #include <sys/mman.h>
40 41 #include <sys/vm.h>
41 42
42 43 #include <sys/disp.h>
43 44 #include <sys/class.h>
44 45
45 46 #include <sys/proc.h>
46 47 #include <sys/buf.h>
47 48 #include <sys/kmem.h>
48 49
49 50 #include <sys/reboot.h>
50 51 #include <sys/uadmin.h>
51 52 #include <sys/callb.h>
52 53
53 54 #include <sys/cred.h>
54 55 #include <sys/vnode.h>
55 56 #include <sys/file.h>
56 57
57 58 #include <sys/procfs.h>
58 59 #include <sys/acct.h>
59 60
60 61 #include <sys/vfs.h>
61 62 #include <sys/dnlc.h>
62 63 #include <sys/var.h>
63 64 #include <sys/cmn_err.h>
64 65 #include <sys/utsname.h>
65 66 #include <sys/debug.h>
66 67
67 68 #include <sys/dumphdr.h>
68 69 #include <sys/bootconf.h>
69 70 #include <sys/varargs.h>
70 71 #include <sys/promif.h>
71 72 #include <sys/modctl.h>
72 73
73 74 #include <sys/consdev.h>
74 75 #include <sys/frame.h>
75 76
76 77 #include <sys/sunddi.h>
77 78 #include <sys/ddidmareq.h>
78 79 #include <sys/psw.h>
79 80 #include <sys/regset.h>
80 81 #include <sys/privregs.h>
81 82 #include <sys/clock.h>
82 83 #include <sys/tss.h>
83 84 #include <sys/cpu.h>
84 85 #include <sys/stack.h>
85 86 #include <sys/trap.h>
86 87 #include <sys/pic.h>
87 88 #include <vm/hat.h>
88 89 #include <vm/anon.h>
89 90 #include <vm/as.h>
90 91 #include <vm/page.h>
91 92 #include <vm/seg.h>
92 93 #include <vm/seg_kmem.h>
93 94 #include <vm/seg_map.h>
94 95 #include <vm/seg_vn.h>
95 96 #include <vm/seg_kp.h>
96 97 #include <vm/hat_i86.h>
97 98 #include <sys/swap.h>
98 99 #include <sys/thread.h>
99 100 #include <sys/sysconf.h>
100 101 #include <sys/vm_machparam.h>
101 102 #include <sys/archsystm.h>
102 103 #include <sys/machsystm.h>
103 104 #include <sys/machlock.h>
104 105 #include <sys/x_call.h>
105 106 #include <sys/instance.h>
106 107
107 108 #include <sys/time.h>
108 109 #include <sys/smp_impldefs.h>
109 110 #include <sys/psm_types.h>
110 111 #include <sys/atomic.h>
111 112 #include <sys/panic.h>
112 113 #include <sys/cpuvar.h>
113 114 #include <sys/dtrace.h>
114 115 #include <sys/bl.h>
115 116 #include <sys/nvpair.h>
116 117 #include <sys/x86_archext.h>
117 118 #include <sys/pool_pset.h>
118 119 #include <sys/autoconf.h>
119 120 #include <sys/mem.h>
120 121 #include <sys/dumphdr.h>
121 122 #include <sys/compress.h>
122 123 #include <sys/cpu_module.h>
123 124 #if defined(__xpv)
124 125 #include <sys/hypervisor.h>
125 126 #include <sys/xpv_panic.h>
126 127 #endif
127 128
128 129 #include <sys/fastboot.h>
129 130 #include <sys/machelf.h>
130 131 #include <sys/kobj.h>
131 132 #include <sys/multiboot.h>
132 133
133 134 #ifdef TRAPTRACE
134 135 #include <sys/traptrace.h>
135 136 #endif /* TRAPTRACE */
136 137
137 138 #include <c2/audit.h>
138 139 #include <sys/clock_impl.h>
139 140
140 141 extern void audit_enterprom(int);
141 142 extern void audit_exitprom(int);
142 143
143 144 /*
144 145 * Tunable to enable apix PSM; if set to 0, pcplusmp PSM will be used.
145 146 */
146 147 int apix_enable = 1;
147 148
148 149 int apic_nvidia_io_max = 0; /* no. of NVIDIA i/o apics */
149 150
150 151 /*
151 152 * Occassionally the kernel knows better whether to power-off or reboot.
152 153 */
153 154 int force_shutdown_method = AD_UNKNOWN;
154 155
155 156 /*
156 157 * The panicbuf array is used to record messages and state:
157 158 */
158 159 char panicbuf[PANICBUFSIZE];
159 160
160 161 /*
161 162 * Flags to control Dynamic Reconfiguration features.
162 163 */
163 164 uint64_t plat_dr_options;
164 165
165 166 /*
166 167 * Maximum physical address for memory DR operations.
167 168 */
168 169 uint64_t plat_dr_physmax;
169 170
170 171 /*
171 172 * maxphys - used during physio
172 173 * klustsize - used for klustering by swapfs and specfs
173 174 */
174 175 int maxphys = 56 * 1024; /* XXX See vm_subr.c - max b_count in physio */
175 176 int klustsize = 56 * 1024;
176 177
177 178 caddr_t p0_va; /* Virtual address for accessing physical page 0 */
178 179
179 180 /*
180 181 * defined here, though unused on x86,
181 182 * to make kstat_fr.c happy.
182 183 */
183 184 int vac;
184 185
185 186 void debug_enter(char *);
186 187
187 188 extern void pm_cfb_check_and_powerup(void);
188 189 extern void pm_cfb_rele(void);
189 190
190 191 extern fastboot_info_t newkernel;
191 192
192 193 /*
193 194 * Machine dependent code to reboot.
194 195 * "mdep" is interpreted as a character pointer; if non-null, it is a pointer
195 196 * to a string to be used as the argument string when rebooting.
196 197 *
197 198 * "invoke_cb" is a boolean. It is set to true when mdboot() can safely
198 199 * invoke CB_CL_MDBOOT callbacks before shutting the system down, i.e. when
199 200 * we are in a normal shutdown sequence (interrupts are not blocked, the
200 201 * system is not panic'ing or being suspended).
201 202 */
202 203 /*ARGSUSED*/
203 204 void
204 205 mdboot(int cmd, int fcn, char *mdep, boolean_t invoke_cb)
205 206 {
206 207 processorid_t bootcpuid = 0;
207 208 static int is_first_quiesce = 1;
208 209 static int is_first_reset = 1;
209 210 int reset_status = 0;
210 211 static char fallback_str[] = "Falling back to regular reboot.\n";
211 212
212 213 if (fcn == AD_FASTREBOOT && !newkernel.fi_valid)
213 214 fcn = AD_BOOT;
214 215
215 216 if (!panicstr) {
216 217 kpreempt_disable();
217 218 if (fcn == AD_FASTREBOOT) {
218 219 mutex_enter(&cpu_lock);
219 220 if (CPU_ACTIVE(cpu_get(bootcpuid))) {
220 221 affinity_set(bootcpuid);
221 222 }
222 223 mutex_exit(&cpu_lock);
223 224 } else {
224 225 affinity_set(CPU_CURRENT);
225 226 }
226 227 }
227 228
228 229 if (force_shutdown_method != AD_UNKNOWN)
229 230 fcn = force_shutdown_method;
230 231
231 232 /*
232 233 * XXX - rconsvp is set to NULL to ensure that output messages
233 234 * are sent to the underlying "hardware" device using the
234 235 * monitor's printf routine since we are in the process of
235 236 * either rebooting or halting the machine.
236 237 */
237 238 rconsvp = NULL;
238 239
239 240 /*
240 241 * Print the reboot message now, before pausing other cpus.
241 242 * There is a race condition in the printing support that
242 243 * can deadlock multiprocessor machines.
243 244 */
244 245 if (!(fcn == AD_HALT || fcn == AD_POWEROFF))
245 246 prom_printf("rebooting...\n");
246 247
247 248 if (IN_XPV_PANIC())
248 249 reset();
249 250
250 251 /*
251 252 * We can't bring up the console from above lock level, so do it now
252 253 */
253 254 pm_cfb_check_and_powerup();
254 255
255 256 /* make sure there are no more changes to the device tree */
256 257 devtree_freeze();
257 258
258 259 if (invoke_cb)
259 260 (void) callb_execute_class(CB_CL_MDBOOT, NULL);
260 261
261 262 /*
262 263 * Clear any unresolved UEs from memory.
263 264 */
264 265 page_retire_mdboot();
265 266
266 267 #if defined(__xpv)
267 268 /*
268 269 * XXPV Should probably think some more about how we deal
269 270 * with panicing before it's really safe to panic.
270 271 * On hypervisors, we reboot very quickly.. Perhaps panic
271 272 * should only attempt to recover by rebooting if,
272 273 * say, we were able to mount the root filesystem,
273 274 * or if we successfully launched init(1m).
274 275 */
275 276 if (panicstr && proc_init == NULL)
276 277 (void) HYPERVISOR_shutdown(SHUTDOWN_poweroff);
277 278 #endif
278 279 /*
279 280 * stop other cpus and raise our priority. since there is only
280 281 * one active cpu after this, and our priority will be too high
281 282 * for us to be preempted, we're essentially single threaded
282 283 * from here on out.
283 284 */
284 285 (void) spl6();
285 286 if (!panicstr) {
286 287 mutex_enter(&cpu_lock);
287 288 pause_cpus(NULL, NULL);
288 289 mutex_exit(&cpu_lock);
289 290 }
290 291
291 292 /*
292 293 * If the system is panicking, the preloaded kernel is valid, and
293 294 * fastreboot_onpanic has been set, and the system has been up for
294 295 * longer than fastreboot_onpanic_uptime (default to 10 minutes),
295 296 * choose Fast Reboot.
296 297 */
297 298 if (fcn == AD_BOOT && panicstr && newkernel.fi_valid &&
298 299 fastreboot_onpanic &&
299 300 (panic_lbolt - lbolt_at_boot) > fastreboot_onpanic_uptime) {
300 301 fcn = AD_FASTREBOOT;
301 302 }
302 303
303 304 /*
304 305 * Try to quiesce devices.
305 306 */
306 307 if (is_first_quiesce) {
307 308 /*
308 309 * Clear is_first_quiesce before calling quiesce_devices()
309 310 * so that if quiesce_devices() causes panics, it will not
310 311 * be invoked again.
311 312 */
312 313 is_first_quiesce = 0;
313 314
314 315 quiesce_active = 1;
315 316 quiesce_devices(ddi_root_node(), &reset_status);
316 317 if (reset_status == -1) {
317 318 if (fcn == AD_FASTREBOOT && !force_fastreboot) {
318 319 prom_printf("Driver(s) not capable of fast "
319 320 "reboot.\n");
320 321 prom_printf(fallback_str);
321 322 fastreboot_capable = 0;
322 323 fcn = AD_BOOT;
323 324 } else if (fcn != AD_FASTREBOOT)
324 325 fastreboot_capable = 0;
325 326 }
326 327 quiesce_active = 0;
327 328 }
328 329
329 330 /*
330 331 * Try to reset devices. reset_leaves() should only be called
331 332 * a) when there are no other threads that could be accessing devices,
332 333 * and
333 334 * b) on a system that's not capable of fast reboot (fastreboot_capable
334 335 * being 0), or on a system where quiesce_devices() failed to
335 336 * complete (quiesce_active being 1).
336 337 */
337 338 if (is_first_reset && (!fastreboot_capable || quiesce_active)) {
338 339 /*
339 340 * Clear is_first_reset before calling reset_devices()
340 341 * so that if reset_devices() causes panics, it will not
341 342 * be invoked again.
342 343 */
343 344 is_first_reset = 0;
344 345 reset_leaves();
345 346 }
346 347
347 348 /* Verify newkernel checksum */
348 349 if (fastreboot_capable && fcn == AD_FASTREBOOT &&
349 350 fastboot_cksum_verify(&newkernel) != 0) {
350 351 fastreboot_capable = 0;
351 352 prom_printf("Fast reboot: checksum failed for the new "
352 353 "kernel.\n");
353 354 prom_printf(fallback_str);
354 355 }
355 356
356 357 (void) spl8();
357 358
358 359 if (fastreboot_capable && fcn == AD_FASTREBOOT) {
359 360 /*
360 361 * psm_shutdown is called within fast_reboot()
361 362 */
362 363 fast_reboot();
363 364 } else {
364 365 (*psm_shutdownf)(cmd, fcn);
365 366
366 367 if (fcn == AD_HALT || fcn == AD_POWEROFF)
367 368 halt((char *)NULL);
368 369 else
369 370 prom_reboot("");
370 371 }
371 372 /*NOTREACHED*/
372 373 }
373 374
374 375 /* mdpreboot - may be called prior to mdboot while root fs still mounted */
375 376 /*ARGSUSED*/
376 377 void
377 378 mdpreboot(int cmd, int fcn, char *mdep)
378 379 {
379 380 if (fcn == AD_FASTREBOOT && !fastreboot_capable) {
380 381 fcn = AD_BOOT;
381 382 #ifdef __xpv
382 383 cmn_err(CE_WARN, "Fast reboot is not supported on xVM");
383 384 #else
384 385 cmn_err(CE_WARN,
385 386 "Fast reboot is not supported on this platform%s",
386 387 fastreboot_nosup_message());
387 388 #endif
388 389 }
389 390
390 391 if (fcn == AD_FASTREBOOT) {
391 392 fastboot_load_kernel(mdep);
392 393 if (!newkernel.fi_valid)
393 394 fcn = AD_BOOT;
394 395 }
395 396
396 397 (*psm_preshutdownf)(cmd, fcn);
397 398 }
398 399
399 400 static void
400 401 stop_other_cpus(void)
401 402 {
402 403 ulong_t s = clear_int_flag(); /* fast way to keep CPU from changing */
403 404 cpuset_t xcset;
404 405
405 406 CPUSET_ALL_BUT(xcset, CPU->cpu_id);
406 407 xc_priority(0, 0, 0, CPUSET2BV(xcset), (xc_func_t)mach_cpu_halt);
407 408 restore_int_flag(s);
408 409 }
409 410
410 411 /*
411 412 * Machine dependent abort sequence handling
412 413 */
413 414 void
414 415 abort_sequence_enter(char *msg)
415 416 {
416 417 if (abort_enable == 0) {
417 418 if (AU_ZONE_AUDITING(GET_KCTX_GZ))
418 419 audit_enterprom(0);
419 420 return;
420 421 }
421 422 if (AU_ZONE_AUDITING(GET_KCTX_GZ))
422 423 audit_enterprom(1);
423 424 debug_enter(msg);
424 425 if (AU_ZONE_AUDITING(GET_KCTX_GZ))
425 426 audit_exitprom(1);
426 427 }
427 428
428 429 /*
429 430 * Enter debugger. Called when the user types ctrl-alt-d or whenever
430 431 * code wants to enter the debugger and possibly resume later.
431 432 *
432 433 * msg: message to print, possibly NULL.
433 434 */
434 435 void
435 436 debug_enter(char *msg)
436 437 {
437 438 if (dtrace_debugger_init != NULL)
438 439 (*dtrace_debugger_init)();
439 440
440 441 if (msg != NULL || (boothowto & RB_DEBUG))
441 442 prom_printf("\n");
442 443
443 444 if (msg != NULL)
444 445 prom_printf("%s\n", msg);
445 446
446 447 if (boothowto & RB_DEBUG)
447 448 kmdb_enter();
448 449
449 450 if (dtrace_debugger_fini != NULL)
450 451 (*dtrace_debugger_fini)();
451 452 }
452 453
453 454 void
454 455 reset(void)
455 456 {
456 457 extern void acpi_reset_system();
457 458 #if !defined(__xpv)
458 459 ushort_t *bios_memchk;
459 460
460 461 /*
461 462 * Can't use psm_map_phys or acpi_reset_system before the hat is
462 463 * initialized.
463 464 */
464 465 if (khat_running) {
465 466 bios_memchk = (ushort_t *)psm_map_phys(0x472,
466 467 sizeof (ushort_t), PROT_READ | PROT_WRITE);
467 468 if (bios_memchk)
468 469 *bios_memchk = 0x1234; /* bios memory check disable */
469 470
470 471 if (options_dip != NULL &&
471 472 ddi_prop_exists(DDI_DEV_T_ANY, ddi_root_node(), 0,
472 473 "efi-systab")) {
473 474 if (bootops == NULL)
474 475 acpi_reset_system();
475 476 efi_reset();
476 477 }
477 478
478 479 /*
479 480 * The problem with using stubs is that we can call
480 481 * acpi_reset_system only after the kernel is up and running.
481 482 *
482 483 * We should create a global state to keep track of how far
483 484 * up the kernel is but for the time being we will depend on
484 485 * bootops. bootops cleared in startup_end().
485 486 */
486 487 if (bootops == NULL)
487 488 acpi_reset_system();
488 489 }
489 490
490 491 pc_reset();
491 492 #else
492 493 if (IN_XPV_PANIC()) {
493 494 if (khat_running && bootops == NULL) {
494 495 acpi_reset_system();
495 496 }
496 497
497 498 pc_reset();
498 499 }
499 500
500 501 (void) HYPERVISOR_shutdown(SHUTDOWN_reboot);
501 502 panic("HYPERVISOR_shutdown() failed");
502 503 #endif
503 504 /*NOTREACHED*/
504 505 }
505 506
506 507 /*
507 508 * Halt the machine and return to the monitor
508 509 */
509 510 void
510 511 halt(char *s)
511 512 {
512 513 stop_other_cpus(); /* send stop signal to other CPUs */
513 514 if (s)
514 515 prom_printf("(%s) \n", s);
515 516 prom_exit_to_mon();
516 517 /*NOTREACHED*/
517 518 }
518 519
519 520 /*
520 521 * Initiate interrupt redistribution.
521 522 */
522 523 void
523 524 i_ddi_intr_redist_all_cpus()
524 525 {
525 526 }
526 527
527 528 /*
528 529 * XXX These probably ought to live somewhere else
529 530 * XXX They are called from mem.c
530 531 */
531 532
532 533 /*
533 534 * Convert page frame number to an OBMEM page frame number
534 535 * (i.e. put in the type bits -- zero for this implementation)
535 536 */
536 537 pfn_t
537 538 impl_obmem_pfnum(pfn_t pf)
538 539 {
539 540 return (pf);
540 541 }
541 542
542 543 #ifdef NM_DEBUG
543 544 int nmi_test = 0; /* checked in intentry.s during clock int */
544 545 int nmtest = -1;
545 546 nmfunc1(int arg, struct regs *rp)
546 547 {
547 548 printf("nmi called with arg = %x, regs = %x\n", arg, rp);
548 549 nmtest += 50;
549 550 if (arg == nmtest) {
550 551 printf("ip = %x\n", rp->r_pc);
551 552 return (1);
552 553 }
553 554 return (0);
554 555 }
555 556
556 557 #endif
557 558
558 559 #include <sys/bootsvcs.h>
559 560
560 561 /* Hacked up initialization for initial kernel check out is HERE. */
561 562 /* The basic steps are: */
562 563 /* kernel bootfuncs definition/initialization for KADB */
563 564 /* kadb bootfuncs pointer initialization */
564 565 /* putchar/getchar (interrupts disabled) */
565 566
566 567 /* kadb bootfuncs pointer initialization */
567 568
568 569 int
569 570 sysp_getchar()
570 571 {
571 572 int i;
572 573 ulong_t s;
573 574
574 575 if (cons_polledio == NULL) {
575 576 /* Uh oh */
576 577 prom_printf("getchar called with no console\n");
577 578 for (;;)
578 579 /* LOOP FOREVER */;
579 580 }
580 581
581 582 s = clear_int_flag();
582 583 i = cons_polledio->cons_polledio_getchar(
583 584 cons_polledio->cons_polledio_argument);
584 585 restore_int_flag(s);
585 586 return (i);
586 587 }
587 588
588 589 void
589 590 sysp_putchar(int c)
590 591 {
591 592 ulong_t s;
592 593
593 594 /*
594 595 * We have no alternative but to drop the output on the floor.
595 596 */
596 597 if (cons_polledio == NULL ||
597 598 cons_polledio->cons_polledio_putchar == NULL)
598 599 return;
599 600
600 601 s = clear_int_flag();
601 602 cons_polledio->cons_polledio_putchar(
602 603 cons_polledio->cons_polledio_argument, c);
603 604 restore_int_flag(s);
604 605 }
605 606
606 607 int
607 608 sysp_ischar()
608 609 {
609 610 int i;
610 611 ulong_t s;
611 612
612 613 if (cons_polledio == NULL ||
613 614 cons_polledio->cons_polledio_ischar == NULL)
614 615 return (0);
615 616
616 617 s = clear_int_flag();
617 618 i = cons_polledio->cons_polledio_ischar(
618 619 cons_polledio->cons_polledio_argument);
619 620 restore_int_flag(s);
620 621 return (i);
621 622 }
622 623
623 624 int
624 625 goany(void)
625 626 {
626 627 prom_printf("Type any key to continue ");
627 628 (void) prom_getchar();
628 629 prom_printf("\n");
629 630 return (1);
630 631 }
631 632
632 633 static struct boot_syscalls kern_sysp = {
633 634 sysp_getchar, /* unchar (*getchar)(); 7 */
634 635 sysp_putchar, /* int (*putchar)(); 8 */
635 636 sysp_ischar, /* int (*ischar)(); 9 */
636 637 };
637 638
638 639 #if defined(__xpv)
639 640 int using_kern_polledio;
640 641 #endif
641 642
642 643 void
643 644 kadb_uses_kernel()
644 645 {
645 646 /*
646 647 * This routine is now totally misnamed, since it does not in fact
647 648 * control kadb's I/O; it only controls the kernel's prom_* I/O.
648 649 */
649 650 sysp = &kern_sysp;
650 651 #if defined(__xpv)
651 652 using_kern_polledio = 1;
652 653 #endif
653 654 }
654 655
655 656 /*
656 657 * the interface to the outside world
657 658 */
658 659
659 660 /*
660 661 * poll_port -- wait for a register to achieve a
661 662 * specific state. Arguments are a mask of bits we care about,
662 663 * and two sub-masks. To return normally, all the bits in the
663 664 * first sub-mask must be ON, all the bits in the second sub-
664 665 * mask must be OFF. If about seconds pass without the register
665 666 * achieving the desired bit configuration, we return 1, else
666 667 * 0.
667 668 */
668 669 int
669 670 poll_port(ushort_t port, ushort_t mask, ushort_t onbits, ushort_t offbits)
670 671 {
671 672 int i;
672 673 ushort_t maskval;
673 674
674 675 for (i = 500000; i; i--) {
675 676 maskval = inb(port) & mask;
676 677 if (((maskval & onbits) == onbits) &&
677 678 ((maskval & offbits) == 0))
678 679 return (0);
679 680 drv_usecwait(10);
680 681 }
681 682 return (1);
682 683 }
683 684
684 685 /*
685 686 * set_idle_cpu is called from idle() when a CPU becomes idle.
686 687 */
687 688 /*LINTED: static unused */
688 689 static uint_t last_idle_cpu;
689 690
690 691 /*ARGSUSED*/
691 692 void
692 693 set_idle_cpu(int cpun)
693 694 {
694 695 last_idle_cpu = cpun;
695 696 (*psm_set_idle_cpuf)(cpun);
696 697 }
697 698
698 699 /*
699 700 * unset_idle_cpu is called from idle() when a CPU is no longer idle.
700 701 */
701 702 /*ARGSUSED*/
702 703 void
703 704 unset_idle_cpu(int cpun)
704 705 {
705 706 (*psm_unset_idle_cpuf)(cpun);
706 707 }
707 708
708 709 /*
709 710 * This routine is almost correct now, but not quite. It still needs the
710 711 * equivalent concept of "hres_last_tick", just like on the sparc side.
711 712 * The idea is to take a snapshot of the hi-res timer while doing the
712 713 * hrestime_adj updates under hres_lock in locore, so that the small
713 714 * interval between interrupt assertion and interrupt processing is
714 715 * accounted for correctly. Once we have this, the code below should
715 716 * be modified to subtract off hres_last_tick rather than hrtime_base.
716 717 *
717 718 * I'd have done this myself, but I don't have source to all of the
718 719 * vendor-specific hi-res timer routines (grrr...). The generic hook I
719 720 * need is something like "gethrtime_unlocked()", which would be just like
720 721 * gethrtime() but would assume that you're already holding CLOCK_LOCK().
721 722 * This is what the GET_HRTIME() macro is for on sparc (although it also
722 723 * serves the function of making time available without a function call
723 724 * so you don't take a register window overflow while traps are disabled).
724 725 */
725 726 void
726 727 pc_gethrestime(timestruc_t *tp)
727 728 {
728 729 int lock_prev;
729 730 timestruc_t now;
730 731 int nslt; /* nsec since last tick */
731 732 int adj; /* amount of adjustment to apply */
732 733
733 734 loop:
734 735 lock_prev = hres_lock;
735 736 now = hrestime;
736 737 nslt = (int)(gethrtime() - hres_last_tick);
737 738 if (nslt < 0) {
738 739 /*
739 740 * nslt < 0 means a tick came between sampling
740 741 * gethrtime() and hres_last_tick; restart the loop
741 742 */
742 743
743 744 goto loop;
744 745 }
745 746 now.tv_nsec += nslt;
746 747 if (hrestime_adj != 0) {
747 748 if (hrestime_adj > 0) {
748 749 adj = (nslt >> ADJ_SHIFT);
749 750 if (adj > hrestime_adj)
750 751 adj = (int)hrestime_adj;
751 752 } else {
752 753 adj = -(nslt >> ADJ_SHIFT);
753 754 if (adj < hrestime_adj)
754 755 adj = (int)hrestime_adj;
755 756 }
756 757 now.tv_nsec += adj;
757 758 }
758 759 while ((unsigned long)now.tv_nsec >= NANOSEC) {
759 760
760 761 /*
761 762 * We might have a large adjustment or have been in the
762 763 * debugger for a long time; take care of (at most) four
763 764 * of those missed seconds (tv_nsec is 32 bits, so
764 765 * anything >4s will be wrapping around). However,
765 766 * anything more than 2 seconds out of sync will trigger
766 767 * timedelta from clock() to go correct the time anyway,
767 768 * so do what we can, and let the big crowbar do the
768 769 * rest. A similar correction while loop exists inside
769 770 * hres_tick(); in all cases we'd like tv_nsec to
770 771 * satisfy 0 <= tv_nsec < NANOSEC to avoid confusing
771 772 * user processes, but if tv_sec's a little behind for a
772 773 * little while, that's OK; time still monotonically
773 774 * increases.
774 775 */
775 776
776 777 now.tv_nsec -= NANOSEC;
777 778 now.tv_sec++;
778 779 }
779 780 if ((hres_lock & ~1) != lock_prev)
780 781 goto loop;
781 782
782 783 *tp = now;
783 784 }
784 785
785 786 void
786 787 gethrestime_lasttick(timespec_t *tp)
787 788 {
788 789 int s;
789 790
790 791 s = hr_clock_lock();
791 792 *tp = hrestime;
792 793 hr_clock_unlock(s);
793 794 }
794 795
795 796 time_t
796 797 gethrestime_sec(void)
797 798 {
798 799 timestruc_t now;
799 800
800 801 gethrestime(&now);
801 802 return (now.tv_sec);
802 803 }
803 804
804 805 /*
805 806 * Initialize a kernel thread's stack
806 807 */
807 808
808 809 caddr_t
809 810 thread_stk_init(caddr_t stk)
810 811 {
811 812 ASSERT(((uintptr_t)stk & (STACK_ALIGN - 1)) == 0);
812 813 return (stk - SA(MINFRAME));
813 814 }
814 815
815 816 /*
816 817 * Initialize lwp's kernel stack.
817 818 */
818 819
819 820 #ifdef TRAPTRACE
820 821 /*
821 822 * There's a tricky interdependency here between use of sysenter and
822 823 * TRAPTRACE which needs recording to avoid future confusion (this is
823 824 * about the third time I've re-figured this out ..)
824 825 *
825 826 * Here's how debugging lcall works with TRAPTRACE.
826 827 *
827 828 * 1 We're in userland with a breakpoint on the lcall instruction.
828 829 * 2 We execute the instruction - the instruction pushes the userland
829 830 * %ss, %esp, %efl, %cs, %eip on the stack and zips into the kernel
830 831 * via the call gate.
831 832 * 3 The hardware raises a debug trap in kernel mode, the hardware
832 833 * pushes %efl, %cs, %eip and gets to dbgtrap via the idt.
833 834 * 4 dbgtrap pushes the error code and trapno and calls cmntrap
834 835 * 5 cmntrap finishes building a trap frame
835 836 * 6 The TRACE_REGS macros in cmntrap copy a REGSIZE worth chunk
836 837 * off the stack into the traptrace buffer.
837 838 *
838 839 * This means that the traptrace buffer contains the wrong values in
839 840 * %esp and %ss, but everything else in there is correct.
840 841 *
841 842 * Here's how debugging sysenter works with TRAPTRACE.
842 843 *
843 844 * a We're in userland with a breakpoint on the sysenter instruction.
844 845 * b We execute the instruction - the instruction pushes -nothing-
845 846 * on the stack, but sets %cs, %eip, %ss, %esp to prearranged
846 847 * values to take us to sys_sysenter, at the top of the lwp's
847 848 * stack.
848 849 * c goto 3
849 850 *
850 851 * At this point, because we got into the kernel without the requisite
851 852 * five pushes on the stack, if we didn't make extra room, we'd
852 853 * end up with the TRACE_REGS macro fetching the saved %ss and %esp
853 854 * values from negative (unmapped) stack addresses -- which really bites.
854 855 * That's why we do the '-= 8' below.
855 856 *
856 857 * XXX Note that reading "up" lwp0's stack works because t0 is declared
857 858 * right next to t0stack in locore.s
858 859 */
859 860 #endif
860 861
861 862 caddr_t
862 863 lwp_stk_init(klwp_t *lwp, caddr_t stk)
863 864 {
864 865 caddr_t oldstk;
865 866 struct pcb *pcb = &lwp->lwp_pcb;
866 867
867 868 oldstk = stk;
868 869 stk -= SA(sizeof (struct regs) + SA(MINFRAME));
869 870 #ifdef TRAPTRACE
870 871 stk -= 2 * sizeof (greg_t); /* space for phony %ss:%sp (see above) */
871 872 #endif
872 873 stk = (caddr_t)((uintptr_t)stk & ~(STACK_ALIGN - 1ul));
873 874 bzero(stk, oldstk - stk);
874 875 lwp->lwp_regs = (void *)(stk + SA(MINFRAME));
875 876
876 877 /*
877 878 * Arrange that the virtualized %fs and %gs GDT descriptors
878 879 * have a well-defined initial state (present, ring 3
879 880 * and of type data).
880 881 */
881 882 #if defined(__amd64)
882 883 if (lwp_getdatamodel(lwp) == DATAMODEL_NATIVE)
883 884 pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_udesc;
884 885 else
885 886 pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_u32desc;
886 887 #elif defined(__i386)
887 888 pcb->pcb_fsdesc = pcb->pcb_gsdesc = zero_udesc;
888 889 #endif /* __i386 */
889 890 lwp_installctx(lwp);
890 891 return (stk);
891 892 }
892 893
893 894 /*
894 895 * Use this opportunity to free any dynamically allocated fp storage.
895 896 */
896 897 void
897 898 lwp_stk_fini(klwp_t *lwp)
898 899 {
899 900 fp_lwp_cleanup(lwp);
900 901 }
901 902
902 903 void
903 904 lwp_fp_init(klwp_t *lwp)
904 905 {
905 906 fp_lwp_init(lwp);
906 907 }
907 908
908 909 /*
909 910 * If we're not the panic CPU, we wait in panic_idle for reboot.
910 911 */
911 912 void
912 913 panic_idle(void)
913 914 {
914 915 splx(ipltospl(CLOCK_LEVEL));
915 916 (void) setjmp(&curthread->t_pcb);
916 917
917 918 dumpsys_helper();
918 919
919 920 #ifndef __xpv
920 921 for (;;)
921 922 i86_halt();
922 923 #else
923 924 for (;;)
924 925 ;
925 926 #endif
926 927 }
927 928
928 929 /*
929 930 * Stop the other CPUs by cross-calling them and forcing them to enter
930 931 * the panic_idle() loop above.
931 932 */
932 933 /*ARGSUSED*/
933 934 void
934 935 panic_stopcpus(cpu_t *cp, kthread_t *t, int spl)
935 936 {
936 937 processorid_t i;
937 938 cpuset_t xcset;
938 939
939 940 /*
940 941 * In the case of a Xen panic, the hypervisor has already stopped
941 942 * all of the CPUs.
942 943 */
943 944 if (!IN_XPV_PANIC()) {
944 945 (void) splzs();
945 946
946 947 CPUSET_ALL_BUT(xcset, cp->cpu_id);
947 948 xc_priority(0, 0, 0, CPUSET2BV(xcset), (xc_func_t)panic_idle);
948 949 }
949 950
950 951 for (i = 0; i < NCPU; i++) {
951 952 if (i != cp->cpu_id && cpu[i] != NULL &&
952 953 (cpu[i]->cpu_flags & CPU_EXISTS))
953 954 cpu[i]->cpu_flags |= CPU_QUIESCED;
954 955 }
955 956 }
956 957
957 958 /*
958 959 * Platform callback following each entry to panicsys().
959 960 */
960 961 /*ARGSUSED*/
961 962 void
962 963 panic_enter_hw(int spl)
963 964 {
964 965 /* Nothing to do here */
965 966 }
966 967
967 968 /*
968 969 * Platform-specific code to execute after panicstr is set: we invoke
969 970 * the PSM entry point to indicate that a panic has occurred.
970 971 */
971 972 /*ARGSUSED*/
972 973 void
973 974 panic_quiesce_hw(panic_data_t *pdp)
974 975 {
975 976 psm_notifyf(PSM_PANIC_ENTER);
976 977
977 978 cmi_panic_callback();
978 979
979 980 #ifdef TRAPTRACE
980 981 /*
981 982 * Turn off TRAPTRACE
982 983 */
983 984 TRAPTRACE_FREEZE;
984 985 #endif /* TRAPTRACE */
985 986 }
986 987
987 988 /*
988 989 * Platform callback prior to writing crash dump.
989 990 */
990 991 /*ARGSUSED*/
991 992 void
992 993 panic_dump_hw(int spl)
993 994 {
994 995 /* Nothing to do here */
995 996 }
996 997
997 998 void *
998 999 plat_traceback(void *fpreg)
999 1000 {
1000 1001 #ifdef __xpv
1001 1002 if (IN_XPV_PANIC())
1002 1003 return (xpv_traceback(fpreg));
1003 1004 #endif
1004 1005 return (fpreg);
1005 1006 }
1006 1007
1007 1008 /*ARGSUSED*/
1008 1009 void
1009 1010 plat_tod_fault(enum tod_fault_type tod_bad)
1010 1011 {}
1011 1012
1012 1013 /*ARGSUSED*/
1013 1014 int
1014 1015 blacklist(int cmd, const char *scheme, nvlist_t *fmri, const char *class)
1015 1016 {
1016 1017 return (ENOTSUP);
1017 1018 }
1018 1019
1019 1020 /*
1020 1021 * The underlying console output routines are protected by raising IPL in case
1021 1022 * we are still calling into the early boot services. Once we start calling
1022 1023 * the kernel console emulator, it will disable interrupts completely during
1023 1024 * character rendering (see sysp_putchar, for example). Refer to the comments
1024 1025 * and code in common/os/console.c for more information on these callbacks.
1025 1026 */
1026 1027 /*ARGSUSED*/
1027 1028 int
1028 1029 console_enter(int busy)
1029 1030 {
1030 1031 return (splzs());
1031 1032 }
1032 1033
1033 1034 /*ARGSUSED*/
1034 1035 void
1035 1036 console_exit(int busy, int spl)
1036 1037 {
1037 1038 splx(spl);
1038 1039 }
1039 1040
1040 1041 /*
1041 1042 * Allocate a region of virtual address space, unmapped.
1042 1043 * Stubbed out except on sparc, at least for now.
1043 1044 */
1044 1045 /*ARGSUSED*/
1045 1046 void *
1046 1047 boot_virt_alloc(void *addr, size_t size)
1047 1048 {
1048 1049 return (addr);
1049 1050 }
1050 1051
1051 1052 volatile unsigned long tenmicrodata;
1052 1053
1053 1054 void
1054 1055 tenmicrosec(void)
1055 1056 {
1056 1057 extern int gethrtime_hires;
1057 1058
1058 1059 if (gethrtime_hires) {
1059 1060 hrtime_t start, end;
1060 1061 start = end = gethrtime();
1061 1062 while ((end - start) < (10 * (NANOSEC / MICROSEC))) {
1062 1063 SMT_PAUSE();
1063 1064 end = gethrtime();
1064 1065 }
1065 1066 } else {
1066 1067 #if defined(__xpv)
1067 1068 hrtime_t newtime;
1068 1069
1069 1070 newtime = xpv_gethrtime() + 10000; /* now + 10 us */
1070 1071 while (xpv_gethrtime() < newtime)
1071 1072 SMT_PAUSE();
1072 1073 #else /* __xpv */
1073 1074 int i;
1074 1075
1075 1076 /*
1076 1077 * Artificial loop to induce delay.
1077 1078 */
1078 1079 for (i = 0; i < microdata; i++)
1079 1080 tenmicrodata = microdata;
1080 1081 #endif /* __xpv */
1081 1082 }
1082 1083 }
1083 1084
1084 1085 /*
1085 1086 * get_cpu_mstate() is passed an array of timestamps, NCMSTATES
1086 1087 * long, and it fills in the array with the time spent on cpu in
1087 1088 * each of the mstates, where time is returned in nsec.
1088 1089 *
1089 1090 * No guarantee is made that the returned values in times[] will
1090 1091 * monotonically increase on sequential calls, although this will
1091 1092 * be true in the long run. Any such guarantee must be handled by
1092 1093 * the caller, if needed. This can happen if we fail to account
1093 1094 * for elapsed time due to a generation counter conflict, yet we
1094 1095 * did account for it on a prior call (see below).
1095 1096 *
1096 1097 * The complication is that the cpu in question may be updating
1097 1098 * its microstate at the same time that we are reading it.
1098 1099 * Because the microstate is only updated when the CPU's state
1099 1100 * changes, the values in cpu_intracct[] can be indefinitely out
1100 1101 * of date. To determine true current values, it is necessary to
1101 1102 * compare the current time with cpu_mstate_start, and add the
1102 1103 * difference to times[cpu_mstate].
1103 1104 *
1104 1105 * This can be a problem if those values are changing out from
1105 1106 * under us. Because the code path in new_cpu_mstate() is
1106 1107 * performance critical, we have not added a lock to it. Instead,
1107 1108 * we have added a generation counter. Before beginning
1108 1109 * modifications, the counter is set to 0. After modifications,
1109 1110 * it is set to the old value plus one.
1110 1111 *
1111 1112 * get_cpu_mstate() will not consider the values of cpu_mstate
1112 1113 * and cpu_mstate_start to be usable unless the value of
1113 1114 * cpu_mstate_gen is both non-zero and unchanged, both before and
1114 1115 * after reading the mstate information. Note that we must
1115 1116 * protect against out-of-order loads around accesses to the
1116 1117 * generation counter. Also, this is a best effort approach in
1117 1118 * that we do not retry should the counter be found to have
1118 1119 * changed.
1119 1120 *
1120 1121 * cpu_intracct[] is used to identify time spent in each CPU
1121 1122 * mstate while handling interrupts. Such time should be reported
1122 1123 * against system time, and so is subtracted out from its
1123 1124 * corresponding cpu_acct[] time and added to
1124 1125 * cpu_acct[CMS_SYSTEM].
1125 1126 */
1126 1127
1127 1128 void
1128 1129 get_cpu_mstate(cpu_t *cpu, hrtime_t *times)
1129 1130 {
1130 1131 int i;
1131 1132 hrtime_t now, start;
1132 1133 uint16_t gen;
1133 1134 uint16_t state;
1134 1135 hrtime_t intracct[NCMSTATES];
1135 1136
1136 1137 /*
1137 1138 * Load all volatile state under the protection of membar.
1138 1139 * cpu_acct[cpu_mstate] must be loaded to avoid double counting
1139 1140 * of (now - cpu_mstate_start) by a change in CPU mstate that
1140 1141 * arrives after we make our last check of cpu_mstate_gen.
1141 1142 */
1142 1143
1143 1144 now = gethrtime_unscaled();
1144 1145 gen = cpu->cpu_mstate_gen;
1145 1146
1146 1147 membar_consumer(); /* guarantee load ordering */
1147 1148 start = cpu->cpu_mstate_start;
1148 1149 state = cpu->cpu_mstate;
1149 1150 for (i = 0; i < NCMSTATES; i++) {
1150 1151 intracct[i] = cpu->cpu_intracct[i];
1151 1152 times[i] = cpu->cpu_acct[i];
1152 1153 }
1153 1154 membar_consumer(); /* guarantee load ordering */
1154 1155
1155 1156 if (gen != 0 && gen == cpu->cpu_mstate_gen && now > start)
1156 1157 times[state] += now - start;
1157 1158
1158 1159 for (i = 0; i < NCMSTATES; i++) {
1159 1160 if (i == CMS_SYSTEM)
1160 1161 continue;
1161 1162 times[i] -= intracct[i];
1162 1163 if (times[i] < 0) {
1163 1164 intracct[i] += times[i];
1164 1165 times[i] = 0;
1165 1166 }
1166 1167 times[CMS_SYSTEM] += intracct[i];
1167 1168 scalehrtime(×[i]);
1168 1169 }
1169 1170 scalehrtime(×[CMS_SYSTEM]);
1170 1171 }
1171 1172
1172 1173 /*
1173 1174 * This is a version of the rdmsr instruction that allows
1174 1175 * an error code to be returned in the case of failure.
1175 1176 */
1176 1177 int
1177 1178 checked_rdmsr(uint_t msr, uint64_t *value)
1178 1179 {
1179 1180 if (!is_x86_feature(x86_featureset, X86FSET_MSR))
1180 1181 return (ENOTSUP);
1181 1182 *value = rdmsr(msr);
1182 1183 return (0);
1183 1184 }
1184 1185
1185 1186 /*
1186 1187 * This is a version of the wrmsr instruction that allows
1187 1188 * an error code to be returned in the case of failure.
1188 1189 */
1189 1190 int
1190 1191 checked_wrmsr(uint_t msr, uint64_t value)
1191 1192 {
1192 1193 if (!is_x86_feature(x86_featureset, X86FSET_MSR))
1193 1194 return (ENOTSUP);
1194 1195 wrmsr(msr, value);
1195 1196 return (0);
1196 1197 }
1197 1198
1198 1199 /*
1199 1200 * The mem driver's usual method of using hat_devload() to establish a
1200 1201 * temporary mapping will not work for foreign pages mapped into this
1201 1202 * domain or for the special hypervisor-provided pages. For the foreign
1202 1203 * pages, we often don't know which domain owns them, so we can't ask the
1203 1204 * hypervisor to set up a new mapping. For the other pages, we don't have
1204 1205 * a pfn, so we can't create a new PTE. For these special cases, we do a
1205 1206 * direct uiomove() from the existing kernel virtual address.
1206 1207 */
1207 1208 /*ARGSUSED*/
1208 1209 int
1209 1210 plat_mem_do_mmio(struct uio *uio, enum uio_rw rw)
1210 1211 {
1211 1212 #if defined(__xpv)
1212 1213 void *va = (void *)(uintptr_t)uio->uio_loffset;
1213 1214 off_t pageoff = uio->uio_loffset & PAGEOFFSET;
1214 1215 size_t nbytes = MIN((size_t)(PAGESIZE - pageoff),
1215 1216 (size_t)uio->uio_iov->iov_len);
1216 1217
1217 1218 if ((rw == UIO_READ &&
1218 1219 (va == HYPERVISOR_shared_info || va == xen_info)) ||
1219 1220 (pfn_is_foreign(hat_getpfnum(kas.a_hat, va))))
1220 1221 return (uiomove(va, nbytes, rw, uio));
1221 1222 #endif
1222 1223 return (ENOTSUP);
1223 1224 }
1224 1225
1225 1226 pgcnt_t
1226 1227 num_phys_pages()
1227 1228 {
1228 1229 pgcnt_t npages = 0;
1229 1230 struct memlist *mp;
1230 1231
1231 1232 #if defined(__xpv)
↓ open down ↓ |
1198 lines elided |
↑ open up ↑ |
1232 1233 if (DOMAIN_IS_INITDOMAIN(xen_info))
1233 1234 return (xpv_nr_phys_pages());
1234 1235 #endif /* __xpv */
1235 1236
1236 1237 for (mp = phys_install; mp != NULL; mp = mp->ml_next)
1237 1238 npages += mp->ml_size >> PAGESHIFT;
1238 1239
1239 1240 return (npages);
1240 1241 }
1241 1242
1242 -/* cpu threshold for compressed dumps */
1243 -#ifdef _LP64
1244 -uint_t dump_plat_mincpu_default = DUMP_PLAT_X86_64_MINCPU;
1245 -#else
1246 -uint_t dump_plat_mincpu_default = DUMP_PLAT_X86_32_MINCPU;
1247 -#endif
1248 -
1249 1243 int
1250 1244 dump_plat_addr()
1251 1245 {
1252 1246 #ifdef __xpv
1253 1247 pfn_t pfn = mmu_btop(xen_info->shared_info) | PFN_IS_FOREIGN_MFN;
1254 1248 mem_vtop_t mem_vtop;
1255 1249 int cnt;
1256 1250
1257 1251 /*
1258 1252 * On the hypervisor, we want to dump the page with shared_info on it.
1259 1253 */
1260 1254 if (!IN_XPV_PANIC()) {
1261 1255 mem_vtop.m_as = &kas;
1262 1256 mem_vtop.m_va = HYPERVISOR_shared_info;
1263 1257 mem_vtop.m_pfn = pfn;
1264 1258 dumpvp_write(&mem_vtop, sizeof (mem_vtop_t));
1265 1259 cnt = 1;
1266 1260 } else {
1267 1261 cnt = dump_xpv_addr();
1268 1262 }
1269 1263 return (cnt);
1270 1264 #else
1271 1265 return (0);
1272 1266 #endif
1273 1267 }
1274 1268
1275 1269 void
1276 1270 dump_plat_pfn()
1277 1271 {
1278 1272 #ifdef __xpv
1279 1273 pfn_t pfn = mmu_btop(xen_info->shared_info) | PFN_IS_FOREIGN_MFN;
1280 1274
1281 1275 if (!IN_XPV_PANIC())
1282 1276 dumpvp_write(&pfn, sizeof (pfn));
1283 1277 else
1284 1278 dump_xpv_pfn();
1285 1279 #endif
1286 1280 }
1287 1281
1288 1282 /*ARGSUSED*/
1289 1283 int
1290 1284 dump_plat_data(void *dump_cbuf)
1291 1285 {
1292 1286 #ifdef __xpv
1293 1287 uint32_t csize;
1294 1288 int cnt;
1295 1289
1296 1290 if (!IN_XPV_PANIC()) {
1297 1291 csize = (uint32_t)compress(HYPERVISOR_shared_info, dump_cbuf,
1298 1292 PAGESIZE);
1299 1293 dumpvp_write(&csize, sizeof (uint32_t));
1300 1294 dumpvp_write(dump_cbuf, csize);
1301 1295 cnt = 1;
1302 1296 } else {
1303 1297 cnt = dump_xpv_data(dump_cbuf);
1304 1298 }
1305 1299 return (cnt);
1306 1300 #else
1307 1301 return (0);
1308 1302 #endif
1309 1303 }
1310 1304
1311 1305 /*
1312 1306 * Calculates a linear address, given the CS selector and PC values
1313 1307 * by looking up the %cs selector process's LDT or the CPU's GDT.
1314 1308 * proc->p_ldtlock must be held across this call.
1315 1309 */
1316 1310 int
1317 1311 linear_pc(struct regs *rp, proc_t *p, caddr_t *linearp)
1318 1312 {
1319 1313 user_desc_t *descrp;
1320 1314 caddr_t baseaddr;
1321 1315 uint16_t idx = SELTOIDX(rp->r_cs);
1322 1316
1323 1317 ASSERT(rp->r_cs <= 0xFFFF);
1324 1318 ASSERT(MUTEX_HELD(&p->p_ldtlock));
1325 1319
1326 1320 if (SELISLDT(rp->r_cs)) {
1327 1321 /*
1328 1322 * Currently 64 bit processes cannot have private LDTs.
1329 1323 */
1330 1324 ASSERT(p->p_model != DATAMODEL_LP64);
1331 1325
1332 1326 if (p->p_ldt == NULL)
1333 1327 return (-1);
1334 1328
1335 1329 descrp = &p->p_ldt[idx];
1336 1330 baseaddr = (caddr_t)(uintptr_t)USEGD_GETBASE(descrp);
1337 1331
1338 1332 /*
1339 1333 * Calculate the linear address (wraparound is not only ok,
1340 1334 * it's expected behavior). The cast to uint32_t is because
1341 1335 * LDT selectors are only allowed in 32-bit processes.
1342 1336 */
1343 1337 *linearp = (caddr_t)(uintptr_t)(uint32_t)((uintptr_t)baseaddr +
1344 1338 rp->r_pc);
1345 1339 } else {
1346 1340 #ifdef DEBUG
1347 1341 descrp = &CPU->cpu_gdt[idx];
1348 1342 baseaddr = (caddr_t)(uintptr_t)USEGD_GETBASE(descrp);
1349 1343 /* GDT-based descriptors' base addresses should always be 0 */
1350 1344 ASSERT(baseaddr == 0);
1351 1345 #endif
1352 1346 *linearp = (caddr_t)(uintptr_t)rp->r_pc;
1353 1347 }
1354 1348
1355 1349 return (0);
1356 1350 }
1357 1351
1358 1352 /*
1359 1353 * The implementation of dtrace_linear_pc is similar to the that of
1360 1354 * linear_pc, above, but here we acquire p_ldtlock before accessing
1361 1355 * p_ldt. This implementation is used by the pid provider; we prefix
1362 1356 * it with "dtrace_" to avoid inducing spurious tracing events.
1363 1357 */
1364 1358 int
1365 1359 dtrace_linear_pc(struct regs *rp, proc_t *p, caddr_t *linearp)
1366 1360 {
1367 1361 user_desc_t *descrp;
1368 1362 caddr_t baseaddr;
1369 1363 uint16_t idx = SELTOIDX(rp->r_cs);
1370 1364
1371 1365 ASSERT(rp->r_cs <= 0xFFFF);
1372 1366
1373 1367 if (SELISLDT(rp->r_cs)) {
1374 1368 /*
1375 1369 * Currently 64 bit processes cannot have private LDTs.
1376 1370 */
1377 1371 ASSERT(p->p_model != DATAMODEL_LP64);
1378 1372
1379 1373 mutex_enter(&p->p_ldtlock);
1380 1374 if (p->p_ldt == NULL) {
1381 1375 mutex_exit(&p->p_ldtlock);
1382 1376 return (-1);
1383 1377 }
1384 1378 descrp = &p->p_ldt[idx];
1385 1379 baseaddr = (caddr_t)(uintptr_t)USEGD_GETBASE(descrp);
1386 1380 mutex_exit(&p->p_ldtlock);
1387 1381
1388 1382 /*
1389 1383 * Calculate the linear address (wraparound is not only ok,
1390 1384 * it's expected behavior). The cast to uint32_t is because
1391 1385 * LDT selectors are only allowed in 32-bit processes.
1392 1386 */
1393 1387 *linearp = (caddr_t)(uintptr_t)(uint32_t)((uintptr_t)baseaddr +
1394 1388 rp->r_pc);
1395 1389 } else {
1396 1390 #ifdef DEBUG
1397 1391 descrp = &CPU->cpu_gdt[idx];
1398 1392 baseaddr = (caddr_t)(uintptr_t)USEGD_GETBASE(descrp);
1399 1393 /* GDT-based descriptors' base addresses should always be 0 */
1400 1394 ASSERT(baseaddr == 0);
1401 1395 #endif
1402 1396 *linearp = (caddr_t)(uintptr_t)rp->r_pc;
1403 1397 }
1404 1398
1405 1399 return (0);
1406 1400 }
1407 1401
1408 1402 /*
1409 1403 * We need to post a soft interrupt to reprogram the lbolt cyclic when
1410 1404 * switching from event to cyclic driven lbolt. The following code adds
1411 1405 * and posts the softint for x86.
1412 1406 */
1413 1407 static ddi_softint_hdl_impl_t lbolt_softint_hdl =
1414 1408 {0, NULL, NULL, NULL, 0, NULL, NULL, NULL};
1415 1409
1416 1410 void
1417 1411 lbolt_softint_add(void)
1418 1412 {
1419 1413 (void) add_avsoftintr((void *)&lbolt_softint_hdl, LOCK_LEVEL,
1420 1414 (avfunc)lbolt_ev_to_cyclic, "lbolt_ev_to_cyclic", NULL, NULL);
1421 1415 }
1422 1416
1423 1417 void
1424 1418 lbolt_softint_post(void)
1425 1419 {
1426 1420 (*setsoftint)(CBE_LOCK_PIL, lbolt_softint_hdl.ih_pending);
1427 1421 }
1428 1422
1429 1423 boolean_t
1430 1424 plat_dr_check_capability(uint64_t features)
1431 1425 {
1432 1426 return ((plat_dr_options & features) == features);
1433 1427 }
1434 1428
1435 1429 boolean_t
1436 1430 plat_dr_support_cpu(void)
1437 1431 {
1438 1432 return (plat_dr_options & PLAT_DR_FEATURE_CPU);
1439 1433 }
1440 1434
1441 1435 boolean_t
1442 1436 plat_dr_support_memory(void)
1443 1437 {
1444 1438 return (plat_dr_options & PLAT_DR_FEATURE_MEMORY);
1445 1439 }
1446 1440
1447 1441 void
1448 1442 plat_dr_enable_capability(uint64_t features)
1449 1443 {
1450 1444 atomic_or_64(&plat_dr_options, features);
1451 1445 }
1452 1446
1453 1447 void
1454 1448 plat_dr_disable_capability(uint64_t features)
1455 1449 {
1456 1450 atomic_and_64(&plat_dr_options, ~features);
1457 1451 }
↓ open down ↓ |
199 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX