diff options
author | Mark Kettenis <kettenis@cvs.openbsd.org> | 2007-03-20 20:59:55 +0000 |
---|---|---|
committer | Mark Kettenis <kettenis@cvs.openbsd.org> | 2007-03-20 20:59:55 +0000 |
commit | edb06578c73fe05fb3c9ab52a47e1d0a34eca656 (patch) | |
tree | 0c292f80e38cc053d22638c7a85f354f2a842154 /sys/arch/powerpc/include | |
parent | c0b399741b60996c0b30aaa0dc02061dc731634c (diff) |
Move macppc to __HAVE_CPUINFO, and make locore.S and trap.c suitable for
MULTIPROCESSOR. From now on sprg0 holds a pointer to struct cpuinfo, which
is used to spill registers to during trap instead of the globals we used to
use for that purpose. Bits and pieces from NetBSD. Help from drahn@ and art@.
Tested by xsa@, thib@, miod@, gwk@, deraadt@.
ok drahn@, gwk@
Diffstat (limited to 'sys/arch/powerpc/include')
-rw-r--r-- | sys/arch/powerpc/include/_types.h | 5 | ||||
-rw-r--r-- | sys/arch/powerpc/include/cpu.h | 101 | ||||
-rw-r--r-- | sys/arch/powerpc/include/intr.h | 26 | ||||
-rw-r--r-- | sys/arch/powerpc/include/lock.h | 112 | ||||
-rw-r--r-- | sys/arch/powerpc/include/pcb.h | 4 |
5 files changed, 226 insertions, 22 deletions
diff --git a/sys/arch/powerpc/include/_types.h b/sys/arch/powerpc/include/_types.h index 1529aa9cdfb..d8cc81d4506 100644 --- a/sys/arch/powerpc/include/_types.h +++ b/sys/arch/powerpc/include/_types.h @@ -1,4 +1,4 @@ -/* $OpenBSD: _types.h,v 1.2 2006/01/13 17:50:06 millert Exp $ */ +/* $OpenBSD: _types.h,v 1.3 2007/03/20 20:59:53 kettenis Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -115,4 +115,7 @@ typedef int __rune_t; typedef void * __wctrans_t; typedef void * __wctype_t; +/* Feature test macros */ +#define __HAVE_CPUINFO + #endif /* _POWERPC__TYPES_H_ */ diff --git a/sys/arch/powerpc/include/cpu.h b/sys/arch/powerpc/include/cpu.h index d89ed88c158..fe4151fa6be 100644 --- a/sys/arch/powerpc/include/cpu.h +++ b/sys/arch/powerpc/include/cpu.h @@ -1,4 +1,4 @@ -/* $OpenBSD: cpu.h,v 1.29 2007/03/15 10:22:29 art Exp $ */ +/* $OpenBSD: cpu.h,v 1.30 2007/03/20 20:59:53 kettenis Exp $ */ /* $NetBSD: cpu.h,v 1.1 1996/09/30 16:34:21 ws Exp $ */ /* @@ -36,7 +36,85 @@ #include <machine/frame.h> -#include <machine/psl.h> +#include <sys/device.h> +#include <sys/lock.h> +#include <sys/sched.h> + +struct cpu_info { + struct device *ci_dev; /* our device */ + struct schedstate_percpu ci_schedstate; /* scheduler state */ + + struct proc *ci_curproc; + + struct pcb *ci_curpcb; + struct pmap *ci_curpm; + struct proc *ci_fpuproc; + struct proc *ci_vecproc; + struct pcb *ci_idle_pcb; /* PA of our idle pcb */ + int ci_cpuid; + + volatile int ci_astpending; + volatile int ci_want_resched; + volatile int ci_cpl; + volatile int ci_iactive; + volatile int ci_ipending; + int ci_intrdepth; + char *ci_intstk; +#define CPUSAVE_LEN 8 + register_t ci_tempsave[CPUSAVE_LEN]; + register_t ci_ddbsave[CPUSAVE_LEN]; +#define DISISAVE_LEN 4 + register_t ci_disisave[DISISAVE_LEN]; +}; + +static __inline struct cpu_info * +curcpu(void) +{ + struct cpu_info *ci; + + __asm volatile ("mfsprg %0,0" : "=r"(ci)); + return ci; +} + +#define curpcb (curcpu()->ci_curpcb) +#define curpm (curcpu()->ci_curpm) + +#define CPU_INFO_UNIT(ci) ((ci)->ci_dev->dv_unit) + +#ifdef MULTIPROCESSOR + +#define PPC_MAXPROCS 4 + +static __inline int +cpu_number(void) +{ + int pir; + + __asm ("mfspr %0,1023" : "=r"(pir)); + return pir; +} + +void cpu_boot_secondary_processors(void); + +#define CPU_IS_PRIMARY(ci) ((ci)->ci_cpuid == 0) +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = &cpu_info[0]; cii < PPC_MAXPROCS; cii++, ci++) + +#else + +#define PPC_MAXPROCS 1 + +#define cpu_number() 0 + +#define CPU_IS_PRIMARY(ci) 1 +#define CPU_INFO_ITERATOR int +#define CPU_INFO_FOREACH(cii, ci) \ + for (cii = 0, ci = curcpu(); ci != NULL; ci = NULL) + +#endif + +extern struct cpu_info cpu_info[PPC_MAXPROCS]; #define CLKF_USERMODE(frame) (((frame)->srr1 & PSL_PR) != 0) #define CLKF_PC(frame) ((frame)->srr0) @@ -47,12 +125,9 @@ void delay(unsigned); #define DELAY(n) delay(n) -extern volatile int want_resched; -extern volatile int astpending; - -#define need_resched(ci) (want_resched = 1, astpending = 1) -#define need_proftick(p) do { astpending = 1; } while (0) -#define signotify(p) (astpending = 1) +#define need_resched(ci) (ci->ci_want_resched = 1, ci->ci_astpending = 1) +#define need_proftick(p) do { curcpu()->ci_astpending = 1; } while (0) +#define signotify(p) (curcpu()->ci_astpending = 1) extern char *bootpath; @@ -200,6 +275,8 @@ void ppc64_mtscomc(u_int64_t); u_int64_t ppc64_mfscomd(void); void ppc_mtscomd(u_int32_t); +#include <machine/psl.h> + /* * General functions to enable and disable interrupts * without having inlined assembly code in many functions. @@ -250,4 +327,12 @@ extern int ppc_proc_is_64b; #define PPC_CPU_MPC7455 0x8001 #define PPC_CPU_MPC7457 0x8002 +/* + * This needs to be included late since it relies on definitions higher + * up in this file. + */ +#if defined(MULTIPROCESSOR) && defined(_KERNEL) +#include <sys/mplock.h> +#endif + #endif /* _POWERPC_CPU_H_ */ diff --git a/sys/arch/powerpc/include/intr.h b/sys/arch/powerpc/include/intr.h index fc328c7d342..aad653eeb87 100644 --- a/sys/arch/powerpc/include/intr.h +++ b/sys/arch/powerpc/include/intr.h @@ -1,4 +1,4 @@ -/* $OpenBSD: intr.h,v 1.31 2006/03/12 02:55:58 brad Exp $ */ +/* $OpenBSD: intr.h,v 1.32 2007/03/20 20:59:53 kettenis Exp $ */ /* * Copyright (c) 1997 Per Fogelstrom, Opsycon AB and RTMX Inc, USA. @@ -68,7 +68,6 @@ int splsoftnet(void); void do_pending_int(void); -volatile extern int cpl, ipending, astpending; extern int imask[IPL_NUM]; /* SPL asserts */ @@ -82,11 +81,12 @@ extern int imask[IPL_NUM]; volatile static __inline int splraise(int newcpl) { + struct cpu_info *ci = curcpu(); int oldcpl; __asm__ volatile("":::"memory"); /* don't reorder.... */ - oldcpl = cpl; - cpl = oldcpl | newcpl; + oldcpl = ci->ci_cpl; + ci->ci_cpl = oldcpl | newcpl; __asm__ volatile("":::"memory"); /* don't reorder.... */ return(oldcpl); } @@ -94,9 +94,11 @@ splraise(int newcpl) volatile static __inline void splx(int newcpl) { + struct cpu_info *ci = curcpu(); + __asm__ volatile("":::"memory"); /* reorder protect */ - cpl = newcpl; - if(ipending & ~newcpl) + ci->ci_cpl = newcpl; + if(ci->ci_ipending & ~newcpl) do_pending_int(); __asm__ volatile("":::"memory"); /* reorder protect */ } @@ -104,12 +106,13 @@ splx(int newcpl) volatile static __inline int spllower(int newcpl) { + struct cpu_info *ci = curcpu(); int oldcpl; __asm__ volatile("":::"memory"); /* reorder protect */ - oldcpl = cpl; - cpl = newcpl; - if(ipending & ~newcpl) + oldcpl = ci->ci_cpl; + ci->ci_cpl = newcpl; + if(ci->ci_ipending & ~newcpl) do_pending_int(); __asm__ volatile("":::"memory"); /* reorder protect */ return(oldcpl); @@ -120,11 +123,12 @@ spllower(int newcpl) static __inline void set_sint(int pending) { + struct cpu_info *ci = curcpu(); int msrsave; __asm__ ("mfmsr %0" : "=r"(msrsave)); __asm__ volatile ("mtmsr %0" :: "r"(msrsave & ~PSL_EE)); - ipending |= pending; + ci->ci_ipending |= pending; __asm__ volatile ("mtmsr %0" :: "r"(msrsave)); } @@ -140,6 +144,8 @@ set_sint(int pending) #define splaudio() splraise(imask[IPL_AUDIO]) #define splclock() splraise(imask[IPL_CLOCK]) #define splvm() splraise(imask[IPL_VM]) +#define splsched() splhigh() +#define spllock() splhigh() #define splstatclock() splhigh() #define splsoftclock() splraise(SINT_CLOCK) #define splsoftnet() splraise(SINT_NET|SINT_CLOCK) diff --git a/sys/arch/powerpc/include/lock.h b/sys/arch/powerpc/include/lock.h new file mode 100644 index 00000000000..a9b64118c5d --- /dev/null +++ b/sys/arch/powerpc/include/lock.h @@ -0,0 +1,112 @@ +/* $OpenBSD: lock.h,v 1.1 2007/03/20 20:59:53 kettenis Exp $ */ +/* $NetBSD: lock.h,v 1.8 2005/12/28 19:09:29 perry Exp $ */ + +/*- + * Copyright (c) 2000 The NetBSD Foundation, Inc. + * All rights reserved. + * + * This code is derived from software contributed to The NetBSD Foundation + * by Jason R. Thorpe. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the NetBSD + * Foundation, Inc. and its contributors. + * 4. Neither the name of The NetBSD Foundation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Machine-dependent spin lock operations. + */ + +#ifndef _POWERPC_LOCK_H_ +#define _POWERPC_LOCK_H_ + +typedef __volatile int __cpu_simple_lock_t; + +#define __SIMPLELOCK_LOCKED 1 +#define __SIMPLELOCK_UNLOCKED 0 + +static __inline void +__cpu_simple_lock_init(__cpu_simple_lock_t *alp) +{ + *alp = __SIMPLELOCK_UNLOCKED; + __asm volatile ("sync"); +} + +static __inline void +__cpu_simple_lock(__cpu_simple_lock_t *alp) +{ + int old; + + __asm volatile (" \ + \n\ +1: lwarx %0,0,%1 \n\ + cmpwi %0,%2 \n\ + beq+ 3f \n\ +2: lwzx %0,0,%1 \n\ + cmpwi %0,%2 \n\ + beq+ 1b \n\ + b 2b \n\ +3: stwcx. %3,0,%1 \n\ + bne- 1b \n\ + isync \n\ + \n" + : "=&r"(old) + : "r"(alp), "I"(__SIMPLELOCK_UNLOCKED), "r"(__SIMPLELOCK_LOCKED) + : "memory"); +} + +static __inline int +__cpu_simple_lock_try(__cpu_simple_lock_t *alp) +{ + int old, dummy; + + __asm volatile (" \ + \n\ +1: lwarx %0,0,%1 \n\ + cmpwi %0,%2 \n\ + bne 2f \n\ + stwcx. %3,0,%1 \n\ + bne- 1b \n\ +2: stwcx. %3,0,%4 \n\ + isync \n\ + \n" + : "=&r"(old) + : "r"(alp), "I"(__SIMPLELOCK_UNLOCKED), "r"(__SIMPLELOCK_LOCKED), + "r"(&dummy) + : "memory"); + + return (old == __SIMPLELOCK_UNLOCKED); +} + +static __inline void +__cpu_simple_unlock(__cpu_simple_lock_t *alp) +{ + __asm volatile ("sync"); + *alp = __SIMPLELOCK_UNLOCKED; +} + +#endif /* _POWERPC_LOCK_H_ */ diff --git a/sys/arch/powerpc/include/pcb.h b/sys/arch/powerpc/include/pcb.h index bd356bd1891..a49d03f1488 100644 --- a/sys/arch/powerpc/include/pcb.h +++ b/sys/arch/powerpc/include/pcb.h @@ -1,4 +1,4 @@ -/* $OpenBSD: pcb.h,v 1.9 2003/02/26 21:54:44 drahn Exp $ */ +/* $OpenBSD: pcb.h,v 1.10 2007/03/20 20:59:53 kettenis Exp $ */ /* $NetBSD: pcb.h,v 1.1 1996/09/30 16:34:29 ws Exp $ */ /*- @@ -65,8 +65,6 @@ struct md_coredump { }; #ifdef _KERNEL -extern struct pcb *curpcb; -extern struct pmap *curpm; extern struct proc *fpuproc; int setfault(faultbuf *env); #endif |