io.h 6.2 KB

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