DMA in a windows kernel service (software only driver)

I want to understand how to allocate DMAble memory in a Windows Software only driver (kernel service)?
IoGetDmaAdapter() takes pdev as argument, a software driver will not have pdev…so how can a software only driver allocate DMAble memory?

Your question does not make a lot of sense. What are you trying to do that
requires ‘dma-able’ memory? Also, in general, all memory can be a dma
target. The exceptions are where the dma device itself has addressing
limitations.
Mark Roddy

1 Like

What do you think “DMAble memory” means?

Thanks Mark and Tim for looking in to my question.

DMAble memory I meant where the device can access the host memory and write some contents in to it.

Why I need DMAble memory?

  • My kernel service (software only driver), sends a command to HW (its a PCI bus master device. Command registers are accessed using PCI BAR). In the command request I also have to give a host address where the HW would DMA the response. I thought of using “AllocateCommonBuffer()” for this purpose.

Why am I accessing HW from a software only driver and not a PnP or miniport driver?

  • It’s a diagnostics only driver(not a IO driver), its purpose is to access the HW using PCI-BAR address for configuring and getting dump of memory and registers.

  • Also I can’t write a filter-driver since it requires the miniport driver to be present.

I am pretty new to Windows environment, so I started with a software driver…is there any other way to achieve this?

Nope, don’t do that. Very bad design. Only the driver(s) loaded for a device should be accessing the device. They own the hardware, and can make assumptions about owning the hardware. The whole point of using the DMA abstractions is so that the PCI bus driver (which understands the DMA requirements) gets involved in the process. If you’re not part of the driver stack for the device, then you don’t have the PCI bus driver below you. You can write a filter driver for any device, whether it has a miniport or not.

What kind/class/type of device is it?

Thanks Tim.
Its a NIC device. My driver is an independent driver, it will not run when we have NDIS miniport driver is running, so it can’t be a filter driver.
(Are u saying I can write a filter driver without NDIS miniport driver being loaded? can u please give me some more details or point me to some sample driver?)

Therefore I have a need to allocate DMAble memory from my software-only-driver.
I understand its not the right way to do. Also looks like this is not even possible??

In Linux, any driver (eg. Character driver) can also allocate a DMAable memory, allocation is not tied to device.

Looks like in Windows, only the driver which has access to HW can allocate DMA(Since IoGetDmaAdater() requires pdev as argument), Is my understanding correct?

How are you going to stop the NDIS miniport from running? You have to disable the driver at which point you should be able to install your driver with an INF and get the hardware resources. Anything less, is madness, because you will not own the hardware.

Just write an ordinary Windows PnP WDF driver. That’s what we do for “special” diagnostic drivers for complex devices that use unique driver models (like, storage adapters). That’s how this is done. Not with a software only driver.

1 Like

@shonnur before you ask how to remove your NDIS driver and install the “diagnostic” one: do not uninstall the NDIS driver. Just replace the .sys file and it should start.

often the necessary support for diagnostics is included in the main driver via a side channel interface