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#ifndef _ATA_H
34#define _ATA_H
35
36
37
38
39
40#ifndef CFG_ATA_STRIDE
41#define CFG_ATA_STRIDE 1
42#endif
43
44#define ATA_IO_DATA(x) (CFG_ATA_DATA_OFFSET+((x) * CFG_ATA_STRIDE))
45#define ATA_IO_REG(x) (CFG_ATA_REG_OFFSET +((x) * CFG_ATA_STRIDE))
46#define ATA_IO_ALT(x) (CFG_ATA_ALT_OFFSET +((x) * CFG_ATA_STRIDE))
47
48
49
50
51#define ATA_DATA_REG ATA_IO_DATA(0)
52#define ATA_ERROR_REG ATA_IO_REG(1)
53#define ATA_SECT_CNT ATA_IO_REG(2)
54#define ATA_SECT_NUM ATA_IO_REG(3)
55#define ATA_CYL_LOW ATA_IO_REG(4)
56#define ATA_CYL_HIGH ATA_IO_REG(5)
57#define ATA_DEV_HD ATA_IO_REG(6)
58#define ATA_COMMAND ATA_IO_REG(7)
59#define ATA_DATA_EVEN ATA_IO_REG(8)
60#define ATA_DATA_ODD ATA_IO_REG(9)
61#define ATA_STATUS ATA_COMMAND
62#define ATA_DEV_CTL ATA_IO_ALT(6)
63#define ATA_LBA_LOW ATA_SECT_NUM
64#define ATA_LBA_MID ATA_CYL_LOW
65#define ATA_LBA_HIGH ATA_CYL_HIGH
66#define ATA_LBA_SEL ATA_DEV_CTL
67
68
69
70
71#define ATA_STAT_BUSY 0x80
72#define ATA_STAT_READY 0x40
73#define ATA_STAT_FAULT 0x20
74#define ATA_STAT_SEEK 0x10
75#define ATA_STAT_DRQ 0x08
76#define ATA_STAT_CORR 0x04
77#define ATA_STAT_INDEX 0x02
78#define ATA_STAT_ERR 0x01
79
80
81
82
83#define ATA_DEVICE(x) ((x & 1)<<4)
84#define ATA_LBA 0xE0
85
86enum {
87 ATA_MAX_DEVICES = 1,
88 ATA_MAX_PRD = 256,
89 ATA_SECT_SIZE = 256,
90
91
92 ATA_HOB = (1 << 7),
93 ATA_NIEN = (1 << 1),
94
95 ATA_DEV1 = (1 << 4),
96 ATA_DEVICE_OBS = (1 << 7) | (1 << 5),
97 ATA_DEVCTL_OBS = (1 << 3),
98 ATA_BUSY = (1 << 7),
99 ATA_DRDY = (1 << 6),
100 ATA_DF = (1 << 5),
101 ATA_DRQ = (1 << 3),
102 ATA_ERR = (1 << 0),
103 ATA_SRST = (1 << 2),
104 ATA_ABORTED = (1 << 2),
105
106 ATA_REG_DATA = 0x00,
107 ATA_REG_ERR = 0x01,
108 ATA_REG_NSECT = 0x02,
109 ATA_REG_LBAL = 0x03,
110 ATA_REG_LBAM = 0x04,
111 ATA_REG_LBAH = 0x05,
112 ATA_REG_DEVICE = 0x06,
113 ATA_REG_STATUS = 0x07,
114 ATA_PCI_CTL_OFS = 0x02,
115
116 ATA_REG_FEATURE = ATA_REG_ERR,
117 ATA_REG_CMD = ATA_REG_STATUS,
118 ATA_REG_BYTEL = ATA_REG_LBAM,
119 ATA_REG_BYTEH = ATA_REG_LBAH,
120 ATA_REG_DEVSEL = ATA_REG_DEVICE,
121 ATA_REG_IRQ = ATA_REG_NSECT,
122
123
124 SETFEATURES_XFER = 0x03,
125 XFER_UDMA_7 = 0x47,
126 XFER_UDMA_6 = 0x46,
127 XFER_UDMA_5 = 0x45,
128 XFER_UDMA_4 = 0x44,
129 XFER_UDMA_3 = 0x43,
130 XFER_UDMA_2 = 0x42,
131 XFER_UDMA_1 = 0x41,
132 XFER_UDMA_0 = 0x40,
133 XFER_MW_DMA_2 = 0x22,
134 XFER_MW_DMA_1 = 0x21,
135 XFER_MW_DMA_0 = 0x20,
136 XFER_PIO_4 = 0x0C,
137 XFER_PIO_3 = 0x0B,
138 XFER_PIO_2 = 0x0A,
139 XFER_PIO_1 = 0x09,
140 XFER_PIO_0 = 0x08,
141 XFER_SW_DMA_2 = 0x12,
142 XFER_SW_DMA_1 = 0x11,
143 XFER_SW_DMA_0 = 0x10,
144 XFER_PIO_SLOW = 0x00
145};
146
147
148
149#define ATA_CMD_READ 0x20
150#define ATA_CMD_READN 0x21
151#define ATA_CMD_WRITE 0x30
152#define ATA_CMD_WRITEN 0x31
153#define ATA_CMD_VRFY 0x40
154#define ATA_CMD_VRFYN 0x41
155#define ATA_CMD_SEEK 0x70
156#define ATA_CMD_DIAG 0x90
157#define ATA_CMD_INIT 0x91
158#define ATA_CMD_RD_MULT 0xC4
159#define ATA_CMD_WR_MULT 0xC5
160#define ATA_CMD_SETMULT 0xC6
161#define ATA_CMD_RD_DMA 0xC8
162#define ATA_CMD_RD_DMAN 0xC9
163#define ATA_CMD_WR_DMA 0xCA
164#define ATA_CMD_WR_DMAN 0xCB
165#define ATA_CMD_IDENT 0xEC
166#define ATA_CMD_SETF 0xEF
167#define ATA_CMD_CHK_PWR 0xE5
168
169#define ATA_CMD_READ_EXT 0x24
170#define ATA_CMD_WRITE_EXT 0x34
171#define ATA_CMD_VRFY_EXT 0x42
172
173
174
175
176#define ATAPI_CMD_IDENT 0xA1
177#define ATAPI_CMD_PACKET 0xA0
178
179
180#define ATAPI_CMD_INQUIRY 0x12
181#define ATAPI_CMD_REQ_SENSE 0x03
182#define ATAPI_CMD_READ_CAP 0x25
183#define ATAPI_CMD_START_STOP 0x1B
184#define ATAPI_CMD_READ_12 0xA8
185
186
187#define ATA_GET_ERR() inb(ATA_STATUS)
188#define ATA_GET_STAT() inb(ATA_STATUS)
189#define ATA_OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good))
190#define ATA_BAD_R_STAT (ATA_STAT_BUSY | ATA_STAT_ERR)
191#define ATA_BAD_W_STAT (ATA_BAD_R_STAT | ATA_STAT_FAULT)
192#define ATA_BAD_STAT (ATA_BAD_R_STAT | ATA_STAT_DRQ)
193#define ATA_DRIVE_READY (ATA_READY_STAT | ATA_STAT_SEEK)
194#define ATA_DATA_READY (ATA_STAT_DRQ)
195
196#define ATA_BLOCKSIZE 512
197#define ATA_BLOCKSHIFT 9
198#define ATA_SECTORWORDS (512 / sizeof(unsigned long))
199
200#ifndef ATA_RESET_TIME
201#define ATA_RESET_TIME 60
202#endif
203
204
205
206
207
208
209typedef struct hd_driveid {
210 unsigned short config;
211 unsigned short cyls;
212 unsigned short reserved2;
213 unsigned short heads;
214 unsigned short track_bytes;
215 unsigned short sector_bytes;
216 unsigned short sectors;
217 unsigned short vendor0;
218 unsigned short vendor1;
219 unsigned short vendor2;
220 unsigned char serial_no[20];
221 unsigned short buf_type;
222 unsigned short buf_size;
223 unsigned short ecc_bytes;
224 unsigned char fw_rev[8];
225 unsigned char model[40];
226 unsigned char max_multsect;
227 unsigned char vendor3;
228 unsigned short dword_io;
229 unsigned char vendor4;
230 unsigned char capability;
231 unsigned short reserved50;
232 unsigned char vendor5;
233 unsigned char tPIO;
234 unsigned char vendor6;
235 unsigned char tDMA;
236 unsigned short field_valid;
237 unsigned short cur_cyls;
238 unsigned short cur_heads;
239 unsigned short cur_sectors;
240 unsigned short cur_capacity0;
241 unsigned short cur_capacity1;
242 unsigned char multsect;
243 unsigned char multsect_valid;
244 unsigned int lba_capacity;
245 unsigned short dma_1word;
246 unsigned short dma_mword;
247 unsigned short eide_pio_modes;
248 unsigned short eide_dma_min;
249 unsigned short eide_dma_time;
250 unsigned short eide_pio;
251 unsigned short eide_pio_iordy;
252 unsigned short words69_70[2];
253 unsigned short words71_74[4];
254 unsigned short queue_depth;
255 unsigned short words76_79[4];
256 unsigned short major_rev_num;
257 unsigned short minor_rev_num;
258 unsigned short command_set_1;
259 unsigned short command_set_2;
260 unsigned short cfsse;
261 unsigned short cfs_enable_1;
262 unsigned short cfs_enable_2;
263 unsigned short csf_default;
264 unsigned short dma_ultra;
265 unsigned short word89;
266 unsigned short word90;
267 unsigned short CurAPMvalues;
268 unsigned short word92;
269 unsigned short hw_config;
270 unsigned short words94_99[6];
271
272 unsigned short lba48_capacity[4];
273 unsigned short words104_125[22];
274 unsigned short last_lun;
275 unsigned short word127;
276 unsigned short dlf;
277
278
279
280
281
282
283
284
285
286
287 unsigned short csfo;
288
289
290
291
292
293
294 unsigned short words130_155[26];
295 unsigned short word156;
296 unsigned short words157_159[3];
297 unsigned short words160_255[95];
298} hd_driveid_t;
299
300
301
302
303
304
305
306
307typedef struct {
308 unsigned int t_setup;
309 unsigned int t_length;
310 unsigned int t_hold;
311}
312pio_config_t;
313
314#define IDE_MAX_PIO_MODE 4
315
316
317
318#endif
319