[BACK]Return to cpu.h CVS log [TXT][DIR] Up to [local] / sys / arch / amd64 / include

Annotation of sys/arch/amd64/include/cpu.h, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: cpu.h,v 1.31 2007/05/29 18:53:52 deraadt Exp $        */
                      2: /*     $NetBSD: cpu.h,v 1.1 2003/04/26 18:39:39 fvdl Exp $     */
                      3:
                      4: /*-
                      5:  * Copyright (c) 1990 The Regents of the University of California.
                      6:  * All rights reserved.
                      7:  *
                      8:  * This code is derived from software contributed to Berkeley by
                      9:  * William Jolitz.
                     10:  *
                     11:  * Redistribution and use in source and binary forms, with or without
                     12:  * modification, are permitted provided that the following conditions
                     13:  * are met:
                     14:  * 1. Redistributions of source code must retain the above copyright
                     15:  *    notice, this list of conditions and the following disclaimer.
                     16:  * 2. Redistributions in binary form must reproduce the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer in the
                     18:  *    documentation and/or other materials provided with the distribution.
                     19:  * 3. Neither the name of the University nor the names of its contributors
                     20:  *    may be used to endorse or promote products derived from this software
                     21:  *    without specific prior written permission.
                     22:  *
                     23:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     24:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     25:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     26:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     27:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     28:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     29:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     30:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     31:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     32:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     33:  * SUCH DAMAGE.
                     34:  *
                     35:  *     @(#)cpu.h       5.4 (Berkeley) 5/9/91
                     36:  */
                     37:
                     38: #ifndef _AMD64_CPU_H_
                     39: #define _AMD64_CPU_H_
                     40:
                     41: /*
                     42:  * Definitions unique to x86-64 cpu support.
                     43:  */
                     44: #include <machine/frame.h>
                     45: #include <machine/segments.h>
                     46: #include <machine/tss.h>
                     47: #include <machine/intrdefs.h>
                     48: #include <machine/cacheinfo.h>
                     49:
                     50: #ifdef MULTIPROCESSOR
                     51: #include <machine/i82489reg.h>
                     52: #include <machine/i82489var.h>
                     53: #endif
                     54:
                     55: #include <sys/device.h>
                     56: #include <sys/lock.h>
                     57: #include <sys/sched.h>
                     58: #include <sys/sensors.h>
                     59:
                     60: #ifdef _KERNEL
                     61:
                     62: struct 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 proc *ci_curproc;
                     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 proc *ci_fpcurproc;
                     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_feature_eflags;
                     99:        u_int32_t       ci_signature;
                    100:        u_int64_t       ci_tsc_freq;
                    101:
                    102:        struct cpu_functions *ci_func;
                    103:        void (*cpu_setup)(struct cpu_info *);
                    104:        void (*ci_info)(struct cpu_info *);
                    105:
                    106:        int             ci_want_resched;
                    107:
                    108:        struct x86_cache_info ci_cinfo[CAI_COUNT];
                    109:
                    110:        struct timeval  ci_cc_time;
                    111:        int64_t         ci_cc_cc;
                    112:        int64_t         ci_cc_ms_delta;
                    113:        int64_t         ci_cc_denom;
                    114:
                    115:        char            *ci_gdt;
                    116:
                    117:        volatile int    ci_ddb_paused;
                    118: #define CI_DDB_RUNNING         0
                    119: #define CI_DDB_SHOULDSTOP      1
                    120: #define CI_DDB_STOPPED         2
                    121: #define CI_DDB_ENTERDDB                3
                    122: #define CI_DDB_INDDB           4
                    123:
                    124:        volatile int ci_setperf_state;
                    125: #define CI_SETPERF_READY       0
                    126: #define CI_SETPERF_SHOULDSTOP  1
                    127: #define CI_SETPERF_INTRANSIT   2
                    128: #define CI_SETPERF_DONE                3
                    129:
                    130:        struct x86_64_tss       ci_doubleflt_tss;
                    131:
                    132:        char *ci_doubleflt_stack;
                    133:
                    134:        struct ksensordev       ci_sensordev;
                    135:        struct ksensor          ci_sensor;
                    136: };
                    137:
                    138: #define CPUF_BSP       0x0001          /* CPU is the original BSP */
                    139: #define CPUF_AP                0x0002          /* CPU is an AP */
                    140: #define CPUF_SP                0x0004          /* CPU is only processor */
                    141: #define CPUF_PRIMARY   0x0008          /* CPU is active primary processor */
                    142:
                    143: #define CPUF_PRESENT   0x1000          /* CPU is present */
                    144: #define CPUF_RUNNING   0x2000          /* CPU is running */
                    145: #define CPUF_PAUSE     0x4000          /* CPU is paused in DDB */
                    146: #define CPUF_GO                0x8000          /* CPU should start running */
                    147:
                    148: #define PROC_PC(p)     ((p)->p_md.md_regs->tf_rip)
                    149:
                    150: extern struct cpu_info cpu_info_primary;
                    151: extern struct cpu_info *cpu_info_list;
                    152:
                    153: #define CPU_INFO_ITERATOR              int
                    154: #define CPU_INFO_FOREACH(cii, ci)      for (cii = 0, ci = cpu_info_list; \
                    155:                                            ci != NULL; ci = ci->ci_next)
                    156:
                    157: #define CPU_INFO_UNIT(ci)      ((ci)->ci_dev->dv_unit)
                    158:
                    159: /*
                    160:  * Preempt the current process if in interrupt from user mode,
                    161:  * or after the current trap/syscall if in system mode.
                    162:  */
                    163: extern void need_resched(struct cpu_info *);
                    164:
                    165: #if defined(MULTIPROCESSOR)
                    166:
                    167: #define X86_MAXPROCS           32      /* bitmask; can be bumped to 64 */
                    168:
                    169: #define CPU_STARTUP(_ci)       ((_ci)->ci_func->start(_ci))
                    170: #define CPU_STOP(_ci)          ((_ci)->ci_func->stop(_ci))
                    171: #define CPU_START_CLEANUP(_ci) ((_ci)->ci_func->cleanup(_ci))
                    172:
                    173: #define curcpu()       ({struct cpu_info *__ci;                  \
                    174:                        asm volatile("movq %%gs:8,%0" : "=r" (__ci)); \
                    175:                        __ci;})
                    176: #define cpu_number()   (curcpu()->ci_cpuid)
                    177:
                    178: #define CPU_IS_PRIMARY(ci)     ((ci)->ci_flags & CPUF_PRIMARY)
                    179:
                    180: extern struct cpu_info *cpu_info[X86_MAXPROCS];
                    181:
                    182: void cpu_boot_secondary_processors(void);
                    183: void cpu_init_idle_pcbs(void);
                    184:
                    185: #else /* !MULTIPROCESSOR */
                    186:
                    187: #define X86_MAXPROCS           1
                    188:
                    189: #ifdef _KERNEL
                    190: extern struct cpu_info cpu_info_primary;
                    191:
                    192: #define curcpu()               (&cpu_info_primary)
                    193:
                    194: #endif
                    195:
                    196: /*
                    197:  * definitions of cpu-dependent requirements
                    198:  * referenced in generic code
                    199:  */
                    200: #define        cpu_number()            0
                    201: #define CPU_IS_PRIMARY(ci)     1
                    202:
                    203: #endif /* MULTIPROCESSOR */
                    204:
                    205: #endif /* _KERNEL */
                    206:
                    207: #include <machine/psl.h>
                    208:
                    209: #ifdef MULTIPROCESSOR
                    210: #include <sys/mplock.h>
                    211: #endif
                    212:
                    213: #define aston(p)       ((p)->p_md.md_astpending = 1)
                    214:
                    215: extern u_int32_t cpus_attached;
                    216:
                    217: #define curpcb         curcpu()->ci_curpcb
                    218: #define curproc                curcpu()->ci_curproc
                    219:
                    220: /*
                    221:  * Arguments to hardclock, softclock and statclock
                    222:  * encapsulate the previous machine state in an opaque
                    223:  * clockframe; for now, use generic intrframe.
                    224:  */
                    225: #define clockframe intrframe
                    226:
                    227: #define        CLKF_USERMODE(frame)    USERMODE((frame)->if_cs, (frame)->if_rflags)
                    228: #define CLKF_PC(frame)         ((frame)->if_rip)
                    229: #define CLKF_INTR(frame)       (curcpu()->ci_idepth > 1)
                    230:
                    231: /*
                    232:  * This is used during profiling to integrate system time.
                    233:  */
                    234: #define        PROC_PC(p)              ((p)->p_md.md_regs->tf_rip)
                    235:
                    236: /*
                    237:  * Give a profiling tick to the current process when the user profiling
                    238:  * buffer pages are invalid.  On the i386, request an ast to send us
                    239:  * through trap(), marking the proc as needing a profiling tick.
                    240:  */
                    241: #define        need_proftick(p)        aston(p)
                    242:
                    243: void signotify(struct proc *);
                    244:
                    245: /*
                    246:  * We need a machine-independent name for this.
                    247:  */
                    248: extern void (*delay_func)(int);
                    249: struct timeval;
                    250:
                    251: #define DELAY(x)               (*delay_func)(x)
                    252: #define delay(x)               (*delay_func)(x)
                    253:
                    254:
                    255: #ifdef _KERNEL
                    256: extern int biosbasemem;
                    257: extern int biosextmem;
                    258: extern int cpu;
                    259: extern int cpu_feature;
                    260: extern int cpu_ecxfeature;
                    261: extern int cpu_id;
                    262: extern char cpu_vendor[];
                    263: extern int cpuid_level;
                    264: extern int cpuspeed;
                    265:
                    266: /* identcpu.c */
                    267: void   identifycpu(struct cpu_info *);
                    268: int    cpu_amd64speed(int *);
                    269: void cpu_probe_features(struct cpu_info *);
                    270:
                    271: /* machdep.c */
                    272: void   dumpconf(void);
                    273: int    cpu_maxproc(void);
                    274: void   cpu_reset(void);
                    275: void   x86_64_proc0_tss_ldt_init(void);
                    276: void   x86_64_bufinit(void);
                    277: void   x86_64_init_pcb_tss_ldt(struct cpu_info *);
                    278: void   cpu_proc_fork(struct proc *, struct proc *);
                    279:
                    280: struct region_descriptor;
                    281: void   lgdt(struct region_descriptor *);
                    282: void   fillw(short, void *, size_t);
                    283:
                    284: struct pcb;
                    285: void   savectx(struct pcb *);
                    286: void   switch_exit(struct proc *, void (*)(struct proc *));
                    287: void   proc_trampoline(void);
                    288: void   child_trampoline(void);
                    289:
                    290: /* clock.c */
                    291: void   initrtclock(void);
                    292: void   startrtclock(void);
                    293: void   i8254_delay(int);
                    294: void   i8254_initclocks(void);
                    295: void   i8254_inittimecounter(void);
                    296: void   i8254_inittimecounter_simple(void);
                    297:
                    298:
                    299: void cpu_init_msrs(struct cpu_info *);
                    300:
                    301:
                    302: /* trap.c */
                    303: void   child_return(void *);
                    304:
                    305: /* dkcsum.c */
                    306: void   dkcsumattach(void);
                    307:
                    308: /* consinit.c */
                    309: void kgdb_port_init(void);
                    310:
                    311: /* bus_machdep.c */
                    312: void x86_bus_space_init(void);
                    313: void x86_bus_space_mallocok(void);
                    314:
                    315: /* powernow-k8.c */
                    316: void k8_powernow_init(struct cpu_info *);
                    317: void k8_powernow_setperf(int);
                    318:
                    319: void est_init(struct cpu_info *);
                    320: void est_setperf(int);
                    321:
                    322: #ifdef MULTIPROCESSOR
                    323: /* mp_setperf.c */
                    324: void mp_setperf_init(void);
                    325: #endif
                    326:
                    327: #endif /* _KERNEL */
                    328:
                    329: /*
                    330:  * CTL_MACHDEP definitions.
                    331:  */
                    332: #define        CPU_CONSDEV             1       /* dev_t: console terminal device */
                    333: #define        CPU_BIOS                2       /* BIOS variables */
                    334: #define        CPU_BLK2CHR             3       /* convert blk maj into chr one */
                    335: #define        CPU_CHR2BLK             4       /* convert chr maj into blk one */
                    336: #define CPU_ALLOWAPERTURE      5       /* allow mmap of /dev/xf86 */
                    337: #define CPU_CPUVENDOR          6       /* cpuid vendor string */
                    338: #define CPU_CPUID              7       /* cpuid */
                    339: #define CPU_CPUFEATURE         8       /* cpuid features */
                    340: #define CPU_APMWARN            9       /* APM battery warning percentage */
                    341: #define CPU_KBDRESET           10      /* keyboard reset under pcvt */
                    342: #define CPU_APMHALT            11      /* halt -p hack */
                    343: #define CPU_USERLDT            12
                    344: #define CPU_MAXID              13      /* number of valid machdep ids */
                    345:
                    346: #define        CTL_MACHDEP_NAMES { \
                    347:        { 0, 0 }, \
                    348:        { "console_device", CTLTYPE_STRUCT }, \
                    349:        { "bios", CTLTYPE_INT }, \
                    350:        { "blk2chr", CTLTYPE_STRUCT }, \
                    351:        { "chr2blk", CTLTYPE_STRUCT }, \
                    352:        { "allowaperture", CTLTYPE_INT }, \
                    353:        { "cpuvendor", CTLTYPE_STRING }, \
                    354:        { "cpuid", CTLTYPE_INT }, \
                    355:        { "cpufeature", CTLTYPE_INT }, \
                    356:        { "apmwarn", CTLTYPE_INT }, \
                    357:        { "kbdreset", CTLTYPE_INT }, \
                    358:        { "apmhalt", CTLTYPE_INT }, \
                    359:        { "userldt", CTLTYPE_INT }, \
                    360: }
                    361:
                    362: /*
                    363:  * Default cr4 flags.
                    364:  * Doesn't really belong here, but doesn't really belong anywhere else
                    365:  * either. Just to avoid painful mismatches of cr4 flags since they are
                    366:  * set in three different places.
                    367:  */
                    368: #define CR4_DEFAULT (CR4_PAE|CR4_PGE|CR4_PSE|CR4_OSFXSR|CR4_OSXMMEXCPT)
                    369:
                    370: #endif /* !_AMD64_CPU_H_ */

CVSweb