io.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
  3. * Scott McNutt <smcnutt@psyent.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #ifndef __ASM_NIOS2_IO_H_
  8. #define __ASM_NIOS2_IO_H_
  9. static inline void sync(void)
  10. {
  11. __asm__ __volatile__ ("sync" : : : "memory");
  12. }
  13. /*
  14. * Given a physical address and a length, return a virtual address
  15. * that can be used to access the memory range with the caching
  16. * properties specified by "flags".
  17. */
  18. #define MAP_NOCACHE (0)
  19. #define MAP_WRCOMBINE (0)
  20. #define MAP_WRBACK (0)
  21. #define MAP_WRTHROUGH (0)
  22. static inline void *
  23. map_physmem(phys_addr_t paddr, unsigned long len, unsigned long flags)
  24. {
  25. return (void *)paddr;
  26. }
  27. /*
  28. * Take down a mapping set up by map_physmem().
  29. */
  30. static inline void unmap_physmem(void *vaddr, unsigned long flags)
  31. {
  32. }
  33. static inline phys_addr_t virt_to_phys(void * vaddr)
  34. {
  35. return (phys_addr_t)(vaddr);
  36. }
  37. extern unsigned char inb (unsigned char *port);
  38. extern unsigned short inw (unsigned short *port);
  39. extern unsigned inl (unsigned port);
  40. #define __raw_writeb(v,a) (*(volatile unsigned char *)(a) = (v))
  41. #define __raw_writew(v,a) (*(volatile unsigned short *)(a) = (v))
  42. #define __raw_writel(v,a) (*(volatile unsigned int *)(a) = (v))
  43. #define __raw_readb(a) (*(volatile unsigned char *)(a))
  44. #define __raw_readw(a) (*(volatile unsigned short *)(a))
  45. #define __raw_readl(a) (*(volatile unsigned int *)(a))
  46. #define readb(addr)\
  47. ({unsigned char val;\
  48. asm volatile( "ldbio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
  49. #define readw(addr)\
  50. ({unsigned short val;\
  51. asm volatile( "ldhio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
  52. #define readl(addr)\
  53. ({unsigned long val;\
  54. asm volatile( "ldwio %0, 0(%1)" :"=r"(val) : "r" (addr)); val;})
  55. #define writeb(val,addr)\
  56. asm volatile ("stbio %0, 0(%1)" : : "r" (val), "r" (addr))
  57. #define writew(val,addr)\
  58. asm volatile ("sthio %0, 0(%1)" : : "r" (val), "r" (addr))
  59. #define writel(val,addr)\
  60. asm volatile ("stwio %0, 0(%1)" : : "r" (val), "r" (addr))
  61. #define inb(addr) readb(addr)
  62. #define inw(addr) readw(addr)
  63. #define inl(addr) readl(addr)
  64. #define outb(val, addr) writeb(val,addr)
  65. #define outw(val, addr) writew(val,addr)
  66. #define outl(val, addr) writel(val,addr)
  67. static inline void insb (unsigned long port, void *dst, unsigned long count)
  68. {
  69. unsigned char *p = dst;
  70. while (count--) *p++ = inb (port);
  71. }
  72. static inline void insw (unsigned long port, void *dst, unsigned long count)
  73. {
  74. unsigned short *p = dst;
  75. while (count--) *p++ = inw (port);
  76. }
  77. static inline void insl (unsigned long port, void *dst, unsigned long count)
  78. {
  79. unsigned long *p = dst;
  80. while (count--) *p++ = inl (port);
  81. }
  82. static inline void outsb (unsigned long port, const void *src, unsigned long count)
  83. {
  84. const unsigned char *p = src;
  85. while (count--) outb (*p++, port);
  86. }
  87. static inline void outsw (unsigned long port, const void *src, unsigned long count)
  88. {
  89. const unsigned short *p = src;
  90. while (count--) outw (*p++, port);
  91. }
  92. static inline void outsl (unsigned long port, const void *src, unsigned long count)
  93. {
  94. const unsigned long *p = src;
  95. while (count--) outl (*p++, port);
  96. }
  97. #endif /* __ASM_NIOS2_IO_H_ */