Multiple Device Support

Hello All,

I have some experience in developing drivers on linux and and a limited level on Windows. Looking into some of the drivers on Linux I noticed that linux allows the developers to use a single driver (kernel module) to register and acquire access to multiple devices.

I was just wandering that is this somehow possible on windows too??? I know that we can specify multiple drivers to register itself for multiple hardware devices in the inf files but what I am really thinking of registering a single driver for multiple devices such as one PCIe and one Hardware timer device.

It might be a stupid idea to start with also but I will appreciate if the Big Guns here can point me to right direction to design something which can achieve such thing.

Regards,
Gaurav

> I was just wandering that is this somehow possible on windows too???

Surely yes.

but what I am really thinking of registering a single driver for multiple devices such as one PCIe and
one Hardware timer device.

Just list 2 HW IDs in the INF file, and ensure the driver’s code can actually support both cases.


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

Hello Maxim,

Thanks for the quick reply.

How the driver will identify the instance/device for which the driver_entry is invoked?

I think one has to read the registry parameters using the DriverObject provided during the driver_entry call, right? but I don’t understand how this is achieved through the INF file.

Can you give some information regarding this or point me to some WDK example or other example where this might be already done?

Thanks and Regards,
Gaurav

Well it certainly would not be in DriverEntry since for a hardware driver it
has not been told yet that there are devices. In AddDevice you can use
IoGetDeviceProperty to get information about the specific device.

I can’t think of any samples for this, because this type of design becomes
very messy. Basically for most service routines you need to have code to
test the device type and then perform the specific device related
operations.

What is the set of devices you feel would be better with a single driver?
There used to be more of these drivers for Windows, I know I replaced a few
with individual drivers for each device, for clients who got sick and tired
of the maintenance headaches.

Don Burn
Windows Filesystem and Driver Consulting
Website: http://www.windrvr.com
Blog: http://msmvps.com/blogs/WinDrvr

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of
xxxxx@gmail.com
Sent: Wednesday, May 14, 2014 8:30 AM
To: Windows System Software Devs Interest List
Subject: RE:[ntdev] Multiple Device Support

Hello Maxim,

Thanks for the quick reply.

How the driver will identify the instance/device for which the driver_entry
is invoked?

I think one has to read the registry parameters using the DriverObject
provided during the driver_entry call, right? but I don’t understand how
this is achieved through the INF file.

Can you give some information regarding this or point me to some WDK example
or other example where this might be already done?

Thanks and Regards,
Gaurav


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

On Wed, May 14, 2014 at 8:50 AM, Don Burn wrote:

> Basically for most service routines you need to have code to
> test the device type and then perform the specific device related
> operations.
>

You use a jump table in the device extension set up when you create the
device extension for the device to route each driver callback to its
appropriate device-type specific callback. If you aren’t allergic to using
c++ the solution is obvious.

Mark Roddy

> How the driver will identify the instance/device for which the driver_entry is invoked?

DriverEntry is invoked once per binary image load.

AddDevice is invoked for each device, and the PDO is provided for it, you can query instance info from it using IoGetDeviceProperty.

I think one has to read the registry parameters using the DriverObject provided during the

Not necessary.

Most important registry values for the instance are maintained by PnP in the kernel, and IoGetDeviceProperty is a way of reading them. If you are not satisfied with this set, then you can add your own and use IoOpenDeviceRegistryKey.

You can also be totally agnostic of the instance info: the driver will just create “device 1” and “device 2”, and both will work, without the clean way of distinguishing them (except by some LEDs on the device or plugging out one of them).

For instance, USB storage flash sticks often do not have USB-level unique ID in them, in this case, the only way of distinguishing them is the FS-level volume label put to the FS as a special file entry. If you have the physically green USB stick, you set the volume label of its FS to “Green”, and so on.

And, if the USB-level unique ID is present, then the OS guarantees (via some non-trivial stuff) that the assigned drive letter for the stick will persist, even if it is plugged to other USB port.


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

xxxxx@gmail.com wrote:

How the driver will identify the instance/device for which the driver_entry is invoked?

I think one has to read the registry parameters using the DriverObject provided during the driver_entry call, right? but I don’t understand how this is achieved through the INF file.

One driver, one DRIVER_OBJECT, one call to DriverEntry, at the point
when the driver is first loaded into memory.

Multiple calls to AddDevice, each with its own DEVICE_OBJECT, each one
handling its own hardware resources. The DEVICE_OBJECT includes your
extension structure, which is where you store the pointers to the
registers and other state information for this instance. Normally, the
devices do not even know that other devices exist.

You probably have many USB hubs in your computer. I have 6 in mine.
They all use usbhub.sys. That driver only gets loaded once. It happens
to have six different DEVICE_OBJECTS that all use its callbacks.

Can you give some information regarding this or point me to some WDK example or other example where this might be already done?

Pretty must EVERY example handles this. You have to go out of your way
NOT to have this ability (usually involving the use of global variables).


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

Well, not if you name your FDOs you don’t. In fact, if you name your FDOs you have to be sure to create unique names and support multiple device instances… using, as Mr. Roberts said, global variables or whatever.

But Mr. Roberts is correct: The examples in the WDK almost universally support this basic feature.

Peter
OSR
@OSRDrivers
(well known supporter of named FDOs)