io.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /*
  2. * (C) Copyright 2003, Psyent Corporation <www.psyent.com>
  3. * Scott McNutt <smcnutt@psyent.com>
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #ifndef __ASM_NIOS_IO_H_
  24. #define __ASM_NIOS_IO_H_
  25. #define readb(addr)\
  26. ({unsigned char val;\
  27. asm volatile( " pfxio 0 \n"\
  28. " ld %0, [%1] \n"\
  29. " ext8d %0, %1 \n"\
  30. :"=r"(val) : "r" (addr)); val;})
  31. #define readw(addr)\
  32. ({unsigned short val;\
  33. asm volatile( " pfxio 0 \n"\
  34. " ld %0, [%1] \n"\
  35. " ext16d %0, %1 \n"\
  36. :"=r"(val) : "r" (addr)); val;})
  37. #define readl(addr)\
  38. ({unsigned long val;\
  39. asm volatile( " pfxio 0 \n"\
  40. " ld %0, [%1] \n"\
  41. :"=r"(val) : "r" (addr)); val;})
  42. #define writeb(addr,val)\
  43. asm volatile ( " fill8 %%r0, %1 \n"\
  44. " st8d [%0], %%r0 \n"\
  45. : : "r" (addr), "r" (val) : "r0")
  46. #define writew(addr,val)\
  47. asm volatile ( " fill16 %%r0, %1 \n"\
  48. " st16d [%0], %%r0 \n"\
  49. : : "r" (addr), "r" (val) : "r0")
  50. #define writel(addr,val)\
  51. asm volatile ( " st [%0], %1 \n"\
  52. : : "r" (addr), "r" (val))
  53. #define inb(addr) readb(addr)
  54. #define inw(addr) readw(addr)
  55. #define inl(addr) readl(addr)
  56. #define outb(val,addr) writeb(addr,val)
  57. #define outw(val,addr) writew(addr,val)
  58. #define outl(val,addr) writel(addr,val)
  59. static inline void insb (unsigned long port, void *dst, unsigned long count)
  60. {
  61. unsigned char *p = dst;
  62. while (count--) *p++ = inb (port);
  63. }
  64. static inline void insw (unsigned long port, void *dst, unsigned long count)
  65. {
  66. unsigned short *p = dst;
  67. while (count--) *p++ = inw (port);
  68. }
  69. static inline void insl (unsigned long port, void *dst, unsigned long count)
  70. {
  71. unsigned long *p = dst;
  72. while (count--) *p++ = inl (port);
  73. }
  74. static inline void outsb (unsigned long port, const void *src, unsigned long count)
  75. {
  76. const unsigned char *p = src;
  77. while (count--) outb (*p++, port);
  78. }
  79. static inline void outsw (unsigned long port, const void *src, unsigned long count)
  80. {
  81. const unsigned short *p = src;
  82. while (count--) outw (*p++, port);
  83. }
  84. static inline void outsl (unsigned long port, const void *src, unsigned long count)
  85. {
  86. const unsigned long *p = src;
  87. while (count--) outl (*p++, port);
  88. }
  89. static inline void sync(void)
  90. {
  91. }
  92. #endif /* __ASM_NIOS_IO_H_ */