From b049f7b4360a73fcdc44a4dd801bfec4579381bb Mon Sep 17 00:00:00 2001 From: Matheus Date: Fri, 30 Sep 2022 19:37:41 -0300 Subject: [PATCH] framebuffer: ioctls --- src/video/framebuffer.c | 137 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 136 insertions(+), 1 deletion(-) diff --git a/src/video/framebuffer.c b/src/video/framebuffer.c index b953293b..71b5eb04 100644 --- a/src/video/framebuffer.c +++ b/src/video/framebuffer.c @@ -70,9 +70,144 @@ static int isseekable(int minor, size_t* max){ return 0; } +#define FBIOGET_VSCREENINFO 0x4600 +#define FBIOGET_FSCREENINFO 0x4602 + +struct fb_bitfield { + uint32_t offset; + uint32_t length; + uint32_t msb_right; +}; + +typedef struct{ + uint32_t xres; + uint32_t yres; + uint32_t xres_virtual; + uint32_t yres_virtual; + uint32_t xoffset; + uint32_t yoffset; + uint32_t bits_per_pixel; + uint32_t grayscale; + struct fb_bitfield red; + struct fb_bitfield green; + struct fb_bitfield blue; + struct fb_bitfield transp; + uint32_t nonstd; + uint32_t activate; + uint32_t height; + uint32_t width; + uint32_t accel_flags; + uint32_t pixclock; + uint32_t left_margin; + uint32_t right_margin; + uint32_t upper_margin; + uint32_t lower_margin; + uint32_t hsync_len; + uint32_t vsync_len; + uint32_t sync; + uint32_t vmode; + uint32_t rotate; + uint32_t colorspace; + uint32_t reserved[4]; +}fb_var_screeninfo; + +typedef struct { + char id[16]; + unsigned long smem_start; + uint32_t smem_len; + uint32_t type; + uint32_t type_aux; + uint32_t visual; + uint16_t xpanstep; + uint16_t ypanstep; + uint16_t ywrapstep; + uint32_t line_length; + unsigned long mmio_start; + uint32_t mmio_len; + uint32_t accel; + uint16_t capabilities; + uint16_t reserved[2]; +} fb_fix_screeninfo; + +#define FB_VISUAL_TRUECOLOR 2 +#define FB_TYPE_PACKED_PIXELS 0 + + +static int ioctl(int minor, unsigned long req, void* arg){ + + if(minor >= fbcount) + return ENODEV; + + struct limine_framebuffer* fb = fbs[minor]; + switch(req){ + case FBIOGET_FSCREENINFO: + { + fb_fix_screeninfo* i = arg; + strcpy(i->id, "LIMINE FB"); + i->smem_start = fb->address; + i->smem_len = fb->pitch*fb->height; + i->type = FB_TYPE_PACKED_PIXELS; + i->visual = FB_VISUAL_TRUECOLOR; + i->xpanstep = 0; + i->ypanstep = 0; + i->line_length = fb->pitch; + i->mmio_start = 0; + i->mmio_len = 0; + i->accel = 0; + i->capabilities = 0; + } + break; + case FBIOGET_VSCREENINFO: + { + fb_var_screeninfo* i = arg; + i->xres = fb->width; + i->yres = fb->height; + i->xres_virtual = fb->width; + i->yres_virtual = fb->height; + i->xoffset = 0; + i->yoffset = 0; + i->bits_per_pixel = fb->bpp; + i->grayscale = 0; + i->red.msb_right = 1; + i->green.msb_right = 1; + i->blue.msb_right = 1; + i->transp.msb_right = 1; + i->red.offset = fb->red_mask_shift; + i->red.length = fb->red_mask_size; + i->blue.offset = fb->blue_mask_shift; + i->blue.length = fb->blue_mask_size; + i->green.offset = fb->green_mask_shift; + i->green.length = fb->green_mask_size; + i->transp.offset = 28; + i->transp.length = 8; + i->nonstd = 0; + i->activate = 0; + i->height = 0; + i->width = 0; + i->accel_flags = 0; + i->pixclock = 0; + i->left_margin = 0; + i->upper_margin = 0; + i->lower_margin = 0; + i->right_margin = 0; + i->hsync_len = 0; + i->vsync_len = 0; + i->vmode = 0; + i->rotate = 0; + i->colorspace = 0; + } + break; + default: + return ENOTTY; + } + + return 0; + +} + static devcalls calls = { - read, write, isatty, isseekable + read, write, isatty, isseekable, ioctl }; void fb_init(){