io.h 3.9 KB

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