2 QEMU Video Controller Driver
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 // QEMU Video Controller Driver
24 #include <Protocol/GraphicsOutput.h>
25 #include <Protocol/PciIo.h>
26 #include <Protocol/DriverSupportedEfiVersion.h>
27 #include <Protocol/DevicePath.h>
29 #include <Library/DebugLib.h>
30 #include <Library/UefiDriverEntryPoint.h>
31 #include <Library/UefiLib.h>
32 #include <Library/PcdLib.h>
33 #include <Library/MemoryAllocationLib.h>
34 #include <Library/UefiBootServicesTableLib.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/DevicePathLib.h>
37 #include <Library/TimerLib.h>
39 #include <IndustryStandard/Pci.h>
42 // QEMU Video PCI Configuration Header values
44 #define CIRRUS_LOGIC_VENDOR_ID 0x1013
45 #define CIRRUS_LOGIC_5430_DEVICE_ID 0x00a8
46 #define CIRRUS_LOGIC_5430_ALTERNATE_DEVICE_ID 0x00a0
47 #define CIRRUS_LOGIC_5446_DEVICE_ID 0x00b8
50 // QEMU Vide Graphical Mode Data
53 UINT32 InternalModeIndex
; // points into card-specific mode table
54 UINT32 HorizontalResolution
;
55 UINT32 VerticalResolution
;
58 } QEMU_VIDEO_MODE_DATA
;
60 #define PIXEL_RED_SHIFT 0
61 #define PIXEL_GREEN_SHIFT 3
62 #define PIXEL_BLUE_SHIFT 6
64 #define PIXEL_RED_MASK (BIT7 | BIT6 | BIT5)
65 #define PIXEL_GREEN_MASK (BIT4 | BIT3 | BIT2)
66 #define PIXEL_BLUE_MASK (BIT1 | BIT0)
68 #define PIXEL_TO_COLOR_BYTE(pixel, mask, shift) ((UINT8) ((pixel & mask) << shift))
69 #define PIXEL_TO_RED_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_RED_MASK, PIXEL_RED_SHIFT)
70 #define PIXEL_TO_GREEN_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_GREEN_MASK, PIXEL_GREEN_SHIFT)
71 #define PIXEL_TO_BLUE_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_BLUE_MASK, PIXEL_BLUE_SHIFT)
73 #define RGB_BYTES_TO_PIXEL(Red, Green, Blue) \
74 (UINT8) ( (((Red) >> PIXEL_RED_SHIFT) & PIXEL_RED_MASK) | \
75 (((Green) >> PIXEL_GREEN_SHIFT) & PIXEL_GREEN_MASK) | \
76 (((Blue) >> PIXEL_BLUE_SHIFT) & PIXEL_BLUE_MASK) )
78 #define PIXEL24_RED_MASK 0x00ff0000
79 #define PIXEL24_GREEN_MASK 0x0000ff00
80 #define PIXEL24_BLUE_MASK 0x000000ff
82 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
85 // QEMU Video Private Data Structure
87 #define QEMU_VIDEO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('Q', 'V', 'I', 'D')
90 QEMU_VIDEO_CIRRUS_5430
= 1,
91 QEMU_VIDEO_CIRRUS_5446
,
93 QEMU_VIDEO_BOCHS_MMIO
,
99 QEMU_VIDEO_VARIANT Variant
;
106 EFI_PCI_IO_PROTOCOL
*PciIo
;
107 UINT64 OriginalPciAttributes
;
108 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput
;
109 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
112 // The next three fields match the client-visible
113 // EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.Mode and
114 // EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.MaxMode fields.
118 QEMU_VIDEO_MODE_DATA
*ModeData
;
121 QEMU_VIDEO_VARIANT Variant
;
122 } QEMU_VIDEO_PRIVATE_DATA
;
125 /// Card-specific Video Mode structures
135 } QEMU_VIDEO_CIRRUS_MODES
;
141 } QEMU_VIDEO_BOCHS_MODES
;
143 #define QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
144 CR(a, QEMU_VIDEO_PRIVATE_DATA, GraphicsOutput, QEMU_VIDEO_PRIVATE_DATA_SIGNATURE)
150 extern UINT8 AttributeController
[];
151 extern UINT8 GraphicsController
[];
152 extern UINT8 Crtc_640_480_256_60
[];
153 extern UINT16 Seq_640_480_256_60
[];
154 extern UINT8 Crtc_800_600_256_60
[];
155 extern UINT16 Seq_800_600_256_60
[];
156 extern UINT8 Crtc_1024_768_256_60
[];
157 extern UINT16 Seq_1024_768_256_60
[];
158 extern QEMU_VIDEO_CIRRUS_MODES QemuVideoCirrusModes
[];
159 extern QEMU_VIDEO_BOCHS_MODES QemuVideoBochsModes
[];
160 extern EFI_DRIVER_BINDING_PROTOCOL gQemuVideoDriverBinding
;
161 extern EFI_COMPONENT_NAME_PROTOCOL gQemuVideoComponentName
;
162 extern EFI_COMPONENT_NAME2_PROTOCOL gQemuVideoComponentName2
;
163 extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gQemuVideoDriverSupportedEfiVersion
;
166 // Io Registers defined by VGA
168 #define CRTC_ADDRESS_REGISTER 0x3d4
169 #define CRTC_DATA_REGISTER 0x3d5
170 #define SEQ_ADDRESS_REGISTER 0x3c4
171 #define SEQ_DATA_REGISTER 0x3c5
172 #define GRAPH_ADDRESS_REGISTER 0x3ce
173 #define GRAPH_DATA_REGISTER 0x3cf
174 #define ATT_ADDRESS_REGISTER 0x3c0
175 #define MISC_OUTPUT_REGISTER 0x3c2
176 #define INPUT_STATUS_1_REGISTER 0x3da
177 #define DAC_PIXEL_MASK_REGISTER 0x3c6
178 #define PALETTE_INDEX_REGISTER 0x3c8
179 #define PALETTE_DATA_REGISTER 0x3c9
181 #define VBE_DISPI_IOPORT_INDEX 0x01CE
182 #define VBE_DISPI_IOPORT_DATA 0x01D0
184 #define VBE_DISPI_INDEX_ID 0x0
185 #define VBE_DISPI_INDEX_XRES 0x1
186 #define VBE_DISPI_INDEX_YRES 0x2
187 #define VBE_DISPI_INDEX_BPP 0x3
188 #define VBE_DISPI_INDEX_ENABLE 0x4
189 #define VBE_DISPI_INDEX_BANK 0x5
190 #define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
191 #define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
192 #define VBE_DISPI_INDEX_X_OFFSET 0x8
193 #define VBE_DISPI_INDEX_Y_OFFSET 0x9
194 #define VBE_DISPI_INDEX_VIDEO_MEMORY_64K 0xa
196 #define VBE_DISPI_ID0 0xB0C0
197 #define VBE_DISPI_ID1 0xB0C1
198 #define VBE_DISPI_ID2 0xB0C2
199 #define VBE_DISPI_ID3 0xB0C3
200 #define VBE_DISPI_ID4 0xB0C4
201 #define VBE_DISPI_ID5 0xB0C5
203 #define VBE_DISPI_DISABLED 0x00
204 #define VBE_DISPI_ENABLED 0x01
205 #define VBE_DISPI_GETCAPS 0x02
206 #define VBE_DISPI_8BIT_DAC 0x20
207 #define VBE_DISPI_LFB_ENABLED 0x40
208 #define VBE_DISPI_NOCLEARMEM 0x80
211 // Graphics Output Hardware abstraction internal worker functions
214 QemuVideoGraphicsOutputConstructor (
215 QEMU_VIDEO_PRIVATE_DATA
*Private
219 QemuVideoGraphicsOutputDestructor (
220 QEMU_VIDEO_PRIVATE_DATA
*Private
225 // EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
228 TODO: Add function description
230 @param This TODO: add argument description
231 @param Controller TODO: add argument description
232 @param RemainingDevicePath TODO: add argument description
234 TODO: add return values
239 QemuVideoControllerDriverSupported (
240 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
241 IN EFI_HANDLE Controller
,
242 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
246 TODO: Add function description
248 @param This TODO: add argument description
249 @param Controller TODO: add argument description
250 @param RemainingDevicePath TODO: add argument description
252 TODO: add return values
257 QemuVideoControllerDriverStart (
258 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
259 IN EFI_HANDLE Controller
,
260 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
264 TODO: Add function description
266 @param This TODO: add argument description
267 @param Controller TODO: add argument description
268 @param NumberOfChildren TODO: add argument description
269 @param ChildHandleBuffer TODO: add argument description
271 TODO: add return values
276 QemuVideoControllerDriverStop (
277 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
278 IN EFI_HANDLE Controller
,
279 IN UINTN NumberOfChildren
,
280 IN EFI_HANDLE
*ChildHandleBuffer
284 // EFI Component Name Functions
287 Retrieves a Unicode string that is the user readable name of the driver.
289 This function retrieves the user readable name of a driver in the form of a
290 Unicode string. If the driver specified by This has a user readable name in
291 the language specified by Language, then a pointer to the driver name is
292 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
293 by This does not support the language specified by Language,
294 then EFI_UNSUPPORTED is returned.
296 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
297 EFI_COMPONENT_NAME_PROTOCOL instance.
299 @param Language[in] A pointer to a Null-terminated ASCII string
300 array indicating the language. This is the
301 language of the driver name that the caller is
302 requesting, and it must match one of the
303 languages specified in SupportedLanguages. The
304 number of languages supported by a driver is up
305 to the driver writer. Language is specified
306 in RFC 4646 or ISO 639-2 language code format.
308 @param DriverName[out] A pointer to the Unicode string to return.
309 This Unicode string is the name of the
310 driver specified by This in the language
311 specified by Language.
313 @retval EFI_SUCCESS The Unicode string for the Driver specified by
314 This and the language specified by Language was
315 returned in DriverName.
317 @retval EFI_INVALID_PARAMETER Language is NULL.
319 @retval EFI_INVALID_PARAMETER DriverName is NULL.
321 @retval EFI_UNSUPPORTED The driver specified by This does not support
322 the language specified by Language.
327 QemuVideoComponentNameGetDriverName (
328 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
330 OUT CHAR16
**DriverName
335 Retrieves a Unicode string that is the user readable name of the controller
336 that is being managed by a driver.
338 This function retrieves the user readable name of the controller specified by
339 ControllerHandle and ChildHandle in the form of a Unicode string. If the
340 driver specified by This has a user readable name in the language specified by
341 Language, then a pointer to the controller name is returned in ControllerName,
342 and EFI_SUCCESS is returned. If the driver specified by This is not currently
343 managing the controller specified by ControllerHandle and ChildHandle,
344 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
345 support the language specified by Language, then EFI_UNSUPPORTED is returned.
347 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
348 EFI_COMPONENT_NAME_PROTOCOL instance.
350 @param ControllerHandle[in] The handle of a controller that the driver
351 specified by This is managing. This handle
352 specifies the controller whose name is to be
355 @param ChildHandle[in] The handle of the child controller to retrieve
356 the name of. This is an optional parameter that
357 may be NULL. It will be NULL for device
358 drivers. It will also be NULL for a bus drivers
359 that wish to retrieve the name of the bus
360 controller. It will not be NULL for a bus
361 driver that wishes to retrieve the name of a
364 @param Language[in] A pointer to a Null-terminated ASCII string
365 array indicating the language. This is the
366 language of the driver name that the caller is
367 requesting, and it must match one of the
368 languages specified in SupportedLanguages. The
369 number of languages supported by a driver is up
370 to the driver writer. Language is specified in
371 RFC 4646 or ISO 639-2 language code format.
373 @param ControllerName[out] A pointer to the Unicode string to return.
374 This Unicode string is the name of the
375 controller specified by ControllerHandle and
376 ChildHandle in the language specified by
377 Language from the point of view of the driver
380 @retval EFI_SUCCESS The Unicode string for the user readable name in
381 the language specified by Language for the
382 driver specified by This was returned in
385 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
387 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
390 @retval EFI_INVALID_PARAMETER Language is NULL.
392 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
394 @retval EFI_UNSUPPORTED The driver specified by This is not currently
395 managing the controller specified by
396 ControllerHandle and ChildHandle.
398 @retval EFI_UNSUPPORTED The driver specified by This does not support
399 the language specified by Language.
404 QemuVideoComponentNameGetControllerName (
405 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
406 IN EFI_HANDLE ControllerHandle
,
407 IN EFI_HANDLE ChildHandle OPTIONAL
,
409 OUT CHAR16
**ControllerName
414 // Local Function Prototypes
417 InitializeCirrusGraphicsMode (
418 QEMU_VIDEO_PRIVATE_DATA
*Private
,
419 QEMU_VIDEO_CIRRUS_MODES
*ModeData
423 InitializeBochsGraphicsMode (
424 QEMU_VIDEO_PRIVATE_DATA
*Private
,
425 QEMU_VIDEO_BOCHS_MODES
*ModeData
430 QEMU_VIDEO_PRIVATE_DATA
*Private
,
439 QEMU_VIDEO_PRIVATE_DATA
*Private
444 QEMU_VIDEO_PRIVATE_DATA
*Private
,
451 QEMU_VIDEO_PRIVATE_DATA
*Private
,
458 QEMU_VIDEO_PRIVATE_DATA
*Private
,
465 QEMU_VIDEO_PRIVATE_DATA
*Private
,
471 QEMU_VIDEO_PRIVATE_DATA
*Private
,
477 QEMU_VIDEO_PRIVATE_DATA
*Private
,
484 QEMU_VIDEO_PRIVATE_DATA
*Private
,
490 QEMU_VIDEO_PRIVATE_DATA
*Private
,
496 QemuVideoCirrusModeSetup (
497 QEMU_VIDEO_PRIVATE_DATA
*Private
501 QemuVideoBochsModeSetup (
502 QEMU_VIDEO_PRIVATE_DATA
*Private
,
508 IN CONST CHAR16
*CardName
,
509 IN EFI_PHYSICAL_ADDRESS FrameBufferBase