vbos/drivers/tty/tty.c
Michael Shaw f177a8e65d tty: make ops struct not a pointer
Signed-off-by: Michael Shaw <m@michaelsshaw.com>
2026-07-11 23:54:48 -04:00

49 lines
1,017 B
C

/* SPDX-License-Identifier: GPL-2.0-only */
#include <kernel/device.h>
#include <kernel/common.h>
#include <kernel/slab.h>
#include <drivers/serial.h>
#include <drivers/tty.h>
static mem_cache_t *tty_slab;
static struct tty_serial_ops arch_serial_ops = {.serial_getchar = arch_serial_read, .serial_putchar = arch_serial_write};
struct tty *tty_create(const char *name, void *priv)
{
struct tty *tty = slab_alloc(tty_slab);
dev_t tty_device = device_create(tty, DEV_CLASS_TTY, name);
tty->dev = tty_device;
tty->priv = priv;
tty->serial_ops = arch_serial_ops;
return tty;
}
void tty_putchar(struct tty *tty, char c)
{
tty->serial_ops.serial_putchar(tty, c);
}
char tty_getchar(struct tty *tty)
{
return tty->serial_ops.serial_getchar(tty);
}
void tty_write(struct tty *tty, const char *s)
{
char c;
while ((c = *s++))
tty_putchar(tty, c);
}
void tty_layer_init()
{
tty_slab = slab_create("tty_layer", sizeof(struct tty), 256 * KB, 8);
if (!tty_slab) {
panic("tty_slab alloc failed\n");
}
}