]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/Csm/BiosThunk/VideoDxe/BiosVideo.h
OvmfPkg: Apply uncrustify changes
[mirror_edk2.git] / OvmfPkg / Csm / BiosThunk / VideoDxe / BiosVideo.h
1 /** @file
2
3 Copyright (c) 2006 - 2012, Intel Corporation. All rights reserved.<BR>
4
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #ifndef _BIOS_GRAPHICS_OUTPUT_H_
10 #define _BIOS_GRAPHICS_OUTPUT_H_
11
12 #include <FrameworkDxe.h>
13
14 #include <Protocol/PciIo.h>
15 #include <Protocol/EdidActive.h>
16 #include <Protocol/DevicePath.h>
17 #include <Protocol/EdidDiscovered.h>
18 #include <Protocol/LegacyBios.h>
19 #include <Protocol/VgaMiniPort.h>
20 #include <Protocol/GraphicsOutput.h>
21 #include <Protocol/EdidOverride.h>
22
23 #include <Guid/StatusCodeDataTypeId.h>
24 #include <Guid/LegacyBios.h>
25 #include <Guid/EventGroup.h>
26
27 #include <Library/PcdLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/ReportStatusCodeLib.h>
30 #include <Library/BaseMemoryLib.h>
31 #include <Library/UefiDriverEntryPoint.h>
32 #include <Library/UefiBootServicesTableLib.h>
33 #include <Library/UefiLib.h>
34 #include <Library/DevicePathLib.h>
35 #include <Library/MemoryAllocationLib.h>
36
37 #include <IndustryStandard/Pci.h>
38 #include "VesaBiosExtensions.h"
39
40 //
41 // Packed format support: The number of bits reserved for each of the colors and the actual
42 // position of RGB in the frame buffer is specified in the VBE Mode information
43 //
44 typedef struct {
45 UINT8 Position; // Position of the color
46 UINT8 Mask; // The number of bits expressed as a mask
47 } BIOS_VIDEO_COLOR_PLACEMENT;
48
49 //
50 // BIOS Graphics Output Graphical Mode Data
51 //
52 typedef struct {
53 UINT16 VbeModeNumber;
54 UINT16 BytesPerScanLine;
55 VOID *LinearFrameBuffer;
56 UINTN FrameBufferSize;
57 UINT32 HorizontalResolution;
58 UINT32 VerticalResolution;
59 UINT32 ColorDepth;
60 UINT32 RefreshRate;
61 UINT32 BitsPerPixel;
62 BIOS_VIDEO_COLOR_PLACEMENT Red;
63 BIOS_VIDEO_COLOR_PLACEMENT Green;
64 BIOS_VIDEO_COLOR_PLACEMENT Blue;
65 BIOS_VIDEO_COLOR_PLACEMENT Reserved;
66 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;
67 EFI_PIXEL_BITMASK PixelBitMask;
68 } BIOS_VIDEO_MODE_DATA;
69
70 //
71 // BIOS video child handle private data Structure
72 //
73 #define BIOS_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
74
75 typedef struct {
76 UINTN Signature;
77 EFI_HANDLE Handle;
78
79 //
80 // Consumed Protocols
81 //
82 EFI_PCI_IO_PROTOCOL *PciIo;
83 EFI_LEGACY_BIOS_PROTOCOL *LegacyBios;
84
85 //
86 // Produced Protocols
87 //
88 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
89 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered;
90 EFI_EDID_ACTIVE_PROTOCOL EdidActive;
91 EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort;
92
93 //
94 // General fields
95 //
96 BOOLEAN VgaCompatible;
97 BOOLEAN ProduceGraphicsOutput;
98
99 //
100 // Graphics Output Protocol related fields
101 //
102 BOOLEAN HardwareNeedsStarting;
103 UINTN CurrentMode;
104 UINTN MaxMode;
105 BIOS_VIDEO_MODE_DATA *ModeData;
106 UINT8 *LineBuffer;
107 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *VbeFrameBuffer;
108 UINT8 *VgaFrameBuffer;
109
110 //
111 // VESA Bios Extensions related fields
112 //
113 UINTN NumberOfPagesBelow1MB; // Number of 4KB pages in PagesBelow1MB
114 EFI_PHYSICAL_ADDRESS PagesBelow1MB; // Buffer for all VBE Information Blocks
115 VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK *VbeInformationBlock; // 0x200 bytes. Must be allocated below 1MB
116 VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK *VbeModeInformationBlock; // 0x100 bytes. Must be allocated below 1MB
117 VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK *VbeEdidDataBlock; // 0x80 bytes. Must be allocated below 1MB
118 VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK *VbeCrtcInformationBlock; // 59 bytes. Must be allocated below 1MB
119 UINTN VbeSaveRestorePages; // Number of 4KB pages in VbeSaveRestoreBuffer
120 EFI_PHYSICAL_ADDRESS VbeSaveRestoreBuffer; // Must be allocated below 1MB
121 //
122 // Status code
123 //
124 EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
125
126 EFI_EVENT ExitBootServicesEvent;
127 } BIOS_VIDEO_DEV;
128
129 #define BIOS_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, BIOS_VIDEO_DEV, PciIo, BIOS_VIDEO_DEV_SIGNATURE)
130 #define BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS(a) CR (a, BIOS_VIDEO_DEV, GraphicsOutput, BIOS_VIDEO_DEV_SIGNATURE)
131 #define BIOS_VIDEO_DEV_FROM_VGA_MINI_PORT_THIS(a) CR (a, BIOS_VIDEO_DEV, VgaMiniPort, BIOS_VIDEO_DEV_SIGNATURE)
132
133 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
134
135 //
136 // Global Variables
137 //
138 extern EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding;
139 extern EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName;
140 extern EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2;
141
142 //
143 // Driver Binding Protocol functions
144 //
145
146 /**
147 Supported.
148
149 @param This Pointer to driver binding protocol
150 @param Controller Controller handle to connect
151 @param RemainingDevicePath A pointer to the remaining portion of a device
152 path
153
154 @retval EFI_STATUS EFI_SUCCESS:This controller can be managed by this
155 driver, Otherwise, this controller cannot be
156 managed by this driver
157
158 **/
159 EFI_STATUS
160 EFIAPI
161 BiosVideoDriverBindingSupported (
162 IN EFI_DRIVER_BINDING_PROTOCOL *This,
163 IN EFI_HANDLE Controller,
164 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
165 );
166
167 /**
168 Install Graphics Output Protocol onto VGA device handles.
169
170 @param This Pointer to driver binding protocol
171 @param Controller Controller handle to connect
172 @param RemainingDevicePath A pointer to the remaining portion of a device
173 path
174
175 @return EFI_STATUS
176
177 **/
178 EFI_STATUS
179 EFIAPI
180 BiosVideoDriverBindingStart (
181 IN EFI_DRIVER_BINDING_PROTOCOL *This,
182 IN EFI_HANDLE Controller,
183 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
184 );
185
186 /**
187 Stop.
188
189 @param This Pointer to driver binding protocol
190 @param Controller Controller handle to connect
191 @param NumberOfChildren Number of children handle created by this driver
192 @param ChildHandleBuffer Buffer containing child handle created
193
194 @retval EFI_SUCCESS Driver disconnected successfully from controller
195 @retval EFI_UNSUPPORTED Cannot find BIOS_VIDEO_DEV structure
196
197 **/
198 EFI_STATUS
199 EFIAPI
200 BiosVideoDriverBindingStop (
201 IN EFI_DRIVER_BINDING_PROTOCOL *This,
202 IN EFI_HANDLE Controller,
203 IN UINTN NumberOfChildren,
204 IN EFI_HANDLE *ChildHandleBuffer
205 );
206
207 //
208 // Private worker functions
209 //
210
211 /**
212 Check for VBE device.
213
214 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
215
216 @retval EFI_SUCCESS VBE device found
217
218 **/
219 EFI_STATUS
220 BiosVideoCheckForVbe (
221 IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate
222 );
223
224 /**
225 Check for VGA device.
226
227 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
228
229 @retval EFI_SUCCESS Standard VGA device found
230
231 **/
232 EFI_STATUS
233 BiosVideoCheckForVga (
234 IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate
235 );
236
237 /**
238 Release resource for BIOS video instance.
239
240 @param BiosVideoPrivate Video child device private data structure
241
242 **/
243 VOID
244 BiosVideoDeviceReleaseResource (
245 BIOS_VIDEO_DEV *BiosVideoPrivate
246 );
247
248 //
249 // BIOS Graphics Output Protocol functions
250 //
251
252 /**
253 Graphics Output protocol interface to get video mode.
254
255 @param This Protocol instance pointer.
256 @param ModeNumber The mode number to return information on.
257 @param SizeOfInfo A pointer to the size, in bytes, of the Info
258 buffer.
259 @param Info Caller allocated buffer that returns information
260 about ModeNumber.
261
262 @retval EFI_SUCCESS Mode information returned.
263 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
264 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the
265 video mode.
266 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
267 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
268
269 **/
270 EFI_STATUS
271 EFIAPI
272 BiosVideoGraphicsOutputQueryMode (
273 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
274 IN UINT32 ModeNumber,
275 OUT UINTN *SizeOfInfo,
276 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
277 );
278
279 /**
280 Graphics Output protocol interface to set video mode.
281
282 @param This Protocol instance pointer.
283 @param ModeNumber The mode number to be set.
284
285 @retval EFI_SUCCESS Graphics mode was changed.
286 @retval EFI_DEVICE_ERROR The device had an error and could not complete the
287 request.
288 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
289
290 **/
291 EFI_STATUS
292 EFIAPI
293 BiosVideoGraphicsOutputSetMode (
294 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
295 IN UINT32 ModeNumber
296 );
297
298 /**
299 Graphics Output protocol instance to block transfer for VBE device.
300
301 @param This Pointer to Graphics Output protocol instance
302 @param BltBuffer The data to transfer to screen
303 @param BltOperation The operation to perform
304 @param SourceX The X coordinate of the source for BltOperation
305 @param SourceY The Y coordinate of the source for BltOperation
306 @param DestinationX The X coordinate of the destination for
307 BltOperation
308 @param DestinationY The Y coordinate of the destination for
309 BltOperation
310 @param Width The width of a rectangle in the blt rectangle in
311 pixels
312 @param Height The height of a rectangle in the blt rectangle in
313 pixels
314 @param Delta Not used for EfiBltVideoFill and
315 EfiBltVideoToVideo operation. If a Delta of 0 is
316 used, the entire BltBuffer will be operated on. If
317 a subrectangle of the BltBuffer is used, then
318 Delta represents the number of bytes in a row of
319 the BltBuffer.
320
321 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
322 @retval EFI_SUCCESS Blt operation success
323
324 **/
325 EFI_STATUS
326 EFIAPI
327 BiosVideoGraphicsOutputVbeBlt (
328 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
329 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL,
330 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
331 IN UINTN SourceX,
332 IN UINTN SourceY,
333 IN UINTN DestinationX,
334 IN UINTN DestinationY,
335 IN UINTN Width,
336 IN UINTN Height,
337 IN UINTN Delta
338 );
339
340 /**
341 Graphics Output protocol instance to block transfer for VGA device.
342
343 @param This Pointer to Graphics Output protocol instance
344 @param BltBuffer The data to transfer to screen
345 @param BltOperation The operation to perform
346 @param SourceX The X coordinate of the source for BltOperation
347 @param SourceY The Y coordinate of the source for BltOperation
348 @param DestinationX The X coordinate of the destination for
349 BltOperation
350 @param DestinationY The Y coordinate of the destination for
351 BltOperation
352 @param Width The width of a rectangle in the blt rectangle in
353 pixels
354 @param Height The height of a rectangle in the blt rectangle in
355 pixels
356 @param Delta Not used for EfiBltVideoFill and
357 EfiBltVideoToVideo operation. If a Delta of 0 is
358 used, the entire BltBuffer will be operated on. If
359 a subrectangle of the BltBuffer is used, then
360 Delta represents the number of bytes in a row of
361 the BltBuffer.
362
363 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
364 @retval EFI_SUCCESS Blt operation success
365
366 **/
367 EFI_STATUS
368 EFIAPI
369 BiosVideoGraphicsOutputVgaBlt (
370 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
371 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer OPTIONAL,
372 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
373 IN UINTN SourceX,
374 IN UINTN SourceY,
375 IN UINTN DestinationX,
376 IN UINTN DestinationY,
377 IN UINTN Width,
378 IN UINTN Height,
379 IN UINTN Delta
380 );
381
382 //
383 // BIOS VGA Mini Port Protocol functions
384 //
385
386 /**
387 VgaMiniPort protocol interface to set mode.
388
389 @param This Pointer to VgaMiniPort protocol instance
390 @param ModeNumber The index of the mode
391
392 @retval EFI_UNSUPPORTED The requested mode is not supported
393 @retval EFI_SUCCESS The requested mode is set successfully
394
395 **/
396 EFI_STATUS
397 EFIAPI
398 BiosVideoVgaMiniPortSetMode (
399 IN EFI_VGA_MINI_PORT_PROTOCOL *This,
400 IN UINTN ModeNumber
401 );
402
403 /**
404 Event handler for Exit Boot Service.
405
406 @param Event The event that be signalled when exiting boot service.
407 @param Context Pointer to instance of BIOS_VIDEO_DEV.
408
409 **/
410 VOID
411 EFIAPI
412 BiosVideoNotifyExitBootServices (
413 IN EFI_EVENT Event,
414 IN VOID *Context
415 );
416
417 //
418 // Standard VGA Definitions
419 //
420 #define VGA_HORIZONTAL_RESOLUTION 640
421 #define VGA_VERTICAL_RESOLUTION 480
422 #define VGA_NUMBER_OF_BIT_PLANES 4
423 #define VGA_PIXELS_PER_BYTE 8
424 #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
425 #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
426
427 #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
428 #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
429
430 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
431
432 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
433
434 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
435
436 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
437 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
438 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
439 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
440 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
441
442 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
443
444 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
445 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
446 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
447 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
448 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
449 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
450 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
451
452 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
453
454 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
455
456 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
457
458 /**
459 Install child handles if the Handle supports MBR format.
460
461 @param This Calling context.
462 @param ParentHandle Parent Handle
463 @param ParentPciIo Parent PciIo interface
464 @param ParentLegacyBios Parent LegacyBios interface
465 @param ParentDevicePath Parent Device Path
466 @param RemainingDevicePath Remaining Device Path
467
468 @retval EFI_SUCCESS If a child handle was added
469 @retval other A child handle was not added
470
471 **/
472 EFI_STATUS
473 BiosVideoChildHandleInstall (
474 IN EFI_DRIVER_BINDING_PROTOCOL *This,
475 IN EFI_HANDLE ParentHandle,
476 IN EFI_PCI_IO_PROTOCOL *ParentPciIo,
477 IN EFI_LEGACY_BIOS_PROTOCOL *ParentLegacyBios,
478 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,
479 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
480 );
481
482 /**
483 Deregister an video child handle and free resources.
484
485 @param This Protocol instance pointer.
486 @param Controller Video controller handle
487 @param Handle Video child handle
488
489 @return EFI_STATUS
490
491 **/
492 EFI_STATUS
493 BiosVideoChildHandleUninstall (
494 EFI_DRIVER_BINDING_PROTOCOL *This,
495 EFI_HANDLE Controller,
496 EFI_HANDLE Handle
497 );
498
499 /**
500 Release resource for BIOS video instance.
501
502 @param BiosVideoPrivate Video child device private data structure
503
504 **/
505 VOID
506 BiosVideoDeviceReleaseResource (
507 BIOS_VIDEO_DEV *BiosVideoPrivate
508 );
509
510 /**
511 Check if all video child handles have been uninstalled.
512
513 @param Controller Video controller handle
514
515 @return TRUE Child handles exist.
516 @return FALSE All video child handles have been uninstalled.
517
518 **/
519 BOOLEAN
520 HasChildHandle (
521 IN EFI_HANDLE Controller
522 );
523
524 #endif