VirtualBox

Changeset 81502 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Oct 24, 2019 1:40:30 AM (5 years ago)
Author:
vboxsync
Message:

EFI,FlashCore: Trying to get ring-0 callback for the flash up and going. bugref:6940

FlashCore:

  • Ring-0 support.
  • Don't keep pDevIns in the structure, let the parent pass it in.
  • Adjustments for new PDM device style.
  • Function documentations at the place of implementation rather than the header, please. We only put it in headers under /include/, and even there only really for iprt as it may have 10 different implementations of each function.

DevEFI:

  • Converted to new PDM device style.
  • Ring-0 support for flash (disabled as of now).
Location:
trunk/src/VBox/Devices
Files:
7 edited

Legend:

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

    r81484 r81502  
    5656
    5757/* EFI includes */
    58 #ifdef _MSC_VER
    59 # pragma warning(push)
    60 # pragma warning(disable:4668)
     58#ifdef IN_RING3
     59# ifdef _MSC_VER
     60#  pragma warning(push)
     61#  pragma warning(disable:4668)
     62# endif
     63# include <ProcessorBind.h>
     64# ifdef _MSC_VER
     65#  pragma warning(pop)
     66# endif
     67# include <Common/UefiBaseTypes.h>
     68# include <Common/PiFirmwareVolume.h>
     69# include <Common/PiFirmwareFile.h>
    6170#endif
    62 #include <ProcessorBind.h>
    63 #ifdef _MSC_VER
    64 # pragma warning(pop)
    65 #endif
    66 #include <Common/UefiBaseTypes.h>
    67 #include <Common/PiFirmwareVolume.h>
    68 #include <Common/PiFirmwareFile.h>
    6971
    7072
     
    135137
    136138/**
    137  * The EFI device state structure.
     139 * The EFI device shared state structure.
    138140 */
    139141typedef struct DEVEFI
     142{
     143    /** The flash device containing the NVRAM. */
     144    FLASHCORE               Flash;
     145    /** The flash MMIO handle. */
     146    IOMMMIOHANDLE           hMmioFlash;
     147} DEVEFI;
     148/** Pointer to the shared EFI state. */
     149typedef DEVEFI *PDEVEFI;
     150
     151/**
     152 * The EFI device state structure for ring-3.
     153 */
     154typedef struct DEVEFIR3
    140155{
    141156    /** Pointer back to the device instance. */
     
    245260    /** NVRAM state variables. */
    246261    NVRAMDESC               NVRAM;
    247     /** The flash device containing the NVRAM. */
    248     FLASHCORE               Flash;
    249262    /** Filename of the file containing the NVRAM store. */
    250263    char                    *pszNvramFile;
     
    264277        PPDMINVRAMCONNECTOR pNvramDrv;
    265278    } Lun0;
    266 } DEVEFI;
    267 typedef DEVEFI *PDEVEFI;
     279} DEVEFIR3;
     280/** Pointer to the ring-3 EFI state. */
     281typedef DEVEFIR3 *PDEVEFIR3;
     282
     283
     284/**
     285 * The EFI device state structure for ring-0.
     286 */
     287typedef struct DEVEFIR0
     288{
     289    uint32_t uEmpty;
     290} DEVEFIR0;
     291/** Pointer to the ring-0 EFI state.  */
     292typedef DEVEFIR0 *PDEVEFIR0;
     293
     294
     295/**
     296 * The EFI device state structure for raw-mode.
     297 */
     298typedef struct DEVEFIRC
     299{
     300    uint32_t uEmpty;
     301} DEVEFIRC;
     302/** Pointer to the raw-mode EFI state.  */
     303typedef DEVEFIRC *PDEVEFIRC;
     304
     305
     306/** @typedef DEVEFICC
     307 * The instance data for the current context. */
     308/** @typedef PDEVEFICC
     309 * Pointer to the instance data for the current context. */
     310#ifdef IN_RING3
     311typedef  DEVEFIR3  DEVEFICC;
     312typedef PDEVEFIR3 PDEVEFICC;
     313#elif defined(IN_RING0)
     314typedef  DEVEFIR0  DEVEFICC;
     315typedef PDEVEFIR0 PDEVEFICC;
     316#elif defined(IN_RC)
     317typedef  DEVEFIRC  DEVEFICC;
     318typedef PDEVEFIRC PDEVEFICC;
     319#else
     320# error "Not IN_RING3, IN_RING0 or IN_RC"
     321#endif
    268322
    269323
     
    287341*   Global Variables                                                                                                             *
    288342*********************************************************************************************************************************/
     343#ifdef IN_RING3
    289344/** Saved state NVRAMDESC field descriptors. */
    290345static SSMFIELD const g_aEfiNvramDescField[] =
     
    319374static const RTUUID g_UuidNvDataFv = { { 0x8d, 0x2b, 0xf1, 0xff, 0x96, 0x76, 0x8b, 0x4c, 0xa9, 0x85, 0x27, 0x47, 0x07, 0x5b, 0x4f, 0x50} };
    320375
    321 #ifdef VBOX_WITH_EFI_IN_DD2
     376# ifdef VBOX_WITH_EFI_IN_DD2
    322377/** Special file name value for indicating the 32-bit built-in EFI firmware. */
    323378static const char g_szEfiBuiltin32[] = "VBoxEFI32.fd";
    324379/** Special file name value for indicating the 64-bit built-in EFI firmware. */
    325380static const char g_szEfiBuiltin64[] = "VBoxEFI64.fd";
    326 #endif
    327 
    328 
    329 
     381# endif
     382#endif /* IN_RING3 */
     383
     384
     385#ifdef IN_RING3
    330386
    331387/**
    332388 * Flushes the variable list.
    333389 *
    334  * @param   pThis               The EFI state.
    335  */
    336 static void nvramFlushDeviceVariableList(PDEVEFI pThis)
    337 {
    338     while (!RTListIsEmpty(&pThis->NVRAM.VarList))
    339     {
    340         PEFIVAR pEfiVar = RTListNodeGetNext(&pThis->NVRAM.VarList, EFIVAR, ListNode);
     390 * @param   pThisCC             The EFI state for the current context.
     391 */
     392static void nvramFlushDeviceVariableList(PDEVEFIR3 pThisCC)
     393{
     394    while (!RTListIsEmpty(&pThisCC->NVRAM.VarList))
     395    {
     396        PEFIVAR pEfiVar = RTListNodeGetNext(&pThisCC->NVRAM.VarList, EFIVAR, ListNode);
    341397        RTListNodeRemove(&pEfiVar->ListNode);
    342398        RTMemFree(pEfiVar);
    343399    }
    344400
    345     pThis->NVRAM.pCurVar = NULL;
     401    pThisCC->NVRAM.pCurVar = NULL;
    346402}
    347403
     
    349405 * This function looks up variable in NVRAM list.
    350406 */
    351 static int nvramLookupVariableByUuidAndName(PDEVEFI pThis, char *pszVariableName, PCRTUUID pUuid, PPEFIVAR ppEfiVar)
     407static int nvramLookupVariableByUuidAndName(PDEVEFIR3 pThisCC, char *pszVariableName, PCRTUUID pUuid, PPEFIVAR ppEfiVar)
    352408{
    353409    LogFlowFunc(("%RTuuid::'%s'\n", pUuid, pszVariableName));
     
    358414     * Start by checking the last variable queried.
    359415     */
    360     if (   pThis->NVRAM.pCurVar
    361         && pThis->NVRAM.pCurVar->cchName == cchVariableName
    362         && memcmp(pThis->NVRAM.pCurVar->szName, pszVariableName, cchVariableName + 1) == 0
    363         && RTUuidCompare(&pThis->NVRAM.pCurVar->uuid, pUuid) == 0
     416    if (   pThisCC->NVRAM.pCurVar
     417        && pThisCC->NVRAM.pCurVar->cchName == cchVariableName
     418        && memcmp(pThisCC->NVRAM.pCurVar->szName, pszVariableName, cchVariableName + 1) == 0
     419        && RTUuidCompare(&pThisCC->NVRAM.pCurVar->uuid, pUuid) == 0
    364420        )
    365421    {
    366         *ppEfiVar = pThis->NVRAM.pCurVar;
     422        *ppEfiVar = pThisCC->NVRAM.pCurVar;
    367423        rc = VINF_SUCCESS;
    368424    }
     
    373429         */
    374430        PEFIVAR pEfiVar;
    375         RTListForEach(&pThis->NVRAM.VarList, pEfiVar, EFIVAR, ListNode)
     431        RTListForEach(&pThisCC->NVRAM.VarList, pEfiVar, EFIVAR, ListNode)
    376432        {
    377433            Assert(strlen(pEfiVar->szName) == pEfiVar->cchName);
     
    397453 * This enforces the desired list ordering and/or insertion policy.
    398454 *
    399  * @param   pThis           The EFI state.
     455 * @param   pThisCC         The EFI state for the current context.
    400456 * @param   pEfiVar         The variable to insert.
    401457 */
    402 static void nvramInsertVariable(PDEVEFI pThis, PEFIVAR pEfiVar)
     458static void nvramInsertVariable(PDEVEFIR3 pThisCC, PEFIVAR pEfiVar)
    403459{
    404460#if 1
     
    407463     */
    408464    PEFIVAR pCurVar;
    409     RTListForEach(&pThis->NVRAM.VarList, pCurVar, EFIVAR, ListNode)
     465    RTListForEach(&pThisCC->NVRAM.VarList, pCurVar, EFIVAR, ListNode)
    410466    {
    411467        int iDiff = RTUuidCompare(&pEfiVar->uuid, &pCurVar->uuid);
     
    423479     * Add it at the end.
    424480     */
    425     RTListAppend(&pThis->NVRAM.VarList, &pEfiVar->ListNode);
     481    RTListAppend(&pThisCC->NVRAM.VarList, &pEfiVar->ListNode);
    426482}
    427483
     
    431487 *
    432488 * @returns VBox status code.
    433  * @param   pThis           The EFI state.
    434  */
    435 static int nvramLoad(PDEVEFI pThis)
     489 * @param   pThisCC         The EFI state for the current context.
     490 */
     491static int nvramLoad(PDEVEFIR3 pThisCC)
    436492{
    437493    int rc;
     
    443499        pEfiVar->cchName = sizeof(pEfiVar->szName);
    444500        pEfiVar->cbValue = sizeof(pEfiVar->abValue);
    445         rc = pThis->Lun0.pNvramDrv->pfnVarQueryByIndex(pThis->Lun0.pNvramDrv, iVar,
     501        rc = pThisCC->Lun0.pNvramDrv->pfnVarQueryByIndex(pThisCC->Lun0.pNvramDrv, iVar,
    446502                                                       &pEfiVar->uuid, &pEfiVar->szName[0], &pEfiVar->cchName,
    447503                                                       &pEfiVar->fAttributes, &pEfiVar->abValue[0], &pEfiVar->cbValue);
     
    469525
    470526        /* Append it. */
    471         nvramInsertVariable(pThis, pEfiVar);
    472         pThis->NVRAM.cVariables++;
     527        nvramInsertVariable(pThisCC, pEfiVar);
     528        pThisCC->NVRAM.cVariables++;
    473529    }
    474530
     
    482538 *
    483539 * @returns VBox status code.
    484  * @param   pThis               The EFI state.
    485  */
    486 static int nvramStore(PDEVEFI pThis)
     540 * @param   pThisCC             The EFI state for the current context.
     541 */
     542static int nvramStore(PDEVEFIR3 pThisCC)
    487543{
    488544    /*
     
    491547    PEFIVAR  pEfiVar;
    492548    uint32_t cNonVolatile = 0;
    493     RTListForEach(&pThis->NVRAM.VarList, pEfiVar, EFIVAR, ListNode)
     549    RTListForEach(&pThisCC->NVRAM.VarList, pEfiVar, EFIVAR, ListNode)
    494550        if (pEfiVar->fAttributes & VBOX_EFI_VARIABLE_NON_VOLATILE)
    495551            cNonVolatile++;
    496     int rc = pThis->Lun0.pNvramDrv->pfnVarStoreSeqBegin(pThis->Lun0.pNvramDrv, cNonVolatile);
     552    int rc = pThisCC->Lun0.pNvramDrv->pfnVarStoreSeqBegin(pThisCC->Lun0.pNvramDrv, cNonVolatile);
    497553    if (RT_SUCCESS(rc))
    498554    {
     
    501557         */
    502558        uint32_t    idxVar  = 0;
    503         RTListForEach(&pThis->NVRAM.VarList, pEfiVar, EFIVAR, ListNode)
     559        RTListForEach(&pThisCC->NVRAM.VarList, pEfiVar, EFIVAR, ListNode)
    504560        {
    505561            /* Skip volatile variables. */
     
    507563                continue;
    508564
    509             int rc2 = pThis->Lun0.pNvramDrv->pfnVarStoreSeqPut(pThis->Lun0.pNvramDrv, idxVar,
     565            int rc2 = pThisCC->Lun0.pNvramDrv->pfnVarStoreSeqPut(pThisCC->Lun0.pNvramDrv, idxVar,
    510566                                                               &pEfiVar->uuid, pEfiVar->szName,  pEfiVar->cchName,
    511567                                                               pEfiVar->fAttributes, pEfiVar->abValue, pEfiVar->cbValue);
     
    522578         * Done.
    523579         */
    524         rc = pThis->Lun0.pNvramDrv->pfnVarStoreSeqEnd(pThis->Lun0.pNvramDrv, rc);
     580        rc = pThisCC->Lun0.pNvramDrv->pfnVarStoreSeqEnd(pThisCC->Lun0.pNvramDrv, rc);
    525581    }
    526582    else
     
    533589 * variable into the VarOpBuf, set pCurVar and u32Status.
    534590 *
    535  * @param   pThis               The EFI state.
     591 * @param   pThisCC             The EFI state for the current context.
    536592 * @param   pEfiVar             The resulting variable. NULL if not found / end.
    537593 * @param   fEnumQuery          Set if enumeration query, clear if specific.
    538594 */
    539 static void nvramWriteVariableOpQueryCopyResult(PDEVEFI pThis, PEFIVAR pEfiVar, bool fEnumQuery)
    540 {
    541     RT_ZERO(pThis->NVRAM.VarOpBuf.abValue);
     595static void nvramWriteVariableOpQueryCopyResult(PDEVEFIR3 pThisCC, PEFIVAR pEfiVar, bool fEnumQuery)
     596{
     597    RT_ZERO(pThisCC->NVRAM.VarOpBuf.abValue);
    542598    if (pEfiVar)
    543599    {
    544         RT_ZERO(pThis->NVRAM.VarOpBuf.szName);
    545         pThis->NVRAM.VarOpBuf.uuid        = pEfiVar->uuid;
    546         pThis->NVRAM.VarOpBuf.cchName     = pEfiVar->cchName;
    547         memcpy(pThis->NVRAM.VarOpBuf.szName, pEfiVar->szName, pEfiVar->cchName); /* no need for + 1. */
    548         pThis->NVRAM.VarOpBuf.fAttributes = pEfiVar->fAttributes;
    549         pThis->NVRAM.VarOpBuf.cbValue     = pEfiVar->cbValue;
    550         memcpy(pThis->NVRAM.VarOpBuf.abValue, pEfiVar->abValue, pEfiVar->cbValue);
    551         pThis->NVRAM.pCurVar              = pEfiVar;
    552         pThis->NVRAM.u32Status            = EFI_VARIABLE_OP_STATUS_OK;
    553         LogFlow(("EFI: Variable query -> %RTuuid::'%s' (%d) abValue=%.*Rhxs\n", &pThis->NVRAM.VarOpBuf.uuid,
    554                  pThis->NVRAM.VarOpBuf.szName, pThis->NVRAM.VarOpBuf.cchName,
    555                  pThis->NVRAM.VarOpBuf.cbValue, pThis->NVRAM.VarOpBuf.abValue));
     600        RT_ZERO(pThisCC->NVRAM.VarOpBuf.szName);
     601        pThisCC->NVRAM.VarOpBuf.uuid        = pEfiVar->uuid;
     602        pThisCC->NVRAM.VarOpBuf.cchName     = pEfiVar->cchName;
     603        memcpy(pThisCC->NVRAM.VarOpBuf.szName, pEfiVar->szName, pEfiVar->cchName); /* no need for + 1. */
     604        pThisCC->NVRAM.VarOpBuf.fAttributes = pEfiVar->fAttributes;
     605        pThisCC->NVRAM.VarOpBuf.cbValue     = pEfiVar->cbValue;
     606        memcpy(pThisCC->NVRAM.VarOpBuf.abValue, pEfiVar->abValue, pEfiVar->cbValue);
     607        pThisCC->NVRAM.pCurVar              = pEfiVar;
     608        pThisCC->NVRAM.u32Status            = EFI_VARIABLE_OP_STATUS_OK;
     609        LogFlow(("EFI: Variable query -> %RTuuid::'%s' (%d) abValue=%.*Rhxs\n", &pThisCC->NVRAM.VarOpBuf.uuid,
     610                 pThisCC->NVRAM.VarOpBuf.szName, pThisCC->NVRAM.VarOpBuf.cchName,
     611                 pThisCC->NVRAM.VarOpBuf.cbValue, pThisCC->NVRAM.VarOpBuf.abValue));
    556612    }
    557613    else
     
    561617        else
    562618            LogFlow(("EFI: Variable query %RTuuid::'%s' -> NOT_FOUND \n",
    563                      &pThis->NVRAM.VarOpBuf.uuid, pThis->NVRAM.VarOpBuf.szName));
    564         RT_ZERO(pThis->NVRAM.VarOpBuf.szName);
    565         pThis->NVRAM.VarOpBuf.fAttributes = 0;
    566         pThis->NVRAM.VarOpBuf.cbValue     = 0;
    567         pThis->NVRAM.VarOpBuf.cchName     = 0;
    568         pThis->NVRAM.pCurVar              = NULL;
    569         pThis->NVRAM.u32Status            = EFI_VARIABLE_OP_STATUS_NOT_FOUND;
     619                     &pThisCC->NVRAM.VarOpBuf.uuid, pThisCC->NVRAM.VarOpBuf.szName));
     620        RT_ZERO(pThisCC->NVRAM.VarOpBuf.szName);
     621        pThisCC->NVRAM.VarOpBuf.fAttributes = 0;
     622        pThisCC->NVRAM.VarOpBuf.cbValue     = 0;
     623        pThisCC->NVRAM.VarOpBuf.cchName     = 0;
     624        pThisCC->NVRAM.pCurVar              = NULL;
     625        pThisCC->NVRAM.u32Status            = EFI_VARIABLE_OP_STATUS_NOT_FOUND;
    570626    }
    571627}
     
    575631 *
    576632 * @returns IOM strict status code.
    577  * @param   pThis               The EFI state.
    578  */
    579 static int nvramWriteVariableOpQuery(PDEVEFI pThis)
    580 {
    581     Log(("EFI_VARIABLE_OP_QUERY: %RTuuid::'%s'\n", &pThis->NVRAM.VarOpBuf.uuid, pThis->NVRAM.VarOpBuf.szName));
     633 * @param   pThisCC             The EFI state for the current context.
     634 */
     635static int nvramWriteVariableOpQuery(PDEVEFIR3 pThisCC)
     636{
     637    Log(("EFI_VARIABLE_OP_QUERY: %RTuuid::'%s'\n", &pThisCC->NVRAM.VarOpBuf.uuid, pThisCC->NVRAM.VarOpBuf.szName));
    582638
    583639    PEFIVAR pEfiVar;
    584     int rc = nvramLookupVariableByUuidAndName(pThis,
    585                                               pThis->NVRAM.VarOpBuf.szName,
    586                                               &pThis->NVRAM.VarOpBuf.uuid,
     640    int rc = nvramLookupVariableByUuidAndName(pThisCC,
     641                                              pThisCC->NVRAM.VarOpBuf.szName,
     642                                              &pThisCC->NVRAM.VarOpBuf.uuid,
    587643                                              &pEfiVar);
    588     nvramWriteVariableOpQueryCopyResult(pThis, RT_SUCCESS(rc) ? pEfiVar : NULL, false /*fEnumQuery*/);
     644    nvramWriteVariableOpQueryCopyResult(pThisCC, RT_SUCCESS(rc) ? pEfiVar : NULL, false /*fEnumQuery*/);
    589645    return VINF_SUCCESS;
    590646}
     
    596652 *
    597653 * @returns IOM strict status code.
    598  * @param   pThis               The EFI state.
    599  */
    600 static int nvramWriteVariableOpQueryNext(PDEVEFI pThis)
    601 {
    602     Log(("EFI_VARIABLE_OP_QUERY_NEXT: pCurVar=%p\n", pThis->NVRAM.pCurVar));
    603     PEFIVAR pEfiVar = pThis->NVRAM.pCurVar;
     654 * @param   pThisCC             The EFI state for the current context.
     655 */
     656static int nvramWriteVariableOpQueryNext(PDEVEFIR3 pThisCC)
     657{
     658    Log(("EFI_VARIABLE_OP_QUERY_NEXT: pCurVar=%p\n", pThisCC->NVRAM.pCurVar));
     659    PEFIVAR pEfiVar = pThisCC->NVRAM.pCurVar;
    604660    if (pEfiVar)
    605         pEfiVar = RTListGetNext(&pThis->NVRAM.VarList, pEfiVar, EFIVAR, ListNode);
     661        pEfiVar = RTListGetNext(&pThisCC->NVRAM.VarList, pEfiVar, EFIVAR, ListNode);
    606662    else
    607         pEfiVar = RTListGetFirst(&pThis->NVRAM.VarList, EFIVAR, ListNode);
    608     nvramWriteVariableOpQueryCopyResult(pThis, pEfiVar, true /* fEnumQuery */);
     663        pEfiVar = RTListGetFirst(&pThisCC->NVRAM.VarList, EFIVAR, ListNode);
     664    nvramWriteVariableOpQueryCopyResult(pThisCC, pEfiVar, true /* fEnumQuery */);
    609665    return VINF_SUCCESS;
    610666}
     
    614670 *
    615671 * @returns IOM strict status code.
    616  * @param   pThis               The EFI state.
    617  */
    618 static int nvramWriteVariableOpAdd(PDEVEFI pThis)
     672 * @param   pThisCC             The EFI state for the current context.
     673 */
     674static int nvramWriteVariableOpAdd(PDEVEFIR3 pThisCC)
    619675{
    620676    Log(("EFI_VARIABLE_OP_ADD: %RTuuid::'%s' fAttributes=%#x abValue=%.*Rhxs\n",
    621          &pThis->NVRAM.VarOpBuf.uuid, pThis->NVRAM.VarOpBuf.szName, pThis->NVRAM.VarOpBuf.fAttributes,
    622          pThis->NVRAM.VarOpBuf.cbValue, pThis->NVRAM.VarOpBuf.abValue));
     677         &pThisCC->NVRAM.VarOpBuf.uuid, pThisCC->NVRAM.VarOpBuf.szName, pThisCC->NVRAM.VarOpBuf.fAttributes,
     678         pThisCC->NVRAM.VarOpBuf.cbValue, pThisCC->NVRAM.VarOpBuf.abValue));
    623679
    624680    /*
    625681     * Validate and adjust the input a little before we start.
    626682     */
    627     int rc = RTStrValidateEncoding(pThis->NVRAM.VarOpBuf.szName);
     683    int rc = RTStrValidateEncoding(pThisCC->NVRAM.VarOpBuf.szName);
    628684    if (RT_FAILURE(rc))
    629         LogRel(("EFI: Badly encoded variable name: %.*Rhxs\n", pThis->NVRAM.VarOpBuf.cchName + 1, pThis->NVRAM.VarOpBuf.szName));
     685        LogRel(("EFI: Badly encoded variable name: %.*Rhxs\n", pThisCC->NVRAM.VarOpBuf.cchName + 1, pThisCC->NVRAM.VarOpBuf.szName));
    630686    if (RT_FAILURE(rc))
    631687    {
    632         pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
     688        pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
    633689        return VINF_SUCCESS;
    634690    }
    635     pThis->NVRAM.VarOpBuf.cchName = (uint32_t)RTStrNLen(pThis->NVRAM.VarOpBuf.szName, sizeof(pThis->NVRAM.VarOpBuf.szName));
     691    pThisCC->NVRAM.VarOpBuf.cchName = (uint32_t)RTStrNLen(pThisCC->NVRAM.VarOpBuf.szName, sizeof(pThisCC->NVRAM.VarOpBuf.szName));
    636692
    637693    /*
     
    639695     */
    640696    PEFIVAR pEfiVar;
    641     rc = nvramLookupVariableByUuidAndName(pThis,
    642                                           pThis->NVRAM.VarOpBuf.szName,
    643                                           &pThis->NVRAM.VarOpBuf.uuid,
     697    rc = nvramLookupVariableByUuidAndName(pThisCC,
     698                                          pThisCC->NVRAM.VarOpBuf.szName,
     699                                          &pThisCC->NVRAM.VarOpBuf.uuid,
    644700                                          &pEfiVar);
    645701    if (RT_SUCCESS(rc))
     
    649705        if (pEfiVar->fAttributes & EFI_VARIABLE_XXXXXXX)
    650706        {
    651             pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_RO;
     707            pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_RO;
    652708            break;
    653709        }
    654710#endif
    655711
    656         if (pThis->NVRAM.VarOpBuf.cbValue == 0)
     712        if (pThisCC->NVRAM.VarOpBuf.cbValue == 0)
    657713        {
    658714            /*
    659715             * Delete it.
    660716             */
    661             LogRel(("EFI: Deleting variable %RTuuid::'%s'\n", &pThis->NVRAM.VarOpBuf.uuid, pThis->NVRAM.VarOpBuf.szName));
     717            LogRel(("EFI: Deleting variable %RTuuid::'%s'\n", &pThisCC->NVRAM.VarOpBuf.uuid, pThisCC->NVRAM.VarOpBuf.szName));
    662718            RTListNodeRemove(&pEfiVar->ListNode);
    663             pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_OK;
    664             pThis->NVRAM.cVariables--;
    665 
    666             if (pThis->NVRAM.pCurVar == pEfiVar)
    667                 pThis->NVRAM.pCurVar = NULL;
     719            pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_OK;
     720            pThisCC->NVRAM.cVariables--;
     721
     722            if (pThisCC->NVRAM.pCurVar == pEfiVar)
     723                pThisCC->NVRAM.pCurVar = NULL;
    668724            RTMemFree(pEfiVar);
    669725            pEfiVar = NULL;
     
    674730             * Update/replace it. (The name and UUID are unchanged, of course.)
    675731             */
    676             LogRel(("EFI: Replacing variable %RTuuid::'%s' fAttrib=%#x cbValue=%#x\n", &pThis->NVRAM.VarOpBuf.uuid,
    677                     pThis->NVRAM.VarOpBuf.szName, pThis->NVRAM.VarOpBuf.fAttributes, pThis->NVRAM.VarOpBuf.cbValue));
    678             pEfiVar->fAttributes   = pThis->NVRAM.VarOpBuf.fAttributes;
    679             pEfiVar->cbValue       = pThis->NVRAM.VarOpBuf.cbValue;
    680             memcpy(pEfiVar->abValue, pThis->NVRAM.VarOpBuf.abValue, pEfiVar->cbValue);
    681             pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_OK;
     732            LogRel(("EFI: Replacing variable %RTuuid::'%s' fAttrib=%#x cbValue=%#x\n", &pThisCC->NVRAM.VarOpBuf.uuid,
     733                    pThisCC->NVRAM.VarOpBuf.szName, pThisCC->NVRAM.VarOpBuf.fAttributes, pThisCC->NVRAM.VarOpBuf.cbValue));
     734            pEfiVar->fAttributes   = pThisCC->NVRAM.VarOpBuf.fAttributes;
     735            pEfiVar->cbValue       = pThisCC->NVRAM.VarOpBuf.cbValue;
     736            memcpy(pEfiVar->abValue, pThisCC->NVRAM.VarOpBuf.abValue, pEfiVar->cbValue);
     737            pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_OK;
    682738        }
    683739    }
    684     else if (pThis->NVRAM.VarOpBuf.cbValue == 0)
     740    else if (pThisCC->NVRAM.VarOpBuf.cbValue == 0)
    685741    {
    686742        /* delete operation, but nothing to delete. */
    687743        LogFlow(("nvramWriteVariableOpAdd: Delete (not found)\n"));
    688         pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_OK;
    689     }
    690     else if (pThis->NVRAM.cVariables < EFI_VARIABLE_MAX)
     744        pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_OK;
     745    }
     746    else if (pThisCC->NVRAM.cVariables < EFI_VARIABLE_MAX)
    691747    {
    692748        /*
    693749         * Add a new variable.
    694750         */
    695         LogRel(("EFI: Adding variable %RTuuid::'%s' fAttrib=%#x cbValue=%#x\n", &pThis->NVRAM.VarOpBuf.uuid,
    696                 pThis->NVRAM.VarOpBuf.szName, pThis->NVRAM.VarOpBuf.fAttributes, pThis->NVRAM.VarOpBuf.cbValue));
     751        LogRel(("EFI: Adding variable %RTuuid::'%s' fAttrib=%#x cbValue=%#x\n", &pThisCC->NVRAM.VarOpBuf.uuid,
     752                pThisCC->NVRAM.VarOpBuf.szName, pThisCC->NVRAM.VarOpBuf.fAttributes, pThisCC->NVRAM.VarOpBuf.cbValue));
    697753        pEfiVar = (PEFIVAR)RTMemAllocZ(sizeof(EFIVAR));
    698754        if (pEfiVar)
    699755        {
    700             pEfiVar->uuid          = pThis->NVRAM.VarOpBuf.uuid;
    701             pEfiVar->cchName       = pThis->NVRAM.VarOpBuf.cchName;
    702             memcpy(pEfiVar->szName, pThis->NVRAM.VarOpBuf.szName, pEfiVar->cchName); /* The buffer is zeroed, so skip '\0'. */
    703             pEfiVar->fAttributes   = pThis->NVRAM.VarOpBuf.fAttributes;
    704             pEfiVar->cbValue       = pThis->NVRAM.VarOpBuf.cbValue;
    705             memcpy(pEfiVar->abValue, pThis->NVRAM.VarOpBuf.abValue, pEfiVar->cbValue);
    706 
    707             nvramInsertVariable(pThis, pEfiVar);
    708             pThis->NVRAM.cVariables++;
    709             pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_OK;
     756            pEfiVar->uuid          = pThisCC->NVRAM.VarOpBuf.uuid;
     757            pEfiVar->cchName       = pThisCC->NVRAM.VarOpBuf.cchName;
     758            memcpy(pEfiVar->szName, pThisCC->NVRAM.VarOpBuf.szName, pEfiVar->cchName); /* The buffer is zeroed, so skip '\0'. */
     759            pEfiVar->fAttributes   = pThisCC->NVRAM.VarOpBuf.fAttributes;
     760            pEfiVar->cbValue       = pThisCC->NVRAM.VarOpBuf.cbValue;
     761            memcpy(pEfiVar->abValue, pThisCC->NVRAM.VarOpBuf.abValue, pEfiVar->cbValue);
     762
     763            nvramInsertVariable(pThisCC, pEfiVar);
     764            pThisCC->NVRAM.cVariables++;
     765            pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_OK;
    710766        }
    711767        else
    712             pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
     768            pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
    713769    }
    714770    else
     
    717773         * Too many variables.
    718774         */
    719         LogRelMax(5, ("EFI: Too many variables (%RTuuid::'%s' fAttrib=%#x cbValue=%#x)\n", &pThis->NVRAM.VarOpBuf.uuid,
    720                   pThis->NVRAM.VarOpBuf.szName, pThis->NVRAM.VarOpBuf.fAttributes, pThis->NVRAM.VarOpBuf.cbValue));
    721         pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
     775        LogRelMax(5, ("EFI: Too many variables (%RTuuid::'%s' fAttrib=%#x cbValue=%#x)\n", &pThisCC->NVRAM.VarOpBuf.uuid,
     776                  pThisCC->NVRAM.VarOpBuf.szName, pThisCC->NVRAM.VarOpBuf.fAttributes, pThisCC->NVRAM.VarOpBuf.cbValue));
     777        pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
    722778        Log(("nvramWriteVariableOpAdd: Too many variabled.\n"));
    723779    }
     
    726782     * Log the value of bugcheck variables.
    727783     */
    728     if (   (   pThis->NVRAM.VarOpBuf.cbValue == 4
    729             || pThis->NVRAM.VarOpBuf.cbValue == 8)
    730         && (   strcmp(pThis->NVRAM.VarOpBuf.szName, "BugCheckCode") == 0
    731             || strcmp(pThis->NVRAM.VarOpBuf.szName, "BugCheckParameter0") == 0
    732             || strcmp(pThis->NVRAM.VarOpBuf.szName, "BugCheckParameter1") == 0
    733             || strcmp(pThis->NVRAM.VarOpBuf.szName, "BugCheckParameter2") == 0
    734             || strcmp(pThis->NVRAM.VarOpBuf.szName, "BugCheckParameter3") == 0
    735             || strcmp(pThis->NVRAM.VarOpBuf.szName, "BugCheckProgress")   == 0 ) )
    736     {
    737         if (pThis->NVRAM.VarOpBuf.cbValue == 4)
    738             LogRel(("EFI: %RTuuid::'%s' = %#010RX32\n", &pThis->NVRAM.VarOpBuf.uuid, pThis->NVRAM.VarOpBuf.szName,
    739                     RT_MAKE_U32_FROM_U8(pThis->NVRAM.VarOpBuf.abValue[0], pThis->NVRAM.VarOpBuf.abValue[1],
    740                                         pThis->NVRAM.VarOpBuf.abValue[2], pThis->NVRAM.VarOpBuf.abValue[3])));
     784    if (   (   pThisCC->NVRAM.VarOpBuf.cbValue == 4
     785            || pThisCC->NVRAM.VarOpBuf.cbValue == 8)
     786        && (   strcmp(pThisCC->NVRAM.VarOpBuf.szName, "BugCheckCode") == 0
     787            || strcmp(pThisCC->NVRAM.VarOpBuf.szName, "BugCheckParameter0") == 0
     788            || strcmp(pThisCC->NVRAM.VarOpBuf.szName, "BugCheckParameter1") == 0
     789            || strcmp(pThisCC->NVRAM.VarOpBuf.szName, "BugCheckParameter2") == 0
     790            || strcmp(pThisCC->NVRAM.VarOpBuf.szName, "BugCheckParameter3") == 0
     791            || strcmp(pThisCC->NVRAM.VarOpBuf.szName, "BugCheckProgress")   == 0 ) )
     792    {
     793        if (pThisCC->NVRAM.VarOpBuf.cbValue == 4)
     794            LogRel(("EFI: %RTuuid::'%s' = %#010RX32\n", &pThisCC->NVRAM.VarOpBuf.uuid, pThisCC->NVRAM.VarOpBuf.szName,
     795                    RT_MAKE_U32_FROM_U8(pThisCC->NVRAM.VarOpBuf.abValue[0], pThisCC->NVRAM.VarOpBuf.abValue[1],
     796                                        pThisCC->NVRAM.VarOpBuf.abValue[2], pThisCC->NVRAM.VarOpBuf.abValue[3])));
    741797        else
    742             LogRel(("EFI: %RTuuid::'%s' = %#018RX64\n", &pThis->NVRAM.VarOpBuf.uuid, pThis->NVRAM.VarOpBuf.szName,
    743                     RT_MAKE_U64_FROM_U8(pThis->NVRAM.VarOpBuf.abValue[0], pThis->NVRAM.VarOpBuf.abValue[1],
    744                                         pThis->NVRAM.VarOpBuf.abValue[2], pThis->NVRAM.VarOpBuf.abValue[3],
    745                                         pThis->NVRAM.VarOpBuf.abValue[4], pThis->NVRAM.VarOpBuf.abValue[5],
    746                                         pThis->NVRAM.VarOpBuf.abValue[6], pThis->NVRAM.VarOpBuf.abValue[7])));
    747     }
    748 
    749 
    750     LogFunc(("cVariables=%u u32Status=%#x\n", pThis->NVRAM.cVariables, pThis->NVRAM.u32Status));
     798            LogRel(("EFI: %RTuuid::'%s' = %#018RX64\n", &pThisCC->NVRAM.VarOpBuf.uuid, pThisCC->NVRAM.VarOpBuf.szName,
     799                    RT_MAKE_U64_FROM_U8(pThisCC->NVRAM.VarOpBuf.abValue[0], pThisCC->NVRAM.VarOpBuf.abValue[1],
     800                                        pThisCC->NVRAM.VarOpBuf.abValue[2], pThisCC->NVRAM.VarOpBuf.abValue[3],
     801                                        pThisCC->NVRAM.VarOpBuf.abValue[4], pThisCC->NVRAM.VarOpBuf.abValue[5],
     802                                        pThisCC->NVRAM.VarOpBuf.abValue[6], pThisCC->NVRAM.VarOpBuf.abValue[7])));
     803    }
     804
     805
     806    LogFunc(("cVariables=%u u32Status=%#x\n", pThisCC->NVRAM.cVariables, pThisCC->NVRAM.u32Status));
    751807    return VINF_SUCCESS;
    752808}
     
    756812 *
    757813 * @returns IOM strict status code.
    758  * @param   pThis               The EFI state.
     814 * @param   pThisCC             The EFI state for the current context.
    759815 * @param   u32Value            The value being written.
    760816 */
    761 static int nvramWriteVariableParam(PDEVEFI pThis, uint32_t u32Value)
     817static int nvramWriteVariableParam(PDEVEFIR3 pThisCC, uint32_t u32Value)
    762818{
    763819    int rc = VINF_SUCCESS;
    764     switch (pThis->NVRAM.enmOp)
     820    switch (pThisCC->NVRAM.enmOp)
    765821    {
    766822        case EFI_VM_VARIABLE_OP_START:
     
    768824            {
    769825                case EFI_VARIABLE_OP_QUERY:
    770                     rc = nvramWriteVariableOpQuery(pThis);
     826                    rc = nvramWriteVariableOpQuery(pThisCC);
    771827                    break;
    772828
    773829                case EFI_VARIABLE_OP_QUERY_NEXT:
    774                     rc = nvramWriteVariableOpQueryNext(pThis);
     830                    rc = nvramWriteVariableOpQueryNext(pThisCC);
    775831                    break;
    776832
    777833                case EFI_VARIABLE_OP_QUERY_REWIND:
    778834                    Log2(("EFI_VARIABLE_OP_QUERY_REWIND\n"));
    779                     pThis->NVRAM.pCurVar   = NULL;
    780                     pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_OK;
     835                    pThisCC->NVRAM.pCurVar   = NULL;
     836                    pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_OK;
    781837                    break;
    782838
    783839                case EFI_VARIABLE_OP_ADD:
    784                     rc = nvramWriteVariableOpAdd(pThis);
     840                    rc = nvramWriteVariableOpAdd(pThisCC);
    785841                    break;
    786842
    787843                default:
    788                     pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
     844                    pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
    789845                    LogRel(("EFI: Unknown  EFI_VM_VARIABLE_OP_START value %#x\n", u32Value));
    790846                    break;
     
    793849
    794850        case EFI_VM_VARIABLE_OP_GUID:
    795             Log2(("EFI_VM_VARIABLE_OP_GUID[%#x]=%#x\n", pThis->NVRAM.offOpBuffer, u32Value));
    796             if (pThis->NVRAM.offOpBuffer < sizeof(pThis->NVRAM.VarOpBuf.uuid))
    797                 pThis->NVRAM.VarOpBuf.uuid.au8[pThis->NVRAM.offOpBuffer++] = (uint8_t)u32Value;
     851            Log2(("EFI_VM_VARIABLE_OP_GUID[%#x]=%#x\n", pThisCC->NVRAM.offOpBuffer, u32Value));
     852            if (pThisCC->NVRAM.offOpBuffer < sizeof(pThisCC->NVRAM.VarOpBuf.uuid))
     853                pThisCC->NVRAM.VarOpBuf.uuid.au8[pThisCC->NVRAM.offOpBuffer++] = (uint8_t)u32Value;
    798854            else
    799855            {
    800856                LogRel(("EFI: Out of bounds EFI_VM_VARIABLE_OP_GUID write (%#x).\n", u32Value));
    801                 pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
     857                pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
    802858            }
    803859            break;
     
    805861        case EFI_VM_VARIABLE_OP_ATTRIBUTE:
    806862            Log2(("EFI_VM_VARIABLE_OP_ATTRIBUTE=%#x\n", u32Value));
    807             pThis->NVRAM.VarOpBuf.fAttributes = u32Value;
     863            pThisCC->NVRAM.VarOpBuf.fAttributes = u32Value;
    808864            break;
    809865
    810866        case EFI_VM_VARIABLE_OP_NAME:
    811             Log2(("EFI_VM_VARIABLE_OP_NAME[%#x]=%#x\n", pThis->NVRAM.offOpBuffer, u32Value));
    812             if (pThis->NVRAM.offOpBuffer < pThis->NVRAM.VarOpBuf.cchName)
    813                 pThis->NVRAM.VarOpBuf.szName[pThis->NVRAM.offOpBuffer++] = (uint8_t)u32Value;
     867            Log2(("EFI_VM_VARIABLE_OP_NAME[%#x]=%#x\n", pThisCC->NVRAM.offOpBuffer, u32Value));
     868            if (pThisCC->NVRAM.offOpBuffer < pThisCC->NVRAM.VarOpBuf.cchName)
     869                pThisCC->NVRAM.VarOpBuf.szName[pThisCC->NVRAM.offOpBuffer++] = (uint8_t)u32Value;
    814870            else if (u32Value == 0)
    815                 Assert(pThis->NVRAM.VarOpBuf.szName[sizeof(pThis->NVRAM.VarOpBuf.szName) - 1] == 0);
     871                Assert(pThisCC->NVRAM.VarOpBuf.szName[sizeof(pThisCC->NVRAM.VarOpBuf.szName) - 1] == 0);
    816872            else
    817873            {
    818874                LogRel(("EFI: Out of bounds EFI_VM_VARIABLE_OP_NAME write (%#x).\n", u32Value));
    819                 pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
     875                pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
    820876            }
    821877            break;
     
    823879        case EFI_VM_VARIABLE_OP_NAME_LENGTH:
    824880            Log2(("EFI_VM_VARIABLE_OP_NAME_LENGTH=%#x\n", u32Value));
    825             RT_ZERO(pThis->NVRAM.VarOpBuf.szName);
    826             if (u32Value < sizeof(pThis->NVRAM.VarOpBuf.szName))
    827                 pThis->NVRAM.VarOpBuf.cchName = u32Value;
     881            RT_ZERO(pThisCC->NVRAM.VarOpBuf.szName);
     882            if (u32Value < sizeof(pThisCC->NVRAM.VarOpBuf.szName))
     883                pThisCC->NVRAM.VarOpBuf.cchName = u32Value;
    828884            else
    829885            {
    830886                LogRel(("EFI: Out of bounds EFI_VM_VARIABLE_OP_NAME_LENGTH write (%#x, max %#x).\n",
    831                         u32Value, sizeof(pThis->NVRAM.VarOpBuf.szName) - 1));
    832                 pThis->NVRAM.VarOpBuf.cchName = sizeof(pThis->NVRAM.VarOpBuf.szName) - 1;
    833                 pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
     887                        u32Value, sizeof(pThisCC->NVRAM.VarOpBuf.szName) - 1));
     888                pThisCC->NVRAM.VarOpBuf.cchName = sizeof(pThisCC->NVRAM.VarOpBuf.szName) - 1;
     889                pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
    834890            }
    835             Assert(pThis->NVRAM.offOpBuffer == 0);
     891            Assert(pThisCC->NVRAM.offOpBuffer == 0);
    836892            break;
    837893
    838894        case EFI_VM_VARIABLE_OP_NAME_UTF16:
    839895        {
    840             Log2(("EFI_VM_VARIABLE_OP_NAME_UTF16[%#x]=%#x\n", pThis->NVRAM.offOpBuffer, u32Value));
     896            Log2(("EFI_VM_VARIABLE_OP_NAME_UTF16[%#x]=%#x\n", pThisCC->NVRAM.offOpBuffer, u32Value));
    841897            /* Currently simplifying this to UCS2, i.e. no surrogates. */
    842             if (pThis->NVRAM.offOpBuffer == 0)
    843                 RT_ZERO(pThis->NVRAM.VarOpBuf.szName);
     898            if (pThisCC->NVRAM.offOpBuffer == 0)
     899                RT_ZERO(pThisCC->NVRAM.VarOpBuf.szName);
    844900            uint32_t cbUtf8 = (uint32_t)RTStrCpSize(u32Value);
    845             if (pThis->NVRAM.offOpBuffer + cbUtf8 < sizeof(pThis->NVRAM.VarOpBuf.szName))
     901            if (pThisCC->NVRAM.offOpBuffer + cbUtf8 < sizeof(pThisCC->NVRAM.VarOpBuf.szName))
    846902            {
    847                 RTStrPutCp(&pThis->NVRAM.VarOpBuf.szName[pThis->NVRAM.offOpBuffer], u32Value);
    848                 pThis->NVRAM.offOpBuffer += cbUtf8;
     903                RTStrPutCp(&pThisCC->NVRAM.VarOpBuf.szName[pThisCC->NVRAM.offOpBuffer], u32Value);
     904                pThisCC->NVRAM.offOpBuffer += cbUtf8;
    849905            }
    850906            else if (u32Value == 0)
    851                 Assert(pThis->NVRAM.VarOpBuf.szName[sizeof(pThis->NVRAM.VarOpBuf.szName) - 1] == 0);
     907                Assert(pThisCC->NVRAM.VarOpBuf.szName[sizeof(pThisCC->NVRAM.VarOpBuf.szName) - 1] == 0);
    852908            else
    853909            {
    854910                LogRel(("EFI: Out of bounds EFI_VM_VARIABLE_OP_NAME_UTF16 write (%#x).\n", u32Value));
    855                 pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
     911                pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
    856912            }
    857913            break;
     
    859915
    860916        case EFI_VM_VARIABLE_OP_VALUE:
    861             Log2(("EFI_VM_VARIABLE_OP_VALUE[%#x]=%#x\n", pThis->NVRAM.offOpBuffer, u32Value));
    862             if (pThis->NVRAM.offOpBuffer < pThis->NVRAM.VarOpBuf.cbValue)
    863                 pThis->NVRAM.VarOpBuf.abValue[pThis->NVRAM.offOpBuffer++] = (uint8_t)u32Value;
     917            Log2(("EFI_VM_VARIABLE_OP_VALUE[%#x]=%#x\n", pThisCC->NVRAM.offOpBuffer, u32Value));
     918            if (pThisCC->NVRAM.offOpBuffer < pThisCC->NVRAM.VarOpBuf.cbValue)
     919                pThisCC->NVRAM.VarOpBuf.abValue[pThisCC->NVRAM.offOpBuffer++] = (uint8_t)u32Value;
    864920            else
    865921            {
    866922                LogRel(("EFI: Out of bounds EFI_VM_VARIABLE_OP_VALUE write (%#x).\n", u32Value));
    867                 pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
     923                pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
    868924            }
    869925            break;
     
    871927        case EFI_VM_VARIABLE_OP_VALUE_LENGTH:
    872928            Log2(("EFI_VM_VARIABLE_OP_VALUE_LENGTH=%#x\n", u32Value));
    873             RT_ZERO(pThis->NVRAM.VarOpBuf.abValue);
    874             if (u32Value <= sizeof(pThis->NVRAM.VarOpBuf.abValue))
    875                 pThis->NVRAM.VarOpBuf.cbValue = u32Value;
     929            RT_ZERO(pThisCC->NVRAM.VarOpBuf.abValue);
     930            if (u32Value <= sizeof(pThisCC->NVRAM.VarOpBuf.abValue))
     931                pThisCC->NVRAM.VarOpBuf.cbValue = u32Value;
    876932            else
    877933            {
    878934                LogRel(("EFI: Out of bounds EFI_VM_VARIABLE_OP_VALUE_LENGTH write (%#x, max %#x).\n",
    879                         u32Value, sizeof(pThis->NVRAM.VarOpBuf.abValue)));
    880                 pThis->NVRAM.VarOpBuf.cbValue = sizeof(pThis->NVRAM.VarOpBuf.abValue);
    881                 pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
     935                        u32Value, sizeof(pThisCC->NVRAM.VarOpBuf.abValue)));
     936                pThisCC->NVRAM.VarOpBuf.cbValue = sizeof(pThisCC->NVRAM.VarOpBuf.abValue);
     937                pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
    882938            }
    883             Assert(pThis->NVRAM.offOpBuffer == 0);
     939            Assert(pThisCC->NVRAM.offOpBuffer == 0);
    884940            break;
    885941
    886942        default:
    887             pThis->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
    888             LogRel(("EFI: Unexpected variable operation %#x\n", pThis->NVRAM.enmOp));
     943            pThisCC->NVRAM.u32Status = EFI_VARIABLE_OP_STATUS_ERROR;
     944            LogRel(("EFI: Unexpected variable operation %#x\n", pThisCC->NVRAM.enmOp));
    889945            break;
    890946    }
     
    896952 *
    897953 * @returns IOM strict status code.
    898  * @param   pThis               The EFI state.
     954 * @param   pThisCC             The EFI state for the current context.
    899955 * @param   u32Value            The value being written.
    900956 */
    901 static int nvramReadVariableOp(PDEVEFI pThis,  uint32_t *pu32, unsigned cb)
    902 {
    903     switch (pThis->NVRAM.enmOp)
     957static int nvramReadVariableOp(PDEVEFIR3 pThisCC,  uint32_t *pu32, unsigned cb)
     958{
     959    switch (pThisCC->NVRAM.enmOp)
    904960    {
    905961        case EFI_VM_VARIABLE_OP_START:
    906             *pu32 = pThis->NVRAM.u32Status;
     962            *pu32 = pThisCC->NVRAM.u32Status;
    907963            break;
    908964
    909965        case EFI_VM_VARIABLE_OP_GUID:
    910             if (pThis->NVRAM.offOpBuffer < sizeof(pThis->NVRAM.VarOpBuf.uuid) && cb == 1)
    911                 *pu32 = pThis->NVRAM.VarOpBuf.uuid.au8[pThis->NVRAM.offOpBuffer++];
     966            if (pThisCC->NVRAM.offOpBuffer < sizeof(pThisCC->NVRAM.VarOpBuf.uuid) && cb == 1)
     967                *pu32 = pThisCC->NVRAM.VarOpBuf.uuid.au8[pThisCC->NVRAM.offOpBuffer++];
    912968            else
    913969            {
     
    921977
    922978        case EFI_VM_VARIABLE_OP_ATTRIBUTE:
    923             *pu32 = pThis->NVRAM.VarOpBuf.fAttributes;
     979            *pu32 = pThisCC->NVRAM.VarOpBuf.fAttributes;
    924980            break;
    925981
    926982        case EFI_VM_VARIABLE_OP_NAME:
    927983            /* allow reading terminator char */
    928             if (pThis->NVRAM.offOpBuffer <= pThis->NVRAM.VarOpBuf.cchName && cb == 1)
    929                 *pu32 = pThis->NVRAM.VarOpBuf.szName[pThis->NVRAM.offOpBuffer++];
     984            if (pThisCC->NVRAM.offOpBuffer <= pThisCC->NVRAM.VarOpBuf.cchName && cb == 1)
     985                *pu32 = pThisCC->NVRAM.VarOpBuf.szName[pThisCC->NVRAM.offOpBuffer++];
    930986            else
    931987            {
     
    939995
    940996        case EFI_VM_VARIABLE_OP_NAME_LENGTH:
    941             *pu32 = pThis->NVRAM.VarOpBuf.cchName;
     997            *pu32 = pThisCC->NVRAM.VarOpBuf.cchName;
    942998            break;
    943999
    9441000        case EFI_VM_VARIABLE_OP_NAME_UTF16:
    9451001            /* Lazy bird: ASSUME no surrogate pairs. */
    946             if (pThis->NVRAM.offOpBuffer <= pThis->NVRAM.VarOpBuf.cchName && cb == 2)
     1002            if (pThisCC->NVRAM.offOpBuffer <= pThisCC->NVRAM.VarOpBuf.cchName && cb == 2)
    9471003            {
    948                 char const *psz1 = &pThis->NVRAM.VarOpBuf.szName[pThis->NVRAM.offOpBuffer];
     1004                char const *psz1 = &pThisCC->NVRAM.VarOpBuf.szName[pThisCC->NVRAM.offOpBuffer];
    9491005                char const *psz2 = psz1;
    9501006                RTUNICP Cp;
    9511007                RTStrGetCpEx(&psz2, &Cp);
    9521008                *pu32 = Cp;
    953                 Log2(("EFI_VM_VARIABLE_OP_NAME_UTF16[%u] => %#x (+%d)\n", pThis->NVRAM.offOpBuffer, *pu32, psz2 - psz1));
    954                 pThis->NVRAM.offOpBuffer += psz2 - psz1;
     1009                Log2(("EFI_VM_VARIABLE_OP_NAME_UTF16[%u] => %#x (+%d)\n", pThisCC->NVRAM.offOpBuffer, *pu32, psz2 - psz1));
     1010                pThisCC->NVRAM.offOpBuffer += psz2 - psz1;
    9551011            }
    9561012            else
     
    9661022        case EFI_VM_VARIABLE_OP_NAME_LENGTH_UTF16:
    9671023            /* Lazy bird: ASSUME no surrogate pairs. */
    968             *pu32 = (uint32_t)RTStrUniLen(pThis->NVRAM.VarOpBuf.szName);
     1024            *pu32 = (uint32_t)RTStrUniLen(pThisCC->NVRAM.VarOpBuf.szName);
    9691025            break;
    9701026
    9711027        case EFI_VM_VARIABLE_OP_VALUE:
    972             if (pThis->NVRAM.offOpBuffer < pThis->NVRAM.VarOpBuf.cbValue && cb == 1)
    973                 *pu32 = pThis->NVRAM.VarOpBuf.abValue[pThis->NVRAM.offOpBuffer++];
     1028            if (pThisCC->NVRAM.offOpBuffer < pThisCC->NVRAM.VarOpBuf.cbValue && cb == 1)
     1029                *pu32 = pThisCC->NVRAM.VarOpBuf.abValue[pThisCC->NVRAM.offOpBuffer++];
    9741030            else
    9751031            {
     
    9831039
    9841040        case EFI_VM_VARIABLE_OP_VALUE_LENGTH:
    985             *pu32 = pThis->NVRAM.VarOpBuf.cbValue;
     1041            *pu32 = pThisCC->NVRAM.VarOpBuf.cbValue;
    9861042            break;
    9871043
     
    10811137{
    10821138    RT_NOREF(pszArgs);
    1083     PDEVEFI pThis = PDMINS_2_DATA(pDevIns, PDEVEFI);
    1084     PDMCritSectEnter(pDevIns->pCritSectRoR3, VERR_IGNORED);
    1085 
    1086     pHlp->pfnPrintf(pHlp, "NVRAM variables: %u\n", pThis->NVRAM.cVariables);
     1139    PDEVEFIR3 pThisCC = PDMINS_2_DATA_CC(pDevIns, PDEVEFIR3);
     1140    PDMDevHlpCritSectEnter(pDevIns, pDevIns->pCritSectRoR3, VERR_IGNORED);
     1141
     1142    pHlp->pfnPrintf(pHlp, "NVRAM variables: %u\n", pThisCC->NVRAM.cVariables);
    10871143    PCEFIVAR pEfiVar;
    1088     RTListForEach(&pThis->NVRAM.VarList, pEfiVar, EFIVAR, ListNode)
     1144    RTListForEach(&pThisCC->NVRAM.VarList, pEfiVar, EFIVAR, ListNode)
    10891145    {
    10901146        /* Detect UTF-8 and UTF-16 strings. */
     
    11111167    }
    11121168
    1113     PDMCritSectLeave(pDevIns->pCritSectRoR3);
     1169    PDMDevHlpCritSectLeave(pDevIns, pDevIns->pCritSectRoR3);
    11141170}
    11151171
     
    11201176 *
    11211177 * @returns Size in bytes, UINT32_MAX on error.
    1122  * @param   pThis               .
    1123  */
    1124 static uint32_t efiInfoSize(PDEVEFI pThis)
    1125 {
    1126     switch (pThis->iInfoSelector)
     1178 * @param   pThisCC             The EFI state for the current context.
     1179 */
     1180static uint32_t efiInfoSize(PDEVEFIR3 pThisCC)
     1181{
     1182    switch (pThisCC->iInfoSelector)
    11271183    {
    11281184        case EFI_INFO_INDEX_VOLUME_BASE:
     
    11371193            return 4;
    11381194        case EFI_INFO_INDEX_BOOT_ARGS:
    1139             return (uint32_t)RTStrNLen(pThis->szBootArgs, sizeof(pThis->szBootArgs)) + 1;
     1195            return (uint32_t)RTStrNLen(pThisCC->szBootArgs, sizeof(pThisCC->szBootArgs)) + 1;
    11401196        case EFI_INFO_INDEX_DEVICE_PROPS:
    1141             return pThis->cbDeviceProps;
     1197            return pThisCC->cbDeviceProps;
    11421198        case EFI_INFO_INDEX_FSB_FREQUENCY:
    11431199        case EFI_INFO_INDEX_CPU_FREQUENCY:
     
    11551211 *
    11561212 * @returns Next (current) byte.
    1157  * @param   pThis               The EFI instance data.
     1213 * @param   pThisCC             The EFI state for the current context.
    11581214 * @param   u64                 The value.
    11591215 */
    1160 static uint8_t efiInfoNextByteU64(PDEVEFI pThis, uint64_t u64)
    1161 {
    1162     uint64_t off = pThis->offInfo;
     1216static uint8_t efiInfoNextByteU64(PDEVEFIR3 pThisCC, uint64_t u64)
     1217{
     1218    uint64_t off = pThisCC->offInfo;
    11631219    if (off >= 8)
    11641220        return 0;
     
    11701226 *
    11711227 * @returns Next (current) byte.
    1172  * @param   pThis               The EFI instance data.
     1228 * @param   pThisCC             The EFI state for the current context.
    11731229 * @param   u32                 The value.
    11741230 */
    1175 static uint8_t efiInfoNextByteU32(PDEVEFI pThis, uint32_t u32)
    1176 {
    1177     uint32_t off = pThis->offInfo;
     1231static uint8_t efiInfoNextByteU32(PDEVEFIR3 pThisCC, uint32_t u32)
     1232{
     1233    uint32_t off = pThisCC->offInfo;
    11781234    if (off >= 4)
    11791235        return 0;
     
    11851241 *
    11861242 * @returns Next (current) byte.
    1187  * @param   pThis               The EFI instance data.
     1243 * @param   pThisCC             The EFI state for the current context.
    11881244 * @param   pvBuf               The buffer.
    11891245 * @param   cbBuf               The buffer size.
    11901246 */
    1191 static uint8_t efiInfoNextByteBuf(PDEVEFI pThis, void const *pvBuf, size_t cbBuf)
    1192 {
    1193     uint32_t off = pThis->offInfo;
     1247static uint8_t efiInfoNextByteBuf(PDEVEFIR3 pThisCC, void const *pvBuf, size_t cbBuf)
     1248{
     1249    uint32_t off = pThisCC->offInfo;
    11941250    if (off >= cbBuf)
    11951251        return 0;
     
    12011257 *
    12021258 * @returns Next (current) byte.
    1203  * @param   pThis               The EFI instance data.
    1204  */
    1205 static uint8_t efiInfoNextByte(PDEVEFI pThis)
    1206 {
    1207     switch (pThis->iInfoSelector)
    1208     {
    1209 
    1210         case EFI_INFO_INDEX_VOLUME_BASE:        return efiInfoNextByteU64(pThis, pThis->GCLoadAddress);
    1211         case EFI_INFO_INDEX_VOLUME_SIZE:        return efiInfoNextByteU64(pThis, pThis->cbEfiRom);
    1212         case EFI_INFO_INDEX_TEMPMEM_BASE:       return efiInfoNextByteU32(pThis, VBOX_EFI_TOP_OF_STACK); /* just after stack */
    1213         case EFI_INFO_INDEX_TEMPMEM_SIZE:       return efiInfoNextByteU32(pThis, _512K);
    1214         case EFI_INFO_INDEX_FSB_FREQUENCY:      return efiInfoNextByteU64(pThis, pThis->u64FsbFrequency);
    1215         case EFI_INFO_INDEX_TSC_FREQUENCY:      return efiInfoNextByteU64(pThis, pThis->u64TscFrequency);
    1216         case EFI_INFO_INDEX_CPU_FREQUENCY:      return efiInfoNextByteU64(pThis, pThis->u64CpuFrequency);
    1217         case EFI_INFO_INDEX_BOOT_ARGS:          return efiInfoNextByteBuf(pThis, pThis->szBootArgs, sizeof(pThis->szBootArgs));
    1218         case EFI_INFO_INDEX_DEVICE_PROPS:       return efiInfoNextByteBuf(pThis, pThis->pbDeviceProps, pThis->cbDeviceProps);
    1219         case EFI_INFO_INDEX_GRAPHICS_MODE:      return efiInfoNextByteU32(pThis, pThis->u32GraphicsMode);
    1220         case EFI_INFO_INDEX_HORIZONTAL_RESOLUTION:  return efiInfoNextByteU32(pThis, pThis->u32HorizontalResolution);
    1221         case EFI_INFO_INDEX_VERTICAL_RESOLUTION:    return efiInfoNextByteU32(pThis, pThis->u32VerticalResolution);
     1259 * @param   pThisCC             The EFI state for the current context.
     1260 */
     1261static uint8_t efiInfoNextByte(PDEVEFIR3 pThisCC)
     1262{
     1263    switch (pThisCC->iInfoSelector)
     1264    {
     1265
     1266        case EFI_INFO_INDEX_VOLUME_BASE:        return efiInfoNextByteU64(pThisCC, pThisCC->GCLoadAddress);
     1267        case EFI_INFO_INDEX_VOLUME_SIZE:        return efiInfoNextByteU64(pThisCC, pThisCC->cbEfiRom);
     1268        case EFI_INFO_INDEX_TEMPMEM_BASE:       return efiInfoNextByteU32(pThisCC, VBOX_EFI_TOP_OF_STACK); /* just after stack */
     1269        case EFI_INFO_INDEX_TEMPMEM_SIZE:       return efiInfoNextByteU32(pThisCC, _512K);
     1270        case EFI_INFO_INDEX_FSB_FREQUENCY:      return efiInfoNextByteU64(pThisCC, pThisCC->u64FsbFrequency);
     1271        case EFI_INFO_INDEX_TSC_FREQUENCY:      return efiInfoNextByteU64(pThisCC, pThisCC->u64TscFrequency);
     1272        case EFI_INFO_INDEX_CPU_FREQUENCY:      return efiInfoNextByteU64(pThisCC, pThisCC->u64CpuFrequency);
     1273        case EFI_INFO_INDEX_BOOT_ARGS:          return efiInfoNextByteBuf(pThisCC, pThisCC->szBootArgs, sizeof(pThisCC->szBootArgs));
     1274        case EFI_INFO_INDEX_DEVICE_PROPS:       return efiInfoNextByteBuf(pThisCC, pThisCC->pbDeviceProps, pThisCC->cbDeviceProps);
     1275        case EFI_INFO_INDEX_GRAPHICS_MODE:      return efiInfoNextByteU32(pThisCC, pThisCC->u32GraphicsMode);
     1276        case EFI_INFO_INDEX_HORIZONTAL_RESOLUTION:  return efiInfoNextByteU32(pThisCC, pThisCC->u32HorizontalResolution);
     1277        case EFI_INFO_INDEX_VERTICAL_RESOLUTION:    return efiInfoNextByteU32(pThisCC, pThisCC->u32VerticalResolution);
    12221278
    12231279        /* Keep in sync with value in EfiThunk.asm */
    1224         case EFI_INFO_INDEX_STACK_BASE:         return efiInfoNextByteU32(pThis,  VBOX_EFI_TOP_OF_STACK - _128K); /* 2M - 128 K */
    1225         case EFI_INFO_INDEX_STACK_SIZE:         return efiInfoNextByteU32(pThis, _128K);
    1226         case EFI_INFO_INDEX_MCFG_BASE:          return efiInfoNextByteU64(pThis, pThis->u64McfgBase);
    1227         case EFI_INFO_INDEX_MCFG_SIZE:          return efiInfoNextByteU64(pThis, pThis->cbMcfgLength);
     1280        case EFI_INFO_INDEX_STACK_BASE:         return efiInfoNextByteU32(pThisCC,  VBOX_EFI_TOP_OF_STACK - _128K); /* 2M - 128 K */
     1281        case EFI_INFO_INDEX_STACK_SIZE:         return efiInfoNextByteU32(pThisCC, _128K);
     1282        case EFI_INFO_INDEX_MCFG_BASE:          return efiInfoNextByteU64(pThisCC, pThisCC->u64McfgBase);
     1283        case EFI_INFO_INDEX_MCFG_SIZE:          return efiInfoNextByteU64(pThisCC, pThisCC->cbMcfgLength);
    12281284
    12291285        default:
    1230             PDMDevHlpDBGFStop(pThis->pDevIns, RT_SRC_POS, "%#x", pThis->iInfoSelector);
     1286            PDMDevHlpDBGFStop(pThisCC->pDevIns, RT_SRC_POS, "%#x", pThisCC->iInfoSelector);
    12311287            return 0;
    12321288    }
     
    12601316 * @returns VBox status suitable for I/O port write handler.
    12611317 *
    1262  * @param   pThis               The EFI state.
     1318 * @param   pThisCC             The EFI state for the current context.
    12631319 * @param   u32                 The value being written.
    12641320 * @param   cb                  The size of the value.
    12651321 */
    1266 static int efiPortImageEventWrite(PDEVEFI pThis, uint32_t u32, unsigned cb)
     1322static int efiPortImageEventWrite(PDEVEFIR3 pThisCC, uint32_t u32, unsigned cb)
    12671323{
    12681324    RT_NOREF(cb);
     
    12781334
    12791335            /* Reset the state. */
    1280             RT_ZERO(pThis->ImageEvt);
    1281             pThis->ImageEvt.uEvt = (uint8_t)u32; Assert(pThis->ImageEvt.uEvt == u32);
     1336            RT_ZERO(pThisCC->ImageEvt);
     1337            pThisCC->ImageEvt.uEvt = (uint8_t)u32; Assert(pThisCC->ImageEvt.uEvt == u32);
    12821338            return VINF_SUCCESS;
    12831339
     
    12921348            {
    12931349                s_cImageEvtLogged++;
    1294                 switch (pThis->ImageEvt.uEvt)
     1350                switch (pThisCC->ImageEvt.uEvt)
    12951351                {
    12961352                    /* ASSUMES the name ends with .pdb and the image file ends with .efi! */
    12971353                    case EFI_IMAGE_EVT_CMD_START_LOAD32:
    12981354                        LogRel(("EFI: VBoxDbg> loadimage32 '%.*s.efi' %#llx LB %#llx\n",
    1299                                 pThis->ImageEvt.offName - 4, pThis->ImageEvt.szName, pThis->ImageEvt.uAddr0, pThis->ImageEvt.cb0));
    1300                         if (pThis->ImageEvt.offName > 4)
     1355                                pThisCC->ImageEvt.offName - 4, pThisCC->ImageEvt.szName, pThisCC->ImageEvt.uAddr0, pThisCC->ImageEvt.cb0));
     1356                        if (pThisCC->ImageEvt.offName > 4)
    13011357                            efiVBoxDbgScript("loadimage32 '%.*s.efi' %#llx\n",
    1302                                              pThis->ImageEvt.offName - 4, pThis->ImageEvt.szName, pThis->ImageEvt.uAddr0);
     1358                                             pThisCC->ImageEvt.offName - 4, pThisCC->ImageEvt.szName, pThisCC->ImageEvt.uAddr0);
    13031359                        break;
    13041360                    case EFI_IMAGE_EVT_CMD_START_LOAD64:
    13051361                        LogRel(("EFI: VBoxDbg> loadimage64 '%.*s.efi' %#llx LB %#llx\n",
    1306                                 pThis->ImageEvt.offName - 4, pThis->ImageEvt.szName, pThis->ImageEvt.uAddr0, pThis->ImageEvt.cb0));
    1307                         if (pThis->ImageEvt.offName > 4)
     1362                                pThisCC->ImageEvt.offName - 4, pThisCC->ImageEvt.szName, pThisCC->ImageEvt.uAddr0, pThisCC->ImageEvt.cb0));
     1363                        if (pThisCC->ImageEvt.offName > 4)
    13081364                            efiVBoxDbgScript("loadimage64 '%.*s.efi' %#llx\n",
    1309                                              pThis->ImageEvt.offName - 4, pThis->ImageEvt.szName, pThis->ImageEvt.uAddr0);
     1365                                             pThisCC->ImageEvt.offName - 4, pThisCC->ImageEvt.szName, pThisCC->ImageEvt.uAddr0);
    13101366                        break;
    13111367                    case EFI_IMAGE_EVT_CMD_START_UNLOAD32:
     
    13131369                    {
    13141370                        LogRel(("EFI: VBoxDbg> unload '%.*s.efi' # %#llx LB %#llx\n",
    1315                                 pThis->ImageEvt.offName - 4 - pThis->ImageEvt.offNameLastComponent,
    1316                                 &pThis->ImageEvt.szName[pThis->ImageEvt.offNameLastComponent],
    1317                                 pThis->ImageEvt.uAddr0, pThis->ImageEvt.cb0));
    1318                         if (pThis->ImageEvt.offName > 4)
     1371                                pThisCC->ImageEvt.offName - 4 - pThisCC->ImageEvt.offNameLastComponent,
     1372                                &pThisCC->ImageEvt.szName[pThisCC->ImageEvt.offNameLastComponent],
     1373                                pThisCC->ImageEvt.uAddr0, pThisCC->ImageEvt.cb0));
     1374                        if (pThisCC->ImageEvt.offName > 4)
    13191375                            efiVBoxDbgScript("unload '%.*s.efi'\n",
    1320                                              pThis->ImageEvt.offName - 4 - pThis->ImageEvt.offNameLastComponent,
    1321                                              &pThis->ImageEvt.szName[pThis->ImageEvt.offNameLastComponent]);
     1376                                             pThisCC->ImageEvt.offName - 4 - pThisCC->ImageEvt.offNameLastComponent,
     1377                                             &pThisCC->ImageEvt.szName[pThisCC->ImageEvt.offNameLastComponent]);
    13221378                        break;
    13231379                    }
     
    13261382                {
    13271383                    LogRel(("EFI: relocate module to %#llx from %#llx\n",
    1328                             pThis->ImageEvt.uAddr0, pThis->ImageEvt.uAddr1));
     1384                            pThisCC->ImageEvt.uAddr0, pThisCC->ImageEvt.uAddr1));
    13291385                    break;
    13301386                }
     
    13391395        case EFI_IMAGE_EVT_CMD_ADDR0:
    13401396            AssertBreak(EFI_IMAGE_EVT_GET_PAYLOAD(u32) <= UINT16_MAX);
    1341             pThis->ImageEvt.uAddr0 <<= 16;
    1342             pThis->ImageEvt.uAddr0 |= EFI_IMAGE_EVT_GET_PAYLOAD_U16(u32);
     1397            pThisCC->ImageEvt.uAddr0 <<= 16;
     1398            pThisCC->ImageEvt.uAddr0 |= EFI_IMAGE_EVT_GET_PAYLOAD_U16(u32);
    13431399            return VINF_SUCCESS;
    13441400
    13451401        case EFI_IMAGE_EVT_CMD_ADDR1:
    13461402            AssertBreak(EFI_IMAGE_EVT_GET_PAYLOAD(u32) <= UINT16_MAX);
    1347             pThis->ImageEvt.uAddr1 <<= 16;
    1348             pThis->ImageEvt.uAddr1 |= EFI_IMAGE_EVT_GET_PAYLOAD_U16(u32);
     1403            pThisCC->ImageEvt.uAddr1 <<= 16;
     1404            pThisCC->ImageEvt.uAddr1 |= EFI_IMAGE_EVT_GET_PAYLOAD_U16(u32);
    13491405            return VINF_SUCCESS;
    13501406
    13511407        case EFI_IMAGE_EVT_CMD_SIZE0:
    13521408            AssertBreak(EFI_IMAGE_EVT_GET_PAYLOAD(u32) <= UINT16_MAX);
    1353             pThis->ImageEvt.cb0 <<= 16;
    1354             pThis->ImageEvt.cb0  |= EFI_IMAGE_EVT_GET_PAYLOAD_U16(u32);
     1409            pThisCC->ImageEvt.cb0 <<= 16;
     1410            pThisCC->ImageEvt.cb0  |= EFI_IMAGE_EVT_GET_PAYLOAD_U16(u32);
    13551411            return VINF_SUCCESS;
    13561412
    13571413        case EFI_IMAGE_EVT_CMD_NAME:
    13581414            AssertBreak(EFI_IMAGE_EVT_GET_PAYLOAD(u32) <= 0x7f);
    1359             if (pThis->ImageEvt.offName < sizeof(pThis->ImageEvt.szName) - 1)
     1415            if (pThisCC->ImageEvt.offName < sizeof(pThisCC->ImageEvt.szName) - 1)
    13601416            {
    13611417                char ch = EFI_IMAGE_EVT_GET_PAYLOAD_U8(u32);
    13621418                if (ch == '\\')
    13631419                    ch = '/';
    1364                 pThis->ImageEvt.szName[pThis->ImageEvt.offName++] = ch;
     1420                pThisCC->ImageEvt.szName[pThisCC->ImageEvt.offName++] = ch;
    13651421                if (ch == '/' || ch == ':')
    1366                     pThis->ImageEvt.offNameLastComponent = pThis->ImageEvt.offName;
     1422                    pThisCC->ImageEvt.offNameLastComponent = pThisCC->ImageEvt.offName;
    13671423            }
    13681424            else
     
    13901446{
    13911447    RT_NOREF(pvUser);
    1392     PDEVEFI pThis = PDMINS_2_DATA(pDevIns, PDEVEFI);
     1448    PDEVEFIR3 pThisCC = PDMINS_2_DATA_CC(pDevIns, PDEVEFIR3);
    13931449    Log4(("EFI in: %x %x\n", Port, cb));
    13941450
     
    13961452    {
    13971453        case EFI_INFO_PORT:
    1398             if (pThis->offInfo == -1 && cb == 4)
     1454            if (pThisCC->offInfo == -1 && cb == 4)
    13991455            {
    1400                 pThis->offInfo = 0;
    1401                 uint32_t cbInfo = *pu32 = efiInfoSize(pThis);
     1456                pThisCC->offInfo = 0;
     1457                uint32_t cbInfo = *pu32 = efiInfoSize(pThisCC);
    14021458                if (cbInfo == UINT32_MAX)
    14031459                    return PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "iInfoSelector=%#x (%d)\n",
    1404                                              pThis->iInfoSelector, pThis->iInfoSelector);
     1460                                             pThisCC->iInfoSelector, pThisCC->iInfoSelector);
    14051461            }
    14061462            else
     
    14081464                if (cb != 1)
    14091465                    return VERR_IOM_IOPORT_UNUSED;
    1410                 *pu32 = efiInfoNextByte(pThis);
    1411                 pThis->offInfo++;
     1466                *pu32 = efiInfoNextByte(pThisCC);
     1467                pThisCC->offInfo++;
    14121468            }
    14131469            return VINF_SUCCESS;
     
    14241480
    14251481        case EFI_PORT_VARIABLE_OP:
    1426             return nvramReadVariableOp(pThis, pu32, cb);
     1482            return nvramReadVariableOp(pThisCC, pu32, cb);
    14271483
    14281484        case EFI_PORT_VARIABLE_PARAM:
     
    14761532{
    14771533    RT_NOREF(pvUser);
    1478     PDEVEFI pThis = PDMINS_2_DATA(pDevIns, PDEVEFI);
     1534    PDEVEFIR3 pThisCC = PDMINS_2_DATA_CC(pDevIns, PDEVEFIR3);
    14791535    int     rc    = VINF_SUCCESS;
    14801536    Log4(("efi: out %x %x %d\n", Port, u32, cb));
     
    14841540        case EFI_INFO_PORT:
    14851541            Log2(("EFI_INFO_PORT: iInfoSelector=%#x\n", u32));
    1486             pThis->iInfoSelector = u32;
    1487             pThis->offInfo       = -1;
     1542            pThisCC->iInfoSelector = u32;
     1543            pThisCC->offInfo       = -1;
    14881544            break;
    14891545
     
    15011557            if (u32 == '\n' || u32 == '\r')
    15021558            {
    1503                 Assert(pThis->iMsg < sizeof(pThis->szMsg));
    1504                 pThis->szMsg[pThis->iMsg] = '\0';
    1505                 if (pThis->iMsg)
    1506                     LogRel2(("efi: %s\n", pThis->szMsg));
    1507                 pThis->iMsg = 0;
     1559                Assert(pThisCC->iMsg < sizeof(pThisCC->szMsg));
     1560                pThisCC->szMsg[pThisCC->iMsg] = '\0';
     1561                if (pThisCC->iMsg)
     1562                    LogRel2(("efi: %s\n", pThisCC->szMsg));
     1563                pThisCC->iMsg = 0;
    15081564            }
    15091565            else
    15101566            {
    1511                 if (pThis->iMsg >= sizeof(pThis->szMsg) - 1)
     1567                if (pThisCC->iMsg >= sizeof(pThisCC->szMsg) - 1)
    15121568                {
    1513                     pThis->szMsg[pThis->iMsg] = '\0';
    1514                     LogRel2(("efi: %s\n", pThis->szMsg));
    1515                     pThis->iMsg = 0;
     1569                    pThisCC->szMsg[pThisCC->iMsg] = '\0';
     1570                    LogRel2(("efi: %s\n", pThisCC->szMsg));
     1571                    pThisCC->iMsg = 0;
    15161572                }
    1517                 pThis->szMsg[pThis->iMsg] = (char)u32;
    1518                 pThis->szMsg[++pThis->iMsg] = '\0';
     1573                pThisCC->szMsg[pThisCC->iMsg] = (char)u32;
     1574                pThisCC->szMsg[++pThisCC->iMsg] = '\0';
    15191575            }
    15201576            break;
     
    15411597                case EFI_PANIC_CMD_START_MSG:
    15421598                    LogRel(("Receiving EFI panic...\n"));
    1543                     pThis->iPanicMsg = 0;
    1544                     pThis->szPanicMsg[0] = '\0';
     1599                    pThisCC->iPanicMsg = 0;
     1600                    pThisCC->szPanicMsg[0] = '\0';
    15451601                    break;
    15461602
    15471603                case EFI_PANIC_CMD_END_MSG:
    15481604#ifdef IN_RING3
    1549                     LogRel(("EFI: Panic! %s\n", pThis->szPanicMsg));
     1605                    LogRel(("EFI: Panic! %s\n", pThisCC->szPanicMsg));
    15501606# ifdef VBOX_STRICT
    1551                     return PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "EFI Panic: %s\n", pThis->szPanicMsg);
     1607                    return PDMDevHlpDBGFStop(pDevIns, RT_SRC_POS, "EFI Panic: %s\n", pThisCC->szPanicMsg);
    15521608# else
    15531609                    return VERR_INTERNAL_ERROR;
     
    15631619                    {
    15641620                        /* Add the message char to the buffer. */
    1565                         uint32_t i = pThis->iPanicMsg;
    1566                         if (i + 1 < sizeof(pThis->szPanicMsg))
     1621                        uint32_t i = pThisCC->iPanicMsg;
     1622                        if (i + 1 < sizeof(pThisCC->szPanicMsg))
    15671623                        {
    15681624                            char ch = EFI_PANIC_CMD_MSG_GET_CHAR(u32);
    15691625                            if (    ch == '\n'
    15701626                                &&  i > 0
    1571                                 &&  pThis->szPanicMsg[i - 1] == '\r')
     1627                                &&  pThisCC->szPanicMsg[i - 1] == '\r')
    15721628                                i--;
    1573                             pThis->szPanicMsg[i] = ch;
    1574                             pThis->szPanicMsg[i + 1] = '\0';
    1575                             pThis->iPanicMsg = i + 1;
     1629                            pThisCC->szPanicMsg[i] = ch;
     1630                            pThisCC->szPanicMsg[i + 1] = '\0';
     1631                            pThisCC->iPanicMsg = i + 1;
    15761632                        }
    15771633                    }
     
    15911647                u32 = EFI_VM_VARIABLE_OP_ERROR;
    15921648            }
    1593             pThis->NVRAM.offOpBuffer = 0;
    1594             pThis->NVRAM.enmOp = (EFIVAROP)u32;
     1649            pThisCC->NVRAM.offOpBuffer = 0;
     1650            pThisCC->NVRAM.enmOp = (EFIVAROP)u32;
    15951651            Log2(("EFI_VARIABLE_OP: enmOp=%#x (%d)\n", u32, u32));
    15961652            break;
     
    15981654
    15991655        case EFI_PORT_VARIABLE_PARAM:
    1600             rc = nvramWriteVariableParam(pThis, u32);
     1656            rc = nvramWriteVariableParam(pThisCC, u32);
    16011657            break;
    16021658
     
    16171673
    16181674        case EFI_PORT_IMAGE_EVENT:
    1619             rc = efiPortImageEventWrite(pThis, u32, cb);
     1675            rc = efiPortImageEventWrite(pThisCC, u32, cb);
    16201676            break;
    16211677
     
    16271683}
    16281684
    1629 
    1630 #ifdef IN_RING3 /* for now */
    1631 /** @callback_method_impl{FNIOMMIWRITE, Flash memory write} */
    1632 PDMBOTHCBDECL(int) efiR3NvMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void const *pv, unsigned cb)
     1685#endif /* IN_RING3 */
     1686
     1687
     1688/**
     1689 * @callback_method_impl{FNIOMMMIONEWWRITE, Flash memory write}
     1690 */
     1691static DECLCALLBACK(VBOXSTRICTRC) efiR3NvMmioWrite(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void const *pv, unsigned cb)
    16331692{
    16341693    PDEVEFI pThis = PDMINS_2_DATA(pDevIns, PDEVEFI);
    1635     RT_NOREF1(pvUser);
    1636 
    1637     return flashWrite(&pThis->Flash, GCPhysAddr - pThis->GCPhysNvram, pv, cb);
    1638 }
    1639 
    1640 
    1641 /** @callback_method_impl{FNIOMMIOREAD, Flash memory read} */
    1642 PDMBOTHCBDECL(int) efiR3NvMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS GCPhysAddr, void *pv, unsigned cb)
     1694    RT_NOREF(pvUser);
     1695
     1696    return flashWrite(&pThis->Flash, off, pv, cb);
     1697}
     1698
     1699
     1700/**
     1701 * @callback_method_impl{FNIOMMMIONEWREAD, Flash memory read}
     1702 */
     1703static DECLCALLBACK(VBOXSTRICTRC) efiR3NvMmioRead(PPDMDEVINS pDevIns, void *pvUser, RTGCPHYS off, void *pv, unsigned cb)
    16431704{
    16441705    PDEVEFI pThis = PDMINS_2_DATA(pDevIns, PDEVEFI);
    1645     RT_NOREF1(pvUser);
    1646 
    1647     return flashRead(&pThis->Flash, GCPhysAddr - pThis->GCPhysNvram, pv, cb);
    1648 }
    1649 #endif /* IN_RING3 for now */
    1650 
     1706    RT_NOREF(pvUser);
     1707
     1708    return flashRead(&pThis->Flash, off, pv, cb);
     1709}
     1710
     1711#ifdef IN_RING3
    16511712
    16521713static DECLCALLBACK(int) efiSaveExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
     
    16551716    LogFlow(("efiSaveExec:\n"));
    16561717
    1657     return flashR3SsmSaveExec(&pThis->Flash, pSSM);
     1718    return flashR3SaveExec(&pThis->Flash, pDevIns, pSSM);
    16581719}
    16591720
    16601721static DECLCALLBACK(int) efiLoadExec(PPDMDEVINS pDevIns, PSSMHANDLE pSSM, uint32_t uVersion, uint32_t uPass)
    16611722{
    1662     PDEVEFI pThis = PDMINS_2_DATA(pDevIns, PDEVEFI);
     1723    PDEVEFI         pThis   = PDMINS_2_DATA(pDevIns, PDEVEFI);
     1724    PDEVEFIR3       pThisCC = PDMINS_2_DATA_CC(pDevIns, PDEVEFIR3);
     1725    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
    16631726    LogFlow(("efiLoadExec: uVersion=%d uPass=%d\n", uVersion, uPass));
    16641727
     
    16761739    int rc;
    16771740    if (uVersion > EFI_SSM_VERSION_PRE_PROPER_NVRAM)
    1678         rc = flashR3SsmLoadExec(&pThis->Flash, pSSM);
     1741        rc = flashR3LoadExec(&pThis->Flash, pDevIns, pSSM);
    16791742    else
    16801743    {
     
    16821745         * Kill the current variables before loading anything.
    16831746         */
    1684         nvramFlushDeviceVariableList(pThis);
     1747        nvramFlushDeviceVariableList(pThisCC);
    16851748
    16861749        /*
    16871750         * Load the NVRAM state.
    16881751         */
    1689         rc = SSMR3GetStructEx(pSSM, &pThis->NVRAM, sizeof(NVRAMDESC), 0, g_aEfiNvramDescField, NULL);
     1752        rc = pHlp->pfnSSMGetStructEx(pSSM, &pThisCC->NVRAM, sizeof(NVRAMDESC), 0, g_aEfiNvramDescField, NULL);
    16901753        AssertRCReturn(rc, rc);
    1691         pThis->NVRAM.pCurVar = NULL;
    1692 
    1693         rc = SSMR3GetStructEx(pSSM, &pThis->NVRAM.VarOpBuf, sizeof(EFIVAR), 0, g_aEfiVariableDescFields, NULL);
     1754        pThisCC->NVRAM.pCurVar = NULL;
     1755
     1756        rc = pHlp->pfnSSMGetStructEx(pSSM, &pThisCC->NVRAM.VarOpBuf, sizeof(EFIVAR), 0, g_aEfiVariableDescFields, NULL);
    16941757        AssertRCReturn(rc, rc);
    16951758
     
    16971760         * Load variables.
    16981761         */
    1699         pThis->NVRAM.pCurVar = NULL;
    1700         Assert(RTListIsEmpty(&pThis->NVRAM.VarList));
    1701         RTListInit(&pThis->NVRAM.VarList);
    1702         for (uint32_t i = 0; i < pThis->NVRAM.cVariables; i++)
     1762        pThisCC->NVRAM.pCurVar = NULL;
     1763        Assert(RTListIsEmpty(&pThisCC->NVRAM.VarList));
     1764        RTListInit(&pThisCC->NVRAM.VarList);
     1765        for (uint32_t i = 0; i < pThisCC->NVRAM.cVariables; i++)
    17031766        {
    17041767            PEFIVAR pEfiVar = (PEFIVAR)RTMemAllocZ(sizeof(EFIVAR));
    17051768            AssertReturn(pEfiVar, VERR_NO_MEMORY);
    17061769
    1707             rc = SSMR3GetStructEx(pSSM, pEfiVar, sizeof(EFIVAR), 0, g_aEfiVariableDescFields, NULL);
     1770            rc = pHlp->pfnSSMGetStructEx(pSSM, pEfiVar, sizeof(EFIVAR), 0, g_aEfiVariableDescFields, NULL);
    17081771            if (RT_SUCCESS(rc))
    17091772            {
     
    17331796               updating the current variable pointer while we're here. */
    17341797#if 1
    1735             RTListAppend(&pThis->NVRAM.VarList, &pEfiVar->ListNode);
     1798            RTListAppend(&pThisCC->NVRAM.VarList, &pEfiVar->ListNode);
    17361799#else
    1737             nvramInsertVariable(pThis, pEfiVar);
     1800            nvramInsertVariable(pThisCC, pEfiVar);
    17381801#endif
    1739             if (pThis->NVRAM.idUniqueCurVar == pEfiVar->idUniqueSavedState)
    1740                 pThis->NVRAM.pCurVar = pEfiVar;
     1802            if (pThisCC->NVRAM.idUniqueCurVar == pEfiVar->idUniqueSavedState)
     1803                pThisCC->NVRAM.pCurVar = pEfiVar;
    17411804        }
    17421805    }
     
    17521815{
    17531816    LogFlowFunc(("ENTER: pIBase=%p pszIID=%p\n", pInterface, pszIID));
    1754     PDEVEFI  pThis = RT_FROM_MEMBER(pInterface, DEVEFI, Lun0.IBase);
    1755 
    1756     PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThis->Lun0.IBase);
     1817    PDEVEFIR3 pThisCC = RT_FROM_MEMBER(pInterface, DEVEFIR3, Lun0.IBase);
     1818
     1819    PDMIBASE_RETURN_INTERFACE(pszIID, PDMIBASE, &pThisCC->Lun0.IBase);
    17571820    return NULL;
    17581821}
     
    17801843static DECLCALLBACK(int) efiInitComplete(PPDMDEVINS pDevIns)
    17811844{
    1782     PDEVEFI pThis = PDMINS_2_DATA(pDevIns, PDEVEFI);
     1845    PDEVEFIR3 pThisCC = PDMINS_2_DATA_CC(pDevIns, PDEVEFIR3);
    17831846
    17841847    PVM pVM                    = PDMDevHlpGetVM(pDevIns);
     
    18141877     * Number of CPUs.
    18151878     */
    1816     cmosWrite(pDevIns, 0x60, pThis->cCpus & 0xff);
     1879    cmosWrite(pDevIns, 0x60, pThisCC->cCpus & 0xff);
    18171880
    18181881    return VINF_SUCCESS;
     
    18261889{
    18271890    RT_NOREF(enmCtx);
    1828     PDEVEFI pThis = PDMINS_2_DATA(pDevIns, PDEVEFI);
     1891    PDEVEFIR3 pThisCC = PDMINS_2_DATA_CC(pDevIns, PDEVEFIR3);
    18291892
    18301893    /*
    18311894     * Re-shadow the Firmware Volume and make it RAM/RAM.
    18321895     */
    1833     uint32_t    cPages = RT_ALIGN_64(pThis->cbEfiRom, PAGE_SIZE) >> PAGE_SHIFT;
    1834     RTGCPHYS    GCPhys = pThis->GCLoadAddress;
     1896    uint32_t    cPages = RT_ALIGN_64(pThisCC->cbEfiRom, PAGE_SIZE) >> PAGE_SHIFT;
     1897    RTGCPHYS    GCPhys = pThisCC->GCLoadAddress;
    18351898    while (cPages > 0)
    18361899    {
     
    18651928static DECLCALLBACK(void) efiReset(PPDMDEVINS pDevIns)
    18661929{
    1867     PDEVEFI  pThis = PDMINS_2_DATA(pDevIns, PDEVEFI);
    1868 
     1930    PDEVEFI   pThis  = PDMINS_2_DATA(pDevIns, PDEVEFI);
     1931    PDEVEFIR3 pThisCC = PDMINS_2_DATA_CC(pDevIns, PDEVEFIR3);
    18691932    LogFlow(("efiReset\n"));
    18701933
    1871     pThis->iInfoSelector = 0;
    1872     pThis->offInfo       = -1;
    1873 
    1874     pThis->iMsg = 0;
    1875     pThis->szMsg[0] = '\0';
    1876     pThis->iPanicMsg = 0;
    1877     pThis->szPanicMsg[0] = '\0';
     1934    pThisCC->iInfoSelector = 0;
     1935    pThisCC->offInfo       = -1;
     1936
     1937    pThisCC->iMsg = 0;
     1938    pThisCC->szMsg[0] = '\0';
     1939    pThisCC->iPanicMsg = 0;
     1940    pThisCC->szPanicMsg[0] = '\0';
    18781941
    18791942    flashR3Reset(&pThis->Flash);
     
    18931956static DECLCALLBACK(void) efiPowerOff(PPDMDEVINS pDevIns)
    18941957{
    1895     PDEVEFI  pThis = PDMINS_2_DATA(pDevIns, PDEVEFI);
    1896 
    1897     if (pThis->Lun0.pNvramDrv)
    1898         nvramStore(pThis);
     1958    PDEVEFIR3  pThisCC = PDMINS_2_DATA_CC(pDevIns, PDEVEFIR3);
     1959
     1960    if (pThisCC->Lun0.pNvramDrv)
     1961        nvramStore(pThisCC);
    18991962}
    19001963
     
    19111974static DECLCALLBACK(int) efiDestruct(PPDMDEVINS pDevIns)
    19121975{
    1913     PDEVEFI  pThis = PDMINS_2_DATA(pDevIns, PDEVEFI);
    19141976    PDMDEV_CHECK_VERSIONS_RETURN_QUIET(pDevIns);
    1915 
    1916     nvramFlushDeviceVariableList(pThis);
    1917 
    1918     if (   !pThis->fNvramStateSaved
    1919         && pThis->pszNvramFile)
    1920     {
    1921         int rc = flashR3SaveToFile(&pThis->Flash, pThis->pszNvramFile);
     1977    PDEVEFI   pThis   = PDMINS_2_DATA(pDevIns, PDEVEFI);
     1978    PDEVEFIR3 pThisCC = PDMINS_2_DATA_CC(pDevIns, PDEVEFIR3);
     1979
     1980    nvramFlushDeviceVariableList(pThisCC);
     1981
     1982    if (   !pThisCC->fNvramStateSaved
     1983        && pThisCC->pszNvramFile)
     1984    {
     1985        int rc = flashR3SaveToFile(&pThis->Flash, pDevIns, pThisCC->pszNvramFile);
    19221986        if (RT_FAILURE(rc))
    1923             LogRel(("EFI: Failed to save flash file to '%s' -> %Rrc\n", pThis->pszNvramFile, rc));
    1924     }
    1925 
    1926     flashR3Destruct(&pThis->Flash);
    1927 
    1928     if (pThis->pszNvramFile)
    1929     {
    1930         PDMDevHlpMMHeapFree(pDevIns, pThis->pszNvramFile);
    1931         pThis->pszNvramFile = NULL;
    1932     }
    1933 
    1934     if (pThis->pu8EfiRomFree)
    1935     {
    1936         RTFileReadAllFree(pThis->pu8EfiRomFree, (size_t)pThis->cbEfiRom + pThis->offEfiRom);
    1937         pThis->pu8EfiRomFree = NULL;
     1987            LogRel(("EFI: Failed to save flash file to '%s' -> %Rrc\n", pThisCC->pszNvramFile, rc));
     1988    }
     1989
     1990    flashR3Destruct(&pThis->Flash, pDevIns);
     1991
     1992    if (pThisCC->pszNvramFile)
     1993    {
     1994        PDMDevHlpMMHeapFree(pDevIns, pThisCC->pszNvramFile);
     1995        pThisCC->pszNvramFile = NULL;
     1996    }
     1997
     1998    if (pThisCC->pu8EfiRomFree)
     1999    {
     2000        RTFileReadAllFree(pThisCC->pu8EfiRomFree, (size_t)pThisCC->cbEfiRom + pThisCC->offEfiRom);
     2001        pThisCC->pu8EfiRomFree = NULL;
    19382002    }
    19392003
     
    19412005     * Free MM heap pointers (waste of time, but whatever).
    19422006     */
    1943     if (pThis->pszEfiRomFile)
    1944     {
    1945         MMR3HeapFree(pThis->pszEfiRomFile);
    1946         pThis->pszEfiRomFile = NULL;
    1947     }
    1948 
    1949     if (pThis->pu8EfiThunk)
    1950     {
    1951         MMR3HeapFree(pThis->pu8EfiThunk);
    1952         pThis->pu8EfiThunk = NULL;
    1953     }
    1954 
    1955     if (pThis->pbDeviceProps)
    1956     {
    1957         PDMDevHlpMMHeapFree(pDevIns, pThis->pbDeviceProps);
    1958         pThis->pbDeviceProps = NULL;
    1959         pThis->cbDeviceProps = 0;
     2007    if (pThisCC->pszEfiRomFile)
     2008    {
     2009        PDMDevHlpMMHeapFree(pDevIns, pThisCC->pszEfiRomFile);
     2010        pThisCC->pszEfiRomFile = NULL;
     2011    }
     2012
     2013    if (pThisCC->pu8EfiThunk)
     2014    {
     2015        PDMDevHlpMMHeapFree(pDevIns, pThisCC->pu8EfiThunk);
     2016        pThisCC->pu8EfiThunk = NULL;
     2017    }
     2018
     2019    if (pThisCC->pbDeviceProps)
     2020    {
     2021        PDMDevHlpMMHeapFree(pDevIns, pThisCC->pbDeviceProps);
     2022        pThisCC->pbDeviceProps = NULL;
     2023        pThisCC->cbDeviceProps = 0;
    19602024    }
    19612025
     
    19992063 *
    20002064 * @returns VBox status code.
    2001  * @param   pThis    The device instance data.
    2002  */
    2003 static int efiParseFirmware(PDEVEFI pThis)
    2004 {
    2005     EFI_FIRMWARE_VOLUME_HEADER const *pFwVolHdr = (EFI_FIRMWARE_VOLUME_HEADER const *)pThis->pu8EfiRom;
     2065 * @param   pDevIns  The device instance.
     2066 * @param   pThis    The shared device state.
     2067 * @param   pThisCC  The device state for the current context.
     2068 */
     2069static int efiParseFirmware(PPDMDEVINS pDevIns, PDEVEFI pThis, PDEVEFIR3 pThisCC)
     2070{
     2071    EFI_FIRMWARE_VOLUME_HEADER const *pFwVolHdr = (EFI_FIRMWARE_VOLUME_HEADER const *)pThisCC->pu8EfiRom;
    20062072
    20072073    /*
     
    20152081                          VERR_VERSION_MISMATCH);
    20162082    /** @todo check checksum, see PE spec vol. 3 */
    2017     AssertLogRelMsgReturn(pFwVolHdr->FvLength <= pThis->cbEfiRom,
    2018                           ("%#llx, expected %#llx\n", pFwVolHdr->FvLength, pThis->cbEfiRom),
     2083    AssertLogRelMsgReturn(pFwVolHdr->FvLength <= pThisCC->cbEfiRom,
     2084                          ("%#llx, expected %#llx\n", pFwVolHdr->FvLength, pThisCC->cbEfiRom),
    20192085                          VERR_INVALID_PARAMETER);
    20202086    AssertLogRelMsgReturn(      pFwVolHdr->BlockMap[0].Length > 0
     
    20232089                          VERR_INVALID_PARAMETER);
    20242090
    2025     AssertLogRelMsgReturn(!(pThis->cbEfiRom & PAGE_OFFSET_MASK), ("%RX64\n", pThis->cbEfiRom), VERR_INVALID_PARAMETER);
     2091    AssertLogRelMsgReturn(!(pThisCC->cbEfiRom & PAGE_OFFSET_MASK), ("%RX64\n", pThisCC->cbEfiRom), VERR_INVALID_PARAMETER);
    20262092
    20272093    LogRel(("Found EFI FW Volume, %u bytes (%u %u-byte blocks)\n", pFwVolHdr->FvLength, pFwVolHdr->BlockMap[0].NumBlocks, pFwVolHdr->BlockMap[0].Length));
     
    20332099
    20342100    /* Found NVRAM storage, configure flash device. */
    2035     pThis->offEfiRom   = pFwVolHdr->FvLength;
    2036     pThis->cbNvram     = pFwVolHdr->FvLength;
    2037     pThis->GCPhysNvram = UINT32_C(0xfffff000) - pThis->cbEfiRom + PAGE_SIZE;
    2038     pThis->cbEfiRom   -= pThis->cbNvram;
    2039 
    2040     int rc = flashR3Init(&pThis->Flash, pThis->pDevIns, 0xA289 /*Intel*/, pThis->cbNvram, pFwVolHdr->BlockMap[0].Length);
     2101    pThisCC->offEfiRom   = pFwVolHdr->FvLength;
     2102    pThisCC->cbNvram     = pFwVolHdr->FvLength;
     2103    pThisCC->GCPhysNvram = UINT32_C(0xfffff000) - pThisCC->cbEfiRom + PAGE_SIZE;
     2104    pThisCC->cbEfiRom   -= pThisCC->cbNvram;
     2105
     2106    int rc = flashR3Init(&pThis->Flash, pThisCC->pDevIns, 0xA289 /*Intel*/, pThisCC->cbNvram, pFwVolHdr->BlockMap[0].Length);
    20412107    if (RT_FAILURE(rc))
    20422108        return rc;
    20432109
    20442110    /* If the file does not exist we initialize the NVRAM from the loaded ROM file. */
    2045     if (!pThis->pszNvramFile || !RTPathExists(pThis->pszNvramFile))
    2046         rc = flashR3LoadFromBuf(&pThis->Flash, pThis->pu8EfiRom, pThis->cbNvram);
     2111    if (!pThisCC->pszNvramFile || !RTPathExists(pThisCC->pszNvramFile))
     2112        rc = flashR3LoadFromBuf(&pThis->Flash, pThisCC->pu8EfiRom, pThisCC->cbNvram);
    20472113    else
    2048         rc = flashR3LoadFromFile(&pThis->Flash, pThis->pszNvramFile);
     2114        rc = flashR3LoadFromFile(&pThis->Flash, pDevIns, pThisCC->pszNvramFile);
    20492115    if (RT_FAILURE(rc))
    20502116        return rc;
    20512117
    2052     pThis->GCLoadAddress = pThis->GCPhysNvram + pThis->cbNvram;
     2118    pThisCC->GCLoadAddress = pThisCC->GCPhysNvram + pThisCC->cbNvram;
    20532119
    20542120    return VINF_SUCCESS;
     
    20592125 *
    20602126 * @returns VBox status code.
    2061  * @param   pThis       The device instance data.
     2127 * @param   pDevIns     The device instance.
     2128 * @param   pThis       The shared Efi state.
     2129 * @param   pThisCC     The device state for the current context.
    20622130 * @param   pCfg        Configuration node handle for the device.
    20632131 */
    2064 static int efiLoadRom(PDEVEFI pThis, PCFGMNODE pCfg)
     2132static int efiLoadRom(PPDMDEVINS pDevIns, PDEVEFI pThis, PDEVEFIR3 pThisCC, PCFGMNODE pCfg)
    20652133{
    20662134    RT_NOREF(pCfg);
     
    20712139    int     rc;
    20722140#ifdef VBOX_WITH_EFI_IN_DD2
    2073     if (RTStrCmp(pThis->pszEfiRomFile, g_szEfiBuiltin32) == 0)
    2074     {
    2075         pThis->pu8EfiRomFree = NULL;
    2076         pThis->pu8EfiRom = g_abEfiFirmware32;
    2077         pThis->cbEfiRom  = g_cbEfiFirmware32;
    2078     }
    2079     else if (RTStrCmp(pThis->pszEfiRomFile, g_szEfiBuiltin64) == 0)
    2080     {
    2081         pThis->pu8EfiRomFree = NULL;
    2082         pThis->pu8EfiRom = g_abEfiFirmware64;
    2083         pThis->cbEfiRom  = g_cbEfiFirmware64;
     2141    if (RTStrCmp(pThisCC->pszEfiRomFile, g_szEfiBuiltin32) == 0)
     2142    {
     2143        pThisCC->pu8EfiRomFree = NULL;
     2144        pThisCC->pu8EfiRom = g_abEfiFirmware32;
     2145        pThisCC->cbEfiRom  = g_cbEfiFirmware32;
     2146    }
     2147    else if (RTStrCmp(pThisCC->pszEfiRomFile, g_szEfiBuiltin64) == 0)
     2148    {
     2149        pThisCC->pu8EfiRomFree = NULL;
     2150        pThisCC->pu8EfiRom = g_abEfiFirmware64;
     2151        pThisCC->cbEfiRom  = g_cbEfiFirmware64;
    20842152    }
    20852153    else
     
    20882156        void   *pvFile;
    20892157        size_t  cbFile;
    2090         rc = RTFileReadAllEx(pThis->pszEfiRomFile,
     2158        rc = RTFileReadAllEx(pThisCC->pszEfiRomFile,
    20912159                             0 /*off*/,
    20922160                             RTFOFF_MAX /*cbMax*/,
     
    20952163                             &cbFile);
    20962164        if (RT_FAILURE(rc))
    2097             return PDMDevHlpVMSetError(pThis->pDevIns, rc, RT_SRC_POS,
     2165            return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
    20982166                                       N_("Loading the EFI firmware volume '%s' failed with rc=%Rrc"),
    2099                                        pThis->pszEfiRomFile, rc);
    2100         pThis->pu8EfiRomFree = (uint8_t *)pvFile;
    2101         pThis->pu8EfiRom = (uint8_t *)pvFile;
    2102         pThis->cbEfiRom  = cbFile;
     2167                                       pThisCC->pszEfiRomFile, rc);
     2168        pThisCC->pu8EfiRomFree = (uint8_t *)pvFile;
     2169        pThisCC->pu8EfiRom = (uint8_t *)pvFile;
     2170        pThisCC->cbEfiRom  = cbFile;
    21032171    }
    21042172
     
    21062174     * Validate firmware volume and figure out the load address as well as the SEC entry point.
    21072175     */
    2108     rc = efiParseFirmware(pThis);
     2176    rc = efiParseFirmware(pDevIns, pThis, pThisCC);
    21092177    if (RT_FAILURE(rc))
    2110         return PDMDevHlpVMSetError(pThis->pDevIns, rc, RT_SRC_POS,
     2178        return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
    21112179                                   N_("Parsing the EFI firmware volume '%s' failed with rc=%Rrc"),
    2112                                    pThis->pszEfiRomFile, rc);
     2180                                   pThisCC->pszEfiRomFile, rc);
    21132181
    21142182    /*
     
    21312199        "EFI Firmware Volume (Part 13)", "EFI Firmware Volume (Part 14)", "EFI Firmware Volume (Part 15)", "EFI Firmware Volume (Part 16)",
    21322200    };
    2133     AssertLogRelMsgReturn(pThis->cbEfiRom < RT_ELEMENTS(s_apszNames) * _512K,
     2201    AssertLogRelMsgReturn(pThisCC->cbEfiRom < RT_ELEMENTS(s_apszNames) * _512K,
    21342202                          ("EFI firmware image too big: %#RX64, max %#zx\n",
    2135                            pThis->cbEfiRom, RT_ELEMENTS(s_apszNames) * _512K),
     2203                           pThisCC->cbEfiRom, RT_ELEMENTS(s_apszNames) * _512K),
    21362204                          VERR_IMAGE_TOO_BIG);
    21372205
    2138     uint32_t const  cbChunk = pThis->cbNvram + pThis->cbEfiRom >= _2M ? _512K
    2139                             : (uint32_t)RT_ALIGN_64((pThis->cbNvram + pThis->cbEfiRom) / 4, PAGE_SIZE);
    2140     uint32_t        cbLeft  = pThis->cbEfiRom;           /* ASSUMES NVRAM comes first! */
    2141     uint32_t        off     = pThis->offEfiRom + cbLeft; /* ASSUMES NVRAM comes first! */
    2142     RTGCPHYS64      GCPhys  = pThis->GCLoadAddress + cbLeft;
     2206    uint32_t const  cbChunk = pThisCC->cbNvram + pThisCC->cbEfiRom >= _2M ? _512K
     2207                            : (uint32_t)RT_ALIGN_64((pThisCC->cbNvram + pThisCC->cbEfiRom) / 4, PAGE_SIZE);
     2208    uint32_t        cbLeft  = pThisCC->cbEfiRom;           /* ASSUMES NVRAM comes first! */
     2209    uint32_t        off     = pThisCC->offEfiRom + cbLeft; /* ASSUMES NVRAM comes first! */
     2210    RTGCPHYS64      GCPhys  = pThisCC->GCLoadAddress + cbLeft;
    21432211    AssertLogRelMsg(GCPhys == _4G, ("%RGp\n", GCPhys));
    21442212
     
    21522220        GCPhys -= cb;
    21532221        off    -= cb;
    2154         rc = PDMDevHlpROMRegister(pThis->pDevIns, GCPhys, cb, pThis->pu8EfiRom + off, cb,
     2222        rc = PDMDevHlpROMRegister(pDevIns, GCPhys, cb, pThisCC->pu8EfiRom + off, cb,
    21552223                                  PGMPHYS_ROM_FLAGS_SHADOWED | PGMPHYS_ROM_FLAGS_PERMANENT_BINARY, s_apszNames[i]);
    21562224        AssertRCReturn(rc, rc);
     
    21682236            off    -= cb;
    21692237            /** @todo Add flag to prevent saved state loading from bitching about these regions. */
    2170             rc = PDMDevHlpROMRegister(pThis->pDevIns, GCPhys, cb, pThis->pu8EfiRom + off, cb,
     2238            rc = PDMDevHlpROMRegister(pDevIns, GCPhys, cb, pThisCC->pu8EfiRom + off, cb,
    21712239                                      PGMPHYS_ROM_FLAGS_SHADOWED | PGMPHYS_ROM_FLAGS_PERMANENT_BINARY
    21722240                                      | PGMPHYS_ROM_FLAGS_MAYBE_MISSING_FROM_STATE, s_apszNames[i]);
     
    21772245
    21782246    /* Not sure what the purpose of this one is... */
    2179     rc = PDMDevHlpROMProtectShadow(pThis->pDevIns, pThis->GCLoadAddress, (uint32_t)cbChunk, PGMROMPROT_READ_RAM_WRITE_IGNORE);
     2247    rc = PDMDevHlpROMProtectShadow(pDevIns, pThisCC->GCLoadAddress, (uint32_t)cbChunk, PGMROMPROT_READ_RAM_WRITE_IGNORE);
    21802248    AssertRCReturn(rc, rc);
    21812249
    21822250#else
    2183     RTGCPHYS cbQuart = RT_ALIGN_64(pThis->cbEfiRom / 4, PAGE_SIZE);
    2184     rc = PDMDevHlpROMRegister(pThis->pDevIns,
    2185                               pThis->GCLoadAddress,
     2251    RTGCPHYS cbQuart = RT_ALIGN_64(pThisCC->cbEfiRom / 4, PAGE_SIZE);
     2252    rc = PDMDevHlpROMRegister(pDevIns,
     2253                              pThisCC->GCLoadAddress,
    21862254                              cbQuart,
    2187                               pThis->pu8EfiRom + pThis->uEfiRomOfs,
     2255                              pThisCC->pu8EfiRom + pThisCC->uEfiRomOfs,
    21882256                              cbQuart,
    21892257                              PGMPHYS_ROM_FLAGS_SHADOWED | PGMPHYS_ROM_FLAGS_PERMANENT_BINARY,
    21902258                              "EFI Firmware Volume");
    21912259    AssertRCReturn(rc, rc);
    2192     rc = PDMDevHlpROMProtectShadow(pThis->pDevIns, pThis->GCLoadAddress, (uint32_t)cbQuart, PGMROMPROT_READ_RAM_WRITE_IGNORE);
     2260    rc = PDMDevHlpROMProtectShadow(pDevIns, pThisCC->GCLoadAddress, (uint32_t)cbQuart, PGMROMPROT_READ_RAM_WRITE_IGNORE);
    21932261    AssertRCReturn(rc, rc);
    2194     rc = PDMDevHlpROMRegister(pThis->pDevIns,
    2195                               pThis->GCLoadAddress + cbQuart,
     2262    rc = PDMDevHlpROMRegister(pDevIns,
     2263                              pThisCC->GCLoadAddress + cbQuart,
    21962264                              cbQuart,
    2197                               pThis->pu8EfiRom + pThis->uEfiRomOfs + cbQuart,
     2265                              pThisCC->pu8EfiRom + pThisCC->uEfiRomOfs + cbQuart,
    21982266                              cbQuart,
    21992267                              PGMPHYS_ROM_FLAGS_SHADOWED | PGMPHYS_ROM_FLAGS_PERMANENT_BINARY,
     
    22012269    if (RT_FAILURE(rc))
    22022270        return rc;
    2203     rc = PDMDevHlpROMRegister(pThis->pDevIns,
    2204                               pThis->GCLoadAddress + cbQuart * 2,
     2271    rc = PDMDevHlpROMRegister(pDevIns,
     2272                              pThisCC->GCLoadAddress + cbQuart * 2,
    22052273                              cbQuart,
    2206                               pThis->pu8EfiRom + pThis->uEfiRomOfs + cbQuart * 2,
     2274                              pThisCC->pu8EfiRom + pThisCC->uEfiRomOfs + cbQuart * 2,
    22072275                              cbQuart,
    22082276                              PGMPHYS_ROM_FLAGS_SHADOWED | PGMPHYS_ROM_FLAGS_PERMANENT_BINARY,
     
    22102278    if (RT_FAILURE(rc))
    22112279        return rc;
    2212     rc = PDMDevHlpROMRegister(pThis->pDevIns,
    2213                               pThis->GCLoadAddress + cbQuart * 3,
    2214                               pThis->cbEfiRom - cbQuart * 3,
    2215                               pThis->pu8EfiRom + pThis->uEfiRomOfs + cbQuart * 3,
    2216                               pThis->cbEfiRom - cbQuart * 3,
     2280    rc = PDMDevHlpROMRegister(pDevIns,
     2281                              pThisCC->GCLoadAddress + cbQuart * 3,
     2282                              pThisCC->cbEfiRom - cbQuart * 3,
     2283                              pThisCC->pu8EfiRom + pThisCC->uEfiRomOfs + cbQuart * 3,
     2284                              pThisCC->cbEfiRom - cbQuart * 3,
    22172285                              PGMPHYS_ROM_FLAGS_SHADOWED | PGMPHYS_ROM_FLAGS_PERMANENT_BINARY,
    22182286                              "EFI Firmware Volume (Part 4)");
     
    22242292     * Register MMIO region for flash device.
    22252293     */
    2226     rc = PDMDevHlpMMIORegister(pThis->pDevIns, pThis->GCPhysNvram, pThis->cbNvram, NULL /*pvUser*/,
    2227                                IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU,
    2228                                efiR3NvMmioWrite, efiR3NvMmioRead,
    2229                                "Flash Memory");
     2294    rc = PDMDevHlpMmioCreateEx(pDevIns, pThisCC->cbNvram, IOMMMIO_FLAGS_READ_PASSTHRU | IOMMMIO_FLAGS_WRITE_PASSTHRU,
     2295                               NULL /*pPciDev*/,  UINT32_MAX, efiR3NvMmioWrite, efiR3NvMmioRead, NULL, NULL /*pvUser*/,
     2296                               "Flash Memory", &pThis->hMmioFlash);
    22302297    AssertRCReturn(rc, rc);
    2231     LogRel(("EFI: Registered %uKB flash at %RGp\n", pThis->cbNvram / _1K, pThis->GCPhysNvram));
    2232 
     2298    rc = PDMDevHlpMmioMap(pDevIns, pThis->hMmioFlash, pThisCC->GCPhysNvram);
     2299    AssertRCReturn(rc, rc);
     2300
     2301    LogRel(("EFI: Registered %uKB flash at %RGp\n", pThisCC->cbNvram / _1K, pThisCC->GCPhysNvram));
    22332302    return VINF_SUCCESS;
    22342303}
     
    22482317
    22492318    return val;
    2250 
    22512319}
    22522320
     
    22542322/**
    22552323 * Converts a hex string into a binary data blob located at
    2256  * pThis->pbDeviceProps, size returned as pThis->cbDeviceProps.
     2324 * pThisCC->pbDeviceProps, size returned as pThisCC->cbDeviceProps.
    22572325 *
    22582326 * @returns VERR_NO_MEMORY or VINF_SUCCESS.
    2259  * @param   pThis           The EFI instance data.
     2327 * @param   pThisCC         The device state for the current context.
    22602328 * @param   pszDeviceProps  The device property hex string to decode.
    22612329 */
    2262 static int efiParseDeviceString(PDEVEFI pThis, const char *pszDeviceProps)
     2330static int efiParseDeviceString(PDEVEFIR3 pThisCC, const char *pszDeviceProps)
    22632331{
    22642332    uint32_t const cbOut = (uint32_t)RTStrNLen(pszDeviceProps, RTSTR_MAX) / 2 + 1;
    2265     pThis->pbDeviceProps = (uint8_t *)PDMDevHlpMMHeapAlloc(pThis->pDevIns, cbOut);
    2266     if (!pThis->pbDeviceProps)
     2333    pThisCC->pbDeviceProps = (uint8_t *)PDMDevHlpMMHeapAlloc(pThisCC->pDevIns, cbOut);
     2334    if (!pThisCC->pbDeviceProps)
    22672335        return VERR_NO_MEMORY;
    22682336
     
    22792347            u8Value = u8Hb << 4;
    22802348        else
    2281             pThis->pbDeviceProps[iHex++] = u8Hb | u8Value;
     2349            pThisCC->pbDeviceProps[iHex++] = u8Hb | u8Value;
    22822350
    22832351        Assert(iHex < cbOut);
     
    22862354
    22872355    Assert(iHex == 0 || fUpper);
    2288     pThis->cbDeviceProps = iHex;
     2356    pThisCC->cbDeviceProps = iHex;
    22892357
    22902358    return VINF_SUCCESS;
     
    22972365static DECLCALLBACK(int)  efiConstruct(PPDMDEVINS pDevIns, int iInstance, PCFGMNODE pCfg)
    22982366{
     2367    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
     2368    PDEVEFI         pThis   = PDMINS_2_DATA(pDevIns, PDEVEFI);
     2369    PDEVEFIR3       pThisCC = PDMINS_2_DATA_CC(pDevIns, PDEVEFIR3);
     2370    PCPDMDEVHLPR3   pHlp    = pDevIns->pHlpR3;
     2371    int             rc;
     2372
    22992373    RT_NOREF(iInstance);
    2300     PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
    2301     PDEVEFI     pThis = PDMINS_2_DATA(pDevIns, PDEVEFI);
    2302     int         rc;
    2303 
    23042374    Assert(iInstance == 0);
    23052375
     
    23072377     * Initalize the basic variables so that the destructor always works.
    23082378     */
    2309     pThis->pDevIns = pDevIns;
    2310     RTListInit(&pThis->NVRAM.VarList);
    2311     pThis->Lun0.IBase.pfnQueryInterface = devEfiQueryInterface;
    2312 
     2379    pThisCC->pDevIns = pDevIns;
     2380    RTListInit(&pThisCC->NVRAM.VarList);
     2381    pThisCC->Lun0.IBase.pfnQueryInterface = devEfiQueryInterface;
    23132382
    23142383    /*
    23152384     * Validate and read the configuration.
    23162385     */
    2317     if (!CFGMR3AreValuesValid(pCfg,
    2318                               "EfiRom\0"
    2319                               "NumCPUs\0"
    2320                               "McfgBase\0"
    2321                               "McfgLength\0"
    2322                               "UUID\0"
    2323                               "IOAPIC\0"
    2324                               "APIC\0"
    2325                               "DmiBIOSFirmwareMajor\0"
    2326                               "DmiBIOSFirmwareMinor\0"
    2327                               "DmiBIOSReleaseDate\0"
    2328                               "DmiBIOSReleaseMajor\0"
    2329                               "DmiBIOSReleaseMinor\0"
    2330                               "DmiBIOSVendor\0"
    2331                               "DmiBIOSVersion\0"
    2332                               "DmiSystemFamily\0"
    2333                               "DmiSystemProduct\0"
    2334                               "DmiSystemSerial\0"
    2335                               "DmiSystemSKU\0"
    2336                               "DmiSystemUuid\0"
    2337                               "DmiSystemVendor\0"
    2338                               "DmiSystemVersion\0"
    2339                               "DmiBoardAssetTag\0"
    2340                               "DmiBoardBoardType\0"
    2341                               "DmiBoardLocInChass\0"
    2342                               "DmiBoardProduct\0"
    2343                               "DmiBoardSerial\0"
    2344                               "DmiBoardVendor\0"
    2345                               "DmiBoardVersion\0"
    2346                               "DmiChassisAssetTag\0"
    2347                               "DmiChassisSerial\0"
    2348                               "DmiChassisType\0"
    2349                               "DmiChassisVendor\0"
    2350                               "DmiChassisVersion\0"
    2351                               "DmiProcManufacturer\0"
    2352                               "DmiProcVersion\0"
    2353                               "DmiOEMVBoxVer\0"
    2354                               "DmiOEMVBoxRev\0"
    2355                               "DmiUseHostInfo\0"
    2356                               "DmiExposeMemoryTable\0"
    2357                               "DmiExposeProcInf\0"
    2358                               "64BitEntry\0"
    2359                               "BootArgs\0"
    2360                               "DeviceProps\0"
    2361                               "GopMode\0"                   // legacy
    2362                               "GraphicsMode\0"
    2363                               "UgaHorizontalResolution\0"   // legacy
    2364                               "UgaVerticalResolution\0"     // legacy
    2365                               "GraphicsResolution\0"
    2366                               "NvramFile\0"))
    2367         return PDMDEV_SET_ERROR(pDevIns, VERR_PDM_DEVINS_UNKNOWN_CFG_VALUES,
    2368                                 N_("Configuration error: Invalid config value(s) for the EFI device"));
     2386    PDMDEV_VALIDATE_CONFIG_RETURN(pDevIns,
     2387                                  "EfiRom|"
     2388                                  "NumCPUs|"
     2389                                  "McfgBase|"
     2390                                  "McfgLength|"
     2391                                  "UUID|"
     2392                                  "IOAPIC|"
     2393                                  "APIC|"
     2394                                  "DmiBIOSFirmwareMajor|"
     2395                                  "DmiBIOSFirmwareMinor|"
     2396                                  "DmiBIOSReleaseDate|"
     2397                                  "DmiBIOSReleaseMajor|"
     2398                                  "DmiBIOSReleaseMinor|"
     2399                                  "DmiBIOSVendor|"
     2400                                  "DmiBIOSVersion|"
     2401                                  "DmiSystemFamily|"
     2402                                  "DmiSystemProduct|"
     2403                                  "DmiSystemSerial|"
     2404                                  "DmiSystemSKU|"
     2405                                  "DmiSystemUuid|"
     2406                                  "DmiSystemVendor|"
     2407                                  "DmiSystemVersion|"
     2408                                  "DmiBoardAssetTag|"
     2409                                  "DmiBoardBoardType|"
     2410                                  "DmiBoardLocInChass|"
     2411                                  "DmiBoardProduct|"
     2412                                  "DmiBoardSerial|"
     2413                                  "DmiBoardVendor|"
     2414                                  "DmiBoardVersion|"
     2415                                  "DmiChassisAssetTag|"
     2416                                  "DmiChassisSerial|"
     2417                                  "DmiChassisType|"
     2418                                  "DmiChassisVendor|"
     2419                                  "DmiChassisVersion|"
     2420                                  "DmiProcManufacturer|"
     2421                                  "DmiProcVersion|"
     2422                                  "DmiOEMVBoxVer|"
     2423                                  "DmiOEMVBoxRev|"
     2424                                  "DmiUseHostInfo|"
     2425                                  "DmiExposeMemoryTable|"
     2426                                  "DmiExposeProcInf|"
     2427                                  "64BitEntry|"
     2428                                  "BootArgs|"
     2429                                  "DeviceProps|"
     2430                                  "GopMode|"                   // legacy
     2431                                  "GraphicsMode|"
     2432                                  "UgaHorizontalResolution|"   // legacy
     2433                                  "UgaVerticalResolution|"     // legacy
     2434                                  "GraphicsResolution|"
     2435                                  "NvramFile", "");
    23692436
    23702437    /* CPU count (optional). */
    2371     rc = CFGMR3QueryU32Def(pCfg, "NumCPUs", &pThis->cCpus, 1);
     2438    rc = pHlp->pfnCFGMQueryU32Def(pCfg, "NumCPUs", &pThisCC->cCpus, 1);
    23722439    AssertLogRelRCReturn(rc, rc);
    23732440
    2374     rc = CFGMR3QueryU64Def(pCfg, "McfgBase", &pThis->u64McfgBase, 0);
     2441    rc = pHlp->pfnCFGMQueryU64Def(pCfg, "McfgBase", &pThisCC->u64McfgBase, 0);
    23752442    if (RT_FAILURE(rc))
    23762443        return PDMDEV_SET_ERROR(pDevIns, rc,
    23772444                                N_("Configuration error: Querying \"\" as integer failed"));
    2378     rc = CFGMR3QueryU64Def(pCfg, "McfgLength", &pThis->cbMcfgLength, 0);
     2445    rc = pHlp->pfnCFGMQueryU64Def(pCfg, "McfgLength", &pThisCC->cbMcfgLength, 0);
    23792446    if (RT_FAILURE(rc))
    23802447        return PDMDEV_SET_ERROR(pDevIns, rc,
    23812448                                N_("Configuration error: Querying \"McfgLength\" as integer failed"));
    23822449
    2383     rc = CFGMR3QueryU8Def(pCfg, "IOAPIC", &pThis->u8IOAPIC, 1);
     2450    rc = pHlp->pfnCFGMQueryU8Def(pCfg, "IOAPIC", &pThisCC->u8IOAPIC, 1);
    23842451    if (RT_FAILURE (rc))
    23852452        return PDMDEV_SET_ERROR(pDevIns, rc,
    23862453                                N_("Configuration error: Failed to read \"IOAPIC\""));
    23872454
    2388     rc = CFGMR3QueryU8Def(pCfg, "APIC", &pThis->u8APIC, 1);
     2455    rc = pHlp->pfnCFGMQueryU8Def(pCfg, "APIC", &pThisCC->u8APIC, 1);
    23892456    if (RT_FAILURE (rc))
    23902457        return PDMDEV_SET_ERROR(pDevIns, rc,
     
    23952462     */
    23962463    RTUUID  uuid;
    2397     rc = CFGMR3QueryBytes(pCfg, "UUID", &uuid, sizeof(uuid));
     2464    rc = pHlp->pfnCFGMQueryBytes(pCfg, "UUID", &uuid, sizeof(uuid));
    23982465    if (RT_FAILURE(rc))
    23992466        return PDMDEV_SET_ERROR(pDevIns, rc,
     
    24072474    uuid.Gen.u16TimeMid = RT_H2BE_U16(uuid.Gen.u16TimeMid);
    24082475    uuid.Gen.u16TimeHiAndVersion = RT_H2BE_U16(uuid.Gen.u16TimeHiAndVersion);
    2409     memcpy(&pThis->aUuid, &uuid, sizeof pThis->aUuid);
     2476    memcpy(&pThisCC->aUuid, &uuid, sizeof pThisCC->aUuid);
    24102477
    24112478    /*
     
    24132480     */
    24142481#ifdef VBOX_WITH_EFI_IN_DD2
    2415     rc = CFGMR3QueryStringAllocDef(pCfg, "EfiRom", &pThis->pszEfiRomFile, g_szEfiBuiltin32);
     2482    rc = pHlp->pfnCFGMQueryStringAllocDef(pCfg, "EfiRom", &pThisCC->pszEfiRomFile, g_szEfiBuiltin32);
    24162483    if (RT_FAILURE(rc))
    24172484#else
    2418     rc = CFGMR3QueryStringAlloc(pCfg, "EfiRom", &pThis->pszEfiRomFile);
     2485    rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "EfiRom", &pThisCC->pszEfiRomFile);
    24192486    if (rc == VERR_CFGM_VALUE_NOT_FOUND)
    24202487    {
    2421         pThis->pszEfiRomFile = (char *)PDMDevHlpMMHeapAlloc(pDevIns, RTPATH_MAX);
    2422         AssertReturn(pThis->pszEfiRomFile, VERR_NO_MEMORY);
    2423         rc = RTPathAppPrivateArchTop(pThis->pszEfiRomFile, RTPATH_MAX);
     2488        pThisCC->pszEfiRomFile = (char *)PDMDevHlpMMHeapAlloc(pDevIns, RTPATH_MAX);
     2489        AssertReturn(pThisCC->pszEfiRomFile, VERR_NO_MEMORY);
     2490        rc = RTPathAppPrivateArchTop(pThisCC->pszEfiRomFile, RTPATH_MAX);
    24242491        AssertRCReturn(rc, rc);
    2425         rc = RTPathAppend(pThis->pszEfiRomFile, RTPATH_MAX, "VBoxEFI32.fd");
     2492        rc = RTPathAppend(pThisCC->pszEfiRomFile, RTPATH_MAX, "VBoxEFI32.fd");
    24262493        AssertRCReturn(rc, rc);
    24272494    }
     
    24342501     * NVRAM processing.
    24352502     */
    2436     rc = PDMDevHlpSSMRegister(pDevIns, EFI_SSM_VERSION, sizeof(*pThis), efiSaveExec, efiLoadExec);
     2503    rc = PDMDevHlpSSMRegister(pDevIns, EFI_SSM_VERSION, sizeof(*pThisCC), efiSaveExec, efiLoadExec);
    24372504    AssertRCReturn(rc, rc);
    24382505
    2439     rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThis->Lun0.IBase, &pThis->Lun0.pDrvBase, "NvramStorage");
     2506    rc = PDMDevHlpDriverAttach(pDevIns, 0, &pThisCC->Lun0.IBase, &pThisCC->Lun0.pDrvBase, "NvramStorage");
    24402507    if (RT_SUCCESS(rc))
    24412508    {
    2442         pThis->Lun0.pNvramDrv = PDMIBASE_QUERY_INTERFACE(pThis->Lun0.pDrvBase, PDMINVRAMCONNECTOR);
    2443         AssertPtrReturn(pThis->Lun0.pNvramDrv, VERR_PDM_MISSING_INTERFACE_BELOW);
    2444 
    2445         rc = nvramLoad(pThis);
     2509        pThisCC->Lun0.pNvramDrv = PDMIBASE_QUERY_INTERFACE(pThisCC->Lun0.pDrvBase, PDMINVRAMCONNECTOR);
     2510        AssertPtrReturn(pThisCC->Lun0.pNvramDrv, VERR_PDM_MISSING_INTERFACE_BELOW);
     2511
     2512        rc = nvramLoad(pThisCC);
    24462513        AssertRCReturn(rc, rc);
    24472514    }
    24482515    else if (rc == VERR_PDM_NO_ATTACHED_DRIVER)
    24492516    {
    2450         pThis->Lun0.pNvramDrv = NULL;
     2517        pThisCC->Lun0.pNvramDrv = NULL;
    24512518        rc = VINF_SUCCESS; /* Missing driver is no error condition. */
    24522519    }
     
    24572524     * Get boot args.
    24582525     */
    2459     rc = CFGMR3QueryStringDef(pCfg, "BootArgs", pThis->szBootArgs, sizeof(pThis->szBootArgs), "");
     2526    rc = pHlp->pfnCFGMQueryStringDef(pCfg, "BootArgs", pThisCC->szBootArgs, sizeof(pThisCC->szBootArgs), "");
    24602527    if (RT_FAILURE(rc))
    24612528        return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
    24622529                                   N_("Configuration error: Querying \"BootArgs\" as a string failed"));
    24632530
    2464     //strcpy(pThis->szBootArgs, "-v keepsyms=1 io=0xf debug=0x2a");
    2465     //strcpy(pThis->szBootArgs, "-v keepsyms=1 debug=0x2a");
    2466     LogRel(("EFI: boot args = %s\n", pThis->szBootArgs));
     2531    //strcpy(pThisCC->szBootArgs, "-v keepsyms=1 io=0xf debug=0x2a");
     2532    //strcpy(pThisCC->szBootArgs, "-v keepsyms=1 debug=0x2a");
     2533    LogRel(("EFI: boot args = %s\n", pThisCC->szBootArgs));
    24672534
    24682535    /*
     
    24702537     */
    24712538    char *pszDeviceProps;
    2472     rc = CFGMR3QueryStringAllocDef(pCfg, "DeviceProps", &pszDeviceProps, NULL);
     2539    rc = pHlp->pfnCFGMQueryStringAllocDef(pCfg, "DeviceProps", &pszDeviceProps, NULL);
    24732540    if (RT_FAILURE(rc))
    24742541        return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
     
    24772544    {
    24782545        LogRel(("EFI: device props = %s\n", pszDeviceProps));
    2479         rc = efiParseDeviceString(pThis, pszDeviceProps);
    2480         MMR3HeapFree(pszDeviceProps);
     2546        rc = efiParseDeviceString(pThisCC, pszDeviceProps);
     2547        PDMDevHlpMMHeapFree(pDevIns, pszDeviceProps);
    24812548        if (RT_FAILURE(rc))
    24822549            return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
     
    24852552    else
    24862553    {
    2487         pThis->pbDeviceProps = NULL;
    2488         pThis->cbDeviceProps = 0;
     2554        pThisCC->pbDeviceProps = NULL;
     2555        pThisCC->cbDeviceProps = 0;
    24892556    }
    24902557
     
    24922559     * CPU frequencies.
    24932560     */
    2494     pThis->u64TscFrequency = TMCpuTicksPerSecond(PDMDevHlpGetVM(pDevIns));
    2495     pThis->u64CpuFrequency = pThis->u64TscFrequency;
    2496     pThis->u64FsbFrequency = CPUMGetGuestScalableBusFrequency(PDMDevHlpGetVM(pDevIns));
     2561    pThisCC->u64TscFrequency = TMCpuTicksPerSecond(PDMDevHlpGetVM(pDevIns));
     2562    pThisCC->u64CpuFrequency = pThisCC->u64TscFrequency;
     2563    pThisCC->u64FsbFrequency = CPUMGetGuestScalableBusFrequency(PDMDevHlpGetVM(pDevIns));
    24972564
    24982565    /*
     
    25002567     * old EFI VGA code the only way to select the GOP mode).
    25012568     */
    2502     rc = CFGMR3QueryU32Def(pCfg, "GraphicsMode", &pThis->u32GraphicsMode, UINT32_MAX);
     2569    rc = pHlp->pfnCFGMQueryU32Def(pCfg, "GraphicsMode", &pThisCC->u32GraphicsMode, UINT32_MAX);
    25032570    if (RT_FAILURE(rc))
    25042571        return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
    25052572                                   N_("Configuration error: Querying \"GraphicsMode\" as a 32-bit int failed"));
    2506     if (pThis->u32GraphicsMode == UINT32_MAX)
     2573    if (pThisCC->u32GraphicsMode == UINT32_MAX)
    25072574    {
    25082575        /* get the legacy value if nothing else was specified */
    2509         rc = CFGMR3QueryU32Def(pCfg, "GopMode", &pThis->u32GraphicsMode, UINT32_MAX);
     2576        rc = pHlp->pfnCFGMQueryU32Def(pCfg, "GopMode", &pThisCC->u32GraphicsMode, UINT32_MAX);
    25102577        if (RT_FAILURE(rc))
    25112578            return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
    25122579                                       N_("Configuration error: Querying \"GopMode\" as a 32-bit int failed"));
    25132580    }
    2514     if (pThis->u32GraphicsMode == UINT32_MAX)
    2515         pThis->u32GraphicsMode = 2; /* 1024x768, at least typically */
     2581    if (pThisCC->u32GraphicsMode == UINT32_MAX)
     2582        pThisCC->u32GraphicsMode = 2; /* 1024x768, at least typically */
    25162583
    25172584    /*
     
    25202587     */
    25212588    char szResolution[16];
    2522     rc = CFGMR3QueryStringDef(pCfg, "GraphicsResolution", szResolution, sizeof(szResolution), "");
     2589    rc = pHlp->pfnCFGMQueryStringDef(pCfg, "GraphicsResolution", szResolution, sizeof(szResolution), "");
    25232590    if (RT_FAILURE(rc))
    25242591        return PDMDevHlpVMSetError(pDevIns, rc, RT_SRC_POS,
     
    25292596        if (pszX)
    25302597        {
    2531             pThis->u32HorizontalResolution = RTStrToUInt32(szResolution);
    2532             pThis->u32VerticalResolution = RTStrToUInt32(pszX + 1);
     2598            pThisCC->u32HorizontalResolution = RTStrToUInt32(szResolution);
     2599            pThisCC->u32VerticalResolution = RTStrToUInt32(pszX + 1);
    25332600        }
    25342601    }
     
    25362603    {
    25372604        /* get the legacy values if nothing else was specified */
    2538         rc = CFGMR3QueryU32Def(pCfg, "UgaHorizontalResolution", &pThis->u32HorizontalResolution, 0);
     2605        rc = pHlp->pfnCFGMQueryU32Def(pCfg, "UgaHorizontalResolution", &pThisCC->u32HorizontalResolution, 0);
    25392606        AssertRCReturn(rc, rc);
    2540         rc = CFGMR3QueryU32Def(pCfg, "UgaVerticalResolution", &pThis->u32VerticalResolution, 0);
     2607        rc = pHlp->pfnCFGMQueryU32Def(pCfg, "UgaVerticalResolution", &pThisCC->u32VerticalResolution, 0);
    25412608        AssertRCReturn(rc, rc);
    25422609    }
    2543     if (pThis->u32HorizontalResolution == 0 || pThis->u32VerticalResolution == 0)
    2544     {
    2545         pThis->u32HorizontalResolution = 1024;
    2546         pThis->u32VerticalResolution = 768;
    2547     }
    2548 
    2549     pThis->pszNvramFile = NULL;
    2550     rc = CFGMR3QueryStringAlloc(pCfg, "NvramFile", &pThis->pszNvramFile);
     2610    if (pThisCC->u32HorizontalResolution == 0 || pThisCC->u32VerticalResolution == 0)
     2611    {
     2612        pThisCC->u32HorizontalResolution = 1024;
     2613        pThisCC->u32VerticalResolution = 768;
     2614    }
     2615
     2616    pThisCC->pszNvramFile = NULL;
     2617    rc = pHlp->pfnCFGMQueryStringAlloc(pCfg, "NvramFile", &pThisCC->pszNvramFile);
    25512618    if (RT_FAILURE(rc) && rc != VERR_CFGM_VALUE_NOT_FOUND)
    25522619        return PDMDEV_SET_ERROR(pDevIns, rc,
     
    25562623     * Load firmware volume and thunk ROM.
    25572624     */
    2558     rc = efiLoadRom(pThis, pCfg);
     2625    rc = efiLoadRom(pDevIns, pThis, pThisCC, pCfg);
    25592626    if (RT_FAILURE(rc))
    25602627        return rc;
     
    25722639     * Plant DMI and MPS tables in the ROM region.
    25732640     */
    2574     rc = FwCommonPlantDMITable(pDevIns, pThis->au8DMIPage, VBOX_DMI_TABLE_SIZE, &pThis->aUuid,
    2575                                pDevIns->pCfg, pThis->cCpus, &pThis->cbDmiTables, &pThis->cNumDmiTables);
     2641    rc = FwCommonPlantDMITable(pDevIns, pThisCC->au8DMIPage, VBOX_DMI_TABLE_SIZE, &pThisCC->aUuid,
     2642                               pDevIns->pCfg, pThisCC->cCpus, &pThisCC->cbDmiTables, &pThisCC->cNumDmiTables);
    25762643    AssertRCReturn(rc, rc);
    25772644
     
    25802647     * the SMBIOS header. The header must be placed in a range that EFI will scan.
    25812648     */
    2582     FwCommonPlantSmbiosAndDmiHdrs(pDevIns, pThis->au8DMIPage + VBOX_DMI_TABLE_SIZE,
    2583                                   pThis->cbDmiTables, pThis->cNumDmiTables);
    2584 
    2585     if (pThis->u8IOAPIC)
     2649    FwCommonPlantSmbiosAndDmiHdrs(pDevIns, pThisCC->au8DMIPage + VBOX_DMI_TABLE_SIZE,
     2650                                  pThisCC->cbDmiTables, pThisCC->cNumDmiTables);
     2651
     2652    if (pThisCC->u8IOAPIC)
    25862653    {
    25872654        FwCommonPlantMpsTable(pDevIns,
    2588                               pThis->au8DMIPage /* aka VBOX_DMI_TABLE_BASE */ + VBOX_DMI_TABLE_SIZE + VBOX_DMI_HDR_SIZE,
    2589                               _4K - VBOX_DMI_TABLE_SIZE - VBOX_DMI_HDR_SIZE, pThis->cCpus);
     2655                              pThisCC->au8DMIPage /* aka VBOX_DMI_TABLE_BASE */ + VBOX_DMI_TABLE_SIZE + VBOX_DMI_HDR_SIZE,
     2656                              _4K - VBOX_DMI_TABLE_SIZE - VBOX_DMI_HDR_SIZE, pThisCC->cCpus);
    25902657        FwCommonPlantMpsFloatPtr(pDevIns, VBOX_DMI_TABLE_BASE + VBOX_DMI_TABLE_SIZE + VBOX_DMI_HDR_SIZE);
    25912658    }
    25922659
    2593     rc = PDMDevHlpROMRegister(pDevIns, VBOX_DMI_TABLE_BASE, _4K, pThis->au8DMIPage, _4K,
     2660    rc = PDMDevHlpROMRegister(pDevIns, VBOX_DMI_TABLE_BASE, _4K, pThisCC->au8DMIPage, _4K,
    25942661                              PGMPHYS_ROM_FLAGS_PERMANENT_BINARY, "DMI tables");
    25952662
     
    26102677}
    26112678
     2679#else  /* IN_RING3 */
     2680
     2681
     2682/**
     2683 * @callback_method_impl{PDMDEVREGR0,pfnConstruct}
     2684 */
     2685static DECLCALLBACK(int)  efiRZConstruct(PPDMDEVINS pDevIns)
     2686{
     2687    PDMDEV_CHECK_VERSIONS_RETURN(pDevIns);
     2688    PDEVEFI   pThis   = PDMINS_2_DATA(pDevIns, PDEVEFI);
     2689
     2690# if 0
     2691    int rc = PDMDevHlpMmioSetUpContext(pDevIns, pThis->hMmioFlash, efiR3NvMmioWrite, efiR3NvMmioRead, NULL /*pvUser*/);
     2692    AssertRCReturn(rc, rc);
     2693# else
     2694    RT_NOREF(pDevIns, pThis);
     2695# endif
     2696
     2697    return VINF_SUCCESS;
     2698}
     2699
     2700
     2701#endif /* IN_RING3 */
    26122702
    26132703/**
     
    26192709    /* .uReserved0 = */             0,
    26202710    /* .szName = */                 "efi",
    2621     /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS,
     2711    /* .fFlags = */                 PDM_DEVREG_FLAGS_DEFAULT_BITS | PDM_DEVREG_FLAGS_R0 | PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_NEW_STYLE,
    26222712    /* .fClass = */                 PDM_DEVREG_CLASS_ARCH_BIOS,
    26232713    /* .cMaxInstances = */          1,
    26242714    /* .uSharedVersion = */         42,
    26252715    /* .cbInstanceShared = */       sizeof(DEVEFI),
    2626     /* .cbInstanceCC = */           0,
    2627     /* .cbInstanceRC = */           0,
     2716    /* .cbInstanceCC = */           sizeof(DEVEFICC),
     2717    /* .cbInstanceRC = */           sizeof(DEVEFIRC),
    26282718    /* .cMaxPciDevices = */         0,
    26292719    /* .cMaxMsixVectors = */        0,
     
    26312721                                    "LUN#0 - NVRAM port",
    26322722#if defined(IN_RING3)
    2633     /* .pszRCMod = */               "",
    2634     /* .pszR0Mod = */               "",
     2723    /* .pszRCMod = */               "VBoxDDRC.rc",
     2724    /* .pszR0Mod = */               "VBoxDDR0.r0",
    26352725    /* .pfnConstruct = */           efiConstruct,
    26362726    /* .pfnDestruct = */            efiDestruct,
     
    26572747#elif defined(IN_RING0)
    26582748    /* .pfnEarlyConstruct = */      NULL,
    2659     /* .pfnConstruct = */           NULL,
     2749    /* .pfnConstruct = */           efiRZConstruct,
    26602750    /* .pfnDestruct = */            NULL,
    26612751    /* .pfnFinalDestruct = */       NULL,
     
    26702760    /* .pfnReserved7 = */           NULL,
    26712761#elif defined(IN_RC)
    2672     /* .pfnConstruct = */           NULL,
     2762    /* .pfnConstruct = */           efiRZConstruct,
    26732763    /* .pfnReserved0 = */           NULL,
    26742764    /* .pfnReserved1 = */           NULL,
  • trunk/src/VBox/Devices/EFI/DevFlash.cpp

    r81250 r81502  
    7575    RT_NOREF1(pvUser);
    7676
    77     return flashWrite(&pThis->Core, GCPhysAddr - pThis->GCPhysFlashBase, pv, cb);
     77    return VBOXSTRICTRC_TODO(flashWrite(&pThis->Core, GCPhysAddr - pThis->GCPhysFlashBase, pv, cb));
    7878}
    7979
     
    8585    RT_NOREF1(pvUser);
    8686
    87     return flashRead(&pThis->Core, GCPhysAddr - pThis->GCPhysFlashBase, pv, cb);
     87    return VBOXSTRICTRC_TODO(flashRead(&pThis->Core, GCPhysAddr - pThis->GCPhysFlashBase, pv, cb));
    8888}
    8989
     
    9797    PDEVFLASH pThis = PDMINS_2_DATA(pDevIns, PDEVFLASH);
    9898
    99     int rc = flashR3SsmSaveExec(&pThis->Core, pSSM);
     99    int rc = flashR3SaveExec(&pThis->Core, pDevIns, pSSM);
    100100    if (RT_SUCCESS(rc))
    101101        pThis->fStateSaved = true;
     
    115115        return VERR_SSM_UNSUPPORTED_DATA_UNIT_VERSION;
    116116
    117     return flashR3SsmLoadExec(&pThis->Core, pSSM);
     117    return flashR3LoadExec(&pThis->Core, pDevIns, pSSM);
    118118}
    119119
     
    138138    if (!pThis->fStateSaved)
    139139    {
    140         rc = flashR3SaveToFile(&pThis->Core, pThis->pszFlashFile);
     140        rc = flashR3SaveToFile(&pThis->Core, pDevIns, pThis->pszFlashFile);
    141141        if (RT_FAILURE(rc))
    142142            LogRel(("Flash: Failed to save flash file"));
     
    149149    }
    150150
    151     flashR3Destruct(&pThis->Core);
     151    flashR3Destruct(&pThis->Core, pDevIns);
    152152    return VINF_SUCCESS;
    153153}
     
    210210
    211211    /* Try to load the flash content from file. */
    212     rc = flashR3LoadFromFile(&pThis->Core, pThis->pszFlashFile);
     212    rc = flashR3LoadFromFile(&pThis->Core, pDevIns, pThis->pszFlashFile);
    213213    if (RT_FAILURE(rc))
    214214        return PDMDEV_SET_ERROR(pDevIns, rc,
  • trunk/src/VBox/Devices/EFI/FlashCore.cpp

    r81485 r81502  
    7171
    7272
    73 #ifdef IN_RING3 /* for now */
    74 
     73
     74/**
     75 * Worker for flashWrite that deals with a single byte.
     76 *
     77 * @retval  VINF_SUCCESS on success, which is always the case in ring-3.
     78 * @retval  VINF_IOM_R3_MMIO_WRITE can be returned when not in ring-3.
     79 */
    7580static int flashMemWriteByte(PFLASHCORE pThis, uint32_t off, uint8_t bCmd)
    7681{
    77     int rc = VINF_SUCCESS;
    78     unsigned uOffset;
    79 
    8082    /* NB: Older datasheets (e.g. 28F008SA) suggest that for two-cycle commands like byte write or
    8183     * erase setup, the address is significant in both cycles, but do not explain what happens
     
    121123            case FLASH_CMD_WRITE:
    122124            case FLASH_CMD_ALT_WRITE:
    123                 uOffset = off;
    124                 if (uOffset < pThis->cbFlashSize)
     125                if (off < pThis->cbFlashSize)
    125126                {
    126                     pThis->pbFlash[uOffset] = bCmd;
     127#ifdef IN_RING3
     128                    pThis->pbFlash[off] = bCmd;
    127129                    /* NB: Writes are instant and never fail. */
    128130                    LogFunc(("wrote byte to flash at %08RX32: %02X\n", off, bCmd));
     131#else
     132                    return VINF_IOM_R3_MMIO_WRITE;
     133#endif
    129134                }
    130135                else
     
    134139                if (bCmd == FLASH_CMD_ERASE_CONFIRM)
    135140                {
     141#ifdef IN_RING3
    136142                    /* The current address determines the block to erase. */
    137                     uOffset = off & ~(pThis->cbBlockSize - 1);
     143                    unsigned uOffset = off & ~(pThis->cbBlockSize - 1);
    138144                    memset(pThis->pbFlash + uOffset, 0xff, pThis->cbBlockSize);
    139145                    LogFunc(("Erasing block at offset %u\n", uOffset));
     146#else
     147                    return VINF_IOM_R3_MMIO_WRITE;
     148#endif
    140149                }
    141150                else
     
    153162        pThis->cBusCycle = 0;
    154163    }
    155     LogFlow(("flashMemWriteByte: write access at %08RX32: %#x rc=%Rrc\n", off, bCmd, rc));
    156     return rc;
    157 }
    158 
    159 
     164    LogFlow(("flashMemWriteByte: write access at %08RX32: %#x\n", off, bCmd));
     165    return VINF_SUCCESS;
     166}
     167
     168/**
     169 * Performs a write to the given flash offset.
     170 *
     171 * Parent device calls this from its MMIO write callback.
     172 *
     173 * @returns Strict VBox status code.
     174 * @retval  VINF_SUCCESS on success, which is always the case in ring-3.
     175 * @retval  VINF_IOM_R3_MMIO_WRITE can be returned when not in ring-3.
     176 *
     177 * @param   pThis               The UART core instance.
     178 * @param   off                 Offset to start writing to.
     179 * @param   pv                  The value to write.
     180 * @param   cb                  Number of bytes to write.
     181 */
     182DECLHIDDEN(VBOXSTRICTRC) flashWrite(PFLASHCORE pThis, uint32_t off, const void *pv, size_t cb)
     183{
     184    const uint8_t *pbSrc = (const uint8_t *)pv;
     185
     186#ifndef IN_RING3
     187    /*
     188     * If multiple bytes are written, just go to ring-3 and do it there as it's
     189     * too much trouble to validate the sequence in adanvce and it is usually
     190     * not restartable as device state changes.
     191     */
     192    VBOXSTRICTRC rcStrict;
     193    if (cb == 1)
     194    {
     195        rcStrict = flashMemWriteByte(pThis, off, *pbSrc);
     196        if (rcStrict == VINF_SUCCESS)
     197            LogFlow(("flashWrite: completed write at %08RX32 (LB %u)\n", off, cb));
     198        else
     199            LogFlow(("flashWrite: incomplete write at %08RX32 (LB %u): rc=%Rrc bCmd=%#x cBusCycle=%u\n",
     200                     off, cb, VBOXSTRICTRC_VAL(rcStrict), *pbSrc, pThis->cBusCycle));
     201    }
     202    else
     203    {
     204        LogFlow(("flashWrite: deferring multi-byte write at %08RX32 (LB %u) to ring-3\n", off, cb));
     205        rcStrict = VINF_IOM_R3_IOPORT_WRITE;
     206    }
     207    return rcStrict;
     208
     209#else  /* IN_RING3 */
     210
     211    for (uint32_t offWrite = 0; offWrite < cb; ++offWrite)
     212        flashMemWriteByte(pThis, off + offWrite, pbSrc[offWrite]);
     213
     214    LogFlow(("flashWrite: completed write at %08RX32 (LB %u)\n", off, cb));
     215    return VINF_SUCCESS;
     216#endif /* IN_RING3 */
     217}
     218
     219/**
     220 * Worker for flashRead that deals with a single byte.
     221 *
     222 * @retval  VINF_SUCCESS on success, which is always the case in ring-3.
     223 * @retval  VINF_IOM_R3_MMIO_READ can be returned when not in ring-3.
     224 */
    160225static int flashMemReadByte(PFLASHCORE pThis, uint32_t off, uint8_t *pbData)
    161226{
    162227    uint8_t bValue;
    163     int rc = VINF_SUCCESS;
    164228
    165229    /*
     
    171235        case FLASH_CMD_ARRAY_READ:
    172236            if (off < pThis->cbFlashSize)
     237#ifdef IN_RING3
    173238                bValue = pThis->pbFlash[off];
     239#else
     240                return VINF_IOM_R3_MMIO_READ;
     241#endif
    174242            else
    175243                bValue = 0xff; /* Play safe and return the default value of non initialized flash. */
     
    188256    *pbData = bValue;
    189257
    190     LogFlow(("flashMemReadByte: read access at %08RX32: %02X (cmd=%02X) rc=%Rrc\n", off, bValue, pThis->bCmd, rc));
    191     return rc;
    192 }
    193 
    194 DECLHIDDEN(int) flashWrite(PFLASHCORE pThis, uint32_t off, const void *pv, size_t cb)
    195 {
    196     int rc = VINF_SUCCESS;
    197     const uint8_t *pu8Mem = (const uint8_t *)pv;
    198 
    199 #ifndef IN_RING3
    200     if (cb > 1)
    201         return VINF_IOM_R3_IOPORT_WRITE;
     258    LogFlow(("flashMemReadByte: read access at %08RX32: %02X (cmd=%02X)\n", off, bValue, pThis->bCmd));
     259    return VINF_SUCCESS;
     260}
     261
     262/**
     263 * Performs a read from the given flash offset.
     264 *
     265 * Parent device calls this from its MMIO read callback.
     266 *
     267 * @returns Strict VBox status code.
     268 * @retval  VINF_SUCCESS on success, which is always the case in ring-3.
     269 * @retval  VINF_IOM_R3_MMIO_READ can be returned when not in ring-3.
     270 *
     271 * @param   pThis               The UART core instance.
     272 * @param   off                 Offset to start reading from.
     273 * @param   pv                  Where to store the read data.
     274 * @param   cb                  Number of bytes to read.
     275 */
     276DECLHIDDEN(VBOXSTRICTRC) flashRead(PFLASHCORE pThis, uint32_t off, void *pv, size_t cb)
     277{
     278    uint8_t *pbDst = (uint8_t *)pv;
     279
     280    /*
     281     * Reads do not change the device state, so we don't need to take any
     282     * precautions when we're not in ring-3 as the read can always be restarted.
     283     */
     284    for (uint32_t offRead = 0; offRead < cb; ++offRead)
     285    {
     286#ifdef IN_RING3
     287        flashMemReadByte(pThis, off + offRead, &pbDst[offRead]);
     288#else
     289        VBOXSTRICTRC rcStrict = flashMemReadByte(pThis, off + offRead, &pbDst[offRead]);
     290        if (rcStrict != VINF_SUCCESS)
     291        {
     292            LogFlow(("flashRead: incomplete read at %08RX32+%#x (LB %u): rc=%Rrc bCmd=%#x\n",
     293                     off, offRead, cb, VBOXSTRICTRC_VAL(rcStrict), pThis->bCmd));
     294            return rcStrict;
     295        }
    202296#endif
    203 
    204     for (uint32_t uOffset = 0; uOffset < cb; ++uOffset)
    205     {
    206         rc = flashMemWriteByte(pThis, off + uOffset, pu8Mem[uOffset]);
    207         if (!RT_SUCCESS(rc))
    208             break;
    209     }
    210 
    211     LogFlow(("flashWrite: completed write at %08RX32 (LB %u): rc=%Rrc\n", off, cb, rc));
    212     return rc;
    213 }
    214 
    215 DECLHIDDEN(int) flashRead(PFLASHCORE pThis, uint32_t off, void *pv, size_t cb)
    216 {
    217     int rc = VINF_SUCCESS;
    218     uint8_t *pu8Mem = (uint8_t *)pv;
    219 
    220     /*
    221      * Reading can always be done witout going back to R3. Reads do not
    222      * change the device state and we always have the data.
    223      */
    224     for (uint32_t uOffset = 0; uOffset < cb; ++uOffset, ++pu8Mem)
    225     {
    226         rc = flashMemReadByte(pThis, off + uOffset, pu8Mem);
    227         if (!RT_SUCCESS(rc))
    228             break;
    229     }
    230 
    231     LogFlow(("flashRead: completed read at %08RX32 (LB %u): rc=%Rrc\n", off, cb, rc));
    232     return rc;
    233 }
    234 
    235 #endif /* IN_RING3 for now */
     297    }
     298
     299    LogFlow(("flashRead: completed read at %08RX32 (LB %u)\n", off, cb));
     300    return VINF_SUCCESS;
     301}
    236302
    237303#ifdef IN_RING3
    238304
     305/**
     306 * Initialiizes the given flash device instance.
     307 *
     308 * @returns VBox status code.
     309 * @param   pThis               The flash device core instance.
     310 * @param   pDevIns             Pointer to the owning device instance.
     311 * @param   idFlashDev          The flash device ID.
     312 * @param   GCPhysFlashBase     Base MMIO address where the flash is located.
     313 * @param   cbFlash             Size of the flash device in bytes.
     314 * @param   cbBlock             Size of a flash block.
     315 */
    239316DECLHIDDEN(int) flashR3Init(PFLASHCORE pThis, PPDMDEVINS pDevIns, uint16_t idFlashDev, uint32_t cbFlash, uint16_t cbBlock)
    240317{
    241     pThis->pDevIns     = pDevIns;
    242318    pThis->u16FlashId  = idFlashDev;
    243319    pThis->cbBlockSize = cbBlock;
     
    257333}
    258334
    259 DECLHIDDEN(void) flashR3Destruct(PFLASHCORE pThis)
     335/**
     336 * Destroys the given flash device instance.
     337 *
     338 * @returns nothing.
     339 * @param   pDevIns             The parent device instance.
     340 * @param   pThis               The flash device core instance.
     341 */
     342DECLHIDDEN(void) flashR3Destruct(PFLASHCORE pThis, PPDMDEVINS pDevIns)
    260343{
    261344    if (pThis->pbFlash)
    262345    {
    263         PDMDevHlpMMHeapFree(pThis->pDevIns, pThis->pbFlash);
     346        PDMDevHlpMMHeapFree(pDevIns, pThis->pbFlash);
    264347        pThis->pbFlash = NULL;
    265348    }
    266349}
    267350
    268 DECLHIDDEN(int) flashR3LoadFromFile(PFLASHCORE pThis, const char *pszFilename)
     351/**
     352 * Loads the flash content from the given file.
     353 *
     354 * @returns VBox status code.
     355 * @param   pThis               The flash device core instance.
     356 * @param   pDevIns             The parent device instance.
     357 * @param   pszFilename         The file to load the flash content from.
     358 */
     359DECLHIDDEN(int) flashR3LoadFromFile(PFLASHCORE pThis, PPDMDEVINS pDevIns, const char *pszFilename)
    269360{
    270361    RTFILE hFlashFile = NIL_RTFILE;
     
    272363    int rc = RTFileOpen(&hFlashFile, pszFilename, RTFILE_O_READ | RTFILE_O_OPEN | RTFILE_O_DENY_WRITE);
    273364    if (RT_FAILURE(rc))
    274         return PDMDEV_SET_ERROR(pThis->pDevIns, rc, N_("Failed to open flash file"));
     365        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to open flash file"));
    275366
    276367    size_t cbRead = 0;
    277368    rc = RTFileRead(hFlashFile, pThis->pbFlash, pThis->cbFlashSize, &cbRead);
    278369    if (RT_FAILURE(rc))
    279         return PDMDEV_SET_ERROR(pThis->pDevIns, rc, N_("Failed to read flash file"));
     370        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to read flash file"));
    280371    Log(("Read %zu bytes from file (asked for %u)\n.", cbRead, pThis->cbFlashSize));
    281372
     
    284375}
    285376
     377/**
     378 * Loads the flash content from the given buffer.
     379 *
     380 * @returns VBox status code.
     381 * @param   pThis               The flash device core instance.
     382 * @param   pvBuf               The buffer to load the content from.
     383 * @param   cbBuf               Size of the buffer in bytes.
     384 */
    286385DECLHIDDEN(int) flashR3LoadFromBuf(PFLASHCORE pThis, void const *pvBuf, size_t cbBuf)
    287386{
     
    292391}
    293392
    294 DECLHIDDEN(int) flashR3SaveToFile(PFLASHCORE pThis, const char *pszFilename)
     393/**
     394 * Saves the flash content to the given file.
     395 *
     396 * @returns VBox status code.
     397 * @param   pThis               The flash device core instance.
     398 * @param   pDevIns             The parent device instance.
     399 * @param   pszFilename         The file to save the flash content to.
     400 */
     401DECLHIDDEN(int) flashR3SaveToFile(PFLASHCORE pThis, PPDMDEVINS pDevIns, const char *pszFilename)
    295402{
    296403    RTFILE hFlashFile = NIL_RTFILE;
     
    298405    int rc = RTFileOpen(&hFlashFile, pszFilename, RTFILE_O_READWRITE | RTFILE_O_OPEN_CREATE | RTFILE_O_DENY_WRITE);
    299406    if (RT_FAILURE(rc))
    300         return PDMDEV_SET_ERROR(pThis->pDevIns, rc, N_("Failed to open flash file"));
     407        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to open flash file"));
    301408
    302409    rc = RTFileWrite(hFlashFile, pThis->pbFlash, pThis->cbFlashSize, NULL);
     410    RTFileClose(hFlashFile);
    303411    if (RT_FAILURE(rc))
    304         return PDMDEV_SET_ERROR(pThis->pDevIns, rc, N_("Failed to write flash file"));
    305 
    306     RTFileClose(hFlashFile);
    307     return VINF_SUCCESS;
    308 }
    309 
     412        return PDMDEV_SET_ERROR(pDevIns, rc, N_("Failed to write flash file"));
     413
     414    return VINF_SUCCESS;
     415}
     416
     417/**
     418 * Saves the flash content to the given buffer.
     419 *
     420 * @returns VBox status code.
     421 * @param   pThis               The flash device core instance.
     422 * @param   pvBuf               The buffer to save the content to.
     423 * @param   cbBuf               Size of the buffer in bytes.
     424 */
    310425DECLHIDDEN(int) flashR3SaveToBuf(PFLASHCORE pThis, void *pvBuf, size_t cbBuf)
    311426{
     
    316431}
    317432
     433/**
     434 * Resets the dynamic part of the flash device state.
     435 *
     436 * @returns nothing.
     437 * @param   pThis               The flash device core instance.
     438 */
    318439DECLHIDDEN(void) flashR3Reset(PFLASHCORE pThis)
    319440{
     
    326447}
    327448
    328 DECLHIDDEN(int) flashR3SsmSaveExec(PFLASHCORE pThis, PSSMHANDLE pSSM)
    329 {
    330     SSMR3PutU32(pSSM, FLASH_SAVED_STATE_VERSION);
     449/**
     450 * Saves the flash device state to the given SSM handle.
     451 *
     452 * @returns VBox status code.
     453 * @param   pThis               The flash device core instance.
     454 * @param   pDevIns             The parent device instance.
     455 * @param   pSSM                The SSM handle to save to.
     456 */
     457DECLHIDDEN(int) flashR3SaveExec(PFLASHCORE pThis, PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
     458{
     459    PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
     460
     461    pHlp->pfnSSMPutU32(pSSM, FLASH_SAVED_STATE_VERSION);
    331462
    332463    /* Save the device state. */
    333     SSMR3PutU8(pSSM, pThis->bCmd);
    334     SSMR3PutU8(pSSM, pThis->bStatus);
    335     SSMR3PutU8(pSSM, pThis->cBusCycle);
     464    pHlp->pfnSSMPutU8(pSSM, pThis->bCmd);
     465    pHlp->pfnSSMPutU8(pSSM, pThis->bStatus);
     466    pHlp->pfnSSMPutU8(pSSM, pThis->cBusCycle);
    336467
    337468    /* Save the current configuration for validation purposes. */
    338     SSMR3PutU16(pSSM, pThis->cbBlockSize);
    339     SSMR3PutU16(pSSM, pThis->u16FlashId);
     469    pHlp->pfnSSMPutU16(pSSM, pThis->cbBlockSize);
     470    pHlp->pfnSSMPutU16(pSSM, pThis->u16FlashId);
    340471
    341472    /* Save the current flash contents. */
    342     SSMR3PutU32(pSSM, pThis->cbFlashSize);
    343     SSMR3PutMem(pSSM, pThis->pbFlash, pThis->cbFlashSize);
    344 
    345     return VINF_SUCCESS;
    346 }
    347 
    348 DECLHIDDEN(int) flashR3SsmLoadExec(PFLASHCORE pThis, PSSMHANDLE pSSM)
    349 {
     473    pHlp->pfnSSMPutU32(pSSM, pThis->cbFlashSize);
     474    return pHlp->pfnSSMPutMem(pSSM, pThis->pbFlash, pThis->cbFlashSize);
     475}
     476
     477/**
     478 * Loads the flash device state from the given SSM handle.
     479 *
     480 * @returns VBox status code.
     481 * @param   pThis               The flash device core instance.
     482 * @param   pDevIns             The parent device instance.
     483 * @param   pSSM                The SSM handle to load from.
     484 */
     485DECLHIDDEN(int) flashR3LoadExec(PFLASHCORE pThis, PPDMDEVINS pDevIns, PSSMHANDLE pSSM)
     486{
     487    PCPDMDEVHLPR3 pHlp = pDevIns->pHlpR3;
     488
    350489    uint32_t uVersion = FLASH_SAVED_STATE_VERSION;
    351     int rc = SSMR3GetU32(pSSM, &uVersion);
     490    int rc = pHlp->pfnSSMGetU32(pSSM, &uVersion);
    352491    AssertRCReturn(rc, rc);
    353492
     
    360499        uint32_t    u32Val;
    361500
    362         SSMR3GetU8(pSSM, &pThis->bCmd);
    363         SSMR3GetU8(pSSM, &pThis->bStatus);
    364         SSMR3GetU8(pSSM, &pThis->cBusCycle);
     501        pHlp->pfnSSMGetU8(pSSM, &pThis->bCmd);
     502        pHlp->pfnSSMGetU8(pSSM, &pThis->bStatus);
     503        pHlp->pfnSSMGetU8(pSSM, &pThis->cBusCycle);
    365504
    366505        /* Make sure configuration didn't change behind our back. */
    367         rc = SSMR3GetU16(pSSM, &u16Val);
     506        rc = pHlp->pfnSSMGetU16(pSSM, &u16Val);
    368507        AssertRCReturn(rc, rc);
    369508        if (u16Val != pThis->cbBlockSize)
    370509            return VERR_SSM_LOAD_CONFIG_MISMATCH;
    371         rc = SSMR3GetU16(pSSM, &u16Val);
     510        rc = pHlp->pfnSSMGetU16(pSSM, &u16Val);
    372511        AssertRCReturn(rc, rc);
    373512        if (u16Val != pThis->u16FlashId)
    374513            return VERR_SSM_LOAD_CONFIG_MISMATCH;
    375         rc = SSMR3GetU32(pSSM, &u32Val);
     514        rc = pHlp->pfnSSMGetU32(pSSM, &u32Val);
    376515        AssertRCReturn(rc, rc);
    377516        if (u32Val != pThis->cbFlashSize)
     
    379518
    380519        /* Suck in the flash contents. */
    381         rc = SSMR3GetMem(pSSM, pThis->pbFlash, pThis->cbFlashSize);
     520        rc = pHlp->pfnSSMGetMem(pSSM, pThis->pbFlash, pThis->cbFlashSize);
    382521    }
    383522    else
  • trunk/src/VBox/Devices/EFI/FlashCore.h

    r81458 r81502  
    5757typedef struct FLASHCORE
    5858{
    59     /** Owning device instance. */
    60     PPDMDEVINS          pDevIns;
    6159    /** The current command. */
    62     uint8_t             bCmd;
     60    uint8_t                 bCmd;
    6361    /** The status register. */
    64     uint8_t             bStatus;
     62    uint8_t                 bStatus;
    6563    /** Current bus cycle. */
    66     uint8_t             cBusCycle;
     64    uint8_t                 cBusCycle;
    6765
    68     uint8_t             uPadding0;
    69 
    70     /* The following state does not change at runtime.*/
     66    /** @name The following state does not change at runtime
     67     * @{ */
     68    /** When set, indicates the state was saved. */
     69    bool                    fStateSaved;
    7170    /** Manufacturer (high byte) and device (low byte) ID. */
    72     uint16_t            u16FlashId;
     71    uint16_t                u16FlashId;
    7372    /** The configured block size of the device. */
    74     uint16_t            cbBlockSize;
     73    uint16_t                cbBlockSize;
    7574    /** The flash memory region size.  */
    76     uint32_t            cbFlashSize;
     75    uint32_t                cbFlashSize;
    7776    /** The actual flash memory data.  */
    78     uint8_t             *pbFlash;
    79     /** When set, indicates the state was saved. */
    80     bool                fStateSaved;
     77    R3PTRTYPE(uint8_t *)    pbFlash;
     78    /** @} */
    8179} FLASHCORE;
    8280
     
    8684#ifndef VBOX_DEVICE_STRUCT_TESTCASE
    8785
    88 /**
    89  * Performs a write to the given flash offset.
    90  *
    91  * @returns VBox status code.
    92  * @param   pThis               The UART core instance.
    93  * @param   off                 Offset to start writing to.
    94  * @param   pv                  The value to write.
    95  * @param   cb                  Number of bytes to write.
    96  */
    97 DECLHIDDEN(int) flashWrite(PFLASHCORE pThis, uint32_t off, const void *pv, size_t cb);
    98 
    99 /**
    100  * Performs a read from the given flash offset.
    101  *
    102  * @returns VBox status code.
    103  * @param   pThis               The UART core instance.
    104  * @param   off                 Offset to start reading from.
    105  * @param   pv                  Where to store the read data.
    106  * @param   cb                  Number of bytes to read.
    107  */
    108 DECLHIDDEN(int) flashRead(PFLASHCORE pThis, uint32_t off, void *pv, size_t cb);
     86DECLHIDDEN(VBOXSTRICTRC) flashWrite(PFLASHCORE pThis, uint32_t off, const void *pv, size_t cb);
     87DECLHIDDEN(VBOXSTRICTRC) flashRead(PFLASHCORE pThis, uint32_t off, void *pv, size_t cb);
    10988
    11089# ifdef IN_RING3
    111 
    112 /**
    113  * Initialiizes the given flash device instance.
    114  *
    115  * @returns VBox status code.
    116  * @param   pThis               The flash device core instance.
    117  * @param   pDevIns             Pointer to the owning device instance.
    118  * @param   idFlashDev          The flash device ID.
    119  * @param   GCPhysFlashBase     Base MMIO address where the flash is located.
    120  * @param   cbFlash             Size of the flash device in bytes.
    121  * @param   cbBlock             Size of a flash block.
    122  */
    12390DECLHIDDEN(int) flashR3Init(PFLASHCORE pThis, PPDMDEVINS pDevIns, uint16_t idFlashDev, uint32_t cbFlash, uint16_t cbBlock);
    124 
    125 /**
    126  * Destroys the given flash device instance.
    127  *
    128  * @returns nothing.
    129  * @param   pThis               The flash device core instance.
    130  */
    131 DECLHIDDEN(void) flashR3Destruct(PFLASHCORE pThis);
    132 
    133 /**
    134  * Loads the flash content from the given file.
    135  *
    136  * @returns VBox status code.
    137  * @param   pThis               The flash device core instance.
    138  * @param   pszFilename         The file to load the flash content from.
    139  */
    140 DECLHIDDEN(int) flashR3LoadFromFile(PFLASHCORE pThis, const char *pszFilename);
    141 
    142 /**
    143  * Loads the flash content from the given buffer.
    144  *
    145  * @returns VBox status code.
    146  * @param   pThis               The flash device core instance.
    147  * @param   pvBuf               The buffer to load the content from.
    148  * @param   cbBuf               Size of the buffer in bytes.
    149  */
     91DECLHIDDEN(void) flashR3Destruct(PFLASHCORE pThis, PPDMDEVINS pDevIns);
     92DECLHIDDEN(int) flashR3LoadFromFile(PFLASHCORE pThis, PPDMDEVINS pDevIns, const char *pszFilename);
    15093DECLHIDDEN(int) flashR3LoadFromBuf(PFLASHCORE pThis, void const *pvBuf, size_t cbBuf);
    151 
    152 /**
    153  * Saves the flash content to the given file.
    154  *
    155  * @returns VBox status code.
    156  * @param   pThis               The flash device core instance.
    157  * @param   pszFilename         The file to save the flash content to.
    158  */
    159 DECLHIDDEN(int) flashR3SaveToFile(PFLASHCORE pThis, const char *pszFilename);
    160 
    161 /**
    162  * Saves the flash content to the given buffer.
    163  *
    164  * @returns VBox status code.
    165  * @param   pThis               The flash device core instance.
    166  * @param   pvBuf               The buffer to save the content to.
    167  * @param   cbBuf               Size of the buffer in bytes.
    168  */
     94DECLHIDDEN(int) flashR3SaveToFile(PFLASHCORE pThis, PPDMDEVINS pDevIns, const char *pszFilename);
    16995DECLHIDDEN(int) flashR3SaveToBuf(PFLASHCORE pThis, void *pvBuf, size_t cbBuf);
    170 
    171 /**
    172  * Resets the dynamic part of the flash device state.
    173  *
    174  * @returns nothing.
    175  * @param   pThis               The flash device core instance.
    176  */
    17796DECLHIDDEN(void) flashR3Reset(PFLASHCORE pThis);
    178 
    179 /**
    180  * Saves the flash device state to the given SSM handle.
    181  *
    182  * @returns VBox status code.
    183  * @param   pThis               The flash device core instance.
    184  * @param   pSSM                The SSM handle to save to.
    185  */
    186 DECLHIDDEN(int) flashR3SsmSaveExec(PFLASHCORE pThis, PSSMHANDLE pSSM);
    187 
    188 /**
    189  * Loads the flash device state from the given SSM handle.
    190  *
    191  * @returns VBox status code.
    192  * @param   pThis               The flash device core instance.
    193  * @param   pSSM                The SSM handle to load from.
    194  */
    195 DECLHIDDEN(int) flashR3SsmLoadExec(PFLASHCORE pThis, PSSMHANDLE pSSM);
    196 
     97DECLHIDDEN(int) flashR3SaveExec(PFLASHCORE pThis, PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
     98DECLHIDDEN(int) flashR3LoadExec(PFLASHCORE pThis, PPDMDEVINS pDevIns, PSSMHANDLE pSSM);
    19799# endif /* IN_RING3 */
    198100
  • trunk/src/VBox/Devices/Makefile.kmk

    r81458 r81502  
    11801180 endif
    11811181
     1182 ifdef VBOX_WITH_EFI
     1183  VBoxDDR0_DEFS         += VBOX_WITH_EFI
     1184  VBoxDDR0_SOURCES      += \
     1185        EFI/DevEFI.cpp \
     1186        EFI/FlashCore.cpp
     1187 endif
     1188
    11821189 if defined(VBOX_WITH_PCI_PASSTHROUGH_IMPL) && !defined(VBOX_WITH_EXTPACK_PUEL)
    11831190  VBoxDDR0_SOURCES      += \
  • trunk/src/VBox/Devices/build/VBoxDDR0.cpp

    r80537 r81502  
    9292    &g_DeviceNVMe,
    9393#endif
     94#ifdef VBOX_WITH_EFI
     95    &g_DeviceEFI,
     96#endif
    9497#ifdef VBOX_WITH_VIRTIO_SCSI
    9598    &g_DeviceVirtioSCSI,
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