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