io.h 6.2 KB

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