1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 *
21 * $FreeBSD$
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
37struct cyc_cpu;
38
39typedef struct {
40	int		cpuid;
41        struct cyc_cpu *cpu_cyclic;
42	uint32_t	cpu_flags;
43	uint_t		cpu_intr_actv;
44	uintptr_t	cpu_profile_pc;
45	uintptr_t	cpu_profile_upc;
46	uintptr_t	cpu_dtrace_caller;	/* DTrace: caller, if any */
47	hrtime_t	cpu_dtrace_chillmark;	/* DTrace: chill mark time */
48	hrtime_t	cpu_dtrace_chilled;	/* DTrace: total chill time */
49} solaris_cpu_t;
50
51/* Some code may choose to redefine this if pcpu_t would be more useful. */
52#define cpu_t	solaris_cpu_t
53#define	cpu_id	cpuid
54
55extern solaris_cpu_t    solaris_cpu[];
56
57#define	CPU_CACHE_COHERENCE_SIZE	64
58
59/*
60 * The cpu_core structure consists of per-CPU state available in any context.
61 * On some architectures, this may mean that the page(s) containing the
62 * NCPU-sized array of cpu_core structures must be locked in the TLB -- it
63 * is up to the platform to assure that this is performed properly.  Note that
64 * the structure is sized to avoid false sharing.
65 */
66#define	CPUC_SIZE		(sizeof (uint16_t) + sizeof (uintptr_t) + \
67				sizeof (kmutex_t))
68#define	CPUC_SIZE1		roundup(CPUC_SIZE, CPU_CACHE_COHERENCE_SIZE)
69#define	CPUC_PADSIZE		CPUC_SIZE1 - CPUC_SIZE
70
71typedef struct cpu_core {
72	uint16_t	cpuc_dtrace_flags;	/* DTrace flags */
73	uint8_t		cpuc_pad[CPUC_PADSIZE];	/* padding */
74	uintptr_t	cpuc_dtrace_illval;	/* DTrace illegal value */
75	kmutex_t	cpuc_pid_lock;		/* DTrace pid provider lock */
76} cpu_core_t;
77
78extern cpu_core_t cpu_core[];
79
80extern kmutex_t	cpu_lock;
81#endif /* _KERNEL */
82
83/*
84 * Flags in the CPU structure.
85 *
86 * These are protected by cpu_lock (except during creation).
87 *
88 * Offlined-CPUs have three stages of being offline:
89 *
90 * CPU_ENABLE indicates that the CPU is participating in I/O interrupts
91 * that can be directed at a number of different CPUs.  If CPU_ENABLE
92 * is off, the CPU will not be given interrupts that can be sent elsewhere,
93 * but will still get interrupts from devices associated with that CPU only,
94 * and from other CPUs.
95 *
96 * CPU_OFFLINE indicates that the dispatcher should not allow any threads
97 * other than interrupt threads to run on that CPU.  A CPU will not have
98 * CPU_OFFLINE set if there are any bound threads (besides interrupts).
99 *
100 * CPU_QUIESCED is set if p_offline was able to completely turn idle the
101 * CPU and it will not have to run interrupt threads.  In this case it'll
102 * stay in the idle loop until CPU_QUIESCED is turned off.
103 *
104 * CPU_FROZEN is used only by CPR to mark CPUs that have been successfully
105 * suspended (in the suspend path), or have yet to be resumed (in the resume
106 * case).
107 *
108 * On some platforms CPUs can be individually powered off.
109 * The following flags are set for powered off CPUs: CPU_QUIESCED,
110 * CPU_OFFLINE, and CPU_POWEROFF.  The following flags are cleared:
111 * CPU_RUNNING, CPU_READY, CPU_EXISTS, and CPU_ENABLE.
112 */
113#define	CPU_RUNNING	0x001		/* CPU running */
114#define	CPU_READY	0x002		/* CPU ready for cross-calls */
115#define	CPU_QUIESCED	0x004		/* CPU will stay in idle */
116#define	CPU_EXISTS	0x008		/* CPU is configured */
117#define	CPU_ENABLE	0x010		/* CPU enabled for interrupts */
118#define	CPU_OFFLINE	0x020		/* CPU offline via p_online */
119#define	CPU_POWEROFF	0x040		/* CPU is powered off */
120#define	CPU_FROZEN	0x080		/* CPU is frozen via CPR suspend */
121#define	CPU_SPARE	0x100		/* CPU offline available for use */
122#define	CPU_FAULTED	0x200		/* CPU offline diagnosed faulty */
123
124typedef enum {
125	CPU_INIT,
126	CPU_CONFIG,
127	CPU_UNCONFIG,
128	CPU_ON,
129	CPU_OFF,
130	CPU_CPUPART_IN,
131	CPU_CPUPART_OUT
132} cpu_setup_t;
133
134typedef int cpu_setup_func_t(cpu_setup_t, int, void *);
135
136
137#endif /* _COMPAT_OPENSOLARIS_SYS_CPUVAR_H */
138