Blame view
include/asm-generic/io.h
8.32 KB
3f7e212df asm-generic: add ... |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
/* Generic I/O port emulation, based on MN10300 code * * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. * Written by David Howells (dhowells@redhat.com) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public Licence * as published by the Free Software Foundation; either version * 2 of the Licence, or (at your option) any later version. */ #ifndef __ASM_GENERIC_IO_H #define __ASM_GENERIC_IO_H #include <asm/page.h> /* I/O is all done through memory accesses */ #include <asm/cacheflush.h> #include <linux/types.h> #ifdef CONFIG_GENERIC_IOMAP #include <asm-generic/iomap.h> #endif |
66eab4df2 lib: add GENERIC_... |
21 |
#include <asm-generic/pci_iomap.h> |
35dbc0e02 asm-generic/io.h:... |
22 |
#ifndef mmiowb |
3f7e212df asm-generic: add ... |
23 |
#define mmiowb() do {} while (0) |
35dbc0e02 asm-generic/io.h:... |
24 |
#endif |
3f7e212df asm-generic: add ... |
25 26 27 28 29 30 31 32 |
/*****************************************************************************/ /* * readX/writeX() are used to access memory mapped devices. On some * architectures the memory mapped IO stuff needs to be accessed * differently. On the simple architectures, we just read/write the * memory location directly. */ |
35dbc0e02 asm-generic/io.h:... |
33 |
#ifndef __raw_readb |
3f7e212df asm-generic: add ... |
34 35 36 37 |
static inline u8 __raw_readb(const volatile void __iomem *addr) { return *(const volatile u8 __force *) addr; } |
35dbc0e02 asm-generic/io.h:... |
38 |
#endif |
3f7e212df asm-generic: add ... |
39 |
|
35dbc0e02 asm-generic/io.h:... |
40 |
#ifndef __raw_readw |
3f7e212df asm-generic: add ... |
41 42 43 44 |
static inline u16 __raw_readw(const volatile void __iomem *addr) { return *(const volatile u16 __force *) addr; } |
35dbc0e02 asm-generic/io.h:... |
45 |
#endif |
3f7e212df asm-generic: add ... |
46 |
|
35dbc0e02 asm-generic/io.h:... |
47 |
#ifndef __raw_readl |
3f7e212df asm-generic: add ... |
48 49 50 51 |
static inline u32 __raw_readl(const volatile void __iomem *addr) { return *(const volatile u32 __force *) addr; } |
35dbc0e02 asm-generic/io.h:... |
52 |
#endif |
3f7e212df asm-generic: add ... |
53 54 55 56 |
#define readb __raw_readb #define readw(addr) __le16_to_cpu(__raw_readw(addr)) #define readl(addr) __le32_to_cpu(__raw_readl(addr)) |
35dbc0e02 asm-generic/io.h:... |
57 |
#ifndef __raw_writeb |
3f7e212df asm-generic: add ... |
58 59 60 61 |
static inline void __raw_writeb(u8 b, volatile void __iomem *addr) { *(volatile u8 __force *) addr = b; } |
35dbc0e02 asm-generic/io.h:... |
62 |
#endif |
3f7e212df asm-generic: add ... |
63 |
|
35dbc0e02 asm-generic/io.h:... |
64 |
#ifndef __raw_writew |
3f7e212df asm-generic: add ... |
65 66 67 68 |
static inline void __raw_writew(u16 b, volatile void __iomem *addr) { *(volatile u16 __force *) addr = b; } |
35dbc0e02 asm-generic/io.h:... |
69 |
#endif |
3f7e212df asm-generic: add ... |
70 |
|
35dbc0e02 asm-generic/io.h:... |
71 |
#ifndef __raw_writel |
3f7e212df asm-generic: add ... |
72 73 74 75 |
static inline void __raw_writel(u32 b, volatile void __iomem *addr) { *(volatile u32 __force *) addr = b; } |
35dbc0e02 asm-generic/io.h:... |
76 |
#endif |
3f7e212df asm-generic: add ... |
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
#define writeb __raw_writeb #define writew(b,addr) __raw_writew(__cpu_to_le16(b),addr) #define writel(b,addr) __raw_writel(__cpu_to_le32(b),addr) #ifdef CONFIG_64BIT static inline u64 __raw_readq(const volatile void __iomem *addr) { return *(const volatile u64 __force *) addr; } #define readq(addr) __le64_to_cpu(__raw_readq(addr)) static inline void __raw_writeq(u64 b, volatile void __iomem *addr) { *(volatile u64 __force *) addr = b; } #define writeq(b,addr) __raw_writeq(__cpu_to_le64(b),addr) #endif |
7dc59bdde asm-generic: fix ... |
95 96 97 |
#ifndef PCI_IOBASE #define PCI_IOBASE ((void __iomem *) 0) #endif |
3f7e212df asm-generic: add ... |
98 99 100 101 102 103 104 |
/*****************************************************************************/ /* * traditional input/output functions */ static inline u8 inb(unsigned long addr) { |
7dc59bdde asm-generic: fix ... |
105 |
return readb(addr + PCI_IOBASE); |
3f7e212df asm-generic: add ... |
106 107 108 109 |
} static inline u16 inw(unsigned long addr) { |
7dc59bdde asm-generic: fix ... |
110 |
return readw(addr + PCI_IOBASE); |
3f7e212df asm-generic: add ... |
111 112 113 114 |
} static inline u32 inl(unsigned long addr) { |
7dc59bdde asm-generic: fix ... |
115 |
return readl(addr + PCI_IOBASE); |
3f7e212df asm-generic: add ... |
116 117 118 119 |
} static inline void outb(u8 b, unsigned long addr) { |
7dc59bdde asm-generic: fix ... |
120 |
writeb(b, addr + PCI_IOBASE); |
3f7e212df asm-generic: add ... |
121 122 123 124 |
} static inline void outw(u16 b, unsigned long addr) { |
7dc59bdde asm-generic: fix ... |
125 |
writew(b, addr + PCI_IOBASE); |
3f7e212df asm-generic: add ... |
126 127 128 129 |
} static inline void outl(u32 b, unsigned long addr) { |
7dc59bdde asm-generic: fix ... |
130 |
writel(b, addr + PCI_IOBASE); |
3f7e212df asm-generic: add ... |
131 132 133 134 135 136 137 138 |
} #define inb_p(addr) inb(addr) #define inw_p(addr) inw(addr) #define inl_p(addr) inl(addr) #define outb_p(x, addr) outb((x), (addr)) #define outw_p(x, addr) outw((x), (addr)) #define outl_p(x, addr) outl((x), (addr)) |
35dbc0e02 asm-generic/io.h:... |
139 |
#ifndef insb |
3f7e212df asm-generic: add ... |
140 141 142 143 144 145 146 147 148 149 |
static inline void insb(unsigned long addr, void *buffer, int count) { if (count) { u8 *buf = buffer; do { u8 x = inb(addr); *buf++ = x; } while (--count); } } |
35dbc0e02 asm-generic/io.h:... |
150 |
#endif |
3f7e212df asm-generic: add ... |
151 |
|
35dbc0e02 asm-generic/io.h:... |
152 |
#ifndef insw |
3f7e212df asm-generic: add ... |
153 154 155 156 157 158 159 160 161 162 |
static inline void insw(unsigned long addr, void *buffer, int count) { if (count) { u16 *buf = buffer; do { u16 x = inw(addr); *buf++ = x; } while (--count); } } |
35dbc0e02 asm-generic/io.h:... |
163 |
#endif |
3f7e212df asm-generic: add ... |
164 |
|
35dbc0e02 asm-generic/io.h:... |
165 |
#ifndef insl |
3f7e212df asm-generic: add ... |
166 167 168 169 170 171 172 173 174 175 |
static inline void insl(unsigned long addr, void *buffer, int count) { if (count) { u32 *buf = buffer; do { u32 x = inl(addr); *buf++ = x; } while (--count); } } |
35dbc0e02 asm-generic/io.h:... |
176 |
#endif |
3f7e212df asm-generic: add ... |
177 |
|
35dbc0e02 asm-generic/io.h:... |
178 |
#ifndef outsb |
3f7e212df asm-generic: add ... |
179 180 181 182 183 184 185 186 187 |
static inline void outsb(unsigned long addr, const void *buffer, int count) { if (count) { const u8 *buf = buffer; do { outb(*buf++, addr); } while (--count); } } |
35dbc0e02 asm-generic/io.h:... |
188 |
#endif |
3f7e212df asm-generic: add ... |
189 |
|
35dbc0e02 asm-generic/io.h:... |
190 |
#ifndef outsw |
3f7e212df asm-generic: add ... |
191 192 193 194 195 196 197 198 199 |
static inline void outsw(unsigned long addr, const void *buffer, int count) { if (count) { const u16 *buf = buffer; do { outw(*buf++, addr); } while (--count); } } |
35dbc0e02 asm-generic/io.h:... |
200 |
#endif |
3f7e212df asm-generic: add ... |
201 |
|
35dbc0e02 asm-generic/io.h:... |
202 |
#ifndef outsl |
3f7e212df asm-generic: add ... |
203 204 205 206 207 208 209 210 211 |
static inline void outsl(unsigned long addr, const void *buffer, int count) { if (count) { const u32 *buf = buffer; do { outl(*buf++, addr); } while (--count); } } |
35dbc0e02 asm-generic/io.h:... |
212 |
#endif |
3f7e212df asm-generic: add ... |
213 |
|
efb2d31c1 asm-generic/io.h:... |
214 215 |
static inline void readsl(const void __iomem *addr, void *buf, int len) { |
7dc59bdde asm-generic: fix ... |
216 |
insl(addr - PCI_IOBASE, buf, len); |
efb2d31c1 asm-generic/io.h:... |
217 218 219 220 |
} static inline void readsw(const void __iomem *addr, void *buf, int len) { |
7dc59bdde asm-generic: fix ... |
221 |
insw(addr - PCI_IOBASE, buf, len); |
efb2d31c1 asm-generic/io.h:... |
222 223 224 225 |
} static inline void readsb(const void __iomem *addr, void *buf, int len) { |
7dc59bdde asm-generic: fix ... |
226 |
insb(addr - PCI_IOBASE, buf, len); |
efb2d31c1 asm-generic/io.h:... |
227 228 229 230 |
} static inline void writesl(const void __iomem *addr, const void *buf, int len) { |
7dc59bdde asm-generic: fix ... |
231 |
outsl(addr - PCI_IOBASE, buf, len); |
efb2d31c1 asm-generic/io.h:... |
232 233 234 235 |
} static inline void writesw(const void __iomem *addr, const void *buf, int len) { |
7dc59bdde asm-generic: fix ... |
236 |
outsw(addr - PCI_IOBASE, buf, len); |
efb2d31c1 asm-generic/io.h:... |
237 238 239 240 |
} static inline void writesb(const void __iomem *addr, const void *buf, int len) { |
7dc59bdde asm-generic: fix ... |
241 |
outsb(addr - PCI_IOBASE, buf, len); |
efb2d31c1 asm-generic/io.h:... |
242 |
} |
3f7e212df asm-generic: add ... |
243 244 245 |
#ifndef CONFIG_GENERIC_IOMAP #define ioread8(addr) readb(addr) #define ioread16(addr) readw(addr) |
7387be337 asm-generic/io.h:... |
246 |
#define ioread16be(addr) be16_to_cpu(ioread16(addr)) |
3f7e212df asm-generic: add ... |
247 |
#define ioread32(addr) readl(addr) |
7387be337 asm-generic/io.h:... |
248 |
#define ioread32be(addr) be32_to_cpu(ioread32(addr)) |
3f7e212df asm-generic: add ... |
249 250 251 |
#define iowrite8(v, addr) writeb((v), (addr)) #define iowrite16(v, addr) writew((v), (addr)) |
7387be337 asm-generic/io.h:... |
252 |
#define iowrite16be(v, addr) iowrite16(be16_to_cpu(v), (addr)) |
3f7e212df asm-generic: add ... |
253 |
#define iowrite32(v, addr) writel((v), (addr)) |
7387be337 asm-generic/io.h:... |
254 |
#define iowrite32be(v, addr) iowrite32(be32_to_cpu(v), (addr)) |
3f7e212df asm-generic: add ... |
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
#define ioread8_rep(p, dst, count) \ insb((unsigned long) (p), (dst), (count)) #define ioread16_rep(p, dst, count) \ insw((unsigned long) (p), (dst), (count)) #define ioread32_rep(p, dst, count) \ insl((unsigned long) (p), (dst), (count)) #define iowrite8_rep(p, src, count) \ outsb((unsigned long) (p), (src), (count)) #define iowrite16_rep(p, src, count) \ outsw((unsigned long) (p), (src), (count)) #define iowrite32_rep(p, src, count) \ outsl((unsigned long) (p), (src), (count)) #endif /* CONFIG_GENERIC_IOMAP */ |
7dc59bdde asm-generic: fix ... |
270 271 272 |
#ifndef IO_SPACE_LIMIT #define IO_SPACE_LIMIT 0xffff #endif |
3f7e212df asm-generic: add ... |
273 274 275 276 277 278 279 |
#ifdef __KERNEL__ #include <linux/vmalloc.h> #define __io_virt(x) ((void __force *) (x)) #ifndef CONFIG_GENERIC_IOMAP |
3f7e212df asm-generic: add ... |
280 |
struct pci_dev; |
3f7e212df asm-generic: add ... |
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p) { } #endif /* CONFIG_GENERIC_IOMAP */ /* * Change virtual addresses to physical addresses and vv. * These are pretty trivial */ static inline unsigned long virt_to_phys(volatile void *address) { return __pa((unsigned long)address); } static inline void *phys_to_virt(unsigned long address) { return __va(address); } /* * Change "struct page" to physical address. |
f1ecc6983 asm-generic: add ... |
302 303 304 |
* * This implementation is for the no-MMU case only... if you have an MMU * you'll need to provide your own definitions. |
3f7e212df asm-generic: add ... |
305 |
*/ |
f1ecc6983 asm-generic: add ... |
306 |
#ifndef CONFIG_MMU |
3f7e212df asm-generic: add ... |
307 308 309 310 311 312 313 314 315 316 317 318 319 320 |
static inline void __iomem *ioremap(phys_addr_t offset, unsigned long size) { return (void __iomem*) (unsigned long)offset; } #define __ioremap(offset, size, flags) ioremap(offset, size) #ifndef ioremap_nocache #define ioremap_nocache ioremap #endif #ifndef ioremap_wc #define ioremap_wc ioremap_nocache #endif |
e66d3c490 add missing __iom... |
321 |
static inline void iounmap(void __iomem *addr) |
3f7e212df asm-generic: add ... |
322 323 |
{ } |
f1ecc6983 asm-generic: add ... |
324 |
#endif /* CONFIG_MMU */ |
3f7e212df asm-generic: add ... |
325 |
|
82ed223c2 iomap: make IOPOR... |
326 |
#ifdef CONFIG_HAS_IOPORT |
3f7e212df asm-generic: add ... |
327 328 329 330 331 332 333 334 335 336 337 338 339 |
#ifndef CONFIG_GENERIC_IOMAP static inline void __iomem *ioport_map(unsigned long port, unsigned int nr) { return (void __iomem *) port; } static inline void ioport_unmap(void __iomem *p) { } #else /* CONFIG_GENERIC_IOMAP */ extern void __iomem *ioport_map(unsigned long port, unsigned int nr); extern void ioport_unmap(void __iomem *p); #endif /* CONFIG_GENERIC_IOMAP */ |
82ed223c2 iomap: make IOPOR... |
340 |
#endif /* CONFIG_HAS_IOPORT */ |
3f7e212df asm-generic: add ... |
341 342 |
#define xlate_dev_kmem_ptr(p) p |
f1ecc6983 asm-generic: add ... |
343 |
#define xlate_dev_mem_ptr(p) __va(p) |
3f7e212df asm-generic: add ... |
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
#ifndef virt_to_bus static inline unsigned long virt_to_bus(volatile void *address) { return ((unsigned long) address); } static inline void *bus_to_virt(unsigned long address) { return (void *) address; } #endif #define memset_io(a, b, c) memset(__io_virt(a), (b), (c)) #define memcpy_fromio(a, b, c) memcpy((a), __io_virt(b), (c)) #define memcpy_toio(a, b, c) memcpy(__io_virt(a), (b), (c)) #endif /* __KERNEL__ */ #endif /* __ASM_GENERIC_IO_H */ |