xref: /titanic_41/usr/src/uts/common/sys/dktp/tgdk.h (revision 6185db853e024a486ff8837e6784dd290d866112)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_DKTP_TGDK_H
28 #define	_SYS_DKTP_TGDK_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 struct	tgdk_ext {
37 	unsigned	tg_rmb	: 1;
38 	unsigned	tg_rdonly  : 1;
39 	unsigned	tg_flag    : 6;
40 	char		*tg_nodetype;
41 	char		tg_ctype;
42 };
43 
44 struct	tgdk_obj {
45 	opaque_t		tg_data;
46 	struct tgdk_objops	*tg_ops;
47 	struct tgdk_ext		*tg_ext;
48 	struct tgdk_ext		tg_extblk;	/* extended blk defined	*/
49 						/* for easy of alloc	*/
50 };
51 
52 struct	tgdk_iob {
53 	struct	buf *b_bp;
54 	daddr_t	b_lblk;
55 	ssize_t	b_xfer;
56 	daddr_t	b_psec;
57 	ssize_t	b_pbytecnt;
58 	short	b_pbyteoff;
59 	short	b_flag;
60 };
61 typedef struct tgdk_iob *tgdk_iob_handle;
62 #define	IOB_BPALLOC	0x0001
63 #define	IOB_BPBUFALLOC	0x0002
64 
65 struct	tgdk_geom {
66 	int	g_cyl;
67 	int	g_acyl;
68 	int	g_head;
69 	int	g_sec;
70 	int	g_secsiz;
71 	int	g_cap;
72 };
73 
74 struct	tgdk_objops {
75 	int  (*tg_init)(opaque_t, opaque_t, opaque_t, opaque_t, opaque_t,
76 	    void *);
77 	int  (*tg_free)(struct tgdk_obj *);
78 	int  (*tg_probe)(opaque_t, int);
79 	int  (*tg_attach)(opaque_t);
80 	int  (*tg_open)(opaque_t, int);
81 	int  (*tg_close)(opaque_t);
82 	int  (*tg_ioctl)(opaque_t, dev_t, int, intptr_t, int, cred_t *, int *);
83 	int  (*tg_strategy)(opaque_t, struct buf *);
84 	int  (*tg_setgeom)(opaque_t, struct tgdk_geom *);
85 	int  (*tg_getgeom)(opaque_t, struct tgdk_geom *);
86 	tgdk_iob_handle	(*tg_iob_alloc)(opaque_t, daddr_t, ssize_t, int);
87 	int  (*tg_iob_free)(opaque_t, struct tgdk_iob *);
88 	caddr_t	(*tg_iob_htoc)(opaque_t, struct tgdk_iob *);
89 	caddr_t	(*tg_iob_xfer)(opaque_t, struct tgdk_iob *, int);
90 	int  (*tg_dump)(opaque_t, struct buf *);
91 	int  (*tg_getphygeom)(opaque_t, struct tgdk_geom *);
92 	int  (*tg_set_bbhobj)(opaque_t, opaque_t);
93 	int  (*tg_check_media)(opaque_t, int *);
94 	int  (*tg_inquiry)(opaque_t, opaque_t *);
95 	void (*tg_cleanup)(struct tgdk_obj *);
96 	void *tg_resv[1];
97 };
98 
99 struct tgdk_obj *dadk_create();
100 
101 #define	TGDK_GETNODETYPE(X) (((struct tgdk_obj *)(X))->tg_ext->tg_nodetype)
102 #define	TGDK_SETNODETYPE(X, Y) \
103 	(((struct tgdk_obj *)(X))->tg_ext->tg_nodetype = (char *)(Y))
104 #define	TGDK_RMB(X) 	(((struct tgdk_obj *)(X))->tg_ext->tg_rmb)
105 #define	TGDK_RDONLY(X) 	(((struct tgdk_obj *)(X))->tg_ext->tg_rdonly)
106 #define	TGDK_GETCTYPE(X) (((struct tgdk_obj *)(X))->tg_ext->tg_ctype)
107 
108 
109 #define	TGDK_INIT(X, devp, flcobjp, queobjp, bbhobjp, lkarg) \
110 	(*((struct tgdk_obj *)(X))->tg_ops->tg_init) \
111 		(((struct tgdk_obj *)(X))->tg_data, (devp), (flcobjp), \
112 		(queobjp), (bbhobjp), (lkarg))
113 #define	TGDK_INIT_X(X, devp, flcobjp, queobjp, bbhobjp, lkarg, cbfunc, cbarg) \
114 	(*((struct tgdk_obj *)(X))->tg_ops->tg_init) \
115 		(((struct tgdk_obj *)(X))->tg_data, (devp), (flcobjp), \
116 		(queobjp), (bbhobjp), (lkarg), (cbfunc), (cbarg))
117 #define	TGDK_FREE(X) (*((struct tgdk_obj *)(X))->tg_ops->tg_free) ((X))
118 #define	TGDK_PROBE(X, WAIT) (*((struct tgdk_obj *)(X))->tg_ops->tg_probe) \
119 	(((struct tgdk_obj *)(X))->tg_data, (WAIT))
120 #define	TGDK_ATTACH(X) (*((struct tgdk_obj *)(X))->tg_ops->tg_attach) \
121 	(((struct tgdk_obj *)(X))->tg_data)
122 #define	TGDK_OPEN(X, flag) (*((struct tgdk_obj *)(X))->tg_ops->tg_open) \
123 	(((struct tgdk_obj *)(X))->tg_data, (flag))
124 #define	TGDK_CLOSE(X) (*((struct tgdk_obj *)(X))->tg_ops->tg_close) \
125 	(((struct tgdk_obj *)(X))->tg_data)
126 #define	TGDK_IOCTL(X, dev, cmd, arg, flag, cred_p, rval_p) \
127 	(*((struct tgdk_obj *)(X))->tg_ops->tg_ioctl) \
128 	(((struct tgdk_obj *)(X))->tg_data, (dev), (cmd), (arg), (flag), \
129 		(cred_p), (rval_p))
130 #define	TGDK_STRATEGY(X, bp) (*((struct tgdk_obj *)(X))->tg_ops->tg_strategy) \
131 	(((struct tgdk_obj *)(X))->tg_data, (bp))
132 #define	TGDK_GETGEOM(X, datap) (*((struct tgdk_obj *)(X))->tg_ops->tg_getgeom) \
133 	(((struct tgdk_obj *)(X))->tg_data, (datap))
134 #define	TGDK_SETGEOM(X, datap) (*((struct tgdk_obj *)(X))->tg_ops->tg_setgeom) \
135 	(((struct tgdk_obj *)(X))->tg_data, (datap))
136 #define	TGDK_IOB_ALLOC(X, logblk, xfer, sleep) \
137 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_alloc) \
138 	(((struct tgdk_obj *)(X))->tg_data, (logblk), (xfer), (sleep))
139 #define	TGDK_IOB_FREE(X, datap) \
140 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_free) \
141 	(((struct tgdk_obj *)(X))->tg_data, (datap))
142 #define	TGDK_IOB_HTOC(X, handle) \
143 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_htoc) \
144 	(((struct tgdk_obj *)(X))->tg_data, (handle))
145 #define	TGDK_IOB_RD(X, handle) \
146 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_xfer) \
147 	(((struct tgdk_obj *)(X))->tg_data, (handle), B_READ)
148 #define	TGDK_IOB_WR(X, handle) \
149 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_xfer) \
150 	(((struct tgdk_obj *)(X))->tg_data, (handle), B_WRITE)
151 #define	TGDK_DUMP(X, bp) (*((struct tgdk_obj *)(X))->tg_ops->tg_dump) \
152 	(((struct tgdk_obj *)(X))->tg_data, (bp))
153 #define	TGDK_GETPHYGEOM(X, datap) \
154 	(*((struct tgdk_obj *)(X))->tg_ops->tg_getphygeom) \
155 	(((struct tgdk_obj *)(X))->tg_data, (datap))
156 #define	TGDK_SET_BBHOBJ(X, objp) \
157 	(*((struct tgdk_obj *)(X))->tg_ops->tg_set_bbhobj) \
158 	(((struct tgdk_obj *)(X))->tg_data, (objp))
159 #define	TGDK_CHECK_MEDIA(X, state) \
160 	(*((struct tgdk_obj *)(X))->tg_ops->tg_check_media) \
161 	(((struct tgdk_obj *)(X))->tg_data, (state))
162 #define	TGDK_INQUIRY(X, inqpp) \
163 	(*((struct tgdk_obj *)(X))->tg_ops->tg_inquiry) \
164 	(((struct tgdk_obj *)(X))->tg_data, (inqpp))
165 #define	TGDK_CLEANUP(X) (*((struct tgdk_obj *)(X))->tg_ops->tg_cleanup) ((X))
166 
167 #define	LBLK2SEC(BLK, SHF) (daddr_t)((BLK) >> (SHF))
168 
169 #define	SETBPERR	bioerror
170 
171 #define	DK_MAXRECSIZE	(256<<10)	/* maximum io record size 	*/
172 
173 #ifdef	__cplusplus
174 }
175 #endif
176 
177 #endif	/* _SYS_DKTP_TGDK_H */
178