xref: /illumos-gate/usr/src/uts/common/sys/beep.h (revision 012e6ce759c490003aed29439cc47d3d73a99ad3)
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  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef _SYS_BEEP_H
27 #define	_SYS_BEEP_H
28 
29 #include <sys/mutex.h>
30 
31 /*
32  * Interface to the system beeper.
33  *
34  * (This is the API, not the hardware interface.)
35  */
36 
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40 
41 #if	defined(_KERNEL)
42 
43 /* beep_entry structure */
44 
45 typedef struct beep_entry {
46 	unsigned short  frequency;
47 	unsigned short  duration;
48 } beep_entry_t;
49 
50 typedef void (*beep_on_func_t)(void *arg);
51 
52 typedef void (*beep_off_func_t)(void *arg);
53 
54 typedef void (*beep_freq_func_t)(void *arg, int freq);
55 
56 /* beep_state structure */
57 
58 typedef struct beep_state {
59 
60 	/* Private data for beep_freq, beep_on, and beep_off functions */
61 	void		*arg;
62 
63 	/* Indicates if a beep command is already in progress */
64 	enum		{BEEP_UNINIT = 0, BEEP_OFF = 1,
65 			    BEEP_TIMED = 2, BEEP_ON = 3} mode;
66 
67 	/* Address of the hw-dependent beep_freq function */
68 	beep_freq_func_t beep_freq;
69 
70 	/* Address of the hw-dependent beep_on function */
71 	beep_on_func_t	beep_on;
72 
73 	/* Address of the hw-dependent beep_off function */
74 	beep_off_func_t	beep_off;
75 
76 	/* Timeout id for the beep_timeout() function */
77 	timeout_id_t	timeout_id;
78 
79 	/* Mutex protecting mode, timeout_id, queue_head, queue_tail, */
80 	/* and queue */
81 	kmutex_t	mutex;
82 
83 	/* Index of head of queue */
84 	int		queue_head;
85 
86 	/* Index of tail of queue */
87 	int		queue_tail;
88 
89 	/* Max queue size */
90 	int		queue_size;
91 
92 	/* Circular ring buffer */
93 	beep_entry_t	*queue;
94 } beep_state_t;
95 
96 #define	BEEP_QUEUE_SIZE	1000
97 
98 /* BEEP_DEFAULT is a sentinel for the beep_param table. */
99 enum beep_type { BEEP_DEFAULT = 0, BEEP_CONSOLE = 1, BEEP_TYPE4 = 2 };
100 
101 typedef struct beep_params {
102 	enum beep_type	type;
103 	int		frequency;	/* Hz */
104 	int		duration;	/* milliseconds */
105 } beep_params_t;
106 
107 
108 extern int beep_init(void *arg,
109     beep_on_func_t beep_on_func,
110     beep_off_func_t beep_off_func,
111     beep_freq_func_t beep_freq_func);
112 
113 extern int beep_fini(void);
114 
115 extern int beeper_off(void);
116 
117 extern int beeper_freq(enum beep_type type, int freq);
118 
119 extern int beep(enum beep_type type);
120 
121 extern int beep_polled(enum beep_type type);
122 
123 extern int beeper_on(enum beep_type type);
124 
125 extern int beep_mktone(int frequency, int duration);
126 
127 extern void beep_timeout(void *arg);
128 
129 extern int beep_busy(void);
130 
131 #endif	/* _KERNEL */
132 
133 #ifdef __cplusplus
134 }
135 #endif
136 
137 #endif /* _SYS_BEEP_H */
138