Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #ifndef __ASM_SMP_H |
| 2 | #define __ASM_SMP_H |
| 3 | |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 4 | #ifndef __ASSEMBLY__ |
| 5 | #include <linux/cpumask.h> |
| 6 | #include <linux/init.h> |
| 7 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | /* |
| 9 | * We need the APIC definitions automatically as part of 'smp.h' |
| 10 | */ |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #endif |
| 18 | |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 19 | extern cpumask_t cpu_callout_map; |
| 20 | extern cpumask_t cpu_callin_map; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | extern int smp_num_siblings; |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 23 | extern unsigned int num_processors; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 25 | extern void smp_alloc_memory(void); |
Li Shaohua | 6fe940d | 2005-06-25 14:54:53 -0700 | [diff] [blame] | 26 | extern void lock_ipi_call_lock(void); |
| 27 | extern void unlock_ipi_call_lock(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 29 | extern void (*mtrr_hook) (void); |
| 30 | extern void zap_low_mappings (void); |
| 31 | |
Mike Travis | 71fff5e | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 32 | extern u8 __initdata x86_cpu_to_apicid_init[]; |
travis@sgi.com | 3b41908 | 2008-01-30 13:33:11 +0100 | [diff] [blame] | 33 | extern void *x86_cpu_to_apicid_early_ptr; |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 34 | |
| 35 | DECLARE_PER_CPU(cpumask_t, cpu_sibling_map); |
| 36 | DECLARE_PER_CPU(cpumask_t, cpu_core_map); |
| 37 | DECLARE_PER_CPU(u8, cpu_llc_id); |
Mike Travis | 71fff5e | 2007-10-19 20:35:03 +0200 | [diff] [blame] | 38 | DECLARE_PER_CPU(u8, x86_cpu_to_apicid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 40 | #ifdef CONFIG_HOTPLUG_CPU |
| 41 | extern void cpu_exit_clear(void); |
| 42 | extern void cpu_uninit(void); |
Jeremy Fitzhardinge | c70df74 | 2007-07-17 18:37:03 -0700 | [diff] [blame] | 43 | extern void remove_siblinginfo(int cpu); |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 44 | #endif |
| 45 | |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 46 | /* Globals due to paravirt */ |
| 47 | extern void set_cpu_sibling_map(int cpu); |
| 48 | |
Jeremy Fitzhardinge | 01a2f43 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 49 | struct smp_ops |
| 50 | { |
| 51 | void (*smp_prepare_boot_cpu)(void); |
| 52 | void (*smp_prepare_cpus)(unsigned max_cpus); |
| 53 | int (*cpu_up)(unsigned cpu); |
| 54 | void (*smp_cpus_done)(unsigned max_cpus); |
| 55 | |
| 56 | void (*smp_send_stop)(void); |
| 57 | void (*smp_send_reschedule)(int cpu); |
| 58 | int (*smp_call_function_mask)(cpumask_t mask, |
| 59 | void (*func)(void *info), void *info, |
| 60 | int wait); |
| 61 | }; |
| 62 | |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 63 | #ifdef CONFIG_SMP |
Jeremy Fitzhardinge | 01a2f43 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 64 | extern struct smp_ops smp_ops; |
| 65 | |
| 66 | static inline void smp_prepare_boot_cpu(void) |
| 67 | { |
| 68 | smp_ops.smp_prepare_boot_cpu(); |
| 69 | } |
| 70 | static inline void smp_prepare_cpus(unsigned int max_cpus) |
| 71 | { |
| 72 | smp_ops.smp_prepare_cpus(max_cpus); |
| 73 | } |
| 74 | static inline int __cpu_up(unsigned int cpu) |
| 75 | { |
| 76 | return smp_ops.cpu_up(cpu); |
| 77 | } |
| 78 | static inline void smp_cpus_done(unsigned int max_cpus) |
| 79 | { |
| 80 | smp_ops.smp_cpus_done(max_cpus); |
| 81 | } |
| 82 | |
| 83 | static inline void smp_send_stop(void) |
| 84 | { |
| 85 | smp_ops.smp_send_stop(); |
| 86 | } |
| 87 | static inline void smp_send_reschedule(int cpu) |
| 88 | { |
| 89 | smp_ops.smp_send_reschedule(cpu); |
| 90 | } |
Thomas Gleixner | ceff8d8 | 2007-10-26 17:22:17 +0200 | [diff] [blame] | 91 | static inline int smp_call_function_mask(cpumask_t mask, |
| 92 | void (*func) (void *info), void *info, |
| 93 | int wait) |
| 94 | { |
| 95 | return smp_ops.smp_call_function_mask(mask, func, info, wait); |
| 96 | } |
Jeremy Fitzhardinge | 01a2f43 | 2007-05-02 19:27:11 +0200 | [diff] [blame] | 97 | |
| 98 | void native_smp_prepare_boot_cpu(void); |
| 99 | void native_smp_prepare_cpus(unsigned int max_cpus); |
| 100 | int native_cpu_up(unsigned int cpunum); |
| 101 | void native_smp_cpus_done(unsigned int max_cpus); |
| 102 | |
Zachary Amsden | ae5da27 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 103 | #ifndef CONFIG_PARAVIRT |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 104 | #define startup_ipi_hook(phys_apicid, start_eip, start_esp) do { } while (0) |
Zachary Amsden | ae5da27 | 2007-02-13 13:26:21 +0100 | [diff] [blame] | 105 | #endif |
| 106 | |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 107 | extern int __cpu_disable(void); |
| 108 | extern void __cpu_die(unsigned int cpu); |
| 109 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 110 | /* |
| 111 | * This function is needed by all SMP systems. It must _always_ be valid |
| 112 | * from the initial startup. We map APIC_BASE very early in page_setup(), |
| 113 | * so this is correct in the x86 case. |
| 114 | */ |
Jeremy Fitzhardinge | 7c3576d | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 115 | DECLARE_PER_CPU(int, cpu_number); |
| 116 | #define raw_smp_processor_id() (x86_read_percpu(cpu_number)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 118 | #define cpu_physical_id(cpu) per_cpu(x86_cpu_to_apicid, cpu) |
| 119 | |
| 120 | extern int safe_smp_processor_id(void); |
| 121 | |
| 122 | void __cpuinit smp_store_cpu_info(int id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | |
| 124 | /* We don't mark CPUs online until __cpu_up(), so we need another measure */ |
| 125 | static inline int num_booting_cpus(void) |
| 126 | { |
| 127 | return cpus_weight(cpu_callout_map); |
| 128 | } |
| 129 | |
Fernando Luis Vazquez Cao | a36166c | 2007-05-09 02:33:27 -0700 | [diff] [blame] | 130 | #else /* CONFIG_SMP */ |
| 131 | |
| 132 | #define safe_smp_processor_id() 0 |
| 133 | #define cpu_physical_id(cpu) boot_cpu_physical_apicid |
| 134 | |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 135 | #endif /* !CONFIG_SMP */ |
Fernando Luis Vazquez Cao | a36166c | 2007-05-09 02:33:27 -0700 | [diff] [blame] | 136 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | #ifdef CONFIG_X86_LOCAL_APIC |
| 138 | |
Andi Kleen | 874c4fe | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 139 | static __inline int logical_smp_processor_id(void) |
| 140 | { |
| 141 | /* we don't want to mark this access volatile - bad code generation */ |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 142 | return GET_APIC_LOGICAL_ID(*(u32 *)(APIC_BASE + APIC_LDR)); |
Andi Kleen | 874c4fe | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 143 | } |
Andi Kleen | 874c4fe | 2006-09-26 10:52:26 +0200 | [diff] [blame] | 144 | |
Thomas Gleixner | ae9d983 | 2008-01-30 13:30:36 +0100 | [diff] [blame] | 145 | # ifdef APIC_DEFINITION |
| 146 | extern int hard_smp_processor_id(void); |
| 147 | # else |
| 148 | # include <mach_apicdef.h> |
| 149 | static inline int hard_smp_processor_id(void) |
| 150 | { |
| 151 | /* we don't want to mark this access volatile - bad code generation */ |
| 152 | return GET_APIC_ID(*(u32 *)(APIC_BASE + APIC_ID)); |
| 153 | } |
| 154 | # endif /* APIC_DEFINITION */ |
| 155 | |
| 156 | #else /* CONFIG_X86_LOCAL_APIC */ |
| 157 | |
| 158 | # ifndef CONFIG_SMP |
| 159 | # define hard_smp_processor_id() 0 |
| 160 | # endif |
| 161 | |
| 162 | #endif /* CONFIG_X86_LOCAL_APIC */ |
| 163 | |
| 164 | #endif /* !ASSEMBLY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | #endif |