aboutsummaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorGlauber de Oliveira Costa <gcosta@redhat.com>2008-03-19 13:26:11 -0400
committerIngo Molnar <mingo@elte.hu>2008-04-17 11:41:04 -0400
commit8aef135c73436fa46fdb4dc8aba49d5539dee72d (patch)
treed733efeff177fc41ccf110dfb1d805b81518f8ef /arch
parent9f3734f631267d2f36008833b62670ca342ac000 (diff)
x86: merge native_smp_prepare_cpus
With the previous changes, code for native_smp_prepare_cpus() in i386 and x86_64 now look very similar. merge them into smpboot.c. Minor differences are inside ifdef Signed-off-by: Glauber Costa <gcosta@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'arch')
-rw-r--r--arch/x86/kernel/smpboot.c170
-rw-r--r--arch/x86/kernel/smpboot_32.c137
-rw-r--r--arch/x86/kernel/smpboot_64.c141
3 files changed, 170 insertions, 278 deletions
diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
index 26118b4a1c38..45119d39f31e 100644
--- a/arch/x86/kernel/smpboot.c
+++ b/arch/x86/kernel/smpboot.c
@@ -7,6 +7,7 @@
7#include <linux/err.h> 7#include <linux/err.h>
8#include <linux/nmi.h> 8#include <linux/nmi.h>
9 9
10#include <asm/acpi.h>
10#include <asm/desc.h> 11#include <asm/desc.h>
11#include <asm/nmi.h> 12#include <asm/nmi.h>
12#include <asm/irq.h> 13#include <asm/irq.h>
@@ -75,6 +76,8 @@ EXPORT_PER_CPU_SYMBOL(cpu_info);
75 76
76static atomic_t init_deasserted; 77static atomic_t init_deasserted;
77 78
79static int boot_cpu_logical_apicid;
80
78/* ready for x86_64, no harm for x86, since it will overwrite after alloc */ 81/* ready for x86_64, no harm for x86, since it will overwrite after alloc */
79unsigned char *trampoline_base = __va(SMP_TRAMPOLINE_BASE); 82unsigned char *trampoline_base = __va(SMP_TRAMPOLINE_BASE);
80 83
@@ -1002,6 +1005,173 @@ int __cpuinit native_cpu_up(unsigned int cpu)
1002} 1005}
1003 1006
1004/* 1007/*
1008 * Fall back to non SMP mode after errors.
1009 *
1010 * RED-PEN audit/test this more. I bet there is more state messed up here.
1011 */
1012static __init void disable_smp(void)
1013{
1014 cpu_present_map = cpumask_of_cpu(0);
1015 cpu_possible_map = cpumask_of_cpu(0);
1016#ifdef CONFIG_X86_32
1017 smpboot_clear_io_apic_irqs();
1018#endif
1019 if (smp_found_config)
1020 phys_cpu_present_map =
1021 physid_mask_of_physid(boot_cpu_physical_apicid);
1022 else
1023 phys_cpu_present_map = physid_mask_of_physid(0);
1024 map_cpu_to_logical_apicid();
1025 cpu_set(0, per_cpu(cpu_sibling_map, 0));
1026 cpu_set(0, per_cpu(cpu_core_map, 0));
1027}
1028
1029/*
1030 * Various sanity checks.
1031 */
1032static int __init smp_sanity_check(unsigned max_cpus)
1033{
1034 if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) {
1035 printk(KERN_WARNING "weird, boot CPU (#%d) not listed"
1036 "by the BIOS.\n", hard_smp_processor_id());
1037 physid_set(hard_smp_processor_id(), phys_cpu_present_map);
1038 }
1039
1040 /*
1041 * If we couldn't find an SMP configuration at boot time,
1042 * get out of here now!
1043 */
1044 if (!smp_found_config && !acpi_lapic) {
1045 printk(KERN_NOTICE "SMP motherboard not detected.\n");
1046 disable_smp();
1047 if (APIC_init_uniprocessor())
1048 printk(KERN_NOTICE "Local APIC not detected."
1049 " Using dummy APIC emulation.\n");
1050 return -1;
1051 }
1052
1053 /*
1054 * Should not be necessary because the MP table should list the boot
1055 * CPU too, but we do it for the sake of robustness anyway.
1056 */
1057 if (!check_phys_apicid_present(boot_cpu_physical_apicid)) {
1058 printk(KERN_NOTICE
1059 "weird, boot CPU (#%d) not listed by the BIOS.\n",
1060 boot_cpu_physical_apicid);
1061 physid_set(hard_smp_processor_id(), phys_cpu_present_map);
1062 }
1063
1064 /*
1065 * If we couldn't find a local APIC, then get out of here now!
1066 */
1067 if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid]) &&
1068 !cpu_has_apic) {
1069 printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
1070 boot_cpu_physical_apicid);
1071 printk(KERN_ERR "... forcing use of dummy APIC emulation."
1072 "(tell your hw vendor)\n");
1073 smpboot_clear_io_apic();
1074 return -1;
1075 }
1076
1077 verify_local_APIC();
1078
1079 /*
1080 * If SMP should be disabled, then really disable it!
1081 */
1082 if (!max_cpus) {
1083 printk(KERN_INFO "SMP mode deactivated,"
1084 "forcing use of dummy APIC emulation.\n");
1085 smpboot_clear_io_apic();
1086#ifdef CONFIG_X86_32
1087 if (nmi_watchdog == NMI_LOCAL_APIC) {
1088 printk(KERN_INFO "activating minimal APIC for"
1089 "NMI watchdog use.\n");
1090 connect_bsp_APIC();
1091 setup_local_APIC();
1092 end_local_APIC_setup();
1093 }
1094#endif
1095 return -1;
1096 }
1097
1098 return 0;
1099}
1100
1101static void __init smp_cpu_index_default(void)
1102{
1103 int i;
1104 struct cpuinfo_x86 *c;
1105
1106 for_each_cpu_mask(i, cpu_possible_map) {
1107 c = &cpu_data(i);
1108 /* mark all to hotplug */
1109 c->cpu_index = NR_CPUS;
1110 }
1111}
1112
1113/*
1114 * Prepare for SMP bootup. The MP table or ACPI has been read
1115 * earlier. Just do some sanity checking here and enable APIC mode.
1116 */
1117void __init native_smp_prepare_cpus(unsigned int max_cpus)
1118{
1119 nmi_watchdog_default();
1120 smp_cpu_index_default();
1121 current_cpu_data = boot_cpu_data;
1122 cpu_callin_map = cpumask_of_cpu(0);
1123 mb();
1124 /*
1125 * Setup boot CPU information
1126 */
1127 smp_store_cpu_info(0); /* Final full version of the data */
1128 boot_cpu_logical_apicid = logical_smp_processor_id();
1129 current_thread_info()->cpu = 0; /* needed? */
1130 set_cpu_sibling_map(0);
1131
1132 if (smp_sanity_check(max_cpus) < 0) {
1133 printk(KERN_INFO "SMP disabled\n");
1134 disable_smp();
1135 return;
1136 }
1137
1138 if (GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_physical_apicid) {
1139 panic("Boot APIC ID in local APIC unexpected (%d vs %d)",
1140 GET_APIC_ID(apic_read(APIC_ID)), boot_cpu_physical_apicid);
1141 /* Or can we switch back to PIC here? */
1142 }
1143
1144#ifdef CONFIG_X86_32
1145 connect_bsp_APIC();
1146#endif
1147 /*
1148 * Switch from PIC to APIC mode.
1149 */
1150 setup_local_APIC();
1151
1152#ifdef CONFIG_X86_64
1153 /*
1154 * Enable IO APIC before setting up error vector
1155 */
1156 if (!skip_ioapic_setup && nr_ioapics)
1157 enable_IO_APIC();
1158#endif
1159 end_local_APIC_setup();
1160
1161 map_cpu_to_logical_apicid();
1162
1163 setup_portio_remap();
1164
1165 smpboot_setup_io_apic();
1166 /*
1167 * Set up local APIC timer on boot CPU.
1168 */
1169
1170 printk(KERN_INFO "CPU%d: ", 0);
1171 print_cpu_info(&cpu_data(0));
1172 setup_boot_clock();
1173}
1174/*
1005 * Early setup to make printk work. 1175 * Early setup to make printk work.
1006 */ 1176 */
1007void __init native_smp_prepare_boot_cpu(void) 1177void __init native_smp_prepare_boot_cpu(void)
diff --git a/arch/x86/kernel/smpboot_32.c b/arch/x86/kernel/smpboot_32.c
index 5a0f57f35191..3a1b9e40cedb 100644
--- a/arch/x86/kernel/smpboot_32.c
+++ b/arch/x86/kernel/smpboot_32.c
@@ -74,7 +74,6 @@ EXPORT_PER_CPU_SYMBOL(x86_bios_cpu_apicid);
74 74
75u8 apicid_2_node[MAX_APICID]; 75u8 apicid_2_node[MAX_APICID];
76 76
77extern void map_cpu_to_logical_apicid(void);
78extern void unmap_cpu_to_logical_apicid(int cpu); 77extern void unmap_cpu_to_logical_apicid(int cpu);
79 78
80#ifdef CONFIG_HOTPLUG_CPU 79#ifdef CONFIG_HOTPLUG_CPU
@@ -94,144 +93,8 @@ void cpu_exit_clear(void)
94} 93}
95#endif 94#endif
96 95
97static int boot_cpu_logical_apicid;
98/* Where the IO area was mapped on multiquad, always 0 otherwise */ 96/* Where the IO area was mapped on multiquad, always 0 otherwise */
99void *xquad_portio; 97void *xquad_portio;
100#ifdef CONFIG_X86_NUMAQ 98#ifdef CONFIG_X86_NUMAQ
101EXPORT_SYMBOL(xquad_portio); 99EXPORT_SYMBOL(xquad_portio);
102#endif 100#endif
103
104static void __init disable_smp(void)
105{
106 cpu_possible_map = cpumask_of_cpu(0);
107 cpu_present_map = cpumask_of_cpu(0);
108 smpboot_clear_io_apic_irqs();
109 if (smp_found_config)
110 phys_cpu_present_map =
111 physid_mask_of_physid(boot_cpu_physical_apicid);
112 else
113 phys_cpu_present_map = physid_mask_of_physid(0);
114 map_cpu_to_logical_apicid();
115 cpu_set(0, per_cpu(cpu_sibling_map, 0));
116 cpu_set(0, per_cpu(cpu_core_map, 0));
117}
118
119static int __init smp_sanity_check(unsigned max_cpus)
120{
121 if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) {
122 printk(KERN_WARNING "weird, boot CPU (#%d) not listed"
123 "by the BIOS.\n", hard_smp_processor_id());
124 physid_set(hard_smp_processor_id(), phys_cpu_present_map);
125 }
126
127 /*
128 * If we couldn't find an SMP configuration at boot time,
129 * get out of here now!
130 */
131 if (!smp_found_config && !acpi_lapic) {
132 printk(KERN_NOTICE "SMP motherboard not detected.\n");
133 disable_smp();
134 if (APIC_init_uniprocessor())
135 printk(KERN_NOTICE "Local APIC not detected."
136 " Using dummy APIC emulation.\n");
137 return -1;
138 }
139
140 /*
141 * Should not be necessary because the MP table should list the boot
142 * CPU too, but we do it for the sake of robustness anyway.
143 * Makes no sense to do this check in clustered apic mode, so skip it
144 */
145 if (!check_phys_apicid_present(boot_cpu_physical_apicid)) {
146 printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
147 boot_cpu_physical_apicid);
148 physid_set(hard_smp_processor_id(), phys_cpu_present_map);
149 }
150
151 /*
152 * If we couldn't find a local APIC, then get out of here now!
153 */
154 if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid]) && !cpu_has_apic) {
155 printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
156 boot_cpu_physical_apicid);
157 printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
158 smpboot_clear_io_apic();
159 return -1;
160 }
161
162 verify_local_APIC();
163
164 /*
165 * If SMP should be disabled, then really disable it!
166 */
167 if (!max_cpus) {
168 smp_found_config = 0;
169 printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
170
171 if (nmi_watchdog == NMI_LOCAL_APIC) {
172 printk(KERN_INFO "activating minimal APIC for NMI watchdog use.\n");
173 connect_bsp_APIC();
174 setup_local_APIC();
175 end_local_APIC_setup();
176 }
177 smpboot_clear_io_apic();
178 return -1;
179 }
180 return 0;
181}
182
183static void __init smp_cpu_index_default(void)
184{
185 int i;
186 struct cpuinfo_x86 *c;
187
188 for_each_cpu_mask(i, cpu_possible_map) {
189 c = &cpu_data(i);
190 /* mark all to hotplug */
191 c->cpu_index = NR_CPUS;
192 }
193}
194
195void __init native_smp_prepare_cpus(unsigned int max_cpus)
196{
197 nmi_watchdog_default();
198 smp_cpu_index_default();
199 current_cpu_data = boot_cpu_data;
200 cpu_callin_map = cpumask_of_cpu(0);
201 mb();
202
203 /*
204 * Setup boot CPU information
205 */
206 smp_store_cpu_info(0); /* Final full version of the data */
207 boot_cpu_logical_apicid = logical_smp_processor_id();
208 current_thread_info()->cpu = 0;
209
210 set_cpu_sibling_map(0);
211
212 if (smp_sanity_check(max_cpus) < 0) {
213 printk(KERN_INFO "SMP disabled\n");
214 disable_smp();
215 return;
216 }
217
218 if (GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_physical_apicid) {
219 panic("Boot APIC ID in local APIC unexpected (%d vs %d)",
220 GET_APIC_ID(apic_read(APIC_ID)), boot_cpu_physical_apicid);
221 /* Or can we switch back to PIC here? */
222 }
223
224 connect_bsp_APIC();
225 setup_local_APIC();
226 end_local_APIC_setup();
227 map_cpu_to_logical_apicid();
228
229 setup_portio_remap();
230
231 smpboot_setup_io_apic();
232
233 printk(KERN_INFO "CPU%d: ", 0);
234 print_cpu_info(&cpu_data(0));
235 setup_boot_clock();
236}
237
diff --git a/arch/x86/kernel/smpboot_64.c b/arch/x86/kernel/smpboot_64.c
index 775244545ffa..66b55629733b 100644
--- a/arch/x86/kernel/smpboot_64.c
+++ b/arch/x86/kernel/smpboot_64.c
@@ -71,144 +71,3 @@ int smp_threads_ready;
71 71
72cycles_t cacheflush_time; 72cycles_t cacheflush_time;
73unsigned long cache_decay_ticks; 73unsigned long cache_decay_ticks;
74
75static int boot_cpu_logical_apicid;
76/*
77 * Fall back to non SMP mode after errors.
78 *
79 * RED-PEN audit/test this more. I bet there is more state messed up here.
80 */
81static __init void disable_smp(void)
82{
83 cpu_present_map = cpumask_of_cpu(0);
84 cpu_possible_map = cpumask_of_cpu(0);
85 if (smp_found_config)
86 phys_cpu_present_map =
87 physid_mask_of_physid(boot_cpu_physical_apicid);
88 else
89 phys_cpu_present_map = physid_mask_of_physid(0);
90 cpu_set(0, per_cpu(cpu_sibling_map, 0));
91 cpu_set(0, per_cpu(cpu_core_map, 0));
92}
93
94/*
95 * Various sanity checks.
96 */
97static int __init smp_sanity_check(unsigned max_cpus)
98{
99 if (!physid_isset(hard_smp_processor_id(), phys_cpu_present_map)) {
100 printk("weird, boot CPU (#%d) not listed by the BIOS.\n",
101 hard_smp_processor_id());
102 physid_set(hard_smp_processor_id(), phys_cpu_present_map);
103 }
104
105 /*
106 * If we couldn't find an SMP configuration at boot time,
107 * get out of here now!
108 */
109 if (!smp_found_config && !acpi_lapic) {
110 printk(KERN_NOTICE "SMP motherboard not detected.\n");
111 disable_smp();
112 if (APIC_init_uniprocessor())
113 printk(KERN_NOTICE "Local APIC not detected."
114 " Using dummy APIC emulation.\n");
115 return -1;
116 }
117
118 /*
119 * Should not be necessary because the MP table should list the boot
120 * CPU too, but we do it for the sake of robustness anyway.
121 */
122 if (!check_phys_apicid_present(boot_cpu_physical_apicid)) {
123 printk(KERN_NOTICE
124 "weird, boot CPU (#%d) not listed by the BIOS.\n",
125 boot_cpu_physical_apicid);
126 physid_set(hard_smp_processor_id(), phys_cpu_present_map);
127 }
128
129 /*
130 * If we couldn't find a local APIC, then get out of here now!
131 */
132 if (APIC_INTEGRATED(apic_version[boot_cpu_physical_apicid]) &&
133 !cpu_has_apic) {
134 printk(KERN_ERR "BIOS bug, local APIC #%d not detected!...\n",
135 boot_cpu_physical_apicid);
136 printk(KERN_ERR "... forcing use of dummy APIC emulation. (tell your hw vendor)\n");
137 smpboot_clear_io_apic();
138 return -1;
139 }
140
141 verify_local_APIC();
142
143 /*
144 * If SMP should be disabled, then really disable it!
145 */
146 if (!max_cpus) {
147 printk(KERN_INFO "SMP mode deactivated, forcing use of dummy APIC emulation.\n");
148 smpboot_clear_io_apic();
149 return -1;
150 }
151
152 return 0;
153}
154
155static void __init smp_cpu_index_default(void)
156{
157 int i;
158 struct cpuinfo_x86 *c;
159
160 for_each_cpu_mask(i, cpu_possible_map) {
161 c = &cpu_data(i);
162 /* mark all to hotplug */
163 c->cpu_index = NR_CPUS;
164 }
165}
166
167/*
168 * Prepare for SMP bootup. The MP table or ACPI has been read
169 * earlier. Just do some sanity checking here and enable APIC mode.
170 */
171void __init native_smp_prepare_cpus(unsigned int max_cpus)
172{
173 nmi_watchdog_default();
174 smp_cpu_index_default();
175 cpu_callin_map = cpumask_of_cpu(0);
176 mb();
177
178 current_cpu_data = boot_cpu_data;
179 boot_cpu_logical_apicid = logical_smp_processor_id();
180 current_thread_info()->cpu = 0; /* needed? */
181 set_cpu_sibling_map(0);
182
183 if (smp_sanity_check(max_cpus) < 0) {
184 printk(KERN_INFO "SMP disabled\n");
185 disable_smp();
186 return;
187 }
188
189 if (GET_APIC_ID(apic_read(APIC_ID)) != boot_cpu_physical_apicid) {
190 panic("Boot APIC ID in local APIC unexpected (%d vs %d)",
191 GET_APIC_ID(apic_read(APIC_ID)), boot_cpu_physical_apicid);
192 /* Or can we switch back to PIC here? */
193 }
194
195 /*
196 * Switch from PIC to APIC mode.
197 */
198 setup_local_APIC();
199
200 /*
201 * Enable IO APIC before setting up error vector
202 */
203 if (!skip_ioapic_setup && nr_ioapics)
204 enable_IO_APIC();
205 end_local_APIC_setup();
206
207 /*
208 * Set up local APIC timer on boot CPU.
209 */
210
211 setup_boot_clock();
212 printk(KERN_INFO "CPU%d: ", 0);
213 print_cpu_info(&cpu_data(0));
214}