io.h 6.8 KB

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