1/*	$NetBSD: cpuvar.h,v 1.6 2010/03/12 21:37:37 darran 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/mutex.h>
33#include <sys/cpuvar_defs.h>
34
35#ifdef _KERNEL
36
37typedef struct {
38	int		cpuid;
39        struct cyc_cpu *cpu_cyclic;
40	uint32_t	cpu_flags;
41	uint_t		cpu_intr_actv;
42	uintptr_t	cpu_profile_pc;
43	uintptr_t	cpu_profile_upc;
44	uintptr_t	cpu_dtrace_caller;	/* DTrace: caller, if any */
45	hrtime_t	cpu_dtrace_chillmark;	/* DTrace: chill mark time */
46	hrtime_t	cpu_dtrace_chilled;	/* DTrace: total chill time */
47} solaris_cpu_t;
48
49/* Some code may choose to redefine this if pcpu_t would be more useful. */
50#define cpu_t	solaris_cpu_t
51#define	cpu_id	cpuid
52
53extern solaris_cpu_t    solaris_cpu[];
54
55#define	CPU_CACHE_COHERENCE_SIZE	64
56
57/*
58 * The cpu_core structure consists of per-CPU state available in any context.
59 * On some architectures, this may mean that the page(s) containing the
60 * NCPU-sized array of cpu_core structures must be locked in the TLB -- it
61 * is up to the platform to assure that this is performed properly.  Note that
62 * the structure is sized to avoid false sharing.
63 */
64#define	CPUC_SIZE		(sizeof (uint16_t) + sizeof (uintptr_t) + \
65				sizeof (kmutex_t))
66#define	CPUC_PADSIZE		CPU_CACHE_COHERENCE_SIZE - CPUC_SIZE
67
68typedef struct cpu_core {
69	uint16_t	cpuc_dtrace_flags;	/* DTrace flags */
70	uint8_t		cpuc_pad[CPUC_PADSIZE];	/* padding */
71	uintptr_t	cpuc_dtrace_illval;	/* DTrace illegal value */
72	kmutex_t	cpuc_pid_lock;		/* DTrace pid provider lock */
73} cpu_core_t;
74
75extern cpu_core_t cpu_core[];
76#endif /* _KERNEL */
77
78/*
79 * DTrace flags.
80 */
81#define	CPU_DTRACE_NOFAULT	0x0001	/* Don't fault */
82#define	CPU_DTRACE_DROP		0x0002	/* Drop this ECB */
83#define	CPU_DTRACE_BADADDR	0x0004	/* DTrace fault: bad address */
84#define	CPU_DTRACE_BADALIGN	0x0008	/* DTrace fault: bad alignment */
85#define	CPU_DTRACE_DIVZERO	0x0010	/* DTrace fault: divide by zero */
86#define	CPU_DTRACE_ILLOP	0x0020	/* DTrace fault: illegal operation */
87#define	CPU_DTRACE_NOSCRATCH	0x0040	/* DTrace fault: out of scratch */
88#define	CPU_DTRACE_KPRIV	0x0080	/* DTrace fault: bad kernel access */
89#define	CPU_DTRACE_UPRIV	0x0100	/* DTrace fault: bad user access */
90#define	CPU_DTRACE_TUPOFLOW	0x0200	/* DTrace fault: tuple stack overflow */
91#if defined(__sparc)
92#define	CPU_DTRACE_FAKERESTORE	0x0400	/* pid provider hint to getreg */
93#endif
94#define	CPU_DTRACE_ENTRY	0x0800	/* pid provider hint to ustack() */
95#define	CPU_DTRACE_BADSTACK	0x1000	/* DTrace fault: bad stack */
96
97#define	CPU_DTRACE_FAULT	(CPU_DTRACE_BADADDR | CPU_DTRACE_BADALIGN | \
98				CPU_DTRACE_DIVZERO | CPU_DTRACE_ILLOP | \
99				CPU_DTRACE_NOSCRATCH | CPU_DTRACE_KPRIV | \
100				CPU_DTRACE_UPRIV | CPU_DTRACE_TUPOFLOW | \
101				CPU_DTRACE_BADSTACK)
102#define	CPU_DTRACE_ERROR	(CPU_DTRACE_FAULT | CPU_DTRACE_DROP)
103
104/*
105 * Flags in the CPU structure.
106 *
107 * These are protected by cpu_lock (except during creation).
108 *
109 * Offlined-CPUs have three stages of being offline:
110 *
111 * CPU_ENABLE indicates that the CPU is participating in I/O interrupts
112 * that can be directed at a number of different CPUs.  If CPU_ENABLE
113 * is off, the CPU will not be given interrupts that can be sent elsewhere,
114 * but will still get interrupts from devices associated with that CPU only,
115 * and from other CPUs.
116 *
117 * CPU_OFFLINE indicates that the dispatcher should not allow any threads
118 * other than interrupt threads to run on that CPU.  A CPU will not have
119 * CPU_OFFLINE set if there are any bound threads (besides interrupts).
120 *
121 * CPU_QUIESCED is set if p_offline was able to completely turn idle the
122 * CPU and it will not have to run interrupt threads.  In this case it'll
123 * stay in the idle loop until CPU_QUIESCED is turned off.
124 *
125 * CPU_FROZEN is used only by CPR to mark CPUs that have been successfully
126 * suspended (in the suspend path), or have yet to be resumed (in the resume
127 * case).
128 *
129 * On some platforms CPUs can be individually powered off.
130 * The following flags are set for powered off CPUs: CPU_QUIESCED,
131 * CPU_OFFLINE, and CPU_POWEROFF.  The following flags are cleared:
132 * CPU_RUNNING, CPU_READY, CPU_EXISTS, and CPU_ENABLE.
133 */
134#define	CPU_RUNNING	0x001		/* CPU running */
135#define	CPU_READY	0x002		/* CPU ready for cross-calls */
136#define	CPU_QUIESCED	0x004		/* CPU will stay in idle */
137#define	CPU_EXISTS	0x008		/* CPU is configured */
138#define	CPU_ENABLE	0x010		/* CPU enabled for interrupts */
139#define	CPU_OFFLINE	0x020		/* CPU offline via p_online */
140#define	CPU_POWEROFF	0x040		/* CPU is powered off */
141#define	CPU_FROZEN	0x080		/* CPU is frozen via CPR suspend */
142#define	CPU_SPARE	0x100		/* CPU offline available for use */
143#define	CPU_FAULTED	0x200		/* CPU offline diagnosed faulty */
144
145typedef enum {
146	CPU_INIT,
147	CPU_CONFIG,
148	CPU_UNCONFIG,
149	CPU_ON,
150	CPU_OFF,
151	CPU_CPUPART_IN,
152	CPU_CPUPART_OUT
153} cpu_setup_t;
154
155typedef int cpu_setup_func_t(cpu_setup_t, int, void *);
156#define mp_maxid ncpu
157
158
159#endif /* _COMPAT_OPENSOLARIS_SYS_CPUVAR_H */
160