VirtualBox

Changeset 100267 in vbox for trunk


Ignore:
Timestamp:
Jun 23, 2023 2:57:53 PM (18 months ago)
Author:
vboxsync
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
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/VBox/VBoxGuest.h

    r98103 r100267  
    266266            /** The MMIO mapping.  NULL if no MMIO region. */
    267267            struct VMMDevMemory volatile RT_FAR *pvVmmDevMapping;
     268            /** The MMIO region for the request port, NULL if not available. */
     269            uintptr_t volatile RT_FAR           *pMmioReq;
    268270            /** The I/O port address. */
    269271            RTIOPORT                        IoPort;
     
    273275    } u;
    274276} VBGLIOCGETVMMDEVIOINFO, RT_FAR *PVBGLIOCGETVMMDEVIOINFO;
    275 AssertCompileSize(VBGLIOCGETVMMDEVIOINFO, 24 + (HC_ARCH_BITS == 64 ? 16 : 8));
     277AssertCompileSize(VBGLIOCGETVMMDEVIOINFO, 24 + (HC_ARCH_BITS == 64 ? 24 : 12));
    276278/** @} */
    277279
     
    388390    VBGLREQHDR      Hdr;
    389391    /** The physical address of the following VMMDevHGCMCall structure. */
    390     RTGCPHYS32      GCPhysReq;
     392    RTGCPHYS64      GCPhysReq;
     393    uint64_t        uTimestamp[2]; /** @todo Looks completely unused. */
    391394    /** Set if interruptible. */
    392395    bool            fInterruptible;
    393396    /** Reserved. */
    394397    uint8_t         abReserved0[3];
    395     uint64_t        uTimestamp[2];
    396     uint8_t         abReserved1[4];
    397398    /* After this structure follows a VMMDevHGCMCall strcuture (44 bytes), then
    398399       zero or more HGCMFunctionParameter structures (12 or 16 bytes), and finally
     
    400401} VBGLIOCIDCHGCMFASTCALL, RT_FAR *PVBGLIOCIDCHGCMFASTCALL;
    401402#pragma pack()
    402 AssertCompileSize(VBGLIOCIDCHGCMFASTCALL, /* 24 + 4 + 1 + 3 + 2*8 + 4 = 0x34 (52) = */ 0x34);
     403AssertCompileSize(VBGLIOCIDCHGCMFASTCALL, /* 24 + 8 + 2*8 + 1 + 3 = 0x34 (52) = */ 0x34);
    403404
    404405/**
     
    407408 *
    408409 * @param   a_pHdr      The request header to initialize.
    409  * @param   a_HdrPhys   The 32-bit physical address corresponding to @a a_pHdr.
     410 * @param   a_HdrPhys   The physical address corresponding to @a a_pHdr.
    410411 * @param   a_pCall     Pointer to the VMMDevHGCMCall structure.
    411412 * @param   a_idClient  The HGCM client ID.
  • trunk/include/VBox/VBoxGuestLib.h

    r100205 r100267  
    121121 * @return VBox status code.
    122122 */
    123 DECLR0VBGL(int)     VbglR0InitPrimary(RTIOPORT portVMMDev, VMMDevMemory *pVMMDevMemory, uint32_t *pfFeatures);
     123DECLR0VBGL(int)     VbglR0InitPrimary(RTIOPORT portVMMDev, uintptr_t volatile *pMmioReq, VMMDevMemory *pVMMDevMemory, uint32_t *pfFeatures);
    124124
    125125/**
     
    484484 *
    485485 * @returns VBox status code.
    486  */
    487 DECLR0VBGL(int)     VbglR0PhysHeapInit(void);
     486 * @param   fAlloc32BitAddr     Flag whether all allocations should be below 4GiB,
     487 *                              so they fit into a 32-bit address.
     488 */
     489DECLR0VBGL(int)     VbglR0PhysHeapInit(bool fAlloc32BitAddr);
    488490
    489491/**
     
    513515 *          isn't valid.
    514516 */
    515 DECLR0VBGL(uint32_t) VbglR0PhysHeapGetPhysAddr(void *pv);
     517DECLR0VBGL(RTCCPHYS) VbglR0PhysHeapGetPhysAddr(void *pv);
    516518
    517519# ifdef IN_TESTCASE
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-darwin.cpp

    r98103 r100267  
    922922                             * Initialize the device extension.
    923923                             */
    924                             int rc = VGDrvCommonInitDevExt(&g_DevExt, IOPortBase, pvMMIOBase, cbMMIO,
     924                            int rc = VGDrvCommonInitDevExt(&g_DevExt, IOPortBase, NULL /*pvMmioReq*/, pvMMIOBase, cbMMIO,
    925925                                                           ARCH_BITS == 64 ? VBOXOSTYPE_MacOS_x64 : VBOXOSTYPE_MacOS, 0);
    926926                            if (RT_SUCCESS(rc))
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-freebsd.c

    r98103 r100267  
    717717             */
    718718            rc = VGDrvCommonInitDevExt(&g_DevExt, pState->uIOPortBase,
     719                                       NULL /*pvMmioReq*/,
    719720                                       pState->pMMIOBase, pState->VMMDevMemSize,
    720721#if ARCH_BITS == 64
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-haiku.c

    r98103 r100267  
    476476             * Call the common device extension initializer.
    477477             */
    478             rc = VGDrvCommonInitDevExt(&g_DevExt, pState->uIOPortBase, pState->pMMIOBase, pState->VMMDevMemSize,
     478            rc = VGDrvCommonInitDevExt(&g_DevExt, pState->uIOPortBase, NULL /*pvMmioReq*/,
     479                                       pState->pMMIOBase, pState->VMMDevMemSize,
    479480#if ARCH_BITS == 64
    480481                                       VBOXOSTYPE_Haiku_x64,
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-linux.c

    r98542 r100267  
    148148/** The pointer to the mapping of the MMIO range. */
    149149static void                    *g_pvMMIOBase;
     150
     151static RTHCPHYS                 g_MmioReqPhysAddr = NIL_RTHCPHYS;
     152static uint32_t                 g_cbMmioReq;
     153static void                    *g_pvMmioReq = NULL;
     154
    150155/** Wait queue used by polling. */
    151156static wait_queue_head_t        g_PollEventQueue;
     
    288293
    289294
     295#if defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
     296static int vgdrvLinuxMapMmio(struct pci_dev *pPciDev)
     297{
     298    g_MmioReqPhysAddr = pci_resource_start(pPciDev, 3);
     299    g_cbMmioReq       = pci_resource_len(pPciDev, 3);
     300    if (request_mem_region(g_MmioReqPhysAddr, g_cbMmioReq, DEVICE_NAME) != NULL)
     301    {
     302        g_pvMmioReq = ioremap(g_MmioReqPhysAddr, g_cbMmioReq);
     303        if (g_pvMmioReq)
     304            return 0;
     305
     306        /* failure cleanup path */
     307        LogRel((DEVICE_NAME ": ioremap failed; MMIO Addr=%RHp cb=%#x\n", g_MmioReqPhysAddr, g_cbMmioReq));
     308        release_mem_region(g_MmioReqPhysAddr, g_cbMmioReq);
     309        return -ENOMEM;
     310    }
     311    else
     312        LogRel((DEVICE_NAME ": failed to obtain adapter memory\n"));
     313
     314    return -EBUSY;
     315}
     316#endif
     317
     318
    290319/**
    291320 * Does the PCI detection and init of the device.
     
    302331    if (rc >= 0)
    303332    {
     333#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
    304334        /* I/O Ports are mandatory, the MMIO bit is not. */
    305335        g_IOPortBase = pci_resource_start(pPciDev, 0);
    306336        if (g_IOPortBase != 0)
     337#elif defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
     338        rc = vgdrvLinuxMapMmio(pPciDev);
     339        if (!rc)
     340#else
     341# error "I have no memory of this arechitecture"
     342#endif
    307343        {
    308344            /*
     
    356392    if (pPciDev)
    357393    {
     394        if (g_pvMmioReq)
     395        {
     396            iounmap(g_pvMmioReq);
     397            g_pvMmioReq = NULL;
     398
     399            release_mem_region(g_MmioReqPhysAddr, g_cbMmioReq);
     400            g_MmioReqPhysAddr = NIL_RTHCPHYS;
     401            g_cbMmioReq = 0;
     402        }
     403
    358404        iounmap(g_pvMMIOBase);
    359405        g_pvMMIOBase = NULL;
     
    703749         * Call the common device extension initializer.
    704750         */
    705 #if RTLNX_VER_MIN(2,6,0) && defined(RT_ARCH_X86)
     751#if RTLNX_VER_MIN(2,6,0) && defined(RT_ARCH_X86) || defined(RT_ARCH_ARM32)
    706752        VBOXOSTYPE enmOSType = VBOXOSTYPE_Linux26;
    707 #elif RTLNX_VER_MIN(2,6,0) && defined(RT_ARCH_AMD64)
     753#elif RTLNX_VER_MIN(2,6,0) && (defined(RT_ARCH_AMD64) || defined(RT_ARCH_ARM64))
    708754        VBOXOSTYPE enmOSType = VBOXOSTYPE_Linux26_x64;
    709755#elif RTLNX_VER_MIN(2,4,0) && defined(RT_ARCH_X86)
     
    717763        rc = VGDrvCommonInitDevExt(&g_DevExt,
    718764                                   g_IOPortBase,
     765                                   g_pvMmioReq,
    719766                                   g_pvMMIOBase,
    720767                                   g_cbMMIO,
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-netbsd.c

    r98103 r100267  
    334334             */
    335335            rc = VGDrvCommonInitDevExt(&g_DevExt, sc->sc_iobase,
     336                                       NULL /*pvMmioReq*/,
    336337                                       bus_space_vaddr(sc->sc_memt, sc->sc_memh),
    337338                                       sc->sc_memsize,
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-os2.cpp

    r98103 r100267  
    187187            if (g_MemMapMMIO != NIL_RTR0MEMOBJ)
    188188                rc = VGDrvCommonInitDevExt(&g_DevExt, g_IOPortBase,
     189                                           NULL /*pvMmioReq*/,
    189190                                           RTR0MemObjAddress(g_MemMapMMIO),
    190191                                           RTR0MemObjSize(g_MemMapMMIO),
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-solaris.c

    r98103 r100267  
    335335                             * Call the common device extension initializer.
    336336                             */
    337                             rc = VGDrvCommonInitDevExt(&g_DevExt, g_uIOPortBase, g_pMMIOBase, g_cbMMIO,
     337                            rc = VGDrvCommonInitDevExt(&g_DevExt, g_uIOPortBase,
     338                                                       NULL /*pvMmioReq*/,
     339                                                       g_pMMIOBase, g_cbMMIO,
    338340#if ARCH_BITS == 64
    339341                                                       VBOXOSTYPE_Solaris_x64,
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.cpp

    r99365 r100267  
    10721072            int vrc = VGDrvCommonInitDevExtResources(&pDevExt->Core,
    10731073                                                     pDevExt->Core.IOPortBase,
     1074                                                     NULL /*pvMmioReq*/,
    10741075                                                     pvMMIOBase, cbMMIO,
    10751076                                                     vgdrvNtVersionToOSType(g_enmVGDrvNtVer),
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest.cpp

    r98103 r100267  
    7272#include <iprt/memobj.h>
    7373#include <iprt/asm.h>
    74 #include <iprt/asm-amd64-x86.h>
     74#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
     75# include <iprt/asm-amd64-x86.h>
     76#endif
    7577#include <iprt/string.h>
    7678#include <iprt/process.h>
     
    994996     */
    995997    pDevExt->IOPortBase = UINT16_MAX;
     998    pDevExt->pMmioReq      = NULL;
     999    pDevExt->pMmioReqFast  = NULL;
    9961000    pDevExt->pVMMDevMemory = NULL;
    9971001    pDevExt->hGuestMappings = NIL_RTR0MEMOBJ;
     
    10981102 * @param   pDevExt         The device extension. Allocated by the native code.
    10991103 * @param   IOPortBase      The base of the I/O port range.
     1104 * @param   pvMmioReq       The base of the MMIO request region.
    11001105 * @param   pvMMIOBase      The base of the MMIO memory mapping.
    11011106 *                          This is optional, pass NULL if not present.
     
    11071112 */
    11081113int VGDrvCommonInitDevExtResources(PVBOXGUESTDEVEXT pDevExt, uint16_t IOPortBase,
    1109                                    void *pvMMIOBase, uint32_t cbMMIO, VBOXOSTYPE enmOSType, uint32_t fFixedEvents)
     1114                                   void *pvMmioReq, void *pvMMIOBase, uint32_t cbMMIO,
     1115                                   VBOXOSTYPE enmOSType, uint32_t fFixedEvents)
    11101116{
    11111117    int rc;
     
    11381144     * made by the VMM.
    11391145     */
    1140     pDevExt->IOPortBase = IOPortBase;
    1141     rc = VbglR0InitPrimary(pDevExt->IOPortBase, (VMMDevMemory *)pDevExt->pVMMDevMemory, &pDevExt->fHostFeatures);
     1146    pDevExt->IOPortBase   = IOPortBase;
     1147    pDevExt->pMmioReq     = (uintptr_t volatile *)pvMmioReq;
     1148    pDevExt->pMmioReqFast = (uint32_t volatile *)((uintptr_t)pvMmioReq + VMMDEV_MMIO_OFF_REQUEST_FAST);
     1149    rc = VbglR0InitPrimary(pDevExt->IOPortBase, pDevExt->pMmioReq, (VMMDevMemory *)pDevExt->pVMMDevMemory, &pDevExt->fHostFeatures);
    11421150    if (RT_SUCCESS(rc))
    11431151    {
     
    11471155        {
    11481156            pDevExt->PhysIrqAckEvents = VbglR0PhysHeapGetPhysAddr(pAckReq);
    1149             Assert(pDevExt->PhysIrqAckEvents != 0);
     1157            Assert(   pDevExt->PhysIrqAckEvents != 0
     1158                   && pDevExt->PhysIrqAckEvents == (uintptr_t)pDevExt->PhysIrqAckEvents);
    11501159            ASMCompilerBarrier(); /* linux + solaris already have IRQs hooked up at this point, so take care. */
    11511160            pDevExt->pIrqAckEvents = (VMMDevEvents *)pAckReq;
     
    13211330 * @param   pDevExt         The device extension. Allocated by the native code.
    13221331 * @param   IOPortBase      The base of the I/O port range.
     1332 * @param   pvMmioReq       The base of the MMIO request region.
    13231333 * @param   pvMMIOBase      The base of the MMIO memory mapping.
    13241334 *                          This is optional, pass NULL if not present.
     
    13301340 */
    13311341int VGDrvCommonInitDevExt(PVBOXGUESTDEVEXT pDevExt, uint16_t IOPortBase,
    1332                           void *pvMMIOBase, uint32_t cbMMIO, VBOXOSTYPE enmOSType, uint32_t fFixedEvents)
     1342                          void *pvMmioReq, void *pvMMIOBase, uint32_t cbMMIO,
     1343                          VBOXOSTYPE enmOSType, uint32_t fFixedEvents)
    13331344{
    13341345    int rc;
     
    13381349    if (RT_SUCCESS(rc))
    13391350    {
    1340         rc = VGDrvCommonInitDevExtResources(pDevExt, IOPortBase, pvMMIOBase, cbMMIO, enmOSType, fFixedEvents);
     1351        rc = VGDrvCommonInitDevExtResources(pDevExt, IOPortBase, pvMmioReq, pvMMIOBase, cbMMIO,
     1352                                            enmOSType, fFixedEvents);
    13411353        if (RT_SUCCESS(rc))
    13421354            return rc;
     
    20762088    pInfo->u.Out.IoPort          = pDevExt->IOPortBase;
    20772089    pInfo->u.Out.pvVmmDevMapping = pDevExt->pVMMDevMemory;
     2090    pInfo->u.Out.pMmioReq        = pDevExt->pMmioReq;
    20782091    pInfo->u.Out.auPadding[0]    = 0;
    20792092#if HC_ARCH_BITS != 32
     
    27992812    fFlags = !fUserData && pSession->R0Process == NIL_RTR0PROCESS ? VBGLR0_HGCMCALL_F_KERNEL : VBGLR0_HGCMCALL_F_USER;
    28002813    uint32_t cbInfo = (uint32_t)(cbData - cbExtra);
    2801 #ifdef RT_ARCH_AMD64
     2814#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_ARM64)
    28022815    if (f32bit)
    28032816    {
     
    28642877     */
    28652878    Assert((pCallReq->GCPhysReq & PAGE_OFFSET_MASK) == ((uintptr_t)pHgcmCall & PAGE_OFFSET_MASK));
     2879    AssertReturn(pCallReq->GCPhysReq == (uintptr_t)pCallReq->GCPhysReq, VERR_VBGL_INVALID_ADDR);
    28662880
    28672881    AssertReturn(!pCallReq->fInterruptible, VERR_NOT_IMPLEMENTED);
     
    28712885     */
    28722886    Log(("vgdrvIoCtl_HGCMFastCall -> host\n"));
    2873     ASMOutU32(pDevExt->IOPortBase + VMMDEV_PORT_OFF_REQUEST, (uint32_t)pCallReq->GCPhysReq);
     2887    if (pDevExt->pMmioReq)
     2888        *pDevExt->pMmioReq = (uintptr_t)pCallReq->GCPhysReq;
     2889    else
     2890    {
     2891#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
     2892        ASMOutU32(pDevExt->IOPortBase + VMMDEV_PORT_OFF_REQUEST, (uint32_t)pCallReq->GCPhysReq);
     2893#elif defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
     2894        AssertReleaseFailed(); /* Not possible on ARM. */
     2895        return VERR_INVALID_STATE;
     2896#else
     2897# error "I have no memory of this architecture"
     2898#endif
     2899    }
    28742900
    28752901    /* Make the compiler aware that the host has changed memory. */
     
    44134439        if (!pReq)
    44144440        {
    4415             fEvents = ASMInU32(pDevExt->IOPortBase + VMMDEV_PORT_OFF_REQUEST_FAST);
     4441            if (pDevExt->pMmioReqFast)
     4442                fEvents = *pDevExt->pMmioReqFast;
     4443            else
     4444            {
     4445#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
     4446                fEvents = ASMInU32(pDevExt->IOPortBase + VMMDEV_PORT_OFF_REQUEST_FAST);
     4447#elif defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
     4448                AssertReleaseFailed(); /* No port I/O on ARM. */
     4449#else
     4450# error "I have no memory of this architecture"
     4451#endif
     4452            }
    44164453            ASMCompilerBarrier();   /* paranoia */
    44174454            rc = fEvents != UINT32_MAX ? VINF_SUCCESS : VERR_INTERNAL_ERROR;
     
    44224459            pReq->events    = 0;
    44234460            ASMCompilerBarrier();
    4424             ASMOutU32(pDevExt->IOPortBase + VMMDEV_PORT_OFF_REQUEST, (uint32_t)pDevExt->PhysIrqAckEvents);
     4461            if (pDevExt->pMmioReq)
     4462                *pDevExt->pMmioReq = pDevExt->PhysIrqAckEvents;
     4463            else
     4464            {
     4465#if defined(RT_ARCH_AMD64) || defined(RT_ARCH_X86)
     4466                ASMOutU32(pDevExt->IOPortBase + VMMDEV_PORT_OFF_REQUEST, (uint32_t)pDevExt->PhysIrqAckEvents);
     4467#elif defined(RT_ARCH_ARM64) || defined(RT_ARCH_ARM32)
     4468                AssertReleaseFailed();
     4469#else
     4470# error "I have no memory of this architecture"
     4471#endif
     4472            }
     4473
    44254474            ASMCompilerBarrier();   /* paranoia */
    44264475            fEvents = pReq->events;
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuestInternal.h

    r98103 r100267  
    157157    /** The base of the adapter I/O ports. */
    158158    RTIOPORT                    IOPortBase;
     159    /** Pointer to the mapping of the MMIO request region if available. */
     160    uintptr_t volatile         *pMmioReq;
     161    /** Pointer to the fast request register in the MMIO region if available. */
     162    uint32_t volatile          *pMmioReqFast;
    159163    /** Pointer to the mapping of the VMMDev adapter memory. */
    160164    VMMDevMemory volatile      *pVMMDevMemory;
     
    350354RT_C_DECLS_BEGIN
    351355
    352 int  VGDrvCommonInitDevExt(PVBOXGUESTDEVEXT pDevExt, uint16_t IOPortBase, void *pvMMIOBase, uint32_t cbMMIO,
     356int  VGDrvCommonInitDevExt(PVBOXGUESTDEVEXT pDevExt, uint16_t IOPortBase, void *pvMmioReq,
     357                           void *pvMMIOBase, uint32_t cbMMIO,
    353358                           VBOXOSTYPE enmOSType, uint32_t fEvents);
    354359void VGDrvCommonDeleteDevExt(PVBOXGUESTDEVEXT pDevExt);
     
    359364void VGDrvCommonDeleteDevExtFundament(PVBOXGUESTDEVEXT pDevExt);
    360365int  VGDrvCommonInitDevExtResources(PVBOXGUESTDEVEXT pDevExt, uint16_t IOPortBase,
    361                                     void *pvMMIOBase, uint32_t cbMMIO, VBOXOSTYPE enmOSType, uint32_t fFixedEvents);
     366                                    void *pvMmioReq, void *pvMMIOBase, uint32_t cbMMIO,
     367                                    VBOXOSTYPE enmOSType, uint32_t fFixedEvents);
    362368void VGDrvCommonDeleteDevExtResources(PVBOXGUESTDEVEXT pDevExt);
    363369int  VGDrvCommonReinitDevExtAfterHibernation(PVBOXGUESTDEVEXT pDevExt, VBOXOSTYPE enmOSType);
  • 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.

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