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%Lx, FrameBufferSize: 0x%Lx\n",
74 Mode
->FrameBufferBase
, (UINT64
)Mode
->FrameBufferSize
));
76 FreePool (FrameBufDesc
);
82 // Graphics Output Protocol Member Functions
86 QemuVideoGraphicsOutputQueryMode (
87 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
89 OUT UINTN
*SizeOfInfo
,
90 OUT EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
**Info
96 Graphics Output protocol interface to query video mode
99 This - Protocol instance pointer.
100 ModeNumber - The mode number to return information on.
101 Info - Caller allocated buffer that returns information about ModeNumber.
102 SizeOfInfo - A pointer to the size, in bytes, of the Info buffer.
105 EFI_SUCCESS - Mode information returned.
106 EFI_BUFFER_TOO_SMALL - The Info buffer was too small.
107 EFI_DEVICE_ERROR - A hardware error occurred trying to retrieve the video mode.
108 EFI_NOT_STARTED - Video display is not initialized. Call SetMode ()
109 EFI_INVALID_PARAMETER - One of the input args was NULL.
113 QEMU_VIDEO_PRIVATE_DATA
*Private
;
114 QEMU_VIDEO_MODE_DATA
*ModeData
;
116 Private
= QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (This
);
118 if (Info
== NULL
|| SizeOfInfo
== NULL
|| ModeNumber
>= This
->Mode
->MaxMode
) {
119 return EFI_INVALID_PARAMETER
;
122 *Info
= AllocatePool (sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
));
124 return EFI_OUT_OF_RESOURCES
;
127 *SizeOfInfo
= sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
129 ModeData
= &Private
->ModeData
[ModeNumber
];
130 (*Info
)->HorizontalResolution
= ModeData
->HorizontalResolution
;
131 (*Info
)->VerticalResolution
= ModeData
->VerticalResolution
;
132 QemuVideoCompleteModeInfo (ModeData
, *Info
);
139 QemuVideoGraphicsOutputSetMode (
140 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
147 Graphics Output protocol interface to set video mode
150 This - Protocol instance pointer.
151 ModeNumber - The mode number to be set.
154 EFI_SUCCESS - Graphics mode was changed.
155 EFI_DEVICE_ERROR - The device had an error and could not complete the request.
156 EFI_UNSUPPORTED - ModeNumber is not supported by this device.
160 QEMU_VIDEO_PRIVATE_DATA
*Private
;
161 QEMU_VIDEO_MODE_DATA
*ModeData
;
164 Private
= QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (This
);
166 if (ModeNumber
>= This
->Mode
->MaxMode
) {
167 return EFI_UNSUPPORTED
;
170 ModeData
= &Private
->ModeData
[ModeNumber
];
172 if (Private
->LineBuffer
) {
173 gBS
->FreePool (Private
->LineBuffer
);
176 Private
->LineBuffer
= AllocatePool (4 * ModeData
->HorizontalResolution
);
177 if (Private
->LineBuffer
== NULL
) {
178 return EFI_OUT_OF_RESOURCES
;
181 switch (Private
->Variant
) {
182 case QEMU_VIDEO_CIRRUS_5430
:
183 case QEMU_VIDEO_CIRRUS_5446
:
184 InitializeCirrusGraphicsMode (Private
, &QemuVideoCirrusModes
[ModeData
->InternalModeIndex
]);
186 case QEMU_VIDEO_BOCHS_MMIO
:
187 case QEMU_VIDEO_BOCHS
:
188 InitializeBochsGraphicsMode (Private
, &QemuVideoBochsModes
[ModeData
->InternalModeIndex
]);
192 gBS
->FreePool (Private
->LineBuffer
);
193 Private
->LineBuffer
= NULL
;
194 return EFI_DEVICE_ERROR
;
197 This
->Mode
->Mode
= ModeNumber
;
198 This
->Mode
->Info
->HorizontalResolution
= ModeData
->HorizontalResolution
;
199 This
->Mode
->Info
->VerticalResolution
= ModeData
->VerticalResolution
;
200 This
->Mode
->SizeOfInfo
= sizeof(EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
);
202 QemuVideoCompleteModeData (Private
, This
->Mode
);
205 (VOID
*)(UINTN
) This
->Mode
->FrameBufferBase
,
214 QemuVideoGraphicsOutputBlt (
215 IN EFI_GRAPHICS_OUTPUT_PROTOCOL
*This
,
216 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
, OPTIONAL
217 IN EFI_GRAPHICS_OUTPUT_BLT_OPERATION BltOperation
,
220 IN UINTN DestinationX
,
221 IN UINTN DestinationY
,
230 Graphics Output protocol instance to block transfer for CirrusLogic device
234 This - Pointer to Graphics Output protocol instance
235 BltBuffer - The data to transfer to screen
236 BltOperation - The operation to perform
237 SourceX - The X coordinate of the source for BltOperation
238 SourceY - The Y coordinate of the source for BltOperation
239 DestinationX - The X coordinate of the destination for BltOperation
240 DestinationY - The Y coordinate of the destination for BltOperation
241 Width - The width of a rectangle in the blt rectangle in pixels
242 Height - The height of a rectangle in the blt rectangle in pixels
243 Delta - Not used for EfiBltVideoFill and EfiBltVideoToVideo operation.
244 If a Delta of 0 is used, the entire BltBuffer will be operated on.
245 If a subrectangle of the BltBuffer is used, then Delta represents
246 the number of bytes in a row of the BltBuffer.
250 EFI_INVALID_PARAMETER - Invalid parameter passed in
251 EFI_SUCCESS - Blt operation success
259 // We have to raise to TPL Notify, so we make an atomic write the frame buffer.
260 // We would not want a timer based event (Cursor, ...) to come in while we are
261 // doing this operation.
263 OriginalTPL
= gBS
->RaiseTPL (TPL_NOTIFY
);
265 switch (BltOperation
) {
266 case EfiBltVideoToBltBuffer
:
267 case EfiBltBufferToVideo
:
268 case EfiBltVideoFill
:
269 case EfiBltVideoToVideo
:
270 Status
= BltLibGopBlt (
284 Status
= EFI_INVALID_PARAMETER
;
288 gBS
->RestoreTPL (OriginalTPL
);
294 QemuVideoGraphicsOutputConstructor (
295 QEMU_VIDEO_PRIVATE_DATA
*Private
299 EFI_GRAPHICS_OUTPUT_PROTOCOL
*GraphicsOutput
;
302 GraphicsOutput
= &Private
->GraphicsOutput
;
303 GraphicsOutput
->QueryMode
= QemuVideoGraphicsOutputQueryMode
;
304 GraphicsOutput
->SetMode
= QemuVideoGraphicsOutputSetMode
;
305 GraphicsOutput
->Blt
= QemuVideoGraphicsOutputBlt
;
308 // Initialize the private data
310 Status
= gBS
->AllocatePool (
312 sizeof (EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE
),
313 (VOID
**) &Private
->GraphicsOutput
.Mode
315 if (EFI_ERROR (Status
)) {
319 Status
= gBS
->AllocatePool (
321 sizeof (EFI_GRAPHICS_OUTPUT_MODE_INFORMATION
),
322 (VOID
**) &Private
->GraphicsOutput
.Mode
->Info
324 if (EFI_ERROR (Status
)) {
327 Private
->GraphicsOutput
.Mode
->MaxMode
= (UINT32
) Private
->MaxMode
;
328 Private
->GraphicsOutput
.Mode
->Mode
= GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER
;
329 Private
->LineBuffer
= NULL
;
332 // Initialize the hardware
334 Status
= GraphicsOutput
->SetMode (GraphicsOutput
, 0);
335 if (EFI_ERROR (Status
)) {
341 Private
->ModeData
[Private
->GraphicsOutput
.Mode
->Mode
].HorizontalResolution
,
342 Private
->ModeData
[Private
->GraphicsOutput
.Mode
->Mode
].VerticalResolution
348 FreePool (Private
->GraphicsOutput
.Mode
->Info
);
351 FreePool (Private
->GraphicsOutput
.Mode
);
352 Private
->GraphicsOutput
.Mode
= NULL
;
358 QemuVideoGraphicsOutputDestructor (
359 QEMU_VIDEO_PRIVATE_DATA
*Private
373 if (Private
->LineBuffer
!= NULL
) {
374 FreePool (Private
->LineBuffer
);
377 if (Private
->GraphicsOutput
.Mode
!= NULL
) {
378 if (Private
->GraphicsOutput
.Mode
->Info
!= NULL
) {
379 gBS
->FreePool (Private
->GraphicsOutput
.Mode
->Info
);
381 gBS
->FreePool (Private
->GraphicsOutput
.Mode
);