]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Csm/BiosThunk/VideoDxe/BiosVideo.h
Currently restoring PCI attributes are put in child uninstall logic, if one child...
[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 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 //
93 // Produced Protocols
94 //
95 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
96 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered;
97 EFI_EDID_ACTIVE_PROTOCOL EdidActive;
98 EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort;
99
100 //
101 // General fields
102 //
103 BOOLEAN VgaCompatible;
104 BOOLEAN ProduceGraphicsOutput;
105
106 //
107 // Graphics Output Protocol related fields
108 //
109 BOOLEAN HardwareNeedsStarting;
110 UINTN CurrentMode;
111 UINTN MaxMode;
112 BIOS_VIDEO_MODE_DATA *ModeData;
113 UINT8 *LineBuffer;
114 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *VbeFrameBuffer;
115 UINT8 *VgaFrameBuffer;
116
117 //
118 // VESA Bios Extensions related fields
119 //
120 UINTN NumberOfPagesBelow1MB; // Number of 4KB pages in PagesBelow1MB
121 EFI_PHYSICAL_ADDRESS PagesBelow1MB; // Buffer for all VBE Information Blocks
122 VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK *VbeInformationBlock; // 0x200 bytes. Must be allocated below 1MB
123 VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK *VbeModeInformationBlock; // 0x100 bytes. Must be allocated below 1MB
124 VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK *VbeEdidDataBlock; // 0x80 bytes. Must be allocated below 1MB
125 VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK *VbeCrtcInformationBlock; // 59 bytes. Must be allocated below 1MB
126 UINTN VbeSaveRestorePages; // Number of 4KB pages in VbeSaveRestoreBuffer
127 EFI_PHYSICAL_ADDRESS VbeSaveRestoreBuffer; // Must be allocated below 1MB
128 //
129 // Status code
130 //
131 EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
132
133 EFI_EVENT ExitBootServicesEvent;
134 } BIOS_VIDEO_DEV;
135
136 #define BIOS_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, BIOS_VIDEO_DEV, PciIo, BIOS_VIDEO_DEV_SIGNATURE)
137 #define BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS(a) CR (a, BIOS_VIDEO_DEV, GraphicsOutput, BIOS_VIDEO_DEV_SIGNATURE)
138 #define BIOS_VIDEO_DEV_FROM_VGA_MINI_PORT_THIS(a) CR (a, BIOS_VIDEO_DEV, VgaMiniPort, BIOS_VIDEO_DEV_SIGNATURE)
139
140 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
141
142 //
143 // Global Variables
144 //
145 extern EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding;
146 extern EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName;
147 extern EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2;
148
149 //
150 // Driver Binding Protocol functions
151 //
152
153 /**
154 Supported.
155
156 @param This Pointer to driver binding protocol
157 @param Controller Controller handle to connect
158 @param RemainingDevicePath A pointer to the remaining portion of a device
159 path
160
161 @retval EFI_STATUS EFI_SUCCESS:This controller can be managed by this
162 driver, Otherwise, this controller cannot be
163 managed by this driver
164
165 **/
166 EFI_STATUS
167 EFIAPI
168 BiosVideoDriverBindingSupported (
169 IN EFI_DRIVER_BINDING_PROTOCOL *This,
170 IN EFI_HANDLE Controller,
171 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
172 );
173
174
175 /**
176 Install Graphics Output Protocol onto VGA device handles.
177
178 @param This Pointer to driver binding protocol
179 @param Controller Controller handle to connect
180 @param RemainingDevicePath A pointer to the remaining portion of a device
181 path
182
183 @return EFI_STATUS
184
185 **/
186 EFI_STATUS
187 EFIAPI
188 BiosVideoDriverBindingStart (
189 IN EFI_DRIVER_BINDING_PROTOCOL *This,
190 IN EFI_HANDLE Controller,
191 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
192 );
193
194
195 /**
196 Stop.
197
198 @param This Pointer to driver binding protocol
199 @param Controller Controller handle to connect
200 @param NumberOfChildren Number of children handle created by this driver
201 @param ChildHandleBuffer Buffer containing child handle created
202
203 @retval EFI_SUCCESS Driver disconnected successfully from controller
204 @retval EFI_UNSUPPORTED Cannot find BIOS_VIDEO_DEV structure
205
206 **/
207 EFI_STATUS
208 EFIAPI
209 BiosVideoDriverBindingStop (
210 IN EFI_DRIVER_BINDING_PROTOCOL *This,
211 IN EFI_HANDLE Controller,
212 IN UINTN NumberOfChildren,
213 IN EFI_HANDLE *ChildHandleBuffer
214 );
215
216 //
217 // Private worker functions
218 //
219
220 /**
221 Check for VBE device.
222
223 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
224
225 @retval EFI_SUCCESS VBE device found
226
227 **/
228 EFI_STATUS
229 BiosVideoCheckForVbe (
230 IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate
231 );
232
233
234 /**
235 Check for VGA device.
236
237 @param BiosVideoPrivate Pointer to BIOS_VIDEO_DEV structure
238
239 @retval EFI_SUCCESS Standard VGA device found
240
241 **/
242 EFI_STATUS
243 BiosVideoCheckForVga (
244 IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate
245 );
246
247
248
249
250 /**
251 Release resource for biso video instance.
252
253 @param BiosVideoPrivate Video child device private data structure
254
255 **/
256 VOID
257 BiosVideoDeviceReleaseResource (
258 BIOS_VIDEO_DEV *BiosVideoPrivate
259 );
260
261 //
262 // BIOS Graphics Output Protocol functions
263 //
264
265 /**
266 Graphics Output protocol interface to get video mode.
267
268 @param This Protocol instance pointer.
269 @param ModeNumber The mode number to return information on.
270 @param SizeOfInfo A pointer to the size, in bytes, of the Info
271 buffer.
272 @param Info Caller allocated buffer that returns information
273 about ModeNumber.
274
275 @retval EFI_SUCCESS Mode information returned.
276 @retval EFI_BUFFER_TOO_SMALL The Info buffer was too small.
277 @retval EFI_DEVICE_ERROR A hardware error occurred trying to retrieve the
278 video mode.
279 @retval EFI_NOT_STARTED Video display is not initialized. Call SetMode ()
280 @retval EFI_INVALID_PARAMETER One of the input args was NULL.
281
282 **/
283 EFI_STATUS
284 EFIAPI
285 BiosVideoGraphicsOutputQueryMode (
286 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
287 IN UINT32 ModeNumber,
288 OUT UINTN *SizeOfInfo,
289 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
290 );
291
292
293 /**
294 Graphics Output protocol interface to set video mode.
295
296 @param This Protocol instance pointer.
297 @param ModeNumber The mode number to be set.
298
299 @retval EFI_SUCCESS Graphics mode was changed.
300 @retval EFI_DEVICE_ERROR The device had an error and could not complete the
301 request.
302 @retval EFI_UNSUPPORTED ModeNumber is not supported by this device.
303
304 **/
305 EFI_STATUS
306 EFIAPI
307 BiosVideoGraphicsOutputSetMode (
308 IN EFI_GRAPHICS_OUTPUT_PROTOCOL * This,
309 IN UINT32 ModeNumber
310 );
311
312
313 /**
314 Graphics Output protocol instance to block transfer for VBE device.
315
316 @param This Pointer to Graphics Output protocol instance
317 @param BltBuffer The data to transfer to screen
318 @param BltOperation The operation to perform
319 @param SourceX The X coordinate of the source for BltOperation
320 @param SourceY The Y coordinate of the source for BltOperation
321 @param DestinationX The X coordinate of the destination for
322 BltOperation
323 @param DestinationY The Y coordinate of the destination for
324 BltOperation
325 @param Width The width of a rectangle in the blt rectangle in
326 pixels
327 @param Height The height of a rectangle in the blt rectangle in
328 pixels
329 @param Delta Not used for EfiBltVideoFill and
330 EfiBltVideoToVideo operation. If a Delta of 0 is
331 used, the entire BltBuffer will be operated on. If
332 a subrectangle of the BltBuffer is used, then
333 Delta represents the number of bytes in a row of
334 the BltBuffer.
335
336 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
337 @retval EFI_SUCCESS Blt operation success
338
339 **/
340 EFI_STATUS
341 EFIAPI
342 BiosVideoGraphicsOutputVbeBlt (
343 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
344 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
345 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
346 IN UINTN SourceX,
347 IN UINTN SourceY,
348 IN UINTN DestinationX,
349 IN UINTN DestinationY,
350 IN UINTN Width,
351 IN UINTN Height,
352 IN UINTN Delta
353 );
354
355
356 /**
357 Grahpics Output protocol instance to block transfer for VGA device.
358
359 @param This Pointer to Grahpics Output protocol instance
360 @param BltBuffer The data to transfer to screen
361 @param BltOperation The operation to perform
362 @param SourceX The X coordinate of the source for BltOperation
363 @param SourceY The Y coordinate of the source for BltOperation
364 @param DestinationX The X coordinate of the destination for
365 BltOperation
366 @param DestinationY The Y coordinate of the destination for
367 BltOperation
368 @param Width The width of a rectangle in the blt rectangle in
369 pixels
370 @param Height The height of a rectangle in the blt rectangle in
371 pixels
372 @param Delta Not used for EfiBltVideoFill and
373 EfiBltVideoToVideo operation. If a Delta of 0 is
374 used, the entire BltBuffer will be operated on. If
375 a subrectangle of the BltBuffer is used, then
376 Delta represents the number of bytes in a row of
377 the BltBuffer.
378
379 @retval EFI_INVALID_PARAMETER Invalid parameter passed in
380 @retval EFI_SUCCESS Blt operation success
381
382 **/
383 EFI_STATUS
384 EFIAPI
385 BiosVideoGraphicsOutputVgaBlt (
386 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
387 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
388 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
389 IN UINTN SourceX,
390 IN UINTN SourceY,
391 IN UINTN DestinationX,
392 IN UINTN DestinationY,
393 IN UINTN Width,
394 IN UINTN Height,
395 IN UINTN Delta
396 );
397
398 //
399 // BIOS VGA Mini Port Protocol functions
400 //
401
402 /**
403 VgaMiniPort protocol interface to set mode.
404
405 @param This Pointer to VgaMiniPort protocol instance
406 @param ModeNumber The index of the mode
407
408 @retval EFI_UNSUPPORTED The requested mode is not supported
409 @retval EFI_SUCCESS The requested mode is set successfully
410
411 **/
412 EFI_STATUS
413 EFIAPI
414 BiosVideoVgaMiniPortSetMode (
415 IN EFI_VGA_MINI_PORT_PROTOCOL *This,
416 IN UINTN ModeNumber
417 );
418
419 /**
420 Event handler for Exit Boot Service.
421
422 @param Event The event that be siganlled when exiting boot service.
423 @param Context Pointer to instance of BIOS_VIDEO_DEV.
424
425 **/
426 VOID
427 EFIAPI
428 BiosVideoNotifyExitBootServices (
429 IN EFI_EVENT Event,
430 IN VOID *Context
431 );
432
433 //
434 // Standard VGA Definitions
435 //
436 #define VGA_HORIZONTAL_RESOLUTION 640
437 #define VGA_VERTICAL_RESOLUTION 480
438 #define VGA_NUMBER_OF_BIT_PLANES 4
439 #define VGA_PIXELS_PER_BYTE 8
440 #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
441 #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
442
443 #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
444 #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
445
446 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
447
448 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
449
450 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
451
452 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
453 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
454 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
455 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
456 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
457
458 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
459
460 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
461 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
462 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
463 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
464 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
465 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
466 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
467
468 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
469
470 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
471
472 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
473
474 /**
475 Install child handles if the Handle supports MBR format.
476
477 @param This Calling context.
478 @param ParentHandle Parent Handle
479 @param ParentPciIo Parent PciIo interface
480 @param ParentLegacyBios Parent LegacyBios interface
481 @param ParentDevicePath Parent Device Path
482 @param RemainingDevicePath Remaining Device Path
483
484 @retval EFI_SUCCESS If a child handle was added
485 @retval other A child handle was not added
486
487 **/
488 EFI_STATUS
489 BiosVideoChildHandleInstall (
490 IN EFI_DRIVER_BINDING_PROTOCOL *This,
491 IN EFI_HANDLE ParentHandle,
492 IN EFI_PCI_IO_PROTOCOL *ParentPciIo,
493 IN EFI_LEGACY_BIOS_PROTOCOL *ParentLegacyBios,
494 IN EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath,
495 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
496 );
497
498 /**
499 Deregister an video child handle and free resources.
500
501 @param This Protocol instance pointer.
502 @param Controller Video controller handle
503 @param Handle Video child handle
504
505 @return EFI_STATUS
506
507 **/
508 EFI_STATUS
509 BiosVideoChildHandleUninstall (
510 EFI_DRIVER_BINDING_PROTOCOL *This,
511 EFI_HANDLE Controller,
512 EFI_HANDLE Handle
513 );
514
515 /**
516 Release resource for biso video instance.
517
518 @param BiosVideoPrivate Video child device private data structure
519
520 **/
521 VOID
522 BiosVideoDeviceReleaseResource (
523 BIOS_VIDEO_DEV *BiosVideoPrivate
524 );
525
526 /**
527 Check if all video child handles have been uninstalled.
528
529 @param Controller Video controller handle
530
531 @return TRUE Child handles exist.
532 @return FALSE All video child handles have been uninstalled.
533
534 **/
535 BOOLEAN
536 HasChildHandle (
537 IN EFI_HANDLE Controller
538 );
539 #endif