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