OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
UgaPassThrough.c
Go to the documentation of this file.
1
16
17#include <Library/DebugLib.h>
18#include <Library/MemoryAllocationLib.h>
19#include <Library/UefiBootServicesTableLib.h>
20
21#include <Library/OcMiscLib.h>
22
23STATIC
24EFI_STATUS
25EFIAPI
27 IN EFI_UGA_DRAW_PROTOCOL *This,
28 OUT UINT32 *HorizontalResolution,
29 OUT UINT32 *VerticalResolution,
30 OUT UINT32 *ColorDepth,
31 OUT UINT32 *RefreshRate
32 )
33{
34 OC_UGA_PROTOCOL *OcUgaDraw;
35 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info;
36
37 DEBUG ((DEBUG_INFO, "OCC: OcUgaDrawGetMode %p\n", This));
38
39 if ( (This == NULL)
40 || (HorizontalResolution == NULL)
41 || (VerticalResolution == NULL)
42 || (ColorDepth == NULL)
43 || (RefreshRate == NULL))
44 {
45 return EFI_INVALID_PARAMETER;
46 }
47
48 OcUgaDraw = BASE_CR (This, OC_UGA_PROTOCOL, Uga);
49 Info = OcUgaDraw->GraphicsOutput->Mode->Info;
50
51 DEBUG ((
52 DEBUG_INFO,
53 "OCC: OcUgaDrawGetMode Info is %ux%u (%u)\n",
54 Info->HorizontalResolution,
55 Info->VerticalResolution,
56 Info->PixelFormat
57 ));
58
59 if ((Info->HorizontalResolution == 0) || (Info->VerticalResolution == 0)) {
60 return EFI_NOT_STARTED;
61 }
62
63 *HorizontalResolution = Info->HorizontalResolution;
64 *VerticalResolution = Info->VerticalResolution;
65 *ColorDepth = DEFAULT_COLOUR_DEPTH;
66 *RefreshRate = DEFAULT_REFRESH_RATE;
67
68 return EFI_SUCCESS;
69}
70
71STATIC
72EFI_STATUS
73EFIAPI
75 IN EFI_UGA_DRAW_PROTOCOL *This,
76 IN UINT32 HorizontalResolution,
77 IN UINT32 VerticalResolution,
78 IN UINT32 ColorDepth,
79 IN UINT32 RefreshRate
80 )
81{
82 EFI_STATUS Status;
83 OC_UGA_PROTOCOL *OcUgaDraw;
84
85 DEBUG ((
86 DEBUG_INFO,
87 "OCC: OcUgaDrawSetMode %p %ux%u@%u/%u\n",
88 This,
89 HorizontalResolution,
90 VerticalResolution,
91 ColorDepth,
92 RefreshRate
93 ));
94
95 OcUgaDraw = BASE_CR (This, OC_UGA_PROTOCOL, Uga);
96
98 OcUgaDraw->GraphicsOutput,
99 HorizontalResolution,
100 VerticalResolution,
101 ColorDepth
102 );
103
104 DEBUG ((DEBUG_INFO, "OCC: UGA SetConsoleResolutionOnHandle attempt - %r\n", Status));
105
106 if (EFI_ERROR (Status)) {
108 OcUgaDraw->GraphicsOutput,
109 0,
110 0,
111 0
112 );
113 DEBUG ((DEBUG_INFO, "OCC: UGA SetConsoleResolutionOnHandle max attempt - %r\n", Status));
114 }
115
116 return Status;
117}
118
119STATIC
120EFI_STATUS
121EFIAPI
123 IN EFI_UGA_DRAW_PROTOCOL *This,
124 IN EFI_UGA_PIXEL *BltBuffer OPTIONAL,
125 IN EFI_UGA_BLT_OPERATION BltOperation,
126 IN UINTN SourceX,
127 IN UINTN SourceY,
128 IN UINTN DestinationX,
129 IN UINTN DestinationY,
130 IN UINTN Width,
131 IN UINTN Height,
132 IN UINTN Delta OPTIONAL
133 )
134{
135 OC_UGA_PROTOCOL *OcUgaDraw;
136
137 OcUgaDraw = BASE_CR (This, OC_UGA_PROTOCOL, Uga);
138
139 return OcUgaDraw->GraphicsOutput->Blt (
140 OcUgaDraw->GraphicsOutput,
141 (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)BltBuffer,
142 (EFI_GRAPHICS_OUTPUT_BLT_OPERATION)BltOperation,
143 SourceX,
144 SourceY,
145 DestinationX,
146 DestinationY,
147 Width,
148 Height,
149 Delta
150 );
151}
152
153EFI_STATUS
155 VOID
156 )
157{
158 EFI_STATUS Status;
159 UINTN HandleCount;
160 EFI_HANDLE *HandleBuffer;
161 UINTN Index;
162 EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
163 EFI_UGA_DRAW_PROTOCOL *UgaDraw;
164 OC_UGA_PROTOCOL *OcUgaDraw;
165
166 //
167 // For now we do not need this but for launching 10.4, but as a side note:
168 // MacPro5,1 has 2 GOP protocols:
169 // - for GPU
170 // - for ConsoleOutput
171 // and 1 UGA protocol:
172 // - for unknown handle
173 //
174 DEBUG_CODE_BEGIN ();
175 DEBUG ((DEBUG_INFO, "OCC: Found %u handles with UGA draw\n", (UINT32)OcCountProtocolInstances (&gEfiUgaDrawProtocolGuid)));
176 DEBUG_CODE_END ();
177
178 Status = gBS->LocateHandleBuffer (
179 ByProtocol,
181 NULL,
182 &HandleCount,
183 &HandleBuffer
184 );
185 if (EFI_ERROR (Status)) {
186 DEBUG ((DEBUG_INFO, "OCC: Failed to find handles with GOP - %r\n", Status));
187 return Status;
188 }
189
190 DEBUG ((DEBUG_INFO, "OCC: Found %u handles with GOP for UGA check\n", (UINT32)HandleCount));
191 for (Index = 0; Index < HandleCount; ++Index) {
192 DEBUG ((DEBUG_INFO, "OCC: Trying handle %u - %p\n", (UINT32)Index, HandleBuffer[Index]));
193
194 Status = gBS->HandleProtocol (
195 HandleBuffer[Index],
197 (VOID **)&GraphicsOutput
198 );
199 if (EFI_ERROR (Status)) {
200 DEBUG ((DEBUG_INFO, "OCC: No GOP protocol - %r\n", Status));
201 continue;
202 }
203
204 Status = gBS->HandleProtocol (
205 HandleBuffer[Index],
207 (VOID **)&UgaDraw
208 );
209 if (!EFI_ERROR (Status)) {
210 DEBUG ((DEBUG_INFO, "OCC: Skipping UGA proxying as it is already present on handle %u - %p\n", (UINT32)Index, HandleBuffer[Index]));
211 continue;
212 }
213
214 OcUgaDraw = AllocateZeroPool (sizeof (*OcUgaDraw));
215 if (OcUgaDraw == NULL) {
216 DEBUG ((DEBUG_INFO, "OCC: Failed to allocate UGA protocol\n"));
217 continue;
218 }
219
220 OcUgaDraw->GraphicsOutput = GraphicsOutput;
221 OcUgaDraw->Uga.GetMode = OcUgaDrawGetMode;
222 OcUgaDraw->Uga.SetMode = OcUgaDrawSetMode;
223 OcUgaDraw->Uga.Blt = OcUgaDrawBlt;
224
225 Status = gBS->InstallMultipleProtocolInterfaces (
226 &HandleBuffer[Index],
228 &OcUgaDraw->Uga,
229 NULL
230 );
231 if (EFI_ERROR (Status)) {
232 FreePool (OcUgaDraw);
233 }
234
235 DEBUG ((
236 DEBUG_INFO,
237 "OCC: Installed UGA protocol - %r (Handle %u - %p)\n",
238 Status,
239 (UINT32)Index,
240 HandleBuffer[Index]
241 ));
242 }
243
244 FreePool (HandleBuffer);
245
246 return Status;
247}
EFI_BOOT_SERVICES * gBS
EFI_STATUS OcSetConsoleResolutionForProtocol(IN EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput, IN UINT32 Width OPTIONAL, IN UINT32 Height OPTIONAL, IN UINT32 Bpp OPTIONAL)
#define DEFAULT_REFRESH_RATE
#define DEFAULT_COLOUR_DEPTH
UINTN OcCountProtocolInstances(IN EFI_GUID *Protocol)
STATIC EFI_STATUS EFIAPI OcUgaDrawBlt(IN EFI_UGA_DRAW_PROTOCOL *This, IN EFI_UGA_PIXEL *BltBuffer OPTIONAL, IN EFI_UGA_BLT_OPERATION BltOperation, IN UINTN SourceX, IN UINTN SourceY, IN UINTN DestinationX, IN UINTN DestinationY, IN UINTN Width, IN UINTN Height, IN UINTN Delta OPTIONAL)
STATIC EFI_STATUS EFIAPI OcUgaDrawGetMode(IN EFI_UGA_DRAW_PROTOCOL *This, OUT UINT32 *HorizontalResolution, OUT UINT32 *VerticalResolution, OUT UINT32 *ColorDepth, OUT UINT32 *RefreshRate)
STATIC EFI_STATUS EFIAPI OcUgaDrawSetMode(IN EFI_UGA_DRAW_PROTOCOL *This, IN UINT32 HorizontalResolution, IN UINT32 VerticalResolution, IN UINT32 ColorDepth, IN UINT32 RefreshRate)
EFI_STATUS OcProvideUgaPassThrough(VOID)
EFI_GUID gEfiUgaDrawProtocolGuid
EFI_GUID gEfiGraphicsOutputProtocolGuid
EFI_GRAPHICS_OUTPUT_PROTOCOL * GraphicsOutput
EFI_UGA_DRAW_PROTOCOL Uga