Regd. WDF QueryInterface

Hi Doran,

Thanks a lot for the help so far.

I have another question related to one of the questions I had asked earlier.

My device will get a QUERY_INTERFACE request for BUS_INTERFACE_STANDARD

from upper layer drivers on the device stack.

I return all routines of the BUS_INTERFACE_STANDARD interfaces I get from

my parent device except for the BusGetData() wherein I do some processing.

So, when I register my query interface for BUS_INTERFACE_STANDARD in

ChildDevice creation routine callback, with just GetBusData and leave out
rest empty, will KMDF use my parents

interface routines for BUS_INTERFACE_STANDARD.

For eg. Say

BusInterfaceStandard.Size = sizeof(BUS_INTERFACE_STANDARD);

BusInterfaceStandard.Version = 0x0100;

BusInterfaceStandard.InterfaceHeader.Context = (PVOID) hChild;

/*

BusInterfaceStandard.InterfaceReference =

(PINTERFACE_REFERENCE)BusIntf_InterfaceReference;

BusInterfaceStandard.InterfaceDereference =

(PINTERFACE_DEREFERENCE)BusIntf_InterfaceDereference;

*/

// Let the framework handle reference counting.

//

BusInterfaceStandard.InterfaceReference = WdfDeviceInterfaceReferenceNoOp;

BusInterfaceStandard.InterfaceDereference =
WdfDeviceInterfaceDereferenceNoOp;

BusInterfaceStandard.GetBusData = (PGET_SET_DEVICE_DATA)BusIntf_GetBusData;

WDF_QUERY_INTERFACE_CONFIG_INIT(&BusIntfStdConfig,

&BusInterfaceStandard,

GUID_BUS_INTERFACE_STANDARD,

NULL);

Will the above code work? If upper-layer drivers want to invoke

GetDmaAapter routine to get adapter object, and query for
BUS_INTERFACE_STANDARD

to get the GetDmaAdapter Interface, would they get it interface from my
parent device incase I don’t set it in my

driver processing of this query wherein I set only BusGetData?

Thanks,

-Praveen

KMDF doesn’t know about specific interfaces and what field is where.
KMDF offers 2 modes of how to deal with QI.

  1. You give KMDF the entire INTERFACE and when the QI arrives, KMDF
    does a copy memory from your copy to the requestor’s copy. This means
    the entire structure is copied over. You can override this behavior
    after the copy by adding a EvtDeviceProcessQueryInterfaceRequest to the
    registration

  2. KMDF will validate the request and then give you the buffer and you
    copy over the bits you want. This allows the caller to provide you with
    information as well as you returning info (the INTERFACe is an IN/OUT
    structure). You copy over the bits in your
    EvtDeviceProcessQueryInterfaceRequest callback. You get this mode by
    setting ImportInterface to TRUE in WDF_QUERY_INTERFACE_CONFIG.

So, you have 2 options

  1. when you create the PDO, you call WdfFdoQueryForInterface() on the
    parent, get the interface, replace the functions you want to override
    (interfacereference/dereference/GetBusData/etc) and then use that
    interface when you call WdfDeviceAddQueryInterface()

  2. you create the PDO, register/implement a
    EvtDeviceProcessQueryInterfaceRequest for the GUID and make the call to
    WdfFdoQueryForInterface() every time
    EvtDeviceProcessQueryInterfaceRequest is called, doing basically the
    same thing in one (query the parent, override the fields you want, copy
    it back to the caller).

I personally would choose option 1). It is much simpler b/c your code
is executed once during init and that’s it. Less chance for error as
well (like out of memory).

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Praveen Kumar
Amritaluru
Sent: Friday, July 28, 2006 8:46 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Regd. WDF QueryInterface

Hi Doran,

Thanks a lot for the help so far.

I have another question related to one of the questions I had asked
earlier.

My device will get a QUERY_INTERFACE request for BUS_INTERFACE_STANDARD

from upper layer drivers on the device stack.

I return all routines of the BUS_INTERFACE_STANDARD interfaces I get
from

my parent device except for the BusGetData() wherein I do some
processing.

So, when I register my query interface for BUS_INTERFACE_STANDARD in

ChildDevice creation routine callback, with just GetBusData and leave
out rest empty, will KMDF use my parents

interface routines for BUS_INTERFACE_STANDARD.

For eg. Say

BusInterfaceStandard.Size = sizeof(BUS_INTERFACE_STANDARD);

BusInterfaceStandard.Version = 0x0100;

BusInterfaceStandard.InterfaceHeader.Context = (PVOID) hChild;

/*

BusInterfaceStandard.InterfaceReference =

(PINTERFACE_REFERENCE)BusIntf_InterfaceReference;

BusInterfaceStandard.InterfaceDereference =

(PINTERFACE_DEREFERENCE)BusIntf_InterfaceDereference;

*/

// Let the framework handle reference counting.

//

BusInterfaceStandard.InterfaceReference =
WdfDeviceInterfaceReferenceNoOp;

BusInterfaceStandard.InterfaceDereference =
WdfDeviceInterfaceDereferenceNoOp;

BusInterfaceStandard.GetBusData =
(PGET_SET_DEVICE_DATA)BusIntf_GetBusData;

WDF_QUERY_INTERFACE_CONFIG_INIT(&BusIntfStdConfig,

&BusInterfaceStandard,

GUID_BUS_INTERFACE_STANDARD,

NULL);

Will the above code work? If upper-layer drivers want to invoke

GetDmaAapter routine to get adapter object, and query for
BUS_INTERFACE_STANDARD

to get the GetDmaAdapter Interface, would they get it interface from my
parent device incase I don’t set it in my

driver processing of this query wherein I set only BusGetData?

Thanks,

-Praveen


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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

Hi d,

I like the option #1. It sounds elegant.

Thanks for the suggestion,
-Praveen

“Doron Holan” wrote in message
news:xxxxx@ntdev…
KMDF doesn’t know about specific interfaces and what field is where.
KMDF offers 2 modes of how to deal with QI.

1) You give KMDF the entire INTERFACE and when the QI arrives, KMDF
does a copy memory from your copy to the requestor’s copy. This means
the entire structure is copied over. You can override this behavior
after the copy by adding a EvtDeviceProcessQueryInterfaceRequest to the
registration

2) KMDF will validate the request and then give you the buffer and you
copy over the bits you want. This allows the caller to provide you with
information as well as you returning info (the INTERFACe is an IN/OUT
structure). You copy over the bits in your
EvtDeviceProcessQueryInterfaceRequest callback. You get this mode by
setting ImportInterface to TRUE in WDF_QUERY_INTERFACE_CONFIG.

So, you have 2 options
1) when you create the PDO, you call WdfFdoQueryForInterface() on the
parent, get the interface, replace the functions you want to override
(interfacereference/dereference/GetBusData/etc) and then use that
interface when you call WdfDeviceAddQueryInterface()

2) you create the PDO, register/implement a
EvtDeviceProcessQueryInterfaceRequest for the GUID and make the call to
WdfFdoQueryForInterface() every time
EvtDeviceProcessQueryInterfaceRequest is called, doing basically the
same thing in one (query the parent, override the fields you want, copy
it back to the caller).

I personally would choose option 1). It is much simpler b/c your code
is executed once during init and that’s it. Less chance for error as
well (like out of memory).

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of Praveen Kumar
Amritaluru
Sent: Friday, July 28, 2006 8:46 AM
To: Windows System Software Devs Interest List
Subject: [ntdev] Regd. WDF QueryInterface

Hi Doran,

Thanks a lot for the help so far.

I have another question related to one of the questions I had asked
earlier.

My device will get a QUERY_INTERFACE request for BUS_INTERFACE_STANDARD

from upper layer drivers on the device stack.

I return all routines of the BUS_INTERFACE_STANDARD interfaces I get
from

my parent device except for the BusGetData() wherein I do some
processing.

So, when I register my query interface for BUS_INTERFACE_STANDARD in

ChildDevice creation routine callback, with just GetBusData and leave
out rest empty, will KMDF use my parents

interface routines for BUS_INTERFACE_STANDARD.

For eg. Say

BusInterfaceStandard.Size = sizeof(BUS_INTERFACE_STANDARD);

BusInterfaceStandard.Version = 0x0100;

BusInterfaceStandard.InterfaceHeader.Context = (PVOID) hChild;

/

BusInterfaceStandard.InterfaceReference =

(PINTERFACE_REFERENCE)BusIntf_InterfaceReference;

BusInterfaceStandard.InterfaceDereference =

(PINTERFACE_DEREFERENCE)BusIntf_InterfaceDereference;

/

// Let the framework handle reference counting.

//

BusInterfaceStandard.InterfaceReference =
WdfDeviceInterfaceReferenceNoOp;

BusInterfaceStandard.InterfaceDereference =
WdfDeviceInterfaceDereferenceNoOp;

BusInterfaceStandard.GetBusData =
(PGET_SET_DEVICE_DATA)BusIntf_GetBusData;

WDF_QUERY_INTERFACE_CONFIG_INIT(&BusIntfStdConfig,

&BusInterfaceStandard,

GUID_BUS_INTERFACE_STANDARD,

NULL);

Will the above code work? If upper-layer drivers want to invoke

GetDmaAapter routine to get adapter object, and query for
BUS_INTERFACE_STANDARD

to get the GetDmaAdapter Interface, would they get it interface from my
parent device incase I don’t set it in my

driver processing of this query wherein I set only BusGetData?

Thanks,

-Praveen


Questions? First check the Kernel Driver FAQ at
http://www.osronline.com/article.cfm?id=256

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