BTW, I should mention that rocketboards.org has a lot of project examples and forums for the SoC boards, check out http://rocketboards.org/foswiki/view/projects, there might be something newer than my suggestions that is closer to your target. And http://forum.rocketboards.org/ of course has a lot of discussion on these topics.
--- Quote Start ---
So the function user_peripheral_mmap gets called when the mmap is called from the user space application? If so, what is the physical address we need to pass to the mmap function in the user app?
--- Quote End ---
None, just NULL. The offset passed to mmap is being used as a flag for the driver. Here's how the user space application calls it:
d->csr = (unsigned int *) mmap(NULL, d->csr_len, PROT_READ|PROT_WRITE,
MAP_SHARED, fd, MMAP_REGS);
if(d->csr == MAP_FAILED){
perror("Error mapping buffer");
return 0;
}
--- Quote Start ---
Also in the github link you provided to me, there is a file named as devicetree.template, what is the meaning of "reg = <0x40000000 0x20000>", The DE1-SoC has 1GB DDR3 SDRAM.
--- Quote End ---
The first is address (0x40000000), the second is length (0x20000), but you shouldn't have to actually edit the devicetree, the SoC Embedded Suite (
https://dl.altera.com/soceds/) should have everything you need. You can use the defaults set up for the right device, i.e. something like embedded/examples/hardware/cv_soc_devkit_ghrd.
Rocketboards.org has good defaults for most boards, you might want to check there first if you haven't yet.
--- Quote Start ---
can you provide to me a sample code for a user app trying to allocate memory using the approach you are giving me please.
--- Quote End ---
The user-periph driver and app code above assumes the kernel allocates the buffers and the application uses mmap to get the buffers. The application can then pass that buffer pointer around to any algorithm to write to it, make sure the buffer is synced to the device (ioctl), signal the FPGA by writing control registers, wait for completion, make sure the buffer is synced to the CPU (ioctl) and then read the FPGA-computed result right out of the same pointer. That's one approach. So the user app isn't allocating memory, in this approach, but rather borrowing kernel driver buffers which have shared access between CPU and FPGA.
But also check out the
rocketboards.org projects because there might be newer source code and methods for accelerators than what I describe here.