1*3941Svenki /* 2*3941Svenki * CDDL HEADER START 3*3941Svenki * 4*3941Svenki * The contents of this file are subject to the terms of the 5*3941Svenki * Common Development and Distribution License (the "License"). 6*3941Svenki * You may not use this file except in compliance with the License. 7*3941Svenki * 8*3941Svenki * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*3941Svenki * or http://www.opensolaris.org/os/licensing. 10*3941Svenki * See the License for the specific language governing permissions 11*3941Svenki * and limitations under the License. 12*3941Svenki * 13*3941Svenki * When distributing Covered Code, include this CDDL HEADER in each 14*3941Svenki * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*3941Svenki * If applicable, add the following below this CDDL HEADER, with the 16*3941Svenki * fields enclosed by brackets "[]" replaced with your own identifying 17*3941Svenki * information: Portions Copyright [yyyy] [name of copyright owner] 18*3941Svenki * 19*3941Svenki * CDDL HEADER END 20*3941Svenki */ 21*3941Svenki 22*3941Svenki /* 23*3941Svenki * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 24*3941Svenki * Use is subject to license terms. 25*3941Svenki */ 26*3941Svenki 27*3941Svenki #pragma ident "%Z%%M% %I% %E% SMI" 28*3941Svenki 29*3941Svenki #include "priplugin.h" 30*3941Svenki 31*3941Svenki #pragma init(priplugin_register) /* place in .init section */ 32*3941Svenki 33*3941Svenki picl_nodehdl_t root_node; 34*3941Svenki md_t *mdp; 35*3941Svenki mde_cookie_t rootnode; 36*3941Svenki 37*3941Svenki void priplugin_init(void); 38*3941Svenki void priplugin_fini(void); 39*3941Svenki 40*3941Svenki picld_plugin_reg_t priplugin_reg = { 41*3941Svenki PICLD_PLUGIN_VERSION_1, 42*3941Svenki PICLD_PLUGIN_CRITICAL, 43*3941Svenki "pri_plugin", 44*3941Svenki priplugin_init, 45*3941Svenki priplugin_fini 46*3941Svenki }; 47*3941Svenki 48*3941Svenki void 49*3941Svenki set_prop_info(ptree_propinfo_t *propinfo, int size, char *name, int type) 50*3941Svenki { 51*3941Svenki propinfo->version = PICLD_PLUGIN_VERSION_1; 52*3941Svenki propinfo->read = NULL; 53*3941Svenki propinfo->write = NULL; 54*3941Svenki propinfo->piclinfo.type = type; 55*3941Svenki propinfo->piclinfo.accessmode = PICL_READ; 56*3941Svenki propinfo->piclinfo.size = size; 57*3941Svenki (void) strncpy(propinfo->piclinfo.name, name, 58*3941Svenki sizeof (propinfo->piclinfo.name)); 59*3941Svenki } 60*3941Svenki 61*3941Svenki boolean_t 62*3941Svenki prop_exists(picl_nodehdl_t node, char *name) 63*3941Svenki { 64*3941Svenki int status; 65*3941Svenki picl_prophdl_t proph; 66*3941Svenki 67*3941Svenki status = ptree_get_prop_by_name(node, name, &proph); 68*3941Svenki if (status == PICL_SUCCESS) 69*3941Svenki return (B_TRUE); 70*3941Svenki else 71*3941Svenki return (B_FALSE); 72*3941Svenki } 73*3941Svenki 74*3941Svenki void 75*3941Svenki add_md_prop(picl_nodehdl_t node, int size, char *name, void* value, int type) 76*3941Svenki { 77*3941Svenki ptree_propinfo_t propinfo; 78*3941Svenki picl_prophdl_t proph; 79*3941Svenki 80*3941Svenki if (!prop_exists(node, name)) { 81*3941Svenki set_prop_info(&propinfo, size, name, type); 82*3941Svenki 83*3941Svenki (void) ptree_create_and_add_prop(node, &propinfo, 84*3941Svenki value, &proph); 85*3941Svenki } 86*3941Svenki } 87*3941Svenki 88*3941Svenki void 89*3941Svenki priplugin_init(void) 90*3941Svenki { 91*3941Svenki int status; 92*3941Svenki 93*3941Svenki pri_debug(LOG_NOTICE, "priplugin: entered\n"); 94*3941Svenki status = ptree_get_root(&root_node); 95*3941Svenki if (status != PICL_SUCCESS) { 96*3941Svenki pri_debug(LOG_NOTICE, "priplugin: can't get picl root node\n"); 97*3941Svenki return; 98*3941Svenki } 99*3941Svenki 100*3941Svenki mdp = pri_devinit(); 101*3941Svenki if (mdp == NULL) { 102*3941Svenki pri_debug(LOG_NOTICE, "priplugin: cannot init pri: %d\n", 103*3941Svenki errno); 104*3941Svenki return; 105*3941Svenki } 106*3941Svenki 107*3941Svenki rootnode = md_root_node(mdp); 108*3941Svenki 109*3941Svenki pri_debug(LOG_NOTICE, "priplugin: have root picl and PRI nodes\n"); 110*3941Svenki 111*3941Svenki status = ptree_walk_tree_by_class(root_node, "memory", 112*3941Svenki "memory-segments", add_mem_prop); 113*3941Svenki if (status != PICL_SUCCESS) { 114*3941Svenki pri_debug(LOG_NOTICE, "pri: memory-segments walk failed\n"); 115*3941Svenki } else 116*3941Svenki pri_debug(LOG_NOTICE, "pri: success walking memory node\n"); 117*3941Svenki 118*3941Svenki io_dev_addlabel(); 119*3941Svenki 120*3941Svenki pri_devfini(mdp); 121*3941Svenki } 122*3941Svenki 123*3941Svenki void 124*3941Svenki priplugin_fini(void) 125*3941Svenki { 126*3941Svenki } 127*3941Svenki 128*3941Svenki void 129*3941Svenki priplugin_register(void) 130*3941Svenki { 131*3941Svenki picld_plugin_register(&priplugin_reg); 132*3941Svenki } 133*3941Svenki 134*3941Svenki /*VARARGS2*/ 135*3941Svenki void 136*3941Svenki pri_debug(int level, char *fmt, ...) 137*3941Svenki { 138*3941Svenki #if (PRI_DEBUG != 0) 139*3941Svenki va_list ap; 140*3941Svenki 141*3941Svenki va_start(ap, fmt); 142*3941Svenki vsyslog(level, fmt, ap); 143*3941Svenki va_end(ap); 144*3941Svenki #endif 145*3941Svenki } 146