viaide.c revision 1.67.2.2 1 1.67.2.2 uebayasi /* $NetBSD: viaide.c,v 1.67.2.2 2010/11/06 08:08:32 uebayasi Exp $ */
2 1.1 bouyer
3 1.1 bouyer /*
4 1.1 bouyer * Copyright (c) 1999, 2000, 2001 Manuel Bouyer.
5 1.1 bouyer *
6 1.1 bouyer * Redistribution and use in source and binary forms, with or without
7 1.1 bouyer * modification, are permitted provided that the following conditions
8 1.1 bouyer * are met:
9 1.1 bouyer * 1. Redistributions of source code must retain the above copyright
10 1.1 bouyer * notice, this list of conditions and the following disclaimer.
11 1.1 bouyer * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 bouyer * notice, this list of conditions and the following disclaimer in the
13 1.1 bouyer * documentation and/or other materials provided with the distribution.
14 1.1 bouyer *
15 1.1 bouyer * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 bouyer * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17 1.1 bouyer * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18 1.24 perry * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19 1.1 bouyer * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20 1.1 bouyer * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 1.1 bouyer * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 1.1 bouyer * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 1.1 bouyer * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24 1.1 bouyer * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 1.1 bouyer *
26 1.1 bouyer */
27 1.1 bouyer
28 1.25 lukem #include <sys/cdefs.h>
29 1.67.2.2 uebayasi __KERNEL_RCSID(0, "$NetBSD: viaide.c,v 1.67.2.2 2010/11/06 08:08:32 uebayasi Exp $");
30 1.25 lukem
31 1.1 bouyer #include <sys/param.h>
32 1.1 bouyer #include <sys/systm.h>
33 1.1 bouyer
34 1.1 bouyer #include <dev/pci/pcivar.h>
35 1.1 bouyer #include <dev/pci/pcidevs.h>
36 1.1 bouyer #include <dev/pci/pciidereg.h>
37 1.1 bouyer #include <dev/pci/pciidevar.h>
38 1.1 bouyer #include <dev/pci/pciide_apollo_reg.h>
39 1.1 bouyer
40 1.5 fvdl static int via_pcib_match(struct pci_attach_args *);
41 1.4 enami static void via_chip_map(struct pciide_softc *, struct pci_attach_args *);
42 1.50 phx static void via_mapchan(struct pci_attach_args *, struct pciide_channel *,
43 1.67.2.2 uebayasi pcireg_t, int (*)(void *));
44 1.56 phx static void via_mapregs_compat_native(struct pci_attach_args *,
45 1.67.2.2 uebayasi struct pciide_channel *);
46 1.35 bouyer static int via_sata_chip_map_common(struct pciide_softc *,
47 1.35 bouyer struct pci_attach_args *);
48 1.4 enami static void via_sata_chip_map(struct pciide_softc *,
49 1.35 bouyer struct pci_attach_args *, int);
50 1.35 bouyer static void via_sata_chip_map_6(struct pciide_softc *,
51 1.35 bouyer struct pci_attach_args *);
52 1.35 bouyer static void via_sata_chip_map_7(struct pciide_softc *,
53 1.35 bouyer struct pci_attach_args *);
54 1.35 bouyer static void via_sata_chip_map_new(struct pciide_softc *,
55 1.4 enami struct pci_attach_args *);
56 1.15 thorpej static void via_setup_channel(struct ata_channel *);
57 1.4 enami
58 1.53 cube static int viaide_match(device_t, cfdata_t, void *);
59 1.53 cube static void viaide_attach(device_t, device_t, void *);
60 1.4 enami static const struct pciide_product_desc *
61 1.4 enami viaide_lookup(pcireg_t);
62 1.67.2.1 uebayasi static bool viaide_suspend(device_t, const pmf_qual_t *);
63 1.67.2.1 uebayasi static bool viaide_resume(device_t, const pmf_qual_t *);
64 1.1 bouyer
65 1.53 cube CFATTACH_DECL_NEW(viaide, sizeof(struct pciide_softc),
66 1.1 bouyer viaide_match, viaide_attach, NULL, NULL);
67 1.1 bouyer
68 1.2 thorpej static const struct pciide_product_desc pciide_amd_products[] = {
69 1.1 bouyer { PCI_PRODUCT_AMD_PBC756_IDE,
70 1.1 bouyer 0,
71 1.59 jmcneill "AMD AMD756 IDE Controller",
72 1.1 bouyer via_chip_map
73 1.1 bouyer },
74 1.1 bouyer { PCI_PRODUCT_AMD_PBC766_IDE,
75 1.1 bouyer 0,
76 1.59 jmcneill "AMD AMD766 IDE Controller",
77 1.1 bouyer via_chip_map
78 1.1 bouyer },
79 1.1 bouyer { PCI_PRODUCT_AMD_PBC768_IDE,
80 1.1 bouyer 0,
81 1.59 jmcneill "AMD AMD768 IDE Controller",
82 1.1 bouyer via_chip_map
83 1.1 bouyer },
84 1.1 bouyer { PCI_PRODUCT_AMD_PBC8111_IDE,
85 1.1 bouyer 0,
86 1.59 jmcneill "AMD AMD8111 IDE Controller",
87 1.1 bouyer via_chip_map
88 1.1 bouyer },
89 1.38 isaki { PCI_PRODUCT_AMD_CS5536_IDE,
90 1.38 isaki 0,
91 1.59 jmcneill "AMD CS5536 IDE Controller",
92 1.38 isaki via_chip_map
93 1.38 isaki },
94 1.1 bouyer { 0,
95 1.1 bouyer 0,
96 1.1 bouyer NULL,
97 1.1 bouyer NULL
98 1.1 bouyer }
99 1.1 bouyer };
100 1.1 bouyer
101 1.2 thorpej static const struct pciide_product_desc pciide_nvidia_products[] = {
102 1.1 bouyer { PCI_PRODUCT_NVIDIA_NFORCE_ATA100,
103 1.1 bouyer 0,
104 1.1 bouyer "NVIDIA nForce IDE Controller",
105 1.1 bouyer via_chip_map
106 1.1 bouyer },
107 1.1 bouyer { PCI_PRODUCT_NVIDIA_NFORCE2_ATA133,
108 1.1 bouyer 0,
109 1.1 bouyer "NVIDIA nForce2 IDE Controller",
110 1.1 bouyer via_chip_map
111 1.1 bouyer },
112 1.20 jdolecek { PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133,
113 1.20 jdolecek 0,
114 1.20 jdolecek "NVIDIA nForce2 Ultra 400 IDE Controller",
115 1.20 jdolecek via_chip_map
116 1.20 jdolecek },
117 1.20 jdolecek { PCI_PRODUCT_NVIDIA_NFORCE2_400_SATA,
118 1.20 jdolecek 0,
119 1.20 jdolecek "NVIDIA nForce2 Ultra 400 Serial ATA Controller",
120 1.35 bouyer via_sata_chip_map_6
121 1.20 jdolecek },
122 1.10 fvdl { PCI_PRODUCT_NVIDIA_NFORCE3_ATA133,
123 1.10 fvdl 0,
124 1.10 fvdl "NVIDIA nForce3 IDE Controller",
125 1.10 fvdl via_chip_map
126 1.10 fvdl },
127 1.19 xtraeme { PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133,
128 1.19 xtraeme 0,
129 1.19 xtraeme "NVIDIA nForce3 250 IDE Controller",
130 1.19 xtraeme via_chip_map
131 1.19 xtraeme },
132 1.19 xtraeme { PCI_PRODUCT_NVIDIA_NFORCE3_250_SATA,
133 1.19 xtraeme 0,
134 1.19 xtraeme "NVIDIA nForce3 250 Serial ATA Controller",
135 1.35 bouyer via_sata_chip_map_6
136 1.19 xtraeme },
137 1.32 xtraeme { PCI_PRODUCT_NVIDIA_NFORCE3_250_SATA2,
138 1.32 xtraeme 0,
139 1.32 xtraeme "NVIDIA nForce3 250 Serial ATA Controller",
140 1.35 bouyer via_sata_chip_map_6
141 1.32 xtraeme },
142 1.21 kent { PCI_PRODUCT_NVIDIA_NFORCE4_ATA133,
143 1.21 kent 0,
144 1.21 kent "NVIDIA nForce4 IDE Controller",
145 1.21 kent via_chip_map
146 1.21 kent },
147 1.21 kent { PCI_PRODUCT_NVIDIA_NFORCE4_SATA1,
148 1.21 kent 0,
149 1.21 kent "NVIDIA nForce4 Serial ATA Controller",
150 1.35 bouyer via_sata_chip_map_6
151 1.21 kent },
152 1.21 kent { PCI_PRODUCT_NVIDIA_NFORCE4_SATA2,
153 1.21 kent 0,
154 1.21 kent "NVIDIA nForce4 Serial ATA Controller",
155 1.35 bouyer via_sata_chip_map_6
156 1.21 kent },
157 1.27 manu { PCI_PRODUCT_NVIDIA_NFORCE430_ATA133,
158 1.27 manu 0,
159 1.27 manu "NVIDIA nForce430 IDE Controller",
160 1.27 manu via_chip_map
161 1.27 manu },
162 1.27 manu { PCI_PRODUCT_NVIDIA_NFORCE430_SATA1,
163 1.27 manu 0,
164 1.27 manu "NVIDIA nForce430 Serial ATA Controller",
165 1.35 bouyer via_sata_chip_map_6
166 1.27 manu },
167 1.27 manu { PCI_PRODUCT_NVIDIA_NFORCE430_SATA2,
168 1.27 manu 0,
169 1.27 manu "NVIDIA nForce430 Serial ATA Controller",
170 1.35 bouyer via_sata_chip_map_6
171 1.27 manu },
172 1.30 xtraeme { PCI_PRODUCT_NVIDIA_MCP04_IDE,
173 1.30 xtraeme 0,
174 1.30 xtraeme "NVIDIA MCP04 IDE Controller",
175 1.30 xtraeme via_chip_map
176 1.30 xtraeme },
177 1.30 xtraeme { PCI_PRODUCT_NVIDIA_MCP04_SATA,
178 1.30 xtraeme 0,
179 1.31 xtraeme "NVIDIA MCP04 Serial ATA Controller",
180 1.35 bouyer via_sata_chip_map_6
181 1.30 xtraeme },
182 1.30 xtraeme { PCI_PRODUCT_NVIDIA_MCP04_SATA2,
183 1.30 xtraeme 0,
184 1.31 xtraeme "NVIDIA MCP04 Serial ATA Controller",
185 1.35 bouyer via_sata_chip_map_6
186 1.30 xtraeme },
187 1.30 xtraeme { PCI_PRODUCT_NVIDIA_MCP55_IDE,
188 1.30 xtraeme 0,
189 1.30 xtraeme "NVIDIA MCP55 IDE Controller",
190 1.30 xtraeme via_chip_map
191 1.30 xtraeme },
192 1.30 xtraeme { PCI_PRODUCT_NVIDIA_MCP55_SATA,
193 1.30 xtraeme 0,
194 1.31 xtraeme "NVIDIA MCP55 Serial ATA Controller",
195 1.35 bouyer via_sata_chip_map_6
196 1.30 xtraeme },
197 1.30 xtraeme { PCI_PRODUCT_NVIDIA_MCP55_SATA2,
198 1.30 xtraeme 0,
199 1.31 xtraeme "NVIDIA MCP55 Serial ATA Controller",
200 1.35 bouyer via_sata_chip_map_6
201 1.30 xtraeme },
202 1.33 xtraeme { PCI_PRODUCT_NVIDIA_MCP61_IDE,
203 1.33 xtraeme 0,
204 1.33 xtraeme "NVIDIA MCP61 IDE Controller",
205 1.33 xtraeme via_chip_map
206 1.33 xtraeme },
207 1.33 xtraeme { PCI_PRODUCT_NVIDIA_MCP65_IDE,
208 1.33 xtraeme 0,
209 1.33 xtraeme "NVIDIA MCP65 IDE Controller",
210 1.33 xtraeme via_chip_map
211 1.33 xtraeme },
212 1.46 xtraeme { PCI_PRODUCT_NVIDIA_MCP73_IDE,
213 1.46 xtraeme 0,
214 1.46 xtraeme "NVIDIA MCP73 IDE Controller",
215 1.46 xtraeme via_chip_map
216 1.46 xtraeme },
217 1.46 xtraeme { PCI_PRODUCT_NVIDIA_MCP77_IDE,
218 1.46 xtraeme 0,
219 1.46 xtraeme "NVIDIA MCP77 IDE Controller",
220 1.46 xtraeme via_chip_map
221 1.46 xtraeme },
222 1.33 xtraeme { PCI_PRODUCT_NVIDIA_MCP61_SATA,
223 1.33 xtraeme 0,
224 1.33 xtraeme "NVIDIA MCP61 Serial ATA Controller",
225 1.35 bouyer via_sata_chip_map_6
226 1.33 xtraeme },
227 1.33 xtraeme { PCI_PRODUCT_NVIDIA_MCP61_SATA2,
228 1.33 xtraeme 0,
229 1.33 xtraeme "NVIDIA MCP61 Serial ATA Controller",
230 1.35 bouyer via_sata_chip_map_6
231 1.33 xtraeme },
232 1.33 xtraeme { PCI_PRODUCT_NVIDIA_MCP61_SATA3,
233 1.33 xtraeme 0,
234 1.33 xtraeme "NVIDIA MCP61 Serial ATA Controller",
235 1.35 bouyer via_sata_chip_map_6
236 1.33 xtraeme },
237 1.33 xtraeme { PCI_PRODUCT_NVIDIA_MCP65_SATA,
238 1.33 xtraeme 0,
239 1.33 xtraeme "NVIDIA MCP65 Serial ATA Controller",
240 1.35 bouyer via_sata_chip_map_6
241 1.33 xtraeme },
242 1.33 xtraeme { PCI_PRODUCT_NVIDIA_MCP65_SATA2,
243 1.33 xtraeme 0,
244 1.33 xtraeme "NVIDIA MCP65 Serial ATA Controller",
245 1.35 bouyer via_sata_chip_map_6
246 1.33 xtraeme },
247 1.33 xtraeme { PCI_PRODUCT_NVIDIA_MCP65_SATA3,
248 1.33 xtraeme 0,
249 1.33 xtraeme "NVIDIA MCP65 Serial ATA Controller",
250 1.35 bouyer via_sata_chip_map_6
251 1.33 xtraeme },
252 1.33 xtraeme { PCI_PRODUCT_NVIDIA_MCP65_SATA4,
253 1.33 xtraeme 0,
254 1.33 xtraeme "NVIDIA MCP65 Serial ATA Controller",
255 1.35 bouyer via_sata_chip_map_6
256 1.33 xtraeme },
257 1.43 xtraeme { PCI_PRODUCT_NVIDIA_MCP67_IDE,
258 1.43 xtraeme 0,
259 1.43 xtraeme "NVIDIA MCP67 IDE Controller",
260 1.43 xtraeme via_chip_map,
261 1.43 xtraeme },
262 1.43 xtraeme { PCI_PRODUCT_NVIDIA_MCP67_SATA,
263 1.43 xtraeme 0,
264 1.43 xtraeme "NVIDIA MCP67 Serial ATA Controller",
265 1.43 xtraeme via_sata_chip_map_6,
266 1.43 xtraeme },
267 1.43 xtraeme { PCI_PRODUCT_NVIDIA_MCP67_SATA2,
268 1.43 xtraeme 0,
269 1.43 xtraeme "NVIDIA MCP67 Serial ATA Controller",
270 1.43 xtraeme via_sata_chip_map_6,
271 1.43 xtraeme },
272 1.43 xtraeme { PCI_PRODUCT_NVIDIA_MCP67_SATA3,
273 1.43 xtraeme 0,
274 1.43 xtraeme "NVIDIA MCP67 Serial ATA Controller",
275 1.43 xtraeme via_sata_chip_map_6,
276 1.43 xtraeme },
277 1.43 xtraeme { PCI_PRODUCT_NVIDIA_MCP67_SATA4,
278 1.43 xtraeme 0,
279 1.43 xtraeme "NVIDIA MCP67 Serial ATA Controller",
280 1.43 xtraeme via_sata_chip_map_6,
281 1.43 xtraeme },
282 1.1 bouyer { 0,
283 1.1 bouyer 0,
284 1.1 bouyer NULL,
285 1.1 bouyer NULL
286 1.1 bouyer }
287 1.1 bouyer };
288 1.1 bouyer
289 1.2 thorpej static const struct pciide_product_desc pciide_via_products[] = {
290 1.1 bouyer { PCI_PRODUCT_VIATECH_VT82C586_IDE,
291 1.1 bouyer 0,
292 1.1 bouyer NULL,
293 1.1 bouyer via_chip_map,
294 1.1 bouyer },
295 1.1 bouyer { PCI_PRODUCT_VIATECH_VT82C586A_IDE,
296 1.1 bouyer 0,
297 1.1 bouyer NULL,
298 1.1 bouyer via_chip_map,
299 1.1 bouyer },
300 1.42 xtraeme { PCI_PRODUCT_VIATECH_CX700_IDE,
301 1.42 xtraeme 0,
302 1.44 xtraeme NULL,
303 1.42 xtraeme via_chip_map,
304 1.42 xtraeme },
305 1.57 rmind { PCI_PRODUCT_VIATECH_CX700M2_IDE,
306 1.57 rmind 0,
307 1.57 rmind NULL,
308 1.57 rmind via_chip_map,
309 1.57 rmind },
310 1.23 abs { PCI_PRODUCT_VIATECH_VT6421_RAID,
311 1.22 abs 0,
312 1.23 abs "VIA Technologies VT6421 Serial RAID Controller",
313 1.35 bouyer via_sata_chip_map_new,
314 1.22 abs },
315 1.1 bouyer { PCI_PRODUCT_VIATECH_VT8237_SATA,
316 1.6 mycroft 0,
317 1.1 bouyer "VIA Technologies VT8237 SATA Controller",
318 1.35 bouyer via_sata_chip_map_7,
319 1.35 bouyer },
320 1.35 bouyer { PCI_PRODUCT_VIATECH_VT8237A_SATA,
321 1.35 bouyer 0,
322 1.35 bouyer "VIA Technologies VT8237A SATA Controller",
323 1.41 garbled via_sata_chip_map_7,
324 1.1 bouyer },
325 1.60 jmcneill { PCI_PRODUCT_VIATECH_VT8237A_SATA_2,
326 1.60 jmcneill 0,
327 1.60 jmcneill "VIA Technologies VT8237A (5337) SATA Controller",
328 1.60 jmcneill via_sata_chip_map_7,
329 1.60 jmcneill },
330 1.29 xtraeme { PCI_PRODUCT_VIATECH_VT8237R_SATA,
331 1.29 xtraeme 0,
332 1.29 xtraeme "VIA Technologies VT8237R SATA Controller",
333 1.63 jakllsch via_sata_chip_map_7,
334 1.29 xtraeme },
335 1.58 nonaka { PCI_PRODUCT_VIATECH_VT8237S_SATA,
336 1.58 nonaka 0,
337 1.58 nonaka "VIA Technologies VT8237S SATA Controller",
338 1.58 nonaka via_sata_chip_map_7,
339 1.58 nonaka },
340 1.1 bouyer { 0,
341 1.1 bouyer 0,
342 1.1 bouyer NULL,
343 1.1 bouyer NULL
344 1.1 bouyer }
345 1.1 bouyer };
346 1.1 bouyer
347 1.4 enami static const struct pciide_product_desc *
348 1.4 enami viaide_lookup(pcireg_t id)
349 1.4 enami {
350 1.4 enami
351 1.4 enami switch (PCI_VENDOR(id)) {
352 1.4 enami case PCI_VENDOR_VIATECH:
353 1.4 enami return (pciide_lookup_product(id, pciide_via_products));
354 1.4 enami
355 1.4 enami case PCI_VENDOR_AMD:
356 1.4 enami return (pciide_lookup_product(id, pciide_amd_products));
357 1.4 enami
358 1.4 enami case PCI_VENDOR_NVIDIA:
359 1.4 enami return (pciide_lookup_product(id, pciide_nvidia_products));
360 1.4 enami }
361 1.4 enami return (NULL);
362 1.4 enami }
363 1.4 enami
364 1.2 thorpej static int
365 1.53 cube viaide_match(device_t parent, cfdata_t match, void *aux)
366 1.1 bouyer {
367 1.1 bouyer struct pci_attach_args *pa = aux;
368 1.1 bouyer
369 1.4 enami if (viaide_lookup(pa->pa_id) != NULL)
370 1.4 enami return (2);
371 1.1 bouyer return (0);
372 1.1 bouyer }
373 1.1 bouyer
374 1.2 thorpej static void
375 1.53 cube viaide_attach(device_t parent, device_t self, void *aux)
376 1.1 bouyer {
377 1.1 bouyer struct pci_attach_args *pa = aux;
378 1.53 cube struct pciide_softc *sc = device_private(self);
379 1.4 enami const struct pciide_product_desc *pp;
380 1.1 bouyer
381 1.53 cube sc->sc_wdcdev.sc_atac.atac_dev = self;
382 1.53 cube
383 1.4 enami pp = viaide_lookup(pa->pa_id);
384 1.1 bouyer if (pp == NULL)
385 1.1 bouyer panic("viaide_attach");
386 1.1 bouyer pciide_common_attach(sc, pa, pp);
387 1.51 joerg
388 1.51 joerg if (!pmf_device_register(self, viaide_suspend, viaide_resume))
389 1.51 joerg aprint_error_dev(self, "couldn't establish power handler\n");
390 1.1 bouyer }
391 1.1 bouyer
392 1.5 fvdl static int
393 1.5 fvdl via_pcib_match(struct pci_attach_args *pa)
394 1.5 fvdl {
395 1.5 fvdl if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
396 1.5 fvdl PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_ISA &&
397 1.5 fvdl PCI_VENDOR(pa->pa_id) == PCI_VENDOR_VIATECH)
398 1.5 fvdl return (1);
399 1.5 fvdl return 0;
400 1.5 fvdl }
401 1.5 fvdl
402 1.51 joerg static bool
403 1.67.2.1 uebayasi viaide_suspend(device_t dv, const pmf_qual_t *qual)
404 1.51 joerg {
405 1.51 joerg struct pciide_softc *sc = device_private(dv);
406 1.51 joerg
407 1.51 joerg sc->sc_pm_reg[0] = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc));
408 1.51 joerg /* APO_DATATIM(sc) includes APO_UDMA(sc) */
409 1.51 joerg sc->sc_pm_reg[1] = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc));
410 1.51 joerg /* This two are VIA-only, but should be ignored by other devices. */
411 1.51 joerg sc->sc_pm_reg[2] = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc));
412 1.51 joerg sc->sc_pm_reg[3] = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_MISCTIM(sc));
413 1.51 joerg
414 1.51 joerg return true;
415 1.51 joerg }
416 1.51 joerg
417 1.51 joerg static bool
418 1.67.2.1 uebayasi viaide_resume(device_t dv, const pmf_qual_t *qual)
419 1.51 joerg {
420 1.51 joerg struct pciide_softc *sc = device_private(dv);
421 1.51 joerg
422 1.51 joerg pci_conf_write(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc),
423 1.51 joerg sc->sc_pm_reg[0]);
424 1.51 joerg pci_conf_write(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc),
425 1.51 joerg sc->sc_pm_reg[1]);
426 1.51 joerg /* This two are VIA-only, but should be ignored by other devices. */
427 1.51 joerg pci_conf_write(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc),
428 1.51 joerg sc->sc_pm_reg[2]);
429 1.51 joerg pci_conf_write(sc->sc_pc, sc->sc_tag, APO_MISCTIM(sc),
430 1.51 joerg sc->sc_pm_reg[3]);
431 1.51 joerg
432 1.51 joerg return true;
433 1.51 joerg }
434 1.51 joerg
435 1.2 thorpej static void
436 1.2 thorpej via_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
437 1.1 bouyer {
438 1.1 bouyer struct pciide_channel *cp;
439 1.1 bouyer pcireg_t interface = PCI_INTERFACE(pa->pa_class);
440 1.1 bouyer pcireg_t vendor = PCI_VENDOR(pa->pa_id);
441 1.1 bouyer int channel;
442 1.1 bouyer u_int32_t ideconf;
443 1.1 bouyer pcireg_t pcib_id, pcib_class;
444 1.5 fvdl struct pci_attach_args pcib_pa;
445 1.1 bouyer
446 1.1 bouyer if (pciide_chipen(sc, pa) == 0)
447 1.1 bouyer return;
448 1.1 bouyer
449 1.3 enami switch (vendor) {
450 1.1 bouyer case PCI_VENDOR_VIATECH:
451 1.1 bouyer /*
452 1.5 fvdl * get a PCI tag for the ISA bridge.
453 1.1 bouyer */
454 1.12 drochner if (pci_find_device(&pcib_pa, via_pcib_match) == 0)
455 1.5 fvdl goto unknown;
456 1.5 fvdl pcib_id = pcib_pa.pa_id;
457 1.5 fvdl pcib_class = pcib_pa.pa_class;
458 1.53 cube aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
459 1.53 cube "VIA Technologies ");
460 1.1 bouyer switch (PCI_PRODUCT(pcib_id)) {
461 1.1 bouyer case PCI_PRODUCT_VIATECH_VT82C586_ISA:
462 1.1 bouyer aprint_normal("VT82C586 (Apollo VP) ");
463 1.1 bouyer if(PCI_REVISION(pcib_class) >= 0x02) {
464 1.1 bouyer aprint_normal("ATA33 controller\n");
465 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
466 1.1 bouyer } else {
467 1.1 bouyer aprint_normal("controller\n");
468 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;
469 1.1 bouyer }
470 1.1 bouyer break;
471 1.1 bouyer case PCI_PRODUCT_VIATECH_VT82C596A:
472 1.1 bouyer aprint_normal("VT82C596A (Apollo Pro) ");
473 1.1 bouyer if (PCI_REVISION(pcib_class) >= 0x12) {
474 1.1 bouyer aprint_normal("ATA66 controller\n");
475 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
476 1.1 bouyer } else {
477 1.1 bouyer aprint_normal("ATA33 controller\n");
478 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 2;
479 1.1 bouyer }
480 1.1 bouyer break;
481 1.1 bouyer case PCI_PRODUCT_VIATECH_VT82C686A_ISA:
482 1.1 bouyer aprint_normal("VT82C686A (Apollo KX133) ");
483 1.1 bouyer if (PCI_REVISION(pcib_class) >= 0x40) {
484 1.1 bouyer aprint_normal("ATA100 controller\n");
485 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
486 1.1 bouyer } else {
487 1.1 bouyer aprint_normal("ATA66 controller\n");
488 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
489 1.1 bouyer }
490 1.1 bouyer break;
491 1.1 bouyer case PCI_PRODUCT_VIATECH_VT8231:
492 1.1 bouyer aprint_normal("VT8231 ATA100 controller\n");
493 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
494 1.1 bouyer break;
495 1.1 bouyer case PCI_PRODUCT_VIATECH_VT8233:
496 1.1 bouyer aprint_normal("VT8233 ATA100 controller\n");
497 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
498 1.1 bouyer break;
499 1.1 bouyer case PCI_PRODUCT_VIATECH_VT8233A:
500 1.1 bouyer aprint_normal("VT8233A ATA133 controller\n");
501 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
502 1.1 bouyer break;
503 1.1 bouyer case PCI_PRODUCT_VIATECH_VT8235:
504 1.1 bouyer aprint_normal("VT8235 ATA133 controller\n");
505 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
506 1.1 bouyer break;
507 1.5 fvdl case PCI_PRODUCT_VIATECH_VT8237:
508 1.1 bouyer aprint_normal("VT8237 ATA133 controller\n");
509 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
510 1.1 bouyer break;
511 1.40 mlelstv case PCI_PRODUCT_VIATECH_VT8237A_ISA:
512 1.40 mlelstv aprint_normal("VT8237A ATA133 controller\n");
513 1.40 mlelstv sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
514 1.40 mlelstv break;
515 1.64 jakllsch case PCI_PRODUCT_VIATECH_CX700:
516 1.44 xtraeme aprint_normal("CX700 ATA133 controller\n");
517 1.44 xtraeme sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
518 1.44 xtraeme break;
519 1.62 jakllsch case PCI_PRODUCT_VIATECH_VT8251:
520 1.62 jakllsch aprint_normal("VT8251 ATA133 controller\n");
521 1.62 jakllsch sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
522 1.62 jakllsch break;
523 1.1 bouyer default:
524 1.5 fvdl unknown:
525 1.1 bouyer aprint_normal("unknown VIA ATA controller\n");
526 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 0;
527 1.1 bouyer }
528 1.1 bouyer sc->sc_apo_regbase = APO_VIA_REGBASE;
529 1.1 bouyer break;
530 1.1 bouyer case PCI_VENDOR_AMD:
531 1.1 bouyer switch (sc->sc_pp->ide_product) {
532 1.11 bouyer case PCI_PRODUCT_AMD_PBC8111_IDE:
533 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
534 1.11 bouyer break;
535 1.45 xtraeme case PCI_PRODUCT_AMD_CS5536_IDE:
536 1.1 bouyer case PCI_PRODUCT_AMD_PBC766_IDE:
537 1.1 bouyer case PCI_PRODUCT_AMD_PBC768_IDE:
538 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
539 1.1 bouyer break;
540 1.1 bouyer default:
541 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 4;
542 1.1 bouyer }
543 1.1 bouyer sc->sc_apo_regbase = APO_AMD_REGBASE;
544 1.1 bouyer break;
545 1.1 bouyer case PCI_VENDOR_NVIDIA:
546 1.1 bouyer switch (sc->sc_pp->ide_product) {
547 1.1 bouyer case PCI_PRODUCT_NVIDIA_NFORCE_ATA100:
548 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
549 1.1 bouyer break;
550 1.1 bouyer case PCI_PRODUCT_NVIDIA_NFORCE2_ATA133:
551 1.20 jdolecek case PCI_PRODUCT_NVIDIA_NFORCE2_400_ATA133:
552 1.5 fvdl case PCI_PRODUCT_NVIDIA_NFORCE3_ATA133:
553 1.19 xtraeme case PCI_PRODUCT_NVIDIA_NFORCE3_250_ATA133:
554 1.21 kent case PCI_PRODUCT_NVIDIA_NFORCE4_ATA133:
555 1.28 xtraeme case PCI_PRODUCT_NVIDIA_NFORCE430_ATA133:
556 1.30 xtraeme case PCI_PRODUCT_NVIDIA_MCP04_IDE:
557 1.30 xtraeme case PCI_PRODUCT_NVIDIA_MCP55_IDE:
558 1.33 xtraeme case PCI_PRODUCT_NVIDIA_MCP61_IDE:
559 1.33 xtraeme case PCI_PRODUCT_NVIDIA_MCP65_IDE:
560 1.43 xtraeme case PCI_PRODUCT_NVIDIA_MCP67_IDE:
561 1.47 xtraeme case PCI_PRODUCT_NVIDIA_MCP73_IDE:
562 1.47 xtraeme case PCI_PRODUCT_NVIDIA_MCP77_IDE:
563 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
564 1.1 bouyer break;
565 1.1 bouyer }
566 1.1 bouyer sc->sc_apo_regbase = APO_NVIDIA_REGBASE;
567 1.1 bouyer break;
568 1.1 bouyer default:
569 1.1 bouyer panic("via_chip_map: unknown vendor");
570 1.1 bouyer }
571 1.3 enami
572 1.53 cube aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
573 1.53 cube "bus-master DMA support present");
574 1.1 bouyer pciide_mapreg_dma(sc, pa);
575 1.39 ad aprint_verbose("\n");
576 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
577 1.1 bouyer if (sc->sc_dma_ok) {
578 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA;
579 1.1 bouyer sc->sc_wdcdev.irqack = pciide_irqack;
580 1.17 thorpej if (sc->sc_wdcdev.sc_atac.atac_udma_cap > 0)
581 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA;
582 1.1 bouyer }
583 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
584 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
585 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_set_modes = via_setup_channel;
586 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
587 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
588 1.1 bouyer
589 1.41 garbled if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
590 1.41 garbled PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
591 1.41 garbled sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
592 1.41 garbled
593 1.15 thorpej wdc_allocate_regs(&sc->sc_wdcdev);
594 1.15 thorpej
595 1.14 thorpej ATADEBUG_PRINT(("via_chip_map: old APO_IDECONF=0x%x, "
596 1.1 bouyer "APO_CTLMISC=0x%x, APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
597 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc)),
598 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, APO_CTLMISC(sc)),
599 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
600 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))),
601 1.1 bouyer DEBUG_PROBE);
602 1.1 bouyer
603 1.1 bouyer ideconf = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_IDECONF(sc));
604 1.17 thorpej for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
605 1.17 thorpej channel++) {
606 1.1 bouyer cp = &sc->pciide_channels[channel];
607 1.1 bouyer if (pciide_chansetup(sc, channel, interface) == 0)
608 1.1 bouyer continue;
609 1.1 bouyer
610 1.1 bouyer if ((ideconf & APO_IDECONF_EN(channel)) == 0) {
611 1.53 cube aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
612 1.53 cube "%s channel ignored (disabled)\n", cp->name);
613 1.15 thorpej cp->ata_channel.ch_flags |= ATACH_DISABLED;
614 1.1 bouyer continue;
615 1.1 bouyer }
616 1.67.2.2 uebayasi via_mapchan(pa, cp, interface, pciide_pci_intr);
617 1.1 bouyer }
618 1.1 bouyer }
619 1.1 bouyer
620 1.2 thorpej static void
621 1.50 phx via_mapchan(struct pci_attach_args *pa, struct pciide_channel *cp,
622 1.67.2.2 uebayasi pcireg_t interface, int (*pci_intr)(void *))
623 1.50 phx {
624 1.50 phx struct ata_channel *wdc_cp;
625 1.50 phx struct pciide_softc *sc;
626 1.50 phx prop_bool_t compat_nat_enable;
627 1.50 phx
628 1.50 phx wdc_cp = &cp->ata_channel;
629 1.50 phx sc = CHAN_TO_PCIIDE(&cp->ata_channel);
630 1.50 phx compat_nat_enable = prop_dictionary_get(
631 1.53 cube device_properties(sc->sc_wdcdev.sc_atac.atac_dev),
632 1.53 cube "use-compat-native-irq");
633 1.50 phx
634 1.50 phx if (interface & PCIIDE_INTERFACE_PCI(wdc_cp->ch_channel)) {
635 1.50 phx /* native mode with irq 14/15 requested? */
636 1.50 phx if (compat_nat_enable != NULL &&
637 1.50 phx prop_bool_true(compat_nat_enable))
638 1.67.2.2 uebayasi via_mapregs_compat_native(pa, cp);
639 1.50 phx else
640 1.67.2.2 uebayasi pciide_mapregs_native(pa, cp, pci_intr);
641 1.50 phx } else {
642 1.67.2.2 uebayasi pciide_mapregs_compat(pa, cp, wdc_cp->ch_channel);
643 1.50 phx if ((cp->ata_channel.ch_flags & ATACH_DISABLED) == 0)
644 1.50 phx pciide_map_compat_intr(pa, cp, wdc_cp->ch_channel);
645 1.50 phx }
646 1.50 phx wdcattach(wdc_cp);
647 1.50 phx }
648 1.50 phx
649 1.50 phx /*
650 1.50 phx * At least under certain (mis)configurations (e.g. on the "Pegasos" board)
651 1.50 phx * the VT8231-IDE's native mode only works with irq 14/15, and cannot be
652 1.50 phx * programmed to use a single native PCI irq alone. So we install an interrupt
653 1.50 phx * handler for each channel, as in compatibility mode.
654 1.50 phx */
655 1.50 phx static void
656 1.56 phx via_mapregs_compat_native(struct pci_attach_args *pa,
657 1.67.2.2 uebayasi struct pciide_channel *cp)
658 1.50 phx {
659 1.50 phx struct ata_channel *wdc_cp;
660 1.50 phx struct pciide_softc *sc;
661 1.50 phx
662 1.50 phx wdc_cp = &cp->ata_channel;
663 1.50 phx sc = CHAN_TO_PCIIDE(&cp->ata_channel);
664 1.50 phx
665 1.50 phx /* XXX prevent pciide_mapregs_native from installing a handler */
666 1.50 phx if (sc->sc_pci_ih == NULL)
667 1.50 phx sc->sc_pci_ih = (void *)~0;
668 1.67.2.2 uebayasi pciide_mapregs_native(pa, cp, NULL);
669 1.50 phx
670 1.50 phx /* interrupts are fixed to 14/15, as in compatibility mode */
671 1.55 phx cp->compat = 1;
672 1.50 phx if ((wdc_cp->ch_flags & ATACH_DISABLED) == 0) {
673 1.50 phx #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
674 1.50 phx cp->ih = pciide_machdep_compat_intr_establish(
675 1.53 cube sc->sc_wdcdev.sc_atac.atac_dev, pa, wdc_cp->ch_channel,
676 1.55 phx pciide_compat_intr, cp);
677 1.50 phx if (cp->ih == NULL) {
678 1.50 phx #endif
679 1.53 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
680 1.53 cube "no compatibility interrupt for "
681 1.53 cube "use by %s channel\n", cp->name);
682 1.50 phx wdc_cp->ch_flags |= ATACH_DISABLED;
683 1.50 phx #ifdef __HAVE_PCIIDE_MACHDEP_COMPAT_INTR_ESTABLISH
684 1.50 phx }
685 1.50 phx sc->sc_pci_ih = cp->ih; /* XXX */
686 1.50 phx #endif
687 1.50 phx }
688 1.50 phx }
689 1.50 phx
690 1.50 phx static void
691 1.15 thorpej via_setup_channel(struct ata_channel *chp)
692 1.1 bouyer {
693 1.1 bouyer u_int32_t udmatim_reg, datatim_reg;
694 1.1 bouyer u_int8_t idedma_ctl;
695 1.18 thorpej int mode, drive, s;
696 1.1 bouyer struct ata_drive_datas *drvp;
697 1.17 thorpej struct atac_softc *atac = chp->ch_atac;
698 1.16 thorpej struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
699 1.16 thorpej struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
700 1.1 bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
701 1.1 bouyer int rev = PCI_REVISION(
702 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, PCI_CLASS_REG));
703 1.1 bouyer #endif
704 1.1 bouyer
705 1.1 bouyer idedma_ctl = 0;
706 1.1 bouyer datatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc));
707 1.1 bouyer udmatim_reg = pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc));
708 1.9 thorpej datatim_reg &= ~APO_DATATIM_MASK(chp->ch_channel);
709 1.9 thorpej udmatim_reg &= ~APO_UDMA_MASK(chp->ch_channel);
710 1.1 bouyer
711 1.1 bouyer /* setup DMA if needed */
712 1.1 bouyer pciide_channel_dma_setup(cp);
713 1.1 bouyer
714 1.1 bouyer for (drive = 0; drive < 2; drive++) {
715 1.1 bouyer drvp = &chp->ch_drive[drive];
716 1.1 bouyer /* If no drive, skip */
717 1.1 bouyer if ((drvp->drive_flags & DRIVE) == 0)
718 1.1 bouyer continue;
719 1.1 bouyer /* add timing values, setup DMA if needed */
720 1.1 bouyer if (((drvp->drive_flags & DRIVE_DMA) == 0 &&
721 1.1 bouyer (drvp->drive_flags & DRIVE_UDMA) == 0)) {
722 1.1 bouyer mode = drvp->PIO_mode;
723 1.1 bouyer goto pio;
724 1.1 bouyer }
725 1.17 thorpej if ((atac->atac_cap & ATAC_CAP_UDMA) &&
726 1.1 bouyer (drvp->drive_flags & DRIVE_UDMA)) {
727 1.1 bouyer /* use Ultra/DMA */
728 1.18 thorpej s = splbio();
729 1.1 bouyer drvp->drive_flags &= ~DRIVE_DMA;
730 1.18 thorpej splx(s);
731 1.9 thorpej udmatim_reg |= APO_UDMA_EN(chp->ch_channel, drive) |
732 1.9 thorpej APO_UDMA_EN_MTH(chp->ch_channel, drive);
733 1.3 enami switch (PCI_VENDOR(sc->sc_pci_id)) {
734 1.1 bouyer case PCI_VENDOR_VIATECH:
735 1.17 thorpej if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 6) {
736 1.1 bouyer /* 8233a */
737 1.1 bouyer udmatim_reg |= APO_UDMA_TIME(
738 1.9 thorpej chp->ch_channel,
739 1.1 bouyer drive,
740 1.1 bouyer via_udma133_tim[drvp->UDMA_mode]);
741 1.17 thorpej } else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 5) {
742 1.1 bouyer /* 686b */
743 1.1 bouyer udmatim_reg |= APO_UDMA_TIME(
744 1.9 thorpej chp->ch_channel,
745 1.1 bouyer drive,
746 1.1 bouyer via_udma100_tim[drvp->UDMA_mode]);
747 1.17 thorpej } else if (sc->sc_wdcdev.sc_atac.atac_udma_cap == 4) {
748 1.1 bouyer /* 596b or 686a */
749 1.1 bouyer udmatim_reg |= APO_UDMA_CLK66(
750 1.9 thorpej chp->ch_channel);
751 1.1 bouyer udmatim_reg |= APO_UDMA_TIME(
752 1.9 thorpej chp->ch_channel,
753 1.1 bouyer drive,
754 1.1 bouyer via_udma66_tim[drvp->UDMA_mode]);
755 1.1 bouyer } else {
756 1.1 bouyer /* 596a or 586b */
757 1.1 bouyer udmatim_reg |= APO_UDMA_TIME(
758 1.9 thorpej chp->ch_channel,
759 1.1 bouyer drive,
760 1.1 bouyer via_udma33_tim[drvp->UDMA_mode]);
761 1.1 bouyer }
762 1.1 bouyer break;
763 1.1 bouyer case PCI_VENDOR_AMD:
764 1.1 bouyer case PCI_VENDOR_NVIDIA:
765 1.9 thorpej udmatim_reg |= APO_UDMA_TIME(chp->ch_channel,
766 1.1 bouyer drive, amd7x6_udma_tim[drvp->UDMA_mode]);
767 1.1 bouyer break;
768 1.1 bouyer }
769 1.1 bouyer /* can use PIO timings, MW DMA unused */
770 1.1 bouyer mode = drvp->PIO_mode;
771 1.1 bouyer } else {
772 1.1 bouyer /* use Multiword DMA, but only if revision is OK */
773 1.18 thorpej s = splbio();
774 1.1 bouyer drvp->drive_flags &= ~DRIVE_UDMA;
775 1.18 thorpej splx(s);
776 1.1 bouyer #ifndef PCIIDE_AMD756_ENABLEDMA
777 1.1 bouyer /*
778 1.1 bouyer * The workaround doesn't seem to be necessary
779 1.1 bouyer * with all drives, so it can be disabled by
780 1.1 bouyer * PCIIDE_AMD756_ENABLEDMA. It causes a hard hang if
781 1.1 bouyer * triggered.
782 1.1 bouyer */
783 1.1 bouyer if (PCI_VENDOR(sc->sc_pci_id) == PCI_VENDOR_AMD &&
784 1.1 bouyer sc->sc_pp->ide_product ==
785 1.3 enami PCI_PRODUCT_AMD_PBC756_IDE &&
786 1.1 bouyer AMD756_CHIPREV_DISABLEDMA(rev)) {
787 1.1 bouyer aprint_normal(
788 1.1 bouyer "%s:%d:%d: multi-word DMA disabled due "
789 1.1 bouyer "to chip revision\n",
790 1.53 cube device_xname(
791 1.53 cube sc->sc_wdcdev.sc_atac.atac_dev),
792 1.9 thorpej chp->ch_channel, drive);
793 1.1 bouyer mode = drvp->PIO_mode;
794 1.18 thorpej s = splbio();
795 1.1 bouyer drvp->drive_flags &= ~DRIVE_DMA;
796 1.18 thorpej splx(s);
797 1.1 bouyer goto pio;
798 1.1 bouyer }
799 1.1 bouyer #endif
800 1.1 bouyer /* mode = min(pio, dma+2) */
801 1.3 enami if (drvp->PIO_mode <= (drvp->DMA_mode + 2))
802 1.1 bouyer mode = drvp->PIO_mode;
803 1.1 bouyer else
804 1.1 bouyer mode = drvp->DMA_mode + 2;
805 1.1 bouyer }
806 1.1 bouyer idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
807 1.1 bouyer
808 1.1 bouyer pio: /* setup PIO mode */
809 1.1 bouyer if (mode <= 2) {
810 1.1 bouyer drvp->DMA_mode = 0;
811 1.1 bouyer drvp->PIO_mode = 0;
812 1.1 bouyer mode = 0;
813 1.1 bouyer } else {
814 1.1 bouyer drvp->PIO_mode = mode;
815 1.1 bouyer drvp->DMA_mode = mode - 2;
816 1.1 bouyer }
817 1.1 bouyer datatim_reg |=
818 1.9 thorpej APO_DATATIM_PULSE(chp->ch_channel, drive,
819 1.1 bouyer apollo_pio_set[mode]) |
820 1.9 thorpej APO_DATATIM_RECOV(chp->ch_channel, drive,
821 1.1 bouyer apollo_pio_rec[mode]);
822 1.1 bouyer }
823 1.1 bouyer if (idedma_ctl != 0) {
824 1.1 bouyer /* Add software bits in status register */
825 1.7 fvdl bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
826 1.1 bouyer idedma_ctl);
827 1.1 bouyer }
828 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc), datatim_reg);
829 1.1 bouyer pci_conf_write(sc->sc_pc, sc->sc_tag, APO_UDMA(sc), udmatim_reg);
830 1.14 thorpej ATADEBUG_PRINT(("via_chip_map: APO_DATATIM=0x%x, APO_UDMA=0x%x\n",
831 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, APO_DATATIM(sc)),
832 1.1 bouyer pci_conf_read(sc->sc_pc, sc->sc_tag, APO_UDMA(sc))), DEBUG_PROBE);
833 1.1 bouyer }
834 1.1 bouyer
835 1.35 bouyer static int
836 1.35 bouyer via_sata_chip_map_common(struct pciide_softc *sc, struct pci_attach_args *pa)
837 1.1 bouyer {
838 1.36 bouyer int maptype, ret;
839 1.1 bouyer
840 1.1 bouyer if (pciide_chipen(sc, pa) == 0)
841 1.35 bouyer return 0;
842 1.1 bouyer
843 1.53 cube aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
844 1.53 cube "bus-master DMA support present");
845 1.1 bouyer pciide_mapreg_dma(sc, pa);
846 1.39 ad aprint_verbose("\n");
847 1.1 bouyer
848 1.1 bouyer if (sc->sc_dma_ok) {
849 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_UDMA | ATAC_CAP_DMA;
850 1.1 bouyer sc->sc_wdcdev.irqack = pciide_irqack;
851 1.1 bouyer }
852 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
853 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
854 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_udma_cap = 6;
855 1.17 thorpej
856 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
857 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_nchannels = PCIIDE_NUM_CHANNELS;
858 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
859 1.17 thorpej sc->sc_wdcdev.sc_atac.atac_set_modes = sata_setup_channel;
860 1.1 bouyer
861 1.41 garbled if (PCI_CLASS(pa->pa_class) == PCI_CLASS_MASS_STORAGE &&
862 1.41 garbled PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_MASS_STORAGE_RAID)
863 1.41 garbled sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_RAID;
864 1.41 garbled
865 1.15 thorpej wdc_allocate_regs(&sc->sc_wdcdev);
866 1.36 bouyer maptype = pci_mapreg_type(pa->pa_pc, pa->pa_tag,
867 1.36 bouyer PCI_MAPREG_START + 0x14);
868 1.36 bouyer switch(maptype) {
869 1.36 bouyer case PCI_MAPREG_TYPE_IO:
870 1.36 bouyer ret = pci_mapreg_map(pa, PCI_MAPREG_START + 0x14,
871 1.36 bouyer PCI_MAPREG_TYPE_IO, 0, &sc->sc_ba5_st, &sc->sc_ba5_sh,
872 1.67.2.2 uebayasi NULL, &sc->sc_ba5_ss);
873 1.36 bouyer break;
874 1.36 bouyer case PCI_MAPREG_MEM_TYPE_32BIT:
875 1.67.2.1 uebayasi /*
876 1.67.2.1 uebayasi * Enable memory-space access if it isn't already there.
877 1.67.2.1 uebayasi */
878 1.67.2.1 uebayasi if ((pa->pa_flags & PCI_FLAGS_MEM_ENABLED) == 0) {
879 1.67.2.1 uebayasi pcireg_t csr;
880 1.67.2.1 uebayasi
881 1.67.2.1 uebayasi pa->pa_flags |= PCI_FLAGS_MEM_ENABLED;
882 1.67.2.1 uebayasi csr = pci_conf_read(pa->pa_pc, pa->pa_tag,
883 1.67.2.1 uebayasi PCI_COMMAND_STATUS_REG);
884 1.67.2.1 uebayasi pci_conf_write(pa->pa_pc, pa->pa_tag,
885 1.67.2.1 uebayasi PCI_COMMAND_STATUS_REG,
886 1.67.2.1 uebayasi csr | PCI_COMMAND_MEM_ENABLE);
887 1.67.2.1 uebayasi }
888 1.67.2.1 uebayasi
889 1.36 bouyer ret = pci_mapreg_map(pa, PCI_MAPREG_START + 0x14,
890 1.35 bouyer PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT,
891 1.35 bouyer 0, &sc->sc_ba5_st, &sc->sc_ba5_sh,
892 1.67.2.2 uebayasi NULL, &sc->sc_ba5_ss);
893 1.36 bouyer break;
894 1.36 bouyer default:
895 1.53 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
896 1.54 dholland "couldn't map sata regs, unsupported maptype (0x%x)\n",
897 1.36 bouyer maptype);
898 1.36 bouyer return 0;
899 1.36 bouyer }
900 1.36 bouyer if (ret != 0) {
901 1.53 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
902 1.53 cube "couldn't map sata regs\n");
903 1.36 bouyer return 0;
904 1.35 bouyer }
905 1.35 bouyer return 1;
906 1.35 bouyer }
907 1.35 bouyer
908 1.35 bouyer static void
909 1.35 bouyer via_sata_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa,
910 1.35 bouyer int satareg_shift)
911 1.35 bouyer {
912 1.35 bouyer struct pciide_channel *cp;
913 1.35 bouyer struct ata_channel *wdc_cp;
914 1.35 bouyer struct wdc_regs *wdr;
915 1.35 bouyer pcireg_t interface = PCI_INTERFACE(pa->pa_class);
916 1.35 bouyer int channel;
917 1.35 bouyer
918 1.35 bouyer if (via_sata_chip_map_common(sc, pa) == 0)
919 1.35 bouyer return;
920 1.35 bouyer
921 1.35 bouyer if (interface == 0) {
922 1.35 bouyer ATADEBUG_PRINT(("via_sata_chip_map interface == 0\n"),
923 1.35 bouyer DEBUG_PROBE);
924 1.35 bouyer interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
925 1.35 bouyer PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
926 1.35 bouyer }
927 1.15 thorpej
928 1.17 thorpej for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
929 1.17 thorpej channel++) {
930 1.1 bouyer cp = &sc->pciide_channels[channel];
931 1.1 bouyer if (pciide_chansetup(sc, channel, interface) == 0)
932 1.1 bouyer continue;
933 1.35 bouyer wdc_cp = &cp->ata_channel;
934 1.35 bouyer wdr = CHAN_TO_WDC_REGS(wdc_cp);
935 1.35 bouyer wdr->sata_iot = sc->sc_ba5_st;
936 1.35 bouyer wdr->sata_baseioh = sc->sc_ba5_sh;
937 1.35 bouyer if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
938 1.64 jakllsch (wdc_cp->ch_channel << satareg_shift) + 0x0, 4,
939 1.35 bouyer &wdr->sata_status) != 0) {
940 1.53 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
941 1.53 cube "couldn't map channel %d sata_status regs\n",
942 1.35 bouyer wdc_cp->ch_channel);
943 1.35 bouyer continue;
944 1.35 bouyer }
945 1.35 bouyer if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
946 1.64 jakllsch (wdc_cp->ch_channel << satareg_shift) + 0x4, 4,
947 1.35 bouyer &wdr->sata_error) != 0) {
948 1.53 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
949 1.53 cube "couldn't map channel %d sata_error regs\n",
950 1.35 bouyer wdc_cp->ch_channel);
951 1.35 bouyer continue;
952 1.35 bouyer }
953 1.35 bouyer if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
954 1.64 jakllsch (wdc_cp->ch_channel << satareg_shift) + 0x8, 4,
955 1.35 bouyer &wdr->sata_control) != 0) {
956 1.53 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
957 1.53 cube "couldn't map channel %d sata_control regs\n",
958 1.35 bouyer wdc_cp->ch_channel);
959 1.35 bouyer continue;
960 1.35 bouyer }
961 1.35 bouyer sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
962 1.67.2.2 uebayasi pciide_mapchan(pa, cp, interface, pciide_pci_intr);
963 1.1 bouyer }
964 1.1 bouyer }
965 1.35 bouyer
966 1.35 bouyer static void
967 1.35 bouyer via_sata_chip_map_6(struct pciide_softc *sc, struct pci_attach_args *pa)
968 1.35 bouyer {
969 1.35 bouyer via_sata_chip_map(sc, pa, 6);
970 1.35 bouyer }
971 1.35 bouyer
972 1.35 bouyer static void
973 1.35 bouyer via_sata_chip_map_7(struct pciide_softc *sc, struct pci_attach_args *pa)
974 1.35 bouyer {
975 1.35 bouyer via_sata_chip_map(sc, pa, 7);
976 1.35 bouyer }
977 1.35 bouyer
978 1.35 bouyer static void
979 1.35 bouyer via_sata_chip_map_new(struct pciide_softc *sc, struct pci_attach_args *pa)
980 1.35 bouyer {
981 1.35 bouyer struct pciide_channel *cp;
982 1.35 bouyer struct ata_channel *wdc_cp;
983 1.35 bouyer struct wdc_regs *wdr;
984 1.35 bouyer pcireg_t interface = PCI_INTERFACE(pa->pa_class);
985 1.35 bouyer int channel;
986 1.35 bouyer pci_intr_handle_t intrhandle;
987 1.35 bouyer const char *intrstr;
988 1.35 bouyer int i;
989 1.35 bouyer
990 1.35 bouyer if (via_sata_chip_map_common(sc, pa) == 0)
991 1.35 bouyer return;
992 1.35 bouyer
993 1.35 bouyer if (interface == 0) {
994 1.35 bouyer ATADEBUG_PRINT(("via_sata_chip_map interface == 0\n"),
995 1.35 bouyer DEBUG_PROBE);
996 1.35 bouyer interface = PCIIDE_INTERFACE_BUS_MASTER_DMA |
997 1.35 bouyer PCIIDE_INTERFACE_PCI(0) | PCIIDE_INTERFACE_PCI(1);
998 1.35 bouyer }
999 1.35 bouyer
1000 1.35 bouyer if (pci_intr_map(pa, &intrhandle) != 0) {
1001 1.53 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
1002 1.53 cube "couldn't map native-PCI interrupt\n");
1003 1.35 bouyer return;
1004 1.35 bouyer }
1005 1.35 bouyer intrstr = pci_intr_string(pa->pa_pc, intrhandle);
1006 1.35 bouyer sc->sc_pci_ih = pci_intr_establish(pa->pa_pc,
1007 1.35 bouyer intrhandle, IPL_BIO, pciide_pci_intr, sc);
1008 1.35 bouyer if (sc->sc_pci_ih == NULL) {
1009 1.53 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
1010 1.53 cube "couldn't establish native-PCI interrupt");
1011 1.35 bouyer if (intrstr != NULL)
1012 1.35 bouyer aprint_error(" at %s", intrstr);
1013 1.35 bouyer aprint_error("\n");
1014 1.35 bouyer return;
1015 1.35 bouyer }
1016 1.53 cube aprint_normal_dev(sc->sc_wdcdev.sc_atac.atac_dev,
1017 1.53 cube "using %s for native-PCI interrupt\n",
1018 1.35 bouyer intrstr ? intrstr : "unknown interrupt");
1019 1.35 bouyer
1020 1.35 bouyer for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
1021 1.35 bouyer channel++) {
1022 1.35 bouyer cp = &sc->pciide_channels[channel];
1023 1.35 bouyer if (pciide_chansetup(sc, channel, interface) == 0)
1024 1.35 bouyer continue;
1025 1.35 bouyer cp->ata_channel.ch_ndrive = 1;
1026 1.35 bouyer wdc_cp = &cp->ata_channel;
1027 1.35 bouyer wdr = CHAN_TO_WDC_REGS(wdc_cp);
1028 1.35 bouyer
1029 1.35 bouyer wdr->sata_iot = sc->sc_ba5_st;
1030 1.35 bouyer wdr->sata_baseioh = sc->sc_ba5_sh;
1031 1.35 bouyer if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
1032 1.64 jakllsch (wdc_cp->ch_channel << 6) + 0x0, 4,
1033 1.35 bouyer &wdr->sata_status) != 0) {
1034 1.53 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
1035 1.53 cube "couldn't map channel %d sata_status regs\n",
1036 1.35 bouyer wdc_cp->ch_channel);
1037 1.35 bouyer continue;
1038 1.35 bouyer }
1039 1.35 bouyer if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
1040 1.64 jakllsch (wdc_cp->ch_channel << 6) + 0x4, 4,
1041 1.35 bouyer &wdr->sata_error) != 0) {
1042 1.53 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
1043 1.53 cube "couldn't map channel %d sata_error regs\n",
1044 1.35 bouyer wdc_cp->ch_channel);
1045 1.35 bouyer continue;
1046 1.35 bouyer }
1047 1.35 bouyer if (bus_space_subregion(wdr->sata_iot, wdr->sata_baseioh,
1048 1.64 jakllsch (wdc_cp->ch_channel << 6) + 0x8, 4,
1049 1.35 bouyer &wdr->sata_control) != 0) {
1050 1.53 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
1051 1.53 cube "couldn't map channel %d sata_control regs\n",
1052 1.35 bouyer wdc_cp->ch_channel);
1053 1.35 bouyer continue;
1054 1.35 bouyer }
1055 1.35 bouyer sc->sc_wdcdev.sc_atac.atac_probe = wdc_sataprobe;
1056 1.35 bouyer
1057 1.64 jakllsch if (pci_mapreg_map(pa, (PCI_MAPREG_START + (4 * (channel))),
1058 1.35 bouyer PCI_MAPREG_TYPE_IO, 0, &wdr->cmd_iot, &wdr->cmd_baseioh,
1059 1.67.2.2 uebayasi NULL, &wdr->cmd_ios) != 0) {
1060 1.53 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
1061 1.53 cube "couldn't map %s channel regs\n", cp->name);
1062 1.35 bouyer }
1063 1.35 bouyer wdr->ctl_iot = wdr->cmd_iot;
1064 1.35 bouyer for (i = 0; i < WDC_NREG; i++) {
1065 1.35 bouyer if (bus_space_subregion(wdr->cmd_iot,
1066 1.35 bouyer wdr->cmd_baseioh, i, i == 0 ? 4 : 1,
1067 1.35 bouyer &wdr->cmd_iohs[i]) != 0) {
1068 1.53 cube aprint_error_dev(
1069 1.53 cube sc->sc_wdcdev.sc_atac.atac_dev,
1070 1.53 cube "couldn't subregion %s "
1071 1.53 cube "channel cmd regs\n", cp->name);
1072 1.35 bouyer return;
1073 1.35 bouyer }
1074 1.35 bouyer }
1075 1.35 bouyer if (bus_space_subregion(wdr->cmd_iot, wdr->cmd_baseioh,
1076 1.35 bouyer WDC_NREG + 2, 1, &wdr->ctl_ioh) != 0) {
1077 1.53 cube aprint_error_dev(sc->sc_wdcdev.sc_atac.atac_dev,
1078 1.53 cube "couldn't map channel %d ctl regs\n", channel);
1079 1.35 bouyer return;
1080 1.35 bouyer }
1081 1.35 bouyer wdc_init_shadow_regs(wdc_cp);
1082 1.65 tsutsui wdr->data32iot = wdr->cmd_iot;
1083 1.65 tsutsui wdr->data32ioh = wdr->cmd_iohs[wd_data];
1084 1.35 bouyer wdcattach(wdc_cp);
1085 1.35 bouyer }
1086 1.35 bouyer }
1087