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')
92 EFI_PCI_IO_PROTOCOL
*PciIo
;
93 UINT64 OriginalPciAttributes
;
94 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput
;
95 EFI_DEVICE_PATH_PROTOCOL
*GopDevicePath
;
98 QEMU_VIDEO_MODE_DATA
*ModeData
;
100 BOOLEAN HardwareNeedsStarting
;
101 } QEMU_VIDEO_PRIVATE_DATA
;
104 /// Video Mode structure
114 } QEMU_VIDEO_VIDEO_MODES
;
116 #define QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
117 CR(a, QEMU_VIDEO_PRIVATE_DATA, GraphicsOutput, QEMU_VIDEO_PRIVATE_DATA_SIGNATURE)
123 extern UINT8 AttributeController
[];
124 extern UINT8 GraphicsController
[];
125 extern UINT8 Crtc_640_480_256_60
[];
126 extern UINT16 Seq_640_480_256_60
[];
127 extern UINT8 Crtc_800_600_256_60
[];
128 extern UINT16 Seq_800_600_256_60
[];
129 extern UINT8 Crtc_1024_768_256_60
[];
130 extern UINT16 Seq_1024_768_256_60
[];
131 extern QEMU_VIDEO_VIDEO_MODES QemuVideoVideoModes
[];
132 extern EFI_DRIVER_BINDING_PROTOCOL gQemuVideoDriverBinding
;
133 extern EFI_COMPONENT_NAME_PROTOCOL gQemuVideoComponentName
;
134 extern EFI_COMPONENT_NAME2_PROTOCOL gQemuVideoComponentName2
;
135 extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gQemuVideoDriverSupportedEfiVersion
;
138 // Io Registers defined by VGA
140 #define CRTC_ADDRESS_REGISTER 0x3d4
141 #define CRTC_DATA_REGISTER 0x3d5
142 #define SEQ_ADDRESS_REGISTER 0x3c4
143 #define SEQ_DATA_REGISTER 0x3c5
144 #define GRAPH_ADDRESS_REGISTER 0x3ce
145 #define GRAPH_DATA_REGISTER 0x3cf
146 #define ATT_ADDRESS_REGISTER 0x3c0
147 #define MISC_OUTPUT_REGISTER 0x3c2
148 #define INPUT_STATUS_1_REGISTER 0x3da
149 #define DAC_PIXEL_MASK_REGISTER 0x3c6
150 #define PALETTE_INDEX_REGISTER 0x3c8
151 #define PALETTE_DATA_REGISTER 0x3c9
155 // Graphics Output Hardware abstraction internal worker functions
158 QemuVideoGraphicsOutputConstructor (
159 QEMU_VIDEO_PRIVATE_DATA
*Private
163 QemuVideoGraphicsOutputDestructor (
164 QEMU_VIDEO_PRIVATE_DATA
*Private
169 // EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
172 TODO: Add function description
174 @param This TODO: add argument description
175 @param Controller TODO: add argument description
176 @param RemainingDevicePath TODO: add argument description
178 TODO: add return values
183 QemuVideoControllerDriverSupported (
184 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
185 IN EFI_HANDLE Controller
,
186 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
190 TODO: Add function description
192 @param This TODO: add argument description
193 @param Controller TODO: add argument description
194 @param RemainingDevicePath TODO: add argument description
196 TODO: add return values
201 QemuVideoControllerDriverStart (
202 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
203 IN EFI_HANDLE Controller
,
204 IN EFI_DEVICE_PATH_PROTOCOL
*RemainingDevicePath
208 TODO: Add function description
210 @param This TODO: add argument description
211 @param Controller TODO: add argument description
212 @param NumberOfChildren TODO: add argument description
213 @param ChildHandleBuffer TODO: add argument description
215 TODO: add return values
220 QemuVideoControllerDriverStop (
221 IN EFI_DRIVER_BINDING_PROTOCOL
*This
,
222 IN EFI_HANDLE Controller
,
223 IN UINTN NumberOfChildren
,
224 IN EFI_HANDLE
*ChildHandleBuffer
228 // EFI Component Name Functions
231 Retrieves a Unicode string that is the user readable name of the driver.
233 This function retrieves the user readable name of a driver in the form of a
234 Unicode string. If the driver specified by This has a user readable name in
235 the language specified by Language, then a pointer to the driver name is
236 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
237 by This does not support the language specified by Language,
238 then EFI_UNSUPPORTED is returned.
240 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
241 EFI_COMPONENT_NAME_PROTOCOL instance.
243 @param Language[in] A pointer to a Null-terminated ASCII string
244 array indicating the language. This is the
245 language of the driver name that the caller is
246 requesting, and it must match one of the
247 languages specified in SupportedLanguages. The
248 number of languages supported by a driver is up
249 to the driver writer. Language is specified
250 in RFC 4646 or ISO 639-2 language code format.
252 @param DriverName[out] A pointer to the Unicode string to return.
253 This Unicode string is the name of the
254 driver specified by This in the language
255 specified by Language.
257 @retval EFI_SUCCESS The Unicode string for the Driver specified by
258 This and the language specified by Language was
259 returned in DriverName.
261 @retval EFI_INVALID_PARAMETER Language is NULL.
263 @retval EFI_INVALID_PARAMETER DriverName is NULL.
265 @retval EFI_UNSUPPORTED The driver specified by This does not support
266 the language specified by Language.
271 QemuVideoComponentNameGetDriverName (
272 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
274 OUT CHAR16
**DriverName
279 Retrieves a Unicode string that is the user readable name of the controller
280 that is being managed by a driver.
282 This function retrieves the user readable name of the controller specified by
283 ControllerHandle and ChildHandle in the form of a Unicode string. If the
284 driver specified by This has a user readable name in the language specified by
285 Language, then a pointer to the controller name is returned in ControllerName,
286 and EFI_SUCCESS is returned. If the driver specified by This is not currently
287 managing the controller specified by ControllerHandle and ChildHandle,
288 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
289 support the language specified by Language, then EFI_UNSUPPORTED is returned.
291 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
292 EFI_COMPONENT_NAME_PROTOCOL instance.
294 @param ControllerHandle[in] The handle of a controller that the driver
295 specified by This is managing. This handle
296 specifies the controller whose name is to be
299 @param ChildHandle[in] The handle of the child controller to retrieve
300 the name of. This is an optional parameter that
301 may be NULL. It will be NULL for device
302 drivers. It will also be NULL for a bus drivers
303 that wish to retrieve the name of the bus
304 controller. It will not be NULL for a bus
305 driver that wishes to retrieve the name of a
308 @param Language[in] A pointer to a Null-terminated ASCII string
309 array indicating the language. This is the
310 language of the driver name that the caller is
311 requesting, and it must match one of the
312 languages specified in SupportedLanguages. The
313 number of languages supported by a driver is up
314 to the driver writer. Language is specified in
315 RFC 4646 or ISO 639-2 language code format.
317 @param ControllerName[out] A pointer to the Unicode string to return.
318 This Unicode string is the name of the
319 controller specified by ControllerHandle and
320 ChildHandle in the language specified by
321 Language from the point of view of the driver
324 @retval EFI_SUCCESS The Unicode string for the user readable name in
325 the language specified by Language for the
326 driver specified by This was returned in
329 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
331 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
334 @retval EFI_INVALID_PARAMETER Language is NULL.
336 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
338 @retval EFI_UNSUPPORTED The driver specified by This is not currently
339 managing the controller specified by
340 ControllerHandle and ChildHandle.
342 @retval EFI_UNSUPPORTED The driver specified by This does not support
343 the language specified by Language.
348 QemuVideoComponentNameGetControllerName (
349 IN EFI_COMPONENT_NAME_PROTOCOL
*This
,
350 IN EFI_HANDLE ControllerHandle
,
351 IN EFI_HANDLE ChildHandle OPTIONAL
,
353 OUT CHAR16
**ControllerName
358 // Local Function Prototypes
361 InitializeGraphicsMode (
362 QEMU_VIDEO_PRIVATE_DATA
*Private
,
363 QEMU_VIDEO_VIDEO_MODES
*ModeData
368 QEMU_VIDEO_PRIVATE_DATA
*Private
,
377 QEMU_VIDEO_PRIVATE_DATA
*Private
382 QEMU_VIDEO_PRIVATE_DATA
*Private
,
389 QEMU_VIDEO_PRIVATE_DATA
*Private
,
396 QEMU_VIDEO_PRIVATE_DATA
*Private
,
403 QEMU_VIDEO_PRIVATE_DATA
*Private
,
409 QEMU_VIDEO_PRIVATE_DATA
*Private
,
414 QemuVideoVideoModeSetup (
415 QEMU_VIDEO_PRIVATE_DATA
*Private