blob: f4835a1be360b5090c9d0bdbd12fdaaab39909b5 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_APIC_H
2#define _ASM_X86_APIC_H
Thomas Gleixner67c5fc52008-01-30 13:30:15 +01003
4#include <linux/pm.h>
5#include <linux/delay.h>
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +01006
7#include <asm/alternative.h>
Thomas Gleixner67c5fc52008-01-30 13:30:15 +01008#include <asm/fixmap.h>
9#include <asm/apicdef.h>
10#include <asm/processor.h>
11#include <asm/system.h>
Suresh Siddha13c88fb2008-07-10 11:16:52 -070012#include <asm/cpufeature.h>
13#include <asm/msr.h>
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010014
15#define ARCH_APICTIMER_STOPS_ON_C3 1
16
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010017/*
18 * Debugging macros
19 */
20#define APIC_QUIET 0
21#define APIC_VERBOSE 1
22#define APIC_DEBUG 2
23
24/*
25 * Define the default level of output to be very little
26 * This can be turned up by using apic=verbose for more
27 * information and apic=debug for _lots_ of information.
28 * apic_verbosity is defined in apic.c
29 */
30#define apic_printk(v, s, a...) do { \
31 if ((v) <= apic_verbosity) \
32 printk(s, ##a); \
33 } while (0)
34
35
36extern void generic_apic_probe(void);
37
38#ifdef CONFIG_X86_LOCAL_APIC
39
Maciej W. Rozyckibaa13182008-07-14 18:44:51 +010040extern unsigned int apic_verbosity;
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010041extern int local_apic_timer_c2_ok;
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010042
Yinghai Lu3c999f12008-06-20 16:11:20 -070043extern int disable_apic;
Ingo Molnar0939e4f2009-01-28 17:16:25 +010044
45#ifdef CONFIG_SMP
46extern void __inquire_remote_apic(int apicid);
47#else /* CONFIG_SMP */
48static inline void __inquire_remote_apic(int apicid)
49{
50}
51#endif /* CONFIG_SMP */
52
53static inline void default_inquire_remote_apic(int apicid)
54{
55 if (apic_verbosity >= APIC_DEBUG)
56 __inquire_remote_apic(apicid);
57}
58
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010059/*
60 * Basic functions accessing APICs.
61 */
62#ifdef CONFIG_PARAVIRT
63#include <asm/paravirt.h>
Thomas Gleixner96a388d2007-10-11 11:20:03 +020064#else
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010065#define setup_boot_clock setup_boot_APIC_clock
66#define setup_secondary_clock setup_secondary_APIC_clock
Thomas Gleixner96a388d2007-10-11 11:20:03 +020067#endif
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010068
Ravikiran G Thirumalaiaa7d8e25e2008-03-20 00:41:16 -070069extern int is_vsmp_box(void);
Jaswinder Singh2b97df02008-07-23 17:13:14 +053070extern void xapic_wait_icr_idle(void);
71extern u32 safe_xapic_wait_icr_idle(void);
Jaswinder Singh2b97df02008-07-23 17:13:14 +053072extern void xapic_icr_write(u32, u32);
73extern int setup_profiling_timer(unsigned int);
Ravikiran G Thirumalaiaa7d8e25e2008-03-20 00:41:16 -070074
Suresh Siddha1b374e42008-07-10 11:16:49 -070075static inline void native_apic_mem_write(u32 reg, u32 v)
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010076{
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +010077 volatile u32 *addr = (volatile u32 *)(APIC_BASE + reg);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010078
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +010079 alternative_io("movl %0, %1", "xchgl %0, %1", X86_FEATURE_11AP,
80 ASM_OUTPUT2("=r" (v), "=m" (*addr)),
81 ASM_OUTPUT2("0" (v), "m" (*addr)));
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010082}
83
Suresh Siddha1b374e42008-07-10 11:16:49 -070084static inline u32 native_apic_mem_read(u32 reg)
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010085{
86 return *((volatile u32 *)(APIC_BASE + reg));
87}
88
Suresh Siddha13c88fb2008-07-10 11:16:52 -070089static inline void native_apic_msr_write(u32 reg, u32 v)
90{
91 if (reg == APIC_DFR || reg == APIC_ID || reg == APIC_LDR ||
92 reg == APIC_LVR)
93 return;
94
95 wrmsr(APIC_BASE_MSR + (reg >> 4), v, 0);
96}
97
98static inline u32 native_apic_msr_read(u32 reg)
99{
100 u32 low, high;
101
102 if (reg == APIC_DFR)
103 return -1;
104
105 rdmsr(APIC_BASE_MSR + (reg >> 4), low, high);
106 return low;
107}
108
Yinghai Luc535b6a2008-07-11 18:41:54 -0700109#ifndef CONFIG_X86_32
Jaswinder Singhb6b301a2008-12-23 21:52:33 +0530110extern int x2apic;
Suresh Siddha6e1cb382008-07-10 11:16:58 -0700111extern void check_x2apic(void);
112extern void enable_x2apic(void);
113extern void enable_IR_x2apic(void);
114extern void x2apic_icr_write(u32 low, u32 id);
Yinghai Lua11b5ab2008-09-03 16:58:31 -0700115static inline int x2apic_enabled(void)
116{
117 int msr, msr2;
118
119 if (!cpu_has_x2apic)
120 return 0;
121
122 rdmsr(MSR_IA32_APICBASE, msr, msr2);
123 if (msr & X2APIC_ENABLE)
124 return 1;
125 return 0;
126}
127#else
128#define x2apic_enabled() 0
Yinghai Luc535b6a2008-07-11 18:41:54 -0700129#endif
Suresh Siddha1b374e42008-07-10 11:16:49 -0700130
131struct apic_ops {
132 u32 (*read)(u32 reg);
133 void (*write)(u32 reg, u32 v);
Suresh Siddha1b374e42008-07-10 11:16:49 -0700134 u64 (*icr_read)(void);
135 void (*icr_write)(u32 low, u32 high);
136 void (*wait_icr_idle)(void);
137 u32 (*safe_wait_icr_idle)(void);
138};
139
140extern struct apic_ops *apic_ops;
141
Jeremy Fitzhardinge3c552ac2009-02-09 12:05:47 -0800142static inline u32 apic_read(u32 reg)
143{
144 return apic_ops->read(reg);
145}
146
147static inline void apic_write(u32 reg, u32 val)
148{
149 apic_ops->write(reg, val);
150}
151
152static inline u64 apic_icr_read(void)
153{
154 return apic_ops->icr_read();
155}
156
157static inline void apic_icr_write(u32 low, u32 high)
158{
159 apic_ops->icr_write(low, high);
160}
161
162static inline void apic_wait_icr_idle(void)
163{
164 apic_ops->wait_icr_idle();
165}
166
167static inline u32 safe_apic_wait_icr_idle(void)
168{
169 return apic_ops->safe_wait_icr_idle();
170}
Suresh Siddha1b374e42008-07-10 11:16:49 -0700171
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100172extern int get_physical_broadcast(void);
173
Suresh Siddha89027d32008-07-10 11:16:56 -0700174#ifdef CONFIG_X86_64
175static inline void ack_x2APIC_irq(void)
176{
177 /* Docs say use 0 for future compatibility */
178 native_apic_msr_write(APIC_EOI, 0);
179}
180#endif
181
182
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100183static inline void ack_APIC_irq(void)
184{
185 /*
Maciej W. Rozycki0791e132008-07-21 01:28:43 +0100186 * ack_APIC_irq() actually gets compiled as a single instruction
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100187 * ... yummie.
188 */
189
190 /* Docs say use 0 for future compatibility */
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +0100191 apic_write(APIC_EOI, 0);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100192}
193
194extern int lapic_get_maxlvt(void);
195extern void clear_local_APIC(void);
196extern void connect_bsp_APIC(void);
197extern void disconnect_bsp_APIC(int virt_wire_setup);
198extern void disable_local_APIC(void);
199extern void lapic_shutdown(void);
200extern int verify_local_APIC(void);
201extern void cache_APIC_registers(void);
202extern void sync_Arb_IDs(void);
203extern void init_bsp_APIC(void);
204extern void setup_local_APIC(void);
Andi Kleen739f33b2008-01-30 13:30:40 +0100205extern void end_local_APIC_setup(void);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100206extern void init_apic_mappings(void);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100207extern void setup_boot_APIC_clock(void);
208extern void setup_secondary_APIC_clock(void);
209extern int APIC_init_uniprocessor(void);
Jan Beuliche9427102008-01-30 13:31:24 +0100210extern void enable_NMI_through_LVT0(void);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100211
212/*
213 * On 32bit this is mach-xxx local
214 */
215#ifdef CONFIG_X86_64
Yinghai Lu8643f9d2008-02-19 03:21:06 -0800216extern void early_init_lapic_mapping(void);
Alok Kataria8fbbc4b2008-07-01 11:43:34 -0700217extern int apic_is_clustered_box(void);
218#else
219static inline int apic_is_clustered_box(void)
220{
221 return 0;
222}
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100223#endif
224
Robert Richter7b83dae2008-01-30 13:30:40 +0100225extern u8 setup_APIC_eilvt_mce(u8 vector, u8 msg_type, u8 mask);
226extern u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100227
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100228
229#else /* !CONFIG_X86_LOCAL_APIC */
230static inline void lapic_shutdown(void) { }
231#define local_apic_timer_c2_ok 1
Yinghai Luf3294a32008-06-27 01:41:56 -0700232static inline void init_apic_mappings(void) { }
Ivan Vecerad3ec5ca2008-11-11 14:33:44 +0100233static inline void disable_local_APIC(void) { }
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100234
235#endif /* !CONFIG_X86_LOCAL_APIC */
236
Ingo Molnar1f75ed02009-01-28 17:36:56 +0100237#ifdef CONFIG_X86_64
238#define SET_APIC_ID(x) (apic->set_apic_id(x))
239#else
240
Ingo Molnar6bda2c82009-01-28 19:32:55 +0100241#ifdef CONFIG_X86_LOCAL_APIC
Ingo Molnar1dcdd3d2009-01-28 17:55:37 +0100242static inline unsigned default_get_apic_id(unsigned long x)
Ingo Molnar1f75ed02009-01-28 17:36:56 +0100243{
244 unsigned int ver = GET_APIC_VERSION(apic_read(APIC_LVR));
245
246 if (APIC_XAPIC(ver))
247 return (x >> 24) & 0xFF;
248 else
249 return (x >> 24) & 0x0F;
250}
Ingo Molnar6bda2c82009-01-28 19:32:55 +0100251#endif
Ingo Molnar1f75ed02009-01-28 17:36:56 +0100252
253#endif
254
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700255#endif /* _ASM_X86_APIC_H */