Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /* |
| 3 | * -- <linux/cdrom.h> |
| 4 | * General header file for linux CD-ROM drivers |
| 5 | * Copyright (C) 1992 David Giller, rafetmad@oxy.edu |
Jan Engelhardt | 96de0e2 | 2007-10-19 23:21:04 +0200 | [diff] [blame] | 6 | * 1994, 1995 Eberhard Mönkeberg, emoenke@gwdg.de |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | #ifndef _LINUX_CDROM_H |
| 12 | #define _LINUX_CDROM_H |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/fs.h> /* not really needed, later.. */ |
Akinobu Mita | 7fd097d | 2008-03-26 12:09:02 +0100 | [diff] [blame] | 15 | #include <linux/list.h> |
David Howells | 607ca46 | 2012-10-13 10:46:48 +0100 | [diff] [blame] | 16 | #include <uapi/linux/cdrom.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | struct packet_command |
| 19 | { |
| 20 | unsigned char cmd[CDROM_PACKET_SIZE]; |
| 21 | unsigned char *buffer; |
| 22 | unsigned int buflen; |
| 23 | int stat; |
| 24 | struct request_sense *sense; |
| 25 | unsigned char data_direction; |
| 26 | int quiet; |
| 27 | int timeout; |
| 28 | void *reserved[1]; |
| 29 | }; |
| 30 | |
| 31 | /* |
| 32 | * _OLD will use PIO transfer on atapi devices, _BPC_* will use DMA |
| 33 | */ |
| 34 | #define CDDA_OLD 0 /* old style */ |
| 35 | #define CDDA_BPC_SINGLE 1 /* single frame block pc */ |
| 36 | #define CDDA_BPC_FULL 2 /* multi frame block pc */ |
| 37 | |
| 38 | /* Uniform cdrom data structures for cdrom.c */ |
| 39 | struct cdrom_device_info { |
Kees Cook | 853fe1b | 2017-02-13 16:25:26 -0800 | [diff] [blame] | 40 | const struct cdrom_device_ops *ops; /* link to device_ops */ |
Akinobu Mita | 7fd097d | 2008-03-26 12:09:02 +0100 | [diff] [blame] | 41 | struct list_head list; /* linked list of all device_info */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | struct gendisk *disk; /* matching block layer disk */ |
| 43 | void *handle; /* driver-dependent data */ |
| 44 | /* specifications */ |
| 45 | int mask; /* mask of capability: disables them */ |
| 46 | int speed; /* maximum speed for reading data */ |
| 47 | int capacity; /* number of discs in jukebox */ |
| 48 | /* device-related storage */ |
Randy Dunlap | 0cba01db | 2007-02-20 13:58:05 -0800 | [diff] [blame] | 49 | unsigned int options : 30; /* options flags */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | unsigned mc_flags : 2; /* media change buffer flags */ |
Tejun Heo | 2d92172 | 2010-12-08 20:57:38 +0100 | [diff] [blame] | 51 | unsigned int vfs_events; /* cached events for vfs path */ |
| 52 | unsigned int ioctl_events; /* cached events for ioctl path */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | int use_count; /* number of times device opened */ |
| 54 | char name[20]; /* name of the device type */ |
| 55 | /* per-device flags */ |
| 56 | __u8 sanyo_slot : 2; /* Sanyo 3 CD changer support */ |
Paolo Bonzini | cdccaa9 | 2012-02-08 20:03:14 +0100 | [diff] [blame] | 57 | __u8 keeplocked : 1; /* CDROM_LOCKDOOR status */ |
| 58 | __u8 reserved : 5; /* not used yet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | int cdda_method; /* see flags */ |
| 60 | __u8 last_sense; |
| 61 | __u8 media_written; /* dirty flag, DVD+RW bookkeeping */ |
| 62 | unsigned short mmc3_profile; /* current MMC3 profile */ |
| 63 | int for_data; |
| 64 | int (*exit)(struct cdrom_device_info *); |
| 65 | int mrw_mode_page; |
| 66 | }; |
| 67 | |
| 68 | struct cdrom_device_ops { |
| 69 | /* routines */ |
| 70 | int (*open) (struct cdrom_device_info *, int); |
| 71 | void (*release) (struct cdrom_device_info *); |
| 72 | int (*drive_status) (struct cdrom_device_info *, int); |
Tejun Heo | 2d92172 | 2010-12-08 20:57:38 +0100 | [diff] [blame] | 73 | unsigned int (*check_events) (struct cdrom_device_info *cdi, |
| 74 | unsigned int clearing, int slot); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | int (*media_changed) (struct cdrom_device_info *, int); |
| 76 | int (*tray_move) (struct cdrom_device_info *, int); |
| 77 | int (*lock_door) (struct cdrom_device_info *, int); |
| 78 | int (*select_speed) (struct cdrom_device_info *, int); |
| 79 | int (*select_disc) (struct cdrom_device_info *, int); |
| 80 | int (*get_last_session) (struct cdrom_device_info *, |
| 81 | struct cdrom_multisession *); |
| 82 | int (*get_mcn) (struct cdrom_device_info *, |
| 83 | struct cdrom_mcn *); |
| 84 | /* hard reset device */ |
| 85 | int (*reset) (struct cdrom_device_info *); |
| 86 | /* play stuff */ |
| 87 | int (*audio_ioctl) (struct cdrom_device_info *,unsigned int, void *); |
Christoph Hellwig | 6a2900b | 2006-03-23 03:00:15 -0800 | [diff] [blame] | 88 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | /* driver specifications */ |
| 90 | const int capability; /* capability flags */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | /* handle uniform packets for scsi type devices (scsi,atapi) */ |
| 92 | int (*generic_packet) (struct cdrom_device_info *, |
| 93 | struct packet_command *); |
| 94 | }; |
| 95 | |
| 96 | /* the general block_device operations structure: */ |
Al Viro | bbc1cc9 | 2007-10-07 17:54:28 -0400 | [diff] [blame] | 97 | extern int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev, |
| 98 | fmode_t mode); |
| 99 | extern void cdrom_release(struct cdrom_device_info *cdi, fmode_t mode); |
| 100 | extern int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev, |
| 101 | fmode_t mode, unsigned int cmd, unsigned long arg); |
Tejun Heo | 2d92172 | 2010-12-08 20:57:38 +0100 | [diff] [blame] | 102 | extern unsigned int cdrom_check_events(struct cdrom_device_info *cdi, |
| 103 | unsigned int clearing); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | extern int cdrom_media_changed(struct cdrom_device_info *); |
| 105 | |
| 106 | extern int register_cdrom(struct cdrom_device_info *cdi); |
Akinobu Mita | 0a0c411 | 2008-03-26 12:09:02 +0100 | [diff] [blame] | 107 | extern void unregister_cdrom(struct cdrom_device_info *cdi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | typedef struct { |
| 110 | int data; |
| 111 | int audio; |
| 112 | int cdi; |
| 113 | int xa; |
| 114 | long error; |
| 115 | } tracktype; |
| 116 | |
| 117 | extern int cdrom_get_last_written(struct cdrom_device_info *cdi, long *last_written); |
| 118 | extern int cdrom_number_of_slots(struct cdrom_device_info *cdi); |
| 119 | extern int cdrom_mode_select(struct cdrom_device_info *cdi, |
| 120 | struct packet_command *cgc); |
| 121 | extern int cdrom_mode_sense(struct cdrom_device_info *cdi, |
| 122 | struct packet_command *cgc, |
| 123 | int page_code, int page_control); |
| 124 | extern void init_cdrom_command(struct packet_command *cgc, |
| 125 | void *buffer, int len, int type); |
Kees Cook | 853fe1b | 2017-02-13 16:25:26 -0800 | [diff] [blame] | 126 | extern int cdrom_dummy_generic_packet(struct cdrom_device_info *cdi, |
| 127 | struct packet_command *cgc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | /* The SCSI spec says there could be 256 slots. */ |
| 130 | #define CDROM_MAX_SLOTS 256 |
| 131 | |
| 132 | struct cdrom_mechstat_header { |
| 133 | #if defined(__BIG_ENDIAN_BITFIELD) |
| 134 | __u8 fault : 1; |
| 135 | __u8 changer_state : 2; |
| 136 | __u8 curslot : 5; |
| 137 | __u8 mech_state : 3; |
| 138 | __u8 door_open : 1; |
| 139 | __u8 reserved1 : 4; |
| 140 | #elif defined(__LITTLE_ENDIAN_BITFIELD) |
| 141 | __u8 curslot : 5; |
| 142 | __u8 changer_state : 2; |
| 143 | __u8 fault : 1; |
| 144 | __u8 reserved1 : 4; |
| 145 | __u8 door_open : 1; |
| 146 | __u8 mech_state : 3; |
| 147 | #endif |
| 148 | __u8 curlba[3]; |
| 149 | __u8 nslots; |
| 150 | __u16 slot_tablelen; |
| 151 | }; |
| 152 | |
| 153 | struct cdrom_slot { |
| 154 | #if defined(__BIG_ENDIAN_BITFIELD) |
| 155 | __u8 disc_present : 1; |
| 156 | __u8 reserved1 : 6; |
| 157 | __u8 change : 1; |
| 158 | #elif defined(__LITTLE_ENDIAN_BITFIELD) |
| 159 | __u8 change : 1; |
| 160 | __u8 reserved1 : 6; |
| 161 | __u8 disc_present : 1; |
| 162 | #endif |
| 163 | __u8 reserved2[3]; |
| 164 | }; |
| 165 | |
| 166 | struct cdrom_changer_info { |
| 167 | struct cdrom_mechstat_header hdr; |
| 168 | struct cdrom_slot slots[CDROM_MAX_SLOTS]; |
| 169 | }; |
| 170 | |
| 171 | typedef enum { |
| 172 | mechtype_caddy = 0, |
| 173 | mechtype_tray = 1, |
| 174 | mechtype_popup = 2, |
| 175 | mechtype_individual_changer = 4, |
| 176 | mechtype_cartridge_changer = 5 |
| 177 | } mechtype_t; |
| 178 | |
| 179 | typedef struct { |
| 180 | #if defined(__BIG_ENDIAN_BITFIELD) |
| 181 | __u8 ps : 1; |
| 182 | __u8 reserved1 : 1; |
| 183 | __u8 page_code : 6; |
| 184 | __u8 page_length; |
| 185 | __u8 reserved2 : 1; |
| 186 | __u8 bufe : 1; |
| 187 | __u8 ls_v : 1; |
| 188 | __u8 test_write : 1; |
| 189 | __u8 write_type : 4; |
| 190 | __u8 multi_session : 2; /* or border, DVD */ |
| 191 | __u8 fp : 1; |
| 192 | __u8 copy : 1; |
| 193 | __u8 track_mode : 4; |
| 194 | __u8 reserved3 : 4; |
| 195 | __u8 data_block_type : 4; |
| 196 | #elif defined(__LITTLE_ENDIAN_BITFIELD) |
| 197 | __u8 page_code : 6; |
| 198 | __u8 reserved1 : 1; |
| 199 | __u8 ps : 1; |
| 200 | __u8 page_length; |
| 201 | __u8 write_type : 4; |
| 202 | __u8 test_write : 1; |
| 203 | __u8 ls_v : 1; |
| 204 | __u8 bufe : 1; |
| 205 | __u8 reserved2 : 1; |
| 206 | __u8 track_mode : 4; |
| 207 | __u8 copy : 1; |
| 208 | __u8 fp : 1; |
| 209 | __u8 multi_session : 2; /* or border, DVD */ |
| 210 | __u8 data_block_type : 4; |
| 211 | __u8 reserved3 : 4; |
| 212 | #endif |
| 213 | __u8 link_size; |
| 214 | __u8 reserved4; |
| 215 | #if defined(__BIG_ENDIAN_BITFIELD) |
| 216 | __u8 reserved5 : 2; |
| 217 | __u8 app_code : 6; |
| 218 | #elif defined(__LITTLE_ENDIAN_BITFIELD) |
| 219 | __u8 app_code : 6; |
| 220 | __u8 reserved5 : 2; |
| 221 | #endif |
| 222 | __u8 session_format; |
| 223 | __u8 reserved6; |
Alexey Dobriyan | 56052d5 | 2005-12-01 17:10:40 -0500 | [diff] [blame] | 224 | __be32 packet_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | __u16 audio_pause; |
| 226 | __u8 mcn[16]; |
| 227 | __u8 isrc[16]; |
| 228 | __u8 subhdr0; |
| 229 | __u8 subhdr1; |
| 230 | __u8 subhdr2; |
| 231 | __u8 subhdr3; |
| 232 | } __attribute__((packed)) write_param_page; |
| 233 | |
| 234 | struct modesel_head |
| 235 | { |
| 236 | __u8 reserved1; |
| 237 | __u8 medium; |
| 238 | __u8 reserved2; |
| 239 | __u8 block_desc_length; |
| 240 | __u8 density; |
| 241 | __u8 number_of_blocks_hi; |
| 242 | __u8 number_of_blocks_med; |
| 243 | __u8 number_of_blocks_lo; |
| 244 | __u8 reserved3; |
| 245 | __u8 block_length_hi; |
| 246 | __u8 block_length_med; |
| 247 | __u8 block_length_lo; |
| 248 | }; |
| 249 | |
| 250 | typedef struct { |
| 251 | __u16 report_key_length; |
| 252 | __u8 reserved1; |
| 253 | __u8 reserved2; |
| 254 | #if defined(__BIG_ENDIAN_BITFIELD) |
| 255 | __u8 type_code : 2; |
| 256 | __u8 vra : 3; |
| 257 | __u8 ucca : 3; |
| 258 | #elif defined(__LITTLE_ENDIAN_BITFIELD) |
| 259 | __u8 ucca : 3; |
| 260 | __u8 vra : 3; |
| 261 | __u8 type_code : 2; |
| 262 | #endif |
| 263 | __u8 region_mask; |
| 264 | __u8 rpc_scheme; |
| 265 | __u8 reserved3; |
| 266 | } rpc_state_t; |
| 267 | |
| 268 | struct event_header { |
Alexey Dobriyan | 56052d5 | 2005-12-01 17:10:40 -0500 | [diff] [blame] | 269 | __be16 data_len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | #if defined(__BIG_ENDIAN_BITFIELD) |
| 271 | __u8 nea : 1; |
| 272 | __u8 reserved1 : 4; |
| 273 | __u8 notification_class : 3; |
| 274 | #elif defined(__LITTLE_ENDIAN_BITFIELD) |
| 275 | __u8 notification_class : 3; |
| 276 | __u8 reserved1 : 4; |
| 277 | __u8 nea : 1; |
| 278 | #endif |
| 279 | __u8 supp_event_class; |
| 280 | }; |
| 281 | |
| 282 | struct media_event_desc { |
| 283 | #if defined(__BIG_ENDIAN_BITFIELD) |
| 284 | __u8 reserved1 : 4; |
| 285 | __u8 media_event_code : 4; |
| 286 | __u8 reserved2 : 6; |
| 287 | __u8 media_present : 1; |
| 288 | __u8 door_open : 1; |
| 289 | #elif defined(__LITTLE_ENDIAN_BITFIELD) |
| 290 | __u8 media_event_code : 4; |
| 291 | __u8 reserved1 : 4; |
| 292 | __u8 door_open : 1; |
| 293 | __u8 media_present : 1; |
| 294 | __u8 reserved2 : 6; |
| 295 | #endif |
| 296 | __u8 start_slot; |
| 297 | __u8 end_slot; |
| 298 | }; |
| 299 | |
| 300 | extern int cdrom_get_media_event(struct cdrom_device_info *cdi, struct media_event_desc *med); |
| 301 | |
Bartlomiej Zolnierkiewicz | a1bb945 | 2008-02-01 23:09:24 +0100 | [diff] [blame] | 302 | static inline void lba_to_msf(int lba, u8 *m, u8 *s, u8 *f) |
| 303 | { |
| 304 | lba += CD_MSF_OFFSET; |
| 305 | lba &= 0xffffff; /* negative lbas use only 24 bits */ |
| 306 | *m = lba / (CD_SECS * CD_FRAMES); |
| 307 | lba %= (CD_SECS * CD_FRAMES); |
| 308 | *s = lba / CD_FRAMES; |
| 309 | *f = lba % CD_FRAMES; |
| 310 | } |
| 311 | |
| 312 | static inline int msf_to_lba(u8 m, u8 s, u8 f) |
| 313 | { |
| 314 | return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET; |
| 315 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | #endif /* _LINUX_CDROM_H */ |