xref: /linux/include/linux/cdrom.h (revision 34f7c6e7d4396090692a09789db231e12cb4762b)
1 /* SPDX-License-Identifier: GPL-2.0 */
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 #ifndef	_LINUX_CDROM_H
12 #define	_LINUX_CDROM_H
13 
14 #include <linux/fs.h>		/* not really needed, later.. */
15 #include <linux/list.h>
16 #include <scsi/scsi_common.h>
17 #include <uapi/linux/cdrom.h>
18 
19 struct packet_command
20 {
21 	unsigned char 		cmd[CDROM_PACKET_SIZE];
22 	unsigned char 		*buffer;
23 	unsigned int 		buflen;
24 	int			stat;
25 	struct scsi_sense_hdr	*sshdr;
26 	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 */
40 struct cdrom_device_info {
41 	const struct cdrom_device_ops *ops; /* link to device_ops */
42 	struct list_head list;		/* linked list of all device_info */
43 	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 */
50 	unsigned int options	: 30;	/* options flags */
51 	unsigned mc_flags	: 2;	/* media change buffer flags */
52 	unsigned int vfs_events;	/* cached events for vfs path */
53 	unsigned int ioctl_events;	/* cached events for ioctl path */
54     	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 */
58         __u8 keeplocked		: 1;	/* CDROM_LOCKDOOR status */
59         __u8 reserved		: 5;	/* not used yet */
60 	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 	__s64 last_media_change_ms;
68 };
69 
70 struct cdrom_device_ops {
71 /* routines */
72 	int (*open) (struct cdrom_device_info *, int);
73 	void (*release) (struct cdrom_device_info *);
74 	int (*drive_status) (struct cdrom_device_info *, int);
75 	unsigned int (*check_events) (struct cdrom_device_info *cdi,
76 				      unsigned int clearing, int slot);
77 	int (*tray_move) (struct cdrom_device_info *, int);
78 	int (*lock_door) (struct cdrom_device_info *, int);
79 	int (*select_speed) (struct cdrom_device_info *, int);
80 	int (*select_disc) (struct cdrom_device_info *, int);
81 	int (*get_last_session) (struct cdrom_device_info *,
82 				 struct cdrom_multisession *);
83 	int (*get_mcn) (struct cdrom_device_info *,
84 			struct cdrom_mcn *);
85 	/* hard reset device */
86 	int (*reset) (struct cdrom_device_info *);
87 	/* play stuff */
88 	int (*audio_ioctl) (struct cdrom_device_info *,unsigned int, void *);
89 
90 	/* handle uniform packets for scsi type devices (scsi,atapi) */
91 	int (*generic_packet) (struct cdrom_device_info *,
92 			       struct packet_command *);
93 	int (*read_cdda_bpc)(struct cdrom_device_info *cdi, void __user *ubuf,
94 			       u32 lba, u32 nframes, u8 *last_sense);
95 /* driver specifications */
96 	const int capability;   /* capability flags */
97 };
98 
99 int cdrom_multisession(struct cdrom_device_info *cdi,
100 		struct cdrom_multisession *info);
101 int cdrom_read_tocentry(struct cdrom_device_info *cdi,
102 		struct cdrom_tocentry *entry);
103 
104 /* the general block_device operations structure: */
105 extern int cdrom_open(struct cdrom_device_info *cdi, struct block_device *bdev,
106 			fmode_t mode);
107 extern void cdrom_release(struct cdrom_device_info *cdi, fmode_t mode);
108 extern int cdrom_ioctl(struct cdrom_device_info *cdi, struct block_device *bdev,
109 		       fmode_t mode, unsigned int cmd, unsigned long arg);
110 extern unsigned int cdrom_check_events(struct cdrom_device_info *cdi,
111 				       unsigned int clearing);
112 
113 extern int register_cdrom(struct gendisk *disk, struct cdrom_device_info *cdi);
114 extern void unregister_cdrom(struct cdrom_device_info *cdi);
115 
116 typedef struct {
117     int data;
118     int audio;
119     int cdi;
120     int xa;
121     long error;
122 } tracktype;
123 
124 extern int cdrom_get_last_written(struct cdrom_device_info *cdi, long *last_written);
125 extern int cdrom_number_of_slots(struct cdrom_device_info *cdi);
126 extern int cdrom_mode_select(struct cdrom_device_info *cdi,
127 			     struct packet_command *cgc);
128 extern int cdrom_mode_sense(struct cdrom_device_info *cdi,
129 			    struct packet_command *cgc,
130 			    int page_code, int page_control);
131 extern void init_cdrom_command(struct packet_command *cgc,
132 			       void *buffer, int len, int type);
133 extern int cdrom_dummy_generic_packet(struct cdrom_device_info *cdi,
134 				      struct packet_command *cgc);
135 
136 /* The SCSI spec says there could be 256 slots. */
137 #define CDROM_MAX_SLOTS	256
138 
139 struct cdrom_mechstat_header {
140 #if defined(__BIG_ENDIAN_BITFIELD)
141 	__u8 fault         : 1;
142 	__u8 changer_state : 2;
143 	__u8 curslot       : 5;
144 	__u8 mech_state    : 3;
145 	__u8 door_open     : 1;
146 	__u8 reserved1     : 4;
147 #elif defined(__LITTLE_ENDIAN_BITFIELD)
148 	__u8 curslot       : 5;
149 	__u8 changer_state : 2;
150 	__u8 fault         : 1;
151 	__u8 reserved1     : 4;
152 	__u8 door_open     : 1;
153 	__u8 mech_state    : 3;
154 #endif
155 	__u8     curlba[3];
156 	__u8     nslots;
157 	__u16 slot_tablelen;
158 };
159 
160 struct cdrom_slot {
161 #if defined(__BIG_ENDIAN_BITFIELD)
162 	__u8 disc_present : 1;
163 	__u8 reserved1    : 6;
164 	__u8 change       : 1;
165 #elif defined(__LITTLE_ENDIAN_BITFIELD)
166 	__u8 change       : 1;
167 	__u8 reserved1    : 6;
168 	__u8 disc_present : 1;
169 #endif
170 	__u8 reserved2[3];
171 };
172 
173 struct cdrom_changer_info {
174 	struct cdrom_mechstat_header hdr;
175 	struct cdrom_slot slots[CDROM_MAX_SLOTS];
176 };
177 
178 typedef enum {
179 	mechtype_caddy = 0,
180 	mechtype_tray  = 1,
181 	mechtype_popup = 2,
182 	mechtype_individual_changer = 4,
183 	mechtype_cartridge_changer  = 5
184 } mechtype_t;
185 
186 typedef struct {
187 #if defined(__BIG_ENDIAN_BITFIELD)
188 	__u8 ps			: 1;
189 	__u8 reserved1		: 1;
190 	__u8 page_code		: 6;
191         __u8 page_length;
192 	__u8 reserved2		: 1;
193 	__u8 bufe		: 1;
194 	__u8 ls_v		: 1;
195 	__u8 test_write		: 1;
196         __u8 write_type		: 4;
197 	__u8 multi_session	: 2; /* or border, DVD */
198 	__u8 fp			: 1;
199 	__u8 copy		: 1;
200 	__u8 track_mode		: 4;
201 	__u8 reserved3		: 4;
202 	__u8 data_block_type	: 4;
203 #elif defined(__LITTLE_ENDIAN_BITFIELD)
204 	__u8 page_code		: 6;
205 	__u8 reserved1		: 1;
206 	__u8 ps			: 1;
207         __u8 page_length;
208         __u8 write_type		: 4;
209 	__u8 test_write		: 1;
210 	__u8 ls_v		: 1;
211 	__u8 bufe		: 1;
212 	__u8 reserved2		: 1;
213 	__u8 track_mode		: 4;
214 	__u8 copy		: 1;
215 	__u8 fp			: 1;
216 	__u8 multi_session	: 2; /* or border, DVD */
217 	__u8 data_block_type	: 4;
218 	__u8 reserved3		: 4;
219 #endif
220 	__u8 link_size;
221 	__u8 reserved4;
222 #if defined(__BIG_ENDIAN_BITFIELD)
223 	__u8 reserved5		: 2;
224 	__u8 app_code		: 6;
225 #elif defined(__LITTLE_ENDIAN_BITFIELD)
226 	__u8 app_code		: 6;
227 	__u8 reserved5		: 2;
228 #endif
229 	__u8 session_format;
230 	__u8 reserved6;
231 	__be32 packet_size;
232 	__u16 audio_pause;
233 	__u8 mcn[16];
234 	__u8 isrc[16];
235 	__u8 subhdr0;
236 	__u8 subhdr1;
237 	__u8 subhdr2;
238 	__u8 subhdr3;
239 } __attribute__((packed)) write_param_page;
240 
241 struct modesel_head
242 {
243 	__u8	reserved1;
244 	__u8	medium;
245 	__u8	reserved2;
246 	__u8	block_desc_length;
247 	__u8	density;
248 	__u8	number_of_blocks_hi;
249 	__u8	number_of_blocks_med;
250 	__u8	number_of_blocks_lo;
251 	__u8	reserved3;
252 	__u8	block_length_hi;
253 	__u8	block_length_med;
254 	__u8	block_length_lo;
255 };
256 
257 typedef struct {
258 	__u16 report_key_length;
259 	__u8 reserved1;
260 	__u8 reserved2;
261 #if defined(__BIG_ENDIAN_BITFIELD)
262 	__u8 type_code			: 2;
263 	__u8 vra			: 3;
264 	__u8 ucca			: 3;
265 #elif defined(__LITTLE_ENDIAN_BITFIELD)
266 	__u8 ucca			: 3;
267 	__u8 vra			: 3;
268 	__u8 type_code			: 2;
269 #endif
270 	__u8 region_mask;
271 	__u8 rpc_scheme;
272 	__u8 reserved3;
273 } rpc_state_t;
274 
275 struct event_header {
276 	__be16 data_len;
277 #if defined(__BIG_ENDIAN_BITFIELD)
278 	__u8 nea		: 1;
279 	__u8 reserved1		: 4;
280 	__u8 notification_class	: 3;
281 #elif defined(__LITTLE_ENDIAN_BITFIELD)
282 	__u8 notification_class	: 3;
283 	__u8 reserved1		: 4;
284 	__u8 nea		: 1;
285 #endif
286 	__u8 supp_event_class;
287 };
288 
289 struct media_event_desc {
290 #if defined(__BIG_ENDIAN_BITFIELD)
291 	__u8 reserved1		: 4;
292 	__u8 media_event_code	: 4;
293 	__u8 reserved2		: 6;
294 	__u8 media_present	: 1;
295 	__u8 door_open		: 1;
296 #elif defined(__LITTLE_ENDIAN_BITFIELD)
297 	__u8 media_event_code	: 4;
298 	__u8 reserved1		: 4;
299 	__u8 door_open		: 1;
300 	__u8 media_present	: 1;
301 	__u8 reserved2		: 6;
302 #endif
303 	__u8 start_slot;
304 	__u8 end_slot;
305 };
306 
307 extern int cdrom_get_media_event(struct cdrom_device_info *cdi, struct media_event_desc *med);
308 
309 static inline void lba_to_msf(int lba, u8 *m, u8 *s, u8 *f)
310 {
311 	lba += CD_MSF_OFFSET;
312 	lba &= 0xffffff;  /* negative lbas use only 24 bits */
313 	*m = lba / (CD_SECS * CD_FRAMES);
314 	lba %= (CD_SECS * CD_FRAMES);
315 	*s = lba / CD_FRAMES;
316 	*f = lba % CD_FRAMES;
317 }
318 
319 static inline int msf_to_lba(u8 m, u8 s, u8 f)
320 {
321 	return (((m * CD_SECS) + s) * CD_FRAMES + f) - CD_MSF_OFFSET;
322 }
323 #endif  /* _LINUX_CDROM_H */
324