blob: 2feddda91e1277ec75b3a22bb43bd69e9ee379ad [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 Kleena8ab26f2005-04-16 15:25:19 -070016extern cpumask_t cpu_callout_map;
Andi Kleen3c021752006-01-11 22:45:12 +010017extern cpumask_t cpu_initialized;
Andi Kleena8ab26f2005-04-16 15:25:19 -070018
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010019extern int smp_num_siblings;
20extern unsigned int num_processors;
21
Linus Torvalds1da177e2005-04-16 15:20:36 -070022extern void smp_alloc_memory(void);
Ashok Raj884d9e42005-06-25 14:55:02 -070023extern void lock_ipi_call_lock(void);
24extern void unlock_ipi_call_lock(void);
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010025
Laurent Vivier66d16ed2007-10-19 20:35:03 +020026extern int smp_call_function_mask(cpumask_t mask, void (*func)(void *),
27 void *info, int wait);
Eric W. Biederman3d483f42005-07-29 14:03:29 -070028
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010029extern u8 __initdata x86_cpu_to_apicid_init[];
30extern void *x86_cpu_to_apicid_ptr;
31extern u8 bios_cpu_apicid[];
32
Mike Travisd5a74302007-10-16 01:24:05 -070033DECLARE_PER_CPU(cpumask_t, cpu_sibling_map);
Mike Travis08357612007-10-16 01:24:04 -070034DECLARE_PER_CPU(cpumask_t, cpu_core_map);
Mike Travisb6278472007-10-19 20:35:03 +020035DECLARE_PER_CPU(u8, cpu_llc_id);
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010036DECLARE_PER_CPU(u8, x86_cpu_to_apicid);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Linus Torvalds1da177e2005-04-16 15:20:36 -070038static inline int cpu_present_to_apicid(int mps_cpu)
39{
40 if (mps_cpu < NR_CPUS)
41 return (int)bios_cpu_apicid[mps_cpu];
42 else
43 return BAD_APICID;
44}
45
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010046#ifdef CONFIG_SMP
47
48#define SMP_TRAMPOLINE_BASE 0x6000
49
50extern int __cpu_disable(void);
51extern void __cpu_die(unsigned int cpu);
52extern void prefill_possible_map(void);
53extern unsigned __cpuinitdata disabled_cpus;
54
55#define raw_smp_processor_id() read_pda(cpunumber)
56#define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu)
57
58#define stack_smp_processor_id() \
59 ({ \
60 struct thread_info *ti; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010062 ti->cpu; \
Linus Torvalds1da177e2005-04-16 15:20:36 -070063})
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010064
65/*
66 * On x86 all CPUs are mapped 1:1 to the APIC space. This simplifies
67 * scheduling and IPI sending and compresses data structures.
68 */
69static inline int num_booting_cpus(void)
70{
71 return cpus_weight(cpu_callout_map);
72}
73
74extern void smp_send_reschedule(int cpu);
75
76#else /* CONFIG_SMP */
77
78extern unsigned int boot_cpu_id;
79#define cpu_physical_id(cpu) boot_cpu_id
80#define stack_smp_processor_id() 0
81
82#endif /* !CONFIG_SMP */
83
84#define safe_smp_processor_id() smp_processor_id()
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Linus Torvalds1da177e2005-04-16 15:20:36 -070086static __inline int logical_smp_processor_id(void)
87{
88 /* we don't want to mark this access volatile - bad code generation */
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010089 return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR));
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
Thomas Gleixnerae9d9832008-01-30 13:30:36 +010092static inline int hard_smp_processor_id(void)
93{
94 /* we don't want to mark this access volatile - bad code generation */
95 return GET_APIC_ID(*(u32 *)(APIC_BASE + APIC_ID));
96}
97
Linus Torvalds1da177e2005-04-16 15:20:36 -070098#endif
99