blob: 0c713278706262e60abaa34229ccedfa4e9a45d9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#ifndef __ASM_SMP_H
2#define __ASM_SMP_H
3
4/*
5 * We need the APIC definitions automatically as part of 'smp.h'
6 */
7#ifndef __ASSEMBLY__
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <linux/kernel.h>
9#include <linux/threads.h>
10#include <linux/cpumask.h>
11#endif
12
Jan Beulich00f1ea62007-05-02 19:27:04 +020013#if defined(CONFIG_X86_LOCAL_APIC) && !defined(__ASSEMBLY__)
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <asm/bitops.h>
15#include <asm/mpspec.h>
Jan Beulich00f1ea62007-05-02 19:27:04 +020016#include <asm/apic.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070017#ifdef CONFIG_X86_IO_APIC
18#include <asm/io_apic.h>
19#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#endif
21
22#define BAD_APICID 0xFFu
23#ifdef CONFIG_SMP
24#ifndef __ASSEMBLY__
25
26/*
27 * Private routines/data
28 */
29
30extern void smp_alloc_memory(void);
31extern int pic_mode;
32extern int smp_num_siblings;
33extern cpumask_t cpu_sibling_map[];
Andi Kleen3dd9d512005-04-16 15:25:15 -070034extern cpumask_t cpu_core_map[];
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
Linus Torvalds1da177e2005-04-16 15:20:36 -070036extern void (*mtrr_hook) (void);
37extern void zap_low_mappings (void);
Li Shaohua6fe940d2005-06-25 14:54:53 -070038extern void lock_ipi_call_lock(void);
39extern void unlock_ipi_call_lock(void);
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41#define MAX_APICID 256
42extern u8 x86_cpu_to_apicid[];
43
Ashok Rajb4033c12005-11-08 21:42:33 -080044#define cpu_physical_id(cpu) x86_cpu_to_apicid[cpu]
45
Li Shaohuae1367da2005-06-25 14:54:56 -070046#ifdef CONFIG_HOTPLUG_CPU
47extern void cpu_exit_clear(void);
48extern void cpu_uninit(void);
Li Shaohuae1367da2005-06-25 14:54:56 -070049#endif
50
Jeremy Fitzhardinge01a2f432007-05-02 19:27:11 +020051struct smp_ops
52{
53 void (*smp_prepare_boot_cpu)(void);
54 void (*smp_prepare_cpus)(unsigned max_cpus);
55 int (*cpu_up)(unsigned cpu);
56 void (*smp_cpus_done)(unsigned max_cpus);
57
58 void (*smp_send_stop)(void);
59 void (*smp_send_reschedule)(int cpu);
60 int (*smp_call_function_mask)(cpumask_t mask,
61 void (*func)(void *info), void *info,
62 int wait);
63};
64
65extern struct smp_ops smp_ops;
66
67static inline void smp_prepare_boot_cpu(void)
68{
69 smp_ops.smp_prepare_boot_cpu();
70}
71static inline void smp_prepare_cpus(unsigned int max_cpus)
72{
73 smp_ops.smp_prepare_cpus(max_cpus);
74}
75static inline int __cpu_up(unsigned int cpu)
76{
77 return smp_ops.cpu_up(cpu);
78}
79static inline void smp_cpus_done(unsigned int max_cpus)
80{
81 smp_ops.smp_cpus_done(max_cpus);
82}
83
84static inline void smp_send_stop(void)
85{
86 smp_ops.smp_send_stop();
87}
88static inline void smp_send_reschedule(int cpu)
89{
90 smp_ops.smp_send_reschedule(cpu);
91}
92static inline int smp_call_function_mask(cpumask_t mask,
93 void (*func) (void *info), void *info,
94 int wait)
95{
96 return smp_ops.smp_call_function_mask(mask, func, info, wait);
97}
98
99void native_smp_prepare_boot_cpu(void);
100void native_smp_prepare_cpus(unsigned int max_cpus);
101int native_cpu_up(unsigned int cpunum);
102void native_smp_cpus_done(unsigned int max_cpus);
103
Zachary Amsdenae5da272007-02-13 13:26:21 +0100104#ifndef CONFIG_PARAVIRT
105#define startup_ipi_hook(phys_apicid, start_eip, start_esp) \
106do { } while (0)
107#endif
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109/*
110 * This function is needed by all SMP systems. It must _always_ be valid
111 * from the initial startup. We map APIC_BASE very early in page_setup(),
112 * so this is correct in the x86 case.
113 */
Jeremy Fitzhardinge7c3576d2007-05-02 19:27:16 +0200114DECLARE_PER_CPU(int, cpu_number);
115#define raw_smp_processor_id() (x86_read_percpu(cpu_number))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117extern cpumask_t cpu_callout_map;
118extern cpumask_t cpu_callin_map;
Zwane Mwaikambo4ad8d382005-09-03 15:56:51 -0700119extern cpumask_t cpu_possible_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121/* We don't mark CPUs online until __cpu_up(), so we need another measure */
122static inline int num_booting_cpus(void)
123{
124 return cpus_weight(cpu_callout_map);
125}
126
Fernando Luis Vazquez Caoa36166c2007-05-09 02:33:27 -0700127extern int safe_smp_processor_id(void);
128extern int __cpu_disable(void);
129extern void __cpu_die(unsigned int cpu);
130extern unsigned int num_processors;
131
132#endif /* !__ASSEMBLY__ */
133
134#else /* CONFIG_SMP */
135
136#define safe_smp_processor_id() 0
137#define cpu_physical_id(cpu) boot_cpu_physical_apicid
138
139#define NO_PROC_ID 0xFF /* No processor magic marker */
140
141#endif /* CONFIG_SMP */
142
143#ifndef __ASSEMBLY__
144
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#ifdef CONFIG_X86_LOCAL_APIC
146
147#ifdef APIC_DEFINITION
148extern int hard_smp_processor_id(void);
149#else
150#include <mach_apicdef.h>
151static inline int hard_smp_processor_id(void)
152{
153 /* we don't want to mark this access volatile - bad code generation */
154 return GET_APIC_ID(*(unsigned long *)(APIC_BASE+APIC_ID));
155}
Fernando Luis Vazquez Caoa36166c2007-05-09 02:33:27 -0700156#endif /* APIC_DEFINITION */
Zwane Mwaikambof3705132005-06-25 14:54:50 -0700157
Fernando Luis Vazquez Caoa36166c2007-05-09 02:33:27 -0700158#else /* CONFIG_X86_LOCAL_APIC */
Andi Kleen874c4fe2006-09-26 10:52:26 +0200159
Fernando Luis Vazquez Caoa36166c2007-05-09 02:33:27 -0700160#ifndef CONFIG_SMP
Fernando Luis Vazquez Cao2f4dfe22007-05-09 02:33:25 -0700161#define hard_smp_processor_id() 0
Fernando Luis Vazquez Caoa36166c2007-05-09 02:33:27 -0700162#endif
Ashok Rajb4033c12005-11-08 21:42:33 -0800163
Fernando Luis Vazquez Caoa36166c2007-05-09 02:33:27 -0700164#endif /* CONFIG_X86_LOCAL_APIC */
Jiri Kosina815a9652006-10-06 11:11:56 +0200165
166extern u8 apicid_2_node[];
167
Andi Kleen874c4fe2006-09-26 10:52:26 +0200168#ifdef CONFIG_X86_LOCAL_APIC
169static __inline int logical_smp_processor_id(void)
170{
171 /* we don't want to mark this access volatile - bad code generation */
172 return GET_APIC_LOGICAL_ID(*(unsigned long *)(APIC_BASE+APIC_LDR));
173}
174#endif
175#endif
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177#endif