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