I'm currently programming a Linux Kernel driver, which needs to tell a FPGA a base address in RAM to write to.
The memory is allocated in the kernel driver with dma_alloc_coherent
.
This will generate a 32 bit physical address and a kernel virtual address, the physical address is being passed to the FPGA.
The FPGA is a Cyclone V with embedded ARM Cortex-A9, on which an embedded Linux with the driver is running.
The problem now is, that the FPGA fabric only generates a 27 bit wide bus to address the sdram, while the physical address, that is being generated by the dma call has 32 bits, e.g. th physical address has been 0x2f220000
, which exceeds 27 bit span.
I want to know, if it is okay to mask the most significant 5 bits and tell the FPGA the address 0x7220000
and still have the correct behaviour (In doc it is stated, that the physical address shall be casted to buswidth, that would mean masking, because I can't use 27 bit in processor).
Also is it okay to access the DMA memory with a simple memcpy command, that copies from the kernel virtual address to a buffer?
Thanks in advance.
1
votes
Perhaps the FPGA write 32bytes at a time? 2^5 is 32 so the least significant bits of the address don't matter. Are you sure it is the top 5 bits that the FPGA ignores? Probably AXI bus is 32bytes wide in the system. I think 32/64 or even 128 are possible.
– artless noise
@artlessnoise Bus widths are usually measured in bits, and not in bytes.
– 0andriy
Are you talking about DMA mask (addressable space as [0, 2^27 - 1] and most significant bits are kept 0) or about alignment (least significant bits should be always 0)?
– 0andriy
1 Answers
2
votes
The answer truly depends on the physical memory layout of your device. If the address bus of the FPGA complements the missing bits so that the actual address resolves to the correct memory, then masking is, probably, okay. If not, then it is possible that the memory that the Linux kernel returned to you is simply in accessible to the FPGA. If that's the case, you will have to find a way to ask Linux to only give you buffers from memory that is accessible.