How to reserve DDR3 memory region for FPGA direct access?

I have a system design that FPGA will generate data, and update to DDR3 of HPS. then notify (interrupts ) HPS. and HPS start to transmit data into PC via Ethernet.

I have few questions of software design in this architecture, please help me to find the solution.

Questions:

  1. How to reserve DDR3 memory region in Linux OS ? (Linux OS will not use this segment of memory).
  2. How to access reserved DDR3 memory region in Linux Application or Linux kernel ?

Thanks in advance.

when creating your u-boot.scr

add the line:
setenv mmcboot ā€˜setenv bootargs console=ttyS0,115200 mem=512M root=${mmcroot} rw rootwait;bootz ${loadaddr} - ${fdtaddr}ā€™

which will allow 512M for Linux (leaving everything else for FPGA)

accessing is a bit more involved (& Iā€™m still figuring it out myself )

hi!!
and also try
memmap=512M$1024M (begining at 1024M for example)
take a look at memmap
https://www.kernel.org/doc/Documentation/kernel-parameters.txt

"
memmap=nn[KMG]$ss[KMG]
[KNL,ACPI] Mark specific memory as reserved.
Region of memory to be reserved is from ss to ss+nn.
Example: Exclude memory from 0x18690000-0x1869ffff
memmap=64K$0x18690000
or
memmap=0x10000$0x18690000
"
or you can also try reserved-memory in your device tree
in kernel /Documentation/devicetree/bindings/reserved-memory.txt

And to access
mmap

bye

Hi,
I planned a similarly architecture in my application and will start to implement them now.
To write the data from FPGA, I can use the upper 512M from my 1GB RAM, when I set the parameter mem=512M in the u-boot scriptā€¦? Is this true?
Have someone any good idea or solution to read the data (from Linux) which are located in the ddr memory? It should be also possible to process the data and write them back from the HPS. (In a further step, the data should be transmitted over Ethernet)

Where is the u-boot-scr file located? Can you elaborate on the steps required? Does only the uboot and perhaps preloader get modified to achieve this, and linux will inherit the reservation? Or do we have to rebuild linux?

hi!
you just create a u-boot.txt file with the kernel parameters
like this:
ā€¦
setenv mmcboot "setenv bootargs console=ttyS0,115200 root=${mmcroot} mem=1020M memmap=4M$1020M rw rootwait;bootz ${loadaddr} - ${fdtaddr}"
run mmcload;
run mmcboot;
ā€¦

Create the u-boot.scr
~/cv_soc_devkit_ghrd/software/spl_bsp/uboot-socfpga/tools/mkimage -A arm -O linux -T script -C none -a 0 -e 0 -n ā€œMy scriptā€ -d u-boot.txt u-boot.scr
(refer http://rocketboards.org/foswiki/view/Documentation/GSRD131ProgrammingFPGA#GSRD_FPGA_Configuration)

Copy it to the fat partition.

For more information
http://blackfin.uclinux.org/doku.php?id=reduce_kernel_memory_footprint&s[]=kernel&s[]=memory

And you dont have to rebuild linux!
bye

Any other Ideas??? or way to do this!!??

Hi,
You can also use a reserved-memory node in your dts file.

Take a look here

Regards,
Fred.

I have tried to reserve memory region in u-boot.scr.

And access reserved memory region in Linux application using mmap(), It seems work.

You can see note of my testing.
download: (1) https://mega.nz/#!a95W1IID!j4LAx0PI-G9Nk7DTh7nsXNv68ziDtmeKtGIsuw0s-Kc
(2) https://mega.nz/#!apgRXYDR!O5QjjIbOaUofs1eCGZzo9nEp45olSP7Xf7aM4OXnWgk

1 Like

Iā€™ve started a design where FPGA uses own DMA to read/write to DDRAM attached to HPS. The tricky part seems to be reserve and found out physical memory adress for a buffer allocated in the app. Iā€™m not reserving memory but instead allocate buffer then figuring out itā€™s physical adress and provide this to DMA (Iā€™m using Scatter Gather DMA). With small amounts of memory it works but I havenā€™t tested yet what happens with large buffers (beyond page size). Translation to physical adress is described in following link but itā€™s more a hack than a portable solution.

https://shanetully.com/2014/12/translating-virtual-addresses-to-physcial-addresses-in-user-space/

Just discovered that this translation of virtual adress to physical doesnā€™t work in user space for me reliably. Sometimes it works but sometimes not!. So I switched to reserving memory and map this from /dev/mem by mmap.

Hi,

Can please tell me how can I use the reserved-memory on a driver?
I have set a node as shown in the link you provided, but after that how can I request or use that memory in my device driver? I need to map that area in my driver.

Regards,
Alex

Hi,

is there a tutorial witch addresses the driver implementation and the hardware part inside the FPGA?

Regards,
Sebastian

Hello there, the link to the kernel-parameters text is broken, probably moved somewhere else?

I have dug out what I think is the same section on the html based documentation from the kernel for version 4.10:

https://www.kernel.org/doc/html/v4.10/admin-guide/kernel-parameters.html?highlight=kernel%20parameters

Hiā€¦i am a new user here. As per my knowledge the tricky part seems to be reserve and found out physical memory adress for a buffer allocated in the app. Iā€™m not reserving memory but instead allocate buffer then figuring out itā€™s physical adress and provide this to DMA. With small amounts of memory it works but I havenā€™t tested yet what happens with large buffers .

pcb assembly

Hi @LUCIANC

I have been able to reserve memory for FPGA and read it using mmap. The issue is the reads are slow. It takes roughly 16 ms to read 1 MByte of data (using memcpy) compared to 4ms for the same amount of data if the data were a local buffer. Any idea on how can we increase the access speed of this memory which is reserved fo FPGA direct access?

Thanks

Hi,

I am also having same requirement with my Intel Stratix-10, I am able to build the linux kernel, and by editing the kernel arguments, able to change the kernel start base address, I would like to access the DDR High memory 0x00000000 from Linux user space application. By using mmap operation I tried to access OCRAM=0xFFE00000 and able write to the OCRAM memory, But not able to access DDR.
I think we need to split DDR memory to user space/kernel space memory to access the DDR from Linux application. if any one able to access the DDR memory from ARM using Linux application. please help me. Thanks in advance

Best Regards,
Prasanna