xref: /illumos-gate/usr/src/uts/sparc/sys/polled_io.h (revision a61ed2ce7a86a4d6428f2a83eb4739fae945447e)
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 /*
23  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef _SYS_POLLED_IO_H
28 #define	_SYS_POLLED_IO_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 typedef struct polled_device {
37 	/*
38 	 * This lock is only used to lock writing from
39 	 * the fields on the structure.  The values in the
40 	 * structure can be read under obp, so the lock
41 	 * isn't valid then.
42 	 */
43 	kmutex_t	polled_device_lock;
44 
45 	/*
46 	 * When we switch over the console, this is the old value
47 	 * so that we can restore it later.
48 	 */
49 	uint64_t	polled_old_handle;
50 
51 	/*
52 	 * Pointer to registerd polled I/O callbacks.
53 	 */
54 	cons_polledio_t	*polled_io;
55 
56 } polled_device_t;
57 
58 _NOTE(MUTEX_PROTECTS_DATA(polled_device_t::polled_device_lock,
59 	polled_device_t))
60 
61 #define	CIF_SUCCESS	((uint_t)0)
62 #define	CIF_FAILURE	((uint_t)-1)
63 
64 /*
65  * The lower layers did not find any characters.
66  */
67 #define	CIF_NO_CHARACTERS	((uint_t)-2)
68 
69 /*
70  * Every CIF has at least 3 arguments:  0 (name), 1 (in args), and 2 (out args).
71  */
72 #define	CIF_MIN_SIZE		3
73 
74 #define	CIF_NAME		0	/* name of function */
75 #define	CIF_NUMBER_IN_ARGS	1	/* number of arguments passed in */
76 #define	CIF_NUMBER_OUT_ARGS	2	/* number of arguments for return */
77 
78 /*
79  * These are the types of polled I/O that this module handles.
80  */
81 typedef enum polled_io_console_type {
82 	POLLED_IO_CONSOLE_INPUT = 0,
83 	POLLED_IO_CONSOLE_OUTPUT = 1
84 } polled_io_console_type_t;
85 
86 /*
87  * Initialize the polled I/O kernel structures
88  */
89 void	polled_io_init(void);
90 
91 /*
92  * De-initialize the polled I/O kernel structures
93  */
94 void	polled_io_fini(void);
95 
96 /*
97  * Register a device to be used as a console for OBP.
98  */
99 int	polled_io_register_callbacks(cons_polledio_t *, int);
100 
101 /*
102  * Unregister a device to be used as a console for OBP.
103  */
104 int	polled_io_unregister_callbacks(cons_polledio_t *, int);
105 
106 void	polled_io_cons_write(uchar_t *, size_t);
107 
108 #ifdef	__cplusplus
109 }
110 #endif
111 
112 #endif	/* _SYS_POLLED_IO_H */
113