xref: /freebsd/sys/powerpc/include/cpu.h (revision 51369649b03ece2aed3eb61b0c8214b9aa5b2fa2)
160727d8bSWarner Losh /*-
2*51369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-4-Clause
3*51369649SPedro F. Giffuni  *
4f9bac91bSBenno Rice  * Copyright (C) 1995-1997 Wolfgang Solfrank.
5f9bac91bSBenno Rice  * Copyright (C) 1995-1997 TooLs GmbH.
6f9bac91bSBenno Rice  * All rights reserved.
7f9bac91bSBenno Rice  *
8f9bac91bSBenno Rice  * Redistribution and use in source and binary forms, with or without
9f9bac91bSBenno Rice  * modification, are permitted provided that the following conditions
10f9bac91bSBenno Rice  * are met:
11f9bac91bSBenno Rice  * 1. Redistributions of source code must retain the above copyright
12f9bac91bSBenno Rice  *    notice, this list of conditions and the following disclaimer.
13f9bac91bSBenno Rice  * 2. Redistributions in binary form must reproduce the above copyright
14f9bac91bSBenno Rice  *    notice, this list of conditions and the following disclaimer in the
15f9bac91bSBenno Rice  *    documentation and/or other materials provided with the distribution.
16f9bac91bSBenno Rice  * 3. All advertising materials mentioning features or use of this software
17f9bac91bSBenno Rice  *    must display the following acknowledgement:
18f9bac91bSBenno Rice  *	This product includes software developed by TooLs GmbH.
19f9bac91bSBenno Rice  * 4. The name of TooLs GmbH may not be used to endorse or promote products
20f9bac91bSBenno Rice  *    derived from this software without specific prior written permission.
21f9bac91bSBenno Rice  *
22f9bac91bSBenno Rice  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23f9bac91bSBenno Rice  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24f9bac91bSBenno Rice  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25f9bac91bSBenno Rice  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26f9bac91bSBenno Rice  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27f9bac91bSBenno Rice  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28f9bac91bSBenno Rice  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29f9bac91bSBenno Rice  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30f9bac91bSBenno Rice  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31f9bac91bSBenno Rice  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32f9bac91bSBenno Rice  *
33f9bac91bSBenno Rice  *	$NetBSD: cpu.h,v 1.11 2000/05/26 21:19:53 thorpej Exp $
34f9bac91bSBenno Rice  * $FreeBSD$
35f9bac91bSBenno Rice  */
36f9bac91bSBenno Rice 
37f9bac91bSBenno Rice #ifndef _MACHINE_CPU_H_
38f9bac91bSBenno Rice #define	_MACHINE_CPU_H_
39f9bac91bSBenno Rice 
40f9bac91bSBenno Rice #include <machine/frame.h>
41f9bac91bSBenno Rice #include <machine/pcb.h>
42f9bac91bSBenno Rice #include <machine/psl.h>
43f9bac91bSBenno Rice 
44227f6604SNathan Whitehorn /*
45227f6604SNathan Whitehorn  * CPU Feature Attributes
46227f6604SNathan Whitehorn  *
47227f6604SNathan Whitehorn  * These are defined in the PowerPC ELF ABI for the AT_HWCAP vector,
48227f6604SNathan Whitehorn  * and are exported to userland via the machdep.cpu_features
49227f6604SNathan Whitehorn  * sysctl.
50227f6604SNathan Whitehorn  */
51227f6604SNathan Whitehorn 
52227f6604SNathan Whitehorn extern int cpu_features;
53b0bf7fcdSNathan Whitehorn extern int cpu_features2;
54227f6604SNathan Whitehorn 
55227f6604SNathan Whitehorn #define	PPC_FEATURE_32		0x80000000	/* Always true */
56227f6604SNathan Whitehorn #define	PPC_FEATURE_64		0x40000000	/* Defined on a 64-bit CPU */
57227f6604SNathan Whitehorn #define	PPC_FEATURE_HAS_ALTIVEC	0x10000000
58227f6604SNathan Whitehorn #define	PPC_FEATURE_HAS_FPU	0x08000000
59227f6604SNathan Whitehorn #define	PPC_FEATURE_HAS_MMU	0x04000000
60227f6604SNathan Whitehorn #define	PPC_FEATURE_UNIFIED_CACHE 0x01000000
61512071deSJustin Hibbits #define	PPC_FEATURE_HAS_SPE	0x00800000
62512071deSJustin Hibbits #define	PPC_FEATURE_HAS_EFP_SINGLE	0x00400000
63512071deSJustin Hibbits #define	PPC_FEATURE_HAS_EFP_DOUBLE	0x00200000
64b0bf7fcdSNathan Whitehorn #define	PPC_FEATURE_BOOKE	0x00008000
65b0bf7fcdSNathan Whitehorn #define	PPC_FEATURE_SMT		0x00004000
66b0bf7fcdSNathan Whitehorn #define	PPC_FEATURE_ARCH_2_05	0x00001000
67b0bf7fcdSNathan Whitehorn #define	PPC_FEATURE_HAS_DFP	0x00000400
68b0bf7fcdSNathan Whitehorn #define	PPC_FEATURE_ARCH_2_06	0x00000100
6935f612b8SNathan Whitehorn #define	PPC_FEATURE_HAS_VSX	0x00000080
70227f6604SNathan Whitehorn 
71b0bf7fcdSNathan Whitehorn #define	PPC_FEATURE2_ARCH_2_07	0x80000000
72b0bf7fcdSNathan Whitehorn #define	PPC_FEATURE2_HAS_HTM	0x40000000
7381d7ebb6SJustin Hibbits #define	PPC_FEATURE2_ISEL	0x08000000
74b0bf7fcdSNathan Whitehorn #define	PPC_FEATURE2_HAS_VCRYPTO 0x02000000
75b0bf7fcdSNathan Whitehorn 
76227f6604SNathan Whitehorn #define	PPC_FEATURE_BITMASK						\
77227f6604SNathan Whitehorn 	"\20"								\
7835f612b8SNathan Whitehorn 	"\040PPC32\037PPC64\035ALTIVEC\034FPU\033MMU\031UNIFIEDCACHE"	\
79512071deSJustin Hibbits 	"\030SPE\027SPESFP\026DPESFP\020BOOKE\017SMT\015ARCH205\013DFP"	\
80512071deSJustin Hibbits 	"\011ARCH206\010VSX"
81b0bf7fcdSNathan Whitehorn #define	PPC_FEATURE2_BITMASK						\
82b0bf7fcdSNathan Whitehorn 	"\20"								\
8381d7ebb6SJustin Hibbits 	"\040ARCH207\037HTM\034ISEL\032VCRYPTO"
84227f6604SNathan Whitehorn 
859a7fefa5SBenno Rice #define	TRAPF_USERMODE(frame)	(((frame)->srr1 & PSL_PR) != 0)
86c791ba59SBenno Rice #define	TRAPF_PC(frame)		((frame)->srr0)
87c791ba59SBenno Rice 
88f9bac91bSBenno Rice /*
89f9bac91bSBenno Rice  * CTL_MACHDEP definitions.
90f9bac91bSBenno Rice  */
91f9bac91bSBenno Rice #define	CPU_CACHELINE	1
92f9bac91bSBenno Rice 
93f9bac91bSBenno Rice static __inline u_int64_t
94f9bac91bSBenno Rice get_cyclecount(void)
95f9bac91bSBenno Rice {
960a9b03cbSPeter Grehan 	u_int32_t _upper, _lower;
970a9b03cbSPeter Grehan 	u_int64_t _time;
98f9bac91bSBenno Rice 
99f9bac91bSBenno Rice 	__asm __volatile(
100f9bac91bSBenno Rice 		"mftb %0\n"
101f9bac91bSBenno Rice 		"mftbu %1"
1020a9b03cbSPeter Grehan 		: "=r" (_lower), "=r" (_upper));
103f9bac91bSBenno Rice 
1040a9b03cbSPeter Grehan 	_time = (u_int64_t)_upper;
1050a9b03cbSPeter Grehan 	_time = (_time << 32) + _lower;
1060a9b03cbSPeter Grehan 	return (_time);
107f9bac91bSBenno Rice }
108f9bac91bSBenno Rice 
1095fd2c51eSMark Peek #define	cpu_getstack(td)	((td)->td_frame->fixreg[1])
1109ddcd322SNathan Whitehorn #define	cpu_spinwait()		__asm __volatile("or 27,27,27") /* yield */
111f9bac91bSBenno Rice 
11211722a8cSMarcel Moolenaar extern char btext[];
11311722a8cSMarcel Moolenaar extern char etext[];
11411722a8cSMarcel Moolenaar 
11526502503SMarcel Moolenaar void	cpu_halt(void);
11626502503SMarcel Moolenaar void	cpu_reset(void);
117e1c161e7SJustin Hibbits void	cpu_sleep(void);
118e1c161e7SJustin Hibbits void	flush_disable_caches(void);
119d163144bSBenno Rice void	fork_trampoline(void);
12026502503SMarcel Moolenaar void	swi_vm(void *);
12126502503SMarcel Moolenaar 
122f9bac91bSBenno Rice #endif	/* _MACHINE_CPU_H_ */
123