Index: sys/powerpc/aim/mp_cpudep.c =================================================================== --- sys/powerpc/aim/mp_cpudep.c +++ sys/powerpc/aim/mp_cpudep.c @@ -60,11 +60,23 @@ void cpudep_ap_early_bootstrap(void) { + struct pcpu *tmp_pc, *pc = NULL; #ifndef __powerpc64__ register_t reg; #endif - __asm __volatile("mtsprg 0, %0" :: "r"(ap_pcpu)); + /* Find apropriate pcpu structure */ + STAILQ_FOREACH(tmp_pc, &cpuhead, pc_allcpu) { + if (tmp_pc->pc_hwref == mfspr(SPR_PIR)) { + pc = tmp_pc; + break; + } + } + + KASSERT(pc != NULL, ("cpudep_ap_early_bootstrap: can't find pcpu " + "structure for cpu")); + + __asm __volatile("mtsprg 0, %0" :: "r"(pc)); powerpc_sync(); switch (mfpvr() >> 16) { Index: sys/powerpc/powernv/platform_powernv.c =================================================================== --- sys/powerpc/powernv/platform_powernv.c +++ sys/powerpc/powernv/platform_powernv.c @@ -54,10 +54,6 @@ #include "platform_if.h" #include "opal.h" -#ifdef SMP -extern void *ap_pcpu; -#endif - static int powernv_probe(platform_t); static int powernv_attach(platform_t); void powernv_mem_regions(platform_t, struct mem_region *phys, int *physsz, @@ -366,7 +362,6 @@ { int result; - ap_pcpu = pc; powerpc_sync(); result = opal_call(OPAL_START_CPU, pc->pc_cpuid, EXC_RST); @@ -425,9 +420,21 @@ static void powernv_smp_ap_init(platform_t platform) { + register_t msr; + /* LPID must not be altered when PSL_DR or PSL_IR is set */ + msr = mfmsr(); + mtmsr(msr & ~(PSL_DR | PSL_IR)); + + isync(); /* Direct interrupts to SRR instead of HSRR and reset LPCR otherwise */ + mtspr(SPR_LPID, 0); + isync(); + + mtmsr(msr); + mtspr(SPR_LPCR, LPCR_LPES); + isync(); } static void Index: sys/powerpc/powerpc/mp_machdep.c =================================================================== --- sys/powerpc/powerpc/mp_machdep.c +++ sys/powerpc/powerpc/mp_machdep.c @@ -94,6 +94,9 @@ printf("SMP: AP CPU #%d launched\n", PCPU_GET(cpuid)); mtx_unlock_spin(&ap_boot_mtx); + while(smp_started == 0) + ; + /* Start per-CPU event timers. */ cpu_initclocks_ap(); @@ -197,6 +200,7 @@ { struct pcpu *pc; int cpus, timeout; + int ret; if (mp_ncpus <= 1) return; @@ -215,12 +219,12 @@ printf("Waking up CPU %d (dev=%x)\n", pc->pc_cpuid, (int)pc->pc_hwref); - platform_smp_start_cpu(pc); - - timeout = 2000; /* wait 2sec for the AP */ - while (!pc->pc_awake && --timeout > 0) - DELAY(1000); - + ret = platform_smp_start_cpu(pc); + if (ret == 0) { + timeout = 2000; /* wait 2sec for the AP */ + while (!pc->pc_awake && --timeout > 0) + DELAY(1000); + } } else { pc->pc_awake = 1; } @@ -253,11 +257,12 @@ mp_ncpus, cpus, smp_cpus); } + if (smp_cpus > 1) + atomic_store_rel_int(&smp_started, 1); + /* Let the APs get into the scheduler */ DELAY(10000); - /* XXX Atomic set operation? */ - smp_started = 1; } SYSINIT(start_aps, SI_SUB_SMP, SI_ORDER_FIRST, cpu_mp_unleash, NULL);