From 1672d8fbe672e59694ee031ca402d2586f0e23de Mon Sep 17 00:00:00 2001 From: vit9696 Date: Thu, 7 Feb 2019 15:46:45 +0300 Subject: [PATCH] Add AppleMajorType to CPU_INFO --- Include/Library/OcCpuLib.h | 7 ++-- Library/OcCpuLib/OcCpuLib.c | 67 +++++++++++++++++++++++++++++++---- Library/OcCpuLib/OcCpuLib.inf | 1 + 3 files changed, 66 insertions(+), 9 deletions(-) diff --git a/Include/Library/OcCpuLib.h b/Include/Library/OcCpuLib.h index 7676b95e..d5562d94 100755 --- a/Include/Library/OcCpuLib.h +++ b/Include/Library/OcCpuLib.h @@ -12,8 +12,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ -#ifndef OC_CPU_LIB_H_ -#define OC_CPU_LIB_H_ +#ifndef OC_CPU_LIB_H +#define OC_CPU_LIB_H // CPU_INFO typedef struct { @@ -30,6 +30,7 @@ typedef struct { UINT64 ExtFeatures; UINT32 Signature; UINT8 Brand; + UINT8 AppleMajorType; UINT32 MaxExtId; @@ -60,7 +61,7 @@ typedef struct { **/ EFI_STATUS OcCpuScanProcessor ( - IN CPU_INFO *Platform + IN OUT CPU_INFO *Cpu ); #endif // OC_CPU_LIB_H_ diff --git a/Library/OcCpuLib/OcCpuLib.c b/Library/OcCpuLib/OcCpuLib.c index cb6aa10c..51c104c8 100755 --- a/Library/OcCpuLib/OcCpuLib.c +++ b/Library/OcCpuLib/OcCpuLib.c @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -27,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -44,16 +46,17 @@ **/ EFI_STATUS OcCpuScanProcessor ( - IN CPU_INFO *Cpu + IN OUT CPU_INFO *Cpu ) { EFI_STATUS Status; - UINT32 CpuidEax; - UINT32 CpuidEbx; - UINT32 CpuidEcx; - UINT32 CpuidEdx; - UINT64 Msr = 0; + UINT32 CpuidEax; + UINT32 CpuidEbx; + UINT32 CpuidEcx; + UINT32 CpuidEdx; + UINT64 Msr = 0; + CONST CHAR8 *BrandInfix; DEBUG_FUNCTION_ENTRY (DEBUG_VERBOSE); @@ -133,6 +136,58 @@ OcCpuScanProcessor ( if (*(UINT32 *)Cpu->Vendor == CPUID_VENDOR_INTEL) { + BrandInfix = AsciiStrStr (Cpu->BrandString, "Core"); + if (BrandInfix != NULL) { + while ((*BrandInfix != ' ') && (*BrandInfix != '\0')) { + ++BrandInfix; + } + + while (*BrandInfix == ' ') { + ++BrandInfix; + } + + if (AsciiStrnCmp (BrandInfix, "i7", L_STR_LEN("i7")) == 0) { + Cpu->AppleMajorType = AppleProcessorMajorI7; + } else if (AsciiStrnCmp (BrandInfix, "i5", L_STR_LEN("i5")) == 0) { + Cpu->AppleMajorType = AppleProcessorMajorI5; + } else if (AsciiStrnCmp (BrandInfix, "i3", L_STR_LEN("i3")) == 0) { + Cpu->AppleMajorType = AppleProcessorMajorI3; + } else if (AsciiStrnCmp (BrandInfix, "i9", L_STR_LEN("i9")) == 0) { + Cpu->AppleMajorType = AppleProcessorMajorI9; + } else if (AsciiStrnCmp (BrandInfix, "m3", L_STR_LEN("m3")) == 0) { + Cpu->AppleMajorType = AppleProcessorMajorM3; + } else if (AsciiStrnCmp (BrandInfix, "m5", L_STR_LEN("m5")) == 0) { + Cpu->AppleMajorType = AppleProcessorMajorM5; + } else if (AsciiStrnCmp (BrandInfix, "m7", L_STR_LEN("m7")) == 0) { + Cpu->AppleMajorType = AppleProcessorMajorM7; + } else if (AsciiStrnCmp (BrandInfix, "M", L_STR_LEN("M")) == 0) { + Cpu->AppleMajorType = AppleProcessorMajorM; + } else if (AsciiStrnCmp (BrandInfix, "2 Duo", L_STR_LEN("2 Duo")) == 0) { + Cpu->AppleMajorType = AppleProcessorMajorCore2; + } else { + Cpu->AppleMajorType = AppleProcessorMajorCore; + } + } else { + BrandInfix = AsciiStrStr (Cpu->BrandString, "Xeon"); + if (BrandInfix != NULL) { + while ((*BrandInfix != ' ') && (*BrandInfix != '\0')) { + ++BrandInfix; + } + + while (*BrandInfix == ' ') { + ++BrandInfix; + } + + if (AsciiStrnCmp (BrandInfix, "E5", L_STR_LEN("E5")) == 0) { + Cpu->AppleMajorType = AppleProcessorMajorXeonE5; + } else if (AsciiStrnCmp (BrandInfix, "W", L_STR_LEN("W")) == 0) { + Cpu->AppleMajorType = AppleProcessorMajorXeonW; + } else { + Cpu->AppleMajorType = AppleProcessorMajorXeonNehalem; + } + } + } + Msr = AsmReadMsr64 (MSR_PKG_CST_CONFIG_CONTROL); if ((Cpu->Family == 0x06 && Cpu->Model >= 0x0c) || diff --git a/Library/OcCpuLib/OcCpuLib.inf b/Library/OcCpuLib/OcCpuLib.inf index 81158363..4cee6860 100755 --- a/Library/OcCpuLib/OcCpuLib.inf +++ b/Library/OcCpuLib/OcCpuLib.inf @@ -31,6 +31,7 @@ MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec UefiCpuPkg/UefiCpuPkg.dec + EfiPkg/EfiPkg.dec [LibraryClasses] BaseLib -- GitLab