82f77bffba8cd580d9d6484ef68d437319add9f4
[reactos.git] / reactos / boot / environ / lib / io / display / display.c
1 /*
2 * COPYRIGHT: See COPYING.ARM in the top level directory
3 * PROJECT: ReactOS UEFI Boot Library
4 * FILE: boot/environ/lib/platform/display.c
5 * PURPOSE: Boot Library Display Management Routines
6 * PROGRAMMER: Alex Ionescu (alex.ionescu@reactos.org)
7 */
8
9 /* INCLUDES ******************************************************************/
10
11 #include "bl.h"
12 #include <bcd.h>
13
14 /* DATA VARIABLES ************************************************************/
15
16 PVOID BfiCachedStrikeData;
17 LIST_ENTRY BfiDeferredListHead;
18 LIST_ENTRY BfiFontFileListHead;
19 PVOID BfiGraphicsRectangle;
20
21 ULONG ConsoleGraphicalResolutionListFlags;
22 BL_DISPLAY_MODE ConsoleGraphicalResolutionList[3] =
23 {
24 {1024, 768, 1024},
25 {800, 600, 800},
26 {1024, 600, 1024}
27 };
28 ULONG ConsoleGraphicalResolutionListSize = RTL_NUMBER_OF(ConsoleGraphicalResolutionList);
29
30 BL_DISPLAY_MODE ConsoleTextResolutionList[1] =
31 {
32 {80, 25, 80}
33 };
34
35 PVOID DspRemoteInputConsole;
36 PVOID DspTextConsole;
37 PVOID DspGraphicalConsole;
38
39 /* FUNCTIONS *****************************************************************/
40
41 BOOLEAN
42 DsppGraphicsDisabledByBcd (
43 VOID
44 )
45 {
46 //EarlyPrint(L"Disabling graphics\r\n");
47 return FALSE;
48 }
49
50 NTSTATUS
51 DsppInitialize (
52 _In_ ULONG Flags
53 )
54 {
55 BL_LIBRARY_PARAMETERS LibraryParameters = BlpLibraryParameters;
56 BOOLEAN NoGraphics;// , HighestMode;
57 NTSTATUS Status;
58 PBL_DISPLAY_MODE DisplayMode;
59 //ULONG GraphicsResolution;
60 PBL_GRAPHICS_CONSOLE GraphicsConsole;
61 PBL_TEXT_CONSOLE TextConsole, RemoteConsole;
62
63 /* Initialize font data */
64 BfiCachedStrikeData = 0;
65 InitializeListHead(&BfiDeferredListHead);
66 InitializeListHead(&BfiFontFileListHead);
67
68 /* Allocate the font rectangle */
69 BfiGraphicsRectangle = BlMmAllocateHeap(0x5A);
70 if (!BfiGraphicsRectangle)
71 {
72 return STATUS_NO_MEMORY;
73 }
74
75 /* Display re-initialization not yet handled */
76 if (LibraryParameters.LibraryFlags & BL_LIBRARY_FLAG_REINITIALIZE_ALL)
77 {
78 EfiPrintf(L"Display path not handled\r\n");
79 return STATUS_NOT_SUPPORTED;
80 }
81
82 /* Check if no graphics console is needed */
83 if ((Flags & BL_LIBRARY_FLAG_NO_GRAPHICS_CONSOLE) ||
84 (DsppGraphicsDisabledByBcd()))
85 {
86 /* Remember this */
87 NoGraphics = TRUE;
88 }
89 else
90 {
91 /* No graphics -- remember this */
92 NoGraphics = FALSE;
93 }
94
95 /* On first load, we always initialize a graphics display */
96 GraphicsConsole = NULL;
97 if (!(Flags & BL_LIBRARY_FLAG_REINITIALIZE_ALL) || !(NoGraphics))
98 {
99 /* Default to mode 0 (1024x768) */
100 DisplayMode = &ConsoleGraphicalResolutionList[0];
101
102 /* Check what resolution to use*/
103 #if 0
104 Status = BlGetBootOptionInteger(BlpApplicationEntry.BcdData,
105 BcdLibraryInteger_GraphicsResolution,
106 &GraphicsResolution);
107 #else
108 //GraphicsResolution = 0;
109 Status = STATUS_NOT_FOUND;
110 #endif
111 if (NT_SUCCESS(Status))
112 {
113 ConsoleGraphicalResolutionListFlags |= BL_DISPLAY_GRAPHICS_FORCED_VIDEO_MODE_FLAG;
114 EfiPrintf(L"Display selection not yet handled\r\n");
115 return STATUS_NOT_IMPLEMENTED;
116 }
117
118 /* Check if the highest mode should be forced */
119 #if 0
120 Status = BlGetBootOptionBoolean(BlpApplicationEntry.BcdData,
121 BcdLibraryBoolean_GraphicsForceHighestMode,
122 &HighestMode);
123 #else
124 //HighestMode = 0;
125 Status = STATUS_NOT_FOUND;
126 #endif
127 if (NT_SUCCESS(Status))
128 {
129 ConsoleGraphicalResolutionListFlags |= BL_DISPLAY_GRAPHICS_FORCED_HIGH_RES_MODE_FLAG;
130 EfiPrintf(L"High res mode not yet handled\r\n");
131 return STATUS_NOT_IMPLEMENTED;
132 }
133
134 /* Do we need graphics mode after all? */
135 if (!NoGraphics)
136 {
137 /* Yep -- go allocate it */
138 GraphicsConsole = BlMmAllocateHeap(sizeof(*GraphicsConsole));
139 if (GraphicsConsole)
140 {
141 /* Construct it */
142 Status = ConsoleGraphicalConstruct(GraphicsConsole);
143 if (!NT_SUCCESS(Status))
144 {
145 EfiPrintf(L"GFX FAILED: %lx\r\n", Status);
146 BlMmFreeHeap(GraphicsConsole);
147 GraphicsConsole = NULL;
148 }
149 else
150 {
151 /* TEST */
152 RtlFillMemory(GraphicsConsole->FrameBuffer, GraphicsConsole->FrameBufferSize, 0x55);
153 }
154 }
155 }
156
157 /* Are we using something else than the default mode? */
158 if (DisplayMode != &ConsoleGraphicalResolutionList[0])
159 {
160 EfiPrintf(L"Display path not handled\r\n");
161 return STATUS_NOT_SUPPORTED;
162 }
163
164 /* Mask out all the flags now */
165 ConsoleGraphicalResolutionListFlags &= ~(BL_DISPLAY_GRAPHICS_FORCED_VIDEO_MODE_FLAG |
166 BL_DISPLAY_GRAPHICS_FORCED_HIGH_RES_MODE_FLAG);
167 }
168
169 /* Do we have a graphics console? */
170 TextConsole = NULL;
171 if (!GraphicsConsole)
172 {
173 /* Nope -- go allocate a text console */
174 TextConsole = BlMmAllocateHeap(sizeof(*TextConsole));
175 if (TextConsole)
176 {
177 /* Construct it */
178 Status = ConsoleTextLocalConstruct(TextConsole, TRUE);
179 if (!NT_SUCCESS(Status))
180 {
181 BlMmFreeHeap(TextConsole);
182 TextConsole = NULL;
183 }
184 }
185 }
186
187 /* Initialize all globals to NULL */
188 DspRemoteInputConsole = NULL;
189 DspTextConsole = NULL;
190 DspGraphicalConsole = NULL;
191
192 /* If we don't have a text console, go get a remote console */
193 RemoteConsole = NULL;
194 if (!TextConsole)
195 {
196 ConsoleCreateRemoteConsole(&RemoteConsole);
197 }
198
199 /* Do we have a remote console? */
200 if (!RemoteConsole)
201 {
202 /* Nope -- what about a graphical one? */
203 if (GraphicsConsole)
204 {
205 /* Yes, use it for both graphics and text */
206 DspGraphicalConsole = GraphicsConsole;
207 DspTextConsole = GraphicsConsole;
208 }
209 else if (TextConsole)
210 {
211 /* Nope, but we have a text console */
212 DspTextConsole = TextConsole;
213 }
214
215 /* Console has been setup */
216 return STATUS_SUCCESS;
217 }
218
219 /* We have a remote console -- have to figure out how to use it*/
220 EfiPrintf(L"Display path not handled\r\n");
221 return STATUS_NOT_SUPPORTED;
222 }
223
224 NTSTATUS
225 BlpDisplayInitialize (
226 _In_ ULONG Flags
227 )
228 {
229 NTSTATUS Status;
230
231 /* Are we resetting or initializing? */
232 if (Flags & BL_LIBRARY_FLAG_REINITIALIZE)
233 {
234 /* This is a reset */
235 Status = STATUS_NOT_IMPLEMENTED;
236 #if 0
237 Status = DsppReinitialize(Flags);
238 if (NT_SUCCESS(Status))
239 {
240 Status = BlpDisplayReinitialize();
241 }
242 #endif
243 }
244 else
245 {
246 /* Initialize the display */
247 Status = DsppInitialize(Flags);
248 }
249
250 /* Return display initailziation state */
251 return Status;
252 }
253
254 VOID
255 BlDisplayGetTextCellResolution (
256 _Out_ PULONG TextWidth,
257 _Out_ PULONG TextHeight
258 )
259 {
260 NTSTATUS Status;
261
262 /* If the caller doesn't want anything, bail out */
263 if (!(TextWidth) || !(TextHeight))
264 {
265 return;
266 }
267
268 /* Do we have a text console? */
269 Status = STATUS_UNSUCCESSFUL;
270 if (DspTextConsole)
271 {
272 /* Do we have a graphics console? */
273 if (DspGraphicalConsole)
274 {
275 /* Yep -- query it */
276 EfiPrintf(L"Not supported\r\n");
277 Status = STATUS_NOT_IMPLEMENTED;
278 }
279 }
280
281 /* Check if we failed to get it from the graphics console */
282 if (!NT_SUCCESS(Status))
283 {
284 /* Set default text size */
285 *TextWidth = 8;
286 *TextHeight = 8;
287 }
288 }