xref: /titanic_52/usr/src/lib/efcode/packages/memalloc.c (revision fb3fb4f3d76d55b64440afd0af72775dfad3bd1d)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
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.
13  *
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]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1999-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <strings.h>
32 
33 #include <fcode/private.h>
34 #include <fcode/log.h>
35 
36 #include <fcdriver/fcdriver.h>
37 
38 static void schizo_vtop(fcode_env_t *, fc_cell_t, fstack_t *, fstack_t *);
39 
40 /*
41  * claim under /openprom/client-services is only used by schizo Fcode, we
42  * call "schizo,claim-memory" service.
43  */
44 void
45 claim(fcode_env_t *env)
46 {
47 	size_t size;
48 	void *hint;
49 	int align;
50 	fc_cell_t vaddr;
51 	int error;
52 
53 	CHECK_DEPTH(env, 3, "schizo,claim-memory");
54 	hint = (void *)POP(DS);
55 	size = POP(DS);
56 	align = POP(DS);
57 	error = fc_run_priv(env->private, "schizo,claim-memory", 3, 1,
58 	    fc_int2cell(align), fc_size2cell(size), fc_ptr2cell(hint), &vaddr);
59 	if (error)
60 		throw_from_fclib(env, 1, "client-services/claim failed\n");
61 	vaddr = mapping_to_mcookie(vaddr, size, NULL, NULL);
62 	PUSH(DS, (fstack_t)vaddr);
63 }
64 
65 void
66 release(fcode_env_t *env)
67 {
68 	size_t size;
69 	void *addr;
70 	int error;
71 
72 	CHECK_DEPTH(env, 2, "schizo,release-memory");
73 	addr = (void *)POP(DS);
74 	size = POP(DS);
75 	error = fc_run_priv(env->private, "schizo,release-memory", 2, 0,
76 	    fc_size2cell(size), fc_ptr2cell(addr));
77 	if (error)
78 		throw_from_fclib(env, 1, "client-services/release failed\n");
79 	delete_mapping((fstack_t)addr);
80 }
81 
82 static void
83 fc_vtop(fcode_env_t *env)
84 {
85 	void *vaddr;
86 	fc_cell_t physlo, physhi;
87 	int error;
88 
89 	CHECK_DEPTH(env, 1, "schizo,vtop");
90 	vaddr = (void *)POP(DS);
91 	error = fc_run_priv(env->private, "schizo,vtop", 1, 2,
92 	    fc_ptr2cell(vaddr), &physlo, &physhi);
93 	if (error)
94 		throw_from_fclib(env, 1, "fc_vtop: '>physical' failed\n");
95 
96 	PUSH(DS, physlo);
97 	PUSH(DS, physhi);
98 }
99 
100 void
101 install_openprom_nodes(fcode_env_t *env)
102 {
103 	MYSELF = open_instance_chain(env, env->root_node, 0);
104 	if (MYSELF != NULL) {
105 		make_a_node(env, "openprom", 0);
106 		make_a_node(env, "client-services", 0);
107 		FORTH(0,	"claim",	claim);
108 		FORTH(0,	"release",	release);
109 		finish_device(env);
110 		finish_device(env);
111 		close_instance_chain(env, MYSELF, 0);
112 		device_end(env);
113 		MYSELF = 0;
114 	}
115 }
116 
117 #pragma init(_init)
118 
119 static void
120 _init(void)
121 {
122 	fcode_env_t *env = initial_env;
123 
124 	ASSERT(env);
125 	NOTICE;
126 
127 	FORTH(0,	"install-openprom-nodes",	install_openprom_nodes);
128 	FORTH(0,	"claim",			claim);
129 	FORTH(0,	"release",			release);
130 	P1275(0x106,	0,	">physical",		fc_vtop);
131 }
132