[tip:x86/apic] x86: read apic ID in the !acpi_lapic case

From: tip-bot for Yinghai Lu
Date: Mon May 11 2009 - 05:57:50 EST


Commit-ID: 4401da6111ac58f94234417427d06a72c4048c74
Gitweb: http://git.kernel.org/tip/4401da6111ac58f94234417427d06a72c4048c74
Author: Yinghai Lu <yinghai@xxxxxxxxxx>
AuthorDate: Sat, 2 May 2009 10:40:57 -0700
Committer: Ingo Molnar <mingo@xxxxxxx>
CommitDate: Mon, 11 May 2009 11:29:23 +0200

x86: read apic ID in the !acpi_lapic case

Ed found that on 32-bit, boot_cpu_physical_apicid is not read right,
when the mptable is broken.

Interestingly, actually three paths use/set it:

1. acpi: at that time that is already read from reg
2. mptable: only read from mptable
3. no madt, and no mptable, that use default apic id 0 for 64-bit, -1 for 32-bit

so we could read the apic id for the 2/3 path. We trust the hardware
register more than we trust a BIOS data structure (the mptable).

We can also avoid the double set_fixmap() when acpi_lapic
is used, and also need to move cpu_has_apic earlier and
call apic_disable().

Also when need to update the apic id, we'd better read and
set the apic version as well - so that quirks are applied precisely.

v2: make path 3 with 64bit, use -1 as apic id, so could read it later.
v3: fix whitespace problem pointed out by Ed Swierk

[ Impact: get correct apic id for bsp other than acpi path ]

Reported-by: Ed Swierk <eswierk@xxxxxxxxxxxxxxxxxx>
Signed-off-by: Yinghai Lu <yinghai@xxxxxxxxxx>
Acked-by: Cyrill Gorcunov <gorcunov@xxxxxxxxxx>
LKML-Reference: <49FC85A9.2070702@xxxxxxxxxx>
[ v4: sanity-check in the ACPI case too ]
Signed-off-by: Ingo Molnar <mingo@xxxxxxx>


---
arch/x86/kernel/apic/apic.c | 31 +++++++++++++++++++++----------
1 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
index e258bed..1ee966f 100644
--- a/arch/x86/kernel/apic/apic.c
+++ b/arch/x86/kernel/apic/apic.c
@@ -1456,7 +1456,6 @@ static int __init detect_init_APIC(void)
}

mp_lapic_addr = APIC_DEFAULT_PHYS_BASE;
- boot_cpu_physical_apicid = 0;
return 0;
}
#else
@@ -1570,6 +1569,8 @@ void __init early_init_lapic_mapping(void)
*/
void __init init_apic_mappings(void)
{
+ unsigned int new_apicid;
+
if (x2apic_mode) {
boot_cpu_physical_apicid = read_apic_id();
return;
@@ -1586,21 +1587,31 @@ void __init init_apic_mappings(void)
} else
apic_phys = mp_lapic_addr;

- set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
+ /* lets check if we may NOP'ify apic operations */
+ if (!cpu_has_apic) {
+ pr_info("APIC: disable apic facility\n");
+ apic_disable();
+ return;
+ }
+
+ /*
+ * acpi lapic path already maps that address in
+ * acpi_register_lapic_address()
+ */
+ if (!acpi_lapic)
+ set_fixmap_nocache(FIX_APIC_BASE, apic_phys);
+
apic_printk(APIC_VERBOSE, "mapped APIC to %08lx (%08lx)\n",
APIC_BASE, apic_phys);
-
/*
* Fetch the APIC ID of the BSP in case we have a
* default configuration (or the MP table is broken).
*/
- if (boot_cpu_physical_apicid == -1U)
- boot_cpu_physical_apicid = read_apic_id();
-
- /* lets check if we may to NOP'ify apic operations */
- if (!cpu_has_apic) {
- pr_info("APIC: disable apic facility\n");
- apic_disable();
+ new_apicid = read_apic_id();
+ if (boot_cpu_physical_apicid != new_apicid) {
+ boot_cpu_physical_apicid = new_apicid;
+ apic_version[new_apicid] =
+ GET_APIC_VERSION(apic_read(APIC_LVR));
}
}

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/