]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - arch/x86_64/kernel/genapic_flat.c
[PATCH] x86_64: Implemenent machine_emergency_restart
[mirror_ubuntu-jammy-kernel.git] / arch / x86_64 / kernel / genapic_flat.c
CommitLineData
1da177e4
LT
1/*
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.
884d9e40
AR
10 * Ashok Raj <ashok.raj@intel.com>
11 * Removed IPI broadcast shortcut to support CPU hotplug
1da177e4
LT
12 */
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
a02c4cb6
AR
23/*
24 * The following permit choosing broadcast IPI shortcut v.s sending IPI only
25 * to online cpus via the send_IPI_mask varient.
26 * The mask version is my preferred option, since it eliminates a lot of
27 * other extra code that would need to be written to cleanup intrs sent
28 * to a CPU while offline.
29 *
30 * Sending broadcast introduces lots of trouble in CPU hotplug situations.
31 * These IPI's are delivered to cpu's irrespective of their offline status
32 * and could pickup stale intr data when these CPUS are turned online.
33 *
34 * Not using broadcast is a cleaner approach IMO, but Andi Kleen disagrees with
35 * the idea of not using broadcast IPI's anymore. Hence the run time check
36 * is introduced, on his request so we can choose an alternate mechanism.
37 *
38 * Initial wacky performance tests that collect cycle counts show
39 * no increase in using mask v.s broadcast version. In fact they seem
40 * identical in terms of cycle counts.
41 *
42 * if we need to use broadcast, we need to do the following.
43 *
44 * cli;
45 * hold call_lock;
46 * clear any pending IPI, just ack and clear all pending intr
47 * set cpu_online_map;
48 * release call_lock;
49 * sti;
50 *
51 * The complicated dummy irq processing shown above is not required if
52 * we didnt sent IPI's to wrong CPU's in the first place.
53 *
54 * - Ashok Raj <ashok.raj@intel.com>
55 */
56#ifdef CONFIG_HOTPLUG_CPU
57#define DEFAULT_SEND_IPI (1)
58#else
59#define DEFAULT_SEND_IPI (0)
60#endif
61
62static int no_broadcast=DEFAULT_SEND_IPI;
1da177e4
LT
63
64static cpumask_t flat_target_cpus(void)
65{
66 return cpu_online_map;
67}
68
69/*
70 * Set up the logical destination ID.
71 *
72 * Intel recommends to set DFR, LDR and TPR before enabling
73 * an APIC. See e.g. "AP-388 82489DX User's Manual" (Intel
74 * document number 292116). So here it goes...
75 */
76static void flat_init_apic_ldr(void)
77{
78 unsigned long val;
79 unsigned long num, id;
80
81 num = smp_processor_id();
82 id = 1UL << num;
83 x86_cpu_to_log_apicid[num] = id;
84 apic_write_around(APIC_DFR, APIC_DFR_FLAT);
85 val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
86 val |= SET_APIC_LOGICAL_ID(id);
87 apic_write_around(APIC_LDR, val);
88}
89
1da177e4
LT
90static void flat_send_IPI_mask(cpumask_t cpumask, int vector)
91{
92 unsigned long mask = cpus_addr(cpumask)[0];
93 unsigned long cfg;
94 unsigned long flags;
95
96 local_save_flags(flags);
97 local_irq_disable();
98
99 /*
100 * Wait for idle.
101 */
102 apic_wait_icr_idle();
103
104 /*
105 * prepare target chip field
106 */
107 cfg = __prepare_ICR2(mask);
108 apic_write_around(APIC_ICR2, cfg);
109
110 /*
111 * program the ICR
112 */
113 cfg = __prepare_ICR(0, vector, APIC_DEST_LOGICAL);
114
115 /*
116 * Send the IPI. The write to APIC_ICR fires this off.
117 */
118 apic_write_around(APIC_ICR, cfg);
119 local_irq_restore(flags);
120}
121
a02c4cb6 122static inline void __local_flat_send_IPI_allbutself(int vector)
884d9e40 123{
a02c4cb6
AR
124 if (no_broadcast) {
125 cpumask_t mask = cpu_online_map;
126 int this_cpu = get_cpu();
884d9e40 127
a02c4cb6 128 cpu_clear(this_cpu, mask);
884d9e40 129 flat_send_IPI_mask(mask, vector);
a02c4cb6
AR
130 put_cpu();
131 }
132 else
133 __send_IPI_shortcut(APIC_DEST_ALLBUT, vector, APIC_DEST_LOGICAL);
134}
884d9e40 135
a02c4cb6
AR
136static inline void __local_flat_send_IPI_all(int vector)
137{
138 if (no_broadcast)
139 flat_send_IPI_mask(cpu_online_map, vector);
140 else
141 __send_IPI_shortcut(APIC_DEST_ALLINC, vector, APIC_DEST_LOGICAL);
142}
143
144static void flat_send_IPI_allbutself(int vector)
145{
146 if (((num_online_cpus()) - 1) >= 1)
147 __local_flat_send_IPI_allbutself(vector);
884d9e40
AR
148}
149
150static void flat_send_IPI_all(int vector)
151{
a02c4cb6 152 __local_flat_send_IPI_all(vector);
884d9e40
AR
153}
154
1da177e4
LT
155static int flat_apic_id_registered(void)
156{
157 return physid_isset(GET_APIC_ID(apic_read(APIC_ID)), phys_cpu_present_map);
158}
159
160static unsigned int flat_cpu_mask_to_apicid(cpumask_t cpumask)
161{
162 return cpus_addr(cpumask)[0] & APIC_ALL_CPUS;
163}
164
165static unsigned int phys_pkg_id(int index_msb)
166{
167 u32 ebx;
168
169 ebx = cpuid_ebx(1);
170 return ((ebx >> 24) & 0xFF) >> index_msb;
171}
172
a02c4cb6
AR
173static __init int no_ipi_broadcast(char *str)
174{
175 get_option(&str, &no_broadcast);
176 printk ("Using %s mode\n", no_broadcast ? "No IPI Broadcast" :
177 "IPI Broadcast");
178 return 1;
179}
180
181__setup("no_ipi_broadcast", no_ipi_broadcast);
182
1da177e4
LT
183struct genapic apic_flat = {
184 .name = "flat",
185 .int_delivery_mode = dest_LowestPrio,
186 .int_dest_mode = (APIC_DEST_LOGICAL != 0),
187 .int_delivery_dest = APIC_DEST_LOGICAL | APIC_DM_LOWEST,
188 .target_cpus = flat_target_cpus,
189 .apic_id_registered = flat_apic_id_registered,
190 .init_apic_ldr = flat_init_apic_ldr,
191 .send_IPI_all = flat_send_IPI_all,
192 .send_IPI_allbutself = flat_send_IPI_allbutself,
193 .send_IPI_mask = flat_send_IPI_mask,
194 .cpu_mask_to_apicid = flat_cpu_mask_to_apicid,
195 .phys_pkg_id = phys_pkg_id,
196};
a02c4cb6
AR
197
198static int __init print_ipi_mode(void)
199{
200 printk ("Using IPI %s mode\n", no_broadcast ? "No-Shortcut" :
201 "Shortcut");
202 return 0;
203}
204
205late_initcall(print_ipi_mode);