VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxVgaDxe/VBoxVga.h@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 16.0 KB
Line 
1/* $Id: VBoxVga.h 96407 2022-08-22 17:43:14Z vboxsync $ */
2/** @file
3 * VBoxVga.h
4 */
5
6/*
7 * Copyright (C) 2009-2022 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * The contents of this file may alternatively be used under the terms
26 * of the Common Development and Distribution License Version 1.0
27 * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
28 * in the VirtualBox distribution, in which case the provisions of the
29 * CDDL are applicable instead of those of the GPL.
30 *
31 * You may elect to license modified versions of this file under the
32 * terms and conditions of either the GPL or the CDDL or both.
33 *
34 * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
35 */
36
37/*
38 This code is based on:
39
40 Cirrus Logic 5430 Controller Driver
41
42 Copyright (c) 2006 - 2007, Intel Corporation
43 All rights reserved. This program and the accompanying materials
44 are licensed and made available under the terms and conditions of the BSD License
45 which accompanies this distribution. The full text of the license may be found at
46 http://opensource.org/licenses/bsd-license.php
47
48 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
49 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
50
51*/
52
53//
54// VirtualBox VGA Controller Driver
55//
56
57#ifndef _VBOX_VGA_H_
58#define _VBOX_VGA_H_
59
60
61#include <Uefi.h>
62#include <Protocol/UgaDraw.h>
63#include <Protocol/GraphicsOutput.h>
64#include <Protocol/PciIo.h>
65#include <Protocol/DriverSupportedEfiVersion.h>
66#include <Protocol/EdidOverride.h>
67#include <Protocol/EdidDiscovered.h>
68#include <Protocol/EdidActive.h>
69#include <Protocol/DevicePath.h>
70
71#include <Library/DebugLib.h>
72#include <Library/UefiDriverEntryPoint.h>
73#include <Library/UefiLib.h>
74#include <Library/PcdLib.h>
75#include <Library/MemoryAllocationLib.h>
76#include <Library/UefiBootServicesTableLib.h>
77#include <Library/BaseMemoryLib.h>
78#include <Library/DevicePathLib.h>
79#include <Library/TimerLib.h>
80
81#include <IndustryStandard/Pci.h>
82
83#include "VBoxPkg.h"
84#include "DevEFI.h"
85#include "VBox/Graphics/VBoxVideoVBE.h"
86#include "VBox/Graphics/VBoxVideoVBEPrivate.h"
87
88//
89// VirtualBox VGA PCI Configuration Header values
90//
91#define VBOX_VENDOR_ID 0x80ee
92#define VBOX_VGA_DEVICE_ID 0xbeef
93
94
95//
96// VMSVGA II PCI Configuration Header values
97//
98#define VMSVGA_VENDOR_ID 0x15ad
99#define VMSVGA_II_DEVICE_ID 0x0405
100
101// Port offsets relative to BAR 0
102#define SVGA_INDEX_PORT 0
103#define SVGA_VALUE_PORT 1
104
105// SVGA_REG_ENABLE bits
106#define SVGA_REG_ENABLE_DISABLE 0
107#define SVGA_REG_ENABLE_ENABLE 1
108
109// Registers
110#define SVGA_REG_ENABLE 1
111#define SVGA_REG_WIDTH 2
112#define SVGA_REG_HEIGHT 3
113#define SVGA_REG_MAX_WIDTH 4
114#define SVGA_REG_MAX_HEIGHT 5
115#define SVGA_REG_DEPTH 6
116#define SVGA_REG_BITS_PER_PIXEL 7
117#define SVGA_REG_BYTES_PER_LINE 12
118#define SVGA_REG_FB_START 13
119#define SVGA_REG_FB_OFFSET 14
120#define SVGA_REG_VRAM_SIZE 15
121#define SVGA_REG_CONFIG_DONE 20 ///@todo: Why do we need this?
122
123//
124// VirtualBox VGA Graphical Mode Data
125//
126typedef struct {
127 UINT32 ModeNumber;
128 UINT32 HorizontalResolution;
129 UINT32 VerticalResolution;
130 UINT32 ColorDepth;
131 UINT32 RefreshRate;
132} VBOX_VGA_MODE_DATA;
133
134#define GRAPHICS_OUTPUT_INVALIDE_MODE_NUMBER 0xffff
135
136//
137// VirtualBox VGA Private Data Structure
138//
139#define VBOX_VGA_PRIVATE_DATA_SIGNATURE SIGNATURE_32 ('V', 'B', 'V', 'D')
140
141typedef struct {
142 UINT64 Signature;
143 EFI_HANDLE Handle;
144 EFI_PCI_IO_PROTOCOL *PciIo;
145 UINT64 OriginalPciAttributes;
146 EFI_UGA_DRAW_PROTOCOL UgaDraw;
147 EFI_GRAPHICS_OUTPUT_PROTOCOL GraphicsOutput;
148 EFI_EDID_DISCOVERED_PROTOCOL EdidDiscovered;
149 EFI_EDID_ACTIVE_PROTOCOL EdidActive;
150 EFI_DEVICE_PATH_PROTOCOL *GopDevicePath;
151 EFI_DEVICE_PATH_PROTOCOL *UgaDevicePath;
152 UINTN CurrentMode;
153 UINTN MaxMode;
154 VBOX_VGA_MODE_DATA *ModeData;
155 BOOLEAN HardwareNeedsStarting;
156 UINT8 BarIndexFB;
157 UINT16 DeviceType;
158 UINT16 IOBase;
159 UINT32 VRAMSize;
160} VBOX_VGA_PRIVATE_DATA;
161
162///
163/// Video Mode structure
164///
165typedef struct {
166 UINT32 Width;
167 UINT32 Height;
168 UINT32 ColorDepth;
169 UINT32 RefreshRate;
170 /// CRTC settings are optional. If NULL then VBE is used
171 UINT8 *CrtcSettings;
172 /// Sequencer settings are optional. If NULL then defaults are used
173 UINT8 *SeqSettings;
174 UINT8 MiscSetting;
175} VBOX_VGA_VIDEO_MODES;
176
177#define VBOX_VGA_PRIVATE_DATA_FROM_UGA_DRAW_THIS(a) \
178 CR(a, VBOX_VGA_PRIVATE_DATA, UgaDraw, VBOX_VGA_PRIVATE_DATA_SIGNATURE)
179
180#define VBOX_VGA_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS(a) \
181 CR(a, VBOX_VGA_PRIVATE_DATA, GraphicsOutput, VBOX_VGA_PRIVATE_DATA_SIGNATURE)
182
183
184//
185// Global Variables
186//
187extern UINT8 AttributeController[];
188extern UINT8 GraphicsController[];
189extern UINT8 Crtc_640_480_256_60[];
190extern UINT8 Seq_640_480_256_60[];
191extern UINT8 Crtc_800_600_256_60[];
192extern UINT8 Seq_800_600_256_60[];
193extern UINT8 Crtc_1024_768_256_60[];
194extern UINT8 Seq_1024_768_256_60[];
195extern VBOX_VGA_VIDEO_MODES VBoxVgaVideoModes[];
196extern const UINT32 VBoxVgaVideoModeCount;
197extern EFI_DRIVER_BINDING_PROTOCOL gVBoxVgaDriverBinding;
198extern EFI_COMPONENT_NAME_PROTOCOL gVBoxVgaComponentName;
199extern EFI_COMPONENT_NAME2_PROTOCOL gVBoxVgaComponentName2;
200extern EFI_DRIVER_SUPPORTED_EFI_VERSION_PROTOCOL gVBoxVgaDriverSupportedEfiVersion;
201
202//
203// Io Registers defined by VGA
204//
205#define CRTC_ADDRESS_REGISTER 0x3d4
206#define CRTC_DATA_REGISTER 0x3d5
207#define SEQ_ADDRESS_REGISTER 0x3c4
208#define SEQ_DATA_REGISTER 0x3c5
209#define GRAPH_ADDRESS_REGISTER 0x3ce
210#define GRAPH_DATA_REGISTER 0x3cf
211#define ATT_ADDRESS_REGISTER 0x3c0
212#define ATT_DATA_REGISTER 0x3c1
213#define MISC_OUTPUT_REGISTER 0x3c2
214#define INPUT_STATUS_1_REGISTER 0x3da
215#define DAC_PIXEL_MASK_REGISTER 0x3c6
216#define PALETTE_INDEX_REGISTER 0x3c8
217#define PALETTE_DATA_REGISTER 0x3c9
218
219
220//
221// UGA Draw Hardware abstraction internal worker functions
222//
223EFI_STATUS
224VBoxVgaUgaDrawConstructor (
225 VBOX_VGA_PRIVATE_DATA *Private
226 );
227
228EFI_STATUS
229VBoxVgaUgaDrawDestructor (
230 VBOX_VGA_PRIVATE_DATA *Private
231 );
232
233//
234// Graphics Output Hardware abstraction internal worker functions
235//
236EFI_STATUS
237VBoxVgaGraphicsOutputConstructor (
238 VBOX_VGA_PRIVATE_DATA *Private
239 );
240
241EFI_STATUS
242VBoxVgaGraphicsOutputDestructor (
243 VBOX_VGA_PRIVATE_DATA *Private
244 );
245
246
247//
248// EFI_DRIVER_BINDING_PROTOCOL Protocol Interface
249//
250/**
251 TODO: Add function description
252
253 @param This TODO: add argument description
254 @param Controller TODO: add argument description
255 @param RemainingDevicePath TODO: add argument description
256
257 TODO: add return values
258
259**/
260EFI_STATUS
261EFIAPI
262VBoxVgaControllerDriverSupported (
263 IN EFI_DRIVER_BINDING_PROTOCOL *This,
264 IN EFI_HANDLE Controller,
265 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
266 );
267
268/**
269 TODO: Add function description
270
271 @param This TODO: add argument description
272 @param Controller TODO: add argument description
273 @param RemainingDevicePath TODO: add argument description
274
275 TODO: add return values
276
277**/
278EFI_STATUS
279EFIAPI
280VBoxVgaControllerDriverStart (
281 IN EFI_DRIVER_BINDING_PROTOCOL *This,
282 IN EFI_HANDLE Controller,
283 IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
284 );
285
286/**
287 TODO: Add function description
288
289 @param This TODO: add argument description
290 @param Controller TODO: add argument description
291 @param NumberOfChildren TODO: add argument description
292 @param ChildHandleBuffer TODO: add argument description
293
294 TODO: add return values
295
296**/
297EFI_STATUS
298EFIAPI
299VBoxVgaControllerDriverStop (
300 IN EFI_DRIVER_BINDING_PROTOCOL *This,
301 IN EFI_HANDLE Controller,
302 IN UINTN NumberOfChildren,
303 IN EFI_HANDLE *ChildHandleBuffer
304 );
305
306//
307// EFI Component Name Functions
308//
309/**
310 Retrieves a Unicode string that is the user readable name of the driver.
311
312 This function retrieves the user readable name of a driver in the form of a
313 Unicode string. If the driver specified by This has a user readable name in
314 the language specified by Language, then a pointer to the driver name is
315 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
316 by This does not support the language specified by Language,
317 then EFI_UNSUPPORTED is returned.
318
319 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
320 EFI_COMPONENT_NAME_PROTOCOL instance.
321
322 @param Language[in] A pointer to a Null-terminated ASCII string
323 array indicating the language. This is the
324 language of the driver name that the caller is
325 requesting, and it must match one of the
326 languages specified in SupportedLanguages. The
327 number of languages supported by a driver is up
328 to the driver writer. Language is specified
329 in RFC 4646 or ISO 639-2 language code format.
330
331 @param DriverName[out] A pointer to the Unicode string to return.
332 This Unicode string is the name of the
333 driver specified by This in the language
334 specified by Language.
335
336 @retval EFI_SUCCESS The Unicode string for the Driver specified by
337 This and the language specified by Language was
338 returned in DriverName.
339
340 @retval EFI_INVALID_PARAMETER Language is NULL.
341
342 @retval EFI_INVALID_PARAMETER DriverName is NULL.
343
344 @retval EFI_UNSUPPORTED The driver specified by This does not support
345 the language specified by Language.
346
347**/
348EFI_STATUS
349EFIAPI
350VBoxVgaComponentNameGetDriverName (
351 IN EFI_COMPONENT_NAME_PROTOCOL *This,
352 IN CHAR8 *Language,
353 OUT CHAR16 **DriverName
354 );
355
356
357/**
358 Retrieves a Unicode string that is the user readable name of the controller
359 that is being managed by a driver.
360
361 This function retrieves the user readable name of the controller specified by
362 ControllerHandle and ChildHandle in the form of a Unicode string. If the
363 driver specified by This has a user readable name in the language specified by
364 Language, then a pointer to the controller name is returned in ControllerName,
365 and EFI_SUCCESS is returned. If the driver specified by This is not currently
366 managing the controller specified by ControllerHandle and ChildHandle,
367 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
368 support the language specified by Language, then EFI_UNSUPPORTED is returned.
369
370 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
371 EFI_COMPONENT_NAME_PROTOCOL instance.
372
373 @param ControllerHandle[in] The handle of a controller that the driver
374 specified by This is managing. This handle
375 specifies the controller whose name is to be
376 returned.
377
378 @param ChildHandle[in] The handle of the child controller to retrieve
379 the name of. This is an optional parameter that
380 may be NULL. It will be NULL for device
381 drivers. It will also be NULL for a bus drivers
382 that wish to retrieve the name of the bus
383 controller. It will not be NULL for a bus
384 driver that wishes to retrieve the name of a
385 child controller.
386
387 @param Language[in] A pointer to a Null-terminated ASCII string
388 array indicating the language. This is the
389 language of the driver name that the caller is
390 requesting, and it must match one of the
391 languages specified in SupportedLanguages. The
392 number of languages supported by a driver is up
393 to the driver writer. Language is specified in
394 RFC 4646 or ISO 639-2 language code format.
395
396 @param ControllerName[out] A pointer to the Unicode string to return.
397 This Unicode string is the name of the
398 controller specified by ControllerHandle and
399 ChildHandle in the language specified by
400 Language from the point of view of the driver
401 specified by This.
402
403 @retval EFI_SUCCESS The Unicode string for the user readable name in
404 the language specified by Language for the
405 driver specified by This was returned in
406 DriverName.
407
408 @retval EFI_INVALID_PARAMETER ControllerHandle is not a valid EFI_HANDLE.
409
410 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
411 EFI_HANDLE.
412
413 @retval EFI_INVALID_PARAMETER Language is NULL.
414
415 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
416
417 @retval EFI_UNSUPPORTED The driver specified by This is not currently
418 managing the controller specified by
419 ControllerHandle and ChildHandle.
420
421 @retval EFI_UNSUPPORTED The driver specified by This does not support
422 the language specified by Language.
423
424**/
425EFI_STATUS
426EFIAPI
427VBoxVgaComponentNameGetControllerName (
428 IN EFI_COMPONENT_NAME_PROTOCOL *This,
429 IN EFI_HANDLE ControllerHandle,
430 IN EFI_HANDLE ChildHandle OPTIONAL,
431 IN CHAR8 *Language,
432 OUT CHAR16 **ControllerName
433 );
434
435
436//
437// Local Function Prototypes
438//
439VOID
440InitializeGraphicsMode (
441 VBOX_VGA_PRIVATE_DATA *Private,
442 VBOX_VGA_VIDEO_MODES *ModeData
443 );
444
445VOID
446SetPaletteColor (
447 VBOX_VGA_PRIVATE_DATA *Private,
448 UINTN Index,
449 UINT8 Red,
450 UINT8 Green,
451 UINT8 Blue
452 );
453
454VOID
455SetDefaultPalette (
456 VBOX_VGA_PRIVATE_DATA *Private
457 );
458
459VOID
460DrawLogo (
461 VBOX_VGA_PRIVATE_DATA *Private,
462 UINTN ScreenWidth,
463 UINTN ScreenHeight
464 );
465
466EFI_STATUS
467VBoxVgaVideoModeSetup (
468 VBOX_VGA_PRIVATE_DATA *Private
469 );
470
471UINT32 VBoxVgaGetVmVariable(UINT32 Variable, CHAR8* Buffer, UINT32 Size);
472
473#endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette