Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.8.2.6
      1  1.8.2.6  jdolecek /*	$NetBSD: cpu.h,v 1.8.2.6 2002/10/10 18:35:19 jdolecek Exp $	*/
      2      1.1        ws 
      3      1.1        ws /*
      4      1.5        ws  * Copyright (C) 1999 Wolfgang Solfrank.
      5      1.5        ws  * Copyright (C) 1999 TooLs GmbH.
      6  1.8.2.1   thorpej  * Copyright (C) 1995-1997 Wolfgang Solfrank.
      7  1.8.2.1   thorpej  * Copyright (C) 1995-1997 TooLs GmbH.
      8      1.1        ws  * All rights reserved.
      9      1.1        ws  *
     10      1.1        ws  * Redistribution and use in source and binary forms, with or without
     11      1.1        ws  * modification, are permitted provided that the following conditions
     12      1.1        ws  * are met:
     13      1.1        ws  * 1. Redistributions of source code must retain the above copyright
     14      1.1        ws  *    notice, this list of conditions and the following disclaimer.
     15      1.1        ws  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1        ws  *    notice, this list of conditions and the following disclaimer in the
     17      1.1        ws  *    documentation and/or other materials provided with the distribution.
     18      1.1        ws  * 3. All advertising materials mentioning features or use of this software
     19      1.1        ws  *    must display the following acknowledgement:
     20      1.1        ws  *	This product includes software developed by TooLs GmbH.
     21      1.1        ws  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     22      1.1        ws  *    derived from this software without specific prior written permission.
     23      1.1        ws  *
     24      1.1        ws  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     25      1.1        ws  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     26      1.1        ws  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     27      1.1        ws  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     28      1.1        ws  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     29      1.1        ws  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     30      1.1        ws  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     31      1.1        ws  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     32      1.1        ws  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     33      1.1        ws  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     34      1.1        ws  */
     35      1.5        ws #ifndef	_POWERPC_CPU_H_
     36      1.5        ws #define	_POWERPC_CPU_H_
     37      1.1        ws 
     38  1.8.2.1   thorpej #if defined(_KERNEL_OPT)
     39  1.8.2.1   thorpej #include "opt_lockdebug.h"
     40  1.8.2.1   thorpej #include "opt_multiprocessor.h"
     41  1.8.2.5  jdolecek #include "opt_ppcarch.h"
     42  1.8.2.1   thorpej #endif
     43  1.8.2.1   thorpej 
     44  1.8.2.1   thorpej #include <machine/frame.h>
     45  1.8.2.1   thorpej #include <machine/psl.h>
     46  1.8.2.1   thorpej #include <machine/intr.h>
     47  1.8.2.5  jdolecek #include <sys/device.h>
     48  1.8.2.1   thorpej 
     49  1.8.2.3  jdolecek 
     50  1.8.2.3  jdolecek struct cache_info {
     51  1.8.2.3  jdolecek 	int dcache_size;
     52  1.8.2.3  jdolecek 	int dcache_line_size;
     53  1.8.2.3  jdolecek 	int icache_size;
     54  1.8.2.3  jdolecek 	int icache_line_size;
     55  1.8.2.3  jdolecek };
     56  1.8.2.3  jdolecek 
     57  1.8.2.3  jdolecek 
     58  1.8.2.1   thorpej #ifdef _KERNEL
     59  1.8.2.1   thorpej #include <sys/sched.h>
     60  1.8.2.3  jdolecek #include <dev/sysmon/sysmonvar.h>
     61  1.8.2.3  jdolecek 
     62  1.8.2.1   thorpej struct cpu_info {
     63  1.8.2.1   thorpej 	struct schedstate_percpu ci_schedstate; /* scheduler state */
     64  1.8.2.1   thorpej #if defined(DIAGNOSTIC) || defined(LOCKDEBUG)
     65  1.8.2.1   thorpej 	u_long ci_spin_locks;		/* # of spin locks held */
     66  1.8.2.1   thorpej 	u_long ci_simple_locks;		/* # of simple locks held */
     67  1.8.2.1   thorpej #endif
     68  1.8.2.1   thorpej 	struct device *ci_dev;		/* device of corresponding cpu */
     69  1.8.2.1   thorpej 	struct proc *ci_curproc;	/* current owner of the processor */
     70  1.8.2.1   thorpej 
     71  1.8.2.1   thorpej 	struct pcb *ci_curpcb;
     72  1.8.2.1   thorpej 	struct pmap *ci_curpm;
     73  1.8.2.1   thorpej 	struct proc *ci_fpuproc;
     74  1.8.2.5  jdolecek 	struct proc *ci_vecproc;
     75  1.8.2.1   thorpej 	struct pcb *ci_idle_pcb;	/* PA of our idle pcb */
     76  1.8.2.1   thorpej 	int ci_cpuid;
     77  1.8.2.1   thorpej 
     78  1.8.2.1   thorpej 	int ci_astpending;
     79  1.8.2.1   thorpej 	int ci_want_resched;
     80  1.8.2.1   thorpej 	u_long ci_lasttb;
     81  1.8.2.1   thorpej 	int ci_tickspending;
     82  1.8.2.1   thorpej 	int ci_cpl;
     83  1.8.2.1   thorpej 	int ci_ipending;
     84  1.8.2.1   thorpej 	int ci_intrdepth;
     85  1.8.2.1   thorpej 	char *ci_intstk;
     86  1.8.2.1   thorpej 	char *ci_spillstk;
     87  1.8.2.1   thorpej 	int ci_tempsave[8];
     88  1.8.2.1   thorpej 	int ci_ddbsave[8];
     89  1.8.2.1   thorpej 	int ci_ipkdbsave[8];
     90  1.8.2.1   thorpej 	int ci_disisave[4];
     91  1.8.2.3  jdolecek 	struct cache_info ci_ci;
     92  1.8.2.3  jdolecek 	struct sysmon_envsys ci_sysmon;
     93  1.8.2.3  jdolecek 	struct envsys_tre_data ci_tau_info;
     94  1.8.2.1   thorpej 	struct evcnt ci_ev_traps;	/* calls to trap() */
     95  1.8.2.1   thorpej 	struct evcnt ci_ev_kdsi;	/* kernel DSI traps */
     96  1.8.2.1   thorpej 	struct evcnt ci_ev_udsi;	/* user DSI traps */
     97  1.8.2.1   thorpej 	struct evcnt ci_ev_udsi_fatal;	/* user DSI trap failures */
     98  1.8.2.1   thorpej 	struct evcnt ci_ev_isi;		/* user ISI traps */
     99  1.8.2.1   thorpej 	struct evcnt ci_ev_isi_fatal;	/* user ISI trap failures */
    100  1.8.2.1   thorpej 	struct evcnt ci_ev_pgm;		/* user PGM traps */
    101  1.8.2.1   thorpej 	struct evcnt ci_ev_fpu;		/* FPU traps */
    102  1.8.2.1   thorpej 	struct evcnt ci_ev_fpusw;	/* FPU context switch */
    103  1.8.2.1   thorpej 	struct evcnt ci_ev_ali;		/* Alignment traps */
    104  1.8.2.1   thorpej 	struct evcnt ci_ev_ali_fatal;	/* Alignment fatal trap */
    105  1.8.2.1   thorpej 	struct evcnt ci_ev_scalls;	/* system call traps */
    106  1.8.2.1   thorpej 	struct evcnt ci_ev_vec;		/* Altivec traps */
    107  1.8.2.1   thorpej 	struct evcnt ci_ev_vecsw;	/* Altivec context switches */
    108  1.8.2.5  jdolecek 	struct evcnt ci_ev_umchk;	/* user MCHK events */
    109  1.8.2.1   thorpej };
    110  1.8.2.1   thorpej 
    111  1.8.2.1   thorpej #ifdef MULTIPROCESSOR
    112  1.8.2.1   thorpej static __inline int
    113  1.8.2.2   thorpej cpu_number(void)
    114  1.8.2.1   thorpej {
    115  1.8.2.1   thorpej 	int pir;
    116  1.8.2.1   thorpej 
    117  1.8.2.1   thorpej 	asm ("mfspr %0,1023" : "=r"(pir));
    118  1.8.2.1   thorpej 	return pir;
    119  1.8.2.1   thorpej }
    120  1.8.2.1   thorpej 
    121  1.8.2.1   thorpej static __inline struct cpu_info *
    122  1.8.2.2   thorpej curcpu(void)
    123  1.8.2.1   thorpej {
    124  1.8.2.1   thorpej 	struct cpu_info *ci;
    125  1.8.2.1   thorpej 
    126  1.8.2.1   thorpej 	asm volatile ("mfsprg %0,0" : "=r"(ci));
    127  1.8.2.1   thorpej 	return ci;
    128  1.8.2.1   thorpej }
    129  1.8.2.2   thorpej 
    130  1.8.2.2   thorpej void	cpu_boot_secondary_processors(void);
    131  1.8.2.1   thorpej 
    132  1.8.2.1   thorpej extern struct cpu_info cpu_info[];
    133  1.8.2.1   thorpej 
    134  1.8.2.1   thorpej #define CPU_IS_PRIMARY(ci)	((ci)->ci_cpuid == 0)
    135  1.8.2.1   thorpej #define curproc			curcpu()->ci_curproc
    136  1.8.2.1   thorpej #define curpcb			curcpu()->ci_curpcb
    137  1.8.2.1   thorpej #define curpm			curcpu()->ci_curpm
    138  1.8.2.1   thorpej #define want_resched		curcpu()->ci_want_resched
    139  1.8.2.1   thorpej #define astpending		curcpu()->ci_astpending
    140  1.8.2.1   thorpej #define	intr_depth		curcpu()->ci_intrdepth
    141  1.8.2.1   thorpej 
    142  1.8.2.5  jdolecek #define CPU_INFO_ITERATOR		int
    143  1.8.2.5  jdolecek #define CPU_INFO_FOREACH(cii, ci)					\
    144  1.8.2.5  jdolecek 	cii = 0, ci = &cpu_info[0]; cii < CPU_MAXNUM; cii++, ci++
    145  1.8.2.5  jdolecek 
    146  1.8.2.1   thorpej #else
    147  1.8.2.1   thorpej extern struct cpu_info cpu_info_store;
    148  1.8.2.1   thorpej extern volatile int want_resched;
    149  1.8.2.1   thorpej extern volatile int astpending;
    150  1.8.2.1   thorpej extern volatile int intr_depth;
    151  1.8.2.1   thorpej 
    152  1.8.2.1   thorpej #define curcpu()		(&cpu_info_store)
    153  1.8.2.1   thorpej #define cpu_number()		0
    154  1.8.2.1   thorpej 
    155  1.8.2.5  jdolecek #define CPU_INFO_ITERATOR		int
    156  1.8.2.5  jdolecek #define CPU_INFO_FOREACH(cii, ci)					\
    157  1.8.2.5  jdolecek 	cii = 0, ci = curcpu(); ci != NULL; ci = NULL
    158  1.8.2.5  jdolecek 
    159  1.8.2.1   thorpej #endif /* MULTIPROCESSOR */
    160  1.8.2.1   thorpej 
    161  1.8.2.5  jdolecek static __inline register_t
    162  1.8.2.5  jdolecek mfmsr(void)
    163  1.8.2.5  jdolecek {
    164  1.8.2.5  jdolecek 	register_t msr;
    165  1.8.2.5  jdolecek 
    166  1.8.2.5  jdolecek 	asm volatile ("mfmsr %0" : "=r"(msr));
    167  1.8.2.5  jdolecek 	return msr;
    168  1.8.2.5  jdolecek }
    169  1.8.2.5  jdolecek 
    170  1.8.2.5  jdolecek static __inline void
    171  1.8.2.5  jdolecek mtmsr(register_t msr)
    172  1.8.2.5  jdolecek {
    173  1.8.2.5  jdolecek 
    174  1.8.2.5  jdolecek 	asm volatile ("mtmsr %0" : : "r"(msr));
    175  1.8.2.5  jdolecek }
    176  1.8.2.5  jdolecek 
    177  1.8.2.5  jdolecek static __inline uint32_t
    178  1.8.2.5  jdolecek mftbl(void)
    179  1.8.2.5  jdolecek {
    180  1.8.2.5  jdolecek 	uint32_t tbl;
    181  1.8.2.5  jdolecek 
    182  1.8.2.5  jdolecek 	asm volatile ("mftbl %0" : "=r"(tbl));
    183  1.8.2.5  jdolecek 	return tbl;
    184  1.8.2.5  jdolecek }
    185  1.8.2.5  jdolecek 
    186  1.8.2.5  jdolecek static __inline uint64_t
    187  1.8.2.5  jdolecek mftb(void)
    188  1.8.2.5  jdolecek {
    189  1.8.2.5  jdolecek 	uint64_t tb;
    190  1.8.2.5  jdolecek 	int tmp;
    191  1.8.2.5  jdolecek 
    192  1.8.2.5  jdolecek 	asm volatile ("
    193  1.8.2.5  jdolecek 1:	mftbu %0	\n\
    194  1.8.2.5  jdolecek 	mftb %0+1	\n\
    195  1.8.2.5  jdolecek 	mftbu %1	\n\
    196  1.8.2.5  jdolecek 	cmplw %0,%1	\n\
    197  1.8.2.5  jdolecek 	bne- 1b"
    198  1.8.2.6  jdolecek 	    : "=r"(tb), "=r"(tmp) :: "cr0");
    199  1.8.2.5  jdolecek 	return tb;
    200  1.8.2.5  jdolecek }
    201  1.8.2.5  jdolecek 
    202  1.8.2.5  jdolecek static __inline uint32_t
    203  1.8.2.5  jdolecek mfpvr(void)
    204  1.8.2.5  jdolecek {
    205  1.8.2.5  jdolecek 	uint32_t pvr;
    206  1.8.2.5  jdolecek 
    207  1.8.2.5  jdolecek 	asm volatile ("mfpvr %0" : "=r"(pvr));
    208  1.8.2.5  jdolecek 	return (pvr);
    209  1.8.2.5  jdolecek }
    210  1.8.2.5  jdolecek 
    211  1.8.2.1   thorpej #define	CLKF_USERMODE(frame)	(((frame)->srr1 & PSL_PR) != 0)
    212  1.8.2.1   thorpej #define	CLKF_BASEPRI(frame)	((frame)->pri == 0)
    213  1.8.2.1   thorpej #define	CLKF_PC(frame)		((frame)->srr0)
    214  1.8.2.1   thorpej #define	CLKF_INTR(frame)	((frame)->depth > 0)
    215  1.8.2.1   thorpej 
    216  1.8.2.1   thorpej #define	PROC_PC(p)		(trapframe(p)->srr0)
    217  1.8.2.1   thorpej 
    218  1.8.2.1   thorpej #define	cpu_swapout(p)
    219  1.8.2.1   thorpej #define cpu_wait(p)
    220  1.8.2.1   thorpej 
    221  1.8.2.1   thorpej extern int powersave;
    222  1.8.2.1   thorpej extern int cpu_timebase;
    223  1.8.2.1   thorpej extern int cpu_printfataltraps;
    224  1.8.2.5  jdolecek extern char cpu_model[];
    225  1.8.2.5  jdolecek 
    226  1.8.2.5  jdolecek struct cpu_info *cpu_attach_common(struct device *, int);
    227  1.8.2.5  jdolecek void cpu_setup(struct device *, struct cpu_info *);
    228  1.8.2.5  jdolecek void cpu_identify(char *, size_t);
    229  1.8.2.5  jdolecek void delay (unsigned int);
    230  1.8.2.5  jdolecek void cpu_probe_cache(void);
    231  1.8.2.5  jdolecek void dcache_flush_page(vaddr_t);
    232  1.8.2.5  jdolecek void icache_flush_page(vaddr_t);
    233  1.8.2.5  jdolecek void dcache_flush(vaddr_t, vsize_t);
    234  1.8.2.5  jdolecek void icache_flush(vaddr_t, vsize_t);
    235  1.8.2.1   thorpej 
    236  1.8.2.1   thorpej #define	DELAY(n)		delay(n)
    237  1.8.2.1   thorpej 
    238  1.8.2.1   thorpej #define	need_resched(ci)	(want_resched = 1, astpending = 1)
    239  1.8.2.1   thorpej #define	need_proftick(p)	((p)->p_flag |= P_OWEUPC, astpending = 1)
    240  1.8.2.1   thorpej #define	signotify(p)		(astpending = 1)
    241  1.8.2.1   thorpej 
    242  1.8.2.5  jdolecek #ifdef PPC_MPC6XX
    243  1.8.2.5  jdolecek void mpc6xx_init(void (*)(void));
    244  1.8.2.5  jdolecek void mpc6xx_startup(const char *);
    245  1.8.2.5  jdolecek void mpc6xx_dumpsys(void);
    246  1.8.2.5  jdolecek void mpc6xx_install_extint(void (*)(void));
    247  1.8.2.5  jdolecek void *mapiodev(paddr_t, psize_t);
    248  1.8.2.5  jdolecek paddr_t kvtop(caddr_t);
    249  1.8.2.5  jdolecek void softnet(int);
    250  1.8.2.5  jdolecek 
    251  1.8.2.5  jdolecek extern paddr_t msgbuf_paddr;
    252  1.8.2.5  jdolecek extern int cpu_altivec;
    253  1.8.2.5  jdolecek #endif
    254  1.8.2.5  jdolecek 
    255  1.8.2.1   thorpej #endif /* _KERNEL */
    256  1.8.2.1   thorpej 
    257  1.8.2.1   thorpej #if defined(_KERNEL) || defined(_STANDALONE)
    258  1.8.2.1   thorpej #if !defined(CACHELINESIZE)
    259  1.8.2.1   thorpej #define	CACHELINESIZE	32
    260  1.8.2.1   thorpej #endif
    261  1.8.2.1   thorpej #endif
    262  1.8.2.1   thorpej 
    263  1.8.2.4  jdolecek void __syncicache(void *, size_t);
    264      1.1        ws 
    265      1.5        ws /*
    266      1.5        ws  * CTL_MACHDEP definitions.
    267      1.5        ws  */
    268  1.8.2.1   thorpej #define	CPU_CACHELINE		1
    269  1.8.2.1   thorpej #define	CPU_TIMEBASE		2
    270  1.8.2.1   thorpej #define	CPU_CPUTEMP		3
    271  1.8.2.1   thorpej #define	CPU_PRINTFATALTRAPS	4
    272  1.8.2.3  jdolecek #define	CPU_CACHEINFO		5
    273  1.8.2.5  jdolecek #define	CPU_ALTIVEC		6
    274  1.8.2.5  jdolecek #define	CPU_MODEL		7
    275  1.8.2.5  jdolecek #define	CPU_POWERSAVE		8
    276  1.8.2.5  jdolecek #define	CPU_MAXID		9
    277      1.1        ws 
    278      1.5        ws #define	CTL_MACHDEP_NAMES { \
    279      1.5        ws 	{ 0, 0 }, \
    280      1.5        ws 	{ "cachelinesize", CTLTYPE_INT }, \
    281      1.7      matt 	{ "timebase", CTLTYPE_INT }, \
    282      1.7      matt 	{ "cputempature", CTLTYPE_INT }, \
    283  1.8.2.1   thorpej 	{ "printfataltraps", CTLTYPE_INT }, \
    284  1.8.2.3  jdolecek 	{ "cacheinfo", CTLTYPE_STRUCT }, \
    285  1.8.2.5  jdolecek 	{ "altivec", CTLTYPE_INT }, \
    286  1.8.2.5  jdolecek 	{ "model", CTLTYPE_STRING }, \
    287  1.8.2.5  jdolecek 	{ "powersave", CTLTYPE_INT }, \
    288      1.1        ws }
    289      1.1        ws 
    290      1.5        ws #endif	/* _POWERPC_CPU_H_ */
    291