1 /* MN10300 I/O port emulation and memory-mapped I/O
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.
14 #include <asm/page.h> /* I/O is all done through memory accesses */
15 #include <asm/cpu-regs.h>
16 #include <asm/cacheflush.h>
17 #include <asm-generic/pci_iomap.h>
19 #define mmiowb() do {} while (0)
21 /*****************************************************************************/
23 * readX/writeX() are used to access memory mapped devices. On some
24 * architectures the memory mapped IO stuff needs to be accessed
25 * differently. On the x86 architecture, we just read/write the
26 * memory location directly.
28 static inline u8
readb(const volatile void __iomem
*addr
)
30 return *(const volatile u8
*) addr
;
33 static inline u16
readw(const volatile void __iomem
*addr
)
35 return *(const volatile u16
*) addr
;
38 static inline u32
readl(const volatile void __iomem
*addr
)
40 return *(const volatile u32
*) addr
;
43 #define __raw_readb readb
44 #define __raw_readw readw
45 #define __raw_readl readl
47 #define readb_relaxed readb
48 #define readw_relaxed readw
49 #define readl_relaxed readl
51 static inline void writeb(u8 b
, volatile void __iomem
*addr
)
53 *(volatile u8
*) addr
= b
;
56 static inline void writew(u16 b
, volatile void __iomem
*addr
)
58 *(volatile u16
*) addr
= b
;
61 static inline void writel(u32 b
, volatile void __iomem
*addr
)
63 *(volatile u32
*) addr
= b
;
66 #define __raw_writeb writeb
67 #define __raw_writew writew
68 #define __raw_writel writel
70 /*****************************************************************************/
72 * traditional input/output functions
74 static inline u8
inb_local(unsigned long addr
)
76 return readb((volatile void __iomem
*) addr
);
79 static inline void outb_local(u8 b
, unsigned long addr
)
81 return writeb(b
, (volatile void __iomem
*) addr
);
84 static inline u8
inb(unsigned long addr
)
86 return readb((volatile void __iomem
*) addr
);
89 static inline u16
inw(unsigned long addr
)
91 return readw((volatile void __iomem
*) addr
);
94 static inline u32
inl(unsigned long addr
)
96 return readl((volatile void __iomem
*) addr
);
99 static inline void outb(u8 b
, unsigned long addr
)
101 return writeb(b
, (volatile void __iomem
*) addr
);
104 static inline void outw(u16 b
, unsigned long addr
)
106 return writew(b
, (volatile void __iomem
*) addr
);
109 static inline void outl(u32 b
, unsigned long addr
)
111 return writel(b
, (volatile void __iomem
*) addr
);
114 #define inb_p(addr) inb(addr)
115 #define inw_p(addr) inw(addr)
116 #define inl_p(addr) inl(addr)
117 #define outb_p(x, addr) outb((x), (addr))
118 #define outw_p(x, addr) outw((x), (addr))
119 #define outl_p(x, addr) outl((x), (addr))
121 static inline void insb(unsigned long addr
, void *buffer
, int count
)
132 static inline void insw(unsigned long addr
, void *buffer
, int count
)
143 static inline void insl(unsigned long addr
, void *buffer
, int count
)
154 static inline void outsb(unsigned long addr
, const void *buffer
, int count
)
157 const u8
*buf
= buffer
;
164 static inline void outsw(unsigned long addr
, const void *buffer
, int count
)
167 const u16
*buf
= buffer
;
174 extern void __outsl(unsigned long addr
, const void *buffer
, int count
);
175 static inline void outsl(unsigned long addr
, const void *buffer
, int count
)
177 if ((unsigned long) buffer
& 0x3)
178 return __outsl(addr
, buffer
, count
);
181 const u32
*buf
= buffer
;
188 #define ioread8(addr) readb(addr)
189 #define ioread16(addr) readw(addr)
190 #define ioread32(addr) readl(addr)
192 #define iowrite8(v, addr) writeb((v), (addr))
193 #define iowrite16(v, addr) writew((v), (addr))
194 #define iowrite32(v, addr) writel((v), (addr))
196 #define ioread8_rep(p, dst, count) \
197 insb((unsigned long) (p), (dst), (count))
198 #define ioread16_rep(p, dst, count) \
199 insw((unsigned long) (p), (dst), (count))
200 #define ioread32_rep(p, dst, count) \
201 insl((unsigned long) (p), (dst), (count))
203 #define iowrite8_rep(p, src, count) \
204 outsb((unsigned long) (p), (src), (count))
205 #define iowrite16_rep(p, src, count) \
206 outsw((unsigned long) (p), (src), (count))
207 #define iowrite32_rep(p, src, count) \
208 outsl((unsigned long) (p), (src), (count))
210 #define readsb(p, dst, count) \
211 insb((unsigned long) (p), (dst), (count))
212 #define readsw(p, dst, count) \
213 insw((unsigned long) (p), (dst), (count))
214 #define readsl(p, dst, count) \
215 insl((unsigned long) (p), (dst), (count))
217 #define writesb(p, src, count) \
218 outsb((unsigned long) (p), (src), (count))
219 #define writesw(p, src, count) \
220 outsw((unsigned long) (p), (src), (count))
221 #define writesl(p, src, count) \
222 outsl((unsigned long) (p), (src), (count))
224 #define IO_SPACE_LIMIT 0xffffffff
228 #include <linux/vmalloc.h>
229 #define __io_virt(x) ((void *) (x))
231 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
233 static inline void pci_iounmap(struct pci_dev
*dev
, void __iomem
*p
)
238 * Change virtual addresses to physical addresses and vv.
239 * These are pretty trivial
241 static inline unsigned long virt_to_phys(volatile void *address
)
243 return __pa(address
);
246 static inline void *phys_to_virt(unsigned long address
)
248 return __va(address
);
252 * Change "struct page" to physical address.
254 static inline void __iomem
*__ioremap(unsigned long offset
, unsigned long size
,
257 return (void __iomem
*) offset
;
260 static inline void __iomem
*ioremap(unsigned long offset
, unsigned long size
)
262 return (void __iomem
*)(offset
& ~0x20000000);
266 * This one maps high address device memory and turns off caching for that
267 * area. it's useful if some control registers are in such an area and write
268 * combining or read caching is not desirable:
270 static inline void __iomem
*ioremap_nocache(unsigned long offset
, unsigned long size
)
272 return (void __iomem
*) (offset
| 0x20000000);
275 #define ioremap_wc ioremap_nocache
277 static inline void iounmap(void __iomem
*addr
)
281 static inline void __iomem
*ioport_map(unsigned long port
, unsigned int nr
)
283 return (void __iomem
*) port
;
286 static inline void ioport_unmap(void __iomem
*p
)
290 #define xlate_dev_kmem_ptr(p) ((void *) (p))
291 #define xlate_dev_mem_ptr(p) ((void *) (p))
294 * PCI bus iomem addresses must be in the region 0x80000000-0x9fffffff
296 static inline unsigned long virt_to_bus(volatile void *address
)
298 return ((unsigned long) address
) & ~0x20000000;
301 static inline void *bus_to_virt(unsigned long address
)
303 return (void *) address
;
306 #define page_to_bus page_to_phys
308 #define memset_io(a, b, c) memset(__io_virt(a), (b), (c))
309 #define memcpy_fromio(a, b, c) memcpy((a), __io_virt(b), (c))
310 #define memcpy_toio(a, b, c) memcpy(__io_virt(a), (b), (c))
312 #endif /* __KERNEL__ */
314 #endif /* _ASM_IO_H */