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