VirtualBox

Changeset 82122 in vbox


Ignore:
Timestamp:
Nov 23, 2019 12:04:34 AM (5 years ago)
Author:
vboxsync
Message:

DevParallel: Split structure. Set new_style flag. bugref:9218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Parallel/DevParallel.cpp

    r82121 r82122  
    9292/**
    9393 * The shared parallel device state.
    94  *
    95  * @implements  PDMIBASE
    96  * @implements  PDMIHOSTPARALLELPORT
    9794 */
    9895typedef struct PARALLELPORT
    9996{
    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;
    11697    /** Flag whether an EPP timeout occurred (error handling). */
    11798    bool                fEppTimeout;
     
    153134typedef PARALLELPORT *PPARALLELPORT;
    154135
    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 */
     143typedef 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. */
     159typedef PARALLELPORTR3 *PPARALLELPORTR3;
     160
     161
     162#ifndef VBOX_DEVICE_STRUCT_TESTCASE /* Rest of file, does not count wrt indentation. */
    161163
    162164#ifdef IN_RING3
    163 static void parallelR3IrqSet(PARALLELPORT *pThis)
     165
     166static void parallelR3IrqSet(PPDMDEVINS pDevIns, PARALLELPORT *pThis)
    164167{
    165168    if (pThis->regControl & LPT_CONTROL_ENABLE_IRQ_VIA_ACK)
    166169    {
    167170        LogFlowFunc(("%d 1\n", pThis->iIrq));
    168         PDMDevHlpISASetIrqNoWait(pThis->CTX_SUFF(pDevIns), pThis->iIrq, 1);
    169     }
    170 }
    171 
    172 static void parallelR3IrqClear(PARALLELPORT *pThis)
     171        PDMDevHlpISASetIrqNoWait(pDevIns, pThis->iIrq, 1);
     172    }
     173}
     174
     175static void parallelR3IrqClear(PPDMDEVINS pDevIns, PARALLELPORT *pThis)
    173176{
    174177    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 */
    178182
    179183#if 0
     
    296300static DECLCALLBACK(int) parallelR3NotifyInterrupt(PPDMIHOSTPARALLELPORT pInterface)
    297301{
    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);
    303309
    304310    return VINF_SUCCESS;
     
    313319parallelIoPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
    314320{
    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;
    317326    RT_NOREF_PV(pvUser);
    318327
     
    332341#else
    333342                pThis->regData = u8;
    334                 if (RT_LIKELY(pThis->pDrvHostParallelConnector))
     343                if (RT_LIKELY(pThisCC->pDrvHostParallelConnector))
    335344                {
    336345                    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);
    338347                    AssertRC(rc);
    339348                }
     
    350359                    return VINF_IOM_R3_IOPORT_WRITE;
    351360#else
    352                     if (RT_LIKELY(pThis->pDrvHostParallelConnector))
     361                    if (RT_LIKELY(pThisCC->pDrvHostParallelConnector))
    353362                    {
    354363                        /* Set data direction. */
    355364                        if (u8 & LPT_CONTROL_ENABLE_BIDIRECT)
    356                             rc = pThis->pDrvHostParallelConnector->pfnSetPortDirection(pThis->pDrvHostParallelConnector, false /* fForward */);
     365                            rc = pThisCC->pDrvHostParallelConnector->pfnSetPortDirection(pThisCC->pDrvHostParallelConnector, false /* fForward */);
    357366                        else
    358                             rc = pThis->pDrvHostParallelConnector->pfnSetPortDirection(pThis->pDrvHostParallelConnector, true /* fForward */);
     367                            rc = pThisCC->pDrvHostParallelConnector->pfnSetPortDirection(pThisCC->pDrvHostParallelConnector, true /* fForward */);
    359368                        AssertRC(rc);
    360369
    361370                        u8 &= ~LPT_CONTROL_ENABLE_BIDIRECT; /* Clear bit. */
    362371
    363                         rc = pThis->pDrvHostParallelConnector->pfnWriteControl(pThis->pDrvHostParallelConnector, u8);
     372                        rc = pThisCC->pDrvHostParallelConnector->pfnWriteControl(pThisCC->pDrvHostParallelConnector, u8);
    364373                        AssertRC(rc);
    365374                    }
     
    377386#else
    378387                pThis->regEppAddr = u8;
    379                 if (RT_LIKELY(pThis->pDrvHostParallelConnector))
     388                if (RT_LIKELY(pThisCC->pDrvHostParallelConnector))
    380389                {
    381390                    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);
    383392                    AssertRC(rc);
    384393                }
     
    391400#else
    392401                pThis->regEppData = u8;
    393                 if (RT_LIKELY(pThis->pDrvHostParallelConnector))
     402                if (RT_LIKELY(pThisCC->pDrvHostParallelConnector))
    394403                {
    395404                    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);
    397406                    AssertRC(rc);
    398407                }
     
    421430parallelIoPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
    422431{
    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;
    425437    RT_NOREF_PV(pvUser);
    426438
     
    438450                    rc = VINF_IOM_R3_IOPORT_READ;
    439451#else
    440                     if (RT_LIKELY(pThis->pDrvHostParallelConnector))
     452                    if (RT_LIKELY(pThisCC->pDrvHostParallelConnector))
    441453                    {
    442                         rc = pThis->pDrvHostParallelConnector->pfnRead(pThis->pDrvHostParallelConnector, &pThis->regData,
     454                        rc = pThisCC->pDrvHostParallelConnector->pfnRead(pThisCC->pDrvHostParallelConnector, &pThis->regData,
    443455                                                                       1, PDM_PARALLEL_PORT_MODE_SPP);
    444456                        Log(("Read data lines 0x%X\n", pThis->regData));
     
    453465                rc = VINF_IOM_R3_IOPORT_READ;
    454466#else
    455                 if (RT_LIKELY(pThis->pDrvHostParallelConnector))
     467                if (RT_LIKELY(pThisCC->pDrvHostParallelConnector))
    456468                {
    457                     rc = pThis->pDrvHostParallelConnector->pfnReadStatus(pThis->pDrvHostParallelConnector, &pThis->regStatus);
     469                    rc = pThisCC->pDrvHostParallelConnector->pfnReadStatus(pThisCC->pDrvHostParallelConnector, &pThis->regStatus);
    458470                    AssertRC(VBOXSTRICTRC_VAL(rc));
    459471                }
    460472                *pu32 = pThis->regStatus;
    461                 parallelR3IrqClear(pThis);
     473                parallelR3IrqClear(pDevIns, pThis);
    462474#endif
    463475                break;
     
    466478                rc = VINF_IOM_R3_IOPORT_READ;
    467479#else
    468                 if (RT_LIKELY(pThis->pDrvHostParallelConnector))
     480                if (RT_LIKELY(pThisCC->pDrvHostParallelConnector))
    469481                {
    470                     rc = pThis->pDrvHostParallelConnector->pfnReadControl(pThis->pDrvHostParallelConnector, &pThis->regControl);
     482                    rc = pThisCC->pDrvHostParallelConnector->pfnReadControl(pThisCC->pDrvHostParallelConnector, &pThis->regControl);
    471483                    AssertRC(VBOXSTRICTRC_VAL(rc));
    472484                    pThis->regControl |= LPT_CONTROL_BIT6 | LPT_CONTROL_BIT7;
     
    480492                rc = VINF_IOM_R3_IOPORT_READ;
    481493#else
    482                 if (RT_LIKELY(pThis->pDrvHostParallelConnector))
     494                if (RT_LIKELY(pThisCC->pDrvHostParallelConnector))
    483495                {
    484                     rc = pThis->pDrvHostParallelConnector->pfnRead(pThis->pDrvHostParallelConnector, &pThis->regEppAddr,
     496                    rc = pThisCC->pDrvHostParallelConnector->pfnRead(pThisCC->pDrvHostParallelConnector, &pThis->regEppAddr,
    485497                                                                   1, PDM_PARALLEL_PORT_MODE_EPP_ADDR);
    486498                    Log(("Read EPP address 0x%X\n", pThis->regEppAddr));
     
    494506                rc = VINF_IOM_R3_IOPORT_READ;
    495507#else
    496                 if (RT_LIKELY(pThis->pDrvHostParallelConnector))
     508                if (RT_LIKELY(pThisCC->pDrvHostParallelConnector))
    497509                {
    498                     rc = pThis->pDrvHostParallelConnector->pfnRead(pThis->pDrvHostParallelConnector, &pThis->regEppData,
     510                    rc = pThisCC->pDrvHostParallelConnector->pfnRead(pThisCC->pDrvHostParallelConnector, &pThis->regEppData,
    499511                                                                   1, PDM_PARALLEL_PORT_MODE_EPP_DATA);
    500512                    Log(("Read EPP data 0x%X\n", pThis->regEppData));
     
    628640        return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("IOBase changed: config=%#x state=%#x"), pThis->IOBase, uIoBase);
    629641
    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);
    634642    return VINF_SUCCESS;
    635643}
     
    641649static DECLCALLBACK(void *) parallelR3QueryInterface(PPDMIBASE pInterface, const char *pszIID)
    642650{
    643     PARALLELPORT *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);
    646654    return NULL;
    647655}
     
    649657
    650658/**
    651  * @copydoc FNPDMDEVRELOCATE
    652  */
    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 /**
    661659 * @interface_method_impl{PDMDEVREG,pfnConstruct}
    662660 */
     
    664662{
    665663    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;
    668667    int             rc;
    669668
     
    673672     * Init the data.
    674673     */
    675     pThis->pDevInsR3 = pDevIns;
    676     pThis->pDevInsR0 = PDMDEVINS_2_R0PTR(pDevIns);
    677     pThis->pDevInsRC = PDMDEVINS_2_RCPTR(pDevIns);
     674    pThisCC->pDevIns = pDevIns;
    678675
    679676    /* IBase */
    680     pThis->IBase.pfnQueryInterface = parallelR3QueryInterface;
     677    pThisCC->IBase.pfnQueryInterface = parallelR3QueryInterface;
    681678
    682679    /* IHostParallelPort */
    683     pThis->IHostParallelPort.pfnNotifyInterrupt = parallelR3NotifyInterrupt;
     680    pThisCC->IHostParallelPort.pfnNotifyInterrupt = parallelR3NotifyInterrupt;
    684681
    685682    /* Init parallel state */
     
    729726     * For now no run-time changes are supported.
    730727     */
    731     rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->IBase, &pThis->pDrvBase, "Parallel Host");
     728    rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThisCC->IBase, &pThisCC->pDrvBase, "Parallel Host");
    732729    if (RT_SUCCESS(rc))
    733730    {
    734         pThis->pDrvHostParallelConnector = PDMIBASE_QUERY_INTERFACE(pThis->pDrvBase, PDMIHOSTPARALLELCONNECTOR);
     731        pThisCC->pDrvHostParallelConnector = PDMIBASE_QUERY_INTERFACE(pThisCC->pDrvBase, PDMIHOSTPARALLELCONNECTOR);
    735732
    736733        /* 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);
    738735        /* 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,
    742739                        ("Configuration error: instance %d has no host parallel interface!\n", iInstance),
    743740                        VERR_PDM_MISSING_INTERFACE);
     
    745742    else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
    746743    {
    747         pThis->pDrvBase = NULL;
    748         pThis->pDrvHostParallelConnector = NULL;
     744        pThisCC->pDrvBase = NULL;
     745        pThisCC->pDrvHostParallelConnector = NULL;
    749746        LogRel(("Parallel%d: no unit\n", iInstance));
    750747    }
    751748    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));
    757752
    758753    return VINF_SUCCESS;
     
    790785    /* .uReserved0 = */             0,
    791786    /* .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,
    793788    /* .fClass = */                 PDM_DEVREG_CLASS_PARALLEL,
    794789    /* .cMaxInstances = */          2,
    795790    /* .uSharedVersion = */         42,
    796791    /* .cbInstanceShared = */       sizeof(PARALLELPORT),
    797     /* .cbInstanceCC = */           0,
     792    /* .cbInstanceCC = */           CTX_EXPR(sizeof(PARALLELPORTR3), 0, 0),
    798793    /* .cbInstanceRC = */           0,
    799794    /* .cMaxPciDevices = */         0,
     
    805800    /* .pfnConstruct = */           parallelR3Construct,
    806801    /* .pfnDestruct = */            NULL,
    807     /* .pfnRelocate = */            parallelR3Relocate,
     802    /* .pfnRelocate = */            NULL,
    808803    /* .pfnMemSetup = */            NULL,
    809804    /* .pfnPowerOn = */             NULL,
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette