13941Svenki /* 23941Svenki * CDDL HEADER START 33941Svenki * 43941Svenki * The contents of this file are subject to the terms of the 53941Svenki * Common Development and Distribution License (the "License"). 63941Svenki * You may not use this file except in compliance with the License. 73941Svenki * 83941Svenki * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 93941Svenki * or http://www.opensolaris.org/os/licensing. 103941Svenki * See the License for the specific language governing permissions 113941Svenki * and limitations under the License. 123941Svenki * 133941Svenki * When distributing Covered Code, include this CDDL HEADER in each 143941Svenki * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 153941Svenki * If applicable, add the following below this CDDL HEADER, with the 163941Svenki * fields enclosed by brackets "[]" replaced with your own identifying 173941Svenki * information: Portions Copyright [yyyy] [name of copyright owner] 183941Svenki * 193941Svenki * CDDL HEADER END 203941Svenki */ 213941Svenki 223941Svenki /* 233941Svenki * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 243941Svenki * Use is subject to license terms. 253941Svenki */ 263941Svenki 273941Svenki #pragma ident "%Z%%M% %I% %E% SMI" 283941Svenki 293941Svenki #include "priplugin.h" 303941Svenki 313941Svenki #pragma init(priplugin_register) /* place in .init section */ 323941Svenki 333941Svenki picl_nodehdl_t root_node; 343941Svenki md_t *mdp; 353941Svenki mde_cookie_t rootnode; 363941Svenki 373941Svenki void priplugin_init(void); 383941Svenki void priplugin_fini(void); 393941Svenki 403941Svenki picld_plugin_reg_t priplugin_reg = { 413941Svenki PICLD_PLUGIN_VERSION_1, 423941Svenki PICLD_PLUGIN_CRITICAL, 433941Svenki "pri_plugin", 443941Svenki priplugin_init, 453941Svenki priplugin_fini 463941Svenki }; 473941Svenki 483941Svenki void 493941Svenki set_prop_info(ptree_propinfo_t *propinfo, int size, char *name, int type) 503941Svenki { 513941Svenki propinfo->version = PICLD_PLUGIN_VERSION_1; 523941Svenki propinfo->read = NULL; 533941Svenki propinfo->write = NULL; 543941Svenki propinfo->piclinfo.type = type; 553941Svenki propinfo->piclinfo.accessmode = PICL_READ; 563941Svenki propinfo->piclinfo.size = size; 57*4003Svivek (void) strlcpy(propinfo->piclinfo.name, name, 583941Svenki sizeof (propinfo->piclinfo.name)); 593941Svenki } 603941Svenki 613941Svenki boolean_t 623941Svenki prop_exists(picl_nodehdl_t node, char *name) 633941Svenki { 643941Svenki int status; 653941Svenki picl_prophdl_t proph; 663941Svenki 673941Svenki status = ptree_get_prop_by_name(node, name, &proph); 683941Svenki if (status == PICL_SUCCESS) 693941Svenki return (B_TRUE); 703941Svenki else 713941Svenki return (B_FALSE); 723941Svenki } 733941Svenki 743941Svenki void 753941Svenki add_md_prop(picl_nodehdl_t node, int size, char *name, void* value, int type) 763941Svenki { 773941Svenki ptree_propinfo_t propinfo; 783941Svenki picl_prophdl_t proph; 793941Svenki 803941Svenki if (!prop_exists(node, name)) { 813941Svenki set_prop_info(&propinfo, size, name, type); 823941Svenki 833941Svenki (void) ptree_create_and_add_prop(node, &propinfo, 843941Svenki value, &proph); 853941Svenki } 863941Svenki } 873941Svenki 883941Svenki void 893941Svenki priplugin_init(void) 903941Svenki { 913941Svenki int status; 923941Svenki 933941Svenki pri_debug(LOG_NOTICE, "priplugin: entered\n"); 943941Svenki status = ptree_get_root(&root_node); 953941Svenki if (status != PICL_SUCCESS) { 963941Svenki pri_debug(LOG_NOTICE, "priplugin: can't get picl root node\n"); 973941Svenki return; 983941Svenki } 993941Svenki 1003941Svenki mdp = pri_devinit(); 1013941Svenki if (mdp == NULL) { 1023941Svenki pri_debug(LOG_NOTICE, "priplugin: cannot init pri: %d\n", 1033941Svenki errno); 1043941Svenki return; 1053941Svenki } 1063941Svenki 1073941Svenki rootnode = md_root_node(mdp); 1083941Svenki 1093941Svenki pri_debug(LOG_NOTICE, "priplugin: have root picl and PRI nodes\n"); 1103941Svenki 1113941Svenki status = ptree_walk_tree_by_class(root_node, "memory", 1123941Svenki "memory-segments", add_mem_prop); 1133941Svenki if (status != PICL_SUCCESS) { 1143941Svenki pri_debug(LOG_NOTICE, "pri: memory-segments walk failed\n"); 1153941Svenki } else 1163941Svenki pri_debug(LOG_NOTICE, "pri: success walking memory node\n"); 1173941Svenki 1183941Svenki io_dev_addlabel(); 1193941Svenki 1203941Svenki pri_devfini(mdp); 1213941Svenki } 1223941Svenki 1233941Svenki void 1243941Svenki priplugin_fini(void) 1253941Svenki { 1263941Svenki } 1273941Svenki 1283941Svenki void 1293941Svenki priplugin_register(void) 1303941Svenki { 1313941Svenki picld_plugin_register(&priplugin_reg); 1323941Svenki } 1333941Svenki 1343941Svenki /*VARARGS2*/ 1353941Svenki void 1363941Svenki pri_debug(int level, char *fmt, ...) 1373941Svenki { 1383941Svenki #if (PRI_DEBUG != 0) 1393941Svenki va_list ap; 1403941Svenki 1413941Svenki va_start(ap, fmt); 1423941Svenki vsyslog(level, fmt, ap); 1433941Svenki va_end(ap); 1443941Svenki #endif 1453941Svenki } 146