1 /*        $NetBSD: cdio.h,v 1.34 2015/09/06 06:01:02 dholland Exp $   */
2 
3 #ifndef _SYS_CDIO_H_
4 #define _SYS_CDIO_H_
5 
6 #include <sys/ioccom.h>
7 
8 /* Shared between kernel & process */
9 
10 union msf_lba {
11           struct {
12                     u_char unused;
13                     u_char minute;
14                     u_char second;
15                     u_char frame;
16           } msf;
17           uint32_t lba;
18           u_char    addr[4];
19 };
20 
21 struct cd_toc_entry {
22           u_char              nothing1;
23 #if BYTE_ORDER == LITTLE_ENDIAN
24           uint32_t  control:4;
25           uint32_t  addr_type:4;
26 #endif
27 #if BYTE_ORDER == BIG_ENDIAN
28           uint32_t  addr_type:4;
29           uint32_t  control:4;
30 #endif
31           u_char              track;
32           u_char              nothing2;
33           union msf_lba       addr;
34 };
35 
36 struct cd_sub_channel_header {
37           u_char    nothing1;
38           u_char    audio_status;
39 #define CD_AS_AUDIO_INVALID   0x00
40 #define CD_AS_PLAY_IN_PROGRESS          0x11
41 #define CD_AS_PLAY_PAUSED     0x12
42 #define CD_AS_PLAY_COMPLETED  0x13
43 #define CD_AS_PLAY_ERROR      0x14
44 #define CD_AS_NO_STATUS                 0x15
45           u_char    data_len[2];
46 };
47 
48 struct cd_sub_channel_q_data {
49           u_char              data_format;
50 #if BYTE_ORDER == LITTLE_ENDIAN
51           uint32_t  control:4;
52           uint32_t  addr_type:4;
53 #endif
54 #if BYTE_ORDER == BIG_ENDIAN
55           uint32_t  addr_type:4;
56           uint32_t  control:4;
57 #endif
58           u_char              track_number;
59           u_char              index_number;
60           u_char              absaddr[4];
61           u_char              reladdr[4];
62 #if BYTE_ORDER == LITTLE_ENDIAN
63         uint32_t    :7;
64         uint32_t    mc_valid:1;
65 #endif
66 #if BYTE_ORDER == BIG_ENDIAN
67         uint32_t    mc_valid:1;
68         uint32_t    :7;
69 #endif
70         u_char  mc_number[15];
71 #if BYTE_ORDER == LITTLE_ENDIAN
72         uint32_t    :7;
73         uint32_t    ti_valid:1;
74 #endif
75 #if BYTE_ORDER == BIG_ENDIAN
76         uint32_t    ti_valid:1;
77         uint32_t    :7;
78 #endif
79         u_char                ti_number[15];
80 };
81 
82 struct cd_sub_channel_position_data {
83           u_char              data_format;
84 #if BYTE_ORDER == LITTLE_ENDIAN
85           uint32_t  control:4;
86           uint32_t  addr_type:4;
87 #endif
88 #if BYTE_ORDER == BIG_ENDIAN
89           uint32_t  addr_type:4;
90           uint32_t  control:4;
91 #endif
92           u_char              track_number;
93           u_char              index_number;
94           union msf_lba       absaddr;
95           union msf_lba       reladdr;
96 };
97 
98 struct cd_sub_channel_media_catalog {
99           u_char              data_format;
100           u_char              nothing1;
101           u_char              nothing2;
102           u_char              nothing3;
103 #if BYTE_ORDER == LITTLE_ENDIAN
104           uint32_t  :7;
105           uint32_t  mc_valid:1;
106 #endif
107 #if BYTE_ORDER == BIG_ENDIAN
108           uint32_t  mc_valid:1;
109           uint32_t  :7;
110 #endif
111           u_char              mc_number[15];
112 };
113 
114 struct cd_sub_channel_track_info {
115           u_char              data_format;
116           u_char              nothing1;
117           u_char              track_number;
118           u_char              nothing2;
119 #if BYTE_ORDER == LITTLE_ENDIAN
120           uint32_t  :7;
121           uint32_t  ti_valid:1;
122 #endif
123 #if BYTE_ORDER == BIG_ENDIAN
124           uint32_t  ti_valid:1;
125           uint32_t  :7;
126 #endif
127           u_char              ti_number[15];
128 };
129 
130 struct cd_sub_channel_info {
131           struct cd_sub_channel_header header;
132           union {
133                     struct cd_sub_channel_q_data q_data;
134                     struct cd_sub_channel_position_data position;
135                     struct cd_sub_channel_media_catalog media_catalog;
136                     struct cd_sub_channel_track_info track_info;
137           } what;
138 };
139 
140 /*
141  * Ioctls for the CD drive
142  */
143 struct ioc_play_track {
144           u_char    start_track;
145           u_char    start_index;
146           u_char    end_track;
147           u_char    end_index;
148 };
149 
150 #define   CDIOCPLAYTRACKS     _IOW('c', 1, struct ioc_play_track)
151 struct ioc_play_blocks {
152           int       blk;
153           int       len;
154 };
155 #define   CDIOCPLAYBLOCKS     _IOW('c', 2, struct ioc_play_blocks)
156 
157 struct ioc_read_subchannel {
158           u_char    address_format;
159 #define CD_LBA_FORMAT                   1
160 #define CD_MSF_FORMAT                   2
161           u_char    data_format;
162 #define CD_SUBQ_DATA                    0
163 #define CD_CURRENT_POSITION   1
164 #define CD_MEDIA_CATALOG      2
165 #define CD_TRACK_INFO                   3
166           u_char    track;
167           int       data_len;
168           struct    cd_sub_channel_info *data;
169 };
170 #define CDIOCREADSUBCHANNEL _IOWR('c', 3, struct ioc_read_subchannel )
171 
172 #ifdef _KERNEL
173 /* As above, but with the buffer following the request for in-kernel users. */
174 struct ioc_read_subchannel_buf {
175           struct ioc_read_subchannel req;
176           struct cd_sub_channel_info info;
177 };
178 #define CDIOCREADSUBCHANNEL_BUF _IOWR('c', 3, struct ioc_read_subchannel_buf)
179 #endif
180 
181 struct ioc_toc_header {
182           u_short   len;
183           u_char    starting_track;
184           u_char    ending_track;
185 };
186 
187 #define CDIOREADTOCHEADER _IOR('c', 4, struct ioc_toc_header)
188 
189 struct ioc_read_toc_entry {
190           u_char    address_format;
191           u_char    starting_track;
192           u_short   data_len;
193           struct    cd_toc_entry *data;
194 };
195 #define CDIOREADTOCENTRIES _IOWR('c', 5, struct ioc_read_toc_entry)
196 #define CDIOREADTOCENTRYS CDIOREADTOCENTRIES
197 
198 #ifdef _KERNEL
199 /* As above, but with the buffer following the request for in-kernel users. */
200 struct ioc_read_toc_entry_buf {
201           struct ioc_read_toc_entry req;
202           struct cd_toc_entry       entry[100];   /* NB: 8 bytes each */
203 };
204 #define CDIOREADTOCENTRIES_BUF _IOWR('c', 5, struct ioc_read_toc_entry_buf)
205 #endif
206 
207 /* read LBA start of a given session; 0=last, others not yet supported */
208 #define CDIOREADMSADDR _IOWR('c', 6, int)
209 
210 struct    ioc_patch {
211           u_char    patch[4]; /* one for each channel */
212 };
213 #define   CDIOCSETPATCH       _IOW('c', 9, struct ioc_patch)
214 
215 struct    ioc_vol {
216           u_char    vol[4];   /* one for each channel */
217 };
218 #define   CDIOCGETVOL         _IOR('c', 10, struct ioc_vol)
219 #define   CDIOCSETVOL         _IOW('c', 11, struct ioc_vol)
220 #define   CDIOCSETMONO        _IO('c', 12)
221 #define   CDIOCSETSTEREO      _IO('c', 13)
222 #define   CDIOCSETMUTE        _IO('c', 14)
223 #define   CDIOCSETLEFT        _IO('c', 15)
224 #define   CDIOCSETRIGHT       _IO('c', 16)
225 #define   CDIOCSETDEBUG       _IO('c', 17)
226 #define   CDIOCCLRDEBUG       _IO('c', 18)
227 #define   CDIOCPAUSE          _IO('c', 19)
228 #define   CDIOCRESUME         _IO('c', 20)
229 #define   CDIOCRESET          _IO('c', 21)
230 #define   CDIOCSTART          _IO('c', 22)
231 #define   CDIOCSTOP _IO('c', 23)
232 #define   CDIOCEJECT          _IO('c', 24)
233 #define   CDIOCALLOW          _IO('c', 25)
234 #define   CDIOCPREVENT        _IO('c', 26)
235 #define   CDIOCCLOSE          _IO('c', 27)
236 
237 struct ioc_play_msf {
238           u_char    start_m;
239           u_char    start_s;
240           u_char    start_f;
241           u_char    end_m;
242           u_char    end_s;
243           u_char    end_f;
244 };
245 #define   CDIOCPLAYMSF        _IOW('c', 25, struct ioc_play_msf)
246 
247 struct ioc_load_unload {
248           u_char options;
249 #define   CD_LU_ABORT         0x1       /* NOTE: These are the same as the ATAPI */
250 #define   CD_LU_UNLOAD        0x2       /* op values for the LOAD_UNLOAD command */
251 #define   CD_LU_LOAD          0x3
252           u_char slot;
253 };
254 #define             CDIOCLOADUNLOAD     _IOW('c', 26, struct ioc_load_unload)
255 
256 
257 #if defined(_KERNEL) || defined(_EXPOSE_MMC)
258 /* not exposed to userland yet until its completely mature */
259 /*
260  * MMC device abstraction interface.
261  *
262  * It gathers information from GET_CONFIGURATION, READ_DISCINFO,
263  * READ_TRACKINFO, READ_TOC2, READ_CD_CAPACITY and GET_CONFIGURATION
264  * SCSI/ATAPI calls regardless if its a legacy CD-ROM/DVD-ROM device or a MMC
265  * standard recordable device.
266  */
267 struct mmc_discinfo {
268           uint16_t  mmc_profile;
269           uint16_t  mmc_class;
270 
271           uint8_t             disc_state;
272           uint8_t             last_session_state;
273           uint8_t             bg_format_state;
274           uint8_t             link_block_penalty; /* in sectors                    */
275 
276           uint64_t  mmc_cur;            /* current MMC_CAPs        */
277           uint64_t  mmc_cap;            /* possible MMC_CAPs       */
278 
279           uint32_t  disc_flags;                   /* misc flags              */
280 
281           uint32_t  disc_id;
282           uint64_t  disc_barcode;
283           uint8_t             application_code;   /* 8 bit really            */
284 
285           uint8_t             unused1[3];                   /* padding                 */
286 
287           uint32_t  last_possible_lba;  /* last leadout start adr. */
288           uint32_t  sector_size;
289 
290           uint16_t  num_sessions;
291           uint16_t  num_tracks;                   /* derived */
292 
293           uint16_t  first_track;
294           uint16_t  first_track_last_session;
295           uint16_t  last_track_last_session;
296 
297           uint16_t  unused2;            /* padding/misc info resv. */
298 
299           uint16_t  reserved1[4];                 /* MMC-5 track resources   */
300           uint32_t  reserved2[3];                 /* MMC-5 POW resources     */
301 
302           uint32_t  reserved3[8];                 /* MMC-5+ */
303 };
304 #define MMCGETDISCINFO        _IOR('c', 28, struct mmc_discinfo)
305 
306 #define MMC_CLASS_UNKN  0
307 #define MMC_CLASS_DISC        1
308 #define MMC_CLASS_CD          2
309 #define MMC_CLASS_DVD         3
310 #define MMC_CLASS_MO          4
311 #define MMC_CLASS_BD          5
312 #define MMC_CLASS_FILE        0xffff    /* emulation mode */
313 
314 #define MMC_DFLAGS_BARCODEVALID         (1 <<  0)  /* barcode is present and valid   */
315 #define MMC_DFLAGS_DISCIDVALID  (1 <<  1)  /* discid is present and valid    */
316 #define MMC_DFLAGS_APPCODEVALID (1 <<  2)  /* application code valid         */
317 #define MMC_DFLAGS_UNRESTRICTED (1 <<  3)  /* restricted, then set app. code */
318 
319 #define MMC_DFLAGS_FLAGBITS \
320     "\10\1BARCODEVALID\2DISCIDVALID\3APPCODEVALID\4UNRESTRICTED"
321 
322 #define MMC_CAP_SEQUENTIAL    (1 <<  0)  /* sequential writable only       */
323 #define MMC_CAP_RECORDABLE    (1 <<  1)  /* record-able; i.e. not static   */
324 #define MMC_CAP_ERASABLE      (1 <<  2)  /* drive can erase sectors        */
325 #define MMC_CAP_BLANKABLE     (1 <<  3)  /* media can be blanked           */
326 #define MMC_CAP_FORMATTABLE   (1 <<  4)  /* media can be formatted         */
327 #define MMC_CAP_REWRITABLE    (1 <<  5)  /* media can be rewritten         */
328 #define MMC_CAP_MRW           (1 <<  6)  /* Mount Rainier formatted        */
329 #define MMC_CAP_PACKET                  (1 <<  7)  /* using packet recording         */
330 #define MMC_CAP_STRICTOVERWRITE         (1 <<  8)  /* only writes a packet at a time */
331 #define MMC_CAP_PSEUDOOVERWRITE (1 <<  9)  /* overwrite through replacement  */
332 #define MMC_CAP_ZEROLINKBLK   (1 << 10)  /* zero link block length capable */
333 #define MMC_CAP_HW_DEFECTFREE (1 << 11)  /* hardware defect management     */
334 
335 #define MMC_CAP_FLAGBITS \
336     "\10\1SEQUENTIAL\2RECORDABLE\3ERASABLE\4BLANKABLE\5FORMATTABLE" \
337     "\6REWRITABLE\7MRW\10PACKET\11STRICTOVERWRITE\12PSEUDOOVERWRITE" \
338     "\13ZEROLINKBLK\14HW_DEFECTFREE"
339 
340 #define MMC_STATE_EMPTY                 0
341 #define MMC_STATE_INCOMPLETE  1
342 #define MMC_STATE_FULL                  2
343 #define MMC_STATE_CLOSED      3
344 
345 #define MMC_BGFSTATE_UNFORM   0
346 #define MMC_BGFSTATE_STOPPED  1
347 #define MMC_BGFSTATE_RUNNING  2
348 #define   MMC_BGFSTATE_COMPLETED        3
349 
350 
351 struct mmc_trackinfo {
352           uint16_t  tracknr;  /* IN/OUT */
353           uint16_t  sessionnr;
354 
355           uint8_t             track_mode;
356           uint8_t             data_mode;
357 
358           uint16_t  flags;
359 
360           uint32_t  track_start;
361           uint32_t  next_writable;
362           uint32_t  free_blocks;
363           uint32_t  packet_size;
364           uint32_t  track_size;
365           uint32_t  last_recorded;
366 };
367 #define MMCGETTRACKINFO       _IOWR('c', 29, struct mmc_trackinfo)
368 
369 #define MMC_TRACKINFO_COPY              (1 <<  0)
370 #define MMC_TRACKINFO_DAMAGED           (1 <<  1)
371 #define MMC_TRACKINFO_FIXED_PACKET      (1 <<  2)
372 #define MMC_TRACKINFO_INCREMENTAL       (1 <<  3)
373 #define MMC_TRACKINFO_BLANK             (1 <<  4)
374 #define MMC_TRACKINFO_RESERVED                    (1 <<  5)
375 #define MMC_TRACKINFO_NWA_VALID                   (1 <<  6)
376 #define MMC_TRACKINFO_LRA_VALID                   (1 <<  7)
377 #define MMC_TRACKINFO_DATA              (1 <<  8)
378 #define MMC_TRACKINFO_AUDIO             (1 <<  9)
379 #define MMC_TRACKINFO_AUDIO_4CHAN       (1 << 10)
380 #define MMC_TRACKINFO_PRE_EMPH                    (1 << 11)
381 
382 #define MMC_TRACKINFO_FLAGBITS \
383     "\10\1COPY\2DAMAGED\3FIXEDPACKET\4INCREMENTAL\5BLANK" \
384     "\6RESERVED\7NWA_VALID\10LRA_VALID\11DATA\12AUDIO" \
385     "\13AUDIO_4CHAN\14PRE_EMPH"
386 
387 struct mmc_op {
388           uint16_t  operation;                    /* IN */
389           uint16_t  mmc_profile;                  /* IN */
390 
391           /* parameters to operation */
392           uint16_t  tracknr;            /* IN */
393           uint16_t  sessionnr;                    /* IN */
394           uint32_t  extent;                       /* IN */
395 
396           uint32_t  reserved[4];
397 };
398 #define MMCOP _IOWR('c', 30, struct mmc_op)
399 
400 #define MMC_OP_SYNCHRONISECACHE                    1
401 #define MMC_OP_CLOSETRACK                2
402 #define MMC_OP_CLOSESESSION              3
403 #define MMC_OP_FINALISEDISC              4
404 #define MMC_OP_RESERVETRACK              5
405 #define MMC_OP_RESERVETRACK_NWA                    6
406 #define MMC_OP_UNRESERVETRACK            7
407 #define MMC_OP_REPAIRTRACK               8
408 #define MMC_OP_UNCLOSELASTSESSION        9
409 #define MMC_OP_MAX                       9
410 
411 struct mmc_writeparams {
412           uint16_t  tracknr;            /* IN */
413           uint16_t  mmc_class;                    /* IN */
414           uint32_t  mmc_cur;            /* IN */
415           uint32_t  blockingnr;                   /* IN */
416 
417           /* when tracknr == 0 */
418           uint8_t             track_mode;                   /* IN; normally 5 */
419           uint8_t             data_mode;                    /* IN; normally 2 */
420 };
421 #define MMC_TRACKMODE_DEFAULT 5                   /* data, incremental recording */
422 #define MMC_DATAMODE_DEFAULT  2                   /* CDROM XA disc */
423 #define MMCSETUPWRITEPARAMS _IOW('c', 31, struct mmc_writeparams)
424 
425 #endif /* _KERNEL || _EXPOSE_MMC */
426 
427 #endif /* !_SYS_CDIO_H_ */
428