kernel: tty: implement tty input using line disciplines

This commit is contained in:
2023-06-11 16:47:33 +01:00
parent 7308fd98fb
commit a7c28e983c
6 changed files with 484 additions and 148 deletions

View File

@@ -1,4 +1,5 @@
#include <socks/tty.h>
#include <socks/input.h>
#include <socks/printk.h>
static void newline(struct device *tty)
@@ -90,3 +91,36 @@ kern_status_t tty_write(struct device *tty, const void *buf, size_t len, size_t
*nr_written = r;
return KERN_OK;
}
static void process_events(struct device *tty)
{
struct tty_device *ttydev = TTY_DEVICE(tty);
if (!ttydev->tty_ldisc || !ttydev->tty_ldisc->process_events) {
struct input_event ev;
while (ringbuffer_unread(&ttydev->tty_events)) {
ringbuffer_read(&ttydev->tty_events, sizeof ev, &ev, S_NOBLOCK);
}
return;
}
ttydev->tty_ldisc->process_events(tty);
}
kern_status_t tty_report_event(struct device *tty, const struct input_event *ev)
{
struct tty_device *ttydev = TTY_DEVICE(tty);
size_t w = ringbuffer_write(&ttydev->tty_events, sizeof *ev, ev, S_NOBLOCK);
if (w != sizeof *ev) {
return KERN_WOULD_BLOCK;
}
if (ringbuffer_unread(&ttydev->tty_events) > 0) {
process_events(tty);
}
return KERN_OK;
}