io.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. /*
  30. * Given a physical address and a length, return a virtual address
  31. * that can be used to access the memory range with the caching
  32. * properties specified by "flags".
  33. */
  34. #define MAP_NOCACHE (0)
  35. #define MAP_WRCOMBINE (0)
  36. #define MAP_WRBACK (0)
  37. #define MAP_WRTHROUGH (0)
  38. static inline void *
  39. map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
  40. {
  41. return (void *)paddr;
  42. }
  43. /*
  44. * Take down a mapping set up by map_physmem().
  45. */
  46. static inline void unmap_physmem(void *vaddr, unsigned long flags)
  47. {
  48. }
  49. static inline phys_addr_t virt_to_phys(void * vaddr)
  50. {
  51. return (phys_addr_t)(vaddr);
  52. }
  53. extern unsigned char inb (unsigned char *port);
  54. extern unsigned short inw (unsigned short *port);
  55. extern unsigned inl (unsigned port);
  56. #define __raw_writeb(v,a) (*(volatile unsigned char *)(a) = (v))
  57. #define __raw_writew(v,a) (*(volatile unsigned short *)(a) = (v))
  58. #define __raw_writel(v,a) (*(volatile unsigned int *)(a) = (v))
  59. #define __raw_readb(a) (*(volatile unsigned char *)(a))
  60. #define __raw_readw(a) (*(volatile unsigned short *)(a))
  61. #define __raw_readl(a) (*(volatile unsigned int *)(a))
  62. #define readb(addr)\
  63. ({unsigned char val;\
  64. asm volatile( "ldbio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
  65. #define readw(addr)\
  66. ({unsigned short val;\
  67. asm volatile( "ldhio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
  68. #define readl(addr)\
  69. ({unsigned long val;\
  70. asm volatile( "ldwio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
  71. #define writeb(addr,val)\
  72. asm volatile ("stbio %1, 0(%0)" : : "r" (addr), "r" (val))
  73. #define writew(addr,val)\
  74. asm volatile ("sthio %1, 0(%0)" : : "r" (addr), "r" (val))
  75. #define writel(addr,val)\
  76. asm volatile ("stwio %1, 0(%0)" : : "r" (addr), "r" (val))
  77. #define inb(addr) readb(addr)
  78. #define inw(addr) readw(addr)
  79. #define inl(addr) readl(addr)
  80. #define outb(addr,val) writeb(addr,val)
  81. #define outw(addr,val) writew(addr,val)
  82. #define outl(addr,val) writel(addr,val)
  83. static inline void insb (unsigned long port, void *dst, unsigned long count)
  84. {
  85. unsigned char *p = dst;
  86. while (count--) *p++ = inb (port);
  87. }
  88. static inline void insw (unsigned long port, void *dst, unsigned long count)
  89. {
  90. unsigned short *p = dst;
  91. while (count--) *p++ = inw (port);
  92. }
  93. static inline void insl (unsigned long port, void *dst, unsigned long count)
  94. {
  95. unsigned long *p = dst;
  96. while (count--) *p++ = inl (port);
  97. }
  98. static inline void outsb (unsigned long port, const void *src, unsigned long count)
  99. {
  100. const unsigned char *p = src;
  101. while (count--) outb (*p++, port);
  102. }
  103. static inline void outsw (unsigned long port, const void *src, unsigned long count)
  104. {
  105. const unsigned short *p = src;
  106. while (count--) outw (*p++, port);
  107. }
  108. static inline void outsl (unsigned long port, const void *src, unsigned long count)
  109. {
  110. const unsigned long *p = src;
  111. while (count--) outl (*p++, port);
  112. }
  113. #endif /* __ASM_NIOS2_IO_H_ */