Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.65.22.3
      1 /*	$NetBSD: cpu.h,v 1.65.22.3 2011/10/14 17:21:26 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 #if defined(_KERNEL) || defined(_KMEMUSER)
     46 #if defined(_KERNEL_OPT)
     47 #include "opt_lockdebug.h"
     48 #include "opt_multiprocessor.h"
     49 #include "opt_ppcarch.h"
     50 #endif
     51 
     52 #ifdef _KERNEL
     53 #include <machine/frame.h>
     54 #include <machine/psl.h>
     55 #include <machine/intr.h>
     56 #include <sys/device.h>
     57 #include <sys/evcnt.h>
     58 #endif
     59 
     60 #include <sys/cpu_data.h>
     61 
     62 struct cpu_info {
     63 	struct cpu_data ci_data;	/* MI per-cpu data */
     64 #ifdef _KERNEL
     65 	device_t ci_dev;		/* device of corresponding cpu */
     66 	struct cpu_softc *ci_softc;	/* private cpu info */
     67 	struct lwp *ci_curlwp;		/* current owner of the processor */
     68 
     69 	struct pcb *ci_curpcb;
     70 	struct pmap *ci_curpm;
     71 	struct lwp * volatile ci_fpulwp;
     72 	struct lwp * volatile ci_veclwp;
     73 	int ci_cpuid;
     74 
     75 	volatile int ci_astpending;
     76 	int ci_want_resched;
     77 	volatile uint64_t ci_lastintr;
     78 	volatile u_long ci_lasttb;
     79 	volatile int ci_tickspending;
     80 	volatile int ci_cpl;
     81 	volatile int ci_iactive;
     82 	volatile int ci_idepth;
     83 #ifndef PPC_BOOKE
     84 	volatile int ci_ipending;
     85 #endif
     86 	int ci_mtx_oldspl;
     87 	int ci_mtx_count;
     88 #ifdef PPC_IBM4XX
     89 	char *ci_intstk;
     90 #endif
     91 #ifndef PPC_BOOKE
     92 #define	CPUSAVE_LEN	8
     93 	register_t ci_tempsave[CPUSAVE_LEN];
     94 	register_t ci_ddbsave[CPUSAVE_LEN];
     95 	register_t ci_ipkdbsave[CPUSAVE_LEN];
     96 #define	CPUSAVE_R28	0		/* where r28 gets saved */
     97 #define	CPUSAVE_R29	1		/* where r29 gets saved */
     98 #define	CPUSAVE_R30	2		/* where r30 gets saved */
     99 #define	CPUSAVE_R31	3		/* where r31 gets saved */
    100 #if defined(PPC_IBM4XX)
    101 #define	CPUSAVE_DEAR	4		/* where SPR_DEAR gets saved */
    102 #define	CPUSAVE_ESR	5		/* where SPR_ESR gets saved */
    103 	register_t ci_tlbmisssave[CPUSAVE_LEN];
    104 #else
    105 #define	CPUSAVE_DAR	4		/* where SPR_DAR gets saved */
    106 #define	CPUSAVE_DSISR	5		/* where SPR_DSISR gets saved */
    107 #define	DISISAVE_LEN	4
    108 	register_t ci_disisave[DISISAVE_LEN];
    109 #endif
    110 #define	CPUSAVE_SRR0	6		/* where SRR0 gets saved */
    111 #define	CPUSAVE_SRR1	7		/* where SRR1 gets saved */
    112 #else /* PPC_BOOKE */
    113 #define	CPUSAVE_LEN	128
    114 	register_t ci_savelifo[CPUSAVE_LEN];
    115 	struct pmap_segtab *ci_pmap_segtabs[2];
    116 #define	ci_pmap_kern_segtab	ci_pmap_segtabs[0]
    117 #define	ci_pmap_user_segtab	ci_pmap_segtabs[1]
    118 	struct pmap_tlb_info *ci_tlb_info;
    119 	tlb_asid_t ci_pmap_asid_cur;
    120 	volatile uint32_t ci_pending_ipis;
    121 	struct lwp *ci_softlwps[SOFTINT_COUNT];
    122 #endif /* PPC_BOOKE */
    123 	struct cache_info ci_ci;
    124 	void *ci_sysmon_cookie;
    125 	void (*ci_idlespin)(void);
    126 	uint32_t ci_khz;
    127 	struct evcnt ci_ev_clock;	/* clock intrs */
    128 	struct evcnt ci_ev_statclock; 	/* stat clock */
    129 #ifndef PPC_BOOKE
    130 	struct evcnt ci_ev_softclock;	/* softclock intrs */
    131 	struct evcnt ci_ev_softnet;	/* softnet intrs */
    132 	struct evcnt ci_ev_softserial;	/* softserial intrs */
    133 #endif
    134 	struct evcnt ci_ev_traps;	/* calls to trap() */
    135 	struct evcnt ci_ev_kdsi;	/* kernel DSI traps */
    136 	struct evcnt ci_ev_udsi;	/* user DSI traps */
    137 	struct evcnt ci_ev_udsi_fatal;	/* user DSI trap failures */
    138 	struct evcnt ci_ev_kisi;	/* kernel ISI traps */
    139 	struct evcnt ci_ev_isi;		/* user ISI traps */
    140 	struct evcnt ci_ev_isi_fatal;	/* user ISI trap failures */
    141 	struct evcnt ci_ev_pgm;		/* user PGM traps */
    142 	struct evcnt ci_ev_debug;	/* user debug traps */
    143 	struct evcnt ci_ev_fpu;		/* FPU traps */
    144 	struct evcnt ci_ev_fpusw;	/* FPU context switch */
    145 	struct evcnt ci_ev_ali;		/* Alignment traps */
    146 	struct evcnt ci_ev_ali_fatal;	/* Alignment fatal trap */
    147 	struct evcnt ci_ev_scalls;	/* system call traps */
    148 	struct evcnt ci_ev_vec;		/* Altivec traps */
    149 	struct evcnt ci_ev_vecsw;	/* Altivec context switches */
    150 	struct evcnt ci_ev_umchk;	/* user MCHK events */
    151 	struct evcnt ci_ev_ipi;		/* IPIs received */
    152 	struct evcnt ci_ev_tlbmiss_soft; /* tlb miss (no trap) */
    153 	struct evcnt ci_ev_dtlbmiss_hard; /* data tlb miss (trap) */
    154 	struct evcnt ci_ev_itlbmiss_hard; /* instruction tlb miss (trap) */
    155 #endif /* _KERNEL */
    156 };
    157 #endif /* _KERNEL || _KMEMUSER */
    158 
    159 #ifdef _KERNEL
    160 
    161 #ifdef MULTIPROCESSOR
    162 
    163 struct cpu_hatch_data {
    164 	struct device *self;
    165 	struct cpu_info *ci;
    166 	int running;
    167 	int pir;
    168 	int asr;
    169 	int hid0;
    170 	int sdr1;
    171 	int sr[16];
    172 	int batu[4], batl[4];
    173 	int tbu, tbl;
    174 };
    175 
    176 static __inline int
    177 cpu_number(void)
    178 {
    179 	int pir;
    180 
    181 	__asm ("mfspr %0,1023" : "=r"(pir));
    182 	return pir;
    183 }
    184 
    185 void	cpu_boot_secondary_processors(void);
    186 
    187 
    188 #define CPU_IS_PRIMARY(ci)	((ci)->ci_cpuid == 0)
    189 #define CPU_INFO_ITERATOR		int
    190 #define CPU_INFO_FOREACH(cii, ci)					\
    191 	cii = 0, ci = &cpu_info[0]; cii < ncpu; cii++, ci++
    192 
    193 #else
    194 
    195 #define cpu_number()		0
    196 
    197 #define CPU_INFO_ITERATOR		int
    198 #define CPU_INFO_FOREACH(cii, ci)					\
    199 	cii = 0, ci = curcpu(); ci != NULL; ci = NULL
    200 
    201 #endif /* MULTIPROCESSOR */
    202 
    203 extern struct cpu_info cpu_info[];
    204 
    205 static __inline struct cpu_info *
    206 curcpu(void)
    207 {
    208 	struct cpu_info *ci;
    209 
    210 	__asm volatile ("mfsprg %0,0" : "=r"(ci));
    211 	return ci;
    212 }
    213 
    214 #define curlwp			(curcpu()->ci_curlwp)
    215 #define curpcb			(curcpu()->ci_curpcb)
    216 #define curpm			(curcpu()->ci_curpm)
    217 
    218 static __inline register_t
    219 mfmsr(void)
    220 {
    221 	register_t msr;
    222 
    223 	__asm volatile ("mfmsr %0" : "=r"(msr));
    224 	return msr;
    225 }
    226 
    227 static __inline void
    228 mtmsr(register_t msr)
    229 {
    230 	//KASSERT(msr & PSL_CE);
    231 	//KASSERT(msr & PSL_DE);
    232 	__asm volatile ("mtmsr %0" : : "r"(msr));
    233 }
    234 
    235 static __inline uint32_t
    236 mftbl(void)
    237 {
    238 	uint32_t tbl;
    239 
    240 	__asm volatile (
    241 #ifdef PPC_IBM403
    242 	"	mftblo %[tbl]"		"\n"
    243 #elif defined(PPC_BOOKE)
    244 	"	mfspr %[tbl],268"	"\n"
    245 #else
    246 	"	mftbl %[tbl]"		"\n"
    247 #endif
    248 	: [tbl] "=r" (tbl));
    249 
    250 	return tbl;
    251 }
    252 
    253 static __inline uint64_t
    254 mftb(void)
    255 {
    256 	uint64_t tb;
    257 
    258 #ifdef _LP64
    259 	__asm volatile ("mftb %0" : "=r"(tb));
    260 #else
    261 	int tmp;
    262 
    263 	__asm volatile (
    264 #ifdef PPC_IBM403
    265 	"1:	mftbhi %[tb]"		"\n"
    266 	"	mftblo %L[tb]"		"\n"
    267 	"	mftbhi %[tmp]"		"\n"
    268 #elif defined(PPC_BOOKE)
    269 	"1:	mfspr %[tb],269"	"\n"
    270 	"	mfspr %L[tb],268"	"\n"
    271 	"	mfspr %[tmp],269"	"\n"
    272 #else
    273 	"1:	mftbu %[tb]"		"\n"
    274 	"	mftb %L[tb]"		"\n"
    275 	"	mftbu %[tmp]"		"\n"
    276 #endif
    277 	"	cmplw %[tb],%[tmp]"	"\n"
    278 	"	bne- 1b"		"\n"
    279 	    : [tb] "=r" (tb), [tmp] "=r"(tmp)
    280 	    :: "cr0");
    281 #endif
    282 
    283 	return tb;
    284 }
    285 
    286 static __inline uint32_t
    287 mfrtcl(void)
    288 {
    289 	uint32_t rtcl;
    290 
    291 	__asm volatile ("mfrtcl %0" : "=r"(rtcl));
    292 	return rtcl;
    293 }
    294 
    295 static __inline void
    296 mfrtc(uint32_t *rtcp)
    297 {
    298 	uint32_t tmp;
    299 
    300 	__asm volatile (
    301 	"1:	mfrtcu	%[rtcu]"	"\n"
    302 	"	mfrtcl	%[rtcl]"	"\n"
    303 	"	mfrtcu	%[tmp]"		"\n"
    304 	"	cmplw	%[rtcu],%[tmp]"	"\n"
    305 	"	bne-	1b"
    306 	    : [rtcu] "=r"(rtcp[0]), [rtcl] "=r"(rtcp[1]), [tmp] "=r"(tmp)
    307 	    :: "cr0");
    308 }
    309 
    310 static __inline uint32_t
    311 mfpvr(void)
    312 {
    313 	uint32_t pvr;
    314 
    315 	__asm volatile ("mfpvr %0" : "=r"(pvr));
    316 	return (pvr);
    317 }
    318 
    319 static __inline int
    320 cntlzw(uint32_t val)
    321 {
    322 	int 			cnt;
    323 
    324 	__asm volatile ("cntlzw %0,%1" : "=r"(cnt) : "r"(val));
    325 	return (cnt);
    326 }
    327 
    328 #define	CLKF_USERMODE(frame)	(((frame)->cf_srr1 & PSL_PR) != 0)
    329 #define	CLKF_PC(frame)		((frame)->cf_srr0)
    330 #define	CLKF_INTR(frame)	((frame)->cf_idepth >= 0)
    331 
    332 #define	LWP_PC(l)		(trapframe(l)->tf_srr0)
    333 
    334 #define	cpu_swapin(p)
    335 #define	cpu_swapout(p)
    336 #define	cpu_proc_fork(p1, p2)
    337 #define cpu_lwp_free2(l)
    338 
    339 extern int powersave;
    340 extern int cpu_timebase;
    341 extern int cpu_printfataltraps;
    342 extern char cpu_model[];
    343 
    344 void cpu_uarea_remap(struct lwp *);
    345 struct cpu_info *cpu_attach_common(struct device *, int);
    346 void cpu_setup(struct device *, struct cpu_info *);
    347 void cpu_identify(char *, size_t);
    348 void delay (unsigned int);
    349 void cpu_probe_cache(void);
    350 #ifndef PPC_BOOKE
    351 void dcache_flush_page(vaddr_t);
    352 void icache_flush_page(vaddr_t);
    353 void dcache_flush(vaddr_t, vsize_t);
    354 void icache_flush(vaddr_t, vsize_t);
    355 #else
    356 void dcache_wb_page(vaddr_t);
    357 void dcache_wbinv_page(vaddr_t);
    358 void dcache_inv_page(vaddr_t);
    359 void dcache_zero_page(vaddr_t);
    360 void icache_inv_page(vaddr_t);
    361 void dcache_wb(vaddr_t, vsize_t);
    362 void dcache_wbinv(vaddr_t, vsize_t);
    363 void dcache_inv(vaddr_t, vsize_t);
    364 void icache_inv(vaddr_t, vsize_t);
    365 #endif
    366 void *mapiodev(paddr_t, psize_t);
    367 void unmapiodev(vaddr_t, vsize_t);
    368 
    369 #ifdef MULTIPROCESSOR
    370 int md_setup_trampoline(volatile struct cpu_hatch_data *, struct cpu_info *);
    371 void md_presync_timebase(volatile struct cpu_hatch_data *);
    372 void md_start_timebase(volatile struct cpu_hatch_data *);
    373 void md_sync_timebase(volatile struct cpu_hatch_data *);
    374 void md_setup_interrupts(void);
    375 int cpu_spinup(struct device *, struct cpu_info *);
    376 register_t cpu_hatch(void);
    377 void cpu_spinup_trampoline(void);
    378 #endif
    379 
    380 #define	DELAY(n)		delay(n)
    381 
    382 #define	cpu_need_resched(ci, v)	(ci->ci_want_resched = ci->ci_astpending = 1)
    383 #define	cpu_did_resched(l)	((void)(curcpu()->ci_want_resched = 0))
    384 #define	cpu_need_proftick(l)	((l)->l_pflag |= LP_OWEUPC, curcpu()->ci_astpending = 1)
    385 #define	cpu_signotify(l)	(curcpu()->ci_astpending = 1)	/* XXXSMP */
    386 
    387 #ifdef PPC_BOOKE
    388 void	cpu_ast(struct lwp *, struct cpu_info *);
    389 void    cpu_fixup_stubs(void);
    390 #endif
    391 
    392 #if !defined(PPC_IBM4XX) && !defined(PPC_BOOKE)
    393 void oea_init(void (*)(void));
    394 void oea_startup(const char *);
    395 void oea_dumpsys(void);
    396 void oea_install_extint(void (*)(void));
    397 paddr_t kvtop(void *);
    398 void softnet(int);
    399 
    400 extern paddr_t msgbuf_paddr;
    401 extern int cpu_altivec;
    402 #endif
    403 
    404 #endif /* _KERNEL */
    405 
    406 /* XXX The below breaks unified pmap on ppc32 */
    407 
    408 #if defined(_KERNEL) || defined(_STANDALONE)
    409 #if !defined(CACHELINESIZE)
    410 #ifdef PPC_IBM403
    411 #define	CACHELINESIZE		16
    412 #define MAXCACHELINESIZE	16
    413 #else
    414 #if defined (PPC_OEA64_BRIDGE)
    415 #define	CACHELINESIZE		128
    416 #define MAXCACHELINESIZE	128
    417 #else
    418 #define	CACHELINESIZE		32
    419 #define MAXCACHELINESIZE	32
    420 #endif /* PPC_OEA64_BRIDGE */
    421 #endif
    422 #endif
    423 #endif
    424 
    425 void __syncicache(void *, size_t);
    426 
    427 /*
    428  * CTL_MACHDEP definitions.
    429  */
    430 #define	CPU_CACHELINE		1
    431 #define	CPU_TIMEBASE		2
    432 #define	CPU_CPUTEMP		3
    433 #define	CPU_PRINTFATALTRAPS	4
    434 #define	CPU_CACHEINFO		5
    435 #define	CPU_ALTIVEC		6
    436 #define	CPU_MODEL		7
    437 #define	CPU_POWERSAVE		8	/* int: use CPU powersave mode */
    438 #define	CPU_BOOTED_DEVICE	9	/* string: device we booted from */
    439 #define	CPU_BOOTED_KERNEL	10	/* string: kernel we booted */
    440 #define	CPU_MAXID		11	/* number of valid machdep ids */
    441 
    442 #endif	/* _POWERPC_CPU_H_ */
    443