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