io.c 2.4 KB

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