io.h 7.1 KB

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