DMA initiated by FPGA to RAM

Hello,

My PCI card gets stream of data from a fast serial input. This data is copied to RAM starting from a specified offset.

The DMA to RAM is initiated by the FPGA. The FPGA knows the start address of this RAM. When it gets to the end of the buffer it starts copying from start.

Till now we used AllocateCommonBuffer to allocate a kernel space that gets this data.
The limit of this buffer (in XP) is 128MB.

Can I allocate more that 128MB for this purpose ? How ?

Thanks.

>Can I allocate more that 128MB for this purpose ? How ?
There is a limit which each version of Windows could allow to allocate. Next versions of Windows allow to allocate more memory. In general, it is not good design which relay on particular memory size. Use either more than one transaction or Scatter Gather List, if your hardware support this.

Igor Sharovar

Hello,

Can I allocate virtual memory in user space (but make sure it is physical
RAM) and give this address to the device driver ?

You wrote “Use either more than one transaction or Scatter Gather List”.
How can this help me ?

Thanks,
Zvika.

----- Original Message -----
From:
To: “Windows System Software Devs Interest List”
Sent: Friday, January 21, 2011 0:13
Subject: RE:[ntdev] DMA initiated by FPGA to RAM

> >Can I allocate more that 128MB for this purpose ? How ?
> There is a limit which each version of Windows could allow to allocate.
> Next versions of Windows allow to allocate more memory. In general, it is
> not good design which relay on particular memory size. Use either more
> than one transaction or Scatter Gather List, if your hardware support
> this.
>
> Igor Sharovar
>
> —
> NTDEV is sponsored by OSR
>
> 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

Zvi Vered wrote:

Can I allocate virtual memory in user space (but make sure it is physical
RAM) and give this address to the device driver ?

Of course. However, the user space memory you allocate will not be
physically contiguous. The pages will be spread out across the whole of
the physical memory space. If your hardware can do scatter/gather DMA,
then you’re golden. Otherwise, you still have a problem.

You wrote “Use either more than one transaction or Scatter Gather List”.
How can this help me ?

Scatter/gather DMA is when your hardware has the ability to take a list
of physical address blocks. Less fancy hardware can only DMA to a
single block of continuous addresses. It’s simply impossible to get a
huge physically contiguous block.


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

Dear Mr. Roberts,

Thank you for your detailed answer.

How can I allocate RAM in user space and be sure that it is a Physical RAM (and not on disk) ?

Thanks.

> Can I allocate more that 128MB for this purpose ? How ?

Even 128M allocation of a common buffer (physically contiguous memory) is not guaranteed in Windows.

Several other drivers allocating common buffers - and you fail due to memory fragmentation.

So, either you live with the tiny common buffers, or your hardware must support chain DMA and hardware-defined scatter-gather lists.

Since your device just generates the stream of data serially, the usual Windows way of doing this is to submit lots of tiny IRPs to the device, and let the DMA to run over the IRP’s buffers. On each next IRP’s buffer completion, and interrupt must occur, and its DPC completes this IRP and switches the DMA to the next IRP’s buffer.

Note that, even with this scheme, you must either:
a) support chain DMA in hardware
b) live with internal memcpy() to internal buffers inside Windows DMA support
c) live with tiny IRPs <= PAGE_SIZE each.

Huge common buffer allocations (with the intent of supporting the pathetic chain-DMA-uncapable hardware which, with such pathetic architecture, requires high performance and low latency) are hardly supported.

One more way for dedicated (not end-user) systems: use /MAXMEM boot parameter to exclude some memory from Windows, then find this memory and use it as yours common buffer.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

> Can I allocate virtual memory in user space (but make sure it is physical

RAM)

Impossible.

Common buffers (and underlying MmAllocateContiguousMemory) are the only calls to do this. Kernel mode only.

And yes, huge physically contiguous buffers are just not supported in Windows.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com

“Maxim S. Shatskih” wrote in message
news:xxxxx@ntdev…
>> Can I allocate virtual memory in user space (but make sure it is physical
>> RAM)
>
> Impossible.
>
> Common buffers (and underlying MmAllocateContiguousMemory) are the only
> calls to do this. Kernel mode only.
>
> And yes, huge physically contiguous buffers are just not supported in
> Windows.

Did he ask for contiguous RAM? If not… this is possible.
The driver can make one or more MDLs from the usermode memory and lock them.
Of course, amount of memory that can be mapped into the kernel address space
is limited.

–pa

I think he was asking how to make sure memory allocated in user space would not be paged out to disk.

Zvi,
Look at MmProbeAndLockPages if you’re looking to make sure allocated memory is not paged out. You will want to be using METHOD_DIRECT for data transfers between kernel and user space. Set this either with WdfDeviceInitSetIoType for WDF drivers or by setting your DeviceObject->Flags after calling IoCreateDevice.

> Did he ask for contiguous RAM? If not… this is possible.

Sorry, I was only thinking about the contiguous RAM.

Non-contiguous case (if the HW supports this) is much simpler: just send the read IRP to DO_DIRECT_IO device, and pass Irp->MdlAddress (after a check that it is non-NULL) via the DMA stuff.

You will get the SGL, then convert it to your hardware format and ping the hardware to start the DMA over it.


Maxim S. Shatskih
Windows DDK MVP
xxxxx@storagecraft.com
http://www.storagecraft.com