PNP device dev in a VM

Hey. Regarding PnP devices, when plugged in they load a .INF file associated with them. Can I emulate this behavior in VMWare for example, even though all it’s PnP devices are virtual and supported, i.e. you plug in a USB and you’re asked if you want to use host/guest connection, or a mouse, etc, but some devices I plug in can’t be passed through.

So I want to create a basic PNP device where I can emulate and trigger the “h/w eject” and “h/w insert” functionality to test my .INF/driver that will be loaded/unloaded when Windows processes the PNP action. Any ddk samples/ideas to create this fake PNP device.

Toaster project should help: https://github.com/microsoft/Windows-driver-samples/tree/master/general/toaster/toastDrv It creates a bus driver that simulates device insertions, ejections, etc.

So I want to create a basic PNP device where I can emulate and trigger the “h/w eject” and “h/w insert” functionality to test my .INF/driver

Hmmmmm… what KIND of device do you want to emulate? In general, VMWare doesn’t provide the ability to pass, for example, PCIe devices through to the VM.

Tell us more about your device and what you want to do.

Peter

@“Peter_Viscarola_(OSR)” said:

So I want to create a basic PNP device where I can emulate and trigger the “h/w eject” and “h/w insert” functionality to test my .INF/driver

Hmmmmm… what KIND of device do you want to emulate? In general, VMWare doesn’t provide the ability to pass, for example, PCIe devices through to the VM.

Tell us more about your device and what you want to do.

Peter

A PCI device. Yes VMWare doesn’t, hence I want to emulate this behavior of IRP_MN_SURPRISE_REMOVAL and the driver being removed, then rescan (or add device trigger) to load the driver again. So I can test the INF/driver associated with multiple load/unload/remove events based on the device being ejected/inserted.

Yes @MichaelK that toastDrv looked interesting, seems I need to create a Bus driver. Any sample code in WDM instead of KMDF? I’ve been reading how PNP works and seems I could use IoInvalidateDeviceState, which I did not see in that KMDF project.

The first rule of OSR is:
You do write drivers in KMDF.
The second rule of OSR is:
You do write drivers in KMDF.

KMDF is just a wrapper over WDM that makes your life and life of your customers easier. Also, it’s open source and avail at github: https://github.com/microsoft/Windows-Driver-Frameworks/tree/master/src/framework/kmdf

If, after all, you still want WDM Toaster, do search older WDK.
IIRC, Toaster of WDK 7 still was a WDM driver.

Simulating a hardware device, including arrival and departure, is a rather difficult undertaking. It could be that you only want to emulate a small subset of stuff, but still… a big job. Unless you have a lot of free time and absolutely no money, you’d be way better off just buying a bunch of systems to test on.

Bus drivers in WDM are exceptionally annoying and complex to write. In KMDF, they’re almost a joy. “The first rule of OSR is…”

Peter

“The first rule of OSR is…”
Never miss opportunity to have some joy at work? :slight_smile:

Simulation of PCI(e) devices is quite common for hardware developers, but if the OP wants pure software - he can use VirtualBox
instead of VMware (opensource), he can look at Qemu…
The real question is - why? Just for joy?

– pa