iomap.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * arch/sh/kernel/iomap.c
  3. *
  4. * Copyright (C) 2000 Niibe Yutaka
  5. * Copyright (C) 2005 - 2007 Paul Mundt
  6. *
  7. * This file is subject to the terms and conditions of the GNU General Public
  8. * License. See the file "COPYING" in the main directory of this archive
  9. * for more details.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/io.h>
  13. unsigned int ioread8(void __iomem *addr)
  14. {
  15. return readb(addr);
  16. }
  17. EXPORT_SYMBOL(ioread8);
  18. unsigned int ioread16(void __iomem *addr)
  19. {
  20. return readw(addr);
  21. }
  22. EXPORT_SYMBOL(ioread16);
  23. unsigned int ioread16be(void __iomem *addr)
  24. {
  25. return be16_to_cpu(__raw_readw(addr));
  26. }
  27. EXPORT_SYMBOL(ioread16be);
  28. unsigned int ioread32(void __iomem *addr)
  29. {
  30. return readl(addr);
  31. }
  32. EXPORT_SYMBOL(ioread32);
  33. unsigned int ioread32be(void __iomem *addr)
  34. {
  35. return be32_to_cpu(__raw_readl(addr));
  36. }
  37. EXPORT_SYMBOL(ioread32be);
  38. void iowrite8(u8 val, void __iomem *addr)
  39. {
  40. writeb(val, addr);
  41. }
  42. EXPORT_SYMBOL(iowrite8);
  43. void iowrite16(u16 val, void __iomem *addr)
  44. {
  45. writew(val, addr);
  46. }
  47. EXPORT_SYMBOL(iowrite16);
  48. void iowrite16be(u16 val, void __iomem *addr)
  49. {
  50. __raw_writew(cpu_to_be16(val), addr);
  51. }
  52. EXPORT_SYMBOL(iowrite16be);
  53. void iowrite32(u32 val, void __iomem *addr)
  54. {
  55. writel(val, addr);
  56. }
  57. EXPORT_SYMBOL(iowrite32);
  58. void iowrite32be(u32 val, void __iomem *addr)
  59. {
  60. __raw_writel(cpu_to_be32(val), addr);
  61. }
  62. EXPORT_SYMBOL(iowrite32be);
  63. /*
  64. * These are the "repeat MMIO read/write" functions.
  65. * Note the "__raw" accesses, since we don't want to
  66. * convert to CPU byte order. We write in "IO byte
  67. * order" (we also don't have IO barriers).
  68. */
  69. static inline void mmio_insb(void __iomem *addr, u8 *dst, int count)
  70. {
  71. while (--count >= 0) {
  72. u8 data = __raw_readb(addr);
  73. *dst = data;
  74. dst++;
  75. }
  76. }
  77. static inline void mmio_insw(void __iomem *addr, u16 *dst, int count)
  78. {
  79. while (--count >= 0) {
  80. u16 data = __raw_readw(addr);
  81. *dst = data;
  82. dst++;
  83. }
  84. }
  85. static inline void mmio_insl(void __iomem *addr, u32 *dst, int count)
  86. {
  87. while (--count >= 0) {
  88. u32 data = __raw_readl(addr);
  89. *dst = data;
  90. dst++;
  91. }
  92. }
  93. static inline void mmio_outsb(void __iomem *addr, const u8 *src, int count)
  94. {
  95. while (--count >= 0) {
  96. __raw_writeb(*src, addr);
  97. src++;
  98. }
  99. }
  100. static inline void mmio_outsw(void __iomem *addr, const u16 *src, int count)
  101. {
  102. while (--count >= 0) {
  103. __raw_writew(*src, addr);
  104. src++;
  105. }
  106. }
  107. static inline void mmio_outsl(void __iomem *addr, const u32 *src, int count)
  108. {
  109. while (--count >= 0) {
  110. __raw_writel(*src, addr);
  111. src++;
  112. }
  113. }
  114. void ioread8_rep(void __iomem *addr, void *dst, unsigned long count)
  115. {
  116. mmio_insb(addr, dst, count);
  117. }
  118. EXPORT_SYMBOL(ioread8_rep);
  119. void ioread16_rep(void __iomem *addr, void *dst, unsigned long count)
  120. {
  121. mmio_insw(addr, dst, count);
  122. }
  123. EXPORT_SYMBOL(ioread16_rep);
  124. void ioread32_rep(void __iomem *addr, void *dst, unsigned long count)
  125. {
  126. mmio_insl(addr, dst, count);
  127. }
  128. EXPORT_SYMBOL(ioread32_rep);
  129. void iowrite8_rep(void __iomem *addr, const void *src, unsigned long count)
  130. {
  131. mmio_outsb(addr, src, count);
  132. }
  133. EXPORT_SYMBOL(iowrite8_rep);
  134. void iowrite16_rep(void __iomem *addr, const void *src, unsigned long count)
  135. {
  136. mmio_outsw(addr, src, count);
  137. }
  138. EXPORT_SYMBOL(iowrite16_rep);
  139. void iowrite32_rep(void __iomem *addr, const void *src, unsigned long count)
  140. {
  141. mmio_outsl(addr, src, count);
  142. }
  143. EXPORT_SYMBOL(iowrite32_rep);