io.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #ifndef _IO_H
  2. #define _IO_H
  3. #include "types.h"
  4. /*
  5. * Low-level I/O routines.
  6. *
  7. * Copied from <file:arch/powerpc/include/asm/io.h> (which has no copyright)
  8. */
  9. static inline int in_8(const volatile unsigned char *addr)
  10. {
  11. int ret;
  12. __asm__ __volatile__("lbz%U1%X1 %0,%1; twi 0,%0,0; isync"
  13. : "=r" (ret) : "m" (*addr));
  14. return ret;
  15. }
  16. static inline void out_8(volatile unsigned char *addr, int val)
  17. {
  18. __asm__ __volatile__("stb%U0%X0 %1,%0; sync"
  19. : "=m" (*addr) : "r" (val));
  20. }
  21. static inline unsigned in_le16(const volatile u16 *addr)
  22. {
  23. unsigned ret;
  24. __asm__ __volatile__("lhbrx %0,0,%1; twi 0,%0,0; isync"
  25. : "=r" (ret) : "r" (addr), "m" (*addr));
  26. return ret;
  27. }
  28. static inline unsigned in_be16(const volatile u16 *addr)
  29. {
  30. unsigned ret;
  31. __asm__ __volatile__("lhz%U1%X1 %0,%1; twi 0,%0,0; isync"
  32. : "=r" (ret) : "m" (*addr));
  33. return ret;
  34. }
  35. static inline void out_le16(volatile u16 *addr, int val)
  36. {
  37. __asm__ __volatile__("sthbrx %1,0,%2; sync" : "=m" (*addr)
  38. : "r" (val), "r" (addr));
  39. }
  40. static inline void out_be16(volatile u16 *addr, int val)
  41. {
  42. __asm__ __volatile__("sth%U0%X0 %1,%0; sync"
  43. : "=m" (*addr) : "r" (val));
  44. }
  45. static inline unsigned in_le32(const volatile unsigned *addr)
  46. {
  47. unsigned ret;
  48. __asm__ __volatile__("lwbrx %0,0,%1; twi 0,%0,0; isync"
  49. : "=r" (ret) : "r" (addr), "m" (*addr));
  50. return ret;
  51. }
  52. static inline unsigned in_be32(const volatile unsigned *addr)
  53. {
  54. unsigned ret;
  55. __asm__ __volatile__("lwz%U1%X1 %0,%1; twi 0,%0,0; isync"
  56. : "=r" (ret) : "m" (*addr));
  57. return ret;
  58. }
  59. static inline void out_le32(volatile unsigned *addr, int val)
  60. {
  61. __asm__ __volatile__("stwbrx %1,0,%2; sync" : "=m" (*addr)
  62. : "r" (val), "r" (addr));
  63. }
  64. static inline void out_be32(volatile unsigned *addr, int val)
  65. {
  66. __asm__ __volatile__("stw%U0%X0 %1,%0; sync"
  67. : "=m" (*addr) : "r" (val));
  68. }
  69. static inline void sync(void)
  70. {
  71. asm volatile("sync" : : : "memory");
  72. }
  73. static inline void eieio(void)
  74. {
  75. asm volatile("eieio" : : : "memory");
  76. }
  77. static inline void barrier(void)
  78. {
  79. asm volatile("" : : : "memory");
  80. }
  81. #endif /* _IO_H */