]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/ata/atapi-cd.h
Fill in missing parts of the ATAPI/CAM XPT: implement XPT_RESET_BUS
[FreeBSD/FreeBSD.git] / sys / dev / 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$
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 #define MST_TYPE_MASK_LOW       0x0f
80 #define MST_FMT_NONE            0x00
81 #define MST_DATA_120            0x01
82 #define MST_AUDIO_120           0x02
83 #define MST_COMB_120            0x03
84 #define MST_PHOTO_120           0x04
85 #define MST_DATA_80             0x05
86 #define MST_AUDIO_80            0x06
87 #define MST_COMB_80             0x07
88 #define MST_PHOTO_80            0x08
89
90 #define MST_TYPE_MASK_HIGH      0x70
91 #define MST_CDROM               0x00
92 #define MST_CDR                 0x10
93 #define MST_CDRW                0x20
94
95 #define MST_NO_DISC             0x70
96 #define MST_DOOR_OPEN           0x71
97 #define MST_FMT_ERROR           0x72
98
99 #define MST_MECH_CADDY          0
100 #define MST_MECH_TRAY           1
101 #define MST_MECH_POPUP          2
102 #define MST_MECH_CHANGER        4
103 #define MST_MECH_CARTRIDGE      5
104
105 #define MST_DLEN_32             0
106 #define MST_DLEN_16             1
107 #define MST_DLEN_24             2
108 #define MST_DLEN_24_I2S         3
109
110 #define ATAPI_CDROM_CAP_PAGE    0x2a
111
112 /* CDROM Capabilities and Mechanical Status Page */
113 struct cappage {
114     /* mode page data header */
115     u_int16_t   data_length;
116     u_int8_t    medium_type;
117
118     u_int8_t    dev_spec;
119     u_int8_t    unused[2];
120     u_int16_t   blk_desc_len;
121
122     /* capabilities page */
123     u_int8_t    page_code;
124
125     u_int8_t    param_len;
126
127 #if BYTE_ORDER == LITTLE_ENDIAN
128     u_int8_t    read_cdr        :1;     /* supports CD-R read */
129     u_int8_t    read_cdrw       :1;     /* supports CD-RW read */
130     u_int8_t    read_packet     :1;     /* supports reading packet tracks */
131     u_int8_t    read_dvdrom     :1;     /* supports DVD-ROM read */
132     u_int8_t    read_dvdr       :1;     /* supports DVD-R read */
133     u_int8_t    read_dvdram     :1;     /* supports DVD-RAM read */
134     u_int8_t    reserved2_67    :2;
135
136     u_int8_t    write_cdr       :1;     /* supports CD-R write */
137     u_int8_t    write_cdrw      :1;     /* supports CD-RW write */
138     u_int8_t    test_write      :1;     /* supports test writing */
139     u_int8_t    reserved3_3     :1;
140     u_int8_t    write_dvdr      :1;     /* supports DVD-R write */
141     u_int8_t    write_dvdram    :1;     /* supports DVD-RAM write */
142     u_int8_t    reserved3_67    :2;
143
144     u_int8_t    audio_play      :1;     /* audio play supported */
145     u_int8_t    composite       :1;     /* composite audio/video supported */
146     u_int8_t    dport1          :1;     /* digital audio on port 1 */
147     u_int8_t    dport2          :1;     /* digital audio on port 2 */
148     u_int8_t    mode2_form1     :1;     /* mode 2 form 1 (XA) read */
149     u_int8_t    mode2_form2     :1;     /* mode 2 form 2 format */
150     u_int8_t    multisession    :1;     /* multi-session photo-CD */
151     u_int8_t    burnproof       :1;     /* supports burnproof */
152
153     u_int8_t    cd_da           :1;     /* audio-CD read supported */
154     u_int8_t    cd_da_stream    :1;     /* CD-DA streaming */
155     u_int8_t    rw              :1;     /* combined R-W subchannels */
156     u_int8_t    rw_corr         :1;     /* R-W subchannel data corrected */
157     u_int8_t    c2              :1;     /* C2 error pointers supported */
158     u_int8_t    isrc            :1;     /* can return the ISRC info */
159     u_int8_t    upc             :1;     /* can return the catalog number UPC */
160     u_int8_t                    :1;
161
162     u_int8_t    lock            :1;     /* can be locked */
163     u_int8_t    locked          :1;     /* current lock state */
164     u_int8_t    prevent         :1;     /* prevent jumper installed */
165     u_int8_t    eject           :1;     /* can eject */
166     u_int8_t                    :1;
167     u_int8_t    mech            :3;     /* loading mechanism type */
168
169     u_int8_t    sep_vol         :1;     /* independent volume of channels */
170     u_int8_t    sep_mute        :1;     /* independent mute of channels */
171     u_int8_t:6;
172 #else
173     /* This is read using 16-bit stream transfers */
174     u_int8_t    reserved2_67    :2;
175     u_int8_t    read_dvdram     :1;     /* supports DVD-RAM read */
176     u_int8_t    read_dvdr       :1;     /* supports DVD-R read */
177     u_int8_t    read_dvdrom     :1;     /* supports DVD-ROM read */
178     u_int8_t    read_packet     :1;     /* supports reading packet tracks */
179     u_int8_t    read_cdrw       :1;     /* supports CD-RW read */
180     u_int8_t    read_cdr        :1;     /* supports CD-R read */
181
182     u_int8_t    reserved3_67    :2;
183     u_int8_t    write_dvdram    :1;     /* supports DVD-RAM write */
184     u_int8_t    write_dvdr      :1;     /* supports DVD-R write */
185     u_int8_t    reserved3_3     :1;
186     u_int8_t    test_write      :1;     /* supports test writing */
187     u_int8_t    write_cdrw      :1;     /* supports CD-RW write */
188     u_int8_t    write_cdr       :1;     /* supports CD-R write */
189         
190     u_int8_t    burnproof       :1;     /* supports burnproof */
191     u_int8_t    multisession    :1;     /* multi-session photo-CD */
192     u_int8_t    mode2_form2     :1;     /* mode 2 form 2 format */
193     u_int8_t    mode2_form1     :1;     /* mode 2 form 1 (XA) read */
194     u_int8_t    dport2          :1;     /* digital audio on port 2 */
195     u_int8_t    dport1          :1;     /* digital audio on port 1 */
196     u_int8_t    composite       :1;     /* composite audio/video supported */
197     u_int8_t    audio_play      :1;     /* audio play supported */
198
199     u_int8_t                    :1;
200     u_int8_t    upc             :1;     /* can return the catalog number UPC */
201     u_int8_t    isrc            :1;     /* can return the ISRC info */
202     u_int8_t    c2              :1;     /* C2 error pointers supported */
203     u_int8_t    rw_corr         :1;     /* R-W subchannel data corrected */
204     u_int8_t    rw              :1;     /* combined R-W subchannels */
205     u_int8_t    cd_da_stream    :1;     /* CD-DA streaming */
206     u_int8_t    cd_da           :1;     /* audio-CD read supported */
207
208     u_int8_t    mech            :3;     /* loading mechanism type */
209     u_int8_t                    :1;
210     u_int8_t    eject           :1;     /* can eject */
211     u_int8_t    prevent         :1;     /* prevent jumper installed */
212     u_int8_t    locked          :1;     /* current lock state */
213     u_int8_t    lock            :1;     /* can be locked */
214
215     u_int8_t:6;
216     u_int8_t    sep_mute        :1;     /* independent mute of channels */
217     u_int8_t    sep_vol         :1;     /* independent volume of channels */
218 #endif
219
220     u_int16_t   max_read_speed;         /* max raw data rate in bytes/1000 */
221     u_int16_t   max_vol_levels;         /* number of discrete volume levels */
222     u_int16_t   buf_size;               /* internal buffer size in bytes/1024 */
223     u_int16_t   cur_read_speed;         /* current data rate in bytes/1000  */
224
225     u_int8_t    reserved3;
226 #if BYTE_ORDER == LITTLE_ENDIAN
227     u_int8_t    bckf            :1;     /* data valid on failing edge of BCK */
228     u_int8_t    rch             :1;     /* high LRCK indicates left channel */
229     u_int8_t    lsbf            :1;     /* set if LSB first */
230     u_int8_t    dlen            :2;
231
232     u_int8_t                    :3;
233 #else
234     u_int8_t                    :3;
235
236     u_int8_t    dlen            :2;
237     u_int8_t    lsbf            :1;     /* set if LSB first */
238     u_int8_t    rch             :1;     /* high LRCK indicates left channel */
239     u_int8_t    bckf            :1;     /* data valid on failing edge of BCK */
240 #endif
241
242     u_int16_t   max_write_speed;        /* max raw data rate in bytes/1000 */
243     u_int16_t   cur_write_speed;        /* current data rate in bytes/1000  */
244     u_int16_t   copy_protect_rev;
245     u_int16_t   reserved4;
246 };
247
248 #define CH_READY                0
249 #define CH_LOADING              1
250 #define CH_UNLOADING            2
251 #define CH_INITIALIZING         3
252
253 #define CD_IDLE                 0
254 #define CD_AUDIO_ACTIVE         1
255 #define CD_AUDIO_SCAN           2
256 #define CD_HOST_ACTIVE          3
257 #define CD_NO_STATE             7
258
259 /* CDROM Changer mechanism status structure */
260 struct changer {
261     u_int8_t    current_slot    :5;     /* active changer slot */
262     u_int8_t    mech_state      :2;     /* current changer state */
263
264     u_int8_t    fault           :1;     /* fault in last operation */
265     u_int8_t    reserved0       :5;
266     u_int8_t    cd_state        :3;     /* current mechanism state */
267
268     u_int8_t    current_lba[3];         /* current LBA */
269     u_int8_t    slots;                  /* number of available slots */
270     u_int16_t   table_length;           /* slot table length */
271     struct {
272         u_int8_t        changed :1;     /* media has changed in this slot */
273         u_int8_t        unused  :6;
274         u_int8_t        present :1;     /* slot has a CD present */
275         u_int8_t        reserved0;
276         u_int8_t        reserved1;
277         u_int8_t        reserved2;
278     } slot[32];
279 };
280
281 /* CDROM Write Parameters Mode Page (Burners ONLY) */
282 struct write_param {
283     /* mode page data header */
284     u_int16_t   data_length;
285     u_int8_t    medium_type;
286     u_int8_t    dev_spec;
287     u_int8_t    unused[2];
288     u_int16_t   blk_desc_len;
289
290     /* write parameters page */
291     u_int8_t    page_code;
292 #define ATAPI_CDROM_WRITE_PARAMETERS_PAGE      0x05
293
294     u_int8_t    page_length;            /* 0x32 */
295     u_int8_t    write_type      :4;     /* write stream type */
296 #define CDR_WTYPE_PACKET        0x00
297 #define CDR_WTYPE_TRACK         0x01
298 #define CDR_WTYPE_SESSION       0x02
299 #define CDR_WTYPE_RAW           0x03
300
301     u_int8_t    test_write      :1;     /* test write enable */
302     u_int8_t    link_size_valid :1;
303     u_int8_t    burnproof       :1;     /* BurnProof enable */
304     u_int8_t    reserved2_7     :1;
305     u_int8_t    track_mode      :4;     /* track mode */
306 #define CDR_TMODE_AUDIO         0x00
307 #define CDR_TMODE_AUDIO_PREEMP  0x01
308 #define CDR_TMODE_ALLOW_COPY    0x02
309 #define CDR_TMODE_DATA          0x04
310 #define CDR_TMODE_QUAD_AUDIO    0x08
311
312     u_int8_t    copy            :1;     /* generation stamp */
313     u_int8_t    fp              :1;     /* fixed packet type */
314     u_int8_t    session_type    :2;     /* session type */
315 #define CDR_SESS_NONE           0x00
316 #define CDR_SESS_FINAL          0x01
317 #define CDR_SESS_RESERVED       0x02
318 #define CDR_SESS_MULTI          0x03
319
320     u_int8_t    datablock_type  :4;     /* data type code (see cdrio.h) */
321     u_int8_t    reserved4_4567  :4;
322     u_int8_t    link_size;
323     u_int8_t    reserved6;
324     u_int8_t    host_app_code   :6;     /* host application code */
325     u_int8_t    reserved7_67    :2;
326     u_int8_t    session_format;         /* session format */
327 #define CDR_SESS_CDROM          0x00
328 #define CDR_SESS_CDI            0x10
329 #define CDR_SESS_CDROM_XA       0x20
330
331     u_int8_t    reserved9;
332     u_int32_t   packet_size;            /* packet size in bytes */
333     u_int16_t   audio_pause_length;     /* audio pause length in secs */
334     u_int8_t    media_catalog_number[16];
335     u_int8_t    isr_code[16];
336     u_int8_t    sub_hdr_byte0;
337     u_int8_t    sub_hdr_byte1;
338     u_int8_t    sub_hdr_byte2;
339     u_int8_t    sub_hdr_byte3;
340     u_int8_t    vendor_specific_byte0;
341     u_int8_t    vendor_specific_byte1;
342     u_int8_t    vendor_specific_byte2;
343     u_int8_t    vendor_specific_byte3;
344 } __packed;
345
346 /* CDROM Read Track Information structure */
347 struct acd_track_info {
348     u_int16_t   data_length;
349     u_int8_t    track_number;           /* current track number */
350     u_int8_t    session_number;         /* current session number */
351     u_int8_t    reserved4;
352     u_int8_t    track_mode      :4;     /* mode of this track */
353     u_int8_t    copy            :1;     /* generation stamp */
354     u_int8_t    damage          :1;     /* damaged track */
355     u_int8_t    reserved5_67    :2;
356     u_int8_t    data_mode       :4;     /* data mode of this disc */
357     u_int8_t    fp              :1;     /* fixed packet */
358     u_int8_t    packet          :1;     /* packet track */
359     u_int8_t    blank           :1;     /* blank (empty) track */
360     u_int8_t    rt              :1;     /* reserved track */
361     u_int8_t    nwa_valid       :1;     /* next_writeable_addr field valid */
362     u_int8_t    reserved7_17    :7;
363     u_int       track_start_addr;       /* start of this track */
364     u_int       next_writeable_addr;    /* next writeable addr on this disc */
365     u_int       free_blocks;            /* free block on this disc */
366     u_int       fixed_packet_size;      /* size of packets on this track */
367     u_int       track_length;           /* length of this track */
368 };
369
370 struct acd_devlist {
371     dev_t       dev;
372     TAILQ_ENTRY(acd_devlist)    chain;          /* list management */  
373 };
374
375 /* Structure describing an ATAPI CDROM device */
376 struct acd_softc {
377     struct ata_device           *device;        /* device softc */
378     int                         lun;            /* logical device unit */
379     int                         flags;          /* device state flags */
380 #define         F_LOCKED                0x0001  /* this unit is locked */
381
382     struct bio_queue_head       queue;          /* queue of i/o requests */
383     TAILQ_HEAD(, acd_devlist)   dev_list;       /* list of "track" devices */
384     struct toc                  toc;            /* table of disc contents */
385     struct audiopage            au;             /* audio page info */
386     struct audiopage            aumask;         /* audio page mask */
387     struct cappage              cap;            /* capabilities page info */
388     struct cd_sub_channel_info  subchan;        /* subchannel info */
389     struct changer              *changer_info;  /* changer info */
390     struct acd_softc            **driver;       /* softc's of changer slots */
391     int                         slot;           /* this instance slot number */
392     time_t                      timestamp;      /* this instance timestamp */
393     int                         disk_size;      /* size of current media */
394     int                         block_size;     /* blocksize currently used */
395     struct disklabel            disklabel;      /* fake disk label */
396     struct devstat              *stats;         /* devstat entry */
397     dev_t                       dev;            /* device place holders */
398     eventhandler_tag            clone_evh;
399 };