17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright (c) 1999-2001 by Sun Microsystems, Inc. 247c478bd9Sstevel@tonic-gate * All rights reserved. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _PTREE_IMPL_H 287c478bd9Sstevel@tonic-gate #define _PTREE_IMPL_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifdef __cplusplus 317c478bd9Sstevel@tonic-gate extern "C" { 327c478bd9Sstevel@tonic-gate #endif 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #include <synch.h> 357c478bd9Sstevel@tonic-gate #include <pthread.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate typedef uint64_t picl_hdl_t; 387c478bd9Sstevel@tonic-gate 397c478bd9Sstevel@tonic-gate /* 407c478bd9Sstevel@tonic-gate * Hash table size of Ptree and PICL tables 417c478bd9Sstevel@tonic-gate */ 427c478bd9Sstevel@tonic-gate #define HASH_TBL_SIZE 128 437c478bd9Sstevel@tonic-gate #define HASH_INDEX(s, x) ((int)((x) & ((s) - 1))) 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate * Invalid PICL handle 477c478bd9Sstevel@tonic-gate */ 487c478bd9Sstevel@tonic-gate #define PICL_INVALID_PICLHDL (picl_hdl_t)0 497c478bd9Sstevel@tonic-gate 507c478bd9Sstevel@tonic-gate /* 517c478bd9Sstevel@tonic-gate * Is the object PICLized? 527c478bd9Sstevel@tonic-gate */ 53*ee613b78SToomas Soome #define IS_PICLIZED(x) ((x)->picl_hdl != 0) 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate /* 567c478bd9Sstevel@tonic-gate * A handle is a 64-bit quantity with the daemon's pid value in top 32 bits 577c478bd9Sstevel@tonic-gate * and the raw handle value in the lower 32 bits. 587c478bd9Sstevel@tonic-gate */ 597c478bd9Sstevel@tonic-gate #define HASH_VAL(x) ((x) & 0xFFFFFFFF) 607c478bd9Sstevel@tonic-gate #define GET_PID(x) ((x) >> 32) 617c478bd9Sstevel@tonic-gate #define MAKE_HANDLE(x, y) (((picl_hdl_t)(x) << 32) | (y)) 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * Lock type when locking a node 657c478bd9Sstevel@tonic-gate */ 667c478bd9Sstevel@tonic-gate #define RDLOCK_NODE 1 677c478bd9Sstevel@tonic-gate #define WRLOCK_NODE 2 687c478bd9Sstevel@tonic-gate 697c478bd9Sstevel@tonic-gate /* 707c478bd9Sstevel@tonic-gate * Property access operation 717c478bd9Sstevel@tonic-gate */ 727c478bd9Sstevel@tonic-gate #define PROP_READ 1 737c478bd9Sstevel@tonic-gate #define PROP_WRITE 2 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate /* 767c478bd9Sstevel@tonic-gate * PICL object type 777c478bd9Sstevel@tonic-gate */ 787c478bd9Sstevel@tonic-gate typedef struct picl_obj picl_obj_t; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate /* 817c478bd9Sstevel@tonic-gate * Hash table structure 827c478bd9Sstevel@tonic-gate */ 837c478bd9Sstevel@tonic-gate struct hash_elem { 847c478bd9Sstevel@tonic-gate uint32_t hdl; 857c478bd9Sstevel@tonic-gate union { 867c478bd9Sstevel@tonic-gate void *data; 877c478bd9Sstevel@tonic-gate uint32_t ptreeh; 887c478bd9Sstevel@tonic-gate } u; 897c478bd9Sstevel@tonic-gate struct hash_elem *next; 907c478bd9Sstevel@tonic-gate }; 917c478bd9Sstevel@tonic-gate typedef struct hash_elem hash_elem_t; 927c478bd9Sstevel@tonic-gate #define hash_obj u.data 937c478bd9Sstevel@tonic-gate #define hash_hdl u.ptreeh 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate typedef struct { 967c478bd9Sstevel@tonic-gate int hash_size; 977c478bd9Sstevel@tonic-gate hash_elem_t **tbl; 987c478bd9Sstevel@tonic-gate } hash_t; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate /* 1017c478bd9Sstevel@tonic-gate * Property expression list 1027c478bd9Sstevel@tonic-gate */ 1037c478bd9Sstevel@tonic-gate typedef struct prop_list { 1047c478bd9Sstevel@tonic-gate char *pname; 1057c478bd9Sstevel@tonic-gate char *pval; 1067c478bd9Sstevel@tonic-gate struct prop_list *next; 1077c478bd9Sstevel@tonic-gate } prop_list_t; 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate /* 1107c478bd9Sstevel@tonic-gate * PICL property (scalar or a table entry) 1117c478bd9Sstevel@tonic-gate */ 1127c478bd9Sstevel@tonic-gate struct picl_prop { 1137c478bd9Sstevel@tonic-gate ptree_propinfo_t info; 1147c478bd9Sstevel@tonic-gate void *pvalue; 1157c478bd9Sstevel@tonic-gate picl_obj_t *nodep; /* prop's node or table */ 1167c478bd9Sstevel@tonic-gate picl_obj_t *next_in_list; 1177c478bd9Sstevel@tonic-gate picl_obj_t *next_by_row; 1187c478bd9Sstevel@tonic-gate picl_obj_t *next_by_col; 1197c478bd9Sstevel@tonic-gate }; 1207c478bd9Sstevel@tonic-gate typedef struct picl_prop picl_prop_t; 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate /* 1237c478bd9Sstevel@tonic-gate * PICL node 1247c478bd9Sstevel@tonic-gate */ 1257c478bd9Sstevel@tonic-gate struct picl_node { 1267c478bd9Sstevel@tonic-gate rwlock_t rwlock; /* protects properties */ 127*ee613b78SToomas Soome picl_obj_t *firstprop; 1287c478bd9Sstevel@tonic-gate char *classname; 1297c478bd9Sstevel@tonic-gate picl_obj_t *parent; /* protected by ptree lock */ 1307c478bd9Sstevel@tonic-gate picl_obj_t *child; /* protected by ptree lock */ 1317c478bd9Sstevel@tonic-gate picl_obj_t *sibling; /* protected by ptree lock */ 1327c478bd9Sstevel@tonic-gate }; 1337c478bd9Sstevel@tonic-gate typedef struct picl_node picl_node_t; 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate /* 1367c478bd9Sstevel@tonic-gate * PICL object types 1377c478bd9Sstevel@tonic-gate */ 1387c478bd9Sstevel@tonic-gate #define PICL_OBJ_NODE 0x1 1397c478bd9Sstevel@tonic-gate #define PICL_OBJ_PROP 0x2 1407c478bd9Sstevel@tonic-gate #define PICL_OBJ_TABLE 0x4 1417c478bd9Sstevel@tonic-gate #define PICL_OBJ_TABLEENTRY 0x8 1427c478bd9Sstevel@tonic-gate 1437c478bd9Sstevel@tonic-gate /* 1447c478bd9Sstevel@tonic-gate * PICL object 1457c478bd9Sstevel@tonic-gate */ 1467c478bd9Sstevel@tonic-gate struct picl_obj { 1477c478bd9Sstevel@tonic-gate uint32_t obj_type; 1487c478bd9Sstevel@tonic-gate picl_hdl_t ptree_hdl; /* ptree handle */ 1497c478bd9Sstevel@tonic-gate picl_hdl_t picl_hdl; /* client handle */ 1507c478bd9Sstevel@tonic-gate union { 1517c478bd9Sstevel@tonic-gate picl_node_t node; 1527c478bd9Sstevel@tonic-gate picl_prop_t prop; 1537c478bd9Sstevel@tonic-gate } u; 1547c478bd9Sstevel@tonic-gate }; 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate #define pinfo_ver u.prop.info.version 1577c478bd9Sstevel@tonic-gate #define prop_type u.prop.info.piclinfo.type 1587c478bd9Sstevel@tonic-gate #define prop_size u.prop.info.piclinfo.size 1597c478bd9Sstevel@tonic-gate #define prop_mode u.prop.info.piclinfo.accessmode 1607c478bd9Sstevel@tonic-gate #define prop_name u.prop.info.piclinfo.name 1617c478bd9Sstevel@tonic-gate #define prop_val u.prop.pvalue 1627c478bd9Sstevel@tonic-gate #define next_row u.prop.next_by_row 1637c478bd9Sstevel@tonic-gate #define next_col u.prop.next_by_col 1647c478bd9Sstevel@tonic-gate #define next_prop u.prop.next_in_list 1657c478bd9Sstevel@tonic-gate #define table_prop u.prop.next_in_list 1667c478bd9Sstevel@tonic-gate #define prop_node u.prop.nodep 1677c478bd9Sstevel@tonic-gate #define prop_table u.prop.nodep 1687c478bd9Sstevel@tonic-gate #define read_func u.prop.info.read 1697c478bd9Sstevel@tonic-gate #define write_func u.prop.info.write 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate #define first_prop u.node.firstprop 1727c478bd9Sstevel@tonic-gate #define node_lock u.node.rwlock 1737c478bd9Sstevel@tonic-gate #define child_node u.node.child 1747c478bd9Sstevel@tonic-gate #define sibling_node u.node.sibling 1757c478bd9Sstevel@tonic-gate #define parent_node u.node.parent 1767c478bd9Sstevel@tonic-gate #define node_classname u.node.classname 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate /* 1797c478bd9Sstevel@tonic-gate * PICL event queue structures 1807c478bd9Sstevel@tonic-gate */ 1817c478bd9Sstevel@tonic-gate struct eventq { 1827c478bd9Sstevel@tonic-gate const char *ename; 1837c478bd9Sstevel@tonic-gate const void *earg; 1847c478bd9Sstevel@tonic-gate size_t size; 1857c478bd9Sstevel@tonic-gate void (*completion_handler)(char *ename, void *earg, 1867c478bd9Sstevel@tonic-gate size_t size); 1877c478bd9Sstevel@tonic-gate struct eventq *next; 1887c478bd9Sstevel@tonic-gate }; 1897c478bd9Sstevel@tonic-gate typedef struct eventq eventq_t; 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate /* 1927c478bd9Sstevel@tonic-gate * Event handler list 1937c478bd9Sstevel@tonic-gate */ 1947c478bd9Sstevel@tonic-gate struct eh_list { 1957c478bd9Sstevel@tonic-gate char *ename; 1967c478bd9Sstevel@tonic-gate void *cookie; 1977c478bd9Sstevel@tonic-gate void (*evt_handler)(const char *ename, const void *earg, 1987c478bd9Sstevel@tonic-gate size_t size, void *cookie); 1997c478bd9Sstevel@tonic-gate short execflg; 2007c478bd9Sstevel@tonic-gate short wakeupflg; 2017c478bd9Sstevel@tonic-gate pthread_cond_t cv; 2027c478bd9Sstevel@tonic-gate struct eh_list *next; 2037c478bd9Sstevel@tonic-gate }; 2047c478bd9Sstevel@tonic-gate typedef struct eh_list evt_handler_t; 2057c478bd9Sstevel@tonic-gate 2067c478bd9Sstevel@tonic-gate #define SUPER_USER 0 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate #define MIN(x, y) ((x) < (y) ? (x) : (y)) 2097c478bd9Sstevel@tonic-gate 2107c478bd9Sstevel@tonic-gate typedef struct picld_plugin_reg_list { 2117c478bd9Sstevel@tonic-gate picld_plugin_reg_t reg; 2127c478bd9Sstevel@tonic-gate struct picld_plugin_reg_list *next; 2137c478bd9Sstevel@tonic-gate } picld_plugin_reg_list_t; 2147c478bd9Sstevel@tonic-gate 2157c478bd9Sstevel@tonic-gate typedef struct picld_plinfo { 2167c478bd9Sstevel@tonic-gate char *libname; 2177c478bd9Sstevel@tonic-gate char *pathname; 218*ee613b78SToomas Soome void *dlh; 2197c478bd9Sstevel@tonic-gate struct picld_plinfo *next; 2207c478bd9Sstevel@tonic-gate } picld_plugin_desc_t; 2217c478bd9Sstevel@tonic-gate 2227c478bd9Sstevel@tonic-gate extern int xptree_initialize(int); 2237c478bd9Sstevel@tonic-gate extern void xptree_destroy(void); 2247c478bd9Sstevel@tonic-gate extern int xptree_reinitialize(void); 2257c478bd9Sstevel@tonic-gate extern int xptree_refresh_notify(uint32_t secs); 2267c478bd9Sstevel@tonic-gate extern int cvt_picl2ptree(picl_hdl_t piclh, picl_hdl_t *ptreeh); 2277c478bd9Sstevel@tonic-gate extern void cvt_ptree2picl(picl_hdl_t *vbuf); 2287c478bd9Sstevel@tonic-gate extern int xptree_get_propinfo_by_name(picl_nodehdl_t nodeh, 2297c478bd9Sstevel@tonic-gate const char *pname, ptree_propinfo_t *pinfo); 2307c478bd9Sstevel@tonic-gate extern int xptree_get_propval_with_cred(picl_prophdl_t proph, void *valbuf, 2317c478bd9Sstevel@tonic-gate size_t size, door_cred_t cred); 2327c478bd9Sstevel@tonic-gate extern int xptree_get_propval_by_name_with_cred(picl_nodehdl_t nodeh, 2337c478bd9Sstevel@tonic-gate const char *propname, void *valbuf, size_t sz, 2347c478bd9Sstevel@tonic-gate door_cred_t cred); 2357c478bd9Sstevel@tonic-gate extern int xptree_update_propval_with_cred(picl_prophdl_t proph, 2367c478bd9Sstevel@tonic-gate const void *valbuf, size_t sz, door_cred_t cred); 2377c478bd9Sstevel@tonic-gate extern int xptree_update_propval_by_name_with_cred(picl_nodehdl_t nodeh, 2387c478bd9Sstevel@tonic-gate const char *propname, const void *valbuf, size_t sz, 2397c478bd9Sstevel@tonic-gate door_cred_t cred); 2407c478bd9Sstevel@tonic-gate 2417c478bd9Sstevel@tonic-gate /* 2427c478bd9Sstevel@tonic-gate * PICL daemon verbose level flag 2437c478bd9Sstevel@tonic-gate */ 2447c478bd9Sstevel@tonic-gate extern int verbose_level; 2457c478bd9Sstevel@tonic-gate extern void dbg_print(int level, const char *fmt, ...); 2467c478bd9Sstevel@tonic-gate extern void dbg_exec(int level, void (*fn)(void *), void *arg); 2477c478bd9Sstevel@tonic-gate 2487c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2497c478bd9Sstevel@tonic-gate } 2507c478bd9Sstevel@tonic-gate #endif 2517c478bd9Sstevel@tonic-gate 2527c478bd9Sstevel@tonic-gate #endif /* _PTREE_IMPL_H */ 253