blob: c7a00caa6ec6e91b0cf094fff0777f7600e3749a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_SMP_H
2#define __ASM_SMP_H
3
Thomas Gleixnerae9d9832008-01-30 13:30:36 +01004#include <linux/cpumask.h>
5#include <linux/init.h>
6
Linus Torvalds1da177e2005-04-16 15:20:36 -07007/*
8 * We need the APIC definitions automatically as part of 'smp.h'
9 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <asm/apic.h>
Jan Beulich00f1ea62007-05-02 19:27:04 +020011#include <asm/io_apic.h>
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010012#include <asm/mpspec.h>
13#include <asm/pda.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/thread_info.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Andi Kleen3c021752006-01-11 22:45:12 +010016extern cpumask_t cpu_initialized;
Andi Kleena8ab26f2005-04-16 15:25:19 -070017
Laurent Vivier66d16ed2007-10-19 20:35:03 +020018extern int smp_call_function_mask(cpumask_t mask, void (*func)(void *),
19 void *info, int wait);
Eric W. Biederman3d483f42005-07-29 14:03:29 -070020
travis@sgi.comef970012008-01-30 13:33:10 +010021extern u16 __initdata x86_cpu_to_apicid_init[];
travis@sgi.come8c10ef2008-01-30 13:33:12 +010022extern u16 __initdata x86_bios_cpu_apicid_init[];
travis@sgi.com3b419082008-01-30 13:33:11 +010023extern void *x86_cpu_to_apicid_early_ptr;
travis@sgi.come8c10ef2008-01-30 13:33:12 +010024extern void *x86_bios_cpu_apicid_early_ptr;
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010025
Mike Travisd5a74302007-10-16 01:24:05 -070026DECLARE_PER_CPU(cpumask_t, cpu_sibling_map);
Mike Travis08357612007-10-16 01:24:04 -070027DECLARE_PER_CPU(cpumask_t, cpu_core_map);
travis@sgi.comef970012008-01-30 13:33:10 +010028DECLARE_PER_CPU(u16, cpu_llc_id);
29DECLARE_PER_CPU(u16, x86_cpu_to_apicid);
travis@sgi.come8c10ef2008-01-30 13:33:12 +010030DECLARE_PER_CPU(u16, x86_bios_cpu_apicid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070031
Linus Torvalds1da177e2005-04-16 15:20:36 -070032static inline int cpu_present_to_apicid(int mps_cpu)
33{
travis@sgi.come8c10ef2008-01-30 13:33:12 +010034 if (cpu_present(mps_cpu))
35 return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 else
37 return BAD_APICID;
38}
39
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010040#ifdef CONFIG_SMP
41
42#define SMP_TRAMPOLINE_BASE 0x6000
43
44extern int __cpu_disable(void);
45extern void __cpu_die(unsigned int cpu);
46extern void prefill_possible_map(void);
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010047
48#define raw_smp_processor_id() read_pda(cpunumber)
49#define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
50
51#define stack_smp_processor_id() \
52 ({ \
53 struct thread_info *ti; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010055 ti->cpu; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070056})
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010057
58/*
59 * On x86 all CPUs are mapped 1:1 to the APIC space. This simplifies
60 * scheduling and IPI sending and compresses data structures.
61 */
62static inline int num_booting_cpus(void)
63{
64 return cpus_weight(cpu_callout_map);
65}
66
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010067#else /* CONFIG_SMP */
68
69extern unsigned int boot_cpu_id;
70#define cpu_physical_id(cpu) boot_cpu_id
71#define stack_smp_processor_id() 0
72
73#endif /* !CONFIG_SMP */
74
75#define safe_smp_processor_id() smp_processor_id()
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Linus Torvalds1da177e2005-04-16 15:20:36 -070077static __inline int logical_smp_processor_id(void)
78{
79 /* we don't want to mark this access volatile - bad code generation */
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010080 return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR));
Linus Torvalds1da177e2005-04-16 15:20:36 -070081}
Linus Torvalds1da177e2005-04-16 15:20:36 -070082
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010083static inline int hard_smp_processor_id(void)
84{
85 /* we don't want to mark this access volatile - bad code generation */
86 return GET_APIC_ID(*(u32 *)(APIC_BASE + APIC_ID));
87}
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089#endif
90