Vegard Nossum | 77ef50a | 2008-06-18 17:08:48 +0200 | [diff] [blame] | 1 | #ifndef ASM_X86__APIC_H |
| 2 | #define ASM_X86__APIC_H |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 3 | |
| 4 | #include <linux/pm.h> |
| 5 | #include <linux/delay.h> |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 6 | |
| 7 | #include <asm/alternative.h> |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 8 | #include <asm/fixmap.h> |
| 9 | #include <asm/apicdef.h> |
| 10 | #include <asm/processor.h> |
| 11 | #include <asm/system.h> |
Suresh Siddha | 13c88fb | 2008-07-10 11:16:52 -0700 | [diff] [blame] | 12 | #include <asm/cpufeature.h> |
| 13 | #include <asm/msr.h> |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 14 | |
| 15 | #define ARCH_APICTIMER_STOPS_ON_C3 1 |
| 16 | |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 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 | |
| 36 | extern void generic_apic_probe(void); |
| 37 | |
| 38 | #ifdef CONFIG_X86_LOCAL_APIC |
| 39 | |
Maciej W. Rozycki | baa1318 | 2008-07-14 18:44:51 +0100 | [diff] [blame] | 40 | extern unsigned int apic_verbosity; |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 41 | extern int local_apic_timer_c2_ok; |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 42 | |
Yinghai Lu | 3c999f1 | 2008-06-20 16:11:20 -0700 | [diff] [blame] | 43 | extern int disable_apic; |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 44 | /* |
| 45 | * Basic functions accessing APICs. |
| 46 | */ |
| 47 | #ifdef CONFIG_PARAVIRT |
| 48 | #include <asm/paravirt.h> |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 49 | #else |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 50 | #define setup_boot_clock setup_boot_APIC_clock |
| 51 | #define setup_secondary_clock setup_secondary_APIC_clock |
Thomas Gleixner | 96a388d | 2007-10-11 11:20:03 +0200 | [diff] [blame] | 52 | #endif |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 53 | |
Ravikiran G Thirumalai | aa7d8e25e | 2008-03-20 00:41:16 -0700 | [diff] [blame] | 54 | extern int is_vsmp_box(void); |
Jaswinder Singh | 2b97df0 | 2008-07-23 17:13:14 +0530 | [diff] [blame] | 55 | extern void xapic_wait_icr_idle(void); |
| 56 | extern u32 safe_xapic_wait_icr_idle(void); |
| 57 | extern u64 xapic_icr_read(void); |
| 58 | extern void xapic_icr_write(u32, u32); |
| 59 | extern int setup_profiling_timer(unsigned int); |
Ravikiran G Thirumalai | aa7d8e25e | 2008-03-20 00:41:16 -0700 | [diff] [blame] | 60 | |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 61 | static inline void native_apic_mem_write(u32 reg, u32 v) |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 62 | { |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 63 | volatile u32 *addr = (volatile u32 *)(APIC_BASE + reg); |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 64 | |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 65 | alternative_io("movl %0, %1", "xchgl %0, %1", X86_FEATURE_11AP, |
| 66 | ASM_OUTPUT2("=r" (v), "=m" (*addr)), |
| 67 | ASM_OUTPUT2("0" (v), "m" (*addr))); |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 68 | } |
| 69 | |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 70 | static inline u32 native_apic_mem_read(u32 reg) |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 71 | { |
| 72 | return *((volatile u32 *)(APIC_BASE + reg)); |
| 73 | } |
| 74 | |
Suresh Siddha | 13c88fb | 2008-07-10 11:16:52 -0700 | [diff] [blame] | 75 | static inline void native_apic_msr_write(u32 reg, u32 v) |
| 76 | { |
| 77 | if (reg == APIC_DFR || reg == APIC_ID || reg == APIC_LDR || |
| 78 | reg == APIC_LVR) |
| 79 | return; |
| 80 | |
| 81 | wrmsr(APIC_BASE_MSR + (reg >> 4), v, 0); |
| 82 | } |
| 83 | |
| 84 | static inline u32 native_apic_msr_read(u32 reg) |
| 85 | { |
| 86 | u32 low, high; |
| 87 | |
| 88 | if (reg == APIC_DFR) |
| 89 | return -1; |
| 90 | |
| 91 | rdmsr(APIC_BASE_MSR + (reg >> 4), low, high); |
| 92 | return low; |
| 93 | } |
| 94 | |
Yinghai Lu | c535b6a | 2008-07-11 18:41:54 -0700 | [diff] [blame] | 95 | #ifndef CONFIG_X86_32 |
Suresh Siddha | 6e1cb38 | 2008-07-10 11:16:58 -0700 | [diff] [blame] | 96 | extern int x2apic, x2apic_preenabled; |
| 97 | extern void check_x2apic(void); |
| 98 | extern void enable_x2apic(void); |
| 99 | extern void enable_IR_x2apic(void); |
| 100 | extern void x2apic_icr_write(u32 low, u32 id); |
Yinghai Lu | a11b5ab | 2008-09-03 16:58:31 -0700 | [diff] [blame^] | 101 | static inline int x2apic_enabled(void) |
| 102 | { |
| 103 | int msr, msr2; |
| 104 | |
| 105 | if (!cpu_has_x2apic) |
| 106 | return 0; |
| 107 | |
| 108 | rdmsr(MSR_IA32_APICBASE, msr, msr2); |
| 109 | if (msr & X2APIC_ENABLE) |
| 110 | return 1; |
| 111 | return 0; |
| 112 | } |
| 113 | #else |
| 114 | #define x2apic_enabled() 0 |
Yinghai Lu | c535b6a | 2008-07-11 18:41:54 -0700 | [diff] [blame] | 115 | #endif |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 116 | |
| 117 | struct apic_ops { |
| 118 | u32 (*read)(u32 reg); |
| 119 | void (*write)(u32 reg, u32 v); |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 120 | u64 (*icr_read)(void); |
| 121 | void (*icr_write)(u32 low, u32 high); |
| 122 | void (*wait_icr_idle)(void); |
| 123 | u32 (*safe_wait_icr_idle)(void); |
| 124 | }; |
| 125 | |
| 126 | extern struct apic_ops *apic_ops; |
| 127 | |
| 128 | #define apic_read (apic_ops->read) |
| 129 | #define apic_write (apic_ops->write) |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 130 | #define apic_icr_read (apic_ops->icr_read) |
| 131 | #define apic_icr_write (apic_ops->icr_write) |
| 132 | #define apic_wait_icr_idle (apic_ops->wait_icr_idle) |
| 133 | #define safe_apic_wait_icr_idle (apic_ops->safe_wait_icr_idle) |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 134 | |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 135 | extern int get_physical_broadcast(void); |
| 136 | |
Suresh Siddha | 89027d3 | 2008-07-10 11:16:56 -0700 | [diff] [blame] | 137 | #ifdef CONFIG_X86_64 |
| 138 | static inline void ack_x2APIC_irq(void) |
| 139 | { |
| 140 | /* Docs say use 0 for future compatibility */ |
| 141 | native_apic_msr_write(APIC_EOI, 0); |
| 142 | } |
| 143 | #endif |
| 144 | |
| 145 | |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 146 | static inline void ack_APIC_irq(void) |
| 147 | { |
| 148 | /* |
Maciej W. Rozycki | 0791e13 | 2008-07-21 01:28:43 +0100 | [diff] [blame] | 149 | * ack_APIC_irq() actually gets compiled as a single instruction |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 150 | * ... yummie. |
| 151 | */ |
| 152 | |
| 153 | /* Docs say use 0 for future compatibility */ |
Maciej W. Rozycki | 593f4a7 | 2008-07-16 19:15:30 +0100 | [diff] [blame] | 154 | apic_write(APIC_EOI, 0); |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | extern int lapic_get_maxlvt(void); |
| 158 | extern void clear_local_APIC(void); |
| 159 | extern void connect_bsp_APIC(void); |
| 160 | extern void disconnect_bsp_APIC(int virt_wire_setup); |
| 161 | extern void disable_local_APIC(void); |
| 162 | extern void lapic_shutdown(void); |
| 163 | extern int verify_local_APIC(void); |
| 164 | extern void cache_APIC_registers(void); |
| 165 | extern void sync_Arb_IDs(void); |
| 166 | extern void init_bsp_APIC(void); |
| 167 | extern void setup_local_APIC(void); |
Andi Kleen | 739f33b | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 168 | extern void end_local_APIC_setup(void); |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 169 | extern void init_apic_mappings(void); |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 170 | extern void setup_boot_APIC_clock(void); |
| 171 | extern void setup_secondary_APIC_clock(void); |
| 172 | extern int APIC_init_uniprocessor(void); |
Jan Beulich | e942710 | 2008-01-30 13:31:24 +0100 | [diff] [blame] | 173 | extern void enable_NMI_through_LVT0(void); |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 174 | |
| 175 | /* |
| 176 | * On 32bit this is mach-xxx local |
| 177 | */ |
| 178 | #ifdef CONFIG_X86_64 |
Yinghai Lu | 8643f9d | 2008-02-19 03:21:06 -0800 | [diff] [blame] | 179 | extern void early_init_lapic_mapping(void); |
Alok Kataria | 8fbbc4b | 2008-07-01 11:43:34 -0700 | [diff] [blame] | 180 | extern int apic_is_clustered_box(void); |
| 181 | #else |
| 182 | static inline int apic_is_clustered_box(void) |
| 183 | { |
| 184 | return 0; |
| 185 | } |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 186 | #endif |
| 187 | |
Robert Richter | 7b83dae | 2008-01-30 13:30:40 +0100 | [diff] [blame] | 188 | extern u8 setup_APIC_eilvt_mce(u8 vector, u8 msg_type, u8 mask); |
| 189 | extern u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask); |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 190 | |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 191 | |
| 192 | #else /* !CONFIG_X86_LOCAL_APIC */ |
| 193 | static inline void lapic_shutdown(void) { } |
| 194 | #define local_apic_timer_c2_ok 1 |
Yinghai Lu | f3294a3 | 2008-06-27 01:41:56 -0700 | [diff] [blame] | 195 | static inline void init_apic_mappings(void) { } |
Thomas Gleixner | 67c5fc5 | 2008-01-30 13:30:15 +0100 | [diff] [blame] | 196 | |
| 197 | #endif /* !CONFIG_X86_LOCAL_APIC */ |
| 198 | |
Vegard Nossum | 77ef50a | 2008-06-18 17:08:48 +0200 | [diff] [blame] | 199 | #endif /* ASM_X86__APIC_H */ |