io.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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. /*
  60. * IO bus memory addresses are also 1:1 with the physical address
  61. */
  62. #define page_to_phys(page) (page_to_pfn(page) << PAGE_SHIFT)
  63. #define page_to_bus page_to_phys
  64. #define virt_to_bus virt_to_phys
  65. extern unsigned char _inb(unsigned long);
  66. extern unsigned short _inw(unsigned long);
  67. extern unsigned long _inl(unsigned long);
  68. extern unsigned char _inb_p(unsigned long);
  69. extern unsigned short _inw_p(unsigned long);
  70. extern unsigned long _inl_p(unsigned long);
  71. extern void _outb(unsigned char, unsigned long);
  72. extern void _outw(unsigned short, unsigned long);
  73. extern void _outl(unsigned long, unsigned long);
  74. extern void _outb_p(unsigned char, unsigned long);
  75. extern void _outw_p(unsigned short, unsigned long);
  76. extern void _outl_p(unsigned long, unsigned long);
  77. extern void _insb(unsigned int, void *, unsigned long);
  78. extern void _insw(unsigned int, void *, unsigned long);
  79. extern void _insl(unsigned int, void *, unsigned long);
  80. extern void _outsb(unsigned int, const void *, unsigned long);
  81. extern void _outsw(unsigned int, const void *, unsigned long);
  82. extern void _outsl(unsigned int, const void *, unsigned long);
  83. static inline unsigned char _readb(unsigned long addr)
  84. {
  85. return *(volatile unsigned char __force *)addr;
  86. }
  87. static inline unsigned short _readw(unsigned long addr)
  88. {
  89. return *(volatile unsigned short __force *)addr;
  90. }
  91. static inline unsigned long _readl(unsigned long addr)
  92. {
  93. return *(volatile unsigned long __force *)addr;
  94. }
  95. static inline void _writeb(unsigned char b, unsigned long addr)
  96. {
  97. *(volatile unsigned char __force *)addr = b;
  98. }
  99. static inline void _writew(unsigned short w, unsigned long addr)
  100. {
  101. *(volatile unsigned short __force *)addr = w;
  102. }
  103. static inline void _writel(unsigned long l, unsigned long addr)
  104. {
  105. *(volatile unsigned long __force *)addr = l;
  106. }
  107. #define inb _inb
  108. #define inw _inw
  109. #define inl _inl
  110. #define outb _outb
  111. #define outw _outw
  112. #define outl _outl
  113. #define inb_p _inb_p
  114. #define inw_p _inw_p
  115. #define inl_p _inl_p
  116. #define outb_p _outb_p
  117. #define outw_p _outw_p
  118. #define outl_p _outl_p
  119. #define insb _insb
  120. #define insw _insw
  121. #define insl _insl
  122. #define outsb _outsb
  123. #define outsw _outsw
  124. #define outsl _outsl
  125. #define readb(addr) _readb((unsigned long)(addr))
  126. #define readw(addr) _readw((unsigned long)(addr))
  127. #define readl(addr) _readl((unsigned long)(addr))
  128. #define __raw_readb readb
  129. #define __raw_readw readw
  130. #define __raw_readl readl
  131. #define readb_relaxed readb
  132. #define readw_relaxed readw
  133. #define readl_relaxed readl
  134. #define writeb(val, addr) _writeb((val), (unsigned long)(addr))
  135. #define writew(val, addr) _writew((val), (unsigned long)(addr))
  136. #define writel(val, addr) _writel((val), (unsigned long)(addr))
  137. #define __raw_writeb writeb
  138. #define __raw_writew writew
  139. #define __raw_writel writel
  140. #define mmiowb()
  141. #define flush_write_buffers() do { } while (0) /* M32R_FIXME */
  142. static inline void
  143. memset_io(volatile void __iomem *addr, unsigned char val, int count)
  144. {
  145. memset((void __force *) addr, val, count);
  146. }
  147. static inline void
  148. memcpy_fromio(void *dst, volatile void __iomem *src, int count)
  149. {
  150. memcpy(dst, (void __force *) src, count);
  151. }
  152. static inline void
  153. memcpy_toio(volatile void __iomem *dst, const void *src, int count)
  154. {
  155. memcpy((void __force *) dst, src, count);
  156. }
  157. /*
  158. * Convert a physical pointer to a virtual kernel pointer for /dev/mem
  159. * access
  160. */
  161. #define xlate_dev_mem_ptr(p) __va(p)
  162. /*
  163. * Convert a virtual cached pointer to an uncached pointer
  164. */
  165. #define xlate_dev_kmem_ptr(p) p
  166. #endif /* __KERNEL__ */
  167. #endif /* _ASM_M32R_IO_H */