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