VirtualBox

Changeset 70104 in vbox for trunk/src/VBox


Ignore:
Timestamp:
Dec 13, 2017 10:22:57 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
119652
Message:

VBoxGuest-win.cpp: style + cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Additions/common/VBoxGuest/VBoxGuest-win.cpp

    r70103 r70104  
    6565*   Structures and Typedefs                                                                                                      *
    6666*********************************************************************************************************************************/
    67 /** Possible device states for our state machine. */
     67/**
     68 * Possible device states for our state machine.
     69 */
    6870typedef enum VGDRVNTDEVSTATE
    6971{
     
    7577    VGDRVNTDEVSTATE_REMOVED
    7678} VGDRVNTDEVSTATE;
     79
    7780
    7881typedef struct VBOXGUESTWINBASEADDRESS
     
    9093    /** Flag: resource is mapped (i.e. MmMapIoSpace called). */
    9194    BOOLEAN ResourceMapped;
    92 } VBOXGUESTWINBASEADDRESS, *PVBOXGUESTWINBASEADDRESS;
    93 
    94 
    95 /** Windows-specific device extension bits. */
     95} VBOXGUESTWINBASEADDRESS;
     96typedef VBOXGUESTWINBASEADDRESS *PVBOXGUESTWINBASEADDRESS;
     97
     98
     99/**
     100 * Subclassing the device extension for adding windows-specific bits.
     101 */
    96102typedef struct VBOXGUESTDEVEXTWIN
    97103{
    98     VBOXGUESTDEVEXT Core;
     104    /** The common device extension core. */
     105    VBOXGUESTDEVEXT         Core;
    99106
    100107    /** Our functional driver object. */
    101     PDEVICE_OBJECT pDeviceObject;
     108    PDEVICE_OBJECT          pDeviceObject;
    102109    /** Top of the stack. */
    103     PDEVICE_OBJECT pNextLowerDriver;
     110    PDEVICE_OBJECT          pNextLowerDriver;
    104111    /** Currently active Irp. */
    105     IRP *pCurrentIrp;
     112    IRP                    *pCurrentIrp;
    106113    /** Interrupt object pointer. */
    107     PKINTERRUPT pInterruptObject;
     114    PKINTERRUPT             pInterruptObject;
    108115
    109116    /** Bus number where the device is located. */
    110     ULONG busNumber;
     117    ULONG                   uBus;
    111118    /** Slot number where the device is located. */
    112     ULONG slotNumber;
     119    ULONG                   uSlot;
    113120    /** Device interrupt level. */
    114     ULONG interruptLevel;
     121    ULONG                   uInterruptLevel;
    115122    /** Device interrupt vector. */
    116     ULONG interruptVector;
     123    ULONG                   uInterruptVector;
    117124    /** Affinity mask. */
    118     KAFFINITY interruptAffinity;
     125    KAFFINITY               fInterruptAffinity;
    119126    /** LevelSensitive or Latched. */
    120     KINTERRUPT_MODE interruptMode;
     127    KINTERRUPT_MODE         enmInterruptMode;
    121128
    122129    /** PCI base address information. */
    123     ULONG pciAddressCount;
    124     VBOXGUESTWINBASEADDRESS pciBaseAddress[PCI_TYPE0_ADDRESSES];
     130    ULONG                   cPciAddresses;
     131    VBOXGUESTWINBASEADDRESS aPciBaseAddresses[PCI_TYPE0_ADDRESSES];
    125132
    126133    /** Physical address and length of VMMDev memory. */
    127     PHYSICAL_ADDRESS vmmDevPhysMemoryAddress;
    128     ULONG vmmDevPhysMemoryLength;
     134    PHYSICAL_ADDRESS        uVmmDevMemoryPhysAddr;
     135    /** Length of VMMDev memory.   */
     136    ULONG                   cbVmmDevMemory;
    129137
    130138    /** Device state. */
    131     VGDRVNTDEVSTATE enmDevState;
    132     /** The previous device state.   */
    133     VGDRVNTDEVSTATE enmPrevDevState;
     139    VGDRVNTDEVSTATE         enmDevState;
     140    /** The previous device state. */
     141    VGDRVNTDEVSTATE         enmPrevDevState;
    134142
    135143    /** Last system power action set (see VBoxGuestPower). */
    136     POWER_ACTION LastSystemPowerAction;
     144    POWER_ACTION            enmLastSystemPowerAction;
    137145    /** Preallocated generic request for shutdown. */
    138146    VMMDevPowerStateRequest *pPowerStateRequest;
    139147    /** Preallocated VMMDevEvents for IRQ handler. */
    140     VMMDevEvents *pIrqAckEvents;
    141 
    142     /** Pre-allocated kernel session data. This is needed
    143      * for handling kernel IOCtls. */
    144     struct VBOXGUESTSESSION *pKernelSession;
     148    VMMDevEvents           *pIrqAckEvents;
    145149
    146150    /** Spinlock protecting MouseNotifyCallback. Required since the consumer is
    147151     *  in a DPC callback and not the ISR. */
    148     KSPIN_LOCK MouseEventAccessLock;
    149 } VBOXGUESTDEVEXTWIN, *PVBOXGUESTDEVEXTWIN;
     152    KSPIN_LOCK              MouseEventAccessSpinLock;
     153} VBOXGUESTDEVEXTWIN;
     154typedef VBOXGUESTDEVEXTWIN *PVBOXGUESTDEVEXTWIN;
    150155
    151156
     
    172177RT_C_DECLS_BEGIN
    173178#ifdef TARGET_NT4
    174 static NTSTATUS vgdrvNt4FindPciDevice(PULONG pulBusNumber, PPCI_SLOT_NUMBER pSlotNumber);
     179static NTSTATUS vgdrvNt4FindPciDevice(PULONG puluBusNumber, PPCI_SLOT_NUMBER puSlotNumber);
    175180static NTSTATUS vgdrvNt4CreateDevice(PDRIVER_OBJECT pDrvObj, PUNICODE_STRING pRegPath);
    176181#else
     
    462467            "CmResourceTypeDma",
    463468            "CmResourceTypeDeviceSpecific",
    464             "CmResourceTypeBusNumber",
     469            "CmResourceTypeuBusNumber",
    465470            "CmResourceTypeDevicePrivate",
    466471            "CmResourceTypeAssignedResource",
     
    528533    RtlInitUnicodeString(&classNameString, L"VBoxGuestAdapter");
    529534    rcNt = HalAssignSlotResources(pRegPath, &classNameString, pDrvObj, pDevObj,
    530                                   PCIBus, pDevExt->busNumber, pDevExt->slotNumber, &pResourceList);
     535                                  PCIBus, pDevExt->uBus, pDevExt->uSlot, &pResourceList);
    531536# ifdef LOG_ENABLED
    532537    if (pResourceList && pResourceList->Count > 0)
     
    551556        uint32_t cbMMIO = 0;
    552557        rcNt = vgdrvNtMapVMMDevMemory(pDevExt,
    553                                       pDevExt->vmmDevPhysMemoryAddress,
    554                                       pDevExt->vmmDevPhysMemoryLength,
     558                                      pDevExt->uVmmDevMemoryPhysAddr,
     559                                      pDevExt->cbVmmDevMemory,
    555560                                      &pvMMIOBase,
    556561                                      &cbMMIO);
     
    601606        /* Get an interrupt vector. */
    602607        /* Only proceed if the device provides an interrupt. */
    603         if (   pDevExt->interruptLevel
    604             || pDevExt->interruptVector)
     608        if (   pDevExt->uInterruptLevel
     609            || pDevExt->uInterruptVector)
    605610        {
    606611            LogFlowFunc(("Getting interrupt vector (HAL): Bus=%u, IRQL=%u, Vector=%u\n",
    607                          pDevExt->busNumber, pDevExt->interruptLevel, pDevExt->interruptVector));
     612                         pDevExt->uBus, pDevExt->uInterruptLevel, pDevExt->uInterruptVector));
    608613
    609614            uInterruptVector = HalGetInterruptVector(PCIBus,
    610                                                      pDevExt->busNumber,
    611                                                      pDevExt->interruptLevel,
    612                                                      pDevExt->interruptVector,
     615                                                     pDevExt->uBus,
     616                                                     pDevExt->uInterruptLevel,
     617                                                     pDevExt->uInterruptVector,
    613618                                                     &irqLevel,
    614                                                      &pDevExt->interruptAffinity);
     619                                                     &pDevExt->fInterruptAffinity);
    615620            LogFlowFunc(("HalGetInterruptVector returns vector=%u\n", uInterruptVector));
    616621            if (uInterruptVector == 0)
     
    620625            LogFunc(("Device does not provide an interrupt!\n"));
    621626#endif
    622         if (pDevExt->interruptVector)
     627        if (pDevExt->uInterruptVector)
    623628        {
    624629#ifdef TARGET_NT4
    625630            LogFlowFunc(("Connecting interrupt (IntVector=%#u), IrqLevel=%u) ...\n", uInterruptVector, irqLevel));
    626631#else
    627             LogFlowFunc(("Connecting interrupt (IntVector=%#u), IrqLevel=%u) ...\n", pDevExt->interruptVector, pDevExt->interruptLevel));
     632            LogFlowFunc(("Connecting interrupt (IntVector=%#u), IrqLevel=%u) ...\n", pDevExt->uInterruptVector, pDevExt->uInterruptLevel));
    628633#endif
    629634
     
    637642                                      irqLevel,                                   /* Interrupt level. */
    638643#else
    639                                       pDevExt->interruptVector,                   /* Interrupt vector. */
    640                                       (KIRQL)pDevExt->interruptLevel,             /* Interrupt level. */
    641                                       (KIRQL)pDevExt->interruptLevel,             /* Interrupt level. */
     644                                      pDevExt->uInterruptVector,                   /* Interrupt vector. */
     645                                      (KIRQL)pDevExt->uInterruptLevel,             /* Interrupt level. */
     646                                      (KIRQL)pDevExt->uInterruptLevel,             /* Interrupt level. */
    642647#endif
    643                                       pDevExt->interruptMode,                     /* LevelSensitive or Latched. */
     648                                      pDevExt->enmInterruptMode,                     /* LevelSensitive or Latched. */
    644649                                      TRUE,                                       /* Shareable interrupt. */
    645                                       pDevExt->interruptAffinity,                 /* CPU affinity. */
     650                                      pDevExt->fInterruptAffinity,                 /* CPU affinity. */
    646651                                      FALSE);                                     /* Don't save FPU stack. */
    647652            if (NT_ERROR(rcNt))
     
    694699     * Find our virtual PCI device
    695700     */
    696     ULONG uBusNumber;
    697     PCI_SLOT_NUMBER SlotNumber;
    698     NTSTATUS rc = vgdrvNt4FindPciDevice(&uBusNumber, &SlotNumber);
     701    ULONG uuBusNumber;
     702    PCI_SLOT_NUMBER uSlot;
     703    NTSTATUS rc = vgdrvNt4FindPciDevice(&uuBusNumber, &uSlot);
    699704    if (NT_ERROR(rc))
    700705    {
     
    735740
    736741            /* Store bus and slot number we've queried before. */
    737             pDevExt->busNumber  = uBusNumber;
    738             pDevExt->slotNumber = SlotNumber.u.AsULONG;
     742            pDevExt->uBus  = uuBusNumber;
     743            pDevExt->uSlot = uSlot.u.AsULONG;
    739744
    740745#ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
     
    772777 * @returns NT status code.
    773778 *
    774  * @param   pulBusNumber    Where to return the bus number on success.
    775  * @param   pSlotNumber     Where to return the slot number on success.
    776  */
    777 static NTSTATUS vgdrvNt4FindPciDevice(PULONG pulBusNumber, PPCI_SLOT_NUMBER pSlotNumber)
     779 * @param   puluBusNumber    Where to return the bus number on success.
     780 * @param   puSlotNumber     Where to return the slot number on success.
     781 */
     782static NTSTATUS vgdrvNt4FindPciDevice(PULONG puluBusNumber, PPCI_SLOT_NUMBER puSlotNumber)
    778783{
    779784    Log(("vgdrvNt4FindPciDevice\n"));
    780785
    781     PCI_SLOT_NUMBER SlotNumber;
    782     SlotNumber.u.AsULONG = 0;
     786    PCI_SLOT_NUMBER uSlot;
     787    uSlot.u.AsULONG = 0;
    783788
    784789    /* Scan each bus. */
    785     for (ULONG ulBusNumber = 0; ulBusNumber < PCI_MAX_BUSES; ulBusNumber++)
     790    for (ULONG uluBusNumber = 0; uluBusNumber < PCI_MAX_BUSES; uluBusNumber++)
    786791    {
    787792        /* Scan each device. */
    788793        for (ULONG deviceNumber = 0; deviceNumber < PCI_MAX_DEVICES; deviceNumber++)
    789794        {
    790             SlotNumber.u.bits.DeviceNumber = deviceNumber;
     795            uSlot.u.bits.DeviceNumber = deviceNumber;
    791796
    792797            /* Scan each function (not really required...). */
    793798            for (ULONG functionNumber = 0; functionNumber < PCI_MAX_FUNCTION; functionNumber++)
    794799            {
    795                 SlotNumber.u.bits.FunctionNumber = functionNumber;
     800                uSlot.u.bits.FunctionNumber = functionNumber;
    796801
    797802                /* Have a look at what's in this slot. */
    798803                PCI_COMMON_CONFIG PciData;
    799                 if (!HalGetBusData(PCIConfiguration, ulBusNumber, SlotNumber.u.AsULONG, &PciData, sizeof(ULONG)))
     804                if (!HalGetBusData(PCIConfiguration, uluBusNumber, uSlot.u.AsULONG, &PciData, sizeof(ULONG)))
    800805                {
    801806                    /* No such bus, we're done with it. */
     
    816821                Log(("vgdrvNt4FindPciDevice: Device found!\n"));
    817822
    818                 *pulBusNumber = ulBusNumber;
    819                 *pSlotNumber  = SlotNumber;
     823                *puluBusNumber = uluBusNumber;
     824                *puSlotNumber  = uSlot;
    820825                return STATUS_SUCCESS;
    821826            }
     
    865870            RT_ZERO(*pDevExt);
    866871
    867             KeInitializeSpinLock(&pDevExt->MouseEventAccessLock);
     872            KeInitializeSpinLock(&pDevExt->MouseEventAccessSpinLock);
    868873
    869874            pDevExt->pDeviceObject   = pDeviceObject;
     
    13371342                            {
    13381343                                if (   pDevExt
    1339                                     && pDevExt->LastSystemPowerAction == PowerActionHibernate)
     1344                                    && pDevExt->enmLastSystemPowerAction == PowerActionHibernate)
    13401345                                {
    13411346                                    Log(("vgdrvNtNt5PlusPower: Returning from hibernation!\n"));
     
    14211426                     */
    14221427                    if (pDevExt)
    1423                         pDevExt->LastSystemPowerAction = enmPowerAction;
     1428                        pDevExt->enmLastSystemPowerAction = enmPowerAction;
    14241429
    14251430                    break;
     
    14871492    if (pDevExt->Core.pVMMDevMemory)
    14881493    {
    1489         MmUnmapIoSpace((void*)pDevExt->Core.pVMMDevMemory, pDevExt->vmmDevPhysMemoryLength);
     1494        MmUnmapIoSpace((void*)pDevExt->Core.pVMMDevMemory, pDevExt->cbVmmDevMemory);
    14901495        pDevExt->Core.pVMMDevMemory = NULL;
    14911496    }
    14921497
    1493     pDevExt->vmmDevPhysMemoryAddress.QuadPart = 0;
    1494     pDevExt->vmmDevPhysMemoryLength = 0;
     1498    pDevExt->uVmmDevMemoryPhysAddr.QuadPart = 0;
     1499    pDevExt->cbVmmDevMemory = 0;
    14951500}
    14961501
     
    15161521    if (pDevExt)
    15171522    {
    1518 
    1519 #if 0 /** @todo  test & enable cleaning global session data */
    1520 #ifdef VBOX_WITH_HGCM
    1521         if (pDevExt->pKernelSession)
    1522         {
    1523             VGDrvCommonCloseSession(pDevExt, pDevExt->pKernelSession);
    1524             pDevExt->pKernelSession = NULL;
    1525         }
    1526 #endif
    1527 #endif
    1528 
    15291523        if (pDevExt->pInterruptObject)
    15301524        {
     
    19141908    /* we need a lock here to avoid concurrency with the set event functionality */
    19151909    KIRQL OldIrql;
    1916     KeAcquireSpinLock(&pDevExtWin->MouseEventAccessLock, &OldIrql);
     1910    KeAcquireSpinLock(&pDevExtWin->MouseEventAccessSpinLock, &OldIrql);
    19171911    pDevExtWin->Core.pfnMouseNotifyCallback   = pNotify->u.In.pfnNotify;
    19181912    pDevExtWin->Core.pvMouseNotifyCallbackArg = pNotify->u.In.pvUser;
    1919     KeReleaseSpinLock(&pDevExtWin->MouseEventAccessLock, OldIrql);
     1913    KeReleaseSpinLock(&pDevExtWin->MouseEventAccessSpinLock, OldIrql);
    19201914    return VINF_SUCCESS;
    19211915}
     
    19421936         * i.e. to prevent the event from destroyed while we're using it */
    19431937        Assert(KeGetCurrentIrql() == DISPATCH_LEVEL);
    1944         KeAcquireSpinLockAtDpcLevel(&pDevExt->MouseEventAccessLock);
     1938        KeAcquireSpinLockAtDpcLevel(&pDevExt->MouseEventAccessSpinLock);
    19451939
    19461940        if (pDevExt->Core.pfnMouseNotifyCallback)
    19471941            pDevExt->Core.pfnMouseNotifyCallback(pDevExt->Core.pvMouseNotifyCallbackArg);
    19481942
    1949         KeReleaseSpinLockFromDpcLevel(&pDevExt->MouseEventAccessLock);
     1943        KeReleaseSpinLockFromDpcLevel(&pDevExt->MouseEventAccessSpinLock);
    19501944    }
    19511945
     
    22192213    ULONG rangeCount = 0;
    22202214    ULONG cMMIORange = 0;
    2221     PVBOXGUESTWINBASEADDRESS pBaseAddress = pDevExt->pciBaseAddress;
     2215    PVBOXGUESTWINBASEADDRESS pBaseAddress = pDevExt->aPciBaseAddresses;
    22222216    for (ULONG i = 0; i < pResList->List->PartialResourceList.Count; i++)
    22232217    {
     
    22652259
    22662260                /* Save information. */
    2267                 pDevExt->interruptLevel    = pPartialData->u.Interrupt.Level;
    2268                 pDevExt->interruptVector   = pPartialData->u.Interrupt.Vector;
    2269                 pDevExt->interruptAffinity = pPartialData->u.Interrupt.Affinity;
     2261                pDevExt->uInterruptLevel    = pPartialData->u.Interrupt.Level;
     2262                pDevExt->uInterruptVector   = pPartialData->u.Interrupt.Vector;
     2263                pDevExt->fInterruptAffinity = pPartialData->u.Interrupt.Affinity;
    22702264
    22712265                /* Check interrupt mode. */
    22722266                if (pPartialData->Flags & CM_RESOURCE_INTERRUPT_LATCHED)
    2273                     pDevExt->interruptMode = Latched;
     2267                    pDevExt->enmInterruptMode = Latched;
    22742268                else
    2275                     pDevExt->interruptMode = LevelSensitive;
     2269                    pDevExt->enmInterruptMode = LevelSensitive;
    22762270                break;
    22772271            }
     
    22932287                    {
    22942288                        /* Save physical MMIO base + length for VMMDev. */
    2295                         pDevExt->vmmDevPhysMemoryAddress = pPartialData->u.Memory.Start;
    2296                         pDevExt->vmmDevPhysMemoryLength = (ULONG)pPartialData->u.Memory.Length;
     2289                        pDevExt->uVmmDevMemoryPhysAddr = pPartialData->u.Memory.Start;
     2290                        pDevExt->cbVmmDevMemory = (ULONG)pPartialData->u.Memory.Length;
    22972291
    22982292                        /* Save resource information. */
     
    23252319
    23262320    /* Memorize the number of resources found. */
    2327     pDevExt->pciAddressCount = rangeCount;
     2321    pDevExt->cPciAddresses = rangeCount;
    23282322    return rc;
    23292323}
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette