io.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * Copyright (C) 2000 David J. Mckay (david.mckay@st.com)
  3. *
  4. * May be copied or modified under the terms of the GNU General Public
  5. * License. See linux/COPYING for more information.
  6. *
  7. * This file contains the I/O routines for use on the overdrive board
  8. *
  9. */
  10. #include <linux/kernel.h>
  11. #include <linux/types.h>
  12. #include <linux/delay.h>
  13. #include <linux/module.h>
  14. #include <asm/system.h>
  15. #include <asm/processor.h>
  16. #include <asm/io.h>
  17. /* Now for the string version of these functions */
  18. void outsb(unsigned long port, const void *addr, unsigned long count)
  19. {
  20. int i;
  21. unsigned char *p = (unsigned char *) addr;
  22. for (i = 0; i < count; i++, p++) {
  23. outb(*p, port);
  24. }
  25. }
  26. EXPORT_SYMBOL(outsb);
  27. void insb(unsigned long port, void *addr, unsigned long count)
  28. {
  29. int i;
  30. unsigned char *p = (unsigned char *) addr;
  31. for (i = 0; i < count; i++, p++) {
  32. *p = inb(port);
  33. }
  34. }
  35. EXPORT_SYMBOL(insb);
  36. /* For the 16 and 32 bit string functions, we have to worry about alignment.
  37. * The SH does not do unaligned accesses, so we have to read as bytes and
  38. * then write as a word or dword.
  39. * This can be optimised a lot more, especially in the case where the data
  40. * is aligned
  41. */
  42. void outsw(unsigned long port, const void *addr, unsigned long count)
  43. {
  44. int i;
  45. unsigned short tmp;
  46. unsigned char *p = (unsigned char *) addr;
  47. for (i = 0; i < count; i++, p += 2) {
  48. tmp = (*p) | ((*(p + 1)) << 8);
  49. outw(tmp, port);
  50. }
  51. }
  52. EXPORT_SYMBOL(outsw);
  53. void insw(unsigned long port, void *addr, unsigned long count)
  54. {
  55. int i;
  56. unsigned short tmp;
  57. unsigned char *p = (unsigned char *) addr;
  58. for (i = 0; i < count; i++, p += 2) {
  59. tmp = inw(port);
  60. p[0] = tmp & 0xff;
  61. p[1] = (tmp >> 8) & 0xff;
  62. }
  63. }
  64. EXPORT_SYMBOL(insw);
  65. void outsl(unsigned long port, const void *addr, unsigned long count)
  66. {
  67. int i;
  68. unsigned tmp;
  69. unsigned char *p = (unsigned char *) addr;
  70. for (i = 0; i < count; i++, p += 4) {
  71. tmp = (*p) | ((*(p + 1)) << 8) | ((*(p + 2)) << 16) |
  72. ((*(p + 3)) << 24);
  73. outl(tmp, port);
  74. }
  75. }
  76. EXPORT_SYMBOL(outsl);
  77. void insl(unsigned long port, void *addr, unsigned long count)
  78. {
  79. int i;
  80. unsigned tmp;
  81. unsigned char *p = (unsigned char *) addr;
  82. for (i = 0; i < count; i++, p += 4) {
  83. tmp = inl(port);
  84. p[0] = tmp & 0xff;
  85. p[1] = (tmp >> 8) & 0xff;
  86. p[2] = (tmp >> 16) & 0xff;
  87. p[3] = (tmp >> 24) & 0xff;
  88. }
  89. }
  90. EXPORT_SYMBOL(insl);
  91. void memcpy_toio(void __iomem *to, const void *from, long count)
  92. {
  93. unsigned char *p = (unsigned char *) from;
  94. while (count) {
  95. count--;
  96. writeb(*p++, to++);
  97. }
  98. }
  99. EXPORT_SYMBOL(memcpy_toio);
  100. void memcpy_fromio(void *to, void __iomem *from, long count)
  101. {
  102. int i;
  103. unsigned char *p = (unsigned char *) to;
  104. for (i = 0; i < count; i++) {
  105. p[i] = readb(from);
  106. from++;
  107. }
  108. }
  109. EXPORT_SYMBOL(memcpy_fromio);