xref: /netbsd-src/external/cddl/osnet/sys/sys/cpuvar.h (revision ba2539a9805a0544ff82c0003cc02fe1eee5603d)
1 /*	$NetBSD: cpuvar.h,v 1.8 2018/05/28 21:05:10 chs Exp $	*/
2 
3 /*
4  * CDDL HEADER START
5  *
6  * The contents of this file are subject to the terms of the
7  * Common Development and Distribution License (the "License").
8  * You may not use this file except in compliance with the License.
9  *
10  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11  * or http://www.opensolaris.org/os/licensing.
12  * See the License for the specific language governing permissions
13  * and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL HEADER in each
16  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17  * If applicable, add the following below this CDDL HEADER, with the
18  * fields enclosed by brackets "[]" replaced with your own identifying
19  * information: Portions Copyright [yyyy] [name of copyright owner]
20  *
21  * CDDL HEADER END
22  */
23 
24 /*
25  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
26  * Use is subject to license terms.
27  */
28 
29 #ifndef _COMPAT_OPENSOLARIS_SYS_CPUVAR_H
30 #define	_COMPAT_OPENSOLARIS_SYS_CPUVAR_H
31 
32 #include <sys/processor.h>
33 #include <sys/mutex.h>
34 #include <sys/cpuvar_defs.h>
35 
36 #ifdef _KERNEL
37 
38 typedef struct {
39 	int		cpuid;
40         struct cyc_cpu *cpu_cyclic;
41 	uint32_t	cpu_flags;
42 	uint_t		cpu_intr_actv;
43 	uintptr_t	cpu_profile_pc;
44 	uintptr_t	cpu_profile_upc;
45 	uintptr_t	cpu_dtrace_caller;	/* DTrace: caller, if any */
46 	hrtime_t	cpu_dtrace_chillmark;	/* DTrace: chill mark time */
47 	hrtime_t	cpu_dtrace_chilled;	/* DTrace: total chill time */
48 } solaris_cpu_t;
49 
50 /* Some code may choose to redefine this if pcpu_t would be more useful. */
51 #define cpu_t	solaris_cpu_t
52 #define	cpu_id	cpuid
53 
54 extern solaris_cpu_t    solaris_cpu[];
55 
56 #define	CPU_CACHE_COHERENCE_SIZE	64
57 
58 /*
59  * The cpu_core structure consists of per-CPU state available in any context.
60  * On some architectures, this may mean that the page(s) containing the
61  * NCPU-sized array of cpu_core structures must be locked in the TLB -- it
62  * is up to the platform to assure that this is performed properly.  Note that
63  * the structure is sized to avoid false sharing.
64  */
65 #define	CPUC_SIZE		(sizeof (uint16_t) + sizeof (uintptr_t) + \
66 				sizeof (kmutex_t))
67 #define	CPUC_PADSIZE		CPU_CACHE_COHERENCE_SIZE - CPUC_SIZE
68 
69 typedef struct cpu_core {
70 	uint16_t	cpuc_dtrace_flags;	/* DTrace flags */
71 	uint8_t		cpuc_pad[CPUC_PADSIZE];	/* padding */
72 	uintptr_t	cpuc_dtrace_illval;	/* DTrace illegal value */
73 	kmutex_t	cpuc_pid_lock;		/* DTrace pid provider lock */
74 } cpu_core_t;
75 
76 extern cpu_core_t cpu_core[];
77 #endif /* _KERNEL */
78 
79 /*
80  * DTrace flags.
81  */
82 #define	CPU_DTRACE_NOFAULT	0x0001	/* Don't fault */
83 #define	CPU_DTRACE_DROP		0x0002	/* Drop this ECB */
84 #define	CPU_DTRACE_BADADDR	0x0004	/* DTrace fault: bad address */
85 #define	CPU_DTRACE_BADALIGN	0x0008	/* DTrace fault: bad alignment */
86 #define	CPU_DTRACE_DIVZERO	0x0010	/* DTrace fault: divide by zero */
87 #define	CPU_DTRACE_ILLOP	0x0020	/* DTrace fault: illegal operation */
88 #define	CPU_DTRACE_NOSCRATCH	0x0040	/* DTrace fault: out of scratch */
89 #define	CPU_DTRACE_KPRIV	0x0080	/* DTrace fault: bad kernel access */
90 #define	CPU_DTRACE_UPRIV	0x0100	/* DTrace fault: bad user access */
91 #define	CPU_DTRACE_TUPOFLOW	0x0200	/* DTrace fault: tuple stack overflow */
92 #if defined(__sparc)
93 #define	CPU_DTRACE_FAKERESTORE	0x0400	/* pid provider hint to getreg */
94 #endif
95 #define	CPU_DTRACE_ENTRY	0x0800	/* pid provider hint to ustack() */
96 #define	CPU_DTRACE_BADSTACK	0x1000	/* DTrace fault: bad stack */
97 
98 #define	CPU_DTRACE_FAULT	(CPU_DTRACE_BADADDR | CPU_DTRACE_BADALIGN | \
99 				CPU_DTRACE_DIVZERO | CPU_DTRACE_ILLOP | \
100 				CPU_DTRACE_NOSCRATCH | CPU_DTRACE_KPRIV | \
101 				CPU_DTRACE_UPRIV | CPU_DTRACE_TUPOFLOW | \
102 				CPU_DTRACE_BADSTACK)
103 #define	CPU_DTRACE_ERROR	(CPU_DTRACE_FAULT | CPU_DTRACE_DROP)
104 
105 /*
106  * Flags in the CPU structure.
107  *
108  * These are protected by cpu_lock (except during creation).
109  *
110  * Offlined-CPUs have three stages of being offline:
111  *
112  * CPU_ENABLE indicates that the CPU is participating in I/O interrupts
113  * that can be directed at a number of different CPUs.  If CPU_ENABLE
114  * is off, the CPU will not be given interrupts that can be sent elsewhere,
115  * but will still get interrupts from devices associated with that CPU only,
116  * and from other CPUs.
117  *
118  * CPU_OFFLINE indicates that the dispatcher should not allow any threads
119  * other than interrupt threads to run on that CPU.  A CPU will not have
120  * CPU_OFFLINE set if there are any bound threads (besides interrupts).
121  *
122  * CPU_QUIESCED is set if p_offline was able to completely turn idle the
123  * CPU and it will not have to run interrupt threads.  In this case it'll
124  * stay in the idle loop until CPU_QUIESCED is turned off.
125  *
126  * CPU_FROZEN is used only by CPR to mark CPUs that have been successfully
127  * suspended (in the suspend path), or have yet to be resumed (in the resume
128  * case).
129  *
130  * On some platforms CPUs can be individually powered off.
131  * The following flags are set for powered off CPUs: CPU_QUIESCED,
132  * CPU_OFFLINE, and CPU_POWEROFF.  The following flags are cleared:
133  * CPU_RUNNING, CPU_READY, CPU_EXISTS, and CPU_ENABLE.
134  */
135 #define	CPU_RUNNING	0x001		/* CPU running */
136 #define	CPU_READY	0x002		/* CPU ready for cross-calls */
137 #define	CPU_QUIESCED	0x004		/* CPU will stay in idle */
138 #define	CPU_EXISTS	0x008		/* CPU is configured */
139 #define	CPU_ENABLE	0x010		/* CPU enabled for interrupts */
140 #define	CPU_OFFLINE	0x020		/* CPU offline via p_online */
141 #define	CPU_POWEROFF	0x040		/* CPU is powered off */
142 #define	CPU_FROZEN	0x080		/* CPU is frozen via CPR suspend */
143 #define	CPU_SPARE	0x100		/* CPU offline available for use */
144 #define	CPU_FAULTED	0x200		/* CPU offline diagnosed faulty */
145 
146 typedef enum {
147 	CPU_INIT,
148 	CPU_CONFIG,
149 	CPU_UNCONFIG,
150 	CPU_ON,
151 	CPU_OFF,
152 	CPU_CPUPART_IN,
153 	CPU_CPUPART_OUT
154 } cpu_setup_t;
155 
156 typedef int cpu_setup_func_t(cpu_setup_t, int, void *);
157 #define mp_maxid ncpu
158 
159 
160 #endif /* _COMPAT_OPENSOLARIS_SYS_CPUVAR_H */
161