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> 15bb898558SAl Viro 16bb898558SAl Viro #define ARCH_APICTIMER_STOPS_ON_C3 1 17bb898558SAl Viro 18bb898558SAl Viro /* 19bb898558SAl Viro * Debugging macros 20bb898558SAl Viro */ 21bb898558SAl Viro #define APIC_QUIET 0 22bb898558SAl Viro #define APIC_VERBOSE 1 23bb898558SAl Viro #define APIC_DEBUG 2 24bb898558SAl Viro 25bb898558SAl Viro /* 26bb898558SAl Viro * Define the default level of output to be very little 27bb898558SAl Viro * This can be turned up by using apic=verbose for more 28bb898558SAl Viro * information and apic=debug for _lots_ of information. 29bb898558SAl Viro * apic_verbosity is defined in apic.c 30bb898558SAl Viro */ 31bb898558SAl Viro #define apic_printk(v, s, a...) do { \ 32bb898558SAl Viro if ((v) <= apic_verbosity) \ 33bb898558SAl Viro printk(s, ##a); \ 34bb898558SAl Viro } while (0) 35bb898558SAl Viro 36bb898558SAl Viro 37160d8dacSIngo Molnar #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32) 38bb898558SAl Viro extern void generic_apic_probe(void); 39160d8dacSIngo Molnar #else 40160d8dacSIngo Molnar static inline void generic_apic_probe(void) 41160d8dacSIngo Molnar { 42160d8dacSIngo Molnar } 43160d8dacSIngo Molnar #endif 44bb898558SAl Viro 45bb898558SAl Viro #ifdef CONFIG_X86_LOCAL_APIC 46bb898558SAl Viro 47bb898558SAl Viro extern unsigned int apic_verbosity; 48bb898558SAl Viro extern int local_apic_timer_c2_ok; 49bb898558SAl Viro 50bb898558SAl Viro extern int disable_apic; 511ade93efSJacob Pan extern unsigned int lapic_timer_frequency; 520939e4fdSIngo Molnar 530939e4fdSIngo Molnar #ifdef CONFIG_SMP 540939e4fdSIngo Molnar extern void __inquire_remote_apic(int apicid); 550939e4fdSIngo Molnar #else /* CONFIG_SMP */ 560939e4fdSIngo Molnar static inline void __inquire_remote_apic(int apicid) 570939e4fdSIngo Molnar { 580939e4fdSIngo Molnar } 590939e4fdSIngo Molnar #endif /* CONFIG_SMP */ 600939e4fdSIngo Molnar 610939e4fdSIngo Molnar static inline void default_inquire_remote_apic(int apicid) 620939e4fdSIngo Molnar { 630939e4fdSIngo Molnar if (apic_verbosity >= APIC_DEBUG) 640939e4fdSIngo Molnar __inquire_remote_apic(apicid); 650939e4fdSIngo Molnar } 660939e4fdSIngo Molnar 67bb898558SAl Viro /* 688312136fSCyrill Gorcunov * With 82489DX we can't rely on apic feature bit 698312136fSCyrill Gorcunov * retrieved via cpuid but still have to deal with 708312136fSCyrill Gorcunov * such an apic chip so we assume that SMP configuration 718312136fSCyrill Gorcunov * is found from MP table (64bit case uses ACPI mostly 728312136fSCyrill Gorcunov * which set smp presence flag as well so we are safe 738312136fSCyrill Gorcunov * to use this helper too). 748312136fSCyrill Gorcunov */ 758312136fSCyrill Gorcunov static inline bool apic_from_smp_config(void) 768312136fSCyrill Gorcunov { 778312136fSCyrill Gorcunov return smp_found_config && !disable_apic; 788312136fSCyrill Gorcunov } 798312136fSCyrill Gorcunov 808312136fSCyrill Gorcunov /* 81bb898558SAl Viro * Basic functions accessing APICs. 82bb898558SAl Viro */ 83bb898558SAl Viro #ifdef CONFIG_PARAVIRT 84bb898558SAl Viro #include <asm/paravirt.h> 85bb898558SAl Viro #endif 86bb898558SAl Viro 8770511134SRavikiran G Thirumalai #ifdef CONFIG_X86_64 88bb898558SAl Viro extern int is_vsmp_box(void); 89129d8bc8SYinghai Lu #else 90129d8bc8SYinghai Lu static inline int is_vsmp_box(void) 91129d8bc8SYinghai Lu { 92129d8bc8SYinghai Lu return 0; 93129d8bc8SYinghai Lu } 94129d8bc8SYinghai Lu #endif 95bb898558SAl Viro extern void xapic_wait_icr_idle(void); 96bb898558SAl Viro extern u32 safe_xapic_wait_icr_idle(void); 97bb898558SAl Viro extern void xapic_icr_write(u32, u32); 98bb898558SAl Viro extern int setup_profiling_timer(unsigned int); 99bb898558SAl Viro 100bb898558SAl Viro static inline void native_apic_mem_write(u32 reg, u32 v) 101bb898558SAl Viro { 102bb898558SAl Viro volatile u32 *addr = (volatile u32 *)(APIC_BASE + reg); 103bb898558SAl Viro 104bb898558SAl Viro alternative_io("movl %0, %1", "xchgl %0, %1", X86_FEATURE_11AP, 105bb898558SAl Viro ASM_OUTPUT2("=r" (v), "=m" (*addr)), 106bb898558SAl Viro ASM_OUTPUT2("0" (v), "m" (*addr))); 107bb898558SAl Viro } 108bb898558SAl Viro 109bb898558SAl Viro static inline u32 native_apic_mem_read(u32 reg) 110bb898558SAl Viro { 111bb898558SAl Viro return *((volatile u32 *)(APIC_BASE + reg)); 112bb898558SAl Viro } 113bb898558SAl Viro 114c1eeb2deSYinghai Lu extern void native_apic_wait_icr_idle(void); 115c1eeb2deSYinghai Lu extern u32 native_safe_apic_wait_icr_idle(void); 116c1eeb2deSYinghai Lu extern void native_apic_icr_write(u32 low, u32 id); 117c1eeb2deSYinghai Lu extern u64 native_apic_icr_read(void); 118c1eeb2deSYinghai Lu 119fc1edaf9SSuresh Siddha extern int x2apic_mode; 120b24696bcSFenghua Yu 121d0b03bd1SHan, Weidong #ifdef CONFIG_X86_X2APIC 122ce4e240cSSuresh Siddha /* 123ce4e240cSSuresh Siddha * Make previous memory operations globally visible before 124ce4e240cSSuresh Siddha * sending the IPI through x2apic wrmsr. We need a serializing instruction or 125ce4e240cSSuresh Siddha * mfence for this. 126ce4e240cSSuresh Siddha */ 127ce4e240cSSuresh Siddha static inline void x2apic_wrmsr_fence(void) 128ce4e240cSSuresh Siddha { 129ce4e240cSSuresh Siddha asm volatile("mfence" : : : "memory"); 130ce4e240cSSuresh Siddha } 131ce4e240cSSuresh Siddha 132bb898558SAl Viro static inline void native_apic_msr_write(u32 reg, u32 v) 133bb898558SAl Viro { 134bb898558SAl Viro if (reg == APIC_DFR || reg == APIC_ID || reg == APIC_LDR || 135bb898558SAl Viro reg == APIC_LVR) 136bb898558SAl Viro return; 137bb898558SAl Viro 138bb898558SAl Viro wrmsr(APIC_BASE_MSR + (reg >> 4), v, 0); 139bb898558SAl Viro } 140bb898558SAl Viro 1410ab711aeSMichael S. Tsirkin static inline void native_apic_msr_eoi_write(u32 reg, u32 v) 1420ab711aeSMichael S. Tsirkin { 1430ab711aeSMichael S. Tsirkin wrmsr(APIC_BASE_MSR + (APIC_EOI >> 4), APIC_EOI_ACK, 0); 1440ab711aeSMichael S. Tsirkin } 1450ab711aeSMichael S. Tsirkin 146bb898558SAl Viro static inline u32 native_apic_msr_read(u32 reg) 147bb898558SAl Viro { 1480059b243SAndi Kleen u64 msr; 149bb898558SAl Viro 150bb898558SAl Viro if (reg == APIC_DFR) 151bb898558SAl Viro return -1; 152bb898558SAl Viro 1530059b243SAndi Kleen rdmsrl(APIC_BASE_MSR + (reg >> 4), msr); 1540059b243SAndi Kleen return (u32)msr; 155bb898558SAl Viro } 156bb898558SAl Viro 157c1eeb2deSYinghai Lu static inline void native_x2apic_wait_icr_idle(void) 158c1eeb2deSYinghai Lu { 159c1eeb2deSYinghai Lu /* no need to wait for icr idle in x2apic */ 160c1eeb2deSYinghai Lu return; 161c1eeb2deSYinghai Lu } 162c1eeb2deSYinghai Lu 163c1eeb2deSYinghai Lu static inline u32 native_safe_x2apic_wait_icr_idle(void) 164c1eeb2deSYinghai Lu { 165c1eeb2deSYinghai Lu /* no need to wait for icr idle in x2apic */ 166c1eeb2deSYinghai Lu return 0; 167c1eeb2deSYinghai Lu } 168c1eeb2deSYinghai Lu 169c1eeb2deSYinghai Lu static inline void native_x2apic_icr_write(u32 low, u32 id) 170c1eeb2deSYinghai Lu { 171c1eeb2deSYinghai Lu wrmsrl(APIC_BASE_MSR + (APIC_ICR >> 4), ((__u64) id) << 32 | low); 172c1eeb2deSYinghai Lu } 173c1eeb2deSYinghai Lu 174c1eeb2deSYinghai Lu static inline u64 native_x2apic_icr_read(void) 175c1eeb2deSYinghai Lu { 176c1eeb2deSYinghai Lu unsigned long val; 177c1eeb2deSYinghai Lu 178c1eeb2deSYinghai Lu rdmsrl(APIC_BASE_MSR + (APIC_ICR >> 4), val); 179c1eeb2deSYinghai Lu return val; 180c1eeb2deSYinghai Lu } 181c1eeb2deSYinghai Lu 182fc1edaf9SSuresh Siddha extern int x2apic_phys; 183fb209bd8SYinghai Lu extern int x2apic_preenabled; 184bb898558SAl Viro extern void check_x2apic(void); 185bb898558SAl Viro extern void enable_x2apic(void); 186bb898558SAl Viro extern void x2apic_icr_write(u32 low, u32 id); 187bb898558SAl Viro static inline int x2apic_enabled(void) 188bb898558SAl Viro { 1890059b243SAndi Kleen u64 msr; 190bb898558SAl Viro 191bb898558SAl Viro if (!cpu_has_x2apic) 192bb898558SAl Viro return 0; 193bb898558SAl Viro 1940059b243SAndi Kleen rdmsrl(MSR_IA32_APICBASE, msr); 195bb898558SAl Viro if (msr & X2APIC_ENABLE) 196bb898558SAl Viro return 1; 197bb898558SAl Viro return 0; 198bb898558SAl Viro } 199fc1edaf9SSuresh Siddha 200fc1edaf9SSuresh Siddha #define x2apic_supported() (cpu_has_x2apic) 201ce69a784SGleb Natapov static inline void x2apic_force_phys(void) 202ce69a784SGleb Natapov { 203ce69a784SGleb Natapov x2apic_phys = 1; 204ce69a784SGleb Natapov } 205bb898558SAl Viro #else 206fb209bd8SYinghai Lu static inline void disable_x2apic(void) 207fb209bd8SYinghai Lu { 208fb209bd8SYinghai Lu } 20906cd9a7dSYinghai Lu static inline void check_x2apic(void) 21006cd9a7dSYinghai Lu { 21106cd9a7dSYinghai Lu } 21206cd9a7dSYinghai Lu static inline void enable_x2apic(void) 21306cd9a7dSYinghai Lu { 21406cd9a7dSYinghai Lu } 21506cd9a7dSYinghai Lu static inline int x2apic_enabled(void) 21606cd9a7dSYinghai Lu { 21706cd9a7dSYinghai Lu return 0; 21806cd9a7dSYinghai Lu } 219ce69a784SGleb Natapov static inline void x2apic_force_phys(void) 220ce69a784SGleb Natapov { 221ce69a784SGleb Natapov } 222cf6567feSSuresh Siddha 223a31bc327SYinghai Lu #define nox2apic 0 22493758238SWeidong Han #define x2apic_preenabled 0 225fc1edaf9SSuresh Siddha #define x2apic_supported() 0 226bb898558SAl Viro #endif 227bb898558SAl Viro 22893758238SWeidong Han extern void enable_IR_x2apic(void); 22993758238SWeidong Han 230bb898558SAl Viro extern int get_physical_broadcast(void); 231bb898558SAl Viro 232bb898558SAl Viro extern int lapic_get_maxlvt(void); 233bb898558SAl Viro extern void clear_local_APIC(void); 234bb898558SAl Viro extern void connect_bsp_APIC(void); 235bb898558SAl Viro extern void disconnect_bsp_APIC(int virt_wire_setup); 236bb898558SAl Viro extern void disable_local_APIC(void); 237bb898558SAl Viro extern void lapic_shutdown(void); 238bb898558SAl Viro extern int verify_local_APIC(void); 239bb898558SAl Viro extern void sync_Arb_IDs(void); 240bb898558SAl Viro extern void init_bsp_APIC(void); 241bb898558SAl Viro extern void setup_local_APIC(void); 242bb898558SAl Viro extern void end_local_APIC_setup(void); 2432fb270f3SJan Beulich extern void bsp_end_local_APIC_setup(void); 244bb898558SAl Viro extern void init_apic_mappings(void); 245c0104d38SYinghai Lu void register_lapic_address(unsigned long address); 246bb898558SAl Viro extern void setup_boot_APIC_clock(void); 247bb898558SAl Viro extern void setup_secondary_APIC_clock(void); 248bb898558SAl Viro extern int APIC_init_uniprocessor(void); 249a906fdaaSThomas Gleixner extern int apic_force_enable(unsigned long addr); 250bb898558SAl Viro 251bb898558SAl Viro /* 252bb898558SAl Viro * On 32bit this is mach-xxx local 253bb898558SAl Viro */ 254bb898558SAl Viro #ifdef CONFIG_X86_64 255bb898558SAl Viro extern int apic_is_clustered_box(void); 256bb898558SAl Viro #else 257bb898558SAl Viro static inline int apic_is_clustered_box(void) 258bb898558SAl Viro { 259bb898558SAl Viro return 0; 260bb898558SAl Viro } 261bb898558SAl Viro #endif 262bb898558SAl Viro 26327afdf20SRobert Richter extern int setup_APIC_eilvt(u8 lvt_off, u8 vector, u8 msg_type, u8 mask); 264bb898558SAl Viro 265bb898558SAl Viro #else /* !CONFIG_X86_LOCAL_APIC */ 266bb898558SAl Viro static inline void lapic_shutdown(void) { } 267bb898558SAl Viro #define local_apic_timer_c2_ok 1 268bb898558SAl Viro static inline void init_apic_mappings(void) { } 269d3ec5caeSIvan Vecera static inline void disable_local_APIC(void) { } 270736decacSThomas Gleixner # define setup_boot_APIC_clock x86_init_noop 271736decacSThomas Gleixner # define setup_secondary_APIC_clock x86_init_noop 272bb898558SAl Viro #endif /* !CONFIG_X86_LOCAL_APIC */ 273bb898558SAl Viro 2741f75ed0cSIngo Molnar #ifdef CONFIG_X86_64 2751f75ed0cSIngo Molnar #define SET_APIC_ID(x) (apic->set_apic_id(x)) 2761f75ed0cSIngo Molnar #else 2771f75ed0cSIngo Molnar 2781f75ed0cSIngo Molnar #endif 2791f75ed0cSIngo Molnar 280e2780a68SIngo Molnar /* 281e2780a68SIngo Molnar * Copyright 2004 James Cleverdon, IBM. 282e2780a68SIngo Molnar * Subject to the GNU Public License, v.2 283e2780a68SIngo Molnar * 284e2780a68SIngo Molnar * Generic APIC sub-arch data struct. 285e2780a68SIngo Molnar * 286e2780a68SIngo Molnar * Hacked for x86-64 by James Cleverdon from i386 architecture code by 287e2780a68SIngo Molnar * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and 288e2780a68SIngo Molnar * James Cleverdon. 289e2780a68SIngo Molnar */ 290be163a15SIngo Molnar struct apic { 291e2780a68SIngo Molnar char *name; 292e2780a68SIngo Molnar 293e2780a68SIngo Molnar int (*probe)(void); 294e2780a68SIngo Molnar int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id); 295fa63030eSDaniel J Blueman int (*apic_id_valid)(int apicid); 296e2780a68SIngo Molnar int (*apic_id_registered)(void); 297e2780a68SIngo Molnar 298e2780a68SIngo Molnar u32 irq_delivery_mode; 299e2780a68SIngo Molnar u32 irq_dest_mode; 300e2780a68SIngo Molnar 301e2780a68SIngo Molnar const struct cpumask *(*target_cpus)(void); 302e2780a68SIngo Molnar 303e2780a68SIngo Molnar int disable_esr; 304e2780a68SIngo Molnar 305e2780a68SIngo Molnar int dest_logical; 3067abc0753SCyrill Gorcunov unsigned long (*check_apicid_used)(physid_mask_t *map, int apicid); 307e2780a68SIngo Molnar unsigned long (*check_apicid_present)(int apicid); 308e2780a68SIngo Molnar 309e2780a68SIngo Molnar void (*vector_allocation_domain)(int cpu, struct cpumask *retmask); 310e2780a68SIngo Molnar void (*init_apic_ldr)(void); 311e2780a68SIngo Molnar 3127abc0753SCyrill Gorcunov void (*ioapic_phys_id_map)(physid_mask_t *phys_map, physid_mask_t *retmap); 313e2780a68SIngo Molnar 314e2780a68SIngo Molnar void (*setup_apic_routing)(void); 315e2780a68SIngo Molnar int (*multi_timer_check)(int apic, int irq); 316e2780a68SIngo Molnar int (*cpu_present_to_apicid)(int mps_cpu); 3177abc0753SCyrill Gorcunov void (*apicid_to_cpu_present)(int phys_apicid, physid_mask_t *retmap); 318e2780a68SIngo Molnar void (*setup_portio_remap)(void); 319e11dadabSThomas Gleixner int (*check_phys_apicid_present)(int phys_apicid); 320e2780a68SIngo Molnar void (*enable_apic_mode)(void); 321e2780a68SIngo Molnar int (*phys_pkg_id)(int cpuid_apic, int index_msb); 322e2780a68SIngo Molnar 323e2780a68SIngo Molnar /* 324be163a15SIngo Molnar * When one of the next two hooks returns 1 the apic 325e2780a68SIngo Molnar * is switched to this. Essentially they are additional 326e2780a68SIngo Molnar * probe functions: 327e2780a68SIngo Molnar */ 328e2780a68SIngo Molnar int (*mps_oem_check)(struct mpc_table *mpc, char *oem, char *productid); 329e2780a68SIngo Molnar 330e2780a68SIngo Molnar unsigned int (*get_apic_id)(unsigned long x); 331e2780a68SIngo Molnar unsigned long (*set_apic_id)(unsigned int id); 332e2780a68SIngo Molnar unsigned long apic_id_mask; 333e2780a68SIngo Molnar 334e2780a68SIngo Molnar unsigned int (*cpu_mask_to_apicid)(const struct cpumask *cpumask); 335e2780a68SIngo Molnar unsigned int (*cpu_mask_to_apicid_and)(const struct cpumask *cpumask, 336e2780a68SIngo Molnar const struct cpumask *andmask); 337e2780a68SIngo Molnar 338e2780a68SIngo Molnar /* ipi */ 339e2780a68SIngo Molnar void (*send_IPI_mask)(const struct cpumask *mask, int vector); 340e2780a68SIngo Molnar void (*send_IPI_mask_allbutself)(const struct cpumask *mask, 341e2780a68SIngo Molnar int vector); 342e2780a68SIngo Molnar void (*send_IPI_allbutself)(int vector); 343e2780a68SIngo Molnar void (*send_IPI_all)(int vector); 344e2780a68SIngo Molnar void (*send_IPI_self)(int vector); 345e2780a68SIngo Molnar 346e2780a68SIngo Molnar /* wakeup_secondary_cpu */ 3471f5bcabfSIngo Molnar int (*wakeup_secondary_cpu)(int apicid, unsigned long start_eip); 348e2780a68SIngo Molnar 349e2780a68SIngo Molnar int trampoline_phys_low; 350e2780a68SIngo Molnar int trampoline_phys_high; 351e2780a68SIngo Molnar 352e2780a68SIngo Molnar void (*wait_for_init_deassert)(atomic_t *deassert); 353e2780a68SIngo Molnar void (*smp_callin_clear_local_apic)(void); 354e2780a68SIngo Molnar void (*inquire_remote_apic)(int apicid); 355e2780a68SIngo Molnar 356e2780a68SIngo Molnar /* apic ops */ 357e2780a68SIngo Molnar u32 (*read)(u32 reg); 358e2780a68SIngo Molnar void (*write)(u32 reg, u32 v); 3592a43195dSMichael S. Tsirkin /* 3602a43195dSMichael S. Tsirkin * ->eoi_write() has the same signature as ->write(). 3612a43195dSMichael S. Tsirkin * 3622a43195dSMichael S. Tsirkin * Drivers can support both ->eoi_write() and ->write() by passing the same 3632a43195dSMichael S. Tsirkin * callback value. Kernel can override ->eoi_write() and fall back 3642a43195dSMichael S. Tsirkin * on write for EOI. 3652a43195dSMichael S. Tsirkin */ 3662a43195dSMichael S. Tsirkin void (*eoi_write)(u32 reg, u32 v); 367e2780a68SIngo Molnar u64 (*icr_read)(void); 368e2780a68SIngo Molnar void (*icr_write)(u32 low, u32 high); 369e2780a68SIngo Molnar void (*wait_icr_idle)(void); 370e2780a68SIngo Molnar u32 (*safe_wait_icr_idle)(void); 371acb8bc09STejun Heo 372acb8bc09STejun Heo #ifdef CONFIG_X86_32 373acb8bc09STejun Heo /* 374acb8bc09STejun Heo * Called very early during boot from get_smp_config(). It should 375acb8bc09STejun Heo * return the logical apicid. x86_[bios]_cpu_to_apicid is 376acb8bc09STejun Heo * initialized before this function is called. 377acb8bc09STejun Heo * 378acb8bc09STejun Heo * If logical apicid can't be determined that early, the function 379acb8bc09STejun Heo * may return BAD_APICID. Logical apicid will be configured after 380acb8bc09STejun Heo * init_apic_ldr() while bringing up CPUs. Note that NUMA affinity 381acb8bc09STejun Heo * won't be applied properly during early boot in this case. 382acb8bc09STejun Heo */ 383acb8bc09STejun Heo int (*x86_32_early_logical_apicid)(int cpu); 38489e5dc21STejun Heo 38584914ed0STejun Heo /* 38684914ed0STejun Heo * Optional method called from setup_local_APIC() after logical 38784914ed0STejun Heo * apicid is guaranteed to be known to initialize apicid -> node 38884914ed0STejun Heo * mapping if NUMA initialization hasn't done so already. Don't 38984914ed0STejun Heo * add new users. 39084914ed0STejun Heo */ 39189e5dc21STejun Heo int (*x86_32_numa_cpu_node)(int cpu); 392acb8bc09STejun Heo #endif 393e2780a68SIngo Molnar }; 394e2780a68SIngo Molnar 3950917c01fSIngo Molnar /* 3960917c01fSIngo Molnar * Pointer to the local APIC driver in use on this system (there's 3970917c01fSIngo Molnar * always just one such driver in use - the kernel decides via an 3980917c01fSIngo Molnar * early probing process which one it picks - and then sticks to it): 3990917c01fSIngo Molnar */ 400be163a15SIngo Molnar extern struct apic *apic; 4010917c01fSIngo Molnar 4020917c01fSIngo Molnar /* 403107e0e0cSSuresh Siddha * APIC drivers are probed based on how they are listed in the .apicdrivers 404107e0e0cSSuresh Siddha * section. So the order is important and enforced by the ordering 405107e0e0cSSuresh Siddha * of different apic driver files in the Makefile. 406107e0e0cSSuresh Siddha * 407107e0e0cSSuresh Siddha * For the files having two apic drivers, we use apic_drivers() 408107e0e0cSSuresh Siddha * to enforce the order with in them. 409107e0e0cSSuresh Siddha */ 410107e0e0cSSuresh Siddha #define apic_driver(sym) \ 411107e0e0cSSuresh Siddha static struct apic *__apicdrivers_##sym __used \ 412107e0e0cSSuresh Siddha __aligned(sizeof(struct apic *)) \ 413107e0e0cSSuresh Siddha __section(.apicdrivers) = { &sym } 414107e0e0cSSuresh Siddha 415107e0e0cSSuresh Siddha #define apic_drivers(sym1, sym2) \ 416107e0e0cSSuresh Siddha static struct apic *__apicdrivers_##sym1##sym2[2] __used \ 417107e0e0cSSuresh Siddha __aligned(sizeof(struct apic *)) \ 418107e0e0cSSuresh Siddha __section(.apicdrivers) = { &sym1, &sym2 } 419107e0e0cSSuresh Siddha 420107e0e0cSSuresh Siddha extern struct apic *__apicdrivers[], *__apicdrivers_end[]; 421107e0e0cSSuresh Siddha 422107e0e0cSSuresh Siddha /* 4230917c01fSIngo Molnar * APIC functionality to boot other CPUs - only used on SMP: 4240917c01fSIngo Molnar */ 4250917c01fSIngo Molnar #ifdef CONFIG_SMP 4262b6163bfSYinghai Lu extern atomic_t init_deasserted; 4272b6163bfSYinghai Lu extern int wakeup_secondary_cpu_via_nmi(int apicid, unsigned long start_eip); 4280917c01fSIngo Molnar #endif 429e2780a68SIngo Molnar 430d674cd19SCyrill Gorcunov #ifdef CONFIG_X86_LOCAL_APIC 431346b46beSFernando Luis Vázquez Cao 432e2780a68SIngo Molnar static inline u32 apic_read(u32 reg) 433e2780a68SIngo Molnar { 434e2780a68SIngo Molnar return apic->read(reg); 435e2780a68SIngo Molnar } 436e2780a68SIngo Molnar 437e2780a68SIngo Molnar static inline void apic_write(u32 reg, u32 val) 438e2780a68SIngo Molnar { 439e2780a68SIngo Molnar apic->write(reg, val); 440e2780a68SIngo Molnar } 441e2780a68SIngo Molnar 4422a43195dSMichael S. Tsirkin static inline void apic_eoi(void) 4432a43195dSMichael S. Tsirkin { 4442a43195dSMichael S. Tsirkin apic->eoi_write(APIC_EOI, APIC_EOI_ACK); 4452a43195dSMichael S. Tsirkin } 4462a43195dSMichael S. Tsirkin 447e2780a68SIngo Molnar static inline u64 apic_icr_read(void) 448e2780a68SIngo Molnar { 449e2780a68SIngo Molnar return apic->icr_read(); 450e2780a68SIngo Molnar } 451e2780a68SIngo Molnar 452e2780a68SIngo Molnar static inline void apic_icr_write(u32 low, u32 high) 453e2780a68SIngo Molnar { 454e2780a68SIngo Molnar apic->icr_write(low, high); 455e2780a68SIngo Molnar } 456e2780a68SIngo Molnar 457e2780a68SIngo Molnar static inline void apic_wait_icr_idle(void) 458e2780a68SIngo Molnar { 459e2780a68SIngo Molnar apic->wait_icr_idle(); 460e2780a68SIngo Molnar } 461e2780a68SIngo Molnar 462e2780a68SIngo Molnar static inline u32 safe_apic_wait_icr_idle(void) 463e2780a68SIngo Molnar { 464e2780a68SIngo Molnar return apic->safe_wait_icr_idle(); 465e2780a68SIngo Molnar } 466e2780a68SIngo Molnar 467d674cd19SCyrill Gorcunov #else /* CONFIG_X86_LOCAL_APIC */ 468d674cd19SCyrill Gorcunov 469d674cd19SCyrill Gorcunov static inline u32 apic_read(u32 reg) { return 0; } 470d674cd19SCyrill Gorcunov static inline void apic_write(u32 reg, u32 val) { } 4712a43195dSMichael S. Tsirkin static inline void apic_eoi(void) { } 472d674cd19SCyrill Gorcunov static inline u64 apic_icr_read(void) { return 0; } 473d674cd19SCyrill Gorcunov static inline void apic_icr_write(u32 low, u32 high) { } 474d674cd19SCyrill Gorcunov static inline void apic_wait_icr_idle(void) { } 475d674cd19SCyrill Gorcunov static inline u32 safe_apic_wait_icr_idle(void) { return 0; } 476d674cd19SCyrill Gorcunov 477d674cd19SCyrill Gorcunov #endif /* CONFIG_X86_LOCAL_APIC */ 478e2780a68SIngo Molnar 479e2780a68SIngo Molnar static inline void ack_APIC_irq(void) 480e2780a68SIngo Molnar { 481e2780a68SIngo Molnar /* 482e2780a68SIngo Molnar * ack_APIC_irq() actually gets compiled as a single instruction 483e2780a68SIngo Molnar * ... yummie. 484e2780a68SIngo Molnar */ 4852a43195dSMichael S. Tsirkin apic_eoi(); 486e2780a68SIngo Molnar } 487e2780a68SIngo Molnar 488e2780a68SIngo Molnar static inline unsigned default_get_apic_id(unsigned long x) 489e2780a68SIngo Molnar { 490e2780a68SIngo Molnar unsigned int ver = GET_APIC_VERSION(apic_read(APIC_LVR)); 491e2780a68SIngo Molnar 49242937e81SAndreas Herrmann if (APIC_XAPIC(ver) || boot_cpu_has(X86_FEATURE_EXTD_APICID)) 493e2780a68SIngo Molnar return (x >> 24) & 0xFF; 494e2780a68SIngo Molnar else 495e2780a68SIngo Molnar return (x >> 24) & 0x0F; 496e2780a68SIngo Molnar } 497e2780a68SIngo Molnar 498e2780a68SIngo Molnar /* 499e2780a68SIngo Molnar * Warm reset vector default position: 500e2780a68SIngo Molnar */ 501e2780a68SIngo Molnar #define DEFAULT_TRAMPOLINE_PHYS_LOW 0x467 502e2780a68SIngo Molnar #define DEFAULT_TRAMPOLINE_PHYS_HIGH 0x469 503e2780a68SIngo Molnar 5042b6163bfSYinghai Lu #ifdef CONFIG_X86_64 505e2780a68SIngo Molnar extern int default_acpi_madt_oem_check(char *, char *); 506e2780a68SIngo Molnar 507e2780a68SIngo Molnar extern void apic_send_IPI_self(int vector); 508e2780a68SIngo Molnar 509e2780a68SIngo Molnar DECLARE_PER_CPU(int, x2apic_extra_bits); 510e2780a68SIngo Molnar 511e2780a68SIngo Molnar extern int default_cpu_present_to_apicid(int mps_cpu); 512e11dadabSThomas Gleixner extern int default_check_phys_apicid_present(int phys_apicid); 513e2780a68SIngo Molnar #endif 514e2780a68SIngo Molnar 515e2780a68SIngo Molnar static inline void default_wait_for_init_deassert(atomic_t *deassert) 516e2780a68SIngo Molnar { 517e2780a68SIngo Molnar while (!atomic_read(deassert)) 518e2780a68SIngo Molnar cpu_relax(); 519e2780a68SIngo Molnar return; 520e2780a68SIngo Molnar } 521e2780a68SIngo Molnar 522838312beSJan Beulich extern void generic_bigsmp_probe(void); 523e2780a68SIngo Molnar 524e2780a68SIngo Molnar 525e2780a68SIngo Molnar #ifdef CONFIG_X86_LOCAL_APIC 526e2780a68SIngo Molnar 527e2780a68SIngo Molnar #include <asm/smp.h> 528e2780a68SIngo Molnar 529e2780a68SIngo Molnar #define APIC_DFR_VALUE (APIC_DFR_FLAT) 530e2780a68SIngo Molnar 531e2780a68SIngo Molnar static inline const struct cpumask *default_target_cpus(void) 532e2780a68SIngo Molnar { 533e2780a68SIngo Molnar #ifdef CONFIG_SMP 534e2780a68SIngo Molnar return cpu_online_mask; 535e2780a68SIngo Molnar #else 536e2780a68SIngo Molnar return cpumask_of(0); 537e2780a68SIngo Molnar #endif 538e2780a68SIngo Molnar } 539e2780a68SIngo Molnar 540e2780a68SIngo Molnar DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid); 541e2780a68SIngo Molnar 542e2780a68SIngo Molnar 543e2780a68SIngo Molnar static inline unsigned int read_apic_id(void) 544e2780a68SIngo Molnar { 545e2780a68SIngo Molnar unsigned int reg; 546e2780a68SIngo Molnar 547e2780a68SIngo Molnar reg = apic_read(APIC_ID); 548e2780a68SIngo Molnar 549e2780a68SIngo Molnar return apic->get_apic_id(reg); 550e2780a68SIngo Molnar } 551e2780a68SIngo Molnar 552fa63030eSDaniel J Blueman static inline int default_apic_id_valid(int apicid) 553fa63030eSDaniel J Blueman { 554b7157acfSSteffen Persvold return (apicid < 255); 555fa63030eSDaniel J Blueman } 556fa63030eSDaniel J Blueman 557e2780a68SIngo Molnar extern void default_setup_apic_routing(void); 558e2780a68SIngo Molnar 5599844ab11SCyrill Gorcunov extern struct apic apic_noop; 5609844ab11SCyrill Gorcunov 561e2780a68SIngo Molnar #ifdef CONFIG_X86_32 5622c1b284eSJaswinder Singh Rajput 563acb8bc09STejun Heo static inline int noop_x86_32_early_logical_apicid(int cpu) 564acb8bc09STejun Heo { 565acb8bc09STejun Heo return BAD_APICID; 566acb8bc09STejun Heo } 567acb8bc09STejun Heo 568e2780a68SIngo Molnar /* 569e2780a68SIngo Molnar * Set up the logical destination ID. 570e2780a68SIngo Molnar * 571e2780a68SIngo Molnar * Intel recommends to set DFR, LDR and TPR before enabling 572e2780a68SIngo Molnar * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel 573e2780a68SIngo Molnar * document number 292116). So here it goes... 574e2780a68SIngo Molnar */ 575e2780a68SIngo Molnar extern void default_init_apic_ldr(void); 576e2780a68SIngo Molnar 577e2780a68SIngo Molnar static inline int default_apic_id_registered(void) 578e2780a68SIngo Molnar { 579e2780a68SIngo Molnar return physid_isset(read_apic_id(), phys_cpu_present_map); 580e2780a68SIngo Molnar } 581e2780a68SIngo Molnar 582f56e5034SYinghai Lu static inline int default_phys_pkg_id(int cpuid_apic, int index_msb) 583f56e5034SYinghai Lu { 584f56e5034SYinghai Lu return cpuid_apic >> index_msb; 585f56e5034SYinghai Lu } 586f56e5034SYinghai Lu 587f56e5034SYinghai Lu #endif 588f56e5034SYinghai Lu 589e2780a68SIngo Molnar static inline unsigned int 590e2780a68SIngo Molnar default_cpu_mask_to_apicid(const struct cpumask *cpumask) 591e2780a68SIngo Molnar { 592f56e5034SYinghai Lu return cpumask_bits(cpumask)[0] & APIC_ALL_CPUS; 593e2780a68SIngo Molnar } 594e2780a68SIngo Molnar 595e2780a68SIngo Molnar static inline unsigned int 596e2780a68SIngo Molnar default_cpu_mask_to_apicid_and(const struct cpumask *cpumask, 597e2780a68SIngo Molnar const struct cpumask *andmask) 598e2780a68SIngo Molnar { 599e2780a68SIngo Molnar unsigned long mask1 = cpumask_bits(cpumask)[0]; 600e2780a68SIngo Molnar unsigned long mask2 = cpumask_bits(andmask)[0]; 601e2780a68SIngo Molnar unsigned long mask3 = cpumask_bits(cpu_online_mask)[0]; 602e2780a68SIngo Molnar 603e2780a68SIngo Molnar return (unsigned int)(mask1 & mask2 & mask3); 604e2780a68SIngo Molnar } 605e2780a68SIngo Molnar 6067abc0753SCyrill Gorcunov static inline unsigned long default_check_apicid_used(physid_mask_t *map, int apicid) 607e2780a68SIngo Molnar { 6087abc0753SCyrill Gorcunov return physid_isset(apicid, *map); 609e2780a68SIngo Molnar } 610e2780a68SIngo Molnar 611e2780a68SIngo Molnar static inline unsigned long default_check_apicid_present(int bit) 612e2780a68SIngo Molnar { 613e2780a68SIngo Molnar return physid_isset(bit, phys_cpu_present_map); 614e2780a68SIngo Molnar } 615e2780a68SIngo Molnar 6167abc0753SCyrill Gorcunov static inline void default_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap) 617e2780a68SIngo Molnar { 6187abc0753SCyrill Gorcunov *retmap = *phys_map; 619e2780a68SIngo Molnar } 620e2780a68SIngo Molnar 621e2780a68SIngo Molnar static inline int __default_cpu_present_to_apicid(int mps_cpu) 622e2780a68SIngo Molnar { 623e2780a68SIngo Molnar if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu)) 624e2780a68SIngo Molnar return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu); 625e2780a68SIngo Molnar else 626e2780a68SIngo Molnar return BAD_APICID; 627e2780a68SIngo Molnar } 628e2780a68SIngo Molnar 629e2780a68SIngo Molnar static inline int 630e11dadabSThomas Gleixner __default_check_phys_apicid_present(int phys_apicid) 631e2780a68SIngo Molnar { 632e11dadabSThomas Gleixner return physid_isset(phys_apicid, phys_cpu_present_map); 633e2780a68SIngo Molnar } 634e2780a68SIngo Molnar 635e2780a68SIngo Molnar #ifdef CONFIG_X86_32 636e2780a68SIngo Molnar static inline int default_cpu_present_to_apicid(int mps_cpu) 637e2780a68SIngo Molnar { 638e2780a68SIngo Molnar return __default_cpu_present_to_apicid(mps_cpu); 639e2780a68SIngo Molnar } 640e2780a68SIngo Molnar 641e2780a68SIngo Molnar static inline int 642e11dadabSThomas Gleixner default_check_phys_apicid_present(int phys_apicid) 643e2780a68SIngo Molnar { 644e11dadabSThomas Gleixner return __default_check_phys_apicid_present(phys_apicid); 645e2780a68SIngo Molnar } 646e2780a68SIngo Molnar #else 647e2780a68SIngo Molnar extern int default_cpu_present_to_apicid(int mps_cpu); 648e11dadabSThomas Gleixner extern int default_check_phys_apicid_present(int phys_apicid); 649e2780a68SIngo Molnar #endif 650e2780a68SIngo Molnar 651e2780a68SIngo Molnar #endif /* CONFIG_X86_LOCAL_APIC */ 652e2780a68SIngo Molnar 6531965aae3SH. Peter Anvin #endif /* _ASM_X86_APIC_H */ 654