]> git.proxmox.com Git - mirror_edk2.git/commitdiff
1. Read 32bit CPU Init APIC ID from CPUID leaf B in XAPIC mode.
authorJeff Fan <jeff.fan@intel.com>
Mon, 16 Sep 2013 08:42:59 +0000 (08:42 +0000)
committervanjeff <vanjeff@6f19259b-4bc3-4df7-8a09-765794883524>
Mon, 16 Sep 2013 08:42:59 +0000 (08:42 +0000)
2. Read CPU APIC ID from CPUID leaf B in case CPU Init APIC ID is larger 255 in XAPIC mode.

Signed-off-by: Jeff Fan <jeff.fan@intel.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>
git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@14674 6f19259b-4bc3-4df7-8a09-765794883524

UefiCpuPkg/Include/Library/LocalApicLib.h
UefiCpuPkg/Include/Register/LocalApic.h
UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c
UefiCpuPkg/Library/BaseXApicX2ApicLib/BaseXApicX2ApicLib.c

index ed847b9579319d3bce53ea0de9441cc7e2318109..896020487650dd3b440e993152b89b964b95ddc3 100644 (file)
@@ -4,7 +4,7 @@
   Local APIC library assumes local APIC is enabled. It does not\r
   handles cases where local APIC is disabled.\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
@@ -78,7 +78,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
index bb0e211dc7e1b106ee00a544108cf039fcb788c2..f49e8f542f84fe1dfc48a6e2930722b3cbccbff6 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   IA32 Local APIC Definitions.\r
 \r
-  Copyright (c) 2010 - 2011, 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
@@ -23,7 +23,9 @@
 //\r
 // Definitions for CPUID instruction\r
 //\r
+#define CPUID_SIGNATURE                         0x0\r
 #define CPUID_VERSION_INFO                      0x1\r
+#define CPUID_EXTENDED_TOPOLOGY                 0xB\r
 #define CPUID_EXTENDED_FUNCTION                 0x80000000\r
 #define CPUID_VIR_PHY_ADDRESS_SIZE              0x80000008\r
 \r
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
index 48468e8bc96b465b52ced2d458ac3953b905e8cd..23dc7910ae68178be10b35f612f2d77466f5521c 100644 (file)
@@ -4,7 +4,7 @@
   This local APIC library instance supports x2APIC capable processors\r
   which have xAPIC and x2APIC modes.\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
@@ -290,7 +290,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
@@ -302,9 +302,24 @@ GetInitialApicId (
   VOID\r
   )\r
 {\r
+  UINT32 ApicId;\r
+  UINT32 MaxCpuIdIndex;\r
   UINT32 RegEbx;\r
 \r
   if (GetApicMode () == LOCAL_APIC_MODE_XAPIC) {\r
+    //\r
+    // Get the max index of basic CPUID\r
+    //\r
+    AsmCpuid (CPUID_SIGNATURE, &MaxCpuIdIndex, NULL, NULL, NULL);\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
     AsmCpuid (CPUID_VERSION_INFO, NULL, &RegEbx, NULL, NULL);\r
     return RegEbx >> 24;\r
   } else {\r
@@ -324,11 +339,13 @@ GetApicId (
   )\r
 {\r
   UINT32 ApicId;\r
+  UINT32 InitApicId;\r
 \r
   ApicId = ReadLocalApicReg (XAPIC_ID_OFFSET);\r
   if (GetApicMode () == LOCAL_APIC_MODE_XAPIC) {\r
-    ApicId >>= 24;\r
+    ApicId = ((InitApicId = GetInitialApicId ()) < 0x100) ? (ApicId >> 24) : InitApicId;\r
   }\r
+\r
   return ApicId;\r
 }\r
 \r