xref: /illumos-gate/usr/src/uts/common/sys/mdesc.h (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
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	_MDESC_H_
28 #define	_MDESC_H_
29 
30 #include <sys/types.h>
31 
32 #ifdef __cplusplus
33 extern "C" {
34 #endif
35 
36 
37 /*
38  * Each logical domain is detailed via a (Virtual) Machine Description
39  * available to each guest Operating System courtesy of a
40  * Hypervisor service.
41  */
42 
43 
44 
45 #ifdef	_ASM
46 #define	U8(_s)	_s
47 #define	U16(_s)	_s
48 #define	U32(_s)	_s
49 #define	U64(_s)	_s
50 #else
51 #define	U8(_s)	((uint8_t)(_s))
52 #define	U16(_s)	((uint16_t)(_s))
53 #define	U32(_s)	((uint32_t)(_s))
54 #define	U64(_s)	((uint64_t)(_s))
55 #endif
56 
57 
58 
59 
60 
61 	/* the version this library understands */
62 
63 #define	MD_HEADER_VERS_OFF	0x0
64 #define	MD_HEADER_NODE_OFF	0x4
65 #define	MD_HEADER_NAME_OFF	0x8
66 #define	MD_HEADER_DATA_OFF	0xc
67 
68 #define	MD_HEADER_SIZE	0x10
69 
70 #define	MD_TRANSPORT_VERSION	U32(0x10000)
71 
72 #define	MD_ELEMENT_SIZE	0x10
73 
74 #define	MDE_ILLEGAL_IDX		U64(-1)
75 
76 #define	MDET_LIST_END	U8(0x0)
77 #define	MDET_NULL	U8(' ')
78 #define	MDET_NODE	U8('N')
79 #define	MDET_NODE_END	U8('E')
80 #define	MDET_PROP_ARC	U8('a')
81 #define	MDET_PROP_VAL	U8('v')
82 #define	MDET_PROP_STR	U8('s')
83 #define	MDET_PROP_DAT	U8('d')
84 
85 
86 #ifndef _ASM	/* { */
87 
88 /*
89  * Opaque handles for use in external interfaces
90  */
91 
92 typedef void			*md_t;
93 
94 typedef uint64_t		mde_cookie_t;
95 #define	MDE_INVAL_ELEM_COOKIE	((mde_cookie_t)-1)
96 
97 typedef	uint32_t		mde_str_cookie_t;
98 #define	MDE_INVAL_STR_COOKIE	((mde_str_cookie_t)-1)
99 
100 typedef uint64_t		md_diff_cookie_t;
101 #define	MD_INVAL_DIFF_COOKIE	((md_diff_cookie_t)-1)
102 
103 #define	MDESC_INVAL_GEN		(0)
104 
105 /*
106  * External structure for MD diff interface
107  */
108 typedef struct {
109 	uint8_t		type;		/* property type */
110 	char		*namep;		/* property name */
111 } md_prop_match_t;
112 
113 
114 /*
115  * Walk callback function return codes
116  */
117 #define	MDE_WALK_ERROR	-1	/* Terminate walk with error */
118 #define	MDE_WALK_NEXT	0	/* Continue to next node */
119 #define	MDE_WALK_DONE	1	/* Terminate walk with success */
120 
121 /*
122  * The function prototype for a walker callback function.
123  * The machine description session, parent node, current node,
124  * and private data are given to the callback.
125  *
126  * The parent node is given to the callback to provide context
127  * on how the walker arrived at this location.  While the node
128  * may have many parents, it will be visited only once, this
129  * provides context on how the walker arrived at the node.
130  *
131  * Input		Description
132  * -------------------	----------------------------------------
133  * md_t *		Pointer to md session
134  * mde_cookie_t		Index of parent node to provide context
135  * mde_cookie_t		The current node in the walk
136  * void *		Private data for the walking function
137  */
138 typedef int md_walk_fn_t(md_t *, mde_cookie_t, mde_cookie_t, void *);
139 
140 
141 /*
142  * External Interface
143  */
144 
145 extern md_t		*md_init_intern(uint64_t *,
146 				void *(*allocp)(size_t),
147 				void (*freep)(void *, size_t));
148 
149 extern int		md_fini(md_t *);
150 
151 extern int		md_node_count(md_t *);
152 
153 extern mde_str_cookie_t md_find_name(md_t *, char *namep);
154 
155 extern mde_cookie_t	md_root_node(md_t *);
156 
157 extern uint64_t		md_get_gen(md_t *);
158 
159 extern size_t		md_get_bin_size(md_t *);
160 
161 extern int		md_scan_dag(md_t *,
162 				mde_cookie_t,
163 				mde_str_cookie_t,
164 				mde_str_cookie_t,
165 				mde_cookie_t *);
166 
167 extern int		md_walk_dag(md_t *,
168 				mde_cookie_t,
169 				mde_str_cookie_t,
170 				mde_str_cookie_t,
171 				md_walk_fn_t,
172 				void *);
173 
174 extern int		md_get_prop_val(md_t *,
175 				mde_cookie_t,
176 				char *,
177 				uint64_t *);
178 
179 extern int		md_get_prop_str(md_t *,
180 				mde_cookie_t,
181 				char *,
182 				char **);
183 
184 extern int		md_get_prop_data(md_t *,
185 				mde_cookie_t,
186 				char *,
187 				uint8_t **,
188 				int *);
189 
190 extern int		md_get_prop_arcs(md_t *,
191 				mde_cookie_t,
192 				char *,
193 				mde_cookie_t *,
194 				size_t);
195 
196 
197 extern md_diff_cookie_t	md_diff_init(md_t *,
198 				mde_cookie_t,
199 				md_t *,
200 				mde_cookie_t,
201 				char *,
202 				md_prop_match_t *);
203 
204 extern int		md_diff_added(md_diff_cookie_t,
205 				mde_cookie_t **);
206 
207 extern int		md_diff_removed(md_diff_cookie_t,
208 				mde_cookie_t **);
209 
210 extern int		md_diff_matched(md_diff_cookie_t,
211 				mde_cookie_t **,
212 				mde_cookie_t **);
213 
214 extern int		md_diff_fini(md_diff_cookie_t);
215 
216 
217 #endif	/* } _ASM */
218 
219 
220 
221 /*
222  * ioctl info for mdesc device
223  */
224 
225 #define	MDESCIOC	('m' << 24 | 'd' << 16 | 'd' << 8)
226 
227 #define	MDESCIOCGSZ	(MDESCIOC | 1)   /* Get quote buffer size */
228 #define	MDESCIOCSSZ	(MDESCIOC | 2)   /* Set new quote buffer size */
229 #define	MDESCIOCDISCARD	(MDESCIOC | 3)   /* Discard quotes and reset */
230 
231 #ifdef __cplusplus
232 }
233 #endif
234 
235 #endif	/* _MDESC_H_ */
236