xref: /openbmc/linux/arch/x86/kernel/apic/bigsmp_32.c (revision c94f0718)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * APIC driver for "bigsmp" xAPIC machines with more than 8 virtual CPUs.
4  *
5  * Drives the local APIC in "clustered mode".
6  */
7 #include <linux/cpumask.h>
8 #include <linux/dmi.h>
9 #include <linux/smp.h>
10 
11 #include <asm/apic.h>
12 
13 #include "local.h"
14 
15 static unsigned bigsmp_get_apic_id(unsigned long x)
16 {
17 	return (x >> 24) & 0xFF;
18 }
19 
20 static int bigsmp_apic_id_registered(void)
21 {
22 	return 1;
23 }
24 
25 static bool bigsmp_check_apicid_used(physid_mask_t *map, int apicid)
26 {
27 	return false;
28 }
29 
30 static int bigsmp_early_logical_apicid(int cpu)
31 {
32 	/* on bigsmp, logical apicid is the same as physical */
33 	return early_per_cpu(x86_cpu_to_apicid, cpu);
34 }
35 
36 static inline unsigned long calculate_ldr(int cpu)
37 {
38 	unsigned long val, id;
39 
40 	val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
41 	id = per_cpu(x86_bios_cpu_apicid, cpu);
42 	val |= SET_APIC_LOGICAL_ID(id);
43 
44 	return val;
45 }
46 
47 /*
48  * Set up the logical destination ID.
49  *
50  * Intel recommends to set DFR, LDR and TPR before enabling
51  * an APIC.  See e.g. "AP-388 82489DX User's Manual" (Intel
52  * document number 292116).  So here it goes...
53  */
54 static void bigsmp_init_apic_ldr(void)
55 {
56 	unsigned long val;
57 	int cpu = smp_processor_id();
58 
59 	apic_write(APIC_DFR, APIC_DFR_FLAT);
60 	val = calculate_ldr(cpu);
61 	apic_write(APIC_LDR, val);
62 }
63 
64 static void bigsmp_setup_apic_routing(void)
65 {
66 	printk(KERN_INFO
67 		"Enabling APIC mode:  Physflat.  Using %d I/O APICs\n",
68 		nr_ioapics);
69 }
70 
71 static int bigsmp_cpu_present_to_apicid(int mps_cpu)
72 {
73 	if (mps_cpu < nr_cpu_ids)
74 		return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
75 
76 	return BAD_APICID;
77 }
78 
79 static void bigsmp_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap)
80 {
81 	/* For clustered we don't have a good way to do this yet - hack */
82 	physids_promote(0xFFL, retmap);
83 }
84 
85 static int bigsmp_check_phys_apicid_present(int phys_apicid)
86 {
87 	return 1;
88 }
89 
90 static int bigsmp_phys_pkg_id(int cpuid_apic, int index_msb)
91 {
92 	return cpuid_apic >> index_msb;
93 }
94 
95 static void bigsmp_send_IPI_allbutself(int vector)
96 {
97 	default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector);
98 }
99 
100 static void bigsmp_send_IPI_all(int vector)
101 {
102 	default_send_IPI_mask_sequence_phys(cpu_online_mask, vector);
103 }
104 
105 static int dmi_bigsmp; /* can be set by dmi scanners */
106 
107 static int hp_ht_bigsmp(const struct dmi_system_id *d)
108 {
109 	printk(KERN_NOTICE "%s detected: force use of apic=bigsmp\n", d->ident);
110 	dmi_bigsmp = 1;
111 
112 	return 0;
113 }
114 
115 
116 static const struct dmi_system_id bigsmp_dmi_table[] = {
117 	{ hp_ht_bigsmp, "HP ProLiant DL760 G2",
118 		{	DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
119 			DMI_MATCH(DMI_BIOS_VERSION, "P44-"),
120 		}
121 	},
122 
123 	{ hp_ht_bigsmp, "HP ProLiant DL740",
124 		{	DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
125 			DMI_MATCH(DMI_BIOS_VERSION, "P47-"),
126 		}
127 	},
128 	{ } /* NULL entry stops DMI scanning */
129 };
130 
131 static int probe_bigsmp(void)
132 {
133 	if (def_to_bigsmp)
134 		dmi_bigsmp = 1;
135 	else
136 		dmi_check_system(bigsmp_dmi_table);
137 
138 	return dmi_bigsmp;
139 }
140 
141 static struct apic apic_bigsmp __ro_after_init = {
142 
143 	.name				= "bigsmp",
144 	.probe				= probe_bigsmp,
145 	.acpi_madt_oem_check		= NULL,
146 	.apic_id_valid			= default_apic_id_valid,
147 	.apic_id_registered		= bigsmp_apic_id_registered,
148 
149 	.irq_delivery_mode		= dest_Fixed,
150 	/* phys delivery to target CPU: */
151 	.irq_dest_mode			= 0,
152 
153 	.disable_esr			= 1,
154 	.dest_logical			= 0,
155 	.check_apicid_used		= bigsmp_check_apicid_used,
156 
157 	.init_apic_ldr			= bigsmp_init_apic_ldr,
158 
159 	.ioapic_phys_id_map		= bigsmp_ioapic_phys_id_map,
160 	.setup_apic_routing		= bigsmp_setup_apic_routing,
161 	.cpu_present_to_apicid		= bigsmp_cpu_present_to_apicid,
162 	.apicid_to_cpu_present		= physid_set_mask_of_physid,
163 	.check_phys_apicid_present	= bigsmp_check_phys_apicid_present,
164 	.phys_pkg_id			= bigsmp_phys_pkg_id,
165 
166 	.get_apic_id			= bigsmp_get_apic_id,
167 	.set_apic_id			= NULL,
168 
169 	.calc_dest_apicid		= apic_default_calc_apicid,
170 
171 	.send_IPI			= default_send_IPI_single_phys,
172 	.send_IPI_mask			= default_send_IPI_mask_sequence_phys,
173 	.send_IPI_mask_allbutself	= NULL,
174 	.send_IPI_allbutself		= bigsmp_send_IPI_allbutself,
175 	.send_IPI_all			= bigsmp_send_IPI_all,
176 	.send_IPI_self			= default_send_IPI_self,
177 
178 	.inquire_remote_apic		= default_inquire_remote_apic,
179 
180 	.read				= native_apic_mem_read,
181 	.write				= native_apic_mem_write,
182 	.eoi_write			= native_apic_mem_write,
183 	.icr_read			= native_apic_icr_read,
184 	.icr_write			= native_apic_icr_write,
185 	.wait_icr_idle			= native_apic_wait_icr_idle,
186 	.safe_wait_icr_idle		= native_safe_apic_wait_icr_idle,
187 
188 	.x86_32_early_logical_apicid	= bigsmp_early_logical_apicid,
189 };
190 
191 void __init generic_bigsmp_probe(void)
192 {
193 	unsigned int cpu;
194 
195 	if (!probe_bigsmp())
196 		return;
197 
198 	apic = &apic_bigsmp;
199 
200 	for_each_possible_cpu(cpu) {
201 		if (early_per_cpu(x86_cpu_to_logical_apicid,
202 				  cpu) == BAD_APICID)
203 			continue;
204 		early_per_cpu(x86_cpu_to_logical_apicid, cpu) =
205 			bigsmp_early_logical_apicid(cpu);
206 	}
207 
208 	pr_info("Overriding APIC driver with %s\n", apic_bigsmp.name);
209 }
210 
211 apic_driver(apic_bigsmp);
212