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>
22 #define mmiowb() do {} while (0)
24 /*****************************************************************************/
26 * readX/writeX() are used to access memory mapped devices. On some
27 * architectures the memory mapped IO stuff needs to be accessed
28 * differently. On the simple architectures, we just read/write the
29 * memory location directly.
31 static inline u8 __raw_readb(const volatile void __iomem *addr)
33 return *(const volatile u8 __force *) addr;
36 static inline u16 __raw_readw(const volatile void __iomem *addr)
38 return *(const volatile u16 __force *) addr;
41 static inline u32 __raw_readl(const volatile void __iomem *addr)
43 return *(const volatile u32 __force *) addr;
46 #define readb __raw_readb
47 #define readw(addr) __le16_to_cpu(__raw_readw(addr))
48 #define readl(addr) __le32_to_cpu(__raw_readl(addr))
50 static inline void __raw_writeb(u8 b, volatile void __iomem *addr)
52 *(volatile u8 __force *) addr = b;
55 static inline void __raw_writew(u16 b, volatile void __iomem *addr)
57 *(volatile u16 __force *) addr = b;
60 static inline void __raw_writel(u32 b, volatile void __iomem *addr)
62 *(volatile u32 __force *) addr = b;
65 #define writeb __raw_writeb
66 #define writew(b,addr) __raw_writew(__cpu_to_le16(b),addr)
67 #define writel(b,addr) __raw_writel(__cpu_to_le32(b),addr)
70 static inline u64 __raw_readq(const volatile void __iomem *addr)
72 return *(const volatile u64 __force *) addr;
74 #define readq(addr) __le64_to_cpu(__raw_readq(addr))
76 static inline void __raw_writeq(u64 b, volatile void __iomem *addr)
78 *(volatile u64 __force *) addr = b;
80 #define writeq(b,addr) __raw_writeq(__cpu_to_le64(b),addr)
83 /*****************************************************************************/
85 * traditional input/output functions
88 static inline u8 inb(unsigned long addr)
90 return readb((volatile void __iomem *) addr);
93 static inline u16 inw(unsigned long addr)
95 return readw((volatile void __iomem *) addr);
98 static inline u32 inl(unsigned long addr)
100 return readl((volatile void __iomem *) addr);
103 static inline void outb(u8 b, unsigned long addr)
105 writeb(b, (volatile void __iomem *) addr);
108 static inline void outw(u16 b, unsigned long addr)
110 writew(b, (volatile void __iomem *) addr);
113 static inline void outl(u32 b, unsigned long addr)
115 writel(b, (volatile void __iomem *) addr);
118 #define inb_p(addr) inb(addr)
119 #define inw_p(addr) inw(addr)
120 #define inl_p(addr) inl(addr)
121 #define outb_p(x, addr) outb((x), (addr))
122 #define outw_p(x, addr) outw((x), (addr))
123 #define outl_p(x, addr) outl((x), (addr))
125 static inline void insb(unsigned long addr, void *buffer, int count)
136 static inline void insw(unsigned long addr, void *buffer, int count)
147 static inline void insl(unsigned long addr, void *buffer, int count)
158 static inline void outsb(unsigned long addr, const void *buffer, int count)
161 const u8 *buf = buffer;
168 static inline void outsw(unsigned long addr, const void *buffer, int count)
171 const u16 *buf = buffer;
178 static inline void outsl(unsigned long addr, const void *buffer, int count)
181 const u32 *buf = buffer;
188 #ifndef CONFIG_GENERIC_IOMAP
189 #define ioread8(addr) readb(addr)
190 #define ioread16(addr) readw(addr)
191 #define ioread16be(addr) be16_to_cpu(ioread16(addr))
192 #define ioread32(addr) readl(addr)
193 #define ioread32be(addr) be32_to_cpu(ioread32(addr))
195 #define iowrite8(v, addr) writeb((v), (addr))
196 #define iowrite16(v, addr) writew((v), (addr))
197 #define iowrite16be(v, addr) iowrite16(be16_to_cpu(v), (addr))
198 #define iowrite32(v, addr) writel((v), (addr))
199 #define iowrite32be(v, addr) iowrite32(be32_to_cpu(v), (addr))
201 #define ioread8_rep(p, dst, count) \
202 insb((unsigned long) (p), (dst), (count))
203 #define ioread16_rep(p, dst, count) \
204 insw((unsigned long) (p), (dst), (count))
205 #define ioread32_rep(p, dst, count) \
206 insl((unsigned long) (p), (dst), (count))
208 #define iowrite8_rep(p, src, count) \
209 outsb((unsigned long) (p), (src), (count))
210 #define iowrite16_rep(p, src, count) \
211 outsw((unsigned long) (p), (src), (count))
212 #define iowrite32_rep(p, src, count) \
213 outsl((unsigned long) (p), (src), (count))
214 #endif /* CONFIG_GENERIC_IOMAP */
217 #define IO_SPACE_LIMIT 0xffffffff
221 #include <linux/vmalloc.h>
222 #define __io_virt(x) ((void __force *) (x))
224 #ifndef CONFIG_GENERIC_IOMAP
225 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
227 extern void __iomem *pci_iomap(struct pci_dev *dev, int bar, unsigned long max);
228 static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
231 #endif /* CONFIG_GENERIC_IOMAP */
234 * Change virtual addresses to physical addresses and vv.
235 * These are pretty trivial
237 static inline unsigned long virt_to_phys(volatile void *address)
239 return __pa((unsigned long)address);
242 static inline void *phys_to_virt(unsigned long address)
244 return __va(address);
248 * Change "struct page" to physical address.
250 static inline void __iomem *ioremap(phys_addr_t offset, unsigned long size)
252 return (void __iomem*) (unsigned long)offset;
255 #define __ioremap(offset, size, flags) ioremap(offset, size)
257 #ifndef ioremap_nocache
258 #define ioremap_nocache ioremap
262 #define ioremap_wc ioremap_nocache
265 static inline void iounmap(void *addr)
269 #ifndef CONFIG_GENERIC_IOMAP
270 static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
272 return (void __iomem *) port;
275 static inline void ioport_unmap(void __iomem *p)
278 #else /* CONFIG_GENERIC_IOMAP */
279 extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
280 extern void ioport_unmap(void __iomem *p);
281 #endif /* CONFIG_GENERIC_IOMAP */
283 #define xlate_dev_kmem_ptr(p) p
284 #define xlate_dev_mem_ptr(p) ((void *) (p))
287 static inline unsigned long virt_to_bus(volatile void *address)
289 return ((unsigned long) address);
292 static inline void *bus_to_virt(unsigned long address)
294 return (void *) address;
298 #define memset_io(a, b, c) memset(__io_virt(a), (b), (c))
299 #define memcpy_fromio(a, b, c) memcpy((a), __io_virt(b), (c))
300 #define memcpy_toio(a, b, c) memcpy(__io_virt(a), (b), (c))
302 #endif /* __KERNEL__ */
304 #endif /* __ASM_GENERIC_IO_H */