xref: /titanic_41/usr/src/uts/common/sys/dktp/tgdk.h (revision db2bae3047e71d795bde12e3baa621f4b6cc8930)
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 /*
23  * Copyright 2008 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 #ifdef	__cplusplus
31 extern "C" {
32 #endif
33 
34 struct	tgdk_ext {
35 	unsigned	tg_rmb	: 1;
36 	unsigned	tg_rdonly  : 1;
37 	unsigned	tg_flag    : 6;
38 	char		*tg_nodetype;
39 	char		tg_ctype;
40 };
41 
42 struct	tgdk_obj {
43 	opaque_t		tg_data;
44 	struct tgdk_objops	*tg_ops;
45 	struct tgdk_ext		*tg_ext;
46 	struct tgdk_ext		tg_extblk;	/* extended blk defined	*/
47 						/* for easy of alloc	*/
48 };
49 
50 struct	tgdk_iob {
51 	struct	buf *b_bp;
52 	daddr_t	b_lblk;
53 	ssize_t	b_xfer;
54 	daddr_t	b_psec;
55 	ssize_t	b_pbytecnt;
56 	short	b_pbyteoff;
57 	short	b_flag;
58 };
59 typedef struct tgdk_iob *tgdk_iob_handle;
60 #define	IOB_BPALLOC	0x0001
61 #define	IOB_BPBUFALLOC	0x0002
62 
63 struct	tgdk_geom {
64 	int	g_cyl;
65 	int	g_acyl;
66 	int	g_head;
67 	int	g_sec;
68 	int	g_secsiz;
69 	diskaddr_t 	g_cap;
70 };
71 
72 struct	tgdk_objops {
73 	int  (*tg_init)(opaque_t, opaque_t, opaque_t, opaque_t, opaque_t,
74 	    void *);
75 	int  (*tg_free)(struct tgdk_obj *);
76 	int  (*tg_probe)(opaque_t, int);
77 	int  (*tg_attach)(opaque_t);
78 	int  (*tg_open)(opaque_t, int);
79 	int  (*tg_close)(opaque_t);
80 	int  (*tg_ioctl)(opaque_t, dev_t, int, intptr_t, int, cred_t *, int *);
81 	int  (*tg_strategy)(opaque_t, struct buf *);
82 	int  (*tg_setgeom)(opaque_t, struct tgdk_geom *);
83 	int  (*tg_getgeom)(opaque_t, struct tgdk_geom *);
84 	tgdk_iob_handle	(*tg_iob_alloc)(opaque_t, daddr_t, ssize_t, int);
85 	int  (*tg_iob_free)(opaque_t, struct tgdk_iob *);
86 	caddr_t	(*tg_iob_htoc)(opaque_t, struct tgdk_iob *);
87 	caddr_t	(*tg_iob_xfer)(opaque_t, struct tgdk_iob *, int);
88 	int  (*tg_dump)(opaque_t, struct buf *);
89 	int  (*tg_getphygeom)(opaque_t, struct tgdk_geom *);
90 	int  (*tg_set_bbhobj)(opaque_t, opaque_t);
91 	int  (*tg_check_media)(opaque_t, int *);
92 	int  (*tg_inquiry)(opaque_t, opaque_t *);
93 	void (*tg_cleanup)(struct tgdk_obj *);
94 	void *tg_resv[1];
95 };
96 
97 struct tgdk_obj *dadk_create();
98 
99 #define	TGDK_GETNODETYPE(X) (((struct tgdk_obj *)(X))->tg_ext->tg_nodetype)
100 #define	TGDK_SETNODETYPE(X, Y) \
101 	(((struct tgdk_obj *)(X))->tg_ext->tg_nodetype = (char *)(Y))
102 #define	TGDK_RMB(X) 	(((struct tgdk_obj *)(X))->tg_ext->tg_rmb)
103 #define	TGDK_RDONLY(X) 	(((struct tgdk_obj *)(X))->tg_ext->tg_rdonly)
104 #define	TGDK_GETCTYPE(X) (((struct tgdk_obj *)(X))->tg_ext->tg_ctype)
105 
106 
107 #define	TGDK_INIT(X, devp, flcobjp, queobjp, bbhobjp, lkarg) \
108 	(*((struct tgdk_obj *)(X))->tg_ops->tg_init) \
109 		(((struct tgdk_obj *)(X))->tg_data, (devp), (flcobjp), \
110 		(queobjp), (bbhobjp), (lkarg))
111 #define	TGDK_INIT_X(X, devp, flcobjp, queobjp, bbhobjp, lkarg, cbfunc, cbarg) \
112 	(*((struct tgdk_obj *)(X))->tg_ops->tg_init) \
113 		(((struct tgdk_obj *)(X))->tg_data, (devp), (flcobjp), \
114 		(queobjp), (bbhobjp), (lkarg), (cbfunc), (cbarg))
115 #define	TGDK_FREE(X) (*((struct tgdk_obj *)(X))->tg_ops->tg_free) ((X))
116 #define	TGDK_PROBE(X, WAIT) (*((struct tgdk_obj *)(X))->tg_ops->tg_probe) \
117 	(((struct tgdk_obj *)(X))->tg_data, (WAIT))
118 #define	TGDK_ATTACH(X) (*((struct tgdk_obj *)(X))->tg_ops->tg_attach) \
119 	(((struct tgdk_obj *)(X))->tg_data)
120 #define	TGDK_OPEN(X, flag) (*((struct tgdk_obj *)(X))->tg_ops->tg_open) \
121 	(((struct tgdk_obj *)(X))->tg_data, (flag))
122 #define	TGDK_CLOSE(X) (*((struct tgdk_obj *)(X))->tg_ops->tg_close) \
123 	(((struct tgdk_obj *)(X))->tg_data)
124 #define	TGDK_IOCTL(X, dev, cmd, arg, flag, cred_p, rval_p) \
125 	(*((struct tgdk_obj *)(X))->tg_ops->tg_ioctl) \
126 	(((struct tgdk_obj *)(X))->tg_data, (dev), (cmd), (arg), (flag), \
127 		(cred_p), (rval_p))
128 #define	TGDK_STRATEGY(X, bp) (*((struct tgdk_obj *)(X))->tg_ops->tg_strategy) \
129 	(((struct tgdk_obj *)(X))->tg_data, (bp))
130 #define	TGDK_GETGEOM(X, datap) (*((struct tgdk_obj *)(X))->tg_ops->tg_getgeom) \
131 	(((struct tgdk_obj *)(X))->tg_data, (datap))
132 #define	TGDK_SETGEOM(X, datap) (*((struct tgdk_obj *)(X))->tg_ops->tg_setgeom) \
133 	(((struct tgdk_obj *)(X))->tg_data, (datap))
134 #define	TGDK_IOB_ALLOC(X, logblk, xfer, sleep) \
135 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_alloc) \
136 	(((struct tgdk_obj *)(X))->tg_data, (logblk), (xfer), (sleep))
137 #define	TGDK_IOB_FREE(X, datap) \
138 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_free) \
139 	(((struct tgdk_obj *)(X))->tg_data, (datap))
140 #define	TGDK_IOB_HTOC(X, handle) \
141 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_htoc) \
142 	(((struct tgdk_obj *)(X))->tg_data, (handle))
143 #define	TGDK_IOB_RD(X, handle) \
144 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_xfer) \
145 	(((struct tgdk_obj *)(X))->tg_data, (handle), B_READ)
146 #define	TGDK_IOB_WR(X, handle) \
147 	(*((struct tgdk_obj *)(X))->tg_ops->tg_iob_xfer) \
148 	(((struct tgdk_obj *)(X))->tg_data, (handle), B_WRITE)
149 #define	TGDK_DUMP(X, bp) (*((struct tgdk_obj *)(X))->tg_ops->tg_dump) \
150 	(((struct tgdk_obj *)(X))->tg_data, (bp))
151 #define	TGDK_GETPHYGEOM(X, datap) \
152 	(*((struct tgdk_obj *)(X))->tg_ops->tg_getphygeom) \
153 	(((struct tgdk_obj *)(X))->tg_data, (datap))
154 #define	TGDK_SET_BBHOBJ(X, objp) \
155 	(*((struct tgdk_obj *)(X))->tg_ops->tg_set_bbhobj) \
156 	(((struct tgdk_obj *)(X))->tg_data, (objp))
157 #define	TGDK_CHECK_MEDIA(X, state) \
158 	(*((struct tgdk_obj *)(X))->tg_ops->tg_check_media) \
159 	(((struct tgdk_obj *)(X))->tg_data, (state))
160 #define	TGDK_INQUIRY(X, inqpp) \
161 	(*((struct tgdk_obj *)(X))->tg_ops->tg_inquiry) \
162 	(((struct tgdk_obj *)(X))->tg_data, (inqpp))
163 #define	TGDK_CLEANUP(X) (*((struct tgdk_obj *)(X))->tg_ops->tg_cleanup) ((X))
164 
165 #define	LBLK2SEC(BLK, SHF) (daddr_t)((BLK) >> (SHF))
166 
167 #define	SETBPERR	bioerror
168 
169 #define	DK_MAXRECSIZE	(256<<10)	/* maximum io record size 	*/
170 
171 #ifdef	__cplusplus
172 }
173 #endif
174 
175 #endif	/* _SYS_DKTP_TGDK_H */
176