コード例 #1
0
ファイル: hermes_res.c プロジェクト: mc01104/CTR
void HERMESFreeResources(PHERMEScontext pCtx)
{
    CM_RESOURCE_LIST NullResourceList;
    BOOLEAN ResourceConflict;

#ifdef DEBUG
    DEBUG1("[HERMESFreeResources]\n");
#endif

    if (pCtx->InterruptObject) IoDisconnectInterrupt(pCtx->InterruptObject);
    pCtx->InterruptObject= NULL;

    //
    // Deallocate the resources.
    //
    RtlZeroMemory((PVOID)&NullResourceList, sizeof(NullResourceList));
    IoReportResourceUsage(NULL,
                          pCtx->DriverObject,
                          &NullResourceList,
                          sizeof(ULONG),
                          NULL,
                          NULL,
                          0,
                          FALSE,
                          &ResourceConflict);
}
コード例 #2
0
/**
 * Cleans up hardware resources.
 * Do not delete DevExt here.
 *
 * @param   pDrvObj     Driver object.
 */
NTSTATUS vboxguestwinCleanup(PDEVICE_OBJECT pDevObj)
{
    Log(("VBoxGuest::vboxguestwinCleanup\n"));

    PVBOXGUESTDEVEXT pDevExt = (PVBOXGUESTDEVEXT)pDevObj->DeviceExtension;
    if (pDevExt)
    {

#if 0 /* @todo: test & enable cleaning global session data */
#ifdef VBOX_WITH_HGCM
        if (pDevExt->win.s.pKernelSession)
        {
            VBoxGuestCloseSession(pDevExt, pDevExt->win.s.pKernelSession);
            pDevExt->win.s.pKernelSession = NULL;
        }
#endif
#endif

        if (pDevExt->win.s.pInterruptObject)
        {
            IoDisconnectInterrupt(pDevExt->win.s.pInterruptObject);
            pDevExt->win.s.pInterruptObject = NULL;
        }

        /* @todo: cleanup the rest stuff */


#ifdef VBOX_WITH_GUEST_BUGCHECK_DETECTION
        hlpDeregisterBugCheckCallback(pDevExt); /* ignore failure! */
#endif
        /* According to MSDN we have to unmap previously mapped memory. */
        vboxguestwinUnmapVMMDevMemory(pDevExt);
    }
    return STATUS_SUCCESS;
}
コード例 #3
0
ACPI_STATUS
AcpiOsRemoveInterruptHandler (
    UINT32                  InterruptNumber,
    ACPI_OSD_HANDLER        ServiceRoutine)
{
    DPRINT("AcpiOsRemoveInterruptHandler()\n");

    if (!ServiceRoutine)
    {
        DPRINT1("Bad parameter\n");
        return AE_BAD_PARAMETER;
    }

    if (AcpiInterruptHandlerRegistered)
    {
        IoDisconnectInterrupt(AcpiInterrupt);
        AcpiInterrupt = NULL;
        AcpiInterruptHandlerRegistered = FALSE;
    }
    else
    {
        DPRINT1("Trying to remove non-existing interrupt handler\n");
        return AE_NOT_EXIST;
    }

    return AE_OK;
}
コード例 #4
0
void DisconnectInterrupt(PDEVICE_OBJECT fdo)
{
	PLOCAL_DEVICE_INFO pdx = (PLOCAL_DEVICE_INFO)fdo->DeviceExtension;

	if (pdx->InterruptObject != NULL)
	{ 
		IoDisconnectInterrupt(pdx->InterruptObject);
		pdx->InterruptObject = NULL;
	}
}
コード例 #5
0
ファイル: floppy.c プロジェクト: HBelusca/NasuTek-Odyssey
static VOID NTAPI
Unload(PDRIVER_OBJECT DriverObject)
/*
 * FUNCTION: Unload the driver from memory
 * ARGUMENTS:
 *     DriverObject - The driver that is being unloaded
 */
{
    ULONG i,j;

    PAGED_CODE();
    UNREFERENCED_PARAMETER(DriverObject);

    TRACE_(FLOPPY, "unloading\n");

    KeSetEvent(&QueueThreadTerminate, 0, FALSE);
    KeWaitForSingleObject(QueueThreadObject, Executive, KernelMode, FALSE, 0);
    ObDereferenceObject(QueueThreadObject);

    for(i = 0; i < gNumberOfControllers; i++)
    {
        if(!gControllerInfo[i].Initialized)
            continue;

        for(j = 0; j < gControllerInfo[i].NumberOfDrives; j++)
        {
            if(!gControllerInfo[i].DriveInfo[j].Initialized)
                continue;

            if(gControllerInfo[i].DriveInfo[j].DeviceObject)
            {
                UNICODE_STRING Link;

                RtlInitUnicodeString(&Link, gControllerInfo[i].DriveInfo[j].SymLinkBuffer);
                IoDeleteSymbolicLink(&Link);

                RtlInitUnicodeString(&Link, gControllerInfo[i].DriveInfo[j].ArcPathBuffer);
                IoDeassignArcName(&Link);

                IoDeleteDevice(gControllerInfo[i].DriveInfo[j].DeviceObject);
            }
        }

        IoDisconnectInterrupt(gControllerInfo[i].InterruptObject);

        /* Power down the controller */
        if(HwPowerOff(&gControllerInfo[i]) != STATUS_SUCCESS)
        {
            WARN_(FLOPPY, "unload: warning: HwPowerOff failed\n");
        }
    }
}
コード例 #6
0
ファイル: io.c プロジェクト: GYGit/reactos
/*
 * @implemented
 */
VOID
EXPORT
NdisMDeregisterInterrupt(
    IN  PNDIS_MINIPORT_INTERRUPT    Interrupt)
/*
 * FUNCTION: Releases an interrupt vector
 * ARGUMENTS:
 *     Interrupt = Pointer to interrupt object
 */
{
    NDIS_DbgPrint(MAX_TRACE, ("Called.\n"));
    IoDisconnectInterrupt(Interrupt->InterruptObject);
    Interrupt->Miniport->RegisteredInterrupts--;

    if (Interrupt->Miniport->Interrupt == Interrupt)
        Interrupt->Miniport->Interrupt = NULL;
}
コード例 #7
0
NTSTATUS HandleRemoveDevice(PDEVICE_EXTENSION pdx, PIRP Irp)
{
	PAGED_CODE();
	KdPrint(("Enter HandleRemoveDevice\n"));

	Irp->IoStatus.Status = STATUS_SUCCESS;
	NTSTATUS status = DefaultPnpHandler(pdx, Irp);

	IoSetDeviceInterfaceState(&pdx->interfaceName, FALSE);
	RtlFreeUnicodeString(&pdx->interfaceName);

    //调用IoDetachDevice()把fdo从设备栈中脱开:
    if (pdx->NextStackDevice)
        IoDetachDevice(pdx->NextStackDevice);
	
    //删除fdo:
    IoDeleteDevice(pdx->fdo);

	//删除中断
	IoDisconnectInterrupt(pdx->InterruptObject);
	KdPrint(("Leave HandleRemoveDevice\n"));
	return status;
}
コード例 #8
0
ファイル: floppy.c プロジェクト: HBelusca/NasuTek-Odyssey
static BOOLEAN NTAPI
AddControllers(PDRIVER_OBJECT DriverObject)
/*
 * FUNCTION: Called on initialization to find our controllers and build device and controller objects for them
 * ARGUMENTS:
 *     DriverObject: Our driver's DriverObject (so we can create devices against it)
 * RETURNS:
 *     FALSE if we can't allocate a device, adapter, or interrupt object, or if we fail to find any controllers
 *     TRUE otherwise (i.e. we have at least one fully-configured controller)
 * NOTES:
 *     - Currently we only support ISA buses.
 *     - BUG: Windows 2000 seems to clobber the response from the IoQueryDeviceDescription callback, so now we
 *       just test a boolean value in the first object to see if it was completely populated.  The same value
 *       is tested for each controller before we build device objects for it.
 * TODO:
 *     - Report resource usage to the HAL
 */
{
    INTERFACE_TYPE InterfaceType = Isa;
    CONFIGURATION_TYPE ControllerType = DiskController;
    CONFIGURATION_TYPE PeripheralType = FloppyDiskPeripheral;
    KAFFINITY Affinity;
    DEVICE_DESCRIPTION DeviceDescription;
    UCHAR i;
    UCHAR j;

    PAGED_CODE();

    /* Find our controllers on all ISA buses */
    IoQueryDeviceDescription(&InterfaceType, 0, &ControllerType, 0, &PeripheralType, 0, ConfigCallback, 0);

    /*
     * w2k breaks the return val from ConfigCallback, so we have to hack around it, rather than just
     * looking for a return value from ConfigCallback.  We expect at least one controller.
     */
    if(!gControllerInfo[0].Populated)
    {
        WARN_(FLOPPY, "AddControllers: failed to get controller info from registry\n");
        return FALSE;
    }

    /* Now that we have a controller, set it up with the system */
    for(i = 0; i < gNumberOfControllers; i++)
    {
        /* 0: Report resource usage to the kernel, to make sure they aren't assigned to anyone else */
        /* FIXME: Implement me. */

        /* 1: Set up interrupt */
        gControllerInfo[i].MappedVector = HalGetInterruptVector(gControllerInfo[i].InterfaceType, gControllerInfo[i].BusNumber,
                                          gControllerInfo[i].Level, gControllerInfo[i].Vector,
                                          &gControllerInfo[i].MappedLevel, &Affinity);

        /* Must set up the DPC before we connect the interrupt */
        KeInitializeDpc(&gControllerInfo[i].Dpc, DpcForIsr, &gControllerInfo[i]);

        INFO_(FLOPPY, "Connecting interrupt %d to controller%d (object 0x%p)\n", gControllerInfo[i].MappedVector,
              i, &gControllerInfo[i]);

        /* NOTE: We cannot share our interrupt, even on level-triggered buses.  See Isr() for details. */
        if(IoConnectInterrupt(&gControllerInfo[i].InterruptObject, Isr, &gControllerInfo[i], 0, gControllerInfo[i].MappedVector,
                              gControllerInfo[i].MappedLevel, gControllerInfo[i].MappedLevel, gControllerInfo[i].InterruptMode,
                              FALSE, Affinity, 0) != STATUS_SUCCESS)
        {
            WARN_(FLOPPY, "AddControllers: unable to connect interrupt\n");
            continue;
        }

        /* 2: Set up DMA */
        memset(&DeviceDescription, 0, sizeof(DeviceDescription));
        DeviceDescription.Version = DEVICE_DESCRIPTION_VERSION;
        DeviceDescription.DmaChannel = gControllerInfo[i].Dma;
        DeviceDescription.InterfaceType = gControllerInfo[i].InterfaceType;
        DeviceDescription.BusNumber = gControllerInfo[i].BusNumber;
        DeviceDescription.MaximumLength = 2*18*512; /* based on a 1.44MB floppy */

        /* DMA 0,1,2,3 are 8-bit; 4,5,6,7 are 16-bit (4 is chain i think) */
        DeviceDescription.DmaWidth = gControllerInfo[i].Dma > 3 ? Width16Bits: Width8Bits;

        gControllerInfo[i].AdapterObject = HalGetAdapter(&DeviceDescription, &gControllerInfo[i].MapRegisters);

        if(!gControllerInfo[i].AdapterObject)
        {
            WARN_(FLOPPY, "AddControllers: unable to allocate an adapter object\n");
            IoDisconnectInterrupt(gControllerInfo[i].InterruptObject);
            continue;
        }

        /* 2b: Initialize the new controller */
        if(InitController(&gControllerInfo[i]) != STATUS_SUCCESS)
        {
            WARN_(FLOPPY, "AddControllers(): Unable to set up controller %d - initialization failed\n", i);
            IoDisconnectInterrupt(gControllerInfo[i].InterruptObject);
            continue;
        }

        /* 2c: Set the controller's initlized flag so we know to release stuff in Unload */
        gControllerInfo[i].Initialized = TRUE;

        /* 3: per-drive setup */
        for(j = 0; j < gControllerInfo[i].NumberOfDrives; j++)
        {
            WCHAR DeviceNameBuf[MAX_DEVICE_NAME];
            UNICODE_STRING DeviceName;
            UNICODE_STRING LinkName;
            UNICODE_STRING ArcPath;
            UCHAR DriveNumber;

            INFO_(FLOPPY, "AddControllers(): Configuring drive %d on controller %d\n", i, j);

            /*
             * 3a: create a device object for the drive
             * Controllers and drives are 0-based, so the combos are:
             * 0: 0,0
             * 1: 0,1
             * 2: 0,2
             * 3: 0,3
             * 4: 1,0
             * 5: 1,1
             * ...
             * 14: 3,2
             * 15: 3,3
             */

            DriveNumber = (UCHAR)(i*4 + j); /* loss of precision is OK; there are only 16 of 'em */

            RtlZeroMemory(&DeviceNameBuf, MAX_DEVICE_NAME * sizeof(WCHAR));
            swprintf(DeviceNameBuf, L"\\Device\\Floppy%d", DriveNumber);
            RtlInitUnicodeString(&DeviceName, DeviceNameBuf);

            if(IoCreateDevice(DriverObject, sizeof(PVOID), &DeviceName,
                              FILE_DEVICE_DISK, FILE_REMOVABLE_MEDIA | FILE_FLOPPY_DISKETTE, FALSE,
                              &gControllerInfo[i].DriveInfo[j].DeviceObject) != STATUS_SUCCESS)
            {
                WARN_(FLOPPY, "AddControllers: unable to register a Device object\n");
                IoDisconnectInterrupt(gControllerInfo[i].InterruptObject);
                continue; /* continue on to next drive */
            }

            INFO_(FLOPPY, "AddControllers: New device: %S (0x%p)\n", DeviceNameBuf, gControllerInfo[i].DriveInfo[j].DeviceObject);

            /* 3b.5: Create an ARC path in case we're booting from this drive */
            swprintf(gControllerInfo[i].DriveInfo[j].ArcPathBuffer,
                     L"\\ArcName\\multi(%d)disk(%d)fdisk(%d)", gControllerInfo[i].BusNumber, i, DriveNumber);

            RtlInitUnicodeString(&ArcPath, gControllerInfo[i].DriveInfo[j].ArcPathBuffer);
            IoAssignArcName(&ArcPath, &DeviceName);

            /* 3c: Set flags up */
            gControllerInfo[i].DriveInfo[j].DeviceObject->Flags |= DO_DIRECT_IO;

            /* 3d: Create a symlink */
            swprintf(gControllerInfo[i].DriveInfo[j].SymLinkBuffer, L"\\DosDevices\\%c:", DriveNumber + 'A');
            RtlInitUnicodeString(&LinkName, gControllerInfo[i].DriveInfo[j].SymLinkBuffer);
            if(IoCreateSymbolicLink(&LinkName, &DeviceName) != STATUS_SUCCESS)
            {
                WARN_(FLOPPY, "AddControllers: Unable to create a symlink for drive %d\n", DriveNumber);
                IoDisconnectInterrupt(gControllerInfo[i].InterruptObject);
                IoDeassignArcName(&ArcPath);
                continue; /* continue to next drive */
            }

            /* 3e: Increase global floppy drives count */
            IoGetConfigurationInformation()->FloppyCount++;

            /* 3f: Set up the DPC */
            IoInitializeDpcRequest(gControllerInfo[i].DriveInfo[j].DeviceObject, (PIO_DPC_ROUTINE)DpcForIsr);

            /* 3g: Point the device extension at our DriveInfo struct */
            gControllerInfo[i].DriveInfo[j].DeviceObject->DeviceExtension = &gControllerInfo[i].DriveInfo[j];

            /* 3h: neat comic strip */

            /* 3i: set the initial media type to unknown */
            memset(&gControllerInfo[i].DriveInfo[j].DiskGeometry, 0, sizeof(DISK_GEOMETRY));
            gControllerInfo[i].DriveInfo[j].DiskGeometry.MediaType = Unknown;

            /* 3j: Now that we're done, set the Initialized flag so we know to free this in Unload */
            gControllerInfo[i].DriveInfo[j].Initialized = TRUE;

            /* 3k: Clear the DO_DEVICE_INITIALIZING flag */
            gControllerInfo[i].DriveInfo[j].DeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
        }
    }

    INFO_(FLOPPY, "AddControllers: --------------------------------------------> finished adding controllers\n");

    return TRUE;
}
コード例 #9
0
ファイル: irq.c プロジェクト: RPG-7/reactos
/*
 * @implemented
 */
NTSTATUS
NTAPI
IoConnectInterrupt(OUT PKINTERRUPT *InterruptObject,
                   IN PKSERVICE_ROUTINE ServiceRoutine,
                   IN PVOID ServiceContext,
                   IN PKSPIN_LOCK SpinLock,
                   IN ULONG Vector,
                   IN KIRQL Irql,
                   IN KIRQL SynchronizeIrql,
                   IN KINTERRUPT_MODE InterruptMode,
                   IN BOOLEAN ShareVector,
                   IN KAFFINITY ProcessorEnableMask,
                   IN BOOLEAN FloatingSave)
{
    PKINTERRUPT Interrupt;
    PKINTERRUPT InterruptUsed;
    PIO_INTERRUPT IoInterrupt;
    PKSPIN_LOCK SpinLockUsed;
    BOOLEAN FirstRun;
    CCHAR Count = 0;
    KAFFINITY Affinity;
    PAGED_CODE();

    /* Assume failure */
    *InterruptObject = NULL;

    /* Get the affinity */
    Affinity = ProcessorEnableMask & KeActiveProcessors;
    while (Affinity)
    {
        /* Increase count */
        if (Affinity & 1) Count++;
        Affinity >>= 1;
    }

    /* Make sure we have a valid CPU count */
    if (!Count) return STATUS_INVALID_PARAMETER;

    /* Allocate the array of I/O Interrupts */
    IoInterrupt = ExAllocatePoolWithTag(NonPagedPool,
                                        (Count - 1) * sizeof(KINTERRUPT) +
                                        sizeof(IO_INTERRUPT),
                                        TAG_KINTERRUPT);
    if (!IoInterrupt) return STATUS_INSUFFICIENT_RESOURCES;

    /* Select which Spinlock to use */
    SpinLockUsed = SpinLock ? SpinLock : &IoInterrupt->SpinLock;

    /* We first start with a built-in Interrupt inside the I/O Structure */
    *InterruptObject = &IoInterrupt->FirstInterrupt;
    Interrupt = (PKINTERRUPT)(IoInterrupt + 1);
    FirstRun = TRUE;

    /* Start with a fresh structure */
    RtlZeroMemory(IoInterrupt, sizeof(IO_INTERRUPT));

    /* Now create all the interrupts */
    Affinity = ProcessorEnableMask & KeActiveProcessors;
    for (Count = 0; Affinity; Count++, Affinity >>= 1)
    {
        /* Check if it's enabled for this CPU */
        if (Affinity & 1)
        {
            /* Check which one we will use */
            InterruptUsed = FirstRun ? &IoInterrupt->FirstInterrupt : Interrupt;

            /* Initialize it */
            KeInitializeInterrupt(InterruptUsed,
                                  ServiceRoutine,
                                  ServiceContext,
                                  SpinLockUsed,
                                  Vector,
                                  Irql,
                                  SynchronizeIrql,
                                  InterruptMode,
                                  ShareVector,
                                  Count,
                                  FloatingSave);

            /* Connect it */
            if (!KeConnectInterrupt(InterruptUsed))
            {
                /* Check how far we got */
                if (FirstRun)
                {
                    /* We failed early so just free this */
                    ExFreePoolWithTag(IoInterrupt, TAG_KINTERRUPT);
                }
                else
                {
                    /* Far enough, so disconnect everything */
                    IoDisconnectInterrupt(&IoInterrupt->FirstInterrupt);
                }

                /* And fail */
                return STATUS_INVALID_PARAMETER;
            }

            /* Now we've used up our First Run */
            if (FirstRun)
            {
                FirstRun = FALSE;
            }
            else
            {
                /* Move on to the next one */
                IoInterrupt->Interrupt[(UCHAR)Count] = Interrupt++;
            }
        }
    }

    /* Return Success */
    return STATUS_SUCCESS;
}
コード例 #10
0
ファイル: halipi.cpp プロジェクト: 340211173/hf-2011
VOID
  SetIpiHandlerRoutine(
    IN struct _KDPC  *Dpc,
    IN PVOID  DeferredContext,
    IN PVOID  SystemArgument1,
    IN PVOID  SystemArgument2
    )

/*++

Routine Description

	CALLBACK

	This is a deferred routine for DPC, which is delivered for each processor in MP system
	 to initialize IPI support.

	This routine connects an IPI interrupt handler

Arguments

	Dpc, DeferredContext, SystemArgument1, SystemArgument2

		Normal parameters of CustomDpc routine, see CustomDpc,KeInitializeDpc,KeInsertQueueDpc in MSDN.

Return Value

	None

--*/

{
	IDTR Idtr;
	__asm
	{
		sidt fword ptr [Idtr]
	}

	ULONG Proc = KeGetCurrentProcessorNumber();
	KdPrint(("[%d] IDT = %x\n", Proc, Idtr.Table));

	if (DeferredContext == NULL)
	{
		NTSTATUS Status;

		Status = IoConnectInterrupt (
			&IntObjs[Proc],
			IpiService,
			NULL,
			NULL,
			IpiVector,
			Irql,
			Irql,
			Latched,
			TRUE,
			Affinity,
			FALSE
			);

		KdPrint(("[%d] IoConnectInterrupt: %x\n", Proc, Status));

		if (!NT_SUCCESS(Status))
			IntObjs[Proc] = NULL;
	}
	else
	{
		if (IntObjs[Proc])
			IoDisconnectInterrupt (IntObjs[Proc]);
		KdPrint(("[%d] Interrupt disconnected\n", Proc));
	}
}
コード例 #11
0
ファイル: PCI_SAMPLE.C プロジェクト: RussianPenguin/samples
///////////////////////////////////////////////////////////////////////////////
//
//  OsrUnload
//
//      This routine is our dynamic unload entry point.  We are called here when
//    the OS wants to unload our driver.  It is our responsibility to release any
//    resources we allocated.
//
//  INPUTS:
//
//      DriverObj - Address of our DRIVER_OBJECT.
//
//  OUTPUTS:
//
//      None.
//
//  RETURNS:
//
//      None.
//
//  IRQL:
//
//    This routine is called at IRQL_PASSIVE_LEVEL.
//
//  NOTES:
//
//    No doubt we pool leak at this entry point by not properly returning everything.
//
///////////////////////////////////////////////////////////////////////////////
VOID OsrUnload(PDRIVER_OBJECT DriverObject)
{
    POSR_DEVICE_EXT devExt;
    PDEVICE_OBJECT devObj;
    IO_RESOURCE_REQUIREMENTS_LIST reqList;
    NTSTATUS code;
    UNICODE_STRING linkName;
    CM_RESOURCE_LIST returnResources;
    BOOLEAN conflictDetected;
            
#if DBG
    DbgPrint("SAMPLE-PCI: UNLOAD called.\n");
#endif

    //
    // For THIS driver, there will only ever be a single device object.
    // Because of this, we just get it from the DriverObj.  If this were
    // a multiple device driver, we would do this in a while loop...
    //
    devObj = DriverObject->DeviceObject;

    if (!devObj) {

        return;
    }

    devExt= (POSR_DEVICE_EXT)devObj->DeviceExtension;

    RtlInitUnicodeString(&linkName, L"\\DosDevices\\OSRPCI");

    IoDeleteSymbolicLink(&linkName);

    //
    // Reset the adapter card
    //
    OsrResetAdapter(devObj, FALSE);

    if (devExt->InterruptObject) {
        //
        // Disconnect the interrupt.
        //
        IoDisconnectInterrupt(devExt->InterruptObject);
    }

    //
    // Unmap any ports that were mapped
    //
    if (devExt->MappedPorts) {

        MmUnmapIoSpace(devExt->AmccBaseRegisterAddress, 0x40);

        devExt->MappedPorts = FALSE;
        devExt->AmccBaseRegisterAddress = 0;
        
    }

    //
    // Delete the device object
    //
    IoDeleteDevice(devObj);
}
コード例 #12
0
ファイル: init.c プロジェクト: BillTheBest/WinNT4
VOID
SoundCleanup(
    IN   PGLOBAL_DEVICE_INFO pGDI
)
/*++

Routine Description:

    Clean up all resources allocated by our initialization

Arguments:

    pGDI - Pointer to global data

Return Value:

    NONE

--*/
{

    PGLOBAL_DEVICE_INFO NextGDI;
    PGLOBAL_DEVICE_INFO FirstGDI;
    PDRIVER_OBJECT      DriverObject;

    FirstGDI = pGDI;

    for (;;) {
        NextGDI = pGDI->Next;

        //
        //  Free the synth device
        //

        SynthCleanup(&pGDI->Synth);

        //
        //  Reset MPU401 if any
        //

        if (pGDI->Hw.MPU401.PortBase != NULL) {
            //
            //  Just in case
            //
            READ_PORT_UCHAR(pGDI->Hw.MPU401.PortBase + MPU401_REG_DATA);
            MPU401Write(pGDI->Hw.MPU401.PortBase, TRUE, MPU401_CMD_RESET);
        }
        //
        // Free our interrupt
        //
        if (pGDI->WaveInfo.Interrupt) {
            IoDisconnectInterrupt(pGDI->WaveInfo.Interrupt);
        }

        //
        // Free our DMA Buffer
        //
        SoundFreeCommonBuffer(&pGDI->WaveInfo.DMABuf);

        //
        //  Unregister shutdown notification
        //
        if (pGDI->ShutdownRegistered) {
            IoUnregisterShutdownNotification(pGDI->DeviceObject[WaveInDevice]);
        }

        //
        // Free our I/O Ports
        //
        if (pGDI->MemType == 0) {
            if (pGDI->Hw.PortBase != NULL) {

                MmUnmapIoSpace(pGDI->Hw.PortBase, NUMBER_OF_SOUND_PORTS);
            }
            if (pGDI->Hw.MPU401.PortBase != NULL) {

                MmUnmapIoSpace(pGDI->Hw.MPU401.PortBase, NUMBER_OF_MPU401_PORTS);
            }
#ifdef SB_CD
            if (pGDI->Hw.SBCDBase != NULL) {

                MmUnmapIoSpace(pGDI->Hw.SBCDBase, 6);
            }
#endif // SB_CD
        }

        //
        // Free device name
        //
        if (pGDI->RegistryPathName) {
            HANDLE hKey;

            //
            //  Free devices key
            //
            if (NT_SUCCESS(SoundOpenDevicesKey(pGDI->RegistryPathName, &hKey))) {
                ZwDeleteKey(hKey);
                ZwClose(hKey);
            }

            ExFreePool(pGDI->RegistryPathName);
        }

        //
        // Save driver object
        //

        DriverObject = pGDI->DriverObject;

        //
        // Free the Pool
        //
        ExFreePool(pGDI);

        if (NextGDI == FirstGDI) {
            break;
        } else {
            pGDI = NextGDI;
        }
    }

    //
    //  Free all devices for this driver.  This will free everything for
    //  every card.
    //

    if (DriverObject != NULL) {
        while (DriverObject->DeviceObject != NULL) {

            /*
            **  Undeclare resources used by device and
            **  delete the device object and associated data
            */

            SoundFreeDevice(DriverObject->DeviceObject);
        }
    }
}
コード例 #13
0
static NTSTATUS
i8042ConnectMouseInterrupt(
    IN PI8042_MOUSE_EXTENSION DeviceExtension)
{
    PPORT_DEVICE_EXTENSION PortDeviceExtension;
    KIRQL DirqlMax;
    NTSTATUS Status;

    TRACE_(I8042PRT, "i8042ConnectMouseInterrupt()\n");

    Status = i8042MouInitialize(DeviceExtension);
    if (!NT_SUCCESS(Status))
        return Status;

    PortDeviceExtension = DeviceExtension->Common.PortDeviceExtension;
    DirqlMax = MAX(
        PortDeviceExtension->KeyboardInterrupt.Dirql,
        PortDeviceExtension->MouseInterrupt.Dirql);

    INFO_(I8042PRT, "MouseInterrupt.Vector         %lu\n",
        PortDeviceExtension->MouseInterrupt.Vector);
    INFO_(I8042PRT, "MouseInterrupt.Dirql          %lu\n",
        PortDeviceExtension->MouseInterrupt.Dirql);
    INFO_(I8042PRT, "MouseInterrupt.DirqlMax       %lu\n",
        DirqlMax);
    INFO_(I8042PRT, "MouseInterrupt.InterruptMode  %s\n",
        PortDeviceExtension->MouseInterrupt.InterruptMode == LevelSensitive ? "LevelSensitive" : "Latched");
    INFO_(I8042PRT, "MouseInterrupt.ShareInterrupt %s\n",
        PortDeviceExtension->MouseInterrupt.ShareInterrupt ? "yes" : "no");
    INFO_(I8042PRT, "MouseInterrupt.Affinity       0x%lx\n",
        PortDeviceExtension->MouseInterrupt.Affinity);
    Status = IoConnectInterrupt(
        &PortDeviceExtension->MouseInterrupt.Object,
        i8042MouInterruptService,
        DeviceExtension, &PortDeviceExtension->SpinLock,
        PortDeviceExtension->MouseInterrupt.Vector, PortDeviceExtension->MouseInterrupt.Dirql, DirqlMax,
        PortDeviceExtension->MouseInterrupt.InterruptMode, PortDeviceExtension->MouseInterrupt.ShareInterrupt,
        PortDeviceExtension->MouseInterrupt.Affinity, FALSE);
    if (!NT_SUCCESS(Status))
    {
        WARN_(I8042PRT, "IoConnectInterrupt() failed with status 0x%08x\n", Status);
        goto cleanup;
    }

    if (DirqlMax == PortDeviceExtension->MouseInterrupt.Dirql)
        PortDeviceExtension->HighestDIRQLInterrupt = PortDeviceExtension->MouseInterrupt.Object;

    PortDeviceExtension->Flags |= MOUSE_INITIALIZED;
    Status = STATUS_SUCCESS;

cleanup:
    if (!NT_SUCCESS(Status))
    {
        PortDeviceExtension->Flags &= ~MOUSE_INITIALIZED;
        if (PortDeviceExtension->MouseInterrupt.Object)
        {
            IoDisconnectInterrupt(PortDeviceExtension->MouseInterrupt.Object);
            PortDeviceExtension->HighestDIRQLInterrupt = PortDeviceExtension->KeyboardInterrupt.Object;
        }
    }
    return Status;
}
コード例 #14
0
ファイル: remove.c プロジェクト: JanD1943/ndas4windows
VOID
SpReleaseAdapterResources(
    IN PADAPTER_EXTENSION Adapter,
    IN BOOLEAN Surprise
    )

/*++

Routine Description:

    This function deletes all of the storage associated with a device
    extension, disconnects from the timers and interrupts and then deletes the
    object.   This function can be called at any time during the initialization.

Arguments:

    Adapter - Supplies a pointer to the device extesnion to be deleted.

Return Value:

    None.

--*/

{

    PCOMMON_EXTENSION commonExtension = &(Adapter->CommonExtension);
    ULONG j;
    PVOID tempPointer;

    PAGED_CODE();

#if DBG

    if(!Surprise) {

        //
        // Free the Remove tracking lookaside list.
        //

        ExDeleteNPagedLookasideList(&(commonExtension->RemoveTrackingLookasideList));
    }
#endif

    //
    // Stop the time and disconnect the interrupt if they have been
    // initialized.  The interrupt object is connected after
    // timer has been initialized, and the interrupt object is connected, but
    // before the timer is started.
    //

    if(Adapter->DeviceObject->Timer != NULL) {
        IoStopTimer(Adapter->DeviceObject);
        KeCancelTimer(&(Adapter->MiniPortTimer));
    }

    if(Adapter->SynchronizeExecution != SpSynchronizeExecution) {

        if (Adapter->InterruptObject) {
            IoDisconnectInterrupt(Adapter->InterruptObject);
        }

        if (Adapter->InterruptObject2) {
            IoDisconnectInterrupt(Adapter->InterruptObject2);
            Adapter->InterruptObject2 = NULL;
        }

        //
        // SpSynchronizeExecution expects to get a pointer to the 
        // adapter extension as the "interrupt" parameter.
        //

        Adapter->InterruptObject = (PVOID) Adapter;
        Adapter->SynchronizeExecution = SpSynchronizeExecution;
    }

    //
    // Delete the miniport's device extension
    //

    if (Adapter->HwDeviceExtension != NULL) {

        PHW_DEVICE_EXTENSION devExt =
            CONTAINING_RECORD(Adapter->HwDeviceExtension,
                              HW_DEVICE_EXTENSION,
                              HwDeviceExtension);

        ExFreePool(devExt);
        Adapter->HwDeviceExtension = NULL;
    }

    //
    // Free the configuration information structure.
    //

    if (Adapter->PortConfig) {
        ExFreePool(Adapter->PortConfig);
        Adapter->PortConfig = NULL;
    }

    //
    // Deallocate SCSIPORT WMI REGINFO information, if any.
    //

    SpWmiDestroySpRegInfo(Adapter->DeviceObject);

    //
    // Free the common buffer.
    //

    if (Adapter->SrbExtensionBuffer != NULL &&
        Adapter->CommonBufferSize != 0) {

        if (Adapter->DmaAdapterObject == NULL) {

            //
            // Since there is no adapter just free the non-paged pool.
            //

            ExFreePool(Adapter->SrbExtensionBuffer);

        } else {

#if defined(_X86_)
            if(Adapter->UncachedExtensionIsCommonBuffer == FALSE) {
                MmFreeContiguousMemorySpecifyCache(Adapter->SrbExtensionBuffer,
                                                   Adapter->CommonBufferSize,
                                                   MmNonCached);
            } else 
#endif
            {

                HalFreeCommonBuffer(
                    Adapter->DmaAdapterObject,
                    Adapter->CommonBufferSize,
                    Adapter->PhysicalCommonBuffer,
                    Adapter->SrbExtensionBuffer,
                    FALSE);
            }

        }
        Adapter->SrbExtensionBuffer = NULL;
    }

    //
    // Free the SRB data array.
    //

    if (Adapter->SrbDataListInitialized) {

        if(Adapter->EmergencySrbData != NULL) {

            ExFreeToNPagedLookasideList(
                &Adapter->SrbDataLookasideList,
                Adapter->EmergencySrbData);
            Adapter->EmergencySrbData = NULL;
        }

        ExDeleteNPagedLookasideList(&Adapter->SrbDataLookasideList);

        Adapter->SrbDataListInitialized = FALSE;
    }

    if (Adapter->InquiryBuffer != NULL) {
        ExFreePool(Adapter->InquiryBuffer);
        Adapter->InquiryBuffer = NULL;
    }

    if (Adapter->InquirySenseBuffer != NULL) {
        ExFreePool(Adapter->InquirySenseBuffer);
        Adapter->InquirySenseBuffer = NULL;
    }

    if (Adapter->InquiryIrp != NULL) {
        IoFreeIrp(Adapter->InquiryIrp);
        Adapter->InquiryIrp = NULL;
    }

    if (Adapter->InquiryMdl != NULL) {
        IoFreeMdl(Adapter->InquiryMdl);
        Adapter->InquiryMdl = NULL;
    }

    //
    // Free the Scatter Gather lookaside list.
    //

    if (Adapter->MediumScatterGatherListInitialized) {

        ExDeleteNPagedLookasideList(
            &Adapter->MediumScatterGatherLookasideList);

        Adapter->MediumScatterGatherListInitialized = FALSE;
    }

    //
    // Unmap any mapped areas.
    //

    SpReleaseMappedAddresses(Adapter);

    //
    // If we've got any resource lists allocated still we should free them
    // now.
    //

    if(Adapter->AllocatedResources != NULL) {
        ExFreePool(Adapter->AllocatedResources);
        Adapter->AllocatedResources = NULL;
    }

    if(Adapter->TranslatedResources != NULL) {
        ExFreePool(Adapter->TranslatedResources);
        Adapter->TranslatedResources = NULL;
    }

    Adapter->CommonExtension.IsInitialized = FALSE;

    return;
}