xref: /openbsd-src/sys/arch/amd64/include/cpu.h (revision 1a81a8e6e44bd2257ef7a22fd415dc9869080982)
1*1a81a8e6Sjsg /*	$OpenBSD: cpu.h,v 1.179 2024/10/22 10:14:49 jsg Exp $	*/
2f5df1827Smickey /*	$NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $	*/
3f5df1827Smickey 
4f5df1827Smickey /*-
5f5df1827Smickey  * Copyright (c) 1990 The Regents of the University of California.
6f5df1827Smickey  * All rights reserved.
7f5df1827Smickey  *
8f5df1827Smickey  * This code is derived from software contributed to Berkeley by
9f5df1827Smickey  * William Jolitz.
10f5df1827Smickey  *
11f5df1827Smickey  * Redistribution and use in source and binary forms, with or without
12f5df1827Smickey  * modification, are permitted provided that the following conditions
13f5df1827Smickey  * are met:
14f5df1827Smickey  * 1. Redistributions of source code must retain the above copyright
15f5df1827Smickey  *    notice, this list of conditions and the following disclaimer.
16f5df1827Smickey  * 2. Redistributions in binary form must reproduce the above copyright
17f5df1827Smickey  *    notice, this list of conditions and the following disclaimer in the
18f5df1827Smickey  *    documentation and/or other materials provided with the distribution.
19c5217b0aSjsg  * 3. Neither the name of the University nor the names of its contributors
20f5df1827Smickey  *    may be used to endorse or promote products derived from this software
21f5df1827Smickey  *    without specific prior written permission.
22f5df1827Smickey  *
23f5df1827Smickey  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24f5df1827Smickey  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25f5df1827Smickey  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26f5df1827Smickey  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27f5df1827Smickey  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28f5df1827Smickey  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29f5df1827Smickey  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30f5df1827Smickey  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31f5df1827Smickey  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32f5df1827Smickey  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33f5df1827Smickey  * SUCH DAMAGE.
34f5df1827Smickey  *
35f5df1827Smickey  *	@(#)cpu.h	5.4 (Berkeley) 5/9/91
36f5df1827Smickey  */
37f5df1827Smickey 
382fa72412Spirofti #ifndef _MACHINE_CPU_H_
392fa72412Spirofti #define _MACHINE_CPU_H_
40f5df1827Smickey 
41f5df1827Smickey /*
42f5df1827Smickey  * Definitions unique to x86-64 cpu support.
43f5df1827Smickey  */
4443d4f7a5Sderaadt #ifdef _KERNEL
45f5df1827Smickey #include <machine/frame.h>
46b767b017Sguenther #include <machine/segments.h>		/* USERMODE */
4743d4f7a5Sderaadt #include <machine/intrdefs.h>
4843d4f7a5Sderaadt #endif /* _KERNEL */
4943d4f7a5Sderaadt 
509e761879Scheloha #include <sys/clockintr.h>
51f5df1827Smickey #include <sys/device.h>
520a894fa6Sdv #include <sys/rwlock.h>
53870ba221Sart #include <sys/sched.h>
540b390b5dStedu #include <sys/sensors.h>
551a1181a9Sjsg #include <sys/srp.h>
5682673a18Smpi #include <uvm/uvm_percpu.h>
57f5df1827Smickey 
58df29cd65Sderaadt #ifdef _KERNEL
59df29cd65Sderaadt 
6077d6d4a2Smlarkin /* VMXON region (Intel) */
6177d6d4a2Smlarkin struct vmxon_region {
6277d6d4a2Smlarkin         uint32_t        vr_revision;
6377d6d4a2Smlarkin };
6477d6d4a2Smlarkin 
6577d6d4a2Smlarkin /*
6677d6d4a2Smlarkin  * VMX for Intel CPUs
6777d6d4a2Smlarkin  */
6877d6d4a2Smlarkin struct vmx {
6977d6d4a2Smlarkin 	uint64_t	vmx_cr0_fixed0;
7077d6d4a2Smlarkin 	uint64_t	vmx_cr0_fixed1;
7177d6d4a2Smlarkin 	uint64_t	vmx_cr4_fixed0;
7277d6d4a2Smlarkin 	uint64_t	vmx_cr4_fixed1;
7377d6d4a2Smlarkin 	uint32_t	vmx_vmxon_revision;
7477d6d4a2Smlarkin 	uint32_t	vmx_msr_table_size;
752a5b1ebdSmlarkin 	uint32_t	vmx_cr3_tgt_count;
76c844c4adSderaadt 	uint8_t		vmx_has_l1_flush_msr;
7730e2643aSdv 	uint64_t	vmx_invept_mode;
7877d6d4a2Smlarkin };
7977d6d4a2Smlarkin 
8077d6d4a2Smlarkin /*
8177d6d4a2Smlarkin  * SVM for AMD CPUs
8277d6d4a2Smlarkin  */
8377d6d4a2Smlarkin struct svm {
84b49f7c39Smlarkin 	uint32_t	svm_max_asid;
85a937696cSmlarkin 	uint8_t		svm_flush_by_asid;
86a937696cSmlarkin 	uint8_t		svm_vmcb_clean;
8718126f0eSdv 	uint8_t		svm_decode_assist;
8877d6d4a2Smlarkin };
8977d6d4a2Smlarkin 
9077d6d4a2Smlarkin union vmm_cpu_cap {
9177d6d4a2Smlarkin 	struct vmx vcc_vmx;
9277d6d4a2Smlarkin 	struct svm vcc_svm;
9377d6d4a2Smlarkin };
9477d6d4a2Smlarkin 
95ccd74f94Sguenther enum cpu_vendor {
96ccd74f94Sguenther     CPUV_UNKNOWN,
97ccd74f94Sguenther     CPUV_AMD,
98ccd74f94Sguenther     CPUV_INTEL,
99ccd74f94Sguenther     CPUV_VIA,
100ccd74f94Sguenther };
101ccd74f94Sguenther 
1020403d5bcSguenther /*
1030403d5bcSguenther  *  Locks used to protect struct members in this file:
1040403d5bcSguenther  *	I	immutable after creation
1050403d5bcSguenther  *	a	atomic operations
1060403d5bcSguenther  *	o	owned (read/modified only) by this CPU
1070403d5bcSguenther  */
108fd94711fSguenther struct x86_64_tss;
1096cbac32fSguenther struct vcpu;
110f5df1827Smickey struct cpu_info {
111b767b017Sguenther 	/*
112b767b017Sguenther 	 * The beginning of this structure in mapped in the userspace "u-k"
113b767b017Sguenther 	 * page tables, so that these first couple members can be accessed
114b767b017Sguenther 	 * from the trampoline code.  The ci_PAGEALIGN member defines where
115b767b017Sguenther 	 * the part that is *not* visible begins, so don't put anything
116b767b017Sguenther 	 * above it that must be kept hidden from userspace!
117b767b017Sguenther 	 */
1180403d5bcSguenther 	u_int64_t	ci_kern_cr3;	/* [o] U+K page table */
1190403d5bcSguenther 	u_int64_t	ci_scratch;	/* [o] for U<-->K transition */
120b767b017Sguenther 
121b767b017Sguenther #define ci_PAGEALIGN	ci_dev
1220403d5bcSguenther 	struct device *ci_dev;		/* [I] */
1230403d5bcSguenther 	struct cpu_info *ci_self;	/* [I] */
1240403d5bcSguenther 	struct cpu_info *ci_next;	/* [I] */
125f5df1827Smickey 
1260403d5bcSguenther 	u_int ci_cpuid;			/* [I] */
1270403d5bcSguenther 	u_int ci_apicid;		/* [I] */
1280403d5bcSguenther 	u_int ci_acpi_proc_id;		/* [I] */
1290403d5bcSguenther 	u_int32_t ci_randseed;		/* [o] */
130f5df1827Smickey 
1310403d5bcSguenther 	u_int64_t ci_kern_rsp;		/* [o] kernel-only stack */
1320403d5bcSguenther 	u_int64_t ci_intr_rsp;		/* [o] U<-->K trampoline stack */
1330403d5bcSguenther 	u_int64_t ci_user_cr3;		/* [o] U-K page table */
134f5df1827Smickey 
135a0dcb178Sguenther 	/* bits for mitigating Micro-architectural Data Sampling */
136c0f33c98Skettenis 	char		ci_mds_tmp[64];	/* [o] 64-byte aligned */
1370403d5bcSguenther 	void		*ci_mds_buf;	/* [I] */
138a0dcb178Sguenther 
139a8972bbdScheloha 	struct proc *ci_curproc;	/* [o] */
140a8972bbdScheloha 	struct schedstate_percpu ci_schedstate; /* scheduler state */
141a8972bbdScheloha 
1426cbac32fSguenther 	struct pmap *ci_proc_pmap;	/* active, non-kernel pmap */
1436cbac32fSguenther 	struct pmap *ci_user_pmap;	/* [o] last pmap used in userspace */
1440403d5bcSguenther 	struct pcb *ci_curpcb;		/* [o] */
1450403d5bcSguenther 	struct pcb *ci_idle_pcb;	/* [o] */
1460403d5bcSguenther 
1470403d5bcSguenther 	u_int	ci_pflags;		/* [o] */
1480403d5bcSguenther #define CPUPF_USERSEGS		0x01	/* CPU has curproc's segs and FS.base */
1490403d5bcSguenther #define CPUPF_USERXSTATE	0x02	/* CPU has curproc's xsave state */
150f5df1827Smickey 
151f5df1827Smickey 	struct intrsource *ci_isources[MAX_INTR_SOURCES];
152092bf81aSkettenis 	u_int64_t	ci_ipending;
153f5df1827Smickey 	int		ci_ilevel;
154f5df1827Smickey 	int		ci_idepth;
1559c9e7f95Sdlg 	int		ci_handled_intr_level;
156092bf81aSkettenis 	u_int64_t	ci_imask[NIPL];
157092bf81aSkettenis 	u_int64_t	ci_iunmask[NIPL];
158521499f7Smatthew #ifdef DIAGNOSTIC
159521499f7Smatthew 	int		ci_mutex_level;
160521499f7Smatthew #endif
161f5df1827Smickey 
1620403d5bcSguenther 	volatile u_int	ci_flags;	/* [a] */
1630403d5bcSguenther 	u_int32_t	ci_ipis;	/* [a] */
164f5df1827Smickey 
165ccd74f94Sguenther 	enum cpu_vendor	ci_vendor;		/* [I] mapped from cpuid(0) */
166ccd74f94Sguenther 	u_int32_t       ci_cpuid_level;         /* [I] cpuid(0).eax */
1670403d5bcSguenther 	u_int32_t	ci_feature_flags;	/* [I] */
1680403d5bcSguenther 	u_int32_t	ci_feature_eflags;	/* [I] */
1690403d5bcSguenther 	u_int32_t	ci_feature_sefflags_ebx;/* [I] */
1700403d5bcSguenther 	u_int32_t	ci_feature_sefflags_ecx;/* [I] */
1710403d5bcSguenther 	u_int32_t	ci_feature_sefflags_edx;/* [I] */
1720403d5bcSguenther 	u_int32_t	ci_feature_amdspec_ebx;	/* [I] */
173f880dfafSbluhm 	u_int32_t	ci_feature_amdsev_eax;	/* [I] */
174f880dfafSbluhm 	u_int32_t	ci_feature_amdsev_ebx;	/* [I] */
175f880dfafSbluhm 	u_int32_t	ci_feature_amdsev_ecx;	/* [I] */
176f880dfafSbluhm 	u_int32_t	ci_feature_amdsev_edx;	/* [I] */
1770403d5bcSguenther 	u_int32_t	ci_feature_tpmflags;	/* [I] */
1780403d5bcSguenther 	u_int32_t	ci_pnfeatset;		/* [I] */
1790403d5bcSguenther 	u_int32_t	ci_efeature_eax;	/* [I] */
1800403d5bcSguenther 	u_int32_t	ci_efeature_ecx;	/* [I] */
1810403d5bcSguenther 	u_int32_t	ci_brand[12];		/* [I] */
1820403d5bcSguenther 	u_int32_t	ci_signature;		/* [I] */
1830403d5bcSguenther 	u_int32_t	ci_family;		/* [I] */
1840403d5bcSguenther 	u_int32_t	ci_model;		/* [I] */
1850403d5bcSguenther 	u_int32_t	ci_cflushsz;		/* [I] */
186f5df1827Smickey 
1870403d5bcSguenther 	int		ci_inatomic;		/* [o] */
188cc85bf3eSkettenis 
18996c11352Skettenis #define __HAVE_CPU_TOPOLOGY
1900403d5bcSguenther 	u_int32_t	ci_smt_id;		/* [I] */
1910403d5bcSguenther 	u_int32_t	ci_core_id;		/* [I] */
1920403d5bcSguenther 	u_int32_t	ci_pkg_id;		/* [I] */
193ec99753cShaesbaert 
1940403d5bcSguenther 	struct cpu_functions *ci_func;		/* [I] */
1950403d5bcSguenther 	void (*cpu_setup)(struct cpu_info *);	/* [I] */
196f5df1827Smickey 
1970403d5bcSguenther 	struct device	*ci_acpicpudev;		/* [I] */
1980403d5bcSguenther 	volatile u_int	ci_mwait;		/* [a] */
1996e1e92d4Sguenther #define	MWAIT_IN_IDLE		0x1	/* don't need IPI to wake */
2006e1e92d4Sguenther #define	MWAIT_KEEP_IDLING	0x2	/* cleared by other cpus to wake me */
201c0558701Sguenther #define	MWAIT_ONLY		0x4	/* set if all idle states use mwait */
2026e1e92d4Sguenther #define	MWAIT_IDLING	(MWAIT_IN_IDLE | MWAIT_KEEP_IDLING)
2036e1e92d4Sguenther 
204f5df1827Smickey 	int		ci_want_resched;
205f5df1827Smickey 
2060403d5bcSguenther 	struct	x86_64_tss *ci_tss;		/* [o] */
2070403d5bcSguenther 	void		*ci_gdt;		/* [o] */
208f5df1827Smickey 
20917e58ef0Sandreas 	volatile int	ci_ddb_paused;
21017e58ef0Sandreas #define CI_DDB_RUNNING		0
21117e58ef0Sandreas #define CI_DDB_SHOULDSTOP	1
21217e58ef0Sandreas #define CI_DDB_STOPPED		2
21317e58ef0Sandreas #define CI_DDB_ENTERDDB		3
21417e58ef0Sandreas #define CI_DDB_INDDB		4
21517e58ef0Sandreas 
21652776b7dSdlg #ifdef MULTIPROCESSOR
21752776b7dSdlg 	struct srp_hazard	ci_srp_hazards[SRP_HAZARD_NUM];
21882673a18Smpi #define __HAVE_UVM_PERCPU
21982673a18Smpi 	struct uvm_pmr_cache	ci_uvm;		/* [o] page cache */
22052776b7dSdlg #endif
22152776b7dSdlg 
2220b390b5dStedu 	struct ksensordev	ci_sensordev;
2230b390b5dStedu 	struct ksensor		ci_sensor;
224b4cf4983Sclaudio 	struct ksensor		ci_hz_sensor;
225b4cf4983Sclaudio 	u_int64_t		ci_hz_mperf;
226b4cf4983Sclaudio 	u_int64_t		ci_hz_aperf;
2276950c8e2Smpi #if defined(GPROF) || defined(DDBPROF)
2286377c2eaSmpi 	struct gmonparam	*ci_gmon;
2291d970828Scheloha 	struct clockintr	ci_gmonclock;
2306377c2eaSmpi #endif
23177d6d4a2Smlarkin 	u_int32_t	ci_vmm_flags;
23277d6d4a2Smlarkin #define	CI_VMM_VMX	(1 << 0)
23377d6d4a2Smlarkin #define	CI_VMM_SVM	(1 << 1)
23477d6d4a2Smlarkin #define	CI_VMM_RVI	(1 << 2)
23577d6d4a2Smlarkin #define	CI_VMM_EPT	(1 << 3)
236b4ff5abaSmartijn #define	CI_VMM_DIS	(1 << 4)
23777d6d4a2Smlarkin 	union		vmm_cpu_cap ci_vmm_cap;
23877d6d4a2Smlarkin 	paddr_t		ci_vmxon_region_pa;
23977d6d4a2Smlarkin 	struct vmxon_region *ci_vmxon_region;
24030e2643aSdv 	paddr_t		ci_vmcs_pa;
24130e2643aSdv 	struct rwlock	ci_vmcs_lock;
24230e2643aSdv 	struct pmap		*ci_ept_pmap;	/* [o] last used EPT pmap */
2436cbac32fSguenther 	struct vcpu		*ci_guest_vcpu;	/* [o] last vcpu resumed */
2448d9f4b32Spirofti 
2451a4a9ab2Scheloha 	char		ci_panicbuf[512];
2460a894fa6Sdv 
247c737cf90Scheloha 	struct clockqueue ci_queue;
248f5df1827Smickey };
249f5df1827Smickey 
250f5df1827Smickey #define CPUF_BSP	0x0001		/* CPU is the original BSP */
251f5df1827Smickey #define CPUF_AP		0x0002		/* CPU is an AP */
252f5df1827Smickey #define CPUF_SP		0x0004		/* CPU is only processor */
253f5df1827Smickey #define CPUF_PRIMARY	0x0008		/* CPU is active primary processor */
254f5df1827Smickey 
2556c090d7fShaesbaert #define CPUF_IDENTIFY	0x0010		/* CPU may now identify */
256b4546092Smikeb #define CPUF_IDENTIFIED	0x0020		/* CPU has been identified */
2576c090d7fShaesbaert 
25807166672Smglocker #define CPUF_CONST_TSC	0x0040		/* CPU has constant TSC */
2599c3f850cSreyk #define CPUF_INVAR_TSC	0x0100		/* CPU has invariant TSC */
26007166672Smglocker 
261f5df1827Smickey #define CPUF_PRESENT	0x1000		/* CPU is present */
262f5df1827Smickey #define CPUF_RUNNING	0x2000		/* CPU is running */
263f5df1827Smickey #define CPUF_PAUSE	0x4000		/* CPU is paused in DDB */
264f5df1827Smickey #define CPUF_GO		0x8000		/* CPU should start running */
26511984784Smlarkin #define CPUF_PARK	0x10000		/* CPU should self-park in real mode */
26677d6d4a2Smlarkin #define CPUF_VMM	0x20000		/* CPU is executing in VMM mode */
267f5df1827Smickey 
268f5df1827Smickey #define PROC_PC(p)	((p)->p_md.md_regs->tf_rip)
2691eaa59e7Sguenther #define PROC_STACK(p)	((p)->p_md.md_regs->tf_rsp)
270f5df1827Smickey 
271b767b017Sguenther struct cpu_info_full;
272b767b017Sguenther extern struct cpu_info_full cpu_info_full_primary;
273b767b017Sguenther #define cpu_info_primary (*(struct cpu_info *)((char *)&cpu_info_full_primary + 4096*2 - offsetof(struct cpu_info, ci_PAGEALIGN)))
274b767b017Sguenther 
275f5df1827Smickey extern struct cpu_info *cpu_info_list;
276f5df1827Smickey 
277f5df1827Smickey #define CPU_INFO_ITERATOR		int
2785d5ec4d4Smiod #define CPU_INFO_FOREACH(cii, ci)	for (cii = 0, ci = cpu_info_list; \
2795d5ec4d4Smiod 					    ci != NULL; ci = ci->ci_next)
280f5df1827Smickey 
281ef44d6b7Sandreas #define CPU_INFO_UNIT(ci)	((ci)->ci_dev ? (ci)->ci_dev->dv_unit : 0)
282b5b9857bSart 
283870ba221Sart /*
284870ba221Sart  * Preempt the current process if in interrupt from user mode,
285870ba221Sart  * or after the current trap/syscall if in system mode.
286870ba221Sart  */
287870ba221Sart extern void need_resched(struct cpu_info *);
2882c9d4ccbSart #define clear_resched(ci) (ci)->ci_want_resched = 0
289870ba221Sart 
290f5df1827Smickey #if defined(MULTIPROCESSOR)
291f5df1827Smickey 
292b1baba0aSpirofti #define MAXCPUS		64	/* bitmask */
293f5df1827Smickey 
294f5df1827Smickey #define CPU_STARTUP(_ci)	((_ci)->ci_func->start(_ci))
295f5df1827Smickey #define CPU_STOP(_ci)		((_ci)->ci_func->stop(_ci))
296f5df1827Smickey #define CPU_START_CLEANUP(_ci)	((_ci)->ci_func->cleanup(_ci))
297f5df1827Smickey 
298f5df1827Smickey #define curcpu()	({struct cpu_info *__ci;                  \
299b767b017Sguenther 			asm volatile("movq %%gs:%P1,%0" : "=r" (__ci) \
300b767b017Sguenther 				:"n" (offsetof(struct cpu_info, ci_self))); \
301f5df1827Smickey 			__ci;})
302f5df1827Smickey #define cpu_number()	(curcpu()->ci_cpuid)
303f5df1827Smickey 
304f5df1827Smickey #define CPU_IS_PRIMARY(ci)	((ci)->ci_flags & CPUF_PRIMARY)
305d73de46fSkettenis #define CPU_IS_RUNNING(ci)	((ci)->ci_flags & CPUF_RUNNING)
306f5df1827Smickey 
30799afcea1Sderaadt extern struct cpu_info *cpu_info[MAXCPUS];
308f5df1827Smickey 
309f5df1827Smickey void cpu_boot_secondary_processors(void);
310f5df1827Smickey 
3116e1e92d4Sguenther void cpu_kick(struct cpu_info *);
3128978f211Sart void cpu_unidle(struct cpu_info *);
3138978f211Sart 
31465f535b7Suebayasi #define CPU_BUSY_CYCLE()	__asm volatile("pause": : : "memory")
31565f535b7Suebayasi 
316f5df1827Smickey #else /* !MULTIPROCESSOR */
317f5df1827Smickey 
31899afcea1Sderaadt #define MAXCPUS		1
319f5df1827Smickey 
320f5df1827Smickey #ifdef _KERNEL
321f5df1827Smickey #define curcpu()		(&cpu_info_primary)
322f5df1827Smickey 
3236e1e92d4Sguenther #define cpu_kick(ci)
3248978f211Sart #define cpu_unidle(ci)
3258978f211Sart 
326b43d7c27Sjca #define CPU_BUSY_CYCLE()	__asm volatile ("" ::: "memory")
32765f535b7Suebayasi 
328f5df1827Smickey #endif
329f5df1827Smickey 
330f5df1827Smickey /*
331f5df1827Smickey  * definitions of cpu-dependent requirements
332f5df1827Smickey  * referenced in generic code
333f5df1827Smickey  */
334f5df1827Smickey #define	cpu_number()		0
335f5df1827Smickey #define CPU_IS_PRIMARY(ci)	1
336d73de46fSkettenis #define CPU_IS_RUNNING(ci)	1
337f5df1827Smickey 
338012ea299Sniklas #endif	/* MULTIPROCESSOR */
339f5df1827Smickey 
3405a26f776Svisa #include <machine/cpufunc.h>
341b5b9857bSart #include <machine/psl.h>
342b5b9857bSart 
343b8f1c15cSdlg static inline unsigned int
344b8f1c15cSdlg cpu_rnd_messybits(void)
345b8f1c15cSdlg {
346b8f1c15cSdlg 	unsigned int hi, lo;
347b8f1c15cSdlg 
348b8f1c15cSdlg 	__asm volatile("rdtsc" : "=d" (hi), "=a" (lo));
349b8f1c15cSdlg 
350b8f1c15cSdlg 	return (hi ^ lo);
351b8f1c15cSdlg }
35201802d2cSdlg 
35343d4f7a5Sderaadt #endif /* _KERNEL */
35443d4f7a5Sderaadt 
355b5b9857bSart #ifdef MULTIPROCESSOR
356b5b9857bSart #include <sys/mplock.h>
357b5b9857bSart #endif
358b5b9857bSart 
359f5df1827Smickey #define aston(p)	((p)->p_md.md_astpending = 1)
360f5df1827Smickey 
361f5df1827Smickey #define curpcb		curcpu()->ci_curpcb
362f5df1827Smickey 
363f5df1827Smickey /*
364f5df1827Smickey  * Arguments to hardclock, softclock and statclock
365f5df1827Smickey  * encapsulate the previous machine state in an opaque
366f5df1827Smickey  * clockframe; for now, use generic intrframe.
367f5df1827Smickey  */
368f5df1827Smickey #define clockframe intrframe
369f5df1827Smickey 
370f5df1827Smickey #define	CLKF_USERMODE(frame)	USERMODE((frame)->if_cs, (frame)->if_rflags)
371f5df1827Smickey #define CLKF_PC(frame)		((frame)->if_rip)
372f5df1827Smickey #define CLKF_INTR(frame)	(curcpu()->ci_idepth > 1)
373f5df1827Smickey 
374f5df1827Smickey /*
375f5df1827Smickey  * Give a profiling tick to the current process when the user profiling
376f5df1827Smickey  * buffer pages are invalid.  On the i386, request an ast to send us
3777c65c9b8Sguenther  * through usertrap(), marking the proc as needing a profiling tick.
378f5df1827Smickey  */
37929514732Sart #define	need_proftick(p)	aston(p)
380f5df1827Smickey 
38131d0dca6Sart void signotify(struct proc *);
382f5df1827Smickey 
383f5df1827Smickey /*
384f5df1827Smickey  * We need a machine-independent name for this.
385f5df1827Smickey  */
386b5b9857bSart extern void (*delay_func)(int);
387040db72bScheloha void delay_fini(void (*)(int));
388c8334f21Scheloha void delay_init(void (*)(int), int);
389f5df1827Smickey struct timeval;
390f5df1827Smickey 
391b5b9857bSart #define DELAY(x)		(*delay_func)(x)
392b5b9857bSart #define delay(x)		(*delay_func)(x)
393f5df1827Smickey 
394f5df1827Smickey 
395f5df1827Smickey #ifdef _KERNEL
39636d473f7Sguenther /* cpu.c */
397f5df1827Smickey extern int cpu_feature;
39877d6d4a2Smlarkin extern int cpu_ebxfeature;
399c098ddcfSjsg extern int cpu_ecxfeature;
4006995b18fShaesbaert extern int ecpu_ecxfeature;
40172a0fbccSbluhm extern int cpu_sev_guestmode;
402f5df1827Smickey extern int cpu_id;
403f5df1827Smickey extern char cpu_vendor[];
404f5df1827Smickey extern int cpuid_level;
40595549711Sguenther extern int cpu_meltdown;
406c0558701Sguenther extern u_int cpu_mwait_size;
407c0558701Sguenther extern u_int cpu_mwait_states;
408c0558701Sguenther 
409ba5ad174Skettenis int	cpu_suspend_primary(void);
410ba5ad174Skettenis 
411831d3bf0Sjsg /* cacheinfo.c */
412831d3bf0Sjsg void	x86_print_cacheinfo(struct cpu_info *);
413831d3bf0Sjsg 
414f5df1827Smickey /* identcpu.c */
415f5df1827Smickey void	identifycpu(struct cpu_info *);
4165922251fSderaadt int	cpu_amd64speed(int *);
41736d473f7Sguenther extern int cpuspeed;
418ebaf145fSbluhm extern int amd64_pos_cbit;
419f5df1827Smickey 
420f5df1827Smickey /* machdep.c */
421f5df1827Smickey void	dumpconf(void);
422ccd74f94Sguenther void	cpu_set_vendor(struct cpu_info *, int _level, const char *_vendor);
423f5df1827Smickey void	cpu_reset(void);
424f5df1827Smickey void	x86_64_proc0_tss_ldt_init(void);
4250f91bea7Sweingart int	amd64_pa_used(paddr_t);
4260c7aa8fcSguenther #define	cpu_idle_enter()	do { /* nothing */ } while (0)
4272692ace4Sjordan extern void (*cpu_idle_cycle_fcn)(void);
4286c195505Skettenis extern void (*cpu_suspend_cycle_fcn)(void);
429d8c6becdSguenther #define	cpu_idle_cycle()	(*cpu_idle_cycle_fcn)()
4300c7aa8fcSguenther #define	cpu_idle_leave()	do { /* nothing */ } while (0)
43111d1f9b2Scheloha extern void (*initclock_func)(void);
43211d1f9b2Scheloha extern void (*startclock_func)(void);
433f5df1827Smickey 
434f5df1827Smickey struct region_descriptor;
435f5df1827Smickey void	lgdt(struct region_descriptor *);
436f5df1827Smickey 
437f5df1827Smickey struct pcb;
438f5df1827Smickey void	savectx(struct pcb *);
439f5df1827Smickey void	proc_trampoline(void);
440f5df1827Smickey 
441f5df1827Smickey /* clock.c */
44294ce6677Sderaadt void	startclocks(void);
4436905cb4aSkettenis void	rtcinit(void);
44494ce6677Sderaadt void	rtcstart(void);
4453191b86aSkettenis void	rtcstop(void);
446f5df1827Smickey void	i8254_delay(int);
447f5df1827Smickey void	i8254_initclocks(void);
44894ce6677Sderaadt void	i8254_startclock(void);
44911d1f9b2Scheloha void	i8254_start_both_clocks(void);
45007e9c1faSotto void	i8254_inittimecounter(void);
45107e9c1faSotto void	i8254_inittimecounter_simple(void);
45207e9c1faSotto 
453e4a861d4Spirofti /* i8259.c */
454e4a861d4Spirofti void	i8259_default_setup(void);
455e4a861d4Spirofti 
456f5df1827Smickey void cpu_init_msrs(struct cpu_info *);
4579f172165Srobert void cpu_fix_msrs(struct cpu_info *);
458b8e34f53Sjsg void cpu_tsx_disable(struct cpu_info *);
459f5df1827Smickey 
4606483bf47Sderaadt /* dkcsum.c */
4616483bf47Sderaadt void	dkcsumattach(void);
4626483bf47Sderaadt 
463f5df1827Smickey /* bus_machdep.c */
464f5df1827Smickey void x86_bus_space_init(void);
465f5df1827Smickey void x86_bus_space_mallocok(void);
466f5df1827Smickey 
46734b4ab5eSuwe /* powernow-k8.c */
4685714d2eaSgwk void k8_powernow_init(struct cpu_info *);
46996773847Sdim void k8_powernow_setperf(int);
47034b4ab5eSuwe 
4710df720aaSclaudio /* k1x-pstate.c */
4720df720aaSclaudio void k1x_init(struct cpu_info *);
4730df720aaSclaudio void k1x_setperf(int);
4740df720aaSclaudio 
4750b390b5dStedu void est_init(struct cpu_info *);
4760b390b5dStedu void est_setperf(int);
4770b390b5dStedu 
4785714d2eaSgwk #ifdef MULTIPROCESSOR
4795714d2eaSgwk /* mp_setperf.c */
4805714d2eaSgwk void mp_setperf_init(void);
4815714d2eaSgwk #endif
4825714d2eaSgwk 
483f5df1827Smickey #endif /* _KERNEL */
484f5df1827Smickey 
485f5df1827Smickey /*
486f5df1827Smickey  * CTL_MACHDEP definitions.
487f5df1827Smickey  */
488f5df1827Smickey #define	CPU_CONSDEV		1	/* dev_t: console terminal device */
489b53e687fSderaadt #define	CPU_BIOS		2	/* BIOS variables */
490b53e687fSderaadt #define	CPU_BLK2CHR		3	/* convert blk maj into chr one */
491b53e687fSderaadt #define	CPU_CHR2BLK		4	/* convert chr maj into blk one */
492b53e687fSderaadt #define CPU_ALLOWAPERTURE	5	/* allow mmap of /dev/xf86 */
493b53e687fSderaadt #define CPU_CPUVENDOR		6	/* cpuid vendor string */
494b53e687fSderaadt #define CPU_CPUID		7	/* cpuid */
495b53e687fSderaadt #define CPU_CPUFEATURE		8	/* cpuid features */
496b53e687fSderaadt #define CPU_KBDRESET		10	/* keyboard reset under pcvt */
497edefdba8Sderaadt #define CPU_XCRYPT		12	/* supports VIA xcrypt in userland */
4982d357aedSnatano #define CPU_LIDACTION		14	/* action caused by lid close */
499151a4d36Smpi #define CPU_FORCEUKBD		15	/* Force ukbd(4) as console keyboard */
500d89cc676Smikeb #define CPU_TSCFREQ		16	/* TSC frequency */
501d89cc676Smikeb #define CPU_INVARIANTTSC	17	/* has invariant TSC */
502e9721e48Stedu #define CPU_PWRACTION		18	/* action caused by power button */
503cd924447Sderaadt #define CPU_RETPOLINE		19	/* cpu requires retpoline pattern */
504cd924447Sderaadt #define CPU_MAXID		20	/* number of valid machdep ids */
505f5df1827Smickey 
506f5df1827Smickey #define	CTL_MACHDEP_NAMES { \
507f5df1827Smickey 	{ 0, 0 }, \
508f5df1827Smickey 	{ "console_device", CTLTYPE_STRUCT }, \
509b53e687fSderaadt 	{ "bios", CTLTYPE_INT }, \
510b53e687fSderaadt 	{ "blk2chr", CTLTYPE_STRUCT }, \
511b53e687fSderaadt 	{ "chr2blk", CTLTYPE_STRUCT }, \
512b53e687fSderaadt 	{ "allowaperture", CTLTYPE_INT }, \
513b53e687fSderaadt 	{ "cpuvendor", CTLTYPE_STRING }, \
514b53e687fSderaadt 	{ "cpuid", CTLTYPE_INT }, \
515b53e687fSderaadt 	{ "cpufeature", CTLTYPE_INT }, \
51627b92d83Stedu 	{ 0, 0 }, \
517b53e687fSderaadt 	{ "kbdreset", CTLTYPE_INT }, \
51827b92d83Stedu 	{ 0, 0 }, \
519edefdba8Sderaadt 	{ "xcrypt", CTLTYPE_INT }, \
52039325887Snatano 	{ 0, 0 }, \
5212d357aedSnatano 	{ "lidaction", CTLTYPE_INT }, \
522a1b81bf1Smpi 	{ "forceukbd", CTLTYPE_INT }, \
523d89cc676Smikeb 	{ "tscfreq", CTLTYPE_QUAD }, \
524d89cc676Smikeb 	{ "invarianttsc", CTLTYPE_INT }, \
525e9721e48Stedu 	{ "pwraction", CTLTYPE_INT }, \
526cd924447Sderaadt 	{ "retpoline", CTLTYPE_INT }, \
527f5df1827Smickey }
528f5df1827Smickey 
5292fa72412Spirofti #endif /* !_MACHINE_CPU_H_ */
530