15 #include <linux/errno.h>
16 #include <asm/cache.h>
17 #include <asm/addrspace.h>
18 #include <asm/machvec.h>
19 #include <asm/pgtable.h>
23 #define __IO_PREFIX generic
28 #define __raw_writeb(v,a) (__chk_io_ptr(a), *(volatile u8 __force *)(a) = (v))
29 #define __raw_writew(v,a) (__chk_io_ptr(a), *(volatile u16 __force *)(a) = (v))
30 #define __raw_writel(v,a) (__chk_io_ptr(a), *(volatile u32 __force *)(a) = (v))
31 #define __raw_writeq(v,a) (__chk_io_ptr(a), *(volatile u64 __force *)(a) = (v))
33 #define __raw_readb(a) (__chk_io_ptr(a), *(volatile u8 __force *)(a))
34 #define __raw_readw(a) (__chk_io_ptr(a), *(volatile u16 __force *)(a))
35 #define __raw_readl(a) (__chk_io_ptr(a), *(volatile u32 __force *)(a))
36 #define __raw_readq(a) (__chk_io_ptr(a), *(volatile u64 __force *)(a))
38 #define readb_relaxed(c) ({ u8 __v = ioswabb(__raw_readb(c)); __v; })
39 #define readw_relaxed(c) ({ u16 __v = ioswabw(__raw_readw(c)); __v; })
40 #define readl_relaxed(c) ({ u32 __v = ioswabl(__raw_readl(c)); __v; })
41 #define readq_relaxed(c) ({ u64 __v = ioswabq(__raw_readq(c)); __v; })
43 #define writeb_relaxed(v,c) ((void)__raw_writeb((__force u8)ioswabb(v),c))
44 #define writew_relaxed(v,c) ((void)__raw_writew((__force u16)ioswabw(v),c))
45 #define writel_relaxed(v,c) ((void)__raw_writel((__force u32)ioswabl(v),c))
46 #define writeq_relaxed(v,c) ((void)__raw_writeq((__force u64)ioswabq(v),c))
48 #define readb(a) ({ u8 r_ = readb_relaxed(a); rmb(); r_; })
49 #define readw(a) ({ u16 r_ = readw_relaxed(a); rmb(); r_; })
50 #define readl(a) ({ u32 r_ = readl_relaxed(a); rmb(); r_; })
51 #define readq(a) ({ u64 r_ = readq_relaxed(a); rmb(); r_; })
53 #define writeb(v,a) ({ wmb(); writeb_relaxed((v),(a)); })
54 #define writew(v,a) ({ wmb(); writew_relaxed((v),(a)); })
55 #define writel(v,a) ({ wmb(); writel_relaxed((v),(a)); })
56 #define writeq(v,a) ({ wmb(); writeq_relaxed((v),(a)); })
58 #define readsb(p,d,l) __raw_readsb(p,d,l)
59 #define readsw(p,d,l) __raw_readsw(p,d,l)
60 #define readsl(p,d,l) __raw_readsl(p,d,l)
62 #define writesb(p,d,l) __raw_writesb(p,d,l)
63 #define writesw(p,d,l) __raw_writesw(p,d,l)
64 #define writesl(p,d,l) __raw_writesl(p,d,l)
66 #define __BUILD_UNCACHED_IO(bwlq, type) \
67 static inline type read##bwlq##_uncached(unsigned long addr) \
71 ret = __raw_read##bwlq(addr); \
76 static inline void write##bwlq##_uncached(type v, unsigned long addr) \
79 __raw_write##bwlq(v, addr); \
83 __BUILD_UNCACHED_IO(
b,
u8)
84 __BUILD_UNCACHED_IO(
w,
u16)
85 __BUILD_UNCACHED_IO(
l,
u32)
86 __BUILD_UNCACHED_IO(
q,
u64)
88 #define __BUILD_MEMORY_STRING(pfx, bwlq, type) \
91 pfx##writes##bwlq(volatile void __iomem *mem, const void *addr, \
94 const volatile type *__addr = addr; \
97 __raw_write##bwlq(*__addr, mem); \
102 static inline void pfx##reads##bwlq(volatile void __iomem *mem, \
103 void *addr, unsigned int count) \
105 volatile type *__addr = addr; \
108 *__addr = __raw_read##bwlq(mem); \
116 #ifdef CONFIG_SUPERH32
125 #ifdef CONFIG_HAS_IOPORT
130 #undef CONF_SLOWDOWN_IO
137 extern unsigned long sh_io_port_base;
139 static inline void __set_io_port_base(
unsigned long pbase)
141 *(
unsigned long *)&sh_io_port_base = pbase;
145 #ifdef CONFIG_GENERIC_IOMAP
146 #define __ioport_map ioport_map
151 #ifdef CONF_SLOWDOWN_IO
152 #define SLOW_DOWN_IO __raw_readw(sh_io_port_base)
157 #define __BUILD_IOPORT_SINGLE(pfx, bwlq, type, p, slow) \
159 static inline void pfx##out##bwlq##p(type val, unsigned long port) \
161 volatile type *__addr; \
163 __addr = __ioport_map(port, sizeof(type)); \
168 static inline type pfx##in##bwlq##p(unsigned long port) \
170 volatile type *__addr; \
173 __addr = __ioport_map(port, sizeof(type)); \
180 #define __BUILD_IOPORT_PFX(bus, bwlq, type) \
181 __BUILD_IOPORT_SINGLE(bus, bwlq, type, ,) \
182 __BUILD_IOPORT_SINGLE(bus, bwlq, type, _p, SLOW_DOWN_IO)
184 #define BUILDIO_IOPORT(bwlq, type) \
185 __BUILD_IOPORT_PFX(, bwlq, type)
192 #define __BUILD_IOPORT_STRING(bwlq, type) \
194 static inline void outs##bwlq(unsigned long port, const void *addr, \
195 unsigned int count) \
197 const volatile type *__addr = addr; \
200 out##bwlq(*__addr, port); \
205 static inline void ins##bwlq(unsigned long port, void *addr, \
206 unsigned int count) \
208 volatile type *__addr = addr; \
211 *__addr = in##bwlq(port); \
228 #define IO_SPACE_LIMIT 0xffffffff
231 #define mmiowb() wmb()
239 unsigned long long peek_real_address_q(
unsigned long long addr);
240 unsigned long long poke_real_address_q(
unsigned long long addr,
241 unsigned long long val);
243 #if !defined(CONFIG_MMU)
244 #define virt_to_phys(address) ((unsigned long)(address))
245 #define phys_to_virt(address) ((void *)(address))
247 #define virt_to_phys(address) (__pa(address))
248 #define phys_to_virt(address) (__va(address))
301 return (
void __iomem *)P1SEGADDR(offset);
303 return (
void __iomem *)P2SEGADDR(offset);
307 if (
unlikely(offset >= P3_ADDR_MAX))
308 return (
void __iomem *)P4SEGADDR(offset);
323 ret = __ioremap_29bit(offset, size, prot);
330 #define __ioremap(offset, size, prot) ((void __iomem *)(offset))
331 #define __ioremap_mode(offset, size, prot) ((void __iomem *)(offset))
332 #define __iounmap(addr) do { } while (0)
343 return __ioremap_mode(offset, size, PAGE_KERNEL);
346 #ifdef CONFIG_HAVE_IOREMAP_PROT
350 return __ioremap_mode(offset, size,
__pgprot(flags));
354 #ifdef CONFIG_IOREMAP_FIXED
370 #define ioremap_nocache ioremap
371 #define iounmap __iounmap
377 #define xlate_dev_mem_ptr(p) __va(p)
382 #define xlate_dev_kmem_ptr(p) p
384 #define ARCH_HAS_VALID_PHYS_ADDR_RANGE