io.h 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. /* originally from linux source.
  2. * removed the dependencies on CONFIG_ values
  3. * removed virt_to_phys stuff (and in fact everything surrounded by #if __KERNEL__)
  4. * Modified By Rob Taylor, Flying Pig Systems, 2000
  5. */
  6. #ifndef _PPC_IO_H
  7. #define _PPC_IO_H
  8. #include <linux/config.h>
  9. #include <asm/byteorder.h>
  10. #define SIO_CONFIG_RA 0x398
  11. #define SIO_CONFIG_RD 0x399
  12. #define readb(addr) in_8((volatile u8 *)(addr))
  13. #define writeb(b,addr) out_8((volatile u8 *)(addr), (b))
  14. #if !defined(__BIG_ENDIAN)
  15. #define readw(addr) (*(volatile u16 *) (addr))
  16. #define readl(addr) (*(volatile u32 *) (addr))
  17. #define writew(b,addr) ((*(volatile u16 *) (addr)) = (b))
  18. #define writel(b,addr) ((*(volatile u32 *) (addr)) = (b))
  19. #else
  20. #define readw(addr) in_le16((volatile u16 *)(addr))
  21. #define readl(addr) in_le32((volatile u32 *)(addr))
  22. #define writew(b,addr) out_le16((volatile u16 *)(addr),(b))
  23. #define writel(b,addr) out_le32((volatile u32 *)(addr),(b))
  24. #endif
  25. /*
  26. * The insw/outsw/insl/outsl macros don't do byte-swapping.
  27. * They are only used in practice for transferring buffers which
  28. * are arrays of bytes, and byte-swapping is not appropriate in
  29. * that case. - paulus
  30. */
  31. #define insb(port, buf, ns) _insb((u8 *)((port)+_IO_BASE), (buf), (ns))
  32. #define outsb(port, buf, ns) _outsb((u8 *)((port)+_IO_BASE), (buf), (ns))
  33. #define insw(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  34. #define outsw(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  35. #define insl(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  36. #define outsl(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  37. #define inb(port) in_8((u8 *)((port)+_IO_BASE))
  38. #define outb(val, port) out_8((u8 *)((port)+_IO_BASE), (val))
  39. #if !defined(__BIG_ENDIAN)
  40. #define inw(port) in_be16((u16 *)((port)+_IO_BASE))
  41. #define outw(val, port) out_be16((u16 *)((port)+_IO_BASE), (val))
  42. #define inl(port) in_be32((u32 *)((port)+_IO_BASE))
  43. #define outl(val, port) out_be32((u32 *)((port)+_IO_BASE), (val))
  44. #else
  45. #define inw(port) in_le16((u16 *)((port)+_IO_BASE))
  46. #define outw(val, port) out_le16((u16 *)((port)+_IO_BASE), (val))
  47. #define inl(port) in_le32((u32 *)((port)+_IO_BASE))
  48. #define outl(val, port) out_le32((u32 *)((port)+_IO_BASE), (val))
  49. #endif
  50. #define inb_p(port) in_8((u8 *)((port)+_IO_BASE))
  51. #define outb_p(val, port) out_8((u8 *)((port)+_IO_BASE), (val))
  52. #define inw_p(port) in_le16((u16 *)((port)+_IO_BASE))
  53. #define outw_p(val, port) out_le16((u16 *)((port)+_IO_BASE), (val))
  54. #define inl_p(port) in_le32((u32 *)((port)+_IO_BASE))
  55. #define outl_p(val, port) out_le32((u32 *)((port)+_IO_BASE), (val))
  56. extern void _insb(volatile u8 *port, void *buf, int ns);
  57. extern void _outsb(volatile u8 *port, const void *buf, int ns);
  58. extern void _insw(volatile u16 *port, void *buf, int ns);
  59. extern void _outsw(volatile u16 *port, const void *buf, int ns);
  60. extern void _insl(volatile u32 *port, void *buf, int nl);
  61. extern void _outsl(volatile u32 *port, const void *buf, int nl);
  62. extern void _insw_ns(volatile u16 *port, void *buf, int ns);
  63. extern void _outsw_ns(volatile u16 *port, const void *buf, int ns);
  64. extern void _insl_ns(volatile u32 *port, void *buf, int nl);
  65. extern void _outsl_ns(volatile u32 *port, const void *buf, int nl);
  66. /*
  67. * The *_ns versions below don't do byte-swapping.
  68. * Neither do the standard versions now, these are just here
  69. * for older code.
  70. */
  71. #define insw_ns(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  72. #define outsw_ns(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  73. #define insl_ns(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  74. #define outsl_ns(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  75. #define IO_SPACE_LIMIT ~0
  76. #define memset_io(a,b,c) memset((void *)(a),(b),(c))
  77. #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
  78. #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
  79. /*
  80. * Enforce In-order Execution of I/O:
  81. * Acts as a barrier to ensure all previous I/O accesses have
  82. * completed before any further ones are issued.
  83. */
  84. static inline void eieio(void)
  85. {
  86. __asm__ __volatile__ ("eieio" : : : "memory");
  87. }
  88. static inline void sync(void)
  89. {
  90. __asm__ __volatile__ ("sync" : : : "memory");
  91. }
  92. static inline void isync(void)
  93. {
  94. __asm__ __volatile__ ("isync" : : : "memory");
  95. }
  96. /* Enforce in-order execution of data I/O.
  97. * No distinction between read/write on PPC; use eieio for all three.
  98. */
  99. #define iobarrier_rw() eieio()
  100. #define iobarrier_r() eieio()
  101. #define iobarrier_w() eieio()
  102. /*
  103. * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
  104. *
  105. * Read operations have additional twi & isync to make sure the read
  106. * is actually performed (i.e. the data has come back) before we start
  107. * executing any following instructions.
  108. */
  109. #define __iomem
  110. extern inline int in_8(const volatile unsigned char __iomem *addr)
  111. {
  112. int ret;
  113. __asm__ __volatile__(
  114. "sync; lbz%U1%X1 %0,%1;\n"
  115. "twi 0,%0,0;\n"
  116. "isync" : "=r" (ret) : "m" (*addr));
  117. return ret;
  118. }
  119. extern inline void out_8(volatile unsigned char __iomem *addr, int val)
  120. {
  121. __asm__ __volatile__("stb%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
  122. }
  123. extern inline int in_le16(const volatile unsigned short __iomem *addr)
  124. {
  125. int ret;
  126. __asm__ __volatile__("sync; lhbrx %0,0,%1;\n"
  127. "twi 0,%0,0;\n"
  128. "isync" : "=r" (ret) :
  129. "r" (addr), "m" (*addr));
  130. return ret;
  131. }
  132. extern inline int in_be16(const volatile unsigned short __iomem *addr)
  133. {
  134. int ret;
  135. __asm__ __volatile__("sync; lhz%U1%X1 %0,%1;\n"
  136. "twi 0,%0,0;\n"
  137. "isync" : "=r" (ret) : "m" (*addr));
  138. return ret;
  139. }
  140. extern inline void out_le16(volatile unsigned short __iomem *addr, int val)
  141. {
  142. __asm__ __volatile__("sync; sthbrx %1,0,%2" : "=m" (*addr) :
  143. "r" (val), "r" (addr));
  144. }
  145. extern inline void out_be16(volatile unsigned short __iomem *addr, int val)
  146. {
  147. __asm__ __volatile__("sync; sth%U0%X0 %1,%0" : "=m" (*addr) : "r" (val));
  148. }
  149. extern inline unsigned in_le32(const volatile unsigned __iomem *addr)
  150. {
  151. unsigned ret;
  152. __asm__ __volatile__("sync; lwbrx %0,0,%1;\n"
  153. "twi 0,%0,0;\n"
  154. "isync" : "=r" (ret) :
  155. "r" (addr), "m" (*addr));
  156. return ret;
  157. }
  158. extern inline unsigned in_be32(const volatile unsigned __iomem *addr)
  159. {
  160. unsigned ret;
  161. __asm__ __volatile__("sync; lwz%U1%X1 %0,%1;\n"
  162. "twi 0,%0,0;\n"
  163. "isync" : "=r" (ret) : "m" (*addr));
  164. return ret;
  165. }
  166. extern inline void out_le32(volatile unsigned __iomem *addr, int val)
  167. {
  168. __asm__ __volatile__("sync; stwbrx %1,0,%2" : "=m" (*addr) :
  169. "r" (val), "r" (addr));
  170. }
  171. extern inline void out_be32(volatile unsigned __iomem *addr, int val)
  172. {
  173. __asm__ __volatile__("sync; stw%U0%X0 %1,%0" : "=m" (*addr) : "r" (val));
  174. }
  175. #endif