Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / dev / disk / ata / atapi-cd.h
1 /*-
2  * Copyright (c) 1998,1999,2000,2001,2002 Søren Schmidt <sos@FreeBSD.org>
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer,
10  *    without modification, immediately at the beginning of the file.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. The name of the author may not be used to endorse or promote products
15  *    derived from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * $FreeBSD: src/sys/dev/ata/atapi-cd.h,v 1.15.2.9 2002/03/18 08:37:34 sos Exp $
29  */
30
31 /* CDROM Table Of Contents */
32 #define MAXTRK 99
33 struct toc {
34     struct ioc_toc_header       hdr;
35     struct cd_toc_entry         tab[MAXTRK + 1];
36 };
37
38 /* DVD CSS authentication */
39 struct dvd_miscauth {
40     u_int16_t   length;
41     u_int16_t   reserved;
42     u_int8_t    data[2048];
43 };
44
45 /* CDROM Audio Control Parameters Page */
46 struct audiopage {
47     /* mode page data header */
48     u_int16_t   data_length;
49     u_int8_t    medium_type;
50     u_int8_t    dev_spec;
51     u_int8_t    unused[2];
52     u_int16_t   blk_desc_len;
53
54     /* audio control page */
55     u_int8_t    page_code;
56 #define ATAPI_CDROM_AUDIO_PAGE      0x0e
57 #define ATAPI_CDROM_AUDIO_PAGE_MASK 0x4e
58
59     u_int8_t    param_len;
60     u_int8_t    flags;
61 #define CD_PA_SOTC      0x02
62 #define CD_PA_IMMED     0x04
63
64     u_int8_t    reserved3;
65     u_int8_t    reserved4;
66     u_int8_t    reserved5;
67     u_int16_t   lb_per_sec;
68     struct port_control {
69         u_int8_t        channels:4;
70 #define CHANNEL_0       1
71 #define CHANNEL_1       2
72 #define CHANNEL_2       4
73 #define CHANNEL_3       8
74
75         u_int8_t        volume;
76     } port[4];
77 };
78
79 /* CDROM Capabilities and Mechanical Status Page */
80 struct cappage {
81     /* mode page data header */
82     u_int16_t   data_length;
83     u_int8_t    medium_type;
84 #define MST_TYPE_MASK_LOW       0x0f
85 #define MST_FMT_NONE            0x00
86 #define MST_DATA_120            0x01
87 #define MST_AUDIO_120           0x02
88 #define MST_COMB_120            0x03
89 #define MST_PHOTO_120           0x04
90 #define MST_DATA_80             0x05
91 #define MST_AUDIO_80            0x06
92 #define MST_COMB_80             0x07
93 #define MST_PHOTO_80            0x08
94
95 #define MST_TYPE_MASK_HIGH      0x70
96 #define MST_CDROM               0x00
97 #define MST_CDR                 0x10
98 #define MST_CDRW                0x20
99
100 #define MST_NO_DISC             0x70
101 #define MST_DOOR_OPEN           0x71
102 #define MST_FMT_ERROR           0x72
103
104     u_int8_t    dev_spec;
105     u_int8_t    unused[2];
106     u_int16_t   blk_desc_len;
107
108     /* capabilities page */
109     u_int8_t    page_code;
110 #define ATAPI_CDROM_CAP_PAGE    0x2a
111
112     u_int8_t    param_len;
113     u_int8_t    read_cdr        :1;     /* supports CD-R read */
114     u_int8_t    read_cdrw       :1;     /* supports CD-RW read */
115     u_int8_t    read_packet     :1;     /* supports reading packet tracks */
116     u_int8_t    read_dvdrom     :1;     /* supports DVD-ROM read */
117     u_int8_t    read_dvdr       :1;     /* supports DVD-R read */
118     u_int8_t    read_dvdram     :1;     /* supports DVD-RAM read */
119     u_int8_t    reserved2_67    :2;
120     u_int8_t    write_cdr       :1;     /* supports CD-R write */
121     u_int8_t    write_cdrw      :1;     /* supports CD-RW write */
122     u_int8_t    test_write      :1;     /* supports test writing */
123     u_int8_t    reserved3_3     :1;
124     u_int8_t    write_dvdr      :1;     /* supports DVD-R write */
125     u_int8_t    write_dvdram    :1;     /* supports DVD-RAM write */
126     u_int8_t    reserved3_67    :2;
127     u_int8_t    audio_play      :1;     /* audio play supported */
128     u_int8_t    composite       :1;     /* composite audio/video supported */
129     u_int8_t    dport1          :1;     /* digital audio on port 1 */
130     u_int8_t    dport2          :1;     /* digital audio on port 2 */
131     u_int8_t    mode2_form1     :1;     /* mode 2 form 1 (XA) read */
132     u_int8_t    mode2_form2     :1;     /* mode 2 form 2 format */
133     u_int8_t    multisession    :1;     /* multi-session photo-CD */
134     u_int8_t    burnproof       :1;     /* supports burnproof */
135     u_int8_t    cd_da           :1;     /* audio-CD read supported */
136     u_int8_t    cd_da_stream    :1;     /* CD-DA streaming */
137     u_int8_t    rw              :1;     /* combined R-W subchannels */
138     u_int8_t    rw_corr         :1;     /* R-W subchannel data corrected */
139     u_int8_t    c2              :1;     /* C2 error pointers supported */
140     u_int8_t    isrc            :1;     /* can return the ISRC info */
141     u_int8_t    upc             :1;     /* can return the catalog number UPC */
142     u_int8_t                    :1;
143     u_int8_t    lock            :1;     /* can be locked */
144     u_int8_t    locked          :1;     /* current lock state */
145     u_int8_t    prevent         :1;     /* prevent jumper installed */
146     u_int8_t    eject           :1;     /* can eject */
147     u_int8_t                    :1;
148     u_int8_t    mech            :3;     /* loading mechanism type */
149 #define MST_MECH_CADDY          0
150 #define MST_MECH_TRAY           1
151 #define MST_MECH_POPUP          2
152 #define MST_MECH_CHANGER        4
153 #define MST_MECH_CARTRIDGE      5
154
155     u_int8_t    sep_vol         :1;     /* independent volume of channels */
156     u_int8_t    sep_mute        :1;     /* independent mute of channels */
157     u_int8_t:6;
158
159     u_int16_t   max_read_speed;         /* max raw data rate in bytes/1000 */
160     u_int16_t   max_vol_levels;         /* number of discrete volume levels */
161     u_int16_t   buf_size;               /* internal buffer size in bytes/1024 */
162     u_int16_t   cur_read_speed;         /* current data rate in bytes/1000  */
163
164     u_int8_t    reserved3;
165     u_int8_t    bckf            :1;     /* data valid on failing edge of BCK */
166     u_int8_t    rch             :1;     /* high LRCK indicates left channel */
167     u_int8_t    lsbf            :1;     /* set if LSB first */
168     u_int8_t    dlen            :2;
169 #define MST_DLEN_32             0
170 #define MST_DLEN_16             1
171 #define MST_DLEN_24             2
172 #define MST_DLEN_24_I2S         3
173
174     u_int8_t                    :3;
175     u_int16_t   max_write_speed;        /* max raw data rate in bytes/1000 */
176     u_int16_t   cur_write_speed;        /* current data rate in bytes/1000  */
177     u_int16_t   copy_protect_rev;
178     u_int16_t   reserved4;
179 };
180
181 /* CDROM Changer mechanism status structure */
182 struct changer {
183     u_int8_t    current_slot    :5;     /* active changer slot */
184     u_int8_t    mech_state      :2;     /* current changer state */
185 #define CH_READY                0
186 #define CH_LOADING              1
187 #define CH_UNLOADING            2
188 #define CH_INITIALIZING         3
189
190     u_int8_t    fault           :1;     /* fault in last operation */
191     u_int8_t    reserved0       :5;
192     u_int8_t    cd_state        :3;     /* current mechanism state */
193 #define CD_IDLE                 0
194 #define CD_AUDIO_ACTIVE         1
195 #define CD_AUDIO_SCAN           2
196 #define CD_HOST_ACTIVE          3
197 #define CD_NO_STATE             7
198
199     u_int8_t    current_lba[3];         /* current LBA */
200     u_int8_t    slots;                  /* number of available slots */
201     u_int16_t   table_length;           /* slot table length */
202     struct {
203         u_int8_t        changed :1;     /* media has changed in this slot */
204         u_int8_t        unused  :6;
205         u_int8_t        present :1;     /* slot has a CD present */
206         u_int8_t        reserved0;
207         u_int8_t        reserved1;
208         u_int8_t        reserved2;
209     } slot[32];
210 };
211
212 /* CDROM Write Parameters Mode Page (Burners ONLY) */
213 struct write_param {
214     /* mode page data header */
215     u_int16_t   data_length;
216     u_int8_t    medium_type;
217     u_int8_t    dev_spec;
218     u_int8_t    unused[2];
219     u_int16_t   blk_desc_len;
220
221     /* write parameters page */
222     u_int8_t    page_code;
223 #define ATAPI_CDROM_WRITE_PARAMETERS_PAGE      0x05
224
225     u_int8_t    page_length;            /* 0x32 */
226     u_int8_t    write_type      :4;     /* write stream type */
227 #define CDR_WTYPE_PACKET        0x00
228 #define CDR_WTYPE_TRACK         0x01
229 #define CDR_WTYPE_SESSION       0x02
230 #define CDR_WTYPE_RAW           0x03
231
232     u_int8_t    test_write      :1;     /* test write enable */
233     u_int8_t    reserved2_5     :1;
234     u_int8_t    burnproof       :1;     /* BurnProof enable */
235     u_int8_t    reserved2_7     :1;
236     u_int8_t    track_mode      :4;     /* track mode */
237 #define CDR_TMODE_AUDIO         0x00
238 #define CDR_TMODE_AUDIO_PREEMP  0x01
239 #define CDR_TMODE_ALLOW_COPY    0x02
240 #define CDR_TMODE_DATA          0x04
241 #define CDR_TMODE_QUAD_AUDIO    0x08
242
243     u_int8_t    copy            :1;     /* generation stamp */
244     u_int8_t    fp              :1;     /* fixed packet type */
245     u_int8_t    session_type    :2;     /* session type */
246 #define CDR_SESS_NONE           0x00
247 #define CDR_SESS_FINAL          0x01
248 #define CDR_SESS_RESERVED       0x02
249 #define CDR_SESS_MULTI          0x03
250
251     u_int8_t    datablock_type  :4;     /* data type code (see cdrio.h) */
252     u_int8_t    reserved4_4567  :4;
253     u_int8_t    reserved5;
254     u_int8_t    reserved6;
255     u_int8_t    host_app_code   :6;     /* host application code */
256     u_int8_t    reserved7_67    :2;
257     u_int8_t    session_format;         /* session format */
258 #define CDR_SESS_CDROM          0x00
259 #define CDR_SESS_CDI            0x10
260 #define CDR_SESS_CDROM_XA       0x20
261
262     u_int8_t    reserved9;
263     u_int32_t   packet_size;            /* packet size in bytes */
264     u_int16_t   audio_pause_length;     /* audio pause length in secs */
265     u_int8_t    media_catalog_number[16];
266     u_int8_t    isr_code[16];
267     u_int8_t    sub_hdr_byte0;
268     u_int8_t    sub_hdr_byte1;
269     u_int8_t    sub_hdr_byte2;
270     u_int8_t    sub_hdr_byte3;
271     u_int8_t    vendor_specific_byte0;
272     u_int8_t    vendor_specific_byte1;
273     u_int8_t    vendor_specific_byte2;
274     u_int8_t    vendor_specific_byte3;
275 } __attribute__((packed));
276
277 /* CDROM Read Track Information structure */
278 struct acd_track_info {
279     u_int16_t   data_length;
280     u_int8_t    track_number;           /* current track number */
281     u_int8_t    session_number;         /* current session number */
282     u_int8_t    reserved4;
283     u_int8_t    track_mode      :4;     /* mode of this track */
284     u_int8_t    copy            :1;     /* generation stamp */
285     u_int8_t    damage          :1;     /* damaged track */
286     u_int8_t    reserved5_67    :2;
287     u_int8_t    data_mode       :4;     /* data mode of this disc */
288     u_int8_t    fp              :1;     /* fixed packet */
289     u_int8_t    packet          :1;     /* packet track */
290     u_int8_t    blank           :1;     /* blank (empty) track */
291     u_int8_t    rt              :1;     /* reserved track */
292     u_int8_t    nwa_valid       :1;     /* next_writeable_addr field valid */
293     u_int8_t    reserved7_17    :7;
294     u_int       track_start_addr;       /* start of this track */
295     u_int       next_writeable_addr;    /* next writeable addr on this disc */
296     u_int       free_blocks;            /* free block on this disc */
297     u_int       fixed_packet_size;      /* size of packets on this track */
298     u_int       track_length;           /* length of this track */
299 };
300
301 struct acd_devlist {
302     dev_t       dev;
303     TAILQ_ENTRY(acd_devlist)    chain;          /* list management */  
304 };
305
306 /* Structure describing an ATAPI CDROM device */
307 struct acd_softc {
308     struct ata_device           *device;        /* device softc */
309     int                         lun;            /* logical device unit */
310     int                         flags;          /* device state flags */
311 #define         F_LOCKED                0x0001  /* this unit is locked */
312
313     struct buf_queue_head       queue;          /* queue of i/o requests */
314     TAILQ_HEAD(, acd_devlist)   dev_list;       /* list of "track" devices */
315     struct toc                  toc;            /* table of disc contents */
316     struct audiopage            au;             /* audio page info */
317     struct audiopage            aumask;         /* audio page mask */
318     struct cappage              cap;            /* capabilities page info */
319     struct cd_sub_channel_info  subchan;        /* subchannel info */
320     struct changer              *changer_info;  /* changer info */
321     struct acd_softc            **driver;       /* softc's of changer slots */
322     int                         slot;           /* this instance slot number */
323     time_t                      timestamp;      /* this instance timestamp */
324     int                         disk_size;      /* size of current media */
325     int                         block_size;     /* blocksize currently used */
326     struct disklabel            disklabel;      /* fake disk label */
327     struct devstat              *stats;         /* devstat entry */
328     dev_t                       dev;            /* device place holders */
329 };