Skip to contentSkip to conversation

need advice on howto access memory from fpga and cpu

DISCUSSION Kai 3 participants 7 messages Oct 30, 2013 – Oct 31, 2013

lore
Share & tools
lore

Kai

author
#0 lore raw

Greetings,

I need advice about a programming project I am doing at my university. The goal basically is to implement a framebuffer in RAM on a Zedboard SoC (www.zedboard.org).

The problem is, that both the integrated FPGA and "the software" need to access the framebuffer, e.g. need access to the same memory region. I am not sure if I have to write a kernel driver for this at all, or if it's sufficient to do some mmap'ing on /dev/mem from userspace. Also, it would be really nice if I could reserve some memory (< 1MB), so that Linux will not touch it, and the framebuffer will always lie@the same address in RAM. Otherwise I would have to tell the FPGA the addresses. I don't really need direct memory access from userspace, I just have to get some images out of the vga port.

So my plan currently is to tell Linux somehow to not touch the first X bytes of the RAM. Thus the memory region of the framebuffer is already known. Then I want to implement a kernel driver that's setting up a character device, say /dev/fb0, to receive frames from userspace.

I already read this[1] post on Stackoverflow, which is going in the right direction, and started reading "Linux Device Drivers 3rd Edition", but I would really like to get some comment from the more experienced programmers, whether there's a better approach to this.

[1] http://stackoverflow.com/questions/647783/direct-memory-access-in-linux

Signature · 3 lines
Gr??e, Kai

"In a world without walls and fences, who needs Windows and Gates?"
author
#1 lore raw
Quoted 2 lines · srinivas bakki

But otherwise am wondering why would you need to tell the FPGA these kernel mapped addresses ? How is it connected to the memory module ?

The FPGA seems to have direct access to the memory. If I would allocate memory for the framebuffer dynamically, I would first have to find out the physical adress of this area, and then tell it to the FPGA, so it can read the frames from there. We are implementing a "GPU" on the FPGA here, or at least something that's reading frames from the RAM, to send it to the VGA port.

Signature · 3 lines
Gr??e, Kai

"In a world without walls and fences, who needs Windows and Gates?"
#2 lore raw

If you don't want dynamic memory allocation for framebuffer and neither do you want it in the user space, All you need is to pass
memmap = <size>$<start address> to the kernel and then write a kernel module module where you ioremap that physical address space.

This is just like any other device driver where device registers are mapped.

Quoted 13 lines · Kai
Quoted 2 lines · srinivas bakki

But otherwise am wondering why would you need to tell the FPGA these kernel mapped addresses ? How is it connected to the memory module ?

The FPGA seems to have direct access to the memory. If I would allocate memory for the framebuffer dynamically, I would first have to find out the physical adress of this area, and then tell it to the FPGA, so it can read the frames from there. We are implementing a "GPU" on the FPGA here, or at least something that's reading frames from the RAM, to send it to the VGA port.
--
Gr??e, Kai

Quoted 7 lines

"In a world without walls and fences, who needs Windows and Gates?"

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131030/fb593324/attachment.html

author
#3 lore raw
Quoted 6 lines · srinivas bakki

If you don't want dynamic memory allocation for framebuffer and neither do you want it in the user space, All you need is to pass
memmap = <size>$<start address> to the kernel and then write a kernel module module where you ioremap that physical address space.

This is just like any other device driver where device registers are mapped.

Thanks for your answers, it sounds very straightforward.

One more question: Currently I'm using the book Linux Device Drivers 3rd Edition (2005) as a reference, and it's discussing Kernel 2.6.10. Do you think that's still okay, or should I get/buy a more recent book on this topic, and which would you recommend?

Signature · 3 lines
Gr??e, Kai

"In a world without walls and fences, who needs Windows and Gates?"
#4 lore raw
Quoted 4 lines · Kai

One more question: Currently I'm using the book Linux Device Drivers 3rd Edition (2005) as a reference, and it's discussing Kernel 2.6.10. Do you think that's still okay, or should I get/buy a more recent book on this topic, and which would you recommend?

The concepts are all valid (when you need locking, stuff like that), but
many of the APIs have been changed. Fortunately, it's kernel policy that
when an API is changed, we change not only the semantics, but also the
signature of the function (name, number of parameters, etc), so old code
will throw a compile error rather than mysteriously bomb at runtime.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 865 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131030/765413a9/attachment.bin

#5 lore raw
In reply to Kai
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line

Thanks for your answers, it sounds very straightforward.

ofcourse it's straightforward. Believe me its not really difficult to write low level drivers in linux. You should be more comfortable with the hardware to write low level stuff. Beauty of linux is the framework it provides to make to it so easy !

Quoted 19 lines · Kai
Quoted 1 line · srinivas bakki

If you don't want dynamic memory allocation for framebuffer and neither

do

Quoted 5 lines

you want it in the user space, All you need is to pass memmap = <size>$<start address> to the kernel and then write a kernel module module where you ioremap that physical address space.

This is just like any other device driver where device registers are

mapped.

Thanks for your answers, it sounds very straightforward.

One more question: Currently I'm using the book Linux Device Drivers 3rd Edition (2005) as a reference, and it's discussing Kernel 2.6.10. Do you think that's still okay, or should I get/buy a more recent book on this topic, and which would you recommend?
--
Gr??e, Kai

Quoted 7 lines

"In a world without walls and fences, who needs Windows and Gates?"

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20131031/30b6f8d8/attachment.html

author
#6 lore raw

Thank you guys, you helped me a lot!

Signature · 3 lines
Gr??e, Kai

"In a world without walls and fences, who needs Windows and Gates?"