No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / pmax / ibus / sii_ds.c
bloba12f31fd915e7717828e2027452905edd35dd28a
1 /* $NetBSD: sii_ds.c,v 1.5 2009/03/14 15:36:11 dsl Exp $ */
3 /*
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 $");
21 #include "sii.h"
23 #include <sys/param.h>
24 #include <sys/systm.h>
25 #include <sys/device.h>
26 #include <sys/buf.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,
48 int length);
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,
53 int length);
56 * Autoconfig definition of driver front-end
58 static int sii_ds_match(struct device* parent, struct cfdata *match,
59 void *aux);
60 static void sii_ds_attach(struct device *parent, struct device *self,
61 void *aux);
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.
73 static int
74 sii_ds_match(struct device *parent, struct cfdata *match, void *aux)
76 struct ibus_attach_args *ia = aux;
77 void *siiaddr;
79 if (strcmp(ia->ia_name, "sii") != 0)
80 return (0);
81 siiaddr = (void *)ia->ia_addr;
82 if (badaddr(siiaddr, 4))
83 return (0);
84 return (1);
87 static void
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) {
99 #if 0
100 sc->sii_copytobuf = CopyToBuffer;
101 sc->sii_copyfrombuf = CopyFromBuffer;
102 #else
103 sc->sii_copytobuf = kn01_copytobuf;
104 sc->sii_copyfrombuf = kn01_copyfrombuf;
105 #endif
106 } else {
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;
114 siiattach(sc);
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.
130 static void
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;
135 int i, n;
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);
144 #endif
146 /* DMA buffer is allocated in 32-bit words, so just copy words. */
147 n = len / 4;
148 if (len & 0x3)
149 n++;
150 for (i = 0; i < n; i++) {
151 *wdst = *wsrc;
152 wsrc++;
153 wdst+= 2;
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.
164 static void
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;
170 int i, n;
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);
179 #endif
181 n = len / 4;
183 for (i = 0; i < n; i++) {
184 *wdst = *wsrc;
185 wsrc += 2;
186 wdst++;
189 if (len & 0x3) {
190 u_int lastword = *wsrc;
192 if (len & 0x2)
193 *((u_short*)(wdst)) = (u_short) (lastword);
195 if (len & 0x1)
196 ((u_char*)(wdst))[2] = (u_char) (lastword >> 16);
199 wbflush(); /* XXX not necessary? */
203 static void
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);
213 #endif
215 CopyToBuffer(src, dst, len);
218 static void
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);
230 #endif
231 CopyFromBuffer(src, dst, len);