2 * APIC driver for "bigsmp" XAPIC machines with more than 8 virtual CPUs.
3 * Drives the local APIC in "clustered mode".
5 #define APIC_DEFINITION 1
6 #include <linux/threads.h>
7 #include <linux/cpumask.h>
8 #include <asm/mpspec.h>
9 #include <asm/genapic.h>
10 #include <asm/fixmap.h>
11 #include <asm/apicdef.h>
13 #include <linux/kernel.h>
14 #include <linux/init.h>
15 #include <linux/dmi.h>
16 #include <linux/smp.h>
19 static inline unsigned bigsmp_get_apic_id(unsigned long x)
21 return (x >> 24) & 0xFF;
24 #define xapic_phys_to_log_apicid(cpu) (per_cpu(x86_bios_cpu_apicid, cpu))
26 static inline int bigsmp_apic_id_registered(void)
31 static inline const cpumask_t *bigsmp_target_cpus(void)
34 return &cpu_online_map;
36 return &cpumask_of_cpu(0);
40 #define APIC_DFR_VALUE (APIC_DFR_FLAT)
42 static inline unsigned long
43 bigsmp_check_apicid_used(physid_mask_t bitmap, int apicid)
48 static inline unsigned long bigsmp_check_apicid_present(int bit)
53 static inline unsigned long calculate_ldr(int cpu)
55 unsigned long val, id;
56 val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
57 id = xapic_phys_to_log_apicid(cpu);
58 val |= SET_APIC_LOGICAL_ID(id);
63 * Set up the logical destination ID.
65 * Intel recommends to set DFR, LDR and TPR before enabling
66 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
67 * document number 292116). So here it goes...
69 static inline void bigsmp_init_apic_ldr(void)
72 int cpu = smp_processor_id();
74 apic_write(APIC_DFR, APIC_DFR_VALUE);
75 val = calculate_ldr(cpu);
76 apic_write(APIC_LDR, val);
79 static inline void bigsmp_setup_apic_routing(void)
81 printk("Enabling APIC mode: %s. Using %d I/O APICs\n",
82 "Physflat", nr_ioapics);
85 static inline int bigsmp_apicid_to_node(int logical_apicid)
87 return apicid_2_node[hard_smp_processor_id()];
90 static inline int bigsmp_cpu_present_to_apicid(int mps_cpu)
92 if (mps_cpu < nr_cpu_ids)
93 return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
98 static inline physid_mask_t bigsmp_apicid_to_cpu_present(int phys_apicid)
100 return physid_mask_of_physid(phys_apicid);
103 extern u8 cpu_2_logical_apicid[];
104 /* Mapping from cpu number to logical apicid */
105 static inline int bigsmp_cpu_to_logical_apicid(int cpu)
107 if (cpu >= nr_cpu_ids)
109 return cpu_physical_id(cpu);
112 static inline physid_mask_t bigsmp_ioapic_phys_id_map(physid_mask_t phys_map)
114 /* For clustered we don't have a good way to do this yet - hack */
115 return physids_promote(0xFFL);
118 static inline void bigsmp_setup_portio_remap(void)
122 static inline int bigsmp_check_phys_apicid_present(int boot_cpu_physical_apicid)
127 /* As we are using single CPU as destination, pick only one CPU here */
128 static inline unsigned int bigsmp_cpu_mask_to_apicid(const cpumask_t *cpumask)
130 return bigsmp_cpu_to_logical_apicid(first_cpu(*cpumask));
133 static inline unsigned int
134 bigsmp_cpu_mask_to_apicid_and(const struct cpumask *cpumask,
135 const struct cpumask *andmask)
140 * We're using fixed IRQ delivery, can only return one phys APIC ID.
141 * May as well be the first.
143 for_each_cpu_and(cpu, cpumask, andmask) {
144 if (cpumask_test_cpu(cpu, cpu_online_mask))
147 if (cpu < nr_cpu_ids)
148 return bigsmp_cpu_to_logical_apicid(cpu);
153 static inline int bigsmp_phys_pkg_id(int cpuid_apic, int index_msb)
155 return cpuid_apic >> index_msb;
158 static inline void bigsmp_send_IPI_mask(const struct cpumask *mask, int vector)
160 default_send_IPI_mask_sequence_phys(mask, vector);
163 static inline void bigsmp_send_IPI_allbutself(int vector)
165 default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector);
168 static inline void bigsmp_send_IPI_all(int vector)
170 bigsmp_send_IPI_mask(cpu_online_mask, vector);
173 static int dmi_bigsmp; /* can be set by dmi scanners */
175 static int hp_ht_bigsmp(const struct dmi_system_id *d)
177 printk(KERN_NOTICE "%s detected: force use of apic=bigsmp\n", d->ident);
183 static const struct dmi_system_id bigsmp_dmi_table[] = {
184 { hp_ht_bigsmp, "HP ProLiant DL760 G2",
185 { DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
186 DMI_MATCH(DMI_BIOS_VERSION, "P44-"),}
189 { hp_ht_bigsmp, "HP ProLiant DL740",
190 { DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
191 DMI_MATCH(DMI_BIOS_VERSION, "P47-"),}
196 static void bigsmp_vector_allocation_domain(int cpu, cpumask_t *retmask)
198 cpus_clear(*retmask);
199 cpu_set(cpu, *retmask);
202 static int probe_bigsmp(void)
207 dmi_check_system(bigsmp_dmi_table);
211 struct genapic apic_bigsmp = {
214 .probe = probe_bigsmp,
215 .acpi_madt_oem_check = NULL,
216 .apic_id_registered = bigsmp_apic_id_registered,
218 .irq_delivery_mode = dest_Fixed,
219 /* phys delivery to target CPU: */
222 .target_cpus = bigsmp_target_cpus,
225 .check_apicid_used = bigsmp_check_apicid_used,
226 .check_apicid_present = bigsmp_check_apicid_present,
228 .vector_allocation_domain = bigsmp_vector_allocation_domain,
229 .init_apic_ldr = bigsmp_init_apic_ldr,
231 .ioapic_phys_id_map = bigsmp_ioapic_phys_id_map,
232 .setup_apic_routing = bigsmp_setup_apic_routing,
233 .multi_timer_check = NULL,
234 .apicid_to_node = bigsmp_apicid_to_node,
235 .cpu_to_logical_apicid = bigsmp_cpu_to_logical_apicid,
236 .cpu_present_to_apicid = bigsmp_cpu_present_to_apicid,
237 .apicid_to_cpu_present = bigsmp_apicid_to_cpu_present,
238 .setup_portio_remap = NULL,
239 .check_phys_apicid_present = bigsmp_check_phys_apicid_present,
240 .enable_apic_mode = NULL,
241 .phys_pkg_id = bigsmp_phys_pkg_id,
242 .mps_oem_check = NULL,
244 .get_apic_id = bigsmp_get_apic_id,
246 .apic_id_mask = 0xFF << 24,
248 .cpu_mask_to_apicid = bigsmp_cpu_mask_to_apicid,
249 .cpu_mask_to_apicid_and = bigsmp_cpu_mask_to_apicid_and,
251 .send_IPI_mask = bigsmp_send_IPI_mask,
252 .send_IPI_mask_allbutself = NULL,
253 .send_IPI_allbutself = bigsmp_send_IPI_allbutself,
254 .send_IPI_all = bigsmp_send_IPI_all,
255 .send_IPI_self = default_send_IPI_self,
258 .trampoline_phys_low = DEFAULT_TRAMPOLINE_PHYS_LOW,
259 .trampoline_phys_high = DEFAULT_TRAMPOLINE_PHYS_HIGH,
261 .wait_for_init_deassert = default_wait_for_init_deassert,
263 .smp_callin_clear_local_apic = NULL,
264 .store_NMI_vector = NULL,
265 .inquire_remote_apic = default_inquire_remote_apic,