1195534Sscottl/*-
2238805Smav * Copyright (c) 2009-2012 Alexander Motin <mav@FreeBSD.org>
3195534Sscottl * All rights reserved.
4195534Sscottl *
5195534Sscottl * Redistribution and use in source and binary forms, with or without
6195534Sscottl * modification, are permitted provided that the following conditions
7195534Sscottl * are met:
8195534Sscottl * 1. Redistributions of source code must retain the above copyright
9195534Sscottl *    notice, this list of conditions and the following disclaimer,
10195534Sscottl *    without modification, immediately at the beginning of the file.
11195534Sscottl * 2. Redistributions in binary form must reproduce the above copyright
12195534Sscottl *    notice, this list of conditions and the following disclaimer in the
13195534Sscottl *    documentation and/or other materials provided with the distribution.
14195534Sscottl *
15195534Sscottl * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16195534Sscottl * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17195534Sscottl * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18195534Sscottl * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19195534Sscottl * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20195534Sscottl * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21195534Sscottl * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22195534Sscottl * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23195534Sscottl * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24195534Sscottl * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25195534Sscottl */
26195534Sscottl
27195534Sscottl#include <sys/cdefs.h>
28195534Sscottl__FBSDID("$FreeBSD: stable/11/sys/dev/ahci/ahci_pci.c 359971 2020-04-15 13:59:09Z mav $");
29195534Sscottl
30195534Sscottl#include <sys/param.h>
31195534Sscottl#include <sys/module.h>
32195534Sscottl#include <sys/systm.h>
33195534Sscottl#include <sys/kernel.h>
34195534Sscottl#include <sys/bus.h>
35220576Smav#include <sys/conf.h>
36195534Sscottl#include <sys/endian.h>
37195534Sscottl#include <sys/malloc.h>
38195534Sscottl#include <sys/lock.h>
39195534Sscottl#include <sys/mutex.h>
40195534Sscottl#include <machine/stdarg.h>
41195534Sscottl#include <machine/resource.h>
42195534Sscottl#include <machine/bus.h>
43195534Sscottl#include <sys/rman.h>
44195534Sscottl#include <dev/pci/pcivar.h>
45195534Sscottl#include <dev/pci/pcireg.h>
46195534Sscottl#include "ahci.h"
47195534Sscottl
48271146Simpstatic int force_ahci = 1;
49271146SimpTUNABLE_INT("hw.ahci.force", &force_ahci);
50195534Sscottl
51276344Smariusstatic const struct {
52199176Smav	uint32_t	id;
53203030Smav	uint8_t		rev;
54199176Smav	const char	*name;
55199322Smav	int		quirks;
56199176Smav} ahci_ids[] = {
57271146Simp	{0x43801002, 0x00, "AMD SB600",
58278034Ssmh	    AHCI_Q_NOMSI | AHCI_Q_ATI_PMP_BUG | AHCI_Q_MAXIO_64K},
59278034Ssmh	{0x43901002, 0x00, "AMD SB7x0/SB8x0/SB9x0",
60278034Ssmh	    AHCI_Q_ATI_PMP_BUG | AHCI_Q_1MSI},
61278034Ssmh	{0x43911002, 0x00, "AMD SB7x0/SB8x0/SB9x0",
62278034Ssmh	    AHCI_Q_ATI_PMP_BUG | AHCI_Q_1MSI},
63278034Ssmh	{0x43921002, 0x00, "AMD SB7x0/SB8x0/SB9x0",
64278034Ssmh	    AHCI_Q_ATI_PMP_BUG | AHCI_Q_1MSI},
65278034Ssmh	{0x43931002, 0x00, "AMD SB7x0/SB8x0/SB9x0",
66278034Ssmh	    AHCI_Q_ATI_PMP_BUG | AHCI_Q_1MSI},
67278034Ssmh	{0x43941002, 0x00, "AMD SB7x0/SB8x0/SB9x0",
68278034Ssmh	    AHCI_Q_ATI_PMP_BUG | AHCI_Q_1MSI},
69271146Simp	/* Not sure SB8x0/SB9x0 needs this quirk. Be conservative though */
70271146Simp	{0x43951002, 0x00, "AMD SB8x0/SB9x0",	AHCI_Q_ATI_PMP_BUG},
71334453Smarius	{0x43b61022, 0x00, "AMD X399",		0},
72336522Smarkj	{0x43b51022, 0x00, "AMD 300 Series",	0}, /* X370 */
73336522Smarkj	{0x43b71022, 0x00, "AMD 300 Series",	0}, /* B350 */
74244146Smav	{0x78001022, 0x00, "AMD Hudson-2",	0},
75244146Smav	{0x78011022, 0x00, "AMD Hudson-2",	0},
76244146Smav	{0x78021022, 0x00, "AMD Hudson-2",	0},
77244146Smav	{0x78031022, 0x00, "AMD Hudson-2",	0},
78244146Smav	{0x78041022, 0x00, "AMD Hudson-2",	0},
79326120Smav	{0x79001022, 0x00, "AMD KERNCZ",	0},
80326120Smav	{0x79011022, 0x00, "AMD KERNCZ",	0},
81326120Smav	{0x79021022, 0x00, "AMD KERNCZ",	0},
82326120Smav	{0x79031022, 0x00, "AMD KERNCZ",	0},
83326120Smav	{0x79041022, 0x00, "AMD KERNCZ",	0},
84317673Smav	{0x06011b21, 0x00, "ASMedia ASM1060",	AHCI_Q_NOCCS|AHCI_Q_NOAUX},
85317673Smav	{0x06021b21, 0x00, "ASMedia ASM1060",	AHCI_Q_NOCCS|AHCI_Q_NOAUX},
86317673Smav	{0x06111b21, 0x00, "ASMedia ASM1061",	AHCI_Q_NOCCS|AHCI_Q_NOAUX},
87317673Smav	{0x06121b21, 0x00, "ASMedia ASM1062",	AHCI_Q_NOCCS|AHCI_Q_NOAUX},
88317673Smav	{0x06201b21, 0x00, "ASMedia ASM106x",	AHCI_Q_NOCCS|AHCI_Q_NOAUX},
89317673Smav	{0x06211b21, 0x00, "ASMedia ASM106x",	AHCI_Q_NOCCS|AHCI_Q_NOAUX},
90317673Smav	{0x06221b21, 0x00, "ASMedia ASM106x",	AHCI_Q_NOCCS|AHCI_Q_NOAUX},
91317673Smav	{0x06241b21, 0x00, "ASMedia ASM106x",	AHCI_Q_NOCCS|AHCI_Q_NOAUX},
92317673Smav	{0x06251b21, 0x00, "ASMedia ASM106x",	AHCI_Q_NOCCS|AHCI_Q_NOAUX},
93358200Smav	{0x79011d94, 0x00, "Hygon KERNCZ",	0},
94203030Smav	{0x26528086, 0x00, "Intel ICH6",	AHCI_Q_NOFORCE},
95203030Smav	{0x26538086, 0x00, "Intel ICH6M",	AHCI_Q_NOFORCE},
96203030Smav	{0x26818086, 0x00, "Intel ESB2",	0},
97203030Smav	{0x26828086, 0x00, "Intel ESB2",	0},
98203030Smav	{0x26838086, 0x00, "Intel ESB2",	0},
99203030Smav	{0x27c18086, 0x00, "Intel ICH7",	0},
100203030Smav	{0x27c38086, 0x00, "Intel ICH7",	0},
101203030Smav	{0x27c58086, 0x00, "Intel ICH7M",	0},
102203030Smav	{0x27c68086, 0x00, "Intel ICH7M",	0},
103203030Smav	{0x28218086, 0x00, "Intel ICH8",	0},
104322572Smav	{0x28228086, 0x00, "Intel ICH8+ (RAID)",	0},
105203030Smav	{0x28248086, 0x00, "Intel ICH8",	0},
106203030Smav	{0x28298086, 0x00, "Intel ICH8M",	0},
107322572Smav	{0x282a8086, 0x00, "Intel ICH8M+ (RAID)",	0},
108203030Smav	{0x29228086, 0x00, "Intel ICH9",	0},
109203030Smav	{0x29238086, 0x00, "Intel ICH9",	0},
110203030Smav	{0x29248086, 0x00, "Intel ICH9",	0},
111203030Smav	{0x29258086, 0x00, "Intel ICH9",	0},
112203030Smav	{0x29278086, 0x00, "Intel ICH9",	0},
113203030Smav	{0x29298086, 0x00, "Intel ICH9M",	0},
114203030Smav	{0x292a8086, 0x00, "Intel ICH9M",	0},
115203030Smav	{0x292b8086, 0x00, "Intel ICH9M",	0},
116203030Smav	{0x292c8086, 0x00, "Intel ICH9M",	0},
117203030Smav	{0x292f8086, 0x00, "Intel ICH9M",	0},
118203030Smav	{0x294d8086, 0x00, "Intel ICH9",	0},
119203030Smav	{0x294e8086, 0x00, "Intel ICH9M",	0},
120322572Smav	{0x3a058086, 0x00, "Intel ICH10 (RAID)",	0},
121203030Smav	{0x3a228086, 0x00, "Intel ICH10",	0},
122322572Smav	{0x3a258086, 0x00, "Intel ICH10 (RAID)",	0},
123322573Smav	{0x3b228086, 0x00, "Intel Ibex Peak",	0},
124322573Smav	{0x3b238086, 0x00, "Intel Ibex Peak",	0},
125322573Smav	{0x3b258086, 0x00, "Intel Ibex Peak (RAID)",	0},
126322573Smav	{0x3b298086, 0x00, "Intel Ibex Peak-M",	0},
127322573Smav	{0x3b2c8086, 0x00, "Intel Ibex Peak-M (RAID)",	0},
128322573Smav	{0x3b2f8086, 0x00, "Intel Ibex Peak-M",	0},
129331195Seadler	{0x19b08086, 0x00, "Intel Denverton",	0},
130331195Seadler	{0x19b18086, 0x00, "Intel Denverton",	0},
131331195Seadler	{0x19b28086, 0x00, "Intel Denverton",	0},
132331195Seadler	{0x19b38086, 0x00, "Intel Denverton",	0},
133331195Seadler	{0x19b48086, 0x00, "Intel Denverton",	0},
134331195Seadler	{0x19b58086, 0x00, "Intel Denverton",	0},
135331195Seadler	{0x19b68086, 0x00, "Intel Denverton",	0},
136331195Seadler	{0x19b78086, 0x00, "Intel Denverton",	0},
137331195Seadler	{0x19be8086, 0x00, "Intel Denverton",	0},
138331195Seadler	{0x19bf8086, 0x00, "Intel Denverton",	0},
139331195Seadler	{0x19c08086, 0x00, "Intel Denverton",	0},
140331195Seadler	{0x19c18086, 0x00, "Intel Denverton",	0},
141331195Seadler	{0x19c28086, 0x00, "Intel Denverton",	0},
142331195Seadler	{0x19c38086, 0x00, "Intel Denverton",	0},
143331195Seadler	{0x19c48086, 0x00, "Intel Denverton",	0},
144331195Seadler	{0x19c58086, 0x00, "Intel Denverton",	0},
145331195Seadler	{0x19c68086, 0x00, "Intel Denverton",	0},
146331195Seadler	{0x19c78086, 0x00, "Intel Denverton",	0},
147331195Seadler	{0x19ce8086, 0x00, "Intel Denverton",	0},
148331195Seadler	{0x19cf8086, 0x00, "Intel Denverton",	0},
149211922Smav	{0x1c028086, 0x00, "Intel Cougar Point",	0},
150211922Smav	{0x1c038086, 0x00, "Intel Cougar Point",	0},
151322572Smav	{0x1c048086, 0x00, "Intel Cougar Point (RAID)",	0},
152322572Smav	{0x1c058086, 0x00, "Intel Cougar Point (RAID)",	0},
153322572Smav	{0x1c068086, 0x00, "Intel Cougar Point (RAID)",	0},
154218605Smav	{0x1d028086, 0x00, "Intel Patsburg",	0},
155218605Smav	{0x1d048086, 0x00, "Intel Patsburg",	0},
156218605Smav	{0x1d068086, 0x00, "Intel Patsburg",	0},
157322572Smav	{0x28268086, 0x00, "Intel Patsburg+ (RAID)",	0},
158221789Sjfv	{0x1e028086, 0x00, "Intel Panther Point",	0},
159221789Sjfv	{0x1e038086, 0x00, "Intel Panther Point",	0},
160258162Smav	{0x1e048086, 0x00, "Intel Panther Point (RAID)",	0},
161258162Smav	{0x1e058086, 0x00, "Intel Panther Point (RAID)",	0},
162258162Smav	{0x1e068086, 0x00, "Intel Panther Point (RAID)",	0},
163258162Smav	{0x1e078086, 0x00, "Intel Panther Point (RAID)",	0},
164258162Smav	{0x1e0e8086, 0x00, "Intel Panther Point (RAID)",	0},
165258162Smav	{0x1e0f8086, 0x00, "Intel Panther Point (RAID)",	0},
166258162Smav	{0x1f228086, 0x00, "Intel Avoton",	0},
167258162Smav	{0x1f238086, 0x00, "Intel Avoton",	0},
168258162Smav	{0x1f248086, 0x00, "Intel Avoton (RAID)",	0},
169258162Smav	{0x1f258086, 0x00, "Intel Avoton (RAID)",	0},
170258162Smav	{0x1f268086, 0x00, "Intel Avoton (RAID)",	0},
171258162Smav	{0x1f278086, 0x00, "Intel Avoton (RAID)",	0},
172258162Smav	{0x1f2e8086, 0x00, "Intel Avoton (RAID)",	0},
173258162Smav	{0x1f2f8086, 0x00, "Intel Avoton (RAID)",	0},
174258162Smav	{0x1f328086, 0x00, "Intel Avoton",	0},
175258162Smav	{0x1f338086, 0x00, "Intel Avoton",	0},
176258162Smav	{0x1f348086, 0x00, "Intel Avoton (RAID)",	0},
177258162Smav	{0x1f358086, 0x00, "Intel Avoton (RAID)",	0},
178258162Smav	{0x1f368086, 0x00, "Intel Avoton (RAID)",	0},
179258162Smav	{0x1f378086, 0x00, "Intel Avoton (RAID)",	0},
180258162Smav	{0x1f3e8086, 0x00, "Intel Avoton (RAID)",	0},
181258162Smav	{0x1f3f8086, 0x00, "Intel Avoton (RAID)",	0},
182278034Ssmh	{0x23a38086, 0x00, "Intel Coleto Creek",	0},
183244983Sjfv	{0x8c028086, 0x00, "Intel Lynx Point",	0},
184244983Sjfv	{0x8c038086, 0x00, "Intel Lynx Point",	0},
185258162Smav	{0x8c048086, 0x00, "Intel Lynx Point (RAID)",	0},
186258162Smav	{0x8c058086, 0x00, "Intel Lynx Point (RAID)",	0},
187258162Smav	{0x8c068086, 0x00, "Intel Lynx Point (RAID)",	0},
188258162Smav	{0x8c078086, 0x00, "Intel Lynx Point (RAID)",	0},
189258162Smav	{0x8c0e8086, 0x00, "Intel Lynx Point (RAID)",	0},
190258162Smav	{0x8c0f8086, 0x00, "Intel Lynx Point (RAID)",	0},
191275101Smav	{0x8c828086, 0x00, "Intel Wildcat Point",	0},
192275101Smav	{0x8c838086, 0x00, "Intel Wildcat Point",	0},
193275101Smav	{0x8c848086, 0x00, "Intel Wildcat Point (RAID)",	0},
194275101Smav	{0x8c858086, 0x00, "Intel Wildcat Point (RAID)",	0},
195275101Smav	{0x8c868086, 0x00, "Intel Wildcat Point (RAID)",	0},
196275101Smav	{0x8c878086, 0x00, "Intel Wildcat Point (RAID)",	0},
197275101Smav	{0x8c8e8086, 0x00, "Intel Wildcat Point (RAID)",	0},
198275101Smav	{0x8c8f8086, 0x00, "Intel Wildcat Point (RAID)",	0},
199258162Smav	{0x8d028086, 0x00, "Intel Wellsburg",	0},
200258162Smav	{0x8d048086, 0x00, "Intel Wellsburg (RAID)",	0},
201258162Smav	{0x8d068086, 0x00, "Intel Wellsburg (RAID)",	0},
202258162Smav	{0x8d628086, 0x00, "Intel Wellsburg",	0},
203258162Smav	{0x8d648086, 0x00, "Intel Wellsburg (RAID)",	0},
204258162Smav	{0x8d668086, 0x00, "Intel Wellsburg (RAID)",	0},
205258162Smav	{0x8d6e8086, 0x00, "Intel Wellsburg (RAID)",	0},
206322572Smav	{0x28238086, 0x00, "Intel Wellsburg+ (RAID)",	0},
207322572Smav	{0x28278086, 0x00, "Intel Wellsburg+ (RAID)",	0},
208258162Smav	{0x9c028086, 0x00, "Intel Lynx Point-LP",	0},
209258162Smav	{0x9c038086, 0x00, "Intel Lynx Point-LP",	0},
210258162Smav	{0x9c048086, 0x00, "Intel Lynx Point-LP (RAID)",	0},
211258162Smav	{0x9c058086, 0x00, "Intel Lynx Point-LP (RAID)",	0},
212258162Smav	{0x9c068086, 0x00, "Intel Lynx Point-LP (RAID)",	0},
213258162Smav	{0x9c078086, 0x00, "Intel Lynx Point-LP (RAID)",	0},
214258162Smav	{0x9c0e8086, 0x00, "Intel Lynx Point-LP (RAID)",	0},
215258162Smav	{0x9c0f8086, 0x00, "Intel Lynx Point-LP (RAID)",	0},
216355329Smav	{0x9c838086, 0x00, "Intel Wildcat Point-LP",	0},
217355329Smav	{0x9c858086, 0x00, "Intel Wildcat Point-LP (RAID)",	0},
218355329Smav	{0x9c878086, 0x00, "Intel Wildcat Point-LP (RAID)",	0},
219355329Smav	{0x9c8f8086, 0x00, "Intel Wildcat Point-LP (RAID)",	0},
220298983Smav	{0x9d038086, 0x00, "Intel Sunrise Point-LP",	0},
221298983Smav	{0x9d058086, 0x00, "Intel Sunrise Point-LP (RAID)",	0},
222298983Smav	{0x9d078086, 0x00, "Intel Sunrise Point-LP (RAID)",	0},
223298983Smav	{0xa1028086, 0x00, "Intel Sunrise Point",	0},
224298983Smav	{0xa1038086, 0x00, "Intel Sunrise Point",	0},
225298983Smav	{0xa1058086, 0x00, "Intel Sunrise Point (RAID)",	0},
226298983Smav	{0xa1068086, 0x00, "Intel Sunrise Point (RAID)",	0},
227298983Smav	{0xa1078086, 0x00, "Intel Sunrise Point (RAID)",	0},
228298983Smav	{0xa10f8086, 0x00, "Intel Sunrise Point (RAID)",	0},
229322572Smav	{0xa1828086, 0x00, "Intel Lewisburg",	0},
230322572Smav	{0xa1868086, 0x00, "Intel Lewisburg (RAID)",	0},
231322572Smav	{0xa1d28086, 0x00, "Intel Lewisburg",	0},
232322572Smav	{0xa1d68086, 0x00, "Intel Lewisburg (RAID)",	0},
233322572Smav	{0xa2028086, 0x00, "Intel Lewisburg",	0},
234322572Smav	{0xa2068086, 0x00, "Intel Lewisburg (RAID)",	0},
235322572Smav	{0xa2528086, 0x00, "Intel Lewisburg",	0},
236322572Smav	{0xa2568086, 0x00, "Intel Lewisburg (RAID)",	0},
237322572Smav	{0xa2828086, 0x00, "Intel Union Point",	0},
238322572Smav	{0xa2868086, 0x00, "Intel Union Point (RAID)",	0},
239322572Smav	{0xa28e8086, 0x00, "Intel Union Point (RAID)",	0},
240345820Smav	{0xa3528086, 0x00, "Intel Cannon Lake",	0},
241345820Smav	{0xa3538086, 0x00, "Intel Cannon Lake",	0},
242221789Sjfv	{0x23238086, 0x00, "Intel DH89xxCC",	0},
243239907Smav	{0x2360197b, 0x00, "JMicron JMB360",	0},
244304658Savg	{0x2361197b, 0x00, "JMicron JMB361",	AHCI_Q_NOFORCE | AHCI_Q_1CH},
245239907Smav	{0x2362197b, 0x00, "JMicron JMB362",	0},
246203030Smav	{0x2363197b, 0x00, "JMicron JMB363",	AHCI_Q_NOFORCE},
247203030Smav	{0x2365197b, 0x00, "JMicron JMB365",	AHCI_Q_NOFORCE},
248203030Smav	{0x2366197b, 0x00, "JMicron JMB366",	AHCI_Q_NOFORCE},
249203030Smav	{0x2368197b, 0x00, "JMicron JMB368",	AHCI_Q_NOFORCE},
250359971Smav	{0x0585197b, 0x00, "JMicron JMB58x",	0},
251285020Smav	{0x611111ab, 0x00, "Marvell 88SE6111",	AHCI_Q_NOFORCE | AHCI_Q_NOPMP |
252285020Smav	    AHCI_Q_1CH | AHCI_Q_EDGEIS},
253285020Smav	{0x612111ab, 0x00, "Marvell 88SE6121",	AHCI_Q_NOFORCE | AHCI_Q_NOPMP |
254285020Smav	    AHCI_Q_2CH | AHCI_Q_EDGEIS | AHCI_Q_NONCQ | AHCI_Q_NOCOUNT},
255285020Smav	{0x614111ab, 0x00, "Marvell 88SE6141",	AHCI_Q_NOFORCE | AHCI_Q_NOPMP |
256285020Smav	    AHCI_Q_4CH | AHCI_Q_EDGEIS | AHCI_Q_NONCQ | AHCI_Q_NOCOUNT},
257285020Smav	{0x614511ab, 0x00, "Marvell 88SE6145",	AHCI_Q_NOFORCE | AHCI_Q_NOPMP |
258285020Smav	    AHCI_Q_4CH | AHCI_Q_EDGEIS | AHCI_Q_NONCQ | AHCI_Q_NOCOUNT},
259271163Smav	{0x91201b4b, 0x00, "Marvell 88SE912x",	AHCI_Q_EDGEIS},
260271163Smav	{0x91231b4b, 0x11, "Marvell 88SE912x",	AHCI_Q_ALTSIG},
261271163Smav	{0x91231b4b, 0x00, "Marvell 88SE912x",	AHCI_Q_EDGEIS|AHCI_Q_SATA2},
262271163Smav	{0x91251b4b, 0x00, "Marvell 88SE9125",	0},
263271163Smav	{0x91281b4b, 0x00, "Marvell 88SE9128",	AHCI_Q_ALTSIG},
264271163Smav	{0x91301b4b, 0x00, "Marvell 88SE9130",  AHCI_Q_ALTSIG},
265271163Smav	{0x91721b4b, 0x00, "Marvell 88SE9172",	0},
266271163Smav	{0x91821b4b, 0x00, "Marvell 88SE9182",	0},
267271163Smav	{0x91831b4b, 0x00, "Marvell 88SS9183",	0},
268271163Smav	{0x91a01b4b, 0x00, "Marvell 88SE91Ax",	0},
269271163Smav	{0x92151b4b, 0x00, "Marvell 88SE9215",  0},
270271163Smav	{0x92201b4b, 0x00, "Marvell 88SE9220",  AHCI_Q_ALTSIG},
271271163Smav	{0x92301b4b, 0x00, "Marvell 88SE9230",  AHCI_Q_ALTSIG},
272271163Smav	{0x92351b4b, 0x00, "Marvell 88SE9235",  0},
273271163Smav	{0x06201103, 0x00, "HighPoint RocketRAID 620",	0},
274271163Smav	{0x06201b4b, 0x00, "HighPoint RocketRAID 620",	0},
275271163Smav	{0x06221103, 0x00, "HighPoint RocketRAID 622",	0},
276271163Smav	{0x06221b4b, 0x00, "HighPoint RocketRAID 622",	0},
277271163Smav	{0x06401103, 0x00, "HighPoint RocketRAID 640",	0},
278271163Smav	{0x06401b4b, 0x00, "HighPoint RocketRAID 640",	0},
279271163Smav	{0x06441103, 0x00, "HighPoint RocketRAID 644",	0},
280271163Smav	{0x06441b4b, 0x00, "HighPoint RocketRAID 644",	0},
281271163Smav	{0x06411103, 0x00, "HighPoint RocketRAID 640L",	0},
282271163Smav	{0x06421103, 0x00, "HighPoint RocketRAID 642L",	0},
283271163Smav	{0x06451103, 0x00, "HighPoint RocketRAID 644L",	0},
284207499Smav	{0x044c10de, 0x00, "NVIDIA MCP65",	AHCI_Q_NOAA},
285207499Smav	{0x044d10de, 0x00, "NVIDIA MCP65",	AHCI_Q_NOAA},
286207499Smav	{0x044e10de, 0x00, "NVIDIA MCP65",	AHCI_Q_NOAA},
287207499Smav	{0x044f10de, 0x00, "NVIDIA MCP65",	AHCI_Q_NOAA},
288207499Smav	{0x045c10de, 0x00, "NVIDIA MCP65",	AHCI_Q_NOAA},
289207499Smav	{0x045d10de, 0x00, "NVIDIA MCP65",	AHCI_Q_NOAA},
290207499Smav	{0x045e10de, 0x00, "NVIDIA MCP65",	AHCI_Q_NOAA},
291207499Smav	{0x045f10de, 0x00, "NVIDIA MCP65",	AHCI_Q_NOAA},
292207499Smav	{0x055010de, 0x00, "NVIDIA MCP67",	AHCI_Q_NOAA},
293207499Smav	{0x055110de, 0x00, "NVIDIA MCP67",	AHCI_Q_NOAA},
294207499Smav	{0x055210de, 0x00, "NVIDIA MCP67",	AHCI_Q_NOAA},
295207499Smav	{0x055310de, 0x00, "NVIDIA MCP67",	AHCI_Q_NOAA},
296207499Smav	{0x055410de, 0x00, "NVIDIA MCP67",	AHCI_Q_NOAA},
297207499Smav	{0x055510de, 0x00, "NVIDIA MCP67",	AHCI_Q_NOAA},
298207499Smav	{0x055610de, 0x00, "NVIDIA MCP67",	AHCI_Q_NOAA},
299207499Smav	{0x055710de, 0x00, "NVIDIA MCP67",	AHCI_Q_NOAA},
300207499Smav	{0x055810de, 0x00, "NVIDIA MCP67",	AHCI_Q_NOAA},
301207499Smav	{0x055910de, 0x00, "NVIDIA MCP67",	AHCI_Q_NOAA},
302207499Smav	{0x055A10de, 0x00, "NVIDIA MCP67",	AHCI_Q_NOAA},
303207499Smav	{0x055B10de, 0x00, "NVIDIA MCP67",	AHCI_Q_NOAA},
304207499Smav	{0x058410de, 0x00, "NVIDIA MCP67",	AHCI_Q_NOAA},
305207499Smav	{0x07f010de, 0x00, "NVIDIA MCP73",	AHCI_Q_NOAA},
306207499Smav	{0x07f110de, 0x00, "NVIDIA MCP73",	AHCI_Q_NOAA},
307207499Smav	{0x07f210de, 0x00, "NVIDIA MCP73",	AHCI_Q_NOAA},
308207499Smav	{0x07f310de, 0x00, "NVIDIA MCP73",	AHCI_Q_NOAA},
309207499Smav	{0x07f410de, 0x00, "NVIDIA MCP73",	AHCI_Q_NOAA},
310207499Smav	{0x07f510de, 0x00, "NVIDIA MCP73",	AHCI_Q_NOAA},
311207499Smav	{0x07f610de, 0x00, "NVIDIA MCP73",	AHCI_Q_NOAA},
312207499Smav	{0x07f710de, 0x00, "NVIDIA MCP73",	AHCI_Q_NOAA},
313207499Smav	{0x07f810de, 0x00, "NVIDIA MCP73",	AHCI_Q_NOAA},
314207499Smav	{0x07f910de, 0x00, "NVIDIA MCP73",	AHCI_Q_NOAA},
315207499Smav	{0x07fa10de, 0x00, "NVIDIA MCP73",	AHCI_Q_NOAA},
316207499Smav	{0x07fb10de, 0x00, "NVIDIA MCP73",	AHCI_Q_NOAA},
317207499Smav	{0x0ad010de, 0x00, "NVIDIA MCP77",	AHCI_Q_NOAA},
318207499Smav	{0x0ad110de, 0x00, "NVIDIA MCP77",	AHCI_Q_NOAA},
319207499Smav	{0x0ad210de, 0x00, "NVIDIA MCP77",	AHCI_Q_NOAA},
320207499Smav	{0x0ad310de, 0x00, "NVIDIA MCP77",	AHCI_Q_NOAA},
321207499Smav	{0x0ad410de, 0x00, "NVIDIA MCP77",	AHCI_Q_NOAA},
322207499Smav	{0x0ad510de, 0x00, "NVIDIA MCP77",	AHCI_Q_NOAA},
323207499Smav	{0x0ad610de, 0x00, "NVIDIA MCP77",	AHCI_Q_NOAA},
324207499Smav	{0x0ad710de, 0x00, "NVIDIA MCP77",	AHCI_Q_NOAA},
325207499Smav	{0x0ad810de, 0x00, "NVIDIA MCP77",	AHCI_Q_NOAA},
326207499Smav	{0x0ad910de, 0x00, "NVIDIA MCP77",	AHCI_Q_NOAA},
327207499Smav	{0x0ada10de, 0x00, "NVIDIA MCP77",	AHCI_Q_NOAA},
328207499Smav	{0x0adb10de, 0x00, "NVIDIA MCP77",	AHCI_Q_NOAA},
329207499Smav	{0x0ab410de, 0x00, "NVIDIA MCP79",	AHCI_Q_NOAA},
330207499Smav	{0x0ab510de, 0x00, "NVIDIA MCP79",	AHCI_Q_NOAA},
331207499Smav	{0x0ab610de, 0x00, "NVIDIA MCP79",	AHCI_Q_NOAA},
332207499Smav	{0x0ab710de, 0x00, "NVIDIA MCP79",	AHCI_Q_NOAA},
333207499Smav	{0x0ab810de, 0x00, "NVIDIA MCP79",	AHCI_Q_NOAA},
334207499Smav	{0x0ab910de, 0x00, "NVIDIA MCP79",	AHCI_Q_NOAA},
335207499Smav	{0x0aba10de, 0x00, "NVIDIA MCP79",	AHCI_Q_NOAA},
336207499Smav	{0x0abb10de, 0x00, "NVIDIA MCP79",	AHCI_Q_NOAA},
337207499Smav	{0x0abc10de, 0x00, "NVIDIA MCP79",	AHCI_Q_NOAA},
338207499Smav	{0x0abd10de, 0x00, "NVIDIA MCP79",	AHCI_Q_NOAA},
339207499Smav	{0x0abe10de, 0x00, "NVIDIA MCP79",	AHCI_Q_NOAA},
340207499Smav	{0x0abf10de, 0x00, "NVIDIA MCP79",	AHCI_Q_NOAA},
341207499Smav	{0x0d8410de, 0x00, "NVIDIA MCP89",	AHCI_Q_NOAA},
342224603Smav	{0x0d8510de, 0x00, "NVIDIA MCP89",	AHCI_Q_NOFORCE|AHCI_Q_NOAA},
343207499Smav	{0x0d8610de, 0x00, "NVIDIA MCP89",	AHCI_Q_NOAA},
344207499Smav	{0x0d8710de, 0x00, "NVIDIA MCP89",	AHCI_Q_NOAA},
345207499Smav	{0x0d8810de, 0x00, "NVIDIA MCP89",	AHCI_Q_NOAA},
346207499Smav	{0x0d8910de, 0x00, "NVIDIA MCP89",	AHCI_Q_NOAA},
347207499Smav	{0x0d8a10de, 0x00, "NVIDIA MCP89",	AHCI_Q_NOAA},
348207499Smav	{0x0d8b10de, 0x00, "NVIDIA MCP89",	AHCI_Q_NOAA},
349207499Smav	{0x0d8c10de, 0x00, "NVIDIA MCP89",	AHCI_Q_NOAA},
350207499Smav	{0x0d8d10de, 0x00, "NVIDIA MCP89",	AHCI_Q_NOAA},
351207499Smav	{0x0d8e10de, 0x00, "NVIDIA MCP89",	AHCI_Q_NOAA},
352207499Smav	{0x0d8f10de, 0x00, "NVIDIA MCP89",	AHCI_Q_NOAA},
353271403Smav	{0x3781105a, 0x00, "Promise TX8660",	0},
354208907Smav	{0x33491106, 0x00, "VIA VT8251",	AHCI_Q_NOPMP|AHCI_Q_NONCQ},
355208907Smav	{0x62871106, 0x00, "VIA VT8251",	AHCI_Q_NOPMP|AHCI_Q_NONCQ},
356203030Smav	{0x11841039, 0x00, "SiS 966",		0},
357203030Smav	{0x11851039, 0x00, "SiS 968",		0},
358203030Smav	{0x01861039, 0x00, "SiS 968",		0},
359279573Semaste	{0xa01c177d, 0x00, "ThunderX",		AHCI_Q_ABAR0|AHCI_Q_1MSI},
360297447Szbb	{0x00311c36, 0x00, "Annapurna",		AHCI_Q_FORCE_PI|AHCI_Q_RESTORE_CAP|AHCI_Q_NOMSIX},
361203030Smav	{0x00000000, 0x00, NULL,		0}
362199176Smav};
363199176Smav
364271146Simpstatic int
365271146Simpahci_pci_ctlr_reset(device_t dev)
366271146Simp{
367220565Smav
368271146Simp	if (pci_read_config(dev, PCIR_DEVVENDOR, 4) == 0x28298086 &&
369271146Simp	    (pci_read_config(dev, 0x92, 1) & 0xfe) == 0x04)
370271146Simp		pci_write_config(dev, 0x92, 0x01, 1);
371271146Simp	return ahci_ctlr_reset(dev);
372271146Simp}
373228200Smav
374195534Sscottlstatic int
375195534Sscottlahci_probe(device_t dev)
376195534Sscottl{
377199176Smav	char buf[64];
378199322Smav	int i, valid = 0;
379199322Smav	uint32_t devid = pci_get_devid(dev);
380203030Smav	uint8_t revid = pci_get_revid(dev);
381199322Smav
382260163Szbb	/*
383260163Szbb	 * Ensure it is not a PCI bridge (some vendors use
384260163Szbb	 * the same PID and VID in PCI bridge and AHCI cards).
385260163Szbb	 */
386260163Szbb	if (pci_get_class(dev) == PCIC_BRIDGE)
387260163Szbb		return (ENXIO);
388260163Szbb
389199322Smav	/* Is this a possible AHCI candidate? */
390199322Smav	if (pci_get_class(dev) == PCIC_STORAGE &&
391199322Smav	    pci_get_subclass(dev) == PCIS_STORAGE_SATA &&
392199322Smav	    pci_get_progif(dev) == PCIP_STORAGE_SATA_AHCI_1_0)
393199322Smav		valid = 1;
394288111Smav	else if (pci_get_class(dev) == PCIC_STORAGE &&
395288111Smav	    pci_get_subclass(dev) == PCIS_STORAGE_RAID)
396288111Smav		valid = 2;
397199322Smav	/* Is this a known AHCI chip? */
398199322Smav	for (i = 0; ahci_ids[i].id != 0; i++) {
399199322Smav		if (ahci_ids[i].id == devid &&
400203030Smav		    ahci_ids[i].rev <= revid &&
401228200Smav		    (valid || (force_ahci == 1 &&
402228200Smav		     !(ahci_ids[i].quirks & AHCI_Q_NOFORCE)))) {
403199717Smav			/* Do not attach JMicrons with single PCI function. */
404199717Smav			if (pci_get_vendor(dev) == 0x197b &&
405359971Smav			    (ahci_ids[i].quirks & AHCI_Q_NOFORCE) &&
406199717Smav			    (pci_read_config(dev, 0xdf, 1) & 0x40) == 0)
407199717Smav				return (ENXIO);
408199322Smav			snprintf(buf, sizeof(buf), "%s AHCI SATA controller",
409199322Smav			    ahci_ids[i].name);
410199322Smav			device_set_desc_copy(dev, buf);
411280393Smav			return (BUS_PROBE_DEFAULT);
412199322Smav		}
413199322Smav	}
414288111Smav	if (valid != 1)
415199322Smav		return (ENXIO);
416199322Smav	device_set_desc_copy(dev, "AHCI SATA controller");
417280393Smav	return (BUS_PROBE_DEFAULT);
418199322Smav}
419199322Smav
420199322Smavstatic int
421199322Smavahci_ata_probe(device_t dev)
422199322Smav{
423199322Smav	char buf[64];
424199176Smav	int i;
425199176Smav	uint32_t devid = pci_get_devid(dev);
426203030Smav	uint8_t revid = pci_get_revid(dev);
427195534Sscottl
428199322Smav	if ((intptr_t)device_get_ivars(dev) >= 0)
429199322Smav		return (ENXIO);
430199176Smav	/* Is this a known AHCI chip? */
431199176Smav	for (i = 0; ahci_ids[i].id != 0; i++) {
432203030Smav		if (ahci_ids[i].id == devid &&
433203030Smav		    ahci_ids[i].rev <= revid) {
434199176Smav			snprintf(buf, sizeof(buf), "%s AHCI SATA controller",
435199176Smav			    ahci_ids[i].name);
436199176Smav			device_set_desc_copy(dev, buf);
437280393Smav			return (BUS_PROBE_DEFAULT);
438199176Smav		}
439199176Smav	}
440199176Smav	device_set_desc_copy(dev, "AHCI SATA controller");
441280393Smav	return (BUS_PROBE_DEFAULT);
442195534Sscottl}
443195534Sscottl
444195534Sscottlstatic int
445285789Szbbahci_pci_read_msix_bars(device_t dev, uint8_t *table_bar, uint8_t *pba_bar)
446285789Szbb{
447285789Szbb	int cap_offset = 0, ret;
448285789Szbb	uint32_t val;
449285789Szbb
450285789Szbb	if ((table_bar == NULL) || (pba_bar == NULL))
451285789Szbb		return (EINVAL);
452285789Szbb
453285789Szbb	ret = pci_find_cap(dev, PCIY_MSIX, &cap_offset);
454285789Szbb	if (ret != 0)
455285789Szbb		return (EINVAL);
456285789Szbb
457285789Szbb	val = pci_read_config(dev, cap_offset + PCIR_MSIX_TABLE, 4);
458285789Szbb	*table_bar = PCIR_BAR(val & PCIM_MSIX_BIR_MASK);
459285789Szbb
460285789Szbb	val = pci_read_config(dev, cap_offset + PCIR_MSIX_PBA, 4);
461285789Szbb	*pba_bar = PCIR_BAR(val & PCIM_MSIX_BIR_MASK);
462285789Szbb
463285789Szbb	return (0);
464285789Szbb}
465285789Szbb
466285789Szbbstatic int
467271146Simpahci_pci_attach(device_t dev)
468195534Sscottl{
469195534Sscottl	struct ahci_controller *ctlr = device_get_softc(dev);
470271146Simp	int	error, i;
471199322Smav	uint32_t devid = pci_get_devid(dev);
472203030Smav	uint8_t revid = pci_get_revid(dev);
473285789Szbb	int msi_count, msix_count;
474285789Szbb	uint8_t table_bar = 0, pba_bar = 0;
475195534Sscottl
476285789Szbb	msi_count = pci_msi_count(dev);
477285789Szbb	msix_count = pci_msix_count(dev);
478285789Szbb
479199322Smav	i = 0;
480203030Smav	while (ahci_ids[i].id != 0 &&
481203030Smav	    (ahci_ids[i].id != devid ||
482203030Smav	     ahci_ids[i].rev > revid))
483199322Smav		i++;
484199322Smav	ctlr->quirks = ahci_ids[i].quirks;
485271146Simp	/* Limit speed for my onboard JMicron external port.
486271146Simp	 * It is not eSATA really, limit to SATA 1 */
487271146Simp	if (pci_get_devid(dev) == 0x2363197b &&
488271146Simp	    pci_get_subvendor(dev) == 0x1043 &&
489271146Simp	    pci_get_subdevice(dev) == 0x81e4)
490271146Simp		ctlr->quirks |= AHCI_Q_SATA1_UNIT0;
491297921Smav	resource_int_value(device_get_name(dev), device_get_unit(dev),
492297921Smav	    "quirks", &ctlr->quirks);
493271146Simp	ctlr->vendorid = pci_get_vendor(dev);
494271146Simp	ctlr->deviceid = pci_get_device(dev);
495271146Simp	ctlr->subvendorid = pci_get_subvendor(dev);
496271146Simp	ctlr->subdeviceid = pci_get_subdevice(dev);
497277100Skib
498277100Skib	/* Default AHCI Base Address is BAR(5), Cavium uses BAR(0) */
499277100Skib	if (ctlr->quirks & AHCI_Q_ABAR0)
500277100Skib		ctlr->r_rid = PCIR_BAR(0);
501277100Skib	else
502277100Skib		ctlr->r_rid = PCIR_BAR(5);
503195534Sscottl	if (!(ctlr->r_mem = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
504195534Sscottl	    &ctlr->r_rid, RF_ACTIVE)))
505195534Sscottl		return ENXIO;
506285789Szbb
507297447Szbb	if (ctlr->quirks & AHCI_Q_NOMSIX)
508297447Szbb		msix_count = 0;
509297447Szbb
510285789Szbb	/* Read MSI-x BAR IDs if supported */
511285789Szbb	if (msix_count > 0) {
512285789Szbb		error = ahci_pci_read_msix_bars(dev, &table_bar, &pba_bar);
513285789Szbb		if (error == 0) {
514285789Szbb			ctlr->r_msix_tab_rid = table_bar;
515285789Szbb			ctlr->r_msix_pba_rid = pba_bar;
516285789Szbb		} else {
517285789Szbb			/* Failed to read BARs, disable MSI-x */
518285789Szbb			msix_count = 0;
519285789Szbb		}
520285789Szbb	}
521285789Szbb
522285789Szbb	/* Allocate resources for MSI-x table and PBA */
523285789Szbb	if (msix_count > 0) {
524285789Szbb		/*
525285789Szbb		 * Allocate new MSI-x table only if not
526285789Szbb		 * allocated before.
527285789Szbb		 */
528285789Szbb		ctlr->r_msix_table = NULL;
529285789Szbb		if (ctlr->r_msix_tab_rid != ctlr->r_rid) {
530285789Szbb			/* Separate BAR for MSI-x */
531285789Szbb			ctlr->r_msix_table = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
532285789Szbb			    &ctlr->r_msix_tab_rid, RF_ACTIVE);
533285789Szbb			if (ctlr->r_msix_table == NULL) {
534285789Szbb				ahci_free_mem(dev);
535285789Szbb				return (ENXIO);
536285789Szbb			}
537285789Szbb		}
538285789Szbb
539285789Szbb		/*
540285789Szbb		 * Allocate new PBA table only if not
541285789Szbb		 * allocated before.
542285789Szbb		 */
543285789Szbb		ctlr->r_msix_pba = NULL;
544285789Szbb		if ((ctlr->r_msix_pba_rid != ctlr->r_msix_tab_rid) &&
545285789Szbb		    (ctlr->r_msix_pba_rid != ctlr->r_rid)) {
546285789Szbb			/* Separate BAR for PBA */
547285789Szbb			ctlr->r_msix_pba = bus_alloc_resource_any(dev, SYS_RES_MEMORY,
548285789Szbb			    &ctlr->r_msix_pba_rid, RF_ACTIVE);
549285789Szbb			if (ctlr->r_msix_pba == NULL) {
550285789Szbb				ahci_free_mem(dev);
551285789Szbb				return (ENXIO);
552285789Szbb			}
553285789Szbb		}
554285789Szbb	}
555285789Szbb
556207511Smav	pci_enable_busmaster(dev);
557195534Sscottl	/* Reset controller */
558271146Simp	if ((error = ahci_pci_ctlr_reset(dev)) != 0) {
559285789Szbb		ahci_free_mem(dev);
560195534Sscottl		return (error);
561297793Spfg	}
562222304Smav
563195534Sscottl	/* Setup interrupts. */
564195534Sscottl
565271146Simp	/* Setup MSI register parameters */
566195534Sscottl	/* Process hints. */
567245875Smav	if (ctlr->quirks & AHCI_Q_NOMSI)
568256843Smav		ctlr->msi = 0;
569278034Ssmh	else if (ctlr->quirks & AHCI_Q_1MSI)
570278034Ssmh		ctlr->msi = 1;
571278034Ssmh	else
572278034Ssmh		ctlr->msi = 2;
573195534Sscottl	resource_int_value(device_get_name(dev),
574256843Smav	    device_get_unit(dev), "msi", &ctlr->msi);
575256843Smav	ctlr->numirqs = 1;
576285789Szbb	if (msi_count == 0 && msix_count == 0)
577285789Szbb		ctlr->msi = 0;
578256843Smav	if (ctlr->msi < 0)
579256843Smav		ctlr->msi = 0;
580285789Szbb	else if (ctlr->msi == 1) {
581285789Szbb		msi_count = min(1, msi_count);
582285789Szbb		msix_count = min(1, msix_count);
583285789Szbb	} else if (ctlr->msi > 1)
584256843Smav		ctlr->msi = 2;
585285789Szbb
586285789Szbb	/* Allocate MSI/MSI-x if needed/present. */
587285789Szbb	if (ctlr->msi > 0) {
588285789Szbb		error = ENXIO;
589285789Szbb
590285789Szbb		/* Try to allocate MSI-x first */
591285789Szbb		if (msix_count > 0) {
592285789Szbb			error = pci_alloc_msix(dev, &msix_count);
593285789Szbb			if (error == 0)
594285789Szbb				ctlr->numirqs = msix_count;
595285789Szbb		}
596285789Szbb
597285789Szbb		/*
598285789Szbb		 * Try to allocate MSI if msi_count is greater than 0
599285789Szbb		 * and if MSI-x allocation failed.
600285789Szbb		 */
601285789Szbb		if ((error != 0) && (msi_count > 0)) {
602285789Szbb			error = pci_alloc_msi(dev, &msi_count);
603285789Szbb			if (error == 0)
604285789Szbb				ctlr->numirqs = msi_count;
605285789Szbb		}
606285789Szbb
607285789Szbb		/* Both MSI and MSI-x allocations failed */
608285789Szbb		if (error != 0) {
609285789Szbb			ctlr->msi = 0;
610285789Szbb			device_printf(dev, "Failed to allocate MSI/MSI-x, "
611285789Szbb			    "falling back to INTx\n");
612285789Szbb		}
613256843Smav	}
614195534Sscottl
615271146Simp	error = ahci_attach(dev);
616285789Szbb	if (error != 0) {
617285789Szbb		if (ctlr->msi > 0)
618271146Simp			pci_release_msi(dev);
619285789Szbb		ahci_free_mem(dev);
620285789Szbb	}
621271146Simp	return error;
622195534Sscottl}
623195534Sscottl
624195534Sscottlstatic int
625271146Simpahci_pci_detach(device_t dev)
626195534Sscottl{
627195534Sscottl
628271146Simp	ahci_detach(dev);
629271146Simp	pci_release_msi(dev);
630195534Sscottl	return (0);
631195534Sscottl}
632195534Sscottl
633195534Sscottlstatic int
634271146Simpahci_pci_suspend(device_t dev)
635195534Sscottl{
636195534Sscottl	struct ahci_controller *ctlr = device_get_softc(dev);
637195534Sscottl
638271146Simp	bus_generic_suspend(dev);
639271146Simp	/* Disable interupts, so the state change(s) doesn't trigger */
640271146Simp	ATA_OUTL(ctlr->r_mem, AHCI_GHC,
641271146Simp	     ATA_INL(ctlr->r_mem, AHCI_GHC) & (~AHCI_GHC_IE));
642271146Simp	return 0;
643195534Sscottl}
644195534Sscottl
645195534Sscottlstatic int
646271146Simpahci_pci_resume(device_t dev)
647195534Sscottl{
648271146Simp	int res;
649195534Sscottl
650271146Simp	if ((res = ahci_pci_ctlr_reset(dev)) != 0)
651271146Simp		return (res);
652271146Simp	ahci_ctlr_setup(dev);
653271146Simp	return (bus_generic_resume(dev));
654195534Sscottl}
655195534Sscottl
656195534Sscottlstatic device_method_t ahci_methods[] = {
657195534Sscottl	DEVMETHOD(device_probe,     ahci_probe),
658271146Simp	DEVMETHOD(device_attach,    ahci_pci_attach),
659271146Simp	DEVMETHOD(device_detach,    ahci_pci_detach),
660271146Simp	DEVMETHOD(device_suspend,   ahci_pci_suspend),
661271146Simp	DEVMETHOD(device_resume,    ahci_pci_resume),
662195534Sscottl	DEVMETHOD(bus_print_child,  ahci_print_child),
663195534Sscottl	DEVMETHOD(bus_alloc_resource,       ahci_alloc_resource),
664195534Sscottl	DEVMETHOD(bus_release_resource,     ahci_release_resource),
665195534Sscottl	DEVMETHOD(bus_setup_intr,   ahci_setup_intr),
666195534Sscottl	DEVMETHOD(bus_teardown_intr,ahci_teardown_intr),
667208410Smav	DEVMETHOD(bus_child_location_str, ahci_child_location_str),
668249346Smav	DEVMETHOD(bus_get_dma_tag,  ahci_get_dma_tag),
669276344Smarius	DEVMETHOD_END
670195534Sscottl};
671195534Sscottlstatic driver_t ahci_driver = {
672195534Sscottl        "ahci",
673195534Sscottl        ahci_methods,
674195534Sscottl        sizeof(struct ahci_controller)
675195534Sscottl};
676276344SmariusDRIVER_MODULE(ahci, pci, ahci_driver, ahci_devclass, NULL, NULL);
677199322Smavstatic device_method_t ahci_ata_methods[] = {
678199322Smav	DEVMETHOD(device_probe,     ahci_ata_probe),
679271146Simp	DEVMETHOD(device_attach,    ahci_pci_attach),
680271146Simp	DEVMETHOD(device_detach,    ahci_pci_detach),
681271146Simp	DEVMETHOD(device_suspend,   ahci_pci_suspend),
682271146Simp	DEVMETHOD(device_resume,    ahci_pci_resume),
683199322Smav	DEVMETHOD(bus_print_child,  ahci_print_child),
684199322Smav	DEVMETHOD(bus_alloc_resource,       ahci_alloc_resource),
685199322Smav	DEVMETHOD(bus_release_resource,     ahci_release_resource),
686199322Smav	DEVMETHOD(bus_setup_intr,   ahci_setup_intr),
687199322Smav	DEVMETHOD(bus_teardown_intr,ahci_teardown_intr),
688208410Smav	DEVMETHOD(bus_child_location_str, ahci_child_location_str),
689276344Smarius	DEVMETHOD_END
690199322Smav};
691199322Smavstatic driver_t ahci_ata_driver = {
692199322Smav        "ahci",
693199322Smav        ahci_ata_methods,
694199322Smav        sizeof(struct ahci_controller)
695199322Smav};
696276344SmariusDRIVER_MODULE(ahci, atapci, ahci_ata_driver, ahci_devclass, NULL, NULL);
697