Using volatile and the framebuffer setup


2 posts
by richcole » Mon Nov 05, 2012 7:46 am
I tried using the framebuffer this weekend and seemed to get into some trouble using volatile. Here is my code:

https://github.com/richcole/RaspberryPi ... framebuf.c

I thought I could get away with declaring structures volatile and that gcc would do the right thing ensuring that full reads from memory were taking place rather than from registers. I also presumed things would work with respect to any caches between the processor and main memory.

My program works with optimizations turned off. But if I compile with -O or -O2 then my program doesn't work. The framebuf_info->ptr never gets initialized whether I loop waiting for it. It also doesn't work if I loop sending messages to the vidcore to setup the frame buffer.

Is there a canonical way to deal with this message box thing and memory shared with the vidcore? Is volatile not to be trusted? I noted a linux article that says you can't trust volatile on all architectures and so it shouldn't be used the linux kernel.

http://www.mjmwired.net/kernel/Document ... armful.txt

While I'm linking. I got going with framebuffer by copying this

https://github.com/G7TNZ/RPi-kernel
Posts: 21
Joined: Sat Dec 10, 2011 11:54 pm
by richcole » Mon Nov 05, 2012 8:05 am
I found the answer in this forum:

viewtopic.php?p=189643#p189643

There is a cache in the vidcore. Yikes, but at least the answer is simple. Add 0x40000000 to addresses that you give the vidcore and then it will skip its cache when writing to them.

https://github.com/richcole/RaspberryPi ... 63803a15ab

regards,

Richard.
Posts: 21
Joined: Sat Dec 10, 2011 11:54 pm