iomap.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef __GENERIC_IO_H
  3. #define __GENERIC_IO_H
  4. #include <linux/linkage.h>
  5. #include <asm/byteorder.h>
  6. /*
  7. * These are the "generic" interfaces for doing new-style
  8. * memory-mapped or PIO accesses. Architectures may do
  9. * their own arch-optimized versions, these just act as
  10. * wrappers around the old-style IO register access functions:
  11. * read[bwl]/write[bwl]/in[bwl]/out[bwl]
  12. *
  13. * Don't include this directly, include it from <asm/io.h>.
  14. */
  15. /*
  16. * Read/write from/to an (offsettable) iomem cookie. It might be a PIO
  17. * access or a MMIO access, these functions don't care. The info is
  18. * encoded in the hardware mapping set up by the mapping functions
  19. * (or the cookie itself, depending on implementation and hw).
  20. *
  21. * The generic routines just encode the PIO/MMIO as part of the
  22. * cookie, and coldly assume that the MMIO IO mappings are not
  23. * in the low address range. Architectures for which this is not
  24. * true can't use this generic implementation.
  25. */
  26. extern unsigned int ioread8(const void __iomem *);
  27. extern unsigned int ioread16(const void __iomem *);
  28. extern unsigned int ioread16be(const void __iomem *);
  29. extern unsigned int ioread32(const void __iomem *);
  30. extern unsigned int ioread32be(const void __iomem *);
  31. #ifdef CONFIG_64BIT
  32. extern u64 ioread64(const void __iomem *);
  33. extern u64 ioread64be(const void __iomem *);
  34. #endif
  35. #ifdef readq
  36. #define ioread64_lo_hi ioread64_lo_hi
  37. #define ioread64_hi_lo ioread64_hi_lo
  38. #define ioread64be_lo_hi ioread64be_lo_hi
  39. #define ioread64be_hi_lo ioread64be_hi_lo
  40. extern u64 ioread64_lo_hi(const void __iomem *addr);
  41. extern u64 ioread64_hi_lo(const void __iomem *addr);
  42. extern u64 ioread64be_lo_hi(const void __iomem *addr);
  43. extern u64 ioread64be_hi_lo(const void __iomem *addr);
  44. #endif
  45. extern void iowrite8(u8, void __iomem *);
  46. extern void iowrite16(u16, void __iomem *);
  47. extern void iowrite16be(u16, void __iomem *);
  48. extern void iowrite32(u32, void __iomem *);
  49. extern void iowrite32be(u32, void __iomem *);
  50. #ifdef CONFIG_64BIT
  51. extern void iowrite64(u64, void __iomem *);
  52. extern void iowrite64be(u64, void __iomem *);
  53. #endif
  54. #ifdef writeq
  55. #define iowrite64_lo_hi iowrite64_lo_hi
  56. #define iowrite64_hi_lo iowrite64_hi_lo
  57. #define iowrite64be_lo_hi iowrite64be_lo_hi
  58. #define iowrite64be_hi_lo iowrite64be_hi_lo
  59. extern void iowrite64_lo_hi(u64 val, void __iomem *addr);
  60. extern void iowrite64_hi_lo(u64 val, void __iomem *addr);
  61. extern void iowrite64be_lo_hi(u64 val, void __iomem *addr);
  62. extern void iowrite64be_hi_lo(u64 val, void __iomem *addr);
  63. #endif
  64. /*
  65. * "string" versions of the above. Note that they
  66. * use native byte ordering for the accesses (on
  67. * the assumption that IO and memory agree on a
  68. * byte order, and CPU byteorder is irrelevant).
  69. *
  70. * They do _not_ update the port address. If you
  71. * want MMIO that copies stuff laid out in MMIO
  72. * memory across multiple ports, use "memcpy_toio()"
  73. * and friends.
  74. */
  75. extern void ioread8_rep(const void __iomem *port, void *buf, unsigned long count);
  76. extern void ioread16_rep(const void __iomem *port, void *buf, unsigned long count);
  77. extern void ioread32_rep(const void __iomem *port, void *buf, unsigned long count);
  78. extern void iowrite8_rep(void __iomem *port, const void *buf, unsigned long count);
  79. extern void iowrite16_rep(void __iomem *port, const void *buf, unsigned long count);
  80. extern void iowrite32_rep(void __iomem *port, const void *buf, unsigned long count);
  81. #ifdef CONFIG_HAS_IOPORT_MAP
  82. /* Create a virtual mapping cookie for an IO port range */
  83. extern void __iomem *ioport_map(unsigned long port, unsigned int nr);
  84. extern void ioport_unmap(void __iomem *);
  85. #endif
  86. #ifndef ARCH_HAS_IOREMAP_WC
  87. #define ioremap_wc ioremap
  88. #endif
  89. #ifndef ARCH_HAS_IOREMAP_WT
  90. #define ioremap_wt ioremap
  91. #endif
  92. #ifndef ARCH_HAS_IOREMAP_NP
  93. /* See the comment in asm-generic/io.h about ioremap_np(). */
  94. #define ioremap_np ioremap_np
  95. static inline void __iomem *ioremap_np(phys_addr_t offset, size_t size)
  96. {
  97. return NULL;
  98. }
  99. #endif
  100. #include <asm-generic/pci_iomap.h>
  101. #endif