]> git.proxmox.com Git - mirror_edk2.git/blob - DuetPkg/BiosVideoThunkDxe/BiosVideo.h
Fix building issue for linux toolchain
[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 BiosVideo.h
15
16 Abstract:
17
18 Revision History
19 --*/
20
21 #ifndef _BIOS_UGA_H
22 #define _BIOS_UGA_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/LegacyBios.h>
38
39 #include <Library/UefiLib.h>
40 #include <Library/DebugLib.h>
41 #include <Library/UefiBootServicesTableLib.h>
42 #include <Library/BaseMemoryLib.h>
43
44 #include <IndustryStandard/Pci22.h>
45
46 #include "VesaBiosExtensions.h"
47 //
48 // Driver Produced Protocol Prototypes
49 //
50 //#include EFI_PROTOCOL_DEFINITION (DriverBinding)
51 //#include EFI_PROTOCOL_DEFINITION (ComponentName)
52 //#include EFI_PROTOCOL_DEFINITION (ComponentName2)
53 //#include EFI_PROTOCOL_DEFINITION (UgaDraw)
54 //#include EFI_PROTOCOL_DEFINITION (VgaMiniPort)
55
56 //
57 // Packed format support: The number of bits reserved for each of the colors and the actual
58 // position of RGB in the frame buffer is specified in the VBE Mode information
59 //
60 typedef struct {
61 UINT8 Position; // Position of the color
62 UINT8 Mask; // The number of bits expressed as a mask
63 } BIOS_VIDEO_COLOR_PLACEMENT;
64
65 //
66 // BIOS UGA Draw Graphical Mode Data
67 //
68 typedef struct {
69 UINT16 VbeModeNumber;
70 UINT16 BytesPerScanLine;
71 VOID *LinearFrameBuffer;
72 UINT32 HorizontalResolution;
73 UINT32 VerticalResolution;
74 UINT32 ColorDepth;
75 UINT32 RefreshRate;
76 UINT32 BitsPerPixel;
77 BIOS_VIDEO_COLOR_PLACEMENT Red;
78 BIOS_VIDEO_COLOR_PLACEMENT Green;
79 BIOS_VIDEO_COLOR_PLACEMENT Blue;
80 } BIOS_VIDEO_MODE_DATA;
81
82 //
83 // BIOS UGA Device Structure
84 //
85 #define BIOS_VIDEO_DEV_SIGNATURE SIGNATURE_32 ('B', 'V', 'M', 'p')
86
87 typedef struct {
88 UINTN Signature;
89 EFI_HANDLE Handle;
90
91 //
92 // Consumed Protocols
93 //
94 EFI_PCI_IO_PROTOCOL *PciIo;
95 //EFI_LEGACY_BIOS_THUNK_PROTOCOL *LegacyBios;
96
97 //
98 // Produced Protocols
99 //
100 EFI_UGA_DRAW_PROTOCOL UgaDraw;
101 EFI_VGA_MINI_PORT_PROTOCOL VgaMiniPort;
102
103 //
104 // General fields
105 //
106 EFI_EVENT ExitBootServicesEvent;
107 BOOLEAN VgaCompatible;
108 BOOLEAN ProduceUgaDraw;
109
110 //
111 // UGA Draw related fields
112 //
113 BOOLEAN HardwareNeedsStarting;
114 UINTN CurrentMode;
115 UINTN MaxMode;
116 BIOS_VIDEO_MODE_DATA *ModeData;
117 UINT8 *LineBuffer;
118 EFI_UGA_PIXEL *VbeFrameBuffer;
119 UINT8 *VgaFrameBuffer;
120
121 //
122 // VESA Bios Extensions related fields
123 //
124 UINTN NumberOfPagesBelow1MB; // Number of 4KB pages in PagesBelow1MB
125 EFI_PHYSICAL_ADDRESS PagesBelow1MB; // Buffer for all VBE Information Blocks
126 VESA_BIOS_EXTENSIONS_INFORMATION_BLOCK *VbeInformationBlock; // 0x200 bytes. Must be allocated below 1MB
127 VESA_BIOS_EXTENSIONS_MODE_INFORMATION_BLOCK *VbeModeInformationBlock; // 0x100 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_UGA_DRAW_THIS(a) CR (a, BIOS_VIDEO_DEV, UgaDraw, BIOS_VIDEO_DEV_SIGNATURE)
138
139 #define BIOS_VIDEO_DEV_FROM_VGA_MINI_PORT_THIS(a) CR (a, BIOS_VIDEO_DEV, VgaMiniPort, BIOS_VIDEO_DEV_SIGNATURE)
140
141 //
142 // Global Variables
143 //
144 extern EFI_DRIVER_BINDING_PROTOCOL gBiosVideoDriverBinding;
145 extern EFI_COMPONENT_NAME_PROTOCOL gBiosVideoComponentName;
146 extern EFI_COMPONENT_NAME2_PROTOCOL gBiosVideoComponentName2;
147
148 //
149 // Driver Binding Protocol functions
150 //
151 EFI_STATUS
152 EFIAPI
153 BiosVideoDriverBindingSupported (
154 IN EFI_DRIVER_BINDING_PROTOCOL *This,
155 IN EFI_HANDLE Controller,
156 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
157 )
158 /*++
159
160 Routine Description:
161
162 Supported.
163
164 Arguments:
165
166 This - Pointer to driver binding protocol
167 Controller - Controller handle to connect
168 RemainingDevicePath - A pointer to the remaining portion of a device path
169
170
171 Returns:
172
173 EFI_STATUS - EFI_SUCCESS:This controller can be managed by this driver,
174 Otherwise, this controller cannot be managed by this driver
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 Install UGA Draw Protocol onto VGA device handles
191
192 Arguments:
193
194 This - Pointer to driver binding protocol
195 Controller - Controller handle to connect
196 RemainingDevicePath - A pointer to the remaining portion of a device path
197
198 Returns:
199
200 EFI_STATUS
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 Stop.
218
219 Arguments:
220
221 This - Pointer to driver binding protocol
222 Controller - Controller handle to connect
223 NumberOfChilren - Number of children handle created by this driver
224 ChildHandleBuffer - Buffer containing child handle created
225
226 Returns:
227
228 EFI_SUCCESS - Driver disconnected successfully from controller
229 EFI_UNSUPPORTED - Cannot find BIOS_VIDEO_DEV structure
230
231 --*/
232 ;
233
234 //
235 // Private worker functions
236 //
237 EFI_STATUS
238 BiosVideoCheckForVbe (
239 BIOS_VIDEO_DEV *BiosVideoPrivate
240 )
241 /*++
242
243 Routine Description:
244
245 Check for VBE device
246
247 Arguments:
248
249 BiosVideoPrivate - Pointer to BIOS_VIDEO_DEV structure
250
251 Returns:
252
253 EFI_SUCCESS - VBE device found
254
255 --*/
256 ;
257
258 EFI_STATUS
259 BiosVideoCheckForVga (
260 BIOS_VIDEO_DEV *BiosVideoPrivate
261 )
262 /*++
263
264 Routine Description:
265
266 Check for VGA device
267
268 Arguments:
269
270 BiosVideoPrivate - Pointer to BIOS_VIDEO_DEV structure
271
272 Returns:
273
274 EFI_SUCCESS - Standard VGA device found
275
276 --*/
277 ;
278
279 //
280 // BIOS UGA Draw Protocol functions
281 //
282 EFI_STATUS
283 EFIAPI
284 BiosVideoUgaDrawGetMode (
285 IN EFI_UGA_DRAW_PROTOCOL *This,
286 OUT UINT32 *HorizontalResolution,
287 OUT UINT32 *VerticalResolution,
288 OUT UINT32 *ColorDepth,
289 OUT UINT32 *RefreshRate
290 )
291 /*++
292
293 Routine Description:
294
295 UGA protocol interface to get video mode
296
297 Arguments:
298
299 This - Pointer to UGA draw protocol instance
300 HorizontalResolution - Horizontal Resolution, in pixels
301 VerticalResolution - Vertical Resolution, in pixels
302 ColorDepth - Bit number used to represent color value of a pixel
303 RefreshRate - Refresh rate, in Hertz
304
305 Returns:
306
307 EFI_DEVICE_ERROR - Hardware need starting
308 EFI_INVALID_PARAMETER - Invalid parameter passed in
309 EFI_SUCCESS - Video mode query successfully
310
311 --*/
312 ;
313
314 EFI_STATUS
315 EFIAPI
316 BiosVideoUgaDrawSetMode (
317 IN EFI_UGA_DRAW_PROTOCOL *This,
318 IN UINT32 HorizontalResolution,
319 IN UINT32 VerticalResolution,
320 IN UINT32 ColorDepth,
321 IN UINT32 RefreshRate
322 )
323 /*++
324
325 Routine Description:
326
327 UGA draw protocol interface to set video mode
328
329 Arguments:
330
331 This - Pointer to UGA draw protocol instance
332 HorizontalResolution - Horizontal Resolution, in pixels
333 VerticalResolution - Vertical Resolution, in pixels
334 ColorDepth - Bit number used to represent color value of a pixel
335 RefreshRate - Refresh rate, in Hertz
336
337 Returns:
338
339 EFI_DEVICE_ERROR - Device error
340 EFI_SUCCESS - Video mode set successfully
341 EFI_UNSUPPORTED - Cannot support this video mode
342
343 --*/
344 ;
345
346 EFI_STATUS
347 EFIAPI
348 BiosVideoUgaDrawVbeBlt (
349 IN EFI_UGA_DRAW_PROTOCOL *This,
350 IN EFI_UGA_PIXEL *BltBuffer, OPTIONAL
351 IN EFI_UGA_BLT_OPERATION BltOperation,
352 IN UINTN SourceX,
353 IN UINTN SourceY,
354 IN UINTN DestinationX,
355 IN UINTN DestinationY,
356 IN UINTN Width,
357 IN UINTN Height,
358 IN UINTN Delta
359 )
360 /*++
361
362 Routine Description:
363
364 UGA draw protocol instance to block transfer for VBE device
365
366 Arguments:
367
368 This - Pointer to UGA draw protocol instance
369 BltBuffer - The data to transfer to screen
370 BltOperation - The operation to perform
371 SourceX - The X coordinate of the source for BltOperation
372 SourceY - The Y coordinate of the source for BltOperation
373 DestinationX - The X coordinate of the destination for BltOperation
374 DestinationY - The Y coordinate of the destination for BltOperation
375 Width - The width of a rectangle in the blt rectangle in pixels
376 Height - The height of a rectangle in the blt rectangle in pixels
377 Delta - Not used for EfiUgaVideoFill and EfiUgaVideoToVideo operation.
378 If a Delta of 0 is used, the entire BltBuffer will be operated on.
379 If a subrectangle of the BltBuffer is used, then Delta represents
380 the number of bytes in a row of the BltBuffer.
381
382 Returns:
383
384 EFI_INVALID_PARAMETER - Invalid parameter passed in
385 EFI_SUCCESS - Blt operation success
386
387 --*/
388 ;
389
390 EFI_STATUS
391 EFIAPI
392 BiosVideoUgaDrawVgaBlt (
393 IN EFI_UGA_DRAW_PROTOCOL *This,
394 IN EFI_UGA_PIXEL *BltBuffer, OPTIONAL
395 IN EFI_UGA_BLT_OPERATION BltOperation,
396 IN UINTN SourceX,
397 IN UINTN SourceY,
398 IN UINTN DestinationX,
399 IN UINTN DestinationY,
400 IN UINTN Width,
401 IN UINTN Height,
402 IN UINTN Delta
403 )
404 /*++
405
406 Routine Description:
407
408 UGA draw protocol instance to block transfer for VGA device
409
410 Arguments:
411
412 This - Pointer to UGA draw protocol instance
413 BltBuffer - The data to transfer to screen
414 BltOperation - The operation to perform
415 SourceX - The X coordinate of the source for BltOperation
416 SourceY - The Y coordinate of the source for BltOperation
417 DestinationX - The X coordinate of the destination for BltOperation
418 DestinationY - The Y coordinate of the destination for BltOperation
419 Width - The width of a rectangle in the blt rectangle in pixels
420 Height - The height of a rectangle in the blt rectangle in pixels
421 Delta - Not used for EfiUgaVideoFill and EfiUgaVideoToVideo operation.
422 If a Delta of 0 is used, the entire BltBuffer will be operated on.
423 If a subrectangle of the BltBuffer is used, then Delta represents
424 the number of bytes in a row of the BltBuffer.
425
426 Returns:
427
428 EFI_INVALID_PARAMETER - Invalid parameter passed in
429 EFI_SUCCESS - Blt operation success
430
431 --*/
432 ;
433
434 //
435 // BIOS VGA Mini Port Protocol functions
436 //
437 EFI_STATUS
438 EFIAPI
439 BiosVideoVgaMiniPortSetMode (
440 IN EFI_VGA_MINI_PORT_PROTOCOL *This,
441 IN UINTN ModeNumber
442 )
443 /*++
444
445 Routine Description:
446
447 VgaMiniPort protocol interface to set mode
448
449 Arguments:
450
451 This - Pointer to VgaMiniPort protocol instance
452 ModeNumber - The index of the mode
453
454 Returns:
455
456 EFI_UNSUPPORTED - The requested mode is not supported
457 EFI_SUCCESS - The requested mode is set successfully
458
459 --*/
460 ;
461
462
463 BOOLEAN
464 BiosVideoIsVga (
465 IN EFI_PCI_IO_PROTOCOL *PciIo
466 )
467 ;
468
469
470 //
471 // Standard VGA Definitions
472 //
473 #define VGA_HORIZONTAL_RESOLUTION 640
474 #define VGA_VERTICAL_RESOLUTION 480
475 #define VGA_NUMBER_OF_BIT_PLANES 4
476 #define VGA_PIXELS_PER_BYTE 8
477 #define VGA_BYTES_PER_SCAN_LINE (VGA_HORIZONTAL_RESOLUTION / VGA_PIXELS_PER_BYTE)
478 #define VGA_BYTES_PER_BIT_PLANE (VGA_VERTICAL_RESOLUTION * VGA_BYTES_PER_SCAN_LINE)
479
480 #define VGA_GRAPHICS_CONTROLLER_ADDRESS_REGISTER 0x3ce
481 #define VGA_GRAPHICS_CONTROLLER_DATA_REGISTER 0x3cf
482
483 #define VGA_GRAPHICS_CONTROLLER_SET_RESET_REGISTER 0x00
484
485 #define VGA_GRAPHICS_CONTROLLER_ENABLE_SET_RESET_REGISTER 0x01
486
487 #define VGA_GRAPHICS_CONTROLLER_COLOR_COMPARE_REGISTER 0x02
488
489 #define VGA_GRAPHICS_CONTROLLER_DATA_ROTATE_REGISTER 0x03
490 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_REPLACE 0x00
491 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_AND 0x08
492 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_OR 0x10
493 #define VGA_GRAPHICS_CONTROLLER_FUNCTION_XOR 0x18
494
495 #define VGA_GRAPHICS_CONTROLLER_READ_MAP_SELECT_REGISTER 0x04
496
497 #define VGA_GRAPHICS_CONTROLLER_MODE_REGISTER 0x05
498 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_0 0x00
499 #define VGA_GRAPHICS_CONTROLLER_READ_MODE_1 0x08
500 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_0 0x00
501 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_1 0x01
502 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_2 0x02
503 #define VGA_GRAPHICS_CONTROLLER_WRITE_MODE_3 0x03
504
505 #define VGA_GRAPHICS_CONTROLLER_MISCELLANEOUS_REGISTER 0x06
506
507 #define VGA_GRAPHICS_CONTROLLER_COLOR_DONT_CARE_REGISTER 0x07
508
509 #define VGA_GRAPHICS_CONTROLLER_BIT_MASK_REGISTER 0x08
510
511 #endif