x86, apic: untangle the send_IPI_*() jungle
[linux-2.6-block.git] / arch / x86 / include / asm / mach-default / mach_apic.h
1 #ifndef _ASM_X86_MACH_DEFAULT_MACH_APIC_H
2 #define _ASM_X86_MACH_DEFAULT_MACH_APIC_H
3
4 #ifdef CONFIG_X86_LOCAL_APIC
5
6 #include <mach_apicdef.h>
7 #include <asm/smp.h>
8
9 #define APIC_DFR_VALUE  (APIC_DFR_FLAT)
10
11 static inline const struct cpumask *default_target_cpus(void)
12
13 #ifdef CONFIG_SMP
14         return cpu_online_mask;
15 #else
16         return cpumask_of(0);
17 #endif
18
19
20 #ifdef CONFIG_X86_64
21 #include <asm/genapic.h>
22 #define read_apic_id()  (apic->get_apic_id(apic_read(APIC_ID)))
23 #define wakeup_secondary_cpu (apic->wakeup_cpu)
24 extern void default_setup_apic_routing(void);
25 #else
26 #define wakeup_secondary_cpu wakeup_secondary_cpu_via_init
27 /*
28  * Set up the logical destination ID.
29  *
30  * Intel recommends to set DFR, LDR and TPR before enabling
31  * an APIC.  See e.g. "AP-388 82489DX User's Manual" (Intel
32  * document number 292116).  So here it goes...
33  */
34 static inline void default_init_apic_ldr(void)
35 {
36         unsigned long val;
37
38         apic_write(APIC_DFR, APIC_DFR_VALUE);
39         val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
40         val |= SET_APIC_LOGICAL_ID(1UL << smp_processor_id());
41         apic_write(APIC_LDR, val);
42 }
43
44 static inline int default_apic_id_registered(void)
45 {
46         return physid_isset(read_apic_id(), phys_cpu_present_map);
47 }
48
49 static inline unsigned int
50 default_cpu_mask_to_apicid(const struct cpumask *cpumask)
51 {
52         return cpumask_bits(cpumask)[0];
53 }
54
55 static inline unsigned int
56 default_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
57                                const struct cpumask *andmask)
58 {
59         unsigned long mask1 = cpumask_bits(cpumask)[0];
60         unsigned long mask2 = cpumask_bits(andmask)[0];
61         unsigned long mask3 = cpumask_bits(cpu_online_mask)[0];
62
63         return (unsigned int)(mask1 & mask2 & mask3);
64 }
65
66 static inline int default_phys_pkg_id(int cpuid_apic, int index_msb)
67 {
68         return cpuid_apic >> index_msb;
69 }
70
71 static inline void default_setup_apic_routing(void)
72 {
73 #ifdef CONFIG_X86_IO_APIC
74         printk("Enabling APIC mode:  %s.  Using %d I/O APICs\n",
75                                         "Flat", nr_ioapics);
76 #endif
77 }
78
79 static inline int default_apicid_to_node(int logical_apicid)
80 {
81 #ifdef CONFIG_SMP
82         return apicid_2_node[hard_smp_processor_id()];
83 #else
84         return 0;
85 #endif
86 }
87
88 #endif
89
90 static inline unsigned long default_check_apicid_used(physid_mask_t bitmap, int apicid)
91 {
92         return physid_isset(apicid, bitmap);
93 }
94
95 static inline unsigned long default_check_apicid_present(int bit)
96 {
97         return physid_isset(bit, phys_cpu_present_map);
98 }
99
100 static inline physid_mask_t default_ioapic_phys_id_map(physid_mask_t phys_map)
101 {
102         return phys_map;
103 }
104
105 /* Mapping from cpu number to logical apicid */
106 static inline int default_cpu_to_logical_apicid(int cpu)
107 {
108         return 1 << cpu;
109 }
110
111 static inline int __default_cpu_present_to_apicid(int mps_cpu)
112 {
113         if (mps_cpu < nr_cpu_ids && cpu_present(mps_cpu))
114                 return (int)per_cpu(x86_bios_cpu_apicid, mps_cpu);
115         else
116                 return BAD_APICID;
117 }
118
119 static inline int
120 __default_check_phys_apicid_present(int boot_cpu_physical_apicid)
121 {
122         return physid_isset(boot_cpu_physical_apicid, phys_cpu_present_map);
123 }
124
125 #ifdef CONFIG_X86_32
126 static inline int default_cpu_present_to_apicid(int mps_cpu)
127 {
128         return __default_cpu_present_to_apicid(mps_cpu);
129 }
130
131 static inline int
132 default_check_phys_apicid_present(int boot_cpu_physical_apicid)
133 {
134         return __default_check_phys_apicid_present(boot_cpu_physical_apicid);
135 }
136 #else
137 extern int default_cpu_present_to_apicid(int mps_cpu);
138 extern int default_check_phys_apicid_present(int boot_cpu_physical_apicid);
139 #endif
140
141 static inline physid_mask_t default_apicid_to_cpu_present(int phys_apicid)
142 {
143         return physid_mask_of_physid(phys_apicid);
144 }
145
146 #endif /* CONFIG_X86_LOCAL_APIC */
147 #endif /* _ASM_X86_MACH_DEFAULT_MACH_APIC_H */