1 | /** @file
|
---|
2 | QEMU Video Controller Driver
|
---|
3 |
|
---|
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
|
---|
9 |
|
---|
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.
|
---|
12 |
|
---|
13 | **/
|
---|
14 |
|
---|
15 | //
|
---|
16 | // QEMU Video Controller Driver
|
---|
17 | //
|
---|
18 |
|
---|
19 | #ifndef _QEMU_H_
|
---|
20 | #define _QEMU_H_
|
---|
21 |
|
---|
22 |
|
---|
23 | #include <Uefi.h>
|
---|
24 | #include <Protocol/GraphicsOutput.h>
|
---|
25 | #include <Protocol/PciIo.h>
|
---|
26 | #include <Protocol/DriverSupportedEfiVersion.h>
|
---|
27 | #include <Protocol/DevicePath.h>
|
---|
28 |
|
---|
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>
|
---|
38 |
|
---|
39 | #include <IndustryStandard/Pci.h>
|
---|
40 |
|
---|
41 | //
|
---|
42 | // QEMU Video PCI Configuration Header values
|
---|
43 | //
|
---|
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
|
---|
48 |
|
---|
49 | //
|
---|
50 | // QEMU Vide Graphical Mode Data
|
---|
51 | //
|
---|
52 | typedef struct {
|
---|
53 | UINT32 ModeNumber;
|
---|
54 | UINT32 HorizontalResolution;
|
---|
55 | UINT32 VerticalResolution;
|
---|
56 | UINT32 ColorDepth;
|
---|
57 | UINT32 RefreshRate;
|
---|
58 | } QEMU_VIDEO_MODE_DATA;
|
---|
59 |
|
---|
60 | #define PIXEL_RED_SHIFT 0
|
---|
61 | #define PIXEL_GREEN_SHIFT 3
|
---|
62 | #define PIXEL_BLUE_SHIFT 6
|
---|
63 |
|
---|
64 | #define PIXEL_RED_MASK (BIT7 | BIT6 | BIT5)
|
---|
65 | #define PIXEL_GREEN_MASK (BIT4 | BIT3 | BIT2)
|
---|
66 | #define PIXEL_BLUE_MASK (BIT1 | BIT0)
|
---|
67 |
|
---|
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)
|
---|
72 |
|
---|
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) )
|
---|
77 |
|
---|
78 | #define PIXEL24_RED_MASK 0x00ff0000
|
---|
79 | #define PIXEL24_GREEN_MASK 0x0000ff00
|
---|
80 | #define PIXEL24_BLUE_MASK 0x000000ff
|
---|
81 |
|
---|
82 | #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
|
---|
83 |
|
---|
84 | //
|
---|
85 | // QEMU Video Private Data Structure
|
---|
86 | //
|
---|
87 | #define QEMU_VIDEO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('Q', 'V', 'I', 'D')
|
---|
88 |
|
---|
89 | typedef struct {
|
---|
90 | UINT64 Signature;
|
---|
91 | EFI_HANDLE Handle;
|
---|
92 | EFI_PCI_IO_PROTOCOL *PciIo;
|
---|
93 | UINT64 OriginalPciAttributes;
|
---|
94 | EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
|
---|
95 | EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
|
---|
96 | UINTN CurrentMode;
|
---|
97 | UINTN MaxMode;
|
---|
98 | QEMU_VIDEO_MODE_DATA *ModeData;
|
---|
99 | UINT8 *LineBuffer;
|
---|
100 | BOOLEAN HardwareNeedsStarting;
|
---|
101 | } QEMU_VIDEO_PRIVATE_DATA;
|
---|
102 |
|
---|
103 | ///
|
---|
104 | /// Video Mode structure
|
---|
105 | ///
|
---|
106 | typedef struct {
|
---|
107 | UINT32 Width;
|
---|
108 | UINT32 Height;
|
---|
109 | UINT32 ColorDepth;
|
---|
110 | UINT32 RefreshRate;
|
---|
111 | UINT8 *CrtcSettings;
|
---|
112 | UINT16 *SeqSettings;
|
---|
113 | UINT8 MiscSetting;
|
---|
114 | } QEMU_VIDEO_VIDEO_MODES;
|
---|
115 |
|
---|
116 | #define QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
|
---|
117 | CR(a, QEMU_VIDEO_PRIVATE_DATA, GraphicsOutput, QEMU_VIDEO_PRIVATE_DATA_SIGNATURE)
|
---|
118 |
|
---|
119 |
|
---|
120 | //
|
---|
121 | // Global Variables
|
---|
122 | //
|
---|
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;
|
---|
136 |
|
---|
137 | //
|
---|
138 | // Io Registers defined by VGA
|
---|
139 | //
|
---|
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
|
---|
152 |
|
---|
153 |
|
---|
154 | //
|
---|
155 | // Graphics Output Hardware abstraction internal worker functions
|
---|
156 | //
|
---|
157 | EFI_STATUS
|
---|
158 | QemuVideoGraphicsOutputConstructor (
|
---|
159 | QEMU_VIDEO_PRIVATE_DATA *Private
|
---|
160 | );
|
---|
161 |
|
---|
162 | EFI_STATUS
|
---|
163 | QemuVideoGraphicsOutputDestructor (
|
---|
164 | QEMU_VIDEO_PRIVATE_DATA *Private
|
---|
165 | );
|
---|
166 |
|
---|
167 |
|
---|
168 | //
|
---|
169 | // EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
|
---|
170 | //
|
---|
171 | /**
|
---|
172 | TODO: Add function description
|
---|
173 |
|
---|
174 | @param This TODO: add argument description
|
---|
175 | @param Controller TODO: add argument description
|
---|
176 | @param RemainingDevicePath TODO: add argument description
|
---|
177 |
|
---|
178 | TODO: add return values
|
---|
179 |
|
---|
180 | **/
|
---|
181 | EFI_STATUS
|
---|
182 | EFIAPI
|
---|
183 | QemuVideoControllerDriverSupported (
|
---|
184 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
185 | IN EFI_HANDLE Controller,
|
---|
186 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
---|
187 | );
|
---|
188 |
|
---|
189 | /**
|
---|
190 | TODO: Add function description
|
---|
191 |
|
---|
192 | @param This TODO: add argument description
|
---|
193 | @param Controller TODO: add argument description
|
---|
194 | @param RemainingDevicePath TODO: add argument description
|
---|
195 |
|
---|
196 | TODO: add return values
|
---|
197 |
|
---|
198 | **/
|
---|
199 | EFI_STATUS
|
---|
200 | EFIAPI
|
---|
201 | QemuVideoControllerDriverStart (
|
---|
202 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
203 | IN EFI_HANDLE Controller,
|
---|
204 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
---|
205 | );
|
---|
206 |
|
---|
207 | /**
|
---|
208 | TODO: Add function description
|
---|
209 |
|
---|
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
|
---|
214 |
|
---|
215 | TODO: add return values
|
---|
216 |
|
---|
217 | **/
|
---|
218 | EFI_STATUS
|
---|
219 | EFIAPI
|
---|
220 | QemuVideoControllerDriverStop (
|
---|
221 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
222 | IN EFI_HANDLE Controller,
|
---|
223 | IN UINTN NumberOfChildren,
|
---|
224 | IN EFI_HANDLE *ChildHandleBuffer
|
---|
225 | );
|
---|
226 |
|
---|
227 | //
|
---|
228 | // EFI Component Name Functions
|
---|
229 | //
|
---|
230 | /**
|
---|
231 | Retrieves a Unicode string that is the user readable name of the driver.
|
---|
232 |
|
---|
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.
|
---|
239 |
|
---|
240 | @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
|
---|
241 | EFI_COMPONENT_NAME_PROTOCOL instance.
|
---|
242 |
|
---|
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.
|
---|
251 |
|
---|
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.
|
---|
256 |
|
---|
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.
|
---|
260 |
|
---|
261 | @retval EFI_INVALID_PARAMETER Language is NULL.
|
---|
262 |
|
---|
263 | @retval EFI_INVALID_PARAMETER DriverName is NULL.
|
---|
264 |
|
---|
265 | @retval EFI_UNSUPPORTED The driver specified by This does not support
|
---|
266 | the language specified by Language.
|
---|
267 |
|
---|
268 | **/
|
---|
269 | EFI_STATUS
|
---|
270 | EFIAPI
|
---|
271 | QemuVideoComponentNameGetDriverName (
|
---|
272 | IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
---|
273 | IN CHAR8 *Language,
|
---|
274 | OUT CHAR16 **DriverName
|
---|
275 | );
|
---|
276 |
|
---|
277 |
|
---|
278 | /**
|
---|
279 | Retrieves a Unicode string that is the user readable name of the controller
|
---|
280 | that is being managed by a driver.
|
---|
281 |
|
---|
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.
|
---|
290 |
|
---|
291 | @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
|
---|
292 | EFI_COMPONENT_NAME_PROTOCOL instance.
|
---|
293 |
|
---|
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
|
---|
297 | returned.
|
---|
298 |
|
---|
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
|
---|
306 | child controller.
|
---|
307 |
|
---|
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.
|
---|
316 |
|
---|
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
|
---|
322 | specified by This.
|
---|
323 |
|
---|
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
|
---|
327 | DriverName.
|
---|
328 |
|
---|
329 | @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
|
---|
330 |
|
---|
331 | @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
|
---|
332 | EFI_HANDLE.
|
---|
333 |
|
---|
334 | @retval EFI_INVALID_PARAMETER Language is NULL.
|
---|
335 |
|
---|
336 | @retval EFI_INVALID_PARAMETER ControllerName is NULL.
|
---|
337 |
|
---|
338 | @retval EFI_UNSUPPORTED The driver specified by This is not currently
|
---|
339 | managing the controller specified by
|
---|
340 | ControllerHandle and ChildHandle.
|
---|
341 |
|
---|
342 | @retval EFI_UNSUPPORTED The driver specified by This does not support
|
---|
343 | the language specified by Language.
|
---|
344 |
|
---|
345 | **/
|
---|
346 | EFI_STATUS
|
---|
347 | EFIAPI
|
---|
348 | QemuVideoComponentNameGetControllerName (
|
---|
349 | IN EFI_COMPONENT_NAME_PROTOCOL *This,
|
---|
350 | IN EFI_HANDLE ControllerHandle,
|
---|
351 | IN EFI_HANDLE ChildHandle OPTIONAL,
|
---|
352 | IN CHAR8 *Language,
|
---|
353 | OUT CHAR16 **ControllerName
|
---|
354 | );
|
---|
355 |
|
---|
356 |
|
---|
357 | //
|
---|
358 | // Local Function Prototypes
|
---|
359 | //
|
---|
360 | VOID
|
---|
361 | InitializeGraphicsMode (
|
---|
362 | QEMU_VIDEO_PRIVATE_DATA *Private,
|
---|
363 | QEMU_VIDEO_VIDEO_MODES *ModeData
|
---|
364 | );
|
---|
365 |
|
---|
366 | VOID
|
---|
367 | SetPaletteColor (
|
---|
368 | QEMU_VIDEO_PRIVATE_DATA *Private,
|
---|
369 | UINTN Index,
|
---|
370 | UINT8 Red,
|
---|
371 | UINT8 Green,
|
---|
372 | UINT8 Blue
|
---|
373 | );
|
---|
374 |
|
---|
375 | VOID
|
---|
376 | SetDefaultPalette (
|
---|
377 | QEMU_VIDEO_PRIVATE_DATA *Private
|
---|
378 | );
|
---|
379 |
|
---|
380 | VOID
|
---|
381 | DrawLogo (
|
---|
382 | QEMU_VIDEO_PRIVATE_DATA *Private,
|
---|
383 | UINTN ScreenWidth,
|
---|
384 | UINTN ScreenHeight
|
---|
385 | );
|
---|
386 |
|
---|
387 | VOID
|
---|
388 | outb (
|
---|
389 | QEMU_VIDEO_PRIVATE_DATA *Private,
|
---|
390 | UINTN Address,
|
---|
391 | UINT8 Data
|
---|
392 | );
|
---|
393 |
|
---|
394 | VOID
|
---|
395 | outw (
|
---|
396 | QEMU_VIDEO_PRIVATE_DATA *Private,
|
---|
397 | UINTN Address,
|
---|
398 | UINT16 Data
|
---|
399 | );
|
---|
400 |
|
---|
401 | UINT8
|
---|
402 | inb (
|
---|
403 | QEMU_VIDEO_PRIVATE_DATA *Private,
|
---|
404 | UINTN Address
|
---|
405 | );
|
---|
406 |
|
---|
407 | UINT16
|
---|
408 | inw (
|
---|
409 | QEMU_VIDEO_PRIVATE_DATA *Private,
|
---|
410 | UINTN Address
|
---|
411 | );
|
---|
412 |
|
---|
413 | EFI_STATUS
|
---|
414 | QemuVideoVideoModeSetup (
|
---|
415 | QEMU_VIDEO_PRIVATE_DATA *Private
|
---|
416 | );
|
---|
417 |
|
---|
418 | #endif
|
---|