1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright (c) 2000 by Sun Microsystems, Inc. 24*0Sstevel@tonic-gate * All rights reserved. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 28*0Sstevel@tonic-gate 29*0Sstevel@tonic-gate #include <sys/stat.h> 30*0Sstevel@tonic-gate #include <fcntl.h> 31*0Sstevel@tonic-gate #include <unistd.h> 32*0Sstevel@tonic-gate #include <stdlib.h> 33*0Sstevel@tonic-gate #include <stdio.h> 34*0Sstevel@tonic-gate #include <strings.h> 35*0Sstevel@tonic-gate #include <fcntl.h> 36*0Sstevel@tonic-gate 37*0Sstevel@tonic-gate #include <fcode/private.h> 38*0Sstevel@tonic-gate #include <fcode/log.h> 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate #include <fcdriver/fcdriver.h> 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate static void 43*0Sstevel@tonic-gate create_node(fcode_env_t *env, device_t *d) 44*0Sstevel@tonic-gate { 45*0Sstevel@tonic-gate int error; 46*0Sstevel@tonic-gate prop_t *p; 47*0Sstevel@tonic-gate instance_t *ih; 48*0Sstevel@tonic-gate char *service = FC_NEW_DEVICE; 49*0Sstevel@tonic-gate private_data_t *pd, *ppd; 50*0Sstevel@tonic-gate char *unit_str; 51*0Sstevel@tonic-gate 52*0Sstevel@tonic-gate pd = (private_data_t *)d->private; 53*0Sstevel@tonic-gate ppd = (private_data_t *)d->parent->private; 54*0Sstevel@tonic-gate 55*0Sstevel@tonic-gate ih = MYSELF; 56*0Sstevel@tonic-gate MYSELF = open_instance_chain(env, d, 0); 57*0Sstevel@tonic-gate p = lookup_package_property(env, "name", d); 58*0Sstevel@tonic-gate if (p == NULL) { 59*0Sstevel@tonic-gate forth_abort(env, "create_node: '%s' name prop not found\n", 60*0Sstevel@tonic-gate get_path(env, d)); 61*0Sstevel@tonic-gate } 62*0Sstevel@tonic-gate 63*0Sstevel@tonic-gate debug_msg(DEBUG_UPLOAD, "Create Node: %p\n", pd->node); 64*0Sstevel@tonic-gate debug_msg(DEBUG_UPLOAD, " Device Name: '%s'\n", p->data); 65*0Sstevel@tonic-gate debug_msg(DEBUG_UPLOAD, " Parent : %p\n", ppd->node); 66*0Sstevel@tonic-gate 67*0Sstevel@tonic-gate my_unit(env); 68*0Sstevel@tonic-gate (void) call_my_parent(env, "encode-unit"); 69*0Sstevel@tonic-gate unit_str = pop_a_duped_string(env, NULL); 70*0Sstevel@tonic-gate if (unit_str == NULL) { 71*0Sstevel@tonic-gate unit_str = STRDUP(""); 72*0Sstevel@tonic-gate } 73*0Sstevel@tonic-gate 74*0Sstevel@tonic-gate debug_msg(DEBUG_UPLOAD, " Unit Addr : '%s'\n", unit_str); 75*0Sstevel@tonic-gate 76*0Sstevel@tonic-gate error = fc_run_priv(pd->common, FC_NEW_DEVICE, 4, 0, 77*0Sstevel@tonic-gate fc_phandle2cell(pd->node), fc_phandle2cell(ppd->node), 78*0Sstevel@tonic-gate fc_ptr2cell(unit_str), fc_ptr2cell(p->data)); 79*0Sstevel@tonic-gate 80*0Sstevel@tonic-gate FREE(unit_str); 81*0Sstevel@tonic-gate close_instance_chain(env, MYSELF, 0); 82*0Sstevel@tonic-gate MYSELF = ih; 83*0Sstevel@tonic-gate 84*0Sstevel@tonic-gate if (error) 85*0Sstevel@tonic-gate log_message(MSG_ERROR, "%s: parent: '%s' new: '%s'\n", service, 86*0Sstevel@tonic-gate get_path(env, d->parent), p->data); 87*0Sstevel@tonic-gate } 88*0Sstevel@tonic-gate 89*0Sstevel@tonic-gate static void 90*0Sstevel@tonic-gate finish_node(fcode_env_t *env, device_t *d) 91*0Sstevel@tonic-gate { 92*0Sstevel@tonic-gate private_data_t *pd; 93*0Sstevel@tonic-gate int error; 94*0Sstevel@tonic-gate 95*0Sstevel@tonic-gate pd = (private_data_t *)d->private; 96*0Sstevel@tonic-gate 97*0Sstevel@tonic-gate debug_msg(DEBUG_UPLOAD, "Finish Node: %p\n", pd->node); 98*0Sstevel@tonic-gate 99*0Sstevel@tonic-gate error = fc_run_priv(pd->common, FC_FINISH_DEVICE, 1, 0, 100*0Sstevel@tonic-gate fc_phandle2cell(pd->node)); 101*0Sstevel@tonic-gate if (error) 102*0Sstevel@tonic-gate log_message(MSG_ERROR, "%s: failed\n", FC_FINISH_DEVICE); 103*0Sstevel@tonic-gate } 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate static void 106*0Sstevel@tonic-gate upload_properties(fcode_env_t *env, device_t *d) 107*0Sstevel@tonic-gate { 108*0Sstevel@tonic-gate prop_t *p; 109*0Sstevel@tonic-gate private_data_t *pd; 110*0Sstevel@tonic-gate int error; 111*0Sstevel@tonic-gate 112*0Sstevel@tonic-gate pd = (private_data_t *)d->private; 113*0Sstevel@tonic-gate debug_msg(DEBUG_UPLOAD, "Upload Properties: node %p upload: %d\n", 114*0Sstevel@tonic-gate pd->node, pd->upload); 115*0Sstevel@tonic-gate 116*0Sstevel@tonic-gate if (!pd->upload) 117*0Sstevel@tonic-gate return; 118*0Sstevel@tonic-gate 119*0Sstevel@tonic-gate for (p = d->properties; p; p = p->next) { 120*0Sstevel@tonic-gate DEBUGF(UPLOAD, print_property(env, p, " Upload: ")); 121*0Sstevel@tonic-gate 122*0Sstevel@tonic-gate error = fc_run_priv(pd->common, FC_CREATE_PROPERTY, 4, 0, 123*0Sstevel@tonic-gate fc_phandle2cell(pd->node), fc_int2cell(p->size), 124*0Sstevel@tonic-gate fc_ptr2cell(p->data), fc_ptr2cell(p->name)); 125*0Sstevel@tonic-gate 126*0Sstevel@tonic-gate if (error) 127*0Sstevel@tonic-gate log_message(MSG_ERROR, "%s: '%s' failed\n", 128*0Sstevel@tonic-gate FC_CREATE_PROPERTY, p->name); 129*0Sstevel@tonic-gate } 130*0Sstevel@tonic-gate } 131*0Sstevel@tonic-gate 132*0Sstevel@tonic-gate static void 133*0Sstevel@tonic-gate upload_node(fcode_env_t *env, device_t *d) 134*0Sstevel@tonic-gate { 135*0Sstevel@tonic-gate private_data_t *pd = (private_data_t *)d->private; 136*0Sstevel@tonic-gate 137*0Sstevel@tonic-gate if (pd) { 138*0Sstevel@tonic-gate debug_msg(DEBUG_UPLOAD, "Upload Node: dev: %p node: %p" 139*0Sstevel@tonic-gate " upload: %d\n", d, pd->node, pd->upload); 140*0Sstevel@tonic-gate if (pd->upload) { 141*0Sstevel@tonic-gate create_node(env, d); 142*0Sstevel@tonic-gate upload_properties(env, d); 143*0Sstevel@tonic-gate finish_node(env, d); 144*0Sstevel@tonic-gate } 145*0Sstevel@tonic-gate } else 146*0Sstevel@tonic-gate debug_msg(DEBUG_UPLOAD, "Upload Node: dev: %p NULL private\n", 147*0Sstevel@tonic-gate d); 148*0Sstevel@tonic-gate } 149*0Sstevel@tonic-gate 150*0Sstevel@tonic-gate void 151*0Sstevel@tonic-gate upload_nodes(fcode_env_t *env) 152*0Sstevel@tonic-gate { 153*0Sstevel@tonic-gate debug_msg(DEBUG_UPLOAD, "Upload Nodes: Recursing Tree\n"); 154*0Sstevel@tonic-gate recurse_tree(env, env->root_node, upload_node); 155*0Sstevel@tonic-gate } 156*0Sstevel@tonic-gate 157*0Sstevel@tonic-gate void 158*0Sstevel@tonic-gate validate_nodes(fcode_env_t *env) 159*0Sstevel@tonic-gate { 160*0Sstevel@tonic-gate int error; 161*0Sstevel@tonic-gate common_data_t *cdp = env->private; 162*0Sstevel@tonic-gate 163*0Sstevel@tonic-gate error = ioctl(cdp->fcode_fd, FC_VALIDATE); 164*0Sstevel@tonic-gate } 165*0Sstevel@tonic-gate 166*0Sstevel@tonic-gate #pragma init(_init) 167*0Sstevel@tonic-gate 168*0Sstevel@tonic-gate static void 169*0Sstevel@tonic-gate _init(void) 170*0Sstevel@tonic-gate { 171*0Sstevel@tonic-gate fcode_env_t *env = initial_env; 172*0Sstevel@tonic-gate 173*0Sstevel@tonic-gate ASSERT(env); 174*0Sstevel@tonic-gate NOTICE; 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate FORTH(0, "upload-nodes", upload_nodes); 177*0Sstevel@tonic-gate FORTH(0, "validate-nodes", validate_nodes); 178*0Sstevel@tonic-gate } 179