17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*25cf1a30Sjl139090 * Common Development and Distribution License (the "License"). 6*25cf1a30Sjl139090 * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*25cf1a30Sjl139090 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 277c478bd9Sstevel@tonic-gate 287c478bd9Sstevel@tonic-gate #include <stdio.h> 297c478bd9Sstevel@tonic-gate #include <stdlib.h> 307c478bd9Sstevel@tonic-gate #include <strings.h> 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate #include <fcode/private.h> 337c478bd9Sstevel@tonic-gate #include <fcode/log.h> 347c478bd9Sstevel@tonic-gate 357c478bd9Sstevel@tonic-gate #include <fcdriver/fcdriver.h> 367c478bd9Sstevel@tonic-gate 377c478bd9Sstevel@tonic-gate /* 38*25cf1a30Sjl139090 * claim under /openprom/client-services is used by schizo and oberon Fcode, we 39*25cf1a30Sjl139090 * call "claim-memory" service. 407c478bd9Sstevel@tonic-gate */ 417c478bd9Sstevel@tonic-gate void 427c478bd9Sstevel@tonic-gate claim(fcode_env_t *env) 437c478bd9Sstevel@tonic-gate { 447c478bd9Sstevel@tonic-gate size_t size; 457c478bd9Sstevel@tonic-gate void *hint; 467c478bd9Sstevel@tonic-gate int align; 477c478bd9Sstevel@tonic-gate fc_cell_t vaddr; 487c478bd9Sstevel@tonic-gate int error; 497c478bd9Sstevel@tonic-gate 50*25cf1a30Sjl139090 CHECK_DEPTH(env, 3, "claim-memory"); 517c478bd9Sstevel@tonic-gate hint = (void *)POP(DS); 527c478bd9Sstevel@tonic-gate size = POP(DS); 537c478bd9Sstevel@tonic-gate align = POP(DS); 54*25cf1a30Sjl139090 error = fc_run_priv(env->private, "claim-memory", 3, 1, 557c478bd9Sstevel@tonic-gate fc_int2cell(align), fc_size2cell(size), fc_ptr2cell(hint), &vaddr); 567c478bd9Sstevel@tonic-gate if (error) 577c478bd9Sstevel@tonic-gate throw_from_fclib(env, 1, "client-services/claim failed\n"); 587c478bd9Sstevel@tonic-gate vaddr = mapping_to_mcookie(vaddr, size, NULL, NULL); 597c478bd9Sstevel@tonic-gate PUSH(DS, (fstack_t)vaddr); 607c478bd9Sstevel@tonic-gate } 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate void 637c478bd9Sstevel@tonic-gate release(fcode_env_t *env) 647c478bd9Sstevel@tonic-gate { 657c478bd9Sstevel@tonic-gate size_t size; 667c478bd9Sstevel@tonic-gate void *addr; 677c478bd9Sstevel@tonic-gate int error; 687c478bd9Sstevel@tonic-gate 69*25cf1a30Sjl139090 CHECK_DEPTH(env, 2, "release-memory"); 707c478bd9Sstevel@tonic-gate addr = (void *)POP(DS); 717c478bd9Sstevel@tonic-gate size = POP(DS); 72*25cf1a30Sjl139090 error = fc_run_priv(env->private, "release-memory", 2, 0, 737c478bd9Sstevel@tonic-gate fc_size2cell(size), fc_ptr2cell(addr)); 747c478bd9Sstevel@tonic-gate if (error) 757c478bd9Sstevel@tonic-gate throw_from_fclib(env, 1, "client-services/release failed\n"); 767c478bd9Sstevel@tonic-gate delete_mapping((fstack_t)addr); 777c478bd9Sstevel@tonic-gate } 787c478bd9Sstevel@tonic-gate 797c478bd9Sstevel@tonic-gate static void 807c478bd9Sstevel@tonic-gate fc_vtop(fcode_env_t *env) 817c478bd9Sstevel@tonic-gate { 827c478bd9Sstevel@tonic-gate void *vaddr; 837c478bd9Sstevel@tonic-gate fc_cell_t physlo, physhi; 847c478bd9Sstevel@tonic-gate int error; 857c478bd9Sstevel@tonic-gate 86*25cf1a30Sjl139090 CHECK_DEPTH(env, 1, "vtop"); 877c478bd9Sstevel@tonic-gate vaddr = (void *)POP(DS); 88*25cf1a30Sjl139090 error = fc_run_priv(env->private, "vtop", 1, 2, 897c478bd9Sstevel@tonic-gate fc_ptr2cell(vaddr), &physlo, &physhi); 907c478bd9Sstevel@tonic-gate if (error) 917c478bd9Sstevel@tonic-gate throw_from_fclib(env, 1, "fc_vtop: '>physical' failed\n"); 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate PUSH(DS, physlo); 947c478bd9Sstevel@tonic-gate PUSH(DS, physhi); 957c478bd9Sstevel@tonic-gate } 967c478bd9Sstevel@tonic-gate 977c478bd9Sstevel@tonic-gate void 987c478bd9Sstevel@tonic-gate install_openprom_nodes(fcode_env_t *env) 997c478bd9Sstevel@tonic-gate { 1007c478bd9Sstevel@tonic-gate MYSELF = open_instance_chain(env, env->root_node, 0); 1017c478bd9Sstevel@tonic-gate if (MYSELF != NULL) { 1027c478bd9Sstevel@tonic-gate make_a_node(env, "openprom", 0); 1037c478bd9Sstevel@tonic-gate make_a_node(env, "client-services", 0); 1047c478bd9Sstevel@tonic-gate FORTH(0, "claim", claim); 1057c478bd9Sstevel@tonic-gate FORTH(0, "release", release); 1067c478bd9Sstevel@tonic-gate finish_device(env); 1077c478bd9Sstevel@tonic-gate finish_device(env); 1087c478bd9Sstevel@tonic-gate close_instance_chain(env, MYSELF, 0); 1097c478bd9Sstevel@tonic-gate device_end(env); 1107c478bd9Sstevel@tonic-gate MYSELF = 0; 1117c478bd9Sstevel@tonic-gate } 1127c478bd9Sstevel@tonic-gate } 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate #pragma init(_init) 1157c478bd9Sstevel@tonic-gate 1167c478bd9Sstevel@tonic-gate static void 1177c478bd9Sstevel@tonic-gate _init(void) 1187c478bd9Sstevel@tonic-gate { 1197c478bd9Sstevel@tonic-gate fcode_env_t *env = initial_env; 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate ASSERT(env); 1227c478bd9Sstevel@tonic-gate NOTICE; 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate FORTH(0, "install-openprom-nodes", install_openprom_nodes); 1257c478bd9Sstevel@tonic-gate FORTH(0, "claim", claim); 1267c478bd9Sstevel@tonic-gate FORTH(0, "release", release); 1277c478bd9Sstevel@tonic-gate P1275(0x106, 0, ">physical", fc_vtop); 1287c478bd9Sstevel@tonic-gate } 129