io.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. #ifndef _ASM_M32R_IO_H
  2. #define _ASM_M32R_IO_H
  3. #include <linux/string.h>
  4. #include <linux/compiler.h>
  5. #include <asm/page.h> /* __va */
  6. #ifdef __KERNEL__
  7. #define IO_SPACE_LIMIT 0xFFFFFFFF
  8. /**
  9. * virt_to_phys - map virtual addresses to physical
  10. * @address: address to remap
  11. *
  12. * The returned physical address is the physical (CPU) mapping for
  13. * the memory address given. It is only valid to use this function on
  14. * addresses directly mapped or allocated via kmalloc.
  15. *
  16. * This function does not give bus mappings for DMA transfers. In
  17. * almost all conceivable cases a device driver should not be using
  18. * this function
  19. */
  20. static inline unsigned long virt_to_phys(volatile void * address)
  21. {
  22. return __pa(address);
  23. }
  24. /**
  25. * phys_to_virt - map physical address to virtual
  26. * @address: address to remap
  27. *
  28. * The returned virtual address is a current CPU mapping for
  29. * the memory address given. It is only valid to use this function on
  30. * addresses that have a kernel mapping
  31. *
  32. * This function does not handle bus mappings for DMA transfers. In
  33. * almost all conceivable cases a device driver should not be using
  34. * this function
  35. */
  36. static inline void *phys_to_virt(unsigned long address)
  37. {
  38. return __va(address);
  39. }
  40. extern void __iomem *
  41. __ioremap(unsigned long offset, unsigned long size, unsigned long flags);
  42. /**
  43. * ioremap - map bus memory into CPU space
  44. * @offset: bus address of the memory
  45. * @size: size of the resource to map
  46. *
  47. * ioremap performs a platform specific sequence of operations to
  48. * make bus memory CPU accessible via the readb/readw/readl/writeb/
  49. * writew/writel functions and the other mmio helpers. The returned
  50. * address is not guaranteed to be usable directly as a virtual
  51. * address.
  52. */
  53. static inline void __iomem *ioremap(unsigned long offset, unsigned long size)
  54. {
  55. return __ioremap(offset, size, 0);
  56. }
  57. extern void iounmap(volatile void __iomem *addr);
  58. #define ioremap_nocache(off,size) ioremap(off,size)
  59. #define ioremap_wc ioremap_nocache
  60. #define ioremap_wt ioremap_nocache
  61. #define ioremap_uc ioremap_nocache
  62. /*
  63. * IO bus memory addresses are also 1:1 with the physical address
  64. */
  65. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  66. #define page_to_bus page_to_phys
  67. #define virt_to_bus virt_to_phys
  68. extern unsigned char _inb(unsigned long);
  69. extern unsigned short _inw(unsigned long);
  70. extern unsigned long _inl(unsigned long);
  71. extern unsigned char _inb_p(unsigned long);
  72. extern unsigned short _inw_p(unsigned long);
  73. extern unsigned long _inl_p(unsigned long);
  74. extern void _outb(unsigned char, unsigned long);
  75. extern void _outw(unsigned short, unsigned long);
  76. extern void _outl(unsigned long, unsigned long);
  77. extern void _outb_p(unsigned char, unsigned long);
  78. extern void _outw_p(unsigned short, unsigned long);
  79. extern void _outl_p(unsigned long, unsigned long);
  80. extern void _insb(unsigned int, void *, unsigned long);
  81. extern void _insw(unsigned int, void *, unsigned long);
  82. extern void _insl(unsigned int, void *, unsigned long);
  83. extern void _outsb(unsigned int, const void *, unsigned long);
  84. extern void _outsw(unsigned int, const void *, unsigned long);
  85. extern void _outsl(unsigned int, const void *, unsigned long);
  86. static inline unsigned char _readb(unsigned long addr)
  87. {
  88. return *(volatile unsigned char __force *)addr;
  89. }
  90. static inline unsigned short _readw(unsigned long addr)
  91. {
  92. return *(volatile unsigned short __force *)addr;
  93. }
  94. static inline unsigned long _readl(unsigned long addr)
  95. {
  96. return *(volatile unsigned long __force *)addr;
  97. }
  98. static inline void _writeb(unsigned char b, unsigned long addr)
  99. {
  100. *(volatile unsigned char __force *)addr = b;
  101. }
  102. static inline void _writew(unsigned short w, unsigned long addr)
  103. {
  104. *(volatile unsigned short __force *)addr = w;
  105. }
  106. static inline void _writel(unsigned long l, unsigned long addr)
  107. {
  108. *(volatile unsigned long __force *)addr = l;
  109. }
  110. #define inb _inb
  111. #define inw _inw
  112. #define inl _inl
  113. #define outb _outb
  114. #define outw _outw
  115. #define outl _outl
  116. #define inb_p _inb_p
  117. #define inw_p _inw_p
  118. #define inl_p _inl_p
  119. #define outb_p _outb_p
  120. #define outw_p _outw_p
  121. #define outl_p _outl_p
  122. #define insb _insb
  123. #define insw _insw
  124. #define insl _insl
  125. #define outsb _outsb
  126. #define outsw _outsw
  127. #define outsl _outsl
  128. #define readb(addr) _readb((unsigned long)(addr))
  129. #define readw(addr) _readw((unsigned long)(addr))
  130. #define readl(addr) _readl((unsigned long)(addr))
  131. #define __raw_readb readb
  132. #define __raw_readw readw
  133. #define __raw_readl readl
  134. #define readb_relaxed readb
  135. #define readw_relaxed readw
  136. #define readl_relaxed readl
  137. #define writeb(val, addr) _writeb((val), (unsigned long)(addr))
  138. #define writew(val, addr) _writew((val), (unsigned long)(addr))
  139. #define writel(val, addr) _writel((val), (unsigned long)(addr))
  140. #define __raw_writeb writeb
  141. #define __raw_writew writew
  142. #define __raw_writel writel
  143. #define writeb_relaxed writeb
  144. #define writew_relaxed writew
  145. #define writel_relaxed writel
  146. #define ioread8 readb
  147. #define ioread16 readw
  148. #define ioread32 readl
  149. #define iowrite8 writeb
  150. #define iowrite16 writew
  151. #define iowrite32 writel
  152. #define ioread8_rep(p, dst, count) insb((unsigned long)(p), (dst), (count))
  153. #define ioread16_rep(p, dst, count) insw((unsigned long)(p), (dst), (count))
  154. #define ioread32_rep(p, dst, count) insl((unsigned long)(p), (dst), (count))
  155. #define iowrite8_rep(p, src, count) outsb((unsigned long)(p), (src), (count))
  156. #define iowrite16_rep(p, src, count) outsw((unsigned long)(p), (src), (count))
  157. #define iowrite32_rep(p, src, count) outsl((unsigned long)(p), (src), (count))
  158. #define ioread16be(addr) be16_to_cpu(readw(addr))
  159. #define ioread32be(addr) be32_to_cpu(readl(addr))
  160. #define iowrite16be(v, addr) writew(cpu_to_be16(v), (addr))
  161. #define iowrite32be(v, addr) writel(cpu_to_be32(v), (addr))
  162. #define mmiowb()
  163. #define flush_write_buffers() do { } while (0) /* M32R_FIXME */
  164. static inline void
  165. memset_io(volatile void __iomem *addr, unsigned char val, int count)
  166. {
  167. memset((void __force *) addr, val, count);
  168. }
  169. static inline void
  170. memcpy_fromio(void *dst, volatile void __iomem *src, int count)
  171. {
  172. memcpy(dst, (void __force *) src, count);
  173. }
  174. static inline void
  175. memcpy_toio(volatile void __iomem *dst, const void *src, int count)
  176. {
  177. memcpy((void __force *) dst, src, count);
  178. }
  179. /*
  180. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  181. * access
  182. */
  183. #define xlate_dev_mem_ptr(p) __va(p)
  184. /*
  185. * Convert a virtual cached pointer to an uncached pointer
  186. */
  187. #define xlate_dev_kmem_ptr(p) p
  188. #endif /* __KERNEL__ */
  189. #endif /* _ASM_M32R_IO_H */