io.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. /*
  2. * linux/arch/sh/kernel/io.c
  3. *
  4. * Copyright (C) 2000 Stuart Menefy
  5. * Copyright (C) 2005 Paul Mundt
  6. *
  7. * Provide real functions which expand to whatever the header file defined.
  8. * Also definitions of machine independent IO functions.
  9. *
  10. * This file is subject to the terms and conditions of the GNU General Public
  11. * License. See the file "COPYING" in the main directory of this archive
  12. * for more details.
  13. */
  14. #include <linux/module.h>
  15. #include <asm/machvec.h>
  16. #include <asm/io.h>
  17. /*
  18. * Copy data from IO memory space to "real" memory space.
  19. * This needs to be optimized.
  20. */
  21. void memcpy_fromio(void *to, volatile void __iomem *from, unsigned long count)
  22. {
  23. char *p = to;
  24. while (count) {
  25. count--;
  26. *p = readb((void __iomem *)from);
  27. p++;
  28. from++;
  29. }
  30. }
  31. EXPORT_SYMBOL(memcpy_fromio);
  32. /*
  33. * Copy data from "real" memory space to IO memory space.
  34. * This needs to be optimized.
  35. */
  36. void memcpy_toio(volatile void __iomem *to, const void *from, unsigned long count)
  37. {
  38. const char *p = from;
  39. while (count) {
  40. count--;
  41. writeb(*p, (void __iomem *)to);
  42. p++;
  43. to++;
  44. }
  45. }
  46. EXPORT_SYMBOL(memcpy_toio);
  47. /*
  48. * "memset" on IO memory space.
  49. * This needs to be optimized.
  50. */
  51. void memset_io(volatile void __iomem *dst, int c, unsigned long count)
  52. {
  53. while (count) {
  54. count--;
  55. writeb(c, (void __iomem *)dst);
  56. dst++;
  57. }
  58. }
  59. EXPORT_SYMBOL(memset_io);
  60. void __raw_readsl(unsigned long addr, void *datap, int len)
  61. {
  62. u32 *data;
  63. for (data = datap; (len != 0) && (((u32)data & 0x1f) != 0); len--)
  64. *data++ = ctrl_inl(addr);
  65. if (likely(len >= (0x20 >> 2))) {
  66. int tmp2, tmp3, tmp4, tmp5, tmp6;
  67. __asm__ __volatile__(
  68. "1: \n\t"
  69. "mov.l @%7, r0 \n\t"
  70. "mov.l @%7, %2 \n\t"
  71. #ifdef CONFIG_CPU_SH4
  72. "movca.l r0, @%0 \n\t"
  73. #else
  74. "mov.l r0, @%0 \n\t"
  75. #endif
  76. "mov.l @%7, %3 \n\t"
  77. "mov.l @%7, %4 \n\t"
  78. "mov.l @%7, %5 \n\t"
  79. "mov.l @%7, %6 \n\t"
  80. "mov.l @%7, r7 \n\t"
  81. "mov.l @%7, r0 \n\t"
  82. "mov.l %2, @(0x04,%0) \n\t"
  83. "mov #0x20>>2, %2 \n\t"
  84. "mov.l %3, @(0x08,%0) \n\t"
  85. "sub %2, %1 \n\t"
  86. "mov.l %4, @(0x0c,%0) \n\t"
  87. "cmp/hi %1, %2 ! T if 32 > len \n\t"
  88. "mov.l %5, @(0x10,%0) \n\t"
  89. "mov.l %6, @(0x14,%0) \n\t"
  90. "mov.l r7, @(0x18,%0) \n\t"
  91. "mov.l r0, @(0x1c,%0) \n\t"
  92. "bf.s 1b \n\t"
  93. " add #0x20, %0 \n\t"
  94. : "=&r" (data), "=&r" (len),
  95. "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4),
  96. "=&r" (tmp5), "=&r" (tmp6)
  97. : "r"(addr), "0" (data), "1" (len)
  98. : "r0", "r7", "t", "memory");
  99. }
  100. for (; len != 0; len--)
  101. *data++ = ctrl_inl(addr);
  102. }
  103. EXPORT_SYMBOL(__raw_readsl);
  104. void __raw_writesl(unsigned long addr, const void *data, int len)
  105. {
  106. if (likely(len != 0)) {
  107. int tmp1;
  108. __asm__ __volatile__ (
  109. "1: \n\t"
  110. "mov.l @%0+, %1 \n\t"
  111. "dt %3 \n\t"
  112. "bf.s 1b \n\t"
  113. " mov.l %1, @%4 \n\t"
  114. : "=&r" (data), "=&r" (tmp1)
  115. : "0" (data), "r" (len), "r"(addr)
  116. : "t", "memory");
  117. }
  118. }
  119. EXPORT_SYMBOL(__raw_writesl);
  120. void __iomem *ioport_map(unsigned long port, unsigned int nr)
  121. {
  122. return sh_mv.mv_ioport_map(port, nr);
  123. }
  124. EXPORT_SYMBOL(ioport_map);
  125. void ioport_unmap(void __iomem *addr)
  126. {
  127. sh_mv.mv_ioport_unmap(addr);
  128. }
  129. EXPORT_SYMBOL(ioport_unmap);