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
,
97 QEMU_VIDEO_VARIANT Variant
;
104 EFI_PCI_IO_PROTOCOL
*PciIo
;
105 UINT64 OriginalPciAttributes
;
106 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput
;
107 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
110 QEMU_VIDEO_MODE_DATA
*ModeData
;
112 BOOLEAN HardwareNeedsStarting
;
113 QEMU_VIDEO_VARIANT Variant
;
114 } QEMU_VIDEO_PRIVATE_DATA
;
117 /// Video Mode structure
127 } QEMU_VIDEO_CIRRUS_MODES
;
129 #define QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
130 CR(a, QEMU_VIDEO_PRIVATE_DATA, GraphicsOutput, QEMU_VIDEO_PRIVATE_DATA_SIGNATURE)
136 extern UINT8 AttributeController
[];
137 extern UINT8 GraphicsController
[];
138 extern UINT8 Crtc_640_480_256_60
[];
139 extern UINT16 Seq_640_480_256_60
[];
140 extern UINT8 Crtc_800_600_256_60
[];
141 extern UINT16 Seq_800_600_256_60
[];
142 extern UINT8 Crtc_1024_768_256_60
[];
143 extern UINT16 Seq_1024_768_256_60
[];
144 extern QEMU_VIDEO_CIRRUS_MODES QemuVideoCirrusModes
[];
145 extern EFI_DRIVER_BINDING_PROTOCOL gQemuVideoDriverBinding
;
146 extern EFI_COMPONENT_NAME_PROTOCOL gQemuVideoComponentName
;
147 extern EFI_COMPONENT_NAME2_PROTOCOL gQemuVideoComponentName2
;
148 extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gQemuVideoDriverSupportedEfiVersion
;
151 // Io Registers defined by VGA
153 #define CRTC_ADDRESS_REGISTER 0x3d4
154 #define CRTC_DATA_REGISTER 0x3d5
155 #define SEQ_ADDRESS_REGISTER 0x3c4
156 #define SEQ_DATA_REGISTER 0x3c5
157 #define GRAPH_ADDRESS_REGISTER 0x3ce
158 #define GRAPH_DATA_REGISTER 0x3cf
159 #define ATT_ADDRESS_REGISTER 0x3c0
160 #define MISC_OUTPUT_REGISTER 0x3c2
161 #define INPUT_STATUS_1_REGISTER 0x3da
162 #define DAC_PIXEL_MASK_REGISTER 0x3c6
163 #define PALETTE_INDEX_REGISTER 0x3c8
164 #define PALETTE_DATA_REGISTER 0x3c9
168 // Graphics Output Hardware abstraction internal worker functions
171 QemuVideoGraphicsOutputConstructor (
172 QEMU_VIDEO_PRIVATE_DATA
*Private
176 QemuVideoGraphicsOutputDestructor (
177 QEMU_VIDEO_PRIVATE_DATA
*Private
182 // EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
185 TODO: Add function description
187 @param This TODO: add argument description
188 @param Controller TODO: add argument description
189 @param RemainingDevicePath TODO: add argument description
191 TODO: add return values
196 QemuVideoControllerDriverSupported (
197 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
198 IN EFI_HANDLE Controller
,
199 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
203 TODO: Add function description
205 @param This TODO: add argument description
206 @param Controller TODO: add argument description
207 @param RemainingDevicePath TODO: add argument description
209 TODO: add return values
214 QemuVideoControllerDriverStart (
215 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
216 IN EFI_HANDLE Controller
,
217 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
221 TODO: Add function description
223 @param This TODO: add argument description
224 @param Controller TODO: add argument description
225 @param NumberOfChildren TODO: add argument description
226 @param ChildHandleBuffer TODO: add argument description
228 TODO: add return values
233 QemuVideoControllerDriverStop (
234 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
235 IN EFI_HANDLE Controller
,
236 IN UINTN NumberOfChildren
,
237 IN EFI_HANDLE
*ChildHandleBuffer
241 // EFI Component Name Functions
244 Retrieves a Unicode string that is the user readable name of the driver.
246 This function retrieves the user readable name of a driver in the form of a
247 Unicode string. If the driver specified by This has a user readable name in
248 the language specified by Language, then a pointer to the driver name is
249 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
250 by This does not support the language specified by Language,
251 then EFI_UNSUPPORTED is returned.
253 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
254 EFI_COMPONENT_NAME_PROTOCOL instance.
256 @param Language[in] A pointer to a Null-terminated ASCII string
257 array indicating the language. This is the
258 language of the driver name that the caller is
259 requesting, and it must match one of the
260 languages specified in SupportedLanguages. The
261 number of languages supported by a driver is up
262 to the driver writer. Language is specified
263 in RFC 4646 or ISO 639-2 language code format.
265 @param DriverName[out] A pointer to the Unicode string to return.
266 This Unicode string is the name of the
267 driver specified by This in the language
268 specified by Language.
270 @retval EFI_SUCCESS The Unicode string for the Driver specified by
271 This and the language specified by Language was
272 returned in DriverName.
274 @retval EFI_INVALID_PARAMETER Language is NULL.
276 @retval EFI_INVALID_PARAMETER DriverName is NULL.
278 @retval EFI_UNSUPPORTED The driver specified by This does not support
279 the language specified by Language.
284 QemuVideoComponentNameGetDriverName (
285 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
287 OUT CHAR16
**DriverName
292 Retrieves a Unicode string that is the user readable name of the controller
293 that is being managed by a driver.
295 This function retrieves the user readable name of the controller specified by
296 ControllerHandle and ChildHandle in the form of a Unicode string. If the
297 driver specified by This has a user readable name in the language specified by
298 Language, then a pointer to the controller name is returned in ControllerName,
299 and EFI_SUCCESS is returned. If the driver specified by This is not currently
300 managing the controller specified by ControllerHandle and ChildHandle,
301 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
302 support the language specified by Language, then EFI_UNSUPPORTED is returned.
304 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
305 EFI_COMPONENT_NAME_PROTOCOL instance.
307 @param ControllerHandle[in] The handle of a controller that the driver
308 specified by This is managing. This handle
309 specifies the controller whose name is to be
312 @param ChildHandle[in] The handle of the child controller to retrieve
313 the name of. This is an optional parameter that
314 may be NULL. It will be NULL for device
315 drivers. It will also be NULL for a bus drivers
316 that wish to retrieve the name of the bus
317 controller. It will not be NULL for a bus
318 driver that wishes to retrieve the name of a
321 @param Language[in] A pointer to a Null-terminated ASCII string
322 array indicating the language. This is the
323 language of the driver name that the caller is
324 requesting, and it must match one of the
325 languages specified in SupportedLanguages. The
326 number of languages supported by a driver is up
327 to the driver writer. Language is specified in
328 RFC 4646 or ISO 639-2 language code format.
330 @param ControllerName[out] A pointer to the Unicode string to return.
331 This Unicode string is the name of the
332 controller specified by ControllerHandle and
333 ChildHandle in the language specified by
334 Language from the point of view of the driver
337 @retval EFI_SUCCESS The Unicode string for the user readable name in
338 the language specified by Language for the
339 driver specified by This was returned in
342 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
344 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
347 @retval EFI_INVALID_PARAMETER Language is NULL.
349 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
351 @retval EFI_UNSUPPORTED The driver specified by This is not currently
352 managing the controller specified by
353 ControllerHandle and ChildHandle.
355 @retval EFI_UNSUPPORTED The driver specified by This does not support
356 the language specified by Language.
361 QemuVideoComponentNameGetControllerName (
362 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
363 IN EFI_HANDLE ControllerHandle
,
364 IN EFI_HANDLE ChildHandle OPTIONAL
,
366 OUT CHAR16
**ControllerName
371 // Local Function Prototypes
374 InitializeCirrusGraphicsMode (
375 QEMU_VIDEO_PRIVATE_DATA
*Private
,
376 QEMU_VIDEO_CIRRUS_MODES
*ModeData
381 QEMU_VIDEO_PRIVATE_DATA
*Private
,
390 QEMU_VIDEO_PRIVATE_DATA
*Private
395 QEMU_VIDEO_PRIVATE_DATA
*Private
,
402 QEMU_VIDEO_PRIVATE_DATA
*Private
,
409 QEMU_VIDEO_PRIVATE_DATA
*Private
,
416 QEMU_VIDEO_PRIVATE_DATA
*Private
,
422 QEMU_VIDEO_PRIVATE_DATA
*Private
,
427 QemuVideoCirrusModeSetup (
428 QEMU_VIDEO_PRIVATE_DATA
*Private