prom_init.c revision 986fd29a0dc13f7608ef7f508f6e700bd7bc2720
2N/A/*
2N/A * CDDL HEADER START
2N/A *
2N/A * The contents of this file are subject to the terms of the
2N/A * Common Development and Distribution License (the "License").
2N/A * You may not use this file except in compliance with the License.
2N/A *
2N/A * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
2N/A * or http://www.opensolaris.org/os/licensing.
2N/A * See the License for the specific language governing permissions
2N/A * and limitations under the License.
2N/A *
2N/A * When distributing Covered Code, include this CDDL HEADER in each
2N/A * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
2N/A * If applicable, add the following below this CDDL HEADER, with the
2N/A * fields enclosed by brackets "[]" replaced with your own identifying
2N/A * information: Portions Copyright [yyyy] [name of copyright owner]
2N/A *
2N/A * CDDL HEADER END
2N/A */
2N/A/*
2N/A * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
2N/A * Use is subject to license terms.
2N/A */
2N/A
2N/A#pragma ident "%Z%%M% %I% %E% SMI"
2N/A
2N/A#include <sys/promif.h>
2N/A#include <sys/promimpl.h>
2N/A#include <sys/platform_module.h>
2N/A
2N/Aint obp_romvec_version = -1; /* -1 rsrvd for non-obp sunromvec */
2N/Aint prom_aligned_allocator = 0; /* Not needed for 1275 */
2N/Avoid *p1275cif; /* 1275 Client interface handler */
2N/A
2N/A#ifdef PROMIF_DEBUG
2N/Aint promif_debug = 0;
2N/A#endif /* PROMIF_DEBUG */
2N/A
2N/A/*
2N/A * This is the string we use to print out "panic" level messages,
2N/A * so that it's easier to identify who's doing the complaining.
2N/A */
2N/A#define PROMIF_CLNTNAMELEN 16
2N/Achar promif_clntname[PROMIF_CLNTNAMELEN];
2N/A
2N/A/*
2N/A * The plat_setprop_enter() and plat_setprop_exit() routines are actually
2N/A * defined as #pragma weak symbols, which confuses lint since it does not grok
2N/A * #pragma weak and thus thinks the routines are used but not defined. Until
2N/A * lint is enhanced, we workaround this with the following stubs.
2N/A */
2N/A#ifdef __lint
2N/Avoid
2N/Aplat_setprop_enter(void)
2N/A{}
2N/A
2N/Avoid
2N/Aplat_setprop_exit(void)
2N/A{}
2N/A#endif
2N/A
2N/A/*
2N/A * This 'do-nothing' function is called immediately before and immediately
2N/A * after entry to the PROM. Some standalones (e.g. the kernel)
2N/A * may replace this routine with their own.
2N/A */
2N/Astatic void
2N/Adefault_prepost_prom(void)
2N/A{}
2N/A
2N/A/*
2N/A * Every standalone that wants to use this library must call
2N/A * prom_init() before any of the other routines can be called.
2N/A * The only state it creates is the obp_romvec_version variable,
2N/A * and the prom_aligned_allocator variable (plus the default pre-
2N/A * and post-prom handlers, and the clientname string)
2N/A *
2N/A */
2N/Avoid
2N/Aprom_init(char *pgmname, void *p1275cookie)
2N/A{
2N/A /*
2N/A * Allow implementation to validate input argument.
2N/A */
2N/A p1275cif = p1275_cif_init(p1275cookie);
2N/A
2N/A if ((p1275cif == NULL)) {
2N/A prom_fatal_error("promif: No interface!");
2N/A /*NOTREACHED*/
2N/A }
2N/A
2N/A /*
2N/A * Initialize the "clientname" string with the string we've
2N/A * been handed by the standalone
2N/A */
2N/A (void) prom_strncpy(promif_clntname, pgmname, PROMIF_CLNTNAMELEN - 1);
2N/A promif_clntname[PROMIF_CLNTNAMELEN - 1] = '\0';
2N/A
2N/A obp_romvec_version = OBP_PSEUDO_ROMVEC_VERSION;
2N/A
2N/A /*
2N/A * Add default pre- and post-prom handlers
2N/A * (We add this null handler to avoid the numerous tests
2N/A * that would otherwise have to be included around every call)
2N/A */
2N/A (void) prom_set_preprom(default_prepost_prom);
2N/A (void) prom_set_postprom(default_prepost_prom);
2N/A}
2N/A
2N/A/*
2N/A * Fatal promif internal error, not an external interface
2N/A */
2N/A
2N/A/*ARGSUSED*/
2N/Avoid
2N/Aprom_fatal_error(const char *errormsg)
2N/A{
2N/A
2N/A volatile int zero = 0;
2N/A volatile int i = 1;
2N/A
2N/A /*
2N/A * No prom interface, try to cause a trap by
2N/A * dividing by zero, leaving the message in %i0.
2N/A */
2N/A
2N/A i = i / zero;
2N/A /*NOTREACHED*/
2N/A}
2N/A