vlapic.c (240772) | vlapic.c (240912) |
---|---|
1/*- 2 * Copyright (c) 2011 NetApp, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 75 unchanged lines hidden (view full) --- 84 85#define PRIO(x) ((x) >> 4) 86 87#define VLAPIC_VERSION (16) 88#define VLAPIC_MAXLVT_ENTRIES (5) 89 90#define x2apic(vlapic) ((vlapic)->msr_apicbase & APICBASE_X2APIC) 91 | 1/*- 2 * Copyright (c) 2011 NetApp, Inc. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 75 unchanged lines hidden (view full) --- 84 85#define PRIO(x) ((x) >> 4) 86 87#define VLAPIC_VERSION (16) 88#define VLAPIC_MAXLVT_ENTRIES (5) 89 90#define x2apic(vlapic) ((vlapic)->msr_apicbase & APICBASE_X2APIC) 91 |
92enum boot_state { 93 BS_INIT, 94 BS_SIPI, 95 BS_RUNNING 96}; 97 |
|
92struct vlapic { 93 struct vm *vm; 94 int vcpuid; 95 96 struct io_region *mmio; 97 struct vdev_ops *ops; 98 struct LAPIC apic; 99 --- 7 unchanged lines hidden (view full) --- 107 * A vector is popped from the stack when the processor does an EOI. 108 * The vector on the top of the stack is used to compute the 109 * Processor Priority in conjunction with the TPR. 110 */ 111 uint8_t isrvec_stk[ISRVEC_STK_SIZE]; 112 int isrvec_stk_top; 113 114 uint64_t msr_apicbase; | 98struct vlapic { 99 struct vm *vm; 100 int vcpuid; 101 102 struct io_region *mmio; 103 struct vdev_ops *ops; 104 struct LAPIC apic; 105 --- 7 unchanged lines hidden (view full) --- 113 * A vector is popped from the stack when the processor does an EOI. 114 * The vector on the top of the stack is used to compute the 115 * Processor Priority in conjunction with the TPR. 116 */ 117 uint8_t isrvec_stk[ISRVEC_STK_SIZE]; 118 int isrvec_stk_top; 119 120 uint64_t msr_apicbase; |
121 enum boot_state boot_state; |
|
115}; 116 117static void 118vlapic_mask_lvts(uint32_t *lvts, int num_lvt) 119{ 120 int i; 121 for (i = 0; i < num_lvt; i++) { 122 *lvts |= APIC_LVT_M; --- 40 unchanged lines hidden (view full) --- 163vlapic_op_reset(void* dev) 164{ 165 struct vlapic *vlapic = (struct vlapic*)dev; 166 struct LAPIC *lapic = &vlapic->apic; 167 168 memset(lapic, 0, sizeof(*lapic)); 169 lapic->apr = vlapic->vcpuid; 170 vlapic_init_ipi(vlapic); | 122}; 123 124static void 125vlapic_mask_lvts(uint32_t *lvts, int num_lvt) 126{ 127 int i; 128 for (i = 0; i < num_lvt; i++) { 129 *lvts |= APIC_LVT_M; --- 40 unchanged lines hidden (view full) --- 170vlapic_op_reset(void* dev) 171{ 172 struct vlapic *vlapic = (struct vlapic*)dev; 173 struct LAPIC *lapic = &vlapic->apic; 174 175 memset(lapic, 0, sizeof(*lapic)); 176 lapic->apr = vlapic->vcpuid; 177 vlapic_init_ipi(vlapic); |
178 179 if (vlapic->vcpuid == 0) 180 vlapic->boot_state = BS_RUNNING; /* BSP */ 181 else 182 vlapic->boot_state = BS_INIT; /* AP */ |
|
171 172 return 0; 173 174} 175 176static int 177vlapic_op_init(void* dev) 178{ --- 234 unchanged lines hidden (view full) --- 413} 414 415static int 416lapic_process_icr(struct vlapic *vlapic, uint64_t icrval) 417{ 418 int i; 419 cpuset_t dmask; 420 uint32_t dest, vec, mode; | 183 184 return 0; 185 186} 187 188static int 189vlapic_op_init(void* dev) 190{ --- 234 unchanged lines hidden (view full) --- 425} 426 427static int 428lapic_process_icr(struct vlapic *vlapic, uint64_t icrval) 429{ 430 int i; 431 cpuset_t dmask; 432 uint32_t dest, vec, mode; |
433 struct vlapic *vlapic2; 434 struct vm_exit *vmexit; |
|
421 422 dest = icrval >> 32; 423 vec = icrval & APIC_VECTOR_MASK; 424 mode = icrval & APIC_DELMODE_MASK; 425 426 if (mode == APIC_DELMODE_FIXED || mode == APIC_DELMODE_NMI) { 427 switch (icrval & APIC_DEST_MASK) { 428 case APIC_DEST_DESTFLD: --- 18 unchanged lines hidden (view full) --- 447 lapic_set_intr(vlapic->vm, i, vec); 448 else 449 vm_inject_nmi(vlapic->vm, i); 450 } 451 452 return (0); /* handled completely in the kernel */ 453 } 454 | 435 436 dest = icrval >> 32; 437 vec = icrval & APIC_VECTOR_MASK; 438 mode = icrval & APIC_DELMODE_MASK; 439 440 if (mode == APIC_DELMODE_FIXED || mode == APIC_DELMODE_NMI) { 441 switch (icrval & APIC_DEST_MASK) { 442 case APIC_DEST_DESTFLD: --- 18 unchanged lines hidden (view full) --- 461 lapic_set_intr(vlapic->vm, i, vec); 462 else 463 vm_inject_nmi(vlapic->vm, i); 464 } 465 466 return (0); /* handled completely in the kernel */ 467 } 468 |
455 /* 456 * XXX this assumes that the startup IPI always succeeds 457 */ 458 if (mode == APIC_DELMODE_STARTUP) 459 vm_activate_cpu(vlapic->vm, dest); | 469 if (mode == APIC_DELMODE_INIT) { 470 if ((icrval & APIC_LEVEL_MASK) == APIC_LEVEL_DEASSERT) 471 return (0); |
460 | 472 |
473 if (vlapic->vcpuid == 0 && dest != 0 && dest < VM_MAXCPU) { 474 vlapic2 = vm_lapic(vlapic->vm, dest); 475 476 /* move from INIT to waiting-for-SIPI state */ 477 if (vlapic2->boot_state == BS_INIT) { 478 vlapic2->boot_state = BS_SIPI; 479 } 480 481 return (0); 482 } 483 } 484 485 if (mode == APIC_DELMODE_STARTUP) { 486 if (vlapic->vcpuid == 0 && dest != 0 && dest < VM_MAXCPU) { 487 vlapic2 = vm_lapic(vlapic->vm, dest); 488 489 /* 490 * Ignore SIPIs in any state other than wait-for-SIPI 491 */ 492 if (vlapic2->boot_state != BS_SIPI) 493 return (0); 494 495 vmexit = vm_exitinfo(vlapic->vm, vlapic->vcpuid); 496 vmexit->exitcode = VM_EXITCODE_SPINUP_AP; 497 vmexit->u.spinup_ap.vcpu = dest; 498 vmexit->u.spinup_ap.rip = vec << PAGE_SHIFT; 499 500 /* 501 * XXX this assumes that the startup IPI always succeeds 502 */ 503 vlapic2->boot_state = BS_RUNNING; 504 vm_activate_cpu(vlapic2->vm, dest); 505 506 return (0); 507 } 508 } 509 |
|
461 /* 462 * This will cause a return to userland. 463 */ 464 return (1); 465} 466 467int 468vlapic_pending_intr(struct vlapic *vlapic) --- 344 unchanged lines hidden --- | 510 /* 511 * This will cause a return to userland. 512 */ 513 return (1); 514} 515 516int 517vlapic_pending_intr(struct vlapic *vlapic) --- 344 unchanged lines hidden --- |