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