1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
|
/** @file
* PDM - Pluggable Device Manager, APIC Interface.
*/
/*
* Copyright (C) 2024-2025 Oracle and/or its affiliates.
*
* This file is part of VirtualBox base platform packages, as
* available from https://www.virtualbox.org.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation, in version 3 of the
* License.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see <https://www.gnu.org/licenses>.
*
* The contents of this file may alternatively be used under the terms
* of the Common Development and Distribution License Version 1.0
* (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
* in the VirtualBox distribution, in which case the provisions of the
* CDDL are applicable instead of those of the GPL.
*
* You may elect to license modified versions of this file under the
* terms and conditions of either the GPL or the CDDL or both.
*
* SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
*/
#ifndef VBOX_INCLUDED_vmm_pdmapic_h
#define VBOX_INCLUDED_vmm_pdmapic_h
#ifndef RT_WITHOUT_PRAGMA_ONCE
# pragma once
#endif
#include <VBox/types.h>
#include <VBox/apic.h>
struct PDMDEVREGCB;
/** @defgroup grp_pdm_apic The local APIC PDM API
* @ingroup grp_pdm
* @{
*/
RT_C_DECLS_BEGIN
/**
* APIC mode argument for apicR3SetCpuIdFeatureLevel.
*
* Also used in saved-states, CFGM don't change existing values.
*/
typedef enum PDMAPICMODE
{
/** Invalid 0 entry. */
PDMAPICMODE_INVALID = 0,
/** No APIC. */
PDMAPICMODE_NONE,
/** Standard APIC (X86_CPUID_FEATURE_EDX_APIC). */
PDMAPICMODE_APIC,
/** Intel X2APIC (X86_CPUID_FEATURE_ECX_X2APIC). */
PDMAPICMODE_X2APIC,
/** The usual 32-bit paranoia. */
PDMAPICMODE_32BIT_HACK = 0x7fffffff
} PDMAPICMODE;
/**
* APIC irq argument for pfnSetInterruptFF and pfnClearInterruptFF.
*/
typedef enum PDMAPICIRQ
{
/** Invalid 0 entry. */
PDMAPICIRQ_INVALID = 0,
/** Normal hardware interrupt. */
PDMAPICIRQ_HARDWARE,
/** NMI. */
PDMAPICIRQ_NMI,
/** SMI. */
PDMAPICIRQ_SMI,
/** ExtINT (HW interrupt via PIC). */
PDMAPICIRQ_EXTINT,
/** Interrupt arrived, needs to be updated to the IRR. */
PDMAPICIRQ_UPDATE_PENDING,
/** The usual 32-bit paranoia. */
PDMAPICIRQ_32BIT_HACK = 0x7fffffff
} PDMAPICIRQ;
/**
* The type of PDM APIC backend.
*/
typedef enum PDMAPICBACKENDTYPE
{
/** None/Invalid PDM APIC backend. */
PDMAPICBACKENDTYPE_NONE = 0,
/** VirtualBox backend. */
PDMAPICBACKENDTYPE_VBOX,
/** KVM backend. */
PDMAPICBACKENDTYPE_KVM,
/** Hyper-V backend. */
PDMAPICBACKENDTYPE_HYPERV,
/** Hypervisor.Framework backend. */
PDMAPICBACKENDTYPE_HVF,
/** End of valid PDM APIC backend values. */
PDMAPICBACKENDTYPE_END,
/** The usual 32-bit paranoia. */
PDMAPICBACKENDTYPE_32BIT_HACK = 0x7fffffff
} PDMAPICBACKENDTYPE;
/**
* PDM APIC backend ring-3 API.
*/
typedef struct PDMAPICBACKENDR3
{
/**
* Returns whether the APIC is hardware enabled or not.
*
* @returns true if enabled, false otherwise.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR3CALLBACKMEMBER(bool, pfnIsEnabled, (PCVMCPUCC pVCpu));
/**
* Initializes per-VCPU APIC to the state following an INIT reset
* ("Wait-for-SIPI" state).
*
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR3CALLBACKMEMBER(void, pfnInitIpi, (PVMCPUCC pVCpu));
/**
* Gets the APIC base MSR (no checks are performed wrt APIC hardware or its
* state).
*
* @returns The base MSR value.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR3CALLBACKMEMBER(uint64_t, pfnGetBaseMsrNoCheck, (PCVMCPUCC pVCpu));
/**
* Gets the APIC base MSR.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param pu64Value Where to store the MSR value.
*/
DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnGetBaseMsr, (PVMCPUCC pVCpu, uint64_t *pu64Value));
/**
* Sets the APIC base MSR.
*
* @returns VBox status code - no informational ones, esp. not
* VINF_CPUM_R3_MSR_WRITE. Only the following two:
* @retval VINF_SUCCESS
* @retval VERR_CPUM_RAISE_GP_0
*
* @param pVCpu The cross context virtual CPU structure.
* @param u64BaseMsr The value to set.
*/
DECLR3CALLBACKMEMBER(int, pfnSetBaseMsr, (PVMCPUCC pVCpu, uint64_t u64BaseMsr));
/**
* Reads a 32-bit register at a specified offset.
*
* @returns The value at the specified offset.
* @param pVCpu The cross context virtual CPU structure.
* @param offReg The offset of the register being read.
*/
DECLR3CALLBACKMEMBER(uint32_t, pfnReadRaw32, (PCVMCPUCC pVCpu, uint16_t offReg));
/**
* Reads an APIC MSR.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u32Reg The MSR being read.
* @param pu64Value Where to store the read value.
*/
DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnReadMsr, (PVMCPUCC pVCpu, uint32_t u32Reg, uint64_t *pu64Value));
/**
* Writes an APIC MSR.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u32Reg The MSR being written.
* @param u64Value The value to write.
*/
DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnWriteMsr, (PVMCPUCC pVCpu, uint32_t u32Reg, uint64_t u64Value));
/**
* Gets the APIC TPR (Task Priority Register).
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param pu8Tpr Where to store the TPR.
* @param pfPending Where to store whether there is a pending interrupt
* (optional, can be NULL).
* @param pu8PendingIntr Where to store the highest-priority pending interrupt
* (optional, can be NULL).
*/
DECLR3CALLBACKMEMBER(int, pfnGetTpr, (PCVMCPUCC pVCpu, uint8_t *pu8Tpr, bool *pfPending, uint8_t *pu8PendingIntr));
/**
* Sets the TPR (Task Priority Register).
*
* @retval VINF_SUCCESS
* @retval VERR_CPUM_RAISE_GP_0
* @retval VERR_PDM_NO_APIC_INSTANCE
*
* @param pVCpu The cross context virtual CPU structure.
* @param u8Tpr The TPR value to set.
* @param fForceX2ApicBehaviour Pretend the APIC is in x2APIC mode during this
* write.
*/
DECLR3CALLBACKMEMBER(int, pfnSetTpr, (PVMCPUCC pVCpu, uint8_t u8Tpr, bool fForceX2ApicBehaviour));
/**
* Gets the Interrupt Command Register (ICR), without performing any interface
* checks.
*
* @returns The ICR value.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR3CALLBACKMEMBER(uint64_t, pfnGetIcrNoCheck, (PVMCPUCC pVCpu));
/**
* Sets the Interrupt Command Register (ICR).
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u64Icr The ICR (High and Low combined).
* @param rcRZ The return code if the operation cannot be performed
* in the current context.
*
* @remarks This function is used by both x2APIC interface and the Hyper-V
* interface, see APICHvSetIcr. The Hyper-V spec isn't clear what
* happens when invalid bits are set. For the time being, it will
* \#GP like a regular x2APIC access.
*/
DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnSetIcr, (PVMCPUCC pVCpu, uint64_t uIcr, int rcRZ));
/**
* Gets the APIC timer frequency.
*
* @returns Strict VBox status code.
* @param pVM The cross context VM structure.
* @param pu64Value Where to store the timer frequency.
*/
DECLR3CALLBACKMEMBER(int, pfnGetTimerFreq, (PVMCC pVM, uint64_t *pu64Value));
/**
* Assert/de-assert the local APIC's LINT0/LINT1 interrupt pins.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u8Pin The interrupt pin (0 for LINT0 or 1 for LINT1).
* @param u8Level The level (0 for low or 1 for high).
* @param rcRZ The return code if the operation cannot be performed in
* the current context.
*
* @note All callers totally ignores the status code!
*/
DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnSetLocalInterrupt, (PVMCPUCC pVCpu, uint8_t u8Pin, uint8_t u8Level, int rcRZ));
/**
* Gets the next highest-priority interrupt from the APIC, marking it as an
* "in-service" interrupt.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param pu8Vector Where to store the vector.
* @param puSrcTag Where to store the interrupt source tag (debugging).
*/
DECLR3CALLBACKMEMBER(int, pfnGetInterrupt, (PVMCPUCC pVCpu, uint8_t *pu8Vector, uint32_t *puSrcTag));
/**
* Posts an interrupt to a target APIC.
*
* This function handles interrupts received from the system bus or
* interrupts generated locally from the LVT or via a self IPI.
*
* Don't use this function to try and deliver ExtINT style interrupts.
*
* @returns true if the interrupt was accepted, false otherwise.
* @param pVCpu The cross context virtual CPU structure.
* @param uVector The vector of the interrupt to be posted.
* @param fAutoEoi Whether this interrupt has automatic EOI
* treatment.
* @param enmTriggerMode The trigger mode of the interrupt.
* @param uSrcTag The interrupt source tag (debugging).
*
* @thread Any.
*/
DECLR3CALLBACKMEMBER(bool, pfnPostInterrupt, (PVMCPUCC pVCpu, uint8_t uVector, XAPICTRIGGERMODE enmTriggerMode, bool fAutoEoi,
uint32_t uSrcTag));
/**
* Updating pending interrupts into the IRR if required.
*
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR3CALLBACKMEMBER(void, pfnUpdatePendingInterrupts, (PVMCPUCC pVCpu));
/**
* Delivers an interrupt message via the system bus.
*
* @returns VBox status code.
* @param pVM The cross context VM structure.
* @param uDest The destination mask.
* @param uDestMode The destination mode.
* @param uDeliveryMode The delivery mode.
* @param uVector The interrupt vector.
* @param uPolarity The interrupt line polarity.
* @param uTriggerMode The trigger mode.
* @param uSrcTag The interrupt source tag (debugging).
*/
DECLR3CALLBACKMEMBER(int, pfnBusDeliver, (PVMCC pVM, uint8_t uDest, uint8_t uDestMode, uint8_t uDeliveryMode, uint8_t uVector,
uint8_t uPolarity, uint8_t uTriggerMode, uint32_t uSrcTag));
/**
* Sets the End-Of-Interrupt (EOI) register.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param uEoi The EOI value.
* @param fForceX2ApicBehaviour Pretend the APIC is in x2APIC mode during
* this write.
*/
DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnSetEoi, (PVMCPUCC pVCpu, uint32_t uEoi, bool fForceX2ApicBehaviour));
/**
* Sets whether Hyper-V compatibility mode (MSR interface) is enabled or not.
* @see APICR3SetHvCompatMode for details.
*
* @returns VBox status code.
* @param pVM The cross context VM structure.
* @param fHyperVCompatMode Whether the compatibility mode is enabled.
*/
DECLR3CALLBACKMEMBER(int, pfnSetHvCompatMode, (PVMCC pVM, bool fHyperVCompatMode));
/**
* Imports the APIC state.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnImportState, (PVMCPUCC pVCpu));
/**
* Exports the APIC state.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR3CALLBACKMEMBER(VBOXSTRICTRC, pfnExportState, (PVMCPUCC pVCpu));
/** @name Reserved for future (MBZ).
* @{ */
DECLR3CALLBACKMEMBER(int, pfnReserved0, (void));
DECLR3CALLBACKMEMBER(int, pfnReserved1, (void));
DECLR3CALLBACKMEMBER(int, pfnReserved2, (void));
DECLR3CALLBACKMEMBER(int, pfnReserved3, (void));
DECLR3CALLBACKMEMBER(int, pfnReserved4, (void));
DECLR3CALLBACKMEMBER(int, pfnReserved5, (void));
DECLR3CALLBACKMEMBER(int, pfnReserved6, (void));
DECLR3CALLBACKMEMBER(int, pfnReserved7, (void));
/** @} */
} PDMAPICBACKENDR3;
/** Pointer to ring-3 APIC backend. */
typedef R3PTRTYPE(struct PDMAPICBACKENDR3 *) PPDMAPICBACKENDR3;
/** Const pointer to ring-3 APIC backend. */
typedef R3PTRTYPE(const struct PDMAPICBACKENDR3 *) PCPDMAPICBACKENDR3;
AssertCompileSizeAlignment(PDMAPICBACKENDR3, 8);
/**
* PDM APIC backend ring-0 API.
*/
typedef struct PDMAPICBACKENDR0
{
/**
* Returns whether the APIC is hardware enabled or not.
*
* @returns true if enabled, false otherwise.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR0CALLBACKMEMBER(bool, pfnIsEnabled, (PCVMCPUCC pVCpu));
/**
* Initializes per-VCPU APIC to the state following an INIT reset
* ("Wait-for-SIPI" state).
*
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR0CALLBACKMEMBER(void, pfnInitIpi, (PVMCPUCC pVCpu));
/**
* Gets the APIC base MSR (no checks are performed wrt APIC hardware or its
* state).
*
* @returns The base MSR value.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR0CALLBACKMEMBER(uint64_t, pfnGetBaseMsrNoCheck, (PCVMCPUCC pVCpu));
/**
* Gets the APIC base MSR.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param pu64Value Where to store the MSR value.
*/
DECLR0CALLBACKMEMBER(VBOXSTRICTRC, pfnGetBaseMsr, (PVMCPUCC pVCpu, uint64_t *pu64Value));
/**
* Sets the APIC base MSR.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u64BaseMsr The value to set.
*/
DECLR0CALLBACKMEMBER(int, pfnSetBaseMsr, (PVMCPUCC pVCpu, uint64_t u64BaseMsr));
/**
* Reads a 32-bit register at a specified offset.
*
* @returns The value at the specified offset.
* @param pVCpu The cross context virtual CPU structure.
* @param offReg The offset of the register being read.
*/
DECLR0CALLBACKMEMBER(uint32_t, pfnReadRaw32, (PCVMCPUCC pVCpu, uint16_t offReg));
/**
* Reads an APIC MSR.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u32Reg The MSR being read.
* @param pu64Value Where to store the read value.
*/
DECLR0CALLBACKMEMBER(VBOXSTRICTRC, pfnReadMsr, (PVMCPUCC pVCpu, uint32_t u32Reg, uint64_t *pu64Value));
/**
* Writes an APIC MSR.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u32Reg The MSR being written.
* @param u64Value The value to write.
*/
DECLR0CALLBACKMEMBER(VBOXSTRICTRC, pfnWriteMsr, (PVMCPUCC pVCpu, uint32_t u32Reg, uint64_t u64Value));
/**
* Gets the APIC TPR (Task Priority Register).
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param pu8Tpr Where to store the TPR.
* @param pfPending Where to store whether there is a pending interrupt
* (optional, can be NULL).
* @param pu8PendingIntr Where to store the highest-priority pending interrupt
* (optional, can be NULL).
*/
DECLR0CALLBACKMEMBER(int, pfnGetTpr, (PCVMCPUCC pVCpu, uint8_t *pu8Tpr, bool *pfPending, uint8_t *pu8PendingIntr));
/**
* Sets the TPR (Task Priority Register).
*
* @retval VINF_SUCCESS
* @retval VERR_CPUM_RAISE_GP_0
* @retval VERR_PDM_NO_APIC_INSTANCE
*
* @param pVCpu The cross context virtual CPU structure.
* @param u8Tpr The TPR value to set.
* @param fForceX2ApicBehaviour Pretend the APIC is in x2APIC mode during this
* write.
*/
DECLR0CALLBACKMEMBER(int, pfnSetTpr, (PVMCPUCC pVCpu, uint8_t u8Tpr, bool fForceX2ApicBehaviour));
/**
* Gets the Interrupt Command Register (ICR), without performing any interface
* checks.
*
* @returns The ICR value.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR0CALLBACKMEMBER(uint64_t, pfnGetIcrNoCheck, (PVMCPUCC pVCpu));
/**
* Sets the Interrupt Command Register (ICR).
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u64Icr The ICR (High and Low combined).
* @param rcRZ The return code if the operation cannot be performed
* in the current context.
*
* @remarks This function is used by both x2APIC interface and the Hyper-V
* interface, see APICHvSetIcr. The Hyper-V spec isn't clear what
* happens when invalid bits are set. For the time being, it will
* \#GP like a regular x2APIC access.
*/
DECLR0CALLBACKMEMBER(VBOXSTRICTRC, pfnSetIcr, (PVMCPUCC pVCpu, uint64_t uIcr, int rcRZ));
/**
* Gets the APIC timer frequency.
*
* @returns Strict VBox status code.
* @param pVM The cross context VM structure.
* @param pu64Value Where to store the timer frequency.
*/
DECLR0CALLBACKMEMBER(int, pfnGetTimerFreq, (PVMCC pVM, uint64_t *pu64Value));
/**
* Assert/de-assert the local APIC's LINT0/LINT1 interrupt pins.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u8Pin The interrupt pin (0 for LINT0 or 1 for LINT1).
* @param u8Level The level (0 for low or 1 for high).
* @param rcRZ The return code if the operation cannot be performed in
* the current context.
*
* @note All callers totally ignores the status code!
*/
DECLR0CALLBACKMEMBER(VBOXSTRICTRC, pfnSetLocalInterrupt, (PVMCPUCC pVCpu, uint8_t u8Pin, uint8_t u8Level, int rcRZ));
/**
* Gets the next highest-priority interrupt from the APIC, marking it as an
* "in-service" interrupt.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param pu8Vector Where to store the vector.
* @param puSrcTag Where to store the interrupt source tag (debugging).
*/
DECLR0CALLBACKMEMBER(int, pfnGetInterrupt, (PVMCPUCC pVCpu, uint8_t *pu8Vector, uint32_t *puTagSrc));
/**
* Posts an interrupt to a target APIC.
*
* This function handles interrupts received from the system bus or
* interrupts generated locally from the LVT or via a self IPI.
*
* Don't use this function to try and deliver ExtINT style interrupts.
*
* @returns true if the interrupt was accepted, false otherwise.
* @param pVCpu The cross context virtual CPU structure.
* @param uVector The vector of the interrupt to be posted.
* @param fAutoEoi Whether this interrupt has automatic EOI
* treatment.
* @param enmTriggerMode The trigger mode of the interrupt.
* @param uSrcTag The interrupt source tag (debugging).
*
* @thread Any.
*/
DECLR0CALLBACKMEMBER(bool, pfnPostInterrupt, (PVMCPUCC pVCpu, uint8_t uVector, XAPICTRIGGERMODE enmTriggerMode, bool fAutoEoi,
uint32_t uSrcTag));
/**
* Updating pending interrupts into the IRR if required.
*
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR0CALLBACKMEMBER(void, pfnUpdatePendingInterrupts, (PVMCPUCC pVCpu));
/**
* Delivers an interrupt message via the system bus.
*
* @returns VBox status code.
* @param pVM The cross context VM structure.
* @param uDest The destination mask.
* @param uDestMode The destination mode.
* @param uDeliveryMode The delivery mode.
* @param uVector The interrupt vector.
* @param uPolarity The interrupt line polarity.
* @param uTriggerMode The trigger mode.
* @param uSrcTag The interrupt source tag (debugging).
*/
DECLR0CALLBACKMEMBER(int, pfnBusDeliver, (PVMCC pVM, uint8_t uDest, uint8_t uDestMode, uint8_t uDeliveryMode, uint8_t uVector,
uint8_t uPolarity, uint8_t uTriggerMode, uint32_t uSrcTag));
/**
* Sets the End-Of-Interrupt (EOI) register.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param uEoi The EOI value.
* @param fForceX2ApicBehaviour Pretend the APIC is in x2APIC mode during
* this write.
*/
DECLR0CALLBACKMEMBER(VBOXSTRICTRC, pfnSetEoi, (PVMCPUCC pVCpu, uint32_t uEoi, bool fForceX2ApicBehaviour));
/**
* Gets the APIC page pointers for the specified VCPU.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param pHCPhys Where to store the host-context physical address.
* @param pR0Ptr Where to store the ring-0 address.
* @param pR3Ptr Where to store the ring-3 address (optional).
*/
DECLR0CALLBACKMEMBER(int, pfnGetApicPageForCpu, (PCVMCPUCC pVCpu, PRTHCPHYS pHCPhys, PRTR0PTR pR0Ptr, PRTR3PTR pR3Ptr));
/**
* Imports the APIC state.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR0CALLBACKMEMBER(VBOXSTRICTRC, pfnImportState, (PVMCPUCC pVCpu));
/**
* Exports the APIC state.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLR0CALLBACKMEMBER(VBOXSTRICTRC, pfnExportState, (PVMCPUCC pVCpu));
/** @name Reserved for future (MBZ).
* @{ */
DECLR0CALLBACKMEMBER(int, pfnReserved0, (void));
DECLR0CALLBACKMEMBER(int, pfnReserved1, (void));
DECLR0CALLBACKMEMBER(int, pfnReserved2, (void));
DECLR0CALLBACKMEMBER(int, pfnReserved3, (void));
DECLR0CALLBACKMEMBER(int, pfnReserved4, (void));
DECLR0CALLBACKMEMBER(int, pfnReserved5, (void));
DECLR0CALLBACKMEMBER(int, pfnReserved6, (void));
DECLR0CALLBACKMEMBER(int, pfnReserved7, (void));
/** @} */
} PDMAPICBACKENDR0;
/** Pointer to ring-0 APIC backend. */
typedef R0PTRTYPE(struct PDMAPICBACKENDR0 *) PPDMAPICBACKENDR0;
/** Const pointer to ring-0 APIC backend. */
typedef R0PTRTYPE(const struct PDMAPICBACKENDR0 *) PCPDMAPICBACKENDR0;
AssertCompileSizeAlignment(PDMAPICBACKENDR0, 8);
/**
* PDM APIC backend RC API.
*/
typedef struct PDMAPICBACKENDRC
{
/**
* Returns whether the APIC is hardware enabled or not.
*
* @returns true if enabled, false otherwise.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLRCCALLBACKMEMBER(bool, pfnIsEnabled, (PCVMCPUCC pVCpu));
/**
* Initializes per-VCPU APIC to the state following an INIT reset
* ("Wait-for-SIPI" state).
*
* @param pVCpu The cross context virtual CPU structure.
*/
DECLRCCALLBACKMEMBER(void, pfnInitIpi, (PVMCPUCC pVCpu));
/**
* Gets the APIC base MSR (no checks are performed wrt APIC hardware or its
* state).
*
* @returns The base MSR value.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLRCCALLBACKMEMBER(uint64_t, pfnGetBaseMsrNoCheck, (PCVMCPUCC pVCpu));
/**
* Gets the APIC base MSR.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param pu64Value Where to store the MSR value.
*/
DECLRCCALLBACKMEMBER(VBOXSTRICTRC, pfnGetBaseMsr, (PVMCPUCC pVCpu, uint64_t *pu64Value));
/**
* Sets the APIC base MSR.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u64BaseMsr The value to set.
*/
DECLRCCALLBACKMEMBER(int, pfnSetBaseMsr, (PVMCPUCC pVCpu, uint64_t u64BaseMsr));
/**
* Reads a 32-bit register at a specified offset.
*
* @returns The value at the specified offset.
* @param pVCpu The cross context virtual CPU structure.
* @param offReg The offset of the register being read.
*/
DECLRCCALLBACKMEMBER(uint32_t, pfnReadRaw32, (PCVMCPUCC pVCpu, uint16_t offReg));
/**
* Reads an APIC MSR.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u32Reg The MSR being read.
* @param pu64Value Where to store the read value.
*/
DECLRCCALLBACKMEMBER(VBOXSTRICTRC, pfnReadMsr, (PVMCPUCC pVCpu, uint32_t u32Reg, uint64_t *pu64Value));
/**
* Writes an APIC MSR.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u32Reg The MSR being written.
* @param u64Value The value to write.
*/
DECLRCCALLBACKMEMBER(VBOXSTRICTRC, pfnWriteMsr, (PVMCPUCC pVCpu, uint32_t u32Reg, uint64_t u64Value));
/**
* Gets the APIC TPR (Task Priority Register).
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param pu8Tpr Where to store the TPR.
* @param pfPending Where to store whether there is a pending interrupt
* (optional, can be NULL).
* @param pu8PendingIntr Where to store the highest-priority pending interrupt
* (optional, can be NULL).
*/
DECLRCCALLBACKMEMBER(int, pfnGetTpr, (PCVMCPUCC pVCpu, uint8_t *pu8Tpr, bool *pfPending, uint8_t *pu8PendingIntr));
/**
* Sets the TPR (Task Priority Register).
*
* @retval VINF_SUCCESS
* @retval VERR_CPUM_RAISE_GP_0
* @retval VERR_PDM_NO_APIC_INSTANCE
*
* @param pVCpu The cross context virtual CPU structure.
* @param u8Tpr The TPR value to set.
* @param fForceX2ApicBehaviour Pretend the APIC is in x2APIC mode during this
* write.
*/
DECLRCCALLBACKMEMBER(int, pfnSetTpr, (PVMCPUCC pVCpu, uint8_t u8Tpr, bool fForceX2ApicBehaviour));
/**
* Gets the Interrupt Command Register (ICR), without performing any interface
* checks.
*
* @returns The ICR value.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLRCCALLBACKMEMBER(uint64_t, pfnGetIcrNoCheck, (PVMCPUCC pVCpu));
/**
* Sets the Interrupt Command Register (ICR).
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u64Icr The ICR (High and Low combined).
* @param rcRZ The return code if the operation cannot be performed
* in the current context.
*
* @remarks This function is used by both x2APIC interface and the Hyper-V
* interface, see APICHvSetIcr. The Hyper-V spec isn't clear what
* happens when invalid bits are set. For the time being, it will
* \#GP like a regular x2APIC access.
*/
DECLRCCALLBACKMEMBER(VBOXSTRICTRC, pfnSetIcr, (PVMCPUCC pVCpu, uint64_t uIcr, int rcRZ));
/**
* Gets the APIC timer frequency.
*
* @returns Strict VBox status code.
* @param pVM The cross context VM structure.
* @param pu64Value Where to store the timer frequency.
*/
DECLRCCALLBACKMEMBER(int, pfnGetTimerFreq, (PVMCC pVM, uint64_t *pu64Value));
/**
* Assert/de-assert the local APIC's LINT0/LINT1 interrupt pins.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param u8Pin The interrupt pin (0 for LINT0 or 1 for LINT1).
* @param u8Level The level (0 for low or 1 for high).
* @param rcRZ The return code if the operation cannot be performed in
* the current context.
*
* @note All callers totally ignores the status code!
*/
DECLRCCALLBACKMEMBER(VBOXSTRICTRC, pfnSetLocalInterrupt, (PVMCPUCC pVCpu, uint8_t u8Pin, uint8_t u8Level, int rcRZ));
/**
* Gets the next highest-priority interrupt from the APIC, marking it as an
* "in-service" interrupt.
*
* @returns VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param pu8Vector Where to store the vector.
* @param puSrcTag Where to store the interrupt source tag (debugging).
*/
DECLRCCALLBACKMEMBER(int, pfnGetInterrupt, (PVMCPUCC pVCpu, uint8_t *pu8Vector, uint32_t *puTagSrc));
/**
* Posts an interrupt to a target APIC.
*
* This function handles interrupts received from the system bus or
* interrupts generated locally from the LVT or via a self IPI.
*
* Don't use this function to try and deliver ExtINT style interrupts.
*
* @returns true if the interrupt was accepted, false otherwise.
* @param pVCpu The cross context virtual CPU structure.
* @param uVector The vector of the interrupt to be posted.
* @param fAutoEoi Whether this interrupt has automatic EOI
* treatment.
* @param enmTriggerMode The trigger mode of the interrupt.
* @param uSrcTag The interrupt source tag (debugging).
*
* @thread Any.
*/
DECLRCCALLBACKMEMBER(bool, pfnPostInterrupt, (PVMCPUCC pVCpu, uint8_t uVector, XAPICTRIGGERMODE enmTriggerMode, bool fAutoEoi,
uint32_t uSrcTag));
/**
* Updating pending interrupts into the IRR if required.
*
* @param pVCpu The cross context virtual CPU structure.
*/
DECLRCCALLBACKMEMBER(void, pfnUpdatePendingInterrupts, (PVMCPUCC pVCpu));
/**
* Delivers an interrupt message via the system bus.
*
* @returns VBox status code.
* @param pVM The cross context VM structure.
* @param uDest The destination mask.
* @param uDestMode The destination mode.
* @param uDeliveryMode The delivery mode.
* @param uVector The interrupt vector.
* @param uPolarity The interrupt line polarity.
* @param uTriggerMode The trigger mode.
* @param uSrcTag The interrupt source tag (debugging).
*/
DECLRCCALLBACKMEMBER(int, pfnBusDeliver, (PVMCC pVM, uint8_t uDest, uint8_t uDestMode, uint8_t uDeliveryMode, uint8_t uVector,
uint8_t uPolarity, uint8_t uTriggerMode, uint32_t uSrcTag));
/**
* Sets the End-Of-Interrupt (EOI) register.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
* @param uEoi The EOI value.
* @param fForceX2ApicBehaviour Pretend the APIC is in x2APIC mode during
* this write.
*/
DECLRCCALLBACKMEMBER(VBOXSTRICTRC, pfnSetEoi, (PVMCPUCC pVCpu, uint32_t uEoi, bool fForceX2ApicBehaviour));
/**
* Imports the APIC state.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLRCCALLBACKMEMBER(VBOXSTRICTRC, pfnImportState, (PVMCPUCC pVCpu));
/**
* Exports the APIC state.
*
* @returns Strict VBox status code.
* @param pVCpu The cross context virtual CPU structure.
*/
DECLRCCALLBACKMEMBER(VBOXSTRICTRC, pfnExportState, (PVMCPUCC pVCpu));
/** @name Reserved for future (MBZ).
* @{ */
DECLRCCALLBACKMEMBER(int, pfnReserved0, (void));
DECLRCCALLBACKMEMBER(int, pfnReserved1, (void));
DECLRCCALLBACKMEMBER(int, pfnReserved2, (void));
DECLRCCALLBACKMEMBER(int, pfnReserved3, (void));
DECLRCCALLBACKMEMBER(int, pfnReserved4, (void));
DECLRCCALLBACKMEMBER(int, pfnReserved5, (void));
DECLRCCALLBACKMEMBER(int, pfnReserved6, (void));
DECLRCCALLBACKMEMBER(int, pfnReserved7, (void));
DECLRCCALLBACKMEMBER(int, pfnReserved8, (void));
DECLRCCALLBACKMEMBER(int, pfnReserved9, (void));
DECLRCCALLBACKMEMBER(int, pfnReserved10, (void));
/** @} */
} PDMAPICBACKENDRC;
/** Pointer to raw-mode context APIC backend. */
typedef RCPTRTYPE(struct PDMAPICBACKENDRC *) PPDMAPICBACKENDRC;
/** Const pointer to raw-mode context APIC backend. */
typedef RCPTRTYPE(const struct PDMAPICBACKENDRC *) PCPDMAPICBACKENDRC;
AssertCompileSizeAlignment(PDMAPICBACKENDRC, 8);
AssertCompile(sizeof(PDMAPICBACKENDR3) == sizeof(PDMAPICBACKENDR0));
/** @typedef PDMAPICBACKENDR3
* A current context PDM APIC backend. */
/** @typedef PPDMAPICBACKENDR3
* Pointer to a current context PDM APIC backend. */
/** @typedef PCPDMAPICBACKENDR3
* Pointer to a const current context PDM APIC backend. */
#if defined(IN_RING3) || defined(DOXYGEN_RUNNING)
typedef PDMAPICBACKENDR3 PDMAPICBACKEND;
typedef PPDMAPICBACKENDR3 PPDMAPICBACKEND;
typedef PCPDMAPICBACKENDR3 PCPDMAPICBACKEND;
#elif defined(IN_RING0)
typedef PDMAPICBACKENDR0 PDMAPICBACKEND;
typedef PPDMAPICBACKENDR0 PPDMAPICBACKEND;
typedef PCPDMAPICBACKENDR0 PCPDMAPICBACKEND;
#elif defined(IN_RC)
typedef PDMAPICBACKENDRC PDMAPICBACKEND;
typedef PPDMAPICBACKENDRC PPDMAPICBACKEND;
typedef PCPDMAPICBACKENDRC PCPDMAPICBACKEND;
#else
# error "Not IN_RING3, IN_RING0 or IN_RC"
#endif
VMM_INT_DECL(int) PDMApicRegisterBackend(PVMCC pVM, PDMAPICBACKENDTYPE enmBackendType, PCPDMAPICBACKEND pBackend);
VMM_INT_DECL(void) PDMApicUpdatePendingInterrupts(PVMCPUCC pVCpu);
VMM_INT_DECL(int) PDMApicGetTpr(PCVMCPUCC pVCpu, uint8_t *pu8Tpr, bool *pfPending, uint8_t *pu8PendingIntr);
VMM_INT_DECL(int) PDMApicSetTpr(PVMCPUCC pVCpu, uint8_t u8Tpr);
VMM_INT_DECL(VBOXSTRICTRC) PDMApicSetIcr(PVMCPUCC pVCpu, uint64_t uIcr);
VMM_INT_DECL(VBOXSTRICTRC) PDMApicImportState(PVMCPUCC pVCpu);
VMM_INT_DECL(VBOXSTRICTRC) PDMApicExportState(PVMCPUCC pVCpu);
VMM_INT_DECL(bool) PDMApicIsEnabled(PCVMCPUCC pVCpu);
VMM_INT_DECL(VBOXSTRICTRC) PDMApicReadMsr(PVMCPUCC pVCpu, uint32_t u32Reg, uint64_t *pu64Value);
VMM_INT_DECL(VBOXSTRICTRC) PDMApicWriteMsr(PVMCPUCC pVCpu, uint32_t u32Reg, uint64_t u64Value);
VMM_INT_DECL(int) PDMApicGetTimerFreq(PVMCC pVM, uint64_t *pu64Value);
VMM_INT_DECL(VBOXSTRICTRC) PDMApicSetLocalInterrupt(PVMCPUCC pVCpu, uint8_t u8Pin, uint8_t u8Level, int rcRZ);
VMM_INT_DECL(uint64_t) PDMApicGetBaseMsrNoCheck(PCVMCPUCC pVCpu);
VMM_INT_DECL(VBOXSTRICTRC) PDMApicGetBaseMsr(PVMCPUCC pVCpu, uint64_t *pu64Value);
VMM_INT_DECL(int) PDMApicSetBaseMsr(PVMCPUCC pVCpu, uint64_t u64BaseMsr);
VMM_INT_DECL(int) PDMApicGetInterrupt(PVMCPUCC pVCpu, uint8_t *pu8Vector, uint32_t *puSrcTag);
VMM_INT_DECL(int) PDMApicBusDeliver(PVMCC pVM, uint8_t uDest, uint8_t uDestMode, uint8_t uDeliveryMode, uint8_t uVector,
uint8_t uPolarity, uint8_t uTriggerMode, uint32_t uTagSrc);
#ifdef IN_RING0
VMM_INT_DECL(int) PDMR0ApicGetApicPageForCpu(PCVMCPUCC pVCpu, PRTHCPHYS pHCPhys, PRTR0PTR pR0Ptr, PRTR3PTR pR3Ptr);
#endif
/** @name Hyper-V interface (Ring-3 and all-context API).
* @{ */
#ifdef IN_RING3
VMMR3_INT_DECL(int) PDMR3ApicSetHvCompatMode(PVM pVM, bool fHyperVCompatMode);
#endif
VMM_INT_DECL(void) PDMApicHvSendInterrupt(PVMCPUCC pVCpu, uint8_t uVector, bool fAutoEoi, XAPICTRIGGERMODE enmTriggerMode);
VMM_INT_DECL(VBOXSTRICTRC) PDMApicHvSetTpr(PVMCPUCC pVCpu, uint8_t uTpr);
VMM_INT_DECL(uint8_t) PDMApicHvGetTpr(PVMCPUCC pVCpu);
VMM_INT_DECL(VBOXSTRICTRC) PDMApicHvSetIcr(PVMCPUCC pVCpu, uint64_t uIcr);
VMM_INT_DECL(uint64_t) PDMApicHvGetIcr(PVMCPUCC pVCpu);
VMM_INT_DECL(VBOXSTRICTRC) PDMApicHvSetEoi(PVMCPUCC pVCpu, uint32_t uEoi);
/** @} */
#ifdef IN_RING3
/** @defgroup grp_pdm_apic_r3 The PDM APIC Host Context Ring-3 API
* @{
*/
VMMR3_INT_DECL(void) PDMR3ApicInitIpi(PVMCPU pVCpu);
/** @} */
#endif /* IN_RING3 */
RT_C_DECLS_END
/** @} */
#endif /* !VBOX_INCLUDED_vmm_pdmapic_h */
|