]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/QemuVideoDxe/Qemu.h
OvmfPkg/QemuVideoDxe: VMWare SVGA device support
[mirror_edk2.git] / OvmfPkg / QemuVideoDxe / Qemu.h
1 /** @file
2 QEMU Video Controller Driver
3
4 Copyright (c) 2006 - 2016, 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 #include <Library/FrameBufferBltLib.h>
39
40 #include <IndustryStandard/Pci.h>
41 #include <IndustryStandard/Acpi.h>
42
43 //
44 // QEMU Video PCI Configuration Header values
45 //
46 #define CIRRUS_LOGIC_VENDOR_ID 0x1013
47 #define CIRRUS_LOGIC_5430_DEVICE_ID 0x00a8
48 #define CIRRUS_LOGIC_5430_ALTERNATE_DEVICE_ID 0x00a0
49 #define CIRRUS_LOGIC_5446_DEVICE_ID 0x00b8
50
51 //
52 // QEMU Vide Graphical Mode Data
53 //
54 typedef struct {
55 UINT32 InternalModeIndex; // points into card-specific mode table
56 UINT32 HorizontalResolution;
57 UINT32 VerticalResolution;
58 UINT32 ColorDepth;
59 } QEMU_VIDEO_MODE_DATA;
60
61 #define PIXEL_RED_SHIFT 0
62 #define PIXEL_GREEN_SHIFT 3
63 #define PIXEL_BLUE_SHIFT 6
64
65 #define PIXEL_RED_MASK (BIT7 | BIT6 | BIT5)
66 #define PIXEL_GREEN_MASK (BIT4 | BIT3 | BIT2)
67 #define PIXEL_BLUE_MASK (BIT1 | BIT0)
68
69 #define PIXEL_TO_COLOR_BYTE(pixel, mask, shift) ((UINT8) ((pixel & mask) << shift))
70 #define PIXEL_TO_RED_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_RED_MASK, PIXEL_RED_SHIFT)
71 #define PIXEL_TO_GREEN_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_GREEN_MASK, PIXEL_GREEN_SHIFT)
72 #define PIXEL_TO_BLUE_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_BLUE_MASK, PIXEL_BLUE_SHIFT)
73
74 #define RGB_BYTES_TO_PIXEL(Red, Green, Blue) \
75 (UINT8) ( (((Red) >> PIXEL_RED_SHIFT) & PIXEL_RED_MASK) | \
76 (((Green) >> PIXEL_GREEN_SHIFT) & PIXEL_GREEN_MASK) | \
77 (((Blue) >> PIXEL_BLUE_SHIFT) & PIXEL_BLUE_MASK) )
78
79 #define PIXEL24_RED_MASK 0x00ff0000
80 #define PIXEL24_GREEN_MASK 0x0000ff00
81 #define PIXEL24_BLUE_MASK 0x000000ff
82
83 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
84
85 //
86 // QEMU Video Private Data Structure
87 //
88 #define QEMU_VIDEO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('Q', 'V', 'I', 'D')
89
90 typedef enum {
91 QEMU_VIDEO_CIRRUS_5430 = 1,
92 QEMU_VIDEO_CIRRUS_5446,
93 QEMU_VIDEO_BOCHS,
94 QEMU_VIDEO_BOCHS_MMIO,
95 QEMU_VIDEO_VMWARE_SVGA,
96 } QEMU_VIDEO_VARIANT;
97
98 typedef struct {
99 UINT16 VendorId;
100 UINT16 DeviceId;
101 QEMU_VIDEO_VARIANT Variant;
102 CHAR16 *Name;
103 } QEMU_VIDEO_CARD;
104
105 typedef struct {
106 UINT64 Signature;
107 EFI_HANDLE Handle;
108 EFI_PCI_IO_PROTOCOL *PciIo;
109 UINT64 OriginalPciAttributes;
110 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
111 EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
112
113 //
114 // The next two fields match the client-visible
115 // EFI_GRAPHICS_OUTPUT_PROTOCOL_MODE.MaxMode field.
116 //
117 UINTN MaxMode;
118 QEMU_VIDEO_MODE_DATA *ModeData;
119 EFI_GRAPHICS_OUTPUT_MODE_INFORMATION *VmwareSvgaModeInfo;
120
121 QEMU_VIDEO_VARIANT Variant;
122 FRAME_BUFFER_CONFIGURE *FrameBufferBltConfigure;
123 UINTN FrameBufferBltConfigureSize;
124 UINT8 FrameBufferVramBarIndex;
125 UINT16 VmwareSvgaBasePort;
126 } QEMU_VIDEO_PRIVATE_DATA;
127
128 ///
129 /// Card-specific Video Mode structures
130 ///
131 typedef struct {
132 UINT32 Width;
133 UINT32 Height;
134 UINT32 ColorDepth;
135 UINT8 *CrtcSettings;
136 UINT16 *SeqSettings;
137 UINT8 MiscSetting;
138 } QEMU_VIDEO_CIRRUS_MODES;
139
140 typedef struct {
141 UINT32 Width;
142 UINT32 Height;
143 UINT32 ColorDepth;
144 } QEMU_VIDEO_BOCHS_MODES;
145
146 #define QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
147 CR(a, QEMU_VIDEO_PRIVATE_DATA, GraphicsOutput, QEMU_VIDEO_PRIVATE_DATA_SIGNATURE)
148
149
150 //
151 // Global Variables
152 //
153 extern UINT8 AttributeController[];
154 extern UINT8 GraphicsController[];
155 extern UINT8 Crtc_640_480_256_60[];
156 extern UINT16 Seq_640_480_256_60[];
157 extern UINT8 Crtc_800_600_256_60[];
158 extern UINT16 Seq_800_600_256_60[];
159 extern UINT8 Crtc_1024_768_256_60[];
160 extern UINT16 Seq_1024_768_256_60[];
161 extern QEMU_VIDEO_CIRRUS_MODES QemuVideoCirrusModes[];
162 extern QEMU_VIDEO_BOCHS_MODES QemuVideoBochsModes[];
163 extern EFI_DRIVER_BINDING_PROTOCOL gQemuVideoDriverBinding;
164 extern EFI_COMPONENT_NAME_PROTOCOL gQemuVideoComponentName;
165 extern EFI_COMPONENT_NAME2_PROTOCOL gQemuVideoComponentName2;
166 extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gQemuVideoDriverSupportedEfiVersion;
167
168 //
169 // Io Registers defined by VGA
170 //
171 #define CRTC_ADDRESS_REGISTER 0x3d4
172 #define CRTC_DATA_REGISTER 0x3d5
173 #define SEQ_ADDRESS_REGISTER 0x3c4
174 #define SEQ_DATA_REGISTER 0x3c5
175 #define GRAPH_ADDRESS_REGISTER 0x3ce
176 #define GRAPH_DATA_REGISTER 0x3cf
177 #define ATT_ADDRESS_REGISTER 0x3c0
178 #define MISC_OUTPUT_REGISTER 0x3c2
179 #define INPUT_STATUS_1_REGISTER 0x3da
180 #define DAC_PIXEL_MASK_REGISTER 0x3c6
181 #define PALETTE_INDEX_REGISTER 0x3c8
182 #define PALETTE_DATA_REGISTER 0x3c9
183
184 #define VBE_DISPI_IOPORT_INDEX 0x01CE
185 #define VBE_DISPI_IOPORT_DATA 0x01D0
186
187 #define VBE_DISPI_INDEX_ID 0x0
188 #define VBE_DISPI_INDEX_XRES 0x1
189 #define VBE_DISPI_INDEX_YRES 0x2
190 #define VBE_DISPI_INDEX_BPP 0x3
191 #define VBE_DISPI_INDEX_ENABLE 0x4
192 #define VBE_DISPI_INDEX_BANK 0x5
193 #define VBE_DISPI_INDEX_VIRT_WIDTH 0x6
194 #define VBE_DISPI_INDEX_VIRT_HEIGHT 0x7
195 #define VBE_DISPI_INDEX_X_OFFSET 0x8
196 #define VBE_DISPI_INDEX_Y_OFFSET 0x9
197 #define VBE_DISPI_INDEX_VIDEO_MEMORY_64K 0xa
198
199 #define VBE_DISPI_ID0 0xB0C0
200 #define VBE_DISPI_ID1 0xB0C1
201 #define VBE_DISPI_ID2 0xB0C2
202 #define VBE_DISPI_ID3 0xB0C3
203 #define VBE_DISPI_ID4 0xB0C4
204 #define VBE_DISPI_ID5 0xB0C5
205
206 #define VBE_DISPI_DISABLED 0x00
207 #define VBE_DISPI_ENABLED 0x01
208 #define VBE_DISPI_GETCAPS 0x02
209 #define VBE_DISPI_8BIT_DAC 0x20
210 #define VBE_DISPI_LFB_ENABLED 0x40
211 #define VBE_DISPI_NOCLEARMEM 0x80
212
213 //
214 // Graphics Output Hardware abstraction internal worker functions
215 //
216 EFI_STATUS
217 QemuVideoGraphicsOutputConstructor (
218 QEMU_VIDEO_PRIVATE_DATA *Private
219 );
220
221 EFI_STATUS
222 QemuVideoGraphicsOutputDestructor (
223 QEMU_VIDEO_PRIVATE_DATA *Private
224 );
225
226
227 //
228 // EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
229 //
230 /**
231 TODO: Add function description
232
233 @param This TODO: add argument description
234 @param Controller TODO: add argument description
235 @param RemainingDevicePath TODO: add argument description
236
237 TODO: add return values
238
239 **/
240 EFI_STATUS
241 EFIAPI
242 QemuVideoControllerDriverSupported (
243 IN EFI_DRIVER_BINDING_PROTOCOL *This,
244 IN EFI_HANDLE Controller,
245 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
246 );
247
248 /**
249 TODO: Add function description
250
251 @param This TODO: add argument description
252 @param Controller TODO: add argument description
253 @param RemainingDevicePath TODO: add argument description
254
255 TODO: add return values
256
257 **/
258 EFI_STATUS
259 EFIAPI
260 QemuVideoControllerDriverStart (
261 IN EFI_DRIVER_BINDING_PROTOCOL *This,
262 IN EFI_HANDLE Controller,
263 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
264 );
265
266 /**
267 TODO: Add function description
268
269 @param This TODO: add argument description
270 @param Controller TODO: add argument description
271 @param NumberOfChildren TODO: add argument description
272 @param ChildHandleBuffer TODO: add argument description
273
274 TODO: add return values
275
276 **/
277 EFI_STATUS
278 EFIAPI
279 QemuVideoControllerDriverStop (
280 IN EFI_DRIVER_BINDING_PROTOCOL *This,
281 IN EFI_HANDLE Controller,
282 IN UINTN NumberOfChildren,
283 IN EFI_HANDLE *ChildHandleBuffer
284 );
285
286 //
287 // EFI Component Name Functions
288 //
289 /**
290 Retrieves a Unicode string that is the user readable name of the driver.
291
292 This function retrieves the user readable name of a driver in the form of a
293 Unicode string. If the driver specified by This has a user readable name in
294 the language specified by Language, then a pointer to the driver name is
295 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
296 by This does not support the language specified by Language,
297 then EFI_UNSUPPORTED is returned.
298
299 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
300 EFI_COMPONENT_NAME_PROTOCOL instance.
301
302 @param Language[in] A pointer to a Null-terminated ASCII string
303 array indicating the language. This is the
304 language of the driver name that the caller is
305 requesting, and it must match one of the
306 languages specified in SupportedLanguages. The
307 number of languages supported by a driver is up
308 to the driver writer. Language is specified
309 in RFC 4646 or ISO 639-2 language code format.
310
311 @param DriverName[out] A pointer to the Unicode string to return.
312 This Unicode string is the name of the
313 driver specified by This in the language
314 specified by Language.
315
316 @retval EFI_SUCCESS The Unicode string for the Driver specified by
317 This and the language specified by Language was
318 returned in DriverName.
319
320 @retval EFI_INVALID_PARAMETER Language is NULL.
321
322 @retval EFI_INVALID_PARAMETER DriverName is NULL.
323
324 @retval EFI_UNSUPPORTED The driver specified by This does not support
325 the language specified by Language.
326
327 **/
328 EFI_STATUS
329 EFIAPI
330 QemuVideoComponentNameGetDriverName (
331 IN EFI_COMPONENT_NAME_PROTOCOL *This,
332 IN CHAR8 *Language,
333 OUT CHAR16 **DriverName
334 );
335
336
337 /**
338 Retrieves a Unicode string that is the user readable name of the controller
339 that is being managed by a driver.
340
341 This function retrieves the user readable name of the controller specified by
342 ControllerHandle and ChildHandle in the form of a Unicode string. If the
343 driver specified by This has a user readable name in the language specified by
344 Language, then a pointer to the controller name is returned in ControllerName,
345 and EFI_SUCCESS is returned. If the driver specified by This is not currently
346 managing the controller specified by ControllerHandle and ChildHandle,
347 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
348 support the language specified by Language, then EFI_UNSUPPORTED is returned.
349
350 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
351 EFI_COMPONENT_NAME_PROTOCOL instance.
352
353 @param ControllerHandle[in] The handle of a controller that the driver
354 specified by This is managing. This handle
355 specifies the controller whose name is to be
356 returned.
357
358 @param ChildHandle[in] The handle of the child controller to retrieve
359 the name of. This is an optional parameter that
360 may be NULL. It will be NULL for device
361 drivers. It will also be NULL for a bus drivers
362 that wish to retrieve the name of the bus
363 controller. It will not be NULL for a bus
364 driver that wishes to retrieve the name of a
365 child controller.
366
367 @param Language[in] A pointer to a Null-terminated ASCII string
368 array indicating the language. This is the
369 language of the driver name that the caller is
370 requesting, and it must match one of the
371 languages specified in SupportedLanguages. The
372 number of languages supported by a driver is up
373 to the driver writer. Language is specified in
374 RFC 4646 or ISO 639-2 language code format.
375
376 @param ControllerName[out] A pointer to the Unicode string to return.
377 This Unicode string is the name of the
378 controller specified by ControllerHandle and
379 ChildHandle in the language specified by
380 Language from the point of view of the driver
381 specified by This.
382
383 @retval EFI_SUCCESS The Unicode string for the user readable name in
384 the language specified by Language for the
385 driver specified by This was returned in
386 DriverName.
387
388 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
389
390 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
391 EFI_HANDLE.
392
393 @retval EFI_INVALID_PARAMETER Language is NULL.
394
395 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
396
397 @retval EFI_UNSUPPORTED The driver specified by This is not currently
398 managing the controller specified by
399 ControllerHandle and ChildHandle.
400
401 @retval EFI_UNSUPPORTED The driver specified by This does not support
402 the language specified by Language.
403
404 **/
405 EFI_STATUS
406 EFIAPI
407 QemuVideoComponentNameGetControllerName (
408 IN EFI_COMPONENT_NAME_PROTOCOL *This,
409 IN EFI_HANDLE ControllerHandle,
410 IN EFI_HANDLE ChildHandle OPTIONAL,
411 IN CHAR8 *Language,
412 OUT CHAR16 **ControllerName
413 );
414
415
416 //
417 // Local Function Prototypes
418 //
419 VOID
420 InitializeCirrusGraphicsMode (
421 QEMU_VIDEO_PRIVATE_DATA *Private,
422 QEMU_VIDEO_CIRRUS_MODES *ModeData
423 );
424
425 VOID
426 InitializeBochsGraphicsMode (
427 QEMU_VIDEO_PRIVATE_DATA *Private,
428 QEMU_VIDEO_BOCHS_MODES *ModeData
429 );
430
431 VOID
432 SetPaletteColor (
433 QEMU_VIDEO_PRIVATE_DATA *Private,
434 UINTN Index,
435 UINT8 Red,
436 UINT8 Green,
437 UINT8 Blue
438 );
439
440 VOID
441 SetDefaultPalette (
442 QEMU_VIDEO_PRIVATE_DATA *Private
443 );
444
445 VOID
446 DrawLogo (
447 QEMU_VIDEO_PRIVATE_DATA *Private,
448 UINTN ScreenWidth,
449 UINTN ScreenHeight
450 );
451
452 VOID
453 outb (
454 QEMU_VIDEO_PRIVATE_DATA *Private,
455 UINTN Address,
456 UINT8 Data
457 );
458
459 VOID
460 outw (
461 QEMU_VIDEO_PRIVATE_DATA *Private,
462 UINTN Address,
463 UINT16 Data
464 );
465
466 UINT8
467 inb (
468 QEMU_VIDEO_PRIVATE_DATA *Private,
469 UINTN Address
470 );
471
472 UINT16
473 inw (
474 QEMU_VIDEO_PRIVATE_DATA *Private,
475 UINTN Address
476 );
477
478 VOID
479 BochsWrite (
480 QEMU_VIDEO_PRIVATE_DATA *Private,
481 UINT16 Reg,
482 UINT16 Data
483 );
484
485 UINT16
486 BochsRead (
487 QEMU_VIDEO_PRIVATE_DATA *Private,
488 UINT16 Reg
489 );
490
491 VOID
492 VgaOutb (
493 QEMU_VIDEO_PRIVATE_DATA *Private,
494 UINTN Reg,
495 UINT8 Data
496 );
497
498 EFI_STATUS
499 QemuVideoCirrusModeSetup (
500 QEMU_VIDEO_PRIVATE_DATA *Private
501 );
502
503 EFI_STATUS
504 QemuVideoBochsModeSetup (
505 QEMU_VIDEO_PRIVATE_DATA *Private,
506 BOOLEAN IsQxl
507 );
508
509 EFI_STATUS
510 QemuVideoVmwareSvgaModeSetup (
511 QEMU_VIDEO_PRIVATE_DATA *Private
512 );
513
514 VOID
515 InstallVbeShim (
516 IN CONST CHAR16 *CardName,
517 IN EFI_PHYSICAL_ADDRESS FrameBufferBase
518 );
519
520 VOID
521 VmwareSvgaWrite (
522 QEMU_VIDEO_PRIVATE_DATA *Private,
523 UINT16 Register,
524 UINT32 Value
525 );
526
527 UINT32
528 VmwareSvgaRead (
529 QEMU_VIDEO_PRIVATE_DATA *Private,
530 UINT16 Register
531 );
532
533 VOID
534 InitializeVmwareSvgaGraphicsMode (
535 QEMU_VIDEO_PRIVATE_DATA *Private,
536 QEMU_VIDEO_BOCHS_MODES *ModeData
537 );
538
539 #endif