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