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