/* SPDX-License-Identifier: GPL-2.0-only */ #include #include #include #include #include #include #include "flanterm.h" #include "fb.h" static struct flanterm_context *ft_ctx; static void fbcon_putchar(struct tty *tty, char c) { flanterm_write(ft_ctx, &c, 1); if (c == '\n') { c = '\r'; flanterm_write(ft_ctx, &c, 1); } } static char fbcon_getchar(struct tty *tty) { return 0; } static struct tty_serial_ops fbcon_serial_ops = { .serial_putchar = fbcon_putchar, .serial_getchar = fbcon_getchar, }; struct tty *fbcon_init(void) { if (!fb_res || !fb_res->framebuffer_count) return NULL; struct limine_framebuffer *fb = fb_res->framebuffers[0]; size_t fb_size = fb->pitch * fb->height; void *fb_virt = map_mmio_dev((paddr_t)TO_PHYS(fb->address), fb_size); if (!fb_virt) return NULL; ft_ctx = flanterm_fb_init( NULL, NULL, fb_virt, fb->width, fb->height, fb->pitch, fb->red_mask_size, fb->red_mask_shift, fb->green_mask_size, fb->green_mask_shift, fb->blue_mask_size, fb->blue_mask_shift, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 0, 0, 0, 0, 0, 0, FLANTERM_FB_ROTATE_0); if (!ft_ctx) return NULL; struct tty *fbtty = tty_create("tty1", NULL); fbtty->serial_ops = fbcon_serial_ops; kinfo("fbcon: framebuffer console initialized (%lux%lu)\n", fb->width, fb->height); return fbtty; }