io.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Copyright 2006 PathScale, Inc. All Rights Reserved.
  3. *
  4. * This file is free software; you can redistribute it and/or modify
  5. * it under the terms of version 2 of the GNU General Public License
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program; if not, write to the Free Software Foundation,
  15. * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  16. */
  17. #ifndef _LINUX_IO_H
  18. #define _LINUX_IO_H
  19. #include <linux/types.h>
  20. #include <linux/init.h>
  21. #include <linux/bug.h>
  22. #include <linux/err.h>
  23. #include <asm/io.h>
  24. #include <asm/page.h>
  25. struct device;
  26. struct resource;
  27. __visible void __iowrite32_copy(void __iomem *to, const void *from, size_t count);
  28. void __iowrite64_copy(void __iomem *to, const void *from, size_t count);
  29. #ifdef CONFIG_MMU
  30. int ioremap_page_range(unsigned long addr, unsigned long end,
  31. phys_addr_t phys_addr, pgprot_t prot);
  32. #else
  33. static inline int ioremap_page_range(unsigned long addr, unsigned long end,
  34. phys_addr_t phys_addr, pgprot_t prot)
  35. {
  36. return 0;
  37. }
  38. #endif
  39. #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
  40. void __init ioremap_huge_init(void);
  41. int arch_ioremap_pud_supported(void);
  42. int arch_ioremap_pmd_supported(void);
  43. #else
  44. static inline void ioremap_huge_init(void) { }
  45. #endif
  46. /*
  47. * Managed iomap interface
  48. */
  49. #ifdef CONFIG_HAS_IOPORT_MAP
  50. void __iomem * devm_ioport_map(struct device *dev, unsigned long port,
  51. unsigned int nr);
  52. void devm_ioport_unmap(struct device *dev, void __iomem *addr);
  53. #else
  54. static inline void __iomem *devm_ioport_map(struct device *dev,
  55. unsigned long port,
  56. unsigned int nr)
  57. {
  58. return NULL;
  59. }
  60. static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr)
  61. {
  62. }
  63. #endif
  64. #define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err)
  65. void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
  66. resource_size_t size);
  67. void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
  68. resource_size_t size);
  69. void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset,
  70. resource_size_t size);
  71. void devm_iounmap(struct device *dev, void __iomem *addr);
  72. int check_signature(const volatile void __iomem *io_addr,
  73. const unsigned char *signature, int length);
  74. void devm_ioremap_release(struct device *dev, void *res);
  75. void *devm_memremap(struct device *dev, resource_size_t offset,
  76. size_t size, unsigned long flags);
  77. void devm_memunmap(struct device *dev, void *addr);
  78. void *__devm_memremap_pages(struct device *dev, struct resource *res);
  79. #ifdef CONFIG_ZONE_DEVICE
  80. void *devm_memremap_pages(struct device *dev, struct resource *res);
  81. #else
  82. static inline void *devm_memremap_pages(struct device *dev, struct resource *res)
  83. {
  84. /*
  85. * Fail attempts to call devm_memremap_pages() without
  86. * ZONE_DEVICE support enabled, this requires callers to fall
  87. * back to plain devm_memremap() based on config
  88. */
  89. WARN_ON_ONCE(1);
  90. return ERR_PTR(-ENXIO);
  91. }
  92. #endif
  93. /*
  94. * Some systems do not have legacy ISA devices.
  95. * /dev/port is not a valid interface on these systems.
  96. * So for those archs, <asm/io.h> should define the following symbol.
  97. */
  98. #ifndef arch_has_dev_port
  99. #define arch_has_dev_port() (1)
  100. #endif
  101. /*
  102. * Some systems (x86 without PAT) have a somewhat reliable way to mark a
  103. * physical address range such that uncached mappings will actually
  104. * end up write-combining. This facility should be used in conjunction
  105. * with pgprot_writecombine, ioremap-wc, or set_memory_wc, since it has
  106. * no effect if the per-page mechanisms are functional.
  107. * (On x86 without PAT, these functions manipulate MTRRs.)
  108. *
  109. * arch_phys_del_wc(0) or arch_phys_del_wc(any error code) is guaranteed
  110. * to have no effect.
  111. */
  112. #ifndef arch_phys_wc_add
  113. static inline int __must_check arch_phys_wc_add(unsigned long base,
  114. unsigned long size)
  115. {
  116. return 0; /* It worked (i.e. did nothing). */
  117. }
  118. static inline void arch_phys_wc_del(int handle)
  119. {
  120. }
  121. #define arch_phys_wc_add arch_phys_wc_add
  122. #ifndef arch_phys_wc_index
  123. static inline int arch_phys_wc_index(int handle)
  124. {
  125. return -1;
  126. }
  127. #define arch_phys_wc_index arch_phys_wc_index
  128. #endif
  129. #endif
  130. enum {
  131. /* See memremap() kernel-doc for usage description... */
  132. MEMREMAP_WB = 1 << 0,
  133. MEMREMAP_WT = 1 << 1,
  134. };
  135. void *memremap(resource_size_t offset, size_t size, unsigned long flags);
  136. void memunmap(void *addr);
  137. /*
  138. * On x86 PAT systems we have memory tracking that keeps track of
  139. * the allowed mappings on memory ranges. This tracking works for
  140. * all the in-kernel mapping APIs (ioremap*), but where the user
  141. * wishes to map a range from a physical device into user memory
  142. * the tracking won't be updated. This API is to be used by
  143. * drivers which remap physical device pages into userspace,
  144. * and wants to make sure they are mapped WC and not UC.
  145. */
  146. #ifndef arch_io_reserve_memtype_wc
  147. static inline int arch_io_reserve_memtype_wc(resource_size_t base,
  148. resource_size_t size)
  149. {
  150. return 0;
  151. }
  152. static inline void arch_io_free_memtype_wc(resource_size_t base,
  153. resource_size_t size)
  154. {
  155. }
  156. #endif
  157. #endif /* _LINUX_IO_H */