Changeset 106022 in vbox for trunk/src/VBox
- Timestamp:
- Sep 12, 2024 9:44:36 AM (3 months ago)
- Location:
- trunk/src/VBox/VMM
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/VMM/VMMR3/PDM.cpp
r105068 r106022 462 462 pUVM->pdm.s.pCritSects = NULL; 463 463 pUVM->pdm.s.pRwCritSects = NULL; 464 return RTCritSectInit (&pUVM->pdm.s.ListCritSect);464 return RTCritSectInitNamed(&pUVM->pdm.s.ListCritSect, "PDM-ListCritSect"); 465 465 } 466 466 … … 502 502 pVM->pdm.s.NopCritSect.s.Core.fFlags |= RTCRITSECT_FLAGS_NOP; 503 503 } 504 if (RT_SUCCESS(rc)) 505 rc = RTCritSectRwInitNamed(&pVM->pdm.s.CoreListCritSectRw, "PDM-CoreListCritSectRw"); 504 506 505 507 /* … … 614 616 pVM->pdm.s.IoApic.pfnSetIrqRC += offDelta; 615 617 if (pVM->pdm.s.IoApic.pfnSendMsiRC) 616 pVM->pdm.s.IoApic.pfnSendMsiRC 618 pVM->pdm.s.IoApic.pfnSendMsiRC += offDelta; 617 619 if (pVM->pdm.s.IoApic.pfnSetEoiRC) 618 pVM->pdm.s.IoApic.pfnSetEoiRC 620 pVM->pdm.s.IoApic.pfnSetEoiRC += offDelta; 619 621 } 620 622 … … 637 639 } 638 640 641 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 639 642 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) 640 643 { … … 690 693 691 694 } 695 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 696 692 697 #endif /* VBOX_WITH_RAW_MODE_KEEP */ 693 698 } … … 696 701 /** 697 702 * Worker for pdmR3Term that terminates a LUN chain. 703 * 704 * @note Caller owns CoreListCritSectRw in exclusive mode. 705 * Will temporarily leave and retake the lock when calling destructors. 698 706 * 699 707 * @param pVM The cross context VM structure. … … 722 730 LogFlow(("pdmR3DevTerm: Destroying - driver '%s'/%d on LUN#%d of device '%s'/%d\n", 723 731 pDrvIns->pReg->szName, pDrvIns->iInstance, pLun->iLun, pszDevice, iInstance)); 732 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 724 733 pDrvIns->pReg->pfnDestruct(pDrvIns); 734 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 725 735 } 726 736 pDrvIns->Internal.s.pDrv->cInstances--; … … 769 779 * from any MM heap since MM will do that in its Term function. 770 780 */ 781 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 782 771 783 /* usb ones first. */ 772 784 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext) … … 781 793 if (pHub) 782 794 { 795 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 783 796 int rc = pHub->Reg.pfnDetachDevice(pHub->pDrvIns, pUsbIns, pUsbIns->Internal.s.iPort); 784 if (RT_FAILURE(rc)) 785 { 786 LogRel(("PDM: Failed to detach USB device '%s' instance %d from %p: %Rrc\n", 787 pUsbIns->pReg->szName, pUsbIns->iInstance, pHub, rc)); 788 } 789 else 797 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 798 if (RT_SUCCESS(rc)) 790 799 { 791 800 pHub->cAvailablePorts++; … … 793 802 pUsbIns->Internal.s.pHub = NULL; 794 803 } 795 } 804 else 805 LogRel(("PDM: Failed to detach USB device '%s' instance %d from %p: %Rrc\n", 806 pUsbIns->pReg->szName, pUsbIns->iInstance, pHub, rc)); 807 } 808 809 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 796 810 797 811 if (pUsbIns->pReg->pfnDestruct) 798 812 { 799 LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n", 800 pUsbIns->pReg->szName, pUsbIns->iInstance)); 813 LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n", pUsbIns->pReg->szName, pUsbIns->iInstance)); 801 814 pUsbIns->pReg->pfnDestruct(pUsbIns); 802 815 } … … 811 824 pUsbIns->pszName = NULL; 812 825 } 826 827 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 813 828 } 814 829 … … 821 836 { 822 837 LogFlow(("pdmR3DevTerm: Destroying - device '%s'/%d\n", pDevIns->pReg->szName, pDevIns->iInstance)); 838 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 823 839 pDevIns->pReg->pfnDestruct(pDevIns); 840 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 824 841 } 825 842 … … 851 868 } 852 869 #endif 870 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 853 871 854 872 TMR3TimerDestroyDevice(pVM, pDevIns); … … 864 882 #endif 865 883 DBGFR3InfoDeregisterDevice(pVM, pDevIns, NULL); 866 } 884 885 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 886 } 887 888 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 867 889 868 890 /* … … 909 931 PDMR3CritSectDelete(pVM, &pVM->pdm.s.CritSect); 910 932 /* The MiscCritSect is deleted by PDMR3CritSectBothTerm later. */ 933 934 if (RTCritSectRwIsInitialized(&pVM->pdm.s.CoreListCritSectRw)) 935 RTCritSectRwDelete(&pVM->pdm.s.CoreListCritSectRw); 911 936 912 937 LogFlow(("PDMR3Term: returns %Rrc\n", VINF_SUCCESS)); … … 1216 1241 * Load the list of devices and verify that they are all there. 1217 1242 */ 1243 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1218 1244 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) 1219 1245 pDevIns->Internal.s.fIntFlags &= ~PDMDEVINSINT_FLAGS_FOUND; 1246 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1220 1247 1221 1248 for (uint32_t i = 0; ; i++) … … 1242 1269 1243 1270 /* Try locate it. */ 1271 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1244 1272 PPDMDEVINS pDevIns; 1245 1273 for (pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) … … 1247 1275 && pDevIns->iInstance == iInstance) 1248 1276 { 1249 AssertLogRelMsgReturn(!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_FOUND), 1250 ("%s/#%u\n", pDevIns->pReg->szName, pDevIns->iInstance), 1251 VERR_SSM_DATA_UNIT_FORMAT_CHANGED); 1277 AssertLogRelMsgReturnStmt(!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_FOUND), 1278 ("%s/#%u\n", pDevIns->pReg->szName, pDevIns->iInstance), 1279 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw), 1280 VERR_SSM_DATA_UNIT_FORMAT_CHANGED); 1252 1281 pDevIns->Internal.s.fIntFlags |= PDMDEVINSINT_FLAGS_FOUND; 1253 1282 break; 1254 1283 } 1284 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1255 1285 1256 1286 if (!pDevIns) … … 1275 1305 * Check that no additional devices were configured. 1276 1306 */ 1307 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 1277 1308 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) 1278 1309 if (!(pDevIns->Internal.s.fIntFlags & PDMDEVINSINT_FLAGS_FOUND)) … … 1285 1316 */ 1286 1317 if ( SSMR3HandleGetAfter(pSSM) != SSMAFTER_DEBUG_IT 1287 && RTStrCmp(pDevIns->pReg->szName, "tpm-ppi")) 1318 && RTStrCmp(pDevIns->pReg->szName, "tpm-ppi") /* !!HACK ALERT!! - ugly, see todo above */) 1319 { 1320 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1288 1321 return SSMR3SetCfgError(pSSM, RT_SRC_POS, N_("Device '%s'/%d not found in the saved state"), 1289 1322 pDevIns->pReg->szName, pDevIns->iInstance); 1290 } 1291 1323 } 1324 } 1325 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1292 1326 1293 1327 /* … … 1393 1427 * processing the drivers associated with those. 1394 1428 */ 1429 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1430 /** @todo locking */ 1431 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1395 1432 int rc = VINF_SUCCESS; 1396 1433 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns && RT_SUCCESS(rc); pDevIns = pDevIns->Internal.s.pNextR3) … … 1718 1755 * Clear all the reset flags. 1719 1756 */ 1757 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1720 1758 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) 1721 1759 { … … 1734 1772 } 1735 1773 #endif 1774 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1736 1775 1737 1776 /* … … 1748 1787 * processing the drivers associated with those. 1749 1788 */ 1789 /** @todo locking */ 1750 1790 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) 1751 1791 { … … 2080 2120 * taking any. (DrvVD changes to read-only in this particular case.) 2081 2121 */ 2122 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 2123 /** @todo locking */ 2124 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 2082 2125 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) 2083 2126 { … … 2223 2266 * processing the drivers associated with those. 2224 2267 */ 2268 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 2269 /** @todo locking */ 2270 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 2225 2271 int rc = VINF_SUCCESS; 2226 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns && RT_SUCCESS(rc);pDevIns = pDevIns->Internal.s.pNextR3)2227 { 2228 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun && RT_SUCCESS(rc); pLun= pLun->pNext)2229 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc);pDrvIns = pDrvIns->Internal.s.pDown)2272 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns && RT_SUCCESS(rc); pDevIns = pDevIns->Internal.s.pNextR3) 2273 { 2274 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun && RT_SUCCESS(rc); pLun = pLun->pNext) 2275 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown) 2230 2276 rc = pdmR3ResumeDrv(pDrvIns, pDevIns->pReg->szName, pDevIns->iInstance, pLun->iLun); 2231 2277 if (RT_SUCCESS(rc)) … … 2234 2280 2235 2281 #ifdef VBOX_WITH_USB 2236 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns && RT_SUCCESS(rc);pUsbIns = pUsbIns->Internal.s.pNext)2237 { 2238 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun && RT_SUCCESS(rc);pLun = pLun->pNext)2239 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc);pDrvIns = pDrvIns->Internal.s.pDown)2282 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns && RT_SUCCESS(rc); pUsbIns = pUsbIns->Internal.s.pNext) 2283 { 2284 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun && RT_SUCCESS(rc); pLun = pLun->pNext) 2285 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns && RT_SUCCESS(rc); pDrvIns = pDrvIns->Internal.s.pDown) 2240 2286 rc = pdmR3ResumeDrv(pDrvIns, pUsbIns->pReg->szName, pUsbIns->iInstance, pLun->iLun); 2241 2287 if (RT_SUCCESS(rc)) … … 2426 2472 * be called in any case. 2427 2473 */ 2474 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 2428 2475 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) 2429 2476 { … … 2445 2492 } 2446 2493 #endif 2494 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 2447 2495 2448 2496 /* … … 2464 2512 * taking any. (DrvVD changes to read-only in this particular case.) 2465 2513 */ 2514 /** @todo locking */ 2466 2515 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) 2467 2516 { … … 2530 2579 LogFlow(("PDMR3DeviceQuery: pszDevice=%p:{%s} iInstance=%u ppBase=%p\n", pszDevice, pszDevice, iInstance, ppBase)); 2531 2580 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE); 2532 VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE); 2581 PVM const pVM = pUVM->pVM; 2582 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 2533 2583 2534 2584 /* 2535 2585 * Iterate registered devices looking for the device. 2536 2586 */ 2537 size_t cchDevice = strlen(pszDevice); 2538 for (PPDMDEV pDev = pUVM->pVM->pdm.s.pDevs; pDev; pDev = pDev->pNext) 2587 size_t const cchDevice = strlen(pszDevice); 2588 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 2589 for (PPDMDEV pDev = pVM->pdm.s.pDevs; pDev; pDev = pDev->pNext) 2539 2590 { 2540 2591 if ( pDev->cchName == cchDevice … … 2551 2602 { 2552 2603 *ppBase = &pDevIns->IBase; 2604 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2553 2605 LogFlow(("PDMR3DeviceQuery: return VINF_SUCCESS and *ppBase=%p\n", *ppBase)); 2554 2606 return VINF_SUCCESS; 2555 2607 } 2556 2608 2609 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2557 2610 LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NO_IBASE\n")); 2558 2611 return VERR_PDM_DEVICE_INSTANCE_NO_IBASE; … … 2560 2613 } 2561 2614 2615 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2562 2616 LogFlow(("PDMR3DeviceQuery: returns VERR_PDM_DEVICE_INSTANCE_NOT_FOUND\n")); 2563 2617 return VERR_PDM_DEVICE_INSTANCE_NOT_FOUND; … … 2565 2619 } 2566 2620 2621 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2567 2622 LogFlow(("PDMR3QueryDevice: returns VERR_PDM_DEVICE_NOT_FOUND\n")); 2568 2623 return VERR_PDM_DEVICE_NOT_FOUND; … … 2631 2686 * Find the LUN. 2632 2687 */ 2688 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 2633 2689 PPDMLUN pLun; 2634 2690 int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun); … … 2638 2694 { 2639 2695 *ppBase = &pLun->pTop->IBase; 2696 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2640 2697 LogFlow(("PDMR3QueryLun: return %Rrc and *ppBase=%p\n", VINF_SUCCESS, *ppBase)); 2641 2698 return VINF_SUCCESS; … … 2643 2700 rc = VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN; 2644 2701 } 2702 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2645 2703 LogFlow(("PDMR3QueryLun: returns %Rrc\n", rc)); 2646 2704 return rc; … … 2669 2727 LogFlow(("PDMR3QueryDriverOnLun: pszDevice=%p:{%s} iInstance=%u iLun=%u pszDriver=%p:{%s} ppBase=%p\n", 2670 2728 pszDevice, pszDevice, iInstance, iLun, pszDriver, pszDriver, ppBase)); 2729 *ppBase = NULL; 2671 2730 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE); 2672 VM_ASSERT_VALID_EXT_RETURN(pUVM->pVM, VERR_INVALID_VM_HANDLE); 2731 PVM const pVM = pUVM->pVM; 2732 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 2673 2733 2674 2734 /* 2675 2735 * Find the LUN. 2676 2736 */ 2737 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 2677 2738 PPDMLUN pLun; 2678 int rc = pdmR3DevFindLun(p UVM->pVM, pszDevice, iInstance, iLun, &pLun);2739 int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun); 2679 2740 if (RT_SUCCESS(rc)) 2680 2741 { … … 2685 2746 { 2686 2747 *ppBase = &pDrvIns->IBase; 2748 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2687 2749 LogFlow(("PDMR3QueryDriverOnLun: return %Rrc and *ppBase=%p\n", VINF_SUCCESS, *ppBase)); 2688 2750 return VINF_SUCCESS; 2689 2690 2751 } 2691 2752 rc = VERR_PDM_DRIVER_NOT_FOUND; … … 2694 2755 rc = VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN; 2695 2756 } 2757 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2696 2758 LogFlow(("PDMR3QueryDriverOnLun: returns %Rrc\n", rc)); 2697 2759 return rc; 2698 2760 } 2699 2761 2762 2700 2763 /** 2701 2764 * Executes pending DMA transfers. … … 2706 2769 VMMR3DECL(void) PDMR3DmaRun(PVM pVM) 2707 2770 { 2771 /** @todo this is bad in SMP... */ 2708 2772 /* Note! Not really SMP safe; restrict it to VCPU 0. */ 2709 2773 if (VMMGetCpuId(pVM) != 0) … … 2712 2776 if (VM_FF_TEST_AND_CLEAR(pVM, VM_FF_PDM_DMA)) 2713 2777 { 2714 if (pVM->pdm.s.pDmac) 2715 { 2716 bool fMore = pVM->pdm.s.pDmac->Reg.pfnRun(pVM->pdm.s.pDmac->pDevIns); 2778 PPDMDMAC const pDmac = pVM->pdm.s.pDmac; 2779 if (pDmac) 2780 { 2781 bool const fMore = pDmac->Reg.pfnRun(pDmac->pDevIns); 2717 2782 if (fMore) 2718 2783 VM_FF_SET(pVM, VM_FF_PDM_DMA); … … 2793 2858 { 2794 2859 AssertReturn(fApply, VINF_SUCCESS); 2860 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 2795 2861 2796 2862 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) … … 2812 2878 } 2813 2879 #endif 2880 2881 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 2814 2882 return VINF_SUCCESS; 2815 2883 } … … 2825 2893 if (!strncmp("dev", pszName, 3)) 2826 2894 { 2895 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); /* Shared-mode is sufficient for this. */ 2827 2896 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) 2828 2897 { … … 2842 2911 else if (!strncmp("usb", pszName, 3)) 2843 2912 { 2913 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); /* Shared-mode is sufficient for this. */ 2844 2914 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext) 2845 2915 { … … 2860 2930 { 2861 2931 AssertReturn(fApply, VINF_SUCCESS); 2932 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); /* Shared-mode is sufficient for this. */ 2862 2933 2863 2934 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) … … 2896 2967 } 2897 2968 #endif 2969 2898 2970 } 2899 2971 else 2900 2972 return VERR_NOT_FOUND; 2901 2973 2974 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2902 2975 return cMatches > 0 ? VINF_SUCCESS : VERR_NOT_FOUND; 2903 2976 } … … 2914 2987 VMMR3_INT_DECL(bool) PDMR3TracingAreAll(PVM pVM, bool fEnabled) 2915 2988 { 2989 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 2990 2916 2991 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) 2917 2992 { 2918 2993 if (pDevIns->fTracing != (uint32_t)fEnabled) 2994 { 2995 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2919 2996 return false; 2997 } 2920 2998 2921 2999 for (PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; pLun; pLun = pLun->pNext) 2922 3000 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown) 2923 3001 if (pDrvIns->fTracing != (uint32_t)fEnabled) 3002 { 3003 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2924 3004 return false; 3005 } 2925 3006 } 2926 3007 … … 2929 3010 { 2930 3011 if (pUsbIns->fTracing != (uint32_t)fEnabled) 3012 { 3013 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2931 3014 return false; 3015 } 2932 3016 2933 3017 for (PPDMLUN pLun = pUsbIns->Internal.s.pLuns; pLun; pLun = pLun->pNext) 2934 3018 for (PPDMDRVINS pDrvIns = pLun->pTop; pDrvIns; pDrvIns = pDrvIns->Internal.s.pDown) 2935 3019 if (pDrvIns->fTracing != (uint32_t)fEnabled) 3020 { 3021 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2936 3022 return false; 3023 } 2937 3024 } 2938 3025 #endif 2939 3026 3027 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 2940 3028 return true; 2941 3029 } … … 2991 3079 VMMR3_INT_DECL(int) PDMR3TracingQueryConfig(PVM pVM, char *pszConfig, size_t cbConfig) 2992 3080 { 2993 int rc;2994 3081 char *pszDst = pszConfig; 2995 3082 size_t cbDst = cbConfig; 2996 3083 3084 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 3085 2997 3086 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) 2998 3087 { 2999 3088 if (pDevIns->fTracing) 3000 3089 { 3001 rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "dev", pDevIns->Internal.s.pDevR3->pReg->szName);3090 int rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "dev", pDevIns->Internal.s.pDevR3->pReg->szName); 3002 3091 if (RT_FAILURE(rc)) 3092 { 3093 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 3003 3094 return rc; 3095 } 3004 3096 } 3005 3097 … … 3008 3100 if (pDrvIns->fTracing) 3009 3101 { 3010 rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "drv", pDrvIns->Internal.s.pDrv->pReg->szName);3102 int rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "drv", pDrvIns->Internal.s.pDrv->pReg->szName); 3011 3103 if (RT_FAILURE(rc)) 3104 { 3105 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 3012 3106 return rc; 3107 } 3013 3108 } 3014 3109 } … … 3019 3114 if (pUsbIns->fTracing) 3020 3115 { 3021 rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "usb", pUsbIns->Internal.s.pUsbDev->pReg->szName);3116 int rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "usb", pUsbIns->Internal.s.pUsbDev->pReg->szName); 3022 3117 if (RT_FAILURE(rc)) 3118 { 3119 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 3023 3120 return rc; 3121 } 3024 3122 } 3025 3123 … … 3028 3126 if (pDrvIns->fTracing) 3029 3127 { 3030 rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "drv", pDrvIns->Internal.s.pDrv->pReg->szName);3128 int rc = pdmR3TracingAdd(&pszDst, &cbDst, pszDst != pszConfig, "drv", pDrvIns->Internal.s.pDrv->pReg->szName); 3031 3129 if (RT_FAILURE(rc)) 3130 { 3131 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 3032 3132 return rc; 3133 } 3033 3134 } 3034 3135 } 3035 3136 #endif 3036 3137 3138 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 3037 3139 return VINF_SUCCESS; 3038 3140 } -
trunk/src/VBox/VMM/VMMR3/PDMDevHlp.cpp
r105352 r106022 181 181 182 182 /** @interface_method_impl{PDMDEVHLPR3,pfnMmioCreateEx} */ 183 static DECLCALLBACK(int) pdmR3DevHlp_MmioCreateEx(PPDMDEVINS pDevIns, RTGCPHYS cbRegion, 184 uint32_t fFlags, PPDMPCIDEV pPciDev, uint32_t iPciRegion,185 PFNIOMMMIONEW WRITE pfnWrite, PFNIOMMMIONEWREAD pfnRead, PFNIOMMMIONEWFILL pfnFill,183 static DECLCALLBACK(int) pdmR3DevHlp_MmioCreateEx(PPDMDEVINS pDevIns, RTGCPHYS cbRegion, uint32_t fFlags, 184 PPDMPCIDEV pPciDev, uint32_t iPciRegion, PFNIOMMMIONEWWRITE pfnWrite, 185 PFNIOMMMIONEWREAD pfnRead, PFNIOMMMIONEWFILL pfnFill, 186 186 void *pvUser, const char *pszDesc, PIOMMMIOHANDLE phRegion) 187 187 { … … 2599 2599 { 2600 2600 PDMDEV_ASSERT_DEVINS(pDevIns); 2601 PVM pVM = pDevIns->Internal.s.pVMR3;2601 PVM const pVM = pDevIns->Internal.s.pVMR3; 2602 2602 VM_ASSERT_EMT(pVM); 2603 2603 LogFlow(("pdmR3DevHlp_DriverAttach: caller='%s'/%d: iLun=%d pBaseInterface=%p ppBaseInterface=%p pszDesc=%p:{%s}\n", … … 2607 2607 * Lookup the LUN, it might already be registered. 2608 2608 */ 2609 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 2610 2609 2611 PPDMLUN pLunPrev = NULL; 2610 2612 PPDMLUN pLun = pDevIns->Internal.s.pLunsR3; … … 2618 2620 if (!pLun) 2619 2621 { 2620 if ( 2621 || 2622 || 2622 if ( !pBaseInterface 2623 || !pszDesc 2624 || !*pszDesc) 2623 2625 { 2626 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 2624 2627 Assert(pBaseInterface); 2625 2628 Assert(pszDesc || *pszDesc); … … 2629 2632 pLun = (PPDMLUN)MMR3HeapAlloc(pVM, MM_TAG_PDM_LUN, sizeof(*pLun)); 2630 2633 if (!pLun) 2634 { 2635 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 2631 2636 return VERR_NO_MEMORY; 2637 } 2632 2638 2633 2639 pLun->iLun = iLun; … … 2648 2654 else if (pLun->pTop) 2649 2655 { 2656 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 2650 2657 AssertMsgFailed(("Already attached! The device should keep track of such things!\n")); 2651 2658 LogFlow(("pdmR3DevHlp_DriverAttach: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VERR_PDM_DRIVER_ALREADY_ATTACHED)); … … 2659 2666 */ 2660 2667 int rc; 2661 PCFGMNODE pNode = CFGMR3GetChildF(pDevIns->Internal.s.pCfgHandle, "LUN#%u", iLun);2668 PCFGMNODE const pNode = CFGMR3GetChildF(pDevIns->Internal.s.pCfgHandle, "LUN#%u", iLun); 2662 2669 if (pNode) 2663 2670 rc = pdmR3DrvInstantiate(pVM, pNode, pBaseInterface, NULL /*pDrvAbove*/, pLun, ppBaseInterface); … … 2665 2672 rc = VERR_PDM_NO_ATTACHED_DRIVER; 2666 2673 2674 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 2675 2667 2676 LogFlow(("pdmR3DevHlp_DriverAttach: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc)); 2668 2677 return rc; … … 2677 2686 pDevIns->pReg->szName, pDevIns->iInstance, pDrvIns)); 2678 2687 2679 #ifdef VBOX_STRICT 2680 PVM pVM = pDevIns->Internal.s.pVMR3; 2688 PVM const pVM = pDevIns->Internal.s.pVMR3; 2681 2689 VM_ASSERT_EMT(pVM); 2682 #endif 2683 2684 int rc = pdmR3DrvDetach(pDrvIns, fFlags); 2690 2691 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 2692 int rc = pdmR3DrvDetach(pVM, pDrvIns, fFlags); 2693 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 2685 2694 2686 2695 LogFlow(("pdmR3DevHlp_DriverDetach: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc)); … … 2694 2703 { 2695 2704 PDMDEV_ASSERT_DEVINS(pDevIns); 2696 PVM pVM = pDevIns->Internal.s.pVMR3;2705 PVM const pVM = pDevIns->Internal.s.pVMR3; 2697 2706 VM_ASSERT_EMT(pVM); 2698 2707 LogFlow(("pdmR3DevHlp_DriverReconfigure: caller='%s'/%d: iLun=%u cDepth=%u fFlags=%#x\n", … … 2715 2724 } 2716 2725 AssertReturn(fFlags == 0, VERR_INVALID_FLAGS); 2726 2727 /* 2728 * Exclusively lock the core stuff (mind, pdmR3DrvDetach will leave + reenter). 2729 */ 2730 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 2717 2731 2718 2732 /* … … 2724 2738 if (pLun->pTop) 2725 2739 { 2726 int rc = pdmR3DrvDetach(p Lun->pTop, 0);2727 AssertRCReturn (rc, rc);2740 int rc = pdmR3DrvDetach(pVM, pLun->pTop, 0); 2741 AssertRCReturnStmt(rc, RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw), rc); 2728 2742 } 2729 2743 break; … … 2767 2781 } 2768 2782 2783 /* Keep the lock till the end to serialize the CFGM changes. */ 2784 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 2769 2785 LogFlow(("pdmR3DevHlp_DriverReconfigure: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, rc)); 2770 2786 return rc; … … 3513 3529 * Only one DMA device. 3514 3530 */ 3515 PVM pVM = pDevIns->Internal.s.pVMR3; 3516 if (pVM->pdm.s.pRtc) 3531 PVM const pVM = pDevIns->Internal.s.pVMR3; 3532 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 3533 3534 int rc = VINF_SUCCESS; 3535 if (!pVM->pdm.s.pRtc) 3536 { 3537 /* 3538 * Allocate and initialize pci bus structure. 3539 */ 3540 PPDMRTC pRtc = (PPDMRTC)MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE, sizeof(*pRtc)); 3541 if (pRtc) 3542 { 3543 pRtc->pDevIns = pDevIns; 3544 pRtc->Reg = *pRtcReg; 3545 pVM->pdm.s.pRtc = pRtc; 3546 3547 /* set the helper pointer. */ 3548 *ppRtcHlp = &g_pdmR3DevRtcHlp; 3549 Log(("PDM: Registered RTC device '%s'/%d pDevIns=%p\n", 3550 pDevIns->pReg->szName, pDevIns->iInstance, pDevIns)); 3551 } 3552 else 3553 rc = VERR_NO_MEMORY; 3554 } 3555 else 3517 3556 { 3518 3557 AssertMsgFailed(("Only one RTC device is supported!\n")); 3519 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc\n", 3520 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER)); 3521 return VERR_INVALID_PARAMETER; 3522 } 3523 3524 /* 3525 * Allocate and initialize pci bus structure. 3526 */ 3527 int rc = VINF_SUCCESS; 3528 PPDMRTC pRtc = (PPDMRTC)MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE, sizeof(*pRtc)); 3529 if (pRtc) 3530 { 3531 pRtc->pDevIns = pDevIns; 3532 pRtc->Reg = *pRtcReg; 3533 pVM->pdm.s.pRtc = pRtc; 3534 3535 /* set the helper pointer. */ 3536 *ppRtcHlp = &g_pdmR3DevRtcHlp; 3537 Log(("PDM: Registered RTC device '%s'/%d pDevIns=%p\n", 3538 pDevIns->pReg->szName, pDevIns->iInstance, pDevIns)); 3539 } 3540 else 3541 rc = VERR_NO_MEMORY; 3542 3558 rc = VERR_ALREADY_EXISTS; 3559 } 3560 3561 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 3543 3562 LogFlow(("pdmR3DevHlp_RTCRegister: caller='%s'/%d: returns %Rrc\n", 3544 3563 pDevIns->pReg->szName, pDevIns->iInstance, rc)); … … 3555 3574 LogFlow(("pdmR3DevHlp_DMARegister: caller='%s'/%d: uChannel=%d pfnTransferHandler=%p pvUser=%p\n", 3556 3575 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, pfnTransferHandler, pvUser)); 3557 int rc = VINF_SUCCESS; 3558 if (pVM->pdm.s.pDmac) 3559 pVM->pdm.s.pDmac->Reg.pfnRegister(pVM->pdm.s.pDmac->pDevIns, uChannel, pDevIns, pfnTransferHandler, pvUser); 3576 int rc = VINF_SUCCESS; 3577 PPDMDMAC const pDmac = pVM->pdm.s.pDmac; 3578 if (pDmac) 3579 pDmac->Reg.pfnRegister(pDmac->pDevIns, uChannel, pDevIns, pfnTransferHandler, pvUser); 3560 3580 else 3561 3581 { … … 3577 3597 LogFlow(("pdmR3DevHlp_DMAReadMemory: caller='%s'/%d: uChannel=%d pvBuffer=%p off=%#x cbBlock=%#x pcbRead=%p\n", 3578 3598 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, pvBuffer, off, cbBlock, pcbRead)); 3579 int rc = VINF_SUCCESS; 3580 if (pVM->pdm.s.pDmac) 3581 { 3582 uint32_t cb = pVM->pdm.s.pDmac->Reg.pfnReadMemory(pVM->pdm.s.pDmac->pDevIns, uChannel, pvBuffer, off, cbBlock); 3599 int rc = VINF_SUCCESS; 3600 PPDMDMAC const pDmac = pVM->pdm.s.pDmac; 3601 if (pDmac) 3602 { 3603 uint32_t cb = pDmac->Reg.pfnReadMemory(pDmac->pDevIns, uChannel, pvBuffer, off, cbBlock); 3583 3604 if (pcbRead) 3584 3605 *pcbRead = cb; … … 3603 3624 LogFlow(("pdmR3DevHlp_DMAWriteMemory: caller='%s'/%d: uChannel=%d pvBuffer=%p off=%#x cbBlock=%#x pcbWritten=%p\n", 3604 3625 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, pvBuffer, off, cbBlock, pcbWritten)); 3605 int rc = VINF_SUCCESS; 3606 if (pVM->pdm.s.pDmac) 3607 { 3608 uint32_t cb = pVM->pdm.s.pDmac->Reg.pfnWriteMemory(pVM->pdm.s.pDmac->pDevIns, uChannel, pvBuffer, off, cbBlock); 3626 int rc = VINF_SUCCESS; 3627 PPDMDMAC const pDmac = pVM->pdm.s.pDmac; 3628 if (pDmac) 3629 { 3630 uint32_t cb = pDmac->Reg.pfnWriteMemory(pDmac->pDevIns, uChannel, pvBuffer, off, cbBlock); 3609 3631 if (pcbWritten) 3610 3632 *pcbWritten = cb; … … 3629 3651 LogFlow(("pdmR3DevHlp_DMASetDREQ: caller='%s'/%d: uChannel=%d uLevel=%d\n", 3630 3652 pDevIns->pReg->szName, pDevIns->iInstance, uChannel, uLevel)); 3631 int rc = VINF_SUCCESS; 3632 if (pVM->pdm.s.pDmac) 3633 pVM->pdm.s.pDmac->Reg.pfnSetDREQ(pVM->pdm.s.pDmac->pDevIns, uChannel, uLevel); 3653 int rc = VINF_SUCCESS; 3654 PPDMDMAC const pDmac = pVM->pdm.s.pDmac; 3655 if (pDmac) 3656 pDmac->Reg.pfnSetDREQ(pDmac->pDevIns, uChannel, uLevel); 3634 3657 else 3635 3658 { … … 3650 3673 LogFlow(("pdmR3DevHlp_DMAGetChannelMode: caller='%s'/%d: uChannel=%d\n", 3651 3674 pDevIns->pReg->szName, pDevIns->iInstance, uChannel)); 3652 uint8_t u8Mode; 3653 if (pVM->pdm.s.pDmac) 3654 u8Mode = pVM->pdm.s.pDmac->Reg.pfnGetChannelMode(pVM->pdm.s.pDmac->pDevIns, uChannel); 3675 uint8_t u8Mode; 3676 PPDMDMAC const pDmac = pVM->pdm.s.pDmac; 3677 if (pDmac) 3678 u8Mode = pDmac->Reg.pfnGetChannelMode(pDmac->pDevIns, uChannel); 3655 3679 else 3656 3680 { … … 3688 3712 pDevIns->pReg->szName, pDevIns->iInstance, iReg, u8Value)); 3689 3713 int rc; 3690 if (pVM->pdm.s.pRtc) 3691 { 3692 PPDMDEVINS pDevInsRtc = pVM->pdm.s.pRtc->pDevIns; 3714 PPDMRTC const pRtc = pVM->pdm.s.pRtc; 3715 if (pRtc) 3716 { 3717 PPDMDEVINS const pDevInsRtc = pRtc->pDevIns; 3693 3718 rc = PDMCritSectEnter(pVM, pDevInsRtc->pCritSectRoR3, VERR_IGNORED); 3694 3719 if (RT_SUCCESS(rc)) 3695 3720 { 3696 rc = p VM->pdm.s.pRtc->Reg.pfnWrite(pDevInsRtc, iReg, u8Value);3721 rc = pRtc->Reg.pfnWrite(pDevInsRtc, iReg, u8Value); 3697 3722 PDMCritSectLeave(pVM, pDevInsRtc->pCritSectRoR3); 3698 3723 } … … 3717 3742 pDevIns->pReg->szName, pDevIns->iInstance, iReg, pu8Value)); 3718 3743 int rc; 3719 if (pVM->pdm.s.pRtc) 3720 { 3721 PPDMDEVINS pDevInsRtc = pVM->pdm.s.pRtc->pDevIns; 3744 PPDMRTC const pRtc = pVM->pdm.s.pRtc; 3745 if (pRtc) 3746 { 3747 PPDMDEVINS const pDevInsRtc = pRtc->pDevIns; 3722 3748 rc = PDMCritSectEnter(pVM, pDevInsRtc->pCritSectRoR3, VERR_IGNORED); 3723 3749 if (RT_SUCCESS(rc)) 3724 3750 { 3725 rc = p VM->pdm.s.pRtc->Reg.pfnRead(pDevInsRtc, iReg, pu8Value);3751 rc = pRtc->Reg.pfnRead(pDevInsRtc, iReg, pu8Value); 3726 3752 PDMCritSectLeave(pVM, pDevInsRtc->pCritSectRoR3); 3727 3753 } … … 3979 4005 VM_ASSERT_STATE_RETURN(pVM, VMSTATE_CREATING, VERR_WRONG_ORDER); 3980 4006 4007 /* Take the core lock exclusively just to be safe. */ 4008 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 4009 3981 4010 /* 3982 4011 * Find free PCI bus entry. … … 3986 4015 if (!pVM->pdm.s.aPciBuses[iBus].pDevInsR3) 3987 4016 break; 3988 AssertLogRelMsgReturn(iBus < RT_ELEMENTS(pVM->pdm.s.aPciBuses), 3989 ("Too many PCI buses. Max=%u\n", RT_ELEMENTS(pVM->pdm.s.aPciBuses)), 3990 VERR_OUT_OF_RESOURCES); 4017 AssertLogRelMsgReturnStmt(iBus < RT_ELEMENTS(pVM->pdm.s.aPciBuses), 4018 ("Too many PCI buses. Max=%u\n", RT_ELEMENTS(pVM->pdm.s.aPciBuses)), 4019 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw), 4020 VERR_OUT_OF_RESOURCES); 3991 4021 PPDMPCIBUS pPciBus = &pVM->pdm.s.aPciBuses[iBus]; 3992 4022 … … 4005 4035 4006 4036 Log(("PDM: Registered PCI bus device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns)); 4037 4038 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 4007 4039 4008 4040 /* set the helper pointer and return. */ … … 4042 4074 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT); 4043 4075 4076 /* Take the core lock exclusively just to be safe. */ 4077 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 4078 4044 4079 /* 4045 4080 * Find free IOMMU slot. … … 4051 4086 if (!pVM->pdm.s.aIommus[idxIommu].pDevInsR3) 4052 4087 break; 4053 AssertLogRelMsgReturn(idxIommu < RT_ELEMENTS(pVM->pdm.s.aIommus), 4054 ("Too many IOMMUs. Max=%u\n", RT_ELEMENTS(pVM->pdm.s.aIommus)), 4055 VERR_OUT_OF_RESOURCES); 4088 AssertLogRelMsgReturnStmt(idxIommu < RT_ELEMENTS(pVM->pdm.s.aIommus), 4089 ("Too many IOMMUs. Max=%u\n", RT_ELEMENTS(pVM->pdm.s.aIommus)), 4090 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw), 4091 VERR_OUT_OF_RESOURCES); 4056 4092 #else 4057 4093 /* Currently we support only a single IOMMU. */ 4058 AssertMsgReturn(!pVM->pdm.s.aIommus[0].pDevInsR3, 4059 ("%s/%u: Only one IOMMU device is supported!\n", pDevIns->pReg->szName, pDevIns->iInstance), 4060 VERR_ALREADY_EXISTS); 4094 AssertMsgReturnStmt(!pVM->pdm.s.aIommus[idxIommu].pDevInsR3, 4095 ("%s/%u: Only one IOMMU device is supported!\n", pDevIns->pReg->szName, pDevIns->iInstance), 4096 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw), 4097 VERR_ALREADY_EXISTS); 4061 4098 #endif 4062 4099 PPDMIOMMUR3 pIommu = &pVM->pdm.s.aIommus[idxIommu]; … … 4071 4108 pIommu->pfnMsiRemap = pIommuReg->pfnMsiRemap; 4072 4109 Log(("PDM: Registered IOMMU device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns)); 4110 4111 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 4073 4112 4074 4113 /* Set the helper pointer and return. */ … … 4107 4146 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT); 4108 4147 4148 /* Take the core lock exclusively just to be safe. */ 4149 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 4150 4109 4151 /* 4110 4152 * Only one PIC device. 4111 4153 */ 4112 AssertMsgReturn(pVM->pdm.s.Pic.pDevInsR3 == NULL, ("%s/%d: Only one PIC!\n", pDevIns->pReg->szName, pDevIns->iInstance), 4113 VERR_ALREADY_EXISTS); 4154 AssertMsgReturnStmt(pVM->pdm.s.Pic.pDevInsR3 == NULL, 4155 ("%s/%d: Only one PIC!\n", pDevIns->pReg->szName, pDevIns->iInstance), 4156 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw), 4157 VERR_ALREADY_EXISTS); 4114 4158 4115 4159 /* … … 4121 4165 Log(("PDM: Registered PIC device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns)); 4122 4166 4167 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 4168 4123 4169 /* set the helper pointer and return. */ 4124 4170 *ppPicHlp = &g_pdmR3DevPicHlp; … … 4140 4186 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT); 4141 4187 4188 /* Take the core lock exclusively just to be safe. */ 4189 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 4190 4142 4191 /* 4143 4192 * Only one APIC device. On SMP we have single logical device covering all LAPICs, 4144 4193 * as they need to communicate and share state easily. 4145 4194 */ 4146 AssertMsgReturn(pVM->pdm.s.Apic.pDevInsR3 == NULL, 4147 ("%s/%u: Only one APIC device is supported!\n", pDevIns->pReg->szName, pDevIns->iInstance), 4148 VERR_ALREADY_EXISTS); 4195 AssertMsgReturnStmt(pVM->pdm.s.Apic.pDevInsR3 == NULL, 4196 ("%s/%u: Only one APIC device is supported!\n", pDevIns->pReg->szName, pDevIns->iInstance), 4197 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw), 4198 VERR_ALREADY_EXISTS); 4149 4199 4150 4200 /* … … 4156 4206 Assert(pVM->pdm.s.Apic.pDevInsRC || !VM_IS_RAW_MODE_ENABLED(pVM)); 4157 4207 #endif 4208 4209 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 4158 4210 4159 4211 LogFlow(("pdmR3DevHlp_ApicRegister: caller='%s'/%d: returns %Rrc\n", pDevIns->pReg->szName, pDevIns->iInstance, VINF_SUCCESS)); … … 4186 4238 VM_ASSERT_EMT0_RETURN(pVM, VERR_VM_THREAD_NOT_EMT); 4187 4239 4240 /* Take the core lock exclusively just to be safe. */ 4241 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 4242 4188 4243 /* 4189 4244 * The I/O APIC requires the APIC to be present (hacks++). 4190 4245 * If the I/O APIC does GC stuff so must the APIC. 4191 4246 */ 4192 AssertMsgReturn(pVM->pdm.s.Apic.pDevInsR3 != NULL, ("Configuration error / Init order error! No APIC!\n"), VERR_WRONG_ORDER); 4247 AssertMsgReturnStmt(pVM->pdm.s.Apic.pDevInsR3 != NULL, 4248 ("Configuration error / Init order error! No APIC!\n"), 4249 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw), 4250 VERR_WRONG_ORDER); 4193 4251 4194 4252 /* 4195 4253 * Only one I/O APIC device. 4196 4254 */ 4197 AssertMsgReturn(pVM->pdm.s.IoApic.pDevInsR3 == NULL, 4198 ("Only one IOAPIC device is supported! (caller %s/%d)\n", pDevIns->pReg->szName, pDevIns->iInstance), 4199 VERR_ALREADY_EXISTS); 4255 AssertMsgReturnStmt(pVM->pdm.s.IoApic.pDevInsR3 == NULL, 4256 ("Only one IOAPIC device is supported! (caller %s/%d)\n", pDevIns->pReg->szName, pDevIns->iInstance), 4257 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw), 4258 VERR_ALREADY_EXISTS); 4200 4259 4201 4260 /* … … 4207 4266 pVM->pdm.s.IoApic.pfnSetEoiR3 = pIoApicReg->pfnSetEoi; 4208 4267 Log(("PDM: Registered I/O APIC device '%s'/%d pDevIns=%p\n", pDevIns->pReg->szName, pDevIns->iInstance, pDevIns)); 4268 4269 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 4209 4270 4210 4271 /* set the helper pointer and return. */ … … 4235 4296 * Only one HPET device. 4236 4297 */ 4237 AssertMsgReturn(pVM->pdm.s.pHpet == NULL, 4238 ("Only one HPET device is supported! (caller %s/%d)\n", pDevIns->pReg->szName, pDevIns->iInstance), 4239 VERR_ALREADY_EXISTS); 4298 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 4299 4300 AssertMsgReturnStmt(pVM->pdm.s.pHpet == NULL, 4301 ("Only one HPET device is supported! (caller %s/%d)\n", pDevIns->pReg->szName, pDevIns->iInstance), 4302 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw), 4303 VERR_ALREADY_EXISTS); 4240 4304 4241 4305 /* … … 4243 4307 */ 4244 4308 pVM->pdm.s.pHpet = pDevIns; 4309 4310 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 4311 4245 4312 *ppHpetHlpR3 = &g_pdmR3DevHpetHlp; 4246 4313 … … 4330 4397 * Only one DMA device. 4331 4398 */ 4332 PVM pVM = pDevIns->Internal.s.pVMR3; 4333 if (pVM->pdm.s.pDmac) 4399 PVM const pVM = pDevIns->Internal.s.pVMR3; 4400 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 4401 4402 int rc = VINF_SUCCESS; 4403 if (!pVM->pdm.s.pDmac) 4404 { 4405 4406 /* 4407 * Allocate and initialize pci bus structure. 4408 */ 4409 PPDMDMAC pDmac = (PPDMDMAC)MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE, sizeof(*pDmac)); 4410 if (pDmac) 4411 { 4412 pDmac->pDevIns = pDevIns; 4413 pDmac->Reg = *pDmacReg; 4414 pVM->pdm.s.pDmac = pDmac; 4415 4416 /* set the helper pointer. */ 4417 *ppDmacHlp = &g_pdmR3DevDmacHlp; 4418 Log(("PDM: Registered DMAC device '%s'/%d pDevIns=%p\n", 4419 pDevIns->pReg->szName, pDevIns->iInstance, pDevIns)); 4420 } 4421 else 4422 rc = VERR_NO_MEMORY; 4423 } 4424 else 4334 4425 { 4335 4426 AssertMsgFailed(("Only one DMA device is supported!\n")); 4336 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc\n", 4337 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER)); 4338 return VERR_INVALID_PARAMETER; 4339 } 4340 4341 /* 4342 * Allocate and initialize pci bus structure. 4343 */ 4344 int rc = VINF_SUCCESS; 4345 PPDMDMAC pDmac = (PPDMDMAC)MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE, sizeof(*pDmac)); 4346 if (pDmac) 4347 { 4348 pDmac->pDevIns = pDevIns; 4349 pDmac->Reg = *pDmacReg; 4350 pVM->pdm.s.pDmac = pDmac; 4351 4352 /* set the helper pointer. */ 4353 *ppDmacHlp = &g_pdmR3DevDmacHlp; 4354 Log(("PDM: Registered DMAC device '%s'/%d pDevIns=%p\n", 4355 pDevIns->pReg->szName, pDevIns->iInstance, pDevIns)); 4356 } 4357 else 4358 rc = VERR_NO_MEMORY; 4359 4427 rc = VERR_ALREADY_EXISTS; 4428 } 4429 4430 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 4360 4431 LogFlow(("pdmR3DevHlp_DMACRegister: caller='%s'/%d: returns %Rrc\n", 4361 4432 pDevIns->pReg->szName, pDevIns->iInstance, rc)); … … 4375 4446 pDevIns->pReg->szName, pDevIns->iInstance, GCPhys, pvHeap, cbHeap)); 4376 4447 4448 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 4377 4449 if (pVM->pdm.s.pvVMMDevHeap == NULL) 4378 4450 { … … 4390 4462 { 4391 4463 pVM->pdm.s.GCPhysVMMDevHeap = GCPhys; 4392 if (pVM->pdm.s.pfnVMMDevHeapNotify) 4393 pVM->pdm.s.pfnVMMDevHeapNotify(pVM, pvHeap, GCPhys); 4464 PFNPDMVMMDEVHEAPNOTIFY const pfnVMMDevHeapNotify = pVM->pdm.s.pfnVMMDevHeapNotify; 4465 if (pfnVMMDevHeapNotify) 4466 pfnVMMDevHeapNotify(pVM, pvHeap, GCPhys); 4394 4467 } 4395 4468 } 4469 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 4396 4470 4397 4471 LogFlow(("pdmR3DevHlp_RegisterVMMDevHeap: caller='%s'/%d: returns %Rrc\n", … … 4438 4512 4439 4513 /* 4440 * Only one DMA device.4514 * Only one firmware registration. 4441 4515 */ 4442 PVM pVM = pDevIns->Internal.s.pVMR3; 4443 if (pVM->pdm.s.pFirmware) 4516 PVM const pVM = pDevIns->Internal.s.pVMR3; 4517 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 4518 4519 int rc = VINF_SUCCESS; 4520 if (!pVM->pdm.s.pFirmware) 4521 { 4522 /* 4523 * Allocate and initialize pci bus structure. 4524 */ 4525 PPDMFW pFirmware = (PPDMFW)MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE, sizeof(*pFirmware)); 4526 if (pFirmware) 4527 { 4528 pFirmware->pDevIns = pDevIns; 4529 pFirmware->Reg = *pFwReg; 4530 pVM->pdm.s.pFirmware = pFirmware; 4531 4532 /* set the helper pointer. */ 4533 *ppFwHlp = &g_pdmR3DevFirmwareHlp; 4534 Log(("PDM: Registered firmware device '%s'/%d pDevIns=%p\n", 4535 pDevIns->pReg->szName, pDevIns->iInstance, pDevIns)); 4536 } 4537 else 4538 rc = VERR_NO_MEMORY; 4539 } 4540 else 4444 4541 { 4445 4542 AssertMsgFailed(("Only one firmware device is supported!\n")); 4446 LogFlow(("pdmR3DevHlp_FirmwareRegister: caller='%s'/%d: returns %Rrc\n", 4447 pDevIns->pReg->szName, pDevIns->iInstance, VERR_INVALID_PARAMETER)); 4448 return VERR_INVALID_PARAMETER; 4449 } 4450 4451 /* 4452 * Allocate and initialize pci bus structure. 4453 */ 4454 int rc = VINF_SUCCESS; 4455 PPDMFW pFirmware = (PPDMFW)MMR3HeapAlloc(pDevIns->Internal.s.pVMR3, MM_TAG_PDM_DEVICE, sizeof(*pFirmware)); 4456 if (pFirmware) 4457 { 4458 pFirmware->pDevIns = pDevIns; 4459 pFirmware->Reg = *pFwReg; 4460 pVM->pdm.s.pFirmware = pFirmware; 4461 4462 /* set the helper pointer. */ 4463 *ppFwHlp = &g_pdmR3DevFirmwareHlp; 4464 Log(("PDM: Registered firmware device '%s'/%d pDevIns=%p\n", 4465 pDevIns->pReg->szName, pDevIns->iInstance, pDevIns)); 4466 } 4467 else 4468 rc = VERR_NO_MEMORY; 4469 4543 rc = VERR_ALREADY_EXISTS; 4544 } 4545 4546 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 4470 4547 LogFlow(("pdmR3DevHlp_FirmwareRegister: caller='%s'/%d: returns %Rrc\n", 4471 4548 pDevIns->pReg->szName, pDevIns->iInstance, rc)); … … 4805 4882 /** @interface_method_impl{PDMDEVHLPR3,pfnQueryLun} */ 4806 4883 static DECLCALLBACK(int) pdmR3DevHlp_QueryLun(PPDMDEVINS pDevIns, const char *pszDevice, 4807 4884 unsigned iInstance, unsigned iLun, PPDMIBASE *ppBase) 4808 4885 { 4809 4886 PDMDEV_ASSERT_DEVINS(pDevIns); -
trunk/src/VBox/VMM/VMMR3/PDMDevice.cpp
r105687 r106022 501 501 * Link it into all the lists. 502 502 */ 503 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 504 503 505 /* The global instance FIFO. */ 504 506 PPDMDEVINS pPrev1 = pVM->pdm.s.pDevInstances; … … 536 538 VMSetError(pVM, rc, RT_SRC_POS, "Failed to construct device '%s' instance #%u", 537 539 pDevIns->pReg->szName, pDevIns->iInstance); 538 paDevs[i].pDev->cInstances--;540 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 539 541 return VERR_NO_MEMORY; 540 542 } … … 550 552 */ 551 553 paDevs[i].pDev->cInstances++; 554 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 555 552 556 Log(("PDM: Constructing device '%s' instance %d...\n", pDevIns->pReg->szName, pDevIns->iInstance)); 553 557 rc = pDevIns->pReg->pfnConstruct(pDevIns, pDevIns->iInstance, pDevIns->pCfg); … … 560 564 /* Because we're damn lazy, the destructor will be called even if 561 565 the constructor fails. So, no unlinking. */ 562 paDevs[i].pDev->cInstances--;566 //paDevs[i].pDev->cInstances--; 563 567 return rc == VERR_VERSION_MISMATCH ? VERR_PDM_DEVICE_VERSION_MISMATCH : rc; 564 568 } … … 584 588 VMSetError(pVM, rc, RT_SRC_POS, "The ring-0 constructor of device '%s' instance #%u failed", 585 589 pDevIns->pReg->szName, pDevIns->iInstance); 586 paDevs[i].pDev->cInstances--; 590 /* No unlinking, see above. */ 591 //paDevs[i].pDev->cInstances--; 587 592 return rc == VERR_VERSION_MISMATCH ? VERR_PDM_DEVICE_VERSION_MISMATCH : rc; 588 593 } … … 617 622 * Iterate thru the device instances and work the callback. 618 623 */ 624 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 619 625 for (PPDMDEVINS pDevIns = pVM->pdm.s.pDevInstances; pDevIns; pDevIns = pDevIns->Internal.s.pNextR3) 620 626 { 621 627 if (pDevIns->pReg->pfnInitComplete) 622 628 { 629 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 623 630 PDMCritSectEnter(pVM, pDevIns->pCritSectRoR3, VERR_IGNORED); 624 631 rc = pDevIns->pReg->pfnInitComplete(pDevIns); … … 630 637 return rc; 631 638 } 639 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 632 640 } 633 641 } 642 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 634 643 635 644 #ifdef VBOX_WITH_USB … … 653 662 PPDMDEV pdmR3DevLookup(PVM pVM, const char *pszName) 654 663 { 655 size_t cchName = strlen(pszName); 664 size_t const cchName = strlen(pszName); 665 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 656 666 for (PPDMDEV pDev = pVM->pdm.s.pDevs; pDev; pDev = pDev->pNext) 657 if ( pDev->cchName == cchName 658 && !strcmp(pDev->pReg->szName, pszName)) 667 if ( pDev->cchName == cchName 668 && !strcmp(pDev->pReg->szName, pszName)) 669 { 670 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 659 671 return pDev; 672 } 673 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 660 674 return NULL; 661 675 } … … 916 930 */ 917 931 PCPDMDEVREGCBINT pRegCB = (PCPDMDEVREGCBINT)pCallbacks; 932 PVM const pVM = pRegCB->pVM; 933 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 934 918 935 PPDMDEV pDevPrev = NULL; 919 PPDMDEV pDev = pRegCB->pVM->pdm.s.pDevs;936 PPDMDEV pDev = pVM->pdm.s.pDevs; 920 937 for (; pDev; pDevPrev = pDev, pDev = pDev->pNext) 921 AssertMsgReturn(strcmp(pDev->pReg->szName, pReg->szName), 922 ("Device '%s' already exists\n", pReg->szName), 923 VERR_PDM_DEVICE_NAME_CLASH); 938 AssertMsgReturnStmt(strcmp(pDev->pReg->szName, pReg->szName), 939 ("Device '%s' already exists\n", pReg->szName), 940 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw), 941 VERR_PDM_DEVICE_NAME_CLASH); 924 942 925 943 /* … … 944 962 else 945 963 pRegCB->pVM->pdm.s.pDevs = pDev; 964 965 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 946 966 Log(("PDM: Registered device '%s'\n", pReg->szName)); 947 967 return VINF_SUCCESS; … … 952 972 else 953 973 rc = VERR_NO_MEMORY; 974 975 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 954 976 return rc; 955 977 } … … 972 994 * Iterate registered devices looking for the device. 973 995 */ 974 size_t cchDevice = strlen(pszDevice); 996 size_t const cchDevice = strlen(pszDevice); 997 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 975 998 for (PPDMDEV pDev = pVM->pdm.s.pDevs; pDev; pDev = pDev->pNext) 976 999 { … … 992 1015 if (pLun->iLun == iLun) 993 1016 { 1017 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 994 1018 *ppLun = pLun; 995 1019 return VINF_SUCCESS; 996 1020 } 997 1021 } 1022 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 998 1023 return VERR_PDM_LUN_NOT_FOUND; 999 1024 } 1000 1025 } 1026 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1001 1027 return VERR_PDM_DEVICE_INSTANCE_NOT_FOUND; 1002 1028 } 1003 1029 } 1030 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1004 1031 return VERR_PDM_DEVICE_NOT_FOUND; 1005 1032 } … … 1020 1047 * @thread EMT 1021 1048 */ 1022 VMMR3DECL(int) PDMR3DeviceAttach(PUVM pUVM, const char *pszDevice, unsigned iInstance, unsigned iLun, uint32_t fFlags, PPPDMIBASE ppBase) 1049 VMMR3DECL(int) PDMR3DeviceAttach(PUVM pUVM, const char *pszDevice, unsigned iInstance, unsigned iLun, 1050 uint32_t fFlags, PPPDMIBASE ppBase) 1023 1051 { 1052 if (ppBase) 1053 *ppBase = NULL; 1024 1054 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE); 1025 1055 PVM pVM = pUVM->pVM; … … 1032 1062 * Find the LUN in question. 1033 1063 */ 1064 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 1034 1065 PPDMLUN pLun; 1035 1066 int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun); … … 1044 1075 if (!pLun->pTop) 1045 1076 { 1077 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1046 1078 PDMCritSectEnter(pVM, pDevIns->pCritSectRoR3, VERR_IGNORED); 1047 1079 rc = pDevIns->pReg->pfnAttach(pDevIns, iLun, fFlags); 1048 1080 PDMCritSectLeave(pVM, pDevIns->pCritSectRoR3); 1081 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 1049 1082 } 1050 1083 else … … 1057 1090 *ppBase = pLun->pTop ? &pLun->pTop->IBase : NULL; 1058 1091 } 1059 else if (ppBase) 1060 *ppBase = NULL; 1092 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1061 1093 1062 1094 if (ppBase) … … 1128 1160 * @thread EMT 1129 1161 */ 1130 VMMR3DECL(int) PDMR3DriverAttach(PUVM pUVM, const char *pszDevice, unsigned iInstance, unsigned iLun, uint32_t fFlags, PPPDMIBASE ppBase) 1162 VMMR3DECL(int) PDMR3DriverAttach(PUVM pUVM, const char *pszDevice, unsigned iInstance, unsigned iLun, 1163 uint32_t fFlags, PPPDMIBASE ppBase) 1131 1164 { 1132 1165 LogFlow(("PDMR3DriverAttach: pszDevice=%p:{%s} iInstance=%d iLun=%d fFlags=%#x ppBase=%p\n", 1133 1166 pszDevice, pszDevice, iInstance, iLun, fFlags, ppBase)); 1167 if (ppBase) 1168 *ppBase = NULL; 1134 1169 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE); 1135 1170 PVM pVM = pUVM->pVM; … … 1137 1172 VM_ASSERT_EMT(pVM); 1138 1173 1139 if (ppBase)1140 *ppBase = NULL;1141 1142 1174 /* 1143 1175 * Find the LUN in question. 1144 1176 */ 1177 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 1145 1178 PPDMLUN pLun; 1146 1179 int rc = pdmR3DevFindLun(pVM, pszDevice, iInstance, iLun, &pLun); … … 1157 1190 if (pDevIns->pReg->pfnAttach) 1158 1191 { 1192 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1159 1193 PDMCritSectEnter(pVM, pDevIns->pCritSectRoR3, VERR_IGNORED); 1160 1194 rc = pDevIns->pReg->pfnAttach(pDevIns, iLun, fFlags); … … 1162 1196 *ppBase = pLun->pTop ? &pLun->pTop->IBase : NULL; 1163 1197 PDMCritSectLeave(pVM, pDevIns->pCritSectRoR3); 1198 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 1164 1199 } 1165 1200 else … … 1173 1208 if (pDrvIns->pReg->pfnAttach) 1174 1209 { 1210 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1175 1211 rc = pDrvIns->pReg->pfnAttach(pDrvIns, fFlags); 1212 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 1176 1213 if (RT_SUCCESS(rc) && ppBase) 1177 1214 *ppBase = pDrvIns->Internal.s.pDown … … 1183 1220 } 1184 1221 } 1222 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1185 1223 1186 1224 if (ppBase) … … 1221 1259 pszDevice, pszDevice, iDevIns, iLun, pszDriver, pszDriver, iOccurrence, fFlags)); 1222 1260 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE); 1223 PVM pVM = pUVM->pVM;1261 PVM const pVM = pUVM->pVM; 1224 1262 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 1225 1263 VM_ASSERT_EMT(pVM); … … 1232 1270 * Find the LUN in question. 1233 1271 */ 1272 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1234 1273 PPDMLUN pLun; 1235 1274 int rc = pdmR3DevFindLun(pVM, pszDevice, iDevIns, iLun, &pLun); … … 1256 1295 } 1257 1296 if (pDrvIns) 1258 rc = pdmR3DrvDetach(p DrvIns, fFlags);1297 rc = pdmR3DrvDetach(pVM, pDrvIns, fFlags); 1259 1298 else 1260 1299 rc = VERR_PDM_DRIVER_INSTANCE_NOT_FOUND; … … 1263 1302 rc = VINF_PDM_NO_DRIVER_ATTACHED_TO_LUN; 1264 1303 } 1304 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1265 1305 1266 1306 LogFlow(("PDMR3DriverDetach: returns %Rrc\n", rc)); -
trunk/src/VBox/VMM/VMMR3/PDMDriver.cpp
r98103 r106022 327 327 * Check for duplicate and find FIFO entry at the same time. 328 328 */ 329 PCPDMDRVREGCBINT pRegCB = (PCPDMDRVREGCBINT)pCallbacks; 329 PCPDMDRVREGCBINT const pRegCB = (PCPDMDRVREGCBINT)pCallbacks; 330 PVM const pVM = pRegCB->pVM; 331 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 332 330 333 PPDMDRV pDrvPrev = NULL; 331 334 PPDMDRV pDrv = pRegCB->pVM->pdm.s.pDrvs; … … 334 337 if (!strcmp(pDrv->pReg->szName, pReg->szName)) 335 338 { 339 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 336 340 AssertMsgFailed(("Driver '%s' already exists\n", pReg->szName)); 337 341 return VERR_PDM_DRIVER_NAME_CLASH; … … 350 354 pDrv->iNextInstance = 0; 351 355 pDrv->pReg = pReg; 356 pDrv->pInstances = NULL; 352 357 rc = CFGMR3QueryStringAllocDef( pRegCB->pCfgNode, "RCSearchPath", &pDrv->pszRCSearchPath, NULL); 353 358 if (RT_SUCCESS(rc)) … … 359 364 else 360 365 pRegCB->pVM->pdm.s.pDrvs = pDrv; 366 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 367 361 368 Log(("PDM: Registered driver '%s'\n", pReg->szName)); 362 369 return VINF_SUCCESS; … … 366 373 else 367 374 rc = VERR_NO_MEMORY; 375 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 368 376 return rc; 369 377 } … … 376 384 PPDMDRV pdmR3DrvLookup(PVM pVM, const char *pszName) 377 385 { 386 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 378 387 for (PPDMDRV pDrv = pVM->pdm.s.pDrvs; pDrv; pDrv = pDrv->pNext) 379 388 if (!strcmp(pDrv->pReg->szName, pszName)) 389 { 390 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 380 391 return pDrv; 392 } 393 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 381 394 return NULL; 382 395 } … … 394 407 * @param ppNode The AttachedDriver node, replaced if any 395 408 * morphing took place. 409 * @note Caller owns CoreListCritSectRw exclusivly. 396 410 */ 397 411 static int pdmR3DrvMaybeTransformChain(PVM pVM, PPDMDRVINS pDrvAbove, PPDMLUN pLun, PCFGMNODE *ppNode) … … 653 667 * Instantiate a driver. 654 668 * 669 * @note The caller must enter CoreListCritSectRw with exclusive access 670 * rights before the call. This function _will_ release the lock for 671 * doing callbacks (and failure cleanups), but it will still own it 672 * upon return. 673 * 655 674 * @returns VBox status code, including informational statuses. 656 675 * … … 680 699 681 700 Assert(pBaseInterface->pfnQueryInterface(pBaseInterface, PDMIBASE_IID) == pBaseInterface); 701 702 /* Exclusive lock ownership w/o any extra recursions. */ 703 Assert(RTCritSectRwIsWriteOwner(&pVM->pdm.s.CoreListCritSectRw)); 704 Assert(RTCritSectRwGetWriteRecursion(&pVM->pdm.s.CoreListCritSectRw) == 1); 682 705 683 706 /* … … 747 770 //pNew->Internal.s.pfnAsyncNotify = NULL; 748 771 pNew->Internal.s.pCfgHandle = pNode; 772 //pNew->Internal.s.pNext = NULL; 749 773 pNew->pReg = pDrv->pReg; 750 774 pNew->pCfg = pConfigNode; … … 775 799 #endif 776 800 801 /* 802 * Update PDMDRV members and link it into the instance list. 803 */ 777 804 pDrv->iNextInstance++; 778 805 pDrv->cInstances++; 806 807 PPDMDRVINS pPrevDrvIns = pDrv->pInstances; 808 if (!pPrevDrvIns) 809 pDrv->pInstances = pNew; 810 else 811 { 812 while (pPrevDrvIns->Internal.s.pNext) 813 pPrevDrvIns = pPrevDrvIns->Internal.s.pNext; 814 pPrevDrvIns->Internal.s.pNext = pNew; 815 } 779 816 780 817 /* … … 793 830 /* 794 831 * Invoke the constructor. 832 * 833 * We have to leave the exclusive CoreListCritSectRw ownership here, as 834 * the constructor may call us back recursively to attach drivers down 835 * the stack, which would cause trouble in pdmR3DrvDestroyChain since 836 * it assumes there is no lock recursion. There is also the possibility 837 * of the constructor engaging with PDM asynchronously via another thread. 795 838 */ 839 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 796 840 rc = pDrv->pReg->pfnConstruct(pNew, pNew->pCfg, 0 /*fFlags*/); 841 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 797 842 if (RT_SUCCESS(rc)) 798 843 { … … 816 861 else 817 862 { 818 pdmR3DrvDestroyChain(p New, PDM_TACH_FLAGS_NO_CALLBACKS);863 pdmR3DrvDestroyChain(pVM, pNew, PDM_TACH_FLAGS_NO_CALLBACKS); 819 864 if (rc == VERR_VERSION_MISMATCH) 820 865 rc = VERR_PDM_DRIVER_VERSION_MISMATCH; … … 854 899 * This will of course lead to the destruction of the driver and all drivers below it in the chain. 855 900 * 901 * @note The caller must enter CoreListCritSectRw with exclusive access 902 * rights before the call. This function _will_ release the lock for 903 * doing callbacks and cleaning up resources associated with the 904 * drivers being destroyed, but it will still own it upon return. 905 * 856 906 * @returns VINF_SUCCESS 907 * @param pVM The cross context VM structure. 857 908 * @param pDrvIns The driver instance to detach. 858 909 * @param fFlags Flags, combination of the PDMDEVATT_FLAGS_* \#defines. 859 910 */ 860 int pdmR3DrvDetach(P PDMDRVINS pDrvIns, uint32_t fFlags)911 int pdmR3DrvDetach(PVM pVM, PPDMDRVINS pDrvIns, uint32_t fFlags) 861 912 { 862 913 PDMDRV_ASSERT_DRVINS(pDrvIns); 863 914 LogFlow(("pdmR3DrvDetach: pDrvIns=%p '%s'/%d\n", pDrvIns, pDrvIns->pReg->szName, pDrvIns->iInstance)); 864 VM_ASSERT_EMT(p DrvIns->Internal.s.pVMR3);915 VM_ASSERT_EMT(pVM); 865 916 866 917 /* … … 891 942 * Join paths with pdmR3DrvDestroyChain. 892 943 */ 893 pdmR3DrvDestroyChain(pDrvIns, fFlags); 944 pdmR3DrvDestroyChain(pVM, pDrvIns, fFlags); 945 894 946 return VINF_SUCCESS; 895 947 } … … 901 953 * This is used when unplugging a device at run time. 902 954 * 955 * @note The caller must enter CoreListCritSectRw with exclusive access 956 * rights before the call. This function _will_ release the lock for 957 * doing callbacks and cleaning up resources associated with the 958 * drivers being destroyed, but it will still own it upon return. 959 * 960 * @param pVM The cross context VM structure. 903 961 * @param pDrvIns Pointer to the driver instance to start with. 904 962 * @param fFlags PDM_TACH_FLAGS_NOT_HOT_PLUG, PDM_TACH_FLAGS_NO_CALLBACKS 905 963 * or 0. 906 964 */ 907 void pdmR3DrvDestroyChain(P PDMDRVINS pDrvIns, uint32_t fFlags)908 { 909 PVM pVM = pDrvIns->Internal.s.pVMR3;965 void pdmR3DrvDestroyChain(PVM pVM, PPDMDRVINS pDrvIns, uint32_t fFlags) 966 { 967 Assert(pDrvIns->Internal.s.pVMR3 == pVM); 910 968 VM_ASSERT_EMT(pVM); 969 970 /* Exclusive lock ownership w/o any extra recursions. */ 971 Assert(RTCritSectRwIsWriteOwner(&pVM->pdm.s.CoreListCritSectRw)); 972 Assert(RTCritSectRwGetWriteRecursion(&pVM->pdm.s.CoreListCritSectRw) == 1); 911 973 912 974 /* 913 975 * Detach the bottommost driver until we've detached pDrvIns. 914 976 */ 977 Assert(!pDrvIns->Internal.s.fDetaching); 915 978 pDrvIns->Internal.s.fDetaching = true; 979 916 980 PPDMDRVINS pCur; 917 981 do … … 940 1004 941 1005 if (!(fFlags & PDM_TACH_FLAGS_NO_CALLBACKS) && pParent->pReg->pfnDetach) 1006 { 1007 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 942 1008 pParent->pReg->pfnDetach(pParent, fFlags); 1009 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1010 } 943 1011 944 1012 pParent->pDownBase = NULL; … … 955 1023 if (pLun->pDevIns->pReg->pfnDetach) 956 1024 { 1025 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 957 1026 PDMCritSectEnter(pVM, pLun->pDevIns->pCritSectRoR3, VERR_IGNORED); 958 1027 pLun->pDevIns->pReg->pfnDetach(pLun->pDevIns, pLun->iLun, fFlags); 959 1028 PDMCritSectLeave(pVM, pLun->pDevIns->pCritSectRoR3); 1029 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 960 1030 } 961 1031 } … … 964 1034 if (pLun->pUsbIns->pReg->pfnDriverDetach) 965 1035 { 1036 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 966 1037 /** @todo USB device locking? */ 967 1038 pLun->pUsbIns->pReg->pfnDriverDetach(pLun->pUsbIns, pLun->iLun, fFlags); 1039 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 968 1040 } 969 1041 } … … 972 1044 973 1045 /* 974 * Calldestructor.1046 * Unlink the instance and call the destructor. 975 1047 */ 1048 PPDMDRVINS pPrevEntry = pCur->Internal.s.pDrv->pInstances; 1049 if (pCur == pPrevEntry) 1050 pCur->Internal.s.pDrv->pInstances = pCur->Internal.s.pNext; 1051 else if (pPrevEntry) 1052 { 1053 PPDMDRVINS pCurEntry = pPrevEntry->Internal.s.pNext; 1054 while (pCurEntry != pCur && pCurEntry) 1055 { 1056 pPrevEntry = pCurEntry; 1057 pCurEntry = pCurEntry->Internal.s.pNext; 1058 } 1059 AssertLogRelMsg(pCurEntry == pCur, ("%s", pCur->pReg->szName)); 1060 if (pCurEntry == pCur) 1061 pPrevEntry->Internal.s.pNext = pCur->Internal.s.pNext; 1062 } 1063 else 1064 AssertLogRelMsg(pPrevEntry != NULL, ("%s", pCur->pReg->szName)); 1065 976 1066 pCur->pUpBase = NULL; 1067 pCur->Internal.s.pDrv->cInstances--; 1068 1069 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1070 977 1071 if (pCur->pReg->pfnDestruct) 978 1072 pCur->pReg->pfnDestruct(pCur); 979 pCur->Internal.s.pDrv->cInstances--;980 1073 981 1074 /* … … 1026 1119 MMR3HeapFree(pCur); 1027 1120 1121 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1028 1122 } while (pCur != pDrvIns); 1029 1123 } 1030 1124 1125 1126 /** 1127 * Enumerates driver instances via a callback. 1128 * 1129 * @returns VBox status code. 1130 * @retval VERR_PDM_DRIVER_NOT_FOUND if @a pszDriver isn't registered. 1131 * @param pUVM The user mode VM handle. 1132 * @param pszDriver The name of the driver which instances should be 1133 * enumerated. 1134 * @param pfnCallback The callback function. 1135 * @param pvUser User argument. 1136 */ 1137 VMMR3DECL(int) PDMR3DriverEnumInstances(PUVM pUVM, const char *pszDriver, PFNPDMENUMDRVINS pfnCallback, void *pvUser) 1138 { 1139 LogFlow(("PDMR3DriverEnumInstances: pszDriver=%p:{%s} pfnCallback=%p pvUser=%p\n", pszDriver, pszDriver, pfnCallback, pvUser)); 1140 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE); 1141 PVM const pVM = pUVM->pVM; 1142 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 1143 1144 /* 1145 * First find the PDMDRV entry for the driver. 1146 */ 1147 int rc = VINF_SUCCESS; 1148 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 1149 PPDMDRV const pDrv = pdmR3DrvLookup(pVM, pszDriver); 1150 if (pDrv) 1151 { 1152 /* 1153 * Walk the list of instances. 1154 */ 1155 for (PPDMDRVINSR3 pDrvIns = pDrv->pInstances; pDrvIns; pDrvIns = pDrvIns->Internal.s.pNext) 1156 { 1157 if (!pDrvIns->Internal.s.fDetaching) /* paranoia */ 1158 { 1159 PPDMLUN const pLun = pDrvIns->Internal.s.pLun; 1160 PPDMDEVINS const pDevIns = pLun->pDevIns; 1161 const char * const pszDevName = pDevIns ? pDevIns->pReg->szName : pLun->pUsbIns->pReg->szName; 1162 uint32_t const uDevInstance = pDevIns ? pDevIns->iInstance : pLun->pUsbIns->iInstance; 1163 int rc2 = pfnCallback(&pDrvIns->IBase, pDrvIns->iInstance, pDevIns == NULL, 1164 pszDevName, uDevInstance, pLun->iLun, pvUser); 1165 if (RT_FAILURE(rc2)) 1166 { 1167 rc = rc2; 1168 break; 1169 } 1170 } 1171 } 1172 } 1173 else 1174 AssertFailedStmt(rc = VERR_PDM_DRIVER_NOT_FOUND); 1175 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1176 return rc; 1177 } 1031 1178 1032 1179 … … 1049 1196 * Check that there isn't anything attached already. 1050 1197 */ 1198 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1051 1199 int rc; 1052 1200 if (!pDrvIns->Internal.s.pDown) … … 1068 1216 rc = VERR_PDM_DRIVER_ALREADY_ATTACHED; 1069 1217 } 1218 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1070 1219 1071 1220 LogFlow(("pdmR3DrvHlp_Attach: caller='%s'/%d: return %Rrc\n", … … 1081 1230 LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d: fFlags=%#x\n", 1082 1231 pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags)); 1083 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3); 1232 PVM const pVM = pDrvIns->Internal.s.pVMR3; 1233 VM_ASSERT_EMT(pVM); 1084 1234 1085 1235 /* … … 1087 1237 */ 1088 1238 int rc; 1239 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1089 1240 if (pDrvIns->Internal.s.pDown) 1090 rc = pdmR3DrvDetach(p DrvIns->Internal.s.pDown, fFlags);1241 rc = pdmR3DrvDetach(pVM, pDrvIns->Internal.s.pDown, fFlags); 1091 1242 else 1092 1243 { … … 1094 1245 rc = VERR_PDM_NO_DRIVER_ATTACHED; 1095 1246 } 1247 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1096 1248 1097 1249 LogFlow(("pdmR3DrvHlp_Detach: caller='%s'/%d: returns %Rrc\n", … … 1107 1259 LogFlow(("pdmR3DrvHlp_DetachSelf: caller='%s'/%d: fFlags=%#x\n", 1108 1260 pDrvIns->pReg->szName, pDrvIns->iInstance, fFlags)); 1109 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3); 1110 1111 int rc = pdmR3DrvDetach(pDrvIns, fFlags); 1261 PVM const pVM = pDrvIns->Internal.s.pVMR3; 1262 VM_ASSERT_EMT(pVM); 1263 1264 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1265 int rc = pdmR3DrvDetach(pVM, pDrvIns, fFlags); 1266 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1112 1267 1113 1268 LogFlow(("pdmR3DrvHlp_Detach: returns %Rrc\n", rc)); /* pDrvIns is freed by now. */ … … 1122 1277 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: pszFilename=%p:{%s} pszCoreDriver=%p:{%s}\n", 1123 1278 pDrvIns->pReg->szName, pDrvIns->iInstance, pszFilename, pszFilename, pszCoreDriver, pszCoreDriver)); 1124 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3); 1279 PVM const pVM = pDrvIns->Internal.s.pVMR3; 1280 VM_ASSERT_EMT(pVM); 1281 1282 /* We're using CoreListCritSectRw for some setup & CFGM serialization here. */ 1283 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1125 1284 1126 1285 /* … … 1129 1288 if (pDrvIns->Internal.s.pDown) 1130 1289 { 1290 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1131 1291 AssertMsgFailed(("Cannot prepare a mount when something's attached to you!\n")); 1132 1292 return VERR_PDM_DRIVER_ALREADY_ATTACHED; … … 1137 1297 * attached configuration tree. 1138 1298 */ 1139 PCFGMNODE 1299 PCFGMNODE pNode = CFGMR3GetChild(pDrvIns->Internal.s.pCfgHandle, "AttachedDriver"); 1140 1300 if (pNode) 1141 1301 CFGMR3RemoveNode(pNode); … … 1147 1307 { 1148 1308 /** @todo implement image probing. */ 1309 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1149 1310 AssertReleaseMsgFailed(("Not implemented!\n")); 1150 1311 return VERR_NOT_IMPLEMENTED; … … 1167 1328 if (RT_SUCCESS(rc)) 1168 1329 { 1330 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1169 1331 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc (Driver=%s)\n", 1170 1332 pDrvIns->pReg->szName, pDrvIns->iInstance, rc, pszCoreDriver)); 1171 1333 return rc; 1172 1334 } 1173 else 1174 AssertMsgFailed(("Path string insert failed, rc=%Rrc\n", rc)); 1335 AssertMsgFailed(("Path string insert failed, rc=%Rrc\n", rc)); 1175 1336 } 1176 1337 else … … 1184 1345 AssertMsgFailed(("AttachedDriver node insert failed, rc=%Rrc\n", rc)); 1185 1346 1347 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1186 1348 LogFlow(("pdmR3DrvHlp_MountPrepare: caller='%s'/%d: returns %Rrc\n", 1187 1349 pDrvIns->pReg->szName, pDrvIns->iInstance, rc)); … … 1226 1388 { 1227 1389 PDMDRV_ASSERT_DRVINS(pDrvIns); 1228 int rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, va); Assert(rc2 == rc); NOREF(rc2); 1390 int const rc2 = VMSetErrorV(pDrvIns->Internal.s.pVMR3, rc, RT_SRC_POS_ARGS, pszFormat, va); 1391 Assert(rc2 == rc); RT_NOREF_PV(rc2); 1229 1392 return rc; 1230 1393 } … … 1407 1570 PDMDRV_ASSERT_DRVINS(pDrvIns); 1408 1571 VM_ASSERT_EMT(pDrvIns->Internal.s.pVMR3); 1409 LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: uVersion=%#x cbGuess=%#x 1572 LogFlow(("pdmR3DrvHlp_SSMRegister: caller='%s'/%d: uVersion=%#x cbGuess=%#x\n" 1410 1573 " pfnLivePrep=%p pfnLiveExec=%p pfnLiveVote=%p pfnSavePrep=%p pfnSaveExec=%p pfnSaveDone=%p pszLoadPrep=%p pfnLoadExec=%p pfnLoaddone=%p\n", 1411 1574 pDrvIns->pReg->szName, pDrvIns->iInstance, uVersion, cbGuess, … … 1453 1616 1454 1617 /** @interface_method_impl{PDMDRVHLPR3,pfnDBGFInfoRegister} */ 1455 static DECLCALLBACK(int) pdmR3DrvHlp_DBGFInfoRegister(PPDMDRVINS pDrvIns, const char *pszName, const char *pszDesc, PFNDBGFHANDLERDRV pfnHandler) 1618 static DECLCALLBACK(int) pdmR3DrvHlp_DBGFInfoRegister(PPDMDRVINS pDrvIns, const char *pszName, const char *pszDesc, 1619 PFNDBGFHANDLERDRV pfnHandler) 1456 1620 { 1457 1621 PDMDRV_ASSERT_DRVINS(pDrvIns); … … 1467 1631 1468 1632 /** @interface_method_impl{PDMDRVHLPR3,pfnDBGFInfoRegisterArgv} */ 1469 static DECLCALLBACK(int) pdmR3DrvHlp_DBGFInfoRegisterArgv(PPDMDRVINS pDrvIns, const char *pszName, const char *pszDesc, PFNDBGFINFOARGVDRV pfnHandler) 1633 static DECLCALLBACK(int) pdmR3DrvHlp_DBGFInfoRegisterArgv(PPDMDRVINS pDrvIns, const char *pszName, const char *pszDesc, 1634 PFNDBGFINFOARGVDRV pfnHandler) 1470 1635 { 1471 1636 PDMDRV_ASSERT_DRVINS(pDrvIns); … … 1516 1681 1517 1682 /** @interface_method_impl{PDMDRVHLPR3,pfnSTAMRegisterV} */ 1518 static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterV(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, 1519 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, va_list args) 1683 static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterV(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, 1684 STAMVISIBILITY enmVisibility, STAMUNIT enmUnit, const char *pszDesc, 1685 const char *pszName, va_list args) 1520 1686 { 1521 1687 PDMDRV_ASSERT_DRVINS(pDrvIns); … … 1546 1712 1547 1713 /** @interface_method_impl{PDMDRVHLPR3,pfnSTAMRegisterF} */ 1548 static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, STAMVISIBILITY enmVisibility, 1549 STAMUNIT enmUnit, const char *pszDesc, const char *pszName, ...) 1714 static DECLCALLBACK(void) pdmR3DrvHlp_STAMRegisterF(PPDMDRVINS pDrvIns, void *pvSample, STAMTYPE enmType, 1715 STAMVISIBILITY enmVisibility, STAMUNIT enmUnit, const char *pszDesc, 1716 const char *pszName, ...) 1550 1717 { 1551 1718 va_list va; … … 1592 1759 if ( uOperation >= VMMR0_DO_SRV_START 1593 1760 && uOperation < VMMR0_DO_SRV_END) 1594 rc = SUPR3CallVMMR0Ex(VMCC_GET_VMR0_FOR_CALL(pDrvIns->Internal.s.pVMR3), NIL_VMCPUID, uOperation, 0, (PSUPVMMR0REQHDR)pvArg); 1761 rc = SUPR3CallVMMR0Ex(VMCC_GET_VMR0_FOR_CALL(pDrvIns->Internal.s.pVMR3), NIL_VMCPUID, 1762 uOperation, 0, (PSUPVMMR0REQHDR)pvArg); 1595 1763 else 1596 1764 { … … 1605 1773 1606 1774 /** @interface_method_impl{PDMDRVHLPR3,pfnUSBRegisterHub} */ 1607 static DECLCALLBACK(int) pdmR3DrvHlp_USBRegisterHub(PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp) 1775 static DECLCALLBACK(int) pdmR3DrvHlp_USBRegisterHub(PPDMDRVINS pDrvIns, uint32_t fVersions, uint32_t cPorts, 1776 PCPDMUSBHUBREG pUsbHubReg, PPCPDMUSBHUBHLP ppUsbHubHlp) 1608 1777 { 1609 1778 PDMDRV_ASSERT_DRVINS(pDrvIns); … … 1676 1845 1677 1846 /** @interface_method_impl{PDMDRVHLPR3,pfnThreadCreate} */ 1678 static DECLCALLBACK(int) pdmR3DrvHlp_ThreadCreate(PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, PFNPDMTHREADDRV pfnThread, 1679 PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, RTTHREADTYPE enmType, const char *pszName) 1847 static DECLCALLBACK(int) pdmR3DrvHlp_ThreadCreate(PPDMDRVINS pDrvIns, PPPDMTHREAD ppThread, void *pvUser, 1848 PFNPDMTHREADDRV pfnThread, PFNPDMTHREADWAKEUPDRV pfnWakeup, size_t cbStack, 1849 RTTHREADTYPE enmType, const char *pszName) 1680 1850 { 1681 1851 PDMDRV_ASSERT_DRVINS(pDrvIns); -
trunk/src/VBox/VMM/VMMR3/PDMUsb.cpp
r98122 r106022 142 142 * Check for duplicate registration and find the last hub for FIFO registration. 143 143 */ 144 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 145 144 146 PPDMUSBHUB pPrev = NULL; 145 147 for (PPDMUSBHUB pCur = pVM->pdm.s.pUsbHubs; pCur; pCur = pCur->pNext) 146 148 { 147 149 if (pCur->pDrvIns == pDrvIns) 150 { 151 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 148 152 return VERR_PDM_USB_HUB_EXISTS; 153 } 149 154 pPrev = pCur; 150 155 } … … 155 160 PPDMUSBHUB pHub = (PPDMUSBHUB)MMR3HeapAlloc(pVM, MM_TAG_PDM_DRIVER, sizeof(*pHub)); 156 161 if (!pHub) 162 { 163 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 157 164 return VERR_NO_MEMORY; 165 } 158 166 159 167 pHub->fVersions = fVersions; … … 169 177 else 170 178 pVM->pdm.s.pUsbHubs = pHub; 179 180 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 171 181 172 182 Log(("PDM: Registered USB hub %p/%s\n", pDrvIns, pDrvIns->pReg->szName)); … … 251 261 * Check for duplicate and find FIFO entry at the same time. 252 262 */ 253 PCPDMUSBREGCBINT pRegCB = (PCPDMUSBREGCBINT)pCallbacks; 263 PCPDMUSBREGCBINT const pRegCB = (PCPDMUSBREGCBINT)pCallbacks; 264 PVM const pVM = pRegCB->pVM; 265 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 266 254 267 PPDMUSB pUsbPrev = NULL; 255 PPDMUSB pUsb = pRegCB->pVM->pdm.s.pUsbDevs;268 PPDMUSB pUsb = pVM->pdm.s.pUsbDevs; 256 269 for (; pUsb; pUsbPrev = pUsb, pUsb = pUsb->pNext) 257 AssertMsgReturn(strcmp(pUsb->pReg->szName, pReg->szName), 258 ("USB Device '%s' already exists\n", pReg->szName), 259 VERR_PDM_USB_NAME_CLASH); 270 AssertMsgReturnStmt(strcmp(pUsb->pReg->szName, pReg->szName), 271 ("USB Device '%s' already exists\n", pReg->szName), 272 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw), 273 VERR_PDM_USB_NAME_CLASH); 260 274 261 275 /* 262 276 * Allocate new device structure and insert it into the list. 263 277 */ 264 pUsb = (PPDMUSB)MMR3HeapAlloc(p RegCB->pVM, MM_TAG_PDM_DEVICE, sizeof(*pUsb));278 pUsb = (PPDMUSB)MMR3HeapAlloc(pVM, MM_TAG_PDM_DEVICE, sizeof(*pUsb)); 265 279 if (pUsb) 266 280 { … … 274 288 pUsbPrev->pNext = pUsb; 275 289 else 276 pRegCB->pVM->pdm.s.pUsbDevs = pUsb; 290 pVM->pdm.s.pUsbDevs = pUsb; 291 292 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 277 293 Log(("PDM: Registered USB device '%s'\n", pReg->szName)); 278 294 return VINF_SUCCESS; 279 295 } 296 297 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 280 298 return VERR_NO_MEMORY; 281 299 } … … 402 420 int pdmR3UsbVMInitComplete(PVM pVM) 403 421 { 422 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 404 423 for (PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext) 405 424 { 406 425 if (pUsbIns->pReg->pfnVMInitComplete) 407 426 { 427 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 408 428 int rc = pUsbIns->pReg->pfnVMInitComplete(pUsbIns); 409 429 if (RT_FAILURE(rc)) … … 413 433 return rc; 414 434 } 415 } 416 } 435 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 436 } 437 } 438 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 417 439 return VINF_SUCCESS; 418 440 } … … 425 447 PPDMUSB pdmR3UsbLookup(PVM pVM, const char *pszName) 426 448 { 427 size_t cchName = strlen(pszName); 449 size_t const cchName = strlen(pszName); 450 451 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 428 452 for (PPDMUSB pUsb = pVM->pdm.s.pUsbDevs; pUsb; pUsb = pUsb->pNext) 429 if ( pUsb->cchName == cchName 430 && !strcmp(pUsb->pReg->szName, pszName)) 453 if ( pUsb->cchName == cchName 454 && !strcmp(pUsb->pReg->szName, pszName)) 455 { 456 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 431 457 return pUsb; 458 } 459 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 432 460 return NULL; 433 461 } … … 449 477 return VERR_PDM_NO_USB_HUBS; 450 478 479 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 451 480 for (PPDMUSBHUB pCur = pVM->pdm.s.pUsbHubs; pCur; pCur = pCur->pNext) 452 481 if (pCur->cAvailablePorts > 0) … … 459 488 } 460 489 /* For high-speed USB 2.0 devices only, allow USB 1.1 fallback. */ 461 if ((iUsbVersion & VUSB_STDVER_20) && (pCur->fVersions == VUSB_STDVER_11))490 if ((iUsbVersion & VUSB_STDVER_20) && pCur->fVersions == VUSB_STDVER_11) 462 491 *ppHub = pCur; 463 492 } 493 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 464 494 if (*ppHub) 465 495 return VINF_SUCCESS; … … 662 692 * Link it into all the lists. 663 693 */ 694 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 695 664 696 /* The global instance FIFO. */ 665 697 PPDMUSBINS pPrev1 = pVM->pdm.s.pUsbInstances; … … 689 721 pPrev2->Internal.s.pPerDeviceNext = pUsbIns; 690 722 } 723 724 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 691 725 692 726 /* … … 1138 1172 * Destroy the luns with their driver chains and call the device destructor. 1139 1173 */ 1174 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1140 1175 while (pUsbIns->Internal.s.pLuns) 1141 1176 { … … 1143 1178 pUsbIns->Internal.s.pLuns = pLun->pNext; 1144 1179 if (pLun->pTop) 1145 pdmR3DrvDestroyChain(p Lun->pTop, PDM_TACH_FLAGS_NOT_HOT_PLUG); /* Hotplugging is handled differently here atm. */1180 pdmR3DrvDestroyChain(pVM, pLun->pTop, PDM_TACH_FLAGS_NOT_HOT_PLUG); /* Hotplugging is handled differently here atm. */ 1146 1181 MMR3HeapFree(pLun); 1147 1182 } 1183 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1148 1184 1149 1185 /* finally, the device. */ … … 1163 1199 * Unlink it. 1164 1200 */ 1201 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1202 1165 1203 /* The global instance FIFO. */ 1166 1204 if (pVM->pdm.s.pUsbInstances == pUsbIns) … … 1196 1234 } 1197 1235 1236 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1237 1198 1238 /* 1199 1239 * Trash it. … … 1225 1265 */ 1226 1266 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE); 1227 PVM pVM = pUVM->pVM;1267 PVM const pVM = pUVM->pVM; 1228 1268 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 1229 1269 VM_ASSERT_EMT(pVM); … … 1233 1273 * Search the global list for it. 1234 1274 */ 1275 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 1235 1276 PPDMUSBINS pUsbIns = pVM->pdm.s.pUsbInstances; 1236 1277 for ( ; pUsbIns; pUsbIns = pUsbIns->Internal.s.pNext) … … 1238 1279 break; 1239 1280 if (!pUsbIns) 1281 { 1282 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1240 1283 return VERR_PDM_DEVICE_INSTANCE_NOT_FOUND; /** @todo VERR_PDM_USB_INSTANCE_NOT_FOUND */ 1284 } 1241 1285 1242 1286 /* … … 1244 1288 */ 1245 1289 PPDMUSBHUB pHub = pUsbIns->Internal.s.pHub; 1290 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); /** @todo would be nice to call the pfnDetachDevice owning this.. */ 1246 1291 if (pHub) 1247 1292 { … … 1254 1299 } 1255 1300 1301 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1256 1302 pHub->cAvailablePorts++; 1257 1303 Assert(pHub->cAvailablePorts > 0 && pHub->cAvailablePorts <= pHub->cPorts); 1258 1304 pUsbIns->Internal.s.pHub = NULL; 1305 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1259 1306 } 1260 1307 … … 1292 1339 * @param iLun The Logical Unit to obtain the interface of. 1293 1340 * @param ppLun Where to store the pointer to the LUN if found. 1294 * @thread Try only do this in EMT...1295 1341 */ 1296 1342 static int pdmR3UsbFindLun(PVM pVM, const char *pszDevice, unsigned iInstance, unsigned iLun, PPPDMLUN ppLun) … … 1299 1345 * Iterate registered devices looking for the device. 1300 1346 */ 1301 size_t cchDevice = strlen(pszDevice); 1347 size_t const cchDevice = strlen(pszDevice); 1348 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 1302 1349 for (PPDMUSB pUsbDev = pVM->pdm.s.pUsbDevs; pUsbDev; pUsbDev = pUsbDev->pNext) 1303 1350 { 1304 if ( 1305 && 1351 if ( pUsbDev->cchName == cchDevice 1352 && !memcmp(pUsbDev->pReg->szName, pszDevice, cchDevice)) 1306 1353 { 1307 1354 /* … … 1320 1367 { 1321 1368 *ppLun = pLun; 1369 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1322 1370 return VINF_SUCCESS; 1323 1371 } 1324 1372 } 1373 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1325 1374 return VERR_PDM_LUN_NOT_FOUND; 1326 1375 } 1327 1376 } 1377 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1328 1378 return VERR_PDM_DEVICE_INSTANCE_NOT_FOUND; 1329 1379 } 1330 1380 } 1381 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1331 1382 return VERR_PDM_DEVICE_NOT_FOUND; 1332 1383 } … … 1355 1406 LogFlow(("PDMR3UsbDriverAttach: pszDevice=%p:{%s} iDevIns=%d iLun=%d fFlags=%#x ppBase=%p\n", 1356 1407 pszDevice, pszDevice, iDevIns, iLun, fFlags, ppBase)); 1408 if (ppBase) 1409 *ppBase = NULL; 1357 1410 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE); 1358 PVM pVM = pUVM->pVM;1411 PVM const pVM = pUVM->pVM; 1359 1412 VM_ASSERT_VALID_EXT_RETURN(pVM, VERR_INVALID_VM_HANDLE); 1360 1413 VM_ASSERT_EMT(pVM); 1361 1362 if (ppBase)1363 *ppBase = NULL;1364 1414 1365 1415 /* … … 1453 1503 * Find the LUN in question. 1454 1504 */ 1505 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1506 1455 1507 PPDMLUN pLun; 1456 1508 int rc = pdmR3UsbFindLun(pVM, pszDevice, iDevIns, iLun, &pLun); … … 1477 1529 } 1478 1530 if (pDrvIns) 1479 rc = pdmR3DrvDetach(pDrvIns, fFlags); 1480 else 1481 rc = VERR_PDM_DRIVER_INSTANCE_NOT_FOUND; 1531 { 1532 rc = pdmR3DrvDetach(pVM, pDrvIns, fFlags); 1533 1534 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1535 LogFlow(("PDMR3UsbDriverDetach: returns %Rrc (pdmR3DrvDetach)\n", rc)); 1536 return rc; 1537 } 1538 rc = VERR_PDM_DRIVER_INSTANCE_NOT_FOUND; 1482 1539 } 1483 1540 else … … 1485 1542 } 1486 1543 1544 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1487 1545 LogFlow(("PDMR3UsbDriverDetach: returns %Rrc\n", rc)); 1488 1546 return rc; … … 1506 1564 LogFlow(("PDMR3UsbQueryLun: pszDevice=%p:{%s} iInstance=%u iLun=%u ppBase=%p\n", 1507 1565 pszDevice, pszDevice, iInstance, iLun, ppBase)); 1566 *ppBase = NULL; 1508 1567 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE); 1509 1568 PVM pVM = pUVM->pVM; … … 1513 1572 * Find the LUN. 1514 1573 */ 1574 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 1575 1515 1576 PPDMLUN pLun; 1516 1577 int rc = pdmR3UsbFindLun(pVM, pszDevice, iInstance, iLun, &pLun); … … 1520 1581 { 1521 1582 *ppBase = &pLun->pTop->IBase; 1583 1584 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1522 1585 LogFlow(("PDMR3UsbQueryLun: return %Rrc and *ppBase=%p\n", VINF_SUCCESS, *ppBase)); 1523 1586 return VINF_SUCCESS; … … 1525 1588 rc = VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN; 1526 1589 } 1590 1591 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1527 1592 LogFlow(("PDMR3UsbQueryLun: returns %Rrc\n", rc)); 1528 1593 return rc; … … 1552 1617 LogFlow(("PDMR3QueryDriverOnLun: pszDevice=%p:{%s} iInstance=%u iLun=%u pszDriver=%p:{%s} ppBase=%p\n", 1553 1618 pszDevice, pszDevice, iInstance, iLun, pszDriver, pszDriver, ppBase)); 1619 *ppBase = NULL; 1554 1620 UVM_ASSERT_VALID_EXT_RETURN(pUVM, VERR_INVALID_VM_HANDLE); 1555 1621 PVM pVM = pUVM->pVM; … … 1559 1625 * Find the LUN. 1560 1626 */ 1627 RTCritSectRwEnterShared(&pVM->pdm.s.CoreListCritSectRw); 1628 1561 1629 PPDMLUN pLun; 1562 1630 int rc = pdmR3UsbFindLun(pVM, pszDevice, iInstance, iLun, &pLun); … … 1569 1637 { 1570 1638 *ppBase = &pDrvIns->IBase; 1639 1640 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1571 1641 LogFlow(("PDMR3UsbQueryDriverOnLun: return %Rrc and *ppBase=%p\n", VINF_SUCCESS, *ppBase)); 1572 1642 return VINF_SUCCESS; 1573 1574 1643 } 1575 1644 rc = VERR_PDM_DRIVER_NOT_FOUND; … … 1578 1647 rc = VERR_PDM_NO_DRIVER_ATTACHED_TO_LUN; 1579 1648 } 1649 1650 RTCritSectRwLeaveShared(&pVM->pdm.s.CoreListCritSectRw); 1580 1651 LogFlow(("PDMR3UsbQueryDriverOnLun: returns %Rrc\n", rc)); 1581 1652 return rc; … … 1600 1671 * Lookup the LUN, it might already be registered. 1601 1672 */ 1673 RTCritSectRwEnterExcl(&pVM->pdm.s.CoreListCritSectRw); 1602 1674 PPDMLUN pLunPrev = NULL; 1603 1675 PPDMLUN pLun = pUsbIns->Internal.s.pLuns; … … 1611 1683 if (!pLun) 1612 1684 { 1613 if ( !pBaseInterface 1614 || !pszDesc 1615 || !*pszDesc) 1616 { 1685 if ( !pBaseInterface 1686 || !pszDesc 1687 || !*pszDesc) 1688 { 1689 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1617 1690 Assert(pBaseInterface); 1618 1691 Assert(pszDesc || *pszDesc); … … 1622 1695 pLun = (PPDMLUN)MMR3HeapAlloc(pVM, MM_TAG_PDM_LUN, sizeof(*pLun)); 1623 1696 if (!pLun) 1697 { 1698 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1624 1699 return VERR_NO_MEMORY; 1700 } 1625 1701 1626 1702 pLun->iLun = iLun; … … 1641 1717 else if (pLun->pTop) 1642 1718 { 1719 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1643 1720 AssertMsgFailed(("Already attached! The device should keep track of such things!\n")); 1644 1721 LogFlow(("pdmR3UsbHlp_DriverAttach: caller='%s'/%d: returns %Rrc\n", pUsbIns->pReg->szName, pUsbIns->iInstance, VERR_PDM_DRIVER_ALREADY_ATTACHED)); … … 1657 1734 else 1658 1735 rc = VERR_PDM_NO_ATTACHED_DRIVER; 1736 RTCritSectRwLeaveExcl(&pVM->pdm.s.CoreListCritSectRw); 1659 1737 1660 1738 -
trunk/src/VBox/VMM/VMMR3/VMMR3.def
r102092 r106022 281 281 PDMR3DriverAttach 282 282 PDMR3DriverDetach 283 PDMR3DriverEnumInstances 283 284 PDMR3NsBwGroupSetLimit 284 285 PDMR3QueryDeviceLun -
trunk/src/VBox/VMM/include/PDMInternal.h
r98570 r106022 417 417 /** Pointer to the ring-0 request handler function. */ 418 418 PFNPDMDRVREQHANDLERR0 pfnReqHandlerR0; 419 /** Pointer to the next instance (starts at PDMDRV::pInstances). */ 420 R3PTRTYPE(PPDMDRVINS) pNext; 419 421 } PDMDRVINSINT; 420 422 … … 610 612 PPDMDRVINS pBottom; 611 613 /** Pointer to the device instance which the LUN belongs to. 612 * Either this is set or pUsbIns is set. Both isnever set at the same time. */614 * Either this is set or pUsbIns is set. Both are never set at the same time. */ 613 615 PPDMDEVINS pDevIns; 614 616 /** Pointer to the USB device instance which the LUN belongs to. */ … … 698 700 /** The search path for ring-0 context modules (';' as separator). */ 699 701 char *pszR0SearchPath; 702 /** Pointer to chain of instances. */ 703 PPDMDRVINSR3 pInstances; 700 704 } PDMDRV; 701 705 … … 1464 1468 * concurrently. */ 1465 1469 PDMCRITSECT NopCritSect; 1470 /** Critical read/write section protecting the core list: devices, 1471 * usb devices, drivers. 1472 * @note The PDMUSERPERVM::ListCritSect lock covers queues and the stuff in 1473 * PDMUSERPERVM. */ 1474 RTCRITSECTRW CoreListCritSectRw; 1466 1475 1467 1476 /** The ring-0 capable task sets (max 128). */ … … 1504 1513 /** The registered RTC device. */ 1505 1514 R3PTRTYPE(PPDMRTC) pRtc; 1506 /** The registered USB HUBs. (FIFO) */ 1515 /** The registered USB HUBs. (FIFO) 1516 * @note Protected by CoreListCritSectRw. */ 1507 1517 R3PTRTYPE(PPDMUSBHUB) pUsbHubs; 1508 1518 1509 1519 /** @name Queues 1520 * @note Protected by PDMUSERPERVM::ListCritSect. 1510 1521 * @{ */ 1511 1522 /** Number of ring-0 capable queues in apQueues. */ … … 1652 1663 /** @todo move more stuff over here. */ 1653 1664 1654 /** Lock protecting the lists below it and the queue list . */1665 /** Lock protecting the lists below it and the queue list (in PDM). */ 1655 1666 RTCRITSECT ListCritSect; 1656 1667 /** Pointer to list of loaded modules. */ … … 1772 1783 int pdmR3DrvInstantiate(PVM pVM, PCFGMNODE pNode, PPDMIBASE pBaseInterface, PPDMDRVINS pDrvAbove, 1773 1784 PPDMLUN pLun, PPDMIBASE *ppBaseInterface); 1774 int pdmR3DrvDetach(P PDMDRVINS pDrvIns, uint32_t fFlags);1775 void pdmR3DrvDestroyChain(P PDMDRVINS pDrvIns, uint32_t fFlags);1785 int pdmR3DrvDetach(PVM pVM, PPDMDRVINS pDrvIns, uint32_t fFlags); 1786 void pdmR3DrvDestroyChain(PVM pVM, PPDMDRVINS pDrvIns, uint32_t fFlags); 1776 1787 PPDMDRV pdmR3DrvLookup(PVM pVM, const char *pszName); 1777 1788
Note:
See TracChangeset
for help on using the changeset viewer.