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