forked from fjballest/nix.markII
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathahci.h
293 lines (263 loc) · 6.52 KB
/
ahci.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
/*
* advanced host controller interface (sata)
* © 2007 coraid, inc
*/
/* ata errors */
enum {
Emed = 1<<0, /* media error */
Enm = 1<<1, /* no media */
Eabrt = 1<<2, /* abort */
Emcr = 1<<3, /* media change request */
Eidnf = 1<<4, /* no user-accessible address */
Emc = 1<<5, /* media change */
Eunc = 1<<6, /* data error */
Ewp = 1<<6, /* write protect */
Eicrc = 1<<7, /* interface crc error */
Efatal = Eidnf|Eicrc, /* must sw reset */
};
/* ata status */
enum {
ASerr = 1<<0, /* error */
ASdrq = 1<<3, /* request */
ASdf = 1<<5, /* fault */
ASdrdy = 1<<6, /* ready */
ASbsy = 1<<7, /* busy */
ASobs = 1<<1|1<<2|1<<4,
};
/* pci configuration */
enum {
Abar = 5,
};
/*
* ahci memory configuration
*
* 0000-0023 generic host control
* 0024-009f reserved
* 00a0-00ff vendor specific.
* 0100-017f port 0
* ...
* 1080-1100 port 31
*/
/* cap bits: supported features */
enum {
Hs64a = 1<<31, /* 64-bit addressing */
Hsncq = 1<<30, /* ncq */
Hssntf = 1<<29, /* snotification reg. */
Hsmps = 1<<28, /* mech pres switch */
Hsss = 1<<27, /* staggered spinup */
Hsalp = 1<<26, /* aggressive link pm */
Hsal = 1<<25, /* activity led */
Hsclo = 1<<24, /* command-list override */
Hiss = 1<<20, /* for interface speed */
// Hsnzo = 1<<19,
Hsam = 1<<18, /* ahci-mode only */
Hspm = 1<<17, /* port multiplier */
// Hfbss = 1<<16,
Hpmb = 1<<15, /* multiple-block pio */
Hssc = 1<<14, /* slumber state */
Hpsc = 1<<13, /* partial-slumber state */
Hncs = 1<<8, /* n command slots */
Hcccs = 1<<7, /* coal */
Hems = 1<<6, /* enclosure mgmt. */
Hsxs = 1<<5, /* external sata */
Hnp = 1<<0, /* n ports */
};
/* ghc bits */
enum {
Hae = 1<<31, /* enable ahci */
Hie = 1<<1, /* " interrupts */
Hhr = 1<<0, /* hba reset */
};
typedef struct {
ulong cap;
ulong ghc;
ulong isr;
ulong pi; /* ports implemented */
ulong ver;
ulong ccc; /* coaleasing control */
ulong cccports;
ulong emloc;
ulong emctl;
} Ahba;
enum {
Acpds = 1<<31, /* cold port detect status */
Atfes = 1<<30, /* task file error status */
Ahbfs = 1<<29, /* hba fatal */
Ahbds = 1<<28, /* hba error (parity error) */
Aifs = 1<<27, /* interface fatal §6.1.2 */
Ainfs = 1<<26, /* interface error (recovered) */
Aofs = 1<<24, /* too many bytes from disk */
Aipms = 1<<23, /* incorrect prt mul status */
Aprcs = 1<<22, /* PhyRdy change status Pxserr.diag.n */
Adpms = 1<<7, /* mechanical presence status */
Apcs = 1<<6, /* port connect diag.x */
Adps = 1<<5, /* descriptor processed */
Aufs = 1<<4, /* unknown fis diag.f */
Asdbs = 1<<3, /* set device bits fis received w/ i bit set */
Adss = 1<<2, /* dma setup */
Apio = 1<<1, /* pio setup fis */
Adhrs = 1<<0, /* device to host register fis */
IEM = Acpds|Atfes|Ahbds|Ahbfs|Ahbds|Aifs|Ainfs|Aprcs|Apcs|Adps|
Aufs|Asdbs|Adss|Adhrs,
Ifatal = Atfes|Ahbfs|Ahbds|Aifs,
};
/* serror bits */
enum {
SerrX = 1<<26, /* exchanged */
SerrF = 1<<25, /* unknown fis */
SerrT = 1<<24, /* transition error */
SerrS = 1<<23, /* link sequence */
SerrH = 1<<22, /* handshake */
SerrC = 1<<21, /* crc */
SerrD = 1<<20, /* not used by ahci */
SerrB = 1<<19, /* 10-tp-8 decode */
SerrW = 1<<18, /* comm wake */
SerrI = 1<<17, /* phy internal */
SerrN = 1<<16, /* phyrdy change */
ErrE = 1<<11, /* internal */
ErrP = 1<<10, /* ata protocol violation */
ErrC = 1<<9, /* communication */
ErrT = 1<<8, /* transient */
ErrM = 1<<1, /* recoverd comm */
ErrI = 1<<0, /* recovered data integrety */
ErrAll = ErrE|ErrP|ErrC|ErrT|ErrM|ErrI,
SerrAll = SerrX|SerrF|SerrT|SerrS|SerrH|SerrC|SerrD|SerrB|SerrW|
SerrI|SerrN|ErrAll,
SerrBad = 0x7f<<19,
};
/* cmd register bits */
enum {
Aicc = 1<<28, /* interface communcations control. 4 bits */
Aasp = 1<<27, /* aggressive slumber & partial sleep */
Aalpe = 1<<26, /* aggressive link pm enable */
Adlae = 1<<25, /* drive led on atapi */
Aatapi = 1<<24, /* device is atapi */
Aesp = 1<<21, /* external sata port */
Acpd = 1<<20, /* cold presence detect */
Ampsp = 1<<19, /* mechanical pres. */
Ahpcp = 1<<18, /* hot plug capable */
Apma = 1<<17, /* pm attached */
Acps = 1<<16, /* cold presence state */
Acr = 1<<15, /* cmdlist running */
Afr = 1<<14, /* fis running */
Ampss = 1<<13, /* mechanical presence switch state */
Accs = 1<<8, /* current command slot 12:08 */
Afre = 1<<4, /* fis enable receive */
Aclo = 1<<3, /* command list override */
Apod = 1<<2, /* power on dev (requires cold-pres. detect) */
Asud = 1<<1, /* spin-up device; requires ss capability */
Ast = 1<<0, /* start */
Arun = Ast|Acr|Afre|Afr,
};
/* ctl register bits */
enum {
Aipm = 1<<8, /* interface power mgmt. 3=off */
Aspd = 1<<4,
Adet = 1<<0, /* device detection */
};
#define sstatus scr0
#define sctl scr2
#define serror scr1
#define sactive scr3
typedef struct {
ulong list; /* PxCLB must be 1kb aligned. */
ulong listhi;
ulong fis; /* 256-byte aligned */
ulong fishi;
ulong isr;
ulong ie; /* interrupt enable */
ulong cmd;
ulong res1;
ulong task;
ulong sig;
ulong scr0;
ulong scr2;
ulong scr1;
ulong scr3;
ulong ci; /* command issue */
ulong ntf;
uchar res2[8];
ulong vendor;
} Aport;
enum {
/*
* Aport sstatus bits (actually states):
* 11-8 interface power management
* 7-4 current interface speed (generation #)
* 3-0 device detection
*/
Intslumber = 0x600,
Intpartpwr = 0x200,
Intactive = 0x100,
Intpm = 0xf00,
Devphyoffline = 4,
Devphycomm = 2, /* phy communication established */
Devpresent = 1,
Devdet = Devpresent | Devphycomm | Devphyoffline,
};
/* in host's memory; not memory mapped */
typedef struct {
uchar *base;
uchar *d;
uchar *p;
uchar *r;
uchar *u;
ulong *devicebits;
} Afis;
enum {
Lprdtl = 1<<16, /* physical region descriptor table len */
Lpmp = 1<<12, /* port multiplier port */
Lclear = 1<<10, /* clear busy on R_OK */
Lbist = 1<<9,
Lreset = 1<<8,
Lpref = 1<<7, /* prefetchable */
Lwrite = 1<<6,
Latapi = 1<<5,
Lcfl = 1<<0, /* command fis length in double words */
};
/* in hosts memory; memory mapped */
typedef struct {
ulong flags;
ulong len;
ulong ctab;
ulong ctabhi;
uchar reserved[16];
} Alist;
typedef struct {
ulong dba;
ulong dbahi;
ulong pad;
ulong count;
} Aprdt;
typedef struct {
uchar cfis[0x40];
uchar atapi[0x10];
uchar pad[0x30];
Aprdt prdt;
} Actab;
enum {
Ferror = 1,
Fdone = 2,
};
enum {
Dllba = 1,
Dsmart = 1<<1,
Dpower = 1<<2,
Dnop = 1<<3,
Datapi = 1<<4,
Datapi16= 1<<5,
};
typedef struct {
QLock;
Rendez;
uchar flag;
uchar feat;
uchar smart;
Afis fis;
Alist *list;
Actab *ctab;
} Aportm;
typedef struct {
Aport *p;
Aportm *pm;
} Aportc;