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