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
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]
23 * Copyright (c) 1999 by Sun Microsystems, Inc.
24 * All rights reserved.
27 #pragma ident "%Z%%M% %I% %E% SMI"
32 #include <fcode/private.h>
33 #include <fcode/log.h>
35 #include <fcdriver/fcdriver.h>
38 static int use_os_handle
= 1;
41 do_use_os_handles(fcode_env_t
*env
)
47 do_use_fake_handles(fcode_env_t
*env
)
49 log_message(MSG_ERROR
, "WARNING: using fake phandles, test only\n");
54 match_nodeid(void *s
, void *d
)
57 my_nodeid_t
*dest
= d
;
58 return ((src
->node
) == (dest
->node
));
62 match_handle(void *s
, void *d
)
65 my_nodeid_t
*dest
= d
;
66 return ((src
->my_handle
) == (dest
->my_handle
));
70 * Convert from an OS phandle to an interpreter phandle
73 convert_phandle(fcode_env_t
*env
, fstack_t d
)
76 common_data_t
*cdp
= env
->private;
81 nh
.my_handle
= (fc_phandle_t
) d
;
82 t
= find_resource(&cdp
->nodeids
, &nh
, match_handle
);
86 my_nodeid_t
*p
= (my_nodeid_t
*) t
->data
;
87 r
= (device_t
*) p
->node
;
95 * Interpreter phandle to OS phandle
98 revert_phandle(fcode_env_t
*env
, device_t
*d
)
101 common_data_t
*cdp
= env
->private;
107 t
= find_resource(&cdp
->nodeids
, &nh
, match_nodeid
);
111 my_nodeid_t
*p
= (my_nodeid_t
*) t
->data
;
112 r
= (fstack_t
) p
->my_handle
;
120 add_my_handle(fcode_env_t
*env
, fc_phandle_t mh
, device_t
*d
)
123 common_data_t
*cdp
= env
->private;
125 nh
= MALLOC(sizeof (my_nodeid_t
));
128 if (add_resource(&cdp
->nodeids
, nh
, match_handle
) == NULL
) {
129 log_message(MSG_ERROR
, "add_my_handle: add_resource failed\n");
134 allocate_phandle(fcode_env_t
*env
)
143 if ((cdp
= env
->private) == NULL
) {
144 log_message(MSG_ERROR
, "allocate_phandle: NULL common\n");
151 current
= MYSELF
->device
;
154 if (cdp
->first_node
) {
155 service
= FC_CONFIG_CHILD
;
158 service
= FC_ALLOC_PHANDLE
;
161 pd
= MALLOC(sizeof (private_data_t
));
163 pd
->parent
= (fc_phandle_t
) revert_phandle(env
, current
->parent
);
164 pd
->upload
= (cdp
->init_done
== 1);
165 current
->private = pd
;
167 error
= fc_run_priv(cdp
, service
, 0, 1, &hcell
);
169 pd
->node
= fc_cell2phandle(hcell
);
171 add_my_handle(env
, pd
->node
, current
);
175 fc_get_ap(common_data_t
*cdp
)
180 error
= fc_run_priv(cdp
, FC_AP_PHANDLE
, 0, 1, &hcell
);
185 return (fc_cell2phandle(hcell
));
194 fcode_env_t
*env
= initial_env
;
199 env
->convert_phandle
= convert_phandle
;
200 env
->revert_phandle
= revert_phandle
;
201 env
->allocate_phandle
= allocate_phandle
;
202 FORTH(0, "use-os-handles", do_use_os_handles
);
203 FORTH(0, "use-fake-handles", do_use_fake_handles
);