diff options
author | 2010-04-28 16:20:28 +0000 | |
---|---|---|
committer | 2010-04-28 16:20:28 +0000 | |
commit | afdabf13cf434cbb2164e59d58340fb877b5becf (patch) | |
tree | da9e1fca3920fbffa3b3f74ec29062edda57f6d2 | |
parent | no need to depend on a file twice (diff) | |
download | wireguard-openbsd-afdabf13cf434cbb2164e59d58340fb877b5becf.tar.xz wireguard-openbsd-afdabf13cf434cbb2164e59d58340fb877b5becf.zip |
Storeing current cpu_info address into LLAddr register, for curcpu().
Instead of previous implementation, we won't use physical cpuid to fetch curcpu().
This requires to implement IP27/35 SMP.
Implemented getcurcpu() and setcurcpu() for it, smp_malloc() renamed alloc_contiguous_pages() because now it only allocate by page.
ok miod@
-rw-r--r-- | sys/arch/mips64/include/asm.h | 10 | ||||
-rw-r--r-- | sys/arch/mips64/include/cpu.h | 14 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/context.S | 5 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/cp0access.S | 16 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/cpu.c | 84 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/genassym.cf | 3 | ||||
-rw-r--r-- | sys/arch/mips64/mips64/ipifuncs.c | 8 | ||||
-rw-r--r-- | sys/arch/sgi/include/asm.h | 11 | ||||
-rw-r--r-- | sys/arch/sgi/include/cpu.h | 23 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/ip30_machdep.c | 10 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/ip30_nmi.S | 4 | ||||
-rw-r--r-- | sys/arch/sgi/sgi/machdep.c | 7 |
12 files changed, 95 insertions, 100 deletions
diff --git a/sys/arch/mips64/include/asm.h b/sys/arch/mips64/include/asm.h index c35d23a53b1..c8c2b368a41 100644 --- a/sys/arch/mips64/include/asm.h +++ b/sys/arch/mips64/include/asm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: asm.h,v 1.10 2010/01/09 23:34:29 miod Exp $ */ +/* $OpenBSD: asm.h,v 1.11 2010/04/28 16:20:28 syuu Exp $ */ /* * Copyright (c) 2001-2002 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -299,11 +299,9 @@ x: ; \ #ifdef MULTIPROCESSOR #define GET_CPU_INFO(ci, tmp) \ - HW_CPU_NUMBER(tmp); \ - PTR_SLL tmp, tmp, LOGREGSZ; \ - LA ci, cpu_info; \ - PTR_ADDU ci, ci, tmp; \ - PTR_L ci, 0(ci) + LOAD_XKPHYS(ci, CCA_CACHED); \ + mfc0 tmp, COP_0_LLADDR; \ + or ci, ci, tmp #else /* MULTIPROCESSOR */ #define GET_CPU_INFO(ci, tmp) \ LA ci, cpu_info_primary diff --git a/sys/arch/mips64/include/cpu.h b/sys/arch/mips64/include/cpu.h index 746fa74aa71..1ac433cee08 100644 --- a/sys/arch/mips64/include/cpu.h +++ b/sys/arch/mips64/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.57 2010/02/28 18:01:36 miod Exp $ */ +/* $OpenBSD: cpu.h,v 1.58 2010/04/28 16:20:28 syuu Exp $ */ /*- * Copyright (c) 1992, 1993 @@ -428,18 +428,22 @@ extern struct cpu_info *cpu_info_list; #ifdef MULTIPROCESSOR #define MAXCPUS 4 -#define curcpu() (cpu_info[cpu_number()]) +extern struct cpu_info *getcurcpu(void); +extern void setcurcpu(struct cpu_info *); +#ifdef DEBUG +extern struct cpu_info *get_cpu_info(int); +#endif +#define curcpu() getcurcpu() #define CPU_IS_PRIMARY(ci) ((ci)->ci_flags & CPUF_PRIMARY) -#define cpu_number() hw_cpu_number() +#define cpu_number() (curcpu()->ci_cpuid) extern struct cpuset cpus_running; -extern struct cpu_info *cpu_info[]; void cpu_unidle(struct cpu_info *); void cpu_boot_secondary_processors(void); #define cpu_boot_secondary(ci) hw_cpu_boot_secondary(ci) #define cpu_hatch(ci) hw_cpu_hatch(ci) -vaddr_t smp_malloc(size_t); +vaddr_t alloc_contiguous_pages(size_t); #define MIPS64_IPI_NOP 0x00000001 #define MIPS64_IPI_RENDEZVOUS 0x00000002 diff --git a/sys/arch/mips64/mips64/context.S b/sys/arch/mips64/mips64/context.S index ae0e3ae7b11..23af7f90105 100644 --- a/sys/arch/mips64/mips64/context.S +++ b/sys/arch/mips64/mips64/context.S @@ -1,4 +1,4 @@ -/* $OpenBSD: context.S,v 1.44 2010/02/13 14:04:45 miod Exp $ */ +/* $OpenBSD: context.S,v 1.45 2010/04/28 16:20:28 syuu Exp $ */ /* * Copyright (c) 2002-2003 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -145,7 +145,8 @@ NON_LEAF(cpu_switchto_asm, FRAMESZ(CF_SZ), ra) PTR_L t0, P_VMSPACE(s0) # p->p_vmspace PTR_L t1, VMSPACE_PMAP(t0) # ->vm_map.pmap #ifdef MULTIPROCESSOR - HW_CPU_NUMBER(v0) # cpuid + GET_CPU_INFO(v0, t2) + PTR_L v0, CI_CPUID(v0) PTR_SLL v0, v0, 0x3 # size of pmap_asid_info PTR_ADDU t1, t1, v0 #endif diff --git a/sys/arch/mips64/mips64/cp0access.S b/sys/arch/mips64/mips64/cp0access.S index 5888e611b66..3321ae85ea7 100644 --- a/sys/arch/mips64/mips64/cp0access.S +++ b/sys/arch/mips64/mips64/cp0access.S @@ -1,4 +1,4 @@ -/* $OpenBSD: cp0access.S,v 1.12 2010/01/09 23:34:29 miod Exp $ */ +/* $OpenBSD: cp0access.S,v 1.13 2010/04/28 16:20:28 syuu Exp $ */ /* * Copyright (c) 2001-2003 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -192,3 +192,17 @@ LEAF(cp0_setperfctrl, 0) j ra nop END(cp0_setperfctrl) + +#ifdef MULTIPROCESSOR +LEAF(getcurcpu, 0) + GET_CPU_INFO(v0, v1) + jr ra + nop +END(getcurcpu) + +LEAF(setcurcpu, 0) + mtc0 a0, COP_0_LLADDR + j ra + nop +END(setcurcpu) +#endif diff --git a/sys/arch/mips64/mips64/cpu.c b/sys/arch/mips64/mips64/cpu.c index f73e28e06b0..29425f944c7 100644 --- a/sys/arch/mips64/mips64/cpu.c +++ b/sys/arch/mips64/mips64/cpu.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.c,v 1.28 2010/03/28 17:09:36 miod Exp $ */ +/* $OpenBSD: cpu.c,v 1.29 2010/04/28 16:20:28 syuu Exp $ */ /* * Copyright (c) 1997-2004 Opsycon AB (www.opsycon.se) @@ -41,15 +41,9 @@ void cpuattach(struct device *, struct device *, void *); struct cpu_info cpu_info_primary; struct cpu_info *cpu_info_list = &cpu_info_primary; +struct cpu_info *cpu_info_secondaries; #ifdef MULTIPROCESSOR struct cpuset cpus_running; - -/* - * Array of CPU info structures. Must be statically-allocated because - * curproc, etc. are used early. - */ - -struct cpu_info *cpu_info[MAXCPUS] = { &cpu_info_primary }; #endif vaddr_t CpuCacheAliasMask; @@ -91,18 +85,18 @@ cpuattach(struct device *parent, struct device *dev, void *aux) #ifdef MULTIPROCESSOR ci->ci_flags |= CPUF_RUNNING | CPUF_PRESENT | CPUF_PRIMARY; cpuset_add(&cpus_running, ci); + cpu_info_secondaries = (struct cpu_info *)alloc_contiguous_pages( + sizeof(struct cpu_info) * ncpusfound - 1); + if (cpu_info_secondaries == NULL) + panic("unable to allocate cpu_info\n"); #endif } #ifdef MULTIPROCESSOR else { - ci = (struct cpu_info *)smp_malloc(sizeof(*ci)); - if (ci == NULL) - panic("unable to allocate cpu_info\n"); - bzero((char *)ci, sizeof(*ci)); + ci = &cpu_info_secondaries[cpuno - 1]; ci->ci_next = cpu_info_list->ci_next; cpu_info_list->ci_next = ci; ci->ci_flags |= CPUF_PRESENT; - cpu_info[cpuno] = ci; } #endif ci->ci_self = ci; @@ -373,16 +367,28 @@ save_fpu(void) } #ifdef MULTIPROCESSOR +#ifdef DEBUG +struct cpu_info * +get_cpu_info(int cpuno) +{ + struct cpu_info *ci; + CPU_INFO_ITERATOR cii; + + CPU_INFO_FOREACH(cii, ci) { + if (ci->ci_cpuid == cpuno) + return ci; + } + return NULL; +} +#endif + void cpu_boot_secondary_processors(void) { struct cpu_info *ci; - u_long i; + CPU_INFO_ITERATOR cii; - for (i = 0; i < MAXCPUS; i++) { - ci = cpu_info[i]; - if (ci == NULL) - continue; + CPU_INFO_FOREACH(cii, ci) { if ((ci->ci_flags & CPUF_PRESENT) == 0) continue; if (ci->ci_flags & CPUF_PRIMARY) @@ -391,7 +397,7 @@ cpu_boot_secondary_processors(void) sched_init_cpu(ci); ci->ci_randseed = random(); cpu_boot_secondary(ci); - } + } /* This must called after xheart0 has initialized, so here is * the best place to do so. @@ -407,31 +413,21 @@ cpu_unidle(struct cpu_info *ci) } vaddr_t -smp_malloc(size_t size) +alloc_contiguous_pages(size_t size) { - struct pglist mlist; - struct vm_page *m; - int error; - vaddr_t va; - paddr_t pa; - - if (size < PAGE_SIZE) { - va = (vaddr_t)malloc(size, M_DEVBUF, M_NOWAIT); - if (va == NULL) - return NULL; - error = pmap_extract(pmap_kernel(), va, &pa); - if (error == FALSE) - return NULL; - } else { - TAILQ_INIT(&mlist); - error = uvm_pglistalloc(size, 0, -1L, 0, 0, - &mlist, 1, UVM_PLA_NOWAIT); - if (error) - return NULL; - m = TAILQ_FIRST(&mlist); - pa = VM_PAGE_TO_PHYS(m); - } - - return PHYS_TO_XKPHYS(pa, CCA_CACHED); + struct pglist mlist; + struct vm_page *m; + int error; + paddr_t pa; + + TAILQ_INIT(&mlist); + error = uvm_pglistalloc(roundup(size, USPACE), 0, 0xffffffff, 0, 0, + &mlist, 1, UVM_PLA_NOWAIT | UVM_PLA_ZERO); + if (error) + return NULL; + m = TAILQ_FIRST(&mlist); + pa = VM_PAGE_TO_PHYS(m); + + return PHYS_TO_XKPHYS(pa, CCA_CACHED); } #endif diff --git a/sys/arch/mips64/mips64/genassym.cf b/sys/arch/mips64/mips64/genassym.cf index b04d4682219..52bb0dd5b76 100644 --- a/sys/arch/mips64/mips64/genassym.cf +++ b/sys/arch/mips64/mips64/genassym.cf @@ -1,4 +1,4 @@ -# $OpenBSD: genassym.cf,v 1.6 2010/01/09 23:43:43 miod Exp $ +# $OpenBSD: genassym.cf,v 1.7 2010/04/28 16:20:28 syuu Exp $ # # Copyright (c) 1997 Per Fogelstrom / Opsycon AB # @@ -58,6 +58,7 @@ member pcb_onfault member pcb_segtab struct cpu_info +member ci_cpuid member ci_curproc member ci_curprocpaddr member ci_fpuproc diff --git a/sys/arch/mips64/mips64/ipifuncs.c b/sys/arch/mips64/mips64/ipifuncs.c index 4a65832952e..850768476d0 100644 --- a/sys/arch/mips64/mips64/ipifuncs.c +++ b/sys/arch/mips64/mips64/ipifuncs.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ipifuncs.c,v 1.3 2010/04/21 14:57:11 deraadt Exp $ */ +/* $OpenBSD: ipifuncs.c,v 1.4 2010/04/28 16:20:28 syuu Exp $ */ /* $NetBSD: ipifuncs.c,v 1.40 2008/04/28 20:23:10 martin Exp $ */ /*- @@ -119,10 +119,10 @@ mips64_ipi_intr(void *arg) void mips64_send_ipi(unsigned int cpuid, unsigned int ipimask) { -#ifdef DIAGNOSTIC - if (cpuid >= CPU_MAXID || cpu_info[cpuid] == NULL) +#ifdef DEBUG + if (cpuid >= CPU_MAXID || get_cpu_info(cpuid) == NULL) panic("mips_send_ipi: bogus cpu_id"); - if (!cpuset_isset(&cpus_running, cpu_info[cpuid])) + if (!cpuset_isset(&cpus_running, get_cpu_info(cpuid))) panic("mips_send_ipi: CPU %ld not running", cpuid); #endif diff --git a/sys/arch/sgi/include/asm.h b/sys/arch/sgi/include/asm.h index 23aea156911..f2930028dcd 100644 --- a/sys/arch/sgi/include/asm.h +++ b/sys/arch/sgi/include/asm.h @@ -1,14 +1,5 @@ -/* $OpenBSD: asm.h,v 1.2 2009/09/30 06:22:00 syuu Exp $ */ +/* $OpenBSD: asm.h,v 1.3 2010/04/28 16:20:28 syuu Exp $ */ /* Use Mips generic include file */ -#ifdef MULTIPROCESSOR -#define HW_CPU_NUMBER(reg) \ - LA reg, HW_CPU_NUMBER_REG; \ - PTR_L reg, 0(reg) -#else /* MULTIPROCESSOR */ -#define HW_CPU_NUMBER(reg) \ - LI reg, 0 -#endif /* MULTIPROCESSOR */ - #include <mips64/asm.h> diff --git a/sys/arch/sgi/include/cpu.h b/sys/arch/sgi/include/cpu.h index cfa370c3622..558e15c1b76 100644 --- a/sys/arch/sgi/include/cpu.h +++ b/sys/arch/sgi/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.8 2010/01/09 23:34:29 miod Exp $ */ +/* $OpenBSD: cpu.h,v 1.9 2010/04/28 16:20:28 syuu Exp $ */ /*- * Copyright (c) 1992, 1993 * The Regents of the University of California. All rights reserved. @@ -45,16 +45,7 @@ #define _SGI_CPU_H_ #ifdef _KERNEL - -#ifdef MULTIPROCESSOR - -#if defined(TGT_OCTANE) -#define HW_CPU_NUMBER_REG 0x900000000ff50000 /* HEART_PRID */ -#else -#error MULTIPROCESSOR kernel not supported on this configuration -#endif - -#if !defined(_LOCORE) +#if defined(MULTIPROCESSOR) && !defined(_LOCORE) struct cpu_info; void hw_cpu_boot_secondary(struct cpu_info *); void hw_cpu_hatch(struct cpu_info *); @@ -62,15 +53,7 @@ void hw_cpu_spinup_trampoline(struct cpu_info *); int hw_ipi_intr_establish(int (*)(void *), u_long); void hw_ipi_intr_set(u_long); void hw_ipi_intr_clear(u_long); -#endif - -#define hw_cpu_number() (*(uint64_t *)HW_CPU_NUMBER_REG) - -#else /* MULTIPROCESSOR */ - -#define hw_cpu_number() 0 - -#endif /* MULTIPROCESSOR */ +#endif /* MULTIPROCESSOR && !_LOCORE */ /* * Define soft selected cache functions. diff --git a/sys/arch/sgi/sgi/ip30_machdep.c b/sys/arch/sgi/sgi/ip30_machdep.c index 8f3a9498a96..0e31926f453 100644 --- a/sys/arch/sgi/sgi/ip30_machdep.c +++ b/sys/arch/sgi/sgi/ip30_machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ip30_machdep.c,v 1.41 2010/04/21 14:57:11 deraadt Exp $ */ +/* $OpenBSD: ip30_machdep.c,v 1.42 2010/04/28 16:20:28 syuu Exp $ */ /* * Copyright (c) 2008, 2009 Miodrag Vallat. @@ -531,10 +531,9 @@ hw_cpu_boot_secondary(struct cpu_info *ci) scachesz, fanloads, launch, rndvz, stackaddr, lparam, rparam, idleflag); #endif - kstack = smp_malloc(USPACE); + kstack = alloc_contiguous_pages(USPACE); if (kstack == NULL) panic("unable to allocate idle stack\n"); - bzero((char *)kstack, USPACE); ci->ci_curprocpaddr = (void *)kstack; *(volatile uint64_t *)(mpconf + MPCONF_STACKADDR(cpuid)) = @@ -554,6 +553,11 @@ hw_cpu_hatch(struct cpu_info *ci) int s; /* + * Set curcpu address on this processor. + */ + setcurcpu(ci); + + /* * Make sure we can access the extended address space. * Note that r10k and later do not allow XUSEG accesses * from kernel mode unless SR_UX is set. diff --git a/sys/arch/sgi/sgi/ip30_nmi.S b/sys/arch/sgi/sgi/ip30_nmi.S index b3f2cbf2b23..3448cc981c3 100644 --- a/sys/arch/sgi/sgi/ip30_nmi.S +++ b/sys/arch/sgi/sgi/ip30_nmi.S @@ -1,4 +1,4 @@ -/* $OpenBSD: ip30_nmi.S,v 1.2 2010/01/13 23:24:27 miod Exp $ */ +/* $OpenBSD: ip30_nmi.S,v 1.3 2010/04/28 16:20:28 syuu Exp $ */ /* * Copyright (c) 2010 Miodrag Vallat. @@ -23,9 +23,7 @@ #include <arch/sgi/sgi/ip30.h> -#ifndef MULTIPROCESSOR #define HW_CPU_NUMBER_REG 0x900000000ff50000 /* HEART_PRID */ -#endif #include "assym.h" diff --git a/sys/arch/sgi/sgi/machdep.c b/sys/arch/sgi/sgi/machdep.c index bf5fec1883f..076b735bde2 100644 --- a/sys/arch/sgi/sgi/machdep.c +++ b/sys/arch/sgi/sgi/machdep.c @@ -1,4 +1,4 @@ -/* $OpenBSD: machdep.c,v 1.100 2010/03/03 12:25:09 jsing Exp $ */ +/* $OpenBSD: machdep.c,v 1.101 2010/04/28 16:20:28 syuu Exp $ */ /* * Copyright (c) 2003-2004 Opsycon AB (www.opsycon.se / www.opsycon.com) @@ -150,6 +150,11 @@ mips_init(int argc, void *argv, caddr_t boot_esym) extern char *hw_vendor; /* + * Set curcpu address on primary processor. + */ + setcurcpu(&cpu_info_primary); + + /* * Make sure we can access the extended address space. * Note that r10k and later do not allow XUSEG accesses * from kernel mode unless SR_UX is set. |