]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/CpuDxe/CpuDxe.c
ShellPkg/comp: Use proper parameter names
[mirror_edk2.git] / UefiCpuPkg / CpuDxe / CpuDxe.c
index bd0aedc7fb457d27fba9bea44630aa97498ce7c3..4a5e282741bc6d9ea8336e5e60621ff9099ee47a 100644 (file)
@@ -27,6 +27,7 @@ EFI_HANDLE                mCpuHandle = NULL;
 BOOLEAN                   mIsFlushingGCD;\r
 UINT64                    mValidMtrrAddressMask = MTRR_LIB_CACHE_VALID_ADDRESS;\r
 UINT64                    mValidMtrrBitsMask    = MTRR_LIB_MSR_VALID_MASK;\r
+UINT64                    mTimerPeriod = 0;\r
 \r
 FIXED_MTRR    mFixedMtrrTable[] = {\r
   {\r
@@ -297,6 +298,9 @@ CpuGetTimerValue (
   OUT UINT64                    *TimerPeriod OPTIONAL\r
   )\r
 {\r
+  UINT64          BeginValue;\r
+  UINT64          EndValue;\r
+\r
   if (TimerValue == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
@@ -308,10 +312,26 @@ CpuGetTimerValue (
   *TimerValue = AsmReadTsc ();\r
 \r
   if (TimerPeriod != NULL) {\r
+    if (mTimerPeriod == 0) {\r
+      //\r
+      // Read time stamp counter before and after delay of 100 microseconds\r
       //\r
-      // BugBug: Hard coded. Don't know how to do this generically\r
+      BeginValue = AsmReadTsc ();\r
+      MicroSecondDelay (100);\r
+      EndValue   = AsmReadTsc ();\r
       //\r
-      *TimerPeriod = 1000000000;\r
+      // Calculate the actual frequency\r
+      //\r
+      mTimerPeriod = DivU64x64Remainder (\r
+                       MultU64x32 (\r
+                         1000 * 1000 * 1000,\r
+                         100\r
+                         ),\r
+                       EndValue - BeginValue,\r
+                       NULL\r
+                       );\r
+    }\r
+    *TimerPeriod = mTimerPeriod;\r
   }\r
 \r
   return EFI_SUCCESS;\r
@@ -383,7 +403,7 @@ CpuSetMemoryAttributes (
   // to avoid unnecessary computing.\r
   //\r
   if (mIsFlushingGCD) {\r
-    DEBUG((EFI_D_INFO, "  Flushing GCD\n"));\r
+    DEBUG((DEBUG_INFO, "  Flushing GCD\n"));\r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -959,13 +979,13 @@ IntersectMemoryDescriptor (
                     IntersectionBase, IntersectionEnd - IntersectionBase,\r
                     Capabilities);\r
 \r
-    DEBUG ((EFI_ERROR (Status) ? EFI_D_ERROR : EFI_D_VERBOSE,\r
+    DEBUG ((EFI_ERROR (Status) ? DEBUG_ERROR : DEBUG_VERBOSE,\r
       "%a: %a: add [%Lx, %Lx): %r\n", gEfiCallerBaseName, __FUNCTION__,\r
       IntersectionBase, IntersectionEnd, Status));\r
     return Status;\r
   }\r
 \r
-  DEBUG ((EFI_D_ERROR, "%a: %a: desc [%Lx, %Lx) type %u cap %Lx conflicts "\r
+  DEBUG ((DEBUG_ERROR, "%a: %a: desc [%Lx, %Lx) type %u cap %Lx conflicts "\r
     "with aperture [%Lx, %Lx) cap %Lx\n", gEfiCallerBaseName, __FUNCTION__,\r
     Descriptor->BaseAddress, Descriptor->BaseAddress + Descriptor->Length,\r
     (UINT32)Descriptor->GcdMemoryType, Descriptor->Capabilities,\r
@@ -998,7 +1018,7 @@ AddMemoryMappedIoSpace (
 \r
   Status = gDS->GetMemorySpaceMap (&NumberOfDescriptors, &MemorySpaceMap);\r
   if (EFI_ERROR (Status)) {\r
-    DEBUG ((EFI_D_ERROR, "%a: %a: GetMemorySpaceMap(): %r\n",\r
+    DEBUG ((DEBUG_ERROR, "%a: %a: GetMemorySpaceMap(): %r\n",\r
       gEfiCallerBaseName, __FUNCTION__, Status));\r
     return Status;\r
   }\r
@@ -1037,6 +1057,44 @@ FreeMemorySpaceMap:
   return Status;\r
 }\r
 \r
+/**\r
+  Add and allocate CPU local APIC memory mapped space. \r
+\r
+  @param[in]ImageHandle     Image handle this driver.\r
+\r
+**/\r
+VOID\r
+AddLocalApicMemorySpace (\r
+  IN EFI_HANDLE               ImageHandle\r
+  )\r
+{\r
+  EFI_STATUS              Status;\r
+  EFI_PHYSICAL_ADDRESS    BaseAddress;\r
+\r
+  BaseAddress = (EFI_PHYSICAL_ADDRESS) GetLocalApicBaseAddress();\r
+  Status = AddMemoryMappedIoSpace (BaseAddress, SIZE_4KB, EFI_MEMORY_UC);\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Try to allocate APIC memory mapped space, does not check return \r
+  // status because it may be allocated by other driver, or DXE Core if\r
+  // this range is built into Memory Allocation HOB.\r
+  //\r
+  Status = gDS->AllocateMemorySpace (\r
+                  EfiGcdAllocateAddress,\r
+                  EfiGcdMemoryTypeMemoryMappedIo,\r
+                  0,\r
+                  SIZE_4KB,\r
+                  &BaseAddress,\r
+                  ImageHandle,\r
+                  NULL\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    DEBUG ((DEBUG_INFO, "%a: %a: AllocateMemorySpace() Status - %r\n",\r
+                         gEfiCallerBaseName, __FUNCTION__, Status));\r
+  }\r
+}\r
+\r
 /**\r
   Initialize the state information for the CPU Architectural Protocol.\r
 \r
@@ -1097,6 +1155,11 @@ InitializeCpu (
   //\r
   RefreshGcdMemoryAttributes ();\r
 \r
+  //\r
+  // Add and allocate local APIC memory mapped space\r
+  //\r
+  AddLocalApicMemorySpace (ImageHandle);\r
+\r
   //\r
   // Setup a callback for idle events\r
   //\r