cramfs: hide function prototypes behind __KERNEL__ macro
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / include / asm-generic / io.h
blob4644c9a7f724adf96ab3f5c71edf9811467712d9
1 /* Generic I/O port emulation, based on MN10300 code
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
11 #ifndef __ASM_GENERIC_IO_H
12 #define __ASM_GENERIC_IO_H
14 #include <asm/page.h> /* I/O is all done through memory accesses */
15 #include <asm/cacheflush.h>
16 #include <linux/types.h>
18 #ifdef CONFIG_GENERIC_IOMAP
19 #include <asm-generic/iomap.h>
20 #endif
22 #ifndef mmiowb
23 #define mmiowb() do {} while (0)
24 #endif
26 /*****************************************************************************/
28 * readX/writeX() are used to access memory mapped devices. On some
29 * architectures the memory mapped IO stuff needs to be accessed
30 * differently. On the simple architectures, we just read/write the
31 * memory location directly.
33 #ifndef __raw_readb
34 static inline u8 __raw_readb(const volatile void __iomem *addr)
36 return *(const volatile u8 __force *) addr;
38 #endif
40 #ifndef __raw_readw
41 static inline u16 __raw_readw(const volatile void __iomem *addr)
43 return *(const volatile u16 __force *) addr;
45 #endif
47 #ifndef __raw_readl
48 static inline u32 __raw_readl(const volatile void __iomem *addr)
50 return *(const volatile u32 __force *) addr;
52 #endif
54 #define readb __raw_readb
55 #define readw(addr) __le16_to_cpu(__raw_readw(addr))
56 #define readl(addr) __le32_to_cpu(__raw_readl(addr))
58 #ifndef __raw_writeb
59 static inline void __raw_writeb(u8 b, volatile void __iomem *addr)
61 *(volatile u8 __force *) addr = b;
63 #endif
65 #ifndef __raw_writew
66 static inline void __raw_writew(u16 b, volatile void __iomem *addr)
68 *(volatile u16 __force *) addr = b;
70 #endif
72 #ifndef __raw_writel
73 static inline void __raw_writel(u32 b, volatile void __iomem *addr)
75 *(volatile u32 __force *) addr = b;
77 #endif
79 #define writeb __raw_writeb
80 #define writew(b,addr) __raw_writew(__cpu_to_le16(b),addr)
81 #define writel(b,addr) __raw_writel(__cpu_to_le32(b),addr)
83 #ifdef CONFIG_64BIT
84 static inline u64 __raw_readq(const volatile void __iomem *addr)
86 return *(const volatile u64 __force *) addr;
88 #define readq(addr) __le64_to_cpu(__raw_readq(addr))
90 static inline void __raw_writeq(u64 b, volatile void __iomem *addr)
92 *(volatile u64 __force *) addr = b;
94 #define writeq(b,addr) __raw_writeq(__cpu_to_le64(b),addr)
95 #endif
97 /*****************************************************************************/
99 * traditional input/output functions
102 static inline u8 inb(unsigned long addr)
104 return readb((volatile void __iomem *) addr);
107 static inline u16 inw(unsigned long addr)
109 return readw((volatile void __iomem *) addr);
112 static inline u32 inl(unsigned long addr)
114 return readl((volatile void __iomem *) addr);
117 static inline void outb(u8 b, unsigned long addr)
119 writeb(b, (volatile void __iomem *) addr);
122 static inline void outw(u16 b, unsigned long addr)
124 writew(b, (volatile void __iomem *) addr);
127 static inline void outl(u32 b, unsigned long addr)
129 writel(b, (volatile void __iomem *) addr);
132 #define inb_p(addr) inb(addr)
133 #define inw_p(addr) inw(addr)
134 #define inl_p(addr) inl(addr)
135 #define outb_p(x, addr) outb((x), (addr))
136 #define outw_p(x, addr) outw((x), (addr))
137 #define outl_p(x, addr) outl((x), (addr))
139 #ifndef insb
140 static inline void insb(unsigned long addr, void *buffer, int count)
142 if (count) {
143 u8 *buf = buffer;
144 do {
145 u8 x = inb(addr);
146 *buf++ = x;
147 } while (--count);
150 #endif
152 #ifndef insw
153 static inline void insw(unsigned long addr, void *buffer, int count)
155 if (count) {
156 u16 *buf = buffer;
157 do {
158 u16 x = inw(addr);
159 *buf++ = x;
160 } while (--count);
163 #endif
165 #ifndef insl
166 static inline void insl(unsigned long addr, void *buffer, int count)
168 if (count) {
169 u32 *buf = buffer;
170 do {
171 u32 x = inl(addr);
172 *buf++ = x;
173 } while (--count);
176 #endif
178 #ifndef outsb
179 static inline void outsb(unsigned long addr, const void *buffer, int count)
181 if (count) {
182 const u8 *buf = buffer;
183 do {
184 outb(*buf++, addr);
185 } while (--count);
188 #endif
190 #ifndef outsw
191 static inline void outsw(unsigned long addr, const void *buffer, int count)
193 if (count) {
194 const u16 *buf = buffer;
195 do {
196 outw(*buf++, addr);
197 } while (--count);
200 #endif
202 #ifndef outsl
203 static inline void outsl(unsigned long addr, const void *buffer, int count)
205 if (count) {
206 const u32 *buf = buffer;
207 do {
208 outl(*buf++, addr);
209 } while (--count);
212 #endif
214 static inline void readsl(const void __iomem *addr, void *buf, int len)
216 insl((unsigned long)addr, buf, len);
219 static inline void readsw(const void __iomem *addr, void *buf, int len)
221 insw((unsigned long)addr, buf, len);
224 static inline void readsb(const void __iomem *addr, void *buf, int len)
226 insb((unsigned long)addr, buf, len);
229 static inline void writesl(const void __iomem *addr, const void *buf, int len)
231 outsl((unsigned long)addr, buf, len);
234 static inline void writesw(const void __iomem *addr, const void *buf, int len)
236 outsw((unsigned long)addr, buf, len);
239 static inline void writesb(const void __iomem *addr, const void *buf, int len)
241 outsb((unsigned long)addr, buf, len);
244 #ifndef CONFIG_GENERIC_IOMAP
245 #define ioread8(addr) readb(addr)
246 #define ioread16(addr) readw(addr)
247 #define ioread16be(addr) be16_to_cpu(ioread16(addr))
248 #define ioread32(addr) readl(addr)
249 #define ioread32be(addr) be32_to_cpu(ioread32(addr))
251 #define iowrite8(v, addr) writeb((v), (addr))
252 #define iowrite16(v, addr) writew((v), (addr))
253 #define iowrite16be(v, addr) iowrite16(be16_to_cpu(v), (addr))
254 #define iowrite32(v, addr) writel((v), (addr))
255 #define iowrite32be(v, addr) iowrite32(be32_to_cpu(v), (addr))
257 #define ioread8_rep(p, dst, count) \
258 insb((unsigned long) (p), (dst), (count))
259 #define ioread16_rep(p, dst, count) \
260 insw((unsigned long) (p), (dst), (count))
261 #define ioread32_rep(p, dst, count) \
262 insl((unsigned long) (p), (dst), (count))
264 #define iowrite8_rep(p, src, count) \
265 outsb((unsigned long) (p), (src), (count))
266 #define iowrite16_rep(p, src, count) \
267 outsw((unsigned long) (p), (src), (count))
268 #define iowrite32_rep(p, src, count) \
269 outsl((unsigned long) (p), (src), (count))
270 #endif /* CONFIG_GENERIC_IOMAP */
273 #define IO_SPACE_LIMIT 0xffffffff
275 #ifdef __KERNEL__
277 #include <linux/vmalloc.h>
278 #define __io_virt(x) ((void __force *) (x))
280 #ifndef CONFIG_GENERIC_IOMAP
281 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
282 struct pci_dev;
283 extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
284 static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
287 #endif /* CONFIG_GENERIC_IOMAP */
290 * Change virtual addresses to physical addresses and vv.
291 * These are pretty trivial
293 static inline unsigned long virt_to_phys(volatile void *address)
295 return __pa((unsigned long)address);
298 static inline void *phys_to_virt(unsigned long address)
300 return __va(address);
304 * Change "struct page" to physical address.
306 static inline void __iomem *ioremap(phys_addr_t offset, unsigned long size)
308 return (void __iomem*) (unsigned long)offset;
311 #define __ioremap(offset, size, flags) ioremap(offset, size)
313 #ifndef ioremap_nocache
314 #define ioremap_nocache ioremap
315 #endif
317 #ifndef ioremap_wc
318 #define ioremap_wc ioremap_nocache
319 #endif
321 static inline void iounmap(void *addr)
325 #ifndef CONFIG_GENERIC_IOMAP
326 static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
328 return (void __iomem *) port;
331 static inline void ioport_unmap(void __iomem *p)
334 #else /* CONFIG_GENERIC_IOMAP */
335 extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
336 extern void ioport_unmap(void __iomem *p);
337 #endif /* CONFIG_GENERIC_IOMAP */
339 #define xlate_dev_kmem_ptr(p) p
340 #define xlate_dev_mem_ptr(p) ((void *) (p))
342 #ifndef virt_to_bus
343 static inline unsigned long virt_to_bus(volatile void *address)
345 return ((unsigned long) address);
348 static inline void *bus_to_virt(unsigned long address)
350 return (void *) address;
352 #endif
354 #define memset_io(a, b, c) memset(__io_virt(a), (b), (c))
355 #define memcpy_fromio(a, b, c) memcpy((a), __io_virt(b), (c))
356 #define memcpy_toio(a, b, c) memcpy(__io_virt(a), (b), (c))
358 #endif /* __KERNEL__ */
360 #endif /* __ASM_GENERIC_IO_H */