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