VirtualBox

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

Last change on this file since 80934 was 80902, checked in by vboxsync, 5 years ago

EFI/FirmwareNew: Implement support for the DataHub protocol which was removed in newer EDK versions and enable the VBoxAppleSim DXE driver again as it is required for macOS to boot

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/* $Id: Cpu.c 80902 2019-09-18 21:02:07Z vboxsync $ */
2/** @file
3 * Cpu.c - VirtualBox CPU descriptors
4 */
5
6/*
7 * Copyright (C) 2009-2019 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/DebugLib.h>
32#include <Library/UefiBootServicesTableLib.h>
33#include <Library/BaseMemoryLib.h>
34#include <Library/MemoryAllocationLib.h>
35#include <Library/UefiLib.h>
36#include <Library/HiiLib.h>
37#include <Library/BaseLib.h>
38
39#include <Protocol/Cpu.h>
40
41#include "DataHub.h"
42
43#define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100
44
45EFI_GUID gEfiAppleMagicHubGuid = {
46 0x64517cc8, 0x6561, 0x4051, {0xb0, 0x3c, 0x59, 0x64, 0xb6, 0x0f, 0x4c, 0x7a }
47};
48
49EFI_GUID gEfiProcessorSubClassGuid = {
50 0x26fdeb7e, 0xb8af, 0x4ccf, { 0xaa, 0x97, 0x02, 0x63, 0x3c, 0xe4, 0x8c, 0xa7 }
51};
52
53#pragma pack(1)
54typedef struct {
55 UINT8 Pad0[0x10]; /* 0x48 */
56 UINT32 NameLen; /* 0x58 , in bytes */
57 UINT32 ValLen; /* 0x5c */
58 UINT8 Data[1]; /* 0x60 Name Value */
59} MAGIC_HUB_DATA;
60#pragma pack()
61
62UINT32
63CopyRecord(MAGIC_HUB_DATA* Rec, const CHAR16* Name, VOID* Val, UINT32 ValLen)
64{
65 Rec->NameLen = (UINT32)StrLen(Name) * sizeof(CHAR16);
66 Rec->ValLen = ValLen;
67 CopyMem(Rec->Data, Name, Rec->NameLen);
68 CopyMem(Rec->Data + Rec->NameLen, Val, ValLen);
69
70 return 0x10 + 4 + 4 + Rec->NameLen + Rec->ValLen;
71}
72
73EFI_STATUS EFIAPI
74LogData(EFI_DATA_HUB_PROTOCOL *DataHub,
75 MAGIC_HUB_DATA *MagicData,
76 CHAR16 *Name,
77 VOID *Data,
78 UINT32 DataSize)
79{
80 UINT32 RecordSize;
81 EFI_STATUS Status;
82
83 RecordSize = CopyRecord(MagicData, Name, Data, DataSize);
84 Status = DataHub->LogData (
85 DataHub,
86 &gEfiProcessorSubClassGuid, /* DataRecordGuid */
87 &gEfiAppleMagicHubGuid, /* ProducerName */
88 EFI_DATA_CLASS_DATA,
89 MagicData,
90 RecordSize
91 );
92 ASSERT_EFI_ERROR (Status);
93
94 return Status;
95}
96
97EFI_STATUS EFIAPI
98CpuUpdateDataHub(EFI_BOOT_SERVICES * bs,
99 UINT64 FSBFrequency,
100 UINT64 TSCFrequency,
101 UINT64 CPUFrequency)
102{
103 EFI_STATUS Status;
104 EFI_DATA_HUB_PROTOCOL *DataHub;
105 MAGIC_HUB_DATA *MagicData;
106 //
107 // Locate DataHub protocol.
108 //
109 Status = bs->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID**)&DataHub);
110 if (EFI_ERROR (Status)) {
111 return Status;
112 }
113
114 MagicData = (MAGIC_HUB_DATA*)AllocatePool (0x200);
115 if (MagicData == NULL) {
116 return EFI_OUT_OF_RESOURCES;
117 }
118
119 // Log data in format some OSes like
120 LogData(DataHub, MagicData, L"FSBFrequency", &FSBFrequency, sizeof(FSBFrequency));
121 // do that twice, as last variable read not really accounted for
122 LogData(DataHub, MagicData, L"FSBFrequency", &FSBFrequency, sizeof(FSBFrequency));
123 LogData(DataHub, MagicData, L"TSCFrequency", &TSCFrequency, sizeof(TSCFrequency));
124 LogData(DataHub, MagicData, L"CPUFrequency", &CPUFrequency, sizeof(CPUFrequency));
125
126 FreePool (MagicData);
127
128 return EFI_SUCCESS;
129}
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