20#include <Protocol/GraphicsOutput.h>
21#include <Protocol/SimpleTextOut.h>
23#include <Library/BaseMemoryLib.h>
24#include <Library/BaseOverflowLib.h>
25#include <Library/BaseLib.h>
26#include <Library/DebugLib.h>
28#include <Library/MemoryAllocationLib.h>
29#include <Library/MtrrLib.h>
32#include <Library/UefiBootServicesTableLib.h>
33#include <Library/UefiRuntimeServicesTableLib.h>
42 IN EFI_GUID *Protocol,
50 if ((Status != EFI_UNSUPPORTED) && EFI_ERROR (Status)) {
59 if (!EFI_ERROR (Status)) {
67 Status =
gBS->LocateProtocol (
72 if (!EFI_ERROR (Status)) {
77 return EFI_UNSUPPORTED;
86 EFI_GRAPHICS_OUTPUT_PROTOCOL *OriginalGop;
87 EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;
89 EFI_HANDLE *HandleBuffer;
100 gBS->CalculateCrc32 (
gBS,
gBS->Hdr.HeaderSize, &
gBS->Hdr.CRC32);
104 Status =
gBS->HandleProtocol (
105 gST->ConsoleOutHandle,
107 (VOID **)&OriginalGop
110 if (!EFI_ERROR (Status)) {
113 "OCC: GOP exists on ConsoleOutHandle and has %u modes\n",
114 (UINT32)OriginalGop->Mode->MaxMode
117 if (OriginalGop->Mode->Info->PixelFormat == PixelBltOnly) {
125 "OCC: Looking for GOP replacement due to blit-only GOP\n"
127 }
else if (OriginalGop->Mode->MaxMode == 0) {
134 "OCC: Looking for GOP replacement due to invalid mode count\n"
138 return EFI_ALREADY_STARTED;
141 Status =
gBS->LocateHandleBuffer (
149 if (EFI_ERROR (Status)) {
150 DEBUG ((DEBUG_INFO,
"OCC: No handles with GOP protocol - %r\n", Status));
151 return EFI_UNSUPPORTED;
154 Status = EFI_NOT_FOUND;
155 for (Index = 0; Index < HandleCount; ++Index) {
156 if (HandleBuffer[Index] !=
gST->ConsoleOutHandle) {
157 Status =
gBS->HandleProtocol (
166 DEBUG ((DEBUG_INFO,
"OCC: Alternative GOP status is - %r\n", Status));
167 FreePool (HandleBuffer);
169 if ( !EFI_ERROR (Status)
170 && (OriginalGop->Mode->Info->PixelFormat == PixelBltOnly))
172 if ((UINT32)Gop->Mode->Info->PixelFormat >= PixelBltOnly) {
173 Status = EFI_NOT_FOUND;
178 "OCC: Checking alternative GOP mode %u - %r\n",
179 Gop->Mode->Info->PixelFormat,
187 if (!EFI_ERROR (Status)) {
193 if (!EFI_ERROR (Status)) {
194 gBS->UninstallProtocolInterface (
195 gST->ConsoleOutHandle,
201 DEBUG ((DEBUG_INFO,
"OCC: Installing GOP (%r) on ConsoleOutHandle...\n", Status));
205 if (!EFI_ERROR (Status)) {
206 Status =
gBS->InstallMultipleProtocolInterfaces (
207 &
gST->ConsoleOutHandle,
212 if (EFI_ERROR (Status)) {
213 DEBUG ((DEBUG_WARN,
"OCC: Failed to install GOP on ConsoleOutHandle - %r\n", Status));
218 DEBUG ((DEBUG_WARN,
"OCC: Missing compatible GOP - %r\n", Status));
235 IN OUT EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
239 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Source;
242 ASSERT (This->Mode != NULL);
243 ASSERT (This->Mode->Info != NULL);
247 This->Mode->FrameBufferBase = 0;
248 This->Mode->FrameBufferSize = 0;
255 This->Mode->Info->VerticalResolution = Source->VerticalResolution;
256 This->Mode->Info->HorizontalResolution = Source->HorizontalResolution;
257 This->Mode->Info->PixelsPerScanLine = Source->PixelsPerScanLine;
270 IN OUT EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
275 ASSERT (This->Mode != NULL);
276 ASSERT (This->Mode->Info != NULL);
280 if ((Rotation == 90) || (Rotation == 270)) {
283 This->Mode->Info->PixelsPerScanLine = This->Mode->Info->HorizontalResolution;
299 This->Mode->FrameBufferBase = 0;
300 This->Mode->FrameBufferSize = 0;
310 IN EFI_PHYSICAL_ADDRESS FramebufferBase,
311 IN EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info,
321 (VOID *)(UINTN)FramebufferBase,
327 if (Status != EFI_BUFFER_TOO_SMALL) {
331 *PageCount = EFI_SIZE_TO_PAGES (ConfigureSize);
332 Context = AllocatePages (*PageCount);
333 if (Context == NULL) {
338 (VOID *)(UINTN)FramebufferBase,
344 if (EFI_ERROR (Status)) {
345 FreePages (Context, *PageCount);
356 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
364 if (ModeNumber == This->Mode->Mode) {
368 OldTpl =
gBS->RaiseTPL (TPL_NOTIFY);
382 if (EFI_ERROR (Status)) {
385 gBS->RestoreTPL (OldTpl);
389 if (Original != NULL) {
401 gBS->RestoreTPL (OldTpl);
402 return EFI_DEVICE_ERROR;
406 MtrrSetMemoryAttribute (
413 gBS->RestoreTPL (OldTpl);
421 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
422 IN UINT32 ModeNumber,
423 OUT UINTN *SizeOfInfo,
424 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
428 UINT32 HorizontalResolution;
432 if (EFI_ERROR (Status)) {
438 HorizontalResolution = (*Info)->HorizontalResolution;
439 (*Info)->HorizontalResolution = (*Info)->VerticalResolution;
440 (*Info)->VerticalResolution = HorizontalResolution;
441 (*Info)->PixelsPerScanLine = (*Info)->HorizontalResolution;
451 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
452 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL,
453 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
456 IN UINTN DestinationX,
457 IN UINTN DestinationY,
460 IN UINTN Delta OPTIONAL
478 return EFI_DEVICE_ERROR;
488 EFI_HANDLE *HandleBuffer;
507 Status =
gBS->LocateHandleBuffer (
514 if (!EFI_ERROR (Status)) {
515 for (Index = 0; Index < HandleCount; ++Index) {
516 gBS->DisconnectController (HandleBuffer[Index], NULL, NULL);
519 for (Index = 0; Index < HandleCount; ++Index) {
520 gBS->ConnectController (HandleBuffer[Index], NULL, NULL, TRUE);
523 FreePool (HandleBuffer);
531 DEBUG ((DEBUG_WARN,
"OCC: Failed to find any text output handles\n"));
541 EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;
545 DEBUG ((DEBUG_INFO,
"OCC: Switching to direct GOP renderer...\n"));
547 Status =
gBS->HandleProtocol (
548 gST->ConsoleOutHandle,
553 if (EFI_ERROR (Status)) {
554 DEBUG ((DEBUG_INFO,
"OCC: Cannot find console GOP for direct GOP - %r\n", Status));
558 if (Gop->Mode->Info->PixelFormat == PixelBltOnly) {
559 DEBUG ((DEBUG_INFO,
"OCC: This GOP does not support direct rendering\n"));
560 return EFI_UNSUPPORTED;
563 Status =
gBS->LocateProtocol (
568 if (!EFI_ERROR (Status)) {
569 DEBUG ((DEBUG_INFO,
"OCC: Found EG2 support %X\n", Eg2->
Revision));
582 DEBUG ((DEBUG_INFO,
"OCC: Got rotation %u degrees from EG2\n",
mGop.
Rotation));
584 DEBUG ((DEBUG_INFO,
"OCC: Invalid rotation %u from EG2 - %r\n", Rotation, Status));
588 DEBUG ((DEBUG_INFO,
"OCC: No Apple EG2 support - %r\n", Status));
599 DEBUG ((DEBUG_INFO,
"OCC: Delaying direct GOP configuration...\n"));
612 if (CacheType >= 0) {
613 Status = MtrrSetMemoryAttribute (
620 "OCC: FB (%Lx, %Lx) MTRR (%x) - %r\n",
626 if (!EFI_ERROR (Status)) {
#define APPLE_EG2_INFO_PROTOCOL_REVISION
EFI_GUID gAppleEg2InfoProtocolGuid
EFI_STATUS OcUseDirectGop(IN INT32 CacheType)
STATIC VOID RotateMode(IN OUT EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN UINT32 Rotation)
STATIC EFI_STATUS EFIAPI DirectGopSetMode(IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN UINT32 ModeNumber)
STATIC EFI_STATUS EFIAPI DirectQueryMode(IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN UINT32 ModeNumber, OUT UINTN *SizeOfInfo, OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info)
STATIC OC_BLIT_CONFIGURE *EFIAPI DirectGopFromTarget(IN EFI_PHYSICAL_ADDRESS FramebufferBase, IN EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Info, OUT UINTN *PageCount)
EFI_STATUS OcProvideConsoleGop(IN BOOLEAN Route)
STATIC CONSOLE_GOP_CONTEXT mGop
STATIC EFI_STATUS EFIAPI ConsoleHandleProtocol(IN EFI_HANDLE Handle, IN EFI_GUID *Protocol, OUT VOID **Interface)
STATIC EFI_STATUS EFIAPI DirectGopBlt(IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL, IN EFI_GRAPHICS_OUTPUT_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)
VOID OcReconnectConsole(VOID)
CONST CONSOLE_GOP_CONTEXT * InternalGetDirectGopContext(VOID)
STATIC VOID SwitchMode(IN OUT EFI_GRAPHICS_OUTPUT_PROTOCOL *This, IN BOOLEAN UseCustom)
RETURN_STATUS EFIAPI OcBlitRender(IN OC_BLIT_CONFIGURE *Configure, IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL, IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation, IN UINTN SourceX, IN UINTN SourceY, IN UINTN DestinationX, IN UINTN DestinationY, IN UINTN Width, IN UINTN Height, IN UINTN Delta)
RETURN_STATUS EFIAPI OcBlitConfigure(IN VOID *FrameBuffer, IN EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *FrameBufferInfo, IN UINT32 Rotation, IN OUT OC_BLIT_CONFIGURE *Configure, IN OUT UINTN *ConfigureSize)
APPLE_EVENT_HANDLE Handle
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
EFI_GUID gEfiUgaDrawProtocolGuid
EFI_GUID gEfiSimpleTextOutProtocolGuid
EFI_GUID gEfiGraphicsOutputProtocolGuid
APPLE_EG2_INFO_GET_ROTATION GetRotation
UINTN FramebufferContextPageCount
EFI_PHYSICAL_ADDRESS OriginalFrameBufferBase
EFI_GRAPHICS_OUTPUT_PROTOCOL_QUERY_MODE OriginalGopQueryMode
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION OriginalModeInfo
OC_BLIT_CONFIGURE * FramebufferContext
UINTN OriginalFrameBufferSize
EFI_GRAPHICS_OUTPUT_PROTOCOL * ConsoleGop
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION CustomModeInfo
EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE OriginalGopSetMode
EFI_HANDLE_PROTOCOL OriginalHandleProtocol