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