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*986fd29aSsetje * Common Development and Distribution License (the "License"). 6*986fd29aSsetje * 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*986fd29aSsetje * Copyright 2007 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 <sys/promif.h> 297c478bd9Sstevel@tonic-gate #include <sys/promimpl.h> 307c478bd9Sstevel@tonic-gate #include <sys/platform_module.h> 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate int obp_romvec_version = -1; /* -1 rsrvd for non-obp sunromvec */ 337c478bd9Sstevel@tonic-gate int prom_aligned_allocator = 0; /* Not needed for 1275 */ 347c478bd9Sstevel@tonic-gate void *p1275cif; /* 1275 Client interface handler */ 357c478bd9Sstevel@tonic-gate 367c478bd9Sstevel@tonic-gate #ifdef PROMIF_DEBUG 377c478bd9Sstevel@tonic-gate int promif_debug = 0; 387c478bd9Sstevel@tonic-gate #endif /* PROMIF_DEBUG */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* 417c478bd9Sstevel@tonic-gate * This is the string we use to print out "panic" level messages, 427c478bd9Sstevel@tonic-gate * so that it's easier to identify who's doing the complaining. 437c478bd9Sstevel@tonic-gate */ 447c478bd9Sstevel@tonic-gate #define PROMIF_CLNTNAMELEN 16 457c478bd9Sstevel@tonic-gate char promif_clntname[PROMIF_CLNTNAMELEN]; 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate /* 487c478bd9Sstevel@tonic-gate * The plat_setprop_enter() and plat_setprop_exit() routines are actually 497c478bd9Sstevel@tonic-gate * defined as #pragma weak symbols, which confuses lint since it does not grok 507c478bd9Sstevel@tonic-gate * #pragma weak and thus thinks the routines are used but not defined. Until 517c478bd9Sstevel@tonic-gate * lint is enhanced, we workaround this with the following stubs. 527c478bd9Sstevel@tonic-gate */ 537c478bd9Sstevel@tonic-gate #ifdef __lint 547c478bd9Sstevel@tonic-gate void 557c478bd9Sstevel@tonic-gate plat_setprop_enter(void) 567c478bd9Sstevel@tonic-gate {} 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate void 597c478bd9Sstevel@tonic-gate plat_setprop_exit(void) 607c478bd9Sstevel@tonic-gate {} 617c478bd9Sstevel@tonic-gate #endif 627c478bd9Sstevel@tonic-gate 637c478bd9Sstevel@tonic-gate /* 647c478bd9Sstevel@tonic-gate * This 'do-nothing' function is called immediately before and immediately 657c478bd9Sstevel@tonic-gate * after entry to the PROM. Some standalones (e.g. the kernel) 667c478bd9Sstevel@tonic-gate * may replace this routine with their own. 677c478bd9Sstevel@tonic-gate */ 687c478bd9Sstevel@tonic-gate static void 697c478bd9Sstevel@tonic-gate default_prepost_prom(void) 707c478bd9Sstevel@tonic-gate {} 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate /* 737c478bd9Sstevel@tonic-gate * Every standalone that wants to use this library must call 747c478bd9Sstevel@tonic-gate * prom_init() before any of the other routines can be called. 757c478bd9Sstevel@tonic-gate * The only state it creates is the obp_romvec_version variable, 767c478bd9Sstevel@tonic-gate * and the prom_aligned_allocator variable (plus the default pre- 777c478bd9Sstevel@tonic-gate * and post-prom handlers, and the clientname string) 787c478bd9Sstevel@tonic-gate * 797c478bd9Sstevel@tonic-gate */ 807c478bd9Sstevel@tonic-gate void 817c478bd9Sstevel@tonic-gate prom_init(char *pgmname, void *p1275cookie) 827c478bd9Sstevel@tonic-gate { 837c478bd9Sstevel@tonic-gate /* 847c478bd9Sstevel@tonic-gate * Allow implementation to validate input argument. 857c478bd9Sstevel@tonic-gate */ 867c478bd9Sstevel@tonic-gate p1275cif = p1275_cif_init(p1275cookie); 877c478bd9Sstevel@tonic-gate 887c478bd9Sstevel@tonic-gate if ((p1275cif == NULL)) { 897c478bd9Sstevel@tonic-gate prom_fatal_error("promif: No interface!"); 907c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 917c478bd9Sstevel@tonic-gate } 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate /* 947c478bd9Sstevel@tonic-gate * Initialize the "clientname" string with the string we've 957c478bd9Sstevel@tonic-gate * been handed by the standalone 967c478bd9Sstevel@tonic-gate */ 977c478bd9Sstevel@tonic-gate (void) prom_strncpy(promif_clntname, pgmname, PROMIF_CLNTNAMELEN - 1); 987c478bd9Sstevel@tonic-gate promif_clntname[PROMIF_CLNTNAMELEN - 1] = '\0'; 997c478bd9Sstevel@tonic-gate 1007c478bd9Sstevel@tonic-gate obp_romvec_version = OBP_PSEUDO_ROMVEC_VERSION; 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate /* 1037c478bd9Sstevel@tonic-gate * Add default pre- and post-prom handlers 1047c478bd9Sstevel@tonic-gate * (We add this null handler to avoid the numerous tests 1057c478bd9Sstevel@tonic-gate * that would otherwise have to be included around every call) 1067c478bd9Sstevel@tonic-gate */ 1077c478bd9Sstevel@tonic-gate (void) prom_set_preprom(default_prepost_prom); 1087c478bd9Sstevel@tonic-gate (void) prom_set_postprom(default_prepost_prom); 1097c478bd9Sstevel@tonic-gate } 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate /* 1127c478bd9Sstevel@tonic-gate * Fatal promif internal error, not an external interface 1137c478bd9Sstevel@tonic-gate */ 1147c478bd9Sstevel@tonic-gate 1157c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 1167c478bd9Sstevel@tonic-gate void 1177c478bd9Sstevel@tonic-gate prom_fatal_error(const char *errormsg) 1187c478bd9Sstevel@tonic-gate { 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate volatile int zero = 0; 1217c478bd9Sstevel@tonic-gate volatile int i = 1; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* 1247c478bd9Sstevel@tonic-gate * No prom interface, try to cause a trap by 1257c478bd9Sstevel@tonic-gate * dividing by zero, leaving the message in %i0. 1267c478bd9Sstevel@tonic-gate */ 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate i = i / zero; 1297c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 1307c478bd9Sstevel@tonic-gate } 131