xref: /illumos-gate/usr/src/uts/i86pc/sys/machcpuvar.h (revision 7c8c0b82)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5100b72f4Sandrei  * Common Development and Distribution License (the "License").
6100b72f4Sandrei  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
220e751525SEric Saxe  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
25f16a0f4cSRobert Mustacchi /*
26c3377ee9SJohn Levon  * Copyright 2019 Joyent, Inc.
27f16a0f4cSRobert Mustacchi  */
287c478bd9Sstevel@tonic-gate 
297c478bd9Sstevel@tonic-gate #ifndef	_SYS_MACHCPUVAR_H
307c478bd9Sstevel@tonic-gate #define	_SYS_MACHCPUVAR_H
317c478bd9Sstevel@tonic-gate 
327c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
337c478bd9Sstevel@tonic-gate extern "C" {
347c478bd9Sstevel@tonic-gate #endif
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #include <sys/inttypes.h>
37f34a7178SJoe Bonasera #include <sys/x_call.h>
387c478bd9Sstevel@tonic-gate #include <sys/tss.h>
397c478bd9Sstevel@tonic-gate #include <sys/segments.h>
407c478bd9Sstevel@tonic-gate #include <sys/rm_platter.h>
417c478bd9Sstevel@tonic-gate #include <sys/avintr.h>
427c478bd9Sstevel@tonic-gate #include <sys/pte.h>
4374ecdb51SJohn Levon #include <sys/stddef.h>
4474ecdb51SJohn Levon #include <sys/debug.h>
4574ecdb51SJohn Levon #include <sys/cpuvar.h>
46*7c8c0b82SPatrick Mooney #include <sys/smt_machcpu.h>
477c478bd9Sstevel@tonic-gate 
487c478bd9Sstevel@tonic-gate #ifndef	_ASM
49b9bc7f78Ssmaybe /*
50b9bc7f78Ssmaybe  * On a virtualized platform a virtual cpu may not be actually
51b9bc7f78Ssmaybe  * on a physical cpu, especially in situations where a configuration has
52b9bc7f78Ssmaybe  * more vcpus than pcpus.  This function tells us (if it's able) if the
53b9bc7f78Ssmaybe  * specified vcpu is currently running on a pcpu.  Note if it is not
54b9bc7f78Ssmaybe  * known or not able to determine, it will return the unknown state.
55b9bc7f78Ssmaybe  */
56b9bc7f78Ssmaybe #define	VCPU_STATE_UNKNOWN	0
57b9bc7f78Ssmaybe #define	VCPU_ON_PCPU		1
58b9bc7f78Ssmaybe #define	VCPU_NOT_ON_PCPU	2
59b9bc7f78Ssmaybe 
60b9bc7f78Ssmaybe extern int vcpu_on_pcpu(processorid_t);
61b9bc7f78Ssmaybe 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * Machine specific fields of the cpu struct
647c478bd9Sstevel@tonic-gate  * defined in common/sys/cpuvar.h.
657c478bd9Sstevel@tonic-gate  *
667c478bd9Sstevel@tonic-gate  * Note:  This is kinda kludgy but seems to be the best
677c478bd9Sstevel@tonic-gate  * of our alternatives.
687c478bd9Sstevel@tonic-gate  */
697c478bd9Sstevel@tonic-gate 
707aec1d6eScindi struct cpuid_info;
712449e17fSsherrym struct cpu_ucode_info;
72a3114836SGerry Liu struct cmi_hdl;
737c478bd9Sstevel@tonic-gate 
74843e1988Sjohnlev /*
75843e1988Sjohnlev  * A note about the hypervisor affinity bits: a one bit in the affinity mask
76843e1988Sjohnlev  * means the corresponding event channel is allowed to be serviced
77843e1988Sjohnlev  * by this cpu.
78843e1988Sjohnlev  */
79843e1988Sjohnlev struct xen_evt_data {
80843e1988Sjohnlev 	ulong_t		pending_sel[PIL_MAX + 1]; /* event array selectors */
81843e1988Sjohnlev 	ulong_t		pending_evts[PIL_MAX + 1][sizeof (ulong_t) * 8];
82843e1988Sjohnlev 	ulong_t		evt_affinity[sizeof (ulong_t) * 8]; /* service on cpu */
83843e1988Sjohnlev };
84843e1988Sjohnlev 
858515d723SPatrick Mooney enum fast_syscall_state {
868515d723SPatrick Mooney 	FSS_DISABLED		= 0,
878515d723SPatrick Mooney 	FSS_ASYSC_ENABLED	= (1 << 0),
888515d723SPatrick Mooney 	FSS_SEP_ENABLED		= (1 << 1)
898515d723SPatrick Mooney };
908515d723SPatrick Mooney 
9174ecdb51SJohn Levon struct kpti_frame {
9274ecdb51SJohn Levon 	uint64_t	kf_lower_redzone;
9374ecdb51SJohn Levon 
9474ecdb51SJohn Levon 	/* Stashed value of %cr3 when we entered the trampoline. */
9574ecdb51SJohn Levon 	greg_t		kf_tr_cr3;
9674ecdb51SJohn Levon 
9774ecdb51SJohn Levon 	/*
9874ecdb51SJohn Levon 	 * We use %r13-r14 as scratch registers in the trampoline code,
9974ecdb51SJohn Levon 	 * so stash those here "below" the rest of the stack so they can be
10074ecdb51SJohn Levon 	 * pushed/popped if needed.
10174ecdb51SJohn Levon 	 */
10274ecdb51SJohn Levon 	greg_t		kf_r14;
10374ecdb51SJohn Levon 	greg_t		kf_r13;
10474ecdb51SJohn Levon 
10574ecdb51SJohn Levon 	/*
10674ecdb51SJohn Levon 	 * Part of this struct is used as the HW stack frame when taking an
10774ecdb51SJohn Levon 	 * interrupt on the user page table. The CPU is going to push a bunch
10874ecdb51SJohn Levon 	 * of regs onto the stack pointer set in the TSS/IDT (which we set to
10974ecdb51SJohn Levon 	 * &kf_rsp here).
11074ecdb51SJohn Levon 	 *
11174ecdb51SJohn Levon 	 * This is only a temporary holding area for them (we'll move them over
11274ecdb51SJohn Levon 	 * to the real interrupt stack once we've set %cr3).
11374ecdb51SJohn Levon 	 *
11474ecdb51SJohn Levon 	 * Note that these must be cleared during a process switch on this cpu.
11574ecdb51SJohn Levon 	 */
11674ecdb51SJohn Levon 	greg_t		kf_err;		/* Bottom of initial hw stack frame */
11774ecdb51SJohn Levon 	greg_t		kf_rip;
11874ecdb51SJohn Levon 	greg_t		kf_cs;
11974ecdb51SJohn Levon 	greg_t		kf_rflags;
12074ecdb51SJohn Levon 	greg_t		kf_rsp;
12174ecdb51SJohn Levon 	greg_t		kf_ss;
12274ecdb51SJohn Levon 
12374ecdb51SJohn Levon 	greg_t		kf_tr_rsp;	/* Top of HW stack frame */
12474ecdb51SJohn Levon 	/* We also write this with the %rsp value on tramp entry */
12574ecdb51SJohn Levon 
12674ecdb51SJohn Levon 	/* Written to 0x1 when this kpti_frame is in use. */
12774ecdb51SJohn Levon 	uint64_t	kf_tr_flag;
12874ecdb51SJohn Levon 
12974ecdb51SJohn Levon 	uint64_t	kf_middle_redzone;
13074ecdb51SJohn Levon 
13174ecdb51SJohn Levon 	/*
13274ecdb51SJohn Levon 	 * The things we need to write to %cr3 to change between page tables.
13374ecdb51SJohn Levon 	 * These live "above" the HW stack.
13474ecdb51SJohn Levon 	 */
13574ecdb51SJohn Levon 	greg_t		kf_kernel_cr3;
13674ecdb51SJohn Levon 	greg_t		kf_user_cr3;
13774ecdb51SJohn Levon 	greg_t		kf_tr_ret_rsp;
13874ecdb51SJohn Levon 
13974ecdb51SJohn Levon 	uint64_t	kf_unused;		/* For 16-byte align */
14074ecdb51SJohn Levon 
14174ecdb51SJohn Levon 	uint64_t	kf_upper_redzone;
14274ecdb51SJohn Levon };
14374ecdb51SJohn Levon 
14474ecdb51SJohn Levon /*
14574ecdb51SJohn Levon  * This first value, MACHCPU_SIZE is the size of all the members in the cpu_t
14674ecdb51SJohn Levon  * AND struct machcpu, before we get to the mcpu_pad and the kpti area.
14774ecdb51SJohn Levon  * The KPTI is used to contain per-CPU data that is visible in both sets of
14874ecdb51SJohn Levon  * page-tables, and hence must be page-aligned and page-sized. See
14974ecdb51SJohn Levon  * hat_pcp_setup().
15074ecdb51SJohn Levon  *
151455e370cSJohn Levon  * There are CTASSERTs in os/intr.c that verify this all works out.
15274ecdb51SJohn Levon  */
153a8ea0c9dSJohn Levon #define	MACHCPU_SIZE	(1568 + 696)
15474ecdb51SJohn Levon #define	MACHCPU_PAD	(MMU_PAGESIZE - MACHCPU_SIZE)
15574ecdb51SJohn Levon #define	MACHCPU_PAD2	(MMU_PAGESIZE - 16 - 3 * sizeof (struct kpti_frame))
15674ecdb51SJohn Levon 
1577c478bd9Sstevel@tonic-gate struct	machcpu {
158f34a7178SJoe Bonasera 	/*
159f34a7178SJoe Bonasera 	 * x_call fields - used for interprocessor cross calls
160f34a7178SJoe Bonasera 	 */
161f34a7178SJoe Bonasera 	struct xc_msg	*xc_msgbox;
162a8ea0c9dSJohn Levon 	struct xc_msg	*xc_curmsg;
163f34a7178SJoe Bonasera 	struct xc_msg	*xc_free;
164f34a7178SJoe Bonasera 	xc_data_t	xc_data;
165f34a7178SJoe Bonasera 	uint32_t	xc_wait_cnt;
166f34a7178SJoe Bonasera 	volatile uint32_t xc_work_cnt;
1677c478bd9Sstevel@tonic-gate 
1687c478bd9Sstevel@tonic-gate 	int		mcpu_nodeid;		/* node-id */
1697c478bd9Sstevel@tonic-gate 	int		mcpu_pri;		/* CPU priority */
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	struct hat	*mcpu_current_hat; /* cpu's current hat */
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	struct hat_cpu_info	*mcpu_hat_info;
1747c478bd9Sstevel@tonic-gate 
17595c0a3c8Sjosephb 	volatile ulong_t	mcpu_tlb_info;
17695c0a3c8Sjosephb 
1777c478bd9Sstevel@tonic-gate 	/* i86 hardware table addresses that cannot be shared */
178ae115bc7Smrj 
1797c478bd9Sstevel@tonic-gate 	user_desc_t	*mcpu_gdt;	/* GDT */
180ae115bc7Smrj 	gate_desc_t	*mcpu_idt;	/* current IDT */
181ae115bc7Smrj 
182f16a0f4cSRobert Mustacchi 	tss_t		*mcpu_tss;	/* TSS */
18374ecdb51SJohn Levon 	void		*mcpu_ldt;
18474ecdb51SJohn Levon 	size_t		mcpu_ldt_len;
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	kmutex_t	mcpu_ppaddr_mutex;
1877c478bd9Sstevel@tonic-gate 	caddr_t		mcpu_caddr1;	/* per cpu CADDR1 */
1887c478bd9Sstevel@tonic-gate 	caddr_t		mcpu_caddr2;	/* per cpu CADDR2 */
189ae115bc7Smrj 	uint64_t	mcpu_caddr1pte;
190ae115bc7Smrj 	uint64_t	mcpu_caddr2pte;
191ae115bc7Smrj 
192ae115bc7Smrj 	struct softint	mcpu_softinfo;
1937c478bd9Sstevel@tonic-gate 	uint64_t	pil_high_start[HIGH_LEVELS];
1947a364d25Sschwartz 	uint64_t	intrstat[PIL_MAX + 1][2];
195ae115bc7Smrj 
1967c478bd9Sstevel@tonic-gate 	struct cpuid_info	 *mcpu_cpi;
197ae115bc7Smrj 
1987c478bd9Sstevel@tonic-gate #if defined(__amd64)
1997c478bd9Sstevel@tonic-gate 	greg_t	mcpu_rtmp_rsp;		/* syscall: temporary %rsp stash */
2007c478bd9Sstevel@tonic-gate 	greg_t	mcpu_rtmp_r15;		/* syscall: temporary %r15 stash */
2017c478bd9Sstevel@tonic-gate #endif
202ae115bc7Smrj 
203ae115bc7Smrj 	struct vcpu_info *mcpu_vcpu_info;
204843e1988Sjohnlev 	uint64_t	mcpu_gdtpa;	/* hypervisor: GDT physical address */
205ae115bc7Smrj 
206843e1988Sjohnlev 	uint16_t mcpu_intr_pending;	/* hypervisor: pending intrpt levels */
207349b53ddSStuart Maybee 	uint16_t mcpu_ec_mbox;		/* hypervisor: evtchn_dev mailbox */
208843e1988Sjohnlev 	struct xen_evt_data *mcpu_evt_pend; /* hypervisor: pending events */
209f98fbcecSbholler 
210f98fbcecSbholler 	volatile uint32_t *mcpu_mwait;	/* MONITOR/MWAIT buffer */
2110e751525SEric Saxe 	void (*mcpu_idle_cpu)(void);	/* idle function */
2120e751525SEric Saxe 	uint16_t mcpu_idle_type;	/* CPU next idle type */
2130e751525SEric Saxe 	uint16_t max_cstates;		/* supported max cstates */
2142449e17fSsherrym 
2158515d723SPatrick Mooney 	enum fast_syscall_state	mcpu_fast_syscall_state;
2168515d723SPatrick Mooney 
2172449e17fSsherrym 	struct cpu_ucode_info	*mcpu_ucode_info;
2180e751525SEric Saxe 
219a3114836SGerry Liu 	void			*mcpu_pm_mach_state;
220a3114836SGerry Liu 	struct cmi_hdl		*mcpu_cmi_hdl;
221a3114836SGerry Liu 	void			*mcpu_mach_ctx_ptr;
2223006ae82SFrank Van Der Linden 
2233006ae82SFrank Van Der Linden 	/*
2243006ae82SFrank Van Der Linden 	 * A stamp that is unique per processor and changes
2253006ae82SFrank Van Der Linden 	 * whenever an interrupt happens. Userful for detecting
2263006ae82SFrank Van Der Linden 	 * if a section of code gets interrupted.
2273006ae82SFrank Van Der Linden 	 * The high order 16 bits will hold the cpu->cpu_id.
2283006ae82SFrank Van Der Linden 	 * The low order bits will be incremented on every interrupt.
2293006ae82SFrank Van Der Linden 	 */
2303006ae82SFrank Van Der Linden 	volatile uint32_t	mcpu_istamp;
23174ecdb51SJohn Levon 
232c3377ee9SJohn Levon 	cpu_smt_t		mcpu_smt;
233455e370cSJohn Levon 
23474ecdb51SJohn Levon 	char			mcpu_pad[MACHCPU_PAD];
23574ecdb51SJohn Levon 
23674ecdb51SJohn Levon 	/* This is the start of the page */
23774ecdb51SJohn Levon 	char			mcpu_pad2[MACHCPU_PAD2];
23874ecdb51SJohn Levon 	struct kpti_frame	mcpu_kpti;
23974ecdb51SJohn Levon 	struct kpti_frame	mcpu_kpti_flt;
24074ecdb51SJohn Levon 	struct kpti_frame	mcpu_kpti_dbg;
24174ecdb51SJohn Levon 	char			mcpu_pad3[16];
2427c478bd9Sstevel@tonic-gate };
2437c478bd9Sstevel@tonic-gate 
244100b72f4Sandrei #define	NINTR_THREADS	(LOCK_LEVEL-1)	/* number of interrupt threads */
245f98fbcecSbholler #define	MWAIT_HALTED	(1)		/* mcpu_mwait set when halting */
246f98fbcecSbholler #define	MWAIT_RUNNING	(0)		/* mcpu_mwait set to wakeup */
2470e751525SEric Saxe #define	MWAIT_WAKEUP_IPI	(2)	/* need IPI to wakeup */
2480e751525SEric Saxe #define	MWAIT_WAKEUP(cpu)	(*((cpu)->cpu_m.mcpu_mwait) = MWAIT_RUNNING)
249100b72f4Sandrei 
2507c478bd9Sstevel@tonic-gate #endif	/* _ASM */
2517c478bd9Sstevel@tonic-gate 
252ae115bc7Smrj /* Please DON'T add any more of this namespace-poisoning sewage here */
253ae115bc7Smrj 
2547c478bd9Sstevel@tonic-gate #define	cpu_nodeid cpu_m.mcpu_nodeid
2557c478bd9Sstevel@tonic-gate #define	cpu_pri cpu_m.mcpu_pri
2567c478bd9Sstevel@tonic-gate #define	cpu_current_hat cpu_m.mcpu_current_hat
2577c478bd9Sstevel@tonic-gate #define	cpu_hat_info cpu_m.mcpu_hat_info
2587c478bd9Sstevel@tonic-gate #define	cpu_ppaddr_mutex cpu_m.mcpu_ppaddr_mutex
2597c478bd9Sstevel@tonic-gate #define	cpu_gdt cpu_m.mcpu_gdt
2607c478bd9Sstevel@tonic-gate #define	cpu_idt cpu_m.mcpu_idt
2617c478bd9Sstevel@tonic-gate #define	cpu_tss cpu_m.mcpu_tss
2627c478bd9Sstevel@tonic-gate #define	cpu_caddr1 cpu_m.mcpu_caddr1
2637c478bd9Sstevel@tonic-gate #define	cpu_caddr2 cpu_m.mcpu_caddr2
2647c478bd9Sstevel@tonic-gate #define	cpu_softinfo cpu_m.mcpu_softinfo
2657c478bd9Sstevel@tonic-gate #define	cpu_caddr1pte cpu_m.mcpu_caddr1pte
2667c478bd9Sstevel@tonic-gate #define	cpu_caddr2pte cpu_m.mcpu_caddr2pte
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2697c478bd9Sstevel@tonic-gate }
2707c478bd9Sstevel@tonic-gate #endif
2717c478bd9Sstevel@tonic-gate 
2727c478bd9Sstevel@tonic-gate #endif	/* _SYS_MACHCPUVAR_H */
273