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