[PATCH] x86_64: Mark mce_amd cpu notifier __cpuinit/__cpuinitdata
[linux-2.6/kvm.git] / include / asm-x86_64 / system.h
blob68e559f3631c00de7b7b03ed830ace3b43173de8
1 #ifndef __ASM_SYSTEM_H
2 #define __ASM_SYSTEM_H
4 #include <linux/kernel.h>
5 #include <asm/segment.h>
6 #include <asm/alternative.h>
8 #ifdef __KERNEL__
10 #define __STR(x) #x
11 #define STR(x) __STR(x)
13 #define __SAVE(reg,offset) "movq %%" #reg ",(14-" #offset ")*8(%%rsp)\n\t"
14 #define __RESTORE(reg,offset) "movq (14-" #offset ")*8(%%rsp),%%" #reg "\n\t"
16 /* frame pointer must be last for get_wchan */
17 #define SAVE_CONTEXT "pushq %%rbp ; movq %%rsi,%%rbp\n\t"
18 #define RESTORE_CONTEXT "movq %%rbp,%%rsi ; popq %%rbp\n\t"
20 #define __EXTRA_CLOBBER \
21 ,"rcx","rbx","rdx","r8","r9","r10","r11","r12","r13","r14","r15"
23 #define switch_to(prev,next,last) \
24 asm volatile(SAVE_CONTEXT \
25 "movq %%rsp,%P[threadrsp](%[prev])\n\t" /* save RSP */ \
26 "movq %P[threadrsp](%[next]),%%rsp\n\t" /* restore RSP */ \
27 "call __switch_to\n\t" \
28 ".globl thread_return\n" \
29 "thread_return:\n\t" \
30 "movq %%gs:%P[pda_pcurrent],%%rsi\n\t" \
31 "movq %P[thread_info](%%rsi),%%r8\n\t" \
32 LOCK_PREFIX "btr %[tif_fork],%P[ti_flags](%%r8)\n\t" \
33 "movq %%rax,%%rdi\n\t" \
34 "jc ret_from_fork\n\t" \
35 RESTORE_CONTEXT \
36 : "=a" (last) \
37 : [next] "S" (next), [prev] "D" (prev), \
38 [threadrsp] "i" (offsetof(struct task_struct, thread.rsp)), \
39 [ti_flags] "i" (offsetof(struct thread_info, flags)),\
40 [tif_fork] "i" (TIF_FORK), \
41 [thread_info] "i" (offsetof(struct task_struct, thread_info)), \
42 [pda_pcurrent] "i" (offsetof(struct x8664_pda, pcurrent)) \
43 : "memory", "cc" __EXTRA_CLOBBER)
45 extern void load_gs_index(unsigned);
48 * Load a segment. Fall back on loading the zero
49 * segment if something goes wrong..
51 #define loadsegment(seg,value) \
52 asm volatile("\n" \
53 "1:\t" \
54 "movl %k0,%%" #seg "\n" \
55 "2:\n" \
56 ".section .fixup,\"ax\"\n" \
57 "3:\t" \
58 "movl %1,%%" #seg "\n\t" \
59 "jmp 2b\n" \
60 ".previous\n" \
61 ".section __ex_table,\"a\"\n\t" \
62 ".align 8\n\t" \
63 ".quad 1b,3b\n" \
64 ".previous" \
65 : :"r" (value), "r" (0))
68 * Clear and set 'TS' bit respectively
70 #define clts() __asm__ __volatile__ ("clts")
72 static inline unsigned long read_cr0(void)
74 unsigned long cr0;
75 asm volatile("movq %%cr0,%0" : "=r" (cr0));
76 return cr0;
79 static inline void write_cr0(unsigned long val)
81 asm volatile("movq %0,%%cr0" :: "r" (val));
84 static inline unsigned long read_cr3(void)
86 unsigned long cr3;
87 asm("movq %%cr3,%0" : "=r" (cr3));
88 return cr3;
91 static inline unsigned long read_cr4(void)
93 unsigned long cr4;
94 asm("movq %%cr4,%0" : "=r" (cr4));
95 return cr4;
98 static inline void write_cr4(unsigned long val)
100 asm volatile("movq %0,%%cr4" :: "r" (val));
103 #define stts() write_cr0(8 | read_cr0())
105 #define wbinvd() \
106 __asm__ __volatile__ ("wbinvd": : :"memory");
109 * On SMP systems, when the scheduler does migration-cost autodetection,
110 * it needs a way to flush as much of the CPU's caches as possible.
112 static inline void sched_cacheflush(void)
114 wbinvd();
117 #endif /* __KERNEL__ */
119 #define nop() __asm__ __volatile__ ("nop")
121 #define xchg(ptr,v) ((__typeof__(*(ptr)))__xchg((unsigned long)(v),(ptr),sizeof(*(ptr))))
123 #define tas(ptr) (xchg((ptr),1))
125 #define __xg(x) ((volatile long *)(x))
127 static inline void set_64bit(volatile unsigned long *ptr, unsigned long val)
129 *ptr = val;
132 #define _set_64bit set_64bit
135 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway
136 * Note 2: xchg has side effect, so that attribute volatile is necessary,
137 * but generally the primitive is invalid, *ptr is output argument. --ANK
139 static inline unsigned long __xchg(unsigned long x, volatile void * ptr, int size)
141 switch (size) {
142 case 1:
143 __asm__ __volatile__("xchgb %b0,%1"
144 :"=q" (x)
145 :"m" (*__xg(ptr)), "0" (x)
146 :"memory");
147 break;
148 case 2:
149 __asm__ __volatile__("xchgw %w0,%1"
150 :"=r" (x)
151 :"m" (*__xg(ptr)), "0" (x)
152 :"memory");
153 break;
154 case 4:
155 __asm__ __volatile__("xchgl %k0,%1"
156 :"=r" (x)
157 :"m" (*__xg(ptr)), "0" (x)
158 :"memory");
159 break;
160 case 8:
161 __asm__ __volatile__("xchgq %0,%1"
162 :"=r" (x)
163 :"m" (*__xg(ptr)), "0" (x)
164 :"memory");
165 break;
167 return x;
171 * Atomic compare and exchange. Compare OLD with MEM, if identical,
172 * store NEW in MEM. Return the initial value in MEM. Success is
173 * indicated by comparing RETURN with OLD.
176 #define __HAVE_ARCH_CMPXCHG 1
178 static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
179 unsigned long new, int size)
181 unsigned long prev;
182 switch (size) {
183 case 1:
184 __asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
185 : "=a"(prev)
186 : "q"(new), "m"(*__xg(ptr)), "0"(old)
187 : "memory");
188 return prev;
189 case 2:
190 __asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2"
191 : "=a"(prev)
192 : "r"(new), "m"(*__xg(ptr)), "0"(old)
193 : "memory");
194 return prev;
195 case 4:
196 __asm__ __volatile__(LOCK_PREFIX "cmpxchgl %k1,%2"
197 : "=a"(prev)
198 : "r"(new), "m"(*__xg(ptr)), "0"(old)
199 : "memory");
200 return prev;
201 case 8:
202 __asm__ __volatile__(LOCK_PREFIX "cmpxchgq %1,%2"
203 : "=a"(prev)
204 : "r"(new), "m"(*__xg(ptr)), "0"(old)
205 : "memory");
206 return prev;
208 return old;
211 #define cmpxchg(ptr,o,n)\
212 ((__typeof__(*(ptr)))__cmpxchg((ptr),(unsigned long)(o),\
213 (unsigned long)(n),sizeof(*(ptr))))
215 #ifdef CONFIG_SMP
216 #define smp_mb() mb()
217 #define smp_rmb() rmb()
218 #define smp_wmb() wmb()
219 #define smp_read_barrier_depends() do {} while(0)
220 #else
221 #define smp_mb() barrier()
222 #define smp_rmb() barrier()
223 #define smp_wmb() barrier()
224 #define smp_read_barrier_depends() do {} while(0)
225 #endif
229 * Force strict CPU ordering.
230 * And yes, this is required on UP too when we're talking
231 * to devices.
233 #define mb() asm volatile("mfence":::"memory")
234 #define rmb() asm volatile("lfence":::"memory")
236 #ifdef CONFIG_UNORDERED_IO
237 #define wmb() asm volatile("sfence" ::: "memory")
238 #else
239 #define wmb() asm volatile("" ::: "memory")
240 #endif
241 #define read_barrier_depends() do {} while(0)
242 #define set_mb(var, value) do { (void) xchg(&var, value); } while (0)
243 #define set_wmb(var, value) do { var = value; wmb(); } while (0)
245 #define warn_if_not_ulong(x) do { unsigned long foo; (void) (&(x) == &foo); } while (0)
247 /* interrupt control.. */
248 #define local_save_flags(x) do { warn_if_not_ulong(x); __asm__ __volatile__("# save_flags \n\t pushfq ; popq %q0":"=g" (x): /* no input */ :"memory"); } while (0)
249 #define local_irq_restore(x) __asm__ __volatile__("# restore_flags \n\t pushq %0 ; popfq": /* no output */ :"g" (x):"memory", "cc")
251 #ifdef CONFIG_X86_VSMP
252 /* Interrupt control for VSMP architecture */
253 #define local_irq_disable() do { unsigned long flags; local_save_flags(flags); local_irq_restore((flags & ~(1 << 9)) | (1 << 18)); } while (0)
254 #define local_irq_enable() do { unsigned long flags; local_save_flags(flags); local_irq_restore((flags | (1 << 9)) & ~(1 << 18)); } while (0)
256 #define irqs_disabled() \
257 ({ \
258 unsigned long flags; \
259 local_save_flags(flags); \
260 (flags & (1<<18)) || !(flags & (1<<9)); \
263 /* For spinlocks etc */
264 #define local_irq_save(x) do { local_save_flags(x); local_irq_restore((x & ~(1 << 9)) | (1 << 18)); } while (0)
265 #else /* CONFIG_X86_VSMP */
266 #define local_irq_disable() __asm__ __volatile__("cli": : :"memory")
267 #define local_irq_enable() __asm__ __volatile__("sti": : :"memory")
269 #define irqs_disabled() \
270 ({ \
271 unsigned long flags; \
272 local_save_flags(flags); \
273 !(flags & (1<<9)); \
276 /* For spinlocks etc */
277 #define local_irq_save(x) do { warn_if_not_ulong(x); __asm__ __volatile__("# local_irq_save \n\t pushfq ; popq %0 ; cli":"=g" (x): /* no input */ :"memory"); } while (0)
278 #endif
280 /* used in the idle loop; sti takes one instruction cycle to complete */
281 #define safe_halt() __asm__ __volatile__("sti; hlt": : :"memory")
282 /* used when interrupts are already enabled or to shutdown the processor */
283 #define halt() __asm__ __volatile__("hlt": : :"memory")
285 void cpu_idle_wait(void);
287 extern unsigned long arch_align_stack(unsigned long sp);
288 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
290 #endif