Commit 54685b18 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] sparc io.h annotations and fixes

 * annotations for sparc io.h
 * missing memcpy_toio()/memcpy_fromio() added
Signed-off-by: default avatarAl Viro <viro@parcelfarce.linux.theplanet.co.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent efcc5858
...@@ -47,8 +47,8 @@ ...@@ -47,8 +47,8 @@
struct resource *_sparc_find_resource(struct resource *r, unsigned long); struct resource *_sparc_find_resource(struct resource *r, unsigned long);
static void *_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz); static void __iomem *_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz);
static void *_sparc_alloc_io(unsigned int busno, unsigned long phys, static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys,
unsigned long size, char *name); unsigned long size, char *name);
static void _sparc_free_io(struct resource *res); static void _sparc_free_io(struct resource *res);
...@@ -103,7 +103,7 @@ static void xres_free(struct xresource *xrp) { ...@@ -103,7 +103,7 @@ static void xres_free(struct xresource *xrp) {
* *
* Bus type is always zero on IIep. * Bus type is always zero on IIep.
*/ */
void *ioremap(unsigned long offset, unsigned long size) void __iomem *ioremap(unsigned long offset, unsigned long size)
{ {
char name[14]; char name[14];
...@@ -114,7 +114,7 @@ void *ioremap(unsigned long offset, unsigned long size) ...@@ -114,7 +114,7 @@ void *ioremap(unsigned long offset, unsigned long size)
/* /*
* Comlimentary to ioremap(). * Comlimentary to ioremap().
*/ */
void iounmap(void *virtual) void iounmap(volatile void __iomem *virtual)
{ {
unsigned long vaddr = (unsigned long) virtual & PAGE_MASK; unsigned long vaddr = (unsigned long) virtual & PAGE_MASK;
struct resource *res; struct resource *res;
...@@ -134,24 +134,24 @@ void iounmap(void *virtual) ...@@ -134,24 +134,24 @@ void iounmap(void *virtual)
/* /*
*/ */
unsigned long sbus_ioremap(struct resource *phyres, unsigned long offset, void __iomem *sbus_ioremap(struct resource *phyres, unsigned long offset,
unsigned long size, char *name) unsigned long size, char *name)
{ {
return (unsigned long) _sparc_alloc_io(phyres->flags & 0xF, return _sparc_alloc_io(phyres->flags & 0xF,
phyres->start + offset, size, name); phyres->start + offset, size, name);
} }
/* /*
*/ */
void sbus_iounmap(unsigned long addr, unsigned long size) void sbus_iounmap(volatile void __iomem *addr, unsigned long size)
{ {
iounmap((void *)addr); iounmap(addr);
} }
/* /*
* Meat of mapping * Meat of mapping
*/ */
static void *_sparc_alloc_io(unsigned int busno, unsigned long phys, static void __iomem *_sparc_alloc_io(unsigned int busno, unsigned long phys,
unsigned long size, char *name) unsigned long size, char *name)
{ {
static int printed_full; static int printed_full;
...@@ -159,7 +159,7 @@ static void *_sparc_alloc_io(unsigned int busno, unsigned long phys, ...@@ -159,7 +159,7 @@ static void *_sparc_alloc_io(unsigned int busno, unsigned long phys,
struct resource *res; struct resource *res;
char *tack; char *tack;
int tlen; int tlen;
void *va; /* P3 diag */ void __iomem *va; /* P3 diag */
if (name == NULL) name = "???"; if (name == NULL) name = "???";
...@@ -189,7 +189,7 @@ static void *_sparc_alloc_io(unsigned int busno, unsigned long phys, ...@@ -189,7 +189,7 @@ static void *_sparc_alloc_io(unsigned int busno, unsigned long phys,
/* /*
*/ */
static void * static void __iomem *
_sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz) _sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz)
{ {
unsigned long offset = ((unsigned long) pa) & (~PAGE_MASK); unsigned long offset = ((unsigned long) pa) & (~PAGE_MASK);
...@@ -206,7 +206,7 @@ _sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz) ...@@ -206,7 +206,7 @@ _sparc_ioremap(struct resource *res, u32 bus, u32 pa, int sz)
pa &= PAGE_MASK; pa &= PAGE_MASK;
sparc_mapiorange(bus, pa, res->start, res->end - res->start + 1); sparc_mapiorange(bus, pa, res->start, res->end - res->start + 1);
return (void *) (res->start + offset); return (void __iomem *) (res->start + offset);
} }
/* /*
......
...@@ -27,87 +27,78 @@ static inline u16 flip_word (u16 w) ...@@ -27,87 +27,78 @@ static inline u16 flip_word (u16 w)
/* /*
* Memory mapped I/O to PCI * Memory mapped I/O to PCI
*
* Observe that ioremap returns void* cookie, but accessors, such
* as readb, take unsigned long as address, by API. This mismatch
* happened historically. The ioremap is much older than accessors,
* so at one time ioremap's cookie was used as address (*a = val).
* When accessors came about, they were designed to be compatible across
* buses, so that drivers can select proper ones like sunhme.c did.
* To make that easier, they use same aruments (ulong) for sbus, pci, isa.
* The offshot is, we must cast readb et. al. arguments with a #define.
*/ */
static inline u8 __raw_readb(unsigned long addr) static inline u8 __raw_readb(const volatile void __iomem *addr)
{ {
return *(volatile u8 *)addr; return *(__force volatile u8 *)addr;
} }
static inline u16 __raw_readw(unsigned long addr) static inline u16 __raw_readw(const volatile void __iomem *addr)
{ {
return *(volatile u16 *)addr; return *(__force volatile u16 *)addr;
} }
static inline u32 __raw_readl(unsigned long addr) static inline u32 __raw_readl(const volatile void __iomem *addr)
{ {
return *(volatile u32 *)addr; return *(__force volatile u32 *)addr;
} }
static inline void __raw_writeb(u8 b, unsigned long addr) static inline void __raw_writeb(u8 b, volatile void __iomem *addr)
{ {
*(volatile u8 *)addr = b; *(__force volatile u8 *)addr = b;
} }
static inline void __raw_writew(u16 w, unsigned long addr) static inline void __raw_writew(u16 w, volatile void __iomem *addr)
{ {
*(volatile u16 *)addr = w; *(__force volatile u16 *)addr = w;
} }
static inline void __raw_writel(u32 l, unsigned long addr) static inline void __raw_writel(u32 l, volatile void __iomem *addr)
{ {
*(volatile u32 *)addr = l; *(__force volatile u32 *)addr = l;
} }
static inline u8 __readb(unsigned long addr) static inline u8 __readb(const volatile void __iomem *addr)
{ {
return *(volatile u8 *)addr; return *(__force volatile u8 *)addr;
} }
static inline u16 __readw(unsigned long addr) static inline u16 __readw(const volatile void __iomem *addr)
{ {
return flip_word(*(volatile u16 *)addr); return flip_word(*(__force volatile u16 *)addr);
} }
static inline u32 __readl(unsigned long addr) static inline u32 __readl(const volatile void __iomem *addr)
{ {
return flip_dword(*(volatile u32 *)addr); return flip_dword(*(__force volatile u32 *)addr);
} }
static inline void __writeb(u8 b, unsigned long addr) static inline void __writeb(u8 b, volatile void __iomem *addr)
{ {
*(volatile u8 *)addr = b; *(__force volatile u8 *)addr = b;
} }
static inline void __writew(u16 w, unsigned long addr) static inline void __writew(u16 w, volatile void __iomem *addr)
{ {
*(volatile u16 *)addr = flip_word(w); *(__force volatile u16 *)addr = flip_word(w);
} }
static inline void __writel(u32 l, unsigned long addr) static inline void __writel(u32 l, volatile void __iomem *addr)
{ {
*(volatile u32 *)addr = flip_dword(l); *(__force volatile u32 *)addr = flip_dword(l);
} }
#define readb(__addr) __readb((unsigned long)(__addr)) #define readb(__addr) __readb(__addr)
#define readw(__addr) __readw((unsigned long)(__addr)) #define readw(__addr) __readw(__addr)
#define readl(__addr) __readl((unsigned long)(__addr)) #define readl(__addr) __readl(__addr)
#define readb_relaxed(__addr) readb(__addr) #define readb_relaxed(__addr) readb(__addr)
#define readw_relaxed(__addr) readw(__addr) #define readw_relaxed(__addr) readw(__addr)
#define readl_relaxed(__addr) readl(__addr) #define readl_relaxed(__addr) readl(__addr)
#define writeb(__b, __addr) __writeb((__b),(unsigned long)(__addr)) #define writeb(__b, __addr) __writeb((__b),(__addr))
#define writew(__w, __addr) __writew((__w),(unsigned long)(__addr)) #define writew(__w, __addr) __writew((__w),(__addr))
#define writel(__l, __addr) __writel((__l),(unsigned long)(__addr)) #define writel(__l, __addr) __writel((__l),(__addr))
/* /*
* I/O space operations * I/O space operations
...@@ -126,15 +117,15 @@ static inline void __writel(u32 l, unsigned long addr) ...@@ -126,15 +117,15 @@ static inline void __writel(u32 l, unsigned long addr)
* mapped somewhere into virtual kernel space and we * mapped somewhere into virtual kernel space and we
* can use inb/outb again. * can use inb/outb again.
*/ */
#define inb_local(__addr) __readb((unsigned long)(__addr)) #define inb_local(__addr) __readb((void __iomem *)(unsigned long)(__addr))
#define inb(__addr) __readb((unsigned long)(__addr)) #define inb(__addr) __readb((void __iomem *)(unsigned long)(__addr))
#define inw(__addr) __readw((unsigned long)(__addr)) #define inw(__addr) __readw((void __iomem *)(unsigned long)(__addr))
#define inl(__addr) __readl((unsigned long)(__addr)) #define inl(__addr) __readl((void __iomem *)(unsigned long)(__addr))
#define outb_local(__b, __addr) __writeb(__b, (unsigned long)(__addr)) #define outb_local(__b, __addr) __writeb(__b, (void __iomem *)(unsigned long)(__addr))
#define outb(__b, __addr) __writeb(__b, (unsigned long)(__addr)) #define outb(__b, __addr) __writeb(__b, (void __iomem *)(unsigned long)(__addr))
#define outw(__w, __addr) __writew(__w, (unsigned long)(__addr)) #define outw(__w, __addr) __writew(__w, (void __iomem *)(unsigned long)(__addr))
#define outl(__l, __addr) __writel(__l, (unsigned long)(__addr)) #define outl(__l, __addr) __writel(__l, (void __iomem *)(unsigned long)(__addr))
#define inb_p(__addr) inb(__addr) #define inb_p(__addr) inb(__addr)
#define outb_p(__b, __addr) outb(__b, __addr) #define outb_p(__b, __addr) outb(__b, __addr)
...@@ -158,73 +149,112 @@ extern void insl(unsigned long addr, void *dst, unsigned long count); ...@@ -158,73 +149,112 @@ extern void insl(unsigned long addr, void *dst, unsigned long count);
* SBus has only one, memory mapped, I/O space. * SBus has only one, memory mapped, I/O space.
* We do not need to flip bytes for SBus of course. * We do not need to flip bytes for SBus of course.
*/ */
static inline u8 _sbus_readb(unsigned long addr) static inline u8 _sbus_readb(const volatile void __iomem *addr)
{ {
return *(volatile u8 *)addr; return *(__force volatile u8 *)addr;
} }
static inline u16 _sbus_readw(unsigned long addr) static inline u16 _sbus_readw(const volatile void __iomem *addr)
{ {
return *(volatile u16 *)addr; return *(__force volatile u16 *)addr;
} }
static inline u32 _sbus_readl(unsigned long addr) static inline u32 _sbus_readl(const volatile void __iomem *addr)
{ {
return *(volatile u32 *)addr; return *(__force volatile u32 *)addr;
} }
static inline void _sbus_writeb(u8 b, unsigned long addr) static inline void _sbus_writeb(u8 b, volatile void __iomem *addr)
{ {
*(volatile u8 *)addr = b; *(__force volatile u8 *)addr = b;
} }
static inline void _sbus_writew(u16 w, unsigned long addr) static inline void _sbus_writew(u16 w, volatile void __iomem *addr)
{ {
*(volatile u16 *)addr = w; *(__force volatile u16 *)addr = w;
} }
static inline void _sbus_writel(u32 l, unsigned long addr) static inline void _sbus_writel(u32 l, volatile void __iomem *addr)
{ {
*(volatile u32 *)addr = l; *(__force volatile u32 *)addr = l;
} }
/* /*
* The only reason for #define's is to hide casts to unsigned long. * The only reason for #define's is to hide casts to unsigned long.
*/ */
#define sbus_readb(__addr) _sbus_readb((unsigned long)(__addr)) #define sbus_readb(__addr) _sbus_readb(__addr)
#define sbus_readw(__addr) _sbus_readw((unsigned long)(__addr)) #define sbus_readw(__addr) _sbus_readw(__addr)
#define sbus_readl(__addr) _sbus_readl((unsigned long)(__addr)) #define sbus_readl(__addr) _sbus_readl(__addr)
#define sbus_writeb(__b, __addr) _sbus_writeb(__b, (unsigned long)(__addr)) #define sbus_writeb(__b, __addr) _sbus_writeb(__b, __addr)
#define sbus_writew(__w, __addr) _sbus_writew(__w, (unsigned long)(__addr)) #define sbus_writew(__w, __addr) _sbus_writew(__w, __addr)
#define sbus_writel(__l, __addr) _sbus_writel(__l, (unsigned long)(__addr)) #define sbus_writel(__l, __addr) _sbus_writel(__l, __addr)
static inline void sbus_memset_io(volatile void __iomem *__dst, int c, __kernel_size_t n)
{
while(n--) {
sbus_writeb(c, __dst);
__dst++;
}
}
static inline void *sbus_memset_io(void *__dst, int c, __kernel_size_t n) static inline void
_memset_io(volatile void __iomem *dst, int c, __kernel_size_t n)
{ {
unsigned long dst = (unsigned long)__dst; volatile void __iomem *d = dst;
while(n--) { while (n--) {
sbus_writeb(c, dst); writeb(c, d);
dst++; d++;
} }
return (void *) dst;
} }
#define memset_io(d,c,sz) _memset_io(d,c,sz)
static inline void
_memcpy_fromio(void *dst, const volatile void __iomem *src, __kernel_size_t n)
{
char *d = dst;
while (n--) {
char tmp = readb(src);
*d++ = tmp;
src++;
}
}
#define memcpy_fromio(d,s,sz) _memcpy_fromio(d,s,sz)
static inline void
_memcpy_toio(volatile void __iomem *dst, const void *src, __kernel_size_t n)
{
const char *s = src;
volatile void __iomem *d = dst;
while (n--) {
char tmp = *s++;
writeb(tmp, d);
d++;
}
}
#define memcpy_toio(d,s,sz) _memcpy_toio(d,s,sz)
#ifdef __KERNEL__ #ifdef __KERNEL__
/* /*
* Bus number may be embedded in the higher bits of the physical address. * Bus number may be embedded in the higher bits of the physical address.
* This is why we have no bus number argument to ioremap(). * This is why we have no bus number argument to ioremap().
*/ */
extern void *ioremap(unsigned long offset, unsigned long size); extern void __iomem *ioremap(unsigned long offset, unsigned long size);
#define ioremap_nocache(X,Y) ioremap((X),(Y)) #define ioremap_nocache(X,Y) ioremap((X),(Y))
extern void iounmap(void *addr); extern void iounmap(volatile void __iomem *addr);
/* /*
* Bus number may be in res->flags... somewhere. * Bus number may be in res->flags... somewhere.
*/ */
extern unsigned long sbus_ioremap(struct resource *res, unsigned long offset, extern void __iomem *sbus_ioremap(struct resource *res, unsigned long offset,
unsigned long size, char *name); unsigned long size, char *name);
extern void sbus_iounmap(unsigned long vaddr, unsigned long size); extern void sbus_iounmap(volatile void __iomem *vaddr, unsigned long size);
/* /*
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment