]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/QemuVideoDxe/Qemu.h
QemuVideo: Add support for the bochs dispi interface
[mirror_edk2.git] / OvmfPkg / QemuVideoDxe / Qemu.h
1 /** @file
2 QEMU Video Controller Driver
3
4 Copyright (c) 2006 - 2010, 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
39 #include <IndustryStandard/Pci.h>
40
41 //
42 // QEMU Video PCI Configuration Header values
43 //
44 #define CIRRUS_LOGIC_VENDOR_ID 0x1013
45 #define CIRRUS_LOGIC_5430_DEVICE_ID 0x00a8
46 #define CIRRUS_LOGIC_5430_ALTERNATE_DEVICE_ID 0x00a0
47 #define CIRRUS_LOGIC_5446_DEVICE_ID 0x00b8
48
49 //
50 // QEMU Vide Graphical Mode Data
51 //
52 typedef struct {
53 UINT32 ModeNumber;
54 UINT32 HorizontalResolution;
55 UINT32 VerticalResolution;
56 UINT32 ColorDepth;
57 UINT32 RefreshRate;
58 } QEMU_VIDEO_MODE_DATA;
59
60 #define PIXEL_RED_SHIFT 0
61 #define PIXEL_GREEN_SHIFT 3
62 #define PIXEL_BLUE_SHIFT 6
63
64 #define PIXEL_RED_MASK (BIT7 | BIT6 | BIT5)
65 #define PIXEL_GREEN_MASK (BIT4 | BIT3 | BIT2)
66 #define PIXEL_BLUE_MASK (BIT1 | BIT0)
67
68 #define PIXEL_TO_COLOR_BYTE(pixel, mask, shift) ((UINT8) ((pixel & mask) << shift))
69 #define PIXEL_TO_RED_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_RED_MASK, PIXEL_RED_SHIFT)
70 #define PIXEL_TO_GREEN_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_GREEN_MASK, PIXEL_GREEN_SHIFT)
71 #define PIXEL_TO_BLUE_BYTE(pixel) PIXEL_TO_COLOR_BYTE(pixel, PIXEL_BLUE_MASK, PIXEL_BLUE_SHIFT)
72
73 #define RGB_BYTES_TO_PIXEL(Red, Green, Blue) \
74 (UINT8) ( (((Red) >> PIXEL_RED_SHIFT) & PIXEL_RED_MASK) | \
75 (((Green) >> PIXEL_GREEN_SHIFT) & PIXEL_GREEN_MASK) | \
76 (((Blue) >> PIXEL_BLUE_SHIFT) & PIXEL_BLUE_MASK) )
77
78 #define PIXEL24_RED_MASK 0x00ff0000
79 #define PIXEL24_GREEN_MASK 0x0000ff00
80 #define PIXEL24_BLUE_MASK 0x000000ff
81
82 #define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
83
84 //
85 // QEMU Video Private Data Structure
86 //
87 #define QEMU_VIDEO_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('Q', 'V', 'I', 'D')
88
89 typedef enum {
90 QEMU_VIDEO_CIRRUS_5430 = 1,
91 QEMU_VIDEO_CIRRUS_5446,
92 QEMU_VIDEO_BOCHS,
93 } QEMU_VIDEO_VARIANT;
94
95 typedef struct {
96 UINT16 VendorId;
97 UINT16 DeviceId;
98 QEMU_VIDEO_VARIANT Variant;
99 CHAR16 *Name;
100 } QEMU_VIDEO_CARD;
101
102 typedef struct {
103 UINT64 Signature;
104 EFI_HANDLE Handle;
105 EFI_PCI_IO_PROTOCOL *PciIo;
106 UINT64 OriginalPciAttributes;
107 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
108 EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
109 UINTN CurrentMode;
110 UINTN MaxMode;
111 QEMU_VIDEO_MODE_DATA *ModeData;
112 UINT8 *LineBuffer;
113 BOOLEAN HardwareNeedsStarting;
114 QEMU_VIDEO_VARIANT Variant;
115 } QEMU_VIDEO_PRIVATE_DATA;
116
117 ///
118 /// Video Mode structure
119 ///
120 typedef struct {
121 UINT32 Width;
122 UINT32 Height;
123 UINT32 ColorDepth;
124 UINT32 RefreshRate;
125 UINT8 *CrtcSettings;
126 UINT16 *SeqSettings;
127 UINT8 MiscSetting;
128 } QEMU_VIDEO_CIRRUS_MODES;
129
130 typedef struct {
131 UINT32 Width;
132 UINT32 Height;
133 UINT32 ColorDepth;
134 } QEMU_VIDEO_BOCHS_MODES;
135
136 #define QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
137 CR(a, QEMU_VIDEO_PRIVATE_DATA, GraphicsOutput, QEMU_VIDEO_PRIVATE_DATA_SIGNATURE)
138
139
140 //
141 // Global Variables
142 //
143 extern UINT8 AttributeController[];
144 extern UINT8 GraphicsController[];
145 extern UINT8 Crtc_640_480_256_60[];
146 extern UINT16 Seq_640_480_256_60[];
147 extern UINT8 Crtc_800_600_256_60[];
148 extern UINT16 Seq_800_600_256_60[];
149 extern UINT8 Crtc_1024_768_256_60[];
150 extern UINT16 Seq_1024_768_256_60[];
151 extern QEMU_VIDEO_CIRRUS_MODES QemuVideoCirrusModes[];
152 extern QEMU_VIDEO_BOCHS_MODES QemuVideoBochsModes[];
153 extern EFI_DRIVER_BINDING_PROTOCOL gQemuVideoDriverBinding;
154 extern EFI_COMPONENT_NAME_PROTOCOL gQemuVideoComponentName;
155 extern EFI_COMPONENT_NAME2_PROTOCOL gQemuVideoComponentName2;
156 extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gQemuVideoDriverSupportedEfiVersion;
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 //
206 EFI_STATUS
207 QemuVideoGraphicsOutputConstructor (
208 QEMU_VIDEO_PRIVATE_DATA *Private
209 );
210
211 EFI_STATUS
212 QemuVideoGraphicsOutputDestructor (
213 QEMU_VIDEO_PRIVATE_DATA *Private
214 );
215
216
217 //
218 // EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
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 **/
230 EFI_STATUS
231 EFIAPI
232 QemuVideoControllerDriverSupported (
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 **/
248 EFI_STATUS
249 EFIAPI
250 QemuVideoControllerDriverStart (
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 **/
267 EFI_STATUS
268 EFIAPI
269 QemuVideoControllerDriverStop (
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 Retrieves a Unicode string that is the user readable name of the driver.
281
282 This function retrieves the user readable name of a driver in the form of a
283 Unicode string. If the driver specified by This has a user readable name in
284 the language specified by Language, then a pointer to the driver name is
285 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
286 by This does not support the language specified by Language,
287 then EFI_UNSUPPORTED is returned.
288
289 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
290 EFI_COMPONENT_NAME_PROTOCOL instance.
291
292 @param Language[in] A pointer to a Null-terminated ASCII string
293 array indicating the language. This is the
294 language of the driver name that the caller is
295 requesting, and it must match one of the
296 languages specified in SupportedLanguages. The
297 number of languages supported by a driver is up
298 to the driver writer. Language is specified
299 in RFC 4646 or ISO 639-2 language code format.
300
301 @param DriverName[out] A pointer to the Unicode string to return.
302 This Unicode string is the name of the
303 driver specified by This in the language
304 specified by Language.
305
306 @retval EFI_SUCCESS The Unicode string for the Driver specified by
307 This and the language specified by Language was
308 returned in DriverName.
309
310 @retval EFI_INVALID_PARAMETER Language is NULL.
311
312 @retval EFI_INVALID_PARAMETER DriverName is NULL.
313
314 @retval EFI_UNSUPPORTED The driver specified by This does not support
315 the language specified by Language.
316
317 **/
318 EFI_STATUS
319 EFIAPI
320 QemuVideoComponentNameGetDriverName (
321 IN EFI_COMPONENT_NAME_PROTOCOL *This,
322 IN CHAR8 *Language,
323 OUT CHAR16 **DriverName
324 );
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 **/
395 EFI_STATUS
396 EFIAPI
397 QemuVideoComponentNameGetControllerName (
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 //
407 // Local Function Prototypes
408 //
409 VOID
410 InitializeCirrusGraphicsMode (
411 QEMU_VIDEO_PRIVATE_DATA *Private,
412 QEMU_VIDEO_CIRRUS_MODES *ModeData
413 );
414
415 VOID
416 InitializeBochsGraphicsMode (
417 QEMU_VIDEO_PRIVATE_DATA *Private,
418 QEMU_VIDEO_BOCHS_MODES *ModeData
419 );
420
421 VOID
422 SetPaletteColor (
423 QEMU_VIDEO_PRIVATE_DATA *Private,
424 UINTN Index,
425 UINT8 Red,
426 UINT8 Green,
427 UINT8 Blue
428 );
429
430 VOID
431 SetDefaultPalette (
432 QEMU_VIDEO_PRIVATE_DATA *Private
433 );
434
435 VOID
436 DrawLogo (
437 QEMU_VIDEO_PRIVATE_DATA *Private,
438 UINTN ScreenWidth,
439 UINTN ScreenHeight
440 );
441
442 VOID
443 outb (
444 QEMU_VIDEO_PRIVATE_DATA *Private,
445 UINTN Address,
446 UINT8 Data
447 );
448
449 VOID
450 outw (
451 QEMU_VIDEO_PRIVATE_DATA *Private,
452 UINTN Address,
453 UINT16 Data
454 );
455
456 UINT8
457 inb (
458 QEMU_VIDEO_PRIVATE_DATA *Private,
459 UINTN Address
460 );
461
462 UINT16
463 inw (
464 QEMU_VIDEO_PRIVATE_DATA *Private,
465 UINTN Address
466 );
467
468 VOID
469 BochsWrite (
470 QEMU_VIDEO_PRIVATE_DATA *Private,
471 UINT16 Reg,
472 UINT16 Data
473 );
474
475 UINT16
476 BochsRead (
477 QEMU_VIDEO_PRIVATE_DATA *Private,
478 UINT16 Reg
479 );
480
481 EFI_STATUS
482 QemuVideoCirrusModeSetup (
483 QEMU_VIDEO_PRIVATE_DATA *Private
484 );
485
486 EFI_STATUS
487 QemuVideoBochsModeSetup (
488 QEMU_VIDEO_PRIVATE_DATA *Private
489 );
490
491 #endif