VirtualBox

Changeset 82120 in vbox for trunk/src


Ignore:
Timestamp:
Nov 22, 2019 11:42:56 PM (5 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
134930
Message:

DevParallel: CFGM & SSM via devhlp. bugref:9218

File:
1 edited

Legend:

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

    r81591 r82120  
    9090*********************************************************************************************************************************/
    9191/**
    92  * Parallel device state.
     92 * The shared parallel device state.
    9393 *
    9494 * @implements  PDMIBASE
     
    9898{
    9999    /** Pointer to the device instance - R3 Ptr */
    100     PPDMDEVINSR3                          pDevInsR3;
     100    PPDMDEVINSR3                            pDevInsR3;
    101101    /** Pointer to the device instance - R0 Ptr */
    102     PPDMDEVINSR0                          pDevInsR0;
     102    PPDMDEVINSR0                            pDevInsR0;
    103103    /** Pointer to the device instance - RC Ptr */
    104     PPDMDEVINSRC                          pDevInsRC;
     104    PPDMDEVINSRC                            pDevInsRC;
    105105    /** Alignment. */
    106     RTRCPTR                               Alignment0;
     106    RTRCPTR                                 RCPtrAlignment0;
    107107    /** LUN\#0: The base interface. */
    108     PDMIBASE                              IBase;
     108    PDMIBASE                                IBase;
    109109    /** LUN\#0: The host device port interface. */
    110     PDMIHOSTPARALLELPORT                  IHostParallelPort;
     110    PDMIHOSTPARALLELPORT                    IHostParallelPort;
    111111    /** Pointer to the attached base driver. */
    112     R3PTRTYPE(PPDMIBASE)                  pDrvBase;
     112    R3PTRTYPE(PPDMIBASE)                    pDrvBase;
    113113    /** Pointer to the attached host device. */
    114     R3PTRTYPE(PPDMIHOSTPARALLELCONNECTOR) pDrvHostParallelConnector;
    115     /** Flag whether the device has its RC component enabled. */
    116     bool                                  fGCEnabled;
    117     /** Flag whether the device has its R0 component enabled. */
    118     bool                                  fR0Enabled;
     114    R3PTRTYPE(PPDMIHOSTPARALLELCONNECTOR)   pDrvHostParallelConnector;
    119115    /** Flag whether an EPP timeout occurred (error handling). */
    120     bool                                  fEppTimeout;
     116    bool                fEppTimeout;
     117    bool                fAlignment1;
    121118    /** Base I/O port of the parallel port. */
    122     RTIOPORT                              IOBase;
     119    RTIOPORT            IOBase;
    123120    /** IRQ number assigned ot the parallel port. */
    124     int                                   iIrq;
     121    int32_t             iIrq;
    125122    /** Data register. */
    126     uint8_t                               regData;
     123    uint8_t             regData;
    127124    /** Status register. */
    128     uint8_t                               regStatus;
     125    uint8_t             regStatus;
    129126    /** Control register. */
    130     uint8_t                               regControl;
     127    uint8_t             regControl;
    131128    /** EPP address register. */
    132     uint8_t                               regEppAddr;
     129    uint8_t             regEppAddr;
    133130    /** EPP data register. */
    134     uint8_t                               regEppData;
     131    uint8_t             regEppData;
    135132    /** More alignment. */
    136     uint32_t                              u32Alignment;
     133    uint8_t             abAlignment2[3];
    137134
    138135#if 0 /* Data for ECP implementation, currently unused. */
    139     uint8_t                               reg_ecp_ecr;
    140     uint8_t                               reg_ecp_base_plus_400h; /* has different meanings */
    141     uint8_t                               reg_ecp_config_b;
     136    uint8_t             reg_ecp_ecr;
     137    uint8_t             reg_ecp_base_plus_400h; /* has different meanings */
     138    uint8_t             reg_ecp_config_b;
    142139
    143140    /** The ECP FIFO implementation*/
    144     uint8_t                             ecp_fifo[LPT_ECP_FIFO_DEPTH];
    145     uint8_t                             abAlignemnt[2];
    146     int                                 act_fifo_pos_write;
    147     int                                 act_fifo_pos_read;
    148 #endif
    149 } PARALLELPORT, *PPARALLELPORT;
     141    uint8_t             ecp_fifo[LPT_ECP_FIFO_DEPTH];
     142    uint8_t             abAlignemnt[3];
     143    int32_t             act_fifo_pos_write;
     144    int32_t             act_fifo_pos_read;
     145#endif
     146} PARALLELPORT;
     147/** Pointer to the shared parallel device state. */
     148typedef PARALLELPORT *PPARALLELPORT;
    150149
    151150#ifndef VBOX_DEVICE_STRUCT_TESTCASE
     
    428427PDMBOTHCBDECL(int) parallelIOPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t *pu32, unsigned cb)
    429428{
    430     PARALLELPORT *pThis = PDMDEVINS_2_DATA(pDevIns, PARALLELPORT *);
     429    PPARALLELPORT pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT);
    431430    int           rc = VINF_SUCCESS;
    432431    RT_NOREF_PV(pvUser);
     
    531530PDMBOTHCBDECL(int) parallelIOPortWriteECP(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t u32, unsigned cb)
    532531{
    533     PARALLELPORT *pThis = PDMDEVINS_2_DATA(pDevIns, PARALLELPORT *);
     532    PPARALLELPORT pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT);
    534533    int            rc = VINF_SUCCESS;
    535534
     
    550549PDMBOTHCBDECL(int) parallelIOPortReadECP(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT Port, uint32_t *pu32, unsigned cb)
    551550{
    552     PARALLELPORT *pThis = PDMDEVINS_2_DATA(pDevIns, PARALLELPORT *);
     551    PPARALLELPORT pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT);
    553552    int           rc = VINF_SUCCESS;
    554553
     
    572571static DECLCALLBACK(int) parallelR3LiveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uPass)
    573572{
     573    PPARALLELPORT   pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT);
     574    PCPDMDEVHLPR3   pHlp  = pDevIns->pHlpR3;
    574575    RT_NOREF(uPass);
    575     PARALLELPORT *pThis = PDMDEVINS_2_DATA(pDevIns, PARALLELPORT *);
    576 
    577     SSMR3PutS32(pSSM, pThis->iIrq);
    578     SSMR3PutU32(pSSM, pThis->IOBase);
    579     SSMR3PutU32(pSSM, UINT32_MAX); /* sanity/terminator */
     576
     577    pHlp->pfnSSMPutS32(pSSM, pThis->iIrq);
     578    pHlp->pfnSSMPutU32(pSSM, pThis->IOBase);
     579    pHlp->pfnSSMPutU32(pSSM, UINT32_MAX); /* sanity/terminator */
    580580    return VINF_SSM_DONT_CALL_AGAIN;
    581581}
     
    587587static DECLCALLBACK(int) parallelR3SaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    588588{
    589     PARALLELPORT *pThis = PDMDEVINS_2_DATA(pDevIns, PARALLELPORT *);
    590 
    591     SSMR3PutU8(pSSM, pThis->regData);
    592     SSMR3PutU8(pSSM, pThis->regStatus);
    593     SSMR3PutU8(pSSM, pThis->regControl);
     589    PPARALLELPORT   pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT);
     590    PCPDMDEVHLPR3   pHlp  = pDevIns->pHlpR3;
     591
     592    pHlp->pfnSSMPutU8(pSSM, pThis->regData);
     593    pHlp->pfnSSMPutU8(pSSM, pThis->regStatus);
     594    pHlp->pfnSSMPutU8(pSSM, pThis->regControl);
    594595
    595596    parallelR3LiveExec(pDevIns, pSSM, 0);
     
    603604static DECLCALLBACK(int) parallelR3LoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
    604605{
    605     PARALLELPORT *pThis = PDMDEVINS_2_DATA(pDevIns, PARALLELPORT *);
     606    PPARALLELPORT   pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT);
     607    PCPDMDEVHLPR3   pHlp  = pDevIns->pHlpR3;
    606608
    607609    AssertMsgReturn(uVersion == PARALLEL_SAVED_STATE_VERSION, ("%d\n", uVersion), VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION);
     
    609611    if (uPass == SSM_PASS_FINAL)
    610612    {
    611         SSMR3GetU8(pSSM, &pThis->regData);
    612         SSMR3GetU8(pSSM, &pThis->regStatus);
    613         SSMR3GetU8(pSSM, &pThis->regControl);
     613        pHlp->pfnSSMGetU8(pSSM, &pThis->regData);
     614        pHlp->pfnSSMGetU8(pSSM, &pThis->regStatus);
     615        pHlp->pfnSSMGetU8(pSSM, &pThis->regControl);
    614616    }
    615617
    616618    /* the config */
    617619    int32_t  iIrq;
    618     SSMR3GetS32(pSSM, &iIrq);
     620    pHlp->pfnSSMGetS32(pSSM, &iIrq);
    619621    uint32_t uIoBase;
    620     SSMR3GetU32(pSSM, &uIoBase);
     622    pHlp->pfnSSMGetU32(pSSM, &uIoBase);
    621623    uint32_t u32;
    622     int rc = SSMR3GetU32(pSSM, &u32);
     624    int rc = pHlp->pfnSSMGetU32(pSSM, &u32);
    623625    if (RT_FAILURE(rc))
    624626        return rc;
     
    626628
    627629    if (pThis->iIrq != iIrq)
    628         return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("IRQ changed: config=%#x state=%#x"), pThis->iIrq, iIrq);
     630        return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("IRQ changed: config=%#x state=%#x"), pThis->iIrq, iIrq);
    629631
    630632    if (pThis->IOBase != uIoBase)
    631         return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("IOBase changed: config=%#x state=%#x"), pThis->IOBase, uIoBase);
     633        return pHlp->pfnSSMSetCfgError(pSSM, RT_SRC_POS, N_("IOBase changed: config=%#x state=%#x"), pThis->IOBase, uIoBase);
    632634
    633635    /* not necessary... but it doesn't harm. */
     
    656658static DECLCALLBACK(void) parallelR3Relocate(PPDMDEVINS pDevIns, RTGCINTPTR offDelta)
    657659{
    658     PARALLELPORT *pThis = PDMDEVINS_2_DATA(pDevIns, PARALLELPORT *);
     660    PPARALLELPORT pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT);
    659661    pThis->pDevInsRC += offDelta;
    660662}
     
    667669{
    668670    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    669     int            rc;
    670     PARALLELPORT *pThis = PDMDEVINS_2_DATA(pDevIns, PARALLELPORT*);
     671    PPARALLELPORT   pThis = PDMDEVINS_2_DATA(pDevIns, PPARALLELPORT);
     672    PCPDMDEVHLPR3   pHlp  = pDevIns->pHlpR3;
     673    int             rc;
    671674
    672675    Assert(iInstance < 4);
     
    696699     * Validate and read the configuration.
    697700     */
    698     if (!CFGMR3AreValuesValid(pCfg, "IRQ\0" "IOBase\0" "GCEnabled\0" "R0Enabled\0"))
    699         return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    700                                 N_("Configuration error: Unknown config key"));
    701 
    702     rc = CFGMR3QueryBoolDef(pCfg, "GCEnabled", &pThis->fGCEnabled, false);
     701    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "IRQ|IOBase", "");
     702
     703    rc = pHlp->pfnCFGMQueryS32Def(pCfg, "IRQ", &pThis->iIrq, 7);
    703704    if (RT_FAILURE(rc))
    704         return PDMDEV_SET_ERROR(pDevIns, rc,
    705                                 N_("Configuration error: Failed to get the \"GCEnabled\" value"));
    706 
    707     rc = CFGMR3QueryBoolDef(pCfg, "R0Enabled", &pThis->fR0Enabled, false);
     705        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to get the \"IRQ\" value"));
     706
     707    rc = pHlp->pfnCFGMQueryU16Def(pCfg, "IOBase", &pThis->IOBase, 0x378);
    708708    if (RT_FAILURE(rc))
    709         return PDMDEV_SET_ERROR(pDevIns, rc,
    710                                 N_("Configuration error: Failed to get the \"R0Enabled\" value"));
    711     rc = CFGMR3QueryS32Def(pCfg, "IRQ", &pThis->iIrq, 7);
    712     if (RT_FAILURE(rc))
    713         return PDMDEV_SET_ERROR(pDevIns, rc,
    714                                 N_("Configuration error: Failed to get the \"IRQ\" value"));
    715     rc = CFGMR3QueryU16Def(pCfg, "IOBase", &pThis->IOBase, 0x378);
    716     if (RT_FAILURE(rc))
    717         return PDMDEV_SET_ERROR(pDevIns, rc,
    718                                 N_("Configuration error: Failed to get the \"IOBase\" value"));
    719 
    720     int port_count = (pThis->IOBase == 0x3BC) ? 4 : 8;
     709        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to get the \"IOBase\" value"));
     710
     711    int cPorts = (pThis->IOBase == 0x3BC) ? 4 : 8;
    721712    /*
    722713     * Register the I/O ports and saved state.
    723714     */
    724     rc = PDMDevHlpIOPortRegister(pDevIns, pThis->IOBase, port_count, 0,
     715    rc = PDMDevHlpIOPortRegister(pDevIns, pThis->IOBase, cPorts, 0,
    725716                                 parallelIOPortWrite, parallelIOPortRead,
    726717                                 NULL, NULL, "Parallel");
    727     if (RT_FAILURE(rc))
    728         return rc;
     718    AssertRCReturn(rc, rc);
    729719
    730720#if 0
     
    733723                                 parallelIOPortWriteECP, parallelIOPortReadECP,
    734724                                 NULL, NULL, "PARALLEL ECP");
    735     if (RT_FAILURE(rc))
    736         return rc;
    737 #endif
    738 
    739     if (pThis->fGCEnabled)
    740     {
    741         rc = PDMDevHlpIOPortRegisterRC(pDevIns, pThis->IOBase, port_count, 0, "parallelIOPortWrite",
     725    AssertRCReturn(rc, rc);
     726#endif
     727
     728    if (pDevIns->fRCEnabled)
     729    {
     730        rc = PDMDevHlpIOPortRegisterRC(pDevIns, pThis->IOBase, cPorts, 0, "parallelIOPortWrite",
    742731                                       "parallelIOPortRead", NULL, NULL, "Parallel");
    743732        if (RT_FAILURE(rc))
     
    745734
    746735#if 0
    747         rc = PDMDevHlpIOPortRegisterGC(pDevIns, io_base+0x400, port_count, 0, "parallelIOPortWriteECP",
     736        rc = PDMDevHlpIOPortRegisterGC(pDevIns, io_base+0x400, cPorts, 0, "parallelIOPortWriteECP",
    748737                                       "parallelIOPortReadECP", NULL, NULL, "Parallel Ecp");
    749738        if (RT_FAILURE(rc))
     
    752741    }
    753742
    754     if (pThis->fR0Enabled)
    755     {
    756         rc = PDMDevHlpIOPortRegisterR0(pDevIns, pThis->IOBase, port_count, 0, "parallelIOPortWrite",
     743    if (pDevIns->fR0Enabled)
     744    {
     745        rc = PDMDevHlpIOPortRegisterR0(pDevIns, pThis->IOBase, cPorts, 0, "parallelIOPortWrite",
    757746                                       "parallelIOPortRead", NULL, NULL, "Parallel");
    758747        if (RT_FAILURE(rc))
     
    769758    rc = PDMDevHlpSSMRegister3(pDevIns, PARALLEL_SAVED_STATE_VERSION, sizeof(*pThis),
    770759                               parallelR3LiveExec, parallelR3SaveExec, parallelR3LoadExec);
    771     if (RT_FAILURE(rc))
    772         return rc;
     760    AssertRCReturn(rc, rc);
    773761
    774762
Note: See TracChangeset for help on using the changeset viewer.

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