Changeset 100267 in vbox for trunk/src/VBox/Additions/common/VBoxGuest/lib
- Timestamp:
- Jun 23, 2023 2:57:53 PM (22 months ago)
- svn:sync-xref-src-repo-rev:
- 157982
- 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 35 35 #include "VBoxGuestR0LibInternal.h" 36 36 #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 38 40 #include <iprt/assert.h> 39 41 #include <iprt/string.h> … … 159 161 { 160 162 RTCCPHYS PhysAddr = VbglR0PhysHeapGetPhysAddr(pReq); 161 if ( PhysAddr != 0 162 && PhysAddr < _4G) /* Port IO is 32 bit. */ 163 if (PhysAddr != 0) 163 164 { 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 165 183 /* 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 } 168 189 } 169 190 else -
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibInit.cpp
r98103 r100267 115 115 g_vbgldata.portVMMDev = PortInfo.u.Out.IoPort; 116 116 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 } 120 130 } 121 131 } … … 160 170 static int vbglR0InitCommon(void) 161 171 { 162 int rc;163 164 172 RT_ZERO(g_vbgldata); 165 173 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; 177 175 } 178 176 … … 186 184 #ifdef VBGL_VBOXGUEST 187 185 188 DECLR0VBGL(int) VbglR0InitPrimary(RTIOPORT portVMMDev, VMMDevMemory *pVMMDevMemory, uint32_t *pfFeatures)186 DECLR0VBGL(int) VbglR0InitPrimary(RTIOPORT portVMMDev, uintptr_t volatile *pMmioReq, VMMDevMemory *pVMMDevMemory, uint32_t *pfFeatures) 189 187 { 190 188 int rc; … … 208 206 g_vbgldata.portVMMDev = portVMMDev; 209 207 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 } 215 224 } 216 225 -
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibInternal.h
r98103 r100267 125 125 typedef struct VBGLDATA 126 126 { 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; 132 135 133 136 /** Physical memory heap data. … … 149 152 /** Head of the chunk list. */ 150 153 VBGLPHYSHEAPCHUNK *pChunkHead; 154 /** Flag whether all allocations should be below 4GiB to fit into 155 * a 32-bit address. */ 156 bool fAlloc32BitAddr; 151 157 /** @} */ 152 158 -
trunk/src/VBox/Additions/common/VBoxGuest/lib/VBoxGuestR0LibPhysHeap.cpp
r98103 r100267 215 215 /** Magic value (VBGL_PH_CHUNKSIGNATURE). */ 216 216 uint32_t u32Signature; 217 218 217 /** Size of the chunk. Includes the chunk header. */ 219 218 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 != 32225 uint32_t uPadding1;226 #endif227 228 219 /** Number of block of any kind. */ 229 220 int32_t cBlocks; … … 231 222 int32_t cFreeBlocks; 232 223 224 /** Physical address of the chunk (contiguous). */ 225 RTCCPHYS physAddr; 226 233 227 /** Pointer to the next chunk. */ 234 228 VBGLPHYSHEAPCHUNK *pNext; … … 239 233 /** The allocation handle. */ 240 234 RTR0MEMOBJ hMemObj; 241 #endif 242 243 #if ARCH_BITS == 64 235 #elif ARCH_BITS == 64 244 236 /** Pad the size up to 64 bytes. */ 245 237 # ifdef VBGL_PH_USE_MEMOBJ … … 252 244 #if ARCH_BITS == 64 253 245 AssertCompileSize(VBGLPHYSHEAPCHUNK, 64); 246 #elif ARCH_BITS == 32 247 AssertCompileSize(VBGLPHYSHEAPCHUNK, 32); 248 #else 249 # error "Unknown architecture!" 254 250 #endif 255 251 … … 536 532 cbChunk = RT_ALIGN_32(cbChunk, VBGL_PH_CHUNKSIZE); 537 533 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 */ 543 541 #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); 546 544 #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 } 549 558 if (!pChunk) 550 559 { … … 569 578 VBGLPHYSHEAPCHUNK *pOldHeadChunk; 570 579 VBGLPHYSHEAPFREEBLOCK *pBlock; 571 AssertRelease(PhysAddr < _4G && PhysAddr + cbChunk <= _4G); 580 AssertRelease( !g_vbgldata.fAlloc32BitAddr 581 || (PhysAddr < _4G && PhysAddr + cbChunk <= _4G)); 572 582 573 583 /* … … 576 586 pChunk->u32Signature = VBGL_PH_CHUNKSIGNATURE; 577 587 pChunk->cbChunk = cbChunk; 578 pChunk->physAddr = (uint32_t)PhysAddr;588 pChunk->physAddr = PhysAddr; 579 589 pChunk->cBlocks = 0; 580 590 pChunk->cFreeBlocks = 0; … … 586 596 587 597 /* Initialize the padding too: */ 588 #if !defined(VBGL_PH_USE_MEMOBJ) || ARCH_BITS != 32589 pChunk->uPadding1 = UINT32_C(0xADDCAAA1);590 #endif591 598 #if ARCH_BITS == 64 592 599 pChunk->auPadding2[0] = UINT64_C(0xADDCAAA3ADDCAAA2); … … 865 872 866 873 867 DECLR0VBGL( uint32_t) VbglR0PhysHeapGetPhysAddr(void *pv)874 DECLR0VBGL(RTCCPHYS) VbglR0PhysHeapGetPhysAddr(void *pv) 868 875 { 869 876 /* … … 1176 1183 #endif /* IN_TESTCASE */ 1177 1184 1178 DECLR0VBGL(int) VbglR0PhysHeapInit(void) 1179 { 1180 g_vbgldata.hMtxHeap = NIL_RTSEMFASTMUTEX; 1185 DECLR0VBGL(int) VbglR0PhysHeapInit(bool fAlloc32BitAddr) 1186 { 1187 g_vbgldata.fAlloc32BitAddr = fAlloc32BitAddr; 1188 g_vbgldata.hMtxHeap = NIL_RTSEMFASTMUTEX; 1181 1189 1182 1190 /* Allocate the first chunk of the heap. */
Note:
See TracChangeset
for help on using the changeset viewer.