Changeset 36257 in vbox
- Timestamp:
- Mar 11, 2011 9:37:58 AM (14 years ago)
- Location:
- trunk/src/VBox/HostDrivers/VBoxPci
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/HostDrivers/VBoxPci/VBoxPci.c
r36218 r36257 75 75 } 76 76 77 DECLINLINE(int) vboxPciDevLock(PVBOXRAWPCIINS pThis) 78 { 79 int rc = RTSemFastMutexRequest(pThis->hFastMtx); 80 AssertRC(rc); 81 return rc; 82 } 83 84 DECLINLINE(void) vboxPciDevUnlock(PVBOXRAWPCIINS pThis) 85 { 86 RTSemFastMutexRelease(pThis->hFastMtx); 87 } 88 89 DECLINLINE(int) vboxPciGlobalsLock(PVBOXRAWPCIGLOBALS pGlobals) 90 { 91 int rc = RTSemFastMutexRequest(pGlobals->hFastMtx); 92 AssertRC(rc); 93 return rc; 94 } 95 96 DECLINLINE(void) vboxPciGlobalsUnlock(PVBOXRAWPCIGLOBALS pGlobals) 97 { 98 RTSemFastMutexRelease(pGlobals->hFastMtx); 99 } 100 101 static PVBOXRAWPCIINS vboxPciFindInstanceLocked(PVBOXRAWPCIGLOBALS pGlobals, uint32_t iHostAddress) 102 { 103 PVBOXRAWPCIINS pCur; 104 for (pCur = pGlobals->pInstanceHead; pCur != NULL; pCur = pCur->pNext) 105 { 106 if (iHostAddress == pCur->HostPciAddress) 107 return pCur; 108 } 109 return NULL; 110 } 111 112 static void vboxPciUnlinkInstanceLocked(PVBOXRAWPCIGLOBALS pGlobals, PVBOXRAWPCIINS pToUnlink) 113 { 114 if (pGlobals->pInstanceHead == pToUnlink) 115 pGlobals->pInstanceHead = pToUnlink->pNext; 116 else 117 { 118 PVBOXRAWPCIINS pCur; 119 for (pCur = pGlobals->pInstanceHead; pCur != NULL; pCur = pCur->pNext) 120 { 121 if (pCur->pNext == pToUnlink) 122 { 123 pCur->pNext = pToUnlink->pNext; 124 break; 125 } 126 } 127 } 128 pToUnlink->pNext = NULL; 129 } 130 131 77 132 /** 78 133 * @copydoc RAWPCIDEVPORT:: pfnRetain … … 80 135 DECLHIDDEN(void) vboxPciDevRetain(PRAWPCIDEVPORT pPort) 81 136 { 137 PVBOXRAWPCIINS pThis = DEVPORT_2_VBOXRAWPCIINS(pPort); 82 138 } 83 139 … … 87 143 DECLHIDDEN(void) vboxPciDevRelease(PRAWPCIDEVPORT pPort) 88 144 { 145 PVBOXRAWPCIINS pThis = DEVPORT_2_VBOXRAWPCIINS(pPort); 146 147 if (pThis->hFastMtx) 148 { 149 RTSemFastMutexDestroy(pThis->hFastMtx); 150 pThis->hFastMtx = NIL_RTSEMFASTMUTEX; 151 } 152 153 if (pThis->hSpinlock) 154 { 155 RTSpinlockDestroy(pThis->hSpinlock); 156 pThis->hSpinlock = NIL_RTSPINLOCK; 157 } 158 159 vboxPciGlobalsLock(pThis->pGlobals); 160 vboxPciUnlinkInstanceLocked(pThis->pGlobals, pThis); 161 vboxPciGlobalsUnlock(pThis->pGlobals); 89 162 } 90 163 … … 95 168 { 96 169 PVBOXRAWPCIINS pThis = DEVPORT_2_VBOXRAWPCIINS(pPort); 97 98 int rc = vboxPciOsDevInit(pThis, fFlags); 170 int rc; 171 172 vboxPciDevLock(pThis); 173 174 rc = vboxPciOsDevInit(pThis, fFlags); 175 176 vboxPciDevUnlock(pThis); 99 177 100 178 return rc; … … 107 185 { 108 186 PVBOXRAWPCIINS pThis = DEVPORT_2_VBOXRAWPCIINS(pPort); 109 110 int rc = vboxPciOsDevDeinit(pThis, fFlags); 187 int rc; 188 189 vboxPciDevLock(pThis); 190 191 rc = vboxPciOsDevDeinit(pThis, fFlags); 192 193 vboxPciDevUnlock(pThis); 111 194 112 195 return rc; … … 124 207 { 125 208 PVBOXRAWPCIINS pThis = DEVPORT_2_VBOXRAWPCIINS(pPort); 126 127 int rc = vboxPciOsDevGetRegionInfo(pThis, iRegion, 128 pRegionStart, pu64RegionSize, 129 pfPresent, pfFlags); 209 int rc; 210 211 vboxPciDevLock(pThis); 212 213 rc = vboxPciOsDevGetRegionInfo(pThis, iRegion, 214 pRegionStart, pu64RegionSize, 215 pfPresent, pfFlags); 216 vboxPciDevUnlock(pThis); 130 217 131 218 return rc; … … 143 230 { 144 231 PVBOXRAWPCIINS pThis = DEVPORT_2_VBOXRAWPCIINS(pPort); 145 146 int rc = vboxPciOsDevMapRegion(pThis, iRegion, RegionStart, u64RegionSize, fFlags, pRegionBase); 232 int rc; 233 234 vboxPciDevLock(pThis); 235 236 rc = vboxPciOsDevMapRegion(pThis, iRegion, RegionStart, u64RegionSize, fFlags, pRegionBase); 237 238 vboxPciDevUnlock(pThis); 147 239 148 240 return rc; … … 159 251 { 160 252 PVBOXRAWPCIINS pThis = DEVPORT_2_VBOXRAWPCIINS(pPort); 161 162 int rc = vboxPciOsDevUnmapRegion(pThis, iRegion, RegionStart, u64RegionSize, RegionBase); 253 int rc; 254 255 vboxPciDevLock(pThis); 256 257 rc = vboxPciOsDevUnmapRegion(pThis, iRegion, RegionStart, u64RegionSize, RegionBase); 258 259 vboxPciDevUnlock(pThis); 163 260 164 261 return rc; … … 174 271 int rc; 175 272 273 vboxPciDevLock(pThis); 274 176 275 rc = vboxPciOsDevPciCfgRead(pThis, Register, pValue); 177 276 277 vboxPciDevUnlock(pThis); 278 178 279 return rc; 179 280 } … … 185 286 { 186 287 PVBOXRAWPCIINS pThis = DEVPORT_2_VBOXRAWPCIINS(pPort); 187 188 int rc = vboxPciOsDevPciCfgWrite(pThis, Register, pValue); 288 int rc; 289 290 vboxPciDevLock(pThis); 291 292 rc = vboxPciOsDevPciCfgWrite(pThis, Register, pValue); 293 294 vboxPciDevUnlock(pThis); 189 295 190 296 return rc; … … 195 301 PVBOXRAWPCIINS pThis = DEVPORT_2_VBOXRAWPCIINS(pPort); 196 302 int rc; 303 304 vboxPciDevLock(pThis); 197 305 198 306 pThis->pfnIrqHandler = pfnHandler; … … 206 314 } 207 315 316 vboxPciDevUnlock(pThis); 317 208 318 return rc; 209 319 } … … 212 322 { 213 323 PVBOXRAWPCIINS pThis = DEVPORT_2_VBOXRAWPCIINS(pPort); 214 215 int rc = vboxPciOsDevUnregisterIrqHandler(pThis, iHostIrq); 324 int rc; 325 326 vboxPciDevLock(pThis); 327 rc = vboxPciOsDevUnregisterIrqHandler(pThis, iHostIrq); 328 if (RT_SUCCESS(rc)) 329 { 330 pThis->pfnIrqHandler = NULL; 331 pThis->pIrqContext = NULL; 332 } 333 vboxPciDevUnlock(pThis); 216 334 217 335 return rc; … … 263 381 if (RT_SUCCESS(rc)) 264 382 { 265 rc = pNew->DevPort.pfnInit(&pNew->DevPort, fFlags);383 rc = RTSemFastMutexCreate(&pNew->hFastMtx); 266 384 if (RT_SUCCESS(rc)) 267 385 { 268 *ppDevPort = &pNew->DevPort; 386 rc = pNew->DevPort.pfnInit(&pNew->DevPort, fFlags); 387 if (RT_SUCCESS(rc)) 388 { 389 *ppDevPort = &pNew->DevPort; 390 391 pNew->pNext = pGlobals->pInstanceHead; 392 pGlobals->pInstanceHead = pNew; 393 394 } 395 else 396 { 397 RTSemFastMutexDestroy(pNew->hFastMtx); 398 RTSpinlockDestroy(pNew->hSpinlock); 399 RTMemFree(pNew); 400 } 401 return rc; 269 402 } 270 else271 {272 RTSpinlockDestroy(pNew->hSpinlock);273 RTMemFree(pNew);274 }275 return rc;276 403 } 277 404 … … 292 419 LogFlow(("vboxPciFactoryCreateAndConnect: PCI=%x fFlags=%#x\n", u32HostAddress, fFlags)); 293 420 Assert(pGlobals->cFactoryRefs > 0); 294 rc = RTSemFastMutexRequest(pGlobals->hFastMtx);421 rc = vboxPciGlobalsLock(pGlobals); 295 422 AssertRCReturn(rc, rc); 296 423 424 /* First search if there's no existing instance with same host device 425 * address - if so - we cannot continue. 426 */ 427 if (vboxPciFindInstanceLocked(pGlobals, u32HostAddress) != NULL) 428 { 429 rc = VERR_RESOURCE_BUSY; 430 goto unlock; 431 } 432 297 433 rc = vboxPciNewInstance(pGlobals, u32HostAddress, fFlags, ppDevPort); 298 434 299 RTSemFastMutexRelease(pGlobals->hFastMtx); 435 unlock: 436 vboxPciGlobalsUnlock(pGlobals); 300 437 301 438 return rc; … … 316 453 static DECLHIDDEN(bool) vboxPciCanUnload(PVBOXRAWPCIGLOBALS pGlobals) 317 454 { 318 int rc = RTSemFastMutexRequest(pGlobals->hFastMtx);455 int rc = vboxPciGlobalsLock(pGlobals); 319 456 bool fRc = !pGlobals->pInstanceHead 320 457 && pGlobals->cFactoryRefs <= 0; 321 RTSemFastMutexRelease(pGlobals->hFastMtx);458 vboxPciGlobalsUnlock(pGlobals); 322 459 AssertRC(rc); 323 460 return fRc; -
trunk/src/VBox/HostDrivers/VBoxPci/VBoxPciInternal.h
r36253 r36257 27 27 28 28 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 31) 29 #define VBOX_WITH_IOMMU 29 # ifdef DEBUG_nike 30 # define VBOX_WITH_IOMMU 31 # endif 30 32 #endif 31 33 … … 55 57 /** Pointer to the globals. */ 56 58 PVBOXRAWPCIGLOBALS pGlobals; 57 /** The spinlock protecting the state variables and host interface handle. */ 59 60 /** Mutex protecting device access. */ 61 RTSEMFASTMUTEX hFastMtx; 62 /** The spinlock protecting the state variables and device access. */ 58 63 RTSPINLOCK hSpinlock; 59 64 /** Pointer to the next device in the list. */ … … 68 73 struct pci_dev * pPciDev; 69 74 #endif 75 bool fMsiUsed; 76 bool fMsixUsed; 77 bool fIommuUsed; 78 bool fPad0; 70 79 71 80 /** The session this interface is associated with. */ … … 77 86 RAWPCIDEVPORT DevPort; 78 87 88 uint32_t cHandlersCount; 79 89 PFNRAWPCIISR pfnIrqHandler; 80 90 void *pIrqContext;
Note:
See TracChangeset
for help on using the changeset viewer.