Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.78
      1  1.54      matt /*	cpu.h,v 1.45.4.7 2008/01/28 18:20:39 matt Exp	*/
      2   1.1   reinoud 
      3   1.1   reinoud /*
      4   1.1   reinoud  * Copyright (c) 1994-1996 Mark Brinicombe.
      5   1.1   reinoud  * Copyright (c) 1994 Brini.
      6   1.1   reinoud  * All rights reserved.
      7   1.1   reinoud  *
      8   1.1   reinoud  * This code is derived from software written for Brini by Mark Brinicombe
      9   1.1   reinoud  *
     10   1.1   reinoud  * Redistribution and use in source and binary forms, with or without
     11   1.1   reinoud  * modification, are permitted provided that the following conditions
     12   1.1   reinoud  * are met:
     13   1.1   reinoud  * 1. Redistributions of source code must retain the above copyright
     14   1.1   reinoud  *    notice, this list of conditions and the following disclaimer.
     15   1.1   reinoud  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1   reinoud  *    notice, this list of conditions and the following disclaimer in the
     17   1.1   reinoud  *    documentation and/or other materials provided with the distribution.
     18   1.1   reinoud  * 3. All advertising materials mentioning features or use of this software
     19   1.1   reinoud  *    must display the following acknowledgement:
     20   1.1   reinoud  *	This product includes software developed by Brini.
     21   1.1   reinoud  * 4. The name of the company nor the name of the author may be used to
     22   1.1   reinoud  *    endorse or promote products derived from this software without specific
     23   1.1   reinoud  *    prior written permission.
     24   1.1   reinoud  *
     25   1.1   reinoud  * THIS SOFTWARE IS PROVIDED BY BRINI ``AS IS'' AND ANY EXPRESS OR IMPLIED
     26   1.1   reinoud  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     27   1.1   reinoud  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     28   1.1   reinoud  * IN NO EVENT SHALL BRINI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
     29   1.1   reinoud  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
     30   1.1   reinoud  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     31   1.1   reinoud  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     32   1.1   reinoud  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     33   1.1   reinoud  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     34   1.1   reinoud  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     35   1.1   reinoud  * SUCH DAMAGE.
     36   1.1   reinoud  *
     37   1.1   reinoud  * RiscBSD kernel project
     38   1.1   reinoud  *
     39   1.1   reinoud  * cpu.h
     40   1.1   reinoud  *
     41   1.1   reinoud  * CPU specific symbols
     42   1.1   reinoud  *
     43   1.1   reinoud  * Created      : 18/09/94
     44   1.1   reinoud  *
     45   1.1   reinoud  * Based on kate/katelib/arm6.h
     46   1.1   reinoud  */
     47   1.1   reinoud 
     48  1.11     bjh21 #ifndef _ARM_CPU_H_
     49  1.11     bjh21 #define _ARM_CPU_H_
     50   1.1   reinoud 
     51   1.8     bjh21 /*
     52   1.8     bjh21  * User-visible definitions
     53   1.8     bjh21  */
     54   1.8     bjh21 
     55   1.8     bjh21 /*  CTL_MACHDEP definitions. */
     56   1.8     bjh21 #define	CPU_DEBUG		1	/* int: misc kernel debug control */
     57   1.8     bjh21 #define	CPU_BOOTED_DEVICE	2	/* string: device we booted from */
     58   1.8     bjh21 #define	CPU_BOOTED_KERNEL	3	/* string: kernel we booted */
     59   1.8     bjh21 #define	CPU_CONSDEV		4	/* struct: dev_t of our console */
     60  1.29   thorpej #define	CPU_POWERSAVE		5	/* int: use CPU powersave mode */
     61  1.29   thorpej #define	CPU_MAXID		6	/* number of valid machdep ids */
     62   1.8     bjh21 
     63  1.63  christos #if defined(_KERNEL) || defined(_KMEMUSER)
     64   1.8     bjh21 
     65   1.8     bjh21 /*
     66   1.8     bjh21  * Kernel-only definitions
     67   1.8     bjh21  */
     68   1.8     bjh21 
     69  1.76      matt #if !defined(_MODULE) && defined(_KERNEL_OPT)
     70  1.34    martin #include "opt_multiprocessor.h"
     71  1.54      matt #include "opt_cpuoptions.h"
     72   1.1   reinoud #include "opt_lockdebug.h"
     73  1.53  rearnsha #include "opt_cputypes.h"
     74  1.76      matt #endif /* !_MODULE && _KERNEL_OPT */
     75  1.53  rearnsha 
     76  1.29   thorpej #ifndef _LOCORE
     77  1.29   thorpej /* 1 == use cpu_sleep(), 0 == don't */
     78  1.29   thorpej extern int cpu_do_powersave;
     79  1.75      matt extern int cpu_fpu_present;
     80  1.11     bjh21 
     81   1.8     bjh21 /* All the CLKF_* macros take a struct clockframe * as an argument. */
     82   1.8     bjh21 
     83   1.1   reinoud /*
     84  1.11     bjh21  * CLKF_USERMODE: Return TRUE/FALSE (1/0) depending on whether the
     85  1.11     bjh21  * frame came from USR mode or not.
     86   1.1   reinoud  */
     87  1.17   thorpej #ifdef __PROG32
     88  1.76      matt #define CLKF_USERMODE(cf) (((cf)->cf_tf.tf_spsr & PSR_MODE) == PSR_USR32_MODE)
     89  1.11     bjh21 #else
     90  1.76      matt #define CLKF_USERMODE(cf) (((cf)->cf_if.if_r15 & R15_MODE) == R15_MODE_USR)
     91  1.11     bjh21 #endif
     92   1.1   reinoud 
     93   1.1   reinoud /*
     94  1.11     bjh21  * CLKF_INTR: True if we took the interrupt from inside another
     95  1.11     bjh21  * interrupt handler.
     96  1.11     bjh21  */
     97  1.76      matt #if defined(__PROG32) && !defined(__ARM_EABI__)
     98   1.1   reinoud /* Hack to treat FPE time as interrupt time so we can measure it */
     99  1.76      matt #define CLKF_INTR(cf)						\
    100  1.76      matt 	((curcpu()->ci_intr_depth > 1) ||			\
    101  1.76      matt 	    ((cf)->cf_tf.tf_spsr & PSR_MODE) == PSR_UND32_MODE)
    102  1.11     bjh21 #else
    103  1.54      matt #define CLKF_INTR(frame)	(curcpu()->ci_intr_depth > 1)
    104  1.11     bjh21 #endif
    105   1.1   reinoud 
    106  1.11     bjh21 /*
    107  1.11     bjh21  * CLKF_PC: Extract the program counter from a clockframe
    108  1.11     bjh21  */
    109  1.17   thorpej #ifdef __PROG32
    110  1.65     skrll #define CLKF_PC(frame)		(frame->cf_tf.tf_pc)
    111  1.11     bjh21 #else
    112  1.37      cube #define CLKF_PC(frame)		(frame->cf_if.if_r15 & R15_PC)
    113  1.11     bjh21 #endif
    114   1.8     bjh21 
    115  1.11     bjh21 /*
    116  1.33   thorpej  * LWP_PC: Find out the program counter for the given lwp.
    117  1.11     bjh21  */
    118  1.17   thorpej #ifdef __PROG32
    119  1.68      matt #define LWP_PC(l)		(lwp_trapframe(l)->tf_pc)
    120  1.11     bjh21 #else
    121  1.68      matt #define LWP_PC(l)		(lwp_trapframe(l)->tf_r15 & R15_PC)
    122  1.11     bjh21 #endif
    123   1.8     bjh21 
    124  1.40     bjh21 /*
    125  1.11     bjh21  * Per-CPU information.  For now we assume one CPU.
    126   1.1   reinoud  */
    127  1.54      matt static inline int curcpl(void);
    128  1.54      matt static inline void set_curcpl(int);
    129  1.54      matt static inline void cpu_dosoftints(void);
    130   1.1   reinoud 
    131  1.78      matt #ifdef _KMEMUSER
    132  1.78      matt #include <sys/intr.h>
    133  1.78      matt #endif
    134  1.76      matt #include <sys/cpu_data.h>
    135  1.62  uebayasi #include <sys/device_if.h>
    136  1.61  uebayasi #include <sys/evcnt.h>
    137  1.72      matt 
    138   1.1   reinoud struct cpu_info {
    139  1.36      yamt 	struct cpu_data ci_data;	/* MI per-cpu data */
    140  1.67      matt 	device_t ci_dev;		/* Device corresponding to this CPU */
    141  1.45        ad 	cpuid_t ci_cpuid;
    142  1.67      matt 	uint32_t ci_arm_cpuid;		/* aggregate CPU id */
    143  1.67      matt 	uint32_t ci_arm_cputype;	/* CPU type */
    144  1.67      matt 	uint32_t ci_arm_cpurev;		/* CPU revision */
    145  1.67      matt 	uint32_t ci_ctrl;		/* The CPU control register */
    146  1.54      matt 	int ci_cpl;			/* current processor level (spl) */
    147  1.54      matt 	int ci_astpending;		/* */
    148  1.54      matt 	int ci_want_resched;		/* resched() was called */
    149  1.54      matt 	int ci_intr_depth;		/* */
    150  1.67      matt 	struct cpu_softc *ci_softc;	/* platform softc */
    151  1.54      matt 	lwp_t *ci_softlwps[SOFTINT_COUNT];
    152  1.64     skrll 	volatile uint32_t ci_softints;
    153  1.54      matt 	lwp_t *ci_curlwp;		/* current lwp */
    154  1.20     bjh21 	struct evcnt ci_arm700bugcount;
    155  1.42      matt 	int32_t ci_mtx_count;
    156  1.42      matt 	int ci_mtx_oldspl;
    157  1.72      matt 	register_t ci_undefsave[3];
    158  1.66      matt 	uint32_t ci_vfp_id;
    159  1.72      matt 	uint64_t ci_lastintr;
    160  1.77      matt 	struct evcnt ci_abt_evs[16];
    161  1.72      matt #if defined(MP_CPU_INFO_MEMBERS)
    162  1.30     bjh21 	MP_CPU_INFO_MEMBERS
    163  1.30     bjh21 #endif
    164   1.1   reinoud };
    165  1.11     bjh21 
    166   1.1   reinoud extern struct cpu_info cpu_info_store;
    167  1.76      matt 
    168  1.69      matt #if defined(TPIDRPRW_IS_CURLWP)
    169  1.54      matt static inline struct lwp *
    170  1.54      matt _curlwp(void)
    171  1.54      matt {
    172  1.72      matt 	return (struct lwp *) armreg_tpidrprw_read();
    173  1.54      matt }
    174  1.54      matt 
    175  1.54      matt static inline void
    176  1.54      matt _curlwp_set(struct lwp *l)
    177  1.54      matt {
    178  1.72      matt 	armreg_tpidrprw_write((uintptr_t)l);
    179  1.54      matt }
    180  1.54      matt 
    181  1.54      matt #define	curlwp		(_curlwp())
    182  1.54      matt static inline struct cpu_info *
    183  1.54      matt curcpu(void)
    184  1.54      matt {
    185  1.54      matt 	return curlwp->l_cpu;
    186  1.54      matt }
    187  1.69      matt #elif defined(TPIDRPRW_IS_CURCPU)
    188  1.54      matt static inline struct cpu_info *
    189  1.54      matt curcpu(void)
    190  1.54      matt {
    191  1.72      matt 	return (struct cpu_info *) armreg_tpidrprw_read();
    192  1.54      matt }
    193  1.72      matt #elif !defined(MULTIPROCESSOR)
    194  1.72      matt #define	curcpu()	(&cpu_info_store)
    195  1.54      matt #else
    196  1.72      matt #error MULTIPROCESSOR requires TPIDRPRW_IS_CURLWP or TPIDRPRW_IS_CURCPU
    197  1.69      matt #endif /* !TPIDRPRW_IS_CURCPU && !TPIDRPRW_IS_CURLWP */
    198  1.72      matt 
    199  1.54      matt #ifndef curlwp
    200  1.54      matt #define	curlwp		(curcpu()->ci_curlwp)
    201  1.54      matt #endif
    202  1.72      matt 
    203  1.72      matt #define CPU_INFO_ITERATOR	int
    204  1.72      matt #if defined(MULTIPROCESSOR)
    205  1.72      matt extern struct cpu_info *cpu_info[];
    206  1.72      matt #define cpu_number()	(curcpu()->ci_cpuid)
    207  1.72      matt void cpu_boot_secondary_processors(void);
    208  1.72      matt #define CPU_IS_PRIMARY(ci)	((ci)->ci_cpuid == 0)
    209  1.72      matt #define CPU_INFO_FOREACH(cii, ci)			\
    210  1.72      matt 	cii = 0, ci = cpu_info[0]; cii < ncpu && (ci = cpu_info[cii]) != NULL; cii++
    211  1.72      matt #else
    212  1.72      matt #define cpu_number()            0
    213  1.72      matt 
    214  1.72      matt #define CPU_IS_PRIMARY(ci)	true
    215  1.72      matt #define CPU_INFO_FOREACH(cii, ci)			\
    216  1.72      matt 	cii = 0, ci = curcpu(); ci != NULL; ci = NULL
    217  1.72      matt #endif
    218  1.72      matt 
    219  1.54      matt #define	LWP0_CPU_INFO	(&cpu_info_store)
    220  1.54      matt 
    221  1.54      matt static inline int
    222  1.54      matt curcpl(void)
    223  1.54      matt {
    224  1.54      matt 	return curcpu()->ci_cpl;
    225  1.54      matt }
    226  1.54      matt 
    227  1.54      matt static inline void
    228  1.54      matt set_curcpl(int pri)
    229  1.54      matt {
    230  1.54      matt 	curcpu()->ci_cpl = pri;
    231  1.54      matt }
    232  1.54      matt 
    233  1.54      matt static inline void
    234  1.54      matt cpu_dosoftints(void)
    235  1.54      matt {
    236  1.72      matt #ifdef __HAVE_FAST_SOFTINTS
    237  1.72      matt 	void	dosoftints(void);
    238  1.72      matt #ifndef __HAVE_PIC_FAST_SOFTINTS
    239  1.56      matt 	struct cpu_info * const ci = curcpu();
    240  1.56      matt 	if (ci->ci_intr_depth == 0 && (ci->ci_softints >> ci->ci_cpl) > 0)
    241  1.54      matt 		dosoftints();
    242  1.72      matt #endif
    243  1.72      matt #endif
    244  1.54      matt }
    245  1.11     bjh21 
    246  1.33   thorpej #ifdef __PROG32
    247  1.33   thorpej void	cpu_proc_fork(struct proc *, struct proc *);
    248  1.33   thorpej #else
    249  1.33   thorpej #define	cpu_proc_fork(p1, p2)
    250  1.33   thorpej #endif
    251  1.11     bjh21 
    252  1.11     bjh21 /*
    253  1.11     bjh21  * Scheduling glue
    254  1.11     bjh21  */
    255  1.11     bjh21 
    256  1.72      matt #define setsoftast()			(curcpu()->ci_astpending = 1)
    257   1.1   reinoud 
    258   1.1   reinoud /*
    259   1.1   reinoud  * Notify the current process (p) that it has a signal pending,
    260   1.1   reinoud  * process as soon as possible.
    261   1.1   reinoud  */
    262   1.1   reinoud 
    263  1.72      matt #define cpu_signotify(l)		setsoftast()
    264   1.1   reinoud 
    265   1.1   reinoud /*
    266   1.1   reinoud  * Give a profiling tick to the current process when the user profiling
    267   1.1   reinoud  * buffer pages are invalid.  On the i386, request an ast to send us
    268   1.1   reinoud  * through trap(), marking the proc as needing a profiling tick.
    269   1.1   reinoud  */
    270  1.42      matt #define	cpu_need_proftick(l)	((l)->l_pflag |= LP_OWEUPC, setsoftast())
    271   1.1   reinoud 
    272  1.72      matt /*
    273  1.72      matt  * We've already preallocated the stack for the idlelwps for additional CPUs.
    274  1.72      matt  * This hook allows to return them.
    275  1.72      matt  */
    276  1.72      matt vaddr_t cpu_uarea_alloc_idlelwp(struct cpu_info *);
    277  1.72      matt 
    278  1.23     bjh21 #ifndef acorn26
    279  1.11     bjh21 /*
    280  1.11     bjh21  * cpu device glue (belongs in cpuvar.h)
    281  1.11     bjh21  */
    282  1.70      matt void	cpu_attach(device_t, cpuid_t);
    283  1.11     bjh21 #endif
    284  1.11     bjh21 
    285  1.76      matt #endif /* !_LOCORE */
    286   1.1   reinoud 
    287   1.8     bjh21 #endif /* _KERNEL */
    288   1.1   reinoud 
    289  1.11     bjh21 #endif /* !_ARM_CPU_H_ */
    290