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