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) 2000 by Sun Microsystems, Inc. 24*7c478bd9Sstevel@tonic-gate * All rights reserved. 25*7c478bd9Sstevel@tonic-gate */ 26*7c478bd9Sstevel@tonic-gate 27*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*7c478bd9Sstevel@tonic-gate 29*7c478bd9Sstevel@tonic-gate #include <stdio.h> 30*7c478bd9Sstevel@tonic-gate #include <unistd.h> 31*7c478bd9Sstevel@tonic-gate #include <stdlib.h> 32*7c478bd9Sstevel@tonic-gate #include <strings.h> 33*7c478bd9Sstevel@tonic-gate 34*7c478bd9Sstevel@tonic-gate #include <fcode/private.h> 35*7c478bd9Sstevel@tonic-gate #include <fcode/log.h> 36*7c478bd9Sstevel@tonic-gate 37*7c478bd9Sstevel@tonic-gate #include <fcdriver/fcdriver.h> 38*7c478bd9Sstevel@tonic-gate 39*7c478bd9Sstevel@tonic-gate 40*7c478bd9Sstevel@tonic-gate static char *prop_buf; 41*7c478bd9Sstevel@tonic-gate 42*7c478bd9Sstevel@tonic-gate static int 43*7c478bd9Sstevel@tonic-gate getproplen(common_data_t *cdp, fc_phandle_t node, char *propname, int inherit) 44*7c478bd9Sstevel@tonic-gate { 45*7c478bd9Sstevel@tonic-gate fc_cell_t len; 46*7c478bd9Sstevel@tonic-gate char *service; 47*7c478bd9Sstevel@tonic-gate int error; 48*7c478bd9Sstevel@tonic-gate 49*7c478bd9Sstevel@tonic-gate service = inherit ? FC_GET_IN_PROPLEN : FC_GET_PKG_PROPLEN; 50*7c478bd9Sstevel@tonic-gate 51*7c478bd9Sstevel@tonic-gate error = fc_run_priv(cdp, service, 2, 1, fc_phandle2cell(node), 52*7c478bd9Sstevel@tonic-gate fc_ptr2cell(propname), &len); 53*7c478bd9Sstevel@tonic-gate if (error) 54*7c478bd9Sstevel@tonic-gate return (-1); 55*7c478bd9Sstevel@tonic-gate 56*7c478bd9Sstevel@tonic-gate return (fc_cell2int(len)); 57*7c478bd9Sstevel@tonic-gate } 58*7c478bd9Sstevel@tonic-gate 59*7c478bd9Sstevel@tonic-gate static int 60*7c478bd9Sstevel@tonic-gate getprop(common_data_t *cdp, fc_phandle_t node, char *propname, char *buf, 61*7c478bd9Sstevel@tonic-gate int inherit) 62*7c478bd9Sstevel@tonic-gate { 63*7c478bd9Sstevel@tonic-gate fc_cell_t len; 64*7c478bd9Sstevel@tonic-gate char *service; 65*7c478bd9Sstevel@tonic-gate int error; 66*7c478bd9Sstevel@tonic-gate 67*7c478bd9Sstevel@tonic-gate service = inherit ? FC_GET_IN_PROP : FC_GET_PKG_PROP; 68*7c478bd9Sstevel@tonic-gate 69*7c478bd9Sstevel@tonic-gate error = fc_run_priv(cdp, service, 3, 1, fc_phandle2cell(node), 70*7c478bd9Sstevel@tonic-gate fc_ptr2cell(buf), fc_ptr2cell(propname), &len); 71*7c478bd9Sstevel@tonic-gate if (error) 72*7c478bd9Sstevel@tonic-gate return (-1); 73*7c478bd9Sstevel@tonic-gate 74*7c478bd9Sstevel@tonic-gate return (fc_cell2int(len)); 75*7c478bd9Sstevel@tonic-gate } 76*7c478bd9Sstevel@tonic-gate 77*7c478bd9Sstevel@tonic-gate int 78*7c478bd9Sstevel@tonic-gate os_get_prop_common(common_data_t *cdp, fc_phandle_t node, char *name, 79*7c478bd9Sstevel@tonic-gate int inherit, char **buf, int *len) 80*7c478bd9Sstevel@tonic-gate { 81*7c478bd9Sstevel@tonic-gate int i, j; 82*7c478bd9Sstevel@tonic-gate char *bp; 83*7c478bd9Sstevel@tonic-gate 84*7c478bd9Sstevel@tonic-gate i = getproplen(cdp, node, name, inherit); 85*7c478bd9Sstevel@tonic-gate if (i <= 0) { 86*7c478bd9Sstevel@tonic-gate /* 87*7c478bd9Sstevel@tonic-gate * OK for properties to be undefined, suppress error message 88*7c478bd9Sstevel@tonic-gate * unless some debug is on. 89*7c478bd9Sstevel@tonic-gate */ 90*7c478bd9Sstevel@tonic-gate if (get_interpreter_debug_level()) 91*7c478bd9Sstevel@tonic-gate log_message(MSG_ERROR, "os_get_prop_common:" 92*7c478bd9Sstevel@tonic-gate " getproplen(%s) returned %d\n", name, i); 93*7c478bd9Sstevel@tonic-gate return (-1); 94*7c478bd9Sstevel@tonic-gate } 95*7c478bd9Sstevel@tonic-gate bp = MALLOC(i); 96*7c478bd9Sstevel@tonic-gate 97*7c478bd9Sstevel@tonic-gate j = getprop(cdp, node, name, bp, inherit); 98*7c478bd9Sstevel@tonic-gate if (i != j) { 99*7c478bd9Sstevel@tonic-gate /* 100*7c478bd9Sstevel@tonic-gate * It's an error if getproplen succeeded but getprop didn't 101*7c478bd9Sstevel@tonic-gate * return a matching length. 102*7c478bd9Sstevel@tonic-gate */ 103*7c478bd9Sstevel@tonic-gate log_message(MSG_ERROR, "os_get_prop_common: getprop(%s)" 104*7c478bd9Sstevel@tonic-gate " return %d, getproplen returned %d\n", name, j, i); 105*7c478bd9Sstevel@tonic-gate FREE(bp); 106*7c478bd9Sstevel@tonic-gate return (-2); 107*7c478bd9Sstevel@tonic-gate } 108*7c478bd9Sstevel@tonic-gate memcpy(prop_buf, bp, i); 109*7c478bd9Sstevel@tonic-gate *buf = prop_buf; 110*7c478bd9Sstevel@tonic-gate *len = i; 111*7c478bd9Sstevel@tonic-gate FREE(bp); 112*7c478bd9Sstevel@tonic-gate return (0); 113*7c478bd9Sstevel@tonic-gate } 114*7c478bd9Sstevel@tonic-gate 115*7c478bd9Sstevel@tonic-gate static void 116*7c478bd9Sstevel@tonic-gate os_get_prop(fcode_env_t *env, int inherit, device_t *dev) 117*7c478bd9Sstevel@tonic-gate { 118*7c478bd9Sstevel@tonic-gate fc_phandle_t node; 119*7c478bd9Sstevel@tonic-gate char *name; 120*7c478bd9Sstevel@tonic-gate char *prop; 121*7c478bd9Sstevel@tonic-gate int len; 122*7c478bd9Sstevel@tonic-gate private_data_t *pd; 123*7c478bd9Sstevel@tonic-gate 124*7c478bd9Sstevel@tonic-gate ASSERT(dev); 125*7c478bd9Sstevel@tonic-gate 126*7c478bd9Sstevel@tonic-gate pd = dev->private; 127*7c478bd9Sstevel@tonic-gate ASSERT(pd); 128*7c478bd9Sstevel@tonic-gate 129*7c478bd9Sstevel@tonic-gate name = pop_a_string(env, &len); 130*7c478bd9Sstevel@tonic-gate 131*7c478bd9Sstevel@tonic-gate node = pd->node; 132*7c478bd9Sstevel@tonic-gate if (node == NULL) { 133*7c478bd9Sstevel@tonic-gate log_message(MSG_ERROR, "os_get_prop: NULL node: %s\n", 134*7c478bd9Sstevel@tonic-gate get_path(env, dev)); 135*7c478bd9Sstevel@tonic-gate PUSH(DS, TRUE); 136*7c478bd9Sstevel@tonic-gate } else if (os_get_prop_common(pd->common, node, name, inherit, &prop, 137*7c478bd9Sstevel@tonic-gate &len)) { 138*7c478bd9Sstevel@tonic-gate PUSH(DS, TRUE); 139*7c478bd9Sstevel@tonic-gate } else { 140*7c478bd9Sstevel@tonic-gate PUSH(DS, (fstack_t)prop); 141*7c478bd9Sstevel@tonic-gate PUSH(DS, len); 142*7c478bd9Sstevel@tonic-gate PUSH(DS, FALSE); 143*7c478bd9Sstevel@tonic-gate } 144*7c478bd9Sstevel@tonic-gate } 145*7c478bd9Sstevel@tonic-gate 146*7c478bd9Sstevel@tonic-gate static void 147*7c478bd9Sstevel@tonic-gate os_get_package_prop(fcode_env_t *env) 148*7c478bd9Sstevel@tonic-gate { 149*7c478bd9Sstevel@tonic-gate device_t *dev; 150*7c478bd9Sstevel@tonic-gate 151*7c478bd9Sstevel@tonic-gate CONVERT_PHANDLE(env, dev, POP(DS)); 152*7c478bd9Sstevel@tonic-gate os_get_prop(env, 0, dev); 153*7c478bd9Sstevel@tonic-gate } 154*7c478bd9Sstevel@tonic-gate 155*7c478bd9Sstevel@tonic-gate static void 156*7c478bd9Sstevel@tonic-gate os_get_inherited_prop(fcode_env_t *env) 157*7c478bd9Sstevel@tonic-gate { 158*7c478bd9Sstevel@tonic-gate os_get_prop(env, 1, env->attachment_pt); 159*7c478bd9Sstevel@tonic-gate } 160*7c478bd9Sstevel@tonic-gate 161*7c478bd9Sstevel@tonic-gate void 162*7c478bd9Sstevel@tonic-gate install_property_vectors(fcode_env_t *env, device_t *d) 163*7c478bd9Sstevel@tonic-gate { 164*7c478bd9Sstevel@tonic-gate d->vectors.get_package_prop = os_get_package_prop; 165*7c478bd9Sstevel@tonic-gate d->vectors.get_inherited_prop = os_get_inherited_prop; 166*7c478bd9Sstevel@tonic-gate } 167*7c478bd9Sstevel@tonic-gate 168*7c478bd9Sstevel@tonic-gate #pragma init(_init) 169*7c478bd9Sstevel@tonic-gate 170*7c478bd9Sstevel@tonic-gate static void 171*7c478bd9Sstevel@tonic-gate _init(void) 172*7c478bd9Sstevel@tonic-gate { 173*7c478bd9Sstevel@tonic-gate fcode_env_t *env = initial_env; 174*7c478bd9Sstevel@tonic-gate 175*7c478bd9Sstevel@tonic-gate ASSERT(env); 176*7c478bd9Sstevel@tonic-gate NOTICE; 177*7c478bd9Sstevel@tonic-gate 178*7c478bd9Sstevel@tonic-gate prop_buf = MALLOC(4096); 179*7c478bd9Sstevel@tonic-gate 180*7c478bd9Sstevel@tonic-gate } 181