Changeset 82122 in vbox
- Timestamp:
- Nov 23, 2019 12:04:34 AM (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/Parallel/DevParallel.cpp
r82121 r82122 92 92 /** 93 93 * The shared parallel device state. 94 *95 * @implements PDMIBASE96 * @implements PDMIHOSTPARALLELPORT97 94 */ 98 95 typedef struct PARALLELPORT 99 96 { 100 /** Pointer to the device instance - R3 Ptr */101 PPDMDEVINSR3 pDevInsR3;102 /** Pointer to the device instance - R0 Ptr */103 PPDMDEVINSR0 pDevInsR0;104 /** Pointer to the device instance - RC Ptr */105 PPDMDEVINSRC pDevInsRC;106 /** Alignment. */107 RTRCPTR RCPtrAlignment0;108 /** LUN\#0: The base interface. */109 PDMIBASE IBase;110 /** LUN\#0: The host device port interface. */111 PDMIHOSTPARALLELPORT IHostParallelPort;112 /** Pointer to the attached base driver. */113 R3PTRTYPE(PPDMIBASE) pDrvBase;114 /** Pointer to the attached host device. */115 R3PTRTYPE(PPDMIHOSTPARALLELCONNECTOR) pDrvHostParallelConnector;116 97 /** Flag whether an EPP timeout occurred (error handling). */ 117 98 bool fEppTimeout; … … 153 134 typedef PARALLELPORT *PPARALLELPORT; 154 135 155 #ifndef VBOX_DEVICE_STRUCT_TESTCASE 156 157 #define PDMIHOSTPARALLELPORT_2_PARALLELPORT(pInstance) ( (PARALLELPORT *)((uintptr_t)(pInterface) - RT_UOFFSETOF(PARALLELPORT, IHostParallelPort)) ) 158 #define PDMIHOSTDEVICEPORT_2_PARALLELPORT(pInstance) ( (PARALLELPORT *)((uintptr_t)(pInterface) - RT_UOFFSETOF(PARALLELPORT, IHostDevicePort)) ) 159 #define PDMIBASE_2_PARALLELPORT(pInstance) ( (PARALLELPORT *)((uintptr_t)(pInterface) - RT_UOFFSETOF(PARALLELPORT, IBase)) ) 160 136 137 /** 138 * The parallel device state for ring-3. 139 * 140 * @implements PDMIBASE 141 * @implements PDMIHOSTPARALLELPORT 142 */ 143 typedef struct PARALLELPORTR3 144 { 145 /** Pointer to the device instance. 146 * @note Only for getting our bearings when arriving here via an interface 147 * method. */ 148 PPDMDEVINSR3 pDevIns; 149 /** LUN\#0: The base interface. */ 150 PDMIBASE IBase; 151 /** LUN\#0: The host device port interface. */ 152 PDMIHOSTPARALLELPORT IHostParallelPort; 153 /** Pointer to the attached base driver. */ 154 R3PTRTYPE(PPDMIBASE) pDrvBase; 155 /** Pointer to the attached host device. */ 156 R3PTRTYPE(PPDMIHOSTPARALLELCONNECTOR) pDrvHostParallelConnector; 157 } PARALLELPORTR3; 158 /** Pointer to the parallel device state for ring-3. */ 159 typedef PARALLELPORTR3 *PPARALLELPORTR3; 160 161 162 #ifndef VBOX_DEVICE_STRUCT_TESTCASE /* Rest of file, does not count wrt indentation. */ 161 163 162 164 #ifdef IN_RING3 163 static void parallelR3IrqSet(PARALLELPORT *pThis) 165 166 static void parallelR3IrqSet(PPDMDEVINS pDevIns, PARALLELPORT *pThis) 164 167 { 165 168 if (pThis->regControl & LPT_CONTROL_ENABLE_IRQ_VIA_ACK) 166 169 { 167 170 LogFlowFunc(("%d 1\n", pThis->iIrq)); 168 PDMDevHlpISASetIrqNoWait(p This->CTX_SUFF(pDevIns), pThis->iIrq, 1);169 } 170 } 171 172 static void parallelR3IrqClear(P ARALLELPORT *pThis)171 PDMDevHlpISASetIrqNoWait(pDevIns, pThis->iIrq, 1); 172 } 173 } 174 175 static void parallelR3IrqClear(PPDMDEVINS pDevIns, PARALLELPORT *pThis) 173 176 { 174 177 LogFlowFunc(("%d 0\n", pThis->iIrq)); 175 PDMDevHlpISASetIrqNoWait(pThis->CTX_SUFF(pDevIns), pThis->iIrq, 0); 176 } 177 #endif 178 PDMDevHlpISASetIrqNoWait(pDevIns, pThis->iIrq, 0); 179 } 180 181 #endif /* IN_RING3 */ 178 182 179 183 #if 0 … … 296 300 static DECLCALLBACK(int) parallelR3NotifyInterrupt(PPDMIHOSTPARALLELPORT pInterface) 297 301 { 298 PARALLELPORT *pThis = PDMIHOSTPARALLELPORT_2_PARALLELPORT(pInterface); 299 300 PDMCritSectEnter(pThis->pDevInsR3->pCritSectRoR3, VINF_SUCCESS); 301 parallelR3IrqSet(pThis); 302 PDMCritSectLeave(pThis->pDevInsR3->pCritSectRoR3); 302 PPARALLELPORTR3 pThisCC = RT_FROM_MEMBER(pInterface, PARALLELPORTR3, IHostParallelPort); 303 PPDMDEVINS pDevIns = pThisCC->pDevIns; 304 PPARALLELPORT pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT); 305 306 PDMCritSectEnter(pDevIns->pCritSectRoR3, VINF_SUCCESS); 307 parallelR3IrqSet(pDevIns, pThis); 308 PDMCritSectLeave(pDevIns->pCritSectRoR3); 303 309 304 310 return VINF_SUCCESS; … … 313 319 parallelIoPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb) 314 320 { 315 PARALLELPORT *pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT); 316 VBOXSTRICTRC rc = VINF_SUCCESS; 321 PPARALLELPORT pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT); 322 #ifdef IN_RING3 323 PPARALLELPORTR3 pThisCC = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORTR3); 324 #endif 325 VBOXSTRICTRC rc = VINF_SUCCESS; 317 326 RT_NOREF_PV(pvUser); 318 327 … … 332 341 #else 333 342 pThis->regData = u8; 334 if (RT_LIKELY(pThis ->pDrvHostParallelConnector))343 if (RT_LIKELY(pThisCC->pDrvHostParallelConnector)) 335 344 { 336 345 LogFlowFunc(("Set data lines 0x%X\n", u8)); 337 rc = pThis ->pDrvHostParallelConnector->pfnWrite(pThis->pDrvHostParallelConnector, &u8, 1, PDM_PARALLEL_PORT_MODE_SPP);346 rc = pThisCC->pDrvHostParallelConnector->pfnWrite(pThisCC->pDrvHostParallelConnector, &u8, 1, PDM_PARALLEL_PORT_MODE_SPP); 338 347 AssertRC(rc); 339 348 } … … 350 359 return VINF_IOM_R3_IOPORT_WRITE; 351 360 #else 352 if (RT_LIKELY(pThis ->pDrvHostParallelConnector))361 if (RT_LIKELY(pThisCC->pDrvHostParallelConnector)) 353 362 { 354 363 /* Set data direction. */ 355 364 if (u8 & LPT_CONTROL_ENABLE_BIDIRECT) 356 rc = pThis ->pDrvHostParallelConnector->pfnSetPortDirection(pThis->pDrvHostParallelConnector, false /* fForward */);365 rc = pThisCC->pDrvHostParallelConnector->pfnSetPortDirection(pThisCC->pDrvHostParallelConnector, false /* fForward */); 357 366 else 358 rc = pThis ->pDrvHostParallelConnector->pfnSetPortDirection(pThis->pDrvHostParallelConnector, true /* fForward */);367 rc = pThisCC->pDrvHostParallelConnector->pfnSetPortDirection(pThisCC->pDrvHostParallelConnector, true /* fForward */); 359 368 AssertRC(rc); 360 369 361 370 u8 &= ~LPT_CONTROL_ENABLE_BIDIRECT; /* Clear bit. */ 362 371 363 rc = pThis ->pDrvHostParallelConnector->pfnWriteControl(pThis->pDrvHostParallelConnector, u8);372 rc = pThisCC->pDrvHostParallelConnector->pfnWriteControl(pThisCC->pDrvHostParallelConnector, u8); 364 373 AssertRC(rc); 365 374 } … … 377 386 #else 378 387 pThis->regEppAddr = u8; 379 if (RT_LIKELY(pThis ->pDrvHostParallelConnector))388 if (RT_LIKELY(pThisCC->pDrvHostParallelConnector)) 380 389 { 381 390 LogFlowFunc(("Write EPP address 0x%X\n", u8)); 382 rc = pThis ->pDrvHostParallelConnector->pfnWrite(pThis->pDrvHostParallelConnector, &u8, 1, PDM_PARALLEL_PORT_MODE_EPP_ADDR);391 rc = pThisCC->pDrvHostParallelConnector->pfnWrite(pThisCC->pDrvHostParallelConnector, &u8, 1, PDM_PARALLEL_PORT_MODE_EPP_ADDR); 383 392 AssertRC(rc); 384 393 } … … 391 400 #else 392 401 pThis->regEppData = u8; 393 if (RT_LIKELY(pThis ->pDrvHostParallelConnector))402 if (RT_LIKELY(pThisCC->pDrvHostParallelConnector)) 394 403 { 395 404 LogFlowFunc(("Write EPP data 0x%X\n", u8)); 396 rc = pThis ->pDrvHostParallelConnector->pfnWrite(pThis->pDrvHostParallelConnector, &u8, 1, PDM_PARALLEL_PORT_MODE_EPP_DATA);405 rc = pThisCC->pDrvHostParallelConnector->pfnWrite(pThisCC->pDrvHostParallelConnector, &u8, 1, PDM_PARALLEL_PORT_MODE_EPP_DATA); 397 406 AssertRC(rc); 398 407 } … … 421 430 parallelIoPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb) 422 431 { 423 PPARALLELPORT pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT); 424 VBOXSTRICTRC rc = VINF_SUCCESS; 432 PPARALLELPORT pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT); 433 #ifdef IN_RING3 434 PPARALLELPORTR3 pThisCC = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORTR3); 435 #endif 436 VBOXSTRICTRC rc = VINF_SUCCESS; 425 437 RT_NOREF_PV(pvUser); 426 438 … … 438 450 rc = VINF_IOM_R3_IOPORT_READ; 439 451 #else 440 if (RT_LIKELY(pThis ->pDrvHostParallelConnector))452 if (RT_LIKELY(pThisCC->pDrvHostParallelConnector)) 441 453 { 442 rc = pThis ->pDrvHostParallelConnector->pfnRead(pThis->pDrvHostParallelConnector, &pThis->regData,454 rc = pThisCC->pDrvHostParallelConnector->pfnRead(pThisCC->pDrvHostParallelConnector, &pThis->regData, 443 455 1, PDM_PARALLEL_PORT_MODE_SPP); 444 456 Log(("Read data lines 0x%X\n", pThis->regData)); … … 453 465 rc = VINF_IOM_R3_IOPORT_READ; 454 466 #else 455 if (RT_LIKELY(pThis ->pDrvHostParallelConnector))467 if (RT_LIKELY(pThisCC->pDrvHostParallelConnector)) 456 468 { 457 rc = pThis ->pDrvHostParallelConnector->pfnReadStatus(pThis->pDrvHostParallelConnector, &pThis->regStatus);469 rc = pThisCC->pDrvHostParallelConnector->pfnReadStatus(pThisCC->pDrvHostParallelConnector, &pThis->regStatus); 458 470 AssertRC(VBOXSTRICTRC_VAL(rc)); 459 471 } 460 472 *pu32 = pThis->regStatus; 461 parallelR3IrqClear(p This);473 parallelR3IrqClear(pDevIns, pThis); 462 474 #endif 463 475 break; … … 466 478 rc = VINF_IOM_R3_IOPORT_READ; 467 479 #else 468 if (RT_LIKELY(pThis ->pDrvHostParallelConnector))480 if (RT_LIKELY(pThisCC->pDrvHostParallelConnector)) 469 481 { 470 rc = pThis ->pDrvHostParallelConnector->pfnReadControl(pThis->pDrvHostParallelConnector, &pThis->regControl);482 rc = pThisCC->pDrvHostParallelConnector->pfnReadControl(pThisCC->pDrvHostParallelConnector, &pThis->regControl); 471 483 AssertRC(VBOXSTRICTRC_VAL(rc)); 472 484 pThis->regControl |= LPT_CONTROL_BIT6 | LPT_CONTROL_BIT7; … … 480 492 rc = VINF_IOM_R3_IOPORT_READ; 481 493 #else 482 if (RT_LIKELY(pThis ->pDrvHostParallelConnector))494 if (RT_LIKELY(pThisCC->pDrvHostParallelConnector)) 483 495 { 484 rc = pThis ->pDrvHostParallelConnector->pfnRead(pThis->pDrvHostParallelConnector, &pThis->regEppAddr,496 rc = pThisCC->pDrvHostParallelConnector->pfnRead(pThisCC->pDrvHostParallelConnector, &pThis->regEppAddr, 485 497 1, PDM_PARALLEL_PORT_MODE_EPP_ADDR); 486 498 Log(("Read EPP address 0x%X\n", pThis->regEppAddr)); … … 494 506 rc = VINF_IOM_R3_IOPORT_READ; 495 507 #else 496 if (RT_LIKELY(pThis ->pDrvHostParallelConnector))508 if (RT_LIKELY(pThisCC->pDrvHostParallelConnector)) 497 509 { 498 rc = pThis ->pDrvHostParallelConnector->pfnRead(pThis->pDrvHostParallelConnector, &pThis->regEppData,510 rc = pThisCC->pDrvHostParallelConnector->pfnRead(pThisCC->pDrvHostParallelConnector, &pThis->regEppData, 499 511 1, PDM_PARALLEL_PORT_MODE_EPP_DATA); 500 512 Log(("Read EPP data 0x%X\n", pThis->regEppData)); … … 628 640 return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("IOBase changed: config=%#x state=%#x"), pThis->IOBase, uIoBase); 629 641 630 /* not necessary... but it doesn't harm. */631 pThis->pDevInsR3 = pDevIns;632 pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);633 pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);634 642 return VINF_SUCCESS; 635 643 } … … 641 649 static DECLCALLBACK(void *) parallelR3QueryInterface(PPDMIBASE pInterface, const char *pszIID) 642 650 { 643 P ARALLELPORT *pThis = PDMIBASE_2_PARALLELPORT(pInterface);644 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis ->IBase);645 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTPARALLELPORT, &pThis ->IHostParallelPort);651 PPARALLELPORTR3 pThisCC = RT_FROM_MEMBER(pInterface, PARALLELPORTR3, IBase); 652 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThisCC->IBase); 653 PDMIBASE_RETURN_INTERFACE(pszIID, PDMIHOSTPARALLELPORT, &pThisCC->IHostParallelPort); 646 654 return NULL; 647 655 } … … 649 657 650 658 /** 651 * @copydoc FNPDMDEVRELOCATE652 */653 static DECLCALLBACK(void) parallelR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)654 {655 PPARALLELPORT pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT);656 pThis->pDevInsRC += offDelta;657 }658 659 660 /**661 659 * @interface_method_impl{PDMDEVREG,pfnConstruct} 662 660 */ … … 664 662 { 665 663 PDMDEV_CHECK_VERSIONS_RETURN(pDevIns); 666 PPARALLELPORT pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT); 667 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3; 664 PPARALLELPORT pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT); 665 PPARALLELPORTR3 pThisCC = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORTR3); 666 PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3; 668 667 int rc; 669 668 … … 673 672 * Init the data. 674 673 */ 675 pThis->pDevInsR3 = pDevIns; 676 pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns); 677 pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns); 674 pThisCC->pDevIns = pDevIns; 678 675 679 676 /* IBase */ 680 pThis ->IBase.pfnQueryInterface = parallelR3QueryInterface;677 pThisCC->IBase.pfnQueryInterface = parallelR3QueryInterface; 681 678 682 679 /* IHostParallelPort */ 683 pThis ->IHostParallelPort.pfnNotifyInterrupt = parallelR3NotifyInterrupt;680 pThisCC->IHostParallelPort.pfnNotifyInterrupt = parallelR3NotifyInterrupt; 684 681 685 682 /* Init parallel state */ … … 729 726 * For now no run-time changes are supported. 730 727 */ 731 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis ->IBase, &pThis->pDrvBase, "Parallel Host");728 rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThisCC->IBase, &pThisCC->pDrvBase, "Parallel Host"); 732 729 if (RT_SUCCESS(rc)) 733 730 { 734 pThis ->pDrvHostParallelConnector = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIHOSTPARALLELCONNECTOR);731 pThisCC->pDrvHostParallelConnector = PDMIBASE_QUERY_INTERFACE(pThisCC->pDrvBase, PDMIHOSTPARALLELCONNECTOR); 735 732 736 733 /* Set compatibility mode */ 737 //pThis ->pDrvHostParallelConnector->pfnSetMode(pThis->pDrvHostParallelConnector, PDM_PARALLEL_PORT_MODE_COMPAT);734 //pThisCC->pDrvHostParallelConnector->pfnSetMode(pThisCC->pDrvHostParallelConnector, PDM_PARALLEL_PORT_MODE_COMPAT); 738 735 /* Get status of control register */ 739 pThis ->pDrvHostParallelConnector->pfnReadControl(pThis->pDrvHostParallelConnector, &pThis->regControl);740 741 AssertMsgReturn(pThis ->pDrvHostParallelConnector,736 pThisCC->pDrvHostParallelConnector->pfnReadControl(pThisCC->pDrvHostParallelConnector, &pThis->regControl); 737 738 AssertMsgReturn(pThisCC->pDrvHostParallelConnector, 742 739 ("Configuration error: instance %d has no host parallel interface!\n", iInstance), 743 740 VERR_PDM_MISSING_INTERFACE); … … 745 742 else if (rc == VERR_PDM_NO_ATTACHED_DRIVER) 746 743 { 747 pThis ->pDrvBase = NULL;748 pThis ->pDrvHostParallelConnector = NULL;744 pThisCC->pDrvBase = NULL; 745 pThisCC->pDrvHostParallelConnector = NULL; 749 746 LogRel(("Parallel%d: no unit\n", iInstance)); 750 747 } 751 748 else 752 { 753 AssertMsgFailed(("Parallel%d: Failed to attach to host driver. rc=%Rrc\n", iInstance, rc)); 754 return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS, 755 N_("Parallel device %d cannot attach to host driver"), iInstance); 756 } 749 AssertMsgFailedReturn(("Parallel%d: Failed to attach to host driver. rc=%Rrc\n", iInstance, rc), 750 PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS, 751 N_("Parallel device %d cannot attach to host driver"), iInstance)); 757 752 758 753 return VINF_SUCCESS; … … 790 785 /* .uReserved0 = */ 0, 791 786 /* .szName = */ "parallel", 792 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ ,787 /* .fFlags = */ PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ | PDM_DEVREG_FLAGS_NEW_STYLE, 793 788 /* .fClass = */ PDM_DEVREG_CLASS_PARALLEL, 794 789 /* .cMaxInstances = */ 2, 795 790 /* .uSharedVersion = */ 42, 796 791 /* .cbInstanceShared = */ sizeof(PARALLELPORT), 797 /* .cbInstanceCC = */ 0,792 /* .cbInstanceCC = */ CTX_EXPR(sizeof(PARALLELPORTR3), 0, 0), 798 793 /* .cbInstanceRC = */ 0, 799 794 /* .cMaxPciDevices = */ 0, … … 805 800 /* .pfnConstruct = */ parallelR3Construct, 806 801 /* .pfnDestruct = */ NULL, 807 /* .pfnRelocate = */ parallelR3Relocate,802 /* .pfnRelocate = */ NULL, 808 803 /* .pfnMemSetup = */ NULL, 809 804 /* .pfnPowerOn = */ NULL,
Note:
See TracChangeset
for help on using the changeset viewer.