And always 7e fault after my code modifycation.
Here are my code for Add device and pnp start:
For IoCreateDevice and IoAttachDeviceToDeviceStack function, it need driverobject and phy do parameters.
So I use a global variable:
1.
PDRIVER_OBJECT pGDriverObject;
Remember it in the DriverEntry function of KMDOD:
pGDriverObject = pDriverObject;
DbgPrint(“Driver Entry driver obj = %p, %p\n”, pGDriverObject, pDriverObject);
- Add device:
I new my USB class instance
and use the driver obj from DriverEntry to create the FDO
and attach to the PDO.
NTSTATUS
BddDdiAddDevice(
In DEVICE_OBJECT* pPhysicalDeviceObject,
Outptr PVOID* ppDeviceContext)
{
PAGED_CODE();
NTSTATUS ntStatus = STATUS_SUCCESS;
PDEVICE_OBJECT deviceObject = NULL;
ULONG deviceType = FILE_DEVICE_UNKNOWN;
PDRIVER_OBJECT DriverObject = pGDriverObject;
if ((pPhysicalDeviceObject == NULL) ||
(ppDeviceContext == NULL))
{
BDD_LOG_ERROR2(“One of pPhysicalDeviceObject (0x%I64x), ppDeviceContext (0x%I64x) is NULL”,
pPhysicalDeviceObject, ppDeviceContext);
return STATUS_INVALID_PARAMETER;
}
if (!DriverObject)
{
DbgPrint(“@@@ AddDevice DriverObject == Null\n”);
return STATUS_INVALID_PARAMETER;
}
DbgPrint(“AddDevice DriverObject == %p\n”, DriverObject);
*ppDeviceContext = NULL;
BASIC_DISPLAY_DRIVER* pBDD = new(NonPagedPoolNx) BASIC_DISPLAY_DRIVER(pPhysicalDeviceObject);
if (pBDD == NULL)
{
BDD_LOG_LOW_RESOURCE0(“pBDD failed to be allocated”);
DbgPrint(“@@@ AddDevice pBDD == Null\n”);
return STATUS_NO_MEMORY;
}
*ppDeviceContext = pBDD;
CKUsbCtlBag* pUsbDev = new(NonPagedPoolNx)CKUsbCtlBag;
if (pUsbDev == NULL)
{
BDD_LOG_LOW_RESOURCE0(“pUsbDev failed to be allocated”);
DbgPrint(“@@@ AddDevice pUsbDev == Null\n”);
delete pBDD;
pBDD = NULL;
return STATUS_NO_MEMORY;
}
pBDD->m_pUsbPtr = pUsbDev;
ntStatus = IoCreateDevice(DriverObject,
sizeof (DEVICE_EXTENSION),
NULL, // No Name
deviceType,
0,
FALSE,
&deviceObject);
if (!NT_SUCCESS(ntStatus)) {
//
// Returning failure here prevents the entire stack from functioning,
// but most likely the rest of the stack will not be able to create
// device objects either, so it is still OK.
//
delete pUsbDev;
pUsbDev = NULL;
pBDD->m_pUsbPtr = NULL;
delete pBDD;
pBDD = NULL;
*ppDeviceContext = NULL;
DbgPrint(“@@@Error: IoCreateDevice failed - 0x%08x!\n”, ntStatus);
DbgPrint(“@@@ AddDevice IoCreateDevice failed with NTSTATUS 0x%08x\n”, ntStatus);
return ntStatus;
}
//////////////////////////////////////////////////////////////////////
PDEVICE_EXTENSION deviceExtension;
deviceExtension = (PDEVICE_EXTENSION)deviceObject->DeviceExtension;
//////////////////////////////////////////////////////////////////////
deviceExtension->NextLowerDriver = IoAttachDeviceToDeviceStack(
deviceObject,
pPhysicalDeviceObject);
//
// Failure for attachment is an indication of a broken plug & play system.
//
if (NULL == pBDD->m_pUsbPtr->m_pTopDeviceObject)
{
delete pUsbDev;
pUsbDev = NULL;
pBDD->m_pUsbPtr = NULL;
delete pBDD;
pBDD = NULL;
*ppDeviceContext = NULL;
IoDeleteDevice(deviceObject);
return STATUS_UNSUCCESSFUL;
}
pBDD->m_pUsbPtr->m_pFDO = deviceObject;
pBDD->m_pUsbPtr->m_pPDO = pPhysicalDeviceObject;
pBDD->m_pUsbPtr->m_pTopDeviceObject = deviceExtension->NextLowerDriver;
#if 1
deviceObject->Flags |= deviceExtension->NextLowerDriver->Flags &
(DO_DIRECT_IO | DO_BUFFERED_IO | DO_POWER_PAGABLE | DO_POWER_INRUSH);
deviceObject->DeviceType = deviceExtension->NextLowerDriver->DeviceType;
deviceObject->Characteristics = deviceExtension->NextLowerDriver->Characteristics;
deviceObject->AlignmentRequirement = deviceExtension->NextLowerDriver->AlignmentRequirement;
deviceObject->StackSize = (CCHAR)(deviceExtension->NextLowerDriver->StackSize + 1);
deviceExtension->Self = deviceObject;
deviceExtension->pUsbCtrlDev = pUsbDev;
#endif
///////////////////////////////////////////////////////////////
//
// Set the initial state of the Filter DO
//
// Clear the “initializing” flag so that we can get IRPs
deviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
DbgPrint(“AddDevice DriverObject success\n”);
return STATUS_SUCCESS;
}
And in my PNP start function: not to call function
DxgkCbAcquirePostDisplayOwnership
but call my USB start function to Read descriptors and then parse the descriptors, and get the pipe handles.
NTSTATUS BASIC_DISPLAY_DRIVER::StartDevice(In DXGK_START_INFO* pDxgkStartInfo,
In DXGKRNL_INTERFACE* pDxgkInterface,
Out ULONG* pNumberOfViews,
Out ULONG* pNumberOfChildren)
{
PAGED_CODE();
BDD_ASSERT(pDxgkStartInfo != NULL);
BDD_ASSERT(pDxgkInterface != NULL);
BDD_ASSERT(pNumberOfViews != NULL);
BDD_ASSERT(pNumberOfChildren != NULL);
RtlCopyMemory(&m_StartInfo, pDxgkStartInfo, sizeof(m_StartInfo));
RtlCopyMemory(&m_DxgkInterface, pDxgkInterface, sizeof(m_DxgkInterface));
RtlZeroMemory(m_CurrentModes, sizeof(m_CurrentModes));
m_CurrentModes[0].DispInfo.TargetId = D3DDDI_ID_UNINITIALIZED;
// Get device information from OS.
NTSTATUS Status = m_DxgkInterface.DxgkCbGetDeviceInformation(m_DxgkInterface.DeviceHandle, &m_DeviceInfo);
if (!NT_SUCCESS(Status))
{
BDD_LOG_ASSERTION1(“DxgkCbGetDeviceInformation failed with status 0x%I64x”,
Status);
return Status;
}
// Ignore return value, since it’s not the end of the world if we failed to write these values to the registry
//RegisterHWInfo();
// TODO: Uncomment the line below after updating the TODOs in the function CheckHardware
// Status = CheckHardware();
if (!NT_SUCCESS(Status))
{
return Status;
}
#if 0
// This sample driver only uses the frame buffer of the POST device. DxgkCbAcquirePostDisplayOwnership
// gives you the frame buffer address and ensures that no one else is drawing to it. Be sure to give it back!
Status = m_DxgkInterface.DxgkCbAcquirePostDisplayOwnership(m_DxgkInterface.DeviceHandle, &(m_CurrentModes[0].DispInfo));
if (!NT_SUCCESS(Status) || m_CurrentModes[0].DispInfo.Width == 0)
{
// The most likely cause of failure is that the driver is simply not running on a POST device, or we are running
// after a pre-WDDM 1.2 driver. Since we can’t draw anything, we should fail to start.
return STATUS_UNSUCCESSFUL;
}
#endif
m_Flags.DriverStarted = TRUE;
*pNumberOfViews = MAX_VIEWS;
*pNumberOfChildren = MAX_CHILDREN;
return m_pUsbPtr->StartUsbModule();
//return STATUS_SUCCESS;
}