1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/console.h>
3 #include <linux/types.h>
4 #include <linux/wait.h>
9 #define SYNTH_BUF_SIZE 8192 /* currently 8K bytes */
11 static u16 synth_buffer
[SYNTH_BUF_SIZE
]; /* guess what this is for! */
12 static u16
*buff_in
= synth_buffer
;
13 static u16
*buff_out
= synth_buffer
;
14 static u16
*buffer_end
= synth_buffer
+ SYNTH_BUF_SIZE
- 1;
16 /* These try to throttle applications by stopping the TTYs
17 * Note: we need to make sure that we will restart them eventually, which is
18 * usually not possible to do from the notifiers. TODO: it should be possible
19 * starting from linux 2.6.26.
21 * So we only stop when we know alive == 1 (else we discard the data anyway),
22 * and the alive synth will eventually call start_ttys from the thread context.
24 void speakup_start_ttys(void)
28 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++) {
29 if (speakup_console
[i
] && speakup_console
[i
]->tty_stopped
)
31 if (vc_cons
[i
].d
&& vc_cons
[i
].d
->port
.tty
)
32 start_tty(vc_cons
[i
].d
->port
.tty
);
35 EXPORT_SYMBOL_GPL(speakup_start_ttys
);
37 static void speakup_stop_ttys(void)
41 for (i
= 0; i
< MAX_NR_CONSOLES
; i
++)
42 if (vc_cons
[i
].d
&& vc_cons
[i
].d
->port
.tty
)
43 stop_tty(vc_cons
[i
].d
->port
.tty
);
46 static int synth_buffer_free(void)
50 if (buff_in
>= buff_out
)
51 chars_free
= SYNTH_BUF_SIZE
- (buff_in
- buff_out
);
53 chars_free
= buff_out
- buff_in
;
57 int synth_buffer_empty(void)
59 return (buff_in
== buff_out
);
61 EXPORT_SYMBOL_GPL(synth_buffer_empty
);
63 void synth_buffer_add(u16 ch
)
66 /* This makes sure that we won't stop TTYs if there is no synth
71 if (synth_buffer_free() <= 100) {
75 if (synth_buffer_free() <= 1)
78 if (buff_in
> buffer_end
)
79 buff_in
= synth_buffer
;
80 /* We have written something to the speech synthesis, so we are not
86 u16
synth_buffer_getc(void)
90 if (buff_out
== buff_in
)
93 if (buff_out
> buffer_end
)
94 buff_out
= synth_buffer
;
97 EXPORT_SYMBOL_GPL(synth_buffer_getc
);
99 u16
synth_buffer_peek(void)
101 if (buff_out
== buff_in
)
105 EXPORT_SYMBOL_GPL(synth_buffer_peek
);
107 void synth_buffer_skip_nonlatin1(void)
109 while (buff_out
!= buff_in
) {
110 if (*buff_out
< 0x100)
113 if (buff_out
> buffer_end
)
114 buff_out
= synth_buffer
;
117 EXPORT_SYMBOL_GPL(synth_buffer_skip_nonlatin1
);
119 void synth_buffer_clear(void)
121 buff_in
= synth_buffer
;
122 buff_out
= synth_buffer
;
124 EXPORT_SYMBOL_GPL(synth_buffer_clear
);