ReactOS 0.4.16-dev-2332-g4cba65d
uefivid.c
Go to the documentation of this file.
1/*
2 * PROJECT: FreeLoader UEFI Support
3 * LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4 * PURPOSE: Video output
5 * COPYRIGHT: Copyright 2022 Justin Miller <justinmiller100@gmail.com>
6 */
7
8#include <uefildr.h>
9#include "../vidfb.h"
10
11#include <debug.h>
13
14/* GLOBALS ********************************************************************/
15
20
24
25#define LOWEST_SUPPORTED_RES 1
26
27/* FUNCTIONS ******************************************************************/
28
29/* EFI 1.x */
30#ifdef EFI_UGA_DRAW_PROTOCOL_GUID
31
32/* NOTE: EFI UGA does not support any other format than 32-bit xRGB, and
33 * no direct access to the underlying hardware framebuffer is offered */
34C_ASSERT(sizeof(EFI_UGA_PIXEL) == sizeof(ULONG));
35
36#endif /* EFI */
37
38/* UEFI support, see efi/GraphicsOutput.h */
39#ifdef EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID // __GRAPHICS_OUTPUT_H__
40
42
47static EFI_PIXEL_BITMASK EfiPixelMasks[] =
48{ /* Red, Green, Blue, Reserved */
49 {0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000}, // PixelRedGreenBlueReserved8BitPerColor
50 {0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000}, // PixelBlueGreenRedReserved8BitPerColor
51 {0, 0, 0, 0} // PixelBitMask, PixelBltOnly, ...
52};
53
54#endif /* UEFI */
55
56static
59{
62
64 EFI_PIXEL_BITMASK* pPixelBitmask;
65 ULONG BitsPerPixel;
66
68 if (Status != EFI_SUCCESS)
69 {
70 TRACE("Failed to find GOP with status %d\n", Status);
71 return Status;
72 }
73
74 /* We don't need high resolutions for freeldr */
76
77 /* Physical format of the pixel */
79 switch (PixelFormat)
80 {
83 {
84 pPixelBitmask = &EfiPixelMasks[PixelFormat];
86 break;
87 }
88
89 case PixelBitMask:
90 {
91 /*
92 * When the GOP pixel format is given by PixelBitMask, the pixel
93 * element size _may be_ different from 4 bytes.
94 * See UEFI Spec Rev.2.10 Section 12.9 "Graphics Output Protocol":
95 * example code "GetPixelElementSize()" function.
96 */
97 pPixelBitmask = &gop->Mode->Info->PixelInformation;
98 BitsPerPixel =
99 PixelBitmasksToBpp(pPixelBitmask->RedMask,
100 pPixelBitmask->GreenMask,
101 pPixelBitmask->BlueMask,
102 pPixelBitmask->ReservedMask);
103 break;
104 }
105
106 case PixelBltOnly:
107 default:
108 {
109 ERR("Unsupported UEFI GOP format %lu\n", PixelFormat);
110 pPixelBitmask = NULL;
111 BitsPerPixel = 0;
112 break;
113 }
114 }
115
120 VramSize,
124 BitsPerPixel,
125 (PPIXEL_BITMASK)pPixelBitmask))
126 {
127 ERR("Couldn't initialize video framebuffer\n");
129 }
130 return Status;
131}
132
133static
136{
138 APPLE_GRAPH_INFO_PROTOCOL *AppleGraph = NULL;
139 EFI_PIXEL_BITMASK* pPixelBitmask;
140
142 UINT32 BytesPerRow, Width, Height, Depth;
143
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,
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 /* All devices requiring Apple Graphics Info use PixelBlueGreenRedReserved8BitPerColor. */
166 pPixelBitmask = &EfiPixelMasks[PixelBlueGreenRedReserved8BitPerColor];
167
172 VramSize,
173 Width,
174 Height,
175 (BytesPerRow / 4),
176 Depth,
177 (PPIXEL_BITMASK)pPixelBitmask))
178 {
179 ERR("Couldn't initialize video framebuffer\n");
181 }
182
183 return Status;
184}
185
188{
190
191 /* First, try GOP */
193 if (Status == EFI_SUCCESS)
194 return Status;
195
196 /* Try Apple Graphics Info if that fails */
197 TRACE("Failed to detect GOP, trying Apple Graphics Info\n");
199 if (Status == EFI_SUCCESS)
200 return Status;
201
202 /* We didn't find GOP or Apple Graphics Info, probably a UGA-only system */
203 ERR("Cannot find framebuffer!\n");
204 return Status;
205}
206
207
208VOID
210{
211 FbConsClearScreen(Attr);
212}
213
214VOID
215UefiVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
216{
217 FbConsPutChar(Ch, Attr, X, Y);
218}
219
220VOID
222{
224}
225
228{
229 /* We only have one mode, semi-text */
230 return VideoTextMode;
231}
232
233ULONG
235{
236 return FbConsGetBufferSize();
237}
238
239VOID
241{
243}
244
245VOID
247{
248 /* We don't have a cursor yet */
249}
250
251VOID
253{
254 /* We don't have a cursor yet */
255}
256
259{
260 return 0;
261}
262
263VOID
265 UCHAR Green, UCHAR Blue)
266{
267 /* Not supported */
268}
269
270VOID
272 UCHAR* Green, UCHAR* Blue)
273{
274 /* Not supported */
275}
#define APPLE_GRAPH_INFO_PROTOCOL_GUID
EFI_GRAPHICS_PIXEL_FORMAT
@ PixelBitMask
@ PixelRedGreenBlueReserved8BitPerColor
@ PixelBlueGreenRedReserved8BitPerColor
@ PixelBltOnly
#define EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID
#define EFI_UNSUPPORTED
Definition: UefiBaseType.h:123
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:31
#define EFI_SUCCESS
Definition: UefiBaseType.h:120
unsigned char BOOLEAN
Definition: actypes.h:127
COMPILER_DEPENDENT_UINT64 UINT64
Definition: actypes.h:131
#define ERR(fmt,...)
Definition: precomp.h:57
#define DBG_DEFAULT_CHANNEL(ch)
Definition: debug.h:106
@ VideoTextMode
Definition: machine.h:35
enum tagVIDEODISPLAYMODE VIDEODISPLAYMODE
Definition: bufpool.h:45
#define NULL
Definition: types.h:112
#define Y(I)
#define ULONG_PTR
Definition: config.h:101
INT PixelFormat
Status
Definition: gdiplustypes.h:25
#define C_ASSERT(e)
Definition: intsafe.h:73
if(dx< 0)
Definition: linetemp.h:194
ULONG FrameBufferSize
Definition: xboxvideo.c:30
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define RTL_BITS_OF(sizeOfArg)
Definition: ntbasedef.h:680
static VIDEODISPLAYMODE DisplayMode
Definition: pcvideo.c:119
#define Ch(x, y, z)
Definition: sha2.c:141
#define TRACE(s)
Definition: solgame.cpp:4
EFI_LOCATE_PROTOCOL LocateProtocol
Definition: UefiSpec.h:1873
EFI_GRAPHICS_PIXEL_FORMAT PixelFormat
EFI_PHYSICAL_ADDRESS FrameBufferBase
EFI_GRAPHICS_OUTPUT_MODE_INFORMATION * Info
EFI_BOOT_SERVICES * BootServices
Definition: UefiSpec.h:1959
Definition: ui.h:200
ReactOS Framebuffer-specific video device configuration data.
Definition: framebuf.h:35
EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE * Mode
EFI_GRAPHICS_OUTPUT_PROTOCOL_SET_MODE SetMode
Physical format of an RGB pixel, specified with per-component bit-masks. A bit being set defines thos...
Definition: vidfb.h:22
uint32_t * PULONG
Definition: typedefs.h:59
const char * PCSTR
Definition: typedefs.h:52
uint32_t ULONG_PTR
Definition: typedefs.h:65
uint32_t UINT32
Definition: typedefs.h:59
uint32_t ULONG
Definition: typedefs.h:59
VOID UefiVideoGetPaletteColor(UCHAR Color, UCHAR *Red, UCHAR *Green, UCHAR *Blue)
Definition: uefivid.c:271
EFI_GUID EfiGraphicsOutputProtocol
Definition: uefivid.c:18
VIDEODISPLAYMODE UefiVideoSetDisplayMode(PCSTR DisplayMode, BOOLEAN Init)
Definition: uefivid.c:227
VOID UefiVideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue)
Definition: uefivid.c:264
ULONG_PTR VramAddress
Definition: uefivid.c:21
VOID UefiVideoClearScreen(UCHAR Attr)
Definition: uefivid.c:209
VOID UefiVideoHideShowTextCursor(BOOLEAN Show)
Definition: uefivid.c:252
ULONG UefiVideoGetBufferSize(VOID)
Definition: uefivid.c:234
EFI_STATUS UefiInitializeVideo(VOID)
Definition: uefivid.c:187
VOID UefiVideoGetDisplaySize(PULONG Width, PULONG Height, PULONG Depth)
Definition: uefivid.c:221
VOID UefiVideoSetTextCursorPosition(UCHAR X, UCHAR Y)
Definition: uefivid.c:246
EFI_SYSTEM_TABLE * GlobalSystemTable
Definition: uefildr.c:16
#define LOWEST_SUPPORTED_RES
Definition: uefivid.c:25
EFI_GUID AppleGraphInfoProtocol
Definition: uefivid.c:19
static EFI_STATUS UefiInitializeAppleGraphics(VOID)
Definition: uefivid.c:135
PCM_FRAMEBUF_DEVICE_DATA FrameBufferData
Definition: uefivid.c:23
VOID UefiVideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y)
Definition: uefivid.c:215
ULONG VramSize
Definition: uefivid.c:22
VOID UefiVideoCopyOffScreenBufferToVRAM(PVOID Buffer)
Definition: uefivid.c:240
static EFI_STATUS UefiInitializeGop(VOID)
Definition: uefivid.c:58
EFI_HANDLE GlobalImageHandle
Definition: uefildr.c:15
BOOLEAN UefiVideoIsPaletteFixed(VOID)
Definition: uefivid.c:258
_In_ HFONT _Out_ PUINT _Out_ PUINT Width
Definition: font.h:89
_In_ HFONT _Out_ PUINT Height
Definition: font.h:88
VOID FbConsClearScreen(_In_ UCHAR Attr)
Definition: vidfb.c:413
VOID FbConsGetDisplaySize(_Out_ PULONG Width, _Out_ PULONG Height, _Out_ PULONG Depth)
Returns the width and height in number of CGA characters/attributes, of a full text-mode CGA-style ch...
Definition: vidfb.c:462
ULONG FbConsGetBufferSize(VOID)
Returns the size in bytes, of a full text-mode CGA-style character buffer rectangle that can fill the...
Definition: vidfb.c:481
VOID FbConsPutChar(_In_ UCHAR Char, _In_ UCHAR Attr, _In_ ULONG Column, _In_ ULONG Row)
Displays a character with specific text attributes at a given position.
Definition: vidfb.c:445
VOID FbConsCopyOffScreenBufferToVRAM(_In_ PVOID Buffer)
Copies a full text-mode CGA-style character buffer rectangle to the console.
Definition: vidfb.c:492
BOOLEAN VidFbInitializeVideo(_Out_opt_ PCM_FRAMEBUF_DEVICE_DATA *pFbData, _In_ ULONG_PTR BaseAddress, _In_ ULONG BufferSize, _In_ UINT32 ScreenWidth, _In_ UINT32 ScreenHeight, _In_ UINT32 PixelsPerScanLine, _In_ UINT32 BitsPerPixel, _In_opt_ PPIXEL_BITMASK PixelMasks)
Initializes internal framebuffer information based on the given parameters.
Definition: vidfb.c:99
FORCEINLINE ULONG PixelBitmasksToBpp(_In_ ULONG RedMask, _In_ ULONG GreenMask, _In_ ULONG BlueMask, _In_ ULONG ReservedMask)
Calculates the number of bits per pixel ("PixelDepth") for the given pixel format,...
Definition: vidfb.h:41
struct _PIXEL_BITMASK * PPIXEL_BITMASK
_In_opt_ PALLOCATE_FUNCTION _In_opt_ PFREE_FUNCTION _In_ ULONG _In_ SIZE_T _In_ ULONG _In_ USHORT Depth
Definition: exfuncs.h:819
unsigned char UCHAR
Definition: xmlstorage.h:181