ReactOS  0.4.14-dev-98-gb0d4763
gop.c File Reference
#include "bl.h"
Include dependency graph for gop.c:

Go to the source code of this file.

Functions

NTSTATUS ConsoleEfiGopGetGraphicalFormat (_In_ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *ModeInfo, _Out_ PULONG PixelDepth)
 
BOOLEAN ConsoleEfiGopIsPixelFormatSupported (_In_ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Mode)
 
NTSTATUS ConsoleEfiGopFindModeFromAllowed (_In_ EFI_GRAPHICS_OUTPUT_PROTOCOL *GopProtocol, _In_ PBL_DISPLAY_MODE SupportedModes, _In_ ULONG MaximumIndex, _Out_ PULONG SupportedMode)
 
NTSTATUS ConsoleEfiGopEnable (_In_ PBL_GRAPHICS_CONSOLE GraphicsConsole)
 
VOID ConsoleEfiGopClose (_In_ PBL_GRAPHICS_CONSOLE GraphicsConsole)
 
NTSTATUS ConsoleEfiGopOpen (_In_ PBL_GRAPHICS_CONSOLE GraphicsConsole)
 

Function Documentation

◆ ConsoleEfiGopClose()

VOID ConsoleEfiGopClose ( _In_ PBL_GRAPHICS_CONSOLE  GraphicsConsole)

Definition at line 177 of file gop.c.

180 {
181  ULONG OldMode;
182 
183  /* Did we switch modes when we turned on the console? */
184  OldMode = GraphicsConsole->OldMode;
185  if (GraphicsConsole->Mode != OldMode)
186  {
187  /* Restore the old mode and reset the OEM bitmap in ACPI */
188  EfiGopSetMode(GraphicsConsole->Protocol, OldMode);
190  }
191 
192  /* Close the GOP protocol */
193  EfiCloseProtocol(GraphicsConsole->Handle,
195 }
VOID BlDisplayInvalidateOemBitmap(VOID)
Definition: display.c:722
NTSTATUS EfiCloseProtocol(_In_ EFI_HANDLE Handle, _In_ EFI_GUID *Protocol)
Definition: firmware.c:581
EFI_GUID EfiGraphicsOutputProtocol
Definition: firmware.c:28
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS EfiGopSetMode(_In_ EFI_GRAPHICS_OUTPUT_PROTOCOL *GopInterface, _In_ ULONG Mode)
Definition: firmware.c:1349

Referenced by ConsoleFirmwareGraphicalClose().

◆ ConsoleEfiGopEnable()

NTSTATUS ConsoleEfiGopEnable ( _In_ PBL_GRAPHICS_CONSOLE  GraphicsConsole)

Definition at line 88 of file gop.c.

91 {
93  UINTN CurrentMode, Dummy;
94  ULONG Mode, PixelDepth;
99  PHYSICAL_ADDRESS FrameBufferPhysical;
100 
101  /* Capture the current mode and protocol */
102  Mode = GraphicsConsole->Mode;
103  Protocol = GraphicsConsole->Protocol;
104 
105  /* Get the current mode and its information */
106  Status = EfiGopGetCurrentMode(Protocol, &CurrentMode, &ModeInformation);
107  if (!NT_SUCCESS(Status))
108  {
109  return Status;
110  }
111 
112  /* Check if we're not in the mode we should be */
113  if (CurrentMode != Mode)
114  {
115  /* Switch modes */
117  if (!NT_SUCCESS(Status))
118  {
119  return Status;
120  }
121 
122  /* Reset the OEM bitmap and get the new more information */
124  EfiGopGetCurrentMode(Protocol, &Dummy, &ModeInformation);
125  }
126 
127  /* Get the pixel depth for this mode */
128  Status = ConsoleEfiGopGetGraphicalFormat(&ModeInformation, &PixelDepth);
129  if (NT_SUCCESS(Status))
130  {
131  /* Get the framebuffer for this mode */
132  EfiGopGetFrameBuffer(Protocol, &FrameBufferPhysical, &FrameBufferSize);
133 
134  /* Map the framebuffer, try as writeback first */
135  FrameBuffer = NULL;
139  FrameBufferPhysical);
140  if (!NT_SUCCESS(Status))
141  {
142  /* That didn't work, so try uncached next */
146  FrameBufferPhysical);
147  }
148  }
149 
150  /* Check if getting all the required information worked out */
151  if (NT_SUCCESS(Status))
152  {
153  /* Capture the resolution, depth, and framebuffer information */
154  GraphicsConsole->DisplayMode.HRes = ModeInformation.HorizontalResolution;
155  GraphicsConsole->DisplayMode.VRes = ModeInformation.VerticalResolution;
156  GraphicsConsole->DisplayMode.HRes2 = ModeInformation.PixelsPerScanLine;
157  GraphicsConsole->PixelDepth = PixelDepth;
158  GraphicsConsole->FrameBuffer = FrameBuffer;
159  GraphicsConsole->FrameBufferSize = FrameBufferSize;
160  GraphicsConsole->PixelsPerScanLine = ModeInformation.PixelsPerScanLine;
161 
162  /* All good */
164  }
165  else if (CurrentMode != GraphicsConsole->Mode)
166  {
167  /* We failed somewhere, reset the mode and the OEM bitmap back */
168  EfiGopSetMode(Protocol, CurrentMode);
170  }
171 
172  /* Return back to caller */
173  return Status;
174 }
NTSTATUS BlMmMapPhysicalAddressEx(_In_ PVOID *VirtualAddress, _In_ ULONG Attributes, _In_ ULONGLONG Size, _In_ PHYSICAL_ADDRESS PhysicalAddress)
Definition: mm.c:192
NTSTATUS EfiGopGetCurrentMode(_In_ EFI_GRAPHICS_OUTPUT_PROTOCOL *GopInterface, _Out_ UINTN *Mode, _Out_ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Information)
Definition: firmware.c:1296
_In_ ULONG Mode
Definition: hubbusif.h:303
ULONG FrameBufferSize
Definition: xboxvideo.c:28
LONG NTSTATUS
Definition: precomp.h:26
_In_ USHORT _In_ ULONG Protocol
Definition: wsk.h:182
UINT32 UINTN
NTSTATUS ConsoleEfiGopGetGraphicalFormat(_In_ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *ModeInfo, _Out_ PULONG PixelDepth)
Definition: gop.c:18
smooth NULL
Definition: ftsmooth.c:416
VOID BlDisplayInvalidateOemBitmap(VOID)
Definition: display.c:722
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:24
VOID EfiGopGetFrameBuffer(_In_ EFI_GRAPHICS_OUTPUT_PROTOCOL *GopInterface, _Out_ PHYSICAL_ADDRESS *FrameBuffer, _Out_ UINTN *FrameBufferSize)
Definition: firmware.c:1255
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS EfiGopSetMode(_In_ EFI_GRAPHICS_OUTPUT_PROTOCOL *GopInterface, _In_ ULONG Mode)
Definition: firmware.c:1349
PVOID FrameBuffer
Definition: xboxvideo.c:27
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by ConsoleFirmwareGraphicalEnable().

◆ ConsoleEfiGopFindModeFromAllowed()

NTSTATUS ConsoleEfiGopFindModeFromAllowed ( _In_ EFI_GRAPHICS_OUTPUT_PROTOCOL GopProtocol,
_In_ PBL_DISPLAY_MODE  SupportedModes,
_In_ ULONG  MaximumIndex,
_Out_ PULONG  SupportedMode 
)

Definition at line 77 of file gop.c.

83 {
85 }
#define STATUS_NOT_IMPLEMENTED
Definition: ntstatus.h:225

Referenced by ConsoleEfiGopOpen().

◆ ConsoleEfiGopGetGraphicalFormat()

NTSTATUS ConsoleEfiGopGetGraphicalFormat ( _In_ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInfo,
_Out_ PULONG  PixelDepth 
)

Definition at line 18 of file gop.c.

22 {
23  /* Convert the format to depth */
24  if (ModeInfo->PixelFormat == PixelBlueGreenRedReserved8BitPerColor)
25  {
26  *PixelDepth = 32;
27  return STATUS_SUCCESS;
28  }
29  if (ModeInfo->PixelFormat == PixelBitMask)
30  {
31  *PixelDepth = 24;
32  return STATUS_SUCCESS;
33  }
34  return STATUS_UNSUCCESSFUL;
35 }
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by ConsoleEfiGopEnable(), and ConsoleEfiGopOpen().

◆ ConsoleEfiGopIsPixelFormatSupported()

BOOLEAN ConsoleEfiGopIsPixelFormatSupported ( _In_ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION Mode)

Definition at line 38 of file gop.c.

41 {
42  BOOLEAN Supported;
44 
45  Supported = FALSE;
46 
47  /* Check if it's simple BGR8 */
48  if (Mode->PixelFormat == PixelBlueGreenRedReserved8BitPerColor)
49  {
50  Supported = TRUE;
51  }
52  else
53  {
54  /* Otherwise, we can check if it's a masked format */
55  if (Mode->PixelFormat == PixelBitMask)
56  {
57  /* Check if the masked format is BGR8 */
58  PixelMask.BlueMask = 0xFF;
59  PixelMask.GreenMask = 0xFF00;
60  PixelMask.RedMask = 0xFF0000;
61  PixelMask.ReservedMask = 0;
62  if (RtlEqualMemory(&Mode->PixelInformation,
63  &PixelMask,
64  sizeof(PixelMask)))
65  {
66  Supported = TRUE;
67  }
68  }
69  }
70 
71  /* Return if the format was supported */
72  return Supported;
73 }
#define TRUE
Definition: types.h:120
_In_ ULONG Mode
Definition: hubbusif.h:303
unsigned char BOOLEAN
NTSYSAPI ULONG NTAPI RtlEqualMemory(CONST VOID *Source1, CONST VOID *Source2, ULONG Length)
UCHAR PixelMask[8]
Definition: vga.c:35

Referenced by ConsoleEfiGopOpen().

◆ ConsoleEfiGopOpen()

NTSTATUS ConsoleEfiGopOpen ( _In_ PBL_GRAPHICS_CONSOLE  GraphicsConsole)

Definition at line 198 of file gop.c.

201 {
203  EFI_GRAPHICS_OUTPUT_PROTOCOL *GopProtocol;
204  ULONG Mode, PixelDepth;
205  UINTN CurrentMode;
206  EFI_GRAPHICS_OUTPUT_MODE_INFORMATION ModeInformation;
207  BOOLEAN CurrentModeOk;
208 
209  /* Open a handle to GOP */
210  Status = EfiOpenProtocol(GraphicsConsole->Handle,
212  (PVOID*)&GopProtocol);
213  if (!NT_SUCCESS(Status))
214  {
215  EfiPrintf(L"GOP OPEN failed: %lx\r\n", Status);
216  return STATUS_NOT_SUPPORTED;
217  }
218 
219  /* Get the current mode */
220  Status = EfiGopGetCurrentMode(GopProtocol, &CurrentMode, &ModeInformation);
221  if (!NT_SUCCESS(Status))
222  {
223  EfiPrintf(L"GOP mode failed: %lx\r\n", Status);
224  goto Quickie;
225  }
226 
227  Mode = CurrentMode;
228 
229  /* Check if any custom BCD options were provided */
233  {
234  /* We'll have to find a mode */
235  CurrentModeOk = FALSE;
236  }
237  else
238  {
239  /* Then we should be in the default mode, check if the pixel format is OK */
240  CurrentModeOk = ConsoleEfiGopIsPixelFormatSupported(&ModeInformation);
241  }
242 
243  /* Is the mode/format OK? */
244  if (!CurrentModeOk)
245  {
246  /* Nope -- we'll have to go find one */
250  &Mode);
251  if (!NT_SUCCESS(Status))
252  {
253  goto Quickie;
254  }
255  }
256 
257  /* Store mode information */
258  GraphicsConsole->Protocol = GopProtocol;
259  GraphicsConsole->Mode = Mode;
260  GraphicsConsole->OldMode = CurrentMode;
261 
262  /* Get format information */
263  Status = ConsoleEfiGopGetGraphicalFormat(&ModeInformation, &PixelDepth);
264  if (NT_SUCCESS(Status))
265  {
266  /* Store it */
267  GraphicsConsole->OldDisplayMode.HRes = ModeInformation.HorizontalResolution;
268  GraphicsConsole->OldDisplayMode.VRes = ModeInformation.VerticalResolution;
269  GraphicsConsole->OldDisplayMode.HRes2 = ModeInformation.PixelsPerScanLine;
270  GraphicsConsole->PixelDepth = PixelDepth;
271  return STATUS_SUCCESS;
272  }
273 
274 Quickie:
275  /* We failed, close the protocol and return the failure code */
276  EfiPrintf(L"Get format failed: %lx\r\n", Status);
277  EfiCloseProtocol(GraphicsConsole->Handle, &EfiGraphicsOutputProtocol);
278  return Status;
279 }
BL_DISPLAY_MODE ConsoleGraphicalResolutionList[]
Definition: display.c:22
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE * Mode
NTSTATUS EfiGopGetCurrentMode(_In_ EFI_GRAPHICS_OUTPUT_PROTOCOL *GopInterface, _Out_ UINTN *Mode, _Out_ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Information)
Definition: firmware.c:1296
_In_ ULONG Mode
Definition: hubbusif.h:303
LONG NTSTATUS
Definition: precomp.h:26
#define BL_DISPLAY_GRAPHICS_FORCED_HIGH_RES_MODE_FLAG
Definition: bl.h:136
UINT32 UINTN
BOOLEAN ConsoleEfiGopIsPixelFormatSupported(_In_ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Mode)
Definition: gop.c:38
NTSTATUS ConsoleEfiGopGetGraphicalFormat(_In_ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *ModeInfo, _Out_ PULONG PixelDepth)
Definition: gop.c:18
ULONG ConsoleGraphicalResolutionListSize
Definition: display.c:28
NTSTATUS EfiOpenProtocol(_In_ EFI_HANDLE Handle, _In_ EFI_GUID *Protocol, _Out_ PVOID *Interface)
#define BL_DISPLAY_GRAPHICS_FORCED_VIDEO_MODE_FLAG
Definition: bl.h:135
ULONG ConsoleGraphicalResolutionListFlags
Definition: display.c:21
unsigned char BOOLEAN
NTSTATUS EfiCloseProtocol(_In_ EFI_HANDLE Handle, _In_ EFI_GUID *Protocol)
Definition: firmware.c:581
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
EFI_GUID EfiGraphicsOutputProtocol
Definition: firmware.c:28
VOID EfiPrintf(_In_ PWCHAR Format,...)
Definition: firmware.c:126
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:409
unsigned int ULONG
Definition: retypes.h:1
NTSTATUS ConsoleEfiGopFindModeFromAllowed(_In_ EFI_GRAPHICS_OUTPUT_PROTOCOL *GopProtocol, _In_ PBL_DISPLAY_MODE SupportedModes, _In_ ULONG MaximumIndex, _Out_ PULONG SupportedMode)
Definition: gop.c:77
return STATUS_SUCCESS
Definition: btrfs.c:2966

Referenced by ConsoleEfiGraphicalOpenProtocol().