xref: /openbsd/sys/dev/cons.h (revision 0f9e9ec2)
1 /*	$OpenBSD: cons.h,v 1.20 2024/05/13 01:15:50 jsg Exp $	*/
2 /*	$NetBSD: cons.h,v 1.14 1996/03/14 19:08:35 christos Exp $	*/
3 
4 /*
5  * Copyright (c) 1988 University of Utah.
6  * Copyright (c) 1990, 1993
7  *	The Regents of the University of California.  All rights reserved.
8  *
9  * This code is derived from software contributed to Berkeley by
10  * the Systems Programming Group of the University of Utah Computer
11  * Science Department.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  * from: Utah $Hdr: cons.h 1.6 92/01/21$
38  *
39  *	@(#)cons.h	8.1 (Berkeley) 6/10/93
40  */
41 
42 struct consdev {
43 				/* probe hardware and fill in consdev info */
44 	void	(*cn_probe)(struct consdev *);
45 				/* turn on as console */
46 	void	(*cn_init)(struct consdev *);
47 				/* kernel getchar interface */
48 	int	(*cn_getc)(dev_t);
49 				/* kernel putchar interface */
50 	void	(*cn_putc)(dev_t, int);
51 				/* turn on and off polling */
52 	void	(*cn_pollc)(dev_t, int);
53 				/* ring bell */
54 	void	(*cn_bell)(dev_t, u_int, u_int, u_int);
55 	dev_t	cn_dev;		/* major/minor of device */
56 	u_int	cn_pri;		/* picking order; the higher the better */
57 };
58 
59 /* Values for cn_pri - policy for console selection. */
60 #define	CN_DEAD		0	/* Device does not exist. */
61 #define CN_LOWPRI	1	/* Device exists and is low priority. */
62 #define CN_MIDPRI	2	/* Device exists and is medium priority. */
63 #define CN_HIGHPRI	3	/* Device exists and is high priority. */
64 #define	CN_FORCED	4	/* Use this device. */
65 
66 /* XXX */
67 #define	CONSMAJOR	0
68 
69 #ifdef _KERNEL
70 
71 extern	struct consdev constab[];
72 extern	struct consdev *cn_tab;
73 extern	struct tty *constty;
74 extern	struct vnode *cn_devvp;
75 
76 struct knote;
77 
78 void	cninit(void);
79 int	cnopen(dev_t, int, int, struct proc *);
80 int	cnclose(dev_t, int, int, struct proc *);
81 int	cnread(dev_t, struct uio *, int);
82 int	cnwrite(dev_t, struct uio *, int);
83 int	cnioctl(dev_t, u_long, caddr_t, int, struct proc *);
84 int	cnkqfilter(dev_t, struct knote *);
85 int	cngetc(void);
86 void	cnputc(int);
87 void	cnpollc(int);
88 void	cnbell(u_int, u_int, u_int);
89 void	nullcnpollc(dev_t, int);
90 
91 /* console-specific types */
92 #define	dev_type_cnprobe(n)	void n(struct consdev *)
93 #define	dev_type_cninit(n)	void n(struct consdev *)
94 #define	dev_type_cngetc(n)	int n(dev_t)
95 #define	dev_type_cnputc(n)	void n(dev_t, int)
96 #define	dev_type_cnpollc(n)	void n(dev_t, int)
97 #define	dev_type_cnbell(n)	void n(dev_t, u_int, u_int, u_int)
98 
99 #define	cons_decl(n) \
100 	dev_decl(n,cnprobe); dev_decl(n,cninit); dev_decl(n,cngetc); \
101 	dev_decl(n,cnputc); dev_decl(n,cnpollc); dev_decl(n,cnbell);
102 
103 #define	cons_init(n) { \
104 	dev_init(1,n,cnprobe), dev_init(1,n,cninit), dev_init(1,n,cngetc), \
105 	dev_init(1,n,cnputc), dev_init(1,n,cnpollc), NULL, \
106 	NODEV, CN_DEAD }
107 
108 #define cons_init_bell(n) { \
109 	dev_init(1,n,cnprobe), dev_init(1,n,cninit), dev_init(1,n,cngetc), \
110 	dev_init(1,n,cnputc), dev_init(1,n,cnpollc), dev_init(1,n,cnbell), \
111 	NODEV, CN_DEAD }
112 
113 #endif
114