asc_tc.c revision 1.11 1 /* $NetBSD: asc_tc.c,v 1.11 1999/11/15 05:25:57 nisimura Exp $ */
2
3 /*
4 * Copyright 1996 The Board of Trustees of The Leland Stanford
5 * Junior University. All Rights Reserved.
6 *
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.
14 *
15 */
16
17 #include <sys/param.h>
18 #include <sys/systm.h>
19 #include <sys/types.h>
20 #include <sys/device.h>
21
22 #include <dev/tc/tcvar.h>
23 #include <dev/tc/ioasicvar.h>
24
25 #include <pmax/dev/device.h> /* XXX */
26 #include <pmax/dev/scsi.h> /* XXX */
27
28 #include <pmax/dev/ascreg.h> /* XXX */
29 #include <dev/tc/ascvar.h>
30
31 /*XXX*/
32
33
34 /*
35 * Autoconfiguration data for config.
36 */
37 int asc_tc_match __P((struct device *, struct cfdata *, void *));
38 void asc_tc_attach __P((struct device *, struct device *, void *));
39
40 struct cfattach asc_tc_ca = {
41 sizeof(struct asc_softc), asc_tc_match, asc_tc_attach
42 };
43
44 /*
45 * DMA callbacks
46 */
47
48 static int
49 tc_dma_start __P((struct asc_softc *asc, struct scsi_state *state,
50 caddr_t cp, int flag, int len, int off));
51
52 static void
53 tc_dma_end __P((struct asc_softc *asc, struct scsi_state *state,
54 int flag));
55
56
57 int
58 asc_tc_match(parent, match, aux)
59 struct device *parent;
60 struct cfdata *match;
61 void *aux;
62 {
63 struct tc_attach_args *t = aux;
64
65 if (strncmp(t->ta_modname, "PMAZ-AA ", TC_ROM_LLEN))
66 return (0);
67
68 return (1);
69 }
70
71
72
73 void
74 asc_tc_attach(parent, self, aux)
75 struct device *parent;
76 struct device *self;
77 void *aux;
78 {
79 register struct tc_attach_args *t = aux;
80 register asc_softc_t asc = (asc_softc_t) self;
81 u_char *buff;
82 int i, speed;
83 tc_addr_t ascaddr;
84 int unit;
85
86 /* Use uncached address for chip registers. */
87 ascaddr = (tc_addr_t)MIPS_PHYS_TO_KSEG1(t->ta_addr);
88 unit = asc->sc_dev.dv_unit;
89
90 /*
91 * Initialize hw descriptor, cache some pointers
92 */
93 asc->regs = (asc_regmap_t *)(ascaddr + ASC_OFFSET_53C94);
94
95 /*
96 * Set up machine dependencies.
97 * (1) how to do dma
98 * (2) timing based on turbochannel frequency
99 */
100
101 /*
102 * Fall through for turbochannel option.
103 */
104 asc->dmar = (volatile int *)(ascaddr + ASC_OFFSET_DMAR);
105 buff = (u_char *)(ascaddr + ASC_OFFSET_RAM);
106
107 /*
108 * Statically partition the DMA buffer between targets.
109 * This way we will eventually be able to attach/detach
110 * drives on-fly. And 18k/target is plenty for normal use.
111 */
112
113 /*
114 * Give each target its own DMA buffer region.
115 * We may want to try ping ponging buffers later.
116 */
117 for (i = 0; i < ASC_NCMD; i++)
118 asc->st[i].dmaBufAddr = buff + PER_TGT_DMA_SIZE * i;
119
120 asc->dma_start = tc_dma_start;
121 asc->dma_end = tc_dma_end;
122
123 /*
124 * Now for timing. The 3max has a 25Mhz tb whereas the 3min and
125 * maxine are 12.5Mhz.
126 */
127 printf(" (bus speed: %s MHz) ", t->ta_busspeed? "25" : "12.5");
128
129 switch (t->ta_busspeed) {
130 case TC_SPEED_25_MHZ:
131 speed = ASC_SPEED_25_MHZ;
132 break;
133
134 default:
135 printf(" (unknown TC speed, assuming 12.5MHz) ");
136 /* FALLTHROUGH*/
137 case TC_SPEED_12_5_MHZ:
138 speed = ASC_SPEED_12_5_MHZ;
139 break;
140 };
141
142 ascattach(asc, speed);
143
144 /* tie pseudo-slot to device */
145 tc_intr_establish(parent, t->ta_cookie, TC_IPL_BIO,
146 asc_intr, asc);
147 }
148
149
150 /*
151 * DMA handling routines. For a turbochannel device, just set the dmar.
152 * For the I/O ASIC, handle the actual DMA interface.
153 */
154 static int
155 tc_dma_start(asc, state, cp, flag, len, off)
156 asc_softc_t asc;
157 State *state;
158 caddr_t cp;
159 int flag;
160 int len;
161 int off;
162 {
163
164 if (len > PER_TGT_DMA_SIZE)
165 len = PER_TGT_DMA_SIZE;
166 if (flag == ASCDMA_WRITE)
167 bcopy(cp, state->dmaBufAddr + off, len);
168 if (flag == ASCDMA_WRITE)
169 *asc->dmar = ASC_DMAR_WRITE | ASC_DMA_ADDR(state->dmaBufAddr + off);
170 else
171 *asc->dmar = ASC_DMA_ADDR(state->dmaBufAddr + off);
172 return (len);
173 }
174
175 static void
176 tc_dma_end(asc, state, flag)
177 asc_softc_t asc;
178 State *state;
179 int flag;
180 {
181 if (flag == ASCDMA_READ)
182 bcopy(state->dmaBufAddr, state->buf, state->dmalen);
183 }
184