PatchworkOS
Loading...
Searching...
No Matches
gop.c
Go to the documentation of this file.
2
4#include <kernel/log/log.h>
5#include <kernel/log/panic.h>
6#include <kernel/mem/vmm.h>
9
10#include <assert.h>
11#include <errno.h>
12#include <string.h>
13#include <sys/fb.h>
14#include <sys/math.h>
15
17static fb_t* fb;
18
19static void* gop_mmap(fb_t* fb, void* addr, uint64_t length, uint64_t* offset, pml_flags_t flags)
20{
21 (void)fb; // Unused
22
23 process_t* process = sched_process();
24
25 uintptr_t physAddr = (uint64_t)gop.physAddr + *offset;
26 uintptr_t endAddr = physAddr + length;
27 if (endAddr > (uint64_t)gop.physAddr + (gop.stride * gop.height * sizeof(uint32_t)))
28 {
29 errno = EINVAL;
30 return NULL;
31 }
32
33 addr = vmm_map(&process->space, addr, (void*)physAddr, length, flags, NULL, NULL);
34 if (addr == NULL)
35 {
36 return NULL;
37 }
38 return addr;
39}
40
42
43void gop_init(const boot_gop_t* in)
44{
45 gop = *in;
46 info.width = in->width;
47 info.height = in->height;
48 info.stride = in->stride;
50 strncpy(info.name, "GOP Framebuffer", MAX_NAME - 1);
51 info.name[MAX_NAME - 1] = '\0';
52
54 if (fb == NULL)
55 {
56 panic(NULL, "Failed to create GOP framebuffer");
57 }
58}
#define MAX_NAME
Maximum length of names.
Definition MAX_NAME.h:11
fb_t * fb_new(const fb_info_t *info, fb_mmap_t mmap)
Allocate and initialize a framebuffer structure.
Definition fb.c:56
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
Definition panic.c:362
void * vmm_map(space_t *space, void *virtAddr, void *physAddr, uint64_t length, pml_flags_t flags, space_callback_func_t func, void *private)
Maps physical memory to virtual memory in a given address space.
Definition vmm.c:231
process_t * sched_process(void)
Retrieves the process of the currently running thread.
Definition sched.c:164
#define EINVAL
Invalid argument.
Definition errno.h:142
#define errno
Error number variable.
Definition errno.h:27
@ FB_ARGB32
Definition fb.h:29
#define NULL
Pointer error value.
Definition NULL.h:23
static void * gop_mmap(fb_t *fb, void *addr, uint64_t length, uint64_t *offset, pml_flags_t flags)
Definition gop.c:19
static fb_t * fb
Definition gop.c:17
void gop_init(const boot_gop_t *in)
Definition gop.c:43
static fb_info_t info
Definition gop.c:41
boot_gop_t * gop
Definition mem.c:18
__UINT32_TYPE__ uint32_t
Definition stdint.h:15
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINTPTR_TYPE__ uintptr_t
Definition stdint.h:43
_PUBLIC char * strncpy(char *_RESTRICT s1, const char *_RESTRICT s2, size_t n)
Definition strncpy.c:3
uint32_t width
Definition boot_info.h:36
uint32_t height
Definition boot_info.h:37
uint32_t * physAddr
Definition boot_info.h:33
uint32_t stride
Definition boot_info.h:38
Framebuffer info struct.
Definition fb.h:39
uint64_t width
Definition fb.h:40
fb_format_t format
Definition fb.h:43
uint64_t stride
Definition fb.h:42
char name[MAX_NAME]
Definition fb.h:44
uint64_t height
Definition fb.h:41
Framebuffer structure.
Definition fb.h:34
A entry in a page table without a specified address or callback ID.
Process structure.
Definition process.h:53
space_t space
Definition process.h:59