wdc_obio.c revision 1.17.4.5 1 1.17.4.5 nathanw /* $NetBSD: wdc_obio.c,v 1.17.4.5 2002/10/18 02:38:36 nathanw Exp $ */
2 1.17.4.2 nathanw
3 1.17.4.2 nathanw /*-
4 1.17.4.2 nathanw * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.17.4.2 nathanw * All rights reserved.
6 1.17.4.2 nathanw *
7 1.17.4.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.17.4.2 nathanw * by Charles M. Hannum and by Onno van der Linden.
9 1.17.4.2 nathanw *
10 1.17.4.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.17.4.2 nathanw * modification, are permitted provided that the following conditions
12 1.17.4.2 nathanw * are met:
13 1.17.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.17.4.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.17.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.17.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.17.4.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.17.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.17.4.2 nathanw * must display the following acknowledgement:
20 1.17.4.2 nathanw * This product includes software developed by the NetBSD
21 1.17.4.2 nathanw * Foundation, Inc. and its contributors.
22 1.17.4.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.17.4.2 nathanw * contributors may be used to endorse or promote products derived
24 1.17.4.2 nathanw * from this software without specific prior written permission.
25 1.17.4.2 nathanw *
26 1.17.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.17.4.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.17.4.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.17.4.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.17.4.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.17.4.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.17.4.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.17.4.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.17.4.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.17.4.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.17.4.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.17.4.2 nathanw */
38 1.17.4.2 nathanw
39 1.17.4.2 nathanw #include <sys/param.h>
40 1.17.4.2 nathanw #include <sys/systm.h>
41 1.17.4.2 nathanw #include <sys/device.h>
42 1.17.4.2 nathanw #include <sys/malloc.h>
43 1.17.4.2 nathanw
44 1.17.4.2 nathanw #include <uvm/uvm_extern.h>
45 1.17.4.2 nathanw
46 1.17.4.2 nathanw #include <machine/bus.h>
47 1.17.4.2 nathanw #include <machine/autoconf.h>
48 1.17.4.2 nathanw
49 1.17.4.2 nathanw #include <dev/ata/atareg.h>
50 1.17.4.2 nathanw #include <dev/ata/atavar.h>
51 1.17.4.2 nathanw #include <dev/ic/wdcvar.h>
52 1.17.4.2 nathanw
53 1.17.4.2 nathanw #include <dev/ofw/openfirm.h>
54 1.17.4.2 nathanw
55 1.17.4.2 nathanw #include <macppc/dev/dbdma.h>
56 1.17.4.2 nathanw
57 1.17.4.2 nathanw #define WDC_REG_NPORTS 8
58 1.17.4.2 nathanw #define WDC_AUXREG_OFFSET 0x16
59 1.17.4.2 nathanw #define WDC_DEFAULT_PIO_IRQ 13 /* XXX */
60 1.17.4.2 nathanw #define WDC_DEFAULT_DMA_IRQ 2 /* XXX */
61 1.17.4.2 nathanw
62 1.17.4.2 nathanw #define WDC_OPTIONS_DMA 0x01
63 1.17.4.2 nathanw
64 1.17.4.2 nathanw /*
65 1.17.4.2 nathanw * XXX This code currently doesn't even try to allow 32-bit data port use.
66 1.17.4.2 nathanw */
67 1.17.4.2 nathanw
68 1.17.4.2 nathanw struct wdc_obio_softc {
69 1.17.4.2 nathanw struct wdc_softc sc_wdcdev;
70 1.17.4.2 nathanw struct channel_softc *wdc_chanptr;
71 1.17.4.2 nathanw struct channel_softc wdc_channel;
72 1.17.4.2 nathanw dbdma_regmap_t *sc_dmareg;
73 1.17.4.2 nathanw dbdma_command_t *sc_dmacmd;
74 1.17.4.2 nathanw u_int sc_dmaconf[2]; /* per target value of CONFIG_REG */
75 1.17.4.2 nathanw void *sc_ih;
76 1.17.4.2 nathanw };
77 1.17.4.2 nathanw
78 1.17.4.2 nathanw int wdc_obio_probe __P((struct device *, struct cfdata *, void *));
79 1.17.4.2 nathanw void wdc_obio_attach __P((struct device *, struct device *, void *));
80 1.17.4.2 nathanw int wdc_obio_detach __P((struct device *, int));
81 1.17.4.2 nathanw int wdc_obio_dma_init __P((void *, int, int, void *, size_t, int));
82 1.17.4.2 nathanw void wdc_obio_dma_start __P((void *, int, int));
83 1.17.4.2 nathanw int wdc_obio_dma_finish __P((void *, int, int, int));
84 1.17.4.2 nathanw
85 1.17.4.2 nathanw static void wdc_obio_select __P((struct channel_softc *, int));
86 1.17.4.2 nathanw static void adjust_timing __P((struct channel_softc *));
87 1.17.4.2 nathanw static void ata4_adjust_timing __P((struct channel_softc *));
88 1.17.4.2 nathanw
89 1.17.4.5 nathanw CFATTACH_DECL(wdc_obio, sizeof(struct wdc_obio_softc),
90 1.17.4.5 nathanw wdc_obio_probe, wdc_obio_attach, wdc_obio_detach, wdcactivate);
91 1.17.4.2 nathanw
92 1.17.4.2 nathanw int
93 1.17.4.2 nathanw wdc_obio_probe(parent, match, aux)
94 1.17.4.2 nathanw struct device *parent;
95 1.17.4.2 nathanw struct cfdata *match;
96 1.17.4.2 nathanw void *aux;
97 1.17.4.2 nathanw {
98 1.17.4.2 nathanw struct confargs *ca = aux;
99 1.17.4.2 nathanw char compat[32];
100 1.17.4.2 nathanw
101 1.17.4.2 nathanw /* XXX should not use name */
102 1.17.4.2 nathanw if (strcmp(ca->ca_name, "ATA") == 0 ||
103 1.17.4.2 nathanw strcmp(ca->ca_name, "ata") == 0 ||
104 1.17.4.2 nathanw strcmp(ca->ca_name, "ata0") == 0 ||
105 1.17.4.2 nathanw strcmp(ca->ca_name, "ide") == 0)
106 1.17.4.2 nathanw return 1;
107 1.17.4.2 nathanw
108 1.17.4.2 nathanw memset(compat, 0, sizeof(compat));
109 1.17.4.2 nathanw OF_getprop(ca->ca_node, "compatible", compat, sizeof(compat));
110 1.17.4.2 nathanw if (strcmp(compat, "heathrow-ata") == 0 ||
111 1.17.4.2 nathanw strcmp(compat, "keylargo-ata") == 0)
112 1.17.4.2 nathanw return 1;
113 1.17.4.2 nathanw
114 1.17.4.2 nathanw return 0;
115 1.17.4.2 nathanw }
116 1.17.4.2 nathanw
117 1.17.4.2 nathanw void
118 1.17.4.2 nathanw wdc_obio_attach(parent, self, aux)
119 1.17.4.2 nathanw struct device *parent, *self;
120 1.17.4.2 nathanw void *aux;
121 1.17.4.2 nathanw {
122 1.17.4.2 nathanw struct wdc_obio_softc *sc = (void *)self;
123 1.17.4.2 nathanw struct confargs *ca = aux;
124 1.17.4.2 nathanw struct channel_softc *chp = &sc->wdc_channel;
125 1.17.4.2 nathanw int intr;
126 1.17.4.2 nathanw int use_dma = 0;
127 1.17.4.2 nathanw char path[80];
128 1.17.4.2 nathanw
129 1.17.4.2 nathanw if (sc->sc_wdcdev.sc_dev.dv_cfdata->cf_flags & WDC_OPTIONS_DMA) {
130 1.17.4.2 nathanw if (ca->ca_nreg >= 16 || ca->ca_nintr == -1)
131 1.17.4.2 nathanw use_dma = 1; /* XXX Don't work yet. */
132 1.17.4.2 nathanw }
133 1.17.4.2 nathanw
134 1.17.4.2 nathanw if (ca->ca_nintr >= 4 && ca->ca_nreg >= 8) {
135 1.17.4.2 nathanw intr = ca->ca_intr[0];
136 1.17.4.2 nathanw printf(" irq %d", intr);
137 1.17.4.2 nathanw } else if (ca->ca_nintr == -1) {
138 1.17.4.2 nathanw intr = WDC_DEFAULT_PIO_IRQ;
139 1.17.4.2 nathanw printf(" irq property not found; using %d", intr);
140 1.17.4.2 nathanw } else {
141 1.17.4.2 nathanw printf(": couldn't get irq property\n");
142 1.17.4.2 nathanw return;
143 1.17.4.2 nathanw }
144 1.17.4.2 nathanw
145 1.17.4.2 nathanw if (use_dma)
146 1.17.4.2 nathanw printf(": DMA transfer");
147 1.17.4.2 nathanw
148 1.17.4.2 nathanw printf("\n");
149 1.17.4.2 nathanw
150 1.17.4.2 nathanw chp->cmd_iot = chp->ctl_iot =
151 1.17.4.2 nathanw macppc_make_bus_space_tag(ca->ca_baseaddr + ca->ca_reg[0], 4);
152 1.17.4.2 nathanw
153 1.17.4.2 nathanw if (bus_space_map(chp->cmd_iot, 0, WDC_REG_NPORTS, 0, &chp->cmd_ioh) ||
154 1.17.4.2 nathanw bus_space_subregion(chp->cmd_iot, chp->cmd_ioh,
155 1.17.4.2 nathanw WDC_AUXREG_OFFSET, 1, &chp->ctl_ioh)) {
156 1.17.4.2 nathanw printf("%s: couldn't map registers\n",
157 1.17.4.2 nathanw sc->sc_wdcdev.sc_dev.dv_xname);
158 1.17.4.2 nathanw return;
159 1.17.4.2 nathanw }
160 1.17.4.2 nathanw #if 0
161 1.17.4.2 nathanw chp->data32iot = chp->cmd_iot;
162 1.17.4.2 nathanw chp->data32ioh = chp->cmd_ioh;
163 1.17.4.2 nathanw #endif
164 1.17.4.2 nathanw
165 1.17.4.2 nathanw sc->sc_ih = intr_establish(intr, IST_LEVEL, IPL_BIO, wdcintr, chp);
166 1.17.4.2 nathanw
167 1.17.4.2 nathanw if (use_dma) {
168 1.17.4.2 nathanw sc->sc_dmacmd = dbdma_alloc(sizeof(dbdma_command_t) * 20);
169 1.17.4.2 nathanw sc->sc_dmareg = mapiodev(ca->ca_baseaddr + ca->ca_reg[2],
170 1.17.4.2 nathanw ca->ca_reg[3]);
171 1.17.4.2 nathanw sc->sc_wdcdev.cap |= WDC_CAPABILITY_DMA;
172 1.17.4.2 nathanw sc->sc_wdcdev.DMA_cap = 2;
173 1.17.4.2 nathanw if (strcmp(ca->ca_name, "ata-4") == 0) {
174 1.17.4.2 nathanw sc->sc_wdcdev.cap |= WDC_CAPABILITY_UDMA;
175 1.17.4.2 nathanw sc->sc_wdcdev.UDMA_cap = 4;
176 1.17.4.2 nathanw sc->sc_wdcdev.set_modes = ata4_adjust_timing;
177 1.17.4.2 nathanw } else {
178 1.17.4.2 nathanw sc->sc_wdcdev.set_modes = adjust_timing;
179 1.17.4.2 nathanw }
180 1.17.4.2 nathanw #ifdef notyet
181 1.17.4.2 nathanw /* Minimum cycle time is 150ns (DMA MODE 1) on ohare. */
182 1.17.4.2 nathanw if (ohare) {
183 1.17.4.2 nathanw sc->sc_wdcdev.PIO_cap = 3;
184 1.17.4.2 nathanw sc->sc_wdcdev.DMA_cap = 1;
185 1.17.4.2 nathanw }
186 1.17.4.2 nathanw #endif
187 1.17.4.2 nathanw } else {
188 1.17.4.2 nathanw /* all non-dma controllers can use adjust_timing */
189 1.17.4.2 nathanw sc->sc_wdcdev.set_modes = adjust_timing;
190 1.17.4.2 nathanw }
191 1.17.4.2 nathanw
192 1.17.4.2 nathanw sc->sc_wdcdev.PIO_cap = 4;
193 1.17.4.2 nathanw sc->sc_wdcdev.cap |= WDC_CAPABILITY_DATA16 | WDC_CAPABILITY_MODE;
194 1.17.4.2 nathanw sc->wdc_chanptr = chp;
195 1.17.4.2 nathanw sc->sc_wdcdev.channels = &sc->wdc_chanptr;
196 1.17.4.2 nathanw sc->sc_wdcdev.nchannels = 1;
197 1.17.4.2 nathanw sc->sc_wdcdev.dma_arg = sc;
198 1.17.4.2 nathanw sc->sc_wdcdev.dma_init = wdc_obio_dma_init;
199 1.17.4.2 nathanw sc->sc_wdcdev.dma_start = wdc_obio_dma_start;
200 1.17.4.2 nathanw sc->sc_wdcdev.dma_finish = wdc_obio_dma_finish;
201 1.17.4.2 nathanw chp->channel = 0;
202 1.17.4.2 nathanw chp->wdc = &sc->sc_wdcdev;
203 1.17.4.2 nathanw chp->ch_queue = malloc(sizeof(struct channel_queue),
204 1.17.4.2 nathanw M_DEVBUF, M_NOWAIT);
205 1.17.4.2 nathanw if (chp->ch_queue == NULL) {
206 1.17.4.2 nathanw printf("%s: can't allocate memory for command queue",
207 1.17.4.2 nathanw sc->sc_wdcdev.sc_dev.dv_xname);
208 1.17.4.2 nathanw return;
209 1.17.4.2 nathanw }
210 1.17.4.2 nathanw
211 1.17.4.2 nathanw #define OHARE_FEATURE_REG 0xf3000038
212 1.17.4.2 nathanw
213 1.17.4.2 nathanw /* XXX Enable wdc1 by feature reg. */
214 1.17.4.2 nathanw memset(path, 0, sizeof(path));
215 1.17.4.2 nathanw OF_package_to_path(ca->ca_node, path, sizeof(path));
216 1.17.4.2 nathanw if (strcmp(path, "/bandit@F2000000/ohare@10/ata@21000") == 0) {
217 1.17.4.2 nathanw u_int x;
218 1.17.4.2 nathanw
219 1.17.4.2 nathanw x = in32rb(OHARE_FEATURE_REG);
220 1.17.4.2 nathanw x |= 8;
221 1.17.4.2 nathanw out32rb(OHARE_FEATURE_REG, x);
222 1.17.4.2 nathanw }
223 1.17.4.2 nathanw
224 1.17.4.2 nathanw wdcattach(chp);
225 1.17.4.2 nathanw sc->sc_wdcdev.set_modes(chp);
226 1.17.4.2 nathanw
227 1.17.4.2 nathanw }
228 1.17.4.2 nathanw
229 1.17.4.2 nathanw /* Multiword DMA transfer timings */
230 1.17.4.2 nathanw struct ide_timings {
231 1.17.4.2 nathanw int cycle; /* minimum cycle time [ns] */
232 1.17.4.2 nathanw int active; /* minimum command active time [ns] */
233 1.17.4.2 nathanw };
234 1.17.4.2 nathanw static struct ide_timings pio_timing[5] = {
235 1.17.4.2 nathanw { 600, 180 }, /* Mode 0 */
236 1.17.4.2 nathanw { 390, 150 }, /* 1 */
237 1.17.4.2 nathanw { 240, 105 }, /* 2 */
238 1.17.4.2 nathanw { 180, 90 }, /* 3 */
239 1.17.4.2 nathanw { 120, 75 } /* 4 */
240 1.17.4.2 nathanw };
241 1.17.4.2 nathanw static struct ide_timings dma_timing[3] = {
242 1.17.4.2 nathanw { 480, 240 }, /* Mode 0 */
243 1.17.4.2 nathanw { 165, 90 }, /* Mode 1 */
244 1.17.4.2 nathanw { 120, 75 } /* Mode 2 */
245 1.17.4.2 nathanw };
246 1.17.4.2 nathanw
247 1.17.4.2 nathanw static struct ide_timings udma_timing[5] = {
248 1.17.4.2 nathanw {120, 180}, /* Mode 0 */
249 1.17.4.2 nathanw { 90, 150}, /* Mode 1 */
250 1.17.4.2 nathanw { 60, 120}, /* Mode 2 */
251 1.17.4.2 nathanw { 45, 90}, /* Mode 3 */
252 1.17.4.2 nathanw { 30, 90} /* Mode 4 */
253 1.17.4.2 nathanw };
254 1.17.4.2 nathanw
255 1.17.4.2 nathanw #define TIME_TO_TICK(time) howmany((time), 30)
256 1.17.4.2 nathanw #define PIO_REC_OFFSET 4
257 1.17.4.2 nathanw #define PIO_REC_MIN 1
258 1.17.4.2 nathanw #define PIO_ACT_MIN 1
259 1.17.4.2 nathanw #define DMA_REC_OFFSET 1
260 1.17.4.2 nathanw #define DMA_REC_MIN 1
261 1.17.4.2 nathanw #define DMA_ACT_MIN 1
262 1.17.4.2 nathanw
263 1.17.4.2 nathanw #define ATA4_TIME_TO_TICK(time) howmany((time), 15) /* 15 ns clock */
264 1.17.4.2 nathanw
265 1.17.4.2 nathanw #define CONFIG_REG (0x200 >> 4) /* IDE access timing register */
266 1.17.4.2 nathanw
267 1.17.4.2 nathanw void
268 1.17.4.2 nathanw wdc_obio_select(chp, drive)
269 1.17.4.2 nathanw struct channel_softc *chp;
270 1.17.4.2 nathanw int drive;
271 1.17.4.2 nathanw {
272 1.17.4.2 nathanw struct wdc_obio_softc *sc = (struct wdc_obio_softc *)chp->wdc;
273 1.17.4.2 nathanw bus_space_write_4(chp->cmd_iot, chp->cmd_ioh,
274 1.17.4.2 nathanw CONFIG_REG, sc->sc_dmaconf[drive]);
275 1.17.4.2 nathanw }
276 1.17.4.2 nathanw
277 1.17.4.2 nathanw void
278 1.17.4.2 nathanw adjust_timing(chp)
279 1.17.4.2 nathanw struct channel_softc *chp;
280 1.17.4.2 nathanw {
281 1.17.4.2 nathanw struct wdc_obio_softc *sc = (struct wdc_obio_softc *)chp->wdc;
282 1.17.4.2 nathanw int drive;
283 1.17.4.2 nathanw int min_cycle, min_active;
284 1.17.4.2 nathanw int cycle_tick, act_tick, inact_tick, half_tick;
285 1.17.4.2 nathanw
286 1.17.4.2 nathanw for (drive = 0; drive < 2; drive++) {
287 1.17.4.2 nathanw u_int conf = 0;
288 1.17.4.2 nathanw struct ata_drive_datas *drvp;
289 1.17.4.2 nathanw
290 1.17.4.2 nathanw drvp = &chp->ch_drive[drive];
291 1.17.4.2 nathanw /* set up pio mode timings */
292 1.17.4.2 nathanw if (drvp->drive_flags & DRIVE) {
293 1.17.4.2 nathanw int piomode = drvp->PIO_mode;
294 1.17.4.2 nathanw min_cycle = pio_timing[piomode].cycle;
295 1.17.4.2 nathanw min_active = pio_timing[piomode].active;
296 1.17.4.2 nathanw
297 1.17.4.2 nathanw cycle_tick = TIME_TO_TICK(min_cycle);
298 1.17.4.2 nathanw act_tick = TIME_TO_TICK(min_active);
299 1.17.4.2 nathanw if (act_tick < PIO_ACT_MIN)
300 1.17.4.2 nathanw act_tick = PIO_ACT_MIN;
301 1.17.4.2 nathanw inact_tick = cycle_tick - act_tick - PIO_REC_OFFSET;
302 1.17.4.2 nathanw if (inact_tick < PIO_REC_MIN)
303 1.17.4.2 nathanw inact_tick = PIO_REC_MIN;
304 1.17.4.2 nathanw /* mask: 0x000007ff */
305 1.17.4.2 nathanw conf |= (inact_tick << 5) | act_tick;
306 1.17.4.2 nathanw }
307 1.17.4.2 nathanw /* Set up dma mode timings */
308 1.17.4.2 nathanw if (drvp->drive_flags & DRIVE_DMA) {
309 1.17.4.2 nathanw int dmamode = drvp->DMA_mode;
310 1.17.4.2 nathanw min_cycle = dma_timing[dmamode].cycle;
311 1.17.4.2 nathanw min_active = dma_timing[dmamode].active;
312 1.17.4.2 nathanw cycle_tick = TIME_TO_TICK(min_cycle);
313 1.17.4.2 nathanw act_tick = TIME_TO_TICK(min_active);
314 1.17.4.2 nathanw inact_tick = cycle_tick - act_tick - DMA_REC_OFFSET;
315 1.17.4.2 nathanw if (inact_tick < DMA_REC_MIN)
316 1.17.4.2 nathanw inact_tick = DMA_REC_MIN;
317 1.17.4.2 nathanw half_tick = 0; /* XXX */
318 1.17.4.2 nathanw /* mask: 0xfffff800 */
319 1.17.4.2 nathanw conf |=
320 1.17.4.2 nathanw (half_tick << 21) |
321 1.17.4.2 nathanw (inact_tick << 16) | (act_tick << 11);
322 1.17.4.2 nathanw }
323 1.17.4.4 nathanw #ifdef DEBUG
324 1.17.4.2 nathanw if (conf) {
325 1.17.4.2 nathanw printf("conf[%d] = 0x%x, cyc = %d (%d ns), act = %d (%d ns), inact = %d\n",
326 1.17.4.2 nathanw drive, conf, cycle_tick, min_cycle, act_tick, min_active, inact_tick);
327 1.17.4.2 nathanw }
328 1.17.4.4 nathanw #endif
329 1.17.4.2 nathanw sc->sc_dmaconf[drive] = conf;
330 1.17.4.2 nathanw }
331 1.17.4.2 nathanw sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_SELECT;
332 1.17.4.2 nathanw sc->sc_wdcdev.select = 0;
333 1.17.4.2 nathanw if (sc->sc_dmaconf[0]) {
334 1.17.4.2 nathanw wdc_obio_select(chp,0);
335 1.17.4.2 nathanw if (sc->sc_dmaconf[1] && (sc->sc_dmaconf[0] != sc->sc_dmaconf[1])) {
336 1.17.4.2 nathanw sc->sc_wdcdev.select = wdc_obio_select;
337 1.17.4.2 nathanw sc->sc_wdcdev.cap |= WDC_CAPABILITY_SELECT;
338 1.17.4.2 nathanw }
339 1.17.4.2 nathanw } else if (sc->sc_dmaconf[1]) {
340 1.17.4.2 nathanw wdc_obio_select(chp,1);
341 1.17.4.2 nathanw }
342 1.17.4.2 nathanw wdc_print_modes(chp);
343 1.17.4.2 nathanw }
344 1.17.4.2 nathanw
345 1.17.4.2 nathanw void
346 1.17.4.2 nathanw ata4_adjust_timing(chp)
347 1.17.4.2 nathanw struct channel_softc *chp;
348 1.17.4.2 nathanw {
349 1.17.4.2 nathanw struct wdc_obio_softc *sc = (struct wdc_obio_softc *)chp->wdc;
350 1.17.4.2 nathanw int drive;
351 1.17.4.2 nathanw int min_cycle, min_active;
352 1.17.4.2 nathanw int cycle_tick, act_tick, inact_tick;
353 1.17.4.2 nathanw
354 1.17.4.2 nathanw for (drive = 0; drive < 2; drive++) {
355 1.17.4.2 nathanw u_int conf = 0;
356 1.17.4.2 nathanw struct ata_drive_datas *drvp;
357 1.17.4.2 nathanw
358 1.17.4.2 nathanw drvp = &chp->ch_drive[drive];
359 1.17.4.2 nathanw /* set up pio mode timings */
360 1.17.4.2 nathanw
361 1.17.4.2 nathanw if (drvp->drive_flags & DRIVE) {
362 1.17.4.2 nathanw int piomode = drvp->PIO_mode;
363 1.17.4.2 nathanw min_cycle = pio_timing[piomode].cycle;
364 1.17.4.2 nathanw min_active = pio_timing[piomode].active;
365 1.17.4.2 nathanw
366 1.17.4.2 nathanw cycle_tick = ATA4_TIME_TO_TICK(min_cycle);
367 1.17.4.2 nathanw act_tick = ATA4_TIME_TO_TICK(min_active);
368 1.17.4.2 nathanw inact_tick = cycle_tick - act_tick;
369 1.17.4.2 nathanw /* mask: 0x000003ff */
370 1.17.4.2 nathanw conf |= (inact_tick << 5) | act_tick;
371 1.17.4.2 nathanw }
372 1.17.4.2 nathanw /* set up dma mode timings */
373 1.17.4.2 nathanw if (drvp->drive_flags & DRIVE_DMA) {
374 1.17.4.2 nathanw int dmamode = drvp->DMA_mode;
375 1.17.4.2 nathanw min_cycle = dma_timing[dmamode].cycle;
376 1.17.4.2 nathanw min_active = dma_timing[dmamode].active;
377 1.17.4.2 nathanw cycle_tick = ATA4_TIME_TO_TICK(min_cycle);
378 1.17.4.2 nathanw act_tick = ATA4_TIME_TO_TICK(min_active);
379 1.17.4.2 nathanw inact_tick = cycle_tick - act_tick;
380 1.17.4.2 nathanw /* mask: 0x001ffc00 */
381 1.17.4.2 nathanw conf |= (act_tick << 10) | (inact_tick << 15);
382 1.17.4.2 nathanw }
383 1.17.4.2 nathanw /* set up udma mode timings */
384 1.17.4.2 nathanw if (drvp->drive_flags & DRIVE_UDMA) {
385 1.17.4.2 nathanw int udmamode = drvp->UDMA_mode;
386 1.17.4.2 nathanw min_cycle = udma_timing[udmamode].cycle;
387 1.17.4.2 nathanw min_active = udma_timing[udmamode].active;
388 1.17.4.2 nathanw act_tick = ATA4_TIME_TO_TICK(min_active);
389 1.17.4.2 nathanw cycle_tick = ATA4_TIME_TO_TICK(min_cycle);
390 1.17.4.2 nathanw /* mask: 0x1ff00000 */
391 1.17.4.2 nathanw conf |= (cycle_tick << 21) | (act_tick << 25) | 0x100000;
392 1.17.4.2 nathanw }
393 1.17.4.4 nathanw #ifdef DEBUG
394 1.17.4.2 nathanw if (conf) {
395 1.17.4.2 nathanw printf("ata4 conf[%d] = 0x%x, cyc = %d (%d ns), act = %d (%d ns), inact = %d\n",
396 1.17.4.2 nathanw drive, conf, cycle_tick, min_cycle, act_tick, min_active, inact_tick);
397 1.17.4.2 nathanw }
398 1.17.4.4 nathanw #endif
399 1.17.4.2 nathanw sc->sc_dmaconf[drive] = conf;
400 1.17.4.2 nathanw }
401 1.17.4.2 nathanw sc->sc_wdcdev.cap &= ~WDC_CAPABILITY_SELECT;
402 1.17.4.2 nathanw sc->sc_wdcdev.select = 0;
403 1.17.4.2 nathanw if (sc->sc_dmaconf[0]) {
404 1.17.4.2 nathanw wdc_obio_select(chp,0);
405 1.17.4.2 nathanw if (sc->sc_dmaconf[1] && (sc->sc_dmaconf[0] != sc->sc_dmaconf[1])) {
406 1.17.4.2 nathanw sc->sc_wdcdev.select = wdc_obio_select;
407 1.17.4.2 nathanw sc->sc_wdcdev.cap |= WDC_CAPABILITY_SELECT;
408 1.17.4.2 nathanw }
409 1.17.4.2 nathanw } else if (sc->sc_dmaconf[1]) {
410 1.17.4.2 nathanw wdc_obio_select(chp,1);
411 1.17.4.2 nathanw }
412 1.17.4.2 nathanw wdc_print_modes(chp);
413 1.17.4.2 nathanw }
414 1.17.4.2 nathanw
415 1.17.4.2 nathanw int
416 1.17.4.2 nathanw wdc_obio_detach(self, flags)
417 1.17.4.2 nathanw struct device *self;
418 1.17.4.2 nathanw int flags;
419 1.17.4.2 nathanw {
420 1.17.4.2 nathanw struct wdc_obio_softc *sc = (void *)self;
421 1.17.4.2 nathanw int error;
422 1.17.4.2 nathanw
423 1.17.4.2 nathanw if ((error = wdcdetach(self, flags)) != 0)
424 1.17.4.2 nathanw return error;
425 1.17.4.2 nathanw
426 1.17.4.2 nathanw intr_disestablish(sc->sc_ih);
427 1.17.4.2 nathanw
428 1.17.4.2 nathanw free(sc->wdc_channel.ch_queue, M_DEVBUF);
429 1.17.4.2 nathanw
430 1.17.4.2 nathanw /* Unmap our i/o space. */
431 1.17.4.2 nathanw bus_space_unmap(chp->cmd_iot, chp->cmd_ioh, WDC_REG_NPORTS);
432 1.17.4.2 nathanw
433 1.17.4.2 nathanw /* Unmap DMA registers. */
434 1.17.4.2 nathanw /* XXX unmapiodev(sc->sc_dmareg); */
435 1.17.4.2 nathanw /* XXX free(sc->sc_dmacmd); */
436 1.17.4.2 nathanw
437 1.17.4.2 nathanw return 0;
438 1.17.4.2 nathanw }
439 1.17.4.2 nathanw
440 1.17.4.2 nathanw int
441 1.17.4.2 nathanw wdc_obio_dma_init(v, channel, drive, databuf, datalen, read)
442 1.17.4.2 nathanw void *v;
443 1.17.4.2 nathanw void *databuf;
444 1.17.4.2 nathanw size_t datalen;
445 1.17.4.2 nathanw int read;
446 1.17.4.2 nathanw {
447 1.17.4.2 nathanw struct wdc_obio_softc *sc = v;
448 1.17.4.2 nathanw vaddr_t va = (vaddr_t)databuf;
449 1.17.4.2 nathanw dbdma_command_t *cmdp;
450 1.17.4.2 nathanw u_int cmd, offset;
451 1.17.4.2 nathanw
452 1.17.4.2 nathanw cmdp = sc->sc_dmacmd;
453 1.17.4.2 nathanw cmd = read ? DBDMA_CMD_IN_MORE : DBDMA_CMD_OUT_MORE;
454 1.17.4.2 nathanw
455 1.17.4.2 nathanw offset = va & PGOFSET;
456 1.17.4.2 nathanw
457 1.17.4.2 nathanw /* if va is not page-aligned, setup the first page */
458 1.17.4.2 nathanw if (offset != 0) {
459 1.17.4.2 nathanw int rest = NBPG - offset; /* the rest of the page */
460 1.17.4.2 nathanw
461 1.17.4.2 nathanw if (datalen > rest) { /* if continues to next page */
462 1.17.4.2 nathanw DBDMA_BUILD(cmdp, cmd, 0, rest, vtophys(va),
463 1.17.4.2 nathanw DBDMA_INT_NEVER, DBDMA_WAIT_NEVER,
464 1.17.4.2 nathanw DBDMA_BRANCH_NEVER);
465 1.17.4.2 nathanw datalen -= rest;
466 1.17.4.2 nathanw va += rest;
467 1.17.4.2 nathanw cmdp++;
468 1.17.4.2 nathanw }
469 1.17.4.2 nathanw }
470 1.17.4.2 nathanw
471 1.17.4.2 nathanw /* now va is page-aligned */
472 1.17.4.2 nathanw while (datalen > NBPG) {
473 1.17.4.2 nathanw DBDMA_BUILD(cmdp, cmd, 0, NBPG, vtophys(va),
474 1.17.4.2 nathanw DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
475 1.17.4.2 nathanw datalen -= NBPG;
476 1.17.4.2 nathanw va += NBPG;
477 1.17.4.2 nathanw cmdp++;
478 1.17.4.2 nathanw }
479 1.17.4.2 nathanw
480 1.17.4.2 nathanw /* the last page (datalen <= NBPG here) */
481 1.17.4.2 nathanw cmd = read ? DBDMA_CMD_IN_LAST : DBDMA_CMD_OUT_LAST;
482 1.17.4.2 nathanw DBDMA_BUILD(cmdp, cmd, 0, datalen, vtophys(va),
483 1.17.4.2 nathanw DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
484 1.17.4.2 nathanw cmdp++;
485 1.17.4.2 nathanw
486 1.17.4.2 nathanw DBDMA_BUILD(cmdp, DBDMA_CMD_STOP, 0, 0, 0,
487 1.17.4.2 nathanw DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
488 1.17.4.2 nathanw
489 1.17.4.2 nathanw return 0;
490 1.17.4.2 nathanw }
491 1.17.4.2 nathanw
492 1.17.4.2 nathanw void
493 1.17.4.2 nathanw wdc_obio_dma_start(v, channel, drive)
494 1.17.4.2 nathanw void *v;
495 1.17.4.2 nathanw int channel, drive;
496 1.17.4.2 nathanw {
497 1.17.4.2 nathanw struct wdc_obio_softc *sc = v;
498 1.17.4.2 nathanw
499 1.17.4.2 nathanw dbdma_start(sc->sc_dmareg, sc->sc_dmacmd);
500 1.17.4.2 nathanw }
501 1.17.4.2 nathanw
502 1.17.4.2 nathanw int
503 1.17.4.2 nathanw wdc_obio_dma_finish(v, channel, drive, read)
504 1.17.4.2 nathanw void *v;
505 1.17.4.2 nathanw int channel, drive;
506 1.17.4.2 nathanw int read;
507 1.17.4.2 nathanw {
508 1.17.4.2 nathanw struct wdc_obio_softc *sc = v;
509 1.17.4.2 nathanw
510 1.17.4.2 nathanw dbdma_stop(sc->sc_dmareg);
511 1.17.4.2 nathanw return 0;
512 1.17.4.2 nathanw }
513