1 | /* $Id: Cpu.c 98103 2023-01-17 14:15:46Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Cpu.c - VirtualBox CPU descriptors
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2009-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 |
|
---|
38 | /*********************************************************************************************************************************
|
---|
39 | * Header Files *
|
---|
40 | *********************************************************************************************************************************/
|
---|
41 | #include <Library/DebugLib.h>
|
---|
42 | #include <Library/UefiBootServicesTableLib.h>
|
---|
43 | #include <Library/BaseMemoryLib.h>
|
---|
44 | #include <Library/MemoryAllocationLib.h>
|
---|
45 | #include <Library/UefiLib.h>
|
---|
46 | #include <Library/HiiLib.h>
|
---|
47 | #include <Library/BaseLib.h>
|
---|
48 |
|
---|
49 | #include <Protocol/Cpu.h>
|
---|
50 |
|
---|
51 | #include "DataHub.h"
|
---|
52 |
|
---|
53 | #define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100
|
---|
54 |
|
---|
55 | EFI_GUID gEfiAppleMagicHubGuid = {
|
---|
56 | 0x64517cc8, 0x6561, 0x4051, {0xb0, 0x3c, 0x59, 0x64, 0xb6, 0x0f, 0x4c, 0x7a }
|
---|
57 | };
|
---|
58 |
|
---|
59 | EFI_GUID gEfiProcessorSubClassGuid = {
|
---|
60 | 0x26fdeb7e, 0xb8af, 0x4ccf, { 0xaa, 0x97, 0x02, 0x63, 0x3c, 0xe4, 0x8c, 0xa7 }
|
---|
61 | };
|
---|
62 |
|
---|
63 | #pragma pack(1)
|
---|
64 | typedef struct {
|
---|
65 | UINT8 Pad0[0x10]; /* 0x48 */
|
---|
66 | UINT32 NameLen; /* 0x58 , in bytes */
|
---|
67 | UINT32 ValLen; /* 0x5c */
|
---|
68 | UINT8 Data[1]; /* 0x60 Name Value */
|
---|
69 | } MAGIC_HUB_DATA;
|
---|
70 | #pragma pack()
|
---|
71 |
|
---|
72 | UINT32
|
---|
73 | CopyRecord(MAGIC_HUB_DATA* Rec, const CHAR16* Name, VOID* Val, UINT32 ValLen)
|
---|
74 | {
|
---|
75 | Rec->NameLen = (UINT32)StrLen(Name) * sizeof(CHAR16);
|
---|
76 | Rec->ValLen = ValLen;
|
---|
77 | CopyMem(Rec->Data, Name, Rec->NameLen);
|
---|
78 | CopyMem(Rec->Data + Rec->NameLen, Val, ValLen);
|
---|
79 |
|
---|
80 | return 0x10 + 4 + 4 + Rec->NameLen + Rec->ValLen;
|
---|
81 | }
|
---|
82 |
|
---|
83 | EFI_STATUS EFIAPI
|
---|
84 | LogData(EFI_DATA_HUB_PROTOCOL *DataHub,
|
---|
85 | MAGIC_HUB_DATA *MagicData,
|
---|
86 | CHAR16 *Name,
|
---|
87 | VOID *Data,
|
---|
88 | UINT32 DataSize)
|
---|
89 | {
|
---|
90 | UINT32 RecordSize;
|
---|
91 | EFI_STATUS Status;
|
---|
92 |
|
---|
93 | RecordSize = CopyRecord(MagicData, Name, Data, DataSize);
|
---|
94 | Status = DataHub->LogData (
|
---|
95 | DataHub,
|
---|
96 | &gEfiProcessorSubClassGuid, /* DataRecordGuid */
|
---|
97 | &gEfiAppleMagicHubGuid, /* ProducerName */
|
---|
98 | EFI_DATA_CLASS_DATA,
|
---|
99 | MagicData,
|
---|
100 | RecordSize
|
---|
101 | );
|
---|
102 | ASSERT_EFI_ERROR (Status);
|
---|
103 |
|
---|
104 | return Status;
|
---|
105 | }
|
---|
106 |
|
---|
107 | EFI_STATUS EFIAPI
|
---|
108 | CpuUpdateDataHub(EFI_BOOT_SERVICES * bs,
|
---|
109 | UINT64 FSBFrequency,
|
---|
110 | UINT64 TSCFrequency,
|
---|
111 | UINT64 CPUFrequency)
|
---|
112 | {
|
---|
113 | EFI_STATUS Status;
|
---|
114 | EFI_DATA_HUB_PROTOCOL *DataHub;
|
---|
115 | MAGIC_HUB_DATA *MagicData;
|
---|
116 | UINT32 Supported = 1;
|
---|
117 | //
|
---|
118 | // Locate DataHub protocol.
|
---|
119 | //
|
---|
120 | Status = bs->LocateProtocol (&gEfiDataHubProtocolGuid, NULL, (VOID**)&DataHub);
|
---|
121 | if (EFI_ERROR (Status)) {
|
---|
122 | return Status;
|
---|
123 | }
|
---|
124 |
|
---|
125 | MagicData = (MAGIC_HUB_DATA*)AllocatePool (0x200);
|
---|
126 | if (MagicData == NULL) {
|
---|
127 | return EFI_OUT_OF_RESOURCES;
|
---|
128 | }
|
---|
129 |
|
---|
130 | // Log data in format some OSes like
|
---|
131 | LogData(DataHub, MagicData, L"FSBFrequency", &FSBFrequency, sizeof(FSBFrequency));
|
---|
132 | // do that twice, as last variable read not really accounted for
|
---|
133 | LogData(DataHub, MagicData, L"FSBFrequency", &FSBFrequency, sizeof(FSBFrequency));
|
---|
134 | LogData(DataHub, MagicData, L"TSCFrequency", &TSCFrequency, sizeof(TSCFrequency));
|
---|
135 | LogData(DataHub, MagicData, L"CPUFrequency", &CPUFrequency, sizeof(CPUFrequency));
|
---|
136 |
|
---|
137 | // The following is required for OS X to construct a SATA boot path. UEFI 2.0 (published
|
---|
138 | // in Jan 2006, same time as the first Intel Macs) did not standardize SATA device paths;
|
---|
139 | // if DevicePathsSupported is not set, OS X will create ATA boot paths which will fail
|
---|
140 | // to boot
|
---|
141 | LogData(DataHub, MagicData, L"DevicePathsSupported", &Supported, sizeof(Supported));
|
---|
142 |
|
---|
143 | FreePool (MagicData);
|
---|
144 |
|
---|
145 | return EFI_SUCCESS;
|
---|
146 | }
|
---|