xref: /titanic_50/usr/src/psm/promif/ieee1275/sun4/prom_init.c (revision 8b464eb836173b92f2b7a65623cd06c8c3c59289)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1994, 2001-2003 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/promif.h>
30 #include <sys/promimpl.h>
31 #include <sys/platform_module.h>
32 
33 int	obp_romvec_version = -1;  /* -1 rsrvd for non-obp sunromvec */
34 int	prom_aligned_allocator = 0; /* Not needed for 1275 */
35 void	*p1275cif;		/* 1275 Client interface handler */
36 
37 #ifdef PROMIF_DEBUG
38 int promif_debug = 0;
39 #endif /* PROMIF_DEBUG */
40 
41 /*
42  * This is the string we use to print out "panic" level messages,
43  * so that it's easier to identify who's doing the complaining.
44  */
45 #define	PROMIF_CLNTNAMELEN	16
46 char	promif_clntname[PROMIF_CLNTNAMELEN];
47 
48 /*
49  * The plat_setprop_enter() and plat_setprop_exit() routines are actually
50  * defined as #pragma weak symbols, which confuses lint since it does not grok
51  * #pragma weak and thus thinks the routines are used but not defined.  Until
52  * lint is enhanced, we workaround this with the following stubs.
53  */
54 #ifdef	__lint
55 void
56 plat_setprop_enter(void)
57 {}
58 
59 void
60 plat_setprop_exit(void)
61 {}
62 #endif
63 
64 /*
65  * This 'do-nothing' function is called immediately before and immediately
66  * after entry to the PROM.  Some standalones (e.g. the kernel)
67  * may replace this routine with their own.
68  */
69 static void
70 default_prepost_prom(void)
71 {}
72 
73 /*
74  * Every standalone that wants to use this library must call
75  * prom_init() before any of the other routines can be called.
76  * The only state it creates is the obp_romvec_version variable,
77  * and the prom_aligned_allocator variable (plus the default pre-
78  * and post-prom handlers, and the clientname string)
79  *
80  */
81 void
82 prom_init(char *pgmname, void *p1275cookie)
83 {
84 	/*
85 	 * Allow implementation to validate input argument.
86 	 */
87 	p1275cif = p1275_cif_init(p1275cookie);
88 
89 	if ((p1275cif == NULL)) {
90 		prom_fatal_error("promif: No interface!");
91 		/*NOTREACHED*/
92 	}
93 
94 	/*
95 	 * Initialize the "clientname" string with the string we've
96 	 * been handed by the standalone
97 	 */
98 	(void) prom_strncpy(promif_clntname, pgmname, PROMIF_CLNTNAMELEN - 1);
99 	promif_clntname[PROMIF_CLNTNAMELEN - 1] = '\0';
100 
101 	obp_romvec_version = OBP_PSEUDO_ROMVEC_VERSION;
102 
103 	/*
104 	 * Add default pre- and post-prom handlers
105 	 * (We add this null handler to avoid the numerous tests
106 	 * that would otherwise have to be included around every call)
107 	 */
108 	(void) prom_set_preprom(default_prepost_prom);
109 	(void) prom_set_postprom(default_prepost_prom);
110 
111 	if (&plat_setprop_enter != NULL) {
112 		prom_setprop_enter = &plat_setprop_enter;
113 		prom_setprop_exit = &plat_setprop_exit;
114 		ASSERT(prom_setprop_exit != NULL);
115 	}
116 }
117 
118 /*
119  * Fatal promif internal error, not an external interface
120  */
121 
122 /*ARGSUSED*/
123 void
124 prom_fatal_error(const char *errormsg)
125 {
126 
127 	volatile int	zero = 0;
128 	volatile int	i = 1;
129 
130 	/*
131 	 * No prom interface, try to cause a trap by
132 	 * dividing by zero, leaving the message in %i0.
133 	 */
134 
135 	i = i / zero;
136 	/*NOTREACHED*/
137 }
138