]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - DuetPkg/BiosVideoThunkDxe/BiosVideo.h
ShellPkg/[hex]edit: Fix mouse freeze issue
[mirror_edk2.git] / DuetPkg / BiosVideoThunkDxe / BiosVideo.h
... / ...
CommitLineData
1/** @file\r
2\r
3Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
4This 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
222EFIAPI\r
223BiosVideoCheckForVbe (\r
224 IN OUT BIOS_VIDEO_DEV *BiosVideoPrivate\r
225 )\r
226;\r
227\r
228/**\r
229 Check for VGA device\r
230\r
231 @param BiosVideoPrivate - Pointer to BIOS_VIDEO_DEV structure\r
232\r
233 @retval EFI_SUCCESS Standard VGA device found\r
234**/\r
235\r
236EFI_STATUS\r
237EFIAPI\r
238BiosVideoCheckForVga (\r
239 BIOS_VIDEO_DEV *BiosVideoPrivate\r
240 )\r
241;\r
242\r
243/**\r
244 Collect the resource from destroyed bios video device.\r
245\r
246 @param BiosVideoPrivate Video child device private data structure\r
247\r
248**/\r
249VOID\r
250BiosVideoDeviceReleaseResource (\r
251 BIOS_VIDEO_DEV *BiosVideoChildPrivate\r
252 )\r
253;\r
254\r
255//\r
256// BIOS Graphics Output Protocol functions\r
257//\r
258/**\r
259\r
260 Graphics Output protocol interface to get video mode\r
261\r
262\r
263 @param This - Protocol instance pointer.\r
264 @param ModeNumber - The mode number to return information on.\r
265 @param SizeOfInfo - A pointer to the size, in bytes, of the Info buffer.\r
266 @param Info - Caller allocated buffer that returns information about ModeNumber.\r
267\r
268 @return EFI_SUCCESS - Mode information returned.\r
269 EFI_DEVICE_ERROR - A hardware error occurred trying to retrieve the video mode.\r
270 EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()\r
271 EFI_INVALID_PARAMETER - One of the input args was NULL.\r
272\r
273**/\r
274EFI_STATUS\r
275EFIAPI\r
276BiosVideoGraphicsOutputQueryMode (\r
277 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,\r
278 IN UINT32 ModeNumber,\r
279 OUT UINTN *SizeOfInfo,\r
280 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info\r
281 )\r
282;\r
283\r
284/**\r
285\r
286 Graphics Output protocol interface to set video mode\r
287\r
288\r
289 @param This - Protocol instance pointer.\r
290 @param ModeNumber - The mode number to be set.\r
291\r
292 @return EFI_SUCCESS - Graphics mode was changed.\r
293 EFI_DEVICE_ERROR - The device had an error and could not complete the request.\r
294 EFI_UNSUPPORTED - ModeNumber is not supported by this device.\r
295\r
296**/\r
297EFI_STATUS\r
298EFIAPI\r
299BiosVideoGraphicsOutputSetMode (\r
300 IN EFI_GRAPHICS_OUTPUT_PROTOCOL * This,\r
301 IN UINT32 ModeNumber\r
302 )\r
303;\r
304\r
305/**\r
306\r
307 Graphics Output protocol instance to block transfer for VBE device\r
308\r
309\r
310 @param This - Pointer to Graphics Output protocol instance\r
311 @param BltBuffer - The data to transfer to screen\r
312 @param BltOperation - The operation to perform\r
313 @param SourceX - The X coordinate of the source for BltOperation\r
314 @param SourceY - The Y coordinate of the source for BltOperation\r
315 @param DestinationX - The X coordinate of the destination for BltOperation\r
316 @param DestinationY - The Y coordinate of the destination for BltOperation\r
317 @param Width - The width of a rectangle in the blt rectangle in pixels\r
318 @param Height - The height of a rectangle in the blt rectangle in pixels\r
319 @param Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.\r
320 If a Delta of 0 is used, the entire BltBuffer will be operated on.\r
321 If a subrectangle of the BltBuffer is used, then Delta represents\r
322 the number of bytes in a row of the BltBuffer.\r
323\r
324 @return EFI_INVALID_PARAMETER - Invalid parameter passed in\r
325 EFI_SUCCESS - Blt operation success\r
326\r
327**/\r
328EFI_STATUS\r
329EFIAPI\r
330BiosVideoGraphicsOutputVbeBlt (\r
331 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,\r
332 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL\r
333 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,\r
334 IN UINTN SourceX,\r
335 IN UINTN SourceY,\r
336 IN UINTN DestinationX,\r
337 IN UINTN DestinationY,\r
338 IN UINTN Width,\r
339 IN UINTN Height,\r
340 IN UINTN Delta\r
341 )\r
342;\r
343\r
344/**\r
345 Grahpics Output protocol instance to block transfer for VGA device\r
346\r
347 @param This Pointer to Grahpics Output protocol instance\r
348 @param BltBuffer The data to transfer to screen\r
349 @param BltOperation The operation to perform\r
350 @param SourceX The X coordinate of the source for BltOperation\r
351 @param SourceY The Y coordinate of the source for BltOperation\r
352 @param DestinationX The X coordinate of the destination for BltOperation\r
353 @param DestinationY The Y coordinate of the destination for BltOperation\r
354 @param Width The width of a rectangle in the blt rectangle in pixels\r
355 @param Height The height of a rectangle in the blt rectangle in pixels\r
356 @param Delta Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.\r
357 If a Delta of 0 is used, the entire BltBuffer will be operated on.\r
358 If a subrectangle of the BltBuffer is used, then Delta represents\r
359 the number of bytes in a row of the BltBuffer.\r
360\r
361 @retval EFI_INVALID_PARAMETER Invalid parameter passed in\r
362 @retval EFI_SUCCESS Blt operation success\r
363\r
364**/\r
365EFI_STATUS\r
366EFIAPI\r
367BiosVideoGraphicsOutputVgaBlt (\r
368 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,\r
369 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL\r
370 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,\r
371 IN UINTN SourceX,\r
372 IN UINTN SourceY,\r
373 IN UINTN DestinationX,\r
374 IN UINTN DestinationY,\r
375 IN UINTN Width,\r
376 IN UINTN Height,\r
377 IN UINTN Delta\r
378 )\r
379;\r
380\r
381//\r
382// BIOS VGA Mini Port Protocol functions\r
383//\r
384/**\r
385 VgaMiniPort protocol interface to set mode\r
386\r
387 @param This Pointer to VgaMiniPort protocol instance\r
388 @param ModeNumber The index of the mode\r
389\r
390 @retval EFI_UNSUPPORTED The requested mode is not supported\r
391 @retval EFI_SUCCESS The requested mode is set successfully\r
392\r
393**/\r
394EFI_STATUS\r
395EFIAPI\r
396BiosVideoVgaMiniPortSetMode (\r
397 IN EFI_VGA_MINI_PORT_PROTOCOL *This,\r
398 IN UINTN ModeNumber\r
399 )\r
400;\r
401\r
402/**\r
403 Judge whether this device is VGA device.\r
404\r
405 @param PciIo Parent PciIo protocol instance pointer\r
406\r
407 @retval TRUE Is vga device\r
408 @retval FALSE Is no vga device\r
409**/\r
410BOOLEAN\r
411BiosVideoIsVga (\r
412 IN EFI_PCI_IO_PROTOCOL *PciIo\r
413 )\r
414;\r
415\r
416\r
417//\r
418// Standard VGA Definitions\r
419//\r
420#define VGA_HORIZONTAL_RESOLUTION 640\r
421#define VGA_VERTICAL_RESOLUTION 480\r
422#define VGA_NUMBER_OF_BIT_PLANES 4\r
423#define VGA_PIXELS_PER_BYTE 8\r
424#define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)\r
425#define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)\r
426\r
427#define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce\r
428#define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf\r
429\r
430#define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00\r
431\r
432#define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01\r
433\r
434#define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02\r
435\r
436#define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03\r
437#define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00\r
438#define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08\r
439#define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10\r
440#define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18\r
441\r
442#define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04\r
443\r
444#define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05\r
445#define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00\r
446#define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08\r
447#define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00\r
448#define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01\r
449#define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02\r
450#define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03\r
451\r
452#define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06\r
453\r
454#define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07\r
455\r
456#define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08\r
457\r
458/**\r
459 Initialize legacy environment for BIOS INI caller.\r
460 \r
461 @param ThunkContext the instance pointer of THUNK_CONTEXT\r
462**/\r
463VOID\r
464InitializeBiosIntCaller (\r
465 THUNK_CONTEXT *ThunkContext\r
466 );\r
467 \r
468/**\r
469 Initialize interrupt redirection code and entries, because\r
470 IDT Vectors 0x68-0x6f must be redirected to IDT Vectors 0x08-0x0f.\r
471 Or the interrupt will lost when we do thunk.\r
472 NOTE: We do not reset 8259 vector base, because it will cause pending\r
473 interrupt lost.\r
474 \r
475 @param Legacy8259 Instance pointer for EFI_LEGACY_8259_PROTOCOL.\r
476 \r
477**/ \r
478VOID\r
479InitializeInterruptRedirection (\r
480 IN EFI_LEGACY_8259_PROTOCOL *Legacy8259\r
481 );\r
482 \r
483/**\r
484 Thunk to 16-bit real mode and execute a software interrupt with a vector \r
485 of BiosInt. Regs will contain the 16-bit register context on entry and \r
486 exit.\r
487 \r
488 @param This Protocol instance pointer.\r
489 @param BiosInt Processor interrupt vector to invoke\r
490 @param Reg Register contexted passed into (and returned) from thunk to 16-bit mode\r
491 \r
492 @retval TRUE Thunk completed, and there were no BIOS errors in the target code.\r
493 See Regs for status.\r
494 @retval FALSE There was a BIOS erro in the target code. \r
495**/ \r
496BOOLEAN\r
497EFIAPI\r
498LegacyBiosInt86 (\r
499 IN BIOS_VIDEO_DEV *BiosDev,\r
500 IN UINT8 BiosInt,\r
501 IN IA32_REGISTER_SET *Regs\r
502 ); \r
503 \r
504#endif\r