- pre3:
[davej-history.git] / drivers / scsi / a3000.c
blobc9a4253f0a8a6b6963be2850f0986e3f018bb9fa
1 #include <linux/types.h>
2 #include <linux/mm.h>
3 #include <linux/blk.h>
4 #include <linux/sched.h>
5 #include <linux/version.h>
6 #include <linux/init.h>
7 #include <linux/spinlock.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>
16 #include "scsi.h"
17 #include "hosts.h"
18 #include "wd33c93.h"
19 #include "a3000.h"
21 #include<linux/stat.h>
23 #define DMA(ptr) ((a3000_scsiregs *)((ptr)->base))
24 #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
26 static struct Scsi_Host *a3000_host = NULL;
28 static void a3000_intr (int irq, void *dummy, struct pt_regs *fp)
30 unsigned long flags;
31 unsigned int status = DMA(a3000_host)->ISTR;
33 if (!(status & ISTR_INT_P))
34 return;
35 if (status & ISTR_INTS)
37 spin_lock_irqsave(&io_request_lock, flags);
38 wd33c93_intr (a3000_host);
39 spin_unlock_irqrestore(&io_request_lock, flags);
40 } else
41 printk("Non-serviced A3000 SCSI-interrupt? ISTR = %02x\n",
42 status);
45 static int dma_setup (Scsi_Cmnd *cmd, int dir_in)
47 unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
48 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
51 * if the physical address has the wrong alignment, or if
52 * physical address is bad, or if it is a write and at the
53 * end of a physical memory chunk, then allocate a bounce
54 * buffer
56 if (addr & A3000_XFER_MASK ||
57 (!dir_in && mm_end_of_chunk (addr, cmd->SCp.this_residual)))
59 HDATA(a3000_host)->dma_bounce_len = (cmd->SCp.this_residual + 511)
60 & ~0x1ff;
61 HDATA(a3000_host)->dma_bounce_buffer =
62 scsi_malloc (HDATA(a3000_host)->dma_bounce_len);
64 /* can't allocate memory; use PIO */
65 if (!HDATA(a3000_host)->dma_bounce_buffer) {
66 HDATA(a3000_host)->dma_bounce_len = 0;
67 return 1;
70 if (!dir_in) {
71 /* copy to bounce buffer for a write */
72 if (cmd->use_sg) {
73 memcpy (HDATA(a3000_host)->dma_bounce_buffer,
74 cmd->SCp.ptr, cmd->SCp.this_residual);
75 } else
76 memcpy (HDATA(a3000_host)->dma_bounce_buffer,
77 cmd->request_buffer, cmd->request_bufflen);
80 addr = virt_to_bus(HDATA(a3000_host)->dma_bounce_buffer);
83 /* setup dma direction */
84 if (!dir_in)
85 cntr |= CNTR_DDIR;
87 /* remember direction */
88 HDATA(a3000_host)->dma_dir = dir_in;
90 DMA(a3000_host)->CNTR = cntr;
92 /* setup DMA *physical* address */
93 DMA(a3000_host)->ACR = addr;
95 if (dir_in)
96 /* invalidate any cache */
97 cache_clear (addr, cmd->SCp.this_residual);
98 else
99 /* push any dirty cache */
100 cache_push (addr, cmd->SCp.this_residual);
102 /* start DMA */
103 DMA(a3000_host)->ST_DMA = 1;
105 /* return success */
106 return 0;
109 static void dma_stop (struct Scsi_Host *instance, Scsi_Cmnd *SCpnt,
110 int status)
112 /* disable SCSI interrupts */
113 unsigned short cntr = CNTR_PDMD;
115 if (!HDATA(instance)->dma_dir)
116 cntr |= CNTR_DDIR;
118 DMA(instance)->CNTR = cntr;
120 /* flush if we were reading */
121 if (HDATA(instance)->dma_dir) {
122 DMA(instance)->FLUSH = 1;
123 while (!(DMA(instance)->ISTR & ISTR_FE_FLG))
127 /* clear a possible interrupt */
128 /* I think that this CINT is only necessary if you are
129 * using the terminal count features. HM 7 Mar 1994
131 DMA(instance)->CINT = 1;
133 /* stop DMA */
134 DMA(instance)->SP_DMA = 1;
136 /* restore the CONTROL bits (minus the direction flag) */
137 DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
139 /* copy from a bounce buffer, if necessary */
140 if (status && HDATA(instance)->dma_bounce_buffer) {
141 if (SCpnt && SCpnt->use_sg) {
142 if (HDATA(instance)->dma_dir && SCpnt)
143 memcpy (SCpnt->SCp.ptr,
144 HDATA(instance)->dma_bounce_buffer,
145 SCpnt->SCp.this_residual);
146 scsi_free (HDATA(instance)->dma_bounce_buffer,
147 HDATA(instance)->dma_bounce_len);
148 HDATA(instance)->dma_bounce_buffer = NULL;
149 HDATA(instance)->dma_bounce_len = 0;
150 } else {
151 if (HDATA(instance)->dma_dir && SCpnt)
152 memcpy (SCpnt->request_buffer,
153 HDATA(instance)->dma_bounce_buffer,
154 SCpnt->request_bufflen);
156 scsi_free (HDATA(instance)->dma_bounce_buffer,
157 HDATA(instance)->dma_bounce_len);
158 HDATA(instance)->dma_bounce_buffer = NULL;
159 HDATA(instance)->dma_bounce_len = 0;
164 int __init a3000_detect(Scsi_Host_Template *tpnt)
166 static unsigned char called = 0;
168 if (called)
169 return 0;
171 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(A3000_SCSI))
172 return 0;
174 tpnt->proc_name = "A3000";
175 tpnt->proc_info = &wd33c93_proc_info;
177 a3000_host = scsi_register (tpnt, sizeof(struct WD33C93_hostdata));
178 if(a3000_host == NULL)
179 return 0;
180 a3000_host->base = ZTWO_VADDR(0xDD0000);
181 a3000_host->irq = IRQ_AMIGA_PORTS;
182 DMA(a3000_host)->DAWR = DAWR_A3000;
183 wd33c93_init(a3000_host, (wd33c93_regs *)&(DMA(a3000_host)->SASR),
184 dma_setup, dma_stop, WD33C93_FS_12_15);
185 request_irq(IRQ_AMIGA_PORTS, a3000_intr, SA_SHIRQ, "A3000 SCSI",
186 a3000_intr);
187 DMA(a3000_host)->CNTR = CNTR_PDMD | CNTR_INTEN;
188 called = 1;
190 return 1;
193 #define HOSTS_C
195 #include "a3000.h"
197 static Scsi_Host_Template driver_template = A3000_SCSI;
199 #include "scsi_module.c"
201 int a3000_release(struct Scsi_Host *instance)
203 #ifdef MODULE
204 wd33c93_release();
205 DMA(instance)->CNTR = 0;
206 free_irq(IRQ_AMIGA_PORTS, a3000_intr);
207 #endif
208 return 1;