From d06eca1772190435e5dcb370db734653d3989bc8 Mon Sep 17 00:00:00 2001 From: Ian Moffett Date: Wed, 24 Apr 2024 19:52:56 -0400 Subject: kernel: fbdev: Add framebuffer ioctl Signed-off-by: Ian Moffett --- sys/dev/video/fbdev.c | 24 ++++++++++++++++++++++++ sys/include/dev/video/fbdev.h | 9 +++++++++ 2 files changed, 33 insertions(+) (limited to 'sys') diff --git a/sys/dev/video/fbdev.c b/sys/dev/video/fbdev.c index 1f20ab6..af020a1 100644 --- a/sys/dev/video/fbdev.c +++ b/sys/dev/video/fbdev.c @@ -31,6 +31,8 @@ #include #include #include +#include +#include #include #include #include @@ -45,6 +47,27 @@ static volatile struct limine_framebuffer_request framebuffer_req = { static struct device *dev; +static int +fbdev_ioctl(struct device *dev, uint32_t cmd, uintptr_t arg) +{ + struct fbdev_info info = { + .width = FRAMEBUFFER->width, + .height = FRAMEBUFFER->height, + .pitch = FRAMEBUFFER->pitch, + .bits_per_pixel = FRAMEBUFFER->bpp + }; + + switch (cmd) { + case FBIOCTL_INFO: + copyout(&info, arg, sizeof(info)); + break; + default: + return -EINVAL; + } + + return 0; +} + static paddr_t fbdev_mmap(struct device *dev, off_t off, vm_prot_t prot) { @@ -80,6 +103,7 @@ fbdev_init(void) dev->read = NULL; dev->write = NULL; dev->mmap = fbdev_mmap; + dev->ioctl = fbdev_ioctl; device_create(dev, device_alloc_major(), 1); devfs_add_dev("fb", dev); diff --git a/sys/include/dev/video/fbdev.h b/sys/include/dev/video/fbdev.h index 123182f..e9c9282 100644 --- a/sys/include/dev/video/fbdev.h +++ b/sys/include/dev/video/fbdev.h @@ -32,6 +32,15 @@ #include +#define FBIOCTL_INFO 0x00000000 + +struct fbdev_info { + uint32_t width; + uint32_t height; + uint32_t pitch; + uint32_t bits_per_pixel; +}; + struct fbdev { void *mem; uint32_t width; -- cgit v1.2.3