- Timestamp:
- Nov 17, 2019 8:29:52 PM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/PC/DevPIC.cpp
r81913 r81914 62 62 /** @def PIC_UNLOCK 63 63 * Releases the PDM lock. This is a NOP if locking is disabled. */ 64 #define PIC_LOCK(a_pDevIns, a_pThis , rc) \64 #define PIC_LOCK(a_pDevIns, a_pThisCC, rc) \ 65 65 do { \ 66 int rc2 = (a_pThis )->CTX_SUFF(pPicHlp)->pfnLock((a_pDevIns), rc); \66 int rc2 = (a_pThisCC)->pPicHlp->pfnLock((a_pDevIns), rc); \ 67 67 if (rc2 != VINF_SUCCESS) \ 68 68 return rc2; \ 69 69 } while (0) 70 #define PIC_UNLOCK(a_pDevIns, a_pThis ) \71 (a_pThis )->CTX_SUFF(pPicHlp)->pfnUnlock((a_pDevIns))70 #define PIC_UNLOCK(a_pDevIns, a_pThisCC) \ 71 (a_pThisCC)->pPicHlp->pfnUnlock((a_pDevIns)) 72 72 73 73 … … 112 112 113 113 /** 114 * The wholePIC device instance data.114 * The shared PIC device instance data. 115 115 */ 116 116 typedef struct DEVPIC … … 118 118 /** The two interrupt controllers. */ 119 119 PICSTATE aPics[2]; 120 /** Pointer to the PIC R3 helpers. */121 R3PTRTYPE(PCPDMPICHLP) pPicHlpR3;122 /** Pointer to the PIC R0 helpers. */123 R0PTRTYPE(PCPDMPICHLP) pPicHlpR0;124 /** Pointer to the PIC RC helpers. */125 RCPTRTYPE(PCPDMPICHLP) pPicHlpRC;126 120 /** Number of release log entries. Used to prevent flooding. */ 127 121 uint32_t cRelLogEntries; 122 uint32_t u32Padding; 128 123 #ifdef VBOX_WITH_STATISTICS 129 124 STAMCOUNTER StatSetIrqRZ; … … 134 129 #endif 135 130 } DEVPIC; 136 /** Pointer to the wholePIC instance data. */131 /** Pointer to the shared PIC instance data. */ 137 132 typedef DEVPIC *PDEVPIC; 133 134 135 /** 136 * The PIC device instance data for ring-3. 137 */ 138 typedef struct DEVPICR3 139 { 140 /** Pointer to the PIC ring-3 helpers. */ 141 R3PTRTYPE(PCPDMPICHLP) pPicHlp; 142 } DEVPICR3; 143 /** Pointer to the ring-3 PIC instance data. */ 144 typedef DEVPICR3 *PDEVPICR3; 145 146 147 /** 148 * The PIC device instance data for ring-0. 149 */ 150 typedef struct DEVPICR0 151 { 152 /** Pointer to the PIC ring-0 helpers. */ 153 R0PTRTYPE(PCPDMPICHLP) pPicHlp; 154 } DEVPICR0; 155 /** Pointer to the ring-0 PIC instance data. */ 156 typedef DEVPICR0 *PDEVPICR0; 157 158 159 /** 160 * The PIC device instance data for raw-mode. 161 */ 162 typedef struct DEVPICRC 163 { 164 /** Pointer to the PIC raw-mode helpers. */ 165 RCPTRTYPE(PCPDMPICHLP) pPicHlp; 166 } DEVPICRC; 167 /** Pointer to the raw-mode PIC instance data. */ 168 typedef DEVPICRC *PDEVPICRC; 169 170 171 /** The PIC instance data for the current context. */ 172 typedef CTX_SUFF(DEVPIC) DEVPICCC; 173 /** Pointer to the PIC instance data for the current context. */ 174 typedef CTX_SUFF(PDEVPIC) PDEVPICCC; 175 138 176 139 177 … … 248 286 /* raise irq to CPU if necessary. must be called every time the active 249 287 irq may change */ 250 static int pic_update_irq(PPDMDEVINS pDevIns, PDEVPIC pThis )288 static int pic_update_irq(PPDMDEVINS pDevIns, PDEVPIC pThis, PDEVPICCC pThisCC) 251 289 { 252 290 int irq2, irq; … … 277 315 Log(("pic%d: imr=%x irr=%x padd=%d\n", i, pThis->aPics[i].imr, pThis->aPics[i].irr, pThis->aPics[i].priority_add)); 278 316 Log(("pic: cpu_interrupt\n")); 279 pThis ->CTX_SUFF(pPicHlp)->pfnSetInterruptFF(pDevIns);317 pThisCC->pPicHlp->pfnSetInterruptFF(pDevIns); 280 318 } 281 319 else … … 286 324 287 325 /* if this was the only pending irq, then we must clear the interrupt ff flag */ 288 pThis ->CTX_SUFF(pPicHlp)->pfnClearInterruptFF(pDevIns);326 pThisCC->pPicHlp->pfnClearInterruptFF(pDevIns); 289 327 290 328 /** @todo Is this correct? */ … … 292 330 293 331 /* Call ourselves again just in case other interrupts are pending */ 294 return pic_update_irq(pDevIns, pThis );332 return pic_update_irq(pDevIns, pThis, pThisCC); 295 333 } 296 334 } … … 300 338 301 339 /* we must clear the interrupt ff flag */ 302 pThis ->CTX_SUFF(pPicHlp)->pfnClearInterruptFF(pDevIns);340 pThisCC->pPicHlp->pfnClearInterruptFF(pDevIns); 303 341 } 304 342 return VINF_SUCCESS; … … 309 347 * 310 348 * @param pDevIns Device instance of the PICs. 349 * @param pDevIns 311 350 * @param iIrq IRQ number to set. 312 351 * @param iLevel IRQ level. 313 352 * @param uTagSrc The IRQ tag and source ID (for tracing). 314 353 */ 315 PDMBOTHCBDECL(void) picSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc) 316 { 317 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 354 static DECLCALLBACK(void) picSetIrq(PPDMDEVINS pDevIns, int iIrq, int iLevel, uint32_t uTagSrc) 355 { 356 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 357 PDEVPICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVPICCC); 318 358 AssertMsgReturnVoid(iIrq < 16, ("iIrq=%d\n", iIrq)); 319 359 … … 329 369 */ 330 370 pic_set_irq1(&RT_SAFE_SUBSCRIPT(pThis->aPics, iIrq >> 3), iIrq & 7, 0, uTagSrc); 331 pic_update_irq(pDevIns, pThis );371 pic_update_irq(pDevIns, pThis, pThisCC); 332 372 } 333 373 pic_set_irq1(&RT_SAFE_SUBSCRIPT(pThis->aPics, iIrq >> 3), iIrq & 7, iLevel & PDM_IRQ_LEVEL_HIGH, uTagSrc); 334 pic_update_irq(pDevIns, pThis );374 pic_update_irq(pDevIns, pThis, pThisCC); 335 375 } 336 376 … … 363 403 * @param puTagSrc Where to return the IRQ tag and source ID. 364 404 */ 365 PDMBOTHCBDECL(int) picGetInterrupt(PPDMDEVINS pDevIns, uint32_t *puTagSrc) 366 { 367 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 405 static DECLCALLBACK(int) picGetInterrupt(PPDMDEVINS pDevIns, uint32_t *puTagSrc) 406 { 407 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 408 PDEVPICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVPICCC); 368 409 int irq; 369 410 int irq2; … … 411 452 *puTagSrc = 0; 412 453 } 413 pic_update_irq(pDevIns, pThis );454 pic_update_irq(pDevIns, pThis, pThisCC); 414 455 415 456 Log(("picGetInterrupt: 0x%02x pending 0:%d 1:%d\n", intno, pic_get_irq(&pThis->aPics[0]), pic_get_irq(&pThis->aPics[1]))); … … 440 481 441 482 442 static VBOXSTRICTRC pic_ioport_write(PPDMDEVINS pDevIns, PDEVPIC pThis, PPICSTATE pPic, uint32_t addr, uint32_t val) 483 static VBOXSTRICTRC pic_ioport_write(PPDMDEVINS pDevIns, PDEVPIC pThis, PDEVPICCC pThisCC, PPICSTATE pPic, 484 uint32_t addr, uint32_t val) 443 485 { 444 486 VBOXSTRICTRC rc = VINF_SUCCESS; … … 454 496 pic_reset(pPic); 455 497 /* deassert a pending interrupt */ 456 pThis ->CTX_SUFF(pPicHlp)->pfnClearInterruptFF(pDevIns);498 pThisCC->pPicHlp->pfnClearInterruptFF(pDevIns); 457 499 458 500 pPic->init_state = 1; … … 492 534 if (cmd == 5) 493 535 pPic->priority_add = (irq + 1) & 7; 494 rc = pic_update_irq(pDevIns, pThis );536 rc = pic_update_irq(pDevIns, pThis, pThisCC); 495 537 Assert(rc == VINF_SUCCESS); 496 538 DumpPICState(pPic, "eoi"); … … 503 545 Log(("pic_write: EOI2 for irq %d\n", irq)); 504 546 pPic->isr &= ~(1 << irq); 505 rc = pic_update_irq(pDevIns, pThis );547 rc = pic_update_irq(pDevIns, pThis, pThisCC); 506 548 Assert(rc == VINF_SUCCESS); 507 549 DumpPICState(pPic, "eoi2"); … … 512 554 pPic->priority_add = (val + 1) & 7; 513 555 Log(("pic_write: lowest priority %d (highest %d)\n", val & 7, pPic->priority_add)); 514 rc = pic_update_irq(pDevIns, pThis );556 rc = pic_update_irq(pDevIns, pThis, pThisCC); 515 557 Assert(rc == VINF_SUCCESS); 516 558 break; … … 522 564 pPic->isr &= ~(1 << irq); 523 565 pPic->priority_add = (irq + 1) & 7; 524 rc = pic_update_irq(pDevIns, pThis );566 rc = pic_update_irq(pDevIns, pThis, pThisCC); 525 567 Assert(rc == VINF_SUCCESS); 526 568 DumpPICState(pPic, "eoi3"); … … 540 582 /* normal mode */ 541 583 pPic->imr = val; 542 rc = pic_update_irq(pDevIns, pThis );584 rc = pic_update_irq(pDevIns, pThis, pThisCC); 543 585 Assert(rc == VINF_SUCCESS); 544 586 break; … … 566 608 567 609 568 static uint32_t pic_poll_read(PPDMDEVINS pDevIns, PDEVPIC pThis, P PICSTATE pPic, uint32_t addr1)610 static uint32_t pic_poll_read(PPDMDEVINS pDevIns, PDEVPIC pThis, PDEVPICCC pThisCC, PPICSTATE pPic, uint32_t addr1) 569 611 { 570 612 int ret = pic_get_irq(pPic); … … 581 623 pPic->isr &= ~(1 << ret); 582 624 if (addr1 >> 7 || ret != 2) 583 pic_update_irq(pDevIns, pThis );625 pic_update_irq(pDevIns, pThis, pThisCC); 584 626 } 585 627 else 586 628 { 587 629 ret = 0; 588 pic_update_irq(pDevIns, pThis );630 pic_update_irq(pDevIns, pThis, pThisCC); 589 631 } 590 632 … … 593 635 594 636 595 static uint32_t pic_ioport_read(PPDMDEVINS pDevIns, PDEVPIC pThis, P PICSTATE pPic, uint32_t addr1, int *pRC)637 static uint32_t pic_ioport_read(PPDMDEVINS pDevIns, PDEVPIC pThis, PDEVPICCC pThisCC, PPICSTATE pPic, uint32_t addr1, int *pRC) 596 638 { 597 639 unsigned int addr; … … 604 646 if (pPic->poll) 605 647 { 606 ret = pic_poll_read(pDevIns, pThis, p Pic, addr1);648 ret = pic_poll_read(pDevIns, pThis, pThisCC, pPic, addr1); 607 649 pPic->poll = 0; 608 650 } … … 632 674 static DECLCALLBACK(VBOXSTRICTRC) picIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb) 633 675 { 634 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 635 uint32_t iPic = (uint32_t)(uintptr_t)pvUser; 676 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 677 PDEVPICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVPICCC); 678 uint32_t iPic = (uint32_t)(uintptr_t)pvUser; 636 679 637 680 Assert(iPic == 0 || iPic == 1); … … 639 682 { 640 683 int rc; 641 PIC_LOCK(pDevIns, pThis , VINF_IOM_R3_IOPORT_READ);642 *pu32 = pic_ioport_read(pDevIns, pThis, &RT_SAFE_SUBSCRIPT(pThis->aPics, iPic), offPort, &rc);643 PIC_UNLOCK(pDevIns, pThis );684 PIC_LOCK(pDevIns, pThisCC, VINF_IOM_R3_IOPORT_READ); 685 *pu32 = pic_ioport_read(pDevIns, pThis, pThisCC, &RT_SAFE_SUBSCRIPT(pThis->aPics, iPic), offPort, &rc); 686 PIC_UNLOCK(pDevIns, pThisCC); 644 687 return rc; 645 688 } … … 653 696 static DECLCALLBACK(VBOXSTRICTRC) picIOPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb) 654 697 { 655 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 656 uint32_t iPic = (uint32_t)(uintptr_t)pvUser; 698 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 699 PDEVPICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVPICCC); 700 uint32_t iPic = (uint32_t)(uintptr_t)pvUser; 657 701 658 702 Assert(iPic == 0 || iPic == 1); … … 661 705 { 662 706 VBOXSTRICTRC rc; 663 PIC_LOCK(pDevIns, pThis , VINF_IOM_R3_IOPORT_WRITE);664 rc = pic_ioport_write(pDevIns, pThis, &RT_SAFE_SUBSCRIPT(pThis->aPics, iPic), offPort, u32);665 PIC_UNLOCK(pDevIns, pThis );707 PIC_LOCK(pDevIns, pThisCC, VINF_IOM_R3_IOPORT_WRITE); 708 rc = pic_ioport_write(pDevIns, pThis, pThisCC, &RT_SAFE_SUBSCRIPT(pThis->aPics, iPic), offPort, u32); 709 PIC_UNLOCK(pDevIns, pThisCC); 666 710 return rc; 667 711 } … … 677 721 if (cb == 1) 678 722 { 679 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC);680 PPICSTATE pPic= (PPICSTATE)pvUser;681 PIC_LOCK(pDevIns, pThis , VINF_IOM_R3_IOPORT_READ);723 PDEVPICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVPICCC); 724 PPICSTATE pPic = (PPICSTATE)pvUser; 725 PIC_LOCK(pDevIns, pThisCC, VINF_IOM_R3_IOPORT_READ); 682 726 *pu32 = pPic->elcr; 683 PIC_UNLOCK(pDevIns, pThis );727 PIC_UNLOCK(pDevIns, pThisCC); 684 728 return VINF_SUCCESS; 685 729 } … … 696 740 if (cb == 1) 697 741 { 698 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC);699 PPICSTATE pPic= (PPICSTATE)pvUser;700 PIC_LOCK(pDevIns, pThis , VINF_IOM_R3_IOPORT_WRITE);742 PDEVPICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVPICCC); 743 PPICSTATE pPic = (PPICSTATE)pvUser; 744 PIC_LOCK(pDevIns, pThisCC, VINF_IOM_R3_IOPORT_WRITE); 701 745 pPic->elcr = u32 & pPic->elcr_mask; 702 PIC_UNLOCK(pDevIns, pThis );746 PIC_UNLOCK(pDevIns, pThisCC); 703 747 } 704 748 RT_NOREF(offPort); … … 814 858 static DECLCALLBACK(void) picR3Reset(PPDMDEVINS pDevIns) 815 859 { 816 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 860 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 861 PDEVPICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVPICCC); 817 862 unsigned i; 818 863 LogFlow(("picR3Reset:\n")); 819 pThis ->pPicHlpR3->pfnLock(pDevIns, VERR_INTERNAL_ERROR);864 pThisCC->pPicHlp->pfnLock(pDevIns, VERR_INTERNAL_ERROR); 820 865 821 866 for (i = 0; i < RT_ELEMENTS(pThis->aPics); i++) 822 867 pic_reset(&pThis->aPics[i]); 823 868 824 PIC_UNLOCK(pDevIns, pThis );869 PIC_UNLOCK(pDevIns, pThisCC); 825 870 } 826 871 … … 831 876 static DECLCALLBACK(void) picR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta) 832 877 { 833 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC);834 pThis ->pPicHlpRC+= offDelta;878 PDEVPICRC pThisRC = PDMINS_2_DATA_RC(pDevIns, PDEVPICRC); 879 pThisRC->pPicHlp += offDelta; 835 880 } 836 881 … … 842 887 { 843 888 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 844 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 889 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 890 PDEVPICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVPICCC); 845 891 int rc; 846 892 RT_NOREF(iInstance, pCfg); … … 872 918 PicReg.pfnGetInterrupt = picGetInterrupt; 873 919 PicReg.u32TheEnd = PDM_PICREG_VERSION; 874 rc = PDMDevHlpPICRegister(pDevIns, &PicReg, &pThis ->pPicHlpR3);920 rc = PDMDevHlpPICRegister(pDevIns, &PicReg, &pThisCC->pPicHlp); 875 921 AssertLogRelMsgRCReturn(rc, ("PDMDevHlpPICRegister -> %Rrc\n", rc), rc); 922 AssertReturn(pThisCC->pPicHlp->u32Version == PDM_PICHLP_VERSION, VERR_VERSION_MISMATCH); 923 AssertReturn(pThisCC->pPicHlp->u32TheEnd == PDM_PICHLP_VERSION, VERR_VERSION_MISMATCH); 876 924 877 925 /* … … 939 987 { 940 988 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 941 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 989 PDEVPIC pThis = PDMDEVINS_2_DATA(pDevIns, PDEVPIC); 990 PDEVPICCC pThisCC = PDMDEVINS_2_DATA_CC(pDevIns, PDEVPICCC); 942 991 943 992 /* NOP the critsect: */ … … 951 1000 PicReg.pfnGetInterrupt = picGetInterrupt; 952 1001 PicReg.u32TheEnd = PDM_PICREG_VERSION; 953 rc = PDMDevHlpPICSetUpContext(pDevIns, &PicReg, &pThis ->CTX_SUFF(pPicHlp));1002 rc = PDMDevHlpPICSetUpContext(pDevIns, &PicReg, &pThisCC->pPicHlp); 954 1003 AssertLogRelMsgRCReturn(rc, ("PDMDevHlpPICSetUpContext -> %Rrc\n", rc), rc); 1004 AssertPtrReturn(pThisCC->pPicHlp, VERR_INTERNAL_ERROR_3); 1005 AssertReturn(pThisCC->pPicHlp->u32Version == PDM_PICHLP_VERSION, VERR_VERSION_MISMATCH); 1006 AssertReturn(pThisCC->pPicHlp->u32TheEnd == PDM_PICHLP_VERSION, VERR_VERSION_MISMATCH); 955 1007 956 1008 /* I/O port callbacks: */ 957 1009 Assert(RT_ELEMENTS(pThis->aPics) == 2); 958 1010 rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->aPics[0].hIoPorts0, picIOPortWrite, picIOPortRead, (void *)0); 959 AssertRCReturn(rc, VERR_INTERNAL_ERROR_2);960 1011 AssertRCReturn(rc, rc); 961 1012 rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->aPics[1].hIoPorts0, picIOPortWrite, picIOPortRead, (void *)1); 962 AssertRCReturn(rc, VERR_INTERNAL_ERROR_3);963 1013 AssertRCReturn(rc, rc); 964 1014 965 1015 rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->aPics[0].hIoPorts1, picIOPortElcrWrite, picIOPortElcrRead, &pThis->aPics[0]); 966 AssertRCReturn(rc, VERR_INTERNAL_ERROR_4);967 1016 AssertRCReturn(rc, rc); 968 1017 rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->aPics[1].hIoPorts1, picIOPortElcrWrite, picIOPortElcrRead, &pThis->aPics[1]); 969 AssertRCReturn(rc, VERR_INTERNAL_ERROR_5);970 1018 AssertRCReturn(rc, rc); 971 1019 … … 983 1031 /* .uReserved0 = */ 0, 984 1032 /* .szName = */ "i8259", 985 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ ,1033 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ | PDM_DEVREG_FLAGS_NEW_STYLE, 986 1034 /* .fClass = */ PDM_DEVREG_CLASS_PIC, 987 1035 /* .cMaxInstances = */ 1, 988 1036 /* .uSharedVersion = */ 42, 989 1037 /* .cbInstanceShared = */ sizeof(DEVPIC), 990 /* .cbInstanceCC = */ 0,991 /* .cbInstanceRC = */ 0,1038 /* .cbInstanceCC = */ sizeof(DEVPICCC), 1039 /* .cbInstanceRC = */ sizeof(DEVPICRC), 992 1040 /* .cMaxPciDevices = */ 0, 993 1041 /* .cMaxMsixVectors = */ 0,
Note:
See TracChangeset
for help on using the changeset viewer.