From 2c08de044fa97d91c6ee1995ebd4140b3877c7fd Mon Sep 17 00:00:00 2001 From: apio Date: Thu, 3 Nov 2022 20:20:22 +0100 Subject: [PATCH] Kernel, libc: Add support for querying the framebuffer's scanline via ioctl() --- kernel/src/fs/devices/Framebuffer.cpp | 33 ++++++++++++--------------- libs/libc/include/sys/ioctl.h | 2 ++ 2 files changed, 17 insertions(+), 18 deletions(-) diff --git a/kernel/src/fs/devices/Framebuffer.cpp b/kernel/src/fs/devices/Framebuffer.cpp index cd198508..b6175650 100644 --- a/kernel/src/fs/devices/Framebuffer.cpp +++ b/kernel/src/fs/devices/Framebuffer.cpp @@ -1,12 +1,12 @@ #include "fs/devices/Framebuffer.h" +#include "bootboot.h" +#include "memory/MemoryManager.h" +#include "misc/utils.h" +#include "std/errno.h" #include "std/stdio.h" #include "std/stdlib.h" #include "std/string.h" -#include "memory/MemoryManager.h" #include "utils/Addresses.h" -#include "misc/utils.h" -#include "std/errno.h" -#include "bootboot.h" extern BOOTBOOT bootboot; extern char fb[1]; @@ -36,39 +36,36 @@ uintptr_t FramebufferDevice::mmap(VFS::Node* node, uintptr_t addr, size_t size, { if (!node) return -1; int real_prot = prot & ~(MAP_AS_OWNED_BY_TASK); - if(round_down_to_nearest_page(offset) != (uintptr_t)offset) - { - return MAP_FAIL(EINVAL); - } - if((size + offset) > bootboot.fb_size) + if (round_down_to_nearest_page(offset) != (uintptr_t)offset) { return MAP_FAIL(EINVAL); } + if ((size + offset) > bootboot.fb_size) { return MAP_FAIL(ERANGE); // FIXME: Should probably be EOVERFLOW. } - MemoryManager::map_several_pages(bootboot.fb_ptr + offset, addr, Utilities::get_blocks_from_size(PAGE_SIZE, size), real_prot); + MemoryManager::map_several_pages(bootboot.fb_ptr + offset, addr, Utilities::get_blocks_from_size(PAGE_SIZE, size), + real_prot); return addr; } ssize_t FramebufferDevice::write(VFS::Node* node, size_t offset, size_t size, const char* buffer) { if (!node) return -1; - if((size + offset) > (uint64_t)bootboot.fb_size) - { - size = (uint64_t)bootboot.fb_size - offset; - } + if ((size + offset) > (uint64_t)bootboot.fb_size) { size = (uint64_t)bootboot.fb_size - offset; } memcpy(fb + offset, buffer, size); return (ssize_t)size; } #define FB_GET_WIDTH 0 #define FB_GET_HEIGHT 1 +#define FB_GET_SCANLINE 2 long FramebufferDevice::ioctl(VFS::Node* node, int cmd, uintptr_t) { if (!node) return -1; - switch(cmd) + switch (cmd) { - case FB_GET_WIDTH: return (long)bootboot.fb_width; - case FB_GET_HEIGHT: return (long)bootboot.fb_height; - default: return -EINVAL; + case FB_GET_WIDTH: return (long)bootboot.fb_width; + case FB_GET_HEIGHT: return (long)bootboot.fb_height; + case FB_GET_SCANLINE: return (long)bootboot.fb_scanline; + default: return -EINVAL; } } \ No newline at end of file diff --git a/libs/libc/include/sys/ioctl.h b/libs/libc/include/sys/ioctl.h index 1c1cb1e9..2de4dac5 100644 --- a/libs/libc/include/sys/ioctl.h +++ b/libs/libc/include/sys/ioctl.h @@ -7,6 +7,8 @@ #define FB_GET_WIDTH 0 /* Get the height of a framebuffer device. */ #define FB_GET_HEIGHT 1 +/* Get the scanline of a framebuffer device. */ +#define FB_GET_SCANLINE 2 #ifdef __cplusplus extern "C"