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