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
11 #include <linux/config.h>
12 #include <linux/threads.h>
13 #include <linux/cpumask.h>
14 #include <linux/string.h>
15 #include <linux/kernel.h>
16 #include <linux/ctype.h>
17 #include <linux/init.h>
22 static cpumask_t
flat_target_cpus(void)
24 return cpu_online_map
;
28 * Set up the logical destination ID.
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...
34 static void flat_init_apic_ldr(void)
37 unsigned long num
, id
;
39 num
= smp_processor_id();
41 x86_cpu_to_log_apicid
[num
] = id
;
42 apic_write_around(APIC_DFR
, APIC_DFR_FLAT
);
43 val
= apic_read(APIC_LDR
) & ~APIC_LDR_MASK
;
44 val
|= SET_APIC_LOGICAL_ID(id
);
45 apic_write_around(APIC_LDR
, val
);
48 static void flat_send_IPI_allbutself(int vector
)
51 * if there are no other CPUs in the system then
52 * we get an APIC send error if we try to broadcast.
53 * thus we have to avoid sending IPIs in this case.
55 if (num_online_cpus() > 1)
56 __send_IPI_shortcut(APIC_DEST_ALLBUT
, vector
, APIC_DEST_LOGICAL
);
59 static void flat_send_IPI_all(int vector
)
61 __send_IPI_shortcut(APIC_DEST_ALLINC
, vector
, APIC_DEST_LOGICAL
);
64 static void flat_send_IPI_mask(cpumask_t cpumask
, int vector
)
66 unsigned long mask
= cpus_addr(cpumask
)[0];
70 local_save_flags(flags
);
79 * prepare target chip field
81 cfg
= __prepare_ICR2(mask
);
82 apic_write_around(APIC_ICR2
, cfg
);
87 cfg
= __prepare_ICR(0, vector
, APIC_DEST_LOGICAL
);
90 * Send the IPI. The write to APIC_ICR fires this off.
92 apic_write_around(APIC_ICR
, cfg
);
93 local_irq_restore(flags
);
96 static int flat_apic_id_registered(void)
98 return physid_isset(GET_APIC_ID(apic_read(APIC_ID
)), phys_cpu_present_map
);
101 static unsigned int flat_cpu_mask_to_apicid(cpumask_t cpumask
)
103 return cpus_addr(cpumask
)[0] & APIC_ALL_CPUS
;
106 static unsigned int phys_pkg_id(int index_msb
)
111 return ((ebx
>> 24) & 0xFF) >> index_msb
;
114 struct genapic apic_flat
= {
116 .int_delivery_mode
= dest_LowestPrio
,
117 .int_dest_mode
= (APIC_DEST_LOGICAL
!= 0),
118 .int_delivery_dest
= APIC_DEST_LOGICAL
| APIC_DM_LOWEST
,
119 .target_cpus
= flat_target_cpus
,
120 .apic_id_registered
= flat_apic_id_registered
,
121 .init_apic_ldr
= flat_init_apic_ldr
,
122 .send_IPI_all
= flat_send_IPI_all
,
123 .send_IPI_allbutself
= flat_send_IPI_allbutself
,
124 .send_IPI_mask
= flat_send_IPI_mask
,
125 .cpu_mask_to_apicid
= flat_cpu_mask_to_apicid
,
126 .phys_pkg_id
= phys_pkg_id
,