io.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338
  1. /*
  2. * IO definitions for the Hexagon architecture
  3. *
  4. * Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #ifndef _ASM_IO_H
  21. #define _ASM_IO_H
  22. #ifdef __KERNEL__
  23. #include <linux/types.h>
  24. #include <asm/iomap.h>
  25. #include <asm/page.h>
  26. #include <asm/cacheflush.h>
  27. /*
  28. * We don't have PCI yet.
  29. * _IO_BASE is pointing at what should be unused virtual space.
  30. */
  31. #define IO_SPACE_LIMIT 0xffff
  32. #define _IO_BASE ((void __iomem *)0xfe000000)
  33. #define IOMEM(x) ((void __force __iomem *)(x))
  34. extern int remap_area_pages(unsigned long start, unsigned long phys_addr,
  35. unsigned long end, unsigned long flags);
  36. extern void __iounmap(const volatile void __iomem *addr);
  37. /* Defined in lib/io.c, needed for smc91x driver. */
  38. extern void __raw_readsw(const void __iomem *addr, void *data, int wordlen);
  39. extern void __raw_writesw(void __iomem *addr, const void *data, int wordlen);
  40. extern void __raw_readsl(const void __iomem *addr, void *data, int wordlen);
  41. extern void __raw_writesl(void __iomem *addr, const void *data, int wordlen);
  42. #define readsw(p, d, l) __raw_readsw(p, d, l)
  43. #define writesw(p, d, l) __raw_writesw(p, d, l)
  44. #define readsl(p, d, l) __raw_readsl(p, d, l)
  45. #define writesl(p, d, l) __raw_writesl(p, d, l)
  46. /*
  47. * virt_to_phys - map virtual address to physical
  48. * @address: address to map
  49. */
  50. static inline unsigned long virt_to_phys(volatile void *address)
  51. {
  52. return __pa(address);
  53. }
  54. /*
  55. * phys_to_virt - map physical address to virtual
  56. * @address: address to map
  57. */
  58. static inline void *phys_to_virt(unsigned long address)
  59. {
  60. return __va(address);
  61. }
  62. /*
  63. * convert a physical pointer to a virtual kernel pointer for
  64. * /dev/mem access.
  65. */
  66. #define xlate_dev_kmem_ptr(p) __va(p)
  67. #define xlate_dev_mem_ptr(p) __va(p)
  68. /*
  69. * IO port access primitives. Hexagon doesn't have special IO access
  70. * instructions; all I/O is memory mapped.
  71. *
  72. * in/out are used for "ports", but we don't have "port instructions",
  73. * so these are really just memory mapped too.
  74. */
  75. /*
  76. * readb - read byte from memory mapped device
  77. * @addr: pointer to memory
  78. *
  79. * Operates on "I/O bus memory space"
  80. */
  81. static inline u8 readb(const volatile void __iomem *addr)
  82. {
  83. u8 val;
  84. asm volatile(
  85. "%0 = memb(%1);"
  86. : "=&r" (val)
  87. : "r" (addr)
  88. );
  89. return val;
  90. }
  91. static inline u16 readw(const volatile void __iomem *addr)
  92. {
  93. u16 val;
  94. asm volatile(
  95. "%0 = memh(%1);"
  96. : "=&r" (val)
  97. : "r" (addr)
  98. );
  99. return val;
  100. }
  101. static inline u32 readl(const volatile void __iomem *addr)
  102. {
  103. u32 val;
  104. asm volatile(
  105. "%0 = memw(%1);"
  106. : "=&r" (val)
  107. : "r" (addr)
  108. );
  109. return val;
  110. }
  111. /*
  112. * writeb - write a byte to a memory location
  113. * @data: data to write to
  114. * @addr: pointer to memory
  115. *
  116. */
  117. static inline void writeb(u8 data, volatile void __iomem *addr)
  118. {
  119. asm volatile(
  120. "memb(%0) = %1;"
  121. :
  122. : "r" (addr), "r" (data)
  123. : "memory"
  124. );
  125. }
  126. static inline void writew(u16 data, volatile void __iomem *addr)
  127. {
  128. asm volatile(
  129. "memh(%0) = %1;"
  130. :
  131. : "r" (addr), "r" (data)
  132. : "memory"
  133. );
  134. }
  135. static inline void writel(u32 data, volatile void __iomem *addr)
  136. {
  137. asm volatile(
  138. "memw(%0) = %1;"
  139. :
  140. : "r" (addr), "r" (data)
  141. : "memory"
  142. );
  143. }
  144. #define __raw_writeb writeb
  145. #define __raw_writew writew
  146. #define __raw_writel writel
  147. #define __raw_readb readb
  148. #define __raw_readw readw
  149. #define __raw_readl readl
  150. /*
  151. * http://comments.gmane.org/gmane.linux.ports.arm.kernel/117626
  152. */
  153. #define readb_relaxed __raw_readb
  154. #define readw_relaxed __raw_readw
  155. #define readl_relaxed __raw_readl
  156. #define writeb_relaxed __raw_writeb
  157. #define writew_relaxed __raw_writew
  158. #define writel_relaxed __raw_writel
  159. #define mmiowb()
  160. /*
  161. * Need an mtype somewhere in here, for cache type deals?
  162. * This is probably too long for an inline.
  163. */
  164. void __iomem *ioremap_nocache(unsigned long phys_addr, unsigned long size);
  165. static inline void __iomem *ioremap(unsigned long phys_addr, unsigned long size)
  166. {
  167. return ioremap_nocache(phys_addr, size);
  168. }
  169. static inline void iounmap(volatile void __iomem *addr)
  170. {
  171. __iounmap(addr);
  172. }
  173. #define __raw_writel writel
  174. static inline void memcpy_fromio(void *dst, const volatile void __iomem *src,
  175. int count)
  176. {
  177. memcpy(dst, (void *) src, count);
  178. }
  179. static inline void memcpy_toio(volatile void __iomem *dst, const void *src,
  180. int count)
  181. {
  182. memcpy((void *) dst, src, count);
  183. }
  184. #define PCI_IO_ADDR (volatile void __iomem *)
  185. /*
  186. * inb - read byte from I/O port or something
  187. * @port: address in I/O space
  188. *
  189. * Operates on "I/O bus I/O space"
  190. */
  191. static inline u8 inb(unsigned long port)
  192. {
  193. return readb(_IO_BASE + (port & IO_SPACE_LIMIT));
  194. }
  195. static inline u16 inw(unsigned long port)
  196. {
  197. return readw(_IO_BASE + (port & IO_SPACE_LIMIT));
  198. }
  199. static inline u32 inl(unsigned long port)
  200. {
  201. return readl(_IO_BASE + (port & IO_SPACE_LIMIT));
  202. }
  203. /*
  204. * outb - write a byte to a memory location
  205. * @data: data to write to
  206. * @addr: address in I/O space
  207. */
  208. static inline void outb(u8 data, unsigned long port)
  209. {
  210. writeb(data, _IO_BASE + (port & IO_SPACE_LIMIT));
  211. }
  212. static inline void outw(u16 data, unsigned long port)
  213. {
  214. writew(data, _IO_BASE + (port & IO_SPACE_LIMIT));
  215. }
  216. static inline void outl(u32 data, unsigned long port)
  217. {
  218. writel(data, _IO_BASE + (port & IO_SPACE_LIMIT));
  219. }
  220. #define outb_p outb
  221. #define outw_p outw
  222. #define outl_p outl
  223. #define inb_p inb
  224. #define inw_p inw
  225. #define inl_p inl
  226. static inline void insb(unsigned long port, void *buffer, int count)
  227. {
  228. if (count) {
  229. u8 *buf = buffer;
  230. do {
  231. u8 x = inb(port);
  232. *buf++ = x;
  233. } while (--count);
  234. }
  235. }
  236. static inline void insw(unsigned long port, void *buffer, int count)
  237. {
  238. if (count) {
  239. u16 *buf = buffer;
  240. do {
  241. u16 x = inw(port);
  242. *buf++ = x;
  243. } while (--count);
  244. }
  245. }
  246. static inline void insl(unsigned long port, void *buffer, int count)
  247. {
  248. if (count) {
  249. u32 *buf = buffer;
  250. do {
  251. u32 x = inw(port);
  252. *buf++ = x;
  253. } while (--count);
  254. }
  255. }
  256. static inline void outsb(unsigned long port, const void *buffer, int count)
  257. {
  258. if (count) {
  259. const u8 *buf = buffer;
  260. do {
  261. outb(*buf++, port);
  262. } while (--count);
  263. }
  264. }
  265. static inline void outsw(unsigned long port, const void *buffer, int count)
  266. {
  267. if (count) {
  268. const u16 *buf = buffer;
  269. do {
  270. outw(*buf++, port);
  271. } while (--count);
  272. }
  273. }
  274. static inline void outsl(unsigned long port, const void *buffer, int count)
  275. {
  276. if (count) {
  277. const u32 *buf = buffer;
  278. do {
  279. outl(*buf++, port);
  280. } while (--count);
  281. }
  282. }
  283. #define flush_write_buffers() do { } while (0)
  284. #endif /* __KERNEL__ */
  285. #endif