io.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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 __raw_writeb(v,a) (*(volatile unsigned char *)(a) = (v))
  33. #define __raw_writew(v,a) (*(volatile unsigned short *)(a) = (v))
  34. #define __raw_writel(v,a) (*(volatile unsigned int *)(a) = (v))
  35. #define __raw_readb(a) (*(volatile unsigned char *)(a))
  36. #define __raw_readw(a) (*(volatile unsigned short *)(a))
  37. #define __raw_readl(a) (*(volatile unsigned int *)(a))
  38. #define readb(addr)\
  39. ({unsigned char val;\
  40. asm volatile( "ldbio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
  41. #define readw(addr)\
  42. ({unsigned short val;\
  43. asm volatile( "ldhio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
  44. #define readl(addr)\
  45. ({unsigned long val;\
  46. asm volatile( "ldwio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
  47. #define writeb(addr,val)\
  48. asm volatile ("stbio %1, 0(%0)" : : "r" (addr), "r" (val))
  49. #define writew(addr,val)\
  50. asm volatile ("sthio %1, 0(%0)" : : "r" (addr), "r" (val))
  51. #define writel(addr,val)\
  52. asm volatile ("stwio %1, 0(%0)" : : "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(addr,val) writeb(addr,val)
  57. #define outw(addr,val) writew(addr,val)
  58. #define outl(addr,val) 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. #endif /* __ASM_NIOS2_IO_H_ */