VirtualBox

Changeset 81512 in vbox for trunk/src/VBox/Devices/EFI


Ignore:
Timestamp:
Oct 24, 2019 9:19:42 AM (5 years ago)
Author:
vboxsync
Message:

DevFlash: Converted to new style and added and enabled ring-0 bits. bugref:9218

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Devices/EFI/DevFlash.cpp

    r81509 r81512  
    4343*********************************************************************************************************************************/
    4444/**
    45  * The flash device
     45 * The flash device, shared state.
    4646 */
    4747typedef struct DEVFLASH
     
    5151    /** The guest physical memory base address. */
    5252    RTGCPHYS            GCPhysFlashBase;
    53     /** The file conaining the flash content. */
    54     char                *pszFlashFile;
     53    /** The handle to the MMIO region. */
     54    IOMMMIOHANDLE       hMmio;
    5555} DEVFLASH;
    5656/** Pointer to the Flash device state. */
    5757typedef DEVFLASH *PDEVFLASH;
    5858
     59/**
     60 * The flash device, ring-3 state.
     61 */
     62typedef struct DEVFLASHR3
     63{
     64    /** The file conaining the flash content. */
     65    char               *pszFlashFile;
     66} DEVFLASHR3;
     67/** Pointer to the ring-3 Flash device state. */
     68typedef DEVFLASHR3 *PDEVFLASHR3;
     69
     70
    5971#ifndef VBOX_DEVICE_STRUCT_TESTCASE
    6072
    6173
    62 #ifdef IN_RING3 /* for now */
    63 
    64 /** @callback_method_impl{FNIOMMIWRITE, Flash memory write} */
    65 PDMBOTHCBDECL(int) flashMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb)
     74/**
     75 * @callback_method_impl{FNIOMMMIONEWWRITE, Flash memory write}
     76 */
     77PDMBOTHCBDECL(VBOXSTRICTRC) flashMMIOWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb)
    6678{
    6779    PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH);
    6880    RT_NOREF1(pvUser);
    69 
    70     return VBOXSTRICTRC_TODO(flashWrite(&pThis->Core, GCPhysAddr - pThis->GCPhysFlashBase, pv, cb));
    71 }
    72 
    73 
    74 /** @callback_method_impl{FNIOMMIOREAD, Flash memory read} */
    75 PDMBOTHCBDECL(int) flashMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
     81    return flashWrite(&pThis->Core, off, pv, cb);
     82}
     83
     84
     85/**
     86 * @callback_method_impl{FNIOMMMIONEWREAD, Flash memory read}
     87 */
     88PDMBOTHCBDECL(VBOXSTRICTRC) flashMMIORead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb)
    7689{
    7790    PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH);
    7891    RT_NOREF1(pvUser);
    79 
    80     return VBOXSTRICTRC_TODO(flashRead(&pThis->Core, GCPhysAddr - pThis->GCPhysFlashBase, pv, cb));
    81 }
    82 
    83 #endif /* IN_RING3 for now */
     92    return flashRead(&pThis->Core, off, pv, cb);
     93}
    8494
    8595#ifdef IN_RING3
    8696
    87 /** @callback_method_impl{FNSSMDEVSAVEEXEC} */
     97/**
     98 * @callback_method_impl{FNSSMDEVSAVEEXEC}
     99 */
    88100static DECLCALLBACK(int) flashSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
    89101{
     
    93105
    94106
    95 /** @callback_method_impl{FNSSMDEVLOADEXEC} */
     107/**
     108 * @callback_method_impl{FNSSMDEVLOADEXEC}
     109 */
    96110static DECLCALLBACK(int) flashLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
    97111{
     
    106120}
    107121
     122
    108123/**
    109124 * @interface_method_impl{PDMDEVREG,pfnReset}
     
    112127{
    113128    PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH);
    114 
    115129    flashR3Reset(&pThis->Core);
    116130}
    117131
     132
    118133/**
    119134 * @interface_method_impl{PDMDEVREG,pfnDestruct}
     
    122137{
    123138    PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
    124     PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH);
    125 
    126     int rc = flashR3SaveToFile(&pThis->Core, pDevIns, pThis->pszFlashFile);
    127     if (RT_FAILURE(rc))
    128         LogRel(("Flash: Failed to save flash file: %Rrc\n", rc));
    129 
    130     if (pThis->pszFlashFile)
     139    PDEVFLASH   pThis   = PDMINS_2_DATA(pDevIns, PDEVFLASH);
     140    PDEVFLASHR3 pThisR3 = PDMINS_2_DATA_CC(pDevIns, PDEVFLASHR3);
     141
     142    if (pThisR3->pszFlashFile)
    131143    {
    132         PDMDevHlpMMHeapFree(pDevIns, pThis->pszFlashFile);
    133         pThis->pszFlashFile = NULL;
     144        int rc = flashR3SaveToFile(&pThis->Core, pDevIns, pThisR3->pszFlashFile);
     145        if (RT_FAILURE(rc))
     146            LogRel(("Flash: Failed to save flash file: %Rrc\n", rc));
     147
     148        PDMDevHlpMMHeapFree(pDevIns, pThisR3->pszFlashFile);
     149        pThisR3->pszFlashFile = NULL;
    134150    }
    135151
     
    138154}
    139155
     156
    140157/**
    141158 * @interface_method_impl{PDMDEVREG,pfnConstruct}
     
    144161{
    145162    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    146     RT_NOREF1(iInstance);
    147     PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH);
    148     Assert(iInstance == 0);
     163    PDEVFLASH       pThis   = PDMINS_2_DATA(pDevIns, PDEVFLASH);
     164    PDEVFLASHR3     pThisR3 = PDMINS_2_DATA_CC(pDevIns, PDEVFLASHR3);
     165    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
     166
     167    Assert(iInstance == 0); RT_NOREF1(iInstance);
    149168
    150169    /*
     
    159178    /* The default device ID is Intel 28F800SA. */
    160179    uint16_t u16FlashId = 0;
    161     int rc = CFGMR3QueryU16Def(pCfg, "DeviceId", &u16FlashId, 0xA289);
     180    int rc = pHlp->pfnCFGMQueryU16Def(pCfg, "DeviceId", &u16FlashId, 0xA289);
    162181    if (RT_FAILURE(rc))
    163182        return PDMDEV_SET_ERROR(pDevIns, rc,
     
    165184
    166185    /* The default base address is 2MB below 4GB. */
    167     rc = CFGMR3QueryU64Def(pCfg, "BaseAddress", &pThis->GCPhysFlashBase, 0xFFE00000);
     186    rc = pHlp->pfnCFGMQueryU64Def(pCfg, "BaseAddress", &pThis->GCPhysFlashBase, 0xFFE00000);
    168187    if (RT_FAILURE(rc))
    169188        return PDMDEV_SET_ERROR(pDevIns, rc,
     
    172191    /* The default flash device size is 128K. */
    173192    uint32_t cbFlash = 0;
    174     rc = CFGMR3QueryU32Def(pCfg, "Size", &cbFlash, 128 * _1K);
     193    rc = pHlp->pfnCFGMQueryU32Def(pCfg, "Size", &cbFlash, 128 * _1K);
    175194    if (RT_FAILURE(rc))
    176195        return PDMDEV_SET_ERROR(pDevIns, rc,
     
    179198    /* The default flash device block size is 4K. */
    180199    uint16_t cbBlock = 0;
    181     rc = CFGMR3QueryU16Def(pCfg, "BlockSize", &cbBlock, _4K);
     200    rc = pHlp->pfnCFGMQueryU16Def(pCfg, "BlockSize", &cbBlock, _4K);
    182201    if (RT_FAILURE(rc))
    183202        return PDMDEV_SET_ERROR(pDevIns, rc,
    184203                                N_("Configuration error: Querying \"BlockSize\" as an integer failed"));
    185204
    186     rc = CFGMR3QueryStringAlloc(pCfg, "FlashFile", &pThis->pszFlashFile);
     205    rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "FlashFile", &pThisR3->pszFlashFile);
    187206    if (RT_FAILURE(rc))
    188207        return PDMDEV_SET_ERROR(pDevIns, rc,
    189208                                N_("Configuration error: Querying \"FlashFile\" as a string failed"));
    190209
     210    /*
     211     * Initialize the flash core.
     212     */
    191213    rc = flashR3Init(&pThis->Core, pDevIns, u16FlashId, cbFlash, cbBlock);
    192214    if (RT_FAILURE(rc))
     
    195217
    196218    /* Try to load the flash content from file. */
    197     rc = flashR3LoadFromFile(&pThis->Core, pDevIns, pThis->pszFlashFile);
     219    rc = flashR3LoadFromFile(&pThis->Core, pDevIns, pThisR3->pszFlashFile);
    198220    if (RT_FAILURE(rc))
    199221        return PDMDEV_SET_ERROR(pDevIns, rc,
     
    203225     * Register MMIO region.
    204226     */
    205     rc = PDMDevHlpMMIORegister(pDevIns, pThis->GCPhysFlashBase, cbFlash, NULL /*pvUser*/,
    206                                IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU,
    207                                flashMMIOWrite, flashMMIORead,
    208                                "Flash Memory");
     227    rc = PDMDevHlpMmioCreateExAndMap(pDevIns, pThis->GCPhysFlashBase, cbFlash,
     228                                     IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU, NULL, UINT32_MAX,
     229                                     flashMMIOWrite, flashMMIORead, NULL, NULL, "Flash Memory", &pThis->hMmio);
    209230    AssertRCReturn(rc, rc);
    210231    LogRel(("Registered %uKB flash at %RGp\n", pThis->Core.cbFlashSize / _1K, pThis->GCPhysFlashBase));
     
    214235     */
    215236    rc = PDMDevHlpSSMRegister(pDevIns, FLASH_SAVED_STATE_VERSION, sizeof(*pThis), flashSaveExec, flashLoadExec);
    216     if (RT_FAILURE(rc))
    217         return rc;
     237    AssertRCReturn(rc, rc);
    218238
    219239    return VINF_SUCCESS;
    220240}
    221241
    222 #endif /* IN_RING3 */
     242#else  /* !IN_RING3 */
     243
     244/**
     245 * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
     246 */
     247static DECLCALLBACK(int) flashRZConstruct(PPDMDEVINS pDevIns)
     248{
     249    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
     250    PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH);
     251
     252# if 1
     253    int rc = PDMDevHlpMmioSetUpContext(pDevIns, pThis->hMmio, flashMMIOWrite, flashMMIORead, NULL /*pvUser*/);
     254    AssertRCReturn(rc, rc);
     255# else
     256    RT_NOREF(pDevIns, pThis); (void)&flashMMIOWrite; (void)&flashMMIORead;
     257# endif
     258
     259    return VINF_SUCCESS;
     260}
     261
     262#endif /* !IN_RING3 */
    223263
    224264/**
     
    230270    /* .uReserved0 = */             0,
    231271    /* .szName = */                 "flash",
    232     /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS,
     272    /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_RZ | PDM_DEVREG_FLAGS_NEW_STYLE,
    233273    /* .fClass = */                 PDM_DEVREG_CLASS_ARCH,
    234274    /* .cMaxInstances = */          1,
     
    267307#elif defined(IN_RING0)
    268308    /* .pfnEarlyConstruct = */      NULL,
    269     /* .pfnConstruct = */           NULL,
     309    /* .pfnConstruct = */           flashRZConstruct,
    270310    /* .pfnDestruct = */            NULL,
    271311    /* .pfnFinalDestruct = */       NULL,
     
    281321#elif defined(IN_RC)
    282322    /* .pfnConstruct = */           NULL,
    283     /* .pfnReserved0 = */           NULL,
     323    /* .pfnReserved0 = */           flashRZConstruct,
    284324    /* .pfnReserved1 = */           NULL,
    285325    /* .pfnReserved2 = */           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