io.h 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. /*
  2. * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
  3. * Copyright (C) 2007-2009 PetaLogix
  4. * Copyright (C) 2006 Atmark Techno, Inc.
  5. *
  6. * This file is subject to the terms and conditions of the GNU General Public
  7. * License. See the file "COPYING" in the main directory of this archive
  8. * for more details.
  9. */
  10. #ifndef _ASM_MICROBLAZE_IO_H
  11. #define _ASM_MICROBLAZE_IO_H
  12. #include <asm/byteorder.h>
  13. #include <asm/page.h>
  14. #include <linux/types.h>
  15. #include <linux/mm.h> /* Get struct page {...} */
  16. #include <asm-generic/iomap.h>
  17. #ifndef CONFIG_PCI
  18. #define _IO_BASE 0
  19. #define _ISA_MEM_BASE 0
  20. #define PCI_DRAM_OFFSET 0
  21. #else
  22. #define _IO_BASE isa_io_base
  23. #define _ISA_MEM_BASE isa_mem_base
  24. #define PCI_DRAM_OFFSET pci_dram_offset
  25. #endif
  26. extern unsigned long isa_io_base;
  27. extern unsigned long pci_io_base;
  28. extern unsigned long pci_dram_offset;
  29. extern resource_size_t isa_mem_base;
  30. #define IO_SPACE_LIMIT (0xFFFFFFFF)
  31. /* the following is needed to support PCI with some drivers */
  32. #define mmiowb()
  33. static inline unsigned char __raw_readb(const volatile void __iomem *addr)
  34. {
  35. return *(volatile unsigned char __force *)addr;
  36. }
  37. static inline unsigned short __raw_readw(const volatile void __iomem *addr)
  38. {
  39. return *(volatile unsigned short __force *)addr;
  40. }
  41. static inline unsigned int __raw_readl(const volatile void __iomem *addr)
  42. {
  43. return *(volatile unsigned int __force *)addr;
  44. }
  45. static inline unsigned long __raw_readq(const volatile void __iomem *addr)
  46. {
  47. return *(volatile unsigned long __force *)addr;
  48. }
  49. static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr)
  50. {
  51. *(volatile unsigned char __force *)addr = v;
  52. }
  53. static inline void __raw_writew(unsigned short v, volatile void __iomem *addr)
  54. {
  55. *(volatile unsigned short __force *)addr = v;
  56. }
  57. static inline void __raw_writel(unsigned int v, volatile void __iomem *addr)
  58. {
  59. *(volatile unsigned int __force *)addr = v;
  60. }
  61. static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr)
  62. {
  63. *(volatile unsigned long __force *)addr = v;
  64. }
  65. /*
  66. * read (readb, readw, readl, readq) and write (writeb, writew,
  67. * writel, writeq) accessors are for PCI and thus little endian.
  68. * Linux 2.4 for Microblaze had this wrong.
  69. */
  70. static inline unsigned char readb(const volatile void __iomem *addr)
  71. {
  72. return *(volatile unsigned char __force *)addr;
  73. }
  74. static inline unsigned short readw(const volatile void __iomem *addr)
  75. {
  76. return le16_to_cpu(*(volatile unsigned short __force *)addr);
  77. }
  78. static inline unsigned int readl(const volatile void __iomem *addr)
  79. {
  80. return le32_to_cpu(*(volatile unsigned int __force *)addr);
  81. }
  82. static inline void writeb(unsigned char v, volatile void __iomem *addr)
  83. {
  84. *(volatile unsigned char __force *)addr = v;
  85. }
  86. static inline void writew(unsigned short v, volatile void __iomem *addr)
  87. {
  88. *(volatile unsigned short __force *)addr = cpu_to_le16(v);
  89. }
  90. static inline void writel(unsigned int v, volatile void __iomem *addr)
  91. {
  92. *(volatile unsigned int __force *)addr = cpu_to_le32(v);
  93. }
  94. /* ioread and iowrite variants. thease are for now same as __raw_
  95. * variants of accessors. we might check for endianess in the feature
  96. */
  97. #define ioread8(addr) __raw_readb((u8 *)(addr))
  98. #define ioread16(addr) __raw_readw((u16 *)(addr))
  99. #define ioread32(addr) __raw_readl((u32 *)(addr))
  100. #define iowrite8(v, addr) __raw_writeb((u8)(v), (u8 *)(addr))
  101. #define iowrite16(v, addr) __raw_writew((u16)(v), (u16 *)(addr))
  102. #define iowrite32(v, addr) __raw_writel((u32)(v), (u32 *)(addr))
  103. #define ioread16be(addr) __raw_readw((u16 *)(addr))
  104. #define ioread32be(addr) __raw_readl((u32 *)(addr))
  105. #define iowrite16be(v, addr) __raw_writew((u16)(v), (u16 *)(addr))
  106. #define iowrite32be(v, addr) __raw_writel((u32)(v), (u32 *)(addr))
  107. /* These are the definitions for the x86 IO instructions
  108. * inb/inw/inl/outb/outw/outl, the "string" versions
  109. * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions
  110. * inb_p/inw_p/...
  111. * The macros don't do byte-swapping.
  112. */
  113. #define inb(port) readb((u8 *)((port)))
  114. #define outb(val, port) writeb((val), (u8 *)((unsigned long)(port)))
  115. #define inw(port) readw((u16 *)((port)))
  116. #define outw(val, port) writew((val), (u16 *)((unsigned long)(port)))
  117. #define inl(port) readl((u32 *)((port)))
  118. #define outl(val, port) writel((val), (u32 *)((unsigned long)(port)))
  119. #define inb_p(port) inb((port))
  120. #define outb_p(val, port) outb((val), (port))
  121. #define inw_p(port) inw((port))
  122. #define outw_p(val, port) outw((val), (port))
  123. #define inl_p(port) inl((port))
  124. #define outl_p(val, port) outl((val), (port))
  125. #define memset_io(a, b, c) memset((void *)(a), (b), (c))
  126. #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
  127. #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
  128. #ifdef CONFIG_MMU
  129. #define phys_to_virt(addr) ((void *)__phys_to_virt(addr))
  130. #define virt_to_phys(addr) ((unsigned long)__virt_to_phys(addr))
  131. #define virt_to_bus(addr) ((unsigned long)__virt_to_phys(addr))
  132. #define page_to_bus(page) (page_to_phys(page))
  133. #define bus_to_virt(addr) (phys_to_virt(addr))
  134. extern void iounmap(void *addr);
  135. /*extern void *__ioremap(phys_addr_t address, unsigned long size,
  136. unsigned long flags);*/
  137. extern void __iomem *ioremap(phys_addr_t address, unsigned long size);
  138. #define ioremap_writethrough(addr, size) ioremap((addr), (size))
  139. #define ioremap_nocache(addr, size) ioremap((addr), (size))
  140. #define ioremap_fullcache(addr, size) ioremap((addr), (size))
  141. #else /* CONFIG_MMU */
  142. /**
  143. * virt_to_phys - map virtual addresses to physical
  144. * @address: address to remap
  145. *
  146. * The returned physical address is the physical (CPU) mapping for
  147. * the memory address given. It is only valid to use this function on
  148. * addresses directly mapped or allocated via kmalloc.
  149. *
  150. * This function does not give bus mappings for DMA transfers. In
  151. * almost all conceivable cases a device driver should not be using
  152. * this function
  153. */
  154. static inline unsigned long __iomem virt_to_phys(volatile void *address)
  155. {
  156. return __pa((unsigned long)address);
  157. }
  158. #define virt_to_bus virt_to_phys
  159. /**
  160. * phys_to_virt - map physical address to virtual
  161. * @address: address to remap
  162. *
  163. * The returned virtual address is a current CPU mapping for
  164. * the memory address given. It is only valid to use this function on
  165. * addresses that have a kernel mapping
  166. *
  167. * This function does not handle bus mappings for DMA transfers. In
  168. * almost all conceivable cases a device driver should not be using
  169. * this function
  170. */
  171. static inline void *phys_to_virt(unsigned long address)
  172. {
  173. return (void *)__va(address);
  174. }
  175. #define bus_to_virt(a) phys_to_virt(a)
  176. static inline void __iomem *__ioremap(phys_addr_t address, unsigned long size,
  177. unsigned long flags)
  178. {
  179. return (void *)address;
  180. }
  181. #define ioremap(physaddr, size) ((void __iomem *)(unsigned long)(physaddr))
  182. #define iounmap(addr) ((void)0)
  183. #define ioremap_nocache(physaddr, size) ioremap(physaddr, size)
  184. #endif /* CONFIG_MMU */
  185. /*
  186. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  187. * access
  188. */
  189. #define xlate_dev_mem_ptr(p) __va(p)
  190. /*
  191. * Convert a virtual cached pointer to an uncached pointer
  192. */
  193. #define xlate_dev_kmem_ptr(p) p
  194. /*
  195. * Big Endian
  196. */
  197. #define out_be32(a, v) __raw_writel((v), (void __iomem __force *)(a))
  198. #define out_be16(a, v) __raw_writew((v), (a))
  199. #define in_be32(a) __raw_readl((const void __iomem __force *)(a))
  200. #define in_be16(a) __raw_readw(a)
  201. #define writel_be(v, a) out_be32((__force unsigned *)a, v)
  202. #define readl_be(a) in_be32((__force unsigned *)a)
  203. /*
  204. * Little endian
  205. */
  206. #define out_le32(a, v) __raw_writel(__cpu_to_le32(v), (a))
  207. #define out_le16(a, v) __raw_writew(__cpu_to_le16(v), (a))
  208. #define in_le32(a) __le32_to_cpu(__raw_readl(a))
  209. #define in_le16(a) __le16_to_cpu(__raw_readw(a))
  210. /* Byte ops */
  211. #define out_8(a, v) __raw_writeb((v), (a))
  212. #define in_8(a) __raw_readb(a)
  213. #define mmiowb()
  214. #define ioport_map(port, nr) ((void __iomem *)(port))
  215. #define ioport_unmap(addr)
  216. /* from asm-generic/io.h */
  217. #ifndef insb
  218. static inline void insb(unsigned long addr, void *buffer, int count)
  219. {
  220. if (count) {
  221. u8 *buf = buffer;
  222. do {
  223. u8 x = inb(addr);
  224. *buf++ = x;
  225. } while (--count);
  226. }
  227. }
  228. #endif
  229. #ifndef insw
  230. static inline void insw(unsigned long addr, void *buffer, int count)
  231. {
  232. if (count) {
  233. u16 *buf = buffer;
  234. do {
  235. u16 x = inw(addr);
  236. *buf++ = x;
  237. } while (--count);
  238. }
  239. }
  240. #endif
  241. #ifndef insl
  242. static inline void insl(unsigned long addr, void *buffer, int count)
  243. {
  244. if (count) {
  245. u32 *buf = buffer;
  246. do {
  247. u32 x = inl(addr);
  248. *buf++ = x;
  249. } while (--count);
  250. }
  251. }
  252. #endif
  253. #ifndef outsb
  254. static inline void outsb(unsigned long addr, const void *buffer, int count)
  255. {
  256. if (count) {
  257. const u8 *buf = buffer;
  258. do {
  259. outb(*buf++, addr);
  260. } while (--count);
  261. }
  262. }
  263. #endif
  264. #ifndef outsw
  265. static inline void outsw(unsigned long addr, const void *buffer, int count)
  266. {
  267. if (count) {
  268. const u16 *buf = buffer;
  269. do {
  270. outw(*buf++, addr);
  271. } while (--count);
  272. }
  273. }
  274. #endif
  275. #ifndef outsl
  276. static inline void outsl(unsigned long addr, const void *buffer, int count)
  277. {
  278. if (count) {
  279. const u32 *buf = buffer;
  280. do {
  281. outl(*buf++, addr);
  282. } while (--count);
  283. }
  284. }
  285. #endif
  286. #define ioread8_rep(p, dst, count) \
  287. insb((unsigned long) (p), (dst), (count))
  288. #define ioread16_rep(p, dst, count) \
  289. insw((unsigned long) (p), (dst), (count))
  290. #define ioread32_rep(p, dst, count) \
  291. insl((unsigned long) (p), (dst), (count))
  292. #define iowrite8_rep(p, src, count) \
  293. outsb((unsigned long) (p), (src), (count))
  294. #define iowrite16_rep(p, src, count) \
  295. outsw((unsigned long) (p), (src), (count))
  296. #define iowrite32_rep(p, src, count) \
  297. outsl((unsigned long) (p), (src), (count))
  298. #endif /* _ASM_MICROBLAZE_IO_H */