]> git.proxmox.com Git - mirror_edk2.git/blobdiff - EmulatorPkg/CpuRuntimeDxe/Cpu.c
Remove Framework concepts and fully port to PI. Remove the use of Hii for hard coded...
[mirror_edk2.git] / EmulatorPkg / CpuRuntimeDxe / Cpu.c
index 2f7d5368e04accf5f47bcbf5b56e980813a2e9e0..7be4146b4926b92a25c70b7a95c07ad42ad776ae 100644 (file)
@@ -2,7 +2,7 @@
   Emu driver to produce CPU Architectural Protocol.\r
 \r
 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>\r
-Portions copyright (c) 2011, Apple Inc. All rights reserved.\r
+Portions copyright (c) 2011 - 2012, Apple Inc. All rights reserved.\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -47,6 +47,179 @@ CPU_ARCH_PROTOCOL_PRIVATE mCpuTemplate = {
 \r
 #define EFI_CPU_DATA_MAXIMUM_LENGTH 0x100\r
 \r
+SMBIOS_TABLE_TYPE4 mCpuSmbiosType4 = {\r
+  { EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION, sizeof (SMBIOS_TABLE_TYPE4), 0},\r
+  1,                    // Socket String\r
+  ProcessorOther,       // ProcessorType;          ///< The enumeration value from PROCESSOR_TYPE_DATA.\r
+  ProcessorFamilyOther, // ProcessorFamily;        ///< The enumeration value from PROCESSOR_FAMILY_DATA.\r
+  2,                    // ProcessorManufacture String;\r
+  {                     // ProcessorId;\r
+    {  // PROCESSOR_SIGNATURE\r
+      0, //  ProcessorSteppingId:4;\r
+      0, //  ProcessorModel:     4;\r
+      0, //  ProcessorFamily:    4;\r
+      0, //  ProcessorType:      2;\r
+      0, //  ProcessorReserved1: 2;\r
+      0, //  ProcessorXModel:    4;\r
+      0, //  ProcessorXFamily:   8;\r
+      0, //  ProcessorReserved2: 4;\r
+    }, \r
+    {  // PROCESSOR_FEATURE_FLAGS\r
+      0, //  ProcessorFpu       :1;\r
+      0, //  ProcessorVme       :1;\r
+      0, //  ProcessorDe        :1;\r
+      0, //  ProcessorPse       :1;\r
+      0, //  ProcessorTsc       :1;\r
+      0, //  ProcessorMsr       :1;\r
+      0, //  ProcessorPae       :1;\r
+      0, //  ProcessorMce       :1;\r
+      0, //  ProcessorCx8       :1;\r
+      0, //  ProcessorApic      :1;\r
+      0, //  ProcessorReserved1 :1;\r
+      0, //  ProcessorSep       :1;\r
+      0, //  ProcessorMtrr      :1;\r
+      0, //  ProcessorPge       :1;\r
+      0, //  ProcessorMca       :1;\r
+      0, //  ProcessorCmov      :1;\r
+      0, //  ProcessorPat       :1;\r
+      0, //  ProcessorPse36     :1;\r
+      0, //  ProcessorPsn       :1;\r
+      0, //  ProcessorClfsh     :1;\r
+      0, //  ProcessorReserved2 :1;\r
+      0, //  ProcessorDs        :1;\r
+      0, //  ProcessorAcpi      :1;\r
+      0, //  ProcessorMmx       :1;\r
+      0, //  ProcessorFxsr      :1;\r
+      0, //  ProcessorSse       :1;\r
+      0, //  ProcessorSse2      :1;\r
+      0, //  ProcessorSs        :1;\r
+      0, //  ProcessorReserved3 :1;\r
+      0, //  ProcessorTm        :1;\r
+      0, //  ProcessorReserved4 :2;\r
+    }\r
+  },\r
+  3,                    // ProcessorVersion String;\r
+  {                     // Voltage;\r
+    1,  // ProcessorVoltageCapability5V        :1; \r
+    1,  // ProcessorVoltageCapability3_3V      :1;  \r
+    1,  // ProcessorVoltageCapability2_9V      :1;  \r
+    0,  // ProcessorVoltageCapabilityReserved  :1; ///< Bit 3, must be zero.\r
+    0,  // ProcessorVoltageReserved            :3; ///< Bits 4-6, must be zero.\r
+    0   // ProcessorVoltageIndicateLegacy      :1;\r
+  },              \r
+  0,                      // ExternalClock;\r
+  0,                      // MaxSpeed;\r
+  0,                      // CurrentSpeed;\r
+  0x41,                   // Status;\r
+  ProcessorUpgradeOther,  // ProcessorUpgrade;      ///< The enumeration value from PROCESSOR_UPGRADE.\r
+  0,                      // L1CacheHandle;\r
+  0,                      // L2CacheHandle;\r
+  0,                      // L3CacheHandle;\r
+  4,                      // SerialNumber;\r
+  5,                      // AssetTag;\r
+  6,                      // PartNumber;\r
+  0,                      // CoreCount;\r
+  0,                      // EnabledCoreCount;\r
+  0,                      // ThreadCount;\r
+  0,                      // ProcessorCharacteristics;\r
+  0,                      // ProcessorFamily2;\r
+};\r
+\r
+CHAR8 *mCpuSmbiosType4Strings[] = {\r
+  "Socket",\r
+  "edk2.svn.sourceforge.net",\r
+  "Emulated Processor",\r
+  "1.0",\r
+  "1.0",\r
+  "1.0",\r
+  NULL\r
+};\r
+\r
+\r
+/**\r
+  Logs SMBIOS record.\r
+\r
+  Note: This should be a genric library function.\r
+\r
+  @param  Template    Fixed SMBIOS structure\r
+  @param  StringPack  Array of strings to convert to an SMBIOS string pack. \r
+\r
+**/\r
+EFI_STATUS\r
+LogSmbiosData (\r
+  IN  EFI_SMBIOS_TABLE_HEADER *Template,\r
+  IN  CHAR8                   **StringPack \r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  EFI_SMBIOS_PROTOCOL       *Smbios;  \r
+  EFI_SMBIOS_HANDLE         SmbiosHandle;\r
+  EFI_SMBIOS_TABLE_HEADER   *Record;\r
+  UINTN                     Index;\r
+  UINTN                     StringSize;\r
+  UINTN                     Size;\r
+  CHAR8                     *Str;\r
+\r
+  //\r
+  // Locate Smbios protocol.\r
+  //\r
+  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios);\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+\r
+  // Calculate the size of the fixed record and optional string pack\r
+  Size = Template->Length;\r
+  for (Index = 0; StringPack[Index] != NULL; Index++) {\r
+    StringSize = AsciiStrSize (StringPack[Index]);\r
+    Size += StringSize;\r
+  }\r
+  // Don't forget the terminating double null\r
+  Size += 1;\r
+\r
+  // Copy over Template\r
+  Record = (EFI_SMBIOS_TABLE_HEADER *)AllocateZeroPool (Size);\r
+  if (Record == NULL) {\r
+    return EFI_OUT_OF_RESOURCES;\r
+  }\r
+  CopyMem (Record, Template, Template->Length);\r
+\r
+  // Append string pack\r
+  Str = ((CHAR8 *)Record) + Record->Length;\r
+  for (Index = 0; StringPack[Index] != NULL; Index++) {\r
+    StringSize = AsciiStrSize (StringPack[Index]);\r
+    CopyMem (Str, StringPack[Index], StringSize);\r
+    Str += StringSize;\r
+  }\r
+  *Str = 0;\r
+  \r
+  SmbiosHandle = SMBIOS_HANDLE_PI_RESERVED;\r
+  Status = Smbios->Add (\r
+                     Smbios,\r
+                     gImageHandle,\r
+                     &SmbiosHandle,\r
+                     Record\r
+                     );\r
+  ASSERT_EFI_ERROR (Status);\r
+  \r
+  FreePool (Record);\r
+  return Status;\r
+}\r
+\r
+\r
+\r
+\r
+VOID\r
+CpuUpdateSmbios (\r
+  IN UINTN  MaxCpus\r
+  )\r
+{\r
+  mCpuSmbiosType4.CoreCount        = MaxCpus;\r
+  mCpuSmbiosType4.EnabledCoreCount = MaxCpus;\r
+  mCpuSmbiosType4.ThreadCount      = MaxCpus;\r
+\r
+  LogSmbiosData ((EFI_SMBIOS_TABLE_HEADER *)&mCpuSmbiosType4, mCpuSmbiosType4Strings);\r
+}\r
 \r
 \r
 //\r
@@ -210,102 +383,6 @@ EmuSetMemoryAttributes (
 \r
 \r
 \r
-/**\r
-  Logs SMBIOS record.\r
-\r
-  @param  Smbios   Pointer to SMBIOS protocol instance.\r
-  @param  Buffer   Pointer to the data buffer.\r
-\r
-**/\r
-VOID\r
-LogSmbiosData (\r
-  IN  EFI_SMBIOS_PROTOCOL        *Smbios,\r
-  IN  UINT8                      *Buffer\r
-  )\r
-{\r
-  EFI_STATUS         Status;\r
-  EFI_SMBIOS_HANDLE  SmbiosHandle;\r
-\r
-  SmbiosHandle = 0;\r
-  Status = Smbios->Add (\r
-                     Smbios,\r
-                     NULL,\r
-                     &SmbiosHandle,\r
-                     (EFI_SMBIOS_TABLE_HEADER*)Buffer\r
-                     );\r
-  ASSERT_EFI_ERROR (Status);\r
-}\r
-\r
-VOID\r
-CpuUpdateSmbios (\r
-  VOID\r
-  )\r
-{\r
-  EFI_STATUS                  Status;\r
-  UINT32                      TotalSize;\r
-  EFI_SMBIOS_PROTOCOL         *Smbios;\r
-  EFI_HII_HANDLE              HiiHandle;\r
-  STRING_REF                  Token;\r
-  UINTN                       CpuVerStrLen;\r
-  EFI_STRING                  CpuVerStr;\r
-  SMBIOS_TABLE_TYPE4          *SmbiosRecord;\r
-  CHAR8                       *OptionalStrStart;\r
-\r
-  //\r
-  // Locate Smbios protocol.\r
-  //\r
-  Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&Smbios);\r
-\r
-  if (EFI_ERROR (Status)) {\r
-    return;\r
-  }\r
-\r
-  //\r
-  // Initialize strings to HII database\r
-  //\r
-  HiiHandle = HiiAddPackages (\r
-                &gEfiCallerIdGuid,\r
-                NULL,\r
-                CpuStrings,\r
-                NULL\r
-                );\r
-  ASSERT (HiiHandle != NULL);\r
-\r
-  Token  = STRING_TOKEN (STR_PROCESSOR_VERSION);\r
-  CpuVerStr = HiiGetPackageString(&gEfiCallerIdGuid, Token, NULL);\r
-  CpuVerStrLen = StrLen(CpuVerStr);\r
-  ASSERT (CpuVerStrLen <= SMBIOS_STRING_MAX_LENGTH);\r
-\r
-  TotalSize = sizeof(SMBIOS_TABLE_TYPE4) + CpuVerStrLen + 1 + 1;\r
-  SmbiosRecord = AllocatePool(TotalSize);\r
-  ZeroMem(SmbiosRecord, TotalSize);\r
-\r
-  SmbiosRecord->Hdr.Type = EFI_SMBIOS_TYPE_PROCESSOR_INFORMATION;\r
-  SmbiosRecord->Hdr.Length = sizeof (SMBIOS_TABLE_TYPE4);\r
-  //\r
-  // Make handle chosen by smbios protocol.add automatically.\r
-  //\r
-  SmbiosRecord->Hdr.Handle = 0;\r
-  //\r
-  // Processor version is the 1st string.\r
-  //\r
-  SmbiosRecord->ProcessorVersion = 1;\r
-  //\r
-  // Store CPU frequency data record to data hub - It's an emulator so make up a value\r
-  //\r
-  SmbiosRecord->CurrentSpeed  = 1234;\r
-\r
-  OptionalStrStart = (CHAR8 *)(SmbiosRecord + 1);\r
-  UnicodeStrToAsciiStr(CpuVerStr, OptionalStrStart);\r
-\r
-  //\r
-  // Now we have got the full smbios record, call smbios protocol to add this record.\r
-  //\r
-  LogSmbiosData(Smbios, (UINT8 *) SmbiosRecord);\r
-  FreePool (SmbiosRecord);\r
-}\r
-\r
-\r
 \r
 /**\r
   Callback function for idle events.\r
@@ -336,6 +413,7 @@ InitializeCpu (
   EFI_STATUS    Status;\r
   UINT64        Frequency;\r
   EFI_EVENT     IdleLoopEvent;\r
+  UINTN         MaxCpu;\r
 \r
   //\r
   // Retrieve the frequency of the performance counter in Hz.\r
@@ -347,9 +425,10 @@ InitializeCpu (
   //\r
   mTimerPeriod = DivU64x64Remainder (1000000000000000ULL, Frequency, NULL);\r
 \r
-  CpuUpdateSmbios ();\r
+  CpuMpServicesInit (&MaxCpu);\r
+\r
+  CpuUpdateSmbios (MaxCpu);\r
 \r
-  CpuMpServicesInit ();\r
 \r
   Status = gBS->CreateEventEx (\r
                   EVT_NOTIFY_SIGNAL,\r