asc_tc.c revision 1.13 1 /* $NetBSD: asc_tc.c,v 1.13 2000/03/04 05:43:51 mhitch 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 int unit;
84 /* XXX Hook for dk_establish() to determine boot device */
85 extern int booted_slot;
86 extern struct device *booted_controller;
87
88 /* Is this the controller we booted from? */
89 if (booted_slot == t->ta_slot)
90 booted_controller = self;
91 /* XXX */
92
93 unit = asc->sc_dev.dv_unit;
94
95 /*
96 * Initialize hw descriptor, cache some pointers
97 */
98 asc->regs = (asc_regmap_t *)(t->ta_addr + ASC_OFFSET_53C94);
99
100 /*
101 * Set up machine dependencies.
102 * (1) how to do dma
103 * (2) timing based on turbochannel frequency
104 */
105
106 /*
107 * Fall through for turbochannel option.
108 */
109 asc->dmar = (volatile int *)(t->ta_addr + ASC_OFFSET_DMAR);
110 buff = (u_char *)(t->ta_addr + ASC_OFFSET_RAM);
111
112 /*
113 * Statically partition the DMA buffer between targets.
114 * This way we will eventually be able to attach/detach
115 * drives on-fly. And 18k/target is plenty for normal use.
116 */
117
118 /*
119 * Give each target its own DMA buffer region.
120 * We may want to try ping ponging buffers later.
121 */
122 for (i = 0; i < ASC_NCMD; i++)
123 asc->st[i].dmaBufAddr = buff + PER_TGT_DMA_SIZE * i;
124
125 asc->dma_start = tc_dma_start;
126 asc->dma_end = tc_dma_end;
127
128 /*
129 * Now for timing. The 3max has a 25Mhz tb whereas the 3min and
130 * maxine are 12.5Mhz.
131 */
132 printf(" (bus speed: %s MHz) ", t->ta_busspeed? "25" : "12.5");
133
134 switch (t->ta_busspeed) {
135 case TC_SPEED_25_MHZ:
136 speed = ASC_SPEED_25_MHZ;
137 break;
138
139 default:
140 printf(" (unknown TC speed, assuming 12.5MHz) ");
141 /* FALLTHROUGH*/
142 case TC_SPEED_12_5_MHZ:
143 speed = ASC_SPEED_12_5_MHZ;
144 break;
145 };
146
147 ascattach(asc, speed);
148
149 /* tie pseudo-slot to device */
150 tc_intr_establish(parent, t->ta_cookie, TC_IPL_BIO,
151 asc_intr, asc);
152 }
153
154
155 /*
156 * DMA handling routines. For a turbochannel device, just set the dmar.
157 * For the I/O ASIC, handle the actual DMA interface.
158 */
159 static int
160 tc_dma_start(asc, state, cp, flag, len, off)
161 asc_softc_t asc;
162 State *state;
163 caddr_t cp;
164 int flag;
165 int len;
166 int off;
167 {
168
169 if (len > PER_TGT_DMA_SIZE)
170 len = PER_TGT_DMA_SIZE;
171 if (flag == ASCDMA_WRITE)
172 bcopy(cp, state->dmaBufAddr + off, len);
173 if (flag == ASCDMA_WRITE)
174 *asc->dmar = ASC_DMAR_WRITE | ASC_DMA_ADDR(state->dmaBufAddr + off);
175 else
176 *asc->dmar = ASC_DMA_ADDR(state->dmaBufAddr + off);
177 return (len);
178 }
179
180 static void
181 tc_dma_end(asc, state, flag)
182 asc_softc_t asc;
183 State *state;
184 int flag;
185 {
186 if (flag == ASCDMA_READ)
187 bcopy(state->dmaBufAddr, state->buf, state->dmalen);
188 }
189