xref: /titanic_41/usr/src/lib/efcode/packages/memalloc.c (revision e0724c534a46ca4754330bc022bf1e2a68f5bb93)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #pragma ident	"%Z%%M%	%I%	%E% SMI"
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <strings.h>
31 
32 #include <fcode/private.h>
33 #include <fcode/log.h>
34 
35 #include <fcdriver/fcdriver.h>
36 
37 /*
38  * claim under /openprom/client-services is used by schizo and oberon Fcode, we
39  * call "claim-memory" service.
40  */
41 void
42 claim(fcode_env_t *env)
43 {
44 	size_t size;
45 	void *hint;
46 	int align;
47 	fc_cell_t vaddr;
48 	int error;
49 
50 	CHECK_DEPTH(env, 3, "claim-memory");
51 	hint = (void *)POP(DS);
52 	size = POP(DS);
53 	align = POP(DS);
54 	error = fc_run_priv(env->private, "claim-memory", 3, 1,
55 	    fc_int2cell(align), fc_size2cell(size), fc_ptr2cell(hint), &vaddr);
56 	if (error)
57 		throw_from_fclib(env, 1, "client-services/claim failed\n");
58 	vaddr = mapping_to_mcookie(vaddr, size, NULL, NULL);
59 	PUSH(DS, (fstack_t)vaddr);
60 }
61 
62 void
63 release(fcode_env_t *env)
64 {
65 	size_t size;
66 	void *addr;
67 	int error;
68 
69 	CHECK_DEPTH(env, 2, "release-memory");
70 	addr = (void *)POP(DS);
71 	size = POP(DS);
72 	error = fc_run_priv(env->private, "release-memory", 2, 0,
73 	    fc_size2cell(size), fc_ptr2cell(addr));
74 	if (error)
75 		throw_from_fclib(env, 1, "client-services/release failed\n");
76 	delete_mapping((fstack_t)addr);
77 }
78 
79 static void
80 fc_vtop(fcode_env_t *env)
81 {
82 	void *vaddr;
83 	fc_cell_t physlo, physhi;
84 	int error;
85 
86 	CHECK_DEPTH(env, 1, "vtop");
87 	vaddr = (void *)POP(DS);
88 	error = fc_run_priv(env->private, "vtop", 1, 2,
89 	    fc_ptr2cell(vaddr), &physlo, &physhi);
90 	if (error)
91 		throw_from_fclib(env, 1, "fc_vtop: '>physical' failed\n");
92 
93 	PUSH(DS, physlo);
94 	PUSH(DS, physhi);
95 }
96 
97 void
98 install_openprom_nodes(fcode_env_t *env)
99 {
100 	MYSELF = open_instance_chain(env, env->root_node, 0);
101 	if (MYSELF != NULL) {
102 		make_a_node(env, "openprom", 0);
103 		make_a_node(env, "client-services", 0);
104 		FORTH(0,	"claim",	claim);
105 		FORTH(0,	"release",	release);
106 		finish_device(env);
107 		finish_device(env);
108 		close_instance_chain(env, MYSELF, 0);
109 		device_end(env);
110 		MYSELF = 0;
111 	}
112 }
113 
114 #pragma init(_init)
115 
116 static void
117 _init(void)
118 {
119 	fcode_env_t *env = initial_env;
120 
121 	ASSERT(env);
122 	NOTICE;
123 
124 	FORTH(0,	"install-openprom-nodes",	install_openprom_nodes);
125 	FORTH(0,	"claim",			claim);
126 	FORTH(0,	"release",			release);
127 	P1275(0x106,	0,	">physical",		fc_vtop);
128 }
129