]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/BiosVideoThunkDxe/BiosVideo.h
Update BiosVideo driver to produce GOP protocol but not UgaDraw protocol which is...
[mirror_edk2.git] / DuetPkg / BiosVideoThunkDxe / BiosVideo.h
1 /*++
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 Module Name:
13
14 UefiBiosVideo.h
15
16 Abstract:
17
18 Revision History
19 --*/
20
21 #ifndef _BIOS_GRAPHICS_OUTPUT_H
22 #define _BIOS_GRAPHICS_OUTPUT_H
23
24 #include <Uefi.h>
25
26 //
27 // Driver Consumed Protocol Prototypes
28 //
29 #include <Protocol/DevicePath.h>
30 #include <Protocol/PciIo.h>
31 #include <Protocol/DriverBinding.h>
32 #include <Protocol/ComponentName.h>
33 #include <Protocol/ComponentName2.h>
34 #include <Protocol/UgaDraw.h>
35 #include <Protocol/VgaMiniPort.h>
36 #include <Protocol/Legacy8259.h>
37 #include <Protocol/EdidActive.h>
38 #include <Protocol/EdidDiscovered.h>
39 #include <Protocol/DevicePath.h>
40 #include <Protocol/LegacyBios.h>
41
42 #include <Library/UefiLib.h>
43 #include <Library/DebugLib.h>
44 #include <Library/UefiBootServicesTableLib.h>
45 #include <Library/BaseMemoryLib.h>
46 #include <Library/DevicePathLib.h>
47
48 #include <IndustryStandard/Pci22.h>
49
50 #include "VesaBiosExtensions.h"
51
52 //
53 // Packed format support: The number of bits reserved for each of the colors and the actual
54 // position of RGB in the frame buffer is specified in the VBE Mode information
55 //
56 typedef struct {
57 UINT8 Position; // Position of the color
58 UINT8 Mask; // The number of bits expressed as a mask
59 } BIOS_VIDEO_COLOR_PLACEMENT;
60
61 //
62 // BIOS Graphics Output Graphical Mode Data
63 //
64 typedef struct {
65 UINT16 VbeModeNumber;
66 UINT16 BytesPerScanLine;
67 VOID *LinearFrameBuffer;
68 UINTN FrameBufferSize;
69 UINT32 HorizontalResolution;
70 UINT32 VerticalResolution;
71 UINT32 RefreshRate;
72 UINT32 BitsPerPixel;
73 BIOS_VIDEO_COLOR_PLACEMENT Red;
74 BIOS_VIDEO_COLOR_PLACEMENT Green;
75 BIOS_VIDEO_COLOR_PLACEMENT Blue;
76 BIOS_VIDEO_COLOR_PLACEMENT Reserved;
77 EFI_GRAPHICS_PIXEL_FORMAT PixelFormat;
78 EFI_PIXEL_BITMASK PixelBitMask;
79 } BIOS_VIDEO_MODE_DATA;
80
81 //
82 // BIOS video child handle private data Structure
83 //
84 #define BIOS_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
85
86 typedef struct {
87 UINTN Signature;
88 EFI_HANDLE Handle;
89
90 //
91 // Consumed Protocols
92 //
93 EFI_PCI_IO_PROTOCOL *PciIo;
94 EFI_LEGACY_8259_PROTOCOL *Legacy8259;
95
96 //
97 // Produced Protocols
98 //
99 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
100 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered;
101 EFI_EDID_ACTIVE_PROTOCOL EdidActive;
102 EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort;
103
104 //
105 // General fields
106 //
107 BOOLEAN VgaCompatible;
108 BOOLEAN ProduceGraphicsOutput;
109 EFI_EVENT ExitBootServicesEvent;
110
111 //
112 // Graphics Output Protocol related fields
113 //
114 BOOLEAN HardwareNeedsStarting;
115 BIOS_VIDEO_MODE_DATA *ModeData;
116 UINT8 *LineBuffer;
117 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *VbeFrameBuffer;
118 UINT8 *VgaFrameBuffer;
119
120 //
121 // VESA Bios Extensions related fields
122 //
123 UINTN NumberOfPagesBelow1MB; // Number of 4KB pages in PagesBelow1MB
124 EFI_PHYSICAL_ADDRESS PagesBelow1MB; // Buffer for all VBE Information Blocks
125 VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK *VbeInformationBlock; // 0x200 bytes. Must be allocated below 1MB
126 VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK *VbeModeInformationBlock; // 0x100 bytes. Must be allocated below 1MB
127 VESA_BIOS_EXTENSIONS_EDID_DATA_BLOCK *VbeEdidDataBlock; // 0x80 bytes. Must be allocated below 1MB
128 VESA_BIOS_EXTENSIONS_CRTC_INFORMATION_BLOCK *VbeCrtcInformationBlock; // 59 bytes. Must be allocated below 1MB
129 UINTN VbeSaveRestorePages; // Number of 4KB pages in VbeSaveRestoreBuffer
130 EFI_PHYSICAL_ADDRESS VbeSaveRestoreBuffer; // Must be allocated below 1MB
131 //
132 // Status code
133 //
134 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
135 } BIOS_VIDEO_DEV;
136
137 #define BIOS_VIDEO_DEV_FROM_PCI_IO_THIS(a) CR (a, BIOS_VIDEO_DEV, PciIo, BIOS_VIDEO_DEV_SIGNATURE)
138 #define BIOS_VIDEO_DEV_FROM_GRAPHICS_OUTPUT_THIS(a) CR (a, BIOS_VIDEO_DEV, GraphicsOutput, BIOS_VIDEO_DEV_SIGNATURE)
139 #define BIOS_VIDEO_DEV_FROM_VGA_MINI_PORT_THIS(a) CR (a, BIOS_VIDEO_DEV, VgaMiniPort, BIOS_VIDEO_DEV_SIGNATURE)
140
141 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
142
143 //
144 // Global Variables
145 //
146 extern EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding;
147 extern EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName;
148 extern EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2;
149
150 //
151 // Driver Binding Protocol functions
152 //
153 EFI_STATUS
154 EFIAPI
155 BiosVideoDriverBindingSupported (
156 IN EFI_DRIVER_BINDING_PROTOCOL *This,
157 IN EFI_HANDLE Controller,
158 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
159 )
160 /*++
161
162 Routine Description:
163
164 GC_TODO: Add function description
165
166 Arguments:
167
168 This - GC_TODO: add argument description
169 Controller - GC_TODO: add argument description
170 RemainingDevicePath - GC_TODO: add argument description
171
172 Returns:
173
174 GC_TODO: add return values
175
176 --*/
177 ;
178
179 EFI_STATUS
180 EFIAPI
181 BiosVideoDriverBindingStart (
182 IN EFI_DRIVER_BINDING_PROTOCOL *This,
183 IN EFI_HANDLE Controller,
184 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
185 )
186 /*++
187
188 Routine Description:
189
190 GC_TODO: Add function description
191
192 Arguments:
193
194 This - GC_TODO: add argument description
195 Controller - GC_TODO: add argument description
196 RemainingDevicePath - GC_TODO: add argument description
197
198 Returns:
199
200 GC_TODO: add return values
201
202 --*/
203 ;
204
205 EFI_STATUS
206 EFIAPI
207 BiosVideoDriverBindingStop (
208 IN EFI_DRIVER_BINDING_PROTOCOL *This,
209 IN EFI_HANDLE Controller,
210 IN UINTN NumberOfChildren,
211 IN EFI_HANDLE *ChildHandleBuffer
212 )
213 /*++
214
215 Routine Description:
216
217 GC_TODO: Add function description
218
219 Arguments:
220
221 This - GC_TODO: add argument description
222 Controller - GC_TODO: add argument description
223 NumberOfChildren - GC_TODO: add argument description
224 ChildHandleBuffer - GC_TODO: add argument description
225
226 Returns:
227
228 GC_TODO: add return values
229
230 --*/
231 ;
232
233 //
234 // Private worker functions
235 //
236 EFI_STATUS
237 BiosVideoCheckForVbe (
238 BIOS_VIDEO_DEV *BiosVideoPrivate
239 )
240 /*++
241
242 Routine Description:
243
244 GC_TODO: Add function description
245
246 Arguments:
247
248 BiosVideoPrivate - GC_TODO: add argument description
249
250 Returns:
251
252 GC_TODO: add return values
253
254 --*/
255 ;
256
257 EFI_STATUS
258 BiosVideoCheckForVga (
259 BIOS_VIDEO_DEV *BiosVideoPrivate
260 )
261 /*++
262
263 Routine Description:
264
265 GC_TODO: Add function description
266
267 Arguments:
268
269 BiosVideoPrivate - GC_TODO: add argument description
270
271 Returns:
272
273 GC_TODO: add return values
274
275 --*/
276 ;
277
278 STATIC
279 EFI_STATUS
280 DeRegisterVideoChildHandle (
281 EFI_DRIVER_BINDING_PROTOCOL *This,
282 EFI_HANDLE Controller,
283 EFI_HANDLE Handle
284 )
285 /*++
286
287 Routine Description:
288
289 Deregister an video child handle and free resources
290
291 Arguments:
292
293 This - Protocol instance pointer.
294 Controller - Video controller handle
295 Handle - Video child handle
296
297 Returns:
298
299 EFI_STATUS
300
301 --*/
302 ;
303
304 VOID
305 BiosVideoDeviceReleaseResource (
306 BIOS_VIDEO_DEV *BiosVideoChildPrivate
307 )
308 /*++
309 Routing Description:
310
311 Release resources of a video child device before stopping it.
312
313 Arguments:
314
315 BiosVideoChildPrivate - Video child device private data structure
316
317 Returns:
318
319 NONE
320
321 ---*/
322 ;
323
324 //
325 // BIOS Graphics Output Protocol functions
326 //
327 EFI_STATUS
328 EFIAPI
329 BiosVideoGraphicsOutputQueryMode (
330 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
331 IN UINT32 ModeNumber,
332 OUT UINTN *SizeOfInfo,
333 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION **Info
334 )
335 /*++
336
337 Routine Description:
338
339 Graphics Output protocol interface to get video mode
340
341 Arguments:
342 This - Protocol instance pointer.
343 ModeNumber - The mode number to return information on.
344 Info - Caller allocated buffer that returns information about ModeNumber.
345 SizeOfInfo - A pointer to the size, in bytes, of the Info buffer.
346
347 Returns:
348 EFI_SUCCESS - Mode information returned.
349 EFI_BUFFER_TOO_SMALL - The Info buffer was too small.
350 EFI_DEVICE_ERROR - A hardware error occurred trying to retrieve the video mode.
351 EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
352 EFI_INVALID_PARAMETER - One of the input args was NULL.
353
354 --*/
355 ;
356
357 EFI_STATUS
358 EFIAPI
359 BiosVideoGraphicsOutputSetMode (
360 IN EFI_GRAPHICS_OUTPUT_PROTOCOL * This,
361 IN UINT32 ModeNumber
362 )
363 /*++
364
365 Routine Description:
366
367 Graphics Output protocol interface to set video mode
368
369 Arguments:
370 This - Protocol instance pointer.
371 ModeNumber - The mode number to be set.
372
373 Returns:
374 EFI_SUCCESS - Graphics mode was changed.
375 EFI_DEVICE_ERROR - The device had an error and could not complete the request.
376 EFI_UNSUPPORTED - ModeNumber is not supported by this device.
377
378 --*/
379 ;
380
381 EFI_STATUS
382 EFIAPI
383 BiosVideoGraphicsOutputVbeBlt (
384 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
385 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
386 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
387 IN UINTN SourceX,
388 IN UINTN SourceY,
389 IN UINTN DestinationX,
390 IN UINTN DestinationY,
391 IN UINTN Width,
392 IN UINTN Height,
393 IN UINTN Delta
394 )
395 /*++
396
397 Routine Description:
398
399 Graphics Output protocol instance to block transfer for VBE device
400
401 Arguments:
402
403 This - Pointer to Graphics Output protocol instance
404 BltBuffer - The data to transfer to screen
405 BltOperation - The operation to perform
406 SourceX - The X coordinate of the source for BltOperation
407 SourceY - The Y coordinate of the source for BltOperation
408 DestinationX - The X coordinate of the destination for BltOperation
409 DestinationY - The Y coordinate of the destination for BltOperation
410 Width - The width of a rectangle in the blt rectangle in pixels
411 Height - The height of a rectangle in the blt rectangle in pixels
412 Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
413 If a Delta of 0 is used, the entire BltBuffer will be operated on.
414 If a subrectangle of the BltBuffer is used, then Delta represents
415 the number of bytes in a row of the BltBuffer.
416
417 Returns:
418
419 EFI_INVALID_PARAMETER - Invalid parameter passed in
420 EFI_SUCCESS - Blt operation success
421
422 --*/
423 ;
424
425 EFI_STATUS
426 EFIAPI
427 BiosVideoGraphicsOutputVgaBlt (
428 IN EFI_GRAPHICS_OUTPUT_PROTOCOL *This,
429 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer, OPTIONAL
430 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation,
431 IN UINTN SourceX,
432 IN UINTN SourceY,
433 IN UINTN DestinationX,
434 IN UINTN DestinationY,
435 IN UINTN Width,
436 IN UINTN Height,
437 IN UINTN Delta
438 )
439 /*++
440
441 Routine Description:
442
443 Grahpics Output protocol instance to block transfer for VGA device
444
445 Arguments:
446
447 This - Pointer to Grahpics Output protocol instance
448 BltBuffer - The data to transfer to screen
449 BltOperation - The operation to perform
450 SourceX - The X coordinate of the source for BltOperation
451 SourceY - The Y coordinate of the source for BltOperation
452 DestinationX - The X coordinate of the destination for BltOperation
453 DestinationY - The Y coordinate of the destination for BltOperation
454 Width - The width of a rectangle in the blt rectangle in pixels
455 Height - The height of a rectangle in the blt rectangle in pixels
456 Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
457 If a Delta of 0 is used, the entire BltBuffer will be operated on.
458 If a subrectangle of the BltBuffer is used, then Delta represents
459 the number of bytes in a row of the BltBuffer.
460
461 Returns:
462
463 EFI_INVALID_PARAMETER - Invalid parameter passed in
464 EFI_SUCCESS - Blt operation success
465
466 --*/
467 ;
468
469 //
470 // BIOS VGA Mini Port Protocol functions
471 //
472 EFI_STATUS
473 EFIAPI
474 BiosVideoVgaMiniPortSetMode (
475 IN EFI_VGA_MINI_PORT_PROTOCOL *This,
476 IN UINTN ModeNumber
477 )
478 /*++
479
480 Routine Description:
481
482 VgaMiniPort protocol interface to set mode
483
484 Arguments:
485
486 This - Pointer to VgaMiniPort protocol instance
487 ModeNumber - The index of the mode
488
489 Returns:
490
491 EFI_UNSUPPORTED - The requested mode is not supported
492 EFI_SUCCESS - The requested mode is set successfully
493
494 --*/
495 ;
496
497
498 BOOLEAN
499 BiosVideoIsVga (
500 IN EFI_PCI_IO_PROTOCOL *PciIo
501 )
502 ;
503
504
505 //
506 // Standard VGA Definitions
507 //
508 #define VGA_HORIZONTAL_RESOLUTION 640
509 #define VGA_VERTICAL_RESOLUTION 480
510 #define VGA_NUMBER_OF_BIT_PLANES 4
511 #define VGA_PIXELS_PER_BYTE 8
512 #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
513 #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
514
515 #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
516 #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
517
518 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
519
520 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
521
522 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
523
524 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
525 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
526 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
527 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
528 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
529
530 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
531
532 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
533 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
534 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
535 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
536 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
537 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
538 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
539
540 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
541
542 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
543
544 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
545
546 VOID
547 InitializeBiosIntCaller (
548 IN BIOS_VIDEO_DEV *BiosDev
549 );
550
551 VOID
552 InitializeInterruptRedirection (
553 IN BIOS_VIDEO_DEV *BiosDev
554 );
555
556 BOOLEAN
557 EFIAPI
558 LegacyBiosInt86 (
559 IN BIOS_VIDEO_DEV *BiosDev,
560 IN UINT8 BiosInt,
561 IN EFI_IA32_REGISTER_SET *Regs
562 );
563
564 #endif