io.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  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 __ioread32_copy(void *to, const void __iomem *from, size_t count);
  29. void __iowrite64_copy(void __iomem *to, const void *from, size_t count);
  30. #ifdef CONFIG_MMU
  31. int ioremap_page_range(unsigned long addr, unsigned long end,
  32. phys_addr_t phys_addr, pgprot_t prot);
  33. #else
  34. static inline int ioremap_page_range(unsigned long addr, unsigned long end,
  35. phys_addr_t phys_addr, pgprot_t prot)
  36. {
  37. return 0;
  38. }
  39. #endif
  40. #ifdef CONFIG_HAVE_ARCH_HUGE_VMAP
  41. void __init ioremap_huge_init(void);
  42. int arch_ioremap_pud_supported(void);
  43. int arch_ioremap_pmd_supported(void);
  44. #else
  45. static inline void ioremap_huge_init(void) { }
  46. #endif
  47. /*
  48. * Managed iomap interface
  49. */
  50. #ifdef CONFIG_HAS_IOPORT_MAP
  51. void __iomem * devm_ioport_map(struct device *dev, unsigned long port,
  52. unsigned int nr);
  53. void devm_ioport_unmap(struct device *dev, void __iomem *addr);
  54. #else
  55. static inline void __iomem *devm_ioport_map(struct device *dev,
  56. unsigned long port,
  57. unsigned int nr)
  58. {
  59. return NULL;
  60. }
  61. static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr)
  62. {
  63. }
  64. #endif
  65. #define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err)
  66. void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
  67. resource_size_t size);
  68. void __iomem *devm_ioremap_nocache(struct device *dev, resource_size_t offset,
  69. resource_size_t size);
  70. void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset,
  71. resource_size_t size);
  72. void devm_iounmap(struct device *dev, void __iomem *addr);
  73. int check_signature(const volatile void __iomem *io_addr,
  74. const unsigned char *signature, int length);
  75. void devm_ioremap_release(struct device *dev, void *res);
  76. void *devm_memremap(struct device *dev, resource_size_t offset,
  77. size_t size, unsigned long flags);
  78. void devm_memunmap(struct device *dev, void *addr);
  79. void *__devm_memremap_pages(struct device *dev, struct resource *res);
  80. /*
  81. * Some systems do not have legacy ISA devices.
  82. * /dev/port is not a valid interface on these systems.
  83. * So for those archs, <asm/io.h> should define the following symbol.
  84. */
  85. #ifndef arch_has_dev_port
  86. #define arch_has_dev_port() (1)
  87. #endif
  88. /*
  89. * Some systems (x86 without PAT) have a somewhat reliable way to mark a
  90. * physical address range such that uncached mappings will actually
  91. * end up write-combining. This facility should be used in conjunction
  92. * with pgprot_writecombine, ioremap-wc, or set_memory_wc, since it has
  93. * no effect if the per-page mechanisms are functional.
  94. * (On x86 without PAT, these functions manipulate MTRRs.)
  95. *
  96. * arch_phys_del_wc(0) or arch_phys_del_wc(any error code) is guaranteed
  97. * to have no effect.
  98. */
  99. #ifndef arch_phys_wc_add
  100. static inline int __must_check arch_phys_wc_add(unsigned long base,
  101. unsigned long size)
  102. {
  103. return 0; /* It worked (i.e. did nothing). */
  104. }
  105. static inline void arch_phys_wc_del(int handle)
  106. {
  107. }
  108. #define arch_phys_wc_add arch_phys_wc_add
  109. #ifndef arch_phys_wc_index
  110. static inline int arch_phys_wc_index(int handle)
  111. {
  112. return -1;
  113. }
  114. #define arch_phys_wc_index arch_phys_wc_index
  115. #endif
  116. #endif
  117. enum {
  118. /* See memremap() kernel-doc for usage description... */
  119. MEMREMAP_WB = 1 << 0,
  120. MEMREMAP_WT = 1 << 1,
  121. MEMREMAP_WC = 1 << 2,
  122. };
  123. void *memremap(resource_size_t offset, size_t size, unsigned long flags);
  124. void memunmap(void *addr);
  125. /*
  126. * On x86 PAT systems we have memory tracking that keeps track of
  127. * the allowed mappings on memory ranges. This tracking works for
  128. * all the in-kernel mapping APIs (ioremap*), but where the user
  129. * wishes to map a range from a physical device into user memory
  130. * the tracking won't be updated. This API is to be used by
  131. * drivers which remap physical device pages into userspace,
  132. * and wants to make sure they are mapped WC and not UC.
  133. */
  134. #ifndef arch_io_reserve_memtype_wc
  135. static inline int arch_io_reserve_memtype_wc(resource_size_t base,
  136. resource_size_t size)
  137. {
  138. return 0;
  139. }
  140. static inline void arch_io_free_memtype_wc(resource_size_t base,
  141. resource_size_t size)
  142. {
  143. }
  144. #endif
  145. #endif /* _LINUX_IO_H */