io.h 6.8 KB

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