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
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 QEMU_VIDEO_MODE_DATA
*ModeData
;
114 BOOLEAN HardwareNeedsStarting
;
115 QEMU_VIDEO_VARIANT Variant
;
116 } QEMU_VIDEO_PRIVATE_DATA
;
119 /// Video Mode structure
129 } QEMU_VIDEO_CIRRUS_MODES
;
135 } QEMU_VIDEO_BOCHS_MODES
;
137 #define QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
138 CR(a, QEMU_VIDEO_PRIVATE_DATA, GraphicsOutput, QEMU_VIDEO_PRIVATE_DATA_SIGNATURE)
144 extern UINT8 AttributeController
[];
145 extern UINT8 GraphicsController
[];
146 extern UINT8 Crtc_640_480_256_60
[];
147 extern UINT16 Seq_640_480_256_60
[];
148 extern UINT8 Crtc_800_600_256_60
[];
149 extern UINT16 Seq_800_600_256_60
[];
150 extern UINT8 Crtc_1024_768_256_60
[];
151 extern UINT16 Seq_1024_768_256_60
[];
152 extern QEMU_VIDEO_CIRRUS_MODES QemuVideoCirrusModes
[];
153 extern QEMU_VIDEO_BOCHS_MODES QemuVideoBochsModes
[];
154 extern EFI_DRIVER_BINDING_PROTOCOL gQemuVideoDriverBinding
;
155 extern EFI_COMPONENT_NAME_PROTOCOL gQemuVideoComponentName
;
156 extern EFI_COMPONENT_NAME2_PROTOCOL gQemuVideoComponentName2
;
157 extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gQemuVideoDriverSupportedEfiVersion
;
160 // Io Registers defined by VGA
162 #define CRTC_ADDRESS_REGISTER 0x3d4
163 #define CRTC_DATA_REGISTER 0x3d5
164 #define SEQ_ADDRESS_REGISTER 0x3c4
165 #define SEQ_DATA_REGISTER 0x3c5
166 #define GRAPH_ADDRESS_REGISTER 0x3ce
167 #define GRAPH_DATA_REGISTER 0x3cf
168 #define ATT_ADDRESS_REGISTER 0x3c0
169 #define MISC_OUTPUT_REGISTER 0x3c2
170 #define INPUT_STATUS_1_REGISTER 0x3da
171 #define DAC_PIXEL_MASK_REGISTER 0x3c6
172 #define PALETTE_INDEX_REGISTER 0x3c8
173 #define PALETTE_DATA_REGISTER 0x3c9
175 #define VBE_DISPI_IOPORT_INDEX 0x01CE
176 #define VBE_DISPI_IOPORT_DATA 0x01D0
178 #define VBE_DISPI_INDEX_ID 0x0
179 #define VBE_DISPI_INDEX_XRES 0x1
180 #define VBE_DISPI_INDEX_YRES 0x2
181 #define VBE_DISPI_INDEX_BPP 0x3
182 #define VBE_DISPI_INDEX_ENABLE 0x4
183 #define VBE_DISPI_INDEX_BANK 0x5
184 #define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
185 #define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
186 #define VBE_DISPI_INDEX_X_OFFSET 0x8
187 #define VBE_DISPI_INDEX_Y_OFFSET 0x9
188 #define VBE_DISPI_INDEX_VIDEO_MEMORY_64K 0xa
190 #define VBE_DISPI_ID0 0xB0C0
191 #define VBE_DISPI_ID1 0xB0C1
192 #define VBE_DISPI_ID2 0xB0C2
193 #define VBE_DISPI_ID3 0xB0C3
194 #define VBE_DISPI_ID4 0xB0C4
195 #define VBE_DISPI_ID5 0xB0C5
197 #define VBE_DISPI_DISABLED 0x00
198 #define VBE_DISPI_ENABLED 0x01
199 #define VBE_DISPI_GETCAPS 0x02
200 #define VBE_DISPI_8BIT_DAC 0x20
201 #define VBE_DISPI_LFB_ENABLED 0x40
202 #define VBE_DISPI_NOCLEARMEM 0x80
205 // Graphics Output Hardware abstraction internal worker functions
208 QemuVideoGraphicsOutputConstructor (
209 QEMU_VIDEO_PRIVATE_DATA
*Private
213 QemuVideoGraphicsOutputDestructor (
214 QEMU_VIDEO_PRIVATE_DATA
*Private
219 // EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
222 TODO: Add function description
224 @param This TODO: add argument description
225 @param Controller TODO: add argument description
226 @param RemainingDevicePath TODO: add argument description
228 TODO: add return values
233 QemuVideoControllerDriverSupported (
234 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
235 IN EFI_HANDLE Controller
,
236 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
240 TODO: Add function description
242 @param This TODO: add argument description
243 @param Controller TODO: add argument description
244 @param RemainingDevicePath TODO: add argument description
246 TODO: add return values
251 QemuVideoControllerDriverStart (
252 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
253 IN EFI_HANDLE Controller
,
254 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
258 TODO: Add function description
260 @param This TODO: add argument description
261 @param Controller TODO: add argument description
262 @param NumberOfChildren TODO: add argument description
263 @param ChildHandleBuffer TODO: add argument description
265 TODO: add return values
270 QemuVideoControllerDriverStop (
271 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
272 IN EFI_HANDLE Controller
,
273 IN UINTN NumberOfChildren
,
274 IN EFI_HANDLE
*ChildHandleBuffer
278 // EFI Component Name Functions
281 Retrieves a Unicode string that is the user readable name of the driver.
283 This function retrieves the user readable name of a driver in the form of a
284 Unicode string. If the driver specified by This has a user readable name in
285 the language specified by Language, then a pointer to the driver name is
286 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
287 by This does not support the language specified by Language,
288 then EFI_UNSUPPORTED is returned.
290 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
291 EFI_COMPONENT_NAME_PROTOCOL instance.
293 @param Language[in] A pointer to a Null-terminated ASCII string
294 array indicating the language. This is the
295 language of the driver name that the caller is
296 requesting, and it must match one of the
297 languages specified in SupportedLanguages. The
298 number of languages supported by a driver is up
299 to the driver writer. Language is specified
300 in RFC 4646 or ISO 639-2 language code format.
302 @param DriverName[out] A pointer to the Unicode string to return.
303 This Unicode string is the name of the
304 driver specified by This in the language
305 specified by Language.
307 @retval EFI_SUCCESS The Unicode string for the Driver specified by
308 This and the language specified by Language was
309 returned in DriverName.
311 @retval EFI_INVALID_PARAMETER Language is NULL.
313 @retval EFI_INVALID_PARAMETER DriverName is NULL.
315 @retval EFI_UNSUPPORTED The driver specified by This does not support
316 the language specified by Language.
321 QemuVideoComponentNameGetDriverName (
322 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
324 OUT CHAR16
**DriverName
329 Retrieves a Unicode string that is the user readable name of the controller
330 that is being managed by a driver.
332 This function retrieves the user readable name of the controller specified by
333 ControllerHandle and ChildHandle in the form of a Unicode string. If the
334 driver specified by This has a user readable name in the language specified by
335 Language, then a pointer to the controller name is returned in ControllerName,
336 and EFI_SUCCESS is returned. If the driver specified by This is not currently
337 managing the controller specified by ControllerHandle and ChildHandle,
338 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
339 support the language specified by Language, then EFI_UNSUPPORTED is returned.
341 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
342 EFI_COMPONENT_NAME_PROTOCOL instance.
344 @param ControllerHandle[in] The handle of a controller that the driver
345 specified by This is managing. This handle
346 specifies the controller whose name is to be
349 @param ChildHandle[in] The handle of the child controller to retrieve
350 the name of. This is an optional parameter that
351 may be NULL. It will be NULL for device
352 drivers. It will also be NULL for a bus drivers
353 that wish to retrieve the name of the bus
354 controller. It will not be NULL for a bus
355 driver that wishes to retrieve the name of a
358 @param Language[in] A pointer to a Null-terminated ASCII string
359 array indicating the language. This is the
360 language of the driver name that the caller is
361 requesting, and it must match one of the
362 languages specified in SupportedLanguages. The
363 number of languages supported by a driver is up
364 to the driver writer. Language is specified in
365 RFC 4646 or ISO 639-2 language code format.
367 @param ControllerName[out] A pointer to the Unicode string to return.
368 This Unicode string is the name of the
369 controller specified by ControllerHandle and
370 ChildHandle in the language specified by
371 Language from the point of view of the driver
374 @retval EFI_SUCCESS The Unicode string for the user readable name in
375 the language specified by Language for the
376 driver specified by This was returned in
379 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
381 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
384 @retval EFI_INVALID_PARAMETER Language is NULL.
386 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
388 @retval EFI_UNSUPPORTED The driver specified by This is not currently
389 managing the controller specified by
390 ControllerHandle and ChildHandle.
392 @retval EFI_UNSUPPORTED The driver specified by This does not support
393 the language specified by Language.
398 QemuVideoComponentNameGetControllerName (
399 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
400 IN EFI_HANDLE ControllerHandle
,
401 IN EFI_HANDLE ChildHandle OPTIONAL
,
403 OUT CHAR16
**ControllerName
408 // Local Function Prototypes
411 InitializeCirrusGraphicsMode (
412 QEMU_VIDEO_PRIVATE_DATA
*Private
,
413 QEMU_VIDEO_CIRRUS_MODES
*ModeData
417 InitializeBochsGraphicsMode (
418 QEMU_VIDEO_PRIVATE_DATA
*Private
,
419 QEMU_VIDEO_BOCHS_MODES
*ModeData
424 QEMU_VIDEO_PRIVATE_DATA
*Private
,
433 QEMU_VIDEO_PRIVATE_DATA
*Private
438 QEMU_VIDEO_PRIVATE_DATA
*Private
,
445 QEMU_VIDEO_PRIVATE_DATA
*Private
,
452 QEMU_VIDEO_PRIVATE_DATA
*Private
,
459 QEMU_VIDEO_PRIVATE_DATA
*Private
,
465 QEMU_VIDEO_PRIVATE_DATA
*Private
,
471 QEMU_VIDEO_PRIVATE_DATA
*Private
,
478 QEMU_VIDEO_PRIVATE_DATA
*Private
,
484 QEMU_VIDEO_PRIVATE_DATA
*Private
,
490 QemuVideoCirrusModeSetup (
491 QEMU_VIDEO_PRIVATE_DATA
*Private
495 QemuVideoBochsModeSetup (
496 QEMU_VIDEO_PRIVATE_DATA
*Private