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