VirtualBox

Ignore:
Timestamp:
Sep 8, 2010 3:00:46 PM (14 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
65664
Message:

Guest Additions/common: Make NT4 legacy driver build. Moved more code to common base.

File:
1 edited

Legend:

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

    r32317 r32322  
    171171        pDrvObj->MajorFunction[IRP_MJ_WRITE]                   = vboxguestwinNotSupportedStub;
    172172#ifdef TARGET_NT4
    173         rc = vboxguestwinNT4CreateDevice(pDrvObj, NULL /* pDevObj */, pRegPath);
     173        rc = vboxguestwinnt4CreateDevice(pDrvObj, NULL /* pDevObj */, pRegPath);
    174174#else
    175175        pDrvObj->MajorFunction[IRP_MJ_PNP]                     = vboxguestwinPnP;
     
    274274
    275275/**
     276 * Debug helper to dump a device resource list.
     277 *
     278 * @param pResourceList  list of device resources.
     279 */
     280static VOID vboxguestwinShowDeviceResources(PCM_PARTIAL_RESOURCE_LIST pResourceList)
     281{
     282#ifdef LOG_ENABLED
     283    PCM_PARTIAL_RESOURCE_DESCRIPTOR resource = pResourceList->PartialDescriptors;
     284    ULONG nres = pResourceList->Count;
     285    ULONG i;
     286
     287    for (i = 0; i < nres; ++i, ++resource)
     288    {
     289        ULONG uType = resource->Type;
     290        static char* aszName[] =
     291        {
     292            "CmResourceTypeNull",
     293            "CmResourceTypePort",
     294            "CmResourceTypeInterrupt",
     295            "CmResourceTypeMemory",
     296            "CmResourceTypeDma",
     297            "CmResourceTypeDeviceSpecific",
     298            "CmResourceTypeBusNumber",
     299            "CmResourceTypeDevicePrivate",
     300            "CmResourceTypeAssignedResource",
     301            "CmResourceTypeSubAllocateFrom",
     302        };
     303
     304        Log(("VBoxGuest::vboxguestwinShowDeviceResources: Type %s",
     305               uType < (sizeof(aszName) / sizeof(aszName[0]))
     306             ? aszName[uType] : "Unknown"));
     307
     308        switch (uType)
     309        {
     310            case CmResourceTypePort:
     311            case CmResourceTypeMemory:
     312                Log(("VBoxGuest::vboxguestwinShowDeviceResources: Start %8X%8.8lX length %X\n",
     313                         resource->u.Port.Start.HighPart, resource->u.Port.Start.LowPart,
     314                         resource->u.Port.Length));
     315                break;
     316
     317            case CmResourceTypeInterrupt:
     318                Log(("VBoxGuest::vboxguestwinShowDeviceResources: Level %X, Vector %X, Affinity %X\n",
     319                         resource->u.Interrupt.Level, resource->u.Interrupt.Vector,
     320                         resource->u.Interrupt.Affinity));
     321                break;
     322
     323            case CmResourceTypeDma:
     324                Log(("VBoxGuest::vboxguestwinShowDeviceResources: Channel %d, Port %X\n",
     325                         resource->u.Dma.Channel, resource->u.Dma.Port));
     326                break;
     327
     328            default:
     329                Log(("\n"));
     330                break;
     331        }
     332    }
     333#endif
     334}
     335
     336
     337/**
     338 * Global initialisation stuff (PnP + NT4 legacy).
     339 *
     340 * @param  pDevObj    Device object.
     341 * @param  pIrp       Request packet.
     342 */
     343#ifndef TARGET_NT4
     344NTSTATUS vboxguestwinInit(PDEVICE_OBJECT pDevObj, PIRP pIrp)
     345#else
     346NTSTATUS vboxguestwinInit(PDRIVER_OBJECT pDrvObj, PDEVICE_OBJECT pDevObj, PUNICODE_STRING pRegPath)
     347#endif
     348{
     349    PVBOXGUESTDEVEXT pDevExt   = (PVBOXGUESTDEVEXT)pDevObj->DeviceExtension;
     350#ifndef TARGET_NT4
     351    PIO_STACK_LOCATION pStack  = IoGetCurrentIrpStackLocation(pIrp);
     352#endif
     353
     354    Log(("VBoxGuest::vboxguestwinInit\n"));
     355
     356    int rc = STATUS_SUCCESS;
     357#ifdef TARGET_NT4
     358    /*
     359     * Let's have a look at what our PCI adapter offers.
     360     */
     361    Log(("VBoxGuest::vboxguestwinInit: Starting to scan PCI resources of VBoxGuest ...\n"));
     362
     363    /* Assign the PCI resources. */
     364    PCM_RESOURCE_LIST pResourceList = NULL;
     365    UNICODE_STRING classNameString;
     366    RtlInitUnicodeString(&classNameString, L"VBoxGuestAdapter");
     367    rc = HalAssignSlotResources(pRegPath, &classNameString,
     368                                pDrvObj, pDevObj,
     369                                PCIBus, pDevExt->win.s.busNumber, pDevExt->win.s.slotNumber,
     370                                &pResourceList);
     371    if (pResourceList && pResourceList->Count > 0)
     372        vboxguestwinShowDeviceResources(&pResourceList->List[0].PartialResourceList);
     373    if (NT_SUCCESS(rc))
     374        rc = vboxguestwinScanPCIResourceList(pResourceList, pDevExt);
     375#else
     376    if (pStack->Parameters.StartDevice.AllocatedResources->Count > 0)
     377        vboxguestwinShowDeviceResources(&pStack->Parameters.StartDevice.AllocatedResources->List[0].PartialResourceList);
     378    if (NT_SUCCESS(rc))
     379        rc = vboxguestwinScanPCIResourceList(pStack->Parameters.StartDevice.AllocatedResourcesTranslated,
     380                                             pDevExt);
     381#endif
     382    if (NT_SUCCESS(rc))
     383    {
     384        /*
     385         * Map physical address of VMMDev memory into MMIO region
     386         * and init the common device extension bits.
     387         */
     388        void *pvMMIOBase = NULL;
     389        uint32_t cbMMIO = 0;
     390        rc = vboxguestwinMapVMMDevMemory(pDevExt,
     391                                         pDevExt->win.s.vmmDevPhysMemoryAddress,
     392                                         pDevExt->win.s.vmmDevPhysMemoryLength,
     393                                         &pvMMIOBase,
     394                                         &cbMMIO);
     395        if (NT_SUCCESS(rc))
     396        {
     397            pDevExt->pVMMDevMemory = (VMMDevMemory *)pvMMIOBase;
     398
     399            Log(("VBoxGuest::vboxguestwinInit: pvMMIOBase = 0x%p, pDevExt = 0x%p, pDevExt->pVMMDevMemory = 0x%p\n",
     400                 pvMMIOBase, pDevExt, pDevExt ? pDevExt->pVMMDevMemory : NULL));
     401
     402            int vrc = VBoxGuestInitDevExt(pDevExt,
     403                                          pDevExt->IOPortBase,
     404                                          pvMMIOBase, cbMMIO,
     405                                          vboxguestwinVersionToOSType(g_winVersion),
     406                                          VMMDEV_EVENT_MOUSE_POSITION_CHANGED);
     407            if (RT_FAILURE(vrc))
     408            {
     409                Log(("VBoxGuest::vboxguestwinInit: Could not init device extension, rc = %Rrc!\n", vrc));
     410                rc = STATUS_DEVICE_CONFIGURATION_ERROR;
     411            }
     412        }
     413        else
     414            Log(("VBoxGuest::vboxguestwinInit: Could not map physical address of VMMDev, rc = 0x%x!\n", rc));
     415    }
     416
     417    if (NT_SUCCESS(rc))
     418    {
     419        int vrc = VbglGRAlloc((VMMDevRequestHeader **)&pDevExt->win.s.pPowerStateRequest,
     420                              sizeof (VMMDevPowerStateRequest), VMMDevReq_SetPowerStatus);
     421        if (RT_FAILURE(vrc))
     422        {
     423            Log(("VBoxGuest::vboxguestwinInit: Alloc for pPowerStateRequest failed, rc = %Rrc\n", vrc));
     424            rc = STATUS_UNSUCCESSFUL;
     425        }
     426    }
     427
     428    if (NT_SUCCESS(rc))
     429    {
     430        /*
     431         * Register DPC and ISR.
     432         */
     433        Log(("VBoxGuest::vboxguestwinInit: Initializing DPC/ISR ...\n"));
     434
     435        IoInitializeDpcRequest(pDevExt->win.s.pDeviceObject, vboxguestwinDpcHandler);
     436#ifdef TARGET_NT4
     437        /* Get an interrupt vector. */
     438        /* Only proceed if the device provides an interrupt. */
     439        if (   pDevExt->win.s.interruptLevel
     440            || pDevExt->win.s.interruptVector)
     441        {
     442            pDevExt->win.s.interruptVector = HalGetInterruptVector(PCIBus,
     443                                                                   pDevExt->win.s.busNumber,
     444                                                                   pDevExt->win.s.interruptLevel,
     445                                                                   pDevExt->win.s.interruptVector,
     446                                                                   (PKIRQL)pDevExt->win.s.interruptLevel,
     447                                                                   &pDevExt->win.s.interruptAffinity);
     448        }
     449        else
     450            Log(("VBoxGuest::vboxguestwinInit: Device does not provide an interrupt!\n"));
     451#endif
     452        if (pDevExt->win.s.interruptVector)
     453        {
     454            rc = IoConnectInterrupt(&pDevExt->win.s.pInterruptObject,          /* Out: interrupt object. */
     455                                    (PKSERVICE_ROUTINE)vboxguestwinIsrHandler, /* Our ISR handler. */
     456                                    pDevExt,                                   /* Device context. */
     457                                    NULL,                                      /* Optional spinlock. */
     458                                    pDevExt->win.s.interruptVector,            /* Interrupt vector. */
     459                                    (KIRQL)pDevExt->win.s.interruptLevel,      /* Interrupt level. */
     460                                    (KIRQL)pDevExt->win.s.interruptLevel,      /* Interrupt level. */
     461                                    pDevExt->win.s.interruptMode,              /* LevelSensitive or Latched. */
     462                                    TRUE,                                      /* Shareable interrupt. */
     463                                    pDevExt->win.s.interruptAffinity,          /* CPU affinity. */
     464                                    FALSE);                                    /* Don't save FPU stack. */
     465            if (NT_ERROR(rc))
     466                Log(("VBoxGuest::vboxguestwinInit: Could not connect interrupt, rc = 0x%x\n", rc));
     467        }
     468        else
     469            Log(("VBoxGuest::vboxguestwinInit: No interrupt vector found!\n"));
     470    }
     471
     472
     473#ifdef VBOX_WITH_HGCM
     474    /* Initialize the HGCM event notification semaphore. */
     475    KeInitializeEvent(&pDevExt->win.s.hgcm.s.keventNotification, NotificationEvent, FALSE);
     476
     477    /* Preallocated constant timeout 250ms for HGCM async waiter. */
     478    pDevExt->win.s.hgcm.s.WaitTimeout.QuadPart  = 250;
     479    pDevExt->win.s.hgcm.s.WaitTimeout.QuadPart *= -10000; /* Relative in 100ns units. */
     480
     481    int vrc = VBoxGuestCreateKernelSession(pDevExt, &pDevExt->win.s.pKernelSession);
     482    if (RT_FAILURE(vrc))
     483    {
     484        Log(("VBoxGuest::vboxguestwinInit: Failed to allocated kernel session data! rc = %Rrc\n", rc));
     485        rc = STATUS_UNSUCCESSFUL;
     486    }
     487#endif
     488
     489    if (RT_SUCCESS(rc))
     490    {
     491        /* Ready to rumble! */
     492        Log(("VBoxGuest::vboxguestwinInit: Device is ready!\n"));
     493        pDevExt->win.s.devState = WORKING;
     494    }
     495
     496    Log(("VBoxGuest::vboxguestwinInit: Returned with rc = 0x%x\n", rc));
     497    return rc;
     498}
     499
     500
     501/**
    276502 * Cleans up all data (like device extension and guest mapping).
    277503 *
    278504 * @param   pDrvObj     Driver object.
    279  * @param   pIrp        Request packet.
    280  */
    281 NTSTATUS vboxguestwinCleanup(PDEVICE_OBJECT pDevObj, PIRP pIrp)
     505 */
     506NTSTATUS vboxguestwinCleanup(PDEVICE_OBJECT pDevObj)
    282507{
    283508    Log(("VBoxGuest::vboxguestwinCleanup\n"));
    284509
    285     NOREF(pIrp);
    286510    PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pDevObj->DeviceExtension;
    287 
    288511    if (pDevExt)
    289512    {
     513#ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
     514        hlpDeregisterBugCheckCallback(pDevExt); /* ignore failure! */
     515#endif
    290516        /* According to MSDN we have to unmap previously mapped memory. */
    291517        vboxguestwinUnmapVMMDevMemory(pDevExt);
     
    307533    Log(("VBoxGuest::vboxguestwinGuestUnload\n"));
    308534#ifdef TARGET_NT4
    309     PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pDrvObj->DeviceObject->DeviceExtension;
    310     unreserveHypervisorMemory(pDevExt);
    311 
    312     hlpVBoxUnmapVMMDevMemory (pDevExt);
    313 
    314     VBoxCleanupMemBalloon(pDevExt);
    315 
    316 #ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
    317     hlpDeregisterBugCheckCallback(pDevExt); /* ignore failure! */
    318 #endif
    319 
     535    vboxguestwinCleanup(pDrvObj->DeviceObject);
    320536    /*
    321537     * I don't think it's possible to unload a driver which processes have
     
    508724        /* Add at least one (bogus) fall through case to shut up MSVC! */
    509725        case 0:
    510 #endif
    511 
    512 #if 0
    513 #ifdef VBOX_WITH_MANAGEMENT
    514         case VBOXGUEST_IOCTL_CHECK_BALLOON:
    515         {
    516             VBoxGuestCheckBalloonInfo *pInfo = (VBoxGuestCheckBalloonInfo *)pBuf;
    517 
    518             if (pStack->Parameters.DeviceIoControl.OutputBufferLength != sizeof(VBoxGuestCheckBalloonInfo))
    519             {
    520                 Log(("VBoxGuest::vboxguestwinGuestDeviceControl: OutputBufferLength %d != sizeof(ULONG) %d\n",
    521                          pStack->Parameters.DeviceIoControl.OutputBufferLength, sizeof(VBoxGuestCheckBalloonInfo)));
    522                 Status = STATUS_INVALID_PARAMETER;
    523                 break;
    524             }
    525 
    526             ULONG cMemoryBalloonChunks;
    527             int rc = VBoxGuestQueryMemoryBalloon(pDevExt, &cMemoryBalloonChunks);
    528             if (RT_FAILURE(rc))
    529             {
    530                 Log(("VBOXGUEST_IOCTL_CHECK_BALLOON: vbox rc = %Rrc\n", rc));
    531                 Status = STATUS_UNSUCCESSFUL;
    532             }
    533             else
    534             {
    535                 cbOut = pStack->Parameters.DeviceIoControl.OutputBufferLength;
    536                 pInfo->cBalloonChunks = cMemoryBalloonChunks;
    537                 pInfo->fHandleInR3 = false;
    538             }
    539             break;
    540         }
    541 #endif
    542 
    543         case VBOXGUEST_IOCTL_LOG(0):    /* The size isn't relevant on NT. */
    544         {
    545             /* Enable this only for debugging:
    546             Log(("VBoxGuest::vboxguestwinGuestDeviceControl: VBOXGUEST_IOCTL_LOG %.*s\n", (int)pStack->Parameters.DeviceIoControl.InputBufferLength, pBuf));
    547              */
    548             LogRel(("%.*s", (int)pStack->Parameters.DeviceIoControl.InputBufferLength, pBuf));
    549             cbOut = 0;
    550             break;
    551         }
    552726#endif
    553727        default:
Note: See TracChangeset for help on using the changeset viewer.

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