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