i386: Split mp_enable() into multiple SYSINITs
authorSepherosa Ziehau <sephe@dragonflybsd.org>
Sat, 4 Jun 2011 13:29:32 +0000 (21:29 +0800)
committerSepherosa Ziehau <sephe@dragonflybsd.org>
Sat, 4 Jun 2011 13:29:32 +0000 (21:29 +0800)
sys/platform/pc32/apic/ioapic.c
sys/platform/pc32/apic/lapic.c
sys/platform/pc32/i386/machdep.c
sys/platform/pc32/i386/mp_machdep.c

index c212c83..31b4f31 100644 (file)
@@ -39,6 +39,7 @@
 #include <machine_base/apic/lapic.h>
 #include <machine_base/apic/ioapic.h>
 #include <machine_base/apic/ioapic_abi.h>
+#include <machine_base/icu/icu_var.h>
 #include <machine/segments.h>
 #include <sys/thread2.h>
 
@@ -586,3 +587,21 @@ ioapic_map(vm_paddr_t pa)
        KKASSERT(pa < 0x100000000LL);
        return pmap_mapdev_uncacheable(pa, PAGE_SIZE);
 }
+
+static void
+ioapic_sysinit(void *dummy __unused)
+{
+       int error;
+
+       if (!ioapic_enable)
+               return;
+
+       KASSERT(lapic_enable, ("I/O APIC is enabled, but LAPIC is disabled\n"));
+       error = ioapic_config();
+       if (error) {
+               ioapic_enable = 0;
+               icu_reinit_noioapic();
+               lapic_fixup_noioapic();
+       }
+}
+SYSINIT(ioapic, SI_BOOT2_IOAPIC, SI_ORDER_FIRST, ioapic_sysinit, NULL)
index a0f3343..2af9ca8 100644 (file)
@@ -38,6 +38,7 @@
 #include <machine_base/apic/lapic.h>
 #include <machine_base/apic/ioapic.h>
 #include <machine_base/apic/ioapic_abi.h>
+#include <machine_base/icu/icu_var.h>
 #include <machine/segments.h>
 #include <sys/thread2.h>
 
@@ -713,3 +714,24 @@ lapic_fixup_noioapic(void)
        temp |= APIC_LVT_MASKED;
        lapic->lvt_lint1 = temp;
 }
+
+static void
+lapic_sysinit(void *dummy __unused)
+{
+       if (lapic_enable) {
+               int error;
+
+               error = lapic_config();
+               if (error)
+                       lapic_enable = 0;
+       }
+
+       if (lapic_enable) {
+               /* Initialize BSP's local APIC */
+               lapic_init(TRUE);
+       } else if (ioapic_enable) {
+               ioapic_enable = 0;
+               icu_reinit_noioapic();
+       }
+}
+SYSINIT(lapic, SI_BOOT2_LAPIC, SI_ORDER_FIRST, lapic_sysinit, NULL)
index d0b18f7..8d3046b 100644 (file)
@@ -367,14 +367,6 @@ again:
         */
        bufinit();
        vm_pager_bufferinit();
-
-#ifdef SMP
-       /*
-        * OK, enough kmem_alloc/malloc state should be up, lets get on with it!
-        */
-       mp_start();                     /* fire up the APs and APICs */
-       mp_announce();
-#endif  /* SMP */
 }
 
 static void
index 780205f..e3503f3 100644 (file)
@@ -168,13 +168,11 @@ static u_int      boot_address;
 static int     mp_finish;
 static int     mp_finish_lapic;
 
-static void    mp_enable(u_int boot_addr);
-
 static int     start_all_aps(u_int boot_addr);
 static void    install_ap_tramp(u_int boot_addr);
 static int     start_ap(struct mdglobaldata *gd, u_int boot_addr, int smibest);
 static int     smitest(void);
-static void    cpu_simple_setup(void);
+static void    mp_bsp_simple_setup(void);
 
 static cpumask_t smp_startup_mask = 1; /* which cpus have been started */
 static cpumask_t smp_lapic_mask = 1;   /* which cpus have lapic been inited */
@@ -196,17 +194,6 @@ mp_bootaddress(u_int basemem)
        return boot_address;
 }
 
-/*
- * Startup the SMP processors.
- */
-void
-mp_start(void)
-{
-       POSTCODE(MP_START_POST);
-       mp_enable(boot_address);
-}
-
-
 /*
  * Print various information about the SMP system hardware and setup.
  */
@@ -301,47 +288,19 @@ init_secondary(void)
  */
 
 /*
- * start the SMP system
+ * Start the SMP system
  */
 static void
-mp_enable(u_int boot_addr)
+mp_start_aps(void *dummy __unused)
 {
-       int error;
-
-       POSTCODE(MP_ENABLE_POST);
-
-       if (lapic_enable) {
-               error = lapic_config();
-               if (error)
-                       lapic_enable = 0;
-       }
-
-       if (lapic_enable) {
-               /* Initialize BSP's local APIC */
-               lapic_init(TRUE);
-       } else if (ioapic_enable) {
-               ioapic_enable = 0;
-               icu_reinit_noioapic();
-       }
-
        if (lapic_enable) {
                /* start each Application Processor */
-               start_all_aps(boot_addr);
+               start_all_aps(boot_address);
        } else {
-               cpu_simple_setup();
-       }
-
-       if (ioapic_enable) {
-               KASSERT(lapic_enable,
-                   ("I/O APIC is enabled, but LAPIC is disabled\n"));
-               error = ioapic_config();
-               if (error) {
-                       ioapic_enable = 0;
-                       icu_reinit_noioapic();
-                       lapic_fixup_noioapic();
-               }
+               mp_bsp_simple_setup();
        }
 }
+SYSINIT(startaps, SI_BOOT2_START_APS, SI_ORDER_FIRST, mp_start_aps, NULL)
 
 /*
  * start each AP in our list
@@ -1128,7 +1087,7 @@ cpu_send_ipiq_passive(int dcpu)
 #endif
 
 static void
-cpu_simple_setup(void)
+mp_bsp_simple_setup(void)
 {
        /* build our map of 'other' CPUs */
        mycpu->gd_other_cpus = smp_startup_mask & ~CPUMASK(mycpu->gd_cpuid);