VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/OvmfPkg/QemuVideoDxe/Qemu.h@ 106129

Last change on this file since 106129 was 99404, checked in by vboxsync, 20 months ago

Devices/EFI/FirmwareNew: Update to edk2-stable202302 and make it build, bugref:4643

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette