1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
27*7c478bd9Sstevel@tonic-gate
28*7c478bd9Sstevel@tonic-gate #include <sys/stropts.h>
29*7c478bd9Sstevel@tonic-gate #include <sys/devops.h>
30*7c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
31*7c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
32*7c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
33*7c478bd9Sstevel@tonic-gate #include <sys/promif.h>
34*7c478bd9Sstevel@tonic-gate #include <sys/note.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/consdev.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/polled_io.h>
37*7c478bd9Sstevel@tonic-gate
38*7c478bd9Sstevel@tonic-gate /*
39*7c478bd9Sstevel@tonic-gate * consconfig is aware of which devices are the stdin and stout. The
40*7c478bd9Sstevel@tonic-gate * post-attach/pre-detach functions are an extension of consconfig because
41*7c478bd9Sstevel@tonic-gate * they know about the dynamic changes to the stdin device. Neither an
42*7c478bd9Sstevel@tonic-gate * individual driver nor the DDI framework knows what device is really the
43*7c478bd9Sstevel@tonic-gate * stdin.
44*7c478bd9Sstevel@tonic-gate */
45*7c478bd9Sstevel@tonic-gate /*
46*7c478bd9Sstevel@tonic-gate * Issues:
47*7c478bd9Sstevel@tonic-gate * o There are probably race conditions between vx_handler for "read"
48*7c478bd9Sstevel@tonic-gate * being called by OBP and the update of the polled_input_t
49*7c478bd9Sstevel@tonic-gate * structure. We need to be careful how the structure is updated.
50*7c478bd9Sstevel@tonic-gate *
51*7c478bd9Sstevel@tonic-gate * Solaris/Intel note: While OBP is not in the picture, there are probably
52*7c478bd9Sstevel@tonic-gate * similar issues with kmdb.
53*7c478bd9Sstevel@tonic-gate */
54*7c478bd9Sstevel@tonic-gate
55*7c478bd9Sstevel@tonic-gate #if defined(MAYBE_SOMETIME)
56*7c478bd9Sstevel@tonic-gate static void polled_give_input(void);
57*7c478bd9Sstevel@tonic-gate static void polled_take_input(void);
58*7c478bd9Sstevel@tonic-gate static void polled_give_output(void);
59*7c478bd9Sstevel@tonic-gate static void polled_take_output(void);
60*7c478bd9Sstevel@tonic-gate
61*7c478bd9Sstevel@tonic-gate static void polled_io_register(cons_polledio_t *,
62*7c478bd9Sstevel@tonic-gate polled_io_console_type_t, int);
63*7c478bd9Sstevel@tonic-gate
64*7c478bd9Sstevel@tonic-gate static void polled_io_unregister(polled_io_console_type_t, int);
65*7c478bd9Sstevel@tonic-gate
66*7c478bd9Sstevel@tonic-gate
67*7c478bd9Sstevel@tonic-gate /*
68*7c478bd9Sstevel@tonic-gate * Make the registered device become the console for OBP
69*7c478bd9Sstevel@tonic-gate */
70*7c478bd9Sstevel@tonic-gate static int polled_io_take_console(polled_io_console_type_t, int);
71*7c478bd9Sstevel@tonic-gate
72*7c478bd9Sstevel@tonic-gate /*
73*7c478bd9Sstevel@tonic-gate * Restore the old console device for OBP.
74*7c478bd9Sstevel@tonic-gate */
75*7c478bd9Sstevel@tonic-gate static int polled_io_release_console(polled_io_console_type_t, int);
76*7c478bd9Sstevel@tonic-gate #endif /* MAYBE_SOMETIME */
77*7c478bd9Sstevel@tonic-gate
78*7c478bd9Sstevel@tonic-gate static polled_device_t polled_input_device;
79*7c478bd9Sstevel@tonic-gate static polled_device_t polled_output_device;
80*7c478bd9Sstevel@tonic-gate
81*7c478bd9Sstevel@tonic-gate /*
82*7c478bd9Sstevel@tonic-gate * This routine is called to initialize polled I/O. We insert our entry
83*7c478bd9Sstevel@tonic-gate * points so that OBP will call into this code when the switch is thrown
84*7c478bd9Sstevel@tonic-gate * in polled_io_take_console().
85*7c478bd9Sstevel@tonic-gate */
86*7c478bd9Sstevel@tonic-gate void
polled_io_init(void)87*7c478bd9Sstevel@tonic-gate polled_io_init(void)
88*7c478bd9Sstevel@tonic-gate {
89*7c478bd9Sstevel@tonic-gate /*
90*7c478bd9Sstevel@tonic-gate * Initialize lock to protect multiple thread access to the
91*7c478bd9Sstevel@tonic-gate * polled_input_device structure. This does not protect
92*7c478bd9Sstevel@tonic-gate * us from access in OBP mode.
93*7c478bd9Sstevel@tonic-gate */
94*7c478bd9Sstevel@tonic-gate mutex_init(&polled_input_device.polled_device_lock,
95*7c478bd9Sstevel@tonic-gate NULL, MUTEX_DRIVER, NULL);
96*7c478bd9Sstevel@tonic-gate
97*7c478bd9Sstevel@tonic-gate /*
98*7c478bd9Sstevel@tonic-gate * Initialize lock to protect multiple thread access to the
99*7c478bd9Sstevel@tonic-gate * polled_output_device structure. This does not protect
100*7c478bd9Sstevel@tonic-gate * us from access in OBP mode.
101*7c478bd9Sstevel@tonic-gate */
102*7c478bd9Sstevel@tonic-gate mutex_init(&polled_output_device.polled_device_lock,
103*7c478bd9Sstevel@tonic-gate NULL, MUTEX_DRIVER, NULL);
104*7c478bd9Sstevel@tonic-gate }
105*7c478bd9Sstevel@tonic-gate
106*7c478bd9Sstevel@tonic-gate /*
107*7c478bd9Sstevel@tonic-gate * Register a device for input or output. The polled_io structure
108*7c478bd9Sstevel@tonic-gate * will be filled in with the callbacks that are appropriate for
109*7c478bd9Sstevel@tonic-gate * that device.
110*7c478bd9Sstevel@tonic-gate */
111*7c478bd9Sstevel@tonic-gate int
polled_io_register_callbacks(cons_polledio_t * polled_io,int flags)112*7c478bd9Sstevel@tonic-gate polled_io_register_callbacks(
113*7c478bd9Sstevel@tonic-gate cons_polledio_t *polled_io,
114*7c478bd9Sstevel@tonic-gate int flags
115*7c478bd9Sstevel@tonic-gate )
116*7c478bd9Sstevel@tonic-gate {
117*7c478bd9Sstevel@tonic-gate #if defined(MAYBE_SOMETIME)
118*7c478bd9Sstevel@tonic-gate /*
119*7c478bd9Sstevel@tonic-gate * If the input structure entries are filled in, then register this
120*7c478bd9Sstevel@tonic-gate * structure as an input device.
121*7c478bd9Sstevel@tonic-gate */
122*7c478bd9Sstevel@tonic-gate if ((polled_io->cons_polledio_getchar != NULL) &&
123*7c478bd9Sstevel@tonic-gate (polled_io->cons_polledio_ischar != NULL)) {
124*7c478bd9Sstevel@tonic-gate
125*7c478bd9Sstevel@tonic-gate polled_io_register(polled_io,
126*7c478bd9Sstevel@tonic-gate POLLED_IO_CONSOLE_INPUT, flags);
127*7c478bd9Sstevel@tonic-gate }
128*7c478bd9Sstevel@tonic-gate
129*7c478bd9Sstevel@tonic-gate /*
130*7c478bd9Sstevel@tonic-gate * If the output structure entries are filled in, then register this
131*7c478bd9Sstevel@tonic-gate * structure as an output device.
132*7c478bd9Sstevel@tonic-gate */
133*7c478bd9Sstevel@tonic-gate if (polled_io->cons_polledio_putchar != NULL) {
134*7c478bd9Sstevel@tonic-gate
135*7c478bd9Sstevel@tonic-gate polled_io_register(polled_io,
136*7c478bd9Sstevel@tonic-gate POLLED_IO_CONSOLE_OUTPUT, flags);
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate #else
139*7c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(flags))
140*7c478bd9Sstevel@tonic-gate cons_polledio = polled_io;
141*7c478bd9Sstevel@tonic-gate #endif
142*7c478bd9Sstevel@tonic-gate
143*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
144*7c478bd9Sstevel@tonic-gate }
145*7c478bd9Sstevel@tonic-gate
146*7c478bd9Sstevel@tonic-gate /*
147*7c478bd9Sstevel@tonic-gate * Unregister a device for console input/output.
148*7c478bd9Sstevel@tonic-gate */
149*7c478bd9Sstevel@tonic-gate int
polled_io_unregister_callbacks(cons_polledio_t * polled_io,int flags)150*7c478bd9Sstevel@tonic-gate polled_io_unregister_callbacks(
151*7c478bd9Sstevel@tonic-gate cons_polledio_t *polled_io,
152*7c478bd9Sstevel@tonic-gate int flags
153*7c478bd9Sstevel@tonic-gate )
154*7c478bd9Sstevel@tonic-gate {
155*7c478bd9Sstevel@tonic-gate #if defined(MAYBE_SOMETIME)
156*7c478bd9Sstevel@tonic-gate /*
157*7c478bd9Sstevel@tonic-gate * If polled_io is being used for input, then unregister it.
158*7c478bd9Sstevel@tonic-gate */
159*7c478bd9Sstevel@tonic-gate if (polled_io == polled_input_device.polled_io) {
160*7c478bd9Sstevel@tonic-gate
161*7c478bd9Sstevel@tonic-gate polled_io_unregister(
162*7c478bd9Sstevel@tonic-gate POLLED_IO_CONSOLE_INPUT, flags);
163*7c478bd9Sstevel@tonic-gate }
164*7c478bd9Sstevel@tonic-gate
165*7c478bd9Sstevel@tonic-gate /*
166*7c478bd9Sstevel@tonic-gate * If polled_io is being used for output, then unregister it.
167*7c478bd9Sstevel@tonic-gate */
168*7c478bd9Sstevel@tonic-gate if (polled_io == polled_output_device.polled_io) {
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate polled_io_unregister(
171*7c478bd9Sstevel@tonic-gate POLLED_IO_CONSOLE_OUTPUT, flags);
172*7c478bd9Sstevel@tonic-gate }
173*7c478bd9Sstevel@tonic-gate #else
174*7c478bd9Sstevel@tonic-gate _NOTE(ARGUNUSED(polled_io,flags))
175*7c478bd9Sstevel@tonic-gate #endif /* MAYBE_SOMETIME */
176*7c478bd9Sstevel@tonic-gate
177*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
178*7c478bd9Sstevel@tonic-gate }
179*7c478bd9Sstevel@tonic-gate
180*7c478bd9Sstevel@tonic-gate /*
181*7c478bd9Sstevel@tonic-gate * This routine is called when we are done handling polled io. We will
182*7c478bd9Sstevel@tonic-gate * remove all of our handlers and destroy any memory that we have allocated.
183*7c478bd9Sstevel@tonic-gate */
184*7c478bd9Sstevel@tonic-gate void
polled_io_fini()185*7c478bd9Sstevel@tonic-gate polled_io_fini()
186*7c478bd9Sstevel@tonic-gate {
187*7c478bd9Sstevel@tonic-gate /*
188*7c478bd9Sstevel@tonic-gate * Destroy the mutexes, we will not need them anymore.
189*7c478bd9Sstevel@tonic-gate */
190*7c478bd9Sstevel@tonic-gate mutex_destroy(&polled_input_device.polled_device_lock);
191*7c478bd9Sstevel@tonic-gate
192*7c478bd9Sstevel@tonic-gate mutex_destroy(&polled_output_device.polled_device_lock);
193*7c478bd9Sstevel@tonic-gate }
194*7c478bd9Sstevel@tonic-gate
195*7c478bd9Sstevel@tonic-gate #if defined(MAYBE_SOMETIME)
196*7c478bd9Sstevel@tonic-gate /*
197*7c478bd9Sstevel@tonic-gate * Generic internal routine for registering a polled input or output device.
198*7c478bd9Sstevel@tonic-gate */
199*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
200*7c478bd9Sstevel@tonic-gate static void
polled_io_register(cons_polledio_t * polled_io,polled_io_console_type_t type,int flags)201*7c478bd9Sstevel@tonic-gate polled_io_register(
202*7c478bd9Sstevel@tonic-gate cons_polledio_t *polled_io,
203*7c478bd9Sstevel@tonic-gate polled_io_console_type_t type,
204*7c478bd9Sstevel@tonic-gate int flags
205*7c478bd9Sstevel@tonic-gate )
206*7c478bd9Sstevel@tonic-gate {
207*7c478bd9Sstevel@tonic-gate switch (type) {
208*7c478bd9Sstevel@tonic-gate case POLLED_IO_CONSOLE_INPUT:
209*7c478bd9Sstevel@tonic-gate /*
210*7c478bd9Sstevel@tonic-gate * Grab the device lock, because we are going to access
211*7c478bd9Sstevel@tonic-gate * protected structure entries. We do this before the
212*7c478bd9Sstevel@tonic-gate * POLLED_IO_CONSOLE_OPEN_INPUT so that we serialize
213*7c478bd9Sstevel@tonic-gate * registration.
214*7c478bd9Sstevel@tonic-gate */
215*7c478bd9Sstevel@tonic-gate mutex_enter(&polled_input_device.polled_device_lock);
216*7c478bd9Sstevel@tonic-gate
217*7c478bd9Sstevel@tonic-gate /*
218*7c478bd9Sstevel@tonic-gate * Save the polled_io pointers so that we can access
219*7c478bd9Sstevel@tonic-gate * them later.
220*7c478bd9Sstevel@tonic-gate */
221*7c478bd9Sstevel@tonic-gate polled_input_device.polled_io = polled_io;
222*7c478bd9Sstevel@tonic-gate
223*7c478bd9Sstevel@tonic-gate mutex_exit(&polled_input_device.polled_device_lock);
224*7c478bd9Sstevel@tonic-gate
225*7c478bd9Sstevel@tonic-gate /*
226*7c478bd9Sstevel@tonic-gate * Tell the generic console framework to
227*7c478bd9Sstevel@tonic-gate * repoint OBP's stdin to this keyboard device.
228*7c478bd9Sstevel@tonic-gate */
229*7c478bd9Sstevel@tonic-gate (void) polled_io_take_console(type, 0);
230*7c478bd9Sstevel@tonic-gate
231*7c478bd9Sstevel@tonic-gate break;
232*7c478bd9Sstevel@tonic-gate
233*7c478bd9Sstevel@tonic-gate case POLLED_IO_CONSOLE_OUTPUT:
234*7c478bd9Sstevel@tonic-gate /*
235*7c478bd9Sstevel@tonic-gate * Grab the device lock, because we are going to access
236*7c478bd9Sstevel@tonic-gate * protected structure entries. We do this before the
237*7c478bd9Sstevel@tonic-gate * POLLED_IO_CONSOLE_OPEN_OUTPUT so that we serialize
238*7c478bd9Sstevel@tonic-gate * registration.
239*7c478bd9Sstevel@tonic-gate */
240*7c478bd9Sstevel@tonic-gate mutex_enter(&polled_output_device.polled_device_lock);
241*7c478bd9Sstevel@tonic-gate
242*7c478bd9Sstevel@tonic-gate /*
243*7c478bd9Sstevel@tonic-gate * Save the polled_io pointers so that we can access
244*7c478bd9Sstevel@tonic-gate * them later.
245*7c478bd9Sstevel@tonic-gate */
246*7c478bd9Sstevel@tonic-gate polled_input_device.polled_io = polled_io;
247*7c478bd9Sstevel@tonic-gate
248*7c478bd9Sstevel@tonic-gate mutex_exit(&polled_output_device.polled_device_lock);
249*7c478bd9Sstevel@tonic-gate
250*7c478bd9Sstevel@tonic-gate break;
251*7c478bd9Sstevel@tonic-gate }
252*7c478bd9Sstevel@tonic-gate }
253*7c478bd9Sstevel@tonic-gate
254*7c478bd9Sstevel@tonic-gate /*
255*7c478bd9Sstevel@tonic-gate * Generic internal routine for unregistering a polled input or output device.
256*7c478bd9Sstevel@tonic-gate */
257*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
258*7c478bd9Sstevel@tonic-gate static void
polled_io_unregister(polled_io_console_type_t type,int flags)259*7c478bd9Sstevel@tonic-gate polled_io_unregister(
260*7c478bd9Sstevel@tonic-gate polled_io_console_type_t type,
261*7c478bd9Sstevel@tonic-gate int flags
262*7c478bd9Sstevel@tonic-gate )
263*7c478bd9Sstevel@tonic-gate {
264*7c478bd9Sstevel@tonic-gate switch (type) {
265*7c478bd9Sstevel@tonic-gate case POLLED_IO_CONSOLE_INPUT:
266*7c478bd9Sstevel@tonic-gate /*
267*7c478bd9Sstevel@tonic-gate * Tell the generic console framework to restore OBP's
268*7c478bd9Sstevel@tonic-gate * old stdin pointers.
269*7c478bd9Sstevel@tonic-gate */
270*7c478bd9Sstevel@tonic-gate (void) polled_io_release_console(type, 0);
271*7c478bd9Sstevel@tonic-gate
272*7c478bd9Sstevel@tonic-gate /*
273*7c478bd9Sstevel@tonic-gate * Grab the device lock, because we are going to access
274*7c478bd9Sstevel@tonic-gate * protected structure entries.
275*7c478bd9Sstevel@tonic-gate */
276*7c478bd9Sstevel@tonic-gate mutex_enter(&polled_input_device.polled_device_lock);
277*7c478bd9Sstevel@tonic-gate
278*7c478bd9Sstevel@tonic-gate /*
279*7c478bd9Sstevel@tonic-gate * We are closing the device, so get the value for the op
280*7c478bd9Sstevel@tonic-gate * pointer. We use the polled_io structure to determine if
281*7c478bd9Sstevel@tonic-gate * there is a device registered, so null the dev_ops
282*7c478bd9Sstevel@tonic-gate * structure.
283*7c478bd9Sstevel@tonic-gate */
284*7c478bd9Sstevel@tonic-gate polled_input_device.polled_io = NULL;
285*7c478bd9Sstevel@tonic-gate
286*7c478bd9Sstevel@tonic-gate mutex_exit(&polled_input_device.polled_device_lock);
287*7c478bd9Sstevel@tonic-gate
288*7c478bd9Sstevel@tonic-gate break;
289*7c478bd9Sstevel@tonic-gate
290*7c478bd9Sstevel@tonic-gate case POLLED_IO_CONSOLE_OUTPUT:
291*7c478bd9Sstevel@tonic-gate /*
292*7c478bd9Sstevel@tonic-gate * Grab the device lock, because we are going to access
293*7c478bd9Sstevel@tonic-gate * protected structure entries.
294*7c478bd9Sstevel@tonic-gate */
295*7c478bd9Sstevel@tonic-gate mutex_enter(&polled_output_device.polled_device_lock);
296*7c478bd9Sstevel@tonic-gate
297*7c478bd9Sstevel@tonic-gate /*
298*7c478bd9Sstevel@tonic-gate * We are closing the device, so get the value for the op
299*7c478bd9Sstevel@tonic-gate * pointer. We use the polled_io structure to determine if
300*7c478bd9Sstevel@tonic-gate * there is a device registered.
301*7c478bd9Sstevel@tonic-gate */
302*7c478bd9Sstevel@tonic-gate polled_output_device.polled_io = NULL;
303*7c478bd9Sstevel@tonic-gate
304*7c478bd9Sstevel@tonic-gate mutex_exit(&polled_output_device.polled_device_lock);
305*7c478bd9Sstevel@tonic-gate
306*7c478bd9Sstevel@tonic-gate break;
307*7c478bd9Sstevel@tonic-gate }
308*7c478bd9Sstevel@tonic-gate }
309*7c478bd9Sstevel@tonic-gate
310*7c478bd9Sstevel@tonic-gate /*
311*7c478bd9Sstevel@tonic-gate * This is the routine that is called to throw the switch from boot
312*7c478bd9Sstevel@tonic-gate * ownership of stdout/stdin to the kernel.
313*7c478bd9Sstevel@tonic-gate */
314*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
315*7c478bd9Sstevel@tonic-gate static int
polled_io_take_console(polled_io_console_type_t type,int flags)316*7c478bd9Sstevel@tonic-gate polled_io_take_console(
317*7c478bd9Sstevel@tonic-gate polled_io_console_type_t type,
318*7c478bd9Sstevel@tonic-gate int flags
319*7c478bd9Sstevel@tonic-gate )
320*7c478bd9Sstevel@tonic-gate {
321*7c478bd9Sstevel@tonic-gate switch (type) {
322*7c478bd9Sstevel@tonic-gate case POLLED_IO_CONSOLE_INPUT:
323*7c478bd9Sstevel@tonic-gate /*
324*7c478bd9Sstevel@tonic-gate * Perhaps this should be where we switch *sysp
325*7c478bd9Sstevel@tonic-gate */
326*7c478bd9Sstevel@tonic-gate break;
327*7c478bd9Sstevel@tonic-gate
328*7c478bd9Sstevel@tonic-gate case POLLED_IO_CONSOLE_OUTPUT:
329*7c478bd9Sstevel@tonic-gate /*
330*7c478bd9Sstevel@tonic-gate * Perhaps this should be where we switch *sysp
331*7c478bd9Sstevel@tonic-gate */
332*7c478bd9Sstevel@tonic-gate break;
333*7c478bd9Sstevel@tonic-gate }
334*7c478bd9Sstevel@tonic-gate
335*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
336*7c478bd9Sstevel@tonic-gate }
337*7c478bd9Sstevel@tonic-gate
338*7c478bd9Sstevel@tonic-gate /*
339*7c478bd9Sstevel@tonic-gate * This routine gives control of console input/output back to ???.
340*7c478bd9Sstevel@tonic-gate *
341*7c478bd9Sstevel@tonic-gate * Solaris/Intel has nobody to give it back to. Hope we don't get here!
342*7c478bd9Sstevel@tonic-gate */
343*7c478bd9Sstevel@tonic-gate /* ARGSUSED */
344*7c478bd9Sstevel@tonic-gate static int
polled_io_release_console(polled_io_console_type_t type,int flags)345*7c478bd9Sstevel@tonic-gate polled_io_release_console(
346*7c478bd9Sstevel@tonic-gate polled_io_console_type_t type,
347*7c478bd9Sstevel@tonic-gate int flags
348*7c478bd9Sstevel@tonic-gate )
349*7c478bd9Sstevel@tonic-gate {
350*7c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
351*7c478bd9Sstevel@tonic-gate "polled_io_release_console: nobody to hand console back to");
352*7c478bd9Sstevel@tonic-gate
353*7c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
354*7c478bd9Sstevel@tonic-gate }
355*7c478bd9Sstevel@tonic-gate
356*7c478bd9Sstevel@tonic-gate /*
357*7c478bd9Sstevel@tonic-gate * This is the routine that kmdb calls to save any state information
358*7c478bd9Sstevel@tonic-gate * before using the input device. This routine, and all of the
359*7c478bd9Sstevel@tonic-gate * routines that it calls, are responsible for saving any state
360*7c478bd9Sstevel@tonic-gate * information so that it can be restored when polled mode is over.
361*7c478bd9Sstevel@tonic-gate */
362*7c478bd9Sstevel@tonic-gate static void
polled_give_input(void)363*7c478bd9Sstevel@tonic-gate polled_give_input(void)
364*7c478bd9Sstevel@tonic-gate {
365*7c478bd9Sstevel@tonic-gate cons_polledio_t *polled_io;
366*7c478bd9Sstevel@tonic-gate
367*7c478bd9Sstevel@tonic-gate /*
368*7c478bd9Sstevel@tonic-gate * We check the dev_ops pointer to see if there is an
369*7c478bd9Sstevel@tonic-gate * input device that has been registered.
370*7c478bd9Sstevel@tonic-gate */
371*7c478bd9Sstevel@tonic-gate polled_io = polled_input_device.polled_io;
372*7c478bd9Sstevel@tonic-gate
373*7c478bd9Sstevel@tonic-gate if (polled_io == NULL || polled_io->cons_polledio_enter == NULL) {
374*7c478bd9Sstevel@tonic-gate return;
375*7c478bd9Sstevel@tonic-gate }
376*7c478bd9Sstevel@tonic-gate
377*7c478bd9Sstevel@tonic-gate /*
378*7c478bd9Sstevel@tonic-gate * Call down to the lower layers to save the state.
379*7c478bd9Sstevel@tonic-gate */
380*7c478bd9Sstevel@tonic-gate polled_io->cons_polledio_enter(
381*7c478bd9Sstevel@tonic-gate polled_io->cons_polledio_argument);
382*7c478bd9Sstevel@tonic-gate }
383*7c478bd9Sstevel@tonic-gate
384*7c478bd9Sstevel@tonic-gate /*
385*7c478bd9Sstevel@tonic-gate * This is the routine that kmdb calls when it is giving up control of the
386*7c478bd9Sstevel@tonic-gate * input device. This routine, and the lower layer routines that it calls,
387*7c478bd9Sstevel@tonic-gate * are responsible for restoring the controller state to the state it was
388*7c478bd9Sstevel@tonic-gate * in before kmdb took control.
389*7c478bd9Sstevel@tonic-gate */
390*7c478bd9Sstevel@tonic-gate static void
polled_take_input(void)391*7c478bd9Sstevel@tonic-gate polled_take_input(void)
392*7c478bd9Sstevel@tonic-gate {
393*7c478bd9Sstevel@tonic-gate cons_polledio_t *polled_io;
394*7c478bd9Sstevel@tonic-gate
395*7c478bd9Sstevel@tonic-gate /*
396*7c478bd9Sstevel@tonic-gate * We check the dev_ops pointer to see if there is an
397*7c478bd9Sstevel@tonic-gate * input device that has been registered.
398*7c478bd9Sstevel@tonic-gate */
399*7c478bd9Sstevel@tonic-gate polled_io = polled_input_device.polled_io;
400*7c478bd9Sstevel@tonic-gate
401*7c478bd9Sstevel@tonic-gate if (polled_io == NULL || polled_io->cons_polledio_exit == NULL) {
402*7c478bd9Sstevel@tonic-gate return;
403*7c478bd9Sstevel@tonic-gate }
404*7c478bd9Sstevel@tonic-gate
405*7c478bd9Sstevel@tonic-gate /*
406*7c478bd9Sstevel@tonic-gate * Call down to the lower layers to save the state.
407*7c478bd9Sstevel@tonic-gate */
408*7c478bd9Sstevel@tonic-gate polled_io->cons_polledio_exit(
409*7c478bd9Sstevel@tonic-gate polled_io->cons_polledio_argument);
410*7c478bd9Sstevel@tonic-gate }
411*7c478bd9Sstevel@tonic-gate
412*7c478bd9Sstevel@tonic-gate /*
413*7c478bd9Sstevel@tonic-gate * This is the routine that kmdb calls to save any state information
414*7c478bd9Sstevel@tonic-gate * before using the output device. This routine, and all of the
415*7c478bd9Sstevel@tonic-gate * routines that it calls, are responsible for saving any state
416*7c478bd9Sstevel@tonic-gate * information so that it can be restored when polled mode is over.
417*7c478bd9Sstevel@tonic-gate */
418*7c478bd9Sstevel@tonic-gate static void
polled_give_output()419*7c478bd9Sstevel@tonic-gate polled_give_output()
420*7c478bd9Sstevel@tonic-gate {
421*7c478bd9Sstevel@tonic-gate cons_polledio_t *polled_io;
422*7c478bd9Sstevel@tonic-gate
423*7c478bd9Sstevel@tonic-gate /*
424*7c478bd9Sstevel@tonic-gate * We check the dev_ops pointer to see if there is an
425*7c478bd9Sstevel@tonic-gate * output device that has been registered.
426*7c478bd9Sstevel@tonic-gate */
427*7c478bd9Sstevel@tonic-gate polled_io = polled_output_device.polled_io;
428*7c478bd9Sstevel@tonic-gate
429*7c478bd9Sstevel@tonic-gate if (polled_io == NULL || polled_io->cons_polledio_enter == NULL) {
430*7c478bd9Sstevel@tonic-gate return;
431*7c478bd9Sstevel@tonic-gate }
432*7c478bd9Sstevel@tonic-gate
433*7c478bd9Sstevel@tonic-gate /*
434*7c478bd9Sstevel@tonic-gate * Call down to the lower layers to save the state.
435*7c478bd9Sstevel@tonic-gate */
436*7c478bd9Sstevel@tonic-gate polled_io->cons_polledio_enter(
437*7c478bd9Sstevel@tonic-gate polled_io->cons_polledio_argument);
438*7c478bd9Sstevel@tonic-gate }
439*7c478bd9Sstevel@tonic-gate
440*7c478bd9Sstevel@tonic-gate /*
441*7c478bd9Sstevel@tonic-gate * This is the routine that kmdb calls when it is giving up control of the
442*7c478bd9Sstevel@tonic-gate * output device. This routine, and the lower layer routines that it calls,
443*7c478bd9Sstevel@tonic-gate * are responsible for restoring the controller state to the state it was
444*7c478bd9Sstevel@tonic-gate * in before kmdb took control.
445*7c478bd9Sstevel@tonic-gate */
446*7c478bd9Sstevel@tonic-gate static void
polled_take_output(void)447*7c478bd9Sstevel@tonic-gate polled_take_output(void)
448*7c478bd9Sstevel@tonic-gate {
449*7c478bd9Sstevel@tonic-gate cons_polledio_t *polled_io;
450*7c478bd9Sstevel@tonic-gate
451*7c478bd9Sstevel@tonic-gate /*
452*7c478bd9Sstevel@tonic-gate * We check the dev_ops pointer to see if there is an
453*7c478bd9Sstevel@tonic-gate * output device that has been registered.
454*7c478bd9Sstevel@tonic-gate */
455*7c478bd9Sstevel@tonic-gate polled_io = polled_output_device.polled_io;
456*7c478bd9Sstevel@tonic-gate
457*7c478bd9Sstevel@tonic-gate if (polled_io == NULL || polled_io->cons_polledio_exit == NULL) {
458*7c478bd9Sstevel@tonic-gate return;
459*7c478bd9Sstevel@tonic-gate }
460*7c478bd9Sstevel@tonic-gate
461*7c478bd9Sstevel@tonic-gate /*
462*7c478bd9Sstevel@tonic-gate * Call down to the lower layers to save the state.
463*7c478bd9Sstevel@tonic-gate */
464*7c478bd9Sstevel@tonic-gate polled_io->cons_polledio_exit(
465*7c478bd9Sstevel@tonic-gate polled_io->cons_polledio_argument);
466*7c478bd9Sstevel@tonic-gate }
467*7c478bd9Sstevel@tonic-gate #endif /* MAYBE_SOMETIME */
468