Annotation of src/sys/arch/amd64/include/cpu.h, Revision 1.14.2.2
1.14.2.2! rmind 1: /* $NetBSD: cpu.h,v 1.14.2.1 2007/03/03 15:42:49 yamt 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>
56: #include <sys/lock.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 intrsource *ci_isources[MAX_INTR_SOURCES];
1.13 ad 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:
1.1 fvdl 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;
1.14.2.1 yamt 101: u_int32_t ci_feature2_flags;
1.1 fvdl 102: u_int32_t ci_signature;
103: u_int64_t ci_tsc_freq;
104:
1.14.2.2! rmind 105: const struct cpu_functions *ci_func;
1.1 fvdl 106: void (*cpu_setup) __P((struct cpu_info *));
107: void (*ci_info) __P((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:
137: extern struct cpu_info cpu_info_primary;
138: extern 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; \
1.9 perry 153: __asm volatile("movq %%gs:8,%0" : "=r" (__ci)); \
1.1 fvdl 154: __ci;})
155: #define cpu_number() (curcpu()->ci_cpuid)
156:
157: #define CPU_IS_PRIMARY(ci) ((ci)->ci_flags & CPUF_PRIMARY)
158:
159: extern struct cpu_info *cpu_info[X86_MAXPROCS];
160:
1.14.2.1 yamt 161: void cpu_boot_secondary_processors(void);
162: void cpu_init_idle_lwps(void);
1.1 fvdl 163:
164:
165: #else /* !MULTIPROCESSOR */
166:
167: #define X86_MAXPROCS 1
168:
169: extern 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:
1.13 ad 180: #endif
181:
182: #define aston(l) ((l)->l_md.md_astpending = 1)
1.1 fvdl 183:
184: extern u_int32_t cpus_attached;
185:
186: #define curlwp curcpu()->ci_curlwp
1.14.2.1 yamt 187: #define curpcb (&curlwp->l_addr->u_pcb)
1.1 fvdl 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: */
1.7 cube 194: struct clockframe {
195: struct intrframe cf_if;
196: };
1.1 fvdl 197:
1.7 cube 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)
1.1 fvdl 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: */
1.13 ad 213: extern void cpu_need_proftick(struct lwp *);
1.1 fvdl 214:
215: /*
1.13 ad 216: * Notify an LWP that it has a signal pending, process as soon as possible.
1.1 fvdl 217: */
1.13 ad 218: extern void cpu_signotify(struct lwp *);
1.1 fvdl 219:
220: /*
221: * We need a machine-independent name for this.
222: */
223: extern void (*delay_func) __P((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:
233: extern int biosbasemem;
234: extern int biosextmem;
235: extern int cpu;
236: extern int cpu_feature;
237: extern int cpu_id;
238: extern char cpu_vendor[];
239: extern int cpuid_level;
240:
241: /* identcpu.c */
242:
243: void identifycpu __P((struct cpu_info *));
244: void cpu_probe_features __P((struct cpu_info *));
245:
246: /* machdep.c */
247: void dumpconf __P((void));
248: int cpu_maxproc __P((void));
249: void cpu_reset __P((void));
250: void x86_64_proc0_tss_ldt_init __P((void));
251: void cpu_proc_fork __P((struct proc *, struct proc *));
252:
253: struct region_descriptor;
254: void lgdt __P((struct region_descriptor *));
255: void fillw __P((short, void *, size_t));
256:
257: struct pcb;
258: void savectx __P((struct pcb *));
259: void switch_exit __P((struct lwp *, void (*)(struct lwp *)));
1.14.2.1 yamt 260: void lwp_trampoline __P((void));
1.1 fvdl 261: void child_trampoline __P((void));
262:
263: /* clock.c */
1.11 kardel 264: void initrtclock __P((u_long));
1.1 fvdl 265: void startrtclock __P((void));
266: void i8254_delay __P((int));
267: void i8254_microtime __P((struct timeval *));
268: void i8254_initclocks __P((void));
269:
270: void cpu_init_msrs __P((struct cpu_info *));
271:
272:
273: /* vm_machdep.c */
1.14.2.2! rmind 274: int kvtop __P((void *));
1.1 fvdl 275:
276: /* trap.c */
277: void child_return __P((void *));
278:
279: /* consinit.c */
280: void kgdb_port_init __P((void));
281:
282: /* bus_machdep.c */
283: void x86_bus_space_init __P((void));
284: void x86_bus_space_mallocok __P((void));
285:
1.12 xtraeme 286: /* powernow_k8.c */
287: void k8_powernow_init(void);
288:
1.1 fvdl 289: #endif /* _KERNEL */
290:
291: #include <machine/psl.h>
292:
293: /*
294: * CTL_MACHDEP definitions.
295: */
296: #define CPU_CONSDEV 1 /* dev_t: console terminal device */
297: #define CPU_BIOSBASEMEM 2 /* int: bios-reported base mem (K) */
298: #define CPU_BIOSEXTMEM 3 /* int: bios-reported ext. mem (K) */
299: #define CPU_NKPDE 4 /* int: number of kernel PDEs */
300: #define CPU_BOOTED_KERNEL 5 /* string: booted kernel name */
301: #define CPU_DISKINFO 6 /* disk geometry information */
302: #define CPU_FPU_PRESENT 7 /* FPU is present */
303: #define CPU_MAXID 8 /* number of valid machdep ids */
304:
305: #define CTL_MACHDEP_NAMES { \
306: { 0, 0 }, \
307: { "console_device", CTLTYPE_STRUCT }, \
308: { "biosbasemem", CTLTYPE_INT }, \
309: { "biosextmem", CTLTYPE_INT }, \
310: { "nkpde", CTLTYPE_INT }, \
311: { "booted_kernel", CTLTYPE_STRING }, \
312: { "diskinfo", CTLTYPE_STRUCT }, \
313: { "fpu_present", CTLTYPE_INT }, \
314: }
315:
316:
317: /*
318: * Structure for CPU_DISKINFO sysctl call.
319: * XXX this should be somewhere else.
320: */
321: #define MAX_BIOSDISKS 16
322:
323: struct disklist {
324: int dl_nbiosdisks; /* number of bios disks */
325: struct biosdisk_info {
326: int bi_dev; /* BIOS device # (0x80 ..) */
327: int bi_cyl; /* cylinders on disk */
328: int bi_head; /* heads per track */
329: int bi_sec; /* sectors per track */
330: u_int64_t bi_lbasecs; /* total sec. (iff ext13) */
331: #define BIFLAG_INVALID 0x01
332: #define BIFLAG_EXTINT13 0x02
333: int bi_flags;
334: } dl_biosdisks[MAX_BIOSDISKS];
335:
336: int dl_nnativedisks; /* number of native disks */
337: struct nativedisk_info {
338: char ni_devname[16]; /* native device name */
339: int ni_nmatches; /* # of matches w/ BIOS */
340: int ni_biosmatches[MAX_BIOSDISKS]; /* indices in dl_biosdisks */
341: } dl_nativedisks[1]; /* actually longer */
342: };
343:
344: #endif /* !_AMD64_CPU_H_ */
CVSweb <webmaster@jp.NetBSD.org>