x86: provide 64-bit with a load_sp0 function.
[sfrench/cifs-2.6.git] / include / asm-x86 / processor_32.h
1 /*
2  * Copyright (C) 1994 Linus Torvalds
3  */
4
5 #ifndef __ASM_I386_PROCESSOR_H
6 #define __ASM_I386_PROCESSOR_H
7
8 #include <asm/vm86.h>
9 #include <asm/math_emu.h>
10 #include <asm/segment.h>
11 #include <asm/page.h>
12 #include <asm/types.h>
13 #include <asm/sigcontext.h>
14 #include <asm/cpufeature.h>
15 #include <asm/msr.h>
16 #include <asm/system.h>
17 #include <linux/cache.h>
18 #include <linux/threads.h>
19 #include <asm/percpu.h>
20 #include <linux/cpumask.h>
21 #include <linux/init.h>
22 #include <asm/desc_defs.h>
23
24 /*
25  *  CPU type and hardware bug flags. Kept separately for each CPU.
26  *  Members of this structure are referenced in head.S, so think twice
27  *  before touching them. [mj]
28  */
29
30 struct cpuinfo_x86 {
31         __u8    x86;            /* CPU family */
32         __u8    x86_vendor;     /* CPU vendor */
33         __u8    x86_model;
34         __u8    x86_mask;
35         char    wp_works_ok;    /* It doesn't on 386's */
36         char    hlt_works_ok;   /* Problems on some 486Dx4's and old 386's */
37         char    hard_math;
38         char    rfu;
39         int     cpuid_level;    /* Maximum supported CPUID level, -1=no CPUID */
40         unsigned long   x86_capability[NCAPINTS];
41         char    x86_vendor_id[16];
42         char    x86_model_id[64];
43         int     x86_cache_size;  /* in KB - valid for CPUS which support this
44                                     call  */
45         int     x86_cache_alignment;    /* In bytes */
46         char    fdiv_bug;
47         char    f00f_bug;
48         char    coma_bug;
49         char    pad0;
50         int     x86_power;
51         unsigned long loops_per_jiffy;
52 #ifdef CONFIG_SMP
53         cpumask_t llc_shared_map;       /* cpus sharing the last level cache */
54 #endif
55         unsigned char x86_max_cores;    /* cpuid returned max cores value */
56         unsigned char apicid;
57         unsigned short x86_clflush_size;
58 #ifdef CONFIG_SMP
59         unsigned char booted_cores;     /* number of cores as seen by OS */
60         __u8 phys_proc_id;              /* Physical processor id. */
61         __u8 cpu_core_id;               /* Core id */
62         __u8 cpu_index;                 /* index into per_cpu list */
63 #endif
64 } __attribute__((__aligned__(SMP_CACHE_BYTES)));
65
66 #define X86_VENDOR_INTEL 0
67 #define X86_VENDOR_CYRIX 1
68 #define X86_VENDOR_AMD 2
69 #define X86_VENDOR_UMC 3
70 #define X86_VENDOR_NEXGEN 4
71 #define X86_VENDOR_CENTAUR 5
72 #define X86_VENDOR_TRANSMETA 7
73 #define X86_VENDOR_NSC 8
74 #define X86_VENDOR_NUM 9
75 #define X86_VENDOR_UNKNOWN 0xff
76
77 /*
78  * capabilities of CPUs
79  */
80
81 extern struct cpuinfo_x86 boot_cpu_data;
82 extern struct cpuinfo_x86 new_cpu_data;
83 extern struct tss_struct doublefault_tss;
84
85 #ifdef CONFIG_SMP
86 DECLARE_PER_CPU(struct cpuinfo_x86, cpu_info);
87 #define cpu_data(cpu)           per_cpu(cpu_info, cpu)
88 #define current_cpu_data        cpu_data(smp_processor_id())
89 #else
90 #define cpu_data(cpu)           boot_cpu_data
91 #define current_cpu_data        boot_cpu_data
92 #endif
93
94 /*
95  * the following now lives in the per cpu area:
96  * extern       int cpu_llc_id[NR_CPUS];
97  */
98 DECLARE_PER_CPU(u8, cpu_llc_id);
99 extern char ignore_fpu_irq;
100
101 void __init cpu_detect(struct cpuinfo_x86 *c);
102
103 extern void identify_boot_cpu(void);
104 extern void identify_secondary_cpu(struct cpuinfo_x86 *);
105
106 #ifdef CONFIG_X86_HT
107 extern void detect_ht(struct cpuinfo_x86 *c);
108 #else
109 static inline void detect_ht(struct cpuinfo_x86 *c) {}
110 #endif
111
112 /* from system description table in BIOS.  Mostly for MCA use, but
113 others may find it useful. */
114 extern unsigned int machine_id;
115 extern unsigned int machine_submodel_id;
116 extern unsigned int BIOS_revision;
117 extern unsigned int mca_pentium_flag;
118
119 /*
120  * User space process size: 3GB (default).
121  */
122 #define TASK_SIZE       (PAGE_OFFSET)
123
124
125 struct i387_fsave_struct {
126         long    cwd;
127         long    swd;
128         long    twd;
129         long    fip;
130         long    fcs;
131         long    foo;
132         long    fos;
133         long    st_space[20];   /* 8*10 bytes for each FP-reg = 80 bytes */
134         long    status;         /* software status information */
135 };
136
137 struct i387_fxsave_struct {
138         unsigned short  cwd;
139         unsigned short  swd;
140         unsigned short  twd;
141         unsigned short  fop;
142         long    fip;
143         long    fcs;
144         long    foo;
145         long    fos;
146         long    mxcsr;
147         long    mxcsr_mask;
148         long    st_space[32];   /* 8*16 bytes for each FP-reg = 128 bytes */
149         long    xmm_space[32];  /* 8*16 bytes for each XMM-reg = 128 bytes */
150         long    padding[56];
151 } __attribute__ ((aligned (16)));
152
153 struct i387_soft_struct {
154         long    cwd;
155         long    swd;
156         long    twd;
157         long    fip;
158         long    fcs;
159         long    foo;
160         long    fos;
161         long    st_space[20];   /* 8*10 bytes for each FP-reg = 80 bytes */
162         unsigned char   ftop, changed, lookahead, no_update, rm, alimit;
163         struct info     *info;
164         unsigned long   entry_eip;
165 };
166
167 union i387_union {
168         struct i387_fsave_struct        fsave;
169         struct i387_fxsave_struct       fxsave;
170         struct i387_soft_struct soft;
171 };
172
173 typedef struct {
174         unsigned long seg;
175 } mm_segment_t;
176
177 #define ARCH_MIN_TASKALIGN      16
178
179 struct thread_struct {
180 /* cached TLS descriptors. */
181         struct desc_struct tls_array[GDT_ENTRY_TLS_ENTRIES];
182         unsigned long   sp0;
183         unsigned long   sysenter_cs;
184         unsigned long   ip;
185         unsigned long   sp;
186         unsigned long   fs;
187         unsigned long   gs;
188 /* Hardware debugging registers */
189         unsigned long   debugreg0;
190         unsigned long   debugreg1;
191         unsigned long   debugreg2;
192         unsigned long   debugreg3;
193         unsigned long   debugreg6;
194         unsigned long   debugreg7;
195 /* fault info */
196         unsigned long   cr2, trap_no, error_code;
197 /* floating point info */
198         union i387_union        i387;
199 /* virtual 86 mode info */
200         struct vm86_struct __user * vm86_info;
201         unsigned long           screen_bitmap;
202         unsigned long           v86flags, v86mask, saved_sp0;
203         unsigned int            saved_fs, saved_gs;
204 /* IO permissions */
205         unsigned long   *io_bitmap_ptr;
206         unsigned long   iopl;
207 /* max allowed port in the bitmap, in bytes: */
208         unsigned long   io_bitmap_max;
209 /* MSR_IA32_DEBUGCTLMSR value to switch in if TIF_DEBUGCTLMSR is set.  */
210         unsigned long   debugctlmsr;
211 /* Debug Store - if not 0 points to a DS Save Area configuration;
212  *               goes into MSR_IA32_DS_AREA */
213         unsigned long   ds_area_msr;
214 };
215
216 #define INIT_THREAD  {                                                  \
217         .sp0 = sizeof(init_stack) + (long)&init_stack,                  \
218         .vm86_info = NULL,                                              \
219         .sysenter_cs = __KERNEL_CS,                                     \
220         .io_bitmap_ptr = NULL,                                          \
221         .fs = __KERNEL_PERCPU,                                          \
222 }
223
224 /*
225  * Note that the .io_bitmap member must be extra-big. This is because
226  * the CPU will access an additional byte beyond the end of the IO
227  * permission bitmap. The extra byte must be all 1 bits, and must
228  * be within the limit.
229  */
230 #define INIT_TSS  {                                                     \
231         .x86_tss = {                                                    \
232                 .sp0            = sizeof(init_stack) + (long)&init_stack, \
233                 .ss0            = __KERNEL_DS,                          \
234                 .ss1            = __KERNEL_CS,                          \
235                 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET,             \
236          },                                                             \
237         .io_bitmap      = { [ 0 ... IO_BITMAP_LONGS] = ~0 },            \
238 }
239
240 #define start_thread(regs, new_eip, new_esp) do {               \
241         __asm__("movl %0,%%gs": :"r" (0));                      \
242         regs->fs = 0;                                           \
243         set_fs(USER_DS);                                        \
244         regs->ds = __USER_DS;                                   \
245         regs->es = __USER_DS;                                   \
246         regs->ss = __USER_DS;                                   \
247         regs->cs = __USER_CS;                                   \
248         regs->ip = new_eip;                                     \
249         regs->sp = new_esp;                                     \
250 } while (0)
251
252
253 extern unsigned long thread_saved_pc(struct task_struct *tsk);
254
255 #define THREAD_SIZE_LONGS      (THREAD_SIZE/sizeof(unsigned long))
256 #define KSTK_TOP(info)                                                 \
257 ({                                                                     \
258        unsigned long *__ptr = (unsigned long *)(info);                 \
259        (unsigned long)(&__ptr[THREAD_SIZE_LONGS]);                     \
260 })
261
262 /*
263  * The below -8 is to reserve 8 bytes on top of the ring0 stack.
264  * This is necessary to guarantee that the entire "struct pt_regs"
265  * is accessable even if the CPU haven't stored the SS/ESP registers
266  * on the stack (interrupt gate does not save these registers
267  * when switching to the same priv ring).
268  * Therefore beware: accessing the ss/esp fields of the
269  * "struct pt_regs" is possible, but they may contain the
270  * completely wrong values.
271  */
272 #define task_pt_regs(task)                                             \
273 ({                                                                     \
274        struct pt_regs *__regs__;                                       \
275        __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
276        __regs__ - 1;                                                   \
277 })
278
279 #define KSTK_ESP(task) (task_pt_regs(task)->sp)
280
281 /* generic versions from gas */
282 #define GENERIC_NOP1    ".byte 0x90\n"
283 #define GENERIC_NOP2            ".byte 0x89,0xf6\n"
284 #define GENERIC_NOP3        ".byte 0x8d,0x76,0x00\n"
285 #define GENERIC_NOP4        ".byte 0x8d,0x74,0x26,0x00\n"
286 #define GENERIC_NOP5        GENERIC_NOP1 GENERIC_NOP4
287 #define GENERIC_NOP6    ".byte 0x8d,0xb6,0x00,0x00,0x00,0x00\n"
288 #define GENERIC_NOP7    ".byte 0x8d,0xb4,0x26,0x00,0x00,0x00,0x00\n"
289 #define GENERIC_NOP8    GENERIC_NOP1 GENERIC_NOP7
290
291 /* Opteron nops */
292 #define K8_NOP1 GENERIC_NOP1
293 #define K8_NOP2 ".byte 0x66,0x90\n" 
294 #define K8_NOP3 ".byte 0x66,0x66,0x90\n" 
295 #define K8_NOP4 ".byte 0x66,0x66,0x66,0x90\n" 
296 #define K8_NOP5 K8_NOP3 K8_NOP2 
297 #define K8_NOP6 K8_NOP3 K8_NOP3
298 #define K8_NOP7 K8_NOP4 K8_NOP3
299 #define K8_NOP8 K8_NOP4 K8_NOP4
300
301 /* K7 nops */
302 /* uses eax dependencies (arbitary choice) */
303 #define K7_NOP1  GENERIC_NOP1
304 #define K7_NOP2 ".byte 0x8b,0xc0\n" 
305 #define K7_NOP3 ".byte 0x8d,0x04,0x20\n"
306 #define K7_NOP4 ".byte 0x8d,0x44,0x20,0x00\n"
307 #define K7_NOP5 K7_NOP4 ASM_NOP1
308 #define K7_NOP6 ".byte 0x8d,0x80,0,0,0,0\n"
309 #define K7_NOP7        ".byte 0x8D,0x04,0x05,0,0,0,0\n"
310 #define K7_NOP8        K7_NOP7 ASM_NOP1
311
312 /* P6 nops */
313 /* uses eax dependencies (Intel-recommended choice) */
314 #define P6_NOP1 GENERIC_NOP1
315 #define P6_NOP2 ".byte 0x66,0x90\n"
316 #define P6_NOP3 ".byte 0x0f,0x1f,0x00\n"
317 #define P6_NOP4 ".byte 0x0f,0x1f,0x40,0\n"
318 #define P6_NOP5 ".byte 0x0f,0x1f,0x44,0x00,0\n"
319 #define P6_NOP6 ".byte 0x66,0x0f,0x1f,0x44,0x00,0\n"
320 #define P6_NOP7 ".byte 0x0f,0x1f,0x80,0,0,0,0\n"
321 #define P6_NOP8 ".byte 0x0f,0x1f,0x84,0x00,0,0,0,0\n"
322
323 #ifdef CONFIG_MK8
324 #define ASM_NOP1 K8_NOP1
325 #define ASM_NOP2 K8_NOP2
326 #define ASM_NOP3 K8_NOP3
327 #define ASM_NOP4 K8_NOP4
328 #define ASM_NOP5 K8_NOP5
329 #define ASM_NOP6 K8_NOP6
330 #define ASM_NOP7 K8_NOP7
331 #define ASM_NOP8 K8_NOP8
332 #elif defined(CONFIG_MK7)
333 #define ASM_NOP1 K7_NOP1
334 #define ASM_NOP2 K7_NOP2
335 #define ASM_NOP3 K7_NOP3
336 #define ASM_NOP4 K7_NOP4
337 #define ASM_NOP5 K7_NOP5
338 #define ASM_NOP6 K7_NOP6
339 #define ASM_NOP7 K7_NOP7
340 #define ASM_NOP8 K7_NOP8
341 #elif defined(CONFIG_M686) || defined(CONFIG_MPENTIUMII) || \
342       defined(CONFIG_MPENTIUMIII) || defined(CONFIG_MPENTIUMM) || \
343       defined(CONFIG_MCORE2) || defined(CONFIG_PENTIUM4)
344 #define ASM_NOP1 P6_NOP1
345 #define ASM_NOP2 P6_NOP2
346 #define ASM_NOP3 P6_NOP3
347 #define ASM_NOP4 P6_NOP4
348 #define ASM_NOP5 P6_NOP5
349 #define ASM_NOP6 P6_NOP6
350 #define ASM_NOP7 P6_NOP7
351 #define ASM_NOP8 P6_NOP8
352 #else
353 #define ASM_NOP1 GENERIC_NOP1
354 #define ASM_NOP2 GENERIC_NOP2
355 #define ASM_NOP3 GENERIC_NOP3
356 #define ASM_NOP4 GENERIC_NOP4
357 #define ASM_NOP5 GENERIC_NOP5
358 #define ASM_NOP6 GENERIC_NOP6
359 #define ASM_NOP7 GENERIC_NOP7
360 #define ASM_NOP8 GENERIC_NOP8
361 #endif
362
363 #define ASM_NOP_MAX 8
364
365 /* Prefetch instructions for Pentium III and AMD Athlon */
366 /* It's not worth to care about 3dnow! prefetches for the K6
367    because they are microcoded there and very slow.
368    However we don't do prefetches for pre XP Athlons currently
369    That should be fixed. */
370 static inline void prefetch(const void *x)
371 {
372         alternative_input(ASM_NOP4,
373                           "prefetchnta (%1)",
374                           X86_FEATURE_XMM,
375                           "r" (x));
376 }
377
378 #define ARCH_HAS_PREFETCH
379
380 /* 3dnow! prefetch to get an exclusive cache line. Useful for 
381    spinlocks to avoid one state transition in the cache coherency protocol. */
382 static inline void prefetchw(const void *x)
383 {
384         alternative_input(ASM_NOP4,
385                           "prefetchw (%1)",
386                           X86_FEATURE_3DNOW,
387                           "r" (x));
388 }
389
390 extern void enable_sep_cpu(void);
391 extern int sysenter_setup(void);
392
393 /* Defined in head.S */
394 extern struct desc_ptr early_gdt_descr;
395
396 extern void cpu_set_gdt(int);
397 extern void switch_to_new_gdt(void);
398 extern void cpu_init(void);
399 extern void init_gdt(int cpu);
400
401 #endif /* __ASM_I386_PROCESSOR_H */