blob: ab1d51a8855e18e80ca4cb24b9ef330e749c13dd [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 Siddha13c88fb52008-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;
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010044/*
45 * Basic functions accessing APICs.
46 */
47#ifdef CONFIG_PARAVIRT
48#include <asm/paravirt.h>
Thomas Gleixner96a388d2007-10-11 11:20:03 +020049#else
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010050#define setup_boot_clock setup_boot_APIC_clock
51#define setup_secondary_clock setup_secondary_APIC_clock
Thomas Gleixner96a388d2007-10-11 11:20:03 +020052#endif
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010053
Ravikiran G Thirumalaiaa7d8e25e2008-03-20 00:41:16 -070054extern int is_vsmp_box(void);
Jaswinder Singh2b97df02008-07-23 17:13:14 +053055extern void xapic_wait_icr_idle(void);
56extern u32 safe_xapic_wait_icr_idle(void);
Jaswinder Singh2b97df02008-07-23 17:13:14 +053057extern void xapic_icr_write(u32, u32);
58extern int setup_profiling_timer(unsigned int);
Ravikiran G Thirumalaiaa7d8e25e2008-03-20 00:41:16 -070059
Suresh Siddha1b374e42008-07-10 11:16:49 -070060static inline void native_apic_mem_write(u32 reg, u32 v)
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010061{
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +010062 volatile u32 *addr = (volatile u32 *)(APIC_BASE + reg);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010063
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +010064 alternative_io("movl %0, %1", "xchgl %0, %1", X86_FEATURE_11AP,
65 ASM_OUTPUT2("=r" (v), "=m" (*addr)),
66 ASM_OUTPUT2("0" (v), "m" (*addr)));
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010067}
68
Suresh Siddha1b374e42008-07-10 11:16:49 -070069static inline u32 native_apic_mem_read(u32 reg)
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010070{
71 return *((volatile u32 *)(APIC_BASE + reg));
72}
73
Suresh Siddha13c88fb52008-07-10 11:16:52 -070074static inline void native_apic_msr_write(u32 reg, u32 v)
75{
76 if (reg == APIC_DFR || reg == APIC_ID || reg == APIC_LDR ||
77 reg == APIC_LVR)
78 return;
79
80 wrmsr(APIC_BASE_MSR + (reg >> 4), v, 0);
81}
82
83static inline u32 native_apic_msr_read(u32 reg)
84{
85 u32 low, high;
86
87 if (reg == APIC_DFR)
88 return -1;
89
90 rdmsr(APIC_BASE_MSR + (reg >> 4), low, high);
91 return low;
92}
93
Yinghai Luc535b6a2008-07-11 18:41:54 -070094#ifndef CONFIG_X86_32
Jaswinder Singhb6b301a2008-12-23 21:52:33 +053095extern int x2apic;
Suresh Siddha6e1cb382008-07-10 11:16:58 -070096extern void check_x2apic(void);
97extern void enable_x2apic(void);
98extern void enable_IR_x2apic(void);
99extern void x2apic_icr_write(u32 low, u32 id);
Yinghai Lua11b5ab2008-09-03 16:58:31 -0700100static inline int x2apic_enabled(void)
101{
102 int msr, msr2;
103
104 if (!cpu_has_x2apic)
105 return 0;
106
107 rdmsr(MSR_IA32_APICBASE, msr, msr2);
108 if (msr & X2APIC_ENABLE)
109 return 1;
110 return 0;
111}
112#else
113#define x2apic_enabled() 0
Yinghai Luc535b6a2008-07-11 18:41:54 -0700114#endif
Suresh Siddha1b374e42008-07-10 11:16:49 -0700115
116struct apic_ops {
117 u32 (*read)(u32 reg);
118 void (*write)(u32 reg, u32 v);
Suresh Siddha1b374e42008-07-10 11:16:49 -0700119 u64 (*icr_read)(void);
120 void (*icr_write)(u32 low, u32 high);
121 void (*wait_icr_idle)(void);
122 u32 (*safe_wait_icr_idle)(void);
123};
124
125extern struct apic_ops *apic_ops;
126
127#define apic_read (apic_ops->read)
128#define apic_write (apic_ops->write)
Suresh Siddha1b374e42008-07-10 11:16:49 -0700129#define apic_icr_read (apic_ops->icr_read)
130#define apic_icr_write (apic_ops->icr_write)
131#define apic_wait_icr_idle (apic_ops->wait_icr_idle)
132#define safe_apic_wait_icr_idle (apic_ops->safe_wait_icr_idle)
Suresh Siddha1b374e42008-07-10 11:16:49 -0700133
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100134extern int get_physical_broadcast(void);
135
Suresh Siddha89027d32008-07-10 11:16:56 -0700136#ifdef CONFIG_X86_64
137static inline void ack_x2APIC_irq(void)
138{
139 /* Docs say use 0 for future compatibility */
140 native_apic_msr_write(APIC_EOI, 0);
141}
142#endif
143
144
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100145static inline void ack_APIC_irq(void)
146{
147 /*
Maciej W. Rozycki0791e132008-07-21 01:28:43 +0100148 * ack_APIC_irq() actually gets compiled as a single instruction
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100149 * ... yummie.
150 */
151
152 /* Docs say use 0 for future compatibility */
Maciej W. Rozycki593f4a72008-07-16 19:15:30 +0100153 apic_write(APIC_EOI, 0);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100154}
155
156extern int lapic_get_maxlvt(void);
157extern void clear_local_APIC(void);
158extern void connect_bsp_APIC(void);
159extern void disconnect_bsp_APIC(int virt_wire_setup);
160extern void disable_local_APIC(void);
161extern void lapic_shutdown(void);
162extern int verify_local_APIC(void);
163extern void cache_APIC_registers(void);
164extern void sync_Arb_IDs(void);
165extern void init_bsp_APIC(void);
166extern void setup_local_APIC(void);
Andi Kleen739f33b2008-01-30 13:30:40 +0100167extern void end_local_APIC_setup(void);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100168extern void init_apic_mappings(void);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100169extern void setup_boot_APIC_clock(void);
170extern void setup_secondary_APIC_clock(void);
171extern int APIC_init_uniprocessor(void);
Jan Beuliche9427102008-01-30 13:31:24 +0100172extern void enable_NMI_through_LVT0(void);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100173
174/*
175 * On 32bit this is mach-xxx local
176 */
177#ifdef CONFIG_X86_64
Yinghai Lu8643f9d2008-02-19 03:21:06 -0800178extern void early_init_lapic_mapping(void);
Alok Kataria8fbbc4b2008-07-01 11:43:34 -0700179extern int apic_is_clustered_box(void);
180#else
181static inline int apic_is_clustered_box(void)
182{
183 return 0;
184}
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100185#endif
186
Robert Richter7b83dae2008-01-30 13:30:40 +0100187extern u8 setup_APIC_eilvt_mce(u8 vector, u8 msg_type, u8 mask);
188extern u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100189
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100190
191#else /* !CONFIG_X86_LOCAL_APIC */
192static inline void lapic_shutdown(void) { }
193#define local_apic_timer_c2_ok 1
Yinghai Luf3294a32008-06-27 01:41:56 -0700194static inline void init_apic_mappings(void) { }
Ivan Vecerad3ec5ca2008-11-11 14:33:44 +0100195static inline void disable_local_APIC(void) { }
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100196
197#endif /* !CONFIG_X86_LOCAL_APIC */
198
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700199#endif /* _ASM_X86_APIC_H */