From: "Michael K. Edwards" <medwards.linux@gmail.com>
To: "Linux Kernel List" <linux-kernel@vger.kernel.org>
Subject: Should io(read|write)(8|16|32)_rep take (const|) volatile u(8|16|32) __iomem *addr?
Date: Thu, 1 Feb 2007 16:35:44 -0800 [thread overview]
Message-ID: <f2b55d220702011635s5b338a6ct861645ea7892f732@mail.gmail.com> (raw)
In-Reply-To: <f2b55d220702011624v6cb13c8ct1d70863a661d2227@mail.gmail.com>
Sorry, I wrote this:
> (This is not an ARM-specific question, although the example is on ARM.)
and then sent it to linux-arm-kernel anyway. :-P
I'm writing an ALSA driver for an ARM SoC whose PCM audio interface is
MMIO. ALSA provides copy_from_user_toio and copy_to_user_fromio
routines for this purpose, but the results are not sane, perhaps
because STMIA to I/O addresses is bollixed on this core. I suspect
that the right thing to do is to use iowrite32_rep and ioread32_rep,
approximately like so (slightly modified ALSA code):
/**
* copy_u32s_to_user_fromio - copy data from mmio-space to user-space
* @dst: the destination pointer on user-space
* @src: the source pointer on mmio
* @count: the data size to copy in u32s
*
* Copies the data from mmio-space to user-space.
*
* Returns zero if successful, or non-zero on failure.
*/
static int copy_u32s_to_user_fromio(void __user *dst, const volatile
void __iomem *src, size_t count)
{
u32 buf[80];
count <<= 2;
while (count) {
size_t c = count;
if (c > sizeof(buf))
c = sizeof(buf);
ioread32_rep(src, buf, c>>2);
if (copy_to_user(dst, buf, c))
return -EFAULT;
count -= c;
dst += c;
src += c;
}
return 0;
}
/**
* copy_u32s_from_user_toio - copy data from user-space to mmio-space
* @dst: the destination pointer on mmio-space
* @src: the source pointer on user-space
* @count: the data size to copy in u32s
*
* Copies the data from user-space to mmio-space.
*
* Returns zero if successful, or non-zero on failure.
*/
static int copy_u32s_from_user_toio(volatile void __iomem *dst, const
void __user *src, size_t count)
{
u32 buf[80];
count <<= 2;
while (count) {
size_t c = count;
if (c > sizeof(buf))
c = sizeof(buf);
if (copy_from_user(buf, src, c))
return -EFAULT;
iowrite32_rep(dst, buf, c>>2);
count -= c;
dst += c;
src += c;
}
return 0;
}
Compiling (with GCC 4.1.2 RC1) gives these warnings:
foo.c: In function 'copy_u32s_to_user_fromio':
foo.c:56: warning: passing argument 1 of '__raw_readsl' discards
qualifiers from pointer target type
foo.c: In function 'copy_u32s_from_user_toio':
foo.c:86: warning: passing argument 1 of '__raw_writesl' discards
qualifiers from pointer target type
The qualifiers being discarded are the "volatile"s, which are indeed
not present in the declarations of these functions (which happen to be
ARM's implementation of io(read|write)32_rep):
include/asm-arm/io.h:extern void __raw_writesb(void __iomem *addr,
const void *data, int bytelen);
include/asm-arm/io.h:extern void __raw_writesw(void __iomem *addr,
const void *data, int wordlen);
include/asm-arm/io.h:extern void __raw_writesl(void __iomem *addr,
const void *data, int longlen);
include/asm-arm/io.h:extern void __raw_readsb(const void __iomem
*addr, void *data, int bytelen);
include/asm-arm/io.h:extern void __raw_readsw(const void __iomem
*addr, void *data, int wordlen);
include/asm-arm/io.h:extern void __raw_readsl(const void __iomem
*addr, void *data, int longlen);
It looks to me, by comparison to memcpy_(from|to)io, as if the
volatiles ought to be there. It also looks to me like the void *
parameters should be u(8|16|32) * instead, so the compiler knows what
alignment to expect (the implementations would generally fail or suck
on non-aligned arguments). (That would also be more consistent with
the fact that the length parameters are in (8|16|32)-bit units, not
octets.)
Opinions?
Cheers,
- Michael
next parent reply other threads:[~2007-02-02 0:35 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <f2b55d220702011624v6cb13c8ct1d70863a661d2227@mail.gmail.com>
2007-02-02 0:35 ` Michael K. Edwards [this message]
2007-02-02 3:15 ` H. Peter Anvin
2007-02-02 6:04 ` Jeff Garzik
2007-02-02 6:30 ` H. Peter Anvin
2007-02-02 11:07 ` Jeff Garzik
2007-02-02 19:58 ` Michael K. Edwards
2007-02-02 21:40 ` Jeff Garzik
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=f2b55d220702011635s5b338a6ct861645ea7892f732@mail.gmail.com \
--to=medwards.linux@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®