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