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