OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
OcMacInfoLib.c
Go to the documentation of this file.
1
15#include <Uefi.h>
16
17#include <Library/BaseLib.h>
18#include <Library/BaseMemoryLib.h>
19#include <Library/DebugLib.h>
22#include <Library/OcStringLib.h>
23
24#include "MacInfoInternal.h"
25
26STATIC CONST UINT32 mDevicePathsSupported = 1;
27
28STATIC
30 {
31 "Macmini", 0, 3
32 },
33 {
34 "MacBookAir", 0, 2
35 },
36 {
37 "MacBookPro", 4, 3
38 },
39 {
40 "MacBook", 0, 5
41 },
42 {
43 "iMac", 8, 7
44 },
45 {
46 "MacPro", 3, 3
47 },
48 {
49 "Xserve", 2, 2
50 }
51};
52
53STATIC
56 CONST CHAR8 *ProductName
57 )
58{
59 UINTN Start;
60 UINTN End;
61 UINTN Curr;
62 INTN Cmp;
63
66
67 //
68 // Classic binary search in a sorted string list.
69 //
70 Start = 0;
72
73 while (Start <= End) {
74 Curr = (Start + End) / 2;
75 Cmp = AsciiStrCmp (gMacInfoModels[Curr].SystemProductName, ProductName);
76
77 if (Cmp == 0) {
78 return &gMacInfoModels[Curr];
79 } else if (Cmp < 0) {
80 Start = Curr + 1;
81 } else if (Curr > 0) {
82 End = Curr - 1;
83 } else {
84 //
85 // Even the first element does not match, required due to unsigned End.
86 //
87 return NULL;
88 }
89 }
90
91 return NULL;
92}
93
94VOID
96 IN CONST CHAR8 *ProductName,
97 OUT MAC_INFO_DATA *MacInfo
98 )
99{
100 CONST MAC_INFO_INTERNAL_ENTRY *InternalEntry;
101
102 ZeroMem (MacInfo, sizeof (*MacInfo));
103
104 InternalEntry = LookupInternalEntry (ProductName);
105 if (InternalEntry == NULL) {
106 //
107 // Fallback to default model if given ProductName is not found.
108 //
109 InternalEntry = &gMacInfoModels[gMacInfoDefaultModel];
110 }
111
112 //
113 // Fill in DataHub values.
114 //
115 MacInfo->DataHub.PlatformName = "platform";
116 MacInfo->DataHub.SystemProductName = ProductName;
117 MacInfo->DataHub.BoardProduct = InternalEntry->BoardProduct;
118 if (InternalEntry->BoardRevision != MAC_INFO_BOARD_REVISION_MISSING) {
119 MacInfo->DataHub.BoardRevision = &InternalEntry->BoardRevision;
120 }
121
122 MacInfo->DataHub.DevicePathsSupported = &mDevicePathsSupported;
123 //
124 // T2-based macs have no SMC branch or revision.
125 //
126 if (InternalEntry->SmcGeneration < 3) {
127 MacInfo->DataHub.SmcRevision = InternalEntry->SmcRevision;
128 MacInfo->DataHub.SmcBranch = InternalEntry->SmcBranch;
129 }
130
131 MacInfo->DataHub.SmcPlatform = InternalEntry->SmcPlatform;
132
133 MacInfo->Smbios.BIOSVersion = InternalEntry->BIOSVersion;
134 MacInfo->Smbios.BIOSReleaseDate = InternalEntry->BIOSReleaseDate;
135 MacInfo->Smbios.SystemProductName = ProductName;
136 MacInfo->Smbios.SystemVersion = InternalEntry->SystemVersion;
137 MacInfo->Smbios.SystemSKUNumber = InternalEntry->SystemSKUNumber;
138 MacInfo->Smbios.SystemFamily = InternalEntry->SystemFamily;
139 MacInfo->Smbios.BoardProduct = InternalEntry->BoardProduct;
140 MacInfo->Smbios.BoardVersion = InternalEntry->BoardVersion;
141 MacInfo->Smbios.BoardAssetTag = InternalEntry->BoardAssetTag;
142 MacInfo->Smbios.BoardLocationInChassis = InternalEntry->BoardLocationInChassis;
143 MacInfo->Smbios.BoardType = &InternalEntry->BoardType;
144 MacInfo->Smbios.ChassisType = &InternalEntry->ChassisType;
145 MacInfo->Smbios.ChassisVersion = InternalEntry->BoardProduct;
146 MacInfo->Smbios.ChassisAssetTag = InternalEntry->ChassisAssetTag;
147 MacInfo->Smbios.MemoryFormFactor = &InternalEntry->MemoryFormFactor;
148 MacInfo->Smbios.FirmwareFeatures = InternalEntry->FirmwareFeatures;
149 MacInfo->Smbios.FirmwareFeaturesMask = InternalEntry->FirmwareFeaturesMask;
150
151 if (InternalEntry->PlatformFeature != MAC_INFO_PLATFORM_FEATURE_MISSING) {
152 MacInfo->Smbios.PlatformFeature = &InternalEntry->PlatformFeature;
153 }
154}
155
156CONST CHAR8 *
158 IN CONST CHAR8 *ProductName
159 )
160{
161 CONST MAC_INFO_INTERNAL_ENTRY *InternalEntry;
162
163 InternalEntry = LookupInternalEntry (ProductName);
164 if (InternalEntry == NULL) {
165 //
166 // Fallback to default model if given ProductName is not found.
167 //
168 InternalEntry = &gMacInfoModels[gMacInfoDefaultModel];
169 }
170
171 if (InternalEntry->SecureBootModel == NULL) {
172 return "x86legacy";
173 }
174
175 return InternalEntry->SecureBootModel;
176}
177
178CONST CHAR8 *
180 IN CONST CHAR8 *BoardId
181 )
182{
183 UINTN Index;
184
185 for (Index = 0; Index < gMacInfoModelCount; ++Index) {
186 if (AsciiStrCmp (gMacInfoModels[Index].BoardProduct, BoardId) == 0) {
187 if (gMacInfoModels[Index].SecureBootModel != NULL) {
188 return gMacInfoModels[Index].SecureBootModel;
189 }
190
191 break;
192 }
193 }
194
195 //
196 // Note, this will not match some models with multiple board-id values,
197 // but from what we know these models do not support SB anyway.
198 //
199 return "x86legacy";
200}
201
202BOOLEAN
204 IN CONST CHAR8 *ProductName
205 )
206{
207 CONST MAC_INFO_INTERNAL_ENTRY *InternalEntry;
208
209 InternalEntry = LookupInternalEntry (ProductName);
210
211 return InternalEntry != NULL;
212}
213
214BOOLEAN
216 IN CONST CHAR8 *ProductName,
217 IN UINT32 KernelVersion
218 )
219{
220 EFI_STATUS Status;
221 UINT32 Index;
222 UINTN CurrentModelLength;
223 UINTN SystemModelLength;
224 CONST CHAR8 *SystemModelSuffix;
225 CHAR8 *SystemModelSeparator;
226 UINT64 SystemModelMajor;
227
228 ASSERT (ProductName != NULL);
229
230 //
231 // <= 10.5 is always 32-bit, and >= 10.8 is always 64-bit.
232 //
234 return FALSE;
236 return TRUE;
237 }
238
239 SystemModelLength = AsciiStrLen (ProductName);
240
241 for (Index = 0; Index < ARRAY_SIZE (gMac64BitModels); Index++) {
242 //
243 // Ensure name is at least as big as what we have in the table, plus a number character.
244 //
245 CurrentModelLength = AsciiStrLen (gMac64BitModels[Index].ModelName);
246 if (SystemModelLength <= CurrentModelLength + 1) {
247 continue;
248 }
249
250 if (AsciiStrnCmp (ProductName, gMac64BitModels[Index].ModelName, CurrentModelLength) == 0) {
251 SystemModelSuffix = &ProductName[CurrentModelLength];
252 if (!IsAsciiNumber (SystemModelSuffix[0])) {
253 continue;
254 }
255
256 SystemModelSeparator = AsciiStrStr (SystemModelSuffix, ",");
257 Status = AsciiStrDecimalToUint64S (SystemModelSuffix, &SystemModelSeparator, &SystemModelMajor);
258 if (!EFI_ERROR (Status)) {
260 return gMac64BitModels[Index].SnowLeoMin64 != 0 && SystemModelMajor >= gMac64BitModels[Index].SnowLeoMin64;
262 return gMac64BitModels[Index].LionMin64 != 0 && SystemModelMajor >= gMac64BitModels[Index].LionMin64;
263 }
264 }
265 }
266 }
267
268 //
269 // Default behavior allows 64-bit on both 10.6 and 10.7 if the model is not found.
270 //
271 return TRUE;
272}
#define ARRAY_SIZE(Array)
Definition AppleMacEfi.h:34
UINT64 Start
EFI_DEVICE_PATH_PROTOCOL End
CONST UINTN gMacInfoModelCount
CONST MAC_INFO_INTERNAL_ENTRY gMacInfoModels[]
CONST UINTN gMacInfoDefaultModel
CHAR16 BoardId[7]
Definition BiosId.h:39
STATIC UINT32 KernelVersion
Definition KextInject.c:28
#define MAC_INFO_BOARD_REVISION_MISSING
#define MAC_INFO_PLATFORM_FEATURE_MISSING
#define KERNEL_VERSION_SNOW_LEOPARD_MIN
#define KERNEL_VERSION_MOUNTAIN_LION_MIN
#define KERNEL_VERSION_SNOW_LEOPARD_MAX
BOOLEAN OcMatchDarwinVersion(IN UINT32 CurrentVersion OPTIONAL, IN UINT32 MinVersion OPTIONAL, IN UINT32 MaxVersion OPTIONAL)
#define KERNEL_VERSION_LION_MAX
#define KERNEL_VERSION_LEOPARD_MAX
#define KERNEL_VERSION_LION_MIN
CONST CHAR8 * GetSecureBootModelFromBoardId(IN CONST CHAR8 *BoardId)
CONST CHAR8 * GetSecureBootModel(IN CONST CHAR8 *ProductName)
VOID GetMacInfo(IN CONST CHAR8 *ProductName, OUT MAC_INFO_DATA *MacInfo)
BOOLEAN IsMacModel64BitCompatible(IN CONST CHAR8 *ProductName, IN UINT32 KernelVersion)
STATIC CONST MAC_INFO_INTERNAL_ENTRY * LookupInternalEntry(CONST CHAR8 *ProductName)
STATIC CONST MAC_INFO_64BIT_COMPAT_ENTRY gMac64BitModels[]
BOOLEAN HasMacInfo(IN CONST CHAR8 *ProductName)
STATIC CONST UINT32 mDevicePathsSupported
BOOLEAN IsAsciiNumber(IN CHAR8 Char)
Definition OcAsciiLib.c:78
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
#define ASSERT(x)
Definition coder.h:55
CONST CHAR8 *CONST SecureBootModel