2 * Copyright 2004 James Cleverdon, IBM.
3 * Subject to the GNU Public License, v.2
5 * Flat APIC subarch code.
7 * Hacked for x86-64 by James Cleverdon from i386 architecture code by
8 * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and
11 #include <linux/threads.h>
12 #include <linux/cpumask.h>
13 #include <linux/string.h>
14 #include <linux/kernel.h>
15 #include <linux/ctype.h>
16 #include <linux/init.h>
20 static cpumask_t
flat_target_cpus(void)
22 return cpu_online_map
;
26 * Set up the logical destination ID.
28 * Intel recommends to set DFR, LDR and TPR before enabling
29 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
30 * document number 292116). So here it goes...
32 static void flat_init_apic_ldr(void)
35 unsigned long num
, id
;
37 num
= smp_processor_id();
39 x86_cpu_to_log_apicid
[num
] = id
;
40 apic_write(APIC_DFR
, APIC_DFR_FLAT
);
41 val
= apic_read(APIC_LDR
) & ~APIC_LDR_MASK
;
42 val
|= SET_APIC_LOGICAL_ID(id
);
43 apic_write(APIC_LDR
, val
);
46 static void flat_send_IPI_mask(cpumask_t cpumask
, int vector
)
48 unsigned long mask
= cpus_addr(cpumask
)[0];
52 local_save_flags(flags
);
61 * prepare target chip field
63 cfg
= __prepare_ICR2(mask
);
64 apic_write(APIC_ICR2
, cfg
);
69 cfg
= __prepare_ICR(0, vector
, APIC_DEST_LOGICAL
);
72 * Send the IPI. The write to APIC_ICR fires this off.
74 apic_write(APIC_ICR
, cfg
);
75 local_irq_restore(flags
);
78 static void flat_send_IPI_allbutself(int vector
)
80 #ifdef CONFIG_HOTPLUG_CPU
85 if (hotplug
|| vector
== NMI_VECTOR
) {
86 cpumask_t allbutme
= cpu_online_map
;
88 cpu_clear(smp_processor_id(), allbutme
);
90 if (!cpus_empty(allbutme
))
91 flat_send_IPI_mask(allbutme
, vector
);
92 } else if (num_online_cpus() > 1) {
93 __send_IPI_shortcut(APIC_DEST_ALLBUT
, vector
,APIC_DEST_LOGICAL
);
97 static void flat_send_IPI_all(int vector
)
99 if (vector
== NMI_VECTOR
)
100 flat_send_IPI_mask(cpu_online_map
, vector
);
102 __send_IPI_shortcut(APIC_DEST_ALLINC
, vector
, APIC_DEST_LOGICAL
);
105 static int flat_apic_id_registered(void)
107 return physid_isset(GET_APIC_ID(apic_read(APIC_ID
)), phys_cpu_present_map
);
110 static unsigned int flat_cpu_mask_to_apicid(cpumask_t cpumask
)
112 return cpus_addr(cpumask
)[0] & APIC_ALL_CPUS
;
115 static unsigned int phys_pkg_id(int index_msb
)
117 return hard_smp_processor_id() >> index_msb
;
120 struct genapic apic_flat
= {
122 .int_delivery_mode
= dest_LowestPrio
,
123 .int_dest_mode
= (APIC_DEST_LOGICAL
!= 0),
124 .int_delivery_dest
= APIC_DEST_LOGICAL
| APIC_DM_LOWEST
,
125 .target_cpus
= flat_target_cpus
,
126 .apic_id_registered
= flat_apic_id_registered
,
127 .init_apic_ldr
= flat_init_apic_ldr
,
128 .send_IPI_all
= flat_send_IPI_all
,
129 .send_IPI_allbutself
= flat_send_IPI_allbutself
,
130 .send_IPI_mask
= flat_send_IPI_mask
,
131 .cpu_mask_to_apicid
= flat_cpu_mask_to_apicid
,
132 .phys_pkg_id
= phys_pkg_id
,
136 * Physflat mode is used when there are more than 8 CPUs on a AMD system.
137 * We cannot use logical delivery in this case because the mask
138 * overflows, so use physical mode.
141 static cpumask_t
physflat_target_cpus(void)
143 return cpumask_of_cpu(0);
146 static void physflat_send_IPI_mask(cpumask_t cpumask
, int vector
)
148 send_IPI_mask_sequence(cpumask
, vector
);
151 static void physflat_send_IPI_allbutself(int vector
)
153 cpumask_t allbutme
= cpu_online_map
;
155 cpu_clear(smp_processor_id(), allbutme
);
156 physflat_send_IPI_mask(allbutme
, vector
);
159 static void physflat_send_IPI_all(int vector
)
161 physflat_send_IPI_mask(cpu_online_map
, vector
);
164 static unsigned int physflat_cpu_mask_to_apicid(cpumask_t cpumask
)
169 * We're using fixed IRQ delivery, can only return one phys APIC ID.
170 * May as well be the first.
172 cpu
= first_cpu(cpumask
);
173 if ((unsigned)cpu
< NR_CPUS
)
174 return x86_cpu_to_apicid
[cpu
];
179 struct genapic apic_physflat
= {
180 .name
= "physical flat",
181 .int_delivery_mode
= dest_Fixed
,
182 .int_dest_mode
= (APIC_DEST_PHYSICAL
!= 0),
183 .int_delivery_dest
= APIC_DEST_PHYSICAL
| APIC_DM_FIXED
,
184 .target_cpus
= physflat_target_cpus
,
185 .apic_id_registered
= flat_apic_id_registered
,
186 .init_apic_ldr
= flat_init_apic_ldr
,/*not needed, but shouldn't hurt*/
187 .send_IPI_all
= physflat_send_IPI_all
,
188 .send_IPI_allbutself
= physflat_send_IPI_allbutself
,
189 .send_IPI_mask
= physflat_send_IPI_mask
,
190 .cpu_mask_to_apicid
= physflat_cpu_mask_to_apicid
,
191 .phys_pkg_id
= phys_pkg_id
,