io.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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. #ifndef _IO_BASE
  13. #define _IO_BASE 0
  14. #endif
  15. #define readb(addr) in_8((volatile u8 *)(addr))
  16. #define writeb(b,addr) out_8((volatile u8 *)(addr), (b))
  17. #if !defined(__BIG_ENDIAN)
  18. #define readw(addr) (*(volatile u16 *) (addr))
  19. #define readl(addr) (*(volatile u32 *) (addr))
  20. #define writew(b,addr) ((*(volatile u16 *) (addr)) = (b))
  21. #define writel(b,addr) ((*(volatile u32 *) (addr)) = (b))
  22. #else
  23. #define readw(addr) in_le16((volatile u16 *)(addr))
  24. #define readl(addr) in_le32((volatile u32 *)(addr))
  25. #define writew(b,addr) out_le16((volatile u16 *)(addr),(b))
  26. #define writel(b,addr) out_le32((volatile u32 *)(addr),(b))
  27. #endif
  28. /*
  29. * The insw/outsw/insl/outsl macros don't do byte-swapping.
  30. * They are only used in practice for transferring buffers which
  31. * are arrays of bytes, and byte-swapping is not appropriate in
  32. * that case. - paulus
  33. */
  34. #define insb(port, buf, ns) _insb((u8 *)((port)+_IO_BASE), (buf), (ns))
  35. #define outsb(port, buf, ns) _outsb((u8 *)((port)+_IO_BASE), (buf), (ns))
  36. #define insw(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  37. #define outsw(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  38. #define insl(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  39. #define outsl(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  40. #define inb(port) in_8((u8 *)((port)+_IO_BASE))
  41. #define outb(val, port) out_8((u8 *)((port)+_IO_BASE), (val))
  42. #if !defined(__BIG_ENDIAN)
  43. #define inw(port) in_be16((u16 *)((port)+_IO_BASE))
  44. #define outw(val, port) out_be16((u16 *)((port)+_IO_BASE), (val))
  45. #define inl(port) in_be32((u32 *)((port)+_IO_BASE))
  46. #define outl(val, port) out_be32((u32 *)((port)+_IO_BASE), (val))
  47. #else
  48. #define inw(port) in_le16((u16 *)((port)+_IO_BASE))
  49. #define outw(val, port) out_le16((u16 *)((port)+_IO_BASE), (val))
  50. #define inl(port) in_le32((u32 *)((port)+_IO_BASE))
  51. #define outl(val, port) out_le32((u32 *)((port)+_IO_BASE), (val))
  52. #endif
  53. #define inb_p(port) in_8((u8 *)((port)+_IO_BASE))
  54. #define outb_p(val, port) out_8((u8 *)((port)+_IO_BASE), (val))
  55. #define inw_p(port) in_le16((u16 *)((port)+_IO_BASE))
  56. #define outw_p(val, port) out_le16((u16 *)((port)+_IO_BASE), (val))
  57. #define inl_p(port) in_le32((u32 *)((port)+_IO_BASE))
  58. #define outl_p(val, port) out_le32((u32 *)((port)+_IO_BASE), (val))
  59. extern void _insb(volatile u8 *port, void *buf, int ns);
  60. extern void _outsb(volatile u8 *port, const void *buf, int ns);
  61. extern void _insw(volatile u16 *port, void *buf, int ns);
  62. extern void _outsw(volatile u16 *port, const void *buf, int ns);
  63. extern void _insl(volatile u32 *port, void *buf, int nl);
  64. extern void _outsl(volatile u32 *port, const void *buf, int nl);
  65. extern void _insw_ns(volatile u16 *port, void *buf, int ns);
  66. extern void _outsw_ns(volatile u16 *port, const void *buf, int ns);
  67. extern void _insl_ns(volatile u32 *port, void *buf, int nl);
  68. extern void _outsl_ns(volatile u32 *port, const void *buf, int nl);
  69. /*
  70. * The *_ns versions below don't do byte-swapping.
  71. * Neither do the standard versions now, these are just here
  72. * for older code.
  73. */
  74. #define insw_ns(port, buf, ns) _insw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  75. #define outsw_ns(port, buf, ns) _outsw_ns((u16 *)((port)+_IO_BASE), (buf), (ns))
  76. #define insl_ns(port, buf, nl) _insl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  77. #define outsl_ns(port, buf, nl) _outsl_ns((u32 *)((port)+_IO_BASE), (buf), (nl))
  78. #define IO_SPACE_LIMIT ~0
  79. #define memset_io(a,b,c) memset((void *)(a),(b),(c))
  80. #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
  81. #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
  82. /*
  83. * Enforce In-order Execution of I/O:
  84. * Acts as a barrier to ensure all previous I/O accesses have
  85. * completed before any further ones are issued.
  86. */
  87. static inline void eieio(void)
  88. {
  89. __asm__ __volatile__ ("eieio" : : : "memory");
  90. }
  91. static inline void sync(void)
  92. {
  93. __asm__ __volatile__ ("sync" : : : "memory");
  94. }
  95. static inline void isync(void)
  96. {
  97. __asm__ __volatile__ ("isync" : : : "memory");
  98. }
  99. /* Enforce in-order execution of data I/O.
  100. * No distinction between read/write on PPC; use eieio for all three.
  101. */
  102. #define iobarrier_rw() eieio()
  103. #define iobarrier_r() eieio()
  104. #define iobarrier_w() eieio()
  105. /*
  106. * Non ordered and non-swapping "raw" accessors
  107. */
  108. #define __iomem
  109. #define PCI_FIX_ADDR(addr) (addr)
  110. static inline unsigned char __raw_readb(const volatile void __iomem *addr)
  111. {
  112. return *(volatile unsigned char *)PCI_FIX_ADDR(addr);
  113. }
  114. static inline unsigned short __raw_readw(const volatile void __iomem *addr)
  115. {
  116. return *(volatile unsigned short *)PCI_FIX_ADDR(addr);
  117. }
  118. static inline unsigned int __raw_readl(const volatile void __iomem *addr)
  119. {
  120. return *(volatile unsigned int *)PCI_FIX_ADDR(addr);
  121. }
  122. static inline void __raw_writeb(unsigned char v, volatile void __iomem *addr)
  123. {
  124. *(volatile unsigned char *)PCI_FIX_ADDR(addr) = v;
  125. }
  126. static inline void __raw_writew(unsigned short v, volatile void __iomem *addr)
  127. {
  128. *(volatile unsigned short *)PCI_FIX_ADDR(addr) = v;
  129. }
  130. static inline void __raw_writel(unsigned int v, volatile void __iomem *addr)
  131. {
  132. *(volatile unsigned int *)PCI_FIX_ADDR(addr) = v;
  133. }
  134. /*
  135. * 8, 16 and 32 bit, big and little endian I/O operations, with barrier.
  136. *
  137. * Read operations have additional twi & isync to make sure the read
  138. * is actually performed (i.e. the data has come back) before we start
  139. * executing any following instructions.
  140. */
  141. extern inline int in_8(const volatile unsigned char __iomem *addr)
  142. {
  143. int ret;
  144. __asm__ __volatile__(
  145. "sync; lbz%U1%X1 %0,%1;\n"
  146. "twi 0,%0,0;\n"
  147. "isync" : "=r" (ret) : "m" (*addr));
  148. return ret;
  149. }
  150. extern inline void out_8(volatile unsigned char __iomem *addr, int val)
  151. {
  152. __asm__ __volatile__("stb%U0%X0 %1,%0; eieio" : "=m" (*addr) : "r" (val));
  153. }
  154. extern inline int in_le16(const volatile unsigned short __iomem *addr)
  155. {
  156. int ret;
  157. __asm__ __volatile__("sync; lhbrx %0,0,%1;\n"
  158. "twi 0,%0,0;\n"
  159. "isync" : "=r" (ret) :
  160. "r" (addr), "m" (*addr));
  161. return ret;
  162. }
  163. extern inline int in_be16(const volatile unsigned short __iomem *addr)
  164. {
  165. int ret;
  166. __asm__ __volatile__("sync; lhz%U1%X1 %0,%1;\n"
  167. "twi 0,%0,0;\n"
  168. "isync" : "=r" (ret) : "m" (*addr));
  169. return ret;
  170. }
  171. extern inline void out_le16(volatile unsigned short __iomem *addr, int val)
  172. {
  173. __asm__ __volatile__("sync; sthbrx %1,0,%2" : "=m" (*addr) :
  174. "r" (val), "r" (addr));
  175. }
  176. extern inline void out_be16(volatile unsigned short __iomem *addr, int val)
  177. {
  178. __asm__ __volatile__("sync; sth%U0%X0 %1,%0" : "=m" (*addr) : "r" (val));
  179. }
  180. extern inline unsigned in_le32(const volatile unsigned __iomem *addr)
  181. {
  182. unsigned ret;
  183. __asm__ __volatile__("sync; lwbrx %0,0,%1;\n"
  184. "twi 0,%0,0;\n"
  185. "isync" : "=r" (ret) :
  186. "r" (addr), "m" (*addr));
  187. return ret;
  188. }
  189. extern inline unsigned in_be32(const volatile unsigned __iomem *addr)
  190. {
  191. unsigned ret;
  192. __asm__ __volatile__("sync; lwz%U1%X1 %0,%1;\n"
  193. "twi 0,%0,0;\n"
  194. "isync" : "=r" (ret) : "m" (*addr));
  195. return ret;
  196. }
  197. extern inline void out_le32(volatile unsigned __iomem *addr, int val)
  198. {
  199. __asm__ __volatile__("sync; stwbrx %1,0,%2" : "=m" (*addr) :
  200. "r" (val), "r" (addr));
  201. }
  202. extern inline void out_be32(volatile unsigned __iomem *addr, int val)
  203. {
  204. __asm__ __volatile__("sync; stw%U0%X0 %1,%0" : "=m" (*addr) : "r" (val));
  205. }
  206. /*
  207. * Given a physical address and a length, return a virtual address
  208. * that can be used to access the memory range with the caching
  209. * properties specified by "flags".
  210. */
  211. typedef unsigned long phys_addr_t;
  212. #define MAP_NOCACHE (0)
  213. #define MAP_WRCOMBINE (0)
  214. #define MAP_WRBACK (0)
  215. #define MAP_WRTHROUGH (0)
  216. static inline void *
  217. map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
  218. {
  219. return (void *)paddr;
  220. }
  221. /*
  222. * Take down a mapping set up by map_physmem().
  223. */
  224. static inline void unmap_physmem(void *vaddr, unsigned long flags)
  225. {
  226. }
  227. #endif