H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_PROCESSOR_H |
| 2 | #define _ASM_X86_PROCESSOR_H |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 3 | |
Glauber de Oliveira Costa | 053de04 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 4 | #include <asm/processor-flags.h> |
| 5 | |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 6 | /* Forward declaration, a strange C thing */ |
| 7 | struct task_struct; |
| 8 | struct mm_struct; |
| 9 | |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 10 | #include <asm/vm86.h> |
| 11 | #include <asm/math_emu.h> |
| 12 | #include <asm/segment.h> |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 13 | #include <asm/types.h> |
| 14 | #include <asm/sigcontext.h> |
| 15 | #include <asm/current.h> |
| 16 | #include <asm/cpufeature.h> |
Glauber de Oliveira Costa | c72dcf8 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 17 | #include <asm/page.h> |
Jeremy Fitzhardinge | 54321d9 | 2009-02-11 10:20:05 -0800 | [diff] [blame] | 18 | #include <asm/pgtable_types.h> |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 19 | #include <asm/percpu.h> |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 20 | #include <asm/msr.h> |
| 21 | #include <asm/desc_defs.h> |
Andi Kleen | bd61643 | 2008-01-30 13:32:38 +0100 | [diff] [blame] | 22 | #include <asm/nops.h> |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame^] | 23 | #include <asm/special_insns.h> |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 24 | |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 25 | #include <linux/personality.h> |
Glauber de Oliveira Costa | 5300db8 | 2008-01-30 13:31:33 +0100 | [diff] [blame] | 26 | #include <linux/cpumask.h> |
| 27 | #include <linux/cache.h> |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 28 | #include <linux/threads.h> |
Peter Zijlstra | 5cbc19a | 2009-09-02 11:49:52 +0200 | [diff] [blame] | 29 | #include <linux/math64.h> |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 30 | #include <linux/init.h> |
Peter Zijlstra | faa4602 | 2010-03-25 14:51:50 +0100 | [diff] [blame] | 31 | #include <linux/err.h> |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame^] | 32 | #include <linux/irqflags.h> |
| 33 | |
| 34 | /* |
| 35 | * We handle most unaligned accesses in hardware. On the other hand |
| 36 | * unaligned DMA can be quite expensive on some Nehalem processors. |
| 37 | * |
| 38 | * Based on this we disable the IP header alignment in network drivers. |
| 39 | */ |
| 40 | #define NET_IP_ALIGN 0 |
Glauber de Oliveira Costa | c72dcf8 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 41 | |
K.Prasad | b332828c | 2009-06-01 23:43:10 +0530 | [diff] [blame] | 42 | #define HBP_NUM 4 |
Glauber de Oliveira Costa | 0ccb8ac | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 43 | /* |
| 44 | * Default implementation of macro that returns current |
| 45 | * instruction pointer ("program counter"). |
| 46 | */ |
| 47 | static inline void *current_text_addr(void) |
| 48 | { |
| 49 | void *pc; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 50 | |
| 51 | asm volatile("mov $1f, %0; 1:":"=r" (pc)); |
| 52 | |
Glauber de Oliveira Costa | 0ccb8ac | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 53 | return pc; |
| 54 | } |
| 55 | |
Glauber de Oliveira Costa | dbcb466 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 56 | #ifdef CONFIG_X86_VSMP |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 57 | # define ARCH_MIN_TASKALIGN (1 << INTERNODE_CACHE_SHIFT) |
| 58 | # define ARCH_MIN_MMSTRUCT_ALIGN (1 << INTERNODE_CACHE_SHIFT) |
Glauber de Oliveira Costa | dbcb466 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 59 | #else |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 60 | # define ARCH_MIN_TASKALIGN 16 |
| 61 | # define ARCH_MIN_MMSTRUCT_ALIGN 0 |
Glauber de Oliveira Costa | dbcb466 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 62 | #endif |
| 63 | |
Glauber de Oliveira Costa | 5300db8 | 2008-01-30 13:31:33 +0100 | [diff] [blame] | 64 | /* |
| 65 | * CPU type and hardware bug flags. Kept separately for each CPU. |
| 66 | * Members of this structure are referenced in head.S, so think twice |
| 67 | * before touching them. [mj] |
| 68 | */ |
| 69 | |
| 70 | struct cpuinfo_x86 { |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 71 | __u8 x86; /* CPU family */ |
| 72 | __u8 x86_vendor; /* CPU vendor */ |
| 73 | __u8 x86_model; |
| 74 | __u8 x86_mask; |
Glauber de Oliveira Costa | 5300db8 | 2008-01-30 13:31:33 +0100 | [diff] [blame] | 75 | #ifdef CONFIG_X86_32 |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 76 | char wp_works_ok; /* It doesn't on 386's */ |
| 77 | |
| 78 | /* Problems on some 486Dx4's and old 386's: */ |
| 79 | char hlt_works_ok; |
| 80 | char hard_math; |
| 81 | char rfu; |
| 82 | char fdiv_bug; |
| 83 | char f00f_bug; |
| 84 | char coma_bug; |
| 85 | char pad0; |
Glauber de Oliveira Costa | 5300db8 | 2008-01-30 13:31:33 +0100 | [diff] [blame] | 86 | #else |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 87 | /* Number of 4K pages in DTLB/ITLB combined(in pages): */ |
H. Peter Anvin | b1882e6 | 2009-01-23 17:18:52 -0800 | [diff] [blame] | 88 | int x86_tlbsize; |
Jan Beulich | 13c6c53 | 2009-03-12 12:37:34 +0000 | [diff] [blame] | 89 | #endif |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 90 | __u8 x86_virt_bits; |
| 91 | __u8 x86_phys_bits; |
| 92 | /* CPUID returned core id bits: */ |
| 93 | __u8 x86_coreid_bits; |
| 94 | /* Max extended CPUID function supported: */ |
| 95 | __u32 extended_cpuid_level; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 96 | /* Maximum supported CPUID level, -1=no CPUID: */ |
| 97 | int cpuid_level; |
| 98 | __u32 x86_capability[NCAPINTS]; |
| 99 | char x86_vendor_id[16]; |
| 100 | char x86_model_id[64]; |
| 101 | /* in KB - valid for CPUS which support this call: */ |
| 102 | int x86_cache_size; |
| 103 | int x86_cache_alignment; /* In bytes */ |
| 104 | int x86_power; |
| 105 | unsigned long loops_per_jiffy; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 106 | /* cpuid returned max cores value: */ |
| 107 | u16 x86_max_cores; |
| 108 | u16 apicid; |
Yinghai Lu | 01aaea1 | 2008-03-06 13:46:39 -0800 | [diff] [blame] | 109 | u16 initial_apicid; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 110 | u16 x86_clflush_size; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 111 | /* number of cores as seen by the OS: */ |
| 112 | u16 booted_cores; |
| 113 | /* Physical processor id: */ |
| 114 | u16 phys_proc_id; |
| 115 | /* Core id: */ |
| 116 | u16 cpu_core_id; |
Andreas Herrmann | 6057b4d | 2010-09-30 14:38:57 +0200 | [diff] [blame] | 117 | /* Compute unit id */ |
| 118 | u8 compute_unit_id; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 119 | /* Index into per_cpu list: */ |
| 120 | u16 cpu_index; |
Andi Kleen | 506ed6b | 2011-10-12 17:46:33 -0700 | [diff] [blame] | 121 | u32 microcode; |
Glauber de Oliveira Costa | 5300db8 | 2008-01-30 13:31:33 +0100 | [diff] [blame] | 122 | } __attribute__((__aligned__(SMP_CACHE_BYTES))); |
| 123 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 124 | #define X86_VENDOR_INTEL 0 |
| 125 | #define X86_VENDOR_CYRIX 1 |
| 126 | #define X86_VENDOR_AMD 2 |
| 127 | #define X86_VENDOR_UMC 3 |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 128 | #define X86_VENDOR_CENTAUR 5 |
| 129 | #define X86_VENDOR_TRANSMETA 7 |
| 130 | #define X86_VENDOR_NSC 8 |
| 131 | #define X86_VENDOR_NUM 9 |
| 132 | |
| 133 | #define X86_VENDOR_UNKNOWN 0xff |
Glauber de Oliveira Costa | 5300db8 | 2008-01-30 13:31:33 +0100 | [diff] [blame] | 134 | |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 135 | /* |
| 136 | * capabilities of CPUs |
| 137 | */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 138 | extern struct cpuinfo_x86 boot_cpu_data; |
| 139 | extern struct cpuinfo_x86 new_cpu_data; |
| 140 | |
| 141 | extern struct tss_struct doublefault_tss; |
Yinghai Lu | 3e0c373 | 2009-05-09 23:47:42 -0700 | [diff] [blame] | 142 | extern __u32 cpu_caps_cleared[NCAPINTS]; |
| 143 | extern __u32 cpu_caps_set[NCAPINTS]; |
Glauber de Oliveira Costa | 5300db8 | 2008-01-30 13:31:33 +0100 | [diff] [blame] | 144 | |
| 145 | #ifdef CONFIG_SMP |
David Howells | 9b8de74 | 2009-04-21 23:00:24 +0100 | [diff] [blame] | 146 | DECLARE_PER_CPU_SHARED_ALIGNED(struct cpuinfo_x86, cpu_info); |
Glauber de Oliveira Costa | 5300db8 | 2008-01-30 13:31:33 +0100 | [diff] [blame] | 147 | #define cpu_data(cpu) per_cpu(cpu_info, cpu) |
Glauber de Oliveira Costa | 5300db8 | 2008-01-30 13:31:33 +0100 | [diff] [blame] | 148 | #else |
Tejun Heo | 7b543a5 | 2010-12-18 16:30:05 +0100 | [diff] [blame] | 149 | #define cpu_info boot_cpu_data |
Glauber de Oliveira Costa | 5300db8 | 2008-01-30 13:31:33 +0100 | [diff] [blame] | 150 | #define cpu_data(cpu) boot_cpu_data |
Glauber de Oliveira Costa | 5300db8 | 2008-01-30 13:31:33 +0100 | [diff] [blame] | 151 | #endif |
| 152 | |
Jaswinder Singh | 1c6c727 | 2008-07-21 22:40:37 +0530 | [diff] [blame] | 153 | extern const struct seq_operations cpuinfo_op; |
| 154 | |
Glauber Costa | 3d3f487 | 2008-03-03 14:12:48 -0300 | [diff] [blame] | 155 | static inline int hlt_works(int cpu) |
| 156 | { |
| 157 | #ifdef CONFIG_X86_32 |
| 158 | return cpu_data(cpu).hlt_works_ok; |
| 159 | #else |
| 160 | return 1; |
| 161 | #endif |
| 162 | } |
| 163 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 164 | #define cache_line_size() (boot_cpu_data.x86_cache_alignment) |
| 165 | |
| 166 | extern void cpu_detect(struct cpuinfo_x86 *c); |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 167 | |
Jaswinder Singh | 8fd329a | 2008-07-21 22:54:56 +0530 | [diff] [blame] | 168 | extern struct pt_regs *idle_regs(struct pt_regs *); |
| 169 | |
Yinghai Lu | f580366 | 2008-06-21 03:24:19 -0700 | [diff] [blame] | 170 | extern void early_cpu_init(void); |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 171 | extern void identify_boot_cpu(void); |
| 172 | extern void identify_secondary_cpu(struct cpuinfo_x86 *); |
Glauber de Oliveira Costa | 5300db8 | 2008-01-30 13:31:33 +0100 | [diff] [blame] | 173 | extern void print_cpu_info(struct cpuinfo_x86 *); |
Yinghai Lu | 21c3fcf | 2012-02-12 09:53:57 -0800 | [diff] [blame] | 174 | void print_cpu_msr(struct cpuinfo_x86 *); |
Glauber de Oliveira Costa | 5300db8 | 2008-01-30 13:31:33 +0100 | [diff] [blame] | 175 | extern void init_scattered_cpuid_features(struct cpuinfo_x86 *c); |
| 176 | extern unsigned int init_intel_cacheinfo(struct cpuinfo_x86 *c); |
| 177 | extern unsigned short num_cache_leaves; |
| 178 | |
Suresh Siddha | bbb65d2 | 2008-08-23 17:47:10 +0200 | [diff] [blame] | 179 | extern void detect_extended_topology(struct cpuinfo_x86 *c); |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 180 | extern void detect_ht(struct cpuinfo_x86 *c); |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 181 | |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 182 | static inline void native_cpuid(unsigned int *eax, unsigned int *ebx, |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 183 | unsigned int *ecx, unsigned int *edx) |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 184 | { |
| 185 | /* ecx is often an input as well as an output. */ |
Suresh Siddha | 45a94d7 | 2009-12-16 16:25:42 -0800 | [diff] [blame] | 186 | asm volatile("cpuid" |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 187 | : "=a" (*eax), |
| 188 | "=b" (*ebx), |
| 189 | "=c" (*ecx), |
| 190 | "=d" (*edx) |
Andi Kleen | 506ed6b | 2011-10-12 17:46:33 -0700 | [diff] [blame] | 191 | : "0" (*eax), "2" (*ecx) |
| 192 | : "memory"); |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 193 | } |
| 194 | |
Glauber de Oliveira Costa | c72dcf8 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 195 | static inline void load_cr3(pgd_t *pgdir) |
| 196 | { |
| 197 | write_cr3(__pa(pgdir)); |
| 198 | } |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 199 | |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 200 | #ifdef CONFIG_X86_32 |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 201 | /* This is the TSS defined by the hardware. */ |
| 202 | struct x86_hw_tss { |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 203 | unsigned short back_link, __blh; |
| 204 | unsigned long sp0; |
| 205 | unsigned short ss0, __ss0h; |
| 206 | unsigned long sp1; |
| 207 | /* ss1 caches MSR_IA32_SYSENTER_CS: */ |
| 208 | unsigned short ss1, __ss1h; |
| 209 | unsigned long sp2; |
| 210 | unsigned short ss2, __ss2h; |
| 211 | unsigned long __cr3; |
| 212 | unsigned long ip; |
| 213 | unsigned long flags; |
| 214 | unsigned long ax; |
| 215 | unsigned long cx; |
| 216 | unsigned long dx; |
| 217 | unsigned long bx; |
| 218 | unsigned long sp; |
| 219 | unsigned long bp; |
| 220 | unsigned long si; |
| 221 | unsigned long di; |
| 222 | unsigned short es, __esh; |
| 223 | unsigned short cs, __csh; |
| 224 | unsigned short ss, __ssh; |
| 225 | unsigned short ds, __dsh; |
| 226 | unsigned short fs, __fsh; |
| 227 | unsigned short gs, __gsh; |
| 228 | unsigned short ldt, __ldth; |
| 229 | unsigned short trace; |
| 230 | unsigned short io_bitmap_base; |
| 231 | |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 232 | } __attribute__((packed)); |
| 233 | #else |
| 234 | struct x86_hw_tss { |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 235 | u32 reserved1; |
| 236 | u64 sp0; |
| 237 | u64 sp1; |
| 238 | u64 sp2; |
| 239 | u64 reserved2; |
| 240 | u64 ist[7]; |
| 241 | u32 reserved3; |
| 242 | u32 reserved4; |
| 243 | u16 reserved5; |
| 244 | u16 io_bitmap_base; |
| 245 | |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 246 | } __attribute__((packed)) ____cacheline_aligned; |
| 247 | #endif |
| 248 | |
| 249 | /* |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 250 | * IO-bitmap sizes: |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 251 | */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 252 | #define IO_BITMAP_BITS 65536 |
| 253 | #define IO_BITMAP_BYTES (IO_BITMAP_BITS/8) |
| 254 | #define IO_BITMAP_LONGS (IO_BITMAP_BYTES/sizeof(long)) |
| 255 | #define IO_BITMAP_OFFSET offsetof(struct tss_struct, io_bitmap) |
| 256 | #define INVALID_IO_BITMAP_OFFSET 0x8000 |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 257 | |
| 258 | struct tss_struct { |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 259 | /* |
| 260 | * The hardware state: |
| 261 | */ |
| 262 | struct x86_hw_tss x86_tss; |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 263 | |
| 264 | /* |
| 265 | * The extra 1 is there because the CPU will access an |
| 266 | * additional byte beyond the end of the IO permission |
| 267 | * bitmap. The extra byte must be all 1 bits, and must |
| 268 | * be within the limit. |
| 269 | */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 270 | unsigned long io_bitmap[IO_BITMAP_LONGS + 1]; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 271 | |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 272 | /* |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 273 | * .. and then another 0x100 bytes for the emergency kernel stack: |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 274 | */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 275 | unsigned long stack[64]; |
| 276 | |
Richard Kennedy | 84e65b0 | 2008-07-04 13:56:16 +0100 | [diff] [blame] | 277 | } ____cacheline_aligned; |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 278 | |
David Howells | 9b8de74 | 2009-04-21 23:00:24 +0100 | [diff] [blame] | 279 | DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss); |
Glauber de Oliveira Costa | ca241c7 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 280 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 281 | /* |
| 282 | * Save the original ist values for checking stack pointers during debugging |
| 283 | */ |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 284 | struct orig_ist { |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 285 | unsigned long ist[7]; |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 286 | }; |
| 287 | |
Roland McGrath | 99f8ecd | 2008-01-30 13:31:48 +0100 | [diff] [blame] | 288 | #define MXCSR_DEFAULT 0x1f80 |
| 289 | |
Glauber de Oliveira Costa | 46265df | 2008-01-30 13:31:41 +0100 | [diff] [blame] | 290 | struct i387_fsave_struct { |
Ingo Molnar | ca9cda2 | 2008-03-05 15:15:42 +0100 | [diff] [blame] | 291 | u32 cwd; /* FPU Control Word */ |
| 292 | u32 swd; /* FPU Status Word */ |
| 293 | u32 twd; /* FPU Tag Word */ |
| 294 | u32 fip; /* FPU IP Offset */ |
| 295 | u32 fcs; /* FPU IP Selector */ |
| 296 | u32 foo; /* FPU Operand Pointer Offset */ |
| 297 | u32 fos; /* FPU Operand Pointer Selector */ |
| 298 | |
| 299 | /* 8*10 bytes for each FP-reg = 80 bytes: */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 300 | u32 st_space[20]; |
Ingo Molnar | ca9cda2 | 2008-03-05 15:15:42 +0100 | [diff] [blame] | 301 | |
| 302 | /* Software status information [not touched by FSAVE ]: */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 303 | u32 status; |
Glauber de Oliveira Costa | 46265df | 2008-01-30 13:31:41 +0100 | [diff] [blame] | 304 | }; |
| 305 | |
| 306 | struct i387_fxsave_struct { |
Ingo Molnar | ca9cda2 | 2008-03-05 15:15:42 +0100 | [diff] [blame] | 307 | u16 cwd; /* Control Word */ |
| 308 | u16 swd; /* Status Word */ |
| 309 | u16 twd; /* Tag Word */ |
| 310 | u16 fop; /* Last Instruction Opcode */ |
Roland McGrath | 99f8ecd | 2008-01-30 13:31:48 +0100 | [diff] [blame] | 311 | union { |
| 312 | struct { |
Ingo Molnar | ca9cda2 | 2008-03-05 15:15:42 +0100 | [diff] [blame] | 313 | u64 rip; /* Instruction Pointer */ |
| 314 | u64 rdp; /* Data Pointer */ |
Roland McGrath | 99f8ecd | 2008-01-30 13:31:48 +0100 | [diff] [blame] | 315 | }; |
| 316 | struct { |
Ingo Molnar | ca9cda2 | 2008-03-05 15:15:42 +0100 | [diff] [blame] | 317 | u32 fip; /* FPU IP Offset */ |
| 318 | u32 fcs; /* FPU IP Selector */ |
| 319 | u32 foo; /* FPU Operand Offset */ |
| 320 | u32 fos; /* FPU Operand Selector */ |
Roland McGrath | 99f8ecd | 2008-01-30 13:31:48 +0100 | [diff] [blame] | 321 | }; |
| 322 | }; |
Ingo Molnar | ca9cda2 | 2008-03-05 15:15:42 +0100 | [diff] [blame] | 323 | u32 mxcsr; /* MXCSR Register State */ |
| 324 | u32 mxcsr_mask; /* MXCSR Mask */ |
| 325 | |
| 326 | /* 8*16 bytes for each FP-reg = 128 bytes: */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 327 | u32 st_space[32]; |
Ingo Molnar | ca9cda2 | 2008-03-05 15:15:42 +0100 | [diff] [blame] | 328 | |
| 329 | /* 16*16 bytes for each XMM-reg = 256 bytes: */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 330 | u32 xmm_space[64]; |
Ingo Molnar | ca9cda2 | 2008-03-05 15:15:42 +0100 | [diff] [blame] | 331 | |
Suresh Siddha | bdd8cab | 2008-07-29 10:29:24 -0700 | [diff] [blame] | 332 | u32 padding[12]; |
| 333 | |
| 334 | union { |
| 335 | u32 padding1[12]; |
| 336 | u32 sw_reserved[12]; |
| 337 | }; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 338 | |
Glauber de Oliveira Costa | 46265df | 2008-01-30 13:31:41 +0100 | [diff] [blame] | 339 | } __attribute__((aligned(16))); |
| 340 | |
Roland McGrath | 99f8ecd | 2008-01-30 13:31:48 +0100 | [diff] [blame] | 341 | struct i387_soft_struct { |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 342 | u32 cwd; |
| 343 | u32 swd; |
| 344 | u32 twd; |
| 345 | u32 fip; |
| 346 | u32 fcs; |
| 347 | u32 foo; |
| 348 | u32 fos; |
| 349 | /* 8*10 bytes for each FP-reg = 80 bytes: */ |
| 350 | u32 st_space[20]; |
| 351 | u8 ftop; |
| 352 | u8 changed; |
| 353 | u8 lookahead; |
| 354 | u8 no_update; |
| 355 | u8 rm; |
| 356 | u8 alimit; |
Tejun Heo | ae6af41 | 2009-02-09 22:17:39 +0900 | [diff] [blame] | 357 | struct math_emu_info *info; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 358 | u32 entry_eip; |
Glauber de Oliveira Costa | 46265df | 2008-01-30 13:31:41 +0100 | [diff] [blame] | 359 | }; |
| 360 | |
Suresh Siddha | a30469e | 2009-04-10 15:21:24 -0700 | [diff] [blame] | 361 | struct ymmh_struct { |
| 362 | /* 16 * 16 bytes for each YMMH-reg = 256 bytes */ |
| 363 | u32 ymmh_space[64]; |
| 364 | }; |
| 365 | |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 366 | struct xsave_hdr_struct { |
| 367 | u64 xstate_bv; |
| 368 | u64 reserved1[2]; |
| 369 | u64 reserved2[5]; |
| 370 | } __attribute__((packed)); |
| 371 | |
| 372 | struct xsave_struct { |
| 373 | struct i387_fxsave_struct i387; |
| 374 | struct xsave_hdr_struct xsave_hdr; |
Suresh Siddha | a30469e | 2009-04-10 15:21:24 -0700 | [diff] [blame] | 375 | struct ymmh_struct ymmh; |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 376 | /* new processor state extensions will go here */ |
| 377 | } __attribute__ ((packed, aligned (64))); |
| 378 | |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 379 | union thread_xstate { |
Roland McGrath | 99f8ecd | 2008-01-30 13:31:48 +0100 | [diff] [blame] | 380 | struct i387_fsave_struct fsave; |
| 381 | struct i387_fxsave_struct fxsave; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 382 | struct i387_soft_struct soft; |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 383 | struct xsave_struct xsave; |
Roland McGrath | 99f8ecd | 2008-01-30 13:31:48 +0100 | [diff] [blame] | 384 | }; |
| 385 | |
Avi Kivity | 8660328 | 2010-05-06 11:45:46 +0300 | [diff] [blame] | 386 | struct fpu { |
Linus Torvalds | 7e16838 | 2012-02-19 13:27:00 -0800 | [diff] [blame] | 387 | unsigned int last_cpu; |
| 388 | unsigned int has_fpu; |
Avi Kivity | 8660328 | 2010-05-06 11:45:46 +0300 | [diff] [blame] | 389 | union thread_xstate *state; |
| 390 | }; |
| 391 | |
Glauber Costa | fe67620 | 2008-03-03 14:12:56 -0300 | [diff] [blame] | 392 | #ifdef CONFIG_X86_64 |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 393 | DECLARE_PER_CPU(struct orig_ist, orig_ist); |
Brian Gerst | 26f80bd | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 394 | |
Brian Gerst | 947e76c | 2009-01-19 12:21:28 +0900 | [diff] [blame] | 395 | union irq_stack_union { |
| 396 | char irq_stack[IRQ_STACK_SIZE]; |
| 397 | /* |
| 398 | * GCC hardcodes the stack canary as %gs:40. Since the |
| 399 | * irq_stack is the object at %gs:0, we reserve the bottom |
| 400 | * 48 bytes of the irq stack for the canary. |
| 401 | */ |
| 402 | struct { |
| 403 | char gs_base[40]; |
| 404 | unsigned long stack_canary; |
| 405 | }; |
| 406 | }; |
| 407 | |
David Howells | 9b8de74 | 2009-04-21 23:00:24 +0100 | [diff] [blame] | 408 | DECLARE_PER_CPU_FIRST(union irq_stack_union, irq_stack_union); |
Brian Gerst | 2add8e2 | 2009-02-08 09:58:39 -0500 | [diff] [blame] | 409 | DECLARE_INIT_PER_CPU(irq_stack_union); |
| 410 | |
Brian Gerst | 26f80bd | 2009-01-19 00:38:58 +0900 | [diff] [blame] | 411 | DECLARE_PER_CPU(char *, irq_stack_ptr); |
Jaswinder Singh Rajput | 9766cdb | 2009-03-14 11:19:49 +0530 | [diff] [blame] | 412 | DECLARE_PER_CPU(unsigned int, irq_count); |
| 413 | extern unsigned long kernel_eflags; |
| 414 | extern asmlinkage void ignore_sysret(void); |
Tejun Heo | 60a5317 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 415 | #else /* X86_64 */ |
| 416 | #ifdef CONFIG_CC_STACKPROTECTOR |
Jeremy Fitzhardinge | 1ea0d14 | 2009-09-03 12:27:15 -0700 | [diff] [blame] | 417 | /* |
| 418 | * Make sure stack canary segment base is cached-aligned: |
| 419 | * "For Intel Atom processors, avoid non zero segment base address |
| 420 | * that is not aligned to cache line boundary at all cost." |
| 421 | * (Optim Ref Manual Assembly/Compiler Coding Rule 15.) |
| 422 | */ |
| 423 | struct stack_canary { |
| 424 | char __pad[20]; /* canary at %gs:20 */ |
| 425 | unsigned long canary; |
| 426 | }; |
Jeremy Fitzhardinge | 53f8245 | 2009-09-03 14:31:44 -0700 | [diff] [blame] | 427 | DECLARE_PER_CPU_ALIGNED(struct stack_canary, stack_canary); |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 428 | #endif |
Tejun Heo | 60a5317 | 2009-02-09 22:17:40 +0900 | [diff] [blame] | 429 | #endif /* X86_64 */ |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 430 | |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 431 | extern unsigned int xstate_size; |
Suresh Siddha | aa283f4 | 2008-03-10 15:28:05 -0700 | [diff] [blame] | 432 | extern void free_thread_xstate(struct task_struct *); |
| 433 | extern struct kmem_cache *task_xstate_cachep; |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 434 | |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 435 | struct perf_event; |
| 436 | |
Glauber de Oliveira Costa | cb38d37 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 437 | struct thread_struct { |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 438 | /* Cached TLS descriptors: */ |
| 439 | struct desc_struct tls_array[GDT_ENTRY_TLS_ENTRIES]; |
| 440 | unsigned long sp0; |
| 441 | unsigned long sp; |
Glauber de Oliveira Costa | cb38d37 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 442 | #ifdef CONFIG_X86_32 |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 443 | unsigned long sysenter_cs; |
Glauber de Oliveira Costa | cb38d37 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 444 | #else |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 445 | unsigned long usersp; /* Copy from PDA */ |
| 446 | unsigned short es; |
| 447 | unsigned short ds; |
| 448 | unsigned short fsindex; |
| 449 | unsigned short gsindex; |
Glauber de Oliveira Costa | cb38d37 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 450 | #endif |
Alexey Dobriyan | 0c23590 | 2009-05-04 03:30:15 +0400 | [diff] [blame] | 451 | #ifdef CONFIG_X86_32 |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 452 | unsigned long ip; |
Alexey Dobriyan | 0c23590 | 2009-05-04 03:30:15 +0400 | [diff] [blame] | 453 | #endif |
Alexey Dobriyan | d756f4ad | 2009-05-04 03:29:52 +0400 | [diff] [blame] | 454 | #ifdef CONFIG_X86_64 |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 455 | unsigned long fs; |
Alexey Dobriyan | d756f4ad | 2009-05-04 03:29:52 +0400 | [diff] [blame] | 456 | #endif |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 457 | unsigned long gs; |
Frederic Weisbecker | 24f1e32c | 2009-09-09 19:22:48 +0200 | [diff] [blame] | 458 | /* Save middle states of ptrace breakpoints */ |
| 459 | struct perf_event *ptrace_bps[HBP_NUM]; |
| 460 | /* Debug status used for traps, single steps, etc... */ |
| 461 | unsigned long debugreg6; |
Frederic Weisbecker | 326264a | 2010-02-18 18:24:18 +0100 | [diff] [blame] | 462 | /* Keep track of the exact dr7 value set by the user */ |
| 463 | unsigned long ptrace_dr7; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 464 | /* Fault info: */ |
| 465 | unsigned long cr2; |
| 466 | unsigned long trap_no; |
| 467 | unsigned long error_code; |
Suresh Siddha | 61c4628 | 2008-03-10 15:28:04 -0700 | [diff] [blame] | 468 | /* floating point and extended processor state */ |
Avi Kivity | 8660328 | 2010-05-06 11:45:46 +0300 | [diff] [blame] | 469 | struct fpu fpu; |
Glauber de Oliveira Costa | cb38d37 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 470 | #ifdef CONFIG_X86_32 |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 471 | /* Virtual 86 mode info */ |
Glauber de Oliveira Costa | cb38d37 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 472 | struct vm86_struct __user *vm86_info; |
| 473 | unsigned long screen_bitmap; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 474 | unsigned long v86flags; |
| 475 | unsigned long v86mask; |
| 476 | unsigned long saved_sp0; |
| 477 | unsigned int saved_fs; |
| 478 | unsigned int saved_gs; |
Glauber de Oliveira Costa | cb38d37 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 479 | #endif |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 480 | /* IO permissions: */ |
| 481 | unsigned long *io_bitmap_ptr; |
| 482 | unsigned long iopl; |
| 483 | /* Max allowed port in the bitmap, in bytes: */ |
| 484 | unsigned io_bitmap_max; |
Glauber de Oliveira Costa | cb38d37 | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 485 | }; |
| 486 | |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 487 | static inline unsigned long native_get_debugreg(int regno) |
| 488 | { |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 489 | unsigned long val = 0; /* Damn you, gcc! */ |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 490 | |
| 491 | switch (regno) { |
| 492 | case 0: |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 493 | asm("mov %%db0, %0" :"=r" (val)); |
| 494 | break; |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 495 | case 1: |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 496 | asm("mov %%db1, %0" :"=r" (val)); |
| 497 | break; |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 498 | case 2: |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 499 | asm("mov %%db2, %0" :"=r" (val)); |
| 500 | break; |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 501 | case 3: |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 502 | asm("mov %%db3, %0" :"=r" (val)); |
| 503 | break; |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 504 | case 6: |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 505 | asm("mov %%db6, %0" :"=r" (val)); |
| 506 | break; |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 507 | case 7: |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 508 | asm("mov %%db7, %0" :"=r" (val)); |
| 509 | break; |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 510 | default: |
| 511 | BUG(); |
| 512 | } |
| 513 | return val; |
| 514 | } |
| 515 | |
| 516 | static inline void native_set_debugreg(int regno, unsigned long value) |
| 517 | { |
| 518 | switch (regno) { |
| 519 | case 0: |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 520 | asm("mov %0, %%db0" ::"r" (value)); |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 521 | break; |
| 522 | case 1: |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 523 | asm("mov %0, %%db1" ::"r" (value)); |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 524 | break; |
| 525 | case 2: |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 526 | asm("mov %0, %%db2" ::"r" (value)); |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 527 | break; |
| 528 | case 3: |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 529 | asm("mov %0, %%db3" ::"r" (value)); |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 530 | break; |
| 531 | case 6: |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 532 | asm("mov %0, %%db6" ::"r" (value)); |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 533 | break; |
| 534 | case 7: |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 535 | asm("mov %0, %%db7" ::"r" (value)); |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 536 | break; |
| 537 | default: |
| 538 | BUG(); |
| 539 | } |
| 540 | } |
| 541 | |
Glauber de Oliveira Costa | 62d7d7e | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 542 | /* |
| 543 | * Set IOPL bits in EFLAGS from given mask |
| 544 | */ |
| 545 | static inline void native_set_iopl_mask(unsigned mask) |
| 546 | { |
| 547 | #ifdef CONFIG_X86_32 |
| 548 | unsigned int reg; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 549 | |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 550 | asm volatile ("pushfl;" |
| 551 | "popl %0;" |
| 552 | "andl %1, %0;" |
| 553 | "orl %2, %0;" |
| 554 | "pushl %0;" |
| 555 | "popfl" |
| 556 | : "=&r" (reg) |
| 557 | : "i" (~X86_EFLAGS_IOPL), "r" (mask)); |
Glauber de Oliveira Costa | 62d7d7e | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 558 | #endif |
| 559 | } |
| 560 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 561 | static inline void |
| 562 | native_load_sp0(struct tss_struct *tss, struct thread_struct *thread) |
Glauber de Oliveira Costa | 7818a1e | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 563 | { |
| 564 | tss->x86_tss.sp0 = thread->sp0; |
| 565 | #ifdef CONFIG_X86_32 |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 566 | /* Only happens when SEP is enabled, no need to test "SEP"arately: */ |
Glauber de Oliveira Costa | 7818a1e | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 567 | if (unlikely(tss->x86_tss.ss1 != thread->sysenter_cs)) { |
| 568 | tss->x86_tss.ss1 = thread->sysenter_cs; |
| 569 | wrmsr(MSR_IA32_SYSENTER_CS, thread->sysenter_cs, 0); |
| 570 | } |
| 571 | #endif |
| 572 | } |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 573 | |
Glauber de Oliveira Costa | e801f86 | 2008-01-30 13:32:08 +0100 | [diff] [blame] | 574 | static inline void native_swapgs(void) |
| 575 | { |
| 576 | #ifdef CONFIG_X86_64 |
| 577 | asm volatile("swapgs" ::: "memory"); |
| 578 | #endif |
| 579 | } |
| 580 | |
Glauber de Oliveira Costa | 7818a1e | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 581 | #ifdef CONFIG_PARAVIRT |
| 582 | #include <asm/paravirt.h> |
| 583 | #else |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 584 | #define __cpuid native_cpuid |
| 585 | #define paravirt_enabled() 0 |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 586 | |
| 587 | /* |
| 588 | * These special macros can be used to get or set a debugging register |
| 589 | */ |
| 590 | #define get_debugreg(var, register) \ |
| 591 | (var) = native_get_debugreg(register) |
| 592 | #define set_debugreg(value, register) \ |
| 593 | native_set_debugreg(register, value) |
| 594 | |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 595 | static inline void load_sp0(struct tss_struct *tss, |
| 596 | struct thread_struct *thread) |
Glauber de Oliveira Costa | 7818a1e | 2008-01-30 13:31:31 +0100 | [diff] [blame] | 597 | { |
| 598 | native_load_sp0(tss, thread); |
| 599 | } |
| 600 | |
Glauber de Oliveira Costa | 62d7d7e | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 601 | #define set_iopl_mask native_set_iopl_mask |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 602 | #endif /* CONFIG_PARAVIRT */ |
| 603 | |
| 604 | /* |
| 605 | * Save the cr4 feature set we're using (ie |
| 606 | * Pentium 4MB enable and PPro Global page |
| 607 | * enable), so that any CPU's that boot up |
| 608 | * after us can get the correct flags. |
| 609 | */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 610 | extern unsigned long mmu_cr4_features; |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 611 | |
| 612 | static inline void set_in_cr4(unsigned long mask) |
| 613 | { |
Brian Gerst | 2df7a6e | 2010-09-03 21:17:08 -0400 | [diff] [blame] | 614 | unsigned long cr4; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 615 | |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 616 | mmu_cr4_features |= mask; |
| 617 | cr4 = read_cr4(); |
| 618 | cr4 |= mask; |
| 619 | write_cr4(cr4); |
| 620 | } |
| 621 | |
| 622 | static inline void clear_in_cr4(unsigned long mask) |
| 623 | { |
Brian Gerst | 2df7a6e | 2010-09-03 21:17:08 -0400 | [diff] [blame] | 624 | unsigned long cr4; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 625 | |
Glauber de Oliveira Costa | 1b46cbe | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 626 | mmu_cr4_features &= ~mask; |
| 627 | cr4 = read_cr4(); |
| 628 | cr4 &= ~mask; |
| 629 | write_cr4(cr4); |
| 630 | } |
| 631 | |
Glauber de Oliveira Costa | fc87e90 | 2008-01-30 13:31:38 +0100 | [diff] [blame] | 632 | typedef struct { |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 633 | unsigned long seg; |
Glauber de Oliveira Costa | fc87e90 | 2008-01-30 13:31:38 +0100 | [diff] [blame] | 634 | } mm_segment_t; |
| 635 | |
| 636 | |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 637 | /* |
| 638 | * create a kernel thread without removing it from tasklists |
| 639 | */ |
| 640 | extern int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags); |
| 641 | |
| 642 | /* Free all resources held by a thread. */ |
| 643 | extern void release_thread(struct task_struct *); |
| 644 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 645 | /* Prepare to copy thread state - unlazy all lazy state */ |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 646 | extern void prepare_to_copy(struct task_struct *tsk); |
| 647 | |
| 648 | unsigned long get_wchan(struct task_struct *p); |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 649 | |
| 650 | /* |
| 651 | * Generic CPUID function |
| 652 | * clear %ecx since some cpus (Cyrix MII) do not set or clear %ecx |
| 653 | * resulting in stale register contents being returned. |
| 654 | */ |
| 655 | static inline void cpuid(unsigned int op, |
| 656 | unsigned int *eax, unsigned int *ebx, |
| 657 | unsigned int *ecx, unsigned int *edx) |
| 658 | { |
| 659 | *eax = op; |
| 660 | *ecx = 0; |
| 661 | __cpuid(eax, ebx, ecx, edx); |
| 662 | } |
| 663 | |
| 664 | /* Some CPUID calls want 'count' to be placed in ecx */ |
| 665 | static inline void cpuid_count(unsigned int op, int count, |
| 666 | unsigned int *eax, unsigned int *ebx, |
| 667 | unsigned int *ecx, unsigned int *edx) |
| 668 | { |
| 669 | *eax = op; |
| 670 | *ecx = count; |
| 671 | __cpuid(eax, ebx, ecx, edx); |
| 672 | } |
| 673 | |
| 674 | /* |
| 675 | * CPUID functions returning a single datum |
| 676 | */ |
| 677 | static inline unsigned int cpuid_eax(unsigned int op) |
| 678 | { |
| 679 | unsigned int eax, ebx, ecx, edx; |
| 680 | |
| 681 | cpuid(op, &eax, &ebx, &ecx, &edx); |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 682 | |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 683 | return eax; |
| 684 | } |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 685 | |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 686 | static inline unsigned int cpuid_ebx(unsigned int op) |
| 687 | { |
| 688 | unsigned int eax, ebx, ecx, edx; |
| 689 | |
| 690 | cpuid(op, &eax, &ebx, &ecx, &edx); |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 691 | |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 692 | return ebx; |
| 693 | } |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 694 | |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 695 | static inline unsigned int cpuid_ecx(unsigned int op) |
| 696 | { |
| 697 | unsigned int eax, ebx, ecx, edx; |
| 698 | |
| 699 | cpuid(op, &eax, &ebx, &ecx, &edx); |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 700 | |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 701 | return ecx; |
| 702 | } |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 703 | |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 704 | static inline unsigned int cpuid_edx(unsigned int op) |
| 705 | { |
| 706 | unsigned int eax, ebx, ecx, edx; |
| 707 | |
| 708 | cpuid(op, &eax, &ebx, &ecx, &edx); |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 709 | |
Glauber de Oliveira Costa | c758ecf | 2008-01-30 13:31:03 +0100 | [diff] [blame] | 710 | return edx; |
| 711 | } |
| 712 | |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 713 | /* REP NOP (PAUSE) is a good thing to insert into busy-wait loops. */ |
| 714 | static inline void rep_nop(void) |
| 715 | { |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 716 | asm volatile("rep; nop" ::: "memory"); |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 717 | } |
| 718 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 719 | static inline void cpu_relax(void) |
| 720 | { |
| 721 | rep_nop(); |
| 722 | } |
| 723 | |
Ben Hutchings | 5367b68 | 2009-09-10 02:53:50 +0100 | [diff] [blame] | 724 | /* Stop speculative execution and prefetching of modified code. */ |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 725 | static inline void sync_core(void) |
| 726 | { |
| 727 | int tmp; |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 728 | |
Ben Hutchings | 5367b68 | 2009-09-10 02:53:50 +0100 | [diff] [blame] | 729 | #if defined(CONFIG_M386) || defined(CONFIG_M486) |
| 730 | if (boot_cpu_data.x86 < 5) |
| 731 | /* There is no speculative execution. |
| 732 | * jmp is a barrier to prefetching. */ |
| 733 | asm volatile("jmp 1f\n1:\n" ::: "memory"); |
| 734 | else |
| 735 | #endif |
| 736 | /* cpuid is a barrier to speculative execution. |
| 737 | * Prefetched instructions are automatically |
| 738 | * invalidated when modified. */ |
| 739 | asm volatile("cpuid" : "=a" (tmp) : "0" (1) |
| 740 | : "ebx", "ecx", "edx", "memory"); |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 741 | } |
| 742 | |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 743 | static inline void __monitor(const void *eax, unsigned long ecx, |
| 744 | unsigned long edx) |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 745 | { |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 746 | /* "monitor %eax, %ecx, %edx;" */ |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 747 | asm volatile(".byte 0x0f, 0x01, 0xc8;" |
| 748 | :: "a" (eax), "c" (ecx), "d"(edx)); |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 749 | } |
| 750 | |
| 751 | static inline void __mwait(unsigned long eax, unsigned long ecx) |
| 752 | { |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 753 | /* "mwait %eax, %ecx;" */ |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 754 | asm volatile(".byte 0x0f, 0x01, 0xc9;" |
| 755 | :: "a" (eax), "c" (ecx)); |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | static inline void __sti_mwait(unsigned long eax, unsigned long ecx) |
| 759 | { |
Peter Zijlstra | 7f424a8 | 2008-04-25 17:39:01 +0200 | [diff] [blame] | 760 | trace_hardirqs_on(); |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 761 | /* "mwait %eax, %ecx;" */ |
Joe Perches | cca2e6f | 2008-03-23 01:03:15 -0700 | [diff] [blame] | 762 | asm volatile("sti; .byte 0x0f, 0x01, 0xc9;" |
| 763 | :: "a" (eax), "c" (ecx)); |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 764 | } |
| 765 | |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 766 | extern void select_idle_routine(const struct cpuinfo_x86 *c); |
Len Brown | 02c68a0 | 2011-04-01 16:59:53 -0400 | [diff] [blame] | 767 | extern void init_amd_e400_c1e_mask(void); |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 768 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 769 | extern unsigned long boot_option_idle_override; |
Len Brown | 02c68a0 | 2011-04-01 16:59:53 -0400 | [diff] [blame] | 770 | extern bool amd_e400_c1e_detected; |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 771 | |
Thomas Renninger | d189604 | 2010-11-03 17:06:14 +0100 | [diff] [blame] | 772 | enum idle_boot_override {IDLE_NO_OVERRIDE=0, IDLE_HALT, IDLE_NOMWAIT, |
| 773 | IDLE_POLL, IDLE_FORCE_MWAIT}; |
| 774 | |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 775 | extern void enable_sep_cpu(void); |
| 776 | extern int sysenter_setup(void); |
| 777 | |
Jan Kiszka | 29c8439 | 2010-05-20 21:04:29 -0500 | [diff] [blame] | 778 | extern void early_trap_init(void); |
| 779 | |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 780 | /* Defined in head.S */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 781 | extern struct desc_ptr early_gdt_descr; |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 782 | |
| 783 | extern void cpu_set_gdt(int); |
Brian Gerst | 552be87 | 2009-01-30 17:47:53 +0900 | [diff] [blame] | 784 | extern void switch_to_new_gdt(int); |
Jeremy Fitzhardinge | 11e3a84 | 2009-01-30 17:47:54 +0900 | [diff] [blame] | 785 | extern void load_percpu_segment(int); |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 786 | extern void cpu_init(void); |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 787 | |
Markus Metzger | c272477 | 2008-12-11 13:49:59 +0100 | [diff] [blame] | 788 | static inline unsigned long get_debugctlmsr(void) |
| 789 | { |
Peter Zijlstra | ea8e61b | 2010-03-25 14:51:51 +0100 | [diff] [blame] | 790 | unsigned long debugctlmsr = 0; |
Markus Metzger | c272477 | 2008-12-11 13:49:59 +0100 | [diff] [blame] | 791 | |
| 792 | #ifndef CONFIG_X86_DEBUGCTLMSR |
| 793 | if (boot_cpu_data.x86 < 6) |
| 794 | return 0; |
| 795 | #endif |
| 796 | rdmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr); |
| 797 | |
Peter Zijlstra | ea8e61b | 2010-03-25 14:51:51 +0100 | [diff] [blame] | 798 | return debugctlmsr; |
Markus Metzger | c272477 | 2008-12-11 13:49:59 +0100 | [diff] [blame] | 799 | } |
| 800 | |
Jan Beulich | 5b0e508 | 2008-03-10 13:11:17 +0000 | [diff] [blame] | 801 | static inline void update_debugctlmsr(unsigned long debugctlmsr) |
| 802 | { |
| 803 | #ifndef CONFIG_X86_DEBUGCTLMSR |
| 804 | if (boot_cpu_data.x86 < 6) |
| 805 | return; |
| 806 | #endif |
| 807 | wrmsrl(MSR_IA32_DEBUGCTLMSR, debugctlmsr); |
| 808 | } |
| 809 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 810 | /* |
| 811 | * from system description table in BIOS. Mostly for MCA use, but |
| 812 | * others may find it useful: |
| 813 | */ |
| 814 | extern unsigned int machine_id; |
| 815 | extern unsigned int machine_submodel_id; |
| 816 | extern unsigned int BIOS_revision; |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 817 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 818 | /* Boot loader type from the setup header: */ |
| 819 | extern int bootloader_type; |
H. Peter Anvin | 5031296 | 2009-05-07 16:54:11 -0700 | [diff] [blame] | 820 | extern int bootloader_version; |
Glauber de Oliveira Costa | 1a53905 | 2008-01-30 13:31:39 +0100 | [diff] [blame] | 821 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 822 | extern char ignore_fpu_irq; |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 823 | |
| 824 | #define HAVE_ARCH_PICK_MMAP_LAYOUT 1 |
| 825 | #define ARCH_HAS_PREFETCHW |
| 826 | #define ARCH_HAS_SPINLOCK_PREFETCH |
| 827 | |
Glauber de Oliveira Costa | ae2e15e | 2008-01-30 13:31:40 +0100 | [diff] [blame] | 828 | #ifdef CONFIG_X86_32 |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 829 | # define BASE_PREFETCH ASM_NOP4 |
| 830 | # define ARCH_HAS_PREFETCH |
Glauber de Oliveira Costa | ae2e15e | 2008-01-30 13:31:40 +0100 | [diff] [blame] | 831 | #else |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 832 | # define BASE_PREFETCH "prefetcht0 (%1)" |
Glauber de Oliveira Costa | ae2e15e | 2008-01-30 13:31:40 +0100 | [diff] [blame] | 833 | #endif |
| 834 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 835 | /* |
| 836 | * Prefetch instructions for Pentium III (+) and AMD Athlon (+) |
| 837 | * |
| 838 | * It's not worth to care about 3dnow prefetches for the K6 |
| 839 | * because they are microcoded there and very slow. |
| 840 | */ |
Glauber de Oliveira Costa | ae2e15e | 2008-01-30 13:31:40 +0100 | [diff] [blame] | 841 | static inline void prefetch(const void *x) |
| 842 | { |
| 843 | alternative_input(BASE_PREFETCH, |
| 844 | "prefetchnta (%1)", |
| 845 | X86_FEATURE_XMM, |
| 846 | "r" (x)); |
| 847 | } |
| 848 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 849 | /* |
| 850 | * 3dnow prefetch to get an exclusive cache line. |
| 851 | * Useful for spinlocks to avoid one state transition in the |
| 852 | * cache coherency protocol: |
| 853 | */ |
Glauber de Oliveira Costa | ae2e15e | 2008-01-30 13:31:40 +0100 | [diff] [blame] | 854 | static inline void prefetchw(const void *x) |
| 855 | { |
| 856 | alternative_input(BASE_PREFETCH, |
| 857 | "prefetchw (%1)", |
| 858 | X86_FEATURE_3DNOW, |
| 859 | "r" (x)); |
| 860 | } |
| 861 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 862 | static inline void spin_lock_prefetch(const void *x) |
| 863 | { |
| 864 | prefetchw(x); |
| 865 | } |
| 866 | |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 867 | #ifdef CONFIG_X86_32 |
| 868 | /* |
| 869 | * User space process size: 3GB (default). |
| 870 | */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 871 | #define TASK_SIZE PAGE_OFFSET |
Ingo Molnar | d951734 | 2009-02-20 23:32:28 +0100 | [diff] [blame] | 872 | #define TASK_SIZE_MAX TASK_SIZE |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 873 | #define STACK_TOP TASK_SIZE |
| 874 | #define STACK_TOP_MAX STACK_TOP |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 875 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 876 | #define INIT_THREAD { \ |
| 877 | .sp0 = sizeof(init_stack) + (long)&init_stack, \ |
| 878 | .vm86_info = NULL, \ |
| 879 | .sysenter_cs = __KERNEL_CS, \ |
| 880 | .io_bitmap_ptr = NULL, \ |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | /* |
| 884 | * Note that the .io_bitmap member must be extra-big. This is because |
| 885 | * the CPU will access an additional byte beyond the end of the IO |
| 886 | * permission bitmap. The extra byte must be all 1 bits, and must |
| 887 | * be within the limit. |
| 888 | */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 889 | #define INIT_TSS { \ |
| 890 | .x86_tss = { \ |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 891 | .sp0 = sizeof(init_stack) + (long)&init_stack, \ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 892 | .ss0 = __KERNEL_DS, \ |
| 893 | .ss1 = __KERNEL_CS, \ |
| 894 | .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \ |
| 895 | }, \ |
| 896 | .io_bitmap = { [0 ... IO_BITMAP_LONGS] = ~0 }, \ |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 897 | } |
| 898 | |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 899 | extern unsigned long thread_saved_pc(struct task_struct *tsk); |
| 900 | |
| 901 | #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long)) |
| 902 | #define KSTK_TOP(info) \ |
| 903 | ({ \ |
| 904 | unsigned long *__ptr = (unsigned long *)(info); \ |
| 905 | (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \ |
| 906 | }) |
| 907 | |
| 908 | /* |
| 909 | * The below -8 is to reserve 8 bytes on top of the ring0 stack. |
| 910 | * This is necessary to guarantee that the entire "struct pt_regs" |
Uwe Kleine-König | b595076 | 2010-11-01 15:38:34 -0400 | [diff] [blame] | 911 | * is accessible even if the CPU haven't stored the SS/ESP registers |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 912 | * on the stack (interrupt gate does not save these registers |
| 913 | * when switching to the same priv ring). |
| 914 | * Therefore beware: accessing the ss/esp fields of the |
| 915 | * "struct pt_regs" is possible, but they may contain the |
| 916 | * completely wrong values. |
| 917 | */ |
| 918 | #define task_pt_regs(task) \ |
| 919 | ({ \ |
| 920 | struct pt_regs *__regs__; \ |
| 921 | __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \ |
| 922 | __regs__ - 1; \ |
| 923 | }) |
| 924 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 925 | #define KSTK_ESP(task) (task_pt_regs(task)->sp) |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 926 | |
| 927 | #else |
| 928 | /* |
| 929 | * User space process size. 47bits minus one guard page. |
| 930 | */ |
Ingo Molnar | d951734 | 2009-02-20 23:32:28 +0100 | [diff] [blame] | 931 | #define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE) |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 932 | |
| 933 | /* This decides where the kernel will search for a free chunk of vm |
| 934 | * space during mmap's. |
| 935 | */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 936 | #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \ |
| 937 | 0xc0000000 : 0xFFFFe000) |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 938 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 939 | #define TASK_SIZE (test_thread_flag(TIF_IA32) ? \ |
Ingo Molnar | d951734 | 2009-02-20 23:32:28 +0100 | [diff] [blame] | 940 | IA32_PAGE_OFFSET : TASK_SIZE_MAX) |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 941 | #define TASK_SIZE_OF(child) ((test_tsk_thread_flag(child, TIF_IA32)) ? \ |
Ingo Molnar | d951734 | 2009-02-20 23:32:28 +0100 | [diff] [blame] | 942 | IA32_PAGE_OFFSET : TASK_SIZE_MAX) |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 943 | |
David Howells | 922a70d | 2008-02-08 04:19:26 -0800 | [diff] [blame] | 944 | #define STACK_TOP TASK_SIZE |
Ingo Molnar | d951734 | 2009-02-20 23:32:28 +0100 | [diff] [blame] | 945 | #define STACK_TOP_MAX TASK_SIZE_MAX |
David Howells | 922a70d | 2008-02-08 04:19:26 -0800 | [diff] [blame] | 946 | |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 947 | #define INIT_THREAD { \ |
| 948 | .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \ |
| 949 | } |
| 950 | |
| 951 | #define INIT_TSS { \ |
| 952 | .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \ |
| 953 | } |
| 954 | |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 955 | /* |
| 956 | * Return saved PC of a blocked thread. |
| 957 | * What is this good for? it will be always the scheduler or ret_from_fork. |
| 958 | */ |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 959 | #define thread_saved_pc(t) (*(unsigned long *)((t)->thread.sp - 8)) |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 960 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 961 | #define task_pt_regs(tsk) ((struct pt_regs *)(tsk)->thread.sp0 - 1) |
Stefani Seibold | 89240ba | 2009-11-03 10:22:40 +0100 | [diff] [blame] | 962 | extern unsigned long KSTK_ESP(struct task_struct *task); |
Glauber de Oliveira Costa | 2f66dcc | 2008-01-30 13:31:57 +0100 | [diff] [blame] | 963 | #endif /* CONFIG_X86_64 */ |
| 964 | |
Ingo Molnar | 513ad84 | 2008-02-21 05:18:40 +0100 | [diff] [blame] | 965 | extern void start_thread(struct pt_regs *regs, unsigned long new_ip, |
| 966 | unsigned long new_sp); |
| 967 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 968 | /* |
| 969 | * This decides where the kernel will search for a free chunk of vm |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 970 | * space during mmap's. |
| 971 | */ |
| 972 | #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3)) |
| 973 | |
Ingo Molnar | 4d46a89 | 2008-02-21 04:24:40 +0100 | [diff] [blame] | 974 | #define KSTK_EIP(task) (task_pt_regs(task)->ip) |
Glauber de Oliveira Costa | 683e025 | 2008-01-30 13:31:27 +0100 | [diff] [blame] | 975 | |
Erik Bosman | 529e25f | 2008-04-14 00:24:18 +0200 | [diff] [blame] | 976 | /* Get/set a process' ability to use the timestamp counter instruction */ |
| 977 | #define GET_TSC_CTL(adr) get_tsc_mode((adr)) |
| 978 | #define SET_TSC_CTL(val) set_tsc_mode((val)) |
| 979 | |
| 980 | extern int get_tsc_mode(unsigned long adr); |
| 981 | extern int set_tsc_mode(unsigned int val); |
| 982 | |
Andreas Herrmann | 6a81269 | 2009-09-16 11:33:40 +0200 | [diff] [blame] | 983 | extern int amd_get_nb_id(int cpu); |
| 984 | |
Peter Zijlstra | 5cbc19a | 2009-09-02 11:49:52 +0200 | [diff] [blame] | 985 | struct aperfmperf { |
| 986 | u64 aperf, mperf; |
| 987 | }; |
| 988 | |
| 989 | static inline void get_aperfmperf(struct aperfmperf *am) |
| 990 | { |
| 991 | WARN_ON_ONCE(!boot_cpu_has(X86_FEATURE_APERFMPERF)); |
| 992 | |
| 993 | rdmsrl(MSR_IA32_APERF, am->aperf); |
| 994 | rdmsrl(MSR_IA32_MPERF, am->mperf); |
| 995 | } |
| 996 | |
| 997 | #define APERFMPERF_SHIFT 10 |
| 998 | |
| 999 | static inline |
| 1000 | unsigned long calc_aperfmperf_ratio(struct aperfmperf *old, |
| 1001 | struct aperfmperf *new) |
| 1002 | { |
| 1003 | u64 aperf = new->aperf - old->aperf; |
| 1004 | u64 mperf = new->mperf - old->mperf; |
| 1005 | unsigned long ratio = aperf; |
| 1006 | |
| 1007 | mperf >>= APERFMPERF_SHIFT; |
| 1008 | if (mperf) |
| 1009 | ratio = div64_u64(aperf, mperf); |
| 1010 | |
| 1011 | return ratio; |
| 1012 | } |
| 1013 | |
Hans Rosenfeld | d78d671 | 2010-07-28 19:09:30 +0200 | [diff] [blame] | 1014 | /* |
| 1015 | * AMD errata checking |
| 1016 | */ |
| 1017 | #ifdef CONFIG_CPU_SUP_AMD |
Hans Rosenfeld | 1be85a6 | 2010-07-28 19:09:32 +0200 | [diff] [blame] | 1018 | extern const int amd_erratum_383[]; |
Hans Rosenfeld | 9d8888c | 2010-07-28 19:09:31 +0200 | [diff] [blame] | 1019 | extern const int amd_erratum_400[]; |
Hans Rosenfeld | d78d671 | 2010-07-28 19:09:30 +0200 | [diff] [blame] | 1020 | extern bool cpu_has_amd_erratum(const int *); |
| 1021 | |
| 1022 | #define AMD_LEGACY_ERRATUM(...) { -1, __VA_ARGS__, 0 } |
| 1023 | #define AMD_OSVW_ERRATUM(osvw_id, ...) { osvw_id, __VA_ARGS__, 0 } |
| 1024 | #define AMD_MODEL_RANGE(f, m_start, s_start, m_end, s_end) \ |
| 1025 | ((f << 24) | (m_start << 16) | (s_start << 12) | (m_end << 4) | (s_end)) |
| 1026 | #define AMD_MODEL_RANGE_FAMILY(range) (((range) >> 24) & 0xff) |
| 1027 | #define AMD_MODEL_RANGE_START(range) (((range) >> 12) & 0xfff) |
| 1028 | #define AMD_MODEL_RANGE_END(range) ((range) & 0xfff) |
| 1029 | |
| 1030 | #else |
| 1031 | #define cpu_has_amd_erratum(x) (false) |
| 1032 | #endif /* CONFIG_CPU_SUP_AMD */ |
| 1033 | |
David Howells | f05e798 | 2012-03-28 18:11:12 +0100 | [diff] [blame^] | 1034 | #ifdef CONFIG_X86_32 |
| 1035 | /* |
| 1036 | * disable hlt during certain critical i/o operations |
| 1037 | */ |
| 1038 | #define HAVE_DISABLE_HLT |
| 1039 | #endif |
| 1040 | |
| 1041 | void disable_hlt(void); |
| 1042 | void enable_hlt(void); |
| 1043 | |
| 1044 | void cpu_idle_wait(void); |
| 1045 | |
| 1046 | extern unsigned long arch_align_stack(unsigned long sp); |
| 1047 | extern void free_init_pages(char *what, unsigned long begin, unsigned long end); |
| 1048 | |
| 1049 | void default_idle(void); |
| 1050 | bool set_pm_idle_to_default(void); |
| 1051 | |
| 1052 | void stop_this_cpu(void *dummy); |
| 1053 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1054 | #endif /* _ASM_X86_PROCESSOR_H */ |