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