a3000.c 6.4 KB

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