2 * Copyright 2004 James Cleverdon, IBM.
3 * Subject to the GNU Public License, v.2
5 * Flat APIC subarch code. Maximum 8 CPUs, logical delivery.
7 * Hacked for x86-64 by James Cleverdon from i386 architecture code by
8 * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and
10 * Ashok Raj <ashok.raj@intel.com>
11 * Removed IPI broadcast shortcut to support CPU hotplug
13 #include <linux/config.h>
14 #include <linux/threads.h>
15 #include <linux/cpumask.h>
16 #include <linux/string.h>
17 #include <linux/kernel.h>
18 #include <linux/ctype.h>
19 #include <linux/init.h>
24 static cpumask_t flat_target_cpus(void)
26 return cpu_online_map;
30 * Set up the logical destination ID.
32 * Intel recommends to set DFR, LDR and TPR before enabling
33 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
34 * document number 292116). So here it goes...
36 static void flat_init_apic_ldr(void)
39 unsigned long num, id;
41 num = smp_processor_id();
43 x86_cpu_to_log_apicid[num] = id;
44 apic_write_around(APIC_DFR, APIC_DFR_FLAT);
45 val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
46 val |= SET_APIC_LOGICAL_ID(id);
47 apic_write_around(APIC_LDR, val);
50 static void flat_send_IPI_mask(cpumask_t cpumask, int vector)
52 unsigned long mask = cpus_addr(cpumask)[0];
56 local_save_flags(flags);
65 * prepare target chip field
67 cfg = __prepare_ICR2(mask);
68 apic_write_around(APIC_ICR2, cfg);
73 cfg = __prepare_ICR(0, vector, APIC_DEST_LOGICAL);
76 * Send the IPI. The write to APIC_ICR fires this off.
78 apic_write_around(APIC_ICR, cfg);
79 local_irq_restore(flags);
82 static void flat_send_IPI_allbutself(int vector)
86 * if there are no other CPUs in the system then
87 * we get an APIC send error if we try to broadcast.
88 * thus we have to avoid sending IPIs in this case.
90 int this_cpu = get_cpu();
92 mask = cpu_online_map;
93 cpu_clear(this_cpu, mask);
95 if (cpus_weight(mask) >= 1)
96 flat_send_IPI_mask(mask, vector);
101 static void flat_send_IPI_all(int vector)
103 flat_send_IPI_mask(cpu_online_map, vector);
106 static int flat_apic_id_registered(void)
108 return physid_isset(GET_APIC_ID(apic_read(APIC_ID)), phys_cpu_present_map);
111 static unsigned int flat_cpu_mask_to_apicid(cpumask_t cpumask)
113 return cpus_addr(cpumask)[0] & APIC_ALL_CPUS;
116 static unsigned int phys_pkg_id(int index_msb)
121 return ((ebx >> 24) & 0xFF) >> index_msb;
124 struct genapic apic_flat = {
126 .int_delivery_mode = dest_LowestPrio,
127 .int_dest_mode = (APIC_DEST_LOGICAL != 0),
128 .int_delivery_dest = APIC_DEST_LOGICAL | APIC_DM_LOWEST,
129 .target_cpus = flat_target_cpus,
130 .apic_id_registered = flat_apic_id_registered,
131 .init_apic_ldr = flat_init_apic_ldr,
132 .send_IPI_all = flat_send_IPI_all,
133 .send_IPI_allbutself = flat_send_IPI_allbutself,
134 .send_IPI_mask = flat_send_IPI_mask,
135 .cpu_mask_to_apicid = flat_cpu_mask_to_apicid,
136 .phys_pkg_id = phys_pkg_id,