xref: /onnv-gate/usr/src/lib/efcode/packages/memalloc.c (revision 1772:78cca3d2cc4b)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*1772Sjl139090  * Common Development and Distribution License (the "License").
6*1772Sjl139090  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*1772Sjl139090  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate #include <stdio.h>
290Sstevel@tonic-gate #include <stdlib.h>
300Sstevel@tonic-gate #include <strings.h>
310Sstevel@tonic-gate 
320Sstevel@tonic-gate #include <fcode/private.h>
330Sstevel@tonic-gate #include <fcode/log.h>
340Sstevel@tonic-gate 
350Sstevel@tonic-gate #include <fcdriver/fcdriver.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate /*
38*1772Sjl139090  * claim under /openprom/client-services is used by schizo and oberon Fcode, we
39*1772Sjl139090  * call "claim-memory" service.
400Sstevel@tonic-gate  */
410Sstevel@tonic-gate void
claim(fcode_env_t * env)420Sstevel@tonic-gate claim(fcode_env_t *env)
430Sstevel@tonic-gate {
440Sstevel@tonic-gate 	size_t size;
450Sstevel@tonic-gate 	void *hint;
460Sstevel@tonic-gate 	int align;
470Sstevel@tonic-gate 	fc_cell_t vaddr;
480Sstevel@tonic-gate 	int error;
490Sstevel@tonic-gate 
50*1772Sjl139090 	CHECK_DEPTH(env, 3, "claim-memory");
510Sstevel@tonic-gate 	hint = (void *)POP(DS);
520Sstevel@tonic-gate 	size = POP(DS);
530Sstevel@tonic-gate 	align = POP(DS);
54*1772Sjl139090 	error = fc_run_priv(env->private, "claim-memory", 3, 1,
550Sstevel@tonic-gate 	    fc_int2cell(align), fc_size2cell(size), fc_ptr2cell(hint), &vaddr);
560Sstevel@tonic-gate 	if (error)
570Sstevel@tonic-gate 		throw_from_fclib(env, 1, "client-services/claim failed\n");
580Sstevel@tonic-gate 	vaddr = mapping_to_mcookie(vaddr, size, NULL, NULL);
590Sstevel@tonic-gate 	PUSH(DS, (fstack_t)vaddr);
600Sstevel@tonic-gate }
610Sstevel@tonic-gate 
620Sstevel@tonic-gate void
release(fcode_env_t * env)630Sstevel@tonic-gate release(fcode_env_t *env)
640Sstevel@tonic-gate {
650Sstevel@tonic-gate 	size_t size;
660Sstevel@tonic-gate 	void *addr;
670Sstevel@tonic-gate 	int error;
680Sstevel@tonic-gate 
69*1772Sjl139090 	CHECK_DEPTH(env, 2, "release-memory");
700Sstevel@tonic-gate 	addr = (void *)POP(DS);
710Sstevel@tonic-gate 	size = POP(DS);
72*1772Sjl139090 	error = fc_run_priv(env->private, "release-memory", 2, 0,
730Sstevel@tonic-gate 	    fc_size2cell(size), fc_ptr2cell(addr));
740Sstevel@tonic-gate 	if (error)
750Sstevel@tonic-gate 		throw_from_fclib(env, 1, "client-services/release failed\n");
760Sstevel@tonic-gate 	delete_mapping((fstack_t)addr);
770Sstevel@tonic-gate }
780Sstevel@tonic-gate 
790Sstevel@tonic-gate static void
fc_vtop(fcode_env_t * env)800Sstevel@tonic-gate fc_vtop(fcode_env_t *env)
810Sstevel@tonic-gate {
820Sstevel@tonic-gate 	void *vaddr;
830Sstevel@tonic-gate 	fc_cell_t physlo, physhi;
840Sstevel@tonic-gate 	int error;
850Sstevel@tonic-gate 
86*1772Sjl139090 	CHECK_DEPTH(env, 1, "vtop");
870Sstevel@tonic-gate 	vaddr = (void *)POP(DS);
88*1772Sjl139090 	error = fc_run_priv(env->private, "vtop", 1, 2,
890Sstevel@tonic-gate 	    fc_ptr2cell(vaddr), &physlo, &physhi);
900Sstevel@tonic-gate 	if (error)
910Sstevel@tonic-gate 		throw_from_fclib(env, 1, "fc_vtop: '>physical' failed\n");
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 	PUSH(DS, physlo);
940Sstevel@tonic-gate 	PUSH(DS, physhi);
950Sstevel@tonic-gate }
960Sstevel@tonic-gate 
970Sstevel@tonic-gate void
install_openprom_nodes(fcode_env_t * env)980Sstevel@tonic-gate install_openprom_nodes(fcode_env_t *env)
990Sstevel@tonic-gate {
1000Sstevel@tonic-gate 	MYSELF = open_instance_chain(env, env->root_node, 0);
1010Sstevel@tonic-gate 	if (MYSELF != NULL) {
1020Sstevel@tonic-gate 		make_a_node(env, "openprom", 0);
1030Sstevel@tonic-gate 		make_a_node(env, "client-services", 0);
1040Sstevel@tonic-gate 		FORTH(0,	"claim",	claim);
1050Sstevel@tonic-gate 		FORTH(0,	"release",	release);
1060Sstevel@tonic-gate 		finish_device(env);
1070Sstevel@tonic-gate 		finish_device(env);
1080Sstevel@tonic-gate 		close_instance_chain(env, MYSELF, 0);
1090Sstevel@tonic-gate 		device_end(env);
1100Sstevel@tonic-gate 		MYSELF = 0;
1110Sstevel@tonic-gate 	}
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate 
1140Sstevel@tonic-gate #pragma init(_init)
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate static void
_init(void)1170Sstevel@tonic-gate _init(void)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate 	fcode_env_t *env = initial_env;
1200Sstevel@tonic-gate 
1210Sstevel@tonic-gate 	ASSERT(env);
1220Sstevel@tonic-gate 	NOTICE;
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	FORTH(0,	"install-openprom-nodes",	install_openprom_nodes);
1250Sstevel@tonic-gate 	FORTH(0,	"claim",			claim);
1260Sstevel@tonic-gate 	FORTH(0,	"release",			release);
1270Sstevel@tonic-gate 	P1275(0x106,	0,	">physical",		fc_vtop);
1280Sstevel@tonic-gate }
129