VirtualBox

Ignore:
Timestamp:
Jun 23, 2023 2:57:53 PM (22 months ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
157982
Message:

Additions: Make the R0 physical heap configurable to allow for allocations >= 4GiB if supported by the VBox device (the MMIO request path is available), add support for the MMIO request path required for ARM, bugref:10457

Location:
trunk/src/VBox/Additions/common/VBoxGuest/lib
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibGenericRequest.cpp

    r98103 r100267  
    3535#include "VBoxGuestR0LibInternal.h"
    3636#include <iprt/asm.h>
    37 #include <iprt/asm-amd64-x86.h>
     37#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
     38# include <iprt/asm-amd64-x86.h>
     39#endif
    3840#include <iprt/assert.h>
    3941#include <iprt/string.h>
     
    159161        {
    160162            RTCCPHYS PhysAddr = VbglR0PhysHeapGetPhysAddr(pReq);
    161             if (   PhysAddr != 0
    162                 && PhysAddr < _4G) /* Port IO is 32 bit. */
     163            if (PhysAddr != 0)
    163164            {
    164                 ASMOutU32(g_vbgldata.portVMMDev + VMMDEV_PORT_OFF_REQUEST, (uint32_t)PhysAddr);
     165                if (g_vbgldata.pMmioReq)
     166                {
     167                    Assert((uintptr_t)PhysAddr == PhysAddr);
     168                    *g_vbgldata.pMmioReq = (uintptr_t)PhysAddr;
     169                }
     170                else if (PhysAddr < _4G) /* Port IO is 32 bit. */
     171                {
     172#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
     173                    ASMOutU32(g_vbgldata.portVMMDev + VMMDEV_PORT_OFF_REQUEST, (uint32_t)PhysAddr);
     174#elif defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
     175                    rc = VERR_INVALID_STATE;
     176#else
     177# error "I have no memory of this architecture"
     178#endif
     179                }
     180                else
     181                    rc = VERR_VBGL_INVALID_ADDR;
     182
    165183                /* Make the compiler aware that the host has changed memory. */
    166                 ASMCompilerBarrier();
    167                 rc = pReq->rc;
     184                if (RT_SUCCESS(rc))
     185                {
     186                    ASMCompilerBarrier();
     187                    rc = pReq->rc;
     188                }
    168189            }
    169190            else
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibInit.cpp

    r98103 r100267  
    115115                    g_vbgldata.portVMMDev    = PortInfo.u.Out.IoPort;
    116116                    g_vbgldata.pVMMDevMemory = (VMMDevMemory *)PortInfo.u.Out.pvVmmDevMapping;
    117                     g_vbgldata.status        = VbglStatusReady;
    118 
    119                     vbglR0QueryHostVersion();
     117                    g_vbgldata.pMmioReq      = PortInfo.u.Out.pMmioReq;
     118
     119                    rc = VbglR0PhysHeapInit(g_vbgldata.pMmioReq == NULL /*fAlloc32BitAddr*/);
     120                    if (RT_SUCCESS(rc))
     121                    {
     122                        g_vbgldata.status = VbglStatusReady;
     123                        vbglR0QueryHostVersion();
     124                    }
     125                    else
     126                    {
     127                        LogRel(("vbglR0QueryDriverInfo: VbglR0PhysHeapInit() -> %Rrc\n", rc));
     128                        g_vbgldata.status = VbglStatusNotInitialized;
     129                    }
    120130                }
    121131            }
     
    160170static int vbglR0InitCommon(void)
    161171{
    162     int rc;
    163 
    164172    RT_ZERO(g_vbgldata);
    165173    g_vbgldata.status = VbglStatusInitializing;
    166 
    167     rc = VbglR0PhysHeapInit();
    168     if (RT_SUCCESS(rc))
    169     {
    170         dprintf(("vbglR0InitCommon: returns rc = %d\n", rc));
    171         return rc;
    172     }
    173 
    174     LogRel(("vbglR0InitCommon: VbglR0PhysHeapInit failed: rc=%Rrc\n", rc));
    175     g_vbgldata.status = VbglStatusNotInitialized;
    176     return rc;
     174    return VINF_SUCCESS;
    177175}
    178176
     
    186184#ifdef VBGL_VBOXGUEST
    187185
    188 DECLR0VBGL(int) VbglR0InitPrimary(RTIOPORT portVMMDev, VMMDevMemory *pVMMDevMemory, uint32_t *pfFeatures)
     186DECLR0VBGL(int) VbglR0InitPrimary(RTIOPORT portVMMDev, uintptr_t volatile *pMmioReq, VMMDevMemory *pVMMDevMemory, uint32_t *pfFeatures)
    189187{
    190188    int rc;
     
    208206        g_vbgldata.portVMMDev    = portVMMDev;
    209207        g_vbgldata.pVMMDevMemory = pVMMDevMemory;
    210         g_vbgldata.status        = VbglStatusReady;
    211 
    212         vbglR0QueryHostVersion();
    213         *pfFeatures = g_vbgldata.hostVersion.features;
    214         return VINF_SUCCESS;
     208        g_vbgldata.pMmioReq      = pMmioReq;
     209
     210        rc = VbglR0PhysHeapInit(pMmioReq == NULL /*fAlloc32BitAddr*/);
     211        if (RT_SUCCESS(rc))
     212        {
     213            g_vbgldata.status = VbglStatusReady;
     214
     215            vbglR0QueryHostVersion();
     216            *pfFeatures = g_vbgldata.hostVersion.features;
     217            return VINF_SUCCESS;
     218        }
     219        else
     220        {
     221            LogRel(("VbglR0InitPrimary: VbglR0PhysHeapInit() -> %Rrc\n", rc));
     222            g_vbgldata.status = VbglStatusNotInitialized;
     223        }
    215224    }
    216225
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibInternal.h

    r98103 r100267  
    125125typedef struct VBGLDATA
    126126{
    127     enum VbglLibStatus status;
    128 
    129     RTIOPORT portVMMDev;
    130 
    131     VMMDevMemory *pVMMDevMemory;
     127    /** Init status of the library. */
     128    enum VbglLibStatus      status;
     129    /** I/O port to issue requests to. */
     130    RTIOPORT                portVMMDev;
     131    /** MMIO request region if available. */
     132    volatile uintptr_t      *pMmioReq;
     133    /** VMMDev adapter memory region if available. */
     134    VMMDevMemory            *pVMMDevMemory;
    132135
    133136    /** Physical memory heap data.
     
    149152    /** Head of the chunk list. */
    150153    VBGLPHYSHEAPCHUNK      *pChunkHead;
     154    /** Flag whether all allocations should be below 4GiB to fit into
     155     * a 32-bit address. */
     156    bool                   fAlloc32BitAddr;
    151157    /** @} */
    152158
  • trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibPhysHeap.cpp

    r98103 r100267  
    215215    /** Magic value (VBGL_PH_CHUNKSIGNATURE). */
    216216    uint32_t u32Signature;
    217 
    218217    /** Size of the chunk. Includes the chunk header. */
    219218    uint32_t cbChunk;
    220 
    221     /** Physical address of the chunk (contiguous). */
    222     uint32_t physAddr;
    223 
    224 #if !defined(VBGL_PH_USE_MEMOBJ) || ARCH_BITS != 32
    225     uint32_t uPadding1;
    226 #endif
    227 
    228219    /** Number of block of any kind. */
    229220    int32_t  cBlocks;
     
    231222    int32_t  cFreeBlocks;
    232223
     224    /** Physical address of the chunk (contiguous). */
     225    RTCCPHYS physAddr;
     226
    233227    /** Pointer to the next chunk. */
    234228    VBGLPHYSHEAPCHUNK  *pNext;
     
    239233    /** The allocation handle. */
    240234    RTR0MEMOBJ          hMemObj;
    241 #endif
    242 
    243 #if ARCH_BITS == 64
     235#elif ARCH_BITS == 64
    244236    /** Pad the size up to 64 bytes. */
    245237# ifdef VBGL_PH_USE_MEMOBJ
     
    252244#if ARCH_BITS == 64
    253245AssertCompileSize(VBGLPHYSHEAPCHUNK, 64);
     246#elif ARCH_BITS == 32
     247AssertCompileSize(VBGLPHYSHEAPCHUNK, 32);
     248#else
     249# error "Unknown architecture!"
    254250#endif
    255251
     
    536532    cbChunk = RT_ALIGN_32(cbChunk, VBGL_PH_CHUNKSIZE);
    537533
    538     /*
    539      * This function allocates physical contiguous memory below 4 GB.  This 4GB
    540      * limitation stems from using a 32-bit OUT instruction to pass a block
    541      * physical address to the host.
    542      */
     534    if (g_vbgldata.fAlloc32BitAddr)
     535    {
     536        /*
     537         * This function allocates physical contiguous memory below 4 GB.  This 4GB
     538         * limitation stems from using a 32-bit OUT instruction to pass a block
     539         * physical address to the host.
     540         */
    543541#ifdef VBGL_PH_USE_MEMOBJ
    544     rc = RTR0MemObjAllocCont(&hMemObj, cbChunk, false /*fExecutable*/);
    545     pChunk = (VBGLPHYSHEAPCHUNK *)(RT_SUCCESS(rc) ? RTR0MemObjAddress(hMemObj) : NULL);
     542        rc = RTR0MemObjAllocCont(&hMemObj, cbChunk, false /*fExecutable*/);
     543        pChunk = (VBGLPHYSHEAPCHUNK *)(RT_SUCCESS(rc) ? RTR0MemObjAddress(hMemObj) : NULL);
    546544#else
    547     pChunk = (VBGLPHYSHEAPCHUNK *)RTMemContAlloc(&PhysAddr, cbChunk);
    548 #endif
     545        pChunk = (VBGLPHYSHEAPCHUNK *)RTMemContAlloc(&PhysAddr, cbChunk);
     546#endif
     547    }
     548    else
     549    {
     550        /** @todo Provide appropriate memory API. */
     551#ifdef VBGL_PH_USE_MEMOBJ
     552        rc = RTR0MemObjAllocCont(&hMemObj, cbChunk, false /*fExecutable*/);
     553        pChunk = (VBGLPHYSHEAPCHUNK *)(RT_SUCCESS(rc) ? RTR0MemObjAddress(hMemObj) : NULL);
     554#else
     555        pChunk = (VBGLPHYSHEAPCHUNK *)RTMemContAlloc(&PhysAddr, cbChunk);
     556#endif
     557    }
    549558    if (!pChunk)
    550559    {
     
    569578        VBGLPHYSHEAPCHUNK     *pOldHeadChunk;
    570579        VBGLPHYSHEAPFREEBLOCK *pBlock;
    571         AssertRelease(PhysAddr < _4G && PhysAddr + cbChunk <= _4G);
     580        AssertRelease(   !g_vbgldata.fAlloc32BitAddr
     581                      || (PhysAddr < _4G && PhysAddr + cbChunk <= _4G));
    572582
    573583        /*
     
    576586        pChunk->u32Signature     = VBGL_PH_CHUNKSIGNATURE;
    577587        pChunk->cbChunk          = cbChunk;
    578         pChunk->physAddr         = (uint32_t)PhysAddr;
     588        pChunk->physAddr         = PhysAddr;
    579589        pChunk->cBlocks          = 0;
    580590        pChunk->cFreeBlocks      = 0;
     
    586596
    587597        /* Initialize the padding too: */
    588 #if !defined(VBGL_PH_USE_MEMOBJ) || ARCH_BITS != 32
    589         pChunk->uPadding1        = UINT32_C(0xADDCAAA1);
    590 #endif
    591598#if ARCH_BITS == 64
    592599        pChunk->auPadding2[0]    = UINT64_C(0xADDCAAA3ADDCAAA2);
     
    865872
    866873
    867 DECLR0VBGL(uint32_t) VbglR0PhysHeapGetPhysAddr(void *pv)
     874DECLR0VBGL(RTCCPHYS) VbglR0PhysHeapGetPhysAddr(void *pv)
    868875{
    869876    /*
     
    11761183#endif /* IN_TESTCASE */
    11771184
    1178 DECLR0VBGL(int) VbglR0PhysHeapInit(void)
    1179 {
    1180     g_vbgldata.hMtxHeap = NIL_RTSEMFASTMUTEX;
     1185DECLR0VBGL(int) VbglR0PhysHeapInit(bool fAlloc32BitAddr)
     1186{
     1187    g_vbgldata.fAlloc32BitAddr = fAlloc32BitAddr;
     1188    g_vbgldata.hMtxHeap        = NIL_RTSEMFASTMUTEX;
    11811189
    11821190    /* Allocate the first chunk of the heap. */
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