xref: /titanic_41/usr/src/cmd/cdrw/misc_scsi.h (revision 4445fffbbb1ea25fd0e9ea68b9380dd7a6709025)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_MISC_SCSI_H
27 #define	_MISC_SCSI_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include "device.h"
36 
37 struct track_info {
38 	uint32_t ti_flags;		/* flags, see below */
39 	int ti_track_no;		/* Track number */
40 	int ti_session_no;		/* session no. 0 if cannot find that */
41 	uchar_t ti_track_mode;		/* track ctrl nibble, see READ TOC */
42 	uchar_t ti_data_mode;		/* Mode 0,1,2 or FF */
43 	uint32_t ti_start_address;	/* Start LBA */
44 	uint32_t ti_track_size;		/* Size in blocks */
45 	uint32_t ti_packet_size;	/* If a packet written track */
46 	uint32_t ti_free_blocks;	/* For an incomplete track */
47 	uint32_t ti_lra;		/* LBA of Last written user datablock */
48 	uint32_t ti_nwa;		/* Next writable address */
49 };
50 
51 /*
52  * track_info_flags
53  */
54 #define	TI_FIXED_PACKET		1
55 #define	TI_PACKET_MODE		2
56 #define	TI_BLANK_TRACK		4
57 #define	TI_RESERVED_TRACK	8
58 #define	TI_COPY			0x10
59 #define	TI_DAMAGED_TRACK	0x20
60 #define	TI_NWA_VALID		0x100
61 #define	TI_LRA_VALID		0x200
62 #define	TI_SESSION_NO_VALID	0x1000
63 #define	TI_FREE_BLOCKS_VALID	0x2000
64 
65 /*
66  * Track mode nibble
67  */
68 #define	TRACK_MODE_DATA		0x06
69 #define	TRACK_MODE_AUDIO	0x02
70 
71 /* 74 minutes, each second is 75 blocks */
72 #define	MAX_CD_BLKS		(74*60*75)
73 #define	MAX_DVD_BLKS		2295100
74 
75 /*
76  * Macros to translate between a bandwidth ("RATE") and a Speed ("X")
77  * for CDs.  Eg, "1X == 176,400 bytes/second".
78  *
79  * Some devices just multiply speed by 176. But more accurate ones
80  * multiply speed by 176.4.
81  */
82 #define	CD_RATE_TO_X(r) ((r) % 176 ? ((uint_t)(((double)(r)*10)/1764 + 0.5)) :\
83 		(r) / 176)
84 #define	CD_X_TO_RATE(s)	((((s)*1764)+5)/10)
85 
86 /*
87  * Macros to translate between a bandwidth ("RATE") and a Speed ("X")
88  * for DVDs. Eg, "1X == 1,385,000 bytes/second".
89  */
90 #define	DVD_RATE_TO_X(r)	(((ulong_t)(r)*1000)/1385000)
91 #define	DVD_X_TO_RATE(s)	(((s)*1385000)/1000)
92 
93 
94 #define	FINALIZE_TIMEOUT		(6 * 12)	/* Six minutes */
95 
96 uint32_t read_scsi32(void *addr);
97 uint16_t read_scsi16(void *addr);
98 void load_scsi32(void *addr, uint32_t val);
99 void load_scsi16(void *addr, uint16_t val);
100 
101 int get_mode_page(int fd, int page_no, int pc, int buf_len, uchar_t *buffer);
102 int set_mode_page(int fd, uchar_t *buffer);
103 int build_track_info(cd_device *dev, int trackno, struct track_info *t_info);
104 uchar_t get_data_mode(int fd, uint32_t lba);
105 int prepare_for_write(cd_device *dev, int track_mode, int test_write,
106     int keep_disc_open);
107 int finalize(cd_device *dev);
108 uint32_t get_last_possible_lba(cd_device *dev);
109 int read_audio_through_read_cd(cd_device *dev, uint_t start_lba, uint_t nblks,
110     uchar_t *buf);
111 int eject_media(cd_device *dev);
112 int cd_speed_ctrl(cd_device *dev, int cmd, int speed);
113 int rt_streaming_ctrl(cd_device *dev, int cmd, int speed);
114 
115 void tao_init(int mode);
116 void tao_fini(void);
117 void write_init(int mode);
118 void write_fini(void);
119 
120 #ifdef	__cplusplus
121 }
122 #endif
123 
124 #endif /* _MISC_SCSI_H */
125