dma-isa.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. /*
  2. * linux/arch/arm/kernel/dma-isa.c
  3. *
  4. * Copyright (C) 1999-2000 Russell King
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * ISA DMA primitives
  11. * Taken from various sources, including:
  12. * linux/include/asm/dma.h: Defines for using and allocating dma channels.
  13. * Written by Hennus Bergman, 1992.
  14. * High DMA channel support & info by Hannu Savolainen and John Boyd,
  15. * Nov. 1992.
  16. * arch/arm/kernel/dma-ebsa285.c
  17. * Copyright (C) 1998 Phil Blundell
  18. */
  19. #include <linux/ioport.h>
  20. #include <linux/init.h>
  21. #include <linux/pci.h>
  22. #include <asm/dma.h>
  23. #include <asm/io.h>
  24. #include <asm/mach/dma.h>
  25. #define ISA_DMA_MODE_READ 0x44
  26. #define ISA_DMA_MODE_WRITE 0x48
  27. #define ISA_DMA_MODE_CASCADE 0xc0
  28. #define ISA_DMA_AUTOINIT 0x10
  29. #define ISA_DMA_MASK 0
  30. #define ISA_DMA_MODE 1
  31. #define ISA_DMA_CLRFF 2
  32. #define ISA_DMA_PGHI 3
  33. #define ISA_DMA_PGLO 4
  34. #define ISA_DMA_ADDR 5
  35. #define ISA_DMA_COUNT 6
  36. static unsigned int isa_dma_port[8][7] = {
  37. /* MASK MODE CLRFF PAGE_HI PAGE_LO ADDR COUNT */
  38. { 0x0a, 0x0b, 0x0c, 0x487, 0x087, 0x00, 0x01 },
  39. { 0x0a, 0x0b, 0x0c, 0x483, 0x083, 0x02, 0x03 },
  40. { 0x0a, 0x0b, 0x0c, 0x481, 0x081, 0x04, 0x05 },
  41. { 0x0a, 0x0b, 0x0c, 0x482, 0x082, 0x06, 0x07 },
  42. { 0xd4, 0xd6, 0xd8, 0x000, 0x000, 0xc0, 0xc2 },
  43. { 0xd4, 0xd6, 0xd8, 0x48b, 0x08b, 0xc4, 0xc6 },
  44. { 0xd4, 0xd6, 0xd8, 0x489, 0x089, 0xc8, 0xca },
  45. { 0xd4, 0xd6, 0xd8, 0x48a, 0x08a, 0xcc, 0xce }
  46. };
  47. static int isa_get_dma_residue(dmach_t channel, dma_t *dma)
  48. {
  49. unsigned int io_port = isa_dma_port[channel][ISA_DMA_COUNT];
  50. int count;
  51. count = 1 + inb(io_port);
  52. count |= inb(io_port) << 8;
  53. return channel < 4 ? count : (count << 1);
  54. }
  55. static void isa_enable_dma(dmach_t channel, dma_t *dma)
  56. {
  57. if (dma->invalid) {
  58. unsigned long address, length;
  59. unsigned int mode, direction;
  60. mode = channel & 3;
  61. switch (dma->dma_mode & DMA_MODE_MASK) {
  62. case DMA_MODE_READ:
  63. mode |= ISA_DMA_MODE_READ;
  64. direction = PCI_DMA_FROMDEVICE;
  65. break;
  66. case DMA_MODE_WRITE:
  67. mode |= ISA_DMA_MODE_WRITE;
  68. direction = PCI_DMA_TODEVICE;
  69. break;
  70. case DMA_MODE_CASCADE:
  71. mode |= ISA_DMA_MODE_CASCADE;
  72. direction = PCI_DMA_BIDIRECTIONAL;
  73. break;
  74. default:
  75. direction = PCI_DMA_NONE;
  76. break;
  77. }
  78. if (!dma->using_sg) {
  79. /*
  80. * Cope with ISA-style drivers which expect cache
  81. * coherence.
  82. */
  83. dma->buf.dma_address = pci_map_single(NULL,
  84. dma->buf.__address, dma->buf.length,
  85. direction);
  86. }
  87. address = dma->buf.dma_address;
  88. length = dma->buf.length - 1;
  89. outb(address >> 16, isa_dma_port[channel][ISA_DMA_PGLO]);
  90. outb(address >> 24, isa_dma_port[channel][ISA_DMA_PGHI]);
  91. if (channel >= 4) {
  92. address >>= 1;
  93. length >>= 1;
  94. }
  95. outb(0, isa_dma_port[channel][ISA_DMA_CLRFF]);
  96. outb(address, isa_dma_port[channel][ISA_DMA_ADDR]);
  97. outb(address >> 8, isa_dma_port[channel][ISA_DMA_ADDR]);
  98. outb(length, isa_dma_port[channel][ISA_DMA_COUNT]);
  99. outb(length >> 8, isa_dma_port[channel][ISA_DMA_COUNT]);
  100. if (dma->dma_mode & DMA_AUTOINIT)
  101. mode |= ISA_DMA_AUTOINIT;
  102. outb(mode, isa_dma_port[channel][ISA_DMA_MODE]);
  103. dma->invalid = 0;
  104. }
  105. outb(channel & 3, isa_dma_port[channel][ISA_DMA_MASK]);
  106. }
  107. static void isa_disable_dma(dmach_t channel, dma_t *dma)
  108. {
  109. outb(channel | 4, isa_dma_port[channel][ISA_DMA_MASK]);
  110. }
  111. static struct dma_ops isa_dma_ops = {
  112. .type = "ISA",
  113. .enable = isa_enable_dma,
  114. .disable = isa_disable_dma,
  115. .residue = isa_get_dma_residue,
  116. };
  117. static struct resource dma_resources[] = {
  118. { "dma1", 0x0000, 0x000f },
  119. { "dma low page", 0x0080, 0x008f },
  120. { "dma2", 0x00c0, 0x00df },
  121. { "dma high page", 0x0480, 0x048f }
  122. };
  123. void __init isa_init_dma(dma_t *dma)
  124. {
  125. /*
  126. * Try to autodetect presence of an ISA DMA controller.
  127. * We do some minimal initialisation, and check that
  128. * channel 0's DMA address registers are writeable.
  129. */
  130. outb(0xff, 0x0d);
  131. outb(0xff, 0xda);
  132. /*
  133. * Write high and low address, and then read them back
  134. * in the same order.
  135. */
  136. outb(0x55, 0x00);
  137. outb(0xaa, 0x00);
  138. if (inb(0) == 0x55 && inb(0) == 0xaa) {
  139. int channel, i;
  140. for (channel = 0; channel < 8; channel++) {
  141. dma[channel].d_ops = &isa_dma_ops;
  142. isa_disable_dma(channel, NULL);
  143. }
  144. outb(0x40, 0x0b);
  145. outb(0x41, 0x0b);
  146. outb(0x42, 0x0b);
  147. outb(0x43, 0x0b);
  148. outb(0xc0, 0xd6);
  149. outb(0x41, 0xd6);
  150. outb(0x42, 0xd6);
  151. outb(0x43, 0xd6);
  152. outb(0, 0xd4);
  153. outb(0x10, 0x08);
  154. outb(0x10, 0xd0);
  155. /*
  156. * Is this correct? According to my documentation, it
  157. * doesn't appear to be. It should be:
  158. * outb(0x3f, 0x40b); outb(0x3f, 0x4d6);
  159. */
  160. outb(0x30, 0x40b);
  161. outb(0x31, 0x40b);
  162. outb(0x32, 0x40b);
  163. outb(0x33, 0x40b);
  164. outb(0x31, 0x4d6);
  165. outb(0x32, 0x4d6);
  166. outb(0x33, 0x4d6);
  167. request_dma(DMA_ISA_CASCADE, "cascade");
  168. for (i = 0; i < sizeof(dma_resources) / sizeof(dma_resources[0]); i++)
  169. request_resource(&ioport_resource, dma_resources + i);
  170. }
  171. }