summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Moffett <ian@osmora.org>2024-04-18 15:09:17 -0400
committerIan Moffett <ian@osmora.org>2024-04-18 15:09:17 -0400
commit265d015c932772bdfc67ea1058188f21dc93ed04 (patch)
tree7312ecf87ad4cf88804f3f84f940005fdab637f2
parent7d17d800d4462a42455b9ac825306acdca6c2a83 (diff)
kernel: fbdev: Create fbdev device file
Signed-off-by: Ian Moffett <ian@osmora.org>
-rw-r--r--sys/dev/video/fbdev.c36
1 files changed, 36 insertions, 0 deletions
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 <sys/types.h>
#include <sys/limine.h>
+#include <sys/device.h>
+#include <sys/driver.h>
#include <dev/video/fbdev.h>
+#include <vm/vm.h>
+#include <fs/devfs.h>
#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);