PatchworkOS  19e446b
A non-POSIX operating system.
Loading...
Searching...
No Matches
gop.c
Go to the documentation of this file.
2#include <kernel/fs/vfs.h>
4#include <kernel/init/init.h>
5#include <kernel/log/log.h>
6#include <kernel/log/panic.h>
7#include <kernel/log/screen.h>
8#include <kernel/mem/vmm.h>
10#include <kernel/proc/process.h>
11#include <kernel/sched/sched.h>
12
13#include <errno.h>
14#include <string.h>
15#include <sys/math.h>
16
17/**
18 * @brief GOP (Graphics Output Protocol) driver.
19 * @defgroup kernel_drivers_gop GOP Driver
20 * @ingroup kernel_drivers
21 *
22 * This module provides a framebuffer device for the GOP framebuffer provided by the bootloader.
23 *
24 * @{
25 */
26
28static fb_t* fb;
29
31{
32 UNUSED(fb);
33
34 info->width = gop.width;
35 info->height = gop.height;
36 info->pitch = gop.stride * sizeof(uint32_t);
37 strncpy(info->format, "B8G8R8A8", sizeof(info->format));
38 return 0;
39}
40
41static size_t gop_read(fb_t* fb, void* buffer, size_t count, size_t* offset)
42{
43 UNUSED(fb);
44
46
47 size_t fbSize = gop.height * gop.stride * sizeof(uint32_t);
48 return BUFFER_READ(buffer, count, offset, ((uint8_t*)gop.virtAddr), fbSize);
49}
50
51static size_t gop_write(fb_t* fb, const void* buffer, size_t count, size_t* offset)
52{
53 UNUSED(fb);
54
56
57 size_t fbSize = gop.height * gop.stride * sizeof(uint32_t);
58 return BUFFER_WRITE(buffer, count, offset, ((uint8_t*)gop.virtAddr), fbSize);
59}
60
61static void* gop_mmap(fb_t* fb, void* addr, size_t length, size_t* offset, pml_flags_t flags)
62{
63 UNUSED(fb);
64
66
67 process_t* process = process_current();
68
69 uintptr_t physAddr = (uintptr_t)gop.physAddr + *offset;
70 phys_addr_t endAddr = physAddr + length;
71 if (endAddr > gop.physAddr + (gop.stride * gop.height * sizeof(uint32_t)))
72 {
73 errno = EINVAL;
74 return NULL;
75 }
76
77 return vmm_map(&process->space, addr, physAddr, length, flags, NULL, NULL);
78}
79
80static fb_ops_t ops = {
81 .info = gop_info,
82 .read = gop_read,
83 .write = gop_write,
84 .mmap = gop_mmap,
85};
86
87static uint64_t gop_init(void)
88{
90 if (bootInfo == NULL || bootInfo->gop.virtAddr == NULL)
91 {
92 LOG_ERR("no GOP provided by bootloader");
93 return ERR;
94 }
95
96 gop = bootInfo->gop;
97 fb = fb_new("Graphics Output Protocol", &ops, NULL);
98 if (fb == NULL)
99 {
100 LOG_ERR("failed to create GOP framebuffer");
101 return ERR;
102 }
103
104 return 0;
105}
106
107/** @} */
108
110{
111 switch (event->type)
112 {
114 if (gop_init() == ERR)
115 {
116 return ERR;
117 }
118 break;
119 default:
120 break;
121 }
122 return 0;
123}
124
125MODULE_INFO("GOP Driver", "Kai Norberg", "A driver for the GOP framebuffer", OS_VERSION, "MIT", "BOOT_GOP");
EFI_PHYSICAL_ADDRESS buffer
Definition main.c:237
boot_info_t * bootInfo
Definition boot_info.c:14
uint64_t _module_procedure(const module_event_t *event)
Definition gop.c:109
fb_t * fb_new(const char *name, const fb_ops_t *ops, void *data)
Allocate and initialize a new framebuffer.
Definition fb.c:134
static uint64_t gop_info(fb_t *fb, fb_info_t *info)
Definition gop.c:30
static fb_ops_t ops
Definition gop.c:80
static boot_gop_t gop
Definition gop.c:27
static fb_t * fb
Definition gop.c:28
static void * gop_mmap(fb_t *fb, void *addr, size_t length, size_t *offset, pml_flags_t flags)
Definition gop.c:61
static size_t gop_read(fb_t *fb, void *buffer, size_t count, size_t *offset)
Definition gop.c:41
static uint64_t gop_init(void)
Definition gop.c:87
static size_t gop_write(fb_t *fb, const void *buffer, size_t count, size_t *offset)
Definition gop.c:51
boot_info_t * boot_info_get(void)
Gets the boot info structure.
Definition boot_info.c:16
void screen_hide(void)
Hide the screen logging.
Definition screen.c:195
#define LOG_ERR(format,...)
Definition log.h:93
uintptr_t phys_addr_t
Physical address type.
void * vmm_map(space_t *space, void *virtAddr, phys_addr_t physAddr, size_t length, pml_flags_t flags, space_callback_func_t func, void *data)
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
static process_t * process_current(void)
Retrieves the process of the currently running thread.
Definition process.h:131
#define BUFFER_WRITE(buffer, count, offset, dest, size)
Helper macro for implementing file operations dealing with simple buffer writes.
Definition vfs.h:227
#define BUFFER_READ(buffer, count, offset, src, size)
Helper macros for implementing file operations dealing with simple buffers.
Definition vfs.h:209
#define EINVAL
Invalid argument.
Definition errno.h:142
#define errno
Error number variable.
Definition errno.h:27
#define UNUSED(x)
Mark a variable as unused.
Definition defs.h:96
#define NULL
Pointer error value.
Definition NULL.h:25
#define ERR
Integer error value.
Definition ERR.h:17
static uint64_t offset
Definition screen.c:19
static const path_flag_t flags[]
Definition path.c:47
static atomic_long count
Definition main.c:11
__UINT32_TYPE__ uint32_t
Definition stdint.h:15
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
__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
size_t stride
Definition boot_info.h:49
phys_addr_t physAddr
Definition boot_info.h:44
uint32_t * virtAddr
Definition boot_info.h:45
size_t width
Definition boot_info.h:47
size_t height
Definition boot_info.h:48
boot_gop_t gop
Definition boot_info.h:101
Framebuffer information.
Definition fb.h:51
char format[MAX_PATH]
Definition fb.h:55
size_t height
Definition fb.h:53
size_t pitch
Definition fb.h:54
size_t width
Definition fb.h:52
Framebuffer operations.
Definition fb.h:63
uint64_t(* info)(fb_t *fb, fb_info_t *info)
Definition fb.h:64
Framebuffer structure.
Definition fb.h:76
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:76
space_t space
Definition process.h:84