Changeset 3977 in vbox for trunk/src/VBox/Runtime/r0drv/freebsd
- Timestamp:
- Aug 2, 2007 12:37:43 AM (18 years ago)
- svn:sync-xref-src-repo-rev:
- 23399
- Location:
- trunk/src/VBox/Runtime/r0drv/freebsd
- Files:
-
- 1 edited
- 3 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Runtime/r0drv/freebsd/memobj-r0drv-freebsd.c
r3911 r3977 1 1 /* $Id$ */ 2 2 /** @file 3 * innotek Portable Runtime - Ring-0 Memory Objects, OS/2.3 * innotek Portable Runtime - Ring-0 Memory Objects, FreeBSD. 4 4 */ 5 5 … … 33 33 * Header Files * 34 34 *******************************************************************************/ 35 #include "the- os2-kernel.h"35 #include "the-freebsd-kernel.h" 36 36 37 37 #include <iprt/memobj.h> … … 49 49 *******************************************************************************/ 50 50 /** 51 * The OS/2version of the memory object structure.51 * The FreeBSD version of the memory object structure. 52 52 */ 53 typedef struct RTR0MEMOBJ DARWIN53 typedef struct RTR0MEMOBJFREEBSD 54 54 { 55 55 /** The core structure. */ 56 56 RTR0MEMOBJINTERNAL Core; 57 #if 0 57 58 /** Lock for the ring-3 / ring-0 pinned objectes. 58 59 * This member might not be allocated for some object types. */ … … 61 62 * This array can be 0 in length for some object types. */ 62 63 KernPageList_t aPages[1]; 63 } RTR0MEMOBJOS2, *PRTR0MEMOBJOS2; 64 #endif 65 } RTR0MEMOBJFREEBSD, *PRTR0MEMOBJFREEBSD; 64 66 65 67 … … 67 69 * Internal Functions * 68 70 *******************************************************************************/ 69 static void rtR0MemObjFixPageList(KernPageList_t *paPages, ULONG cPages, ULONG cPagesRet);70 71 71 72 72 73 int rtR0MemObjNativeFree(RTR0MEMOBJ pMem) 73 74 { 74 PRTR0MEMOBJ OS2 pMemOs2 = (PRTR0MEMOBJOS2)pMem;75 int rc;76 77 switch (pMem Os2->Core.enmType)75 PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)pMem; 76 // int rc; 77 78 switch (pMemFreeBSD->Core.enmType) 78 79 { 79 80 case RTR0MEMOBJTYPE_PHYS: 80 if (!pMem Os2->Core.pv)81 if (!pMemFreeBSD->Core.pv) 81 82 break; 82 83 83 84 case RTR0MEMOBJTYPE_MAPPING: 84 if (pMem Os2->Core.u.Mapping.R0Process == NIL_RTR0PROCESS)85 if (pMemFreeBSD->Core.u.Mapping.R0Process == NIL_RTR0PROCESS) 85 86 break; 86 87 … … 89 90 case RTR0MEMOBJTYPE_LOW: 90 91 case RTR0MEMOBJTYPE_CONT: 91 rc = KernVMFree(pMemOs2->Core.pv);92 AssertMsg(!rc, ("rc=%d type=%d pv=%p cb=%#zx\n", rc, pMemOs2->Core.enmType, pMemOs2->Core.pv, pMemOs2->Core.cb));92 //rc = KernVMFree(pMemFreeBSD->Core.pv); 93 //AssertMsg(!rc, ("rc=%d type=%d pv=%p cb=%#zx\n", rc, pMemFreeBSD->Core.enmType, pMemFreeBSD->Core.pv, pMemFreeBSD->Core.cb)); 93 94 break; 94 95 95 96 case RTR0MEMOBJTYPE_LOCK: 96 rc = KernVMUnlock(&pMemOs2->Lock);97 AssertMsg(!rc, ("rc=%d\n", rc));97 //rc = KernVMUnlock(&pMemFreeBSD->Lock); 98 //AssertMsg(!rc, ("rc=%d\n", rc)); 98 99 break; 99 100 100 101 case RTR0MEMOBJTYPE_RES_VIRT: 101 102 default: 102 AssertMsgFailed(("enmType=%d\n", pMem Os2->Core.enmType));103 AssertMsgFailed(("enmType=%d\n", pMemFreeBSD->Core.enmType)); 103 104 return VERR_INTERNAL_ERROR; 104 105 } … … 112 113 NOREF(fExecutable); 113 114 115 #if 0 114 116 /* create the object. */ 115 117 const ULONG cPages = cb >> PAGE_SHIFT; 116 PRTR0MEMOBJ OS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_PAGE, NULL, cb);117 if (!pMem Os2)118 PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_PAGE, NULL, cb); 119 if (!pMemFreeBSD) 118 120 return VERR_NO_MEMORY; 119 121 120 122 /* do the allocation. */ 121 int rc = KernVMAlloc(cb, VMDHA_FIXED, &pMem Os2->Core.pv, (PPVOID)-1, NULL);123 int rc = KernVMAlloc(cb, VMDHA_FIXED, &pMemFreeBSD->Core.pv, (PPVOID)-1, NULL); 122 124 if (!rc) 123 125 { 124 126 ULONG cPagesRet = cPages; 125 rc = KernLinToPageList(pMem Os2->Core.pv, cb, &pMemOs2->aPages[0], &cPagesRet);127 rc = KernLinToPageList(pMemFreeBSD->Core.pv, cb, &pMemFreeBSD->aPages[0], &cPagesRet); 126 128 if (!rc) 127 129 { 128 rtR0MemObjFixPageList(&pMem Os2->aPages[0], cPages, cPagesRet);129 *ppMem = &pMem Os2->Core;130 rtR0MemObjFixPageList(&pMemFreeBSD->aPages[0], cPages, cPagesRet); 131 *ppMem = &pMemFreeBSD->Core; 130 132 return VINF_SUCCESS; 131 133 } 132 KernVMFree(pMemOs2->Core.pv); 133 } 134 rtR0MemObjDelete(&pMemOs2->Core); 135 return RTErrConvertFromOS2(rc); 134 KernVMFree(pMemFreeBSD->Core.pv); 135 } 136 rtR0MemObjDelete(&pMemFreeBSD->Core); 137 return RTErrConvertFromOS2(rc); 138 #endif 139 return VERR_NOT_IMPLEMENTED; 136 140 } 137 141 … … 141 145 NOREF(fExecutable); 142 146 143 /* create the object. */ 147 #if 0 148 /* create the object. */ 144 149 const ULONG cPages = cb >> PAGE_SHIFT; 145 PRTR0MEMOBJ OS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOW, NULL, cb);146 if (!pMem Os2)150 PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOW, NULL, cb); 151 if (!pMemFreeBSD) 147 152 return VERR_NO_MEMORY; 148 153 149 154 /* do the allocation. */ 150 int rc = KernVMAlloc(cb, VMDHA_FIXED, &pMem Os2->Core.pv, (PPVOID)-1, NULL);155 int rc = KernVMAlloc(cb, VMDHA_FIXED, &pMemFreeBSD->Core.pv, (PPVOID)-1, NULL); 151 156 if (!rc) 152 157 { 153 158 ULONG cPagesRet = cPages; 154 rc = KernLinToPageList(pMem Os2->Core.pv, cb, &pMemOs2->aPages[0], &cPagesRet);159 rc = KernLinToPageList(pMemFreeBSD->Core.pv, cb, &pMemFreeBSD->aPages[0], &cPagesRet); 155 160 if (!rc) 156 161 { 157 rtR0MemObjFixPageList(&pMem Os2->aPages[0], cPages, cPagesRet);158 *ppMem = &pMem Os2->Core;162 rtR0MemObjFixPageList(&pMemFreeBSD->aPages[0], cPages, cPagesRet); 163 *ppMem = &pMemFreeBSD->Core; 159 164 return VINF_SUCCESS; 160 165 } 161 KernVMFree(pMemOs2->Core.pv); 162 } 163 rtR0MemObjDelete(&pMemOs2->Core); 164 return RTErrConvertFromOS2(rc); 166 KernVMFree(pMemFreeBSD->Core.pv); 167 } 168 rtR0MemObjDelete(&pMemFreeBSD->Core); 169 return RTErrConvertFromOS2(rc); 170 #endif 171 return VERR_NOT_IMPLEMENTED; 165 172 } 166 173 … … 170 177 NOREF(fExecutable); 171 178 172 /* create the object. */ 173 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_CONT, NULL, cb); 174 if (!pMemOs2) 179 #if 0 180 /* create the object. */ 181 PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_CONT, NULL, cb); 182 if (!pMemFreeBSD) 175 183 return VERR_NO_MEMORY; 176 184 177 185 /* do the allocation. */ 178 186 ULONG ulPhys = ~0UL; 179 int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG, &pMem Os2->Core.pv, (PPVOID)&ulPhys, NULL);187 int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG, &pMemFreeBSD->Core.pv, (PPVOID)&ulPhys, NULL); 180 188 if (!rc) 181 189 { 182 190 Assert(ulPhys != ~0UL); 183 pMemOs2->Core.u.Cont.Phys = ulPhys; 184 *ppMem = &pMemOs2->Core; 185 return VINF_SUCCESS; 186 } 187 rtR0MemObjDelete(&pMemOs2->Core); 188 return RTErrConvertFromOS2(rc); 191 pMemFreeBSD->Core.u.Cont.Phys = ulPhys; 192 *ppMem = &pMemFreeBSD->Core; 193 return VINF_SUCCESS; 194 } 195 rtR0MemObjDelete(&pMemFreeBSD->Core); 196 return RTErrConvertFromOS2(rc); 197 #endif 198 return VERR_NOT_IMPLEMENTED; 189 199 } 190 200 … … 193 203 { 194 204 AssertMsgReturn(PhysHighest >= 16 *_1M, ("PhysHigest=%VHp\n", PhysHighest), VERR_NOT_IMPLEMENTED); 195 196 /* create the object. */ 197 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb); 198 if (!pMemOs2) 205 206 #if 0 207 /* create the object. */ 208 PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb); 209 if (!pMemFreeBSD) 199 210 return VERR_NO_MEMORY; 200 211 201 212 /* do the allocation. */ 202 213 ULONG ulPhys = ~0UL; 203 int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG | (PhysHighest < _4G ? VMDHA_16M : 0), &pMem Os2->Core.pv, (PPVOID)&ulPhys, NULL);214 int rc = KernVMAlloc(cb, VMDHA_FIXED | VMDHA_CONTIG | (PhysHighest < _4G ? VMDHA_16M : 0), &pMemFreeBSD->Core.pv, (PPVOID)&ulPhys, NULL); 204 215 if (!rc) 205 216 { 206 217 Assert(ulPhys != ~0UL); 207 pMemOs2->Core.u.Phys.fAllocated = true; 208 pMemOs2->Core.u.Phys.PhysBase = ulPhys; 209 *ppMem = &pMemOs2->Core; 210 return VINF_SUCCESS; 211 } 212 rtR0MemObjDelete(&pMemOs2->Core); 213 return RTErrConvertFromOS2(rc); 218 pMemFreeBSD->Core.u.Phys.fAllocated = true; 219 pMemFreeBSD->Core.u.Phys.PhysBase = ulPhys; 220 *ppMem = &pMemFreeBSD->Core; 221 return VINF_SUCCESS; 222 } 223 rtR0MemObjDelete(&pMemFreeBSD->Core); 224 return RTErrConvertFromOS2(rc); 225 #endif 226 return VERR_NOT_IMPLEMENTED; 214 227 } 215 228 … … 217 230 int rtR0MemObjNativeEnterPhys(PPRTR0MEMOBJINTERNAL ppMem, RTHCPHYS Phys, size_t cb) 218 231 { 219 /* create the object. */ 220 PRTR0MEMOBJOS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb); 221 if (!pMemOs2) 232 #if 0 233 /* create the object. */ 234 PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_PHYS, NULL, cb); 235 if (!pMemFreeBSD) 222 236 return VERR_NO_MEMORY; 223 237 224 238 /* there is no allocation here, right? it needs to be mapped somewhere first. */ 225 pMem Os2->Core.u.Phys.fAllocated = false;226 pMem Os2->Core.u.Phys.PhysBase = Phys;227 *ppMem = &pMem Os2->Core;239 pMemFreeBSD->Core.u.Phys.fAllocated = false; 240 pMemFreeBSD->Core.u.Phys.PhysBase = Phys; 241 *ppMem = &pMemFreeBSD->Core; 228 242 return VINF_SUCCESS; 243 #endif 244 return VERR_NOT_IMPLEMENTED; 229 245 } 230 246 … … 232 248 int rtR0MemObjNativeLockUser(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb, RTR0PROCESS R0Process) 233 249 { 250 #if 0 234 251 AssertMsgReturn(R0Process == RTR0ProcHandleSelf(), ("%p != %p\n", R0Process, RTR0ProcHandleSelf()), VERR_NOT_SUPPORTED); 235 252 236 253 /* create the object. */ 237 254 const ULONG cPages = cb >> PAGE_SHIFT; 238 PRTR0MEMOBJ OS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, pv, cb);239 if (!pMem Os2)255 PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, pv, cb); 256 if (!pMemFreeBSD) 240 257 return VERR_NO_MEMORY; 241 258 242 259 /* lock it. */ 243 260 ULONG cPagesRet = cPages; 244 int rc = KernVMLock(VMDHL_LONG | VMDHL_WRITE, pv, cb, &pMemOs2->Lock, &pMemOs2->aPages[0], &cPagesRet); 245 if (!rc) 246 { 247 rtR0MemObjFixPageList(&pMemOs2->aPages[0], cPages, cPagesRet); 248 Assert(cb == pMemOs2->Core.cb); 249 Assert(pv == pMemOs2->Core.pv); 250 pMemOs2->Core.u.Lock.R0Process = R0Process; 251 *ppMem = &pMemOs2->Core; 252 return VINF_SUCCESS; 253 } 254 rtR0MemObjDelete(&pMemOs2->Core); 255 return RTErrConvertFromOS2(rc); 261 int rc = KernVMLock(VMDHL_LONG | VMDHL_WRITE, pv, cb, &pMemFreeBSD->Lock, &pMemFreeBSD->aPages[0], &cPagesRet); 262 if (!rc) 263 { 264 rtR0MemObjFixPageList(&pMemFreeBSD->aPages[0], cPages, cPagesRet); 265 Assert(cb == pMemFreeBSD->Core.cb); 266 Assert(pv == pMemFreeBSD->Core.pv); 267 pMemFreeBSD->Core.u.Lock.R0Process = R0Process; 268 *ppMem = &pMemFreeBSD->Core; 269 return VINF_SUCCESS; 270 } 271 rtR0MemObjDelete(&pMemFreeBSD->Core); 272 return RTErrConvertFromOS2(rc); 273 #endif 274 return VERR_NOT_IMPLEMENTED; 256 275 } 257 276 … … 259 278 int rtR0MemObjNativeLockKernel(PPRTR0MEMOBJINTERNAL ppMem, void *pv, size_t cb) 260 279 { 280 #if 0 261 281 /* create the object. */ 262 282 const ULONG cPages = cb >> PAGE_SHIFT; 263 PRTR0MEMOBJ OS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, pv, cb);264 if (!pMem Os2)283 PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, aPages[cPages]), RTR0MEMOBJTYPE_LOCK, pv, cb); 284 if (!pMemFreeBSD) 265 285 return VERR_NO_MEMORY; 266 286 267 287 /* lock it. */ 268 288 ULONG cPagesRet = cPages; 269 int rc = KernVMLock(VMDHL_LONG | VMDHL_WRITE, pv, cb, &pMemOs2->Lock, &pMemOs2->aPages[0], &cPagesRet); 270 if (!rc) 271 { 272 rtR0MemObjFixPageList(&pMemOs2->aPages[0], cPages, cPagesRet); 273 pMemOs2->Core.u.Lock.R0Process = NIL_RTR0PROCESS; 274 *ppMem = &pMemOs2->Core; 275 return VINF_SUCCESS; 276 } 277 rtR0MemObjDelete(&pMemOs2->Core); 278 return RTErrConvertFromOS2(rc); 289 int rc = KernVMLock(VMDHL_LONG | VMDHL_WRITE, pv, cb, &pMemFreeBSD->Lock, &pMemFreeBSD->aPages[0], &cPagesRet); 290 if (!rc) 291 { 292 rtR0MemObjFixPageList(&pMemFreeBSD->aPages[0], cPages, cPagesRet); 293 pMemFreeBSD->Core.u.Lock.R0Process = NIL_RTR0PROCESS; 294 *ppMem = &pMemFreeBSD->Core; 295 return VINF_SUCCESS; 296 } 297 rtR0MemObjDelete(&pMemFreeBSD->Core); 298 return RTErrConvertFromOS2(rc); 299 #endif 300 return VERR_NOT_IMPLEMENTED; 279 301 } 280 302 … … 296 318 AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED); 297 319 320 #if 0 298 321 /** @todo finish the implementation. */ 299 322 300 323 int rc; 301 324 void *pvR0 = NULL; 302 PRTR0MEMOBJ OS2 pMemToMapOs2 = (PRTR0MEMOBJOS2)pMemToMap;325 PRTR0MEMOBJFREEBSD pMemToMapOs2 = (PRTR0MEMOBJFREEBSD)pMemToMap; 303 326 switch (pMemToMapOs2->Core.enmType) 304 327 { … … 349 372 * (reference counting). 350 373 */ 351 PRTR0MEMOBJ OS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_MAPPING, pvR0, pMemToMapOs2->Core.cb);352 if (pMem Os2)353 { 354 pMem Os2->Core.u.Mapping.R0Process = NIL_RTR0PROCESS;355 *ppMem = &pMem Os2->Core;374 PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_MAPPING, pvR0, pMemToMapOs2->Core.cb); 375 if (pMemFreeBSD) 376 { 377 pMemFreeBSD->Core.u.Mapping.R0Process = NIL_RTR0PROCESS; 378 *ppMem = &pMemFreeBSD->Core; 356 379 return VINF_SUCCESS; 357 380 } 358 381 return VERR_NO_MEMORY; 382 #endif 383 return VERR_NOT_IMPLEMENTED; 359 384 } 360 385 … … 365 390 AssertMsgReturn(pvFixed == (void *)-1, ("%p\n", pvFixed), VERR_NOT_SUPPORTED); 366 391 392 #if 0 367 393 int rc; 368 394 void *pvR0; 369 395 void *pvR3 = NULL; 370 PRTR0MEMOBJ OS2 pMemToMapOs2 = (PRTR0MEMOBJOS2)pMemToMap;396 PRTR0MEMOBJFREEBSD pMemToMapOs2 = (PRTR0MEMOBJFREEBSD)pMemToMap; 371 397 switch (pMemToMapOs2->Core.enmType) 372 398 { … … 431 457 * Create a mapping object for it. 432 458 */ 433 PRTR0MEMOBJ OS2 pMemOs2 = (PRTR0MEMOBJOS2)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_MAPPING, pvR3, pMemToMapOs2->Core.cb);434 if (pMem Os2)435 { 436 Assert(pMem Os2->Core.pv == pvR3);437 pMem Os2->Core.u.Mapping.R0Process = R0Process;438 *ppMem = &pMem Os2->Core;459 PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)rtR0MemObjNew(RT_OFFSETOF(RTR0MEMOBJOS2, Lock), RTR0MEMOBJTYPE_MAPPING, pvR3, pMemToMapOs2->Core.cb); 460 if (pMemFreeBSD) 461 { 462 Assert(pMemFreeBSD->Core.pv == pvR3); 463 pMemFreeBSD->Core.u.Mapping.R0Process = R0Process; 464 *ppMem = &pMemFreeBSD->Core; 439 465 return VINF_SUCCESS; 440 466 } 441 467 KernVMFree(pvR3); 442 468 return VERR_NO_MEMORY; 469 #endif 470 return VERR_NOT_IMPLEMENTED; 443 471 } 444 472 … … 446 474 RTHCPHYS rtR0MemObjNativeGetPagePhysAddr(PRTR0MEMOBJINTERNAL pMem, unsigned iPage) 447 475 { 448 PRTR0MEMOBJ OS2 pMemOs2 = (PRTR0MEMOBJOS2)pMem;449 450 switch (pMem Os2->Core.enmType)476 PRTR0MEMOBJFREEBSD pMemFreeBSD = (PRTR0MEMOBJFREEBSD)pMem; 477 478 switch (pMemFreeBSD->Core.enmType) 451 479 { 452 480 case RTR0MEMOBJTYPE_PAGE: 453 481 case RTR0MEMOBJTYPE_LOW: 454 482 case RTR0MEMOBJTYPE_LOCK: 455 return pMemOs2->aPages[iPage].Addr; 483 // return pMemFreeBSD->aPages[iPage].Addr; 484 return NIL_RTHCPHYS; 456 485 457 486 case RTR0MEMOBJTYPE_CONT: 458 return pMem Os2->Core.u.Cont.Phys + (iPage << PAGE_SHIFT);487 return pMemFreeBSD->Core.u.Cont.Phys + (iPage << PAGE_SHIFT); 459 488 460 489 case RTR0MEMOBJTYPE_PHYS: 461 return pMem Os2->Core.u.Phys.PhysBase + (iPage << PAGE_SHIFT);490 return pMemFreeBSD->Core.u.Phys.PhysBase + (iPage << PAGE_SHIFT); 462 491 463 492 case RTR0MEMOBJTYPE_RES_VIRT: … … 467 496 } 468 497 } 469 470 471 /**472 * Expands the page list so we can index pages directly.473 *474 * @param paPages The page list array to fix.475 * @param cPages The number of pages that's supposed to go into the list.476 * @param cPagesRet The actual number of pages in the list.477 */478 static void rtR0MemObjFixPageList(KernPageList_t *paPages, ULONG cPages, ULONG cPagesRet)479 {480 Assert(cPages >= cPagesRet);481 if (cPages != cPagesRet)482 {483 ULONG iIn = cPagesRet;484 ULONG iOut = cPages;485 do486 {487 iIn--;488 iOut--;489 Assert(iIn <= iOut);490 491 KernPageList_t Page = paPages[iIn];492 Assert(!(Page.Addr & PAGE_OFFSET_MASK));493 Assert(Page.Size == RT_ALIGN_Z(Page.Size, PAGE_SIZE));494 495 if (Page.Size > PAGE_SIZE)496 {497 do498 {499 Page.Size -= PAGE_SIZE;500 paPages[iOut].Addr = Page.Addr + Page.Size;501 paPages[iOut].Size = PAGE_SIZE;502 iOut--;503 } while (Page.Size > PAGE_SIZE);504 }505 506 paPages[iOut].Addr = Page.Addr;507 paPages[iOut].Size = PAGE_SIZE;508 } while ( iIn != iOut509 && iIn > 0);510 }511 }512 -
trunk/src/VBox/Runtime/r0drv/freebsd/the-freebsd-kernel.h
r3680 r3977 52 52 #include <sys/mutex.h> 53 53 #include <sys/sched.h> 54 #include <sys/callout.h> 54 55 #include <vm/vm.h> /* for vtophys */ 55 56 #include <vm/pmap.h> /* for vtophys */ -
trunk/src/VBox/Runtime/r0drv/freebsd/time-r0drv-freebsd.c
r3911 r3977 1 1 /* $Id$ */ 2 2 /** @file 3 * innotek Portable Runtime - Time, Ring-0 Driver, OS/2.3 * innotek Portable Runtime - Time, Ring-0 Driver, FreeBSD. 4 4 */ 5 5 … … 33 33 * Header Files * 34 34 *******************************************************************************/ 35 #include "the-os2-kernel.h" 35 #include "the-freebsd-kernel.h" 36 #define RTTIME_INCL_TIMESPEC 36 37 37 38 #include <iprt/time.h> … … 40 41 RTDECL(uint64_t) RTTimeNanoTS(void) 41 42 { 42 /** @remark OS/2 Ring-0: will wrap after 48 days. */ 43 return g_pGIS->msecs * UINT64_C(1000000); 43 struct timespec tsp; 44 nanouptime(&tsp); 45 return tsp.tv_sec * UINT64_C(1000000000) 46 + tsp.tv_nsec; 44 47 } 45 48 … … 47 50 RTDECL(uint64_t) RTTimeMilliTS(void) 48 51 { 49 /** @remark OS/2 Ring-0: will wrap after 48 days. */ 50 return g_pGIS->msecs; 52 return RTTimeNanoTS() / 1000; 51 53 } 52 54 … … 54 56 RTDECL(uint64_t) RTTimeSystemNanoTS(void) 55 57 { 56 /** @remark OS/2 Ring-0: will wrap after 48 days. */ 57 return g_pGIS->msecs * UINT64_C(1000000); 58 return RTTimeNanoTS(); 58 59 } 59 60 … … 61 62 RTDECL(uint64_t) RTTimeSystemMilliTS(void) 62 63 { 63 /** @remark OS/2 Ring-0: will wrap after 48 days. */ 64 return g_pGIS->msecs; 64 return RTTimeMilliTS(); 65 65 } 66 66 … … 68 68 RTDECL(PRTTIMESPEC) RTTimeNow(PRTTIMESPEC pTime) 69 69 { 70 /* 71 * Get the seconds since the unix epoch (local time) and current hundredths. 72 */ 73 GINFOSEG volatile *pGIS = (GINFOSEG volatile *)g_pGIS; 74 UCHAR uchHundredths; 75 ULONG ulSeconds; 76 do 77 { 78 uchHundredths = pGIS->hundredths; 79 ulSeconds = pGIS->time; 80 } while ( uchHundredths == pGIS->hundredths 81 && ulSeconds == pGIS->time); 82 83 /* 84 * Combine the two and convert to UCT (later). 85 */ 86 uint64_t u64 = ulSeconds * UINT64_C(1000000000) + (uint32_t)uchHundredths * 10000000; 87 /** @todo convert from local to UCT. */ 88 89 /** @remark OS/2 Ring-0: Currently returns local time instead of UCT. */ 90 return RTTimeSpecSetNano(pTime, u64); 70 struct timespec tsp; 71 nanotime(&tsp); 72 return RTTimeSpecSetTimespec(pTime, &tsp); 91 73 } 92 -
trunk/src/VBox/Runtime/r0drv/freebsd/timer-r0drv-freebsd.c
r3911 r3977 1 1 /* $Id$ */ 2 2 /** @file 3 * innotek Portable Runtime - Memory Allocation, Ring-0 Driver, OS/2.3 * innotek Portable Runtime - Memory Allocation, Ring-0 Driver, FreeBSD. 4 4 */ 5 5 … … 33 33 * Header Files * 34 34 *******************************************************************************/ 35 #include "the- os2-kernel.h"35 #include "the-freebsd-kernel.h" 36 36 37 37 #include <iprt/timer.h> … … 50 50 *******************************************************************************/ 51 51 /** 52 * The internal representation of an OS/2timer handle.52 * The internal representation of an FreeBSD timer handle. 53 53 */ 54 54 typedef struct RTTIMER … … 58 58 * is destroyed to indicate clearly that thread should exit. */ 59 59 uint32_t volatile u32Magic; 60 /** The next timer in the timer list. */61 PRTTIMER pNext;62 60 /** Flag indicating the the timer is suspended. */ 63 61 uint8_t volatile fSuspended; 64 /** Cleared at the start of timer processing, set when calling pfnTimer. 65 * If any timer changes occures while doing the callback this will be used to resume the cycle. */ 66 bool fDone; 62 /** Whether the timer must run on a specific CPU or not. */ 63 uint8_t fSpecificCpu; 64 /** The CPU it must run on if fSpecificCpu is set. */ 65 uint8_t iCpu; 66 /** The FreeBSD callout structure. */ 67 struct callout Callout; 67 68 /** Callback. */ 68 69 PFNRTTIMER pfnTimer; … … 83 84 84 85 /******************************************************************************* 85 * Global Variables *86 *******************************************************************************/87 /** Spinlock protecting the timers. */88 static RTSPINLOCK g_Spinlock = NIL_RTSPINLOCK;89 /** The timer head. */90 static PRTTIMER volatile g_pTimerHead = NULL;91 /** The number of active timers. */92 static uint32_t volatile g_cActiveTimers = 0;93 /** The number of active timers. */94 static uint32_t volatile g_cTimers = 0;95 /** The change number.96 * This is used to detect list changes during the timer callback loop. */97 static uint32_t volatile g_u32ChangeNo;98 99 100 /*******************************************************************************101 86 * Internal Functions * 102 87 *******************************************************************************/ 103 __BEGIN_DECLS 104 DECLASM(void) rtTimerOs2Tick(void); 105 DECLASM(int) rtTimerOs2Arm(void); 106 DECLASM(int) rtTimerOs2Dearm(void); 107 __END_DECLS 108 109 110 111 RTDECL(int) RTTimerCreate(PRTTIMER *ppTimer, unsigned uMilliesInterval, PFNRTTIMER pfnTimer, void *pvUser) 112 { 113 int rc = RTTimerCreateEx(ppTimer, uMilliesInterval * UINT64_C(1000000), 0, pfnTimer, pvUser); 114 if (RT_SUCCESS(rc)) 115 { 116 rc = RTTimerStart(*ppTimer, 0); 117 if (RT_SUCCESS(rc)) 118 return rc; 119 int rc2 = RTTimerDestroy(*ppTimer); AssertRC(rc2); 120 *ppTimer = NULL; 121 } 122 return rc; 123 } 88 static void rtTimerFreeBSDCallback(void *pvTimer); 89 124 90 125 91 … … 129 95 130 96 /* 131 * Lazy initialize the spinlock. 132 */ 133 if (g_Spinlock == NIL_RTSPINLOCK) 134 { 135 RTSPINLOCK Spinlock; 136 int rc = RTSpinlockCreate(&Spinlock); 137 AssertRCReturn(rc, rc); 138 //bool fRc; 139 //ASMAtomicCmpXchgSize(&g_Spinlock, Spinlock, NIL_RTSPINLOCK, fRc); 140 //if (!fRc) 141 if (!ASMAtomicCmpXchgPtr((void * volatile *)&g_Spinlock, Spinlock, NIL_RTSPINLOCK)) 142 RTSpinlockDestroy(Spinlock); 143 } 144 97 * Validate flags. 98 */ 99 if (!RTTIMER_FLAGS_IS_VALID(fFlags)) 100 return VERR_INVALID_PARAMETER; 101 if ( (fFlags & RTTIMER_FLAGS_CPU_SPECIFIC) 102 && (fFlags & RTTIMER_FLAGS_CPU_ALL) != RTTIMER_FLAGS_CPU_ALL 103 && (fFlags & RTTIMER_FLAGS_CPU_MASK) > mp_maxid) 104 return VERR_INVALID_PARAMETER; 105 145 106 /* 146 107 * Allocate and initialize the timer handle. … … 151 112 152 113 pTimer->u32Magic = RTTIMER_MAGIC; 153 pTimer->pNext = NULL;154 114 pTimer->fSuspended = true; 115 pTimer->fSpecificCpu = !!(fFlags & RTTIMER_FLAGS_CPU_SPECIFIC); 116 pTimer->iCpu = fFlags & RTTIMER_FLAGS_CPU_MASK; 155 117 pTimer->pfnTimer = pfnTimer; 156 118 pTimer->pvUser = pvUser; 157 119 pTimer->u64NanoInterval = u64NanoInterval; 158 120 pTimer->u64StartTS = 0; 159 160 /* 161 * Insert the timer into the list (LIFO atm). 162 */ 163 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 164 RTSpinlockAcquireNoInts(g_Spinlock, &Tmp); 165 g_u32ChangeNo++; 166 pTimer->pNext = g_pTimerHead; 167 g_pTimerHead = pTimer; 168 g_cTimers++; 169 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp); 121 callout_init(&pTimer->Callout, CALLOUT_MPSAFE); 170 122 171 123 *ppTimer = pTimer; … … 197 149 198 150 /* 199 * Remove it from the list.200 */201 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;202 RTSpinlockAcquireNoInts(g_Spinlock, &Tmp);203 g_u32ChangeNo++;204 if (g_pTimerHead == pTimer)205 g_pTimerHead = pTimer->pNext;206 else207 {208 PRTTIMER pPrev = g_pTimerHead;209 while (pPrev->pNext != pTimer)210 {211 pPrev = pPrev->pNext;212 if (RT_UNLIKELY(!pPrev))213 {214 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp);215 return VERR_INVALID_HANDLE;216 }217 }218 pPrev->pNext = pTimer->pNext;219 }220 Assert(g_cTimers > 0);221 g_cTimers--;222 if (!pTimer->fSuspended)223 {224 Assert(g_cActiveTimers > 0);225 g_cActiveTimers--;226 if (!g_cActiveTimers)227 rtTimerOs2Dearm();228 }229 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp);230 231 /*232 151 * Free the associated resources. 233 152 */ 234 153 pTimer->u32Magic++; 154 callout_stop(&pTimer->Callout); 235 155 RTMemFree(pTimer); 236 156 return VINF_SUCCESS; … … 240 160 RTDECL(int) RTTimerStart(PRTTIMER pTimer, uint64_t u64First) 241 161 { 162 struct timeval tv; 163 242 164 if (!rtTimerIsValid(pTimer)) 243 165 return VERR_INVALID_HANDLE; … … 246 168 247 169 /* 248 * Calc when it should start fireing and give the thread a kick so it get going.170 * Calc when it should start fireing. 249 171 */ 250 172 u64First += RTTimeNanoTS(); 251 173 252 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;253 RTSpinlockAcquireNoInts(g_Spinlock, &Tmp);254 g_u32ChangeNo++;255 if (!g_cActiveTimers)256 {257 int rc = rtTimerOs2Arm();258 if (RT_FAILURE(rc))259 {260 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp);261 return rc;262 }263 }264 g_cActiveTimers++;265 174 pTimer->fSuspended = false; 266 pTimer->fDone = true; /* next tick, not current! */267 175 pTimer->iTick = 0; 268 176 pTimer->u64StartTS = u64First; 269 177 pTimer->u64NextTS = u64First; 270 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp); 178 179 tv.tv_sec = u64First / 1000000000; 180 tv.tv_usec = (u64First % 1000000000) / 1000; 181 callout_reset(&pTimer->Callout, tvtohz(&tv), rtTimerFreeBSDCallback, pTimer); 271 182 272 183 return VINF_SUCCESS; … … 284 195 * Suspend the timer. 285 196 */ 286 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER;287 RTSpinlockAcquireNoInts(g_Spinlock, &Tmp);288 g_u32ChangeNo++;289 197 pTimer->fSuspended = true; 290 Assert(g_cActiveTimers > 0); 291 g_cActiveTimers--; 292 if (!g_cActiveTimers) 293 rtTimerOs2Dearm(); 294 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp); 295 296 return VINF_SUCCESS; 297 } 298 299 300 DECLASM(void) rtTimerOs2Tick(void) 301 { 302 /* 303 * Query the current time and then take the lock. 304 */ 305 const uint64_t u64NanoTS = RTTimeNanoTS(); 306 307 RTSPINLOCKTMP Tmp = RTSPINLOCKTMP_INITIALIZER; 308 RTSpinlockAcquireNoInts(g_Spinlock, &Tmp); 309 310 /* 311 * Clear the fDone flag. 312 */ 313 PRTTIMER pTimer; 314 for (pTimer = g_pTimerHead; pTimer; pTimer = pTimer->pNext) 315 pTimer->fDone = false; 316 317 /* 318 * Walk the timer list and do the callbacks for any active timer. 319 */ 320 uint32_t u32CurChangeNo = g_u32ChangeNo; 321 pTimer = g_pTimerHead; 322 while (pTimer) 198 callout_stop(&pTimer->Callout); 199 200 return VINF_SUCCESS; 201 } 202 203 204 /** 205 * smp_rendezvous action callback. 206 * 207 * This will perform the timer callback if we're on the right CPU. 208 * 209 * @param pvTimer The timer. 210 */ 211 static void rtTimerFreeBSDIpiAction(void *pvTimer) 212 { 213 PRTTIMER pTimer = (PRTTIMER)pvTimer; 214 if ( pTimer->iCpu == RTTIMER_FLAGS_CPU_ALL 215 || (u_int)pTimer->iCpu == curcpu) 216 pTimer->pfnTimer(pTimer, pTimer->pvUser); 217 } 218 219 220 static void rtTimerFreeBSDCallback(void *pvTimer) 221 { 222 PRTTIMER pTimer = (PRTTIMER)pvTimer; 223 224 /* calculate and set the next timeout */ 225 if (!pTimer->u64NanoInterval) 323 226 { 324 PRTTIMER pNext = pTimer->pNext; 325 if ( !pTimer->fSuspended 326 && !pTimer->fDone 327 && pTimer->u64NextTS <= u64NanoTS) 328 { 329 pTimer->fDone = true; 330 331 /* calculate the next timeout */ 332 if (!pTimer->u64NanoInterval) 333 pTimer->fSuspended = true; 334 else 335 { 336 pTimer->u64NextTS = pTimer->u64StartTS + pTimer->iTick * pTimer->u64NanoInterval; 337 if (pTimer->u64NextTS < u64NanoTS) 338 pTimer->u64NextTS = u64NanoTS + RTTimerGetSystemGranularity() / 2; 339 } 340 341 /* do the callout */ 342 PFNRTTIMER pfnTimer = pTimer->pfnTimer; 343 void *pvUser = pTimer->pvUser; 344 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp); 345 pfnTimer(pTimer, pvUser); 346 347 RTSpinlockAcquireNoInts(g_Spinlock, &Tmp); 348 349 /* check if anything changed. */ 350 if (u32CurChangeNo != g_u32ChangeNo) 351 { 352 u32CurChangeNo = g_u32ChangeNo; 353 pNext = g_pTimerHead; 354 } 355 } 356 357 /* next */ 358 pTimer = pNext; 227 pTimer->fSuspended = true; 228 callout_stop(&pTimer->Callout); 359 229 } 360 361 RTSpinlockReleaseNoInts(g_Spinlock, &Tmp); 230 else 231 { 232 struct timeval tv; 233 const uint64_t u64NanoTS = RTTimeNanoTS(); 234 pTimer->u64NextTS = pTimer->u64StartTS + pTimer->iTick * pTimer->u64NanoInterval; 235 if (pTimer->u64NextTS < u64NanoTS) 236 pTimer->u64NextTS = u64NanoTS + RTTimerGetSystemGranularity() / 2; 237 238 tv.tv_sec = pTimer->u64NextTS / 1000000000; 239 tv.tv_usec = (pTimer->u64NextTS % 1000000000) / 1000; 240 callout_reset(&pTimer->Callout, tvtohz(&tv), rtTimerFreeBSDCallback, pTimer); 241 } 242 243 /* callback */ 244 if ( !pTimer->fSpecificCpu 245 || pTimer->iCpu == curcpu) 246 pTimer->pfnTimer(pTimer, pTimer->pvUser); 247 else 248 smp_rendezvous(NULL, rtTimerFreeBSDIpiAction, NULL, pvTimer); 362 249 } 363 250 … … 365 252 RTDECL(uint32_t) RTTimerGetSystemGranularity(void) 366 253 { 367 return 32000000; /* 32ms */254 return 1000000000 / hz; /* ns */ 368 255 } 369 256
Note:
See TracChangeset
for help on using the changeset viewer.