Specifying device type from a bus driver

I’ve been working on developing a device driver for a virtual device. Naturally enough this resulted in a need to cause the system load the driver for my device and call add device at least once. Being a virtual device I initially used the root bus for that. However I wasn’t satisfied with that solution because I couldn’t figure out a way of adding and removing instances of the virtual device at runtime. The next step was to create a bus driver, based on the MS Toaster sample bus driver. For the most part I understand what is going on, or at least I’d like to think so.

The one thing that I can’t figure out is how the creation of the bus’s PDO leads to the call to the AddDevice function in my virtual device’s driver. Essentially I think that I understand the process of calling IoCreateDevice then telling the system to ask for new BusRelations. You then add the bus driver’s PDO to the resulting query, which should eventually result in a call to AddDevice. But how does the system know that the PDEVICE_OBJECT that you return here corresponds with the virtual driver? I guess that I should also canvass the possibility that I am going the wrong way and need to try a different tack.

I hope that all makes some semblance of sense, and that I’m not completely wrong on all counts.

Thanks in advance

Richard McNally

You need to split your thinking into separate “functions”. Split the
idea into 2 drivers.

Your virtual bus driver enumerates PDOs. Each PDO is an instance of
your virtual device. The PDO is itself is no the virtual device itself,
it is the root of that virtual device’s stack. This will load your
functional device drive and call it’s AddDevice routine.

The function driver is the same driver you had before, except now the
bus stuff is split out.

Now, you can join these 2 functions into one driver image. The problem
now becomes how do you distinguish between an AddDevice for a bus part
vs an AddDevice for function part. One very easy way is to query for
the enumerator (IoGetDeviceProperty) of the PDO. Your bus part will
have ROOT as the enumerator. When you enumerate the PDO, use a unique
enumerator name (a GUID in string form is highly recommended). This
name is known to your functiona part so it knows how to find itself.

d

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com] On Behalf Of McNally, Richard
Sent: Monday, January 31, 2005 3:33 PM
To: Windows System Software Devs Interest List
Subject: [ntdev] Specifying device type from a bus driver

I’ve been working on developing a device driver for a virtual device.
Naturally enough this resulted in a need to cause the system load the
driver for my device and call add device at least once. Being a virtual
device I initially used the root bus for that. However I wasn’t
satisfied with that solution because I couldn’t figure out a way of
adding and removing instances of the virtual device at runtime. The next
step was to create a bus driver, based on the MS Toaster sample bus
driver. For the most part I understand what is going on, or at least I’d
like to think so.

The one thing that I can’t figure out is how the creation of the bus’s
PDO leads to the call to the AddDevice function in my virtual device’s
driver. Essentially I think that I understand the process of calling
IoCreateDevice then telling the system to ask for new BusRelations. You
then add the bus driver’s PDO to the resulting query, which should
eventually result in a call to AddDevice. But how does the system know
that the PDEVICE_OBJECT that you return here corresponds with the
virtual driver? I guess that I should also canvass the possibility that
I am going the wrong way and need to try a different tack.

I hope that all makes some semblance of sense, and that I’m not
completely wrong on all counts.

Thanks in advance

Richard McNally


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

You are currently subscribed to ntdev as: xxxxx@windows.microsoft.com
To unsubscribe send a blank email to xxxxx@lists.osr.com

>But how does the system know that the PDEVICE_OBJECT that you return here

corresponds with the virtual driver?

Your PDO has some hardware id assigned by you (BUS_HARDWARE_IDS for
toaster). The INF file of your virtual function driver associates this id
with the function driver name. The system then loads your function driver by
name.


http://www.firestreamer.com - NTBackup to DVD and DV

“McNally, Richard” wrote in message
news:xxxxx@ntdev…
> I’ve been working on developing a device driver for a virtual device.
> Naturally enough this resulted in a need to cause the system load the
> driver for my device and call add device at least once. Being a virtual
> device I initially used the root bus for that. However I wasn’t satisfied
> with that solution because I couldn’t figure out a way of adding and
> removing instances of the virtual device at runtime. The next step was to
> create a bus driver, based on the MS Toaster sample bus driver. For the
> most part I understand what is going on, or at least I’d like to think so.
>
> The one thing that I can’t figure out is how the creation of the bus’s PDO
> leads to the call to the AddDevice function in my virtual device’s driver.
> Essentially I think that I understand the process of calling
> IoCreateDevice then telling the system to ask for new BusRelations. You
> then add the bus driver’s PDO to the resulting query, which should
> eventually result in a call to AddDevice. But how does the system know
> that the PDEVICE_OBJECT that you return here corresponds with the virtual
> driver? I guess that I should also canvass the possibility that I am going
> the wrong way and need to try a different tack.
>
> I hope that all makes some semblance of sense, and that I’m not completely
> wrong on all counts.
>
> Thanks in advance
>
> Richard McNally
>

> The one thing that I can’t figure out is how the creation of the bus’s PDO
leads to the call to

AddDevice function in my virtual device’s driver.

  • PnP sends MN_QUERY_RELATIONS
  • you respond with your PDO(s)
  • PnP enlists it in its tree, builds a DeviceObjectExtension additional
    structure (“devnode”)
  • PnP send MN_QUERY_ID to your PDO
  • based on these IDs, PnP sets up the registry location for a PDO
  • then PnP handles the work to user-mode-PnP
  • user-mode-PnP finds the INF file with such a hardware ID, if found - executes
    it, it causes some registry values to be added to your PDO’s key, one of them
    is driver name
  • user-mode-PnP returns to kernel-mode-PnP
  • PnP loads the driver whose name is in the PDO’s key, and calls its AddDevice.

Maxim Shatskih, Windows DDK MVP
StorageCraft Corporation
xxxxx@storagecraft.com
http://www.storagecraft.com