io.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. #ifndef _ASM_X86_IO_H
  2. #define _ASM_X86_IO_H
  3. #define ARCH_HAS_IOREMAP_WC
  4. #include <linux/compiler.h>
  5. #include <asm-generic/int-ll64.h>
  6. #include <asm/page.h>
  7. #define build_mmio_read(name, size, type, reg, barrier) \
  8. static inline type name(const volatile void __iomem *addr) \
  9. { type ret; asm volatile("mov" size " %1,%0":reg (ret) \
  10. :"m" (*(volatile type __force *)addr) barrier); return ret; }
  11. #define build_mmio_write(name, size, type, reg, barrier) \
  12. static inline void name(type val, volatile void __iomem *addr) \
  13. { asm volatile("mov" size " %0,%1": :reg (val), \
  14. "m" (*(volatile type __force *)addr) barrier); }
  15. build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
  16. build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
  17. build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
  18. build_mmio_read(__readb, "b", unsigned char, "=q", )
  19. build_mmio_read(__readw, "w", unsigned short, "=r", )
  20. build_mmio_read(__readl, "l", unsigned int, "=r", )
  21. build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
  22. build_mmio_write(writew, "w", unsigned short, "r", :"memory")
  23. build_mmio_write(writel, "l", unsigned int, "r", :"memory")
  24. build_mmio_write(__writeb, "b", unsigned char, "q", )
  25. build_mmio_write(__writew, "w", unsigned short, "r", )
  26. build_mmio_write(__writel, "l", unsigned int, "r", )
  27. #define readb_relaxed(a) __readb(a)
  28. #define readw_relaxed(a) __readw(a)
  29. #define readl_relaxed(a) __readl(a)
  30. #define __raw_readb __readb
  31. #define __raw_readw __readw
  32. #define __raw_readl __readl
  33. #define __raw_writeb __writeb
  34. #define __raw_writew __writew
  35. #define __raw_writel __writel
  36. #define mmiowb() barrier()
  37. #ifdef CONFIG_X86_64
  38. build_mmio_read(readq, "q", unsigned long, "=r", :"memory")
  39. build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
  40. #else
  41. static inline __u64 readq(const volatile void __iomem *addr)
  42. {
  43. const volatile u32 __iomem *p = addr;
  44. u32 low, high;
  45. low = readl(p);
  46. high = readl(p + 1);
  47. return low + ((u64)high << 32);
  48. }
  49. static inline void writeq(__u64 val, volatile void __iomem *addr)
  50. {
  51. writel(val, addr);
  52. writel(val >> 32, addr+4);
  53. }
  54. #endif
  55. #define readq_relaxed(a) readq(a)
  56. #define __raw_readq(a) readq(a)
  57. #define __raw_writeq(val, addr) writeq(val, addr)
  58. /* Let people know that we have them */
  59. #define readq readq
  60. #define writeq writeq
  61. /**
  62. * virt_to_phys - map virtual addresses to physical
  63. * @address: address to remap
  64. *
  65. * The returned physical address is the physical (CPU) mapping for
  66. * the memory address given. It is only valid to use this function on
  67. * addresses directly mapped or allocated via kmalloc.
  68. *
  69. * This function does not give bus mappings for DMA transfers. In
  70. * almost all conceivable cases a device driver should not be using
  71. * this function
  72. */
  73. static inline phys_addr_t virt_to_phys(volatile void *address)
  74. {
  75. return __pa(address);
  76. }
  77. /**
  78. * phys_to_virt - map physical address to virtual
  79. * @address: address to remap
  80. *
  81. * The returned virtual address is a current CPU mapping for
  82. * the memory address given. It is only valid to use this function on
  83. * addresses that have a kernel mapping
  84. *
  85. * This function does not handle bus mappings for DMA transfers. In
  86. * almost all conceivable cases a device driver should not be using
  87. * this function
  88. */
  89. static inline void *phys_to_virt(phys_addr_t address)
  90. {
  91. return __va(address);
  92. }
  93. /*
  94. * Change "struct page" to physical address.
  95. */
  96. #define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << PAGE_SHIFT)
  97. /*
  98. * ISA I/O bus memory addresses are 1:1 with the physical address.
  99. */
  100. #define isa_virt_to_bus virt_to_phys
  101. #define isa_page_to_bus page_to_phys
  102. #define isa_bus_to_virt phys_to_virt
  103. /*
  104. * However PCI ones are not necessarily 1:1 and therefore these interfaces
  105. * are forbidden in portable PCI drivers.
  106. *
  107. * Allow them on x86 for legacy drivers, though.
  108. */
  109. #define virt_to_bus virt_to_phys
  110. #define bus_to_virt phys_to_virt
  111. /**
  112. * ioremap - map bus memory into CPU space
  113. * @offset: bus address of the memory
  114. * @size: size of the resource to map
  115. *
  116. * ioremap performs a platform specific sequence of operations to
  117. * make bus memory CPU accessible via the readb/readw/readl/writeb/
  118. * writew/writel functions and the other mmio helpers. The returned
  119. * address is not guaranteed to be usable directly as a virtual
  120. * address.
  121. *
  122. * If the area you are trying to map is a PCI BAR you should have a
  123. * look at pci_iomap().
  124. */
  125. extern void __iomem *ioremap_nocache(resource_size_t offset, unsigned long size);
  126. extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);
  127. extern void __iomem *ioremap_prot(resource_size_t offset, unsigned long size,
  128. unsigned long prot_val);
  129. /*
  130. * The default ioremap() behavior is non-cached:
  131. */
  132. static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
  133. {
  134. return ioremap_nocache(offset, size);
  135. }
  136. extern void iounmap(volatile void __iomem *addr);
  137. extern void __iomem *fix_ioremap(unsigned idx, unsigned long phys);
  138. #ifdef CONFIG_X86_32
  139. # include "io_32.h"
  140. #else
  141. # include "io_64.h"
  142. #endif
  143. extern void *xlate_dev_mem_ptr(unsigned long phys);
  144. extern void unxlate_dev_mem_ptr(unsigned long phys, void *addr);
  145. extern int ioremap_change_attr(unsigned long vaddr, unsigned long size,
  146. unsigned long prot_val);
  147. extern void __iomem *ioremap_wc(unsigned long offset, unsigned long size);
  148. /*
  149. * early_ioremap() and early_iounmap() are for temporary early boot-time
  150. * mappings, before the real ioremap() is functional.
  151. * A boot-time mapping is currently limited to at most 16 pages.
  152. */
  153. extern void early_ioremap_init(void);
  154. extern void early_ioremap_reset(void);
  155. extern void __iomem *early_ioremap(unsigned long offset, unsigned long size);
  156. extern void __iomem *early_memremap(unsigned long offset, unsigned long size);
  157. extern void early_iounmap(void __iomem *addr, unsigned long size);
  158. extern void __iomem *fix_ioremap(unsigned idx, unsigned long phys);
  159. #endif /* _ASM_X86_IO_H */