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