Changeset 37466 in vbox for trunk/src/VBox/VMM
- Timestamp:
- Jun 15, 2011 12:44:16 PM (14 years ago)
- svn:sync-xref-src-repo-rev:
- 72280
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMAll/IOMAll.cpp
r37452 r37466 94 94 } 95 95 96 96 97 /** 97 98 * Returns the contents of register or immediate data of instruction's parameter. … … 316 317 void *pvUser = pRange->pvUser; 317 318 PPDMDEVINS pDevIns = pRange->pDevIns; 318 PPDMCRITSECT pCritSect = pDevIns->CTX_SUFF(pCritSect );319 PPDMCRITSECT pCritSect = pDevIns->CTX_SUFF(pCritSectRo); 319 320 320 321 /* … … 512 513 void *pvUser = pRange->pvUser; 513 514 PPDMDEVINS pDevIns = pRange->pDevIns; 514 PPDMCRITSECT pCritSect = pDevIns->CTX_SUFF(pCritSect );515 PPDMCRITSECT pCritSect = pDevIns->CTX_SUFF(pCritSectRo); 515 516 516 517 /* … … 680 681 } 681 682 #endif 682 void *pvUser = 683 void *pvUser = pRange->pvUser; 683 684 PPDMDEVINS pDevIns = pRange->pDevIns; 684 PPDMCRITSECT pCritSect = pDevIns->CTX_SUFF(pCritSect );685 PPDMCRITSECT pCritSect = pDevIns->CTX_SUFF(pCritSectRo); 685 686 686 687 /* … … 852 853 void *pvUser = pRange->pvUser; 853 854 PPDMDEVINS pDevIns = pRange->pDevIns; 854 PPDMCRITSECT pCritSect = pDevIns->CTX_SUFF(pCritSect );855 PPDMCRITSECT pCritSect = pDevIns->CTX_SUFF(pCritSectRo); 855 856 856 857 /* -
trunk/src/VBox/VMM/VMMAll/IOMAllMMIO.cpp
r37452 r37466 1137 1137 iomMmioRetainRange(pRange); 1138 1138 PPDMDEVINS pDevIns = pRange->CTX_SUFF(pDevIns); 1139 PPDMCRITSECT pLock = pDevIns->CTX_SUFF(pCritSect );1139 PPDMCRITSECT pLock = pDevIns->CTX_SUFF(pCritSectRo); 1140 1140 if (!pLock) 1141 1141 pLock = &pVM->iom.s.EmtLock; … … 1376 1376 iomMmioRetainRange(pRange); 1377 1377 PPDMDEVINS pDevIns = pRange->CTX_SUFF(pDevIns); 1378 PPDMCRITSECT pLock = pDevIns->CTX_SUFF(pCritSect );1378 PPDMCRITSECT pLock = pDevIns->CTX_SUFF(pCritSectRo); 1379 1379 if (!pLock) 1380 1380 pLock = &pVM->iom.s.EmtLock; … … 1460 1460 iomMmioRetainRange(pRange); 1461 1461 PPDMDEVINS pDevIns = pRange->CTX_SUFF(pDevIns); 1462 PPDMCRITSECT pLock = pDevIns->CTX_SUFF(pCritSect );1462 PPDMCRITSECT pLock = pDevIns->CTX_SUFF(pCritSectRo); 1463 1463 if (!pLock) 1464 1464 pLock = &pVM->iom.s.EmtLock; … … 1610 1610 iomMmioRetainRange(pRange); 1611 1611 PPDMDEVINS pDevIns = pRange->CTX_SUFF(pDevIns); 1612 PPDMCRITSECT pLock = pDevIns->CTX_SUFF(pCritSect );1612 PPDMCRITSECT pLock = pDevIns->CTX_SUFF(pCritSectRo); 1613 1613 if (!pLock) 1614 1614 pLock = &pVM->iom.s.EmtLock; -
trunk/src/VBox/VMM/VMMR3/IOM.cpp
r37452 r37466 159 159 * Initialize the REM critical section. 160 160 */ 161 int rc = PDMR3CritSectInit(pVM, &pVM->iom.s.EmtLock, RT_SRC_POS, "IOM EMTLock");161 int rc = PDMR3CritSectInit(pVM, &pVM->iom.s.EmtLock, RT_SRC_POS, "IOM Lock"); 162 162 AssertRCReturn(rc, rc); 163 163 … … 1707 1707 1708 1708 /** 1709 * For TM only!1710 *1711 * @returns Pointer to the critical section.1712 * @param pVM The VM handle.1713 */1714 VMMR3DECL(PPDMCRITSECT) IOMR3GetCritSect(PVM pVM)1715 {1716 return &pVM->iom.s.EmtLock;1717 }1718 1719 1720 /**1721 1709 * Display a single MMIO range. 1722 1710 * -
trunk/src/VBox/VMM/VMMR3/PDM.cpp
r37443 r37466 366 366 rc = PDMR3CritSectInit(pVM, &pVM->pdm.s.CritSect, RT_SRC_POS, "PDM"); 367 367 if (RT_SUCCESS(rc)) 368 rc = PDMR3CritSectInit(pVM, &pVM->pdm.s.GiantDevCritSect, RT_SRC_POS, "Giant PDM Dev");369 if (RT_SUCCESS(rc))370 368 { 371 369 rc = PDMR3CritSectInit(pVM, &pVM->pdm.s.NopCritSect, RT_SRC_POS, "NOP"); … … 507 505 pDevIns->pHlpRC = pDevHlpRC; 508 506 pDevIns->pvInstanceDataRC = MMHyperR3ToRC(pVM, pDevIns->pvInstanceDataR3); 509 if (pDevIns->pCritSectR 3)510 pDevIns->pCritSectR C = MMHyperR3ToRC(pVM, pDevIns->pCritSectR3);507 if (pDevIns->pCritSectRoR3) 508 pDevIns->pCritSectRoRC = MMHyperR3ToRC(pVM, pDevIns->pCritSectRoR3); 511 509 pDevIns->Internal.s.pVMRC = pVM->pVMRC; 512 510 if (pDevIns->Internal.s.pPciBusR3) -
trunk/src/VBox/VMM/VMMR3/PDMCritSect.cpp
r37443 r37466 165 165 pCritSect->pVMRC = pVM->pVMRC; 166 166 pCritSect->pvKey = pvKey; 167 pCritSect->fAutomaticDefaultCritsect = false; 168 pCritSect->fUsedByTimerOrSimilar = false; 167 169 pCritSect->EventToSignal = NIL_RTSEMEVENT; 168 170 pCritSect->pNext = pVM->pUVM->pdm.s.pCritSects; … … 236 238 { 237 239 return pdmR3CritSectInitOne(pVM, &pCritSect->s, pDevIns, RT_SRC_POS_ARGS, pszNameFmt, va); 240 } 241 242 243 /** 244 * Initializes the automatic default PDM critical section for a device. 245 * 246 * @returns VBox status code. 247 * @param pVM The VM handle. 248 * @param pDevIns Device instance. 249 * @param pCritSect Pointer to the critical section. 250 */ 251 int pdmR3CritSectInitDeviceAuto(PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL, 252 const char *pszNameFmt, ...) 253 { 254 va_list va; 255 va_start(va, pszNameFmt); 256 int rc = pdmR3CritSectInitOne(pVM, &pCritSect->s, pDevIns, RT_SRC_POS_ARGS, pszNameFmt, va); 257 if (RT_SUCCESS(rc)) 258 pCritSect->s.fAutomaticDefaultCritsect = true; 259 va_end(va); 260 return rc; 238 261 } 239 262 -
trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp
r37452 r37466 1583 1583 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect)); 1584 1584 return pCritSect; 1585 } 1586 1587 1588 /** @interface_method_impl{PDMDEVHLPR3,pfnSetDeviceCritSect} */ 1589 static DECLCALLBACK(int) pdmR3DevHlp_SetDeviceCritSect(PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect) 1590 { 1591 /* 1592 * Validate input. 1593 * 1594 * Note! We only allow the automatically created default critical section 1595 * to be replaced by this API. 1596 */ 1597 PDMDEV_ASSERT_DEVINS(pDevIns); 1598 AssertPtrReturn(pCritSect, VERR_INVALID_POINTER); 1599 LogFlow(("pdmR3DevHlp_SetDeviceCritSect: caller='%s'/%d: pCritSect=%p (%s)\n", 1600 pDevIns->pReg->szName, pDevIns->iInstance, pCritSect, pCritSect->s.pszName)); 1601 AssertReturn(PDMCritSectIsInitialized(pCritSect), VERR_INVALID_PARAMETER); 1602 PVM pVM = pDevIns->Internal.s.pVMR3; 1603 AssertReturn(pCritSect->s.pVMR3 == pVM, VERR_INVALID_PARAMETER); 1604 1605 VM_ASSERT_EMT(pVM); 1606 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_CREATING, VERR_WRONG_ORDER); 1607 1608 AssertReturn(pDevIns->pCritSectRoR3, VERR_INTERNAL_ERROR_4); 1609 AssertReturn(pDevIns->pCritSectRoR3->s.fAutomaticDefaultCritsect, VERR_WRONG_ORDER); 1610 AssertReturn(!pDevIns->pCritSectRoR3->s.fUsedByTimerOrSimilar, VERR_WRONG_ORDER); 1611 AssertReturn(pDevIns->pCritSectRoR3 != pCritSect, VERR_INVALID_PARAMETER); 1612 1613 /* 1614 * Replace the critical section and destroy the automatic default section. 1615 */ 1616 PPDMCRITSECT pOldCritSect = pDevIns->pCritSectRoR3; 1617 pDevIns->pCritSectRoR3 = pCritSect; 1618 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0) 1619 pDevIns->pCritSectRoR0 = MMHyperCCToR0(pVM, pDevIns->pCritSectRoR3); 1620 else 1621 Assert(pDevIns->pCritSectRoR0 == NIL_RTRCPTR); 1622 1623 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC) 1624 pDevIns->pCritSectRoRC = MMHyperCCToRC(pVM, pDevIns->pCritSectRoR3); 1625 else 1626 Assert(pDevIns->pCritSectRoRC == NIL_RTRCPTR); 1627 1628 PDMR3CritSectDelete(pOldCritSect); 1629 if (pDevIns->pReg->fFlags & (PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0)) 1630 MMHyperFree(pVM, pOldCritSect); 1631 else 1632 MMR3HeapFree(pOldCritSect); 1633 1634 LogFlow(("pdmR3DevHlp_SetDeviceCritSect: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS)); 1635 return VINF_SUCCESS; 1585 1636 } 1586 1637 … … 3263 3314 pdmR3DevHlp_CritSectGetNopR0, 3264 3315 pdmR3DevHlp_CritSectGetNopRC, 3316 pdmR3DevHlp_SetDeviceCritSect, 3265 3317 pdmR3DevHlp_ThreadCreate, 3266 3318 pdmR3DevHlp_SetAsyncNotification, … … 3478 3530 pdmR3DevHlp_CritSectGetNopR0, 3479 3531 pdmR3DevHlp_CritSectGetNopRC, 3532 pdmR3DevHlp_SetDeviceCritSect, 3480 3533 pdmR3DevHlp_ThreadCreate, 3481 3534 pdmR3DevHlp_SetAsyncNotification, -
trunk/src/VBox/VMM/VMMR3/PDMDevice.cpp
r35810 r37466 288 288 289 289 /* 290 * Allocate the device instance .290 * Allocate the device instance and critical section. 291 291 */ 292 292 AssertReturn(paDevs[i].pDev->cInstances < paDevs[i].pDev->pReg->cMaxInstances, VERR_PDM_TOO_MANY_DEVICE_INSTANCES); … … 298 298 else 299 299 rc = MMR3HeapAllocZEx(pVM, MM_TAG_PDM_DEVICE, cb, (void **)&pDevIns); 300 if (RT_FAILURE(rc)) 301 { 302 AssertMsgFailed(("Failed to allocate %d bytes of instance data for device '%s'. rc=%Rrc\n", 303 cb, paDevs[i].pDev->pReg->szName, rc)); 304 return rc; 305 } 300 AssertLogRelMsgRCReturn(rc, 301 ("Failed to allocate %d bytes of instance data for device '%s'. rc=%Rrc\n", 302 cb, paDevs[i].pDev->pReg->szName, rc), 303 rc); 304 PPDMCRITSECT pCritSect; 305 if (paDevs[i].pDev->pReg->fFlags & (PDM_DEVREG_FLAGS_RC | PDM_DEVREG_FLAGS_R0)) 306 rc = MMHyperAlloc(pVM, sizeof(*pCritSect), 0, MM_TAG_PDM_DEVICE, (void **)&pCritSect); 307 else 308 rc = MMR3HeapAllocZEx(pVM, MM_TAG_PDM_DEVICE, sizeof(*pCritSect), (void **)&pCritSect); 309 AssertLogRelMsgRCReturn(rc, ("Failed to allocate a critical section for the device\n", rc), rc); 306 310 307 311 /* … … 335 339 pDevIns->pvInstanceDataR0 = pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0 336 340 ? MMHyperR3ToR0(pVM, pDevIns->pvInstanceDataR3) : NIL_RTR0PTR; 337 //pDevIns->pCritSectR3 = NULL; 338 //pDevIns->pCritSectR0 = NIL_RTR0PTR; 339 //pDevIns->pCritSectRC = NIL_RTRCPTR; 341 342 pDevIns->pCritSectRoR3 = pCritSect; 343 pDevIns->pCritSectRoRC = pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC 344 ? MMHyperR3ToRC(pVM, pCritSect) : NIL_RTRCPTR; 345 pDevIns->pCritSectRoR0 = pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0 346 ? MMHyperR3ToR0(pVM, pCritSect) : NIL_RTR0PTR; 347 348 rc = pdmR3CritSectInitDeviceAuto(pVM, pDevIns, pCritSect, RT_SRC_POS, 349 "%s#%u Auto", pDevIns->pReg->szName, pDevIns->iInstance); 350 AssertLogRelRCReturn(rc, rc); 340 351 341 352 /* … … 370 381 Log(("PDM: Constructing device '%s' instance %d...\n", pDevIns->pReg->szName, pDevIns->iInstance)); 371 382 rc = pDevIns->pReg->pfnConstruct(pDevIns, pDevIns->iInstance, pDevIns->pCfg); 372 if (RT_SUCCESS(rc))373 {374 /*375 * Per-device critsect fun.376 */377 if (pDevIns->pCritSectR3)378 {379 AssertStmt(PDMCritSectIsInitialized(pDevIns->pCritSectR3), rc = VERR_INTERNAL_ERROR_4);380 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_R0)381 {382 pDevIns->pCritSectR0 = MMHyperCCToR0(pVM, pDevIns->pCritSectR3);383 AssertStmt(pDevIns->pCritSectR0 != NIL_RTR0PTR, rc = VERR_INTERNAL_ERROR_3);384 }385 else386 AssertStmt(pDevIns->pCritSectR0 == NIL_RTRCPTR, rc = VERR_INTERNAL_ERROR_2);387 388 if (pDevIns->pReg->fFlags & PDM_DEVREG_FLAGS_RC)389 {390 pDevIns->pCritSectRC = MMHyperCCToRC(pVM, pDevIns->pCritSectR3);391 AssertStmt(pDevIns->pCritSectRC != NIL_RTRCPTR, rc = VERR_INTERNAL_ERROR_3);392 }393 else394 AssertStmt(pDevIns->pCritSectRC == NIL_RTRCPTR, rc = VERR_INTERNAL_ERROR_2);395 }396 else397 AssertStmt( pDevIns->pCritSectRC == NIL_RTRCPTR398 && pDevIns->pCritSectR0 == NIL_RTR0PTR,399 rc = VERR_INTERNAL_ERROR_5);400 }401 383 if (RT_FAILURE(rc)) 402 384 { 403 385 LogRel(("PDM: Failed to construct '%s'/%d! %Rra\n", pDevIns->pReg->szName, pDevIns->iInstance, rc)); 404 386 paDevs[i].pDev->cInstances--; 405 /* because we're damn lazy right now, we'll say that the destructor will be called even if the constructor fails. */ 387 /* Because we're damn lazy, the destructor will be called even if 388 the constructor fails. So, no unlinking. */ 406 389 return rc == VERR_VERSION_MISMATCH ? VERR_PDM_DEVICE_VERSION_MISMATCH : rc; 407 390 } … … 855 838 856 839 /** 840 * References the critical section associated with a device for the use by a 841 * timer or similar created by the device. 842 * 843 * @returns Pointer to the critical section. 844 * @param pVM The VM handle. 845 * @param pDevIns The device instance in question. 846 * 847 * @internal 848 */ 849 VMMR3_INT_DECL(PPDMCRITSECT) PDMR3DevGetCritSect(PVM pVM, PPDMDEVINS pDevIns) 850 { 851 VM_ASSERT_EMT(pVM); 852 VM_ASSERT_STATE(pVM, VMSTATE_CREATING); 853 AssertPtr(pDevIns); 854 855 PPDMCRITSECT pCritSect = pDevIns->pCritSectRoR3; 856 AssertPtr(pCritSect); 857 pCritSect->s.fUsedByTimerOrSimilar = true; 858 859 return pCritSect; 860 } 861 862 863 /** 857 864 * Attaches a preconfigured driver to an existing device or driver instance. 858 865 * -
trunk/src/VBox/VMM/VMMR3/TM.cpp
r37452 r37466 1332 1332 (*ppTimer)->pvUser = pvUser; 1333 1333 if (!(fFlags & TMTIMER_FLAGS_NO_CRIT_SECT)) 1334 { 1335 if (pDevIns->pCritSectR3) 1336 (*ppTimer)->pCritSect = pDevIns->pCritSectR3; 1337 else 1338 (*ppTimer)->pCritSect = IOMR3GetCritSect(pVM); 1339 } 1334 (*ppTimer)->pCritSect = PDMR3DevGetCritSect(pVM, pDevIns); 1340 1335 Log(("TM: Created device timer %p clock %d callback %p '%s'\n", (*ppTimer), enmClock, pfnCallback, pszDesc)); 1341 1336 } -
trunk/src/VBox/VMM/include/PDMInternal.h
r37443 r37466 268 268 /** Pointer to the VM - GCPtr. */ 269 269 PVMRC pVMRC; 270 /** Set if this critical section is the automatically created default 271 * section of a device.. */ 272 bool fAutomaticDefaultCritsect; 273 /** Set if the critical section is used by a timer or similar. 274 * See PDMR3DevGetCritSect. */ 275 bool fUsedByTimerOrSimilar; 270 276 /** Alignment padding. */ 271 uint32_t padding;277 bool afPadding[2]; 272 278 /** Event semaphore that is scheduled to be signaled upon leaving the 273 279 * critical section. This is Ring-3 only of course. */ … … 951 957 * the PIC, APIC, IOAPIC and PCI devices plus some PDM functions. */ 952 958 PDMCRITSECT CritSect; 953 954 /** The giant PDM device lock.955 * This is a temporary measure and will be removed. */956 PDMCRITSECT GiantDevCritSect;957 958 959 /** The NOP critical section. 959 960 * This is a dummy critical section that will not do any thread … … 1126 1127 void pdmR3CritSectRelocate(PVM pVM); 1127 1128 int pdmR3CritSectInitDevice(PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL, const char *pszNameFmt, va_list va); 1129 int pdmR3CritSectInitDeviceAuto(PVM pVM, PPDMDEVINS pDevIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL, 1130 const char *pszNameFmt, ...); 1128 1131 int pdmR3CritSectDeleteDevice(PVM pVM, PPDMDEVINS pDevIns); 1129 1132 int pdmR3CritSectInitDriver(PVM pVM, PPDMDRVINS pDrvIns, PPDMCRITSECT pCritSect, RT_SRC_POS_DECL, const char *pszNameFmt, ...); -
trunk/src/VBox/VMM/testcase/tstVMStructRC.cpp
r37452 r37466 291 291 GEN_CHECK_SIZE(PDM); 292 292 GEN_CHECK_OFF(PDM, CritSect); 293 GEN_CHECK_OFF(PDM, GiantDevCritSect);294 293 GEN_CHECK_OFF(PDM, NopCritSect); 295 294 GEN_CHECK_OFF(PDM, pDevs);
Note:
See TracChangeset
for help on using the changeset viewer.