From: Arnd Bergmann <arnd@arndb.de>
To: linuxppc-dev@ozlabs.org
Subject: Re: [PATCH/RFC] Hookable IO operations
Date: Sat, 4 Nov 2006 01:15:34 +0100 [thread overview]
Message-ID: <200611040115.34235.arnd@arndb.de> (raw)
In-Reply-To: <1162594589.10630.135.camel@localhost.localdomain>
On Friday 03 November 2006 23:56, Benjamin Herrenschmidt wrote:
>
> > Did you never consider this, or did you make your mind up in the
> > process?
>
> I considered this and decided against it while doing the macro since I
> could get the hooks auto-generated easier as globals, but I can still
> change it, it's not that much bloat and might indeed look nicer.
I've just tried hacking something up, this is the best I could come up
with using the structure:
/* are these all we need, or did I miss any? */
struct ppc_io {
void (*writeb)(u8 val);
void (*writew)(u16 val);
void (*writel)(u32 val);
void (*writeq)(u64 val);
u8 (*readb)(void);
u16 (*readw)(void);
u32 (*readl)(void);
u64 (*readq)(void);
void (*outb)(u8 val);
void (*outw)(u16 val);
void (*outl)(u32 val);
void (*outq)(u64 val);
u8 (*inb)(void);
u16 (*inw)(void);
u32 (*inl)(void);
u64 (*inq)(void);
void (*memset_io)(volatile void __iomem *addr, int c, unsigned long n);
void (*memcpy_fromio)(void *dest,
const volatile void __iomem *src, unsigned long n);
void (*memcpy_toio)(volatile void __iomem *dest,
const void *src, unsigned long n);
} ppc_io;
/* all these should be static inline or extern */
void direct_writeb(u8 val);
void direct_writew(u16 val);
void direct_writel(u32 val);
void direct_writeq(u64 val);
u8 direct_readb(void);
u16 direct_readw(void);
u32 direct_readl(void);
u64 direct_readq(void);
void direct_outb(u8 val);
void direct_outw(u16 val);
void direct_outl(u32 val);
void direct_outq(u64 val);
u8 direct_inb(void);
u16 direct_inw(void);
u32 direct_inl(void);
u64 direct_inq(void);
void direct_memset_io(volatile void __iomem *addr, int c,
unsigned long n);
void direct_memcpy_fromio(void *dest,
const volatile void __iomem *src, unsigned long n);
void direct_memcpy_toio(volatile void __iomem *dest,
const void *src, unsigned long n);
/* a simple indirection more than your code, going
through the structure */
#ifdef CONFIG_INDIRECT_IO
#define ppc_io_indirect(x) ppc_io.x
#else
#define ppc_io_indirect(x) NULL
#endif
#define DEF_IO_OUT(name, arg) \
static inline void name(arg val) \
{ \
if (ppc_io_indirect(name)) \
return ppc_io.name(val); \
else \
return direct_ ## name(val); \
}
#define DEF_IO_IN(name, arg) \
static inline arg name(void) \
{ \
if (ppc_io_indirect(name)) \
return ppc_io.name(); \
else \
return direct_ ## name(); \
}
DEF_IO_OUT(writeb, u8)
DEF_IO_OUT(writew, u16)
DEF_IO_OUT(writel, u32)
DEF_IO_OUT(writeq, u64)
DEF_IO_IN(readb, u8)
DEF_IO_IN(readw, u16)
DEF_IO_IN(readl, u32)
DEF_IO_IN(readq, u64)
DEF_IO_OUT(outb, u8)
DEF_IO_OUT(outw, u16)
DEF_IO_OUT(outl, u32)
DEF_IO_OUT(outq, u64)
DEF_IO_IN(inb, u8)
DEF_IO_IN(inw, u16)
DEF_IO_IN(inl, u32)
DEF_IO_IN(inq, u64)
/* using variadic macros makes this somewhat simpler
* than writing the whole prototype */
#define memset_io(arg...) \
do { \
if (ppc_io_indirect(memset_io)) \
ppc_io.memset_io(arg); \
else \
direct_memset_io(arg); \
} while (0)
#define memcpy_fromio(arg...) \
do { \
if (ppc_io_indirect(memcpy_fromio)) \
ppc_io.memcpy_fromio(arg); \
else \
direct_memcpy_fromio(arg); \
} while (0)
#define memcpy_toio(arg...) \
do { \
if (ppc_io_indirect(memcpy_toio)) \
ppc_io.memcpy_toio(arg); \
else \
direct_memcpy_toio(arg); \
} while (0)
next prev parent reply other threads:[~2006-11-04 0:15 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-11-03 21:12 [PATCH/RFC] Hookable IO operations Benjamin Herrenschmidt
2006-11-03 22:20 ` Arnd Bergmann
2006-11-03 22:32 ` Benjamin Herrenschmidt
2006-11-03 22:48 ` Arnd Bergmann
2006-11-03 22:56 ` Benjamin Herrenschmidt
2006-11-04 0:15 ` Arnd Bergmann [this message]
2006-11-04 1:06 ` Benjamin Herrenschmidt
2006-11-04 16:28 ` Segher Boessenkool
2006-11-04 22:05 ` Benjamin Herrenschmidt
2006-11-04 22:33 ` Segher Boessenkool
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=200611040115.34235.arnd@arndb.de \
--to=arnd@arndb.de \
--cc=linuxppc-dev@ozlabs.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.