io.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * I/O string operations
  3. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  4. * Copyright (C) 2006 IBM Corporation
  5. *
  6. * Largely rewritten by Cort Dougan (cort@cs.nmt.edu)
  7. * and Paul Mackerras.
  8. *
  9. * Adapted for iSeries by Mike Corrigan (mikejc@us.ibm.com)
  10. * PPC64 updates by Dave Engebretsen (engebret@us.ibm.com)
  11. *
  12. * Rewritten in C by Stephen Rothwell.
  13. *
  14. * This program is free software; you can redistribute it and/or
  15. * modify it under the terms of the GNU General Public License
  16. * as published by the Free Software Foundation; either version
  17. * 2 of the License, or (at your option) any later version.
  18. */
  19. #include <linux/kernel.h>
  20. #include <linux/types.h>
  21. #include <linux/compiler.h>
  22. #include <linux/module.h>
  23. #include <asm/io.h>
  24. void _insb(volatile u8 __iomem *port, void *buf, long count)
  25. {
  26. u8 *tbuf = buf;
  27. u8 tmp;
  28. if (unlikely(count <= 0))
  29. return;
  30. asm volatile("sync");
  31. do {
  32. tmp = *port;
  33. asm volatile("eieio");
  34. *tbuf++ = tmp;
  35. } while (--count != 0);
  36. asm volatile("twi 0,%0,0; isync" : : "r" (tmp));
  37. }
  38. EXPORT_SYMBOL(_insb);
  39. void _outsb(volatile u8 __iomem *port, const void *buf, long count)
  40. {
  41. const u8 *tbuf = buf;
  42. if (unlikely(count <= 0))
  43. return;
  44. asm volatile("sync");
  45. do {
  46. *port = *tbuf++;
  47. } while (--count != 0);
  48. asm volatile("sync");
  49. }
  50. EXPORT_SYMBOL(_outsb);
  51. void _insw_ns(volatile u16 __iomem *port, void *buf, long count)
  52. {
  53. u16 *tbuf = buf;
  54. u16 tmp;
  55. if (unlikely(count <= 0))
  56. return;
  57. asm volatile("sync");
  58. do {
  59. tmp = *port;
  60. asm volatile("eieio");
  61. *tbuf++ = tmp;
  62. } while (--count != 0);
  63. asm volatile("twi 0,%0,0; isync" : : "r" (tmp));
  64. }
  65. EXPORT_SYMBOL(_insw_ns);
  66. void _outsw_ns(volatile u16 __iomem *port, const void *buf, long count)
  67. {
  68. const u16 *tbuf = buf;
  69. if (unlikely(count <= 0))
  70. return;
  71. asm volatile("sync");
  72. do {
  73. *port = *tbuf++;
  74. } while (--count != 0);
  75. asm volatile("sync");
  76. }
  77. EXPORT_SYMBOL(_outsw_ns);
  78. void _insl_ns(volatile u32 __iomem *port, void *buf, long count)
  79. {
  80. u32 *tbuf = buf;
  81. u32 tmp;
  82. if (unlikely(count <= 0))
  83. return;
  84. asm volatile("sync");
  85. do {
  86. tmp = *port;
  87. asm volatile("eieio");
  88. *tbuf++ = tmp;
  89. } while (--count != 0);
  90. asm volatile("twi 0,%0,0; isync" : : "r" (tmp));
  91. }
  92. EXPORT_SYMBOL(_insl_ns);
  93. void _outsl_ns(volatile u32 __iomem *port, const void *buf, long count)
  94. {
  95. const u32 *tbuf = buf;
  96. if (unlikely(count <= 0))
  97. return;
  98. asm volatile("sync");
  99. do {
  100. *port = *tbuf++;
  101. } while (--count != 0);
  102. asm volatile("sync");
  103. }
  104. EXPORT_SYMBOL(_outsl_ns);