io.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * arch/sh/kernel/io.c - Machine independent I/O functions.
  3. *
  4. * Copyright (C) 2000 - 2009 Stuart Menefy
  5. * Copyright (C) 2005 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/pci.h>
  13. #include <asm/machvec.h>
  14. #include <asm/io.h>
  15. /*
  16. * Copy data from IO memory space to "real" memory space.
  17. */
  18. void memcpy_fromio(void *to, const volatile void __iomem *from, unsigned long count)
  19. {
  20. /*
  21. * Would it be worthwhile doing byte and long transfers first
  22. * to try and get aligned?
  23. */
  24. #ifdef CONFIG_CPU_SH4
  25. if ((count >= 0x20) &&
  26. (((u32)to & 0x1f) == 0) && (((u32)from & 0x3) == 0)) {
  27. int tmp2, tmp3, tmp4, tmp5, tmp6;
  28. __asm__ __volatile__(
  29. "1: \n\t"
  30. "mov.l @%7+, r0 \n\t"
  31. "mov.l @%7+, %2 \n\t"
  32. "movca.l r0, @%0 \n\t"
  33. "mov.l @%7+, %3 \n\t"
  34. "mov.l @%7+, %4 \n\t"
  35. "mov.l @%7+, %5 \n\t"
  36. "mov.l @%7+, %6 \n\t"
  37. "mov.l @%7+, r7 \n\t"
  38. "mov.l @%7+, r0 \n\t"
  39. "mov.l %2, @(0x04,%0) \n\t"
  40. "mov #0x20, %2 \n\t"
  41. "mov.l %3, @(0x08,%0) \n\t"
  42. "sub %2, %1 \n\t"
  43. "mov.l %4, @(0x0c,%0) \n\t"
  44. "cmp/hi %1, %2 ! T if 32 > count \n\t"
  45. "mov.l %5, @(0x10,%0) \n\t"
  46. "mov.l %6, @(0x14,%0) \n\t"
  47. "mov.l r7, @(0x18,%0) \n\t"
  48. "mov.l r0, @(0x1c,%0) \n\t"
  49. "bf.s 1b \n\t"
  50. " add #0x20, %0 \n\t"
  51. : "=&r" (to), "=&r" (count),
  52. "=&r" (tmp2), "=&r" (tmp3), "=&r" (tmp4),
  53. "=&r" (tmp5), "=&r" (tmp6), "=&r" (from)
  54. : "7"(from), "0" (to), "1" (count)
  55. : "r0", "r7", "t", "memory");
  56. }
  57. #endif
  58. if ((((u32)to | (u32)from) & 0x3) == 0) {
  59. for (; count > 3; count -= 4) {
  60. *(u32 *)to = *(volatile u32 *)from;
  61. to += 4;
  62. from += 4;
  63. }
  64. }
  65. for (; count > 0; count--) {
  66. *(u8 *)to = *(volatile u8 *)from;
  67. to++;
  68. from++;
  69. }
  70. mb();
  71. }
  72. EXPORT_SYMBOL(memcpy_fromio);
  73. /*
  74. * Copy data from "real" memory space to IO memory space.
  75. */
  76. void memcpy_toio(volatile void __iomem *to, const void *from, unsigned long count)
  77. {
  78. if ((((u32)to | (u32)from) & 0x3) == 0) {
  79. for ( ; count > 3; count -= 4) {
  80. *(volatile u32 *)to = *(u32 *)from;
  81. to += 4;
  82. from += 4;
  83. }
  84. }
  85. for (; count > 0; count--) {
  86. *(volatile u8 *)to = *(u8 *)from;
  87. to++;
  88. from++;
  89. }
  90. mb();
  91. }
  92. EXPORT_SYMBOL(memcpy_toio);
  93. /*
  94. * "memset" on IO memory space.
  95. * This needs to be optimized.
  96. */
  97. void memset_io(volatile void __iomem *dst, int c, unsigned long count)
  98. {
  99. while (count) {
  100. count--;
  101. writeb(c, dst);
  102. dst++;
  103. }
  104. }
  105. EXPORT_SYMBOL(memset_io);