io.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright 2006 PathScale, Inc. All Rights Reserved.
  4. */
  5. #ifndef _LINUX_IO_H
  6. #define _LINUX_IO_H
  7. #include <linux/types.h>
  8. #include <linux/init.h>
  9. #include <linux/bug.h>
  10. #include <linux/err.h>
  11. #include <asm/io.h>
  12. #include <asm/page.h>
  13. struct device;
  14. struct resource;
  15. __visible void __iowrite32_copy(void __iomem *to, const void *from, size_t count);
  16. void __ioread32_copy(void *to, const void __iomem *from, size_t count);
  17. void __iowrite64_copy(void __iomem *to, const void *from, size_t count);
  18. #ifdef CONFIG_MMU
  19. void ioremap_phys_range_hook(phys_addr_t phys_addr, size_t size, pgprot_t prot);
  20. void iounmap_phys_range_hook(phys_addr_t phys_addr, size_t size);
  21. int ioremap_page_range(unsigned long addr, unsigned long end,
  22. phys_addr_t phys_addr, pgprot_t prot);
  23. #else
  24. static inline int ioremap_page_range(unsigned long addr, unsigned long end,
  25. phys_addr_t phys_addr, pgprot_t prot)
  26. {
  27. return 0;
  28. }
  29. #endif
  30. /*
  31. * Managed iomap interface
  32. */
  33. #ifdef CONFIG_HAS_IOPORT_MAP
  34. void __iomem * devm_ioport_map(struct device *dev, unsigned long port,
  35. unsigned int nr);
  36. void devm_ioport_unmap(struct device *dev, void __iomem *addr);
  37. #else
  38. static inline void __iomem *devm_ioport_map(struct device *dev,
  39. unsigned long port,
  40. unsigned int nr)
  41. {
  42. return NULL;
  43. }
  44. static inline void devm_ioport_unmap(struct device *dev, void __iomem *addr)
  45. {
  46. }
  47. #endif
  48. #define IOMEM_ERR_PTR(err) (__force void __iomem *)ERR_PTR(err)
  49. void __iomem *devm_ioremap(struct device *dev, resource_size_t offset,
  50. resource_size_t size);
  51. void __iomem *devm_ioremap_uc(struct device *dev, resource_size_t offset,
  52. resource_size_t size);
  53. void __iomem *devm_ioremap_wc(struct device *dev, resource_size_t offset,
  54. resource_size_t size);
  55. void devm_iounmap(struct device *dev, void __iomem *addr);
  56. int check_signature(const volatile void __iomem *io_addr,
  57. const unsigned char *signature, int length);
  58. void devm_ioremap_release(struct device *dev, void *res);
  59. void *devm_memremap(struct device *dev, resource_size_t offset,
  60. size_t size, unsigned long flags);
  61. void devm_memunmap(struct device *dev, void *addr);
  62. #ifdef CONFIG_PCI
  63. /*
  64. * The PCI specifications (Rev 3.0, 3.2.5 "Transaction Ordering and
  65. * Posting") mandate non-posted configuration transactions. This default
  66. * implementation attempts to use the ioremap_np() API to provide this
  67. * on arches that support it, and falls back to ioremap() on those that
  68. * don't. Overriding this function is deprecated; arches that properly
  69. * support non-posted accesses should implement ioremap_np() instead, which
  70. * this default implementation can then use to return mappings compliant with
  71. * the PCI specification.
  72. */
  73. #ifndef pci_remap_cfgspace
  74. #define pci_remap_cfgspace pci_remap_cfgspace
  75. static inline void __iomem *pci_remap_cfgspace(phys_addr_t offset,
  76. size_t size)
  77. {
  78. return ioremap_np(offset, size) ?: ioremap(offset, size);
  79. }
  80. #endif
  81. #endif
  82. /*
  83. * Some systems do not have legacy ISA devices.
  84. * /dev/port is not a valid interface on these systems.
  85. * So for those archs, <asm/io.h> should define the following symbol.
  86. */
  87. #ifndef arch_has_dev_port
  88. #define arch_has_dev_port() (1)
  89. #endif
  90. /*
  91. * Some systems (x86 without PAT) have a somewhat reliable way to mark a
  92. * physical address range such that uncached mappings will actually
  93. * end up write-combining. This facility should be used in conjunction
  94. * with pgprot_writecombine, ioremap-wc, or set_memory_wc, since it has
  95. * no effect if the per-page mechanisms are functional.
  96. * (On x86 without PAT, these functions manipulate MTRRs.)
  97. *
  98. * arch_phys_del_wc(0) or arch_phys_del_wc(any error code) is guaranteed
  99. * to have no effect.
  100. */
  101. #ifndef arch_phys_wc_add
  102. static inline int __must_check arch_phys_wc_add(unsigned long base,
  103. unsigned long size)
  104. {
  105. return 0; /* It worked (i.e. did nothing). */
  106. }
  107. static inline void arch_phys_wc_del(int handle)
  108. {
  109. }
  110. #define arch_phys_wc_add arch_phys_wc_add
  111. #ifndef arch_phys_wc_index
  112. static inline int arch_phys_wc_index(int handle)
  113. {
  114. return -1;
  115. }
  116. #define arch_phys_wc_index arch_phys_wc_index
  117. #endif
  118. #endif
  119. int devm_arch_phys_wc_add(struct device *dev, unsigned long base, unsigned long size);
  120. enum {
  121. /* See memremap() kernel-doc for usage description... */
  122. MEMREMAP_WB = 1 << 0,
  123. MEMREMAP_WT = 1 << 1,
  124. MEMREMAP_WC = 1 << 2,
  125. MEMREMAP_ENC = 1 << 3,
  126. MEMREMAP_DEC = 1 << 4,
  127. };
  128. void *memremap(resource_size_t offset, size_t size, unsigned long flags);
  129. void memunmap(void *addr);
  130. /*
  131. * On x86 PAT systems we have memory tracking that keeps track of
  132. * the allowed mappings on memory ranges. This tracking works for
  133. * all the in-kernel mapping APIs (ioremap*), but where the user
  134. * wishes to map a range from a physical device into user memory
  135. * the tracking won't be updated. This API is to be used by
  136. * drivers which remap physical device pages into userspace,
  137. * and wants to make sure they are mapped WC and not UC.
  138. */
  139. #ifndef arch_io_reserve_memtype_wc
  140. static inline int arch_io_reserve_memtype_wc(resource_size_t base,
  141. resource_size_t size)
  142. {
  143. return 0;
  144. }
  145. static inline void arch_io_free_memtype_wc(resource_size_t base,
  146. resource_size_t size)
  147. {
  148. }
  149. #endif
  150. int devm_arch_io_reserve_memtype_wc(struct device *dev, resource_size_t start,
  151. resource_size_t size);
  152. #endif /* _LINUX_IO_H */