io.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  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. /*****************************************************************************/
  59. /*
  60. * traditional input/output functions
  61. */
  62. static inline u8 inb_local(unsigned long addr)
  63. {
  64. return readb((volatile void __iomem *) addr);
  65. }
  66. static inline void outb_local(u8 b, unsigned long addr)
  67. {
  68. return writeb(b, (volatile void __iomem *) addr);
  69. }
  70. static inline u8 inb(unsigned long addr)
  71. {
  72. return readb((volatile void __iomem *) addr);
  73. }
  74. static inline u16 inw(unsigned long addr)
  75. {
  76. return readw((volatile void __iomem *) addr);
  77. }
  78. static inline u32 inl(unsigned long addr)
  79. {
  80. return readl((volatile void __iomem *) addr);
  81. }
  82. static inline void outb(u8 b, unsigned long addr)
  83. {
  84. return writeb(b, (volatile void __iomem *) addr);
  85. }
  86. static inline void outw(u16 b, unsigned long addr)
  87. {
  88. return writew(b, (volatile void __iomem *) addr);
  89. }
  90. static inline void outl(u32 b, unsigned long addr)
  91. {
  92. return writel(b, (volatile void __iomem *) addr);
  93. }
  94. #define inb_p(addr) inb(addr)
  95. #define inw_p(addr) inw(addr)
  96. #define inl_p(addr) inl(addr)
  97. #define outb_p(x, addr) outb((x), (addr))
  98. #define outw_p(x, addr) outw((x), (addr))
  99. #define outl_p(x, addr) outl((x), (addr))
  100. static inline void insb(unsigned long addr, void *buffer, int count)
  101. {
  102. if (count) {
  103. u8 *buf = buffer;
  104. do {
  105. u8 x = inb(addr);
  106. *buf++ = x;
  107. } while (--count);
  108. }
  109. }
  110. static inline void insw(unsigned long addr, void *buffer, int count)
  111. {
  112. if (count) {
  113. u16 *buf = buffer;
  114. do {
  115. u16 x = inw(addr);
  116. *buf++ = x;
  117. } while (--count);
  118. }
  119. }
  120. static inline void insl(unsigned long addr, void *buffer, int count)
  121. {
  122. if (count) {
  123. u32 *buf = buffer;
  124. do {
  125. u32 x = inl(addr);
  126. *buf++ = x;
  127. } while (--count);
  128. }
  129. }
  130. static inline void outsb(unsigned long addr, const void *buffer, int count)
  131. {
  132. if (count) {
  133. const u8 *buf = buffer;
  134. do {
  135. outb(*buf++, addr);
  136. } while (--count);
  137. }
  138. }
  139. static inline void outsw(unsigned long addr, const void *buffer, int count)
  140. {
  141. if (count) {
  142. const u16 *buf = buffer;
  143. do {
  144. outw(*buf++, addr);
  145. } while (--count);
  146. }
  147. }
  148. extern void __outsl(unsigned long addr, const void *buffer, int count);
  149. static inline void outsl(unsigned long addr, const void *buffer, int count)
  150. {
  151. if ((unsigned long) buffer & 0x3)
  152. return __outsl(addr, buffer, count);
  153. if (count) {
  154. const u32 *buf = buffer;
  155. do {
  156. outl(*buf++, addr);
  157. } while (--count);
  158. }
  159. }
  160. #define ioread8(addr) readb(addr)
  161. #define ioread16(addr) readw(addr)
  162. #define ioread32(addr) readl(addr)
  163. #define iowrite8(v, addr) writeb((v), (addr))
  164. #define iowrite16(v, addr) writew((v), (addr))
  165. #define iowrite32(v, addr) writel((v), (addr))
  166. #define ioread8_rep(p, dst, count) \
  167. insb((unsigned long) (p), (dst), (count))
  168. #define ioread16_rep(p, dst, count) \
  169. insw((unsigned long) (p), (dst), (count))
  170. #define ioread32_rep(p, dst, count) \
  171. insl((unsigned long) (p), (dst), (count))
  172. #define iowrite8_rep(p, src, count) \
  173. outsb((unsigned long) (p), (src), (count))
  174. #define iowrite16_rep(p, src, count) \
  175. outsw((unsigned long) (p), (src), (count))
  176. #define iowrite32_rep(p, src, count) \
  177. outsl((unsigned long) (p), (src), (count))
  178. #define readsb(p, dst, count) \
  179. insb((unsigned long) (p), (dst), (count))
  180. #define readsw(p, dst, count) \
  181. insw((unsigned long) (p), (dst), (count))
  182. #define readsl(p, dst, count) \
  183. insl((unsigned long) (p), (dst), (count))
  184. #define writesb(p, src, count) \
  185. outsb((unsigned long) (p), (src), (count))
  186. #define writesw(p, src, count) \
  187. outsw((unsigned long) (p), (src), (count))
  188. #define writesl(p, src, count) \
  189. outsl((unsigned long) (p), (src), (count))
  190. #define IO_SPACE_LIMIT 0xffffffff
  191. #ifdef __KERNEL__
  192. #include <linux/vmalloc.h>
  193. #define __io_virt(x) ((void *) (x))
  194. /* Create a virtual mapping cookie for a PCI BAR (memory or IO) */
  195. struct pci_dev;
  196. static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
  197. {
  198. }
  199. /*
  200. * Change virtual addresses to physical addresses and vv.
  201. * These are pretty trivial
  202. */
  203. static inline unsigned long virt_to_phys(volatile void *address)
  204. {
  205. return __pa(address);
  206. }
  207. static inline void *phys_to_virt(unsigned long address)
  208. {
  209. return __va(address);
  210. }
  211. /*
  212. * Change "struct page" to physical address.
  213. */
  214. static inline void __iomem *__ioremap(unsigned long offset, unsigned long size,
  215. unsigned long flags)
  216. {
  217. return (void __iomem *) offset;
  218. }
  219. static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
  220. {
  221. return (void __iomem *)(offset & ~0x20000000);
  222. }
  223. /*
  224. * This one maps high address device memory and turns off caching for that
  225. * area. it's useful if some control registers are in such an area and write
  226. * combining or read caching is not desirable:
  227. */
  228. static inline void __iomem *ioremap_nocache(unsigned long offset, unsigned long size)
  229. {
  230. return (void __iomem *) (offset | 0x20000000);
  231. }
  232. #define ioremap_wc ioremap_nocache
  233. static inline void iounmap(void __iomem *addr)
  234. {
  235. }
  236. static inline void __iomem *ioport_map(unsigned long port, unsigned int nr)
  237. {
  238. return (void __iomem *) port;
  239. }
  240. static inline void ioport_unmap(void __iomem *p)
  241. {
  242. }
  243. #define xlate_dev_kmem_ptr(p) ((void *) (p))
  244. #define xlate_dev_mem_ptr(p) ((void *) (p))
  245. /*
  246. * PCI bus iomem addresses must be in the region 0x80000000-0x9fffffff
  247. */
  248. static inline unsigned long virt_to_bus(volatile void *address)
  249. {
  250. return ((unsigned long) address) & ~0x20000000;
  251. }
  252. static inline void *bus_to_virt(unsigned long address)
  253. {
  254. return (void *) address;
  255. }
  256. #define page_to_bus page_to_phys
  257. #define memset_io(a, b, c) memset(__io_virt(a), (b), (c))
  258. #define memcpy_fromio(a, b, c) memcpy((a), __io_virt(b), (c))
  259. #define memcpy_toio(a, b, c) memcpy(__io_virt(a), (b), (c))
  260. #endif /* __KERNEL__ */
  261. #endif /* _ASM_IO_H */