From: Om <om.turyx@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: 64 bit PCI access using MMX register -- how?
Date: Wed, 07 Jan 2009 15:03:24 -0800 [thread overview]
Message-ID: <496534BC.4060603@gmail.com> (raw)
Hi,
I have a buggy hardware with many 64 bit registers. (The bug is, when a
64bit read/write is split to two 32bit read/write, under high loads,
hardware would mess up the order of reads/writes. As a result,
read/written values would not be correct).
To avoid data corruption in 32bit Linux, when I implement `readq` as two
back to back `readl`, I need a lock serializing accesses to whole PIO
space. To avoid locking, I implemented suggestion from a friend to use
MMX registers like below.
#if BITS_PER_LONG == 32
static inline void hxge_writeq32(u64 val, void *addr)
{
u64 tmp = 0;
__asm__ __volatile__ (
"movq %%mm0, %[t]\n\t"
"movq %[d], %%mm0\n\t"
"movl %[a], %%eax\n\t"
"movq %%mm0, (%%eax)\n\t"
"movq %[t], %%mm0\n\t"
:[t] "+m"(tmp)
:[a] "r"(addr), [d] "m"(val)
:"%eax"
);
smp_wmb();
return;
}
static inline unsigned long long hxge_readq32(void __iomem *addr)
{
u64 var = 0, tmp = 0xfeedfacedeadbeefULL;
printk(KERN_ERR "addr= %#lx\n", (unsigned long) addr);
__asm__ __volatile__ (
"movq %%mm0, %[t]\n\t"
"movl %[a], %%eax\n\t"
"movq (%%eax), %%mm0\n\t"
"movq %%mm0, %[r]\n\t"
"movq %[t], %%mm0\n\t"
:[r] "=m"(var), [t]"+m"(tmp)
:[a] "r"(addr)
:"%eax"
);
smp_rmb();
printk(KERN_ERR "tmp = %#llx, var = %#llx\n", (unsigned long
long) tmp,
var);
return var;
}
#endif
All the reads return 0xFFFFFFFFFFFFFFFF when tried on ioremap_nocache()
PCI address space.
E.g, output from dmesg:
addr= 0xf9f80010
tmp = 0x0, var = 0xffffffffffffffff
data = 0xffffffffffffffff, da = 0xbc000004
(da is the result of 32bit read on the same address)
Any idea what could be wrong? Any suggestions / pointers?
( I am not subscribed, please CC: me)
I tried reading and writing an ordinary memory location ( a global u64
variable, that is working fine. Only PCI access gives a problem)
PCI access in the form of
val = *((u64*)ioremapped_address)
gets me the expected result. But my question is, is this operation
atomic in 32bit arch?
Thanks,
Om.
next reply other threads:[~2009-01-07 23:04 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-07 23:03 Om [this message]
2009-01-07 23:39 ` 64 bit PCI access using MMX register -- how? Alan Cox
2009-01-08 5:52 ` Andi Kleen
2009-01-08 6:46 ` Roland Dreier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=496534BC.4060603@gmail.com \
--to=om.turyx@gmail.com \
--cc=linux-kernel@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.