PatchworkOS  c9fea19
A non-POSIX operating system.
Loading...
Searching...
No Matches
gop.c
Go to the documentation of this file.
3#include <kernel/init/init.h>
4#include <kernel/log/log.h>
5#include <kernel/log/panic.h>
6#include <kernel/mem/vmm.h>
10
11#include <errno.h>
12#include <string.h>
13#include <sys/fb.h>
14#include <sys/math.h>
15
16/**
17 * @brief GOP (Graphics Output Protocol) driver.
18 * @defgroup modules_drivers_gop GOP Driver
19 * @ingroup modules_drivers
20 *
21 * This module provides a framebuffer device for the GOP framebuffer provided by the bootloader.
22 *
23 * @{
24 */
25
27static fb_t* fb;
28
29static void* gop_mmap(fb_t* fb, void* addr, uint64_t length, uint64_t* offset, pml_flags_t flags)
30{
31 (void)fb; // Unused
32
33 process_t* process = sched_process();
34
35 uintptr_t physAddr = (uint64_t)gop.physAddr + *offset;
36 uintptr_t endAddr = physAddr + length;
37 if (endAddr > (uint64_t)gop.physAddr + (gop.stride * gop.height * sizeof(uint32_t)))
38 {
39 errno = EINVAL;
40 return NULL;
41 }
42
43 addr = vmm_map(&process->space, addr, (void*)physAddr, length, flags, NULL, NULL);
44 if (addr == NULL)
45 {
46 return NULL;
47 }
48 return addr;
49}
50
52
53static uint64_t gop_init(void)
54{
56 if (bootInfo == NULL || bootInfo->gop.virtAddr == NULL)
57 {
58 LOG_ERR("no GOP provided by bootloader");
59 return ERR;
60 }
61
62 gop = bootInfo->gop;
67 strncpy(info.name, "GOP Framebuffer", MAX_NAME - 1);
68 info.name[MAX_NAME - 1] = '\0';
69
71 if (fb == NULL)
72 {
73 LOG_ERR("Failed to create GOP framebuffer");
74 return ERR;
75 }
76
77 LOG_INFO("GOP framebuffer initialized %ux%u\n", info.width, info.height);
78 return 0;
79}
80
81/** @} */
82
84{
85 switch (event->type)
86 {
88 if (gop_init() == ERR)
89 {
90 return ERR;
91 }
92 break;
93 default:
94 break;
95 }
96 return 0;
97}
98
99MODULE_INFO("GOP Driver", "Kai Norberg", "A driver for the GOP framebuffer", OS_VERSION, "MIT", "BOOT_GOP");
#define MAX_NAME
Maximum length of names.
Definition MAX_NAME.h:11
boot_info_t * bootInfo
Definition boot_info.c:14
fb_t * fb_new(const fb_info_t *info, fb_mmap_t mmap)
Allocate and initialize a framebuffer structure.
Definition fb.c:56
boot_info_t * boot_info_get(void)
Gets the boot info structure.
Definition boot_info.c:16
#define LOG_ERR(format,...)
Definition log.h:108
#define LOG_INFO(format,...)
Definition log.h:106
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:226
#define MODULE_INFO(_name, _author, _description, _version, _licence, _deviceTypes)
Macro to define module information.
Definition module.h:200
@ MODULE_EVENT_LOAD
Definition module.h:239
process_t * sched_process(void)
Retrieves the process of the currently running thread.
Definition sched.c:620
#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
#define ERR
Integer error value.
Definition ERR.h:17
static void * gop_mmap(fb_t *fb, void *addr, uint64_t length, uint64_t *offset, pml_flags_t flags)
Definition gop.c:29
static fb_t * fb
Definition gop.c:27
static fb_info_t info
Definition gop.c:51
static uint64_t gop_init(void)
Definition gop.c:53
boot_gop_t * gop
Definition mem.c:18
uint64_t _module_procedure(const module_event_t *event)
Definition gop.c:83
static const path_flag_t flags[]
Definition path.c:42
__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:47
uint32_t * virtAddr
Definition boot_info.h:45
uint32_t height
Definition boot_info.h:48
uint32_t * physAddr
Definition boot_info.h:44
uint32_t stride
Definition boot_info.h:49
boot_gop_t gop
Definition boot_info.h:101
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
module_event_type_t type
Definition module.h:268
A entry in a page table without a specified address or callback ID.
Process structure.
Definition process.h:205
space_t space
Definition process.h:210