PatchworkOS
Loading...
Searching...
No Matches
gop.c
Go to the documentation of this file.
1#include "gop.h"
2#include "mem.h"
3
4#include <boot/boot_info.h>
6#include <stddef.h>
7#include <stdint.h>
8#include <sys/proc.h>
9
10static void gop_select_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL* gop, int64_t width, int64_t height)
11{
12 uint64_t bestMatch = UINT64_MAX;
13 uint64_t bestDistance = UINT64_MAX;
14 for (uint64_t i = 0; i < gop->Mode->MaxMode; ++i)
15 {
16 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION* info;
17 uint64_t size;
18 uefi_call_wrapper(gop->QueryMode, 4, gop, i, &size, &info);
19
20 // Note: The distance is squared but it does not matter as we are only doing comparisons.
21 int64_t xOffset = (int64_t)info->HorizontalResolution - width;
22 int64_t yOffset = (int64_t)info->VerticalResolution - height;
23 uint64_t distance = xOffset * xOffset + yOffset * yOffset;
24 if (distance < bestDistance)
25 {
26 bestMatch = i;
27 bestDistance = distance;
28 }
29 }
30
31 uefi_call_wrapper(gop->SetMode, 2, gop, bestMatch);
32}
33
35{
36 Print(L"Locating GOP... ");
37 EFI_GRAPHICS_OUTPUT_PROTOCOL* gop;
38 EFI_GUID guid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
39 EFI_STATUS status = uefi_call_wrapper(BS->LocateProtocol, 3, &guid, 0, (void**)&gop);
40 if (EFI_ERROR(status))
41 {
42 Print(L"failed to locate GOP!\n");
43 return status;
44 }
45
46#if !(GOP_USE_DEFAULT_RES)
48#endif
49 buffer->physAddr = (uint32_t*)gop->Mode->FrameBufferBase;
50 buffer->virtAddr = (uint32_t*)PML_LOWER_TO_HIGHER(gop->Mode->FrameBufferBase);
51 buffer->size = gop->Mode->FrameBufferSize;
52 buffer->width = gop->Mode->Info->HorizontalResolution;
53 buffer->height = gop->Mode->Info->VerticalResolution;
54 buffer->stride = gop->Mode->Info->PixelsPerScanLine;
55 Print(L"located buffer width=%d, height=%d, stride=%d... ", buffer->width, buffer->height, buffer->stride);
56
57 Print(L"done!\n");
58 return EFI_SUCCESS;
59}
static void gop_select_mode(EFI_GRAPHICS_OUTPUT_PROTOCOL *gop, int64_t width, int64_t height)
Definition gop.c:10
EFI_STATUS gop_buffer_init(boot_gop_t *buffer)
Definition gop.c:34
#define PML_LOWER_TO_HIGHER(addr)
Converts an address from the lower half to the higher half.
static fb_info_t info
Definition gop.c:41
boot_gop_t * gop
Definition mem.c:18
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
#define GOP_WIDTH
Definition gop.h:7
#define GOP_HEIGHT
Definition gop.h:8
__UINT32_TYPE__ uint32_t
Definition stdint.h:15
__UINT64_TYPE__ uint64_t
Definition stdint.h:17
#define UINT64_MAX
Definition stdint.h:74
__INT64_TYPE__ int64_t
Definition stdint.h:16
uint32_t width
Definition boot_info.h:36
uint32_t height
Definition boot_info.h:37
uint32_t stride
Definition boot_info.h:38