diff --git a/sys/arch/hp700/dev/cpu.c b/sys/arch/hp700/dev/cpu.c index 04f4f44020e5..2cb2cf921c18 100644 --- a/sys/arch/hp700/dev/cpu.c +++ b/sys/arch/hp700/dev/cpu.c @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.c,v 1.14 2010/03/30 07:58:02 skrll Exp $ */ +/* $NetBSD: cpu.c,v 1.15 2010/06/06 12:13:35 skrll Exp $ */ /* $OpenBSD: cpu.c,v 1.28 2004/12/28 05:18:25 mickey Exp $ */ @@ -29,7 +29,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.14 2010/03/30 07:58:02 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: cpu.c,v 1.15 2010/06/06 12:13:35 skrll Exp $"); #include #include @@ -51,6 +51,10 @@ struct cpu_softc { void *sc_ih; }; +#ifdef MULTIPROCESSOR +int hppa_ncpus; +#endif + int cpumatch(device_t, cfdata_t, void *); void cpuattach(device_t, device_t, void *); diff --git a/sys/arch/hp700/hp700/locore.S b/sys/arch/hp700/hp700/locore.S index 9d4eff06f134..b212d6f5027d 100644 --- a/sys/arch/hp700/hp700/locore.S +++ b/sys/arch/hp700/hp700/locore.S @@ -1,4 +1,4 @@ -/* $NetBSD: locore.S,v 1.46 2010/04/05 12:56:51 skrll Exp $ */ +/* $NetBSD: locore.S,v 1.47 2010/06/06 12:13:35 skrll Exp $ */ /* $OpenBSD: locore.S,v 1.158 2008/07/28 19:08:46 miod Exp $ */ /* @@ -140,6 +140,16 @@ #define MFCPU_C(r,x) .word 0x14000600 | ((r) << 21) | ((x) << 16) #define MFCPU_U(r,x) .word 0x140008a0 | ((r) << 21) | ((x)) #define MTCPU_U(x,r) .word 0x14001840 | ((r) << 21) | ((x) << 16) +#endif + +#ifdef MULTIPROCESSOR +#define GET_CURCPU(r) mfctl CR_CURCPU, r +#define GET_CURLWP(r) mfctl CR_CURCPU, r ! ldw CI_CURLWP(r), r +#define SET_CURLWP(r,s) mfctl CR_CURCPU, s ! stw r, CI_CURLWP(s) +#else +#define GET_CURCPU(r) mfctl CR_CURLWP, r ! ldw L_CPU(r), r +#define GET_CURLWP(r) mfctl CR_CURLWP, r +#define SET_CURLWP(r,s) mtctl r, CR_CURLWP #endif .import $global$, data @@ -537,8 +547,7 @@ EXIT(pdc_call) * int splraise(int ncpl); */ LEAF_ENTRY(splraise) - mfctl CR_CURLWP, %t1 - ldw L_CPU(%t1),%t1 + GET_CURCPU(%t1) ldw CI_CPL(%t1), %ret0 or %ret0, %arg0, %arg0 bv %r0(%rp) @@ -549,8 +558,7 @@ EXIT(splraise) * int spllower(int ncpl); */ ENTRY(spllower,HPPA_FRAME_SIZE) - mfctl CR_CURLWP, %t1 - ldw L_CPU(%t1),%t1 + GET_CURCPU(%t1) ldw CI_IPENDING(%t1), %r1 ; load ipending andcm,<> %r1, %arg0, %r1 ; and with complement of new cpl @@ -615,8 +623,7 @@ EXIT(spllower) * void hp700_intr_schedule(int mask); */ ENTRY(hp700_intr_schedule,0) - mfctl CR_CURLWP, %t1 - ldw L_CPU(%t1),%t2 + GET_CURCPU(%t2) mfctl %eiem, %arg1 mtctl %r0, %eiem ; disable interrupts ldw CI_IPENDING(%t2), %r1 ; load ipending @@ -870,12 +877,7 @@ switch_exited: ldw TF_CR30(%t1), %t2 /* pmap_activate? */ mtctl %t2, CR_FPPADDR /* pmap_activate? */ - mtctl %arg1, CR_CURLWP - -#ifdef MULTIPROCESSOR - ldw L_CPU(%arg1),%t2 ; %t2 = curcpu() - stw %arg1, CI_CURLWP(%t2) -#endif + SET_CURLWP(%arg1, %t2) ldo -(HPPA_FRAME_SIZE+16*4)(%sp), %r3 @@ -991,7 +993,7 @@ ALTENTRY(setfunc_trampoline) * this LWP was created by the fork() * syscall, which we now return from. */ - mfctl CR_CURLWP, %t2 + GET_CURLWP(%t2) .call b syscall_return ldw L_MD(%t2), %t3 diff --git a/sys/arch/hp700/hp700/machdep.c b/sys/arch/hp700/hp700/machdep.c index 7655869e07c4..5dd5ba44e17f 100644 --- a/sys/arch/hp700/hp700/machdep.c +++ b/sys/arch/hp700/hp700/machdep.c @@ -1,4 +1,4 @@ -/* $NetBSD: machdep.c,v 1.87 2010/06/06 10:15:51 skrll Exp $ */ +/* $NetBSD: machdep.c,v 1.88 2010/06/06 12:13:35 skrll Exp $ */ /*- * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc. @@ -58,7 +58,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.87 2010/06/06 10:15:51 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.88 2010/06/06 12:13:35 skrll Exp $"); #include "opt_cputype.h" #include "opt_ddb.h" @@ -256,10 +256,13 @@ struct fpreg lwp0_fpregs; /* Virtual page frame for /dev/mem (see mem.c) */ vaddr_t vmmap; +/* Our exported CPU info */ struct cpu_info cpus[HPPA_MAXCPUS] = { + { #ifdef MULTIPROCESSOR - .ci_curlwp = &lwp0 + .ci_curlwp = &lwp0, #endif + }, }; struct vm_map *phys_map = NULL; @@ -426,8 +429,12 @@ hppa_init(paddr_t start, void *bi) #ifdef KGDB boothowto |= RB_KDB; /* go to kgdb early if compiled in. */ #endif - /* Setup curlwp early for LOCKDEBUG */ + /* Setup curlwp/curcpu early for LOCKDEBUG */ +#ifdef MULTIPROCESSOR + mtctl(&cpus[0], CR_CURCPU); +#else mtctl(&lwp0, CR_CURLWP); +#endif /* Copy bootinfo */ if (bi != NULL) diff --git a/sys/arch/hp700/include/cpu.h b/sys/arch/hp700/include/cpu.h index bc592ff0c9da..ead7a2dd5ab6 100644 --- a/sys/arch/hp700/include/cpu.h +++ b/sys/arch/hp700/include/cpu.h @@ -1,4 +1,4 @@ -/* $NetBSD: cpu.h,v 1.51 2010/06/06 10:22:43 skrll Exp $ */ +/* $NetBSD: cpu.h,v 1.52 2010/06/06 12:13:36 skrll Exp $ */ /* $OpenBSD: cpu.h,v 1.55 2008/07/23 17:39:35 kettenis Exp $ */ @@ -231,7 +231,9 @@ struct cpu_info { struct cpu_data ci_data; /* MI per-cpu data */ +#ifdef MULTIPROCESSOR struct lwp *ci_curlwp; /* CPU owner */ +#endif int ci_cpuid; /* CPU index (see cpus[] array) */ int ci_mtx_count; int ci_mtx_oldspl; @@ -252,15 +254,31 @@ struct cpu_info { #ifdef MULTIPROCESSOR +/* Number of CPUs in the system */ +extern int hppa_ncpus; + #define HPPA_MAXCPUS 4 #define cpu_number() (curcpu()->ci_cpuid) #define CPU_IS_PRIMARY(ci) ((ci)->ci_cpuid == 0) #define CPU_INFO_ITERATOR int -#define CPU_INFO_FOREACH(cii, ci) cii = 0; ci = &cpus[0], cii < ncpus; cii++, ci++ +#define CPU_INFO_FOREACH(cii, ci) cii = 0; ci = &cpus[0], cii < hppa_ncpus; cii++, ci++ void cpu_boot_secondary_processors(void); -#else /* MULTIPROCESSOR */ + +static __inline struct cpu_info * +hppa_curcpu(void) +{ + struct cpu_info *ci; + + __asm volatile("mfctl %1, %0" : "=r" (ci): "i" (CR_CURCPU)); + + return ci; +} + +#define curcpu() hppa_curcpu() + +#else /* MULTIPROCESSOR */ #define HPPA_MAXCPUS 1 #define curcpu() (&cpus[0]) diff --git a/sys/arch/hppa/hppa/copy.S b/sys/arch/hppa/hppa/copy.S index 920a42d2c50f..6cda50d535e1 100644 --- a/sys/arch/hppa/hppa/copy.S +++ b/sys/arch/hppa/hppa/copy.S @@ -1,4 +1,4 @@ -/* $NetBSD: copy.S,v 1.16 2010/03/20 23:31:27 chs Exp $ */ +/* $NetBSD: copy.S,v 1.17 2010/06/06 12:13:36 skrll Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -98,7 +98,7 @@ LEAF_ENTRY_NOPROFILE(name) ! \ ldil L%VM_MAXUSER_ADDRESS, %t1 ! \ comb,>>= %arg0, %t1, fusubadaddr ! \ - mfctl CR_CURLWP, %t1 ! \ + GET_CURLWP(%t1) ! \ ldw L_PCB(%t1), %t1 ! \ ldil L%fusufault, %t2 ! \ ldo R%fusufault(%t2), %t2 ! \ @@ -149,7 +149,7 @@ SUX(suswintr, sth) */ LEAF_ENTRY(spstrcpy) /* setup fault handler */ - mfctl CR_CURLWP, %r31 + GET_CURLWP(%r31) ldw L_PCB(%r31), %r31 ldil L%L$spstrcpy_fault, %t2 ldo R%L$spstrcpy_fault(%t2), %t2 @@ -222,7 +222,7 @@ EXIT(name) /* This loads curlwp's space into the given register. */ #define SPACE_CURLWP(reg) \ - mfctl CR_CURLWP, reg ! \ + GET_CURLWP(reg) ! \ ldw L_PCB(reg), reg ! \ ldw PCB_SPACE(reg), reg @@ -352,7 +352,7 @@ LEAF_ENTRY(ucas_32) comb,>>= %arg0, %t1, 1f /* setup fault handler */ - mfctl CR_CURLWP, %r31 + GET_CURLWP(%r31) ldw L_PCB(%r31), %r31 ldil L%L$ucas_32_fault, %t2 ldo R%L$ucas_32_fault(%t2), %t2 diff --git a/sys/arch/hppa/hppa/trap.S b/sys/arch/hppa/hppa/trap.S index 636275e0471b..d98f0ad8ced9 100644 --- a/sys/arch/hppa/hppa/trap.S +++ b/sys/arch/hppa/hppa/trap.S @@ -1,4 +1,4 @@ -/* $NetBSD: trap.S,v 1.49 2010/04/26 12:10:51 skrll Exp $ */ +/* $NetBSD: trap.S,v 1.50 2010/06/06 12:13:36 skrll Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -203,7 +203,7 @@ syscall_entry: */ /* t2 = curlwp PCB */ - mfctl CR_CURLWP, %t3 + GET_CURLWP(%t3) ldw L_PCB(%sr1, %t3), %t2 /* XXX can use ,sl */ /* @@ -399,7 +399,7 @@ syscall_entry: CALL(syscall, %r1) /* load curlwp's trapframe pointer */ - mfctl CR_CURLWP, %r1 + GET_CURLWP(%r1) ldw L_MD(%r1), %t3 .exit @@ -421,8 +421,7 @@ syscall_return: * a note for trapall). Hopefully no page fault would happen on or after * the copy, and interrupts are disabled. */ - mfctl CR_CURLWP, %t2 - ldw L_CPU(%t2), %t2 + GET_CURCPU(%t2) ldo CI_TRAPSAVE(%t2), %t2 ldw 0(%t3), %r1 ! ldw 4(%t3), %t1 ! stw %r1, 0(%t2) ! stw %t1, 4(%t2) @@ -508,8 +507,13 @@ syscall_return: ldw TF_CR30(%sr3, %t3), %t1 mtctl %t1, CR_FPPADDR +#ifdef MULTIPROCESSOR + mfctl CR_CURCPU, %t3 +#else mfctl CR_CURLWP, %t3 ldw L_CPU(%sr3, %t3), %t3 +#endif + /* * Clear the system mask, this puts us back into physical mode. Reload * the trapframe pointer with the correspondent PA value. %sp will be @@ -1910,8 +1914,7 @@ ENTRY_NOPROFILE(TLABEL(all),0) /* do not overwrite %tr4(%cr28) it contains the contents of r24 */ mtctl %t3, %tr2 - mfctl CR_CURLWP, %t3 - ldw L_CPU(%t3), %t3 + GET_CURCPU(%t3) stw %t1, CI_TRAPSAVE + TF_R22(%t3) /* use ,bc */ stw %t2, CI_TRAPSAVE + TF_R21(%t3) @@ -2119,8 +2122,7 @@ trapnowvirt: /* * Copy partially saved state from the store into the frame */ - mfctl CR_CURLWP, %t2 - ldw L_CPU(%t2), %t2 + GET_CURCPU(%t2) ldo CI_TRAPSAVE(%t2), %t2 /* use ,bc each line */ @@ -2222,7 +2224,7 @@ trapnowvirt: bb,>=,n %arg0, TFF_LAST_POS, L$trap_return nop - mfctl CR_CURLWP, %t2 + GET_CURLWP(%t2) ldw L_MD(%t2), %t3 L$trap_return: diff --git a/sys/arch/hppa/include/reg.h b/sys/arch/hppa/include/reg.h index 6e948cab3ac1..2227aede9db4 100644 --- a/sys/arch/hppa/include/reg.h +++ b/sys/arch/hppa/include/reg.h @@ -1,4 +1,4 @@ -/* $NetBSD: reg.h,v 1.11 2010/03/16 16:20:19 skrll Exp $ */ +/* $NetBSD: reg.h,v 1.12 2010/06/06 12:13:36 skrll Exp $ */ /* $OpenBSD: reg.h,v 1.7 2000/06/15 17:00:37 mickey Exp $ */ @@ -82,7 +82,11 @@ #define CR_EIRR 23 /* Temporary control registers */ +#ifdef MULTIPROCESSOR +#define CR_CURCPU 24 /* tr0: curcpu */ +#else #define CR_CURLWP 24 /* tr0: curlwp */ +#endif #define CR_VTOP 25 /* tr1: virt to phys table address */ #define CR_TR2 26 /* tr2: temporary */ #define CR_TLS 27 /* tr3: thread local storage pointer */