x86, apic: refactor ->cpu_mask_to_apicid*()
[linux-2.6-block.git] / arch / x86 / include / asm / bigsmp / apic.h
CommitLineData
1176fa91
YL
1#ifndef __ASM_MACH_APIC_H
2#define __ASM_MACH_APIC_H
1855a2c4 3
cbe879fc 4#define xapic_phys_to_log_apicid(cpu) (per_cpu(x86_bios_cpu_apicid, cpu))
1da177e4 5
7ed248da 6static inline int bigsmp_apic_id_registered(void)
1da177e4 7{
7ed248da 8 return 1;
1da177e4
LT
9}
10
0a9cc20b 11static inline const cpumask_t *bigsmp_target_cpus(void)
1176fa91 12{
497c9a19 13#ifdef CONFIG_SMP
e7986739 14 return &cpu_online_map;
497c9a19 15#else
e7986739 16 return &cpumask_of_cpu(0);
497c9a19 17#endif
1da177e4 18}
1da177e4 19
1855a2c4 20#define APIC_DFR_VALUE (APIC_DFR_FLAT)
1da177e4 21
d1d7cae8
IM
22static inline unsigned long
23bigsmp_check_apicid_used(physid_mask_t bitmap, int apicid)
1da177e4 24{
d1d7cae8 25 return 0;
1da177e4
LT
26}
27
d1d7cae8 28static inline unsigned long bigsmp_check_apicid_present(int bit)
1da177e4 29{
d1d7cae8 30 return 1;
1da177e4
LT
31}
32
1855a2c4 33static inline unsigned long calculate_ldr(int cpu)
1da177e4 34{
1855a2c4
AR
35 unsigned long val, id;
36 val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
37 id = xapic_phys_to_log_apicid(cpu);
38 val |= SET_APIC_LOGICAL_ID(id);
39 return val;
1da177e4
LT
40}
41
42/*
43 * Set up the logical destination ID.
44 *
45 * Intel recommends to set DFR, LDR and TPR before enabling
46 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
47 * document number 292116). So here it goes...
48 */
a5c43296 49static inline void bigsmp_init_apic_ldr(void)
1da177e4
LT
50{
51 unsigned long val;
1855a2c4 52 int cpu = smp_processor_id();
1da177e4 53
593f4a78 54 apic_write(APIC_DFR, APIC_DFR_VALUE);
1855a2c4 55 val = calculate_ldr(cpu);
593f4a78 56 apic_write(APIC_LDR, val);
1da177e4
LT
57}
58
72ce0165 59static inline void bigsmp_setup_apic_routing(void)
1da177e4
LT
60{
61 printk("Enabling APIC mode: %s. Using %d I/O APICs\n",
1855a2c4 62 "Physflat", nr_ioapics);
1da177e4
LT
63}
64
3f57a318 65static inline int bigsmp_apicid_to_node(int logical_apicid)
1da177e4 66{
f47f9d53 67 return apicid_2_node[hard_smp_processor_id()];
1da177e4
LT
68}
69
a21769a4 70static inline int bigsmp_cpu_present_to_apicid(int mps_cpu)
1da177e4 71{
e7986739 72 if (mps_cpu < nr_cpu_ids)
cbe879fc 73 return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
1855a2c4
AR
74
75 return BAD_APICID;
1da177e4
LT
76}
77
8058714a 78static inline physid_mask_t bigsmp_apicid_to_cpu_present(int phys_apicid)
1da177e4
LT
79{
80 return physid_mask_of_physid(phys_apicid);
81}
82
83extern u8 cpu_2_logical_apicid[];
84/* Mapping from cpu number to logical apicid */
5257c511 85static inline int bigsmp_cpu_to_logical_apicid(int cpu)
1da177e4 86{
e7986739 87 if (cpu >= nr_cpu_ids)
1855a2c4
AR
88 return BAD_APICID;
89 return cpu_physical_id(cpu);
90}
1da177e4 91
d190cb87 92static inline physid_mask_t bigsmp_ioapic_phys_id_map(physid_mask_t phys_map)
1da177e4
LT
93{
94 /* For clustered we don't have a good way to do this yet - hack */
1855a2c4 95 return physids_promote(0xFFL);
1da177e4
LT
96}
97
d83093b5 98static inline void bigsmp_setup_portio_remap(void)
1da177e4
LT
99{
100}
101
a27a6210 102static inline int bigsmp_check_phys_apicid_present(int boot_cpu_physical_apicid)
1da177e4 103{
a27a6210 104 return 1;
1da177e4
LT
105}
106
1da177e4 107/* As we are using single CPU as destination, pick only one CPU here */
debccb3e 108static inline unsigned int bigsmp_cpu_mask_to_apicid(const cpumask_t *cpumask)
1da177e4 109{
debccb3e 110 return bigsmp_cpu_to_logical_apicid(first_cpu(*cpumask));
1da177e4
LT
111}
112
debccb3e
IM
113static inline unsigned int
114bigsmp_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
115 const struct cpumask *andmask)
95d313cf
MT
116{
117 int cpu;
118
119 /*
120 * We're using fixed IRQ delivery, can only return one phys APIC ID.
121 * May as well be the first.
122 */
debccb3e 123 for_each_cpu_and(cpu, cpumask, andmask) {
a775a38b
MT
124 if (cpumask_test_cpu(cpu, cpu_online_mask))
125 break;
debccb3e 126 }
6eeb7c5a 127 if (cpu < nr_cpu_ids)
5257c511 128 return bigsmp_cpu_to_logical_apicid(cpu);
95d313cf
MT
129
130 return BAD_APICID;
131}
132
cb8cc442 133static inline int bigsmp_phys_pkg_id(int cpuid_apic, int index_msb)
1da177e4
LT
134{
135 return cpuid_apic >> index_msb;
136}
137
1176fa91 138#endif /* __ASM_MACH_APIC_H */