a3000.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #include <linux/types.h>
  2. #include <linux/mm.h>
  3. #include <linux/blkdev.h>
  4. #include <linux/ioport.h>
  5. #include <linux/init.h>
  6. #include <linux/spinlock.h>
  7. #include <linux/interrupt.h>
  8. #include <asm/setup.h>
  9. #include <asm/page.h>
  10. #include <asm/pgtable.h>
  11. #include <asm/amigaints.h>
  12. #include <asm/amigahw.h>
  13. #include <asm/irq.h>
  14. #include "scsi.h"
  15. #include <scsi/scsi_host.h>
  16. #include "wd33c93.h"
  17. #include "a3000.h"
  18. #include<linux/stat.h>
  19. #define DMA(ptr) ((a3000_scsiregs *)((ptr)->base))
  20. #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
  21. static struct Scsi_Host *a3000_host = NULL;
  22. static int a3000_release(struct Scsi_Host *instance);
  23. static irqreturn_t a3000_intr (int irq, void *dummy)
  24. {
  25. unsigned long flags;
  26. unsigned int status = DMA(a3000_host)->ISTR;
  27. if (!(status & ISTR_INT_P))
  28. return IRQ_NONE;
  29. if (status & ISTR_INTS)
  30. {
  31. spin_lock_irqsave(a3000_host->host_lock, flags);
  32. wd33c93_intr (a3000_host);
  33. spin_unlock_irqrestore(a3000_host->host_lock, flags);
  34. return IRQ_HANDLED;
  35. }
  36. printk("Non-serviced A3000 SCSI-interrupt? ISTR = %02x\n", status);
  37. return IRQ_NONE;
  38. }
  39. static int dma_setup(struct scsi_cmnd *cmd, int dir_in)
  40. {
  41. unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
  42. unsigned long addr = virt_to_bus(cmd->SCp.ptr);
  43. /*
  44. * if the physical address has the wrong alignment, or if
  45. * physical address is bad, or if it is a write and at the
  46. * end of a physical memory chunk, then allocate a bounce
  47. * buffer
  48. */
  49. if (addr & A3000_XFER_MASK)
  50. {
  51. HDATA(a3000_host)->dma_bounce_len = (cmd->SCp.this_residual + 511)
  52. & ~0x1ff;
  53. HDATA(a3000_host)->dma_bounce_buffer =
  54. kmalloc (HDATA(a3000_host)->dma_bounce_len, GFP_KERNEL);
  55. /* can't allocate memory; use PIO */
  56. if (!HDATA(a3000_host)->dma_bounce_buffer) {
  57. HDATA(a3000_host)->dma_bounce_len = 0;
  58. return 1;
  59. }
  60. if (!dir_in) {
  61. /* copy to bounce buffer for a write */
  62. memcpy (HDATA(a3000_host)->dma_bounce_buffer,
  63. cmd->SCp.ptr, cmd->SCp.this_residual);
  64. }
  65. addr = virt_to_bus(HDATA(a3000_host)->dma_bounce_buffer);
  66. }
  67. /* setup dma direction */
  68. if (!dir_in)
  69. cntr |= CNTR_DDIR;
  70. /* remember direction */
  71. HDATA(a3000_host)->dma_dir = dir_in;
  72. DMA(a3000_host)->CNTR = cntr;
  73. /* setup DMA *physical* address */
  74. DMA(a3000_host)->ACR = addr;
  75. if (dir_in)
  76. /* invalidate any cache */
  77. cache_clear (addr, cmd->SCp.this_residual);
  78. else
  79. /* push any dirty cache */
  80. cache_push (addr, cmd->SCp.this_residual);
  81. /* start DMA */
  82. mb(); /* make sure setup is completed */
  83. DMA(a3000_host)->ST_DMA = 1;
  84. mb(); /* make sure DMA has started before next IO */
  85. /* return success */
  86. return 0;
  87. }
  88. static void dma_stop(struct Scsi_Host *instance, struct scsi_cmnd *SCpnt,
  89. int status)
  90. {
  91. /* disable SCSI interrupts */
  92. unsigned short cntr = CNTR_PDMD;
  93. if (!HDATA(instance)->dma_dir)
  94. cntr |= CNTR_DDIR;
  95. DMA(instance)->CNTR = cntr;
  96. mb(); /* make sure CNTR is updated before next IO */
  97. /* flush if we were reading */
  98. if (HDATA(instance)->dma_dir) {
  99. DMA(instance)->FLUSH = 1;
  100. mb(); /* don't allow prefetch */
  101. while (!(DMA(instance)->ISTR & ISTR_FE_FLG))
  102. barrier();
  103. mb(); /* no IO until FLUSH is done */
  104. }
  105. /* clear a possible interrupt */
  106. /* I think that this CINT is only necessary if you are
  107. * using the terminal count features. HM 7 Mar 1994
  108. */
  109. DMA(instance)->CINT = 1;
  110. /* stop DMA */
  111. DMA(instance)->SP_DMA = 1;
  112. mb(); /* make sure DMA is stopped before next IO */
  113. /* restore the CONTROL bits (minus the direction flag) */
  114. DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
  115. mb(); /* make sure CNTR is updated before next IO */
  116. /* copy from a bounce buffer, if necessary */
  117. if (status && HDATA(instance)->dma_bounce_buffer) {
  118. if (SCpnt) {
  119. if (HDATA(instance)->dma_dir && SCpnt)
  120. memcpy (SCpnt->SCp.ptr,
  121. HDATA(instance)->dma_bounce_buffer,
  122. SCpnt->SCp.this_residual);
  123. kfree (HDATA(instance)->dma_bounce_buffer);
  124. HDATA(instance)->dma_bounce_buffer = NULL;
  125. HDATA(instance)->dma_bounce_len = 0;
  126. } else {
  127. kfree (HDATA(instance)->dma_bounce_buffer);
  128. HDATA(instance)->dma_bounce_buffer = NULL;
  129. HDATA(instance)->dma_bounce_len = 0;
  130. }
  131. }
  132. }
  133. static int __init a3000_detect(struct scsi_host_template *tpnt)
  134. {
  135. wd33c93_regs regs;
  136. if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(A3000_SCSI))
  137. return 0;
  138. if (!request_mem_region(0xDD0000, 256, "wd33c93"))
  139. return 0;
  140. tpnt->proc_name = "A3000";
  141. tpnt->proc_info = &wd33c93_proc_info;
  142. a3000_host = scsi_register (tpnt, sizeof(struct WD33C93_hostdata));
  143. if (a3000_host == NULL)
  144. goto fail_register;
  145. a3000_host->base = ZTWO_VADDR(0xDD0000);
  146. a3000_host->irq = IRQ_AMIGA_PORTS;
  147. DMA(a3000_host)->DAWR = DAWR_A3000;
  148. regs.SASR = &(DMA(a3000_host)->SASR);
  149. regs.SCMD = &(DMA(a3000_host)->SCMD);
  150. HDATA(a3000_host)->no_sync = 0xff;
  151. HDATA(a3000_host)->fast = 0;
  152. HDATA(a3000_host)->dma_mode = CTRL_DMA;
  153. wd33c93_init(a3000_host, regs, dma_setup, dma_stop, WD33C93_FS_12_15);
  154. if (request_irq(IRQ_AMIGA_PORTS, a3000_intr, IRQF_SHARED, "A3000 SCSI",
  155. a3000_intr))
  156. goto fail_irq;
  157. DMA(a3000_host)->CNTR = CNTR_PDMD | CNTR_INTEN;
  158. return 1;
  159. fail_irq:
  160. wd33c93_release();
  161. scsi_unregister(a3000_host);
  162. fail_register:
  163. release_mem_region(0xDD0000, 256);
  164. return 0;
  165. }
  166. static int a3000_bus_reset(struct scsi_cmnd *cmd)
  167. {
  168. /* FIXME perform bus-specific reset */
  169. /* FIXME 2: kill this entire function, which should
  170. cause mid-layer to call wd33c93_host_reset anyway? */
  171. spin_lock_irq(cmd->device->host->host_lock);
  172. wd33c93_host_reset(cmd);
  173. spin_unlock_irq(cmd->device->host->host_lock);
  174. return SUCCESS;
  175. }
  176. #define HOSTS_C
  177. static struct scsi_host_template driver_template = {
  178. .proc_name = "A3000",
  179. .name = "Amiga 3000 built-in SCSI",
  180. .detect = a3000_detect,
  181. .release = a3000_release,
  182. .queuecommand = wd33c93_queuecommand,
  183. .eh_abort_handler = wd33c93_abort,
  184. .eh_bus_reset_handler = a3000_bus_reset,
  185. .eh_host_reset_handler = wd33c93_host_reset,
  186. .can_queue = CAN_QUEUE,
  187. .this_id = 7,
  188. .sg_tablesize = SG_ALL,
  189. .cmd_per_lun = CMD_PER_LUN,
  190. .use_clustering = ENABLE_CLUSTERING
  191. };
  192. #include "scsi_module.c"
  193. static int a3000_release(struct Scsi_Host *instance)
  194. {
  195. wd33c93_release();
  196. DMA(instance)->CNTR = 0;
  197. release_mem_region(0xDD0000, 256);
  198. free_irq(IRQ_AMIGA_PORTS, a3000_intr);
  199. return 1;
  200. }
  201. MODULE_LICENSE("GPL");