schide.c revision 1.1.6.2 1 1.1.6.2 rmind /* $NetBSD: schide.c,v 1.1.6.2 2011/03/05 20:53:57 rmind Exp $ */
2 1.1.6.2 rmind /* $OpenBSD: pciide.c,v 1.305 2009/11/01 01:50:15 dlg Exp $ */
3 1.1.6.2 rmind
4 1.1.6.2 rmind /*
5 1.1.6.2 rmind * Copyright (c) 1999, 2000, 2001 Manuel Bouyer.
6 1.1.6.2 rmind *
7 1.1.6.2 rmind * Redistribution and use in source and binary forms, with or without
8 1.1.6.2 rmind * modification, are permitted provided that the following conditions
9 1.1.6.2 rmind * are met:
10 1.1.6.2 rmind * 1. Redistributions of source code must retain the above copyright
11 1.1.6.2 rmind * notice, this list of conditions and the following disclaimer.
12 1.1.6.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
13 1.1.6.2 rmind * notice, this list of conditions and the following disclaimer in the
14 1.1.6.2 rmind * documentation and/or other materials provided with the distribution.
15 1.1.6.2 rmind *
16 1.1.6.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1.6.2 rmind * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1.6.2 rmind * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1.6.2 rmind * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1.6.2 rmind * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 1.1.6.2 rmind * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 1.1.6.2 rmind * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 1.1.6.2 rmind * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 1.1.6.2 rmind * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 1.1.6.2 rmind * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 1.1.6.2 rmind *
27 1.1.6.2 rmind */
28 1.1.6.2 rmind
29 1.1.6.2 rmind /*
30 1.1.6.2 rmind * Copyright (c) 1996, 1998 Christopher G. Demetriou. All rights reserved.
31 1.1.6.2 rmind *
32 1.1.6.2 rmind * Redistribution and use in source and binary forms, with or without
33 1.1.6.2 rmind * modification, are permitted provided that the following conditions
34 1.1.6.2 rmind * are met:
35 1.1.6.2 rmind * 1. Redistributions of source code must retain the above copyright
36 1.1.6.2 rmind * notice, this list of conditions and the following disclaimer.
37 1.1.6.2 rmind * 2. Redistributions in binary form must reproduce the above copyright
38 1.1.6.2 rmind * notice, this list of conditions and the following disclaimer in the
39 1.1.6.2 rmind * documentation and/or other materials provided with the distribution.
40 1.1.6.2 rmind * 3. All advertising materials mentioning features or use of this software
41 1.1.6.2 rmind * must display the following acknowledgement:
42 1.1.6.2 rmind * This product includes software developed by Christopher G. Demetriou
43 1.1.6.2 rmind * for the NetBSD Project.
44 1.1.6.2 rmind * 4. The name of the author may not be used to endorse or promote products
45 1.1.6.2 rmind * derived from this software without specific prior written permission
46 1.1.6.2 rmind *
47 1.1.6.2 rmind * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
48 1.1.6.2 rmind * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
49 1.1.6.2 rmind * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
50 1.1.6.2 rmind * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
51 1.1.6.2 rmind * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
52 1.1.6.2 rmind * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
53 1.1.6.2 rmind * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
54 1.1.6.2 rmind * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
55 1.1.6.2 rmind * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
56 1.1.6.2 rmind * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
57 1.1.6.2 rmind */
58 1.1.6.2 rmind
59 1.1.6.2 rmind #include <sys/cdefs.h>
60 1.1.6.2 rmind __KERNEL_RCSID(0, "$NetBSD: schide.c,v 1.1.6.2 2011/03/05 20:53:57 rmind Exp $");
61 1.1.6.2 rmind
62 1.1.6.2 rmind #include <sys/param.h>
63 1.1.6.2 rmind #include <sys/systm.h>
64 1.1.6.2 rmind
65 1.1.6.2 rmind #include <dev/pci/pcivar.h>
66 1.1.6.2 rmind #include <dev/pci/pcidevs.h>
67 1.1.6.2 rmind #include <dev/pci/pciidereg.h>
68 1.1.6.2 rmind #include <dev/pci/pciidevar.h>
69 1.1.6.2 rmind #include <dev/pci/pciide_sch_reg.h>
70 1.1.6.2 rmind
71 1.1.6.2 rmind static void sch_chip_map(struct pciide_softc*, struct pci_attach_args*);
72 1.1.6.2 rmind static void sch_setup_channel(struct ata_channel*);
73 1.1.6.2 rmind static int schide_match(device_t, cfdata_t, void *);
74 1.1.6.2 rmind static void schide_attach(device_t, device_t, void *);
75 1.1.6.2 rmind
76 1.1.6.2 rmind CFATTACH_DECL_NEW(schide, sizeof(struct pciide_softc),
77 1.1.6.2 rmind schide_match, schide_attach, NULL, NULL);
78 1.1.6.2 rmind
79 1.1.6.2 rmind static const struct pciide_product_desc pciide_sch_products[] = {
80 1.1.6.2 rmind { PCI_PRODUCT_INTEL_SCH_IDE,
81 1.1.6.2 rmind 0,
82 1.1.6.2 rmind "Intel SCH IDE Controller",
83 1.1.6.2 rmind sch_chip_map,
84 1.1.6.2 rmind },
85 1.1.6.2 rmind { 0,
86 1.1.6.2 rmind 0,
87 1.1.6.2 rmind NULL,
88 1.1.6.2 rmind NULL
89 1.1.6.2 rmind }
90 1.1.6.2 rmind };
91 1.1.6.2 rmind
92 1.1.6.2 rmind static int
93 1.1.6.2 rmind schide_match(device_t parent, cfdata_t match, void *aux)
94 1.1.6.2 rmind {
95 1.1.6.2 rmind struct pci_attach_args *pa = aux;
96 1.1.6.2 rmind
97 1.1.6.2 rmind if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_INTEL) {
98 1.1.6.2 rmind if (pciide_lookup_product(pa->pa_id, pciide_sch_products))
99 1.1.6.2 rmind return (2);
100 1.1.6.2 rmind }
101 1.1.6.2 rmind return (0);
102 1.1.6.2 rmind }
103 1.1.6.2 rmind
104 1.1.6.2 rmind static void
105 1.1.6.2 rmind schide_attach(device_t parent, device_t self, void *aux)
106 1.1.6.2 rmind {
107 1.1.6.2 rmind struct pci_attach_args *pa = aux;
108 1.1.6.2 rmind struct pciide_softc *sc = device_private(self);
109 1.1.6.2 rmind
110 1.1.6.2 rmind sc->sc_wdcdev.sc_atac.atac_dev = self;
111 1.1.6.2 rmind
112 1.1.6.2 rmind pciide_common_attach(sc, pa,
113 1.1.6.2 rmind pciide_lookup_product(pa->pa_id, pciide_sch_products));
114 1.1.6.2 rmind
115 1.1.6.2 rmind }
116 1.1.6.2 rmind
117 1.1.6.2 rmind static void
118 1.1.6.2 rmind sch_chip_map(struct pciide_softc *sc, struct pci_attach_args *pa)
119 1.1.6.2 rmind {
120 1.1.6.2 rmind struct pciide_channel *cp;
121 1.1.6.2 rmind pcireg_t interface;
122 1.1.6.2 rmind int channel;
123 1.1.6.2 rmind
124 1.1.6.2 rmind if (pciide_chipen(sc, pa) == 0)
125 1.1.6.2 rmind return;
126 1.1.6.2 rmind
127 1.1.6.2 rmind aprint_verbose_dev(sc->sc_wdcdev.sc_atac.atac_dev,
128 1.1.6.2 rmind "bus-master DMA support present");
129 1.1.6.2 rmind pciide_mapreg_dma(sc, pa);
130 1.1.6.2 rmind aprint_verbose("\n");
131 1.1.6.2 rmind sc->sc_wdcdev.sc_atac.atac_cap = ATAC_CAP_DATA16 | ATAC_CAP_DATA32;
132 1.1.6.2 rmind
133 1.1.6.2 rmind if (sc->sc_dma_ok) {
134 1.1.6.2 rmind sc->sc_wdcdev.sc_atac.atac_cap |= ATAC_CAP_DMA | ATAC_CAP_UDMA;
135 1.1.6.2 rmind sc->sc_wdcdev.irqack = pciide_irqack;
136 1.1.6.2 rmind }
137 1.1.6.2 rmind sc->sc_wdcdev.sc_atac.atac_pio_cap = 4;
138 1.1.6.2 rmind sc->sc_wdcdev.sc_atac.atac_dma_cap = 2;
139 1.1.6.2 rmind sc->sc_wdcdev.sc_atac.atac_udma_cap = 5;
140 1.1.6.2 rmind sc->sc_wdcdev.sc_atac.atac_set_modes = sch_setup_channel;
141 1.1.6.2 rmind sc->sc_wdcdev.sc_atac.atac_channels = sc->wdc_chanarray;
142 1.1.6.2 rmind sc->sc_wdcdev.sc_atac.atac_nchannels = 1;
143 1.1.6.2 rmind
144 1.1.6.2 rmind
145 1.1.6.2 rmind ATADEBUG_PRINT(("sch_setup_chip: old d0tim=0x%x, d1tim=0x%x\n",
146 1.1.6.2 rmind pci_conf_read(sc->sc_pc, sc->sc_tag, SCH_D0TIM),
147 1.1.6.2 rmind pci_conf_read(sc->sc_pc, sc->sc_tag, SCH_D1TIM)),
148 1.1.6.2 rmind DEBUG_PROBE);
149 1.1.6.2 rmind
150 1.1.6.2 rmind interface = PCI_INTERFACE(pa->pa_class);
151 1.1.6.2 rmind
152 1.1.6.2 rmind wdc_allocate_regs(&sc->sc_wdcdev);
153 1.1.6.2 rmind
154 1.1.6.2 rmind for (channel = 0; channel < sc->sc_wdcdev.sc_atac.atac_nchannels;
155 1.1.6.2 rmind channel++) {
156 1.1.6.2 rmind cp = &sc->pciide_channels[channel];
157 1.1.6.2 rmind if (pciide_chansetup(sc, channel, interface) == 0)
158 1.1.6.2 rmind continue;
159 1.1.6.2 rmind pciide_mapchan(pa, cp, interface, pciide_pci_intr);
160 1.1.6.2 rmind }
161 1.1.6.2 rmind
162 1.1.6.2 rmind ATADEBUG_PRINT(("sch_setup_chip: d0tim=0x%x, d1tim=0x%x\n",
163 1.1.6.2 rmind pci_conf_read(sc->sc_pc, sc->sc_tag, SCH_D0TIM),
164 1.1.6.2 rmind pci_conf_read(sc->sc_pc, sc->sc_tag, SCH_D1TIM)),
165 1.1.6.2 rmind DEBUG_PROBE);
166 1.1.6.2 rmind }
167 1.1.6.2 rmind
168 1.1.6.2 rmind static void
169 1.1.6.2 rmind sch_setup_channel(struct ata_channel *chp)
170 1.1.6.2 rmind {
171 1.1.6.2 rmind struct ata_drive_datas *drvp;
172 1.1.6.2 rmind u_int32_t tim, timaddr, idedma_ctl;
173 1.1.6.2 rmind struct atac_softc *atac = chp->ch_atac;
174 1.1.6.2 rmind struct pciide_channel *cp = CHAN_TO_PCHAN(chp);
175 1.1.6.2 rmind struct pciide_softc *sc = CHAN_TO_PCIIDE(chp);
176 1.1.6.2 rmind int drive, s;
177 1.1.6.2 rmind
178 1.1.6.2 rmind idedma_ctl = 0;
179 1.1.6.2 rmind
180 1.1.6.2 rmind /* setup DMA if needed */
181 1.1.6.2 rmind pciide_channel_dma_setup(cp);
182 1.1.6.2 rmind
183 1.1.6.2 rmind /* Per drive settings */
184 1.1.6.2 rmind for (drive = 0; drive < 2; drive++) {
185 1.1.6.2 rmind drvp = &chp->ch_drive[drive];
186 1.1.6.2 rmind /* If no drive, skip */
187 1.1.6.2 rmind if ((drvp->drive_flags & DRIVE) == 0)
188 1.1.6.2 rmind continue;
189 1.1.6.2 rmind
190 1.1.6.2 rmind timaddr = (drive == 0) ? SCH_D0TIM : SCH_D1TIM;
191 1.1.6.2 rmind tim = pci_conf_read(sc->sc_pc, sc->sc_tag, timaddr);
192 1.1.6.2 rmind tim &= ~SCH_TIM_MASK;
193 1.1.6.2 rmind
194 1.1.6.2 rmind if (((drvp->drive_flags & DRIVE_DMA) == 0 &&
195 1.1.6.2 rmind (drvp->drive_flags & DRIVE_UDMA) == 0))
196 1.1.6.2 rmind goto pio;
197 1.1.6.2 rmind
198 1.1.6.2 rmind /* add timing values, setup DMA if needed */
199 1.1.6.2 rmind if ((atac->atac_cap & ATAC_CAP_UDMA) &&
200 1.1.6.2 rmind (drvp->drive_flags & DRIVE_UDMA)) {
201 1.1.6.2 rmind /* use Ultra/DMA */
202 1.1.6.2 rmind tim |= (drvp->UDMA_mode << 16) | SCH_TIM_SYNCDMA;
203 1.1.6.2 rmind } else {
204 1.1.6.2 rmind /* use Multiword DMA */
205 1.1.6.2 rmind s = splbio();
206 1.1.6.2 rmind drvp->drive_flags &= ~DRIVE_UDMA;
207 1.1.6.2 rmind splx(s);
208 1.1.6.2 rmind tim &= ~SCH_TIM_SYNCDMA;
209 1.1.6.2 rmind }
210 1.1.6.2 rmind idedma_ctl |= IDEDMA_CTL_DRV_DMA(drive);
211 1.1.6.2 rmind
212 1.1.6.2 rmind pio: /* use PIO mode */
213 1.1.6.2 rmind
214 1.1.6.2 rmind tim |= (drvp->DMA_mode << 8) | (drvp->PIO_mode);
215 1.1.6.2 rmind pci_conf_write(sc->sc_pc, sc->sc_tag, timaddr, tim);
216 1.1.6.2 rmind }
217 1.1.6.2 rmind if (idedma_ctl != 0) {
218 1.1.6.2 rmind /* Add software bits in status register */
219 1.1.6.2 rmind bus_space_write_1(sc->sc_dma_iot, cp->dma_iohs[IDEDMA_CTL], 0,
220 1.1.6.2 rmind idedma_ctl);
221 1.1.6.2 rmind }
222 1.1.6.2 rmind }
223