OpenCore  1.0.4
OpenCore Bootloader
Loading...
Searching...
No Matches
AppleCpuSupport.c
Go to the documentation of this file.
1
15#include <Uefi.h>
16
18#include <Library/BaseLib.h>
19#include <Library/OcCpuLib.h>
20#include <Library/OcStringLib.h>
22
23#include "OcCpuInternals.h"
24
25UINT8
27 IN CONST CHAR8 *BrandString
28 )
29{
30 CONST CHAR8 *BrandInfix;
31
32 BrandInfix = AsciiStrStr (BrandString, "Core");
33 if (BrandInfix != NULL) {
34 while ((*BrandInfix != ' ') && (*BrandInfix != '\0')) {
35 ++BrandInfix;
36 }
37
38 while (*BrandInfix == ' ') {
39 ++BrandInfix;
40 }
41
42 if (AsciiStrnCmp (BrandInfix, "i7", L_STR_LEN ("i7")) == 0) {
44 }
45
46 if (AsciiStrnCmp (BrandInfix, "i5", L_STR_LEN ("i5")) == 0) {
48 }
49
50 if (AsciiStrnCmp (BrandInfix, "i3", L_STR_LEN ("i3")) == 0) {
52 }
53
54 if (AsciiStrnCmp (BrandInfix, "i9", L_STR_LEN ("i9")) == 0) {
56 }
57
58 if (AsciiStrnCmp (BrandInfix, "m3", L_STR_LEN ("m3")) == 0) {
60 }
61
62 if (AsciiStrnCmp (BrandInfix, "m5", L_STR_LEN ("m5")) == 0) {
64 }
65
66 if (AsciiStrnCmp (BrandInfix, "m7", L_STR_LEN ("m7")) == 0) {
68 }
69
70 if (AsciiStrnCmp (BrandInfix, "M", L_STR_LEN ("M")) == 0) {
72 }
73
74 if (AsciiStrnCmp (BrandInfix, "Duo", L_STR_LEN ("Duo")) == 0) {
76 }
77
78 if (AsciiStrnCmp (BrandInfix, "Quad", L_STR_LEN ("Quad")) == 0) {
80 }
81
83 }
84
85 BrandInfix = AsciiStrStr (BrandString, "Xeon");
86 if (BrandInfix != NULL) {
87 while ((*BrandInfix != ' ') && (*BrandInfix != '\0')) {
88 ++BrandInfix;
89 }
90
91 while (*BrandInfix == ' ') {
92 ++BrandInfix;
93 }
94
95 //
96 // Support Xeon Scalable chips: Xeon(R) Gold 6136 CPU
97 //
98 if ((AsciiStrnCmp (BrandInfix, "Bronze", L_STR_LEN ("Bronze")) == 0) ||
99 (AsciiStrnCmp (BrandInfix, "Silver", L_STR_LEN ("Silver")) == 0) ||
100 (AsciiStrnCmp (BrandInfix, "Gold", L_STR_LEN ("Gold")) == 0) ||
101 (AsciiStrnCmp (BrandInfix, "Platinum", L_STR_LEN ("Platinum")) == 0))
102 {
103 // Treat Xeon Scalable chips as their closest relatives, Xeon W
105 }
106
107 //
108 // Support both variants: Xeon(R) E5-1234 and Xeon(R) CPU E5-1234
109 //
110 if (AsciiStrnCmp (BrandInfix, "CPU", L_STR_LEN ("CPU")) == 0) {
111 BrandInfix += L_STR_LEN ("CPU");
112 while (*BrandInfix == ' ') {
113 ++BrandInfix;
114 }
115 }
116
117 if (AsciiStrnCmp (BrandInfix, "E5-", L_STR_LEN ("E5-")) == 0) {
119 }
120
121 if (AsciiStrnCmp (BrandInfix, "W-", L_STR_LEN ("W-")) == 0) {
123 }
124
126 }
127
129}
130
131UINT16
133 IN UINT8 Model,
134 IN UINT8 Stepping,
135 IN UINT8 AppleMajorType,
136 IN UINT16 CoreCount,
137 IN BOOLEAN Is64Bit
138 )
139{
140 switch (Model) {
141 //
142 // Willamette: https://en.wikipedia.org/wiki/Pentium_4#Willamette
143 // Northwood: same page.
144 // Yonah: https://en.wikipedia.org/wiki/Yonah_(microprocessor)#Models_and_brand_names
145 //
146 // Used by Apple:
147 // Core Duo, Core Solo
148 //
149 // Not used by Apple:
150 // Pentium, Celeron
151 //
152 // All 0x0201.
153 //
154 case CPU_MODEL_WILLAMETTE: // 0x01
155 case CPU_MODEL_NORTHWOOD: // 0x02
156 case CPU_MODEL_BANIAS: // 0x09
157 case CPU_MODEL_DOTHAN: // 0x0D
158 case CPU_MODEL_YONAH: // 0x0E
159 // IM41 (T2400/T2500), MM11 (Solo T1200 / Duo T2300/T2400),
160 // MBP11 (L2400/T2400/T2500/T2600), MBP12 (T2600),
161 // MB11 (T2400/T2500)
162 return AppleProcessorTypeCoreSolo; // 0x0201
163
164 //
165 // Prescott: https://en.wikipedia.org/wiki/Pentium_4#Prescott
166 // Prescott-2M: same page.
167 // Cedar Mill: same page.
168 // Bonnell: https://en.wikipedia.org/wiki/Bonnell_(microarchitecture)
169 // Saltwell: same page.
170 //
171 // Not used by Apple.
172 //
173 case CPU_MODEL_PRESCOTT: // 0x03
174 case CPU_MODEL_PRESCOTT_2M: // 0x04
175 case CPU_MODEL_CEDAR_MILL: // 0x06
176 case CPU_MODEL_BONNELL: // 0x1C
177 case CPU_MODEL_BONNELL_MID: // 0x26
178 case CPU_MODEL_SALTWELL: // 0x36
179 return Is64Bit ? AppleProcessorTypeCore2DuoType1 : AppleProcessorTypeCoreSolo; // 0x0301 if 64-bit, otherwise 0x0201
180
181 //
182 // Merom: https://en.wikipedia.org/wiki/Merom_(microprocessor)#Variants
183 // Penryn: https://en.wikipedia.org/wiki/Penryn_(microprocessor)#Variants
184 //
185 // Used by Apple:
186 // Core 2 Extreme, Core 2 Duo (Merom),
187 // Core 2 Duo, (Penryn),
188 // certain Clovertown (Merom) / Harpertown (Penryn) based models
189 //
190 // Not used by Apple:
191 // Merom: Core 2 Solo, Pentium, Celeron M, Celeron
192 // Penryn: Core 2 Extreme, Core 2 Quad, Core 2 Solo, Pentium, Celeron
193 //
194 case CPU_MODEL_MEROM: // 0x0F
195 case CPU_MODEL_PENRYN: // 0x17
196 if (AppleMajorType == AppleProcessorMajorCore2) {
197 // TODO: add check for models above. (by changing the following "if (0)")
198 if (0) {
199 // ONLY MBA31 (SU9400/SU9600) and MBA32 (SL9400/SL9600)
200 return AppleProcessorTypeCore2DuoType2; // 0x0302
201 }
202
203 // IM51 (T7200), IM61 (T7400), IM71 (T7300), IM81 (E8435), IM101 (E7600),
204 // MM21 (unknown), MM31 (P7350),
205 // MBP21 (T7600), MBP22 (unknown), MBP31 (T7700), MBP41 (T8300), MBP71 (P8600),
206 // MBP51 (P8600), MBP52 (T9600), MBP53 (P8800), MBP54 (P8700), MBP55 (P7550),
207 // MBA11 (P7500), MBA21 (SL9600),
208 // MB21 (unknown), MB31 (T7500), MB41 (T8300), MB51 (P8600), MB52 (P7450), MB61 (P7550), MB71 (P8600)
209 return AppleProcessorTypeCore2DuoType1; // 0x0301
210 }
211
212 if ( (AppleMajorType == AppleProcessorMajorXeonPenryn)
213 || (AppleMajorType == AppleProcessorMajorXeonE5)
214 || (AppleMajorType == AppleProcessorMajorXeonNehalem))
215 {
216 // MP21 (2x X5365), MP31 (2x E5462) - 0x0402
217 // FIXME: check when 0x0401 will be used.
218 return AppleProcessorTypeXeonPenrynType2; // 0x0402
219 }
220
221 // here stands for models not used by Apple (Merom/Penryn), putting 0x0301 as lowest
222 return AppleProcessorTypeCore2DuoType1; // 0x0301
223
224 //
225 // Nehalem: https://en.wikipedia.org/wiki/Nehalem_(microarchitecture)#Server_and_desktop_processors
226 // Westmere: https://en.wikipedia.org/wiki/Westmere_(microarchitecture)#Server_/_Desktop_processors
227 //
228 // Used by Apple:
229 // Gainestown (Xeon), Bloomfield (Xeon), Lynnfield (i5/i7) [Nehalem]
230 // Gulftown (aka Westmere-EP, Xeon), Clarkdale (i3/i5), Arrandale (i5/i7) [Westmere]
231 //
232 // Not used by Apple:
233 // Beckton (Xeon), Jasper Forest (Xeon), Clarksfield (i7), Pentium, Celeron [Nehalem]
234 // Westmere-EX (Xeon E7), Pentium, Celeron [Westmere]
235 //
236 case CPU_MODEL_NEHALEM: // 0x1A
237 case CPU_MODEL_NEHALEM_EX: // 0x2E, not used by Apple
238 case CPU_MODEL_FIELDS: // 0x1E, Lynnfield, Clarksfield (part of Nehalem)
239 case CPU_MODEL_WESTMERE: // 0x2C
240 case CPU_MODEL_WESTMERE_EX: // 0x2F, not used by Apple
241 case CPU_MODEL_DALES_32NM: // 0x25, Clarkdale, Arrandale (part of Westmere)
242 if (AppleMajorType == AppleProcessorMajorXeonNehalem) {
243 // MP41 & Xserve31 (2x E5520, CPU_MODEL_NEHALEM), MP51 (2x X5670, CPU_MODEL_WESTMERE)
244 return AppleProcessorTypeXeon; // 0x0501
245 }
246
247 if (AppleMajorType == AppleProcessorMajorI3) {
248 // IM112 (i3-540, 0x0901, CPU_MODEL_DALES_32NM)
249 return AppleProcessorTypeCorei3Type1; // 0x0901
250 }
251
252 if (AppleMajorType == AppleProcessorMajorI5) {
253 // FIXME: no idea what it is on IM112 (i5-680)
254 // MBP61, i5-640M, 0x0602, CPU_MODEL_DALES_32NM
255 return AppleProcessorTypeCorei5Type2; // 0x0602
256 }
257
258 if (AppleMajorType == AppleProcessorMajorI7) {
259 // FIXME: used by Apple, no idea what to use, assuming 0x0702 for now (based off 0x0602 on i5)
260 return AppleProcessorTypeCorei7Type2; // 0x0702
261 }
262
263 // here stands for Pentium and Celeron (Nehalem/Westmere), not used by Apple at all.
264 // putting 0x0901 (i3) as lowest
265 return AppleProcessorTypeCorei3Type1; // 0x0901
266
267 //
268 // Sandy Bridge: https://en.wikipedia.org/wiki/Sandy_Bridge#List_of_Sandy_Bridge_processors
269 // Sandy Bridge-E: https://en.wikipedia.org/wiki/Sandy_Bridge-E#Overview
270 //
271 // Used by Apple:
272 // Core i5/i7 / i3 (see NOTE below)
273 //
274 // NOTE: There seems to be one more i3-2100 used on IM121 (EDU),
275 // assuming it exists for now.
276 //
277 // Not used by Apple:
278 // Xeon v1 (E5/E3),
279 // SNB-E based Core i7 (and Extreme): 3970X, 3960X, 3930K, 3820,
280 // Pentium, Celeron
281 //
282 case CPU_MODEL_SANDYBRIDGE: // 0x2A
283 case CPU_MODEL_JAKETOWN: // 0x2D, SNB-E, not used by Apple
284 if (AppleMajorType == AppleProcessorMajorI3) {
285 // FIXME: used by Apple on iMac12,1 (EDU, i3-2100), not confirmed yet
286 return AppleProcessorTypeCorei3Type3; // 0x0903
287 }
288
289 if (AppleMajorType == AppleProcessorMajorI5) {
290 // NOTE: two values are used here. (0x0602 and 0x0603)
291 // TODO: how to classify them. (by changing "if (0)")
292 if (0) {
293 // MM51 (i5-2415M), MM52 (i5-2520M), MBA41 (i5-2467M), MBA42 (i5-2557M)
294 return AppleProcessorTypeCorei5Type2; // 0x0602
295 }
296
297 // IM121 (i5-2400S), MBP81 (i5-2415M)
298 return AppleProcessorTypeCorei5Type3; // 0x0603
299 }
300
301 if (AppleMajorType == AppleProcessorMajorI7) {
302 // IM122 (i7-2600), MBP82 (i7-2675QM), MBP83 (i7-2820QM)
303 //
304 // FIXME: will those i7 not used by Apple (see above), be identified as AppleProcessorMajorI7?
305 return AppleProcessorTypeCorei7Type3; // 0x0703
306 }
307
308 if (AppleMajorType == AppleProcessorMajorXeonE5) {
309 // see TODO below
310 // for Sandy Xeon E5, not used by Apple
311 // FIXME: is AppleProcessorMajorXeonE5, which seems to be for IVY-E only, compatible with SNB-E too?
312 // TODO: write some decent code to check SNB-E based Xeon E5.
313 return AppleProcessorTypeXeonE5; // 0x0A01
314 }
315
316 if (AppleMajorType == AppleProcessorMajorXeonNehalem) {
317 // see TODO below
318 // for Sandy Xeon E3
319 // NOTE: Xeon E3 is not used by Apple at all and should be somehow treated as i7,
320 // but here we'd like to show Xeon in "About This Mac".
321 // TODO: CPU major type check for SNB based Xeon E3
322 return AppleProcessorTypeXeon; // 0x0501
323 }
324
325 if (CoreCount > 4) {
326 // This can possibly be some engineering sample of a Xeon CPU.
327 // REF: https://github.com/acidanthera/bugtracker/issues/1149
329 }
330
331 // here stands for Pentium and Celeron (Sandy), not used by Apple at all.
332 // putting 0x0903 (i3) as lowest
333 return AppleProcessorTypeCorei3Type3; // 0x0903
334
335 //
336 // Ivy Bridge: https://en.wikipedia.org/wiki/Ivy_Bridge_(microarchitecture)#List_of_Ivy_Bridge_processors
337 // Ivy Bridge-E: https://en.wikipedia.org/wiki/Ivy_Bridge_(microarchitecture)#Models_and_steppings_2
338 //
339 // Used by Apple:
340 // Core i5/i7 / i3 (see NOTE below),
341 // Xeon E5 v2
342 //
343 // NOTE: There seems to be an iMac13,1 (EDU version), or rather iMac13,3, with CPU i3-3225,
344 // assuming it exists for now.
345 //
346 // Not used by Apple:
347 // Xeon v2 (E7/E3),
348 // IVY-E based Core i7 (and Extreme): 4960X, 4930K, 4820K,
349 // Pentium, Celeron
350 //
351 case CPU_MODEL_IVYBRIDGE: // 0x3A
352 case CPU_MODEL_IVYBRIDGE_EP: // 0x3E
353 if (AppleMajorType == AppleProcessorMajorXeonE5) {
354 // MP61 (E5-1620 v2)
355 return AppleProcessorTypeXeonE5; // 0x0A01
356 }
357
358 if (AppleMajorType == AppleProcessorMajorI5) {
359 // IM131 (i5-3470S), IM132 (i5-3470S),
360 // MBP92 (i5-3210M), MBP102 (i5-3210M)
361 // MBA51 (i6-3317U), MBA52 (i5-3427U)
362 return AppleProcessorTypeCorei5Type4; // 0x0604
363 }
364
365 if (AppleMajorType == AppleProcessorMajorI7) {
366 // MM62 (i7-3615QM),
367 // MBP91 (i7-3615QM), MBP101 (i7-3820QM)
368 //
369 // FIXME: will those i7 not used by Apple (see above), be identified as AppleProcessorMajorI7?
370 return AppleProcessorTypeCorei7Type4; // 0x0704
371 }
372
373 if (AppleMajorType == AppleProcessorMajorI3) {
374 // FIXME: used by Apple (if iMac13,3 were existent, i3-3225), not confirmed yet
375 // assuming it exists for now
376 return AppleProcessorTypeCorei3Type4; // 0x0904
377 }
378
379 if (AppleMajorType == AppleProcessorMajorXeonNehalem) {
380 // see TODO below
381 // for Ivy/Ivy-E E3/E7, not used by Apple
382 // NOTE: Xeon E3/E7 is not used by Apple at all and should be somehow treated as i7,
383 // but here we'd like to show Xeon in "About This Mac".
384 // TODO: CPU major type check for IVY based Xeon E3/E7
385 return AppleProcessorTypeXeon; // 0x0501
386 }
387
388 // here stands for Pentium and Celeron (Ivy), not used by Apple at all.
389 // putting 0x0904 (i3) as lowest.
390 return AppleProcessorTypeCorei3Type4; // 0x0904
391
392 //
393 // Haswell: https://en.wikipedia.org/wiki/Haswell_(microarchitecture)#List_of_Haswell_processors
394 // Haswell-E: basically the same page.
395 //
396 // Used by Apple:
397 // Core i5/i7
398 //
399 // Not used by Apple:
400 // Xeon v3 (E7/E5/E3),
401 // Core i3,
402 // Haswell-E based Core i7 Extreme: 5960X, 5930K, 5820K,
403 // Pentium, Celeron
404 //
405 case CPU_MODEL_HASWELL: // 0x3C
406 case CPU_MODEL_HASWELL_EP: // 0x3F
407 case CPU_MODEL_HASWELL_ULT: // 0x45
408 if (AppleMajorType == AppleProcessorMajorI5) {
409 // IM141 (i5-4570R), IM142 (i5-4670), IM151 (i5-4690),
410 // MM71 (i5-4260U),
411 // MBA62 (i5-4250U)
412 return AppleProcessorTypeCorei5Type5; // 0x0605
413 }
414
415 if (AppleMajorType == AppleProcessorMajorI7) {
416 // MBP112 (i7-4770HQ), MBP113 (i7-4850HQ)
417 //
418 // FIXME: will those i7 not used by Apple (see above), be identified as AppleProcessorMajorI7?
419 return AppleProcessorTypeCorei7Type5; // 0x0705
420 }
421
422 if (AppleMajorType == AppleProcessorMajorI3) {
423 // for i3, not used by Apple, just for showing i3 in "About This Mac".
424 return AppleProcessorTypeCorei3Type5; // 0x0905
425 }
426
427 if (AppleMajorType == AppleProcessorMajorXeonE5) {
428 // see TODO below
429 // for Haswell-E Xeon E5, not used by Apple
430 // FIXME: is AppleProcessorMajorXeonE5, which seems to be for IVY-E only, compatible with Haswell-E too?
431 // TODO: write some decent code to check Haswell-E based Xeon E5.
432 return AppleProcessorTypeXeonE5; // 0x0A01
433 }
434
435 if (AppleMajorType == AppleProcessorMajorXeonNehalem) {
436 // see TODO below
437 // for Haswell/Haswell-E E3/E7, not used by Apple
438 // NOTE: Xeon E3/E7 is not used by Apple at all and should be somehow treated as i7,
439 // but here we'd like to show Xeon in "About This Mac".
440 // TODO: CPU major type check for Haswell/Haswell-E based Xeon E3/E7
441 return AppleProcessorTypeXeon; // 0x0501
442 }
443
444 // here stands for Pentium and Celeron (Haswell), not used by Apple at all.
445 // putting 0x0905 (i3) as lowest.
446 return AppleProcessorTypeCorei3Type5; // 0x0905
447
448 //
449 // Broadwell: https://en.wikipedia.org/wiki/Broadwell_(microarchitecture)#List_of_Broadwell_processors
450 // Broadwell-E: https://en.wikipedia.org/wiki/Broadwell_(microarchitecture)#"Broadwell-E"_HEDT_(14_nm)
451 //
452 // NOTE: support table for BDW-E is missing in XNU, thus a CPUID patch might be needed. (See Clover FakeCPUID)
453 //
454 // Used by Apple:
455 // Core i5/i7, Core M
456 //
457 // Not used by Apple:
458 // Broadwell-E: i7 6950X/6900K/6850K/6800K,
459 // Xeon v4 (E5/E3),
460 // Core i3,
461 // Pentium, Celeron
462 //
463 case CPU_MODEL_BROADWELL: // 0x3D
464 case CPU_MODEL_BROADWELL_EP: // 0x4F
465 case CPU_MODEL_CRYSTALWELL: // 0x46
466 case CPU_MODEL_BRYSTALWELL: // 0x47
467 if (AppleMajorType == AppleProcessorMajorM) {
468 // MB81 (M 5Y51)
469 return AppleProcessorTypeCoreMType6; // 0x0B06
470 }
471
472 if (AppleMajorType == AppleProcessorMajorI5) {
473 // IM161 (i5-5250U), IM162 (i5-5675R),
474 // MBP121 (i5-5257U),
475 // MBA71 (i5-5250U), MBA72 (unknown)
476 return AppleProcessorTypeCorei5Type6; // 0x0606
477 }
478
479 if (AppleMajorType == AppleProcessorMajorI7) {
480 // FIXME: 0x0706 is just an ideal value for i7, waiting for confirmation
481 // FIXME: will those i7 not used by Apple (see above), be identified as AppleProcessorMajorI7?
482 return AppleProcessorTypeCorei7Type6; // 0x0706
483 }
484
485 if (AppleMajorType == AppleProcessorMajorI3) {
486 // for i3, not used by Apple, just for showing i3 in "About This Mac".
487 // FIXME: 0x0906 is just an ideal value for i3, waiting for confirmation
488 return AppleProcessorTypeCorei3Type6; // 0x0906
489 }
490
491 if (AppleMajorType == AppleProcessorMajorXeonE5) {
492 // see TODO below
493 // for Broadwell-E Xeon E5, not used by Apple
494 // FIXME: is AppleProcessorMajorXeonE5, which seems to be for IVY-E only, compatible with Broadwell-E too?
495 // TODO: write some decent code to check Broadwell-E based Xeon E5.
496 return AppleProcessorTypeXeonE5; // 0x0A01
497 }
498
499 if (AppleMajorType == AppleProcessorMajorXeonNehalem) {
500 // see TODO below
501 // for Broadwell E3, not used by Apple
502 // NOTE: Xeon E3 is not used by Apple at all and should be somehow treated as i7,
503 // but here we'd like to show Xeon in "About This Mac".
504 // TODO: CPU major type check for Broadwell based Xeon E3
505 return AppleProcessorTypeXeon; // 0x0501
506 }
507
508 // here stands for Pentium and Celeron (Broadwell), not used by Apple at all.
509 // putting 0x0906 (i3) as lowest.
510 return AppleProcessorTypeCorei3Type5; // 0x0906
511
512 //
513 // Skylake: https://en.wikipedia.org/wiki/Skylake_(microarchitecture)#List_of_Skylake_processor_models
514 //
515 // Used by Apple:
516 // Xeon W, Core m3, m5, m7, i5, i7
517 //
518 // Not used by Apple:
519 // Core i3,
520 // all high-end models (Core i9, i7 Extreme): see https://en.wikipedia.org/wiki/Skylake_(microarchitecture)#High-end_desktop_processors
521 // Xeon E3 v5, Xeon Scalable
522 // Pentium, Celeron
523 //
524 case CPU_MODEL_SKYLAKE: // 0x4E
525 case CPU_MODEL_SKYLAKE_DT: // 0x5E
526 case CPU_MODEL_SKYLAKE_W: // 0x55, also SKL-X and SKL-SP
527 if (AppleMajorType == AppleProcessorMajorXeonNehalem) {
528 // see TODO below
529 // for Skylake E3 (there's no E5/E7 on Skylake), not used by Apple
530 // NOTE: Xeon E3 is not used by Apple at all and should be somehow treated as i7,
531 // but here we'd like to show Xeon in "About This Mac".
532 // TODO: CPU major type check for Skylake based Xeon E3
533 return AppleProcessorTypeXeon; // 0x0501
534 }
535
536 if ((AppleMajorType == AppleProcessorMajorXeonW) || (CoreCount > 10)) {
537 // IMP11 (Xeon W 2140B)
538 // This will also get applied for i9 CPUs containing too many cores
539 // that are otherwise marked as unknown.
540 return AppleProcessorTypeXeonW; // 0x0F01
541 }
542
543 if (AppleMajorType == AppleProcessorMajorM3) {
544 // FIXME: we dont have any m3 (Skylake) dump!
545 // using an ideal value (0x0C07), which is used on MB101 (m3-7Y32)
546 return AppleProcessorTypeCoreM3Type7; // 0x0C07
547 }
548
549 if (AppleMajorType == AppleProcessorMajorM5) {
550 // MB91 (m5 6Y54)
551 return AppleProcessorTypeCoreM5Type7; // 0x0D07
552 }
553
554 if (AppleMajorType == AppleProcessorMajorM7) {
555 // FIXME: we dont have any m7 (Skylake) dump!
556 // using an ideal value (0x0E07)
557 return AppleProcessorTypeCoreM7Type7; // 0x0E07
558 }
559
560 if (AppleMajorType == AppleProcessorMajorI5) {
561 return AppleProcessorTypeCorei5Type5; // 0x0605
562 }
563
564 if (AppleMajorType == AppleProcessorMajorI7) {
565 // FIXME: used by Apple, but not sure what to use...
566 // 0x0707 is used on MBP133 (i7-6700HQ),
567 // 0x0705 is not confirmed, just an ideal one comparing to 0x0605 (AppleProcessorTypeCorei5Type5)
568 // using 0x0705 for now
569 return AppleProcessorTypeCorei7Type5; // 0x0705
570 }
571
572 if (AppleMajorType == AppleProcessorMajorI3) {
573 // for i3, not used by Apple, just for showing i3 in "About This Mac".
574 return AppleProcessorTypeCorei3Type5; // 0x0905
575 }
576
577 if (AppleMajorType == AppleProcessorMajorI9) {
578 // for i9 (SKL-X), not used by Apple, just for showing i9 in "About This Mac".
579 // FIXME: i9 was not introdced in this era but later (MBP151, Coffee Lake),
580 // will AppleProcessorMajorI9 work here?
581 // NOTE: using a mostly invalid value 0x1005 for now...
582 return AppleProcessorTypeCorei9Type5; // 0x1005
583 }
584
585 // here stands for Pentium and Celeron (Skylake), not used by Apple at all.
586 // putting 0x0905 (i3) as lowest.
587 return AppleProcessorTypeCorei3Type5; // 0x0905
588
589 //
590 // Kaby Lake: https://en.wikipedia.org/wiki/Kaby_Lake#List_of_7th_generation_Kaby_Lake_processors
591 // Coffee Lake: https://en.wikipedia.org/wiki/Coffee_Lake#List_of_8th_generation_Coffee_Lake_processors
592 //
593 // Used by Apple:
594 // Core m3 [Kaby],
595 // Core i5/i7 [Kaby/Coffee],
596 // Core i9 [Coffee],
597 //
598 // Not used by Apple:
599 // Core i3 [Kaby/Coffee],
600 // Xeon E3 v6 [Kaby],
601 // Xeon E [Coffee],
602 // Pentium, Celeron
603 //
604 case CPU_MODEL_KABYLAKE: // 0x8E
605 case CPU_MODEL_COFFEELAKE: // 0x9E
606 case CPU_MODEL_COMETLAKE_S: // 0xA5 FIXME - unknown, for now
607 case CPU_MODEL_COMETLAKE_U: // 0xA6 FIXME - unknown, for now
608 case CPU_MODEL_ROCKETLAKE_S: // 0xA7 FIXME - unknown, for now
609 case CPU_MODEL_ICELAKE_Y: // 0x7D FIXME - unknown, for now
610 case CPU_MODEL_ICELAKE_U: // 0x7E FIXME - unknown, for now
611 case CPU_MODEL_ICELAKE_SP: // 0x9F FIXME - unknown, for now
612 case CPU_MODEL_TIGERLAKE_U: // 0x8C FIXME - unknown, for now
613 case CPU_MODEL_ALDERLAKE_S: // 0x97 FIXME - unknown, for now
614 case CPU_MODEL_RAPTORLAKE_S: // 0xB7 FIXME - unknown, for now
615 case CPU_MODEL_RAPTORLAKE_HX: // 0xBF FIXME - unknown, for now
616 case CPU_MODEL_ARROWLAKE_S: // 0xC6 FIXME - unknown, for now
617 case CPU_MODEL_ARROWLAKE_HX: // 0xC5 FIXME - unknown, for now
618 case CPU_MODEL_ARROWLAKE_U: // 0xB5 FIXME - unknown, for now
619 if (AppleMajorType == AppleProcessorMajorM3) {
620 // MB101 (m3 7Y32)
621 return AppleProcessorTypeCoreM3Type7; // 0x0C07
622 }
623
624 if (AppleMajorType == AppleProcessorMajorI5) {
625 // Kaby has 0x9 stepping, and Coffee use 0xA / 0xB stepping.
626 if (Stepping == 9) {
627 // IM181 (i5-7360U), IM182 (i5-7400), IM183 (i5-7600), IM191 (i5-8600) [NOTE 1]
628 // MBP141 (i5-7360U), MBP142 (i5-7267U)
629 //
630 // NOTE 1: IM191 is Coffee and thus 0x0609 will be used, TODO.
631 return AppleProcessorTypeCorei5Type5; // 0x0605
632 }
633
634 // MM81 (i5-8500B)
635 // MBP152 (i5-8259U)
636 return AppleProcessorTypeCorei5Type9; // 0x0609
637 }
638
639 if (AppleMajorType == AppleProcessorMajorI7) {
640 // Kaby has 0x9 stepping, and Coffee use 0xA / 0xB stepping.
641 if (Stepping == 9) {
642 // FIXME: used by Apple, but not sure what to use...
643 // 0x0709 is used on MBP151 (i7-8850H),
644 // 0x0705 is not confirmed, just an ideal one comparing to 0x0605 (AppleProcessorTypeCorei5Type5)
645 // using 0x0705 for now
646 return AppleProcessorTypeCorei7Type5; // 0x0705
647 }
648
649 // MM81 (i7-8700B)
650 return AppleProcessorTypeCorei7Type9; // 0x0709
651 }
652
653 if (AppleMajorType == AppleProcessorMajorI9) {
654 // FIXME: find a dump from MBP151 with i9-8950HK,
655 // for now using an ideal value (0x1009), comparing to 0x0709 (used on MBP151, i7-8850H and MM81, i7-8700B)
656 // MBP161 (i9-9980HK)
657 return AppleProcessorTypeCorei9Type9; // 0x1009
658 }
659
660 if (AppleMajorType == AppleProcessorMajorI3) {
661 // FIXME: find a dump from MM71 with i3...
662 // for now using an idea value (0x0905)
663 return AppleProcessorTypeCorei3Type5; // 0x0905
664 }
665
666 if (AppleMajorType == AppleProcessorMajorXeonNehalem) {
667 // see TODO below
668 // for Kaby Lake/Coffee Lake E3 (there's no E5/E7 on either), not used by Apple
669 // NOTE: Xeon E3 is not used by Apple at all and should be somehow treated as i7,
670 // but here we'd like to show Xeon in "About This Mac".
671 // TODO: CPU major type check for KBL/CFL based Xeon E3
672 return AppleProcessorTypeXeon; // 0x0501
673 }
674
675 // here stands for Pentium and Celeron (KBL/CFL), not used by Apple at all.
676 // putting 0x0905 (i3) as lowest.
677 return AppleProcessorTypeCorei3Type5; // 0x0905
678
679 default:
680 // NOTE: by default it is really unknown, but we fallback
681 return AppleProcessorTypeCorei5Type5; // 0x0605
682 }
683}
684
685UINT32
687 IN CPUID_VERSION_INFO_EAX VersionEax
688 )
689{
690 UINT8 Model;
691
692 if (VersionEax.Bits.FamilyId != 6) {
693 return CPUFAMILY_UNKNOWN;
694 }
695
696 //
697 // This MUST be 1 to 1 with Apple XNU kernel implemenation.
698 //
699
700 Model = (UINT8)VersionEax.Bits.Model | (UINT8)(VersionEax.Bits.ExtendedModelId << 4U);
701
702 switch (Model) {
703 case CPU_MODEL_PENRYN:
706 case CPU_MODEL_FIELDS:
707 case CPU_MODEL_DALES:
736 default:
737 return CPUFAMILY_UNKNOWN;
738 }
739}
740
741UINT16
743 IN UINT64 Frequency
744 )
745{
746 UINT16 MhzSpeed;
747 UINT16 MhzRemainder;
748
749 //
750 // Round to nearest in MHz
751 //
752 MhzSpeed = (UINT16)DivU64x32 (Frequency + 500000, 1000000);
753 MhzRemainder = MhzSpeed % 100;
754 //
755 // Round to two digits when the second digit is above zero or to one otherwise.
756 // REF: https://github.com/acidanthera/bugtracker/issues/1521
757 //
758 if ((MhzRemainder >= 60) && (MhzRemainder < 89)) {
759 MhzSpeed = (MhzSpeed) / 10 * 10;
760 } else if ((MhzRemainder >= 12) && (MhzRemainder < 89)) {
761 MhzSpeed = (MhzSpeed + 5) / 10 * 10;
762 } else {
763 MhzSpeed = (MhzSpeed + 50) / 100 * 100;
764 }
765
766 return MhzSpeed;
767}
UINT16 InternalDetectAppleProcessorType(IN UINT8 Model, IN UINT8 Stepping, IN UINT8 AppleMajorType, IN UINT16 CoreCount, IN BOOLEAN Is64Bit)
UINT32 OcCpuModelToAppleFamily(IN CPUID_VERSION_INFO_EAX VersionEax)
UINT8 InternalDetectAppleMajorType(IN CONST CHAR8 *BrandString)
UINT16 OcCpuFrequencyToDisplayFrequency(IN UINT64 Frequency)
#define CPUFAMILY_UNKNOWN
#define CPUFAMILY_INTEL_SANDYBRIDGE
#define CPUFAMILY_INTEL_KABYLAKE
#define CPUFAMILY_INTEL_PENRYN
#define CPUFAMILY_INTEL_WESTMERE
#define CPUFAMILY_INTEL_HASWELL
#define CPUFAMILY_INTEL_SKYLAKE
#define CPUFAMILY_INTEL_BROADWELL
#define CPUFAMILY_INTEL_NEHALEM
#define CPUFAMILY_INTEL_IVYBRIDGE
@ AppleProcessorTypeXeonW
@ AppleProcessorTypeCorei5Type9
@ AppleProcessorTypeCorei3Type1
@ AppleProcessorTypeCorei5Type3
@ AppleProcessorTypeCorei3Type4
@ AppleProcessorTypeCorei7Type4
@ AppleProcessorTypeXeonE5
@ AppleProcessorTypeCorei7Type9
@ AppleProcessorTypeCoreMType6
@ AppleProcessorTypeCore2DuoType2
@ AppleProcessorTypeCorei7Type5
@ AppleProcessorTypeCorei5Type2
@ AppleProcessorTypeCorei7Type3
@ AppleProcessorTypeCoreM5Type7
@ AppleProcessorTypeCoreSolo
@ AppleProcessorTypeCore2DuoType1
@ AppleProcessorTypeCorei9Type5
@ AppleProcessorTypeCorei3Type3
@ AppleProcessorTypeCorei7Type2
@ AppleProcessorTypeXeon
@ AppleProcessorTypeCorei5Type6
@ AppleProcessorTypeCorei9Type9
@ AppleProcessorTypeCoreM3Type7
@ AppleProcessorTypeCoreM7Type7
@ AppleProcessorTypeCorei3Type6
@ AppleProcessorTypeXeonPenrynType2
@ AppleProcessorTypeCorei5Type5
@ AppleProcessorTypeCorei5Type4
@ AppleProcessorTypeCorei3Type5
@ AppleProcessorTypeCorei7Type6
@ AppleProcessorMajorI5
@ AppleProcessorMajorXeonPenryn
@ AppleProcessorMajorXeonNehalem
@ AppleProcessorMajorUnknown
@ AppleProcessorMajorCore
@ AppleProcessorMajorXeonE5
@ AppleProcessorMajorI7
@ AppleProcessorMajorCore2
@ AppleProcessorMajorM
@ AppleProcessorMajorM5
@ AppleProcessorMajorM3
@ AppleProcessorMajorM7
@ AppleProcessorMajorI3
@ AppleProcessorMajorI9
@ AppleProcessorMajorXeonW
#define L_STR_LEN(String)
Definition OcStringLib.h:26
#define CPU_MODEL_PRESCOTT
Prescott, Nocona, Cranford, Potomac.
#define CPU_MODEL_SKYLAKE_W
#define CPU_MODEL_IVYBRIDGE_EP
#define CPU_MODEL_TIGERLAKE_U
#define CPU_MODEL_MEROM
Allendale, Conroe, Kentsfield, Woodcrest, Clovertown, Tigerton, Merom.
#define CPU_MODEL_IVYBRIDGE
Ivy Bridge.
#define CPU_MODEL_ARROWLAKE_U
#define CPU_MODEL_ROCKETLAKE_S
desktop RocketLake
#define CPU_MODEL_SKYLAKE_DT
#define CPU_MODEL_SALTWELL
Saltwell, Cedarview.
#define CPU_MODEL_BANIAS
Banias.
#define CPU_MODEL_ARROWLAKE_S
desktop ArrowLake
#define CPU_MODEL_ARROWLAKE_HX
#define CPU_MODEL_RAPTORLAKE_S
Raptor Lake B0 stepping.
#define CPU_MODEL_JAKETOWN
Sandy Bridge Xeon E5, Core i7 Extreme.
#define CPU_MODEL_YONAH
Sossaman, Yonah.
#define CPU_MODEL_PRESCOTT_2M
Prescott 2M, Smithfield, Irwindale, Paxville.
#define CPU_MODEL_BROADWELL_EP
Broadwell_EP.
#define CPU_MODEL_COMETLAKE_S
desktop CometLake
#define CPU_MODEL_NEHALEM
Bloomfield, Nehalem-EP, Nehalem-WS, Gainestown.
#define CPU_MODEL_COFFEELAKE
#define CPU_MODEL_COMETLAKE_U
#define CPU_MODEL_BRYSTALWELL
#define CPU_MODEL_ICELAKE_U
#define CPU_MODEL_HASWELL
#define CPU_MODEL_CRYSTALWELL
#define CPU_MODEL_WESTMERE
Gulftown, Westmere-EP, Westmere-WS.
#define CPU_MODEL_WESTMERE_EX
#define CPU_MODEL_HASWELL_ULT
Haswell ULT.
#define CPU_MODEL_ICELAKE_Y
#define CPU_MODEL_NORTHWOOD
Northwood, Prestonia, Gallatin.
#define CPU_MODEL_PENRYN
Wolfdale, Yorkfield, Harpertown, Penryn.
#define CPU_MODEL_RAPTORLAKE_HX
Raptor Lake C0 stepping.
#define CPU_MODEL_HASWELL_EP
Haswell MB.
#define CPU_MODEL_SKYLAKE
Skylake-S.
#define CPU_MODEL_CEDAR_MILL
Cedar Mill, Presler, Tusla, Dempsey.
#define CPU_MODEL_FIELDS
Lynnfield, Clarksfield, Jasper Forest.
#define CPU_MODEL_NEHALEM_EX
Beckton.
#define CPU_MODEL_WILLAMETTE
Willamette, Foster.
#define CPU_MODEL_DALES_32NM
Clarkdale, Arrandale.
#define CPU_MODEL_ALDERLAKE_S
#define CPU_MODEL_ICELAKE_SP
Some variation of Ice Lake.
#define CPU_MODEL_DOTHAN
Dothan.
#define CPU_MODEL_BONNELL
Bonnell, Silverthorne, Diamondville, Pineview.
#define CPU_MODEL_BROADWELL
Broadwell.
#define CPU_MODEL_KABYLAKE_DT
#define CPU_MODEL_KABYLAKE
Kabylake Dektop.
#define CPU_MODEL_DALES
Havendale, Auburndale.
#define CPU_MODEL_BONNELL_MID
Bonnell, Lincroft.
#define CPU_MODEL_SANDYBRIDGE
Sandy Bridge.
#define DivU64x32(x, y, z)