[BACK]Return to cpu.h CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / arch / amd64 / include

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

1.19    ! xtraeme     1: /*     $NetBSD: cpu.h,v 1.18 2007/03/16 06:20:36 xtraeme Exp $ */
1.1       fvdl        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.
1.2       agc        18:  * 3. Neither the name of the University nor the names of its contributors
1.1       fvdl       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:
1.6       yamt       40: #if defined(_KERNEL)
1.1       fvdl       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>
1.17      ad         56: #include <sys/simplelock.h>
1.4       yamt       57: #include <sys/cpu_data.h>
                     58: #include <sys/cc_microtime.h>
1.1       fvdl       59:
                     60: struct cpu_info {
                     61:        struct device *ci_dev;
                     62:        struct cpu_info *ci_self;
1.13      ad         63:        void *ci_self200;               /* self + 0x200, see lock_stubs.S */
1.4       yamt       64:        struct cpu_data ci_data;        /* MI per-cpu data */
1.5       yamt       65:        struct cc_microtime_state ci_cc;/* cc_microtime state */
1.1       fvdl       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 pcb *ci_curpcb;
                     81:        struct pcb *ci_idle_pcb;
                     82:        int ci_idle_tss_sel;
                     83:
                     84:        struct intrsource *ci_isources[MAX_INTR_SOURCES];
1.13      ad         85:        volatile int    ci_mtx_count;   /* Negative count of spin mutexes */
                     86:        volatile int    ci_mtx_oldspl;  /* Old SPL at this ci_idepth */
                     87:
                     88:        /* The following must be aligned for cmpxchg8b. */
                     89:        struct {
                     90:                uint32_t        ipending;
                     91:                int             ilevel;
                     92:        } ci_istate __aligned(8);
                     93: #define ci_ipending    ci_istate.ipending
                     94: #define        ci_ilevel       ci_istate.ilevel
                     95:
1.1       fvdl       96:        int             ci_idepth;
                     97:        u_int32_t       ci_imask[NIPL];
                     98:        u_int32_t       ci_iunmask[NIPL];
                     99:
                    100:        paddr_t         ci_idle_pcb_paddr;
                    101:        u_int           ci_flags;
                    102:        u_int32_t       ci_ipis;
                    103:
                    104:        u_int32_t       ci_feature_flags;
1.19    ! xtraeme   105:        uint32_t        ci_feature2_flags;
1.1       fvdl      106:        u_int32_t       ci_signature;
                    107:        u_int64_t       ci_tsc_freq;
                    108:
1.16      drochner  109:        const struct cpu_functions *ci_func;
1.18      xtraeme   110:        void (*cpu_setup)(struct cpu_info *);
                    111:        void (*ci_info)(struct cpu_info *);
1.1       fvdl      112:
                    113:        int             ci_want_resched;
                    114:        int             ci_astpending;
                    115:        struct trapframe *ci_ddb_regs;
                    116:
                    117:        struct x86_cache_info ci_cinfo[CAI_COUNT];
                    118:
                    119:        char            *ci_gdt;
                    120:
                    121:        struct x86_64_tss       ci_doubleflt_tss;
                    122:        struct x86_64_tss       ci_ddbipi_tss;
                    123:
                    124:        char *ci_doubleflt_stack;
                    125:        char *ci_ddbipi_stack;
                    126:
                    127:        struct evcnt ci_ipi_events[X86_NIPI];
                    128: };
                    129:
                    130: #define CPUF_BSP       0x0001          /* CPU is the original BSP */
                    131: #define CPUF_AP                0x0002          /* CPU is an AP */
                    132: #define CPUF_SP                0x0004          /* CPU is only processor */
                    133: #define CPUF_PRIMARY   0x0008          /* CPU is active primary processor */
                    134:
                    135: #define CPUF_PRESENT   0x1000          /* CPU is present */
                    136: #define CPUF_RUNNING   0x2000          /* CPU is running */
                    137: #define CPUF_PAUSE     0x4000          /* CPU is paused in DDB */
                    138: #define CPUF_GO                0x8000          /* CPU should start running */
                    139:
                    140:
                    141: extern struct cpu_info cpu_info_primary;
                    142: extern struct cpu_info *cpu_info_list;
                    143:
                    144: #define CPU_INFO_ITERATOR              int
                    145: #define CPU_INFO_FOREACH(cii, ci)      cii = 0, ci = cpu_info_list; \
                    146:                                        ci != NULL; ci = ci->ci_next
                    147:
                    148: #if defined(MULTIPROCESSOR)
                    149:
                    150: #define X86_MAXPROCS           32      /* bitmask; can be bumped to 64 */
                    151:
                    152: #define CPU_STARTUP(_ci)       ((_ci)->ci_func->start(_ci))
                    153: #define CPU_STOP(_ci)          ((_ci)->ci_func->stop(_ci))
                    154: #define CPU_START_CLEANUP(_ci) ((_ci)->ci_func->cleanup(_ci))
                    155:
                    156: #define curcpu()       ({struct cpu_info *__ci;                  \
1.9       perry     157:                        __asm volatile("movq %%gs:8,%0" : "=r" (__ci)); \
1.1       fvdl      158:                        __ci;})
                    159: #define cpu_number()   (curcpu()->ci_cpuid)
                    160:
                    161: #define CPU_IS_PRIMARY(ci)     ((ci)->ci_flags & CPUF_PRIMARY)
                    162:
                    163: extern struct cpu_info *cpu_info[X86_MAXPROCS];
                    164:
1.18      xtraeme   165: void cpu_boot_secondary_processors(void);
                    166: void cpu_init_idle_pcbs(void);
1.1       fvdl      167:
                    168:
                    169: #else /* !MULTIPROCESSOR */
                    170:
                    171: #define X86_MAXPROCS           1
                    172:
                    173: extern struct cpu_info cpu_info_primary;
                    174:
                    175: #define curcpu()               (&cpu_info_primary)
                    176:
                    177: /*
                    178:  * definitions of cpu-dependent requirements
                    179:  * referenced in generic code
                    180:  */
                    181: #define        cpu_number()            0
                    182: #define CPU_IS_PRIMARY(ci)     1
                    183:
1.13      ad        184: #endif
                    185:
1.1       fvdl      186: /*
                    187:  * Preempt the current process if in interrupt from user mode,
                    188:  * or after the current trap/syscall if in system mode.
                    189:  */
1.13      ad        190: extern void cpu_need_resched(struct cpu_info *);
1.1       fvdl      191:
1.13      ad        192: #define aston(l)       ((l)->l_md.md_astpending = 1)
1.1       fvdl      193:
                    194: extern u_int32_t cpus_attached;
                    195:
                    196: #define curpcb         curcpu()->ci_curpcb
                    197: #define curlwp         curcpu()->ci_curlwp
                    198:
                    199: /*
                    200:  * Arguments to hardclock, softclock and statclock
                    201:  * encapsulate the previous machine state in an opaque
                    202:  * clockframe; for now, use generic intrframe.
                    203:  */
1.7       cube      204: struct clockframe {
                    205:        struct intrframe cf_if;
                    206: };
1.1       fvdl      207:
1.7       cube      208: #define        CLKF_USERMODE(frame)    USERMODE((frame)->cf_if.if_cs, (frame)->cf_if.if_rflags)
                    209: #define CLKF_PC(frame)         ((frame)->cf_if.if_rip)
1.1       fvdl      210: #define CLKF_INTR(frame)       (curcpu()->ci_idepth > 1)
                    211:
                    212: /*
                    213:  * This is used during profiling to integrate system time.  It can safely
                    214:  * assume that the process is resident.
                    215:  */
                    216: #define LWP_PC(l)              ((l)->l_md.md_regs->tf_rip)
                    217:
                    218: /*
                    219:  * Give a profiling tick to the current process when the user profiling
                    220:  * buffer pages are invalid.  On the i386, request an ast to send us
                    221:  * through trap(), marking the proc as needing a profiling tick.
                    222:  */
1.13      ad        223: extern void cpu_need_proftick(struct lwp *);
1.1       fvdl      224:
                    225: /*
1.13      ad        226:  * Notify an LWP that it has a signal pending, process as soon as possible.
1.1       fvdl      227:  */
1.13      ad        228: extern void cpu_signotify(struct lwp *);
1.1       fvdl      229:
                    230: /*
                    231:  * We need a machine-independent name for this.
                    232:  */
1.18      xtraeme   233: extern void (*delay_func)(int);
1.1       fvdl      234:
                    235: #define DELAY(x)               (*delay_func)(x)
                    236: #define delay(x)               (*delay_func)(x)
                    237:
                    238:
                    239: /*
                    240:  * pull in #defines for kinds of processors
                    241:  */
                    242:
                    243: extern int biosbasemem;
                    244: extern int biosextmem;
                    245: extern int cpu;
                    246: extern int cpu_feature;
                    247: extern int cpu_id;
                    248: extern char cpu_vendor[];
                    249: extern int cpuid_level;
                    250:
                    251: /* identcpu.c */
                    252:
1.18      xtraeme   253: void   identifycpu(struct cpu_info *);
                    254: void cpu_probe_features(struct cpu_info *);
1.1       fvdl      255:
                    256: /* machdep.c */
1.18      xtraeme   257: void   dumpconf(void);
                    258: int    cpu_maxproc(void);
                    259: void   cpu_reset(void);
                    260: void   x86_64_proc0_tss_ldt_init(void);
                    261: void   x86_64_init_pcb_tss_ldt(struct cpu_info *);
                    262: void   cpu_proc_fork(struct proc *, struct proc *);
1.1       fvdl      263:
                    264: struct region_descriptor;
1.18      xtraeme   265: void   lgdt(struct region_descriptor *);
                    266: void   fillw(short, void *, size_t);
1.1       fvdl      267:
                    268: struct pcb;
1.18      xtraeme   269: void   savectx(struct pcb *);
                    270: void   switch_exit(struct lwp *, void (*)(struct lwp *));
                    271: void   proc_trampoline(void);
                    272: void   child_trampoline(void);
1.1       fvdl      273:
                    274: /* clock.c */
1.18      xtraeme   275: void   initrtclock(u_long);
                    276: void   startrtclock(void);
                    277: void   i8254_delay(int);
                    278: void   i8254_microtime(struct timeval *);
                    279: void   i8254_initclocks(void);
1.1       fvdl      280:
1.18      xtraeme   281: void cpu_init_msrs(struct cpu_info *);
1.1       fvdl      282:
                    283:
                    284: /* vm_machdep.c */
1.18      xtraeme   285: int kvtop(void *);
1.1       fvdl      286:
                    287: /* trap.c */
1.18      xtraeme   288: void   child_return(void *);
1.1       fvdl      289:
                    290: /* consinit.c */
1.18      xtraeme   291: void kgdb_port_init(void);
1.1       fvdl      292:
                    293: /* bus_machdep.c */
1.18      xtraeme   294: void x86_bus_space_init(void);
                    295: void x86_bus_space_mallocok(void);
1.12      xtraeme   296:
1.1       fvdl      297: #endif /* _KERNEL */
                    298:
                    299: #include <machine/psl.h>
                    300:
                    301: /*
                    302:  * CTL_MACHDEP definitions.
                    303:  */
                    304: #define        CPU_CONSDEV             1       /* dev_t: console terminal device */
                    305: #define        CPU_BIOSBASEMEM         2       /* int: bios-reported base mem (K) */
                    306: #define        CPU_BIOSEXTMEM          3       /* int: bios-reported ext. mem (K) */
                    307: #define        CPU_NKPDE               4       /* int: number of kernel PDEs */
                    308: #define        CPU_BOOTED_KERNEL       5       /* string: booted kernel name */
                    309: #define CPU_DISKINFO           6       /* disk geometry information */
                    310: #define CPU_FPU_PRESENT                7       /* FPU is present */
                    311: #define        CPU_MAXID               8       /* number of valid machdep ids */
                    312:
                    313: #define        CTL_MACHDEP_NAMES { \
                    314:        { 0, 0 }, \
                    315:        { "console_device", CTLTYPE_STRUCT }, \
                    316:        { "biosbasemem", CTLTYPE_INT }, \
                    317:        { "biosextmem", CTLTYPE_INT }, \
                    318:        { "nkpde", CTLTYPE_INT }, \
                    319:        { "booted_kernel", CTLTYPE_STRING }, \
                    320:        { "diskinfo", CTLTYPE_STRUCT }, \
                    321:        { "fpu_present", CTLTYPE_INT }, \
                    322: }
                    323:
                    324:
                    325: /*
                    326:  * Structure for CPU_DISKINFO sysctl call.
                    327:  * XXX this should be somewhere else.
                    328:  */
                    329: #define MAX_BIOSDISKS  16
                    330:
                    331: struct disklist {
                    332:        int dl_nbiosdisks;                         /* number of bios disks */
                    333:        struct biosdisk_info {
                    334:                int bi_dev;                        /* BIOS device # (0x80 ..) */
                    335:                int bi_cyl;                        /* cylinders on disk */
                    336:                int bi_head;                       /* heads per track */
                    337:                int bi_sec;                        /* sectors per track */
                    338:                u_int64_t bi_lbasecs;              /* total sec. (iff ext13) */
                    339: #define BIFLAG_INVALID         0x01
                    340: #define BIFLAG_EXTINT13                0x02
                    341:                int bi_flags;
                    342:        } dl_biosdisks[MAX_BIOSDISKS];
                    343:
                    344:        int dl_nnativedisks;                       /* number of native disks */
                    345:        struct nativedisk_info {
                    346:                char ni_devname[16];               /* native device name */
                    347:                int ni_nmatches;                   /* # of matches w/ BIOS */
                    348:                int ni_biosmatches[MAX_BIOSDISKS]; /* indices in dl_biosdisks */
                    349:        } dl_nativedisks[1];                       /* actually longer */
                    350: };
                    351:
                    352: #endif /* !_AMD64_CPU_H_ */

CVSweb <webmaster@jp.NetBSD.org>