]> bbs.cooldavid.org Git - net-next-2.6.git/blame - arch/x86/include/asm/apic.h
x86, apic: Fix missed handling of discrete apics
[net-next-2.6.git] / arch / x86 / include / asm / apic.h
CommitLineData
1965aae3
PA
1#ifndef _ASM_X86_APIC_H
2#define _ASM_X86_APIC_H
67c5fc5c 3
e2780a68 4#include <linux/cpumask.h>
67c5fc5c 5#include <linux/delay.h>
e2780a68 6#include <linux/pm.h>
593f4a78
MR
7
8#include <asm/alternative.h>
e2780a68 9#include <asm/cpufeature.h>
67c5fc5c 10#include <asm/processor.h>
e2780a68
IM
11#include <asm/apicdef.h>
12#include <asm/atomic.h>
13#include <asm/fixmap.h>
14#include <asm/mpspec.h>
67c5fc5c 15#include <asm/system.h>
13c88fb5 16#include <asm/msr.h>
67c5fc5c
TG
17
18#define ARCH_APICTIMER_STOPS_ON_C3 1
19
67c5fc5c
TG
20/*
21 * Debugging macros
22 */
23#define APIC_QUIET 0
24#define APIC_VERBOSE 1
25#define APIC_DEBUG 2
26
27/*
28 * Define the default level of output to be very little
29 * This can be turned up by using apic=verbose for more
30 * information and apic=debug for _lots_ of information.
31 * apic_verbosity is defined in apic.c
32 */
33#define apic_printk(v, s, a...) do { \
34 if ((v) <= apic_verbosity) \
35 printk(s, ##a); \
36 } while (0)
37
38
160d8dac 39#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
67c5fc5c 40extern void generic_apic_probe(void);
160d8dac
IM
41#else
42static inline void generic_apic_probe(void)
43{
44}
45#endif
67c5fc5c
TG
46
47#ifdef CONFIG_X86_LOCAL_APIC
48
baa13188 49extern unsigned int apic_verbosity;
67c5fc5c 50extern int local_apic_timer_c2_ok;
67c5fc5c 51
3c999f14 52extern int disable_apic;
0939e4fd
IM
53
54#ifdef CONFIG_SMP
55extern void __inquire_remote_apic(int apicid);
56#else /* CONFIG_SMP */
57static inline void __inquire_remote_apic(int apicid)
58{
59}
60#endif /* CONFIG_SMP */
61
62static inline void default_inquire_remote_apic(int apicid)
63{
64 if (apic_verbosity >= APIC_DEBUG)
65 __inquire_remote_apic(apicid);
66}
67
8312136f
CG
68/*
69 * With 82489DX we can't rely on apic feature bit
70 * retrieved via cpuid but still have to deal with
71 * such an apic chip so we assume that SMP configuration
72 * is found from MP table (64bit case uses ACPI mostly
73 * which set smp presence flag as well so we are safe
74 * to use this helper too).
75 */
76static inline bool apic_from_smp_config(void)
77{
78 return smp_found_config && !disable_apic;
79}
80
67c5fc5c
TG
81/*
82 * Basic functions accessing APICs.
83 */
84#ifdef CONFIG_PARAVIRT
85#include <asm/paravirt.h>
96a388de 86#else
67c5fc5c
TG
87#define setup_boot_clock setup_boot_APIC_clock
88#define setup_secondary_clock setup_secondary_APIC_clock
96a388de 89#endif
67c5fc5c 90
70511134 91#ifdef CONFIG_X86_64
aa7d8e25 92extern int is_vsmp_box(void);
129d8bc8
YL
93#else
94static inline int is_vsmp_box(void)
95{
96 return 0;
97}
98#endif
2b97df06
JS
99extern void xapic_wait_icr_idle(void);
100extern u32 safe_xapic_wait_icr_idle(void);
2b97df06
JS
101extern void xapic_icr_write(u32, u32);
102extern int setup_profiling_timer(unsigned int);
aa7d8e25 103
1b374e4d 104static inline void native_apic_mem_write(u32 reg, u32 v)
67c5fc5c 105{
593f4a78 106 volatile u32 *addr = (volatile u32 *)(APIC_BASE + reg);
67c5fc5c 107
593f4a78
MR
108 alternative_io("movl %0, %1", "xchgl %0, %1", X86_FEATURE_11AP,
109 ASM_OUTPUT2("=r" (v), "=m" (*addr)),
110 ASM_OUTPUT2("0" (v), "m" (*addr)));
67c5fc5c
TG
111}
112
1b374e4d 113static inline u32 native_apic_mem_read(u32 reg)
67c5fc5c
TG
114{
115 return *((volatile u32 *)(APIC_BASE + reg));
116}
117
c1eeb2de
YL
118extern void native_apic_wait_icr_idle(void);
119extern u32 native_safe_apic_wait_icr_idle(void);
120extern void native_apic_icr_write(u32 low, u32 id);
121extern u64 native_apic_icr_read(void);
122
fc1edaf9 123extern int x2apic_mode;
b24696bc 124
d0b03bd1 125#ifdef CONFIG_X86_X2APIC
ce4e240c
SS
126/*
127 * Make previous memory operations globally visible before
128 * sending the IPI through x2apic wrmsr. We need a serializing instruction or
129 * mfence for this.
130 */
131static inline void x2apic_wrmsr_fence(void)
132{
133 asm volatile("mfence" : : : "memory");
134}
135
13c88fb5
SS
136static inline void native_apic_msr_write(u32 reg, u32 v)
137{
138 if (reg == APIC_DFR || reg == APIC_ID || reg == APIC_LDR ||
139 reg == APIC_LVR)
140 return;
141
142 wrmsr(APIC_BASE_MSR + (reg >> 4), v, 0);
143}
144
145static inline u32 native_apic_msr_read(u32 reg)
146{
147 u32 low, high;
148
149 if (reg == APIC_DFR)
150 return -1;
151
152 rdmsr(APIC_BASE_MSR + (reg >> 4), low, high);
153 return low;
154}
155
c1eeb2de
YL
156static inline void native_x2apic_wait_icr_idle(void)
157{
158 /* no need to wait for icr idle in x2apic */
159 return;
160}
161
162static inline u32 native_safe_x2apic_wait_icr_idle(void)
163{
164 /* no need to wait for icr idle in x2apic */
165 return 0;
166}
167
168static inline void native_x2apic_icr_write(u32 low, u32 id)
169{
170 wrmsrl(APIC_BASE_MSR + (APIC_ICR >> 4), ((__u64) id) << 32 | low);
171}
172
173static inline u64 native_x2apic_icr_read(void)
174{
175 unsigned long val;
176
177 rdmsrl(APIC_BASE_MSR + (APIC_ICR >> 4), val);
178 return val;
179}
180
fc1edaf9 181extern int x2apic_phys;
6e1cb38a
SS
182extern void check_x2apic(void);
183extern void enable_x2apic(void);
6e1cb38a 184extern void x2apic_icr_write(u32 low, u32 id);
a11b5abe
YL
185static inline int x2apic_enabled(void)
186{
187 int msr, msr2;
188
189 if (!cpu_has_x2apic)
190 return 0;
191
192 rdmsr(MSR_IA32_APICBASE, msr, msr2);
193 if (msr & X2APIC_ENABLE)
194 return 1;
195 return 0;
196}
fc1edaf9
SS
197
198#define x2apic_supported() (cpu_has_x2apic)
ce69a784
GN
199static inline void x2apic_force_phys(void)
200{
201 x2apic_phys = 1;
202}
a11b5abe 203#else
06cd9a7d
YL
204static inline void check_x2apic(void)
205{
206}
207static inline void enable_x2apic(void)
208{
209}
06cd9a7d
YL
210static inline int x2apic_enabled(void)
211{
212 return 0;
213}
ce69a784
GN
214static inline void x2apic_force_phys(void)
215{
216}
cf6567fe 217
93758238 218#define x2apic_preenabled 0
fc1edaf9 219#define x2apic_supported() 0
c535b6a1 220#endif
1b374e4d 221
93758238
WH
222extern void enable_IR_x2apic(void);
223
67c5fc5c
TG
224extern int get_physical_broadcast(void);
225
08306ce6 226extern void apic_disable(void);
67c5fc5c
TG
227extern int lapic_get_maxlvt(void);
228extern void clear_local_APIC(void);
229extern void connect_bsp_APIC(void);
230extern void disconnect_bsp_APIC(int virt_wire_setup);
231extern void disable_local_APIC(void);
232extern void lapic_shutdown(void);
233extern int verify_local_APIC(void);
234extern void cache_APIC_registers(void);
235extern void sync_Arb_IDs(void);
236extern void init_bsp_APIC(void);
237extern void setup_local_APIC(void);
739f33b3 238extern void end_local_APIC_setup(void);
67c5fc5c 239extern void init_apic_mappings(void);
67c5fc5c
TG
240extern void setup_boot_APIC_clock(void);
241extern void setup_secondary_APIC_clock(void);
242extern int APIC_init_uniprocessor(void);
e9427101 243extern void enable_NMI_through_LVT0(void);
67c5fc5c
TG
244
245/*
246 * On 32bit this is mach-xxx local
247 */
248#ifdef CONFIG_X86_64
8643f9d0 249extern void early_init_lapic_mapping(void);
8fbbc4b4
AK
250extern int apic_is_clustered_box(void);
251#else
252static inline int apic_is_clustered_box(void)
253{
254 return 0;
255}
67c5fc5c
TG
256#endif
257
7b83dae7
RR
258extern u8 setup_APIC_eilvt_mce(u8 vector, u8 msg_type, u8 mask);
259extern u8 setup_APIC_eilvt_ibs(u8 vector, u8 msg_type, u8 mask);
67c5fc5c 260
67c5fc5c
TG
261
262#else /* !CONFIG_X86_LOCAL_APIC */
263static inline void lapic_shutdown(void) { }
264#define local_apic_timer_c2_ok 1
f3294a33 265static inline void init_apic_mappings(void) { }
d3ec5cae 266static inline void disable_local_APIC(void) { }
08306ce6 267static inline void apic_disable(void) { }
67c5fc5c
TG
268#endif /* !CONFIG_X86_LOCAL_APIC */
269
1f75ed0c
IM
270#ifdef CONFIG_X86_64
271#define SET_APIC_ID(x) (apic->set_apic_id(x))
272#else
273
1f75ed0c
IM
274#endif
275
e2780a68
IM
276/*
277 * Copyright 2004 James Cleverdon, IBM.
278 * Subject to the GNU Public License, v.2
279 *
280 * Generic APIC sub-arch data struct.
281 *
282 * Hacked for x86-64 by James Cleverdon from i386 architecture code by
283 * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and
284 * James Cleverdon.
285 */
be163a15 286struct apic {
e2780a68
IM
287 char *name;
288
289 int (*probe)(void);
290 int (*acpi_madt_oem_check)(char *oem_id, char *oem_table_id);
291 int (*apic_id_registered)(void);
292
293 u32 irq_delivery_mode;
294 u32 irq_dest_mode;
295
296 const struct cpumask *(*target_cpus)(void);
297
298 int disable_esr;
299
300 int dest_logical;
301 unsigned long (*check_apicid_used)(physid_mask_t bitmap, int apicid);
302 unsigned long (*check_apicid_present)(int apicid);
303
304 void (*vector_allocation_domain)(int cpu, struct cpumask *retmask);
305 void (*init_apic_ldr)(void);
306
307 physid_mask_t (*ioapic_phys_id_map)(physid_mask_t map);
308
309 void (*setup_apic_routing)(void);
310 int (*multi_timer_check)(int apic, int irq);
311 int (*apicid_to_node)(int logical_apicid);
312 int (*cpu_to_logical_apicid)(int cpu);
313 int (*cpu_present_to_apicid)(int mps_cpu);
314 physid_mask_t (*apicid_to_cpu_present)(int phys_apicid);
315 void (*setup_portio_remap)(void);
316 int (*check_phys_apicid_present)(int boot_cpu_physical_apicid);
317 void (*enable_apic_mode)(void);
318 int (*phys_pkg_id)(int cpuid_apic, int index_msb);
319
320 /*
be163a15 321 * When one of the next two hooks returns 1 the apic
e2780a68
IM
322 * is switched to this. Essentially they are additional
323 * probe functions:
324 */
325 int (*mps_oem_check)(struct mpc_table *mpc, char *oem, char *productid);
326
327 unsigned int (*get_apic_id)(unsigned long x);
328 unsigned long (*set_apic_id)(unsigned int id);
329 unsigned long apic_id_mask;
330
331 unsigned int (*cpu_mask_to_apicid)(const struct cpumask *cpumask);
332 unsigned int (*cpu_mask_to_apicid_and)(const struct cpumask *cpumask,
333 const struct cpumask *andmask);
334
335 /* ipi */
336 void (*send_IPI_mask)(const struct cpumask *mask, int vector);
337 void (*send_IPI_mask_allbutself)(const struct cpumask *mask,
338 int vector);
339 void (*send_IPI_allbutself)(int vector);
340 void (*send_IPI_all)(int vector);
341 void (*send_IPI_self)(int vector);
342
343 /* wakeup_secondary_cpu */
1f5bcabf 344 int (*wakeup_secondary_cpu)(int apicid, unsigned long start_eip);
e2780a68
IM
345
346 int trampoline_phys_low;
347 int trampoline_phys_high;
348
349 void (*wait_for_init_deassert)(atomic_t *deassert);
350 void (*smp_callin_clear_local_apic)(void);
e2780a68
IM
351 void (*inquire_remote_apic)(int apicid);
352
353 /* apic ops */
354 u32 (*read)(u32 reg);
355 void (*write)(u32 reg, u32 v);
356 u64 (*icr_read)(void);
357 void (*icr_write)(u32 low, u32 high);
358 void (*wait_icr_idle)(void);
359 u32 (*safe_wait_icr_idle)(void);
360};
361
0917c01f
IM
362/*
363 * Pointer to the local APIC driver in use on this system (there's
364 * always just one such driver in use - the kernel decides via an
365 * early probing process which one it picks - and then sticks to it):
366 */
be163a15 367extern struct apic *apic;
0917c01f
IM
368
369/*
370 * APIC functionality to boot other CPUs - only used on SMP:
371 */
372#ifdef CONFIG_SMP
2b6163bf
YL
373extern atomic_t init_deasserted;
374extern int wakeup_secondary_cpu_via_nmi(int apicid, unsigned long start_eip);
0917c01f 375#endif
e2780a68
IM
376
377static inline u32 apic_read(u32 reg)
378{
379 return apic->read(reg);
380}
381
382static inline void apic_write(u32 reg, u32 val)
383{
384 apic->write(reg, val);
385}
386
387static inline u64 apic_icr_read(void)
388{
389 return apic->icr_read();
390}
391
392static inline void apic_icr_write(u32 low, u32 high)
393{
394 apic->icr_write(low, high);
395}
396
397static inline void apic_wait_icr_idle(void)
398{
399 apic->wait_icr_idle();
400}
401
402static inline u32 safe_apic_wait_icr_idle(void)
403{
404 return apic->safe_wait_icr_idle();
405}
406
407
408static inline void ack_APIC_irq(void)
409{
b2b35259 410#ifdef CONFIG_X86_LOCAL_APIC
e2780a68
IM
411 /*
412 * ack_APIC_irq() actually gets compiled as a single instruction
413 * ... yummie.
414 */
415
416 /* Docs say use 0 for future compatibility */
417 apic_write(APIC_EOI, 0);
b2b35259 418#endif
e2780a68
IM
419}
420
421static inline unsigned default_get_apic_id(unsigned long x)
422{
423 unsigned int ver = GET_APIC_VERSION(apic_read(APIC_LVR));
424
42937e81 425 if (APIC_XAPIC(ver) || boot_cpu_has(X86_FEATURE_EXTD_APICID))
e2780a68
IM
426 return (x >> 24) & 0xFF;
427 else
428 return (x >> 24) & 0x0F;
429}
430
431/*
432 * Warm reset vector default position:
433 */
434#define DEFAULT_TRAMPOLINE_PHYS_LOW 0x467
435#define DEFAULT_TRAMPOLINE_PHYS_HIGH 0x469
436
2b6163bf 437#ifdef CONFIG_X86_64
be163a15
IM
438extern struct apic apic_flat;
439extern struct apic apic_physflat;
440extern struct apic apic_x2apic_cluster;
441extern struct apic apic_x2apic_phys;
e2780a68
IM
442extern int default_acpi_madt_oem_check(char *, char *);
443
444extern void apic_send_IPI_self(int vector);
445
be163a15 446extern struct apic apic_x2apic_uv_x;
e2780a68
IM
447DECLARE_PER_CPU(int, x2apic_extra_bits);
448
449extern int default_cpu_present_to_apicid(int mps_cpu);
450extern int default_check_phys_apicid_present(int boot_cpu_physical_apicid);
451#endif
452
453static inline void default_wait_for_init_deassert(atomic_t *deassert)
454{
455 while (!atomic_read(deassert))
456 cpu_relax();
457 return;
458}
459
460extern void generic_bigsmp_probe(void);
461
462
463#ifdef CONFIG_X86_LOCAL_APIC
464
465#include <asm/smp.h>
466
467#define APIC_DFR_VALUE (APIC_DFR_FLAT)
468
469static inline const struct cpumask *default_target_cpus(void)
470{
471#ifdef CONFIG_SMP
472 return cpu_online_mask;
473#else
474 return cpumask_of(0);
475#endif
476}
477
478DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid);
479
480
481static inline unsigned int read_apic_id(void)
482{
483 unsigned int reg;
484
485 reg = apic_read(APIC_ID);
486
487 return apic->get_apic_id(reg);
488}
489
490extern void default_setup_apic_routing(void);
491
492#ifdef CONFIG_X86_32
2c1b284e
JSR
493
494extern struct apic apic_default;
495
e2780a68
IM
496/*
497 * Set up the logical destination ID.
498 *
499 * Intel recommends to set DFR, LDR and TPR before enabling
500 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
501 * document number 292116). So here it goes...
502 */
503extern void default_init_apic_ldr(void);
504
505static inline int default_apic_id_registered(void)
506{
507 return physid_isset(read_apic_id(), phys_cpu_present_map);
508}
509
f56e5034
YL
510static inline int default_phys_pkg_id(int cpuid_apic, int index_msb)
511{
512 return cpuid_apic >> index_msb;
513}
514
515extern int default_apicid_to_node(int logical_apicid);
516
517#endif
518
e2780a68
IM
519static inline unsigned int
520default_cpu_mask_to_apicid(const struct cpumask *cpumask)
521{
f56e5034 522 return cpumask_bits(cpumask)[0] & APIC_ALL_CPUS;
e2780a68
IM
523}
524
525static inline unsigned int
526default_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
527 const struct cpumask *andmask)
528{
529 unsigned long mask1 = cpumask_bits(cpumask)[0];
530 unsigned long mask2 = cpumask_bits(andmask)[0];
531 unsigned long mask3 = cpumask_bits(cpu_online_mask)[0];
532
533 return (unsigned int)(mask1 & mask2 & mask3);
534}
535
e2780a68
IM
536static inline unsigned long default_check_apicid_used(physid_mask_t bitmap, int apicid)
537{
538 return physid_isset(apicid, bitmap);
539}
540
541static inline unsigned long default_check_apicid_present(int bit)
542{
543 return physid_isset(bit, phys_cpu_present_map);
544}
545
546static inline physid_mask_t default_ioapic_phys_id_map(physid_mask_t phys_map)
547{
548 return phys_map;
549}
550
551/* Mapping from cpu number to logical apicid */
552static inline int default_cpu_to_logical_apicid(int cpu)
553{
554 return 1 << cpu;
555}
556
557static inline int __default_cpu_present_to_apicid(int mps_cpu)
558{
559 if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu))
560 return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu);
561 else
562 return BAD_APICID;
563}
564
565static inline int
566__default_check_phys_apicid_present(int boot_cpu_physical_apicid)
567{
568 return physid_isset(boot_cpu_physical_apicid, phys_cpu_present_map);
569}
570
571#ifdef CONFIG_X86_32
572static inline int default_cpu_present_to_apicid(int mps_cpu)
573{
574 return __default_cpu_present_to_apicid(mps_cpu);
575}
576
577static inline int
578default_check_phys_apicid_present(int boot_cpu_physical_apicid)
579{
580 return __default_check_phys_apicid_present(boot_cpu_physical_apicid);
581}
582#else
583extern int default_cpu_present_to_apicid(int mps_cpu);
584extern int default_check_phys_apicid_present(int boot_cpu_physical_apicid);
585#endif
586
587static inline physid_mask_t default_apicid_to_cpu_present(int phys_apicid)
588{
589 return physid_mask_of_physid(phys_apicid);
590}
591
592#endif /* CONFIG_X86_LOCAL_APIC */
593
2f205bc4
IM
594#ifdef CONFIG_X86_32
595extern u8 cpu_2_logical_apicid[NR_CPUS];
596#endif
597
1965aae3 598#endif /* _ASM_X86_APIC_H */