ReactOS 0.4.15-dev-8222-g9164419
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}
EFI_GUID EfiGraphicsOutputProtocol
Definition: firmware.c:28
NTSTATUS EfiCloseProtocol(_In_ EFI_HANDLE Handle, _In_ EFI_GUID *Protocol)
Definition: firmware.c:581
VOID BlDisplayInvalidateOemBitmap(VOID)
Definition: display.c:723
NTSTATUS EfiGopSetMode(_In_ EFI_GRAPHICS_OUTPUT_PROTOCOL *GopInterface, _In_ ULONG Mode)
Definition: firmware.c:1349
uint32_t ULONG
Definition: typedefs.h:59

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 */
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}
UINT32 UINTN
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS EfiGopGetCurrentMode(_In_ EFI_GRAPHICS_OUTPUT_PROTOCOL *GopInterface, _Out_ UINTN *Mode, _Out_ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Information)
Definition: firmware.c:1296
NTSTATUS BlMmMapPhysicalAddressEx(_In_ PVOID *VirtualAddress, _In_ ULONG Attributes, _In_ ULONGLONG Size, _In_ PHYSICAL_ADDRESS PhysicalAddress)
Definition: mm.c:192
@ BlMemoryUncached
Definition: bl.h:346
@ BlMemoryWriteBack
Definition: bl.h:349
VOID EfiGopGetFrameBuffer(_In_ EFI_GRAPHICS_OUTPUT_PROTOCOL *GopInterface, _Out_ PHYSICAL_ADDRESS *FrameBuffer, _Out_ UINTN *FrameBufferSize)
Definition: firmware.c:1255
#define NULL
Definition: types.h:112
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
Status
Definition: gdiplustypes.h:25
NTSTATUS ConsoleEfiGopGetGraphicalFormat(_In_ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *ModeInfo, _Out_ PULONG PixelDepth)
Definition: gop.c:18
_In_ ULONG Mode
Definition: hubbusif.h:303
ULONG FrameBufferSize
Definition: xboxvideo.c:29
PVOID FrameBuffer
Definition: xboxvideo.c:28
#define STATUS_SUCCESS
Definition: shellext.h:65

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:239

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 }
35}
@ PixelBitMask
@ PixelBlueGreenRedReserved8BitPerColor
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132

Referenced by ConsoleEfiGopEnable(), and ConsoleEfiGopOpen().

◆ ConsoleEfiGopIsPixelFormatSupported()

BOOLEAN ConsoleEfiGopIsPixelFormatSupported ( _In_ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION Mode)

Definition at line 38 of file gop.c.

41{
44
46
47 /* Check if it's simple BGR8 */
49 {
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 {
67 }
68 }
69 }
70
71 /* Return if the format was supported */
72 return Supported;
73}
unsigned char BOOLEAN
@ Supported
Definition: classpnp.h:733
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define RtlEqualMemory(dst, src, len)
Definition: kdvm.h:18
UCHAR PixelMask[8]
Definition: vga.c:37

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;
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);
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
274Quickie:
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}
VOID EfiPrintf(_In_ PWCHAR Format,...)
Definition: firmware.c:126
BL_DISPLAY_MODE ConsoleGraphicalResolutionList[]
Definition: display.c:22
NTSTATUS EfiOpenProtocol(_In_ EFI_HANDLE Handle, _In_ EFI_GUID *Protocol, _Out_ PVOID *Interface)
ULONG ConsoleGraphicalResolutionListSize
Definition: display.c:28
#define BL_DISPLAY_GRAPHICS_FORCED_HIGH_RES_MODE_FLAG
Definition: bl.h:135
#define BL_DISPLAY_GRAPHICS_FORCED_VIDEO_MODE_FLAG
Definition: bl.h:134
ULONG ConsoleGraphicalResolutionListFlags
Definition: display.c:21
NTSTATUS ConsoleEfiGopFindModeFromAllowed(_In_ EFI_GRAPHICS_OUTPUT_PROTOCOL *GopProtocol, _In_ PBL_DISPLAY_MODE SupportedModes, _In_ ULONG MaximumIndex, _Out_ PULONG SupportedMode)
Definition: gop.c:77
BOOLEAN ConsoleEfiGopIsPixelFormatSupported(_In_ EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *Mode)
Definition: gop.c:38
#define STATUS_NOT_SUPPORTED
Definition: ntstatus.h:423
#define L(x)
Definition: ntvdm.h:50
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE * Mode

Referenced by ConsoleEfiGraphicalOpenProtocol().