io.h 6.6 KB

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