2 Graphics Output Protocol functions for the QEMU video controller.
4 Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <IndustryStandard/Acpi.h>
18 #include <Library/BltLib.h>
22 QemuVideoCompleteModeInfo (
23 IN QEMU_VIDEO_MODE_DATA
*ModeData
,
24 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
28 if (ModeData
->ColorDepth
== 8) {
29 Info
->PixelFormat
= PixelBitMask
;
30 Info
->PixelInformation
.RedMask
= PIXEL_RED_MASK
;
31 Info
->PixelInformation
.GreenMask
= PIXEL_GREEN_MASK
;
32 Info
->PixelInformation
.BlueMask
= PIXEL_BLUE_MASK
;
33 Info
->PixelInformation
.ReservedMask
= 0;
34 } else if (ModeData
->ColorDepth
== 24) {
35 Info
->PixelFormat
= PixelBitMask
;
36 Info
->PixelInformation
.RedMask
= PIXEL24_RED_MASK
;
37 Info
->PixelInformation
.GreenMask
= PIXEL24_GREEN_MASK
;
38 Info
->PixelInformation
.BlueMask
= PIXEL24_BLUE_MASK
;
39 Info
->PixelInformation
.ReservedMask
= 0;
40 } else if (ModeData
->ColorDepth
== 32) {
41 DEBUG ((EFI_D_INFO
, "PixelBlueGreenRedReserved8BitPerColor\n"));
42 Info
->PixelFormat
= PixelBlueGreenRedReserved8BitPerColor
;
44 Info
->PixelsPerScanLine
= Info
->HorizontalResolution
;
50 QemuVideoCompleteModeData (
51 IN QEMU_VIDEO_PRIVATE_DATA
*Private
,
52 OUT EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
*Mode
55 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
*Info
;
56 EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR
*FrameBufDesc
;
57 QEMU_VIDEO_MODE_DATA
*ModeData
;
59 ModeData
= &Private
->ModeData
[Mode
->Mode
];
61 QemuVideoCompleteModeInfo (ModeData
, Info
);
63 Private
->PciIo
->GetBarAttributes (
67 (VOID
**) &FrameBufDesc
70 Mode
->FrameBufferBase
= FrameBufDesc
->AddrRangeMin
;
71 Mode
->FrameBufferSize
= Info
->HorizontalResolution
* Info
->VerticalResolution
;
72 Mode
->FrameBufferSize
= Mode
->FrameBufferSize
* ((ModeData
->ColorDepth
+ 7) / 8);
73 DEBUG ((EFI_D_INFO
, "FrameBufferBase: 0x%x, FrameBufferSize: 0x%x\n", Mode
->FrameBufferBase
, Mode
->FrameBufferSize
));
80 // Graphics Output Protocol Member Functions
84 QemuVideoGraphicsOutputQueryMode (
85 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
87 OUT UINTN
*SizeOfInfo
,
88 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
94 Graphics Output protocol interface to query video mode
97 This - Protocol instance pointer.
98 ModeNumber - The mode number to return information on.
99 Info - Caller allocated buffer that returns information about ModeNumber.
100 SizeOfInfo - A pointer to the size, in bytes, of the Info buffer.
103 EFI_SUCCESS - Mode information returned.
104 EFI_BUFFER_TOO_SMALL - The Info buffer was too small.
105 EFI_DEVICE_ERROR - A hardware error occurred trying to retrieve the video mode.
106 EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
107 EFI_INVALID_PARAMETER - One of the input args was NULL.
111 QEMU_VIDEO_PRIVATE_DATA
*Private
;
112 QEMU_VIDEO_MODE_DATA
*ModeData
;
114 Private
= QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (This
);
116 if (Private
->HardwareNeedsStarting
) {
117 return EFI_NOT_STARTED
;
120 if (Info
== NULL
|| SizeOfInfo
== NULL
|| ModeNumber
>= This
->Mode
->MaxMode
) {
121 return EFI_INVALID_PARAMETER
;
124 *Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
126 return EFI_OUT_OF_RESOURCES
;
129 *SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
131 ModeData
= &Private
->ModeData
[ModeNumber
];
132 (*Info
)->HorizontalResolution
= ModeData
->HorizontalResolution
;
133 (*Info
)->VerticalResolution
= ModeData
->VerticalResolution
;
134 QemuVideoCompleteModeInfo (ModeData
, *Info
);
141 QemuVideoGraphicsOutputSetMode (
142 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
149 Graphics Output protocol interface to set video mode
152 This - Protocol instance pointer.
153 ModeNumber - The mode number to be set.
156 EFI_SUCCESS - Graphics mode was changed.
157 EFI_DEVICE_ERROR - The device had an error and could not complete the request.
158 EFI_UNSUPPORTED - ModeNumber is not supported by this device.
162 QEMU_VIDEO_PRIVATE_DATA
*Private
;
163 QEMU_VIDEO_MODE_DATA
*ModeData
;
166 Private
= QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (This
);
168 if (ModeNumber
>= This
->Mode
->MaxMode
) {
169 return EFI_UNSUPPORTED
;
172 ModeData
= &Private
->ModeData
[ModeNumber
];
174 if (Private
->LineBuffer
) {
175 gBS
->FreePool (Private
->LineBuffer
);
178 Private
->LineBuffer
= NULL
;
179 Private
->LineBuffer
= AllocatePool (4 * ModeData
->HorizontalResolution
);
180 if (Private
->LineBuffer
== NULL
) {
181 return EFI_OUT_OF_RESOURCES
;
184 InitializeGraphicsMode (Private
, &QemuVideoVideoModes
[ModeData
->ModeNumber
]);
186 This
->Mode
->Mode
= ModeNumber
;
187 This
->Mode
->Info
->HorizontalResolution
= ModeData
->HorizontalResolution
;
188 This
->Mode
->Info
->VerticalResolution
= ModeData
->VerticalResolution
;
189 This
->Mode
->SizeOfInfo
= sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
191 QemuVideoCompleteModeData (Private
, This
->Mode
);
194 (VOID
*)(UINTN
) This
->Mode
->FrameBufferBase
,
198 Private
->HardwareNeedsStarting
= FALSE
;
205 QemuVideoGraphicsOutputBlt (
206 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
207 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
208 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
211 IN UINTN DestinationX
,
212 IN UINTN DestinationY
,
221 Graphics Output protocol instance to block transfer for CirrusLogic device
225 This - Pointer to Graphics Output protocol instance
226 BltBuffer - The data to transfer to screen
227 BltOperation - The operation to perform
228 SourceX - The X coordinate of the source for BltOperation
229 SourceY - The Y coordinate of the source for BltOperation
230 DestinationX - The X coordinate of the destination for BltOperation
231 DestinationY - The Y coordinate of the destination for BltOperation
232 Width - The width of a rectangle in the blt rectangle in pixels
233 Height - The height of a rectangle in the blt rectangle in pixels
234 Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
235 If a Delta of 0 is used, the entire BltBuffer will be operated on.
236 If a subrectangle of the BltBuffer is used, then Delta represents
237 the number of bytes in a row of the BltBuffer.
241 EFI_INVALID_PARAMETER - Invalid parameter passed in
242 EFI_SUCCESS - Blt operation success
250 // We have to raise to TPL Notify, so we make an atomic write the frame buffer.
251 // We would not want a timer based event (Cursor, ...) to come in while we are
252 // doing this operation.
254 OriginalTPL
= gBS
->RaiseTPL (TPL_NOTIFY
);
256 switch (BltOperation
) {
257 case EfiBltVideoToBltBuffer
:
258 case EfiBltBufferToVideo
:
259 case EfiBltVideoFill
:
260 case EfiBltVideoToVideo
:
261 Status
= BltLibGopBlt (
275 Status
= EFI_INVALID_PARAMETER
;
279 gBS
->RestoreTPL (OriginalTPL
);
285 QemuVideoGraphicsOutputConstructor (
286 QEMU_VIDEO_PRIVATE_DATA
*Private
290 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
293 GraphicsOutput
= &Private
->GraphicsOutput
;
294 GraphicsOutput
->QueryMode
= QemuVideoGraphicsOutputQueryMode
;
295 GraphicsOutput
->SetMode
= QemuVideoGraphicsOutputSetMode
;
296 GraphicsOutput
->Blt
= QemuVideoGraphicsOutputBlt
;
299 // Initialize the private data
301 Status
= gBS
->AllocatePool (
303 sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
),
304 (VOID
**) &Private
->GraphicsOutput
.Mode
306 if (EFI_ERROR (Status
)) {
309 Status
= gBS
->AllocatePool (
311 sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
),
312 (VOID
**) &Private
->GraphicsOutput
.Mode
->Info
314 if (EFI_ERROR (Status
)) {
317 Private
->GraphicsOutput
.Mode
->MaxMode
= (UINT32
) Private
->MaxMode
;
318 Private
->GraphicsOutput
.Mode
->Mode
= GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER
;
319 Private
->HardwareNeedsStarting
= TRUE
;
320 Private
->LineBuffer
= NULL
;
323 // Initialize the hardware
325 GraphicsOutput
->SetMode (GraphicsOutput
, 0);
328 Private
->ModeData
[Private
->GraphicsOutput
.Mode
->Mode
].HorizontalResolution
,
329 Private
->ModeData
[Private
->GraphicsOutput
.Mode
->Mode
].VerticalResolution
336 QemuVideoGraphicsOutputDestructor (
337 QEMU_VIDEO_PRIVATE_DATA
*Private
351 if (Private
->GraphicsOutput
.Mode
!= NULL
) {
352 if (Private
->GraphicsOutput
.Mode
->Info
!= NULL
) {
353 gBS
->FreePool (Private
->GraphicsOutput
.Mode
->Info
);
355 gBS
->FreePool (Private
->GraphicsOutput
.Mode
);