io_no.h 5.5 KB

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