1 #include <linux/types.h>
4 #include <linux/sched.h>
5 #include <linux/version.h>
6 #include <linux/init.h>
7 #include <linux/spinlock.h>
11 #include <asm/pgtable.h>
12 #include <asm/amigaints.h>
13 #include <asm/amigahw.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
)
36 unsigned int status
= DMA(a3000_host
)->ISTR
;
38 if (!(status
& ISTR_INT_P
))
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
);
46 printk("Non-serviced A3000 SCSI-interrupt? ISTR = %02x\n",
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
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)
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;
76 /* copy to bounce buffer for a write */
78 memcpy (HDATA(a3000_host
)->dma_bounce_buffer
,
79 cmd
->SCp
.ptr
, cmd
->SCp
.this_residual
);
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 */
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
;
101 /* invalidate any cache */
102 cache_clear (addr
, cmd
->SCp
.this_residual
);
104 /* push any dirty cache */
105 cache_push (addr
, cmd
->SCp
.this_residual
);
108 DMA(a3000_host
)->ST_DMA
= 1;
114 static void dma_stop (struct Scsi_Host
*instance
, Scsi_Cmnd
*SCpnt
,
117 /* disable SCSI interrupts */
118 unsigned short cntr
= CNTR_PDMD
;
120 if (!HDATA(instance
)->dma_dir
)
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;
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;
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;
176 if (!MACH_IS_AMIGA
|| !AMIGAHW_PRESENT(A3000_SCSI
))
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",
190 DMA(a3000_host
)->CNTR
= CNTR_PDMD
| CNTR_INTEN
;
202 Scsi_Host_Template driver_template
= A3000_SCSI
;
204 #include "scsi_module.c"
208 int a3000_release(struct Scsi_Host
*instance
)
212 DMA(instance
)->CNTR
= 0;
213 free_irq(IRQ_AMIGA_PORTS
, a3000_intr
);