VirtualBox

Changeset 99079 in vbox


Ignore:
Timestamp:
Mar 21, 2023 11:05:38 AM (2 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
156444
Message:

VMM/MM: For ARMv8 we need to be more flexible when it comes to configure accessible guest RAM, there is no standard layout and every SoC can have RAM at different physical addresses. MM gets a list of memory regions through CFGM and sets up the RAM ranges, bugref:10388

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/VMM/VMMR3/MM.cpp

    r99051 r99079  
    269269
    270270
     271#if defined(VBOX_VMM_TARGET_ARMV8)
     272/**
     273 * This sets up the RAM ranges from the VM config.
     274 *
     275 * @returns VBox status code.
     276 * @param   pVM         The cross context VM structure.
     277 * @param   pMMCfg      Pointer to the CFGM node holding the RAM config.
     278 *
     279 * @note On ARM there is no "standard" way to handle RAM like on x86.
     280 *       Every SoC can have multiple RAM regions scattered across the whole
     281 *       address space so we have to be much more flexible here.
     282 */
     283static int mmR3InitRamArmV8(PVM pVM, PCFGMNODE pMMCfg)
     284{
     285    int rc = VINF_SUCCESS;
     286    PCFGMNODE pMemRegions = CFGMR3GetChild(pMMCfg, "MemRegions");
     287
     288    pVM->mm.s.cbRamBase     = 0;
     289    pVM->mm.s.cbRamHole     = 0;
     290    pVM->mm.s.cbRamBelow4GB = 0;
     291    pVM->mm.s.cbRamAbove4GB = 0;
     292
     293    for (PCFGMNODE pCur = CFGMR3GetFirstChild(pMemRegions); pCur; pCur = CFGMR3GetNextChild(pCur))
     294    {
     295        char szMemRegion[512]; RT_ZERO(szMemRegion);
     296        rc = CFGMR3GetName(pCur, &szMemRegion[0], sizeof(szMemRegion));
     297        if (RT_FAILURE(rc))
     298        {
     299            LogRel(("Failed to query memory region name -> %Rrc\n", rc));
     300            break;
     301        }
     302
     303        uint64_t u64GCPhysStart = 0;
     304        rc = CFGMR3QueryU64(pCur, "GCPhysStart", &u64GCPhysStart);
     305        if (RT_FAILURE(rc))
     306        {
     307            LogRel(("Failed to query \"GCPhysStart\" for memory region %s -> %Rrc\n", szMemRegion, rc));
     308            break;
     309        }
     310
     311        uint64_t u64MemSize = 0;
     312        rc = CFGMR3QueryU64(pCur, "Size", &u64MemSize);
     313        if (RT_FAILURE(rc))
     314        {
     315            LogRel(("Failed to query \"Size\" for memory region %s -> %Rrc\n", szMemRegion, rc));
     316            break;
     317        }
     318
     319        rc = PGMR3PhysRegisterRam(pVM, u64GCPhysStart, u64MemSize, "Conventional RAM");
     320        if (RT_FAILURE(rc))
     321        {
     322            LogRel(("Failed to register memory region '%s' GCPhysStart=%RGp Size=%#RX64 -> %Rrc\n",
     323                    szMemRegion, u64GCPhysStart, u64MemSize));
     324            break;
     325        }
     326
     327        pVM->mm.s.cbRamBase += u64MemSize;
     328        if (u64GCPhysStart >= _4G)
     329            pVM->mm.s.cbRamAbove4GB += u64MemSize;
     330        else if (u64GCPhysStart + u64MemSize > _4G)
     331        {
     332            uint64_t cbRamAbove4GB = (u64GCPhysStart + u64MemSize) - _4G;
     333            pVM->mm.s.cbRamAbove4GB += cbRamAbove4GB;
     334            pVM->mm.s.cbRamBelow4GB += (u64MemSize - cbRamAbove4GB);
     335        }
     336        else
     337            pVM->mm.s.cbRamBelow4GB += (uint32_t)u64MemSize;
     338    }
     339
     340    return rc;
     341}
     342#endif
     343
     344
    271345/**
    272346 * Initializes the MM parts which depends on PGM being initialized.
     
    291365    }
    292366
     367#if defined(VBOX_VMM_TARGET_ARMV8)
     368    rc = mmR3InitRamArmV8(pVM, pMMCfg);
     369#else
    293370    /** @cfgm{/RamSize, uint64_t, 0, 16TB, 0}
    294371     * Specifies the size of the base RAM that is to be set up during
     
    405482    pVM->mm.s.cbRamAbove4GB = cbRam > offRamHole ? cbRam - offRamHole : 0;
    406483
    407 #if defined(VBOX_VMM_TARGET_ARMV8)
    408     rc = PGMR3PhysRegisterRam(pVM, 0, cbRam, "Conventional RAM");
    409 #else
    410484    /* First the conventional memory: */
    411485    rc = PGMR3PhysRegisterRam(pVM, 0, RT_MIN(cbRam, 640*_1K), "Conventional RAM");
     
    424498        }
    425499    }
    426 #endif
     500#endif /* !VBOX_VMM_TARGET_ARMV8 */
    427501
    428502    /*
Note: See TracChangeset for help on using the changeset viewer.

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