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