io.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  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. #define IO_SPACE_LIMIT (0xFFFFFFFF)
  17. static inline unsigned char __raw_readb(const volatile void __iomem *addr)
  18. {
  19. return *(volatile unsigned char __force *)addr;
  20. }
  21. static inline unsigned short __raw_readw(const volatile void __iomem *addr)
  22. {
  23. return *(volatile unsigned short __force *)addr;
  24. }
  25. static inline unsigned int __raw_readl(const volatile void __iomem *addr)
  26. {
  27. return *(volatile unsigned int __force *)addr;
  28. }
  29. static inline unsigned long __raw_readq(const volatile void __iomem *addr)
  30. {
  31. return *(volatile unsigned long __force *)addr;
  32. }
  33. static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr)
  34. {
  35. *(volatile unsigned char __force *)addr = v;
  36. }
  37. static inline void __raw_writew(unsigned short v, volatile void __iomem *addr)
  38. {
  39. *(volatile unsigned short __force *)addr = v;
  40. }
  41. static inline void __raw_writel(unsigned int v, volatile void __iomem *addr)
  42. {
  43. *(volatile unsigned int __force *)addr = v;
  44. }
  45. static inline void __raw_writeq(unsigned long v, volatile void __iomem *addr)
  46. {
  47. *(volatile unsigned long __force *)addr = v;
  48. }
  49. /*
  50. * read (readb, readw, readl, readq) and write (writeb, writew,
  51. * writel, writeq) accessors are for PCI and thus littel endian.
  52. * Linux 2.4 for Microblaze had this wrong.
  53. */
  54. static inline unsigned char readb(const volatile void __iomem *addr)
  55. {
  56. return *(volatile unsigned char __force *)addr;
  57. }
  58. static inline unsigned short readw(const volatile void __iomem *addr)
  59. {
  60. return le16_to_cpu(*(volatile unsigned short __force *)addr);
  61. }
  62. static inline unsigned int readl(const volatile void __iomem *addr)
  63. {
  64. return le32_to_cpu(*(volatile unsigned int __force *)addr);
  65. }
  66. static inline void writeb(unsigned char v, volatile void __iomem *addr)
  67. {
  68. *(volatile unsigned char __force *)addr = v;
  69. }
  70. static inline void writew(unsigned short v, volatile void __iomem *addr)
  71. {
  72. *(volatile unsigned short __force *)addr = cpu_to_le16(v);
  73. }
  74. static inline void writel(unsigned int v, volatile void __iomem *addr)
  75. {
  76. *(volatile unsigned int __force *)addr = cpu_to_le32(v);
  77. }
  78. /* ioread and iowrite variants. thease are for now same as __raw_
  79. * variants of accessors. we might check for endianess in the feature
  80. */
  81. #define ioread8(addr) __raw_readb((u8 *)(addr))
  82. #define ioread16(addr) __raw_readw((u16 *)(addr))
  83. #define ioread32(addr) __raw_readl((u32 *)(addr))
  84. #define iowrite8(v, addr) __raw_writeb((u8)(v), (u8 *)(addr))
  85. #define iowrite16(v, addr) __raw_writew((u16)(v), (u16 *)(addr))
  86. #define iowrite32(v, addr) __raw_writel((u32)(v), (u32 *)(addr))
  87. /* These are the definitions for the x86 IO instructions
  88. * inb/inw/inl/outb/outw/outl, the "string" versions
  89. * insb/insw/insl/outsb/outsw/outsl, and the "pausing" versions
  90. * inb_p/inw_p/...
  91. * The macros don't do byte-swapping.
  92. */
  93. #define inb(port) readb((u8 *)((port)))
  94. #define outb(val, port) writeb((val), (u8 *)((unsigned long)(port)))
  95. #define inw(port) readw((u16 *)((port)))
  96. #define outw(val, port) writew((val), (u16 *)((unsigned long)(port)))
  97. #define inl(port) readl((u32 *)((port)))
  98. #define outl(val, port) writel((val), (u32 *)((unsigned long)(port)))
  99. #define inb_p(port) inb((port))
  100. #define outb_p(val, port) outb((val), (port))
  101. #define inw_p(port) inw((port))
  102. #define outw_p(val, port) outw((val), (port))
  103. #define inl_p(port) inl((port))
  104. #define outl_p(val, port) outl((val), (port))
  105. #define memset_io(a, b, c) memset((void *)(a), (b), (c))
  106. #define memcpy_fromio(a, b, c) memcpy((a), (void *)(b), (c))
  107. #define memcpy_toio(a, b, c) memcpy((void *)(a), (b), (c))
  108. #ifdef CONFIG_MMU
  109. #define mm_ptov(addr) ((void *)__phys_to_virt(addr))
  110. #define mm_vtop(addr) ((unsigned long)__virt_to_phys(addr))
  111. #define phys_to_virt(addr) ((void *)__phys_to_virt(addr))
  112. #define virt_to_phys(addr) ((unsigned long)__virt_to_phys(addr))
  113. #define virt_to_bus(addr) ((unsigned long)__virt_to_phys(addr))
  114. #define __page_address(page) \
  115. (PAGE_OFFSET + (((page) - mem_map) << PAGE_SHIFT))
  116. #define page_to_phys(page) virt_to_phys((void *)__page_address(page))
  117. #define page_to_bus(page) (page_to_phys(page))
  118. #define bus_to_virt(addr) (phys_to_virt(addr))
  119. extern void iounmap(void *addr);
  120. /*extern void *__ioremap(phys_addr_t address, unsigned long size,
  121. unsigned long flags);*/
  122. extern void __iomem *ioremap(phys_addr_t address, unsigned long size);
  123. #define ioremap_writethrough(addr, size) ioremap((addr), (size))
  124. #define ioremap_nocache(addr, size) ioremap((addr), (size))
  125. #define ioremap_fullcache(addr, size) ioremap((addr), (size))
  126. #else /* CONFIG_MMU */
  127. /**
  128. * virt_to_phys - map virtual addresses to physical
  129. * @address: address to remap
  130. *
  131. * The returned physical address is the physical (CPU) mapping for
  132. * the memory address given. It is only valid to use this function on
  133. * addresses directly mapped or allocated via kmalloc.
  134. *
  135. * This function does not give bus mappings for DMA transfers. In
  136. * almost all conceivable cases a device driver should not be using
  137. * this function
  138. */
  139. static inline unsigned long __iomem virt_to_phys(volatile void *address)
  140. {
  141. return __pa((unsigned long)address);
  142. }
  143. #define virt_to_bus virt_to_phys
  144. /**
  145. * phys_to_virt - map physical address to virtual
  146. * @address: address to remap
  147. *
  148. * The returned virtual address is a current CPU mapping for
  149. * the memory address given. It is only valid to use this function on
  150. * addresses that have a kernel mapping
  151. *
  152. * This function does not handle bus mappings for DMA transfers. In
  153. * almost all conceivable cases a device driver should not be using
  154. * this function
  155. */
  156. static inline void *phys_to_virt(unsigned long address)
  157. {
  158. return (void *)__va(address);
  159. }
  160. #define bus_to_virt(a) phys_to_virt(a)
  161. static inline void __iomem *__ioremap(phys_addr_t address, unsigned long size,
  162. unsigned long flags)
  163. {
  164. return (void *)address;
  165. }
  166. #define ioremap(physaddr, size) ((void __iomem *)(unsigned long)(physaddr))
  167. #define iounmap(addr) ((void)0)
  168. #define ioremap_nocache(physaddr, size) ioremap(physaddr, size)
  169. #endif /* CONFIG_MMU */
  170. /*
  171. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  172. * access
  173. */
  174. #define xlate_dev_mem_ptr(p) __va(p)
  175. /*
  176. * Convert a virtual cached pointer to an uncached pointer
  177. */
  178. #define xlate_dev_kmem_ptr(p) p
  179. /*
  180. * Big Endian
  181. */
  182. #define out_be32(a, v) __raw_writel((v), (void __iomem __force *)(a))
  183. #define out_be16(a, v) __raw_writew((v), (a))
  184. #define in_be32(a) __raw_readl((const void __iomem __force *)(a))
  185. #define in_be16(a) __raw_readw(a)
  186. #define writel_be(v, a) out_be32((__force unsigned *)a, v)
  187. #define readl_be(a) in_be32((__force unsigned *)a)
  188. /*
  189. * Little endian
  190. */
  191. #define out_le32(a, v) __raw_writel(__cpu_to_le32(v), (a));
  192. #define out_le16(a, v) __raw_writew(__cpu_to_le16(v), (a))
  193. #define in_le32(a) __le32_to_cpu(__raw_readl(a))
  194. #define in_le16(a) __le16_to_cpu(__raw_readw(a))
  195. /* Byte ops */
  196. #define out_8(a, v) __raw_writeb((v), (a))
  197. #define in_8(a) __raw_readb(a)
  198. /* FIXME */
  199. static inline void __iomem *ioport_map(unsigned long port, unsigned int len)
  200. {
  201. return (void __iomem *) (port);
  202. }
  203. static inline void ioport_unmap(void __iomem *addr)
  204. {
  205. /* Nothing to do */
  206. }
  207. #endif /* _ASM_MICROBLAZE_IO_H */