1 | /* $Id: VBoxConsole.c 52069 2014-07-17 08:40:36Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBoxConsole.c - Helper driver waiting for Ready to Boot event to switch graphic mode into user-defined one.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2010 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 | #include "VBoxConsole.h"
|
---|
28 | #include "VBoxPkg.h"
|
---|
29 | #include "DevEFI.h"
|
---|
30 | #include "iprt/asm.h"
|
---|
31 |
|
---|
32 | /* @todo understand the reasons why TextOutputProtocol.SetMode isn't enough to switch mode. */
|
---|
33 | #define VBOX_CONSOLE_VAR L"VBOX_CONSOLE_VAR"
|
---|
34 | /*b53865fd-b76c-4433-9e85-c0cadf65aab8*/
|
---|
35 | static EFI_GUID gVBoxConsoleVarGuid = { 0xb53865fd, 0xb76c, 0x4433, { 0x9e, 0x85, 0xc0, 0xca, 0xdf, 0x65, 0xaa, 0xb8}};
|
---|
36 |
|
---|
37 | static EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL *TextOutputProtocol;
|
---|
38 | static EFI_GRAPHICS_OUTPUT_PROTOCOL *Gop;
|
---|
39 | static EFI_UGA_DRAW_PROTOCOL *Uga;
|
---|
40 |
|
---|
41 | /*
|
---|
42 | * @todo move this function to the library.
|
---|
43 | */
|
---|
44 | static UINT32
|
---|
45 | GetVmVariable(UINT32 Variable, CHAR8* Buffer, UINT32 Size )
|
---|
46 | {
|
---|
47 | UINT32 VarLen, i;
|
---|
48 |
|
---|
49 |
|
---|
50 | ASMOutU32(EFI_INFO_PORT, Variable);
|
---|
51 | VarLen = ASMInU32(EFI_INFO_PORT);
|
---|
52 |
|
---|
53 | for (i=0; i < VarLen && i < Size; i++)
|
---|
54 | {
|
---|
55 | Buffer[i] = ASMInU8(EFI_INFO_PORT);
|
---|
56 | }
|
---|
57 |
|
---|
58 | return VarLen;
|
---|
59 | }
|
---|
60 |
|
---|
61 | static VOID
|
---|
62 | EFIAPI
|
---|
63 | ConsoleSwitchMode (
|
---|
64 | IN EFI_EVENT Event,
|
---|
65 | IN VOID *Context
|
---|
66 | )
|
---|
67 | {
|
---|
68 | EFI_STATUS r = EFI_NOT_FOUND; /* Neither GOP nor UGA is found*/
|
---|
69 | EFI_TPL OldTpl;
|
---|
70 | OldTpl = gBS->RaiseTPL (TPL_NOTIFY);
|
---|
71 | DEBUG((DEBUG_INFO, "%a:%d - SwitchMode\n", __FILE__, __LINE__));
|
---|
72 | if (Gop)
|
---|
73 | {
|
---|
74 | UINT32 mode = 2;
|
---|
75 | GetVmVariable(EFI_INFO_INDEX_GOP_MODE, (CHAR8 *)&mode, sizeof(UINT32));
|
---|
76 | r = Gop->SetMode(Gop, mode);
|
---|
77 | }
|
---|
78 | else if (Uga)
|
---|
79 | {
|
---|
80 | UINT32 H = 1027;
|
---|
81 | UINT32 V = 768;
|
---|
82 | GetVmVariable(EFI_INFO_INDEX_UGA_HORIZONTAL_RESOLUTION, (CHAR8 *)&H, sizeof(UINT32));
|
---|
83 | GetVmVariable(EFI_INFO_INDEX_UGA_VERTICAL_RESOLUTION, (CHAR8 *)&V, sizeof(UINT32));
|
---|
84 | r = Uga->SetMode(Uga, H, V, 32, 60);
|
---|
85 | }
|
---|
86 | if(EFI_ERROR(r))
|
---|
87 | {
|
---|
88 | DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
|
---|
89 | goto done;
|
---|
90 | }
|
---|
91 | r = TextOutputProtocol->SetMode(TextOutputProtocol, TextOutputProtocol->Mode->MaxMode);
|
---|
92 | if(EFI_ERROR(r))
|
---|
93 | {
|
---|
94 | DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
|
---|
95 | goto done;
|
---|
96 | }
|
---|
97 | done:
|
---|
98 | gBS->RestoreTPL (OldTpl);
|
---|
99 | return;
|
---|
100 | }
|
---|
101 |
|
---|
102 | EFI_STATUS
|
---|
103 | EFIAPI
|
---|
104 | VBoxConsoleInit(EFI_HANDLE hImage, EFI_SYSTEM_TABLE *pSysTable)
|
---|
105 | {
|
---|
106 | EFI_STATUS r;
|
---|
107 | UINT32 val;
|
---|
108 | EFI_EVENT event;
|
---|
109 | UINTN size = sizeof(UINT32);
|
---|
110 | DEBUG((DEBUG_INFO, "%a:%d - STARTING\n", __FILE__, __LINE__));
|
---|
111 | r = gRT->GetVariable(VBOX_CONSOLE_VAR, &gVBoxConsoleVarGuid, NULL, &size, &val);
|
---|
112 | if ( EFI_ERROR(r)
|
---|
113 | && r == EFI_NOT_FOUND)
|
---|
114 | {
|
---|
115 | size = sizeof(UINT32);
|
---|
116 | val = 1;
|
---|
117 | r = gRT->SetVariable(VBOX_CONSOLE_VAR, &gVBoxConsoleVarGuid, EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS, size, &val);
|
---|
118 | if (EFI_ERROR(r))
|
---|
119 | {
|
---|
120 | DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
|
---|
121 | return r;
|
---|
122 | }
|
---|
123 |
|
---|
124 | r = gBS->LocateProtocol(&gEfiSimpleTextOutProtocolGuid, NULL, (VOID **)&TextOutputProtocol);
|
---|
125 | if(EFI_ERROR(r))
|
---|
126 | {
|
---|
127 | DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
|
---|
128 | }
|
---|
129 |
|
---|
130 | r = gBS->LocateProtocol(&gEfiUgaDrawProtocolGuid, NULL, (VOID **)&Uga);
|
---|
131 | if(EFI_ERROR(r))
|
---|
132 | {
|
---|
133 | DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
|
---|
134 | }
|
---|
135 | r = gBS->LocateProtocol(&gEfiGraphicsOutputProtocolGuid, NULL, (VOID **)&Gop);
|
---|
136 | if(EFI_ERROR(r))
|
---|
137 | {
|
---|
138 | DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
|
---|
139 | }
|
---|
140 | ASSERT((Uga || Gop));
|
---|
141 | r = gBS->CreateEventEx(EVT_NOTIFY_SIGNAL, TPL_NOTIFY, ConsoleSwitchMode, NULL, &gEfiEventReadyToBootGuid, &event);
|
---|
142 | if (EFI_ERROR(r))
|
---|
143 | {
|
---|
144 | DEBUG((DEBUG_INFO, "%a:%d - %r\n", __FILE__, __LINE__, r));
|
---|
145 | return r;
|
---|
146 | }
|
---|
147 | return r;
|
---|
148 | }
|
---|
149 | if (!EFI_ERROR(r))
|
---|
150 | {
|
---|
151 | return EFI_ALREADY_STARTED;
|
---|
152 | }
|
---|
153 | return r;
|
---|
154 | }
|
---|
155 |
|
---|
156 | EFI_STATUS
|
---|
157 | EFIAPI
|
---|
158 | VBoxConsoleFini(EFI_HANDLE hImage)
|
---|
159 | {
|
---|
160 | return EFI_SUCCESS;
|
---|
161 | }
|
---|
162 |
|
---|