io.h 7.4 KB

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