Question on loading firmware into PCIe device.

Hi,

I’d like to get an answer to a question and some ideas/feedback on a good way to load a firmware binary into my PCIe device.

The card requires that I specify the address of the firmware code in system memory using four 16 bit registers (it can support a 64 bit address) and two 16 bit registers for the length. Then write a command to another register to cause it to read the data from system memory. The firmware binary is approx 256kb.

My game plan so far is to read the firmware binary off disk and into a WDFMemory object during DriverEntry. This way if the file is not found or something is wrong with it, I can fail the driver early (also the framework will clean up the memory object for me when the driver unloads).

Next in the EvtDeviceAdd callback I’ll set up a WDFDMAEnabler and WDFCommonBuffer. I’ll need this later anyway for other DMA operations.

The routine to actually load the firmware into the device will probably be called from EvtDeviceD0EntryPostInterruptsEnabled.
In this routine I plan to copy the data from the WDFMemory buffer to the WDFCommonBuffer, then start a DMA transaction.

Here’s where I hit a bit of a snag. The WdfDmaTransactionInitialize function requires an MDL and a VirtualAddress.
I’m assuming I can supply the virtual address of the WDFCommonBuffer, but where do I get the MDL from?
Do I need to call IoAllocateMdl and MmBuildMdlForNonPagedPool and then pass that to the WdfDmaTransactionInitialize function?

Thanks,
Erik

Ah! I just did this… don’t use a DMA transaction. Instead, just pass the Logical address of the Common Buffer to your device to use in its DMA operation. Done!

Peter

Thanks Peter. This feels like one of those “duh!” moments where the answer was right in front of my face and I didn’t see it. For some reason I was thinking the “map registers” part of it happened later in the DMA process.