Re: Accessing flash directly from User Space [SOLVED]

2009-11-01 Thread Segher Boessenkool
mmio[0] = address; mmio[1] = data; mb(); eieio is enough here. mmio[3] |= 0x01; /* This triggers an operation -> address=data */ /* probably also need an mb() here, if the following code * depends on the operation to be triggered. */ No, a sync does not guarantee the device has seen the sto

Re: Accessing flash directly from User Space [SOLVED]

2009-10-31 Thread Joakim Tjernlund
Michael Buesch wrote on 31/10/2009 21:35:31: > > On Saturday 31 October 2009 21:14:07 Joakim Tjernlund wrote: > > Michael Buesch wrote on 31/10/2009 17:42:54: > > > > > > On Saturday 31 October 2009 14:26:48 Joakim Tjernlund wrote: > > > > > > > > > > > On Friday 30 October 2009 16:08:55 Alessand

Re: Accessing flash directly from User Space [SOLVED]

2009-10-31 Thread Michael Buesch
On Saturday 31 October 2009 21:14:07 Joakim Tjernlund wrote: > Michael Buesch wrote on 31/10/2009 17:42:54: > > > > On Saturday 31 October 2009 14:26:48 Joakim Tjernlund wrote: > > > > > > > > > On Friday 30 October 2009 16:08:55 Alessandro Rubini wrote: > > > > > > > asm("eieio; sync"); > > > > >

Re: Accessing flash directly from User Space [SOLVED]

2009-10-31 Thread Joakim Tjernlund
Michael Buesch wrote on 31/10/2009 17:42:54: > > On Saturday 31 October 2009 14:26:48 Joakim Tjernlund wrote: > > > > > > > On Friday 30 October 2009 16:08:55 Alessandro Rubini wrote: > > > > > > asm("eieio; sync"); > > > > > > > > > > Hmm... > > > > >: : : "memory" > > > > > > > > > > And, do

Re: Accessing flash directly from User Space [SOLVED]

2009-10-31 Thread Michael Buesch
On Saturday 31 October 2009 14:26:48 Joakim Tjernlund wrote: > > > > > On Friday 30 October 2009 16:08:55 Alessandro Rubini wrote: > > > > > asm("eieio; sync"); > > > > > > > > Hmm... > > > >: : : "memory" > > > > > > > > And, doesn't ";" start a comment in assembly? (no, not on powerpc > > > i

RE: Accessing flash directly from User Space [SOLVED]

2009-10-31 Thread Joakim Tjernlund
> > > On Friday 30 October 2009 16:08:55 Alessandro Rubini wrote: > > > > asm("eieio; sync"); > > > > > > Hmm... > > >: : : "memory" > > > > > > And, doesn't ";" start a comment in assembly? (no, not on powerpc > > it seems) > > > > Yes, I think the barrier is wrong. > > Please try with > > > >

Re: Accessing flash directly from User Space [SOLVED]

2009-10-30 Thread Gabriel Paubert
On Fri, Oct 30, 2009 at 10:46:46AM -0600, Jonathan Haws wrote: > > Michael Buesch wrote: > > > Yes, I think the barrier is wrong. > > > Please try with > > > > > > #define mb() __asm__ __volatile__("eieio\n sync\n" : : : > > "memory") > > > > > > For uncached memory, eieio should be enough.

RE: Accessing flash directly from User Space [SOLVED]

2009-10-30 Thread Jonathan Haws
> Michael Buesch wrote: > > Yes, I think the barrier is wrong. > > Please try with > > > > #define mb()__asm__ __volatile__("eieio\n sync\n" : : : > "memory") > > > For uncached memory, eieio should be enough. I tried eieio alone and it did not work. It needed the above command to take

Re: Accessing flash directly from User Space [SOLVED]

2009-10-30 Thread Scott Wood
On Fri, Oct 30, 2009 at 04:08:55PM +0100, Alessandro Rubini wrote: > > asm("eieio; sync"); > > Hmm... > : : : "memory" > > And, doesn't ";" start a comment in assembly? (no, not on powerpc it seems) ';' is an instruction separator on all GNU as targets that I'm familiar with (though a quic

Re: Accessing flash directly from User Space [SOLVED]

2009-10-30 Thread Micha Nelissen
Michael Buesch wrote: Yes, I think the barrier is wrong. Please try with #define mb()__asm__ __volatile__("eieio\n sync\n" : : : "memory") For uncached memory, eieio should be enough. Micha ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlab

RE: Accessing flash directly from User Space [SOLVED]

2009-10-30 Thread Jonathan Haws
> On Friday 30 October 2009 16:08:55 Alessandro Rubini wrote: > > > asm("eieio; sync"); > > > > Hmm... > > : : : "memory" > > > > And, doesn't ";" start a comment in assembly? (no, not on powerpc > it seems) > > Yes, I think the barrier is wrong. > Please try with > > #define mb() __asm__ __

Re: Accessing flash directly from User Space [SOLVED]

2009-10-30 Thread Michael Buesch
On Friday 30 October 2009 16:08:55 Alessandro Rubini wrote: > > asm("eieio; sync"); > > Hmm... > : : : "memory" > > And, doesn't ";" start a comment in assembly? (no, not on powerpc it seems) Yes, I think the barrier is wrong. Please try with #define mb()__asm__ __volatile__("eieio\n

Re: Accessing flash directly from User Space [SOLVED]

2009-10-30 Thread Alessandro Rubini
> asm("eieio; sync"); Hmm... : : : "memory" And, doesn't ";" start a comment in assembly? (no, not on powerpc it seems) Just to make sure, if you replace msync() with another system call, like "kill(1, 0);" you can verify wether it's really useful or if it's only acting as a barrier. /a

RE: Accessing flash directly from User Space [SOLVED]

2009-10-30 Thread Jonathan Haws
> On Friday 30 October 2009 15:50:22 Jonathan Haws wrote: > > > I suspect that the msync() was merely serving as a very > heavyweight > > > memory barrier. > > > > I did try hacking the mb() calls from the kernel source to use > them in user space, but they had no effect. I still had to include >

Re: Accessing flash directly from User Space [SOLVED]

2009-10-30 Thread Michael Buesch
On Friday 30 October 2009 15:50:22 Jonathan Haws wrote: > > I suspect that the msync() was merely serving as a very heavyweight > > memory barrier. > > I did try hacking the mb() calls from the kernel source to use them in user > space, but they had no effect. I still had to include the calls to

RE: Accessing flash directly from User Space [SOLVED]

2009-10-30 Thread Jonathan Haws
> On Thu, Oct 29, 2009 at 10:00:28AM +0100, Joakim Tjernlund wrote: > > > I have found the problem. It occurred to me in the shower (okay > not really, > > > but most good ideas happen there). > > > > > > What was happening is that I was in fact able to write to the > correct > > > registers. How

Re: Accessing flash directly from User Space [SOLVED]

2009-10-29 Thread Scott Wood
On Thu, Oct 29, 2009 at 10:00:28AM +0100, Joakim Tjernlund wrote: > > I have found the problem. It occurred to me in the shower (okay not really, > > but most good ideas happen there). > > > > What was happening is that I was in fact able to write to the correct > > registers. However, I would tr

RE: Accessing flash directly from User Space

2009-10-29 Thread Jonathan Haws
> Looking through our notes and talking with the engineer > who was performing the tests, it was exactly that - MTD was waiting > for a signal that was produced differently than the hardware > ready signal. By simply polling the flash until the hardware > ready signal toggled we were able to get

Re: Accessing flash directly from User Space

2009-10-29 Thread Joerg Albert
Jonathan, On 10/28/2009 03:45 PM, Jonathan Haws wrote: > Looking through our notes and talking with the engineer > who was performing the tests, it was exactly that - MTD was waiting > for a signal that was produced differently than the hardware > ready signal. By simply polling the flash until

RE: Accessing flash directly from User Space [SOLVED]

2009-10-29 Thread Jonathan Haws
> > > Anyway, to make a long story short, I inserted an msync() after > each > > > assignment to the flash. This resolved my problem and I can now > program my flash. > > > > Ouch, this was news to me too. Calling msync() after every write > kills performance. > > We use mmap(/dev/mem) to access H

RE: Accessing flash directly from User Space [SOLVED]

2009-10-29 Thread Jonathan Haws
> Does O_DIRECT help? (you may need to define _GNU_SOURCE before > #include) Nope, O_DIRECT did not help - in fact it caused the application to crash. Why that is I am not sure, but it crashed. ___ Linuxppc-dev mailing list Linuxppc-dev@lists.ozlabs.o

RE: Accessing flash directly from User Space

2009-10-29 Thread Jonathan Haws
> On Tue, Oct 27, 2009 at 04:52:40PM -0600, Jonathan Haws wrote: > > > Will the device respond to 0x1234 being written at offset zero? > You > > > generally have to poke these things pretty specifically in order > to > > > get > > > them to go into command mode. > > > > > > > It should because that

Re: Accessing flash directly from User Space

2009-10-29 Thread Scott Wood
On Tue, Oct 27, 2009 at 04:52:40PM -0600, Jonathan Haws wrote: > > Will the device respond to 0x1234 being written at offset zero? You > > generally have to poke these things pretty specifically in order to > > get > > them to go into command mode. > > > > It should because that is the first dat

RE: Accessing flash directly from User Space [SOLVED]

2009-10-29 Thread Kenneth Johansson
On Thu, 2009-10-29 at 10:00 +0100, Joakim Tjernlund wrote: > > > > > > On Tue, Oct 27, 2009 at 04:24:53PM -0600, Jonathan Haws wrote: > > > > >> >>> How can I get that pointer? Unfortunately I cannot simply > > > > use > > > > >> the > > > > >> >>> > > > > >> >> address of the flash. Is there som

RE: Accessing flash directly from User Space [SOLVED]

2009-10-29 Thread Joakim Tjernlund
> > > > > > > On Tue, Oct 27, 2009 at 04:24:53PM -0600, Jonathan Haws wrote: > > > > >> >>> How can I get that pointer? Unfortunately I cannot simply > > > > use > > > > >> the > > > > >> >>> > > > > >> >> address of the flash. Is there some magical function call > > > > that > > > > >> >> gives

RE: Accessing flash directly from User Space [SOLVED]

2009-10-29 Thread Joakim Tjernlund
> > > > On Tue, Oct 27, 2009 at 04:24:53PM -0600, Jonathan Haws wrote: > > > >> >>> How can I get that pointer? Unfortunately I cannot simply > > > use > > > >> the > > > >> >>> > > > >> >> address of the flash. Is there some magical function call > > > that > > > >> >> gives me access to that po

RE: Accessing flash directly from User Space [SOLVED]

2009-10-28 Thread Jonathan Haws
> > On Tue, Oct 27, 2009 at 04:24:53PM -0600, Jonathan Haws wrote: > > >> >>> How can I get that pointer? Unfortunately I cannot simply > > use > > >> the > > >> >>> > > >> >> address of the flash. Is there some magical function call > > that > > >> >> gives me access to that portion of the memor

RE: Accessing flash directly from User Space

2009-10-28 Thread Jonathan Haws
> On Tue, 2009-10-27 at 16:52 -0600, Jonathan Haws wrote: > > > Jonathan Haws wrote: > > > > I had thought about using MTD, but decided against it because > with > > > > previous benchmarking that we did with MTD and our custom > driver, > > > we > > > > found that our custom driver was about 10x f

RE: Accessing flash directly from User Space

2009-10-28 Thread Jonathan Haws
> On Tue, Oct 27, 2009 at 04:24:53PM -0600, Jonathan Haws wrote: > >> >>> How can I get that pointer? Unfortunately I cannot simply > use > >> the > >> >>> > >> >> address of the flash. Is there some magical function call > that > >> >> gives me access to that portion of the memory space? > >> >>

Re: Accessing flash directly from User Space

2009-10-28 Thread Josh Boyer
On Tue, Oct 27, 2009 at 04:24:53PM -0600, Jonathan Haws wrote: >> >>> How can I get that pointer? Unfortunately I cannot simply use >> the >> >>> >> >> address of the flash. Is there some magical function call that >> >> gives me access to that portion of the memory space? >> >> >> >> $ man 2 mma

RE: Accessing flash directly from User Space

2009-10-28 Thread Kenneth Johansson
On Tue, 2009-10-27 at 16:52 -0600, Jonathan Haws wrote: > > Jonathan Haws wrote: > > > I had thought about using MTD, but decided against it because with > > > previous benchmarking that we did with MTD and our custom driver, > > we > > > found that our custom driver was about 10x faster. > > > >

RE: Accessing flash directly from User Space

2009-10-27 Thread Jonathan Haws
> Jonathan Haws wrote: > >>> flash[0] = 0x1234; > >>> msync(flash, NOR_FLASH_SIZE, MS_SYNC | MS_INVALIDATE); > >>> printf("flash[0] = %#04x\n", flash[0]); > >>> > >>> That prints flash[0] = 0x7f45. I have verified that I am > reading > >> the correct values. I can display the flash contents

Re: Accessing flash directly from User Space

2009-10-27 Thread Alessandro Rubini
> I realize that. I have a driver written that does exactly that. > However, I need to be able to write to certain registers to setup > the erasure. The driver works perfectly in VxWorks, now I am > porting it to Linux. Most likey you are hit by the compiler reordering the accesses and caching d

Re: Accessing flash directly from User Space

2009-10-27 Thread Scott Wood
Jonathan Haws wrote: flash[0] = 0x1234; msync(flash, NOR_FLASH_SIZE, MS_SYNC | MS_INVALIDATE); printf("flash[0] = %#04x\n", flash[0]); That prints flash[0] = 0x7f45. I have verified that I am reading the correct values. I can display the flash contents in U-Boot and 7f

Re: Accessing flash directly from User Space

2009-10-27 Thread Alessandro Rubini
> Okay, I now have access to the flash memory, however when I write to > it the writes do not take. > (PROT_READ | PROT_WRITE), MAP_PRIVATE, fd, MAP_SHARED. Bill told you. With MAP_PRIVATE you write to a local in-ram copy of the data, not to the original one. /alessandro

RE: Accessing flash directly from User Space

2009-10-27 Thread Jonathan Haws
> > Okay, I now have access to the flash memory, however when I write > to it the writes do not take. I have tried calling msync() on the > mapping to no avail. I have opened the fd with O_SYNC, but cannot > get things to work right. > > > > Here are the calls: > > > > int fd = open("/dev/mem

RE: Accessing flash directly from User Space

2009-10-27 Thread Jonathan Haws
> > Okay, I now have access to the flash memory, however when I write > to > > it the writes do not take. > > > > (PROT_READ | PROT_WRITE), MAP_PRIVATE, fd, > > MAP_SHARED. Bill told you. With MAP_PRIVATE you write to a local > in-ram copy of the data, not to the original on

Re: Accessing flash directly from User Space

2009-10-27 Thread Scott Wood
Jonathan Haws wrote: Okay, I now have access to the flash memory, however when I write to it the writes do not take. I have tried calling msync() on the mapping to no avail. I have opened the fd with O_SYNC, but cannot get things to work right. Here are the calls: int fd = open("/de

RE: Accessing flash directly from User Space

2009-10-27 Thread Jonathan Haws
> >>> How can I get that pointer? Unfortunately I cannot simply use > the > >>> > >> address of the flash. Is there some magical function call that > >> gives me access to that portion of the memory space? > >> > >> $ man 2 mmap > >> > >> You want MAP_SHARED and O_SYNC. > >> > > > > > > To use th

RE: Accessing flash directly from User Space

2009-10-27 Thread Jonathan Haws
> Jonathan Haws wrote: > >>> How can I get that pointer? Unfortunately I cannot simply use > the > >>> > >> address of the flash. Is there some magical function call that > >> gives me access to that portion of the memory space? > >> > >> $ man 2 mmap > >> > >> You want MAP_SHARED and O_SYNC. > >

Re: Accessing flash directly from User Space

2009-10-27 Thread Bill Gatliff
Jonathan Haws wrote: >>> How can I get that pointer? Unfortunately I cannot simply use the >>> >> address of the flash. Is there some magical function call that >> gives me access to that portion of the memory space? >> >> $ man 2 mmap >> >> You want MAP_SHARED and O_SYNC. >> > >

RE: Accessing flash directly from User Space

2009-10-27 Thread Jonathan Haws
> > How can I get that pointer? Unfortunately I cannot simply use the > address of the flash. Is there some magical function call that > gives me access to that portion of the memory space? > > > > $ man 2 mmap > > You want MAP_SHARED and O_SYNC. To use that I need to have a file descriptor t

Re: Accessing flash directly from User Space

2009-10-27 Thread Bill Gatliff
Jonathan Haws wrote: > > How can I get that pointer? Unfortunately I cannot simply use the address of > the flash. Is there some magical function call that gives me access to that > portion of the memory space? > $ man 2 mmap You want MAP_SHARED and O_SYNC. b.g. -- Bill Gatliff b...@bi

Accessing flash directly from User Space

2009-10-27 Thread Jonathan Haws
I know this is probably a really dumb question, but a wise man once said that the only stupid question is the one that is not asked. So, I have written a flash driver in VxWorks that simply addresses the flash directly and handles all the hardware accesses just fine. I am porting that to Linux