diff options
Diffstat (limited to 'usr/src/lib/efcode/packages/memalloc.c')
-rw-r--r-- | usr/src/lib/efcode/packages/memalloc.c | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/usr/src/lib/efcode/packages/memalloc.c b/usr/src/lib/efcode/packages/memalloc.c new file mode 100644 index 0000000000..3bb4a928ff --- /dev/null +++ b/usr/src/lib/efcode/packages/memalloc.c @@ -0,0 +1,131 @@ +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License, Version 1.0 only + * (the "License"). You may not use this file except in compliance + * with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or http://www.opensolaris.org/os/licensing. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright 1999-2003 Sun Microsystems, Inc. All rights reserved. + * Use is subject to license terms. + */ + +#pragma ident "%Z%%M% %I% %E% SMI" + +#include <stdio.h> +#include <stdlib.h> +#include <strings.h> + +#include <fcode/private.h> +#include <fcode/log.h> + +#include <fcdriver/fcdriver.h> + +static void schizo_vtop(fcode_env_t *, fc_cell_t, fstack_t *, fstack_t *); + +/* + * claim under /openprom/client-services is only used by schizo Fcode, we + * call "schizo,claim-memory" service. + */ +void +claim(fcode_env_t *env) +{ + size_t size; + void *hint; + int align; + fc_cell_t vaddr; + int error; + + CHECK_DEPTH(env, 3, "schizo,claim-memory"); + hint = (void *)POP(DS); + size = POP(DS); + align = POP(DS); + error = fc_run_priv(env->private, "schizo,claim-memory", 3, 1, + fc_int2cell(align), fc_size2cell(size), fc_ptr2cell(hint), &vaddr); + if (error) + throw_from_fclib(env, 1, "client-services/claim failed\n"); + vaddr = mapping_to_mcookie(vaddr, size, NULL, NULL); + PUSH(DS, (fstack_t)vaddr); +} + +void +release(fcode_env_t *env) +{ + size_t size; + void *addr; + int error; + + CHECK_DEPTH(env, 2, "schizo,release-memory"); + addr = (void *)POP(DS); + size = POP(DS); + error = fc_run_priv(env->private, "schizo,release-memory", 2, 0, + fc_size2cell(size), fc_ptr2cell(addr)); + if (error) + throw_from_fclib(env, 1, "client-services/release failed\n"); + delete_mapping((fstack_t)addr); +} + +static void +fc_vtop(fcode_env_t *env) +{ + void *vaddr; + fc_cell_t physlo, physhi; + int error; + + CHECK_DEPTH(env, 1, "schizo,vtop"); + vaddr = (void *)POP(DS); + error = fc_run_priv(env->private, "schizo,vtop", 1, 2, + fc_ptr2cell(vaddr), &physlo, &physhi); + if (error) + throw_from_fclib(env, 1, "fc_vtop: '>physical' failed\n"); + + PUSH(DS, physlo); + PUSH(DS, physhi); +} + +void +install_openprom_nodes(fcode_env_t *env) +{ + MYSELF = open_instance_chain(env, env->root_node, 0); + if (MYSELF != NULL) { + make_a_node(env, "openprom", 0); + make_a_node(env, "client-services", 0); + FORTH(0, "claim", claim); + FORTH(0, "release", release); + finish_device(env); + finish_device(env); + close_instance_chain(env, MYSELF, 0); + device_end(env); + MYSELF = 0; + } +} + +#pragma init(_init) + +static void +_init(void) +{ + fcode_env_t *env = initial_env; + + ASSERT(env); + NOTICE; + + FORTH(0, "install-openprom-nodes", install_openprom_nodes); + FORTH(0, "claim", claim); + FORTH(0, "release", release); + P1275(0x106, 0, ">physical", fc_vtop); +} |