]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - sys/dev/ata/chipsets/ata-intel.c
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / sys / dev / ata / chipsets / ata-intel.c
1 /*-
2  * Copyright (c) 1998 - 2008 Søren Schmidt <sos@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10  *    without modification, immediately at the beginning of the file.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD$");
29
30 #include "opt_ata.h"
31 #include <sys/param.h>
32 #include <sys/module.h>
33 #include <sys/systm.h>
34 #include <sys/kernel.h>
35 #include <sys/ata.h>
36 #include <sys/bus.h>
37 #include <sys/endian.h>
38 #include <sys/malloc.h>
39 #include <sys/lock.h>
40 #include <sys/mutex.h>
41 #include <sys/sema.h>
42 #include <sys/taskqueue.h>
43 #include <vm/uma.h>
44 #include <machine/stdarg.h>
45 #include <machine/resource.h>
46 #include <machine/bus.h>
47 #include <sys/rman.h>
48 #include <dev/pci/pcivar.h>
49 #include <dev/pci/pcireg.h>
50 #include <dev/ata/ata-all.h>
51 #include <dev/ata/ata-pci.h>
52 #include <ata_if.h>
53
54 /* local prototypes */
55 static int ata_intel_chipinit(device_t dev);
56 static int ata_intel_chipdeinit(device_t dev);
57 static int ata_intel_ch_attach(device_t dev);
58 static void ata_intel_reset(device_t dev);
59 static int ata_intel_old_setmode(device_t dev, int target, int mode);
60 static int ata_intel_new_setmode(device_t dev, int target, int mode);
61 static int ata_intel_sch_setmode(device_t dev, int target, int mode);
62 static int ata_intel_sata_getrev(device_t dev, int target);
63 static int ata_intel_sata_status(device_t dev);
64 static int ata_intel_sata_ahci_read(device_t dev, int port,
65     int reg, u_int32_t *result);
66 static int ata_intel_sata_cscr_read(device_t dev, int port,
67     int reg, u_int32_t *result);
68 static int ata_intel_sata_sidpr_read(device_t dev, int port,
69     int reg, u_int32_t *result);
70 static int ata_intel_sata_ahci_write(device_t dev, int port,
71     int reg, u_int32_t result);
72 static int ata_intel_sata_cscr_write(device_t dev, int port,
73     int reg, u_int32_t result);
74 static int ata_intel_sata_sidpr_write(device_t dev, int port,
75     int reg, u_int32_t result);
76 static int ata_intel_sata_sidpr_test(device_t dev);
77 static int ata_intel_31244_ch_attach(device_t dev);
78 static int ata_intel_31244_ch_detach(device_t dev);
79 static int ata_intel_31244_status(device_t dev);
80 static void ata_intel_31244_tf_write(struct ata_request *request);
81 static void ata_intel_31244_reset(device_t dev);
82
83 /* misc defines */
84 #define INTEL_AHCI      1
85 #define INTEL_ICH5      2
86 #define INTEL_6CH       4
87 #define INTEL_6CH2      8
88 #define INTEL_ICH7      16
89
90 struct ata_intel_data {
91         struct mtx      lock;
92         u_char          smap[4];
93 };
94
95 #define ATA_INTEL_SMAP(ctlr, ch) \
96     &((struct ata_intel_data *)((ctlr)->chipset_data))->smap[(ch)->unit * 2]
97 #define ATA_INTEL_LOCK(ctlr) \
98     mtx_lock(&((struct ata_intel_data *)((ctlr)->chipset_data))->lock)
99 #define ATA_INTEL_UNLOCK(ctlr) \
100     mtx_unlock(&((struct ata_intel_data *)((ctlr)->chipset_data))->lock)
101
102 /*
103  * Intel chipset support functions
104  */
105 static int
106 ata_intel_probe(device_t dev)
107 {
108     struct ata_pci_controller *ctlr = device_get_softc(dev);
109     static const struct ata_chip_id ids[] =
110     {{ ATA_I82371FB,     0,          0, 2, ATA_WDMA2, "PIIX" },
111      { ATA_I82371SB,     0,          0, 2, ATA_WDMA2, "PIIX3" },
112      { ATA_I82371AB,     0,          0, 2, ATA_UDMA2, "PIIX4" },
113      { ATA_I82443MX,     0,          0, 2, ATA_UDMA2, "PIIX4" },
114      { ATA_I82451NX,     0,          0, 2, ATA_UDMA2, "PIIX4" },
115      { ATA_I82801AB,     0,          0, 2, ATA_UDMA2, "ICH0" },
116      { ATA_I82801AA,     0,          0, 2, ATA_UDMA4, "ICH" },
117      { ATA_I82372FB,     0,          0, 2, ATA_UDMA4, "ICH" },
118      { ATA_I82801BA,     0,          0, 2, ATA_UDMA5, "ICH2" },
119      { ATA_I82801BA_1,   0,          0, 2, ATA_UDMA5, "ICH2" },
120      { ATA_I82801CA,     0,          0, 2, ATA_UDMA5, "ICH3" },
121      { ATA_I82801CA_1,   0,          0, 2, ATA_UDMA5, "ICH3" },
122      { ATA_I82801DB,     0,          0, 2, ATA_UDMA5, "ICH4" },
123      { ATA_I82801DB_1,   0,          0, 2, ATA_UDMA5, "ICH4" },
124      { ATA_I82801EB,     0,          0, 2, ATA_UDMA5, "ICH5" },
125      { ATA_I82801EB_S1,  0, INTEL_ICH5, 2, ATA_SA150, "ICH5" },
126      { ATA_I82801EB_R1,  0, INTEL_ICH5, 2, ATA_SA150, "ICH5" },
127      { ATA_I6300ESB,     0,          0, 2, ATA_UDMA5, "6300ESB" },
128      { ATA_I6300ESB_S1,  0, INTEL_ICH5, 2, ATA_SA150, "6300ESB" },
129      { ATA_I6300ESB_R1,  0, INTEL_ICH5, 2, ATA_SA150, "6300ESB" },
130      { ATA_I82801FB,     0,          0, 2, ATA_UDMA5, "ICH6" },
131      { ATA_I82801FB_S1,  0, INTEL_AHCI, 0, ATA_SA150, "ICH6" },
132      { ATA_I82801FB_R1,  0, INTEL_AHCI, 0, ATA_SA150, "ICH6" },
133      { ATA_I82801FBM,    0, INTEL_AHCI, 0, ATA_SA150, "ICH6M" },
134      { ATA_I82801GB,     0,          0, 1, ATA_UDMA5, "ICH7" },
135      { ATA_I82801GB_S1,  0, INTEL_ICH7, 0, ATA_SA300, "ICH7" },
136      { ATA_I82801GB_R1,  0, INTEL_AHCI, 0, ATA_SA300, "ICH7" },
137      { ATA_I82801GB_AH,  0, INTEL_AHCI, 0, ATA_SA300, "ICH7" },
138      { ATA_I82801GBM_S1, 0, INTEL_ICH7, 0, ATA_SA150, "ICH7M" },
139      { ATA_I82801GBM_R1, 0, INTEL_AHCI, 0, ATA_SA150, "ICH7M" },
140      { ATA_I82801GBM_AH, 0, INTEL_AHCI, 0, ATA_SA150, "ICH7M" },
141      { ATA_I63XXESB2,    0,          0, 1, ATA_UDMA5, "63XXESB2" },
142      { ATA_I63XXESB2_S1, 0,          0, 0, ATA_SA300, "63XXESB2" },
143      { ATA_I63XXESB2_S2, 0, INTEL_AHCI, 0, ATA_SA300, "63XXESB2" },
144      { ATA_I63XXESB2_R1, 0, INTEL_AHCI, 0, ATA_SA300, "63XXESB2" },
145      { ATA_I63XXESB2_R2, 0, INTEL_AHCI, 0, ATA_SA300, "63XXESB2" },
146      { ATA_I82801HB_S1,  0, INTEL_6CH,  0, ATA_SA300, "ICH8" },
147      { ATA_I82801HB_S2,  0, INTEL_6CH2, 0, ATA_SA300, "ICH8" },
148      { ATA_I82801HB_R1,  0, INTEL_AHCI, 0, ATA_SA300, "ICH8" },
149      { ATA_I82801HB_AH4, 0, INTEL_AHCI, 0, ATA_SA300, "ICH8" },
150      { ATA_I82801HB_AH6, 0, INTEL_AHCI, 0, ATA_SA300, "ICH8" },
151      { ATA_I82801HBM,    0,          0, 1, ATA_UDMA5, "ICH8M" },
152      { ATA_I82801HBM_S1, 0, INTEL_6CH,  0, ATA_SA300, "ICH8M" },
153      { ATA_I82801HBM_S2, 0, INTEL_AHCI, 0, ATA_SA300, "ICH8M" },
154      { ATA_I82801HBM_S3, 0, INTEL_AHCI, 0, ATA_SA300, "ICH8M" },
155      { ATA_I82801IB_S1,  0, INTEL_6CH,  0, ATA_SA300, "ICH9" },
156      { ATA_I82801IB_S2,  0, INTEL_6CH2, 0, ATA_SA300, "ICH9" },
157      { ATA_I82801IB_S3,  0, INTEL_6CH2, 0, ATA_SA300, "ICH9" },
158      { ATA_I82801IB_AH4, 0, INTEL_AHCI, 0, ATA_SA300, "ICH9" },
159      { ATA_I82801IB_AH6, 0, INTEL_AHCI, 0, ATA_SA300, "ICH9" },
160      { ATA_I82801IB_R1,  0, INTEL_AHCI, 0, ATA_SA300, "ICH9" },
161      { ATA_I82801IBM_S1, 0, INTEL_6CH2, 0, ATA_SA300, "ICH9M" },
162      { ATA_I82801IBM_AH, 0, INTEL_AHCI, 0, ATA_SA300, "ICH9M" },
163      { ATA_I82801IBM_R1, 0, INTEL_AHCI, 0, ATA_SA300, "ICH9M" },
164      { ATA_I82801IBM_S2, 0, INTEL_6CH2, 0, ATA_SA300, "ICH9M" },
165      { ATA_I82801JIB_S1, 0, INTEL_6CH,  0, ATA_SA300, "ICH10" },
166      { ATA_I82801JIB_AH, 0, INTEL_AHCI, 0, ATA_SA300, "ICH10" },
167      { ATA_I82801JIB_R1, 0, INTEL_AHCI, 0, ATA_SA300, "ICH10" },
168      { ATA_I82801JIB_S2, 0, INTEL_6CH2, 0, ATA_SA300, "ICH10" },
169      { ATA_I82801JD_S1,  0, INTEL_6CH,  0, ATA_SA300, "ICH10" },
170      { ATA_I82801JD_AH,  0, INTEL_AHCI, 0, ATA_SA300, "ICH10" },
171      { ATA_I82801JD_R1,  0, INTEL_AHCI, 0, ATA_SA300, "ICH10" },
172      { ATA_I82801JD_S2,  0, INTEL_6CH2, 0, ATA_SA300, "ICH10" },
173      { ATA_I82801JI_S1,  0, INTEL_6CH,  0, ATA_SA300, "ICH10" },
174      { ATA_I82801JI_AH,  0, INTEL_AHCI, 0, ATA_SA300, "ICH10" },
175      { ATA_I82801JI_R1,  0, INTEL_AHCI, 0, ATA_SA300, "ICH10" },
176      { ATA_I82801JI_S2,  0, INTEL_6CH2, 0, ATA_SA300, "ICH10" },
177      { ATA_5Series_S1,   0, INTEL_6CH,  0, ATA_SA300, "5 Series/3400 Series PCH" },
178      { ATA_5Series_S2,   0, INTEL_6CH2, 0, ATA_SA300, "5 Series/3400 Series PCH" },
179      { ATA_5Series_AH1,  0, INTEL_AHCI, 0, ATA_SA300, "5 Series/3400 Series PCH" },
180      { ATA_5Series_AH2,  0, INTEL_AHCI, 0, ATA_SA300, "5 Series/3400 Series PCH" },
181      { ATA_5Series_R1,   0, INTEL_AHCI, 0, ATA_SA300, "5 Series/3400 Series PCH" },
182      { ATA_5Series_S3,   0, INTEL_6CH2, 0, ATA_SA300, "5 Series/3400 Series PCH" },
183      { ATA_5Series_S4,   0, INTEL_6CH,  0, ATA_SA300, "5 Series/3400 Series PCH" },
184      { ATA_5Series_AH3,  0, INTEL_AHCI, 0, ATA_SA300, "5 Series/3400 Series PCH" },
185      { ATA_5Series_R2,   0, INTEL_AHCI, 0, ATA_SA300, "5 Series/3400 Series PCH" },
186      { ATA_5Series_S5,   0, INTEL_6CH2, 0, ATA_SA300, "5 Series/3400 Series PCH" },
187      { ATA_5Series_S6,   0, INTEL_6CH,  0, ATA_SA300, "5 Series/3400 Series PCH" },
188      { ATA_5Series_AH4,  0, INTEL_AHCI, 0, ATA_SA300, "5 Series/3400 Series PCH" },
189      { ATA_CPT_S1,       0, INTEL_6CH,  0, ATA_SA300, "Cougar Point" },
190      { ATA_CPT_S2,       0, INTEL_6CH,  0, ATA_SA300, "Cougar Point" },
191      { ATA_CPT_AH1,      0, INTEL_AHCI, 0, ATA_SA300, "Cougar Point" },
192      { ATA_CPT_AH2,      0, INTEL_AHCI, 0, ATA_SA300, "Cougar Point" },
193      { ATA_CPT_R1,       0, INTEL_AHCI, 0, ATA_SA300, "Cougar Point" },
194      { ATA_CPT_R2,       0, INTEL_AHCI, 0, ATA_SA300, "Cougar Point" },
195      { ATA_CPT_S3,       0, INTEL_6CH2, 0, ATA_SA300, "Cougar Point" },
196      { ATA_CPT_S4,       0, INTEL_6CH2, 0, ATA_SA300, "Cougar Point" },
197      { ATA_PBG_S1,       0, INTEL_6CH,  0, ATA_SA300, "Patsburg" },
198      { ATA_PBG_AH1,      0, INTEL_AHCI, 0, ATA_SA300, "Patsburg" },
199      { ATA_PBG_R1,       0, INTEL_AHCI, 0, ATA_SA300, "Patsburg" },
200      { ATA_PBG_R2,       0, INTEL_AHCI, 0, ATA_SA300, "Patsburg" },
201      { ATA_PBG_R3,       0, INTEL_AHCI, 0, ATA_SA300, "Patsburg" },
202      { ATA_PBG_S2,       0, INTEL_6CH2, 0, ATA_SA300, "Patsburg" },
203      { ATA_PPT_S1,       0, INTEL_6CH,  0, ATA_SA300, "Panther Point" },
204      { ATA_PPT_S2,       0, INTEL_6CH,  0, ATA_SA300, "Panther Point" },
205      { ATA_PPT_AH1,      0, INTEL_AHCI, 0, ATA_SA300, "Panther Point" },
206      { ATA_PPT_AH2,      0, INTEL_AHCI, 0, ATA_SA300, "Panther Point" },
207      { ATA_PPT_R1,       0, INTEL_AHCI, 0, ATA_SA300, "Panther Point" },
208      { ATA_PPT_R2,       0, INTEL_AHCI, 0, ATA_SA300, "Panther Point" },
209      { ATA_PPT_R3,       0, INTEL_AHCI, 0, ATA_SA300, "Panther Point" },
210      { ATA_PPT_R4,       0, INTEL_AHCI, 0, ATA_SA300, "Panther Point" },
211      { ATA_PPT_S3,       0, INTEL_6CH2, 0, ATA_SA300, "Panther Point" },
212      { ATA_PPT_S4,       0, INTEL_6CH2, 0, ATA_SA300, "Panther Point" },
213      { ATA_PPT_R5,       0, INTEL_AHCI, 0, ATA_SA300, "Panther Point" },
214      { ATA_PPT_R6,       0, INTEL_AHCI, 0, ATA_SA300, "Panther Point" },
215      { ATA_LPT_S1,       0, INTEL_6CH,  0, ATA_SA300, "Lynx Point" },
216      { ATA_LPT_S2,       0, INTEL_6CH,  0, ATA_SA300, "Lynx Point" },
217      { ATA_LPT_AH1,      0, INTEL_AHCI, 0, ATA_SA300, "Lynx Point" },
218      { ATA_LPT_AH2,      0, INTEL_AHCI, 0, ATA_SA300, "Lynx Point" },
219      { ATA_LPT_R1,       0, INTEL_AHCI, 0, ATA_SA300, "Lynx Point" },
220      { ATA_LPT_R2,       0, INTEL_AHCI, 0, ATA_SA300, "Lynx Point" },
221      { ATA_LPT_R3,       0, INTEL_AHCI, 0, ATA_SA300, "Lynx Point" },
222      { ATA_LPT_R4,       0, INTEL_AHCI, 0, ATA_SA300, "Lynx Point" },
223      { ATA_LPT_S3,       0, INTEL_6CH2, 0, ATA_SA300, "Lynx Point" },
224      { ATA_LPT_S4,       0, INTEL_6CH2, 0, ATA_SA300, "Lynx Point" },
225      { ATA_LPT_R5,       0, INTEL_AHCI, 0, ATA_SA300, "Lynx Point" },
226      { ATA_LPT_R6,       0, INTEL_AHCI, 0, ATA_SA300, "Lynx Point" },
227      { ATA_I31244,       0,          0, 2, ATA_SA150, "31244" },
228      { ATA_ISCH,         0,          0, 1, ATA_UDMA5, "SCH" },
229      { ATA_DH89XXCC,     0, INTEL_AHCI, 0, ATA_SA300, "DH89xxCC" },
230      { 0, 0, 0, 0, 0, 0}};
231
232     if (pci_get_vendor(dev) != ATA_INTEL_ID)
233         return ENXIO;
234
235     if (!(ctlr->chip = ata_match_chip(dev, ids)))
236         return ENXIO;
237
238     ata_set_desc(dev);
239     ctlr->chipinit = ata_intel_chipinit;
240     ctlr->chipdeinit = ata_intel_chipdeinit;
241     return (BUS_PROBE_DEFAULT);
242 }
243
244 static int
245 ata_intel_chipinit(device_t dev)
246 {
247     struct ata_pci_controller *ctlr = device_get_softc(dev);
248     struct ata_intel_data *data;
249
250     if (ata_setup_interrupt(dev, ata_generic_intr))
251         return ENXIO;
252
253     data = malloc(sizeof(struct ata_intel_data), M_ATAPCI, M_WAITOK | M_ZERO);
254     mtx_init(&data->lock, "Intel SATA lock", NULL, MTX_DEF);
255     ctlr->chipset_data = (void *)data;
256
257     /* good old PIIX needs special treatment (not implemented) */
258     if (ctlr->chip->chipid == ATA_I82371FB) {
259         ctlr->setmode = ata_intel_old_setmode;
260     }
261
262     /* the intel 31244 needs special care if in DPA mode */
263     else if (ctlr->chip->chipid == ATA_I31244) {
264         if (pci_get_subclass(dev) != PCIS_STORAGE_IDE) {
265             ctlr->r_type2 = SYS_RES_MEMORY;
266             ctlr->r_rid2 = PCIR_BAR(0);
267             if (!(ctlr->r_res2 = bus_alloc_resource_any(dev, ctlr->r_type2,
268                                                         &ctlr->r_rid2,
269                                                         RF_ACTIVE)))
270                 return ENXIO;
271             ctlr->channels = 4;
272             ctlr->ch_attach = ata_intel_31244_ch_attach;
273             ctlr->ch_detach = ata_intel_31244_ch_detach;
274             ctlr->reset = ata_intel_31244_reset;
275         }
276         ctlr->setmode = ata_sata_setmode;
277         ctlr->getrev = ata_sata_getrev;
278     }
279     /* SCH */
280     else if (ctlr->chip->chipid == ATA_ISCH) {
281         ctlr->channels = 1;
282         ctlr->ch_attach = ata_intel_ch_attach;
283         ctlr->ch_detach = ata_pci_ch_detach;
284         ctlr->setmode = ata_intel_sch_setmode;
285     }
286     /* non SATA intel chips goes here */
287     else if (ctlr->chip->max_dma < ATA_SA150) {
288         ctlr->channels = ctlr->chip->cfg2;
289         ctlr->ch_attach = ata_intel_ch_attach;
290         ctlr->ch_detach = ata_pci_ch_detach;
291         ctlr->setmode = ata_intel_new_setmode;
292     }
293
294     /* SATA parts can be either compat or AHCI */
295     else {
296         /* force all ports active "the legacy way" */
297         pci_write_config(dev, 0x92, pci_read_config(dev, 0x92, 2) | 0x0f, 2);
298
299         ctlr->ch_attach = ata_intel_ch_attach;
300         ctlr->ch_detach = ata_pci_ch_detach;
301         ctlr->reset = ata_intel_reset;
302
303         /* 
304          * if we have AHCI capability and AHCI or RAID mode enabled
305          * in BIOS we try for AHCI mode
306          */ 
307         if ((ctlr->chip->cfg1 & INTEL_AHCI) &&
308             (pci_read_config(dev, 0x90, 1) & 0xc0) &&
309             (ata_ahci_chipinit(dev) != ENXIO))
310             return 0;
311
312         /* BAR(5) may point to SATA interface registers */
313         if ((ctlr->chip->cfg1 & INTEL_ICH7)) {
314                 ctlr->r_type2 = SYS_RES_MEMORY;
315                 ctlr->r_rid2 = PCIR_BAR(5);
316                 ctlr->r_res2 = bus_alloc_resource_any(dev, ctlr->r_type2,
317                     &ctlr->r_rid2, RF_ACTIVE);
318                 if (ctlr->r_res2 != NULL) {
319                         /* Set SCRAE bit to enable registers access. */
320                         pci_write_config(dev, 0x94,
321                             pci_read_config(dev, 0x94, 4) | (1 << 9), 4);
322                         /* Set Ports Implemented register bits. */
323                         ATA_OUTL(ctlr->r_res2, 0x0C,
324                             ATA_INL(ctlr->r_res2, 0x0C) | 0xf);
325                 }
326         /* Skip BAR(5) on ICH8M Apples, system locks up on access. */
327         } else if (ctlr->chip->chipid != ATA_I82801HBM_S1 ||
328             pci_get_subvendor(dev) != 0x106b) {
329                 ctlr->r_type2 = SYS_RES_IOPORT;
330                 ctlr->r_rid2 = PCIR_BAR(5);
331                 ctlr->r_res2 = bus_alloc_resource_any(dev, ctlr->r_type2,
332                     &ctlr->r_rid2, RF_ACTIVE);
333         }
334         if (ctlr->r_res2 != NULL ||
335             (ctlr->chip->cfg1 & INTEL_ICH5))
336                 ctlr->getrev = ata_intel_sata_getrev;
337         ctlr->setmode = ata_sata_setmode;
338     }
339     return 0;
340 }
341
342 static int
343 ata_intel_chipdeinit(device_t dev)
344 {
345         struct ata_pci_controller *ctlr = device_get_softc(dev);
346         struct ata_intel_data *data;
347
348         data = ctlr->chipset_data;
349         mtx_destroy(&data->lock);
350         free(data, M_ATAPCI);
351         ctlr->chipset_data = NULL;
352         return (0);
353 }
354
355 static int
356 ata_intel_ch_attach(device_t dev)
357 {
358         struct ata_pci_controller *ctlr;
359         struct ata_channel *ch;
360         u_char *smap;
361         u_int map;
362
363         /* setup the usual register normal pci style */
364         if (ata_pci_ch_attach(dev))
365                 return (ENXIO);
366
367         ctlr = device_get_softc(device_get_parent(dev));
368         ch = device_get_softc(dev);
369
370         /* if r_res2 is valid it points to SATA interface registers */
371         if (ctlr->r_res2) {
372                 ch->r_io[ATA_IDX_ADDR].res = ctlr->r_res2;
373                 ch->r_io[ATA_IDX_ADDR].offset = 0x00;
374                 ch->r_io[ATA_IDX_DATA].res = ctlr->r_res2;
375                 ch->r_io[ATA_IDX_DATA].offset = 0x04;
376         }
377
378         ch->flags |= ATA_ALWAYS_DMASTAT;
379         if (ctlr->chip->max_dma >= ATA_SA150) {
380                 smap = ATA_INTEL_SMAP(ctlr, ch);
381                 map = pci_read_config(device_get_parent(dev), 0x90, 1);
382                 if (ctlr->chip->cfg1 & INTEL_ICH5) {
383                         map &= 0x07;
384                         if ((map & 0x04) == 0) {
385                                 ch->flags |= ATA_SATA;
386                                 ch->flags |= ATA_NO_SLAVE;
387                                 smap[0] = (map & 0x01) ^ ch->unit;
388                                 smap[1] = 0;
389                         } else if ((map & 0x02) == 0 && ch->unit == 0) {
390                                 ch->flags |= ATA_SATA;
391                                 smap[0] = (map & 0x01) ? 1 : 0;
392                                 smap[1] = (map & 0x01) ? 0 : 1;
393                         } else if ((map & 0x02) != 0 && ch->unit == 1) {
394                                 ch->flags |= ATA_SATA;
395                                 smap[0] = (map & 0x01) ? 1 : 0;
396                                 smap[1] = (map & 0x01) ? 0 : 1;
397                         }
398                 } else if (ctlr->chip->cfg1 & INTEL_6CH2) {
399                         ch->flags |= ATA_SATA;
400                         ch->flags |= ATA_NO_SLAVE;
401                         smap[0] = (ch->unit == 0) ? 0 : 1;
402                         smap[1] = 0;
403                 } else {
404                         map &= 0x03;
405                         if (map == 0x00) {
406                                 ch->flags |= ATA_SATA;
407                                 smap[0] = (ch->unit == 0) ? 0 : 1;
408                                 smap[1] = (ch->unit == 0) ? 2 : 3;
409                         } else if (map == 0x02 && ch->unit == 0) {
410                                 ch->flags |= ATA_SATA;
411                                 smap[0] = 0;
412                                 smap[1] = 2;
413                         } else if (map == 0x01 && ch->unit == 1) {
414                                 ch->flags |= ATA_SATA;
415                                 smap[0] = 1;
416                                 smap[1] = 3;
417                         }
418                 }
419                 if (ch->flags & ATA_SATA) {
420                         if ((ctlr->chip->cfg1 & INTEL_ICH5)) {
421                                 ch->hw.pm_read = ata_intel_sata_cscr_read;
422                                 ch->hw.pm_write = ata_intel_sata_cscr_write;
423                         } else if (ctlr->r_res2) {
424                                 if ((ctlr->chip->cfg1 & INTEL_ICH7)) {
425                                         ch->hw.pm_read = ata_intel_sata_ahci_read;
426                                         ch->hw.pm_write = ata_intel_sata_ahci_write;
427                                 } else if (ata_intel_sata_sidpr_test(dev)) {
428                                         ch->hw.pm_read = ata_intel_sata_sidpr_read;
429                                         ch->hw.pm_write = ata_intel_sata_sidpr_write;
430                                 };
431                         }
432                         if (ch->hw.pm_write != NULL) {
433                                 ch->flags |= ATA_PERIODIC_POLL;
434                                 ch->hw.status = ata_intel_sata_status;
435                                 ata_sata_scr_write(ch, 0,
436                                     ATA_SERROR, 0xffffffff);
437                                 if ((ch->flags & ATA_NO_SLAVE) == 0) {
438                                         ata_sata_scr_write(ch, 1,
439                                             ATA_SERROR, 0xffffffff);
440                                 }
441                         }
442                 } else
443                         ctlr->setmode = ata_intel_new_setmode;
444         } else if (ctlr->chip->chipid != ATA_ISCH)
445                 ch->flags |= ATA_CHECKS_CABLE;
446         return (0);
447 }
448
449 static void
450 ata_intel_reset(device_t dev)
451 {
452         device_t parent = device_get_parent(dev);
453         struct ata_pci_controller *ctlr = device_get_softc(parent);
454         struct ata_channel *ch = device_get_softc(dev);
455         int mask, pshift, timeout, devs;
456         u_char *smap;
457         uint16_t pcs;
458
459         /* In combined mode, skip SATA stuff for PATA channel. */
460         if ((ch->flags & ATA_SATA) == 0)
461                 return (ata_generic_reset(dev));
462
463         /* Do hard-reset on respective SATA ports. */
464         smap = ATA_INTEL_SMAP(ctlr, ch);
465         mask = 1 << smap[0];
466         if ((ch->flags & ATA_NO_SLAVE) == 0)
467                 mask |= (1 << smap[1]);
468         pci_write_config(parent, 0x92,
469             pci_read_config(parent, 0x92, 2) & ~mask, 2);
470         DELAY(10);
471         pci_write_config(parent, 0x92,
472             pci_read_config(parent, 0x92, 2) | mask, 2);
473
474         /* Wait up to 1 sec for "connect well". */
475         if (ctlr->chip->cfg1 & (INTEL_6CH | INTEL_6CH2))
476                 pshift = 8;
477         else
478                 pshift = 4;
479         for (timeout = 0; timeout < 100 ; timeout++) {
480                 pcs = (pci_read_config(parent, 0x92, 2) >> pshift) & mask;
481                 if ((pcs == mask) && (ATA_IDX_INB(ch, ATA_STATUS) != 0xff))
482                         break;
483                 ata_udelay(10000);
484         }
485
486         if (bootverbose)
487                 device_printf(dev, "SATA reset: ports status=0x%02x\n", pcs);
488         /* If any device found, do soft-reset. */
489         if (ch->hw.pm_read != NULL) {
490                 devs = ata_sata_phy_reset(dev, 0, 2) ? ATA_ATA_MASTER : 0;
491                 if ((ch->flags & ATA_NO_SLAVE) == 0)
492                         devs |= ata_sata_phy_reset(dev, 1, 2) ?
493                             ATA_ATA_SLAVE : 0;
494         } else {
495                 devs = (pcs & (1 << smap[0])) ? ATA_ATA_MASTER : 0;
496                 if ((ch->flags & ATA_NO_SLAVE) == 0)
497                         devs |= (pcs & (1 << smap[1])) ?
498                             ATA_ATA_SLAVE : 0;
499         }
500         if (devs) {
501                 ata_generic_reset(dev);
502                 /* Reset may give fake slave when only ATAPI master present. */
503                 ch->devices &= (devs | (devs * ATA_ATAPI_MASTER));
504         } else
505                 ch->devices = 0;
506 }
507
508 static int
509 ata_intel_old_setmode(device_t dev, int target, int mode)
510 {
511         device_t parent = device_get_parent(dev);
512         struct ata_pci_controller *ctlr = device_get_softc(parent);
513
514         mode = min(mode, ctlr->chip->max_dma);
515         return (mode);
516 }
517
518 static int
519 ata_intel_new_setmode(device_t dev, int target, int mode)
520 {
521         device_t parent = device_get_parent(dev);
522         struct ata_pci_controller *ctlr = device_get_softc(parent);
523         struct ata_channel *ch = device_get_softc(dev);
524         int devno = (ch->unit << 1) + target;
525         int piomode;
526         u_int32_t reg40 = pci_read_config(parent, 0x40, 4);
527         u_int8_t reg44 = pci_read_config(parent, 0x44, 1);
528         u_int8_t reg48 = pci_read_config(parent, 0x48, 1);
529         u_int16_t reg4a = pci_read_config(parent, 0x4a, 2);
530         u_int16_t reg54 = pci_read_config(parent, 0x54, 2);
531         u_int32_t mask40 = 0, new40 = 0;
532         u_int8_t mask44 = 0, new44 = 0;
533         static const uint8_t timings[] =
534             { 0x00, 0x00, 0x10, 0x21, 0x23, 0x00, 0x21, 0x23 };
535         static const uint8_t utimings[] =
536             { 0x00, 0x01, 0x02, 0x01, 0x02, 0x01, 0x02 };
537
538         /* In combined mode, skip PATA stuff for SATA channel. */
539         if (ch->flags & ATA_SATA)
540                 return (ata_sata_setmode(dev, target, mode));
541
542         mode = min(mode, ctlr->chip->max_dma);
543         if (ata_dma_check_80pin && mode > ATA_UDMA2 &&
544             !(reg54 & (0x10 << devno))) {
545                 ata_print_cable(dev, "controller");
546                 mode = ATA_UDMA2;
547         }
548         /* Enable/disable UDMA and set timings. */
549         if (mode >= ATA_UDMA0) {
550             pci_write_config(parent, 0x48, reg48 | (0x0001 << devno), 2);
551             pci_write_config(parent, 0x4a,
552                 (reg4a & ~(0x3 << (devno << 2))) |
553                 (utimings[mode & ATA_MODE_MASK] << (devno<<2)), 2);
554             piomode = ATA_PIO4;
555         } else {
556             pci_write_config(parent, 0x48, reg48 & ~(0x0001 << devno), 2);
557             pci_write_config(parent, 0x4a, (reg4a & ~(0x3 << (devno << 2))),2);
558             piomode = mode;
559         }
560         reg54 |= 0x0400;
561         /* Set UDMA reference clock (33/66/133MHz). */
562         reg54 &= ~(0x1001 << devno);
563         if (mode >= ATA_UDMA5)
564             reg54 |= (0x1000 << devno);
565         else if (mode >= ATA_UDMA3)
566             reg54 |= (0x1 << devno);
567         pci_write_config(parent, 0x54, reg54, 2);
568         /* Allow PIO/WDMA timing controls. */
569         reg40 &= ~0x00ff00ff;
570         reg40 |= 0x40774077;
571         /* Set PIO/WDMA timings. */
572         if (target == 0) {
573             mask40 = 0x3300;
574             new40 = timings[ata_mode2idx(piomode)] << 8;
575         } else {
576             mask44 = 0x0f;
577             new44 = ((timings[ata_mode2idx(piomode)] & 0x30) >> 2) |
578                     (timings[ata_mode2idx(piomode)] & 0x03);
579         }
580         if (ch->unit) {
581             mask40 <<= 16;
582             new40 <<= 16;
583             mask44 <<= 4;
584             new44 <<= 4;
585         }
586         pci_write_config(parent, 0x40, (reg40 & ~mask40) | new40, 4);
587         pci_write_config(parent, 0x44, (reg44 & ~mask44) | new44, 1);
588         return (mode);
589 }
590
591 static int
592 ata_intel_sch_setmode(device_t dev, int target, int mode)
593 {
594         device_t parent = device_get_parent(dev);
595         struct ata_pci_controller *ctlr = device_get_softc(parent);
596         u_int8_t dtim = 0x80 + (target << 2);
597         u_int32_t tim = pci_read_config(parent, dtim, 4);
598         int piomode;
599
600         mode = min(mode, ctlr->chip->max_dma);
601         if (mode >= ATA_UDMA0) {
602                 tim |= (0x1 << 31);
603                 tim &= ~(0x7 << 16);
604                 tim |= ((mode & ATA_MODE_MASK) << 16);
605                 piomode = ATA_PIO4;
606         } else if (mode >= ATA_WDMA0) {
607                 tim &= ~(0x1 << 31);
608                 tim &= ~(0x3 << 8);
609                 tim |= ((mode & ATA_MODE_MASK) << 8);
610                 piomode = (mode == ATA_WDMA0) ? ATA_PIO0 :
611                     (mode == ATA_WDMA1) ? ATA_PIO3 : ATA_PIO4;
612         } else
613                 piomode = mode;
614         tim &= ~(0x7);
615         tim |= (piomode & 0x7);
616         pci_write_config(parent, dtim, tim, 4);
617         return (mode);
618 }
619
620 static int
621 ata_intel_sata_getrev(device_t dev, int target)
622 {
623         struct ata_channel *ch = device_get_softc(dev);
624         uint32_t status;
625
626         if (ata_sata_scr_read(ch, target, ATA_SSTATUS, &status) == 0)
627                 return ((status & 0x0f0) >> 4);
628         return (0xff);
629 }
630
631 static int
632 ata_intel_sata_status(device_t dev)
633 {
634         struct ata_channel *ch = device_get_softc(dev);
635
636         ata_sata_phy_check_events(dev, 0);
637         if ((ch->flags & ATA_NO_SLAVE) == 0)
638                 ata_sata_phy_check_events(dev, 1);
639
640         return ata_pci_status(dev);
641 }
642
643 static int
644 ata_intel_sata_ahci_read(device_t dev, int port, int reg, u_int32_t *result)
645 {
646         struct ata_pci_controller *ctlr;
647         struct ata_channel *ch;
648         device_t parent;
649         u_char *smap;
650         int offset;
651
652         parent = device_get_parent(dev);
653         ctlr = device_get_softc(parent);
654         ch = device_get_softc(dev);
655         port = (port == 1) ? 1 : 0;
656         smap = ATA_INTEL_SMAP(ctlr, ch);
657         offset = 0x100 + smap[port] * 0x80;
658         switch (reg) {
659         case ATA_SSTATUS:
660             reg = 0x28;
661             break;
662         case ATA_SCONTROL:
663             reg = 0x2c;
664             break;
665         case ATA_SERROR:
666             reg = 0x30;
667             break;
668         default:
669             return (EINVAL);
670         }
671         *result = ATA_INL(ctlr->r_res2, offset + reg);
672         return (0);
673 }
674
675 static int
676 ata_intel_sata_cscr_read(device_t dev, int port, int reg, u_int32_t *result)
677 {
678         struct ata_pci_controller *ctlr;
679         struct ata_channel *ch;
680         device_t parent;
681         u_char *smap;
682
683         parent = device_get_parent(dev);
684         ctlr = device_get_softc(parent);
685         ch = device_get_softc(dev);
686         smap = ATA_INTEL_SMAP(ctlr, ch);
687         port = (port == 1) ? 1 : 0;
688         switch (reg) {
689         case ATA_SSTATUS:
690             reg = 0;
691             break;
692         case ATA_SERROR:
693             reg = 1;
694             break;
695         case ATA_SCONTROL:
696             reg = 2;
697             break;
698         default:
699             return (EINVAL);
700         }
701         ATA_INTEL_LOCK(ctlr);
702         pci_write_config(parent, 0xa0,
703             0x50 + smap[port] * 0x10 + reg * 4, 4);
704         *result = pci_read_config(parent, 0xa4, 4);
705         ATA_INTEL_UNLOCK(ctlr);
706         return (0);
707 }
708
709 static int
710 ata_intel_sata_sidpr_read(device_t dev, int port, int reg, u_int32_t *result)
711 {
712         struct ata_pci_controller *ctlr;
713         struct ata_channel *ch;
714         device_t parent;
715
716         parent = device_get_parent(dev);
717         ctlr = device_get_softc(parent);
718         ch = device_get_softc(dev);
719         port = (port == 1) ? 1 : 0;
720         switch (reg) {
721         case ATA_SSTATUS:
722             reg = 0;
723             break;
724         case ATA_SCONTROL:
725             reg = 1;
726             break;
727         case ATA_SERROR:
728             reg = 2;
729             break;
730         default:
731             return (EINVAL);
732         }
733         ATA_INTEL_LOCK(ctlr);
734         ATA_IDX_OUTL(ch, ATA_IDX_ADDR, ((ch->unit * 2 + port) << 8) + reg);
735         *result = ATA_IDX_INL(ch, ATA_IDX_DATA);
736         ATA_INTEL_UNLOCK(ctlr);
737         return (0);
738 }
739
740 static int
741 ata_intel_sata_ahci_write(device_t dev, int port, int reg, u_int32_t value)
742 {
743         struct ata_pci_controller *ctlr;
744         struct ata_channel *ch;
745         device_t parent;
746         u_char *smap;
747         int offset;
748
749         parent = device_get_parent(dev);
750         ctlr = device_get_softc(parent);
751         ch = device_get_softc(dev);
752         port = (port == 1) ? 1 : 0;
753         smap = ATA_INTEL_SMAP(ctlr, ch);
754         offset = 0x100 + smap[port] * 0x80;
755         switch (reg) {
756         case ATA_SSTATUS:
757             reg = 0x28;
758             break;
759         case ATA_SCONTROL:
760             reg = 0x2c;
761             break;
762         case ATA_SERROR:
763             reg = 0x30;
764             break;
765         default:
766             return (EINVAL);
767         }
768         ATA_OUTL(ctlr->r_res2, offset + reg, value);
769         return (0);
770 }
771
772 static int
773 ata_intel_sata_cscr_write(device_t dev, int port, int reg, u_int32_t value)
774 {
775         struct ata_pci_controller *ctlr;
776         struct ata_channel *ch;
777         device_t parent;
778         u_char *smap;
779
780         parent = device_get_parent(dev);
781         ctlr = device_get_softc(parent);
782         ch = device_get_softc(dev);
783         smap = ATA_INTEL_SMAP(ctlr, ch);
784         port = (port == 1) ? 1 : 0;
785         switch (reg) {
786         case ATA_SSTATUS:
787             reg = 0;
788             break;
789         case ATA_SERROR:
790             reg = 1;
791             break;
792         case ATA_SCONTROL:
793             reg = 2;
794             break;
795         default:
796             return (EINVAL);
797         }
798         ATA_INTEL_LOCK(ctlr);
799         pci_write_config(parent, 0xa0,
800             0x50 + smap[port] * 0x10 + reg * 4, 4);
801         pci_write_config(parent, 0xa4, value, 4);
802         ATA_INTEL_UNLOCK(ctlr);
803         return (0);
804 }
805
806 static int
807 ata_intel_sata_sidpr_write(device_t dev, int port, int reg, u_int32_t value)
808 {
809         struct ata_pci_controller *ctlr;
810         struct ata_channel *ch;
811         device_t parent;
812
813         parent = device_get_parent(dev);
814         ctlr = device_get_softc(parent);
815         ch = device_get_softc(dev);
816         port = (port == 1) ? 1 : 0;
817         switch (reg) {
818         case ATA_SSTATUS:
819             reg = 0;
820             break;
821         case ATA_SCONTROL:
822             reg = 1;
823             break;
824         case ATA_SERROR:
825             reg = 2;
826             break;
827         default:
828             return (EINVAL);
829         }
830         ATA_INTEL_LOCK(ctlr);
831         ATA_IDX_OUTL(ch, ATA_IDX_ADDR, ((ch->unit * 2 + port) << 8) + reg);
832         ATA_IDX_OUTL(ch, ATA_IDX_DATA, value);
833         ATA_INTEL_UNLOCK(ctlr);
834         return (0);
835 }
836
837 static int
838 ata_intel_sata_sidpr_test(device_t dev)
839 {
840         struct ata_channel *ch = device_get_softc(dev);
841         int port;
842         uint32_t val;
843
844         port = (ch->flags & ATA_NO_SLAVE) ? 0 : 1;
845         for (; port >= 0; port--) {
846                 ata_intel_sata_sidpr_read(dev, port, ATA_SCONTROL, &val);
847                 if ((val & ATA_SC_IPM_MASK) ==
848                     (ATA_SC_IPM_DIS_PARTIAL | ATA_SC_IPM_DIS_SLUMBER))
849                         return (1);
850                 val |= ATA_SC_IPM_DIS_PARTIAL | ATA_SC_IPM_DIS_SLUMBER;
851                 ata_intel_sata_sidpr_write(dev, port, ATA_SCONTROL, val);
852                 ata_intel_sata_sidpr_read(dev, port, ATA_SCONTROL, &val);
853                 if ((val & ATA_SC_IPM_MASK) ==
854                     (ATA_SC_IPM_DIS_PARTIAL | ATA_SC_IPM_DIS_SLUMBER))
855                         return (1);
856         }
857         if (bootverbose)
858                 device_printf(dev,
859                     "SControl registers are not functional: %08x\n", val);
860         return (0);
861 }
862
863 static int
864 ata_intel_31244_ch_attach(device_t dev)
865 {
866     struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
867     struct ata_channel *ch = device_get_softc(dev);
868     int i;
869     int ch_offset;
870
871     ata_pci_dmainit(dev);
872
873     ch_offset = 0x200 + ch->unit * 0x200;
874
875     for (i = ATA_DATA; i < ATA_MAX_RES; i++)
876         ch->r_io[i].res = ctlr->r_res2;
877
878     /* setup ATA registers */
879     ch->r_io[ATA_DATA].offset = ch_offset + 0x00;
880     ch->r_io[ATA_FEATURE].offset = ch_offset + 0x06;
881     ch->r_io[ATA_COUNT].offset = ch_offset + 0x08;
882     ch->r_io[ATA_SECTOR].offset = ch_offset + 0x0c;
883     ch->r_io[ATA_CYL_LSB].offset = ch_offset + 0x10;
884     ch->r_io[ATA_CYL_MSB].offset = ch_offset + 0x14;
885     ch->r_io[ATA_DRIVE].offset = ch_offset + 0x18;
886     ch->r_io[ATA_COMMAND].offset = ch_offset + 0x1d;
887     ch->r_io[ATA_ERROR].offset = ch_offset + 0x04;
888     ch->r_io[ATA_STATUS].offset = ch_offset + 0x1c;
889     ch->r_io[ATA_ALTSTAT].offset = ch_offset + 0x28;
890     ch->r_io[ATA_CONTROL].offset = ch_offset + 0x29;
891
892     /* setup DMA registers */
893     ch->r_io[ATA_SSTATUS].offset = ch_offset + 0x100;
894     ch->r_io[ATA_SERROR].offset = ch_offset + 0x104;
895     ch->r_io[ATA_SCONTROL].offset = ch_offset + 0x108;
896
897     /* setup SATA registers */
898     ch->r_io[ATA_BMCMD_PORT].offset = ch_offset + 0x70;
899     ch->r_io[ATA_BMSTAT_PORT].offset = ch_offset + 0x72;
900     ch->r_io[ATA_BMDTP_PORT].offset = ch_offset + 0x74;
901
902     ch->flags |= ATA_NO_SLAVE;
903     ch->flags |= ATA_SATA;
904     ata_pci_hw(dev);
905     ch->hw.status = ata_intel_31244_status;
906     ch->hw.tf_write = ata_intel_31244_tf_write;
907
908     /* enable PHY state change interrupt */
909     ATA_OUTL(ctlr->r_res2, 0x4,
910              ATA_INL(ctlr->r_res2, 0x04) | (0x01 << (ch->unit << 3)));
911     return 0;
912 }
913
914 static int
915 ata_intel_31244_ch_detach(device_t dev)
916 {
917
918     ata_pci_dmafini(dev);
919     return (0);
920 }
921
922 static int
923 ata_intel_31244_status(device_t dev)
924 {
925     /* do we have any PHY events ? */
926     ata_sata_phy_check_events(dev, -1);
927
928     /* any drive action to take care of ? */
929     return ata_pci_status(dev);
930 }
931
932 static void
933 ata_intel_31244_tf_write(struct ata_request *request)
934 {
935     struct ata_channel *ch = device_get_softc(request->parent);
936 #ifndef ATA_CAM
937     struct ata_device *atadev = device_get_softc(request->dev);
938 #endif
939
940     if (request->flags & ATA_R_48BIT) {
941         ATA_IDX_OUTW(ch, ATA_FEATURE, request->u.ata.feature);
942         ATA_IDX_OUTW(ch, ATA_COUNT, request->u.ata.count);
943         ATA_IDX_OUTW(ch, ATA_SECTOR, ((request->u.ata.lba >> 16) & 0xff00) |
944                                       (request->u.ata.lba & 0x00ff));
945         ATA_IDX_OUTW(ch, ATA_CYL_LSB, ((request->u.ata.lba >> 24) & 0xff00) |
946                                        ((request->u.ata.lba >> 8) & 0x00ff));
947         ATA_IDX_OUTW(ch, ATA_CYL_MSB, ((request->u.ata.lba >> 32) & 0xff00) | 
948                                        ((request->u.ata.lba >> 16) & 0x00ff));
949         ATA_IDX_OUTW(ch, ATA_DRIVE, ATA_D_LBA | ATA_DEV(request->unit));
950     }
951     else {
952         ATA_IDX_OUTB(ch, ATA_FEATURE, request->u.ata.feature);
953         ATA_IDX_OUTB(ch, ATA_COUNT, request->u.ata.count);
954 #ifndef ATA_CAM
955         if (atadev->flags & ATA_D_USE_CHS) {
956             int heads, sectors;
957     
958             if (atadev->param.atavalid & ATA_FLAG_54_58) {
959                 heads = atadev->param.current_heads;
960                 sectors = atadev->param.current_sectors;
961             }
962             else {
963                 heads = atadev->param.heads;
964                 sectors = atadev->param.sectors;
965             }
966             ATA_IDX_OUTB(ch, ATA_SECTOR, (request->u.ata.lba % sectors)+1);
967             ATA_IDX_OUTB(ch, ATA_CYL_LSB,
968                          (request->u.ata.lba / (sectors * heads)));
969             ATA_IDX_OUTB(ch, ATA_CYL_MSB,
970                          (request->u.ata.lba / (sectors * heads)) >> 8);
971             ATA_IDX_OUTB(ch, ATA_DRIVE, ATA_D_IBM | ATA_DEV(request->unit) | 
972                          (((request->u.ata.lba% (sectors * heads)) /
973                            sectors) & 0xf));
974         }
975         else {
976 #endif
977             ATA_IDX_OUTB(ch, ATA_SECTOR, request->u.ata.lba);
978             ATA_IDX_OUTB(ch, ATA_CYL_LSB, request->u.ata.lba >> 8);
979             ATA_IDX_OUTB(ch, ATA_CYL_MSB, request->u.ata.lba >> 16);
980             ATA_IDX_OUTB(ch, ATA_DRIVE,
981                          ATA_D_IBM | ATA_D_LBA | ATA_DEV(request->unit) |
982                          ((request->u.ata.lba >> 24) & 0x0f));
983 #ifndef ATA_CAM
984         }
985 #endif
986     }
987 }
988
989 static void
990 ata_intel_31244_reset(device_t dev)
991 {
992     struct ata_channel *ch = device_get_softc(dev);
993
994     if (ata_sata_phy_reset(dev, -1, 1))
995         ata_generic_reset(dev);
996     else
997         ch->devices = 0;
998 }
999
1000 ATA_DECLARE_DRIVER(ata_intel);
1001 MODULE_DEPEND(ata_intel, ata_ahci, 1, 1, 1);