io.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. #define eieio() __asm__ __volatile__ ("eieio" : : : "memory");
  85. #define sync() __asm__ __volatile__ ("sync" : : : "memory");
  86. /* Enforce in-order execution of data I/O.
  87. * No distinction between read/write on PPC; use eieio for all three.
  88. */
  89. #define iobarrier_rw() eieio()
  90. #define iobarrier_r() eieio()
  91. #define iobarrier_w() eieio()
  92. /*
  93. * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
  94. */
  95. extern inline int in_8(volatile u8 *addr)
  96. {
  97. int ret;
  98. __asm__ __volatile__("lbz%U1%X1 %0,%1; eieio" : "=r" (ret) : "m" (*addr));
  99. return ret;
  100. }
  101. extern inline void out_8(volatile u8 *addr, int val)
  102. {
  103. __asm__ __volatile__("stb%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
  104. }
  105. extern inline int in_le16(volatile u16 *addr)
  106. {
  107. int ret;
  108. __asm__ __volatile__("lhbrx %0,0,%1; eieio" : "=r" (ret) :
  109. "r" (addr), "m" (*addr));
  110. return ret;
  111. }
  112. extern inline int in_be16(volatile u16 *addr)
  113. {
  114. int ret;
  115. __asm__ __volatile__("lhz%U1%X1 %0,%1; eieio" : "=r" (ret) : "m" (*addr));
  116. return ret;
  117. }
  118. extern inline void out_le16(volatile u16 *addr, int val)
  119. {
  120. __asm__ __volatile__("sthbrx %1,0,%2; eieio" : "=m" (*addr) :
  121. "r" (val), "r" (addr));
  122. }
  123. extern inline void out_be16(volatile u16 *addr, int val)
  124. {
  125. __asm__ __volatile__("sth%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
  126. }
  127. extern inline unsigned in_le32(volatile u32 *addr)
  128. {
  129. unsigned ret;
  130. __asm__ __volatile__("lwbrx %0,0,%1; eieio" : "=r" (ret) :
  131. "r" (addr), "m" (*addr));
  132. return ret;
  133. }
  134. extern inline unsigned in_be32(volatile u32 *addr)
  135. {
  136. unsigned ret;
  137. __asm__ __volatile__("lwz%U1%X1 %0,%1; eieio" : "=r" (ret) : "m" (*addr));
  138. return ret;
  139. }
  140. extern inline void out_le32(volatile unsigned *addr, int val)
  141. {
  142. __asm__ __volatile__("stwbrx %1,0,%2; eieio" : "=m" (*addr) :
  143. "r" (val), "r" (addr));
  144. }
  145. extern inline void out_be32(volatile unsigned *addr, int val)
  146. {
  147. __asm__ __volatile__("stw%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
  148. }
  149. #endif