Import 2.3.18pre1
[davej-history.git] / drivers / scsi / a3000.c
blobef4b010a647058d872305055df61978e0cf8a195
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 struct proc_dir_entry proc_scsi_a3000 = {
24 PROC_SCSI_A3000, 5, "A3000",
25 S_IFDIR | S_IRUGO | S_IXUGO, 2
28 #define DMA(ptr) ((a3000_scsiregs *)((ptr)->base))
29 #define HDATA(ptr) ((struct WD33C93_hostdata *)((ptr)->hostdata))
31 static struct Scsi_Host *a3000_host = NULL;
33 static void a3000_intr (int irq, void *dummy, struct pt_regs *fp)
35 unsigned long flags;
36 unsigned int status = DMA(a3000_host)->ISTR;
38 if (!(status & ISTR_INT_P))
39 return;
40 if (status & ISTR_INTS)
42 spin_lock_irqsave(&io_request_lock, flags);
43 wd33c93_intr (a3000_host);
44 spin_unlock_irqrestore(&io_request_lock, flags);
45 } else
46 printk("Non-serviced A3000 SCSI-interrupt? ISTR = %02x\n",
47 status);
50 static int dma_setup (Scsi_Cmnd *cmd, int dir_in)
52 unsigned short cntr = CNTR_PDMD | CNTR_INTEN;
53 unsigned long addr = virt_to_bus(cmd->SCp.ptr);
56 * if the physical address has the wrong alignment, or if
57 * physical address is bad, or if it is a write and at the
58 * end of a physical memory chunk, then allocate a bounce
59 * buffer
61 if (addr & A3000_XFER_MASK ||
62 (!dir_in && mm_end_of_chunk (addr, cmd->SCp.this_residual)))
64 HDATA(a3000_host)->dma_bounce_len = (cmd->SCp.this_residual + 511)
65 & ~0x1ff;
66 HDATA(a3000_host)->dma_bounce_buffer =
67 scsi_malloc (HDATA(a3000_host)->dma_bounce_len);
69 /* can't allocate memory; use PIO */
70 if (!HDATA(a3000_host)->dma_bounce_buffer) {
71 HDATA(a3000_host)->dma_bounce_len = 0;
72 return 1;
75 if (!dir_in) {
76 /* copy to bounce buffer for a write */
77 if (cmd->use_sg) {
78 memcpy (HDATA(a3000_host)->dma_bounce_buffer,
79 cmd->SCp.ptr, cmd->SCp.this_residual);
80 } else
81 memcpy (HDATA(a3000_host)->dma_bounce_buffer,
82 cmd->request_buffer, cmd->request_bufflen);
85 addr = virt_to_bus(HDATA(a3000_host)->dma_bounce_buffer);
88 /* setup dma direction */
89 if (!dir_in)
90 cntr |= CNTR_DDIR;
92 /* remember direction */
93 HDATA(a3000_host)->dma_dir = dir_in;
95 DMA(a3000_host)->CNTR = cntr;
97 /* setup DMA *physical* address */
98 DMA(a3000_host)->ACR = addr;
100 if (dir_in)
101 /* invalidate any cache */
102 cache_clear (addr, cmd->SCp.this_residual);
103 else
104 /* push any dirty cache */
105 cache_push (addr, cmd->SCp.this_residual);
107 /* start DMA */
108 DMA(a3000_host)->ST_DMA = 1;
110 /* return success */
111 return 0;
114 static void dma_stop (struct Scsi_Host *instance, Scsi_Cmnd *SCpnt,
115 int status)
117 /* disable SCSI interrupts */
118 unsigned short cntr = CNTR_PDMD;
120 if (!HDATA(instance)->dma_dir)
121 cntr |= CNTR_DDIR;
123 DMA(instance)->CNTR = cntr;
125 /* flush if we were reading */
126 if (HDATA(instance)->dma_dir) {
127 DMA(instance)->FLUSH = 1;
128 while (!(DMA(instance)->ISTR & ISTR_FE_FLG))
132 /* clear a possible interrupt */
133 /* I think that this CINT is only necessary if you are
134 * using the terminal count features. HM 7 Mar 1994
136 DMA(instance)->CINT = 1;
138 /* stop DMA */
139 DMA(instance)->SP_DMA = 1;
141 /* restore the CONTROL bits (minus the direction flag) */
142 DMA(instance)->CNTR = CNTR_PDMD | CNTR_INTEN;
144 /* copy from a bounce buffer, if necessary */
145 if (status && HDATA(instance)->dma_bounce_buffer) {
146 if (SCpnt && SCpnt->use_sg) {
147 if (HDATA(instance)->dma_dir && SCpnt)
148 memcpy (SCpnt->SCp.ptr,
149 HDATA(instance)->dma_bounce_buffer,
150 SCpnt->SCp.this_residual);
151 scsi_free (HDATA(instance)->dma_bounce_buffer,
152 HDATA(instance)->dma_bounce_len);
153 HDATA(instance)->dma_bounce_buffer = NULL;
154 HDATA(instance)->dma_bounce_len = 0;
155 } else {
156 if (HDATA(instance)->dma_dir && SCpnt)
157 memcpy (SCpnt->request_buffer,
158 HDATA(instance)->dma_bounce_buffer,
159 SCpnt->request_bufflen);
161 scsi_free (HDATA(instance)->dma_bounce_buffer,
162 HDATA(instance)->dma_bounce_len);
163 HDATA(instance)->dma_bounce_buffer = NULL;
164 HDATA(instance)->dma_bounce_len = 0;
169 int __init a3000_detect(Scsi_Host_Template *tpnt)
171 static unsigned char called = 0;
173 if (called)
174 return 0;
176 if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT(A3000_SCSI))
177 return 0;
179 tpnt->proc_dir = &proc_scsi_a3000;
180 tpnt->proc_info = &wd33c93_proc_info;
182 a3000_host = scsi_register (tpnt, sizeof(struct WD33C93_hostdata));
183 a3000_host->base = (unsigned char *)ZTWO_VADDR(0xDD0000);
184 a3000_host->irq = IRQ_AMIGA_PORTS;
185 DMA(a3000_host)->DAWR = DAWR_A3000;
186 wd33c93_init(a3000_host, (wd33c93_regs *)&(DMA(a3000_host)->SASR),
187 dma_setup, dma_stop, WD33C93_FS_12_15);
188 request_irq(IRQ_AMIGA_PORTS, a3000_intr, SA_SHIRQ, "A3000 SCSI",
189 a3000_intr);
190 DMA(a3000_host)->CNTR = CNTR_PDMD | CNTR_INTEN;
191 called = 1;
193 return 1;
196 #ifdef MODULE
198 #define HOSTS_C
200 #include "a3000.h"
202 Scsi_Host_Template driver_template = A3000_SCSI;
204 #include "scsi_module.c"
206 #endif
208 int a3000_release(struct Scsi_Host *instance)
210 #ifdef MODULE
211 wd33c93_release();
212 DMA(instance)->CNTR = 0;
213 free_irq(IRQ_AMIGA_PORTS, a3000_intr);
214 #endif
215 return 1;