HelenOS sources
This source file includes following definitions.
- smp_init
- cpu_arch_id_init
- kmp
- smp_irq_to_pin
#include <smp/smp.h>
#include <arch/smp/smp.h>
#include <arch/smp/mps.h>
#include <arch/smp/ap.h>
#include <arch/boot/boot.h>
#include <assert.h>
#include <errno.h>
#include <genarch/acpi/acpi.h>
#include <genarch/acpi/madt.h>
#include <config.h>
#include <synch/waitq.h>
#include <arch/pm.h>
#include <halt.h>
#include <panic.h>
#include <arch/asm.h>
#include <mm/page.h>
#include <mm/frame.h>
#include <mm/km.h>
#include <stdlib.h>
#include <mm/as.h>
#include <log.h>
#include <memw.h>
#include <genarch/drivers/i8259/i8259.h>
#include <cpu.h>
#ifdef CONFIG_SMP
static struct smp_config_operations *ops = NULL;
void smp_init(void)
{
if (acpi_madt) {
acpi_madt_parse();
ops = &madt_config_operations;
}
if (config.cpu_count == 1) {
mps_init();
ops = &mps_config_operations;
}
if (config.cpu_count > 1) {
l_apic = (uint32_t *) km_map((uintptr_t) l_apic, PAGE_SIZE,
PAGE_SIZE, PAGE_WRITE | PAGE_NOT_CACHEABLE);
io_apic = (uint32_t *) km_map((uintptr_t) io_apic, PAGE_SIZE,
PAGE_SIZE, PAGE_WRITE | PAGE_NOT_CACHEABLE);
}
}
static void cpu_arch_id_init(void)
{
assert(ops != NULL);
assert(cpus != NULL);
for (unsigned int i = 0; i < config.cpu_count; ++i) {
cpus[i].arch.id = ops->cpu_apic_id(i);
}
}
void kmp(void *arg __attribute__((unused)))
{
unsigned int i;
assert(ops != NULL);
cpu_arch_id_init();
*((uint16_t *) (PA2KA(0x467 + 0))) =
(uint16_t) (((uintptr_t) ap_boot) >> 4);
*((uint16_t *) (PA2KA(0x467 + 2))) = 0;
pio_write_8((ioport8_t *) 0x70, 0xf);
pio_write_8((ioport8_t *) 0x71, 0xa);
i8259_disable_irqs(0xffff);
apic_init();
for (i = 0; i < config.cpu_count; i++) {
if (!ops->cpu_enabled(i))
continue;
if (ops->cpu_bootstrap(i))
continue;
if (ops->cpu_apic_id(i) == bsp_l_apic) {
log(LF_ARCH, LVL_ERROR, "kmp: bad processor entry #%u, "
"will not send IPI to myself", i);
continue;
}
descriptor_t *gdt_new =
(descriptor_t *) malloc(GDT_ITEMS * sizeof(descriptor_t));
if (!gdt_new)
panic("Cannot allocate memory for GDT.");
memcpy(gdt_new, gdt, GDT_ITEMS * sizeof(descriptor_t));
memsetb(&gdt_new[TSS_DES], sizeof(descriptor_t), 0);
protected_ap_gdtr.limit = GDT_ITEMS * sizeof(descriptor_t);
protected_ap_gdtr.base = KA2PA((uintptr_t) gdt_new);
gdtr.base = (uintptr_t) gdt_new;
if (l_apic_send_init_ipi(ops->cpu_apic_id(i))) {
if (semaphore_down_timeout(&ap_completion_semaphore, 1000000) != EOK) {
log(LF_ARCH, LVL_NOTE, "%s: waiting for cpu%u "
"(APIC ID = %d) timed out", __FUNCTION__,
i, ops->cpu_apic_id(i));
}
} else
log(LF_ARCH, LVL_ERROR, "INIT IPI for l_apic%d failed",
ops->cpu_apic_id(i));
}
}
int smp_irq_to_pin(unsigned int irq)
{
assert(ops != NULL);
return ops->irq_to_pin(irq);
}
#endif
HelenOS homepage, sources at GitHub