⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dt2851.c

📁 DT2851图形卡NT驱动源码
💻 C
📖 第 1 页 / 共 3 页
字号:

    // NT copies inbuf here before entry and copies this to outbuf after return,
    // for METHOD_BUFFERED IOCTL's.
    pIOBuffer     = (PULONG) pIORequestPacket->AssociatedIrp.SystemBuffer;

    // We don't return any data on a write port.
    pIORequestPacket->IoStatus.Information = 0;
    
    // Check to ensure input buffer is big enough to hold a port number as well
    // as the data to write.
    //
    // The relative port # is a ULONG, and the data is the type appropriate to
    // the IOCTL.
    //

    DataBufferSize = sizeof(USHORT);
    
    if ( InBufferSize < (sizeof(ULONG) + DataBufferSize) )
    {
        return STATUS_INVALID_PARAMETER;
    }

    nPort = *pIOBuffer++;

    if (nPort >= extension->portCount ||
        (nPort + DataBufferSize) > extension->portCount ||
        (((ULONG)extension->portBase + nPort) & (DataBufferSize - 1)) != 0)
    {
        return STATUS_ACCESS_VIOLATION;   // Illegal port number
    }

    if (extension->portMemoryType == 1)
    {
        // Address is in I/O space

        WRITE_PORT_USHORT(
            (PUSHORT)((ULONG)extension->portBase + nPort),
            *(PUSHORT)pIOBuffer );
     
    } else {
        // Address is in Memory space

        WRITE_REGISTER_USHORT(
                (PUSHORT)((ULONG)extension->portBase + nPort),
                *(PUSHORT)pIOBuffer );
    }

    return STATUS_SUCCESS;
}

///////////////////////////////////////////////////////////////////////////////

NTSTATUS
DT2851ReadMemory(
    IN PDT2851_EXTENSION extension,
    IN PIRP pIORequestPacket,
    IN PIO_STACK_LOCATION pIrpStack )

/*

Routine Description:
    This routine processes the IOCTLs which read the memory.

Arguments:
    
    extension        - the device extension
    pIORequestPacket - IO request packet
    IrpStack         - The current stack location

Return Value:
    STATUS_SUCCESS           -- OK

    STATUS_INVALID_PARAMETER -- Either the frameGrabber memory bank
                                was out of range, or the byte offset +
                                number of bytes to copy went out of
                                range

    STATUS_ACCESS_VIOLATION  -- An illegal address was given.

*/

{
                                // NOTE:  Use METHOD_BUFFERED ioctls.
    PULONG pIOBuffer;           // Pointer to transfer buffer
                                //      (treated as an array of longs).
    ULONG InBufferSize;         // Amount of data avail. from caller.

    DT2851_MEMORY_BUFFER* buff; // cast pIOBuffer into someting that 
                                // we know how to work with

    PVOID sourceAddress;          // begging address of copy      

    // NT copies inbuf here before entry and copies this to outbuf after
    // return, for METHOD_BUFFERED IOCTL's.
    pIOBuffer     = (PULONG)pIORequestPacket->AssociatedIrp.SystemBuffer;

    buff = (DT2851_MEMORY_BUFFER*) pIOBuffer;
    if(buff->bufferNumber <= 1 && (buff->byteOffset + buff->numberOfBytes) < MEMORY_SIZE/2)
    {
        sourceAddress = (PVOID) (((ULONG)extension->baseAddress) + 
                      (buff->bufferNumber * MEMORY_SIZE/2 +
                      buff->byteOffset));
      
        RtlCopyMemory (
            buff->userBuffer,
            sourceAddress,
            buff->numberOfBytes);
        
        return STATUS_SUCCESS;
    }

    return STATUS_INVALID_PARAMETER;
}

///////////////////////////////////////////////////////////////////////////////


NTSTATUS
DT2851WriteMemory(
    IN PDT2851_EXTENSION extension,
    IN PIRP pIORequestPacket,
    IN PIO_STACK_LOCATION pIrpStack )

/*

Routine Description:
    This routine processes the IOCTLs which write to the memory.

Arguments:
    
    extension        - the device extension
    pIORequestPacket - IO request packet
    IrpStack         - The current stack location

Return Value:
    STATUS_SUCCESS           -- OK

    STATUS_INVALID_PARAMETER -- Either the frameGrabber memory bank
                                was out of range, or the byte offset +
                                number of bytes to copy went out of
                                range

    STATUS_ACCESS_VIOLATION  -- An illegal address was given.

*/

{
                                // NOTE:  Use METHOD_BUFFERED ioctls.
    PULONG pIOBuffer;           // Pointer to transfer buffer
                                //      (treated as an array of longs).
    ULONG InBufferSize;         // Amount of data avail. from caller.

    DT2851_MEMORY_BUFFER* buff; // cast pIOBuffer into someting that 
                                // we know how to work with

    PVOID destAddress;          // begging address of copy      

    // NT copies inbuf here before entry and copies this to outbuf after
    // return, for METHOD_BUFFERED IOCTL's.
    pIOBuffer     = (PULONG)pIORequestPacket->AssociatedIrp.SystemBuffer;

    buff = (DT2851_MEMORY_BUFFER*) pIOBuffer;
    if(buff->bufferNumber <= 1 && (buff->byteOffset + buff->numberOfBytes) < MEMORY_SIZE/2)
    {
        destAddress = (PVOID) (((ULONG)extension->baseAddress) + 
                      (buff->bufferNumber * MEMORY_SIZE/2 +
                      buff->byteOffset));
      
        RtlCopyMemory (
            destAddress,
            buff->userBuffer,
            buff->numberOfBytes);
        
        return STATUS_SUCCESS;
    }

    return STATUS_INVALID_PARAMETER;
}

///////////////////////////////////////////////////////////////////////////////

NTSTATUS
DT2851FillMemory(
    IN PDT2851_EXTENSION extension,
    IN PIRP pIORequestPacket,
    IN PIO_STACK_LOCATION pIrpStack )

/*

Routine Description:
    This routine processes the IOCTLs which read the memory.

Arguments:
    
    extension        - the device extension
    pIORequestPacket - IO request packet
    IrpStack         - The current stack location

Return Value:
    STATUS_SUCCESS           -- OK

    STATUS_INVALID_PARAMETER -- Either the frameGrabber memory bank
                                was out of range, or the byte offset +
                                number of bytes to copy went out of
                                range

    STATUS_ACCESS_VIOLATION  -- An illegal address was given.

*/

{
                                // NOTE:  Use METHOD_BUFFERED ioctls.
    PULONG pIOBuffer;           // Pointer to transfer buffer
                                //      (treated as an array of longs).
    ULONG InBufferSize;         // Amount of data avail. from caller.

    DT2851_MEMORY_BUFFER* buff; // cast pIOBuffer into someting that 
                                // we know how to work with

    PVOID destAddress;          // begging address of copy      

    // NT copies inbuf here before entry and copies this to outbuf after
    // return, for METHOD_BUFFERED IOCTL's.
    pIOBuffer     = (PULONG)pIORequestPacket->AssociatedIrp.SystemBuffer;

    buff = (DT2851_MEMORY_BUFFER*) pIOBuffer;
    if(buff->bufferNumber <= 1 && (buff->byteOffset + buff->numberOfBytes) < MEMORY_SIZE/2)
    {
        destAddress = (PVOID) (((ULONG)extension->baseAddress) + 
                      (buff->bufferNumber * MEMORY_SIZE/2 +
                      buff->byteOffset));

        RtlFillMemory (
            destAddress,
            buff->numberOfBytes,
            buff->fillValue);     
        
        return STATUS_SUCCESS;
    }

    return STATUS_INVALID_PARAMETER;
}

///////////////////////////////////////////////////////////////////////////////


VOID DT2851Unload( PDRIVER_OBJECT pDriverObject )
/*

Routine Description:
    This routine prepares our driver to be unloaded.  It is responsible
    for freeing all resources allocated by DriverEntry as well as any 
    allocated while the driver was running.  The symbolic link must be
    deleted as well.

Arguments:
    
    driverObject - Pointer to driver object created by the system.

Return Value:

    None
*/

{
    PDT2851_EXTENSION extension;
    CM_RESOURCE_LIST NullresourceList;
    BOOLEAN resourceConflict;
    UNICODE_STRING Win32DeviceName;

    // Find our global data
     extension = (PDT2851_EXTENSION)pDriverObject->DeviceObject->DeviceExtension;

    // Unmap the ports

    if (extension->portWasMapped)
    {
        MmUnmapIoSpace(extension->portBase, extension->portCount);
    }

    // Unmap the framegrabber memory

    if(extension->baseAddress)
    {
        MmUnmapIoSpace(extension->baseAddress, MEMORY_SIZE);
    }

#if 0

    // Report we're not using any hardware.  If we don't do this
    // then we'll conflict with ourselves (!) on the next load

    RtlZeroMemory((PVOID)&NullresourceList, sizeof(NullresourceList));

    IoReportResourceUsage(
              NULL,
              pDriverObject,
              &NullresourceList,
              sizeof(ULONG),
              NULL,
              NULL,
              0,
              FALSE,
              &resourceConflict );

    // Assume all handles are closed down.
    // Delete the things we allocated - devices, symbolic links

#endif 

    RtlInitUnicodeString(&Win32DeviceName, DOS_DT2851_DEVICE_NAME);

    IoDeleteSymbolicLink(&Win32DeviceName);

    IoDeleteDevice(extension->deviceObject);
}
</XMP></BODY></HTML>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -