Home | History | Annotate | Line # | Download | only in include
cpu.h revision 1.70
      1  1.70   msaitoh /*	$NetBSD: cpu.h,v 1.70 2017/05/15 04:02:52 msaitoh Exp $	*/
      2   1.1        ad 
      3   1.1        ad /*-
      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.1        ad #ifdef i386
     51   1.1        ad #include "opt_user_ldt.h"
     52   1.1        ad #include "opt_vm86.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.44    cegger #include <xen/xen-public/xen.h>
     73  1.44    cegger #include <xen/xen-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.1        ad /*
     88   1.1        ad  * a bunch of this belongs in cpuvar.h; move it later..
     89   1.1        ad  */
     90   1.1        ad 
     91   1.1        ad struct cpu_info {
     92  1.26  christos 	struct cpu_data ci_data;	/* MI per-cpu data */
     93  1.19    cegger 	device_t ci_dev;		/* pointer to our device */
     94   1.1        ad 	struct cpu_info *ci_self;	/* self-pointer */
     95   1.1        ad 	volatile struct vcpu_info *ci_vcpu; /* for XEN */
     96   1.1        ad 	void	*ci_tlog_base;		/* Trap log base */
     97   1.1        ad 	int32_t ci_tlog_offset;		/* Trap log current offset */
     98   1.1        ad 
     99   1.1        ad 	/*
    100   1.1        ad 	 * Will be accessed by other CPUs.
    101   1.1        ad 	 */
    102   1.1        ad 	struct cpu_info *ci_next;	/* next cpu */
    103   1.1        ad 	struct lwp *ci_curlwp;		/* current owner of the processor */
    104  1.58  christos 	struct lwp *ci_fpcurlwp;	/* current owner of the FPU */
    105  1.61       dsl 	int	_unused1[2];
    106   1.1        ad 	cpuid_t ci_cpuid;		/* our CPU ID */
    107  1.50     rmind 	int	_unused;
    108  1.24    jruoho 	uint32_t ci_acpiid;		/* our ACPI/MADT ID */
    109  1.19    cegger 	uint32_t ci_initapicid;		/* our intitial APIC ID */
    110   1.1        ad 
    111   1.1        ad 	/*
    112   1.1        ad 	 * Private members.
    113   1.1        ad 	 */
    114   1.1        ad 	struct evcnt ci_tlb_evcnt;	/* tlb shootdown counter */
    115   1.1        ad 	struct pmap *ci_pmap;		/* current pmap */
    116   1.1        ad 	int ci_need_tlbwait;		/* need to wait for TLB invalidations */
    117   1.1        ad 	int ci_want_pmapload;		/* pmap_load() is needed */
    118   1.1        ad 	volatile int ci_tlbstate;	/* one of TLBSTATE_ states. see below */
    119   1.1        ad #define	TLBSTATE_VALID	0	/* all user tlbs are valid */
    120   1.1        ad #define	TLBSTATE_LAZY	1	/* tlbs are valid but won't be kept uptodate */
    121   1.1        ad #define	TLBSTATE_STALE	2	/* we might have stale user tlbs */
    122   1.3        ad 	int ci_curldt;		/* current LDT descriptor */
    123  1.16        ad 	int ci_nintrhand;	/* number of H/W interrupt handlers */
    124   1.1        ad 	uint64_t ci_scratch;
    125  1.35     rmind 	uintptr_t ci_pmap_data[128 / sizeof(uintptr_t)];
    126   1.1        ad 
    127   1.1        ad #ifdef XEN
    128   1.1        ad 	struct iplsource  *ci_isources[NIPL];
    129  1.43    cherry 	u_long ci_evtmask[NR_EVENT_CHANNELS]; /* events allowed on this CPU */
    130   1.1        ad #else
    131   1.1        ad 	struct intrsource *ci_isources[MAX_INTR_SOURCES];
    132   1.1        ad #endif
    133   1.1        ad 	volatile int	ci_mtx_count;	/* Negative count of spin mutexes */
    134   1.1        ad 	volatile int	ci_mtx_oldspl;	/* Old SPL at this ci_idepth */
    135   1.1        ad 
    136  1.68      maxv #ifndef __HAVE_DIRECT_MAP
    137  1.68      maxv #define VPAGE_SRC 0
    138  1.68      maxv #define VPAGE_DST 1
    139  1.68      maxv #define VPAGE_ZER 2
    140  1.68      maxv #define VPAGE_PTP 3
    141  1.68      maxv #define VPAGE_MAX 4
    142  1.68      maxv 	vaddr_t		vpage[VPAGE_MAX];
    143  1.68      maxv 	pt_entry_t	*vpage_pte[VPAGE_MAX];
    144  1.68      maxv #endif
    145  1.68      maxv 
    146   1.1        ad 	/* The following must be aligned for cmpxchg8b. */
    147   1.1        ad 	struct {
    148   1.1        ad 		uint32_t	ipending;
    149   1.1        ad 		int		ilevel;
    150   1.1        ad 	} ci_istate __aligned(8);
    151   1.1        ad #define ci_ipending	ci_istate.ipending
    152   1.1        ad #define	ci_ilevel	ci_istate.ilevel
    153   1.1        ad 
    154   1.1        ad 	int		ci_idepth;
    155   1.1        ad 	void *		ci_intrstack;
    156   1.1        ad 	uint32_t	ci_imask[NIPL];
    157   1.1        ad 	uint32_t	ci_iunmask[NIPL];
    158   1.1        ad 
    159   1.1        ad 	uint32_t ci_flags;		/* flags; see below */
    160   1.1        ad 	uint32_t ci_ipis;		/* interprocessor interrupts pending */
    161  1.19    cegger 	uint32_t sc_apic_version;	/* local APIC version */
    162   1.1        ad 
    163  1.64       dsl 	uint32_t	ci_signature;	 /* X86 cpuid type (cpuid.1.%eax) */
    164   1.1        ad 	uint32_t	ci_vendor[4];	 /* vendor string */
    165  1.64       dsl 	uint32_t	_unused2;
    166  1.64       dsl 	uint32_t	ci_max_cpuid;	/* cpuid.0:%eax */
    167  1.64       dsl 	uint32_t	ci_max_ext_cpuid; /* cpuid.80000000:%eax */
    168   1.1        ad 	volatile uint32_t	ci_lapic_counter;
    169   1.1        ad 
    170  1.67      maxv 	uint32_t	ci_feat_val[7]; /* X86 CPUID feature bits */
    171  1.64       dsl 			/* [0] basic features cpuid.1:%edx
    172  1.64       dsl 			 * [1] basic features cpuid.1:%ecx (CPUID2_xxx bits)
    173  1.64       dsl 			 * [2] extended features cpuid:80000001:%edx
    174  1.64       dsl 			 * [3] extended features cpuid:80000001:%ecx
    175  1.64       dsl 			 * [4] VIA padlock features
    176  1.67      maxv 			 * [5] structured extended features cpuid.7:%ebx
    177  1.67      maxv 			 * [6] structured extended features cpuid.7:%ecx
    178  1.64       dsl 			 */
    179  1.21       jym 
    180   1.1        ad 	const struct cpu_functions *ci_func;  /* start/stop functions */
    181   1.1        ad 	struct trapframe *ci_ddb_regs;
    182   1.1        ad 
    183  1.70   msaitoh 	u_int ci_cflush_lsize;	/* CLFLUSH insn line size */
    184   1.1        ad 	struct x86_cache_info ci_cinfo[CAI_COUNT];
    185   1.1        ad 
    186   1.1        ad 	union descriptor *ci_gdt;
    187   1.1        ad 
    188   1.1        ad #ifdef i386
    189   1.1        ad 	struct i386tss	ci_doubleflt_tss;
    190   1.1        ad 	struct i386tss	ci_ddbipi_tss;
    191   1.1        ad #endif
    192  1.23       jym 
    193  1.23       jym #ifdef PAE
    194  1.45    cherry 	uint32_t	ci_pae_l3_pdirpa; /* PA of L3 PD */
    195  1.23       jym 	pd_entry_t *	ci_pae_l3_pdir; /* VA pointer to L3 PD */
    196  1.23       jym #endif
    197  1.23       jym 
    198  1.41    cherry #if defined(XEN) && (defined(PAE) || defined(__x86_64__))
    199  1.23       jym 	/* Currently active user PGD (can't use rcr3() with Xen) */
    200  1.41    cherry 	pd_entry_t *	ci_kpm_pdir;	/* per-cpu PMD (va) */
    201  1.46    cherry 	paddr_t		ci_kpm_pdirpa;  /* per-cpu PMD (pa) */
    202  1.48    bouyer 	kmutex_t	ci_kpm_mtx;
    203  1.41    cherry #if defined(__x86_64__)
    204  1.46    cherry 	/* per-cpu version of normal_pdes */
    205  1.46    cherry 	pd_entry_t *	ci_normal_pdes[3]; /* Ok to hardcode. only for x86_64 && XEN */
    206  1.23       jym 	paddr_t		ci_xen_current_user_pgd;
    207  1.41    cherry #endif /* __x86_64__ */
    208  1.41    cherry #endif /* XEN et.al */
    209  1.41    cherry 
    210   1.1        ad 	char *ci_doubleflt_stack;
    211   1.1        ad 	char *ci_ddbipi_stack;
    212   1.1        ad 
    213  1.36    cherry #ifndef XEN
    214   1.1        ad 	struct evcnt ci_ipi_events[X86_NIPI];
    215  1.36    cherry #else   /* XEN */
    216  1.36    cherry 	struct evcnt ci_ipi_events[XEN_NIPIS];
    217  1.36    cherry 	evtchn_port_t ci_ipi_evtchn;
    218  1.36    cherry #endif  /* XEN */
    219   1.1        ad 
    220  1.30    jruoho 	device_t	ci_frequency;	/* Frequency scaling technology */
    221  1.27  jmcneill 	device_t	ci_padlock;	/* VIA PadLock private storage */
    222  1.31    jruoho 	device_t	ci_temperature;	/* Intel coretemp(4) or equivalent */
    223  1.39  jmcneill 	device_t	ci_vm;		/* Virtual machine guest driver */
    224   1.1        ad 
    225   1.1        ad 	struct i386tss	ci_tss;		/* Per-cpu TSS; shared among LWPs */
    226   1.1        ad 	char		ci_iomap[IOMAPSIZE]; /* I/O Bitmap */
    227   1.1        ad 	int ci_tss_sel;			/* TSS selector of this cpu */
    228   1.1        ad 
    229   1.1        ad 	/*
    230   1.1        ad 	 * The following two are actually region_descriptors,
    231   1.1        ad 	 * but that would pollute the namespace.
    232   1.1        ad 	 */
    233   1.1        ad 	uintptr_t	ci_suspend_gdt;
    234   1.1        ad 	uint16_t	ci_suspend_gdt_padding;
    235   1.1        ad 	uintptr_t	ci_suspend_idt;
    236   1.1        ad 	uint16_t	ci_suspend_idt_padding;
    237   1.1        ad 
    238   1.1        ad 	uint16_t	ci_suspend_tr;
    239   1.1        ad 	uint16_t	ci_suspend_ldt;
    240   1.1        ad 	uintptr_t	ci_suspend_fs;
    241   1.1        ad 	uintptr_t	ci_suspend_gs;
    242   1.1        ad 	uintptr_t	ci_suspend_kgs;
    243   1.1        ad 	uintptr_t	ci_suspend_efer;
    244   1.1        ad 	uintptr_t	ci_suspend_reg[12];
    245   1.1        ad 	uintptr_t	ci_suspend_cr0;
    246   1.1        ad 	uintptr_t	ci_suspend_cr2;
    247   1.1        ad 	uintptr_t	ci_suspend_cr3;
    248   1.1        ad 	uintptr_t	ci_suspend_cr4;
    249   1.1        ad 	uintptr_t	ci_suspend_cr8;
    250   1.1        ad 
    251   1.1        ad 	/* The following must be in a single cache line. */
    252   1.1        ad 	int		ci_want_resched __aligned(64);
    253   1.1        ad 	int		ci_padout __aligned(64);
    254   1.1        ad };
    255   1.1        ad 
    256   1.1        ad /*
    257  1.15     rmind  * Macros to handle (some) trapframe registers for common x86 code.
    258  1.15     rmind  */
    259  1.15     rmind #ifdef __x86_64__
    260  1.15     rmind #define	X86_TF_RAX(tf)		tf->tf_rax
    261  1.15     rmind #define	X86_TF_RDX(tf)		tf->tf_rdx
    262  1.15     rmind #define	X86_TF_RSP(tf)		tf->tf_rsp
    263  1.15     rmind #define	X86_TF_RIP(tf)		tf->tf_rip
    264  1.15     rmind #define	X86_TF_RFLAGS(tf)	tf->tf_rflags
    265  1.15     rmind #else
    266  1.15     rmind #define	X86_TF_RAX(tf)		tf->tf_eax
    267  1.15     rmind #define	X86_TF_RDX(tf)		tf->tf_edx
    268  1.15     rmind #define	X86_TF_RSP(tf)		tf->tf_esp
    269  1.15     rmind #define	X86_TF_RIP(tf)		tf->tf_eip
    270  1.15     rmind #define	X86_TF_RFLAGS(tf)	tf->tf_eflags
    271  1.15     rmind #endif
    272  1.15     rmind 
    273  1.15     rmind /*
    274   1.1        ad  * Processor flag notes: The "primary" CPU has certain MI-defined
    275   1.1        ad  * roles (mostly relating to hardclock handling); we distinguish
    276   1.1        ad  * betwen the processor which booted us, and the processor currently
    277   1.1        ad  * holding the "primary" role just to give us the flexibility later to
    278   1.1        ad  * change primaries should we be sufficiently twisted.
    279   1.1        ad  */
    280   1.1        ad 
    281   1.1        ad #define	CPUF_BSP	0x0001		/* CPU is the original BSP */
    282   1.1        ad #define	CPUF_AP		0x0002		/* CPU is an AP */
    283   1.1        ad #define	CPUF_SP		0x0004		/* CPU is only processor */
    284   1.1        ad #define	CPUF_PRIMARY	0x0008		/* CPU is active primary processor */
    285   1.1        ad 
    286   1.1        ad #define	CPUF_SYNCTSC	0x0800		/* Synchronize TSC */
    287   1.1        ad #define	CPUF_PRESENT	0x1000		/* CPU is present */
    288   1.1        ad #define	CPUF_RUNNING	0x2000		/* CPU is running */
    289   1.1        ad #define	CPUF_PAUSE	0x4000		/* CPU is paused in DDB */
    290   1.1        ad #define	CPUF_GO		0x8000		/* CPU should start running */
    291   1.1        ad 
    292  1.40     joerg #endif /* _KERNEL || __KMEMUSER */
    293  1.40     joerg 
    294  1.40     joerg #ifdef _KERNEL
    295   1.1        ad /*
    296   1.1        ad  * We statically allocate the CPU info for the primary CPU (or,
    297   1.1        ad  * the only CPU on uniprocessors), and the primary CPU is the
    298   1.1        ad  * first CPU on the CPU info list.
    299   1.1        ad  */
    300   1.1        ad extern struct cpu_info cpu_info_primary;
    301   1.1        ad extern struct cpu_info *cpu_info_list;
    302   1.1        ad 
    303  1.57  christos #define	CPU_INFO_ITERATOR		int __unused
    304  1.57  christos #define	CPU_INFO_FOREACH(cii, ci)	ci = cpu_info_list; \
    305   1.1        ad 					ci != NULL; ci = ci->ci_next
    306   1.1        ad 
    307   1.1        ad #define CPU_STARTUP(_ci, _target)	((_ci)->ci_func->start(_ci, _target))
    308   1.1        ad #define CPU_STOP(_ci)	        	((_ci)->ci_func->stop(_ci))
    309   1.1        ad #define CPU_START_CLEANUP(_ci)		((_ci)->ci_func->cleanup(_ci))
    310   1.1        ad 
    311  1.10     pooka #if !defined(__GNUC__) || defined(_MODULE)
    312   1.1        ad /* For non-GCC and modules */
    313   1.1        ad struct cpu_info	*x86_curcpu(void);
    314   1.1        ad void	cpu_set_curpri(int);
    315   1.5        ad # ifdef __GNUC__
    316   1.5        ad lwp_t	*x86_curlwp(void) __attribute__ ((const));
    317   1.5        ad # else
    318   1.5        ad lwp_t   *x86_curlwp(void);
    319   1.5        ad # endif
    320   1.1        ad #endif
    321   1.1        ad 
    322   1.4        ad #define cpu_number() 		(cpu_index(curcpu()))
    323   1.1        ad 
    324   1.1        ad #define CPU_IS_PRIMARY(ci)	((ci)->ci_flags & CPUF_PRIMARY)
    325   1.1        ad 
    326   1.1        ad #define	X86_AST_GENERIC		0x01
    327   1.1        ad #define	X86_AST_PREEMPT		0x02
    328   1.1        ad 
    329   1.1        ad #define aston(l, why)		((l)->l_md.md_astpending |= (why))
    330   1.1        ad #define	cpu_did_resched(l)	((l)->l_md.md_astpending &= ~X86_AST_PREEMPT)
    331   1.1        ad 
    332   1.1        ad void cpu_boot_secondary_processors(void);
    333   1.1        ad void cpu_init_idle_lwps(void);
    334   1.1        ad void cpu_init_msrs(struct cpu_info *, bool);
    335  1.48    bouyer void cpu_load_pmap(struct pmap *, struct pmap *);
    336  1.37    cherry void cpu_broadcast_halt(void);
    337  1.37    cherry void cpu_kick(struct cpu_info *);
    338   1.1        ad 
    339   1.1        ad #define	curcpu()		x86_curcpu()
    340   1.1        ad #define	curlwp			x86_curlwp()
    341  1.18     rmind #define	curpcb			((struct pcb *)lwp_getpcb(curlwp))
    342   1.1        ad 
    343   1.1        ad /*
    344   1.1        ad  * Arguments to hardclock, softclock and statclock
    345   1.1        ad  * encapsulate the previous machine state in an opaque
    346   1.1        ad  * clockframe; for now, use generic intrframe.
    347   1.1        ad  */
    348   1.1        ad struct clockframe {
    349   1.1        ad 	struct intrframe cf_if;
    350   1.1        ad };
    351   1.1        ad 
    352   1.1        ad /*
    353   1.1        ad  * Give a profiling tick to the current process when the user profiling
    354   1.1        ad  * buffer pages are invalid.  On the i386, request an ast to send us
    355   1.1        ad  * through trap(), marking the proc as needing a profiling tick.
    356   1.1        ad  */
    357   1.1        ad extern void	cpu_need_proftick(struct lwp *l);
    358   1.1        ad 
    359   1.1        ad /*
    360   1.1        ad  * Notify the LWP l that it has a signal pending, process as soon as
    361   1.1        ad  * possible.
    362   1.1        ad  */
    363   1.1        ad extern void	cpu_signotify(struct lwp *);
    364   1.1        ad 
    365   1.1        ad /*
    366   1.1        ad  * We need a machine-independent name for this.
    367   1.1        ad  */
    368   1.1        ad extern void (*delay_func)(unsigned int);
    369   1.1        ad struct timeval;
    370   1.1        ad 
    371   1.1        ad #define	DELAY(x)		(*delay_func)(x)
    372   1.1        ad #define delay(x)		(*delay_func)(x)
    373   1.1        ad 
    374   1.1        ad extern int biosbasemem;
    375   1.1        ad extern int biosextmem;
    376  1.51       chs extern int cputype;
    377   1.1        ad extern int cpuid_level;
    378   1.1        ad extern int cpu_class;
    379   1.1        ad extern char cpu_brand_string[];
    380  1.42       jym extern int use_pae;
    381   1.1        ad 
    382  1.61       dsl #ifdef __i386__
    383  1.61       dsl extern int i386_fpu_present;
    384  1.61       dsl int npx586bug1(int, int);
    385  1.61       dsl extern int i386_fpu_fdivbug;
    386   1.1        ad extern int i386_use_fxsave;
    387   1.1        ad extern int i386_has_sse;
    388   1.1        ad extern int i386_has_sse2;
    389  1.61       dsl #else
    390  1.61       dsl #define	i386_fpu_present	1
    391  1.61       dsl #define	i386_fpu_fdivbug	0
    392  1.61       dsl #define	i386_use_fxsave		1
    393  1.61       dsl #define	i386_has_sse		1
    394  1.61       dsl #define	i386_has_sse2		1
    395  1.61       dsl #endif
    396   1.1        ad 
    397  1.65       dsl extern int x86_fpu_save;
    398  1.65       dsl #define	FPU_SAVE_FSAVE		0
    399  1.65       dsl #define	FPU_SAVE_FXSAVE		1
    400  1.65       dsl #define	FPU_SAVE_XSAVE		2
    401  1.65       dsl #define	FPU_SAVE_XSAVEOPT	3
    402  1.66       dsl extern unsigned int x86_fpu_save_size;
    403  1.65       dsl extern uint64_t x86_xsave_features;
    404  1.65       dsl 
    405   1.1        ad extern void (*x86_cpu_idle)(void);
    406   1.1        ad #define	cpu_idle() (*x86_cpu_idle)()
    407   1.1        ad 
    408   1.1        ad /* machdep.c */
    409   1.1        ad void	dumpconf(void);
    410   1.1        ad void	cpu_reset(void);
    411   1.1        ad void	i386_proc0_tss_ldt_init(void);
    412   1.1        ad void	dumpconf(void);
    413   1.1        ad void	cpu_reset(void);
    414   1.1        ad void	x86_64_proc0_tss_ldt_init(void);
    415   1.1        ad void	x86_64_init_pcb_tss_ldt(struct cpu_info *);
    416   1.1        ad 
    417   1.1        ad /* longrun.c */
    418   1.1        ad u_int 	tmx86_get_longrun_mode(void);
    419   1.1        ad void 	tmx86_get_longrun_status(u_int *, u_int *, u_int *);
    420   1.1        ad void 	tmx86_init_longrun(void);
    421   1.1        ad 
    422   1.1        ad /* identcpu.c */
    423   1.1        ad void 	cpu_probe(struct cpu_info *);
    424   1.1        ad void	cpu_identify(struct cpu_info *);
    425   1.1        ad 
    426  1.17     rmind /* cpu_topology.c */
    427  1.20     rmind void	x86_cpu_topology(struct cpu_info *);
    428  1.17     rmind 
    429   1.1        ad /* vm_machdep.c */
    430   1.1        ad void	cpu_proc_fork(struct proc *, struct proc *);
    431   1.1        ad 
    432   1.1        ad /* locore.s */
    433   1.1        ad struct region_descriptor;
    434   1.1        ad void	lgdt(struct region_descriptor *);
    435   1.1        ad #ifdef XEN
    436   1.1        ad void	lgdt_finish(void);
    437   1.1        ad #endif
    438   1.1        ad 
    439   1.1        ad struct pcb;
    440   1.1        ad void	savectx(struct pcb *);
    441   1.1        ad void	lwp_trampoline(void);
    442   1.1        ad #ifdef XEN
    443   1.1        ad void	startrtclock(void);
    444   1.1        ad void	xen_delay(unsigned int);
    445   1.1        ad void	xen_initclocks(void);
    446  1.47       jym void	xen_suspendclocks(struct cpu_info *);
    447  1.47       jym void	xen_resumeclocks(struct cpu_info *);
    448   1.1        ad #else
    449   1.1        ad /* clock.c */
    450   1.1        ad void	initrtclock(u_long);
    451   1.1        ad void	startrtclock(void);
    452   1.1        ad void	i8254_delay(unsigned int);
    453   1.1        ad void	i8254_microtime(struct timeval *);
    454   1.1        ad void	i8254_initclocks(void);
    455   1.1        ad #endif
    456   1.1        ad 
    457   1.1        ad /* cpu.c */
    458   1.1        ad 
    459   1.1        ad void	cpu_probe_features(struct cpu_info *);
    460   1.1        ad 
    461   1.1        ad /* vm_machdep.c */
    462  1.13     rmind paddr_t	kvtop(void *);
    463   1.1        ad 
    464   1.1        ad #ifdef USER_LDT
    465   1.1        ad /* sys_machdep.h */
    466   1.1        ad int	x86_get_ldt(struct lwp *, void *, register_t *);
    467   1.1        ad int	x86_set_ldt(struct lwp *, void *, register_t *);
    468   1.1        ad #endif
    469   1.1        ad 
    470   1.1        ad /* isa_machdep.c */
    471   1.1        ad void	isa_defaultirq(void);
    472   1.1        ad int	isa_nmi(void);
    473   1.1        ad 
    474   1.1        ad #ifdef VM86
    475   1.1        ad /* vm86.c */
    476   1.1        ad void	vm86_gpfault(struct lwp *, int);
    477   1.1        ad #endif /* VM86 */
    478   1.1        ad 
    479   1.1        ad /* consinit.c */
    480   1.1        ad void kgdb_port_init(void);
    481   1.1        ad 
    482   1.1        ad /* bus_machdep.c */
    483   1.1        ad void x86_bus_space_init(void);
    484   1.1        ad void x86_bus_space_mallocok(void);
    485   1.1        ad 
    486  1.40     joerg #endif /* _KERNEL */
    487  1.40     joerg 
    488  1.40     joerg #if defined(_KERNEL) || defined(_KMEMUSER)
    489   1.1        ad #include <machine/psl.h>	/* Must be after struct cpu_info declaration */
    490  1.11        ad #endif /* _KERNEL || __KMEMUSER */
    491   1.1        ad 
    492   1.1        ad /*
    493   1.1        ad  * CTL_MACHDEP definitions.
    494   1.1        ad  */
    495   1.1        ad #define	CPU_CONSDEV		1	/* dev_t: console terminal device */
    496   1.1        ad #define	CPU_BIOSBASEMEM		2	/* int: bios-reported base mem (K) */
    497   1.1        ad #define	CPU_BIOSEXTMEM		3	/* int: bios-reported ext. mem (K) */
    498   1.1        ad /* 	CPU_NKPDE		4	obsolete: int: number of kernel PDEs */
    499   1.1        ad #define	CPU_BOOTED_KERNEL	5	/* string: booted kernel name */
    500   1.1        ad #define CPU_DISKINFO		6	/* struct disklist *:
    501   1.1        ad 					 * disk geometry information */
    502   1.1        ad #define CPU_FPU_PRESENT		7	/* int: FPU is present */
    503   1.1        ad #define	CPU_OSFXSR		8	/* int: OS uses FXSAVE/FXRSTOR */
    504   1.1        ad #define	CPU_SSE			9	/* int: OS/CPU supports SSE */
    505   1.1        ad #define	CPU_SSE2		10	/* int: OS/CPU supports SSE2 */
    506   1.1        ad #define	CPU_TMLR_MODE		11	/* int: longrun mode
    507   1.1        ad 					 * 0: minimum frequency
    508   1.1        ad 					 * 1: economy
    509   1.1        ad 					 * 2: performance
    510   1.1        ad 					 * 3: maximum frequency
    511   1.1        ad 					 */
    512   1.1        ad #define	CPU_TMLR_FREQUENCY	12	/* int: current frequency */
    513   1.1        ad #define	CPU_TMLR_VOLTAGE	13	/* int: curret voltage */
    514   1.1        ad #define	CPU_TMLR_PERCENTAGE	14	/* int: current clock percentage */
    515  1.69     kamil #define	CPU_FPU_SAVE		15	/* int: FPU Instructions layout
    516  1.69     kamil 					 * to use this, CPU_OSFXSR must be true
    517  1.69     kamil 					 * 0: FSAVE
    518  1.69     kamil 					 * 1: FXSAVE
    519  1.69     kamil 					 * 2: XSAVE
    520  1.69     kamil 					 * 3: XSAVEOPT
    521  1.69     kamil 					 */
    522  1.69     kamil #define	CPU_FPU_SAVE_SIZE	16	/* int: FPU Instruction layout size */
    523  1.69     kamil #define	CPU_XSAVE_FEATURES	17	/* quad: XSAVE features */
    524  1.69     kamil 
    525  1.69     kamil #define	CPU_MAXID		18	/* number of valid machdep ids */
    526   1.1        ad 
    527   1.1        ad /*
    528   1.1        ad  * Structure for CPU_DISKINFO sysctl call.
    529   1.1        ad  * XXX this should be somewhere else.
    530   1.1        ad  */
    531   1.1        ad #define MAX_BIOSDISKS	16
    532   1.1        ad 
    533   1.1        ad struct disklist {
    534   1.1        ad 	int dl_nbiosdisks;			   /* number of bios disks */
    535   1.1        ad 	struct biosdisk_info {
    536   1.1        ad 		int bi_dev;			   /* BIOS device # (0x80 ..) */
    537   1.1        ad 		int bi_cyl;			   /* cylinders on disk */
    538   1.1        ad 		int bi_head;			   /* heads per track */
    539   1.1        ad 		int bi_sec;			   /* sectors per track */
    540   1.1        ad 		uint64_t bi_lbasecs;		   /* total sec. (iff ext13) */
    541   1.1        ad #define BIFLAG_INVALID		0x01
    542   1.1        ad #define BIFLAG_EXTINT13		0x02
    543   1.1        ad 		int bi_flags;
    544   1.1        ad 	} dl_biosdisks[MAX_BIOSDISKS];
    545   1.1        ad 
    546   1.1        ad 	int dl_nnativedisks;			   /* number of native disks */
    547   1.1        ad 	struct nativedisk_info {
    548   1.1        ad 		char ni_devname[16];		   /* native device name */
    549   1.1        ad 		int ni_nmatches; 		   /* # of matches w/ BIOS */
    550   1.1        ad 		int ni_biosmatches[MAX_BIOSDISKS]; /* indices in dl_biosdisks */
    551   1.1        ad 	} dl_nativedisks[1];			   /* actually longer */
    552   1.1        ad };
    553   1.1        ad #endif /* !_X86_CPU_H_ */
    554