added a lot of printk output to ease writing of emulator
[linux-2.4.21-pre4.git] / include / linux / cdrom.h
1 /*
2  * -- <linux/cdrom.h>
3  * General header file for linux CD-ROM drivers 
4  * Copyright (C) 1992         David Giller, rafetmad@oxy.edu
5  *               1994, 1995   Eberhard Moenkeberg, emoenke@gwdg.de
6  *               1996         David van Leeuwen, david@tm.tno.nl
7  *               1997, 1998   Erik Andersen, andersee@debian.org
8  *               1998-2000    Jens Axboe, axboe@suse.de
9  */
10  
11 #ifndef _LINUX_CDROM_H
12 #define _LINUX_CDROM_H
13
14 #include <asm/byteorder.h>
15
16 /*******************************************************
17  * As of Linux 2.1.x, all Linux CD-ROM application programs will use this 
18  * (and only this) include file.  It is my hope to provide Linux with
19  * a uniform interface between software accessing CD-ROMs and the various 
20  * device drivers that actually talk to the drives.  There may still be
21  * 23 different kinds of strange CD-ROM drives, but at least there will 
22  * now be one, and only one, Linux CD-ROM interface.
23  *
24  * Additionally, as of Linux 2.1.x, all Linux application programs 
25  * should use the O_NONBLOCK option when opening a CD-ROM device 
26  * for subsequent ioctl commands.  This allows for neat system errors 
27  * like "No medium found" or "Wrong medium type" upon attempting to 
28  * mount or play an empty slot, mount an audio disc, or play a data disc.
29  * Generally, changing an application program to support O_NONBLOCK
30  * is as easy as the following:
31  *       -    drive = open("/dev/cdrom", O_RDONLY);
32  *       +    drive = open("/dev/cdrom", O_RDONLY | O_NONBLOCK);
33  * It is worth the small change.
34  *
35  *  Patches for many common CD programs (provided by David A. van Leeuwen)
36  *  can be found at:  ftp://ftp.gwdg.de/pub/linux/cdrom/drivers/cm206/
37  * 
38  *******************************************************/
39
40 /* When a driver supports a certain function, but the cdrom drive we are 
41  * using doesn't, we will return the error EDRIVE_CANT_DO_THIS.  We will 
42  * borrow the "Operation not supported" error from the network folks to 
43  * accomplish this.  Maybe someday we will get a more targeted error code, 
44  * but this will do for now... */
45 #define EDRIVE_CANT_DO_THIS  EOPNOTSUPP
46
47 /*******************************************************
48  * The CD-ROM IOCTL commands  -- these should be supported by 
49  * all the various cdrom drivers.  For the CD-ROM ioctls, we 
50  * will commandeer byte 0x53, or 'S'.
51  *******************************************************/
52 #define CDROMPAUSE              0x5301 /* Pause Audio Operation */ 
53 #define CDROMRESUME             0x5302 /* Resume paused Audio Operation */
54 #define CDROMPLAYMSF            0x5303 /* Play Audio MSF (struct cdrom_msf) */
55 #define CDROMPLAYTRKIND         0x5304 /* Play Audio Track/index 
56                                            (struct cdrom_ti) */
57 #define CDROMREADTOCHDR         0x5305 /* Read TOC header 
58                                            (struct cdrom_tochdr) */
59 #define CDROMREADTOCENTRY       0x5306 /* Read TOC entry 
60                                            (struct cdrom_tocentry) */
61 #define CDROMSTOP               0x5307 /* Stop the cdrom drive */
62 #define CDROMSTART              0x5308 /* Start the cdrom drive */
63 #define CDROMEJECT              0x5309 /* Ejects the cdrom media */
64 #define CDROMVOLCTRL            0x530a /* Control output volume 
65                                            (struct cdrom_volctrl) */
66 #define CDROMSUBCHNL            0x530b /* Read subchannel data 
67                                            (struct cdrom_subchnl) */
68 #define CDROMREADMODE2          0x530c /* Read CDROM mode 2 data (2336 Bytes) 
69                                            (struct cdrom_read) */
70 #define CDROMREADMODE1          0x530d /* Read CDROM mode 1 data (2048 Bytes)
71                                            (struct cdrom_read) */
72 #define CDROMREADAUDIO          0x530e /* (struct cdrom_read_audio) */
73 #define CDROMEJECT_SW           0x530f /* enable(1)/disable(0) auto-ejecting */
74 #define CDROMMULTISESSION       0x5310 /* Obtain the start-of-last-session 
75                                            address of multi session disks 
76                                            (struct cdrom_multisession) */
77 #define CDROM_GET_MCN           0x5311 /* Obtain the "Universal Product Code" 
78                                            if available (struct cdrom_mcn) */
79 #define CDROM_GET_UPC           CDROM_GET_MCN  /* This one is depricated, 
80                                           but here anyway for compatability */
81 #define CDROMRESET              0x5312 /* hard-reset the drive */
82 #define CDROMVOLREAD            0x5313 /* Get the drive's volume setting 
83                                           (struct cdrom_volctrl) */
84 #define CDROMREADRAW            0x5314  /* read data in raw mode (2352 Bytes)
85                                            (struct cdrom_read) */
86 /* 
87  * These ioctls are used only used in aztcd.c and optcd.c
88  */
89 #define CDROMREADCOOKED         0x5315  /* read data in cooked mode */
90 #define CDROMSEEK               0x5316  /* seek msf address */
91   
92 /*
93  * This ioctl is only used by the scsi-cd driver.  
94    It is for playing audio in logical block addressing mode.
95  */
96 #define CDROMPLAYBLK            0x5317  /* (struct cdrom_blk) */
97
98 /* 
99  * These ioctls are only used in optcd.c
100  */
101 #define CDROMREADALL            0x5318  /* read all 2646 bytes */
102
103 /* 
104  * These ioctls are (now) only in ide-cd.c for controlling 
105  * drive spindown time.  They should be implemented in the
106  * Uniform driver, via generic packet commands, GPCMD_MODE_SELECT_10,
107  * GPCMD_MODE_SENSE_10 and the GPMODE_POWER_PAGE...
108  *  -Erik
109  */
110 #define CDROMGETSPINDOWN        0x531d
111 #define CDROMSETSPINDOWN        0x531e
112
113 /* 
114  * These ioctls are implemented through the uniform CD-ROM driver
115  * They _will_ be adopted by all CD-ROM drivers, when all the CD-ROM
116  * drivers are eventually ported to the uniform CD-ROM driver interface.
117  */
118 #define CDROMCLOSETRAY          0x5319  /* pendant of CDROMEJECT */
119 #define CDROM_SET_OPTIONS       0x5320  /* Set behavior options */
120 #define CDROM_CLEAR_OPTIONS     0x5321  /* Clear behavior options */
121 #define CDROM_SELECT_SPEED      0x5322  /* Set the CD-ROM speed */
122 #define CDROM_SELECT_DISC       0x5323  /* Select disc (for juke-boxes) */
123 #define CDROM_MEDIA_CHANGED     0x5325  /* Check is media changed  */
124 #define CDROM_DRIVE_STATUS      0x5326  /* Get tray position, etc. */
125 #define CDROM_DISC_STATUS       0x5327  /* Get disc type, etc. */
126 #define CDROM_CHANGER_NSLOTS    0x5328  /* Get number of slots */
127 #define CDROM_LOCKDOOR          0x5329  /* lock or unlock door */
128 #define CDROM_DEBUG             0x5330  /* Turn debug messages on/off */
129 #define CDROM_GET_CAPABILITY    0x5331  /* get capabilities */
130
131 /* Note that scsi/scsi_ioctl.h also uses 0x5382 - 0x5386.
132  * Future CDROM ioctls should be kept below 0x537F
133  */
134
135 /* This ioctl is only used by sbpcd at the moment */
136 #define CDROMAUDIOBUFSIZ        0x5382  /* set the audio buffer size */
137                                         /* conflict with SCSI_IOCTL_GET_IDLUN */
138
139 /* DVD-ROM Specific ioctls */
140 #define DVD_READ_STRUCT         0x5390  /* Read structure */
141 #define DVD_WRITE_STRUCT        0x5391  /* Write structure */
142 #define DVD_AUTH                0x5392  /* Authentication */
143
144 #define CDROM_SEND_PACKET       0x5393  /* send a packet to the drive */
145 #define CDROM_NEXT_WRITABLE     0x5394  /* get next writable block */
146 #define CDROM_LAST_WRITTEN      0x5395  /* get last block written on disc */
147
148 //jack add for test cdrom if ready
149 #define CDROM_TEST_READY    0x53ff  
150
151 /*******************************************************
152  * CDROM IOCTL structures
153  *******************************************************/
154
155 /* Address in MSF format */
156 struct cdrom_msf0               
157 {
158         __u8    minute;
159         __u8    second;
160         __u8    frame;
161 };
162
163 /* Address in either MSF or logical format */
164 union cdrom_addr                
165 {
166         struct cdrom_msf0       msf;
167         int                     lba;
168 };
169
170 /* This struct is used by the CDROMPLAYMSF ioctl */ 
171 struct cdrom_msf 
172 {
173         __u8    cdmsf_min0;     /* start minute */
174         __u8    cdmsf_sec0;     /* start second */
175         __u8    cdmsf_frame0;   /* start frame */
176         __u8    cdmsf_min1;     /* end minute */
177         __u8    cdmsf_sec1;     /* end second */
178         __u8    cdmsf_frame1;   /* end frame */
179 };
180
181 /* This struct is used by the CDROMPLAYTRKIND ioctl */
182 struct cdrom_ti 
183 {
184         __u8    cdti_trk0;      /* start track */
185         __u8    cdti_ind0;      /* start index */
186         __u8    cdti_trk1;      /* end track */
187         __u8    cdti_ind1;      /* end index */
188 };
189
190 /* This struct is used by the CDROMREADTOCHDR ioctl */
191 struct cdrom_tochdr     
192 {
193         __u8    cdth_trk0;      /* start track */
194         __u8    cdth_trk1;      /* end track */
195 };
196
197 /* This struct is used by the CDROMVOLCTRL and CDROMVOLREAD ioctls */
198 struct cdrom_volctrl
199 {
200         __u8    channel0;
201         __u8    channel1;
202         __u8    channel2;
203         __u8    channel3;
204 };
205
206 /* This struct is used by the CDROMSUBCHNL ioctl */
207 struct cdrom_subchnl 
208 {
209         __u8    cdsc_format;
210         __u8    cdsc_audiostatus;
211         __u8    cdsc_adr:       4;
212         __u8    cdsc_ctrl:      4;
213         __u8    cdsc_trk;
214         __u8    cdsc_ind;
215         union cdrom_addr cdsc_absaddr;
216         union cdrom_addr cdsc_reladdr;
217 };
218
219
220 /* This struct is used by the CDROMREADTOCENTRY ioctl */
221 struct cdrom_tocentry 
222 {
223         __u8    cdte_track;
224         __u8    cdte_adr        :4;
225         __u8    cdte_ctrl       :4;
226         __u8    cdte_format;
227         union cdrom_addr cdte_addr;
228         __u8    cdte_datamode;
229 };
230
231 /* This struct is used by the CDROMREADMODE1, and CDROMREADMODE2 ioctls */
232 struct cdrom_read      
233 {
234         int     cdread_lba;
235         char    *cdread_bufaddr;
236         int     cdread_buflen;
237 };
238
239 /* This struct is used by the CDROMREADAUDIO ioctl */
240 struct cdrom_read_audio
241 {
242         union cdrom_addr addr; /* frame address */
243         __u8 addr_format;    /* CDROM_LBA or CDROM_MSF */
244         int nframes;           /* number of 2352-byte-frames to read at once */
245         __u8 *buf;           /* frame buffer (size: nframes*2352 bytes) */
246 };
247
248 /* This struct is used with the CDROMMULTISESSION ioctl */
249 struct cdrom_multisession
250 {
251         union cdrom_addr addr; /* frame address: start-of-last-session 
252                                    (not the new "frame 16"!).  Only valid
253                                    if the "xa_flag" is true. */
254         __u8 xa_flag;        /* 1: "is XA disk" */
255         __u8 addr_format;    /* CDROM_LBA or CDROM_MSF */
256 };
257
258 /* This struct is used with the CDROM_GET_MCN ioctl.  
259  * Very few audio discs actually have Universal Product Code information, 
260  * which should just be the Medium Catalog Number on the box.  Also note 
261  * that the way the codeis written on CD is _not_ uniform across all discs!
262  */  
263 struct cdrom_mcn 
264 {
265   __u8 medium_catalog_number[14]; /* 13 ASCII digits, null-terminated */
266 };
267
268 /* This is used by the CDROMPLAYBLK ioctl */
269 struct cdrom_blk 
270 {
271         unsigned from;
272         unsigned short len;
273 };
274
275 #define CDROM_PACKET_SIZE       12
276
277 #define CGC_DATA_UNKNOWN        0
278 #define CGC_DATA_WRITE          1
279 #define CGC_DATA_READ           2
280 #define CGC_DATA_NONE           3
281
282 /* for CDROM_PACKET_COMMAND ioctl */
283 struct cdrom_generic_command
284 {
285         unsigned char           cmd[CDROM_PACKET_SIZE];
286         unsigned char           *buffer;
287         unsigned int            buflen;
288         int                     stat;
289         struct request_sense    *sense;
290         unsigned char           data_direction;
291         int                     quiet;
292         int                     timeout;
293         void                    *reserved[1];
294 };
295
296
297 /*
298  * A CD-ROM physical sector size is 2048, 2052, 2056, 2324, 2332, 2336, 
299  * 2340, or 2352 bytes long.  
300
301 *         Sector types of the standard CD-ROM data formats:
302  *
303  * format   sector type               user data size (bytes)
304  * -----------------------------------------------------------------------------
305  *   1     (Red Book)    CD-DA          2352    (CD_FRAMESIZE_RAW)
306  *   2     (Yellow Book) Mode1 Form1    2048    (CD_FRAMESIZE)
307  *   3     (Yellow Book) Mode1 Form2    2336    (CD_FRAMESIZE_RAW0)
308  *   4     (Green Book)  Mode2 Form1    2048    (CD_FRAMESIZE)
309  *   5     (Green Book)  Mode2 Form2    2328    (2324+4 spare bytes)
310  *
311  *
312  *       The layout of the standard CD-ROM data formats:
313  * -----------------------------------------------------------------------------
314  * - audio (red):                  | audio_sample_bytes |
315  *                                 |        2352        |
316  *
317  * - data (yellow, mode1):         | sync - head - data - EDC - zero - ECC |
318  *                                 |  12  -   4  - 2048 -  4  -   8  - 276 |
319  *
320  * - data (yellow, mode2):         | sync - head - data |
321  *                                 |  12  -   4  - 2336 |
322  *
323  * - XA data (green, mode2 form1): | sync - head - sub - data - EDC - ECC |
324  *                                 |  12  -   4  -  8  - 2048 -  4  - 276 |
325  *
326  * - XA data (green, mode2 form2): | sync - head - sub - data - Spare |
327  *                                 |  12  -   4  -  8  - 2324 -  4    |
328  *
329  */
330
331 /* Some generally useful CD-ROM information -- mostly based on the above */
332 #define CD_MINS              74 /* max. minutes per CD, not really a limit */
333 #define CD_SECS              60 /* seconds per minute */
334 #define CD_FRAMES            75 /* frames per second */
335 #define CD_SYNC_SIZE         12 /* 12 sync bytes per raw data frame */
336 #define CD_MSF_OFFSET       150 /* MSF numbering offset of first frame */
337 #define CD_CHUNK_SIZE        24 /* lowest-level "data bytes piece" */
338 #define CD_NUM_OF_CHUNKS     98 /* chunks per frame */
339 #define CD_FRAMESIZE_SUB     96 /* subchannel data "frame" size */
340 #define CD_HEAD_SIZE          4 /* header (address) bytes per raw data frame */
341 #define CD_SUBHEAD_SIZE       8 /* subheader bytes per raw XA data frame */
342 #define CD_EDC_SIZE           4 /* bytes EDC per most raw data frame types */
343 #define CD_ZERO_SIZE          8 /* bytes zero per yellow book mode 1 frame */
344 #define CD_ECC_SIZE         276 /* bytes ECC per most raw data frame types */
345 #define CD_FRAMESIZE       2048 /* bytes per frame, "cooked" mode */
346 #define CD_FRAMESIZE_RAW   2352 /* bytes per frame, "raw" mode */
347 #define CD_FRAMESIZE_RAWER 2646 /* The maximum possible returned bytes */ 
348 /* most drives don't deliver everything: */
349 #define CD_FRAMESIZE_RAW1 (CD_FRAMESIZE_RAW-CD_SYNC_SIZE) /*2340*/
350 #define CD_FRAMESIZE_RAW0 (CD_FRAMESIZE_RAW-CD_SYNC_SIZE-CD_HEAD_SIZE) /*2336*/
351
352 #define CD_XA_HEAD        (CD_HEAD_SIZE+CD_SUBHEAD_SIZE) /* "before data" part of raw XA frame */
353 #define CD_XA_TAIL        (CD_EDC_SIZE+CD_ECC_SIZE) /* "after data" part of raw XA frame */
354 #define CD_XA_SYNC_HEAD   (CD_SYNC_SIZE+CD_XA_HEAD) /* sync bytes + header of XA frame */
355
356 /* CD-ROM address types (cdrom_tocentry.cdte_format) */
357 #define CDROM_LBA 0x01 /* "logical block": first frame is #0 */
358 #define CDROM_MSF 0x02 /* "minute-second-frame": binary, not bcd here! */
359
360 /* bit to tell whether track is data or audio (cdrom_tocentry.cdte_ctrl) */
361 #define CDROM_DATA_TRACK        0x04
362
363 /* The leadout track is always 0xAA, regardless of # of tracks on disc */
364 #define CDROM_LEADOUT           0xAA
365
366 /* audio states (from SCSI-2, but seen with other drives, too) */
367 #define CDROM_AUDIO_INVALID     0x00    /* audio status not supported */
368 #define CDROM_AUDIO_PLAY        0x11    /* audio play operation in progress */
369 #define CDROM_AUDIO_PAUSED      0x12    /* audio play operation paused */
370 #define CDROM_AUDIO_COMPLETED   0x13    /* audio play successfully completed */
371 #define CDROM_AUDIO_ERROR       0x14    /* audio play stopped due to error */
372 #define CDROM_AUDIO_NO_STATUS   0x15    /* no current audio status to return */
373
374 /* capability flags used with the uniform CD-ROM driver */ 
375 #define CDC_CLOSE_TRAY          0x1     /* caddy systems _can't_ close */
376 #define CDC_OPEN_TRAY           0x2     /* but _can_ eject.  */
377 #define CDC_LOCK                0x4     /* disable manual eject */
378 #define CDC_SELECT_SPEED        0x8     /* programmable speed */
379 #define CDC_SELECT_DISC         0x10    /* select disc from juke-box */
380 #define CDC_MULTI_SESSION       0x20    /* read sessions>1 */
381 #define CDC_MCN                 0x40    /* Medium Catalog Number */
382 #define CDC_MEDIA_CHANGED       0x80    /* media changed */
383 #define CDC_PLAY_AUDIO          0x100   /* audio functions */
384 #define CDC_RESET               0x200   /* hard reset device */
385 #define CDC_IOCTLS              0x400   /* driver has non-standard ioctls */
386 #define CDC_DRIVE_STATUS        0x800   /* driver implements drive status */
387 #define CDC_GENERIC_PACKET      0x1000  /* driver implements generic packets */
388 #define CDC_CD_R                0x2000  /* drive is a CD-R */
389 #define CDC_CD_RW               0x4000  /* drive is a CD-RW */
390 #define CDC_DVD                 0x8000  /* drive is a DVD */
391 #define CDC_DVD_R               0x10000 /* drive can write DVD-R */
392 #define CDC_DVD_RAM             0x20000 /* drive can write DVD-RAM */
393
394 /* drive status possibilities returned by CDROM_DRIVE_STATUS ioctl */
395 #define CDS_NO_INFO             0       /* if not implemented */
396 #define CDS_NO_DISC             1
397 #define CDS_TRAY_OPEN           2
398 #define CDS_DRIVE_NOT_READY     3
399 #define CDS_DISC_OK             4
400
401 /* return values for the CDROM_DISC_STATUS ioctl */
402 /* can also return CDS_NO_[INFO|DISC], from above */
403 #define CDS_AUDIO               100
404 #define CDS_DATA_1              101
405 #define CDS_DATA_2              102
406 #define CDS_XA_2_1              103
407 #define CDS_XA_2_2              104
408 #define CDS_MIXED               105
409
410 /* User-configurable behavior options for the uniform CD-ROM driver */
411 #define CDO_AUTO_CLOSE          0x1     /* close tray on first open() */
412 #define CDO_AUTO_EJECT          0x2     /* open tray on last release() */
413 #define CDO_USE_FFLAGS          0x4     /* use O_NONBLOCK information on open */
414 #define CDO_LOCK                0x8     /* lock tray on open files */
415 #define CDO_CHECK_TYPE          0x10    /* check type on open for data */
416
417 /* Special codes used when specifying changer slots. */
418 #define CDSL_NONE               ((int) (~0U>>1)-1)
419 #define CDSL_CURRENT            ((int) (~0U>>1))
420
421 /* For partition based multisession access. IDE can handle 64 partitions
422  * per drive - SCSI CD-ROM's use minors to differentiate between the
423  * various drives, so we can't do multisessions the same way there.
424  * Use the -o session=x option to mount on them.
425  */
426 #define CD_PART_MAX             64
427 #define CD_PART_MASK            (CD_PART_MAX - 1)
428
429 /*********************************************************************
430  * Generic Packet commands, MMC commands, and such
431  *********************************************************************/
432
433  /* The generic packet command opcodes for CD/DVD Logical Units,
434  * From Table 57 of the SFF8090 Ver. 3 (Mt. Fuji) draft standard. */
435 #define GPCMD_BLANK                         0xa1
436 #define GPCMD_CLOSE_TRACK                   0x5b
437 #define GPCMD_FLUSH_CACHE                   0x35
438 #define GPCMD_FORMAT_UNIT                   0x04
439 #define GPCMD_GET_CONFIGURATION             0x46
440 #define GPCMD_GET_EVENT_STATUS_NOTIFICATION 0x4a
441 #define GPCMD_GET_PERFORMANCE               0xac
442 #define GPCMD_INQUIRY                       0x12
443 #define GPCMD_LOAD_UNLOAD                   0xa6
444 #define GPCMD_MECHANISM_STATUS              0xbd
445 #define GPCMD_MODE_SELECT_10                0x55
446 #define GPCMD_MODE_SENSE_10                 0x5a
447 #define GPCMD_PAUSE_RESUME                  0x4b
448 #define GPCMD_PLAY_AUDIO_10                 0x45
449 #define GPCMD_PLAY_AUDIO_MSF                0x47
450 #define GPCMD_PLAY_AUDIO_TI                 0x48
451 #define GPCMD_PLAY_CD                       0xbc
452 #define GPCMD_PREVENT_ALLOW_MEDIUM_REMOVAL  0x1e
453 #define GPCMD_READ_10                       0x28
454 #define GPCMD_READ_12                       0xa8
455 #define GPCMD_READ_CDVD_CAPACITY            0x25
456 #define GPCMD_READ_CD                       0xbe
457 #define GPCMD_READ_CD_MSF                   0xb9
458 #define GPCMD_READ_DISC_INFO                0x51
459 #define GPCMD_READ_DVD_STRUCTURE            0xad
460 #define GPCMD_READ_FORMAT_CAPACITIES        0x23
461 #define GPCMD_READ_HEADER                   0x44
462 #define GPCMD_READ_TRACK_RZONE_INFO         0x52
463 #define GPCMD_READ_SUBCHANNEL               0x42
464 #define GPCMD_READ_TOC_PMA_ATIP             0x43
465 #define GPCMD_REPAIR_RZONE_TRACK            0x58
466 #define GPCMD_REPORT_KEY                    0xa4
467 #define GPCMD_REQUEST_SENSE                 0x03
468 #define GPCMD_RESERVE_RZONE_TRACK           0x53
469 #define GPCMD_SCAN                          0xba
470 #define GPCMD_SEEK                          0x2b
471 #define GPCMD_SEND_DVD_STRUCTURE            0xad
472 #define GPCMD_SEND_EVENT                    0xa2
473 #define GPCMD_SEND_KEY                      0xa3
474 #define GPCMD_SEND_OPC                      0x54
475 #define GPCMD_SET_READ_AHEAD                0xa7
476 #define GPCMD_SET_STREAMING                 0xb6
477 #define GPCMD_START_STOP_UNIT               0x1b
478 #define GPCMD_STOP_PLAY_SCAN                0x4e
479 #define GPCMD_TEST_UNIT_READY               0x00
480 #define GPCMD_VERIFY_10                     0x2f
481 #define GPCMD_WRITE_10                      0x2a
482 #define GPCMD_WRITE_AND_VERIFY_10           0x2e
483 /* This is listed as optional in ATAPI 2.6, but is (curiously) 
484  * missing from Mt. Fuji, Table 57.  It _is_ mentioned in Mt. Fuji
485  * Table 377 as an MMC command for SCSi devices though...  Most ATAPI
486  * drives support it. */
487 #define GPCMD_SET_SPEED                     0xbb
488 /* This seems to be a SCSI specific CD-ROM opcode 
489  * to play data at track/index */
490 #define GPCMD_PLAYAUDIO_TI                  0x48
491 /*
492  * From MS Media Status Notification Support Specification. For
493  * older drives only.
494  */
495 #define GPCMD_GET_MEDIA_STATUS              0xda
496
497 /* Mode page codes for mode sense/set */
498 #define GPMODE_R_W_ERROR_PAGE           0x01
499 #define GPMODE_WRITE_PARMS_PAGE         0x05
500 #define GPMODE_AUDIO_CTL_PAGE           0x0e
501 #define GPMODE_POWER_PAGE               0x1a
502 #define GPMODE_FAULT_FAIL_PAGE          0x1c
503 #define GPMODE_TO_PROTECT_PAGE          0x1d
504 #define GPMODE_CAPABILITIES_PAGE        0x2a
505 #define GPMODE_ALL_PAGES                0x3f
506 /* Not in Mt. Fuji, but in ATAPI 2.6 -- depricated now in favor
507  * of MODE_SENSE_POWER_PAGE */
508 #define GPMODE_CDROM_PAGE               0x0d
509
510
511
512 /* DVD struct types */
513 #define DVD_STRUCT_PHYSICAL     0x00
514 #define DVD_STRUCT_COPYRIGHT    0x01
515 #define DVD_STRUCT_DISCKEY      0x02
516 #define DVD_STRUCT_BCA          0x03
517 #define DVD_STRUCT_MANUFACT     0x04
518
519 struct dvd_layer {
520         __u8 book_version       : 4;
521         __u8 book_type          : 4;
522         __u8 min_rate           : 4;
523         __u8 disc_size          : 4;
524         __u8 layer_type         : 4;
525         __u8 track_path         : 1;
526         __u8 nlayers            : 2;
527         __u8 track_density      : 4;
528         __u8 linear_density     : 4;
529         __u8 bca                : 1;
530         __u32 start_sector;
531         __u32 end_sector;
532         __u32 end_sector_l0;
533 };
534
535 #define DVD_LAYERS      4
536
537 struct dvd_physical {
538         __u8 type;
539         __u8 layer_num;
540         struct dvd_layer layer[DVD_LAYERS];
541 };
542
543 struct dvd_copyright {
544         __u8 type;
545
546         __u8 layer_num;
547         __u8 cpst;
548         __u8 rmi;
549 };
550
551 struct dvd_disckey {
552         __u8 type;
553
554         unsigned agid           : 2;
555         __u8 value[2048];
556 };
557
558 struct dvd_bca {
559         __u8 type;
560
561         int len;
562         __u8 value[188];
563 };
564
565 struct dvd_manufact {
566         __u8 type;
567
568         __u8 layer_num;
569         int len;
570         __u8 value[2048];
571 };
572
573 typedef union {
574         __u8 type;
575
576         struct dvd_physical     physical;
577         struct dvd_copyright    copyright;
578         struct dvd_disckey      disckey;
579         struct dvd_bca          bca;
580         struct dvd_manufact     manufact;
581 } dvd_struct;
582
583 /*
584  * DVD authentication ioctl
585  */
586
587 /* Authentication states */
588 #define DVD_LU_SEND_AGID        0
589 #define DVD_HOST_SEND_CHALLENGE 1
590 #define DVD_LU_SEND_KEY1        2
591 #define DVD_LU_SEND_CHALLENGE   3
592 #define DVD_HOST_SEND_KEY2      4
593
594 /* Termination states */
595 #define DVD_AUTH_ESTABLISHED    5
596 #define DVD_AUTH_FAILURE        6
597
598 /* Other functions */
599 #define DVD_LU_SEND_TITLE_KEY   7
600 #define DVD_LU_SEND_ASF         8
601 #define DVD_INVALIDATE_AGID     9
602 #define DVD_LU_SEND_RPC_STATE   10
603 #define DVD_HOST_SEND_RPC_STATE 11
604
605 /* State data */
606 typedef __u8 dvd_key[5];                /* 40-bit value, MSB is first elem. */
607 typedef __u8 dvd_challenge[10]; /* 80-bit value, MSB is first elem. */
608
609 struct dvd_lu_send_agid {
610         __u8 type;
611         unsigned agid           : 2;
612 };
613
614 struct dvd_host_send_challenge {
615         __u8 type;
616         unsigned agid           : 2;
617
618         dvd_challenge chal;
619 };
620
621 struct dvd_send_key {
622         __u8 type;
623         unsigned agid           : 2;
624
625         dvd_key key;
626 };
627
628 struct dvd_lu_send_challenge {
629         __u8 type;
630         unsigned agid           : 2;
631
632         dvd_challenge chal;
633 };
634
635 #define DVD_CPM_NO_COPYRIGHT    0
636 #define DVD_CPM_COPYRIGHTED     1
637
638 #define DVD_CP_SEC_NONE         0
639 #define DVD_CP_SEC_EXIST        1
640
641 #define DVD_CGMS_UNRESTRICTED   0
642 #define DVD_CGMS_SINGLE         2
643 #define DVD_CGMS_RESTRICTED     3
644
645 struct dvd_lu_send_title_key {
646         __u8 type;
647         unsigned agid           : 2;
648
649         dvd_key title_key;
650         int lba;
651         unsigned cpm            : 1;
652         unsigned cp_sec         : 1;
653         unsigned cgms           : 2;
654 };
655
656 struct dvd_lu_send_asf {
657         __u8 type;
658         unsigned agid           : 2;
659
660         unsigned asf            : 1;
661 };
662
663 struct dvd_host_send_rpcstate {
664         __u8 type;
665         __u8 pdrc;
666 };
667
668 struct dvd_lu_send_rpcstate {
669         __u8 type               : 2;
670         __u8 vra                : 3;
671         __u8 ucca               : 3;
672         __u8 region_mask;
673         __u8 rpc_scheme;
674 };
675
676 typedef union {
677         __u8 type;
678
679         struct dvd_lu_send_agid         lsa;
680         struct dvd_host_send_challenge  hsc;
681         struct dvd_send_key             lsk;
682         struct dvd_lu_send_challenge    lsc;
683         struct dvd_send_key             hsk;
684         struct dvd_lu_send_title_key    lstk;
685         struct dvd_lu_send_asf          lsasf;
686         struct dvd_host_send_rpcstate   hrpcs;
687         struct dvd_lu_send_rpcstate     lrpcs;
688 } dvd_authinfo;
689
690 struct request_sense {
691 #if defined(__BIG_ENDIAN_BITFIELD)
692         __u8 valid              : 1;
693         __u8 error_code         : 7;
694 #elif defined(__LITTLE_ENDIAN_BITFIELD)
695         __u8 error_code         : 7;
696         __u8 valid              : 1;
697 #endif
698         __u8 segment_number;
699 #if defined(__BIG_ENDIAN_BITFIELD)
700         __u8 reserved1          : 2;
701         __u8 ili                : 1;
702         __u8 reserved2          : 1;
703         __u8 sense_key          : 4;
704 #elif defined(__LITTLE_ENDIAN_BITFIELD)
705         __u8 sense_key          : 4;
706         __u8 reserved2          : 1;
707         __u8 ili                : 1;
708         __u8 reserved1          : 2;
709 #endif
710         __u8 information[4];
711         __u8 add_sense_len;
712         __u8 command_info[4];
713         __u8 asc;
714         __u8 ascq;
715         __u8 fruc;
716         __u8 sks[3];
717         __u8 asb[46];
718 };
719
720 #ifdef __KERNEL__
721 #include <linux/devfs_fs_kernel.h>
722
723 struct cdrom_write_settings {
724         unsigned char fpacket;          /* fixed/variable packets */
725         unsigned long packet_size;      /* write out this number of packets */
726         unsigned long nwa;              /* next writeable address */
727         unsigned char writeable;        /* cdrom is writeable */
728 };
729
730 /* Uniform cdrom data structures for cdrom.c */
731 struct cdrom_device_info {
732         struct cdrom_device_ops  *ops;  /* link to device_ops */
733         struct cdrom_device_info *next; /* next device_info for this major */
734         void *handle;                   /* driver-dependent data */
735         devfs_handle_t de;              /* real driver should create this  */
736         int number;                     /* generic driver updates this  */
737 /* specifications */
738         kdev_t dev;                     /* device number */
739         int mask;                       /* mask of capability: disables them */
740         int speed;                      /* maximum speed for reading data */
741         int capacity;                   /* number of discs in jukebox */
742 /* device-related storage */
743         int options             : 30;   /* options flags */
744         unsigned mc_flags       : 2;    /* media change buffer flags */
745         int use_count;                  /* number of times device opened */
746         char name[20];                  /* name of the device type */
747 /* per-device flags */
748         __u8 sanyo_slot         : 2;    /* Sanyo 3 CD changer support */
749         __u8 reserved           : 6;    /* not used yet */
750         struct cdrom_write_settings write;
751 };
752
753 struct cdrom_device_ops {
754 /* routines */
755         int (*open) (struct cdrom_device_info *, int);
756         void (*release) (struct cdrom_device_info *);
757         int (*drive_status) (struct cdrom_device_info *, int);
758         int (*media_changed) (struct cdrom_device_info *, int);
759         int (*tray_move) (struct cdrom_device_info *, int);
760         int (*lock_door) (struct cdrom_device_info *, int);
761         int (*select_speed) (struct cdrom_device_info *, int);
762         int (*select_disc) (struct cdrom_device_info *, int);
763         int (*get_last_session) (struct cdrom_device_info *,
764                                  struct cdrom_multisession *);
765         int (*get_mcn) (struct cdrom_device_info *,
766                         struct cdrom_mcn *);
767         /* hard reset device */
768         int (*reset) (struct cdrom_device_info *);
769         /* play stuff */
770         int (*audio_ioctl) (struct cdrom_device_info *,unsigned int, void *);
771         /* dev-specific */
772         int (*dev_ioctl) (struct cdrom_device_info *,
773                           unsigned int, unsigned long);
774 /* driver specifications */
775         const int capability;   /* capability flags */
776         int n_minors;           /* number of active minor devices */
777         /* handle uniform packets for scsi type devices (scsi,atapi) */
778         int (*generic_packet) (struct cdrom_device_info *,
779                                struct cdrom_generic_command *);
780 };
781
782 /* the general block_device operations structure: */
783 extern int cdrom_open(struct inode *, struct file *);
784 extern int cdrom_release(struct inode *, struct file *);
785 extern int cdrom_ioctl(struct inode *, struct file *, unsigned, unsigned long);
786 extern int cdrom_media_changed(kdev_t);
787
788 extern int register_cdrom(struct cdrom_device_info *cdi);
789 extern int unregister_cdrom(struct cdrom_device_info *cdi);
790
791 static inline void devfs_plain_cdrom(struct cdrom_device_info *cdi,
792                                 struct block_device_operations *ops)
793 {
794         char vname[23];
795
796         sprintf (vname, "cdroms/cdrom%d", cdi->number);
797         cdi->de = devfs_register (NULL, vname, DEVFS_FL_DEFAULT,
798                                     MAJOR (cdi->dev), MINOR (cdi->dev),
799                                     S_IFBLK | S_IRUGO | S_IWUGO,
800                                     ops, NULL);
801 }
802
803 typedef struct {
804     int data;
805     int audio;
806     int cdi;
807     int xa;
808     long error;
809 } tracktype;
810
811 extern void cdrom_count_tracks(struct cdrom_device_info *cdi,tracktype* tracks);
812 extern int cdrom_get_next_writable(kdev_t dev, long *next_writable);
813 extern int cdrom_get_last_written(kdev_t dev, long *last_written);
814 extern int cdrom_number_of_slots(struct cdrom_device_info *cdi);
815 extern int cdrom_select_disc(struct cdrom_device_info *cdi, int slot);
816 extern int cdrom_mode_select(struct cdrom_device_info *cdi,
817                              struct cdrom_generic_command *cgc);
818 extern int cdrom_mode_sense(struct cdrom_device_info *cdi,
819                             struct cdrom_generic_command *cgc,
820                             int page_code, int page_control);
821 extern void init_cdrom_command(struct cdrom_generic_command *cgc,
822                                void *buffer, int len, int type);
823 extern struct cdrom_device_info *cdrom_find_device(kdev_t dev);
824
825 typedef struct {
826         __u16 disc_information_length;
827 #if defined(__BIG_ENDIAN_BITFIELD)
828         __u8 reserved1                  : 3;
829         __u8 erasable                   : 1;
830         __u8 border_status              : 2;
831         __u8 disc_status                : 2;
832 #elif defined(__LITTLE_ENDIAN_BITFIELD)
833         __u8 disc_status                : 2;
834         __u8 border_status              : 2;
835         __u8 erasable                   : 1;
836         __u8 reserved1                  : 3;
837 #else
838 #error "Please fix <asm/byteorder.h>"
839 #endif
840         __u8 n_first_track;
841         __u8 n_sessions_lsb;
842         __u8 first_track_lsb;
843         __u8 last_track_lsb;
844 #if defined(__BIG_ENDIAN_BITFIELD)
845         __u8 did_v                      : 1;
846         __u8 dbc_v                      : 1;
847         __u8 uru                        : 1;
848         __u8 reserved2                  : 5;
849 #elif defined(__LITTLE_ENDIAN_BITFIELD)
850         __u8 reserved2                  : 5;
851         __u8 uru                        : 1;
852         __u8 dbc_v                      : 1;
853         __u8 did_v                      : 1;
854 #endif
855         __u8 disc_type;
856         __u8 n_sessions_msb;
857         __u8 first_track_msb;
858         __u8 last_track_msb;
859         __u32 disc_id;
860         __u32 lead_in;
861         __u32 lead_out;
862         __u8 disc_bar_code[8];
863         __u8 reserved3;
864         __u8 n_opc;
865 } disc_information;
866
867 typedef struct {
868         __u16 track_information_length;
869         __u8 track_lsb;
870         __u8 session_lsb;
871         __u8 reserved1;
872 #if defined(__BIG_ENDIAN_BITFIELD)
873         __u8 reserved2                  : 2;
874         __u8 damage                     : 1;
875         __u8 copy                       : 1;
876         __u8 track_mode                 : 4;
877         __u8 rt                         : 1;
878         __u8 blank                      : 1;
879         __u8 packet                     : 1;
880         __u8 fp                         : 1;
881         __u8 data_mode                  : 4;
882         __u8 reserved3                  : 6;
883         __u8 lra_v                      : 1;
884         __u8 nwa_v                      : 1;
885 #elif defined(__LITTLE_ENDIAN_BITFIELD)
886         __u8 track_mode                 : 4;
887         __u8 copy                       : 1;
888         __u8 damage                     : 1;
889         __u8 reserved2                  : 2;
890         __u8 data_mode                  : 4;
891         __u8 fp                         : 1;
892         __u8 packet                     : 1;
893         __u8 blank                      : 1;
894         __u8 rt                         : 1;
895         __u8 nwa_v                      : 1;
896         __u8 lra_v                      : 1;
897         __u8 reserved3                  : 6;
898 #endif
899         __u32 track_start;
900         __u32 next_writable;
901         __u32 free_blocks;
902         __u32 fixed_packet_size;
903         __u32 track_size;
904         __u32 last_rec_address;
905 } track_information;
906
907 extern int cdrom_get_disc_info(kdev_t dev, disc_information *di);
908 extern int cdrom_get_track_info(kdev_t dev, __u16 track, __u8 type,
909                                 track_information *ti);
910
911 /* The SCSI spec says there could be 256 slots. */
912 #define CDROM_MAX_SLOTS 256
913
914 struct cdrom_mechstat_header {
915 #if defined(__BIG_ENDIAN_BITFIELD)
916         __u8 fault         : 1;
917         __u8 changer_state : 2;
918         __u8 curslot       : 5;
919         __u8 mech_state    : 3;
920         __u8 door_open     : 1;
921         __u8 reserved1     : 4;
922 #elif defined(__LITTLE_ENDIAN_BITFIELD)
923         __u8 curslot       : 5;
924         __u8 changer_state : 2;
925         __u8 fault         : 1;
926         __u8 reserved1     : 4;
927         __u8 door_open     : 1;
928         __u8 mech_state    : 3;
929 #endif
930         __u8     curlba[3];
931         __u8     nslots;
932         __u16 slot_tablelen;
933 };
934
935 struct cdrom_slot {
936 #if defined(__BIG_ENDIAN_BITFIELD)
937         __u8 disc_present : 1;
938         __u8 reserved1    : 6;
939         __u8 change       : 1;
940 #elif defined(__LITTLE_ENDIAN_BITFIELD)
941         __u8 change       : 1;
942         __u8 reserved1    : 6;
943         __u8 disc_present : 1;
944 #endif
945         __u8 reserved2[3];
946 };
947
948 struct cdrom_changer_info {
949         struct cdrom_mechstat_header hdr;
950         struct cdrom_slot slots[CDROM_MAX_SLOTS];
951 };
952
953 typedef enum {
954         mechtype_caddy = 0,
955         mechtype_tray  = 1,
956         mechtype_popup = 2,
957         mechtype_individual_changer = 4,
958         mechtype_cartridge_changer  = 5
959 } mechtype_t;
960
961 struct mode_page_header {
962         __u16 mode_data_length;
963         __u8 medium_type;
964         __u8 reserved1;
965         __u8 reserved2;
966         __u8 reserved3;
967         __u16 desc_length;
968 };
969
970 typedef struct {
971 #if defined(__BIG_ENDIAN_BITFIELD)
972         __u8 ps                 : 1;
973         __u8 reserved1          : 1;
974         __u8 page_code          : 6;
975         __u8 page_length;
976         __u8 reserved2          : 1;
977         __u8 bufe               : 1;
978         __u8 ls_v               : 1;
979         __u8 test_write         : 1;
980         __u8 write_type         : 4;
981         __u8 multi_session      : 2; /* or border, DVD */
982         __u8 fp                 : 1;
983         __u8 copy               : 1;
984         __u8 track_mode         : 4;
985         __u8 reserved3          : 4;
986         __u8 data_block_type    : 4;
987 #elif defined(__LITTLE_ENDIAN_BITFIELD)
988         __u8 page_code          : 6;
989         __u8 reserved1          : 1;
990         __u8 ps                 : 1;
991         __u8 page_length;
992         __u8 write_type         : 4;
993         __u8 test_write         : 1;
994         __u8 ls_v               : 1;
995         __u8 bufe               : 1;
996         __u8 reserved2          : 1;
997         __u8 track_mode         : 4;
998         __u8 copy               : 1;
999         __u8 fp                 : 1;
1000         __u8 multi_session      : 2; /* or border, DVD */
1001         __u8 data_block_type    : 4;
1002         __u8 reserved3          : 4;
1003 #endif
1004         __u8 link_size;
1005         __u8 reserved4;
1006 #if defined(__BIG_ENDIAN_BITFIELD)
1007         __u8 reserved5          : 2;
1008         __u8 app_code           : 6;
1009 #elif defined(__LITTLE_ENDIAN_BITFIELD)
1010         __u8 app_code           : 6;
1011         __u8 reserved5          : 2;
1012 #endif
1013         __u8 session_format;
1014         __u8 reserved6;
1015         __u32 packet_size;
1016         __u16 audio_pause;
1017         __u8 mcn[16];
1018         __u8 isrc[16];
1019         __u8 subhdr0;
1020         __u8 subhdr1;
1021         __u8 subhdr2;
1022         __u8 subhdr3;
1023 } __attribute__((packed)) write_param_page;
1024
1025 struct modesel_head
1026 {
1027         __u8    reserved1;
1028         __u8    medium;
1029         __u8    reserved2;
1030         __u8    block_desc_length;
1031         __u8    density;
1032         __u8    number_of_blocks_hi;
1033         __u8    number_of_blocks_med;
1034         __u8    number_of_blocks_lo;
1035         __u8    reserved3;
1036         __u8    block_length_hi;
1037         __u8    block_length_med;
1038         __u8    block_length_lo;
1039 };
1040
1041 typedef struct {
1042         __u16 report_key_length;
1043         __u8 reserved1;
1044         __u8 reserved2;
1045 #if defined(__BIG_ENDIAN_BITFIELD)
1046         __u8 type_code                  : 2;
1047         __u8 vra                        : 3;
1048         __u8 ucca                       : 3;
1049 #elif defined(__LITTLE_ENDIAN_BITFIELD)
1050         __u8 ucca                       : 3;
1051         __u8 vra                        : 3;
1052         __u8 type_code                  : 2;
1053 #endif
1054         __u8 region_mask;
1055         __u8 rpc_scheme;
1056         __u8 reserved3;
1057 } rpc_state_t;
1058
1059 #endif  /* End of kernel only stuff */ 
1060
1061 #endif  /* _LINUX_CDROM_H */