11965aae3SH. Peter Anvin #ifndef _ASM_X86_APIC_H 21965aae3SH. Peter Anvin #define _ASM_X86_APIC_H 3bb898558SAl Viro 4e2780a68SIngo Molnar #include <linux/cpumask.h> 5e2780a68SIngo Molnar #include <linux/pm.h> 6bb898558SAl Viro 7bb898558SAl Viro #include <asm/alternative.h> 8bb898558SAl Viro #include <asm/cpufeature.h> 9e2780a68SIngo Molnar #include <asm/processor.h> 10e2780a68SIngo Molnar #include <asm/apicdef.h> 1160063497SArun Sharma #include <linux/atomic.h> 12e2780a68SIngo Molnar #include <asm/fixmap.h> 13e2780a68SIngo Molnar #include <asm/mpspec.h> 14bb898558SAl Viro #include <asm/msr.h> 15eddc0e92SSeiji Aguchi #include <asm/idle.h> 16bb898558SAl Viro 17bb898558SAl Viro #define ARCH_APICTIMER_STOPS_ON_C3 1 18bb898558SAl Viro 19bb898558SAl Viro /* 20bb898558SAl Viro * Debugging macros 21bb898558SAl Viro */ 22bb898558SAl Viro #define APIC_QUIET 0 23bb898558SAl Viro #define APIC_VERBOSE 1 24bb898558SAl Viro #define APIC_DEBUG 2 25bb898558SAl Viro 26bb898558SAl Viro /* 27bb898558SAl Viro * Define the default level of output to be very little 28bb898558SAl Viro * This can be turned up by using apic=verbose for more 29bb898558SAl Viro * information and apic=debug for _lots_ of information. 30bb898558SAl Viro * apic_verbosity is defined in apic.c 31bb898558SAl Viro */ 32bb898558SAl Viro #define apic_printk(v, s, a...) do { \ 33bb898558SAl Viro if ((v) <= apic_verbosity) \ 34bb898558SAl Viro printk(s, ##a); \ 35bb898558SAl Viro } while (0) 36bb898558SAl Viro 37bb898558SAl Viro 38160d8dacSIngo Molnar #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32) 39bb898558SAl Viro extern void generic_apic_probe(void); 40160d8dacSIngo Molnar #else 41160d8dacSIngo Molnar static inline void generic_apic_probe(void) 42160d8dacSIngo Molnar { 43160d8dacSIngo Molnar } 44160d8dacSIngo Molnar #endif 45bb898558SAl Viro 46bb898558SAl Viro #ifdef CONFIG_X86_LOCAL_APIC 47bb898558SAl Viro 48bb898558SAl Viro extern unsigned int apic_verbosity; 49bb898558SAl Viro extern int local_apic_timer_c2_ok; 50bb898558SAl Viro 51bb898558SAl Viro extern int disable_apic; 521ade93efSJacob Pan extern unsigned int lapic_timer_frequency; 530939e4fdSIngo Molnar 540939e4fdSIngo Molnar #ifdef CONFIG_SMP 550939e4fdSIngo Molnar extern void __inquire_remote_apic(int apicid); 560939e4fdSIngo Molnar #else /* CONFIG_SMP */ 570939e4fdSIngo Molnar static inline void __inquire_remote_apic(int apicid) 580939e4fdSIngo Molnar { 590939e4fdSIngo Molnar } 600939e4fdSIngo Molnar #endif /* CONFIG_SMP */ 610939e4fdSIngo Molnar 620939e4fdSIngo Molnar static inline void default_inquire_remote_apic(int apicid) 630939e4fdSIngo Molnar { 640939e4fdSIngo Molnar if (apic_verbosity >= APIC_DEBUG) 650939e4fdSIngo Molnar __inquire_remote_apic(apicid); 660939e4fdSIngo Molnar } 670939e4fdSIngo Molnar 68bb898558SAl Viro /* 698312136fSCyrill Gorcunov * With 82489DX we can't rely on apic feature bit 708312136fSCyrill Gorcunov * retrieved via cpuid but still have to deal with 718312136fSCyrill Gorcunov * such an apic chip so we assume that SMP configuration 728312136fSCyrill Gorcunov * is found from MP table (64bit case uses ACPI mostly 738312136fSCyrill Gorcunov * which set smp presence flag as well so we are safe 748312136fSCyrill Gorcunov * to use this helper too). 758312136fSCyrill Gorcunov */ 768312136fSCyrill Gorcunov static inline bool apic_from_smp_config(void) 778312136fSCyrill Gorcunov { 788312136fSCyrill Gorcunov return smp_found_config && !disable_apic; 798312136fSCyrill Gorcunov } 808312136fSCyrill Gorcunov 818312136fSCyrill Gorcunov /* 82bb898558SAl Viro * Basic functions accessing APICs. 83bb898558SAl Viro */ 84bb898558SAl Viro #ifdef CONFIG_PARAVIRT 85bb898558SAl Viro #include <asm/paravirt.h> 86bb898558SAl Viro #endif 87bb898558SAl Viro 88bb898558SAl Viro extern int setup_profiling_timer(unsigned int); 89bb898558SAl Viro 90bb898558SAl Viro static inline void native_apic_mem_write(u32 reg, u32 v) 91bb898558SAl Viro { 92bb898558SAl Viro volatile u32 *addr = (volatile u32 *)(APIC_BASE + reg); 93bb898558SAl Viro 949b13a93dSBorislav Petkov alternative_io("movl %0, %1", "xchgl %0, %1", X86_BUG_11AP, 95bb898558SAl Viro ASM_OUTPUT2("=r" (v), "=m" (*addr)), 96bb898558SAl Viro ASM_OUTPUT2("0" (v), "m" (*addr))); 97bb898558SAl Viro } 98bb898558SAl Viro 99bb898558SAl Viro static inline u32 native_apic_mem_read(u32 reg) 100bb898558SAl Viro { 101bb898558SAl Viro return *((volatile u32 *)(APIC_BASE + reg)); 102bb898558SAl Viro } 103bb898558SAl Viro 104c1eeb2deSYinghai Lu extern void native_apic_wait_icr_idle(void); 105c1eeb2deSYinghai Lu extern u32 native_safe_apic_wait_icr_idle(void); 106c1eeb2deSYinghai Lu extern void native_apic_icr_write(u32 low, u32 id); 107c1eeb2deSYinghai Lu extern u64 native_apic_icr_read(void); 108c1eeb2deSYinghai Lu 1098d806960SThomas Gleixner static inline bool apic_is_x2apic_enabled(void) 1108d806960SThomas Gleixner { 1118d806960SThomas Gleixner u64 msr; 1128d806960SThomas Gleixner 1138d806960SThomas Gleixner if (rdmsrl_safe(MSR_IA32_APICBASE, &msr)) 1148d806960SThomas Gleixner return false; 1158d806960SThomas Gleixner return msr & X2APIC_ENABLE; 1168d806960SThomas Gleixner } 1178d806960SThomas Gleixner 118d0b03bd1SHan, Weidong #ifdef CONFIG_X86_X2APIC 119ce4e240cSSuresh Siddha /* 120ce4e240cSSuresh Siddha * Make previous memory operations globally visible before 121ce4e240cSSuresh Siddha * sending the IPI through x2apic wrmsr. We need a serializing instruction or 122ce4e240cSSuresh Siddha * mfence for this. 123ce4e240cSSuresh Siddha */ 124ce4e240cSSuresh Siddha static inline void x2apic_wrmsr_fence(void) 125ce4e240cSSuresh Siddha { 126ce4e240cSSuresh Siddha asm volatile("mfence" : : : "memory"); 127ce4e240cSSuresh Siddha } 128ce4e240cSSuresh Siddha 129bb898558SAl Viro static inline void native_apic_msr_write(u32 reg, u32 v) 130bb898558SAl Viro { 131bb898558SAl Viro if (reg == APIC_DFR || reg == APIC_ID || reg == APIC_LDR || 132bb898558SAl Viro reg == APIC_LVR) 133bb898558SAl Viro return; 134bb898558SAl Viro 135bb898558SAl Viro wrmsr(APIC_BASE_MSR + (reg >> 4), v, 0); 136bb898558SAl Viro } 137bb898558SAl Viro 1380ab711aeSMichael S. Tsirkin static inline void native_apic_msr_eoi_write(u32 reg, u32 v) 1390ab711aeSMichael S. Tsirkin { 1400ab711aeSMichael S. Tsirkin wrmsr(APIC_BASE_MSR + (APIC_EOI >> 4), APIC_EOI_ACK, 0); 1410ab711aeSMichael S. Tsirkin } 1420ab711aeSMichael S. Tsirkin 143bb898558SAl Viro static inline u32 native_apic_msr_read(u32 reg) 144bb898558SAl Viro { 1450059b243SAndi Kleen u64 msr; 146bb898558SAl Viro 147bb898558SAl Viro if (reg == APIC_DFR) 148bb898558SAl Viro return -1; 149bb898558SAl Viro 1500059b243SAndi Kleen rdmsrl(APIC_BASE_MSR + (reg >> 4), msr); 1510059b243SAndi Kleen return (u32)msr; 152bb898558SAl Viro } 153bb898558SAl Viro 154c1eeb2deSYinghai Lu static inline void native_x2apic_wait_icr_idle(void) 155c1eeb2deSYinghai Lu { 156c1eeb2deSYinghai Lu /* no need to wait for icr idle in x2apic */ 157c1eeb2deSYinghai Lu return; 158c1eeb2deSYinghai Lu } 159c1eeb2deSYinghai Lu 160c1eeb2deSYinghai Lu static inline u32 native_safe_x2apic_wait_icr_idle(void) 161c1eeb2deSYinghai Lu { 162c1eeb2deSYinghai Lu /* no need to wait for icr idle in x2apic */ 163c1eeb2deSYinghai Lu return 0; 164c1eeb2deSYinghai Lu } 165c1eeb2deSYinghai Lu 166c1eeb2deSYinghai Lu static inline void native_x2apic_icr_write(u32 low, u32 id) 167c1eeb2deSYinghai Lu { 168c1eeb2deSYinghai Lu wrmsrl(APIC_BASE_MSR + (APIC_ICR >> 4), ((__u64) id) << 32 | low); 169c1eeb2deSYinghai Lu } 170c1eeb2deSYinghai Lu 171c1eeb2deSYinghai Lu static inline u64 native_x2apic_icr_read(void) 172c1eeb2deSYinghai Lu { 173c1eeb2deSYinghai Lu unsigned long val; 174c1eeb2deSYinghai Lu 175c1eeb2deSYinghai Lu rdmsrl(APIC_BASE_MSR + (APIC_ICR >> 4), val); 176c1eeb2deSYinghai Lu return val; 177c1eeb2deSYinghai Lu } 178c1eeb2deSYinghai Lu 17981a46dd8SThomas Gleixner extern int x2apic_mode; 180fc1edaf9SSuresh Siddha extern int x2apic_phys; 181fb209bd8SYinghai Lu extern int x2apic_preenabled; 182bb898558SAl Viro extern void check_x2apic(void); 183bb898558SAl Viro extern void enable_x2apic(void); 184bb898558SAl Viro static inline int x2apic_enabled(void) 185bb898558SAl Viro { 1868d806960SThomas Gleixner return cpu_has_x2apic && apic_is_x2apic_enabled(); 187bb898558SAl Viro } 188fc1edaf9SSuresh Siddha 189fc1edaf9SSuresh Siddha #define x2apic_supported() (cpu_has_x2apic) 190ce69a784SGleb Natapov static inline void x2apic_force_phys(void) 191ce69a784SGleb Natapov { 192ce69a784SGleb Natapov x2apic_phys = 1; 193ce69a784SGleb Natapov } 194bb898558SAl Viro #else 195fb209bd8SYinghai Lu static inline void disable_x2apic(void) 196fb209bd8SYinghai Lu { 197fb209bd8SYinghai Lu } 19806cd9a7dSYinghai Lu static inline void check_x2apic(void) 19906cd9a7dSYinghai Lu { 20006cd9a7dSYinghai Lu } 20106cd9a7dSYinghai Lu static inline void enable_x2apic(void) 20206cd9a7dSYinghai Lu { 20306cd9a7dSYinghai Lu } 20406cd9a7dSYinghai Lu static inline int x2apic_enabled(void) 20506cd9a7dSYinghai Lu { 20606cd9a7dSYinghai Lu return 0; 20706cd9a7dSYinghai Lu } 208ce69a784SGleb Natapov static inline void x2apic_force_phys(void) 209ce69a784SGleb Natapov { 210ce69a784SGleb Natapov } 211cf6567feSSuresh Siddha 21281a46dd8SThomas Gleixner #define x2apic_mode (0) 21381a46dd8SThomas Gleixner #define x2apic_preenabled (0) 21481a46dd8SThomas Gleixner #define x2apic_supported() (0) 215bb898558SAl Viro #endif 216bb898558SAl Viro 21793758238SWeidong Han extern void enable_IR_x2apic(void); 21893758238SWeidong Han 219bb898558SAl Viro extern int get_physical_broadcast(void); 220bb898558SAl Viro 221bb898558SAl Viro extern int lapic_get_maxlvt(void); 222bb898558SAl Viro extern void clear_local_APIC(void); 223bb898558SAl Viro extern void connect_bsp_APIC(void); 224bb898558SAl Viro extern void disconnect_bsp_APIC(int virt_wire_setup); 225bb898558SAl Viro extern void disable_local_APIC(void); 226bb898558SAl Viro extern void lapic_shutdown(void); 227bb898558SAl Viro extern int verify_local_APIC(void); 228bb898558SAl Viro extern void sync_Arb_IDs(void); 229bb898558SAl Viro extern void init_bsp_APIC(void); 230bb898558SAl Viro extern void setup_local_APIC(void); 231bb898558SAl Viro extern void end_local_APIC_setup(void); 2322fb270f3SJan Beulich extern void bsp_end_local_APIC_setup(void); 233bb898558SAl Viro extern void init_apic_mappings(void); 234c0104d38SYinghai Lu void register_lapic_address(unsigned long address); 235bb898558SAl Viro extern void setup_boot_APIC_clock(void); 236bb898558SAl Viro extern void setup_secondary_APIC_clock(void); 237bb898558SAl Viro extern int APIC_init_uniprocessor(void); 238a906fdaaSThomas Gleixner extern int apic_force_enable(unsigned long addr); 239bb898558SAl Viro 240bb898558SAl Viro /* 241bb898558SAl Viro * On 32bit this is mach-xxx local 242bb898558SAl Viro */ 243bb898558SAl Viro #ifdef CONFIG_X86_64 244bb898558SAl Viro extern int apic_is_clustered_box(void); 245bb898558SAl Viro #else 246bb898558SAl Viro static inline int apic_is_clustered_box(void) 247bb898558SAl Viro { 248bb898558SAl Viro return 0; 249bb898558SAl Viro } 250bb898558SAl Viro #endif 251bb898558SAl Viro 25227afdf20SRobert Richter extern int setup_APIC_eilvt(u8 lvt_off, u8 vector, u8 msg_type, u8 mask); 253bb898558SAl Viro 254bb898558SAl Viro #else /* !CONFIG_X86_LOCAL_APIC */ 255bb898558SAl Viro static inline void lapic_shutdown(void) { } 256bb898558SAl Viro #define local_apic_timer_c2_ok 1 257bb898558SAl Viro static inline void init_apic_mappings(void) { } 258d3ec5caeSIvan Vecera static inline void disable_local_APIC(void) { } 259736decacSThomas Gleixner # define setup_boot_APIC_clock x86_init_noop 260736decacSThomas Gleixner # define setup_secondary_APIC_clock x86_init_noop 261bb898558SAl Viro #endif /* !CONFIG_X86_LOCAL_APIC */ 262bb898558SAl Viro 2631f75ed0cSIngo Molnar #ifdef CONFIG_X86_64 2641f75ed0cSIngo Molnar #define SET_APIC_ID(x) (apic->set_apic_id(x)) 2651f75ed0cSIngo Molnar #else 2661f75ed0cSIngo Molnar 2671f75ed0cSIngo Molnar #endif 2681f75ed0cSIngo Molnar 269e2780a68SIngo Molnar /* 270e2780a68SIngo Molnar * Copyright 2004 James Cleverdon, IBM. 271e2780a68SIngo Molnar * Subject to the GNU Public License, v.2 272e2780a68SIngo Molnar * 273e2780a68SIngo Molnar * Generic APIC sub-arch data struct. 274e2780a68SIngo Molnar * 275e2780a68SIngo Molnar * Hacked for x86-64 by James Cleverdon from i386 architecture code by 276e2780a68SIngo Molnar * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and 277e2780a68SIngo Molnar * James Cleverdon. 278e2780a68SIngo Molnar */ 279be163a15SIngo Molnar struct apic { 280e2780a68SIngo Molnar char *name; 281e2780a68SIngo Molnar 282e2780a68SIngo Molnar int (*probe)(void); 283e2780a68SIngo Molnar int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id); 284fa63030eSDaniel J Blueman int (*apic_id_valid)(int apicid); 285e2780a68SIngo Molnar int (*apic_id_registered)(void); 286e2780a68SIngo Molnar 287e2780a68SIngo Molnar u32 irq_delivery_mode; 288e2780a68SIngo Molnar u32 irq_dest_mode; 289e2780a68SIngo Molnar 290e2780a68SIngo Molnar const struct cpumask *(*target_cpus)(void); 291e2780a68SIngo Molnar 292e2780a68SIngo Molnar int disable_esr; 293e2780a68SIngo Molnar 294e2780a68SIngo Molnar int dest_logical; 2957abc0753SCyrill Gorcunov unsigned long (*check_apicid_used)(physid_mask_t *map, int apicid); 296e2780a68SIngo Molnar 2971ac322d0SSuresh Siddha void (*vector_allocation_domain)(int cpu, struct cpumask *retmask, 2981ac322d0SSuresh Siddha const struct cpumask *mask); 299e2780a68SIngo Molnar void (*init_apic_ldr)(void); 300e2780a68SIngo Molnar 3017abc0753SCyrill Gorcunov void (*ioapic_phys_id_map)(physid_mask_t *phys_map, physid_mask_t *retmap); 302e2780a68SIngo Molnar 303e2780a68SIngo Molnar void (*setup_apic_routing)(void); 304e2780a68SIngo Molnar int (*cpu_present_to_apicid)(int mps_cpu); 3057abc0753SCyrill Gorcunov void (*apicid_to_cpu_present)(int phys_apicid, physid_mask_t *retmap); 306e11dadabSThomas Gleixner int (*check_phys_apicid_present)(int phys_apicid); 307e2780a68SIngo Molnar int (*phys_pkg_id)(int cpuid_apic, int index_msb); 308e2780a68SIngo Molnar 309e2780a68SIngo Molnar unsigned int (*get_apic_id)(unsigned long x); 310e2780a68SIngo Molnar unsigned long (*set_apic_id)(unsigned int id); 311e2780a68SIngo Molnar unsigned long apic_id_mask; 312e2780a68SIngo Molnar 313ff164324SAlexander Gordeev int (*cpu_mask_to_apicid_and)(const struct cpumask *cpumask, 314ff164324SAlexander Gordeev const struct cpumask *andmask, 315ff164324SAlexander Gordeev unsigned int *apicid); 316e2780a68SIngo Molnar 317e2780a68SIngo Molnar /* ipi */ 318e2780a68SIngo Molnar void (*send_IPI_mask)(const struct cpumask *mask, int vector); 319e2780a68SIngo Molnar void (*send_IPI_mask_allbutself)(const struct cpumask *mask, 320e2780a68SIngo Molnar int vector); 321e2780a68SIngo Molnar void (*send_IPI_allbutself)(int vector); 322e2780a68SIngo Molnar void (*send_IPI_all)(int vector); 323e2780a68SIngo Molnar void (*send_IPI_self)(int vector); 324e2780a68SIngo Molnar 325e2780a68SIngo Molnar /* wakeup_secondary_cpu */ 3261f5bcabfSIngo Molnar int (*wakeup_secondary_cpu)(int apicid, unsigned long start_eip); 327e2780a68SIngo Molnar 328465822cfSDavid Rientjes bool wait_for_init_deassert; 329e2780a68SIngo Molnar void (*inquire_remote_apic)(int apicid); 330e2780a68SIngo Molnar 331e2780a68SIngo Molnar /* apic ops */ 332e2780a68SIngo Molnar u32 (*read)(u32 reg); 333e2780a68SIngo Molnar void (*write)(u32 reg, u32 v); 3342a43195dSMichael S. Tsirkin /* 3352a43195dSMichael S. Tsirkin * ->eoi_write() has the same signature as ->write(). 3362a43195dSMichael S. Tsirkin * 3372a43195dSMichael S. Tsirkin * Drivers can support both ->eoi_write() and ->write() by passing the same 3382a43195dSMichael S. Tsirkin * callback value. Kernel can override ->eoi_write() and fall back 3392a43195dSMichael S. Tsirkin * on write for EOI. 3402a43195dSMichael S. Tsirkin */ 3412a43195dSMichael S. Tsirkin void (*eoi_write)(u32 reg, u32 v); 342e2780a68SIngo Molnar u64 (*icr_read)(void); 343e2780a68SIngo Molnar void (*icr_write)(u32 low, u32 high); 344e2780a68SIngo Molnar void (*wait_icr_idle)(void); 345e2780a68SIngo Molnar u32 (*safe_wait_icr_idle)(void); 346acb8bc09STejun Heo 347acb8bc09STejun Heo #ifdef CONFIG_X86_32 348acb8bc09STejun Heo /* 349acb8bc09STejun Heo * Called very early during boot from get_smp_config(). It should 350acb8bc09STejun Heo * return the logical apicid. x86_[bios]_cpu_to_apicid is 351acb8bc09STejun Heo * initialized before this function is called. 352acb8bc09STejun Heo * 353acb8bc09STejun Heo * If logical apicid can't be determined that early, the function 354acb8bc09STejun Heo * may return BAD_APICID. Logical apicid will be configured after 355acb8bc09STejun Heo * init_apic_ldr() while bringing up CPUs. Note that NUMA affinity 356acb8bc09STejun Heo * won't be applied properly during early boot in this case. 357acb8bc09STejun Heo */ 358acb8bc09STejun Heo int (*x86_32_early_logical_apicid)(int cpu); 359acb8bc09STejun Heo #endif 360e2780a68SIngo Molnar }; 361e2780a68SIngo Molnar 3620917c01fSIngo Molnar /* 3630917c01fSIngo Molnar * Pointer to the local APIC driver in use on this system (there's 3640917c01fSIngo Molnar * always just one such driver in use - the kernel decides via an 3650917c01fSIngo Molnar * early probing process which one it picks - and then sticks to it): 3660917c01fSIngo Molnar */ 367be163a15SIngo Molnar extern struct apic *apic; 3680917c01fSIngo Molnar 3690917c01fSIngo Molnar /* 370107e0e0cSSuresh Siddha * APIC drivers are probed based on how they are listed in the .apicdrivers 371107e0e0cSSuresh Siddha * section. So the order is important and enforced by the ordering 372107e0e0cSSuresh Siddha * of different apic driver files in the Makefile. 373107e0e0cSSuresh Siddha * 374107e0e0cSSuresh Siddha * For the files having two apic drivers, we use apic_drivers() 375107e0e0cSSuresh Siddha * to enforce the order with in them. 376107e0e0cSSuresh Siddha */ 377107e0e0cSSuresh Siddha #define apic_driver(sym) \ 37875fdd155SAndi Kleen static const struct apic *__apicdrivers_##sym __used \ 379107e0e0cSSuresh Siddha __aligned(sizeof(struct apic *)) \ 380107e0e0cSSuresh Siddha __section(.apicdrivers) = { &sym } 381107e0e0cSSuresh Siddha 382107e0e0cSSuresh Siddha #define apic_drivers(sym1, sym2) \ 383107e0e0cSSuresh Siddha static struct apic *__apicdrivers_##sym1##sym2[2] __used \ 384107e0e0cSSuresh Siddha __aligned(sizeof(struct apic *)) \ 385107e0e0cSSuresh Siddha __section(.apicdrivers) = { &sym1, &sym2 } 386107e0e0cSSuresh Siddha 387107e0e0cSSuresh Siddha extern struct apic *__apicdrivers[], *__apicdrivers_end[]; 388107e0e0cSSuresh Siddha 389107e0e0cSSuresh Siddha /* 3900917c01fSIngo Molnar * APIC functionality to boot other CPUs - only used on SMP: 3910917c01fSIngo Molnar */ 3920917c01fSIngo Molnar #ifdef CONFIG_SMP 3932b6163bfSYinghai Lu extern atomic_t init_deasserted; 3942b6163bfSYinghai Lu extern int wakeup_secondary_cpu_via_nmi(int apicid, unsigned long start_eip); 3950917c01fSIngo Molnar #endif 396e2780a68SIngo Molnar 397d674cd19SCyrill Gorcunov #ifdef CONFIG_X86_LOCAL_APIC 398346b46beSFernando Luis Vázquez Cao 399e2780a68SIngo Molnar static inline u32 apic_read(u32 reg) 400e2780a68SIngo Molnar { 401e2780a68SIngo Molnar return apic->read(reg); 402e2780a68SIngo Molnar } 403e2780a68SIngo Molnar 404e2780a68SIngo Molnar static inline void apic_write(u32 reg, u32 val) 405e2780a68SIngo Molnar { 406e2780a68SIngo Molnar apic->write(reg, val); 407e2780a68SIngo Molnar } 408e2780a68SIngo Molnar 4092a43195dSMichael S. Tsirkin static inline void apic_eoi(void) 4102a43195dSMichael S. Tsirkin { 4112a43195dSMichael S. Tsirkin apic->eoi_write(APIC_EOI, APIC_EOI_ACK); 4122a43195dSMichael S. Tsirkin } 4132a43195dSMichael S. Tsirkin 414e2780a68SIngo Molnar static inline u64 apic_icr_read(void) 415e2780a68SIngo Molnar { 416e2780a68SIngo Molnar return apic->icr_read(); 417e2780a68SIngo Molnar } 418e2780a68SIngo Molnar 419e2780a68SIngo Molnar static inline void apic_icr_write(u32 low, u32 high) 420e2780a68SIngo Molnar { 421e2780a68SIngo Molnar apic->icr_write(low, high); 422e2780a68SIngo Molnar } 423e2780a68SIngo Molnar 424e2780a68SIngo Molnar static inline void apic_wait_icr_idle(void) 425e2780a68SIngo Molnar { 426e2780a68SIngo Molnar apic->wait_icr_idle(); 427e2780a68SIngo Molnar } 428e2780a68SIngo Molnar 429e2780a68SIngo Molnar static inline u32 safe_apic_wait_icr_idle(void) 430e2780a68SIngo Molnar { 431e2780a68SIngo Molnar return apic->safe_wait_icr_idle(); 432e2780a68SIngo Molnar } 433e2780a68SIngo Molnar 4341551df64SMichael S. Tsirkin extern void __init apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v)); 4351551df64SMichael S. Tsirkin 436d674cd19SCyrill Gorcunov #else /* CONFIG_X86_LOCAL_APIC */ 437d674cd19SCyrill Gorcunov 438d674cd19SCyrill Gorcunov static inline u32 apic_read(u32 reg) { return 0; } 439d674cd19SCyrill Gorcunov static inline void apic_write(u32 reg, u32 val) { } 4402a43195dSMichael S. Tsirkin static inline void apic_eoi(void) { } 441d674cd19SCyrill Gorcunov static inline u64 apic_icr_read(void) { return 0; } 442d674cd19SCyrill Gorcunov static inline void apic_icr_write(u32 low, u32 high) { } 443d674cd19SCyrill Gorcunov static inline void apic_wait_icr_idle(void) { } 444d674cd19SCyrill Gorcunov static inline u32 safe_apic_wait_icr_idle(void) { return 0; } 4451551df64SMichael S. Tsirkin static inline void apic_set_eoi_write(void (*eoi_write)(u32 reg, u32 v)) {} 446d674cd19SCyrill Gorcunov 447d674cd19SCyrill Gorcunov #endif /* CONFIG_X86_LOCAL_APIC */ 448e2780a68SIngo Molnar 449e2780a68SIngo Molnar static inline void ack_APIC_irq(void) 450e2780a68SIngo Molnar { 451e2780a68SIngo Molnar /* 452e2780a68SIngo Molnar * ack_APIC_irq() actually gets compiled as a single instruction 453e2780a68SIngo Molnar * ... yummie. 454e2780a68SIngo Molnar */ 4552a43195dSMichael S. Tsirkin apic_eoi(); 456e2780a68SIngo Molnar } 457e2780a68SIngo Molnar 458e2780a68SIngo Molnar static inline unsigned default_get_apic_id(unsigned long x) 459e2780a68SIngo Molnar { 460e2780a68SIngo Molnar unsigned int ver = GET_APIC_VERSION(apic_read(APIC_LVR)); 461e2780a68SIngo Molnar 46242937e81SAndreas Herrmann if (APIC_XAPIC(ver) || boot_cpu_has(X86_FEATURE_EXTD_APICID)) 463e2780a68SIngo Molnar return (x >> 24) & 0xFF; 464e2780a68SIngo Molnar else 465e2780a68SIngo Molnar return (x >> 24) & 0x0F; 466e2780a68SIngo Molnar } 467e2780a68SIngo Molnar 468e2780a68SIngo Molnar /* 4696ab1b27cSDavid Rientjes * Warm reset vector position: 470e2780a68SIngo Molnar */ 4716ab1b27cSDavid Rientjes #define TRAMPOLINE_PHYS_LOW 0x467 4726ab1b27cSDavid Rientjes #define TRAMPOLINE_PHYS_HIGH 0x469 473e2780a68SIngo Molnar 4742b6163bfSYinghai Lu #ifdef CONFIG_X86_64 475e2780a68SIngo Molnar extern void apic_send_IPI_self(int vector); 476e2780a68SIngo Molnar 477e2780a68SIngo Molnar DECLARE_PER_CPU(int, x2apic_extra_bits); 478e2780a68SIngo Molnar 479e2780a68SIngo Molnar extern int default_cpu_present_to_apicid(int mps_cpu); 480e11dadabSThomas Gleixner extern int default_check_phys_apicid_present(int phys_apicid); 481e2780a68SIngo Molnar #endif 482e2780a68SIngo Molnar 483838312beSJan Beulich extern void generic_bigsmp_probe(void); 484e2780a68SIngo Molnar 485e2780a68SIngo Molnar 486e2780a68SIngo Molnar #ifdef CONFIG_X86_LOCAL_APIC 487e2780a68SIngo Molnar 488e2780a68SIngo Molnar #include <asm/smp.h> 489e2780a68SIngo Molnar 490e2780a68SIngo Molnar #define APIC_DFR_VALUE (APIC_DFR_FLAT) 491e2780a68SIngo Molnar 492e2780a68SIngo Molnar static inline const struct cpumask *default_target_cpus(void) 493e2780a68SIngo Molnar { 494e2780a68SIngo Molnar #ifdef CONFIG_SMP 495e2780a68SIngo Molnar return cpu_online_mask; 496e2780a68SIngo Molnar #else 497e2780a68SIngo Molnar return cpumask_of(0); 498e2780a68SIngo Molnar #endif 499e2780a68SIngo Molnar } 500e2780a68SIngo Molnar 501bf721d3aSAlexander Gordeev static inline const struct cpumask *online_target_cpus(void) 502bf721d3aSAlexander Gordeev { 503bf721d3aSAlexander Gordeev return cpu_online_mask; 504bf721d3aSAlexander Gordeev } 505bf721d3aSAlexander Gordeev 5060816b0f0SVlad Zolotarov DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_bios_cpu_apicid); 507e2780a68SIngo Molnar 508e2780a68SIngo Molnar 509e2780a68SIngo Molnar static inline unsigned int read_apic_id(void) 510e2780a68SIngo Molnar { 511e2780a68SIngo Molnar unsigned int reg; 512e2780a68SIngo Molnar 513e2780a68SIngo Molnar reg = apic_read(APIC_ID); 514e2780a68SIngo Molnar 515e2780a68SIngo Molnar return apic->get_apic_id(reg); 516e2780a68SIngo Molnar } 517e2780a68SIngo Molnar 518fa63030eSDaniel J Blueman static inline int default_apic_id_valid(int apicid) 519fa63030eSDaniel J Blueman { 520b7157acfSSteffen Persvold return (apicid < 255); 521fa63030eSDaniel J Blueman } 522fa63030eSDaniel J Blueman 523a491cc90SJiang Liu extern int default_acpi_madt_oem_check(char *, char *); 524a491cc90SJiang Liu 525e2780a68SIngo Molnar extern void default_setup_apic_routing(void); 526e2780a68SIngo Molnar 5279844ab11SCyrill Gorcunov extern struct apic apic_noop; 5289844ab11SCyrill Gorcunov 529e2780a68SIngo Molnar #ifdef CONFIG_X86_32 5302c1b284eSJaswinder Singh Rajput 531acb8bc09STejun Heo static inline int noop_x86_32_early_logical_apicid(int cpu) 532acb8bc09STejun Heo { 533acb8bc09STejun Heo return BAD_APICID; 534acb8bc09STejun Heo } 535acb8bc09STejun Heo 536e2780a68SIngo Molnar /* 537e2780a68SIngo Molnar * Set up the logical destination ID. 538e2780a68SIngo Molnar * 539e2780a68SIngo Molnar * Intel recommends to set DFR, LDR and TPR before enabling 540e2780a68SIngo Molnar * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel 541e2780a68SIngo Molnar * document number 292116). So here it goes... 542e2780a68SIngo Molnar */ 543e2780a68SIngo Molnar extern void default_init_apic_ldr(void); 544e2780a68SIngo Molnar 545e2780a68SIngo Molnar static inline int default_apic_id_registered(void) 546e2780a68SIngo Molnar { 547e2780a68SIngo Molnar return physid_isset(read_apic_id(), phys_cpu_present_map); 548e2780a68SIngo Molnar } 549e2780a68SIngo Molnar 550f56e5034SYinghai Lu static inline int default_phys_pkg_id(int cpuid_apic, int index_msb) 551f56e5034SYinghai Lu { 552f56e5034SYinghai Lu return cpuid_apic >> index_msb; 553f56e5034SYinghai Lu } 554f56e5034SYinghai Lu 555f56e5034SYinghai Lu #endif 556f56e5034SYinghai Lu 557ff164324SAlexander Gordeev static inline int 558a5a39156SAlexander Gordeev flat_cpu_mask_to_apicid_and(const struct cpumask *cpumask, 559a5a39156SAlexander Gordeev const struct cpumask *andmask, 560a5a39156SAlexander Gordeev unsigned int *apicid) 561e2780a68SIngo Molnar { 562a5a39156SAlexander Gordeev unsigned long cpu_mask = cpumask_bits(cpumask)[0] & 563a5a39156SAlexander Gordeev cpumask_bits(andmask)[0] & 564a5a39156SAlexander Gordeev cpumask_bits(cpu_online_mask)[0] & 565a5a39156SAlexander Gordeev APIC_ALL_CPUS; 566a5a39156SAlexander Gordeev 567ff164324SAlexander Gordeev if (likely(cpu_mask)) { 568ff164324SAlexander Gordeev *apicid = (unsigned int)cpu_mask; 569ff164324SAlexander Gordeev return 0; 570ff164324SAlexander Gordeev } else { 571ff164324SAlexander Gordeev return -EINVAL; 572ff164324SAlexander Gordeev } 573e2780a68SIngo Molnar } 574e2780a68SIngo Molnar 575ff164324SAlexander Gordeev extern int 5766398268dSAlexander Gordeev default_cpu_mask_to_apicid_and(const struct cpumask *cpumask, 577ff164324SAlexander Gordeev const struct cpumask *andmask, 578ff164324SAlexander Gordeev unsigned int *apicid); 5796398268dSAlexander Gordeev 580b39f25a8SSuresh Siddha static inline void 5811ac322d0SSuresh Siddha flat_vector_allocation_domain(int cpu, struct cpumask *retmask, 5821ac322d0SSuresh Siddha const struct cpumask *mask) 5839d8e1066SAlexander Gordeev { 5849d8e1066SAlexander Gordeev /* Careful. Some cpus do not strictly honor the set of cpus 5859d8e1066SAlexander Gordeev * specified in the interrupt destination when using lowest 5869d8e1066SAlexander Gordeev * priority interrupt delivery mode. 5879d8e1066SAlexander Gordeev * 5889d8e1066SAlexander Gordeev * In particular there was a hyperthreading cpu observed to 5899d8e1066SAlexander Gordeev * deliver interrupts to the wrong hyperthread when only one 5909d8e1066SAlexander Gordeev * hyperthread was specified in the interrupt desitination. 5919d8e1066SAlexander Gordeev */ 5929d8e1066SAlexander Gordeev cpumask_clear(retmask); 5939d8e1066SAlexander Gordeev cpumask_bits(retmask)[0] = APIC_ALL_CPUS; 5949d8e1066SAlexander Gordeev } 5959d8e1066SAlexander Gordeev 596b39f25a8SSuresh Siddha static inline void 5971ac322d0SSuresh Siddha default_vector_allocation_domain(int cpu, struct cpumask *retmask, 5981ac322d0SSuresh Siddha const struct cpumask *mask) 5999d8e1066SAlexander Gordeev { 6009d8e1066SAlexander Gordeev cpumask_copy(retmask, cpumask_of(cpu)); 6019d8e1066SAlexander Gordeev } 6029d8e1066SAlexander Gordeev 6037abc0753SCyrill Gorcunov static inline unsigned long default_check_apicid_used(physid_mask_t *map, int apicid) 604e2780a68SIngo Molnar { 6057abc0753SCyrill Gorcunov return physid_isset(apicid, *map); 606e2780a68SIngo Molnar } 607e2780a68SIngo Molnar 6087abc0753SCyrill Gorcunov static inline void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap) 609e2780a68SIngo Molnar { 6107abc0753SCyrill Gorcunov *retmap = *phys_map; 611e2780a68SIngo Molnar } 612e2780a68SIngo Molnar 613e2780a68SIngo Molnar static inline int __default_cpu_present_to_apicid(int mps_cpu) 614e2780a68SIngo Molnar { 615e2780a68SIngo Molnar if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu)) 616e2780a68SIngo Molnar return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu); 617e2780a68SIngo Molnar else 618e2780a68SIngo Molnar return BAD_APICID; 619e2780a68SIngo Molnar } 620e2780a68SIngo Molnar 621e2780a68SIngo Molnar static inline int 622e11dadabSThomas Gleixner __default_check_phys_apicid_present(int phys_apicid) 623e2780a68SIngo Molnar { 624e11dadabSThomas Gleixner return physid_isset(phys_apicid, phys_cpu_present_map); 625e2780a68SIngo Molnar } 626e2780a68SIngo Molnar 627e2780a68SIngo Molnar #ifdef CONFIG_X86_32 628e2780a68SIngo Molnar static inline int default_cpu_present_to_apicid(int mps_cpu) 629e2780a68SIngo Molnar { 630e2780a68SIngo Molnar return __default_cpu_present_to_apicid(mps_cpu); 631e2780a68SIngo Molnar } 632e2780a68SIngo Molnar 633e2780a68SIngo Molnar static inline int 634e11dadabSThomas Gleixner default_check_phys_apicid_present(int phys_apicid) 635e2780a68SIngo Molnar { 636e11dadabSThomas Gleixner return __default_check_phys_apicid_present(phys_apicid); 637e2780a68SIngo Molnar } 638e2780a68SIngo Molnar #else 639e2780a68SIngo Molnar extern int default_cpu_present_to_apicid(int mps_cpu); 640e11dadabSThomas Gleixner extern int default_check_phys_apicid_present(int phys_apicid); 641e2780a68SIngo Molnar #endif 642e2780a68SIngo Molnar 643e2780a68SIngo Molnar #endif /* CONFIG_X86_LOCAL_APIC */ 644eddc0e92SSeiji Aguchi extern void irq_enter(void); 645eddc0e92SSeiji Aguchi extern void irq_exit(void); 646eddc0e92SSeiji Aguchi 647eddc0e92SSeiji Aguchi static inline void entering_irq(void) 648eddc0e92SSeiji Aguchi { 649eddc0e92SSeiji Aguchi irq_enter(); 650eddc0e92SSeiji Aguchi exit_idle(); 651eddc0e92SSeiji Aguchi } 652eddc0e92SSeiji Aguchi 653eddc0e92SSeiji Aguchi static inline void entering_ack_irq(void) 654eddc0e92SSeiji Aguchi { 655eddc0e92SSeiji Aguchi ack_APIC_irq(); 656eddc0e92SSeiji Aguchi entering_irq(); 657eddc0e92SSeiji Aguchi } 658eddc0e92SSeiji Aguchi 659eddc0e92SSeiji Aguchi static inline void exiting_irq(void) 660eddc0e92SSeiji Aguchi { 661eddc0e92SSeiji Aguchi irq_exit(); 662eddc0e92SSeiji Aguchi } 663eddc0e92SSeiji Aguchi 664eddc0e92SSeiji Aguchi static inline void exiting_ack_irq(void) 665eddc0e92SSeiji Aguchi { 666eddc0e92SSeiji Aguchi irq_exit(); 667eddc0e92SSeiji Aguchi /* Ack only at the end to avoid potential reentry */ 668eddc0e92SSeiji Aguchi ack_APIC_irq(); 669eddc0e92SSeiji Aguchi } 670e2780a68SIngo Molnar 67117405453SYoshihiro YUNOMAE extern void ioapic_zap_locks(void); 67217405453SYoshihiro YUNOMAE 6731965aae3SH. Peter Anvin #endif /* _ASM_X86_APIC_H */ 674