io.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. /*
  2. * arch/arm/include/asm/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. * 05-Oct-2004 BJD Moved memory string functions to use void __iomem
  20. */
  21. #ifndef __ASM_ARM_IO_H
  22. #define __ASM_ARM_IO_H
  23. #ifdef __KERNEL__
  24. #include <linux/types.h>
  25. #include <asm/byteorder.h>
  26. #include <asm/memory.h>
  27. #include <asm-generic/pci_iomap.h>
  28. #include <mach/msm_rtb.h>
  29. /*
  30. * ISA I/O bus memory addresses are 1:1 with the physical address.
  31. */
  32. #define isa_virt_to_bus virt_to_phys
  33. #define isa_page_to_bus page_to_phys
  34. #define isa_bus_to_virt phys_to_virt
  35. /*
  36. * Generic IO read/write. These perform native-endian accesses. Note
  37. * that some architectures will want to re-define __raw_{read,write}w.
  38. */
  39. extern void __raw_writesb(void __iomem *addr, const void *data, int bytelen);
  40. extern void __raw_writesw(void __iomem *addr, const void *data, int wordlen);
  41. extern void __raw_writesl(void __iomem *addr, const void *data, int longlen);
  42. extern void __raw_readsb(const void __iomem *addr, void *data, int bytelen);
  43. extern void __raw_readsw(const void __iomem *addr, void *data, int wordlen);
  44. extern void __raw_readsl(const void __iomem *addr, void *data, int longlen);
  45. /*
  46. * There may be cases when clients don't want to support or can't support the
  47. * logging. The appropriate functions can be used but clients should carefully
  48. * consider why they can't support the logging.
  49. */
  50. #define __raw_write_logged(v, a, _t) ({ \
  51. int _ret; \
  52. void *_addr = (void *)(a); \
  53. _ret = uncached_logk(LOGK_WRITEL, _addr); \
  54. ETB_WAYPOINT; \
  55. __raw_write##_t##_no_log((v), _addr); \
  56. if (_ret) \
  57. LOG_BARRIER; \
  58. })
  59. #define __raw_writeb_no_log(v, a) (__chk_io_ptr(a), *(volatile unsigned char __force *)(a) = (v))
  60. #define __raw_writew_no_log(v, a) (__chk_io_ptr(a), *(volatile unsigned short __force *)(a) = (v))
  61. #define __raw_writel_no_log(v, a) (__chk_io_ptr(a), *(volatile unsigned int __force *)(a) = (v))
  62. #define __raw_writell_no_log(v, a) (__chk_io_ptr(a), *(volatile unsigned long long __force *)(a) = (v))
  63. #define __raw_writeb(v, a) __raw_write_logged((v), (a), b)
  64. #define __raw_writew(v, a) __raw_write_logged((v), (a), w)
  65. #define __raw_writel(v, a) __raw_write_logged((v), (a), l)
  66. #define __raw_writell(v, a) __raw_write_logged((v), (a), ll)
  67. #define __raw_readb_no_log(a) (__chk_io_ptr(a), *(volatile unsigned char __force *)(a))
  68. #define __raw_readw_no_log(a) (__chk_io_ptr(a), *(volatile unsigned short __force *)(a))
  69. #define __raw_readl_no_log(a) (__chk_io_ptr(a), *(volatile unsigned int __force *)(a))
  70. #define __raw_readll_no_log(a) (__chk_io_ptr(a), *(volatile unsigned long long __force *)(a))
  71. #define __raw_read_logged(a, _l, _t) ({ \
  72. unsigned _t __a; \
  73. void *_addr = (void *)(a); \
  74. int _ret; \
  75. _ret = uncached_logk(LOGK_READL, _addr); \
  76. ETB_WAYPOINT; \
  77. __a = __raw_read##_l##_no_log(_addr);\
  78. if (_ret) \
  79. LOG_BARRIER; \
  80. __a; \
  81. })
  82. #define __raw_readb(a) __raw_read_logged((a), b, char)
  83. #define __raw_readw(a) __raw_read_logged((a), w, short)
  84. #define __raw_readl(a) __raw_read_logged((a), l, int)
  85. #define __raw_readll(a) __raw_read_logged((a), ll, long long)
  86. /*
  87. * Architecture ioremap implementation.
  88. */
  89. #define MT_DEVICE 0
  90. #define MT_DEVICE_NONSHARED 1
  91. #define MT_DEVICE_CACHED 2
  92. #define MT_DEVICE_WC 3
  93. /*
  94. * types 4 onwards can be found in asm/mach/map.h and are undefined
  95. * for ioremap
  96. */
  97. /*
  98. * __arm_ioremap takes CPU physical address.
  99. * __arm_ioremap_pfn takes a Page Frame Number and an offset into that page
  100. * The _caller variety takes a __builtin_return_address(0) value for
  101. * /proc/vmalloc to use - and should only be used in non-inline functions.
  102. */
  103. extern void __iomem *__arm_ioremap_pfn_caller(unsigned long, unsigned long,
  104. size_t, unsigned int, void *);
  105. extern void __iomem *__arm_ioremap_caller(phys_addr_t, size_t, unsigned int,
  106. void *);
  107. extern void __iomem *__arm_ioremap_pfn(unsigned long, unsigned long, size_t, unsigned int);
  108. extern void __iomem *__arm_ioremap(phys_addr_t, size_t, unsigned int);
  109. extern void __iomem *__arm_ioremap_exec(phys_addr_t, size_t, bool cached);
  110. extern void __iounmap(volatile void __iomem *addr);
  111. extern void __arm_iounmap(volatile void __iomem *addr);
  112. extern void __iomem * (*arch_ioremap_caller)(phys_addr_t, size_t,
  113. unsigned int, void *);
  114. extern void (*arch_iounmap)(volatile void __iomem *);
  115. /*
  116. * Bad read/write accesses...
  117. */
  118. extern void __readwrite_bug(const char *fn);
  119. /*
  120. * A typesafe __io() helper
  121. */
  122. static inline void __iomem *__typesafe_io(unsigned long addr)
  123. {
  124. return (void __iomem *)addr;
  125. }
  126. #define IOMEM(x) ((void __force __iomem *)(x))
  127. /* IO barriers */
  128. #ifdef CONFIG_ARM_DMA_MEM_BUFFERABLE
  129. #include <asm/barrier.h>
  130. #define __iormb() rmb()
  131. #define __iowmb() wmb()
  132. #else
  133. #define __iormb() do { } while (0)
  134. #define __iowmb() do { } while (0)
  135. #endif
  136. /*
  137. * Now, pick up the machine-defined IO definitions
  138. */
  139. #ifdef CONFIG_NEED_MACH_IO_H
  140. #include <mach/io.h>
  141. #else
  142. #define __io(a) __typesafe_io((a) & IO_SPACE_LIMIT)
  143. #endif
  144. /*
  145. * This is the limit of PC card/PCI/ISA IO space, which is by default
  146. * 64K if we have PC card, PCI or ISA support. Otherwise, default to
  147. * zero to prevent ISA/PCI drivers claiming IO space (and potentially
  148. * oopsing.)
  149. *
  150. * Only set this larger if you really need inb() et.al. to operate over
  151. * a larger address space. Note that SOC_COMMON ioremaps each sockets
  152. * IO space area, and so inb() et.al. must be defined to operate as per
  153. * readb() et.al. on such platforms.
  154. */
  155. #ifndef IO_SPACE_LIMIT
  156. #if defined(CONFIG_PCMCIA_SOC_COMMON) || defined(CONFIG_PCMCIA_SOC_COMMON_MODULE)
  157. #define IO_SPACE_LIMIT ((resource_size_t)0xffffffff)
  158. #elif defined(CONFIG_PCI) || defined(CONFIG_ISA) || defined(CONFIG_PCCARD)
  159. #define IO_SPACE_LIMIT ((resource_size_t)0xffff)
  160. #else
  161. #define IO_SPACE_LIMIT ((resource_size_t)0)
  162. #endif
  163. #endif
  164. /*
  165. * IO port access primitives
  166. * -------------------------
  167. *
  168. * The ARM doesn't have special IO access instructions; all IO is memory
  169. * mapped. Note that these are defined to perform little endian accesses
  170. * only. Their primary purpose is to access PCI and ISA peripherals.
  171. *
  172. * Note that for a big endian machine, this implies that the following
  173. * big endian mode connectivity is in place, as described by numerous
  174. * ARM documents:
  175. *
  176. * PCI: D0-D7 D8-D15 D16-D23 D24-D31
  177. * ARM: D24-D31 D16-D23 D8-D15 D0-D7
  178. *
  179. * The machine specific io.h include defines __io to translate an "IO"
  180. * address to a memory address.
  181. *
  182. * Note that we prevent GCC re-ordering or caching values in expressions
  183. * by introducing sequence points into the in*() definitions. Note that
  184. * __raw_* do not guarantee this behaviour.
  185. *
  186. * The {in,out}[bwl] macros are for emulating x86-style PCI/ISA IO space.
  187. */
  188. #ifdef __io
  189. #define outb(v,p) ({ __iowmb(); __raw_writeb(v,__io(p)); })
  190. #define outw(v,p) ({ __iowmb(); __raw_writew((__force __u16) \
  191. cpu_to_le16(v),__io(p)); })
  192. #define outl(v,p) ({ __iowmb(); __raw_writel((__force __u32) \
  193. cpu_to_le32(v),__io(p)); })
  194. #define inb(p) ({ __u8 __v = __raw_readb(__io(p)); __iormb(); __v; })
  195. #define inw(p) ({ __u16 __v = le16_to_cpu((__force __le16) \
  196. __raw_readw(__io(p))); __iormb(); __v; })
  197. #define inl(p) ({ __u32 __v = le32_to_cpu((__force __le32) \
  198. __raw_readl(__io(p))); __iormb(); __v; })
  199. #define outsb(p,d,l) __raw_writesb(__io(p),d,l)
  200. #define outsw(p,d,l) __raw_writesw(__io(p),d,l)
  201. #define outsl(p,d,l) __raw_writesl(__io(p),d,l)
  202. #define insb(p,d,l) __raw_readsb(__io(p),d,l)
  203. #define insw(p,d,l) __raw_readsw(__io(p),d,l)
  204. #define insl(p,d,l) __raw_readsl(__io(p),d,l)
  205. #endif
  206. #define outb_p(val,port) outb((val),(port))
  207. #define outw_p(val,port) outw((val),(port))
  208. #define outl_p(val,port) outl((val),(port))
  209. #define inb_p(port) inb((port))
  210. #define inw_p(port) inw((port))
  211. #define inl_p(port) inl((port))
  212. #define outsb_p(port,from,len) outsb(port,from,len)
  213. #define outsw_p(port,from,len) outsw(port,from,len)
  214. #define outsl_p(port,from,len) outsl(port,from,len)
  215. #define insb_p(port,to,len) insb(port,to,len)
  216. #define insw_p(port,to,len) insw(port,to,len)
  217. #define insl_p(port,to,len) insl(port,to,len)
  218. /*
  219. * String version of IO memory access ops:
  220. */
  221. extern void _memcpy_fromio(void *, const volatile void __iomem *, size_t);
  222. extern void _memcpy_toio(volatile void __iomem *, const void *, size_t);
  223. extern void _memset_io(volatile void __iomem *, int, size_t);
  224. #define mmiowb()
  225. /*
  226. * Memory access primitives
  227. * ------------------------
  228. *
  229. * These perform PCI memory accesses via an ioremap region. They don't
  230. * take an address as such, but a cookie.
  231. *
  232. * Again, this are defined to perform little endian accesses. See the
  233. * IO port primitives for more information.
  234. */
  235. #ifndef readl
  236. #define readb_relaxed(c) ({ u8 __r = __raw_readb(c); __r; })
  237. #define readw_relaxed(c) ({ u16 __r = le16_to_cpu((__force __le16) \
  238. __raw_readw(c)); __r; })
  239. #define readl_relaxed(c) ({ u32 __r = le32_to_cpu((__force __le32) \
  240. __raw_readl(c)); __r; })
  241. #define readll_relaxed(c) ({ u64 __r = le64_to_cpu((__force __le64) \
  242. __raw_readll(c)); __r; })
  243. #define readl_relaxed_no_log(c) ({ u32 __r = le32_to_cpu((__force __le32) \
  244. __raw_readl_no_log(c)); __r; })
  245. #define readll_relaxed_no_log(c) ({ u64 __r = le64_to_cpu((__force __le64) \
  246. __raw_readll_no_log(c)); __r; })
  247. #define writeb_relaxed(v,c) ((void)__raw_writeb(v,c))
  248. #define writew_relaxed(v,c) ((void)__raw_writew((__force u16) \
  249. cpu_to_le16(v),c))
  250. #define writel_relaxed(v,c) ((void)__raw_writel((__force u32) \
  251. cpu_to_le32(v),c))
  252. #define writell_relaxed(v, c) ((void)__raw_writell((__force u64) \
  253. cpu_to_le64(v), c))
  254. #define writel_relaxed_no_log(v, c) ((void)__raw_writel_no_log((__force u32) \
  255. cpu_to_le32(v), c))
  256. #define writell_relaxed_no_log(v, c) ((void)__raw_writell_no_log((__force u64) \
  257. cpu_to_le64(v), c))
  258. #define readb(c) ({ u8 __v = readb_relaxed(c); __iormb(); __v; })
  259. #define readw(c) ({ u16 __v = readw_relaxed(c); __iormb(); __v; })
  260. #define readl(c) ({ u32 __v = readl_relaxed(c); __iormb(); __v; })
  261. #define readll(c) ({ u64 __v = readll_relaxed(c); __iormb(); __v; })
  262. #define writeb(v,c) ({ __iowmb(); writeb_relaxed(v,c); })
  263. #define writew(v,c) ({ __iowmb(); writew_relaxed(v,c); })
  264. #define writel(v,c) ({ __iowmb(); writel_relaxed(v,c); })
  265. #define writell(v, c) ({ __iowmb(); writell_relaxed(v, c); })
  266. #define readsb(p,d,l) __raw_readsb(p,d,l)
  267. #define readsw(p,d,l) __raw_readsw(p,d,l)
  268. #define readsl(p,d,l) __raw_readsl(p,d,l)
  269. #define writesb(p,d,l) __raw_writesb(p,d,l)
  270. #define writesw(p,d,l) __raw_writesw(p,d,l)
  271. #define writesl(p,d,l) __raw_writesl(p,d,l)
  272. #define memset_io(c,v,l) _memset_io(c,(v),(l))
  273. #define memcpy_fromio(a,c,l) _memcpy_fromio((a),c,(l))
  274. #define memcpy_toio(c,a,l) _memcpy_toio(c,(a),(l))
  275. #endif /* readl */
  276. /*
  277. * ioremap and friends.
  278. *
  279. * ioremap takes a PCI memory address, as specified in
  280. * Documentation/io-mapping.txt.
  281. *
  282. */
  283. #define ioremap(cookie,size) __arm_ioremap((cookie), (size), MT_DEVICE)
  284. #define ioremap_nocache(cookie,size) __arm_ioremap((cookie), (size), MT_DEVICE)
  285. #define ioremap_cached(cookie,size) __arm_ioremap((cookie), (size), MT_DEVICE_CACHED)
  286. #define ioremap_wc(cookie,size) __arm_ioremap((cookie), (size), MT_DEVICE_WC)
  287. #define iounmap __arm_iounmap
  288. /*
  289. * io{read,write}{8,16,32,64} macros
  290. */
  291. #ifndef ioread8
  292. #define ioread8(p) ({ unsigned int __v = __raw_readb(p); __iormb(); __v; })
  293. #define ioread16(p) ({ unsigned int __v = le16_to_cpu((__force __le16)__raw_readw(p)); __iormb(); __v; })
  294. #define ioread32(p) ({ unsigned int __v = le32_to_cpu((__force __le32)__raw_readl(p)); __iormb(); __v; })
  295. #define ioread64(p) ({ unsigned int __v = le64_to_cpu((__force __le64)__raw_readll(p)); __iormb(); __v; })
  296. #define ioread16be(p) ({ unsigned int __v = be16_to_cpu((__force __be16)__raw_readw(p)); __iormb(); __v; })
  297. #define ioread32be(p) ({ unsigned int __v = be32_to_cpu((__force __be32)__raw_readl(p)); __iormb(); __v; })
  298. #define ioread64be(p) ({ unsigned int __v = be64_to_cpu((__force __be64)__raw_readll(p)); __iormb(); __v; })
  299. #define iowrite8(v,p) ({ __iowmb(); (void)__raw_writeb(v, p); })
  300. #define iowrite16(v,p) ({ __iowmb(); (void)__raw_writew((__force __u16)cpu_to_le16(v), p); })
  301. #define iowrite32(v,p) ({ __iowmb(); (void)__raw_writel((__force __u32)cpu_to_le32(v), p); })
  302. #define iowrite64(v, p) ({ __iowmb(); (void)__raw_writell((__force __u64)cpu_to_le64(v), p); })
  303. #define iowrite16be(v,p) ({ __iowmb(); (void)__raw_writew((__force __u16)cpu_to_be16(v), p); })
  304. #define iowrite32be(v,p) ({ __iowmb(); (void)__raw_writel((__force __u32)cpu_to_be32(v), p); })
  305. #define iowrite64be(v, p) ({ __iowmb(); (void)__raw_writell((__force __u64)cpu_to_be64(v), p); })
  306. #define ioread8_rep(p,d,c) __raw_readsb(p,d,c)
  307. #define ioread16_rep(p,d,c) __raw_readsw(p,d,c)
  308. #define ioread32_rep(p,d,c) __raw_readsl(p,d,c)
  309. #define iowrite8_rep(p,s,c) __raw_writesb(p,s,c)
  310. #define iowrite16_rep(p,s,c) __raw_writesw(p,s,c)
  311. #define iowrite32_rep(p,s,c) __raw_writesl(p,s,c)
  312. extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
  313. extern void ioport_unmap(void __iomem *addr);
  314. #endif
  315. struct pci_dev;
  316. extern void pci_iounmap(struct pci_dev *dev, void __iomem *addr);
  317. /*
  318. * can the hardware map this into one segment or not, given no other
  319. * constraints.
  320. */
  321. #define BIOVEC_MERGEABLE(vec1, vec2) \
  322. ((bvec_to_phys((vec1)) + (vec1)->bv_len) == bvec_to_phys((vec2)))
  323. #ifdef CONFIG_MMU
  324. #define ARCH_HAS_VALID_PHYS_ADDR_RANGE
  325. extern int valid_phys_addr_range(unsigned long addr, size_t size);
  326. extern int valid_mmap_phys_addr_range(unsigned long pfn, size_t size);
  327. extern int devmem_is_allowed(unsigned long pfn);
  328. #endif
  329. /*
  330. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  331. * access
  332. */
  333. #define xlate_dev_mem_ptr(p) __va(p)
  334. /*
  335. * Convert a virtual cached pointer to an uncached pointer
  336. */
  337. #define xlate_dev_kmem_ptr(p) p
  338. /*
  339. * Register ISA memory and port locations for glibc iopl/inb/outb
  340. * emulation.
  341. */
  342. extern void register_isa_ports(unsigned int mmio, unsigned int io,
  343. unsigned int io_shift);
  344. #endif /* __KERNEL__ */
  345. #endif /* __ASM_ARM_IO_H */