Skip to content

Commit bc4d990

Browse files
[UEFILDR] Add support for Apple Graphics Info Protocol
1 parent e1853c6 commit bc4d990

3 files changed

Lines changed: 116 additions & 1 deletion

File tree

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

Lines changed: 83 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ DBG_DEFAULT_CHANNEL(UI);
1616
extern EFI_SYSTEM_TABLE* GlobalSystemTable;
1717
extern EFI_HANDLE GlobalImageHandle;
1818
EFI_GUID EfiGraphicsOutputProtocol = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
19+
EFI_GUID AppleGraphInfoProtocol = APPLE_GRAPH_INFO_PROTOCOL_GUID;
1920

2021
ULONG_PTR VramAddress;
2122
ULONG VramSize;
@@ -52,8 +53,9 @@ static EFI_PIXEL_BITMASK EfiPixelMasks[] =
5253

5354
#endif /* UEFI */
5455

56+
static
5557
EFI_STATUS
56-
UefiInitializeVideo(VOID)
58+
UefiInitializeGop(VOID)
5759
{
5860
EFI_STATUS Status;
5961
EFI_GRAPHICS_OUTPUT_PROTOCOL* gop = NULL;
@@ -128,6 +130,86 @@ UefiInitializeVideo(VOID)
128130
return Status;
129131
}
130132

133+
static
134+
EFI_STATUS
135+
UefiInitializeAppleGraphics(VOID)
136+
{
137+
EFI_STATUS Status;
138+
APPLE_GRAPH_INFO_PROTOCOL *AppleGraph = NULL;
139+
EFI_PIXEL_BITMASK* pPixelBitmask;
140+
141+
UINT64 BaseAddress, FrameBufferSize;
142+
UINT32 BytesPerRow, Width, Height, Depth;
143+
144+
Status = GlobalSystemTable->BootServices->LocateProtocol(&AppleGraphInfoProtocol, 0, (VOID**)&AppleGraph);
145+
if (Status != EFI_SUCCESS)
146+
{
147+
ERR("Failed to find Apple Graphics Info with status %d\n", Status);
148+
return Status;
149+
}
150+
151+
Status = AppleGraph->GetInfo(AppleGraph,
152+
&BaseAddress,
153+
&FrameBufferSize,
154+
&BytesPerRow,
155+
&Width,
156+
&Height,
157+
&Depth);
158+
159+
if (Status != EFI_SUCCESS)
160+
{
161+
ERR("Failed to get graphics info from Apple Scren Info: %d\n", Status);
162+
return Status;
163+
}
164+
165+
VramAddress = (ULONG_PTR) BaseAddress;
166+
VramSize = (ULONG) FrameBufferSize;
167+
168+
/* All devices requiring Apple Graphics Info use PixelBlueGreenRedReserved8BitPerColor. */
169+
pPixelBitmask = &EfiPixelMasks[PixelBlueGreenRedReserved8BitPerColor];
170+
171+
if (!VidFbInitializeVideo(&FrameBufferData,
172+
VramAddress,
173+
VramSize,
174+
Width,
175+
Height,
176+
(BytesPerRow / 4),
177+
Depth,
178+
(PPIXEL_BITMASK)pPixelBitmask))
179+
{
180+
ERR("Couldn't initialize video framebuffer\n");
181+
Status = EFI_UNSUPPORTED;
182+
}
183+
184+
return Status;
185+
}
186+
187+
EFI_STATUS
188+
UefiInitializeVideo(VOID)
189+
{
190+
EFI_STATUS Status;
191+
192+
/* First, try GOP */
193+
Status = UefiInitializeGop();
194+
if (Status == EFI_SUCCESS)
195+
{
196+
return Status;
197+
}
198+
199+
/* Try Apple Graphics Info if that fails */
200+
TRACE("Failed to detect GOP, trying Apple Graphics Info\n");
201+
Status = UefiInitializeAppleGraphics();
202+
if (Status == EFI_SUCCESS)
203+
{
204+
return Status;
205+
}
206+
207+
/* We didn't find GOP or Apple Graphics Info, probably a UGA-only system */
208+
ERR("Cannot find framebuffer!\n");
209+
return Status;
210+
}
211+
212+
131213
VOID
132214
UefiVideoClearScreen(UCHAR Attr)
133215
{

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 <AppleGraphInfo.h>
1920
#include <BlockIo.h>
2021
#include <Acpi.h>
2122
#include <GlobalVariable.h>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* PROJECT: ReactOS UEFI Support
3+
* LICENSE: MIT (https://spdx.org/licenses/MIT)
4+
* PURPOSE: Apple Graphics Info Protocol
5+
* COPYRIGHT: Copyright 2026 Sylas Hollander <distrohopper39b.business@gmail.com>
6+
*/
7+
8+
/*
9+
* Implementation based on AppleGraphInfo.h from macosxbootloader, written by "tiamo"
10+
* which is licensed under BSD-3-Clause (https://spdx.org/licenses/BSD-3-Clause)
11+
* (see note in macosxbootloader README)
12+
*/
13+
14+
#pragma once
15+
16+
#define APPLE_GRAPH_INFO_PROTOCOL_GUID {0xe316e100, 0x0751, 0x4c49, {0x90, 0x56, 0x48, 0x6c, 0x7e, 0x47, 0x29, 0x03}}
17+
18+
typedef struct _APPLE_GRAPH_INFO_PROTOCOL APPLE_GRAPH_INFO_PROTOCOL;
19+
20+
typedef EFI_STATUS (EFIAPI *GET_INFO)(
21+
APPLE_GRAPH_INFO_PROTOCOL *This,
22+
UINT64 *BaseAddress,
23+
UINT64 *FrameBufferSize,
24+
UINT32 *BytesPerRow,
25+
UINT32 *Width,
26+
UINT32 *Height,
27+
UINT32 *Depth);
28+
29+
struct _APPLE_GRAPH_INFO_PROTOCOL
30+
{
31+
GET_INFO GetInfo;
32+
};

0 commit comments

Comments
 (0)