/*++
Copyright (c) 1995 Microsoft Corporation
Module Name:
D12.c
Abstract:
USB device driver for Philips D12 USB test board
Environment:
kernel mode only
Notes:
THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
PURPOSE.
Copyright (c) 1996 Microsoft Corporation. All Rights Reserved.
Revision History:
5-4-96 : created
--*/
#define DRIVER
#include "wdm.h"
#include "stdarg.h"
#include "stdio.h"
#include "usbdi.h"
#include "usbdlib.h"
#include "D12.h"
#include "d12irp.h"
#include "guid829.h"
//
// Global pointer to Driver Object
//
PDRIVER_OBJECT D12_DriverObject;
NTSTATUS
DriverEntry(
IN PDRIVER_OBJECT DriverObject,
IN PUNICODE_STRING RegistryPath
)
/*++
Routine Description:
Installable driver initialization entry point.
This entry point is called directly by the I/O system.
Arguments:
DriverObject - pointer to the driver object
RegistryPath - pointer to a unicode string representing the path
to driver-specific key in the registry
Return Value:
STATUS_SUCCESS if successful,
STATUS_UNSUCCESSFUL otherwise
--*/
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_OBJECT deviceObject = NULL;
D12_KdPrint (("D12TEST.SYS: entering (D12) DriverEntry\n"));
D12_DriverObject = DriverObject;
//
// Create dispatch points for device control, create, close.
//
DriverObject->MajorFunction[IRP_MJ_CREATE] = D12_Create;
DriverObject->MajorFunction[IRP_MJ_CLOSE] = D12_Close;
DriverObject->DriverUnload = D12_Unload;
DriverObject->MajorFunction[IRP_MJ_DEVICE_CONTROL] = D12_ProcessIOCTL;
DriverObject->MajorFunction[IRP_MJ_WRITE] = D12_Write;
DriverObject->MajorFunction[IRP_MJ_READ] = D12_Read;
DriverObject->MajorFunction[IRP_MJ_SYSTEM_CONTROL] =
DriverObject->MajorFunction[IRP_MJ_PNP] = D12_Dispatch;
DriverObject->MajorFunction[IRP_MJ_POWER] = D12_ProcessPowerIrp;
DriverObject->DriverExtension->AddDevice = D12_PnPAddDevice;
D12_KdPrint (("D12TEST.SYS: exiting (D12) DriverEntry (%x)\n", ntStatus));
return ntStatus;
}
NTSTATUS
D12_PoRequestCompletion(
IN PDEVICE_OBJECT DeviceObject,
IN UCHAR MinorFunction,
IN POWER_STATE PowerState,
IN PVOID Context,
IN PIO_STATUS_BLOCK IoStatus
)
/*++
Routine Description:
This routine is called when the port driver completes an IRP.
Arguments:
DeviceObject - Pointer to the device object for the class device.
Context - Driver defined context.
Return Value:
The function value is the final status from the operation.
--*/
{
PIRP irp;
PDEVICE_EXTENSION deviceExtension;
PDEVICE_OBJECT deviceObject = Context;
NTSTATUS ntStatus;
deviceExtension = deviceObject->DeviceExtension;
irp = deviceExtension->PowerIrp;
ntStatus = IoStatus->Status;
D12_KdPrint(("'D12_PoRequestCompletion\n"));
IoCopyCurrentIrpStackLocationToNext(irp);
PoStartNextPowerIrp(irp);
PoCallDriver(deviceExtension->TopOfStackDeviceObject,
irp);
D12_DecrementIoCount(deviceObject);
return ntStatus;
}
NTSTATUS
D12_PowerIrp_Complete(
IN PDEVICE_OBJECT NullDeviceObject,
IN PIRP Irp,
IN PVOID Context
)
/*++
Routine Description:
This routine is called when the port driver completes an IRP.
Arguments:
DeviceObject - Pointer to the device object for the class device.
Irp - Irp completed.
Context - Driver defined context.
Return Value:
The function value is the final status from the operation.
--*/
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_OBJECT deviceObject;
PIO_STACK_LOCATION irpStack;
PDEVICE_EXTENSION deviceExtension;
D12_KdPrint(("D12TEST.SYS: enter D12_PowerIrp_Complete\n"));
deviceObject = (PDEVICE_OBJECT) Context;
deviceExtension = (PDEVICE_EXTENSION) deviceObject->DeviceExtension;
// BUGBUG
// kenray sez we should be calling IoMarkIrpPending
// from our completion routine.
//
if (Irp->PendingReturned) {
IoMarkIrpPending(Irp);
}
irpStack = IoGetCurrentIrpStackLocation (Irp);
ASSERT(irpStack->MajorFunction == IRP_MJ_POWER);
ASSERT(irpStack->MinorFunction == IRP_MN_SET_POWER);
ASSERT(irpStack->Parameters.Power.Type==DevicePowerState);
ASSERT(irpStack->Parameters.Power.State.DeviceState==PowerDeviceD0);
deviceExtension->CurrentDevicePowerState = PowerDeviceD0;
KdPrint(("D12TEST.SYS: enter D0 complete\n"));
Irp->IoStatus.Status = ntStatus;
D12_DecrementIoCount(deviceObject);
return ntStatus;
}
NTSTATUS
D12_SetDevicePowerState(
IN PDEVICE_OBJECT DeviceObject,
IN DEVICE_POWER_STATE DeviceState,
IN PBOOLEAN HookIt
)
/*++
Routine Description:
Arguments:
DeviceObject - Pointer to the device object for the class device.
Irp - Irp completed.
DeviceState - Device specific power state to set the device in to.
Return Value:
--*/
{
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_EXTENSION deviceExtension;
deviceExtension = (PDEVICE_EXTENSION) DeviceObject->DeviceExtension;
switch (DeviceState) {
case PowerDeviceD3:
//
// device will be going OFF, save any state now.
//
D12_KdPrint(("D12TEST.SYS: PowerDeviceD3 (OFF)\n"));
KdPrint(("D12: PM power off\n"));
deviceExtension->CurrentDevicePowerState = DeviceState;
break;
case PowerDeviceD1:
case PowerDeviceD2:
//
// power states D1,D2 translate to USB suspend
D12_KdPrint(("D12TEST.SYS: PowerDeviceD1/D2 (SUSPEND)\n"));
KdPrint(("D12: device entered D%d\n", DeviceState-1));
deviceExtension->CurrentDevicePowerState = DeviceState;
break;
case PowerDeviceD0:
D12_KdPrint(("D12TEST.SYS: PowerDeviceD0 (ON)\n"));
//
// finish the rest in the completion routine
//
*HookIt = TRUE;
// pass on to PDO
break;
default:
D12_KdPrint(("D12TEST.SYS: Bogus DeviceState = %x\n", DeviceState));
}
return ntStatus;
}
NTSTATUS
D12_DeferIrpCompletion(
IN PDEVICE_OBJECT DeviceObject,
IN PIRP Irp,
IN PVOID Context
)
/*++
Routine Description:
This routine is called when the port driver completes an IRP.
Arguments:
DeviceObject - Pointer to the device object for the class device.
Irp - Irp completed.
Context - Driver defined context.
Return Value:
The function value is the final status from the operation.
--*/
{
PKEVENT event = Context;
KeSetEvent(event,
1,
FALSE);
return STATUS_MORE_PROCESSING_REQUIRED;
}
NTSTATUS
D12_QueryCapabilities(
IN PDEVICE_OBJECT PdoDeviceObject,
IN PDEVICE_CAPABILITIES DeviceCapabilities
)
/*++
Routine Description:
This routine reads or write config space.
Arguments:
DeviceObject - Physical DeviceObject for this USB controller.
Return Value:
None.
--*/
{
PIO_STACK_LOCATION nextStack;
PIRP irp;
NTSTATUS ntStatus;
KEVENT event;
PAGED_CODE();
irp = IoAllocateIrp(PdoDeviceObject->StackSize, FALSE);
if (!irp) {
return STATUS_INSUFFICIENT_RESOURCES;
}
nextStack = IoGetNextIrpStackLocation(irp);
ASSERT(nextStack != NULL);
nextS
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
PDIUSBD12DDK驱动代码.rar (23个子文件)
source
NTSTATUS.H 179KB
D12.c 55KB
EXCPT.H 3KB
NTIOLOGC.H 12KB
GUID829.H 899B
USBDI.H 26KB
D12.h 5KB
obj
_objects.mac 836B
Sources 361B
objfre
i386
D12IRP.H 343B
NTDEF.H 41KB
D12irp.c 2KB
MAKEFILE 670B
WDM.H 270KB
D12.rc 3KB
USBDLIB.H 15KB
Ioctl.c 20KB
Ioctl.h 3KB
RESOURCE.H 453B
buildfre.log 2KB
BUGCODES.H 27KB
Ocrw.c 25KB
D12.APS 3KB
共 23 条
- 1
资源评论
- 老老实实2013-05-11很好,可用
- Klauszou2013-09-14代码有基本错误,需要自行更改才可使用。对高版本wdk(DDK)则根本不适用
- intech592013-12-18编译后,有问题,还要学习一下。
familyrobot
- 粉丝: 0
- 资源: 2
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功