arch/x86: Fix ugly NEED_LAPIC use

Change-Id: I2d6fdfd0465fe5f558daa04c6f980f7226596b55
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/21087
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Kyösti Mälkki 2017-08-18 12:11:16 +03:00
parent aeb2d64c85
commit ff284f6566
3 changed files with 31 additions and 47 deletions

View File

@ -16,7 +16,7 @@
#include <cpu/x86/msr.h>
#include <cpu/x86/mtrr.h>
void setup_lapic(void)
void do_lapic_init(void)
{
/* this is so interrupts work. This is very limited scope --
* linux will do better later, we hope ...
@ -26,18 +26,10 @@ void setup_lapic(void)
* see the Intel mp1.4 spec, page A-3
*/
#if NEED_LAPIC == 1
/* Only Pentium Pro and later have those MSR stuff */
msr_t msr;
printk(BIOS_INFO, "Setting up local APIC...");
/* Enable the local APIC */
msr = rdmsr(LAPIC_BASE_MSR);
msr.lo |= LAPIC_BASE_MSR_ENABLE;
msr.lo &= ~LAPIC_BASE_MSR_ADDR_MASK;
msr.lo |= LAPIC_DEFAULT_BASE;
wrmsr(LAPIC_BASE_MSR, msr);
enable_lapic();
/*
* Set Task Priority to 'accept all'.
@ -69,17 +61,5 @@ void setup_lapic(void)
);
printk(BIOS_DEBUG, " apic_id: 0x%02lx ", lapicid());
#else /* !NEED_LAPIC */
/* Only Pentium Pro and later have those MSR stuff */
msr_t msr;
printk(BIOS_INFO, "Disabling local APIC...");
msr = rdmsr(LAPIC_BASE_MSR);
msr.lo &= ~LAPIC_BASE_MSR_ENABLE;
wrmsr(LAPIC_BASE_MSR, msr);
#endif /* !NEED_LAPIC */
printk(BIOS_INFO, "done.\n");
post_code(0x9b);
}

View File

@ -541,18 +541,18 @@ void initialize_cpus(struct bus *cpu_bus)
/* Find the info struct for this CPU */
info = cpu_info();
#if NEED_LAPIC == 1
/* Ensure the local APIC is enabled */
enable_lapic();
if (need_lapic_init()) {
/* Ensure the local APIC is enabled */
enable_lapic();
/* Get the device path of the boot CPU */
cpu_path.type = DEVICE_PATH_APIC;
cpu_path.apic.apic_id = lapicid();
#else
/* Get the device path of the boot CPU */
cpu_path.type = DEVICE_PATH_CPU;
cpu_path.cpu.id = 0;
#endif
/* Get the device path of the boot CPU */
cpu_path.type = DEVICE_PATH_APIC;
cpu_path.apic.apic_id = lapicid();
} else {
/* Get the device path of the boot CPU */
cpu_path.type = DEVICE_PATH_CPU;
cpu_path.cpu.id = 0;
}
/* Find the device structure for the boot CPU */
info->cpu = alloc_find_dev(cpu_bus, &cpu_path);

View File

@ -6,13 +6,6 @@
#include <halt.h>
#include <smp/node.h>
/* See if I need to initialize the local APIC */
#if IS_ENABLED(CONFIG_SMP) || IS_ENABLED(CONFIG_IOAPIC)
# define NEED_LAPIC 1
#else
# define NEED_LAPIC 0
#endif
static inline __attribute__((always_inline)) unsigned long lapic_read(
unsigned long reg)
{
@ -32,12 +25,12 @@ static inline __attribute__((always_inline)) void lapic_wait_icr_idle(void)
static inline void enable_lapic(void)
{
msr_t msr;
msr = rdmsr(LAPIC_BASE_MSR);
msr.hi &= 0xffffff00;
msr.lo &= 0x000007ff;
msr.lo |= LAPIC_DEFAULT_BASE | (1 << 11);
msr.lo &= ~LAPIC_BASE_MSR_ADDR_MASK;
msr.lo |= LAPIC_DEFAULT_BASE;
msr.lo |= LAPIC_BASE_MSR_ENABLE;
wrmsr(LAPIC_BASE_MSR, msr);
}
@ -45,7 +38,7 @@ static inline void disable_lapic(void)
{
msr_t msr;
msr = rdmsr(LAPIC_BASE_MSR);
msr.lo &= ~(1 << 11);
msr.lo &= ~LAPIC_BASE_MSR_ENABLE;
wrmsr(LAPIC_BASE_MSR, msr);
}
@ -146,13 +139,24 @@ static inline int lapic_remote_read(int apicid, int reg, unsigned long *pvalue)
return result;
}
void do_lapic_init(void);
void setup_lapic(void);
/* See if I need to initialize the local APIC */
static inline int need_lapic_init(void)
{
return IS_ENABLED(CONFIG_SMP) || IS_ENABLED(CONFIG_IOAPIC);
}
static inline void setup_lapic(void)
{
if (need_lapic_init())
do_lapic_init();
else
disable_lapic();
}
#if IS_ENABLED(CONFIG_SMP)
struct device;
int start_cpu(struct device *cpu);
#endif /* CONFIG_SMP */
#endif /* !__PRE_RAM__ */