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