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.
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.
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]
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
29 #include <sys/promif.h>
30 #include <sys/promimpl.h>
33 * The functions in this file are used to control the pre- and post-processing
34 * functions that bracket calls to the OBP CIF handler. One set, promif_preprom
35 * and promif_postprom, are provided for general kernel use. The other set,
36 * promif_preout and promif_postout, are used by the power management subsystem
37 * to ensure that the framebuffer is active when PROM functions that interact
38 * with the console are invoked.
40 * In some cases, the operation of these functions must be suppressed. As such,
41 * this file provides the ability to suspend and resume use of both sets
42 * simultaneously. Complicating matters is the fact that both current uses of
43 * the pre- and post-processor suspension and resume facilities, kmdb and CPR
44 * may be used simultaneously. We therefore support normal operation and two
45 * levels of suspension. The pre- and post-processing functions are only
46 * called during normal operation. With each suspension request, this
47 * subsystem enters the first suspension level, or passes to the second
48 * suspension level, as appropriate. Resume calls decrement the suspension
49 * level. Only two nested suspensions are supported.
51 * As indicated above, the two current users are CPR and kmdb. CPR must prevent
52 * kernel accesses outside of the nucleus page during the late stages of system
53 * suspension and during the early stages of system resumption. As such, the
54 * PM-related processing must not occur during these times.
56 * The platform-specific portions of kmdb live in the platmods, and thus execute
57 * in the linker environment of the platmods. That is, any promif calls they
58 * may make are executed by the kernel copies of those functions, rather than
59 * the versions included with kmdb. The only difference between the two copies
60 * being the nonuse of the pre- and post-processing functions in the kmdb
61 * versions, we must ensure that these functions are not used when the kmdb
62 * platmod code executes. Accordingly, kmdb disables the pre- and post-
63 * processing functions via the KDI prior to passing control to the platmod
67 static int promif_suspendlevel
;
69 static promif_preprom_f
*promif_preprom_fn
;
70 static promif_postprom_f
*promif_postprom_fn
;
73 * When this is set, the PROM output functions attempt to
74 * redirect output to the kernel terminal emulator.
76 promif_redir_t promif_redirect
;
77 promif_redir_arg_t promif_redirect_arg
;
80 * Sets new callback and argument, returns previous callback.
83 prom_set_stdout_redirect(promif_redir_t new_fn
, promif_redir_arg_t opaque_arg
)
85 promif_redirect_arg
= opaque_arg
;
86 promif_redirect
= new_fn
;
90 prom_set_preprom(promif_preprom_f
*new)
92 promif_preprom_fn
= new;
96 prom_set_postprom(promif_postprom_f
*new)
98 promif_postprom_fn
= new;
104 if (promif_suspendlevel
== 0 && promif_preprom_fn
!= NULL
)
109 promif_postprom(void)
111 if (promif_suspendlevel
== 0 && promif_postprom_fn
!= NULL
)
112 promif_postprom_fn();
116 * The reader will note that the layout and calling conventions of the
117 * prom_preout and prom_postout functions differ from the prom_preprom and
118 * prom_postprom functions, above. At the time the preout and postout
119 * functions are initialized, kernel startup is well underway. There exists
120 * a race condition whereby a PROM call may begin before preout has been
121 * initialized, and may end after postout has been initialized. In such
122 * cases, there will be a call to postout without a corresponding preout
123 * call. The preprom and postprom calls above are initialized early enough
124 * that this race condition does not occur.
126 * To avoid the race condition, the preout/postout functions are designed
127 * such that the initialization is atomic. Further, the preout call returns
128 * a data structure that includes a pointer to the postout function that
129 * corresponds to the invoked preout function. This ensures that the preout
130 * and postout functions will only be used as a matched set.
138 static promif_owrap_t nullwrapper
=
144 static promif_owrap_t
*wrapper
= &nullwrapper
;
145 static promif_owrap_t pmwrapper
;
152 if (promif_suspendlevel
> 0)
153 return (&nullwrapper
);
156 if (ow
->preout
!= NULL
)
162 promif_postout(promif_owrap_t
*ow
)
164 if (ow
->postout
!= NULL
)
169 prom_set_outfuncs(void (*pref
)(void), void (*postf
)(void))
171 pmwrapper
.preout
= pref
;
172 pmwrapper
.postout
= postf
;
173 wrapper
= &pmwrapper
;
177 prom_suspend_prepost(void)
179 ASSERT(promif_suspendlevel
< 2);
181 promif_suspendlevel
++;
185 prom_resume_prepost(void)
187 ASSERT(promif_suspendlevel
>= 0);
189 promif_suspendlevel
--;