H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_SMP_H |
| 2 | #define _ASM_X86_SMP_H |
Glauber Costa | c27cfef | 2008-03-03 14:12:29 -0300 | [diff] [blame] | 3 | #ifndef __ASSEMBLY__ |
Glauber Costa | 53ebef4 | 2008-03-03 14:12:31 -0300 | [diff] [blame] | 4 | #include <linux/cpumask.h> |
Glauber Costa | 93b016f | 2008-03-03 14:12:40 -0300 | [diff] [blame] | 5 | #include <linux/init.h> |
Glauber de Oliveira Costa | 7e1efc0 | 2008-03-19 14:25:18 -0300 | [diff] [blame] | 6 | #include <asm/percpu.h> |
Glauber Costa | 53ebef4 | 2008-03-03 14:12:31 -0300 | [diff] [blame] | 7 | |
Glauber Costa | b23dab0 | 2008-03-27 14:06:00 -0300 | [diff] [blame] | 8 | /* |
| 9 | * We need the APIC definitions automatically as part of 'smp.h' |
| 10 | */ |
| 11 | #ifdef CONFIG_X86_LOCAL_APIC |
| 12 | # include <asm/mpspec.h> |
| 13 | # include <asm/apic.h> |
| 14 | # ifdef CONFIG_X86_IO_APIC |
| 15 | # include <asm/io_apic.h> |
| 16 | # endif |
| 17 | #endif |
| 18 | #include <asm/pda.h> |
| 19 | #include <asm/thread_info.h> |
Jaswinder Singh Rajput | fb8fd07 | 2009-01-10 12:20:24 +0530 | [diff] [blame^] | 20 | #include <asm/cpumask.h> |
Glauber Costa | b23dab0 | 2008-03-27 14:06:00 -0300 | [diff] [blame] | 21 | |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 22 | #ifdef CONFIG_X86_64 |
| 23 | |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 24 | extern cpumask_var_t cpu_initialized_mask; |
| 25 | extern cpumask_var_t cpu_sibling_setup_mask; |
| 26 | |
| 27 | #else /* CONFIG_X86_32 */ |
| 28 | |
Glauber Costa | 8be9ac8 | 2008-03-27 14:06:04 -0300 | [diff] [blame] | 29 | extern cpumask_t cpu_initialized; |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 30 | extern cpumask_t cpu_sibling_setup_map; |
| 31 | |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 32 | #define cpu_initialized_mask ((struct cpumask *)&cpu_initialized) |
| 33 | #define cpu_sibling_setup_mask ((struct cpumask *)&cpu_sibling_setup_map) |
| 34 | |
| 35 | #endif /* CONFIG_X86_32 */ |
Glauber Costa | 8be9ac8 | 2008-03-27 14:06:04 -0300 | [diff] [blame] | 36 | |
Jeremy Fitzhardinge | 7c33b1e | 2008-07-08 15:06:29 -0700 | [diff] [blame] | 37 | extern int __cpuinit get_local_pda(int cpu); |
| 38 | |
Glauber Costa | 53ebef4 | 2008-03-03 14:12:31 -0300 | [diff] [blame] | 39 | extern int smp_num_siblings; |
| 40 | extern unsigned int num_processors; |
Glauber Costa | c27cfef | 2008-03-03 14:12:29 -0300 | [diff] [blame] | 41 | |
Glauber de Oliveira Costa | 7e1efc0 | 2008-03-19 14:25:18 -0300 | [diff] [blame] | 42 | DECLARE_PER_CPU(cpumask_t, cpu_sibling_map); |
| 43 | DECLARE_PER_CPU(cpumask_t, cpu_core_map); |
| 44 | DECLARE_PER_CPU(u16, cpu_llc_id); |
Jaswinder Singh | fb26132 | 2008-07-21 21:36:40 +0530 | [diff] [blame] | 45 | #ifdef CONFIG_X86_32 |
| 46 | DECLARE_PER_CPU(int, cpu_number); |
| 47 | #endif |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 48 | |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 49 | static inline struct cpumask *cpu_sibling_mask(int cpu) |
| 50 | { |
| 51 | return &per_cpu(cpu_sibling_map, cpu); |
| 52 | } |
| 53 | |
| 54 | static inline struct cpumask *cpu_core_mask(int cpu) |
| 55 | { |
| 56 | return &per_cpu(cpu_core_map, cpu); |
| 57 | } |
| 58 | |
Mike Travis | 23ca4bb | 2008-05-12 21:21:12 +0200 | [diff] [blame] | 59 | DECLARE_EARLY_PER_CPU(u16, x86_cpu_to_apicid); |
| 60 | DECLARE_EARLY_PER_CPU(u16, x86_bios_cpu_apicid); |
Glauber de Oliveira Costa | 7e1efc0 | 2008-03-19 14:25:18 -0300 | [diff] [blame] | 61 | |
Glauber de Oliveira Costa | 9d97d0d | 2008-03-19 14:25:57 -0300 | [diff] [blame] | 62 | /* Static state in head.S used to set up a CPU */ |
| 63 | extern struct { |
| 64 | void *sp; |
| 65 | unsigned short ss; |
| 66 | } stack_start; |
| 67 | |
Glauber Costa | 1669402 | 2008-03-03 14:12:32 -0300 | [diff] [blame] | 68 | struct smp_ops { |
| 69 | void (*smp_prepare_boot_cpu)(void); |
| 70 | void (*smp_prepare_cpus)(unsigned max_cpus); |
Glauber Costa | 1669402 | 2008-03-03 14:12:32 -0300 | [diff] [blame] | 71 | void (*smp_cpus_done)(unsigned max_cpus); |
| 72 | |
| 73 | void (*smp_send_stop)(void); |
| 74 | void (*smp_send_reschedule)(int cpu); |
Jens Axboe | 3b16cf8 | 2008-06-26 11:21:54 +0200 | [diff] [blame] | 75 | |
Alex Nixon | 93be71b | 2008-08-22 11:52:11 +0100 | [diff] [blame] | 76 | int (*cpu_up)(unsigned cpu); |
| 77 | int (*cpu_disable)(void); |
| 78 | void (*cpu_die)(unsigned int cpu); |
| 79 | void (*play_dead)(void); |
| 80 | |
Mike Travis | bcda016 | 2008-12-16 17:33:59 -0800 | [diff] [blame] | 81 | void (*send_call_func_ipi)(const struct cpumask *mask); |
Jens Axboe | 3b16cf8 | 2008-06-26 11:21:54 +0200 | [diff] [blame] | 82 | void (*send_call_func_single_ipi)(int cpu); |
Glauber Costa | 1669402 | 2008-03-03 14:12:32 -0300 | [diff] [blame] | 83 | }; |
| 84 | |
Glauber Costa | 1452207 | 2008-03-03 14:12:59 -0300 | [diff] [blame] | 85 | /* Globals due to paravirt */ |
| 86 | extern void set_cpu_sibling_map(int cpu); |
| 87 | |
Glauber Costa | c76cb36 | 2008-03-03 14:12:33 -0300 | [diff] [blame] | 88 | #ifdef CONFIG_SMP |
Glauber de Oliveira Costa | d0173ae | 2008-03-19 14:24:59 -0300 | [diff] [blame] | 89 | #ifndef CONFIG_PARAVIRT |
| 90 | #define startup_ipi_hook(phys_apicid, start_eip, start_esp) do { } while (0) |
| 91 | #endif |
Glauber Costa | c76cb36 | 2008-03-03 14:12:33 -0300 | [diff] [blame] | 92 | extern struct smp_ops smp_ops; |
Glauber Costa | 8678969 | 2008-03-03 14:12:34 -0300 | [diff] [blame] | 93 | |
Glauber Costa | 377d698 | 2008-03-03 14:12:51 -0300 | [diff] [blame] | 94 | static inline void smp_send_stop(void) |
| 95 | { |
| 96 | smp_ops.smp_send_stop(); |
| 97 | } |
| 98 | |
Glauber Costa | 1e3fac8 | 2008-03-03 14:12:37 -0300 | [diff] [blame] | 99 | static inline void smp_prepare_boot_cpu(void) |
| 100 | { |
| 101 | smp_ops.smp_prepare_boot_cpu(); |
| 102 | } |
| 103 | |
Glauber Costa | 7557da6 | 2008-03-03 14:12:38 -0300 | [diff] [blame] | 104 | static inline void smp_prepare_cpus(unsigned int max_cpus) |
| 105 | { |
| 106 | smp_ops.smp_prepare_cpus(max_cpus); |
| 107 | } |
| 108 | |
Glauber Costa | c559764 | 2008-03-03 14:12:39 -0300 | [diff] [blame] | 109 | static inline void smp_cpus_done(unsigned int max_cpus) |
| 110 | { |
| 111 | smp_ops.smp_cpus_done(max_cpus); |
| 112 | } |
| 113 | |
Glauber Costa | 71d1954 | 2008-03-03 14:12:36 -0300 | [diff] [blame] | 114 | static inline int __cpu_up(unsigned int cpu) |
| 115 | { |
| 116 | return smp_ops.cpu_up(cpu); |
| 117 | } |
| 118 | |
Alex Nixon | 93be71b | 2008-08-22 11:52:11 +0100 | [diff] [blame] | 119 | static inline int __cpu_disable(void) |
| 120 | { |
| 121 | return smp_ops.cpu_disable(); |
| 122 | } |
| 123 | |
| 124 | static inline void __cpu_die(unsigned int cpu) |
| 125 | { |
| 126 | smp_ops.cpu_die(cpu); |
| 127 | } |
| 128 | |
| 129 | static inline void play_dead(void) |
| 130 | { |
| 131 | smp_ops.play_dead(); |
| 132 | } |
| 133 | |
Glauber Costa | 8678969 | 2008-03-03 14:12:34 -0300 | [diff] [blame] | 134 | static inline void smp_send_reschedule(int cpu) |
| 135 | { |
| 136 | smp_ops.smp_send_reschedule(cpu); |
| 137 | } |
Glauber Costa | 64b1a21 | 2008-03-03 14:12:35 -0300 | [diff] [blame] | 138 | |
Jens Axboe | 3b16cf8 | 2008-06-26 11:21:54 +0200 | [diff] [blame] | 139 | static inline void arch_send_call_function_single_ipi(int cpu) |
Glauber Costa | 64b1a21 | 2008-03-03 14:12:35 -0300 | [diff] [blame] | 140 | { |
Jens Axboe | 3b16cf8 | 2008-06-26 11:21:54 +0200 | [diff] [blame] | 141 | smp_ops.send_call_func_single_ipi(cpu); |
| 142 | } |
| 143 | |
| 144 | static inline void arch_send_call_function_ipi(cpumask_t mask) |
| 145 | { |
Mike Travis | e798673 | 2008-12-16 17:33:52 -0800 | [diff] [blame] | 146 | smp_ops.send_call_func_ipi(&mask); |
Glauber Costa | 64b1a21 | 2008-03-03 14:12:35 -0300 | [diff] [blame] | 147 | } |
Glauber Costa | 71d1954 | 2008-03-03 14:12:36 -0300 | [diff] [blame] | 148 | |
Alex Nixon | 8227dce | 2008-08-22 11:52:14 +0100 | [diff] [blame] | 149 | void cpu_disable_common(void); |
Glauber Costa | 1e3fac8 | 2008-03-03 14:12:37 -0300 | [diff] [blame] | 150 | void native_smp_prepare_boot_cpu(void); |
Glauber Costa | 7557da6 | 2008-03-03 14:12:38 -0300 | [diff] [blame] | 151 | void native_smp_prepare_cpus(unsigned int max_cpus); |
Glauber Costa | c559764 | 2008-03-03 14:12:39 -0300 | [diff] [blame] | 152 | void native_smp_cpus_done(unsigned int max_cpus); |
Glauber Costa | 71d1954 | 2008-03-03 14:12:36 -0300 | [diff] [blame] | 153 | int native_cpu_up(unsigned int cpunum); |
Alex Nixon | 93be71b | 2008-08-22 11:52:11 +0100 | [diff] [blame] | 154 | int native_cpu_disable(void); |
| 155 | void native_cpu_die(unsigned int cpu); |
| 156 | void native_play_dead(void); |
Alex Nixon | a21f5d8 | 2008-08-22 11:52:13 +0100 | [diff] [blame] | 157 | void play_dead_common(void); |
Alex Nixon | 93be71b | 2008-08-22 11:52:11 +0100 | [diff] [blame] | 158 | |
Mike Travis | bcda016 | 2008-12-16 17:33:59 -0800 | [diff] [blame] | 159 | void native_send_call_func_ipi(const struct cpumask *mask); |
Jens Axboe | 3b16cf8 | 2008-06-26 11:21:54 +0200 | [diff] [blame] | 160 | void native_send_call_func_single_ipi(int cpu); |
Glauber Costa | 93b016f | 2008-03-03 14:12:40 -0300 | [diff] [blame] | 161 | |
Glauber de Oliveira Costa | 1d89a7f | 2008-03-19 14:25:05 -0300 | [diff] [blame] | 162 | void smp_store_cpu_info(int id); |
Glauber de Oliveira Costa | c70dcb7 | 2008-03-19 14:25:58 -0300 | [diff] [blame] | 163 | #define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu) |
Glauber Costa | a9c057c | 2008-03-27 14:06:02 -0300 | [diff] [blame] | 164 | |
| 165 | /* We don't mark CPUs online until __cpu_up(), so we need another measure */ |
| 166 | static inline int num_booting_cpus(void) |
| 167 | { |
Mike Travis | c2d1cec | 2009-01-04 05:18:03 -0800 | [diff] [blame] | 168 | return cpumask_weight(cpu_callout_mask); |
Glauber Costa | a9c057c | 2008-03-27 14:06:02 -0300 | [diff] [blame] | 169 | } |
Chuck Ebbert | 14adf85 | 2008-09-29 18:29:42 -0400 | [diff] [blame] | 170 | #endif /* CONFIG_SMP */ |
Glauber Costa | a9c057c | 2008-03-27 14:06:02 -0300 | [diff] [blame] | 171 | |
Alexey Starikovskiy | 2fe6014 | 2008-04-04 23:41:44 +0400 | [diff] [blame] | 172 | extern unsigned disabled_cpus __cpuinitdata; |
| 173 | |
Glauber Costa | a9c057c | 2008-03-27 14:06:02 -0300 | [diff] [blame] | 174 | #ifdef CONFIG_X86_32_SMP |
| 175 | /* |
| 176 | * This function is needed by all SMP systems. It must _always_ be valid |
| 177 | * from the initial startup. We map APIC_BASE very early in page_setup(), |
| 178 | * so this is correct in the x86 case. |
| 179 | */ |
Glauber Costa | a9c057c | 2008-03-27 14:06:02 -0300 | [diff] [blame] | 180 | #define raw_smp_processor_id() (x86_read_percpu(cpu_number)) |
| 181 | extern int safe_smp_processor_id(void); |
| 182 | |
| 183 | #elif defined(CONFIG_X86_64_SMP) |
| 184 | #define raw_smp_processor_id() read_pda(cpunumber) |
| 185 | |
| 186 | #define stack_smp_processor_id() \ |
| 187 | ({ \ |
| 188 | struct thread_info *ti; \ |
| 189 | __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \ |
| 190 | ti->cpu; \ |
| 191 | }) |
| 192 | #define safe_smp_processor_id() smp_processor_id() |
| 193 | |
Glauber Costa | c76cb36 | 2008-03-03 14:12:33 -0300 | [diff] [blame] | 194 | #endif |
Glauber Costa | 1669402 | 2008-03-03 14:12:32 -0300 | [diff] [blame] | 195 | |
Glauber Costa | 1b00084 | 2008-03-27 14:05:58 -0300 | [diff] [blame] | 196 | #ifdef CONFIG_X86_LOCAL_APIC |
| 197 | |
Suresh Siddha | 1b374e4 | 2008-07-10 11:16:49 -0700 | [diff] [blame] | 198 | #ifndef CONFIG_X86_64 |
Glauber Costa | 1b00084 | 2008-03-27 14:05:58 -0300 | [diff] [blame] | 199 | static inline int logical_smp_processor_id(void) |
| 200 | { |
| 201 | /* we don't want to mark this access volatile - bad code generation */ |
| 202 | return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR)); |
| 203 | } |
| 204 | |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 205 | #include <mach_apicdef.h> |
Jack Steiner | 05f2d12 | 2008-03-28 14:12:02 -0500 | [diff] [blame] | 206 | static inline unsigned int read_apic_id(void) |
| 207 | { |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 208 | unsigned int reg; |
| 209 | |
| 210 | reg = *(u32 *)(APIC_BASE + APIC_ID); |
| 211 | |
| 212 | return GET_APIC_ID(reg); |
Jack Steiner | 05f2d12 | 2008-03-28 14:12:02 -0500 | [diff] [blame] | 213 | } |
Jack Steiner | ac23d4e | 2008-03-28 14:12:16 -0500 | [diff] [blame] | 214 | #endif |
| 215 | |
Jack Steiner | 05f2d12 | 2008-03-28 14:12:02 -0500 | [diff] [blame] | 216 | |
Suresh Siddha | 0c81c74 | 2008-07-10 11:16:48 -0700 | [diff] [blame] | 217 | # if defined(APIC_DEFINITION) || defined(CONFIG_X86_64) |
Glauber Costa | 1b00084 | 2008-03-27 14:05:58 -0300 | [diff] [blame] | 218 | extern int hard_smp_processor_id(void); |
| 219 | # else |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 220 | #include <mach_apicdef.h> |
Glauber Costa | 1b00084 | 2008-03-27 14:05:58 -0300 | [diff] [blame] | 221 | static inline int hard_smp_processor_id(void) |
| 222 | { |
| 223 | /* we don't want to mark this access volatile - bad code generation */ |
Yinghai Lu | 4c9961d | 2008-07-11 18:44:16 -0700 | [diff] [blame] | 224 | return read_apic_id(); |
Glauber Costa | 1b00084 | 2008-03-27 14:05:58 -0300 | [diff] [blame] | 225 | } |
| 226 | # endif /* APIC_DEFINITION */ |
| 227 | |
| 228 | #else /* CONFIG_X86_LOCAL_APIC */ |
| 229 | |
| 230 | # ifndef CONFIG_SMP |
| 231 | # define hard_smp_processor_id() 0 |
| 232 | # endif |
| 233 | |
| 234 | #endif /* CONFIG_X86_LOCAL_APIC */ |
| 235 | |
Glauber Costa | c27cfef | 2008-03-03 14:12:29 -0300 | [diff] [blame] | 236 | #endif /* __ASSEMBLY__ */ |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 237 | #endif /* _ASM_X86_SMP_H */ |