io.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /* 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. #include <asm/page.h> /* I/O is all done through memory accesses */
  14. #include <asm/cpu-regs.h>
  15. #include <asm/cacheflush.h>
  16. #include <asm-generic/pci_iomap.h>
  17. #define mmiowb() do {} while (0)
  18. /*****************************************************************************/
  19. /*
  20. * readX/writeX() are used to access memory mapped devices. On some
  21. * architectures the memory mapped IO stuff needs to be accessed
  22. * differently. On the x86 architecture, we just read/write the
  23. * memory location directly.
  24. */
  25. static inline u8 readb(const volatile void __iomem *addr)
  26. {
  27. return *(const volatile u8 *) addr;
  28. }
  29. static inline u16 readw(const volatile void __iomem *addr)
  30. {
  31. return *(const volatile u16 *) addr;
  32. }
  33. static inline u32 readl(const volatile void __iomem *addr)
  34. {
  35. return *(const volatile u32 *) addr;
  36. }
  37. #define __raw_readb readb
  38. #define __raw_readw readw
  39. #define __raw_readl readl
  40. #define readb_relaxed readb
  41. #define readw_relaxed readw
  42. #define readl_relaxed readl
  43. static inline void writeb(u8 b, volatile void __iomem *addr)
  44. {
  45. *(volatile u8 *) addr = b;
  46. }
  47. static inline void writew(u16 b, volatile void __iomem *addr)
  48. {
  49. *(volatile u16 *) addr = b;
  50. }
  51. static inline void writel(u32 b, volatile void __iomem *addr)
  52. {
  53. *(volatile u32 *) addr = b;
  54. }
  55. #define __raw_writeb writeb
  56. #define __raw_writew writew
  57. #define __raw_writel writel
  58. #define writeb_relaxed writeb
  59. #define writew_relaxed writew
  60. #define writel_relaxed writel
  61. /*****************************************************************************/
  62. /*
  63. * traditional input/output functions
  64. */
  65. static inline u8 inb_local(unsigned long addr)
  66. {
  67. return readb((volatile void __iomem *) addr);
  68. }
  69. static inline void outb_local(u8 b, unsigned long addr)
  70. {
  71. return writeb(b, (volatile void __iomem *) addr);
  72. }
  73. static inline u8 inb(unsigned long addr)
  74. {
  75. return readb((volatile void __iomem *) addr);
  76. }
  77. static inline u16 inw(unsigned long addr)
  78. {
  79. return readw((volatile void __iomem *) addr);
  80. }
  81. static inline u32 inl(unsigned long addr)
  82. {
  83. return readl((volatile void __iomem *) addr);
  84. }
  85. static inline void outb(u8 b, unsigned long addr)
  86. {
  87. return writeb(b, (volatile void __iomem *) addr);
  88. }
  89. static inline void outw(u16 b, unsigned long addr)
  90. {
  91. return writew(b, (volatile void __iomem *) addr);
  92. }
  93. static inline void outl(u32 b, unsigned long addr)
  94. {
  95. return writel(b, (volatile void __iomem *) addr);
  96. }
  97. #define inb_p(addr) inb(addr)
  98. #define inw_p(addr) inw(addr)
  99. #define inl_p(addr) inl(addr)
  100. #define outb_p(x, addr) outb((x), (addr))
  101. #define outw_p(x, addr) outw((x), (addr))
  102. #define outl_p(x, addr) outl((x), (addr))
  103. static inline void insb(unsigned long addr, void *buffer, int count)
  104. {
  105. if (count) {
  106. u8 *buf = buffer;
  107. do {
  108. u8 x = inb(addr);
  109. *buf++ = x;
  110. } while (--count);
  111. }
  112. }
  113. static inline void insw(unsigned long addr, void *buffer, int count)
  114. {
  115. if (count) {
  116. u16 *buf = buffer;
  117. do {
  118. u16 x = inw(addr);
  119. *buf++ = x;
  120. } while (--count);
  121. }
  122. }
  123. static inline void insl(unsigned long addr, void *buffer, int count)
  124. {
  125. if (count) {
  126. u32 *buf = buffer;
  127. do {
  128. u32 x = inl(addr);
  129. *buf++ = x;
  130. } while (--count);
  131. }
  132. }
  133. static inline void outsb(unsigned long addr, const void *buffer, int count)
  134. {
  135. if (count) {
  136. const u8 *buf = buffer;
  137. do {
  138. outb(*buf++, addr);
  139. } while (--count);
  140. }
  141. }
  142. static inline void outsw(unsigned long addr, const void *buffer, int count)
  143. {
  144. if (count) {
  145. const u16 *buf = buffer;
  146. do {
  147. outw(*buf++, addr);
  148. } while (--count);
  149. }
  150. }
  151. extern void __outsl(unsigned long addr, const void *buffer, int count);
  152. static inline void outsl(unsigned long addr, const void *buffer, int count)
  153. {
  154. if ((unsigned long) buffer & 0x3)
  155. return __outsl(addr, buffer, count);
  156. if (count) {
  157. const u32 *buf = buffer;
  158. do {
  159. outl(*buf++, addr);
  160. } while (--count);
  161. }
  162. }
  163. #define ioread8(addr) readb(addr)
  164. #define ioread16(addr) readw(addr)
  165. #define ioread32(addr) readl(addr)
  166. #define iowrite8(v, addr) writeb((v), (addr))
  167. #define iowrite16(v, addr) writew((v), (addr))
  168. #define iowrite32(v, addr) writel((v), (addr))
  169. #define ioread16be(addr) be16_to_cpu(readw(addr))
  170. #define ioread32be(addr) be32_to_cpu(readl(addr))
  171. #define iowrite16be(v, addr) writew(cpu_to_be16(v), (addr))
  172. #define iowrite32be(v, addr) writel(cpu_to_be32(v), (addr))
  173. #define ioread8_rep(p, dst, count) \
  174. insb((unsigned long) (p), (dst), (count))
  175. #define ioread16_rep(p, dst, count) \
  176. insw((unsigned long) (p), (dst), (count))
  177. #define ioread32_rep(p, dst, count) \
  178. insl((unsigned long) (p), (dst), (count))
  179. #define iowrite8_rep(p, src, count) \
  180. outsb((unsigned long) (p), (src), (count))
  181. #define iowrite16_rep(p, src, count) \
  182. outsw((unsigned long) (p), (src), (count))
  183. #define iowrite32_rep(p, src, count) \
  184. outsl((unsigned long) (p), (src), (count))
  185. #define readsb(p, dst, count) \
  186. insb((unsigned long) (p), (dst), (count))
  187. #define readsw(p, dst, count) \
  188. insw((unsigned long) (p), (dst), (count))
  189. #define readsl(p, dst, count) \
  190. insl((unsigned long) (p), (dst), (count))
  191. #define writesb(p, src, count) \
  192. outsb((unsigned long) (p), (src), (count))
  193. #define writesw(p, src, count) \
  194. outsw((unsigned long) (p), (src), (count))
  195. #define writesl(p, src, count) \
  196. outsl((unsigned long) (p), (src), (count))
  197. #define IO_SPACE_LIMIT 0xffffffff
  198. #ifdef __KERNEL__
  199. #include <linux/vmalloc.h>
  200. #define __io_virt(x) ((void *) (x))
  201. /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
  202. struct pci_dev;
  203. static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
  204. {
  205. }
  206. /*
  207. * Change virtual addresses to physical addresses and vv.
  208. * These are pretty trivial
  209. */
  210. static inline unsigned long virt_to_phys(volatile void *address)
  211. {
  212. return __pa(address);
  213. }
  214. static inline void *phys_to_virt(unsigned long address)
  215. {
  216. return __va(address);
  217. }
  218. /*
  219. * Change "struct page" to physical address.
  220. */
  221. static inline void __iomem *__ioremap(unsigned long offset, unsigned long size,
  222. unsigned long flags)
  223. {
  224. return (void __iomem *) offset;
  225. }
  226. static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
  227. {
  228. return (void __iomem *)(offset & ~0x20000000);
  229. }
  230. /*
  231. * This one maps high address device memory and turns off caching for that
  232. * area. it's useful if some control registers are in such an area and write
  233. * combining or read caching is not desirable:
  234. */
  235. static inline void __iomem *ioremap_nocache(unsigned long offset, unsigned long size)
  236. {
  237. return (void __iomem *) (offset | 0x20000000);
  238. }
  239. #define ioremap_wc ioremap_nocache
  240. #define ioremap_wt ioremap_nocache
  241. #define ioremap_uc ioremap_nocache
  242. static inline void iounmap(void __iomem *addr)
  243. {
  244. }
  245. static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
  246. {
  247. return (void __iomem *) port;
  248. }
  249. static inline void ioport_unmap(void __iomem *p)
  250. {
  251. }
  252. #define xlate_dev_kmem_ptr(p) ((void *) (p))
  253. #define xlate_dev_mem_ptr(p) ((void *) (p))
  254. /*
  255. * PCI bus iomem addresses must be in the region 0x80000000-0x9fffffff
  256. */
  257. static inline unsigned long virt_to_bus(volatile void *address)
  258. {
  259. return ((unsigned long) address) & ~0x20000000;
  260. }
  261. static inline void *bus_to_virt(unsigned long address)
  262. {
  263. return (void *) address;
  264. }
  265. #define page_to_bus page_to_phys
  266. #define memset_io(a, b, c) memset(__io_virt(a), (b), (c))
  267. #define memcpy_fromio(a, b, c) memcpy((a), __io_virt(b), (c))
  268. #define memcpy_toio(a, b, c) memcpy(__io_virt(a), (b), (c))
  269. #endif /* __KERNEL__ */
  270. #endif /* _ASM_IO_H */