From owner-svn-src-projects@FreeBSD.ORG Wed Aug 31 09:29:46 2011 Return-Path: Delivered-To: svn-src-projects@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 7C664106564A; Wed, 31 Aug 2011 09:29:46 +0000 (UTC) (envelope-from gber@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 622AA8FC17; Wed, 31 Aug 2011 09:29:46 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p7V9TkSU092047; Wed, 31 Aug 2011 09:29:46 GMT (envelope-from gber@svn.freebsd.org) Received: (from gber@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p7V9Tk5W092044; Wed, 31 Aug 2011 09:29:46 GMT (envelope-from gber@svn.freebsd.org) Message-Id: <201108310929.p7V9Tk5W092044@svn.freebsd.org> From: Grzegorz Bernacki Date: Wed, 31 Aug 2011 09:29:46 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225290 - in projects/armv6/sys/arm: arm include X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 31 Aug 2011 09:29:46 -0000 Author: gber Date: Wed Aug 31 09:29:46 2011 New Revision: 225290 URL: http://svn.freebsd.org/changeset/base/225290 Log: Update SMP framework on ARM based on MIPS implementation. Obtained from: Marvell, Semihalf Modified: projects/armv6/sys/arm/arm/mp_machdep.c projects/armv6/sys/arm/include/smp.h Modified: projects/armv6/sys/arm/arm/mp_machdep.c ============================================================================== --- projects/armv6/sys/arm/arm/mp_machdep.c Wed Aug 31 09:15:52 2011 (r225289) +++ projects/armv6/sys/arm/arm/mp_machdep.c Wed Aug 31 09:29:46 2011 (r225290) @@ -23,7 +23,6 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ - #include __FBSDID("$FreeBSD$"); #include @@ -31,29 +30,81 @@ __FBSDID("$FreeBSD$"); #include #include #include - +#include +#include +#include #include +#include +#include +#include + #include +extern struct pcpu __pcpu[]; + /* used to hold the AP's until we are ready to release them */ static struct mtx ap_boot_mtx; +/* # of Applications processors */ +int mp_naps; + +/* Set to 1 once we're ready to let the APs out of the pen. */ +static volatile int aps_ready = 0; + +/* Temporary variables for init_secondary() */ +void *dpcpu; + + /* Determine if we running MP machine */ int cpu_mp_probe(void) { CPU_SETOF(0, &all_cpus); - return (mp_ncpus > 1); + return (platform_mp_probe()); } +/* Start Application Processor via platform specific function */ +static int +start_ap(int cpu) +{ + int cpus, ms; + + cpus = mp_naps; + + if (platform_mp_start_ap(cpu) != 0) + return (-1); /* could not start AP */ + + for (ms = 0; ms < 5000; ++ms) { + if (mp_naps > cpus) + return (0); /* success */ + else + DELAY(1000); + } + + return (-2); +} + + /* Initialize and fire up non-boot processors */ void cpu_mp_start(void) { + int error, i; + mtx_init(&ap_boot_mtx, "ap boot", NULL, MTX_SPIN); + for (i = 1; i < mp_maxid; i++) { + error = start_ap(i); + if (error) { + printf("AP #%d failed to start\n", i); + continue; + } + CPU_SET(i, &all_cpus); + } + + return; } @@ -64,6 +115,61 @@ cpu_mp_announce(void) return; } +void +init_secondary(int cpu) +{ + struct pcpu *pc; + void *dpcpu; + + /* Per-cpu initialization */ + pc = &__pcpu[cpu]; + pcpu_init(pc, cpu, sizeof(struct pcpu)); + + dpcpu = (void *)kmem_alloc(kernel_map, DPCPU_SIZE); + dpcpu_init(dpcpu, cpu); + + /* Signal our startup to BSP */ + mp_naps++; + + /* Spin until the BSP releases the APs */ + while (!aps_ready) + ; + + /* Initialize curthread */ + KASSERT(PCPU_GET(idlethread) != NULL, ("no idle thread")); + PCPU_SET(curthread, PCPU_GET(idlethread)); + + + mtx_lock_spin(&ap_boot_mtx); + + printf("SMP: AP CPU #%d Launched!\n", cpu); + + smp_cpus++; + + if (smp_cpus == mp_ncpus) { + /* enable IPI's, tlb shootdown, freezes etc */ + atomic_store_rel_int(&smp_started, 1); + /* + * XXX do we really need it + * smp_active = 1; + */ + } + + mtx_unlock_spin(&ap_boot_mtx); + + while (smp_started == 0) + ; + + /* Start per-CPU event timers. */ + cpu_initclocks_ap(); + + /* Enter the scheduler */ + sched_throw(NULL); + + panic("scheduler returned us to %s", __func__); + /* NOTREACHED */ +} + struct cpu_group * cpu_topo(void) { @@ -73,26 +179,29 @@ cpu_topo(void) void cpu_mp_setmaxid(void) { - mp_ncpus = 4; - mp_maxid = 3; + + platform_mp_setmaxid(); } /* Sending IPI */ void ipi_all_but_self(u_int ipi) { + return; } void ipi_cpu(int cpu, u_int ipi) { + return; } void ipi_selected(cpuset_t cpus, u_int ipi) { + return; } Modified: projects/armv6/sys/arm/include/smp.h ============================================================================== --- projects/armv6/sys/arm/include/smp.h Wed Aug 31 09:15:52 2011 (r225289) +++ projects/armv6/sys/arm/include/smp.h Wed Aug 31 09:29:46 2011 (r225290) @@ -12,8 +12,16 @@ #define IPI_STOP_HARD 5 #define IPI_HARDCLOCK 6 +void init_secondary(int cpu); + void ipi_all_but_self(u_int ipi); void ipi_cpu(int cpu, u_int ipi); void ipi_selected(cpuset_t cpus, u_int ipi); +/* Platform interface */ +void platform_mp_setmaxid(void); +int platform_mp_probe(void); +int platform_mp_start_ap(int cpuid); + + #endif /* !_MACHINE_SMP_H_ */