cpu.h revision 1.23
1/* $NetBSD: cpu.h,v 1.23 2007/05/17 14:51:15 yamt Exp $ */ 2 3/*- 4 * Copyright (c) 1990 The Regents of the University of California. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to Berkeley by 8 * William Jolitz. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32 * SUCH DAMAGE. 33 * 34 * @(#)cpu.h 5.4 (Berkeley) 5/9/91 35 */ 36 37#ifndef _AMD64_CPU_H_ 38#define _AMD64_CPU_H_ 39 40#if defined(_KERNEL) 41#if defined(_KERNEL_OPT) 42#include "opt_multiprocessor.h" 43#include "opt_lockdebug.h" 44#endif 45 46/* 47 * Definitions unique to x86-64 cpu support. 48 */ 49#include <machine/frame.h> 50#include <machine/segments.h> 51#include <machine/tss.h> 52#include <machine/intrdefs.h> 53#include <x86/cacheinfo.h> 54 55#include <sys/device.h> 56#include <sys/simplelock.h> 57#include <sys/cpu_data.h> 58#include <sys/cc_microtime.h> 59 60struct cpu_info { 61 struct device *ci_dev; 62 struct cpu_info *ci_self; 63 void *ci_self200; /* self + 0x200, see lock_stubs.S */ 64 struct cpu_data ci_data; /* MI per-cpu data */ 65 struct cc_microtime_state ci_cc;/* cc_microtime state */ 66 struct cpu_info *ci_next; 67 68 struct lwp *ci_curlwp; 69 struct simplelock ci_slock; 70 u_int ci_cpuid; 71 u_int ci_apicid; 72 73 u_int64_t ci_scratch; 74 75 struct lwp *ci_fpcurlwp; 76 int ci_fpsaving; 77 78 volatile u_int32_t ci_tlb_ipi_mask; 79 80 struct intrsource *ci_isources[MAX_INTR_SOURCES]; 81 volatile int ci_mtx_count; /* Negative count of spin mutexes */ 82 volatile int ci_mtx_oldspl; /* Old SPL at this ci_idepth */ 83 84 /* The following must be aligned for cmpxchg8b. */ 85 struct { 86 uint32_t ipending; 87 int ilevel; 88 } ci_istate __aligned(8); 89#define ci_ipending ci_istate.ipending 90#define ci_ilevel ci_istate.ilevel 91 92 int ci_idepth; 93 u_int32_t ci_imask[NIPL]; 94 u_int32_t ci_iunmask[NIPL]; 95 96 paddr_t ci_idle_pcb_paddr; 97 u_int ci_flags; 98 u_int32_t ci_ipis; 99 100 u_int32_t ci_feature_flags; 101 uint32_t ci_feature2_flags; 102 u_int32_t ci_signature; 103 u_int64_t ci_tsc_freq; 104 105 const struct cpu_functions *ci_func; 106 void (*cpu_setup)(struct cpu_info *); 107 void (*ci_info)(struct cpu_info *); 108 109 int ci_want_resched; 110 int ci_astpending; 111 struct trapframe *ci_ddb_regs; 112 113 struct x86_cache_info ci_cinfo[CAI_COUNT]; 114 115 char *ci_gdt; 116 117 struct x86_64_tss ci_doubleflt_tss; 118 struct x86_64_tss ci_ddbipi_tss; 119 120 char *ci_doubleflt_stack; 121 char *ci_ddbipi_stack; 122 123 struct evcnt ci_ipi_events[X86_NIPI]; 124}; 125 126#define CPUF_BSP 0x0001 /* CPU is the original BSP */ 127#define CPUF_AP 0x0002 /* CPU is an AP */ 128#define CPUF_SP 0x0004 /* CPU is only processor */ 129#define CPUF_PRIMARY 0x0008 /* CPU is active primary processor */ 130 131#define CPUF_PRESENT 0x1000 /* CPU is present */ 132#define CPUF_RUNNING 0x2000 /* CPU is running */ 133#define CPUF_PAUSE 0x4000 /* CPU is paused in DDB */ 134#define CPUF_GO 0x8000 /* CPU should start running */ 135 136 137extern struct cpu_info cpu_info_primary; 138extern struct cpu_info *cpu_info_list; 139 140#define CPU_INFO_ITERATOR int 141#define CPU_INFO_FOREACH(cii, ci) cii = 0, ci = cpu_info_list; \ 142 ci != NULL; ci = ci->ci_next 143 144#if defined(MULTIPROCESSOR) 145 146#define X86_MAXPROCS 32 /* bitmask; can be bumped to 64 */ 147 148#define CPU_STARTUP(_ci) ((_ci)->ci_func->start(_ci)) 149#define CPU_STOP(_ci) ((_ci)->ci_func->stop(_ci)) 150#define CPU_START_CLEANUP(_ci) ((_ci)->ci_func->cleanup(_ci)) 151 152#define curcpu() ({struct cpu_info *__ci; \ 153 __asm volatile("movq %%gs:8,%0" : "=r" (__ci)); \ 154 __ci;}) 155#define cpu_number() (curcpu()->ci_cpuid) 156 157#define CPU_IS_PRIMARY(ci) ((ci)->ci_flags & CPUF_PRIMARY) 158 159extern struct cpu_info *cpu_info[X86_MAXPROCS]; 160 161void cpu_boot_secondary_processors(void); 162void cpu_init_idle_lwps(void); 163 164 165#else /* !MULTIPROCESSOR */ 166 167#define X86_MAXPROCS 1 168 169extern struct cpu_info cpu_info_primary; 170 171#define curcpu() (&cpu_info_primary) 172 173/* 174 * definitions of cpu-dependent requirements 175 * referenced in generic code 176 */ 177#define cpu_number() 0 178#define CPU_IS_PRIMARY(ci) 1 179 180#endif 181 182#define aston(l) ((l)->l_md.md_astpending = 1) 183 184extern u_int32_t cpus_attached; 185 186#define curlwp curcpu()->ci_curlwp 187#define curpcb (&curlwp->l_addr->u_pcb) 188 189/* 190 * Arguments to hardclock, softclock and statclock 191 * encapsulate the previous machine state in an opaque 192 * clockframe; for now, use generic intrframe. 193 */ 194struct clockframe { 195 struct intrframe cf_if; 196}; 197 198#define CLKF_USERMODE(frame) USERMODE((frame)->cf_if.if_cs, (frame)->cf_if.if_rflags) 199#define CLKF_PC(frame) ((frame)->cf_if.if_rip) 200#define CLKF_INTR(frame) (curcpu()->ci_idepth > 1) 201 202/* 203 * This is used during profiling to integrate system time. It can safely 204 * assume that the process is resident. 205 */ 206#define LWP_PC(l) ((l)->l_md.md_regs->tf_rip) 207 208/* 209 * Give a profiling tick to the current process when the user profiling 210 * buffer pages are invalid. On the i386, request an ast to send us 211 * through trap(), marking the proc as needing a profiling tick. 212 */ 213extern void cpu_need_proftick(struct lwp *); 214 215/* 216 * Notify an LWP that it has a signal pending, process as soon as possible. 217 */ 218extern void cpu_signotify(struct lwp *); 219 220/* 221 * We need a machine-independent name for this. 222 */ 223extern void (*delay_func)(int); 224 225#define DELAY(x) (*delay_func)(x) 226#define delay(x) (*delay_func)(x) 227 228 229/* 230 * pull in #defines for kinds of processors 231 */ 232 233extern int biosbasemem; 234extern int biosextmem; 235extern int cpu; 236extern int cpu_feature; 237extern int cpu_id; 238extern char cpu_vendor[]; 239extern int cpuid_level; 240 241/* identcpu.c */ 242 243void identifycpu(struct cpu_info *); 244void cpu_probe_features(struct cpu_info *); 245 246/* machdep.c */ 247void dumpconf(void); 248int cpu_maxproc(void); 249void cpu_reset(void); 250void x86_64_proc0_tss_ldt_init(void); 251void x86_64_init_pcb_tss_ldt(struct cpu_info *); 252void cpu_proc_fork(struct proc *, struct proc *); 253void load_fsgs32(uint16_t, uint16_t); 254 255struct region_descriptor; 256void lgdt(struct region_descriptor *); 257void fillw(short, void *, size_t); 258 259struct pcb; 260void savectx(struct pcb *); 261void lwp_trampoline(void); 262void child_trampoline(void); 263 264/* clock.c */ 265void initrtclock(u_long); 266void startrtclock(void); 267void i8254_delay(int); 268void i8254_microtime(struct timeval *); 269void i8254_initclocks(void); 270 271void cpu_init_msrs(struct cpu_info *); 272 273 274/* vm_machdep.c */ 275int kvtop(void *); 276 277/* trap.c */ 278void child_return(void *); 279 280/* consinit.c */ 281void kgdb_port_init(void); 282 283/* bus_machdep.c */ 284void x86_bus_space_init(void); 285void x86_bus_space_mallocok(void); 286 287#endif /* _KERNEL */ 288 289#include <machine/psl.h> 290 291/* 292 * CTL_MACHDEP definitions. 293 */ 294#define CPU_CONSDEV 1 /* dev_t: console terminal device */ 295#define CPU_BIOSBASEMEM 2 /* int: bios-reported base mem (K) */ 296#define CPU_BIOSEXTMEM 3 /* int: bios-reported ext. mem (K) */ 297#define CPU_NKPDE 4 /* int: number of kernel PDEs */ 298#define CPU_BOOTED_KERNEL 5 /* string: booted kernel name */ 299#define CPU_DISKINFO 6 /* disk geometry information */ 300#define CPU_FPU_PRESENT 7 /* FPU is present */ 301#define CPU_MAXID 8 /* number of valid machdep ids */ 302 303#define CTL_MACHDEP_NAMES { \ 304 { 0, 0 }, \ 305 { "console_device", CTLTYPE_STRUCT }, \ 306 { "biosbasemem", CTLTYPE_INT }, \ 307 { "biosextmem", CTLTYPE_INT }, \ 308 { "nkpde", CTLTYPE_INT }, \ 309 { "booted_kernel", CTLTYPE_STRING }, \ 310 { "diskinfo", CTLTYPE_STRUCT }, \ 311 { "fpu_present", CTLTYPE_INT }, \ 312} 313 314 315/* 316 * Structure for CPU_DISKINFO sysctl call. 317 * XXX this should be somewhere else. 318 */ 319#define MAX_BIOSDISKS 16 320 321struct disklist { 322 int dl_nbiosdisks; /* number of bios disks */ 323 struct biosdisk_info { 324 int bi_dev; /* BIOS device # (0x80 ..) */ 325 int bi_cyl; /* cylinders on disk */ 326 int bi_head; /* heads per track */ 327 int bi_sec; /* sectors per track */ 328 u_int64_t bi_lbasecs; /* total sec. (iff ext13) */ 329#define BIFLAG_INVALID 0x01 330#define BIFLAG_EXTINT13 0x02 331 int bi_flags; 332 } dl_biosdisks[MAX_BIOSDISKS]; 333 334 int dl_nnativedisks; /* number of native disks */ 335 struct nativedisk_info { 336 char ni_devname[16]; /* native device name */ 337 int ni_nmatches; /* # of matches w/ BIOS */ 338 int ni_biosmatches[MAX_BIOSDISKS]; /* indices in dl_biosdisks */ 339 } dl_nativedisks[1]; /* actually longer */ 340}; 341 342#endif /* !_AMD64_CPU_H_ */ 343