blob: 897ba3c12b3276b9071a56e70e67e7e39d28850e [file] [log] [blame]
David Howellsb920de12008-02-08 04:19:31 -08001/* MN10300 I/O port emulation and memory-mapped I/O
2 *
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
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.
10 */
11#ifndef _ASM_IO_H
12#define _ASM_IO_H
13
14#include <asm/page.h> /* I/O is all done through memory accesses */
15#include <asm/cpu-regs.h>
16#include <asm/cacheflush.h>
David Howells76583cf2012-12-12 15:36:40 +000017#include <asm-generic/pci_iomap.h>
David Howellsb920de12008-02-08 04:19:31 -080018
19#define mmiowb() do {} while (0)
20
21/*****************************************************************************/
22/*
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.
27 */
28static inline u8 readb(const volatile void __iomem *addr)
29{
30 return *(const volatile u8 *) addr;
31}
32
33static inline u16 readw(const volatile void __iomem *addr)
34{
35 return *(const volatile u16 *) addr;
36}
37
38static inline u32 readl(const volatile void __iomem *addr)
39{
40 return *(const volatile u32 *) addr;
41}
42
43#define __raw_readb readb
44#define __raw_readw readw
45#define __raw_readl readl
46
47#define readb_relaxed readb
48#define readw_relaxed readw
49#define readl_relaxed readl
50
51static inline void writeb(u8 b, volatile void __iomem *addr)
52{
53 *(volatile u8 *) addr = b;
54}
55
56static inline void writew(u16 b, volatile void __iomem *addr)
57{
58 *(volatile u16 *) addr = b;
59}
60
61static inline void writel(u32 b, volatile void __iomem *addr)
62{
63 *(volatile u32 *) addr = b;
64}
65
66#define __raw_writeb writeb
67#define __raw_writew writew
68#define __raw_writel writel
69
Will Deacon960a5592013-09-03 19:17:02 +010070#define writeb_relaxed writeb
71#define writew_relaxed writew
72#define writel_relaxed writel
73
David Howellsb920de12008-02-08 04:19:31 -080074/*****************************************************************************/
75/*
76 * traditional input/output functions
77 */
78static inline u8 inb_local(unsigned long addr)
79{
80 return readb((volatile void __iomem *) addr);
81}
82
83static inline void outb_local(u8 b, unsigned long addr)
84{
85 return writeb(b, (volatile void __iomem *) addr);
86}
87
88static inline u8 inb(unsigned long addr)
89{
90 return readb((volatile void __iomem *) addr);
91}
92
93static inline u16 inw(unsigned long addr)
94{
95 return readw((volatile void __iomem *) addr);
96}
97
98static inline u32 inl(unsigned long addr)
99{
100 return readl((volatile void __iomem *) addr);
101}
102
103static inline void outb(u8 b, unsigned long addr)
104{
105 return writeb(b, (volatile void __iomem *) addr);
106}
107
108static inline void outw(u16 b, unsigned long addr)
109{
110 return writew(b, (volatile void __iomem *) addr);
111}
112
113static inline void outl(u32 b, unsigned long addr)
114{
115 return writel(b, (volatile void __iomem *) addr);
116}
117
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))
124
125static inline void insb(unsigned long addr, void *buffer, int count)
126{
127 if (count) {
128 u8 *buf = buffer;
129 do {
130 u8 x = inb(addr);
131 *buf++ = x;
132 } while (--count);
133 }
134}
135
136static inline void insw(unsigned long addr, void *buffer, int count)
137{
138 if (count) {
139 u16 *buf = buffer;
140 do {
141 u16 x = inw(addr);
142 *buf++ = x;
143 } while (--count);
144 }
145}
146
147static inline void insl(unsigned long addr, void *buffer, int count)
148{
149 if (count) {
150 u32 *buf = buffer;
151 do {
152 u32 x = inl(addr);
153 *buf++ = x;
154 } while (--count);
155 }
156}
157
158static inline void outsb(unsigned long addr, const void *buffer, int count)
159{
160 if (count) {
161 const u8 *buf = buffer;
162 do {
163 outb(*buf++, addr);
164 } while (--count);
165 }
166}
167
168static inline void outsw(unsigned long addr, const void *buffer, int count)
169{
170 if (count) {
171 const u16 *buf = buffer;
172 do {
173 outw(*buf++, addr);
174 } while (--count);
175 }
176}
177
178extern void __outsl(unsigned long addr, const void *buffer, int count);
179static inline void outsl(unsigned long addr, const void *buffer, int count)
180{
181 if ((unsigned long) buffer & 0x3)
182 return __outsl(addr, buffer, count);
183
184 if (count) {
185 const u32 *buf = buffer;
186 do {
187 outl(*buf++, addr);
188 } while (--count);
189 }
190}
191
192#define ioread8(addr) readb(addr)
193#define ioread16(addr) readw(addr)
194#define ioread32(addr) readl(addr)
195
196#define iowrite8(v, addr) writeb((v), (addr))
197#define iowrite16(v, addr) writew((v), (addr))
198#define iowrite32(v, addr) writel((v), (addr))
199
200#define ioread8_rep(p, dst, count) \
201 insb((unsigned long) (p), (dst), (count))
202#define ioread16_rep(p, dst, count) \
203 insw((unsigned long) (p), (dst), (count))
204#define ioread32_rep(p, dst, count) \
205 insl((unsigned long) (p), (dst), (count))
206
207#define iowrite8_rep(p, src, count) \
208 outsb((unsigned long) (p), (src), (count))
209#define iowrite16_rep(p, src, count) \
210 outsw((unsigned long) (p), (src), (count))
211#define iowrite32_rep(p, src, count) \
212 outsl((unsigned long) (p), (src), (count))
213
Akira Takeuchi9f59f7d2010-10-27 17:28:37 +0100214#define readsb(p, dst, count) \
215 insb((unsigned long) (p), (dst), (count))
216#define readsw(p, dst, count) \
217 insw((unsigned long) (p), (dst), (count))
218#define readsl(p, dst, count) \
219 insl((unsigned long) (p), (dst), (count))
220
221#define writesb(p, src, count) \
222 outsb((unsigned long) (p), (src), (count))
223#define writesw(p, src, count) \
224 outsw((unsigned long) (p), (src), (count))
225#define writesl(p, src, count) \
226 outsl((unsigned long) (p), (src), (count))
David Howellsb920de12008-02-08 04:19:31 -0800227
228#define IO_SPACE_LIMIT 0xffffffff
229
230#ifdef __KERNEL__
231
232#include <linux/vmalloc.h>
233#define __io_virt(x) ((void *) (x))
234
235/* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
236struct pci_dev;
David Howellsb920de12008-02-08 04:19:31 -0800237static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
238{
239}
240
241/*
242 * Change virtual addresses to physical addresses and vv.
243 * These are pretty trivial
244 */
245static inline unsigned long virt_to_phys(volatile void *address)
246{
247 return __pa(address);
248}
249
250static inline void *phys_to_virt(unsigned long address)
251{
252 return __va(address);
253}
254
255/*
256 * Change "struct page" to physical address.
257 */
Michael S. Tsirkin2ebf5d02011-12-01 13:12:22 +0200258static inline void __iomem *__ioremap(unsigned long offset, unsigned long size,
259 unsigned long flags)
David Howellsb920de12008-02-08 04:19:31 -0800260{
Michael S. Tsirkin2ebf5d02011-12-01 13:12:22 +0200261 return (void __iomem *) offset;
David Howellsb920de12008-02-08 04:19:31 -0800262}
263
Michael S. Tsirkin2ebf5d02011-12-01 13:12:22 +0200264static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
David Howellsb920de12008-02-08 04:19:31 -0800265{
David Howells83c2dc12012-12-12 15:36:39 +0000266 return (void __iomem *)(offset & ~0x20000000);
David Howellsb920de12008-02-08 04:19:31 -0800267}
268
269/*
270 * This one maps high address device memory and turns off caching for that
271 * area. it's useful if some control registers are in such an area and write
272 * combining or read caching is not desirable:
273 */
Michael S. Tsirkin2ebf5d02011-12-01 13:12:22 +0200274static inline void __iomem *ioremap_nocache(unsigned long offset, unsigned long size)
David Howellsb920de12008-02-08 04:19:31 -0800275{
Michael S. Tsirkin2ebf5d02011-12-01 13:12:22 +0200276 return (void __iomem *) (offset | 0x20000000);
David Howellsb920de12008-02-08 04:19:31 -0800277}
278
David Howells449f7652008-08-20 15:53:33 +0100279#define ioremap_wc ioremap_nocache
280
Michael S. Tsirkin2ebf5d02011-12-01 13:12:22 +0200281static inline void iounmap(void __iomem *addr)
David Howellsb920de12008-02-08 04:19:31 -0800282{
283}
284
285static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
286{
287 return (void __iomem *) port;
288}
289
290static inline void ioport_unmap(void __iomem *p)
291{
292}
293
294#define xlate_dev_kmem_ptr(p) ((void *) (p))
295#define xlate_dev_mem_ptr(p) ((void *) (p))
296
297/*
298 * PCI bus iomem addresses must be in the region 0x80000000-0x9fffffff
299 */
300static inline unsigned long virt_to_bus(volatile void *address)
301{
302 return ((unsigned long) address) & ~0x20000000;
303}
304
305static inline void *bus_to_virt(unsigned long address)
306{
307 return (void *) address;
308}
309
310#define page_to_bus page_to_phys
311
312#define memset_io(a, b, c) memset(__io_virt(a), (b), (c))
313#define memcpy_fromio(a, b, c) memcpy((a), __io_virt(b), (c))
314#define memcpy_toio(a, b, c) memcpy(__io_virt(a), (b), (c))
315
316#endif /* __KERNEL__ */
317
318#endif /* _ASM_IO_H */