io.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * (C) Copyright 2004, 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_NIOS2_IO_H_
  24. #define __ASM_NIOS2_IO_H_
  25. static inline void sync(void)
  26. {
  27. __asm__ __volatile__ ("sync" : : : "memory");
  28. }
  29. extern unsigned char inb (unsigned char *port);
  30. extern unsigned short inw (unsigned short *port);
  31. extern unsigned inl (unsigned port);
  32. #define readb(addr)\
  33. ({unsigned char val;\
  34. asm volatile( "ldbio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
  35. #define readw(addr)\
  36. ({unsigned short val;\
  37. asm volatile( "ldhio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
  38. #define readl(addr)\
  39. ({unsigned long val;\
  40. asm volatile( "ldwio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
  41. #define writeb(addr,val)\
  42. asm volatile ("stbio %1, 0(%0)" : : "r" (addr), "r" (val))
  43. #define writew(addr,val)\
  44. asm volatile ("sthio %1, 0(%0)" : : "r" (addr), "r" (val))
  45. #define writel(addr,val)\
  46. asm volatile ("stwio %1, 0(%0)" : : "r" (addr), "r" (val))
  47. #define inb(addr) readb(addr)
  48. #define inw(addr) readw(addr)
  49. #define inl(addr) readl(addr)
  50. #define outb(addr,val) writeb(addr,val)
  51. #define outw(addr,val) writew(addr,val)
  52. #define outl(addr,val) writel(addr,val)
  53. static inline void insb (unsigned long port, void *dst, unsigned long count)
  54. {
  55. unsigned char *p = dst;
  56. while (count--) *p++ = inb (port);
  57. }
  58. static inline void insw (unsigned long port, void *dst, unsigned long count)
  59. {
  60. unsigned short *p = dst;
  61. while (count--) *p++ = inw (port);
  62. }
  63. static inline void insl (unsigned long port, void *dst, unsigned long count)
  64. {
  65. unsigned long *p = dst;
  66. while (count--) *p++ = inl (port);
  67. }
  68. static inline void outsb (unsigned long port, const void *src, unsigned long count)
  69. {
  70. const unsigned char *p = src;
  71. while (count--) outb (*p++, port);
  72. }
  73. static inline void outsw (unsigned long port, const void *src, unsigned long count)
  74. {
  75. const unsigned short *p = src;
  76. while (count--) outw (*p++, port);
  77. }
  78. static inline void outsl (unsigned long port, const void *src, unsigned long count)
  79. {
  80. const unsigned long *p = src;
  81. while (count--) outl (*p++, port);
  82. }
  83. #endif /* __ASM_NIOS2_IO_H_ */