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>
18 #define mmiowb() do {} while (0)
20 /*****************************************************************************/
22 * readX/writeX() are used to access memory mapped devices. On some
23 * architectures the memory mapped IO stuff needs to be accessed
24 * differently. On the x86 architecture, we just read/write the
25 * memory location directly.
27 static inline u8
readb(const volatile void __iomem
*addr
)
29 return *(const volatile u8
*) addr
;
32 static inline u16
readw(const volatile void __iomem
*addr
)
34 return *(const volatile u16
*) addr
;
37 static inline u32
readl(const volatile void __iomem
*addr
)
39 return *(const volatile u32
*) addr
;
42 #define __raw_readb readb
43 #define __raw_readw readw
44 #define __raw_readl readl
46 #define readb_relaxed readb
47 #define readw_relaxed readw
48 #define readl_relaxed readl
50 static inline void writeb(u8 b
, volatile void __iomem
*addr
)
52 *(volatile u8
*) addr
= b
;
55 static inline void writew(u16 b
, volatile void __iomem
*addr
)
57 *(volatile u16
*) addr
= b
;
60 static inline void writel(u32 b
, volatile void __iomem
*addr
)
62 *(volatile u32
*) addr
= b
;
65 #define __raw_writeb writeb
66 #define __raw_writew writew
67 #define __raw_writel writel
69 /*****************************************************************************/
71 * traditional input/output functions
73 static inline u8
inb_local(unsigned long addr
)
75 return readb((volatile void __iomem
*) addr
);
78 static inline void outb_local(u8 b
, unsigned long addr
)
80 return writeb(b
, (volatile void __iomem
*) addr
);
83 static inline u8
inb(unsigned long addr
)
85 return readb((volatile void __iomem
*) addr
);
88 static inline u16
inw(unsigned long addr
)
90 return readw((volatile void __iomem
*) addr
);
93 static inline u32
inl(unsigned long addr
)
95 return readl((volatile void __iomem
*) addr
);
98 static inline void outb(u8 b
, unsigned long addr
)
100 return writeb(b
, (volatile void __iomem
*) addr
);
103 static inline void outw(u16 b
, unsigned long addr
)
105 return writew(b
, (volatile void __iomem
*) addr
);
108 static inline void outl(u32 b
, unsigned long addr
)
110 return writel(b
, (volatile void __iomem
*) addr
);
113 #define inb_p(addr) inb(addr)
114 #define inw_p(addr) inw(addr)
115 #define inl_p(addr) inl(addr)
116 #define outb_p(x, addr) outb((x), (addr))
117 #define outw_p(x, addr) outw((x), (addr))
118 #define outl_p(x, addr) outl((x), (addr))
120 static inline void insb(unsigned long addr
, void *buffer
, int count
)
131 static inline void insw(unsigned long addr
, void *buffer
, int count
)
142 static inline void insl(unsigned long addr
, void *buffer
, int count
)
153 static inline void outsb(unsigned long addr
, const void *buffer
, int count
)
156 const u8
*buf
= buffer
;
163 static inline void outsw(unsigned long addr
, const void *buffer
, int count
)
166 const u16
*buf
= buffer
;
173 extern void __outsl(unsigned long addr
, const void *buffer
, int count
);
174 static inline void outsl(unsigned long addr
, const void *buffer
, int count
)
176 if ((unsigned long) buffer
& 0x3)
177 return __outsl(addr
, buffer
, count
);
180 const u32
*buf
= buffer
;
187 #define ioread8(addr) readb(addr)
188 #define ioread16(addr) readw(addr)
189 #define ioread32(addr) readl(addr)
191 #define iowrite8(v, addr) writeb((v), (addr))
192 #define iowrite16(v, addr) writew((v), (addr))
193 #define iowrite32(v, addr) writel((v), (addr))
195 #define ioread8_rep(p, dst, count) \
196 insb((unsigned long) (p), (dst), (count))
197 #define ioread16_rep(p, dst, count) \
198 insw((unsigned long) (p), (dst), (count))
199 #define ioread32_rep(p, dst, count) \
200 insl((unsigned long) (p), (dst), (count))
202 #define iowrite8_rep(p, src, count) \
203 outsb((unsigned long) (p), (src), (count))
204 #define iowrite16_rep(p, src, count) \
205 outsw((unsigned long) (p), (src), (count))
206 #define iowrite32_rep(p, src, count) \
207 outsl((unsigned long) (p), (src), (count))
210 #define IO_SPACE_LIMIT 0xffffffff
214 #include <linux/vmalloc.h>
215 #define __io_virt(x) ((void *) (x))
217 /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
219 extern void __iomem
*pci_iomap(struct pci_dev
*dev
, int bar
, unsigned long max
);
220 static inline void pci_iounmap(struct pci_dev
*dev
, void __iomem
*p
)
225 * Change virtual addresses to physical addresses and vv.
226 * These are pretty trivial
228 static inline unsigned long virt_to_phys(volatile void *address
)
230 return __pa(address
);
233 static inline void *phys_to_virt(unsigned long address
)
235 return __va(address
);
239 * Change "struct page" to physical address.
241 static inline void *__ioremap(unsigned long offset
, unsigned long size
,
244 return (void *) offset
;
247 static inline void *ioremap(unsigned long offset
, unsigned long size
)
249 return (void *) offset
;
253 * This one maps high address device memory and turns off caching for that
254 * area. it's useful if some control registers are in such an area and write
255 * combining or read caching is not desirable:
257 static inline void *ioremap_nocache(unsigned long offset
, unsigned long size
)
259 return (void *) (offset
| 0x20000000);
262 static inline void iounmap(void *addr
)
266 static inline void __iomem
*ioport_map(unsigned long port
, unsigned int nr
)
268 return (void __iomem
*) port
;
271 static inline void ioport_unmap(void __iomem
*p
)
275 #define xlate_dev_kmem_ptr(p) ((void *) (p))
276 #define xlate_dev_mem_ptr(p) ((void *) (p))
279 * PCI bus iomem addresses must be in the region 0x80000000-0x9fffffff
281 static inline unsigned long virt_to_bus(volatile void *address
)
283 return ((unsigned long) address
) & ~0x20000000;
286 static inline void *bus_to_virt(unsigned long address
)
288 return (void *) address
;
291 #define page_to_bus page_to_phys
293 #define memset_io(a, b, c) memset(__io_virt(a), (b), (c))
294 #define memcpy_fromio(a, b, c) memcpy((a), __io_virt(b), (c))
295 #define memcpy_toio(a, b, c) memcpy(__io_virt(a), (b), (c))
297 #endif /* __KERNEL__ */
299 #endif /* _ASM_IO_H */