io.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. * However, we truncate the address to unsigned int to avoid undesirable
  100. * promitions in legacy drivers.
  101. */
  102. static inline unsigned int isa_virt_to_bus(volatile void *address)
  103. {
  104. return (unsigned int)virt_to_phys(address);
  105. }
  106. #define isa_page_to_bus(page) ((unsigned int)page_to_phys(page))
  107. #define isa_bus_to_virt phys_to_virt
  108. /*
  109. * However PCI ones are not necessarily 1:1 and therefore these interfaces
  110. * are forbidden in portable PCI drivers.
  111. *
  112. * Allow them on x86 for legacy drivers, though.
  113. */
  114. #define virt_to_bus virt_to_phys
  115. #define bus_to_virt phys_to_virt
  116. /**
  117. * ioremap - map bus memory into CPU space
  118. * @offset: bus address of the memory
  119. * @size: size of the resource to map
  120. *
  121. * ioremap performs a platform specific sequence of operations to
  122. * make bus memory CPU accessible via the readb/readw/readl/writeb/
  123. * writew/writel functions and the other mmio helpers. The returned
  124. * address is not guaranteed to be usable directly as a virtual
  125. * address.
  126. *
  127. * If the area you are trying to map is a PCI BAR you should have a
  128. * look at pci_iomap().
  129. */
  130. extern void __iomem *ioremap_nocache(resource_size_t offset, unsigned long size);
  131. extern void __iomem *ioremap_cache(resource_size_t offset, unsigned long size);
  132. extern void __iomem *ioremap_prot(resource_size_t offset, unsigned long size,
  133. unsigned long prot_val);
  134. /*
  135. * The default ioremap() behavior is non-cached:
  136. */
  137. static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
  138. {
  139. return ioremap_nocache(offset, size);
  140. }
  141. extern void iounmap(volatile void __iomem *addr);
  142. #ifdef CONFIG_X86_32
  143. # include "io_32.h"
  144. #else
  145. # include "io_64.h"
  146. #endif
  147. extern void *xlate_dev_mem_ptr(unsigned long phys);
  148. extern void unxlate_dev_mem_ptr(unsigned long phys, void *addr);
  149. extern int ioremap_change_attr(unsigned long vaddr, unsigned long size,
  150. unsigned long prot_val);
  151. extern void __iomem *ioremap_wc(resource_size_t offset, unsigned long size);
  152. /*
  153. * early_ioremap() and early_iounmap() are for temporary early boot-time
  154. * mappings, before the real ioremap() is functional.
  155. * A boot-time mapping is currently limited to at most 16 pages.
  156. */
  157. extern void early_ioremap_init(void);
  158. extern void early_ioremap_reset(void);
  159. extern void __iomem *early_ioremap(unsigned long offset, unsigned long size);
  160. extern void __iomem *early_memremap(unsigned long offset, unsigned long size);
  161. extern void early_iounmap(void __iomem *addr, unsigned long size);
  162. #define IO_SPACE_LIMIT 0xffff
  163. #endif /* _ASM_X86_IO_H */