io.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. #include <asm/firmware.h>
  25. #include <asm/bug.h>
  26. void _insb(volatile u8 __iomem *port, void *buf, long count)
  27. {
  28. u8 *tbuf = buf;
  29. u8 tmp;
  30. BUG_ON(firmware_has_feature(FW_FEATURE_ISERIES));
  31. if (unlikely(count <= 0))
  32. return;
  33. asm volatile("sync");
  34. do {
  35. tmp = *port;
  36. asm volatile("eieio");
  37. *tbuf++ = tmp;
  38. } while (--count != 0);
  39. asm volatile("twi 0,%0,0; isync" : : "r" (tmp));
  40. }
  41. EXPORT_SYMBOL(_insb);
  42. void _outsb(volatile u8 __iomem *port, const void *buf, long count)
  43. {
  44. const u8 *tbuf = buf;
  45. BUG_ON(firmware_has_feature(FW_FEATURE_ISERIES));
  46. if (unlikely(count <= 0))
  47. return;
  48. asm volatile("sync");
  49. do {
  50. *port = *tbuf++;
  51. } while (--count != 0);
  52. asm volatile("sync");
  53. }
  54. EXPORT_SYMBOL(_outsb);
  55. void _insw_ns(volatile u16 __iomem *port, void *buf, long count)
  56. {
  57. u16 *tbuf = buf;
  58. u16 tmp;
  59. BUG_ON(firmware_has_feature(FW_FEATURE_ISERIES));
  60. if (unlikely(count <= 0))
  61. return;
  62. asm volatile("sync");
  63. do {
  64. tmp = *port;
  65. asm volatile("eieio");
  66. *tbuf++ = tmp;
  67. } while (--count != 0);
  68. asm volatile("twi 0,%0,0; isync" : : "r" (tmp));
  69. }
  70. EXPORT_SYMBOL(_insw_ns);
  71. void _outsw_ns(volatile u16 __iomem *port, const void *buf, long count)
  72. {
  73. const u16 *tbuf = buf;
  74. BUG_ON(firmware_has_feature(FW_FEATURE_ISERIES));
  75. if (unlikely(count <= 0))
  76. return;
  77. asm volatile("sync");
  78. do {
  79. *port = *tbuf++;
  80. } while (--count != 0);
  81. asm volatile("sync");
  82. }
  83. EXPORT_SYMBOL(_outsw_ns);
  84. void _insl_ns(volatile u32 __iomem *port, void *buf, long count)
  85. {
  86. u32 *tbuf = buf;
  87. u32 tmp;
  88. BUG_ON(firmware_has_feature(FW_FEATURE_ISERIES));
  89. if (unlikely(count <= 0))
  90. return;
  91. asm volatile("sync");
  92. do {
  93. tmp = *port;
  94. asm volatile("eieio");
  95. *tbuf++ = tmp;
  96. } while (--count != 0);
  97. asm volatile("twi 0,%0,0; isync" : : "r" (tmp));
  98. }
  99. EXPORT_SYMBOL(_insl_ns);
  100. void _outsl_ns(volatile u32 __iomem *port, const void *buf, long count)
  101. {
  102. const u32 *tbuf = buf;
  103. BUG_ON(firmware_has_feature(FW_FEATURE_ISERIES));
  104. if (unlikely(count <= 0))
  105. return;
  106. asm volatile("sync");
  107. do {
  108. *port = *tbuf++;
  109. } while (--count != 0);
  110. asm volatile("sync");
  111. }
  112. EXPORT_SYMBOL(_outsl_ns);