FreeBSD/Linux Kernel Cross Reference
sys/i386/isa/atapi.h
1 /*
2 * Device-independent level for ATAPI drivers.
3 *
4 * Copyright (C) 1995 Cronyx Ltd.
5 * Author Serge Vakulenko, <vak@cronyx.ru>
6 *
7 * This software is distributed with NO WARRANTIES, not even the implied
8 * warranties for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
9 *
10 * Authors grant any other persons or organizations permission to use
11 * or modify this software as long as this message is kept with the software,
12 * all derivative works or modified versions.
13 *
14 * Version 1.9, Thu Oct 12 15:53:50 MSK 1995
15 */
16
17 /*
18 * Disk Controller ATAPI register definitions.
19 */
20 #ifdef PC98
21 #define AR_DATA 0x0 /* RW - data register (16 bits) */
22 #define AR_ERROR 0x2 /* R - error register */
23 #define AR_FEATURES 0x2 /* W - features */
24 #define AR_IREASON 0x4 /* RW - interrupt reason */
25 #define AR_TAG 0x6 /* - reserved for SAM TAG byte */
26 #define AR_CNTLO 0x8 /* RW - byte count, low byte */
27 #define AR_CNTHI 0xa /* RW - byte count, high byte */
28 #define AR_DRIVE 0xc /* RW - drive select */
29 #define AR_COMMAND 0xe /* W - command register */
30 #define AR_STATUS 0xe /* R - immediate status */
31 #else
32 #define AR_DATA 0x0 /* RW - data register (16 bits) */
33 #define AR_ERROR 0x1 /* R - error register */
34 #define AR_FEATURES 0x1 /* W - features */
35 #define AR_IREASON 0x2 /* RW - interrupt reason */
36 #define AR_TAG 0x3 /* - reserved for SAM TAG byte */
37 #define AR_CNTLO 0x4 /* RW - byte count, low byte */
38 #define AR_CNTHI 0x5 /* RW - byte count, high byte */
39 #define AR_DRIVE 0x6 /* RW - drive select */
40 #define AR_COMMAND 0x7 /* W - command register */
41 #define AR_STATUS 0x7 /* R - immediate status */
42 #endif
43
44 /*
45 * Status register bits
46 */
47 #define ARS_CHECK 0x01 /* error occured, see sense key/code */
48 /* bit 0x02 reserved */
49 #define ARS_CORR 0x04 /* correctable error occured */
50 #define ARS_DRQ 0x08 /* data request / ireason valid */
51 #define ARS_DSC 0x10 /* immediate operation completed */
52 #define ARS_DF 0x20 /* drive fault */
53 #define ARS_DRDY 0x40 /* ready to get command */
54 #define ARS_BSY 0x80 /* registers busy */
55 /* for overlap mode only: */
56 #define ARS_SERVICE 0x10 /* service is requested */
57 #define ARS_DMARDY 0x20 /* ready to start a DMA transfer */
58 #define ARS_BITS "\2\010busy\7ready\6fault\5opdone\4drq\3corr\1check"
59
60 /*
61 * Error register bits
62 */
63 #define AER_ILI 0x01 /* illegal length indication */
64 #define AER_EOM 0x02 /* end of media detected */
65 #define AER_ABRT 0x04 /* command aborted */
66 #define AER_MCR 0x08 /* media change requested */
67 #define AER_SKEY 0xf0 /* sense key mask */
68 #define AER_SK_NO_SENSE 0x00 /* no specific sense key info */
69 #define AER_SK_RECOVERED_ERROR 0x10 /* command succeeded, data recovered */
70 #define AER_SK_NOT_READY 0x20 /* no access to drive */
71 #define AER_SK_MEDIUM_ERROR 0x30 /* non-recovered data error */
72 #define AER_SK_HARDWARE_ERROR 0x40 /* non-recoverable hardware failure */
73 #define AER_SK_ILLEGAL_REQUEST 0x50 /* invalid command parameter(s) */
74 #define AER_SK_UNIT_ATTENTION 0x60 /* media changed */
75 #define AER_SK_DATA_PROTECT 0x70 /* reading read-protected sector */
76 #define AER_SK_BLANK_CHECK 0x80 /* blank check */
77 #define AER_SK_VENDOR_SPECIFIC 0x90 /* vendor specific skey */
78 #define AER_SK_COPY_ABORTED 0xa0 /* copy aborted */
79 #define AER_SK_ABORTED_COMMAND 0xb0 /* command aborted, try again */
80 #define AER_SK_EQUAL 0xc0 /* equal */
81 #define AER_SK_VOLUME_OVERFLOW 0xd0 /* volume overflow */
82 #define AER_SK_MISCOMPARE 0xe0 /* data did not match the medium */
83 #define AER_SK_RESERVED 0xf0
84 #define AER_BITS "\2\4mchg\3abort\2eom\1ili"
85
86 /*
87 * Feature register bits
88 */
89 #define ARF_DMA 0x01 /* transfer data via DMA */
90 #define ARF_OVERLAP 0x02 /* release the bus until completion */
91
92 /*
93 * Interrupt reason register bits
94 */
95 #define ARI_CMD 0x01 /* command(1) or data(0) */
96 #define ARI_IN 0x02 /* transfer to(1) or from(0) the host */
97 #define ARI_RELEASE 0x04 /* bus released until completion */
98
99 /*
100 * Drive register values
101 */
102 #define ARD_DRIVE0 0xa0 /* drive 0 selected */
103 #define ARD_DRIVE1 0xb0 /* drive 1 selected */
104
105 /*
106 * ATA commands
107 */
108 #define ATAPIC_IDENTIFY 0xa1 /* get drive parameters */
109 #define ATAPIC_PACKET 0xa0 /* execute packet command */
110
111 /*
112 * Mandatory packet commands
113 */
114 #define ATAPI_TEST_UNIT_READY 0x00 /* check if the device is ready */
115 #define ATAPI_REZERO_UNIT 0x01 /* reinit device */
116 #define ATAPI_REQUEST_SENSE 0x03 /* get sense data */
117 #define ATAPI_START_STOP 0x1b /* start/stop the media */
118 #define ATAPI_PREVENT_ALLOW 0x1e /* prevent/allow media removal */
119 #define ATAPI_READ_CAPACITY 0x25 /* get volume capacity */
120 #define ATAPI_READ_BIG 0x28 /* read data */
121 #define ATAPI_WRITE_BIG 0x2a /* write data */
122 #define ATAPI_SYNCHRONIZE_CACHE 0x35 /* flush write buf, close write chan */
123 #define ATAPI_READ_SUBCHANNEL 0x42 /* get subchannel info */
124 #define ATAPI_READ_TOC 0x43 /* get table of contents */
125 #define ATAPI_READ_TRACK_INFO 0x52 /* get track information structure */
126 #define ATAPI_MODE_SELECT 0x55 /* set device parameters */
127 #define ATAPI_MODE_SENSE 0x5a /* get device parameters */
128 #define ATAPI_CLOSE_TRACK 0x5b /* close track/session */
129 #define ATAPI_LOAD_UNLOAD 0xa6 /* changer control command */
130 #define ATAPI_PLAY_CD 0xb4 /* universal play command */
131 #define ATAPI_MECH_STATUS 0xbd /* get changer mechanism status */
132 #define ATAPI_READ_CD 0xbe /* read data */
133 /*
134 * Optional packet commands
135 */
136 #define ATAPI_PLAY_MSF 0x47 /* play by MSF address */
137 #define ATAPI_PAUSE 0x4b /* stop/start audio operation */
138
139 /*
140 * Nonstandard packet commands
141 */
142 #define ATAPI_PLAY_TRACK 0x48 /* play by track number */
143 #define ATAPI_PLAY_BIG 0xa5 /* play by logical block address */
144
145 #define DSC_POLL_INTERVAL 10
146
147 /*
148 * Drive parameter information
149 */
150 struct atapi_params {
151 unsigned cmdsz : 2; /* packet command size */
152 #define AT_PSIZE_12 0 /* 12 bytes */
153 #define AT_PSIZE_16 1 /* 16 bytes */
154 unsigned : 3;
155 unsigned drqtype : 2; /* DRQ type */
156 #define AT_DRQT_MPROC 0 /* microprocessor DRQ - 3 msec delay */
157 #define AT_DRQT_INTR 1 /* interrupt DRQ - 10 msec delay */
158 #define AT_DRQT_ACCEL 2 /* accelerated DRQ - 50 usec delay */
159 unsigned removable : 1; /* device is removable */
160 unsigned devtype : 5; /* device type */
161 #define AT_TYPE_DIRECT 0 /* direct-access (magnetic disk) */
162 #define AT_TYPE_TAPE 1 /* streaming tape (QIC-121 model) */
163 #define AT_TYPE_CDROM 5 /* CD-ROM device */
164 #define AT_TYPE_OPTICAL 7 /* optical disk */
165 unsigned : 1;
166 unsigned proto : 2; /* command protocol */
167 #define AT_PROTO_ATAPI 2
168 short reserved1[9];
169 char serial[20]; /* serial number - optional */
170 short reserved2[3];
171 char revision[8]; /* firmware revision */
172 char model[40]; /* model name */
173 short reserved3[2];
174 u_char vendor_cap; /* vendor unique capabilities */
175 unsigned dmaflag : 1; /* DMA supported */
176 unsigned lbaflag : 1; /* LBA supported - always 1 */
177 unsigned iordydis : 1; /* IORDY can be disabled */
178 unsigned iordyflag : 1; /* IORDY supported */
179 unsigned : 1;
180 unsigned ovlapflag : 1; /* overlap operation supported */
181 unsigned : 1;
182 unsigned idmaflag : 1; /* interleaved DMA supported */
183 short reserved4;
184 u_short pio_timing; /* PIO cycle timing */
185 u_short dma_timing; /* DMA cycle timing */
186 u_short flags;
187 #define AT_FLAG_54_58 1 /* words 54-58 valid */
188 #define AT_FLAG_64_70 2 /* words 64-70 valid */
189 short reserved5[8];
190 u_char swdma_flag; /* singleword DMA mode supported */
191 u_char swdma_active; /* singleword DMA mode active */
192 u_char mwdma_flag; /* multiword DMA mode supported */
193 u_char mwdma_active; /* multiword DMA mode active */
194 u_char apio_flag; /* advanced PIO mode supported */
195 u_char reserved6;
196 u_short mwdma_min; /* min. M/W DMA time per word (ns) */
197 u_short mwdma_dflt; /* recommended M/W DMA time (ns) - optional */
198 u_short pio_nfctl_min; /* min. PIO cycle time w/o flow ctl - optional */
199 u_short pio_iordy_min; /* min. PIO c/t with IORDY flow ctl - optional */
200 short reserved7[2];
201 u_short rls_ovlap; /* release time (us) for overlap cmd - optional */
202 u_short rls_service; /* release time (us) for service cmd - optional */
203 };
204
205 /*
206 * ATAPI operation result structure
207 */
208 struct atapires {
209 u_char code; /* result code */
210 #define RES_OK 0 /* i/o done */
211 #define RES_ERR 1 /* i/o finished with error */
212 #define RES_NOTRDY 2 /* controller not ready */
213 #define RES_NODRQ 3 /* no data request */
214 #define RES_INVDIR 4 /* invalid bus phase direction */
215 #define RES_OVERRUN 5 /* data overrun */
216 #define RES_UNDERRUN 6 /* data underrun */
217 u_char status; /* status register contents */
218 u_char error; /* error register contents */
219 };
220
221 struct atapidrv { /* delayed attach info */
222 int ctlr; /* IDE controller, 0/1 */
223 int unit; /* drive unit, 0/1 */
224 int port; /* controller base port */
225 int attached; /* the drive is attached */
226 };
227
228 struct buf;
229 struct wcd;
230 typedef void atapi_callback_t(struct wcd *, struct buf *, int, struct atapires);
231
232 struct atapicmd { /* ATAPI command block */
233 struct atapicmd *next; /* next command in queue */
234 int busy; /* busy flag */
235 u_char cmd[16]; /* command and args */
236 int unit; /* drive unit number */
237 int count; /* byte count, >0 - read, <0 - write */
238 char *addr; /* data to transfer */
239 atapi_callback_t *callback; /* call when done */
240 void *cbarg1; /* callback arg 1 */
241 void *cbarg2; /* callback arg 1 */
242 struct atapires result; /* resulting error code */
243 };
244
245 struct atapi { /* ATAPI controller data */
246 u_short port; /* i/o port base */
247 u_char ctrlr; /* physical controller number */
248 u_char debug : 1; /* trace enable flag */
249 u_char cmd16 : 1; /* 16-byte command flag */
250 u_char intrcmd : 1; /* interrupt before cmd flag */
251 u_char slow : 1; /* slow reaction device */
252 u_char accel : 1; /* accelerated reaction device */
253 u_char use_dsc : 1; /* use DSC completition handeling */
254 u_char wait_for_dsc : 1;
255 u_int dsc_timeout;
256 u_char attached[2]; /* units are attached to subdrivers */
257 struct atapi_params *params[2]; /* params for units 0,1 */
258 struct atapicmd *queue; /* queue of commands to perform */
259 struct atapicmd *tail; /* tail of queue */
260 struct atapicmd *free; /* queue of free command blocks */
261 struct atapicmd cmdrq[16]; /* pool of command requests */
262 };
263
264 #ifdef KERNEL
265 struct atapi;
266
267 extern struct atapidrv atapi_drvtab[4]; /* delayed attach info */
268 extern int atapi_ndrv; /* the number of potential drives */
269 extern struct atapi *atapi_tab; /* the table of atapi controllers */
270
271 #ifndef ATAPI_STATIC
272 # define atapi_start (*atapi_start_ptr)
273 # define atapi_intr (*atapi_intr_ptr)
274 # define atapi_debug (*atapi_debug_ptr)
275 # define atapi_request_wait (*atapi_request_wait_ptr)
276 # define atapi_request_callback (*atapi_request_callback_ptr)
277 # define atapi_request_immediate (*atapi_request_immediate_ptr)
278 #endif
279
280 #ifndef ATAPI_MODULE
281 int atapi_attach (int ctlr, int unit, int port);
282 #endif
283
284 /*
285 * These "functions" are declared with archaic `extern's because they are
286 * actually pointers in the !ATAPI_STATIC case.
287 */
288 extern int atapi_start (int ctrlr);
289 extern int atapi_intr (int ctrlr);
290 extern void atapi_debug (struct atapi *ata, int on);
291 extern struct atapires atapi_request_wait (struct atapi *ata, int unit,
292 u_char cmd, u_char a1, u_char a2, u_char a3, u_char a4,
293 u_char a5, u_char a6, u_char a7, u_char a8, u_char a9,
294 u_char a10, u_char a11, u_char a12, u_char a13, u_char a14, u_char a15,
295 char *addr, int count);
296 extern void atapi_request_callback (struct atapi *ata, int unit,
297 u_char cmd, u_char a1, u_char a2, u_char a3, u_char a4,
298 u_char a5, u_char a6, u_char a7, u_char a8, u_char a9,
299 u_char a10, u_char a11, u_char a12, u_char a13, u_char a14, u_char a15,
300 char *addr, int count, atapi_callback_t *done, void *x, void *y);
301 extern struct atapires atapi_request_immediate (struct atapi *ata, int unit,
302 u_char cmd, u_char a1, u_char a2, u_char a3, u_char a4,
303 u_char a5, u_char a6, u_char a7, u_char a8, u_char a9,
304 u_char a10, u_char a11, u_char a12, u_char a13, u_char a14, u_char a15,
305 char *addr, int count);
306 #endif
307
308 #define ATAPI_MODE_SELECT_BIG 0x55 /* set device parameters */
Cache object: 7215bc6961b6910484d1fa845ddeb6a3
|