]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Csm/BiosThunk/VideoDxe/BiosVideo.h
IntelFrameworkModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFrameworkModulePkg / 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 /**
169 Install Graphics Output Protocol onto VGA device handles.
170
171 @param This Pointer to driver binding protocol
172 @param Controller Controller handle to connect
173 @param RemainingDevicePath A pointer to the remaining portion of a device
174 path
175
176 @return EFI_STATUS
177
178 **/
179 EFI_STATUS
180 EFIAPI
181 BiosVideoDriverBindingStart (
182 IN EFI_DRIVER_BINDING_PROTOCOL *This,
183 IN EFI_HANDLE Controller,
184 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
185 );
186
187
188 /**
189 Stop.
190
191 @param This Pointer to driver binding protocol
192 @param Controller Controller handle to connect
193 @param NumberOfChildren Number of children handle created by this driver
194 @param ChildHandleBuffer Buffer containing child handle created
195
196 @retval EFI_SUCCESS Driver disconnected successfully from controller
197 @retval EFI_UNSUPPORTED Cannot find BIOS_VIDEO_DEV structure
198
199 **/
200 EFI_STATUS
201 EFIAPI
202 BiosVideoDriverBindingStop (
203 IN EFI_DRIVER_BINDING_PROTOCOL *This,
204 IN EFI_HANDLE Controller,
205 IN UINTN NumberOfChildren,
206 IN EFI_HANDLE *ChildHandleBuffer
207 );
208
209 //
210 // Private worker functions
211 //
212
213 /**
214 Check for VBE device.
215
216 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
217
218 @retval EFI_SUCCESS VBE device found
219
220 **/
221 EFI_STATUS
222 BiosVideoCheckForVbe (
223 IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate
224 );
225
226
227 /**
228 Check for VGA device.
229
230 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
231
232 @retval EFI_SUCCESS Standard VGA device found
233
234 **/
235 EFI_STATUS
236 BiosVideoCheckForVga (
237 IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate
238 );
239
240
241
242
243 /**
244 Release resource for biso video instance.
245
246 @param BiosVideoPrivate Video child device private data structure
247
248 **/
249 VOID
250 BiosVideoDeviceReleaseResource (
251 BIOS_VIDEO_DEV *BiosVideoPrivate
252 );
253
254 //
255 // BIOS Graphics Output Protocol functions
256 //
257
258 /**
259 Graphics Output protocol interface to get video mode.
260
261 @param This Protocol instance pointer.
262 @param ModeNumber The mode number to return information on.
263 @param SizeOfInfo A pointer to the size, in bytes, of the Info
264 buffer.
265 @param Info Caller allocated buffer that returns information
266 about ModeNumber.
267
268 @retval EFI_SUCCESS Mode information returned.
269 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
270 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the
271 video mode.
272 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
273 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
274
275 **/
276 EFI_STATUS
277 EFIAPI
278 BiosVideoGraphicsOutputQueryMode (
279 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
280 IN UINT32 ModeNumber,
281 OUT UINTN *SizeOfInfo,
282 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
283 );
284
285
286 /**
287 Graphics Output protocol interface to set video mode.
288
289 @param This Protocol instance pointer.
290 @param ModeNumber The mode number to be set.
291
292 @retval EFI_SUCCESS Graphics mode was changed.
293 @retval EFI_DEVICE_ERROR The device had an error and could not complete the
294 request.
295 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
296
297 **/
298 EFI_STATUS
299 EFIAPI
300 BiosVideoGraphicsOutputSetMode (
301 IN EFI_GRAPHICS_OUTPUT_PROTOCOL * This,
302 IN UINT32 ModeNumber
303 );
304
305
306 /**
307 Graphics Output protocol instance to block transfer for VBE device.
308
309 @param This Pointer to Graphics Output protocol instance
310 @param BltBuffer The data to transfer to screen
311 @param BltOperation The operation to perform
312 @param SourceX The X coordinate of the source for BltOperation
313 @param SourceY The Y coordinate of the source for BltOperation
314 @param DestinationX The X coordinate of the destination for
315 BltOperation
316 @param DestinationY The Y coordinate of the destination for
317 BltOperation
318 @param Width The width of a rectangle in the blt rectangle in
319 pixels
320 @param Height The height of a rectangle in the blt rectangle in
321 pixels
322 @param Delta Not used for EfiBltVideoFill and
323 EfiBltVideoToVideo operation. If a Delta of 0 is
324 used, the entire BltBuffer will be operated on. If
325 a subrectangle of the BltBuffer is used, then
326 Delta represents the number of bytes in a row of
327 the BltBuffer.
328
329 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
330 @retval EFI_SUCCESS Blt operation success
331
332 **/
333 EFI_STATUS
334 EFIAPI
335 BiosVideoGraphicsOutputVbeBlt (
336 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
337 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
338 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
339 IN UINTN SourceX,
340 IN UINTN SourceY,
341 IN UINTN DestinationX,
342 IN UINTN DestinationY,
343 IN UINTN Width,
344 IN UINTN Height,
345 IN UINTN Delta
346 );
347
348
349 /**
350 Grahpics Output protocol instance to block transfer for VGA device.
351
352 @param This Pointer to Grahpics Output protocol instance
353 @param BltBuffer The data to transfer to screen
354 @param BltOperation The operation to perform
355 @param SourceX The X coordinate of the source for BltOperation
356 @param SourceY The Y coordinate of the source for BltOperation
357 @param DestinationX The X coordinate of the destination for
358 BltOperation
359 @param DestinationY The Y coordinate of the destination for
360 BltOperation
361 @param Width The width of a rectangle in the blt rectangle in
362 pixels
363 @param Height The height of a rectangle in the blt rectangle in
364 pixels
365 @param Delta Not used for EfiBltVideoFill and
366 EfiBltVideoToVideo operation. If a Delta of 0 is
367 used, the entire BltBuffer will be operated on. If
368 a subrectangle of the BltBuffer is used, then
369 Delta represents the number of bytes in a row of
370 the BltBuffer.
371
372 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
373 @retval EFI_SUCCESS Blt operation success
374
375 **/
376 EFI_STATUS
377 EFIAPI
378 BiosVideoGraphicsOutputVgaBlt (
379 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
380 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
381 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
382 IN UINTN SourceX,
383 IN UINTN SourceY,
384 IN UINTN DestinationX,
385 IN UINTN DestinationY,
386 IN UINTN Width,
387 IN UINTN Height,
388 IN UINTN Delta
389 );
390
391 //
392 // BIOS VGA Mini Port Protocol functions
393 //
394
395 /**
396 VgaMiniPort protocol interface to set mode.
397
398 @param This Pointer to VgaMiniPort protocol instance
399 @param ModeNumber The index of the mode
400
401 @retval EFI_UNSUPPORTED The requested mode is not supported
402 @retval EFI_SUCCESS The requested mode is set successfully
403
404 **/
405 EFI_STATUS
406 EFIAPI
407 BiosVideoVgaMiniPortSetMode (
408 IN EFI_VGA_MINI_PORT_PROTOCOL *This,
409 IN UINTN ModeNumber
410 );
411
412 /**
413 Event handler for Exit Boot Service.
414
415 @param Event The event that be siganlled when exiting boot service.
416 @param Context Pointer to instance of BIOS_VIDEO_DEV.
417
418 **/
419 VOID
420 EFIAPI
421 BiosVideoNotifyExitBootServices (
422 IN EFI_EVENT Event,
423 IN VOID *Context
424 );
425
426 //
427 // Standard VGA Definitions
428 //
429 #define VGA_HORIZONTAL_RESOLUTION 640
430 #define VGA_VERTICAL_RESOLUTION 480
431 #define VGA_NUMBER_OF_BIT_PLANES 4
432 #define VGA_PIXELS_PER_BYTE 8
433 #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
434 #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
435
436 #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
437 #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
438
439 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
440
441 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
442
443 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
444
445 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
446 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
447 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
448 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
449 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
450
451 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
452
453 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
454 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
455 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
456 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
457 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
458 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
459 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
460
461 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
462
463 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
464
465 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
466
467 /**
468 Install child handles if the Handle supports MBR format.
469
470 @param This Calling context.
471 @param ParentHandle Parent Handle
472 @param ParentPciIo Parent PciIo interface
473 @param ParentLegacyBios Parent LegacyBios interface
474 @param ParentDevicePath Parent Device Path
475 @param RemainingDevicePath Remaining Device Path
476
477 @retval EFI_SUCCESS If a child handle was added
478 @retval other A child handle was not added
479
480 **/
481 EFI_STATUS
482 BiosVideoChildHandleInstall (
483 IN EFI_DRIVER_BINDING_PROTOCOL *This,
484 IN EFI_HANDLE ParentHandle,
485 IN EFI_PCI_IO_PROTOCOL *ParentPciIo,
486 IN EFI_LEGACY_BIOS_PROTOCOL *ParentLegacyBios,
487 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,
488 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
489 );
490
491 /**
492 Deregister an video child handle and free resources.
493
494 @param This Protocol instance pointer.
495 @param Controller Video controller handle
496 @param Handle Video child handle
497
498 @return EFI_STATUS
499
500 **/
501 EFI_STATUS
502 BiosVideoChildHandleUninstall (
503 EFI_DRIVER_BINDING_PROTOCOL *This,
504 EFI_HANDLE Controller,
505 EFI_HANDLE Handle
506 );
507
508 /**
509 Release resource for biso video instance.
510
511 @param BiosVideoPrivate Video child device private data structure
512
513 **/
514 VOID
515 BiosVideoDeviceReleaseResource (
516 BIOS_VIDEO_DEV *BiosVideoPrivate
517 );
518
519 /**
520 Check if all video child handles have been uninstalled.
521
522 @param Controller Video controller handle
523
524 @return TRUE Child handles exist.
525 @return FALSE All video child handles have been uninstalled.
526
527 **/
528 BOOLEAN
529 HasChildHandle (
530 IN EFI_HANDLE Controller
531 );
532 #endif