x86, apic: clean up ->setup_apic_routing()
[deliverable/linux.git] / arch / x86 / include / asm / es7000 / apic.h
1 #ifndef __ASM_ES7000_APIC_H
2 #define __ASM_ES7000_APIC_H
3
4 #include <linux/gfp.h>
5
6 #define xapic_phys_to_log_apicid(cpu) per_cpu(x86_bios_cpu_apicid, cpu)
7
8 static inline int es7000_apic_id_registered(void)
9 {
10 return 1;
11 }
12
13 static inline const cpumask_t *target_cpus_cluster(void)
14 {
15 return &CPU_MASK_ALL;
16 }
17
18 static inline const cpumask_t *es7000_target_cpus(void)
19 {
20 return &cpumask_of_cpu(smp_processor_id());
21 }
22
23 #define APIC_DFR_VALUE_CLUSTER (APIC_DFR_CLUSTER)
24 #define INT_DELIVERY_MODE_CLUSTER (dest_LowestPrio)
25 #define INT_DEST_MODE_CLUSTER (1) /* logical delivery broadcast to all procs */
26
27 #define APIC_DFR_VALUE (APIC_DFR_FLAT)
28
29 static inline unsigned long
30 es7000_check_apicid_used(physid_mask_t bitmap, int apicid)
31 {
32 return 0;
33 }
34 static inline unsigned long es7000_check_apicid_present(int bit)
35 {
36 return physid_isset(bit, phys_cpu_present_map);
37 }
38
39 #define apicid_cluster(apicid) (apicid & 0xF0)
40
41 static inline unsigned long calculate_ldr(int cpu)
42 {
43 unsigned long id;
44 id = xapic_phys_to_log_apicid(cpu);
45 return (SET_APIC_LOGICAL_ID(id));
46 }
47
48 /*
49 * Set up the logical destination ID.
50 *
51 * Intel recommends to set DFR, LdR and TPR before enabling
52 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
53 * document number 292116). So here it goes...
54 */
55 static inline void es7000_init_apic_ldr_cluster(void)
56 {
57 unsigned long val;
58 int cpu = smp_processor_id();
59
60 apic_write(APIC_DFR, APIC_DFR_VALUE_CLUSTER);
61 val = calculate_ldr(cpu);
62 apic_write(APIC_LDR, val);
63 }
64
65 static inline void es7000_init_apic_ldr(void)
66 {
67 unsigned long val;
68 int cpu = smp_processor_id();
69
70 apic_write(APIC_DFR, APIC_DFR_VALUE);
71 val = calculate_ldr(cpu);
72 apic_write(APIC_LDR, val);
73 }
74
75 extern int apic_version [MAX_APICS];
76 static inline void es7000_setup_apic_routing(void)
77 {
78 int apic = per_cpu(x86_bios_cpu_apicid, smp_processor_id());
79 printk("Enabling APIC mode: %s. Using %d I/O APICs, target cpus %lx\n",
80 (apic_version[apic] == 0x14) ?
81 "Physical Cluster" : "Logical Cluster",
82 nr_ioapics, cpus_addr(*es7000_target_cpus())[0]);
83 }
84
85 static inline int multi_timer_check(int apic, int irq)
86 {
87 return 0;
88 }
89
90 static inline int apicid_to_node(int logical_apicid)
91 {
92 return 0;
93 }
94
95
96 static inline int cpu_present_to_apicid(int mps_cpu)
97 {
98 if (!mps_cpu)
99 return boot_cpu_physical_apicid;
100 else if (mps_cpu < nr_cpu_ids)
101 return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
102 else
103 return BAD_APICID;
104 }
105
106 static inline physid_mask_t apicid_to_cpu_present(int phys_apicid)
107 {
108 static int id = 0;
109 physid_mask_t mask;
110 mask = physid_mask_of_physid(id);
111 ++id;
112 return mask;
113 }
114
115 extern u8 cpu_2_logical_apicid[];
116 /* Mapping from cpu number to logical apicid */
117 static inline int cpu_to_logical_apicid(int cpu)
118 {
119 #ifdef CONFIG_SMP
120 if (cpu >= nr_cpu_ids)
121 return BAD_APICID;
122 return (int)cpu_2_logical_apicid[cpu];
123 #else
124 return logical_smp_processor_id();
125 #endif
126 }
127
128 static inline physid_mask_t es7000_ioapic_phys_id_map(physid_mask_t phys_map)
129 {
130 /* For clustered we don't have a good way to do this yet - hack */
131 return physids_promote(0xff);
132 }
133
134
135 static inline void setup_portio_remap(void)
136 {
137 }
138
139 extern unsigned int boot_cpu_physical_apicid;
140 static inline int check_phys_apicid_present(int cpu_physical_apicid)
141 {
142 boot_cpu_physical_apicid = read_apic_id();
143 return (1);
144 }
145
146 static inline unsigned int
147 cpu_mask_to_apicid_cluster(const struct cpumask *cpumask)
148 {
149 int num_bits_set;
150 int cpus_found = 0;
151 int cpu;
152 int apicid;
153
154 num_bits_set = cpumask_weight(cpumask);
155 /* Return id to all */
156 if (num_bits_set == nr_cpu_ids)
157 return 0xFF;
158 /*
159 * The cpus in the mask must all be on the apic cluster. If are not
160 * on the same apicid cluster return default value of target_cpus():
161 */
162 cpu = cpumask_first(cpumask);
163 apicid = cpu_to_logical_apicid(cpu);
164 while (cpus_found < num_bits_set) {
165 if (cpumask_test_cpu(cpu, cpumask)) {
166 int new_apicid = cpu_to_logical_apicid(cpu);
167 if (apicid_cluster(apicid) !=
168 apicid_cluster(new_apicid)){
169 printk ("%s: Not a valid mask!\n", __func__);
170 return 0xFF;
171 }
172 apicid = new_apicid;
173 cpus_found++;
174 }
175 cpu++;
176 }
177 return apicid;
178 }
179
180 static inline unsigned int cpu_mask_to_apicid(const cpumask_t *cpumask)
181 {
182 int num_bits_set;
183 int cpus_found = 0;
184 int cpu;
185 int apicid;
186
187 num_bits_set = cpus_weight(*cpumask);
188 /* Return id to all */
189 if (num_bits_set == nr_cpu_ids)
190 return cpu_to_logical_apicid(0);
191 /*
192 * The cpus in the mask must all be on the apic cluster. If are not
193 * on the same apicid cluster return default value of target_cpus():
194 */
195 cpu = first_cpu(*cpumask);
196 apicid = cpu_to_logical_apicid(cpu);
197 while (cpus_found < num_bits_set) {
198 if (cpu_isset(cpu, *cpumask)) {
199 int new_apicid = cpu_to_logical_apicid(cpu);
200 if (apicid_cluster(apicid) !=
201 apicid_cluster(new_apicid)){
202 printk ("%s: Not a valid mask!\n", __func__);
203 return cpu_to_logical_apicid(0);
204 }
205 apicid = new_apicid;
206 cpus_found++;
207 }
208 cpu++;
209 }
210 return apicid;
211 }
212
213
214 static inline unsigned int cpu_mask_to_apicid_and(const struct cpumask *inmask,
215 const struct cpumask *andmask)
216 {
217 int apicid = cpu_to_logical_apicid(0);
218 cpumask_var_t cpumask;
219
220 if (!alloc_cpumask_var(&cpumask, GFP_ATOMIC))
221 return apicid;
222
223 cpumask_and(cpumask, inmask, andmask);
224 cpumask_and(cpumask, cpumask, cpu_online_mask);
225 apicid = cpu_mask_to_apicid(cpumask);
226
227 free_cpumask_var(cpumask);
228 return apicid;
229 }
230
231 static inline u32 phys_pkg_id(u32 cpuid_apic, int index_msb)
232 {
233 return cpuid_apic >> index_msb;
234 }
235
236 #endif /* __ASM_ES7000_APIC_H */
This page took 0.041106 seconds and 5 git commands to generate.