blob: f48d0a31deaece2dafcd65a2d68925c50bb4bbbc [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001/* SPDX-License-Identifier: GPL-2.0 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*
3 * -- <linux/cdrom.h>
4 * General header file for linux CD-ROM drivers
5 * Copyright (C) 1992 David Giller, rafetmad@oxy.edu
Jan Engelhardt96de0e22007-10-19 23:21:04 +02006 * 1994, 1995 Eberhard Mönkeberg, emoenke@gwdg.de
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 * 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 Torvalds1da177e2005-04-16 15:20:36 -070011#ifndef _LINUX_CDROM_H
12#define _LINUX_CDROM_H
13
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/fs.h> /* not really needed, later.. */
Akinobu Mita7fd097d2008-03-26 12:09:02 +010015#include <linux/list.h>
Kees Cooke7d07482018-08-02 15:22:13 -060016#include <scsi/scsi_common.h>
David Howells607ca462012-10-13 10:46:48 +010017#include <uapi/linux/cdrom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
19struct packet_command
20{
21 unsigned char cmd[CDROM_PACKET_SIZE];
22 unsigned char *buffer;
23 unsigned int buflen;
24 int stat;
Kees Cooke7d07482018-08-02 15:22:13 -060025 struct scsi_sense_hdr *sshdr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070026 unsigned char data_direction;
27 int quiet;
28 int timeout;
29 void *reserved[1];
30};
31
32/*
33 * _OLD will use PIO transfer on atapi devices, _BPC_* will use DMA
34 */
35#define CDDA_OLD 0 /* old style */
36#define CDDA_BPC_SINGLE 1 /* single frame block pc */
37#define CDDA_BPC_FULL 2 /* multi frame block pc */
38
39/* Uniform cdrom data structures for cdrom.c */
40struct cdrom_device_info {
Kees Cook853fe1b2017-02-13 16:25:26 -080041 const struct cdrom_device_ops *ops; /* link to device_ops */
Akinobu Mita7fd097d2008-03-26 12:09:02 +010042 struct list_head list; /* linked list of all device_info */
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 struct gendisk *disk; /* matching block layer disk */
44 void *handle; /* driver-dependent data */
45/* specifications */
46 int mask; /* mask of capability: disables them */
47 int speed; /* maximum speed for reading data */
48 int capacity; /* number of discs in jukebox */
49/* device-related storage */
Randy Dunlap0cba01db2007-02-20 13:58:05 -080050 unsigned int options : 30; /* options flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -070051 unsigned mc_flags : 2; /* media change buffer flags */
Tejun Heo2d921722010-12-08 20:57:38 +010052 unsigned int vfs_events; /* cached events for vfs path */
53 unsigned int ioctl_events; /* cached events for ioctl path */
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 int use_count; /* number of times device opened */
55 char name[20]; /* name of the device type */
56/* per-device flags */
57 __u8 sanyo_slot : 2; /* Sanyo 3 CD changer support */
Paolo Bonzinicdccaa92012-02-08 20:03:14 +010058 __u8 keeplocked : 1; /* CDROM_LOCKDOOR status */
59 __u8 reserved : 5; /* not used yet */
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 int cdda_method; /* see flags */
61 __u8 last_sense;
62 __u8 media_written; /* dirty flag, DVD+RW bookkeeping */
63 unsigned short mmc3_profile; /* current MMC3 profile */
64 int for_data;
65 int (*exit)(struct cdrom_device_info *);
66 int mrw_mode_page;
67};
68
69struct cdrom_device_ops {
70/* routines */
71 int (*open) (struct cdrom_device_info *, int);
72 void (*release) (struct cdrom_device_info *);
73 int (*drive_status) (struct cdrom_device_info *, int);
Tejun Heo2d921722010-12-08 20:57:38 +010074 unsigned int (*check_events) (struct cdrom_device_info *cdi,
75 unsigned int clearing, int slot);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 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 Hellwig6a2900b2006-03-23 03:00:15 -080088
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/* driver specifications */
90 const int capability; /* capability flags */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 /* handle uniform packets for scsi type devices (scsi,atapi) */
92 int (*generic_packet) (struct cdrom_device_info *,
93 struct packet_command *);
94};
95
Christoph Hellwigeaf8e3e2020-04-25 09:57:03 +020096int cdrom_multisession(struct cdrom_device_info *cdi,
97 struct cdrom_multisession *info);
Christoph Hellwig4c3cfcc2020-04-25 09:57:02 +020098int cdrom_read_tocentry(struct cdrom_device_info *cdi,
99 struct cdrom_tocentry *entry);
100
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101/* the general block_device operations structure: */
Al Virobbc1cc92007-10-07 17:54:28 -0400102extern int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev,
103 fmode_t mode);
104extern void cdrom_release(struct cdrom_device_info *cdi, fmode_t mode);
105extern int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
106 fmode_t mode, unsigned int cmd, unsigned long arg);
Tejun Heo2d921722010-12-08 20:57:38 +0100107extern unsigned int cdrom_check_events(struct cdrom_device_info *cdi,
108 unsigned int clearing);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
Christoph Hellwiga711d912020-04-25 09:57:00 +0200110extern int register_cdrom(struct gendisk *disk, struct cdrom_device_info *cdi);
Akinobu Mita0a0c4112008-03-26 12:09:02 +0100111extern void unregister_cdrom(struct cdrom_device_info *cdi);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112
113typedef struct {
114 int data;
115 int audio;
116 int cdi;
117 int xa;
118 long error;
119} tracktype;
120
121extern int cdrom_get_last_written(struct cdrom_device_info *cdi, long *last_written);
122extern int cdrom_number_of_slots(struct cdrom_device_info *cdi);
123extern int cdrom_mode_select(struct cdrom_device_info *cdi,
124 struct packet_command *cgc);
125extern int cdrom_mode_sense(struct cdrom_device_info *cdi,
126 struct packet_command *cgc,
127 int page_code, int page_control);
128extern void init_cdrom_command(struct packet_command *cgc,
129 void *buffer, int len, int type);
Kees Cook853fe1b2017-02-13 16:25:26 -0800130extern int cdrom_dummy_generic_packet(struct cdrom_device_info *cdi,
131 struct packet_command *cgc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133/* The SCSI spec says there could be 256 slots. */
134#define CDROM_MAX_SLOTS 256
135
136struct cdrom_mechstat_header {
137#if defined(__BIG_ENDIAN_BITFIELD)
138 __u8 fault : 1;
139 __u8 changer_state : 2;
140 __u8 curslot : 5;
141 __u8 mech_state : 3;
142 __u8 door_open : 1;
143 __u8 reserved1 : 4;
144#elif defined(__LITTLE_ENDIAN_BITFIELD)
145 __u8 curslot : 5;
146 __u8 changer_state : 2;
147 __u8 fault : 1;
148 __u8 reserved1 : 4;
149 __u8 door_open : 1;
150 __u8 mech_state : 3;
151#endif
152 __u8 curlba[3];
153 __u8 nslots;
154 __u16 slot_tablelen;
155};
156
157struct cdrom_slot {
158#if defined(__BIG_ENDIAN_BITFIELD)
159 __u8 disc_present : 1;
160 __u8 reserved1 : 6;
161 __u8 change : 1;
162#elif defined(__LITTLE_ENDIAN_BITFIELD)
163 __u8 change : 1;
164 __u8 reserved1 : 6;
165 __u8 disc_present : 1;
166#endif
167 __u8 reserved2[3];
168};
169
170struct cdrom_changer_info {
171 struct cdrom_mechstat_header hdr;
172 struct cdrom_slot slots[CDROM_MAX_SLOTS];
173};
174
175typedef enum {
176 mechtype_caddy = 0,
177 mechtype_tray = 1,
178 mechtype_popup = 2,
179 mechtype_individual_changer = 4,
180 mechtype_cartridge_changer = 5
181} mechtype_t;
182
183typedef struct {
184#if defined(__BIG_ENDIAN_BITFIELD)
185 __u8 ps : 1;
186 __u8 reserved1 : 1;
187 __u8 page_code : 6;
188 __u8 page_length;
189 __u8 reserved2 : 1;
190 __u8 bufe : 1;
191 __u8 ls_v : 1;
192 __u8 test_write : 1;
193 __u8 write_type : 4;
194 __u8 multi_session : 2; /* or border, DVD */
195 __u8 fp : 1;
196 __u8 copy : 1;
197 __u8 track_mode : 4;
198 __u8 reserved3 : 4;
199 __u8 data_block_type : 4;
200#elif defined(__LITTLE_ENDIAN_BITFIELD)
201 __u8 page_code : 6;
202 __u8 reserved1 : 1;
203 __u8 ps : 1;
204 __u8 page_length;
205 __u8 write_type : 4;
206 __u8 test_write : 1;
207 __u8 ls_v : 1;
208 __u8 bufe : 1;
209 __u8 reserved2 : 1;
210 __u8 track_mode : 4;
211 __u8 copy : 1;
212 __u8 fp : 1;
213 __u8 multi_session : 2; /* or border, DVD */
214 __u8 data_block_type : 4;
215 __u8 reserved3 : 4;
216#endif
217 __u8 link_size;
218 __u8 reserved4;
219#if defined(__BIG_ENDIAN_BITFIELD)
220 __u8 reserved5 : 2;
221 __u8 app_code : 6;
222#elif defined(__LITTLE_ENDIAN_BITFIELD)
223 __u8 app_code : 6;
224 __u8 reserved5 : 2;
225#endif
226 __u8 session_format;
227 __u8 reserved6;
Alexey Dobriyan56052d52005-12-01 17:10:40 -0500228 __be32 packet_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 __u16 audio_pause;
230 __u8 mcn[16];
231 __u8 isrc[16];
232 __u8 subhdr0;
233 __u8 subhdr1;
234 __u8 subhdr2;
235 __u8 subhdr3;
236} __attribute__((packed)) write_param_page;
237
238struct modesel_head
239{
240 __u8 reserved1;
241 __u8 medium;
242 __u8 reserved2;
243 __u8 block_desc_length;
244 __u8 density;
245 __u8 number_of_blocks_hi;
246 __u8 number_of_blocks_med;
247 __u8 number_of_blocks_lo;
248 __u8 reserved3;
249 __u8 block_length_hi;
250 __u8 block_length_med;
251 __u8 block_length_lo;
252};
253
254typedef struct {
255 __u16 report_key_length;
256 __u8 reserved1;
257 __u8 reserved2;
258#if defined(__BIG_ENDIAN_BITFIELD)
259 __u8 type_code : 2;
260 __u8 vra : 3;
261 __u8 ucca : 3;
262#elif defined(__LITTLE_ENDIAN_BITFIELD)
263 __u8 ucca : 3;
264 __u8 vra : 3;
265 __u8 type_code : 2;
266#endif
267 __u8 region_mask;
268 __u8 rpc_scheme;
269 __u8 reserved3;
270} rpc_state_t;
271
272struct event_header {
Alexey Dobriyan56052d52005-12-01 17:10:40 -0500273 __be16 data_len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274#if defined(__BIG_ENDIAN_BITFIELD)
275 __u8 nea : 1;
276 __u8 reserved1 : 4;
277 __u8 notification_class : 3;
278#elif defined(__LITTLE_ENDIAN_BITFIELD)
279 __u8 notification_class : 3;
280 __u8 reserved1 : 4;
281 __u8 nea : 1;
282#endif
283 __u8 supp_event_class;
284};
285
286struct media_event_desc {
287#if defined(__BIG_ENDIAN_BITFIELD)
288 __u8 reserved1 : 4;
289 __u8 media_event_code : 4;
290 __u8 reserved2 : 6;
291 __u8 media_present : 1;
292 __u8 door_open : 1;
293#elif defined(__LITTLE_ENDIAN_BITFIELD)
294 __u8 media_event_code : 4;
295 __u8 reserved1 : 4;
296 __u8 door_open : 1;
297 __u8 media_present : 1;
298 __u8 reserved2 : 6;
299#endif
300 __u8 start_slot;
301 __u8 end_slot;
302};
303
304extern int cdrom_get_media_event(struct cdrom_device_info *cdi, struct media_event_desc *med);
305
Bartlomiej Zolnierkiewicza1bb9452008-02-01 23:09:24 +0100306static inline void lba_to_msf(int lba, u8 *m, u8 *s, u8 *f)
307{
308 lba += CD_MSF_OFFSET;
309 lba &= 0xffffff; /* negative lbas use only 24 bits */
310 *m = lba / (CD_SECS * CD_FRAMES);
311 lba %= (CD_SECS * CD_FRAMES);
312 *s = lba / CD_FRAMES;
313 *f = lba % CD_FRAMES;
314}
315
316static inline int msf_to_lba(u8 m, u8 s, u8 f)
317{
318 return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
319}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320#endif /* _LINUX_CDROM_H */