diff options
author | 2015-08-04 12:17:53 -0700 | |
---|---|---|
committer | 2015-08-04 15:44:42 -0700 | |
commit | 9ca8dbcc65cfc63d6f5ef3312a33184e1d726e00 (patch) | |
tree | 1c9cafbcd35f783a87880a10f85d1a060db1a563 /kernel/drivers/staging/speakup/buffers.c | |
parent | 98260f3884f4a202f9ca5eabed40b1354c489b29 (diff) |
Add the rt linux 4.1.3-rt3 as base
Import the rt linux 4.1.3-rt3 as OPNFV kvm base.
It's from git://git.kernel.org/pub/scm/linux/kernel/git/rt/linux-rt-devel.git linux-4.1.y-rt and
the base is:
commit 0917f823c59692d751951bf5ea699a2d1e2f26a2
Author: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
Date: Sat Jul 25 12:13:34 2015 +0200
Prepare v4.1.3-rt3
Signed-off-by: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
We lose all the git history this way and it's not good. We
should apply another opnfv project repo in future.
Change-Id: I87543d81c9df70d99c5001fbdf646b202c19f423
Signed-off-by: Yunhong Jiang <yunhong.jiang@intel.com>
Diffstat (limited to 'kernel/drivers/staging/speakup/buffers.c')
-rw-r--r-- | kernel/drivers/staging/speakup/buffers.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/kernel/drivers/staging/speakup/buffers.c b/kernel/drivers/staging/speakup/buffers.c new file mode 100644 index 000000000..d45c8afb0 --- /dev/null +++ b/kernel/drivers/staging/speakup/buffers.c @@ -0,0 +1,105 @@ +#include <linux/console.h> +#include <linux/types.h> +#include <linux/wait.h> + +#include "speakup.h" +#include "spk_priv.h" + +#define SYNTH_BUF_SIZE 8192 /* currently 8K bytes */ + +static u_char synth_buffer[SYNTH_BUF_SIZE]; /* guess what this is for! */ +static u_char *buff_in = synth_buffer; +static u_char *buff_out = synth_buffer; +static u_char *buffer_end = synth_buffer + SYNTH_BUF_SIZE - 1; + +/* These try to throttle applications by stopping the TTYs + * Note: we need to make sure that we will restart them eventually, which is + * usually not possible to do from the notifiers. TODO: it should be possible + * starting from linux 2.6.26. + * + * So we only stop when we know alive == 1 (else we discard the data anyway), + * and the alive synth will eventually call start_ttys from the thread context. + */ +void speakup_start_ttys(void) +{ + int i; + + for (i = 0; i < MAX_NR_CONSOLES; i++) { + if (speakup_console[i] && speakup_console[i]->tty_stopped) + continue; + if ((vc_cons[i].d != NULL) && (vc_cons[i].d->port.tty != NULL)) + start_tty(vc_cons[i].d->port.tty); + } +} +EXPORT_SYMBOL_GPL(speakup_start_ttys); + +static void speakup_stop_ttys(void) +{ + int i; + + for (i = 0; i < MAX_NR_CONSOLES; i++) + if ((vc_cons[i].d != NULL) && (vc_cons[i].d->port.tty != NULL)) + stop_tty(vc_cons[i].d->port.tty); +} + +static int synth_buffer_free(void) +{ + int bytes_free; + + if (buff_in >= buff_out) + bytes_free = SYNTH_BUF_SIZE - (buff_in - buff_out); + else + bytes_free = buff_out - buff_in; + return bytes_free; +} + +int synth_buffer_empty(void) +{ + return (buff_in == buff_out); +} +EXPORT_SYMBOL_GPL(synth_buffer_empty); + +void synth_buffer_add(char ch) +{ + if (!synth->alive) { + /* This makes sure that we won't stop TTYs if there is no synth + * to restart them */ + return; + } + if (synth_buffer_free() <= 100) { + synth_start(); + speakup_stop_ttys(); + } + if (synth_buffer_free() <= 1) + return; + *buff_in++ = ch; + if (buff_in > buffer_end) + buff_in = synth_buffer; +} + +char synth_buffer_getc(void) +{ + char ch; + + if (buff_out == buff_in) + return 0; + ch = *buff_out++; + if (buff_out > buffer_end) + buff_out = synth_buffer; + return ch; +} +EXPORT_SYMBOL_GPL(synth_buffer_getc); + +char synth_buffer_peek(void) +{ + if (buff_out == buff_in) + return 0; + return *buff_out; +} +EXPORT_SYMBOL_GPL(synth_buffer_peek); + +void synth_buffer_clear(void) +{ + buff_in = buff_out = synth_buffer; +} +EXPORT_SYMBOL_GPL(synth_buffer_clear); |