]>
Commit | Line | Data |
---|---|---|
804405e7 | 1 | /*++ |
2 | ||
ab5255fc | 3 | Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR> |
f9b8ab56 | 4 | This program and the accompanying materials |
804405e7 | 5 | are licensed and made available under the terms and conditions of the BSD License |
6 | which accompanies this distribution. The full text of the license may be found at | |
7 | http://opensource.org/licenses/bsd-license.php | |
8 | ||
9 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, | |
10 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. | |
11 | ||
12 | Module Name: | |
13 | ||
14 | UnixUgaScreen.c | |
15 | ||
16 | Abstract: | |
17 | ||
18 | This file produces the graphics abstration of UGA. It is called by | |
19 | UnixUgaDriver.c file which deals with the EFI 1.1 driver model. | |
20 | This file just does graphics. | |
21 | ||
22 | --*/ | |
23 | ||
24 | #include "UnixUga.h" | |
25 | ||
26 | EFI_UNIX_THUNK_PROTOCOL *mUnix; | |
7492c63d | 27 | EFI_EVENT mUgaScreenExitBootServicesEvent; |
804405e7 | 28 | |
804405e7 | 29 | EFI_STATUS |
30 | UnixUgaStartWindow ( | |
31 | IN UGA_PRIVATE_DATA *Private, | |
32 | IN UINT32 HorizontalResolution, | |
33 | IN UINT32 VerticalResolution, | |
34 | IN UINT32 ColorDepth, | |
35 | IN UINT32 RefreshRate | |
36 | ); | |
37 | ||
804405e7 | 38 | VOID |
39 | EFIAPI | |
40 | KillNtUgaThread ( | |
41 | IN EFI_EVENT Event, | |
42 | IN VOID *Context | |
43 | ); | |
44 | ||
45 | // | |
46 | // UGA Protocol Member Functions | |
47 | // | |
48 | ||
49 | EFI_STATUS | |
50 | EFIAPI | |
51 | UnixUgaGetMode ( | |
52 | EFI_UGA_DRAW_PROTOCOL *This, | |
53 | UINT32 *HorizontalResolution, | |
54 | UINT32 *VerticalResolution, | |
55 | UINT32 *ColorDepth, | |
56 | UINT32 *RefreshRate | |
57 | ) | |
58 | /*++ | |
59 | ||
60 | Routine Description: | |
61 | Return the current video mode information. | |
62 | ||
63 | Arguments: | |
64 | This - Protocol instance pointer. | |
65 | HorizontalResolution - Current video horizontal resolution in pixels | |
66 | VerticalResolution - Current video Vertical resolution in pixels | |
67 | ColorDepth - Current video color depth in bits per pixel | |
68 | RefreshRate - Current video refresh rate in Hz. | |
69 | ||
70 | Returns: | |
71 | EFI_SUCCESS - Mode information returned. | |
72 | EFI_NOT_STARTED - Video display is not initialized. Call SetMode () | |
73 | EFI_INVALID_PARAMETER - One of the input args was NULL. | |
74 | ||
75 | --*/ | |
76 | // TODO: ADD IN/OUT description here | |
77 | { | |
78 | UGA_PRIVATE_DATA *Private; | |
79 | ||
80 | Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (This); | |
81 | ||
82 | if (Private->HardwareNeedsStarting) { | |
83 | return EFI_NOT_STARTED; | |
84 | } | |
85 | ||
86 | if ((HorizontalResolution == NULL) || | |
87 | (VerticalResolution == NULL) || | |
88 | (ColorDepth == NULL) || | |
89 | (RefreshRate == NULL)) { | |
90 | return EFI_INVALID_PARAMETER; | |
91 | } | |
92 | ||
93 | *HorizontalResolution = Private->HorizontalResolution; | |
94 | *VerticalResolution = Private->VerticalResolution; | |
95 | *ColorDepth = Private->ColorDepth; | |
96 | *RefreshRate = Private->RefreshRate; | |
97 | return EFI_SUCCESS; | |
98 | } | |
99 | ||
100 | EFI_STATUS | |
101 | EFIAPI | |
102 | UnixUgaSetMode ( | |
103 | EFI_UGA_DRAW_PROTOCOL *This, | |
104 | UINT32 HorizontalResolution, | |
105 | UINT32 VerticalResolution, | |
106 | UINT32 ColorDepth, | |
107 | UINT32 RefreshRate | |
108 | ) | |
109 | /*++ | |
110 | ||
111 | Routine Description: | |
112 | Return the current video mode information. | |
113 | ||
114 | Arguments: | |
115 | This - Protocol instance pointer. | |
116 | HorizontalResolution - Current video horizontal resolution in pixels | |
117 | VerticalResolution - Current video Vertical resolution in pixels | |
118 | ColorDepth - Current video color depth in bits per pixel | |
119 | RefreshRate - Current video refresh rate in Hz. | |
120 | ||
121 | Returns: | |
122 | EFI_SUCCESS - Mode information returned. | |
123 | EFI_NOT_STARTED - Video display is not initialized. Call SetMode () | |
124 | EFI_INVALID_PARAMETER - One of the input args was NULL. | |
125 | ||
126 | --*/ | |
127 | // TODO: EFI_DEVICE_ERROR - add return value to function comment | |
128 | // TODO: EFI_DEVICE_ERROR - add return value to function comment | |
129 | // TODO: ADD IN/OUT description here | |
130 | { | |
131 | EFI_STATUS Status; | |
132 | UGA_PRIVATE_DATA *Private; | |
133 | EFI_UGA_PIXEL Fill; | |
134 | ||
135 | Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (This); | |
136 | ||
137 | if (Private->HardwareNeedsStarting) { | |
138 | Status = UnixUgaStartWindow ( | |
139 | Private, | |
140 | HorizontalResolution, | |
141 | VerticalResolution, | |
142 | ColorDepth, | |
143 | RefreshRate | |
144 | ); | |
145 | if (EFI_ERROR (Status)) { | |
146 | return EFI_DEVICE_ERROR; | |
147 | } | |
148 | ||
149 | Private->HardwareNeedsStarting = FALSE; | |
150 | } | |
151 | Status = Private->UgaIo->UgaSize(Private->UgaIo, | |
152 | HorizontalResolution, | |
153 | VerticalResolution); | |
154 | ||
155 | Private->HorizontalResolution = HorizontalResolution; | |
156 | Private->VerticalResolution = VerticalResolution; | |
157 | Private->ColorDepth = ColorDepth; | |
158 | Private->RefreshRate = RefreshRate; | |
159 | ||
160 | Fill.Red = 0x7f; | |
161 | Fill.Green = 0x7F; | |
162 | Fill.Blue = 0x7f; | |
163 | This->Blt ( | |
164 | This, | |
165 | &Fill, | |
166 | EfiUgaVideoFill, | |
167 | 0, | |
168 | 0, | |
169 | 0, | |
170 | 0, | |
171 | HorizontalResolution, | |
172 | VerticalResolution, | |
173 | HorizontalResolution * sizeof (EFI_UGA_PIXEL) | |
174 | ); | |
175 | return EFI_SUCCESS; | |
176 | } | |
177 | ||
178 | EFI_STATUS | |
179 | EFIAPI | |
180 | UnixUgaBlt ( | |
181 | IN EFI_UGA_DRAW_PROTOCOL *This, | |
182 | IN EFI_UGA_PIXEL *BltBuffer, OPTIONAL | |
183 | IN EFI_UGA_BLT_OPERATION BltOperation, | |
184 | IN UINTN SourceX, | |
185 | IN UINTN SourceY, | |
186 | IN UINTN DestinationX, | |
187 | IN UINTN DestinationY, | |
188 | IN UINTN Width, | |
189 | IN UINTN Height, | |
190 | IN UINTN Delta OPTIONAL | |
191 | ) | |
192 | /*++ | |
193 | ||
194 | Routine Description: | |
195 | Blt pixels from the rectangle (Width X Height) formed by the BltBuffer | |
196 | onto the graphics screen starting a location (X, Y). (0, 0) is defined as | |
197 | the upper left hand side of the screen. (X, Y) can be outside of the | |
198 | current screen geometry and the BltBuffer will be cliped when it is | |
199 | displayed. X and Y can be negative or positive. If Width or Height is | |
200 | bigger than the current video screen the image will be clipped. | |
201 | ||
202 | Arguments: | |
203 | This - Protocol instance pointer. | |
204 | X - X location on graphics screen. | |
205 | Y - Y location on the graphics screen. | |
206 | Width - Width of BltBuffer. | |
207 | Height - Hight of BltBuffer | |
208 | BltOperation - Operation to perform on BltBuffer and video memory | |
209 | BltBuffer - Buffer containing data to blt into video buffer. This | |
210 | buffer has a size of Width*Height*sizeof(EFI_UGA_PIXEL) | |
211 | SourceX - If the BltOperation is a EfiCopyBlt this is the source | |
212 | of the copy. For other BLT operations this argument is not | |
213 | used. | |
214 | SourceX - If the BltOperation is a EfiCopyBlt this is the source | |
215 | of the copy. For other BLT operations this argument is not | |
216 | used. | |
217 | ||
218 | Returns: | |
219 | EFI_SUCCESS - The palette is updated with PaletteArray. | |
220 | EFI_INVALID_PARAMETER - BltOperation is not valid. | |
221 | EFI_DEVICE_ERROR - A hardware error occured writting to the video | |
222 | buffer. | |
223 | ||
224 | --*/ | |
225 | // TODO: SourceY - add argument and description to function comment | |
226 | // TODO: DestinationX - add argument and description to function comment | |
227 | // TODO: DestinationY - add argument and description to function comment | |
228 | // TODO: Delta - add argument and description to function comment | |
229 | { | |
230 | UGA_PRIVATE_DATA *Private; | |
231 | EFI_TPL OriginalTPL; | |
232 | EFI_STATUS Status; | |
ab5255fc | 233 | UGA_BLT_ARGS UgaBltArgs; |
804405e7 | 234 | |
235 | Private = UGA_DRAW_PRIVATE_DATA_FROM_THIS (This); | |
236 | ||
237 | if ((BltOperation < 0) || (BltOperation >= EfiUgaBltMax)) { | |
238 | return EFI_INVALID_PARAMETER; | |
239 | } | |
240 | ||
241 | if (Width == 0 || Height == 0) { | |
242 | return EFI_INVALID_PARAMETER; | |
243 | } | |
244 | // | |
245 | // If Delta is zero, then the entire BltBuffer is being used, so Delta | |
246 | // is the number of bytes in each row of BltBuffer. Since BltBuffer is Width pixels size, | |
247 | // the number of bytes in each row can be computed. | |
248 | // | |
249 | if (Delta == 0) { | |
250 | Delta = Width * sizeof (EFI_UGA_PIXEL); | |
251 | } | |
252 | ||
253 | // | |
254 | // We have to raise to TPL Notify, so we make an atomic write the frame buffer. | |
255 | // We would not want a timer based event (Cursor, ...) to come in while we are | |
256 | // doing this operation. | |
257 | // | |
258 | OriginalTPL = gBS->RaiseTPL (TPL_NOTIFY); | |
bb111c23 | 259 | |
ab5255fc | 260 | // |
c8e07351 | 261 | // Pack UGA Draw protocol parameters to UGA_BLT_ARGS structure to adapt to |
262 | // UgaBlt() API of Unix UGA IO protocol. | |
ab5255fc | 263 | // |
264 | UgaBltArgs.DestinationX = DestinationX; | |
265 | UgaBltArgs.DestinationY = DestinationY; | |
266 | UgaBltArgs.Height = Height; | |
267 | UgaBltArgs.Width = Width; | |
268 | UgaBltArgs.SourceX = SourceX; | |
269 | UgaBltArgs.SourceY = SourceY; | |
270 | UgaBltArgs.Delta = Delta; | |
804405e7 | 271 | Status = Private->UgaIo->UgaBlt (Private->UgaIo, |
272 | BltBuffer, | |
273 | BltOperation, | |
ab5255fc | 274 | &UgaBltArgs |
275 | ); | |
804405e7 | 276 | |
277 | gBS->RestoreTPL (OriginalTPL); | |
278 | ||
279 | return Status; | |
280 | } | |
281 | ||
282 | ||
283 | // | |
284 | // Construction and Destruction functions | |
285 | // | |
286 | ||
287 | EFI_STATUS | |
288 | UnixUgaSupported ( | |
289 | IN EFI_UNIX_IO_PROTOCOL *UnixIo | |
290 | ) | |
291 | /*++ | |
292 | ||
293 | Routine Description: | |
294 | ||
295 | Arguments: | |
296 | ||
297 | Returns: | |
298 | ||
299 | None | |
300 | ||
301 | --*/ | |
302 | // TODO: UnixIo - add argument and description to function comment | |
303 | // TODO: EFI_UNSUPPORTED - add return value to function comment | |
304 | // TODO: EFI_SUCCESS - add return value to function comment | |
305 | { | |
306 | // | |
307 | // Check to see if the IO abstraction represents a device type we support. | |
308 | // | |
309 | // This would be replaced a check of PCI subsystem ID, etc. | |
310 | // | |
311 | if (!CompareGuid (UnixIo->TypeGuid, &gEfiUnixUgaGuid)) { | |
312 | return EFI_UNSUPPORTED; | |
313 | } | |
314 | ||
315 | return EFI_SUCCESS; | |
316 | } | |
317 | ||
318 | ||
804405e7 | 319 | EFI_STATUS |
320 | UnixUgaStartWindow ( | |
321 | IN UGA_PRIVATE_DATA *Private, | |
322 | IN UINT32 HorizontalResolution, | |
323 | IN UINT32 VerticalResolution, | |
324 | IN UINT32 ColorDepth, | |
325 | IN UINT32 RefreshRate | |
326 | ) | |
327 | /*++ | |
328 | ||
329 | Routine Description: | |
330 | ||
331 | TODO: Add function description | |
332 | ||
333 | Arguments: | |
334 | ||
335 | Private - TODO: add argument description | |
336 | HorizontalResolution - TODO: add argument description | |
337 | VerticalResolution - TODO: add argument description | |
338 | ColorDepth - TODO: add argument description | |
339 | RefreshRate - TODO: add argument description | |
340 | ||
341 | Returns: | |
342 | ||
343 | TODO: add return values | |
344 | ||
345 | --*/ | |
346 | { | |
347 | EFI_STATUS Status; | |
348 | ||
349 | mUnix = Private->UnixThunk; | |
350 | ||
351 | Private->HorizontalResolution = HorizontalResolution; | |
352 | Private->VerticalResolution = VerticalResolution; | |
353 | ||
354 | // | |
355 | // Register to be notified on exit boot services so we can destroy the window. | |
356 | // | |
357 | Status = gBS->CreateEvent ( | |
358 | EVT_SIGNAL_EXIT_BOOT_SERVICES, | |
359 | TPL_CALLBACK, | |
360 | KillNtUgaThread, | |
361 | Private, | |
362 | &mUgaScreenExitBootServicesEvent | |
363 | ); | |
364 | ||
365 | Status = Private->UnixThunk->UgaCreate(&Private->UgaIo, Private->WindowName); | |
366 | return Status; | |
367 | } | |
368 | ||
369 | EFI_STATUS | |
370 | UnixUgaConstructor ( | |
371 | UGA_PRIVATE_DATA *Private | |
372 | ) | |
373 | /*++ | |
374 | ||
375 | Routine Description: | |
376 | ||
377 | Arguments: | |
378 | ||
379 | Returns: | |
380 | ||
381 | None | |
382 | ||
383 | --*/ | |
384 | // TODO: Private - add argument and description to function comment | |
385 | // TODO: EFI_SUCCESS - add return value to function comment | |
386 | { | |
387 | ||
388 | Private->UgaDraw.GetMode = UnixUgaGetMode; | |
389 | Private->UgaDraw.SetMode = UnixUgaSetMode; | |
390 | Private->UgaDraw.Blt = UnixUgaBlt; | |
391 | ||
392 | Private->HardwareNeedsStarting = TRUE; | |
393 | Private->UgaIo = NULL; | |
394 | ||
395 | UnixUgaInitializeSimpleTextInForWindow (Private); | |
396 | ||
2ff79f2e | 397 | UnixUgaInitializeSimplePointerForWindow (Private); |
398 | ||
804405e7 | 399 | return EFI_SUCCESS; |
400 | } | |
401 | ||
402 | EFI_STATUS | |
403 | UnixUgaDestructor ( | |
404 | UGA_PRIVATE_DATA *Private | |
405 | ) | |
406 | /*++ | |
407 | ||
408 | Routine Description: | |
409 | ||
410 | Arguments: | |
411 | ||
412 | Returns: | |
413 | ||
414 | None | |
415 | ||
416 | --*/ | |
417 | // TODO: Private - add argument and description to function comment | |
418 | // TODO: EFI_SUCCESS - add return value to function comment | |
419 | { | |
420 | if (!Private->HardwareNeedsStarting) { | |
421 | Private->UgaIo->UgaClose(Private->UgaIo); | |
422 | Private->UgaIo = NULL; | |
423 | } | |
424 | ||
425 | return EFI_SUCCESS; | |
426 | } | |
427 | ||
804405e7 | 428 | VOID |
429 | EFIAPI | |
430 | KillNtUgaThread ( | |
431 | IN EFI_EVENT Event, | |
432 | IN VOID *Context | |
433 | ) | |
434 | /*++ | |
435 | ||
436 | Routine Description: | |
437 | ||
438 | This is the UGA screen's callback notification function for exit-boot-services. | |
439 | All we do here is call UnixUgaDestructor(). | |
440 | ||
441 | Arguments: | |
442 | ||
443 | Event - not used | |
444 | Context - pointer to the Private structure. | |
445 | ||
446 | Returns: | |
447 | ||
448 | None. | |
449 | ||
450 | --*/ | |
451 | { | |
452 | EFI_STATUS Status; | |
453 | Status = UnixUgaDestructor (Context); | |
454 | } |