From a0af6b27288fb1797e618d45ba3b4d6a9c742944 Mon Sep 17 00:00:00 2001 From: andrewfish Date: Tue, 24 Jan 2012 08:39:11 +0000 Subject: [PATCH] Remove Framework concepts and fully port to PI. Remove the use of Hii for hard coded strings. Note: The LogSmbiosData() function should probably be an MdeModulePkg library function. signed-off-by: andrewfish git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12954 6f19259b-4bc3-4df7-8a09-765794883524 --- EmulatorPkg/CpuRuntimeDxe/Cpu.c | 286 +++++++++++++++++--------- EmulatorPkg/CpuRuntimeDxe/Cpu.inf | 3 - EmulatorPkg/CpuRuntimeDxe/CpuDriver.h | 8 +- EmulatorPkg/CpuRuntimeDxe/CpuIo.c | 5 +- EmulatorPkg/CpuRuntimeDxe/MpService.c | 12 +- EmulatorPkg/CpuRuntimeDxe/Strings.uni | Bin 1712 -> 0 bytes 6 files changed, 195 insertions(+), 119 deletions(-) delete mode 100644 EmulatorPkg/CpuRuntimeDxe/Strings.uni diff --git a/EmulatorPkg/CpuRuntimeDxe/Cpu.c b/EmulatorPkg/CpuRuntimeDxe/Cpu.c index 07d6420807..7be4146b49 100644 --- a/EmulatorPkg/CpuRuntimeDxe/Cpu.c +++ b/EmulatorPkg/CpuRuntimeDxe/Cpu.c @@ -2,7 +2,7 @@ Emu driver to produce CPU Architectural Protocol. Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.
-Portions copyright (c) 2011, Apple Inc. All rights reserved. +Portions copyright (c) 2011 - 2012, Apple Inc. All rights reserved. This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -47,6 +47,179 @@ CPU_ARCH_PROTOCOL_PRIVATE mCpuTemplate = { #define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100 +SMBIOS_TABLE_TYPE4 mCpuSmbiosType4 = { + { EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION, sizeof (SMBIOS_TABLE_TYPE4), 0}, + 1, // Socket String + ProcessorOther, // ProcessorType; ///< The enumeration value from PROCESSOR_TYPE_DATA. + ProcessorFamilyOther, // ProcessorFamily; ///< The enumeration value from PROCESSOR_FAMILY_DATA. + 2, // ProcessorManufacture String; + { // ProcessorId; + { // PROCESSOR_SIGNATURE + 0, // ProcessorSteppingId:4; + 0, // ProcessorModel: 4; + 0, // ProcessorFamily: 4; + 0, // ProcessorType: 2; + 0, // ProcessorReserved1: 2; + 0, // ProcessorXModel: 4; + 0, // ProcessorXFamily: 8; + 0, // ProcessorReserved2: 4; + }, + { // PROCESSOR_FEATURE_FLAGS + 0, // ProcessorFpu :1; + 0, // ProcessorVme :1; + 0, // ProcessorDe :1; + 0, // ProcessorPse :1; + 0, // ProcessorTsc :1; + 0, // ProcessorMsr :1; + 0, // ProcessorPae :1; + 0, // ProcessorMce :1; + 0, // ProcessorCx8 :1; + 0, // ProcessorApic :1; + 0, // ProcessorReserved1 :1; + 0, // ProcessorSep :1; + 0, // ProcessorMtrr :1; + 0, // ProcessorPge :1; + 0, // ProcessorMca :1; + 0, // ProcessorCmov :1; + 0, // ProcessorPat :1; + 0, // ProcessorPse36 :1; + 0, // ProcessorPsn :1; + 0, // ProcessorClfsh :1; + 0, // ProcessorReserved2 :1; + 0, // ProcessorDs :1; + 0, // ProcessorAcpi :1; + 0, // ProcessorMmx :1; + 0, // ProcessorFxsr :1; + 0, // ProcessorSse :1; + 0, // ProcessorSse2 :1; + 0, // ProcessorSs :1; + 0, // ProcessorReserved3 :1; + 0, // ProcessorTm :1; + 0, // ProcessorReserved4 :2; + } + }, + 3, // ProcessorVersion String; + { // Voltage; + 1, // ProcessorVoltageCapability5V :1; + 1, // ProcessorVoltageCapability3_3V :1; + 1, // ProcessorVoltageCapability2_9V :1; + 0, // ProcessorVoltageCapabilityReserved :1; ///< Bit 3, must be zero. + 0, // ProcessorVoltageReserved :3; ///< Bits 4-6, must be zero. + 0 // ProcessorVoltageIndicateLegacy :1; + }, + 0, // ExternalClock; + 0, // MaxSpeed; + 0, // CurrentSpeed; + 0x41, // Status; + ProcessorUpgradeOther, // ProcessorUpgrade; ///< The enumeration value from PROCESSOR_UPGRADE. + 0, // L1CacheHandle; + 0, // L2CacheHandle; + 0, // L3CacheHandle; + 4, // SerialNumber; + 5, // AssetTag; + 6, // PartNumber; + 0, // CoreCount; + 0, // EnabledCoreCount; + 0, // ThreadCount; + 0, // ProcessorCharacteristics; + 0, // ProcessorFamily2; +}; + +CHAR8 *mCpuSmbiosType4Strings[] = { + "Socket", + "edk2.svn.sourceforge.net", + "Emulated Processor", + "1.0", + "1.0", + "1.0", + NULL +}; + + +/** + Logs SMBIOS record. + + Note: This should be a genric library function. + + @param Template Fixed SMBIOS structure + @param StringPack Array of strings to convert to an SMBIOS string pack. + +**/ +EFI_STATUS +LogSmbiosData ( + IN EFI_SMBIOS_TABLE_HEADER *Template, + IN CHAR8 **StringPack + ) +{ + EFI_STATUS Status; + EFI_SMBIOS_PROTOCOL *Smbios; + EFI_SMBIOS_HANDLE SmbiosHandle; + EFI_SMBIOS_TABLE_HEADER *Record; + UINTN Index; + UINTN StringSize; + UINTN Size; + CHAR8 *Str; + + // + // Locate Smbios protocol. + // + Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios); + if (EFI_ERROR (Status)) { + return Status; + } + + // Calculate the size of the fixed record and optional string pack + Size = Template->Length; + for (Index = 0; StringPack[Index] != NULL; Index++) { + StringSize = AsciiStrSize (StringPack[Index]); + Size += StringSize; + } + // Don't forget the terminating double null + Size += 1; + + // Copy over Template + Record = (EFI_SMBIOS_TABLE_HEADER *)AllocateZeroPool (Size); + if (Record == NULL) { + return EFI_OUT_OF_RESOURCES; + } + CopyMem (Record, Template, Template->Length); + + // Append string pack + Str = ((CHAR8 *)Record) + Record->Length; + for (Index = 0; StringPack[Index] != NULL; Index++) { + StringSize = AsciiStrSize (StringPack[Index]); + CopyMem (Str, StringPack[Index], StringSize); + Str += StringSize; + } + *Str = 0; + + SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED; + Status = Smbios->Add ( + Smbios, + gImageHandle, + &SmbiosHandle, + Record + ); + ASSERT_EFI_ERROR (Status); + + FreePool (Record); + return Status; +} + + + + +VOID +CpuUpdateSmbios ( + IN UINTN MaxCpus + ) +{ + mCpuSmbiosType4.CoreCount = MaxCpus; + mCpuSmbiosType4.EnabledCoreCount = MaxCpus; + mCpuSmbiosType4.ThreadCount = MaxCpus; + + LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER *)&mCpuSmbiosType4, mCpuSmbiosType4Strings); +} // @@ -127,6 +300,9 @@ EmuInit ( IN EFI_CPU_INIT_TYPE InitType ) { + CPU_ARCH_PROTOCOL_PRIVATE *Private; + + Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This); return EFI_UNSUPPORTED; } @@ -138,6 +314,8 @@ EmuRegisterInterruptHandler ( IN EFI_CPU_INTERRUPT_HANDLER InterruptHandler ) { + CPU_ARCH_PROTOCOL_PRIVATE *Private; + // // Do parameter checking for EFI spec conformance // @@ -147,6 +325,7 @@ EmuRegisterInterruptHandler ( // // Do nothing for Emu emulation // + Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This); return EFI_UNSUPPORTED; } @@ -186,6 +365,8 @@ EmuSetMemoryAttributes ( IN UINT64 Attributes ) { + CPU_ARCH_PROTOCOL_PRIVATE *Private; + // // Check for invalid parameter for Spec conformance // @@ -196,107 +377,12 @@ EmuSetMemoryAttributes ( // // Do nothing for Nt32 emulation // + Private = CPU_ARCH_PROTOCOL_PRIVATE_DATA_FROM_THIS (This); return EFI_UNSUPPORTED; } -/** - Logs SMBIOS record. - - @param Smbios Pointer to SMBIOS protocol instance. - @param Buffer Pointer to the data buffer. - -**/ -VOID -LogSmbiosData ( - IN EFI_SMBIOS_PROTOCOL *Smbios, - IN UINT8 *Buffer - ) -{ - EFI_STATUS Status; - EFI_SMBIOS_HANDLE SmbiosHandle; - - SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED; - Status = Smbios->Add ( - Smbios, - NULL, - &SmbiosHandle, - (EFI_SMBIOS_TABLE_HEADER*)Buffer - ); - ASSERT_EFI_ERROR (Status); -} - -VOID -CpuUpdateSmbios ( - VOID - ) -{ - EFI_STATUS Status; - UINT32 TotalSize; - EFI_SMBIOS_PROTOCOL *Smbios; - EFI_HII_HANDLE HiiHandle; - STRING_REF Token; - UINTN CpuVerStrLen; - EFI_STRING CpuVerStr; - SMBIOS_TABLE_TYPE4 *SmbiosRecord; - CHAR8 *OptionalStrStart; - - // - // Locate Smbios protocol. - // - Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios); - - if (EFI_ERROR (Status)) { - return; - } - - // - // Initialize strings to HII database - // - HiiHandle = HiiAddPackages ( - &gEfiCallerIdGuid, - NULL, - CpuStrings, - NULL - ); - ASSERT (HiiHandle != NULL); - - Token = STRING_TOKEN (STR_PROCESSOR_VERSION); - CpuVerStr = HiiGetPackageString(&gEfiCallerIdGuid, Token, NULL); - CpuVerStrLen = StrLen(CpuVerStr); - ASSERT (CpuVerStrLen <= SMBIOS_STRING_MAX_LENGTH); - - TotalSize = sizeof(SMBIOS_TABLE_TYPE4) + CpuVerStrLen + 1 + 1; - SmbiosRecord = AllocatePool(TotalSize); - ZeroMem(SmbiosRecord, TotalSize); - - SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION; - SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE4); - // - // Make handle chosen by smbios protocol.add automatically. - // - SmbiosRecord->Hdr.Handle = 0; - // - // Processor version is the 1st string. - // - SmbiosRecord->ProcessorVersion = 1; - // - // Store CPU frequency data record to data hub - It's an emulator so make up a value - // - SmbiosRecord->CurrentSpeed = 1234; - - OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1); - UnicodeStrToAsciiStr(CpuVerStr, OptionalStrStart); - - // - // Now we have got the full smbios record, call smbios protocol to add this record. - // - LogSmbiosData(Smbios, (UINT8 *) SmbiosRecord); - FreePool (SmbiosRecord); -} - - /** Callback function for idle events. @@ -327,6 +413,7 @@ InitializeCpu ( EFI_STATUS Status; UINT64 Frequency; EFI_EVENT IdleLoopEvent; + UINTN MaxCpu; // // Retrieve the frequency of the performance counter in Hz. @@ -338,9 +425,10 @@ InitializeCpu ( // mTimerPeriod = DivU64x64Remainder (1000000000000000ULL, Frequency, NULL); - CpuUpdateSmbios (); + CpuMpServicesInit (&MaxCpu); + + CpuUpdateSmbios (MaxCpu); - CpuMpServicesInit (); Status = gBS->CreateEventEx ( EVT_NOTIFY_SIGNAL, diff --git a/EmulatorPkg/CpuRuntimeDxe/Cpu.inf b/EmulatorPkg/CpuRuntimeDxe/Cpu.inf index e87c50a6fc..b8e8ebd8e2 100644 --- a/EmulatorPkg/CpuRuntimeDxe/Cpu.inf +++ b/EmulatorPkg/CpuRuntimeDxe/Cpu.inf @@ -34,14 +34,12 @@ CpuIo.c Cpu.c CpuDriver.h - Strings.uni MpService.c [Packages] MdePkg/MdePkg.dec MdeModulePkg/MdeModulePkg.dec - IntelFrameworkPkg/IntelFrameworkPkg.dec EmulatorPkg/EmulatorPkg.dec @@ -60,7 +58,6 @@ [Protocols] gEmuIoThunkProtocolGuid # PROTOCOL_NOTIFY SOMETIMES_CONSUMED gEfiSmbiosProtocolGuid # PROTOCOL SOMETIMES_CONSUMED - gEfiHiiProtocolGuid # PROTOCOL SOMETIMES_CONSUMED gEfiCpuIo2ProtocolGuid # PROTOCOL ALWAYS_PRODUCED gEfiCpuArchProtocolGuid # PROTOCOL ALWAYS_PRODUCED gEmuThreadThunkProtocolGuid diff --git a/EmulatorPkg/CpuRuntimeDxe/CpuDriver.h b/EmulatorPkg/CpuRuntimeDxe/CpuDriver.h index 3ede8473d3..5ec515dcbe 100644 --- a/EmulatorPkg/CpuRuntimeDxe/CpuDriver.h +++ b/EmulatorPkg/CpuRuntimeDxe/CpuDriver.h @@ -17,22 +17,19 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #define _CPU_ARCHITECTURAL_PROTOCOL_DRIVER_H_ -#include +#include #include #include #include -#include #include #include #include -#include #include #include #include -#include #include #include #include @@ -42,7 +39,6 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include -extern UINT8 CpuStrings[]; // // Internal Data Structures @@ -230,7 +226,7 @@ EmuSetMemoryAttributes ( EFI_STATUS CpuMpServicesInit ( - VOID + OUT UINTN *MaxCores ); EFI_STATUS diff --git a/EmulatorPkg/CpuRuntimeDxe/CpuIo.c b/EmulatorPkg/CpuRuntimeDxe/CpuIo.c index a8c10ba555..3d4309d422 100644 --- a/EmulatorPkg/CpuRuntimeDxe/CpuIo.c +++ b/EmulatorPkg/CpuRuntimeDxe/CpuIo.c @@ -18,12 +18,9 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ -#include +#include #include -#include -#include #include -#include #include #include diff --git a/EmulatorPkg/CpuRuntimeDxe/MpService.c b/EmulatorPkg/CpuRuntimeDxe/MpService.c index ba0ad82504..6eecbbc9bd 100644 --- a/EmulatorPkg/CpuRuntimeDxe/MpService.c +++ b/EmulatorPkg/CpuRuntimeDxe/MpService.c @@ -1308,35 +1308,33 @@ CpuReadToBootFunction ( EFI_STATUS CpuMpServicesInit ( - VOID + OUT UINTN *MaxCpus ) { EFI_STATUS Status; EFI_HANDLE Handle; EMU_IO_THUNK_PROTOCOL *IoThunk; - UINTN MaxCpus; - - MaxCpus = 1; // BSP + *MaxCpus = 1; // BSP IoThunk = GetIoThunkInstance (&gEmuThreadThunkProtocolGuid, 0); if (IoThunk != NULL) { Status = IoThunk->Open (IoThunk); if (!EFI_ERROR (Status)) { if (IoThunk->ConfigString != NULL) { - MaxCpus += StrDecimalToUintn (IoThunk->ConfigString); + *MaxCpus += StrDecimalToUintn (IoThunk->ConfigString); gThread = IoThunk->Interface; } } } - if (MaxCpus == 1) { + if (*MaxCpus == 1) { // We are not MP so nothing to do return EFI_SUCCESS; } gPollInterval = PcdGet64 (PcdEmuMpServicesPollingInterval); - Status = InitializeMpSystemData (MaxCpus); + Status = InitializeMpSystemData (*MaxCpus); if (EFI_ERROR (Status)) { return Status; } diff --git a/EmulatorPkg/CpuRuntimeDxe/Strings.uni b/EmulatorPkg/CpuRuntimeDxe/Strings.uni deleted file mode 100644 index f5aa4ddb43fc82805bc19c23452e2a6e5c94cc50..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 1712 zcmbu9O>PrG5QS?C5_cFm8whcXSg?oy$srDm0Nb)1epXTZn~`E0%{T@hk&_@U0er7| z#xu6OLzcU{x~g8iu6{j#|1_*&ksaGpevj-SR%1Iy_Qsa>%{G==Vl%t76|s+PWKWo% z+cSPI?1Xh}3w#s1W38N&ER8qpCae~Ail>QR5hYsY*2FS$Q(H5RiF|42*0a|Y9s_D8 zL`C4H;LRL+j(r36n0ZCS#O)FMmNq9+z72T`;v;s%Ms*Tacc2yL6-w&aclbuE7S2ex z1-`P!d4)CW1cVzKGOFsmvk-R4B-ENa>jFj0#5dXYMQ2*tw32sjeY?Q^u*0R~`rUgm zViddG(yt2+GrPjGMb+AUy(lqCqM0Hxd5;!