]> git.proxmox.com Git - mirror_edk2.git/blob - OvmfPkg/QemuVideoDxe/Qemu.h
f294901fa6a14c6140d05241989f3b29c849aa4b
[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_VARIANT;
93
94 typedef struct {
95 UINT16 VendorId;
96 UINT16 DeviceId;
97 QEMU_VIDEO_VARIANT Variant;
98 CHAR16 *Name;
99 } QEMU_VIDEO_CARD;
100
101 typedef struct {
102 UINT64 Signature;
103 EFI_HANDLE Handle;
104 EFI_PCI_IO_PROTOCOL *PciIo;
105 UINT64 OriginalPciAttributes;
106 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
107 EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
108 UINTN CurrentMode;
109 UINTN MaxMode;
110 QEMU_VIDEO_MODE_DATA *ModeData;
111 UINT8 *LineBuffer;
112 BOOLEAN HardwareNeedsStarting;
113 QEMU_VIDEO_VARIANT Variant;
114 } QEMU_VIDEO_PRIVATE_DATA;
115
116 ///
117 /// Video Mode structure
118 ///
119 typedef struct {
120 UINT32 Width;
121 UINT32 Height;
122 UINT32 ColorDepth;
123 UINT32 RefreshRate;
124 UINT8 *CrtcSettings;
125 UINT16 *SeqSettings;
126 UINT8 MiscSetting;
127 } QEMU_VIDEO_CIRRUS_MODES;
128
129 #define QEMU_VIDEO_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
130 CR(a, QEMU_VIDEO_PRIVATE_DATA, GraphicsOutput, QEMU_VIDEO_PRIVATE_DATA_SIGNATURE)
131
132
133 //
134 // Global Variables
135 //
136 extern UINT8 AttributeController[];
137 extern UINT8 GraphicsController[];
138 extern UINT8 Crtc_640_480_256_60[];
139 extern UINT16 Seq_640_480_256_60[];
140 extern UINT8 Crtc_800_600_256_60[];
141 extern UINT16 Seq_800_600_256_60[];
142 extern UINT8 Crtc_1024_768_256_60[];
143 extern UINT16 Seq_1024_768_256_60[];
144 extern QEMU_VIDEO_CIRRUS_MODES QemuVideoCirrusModes[];
145 extern EFI_DRIVER_BINDING_PROTOCOL gQemuVideoDriverBinding;
146 extern EFI_COMPONENT_NAME_PROTOCOL gQemuVideoComponentName;
147 extern EFI_COMPONENT_NAME2_PROTOCOL gQemuVideoComponentName2;
148 extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gQemuVideoDriverSupportedEfiVersion;
149
150 //
151 // Io Registers defined by VGA
152 //
153 #define CRTC_ADDRESS_REGISTER 0x3d4
154 #define CRTC_DATA_REGISTER 0x3d5
155 #define SEQ_ADDRESS_REGISTER 0x3c4
156 #define SEQ_DATA_REGISTER 0x3c5
157 #define GRAPH_ADDRESS_REGISTER 0x3ce
158 #define GRAPH_DATA_REGISTER 0x3cf
159 #define ATT_ADDRESS_REGISTER 0x3c0
160 #define MISC_OUTPUT_REGISTER 0x3c2
161 #define INPUT_STATUS_1_REGISTER 0x3da
162 #define DAC_PIXEL_MASK_REGISTER 0x3c6
163 #define PALETTE_INDEX_REGISTER 0x3c8
164 #define PALETTE_DATA_REGISTER 0x3c9
165
166
167 //
168 // Graphics Output Hardware abstraction internal worker functions
169 //
170 EFI_STATUS
171 QemuVideoGraphicsOutputConstructor (
172 QEMU_VIDEO_PRIVATE_DATA *Private
173 );
174
175 EFI_STATUS
176 QemuVideoGraphicsOutputDestructor (
177 QEMU_VIDEO_PRIVATE_DATA *Private
178 );
179
180
181 //
182 // EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
183 //
184 /**
185 TODO: Add function description
186
187 @param This TODO: add argument description
188 @param Controller TODO: add argument description
189 @param RemainingDevicePath TODO: add argument description
190
191 TODO: add return values
192
193 **/
194 EFI_STATUS
195 EFIAPI
196 QemuVideoControllerDriverSupported (
197 IN EFI_DRIVER_BINDING_PROTOCOL *This,
198 IN EFI_HANDLE Controller,
199 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
200 );
201
202 /**
203 TODO: Add function description
204
205 @param This TODO: add argument description
206 @param Controller TODO: add argument description
207 @param RemainingDevicePath TODO: add argument description
208
209 TODO: add return values
210
211 **/
212 EFI_STATUS
213 EFIAPI
214 QemuVideoControllerDriverStart (
215 IN EFI_DRIVER_BINDING_PROTOCOL *This,
216 IN EFI_HANDLE Controller,
217 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
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 NumberOfChildren TODO: add argument description
226 @param ChildHandleBuffer TODO: add argument description
227
228 TODO: add return values
229
230 **/
231 EFI_STATUS
232 EFIAPI
233 QemuVideoControllerDriverStop (
234 IN EFI_DRIVER_BINDING_PROTOCOL *This,
235 IN EFI_HANDLE Controller,
236 IN UINTN NumberOfChildren,
237 IN EFI_HANDLE *ChildHandleBuffer
238 );
239
240 //
241 // EFI Component Name Functions
242 //
243 /**
244 Retrieves a Unicode string that is the user readable name of the driver.
245
246 This function retrieves the user readable name of a driver in the form of a
247 Unicode string. If the driver specified by This has a user readable name in
248 the language specified by Language, then a pointer to the driver name is
249 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
250 by This does not support the language specified by Language,
251 then EFI_UNSUPPORTED is returned.
252
253 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
254 EFI_COMPONENT_NAME_PROTOCOL instance.
255
256 @param Language[in] A pointer to a Null-terminated ASCII string
257 array indicating the language. This is the
258 language of the driver name that the caller is
259 requesting, and it must match one of the
260 languages specified in SupportedLanguages. The
261 number of languages supported by a driver is up
262 to the driver writer. Language is specified
263 in RFC 4646 or ISO 639-2 language code format.
264
265 @param DriverName[out] A pointer to the Unicode string to return.
266 This Unicode string is the name of the
267 driver specified by This in the language
268 specified by Language.
269
270 @retval EFI_SUCCESS The Unicode string for the Driver specified by
271 This and the language specified by Language was
272 returned in DriverName.
273
274 @retval EFI_INVALID_PARAMETER Language is NULL.
275
276 @retval EFI_INVALID_PARAMETER DriverName is NULL.
277
278 @retval EFI_UNSUPPORTED The driver specified by This does not support
279 the language specified by Language.
280
281 **/
282 EFI_STATUS
283 EFIAPI
284 QemuVideoComponentNameGetDriverName (
285 IN EFI_COMPONENT_NAME_PROTOCOL *This,
286 IN CHAR8 *Language,
287 OUT CHAR16 **DriverName
288 );
289
290
291 /**
292 Retrieves a Unicode string that is the user readable name of the controller
293 that is being managed by a driver.
294
295 This function retrieves the user readable name of the controller specified by
296 ControllerHandle and ChildHandle in the form of a Unicode string. If the
297 driver specified by This has a user readable name in the language specified by
298 Language, then a pointer to the controller name is returned in ControllerName,
299 and EFI_SUCCESS is returned. If the driver specified by This is not currently
300 managing the controller specified by ControllerHandle and ChildHandle,
301 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
302 support the language specified by Language, then EFI_UNSUPPORTED is returned.
303
304 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
305 EFI_COMPONENT_NAME_PROTOCOL instance.
306
307 @param ControllerHandle[in] The handle of a controller that the driver
308 specified by This is managing. This handle
309 specifies the controller whose name is to be
310 returned.
311
312 @param ChildHandle[in] The handle of the child controller to retrieve
313 the name of. This is an optional parameter that
314 may be NULL. It will be NULL for device
315 drivers. It will also be NULL for a bus drivers
316 that wish to retrieve the name of the bus
317 controller. It will not be NULL for a bus
318 driver that wishes to retrieve the name of a
319 child controller.
320
321 @param Language[in] A pointer to a Null-terminated ASCII string
322 array indicating the language. This is the
323 language of the driver name that the caller is
324 requesting, and it must match one of the
325 languages specified in SupportedLanguages. The
326 number of languages supported by a driver is up
327 to the driver writer. Language is specified in
328 RFC 4646 or ISO 639-2 language code format.
329
330 @param ControllerName[out] A pointer to the Unicode string to return.
331 This Unicode string is the name of the
332 controller specified by ControllerHandle and
333 ChildHandle in the language specified by
334 Language from the point of view of the driver
335 specified by This.
336
337 @retval EFI_SUCCESS The Unicode string for the user readable name in
338 the language specified by Language for the
339 driver specified by This was returned in
340 DriverName.
341
342 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
343
344 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
345 EFI_HANDLE.
346
347 @retval EFI_INVALID_PARAMETER Language is NULL.
348
349 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
350
351 @retval EFI_UNSUPPORTED The driver specified by This is not currently
352 managing the controller specified by
353 ControllerHandle and ChildHandle.
354
355 @retval EFI_UNSUPPORTED The driver specified by This does not support
356 the language specified by Language.
357
358 **/
359 EFI_STATUS
360 EFIAPI
361 QemuVideoComponentNameGetControllerName (
362 IN EFI_COMPONENT_NAME_PROTOCOL *This,
363 IN EFI_HANDLE ControllerHandle,
364 IN EFI_HANDLE ChildHandle OPTIONAL,
365 IN CHAR8 *Language,
366 OUT CHAR16 **ControllerName
367 );
368
369
370 //
371 // Local Function Prototypes
372 //
373 VOID
374 InitializeCirrusGraphicsMode (
375 QEMU_VIDEO_PRIVATE_DATA *Private,
376 QEMU_VIDEO_CIRRUS_MODES *ModeData
377 );
378
379 VOID
380 SetPaletteColor (
381 QEMU_VIDEO_PRIVATE_DATA *Private,
382 UINTN Index,
383 UINT8 Red,
384 UINT8 Green,
385 UINT8 Blue
386 );
387
388 VOID
389 SetDefaultPalette (
390 QEMU_VIDEO_PRIVATE_DATA *Private
391 );
392
393 VOID
394 DrawLogo (
395 QEMU_VIDEO_PRIVATE_DATA *Private,
396 UINTN ScreenWidth,
397 UINTN ScreenHeight
398 );
399
400 VOID
401 outb (
402 QEMU_VIDEO_PRIVATE_DATA *Private,
403 UINTN Address,
404 UINT8 Data
405 );
406
407 VOID
408 outw (
409 QEMU_VIDEO_PRIVATE_DATA *Private,
410 UINTN Address,
411 UINT16 Data
412 );
413
414 UINT8
415 inb (
416 QEMU_VIDEO_PRIVATE_DATA *Private,
417 UINTN Address
418 );
419
420 UINT16
421 inw (
422 QEMU_VIDEO_PRIVATE_DATA *Private,
423 UINTN Address
424 );
425
426 EFI_STATUS
427 QemuVideoCirrusModeSetup (
428 QEMU_VIDEO_PRIVATE_DATA *Private
429 );
430
431 #endif