xref: /titanic_44/usr/src/lib/libpicltree/ptree_impl.h (revision 0ba2cbe97e0678a691742f98d2532caed0a2c4aa)
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 (c) 1999-2001 by Sun Microsystems, Inc.
24  * All rights reserved.
25  */
26 
27 #ifndef	_PTREE_IMPL_H
28 #define	_PTREE_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #include <synch.h>
37 #include <pthread.h>
38 
39 typedef uint64_t picl_hdl_t;
40 
41 /*
42  * Hash table size of Ptree and PICL tables
43  */
44 #define	HASH_TBL_SIZE		128
45 #define	HASH_INDEX(s, x)	((int)((x) & ((s) - 1)))
46 
47 /*
48  * Invalid PICL handle
49  */
50 #define	PICL_INVALID_PICLHDL	(picl_hdl_t)0
51 
52 /*
53  * Is the object PICLized?
54  */
55 #define	IS_PICLIZED(x)		((x)->picl_hdl != NULL)
56 
57 /*
58  * A handle is a 64-bit quantity with the daemon's pid value in top 32 bits
59  * and the raw handle value in the lower 32 bits.
60  */
61 #define	HASH_VAL(x)		((x) & 0xFFFFFFFF)
62 #define	GET_PID(x)		((x) >> 32)
63 #define	MAKE_HANDLE(x, y)	(((picl_hdl_t)(x) << 32) | (y))
64 
65 /*
66  * Lock type when locking a node
67  */
68 #define	RDLOCK_NODE		1
69 #define	WRLOCK_NODE		2
70 
71 /*
72  * Property access operation
73  */
74 #define	PROP_READ		1
75 #define	PROP_WRITE		2
76 
77 /*
78  * PICL object type
79  */
80 typedef	struct picl_obj		picl_obj_t;
81 
82 /*
83  * Hash table structure
84  */
85 struct hash_elem {
86 	uint32_t		hdl;
87 	union {
88 		void		*data;
89 		uint32_t	ptreeh;
90 	} u;
91 	struct hash_elem	*next;
92 };
93 typedef	struct hash_elem	hash_elem_t;
94 #define	hash_obj	u.data
95 #define	hash_hdl	u.ptreeh
96 
97 typedef struct {
98 	int		hash_size;
99 	hash_elem_t	**tbl;
100 } hash_t;
101 
102 /*
103  * Property expression list
104  */
105 typedef struct prop_list {
106 	char			*pname;
107 	char			*pval;
108 	struct prop_list	*next;
109 } prop_list_t;
110 
111 /*
112  * PICL property (scalar or a table entry)
113  */
114 struct picl_prop {
115 	ptree_propinfo_t	info;
116 	void			*pvalue;
117 	picl_obj_t		*nodep;		/* prop's node or table */
118 	picl_obj_t		*next_in_list;
119 	picl_obj_t		*next_by_row;
120 	picl_obj_t		*next_by_col;
121 };
122 typedef	struct picl_prop	picl_prop_t;
123 
124 /*
125  * PICL node
126  */
127 struct picl_node {
128 	rwlock_t	rwlock;		/* protects properties */
129 	picl_obj_t  	*firstprop;
130 	char		*classname;
131 	picl_obj_t	*parent;	/* protected by ptree lock */
132 	picl_obj_t	*child;		/* protected by ptree lock */
133 	picl_obj_t	*sibling;	/* protected by ptree lock */
134 };
135 typedef struct picl_node	picl_node_t;
136 
137 /*
138  * PICL object types
139  */
140 #define	PICL_OBJ_NODE		0x1
141 #define	PICL_OBJ_PROP		0x2
142 #define	PICL_OBJ_TABLE		0x4
143 #define	PICL_OBJ_TABLEENTRY	0x8
144 
145 /*
146  * PICL object
147  */
148 struct picl_obj {
149 	uint32_t	obj_type;
150 	picl_hdl_t	ptree_hdl;		/* ptree handle */
151 	picl_hdl_t	picl_hdl;		/* client handle */
152 	union {
153 		picl_node_t	node;
154 		picl_prop_t	prop;
155 	} u;
156 };
157 
158 #define	pinfo_ver	u.prop.info.version
159 #define	prop_type	u.prop.info.piclinfo.type
160 #define	prop_size	u.prop.info.piclinfo.size
161 #define	prop_mode	u.prop.info.piclinfo.accessmode
162 #define	prop_name	u.prop.info.piclinfo.name
163 #define	prop_val	u.prop.pvalue
164 #define	next_row	u.prop.next_by_row
165 #define	next_col	u.prop.next_by_col
166 #define	next_prop	u.prop.next_in_list
167 #define	table_prop	u.prop.next_in_list
168 #define	prop_node	u.prop.nodep
169 #define	prop_table	u.prop.nodep
170 #define	read_func	u.prop.info.read
171 #define	write_func	u.prop.info.write
172 
173 #define	first_prop	u.node.firstprop
174 #define	node_lock	u.node.rwlock
175 #define	child_node	u.node.child
176 #define	sibling_node	u.node.sibling
177 #define	parent_node	u.node.parent
178 #define	node_classname	u.node.classname
179 
180 /*
181  * PICL event queue structures
182  */
183 struct eventq {
184 	const char		*ename;
185 	const void		*earg;
186 	size_t		size;
187 	void		(*completion_handler)(char *ename, void *earg,
188 			    size_t size);
189 	struct eventq	*next;
190 };
191 typedef struct eventq	eventq_t;
192 
193 /*
194  * Event handler list
195  */
196 struct eh_list {
197 	char		*ename;
198 	void		*cookie;
199 	void		(*evt_handler)(const char *ename, const void *earg,
200 			    size_t size, void *cookie);
201 	short		execflg;
202 	short		wakeupflg;
203 	pthread_cond_t	cv;
204 	struct eh_list	*next;
205 };
206 typedef struct eh_list	evt_handler_t;
207 
208 #define	SUPER_USER		0
209 
210 #define	MIN(x, y)		((x) < (y) ? (x) : (y))
211 
212 typedef struct picld_plugin_reg_list {
213 	picld_plugin_reg_t		reg;
214 	struct picld_plugin_reg_list	*next;
215 } picld_plugin_reg_list_t;
216 
217 typedef struct picld_plinfo {
218 	char			*libname;
219 	char			*pathname;
220 	void 			*dlh;
221 	struct picld_plinfo	*next;
222 } picld_plugin_desc_t;
223 
224 extern	int	xptree_initialize(int);
225 extern	void	xptree_destroy(void);
226 extern	int	xptree_reinitialize(void);
227 extern	int	xptree_refresh_notify(uint32_t secs);
228 extern	int	cvt_picl2ptree(picl_hdl_t piclh, picl_hdl_t *ptreeh);
229 extern	void	cvt_ptree2picl(picl_hdl_t *vbuf);
230 extern	int	xptree_get_propinfo_by_name(picl_nodehdl_t nodeh,
231 			const char *pname, ptree_propinfo_t *pinfo);
232 extern	int	xptree_get_propval_with_cred(picl_prophdl_t proph, void *valbuf,
233 			size_t size, door_cred_t cred);
234 extern	int	xptree_get_propval_by_name_with_cred(picl_nodehdl_t nodeh,
235 			const char *propname, void *valbuf, size_t sz,
236 			door_cred_t cred);
237 extern	int	xptree_update_propval_with_cred(picl_prophdl_t proph,
238 			const void *valbuf, size_t sz, door_cred_t cred);
239 extern	int	xptree_update_propval_by_name_with_cred(picl_nodehdl_t nodeh,
240 			const char *propname, const void *valbuf, size_t sz,
241 			door_cred_t cred);
242 
243 /*
244  * PICL daemon verbose level flag
245  */
246 extern	int	verbose_level;
247 extern	void	dbg_print(int level, const char *fmt, ...);
248 extern	void	dbg_exec(int level, void (*fn)(void *), void *arg);
249 
250 #ifdef	__cplusplus
251 }
252 #endif
253 
254 #endif	/* _PTREE_IMPL_H */
255