1 | /* $Id: VBoxVga.c 82968 2020-02-04 10:35:17Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxVga.c
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2020 Oracle Corporation
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
10 | * available from http://www.virtualbox.org. This file is free software;
|
---|
11 | * you can redistribute it and/or modify it under the terms of the GNU
|
---|
12 | * General Public License (GPL) as published by the Free Software
|
---|
13 | * Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
14 | * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
15 | * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
16 | *
|
---|
17 | * The contents of this file may alternatively be used under the terms
|
---|
18 | * of the Common Development and Distribution License Version 1.0
|
---|
19 | * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
20 | * VirtualBox OSE distribution, in which case the provisions of the
|
---|
21 | * CDDL are applicable instead of those of the GPL.
|
---|
22 | *
|
---|
23 | * You may elect to license modified versions of this file under the
|
---|
24 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
25 | */
|
---|
26 |
|
---|
27 | /*
|
---|
28 | This code is based on:
|
---|
29 |
|
---|
30 | Cirrus Logic 5430 Controller Driver.
|
---|
31 | This driver is a sample implementation of the UGA Draw and Graphics Output
|
---|
32 | Protocols for the Cirrus Logic 5430 family of PCI video controllers.
|
---|
33 | This driver is only usable in the EFI pre-boot environment.
|
---|
34 | This sample is intended to show how the UGA Draw and Graphics output Protocol
|
---|
35 | is able to function.
|
---|
36 | The UGA I/O Protocol is not implemented in this sample.
|
---|
37 | A fully compliant EFI UGA driver requires both
|
---|
38 | the UGA Draw and the UGA I/O Protocol. Please refer to Microsoft's
|
---|
39 | documentation on UGA for details on how to write a UGA driver that is able
|
---|
40 | to function both in the EFI pre-boot environment and from the OS runtime.
|
---|
41 |
|
---|
42 | Copyright (c) 2006 - 2009, 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 | #include "VBoxVga.h"
|
---|
57 | #include <IndustryStandard/Acpi.h>
|
---|
58 | #include "iprt/asm.h"
|
---|
59 |
|
---|
60 |
|
---|
61 | #define BOUTB(storage, count, aport, dport) \
|
---|
62 | do { \
|
---|
63 | for (i = 0 ; i < (count); ++i) \
|
---|
64 | if ((dport) == (aport) + 1) \
|
---|
65 | ASMOutU16((aport), ((UINT16)storage[i] << 8) | (UINT8)i); \
|
---|
66 | else { \
|
---|
67 | ASMOutU8((aport), (UINT8)i); \
|
---|
68 | ASMOutU8((dport), storage[i]); \
|
---|
69 | } \
|
---|
70 | } while (0)
|
---|
71 |
|
---|
72 |
|
---|
73 |
|
---|
74 | EFI_DRIVER_BINDING_PROTOCOL gVBoxVgaDriverBinding = {
|
---|
75 | VBoxVgaControllerDriverSupported,
|
---|
76 | VBoxVgaControllerDriverStart,
|
---|
77 | VBoxVgaControllerDriverStop,
|
---|
78 | 0x10,
|
---|
79 | NULL,
|
---|
80 | NULL
|
---|
81 | };
|
---|
82 |
|
---|
83 | ///
|
---|
84 | /// Generic Attribute Controller Register Settings
|
---|
85 | ///
|
---|
86 | UINT8 AttributeController[21] = {
|
---|
87 | 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
|
---|
88 | 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
|
---|
89 | 0x41, 0x00, 0x0F, 0x00, 0x00
|
---|
90 | };
|
---|
91 |
|
---|
92 | ///
|
---|
93 | /// Generic Graphics Controller Register Settings
|
---|
94 | ///
|
---|
95 | UINT8 GraphicsController[9] = {
|
---|
96 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0F, 0xff
|
---|
97 | };
|
---|
98 |
|
---|
99 | ///
|
---|
100 | /// Generic Graphics Controller Sequencer Register Settings
|
---|
101 | ///
|
---|
102 | UINT8 Seq_Default[5] = {
|
---|
103 | 0x01, 0x01, 0x0f, 0x00, 0x0a
|
---|
104 | };
|
---|
105 |
|
---|
106 | #if 0 // CRTC tables not used (and not checked for correctness), as VBE is much simpler
|
---|
107 | //
|
---|
108 | // 640 x 480 x 256 color @ 60 Hertz
|
---|
109 | //
|
---|
110 | UINT8 Crtc_640_480_256_60[25] = {
|
---|
111 | /* r0 = */0x5f, /* r1 = */0x4f, /* r2 = */0x50, /* r3 = */0x82,
|
---|
112 | /* r4 = */0x54, /* r5 = */0x80, /* r6 = */0x0b, /* r7 = */0x3e,
|
---|
113 | /* r8 = */0x00, /* r9 = */0x40, /* r10 = */0x00, /* r11 = */0x00,
|
---|
114 | /* r12 = */0x00, /* r13 = */0x00, /* r14 = */0x00, /* r15 = */0x00,
|
---|
115 | /* r16 = */0xea, /* r17 = */0x0c, /* r18 = */0xdf, /* r19 = */0x28,
|
---|
116 | /* r20 = */0x4f, /* r21 = */0xe7, /* r22 = */0x04, /* r23 = */0xe3,
|
---|
117 | /* r24 = */0xff
|
---|
118 | };
|
---|
119 |
|
---|
120 | //
|
---|
121 | // 800 x 600 x 256 color @ 60 Hertz
|
---|
122 | //
|
---|
123 | UINT8 Crtc_800_600_256_60[25] = {
|
---|
124 | /* r0 = */0x7f, /* r1 = */0x63, /* r2 = */0x64, /* r3 = */0x82,
|
---|
125 | /* r4 = */0x6b, /* r5 = */0x80, /* r6 = */0x0b, /* r7 = */0x3e,
|
---|
126 | /* r8 = */0x00, /* r9 = */0x60, /* r10 = */0x00, /* r11 = */0x00,
|
---|
127 | /* r12 = */0x00, /* r13 = */0x00, /* r14 = */0x00, /* r15 = */0x00,
|
---|
128 | /* r16 = */0xea, /* r17 = */0x0c, /* r18 = */0xdf, /* r19 = */0x28,
|
---|
129 | /* r20 = */0x4f, /* r21 = */0xe7, /* r22 = */0x04, /* r23 = */0xe3,
|
---|
130 | /* r24 = */0xff
|
---|
131 |
|
---|
132 | };
|
---|
133 |
|
---|
134 | //
|
---|
135 | // 1024 x 768 x 256 color @ 60 Hertz
|
---|
136 | //
|
---|
137 | UINT8 Crtc_1024_768_256_60[25] = {
|
---|
138 | /* r0 = */0xa3, /* r1 = */0x7f, /* r2 = */0x81, /* r3 = */0x90,
|
---|
139 | /* r4 = */0x88, /* r5 = */0x05, /* r6 = */0x28, /* r7 = */0xfd,
|
---|
140 | /* r8 = */0x00, /* r9 = */0x60, /* r10 = */0x00, /* r11 = */0x00,
|
---|
141 | /* r12 = */0x00, /* r13 = */0x00, /* r14 = */0x00, /* r15 = */0x00,
|
---|
142 | /* r16 = */0x06, /* r17 = */0x0f, /* r18 = */0xff, /* r19 = */0x40,
|
---|
143 | /* r20 = */0x4f, /* r21 = */0x05, /* r22 = */0x1a, /* r23 = */0xe3,
|
---|
144 | /* r24 = */0xff
|
---|
145 | };
|
---|
146 | #endif
|
---|
147 |
|
---|
148 | ///
|
---|
149 | /// Table of supported video modes (sorted by increasing horizontal, then by
|
---|
150 | /// increasing vertical resolution)
|
---|
151 | ///
|
---|
152 | VBOX_VGA_VIDEO_MODES VBoxVgaVideoModes[] =
|
---|
153 | {
|
---|
154 | { 640, 480, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // VGA 4:3
|
---|
155 | { 800, 600, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // SVGA 4:3
|
---|
156 | { 1024, 768, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // XGA 4:3
|
---|
157 | { 1152, 864, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // XGA+ 4:3
|
---|
158 | { 1280, 720, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // HD 16:9
|
---|
159 | { 1280, 800, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // WXGA 16:10
|
---|
160 | { 1280, 1024, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // SXGA 5:4
|
---|
161 | { 1400, 1050, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // SXGA+ 4:3
|
---|
162 | { 1440, 900, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // WXGA+ 16:10
|
---|
163 | { 1600, 900, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // HD+ 16:9
|
---|
164 | { 1600, 1200, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // UXGA 4:3
|
---|
165 | { 1680, 1050, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // WSXGA+ 16:10
|
---|
166 | { 1920, 1080, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // FHD 16:9
|
---|
167 | { 1920, 1200, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // WUXGA 16:10
|
---|
168 | { 2048, 1080, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // DCI_2K 19:10
|
---|
169 | { 2160, 1440, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // FHD+ 3:2
|
---|
170 | { 2304, 1440, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // unnamed 16:10
|
---|
171 | { 2560, 1440, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // QHD 16:9
|
---|
172 | { 2560, 1600, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // WQXGA 16:10
|
---|
173 | { 2880, 1800, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // QWXGA+ 16:10
|
---|
174 | { 3200, 1800, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // QHD+ 16:9
|
---|
175 | { 3200, 2048, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // WQSXGA 16:10
|
---|
176 | { 3840, 2160, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // 4K_UHD 16:9
|
---|
177 | { 3840, 2400, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // WQUXGA 16:10
|
---|
178 | { 4096, 2160, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // DCI_4K 19:10
|
---|
179 | { 4096, 3072, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // HXGA 4:3
|
---|
180 | { 5120, 2880, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // UHD+ 16:9
|
---|
181 | { 5120, 3200, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // WHXGA 16:10
|
---|
182 | { 6400, 4096, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // WHSXGA 16:10
|
---|
183 | { 6400, 4800, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // HUXGA 4:3
|
---|
184 | { 7680, 4320, 32, 60, NULL /* crtc */, NULL /* sequencer */, 0x01 }, // 8K_UHD2 16:9
|
---|
185 | { 0, }, // Custom video mode 0, do not delete, must be at the end!
|
---|
186 | { 0, }, // Custom video mode 1, do not delete, must be at the end!
|
---|
187 | { 0, }, // Custom video mode 2, do not delete, must be at the end!
|
---|
188 | { 0, }, // Custom video mode 3, do not delete, must be at the end!
|
---|
189 | { 0, }, // Custom video mode 4, do not delete, must be at the end!
|
---|
190 | { 0, }, // Custom video mode 5, do not delete, must be at the end!
|
---|
191 | { 0, }, // Custom video mode 6, do not delete, must be at the end!
|
---|
192 | { 0, }, // Custom video mode 7, do not delete, must be at the end!
|
---|
193 | { 0, }, // Custom video mode 8, do not delete, must be at the end!
|
---|
194 | { 0, }, // Custom video mode 9, do not delete, must be at the end!
|
---|
195 | { 0, }, // Custom video mode 10, do not delete, must be at the end!
|
---|
196 | { 0, }, // Custom video mode 11, do not delete, must be at the end!
|
---|
197 | { 0, }, // Custom video mode 12, do not delete, must be at the end!
|
---|
198 | { 0, }, // Custom video mode 13, do not delete, must be at the end!
|
---|
199 | { 0, }, // Custom video mode 14, do not delete, must be at the end!
|
---|
200 | { 0, } // Custom video mode 15, do not delete, must be at the end!
|
---|
201 | };
|
---|
202 |
|
---|
203 | const UINT32 VBoxVgaVideoModeCount = sizeof(VBoxVgaVideoModes) / sizeof(VBoxVgaVideoModes[0]);
|
---|
204 |
|
---|
205 | typedef struct _APPLE_FRAMEBUFFERINFO_PROTOCOL APPLE_FRAMEBUFFERINFO_PROTOCOL;
|
---|
206 |
|
---|
207 | typedef
|
---|
208 | EFI_STATUS
|
---|
209 | (EFIAPI *APPLE_FRAMEBUFFERINFO_PROTOCOL_GET_INFO) (
|
---|
210 | IN APPLE_FRAMEBUFFERINFO_PROTOCOL *This,
|
---|
211 | OUT UINT32 *BaseAddr,
|
---|
212 | OUT UINT32 *Something,
|
---|
213 | OUT UINT32 *RowBytes,
|
---|
214 | OUT UINT32 *Width,
|
---|
215 | OUT UINT32 *Height,
|
---|
216 | OUT UINT32 *Depth);
|
---|
217 |
|
---|
218 | struct _APPLE_FRAMEBUFFERINFO_PROTOCOL {
|
---|
219 | APPLE_FRAMEBUFFERINFO_PROTOCOL_GET_INFO GetInfo;
|
---|
220 | VBOX_VGA_PRIVATE_DATA *Private;
|
---|
221 | };
|
---|
222 |
|
---|
223 | EFI_STATUS EFIAPI
|
---|
224 | GetFrameBufferInfo(IN APPLE_FRAMEBUFFERINFO_PROTOCOL *This,
|
---|
225 | OUT UINT32 *BaseAddr,
|
---|
226 | OUT UINT32 *Something,
|
---|
227 | OUT UINT32 *RowBytes,
|
---|
228 | OUT UINT32 *Width,
|
---|
229 | OUT UINT32 *Height,
|
---|
230 | OUT UINT32 *Depth);
|
---|
231 |
|
---|
232 | static APPLE_FRAMEBUFFERINFO_PROTOCOL gAppleFrameBufferInfo =
|
---|
233 | {
|
---|
234 | GetFrameBufferInfo,
|
---|
235 | NULL
|
---|
236 | };
|
---|
237 |
|
---|
238 |
|
---|
239 | /*
|
---|
240 | * @todo move this function to the library.
|
---|
241 | */
|
---|
242 | UINT32 VBoxVgaGetVmVariable(UINT32 Variable, CHAR8* Buffer, UINT32 Size)
|
---|
243 | {
|
---|
244 | UINT32 VarLen, i;
|
---|
245 |
|
---|
246 | ASMOutU32(EFI_INFO_PORT, Variable);
|
---|
247 | VarLen = ASMInU32(EFI_INFO_PORT);
|
---|
248 |
|
---|
249 | for (i = 0; i < VarLen && i < Size; i++)
|
---|
250 | Buffer[i] = ASMInU8(EFI_INFO_PORT);
|
---|
251 |
|
---|
252 | return VarLen;
|
---|
253 | }
|
---|
254 |
|
---|
255 |
|
---|
256 | /**
|
---|
257 | VBoxVgaControllerDriverSupported
|
---|
258 |
|
---|
259 | TODO: This - add argument and description to function comment
|
---|
260 | TODO: Controller - add argument and description to function comment
|
---|
261 | TODO: RemainingDevicePath - add argument and description to function comment
|
---|
262 | **/
|
---|
263 | EFI_STATUS
|
---|
264 | EFIAPI
|
---|
265 | VBoxVgaControllerDriverSupported (
|
---|
266 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
267 | IN EFI_HANDLE Controller,
|
---|
268 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
---|
269 | )
|
---|
270 | {
|
---|
271 | EFI_STATUS Status;
|
---|
272 | EFI_PCI_IO_PROTOCOL *PciIo;
|
---|
273 | PCI_TYPE00 Pci;
|
---|
274 | EFI_DEV_PATH *Node;
|
---|
275 |
|
---|
276 | //
|
---|
277 | // Open the PCI I/O Protocol
|
---|
278 | //
|
---|
279 | Status = gBS->OpenProtocol (
|
---|
280 | Controller,
|
---|
281 | &gEfiPciIoProtocolGuid,
|
---|
282 | (VOID **) &PciIo,
|
---|
283 | This->DriverBindingHandle,
|
---|
284 | Controller,
|
---|
285 | EFI_OPEN_PROTOCOL_BY_DRIVER
|
---|
286 | );
|
---|
287 | if (EFI_ERROR (Status)) {
|
---|
288 | DEBUG((DEBUG_INFO, "%a:%d status:%r\n", __FILE__, __LINE__, Status));
|
---|
289 | return Status;
|
---|
290 | }
|
---|
291 |
|
---|
292 | //
|
---|
293 | // Read the PCI Configuration Header from the PCI Device
|
---|
294 | //
|
---|
295 | Status = PciIo->Pci.Read (
|
---|
296 | PciIo,
|
---|
297 | EfiPciIoWidthUint32,
|
---|
298 | 0,
|
---|
299 | sizeof (Pci) / sizeof (UINT32),
|
---|
300 | &Pci
|
---|
301 | );
|
---|
302 | if (EFI_ERROR (Status)) {
|
---|
303 | DEBUG((DEBUG_INFO, "%a:%d status:%r\n", __FILE__, __LINE__, Status));
|
---|
304 | goto Done;
|
---|
305 | }
|
---|
306 |
|
---|
307 | Status = EFI_UNSUPPORTED;
|
---|
308 | //
|
---|
309 | // See if the I/O enable is on. Most systems only allow one VGA device to be turned on
|
---|
310 | // at a time, so see if this is one that is turned on.
|
---|
311 | //
|
---|
312 | // if (((Pci.Hdr.Command & 0x01) == 0x01)) {
|
---|
313 | //
|
---|
314 | // See if this is a VirtualBox VGA or VMSVGA II PCI controller
|
---|
315 | //
|
---|
316 | if ( ((Pci.Hdr.VendorId == VBOX_VENDOR_ID) && (Pci.Hdr.DeviceId == VBOX_VGA_DEVICE_ID))
|
---|
317 | || ((Pci.Hdr.VendorId == VMSVGA_VENDOR_ID) && (Pci.Hdr.DeviceId == VMSVGA_II_DEVICE_ID))) {
|
---|
318 |
|
---|
319 | Status = EFI_SUCCESS;
|
---|
320 | if (RemainingDevicePath != NULL) {
|
---|
321 | Node = (EFI_DEV_PATH *) RemainingDevicePath;
|
---|
322 | //
|
---|
323 | // Check if RemainingDevicePath is the End of Device Path Node,
|
---|
324 | // if yes, return EFI_SUCCESS
|
---|
325 | //
|
---|
326 | if (!IsDevicePathEnd (Node)) {
|
---|
327 | //
|
---|
328 | // If RemainingDevicePath isn't the End of Device Path Node,
|
---|
329 | // check its validation
|
---|
330 | //
|
---|
331 | if (Node->DevPath.Type != ACPI_DEVICE_PATH ||
|
---|
332 | Node->DevPath.SubType != ACPI_ADR_DP ||
|
---|
333 | DevicePathNodeLength(&Node->DevPath) != sizeof(ACPI_ADR_DEVICE_PATH)) {
|
---|
334 | DEBUG((DEBUG_INFO, "%a:%d status:%r\n", __FILE__, __LINE__, Status));
|
---|
335 | Status = EFI_UNSUPPORTED;
|
---|
336 | }
|
---|
337 | }
|
---|
338 | }
|
---|
339 | }
|
---|
340 |
|
---|
341 | Done:
|
---|
342 | //
|
---|
343 | // Close the PCI I/O Protocol
|
---|
344 | //
|
---|
345 | gBS->CloseProtocol (
|
---|
346 | Controller,
|
---|
347 | &gEfiPciIoProtocolGuid,
|
---|
348 | This->DriverBindingHandle,
|
---|
349 | Controller
|
---|
350 | );
|
---|
351 |
|
---|
352 | DEBUG((DEBUG_INFO, "%a:%d status:%r\n", __FILE__, __LINE__, Status));
|
---|
353 | return Status;
|
---|
354 | }
|
---|
355 |
|
---|
356 | /**
|
---|
357 | VBoxVgaControllerDriverStart
|
---|
358 |
|
---|
359 | TODO: This - add argument and description to function comment
|
---|
360 | TODO: Controller - add argument and description to function comment
|
---|
361 | TODO: RemainingDevicePath - add argument and description to function comment
|
---|
362 | **/
|
---|
363 | EFI_STATUS
|
---|
364 | EFIAPI
|
---|
365 | VBoxVgaControllerDriverStart (
|
---|
366 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
367 | IN EFI_HANDLE Controller,
|
---|
368 | IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath
|
---|
369 | )
|
---|
370 | {
|
---|
371 | EFI_STATUS Status;
|
---|
372 | VBOX_VGA_PRIVATE_DATA *Private;
|
---|
373 | BOOLEAN PciAttributesSaved;
|
---|
374 | EFI_DEVICE_PATH_PROTOCOL *ParentDevicePath;
|
---|
375 | ACPI_ADR_DEVICE_PATH AcpiDeviceNode;
|
---|
376 | PCI_TYPE00 Pci;
|
---|
377 |
|
---|
378 | PciAttributesSaved = FALSE;
|
---|
379 | //
|
---|
380 | // Allocate Private context data for UGA Draw interface.
|
---|
381 | //
|
---|
382 | Private = AllocateZeroPool (sizeof (VBOX_VGA_PRIVATE_DATA));
|
---|
383 | if (Private == NULL) {
|
---|
384 | Status = EFI_OUT_OF_RESOURCES;
|
---|
385 | goto Error;
|
---|
386 | }
|
---|
387 | gAppleFrameBufferInfo.Private = Private;
|
---|
388 | //
|
---|
389 | // Set up context record
|
---|
390 | //
|
---|
391 | Private->Signature = VBOX_VGA_PRIVATE_DATA_SIGNATURE;
|
---|
392 | Private->Handle = NULL;
|
---|
393 |
|
---|
394 | //
|
---|
395 | // Open PCI I/O Protocol
|
---|
396 | //
|
---|
397 | Status = gBS->OpenProtocol (
|
---|
398 | Controller,
|
---|
399 | &gEfiPciIoProtocolGuid,
|
---|
400 | (VOID **) &Private->PciIo,
|
---|
401 | This->DriverBindingHandle,
|
---|
402 | Controller,
|
---|
403 | EFI_OPEN_PROTOCOL_BY_DRIVER
|
---|
404 | );
|
---|
405 | if (EFI_ERROR (Status)) {
|
---|
406 | goto Error;
|
---|
407 | }
|
---|
408 |
|
---|
409 | //
|
---|
410 | // Read the PCI Configuration Header from the PCI Device again to figure out the model.
|
---|
411 | //
|
---|
412 | Status = Private->PciIo->Pci.Read (
|
---|
413 | Private->PciIo,
|
---|
414 | EfiPciIoWidthUint32,
|
---|
415 | 0,
|
---|
416 | sizeof (Pci) / sizeof (UINT32),
|
---|
417 | &Pci
|
---|
418 | );
|
---|
419 | if (EFI_ERROR (Status)) {
|
---|
420 | DEBUG((DEBUG_INFO, "%a:%d status:%r\n", __FILE__, __LINE__, Status));
|
---|
421 | goto Error;
|
---|
422 | }
|
---|
423 |
|
---|
424 | Private->DeviceType = Pci.Hdr.DeviceId;
|
---|
425 |
|
---|
426 | //
|
---|
427 | // Save original PCI attributes
|
---|
428 | //
|
---|
429 | Status = Private->PciIo->Attributes (
|
---|
430 | Private->PciIo,
|
---|
431 | EfiPciIoAttributeOperationGet,
|
---|
432 | 0,
|
---|
433 | &Private->OriginalPciAttributes
|
---|
434 | );
|
---|
435 |
|
---|
436 | if (EFI_ERROR (Status)) {
|
---|
437 | goto Error;
|
---|
438 | }
|
---|
439 | PciAttributesSaved = TRUE;
|
---|
440 |
|
---|
441 | Status = Private->PciIo->Attributes (
|
---|
442 | Private->PciIo,
|
---|
443 | EfiPciIoAttributeOperationEnable,
|
---|
444 | EFI_PCI_DEVICE_ENABLE | EFI_PCI_IO_ATTRIBUTE_VGA_MEMORY | EFI_PCI_IO_ATTRIBUTE_VGA_IO,
|
---|
445 | NULL
|
---|
446 | );
|
---|
447 | if (EFI_ERROR (Status)) {
|
---|
448 | goto Error;
|
---|
449 | }
|
---|
450 |
|
---|
451 | //
|
---|
452 | // Get ParentDevicePath
|
---|
453 | //
|
---|
454 | Status = gBS->HandleProtocol (
|
---|
455 | Controller,
|
---|
456 | &gEfiDevicePathProtocolGuid,
|
---|
457 | (VOID **) &ParentDevicePath
|
---|
458 | );
|
---|
459 | if (EFI_ERROR (Status)) {
|
---|
460 | goto Error;
|
---|
461 | }
|
---|
462 |
|
---|
463 | if (FeaturePcdGet (PcdSupportGop)) {
|
---|
464 | //
|
---|
465 | // Set Gop Device Path
|
---|
466 | //
|
---|
467 | if (RemainingDevicePath == NULL) {
|
---|
468 | ZeroMem (&AcpiDeviceNode, sizeof (ACPI_ADR_DEVICE_PATH));
|
---|
469 | AcpiDeviceNode.Header.Type = ACPI_DEVICE_PATH;
|
---|
470 | AcpiDeviceNode.Header.SubType = ACPI_ADR_DP;
|
---|
471 | AcpiDeviceNode.ADR = ACPI_DISPLAY_ADR (1, 0, 0, 1, 0, ACPI_ADR_DISPLAY_TYPE_VGA, 0, 0);
|
---|
472 | SetDevicePathNodeLength (&AcpiDeviceNode.Header, sizeof (ACPI_ADR_DEVICE_PATH));
|
---|
473 |
|
---|
474 | Private->GopDevicePath = AppendDevicePathNode (
|
---|
475 | ParentDevicePath,
|
---|
476 | (EFI_DEVICE_PATH_PROTOCOL *) &AcpiDeviceNode
|
---|
477 | );
|
---|
478 | } else if (!IsDevicePathEnd (RemainingDevicePath)) {
|
---|
479 | //
|
---|
480 | // If RemainingDevicePath isn't the End of Device Path Node,
|
---|
481 | // only scan the specified device by RemainingDevicePath
|
---|
482 | //
|
---|
483 | Private->GopDevicePath = AppendDevicePathNode (ParentDevicePath, RemainingDevicePath);
|
---|
484 | } else {
|
---|
485 | //
|
---|
486 | // If RemainingDevicePath is the End of Device Path Node,
|
---|
487 | // don't create child device and return EFI_SUCCESS
|
---|
488 | //
|
---|
489 | Private->GopDevicePath = NULL;
|
---|
490 | }
|
---|
491 |
|
---|
492 | if (Private->GopDevicePath != NULL) {
|
---|
493 | //
|
---|
494 | // Create child handle and device path protocol first
|
---|
495 | //
|
---|
496 | Private->Handle = NULL;
|
---|
497 | Status = gBS->InstallMultipleProtocolInterfaces (
|
---|
498 | &Private->Handle,
|
---|
499 | &gEfiDevicePathProtocolGuid,
|
---|
500 | Private->GopDevicePath,
|
---|
501 | NULL
|
---|
502 | );
|
---|
503 | }
|
---|
504 | }
|
---|
505 |
|
---|
506 | //
|
---|
507 | // Now do some model-specific setup.
|
---|
508 | //
|
---|
509 | if (Private->DeviceType == VMSVGA_II_DEVICE_ID) {
|
---|
510 | EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *IOPortDesc;
|
---|
511 |
|
---|
512 | // VMSVGA
|
---|
513 | Private->BarIndexFB = 1;
|
---|
514 |
|
---|
515 | Private->PciIo->GetBarAttributes (
|
---|
516 | Private->PciIo,
|
---|
517 | 0, // BAR 0 is the I/O port space
|
---|
518 | NULL,
|
---|
519 | (VOID**) &IOPortDesc
|
---|
520 | );
|
---|
521 | Private->IOBase = (UINT16)IOPortDesc->AddrRangeMin;
|
---|
522 |
|
---|
523 | //
|
---|
524 | // Query the VRAM size (for proper mode filtering)
|
---|
525 | //
|
---|
526 | ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_VRAM_SIZE);
|
---|
527 | Private->VRAMSize = ASMInU32(Private->IOBase + SVGA_VALUE_PORT);
|
---|
528 |
|
---|
529 | #if 0
|
---|
530 | // Not used because of buggy emulation(?) which is not fully compatible
|
---|
531 | // with the simple "legacy" VMSVGA II register interface.
|
---|
532 |
|
---|
533 | // Enable the device, set initial mode
|
---|
534 | ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_WIDTH);
|
---|
535 | ASMOutU32(Private->IOBase + SVGA_VALUE_PORT, 1024);
|
---|
536 | ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_HEIGHT);
|
---|
537 | ASMOutU32(Private->IOBase + SVGA_VALUE_PORT, 768);
|
---|
538 | ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_BYTES_PER_LINE);
|
---|
539 | ASMOutU32(Private->IOBase + SVGA_VALUE_PORT, 768 * 4);
|
---|
540 | ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_BITS_PER_PIXEL);
|
---|
541 | ASMOutU32(Private->IOBase + SVGA_VALUE_PORT, 32);
|
---|
542 | ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_CONFIG_DONE);
|
---|
543 | ASMOutU32(Private->IOBase + SVGA_VALUE_PORT, 1);
|
---|
544 |
|
---|
545 | ASMOutU32(Private->IOBase + SVGA_INDEX_PORT, SVGA_REG_ENABLE);
|
---|
546 | ASMOutU32(Private->IOBase + SVGA_VALUE_PORT, SVGA_REG_ENABLE_ENABLE);
|
---|
547 | #endif
|
---|
548 | } else {
|
---|
549 | // VBoxVGA / VBoxSVGA
|
---|
550 | Private->BarIndexFB = 0;
|
---|
551 | //
|
---|
552 | // Get VRAM size, needed for constructing a correct video mode list
|
---|
553 | //
|
---|
554 | Private->VRAMSize = ASMInU32(VBE_DISPI_IOPORT_DATA);
|
---|
555 | }
|
---|
556 |
|
---|
557 |
|
---|
558 | //
|
---|
559 | // Construct video mode list
|
---|
560 | //
|
---|
561 | Status = VBoxVgaVideoModeSetup (Private);
|
---|
562 | if (EFI_ERROR (Status)) {
|
---|
563 | goto Error;
|
---|
564 | }
|
---|
565 |
|
---|
566 | if (FeaturePcdGet (PcdSupportUga)) {
|
---|
567 | //
|
---|
568 | // Start the UGA Draw software stack.
|
---|
569 | //
|
---|
570 | Status = VBoxVgaUgaDrawConstructor (Private);
|
---|
571 | ASSERT_EFI_ERROR (Status);
|
---|
572 |
|
---|
573 | Private->UgaDevicePath = ParentDevicePath;
|
---|
574 | Status = gBS->InstallMultipleProtocolInterfaces (
|
---|
575 | &Controller,
|
---|
576 | //&gEfiUgaDrawProtocolGuid,
|
---|
577 | //&Private->UgaDraw,
|
---|
578 | &gEfiDevicePathProtocolGuid,
|
---|
579 | Private->UgaDevicePath,
|
---|
580 | NULL
|
---|
581 | );
|
---|
582 | Status = gBS->InstallMultipleProtocolInterfaces (
|
---|
583 | &Controller,
|
---|
584 | &gEfiUgaDrawProtocolGuid,
|
---|
585 | &Private->UgaDraw,
|
---|
586 | NULL
|
---|
587 | );
|
---|
588 |
|
---|
589 | } else if (FeaturePcdGet (PcdSupportGop)) {
|
---|
590 | if (Private->GopDevicePath == NULL) {
|
---|
591 | //
|
---|
592 | // If RemainingDevicePath is the End of Device Path Node,
|
---|
593 | // don't create child device and return EFI_SUCCESS
|
---|
594 | //
|
---|
595 | Status = EFI_SUCCESS;
|
---|
596 | } else {
|
---|
597 |
|
---|
598 | //
|
---|
599 | // Start the GOP software stack.
|
---|
600 | //
|
---|
601 | Status = VBoxVgaGraphicsOutputConstructor (Private);
|
---|
602 | ASSERT_EFI_ERROR (Status);
|
---|
603 |
|
---|
604 | Status = gBS->InstallMultipleProtocolInterfaces (
|
---|
605 | &Private->Handle,
|
---|
606 | &gEfiGraphicsOutputProtocolGuid,
|
---|
607 | &Private->GraphicsOutput,
|
---|
608 | &gEfiEdidDiscoveredProtocolGuid,
|
---|
609 | &Private->EdidDiscovered,
|
---|
610 | &gEfiEdidActiveProtocolGuid,
|
---|
611 | &Private->EdidActive,
|
---|
612 | NULL
|
---|
613 | );
|
---|
614 | }
|
---|
615 | } else {
|
---|
616 | //
|
---|
617 | // This driver must support eithor GOP or UGA or both.
|
---|
618 | //
|
---|
619 | ASSERT (FALSE);
|
---|
620 | Status = EFI_UNSUPPORTED;
|
---|
621 | }
|
---|
622 |
|
---|
623 | Error:
|
---|
624 | if (EFI_ERROR (Status)) {
|
---|
625 | if (Private) {
|
---|
626 | if (Private->PciIo) {
|
---|
627 | if (PciAttributesSaved == TRUE) {
|
---|
628 | //
|
---|
629 | // Restore original PCI attributes
|
---|
630 | //
|
---|
631 | Private->PciIo->Attributes (
|
---|
632 | Private->PciIo,
|
---|
633 | EfiPciIoAttributeOperationSet,
|
---|
634 | Private->OriginalPciAttributes,
|
---|
635 | NULL
|
---|
636 | );
|
---|
637 | }
|
---|
638 | //
|
---|
639 | // Close the PCI I/O Protocol
|
---|
640 | //
|
---|
641 | gBS->CloseProtocol (
|
---|
642 | Private->Handle,
|
---|
643 | &gEfiPciIoProtocolGuid,
|
---|
644 | This->DriverBindingHandle,
|
---|
645 | Private->Handle
|
---|
646 | );
|
---|
647 | }
|
---|
648 |
|
---|
649 | gBS->FreePool (Private);
|
---|
650 | }
|
---|
651 | }
|
---|
652 |
|
---|
653 | return Status;
|
---|
654 | }
|
---|
655 |
|
---|
656 | /**
|
---|
657 | VBoxVgaControllerDriverStop
|
---|
658 |
|
---|
659 | TODO: This - add argument and description to function comment
|
---|
660 | TODO: Controller - add argument and description to function comment
|
---|
661 | TODO: NumberOfChildren - add argument and description to function comment
|
---|
662 | TODO: ChildHandleBuffer - add argument and description to function comment
|
---|
663 | TODO: EFI_SUCCESS - add return value to function comment
|
---|
664 | **/
|
---|
665 | EFI_STATUS
|
---|
666 | EFIAPI
|
---|
667 | VBoxVgaControllerDriverStop (
|
---|
668 | IN EFI_DRIVER_BINDING_PROTOCOL *This,
|
---|
669 | IN EFI_HANDLE Controller,
|
---|
670 | IN UINTN NumberOfChildren,
|
---|
671 | IN EFI_HANDLE *ChildHandleBuffer
|
---|
672 | )
|
---|
673 | {
|
---|
674 | EFI_UGA_DRAW_PROTOCOL *UgaDraw;
|
---|
675 | EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput;
|
---|
676 |
|
---|
677 | EFI_STATUS Status;
|
---|
678 | VBOX_VGA_PRIVATE_DATA *Private;
|
---|
679 |
|
---|
680 | if (FeaturePcdGet (PcdSupportUga)) {
|
---|
681 | Status = gBS->OpenProtocol (
|
---|
682 | Controller,
|
---|
683 | &gEfiUgaDrawProtocolGuid,
|
---|
684 | (VOID **) &UgaDraw,
|
---|
685 | This->DriverBindingHandle,
|
---|
686 | Controller,
|
---|
687 | EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
---|
688 | );
|
---|
689 | if (EFI_ERROR (Status)) {
|
---|
690 | return Status;
|
---|
691 | }
|
---|
692 |
|
---|
693 | //
|
---|
694 | // Get our private context information
|
---|
695 | //
|
---|
696 | Private = VBOX_VGA_PRIVATE_DATA_FROM_UGA_DRAW_THIS (UgaDraw);
|
---|
697 | VBoxVgaUgaDrawDestructor (Private);
|
---|
698 |
|
---|
699 | if (FeaturePcdGet (PcdSupportGop)) {
|
---|
700 | VBoxVgaGraphicsOutputDestructor (Private);
|
---|
701 | //
|
---|
702 | // Remove the UGA and GOP protocol interface from the system
|
---|
703 | //
|
---|
704 | Status = gBS->UninstallMultipleProtocolInterfaces (
|
---|
705 | Private->Handle,
|
---|
706 | &gEfiUgaDrawProtocolGuid,
|
---|
707 | &Private->UgaDraw,
|
---|
708 | &gEfiGraphicsOutputProtocolGuid,
|
---|
709 | &Private->GraphicsOutput,
|
---|
710 | NULL
|
---|
711 | );
|
---|
712 | } else {
|
---|
713 | //
|
---|
714 | // Remove the UGA Draw interface from the system
|
---|
715 | //
|
---|
716 | Status = gBS->UninstallMultipleProtocolInterfaces (
|
---|
717 | Private->Handle,
|
---|
718 | &gEfiUgaDrawProtocolGuid,
|
---|
719 | &Private->UgaDraw,
|
---|
720 | NULL
|
---|
721 | );
|
---|
722 | }
|
---|
723 | } else {
|
---|
724 | Status = gBS->OpenProtocol (
|
---|
725 | Controller,
|
---|
726 | &gEfiGraphicsOutputProtocolGuid,
|
---|
727 | (VOID **) &GraphicsOutput,
|
---|
728 | This->DriverBindingHandle,
|
---|
729 | Controller,
|
---|
730 | EFI_OPEN_PROTOCOL_GET_PROTOCOL
|
---|
731 | );
|
---|
732 | if (EFI_ERROR (Status)) {
|
---|
733 | return Status;
|
---|
734 | }
|
---|
735 |
|
---|
736 | //
|
---|
737 | // Get our private context information
|
---|
738 | //
|
---|
739 | Private = VBOX_VGA_PRIVATE_DATA_FROM_GRAPHICS_OUTPUT_THIS (GraphicsOutput);
|
---|
740 |
|
---|
741 | VBoxVgaGraphicsOutputDestructor (Private);
|
---|
742 | //
|
---|
743 | // Remove the GOP protocol interface from the system
|
---|
744 | //
|
---|
745 | Status = gBS->UninstallMultipleProtocolInterfaces (
|
---|
746 | Private->Handle,
|
---|
747 | &gEfiGraphicsOutputProtocolGuid,
|
---|
748 | &Private->GraphicsOutput,
|
---|
749 | NULL
|
---|
750 | );
|
---|
751 | }
|
---|
752 |
|
---|
753 | if (EFI_ERROR (Status)) {
|
---|
754 | return Status;
|
---|
755 | }
|
---|
756 |
|
---|
757 | if (Private->ModeData) {
|
---|
758 | FreePool(Private->ModeData);
|
---|
759 | Private->ModeData = NULL;
|
---|
760 | }
|
---|
761 |
|
---|
762 | //
|
---|
763 | // Restore original PCI attributes
|
---|
764 | //
|
---|
765 | Private->PciIo->Attributes (
|
---|
766 | Private->PciIo,
|
---|
767 | EfiPciIoAttributeOperationSet,
|
---|
768 | Private->OriginalPciAttributes,
|
---|
769 | NULL
|
---|
770 | );
|
---|
771 |
|
---|
772 | //
|
---|
773 | // Close the PCI I/O Protocol
|
---|
774 | //
|
---|
775 | gBS->CloseProtocol (
|
---|
776 | Controller,
|
---|
777 | &gEfiPciIoProtocolGuid,
|
---|
778 | This->DriverBindingHandle,
|
---|
779 | Controller
|
---|
780 | );
|
---|
781 |
|
---|
782 | //
|
---|
783 | // Free our instance data
|
---|
784 | //
|
---|
785 | gBS->FreePool (Private);
|
---|
786 |
|
---|
787 | return EFI_SUCCESS;
|
---|
788 | }
|
---|
789 |
|
---|
790 | /**
|
---|
791 | VBoxVgaUgaDrawDestructor
|
---|
792 |
|
---|
793 | TODO: Private - add argument and description to function comment
|
---|
794 | TODO: EFI_SUCCESS - add return value to function comment
|
---|
795 | **/
|
---|
796 | EFI_STATUS
|
---|
797 | VBoxVgaUgaDrawDestructor (
|
---|
798 | VBOX_VGA_PRIVATE_DATA *Private
|
---|
799 | )
|
---|
800 | {
|
---|
801 | return EFI_SUCCESS;
|
---|
802 | }
|
---|
803 |
|
---|
804 | /**
|
---|
805 | TODO: Add function description
|
---|
806 |
|
---|
807 | @param Private TODO: add argument description
|
---|
808 | @param Index TODO: add argument description
|
---|
809 | @param Red TODO: add argument description
|
---|
810 | @param Green TODO: add argument description
|
---|
811 | @param Blue TODO: add argument description
|
---|
812 |
|
---|
813 | TODO: add return values
|
---|
814 |
|
---|
815 | **/
|
---|
816 | VOID
|
---|
817 | SetPaletteColor (
|
---|
818 | VBOX_VGA_PRIVATE_DATA *Private,
|
---|
819 | UINTN Index,
|
---|
820 | UINT8 Red,
|
---|
821 | UINT8 Green,
|
---|
822 | UINT8 Blue
|
---|
823 | )
|
---|
824 | {
|
---|
825 | ASMOutU8(PALETTE_INDEX_REGISTER, (UINT8) Index);
|
---|
826 | ASMOutU8(PALETTE_DATA_REGISTER, (UINT8) (Red >> 2));
|
---|
827 | ASMOutU8(PALETTE_DATA_REGISTER, (UINT8) (Green >> 2));
|
---|
828 | ASMOutU8(PALETTE_DATA_REGISTER, (UINT8) (Blue >> 2));
|
---|
829 | }
|
---|
830 |
|
---|
831 | /**
|
---|
832 | TODO: Add function description
|
---|
833 |
|
---|
834 | @param Private TODO: add argument description
|
---|
835 |
|
---|
836 | TODO: add return values
|
---|
837 |
|
---|
838 | **/
|
---|
839 | VOID
|
---|
840 | SetDefaultPalette (
|
---|
841 | VBOX_VGA_PRIVATE_DATA *Private
|
---|
842 | )
|
---|
843 | {
|
---|
844 | #if 1
|
---|
845 | UINTN Index;
|
---|
846 | UINTN RedIndex;
|
---|
847 | UINTN GreenIndex;
|
---|
848 | UINTN BlueIndex;
|
---|
849 | Index = 0;
|
---|
850 | for (RedIndex = 0; RedIndex < 8; RedIndex++) {
|
---|
851 | for (GreenIndex = 0; GreenIndex < 8; GreenIndex++) {
|
---|
852 | for (BlueIndex = 0; BlueIndex < 4; BlueIndex++) {
|
---|
853 | SetPaletteColor (Private, Index, (UINT8) (RedIndex << 5), (UINT8) (GreenIndex << 5), (UINT8) (BlueIndex << 6));
|
---|
854 | Index++;
|
---|
855 | }
|
---|
856 | }
|
---|
857 | }
|
---|
858 | #else
|
---|
859 | {
|
---|
860 | int i;
|
---|
861 | static const UINT8 s_a3bVgaDac[64*3] =
|
---|
862 | {
|
---|
863 | 0x00, 0x00, 0x00,
|
---|
864 | 0x00, 0x00, 0x2A,
|
---|
865 | 0x00, 0x2A, 0x00,
|
---|
866 | 0x00, 0x2A, 0x2A,
|
---|
867 | 0x2A, 0x00, 0x00,
|
---|
868 | 0x2A, 0x00, 0x2A,
|
---|
869 | 0x2A, 0x2A, 0x00,
|
---|
870 | 0x2A, 0x2A, 0x2A,
|
---|
871 | 0x00, 0x00, 0x15,
|
---|
872 | 0x00, 0x00, 0x3F,
|
---|
873 | 0x00, 0x2A, 0x15,
|
---|
874 | 0x00, 0x2A, 0x3F,
|
---|
875 | 0x2A, 0x00, 0x15,
|
---|
876 | 0x2A, 0x00, 0x3F,
|
---|
877 | 0x2A, 0x2A, 0x15,
|
---|
878 | 0x2A, 0x2A, 0x3F,
|
---|
879 | 0x00, 0x15, 0x00,
|
---|
880 | 0x00, 0x15, 0x2A,
|
---|
881 | 0x00, 0x3F, 0x00,
|
---|
882 | 0x00, 0x3F, 0x2A,
|
---|
883 | 0x2A, 0x15, 0x00,
|
---|
884 | 0x2A, 0x15, 0x2A,
|
---|
885 | 0x2A, 0x3F, 0x00,
|
---|
886 | 0x2A, 0x3F, 0x2A,
|
---|
887 | 0x00, 0x15, 0x15,
|
---|
888 | 0x00, 0x15, 0x3F,
|
---|
889 | 0x00, 0x3F, 0x15,
|
---|
890 | 0x00, 0x3F, 0x3F,
|
---|
891 | 0x2A, 0x15, 0x15,
|
---|
892 | 0x2A, 0x15, 0x3F,
|
---|
893 | 0x2A, 0x3F, 0x15,
|
---|
894 | 0x2A, 0x3F, 0x3F,
|
---|
895 | 0x15, 0x00, 0x00,
|
---|
896 | 0x15, 0x00, 0x2A,
|
---|
897 | 0x15, 0x2A, 0x00,
|
---|
898 | 0x15, 0x2A, 0x2A,
|
---|
899 | 0x3F, 0x00, 0x00,
|
---|
900 | 0x3F, 0x00, 0x2A,
|
---|
901 | 0x3F, 0x2A, 0x00,
|
---|
902 | 0x3F, 0x2A, 0x2A,
|
---|
903 | 0x15, 0x00, 0x15,
|
---|
904 | 0x15, 0x00, 0x3F,
|
---|
905 | 0x15, 0x2A, 0x15,
|
---|
906 | 0x15, 0x2A, 0x3F,
|
---|
907 | 0x3F, 0x00, 0x15,
|
---|
908 | 0x3F, 0x00, 0x3F,
|
---|
909 | 0x3F, 0x2A, 0x15,
|
---|
910 | 0x3F, 0x2A, 0x3F,
|
---|
911 | 0x15, 0x15, 0x00,
|
---|
912 | 0x15, 0x15, 0x2A,
|
---|
913 | 0x15, 0x3F, 0x00,
|
---|
914 | 0x15, 0x3F, 0x2A,
|
---|
915 | 0x3F, 0x15, 0x00,
|
---|
916 | 0x3F, 0x15, 0x2A,
|
---|
917 | 0x3F, 0x3F, 0x00,
|
---|
918 | 0x3F, 0x3F, 0x2A,
|
---|
919 | 0x15, 0x15, 0x15,
|
---|
920 | 0x15, 0x15, 0x3F,
|
---|
921 | 0x15, 0x3F, 0x15,
|
---|
922 | 0x15, 0x3F, 0x3F,
|
---|
923 | 0x3F, 0x15, 0x15,
|
---|
924 | 0x3F, 0x15, 0x3F,
|
---|
925 | 0x3F, 0x3F, 0x15,
|
---|
926 | 0x3F, 0x3F, 0x3F
|
---|
927 | };
|
---|
928 |
|
---|
929 | for (i = 0; i < 64; ++i)
|
---|
930 | {
|
---|
931 | ASMOutU8(PALETTE_INDEX_REGISTER, (UINT8)i);
|
---|
932 | ASMOutU8(PALETTE_DATA_REGISTER, s_a3bVgaDac[i*3 + 0]);
|
---|
933 | ASMOutU8(PALETTE_DATA_REGISTER, s_a3bVgaDac[i*3 + 1]);
|
---|
934 | ASMOutU8(PALETTE_DATA_REGISTER, s_a3bVgaDac[i*3 + 2]);
|
---|
935 | }
|
---|
936 | }
|
---|
937 |
|
---|
938 | #endif
|
---|
939 | }
|
---|
940 |
|
---|
941 | /**
|
---|
942 | TODO: Add function description
|
---|
943 |
|
---|
944 | @param Private TODO: add argument description
|
---|
945 |
|
---|
946 | TODO: add return values
|
---|
947 |
|
---|
948 | **/
|
---|
949 | VOID
|
---|
950 | ClearScreen (
|
---|
951 | VBOX_VGA_PRIVATE_DATA *Private
|
---|
952 | )
|
---|
953 | {
|
---|
954 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL blt;
|
---|
955 | blt.Blue = 0;
|
---|
956 | blt.Green = 0;
|
---|
957 | blt.Red = 0;
|
---|
958 | blt.Reserved = 0;
|
---|
959 | Private->PciIo->Mem.Write (
|
---|
960 | Private->PciIo,
|
---|
961 | EfiPciIoWidthFillUint32,
|
---|
962 | Private->BarIndexFB,
|
---|
963 | 0,
|
---|
964 | Private->ModeData[Private->CurrentMode].HorizontalResolution
|
---|
965 | * Private->ModeData[Private->CurrentMode].VerticalResolution,
|
---|
966 | &blt
|
---|
967 | );
|
---|
968 | }
|
---|
969 |
|
---|
970 | /**
|
---|
971 | TODO: Add function description
|
---|
972 |
|
---|
973 | @param Private TODO: add argument description
|
---|
974 |
|
---|
975 | TODO: add return values
|
---|
976 |
|
---|
977 | **/
|
---|
978 | VOID
|
---|
979 | DrawLogo (
|
---|
980 | VBOX_VGA_PRIVATE_DATA *Private,
|
---|
981 | UINTN ScreenWidth,
|
---|
982 | UINTN ScreenHeight
|
---|
983 | )
|
---|
984 | {
|
---|
985 | DEBUG((DEBUG_INFO, "UGA is %a GOP is %a\n",
|
---|
986 | FeaturePcdGet(PcdSupportUga) ? "on" : "off",
|
---|
987 | FeaturePcdGet(PcdSupportGop) ? "on" : "off"
|
---|
988 | ));
|
---|
989 | }
|
---|
990 |
|
---|
991 | /**
|
---|
992 | TODO: Add function description
|
---|
993 |
|
---|
994 | @param Private TODO: add argument description
|
---|
995 | @param ModeData TODO: add argument description
|
---|
996 |
|
---|
997 | TODO: add return values
|
---|
998 |
|
---|
999 | **/
|
---|
1000 | VOID
|
---|
1001 | InitializeGraphicsMode (
|
---|
1002 | VBOX_VGA_PRIVATE_DATA *Private,
|
---|
1003 | VBOX_VGA_VIDEO_MODES *ModeData
|
---|
1004 | )
|
---|
1005 | {
|
---|
1006 | UINT16 DeviceId;
|
---|
1007 | EFI_STATUS Status;
|
---|
1008 | int i;
|
---|
1009 |
|
---|
1010 | DEBUG((DEBUG_INFO, "%a:%d InitializeGraphicsMode: %dx%d bpp:%d\n", __FILE__, __LINE__, ModeData->Width, ModeData->Height, ModeData->ColorDepth));
|
---|
1011 |
|
---|
1012 | //
|
---|
1013 | // Read the PCI ID from the PCI Device (dummy)
|
---|
1014 | //
|
---|
1015 | Status = Private->PciIo->Pci.Read (
|
---|
1016 | Private->PciIo,
|
---|
1017 | EfiPciIoWidthUint16,
|
---|
1018 | PCI_DEVICE_ID_OFFSET,
|
---|
1019 | 1,
|
---|
1020 | &DeviceId
|
---|
1021 | );
|
---|
1022 | ASSERT_EFI_ERROR(Status);
|
---|
1023 |
|
---|
1024 | ASMOutU8(MISC_OUTPUT_REGISTER, 0xc3);
|
---|
1025 | ASMOutU16(SEQ_ADDRESS_REGISTER, 0x0204);
|
---|
1026 |
|
---|
1027 | ASMInU8(INPUT_STATUS_1_REGISTER); // reset attribute address/data flip-flop
|
---|
1028 | ASMOutU8(ATT_ADDRESS_REGISTER, 0); // blank screen using the attribute address register
|
---|
1029 |
|
---|
1030 | ASMOutU16(CRTC_ADDRESS_REGISTER, 0x0011);
|
---|
1031 |
|
---|
1032 | ASMOutU16(SEQ_ADDRESS_REGISTER, 0x0100);
|
---|
1033 | if (ModeData->SeqSettings)
|
---|
1034 | BOUTB(ModeData->SeqSettings, 5, SEQ_ADDRESS_REGISTER, SEQ_DATA_REGISTER);
|
---|
1035 | else
|
---|
1036 | BOUTB(Seq_Default, 5, SEQ_ADDRESS_REGISTER, SEQ_DATA_REGISTER);
|
---|
1037 | ASMOutU16(SEQ_ADDRESS_REGISTER, 0x0300);
|
---|
1038 |
|
---|
1039 | BOUTB(GraphicsController, 9, GRAPH_ADDRESS_REGISTER, GRAPH_DATA_REGISTER);
|
---|
1040 |
|
---|
1041 | ASMInU8(INPUT_STATUS_1_REGISTER); // reset attribute address/data flip-flop
|
---|
1042 | BOUTB(AttributeController, 21, ATT_ADDRESS_REGISTER, ATT_DATA_REGISTER);
|
---|
1043 |
|
---|
1044 | ASMOutU8(MISC_OUTPUT_REGISTER, ModeData->MiscSetting);
|
---|
1045 |
|
---|
1046 | if (ModeData->ColorDepth <= 8)
|
---|
1047 | {
|
---|
1048 | ASMOutU8(DAC_PIXEL_MASK_REGISTER, 0xff);
|
---|
1049 | SetDefaultPalette(Private);
|
---|
1050 | }
|
---|
1051 |
|
---|
1052 | if (!ModeData->CrtcSettings)
|
---|
1053 | {
|
---|
1054 | // No CRTC settings, use VBE
|
---|
1055 | ASMOutU16(VBE_DISPI_IOPORT_INDEX, 0x00); ASMOutU16(VBE_DISPI_IOPORT_DATA, 0xb0c0); // ID
|
---|
1056 | ASMOutU16(VBE_DISPI_IOPORT_INDEX, 0x04); ASMOutU16(VBE_DISPI_IOPORT_DATA, 0); // ENABLE
|
---|
1057 | ASMOutU16(VBE_DISPI_IOPORT_INDEX, 0x01); ASMOutU16(VBE_DISPI_IOPORT_DATA, (UINT16)ModeData->Width); // XRES
|
---|
1058 | ASMOutU16(VBE_DISPI_IOPORT_INDEX, 0x02); ASMOutU16(VBE_DISPI_IOPORT_DATA, (UINT16)ModeData->Height); // YRES
|
---|
1059 | ASMOutU16(VBE_DISPI_IOPORT_INDEX, 0x03); ASMOutU16(VBE_DISPI_IOPORT_DATA, (UINT16)ModeData->ColorDepth); // BPP
|
---|
1060 | ASMOutU16(VBE_DISPI_IOPORT_INDEX, 0x05); ASMOutU16(VBE_DISPI_IOPORT_DATA, 0); // BANK
|
---|
1061 | ASMOutU16(VBE_DISPI_IOPORT_INDEX, 0x06); ASMOutU16(VBE_DISPI_IOPORT_DATA, (UINT16)ModeData->Width); // VIRT_WIDTH
|
---|
1062 | ASMOutU16(VBE_DISPI_IOPORT_INDEX, 0x07); ASMOutU16(VBE_DISPI_IOPORT_DATA, (UINT16)ModeData->Height); // VIRT_HEIGHT
|
---|
1063 | ASMOutU16(VBE_DISPI_IOPORT_INDEX, 0x08); ASMOutU16(VBE_DISPI_IOPORT_DATA, 0); // X_OFFSET
|
---|
1064 | ASMOutU16(VBE_DISPI_IOPORT_INDEX, 0x09); ASMOutU16(VBE_DISPI_IOPORT_DATA, 0); // Y_OFFSET
|
---|
1065 | ASMOutU16(VBE_DISPI_IOPORT_INDEX, 0x04); ASMOutU16(VBE_DISPI_IOPORT_DATA, 1); // ENABLE
|
---|
1066 | /// @todo enabling VBE is automatically tweaking the CRTC, GC, SC, clears the
|
---|
1067 | // screen and at the end unblanks graphics. So make sure that nothing is done
|
---|
1068 | // after this which needs blanking. Way too much magic, but that's how it is...
|
---|
1069 | }
|
---|
1070 | else
|
---|
1071 | {
|
---|
1072 | BOUTB(ModeData->CrtcSettings, 25, CRTC_ADDRESS_REGISTER, CRTC_DATA_REGISTER);
|
---|
1073 | }
|
---|
1074 |
|
---|
1075 | ASMInU8(INPUT_STATUS_1_REGISTER); // reset attribute address/data flip-flop
|
---|
1076 | ASMOutU8(ATT_ADDRESS_REGISTER, 0x20); // unblank screen
|
---|
1077 |
|
---|
1078 | ClearScreen(Private);
|
---|
1079 | }
|
---|
1080 |
|
---|
1081 | /** Aka know as AppleGraphInfoProtocolGuid in other sources. */
|
---|
1082 | #define EFI_UNKNOWN_2_PROTOCOL_GUID \
|
---|
1083 | { 0xE316E100, 0x0751, 0x4C49, {0x90, 0x56, 0x48, 0x6C, 0x7E, 0x47, 0x29, 0x03} }
|
---|
1084 |
|
---|
1085 | EFI_GUID gEfiAppleFrameBufferInfoGuid = EFI_UNKNOWN_2_PROTOCOL_GUID;
|
---|
1086 |
|
---|
1087 | EFI_STATUS EFIAPI
|
---|
1088 | GetFrameBufferInfo(IN APPLE_FRAMEBUFFERINFO_PROTOCOL *This,
|
---|
1089 | OUT UINT32 *BaseAddr,
|
---|
1090 | OUT UINT32 *Something,
|
---|
1091 | OUT UINT32 *RowBytes,
|
---|
1092 | OUT UINT32 *Width,
|
---|
1093 | OUT UINT32 *Height,
|
---|
1094 | OUT UINT32 *Depth)
|
---|
1095 | {
|
---|
1096 | EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *FrameBufDesc;
|
---|
1097 | UINT32 W, H, BPP;
|
---|
1098 | VBOX_VGA_PRIVATE_DATA *Private = This->Private;
|
---|
1099 | UINTN CurrentModeNumber = Private->CurrentMode;
|
---|
1100 | VBOX_VGA_MODE_DATA const *pCurrentMode = &Private->ModeData[CurrentModeNumber];
|
---|
1101 |
|
---|
1102 | W = pCurrentMode->HorizontalResolution;
|
---|
1103 | H = pCurrentMode->VerticalResolution;
|
---|
1104 | BPP = pCurrentMode->ColorDepth;
|
---|
1105 | DEBUG((DEBUG_INFO, "%a:%d GetFrameBufferInfo: %dx%d bpp:%d\n", __FILE__, __LINE__, W, H, BPP));
|
---|
1106 |
|
---|
1107 | Private->PciIo->GetBarAttributes (
|
---|
1108 | Private->PciIo,
|
---|
1109 | Private->BarIndexFB,
|
---|
1110 | NULL,
|
---|
1111 | (VOID**) &FrameBufDesc
|
---|
1112 | );
|
---|
1113 |
|
---|
1114 |
|
---|
1115 | /* EFI firmware remaps it here */
|
---|
1116 | *BaseAddr = (UINT32)FrameBufDesc->AddrRangeMin;
|
---|
1117 | *RowBytes = W * BPP / 8;
|
---|
1118 | *Width = W;
|
---|
1119 | *Height = H;
|
---|
1120 | *Depth = BPP;
|
---|
1121 | // what *Something shall be?
|
---|
1122 |
|
---|
1123 | return EFI_SUCCESS;
|
---|
1124 | }
|
---|
1125 |
|
---|
1126 | EFI_STATUS
|
---|
1127 | EFIAPI
|
---|
1128 | InitializeVBoxVga (
|
---|
1129 | IN EFI_HANDLE ImageHandle,
|
---|
1130 | IN EFI_SYSTEM_TABLE *SystemTable
|
---|
1131 | )
|
---|
1132 | {
|
---|
1133 | EFI_STATUS Status;
|
---|
1134 |
|
---|
1135 | Status = EfiLibInstallDriverBindingComponentName2 (
|
---|
1136 | ImageHandle,
|
---|
1137 | SystemTable,
|
---|
1138 | &gVBoxVgaDriverBinding,
|
---|
1139 | ImageHandle,
|
---|
1140 | &gVBoxVgaComponentName,
|
---|
1141 | &gVBoxVgaComponentName2
|
---|
1142 | );
|
---|
1143 | ASSERT_EFI_ERROR (Status);
|
---|
1144 |
|
---|
1145 | //
|
---|
1146 | // Install EFI Driver Supported EFI Version Protocol required for
|
---|
1147 | // EFI drivers that are on PCI and other plug in cards.
|
---|
1148 | //
|
---|
1149 | gVBoxVgaDriverSupportedEfiVersion.FirmwareVersion = PcdGet32 (PcdDriverSupportedEfiVersion);
|
---|
1150 | Status = gBS->InstallMultipleProtocolInterfaces (
|
---|
1151 | &ImageHandle,
|
---|
1152 | &gEfiDriverSupportedEfiVersionProtocolGuid,
|
---|
1153 | &gVBoxVgaDriverSupportedEfiVersion,
|
---|
1154 | &gEfiAppleFrameBufferInfoGuid,
|
---|
1155 | &gAppleFrameBufferInfo,
|
---|
1156 | NULL
|
---|
1157 | );
|
---|
1158 | ASSERT_EFI_ERROR (Status);
|
---|
1159 |
|
---|
1160 | return Status;
|
---|
1161 | }
|
---|