VirtualBox

Changeset 81889 in vbox


Ignore:
Timestamp:
Nov 15, 2019 10:44:32 PM (5 years ago)
Author:
vboxsync
Message:

DevSerial: Working on converting to the new PDM device style - I/O ports. bugref:9218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/Serial/DevSerial.cpp

    r81888 r81889  
    5050    /** Pointer to the device instance - RC Ptr. */
    5151    PPDMDEVINSRC                    pDevInsRC;
    52     /** Alignment. */
    53     RTRCPTR                         Alignment0;
    54     /** Flag whether the R0 portion of this device is enabled. */
    55     bool                            fR0Enabled;
    56     /** Flag whether the RC portion of this device is enabled. */
    57     bool                            fRCEnabled;
    58     /** Alignment. */
    59     bool                            afAlignment1[2];
    6052    /** The IRQ value. */
    6153    uint8_t                         uIrq;
     54    uint8_t                         bAlignment;
    6255    /** The base I/O port the device is registered at. */
    6356    RTIOPORT                        PortBase;
     57    /** The I/O ports registration. */
     58    IOMIOPORTHANDLE                 hIoPorts;
    6459
    6560    /** The UART core. */
     
    8479
    8580/**
    86  * @callback_method_impl{FNIOMIOPORTOUT}
    87  */
    88 PDMBOTHCBDECL(int) serialIoPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t u32, unsigned cb)
     81 * @callback_method_impl{FNIOMIOPORTNEWOUT}
     82 */
     83static DECLCALLBACK(VBOXSTRICTRC)
     84serialIoPortWrite(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t u32, unsigned cb)
    8985{
    9086    PDEVSERIAL pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSERIAL);
    9187    RT_NOREF_PV(pvUser);
    9288
    93     return uartRegWrite(&pThis->UartCore, uPort - pThis->PortBase, u32, cb);
    94 }
    95 
    96 
    97 /**
    98  * @callback_method_impl{FNIOMIOPORTIN}
    99  */
    100 PDMBOTHCBDECL(int) serialIoPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT uPort, uint32_t *pu32, unsigned cb)
     89    return uartRegWrite(&pThis->UartCore, offPort, u32, cb);
     90}
     91
     92
     93/**
     94 * @callback_method_impl{FNIOMIOPORTNEWIN}
     95 */
     96static DECLCALLBACK(VBOXSTRICTRC)
     97serialIoPortRead(PPDMDEVINS pDevIns, void *pvUser, RTIOPORT offPort, uint32_t *pu32, unsigned cb)
    10198{
    10299    PDEVSERIAL pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSERIAL);
    103100    RT_NOREF_PV(pvUser);
    104101
    105     return uartRegRead(&pThis->UartCore, uPort - pThis->PortBase, pu32, cb);
     102    return uartRegRead(&pThis->UartCore, offPort, pu32, cb);
    106103}
    107104
     
    326323    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns, "IRQ|IOBase|YieldOnLSRRead|UartType", "");
    327324
    328     rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "GCEnabled", &pThis->fRCEnabled, true);
    329     if (RT_FAILURE(rc))
    330         return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to get the \"GCEnabled\" value"));
    331 
    332     rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "R0Enabled", &pThis->fR0Enabled, true);
    333     if (RT_FAILURE(rc))
    334         return PDMDEV_SET_ERROR(pDevIns, rc, N_("Configuration error: Failed to get the \"R0Enabled\" value"));
    335 
    336325    bool fYieldOnLSRRead = false;
    337326    rc = pHlp->pfnCFGMQueryBoolDef(pCfg, "YieldOnLSRRead", &fYieldOnLSRRead, false);
     
    393382     * Register the I/O ports.
    394383     */
    395     rc = PDMDevHlpIOPortRegister(pDevIns, uIoBase, 8, 0,
    396                                  serialIoPortWrite, serialIoPortRead,
    397                                  NULL, NULL, "SERIAL");
    398     if (RT_FAILURE(rc))
    399         return rc;
     384    rc = PDMDevHlpIoPortCreateAndMap(pDevIns, uIoBase, 8 /*cPorts*/, serialIoPortWrite, serialIoPortRead,
     385                                     "SERIAL", NULL /*paExtDescs*/, &pThis->hIoPorts);
     386    AssertRCReturn(rc, rc);
    400387
    401388    PVM pVM = PDMDevHlpGetVM(pDevIns);
     
    406393    if (pDevIns->fRCEnabled)
    407394    {
    408         rc = PDMDevHlpIOPortRegisterRC(pDevIns, uIoBase, 8, 0, "serialIoPortWrite", "serialIoPortRead", NULL, NULL, "SERIAL");
    409         if (   RT_SUCCESS(rc)
    410             && VM_IS_RAW_MODE_ENABLED(pVM)) /** @todo this dynamic symbol resolving will be reworked later! */
     395        if (VM_IS_RAW_MODE_ENABLED(pVM)) /** @todo this dynamic symbol resolving will be reworked later! */
    411396            rc = PDMR3LdrGetSymbolRC(pVM, pDevIns->pReg->pszRCMod, "serialIrqReq", &pfnSerialIrqReqRC);
    412397        if (RT_FAILURE(rc))
     
    417402    if (pDevIns->fR0Enabled)
    418403    {
    419         rc = PDMDevHlpIOPortRegisterR0(pDevIns, uIoBase, 8, 0, "serialIoPortWrite", "serialIoPortRead", NULL, NULL, "SERIAL");
    420         if (RT_SUCCESS(rc)) /** @todo this dynamic symbol resolving will be reworked later! */
    421             rc = PDMR3LdrGetSymbolR0(pVM, pDevIns->pReg->pszR0Mod, "serialIrqReq", &pfnSerialIrqReqR0);
     404        /** @todo this dynamic symbol resolving will be reworked later! */
     405        rc = PDMR3LdrGetSymbolR0(pVM, pDevIns->pReg->pszR0Mod, "serialIrqReq", &pfnSerialIrqReqR0);
    422406        if (RT_FAILURE(rc))
    423407            return rc;
     
    442426}
    443427
    444 #endif /* IN_RING3 */
     428#else  /* !IN_RING3 */
     429
     430/**
     431 * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
     432 */
     433static DECLCALLBACK(int) serialRZConstruct(PPDMDEVINS pDevIns)
     434{
     435    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
     436    PDEVSERIAL pThis = PDMDEVINS_2_DATA(pDevIns, PDEVSERIAL);
     437
     438    int rc = PDMDevHlpSetDeviceCritSect(pDevIns, PDMDevHlpCritSectGetNop(pDevIns));
     439    AssertRCReturn(rc, rc);
     440
     441    rc = PDMDevHlpIoPortSetUpContext(pDevIns, pThis->hIoPorts, serialIoPortWrite, serialIoPortRead, NULL /*pvUser*/);
     442    AssertRCReturn(rc, rc);
     443
     444    return VINF_SUCCESS;
     445}
     446
     447#endif /* !IN_RING3 */
    445448
    446449/**
     
    452455    /* .uReserved0 = */             0,
    453456    /* .szName = */                 "serial",
    454     /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ,
     457    /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ | PDM_DEVREG_FLAGS_NEW_STYLE,
    455458    /* .fClass = */                 PDM_DEVREG_CLASS_SERIAL,
    456459    /* .cMaxInstances = */          UINT32_MAX,
     
    489492#elif defined(IN_RING0)
    490493    /* .pfnEarlyConstruct = */      NULL,
    491     /* .pfnConstruct = */           NULL,
     494    /* .pfnConstruct = */           serialRZConstruct,
    492495    /* .pfnDestruct = */            NULL,
    493496    /* .pfnFinalDestruct = */       NULL,
     
    502505    /* .pfnReserved7 = */           NULL,
    503506#elif defined(IN_RC)
    504     /* .pfnConstruct = */           NULL,
     507    /* .pfnConstruct = */           serialRZConstruct,
    505508    /* .pfnReserved0 = */           NULL,
    506509    /* .pfnReserved1 = */           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