io_no.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. #ifndef _M68KNOMMU_IO_H
  2. #define _M68KNOMMU_IO_H
  3. #ifdef __KERNEL__
  4. #include <asm/virtconvert.h>
  5. /*
  6. * These are for ISA/PCI shared memory _only_ and should never be used
  7. * on any other type of memory, including Zorro memory. They are meant to
  8. * access the bus in the bus byte order which is little-endian!.
  9. *
  10. * readX/writeX() are used to access memory mapped devices. On some
  11. * architectures the memory mapped IO stuff needs to be accessed
  12. * differently. On the m68k architecture, we just read/write the
  13. * memory location directly.
  14. */
  15. /* ++roman: The assignments to temp. vars avoid that gcc sometimes generates
  16. * two accesses to memory, which may be undesirable for some devices.
  17. */
  18. /*
  19. * swap functions are sometimes needed to interface little-endian hardware
  20. */
  21. static inline unsigned short _swapw(volatile unsigned short v)
  22. {
  23. return ((v << 8) | (v >> 8));
  24. }
  25. static inline unsigned int _swapl(volatile unsigned long v)
  26. {
  27. return ((v << 24) | ((v & 0xff00) << 8) | ((v & 0xff0000) >> 8) | (v >> 24));
  28. }
  29. #define readb(addr) \
  30. ({ unsigned char __v = (*(volatile unsigned char *) (addr)); __v; })
  31. #define readw(addr) \
  32. ({ unsigned short __v = (*(volatile unsigned short *) (addr)); __v; })
  33. #define readl(addr) \
  34. ({ unsigned int __v = (*(volatile unsigned int *) (addr)); __v; })
  35. #define readb_relaxed(addr) readb(addr)
  36. #define readw_relaxed(addr) readw(addr)
  37. #define readl_relaxed(addr) readl(addr)
  38. #define writeb(b,addr) (void)((*(volatile unsigned char *) (addr)) = (b))
  39. #define writew(b,addr) (void)((*(volatile unsigned short *) (addr)) = (b))
  40. #define writel(b,addr) (void)((*(volatile unsigned int *) (addr)) = (b))
  41. #define __raw_readb readb
  42. #define __raw_readw readw
  43. #define __raw_readl readl
  44. #define __raw_writeb writeb
  45. #define __raw_writew writew
  46. #define __raw_writel writel
  47. static inline void io_outsb(unsigned int addr, void *buf, int len)
  48. {
  49. volatile unsigned char *ap = (volatile unsigned char *) addr;
  50. unsigned char *bp = (unsigned char *) buf;
  51. while (len--)
  52. *ap = *bp++;
  53. }
  54. static inline void io_outsw(unsigned int addr, void *buf, int len)
  55. {
  56. volatile unsigned short *ap = (volatile unsigned short *) addr;
  57. unsigned short *bp = (unsigned short *) buf;
  58. while (len--)
  59. *ap = _swapw(*bp++);
  60. }
  61. static inline void io_outsl(unsigned int addr, void *buf, int len)
  62. {
  63. volatile unsigned int *ap = (volatile unsigned int *) addr;
  64. unsigned int *bp = (unsigned int *) buf;
  65. while (len--)
  66. *ap = _swapl(*bp++);
  67. }
  68. static inline void io_insb(unsigned int addr, void *buf, int len)
  69. {
  70. volatile unsigned char *ap = (volatile unsigned char *) addr;
  71. unsigned char *bp = (unsigned char *) buf;
  72. while (len--)
  73. *bp++ = *ap;
  74. }
  75. static inline void io_insw(unsigned int addr, void *buf, int len)
  76. {
  77. volatile unsigned short *ap = (volatile unsigned short *) addr;
  78. unsigned short *bp = (unsigned short *) buf;
  79. while (len--)
  80. *bp++ = _swapw(*ap);
  81. }
  82. static inline void io_insl(unsigned int addr, void *buf, int len)
  83. {
  84. volatile unsigned int *ap = (volatile unsigned int *) addr;
  85. unsigned int *bp = (unsigned int *) buf;
  86. while (len--)
  87. *bp++ = _swapl(*ap);
  88. }
  89. #define mmiowb()
  90. /*
  91. * make the short names macros so specific devices
  92. * can override them as required
  93. */
  94. #define memset_io(a,b,c) memset((void *)(a),(b),(c))
  95. #define memcpy_fromio(a,b,c) memcpy((a),(void *)(b),(c))
  96. #define memcpy_toio(a,b,c) memcpy((void *)(a),(b),(c))
  97. #define inb(addr) readb(addr)
  98. #define inw(addr) readw(addr)
  99. #define inl(addr) readl(addr)
  100. #define outb(x,addr) ((void) writeb(x,addr))
  101. #define outw(x,addr) ((void) writew(x,addr))
  102. #define outl(x,addr) ((void) writel(x,addr))
  103. #define inb_p(addr) inb(addr)
  104. #define inw_p(addr) inw(addr)
  105. #define inl_p(addr) inl(addr)
  106. #define outb_p(x,addr) outb(x,addr)
  107. #define outw_p(x,addr) outw(x,addr)
  108. #define outl_p(x,addr) outl(x,addr)
  109. #define outsb(a,b,l) io_outsb(a,b,l)
  110. #define outsw(a,b,l) io_outsw(a,b,l)
  111. #define outsl(a,b,l) io_outsl(a,b,l)
  112. #define insb(a,b,l) io_insb(a,b,l)
  113. #define insw(a,b,l) io_insw(a,b,l)
  114. #define insl(a,b,l) io_insl(a,b,l)
  115. #define IO_SPACE_LIMIT 0xffffffff
  116. /* Values for nocacheflag and cmode */
  117. #define IOMAP_FULL_CACHING 0
  118. #define IOMAP_NOCACHE_SER 1
  119. #define IOMAP_NOCACHE_NONSER 2
  120. #define IOMAP_WRITETHROUGH 3
  121. extern void *__ioremap(unsigned long physaddr, unsigned long size, int cacheflag);
  122. extern void __iounmap(void *addr, unsigned long size);
  123. static inline void *ioremap(unsigned long physaddr, unsigned long size)
  124. {
  125. return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
  126. }
  127. static inline void *ioremap_nocache(unsigned long physaddr, unsigned long size)
  128. {
  129. return __ioremap(physaddr, size, IOMAP_NOCACHE_SER);
  130. }
  131. static inline void *ioremap_writethrough(unsigned long physaddr, unsigned long size)
  132. {
  133. return __ioremap(physaddr, size, IOMAP_WRITETHROUGH);
  134. }
  135. static inline void *ioremap_fullcache(unsigned long physaddr, unsigned long size)
  136. {
  137. return __ioremap(physaddr, size, IOMAP_FULL_CACHING);
  138. }
  139. extern void iounmap(void *addr);
  140. /*
  141. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  142. * access
  143. */
  144. #define xlate_dev_mem_ptr(p) __va(p)
  145. /*
  146. * Convert a virtual cached pointer to an uncached pointer
  147. */
  148. #define xlate_dev_kmem_ptr(p) p
  149. #endif /* __KERNEL__ */
  150. #endif /* _M68KNOMMU_IO_H */