Atomic 64 bit write access on PCIe device
Hi everybody,
perhaps this issue is off-topic, but I expect that there are many experts on that issue reading the Xenomai list... I have a Core2Duo Intel CPU (32 bit mode) and a proprietary PCI Express I/O board plugged in. This PCI Express I/O board has some 64 bit registers that are mapped into address space via mmap. Now, I want to write atomically (one PCIe access) to one of the 64 bit registers.
Unfortunately, the Intel CPUs does not have an atomic 64 bit write operations when running the CPU in 32 bit mode. When doing something like
volatile unsigned long long *ull = register_address; *ull = my_new_register_value;
I see the gcc is generating two 32 bit write accesses. Of course this will not lead to an atomic 64 bit write access.
Any idea, how I can write 64 bit integers atomically to such an 64 bit register?
Thanks for any feedback!
Regards
Mathias
Signature · 9 lines
Mathias Koehrer [email protected] Viel oder wenig? Schnell oder langsam? Unbegrenzt surfen + telefonieren ohne Zeit- und Volumenbegrenzung? DAS TOP ANGEBOT FÜR ALLE NEUEINSTEIGER Jetzt bei Arcor: günstig und schnell mit DSL - das All-Inclusive-Paket für clevere Doppel-Sparer, nur 29,95 Euro inkl. DSL- und ISDN-Grundgebühr! http://www.arcor.de/rd/emf-dsl-2
Quoted 12 lines · M. Koehrer
Hi everybody,
perhaps this issue is off-topic, but I expect that there are many experts on that issue reading the Xenomai list... I have a Core2Duo Intel CPU (32 bit mode) and a proprietary PCI Express I/O board plugged in. This PCI Express I/O board has some 64 bit registers that are mapped into address space via mmap. Now, I want to write atomically (one PCIe access) to one of the 64 bit registers.
Unfortunately, the Intel CPUs does not have an atomic 64 bit write operations when running the CPU in 32 bit mode. When doing something likevolatile unsigned long long *ull =
register_address; *ull =my_new_register_value;
Quoted 6 lines
I see the gcc is generating two 32 bit write accesses. Of course this will not lead to an atomic 64 bit write access.
Any idea, how I can write 64 bit integers atomically to such an 64 bit register?
Thanks for any feedback!
Maybe using a spinlock would be possible ?
I do not think that using inline assembly would work (I would expect the assembler to refuse 64 bits instructions when in 32 bits mode). Why not compiling the kernel and Xenomai in 64 bits mode ?
Signature · 1 line
Gilles Chanteperdrix
Quoted 9 lines · M. Koehrer
Hi everybody,
perhaps this issue is off-topic, but I expect that there are many experts on that issue reading the Xenomai list... I have a Core2Duo Intel CPU (32 bit mode) and a proprietary PCI Express I/O board plugged in. This PCI Express I/O board has some 64 bit registers that are mapped into address space via mmap. Now, I want to write atomically (one PCIe access) to one of the 64 bit registers.
Unfortunately, the Intel CPUs does not have an atomic 64 bit write operations when running the CPU in 32 bit mode. When doing something like
Quoted 7 lines
volatile unsigned long long *ull =
register_address; *ull =my_new_register_value;I see the gcc is generating two 32 bit write accesses. Of course this will not lead to an atomic 64 bit write access.
Any idea, how I can write 64 bit integers atomically to such an 64 bit register?
Assuming this register may only be accessed from userland through mmapped memory (and not concurrently from a kernel driver), and that you may write this value as 2 x 32bit as far as the hw is concerned but you want to avoid software access races doing so, something like this would probably do:
iopl(3)
...mutex_lock(&lock); /* prevent SMP race */ asm volatile("cli"); /* prevent local preemption */ *ull = my_new_register_value;
asm volatile("sti");mutex_unlock(&lock);
Yeah, that's pretty ugly. Yum.
Quoted 7 lines
Thanks for any feedback!
Regards
Mathias
Signature · 1 line
Philippe.