blob: 129752dd2525e9ff45aead3410a3d26816fd797c [file] [log] [blame]
Thomas Gleixner67c5fc52008-01-30 13:30:15 +01001#ifndef _ASM_X86_APIC_H
2#define _ASM_X86_APIC_H
3
4#include <linux/pm.h>
5#include <linux/delay.h>
6#include <asm/fixmap.h>
7#include <asm/apicdef.h>
8#include <asm/processor.h>
9#include <asm/system.h>
Suresh Siddha13c88fb2008-07-10 11:16:52 -070010#include <asm/cpufeature.h>
11#include <asm/msr.h>
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010012
13#define ARCH_APICTIMER_STOPS_ON_C3 1
14
15#define Dprintk(x...)
16
17/*
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
40extern 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
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010043extern int ioapic_force;
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010044
Yinghai Lu3c999f12008-06-20 16:11:20 -070045extern int disable_apic;
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010046/*
47 * Basic functions accessing APICs.
48 */
49#ifdef CONFIG_PARAVIRT
50#include <asm/paravirt.h>
Thomas Gleixner96a388d2007-10-11 11:20:03 +020051#else
Suresh Siddha1b374e42008-07-10 11:16:49 -070052#ifndef CONFIG_X86_64
53#define apic_write native_apic_mem_write
54#define apic_write_atomic native_apic_mem_write_atomic
55#define apic_read native_apic_mem_read
56#endif
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010057#define setup_boot_clock setup_boot_APIC_clock
58#define setup_secondary_clock setup_secondary_APIC_clock
Thomas Gleixner96a388d2007-10-11 11:20:03 +020059#endif
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010060
Ravikiran G Thirumalaiaa7d8e25e2008-03-20 00:41:16 -070061extern int is_vsmp_box(void);
62
Suresh Siddha1b374e42008-07-10 11:16:49 -070063static inline void native_apic_mem_write(u32 reg, u32 v)
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010064{
65 *((volatile u32 *)(APIC_BASE + reg)) = v;
66}
67
Suresh Siddha1b374e42008-07-10 11:16:49 -070068static inline void native_apic_mem_write_atomic(u32 reg, u32 v)
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010069{
Joe Perches3c311fe2008-03-23 01:01:40 -070070 (void)xchg((u32 *)(APIC_BASE + reg), v);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010071}
72
Suresh Siddha1b374e42008-07-10 11:16:49 -070073static inline u32 native_apic_mem_read(u32 reg)
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010074{
75 return *((volatile u32 *)(APIC_BASE + reg));
76}
77
Suresh Siddha13c88fb2008-07-10 11:16:52 -070078static inline void native_apic_msr_write(u32 reg, u32 v)
79{
80 if (reg == APIC_DFR || reg == APIC_ID || reg == APIC_LDR ||
81 reg == APIC_LVR)
82 return;
83
84 wrmsr(APIC_BASE_MSR + (reg >> 4), v, 0);
85}
86
87static inline u32 native_apic_msr_read(u32 reg)
88{
89 u32 low, high;
90
91 if (reg == APIC_DFR)
92 return -1;
93
94 rdmsr(APIC_BASE_MSR + (reg >> 4), low, high);
95 return low;
96}
97
Suresh Siddha1b374e42008-07-10 11:16:49 -070098#ifdef CONFIG_X86_32
Thomas Gleixner67c5fc52008-01-30 13:30:15 +010099extern void apic_wait_icr_idle(void);
100extern u32 safe_apic_wait_icr_idle(void);
Suresh Siddha1b374e42008-07-10 11:16:49 -0700101extern void apic_icr_write(u32 low, u32 id);
102#else
Suresh Siddha6e1cb382008-07-10 11:16:58 -0700103extern int x2apic, x2apic_preenabled;
104extern void check_x2apic(void);
105extern void enable_x2apic(void);
106extern void enable_IR_x2apic(void);
107extern void x2apic_icr_write(u32 low, u32 id);
Suresh Siddha1b374e42008-07-10 11:16:49 -0700108
109struct apic_ops {
110 u32 (*read)(u32 reg);
111 void (*write)(u32 reg, u32 v);
112 void (*write_atomic)(u32 reg, u32 v);
113 u64 (*icr_read)(void);
114 void (*icr_write)(u32 low, u32 high);
115 void (*wait_icr_idle)(void);
116 u32 (*safe_wait_icr_idle)(void);
117};
118
119extern struct apic_ops *apic_ops;
120
121#define apic_read (apic_ops->read)
122#define apic_write (apic_ops->write)
123#define apic_write_atomic (apic_ops->write_atomic)
124#define apic_icr_read (apic_ops->icr_read)
125#define apic_icr_write (apic_ops->icr_write)
126#define apic_wait_icr_idle (apic_ops->wait_icr_idle)
127#define safe_apic_wait_icr_idle (apic_ops->safe_wait_icr_idle)
128#endif
129
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100130extern int get_physical_broadcast(void);
131
132#ifdef CONFIG_X86_GOOD_APIC
133# define FORCE_READ_AROUND_WRITE 0
134# define apic_read_around(x)
135# define apic_write_around(x, y) apic_write((x), (y))
136#else
137# define FORCE_READ_AROUND_WRITE 1
138# define apic_read_around(x) apic_read(x)
139# define apic_write_around(x, y) apic_write_atomic((x), (y))
140#endif
141
Suresh Siddha89027d32008-07-10 11:16:56 -0700142#ifdef CONFIG_X86_64
143static inline void ack_x2APIC_irq(void)
144{
145 /* Docs say use 0 for future compatibility */
146 native_apic_msr_write(APIC_EOI, 0);
147}
148#endif
149
150
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100151static inline void ack_APIC_irq(void)
152{
153 /*
154 * ack_APIC_irq() actually gets compiled as a single instruction:
155 * - a single rmw on Pentium/82489DX
156 * - a single write on P6+ cores (CONFIG_X86_GOOD_APIC)
157 * ... yummie.
158 */
159
160 /* Docs say use 0 for future compatibility */
Suresh Siddha1b374e42008-07-10 11:16:49 -0700161#ifdef CONFIG_X86_32
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100162 apic_write_around(APIC_EOI, 0);
Suresh Siddha1b374e42008-07-10 11:16:49 -0700163#else
164 native_apic_mem_write(APIC_EOI, 0);
165#endif
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100166}
167
168extern int lapic_get_maxlvt(void);
169extern void clear_local_APIC(void);
170extern void connect_bsp_APIC(void);
171extern void disconnect_bsp_APIC(int virt_wire_setup);
172extern void disable_local_APIC(void);
173extern void lapic_shutdown(void);
174extern int verify_local_APIC(void);
175extern void cache_APIC_registers(void);
176extern void sync_Arb_IDs(void);
177extern void init_bsp_APIC(void);
178extern void setup_local_APIC(void);
Andi Kleen739f33b2008-01-30 13:30:40 +0100179extern void end_local_APIC_setup(void);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100180extern void init_apic_mappings(void);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100181extern void setup_boot_APIC_clock(void);
182extern void setup_secondary_APIC_clock(void);
183extern int APIC_init_uniprocessor(void);
Jan Beuliche9427102008-01-30 13:31:24 +0100184extern void enable_NMI_through_LVT0(void);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100185
186/*
187 * On 32bit this is mach-xxx local
188 */
189#ifdef CONFIG_X86_64
Yinghai Lu8643f9d2008-02-19 03:21:06 -0800190extern void early_init_lapic_mapping(void);
Alok Kataria8fbbc4b2008-07-01 11:43:34 -0700191extern int apic_is_clustered_box(void);
192#else
193static inline int apic_is_clustered_box(void)
194{
195 return 0;
196}
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100197#endif
198
Robert Richter7b83dae2008-01-30 13:30:40 +0100199extern u8 setup_APIC_eilvt_mce(u8 vector, u8 msg_type, u8 mask);
200extern u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask);
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100201
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100202
203#else /* !CONFIG_X86_LOCAL_APIC */
204static inline void lapic_shutdown(void) { }
205#define local_apic_timer_c2_ok 1
Yinghai Luf3294a32008-06-27 01:41:56 -0700206static inline void init_apic_mappings(void) { }
Thomas Gleixner67c5fc52008-01-30 13:30:15 +0100207
208#endif /* !CONFIG_X86_LOCAL_APIC */
209
210#endif /* __ASM_APIC_H */