aboutsummaryrefslogtreecommitdiff
path: root/kernel/drivers/vbe.c
diff options
context:
space:
mode:
authorMarvin Borner2021-05-20 22:18:35 +0200
committerMarvin Borner2021-05-20 22:19:20 +0200
commitd8d17375291f89d37cad43df36c11d9c132e23be (patch)
treeed6ba70ac6bd6b4e50dde6e1a0b2d62b7881e721 /kernel/drivers/vbe.c
parent298aaf63f15350e6248d5a96e8c6a63b0ec93e0f (diff)
Added BGA driver and generic FB wrapper
Diffstat (limited to 'kernel/drivers/vbe.c')
-rw-r--r--kernel/drivers/vbe.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/kernel/drivers/vbe.c b/kernel/drivers/vbe.c
index b384936..fd91062 100644
--- a/kernel/drivers/vbe.c
+++ b/kernel/drivers/vbe.c
@@ -5,6 +5,7 @@
#include <drivers/cpu.h>
#include <drivers/vbe.h>
#include <errno.h>
+#include <fb.h>
#include <io.h>
#include <mem.h>
#include <mm.h>
@@ -12,8 +13,6 @@
#include <str.h>
#include <sys.h>
-#define FB_SIZE (vbe->height * vbe->pitch)
-
struct vbe_basic {
u8 stuff1[16];
u16 pitch;
@@ -24,15 +23,7 @@ struct vbe_basic {
u8 stuff3[212];
};
-PROTECTED static struct vbe_basic *vbe = NULL;
-
-static u32 vbe_map_buffer(struct page_dir *dir)
-{
- assert(vbe);
- struct memory_range r =
- virtual_alloc(dir, memory_range_around((u32)vbe->fb, FB_SIZE), MEMORY_USER);
- return r.base;
-}
+PROTECTED static struct fb_generic generic = { 0 };
static u32 fb_owner = 0;
static res vbe_control(u32 request, void *arg1, void *arg2, void *arg3)
@@ -41,10 +32,10 @@ static res vbe_control(u32 request, void *arg1, void *arg2, void *arg3)
switch (request) {
case IOCTL_FB_GET: {
- if (!vbe)
+ if (!generic.fb)
return -ENOENT;
- u32 size = MIN(sizeof(*vbe), (u32)arg2);
+ u32 size = MIN(sizeof(generic), (u32)arg2);
if (!memory_writable_range(memory_range(arg1, size)))
return -EFAULT;
@@ -52,11 +43,11 @@ static res vbe_control(u32 request, void *arg1, void *arg2, void *arg3)
return -EBUSY;
fb_owner = proc_current()->pid;
- u32 fb = vbe_map_buffer(proc_current()->page_dir);
+ u32 fb = fb_map_buffer(proc_current()->page_dir, &generic);
stac();
- memcpy(arg1, vbe, size);
- ((struct vbe_basic *)arg1)->fb = (u8 *)fb;
+ memcpy(arg1, &generic, size);
+ ((struct fb_generic *)arg1)->fb = (u8 *)fb;
clac();
return EOK;
@@ -68,12 +59,15 @@ static res vbe_control(u32 request, void *arg1, void *arg2, void *arg3)
CLEAR void vbe_install(u32 data)
{
- vbe = (void *)data;
+ struct vbe_basic *vbe = (void *)data;
+ generic.bpp = (vbe->pitch / vbe->width) << 3;
+ generic.pitch = vbe->pitch;
+ generic.width = vbe->width;
+ generic.height = vbe->height;
+ generic.fb = vbe->fb;
+ fb_protect(&generic);
struct io_dev *dev = zalloc(sizeof(*dev));
dev->control = vbe_control;
io_add(IO_FRAMEBUFFER, dev);
-
- // Set framebuffer range used to prevent unwanted writing
- physical_set_used(memory_range_around((u32)vbe->fb, FB_SIZE));
}