1 /* SPDX-License-Identifier: GPL-2.0 */
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
11 #ifndef _LINUX_CDROM_H
12 #define _LINUX_CDROM_H
14 #include <linux/fs.h> /* not really needed, later.. */
15 #include <linux/list.h>
16 #include <linux/blkdev.h>
17 #include <scsi/scsi_common.h>
18 #include <uapi/linux/cdrom.h>
22 unsigned char cmd
[CDROM_PACKET_SIZE
];
23 unsigned char *buffer
;
26 struct scsi_sense_hdr
*sshdr
;
27 unsigned char data_direction
;
34 * _OLD will use PIO transfer on atapi devices, _BPC_* will use DMA
36 #define CDDA_OLD 0 /* old style */
37 #define CDDA_BPC_SINGLE 1 /* single frame block pc */
38 #define CDDA_BPC_FULL 2 /* multi frame block pc */
40 /* Uniform cdrom data structures for cdrom.c */
41 struct cdrom_device_info
{
42 const struct cdrom_device_ops
*ops
; /* link to device_ops */
43 struct list_head list
; /* linked list of all device_info */
44 struct gendisk
*disk
; /* matching block layer disk */
45 void *handle
; /* driver-dependent data */
47 int mask
; /* mask of capability: disables them */
48 int speed
; /* maximum speed for reading data */
49 int capacity
; /* number of discs in jukebox */
50 /* device-related storage */
51 unsigned int options
: 30; /* options flags */
52 unsigned mc_flags
: 2; /* media change buffer flags */
53 unsigned int vfs_events
; /* cached events for vfs path */
54 unsigned int ioctl_events
; /* cached events for ioctl path */
55 int use_count
; /* number of times device opened */
56 char name
[20]; /* name of the device type */
57 /* per-device flags */
58 __u8 sanyo_slot
: 2; /* Sanyo 3 CD changer support */
59 __u8 keeplocked
: 1; /* CDROM_LOCKDOOR status */
60 __u8 reserved
: 5; /* not used yet */
61 int cdda_method
; /* see flags */
63 __u8 media_written
; /* dirty flag, DVD+RW bookkeeping */
64 unsigned short mmc3_profile
; /* current MMC3 profile */
65 int (*exit
)(struct cdrom_device_info
*);
68 __s64 last_media_change_ms
;
71 struct cdrom_device_ops
{
73 int (*open
) (struct cdrom_device_info
*, int);
74 void (*release
) (struct cdrom_device_info
*);
75 int (*drive_status
) (struct cdrom_device_info
*, int);
76 unsigned int (*check_events
) (struct cdrom_device_info
*cdi
,
77 unsigned int clearing
, int slot
);
78 int (*tray_move
) (struct cdrom_device_info
*, int);
79 int (*lock_door
) (struct cdrom_device_info
*, int);
80 int (*select_speed
) (struct cdrom_device_info
*, unsigned long);
81 int (*get_last_session
) (struct cdrom_device_info
*,
82 struct cdrom_multisession
*);
83 int (*get_mcn
) (struct cdrom_device_info
*,
85 /* hard reset device */
86 int (*reset
) (struct cdrom_device_info
*);
88 int (*audio_ioctl
) (struct cdrom_device_info
*,unsigned int, void *);
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 */
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
);
104 /* the general block_device operations structure: */
105 int cdrom_open(struct cdrom_device_info
*cdi
, blk_mode_t mode
);
106 void cdrom_release(struct cdrom_device_info
*cdi
);
107 int cdrom_ioctl(struct cdrom_device_info
*cdi
, struct block_device
*bdev
,
108 unsigned int cmd
, unsigned long arg
);
109 extern unsigned int cdrom_check_events(struct cdrom_device_info
*cdi
,
110 unsigned int clearing
);
112 extern int register_cdrom(struct gendisk
*disk
, struct cdrom_device_info
*cdi
);
113 extern void unregister_cdrom(struct cdrom_device_info
*cdi
);
123 extern int cdrom_get_last_written(struct cdrom_device_info
*cdi
, long *last_written
);
124 extern int cdrom_number_of_slots(struct cdrom_device_info
*cdi
);
125 extern int cdrom_mode_select(struct cdrom_device_info
*cdi
,
126 struct packet_command
*cgc
);
127 extern int cdrom_mode_sense(struct cdrom_device_info
*cdi
,
128 struct packet_command
*cgc
,
129 int page_code
, int page_control
);
130 extern void init_cdrom_command(struct packet_command
*cgc
,
131 void *buffer
, int len
, int type
);
132 extern int cdrom_dummy_generic_packet(struct cdrom_device_info
*cdi
,
133 struct packet_command
*cgc
);
135 /* The SCSI spec says there could be 256 slots. */
136 #define CDROM_MAX_SLOTS 256
138 struct cdrom_mechstat_header
{
139 #if defined(__BIG_ENDIAN_BITFIELD)
141 __u8 changer_state
: 2;
146 #elif defined(__LITTLE_ENDIAN_BITFIELD)
148 __u8 changer_state
: 2;
160 #if defined(__BIG_ENDIAN_BITFIELD)
161 __u8 disc_present
: 1;
164 #elif defined(__LITTLE_ENDIAN_BITFIELD)
167 __u8 disc_present
: 1;
172 struct cdrom_changer_info
{
173 struct cdrom_mechstat_header hdr
;
174 struct cdrom_slot slots
[CDROM_MAX_SLOTS
];
181 mechtype_individual_changer
= 4,
182 mechtype_cartridge_changer
= 5
186 #if defined(__BIG_ENDIAN_BITFIELD)
196 __u8 multi_session
: 2; /* or border, DVD */
201 __u8 data_block_type
: 4;
202 #elif defined(__LITTLE_ENDIAN_BITFIELD)
215 __u8 multi_session
: 2; /* or border, DVD */
216 __u8 data_block_type
: 4;
221 #if defined(__BIG_ENDIAN_BITFIELD)
224 #elif defined(__LITTLE_ENDIAN_BITFIELD)
238 } __attribute__((packed
)) write_param_page
;
245 __u8 block_desc_length
;
247 __u8 number_of_blocks_hi
;
248 __u8 number_of_blocks_med
;
249 __u8 number_of_blocks_lo
;
251 __u8 block_length_hi
;
252 __u8 block_length_med
;
253 __u8 block_length_lo
;
257 __u16 report_key_length
;
260 #if defined(__BIG_ENDIAN_BITFIELD)
264 #elif defined(__LITTLE_ENDIAN_BITFIELD)
274 struct event_header
{
276 #if defined(__BIG_ENDIAN_BITFIELD)
279 __u8 notification_class
: 3;
280 #elif defined(__LITTLE_ENDIAN_BITFIELD)
281 __u8 notification_class
: 3;
285 __u8 supp_event_class
;
288 struct media_event_desc
{
289 #if defined(__BIG_ENDIAN_BITFIELD)
291 __u8 media_event_code
: 4;
293 __u8 media_present
: 1;
295 #elif defined(__LITTLE_ENDIAN_BITFIELD)
296 __u8 media_event_code
: 4;
299 __u8 media_present
: 1;
306 extern int cdrom_get_media_event(struct cdrom_device_info
*cdi
, struct media_event_desc
*med
);
308 static inline void lba_to_msf(int lba
, u8
*m
, u8
*s
, u8
*f
)
310 lba
+= CD_MSF_OFFSET
;
311 lba
&= 0xffffff; /* negative lbas use only 24 bits */
312 *m
= lba
/ (CD_SECS
* CD_FRAMES
);
313 lba
%= (CD_SECS
* CD_FRAMES
);
314 *s
= lba
/ CD_FRAMES
;
315 *f
= lba
% CD_FRAMES
;
318 static inline int msf_to_lba(u8 m
, u8 s
, u8 f
)
320 return (((m
* CD_SECS
) + s
) * CD_FRAMES
+ f
) - CD_MSF_OFFSET
;
322 #endif /* _LINUX_CDROM_H */