1 #ifndef __ASM_ES7000_APIC_H |
1 #ifndef __ASM_ES7000_APIC_H |
2 #define __ASM_ES7000_APIC_H |
2 #define __ASM_ES7000_APIC_H |
3 |
3 |
|
4 #include <linux/gfp.h> |
|
5 |
4 #define xapic_phys_to_log_apicid(cpu) per_cpu(x86_bios_cpu_apicid, cpu) |
6 #define xapic_phys_to_log_apicid(cpu) per_cpu(x86_bios_cpu_apicid, cpu) |
5 #define esr_disable (1) |
7 #define esr_disable (1) |
6 |
8 |
7 static inline int apic_id_registered(void) |
9 static inline int apic_id_registered(void) |
8 { |
10 { |
9 return (1); |
11 return (1); |
10 } |
12 } |
11 |
13 |
12 static inline cpumask_t target_cpus(void) |
14 static inline const cpumask_t *target_cpus_cluster(void) |
13 { |
15 { |
14 #if defined CONFIG_ES7000_CLUSTERED_APIC |
16 return &CPU_MASK_ALL; |
15 return CPU_MASK_ALL; |
17 } |
16 #else |
18 |
17 return cpumask_of_cpu(smp_processor_id()); |
19 static inline const cpumask_t *target_cpus(void) |
18 #endif |
20 { |
19 } |
21 return &cpumask_of_cpu(smp_processor_id()); |
20 |
22 } |
21 #if defined CONFIG_ES7000_CLUSTERED_APIC |
23 |
22 #define APIC_DFR_VALUE (APIC_DFR_CLUSTER) |
24 #define APIC_DFR_VALUE_CLUSTER (APIC_DFR_CLUSTER) |
23 #define INT_DELIVERY_MODE (dest_LowestPrio) |
25 #define INT_DELIVERY_MODE_CLUSTER (dest_LowestPrio) |
24 #define INT_DEST_MODE (1) /* logical delivery broadcast to all procs */ |
26 #define INT_DEST_MODE_CLUSTER (1) /* logical delivery broadcast to all procs */ |
25 #define NO_BALANCE_IRQ (1) |
27 #define NO_BALANCE_IRQ_CLUSTER (1) |
26 #undef WAKE_SECONDARY_VIA_INIT |
28 |
27 #define WAKE_SECONDARY_VIA_MIP |
|
28 #else |
|
29 #define APIC_DFR_VALUE (APIC_DFR_FLAT) |
29 #define APIC_DFR_VALUE (APIC_DFR_FLAT) |
30 #define INT_DELIVERY_MODE (dest_Fixed) |
30 #define INT_DELIVERY_MODE (dest_Fixed) |
31 #define INT_DEST_MODE (0) /* phys delivery to target procs */ |
31 #define INT_DEST_MODE (0) /* phys delivery to target procs */ |
32 #define NO_BALANCE_IRQ (0) |
32 #define NO_BALANCE_IRQ (0) |
33 #undef APIC_DEST_LOGICAL |
33 #undef APIC_DEST_LOGICAL |
34 #define APIC_DEST_LOGICAL 0x0 |
34 #define APIC_DEST_LOGICAL 0x0 |
35 #define WAKE_SECONDARY_VIA_INIT |
|
36 #endif |
|
37 |
35 |
38 static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid) |
36 static inline unsigned long check_apicid_used(physid_mask_t bitmap, int apicid) |
39 { |
37 { |
40 return 0; |
38 return 0; |
41 } |
39 } |
58 * |
56 * |
59 * Intel recommends to set DFR, LdR and TPR before enabling |
57 * Intel recommends to set DFR, LdR and TPR before enabling |
60 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel |
58 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel |
61 * document number 292116). So here it goes... |
59 * document number 292116). So here it goes... |
62 */ |
60 */ |
|
61 static inline void init_apic_ldr_cluster(void) |
|
62 { |
|
63 unsigned long val; |
|
64 int cpu = smp_processor_id(); |
|
65 |
|
66 apic_write(APIC_DFR, APIC_DFR_VALUE_CLUSTER); |
|
67 val = calculate_ldr(cpu); |
|
68 apic_write(APIC_LDR, val); |
|
69 } |
|
70 |
63 static inline void init_apic_ldr(void) |
71 static inline void init_apic_ldr(void) |
64 { |
72 { |
65 unsigned long val; |
73 unsigned long val; |
66 int cpu = smp_processor_id(); |
74 int cpu = smp_processor_id(); |
67 |
75 |
68 apic_write(APIC_DFR, APIC_DFR_VALUE); |
76 apic_write(APIC_DFR, APIC_DFR_VALUE); |
69 val = calculate_ldr(cpu); |
77 val = calculate_ldr(cpu); |
70 apic_write(APIC_LDR, val); |
78 apic_write(APIC_LDR, val); |
71 } |
79 } |
72 |
80 |
73 #ifndef CONFIG_X86_GENERICARCH |
|
74 extern void enable_apic_mode(void); |
|
75 #endif |
|
76 |
|
77 extern int apic_version [MAX_APICS]; |
81 extern int apic_version [MAX_APICS]; |
78 static inline void setup_apic_routing(void) |
82 static inline void setup_apic_routing(void) |
79 { |
83 { |
80 int apic = per_cpu(x86_bios_cpu_apicid, smp_processor_id()); |
84 int apic = per_cpu(x86_bios_cpu_apicid, smp_processor_id()); |
81 printk("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n", |
85 printk("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n", |
82 (apic_version[apic] == 0x14) ? |
86 (apic_version[apic] == 0x14) ? |
83 "Physical Cluster" : "Logical Cluster", nr_ioapics, cpus_addr(target_cpus())[0]); |
87 "Physical Cluster" : "Logical Cluster", |
|
88 nr_ioapics, cpus_addr(*target_cpus())[0]); |
84 } |
89 } |
85 |
90 |
86 static inline int multi_timer_check(int apic, int irq) |
91 static inline int multi_timer_check(int apic, int irq) |
87 { |
92 { |
88 return 0; |
93 return 0; |
142 { |
147 { |
143 boot_cpu_physical_apicid = read_apic_id(); |
148 boot_cpu_physical_apicid = read_apic_id(); |
144 return (1); |
149 return (1); |
145 } |
150 } |
146 |
151 |
147 static inline unsigned int cpu_mask_to_apicid(cpumask_t cpumask) |
152 static inline unsigned int |
|
153 cpu_mask_to_apicid_cluster(const struct cpumask *cpumask) |
148 { |
154 { |
149 int num_bits_set; |
155 int num_bits_set; |
150 int cpus_found = 0; |
156 int cpus_found = 0; |
151 int cpu; |
157 int cpu; |
152 int apicid; |
158 int apicid; |
153 |
159 |
154 num_bits_set = cpus_weight(cpumask); |
160 num_bits_set = cpumask_weight(cpumask); |
155 /* Return id to all */ |
161 /* Return id to all */ |
156 if (num_bits_set == NR_CPUS) |
162 if (num_bits_set == nr_cpu_ids) |
157 #if defined CONFIG_ES7000_CLUSTERED_APIC |
|
158 return 0xFF; |
163 return 0xFF; |
159 #else |
|
160 return cpu_to_logical_apicid(0); |
|
161 #endif |
|
162 /* |
164 /* |
163 * The cpus in the mask must all be on the apic cluster. If are not |
165 * The cpus in the mask must all be on the apic cluster. If are not |
164 * on the same apicid cluster return default value of TARGET_CPUS. |
166 * on the same apicid cluster return default value of TARGET_CPUS. |
165 */ |
167 */ |
166 cpu = first_cpu(cpumask); |
168 cpu = cpumask_first(cpumask); |
167 apicid = cpu_to_logical_apicid(cpu); |
169 apicid = cpu_to_logical_apicid(cpu); |
168 while (cpus_found < num_bits_set) { |
170 while (cpus_found < num_bits_set) { |
169 if (cpu_isset(cpu, cpumask)) { |
171 if (cpumask_test_cpu(cpu, cpumask)) { |
170 int new_apicid = cpu_to_logical_apicid(cpu); |
172 int new_apicid = cpu_to_logical_apicid(cpu); |
171 if (apicid_cluster(apicid) != |
173 if (apicid_cluster(apicid) != |
172 apicid_cluster(new_apicid)){ |
174 apicid_cluster(new_apicid)){ |
173 printk ("%s: Not a valid mask!\n", __func__); |
175 printk ("%s: Not a valid mask!\n", __func__); |
174 #if defined CONFIG_ES7000_CLUSTERED_APIC |
|
175 return 0xFF; |
176 return 0xFF; |
176 #else |
|
177 return cpu_to_logical_apicid(0); |
|
178 #endif |
|
179 } |
177 } |
180 apicid = new_apicid; |
178 apicid = new_apicid; |
181 cpus_found++; |
179 cpus_found++; |
182 } |
180 } |
183 cpu++; |
181 cpu++; |
184 } |
182 } |
185 return apicid; |
183 return apicid; |
186 } |
184 } |
187 |
185 |
|
186 static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask) |
|
187 { |
|
188 int num_bits_set; |
|
189 int cpus_found = 0; |
|
190 int cpu; |
|
191 int apicid; |
|
192 |
|
193 num_bits_set = cpus_weight(*cpumask); |
|
194 /* Return id to all */ |
|
195 if (num_bits_set == nr_cpu_ids) |
|
196 return cpu_to_logical_apicid(0); |
|
197 /* |
|
198 * The cpus in the mask must all be on the apic cluster. If are not |
|
199 * on the same apicid cluster return default value of TARGET_CPUS. |
|
200 */ |
|
201 cpu = first_cpu(*cpumask); |
|
202 apicid = cpu_to_logical_apicid(cpu); |
|
203 while (cpus_found < num_bits_set) { |
|
204 if (cpu_isset(cpu, *cpumask)) { |
|
205 int new_apicid = cpu_to_logical_apicid(cpu); |
|
206 if (apicid_cluster(apicid) != |
|
207 apicid_cluster(new_apicid)){ |
|
208 printk ("%s: Not a valid mask!\n", __func__); |
|
209 return cpu_to_logical_apicid(0); |
|
210 } |
|
211 apicid = new_apicid; |
|
212 cpus_found++; |
|
213 } |
|
214 cpu++; |
|
215 } |
|
216 return apicid; |
|
217 } |
|
218 |
|
219 |
|
220 static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *inmask, |
|
221 const struct cpumask *andmask) |
|
222 { |
|
223 int apicid = cpu_to_logical_apicid(0); |
|
224 cpumask_var_t cpumask; |
|
225 |
|
226 if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC)) |
|
227 return apicid; |
|
228 |
|
229 cpumask_and(cpumask, inmask, andmask); |
|
230 cpumask_and(cpumask, cpumask, cpu_online_mask); |
|
231 apicid = cpu_mask_to_apicid(cpumask); |
|
232 |
|
233 free_cpumask_var(cpumask); |
|
234 return apicid; |
|
235 } |
|
236 |
188 static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb) |
237 static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb) |
189 { |
238 { |
190 return cpuid_apic >> index_msb; |
239 return cpuid_apic >> index_msb; |
191 } |
240 } |
192 |
241 |