From 265d015c932772bdfc67ea1058188f21dc93ed04 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Thu, 18 Apr 2024 15:09:17 -0400 Subject: kernel: fbdev: Create fbdev device file Signed-off-by: Ian Moffett --- sys/dev/video/fbdev.c | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/sys/dev/video/fbdev.c b/sys/dev/video/fbdev.c index 326f548..70031a0 100644 --- a/sys/dev/video/fbdev.c +++ b/sys/dev/video/fbdev.c @@ -29,7 +29,11 @@ #include #include +#include +#include #include +#include +#include #define FRAMEBUFFER \ framebuffer_req.response->framebuffers[0] @@ -39,6 +43,23 @@ static volatile struct limine_framebuffer_request framebuffer_req = { .revision = 0 }; +static struct device *dev; + +static paddr_t +fbdev_mmap(struct device *dev, off_t off, vm_prot_t prot) +{ + struct fbdev fbdev = fbdev_get_front(); + paddr_t len = fbdev.width * fbdev.pitch; + paddr_t base = VIRT_TO_PHYS(fbdev.mem); + paddr_t max_paddr = base + len; + + if (base + off > max_paddr) { + return 0; + } + + return base + off; +} + struct fbdev fbdev_get_front(void) { @@ -49,5 +70,20 @@ fbdev_get_front(void) ret.height = FRAMEBUFFER->height; ret.pitch = FRAMEBUFFER->pitch; return ret; +} +static int +fbdev_init(void) +{ + dev = DEVICE_ALLOC(); + dev->blocksize = 1; + dev->read = NULL; + dev->write = NULL; + dev->mmap = fbdev_mmap; + + device_create(dev, device_alloc_major(), 1); + devfs_add_dev("fb", dev); + return 0; } + +DRIVER_EXPORT(fbdev_init); -- cgit v1.2.3