io.h 2.8 KB

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