1 /* $NetBSD: sii_ds.c,v 1.5 2009/03/14 15:36:11 dsl Exp $ */
4 * Copyright 1996 The Board of Trustees of The Leland Stanford
5 * Junior University. All Rights Reserved.
7 * Permission to use, copy, modify, and distribute this
8 * software and its documentation for any purpose and without
9 * fee is hereby granted, provided that the above copyright
10 * notice appear in all copies. Stanford University
11 * makes no representations about the suitability of this
12 * software for any purpose. It is provided "as is" without
13 * express or implied warranty.
15 * this driver contributed by Jonathan Stone
18 #include <sys/cdefs.h>
19 __KERNEL_RCSID(0, "$NetBSD: sii_ds.c,v 1.5 2009/03/14 15:36:11 dsl Exp $");
23 #include <sys/param.h>
24 #include <sys/systm.h>
25 #include <sys/device.h>
28 #include <machine/locore.h>
30 #include <dev/scsipi/scsi_all.h>
31 #include <dev/scsipi/scsipi_all.h>
32 #include <dev/scsipi/scsiconf.h>
33 #include <dev/scsipi/scsi_message.h>
35 #include <machine/bus.h>
36 #include <pmax/ibus/siireg.h>
37 #include <pmax/ibus/siivar.h>
39 #include <pmax/ibus/ibusvar.h> /* interrupt etablish */
41 #include <pmax/pmax/kn01.h> /* kn01 (ds3100) address constants */
42 #include <pmax/pmax/pmaxtype.h>
45 static void kn230_copytobuf(u_short
*src
, /* NB: must be short aligned */
46 volatile u_short
*dst
, int length
);
47 static void kn230_copyfrombuf(volatile u_short
*src
, char *dst
,
50 static void kn01_copytobuf(u_short
*src
, /* NB: must be short aligned */
51 volatile u_short
*dst
, int length
);
52 static void kn01_copyfrombuf(volatile u_short
*src
, char *dst
,
56 * Autoconfig definition of driver front-end
58 static int sii_ds_match(struct device
* parent
, struct cfdata
*match
,
60 static void sii_ds_attach(struct device
*parent
, struct device
*self
,
63 CFATTACH_DECL(sii_ds
, sizeof(struct siisoftc
),
64 sii_ds_match
, sii_ds_attach
, NULL
, NULL
);
66 /* define a safe address in the SCSI buffer for doing status & message DMA */
67 #define SII_BUF_ADDR (MIPS_PHYS_TO_KSEG1(KN01_SYS_SII_B_START) \
68 + SII_MAX_DMA_XFER_LENGTH * 14)
71 * Match driver on Decstation (2100, 3100, 5100) based on name and probe.
74 sii_ds_match(struct device
*parent
, struct cfdata
*match
, void *aux
)
76 struct ibus_attach_args
*ia
= aux
;
79 if (strcmp(ia
->ia_name
, "sii") != 0)
81 siiaddr
= (void *)ia
->ia_addr
;
82 if (badaddr(siiaddr
, 4))
88 sii_ds_attach(struct device
*parent
, struct device
*self
, void *aux
)
90 struct ibus_attach_args
*ia
= aux
;
91 struct siisoftc
*sc
= (struct siisoftc
*) self
;
93 sc
->sc_regs
= (SIIRegs
*)MIPS_PHYS_TO_KSEG1(ia
->ia_addr
);
95 /* set up scsi buffer. XXX Why statically allocated? */
96 sc
->sc_buf
= (void*)(MIPS_PHYS_TO_KSEG1(KN01_SYS_SII_B_START
));
98 if (systype
== DS_PMAX
) {
100 sc
->sii_copytobuf
= CopyToBuffer
;
101 sc
->sii_copyfrombuf
= CopyFromBuffer
;
103 sc
->sii_copytobuf
= kn01_copytobuf
;
104 sc
->sii_copyfrombuf
= kn01_copyfrombuf
;
107 sc
->sii_copytobuf
= kn230_copytobuf
;
108 sc
->sii_copyfrombuf
= kn230_copyfrombuf
;
111 /* Do the common parts of attachment. */
112 sc
->sc_adapter
.adapt_request
= sii_scsi_request
;
113 sc
->sc_adapter
.adapt_minphys
= minphys
;
116 /* tie pseudo-slot to device */
117 ibus_intr_establish(parent
, (void*)ia
->ia_cookie
, IPL_BIO
, siiintr
, sc
);
122 * Padded DMA copy functions
127 * XXX assumes src is always 32-bit aligned.
128 * currently safe on sii driver, but API and casts should be changed.
131 kn230_copytobuf(u_short
*src
, volatile u_short
*dst
, int len
)
133 u_int
*wsrc
= (u_int
*)src
;
134 volatile u_int
*wdst
= (volatile u_int
*)dst
;
137 #if defined(DIAGNOSTIC) || defined(DEBUG)
138 if ((u_int
)(src
) & 0x3) {
139 printf("kn230: copytobuf, src %p misaligned\n", src
);
141 if ((u_int
)(dst
) & 0x3) {
142 printf("kn230: copytobuf, dst %p misaligned\n", dst
);
146 /* DMA buffer is allocated in 32-bit words, so just copy words. */
150 for (i
= 0; i
< n
; i
++) {
156 wbflush(); /* XXX not necessary? */
161 * XXX assumes dst is always 32-bit aligned.
162 * currently safe on sii driver, but API and casts should be changed.
165 kn230_copyfrombuf(volatile u_short
*src
, char *dst
, int len
)
166 /* dst: XXX assume 32-bit aligned? */
168 volatile u_int
*wsrc
= (volatile u_int
*)src
;
169 u_int
*wdst
= (u_int
*)dst
;
172 #if defined(DIAGNOSTIC) || defined(DEBUG)
173 if ((u_int
)(src
) & 0x3) {
174 printf("kn230: copyfrombuf, src %p misaligned\n", src
);
176 if ((u_int
)(dst
) & 0x3) {
177 printf("kn230: copyfrombuf, dst %p misaligned\n", dst
);
183 for (i
= 0; i
< n
; i
++) {
190 u_int lastword
= *wsrc
;
193 *((u_short
*)(wdst
)) = (u_short
) (lastword
);
196 ((u_char
*)(wdst
))[2] = (u_char
) (lastword
>> 16);
199 wbflush(); /* XXX not necessary? */
204 kn01_copytobuf(u_short
*src
, volatile u_short
*dst
, int len
)
206 #if defined(DIAGNOSTIC) || defined(DEBUG)
207 if ((u_int
)(src
) & 0x3) {
208 printf("kn01: copytobuf, src %p misaligned\n", src
);
210 if ((u_int
)(dst
) & 0x3) {
211 printf("kn01: copytobuf, dst %p misaligned\n", dst
);
215 CopyToBuffer(src
, dst
, len
);
219 kn01_copyfrombuf(volatile u_short
*src
, char *dst
, int len
)
220 /* dst: XXX assume 32-bit aligned? */
222 #if defined(DIAGNOSTIC) || defined(DEBUG)
223 if ((u_int
)(src
) & 0x3) {
224 printf("kn01: copyfrombuf, src %p misaligned\n", src
);
226 if ((u_int
)(dst
) & 0x3) {
227 printf("kn01: copyfrombuf, dst %p misaligned\n", dst
);
231 CopyFromBuffer(src
, dst
, len
);