blob: 00f3fa6df71406b6eb5b6d64cb071f65a05e5b84 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Copyright 2004 James Cleverdon, IBM.
3 * Subject to the GNU Public License, v.2
4 *
5 * Flat APIC subarch code. Maximum 8 CPUs, logical delivery.
6 *
7 * Hacked for x86-64 by James Cleverdon from i386 architecture code by
8 * Martin Bligh, Andi Kleen, James Bottomley, John Stultz, and
9 * James Cleverdon.
Ashok Raj884d9e42005-06-25 14:55:02 -070010 * Ashok Raj <ashok.raj@intel.com>
11 * Removed IPI broadcast shortcut to support CPU hotplug
Linus Torvalds1da177e2005-04-16 15:20:36 -070012 */
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>
20#include <asm/smp.h>
21#include <asm/ipi.h>
22
23
24static cpumask_t flat_target_cpus(void)
25{
26 return cpu_online_map;
27}
28
29/*
30 * Set up the logical destination ID.
31 *
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...
35 */
36static void flat_init_apic_ldr(void)
37{
38 unsigned long val;
39 unsigned long num, id;
40
41 num = smp_processor_id();
42 id = 1UL << num;
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);
48}
49
Linus Torvalds1da177e2005-04-16 15:20:36 -070050static void flat_send_IPI_mask(cpumask_t cpumask, int vector)
51{
52 unsigned long mask = cpus_addr(cpumask)[0];
53 unsigned long cfg;
54 unsigned long flags;
55
56 local_save_flags(flags);
57 local_irq_disable();
58
59 /*
60 * Wait for idle.
61 */
62 apic_wait_icr_idle();
63
64 /*
65 * prepare target chip field
66 */
67 cfg = __prepare_ICR2(mask);
68 apic_write_around(APIC_ICR2, cfg);
69
70 /*
71 * program the ICR
72 */
73 cfg = __prepare_ICR(0, vector, APIC_DEST_LOGICAL);
74
75 /*
76 * Send the IPI. The write to APIC_ICR fires this off.
77 */
78 apic_write_around(APIC_ICR, cfg);
79 local_irq_restore(flags);
80}
81
Ashok Raj884d9e42005-06-25 14:55:02 -070082static void flat_send_IPI_allbutself(int vector)
83{
84 cpumask_t mask;
85 /*
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.
89 */
90 int this_cpu = get_cpu();
91
92 mask = cpu_online_map;
93 cpu_clear(this_cpu, mask);
94
95 if (cpus_weight(mask) >= 1)
96 flat_send_IPI_mask(mask, vector);
97
98 put_cpu();
99}
100
101static void flat_send_IPI_all(int vector)
102{
103 flat_send_IPI_mask(cpu_online_map, vector);
104}
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106static int flat_apic_id_registered(void)
107{
108 return physid_isset(GET_APIC_ID(apic_read(APIC_ID)), phys_cpu_present_map);
109}
110
111static unsigned int flat_cpu_mask_to_apicid(cpumask_t cpumask)
112{
113 return cpus_addr(cpumask)[0] & APIC_ALL_CPUS;
114}
115
116static unsigned int phys_pkg_id(int index_msb)
117{
118 u32 ebx;
119
120 ebx = cpuid_ebx(1);
121 return ((ebx >> 24) & 0xFF) >> index_msb;
122}
123
124struct genapic apic_flat = {
125 .name = "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,
137};