[PATCH] rcu: join rcu_ctrlblk and rcu_state
[powerpc.git] / include / asm-mips / io.h
index 3b4d97d..d426857 100644 (file)
@@ -27,6 +27,7 @@
 #include <asm/processor.h>
 #include <asm/string.h>
 
+#include <ioremap.h>
 #include <mangle-port.h>
 
 /*
@@ -209,6 +210,8 @@ extern void __iounmap(volatile void __iomem *addr);
 static inline void __iomem * __ioremap_mode(phys_t offset, unsigned long size,
        unsigned long flags)
 {
+#define __IS_LOW512(addr) (!((phys_t)(addr) & (phys_t) ~0x1fffffffULL))
+
        if (cpu_has_64bit_addresses) {
                u64 base = UNCAC_BASE;
 
@@ -219,9 +222,29 @@ static inline void __iomem * __ioremap_mode(phys_t offset, unsigned long size,
                if (flags == _CACHE_UNCACHED)
                        base = (u64) IO_BASE;
                return (void __iomem *) (unsigned long) (base + offset);
+       } else if (__builtin_constant_p(offset) &&
+                  __builtin_constant_p(size) && __builtin_constant_p(flags)) {
+               phys_t phys_addr, last_addr;
+
+               phys_addr = fixup_bigphys_addr(offset, size);
+
+               /* Don't allow wraparound or zero size. */
+               last_addr = phys_addr + size - 1;
+               if (!size || last_addr < phys_addr)
+                       return NULL;
+
+               /*
+                * Map uncached objects in the low 512MB of address
+                * space using KSEG1.
+                */
+               if (__IS_LOW512(phys_addr) && __IS_LOW512(last_addr) &&
+                   flags == _CACHE_UNCACHED)
+                       return (void __iomem *)CKSEG1ADDR(phys_addr);
        }
 
        return __ioremap(offset, size, flags);
+
+#undef __IS_LOW512
 }
 
 /*
@@ -273,12 +296,16 @@ static inline void __iomem * __ioremap_mode(phys_t offset, unsigned long size,
 
 static inline void iounmap(volatile void __iomem *addr)
 {
-       if (cpu_has_64bit_addresses)
+#define __IS_KSEG1(addr) (((unsigned long)(addr) & ~0x1fffffffUL) == CKSEG1)
+
+       if (cpu_has_64bit_addresses ||
+           (__builtin_constant_p(addr) && __IS_KSEG1(addr)))
                return;
 
        __iounmap(addr);
-}
 
+#undef __IS_KSEG1
+}
 
 #define __BUILD_MEMORY_SINGLE(pfx, bwlq, type, irq)                    \
                                                                        \
@@ -360,11 +387,11 @@ static inline void pfx##out##bwlq##p(type val, unsigned long port)        \
                                                                        \
        __val = pfx##ioswab##bwlq(val);                                 \
                                                                        \
-       if (sizeof(type) != sizeof(u64)) {                              \
-               *__addr = __val;                                        \
-               slow;                                                   \
-       } else                                                          \
-               BUILD_BUG();                                            \
+       /* Really, we want this to be atomic */                         \
+       BUILD_BUG_ON(sizeof(type) > sizeof(unsigned long));             \
+                                                                       \
+       *__addr = __val;                                                \
+       slow;                                                           \
 }                                                                      \
                                                                        \
 static inline type pfx##in##bwlq##p(unsigned long port)                        \
@@ -375,13 +402,10 @@ static inline type pfx##in##bwlq##p(unsigned long port)                   \
        port = __swizzle_addr_##bwlq(port);                             \
        __addr = (void *)(mips_io_port_base + port);                    \
                                                                        \
-       if (sizeof(type) != sizeof(u64)) {                              \
-               __val = *__addr;                                        \
-               slow;                                                   \
-       } else {                                                        \
-               __val = 0;                                              \
-               BUILD_BUG();                                            \
-       }                                                               \
+       BUILD_BUG_ON(sizeof(type) > sizeof(unsigned long));             \
+                                                                       \
+       __val = *__addr;                                                \
+       slow;                                                           \
                                                                        \
        return pfx##ioswab##bwlq(__val);                                \
 }
@@ -390,28 +414,36 @@ static inline type pfx##in##bwlq##p(unsigned long port)                   \
                                                                        \
 __BUILD_MEMORY_SINGLE(bus, bwlq, type, 1)
 
-#define __BUILD_IOPORT_PFX(bus, bwlq, type)                            \
-                                                                       \
-__BUILD_IOPORT_SINGLE(bus, bwlq, type, ,)                              \
-__BUILD_IOPORT_SINGLE(bus, bwlq, type, _p, SLOW_DOWN_IO)
-
-#define BUILDIO(bwlq, type)                                            \
+#define BUILDIO_MEM(bwlq, type)                                                \
                                                                        \
 __BUILD_MEMORY_PFX(__raw_, bwlq, type)                                 \
 __BUILD_MEMORY_PFX(, bwlq, type)                                       \
 __BUILD_MEMORY_PFX(mem_, bwlq, type)                                   \
-__BUILD_IOPORT_PFX(, bwlq, type)                                       \
-__BUILD_IOPORT_PFX(mem_, bwlq, type)
+
+BUILDIO_MEM(b, u8)
+BUILDIO_MEM(w, u16)
+BUILDIO_MEM(l, u32)
+BUILDIO_MEM(q, u64)
+
+#define __BUILD_IOPORT_PFX(bus, bwlq, type)                            \
+       __BUILD_IOPORT_SINGLE(bus, bwlq, type, ,)                       \
+       __BUILD_IOPORT_SINGLE(bus, bwlq, type, _p, SLOW_DOWN_IO)
+
+#define BUILDIO_IOPORT(bwlq, type)                                     \
+       __BUILD_IOPORT_PFX(, bwlq, type)                                \
+       __BUILD_IOPORT_PFX(mem_, bwlq, type)
+
+BUILDIO_IOPORT(b, u8)
+BUILDIO_IOPORT(w, u16)
+BUILDIO_IOPORT(l, u32)
+#ifdef CONFIG_64BIT
+BUILDIO_IOPORT(q, u64)
+#endif
 
 #define __BUILDIO(bwlq, type)                                          \
                                                                        \
 __BUILD_MEMORY_SINGLE(____raw_, bwlq, type, 0)
 
-BUILDIO(b, u8)
-BUILDIO(w, u16)
-BUILDIO(l, u32)
-BUILDIO(q, u64)
-
 __BUILDIO(q, u64)
 
 #define readb_relaxed                  readb
@@ -427,10 +459,10 @@ __BUILDIO(q, u64)
 
 #define __BUILD_MEMORY_STRING(bwlq, type)                              \
                                                                        \
-static inline void writes##bwlq(volatile void __iomem *mem, void *addr,        \
-                               unsigned int count)                     \
+static inline void writes##bwlq(volatile void __iomem *mem,            \
+                               const void *addr, unsigned int count)   \
 {                                                                      \
-       volatile type *__addr = addr;                                   \
+       const volatile type *__addr = addr;                             \
                                                                        \
        while (count--) {                                               \
                mem_write##bwlq(*__addr, mem);                          \
@@ -481,7 +513,9 @@ __BUILD_IOPORT_STRING(bwlq, type)
 BUILDSTRING(b, u8)
 BUILDSTRING(w, u16)
 BUILDSTRING(l, u32)
+#ifdef CONFIG_64BIT
 BUILDSTRING(q, u64)
+#endif
 
 
 /* Depends on MIPS II instruction set */