VirtualBox

source: vbox/trunk/src/VBox/Devices/EFI/Firmware/VBoxPkg/VBoxAppleSim/VBoxAppleSim.c@ 48674

Last change on this file since 48674 was 48674, checked in by vboxsync, 11 years ago

EFI: Export newly imported tinaocore UEFI sources to OSE.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.3 KB
Line 
1/* $Id: VBoxAppleSim.c 48674 2013-09-25 08:26:15Z vboxsync $ */
2/** @file
3 * VBoxAppleSim.c - VirtualBox Apple Firmware simulation support
4 */
5
6/*
7 * Copyright (C) 2010-2011 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/*******************************************************************************
29* Header Files *
30*******************************************************************************/
31#include <Library/BaseMemoryLib.h>
32#include <Library/DebugLib.h>
33#include <Library/UefiBootServicesTableLib.h>
34#include <Library/UefiLib.h>
35
36#include <Protocol/DevicePathToText.h>
37
38#include <IndustryStandard/Acpi10.h>
39#include <IndustryStandard/Acpi20.h>
40#include <IndustryStandard/SmBios.h>
41
42#include <Guid/SmBios.h>
43#include <Guid/Acpi.h>
44#include <Guid/Mps.h>
45
46#include "VBoxPkg.h"
47#include "DevEFI.h"
48#include "iprt/asm.h"
49
50
51/*
52 * External functions
53 */
54EFI_STATUS EFIAPI
55CpuUpdateDataHub(EFI_BOOT_SERVICES * bs,
56 UINT64 FSBFrequency,
57 UINT64 TSCFrequency,
58 UINT64 CPUFrequency);
59
60EFI_STATUS EFIAPI
61InitializeConsoleSim (IN EFI_HANDLE ImageHandle,
62 IN EFI_SYSTEM_TABLE *SystemTable);
63
64
65/*
66 * Internal Functions *
67 */
68static UINT32
69GetVmVariable(UINT32 Variable, CHAR8* Buffer, UINT32 Size )
70{
71 UINT32 VarLen, i;
72
73
74 ASMOutU32(EFI_INFO_PORT, Variable);
75 VarLen = ASMInU32(EFI_INFO_PORT);
76
77 for (i=0; i < VarLen && i < Size; i++)
78 {
79 Buffer[i] = ASMInU8(EFI_INFO_PORT);
80 }
81
82 return VarLen;
83}
84
85/*
86 * GUIDs
87 */
88EFI_GUID gEfiAppleNvramGuid = {
89 0x4D1EDE05, 0x38C7, 0x4A6A, {0x9C, 0xC6, 0x4B, 0xCC, 0xA8, 0xB3, 0x8C, 0x14 }
90};
91
92EFI_GUID gEfiAppleBootGuid = {
93 0x7C436110, 0xAB2A, 0x4BBB, {0xA8, 0x80, 0xFE, 0x41, 0x99, 0x5C, 0x9F, 0x82}
94};
95
96EFI_GUID gEfiAppleVarGuid = {
97 0x91BD12FE, 0xF6C3, 0x44FB, {0xA5, 0xB7, 0x51, 0x22, 0xAB, 0x30, 0x3A, 0xE0}
98};
99
100EFI_GUID gEfiUnknown1ProtocolGuid = {
101 0xDD8E06AC, 0x00E2, 0x49A9, {0x88, 0x8F, 0xFA, 0x46, 0xDE, 0xD4, 0x0A, 0x52}
102};
103
104/*
105 * Typedefs
106 */
107typedef struct _APPLE_GETVAR_PROTOCOL APPLE_GETVAR_PROTOCOL;
108
109typedef
110EFI_STATUS
111(EFIAPI *APPLE_GETVAR_PROTOCOL_GET_DEVICE_PROPS) (
112 IN APPLE_GETVAR_PROTOCOL *This,
113 IN CHAR8 *Buffer,
114 IN OUT UINT32 *BufferSize);
115
116
117struct _APPLE_GETVAR_PROTOCOL {
118 EFI_STATUS(EFIAPI *Unknown0)(IN VOID *);
119 EFI_STATUS(EFIAPI *Unknown1)(IN VOID *);
120 EFI_STATUS(EFIAPI *Unknown2)(IN VOID *);
121 EFI_STATUS(EFIAPI *Unknown3)(IN VOID *);
122 EFI_STATUS(EFIAPI *Unknown4)(IN VOID *);
123 APPLE_GETVAR_PROTOCOL_GET_DEVICE_PROPS GetDevProps;
124};
125
126
127#define IMPL_STUB(iface, num) \
128 EFI_STATUS EFIAPI \
129 iface##Unknown##num(IN VOID *This) \
130 { \
131 Print(L"Unknown%d of %a called", num, #iface); \
132 return EFI_SUCCESS; \
133 }
134
135IMPL_STUB(GetVar, 0)
136IMPL_STUB(GetVar, 1)
137IMPL_STUB(GetVar, 2)
138IMPL_STUB(GetVar, 3)
139IMPL_STUB(GetVar, 4)
140
141EFI_STATUS EFIAPI
142GetDeviceProps(IN APPLE_GETVAR_PROTOCOL *This,
143 IN CHAR8 *Buffer,
144 IN OUT UINT32 *BufferSize)
145{
146 UINT32 BufLen = *BufferSize, DataLen;
147
148 DataLen = GetVmVariable(EFI_INFO_INDEX_DEVICE_PROPS, Buffer, BufLen);
149 *BufferSize = DataLen;
150
151 if (DataLen > BufLen)
152 return EFI_BUFFER_TOO_SMALL;
153
154 return EFI_SUCCESS;
155}
156
157APPLE_GETVAR_PROTOCOL gPrivateVarHandler =
158{
159 GetVarUnknown0,
160 GetVarUnknown1,
161 GetVarUnknown2,
162 GetVarUnknown3,
163 GetVarUnknown4,
164 GetDeviceProps
165};
166
167EFI_STATUS EFIAPI
168UnknownHandlerImpl()
169{
170 Print(L"Unknown called\n");
171 return EFI_SUCCESS;
172}
173
174/* array of pointers to function */
175EFI_STATUS (EFIAPI *gUnknownProtoHandler[])() =
176{
177 UnknownHandlerImpl,
178 UnknownHandlerImpl,
179 UnknownHandlerImpl,
180 UnknownHandlerImpl,
181 UnknownHandlerImpl,
182 UnknownHandlerImpl,
183 UnknownHandlerImpl,
184 UnknownHandlerImpl,
185 UnknownHandlerImpl,
186 UnknownHandlerImpl,
187 UnknownHandlerImpl,
188 UnknownHandlerImpl,
189 UnknownHandlerImpl,
190 UnknownHandlerImpl,
191 UnknownHandlerImpl,
192 UnknownHandlerImpl,
193 UnknownHandlerImpl,
194 UnknownHandlerImpl
195};
196
197EFI_STATUS EFIAPI
198SetPrivateVarProto(IN EFI_HANDLE ImageHandle, EFI_BOOT_SERVICES * bs)
199{
200 EFI_STATUS rc;
201
202 rc = gBS->InstallMultipleProtocolInterfaces (
203 &ImageHandle,
204 &gEfiAppleVarGuid,
205 &gPrivateVarHandler,
206 NULL
207 );
208 ASSERT_EFI_ERROR (rc);
209
210 return EFI_SUCCESS;
211}
212
213EFI_STATUS EFIAPI
214SetProperVariables(IN EFI_HANDLE ImageHandle, EFI_RUNTIME_SERVICES * rs)
215{
216 EFI_STATUS rc;
217 UINT32 vBackgroundClear = 0x00000000;
218 UINT32 vFwFeatures = 0x80000015;
219 UINT32 vFwFeaturesMask = 0x800003ff;
220
221 // -legacy acpi=0xffffffff acpi_debug=0xfffffff panic_io_port=0xef11 io=0xfffffffe trace=4096 io=0xffffffef -v serial=2 serialbaud=9600
222 // 0x10 makes kdb default, thus 0x15e for kdb, 0x14e for gdb
223
224 //static const CHAR8 vBootArgs[] = "debug=0x15e keepsyms=1 acpi=0xffffffff acpi_debug=0xff acpi_level=7 -v -x32 -s"; // or just "debug=0x8 -legacy"
225 // 0x14e for serial output
226 //static const CHAR8 vDefBootArgs[] = "debug=0x146 keepsyms=1 -v -serial=0x1";
227 static const CHAR8 vDefBootArgs[] = "keepsyms=1 -v -serial=0x1";
228 CHAR8 vBootArgs[256];
229 UINT32 BootArgsLen;
230
231 BootArgsLen = GetVmVariable(EFI_INFO_INDEX_BOOT_ARGS, vBootArgs, sizeof vBootArgs);
232 if (BootArgsLen <= 1)
233 {
234 BootArgsLen = sizeof vDefBootArgs;
235 CopyMem(vBootArgs, vDefBootArgs, BootArgsLen);
236 }
237 rc = rs->SetVariable(L"BackgroundClear",
238 &gEfiAppleNvramGuid,
239 /* EFI_VARIABLE_NON_VOLATILE | */ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
240 sizeof(vBackgroundClear), &vBackgroundClear);
241
242 rc = rs->SetVariable(L"FirmwareFeatures",
243 &gEfiAppleNvramGuid,
244 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
245 sizeof(vFwFeatures), &vFwFeatures);
246
247 rc = rs->SetVariable(L"FirmwareFeaturesMask",
248 &gEfiAppleNvramGuid,
249 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
250 sizeof(vFwFeaturesMask), &vFwFeaturesMask);
251
252 rc = rs->SetVariable(L"boot-args",
253 &gEfiAppleBootGuid,
254 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS,
255 BootArgsLen, &vBootArgs);
256
257 return EFI_SUCCESS;
258}
259
260/**
261 * VBoxInitAppleSim entry point.
262 *
263 * @returns EFI status code.
264 *
265 * @param ImageHandle The image handle.
266 * @param SystemTable The system table pointer.
267 */
268EFI_STATUS EFIAPI
269VBoxInitAppleSim(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
270{
271 EFI_STATUS rc;
272 UINT64 FSBFrequency;
273 UINT64 TSCFrequency;
274 UINT64 CPUFrequency;
275
276 rc = SetProperVariables(ImageHandle, SystemTable->RuntimeServices);
277 ASSERT_EFI_ERROR (rc);
278
279 rc = SetPrivateVarProto(ImageHandle, gBS);
280 ASSERT_EFI_ERROR (rc);
281
282 GetVmVariable(EFI_INFO_INDEX_FSB_FREQUENCY, (CHAR8*)&FSBFrequency, sizeof FSBFrequency);
283 GetVmVariable(EFI_INFO_INDEX_TSC_FREQUENCY, (CHAR8*)&TSCFrequency, sizeof TSCFrequency);
284 GetVmVariable(EFI_INFO_INDEX_CPU_FREQUENCY, (CHAR8*)&CPUFrequency, sizeof CPUFrequency);
285
286 rc = CpuUpdateDataHub(gBS, FSBFrequency, TSCFrequency, CPUFrequency);
287 ASSERT_EFI_ERROR (rc);
288
289 rc = InitializeConsoleSim(ImageHandle, SystemTable);
290 ASSERT_EFI_ERROR (rc);
291
292 rc = gBS->InstallMultipleProtocolInterfaces (
293 &ImageHandle,
294 &gEfiUnknown1ProtocolGuid,
295 gUnknownProtoHandler,
296 NULL
297 );
298 ASSERT_EFI_ERROR (rc);
299
300 return EFI_SUCCESS;
301}
302
303EFI_STATUS EFIAPI
304VBoxDeinitAppleSim(IN EFI_HANDLE ImageHandle)
305{
306 return EFI_SUCCESS;
307}
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