cpu.h revision 1.5
11.5Syamt/* $NetBSD: cpu.h,v 1.5 2004/09/25 03:05:23 yamt Exp $ */ 21.1Sfvdl 31.1Sfvdl/*- 41.1Sfvdl * Copyright (c) 1990 The Regents of the University of California. 51.1Sfvdl * All rights reserved. 61.1Sfvdl * 71.1Sfvdl * This code is derived from software contributed to Berkeley by 81.1Sfvdl * William Jolitz. 91.1Sfvdl * 101.1Sfvdl * Redistribution and use in source and binary forms, with or without 111.1Sfvdl * modification, are permitted provided that the following conditions 121.1Sfvdl * are met: 131.1Sfvdl * 1. Redistributions of source code must retain the above copyright 141.1Sfvdl * notice, this list of conditions and the following disclaimer. 151.1Sfvdl * 2. Redistributions in binary form must reproduce the above copyright 161.1Sfvdl * notice, this list of conditions and the following disclaimer in the 171.1Sfvdl * documentation and/or other materials provided with the distribution. 181.2Sagc * 3. Neither the name of the University nor the names of its contributors 191.1Sfvdl * may be used to endorse or promote products derived from this software 201.1Sfvdl * without specific prior written permission. 211.1Sfvdl * 221.1Sfvdl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 231.1Sfvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 241.1Sfvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 251.1Sfvdl * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 261.1Sfvdl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 271.1Sfvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 281.1Sfvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 291.1Sfvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 301.1Sfvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 311.1Sfvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 321.1Sfvdl * SUCH DAMAGE. 331.1Sfvdl * 341.1Sfvdl * @(#)cpu.h 5.4 (Berkeley) 5/9/91 351.1Sfvdl */ 361.1Sfvdl 371.1Sfvdl#ifndef _AMD64_CPU_H_ 381.1Sfvdl#define _AMD64_CPU_H_ 391.1Sfvdl 401.1Sfvdl#if defined(_KERNEL_OPT) 411.1Sfvdl#include "opt_multiprocessor.h" 421.1Sfvdl#include "opt_lockdebug.h" 431.1Sfvdl#endif 441.1Sfvdl 451.1Sfvdl/* 461.1Sfvdl * Definitions unique to x86-64 cpu support. 471.1Sfvdl */ 481.1Sfvdl#include <machine/frame.h> 491.1Sfvdl#include <machine/segments.h> 501.1Sfvdl#include <machine/tss.h> 511.1Sfvdl#include <machine/intrdefs.h> 521.1Sfvdl#include <x86/cacheinfo.h> 531.1Sfvdl 541.1Sfvdl#include <sys/device.h> 551.1Sfvdl#include <sys/lock.h> 561.4Syamt#include <sys/cpu_data.h> 571.4Syamt#include <sys/cc_microtime.h> 581.1Sfvdl 591.1Sfvdlstruct cpu_info { 601.1Sfvdl struct device *ci_dev; 611.1Sfvdl struct cpu_info *ci_self; 621.4Syamt struct cpu_data ci_data; /* MI per-cpu data */ 631.5Syamt struct cc_microtime_state ci_cc;/* cc_microtime state */ 641.1Sfvdl struct cpu_info *ci_next; 651.1Sfvdl 661.1Sfvdl struct lwp *ci_curlwp; 671.1Sfvdl struct simplelock ci_slock; 681.1Sfvdl u_int ci_cpuid; 691.1Sfvdl u_int ci_apicid; 701.1Sfvdl 711.1Sfvdl u_int64_t ci_scratch; 721.1Sfvdl 731.1Sfvdl struct lwp *ci_fpcurlwp; 741.1Sfvdl int ci_fpsaving; 751.1Sfvdl 761.1Sfvdl volatile u_int32_t ci_tlb_ipi_mask; 771.1Sfvdl 781.1Sfvdl struct pcb *ci_curpcb; 791.1Sfvdl struct pcb *ci_idle_pcb; 801.1Sfvdl int ci_idle_tss_sel; 811.1Sfvdl 821.1Sfvdl struct intrsource *ci_isources[MAX_INTR_SOURCES]; 831.1Sfvdl u_int32_t ci_ipending; 841.1Sfvdl int ci_ilevel; 851.1Sfvdl int ci_idepth; 861.1Sfvdl u_int32_t ci_imask[NIPL]; 871.1Sfvdl u_int32_t ci_iunmask[NIPL]; 881.1Sfvdl 891.1Sfvdl paddr_t ci_idle_pcb_paddr; 901.1Sfvdl u_int ci_flags; 911.1Sfvdl u_int32_t ci_ipis; 921.1Sfvdl 931.1Sfvdl u_int32_t ci_feature_flags; 941.1Sfvdl u_int32_t ci_signature; 951.1Sfvdl u_int64_t ci_tsc_freq; 961.1Sfvdl 971.1Sfvdl struct cpu_functions *ci_func; 981.1Sfvdl void (*cpu_setup) __P((struct cpu_info *)); 991.1Sfvdl void (*ci_info) __P((struct cpu_info *)); 1001.1Sfvdl 1011.1Sfvdl int ci_want_resched; 1021.1Sfvdl int ci_astpending; 1031.1Sfvdl struct trapframe *ci_ddb_regs; 1041.1Sfvdl 1051.1Sfvdl struct x86_cache_info ci_cinfo[CAI_COUNT]; 1061.1Sfvdl 1071.1Sfvdl char *ci_gdt; 1081.1Sfvdl 1091.1Sfvdl struct x86_64_tss ci_doubleflt_tss; 1101.1Sfvdl struct x86_64_tss ci_ddbipi_tss; 1111.1Sfvdl 1121.1Sfvdl char *ci_doubleflt_stack; 1131.1Sfvdl char *ci_ddbipi_stack; 1141.1Sfvdl 1151.1Sfvdl struct evcnt ci_ipi_events[X86_NIPI]; 1161.1Sfvdl}; 1171.1Sfvdl 1181.1Sfvdl#define CPUF_BSP 0x0001 /* CPU is the original BSP */ 1191.1Sfvdl#define CPUF_AP 0x0002 /* CPU is an AP */ 1201.1Sfvdl#define CPUF_SP 0x0004 /* CPU is only processor */ 1211.1Sfvdl#define CPUF_PRIMARY 0x0008 /* CPU is active primary processor */ 1221.1Sfvdl 1231.1Sfvdl#define CPUF_PRESENT 0x1000 /* CPU is present */ 1241.1Sfvdl#define CPUF_RUNNING 0x2000 /* CPU is running */ 1251.1Sfvdl#define CPUF_PAUSE 0x4000 /* CPU is paused in DDB */ 1261.1Sfvdl#define CPUF_GO 0x8000 /* CPU should start running */ 1271.1Sfvdl 1281.1Sfvdl 1291.1Sfvdlextern struct cpu_info cpu_info_primary; 1301.1Sfvdlextern struct cpu_info *cpu_info_list; 1311.1Sfvdl 1321.1Sfvdl#define CPU_INFO_ITERATOR int 1331.1Sfvdl#define CPU_INFO_FOREACH(cii, ci) cii = 0, ci = cpu_info_list; \ 1341.1Sfvdl ci != NULL; ci = ci->ci_next 1351.1Sfvdl 1361.1Sfvdl#if defined(MULTIPROCESSOR) 1371.1Sfvdl 1381.1Sfvdl#define X86_MAXPROCS 32 /* bitmask; can be bumped to 64 */ 1391.1Sfvdl 1401.1Sfvdl#define CPU_STARTUP(_ci) ((_ci)->ci_func->start(_ci)) 1411.1Sfvdl#define CPU_STOP(_ci) ((_ci)->ci_func->stop(_ci)) 1421.1Sfvdl#define CPU_START_CLEANUP(_ci) ((_ci)->ci_func->cleanup(_ci)) 1431.1Sfvdl 1441.1Sfvdl#define curcpu() ({struct cpu_info *__ci; \ 1451.1Sfvdl asm volatile("movq %%gs:8,%0" : "=r" (__ci)); \ 1461.1Sfvdl __ci;}) 1471.1Sfvdl#define cpu_number() (curcpu()->ci_cpuid) 1481.1Sfvdl 1491.1Sfvdl#define CPU_IS_PRIMARY(ci) ((ci)->ci_flags & CPUF_PRIMARY) 1501.1Sfvdl 1511.1Sfvdlextern struct cpu_info *cpu_info[X86_MAXPROCS]; 1521.1Sfvdl 1531.1Sfvdlvoid cpu_boot_secondary_processors __P((void)); 1541.1Sfvdlvoid cpu_init_idle_pcbs __P((void)); 1551.1Sfvdl 1561.1Sfvdl 1571.1Sfvdl/* 1581.1Sfvdl * Preempt the current process if in interrupt from user mode, 1591.1Sfvdl * or after the current trap/syscall if in system mode. 1601.1Sfvdl */ 1611.1Sfvdlextern void need_resched __P((struct cpu_info *)); 1621.1Sfvdl 1631.1Sfvdl#else /* !MULTIPROCESSOR */ 1641.1Sfvdl 1651.1Sfvdl#define X86_MAXPROCS 1 1661.1Sfvdl 1671.1Sfvdl#ifdef _KERNEL 1681.1Sfvdlextern struct cpu_info cpu_info_primary; 1691.1Sfvdl 1701.1Sfvdl#define curcpu() (&cpu_info_primary) 1711.1Sfvdl 1721.1Sfvdl#endif 1731.1Sfvdl 1741.1Sfvdl/* 1751.1Sfvdl * definitions of cpu-dependent requirements 1761.1Sfvdl * referenced in generic code 1771.1Sfvdl */ 1781.1Sfvdl#define cpu_number() 0 1791.1Sfvdl#define CPU_IS_PRIMARY(ci) 1 1801.1Sfvdl 1811.1Sfvdl/* 1821.1Sfvdl * Preempt the current process if in interrupt from user mode, 1831.1Sfvdl * or after the current trap/syscall if in system mode. 1841.1Sfvdl */ 1851.1Sfvdl 1861.1Sfvdl#define need_resched(ci) \ 1871.1Sfvdldo { \ 1881.1Sfvdl struct cpu_info *__ci = (ci); \ 1891.1Sfvdl __ci->ci_want_resched = 1; \ 1901.1Sfvdl if (__ci->ci_curlwp != NULL) \ 1911.1Sfvdl aston(__ci->ci_curlwp->l_proc); \ 1921.1Sfvdl} while (/*CONSTCOND*/0) 1931.1Sfvdl 1941.1Sfvdl#endif 1951.1Sfvdl 1961.1Sfvdl#define aston(p) ((p)->p_md.md_astpending = 1) 1971.1Sfvdl 1981.1Sfvdlextern u_int32_t cpus_attached; 1991.1Sfvdl 2001.1Sfvdl#define curpcb curcpu()->ci_curpcb 2011.1Sfvdl#define curlwp curcpu()->ci_curlwp 2021.1Sfvdl 2031.1Sfvdl/* 2041.1Sfvdl * Arguments to hardclock, softclock and statclock 2051.1Sfvdl * encapsulate the previous machine state in an opaque 2061.1Sfvdl * clockframe; for now, use generic intrframe. 2071.1Sfvdl */ 2081.1Sfvdl#define clockframe intrframe 2091.1Sfvdl 2101.1Sfvdl#define CLKF_USERMODE(frame) USERMODE((frame)->if_cs, (frame)->if_rflags) 2111.1Sfvdl#define CLKF_BASEPRI(frame) (0) 2121.1Sfvdl#define CLKF_PC(frame) ((frame)->if_rip) 2131.1Sfvdl#define CLKF_INTR(frame) (curcpu()->ci_idepth > 1) 2141.1Sfvdl 2151.1Sfvdl/* 2161.1Sfvdl * This is used during profiling to integrate system time. It can safely 2171.1Sfvdl * assume that the process is resident. 2181.1Sfvdl */ 2191.1Sfvdl#define LWP_PC(l) ((l)->l_md.md_regs->tf_rip) 2201.1Sfvdl 2211.1Sfvdl/* 2221.1Sfvdl * Give a profiling tick to the current process when the user profiling 2231.1Sfvdl * buffer pages are invalid. On the i386, request an ast to send us 2241.1Sfvdl * through trap(), marking the proc as needing a profiling tick. 2251.1Sfvdl */ 2261.1Sfvdl#define need_proftick(p) ((p)->p_flag |= P_OWEUPC, aston(p)) 2271.1Sfvdl 2281.1Sfvdl/* 2291.1Sfvdl * Notify the current process (p) that it has a signal pending, 2301.1Sfvdl * process as soon as possible. 2311.1Sfvdl */ 2321.1Sfvdl#define signotify(p) aston(p) 2331.1Sfvdl 2341.1Sfvdl/* 2351.1Sfvdl * We need a machine-independent name for this. 2361.1Sfvdl */ 2371.1Sfvdlextern void (*delay_func) __P((int)); 2381.1Sfvdlstruct timeval; 2391.1Sfvdlextern void (*microtime_func) __P((struct timeval *)); 2401.1Sfvdl 2411.1Sfvdl#define DELAY(x) (*delay_func)(x) 2421.1Sfvdl#define delay(x) (*delay_func)(x) 2431.1Sfvdl#define microtime(tv) (*microtime_func)(tv) 2441.1Sfvdl 2451.1Sfvdl 2461.1Sfvdl/* 2471.1Sfvdl * pull in #defines for kinds of processors 2481.1Sfvdl */ 2491.1Sfvdl 2501.1Sfvdl#ifdef _KERNEL 2511.1Sfvdlextern int biosbasemem; 2521.1Sfvdlextern int biosextmem; 2531.1Sfvdlextern int cpu; 2541.1Sfvdlextern int cpu_feature; 2551.1Sfvdlextern int cpu_id; 2561.1Sfvdlextern char cpu_vendor[]; 2571.1Sfvdlextern int cpuid_level; 2581.1Sfvdl 2591.1Sfvdl/* identcpu.c */ 2601.1Sfvdl 2611.1Sfvdlvoid identifycpu __P((struct cpu_info *)); 2621.1Sfvdlvoid cpu_probe_features __P((struct cpu_info *)); 2631.1Sfvdl 2641.1Sfvdl/* machdep.c */ 2651.1Sfvdlvoid delay __P((int)); 2661.1Sfvdlvoid dumpconf __P((void)); 2671.1Sfvdlint cpu_maxproc __P((void)); 2681.1Sfvdlvoid cpu_reset __P((void)); 2691.1Sfvdlvoid x86_64_proc0_tss_ldt_init __P((void)); 2701.1Sfvdlvoid x86_64_init_pcb_tss_ldt __P((struct cpu_info *)); 2711.1Sfvdlvoid cpu_proc_fork __P((struct proc *, struct proc *)); 2721.1Sfvdl 2731.1Sfvdlstruct region_descriptor; 2741.1Sfvdlvoid lgdt __P((struct region_descriptor *)); 2751.1Sfvdlvoid fillw __P((short, void *, size_t)); 2761.1Sfvdl 2771.1Sfvdlstruct pcb; 2781.1Sfvdlvoid savectx __P((struct pcb *)); 2791.1Sfvdlvoid switch_exit __P((struct lwp *, void (*)(struct lwp *))); 2801.1Sfvdlvoid proc_trampoline __P((void)); 2811.1Sfvdlvoid child_trampoline __P((void)); 2821.1Sfvdl 2831.1Sfvdl/* clock.c */ 2841.1Sfvdlvoid initrtclock __P((void)); 2851.1Sfvdlvoid startrtclock __P((void)); 2861.1Sfvdlvoid i8254_delay __P((int)); 2871.1Sfvdlvoid i8254_microtime __P((struct timeval *)); 2881.1Sfvdlvoid i8254_initclocks __P((void)); 2891.1Sfvdl 2901.1Sfvdlvoid cpu_init_msrs __P((struct cpu_info *)); 2911.1Sfvdl 2921.1Sfvdl 2931.1Sfvdl/* vm_machdep.c */ 2941.1Sfvdlint kvtop __P((caddr_t)); 2951.1Sfvdl 2961.1Sfvdl/* trap.c */ 2971.1Sfvdlvoid child_return __P((void *)); 2981.1Sfvdl 2991.1Sfvdl/* consinit.c */ 3001.1Sfvdlvoid kgdb_port_init __P((void)); 3011.1Sfvdl 3021.1Sfvdl/* bus_machdep.c */ 3031.1Sfvdlvoid x86_bus_space_init __P((void)); 3041.1Sfvdlvoid x86_bus_space_mallocok __P((void)); 3051.1Sfvdl 3061.1Sfvdl#endif /* _KERNEL */ 3071.1Sfvdl 3081.1Sfvdl#include <machine/psl.h> 3091.1Sfvdl 3101.1Sfvdl/* 3111.1Sfvdl * CTL_MACHDEP definitions. 3121.1Sfvdl */ 3131.1Sfvdl#define CPU_CONSDEV 1 /* dev_t: console terminal device */ 3141.1Sfvdl#define CPU_BIOSBASEMEM 2 /* int: bios-reported base mem (K) */ 3151.1Sfvdl#define CPU_BIOSEXTMEM 3 /* int: bios-reported ext. mem (K) */ 3161.1Sfvdl#define CPU_NKPDE 4 /* int: number of kernel PDEs */ 3171.1Sfvdl#define CPU_BOOTED_KERNEL 5 /* string: booted kernel name */ 3181.1Sfvdl#define CPU_DISKINFO 6 /* disk geometry information */ 3191.1Sfvdl#define CPU_FPU_PRESENT 7 /* FPU is present */ 3201.1Sfvdl#define CPU_MAXID 8 /* number of valid machdep ids */ 3211.1Sfvdl 3221.1Sfvdl#define CTL_MACHDEP_NAMES { \ 3231.1Sfvdl { 0, 0 }, \ 3241.1Sfvdl { "console_device", CTLTYPE_STRUCT }, \ 3251.1Sfvdl { "biosbasemem", CTLTYPE_INT }, \ 3261.1Sfvdl { "biosextmem", CTLTYPE_INT }, \ 3271.1Sfvdl { "nkpde", CTLTYPE_INT }, \ 3281.1Sfvdl { "booted_kernel", CTLTYPE_STRING }, \ 3291.1Sfvdl { "diskinfo", CTLTYPE_STRUCT }, \ 3301.1Sfvdl { "fpu_present", CTLTYPE_INT }, \ 3311.1Sfvdl} 3321.1Sfvdl 3331.1Sfvdl 3341.1Sfvdl/* 3351.1Sfvdl * Structure for CPU_DISKINFO sysctl call. 3361.1Sfvdl * XXX this should be somewhere else. 3371.1Sfvdl */ 3381.1Sfvdl#define MAX_BIOSDISKS 16 3391.1Sfvdl 3401.1Sfvdlstruct disklist { 3411.1Sfvdl int dl_nbiosdisks; /* number of bios disks */ 3421.1Sfvdl struct biosdisk_info { 3431.1Sfvdl int bi_dev; /* BIOS device # (0x80 ..) */ 3441.1Sfvdl int bi_cyl; /* cylinders on disk */ 3451.1Sfvdl int bi_head; /* heads per track */ 3461.1Sfvdl int bi_sec; /* sectors per track */ 3471.1Sfvdl u_int64_t bi_lbasecs; /* total sec. (iff ext13) */ 3481.1Sfvdl#define BIFLAG_INVALID 0x01 3491.1Sfvdl#define BIFLAG_EXTINT13 0x02 3501.1Sfvdl int bi_flags; 3511.1Sfvdl } dl_biosdisks[MAX_BIOSDISKS]; 3521.1Sfvdl 3531.1Sfvdl int dl_nnativedisks; /* number of native disks */ 3541.1Sfvdl struct nativedisk_info { 3551.1Sfvdl char ni_devname[16]; /* native device name */ 3561.1Sfvdl int ni_nmatches; /* # of matches w/ BIOS */ 3571.1Sfvdl int ni_biosmatches[MAX_BIOSDISKS]; /* indices in dl_biosdisks */ 3581.1Sfvdl } dl_nativedisks[1]; /* actually longer */ 3591.1Sfvdl}; 3601.1Sfvdl 3611.1Sfvdl#endif /* !_AMD64_CPU_H_ */ 362