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 #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
)
31 unsigned int status
= DMA(a3000_host
)->ISTR
;
33 if (!(status
& ISTR_INT_P
))
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
);
41 printk("Non-serviced A3000 SCSI-interrupt? ISTR = %02x\n",
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
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)
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;
71 /* copy to bounce buffer for a write */
73 memcpy (HDATA(a3000_host
)->dma_bounce_buffer
,
74 cmd
->SCp
.ptr
, cmd
->SCp
.this_residual
);
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 */
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
;
96 /* invalidate any cache */
97 cache_clear (addr
, cmd
->SCp
.this_residual
);
99 /* push any dirty cache */
100 cache_push (addr
, cmd
->SCp
.this_residual
);
103 DMA(a3000_host
)->ST_DMA
= 1;
109 static void dma_stop (struct Scsi_Host
*instance
, Scsi_Cmnd
*SCpnt
,
112 /* disable SCSI interrupts */
113 unsigned short cntr
= CNTR_PDMD
;
115 if (!HDATA(instance
)->dma_dir
)
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;
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;
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;
171 if (!MACH_IS_AMIGA
|| !AMIGAHW_PRESENT(A3000_SCSI
))
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
)
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",
187 DMA(a3000_host
)->CNTR
= CNTR_PDMD
| CNTR_INTEN
;
197 static Scsi_Host_Template driver_template
= A3000_SCSI
;
199 #include "scsi_module.c"
201 int a3000_release(struct Scsi_Host
*instance
)
205 DMA(instance
)->CNTR
= 0;
206 free_irq(IRQ_AMIGA_PORTS
, a3000_intr
);