io.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. /*
  2. * linux/include/asm-arm/io.h
  3. *
  4. * Copyright (C) 1996-2000 Russell King
  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 as
  8. * published by the Free Software Foundation.
  9. *
  10. * Modifications:
  11. * 16-Sep-1996 RMK Inlined the inx/outx functions & optimised for both
  12. * constant addresses and variable addresses.
  13. * 04-Dec-1997 RMK Moved a lot of this stuff to the new architecture
  14. * specific IO header files.
  15. * 27-Mar-1999 PJB Second parameter of memcpy_toio is const..
  16. * 04-Apr-1999 PJB Added check_signature.
  17. * 12-Dec-1999 RMK More cleanups
  18. * 18-Jun-2000 RMK Removed virt_to_* and friends definitions
  19. */
  20. #ifndef __ASM_ARM_IO_H
  21. #define __ASM_ARM_IO_H
  22. #ifdef __KERNEL__
  23. #include <linux/types.h>
  24. #include <asm/byteorder.h>
  25. #include <asm/memory.h>
  26. #include <asm/barriers.h>
  27. #if 0 /* XXX###XXX */
  28. #include <asm/arch/hardware.h>
  29. #endif /* XXX###XXX */
  30. static inline void sync(void)
  31. {
  32. }
  33. /*
  34. * Generic virtual read/write. Note that we don't support half-word
  35. * read/writes. We define __arch_*[bl] here, and leave __arch_*w
  36. * to the architecture specific code.
  37. */
  38. #define __arch_getb(a) (*(volatile unsigned char *)(a))
  39. #define __arch_getw(a) (*(volatile unsigned short *)(a))
  40. #define __arch_getl(a) (*(volatile unsigned int *)(a))
  41. #define __arch_getq(a) (*(volatile unsigned long long *)(a))
  42. #define __arch_putb(v,a) (*(volatile unsigned char *)(a) = (v))
  43. #define __arch_putw(v,a) (*(volatile unsigned short *)(a) = (v))
  44. #define __arch_putl(v,a) (*(volatile unsigned int *)(a) = (v))
  45. #define __arch_putq(v,a) (*(volatile unsigned long long *)(a) = (v))
  46. static inline void __raw_writesb(unsigned long addr, const void *data,
  47. int bytelen)
  48. {
  49. uint8_t *buf = (uint8_t *)data;
  50. while(bytelen--)
  51. __arch_putb(*buf++, addr);
  52. }
  53. static inline void __raw_writesw(unsigned long addr, const void *data,
  54. int wordlen)
  55. {
  56. uint16_t *buf = (uint16_t *)data;
  57. while(wordlen--)
  58. __arch_putw(*buf++, addr);
  59. }
  60. static inline void __raw_writesl(unsigned long addr, const void *data,
  61. int longlen)
  62. {
  63. uint32_t *buf = (uint32_t *)data;
  64. while(longlen--)
  65. __arch_putl(*buf++, addr);
  66. }
  67. static inline void __raw_readsb(unsigned long addr, void *data, int bytelen)
  68. {
  69. uint8_t *buf = (uint8_t *)data;
  70. while(bytelen--)
  71. *buf++ = __arch_getb(addr);
  72. }
  73. static inline void __raw_readsw(unsigned long addr, void *data, int wordlen)
  74. {
  75. uint16_t *buf = (uint16_t *)data;
  76. while(wordlen--)
  77. *buf++ = __arch_getw(addr);
  78. }
  79. static inline void __raw_readsl(unsigned long addr, void *data, int longlen)
  80. {
  81. uint32_t *buf = (uint32_t *)data;
  82. while(longlen--)
  83. *buf++ = __arch_getl(addr);
  84. }
  85. #define __raw_writeb(v,a) __arch_putb(v,a)
  86. #define __raw_writew(v,a) __arch_putw(v,a)
  87. #define __raw_writel(v,a) __arch_putl(v,a)
  88. #define __raw_writeq(v,a) __arch_putq(v,a)
  89. #define __raw_readb(a) __arch_getb(a)
  90. #define __raw_readw(a) __arch_getw(a)
  91. #define __raw_readl(a) __arch_getl(a)
  92. #define __raw_readq(a) __arch_getq(a)
  93. /*
  94. * TODO: The kernel offers some more advanced versions of barriers, it might
  95. * have some advantages to use them instead of the simple one here.
  96. */
  97. #define mb() dsb()
  98. #define __iormb() dmb()
  99. #define __iowmb() dmb()
  100. #define writeb(v,c) ({ u8 __v = v; __iowmb(); __arch_putb(__v,c); __v; })
  101. #define writew(v,c) ({ u16 __v = v; __iowmb(); __arch_putw(__v,c); __v; })
  102. #define writel(v,c) ({ u32 __v = v; __iowmb(); __arch_putl(__v,c); __v; })
  103. #define writeq(v,c) ({ u64 __v = v; __iowmb(); __arch_putq(__v,c); __v; })
  104. #define readb(c) ({ u8 __v = __arch_getb(c); __iormb(); __v; })
  105. #define readw(c) ({ u16 __v = __arch_getw(c); __iormb(); __v; })
  106. #define readl(c) ({ u32 __v = __arch_getl(c); __iormb(); __v; })
  107. #define readq(c) ({ u64 __v = __arch_getq(c); __iormb(); __v; })
  108. /*
  109. * The compiler seems to be incapable of optimising constants
  110. * properly. Spell it out to the compiler in some cases.
  111. * These are only valid for small values of "off" (< 1<<12)
  112. */
  113. #define __raw_base_writeb(val,base,off) __arch_base_putb(val,base,off)
  114. #define __raw_base_writew(val,base,off) __arch_base_putw(val,base,off)
  115. #define __raw_base_writel(val,base,off) __arch_base_putl(val,base,off)
  116. #define __raw_base_readb(base,off) __arch_base_getb(base,off)
  117. #define __raw_base_readw(base,off) __arch_base_getw(base,off)
  118. #define __raw_base_readl(base,off) __arch_base_getl(base,off)
  119. /*
  120. * Clear and set bits in one shot. These macros can be used to clear and
  121. * set multiple bits in a register using a single call. These macros can
  122. * also be used to set a multiple-bit bit pattern using a mask, by
  123. * specifying the mask in the 'clear' parameter and the new bit pattern
  124. * in the 'set' parameter.
  125. */
  126. #define out_arch(type,endian,a,v) __raw_write##type(cpu_to_##endian(v),a)
  127. #define in_arch(type,endian,a) endian##_to_cpu(__raw_read##type(a))
  128. #define out_le64(a,v) out_arch(q,le64,a,v)
  129. #define out_le32(a,v) out_arch(l,le32,a,v)
  130. #define out_le16(a,v) out_arch(w,le16,a,v)
  131. #define in_le64(a) in_arch(q,le64,a)
  132. #define in_le32(a) in_arch(l,le32,a)
  133. #define in_le16(a) in_arch(w,le16,a)
  134. #define out_be32(a,v) out_arch(l,be32,a,v)
  135. #define out_be16(a,v) out_arch(w,be16,a,v)
  136. #define in_be32(a) in_arch(l,be32,a)
  137. #define in_be16(a) in_arch(w,be16,a)
  138. #define out_8(a,v) __raw_writeb(v,a)
  139. #define in_8(a) __raw_readb(a)
  140. #define clrbits(type, addr, clear) \
  141. out_##type((addr), in_##type(addr) & ~(clear))
  142. #define setbits(type, addr, set) \
  143. out_##type((addr), in_##type(addr) | (set))
  144. #define clrsetbits(type, addr, clear, set) \
  145. out_##type((addr), (in_##type(addr) & ~(clear)) | (set))
  146. #define clrbits_be32(addr, clear) clrbits(be32, addr, clear)
  147. #define setbits_be32(addr, set) setbits(be32, addr, set)
  148. #define clrsetbits_be32(addr, clear, set) clrsetbits(be32, addr, clear, set)
  149. #define clrbits_le32(addr, clear) clrbits(le32, addr, clear)
  150. #define setbits_le32(addr, set) setbits(le32, addr, set)
  151. #define clrsetbits_le32(addr, clear, set) clrsetbits(le32, addr, clear, set)
  152. #define clrbits_be16(addr, clear) clrbits(be16, addr, clear)
  153. #define setbits_be16(addr, set) setbits(be16, addr, set)
  154. #define clrsetbits_be16(addr, clear, set) clrsetbits(be16, addr, clear, set)
  155. #define clrbits_le16(addr, clear) clrbits(le16, addr, clear)
  156. #define setbits_le16(addr, set) setbits(le16, addr, set)
  157. #define clrsetbits_le16(addr, clear, set) clrsetbits(le16, addr, clear, set)
  158. #define clrbits_8(addr, clear) clrbits(8, addr, clear)
  159. #define setbits_8(addr, set) setbits(8, addr, set)
  160. #define clrsetbits_8(addr, clear, set) clrsetbits(8, addr, clear, set)
  161. /*
  162. * Now, pick up the machine-defined IO definitions
  163. */
  164. #if 0 /* XXX###XXX */
  165. #include <asm/arch/io.h>
  166. #endif /* XXX###XXX */
  167. /*
  168. * IO port access primitives
  169. * -------------------------
  170. *
  171. * The ARM doesn't have special IO access instructions; all IO is memory
  172. * mapped. Note that these are defined to perform little endian accesses
  173. * only. Their primary purpose is to access PCI and ISA peripherals.
  174. *
  175. * Note that for a big endian machine, this implies that the following
  176. * big endian mode connectivity is in place, as described by numerous
  177. * ARM documents:
  178. *
  179. * PCI: D0-D7 D8-D15 D16-D23 D24-D31
  180. * ARM: D24-D31 D16-D23 D8-D15 D0-D7
  181. *
  182. * The machine specific io.h include defines __io to translate an "IO"
  183. * address to a memory address.
  184. *
  185. * Note that we prevent GCC re-ordering or caching values in expressions
  186. * by introducing sequence points into the in*() definitions. Note that
  187. * __raw_* do not guarantee this behaviour.
  188. *
  189. * The {in,out}[bwl] macros are for emulating x86-style PCI/ISA IO space.
  190. */
  191. #ifdef __io
  192. #define outb(v,p) __raw_writeb(v,__io(p))
  193. #define outw(v,p) __raw_writew(cpu_to_le16(v),__io(p))
  194. #define outl(v,p) __raw_writel(cpu_to_le32(v),__io(p))
  195. #define inb(p) ({ unsigned int __v = __raw_readb(__io(p)); __v; })
  196. #define inw(p) ({ unsigned int __v = le16_to_cpu(__raw_readw(__io(p))); __v; })
  197. #define inl(p) ({ unsigned int __v = le32_to_cpu(__raw_readl(__io(p))); __v; })
  198. #define outsb(p,d,l) __raw_writesb(__io(p),d,l)
  199. #define outsw(p,d,l) __raw_writesw(__io(p),d,l)
  200. #define outsl(p,d,l) __raw_writesl(__io(p),d,l)
  201. #define insb(p,d,l) __raw_readsb(__io(p),d,l)
  202. #define insw(p,d,l) __raw_readsw(__io(p),d,l)
  203. #define insl(p,d,l) __raw_readsl(__io(p),d,l)
  204. #endif
  205. #define outb_p(val,port) outb((val),(port))
  206. #define outw_p(val,port) outw((val),(port))
  207. #define outl_p(val,port) outl((val),(port))
  208. #define inb_p(port) inb((port))
  209. #define inw_p(port) inw((port))
  210. #define inl_p(port) inl((port))
  211. #define outsb_p(port,from,len) outsb(port,from,len)
  212. #define outsw_p(port,from,len) outsw(port,from,len)
  213. #define outsl_p(port,from,len) outsl(port,from,len)
  214. #define insb_p(port,to,len) insb(port,to,len)
  215. #define insw_p(port,to,len) insw(port,to,len)
  216. #define insl_p(port,to,len) insl(port,to,len)
  217. #define writesl(a, d, s) __raw_writesl((unsigned long)a, d, s)
  218. #define readsl(a, d, s) __raw_readsl((unsigned long)a, d, s)
  219. #define writesw(a, d, s) __raw_writesw((unsigned long)a, d, s)
  220. #define readsw(a, d, s) __raw_readsw((unsigned long)a, d, s)
  221. #define writesb(a, d, s) __raw_writesb((unsigned long)a, d, s)
  222. #define readsb(a, d, s) __raw_readsb((unsigned long)a, d, s)
  223. /*
  224. * DMA-consistent mapping functions. These allocate/free a region of
  225. * uncached, unwrite-buffered mapped memory space for use with DMA
  226. * devices. This is the "generic" version. The PCI specific version
  227. * is in pci.h
  228. */
  229. extern void *consistent_alloc(int gfp, size_t size, dma_addr_t *handle);
  230. extern void consistent_free(void *vaddr, size_t size, dma_addr_t handle);
  231. extern void consistent_sync(void *vaddr, size_t size, int rw);
  232. /*
  233. * String version of IO memory access ops:
  234. */
  235. extern void _memcpy_fromio(void *, unsigned long, size_t);
  236. extern void _memcpy_toio(unsigned long, const void *, size_t);
  237. extern void _memset_io(unsigned long, int, size_t);
  238. extern void __readwrite_bug(const char *fn);
  239. /*
  240. * If this architecture has PCI memory IO, then define the read/write
  241. * macros. These should only be used with the cookie passed from
  242. * ioremap.
  243. */
  244. #ifdef __mem_pci
  245. #define readb(c) ({ unsigned int __v = __raw_readb(__mem_pci(c)); __v; })
  246. #define readw(c) ({ unsigned int __v = le16_to_cpu(__raw_readw(__mem_pci(c))); __v; })
  247. #define readl(c) ({ unsigned int __v = le32_to_cpu(__raw_readl(__mem_pci(c))); __v; })
  248. #define writeb(v,c) __raw_writeb(v,__mem_pci(c))
  249. #define writew(v,c) __raw_writew(cpu_to_le16(v),__mem_pci(c))
  250. #define writel(v,c) __raw_writel(cpu_to_le32(v),__mem_pci(c))
  251. #define memset_io(c,v,l) _memset_io(__mem_pci(c),(v),(l))
  252. #define memcpy_fromio(a,c,l) _memcpy_fromio((a),__mem_pci(c),(l))
  253. #define memcpy_toio(c,a,l) _memcpy_toio(__mem_pci(c),(a),(l))
  254. #define eth_io_copy_and_sum(s,c,l,b) \
  255. eth_copy_and_sum((s),__mem_pci(c),(l),(b))
  256. static inline int
  257. check_signature(unsigned long io_addr, const unsigned char *signature,
  258. int length)
  259. {
  260. int retval = 0;
  261. do {
  262. if (readb(io_addr) != *signature)
  263. goto out;
  264. io_addr++;
  265. signature++;
  266. length--;
  267. } while (length);
  268. retval = 1;
  269. out:
  270. return retval;
  271. }
  272. #else
  273. #define memset_io(a, b, c) memset((void *)(a), (b), (c))
  274. #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
  275. #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
  276. #if !defined(readb)
  277. #define readb(addr) (__readwrite_bug("readb"),0)
  278. #define readw(addr) (__readwrite_bug("readw"),0)
  279. #define readl(addr) (__readwrite_bug("readl"),0)
  280. #define writeb(v,addr) __readwrite_bug("writeb")
  281. #define writew(v,addr) __readwrite_bug("writew")
  282. #define writel(v,addr) __readwrite_bug("writel")
  283. #define eth_io_copy_and_sum(a,b,c,d) __readwrite_bug("eth_io_copy_and_sum")
  284. #define check_signature(io,sig,len) (0)
  285. #endif
  286. #endif /* __mem_pci */
  287. /*
  288. * If this architecture has ISA IO, then define the isa_read/isa_write
  289. * macros.
  290. */
  291. #ifdef __mem_isa
  292. #define isa_readb(addr) __raw_readb(__mem_isa(addr))
  293. #define isa_readw(addr) __raw_readw(__mem_isa(addr))
  294. #define isa_readl(addr) __raw_readl(__mem_isa(addr))
  295. #define isa_writeb(val,addr) __raw_writeb(val,__mem_isa(addr))
  296. #define isa_writew(val,addr) __raw_writew(val,__mem_isa(addr))
  297. #define isa_writel(val,addr) __raw_writel(val,__mem_isa(addr))
  298. #define isa_memset_io(a,b,c) _memset_io(__mem_isa(a),(b),(c))
  299. #define isa_memcpy_fromio(a,b,c) _memcpy_fromio((a),__mem_isa(b),(c))
  300. #define isa_memcpy_toio(a,b,c) _memcpy_toio(__mem_isa((a)),(b),(c))
  301. #define isa_eth_io_copy_and_sum(a,b,c,d) \
  302. eth_copy_and_sum((a),__mem_isa(b),(c),(d))
  303. static inline int
  304. isa_check_signature(unsigned long io_addr, const unsigned char *signature,
  305. int length)
  306. {
  307. int retval = 0;
  308. do {
  309. if (isa_readb(io_addr) != *signature)
  310. goto out;
  311. io_addr++;
  312. signature++;
  313. length--;
  314. } while (length);
  315. retval = 1;
  316. out:
  317. return retval;
  318. }
  319. #else /* __mem_isa */
  320. #define isa_readb(addr) (__readwrite_bug("isa_readb"),0)
  321. #define isa_readw(addr) (__readwrite_bug("isa_readw"),0)
  322. #define isa_readl(addr) (__readwrite_bug("isa_readl"),0)
  323. #define isa_writeb(val,addr) __readwrite_bug("isa_writeb")
  324. #define isa_writew(val,addr) __readwrite_bug("isa_writew")
  325. #define isa_writel(val,addr) __readwrite_bug("isa_writel")
  326. #define isa_memset_io(a,b,c) __readwrite_bug("isa_memset_io")
  327. #define isa_memcpy_fromio(a,b,c) __readwrite_bug("isa_memcpy_fromio")
  328. #define isa_memcpy_toio(a,b,c) __readwrite_bug("isa_memcpy_toio")
  329. #define isa_eth_io_copy_and_sum(a,b,c,d) \
  330. __readwrite_bug("isa_eth_io_copy_and_sum")
  331. #define isa_check_signature(io,sig,len) (0)
  332. #endif /* __mem_isa */
  333. #endif /* __KERNEL__ */
  334. #include <asm-generic/io.h>
  335. #include <iotrace.h>
  336. #endif /* __ASM_ARM_IO_H */