Modify KMDOD sample for USB display

This gets it straight to the point. Actually we can take this even further:
On the way from version 1.0 to version 5.0, I am often trying
to enforce what I call “Continuous Improvement Process”.
While adding new features, also correct code inefficiencies spotted on the way
and try to increase code reuse and coverage…

Very often, this results in a negative value for the metrics “Lines of code per day”
over long periods of time while functionality and stability are increasing.
Of course, there is always a J-Curve effect first, also requiring additional testing…

Why did I learn about the J-Curve effect only in economics?
It applies much more even to computer science…

The above of course only applies to long term development projects with quality aware customers
(yes - this endangered species does still exist :wink:

PS: Probably time to close the thread before it turns into
a “Late night engineering discussion”.
Maybe we can leave it with a final reply count of 42
until the Second Coming of Zarquon.

Marcel Ruedinger
datronicsoft

> On the way from version 1.0 to version 5.0, I am often trying

to enforce what I call “Continuous Improvement Process”.

…and you cannot apply SLOC metric to it, unless you want to get extremely low numbers which show nothing.

The above of course only applies to long term development projects with quality aware customers
(yes - this endangered species does still exist :wink:

Yes, surely.

For “sign acceptance document, get the money and forget” other stuff is usable, like the Agile stuff (invented for this kinds of work like websites and business/accounting automation for small/medium businesses, as also to please the investors on the early stages of the startup).


Maxim S. Shatskih
Microsoft MVP on File System And Storage
xxxxx@storagecraft.com
http://www.storagecraft.com

Any one have experience to merge WDDM miniport and AVStream miniclass driver?

I said before, to implement a USB display driver:
it includes the WDDM miniport and the other big part is like USB Video class driver which actually is a AVStream miniclass driver.

Pls comments on this merge:
can or not?
any suggestions.

workingmailing@163.com wrote:

Any one have experience to merge WDDM miniport and AVStream miniclass driver?

I said before, to implement a USB display driver:
it includes the WDDM miniport and the other big part is like USB Video class driver which actually is a AVStream miniclass driver.

Pls comments on this merge:
can or not?

Merge? No. It’s clearly two separate drivers, with two completely
different interfaces, living in two separate stacks.

Now, you could conceivably have a low-level bus driver that talks to the
hardware, and have it create two PDOs, one for AVStream and one for
WDDM. However, I’m not sure it’s worth the trouble to build an AVStream
driver. I don’t know of any application that expect to attach to a
hardware renderer.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

A question:

as you known, when AVSTREAM miniclass driver is loaded,
in the pnpstart routine, the ksdevice parameter will give you the information which will be used in later by USB call:
m_pFDO=pKSDevice->FunctionalDeviceObject;
m_pPDO=pKSDevice->PhysicalDeviceObject;
m_pTopDeviceObject=pKSDevice->NextDeviceObject;

but in KMDOD, I could not get the NextDeviceObject pointer from BddDdiStartDevice function, and in BddDdiAddDevice function, we can only get the pPhysicalDeviceObject.

And also, I am not clear about the pPhysicalDeviceObject from BddDdiAddDevice is or is not the USB pdo?

Any one have port the KMDOD to a USB device, and how to get the NextDeviceObject for USBDCALL function?

Another question:

I develop AVSTREAM driver by print view at DebugView .EXE

Long time does not develop Win driver.

Who can tell me, how to view the driver log in Win8.1 SYSTEM?

and in VS 2013, for USB function

LINK error, cause USBD_ParseConfigurationDescriptorEx could not linked.

Can any one help answer how to fix this link error.

I try to add the $(ddk_lib_path) in VS 2013 VC++ directories , general, librayr directories, but still link error.

has the ‘usbd.lib’ been linked?

I have specify the $(DDK_LIB_PATH)\usbd.lib in VS2013 VC++ directories –> general –> library directories, but still link error.
The link issue still not fixed.

And the log print issue.

And:
I just review the general function driver:
I think I can get the FDO and NextDeviceObject by
IoCreateDevice and IoAttachDeviceToDeviceStack.

My question is, both these two function need the physical device object.
Does the phy dev object is got from Add device function?
And also, I am not clear about the pPhysicalDeviceObject from BddDdiAddDevice is
or is not the USB pdo?
If it is yes, then both the FDO and NextDeviceObject could fecthing.

workingmailing@163.com wrote:

as you known, when AVSTREAM miniclass driver is loaded,
in the pnpstart routine, the ksdevice parameter will give you the information which will be used in later by USB call:
m_pFDO=pKSDevice->FunctionalDeviceObject;
m_pPDO=pKSDevice->PhysicalDeviceObject;
m_pTopDeviceObject=pKSDevice->NextDeviceObject;

but in KMDOD, I could not get the NextDeviceObject pointer from BddDdiStartDevice function, and in BddDdiAddDevice function, we can only get the pPhysicalDeviceObject.

And also, I am not clear about the pPhysicalDeviceObject from BddDdiAddDevice is or is not the USB pdo?

The PDO is the one to which you send requests. It is your PDO, created
by the USB bus driver. Even in the AVStream case, in most cases
PhysicalDeviceObject and NextDeviceObject are exactly the same.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

workingmailing@163.com wrote:

Another question:

I develop AVSTREAM driver by print view at DebugView .EXE

Long time does not develop Win driver.

Who can tell me, how to view the driver log in Win8.1 SYSTEM?

DebugView still works. You just have to turn on Capture Kernel and
Enable Verbose Kernel Output. That does get you a lot of annoying spew,
so you may want to consider using one of filters, like
DPFLTR_IHVVIDEO_ID. Then you can use a “Debug Print Filter” registry
setting to pass your messages through, instead of “Enable Verbose Kernel
Output”.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

Although i haven’t still any driver built with visual studio but there is a guess that libraries to be linked against are to be set at “Configuration properties –> Linker –> Input –> Additional Dependencies”

Correct, you want to add a specific lib in Additional Dependencies. Library directories changes the default set of directories to resolve XXXX.lib references (where there is no full path). This is why the wdk uses full paths to the lib, ie $(DDK_LIB_PATH)\XXX.lib, so that library paths are not needed.

d

-----Original Message-----
From: xxxxx@lists.osr.com [mailto:xxxxx@lists.osr.com] On Behalf Of xxxxx@seznam.cz
Sent: Tuesday, June 17, 2014 9:54 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Modify KMDOD sample for USB display

Although i haven’t still any driver built with visual studio but there is a guess that libraries to be linked against are to be set at “Configuration properties –> Linker –> Input –> Additional Dependencies”


NTDEV is sponsored by OSR

Visit the list at: http://www.osronline.com/showlists.cfm?list=ntdev

OSR is HIRING!! See http://www.osr.com/careers

For our schedule of WDF, WDM, debugging and other seminars visit:
http://www.osr.com/seminars

To unsubscribe, visit the List Server section of OSR Online at http://www.osronline.com/page.cfm?name=ListServer

thank you Tim

Dbgview worked on Win8.1
and now com debug with windbg also worked.

But in Windbg, every time set the bp
it pop out the window: code not found, bp not set.

What’s the reason?

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);

  1. 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;
}

Follow are Windbg pirntout.
It seems that Adddevice have finished.

But still does not run PnpStart.

What is the cause for this issue?

Driver Entry driver obj = A682F190, A682F190
AddDevice DriverObject == A682F190
AddDevice DriverObject success
KDTARGET: Refreshing KD connection

*** Fatal System Error: 0x0000007e
(0xC0000005,0x20206F49,0x88A07518,0x88A070E0)

Break instruction exception - code 80000003 (first chance)

A fatal system error has occurred.
Debugger entered on first try; Bugcheck callbacks have not been invoked.

A fatal system error has occurred.

Connected to Windows 8 9600 x86 compatible target at (Wed Jun 18 18:11:02.867 2014 (UTC + 8:00)), ptr64 FALSE
Loading Kernel Symbols

Press ctrl-c (cdb, kd, ntsd) or ctrl-break (windbg) to abort symbol loads that take too long.
Run !sym noisy before .reload to track down problems loading symbols.

0x0000007e - SYSTEM_THREAD_EXCEPTION_NOT_HANDLED
0xC0000005 - STATUS_ACCESS_VIOLATION

Most probably there some memory misaccess occured, a stack backtrace typically helps to get the reason.
Load your crashdump into windbg, make sure the kernel and your module symbols are loaded (see .sympath, .reload), and do ‘analyze -v’.

ditto, make sure your module symbols are loaded.

workingmailing@163.com wrote:

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.

Remembering that I have not actually done this, I believe the display
port driver is handling all of that for you. Your AddDevice callback is
simply for you to create and initialize your device context structure.
The boilerplate WDM tasks are all done in the port driver.


Tim Roberts, xxxxx@probo.com
Providenza & Boekelheide, Inc.

So Tim,

What you mentioned is:
WDDM port have create the FDO, PDO, and for y ou.
As my previous post, AVSTREAM have pass you the KSDEVICE structure, where you can get the PDO, FDO and nexttop.

But how can I get these, especially for the nexttop, which is use for pass URB downwords.