Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.103
      1  1.103    cherry /*	$NetBSD: cpu.h,v 1.103 2019/02/11 14:59:32 cherry Exp $	*/
      2    1.1        ad 
      3   1.84      maxv /*
      4    1.1        ad  * Copyright (c) 1990 The Regents of the University of California.
      5    1.1        ad  * All rights reserved.
      6    1.1        ad  *
      7    1.1        ad  * This code is derived from software contributed to Berkeley by
      8    1.1        ad  * William Jolitz.
      9    1.1        ad  *
     10    1.1        ad  * Redistribution and use in source and binary forms, with or without
     11    1.1        ad  * modification, are permitted provided that the following conditions
     12    1.1        ad  * are met:
     13    1.1        ad  * 1. Redistributions of source code must retain the above copyright
     14    1.1        ad  *    notice, this list of conditions and the following disclaimer.
     15    1.1        ad  * 2. Redistributions in binary form must reproduce the above copyright
     16    1.1        ad  *    notice, this list of conditions and the following disclaimer in the
     17    1.1        ad  *    documentation and/or other materials provided with the distribution.
     18    1.1        ad  * 3. Neither the name of the University nor the names of its contributors
     19    1.1        ad  *    may be used to endorse or promote products derived from this software
     20    1.1        ad  *    without specific prior written permission.
     21    1.1        ad  *
     22    1.1        ad  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23    1.1        ad  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24    1.1        ad  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25    1.1        ad  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26    1.1        ad  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27    1.1        ad  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28    1.1        ad  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29    1.1        ad  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30    1.1        ad  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31    1.1        ad  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32    1.1        ad  * SUCH DAMAGE.
     33    1.1        ad  *
     34    1.1        ad  *	@(#)cpu.h	5.4 (Berkeley) 5/9/91
     35    1.1        ad  */
     36    1.1        ad 
     37    1.1        ad #ifndef _X86_CPU_H_
     38    1.1        ad #define _X86_CPU_H_
     39    1.1        ad 
     40   1.32       mrg #if defined(_KERNEL) || defined(_STANDALONE)
     41   1.32       mrg #include <sys/types.h>
     42   1.32       mrg #else
     43   1.63       dsl #include <stdint.h>
     44   1.32       mrg #include <stdbool.h>
     45   1.32       mrg #endif /* _KERNEL || _STANDALONE */
     46   1.32       mrg 
     47   1.11        ad #if defined(_KERNEL) || defined(_KMEMUSER)
     48    1.1        ad #if defined(_KERNEL_OPT)
     49    1.1        ad #include "opt_xen.h"
     50   1.88      maxv #include "opt_svs.h"
     51    1.1        ad #ifdef i386
     52    1.1        ad #include "opt_user_ldt.h"
     53    1.1        ad #endif
     54    1.1        ad #endif
     55    1.1        ad 
     56    1.1        ad /*
     57    1.1        ad  * Definitions unique to x86 cpu support.
     58    1.1        ad  */
     59    1.1        ad #include <machine/frame.h>
     60   1.23       jym #include <machine/pte.h>
     61    1.1        ad #include <machine/segments.h>
     62    1.1        ad #include <machine/tss.h>
     63    1.1        ad #include <machine/intrdefs.h>
     64    1.1        ad 
     65    1.1        ad #include <x86/cacheinfo.h>
     66    1.1        ad 
     67    1.1        ad #include <sys/cpu_data.h>
     68    1.9       mrg #include <sys/evcnt.h>
     69   1.19    cegger #include <sys/device_if.h> /* for device_t */
     70    1.1        ad 
     71   1.36    cherry #ifdef XEN
     72  1.102    cherry #include <xen/include/public/xen.h>
     73  1.102    cherry #include <xen/include/public/event_channel.h>
     74   1.48    bouyer #include <sys/mutex.h>
     75   1.36    cherry #endif /* XEN */
     76   1.36    cherry 
     77    1.1        ad struct intrsource;
     78    1.1        ad struct pmap;
     79    1.1        ad 
     80    1.1        ad #ifdef __x86_64__
     81    1.1        ad #define	i386tss	x86_64_tss
     82    1.1        ad #endif
     83    1.1        ad 
     84    1.1        ad #define	NIOPORTS	1024		/* # of ports we allow to be mapped */
     85    1.1        ad #define	IOMAPSIZE	(NIOPORTS / 8)	/* I/O bitmap size in bytes */
     86    1.1        ad 
     87   1.85      maxv struct cpu_tss {
     88   1.85      maxv #ifdef i386
     89   1.85      maxv 	struct i386tss dblflt_tss;
     90   1.85      maxv 	struct i386tss ddbipi_tss;
     91   1.85      maxv #endif
     92   1.85      maxv 	struct i386tss tss;
     93   1.85      maxv 	uint8_t iomap[IOMAPSIZE];
     94   1.85      maxv } __packed;
     95   1.85      maxv 
     96    1.1        ad /*
     97   1.99    cherry  * Arguments to hardclock, softclock and statclock
     98   1.99    cherry  * encapsulate the previous machine state in an opaque
     99   1.99    cherry  * clockframe; for now, use generic intrframe.
    100   1.99    cherry  */
    101   1.99    cherry struct clockframe {
    102   1.99    cherry 	struct intrframe cf_if;
    103   1.99    cherry };
    104   1.99    cherry 
    105   1.99    cherry /*
    106    1.1        ad  * a bunch of this belongs in cpuvar.h; move it later..
    107    1.1        ad  */
    108    1.1        ad 
    109    1.1        ad struct cpu_info {
    110   1.26  christos 	struct cpu_data ci_data;	/* MI per-cpu data */
    111   1.19    cegger 	device_t ci_dev;		/* pointer to our device */
    112    1.1        ad 	struct cpu_info *ci_self;	/* self-pointer */
    113  1.103    cherry #ifdef XEN
    114    1.1        ad 	volatile struct vcpu_info *ci_vcpu; /* for XEN */
    115  1.103    cherry #endif
    116    1.1        ad 
    117    1.1        ad 	/*
    118    1.1        ad 	 * Will be accessed by other CPUs.
    119    1.1        ad 	 */
    120    1.1        ad 	struct cpu_info *ci_next;	/* next cpu */
    121    1.1        ad 	struct lwp *ci_curlwp;		/* current owner of the processor */
    122   1.58  christos 	struct lwp *ci_fpcurlwp;	/* current owner of the FPU */
    123    1.1        ad 	cpuid_t ci_cpuid;		/* our CPU ID */
    124   1.24    jruoho 	uint32_t ci_acpiid;		/* our ACPI/MADT ID */
    125   1.84      maxv 	uint32_t ci_initapicid;		/* our initial APIC ID */
    126    1.1        ad 
    127    1.1        ad 	/*
    128    1.1        ad 	 * Private members.
    129    1.1        ad 	 */
    130    1.1        ad 	struct pmap *ci_pmap;		/* current pmap */
    131    1.1        ad 	int ci_want_pmapload;		/* pmap_load() is needed */
    132    1.1        ad 	volatile int ci_tlbstate;	/* one of TLBSTATE_ states. see below */
    133    1.1        ad #define	TLBSTATE_VALID	0	/* all user tlbs are valid */
    134    1.1        ad #define	TLBSTATE_LAZY	1	/* tlbs are valid but won't be kept uptodate */
    135    1.1        ad #define	TLBSTATE_STALE	2	/* we might have stale user tlbs */
    136    1.3        ad 	int ci_curldt;		/* current LDT descriptor */
    137   1.16        ad 	int ci_nintrhand;	/* number of H/W interrupt handlers */
    138    1.1        ad 	uint64_t ci_scratch;
    139   1.35     rmind 	uintptr_t ci_pmap_data[128 / sizeof(uintptr_t)];
    140    1.1        ad 
    141    1.1        ad 	struct intrsource *ci_isources[MAX_INTR_SOURCES];
    142  1.101    cherry #if defined(XEN)
    143  1.101    cherry 	struct intrsource *ci_xsources[NIPL];
    144  1.101    cherry 	uint32_t	ci_xmask[NIPL];
    145  1.101    cherry 	uint32_t	ci_xunmask[NIPL];
    146  1.101    cherry 	uint32_t	ci_xpending; /* XEN doesn't use the cmpxchg8 path */
    147  1.101    cherry #endif
    148  1.101    cherry 
    149    1.1        ad 	volatile int	ci_mtx_count;	/* Negative count of spin mutexes */
    150    1.1        ad 	volatile int	ci_mtx_oldspl;	/* Old SPL at this ci_idepth */
    151    1.1        ad 
    152    1.1        ad 	/* The following must be aligned for cmpxchg8b. */
    153    1.1        ad 	struct {
    154    1.1        ad 		uint32_t	ipending;
    155    1.1        ad 		int		ilevel;
    156    1.1        ad 	} ci_istate __aligned(8);
    157    1.1        ad #define ci_ipending	ci_istate.ipending
    158    1.1        ad #define	ci_ilevel	ci_istate.ilevel
    159    1.1        ad 	int		ci_idepth;
    160    1.1        ad 	void *		ci_intrstack;
    161    1.1        ad 	uint32_t	ci_imask[NIPL];
    162    1.1        ad 	uint32_t	ci_iunmask[NIPL];
    163    1.1        ad 
    164    1.1        ad 	uint32_t ci_flags;		/* flags; see below */
    165    1.1        ad 	uint32_t ci_ipis;		/* interprocessor interrupts pending */
    166    1.1        ad 
    167   1.64       dsl 	uint32_t	ci_signature;	 /* X86 cpuid type (cpuid.1.%eax) */
    168    1.1        ad 	uint32_t	ci_vendor[4];	 /* vendor string */
    169   1.64       dsl 	uint32_t	ci_max_cpuid;	/* cpuid.0:%eax */
    170   1.64       dsl 	uint32_t	ci_max_ext_cpuid; /* cpuid.80000000:%eax */
    171    1.1        ad 	volatile uint32_t	ci_lapic_counter;
    172    1.1        ad 
    173   1.90      maxv 	uint32_t	ci_feat_val[8]; /* X86 CPUID feature bits */
    174   1.64       dsl 			/* [0] basic features cpuid.1:%edx
    175   1.64       dsl 			 * [1] basic features cpuid.1:%ecx (CPUID2_xxx bits)
    176   1.64       dsl 			 * [2] extended features cpuid:80000001:%edx
    177   1.64       dsl 			 * [3] extended features cpuid:80000001:%ecx
    178   1.64       dsl 			 * [4] VIA padlock features
    179   1.67      maxv 			 * [5] structured extended features cpuid.7:%ebx
    180   1.67      maxv 			 * [6] structured extended features cpuid.7:%ecx
    181   1.90      maxv 			 * [7] structured extended features cpuid.7:%edx
    182   1.64       dsl 			 */
    183   1.21       jym 
    184    1.1        ad 	const struct cpu_functions *ci_func;  /* start/stop functions */
    185    1.1        ad 	struct trapframe *ci_ddb_regs;
    186    1.1        ad 
    187   1.70   msaitoh 	u_int ci_cflush_lsize;	/* CLFLUSH insn line size */
    188    1.1        ad 	struct x86_cache_info ci_cinfo[CAI_COUNT];
    189    1.1        ad 
    190   1.96  pgoyette 	device_t	ci_frequency;	/* Frequency scaling technology */
    191   1.96  pgoyette 	device_t	ci_padlock;	/* VIA PadLock private storage */
    192   1.96  pgoyette 	device_t	ci_temperature;	/* Intel coretemp(4) or equivalent */
    193   1.96  pgoyette 	device_t	ci_vm;		/* Virtual machine guest driver */
    194   1.96  pgoyette 
    195   1.96  pgoyette 	/*
    196   1.96  pgoyette 	 * Segmentation-related data.
    197   1.96  pgoyette 	 */
    198   1.96  pgoyette 	union descriptor *ci_gdt;
    199   1.96  pgoyette 	struct cpu_tss	*ci_tss;	/* Per-cpu TSSes; shared among LWPs */
    200   1.96  pgoyette 	int ci_tss_sel;			/* TSS selector of this cpu */
    201   1.96  pgoyette 
    202   1.96  pgoyette 	/*
    203   1.96  pgoyette 	 * The following two are actually region_descriptors,
    204   1.96  pgoyette 	 * but that would pollute the namespace.
    205   1.96  pgoyette 	 */
    206   1.96  pgoyette 	uintptr_t	ci_suspend_gdt;
    207   1.96  pgoyette 	uint16_t	ci_suspend_gdt_padding;
    208   1.96  pgoyette 	uintptr_t	ci_suspend_idt;
    209   1.96  pgoyette 	uint16_t	ci_suspend_idt_padding;
    210   1.96  pgoyette 
    211   1.96  pgoyette 	uint16_t	ci_suspend_tr;
    212   1.96  pgoyette 	uint16_t	ci_suspend_ldt;
    213   1.96  pgoyette 	uintptr_t	ci_suspend_fs;
    214   1.96  pgoyette 	uintptr_t	ci_suspend_gs;
    215   1.96  pgoyette 	uintptr_t	ci_suspend_kgs;
    216   1.96  pgoyette 	uintptr_t	ci_suspend_efer;
    217   1.96  pgoyette 	uintptr_t	ci_suspend_reg[12];
    218   1.96  pgoyette 	uintptr_t	ci_suspend_cr0;
    219   1.96  pgoyette 	uintptr_t	ci_suspend_cr2;
    220   1.96  pgoyette 	uintptr_t	ci_suspend_cr3;
    221   1.96  pgoyette 	uintptr_t	ci_suspend_cr4;
    222   1.96  pgoyette 	uintptr_t	ci_suspend_cr8;
    223   1.96  pgoyette 
    224   1.96  pgoyette 	/* The following must be in a single cache line. */
    225   1.96  pgoyette 	int		ci_want_resched __aligned(64);
    226   1.96  pgoyette 	int		ci_padout __aligned(64);
    227   1.96  pgoyette 
    228   1.95      maxv #ifndef __HAVE_DIRECT_MAP
    229   1.95      maxv #define VPAGE_SRC 0
    230   1.95      maxv #define VPAGE_DST 1
    231   1.95      maxv #define VPAGE_ZER 2
    232   1.95      maxv #define VPAGE_PTP 3
    233   1.95      maxv #define VPAGE_MAX 4
    234   1.95      maxv 	vaddr_t		vpage[VPAGE_MAX];
    235   1.95      maxv 	pt_entry_t	*vpage_pte[VPAGE_MAX];
    236   1.95      maxv #endif
    237   1.95      maxv 
    238   1.23       jym #ifdef PAE
    239   1.45    cherry 	uint32_t	ci_pae_l3_pdirpa; /* PA of L3 PD */
    240   1.23       jym 	pd_entry_t *	ci_pae_l3_pdir; /* VA pointer to L3 PD */
    241   1.23       jym #endif
    242   1.23       jym 
    243   1.88      maxv #ifdef SVS
    244   1.88      maxv 	pd_entry_t *	ci_svs_updir;
    245   1.88      maxv 	paddr_t		ci_svs_updirpa;
    246   1.88      maxv 	paddr_t		ci_svs_kpdirpa;
    247   1.88      maxv 	kmutex_t	ci_svs_mtx;
    248   1.89      maxv 	pd_entry_t *	ci_svs_rsp0_pte;
    249   1.89      maxv 	vaddr_t		ci_svs_rsp0;
    250   1.89      maxv 	vaddr_t		ci_svs_ursp0;
    251   1.89      maxv 	vaddr_t		ci_svs_krsp0;
    252   1.89      maxv 	vaddr_t		ci_svs_utls;
    253   1.88      maxv #endif
    254   1.88      maxv 
    255  1.103    cherry #ifdef XEN
    256  1.103    cherry 	u_long ci_evtmask[NR_EVENT_CHANNELS]; /* events allowed on this CPU */
    257  1.103    cherry 	struct evcnt ci_ipi_events[XEN_NIPIS];
    258  1.103    cherry 	evtchn_port_t ci_ipi_evtchn;
    259  1.103    cherry #if defined(XENPV)
    260   1.96  pgoyette #if defined(PAE) || defined(__x86_64__)
    261   1.23       jym 	/* Currently active user PGD (can't use rcr3() with Xen) */
    262   1.41    cherry 	pd_entry_t *	ci_kpm_pdir;	/* per-cpu PMD (va) */
    263   1.46    cherry 	paddr_t		ci_kpm_pdirpa;  /* per-cpu PMD (pa) */
    264   1.48    bouyer 	kmutex_t	ci_kpm_mtx;
    265   1.96  pgoyette #endif /* defined(PAE) || defined(__x86_64__) */
    266   1.96  pgoyette 
    267   1.41    cherry #if defined(__x86_64__)
    268   1.46    cherry 	/* per-cpu version of normal_pdes */
    269  1.103    cherry 	pd_entry_t *	ci_normal_pdes[3]; /* Ok to hardcode. only for x86_64 && XENPV */
    270   1.23       jym 	paddr_t		ci_xen_current_user_pgd;
    271   1.96  pgoyette #endif	/* defined(__x86_64__) */
    272   1.41    cherry 
    273   1.96  pgoyette 	size_t		ci_xpq_idx;
    274   1.93  riastrad 	/* Xen raw system time at which we last ran hardclock.  */
    275   1.93  riastrad 	uint64_t	ci_xen_hardclock_systime_ns;
    276   1.93  riastrad 
    277   1.93  riastrad 	/*
    278   1.93  riastrad 	 * Last TSC-adjusted local Xen system time we observed.  Used
    279   1.93  riastrad 	 * to detect whether the Xen clock has gone backwards.
    280   1.93  riastrad 	 */
    281   1.93  riastrad 	uint64_t	ci_xen_last_systime_ns;
    282   1.93  riastrad 
    283   1.93  riastrad 	/*
    284   1.93  riastrad 	 * Distance in nanoseconds from the local view of system time
    285   1.93  riastrad 	 * to the global view of system time, if the local time is
    286   1.93  riastrad 	 * behind the global time.
    287   1.93  riastrad 	 */
    288   1.93  riastrad 	uint64_t	ci_xen_systime_ns_skew;
    289   1.93  riastrad 
    290   1.94  riastrad 	/* Xen periodic timer interrupt handle.  */
    291   1.94  riastrad 	struct intrhand	*ci_xen_timer_intrhand;
    292   1.94  riastrad 
    293   1.99    cherry 	/*
    294   1.99    cherry 	 * Clockframe for timer interrupt handler.
    295   1.99    cherry 	 * Saved at entry via event callback.
    296   1.99    cherry 	 */
    297  1.100    cherry 	vaddr_t ci_xen_clockf_pc; /* RIP at last event interrupt */
    298  1.100    cherry 	bool ci_xen_clockf_usermode; /* Was the guest in usermode ? */
    299   1.99    cherry 
    300   1.93  riastrad 	/* Event counters for various pathologies that might happen.  */
    301   1.93  riastrad 	struct evcnt	ci_xen_cpu_tsc_backwards_evcnt;
    302   1.93  riastrad 	struct evcnt	ci_xen_tsc_delta_negative_evcnt;
    303   1.93  riastrad 	struct evcnt	ci_xen_raw_systime_wraparound_evcnt;
    304   1.93  riastrad 	struct evcnt	ci_xen_raw_systime_backwards_evcnt;
    305   1.93  riastrad 	struct evcnt	ci_xen_systime_backwards_hardclock_evcnt;
    306   1.93  riastrad 	struct evcnt	ci_xen_missed_hardclock_evcnt;
    307  1.103    cherry #endif /* XENPV */
    308  1.103    cherry #else   /* XEN */
    309   1.96  pgoyette 	struct evcnt ci_ipi_events[X86_NIPI];
    310  1.103    cherry #endif	/* XEN */
    311   1.93  riastrad 
    312    1.1        ad };
    313    1.1        ad 
    314    1.1        ad /*
    315   1.15     rmind  * Macros to handle (some) trapframe registers for common x86 code.
    316   1.15     rmind  */
    317   1.15     rmind #ifdef __x86_64__
    318   1.15     rmind #define	X86_TF_RAX(tf)		tf->tf_rax
    319   1.15     rmind #define	X86_TF_RDX(tf)		tf->tf_rdx
    320   1.15     rmind #define	X86_TF_RSP(tf)		tf->tf_rsp
    321   1.15     rmind #define	X86_TF_RIP(tf)		tf->tf_rip
    322   1.15     rmind #define	X86_TF_RFLAGS(tf)	tf->tf_rflags
    323   1.15     rmind #else
    324   1.15     rmind #define	X86_TF_RAX(tf)		tf->tf_eax
    325   1.15     rmind #define	X86_TF_RDX(tf)		tf->tf_edx
    326   1.15     rmind #define	X86_TF_RSP(tf)		tf->tf_esp
    327   1.15     rmind #define	X86_TF_RIP(tf)		tf->tf_eip
    328   1.15     rmind #define	X86_TF_RFLAGS(tf)	tf->tf_eflags
    329   1.15     rmind #endif
    330   1.15     rmind 
    331   1.15     rmind /*
    332    1.1        ad  * Processor flag notes: The "primary" CPU has certain MI-defined
    333    1.1        ad  * roles (mostly relating to hardclock handling); we distinguish
    334   1.84      maxv  * between the processor which booted us, and the processor currently
    335    1.1        ad  * holding the "primary" role just to give us the flexibility later to
    336    1.1        ad  * change primaries should we be sufficiently twisted.
    337    1.1        ad  */
    338    1.1        ad 
    339    1.1        ad #define	CPUF_BSP	0x0001		/* CPU is the original BSP */
    340    1.1        ad #define	CPUF_AP		0x0002		/* CPU is an AP */
    341    1.1        ad #define	CPUF_SP		0x0004		/* CPU is only processor */
    342    1.1        ad #define	CPUF_PRIMARY	0x0008		/* CPU is active primary processor */
    343    1.1        ad 
    344    1.1        ad #define	CPUF_SYNCTSC	0x0800		/* Synchronize TSC */
    345    1.1        ad #define	CPUF_PRESENT	0x1000		/* CPU is present */
    346    1.1        ad #define	CPUF_RUNNING	0x2000		/* CPU is running */
    347    1.1        ad #define	CPUF_PAUSE	0x4000		/* CPU is paused in DDB */
    348    1.1        ad #define	CPUF_GO		0x8000		/* CPU should start running */
    349    1.1        ad 
    350   1.40     joerg #endif /* _KERNEL || __KMEMUSER */
    351   1.40     joerg 
    352   1.40     joerg #ifdef _KERNEL
    353    1.1        ad /*
    354    1.1        ad  * We statically allocate the CPU info for the primary CPU (or,
    355    1.1        ad  * the only CPU on uniprocessors), and the primary CPU is the
    356    1.1        ad  * first CPU on the CPU info list.
    357    1.1        ad  */
    358    1.1        ad extern struct cpu_info cpu_info_primary;
    359    1.1        ad extern struct cpu_info *cpu_info_list;
    360    1.1        ad 
    361   1.57  christos #define	CPU_INFO_ITERATOR		int __unused
    362   1.57  christos #define	CPU_INFO_FOREACH(cii, ci)	ci = cpu_info_list; \
    363    1.1        ad 					ci != NULL; ci = ci->ci_next
    364    1.1        ad 
    365    1.1        ad #define CPU_STARTUP(_ci, _target)	((_ci)->ci_func->start(_ci, _target))
    366    1.1        ad #define CPU_STOP(_ci)	        	((_ci)->ci_func->stop(_ci))
    367    1.1        ad #define CPU_START_CLEANUP(_ci)		((_ci)->ci_func->cleanup(_ci))
    368    1.1        ad 
    369   1.10     pooka #if !defined(__GNUC__) || defined(_MODULE)
    370    1.1        ad /* For non-GCC and modules */
    371    1.1        ad struct cpu_info	*x86_curcpu(void);
    372    1.1        ad void	cpu_set_curpri(int);
    373    1.5        ad # ifdef __GNUC__
    374    1.5        ad lwp_t	*x86_curlwp(void) __attribute__ ((const));
    375    1.5        ad # else
    376    1.5        ad lwp_t   *x86_curlwp(void);
    377    1.5        ad # endif
    378    1.1        ad #endif
    379    1.1        ad 
    380    1.4        ad #define cpu_number() 		(cpu_index(curcpu()))
    381    1.1        ad 
    382    1.1        ad #define CPU_IS_PRIMARY(ci)	((ci)->ci_flags & CPUF_PRIMARY)
    383    1.1        ad 
    384    1.1        ad #define	X86_AST_GENERIC		0x01
    385    1.1        ad #define	X86_AST_PREEMPT		0x02
    386    1.1        ad 
    387    1.1        ad #define aston(l, why)		((l)->l_md.md_astpending |= (why))
    388    1.1        ad #define	cpu_did_resched(l)	((l)->l_md.md_astpending &= ~X86_AST_PREEMPT)
    389    1.1        ad 
    390    1.1        ad void cpu_boot_secondary_processors(void);
    391    1.1        ad void cpu_init_idle_lwps(void);
    392    1.1        ad void cpu_init_msrs(struct cpu_info *, bool);
    393   1.48    bouyer void cpu_load_pmap(struct pmap *, struct pmap *);
    394   1.37    cherry void cpu_broadcast_halt(void);
    395   1.37    cherry void cpu_kick(struct cpu_info *);
    396    1.1        ad 
    397   1.87      maxv void cpu_pcpuarea_init(struct cpu_info *);
    398   1.88      maxv void cpu_svs_init(struct cpu_info *);
    399   1.91      maxv void cpu_speculation_init(struct cpu_info *);
    400   1.87      maxv 
    401    1.1        ad #define	curcpu()		x86_curcpu()
    402    1.1        ad #define	curlwp			x86_curlwp()
    403   1.18     rmind #define	curpcb			((struct pcb *)lwp_getpcb(curlwp))
    404    1.1        ad 
    405    1.1        ad /*
    406    1.1        ad  * Give a profiling tick to the current process when the user profiling
    407    1.1        ad  * buffer pages are invalid.  On the i386, request an ast to send us
    408    1.1        ad  * through trap(), marking the proc as needing a profiling tick.
    409    1.1        ad  */
    410    1.1        ad extern void	cpu_need_proftick(struct lwp *l);
    411    1.1        ad 
    412    1.1        ad /*
    413    1.1        ad  * Notify the LWP l that it has a signal pending, process as soon as
    414    1.1        ad  * possible.
    415    1.1        ad  */
    416    1.1        ad extern void	cpu_signotify(struct lwp *);
    417    1.1        ad 
    418    1.1        ad /*
    419    1.1        ad  * We need a machine-independent name for this.
    420    1.1        ad  */
    421    1.1        ad extern void (*delay_func)(unsigned int);
    422    1.1        ad struct timeval;
    423    1.1        ad 
    424   1.72       chs #ifndef __HIDE_DELAY
    425    1.1        ad #define	DELAY(x)		(*delay_func)(x)
    426    1.1        ad #define delay(x)		(*delay_func)(x)
    427   1.72       chs #endif
    428    1.1        ad 
    429    1.1        ad extern int biosbasemem;
    430    1.1        ad extern int biosextmem;
    431   1.51       chs extern int cputype;
    432    1.1        ad extern int cpuid_level;
    433    1.1        ad extern int cpu_class;
    434    1.1        ad extern char cpu_brand_string[];
    435   1.42       jym extern int use_pae;
    436    1.1        ad 
    437   1.61       dsl #ifdef __i386__
    438   1.81     kamil #define	i386_fpu_present	1
    439   1.61       dsl int npx586bug1(int, int);
    440   1.61       dsl extern int i386_fpu_fdivbug;
    441    1.1        ad extern int i386_use_fxsave;
    442    1.1        ad extern int i386_has_sse;
    443    1.1        ad extern int i386_has_sse2;
    444   1.61       dsl #else
    445   1.81     kamil #define	i386_fpu_present	1
    446   1.61       dsl #define	i386_fpu_fdivbug	0
    447   1.61       dsl #define	i386_use_fxsave		1
    448   1.61       dsl #define	i386_has_sse		1
    449   1.61       dsl #define	i386_has_sse2		1
    450   1.61       dsl #endif
    451    1.1        ad 
    452   1.65       dsl extern int x86_fpu_save;
    453   1.65       dsl #define	FPU_SAVE_FSAVE		0
    454   1.65       dsl #define	FPU_SAVE_FXSAVE		1
    455   1.65       dsl #define	FPU_SAVE_XSAVE		2
    456   1.65       dsl #define	FPU_SAVE_XSAVEOPT	3
    457   1.66       dsl extern unsigned int x86_fpu_save_size;
    458   1.65       dsl extern uint64_t x86_xsave_features;
    459   1.98      maxv extern uint32_t x86_fpu_mxcsr_mask;
    460   1.92      maxv extern bool x86_fpu_eager;
    461   1.65       dsl 
    462    1.1        ad extern void (*x86_cpu_idle)(void);
    463    1.1        ad #define	cpu_idle() (*x86_cpu_idle)()
    464    1.1        ad 
    465    1.1        ad /* machdep.c */
    466   1.78      maxv #ifdef i386
    467   1.78      maxv void	cpu_set_tss_gates(struct cpu_info *);
    468   1.78      maxv #endif
    469    1.1        ad void	cpu_reset(void);
    470    1.1        ad 
    471    1.1        ad /* longrun.c */
    472    1.1        ad u_int 	tmx86_get_longrun_mode(void);
    473    1.1        ad void 	tmx86_get_longrun_status(u_int *, u_int *, u_int *);
    474    1.1        ad void 	tmx86_init_longrun(void);
    475    1.1        ad 
    476    1.1        ad /* identcpu.c */
    477    1.1        ad void 	cpu_probe(struct cpu_info *);
    478    1.1        ad void	cpu_identify(struct cpu_info *);
    479   1.71    nonaka void	identify_hypervisor(void);
    480   1.71    nonaka 
    481   1.71    nonaka typedef enum vm_guest {
    482   1.71    nonaka 	VM_GUEST_NO = 0,
    483   1.71    nonaka 	VM_GUEST_VM,
    484   1.71    nonaka 	VM_GUEST_XEN,
    485   1.71    nonaka 	VM_GUEST_HV,
    486   1.71    nonaka 	VM_GUEST_VMWARE,
    487   1.71    nonaka 	VM_GUEST_KVM,
    488   1.71    nonaka 	VM_LAST
    489   1.71    nonaka } vm_guest_t;
    490   1.71    nonaka extern vm_guest_t vm_guest;
    491    1.1        ad 
    492   1.17     rmind /* cpu_topology.c */
    493   1.20     rmind void	x86_cpu_topology(struct cpu_info *);
    494   1.17     rmind 
    495    1.1        ad /* locore.s */
    496    1.1        ad struct region_descriptor;
    497    1.1        ad void	lgdt(struct region_descriptor *);
    498  1.103    cherry #ifdef XENPV
    499    1.1        ad void	lgdt_finish(void);
    500    1.1        ad #endif
    501    1.1        ad 
    502    1.1        ad struct pcb;
    503    1.1        ad void	savectx(struct pcb *);
    504    1.1        ad void	lwp_trampoline(void);
    505  1.103    cherry #ifdef XENPV
    506    1.1        ad void	startrtclock(void);
    507    1.1        ad void	xen_delay(unsigned int);
    508    1.1        ad void	xen_initclocks(void);
    509   1.47       jym void	xen_suspendclocks(struct cpu_info *);
    510   1.47       jym void	xen_resumeclocks(struct cpu_info *);
    511    1.1        ad #else
    512    1.1        ad /* clock.c */
    513    1.1        ad void	initrtclock(u_long);
    514    1.1        ad void	startrtclock(void);
    515    1.1        ad void	i8254_delay(unsigned int);
    516    1.1        ad void	i8254_microtime(struct timeval *);
    517    1.1        ad void	i8254_initclocks(void);
    518    1.1        ad #endif
    519    1.1        ad 
    520    1.1        ad /* cpu.c */
    521    1.1        ad void	cpu_probe_features(struct cpu_info *);
    522    1.1        ad 
    523    1.1        ad /* vm_machdep.c */
    524   1.78      maxv void	cpu_proc_fork(struct proc *, struct proc *);
    525   1.13     rmind paddr_t	kvtop(void *);
    526    1.1        ad 
    527    1.1        ad #ifdef USER_LDT
    528    1.1        ad /* sys_machdep.h */
    529    1.1        ad int	x86_get_ldt(struct lwp *, void *, register_t *);
    530    1.1        ad int	x86_set_ldt(struct lwp *, void *, register_t *);
    531    1.1        ad #endif
    532    1.1        ad 
    533    1.1        ad /* isa_machdep.c */
    534    1.1        ad void	isa_defaultirq(void);
    535    1.1        ad int	isa_nmi(void);
    536    1.1        ad 
    537    1.1        ad /* consinit.c */
    538    1.1        ad void kgdb_port_init(void);
    539    1.1        ad 
    540    1.1        ad /* bus_machdep.c */
    541    1.1        ad void x86_bus_space_init(void);
    542    1.1        ad void x86_bus_space_mallocok(void);
    543    1.1        ad 
    544   1.40     joerg #endif /* _KERNEL */
    545   1.40     joerg 
    546   1.40     joerg #if defined(_KERNEL) || defined(_KMEMUSER)
    547    1.1        ad #include <machine/psl.h>	/* Must be after struct cpu_info declaration */
    548   1.11        ad #endif /* _KERNEL || __KMEMUSER */
    549    1.1        ad 
    550    1.1        ad /*
    551    1.1        ad  * CTL_MACHDEP definitions.
    552    1.1        ad  */
    553    1.1        ad #define	CPU_CONSDEV		1	/* dev_t: console terminal device */
    554    1.1        ad #define	CPU_BIOSBASEMEM		2	/* int: bios-reported base mem (K) */
    555    1.1        ad #define	CPU_BIOSEXTMEM		3	/* int: bios-reported ext. mem (K) */
    556    1.1        ad /* 	CPU_NKPDE		4	obsolete: int: number of kernel PDEs */
    557    1.1        ad #define	CPU_BOOTED_KERNEL	5	/* string: booted kernel name */
    558    1.1        ad #define CPU_DISKINFO		6	/* struct disklist *:
    559    1.1        ad 					 * disk geometry information */
    560    1.1        ad #define CPU_FPU_PRESENT		7	/* int: FPU is present */
    561    1.1        ad #define	CPU_OSFXSR		8	/* int: OS uses FXSAVE/FXRSTOR */
    562    1.1        ad #define	CPU_SSE			9	/* int: OS/CPU supports SSE */
    563    1.1        ad #define	CPU_SSE2		10	/* int: OS/CPU supports SSE2 */
    564    1.1        ad #define	CPU_TMLR_MODE		11	/* int: longrun mode
    565    1.1        ad 					 * 0: minimum frequency
    566    1.1        ad 					 * 1: economy
    567    1.1        ad 					 * 2: performance
    568    1.1        ad 					 * 3: maximum frequency
    569    1.1        ad 					 */
    570    1.1        ad #define	CPU_TMLR_FREQUENCY	12	/* int: current frequency */
    571   1.84      maxv #define	CPU_TMLR_VOLTAGE	13	/* int: current voltage */
    572    1.1        ad #define	CPU_TMLR_PERCENTAGE	14	/* int: current clock percentage */
    573   1.69     kamil #define	CPU_FPU_SAVE		15	/* int: FPU Instructions layout
    574   1.69     kamil 					 * to use this, CPU_OSFXSR must be true
    575   1.69     kamil 					 * 0: FSAVE
    576   1.69     kamil 					 * 1: FXSAVE
    577   1.69     kamil 					 * 2: XSAVE
    578   1.69     kamil 					 * 3: XSAVEOPT
    579   1.69     kamil 					 */
    580   1.69     kamil #define	CPU_FPU_SAVE_SIZE	16	/* int: FPU Instruction layout size */
    581   1.69     kamil #define	CPU_XSAVE_FEATURES	17	/* quad: XSAVE features */
    582   1.69     kamil 
    583    1.1        ad /*
    584    1.1        ad  * Structure for CPU_DISKINFO sysctl call.
    585    1.1        ad  * XXX this should be somewhere else.
    586    1.1        ad  */
    587    1.1        ad #define MAX_BIOSDISKS	16
    588    1.1        ad 
    589    1.1        ad struct disklist {
    590    1.1        ad 	int dl_nbiosdisks;			   /* number of bios disks */
    591   1.83  christos 	int dl_unused;
    592    1.1        ad 	struct biosdisk_info {
    593    1.1        ad 		int bi_dev;			   /* BIOS device # (0x80 ..) */
    594    1.1        ad 		int bi_cyl;			   /* cylinders on disk */
    595    1.1        ad 		int bi_head;			   /* heads per track */
    596    1.1        ad 		int bi_sec;			   /* sectors per track */
    597    1.1        ad 		uint64_t bi_lbasecs;		   /* total sec. (iff ext13) */
    598    1.1        ad #define BIFLAG_INVALID		0x01
    599    1.1        ad #define BIFLAG_EXTINT13		0x02
    600    1.1        ad 		int bi_flags;
    601   1.83  christos 		int bi_unused;
    602    1.1        ad 	} dl_biosdisks[MAX_BIOSDISKS];
    603    1.1        ad 
    604    1.1        ad 	int dl_nnativedisks;			   /* number of native disks */
    605    1.1        ad 	struct nativedisk_info {
    606    1.1        ad 		char ni_devname[16];		   /* native device name */
    607    1.1        ad 		int ni_nmatches; 		   /* # of matches w/ BIOS */
    608    1.1        ad 		int ni_biosmatches[MAX_BIOSDISKS]; /* indices in dl_biosdisks */
    609    1.1        ad 	} dl_nativedisks[1];			   /* actually longer */
    610    1.1        ad };
    611    1.1        ad #endif /* !_X86_CPU_H_ */
    612