Skip to content

Commit ae003dd

Browse files
[FREELDR] Implement Apple Screen Info Protocol
1 parent 8bfa728 commit ae003dd

File tree

3 files changed

+98
-2
lines changed

3 files changed

+98
-2
lines changed

boot/freeldr/freeldr/arch/uefi/uefivid.c

Lines changed: 72 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
#include <uefildr.h>
9+
#include <drivers/bootvid/framebuf.h>
910

1011
#include <debug.h>
1112
DBG_DEFAULT_CHANNEL(WARNING);
@@ -24,12 +25,14 @@ extern UCHAR BitmapFont8x16[256 * 16];
2425
UCHAR MachDefaultTextColor = COLOR_GRAY;
2526
REACTOS_INTERNAL_BGCONTEXT framebufferData;
2627
EFI_GUID EfiGraphicsOutputProtocol = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
28+
EFI_GUID AppleScreenInfoGUID = APPLE_SCREEN_INFO_PROTOCOL_GUID;
2729
/****/EFI_PIXEL_BITMASK UefiGopPixelBitmask;/****/
2830

2931
/* FUNCTIONS ******************************************************************/
3032

33+
static
3134
EFI_STATUS
32-
UefiInitializeVideo(VOID)
35+
UefiInitializeGop(VOID)
3336
{
3437
EFI_STATUS Status;
3538
EFI_GRAPHICS_OUTPUT_PROTOCOL* gop = NULL;
@@ -43,7 +46,7 @@ UefiInitializeVideo(VOID)
4346
}
4447

4548
/* We don't need high resolutions for freeldr */
46-
//gop->SetMode(gop, LOWEST_SUPPORTED_RES);
49+
gop->SetMode(gop, LOWEST_SUPPORTED_RES);
4750

4851
framebufferData.BaseAddress = (ULONG_PTR)gop->Mode->FrameBufferBase;
4952
framebufferData.BufferSize = gop->Mode->FrameBufferSize;
@@ -55,6 +58,73 @@ UefiInitializeVideo(VOID)
5558
return Status;
5659
}
5760

61+
static
62+
EFI_STATUS
63+
UefiInitializeAppleScreen(VOID)
64+
{
65+
EFI_STATUS Status;
66+
APPLE_SCREEN_INFO_PROTOCOL* AppleScreen = NULL;
67+
UINT64 BaseAddress, FrameBufferSize;
68+
UINT32 BytesPerRow, Width, Height, Depth;
69+
70+
RtlZeroMemory(&framebufferData, sizeof(framebufferData));
71+
72+
Status = GlobalSystemTable->BootServices->LocateProtocol(&AppleScreenInfoGUID, 0, (void**)&AppleScreen);
73+
if (Status != EFI_SUCCESS)
74+
{
75+
TRACE("Failed to find Apple Screen Info Protocol with status %d\n", Status);
76+
return Status;
77+
}
78+
79+
Status = AppleScreen->GetInfo(AppleScreen,
80+
&BaseAddress,
81+
&FrameBufferSize,
82+
&BytesPerRow,
83+
&Width,
84+
&Height,
85+
&Depth);
86+
87+
if (Status != EFI_SUCCESS)
88+
{
89+
TRACE("Failed to get screen info from Apple EFI with status %d\n", Status);
90+
return Status;
91+
}
92+
93+
ASSERT(Depth == 32);
94+
95+
framebufferData.BaseAddress = (ULONG_PTR) BaseAddress;
96+
framebufferData.BufferSize = (ULONG_PTR) FrameBufferSize;
97+
framebufferData.ScreenWidth = Width;
98+
framebufferData.ScreenHeight = Height;
99+
framebufferData.PixelsPerScanLine = BytesPerRow / 4;
100+
framebufferData.PixelFormat = PixelBlueGreenRedReserved8BitPerColor;
101+
UefiGopPixelBitmask = EfiPixelMasks[PixelBlueGreenRedReserved8BitPerColor];
102+
103+
return Status;
104+
}
105+
106+
EFI_STATUS
107+
UefiInitializeVideo(VOID)
108+
{
109+
EFI_STATUS Status;
110+
111+
// First try UEFI GOP.
112+
Status = UefiInitializeGop();
113+
if (Status == EFI_SUCCESS)
114+
{
115+
return Status;
116+
}
117+
118+
// Fall back to Apple Screen Info Protocol if GOP is unavailable.
119+
Status = UefiInitializeAppleScreen();
120+
if (Status != EFI_SUCCESS)
121+
{
122+
ERR("Unable to find any suitable video modes!\n");
123+
}
124+
125+
return Status;
126+
}
127+
58128
VOID
59129
UefiPrintFramebufferData(VOID)
60130
{
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
* PROJECT: Freeldr UEFI Extension
3+
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4+
* PURPOSE: UEFI Apple Screen Info Protocol
5+
* COPYRIGHT: Copyright 2025 Sylas Hollander <[email protected]>
6+
*/
7+
8+
#pragma once
9+
10+
/* Apple's proprietary screen info protocol */
11+
#define APPLE_SCREEN_INFO_PROTOCOL_GUID {0xe316e100, 0x0751, 0x4c49, {0x90, 0x56, 0x48, 0x6c, 0x7e, 0x47, 0x29, 0x03}}
12+
13+
typedef struct _APPLE_SCREEN_INFO_PROTOCOL APPLE_SCREEN_INFO_PROTOCOL;
14+
15+
typedef EFI_STATUS (EFIAPI *GetAppleScreenInfo)(APPLE_SCREEN_INFO_PROTOCOL *This,
16+
UINT64 *BaseAddress,
17+
UINT64 *FrameBufferSize,
18+
UINT32 *BytesPerRow,
19+
UINT32 *Width,
20+
UINT32 *Height,
21+
UINT32 *Depth);
22+
23+
struct _APPLE_SCREEN_INFO_PROTOCOL {
24+
GetAppleScreenInfo GetInfo;
25+
};

boot/freeldr/freeldr/include/arch/uefi/uefildr.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <LoadedImage.h>
1717
#include <GraphicsOutput.h>
1818
#include <UgaDraw.h>
19+
#include <apple_screen.h>
1920
#include <BlockIo.h>
2021
#include <Acpi.h>
2122
#include <GlobalVariable.h>

0 commit comments

Comments
 (0)