]> git.proxmox.com Git - mirror_edk2.git/blobdiff - UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c
Fix build fail for VS2005 tool chain.
[mirror_edk2.git] / UefiCpuPkg / Library / BaseXApicLib / BaseXApicLib.c
index 53c1610810722a85d5c99a28dfea695e6f10345b..bd97fae9c2c37dd84456a04e063447d065f3c9d7 100644 (file)
@@ -3,7 +3,7 @@
 \r
   This local APIC library instance supports xAPIC mode only.\r
 \r
-  Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2010 - 2013, Intel Corporation. All rights reserved.<BR>\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
@@ -207,7 +207,7 @@ SetApicMode (
 /**\r
   Get the initial local APIC ID of the executing processor assigned by hardware upon power on or reset.\r
 \r
-  In xAPIC mode, the initial local APIC ID is 8-bit, and may be different from current APIC ID.\r
+  In xAPIC mode, the initial local APIC ID may be different from current APIC ID.\r
   In x2APIC mode, the local APIC ID can't be changed and there is no concept of initial APIC ID. In this case, \r
   the 32-bit local APIC ID is returned as initial APIC ID.\r
 \r
@@ -219,10 +219,27 @@ GetInitialApicId (
   VOID\r
   )\r
 {\r
+  UINT32 ApicId;\r
+  UINT32 MaxCpuIdIndex;\r
   UINT32 RegEbx;\r
 \r
   ASSERT (GetApicMode () == LOCAL_APIC_MODE_XAPIC);\r
 \r
+  //\r
+  // Get the max index of basic CPUID\r
+  //\r
+  AsmCpuid (CPUID_SIGNATURE, &MaxCpuIdIndex, NULL, NULL, NULL);\r
+\r
+  //\r
+  // If CPUID Leaf B is supported, \r
+  // Then the initial 32-bit APIC ID = CPUID.0BH:EDX\r
+  // Else the initial 8-bit APIC ID = CPUID.1:EBX[31:24]\r
+  //\r
+  if (MaxCpuIdIndex >= CPUID_EXTENDED_TOPOLOGY) {\r
+    AsmCpuidEx (CPUID_EXTENDED_TOPOLOGY, 0, NULL, NULL, NULL, &ApicId);\r
+    return ApicId;\r
+  }\r
+\r
   AsmCpuid (CPUID_VERSION_INFO, NULL, &RegEbx, NULL, NULL);\r
   return RegEbx >> 24;\r
 }\r
@@ -241,9 +258,15 @@ GetApicId (
   UINT32 ApicId;\r
 \r
   ASSERT (GetApicMode () == LOCAL_APIC_MODE_XAPIC);\r
-\r
-  ApicId = ReadLocalApicReg (XAPIC_ID_OFFSET);\r
-  ApicId >>= 24;\r
+  \r
+  if ((ApicId = GetInitialApicId ()) < 0x100) {\r
+    //\r
+    // If the initial local APIC ID is less 0x100, read APIC ID from\r
+    // XAPIC_ID_OFFSET, otherwise return the initial local APIC ID.\r
+    //\r
+    ApicId = ReadLocalApicReg (XAPIC_ID_OFFSET);\r
+    ApicId >>= 24;\r
+  }\r
   return ApicId;\r
 }\r
 \r