xref: /openbmc/linux/arch/x86/kernel/apic/bigsmp_32.c (revision b2441318)
1b2441318SGreg Kroah-Hartman // SPDX-License-Identifier: GPL-2.0
22a05180fSIngo Molnar /*
32a05180fSIngo Molnar  * APIC driver for "bigsmp" xAPIC machines with more than 8 virtual CPUs.
42a05180fSIngo Molnar  *
52a05180fSIngo Molnar  * Drives the local APIC in "clustered mode".
62a05180fSIngo Molnar  */
72a05180fSIngo Molnar #include <linux/threads.h>
82a05180fSIngo Molnar #include <linux/cpumask.h>
92a05180fSIngo Molnar #include <linux/kernel.h>
102a05180fSIngo Molnar #include <linux/init.h>
112a05180fSIngo Molnar #include <linux/dmi.h>
122a05180fSIngo Molnar #include <linux/smp.h>
132a05180fSIngo Molnar 
142a05180fSIngo Molnar #include <asm/apicdef.h>
152a05180fSIngo Molnar #include <asm/fixmap.h>
162a05180fSIngo Molnar #include <asm/mpspec.h>
172a05180fSIngo Molnar #include <asm/apic.h>
182a05180fSIngo Molnar #include <asm/ipi.h>
192a05180fSIngo Molnar 
209694cd6cSJiri Slaby static unsigned bigsmp_get_apic_id(unsigned long x)
212a05180fSIngo Molnar {
222a05180fSIngo Molnar 	return (x >> 24) & 0xFF;
232a05180fSIngo Molnar }
242a05180fSIngo Molnar 
259694cd6cSJiri Slaby static int bigsmp_apic_id_registered(void)
262a05180fSIngo Molnar {
272a05180fSIngo Molnar 	return 1;
282a05180fSIngo Molnar }
292a05180fSIngo Molnar 
307abc0753SCyrill Gorcunov static unsigned long bigsmp_check_apicid_used(physid_mask_t *map, int apicid)
312a05180fSIngo Molnar {
322a05180fSIngo Molnar 	return 0;
332a05180fSIngo Molnar }
342a05180fSIngo Molnar 
3512bf24a4STejun Heo static int bigsmp_early_logical_apicid(int cpu)
3612bf24a4STejun Heo {
3712bf24a4STejun Heo 	/* on bigsmp, logical apicid is the same as physical */
3812bf24a4STejun Heo 	return early_per_cpu(x86_cpu_to_apicid, cpu);
3912bf24a4STejun Heo }
4012bf24a4STejun Heo 
412a05180fSIngo Molnar static inline unsigned long calculate_ldr(int cpu)
422a05180fSIngo Molnar {
432a05180fSIngo Molnar 	unsigned long val, id;
442a05180fSIngo Molnar 
452a05180fSIngo Molnar 	val = apic_read(APIC_LDR) & ~APIC_LDR_MASK;
462a05180fSIngo Molnar 	id = per_cpu(x86_bios_cpu_apicid, cpu);
472a05180fSIngo Molnar 	val |= SET_APIC_LOGICAL_ID(id);
482a05180fSIngo Molnar 
492a05180fSIngo Molnar 	return val;
502a05180fSIngo Molnar }
512a05180fSIngo Molnar 
522a05180fSIngo Molnar /*
532a05180fSIngo Molnar  * Set up the logical destination ID.
542a05180fSIngo Molnar  *
552a05180fSIngo Molnar  * Intel recommends to set DFR, LDR and TPR before enabling
562a05180fSIngo Molnar  * an APIC.  See e.g. "AP-388 82489DX User's Manual" (Intel
572a05180fSIngo Molnar  * document number 292116).  So here it goes...
582a05180fSIngo Molnar  */
599694cd6cSJiri Slaby static void bigsmp_init_apic_ldr(void)
602a05180fSIngo Molnar {
612a05180fSIngo Molnar 	unsigned long val;
622a05180fSIngo Molnar 	int cpu = smp_processor_id();
632a05180fSIngo Molnar 
642a05180fSIngo Molnar 	apic_write(APIC_DFR, APIC_DFR_FLAT);
652a05180fSIngo Molnar 	val = calculate_ldr(cpu);
662a05180fSIngo Molnar 	apic_write(APIC_LDR, val);
672a05180fSIngo Molnar }
682a05180fSIngo Molnar 
699694cd6cSJiri Slaby static void bigsmp_setup_apic_routing(void)
702a05180fSIngo Molnar {
712a05180fSIngo Molnar 	printk(KERN_INFO
722a05180fSIngo Molnar 		"Enabling APIC mode:  Physflat.  Using %d I/O APICs\n",
732a05180fSIngo Molnar 		nr_ioapics);
742a05180fSIngo Molnar }
752a05180fSIngo Molnar 
769694cd6cSJiri Slaby static int bigsmp_cpu_present_to_apicid(int mps_cpu)
772a05180fSIngo Molnar {
782a05180fSIngo Molnar 	if (mps_cpu < nr_cpu_ids)
792a05180fSIngo Molnar 		return (int) per_cpu(x86_bios_cpu_apicid, mps_cpu);
802a05180fSIngo Molnar 
812a05180fSIngo Molnar 	return BAD_APICID;
822a05180fSIngo Molnar }
832a05180fSIngo Molnar 
847abc0753SCyrill Gorcunov static void bigsmp_ioapic_phys_id_map(physid_mask_t *phys_map, physid_mask_t *retmap)
852a05180fSIngo Molnar {
862a05180fSIngo Molnar 	/* For clustered we don't have a good way to do this yet - hack */
877abc0753SCyrill Gorcunov 	physids_promote(0xFFL, retmap);
882a05180fSIngo Molnar }
892a05180fSIngo Molnar 
90e11dadabSThomas Gleixner static int bigsmp_check_phys_apicid_present(int phys_apicid)
912a05180fSIngo Molnar {
922a05180fSIngo Molnar 	return 1;
932a05180fSIngo Molnar }
942a05180fSIngo Molnar 
959694cd6cSJiri Slaby static int bigsmp_phys_pkg_id(int cpuid_apic, int index_msb)
962a05180fSIngo Molnar {
972a05180fSIngo Molnar 	return cpuid_apic >> index_msb;
982a05180fSIngo Molnar }
992a05180fSIngo Molnar 
1009694cd6cSJiri Slaby static void bigsmp_send_IPI_allbutself(int vector)
1012a05180fSIngo Molnar {
1022a05180fSIngo Molnar 	default_send_IPI_mask_allbutself_phys(cpu_online_mask, vector);
1032a05180fSIngo Molnar }
1042a05180fSIngo Molnar 
1059694cd6cSJiri Slaby static void bigsmp_send_IPI_all(int vector)
1062a05180fSIngo Molnar {
107500bd02fSThomas Gleixner 	default_send_IPI_mask_sequence_phys(cpu_online_mask, vector);
1082a05180fSIngo Molnar }
1092a05180fSIngo Molnar 
1102a05180fSIngo Molnar static int dmi_bigsmp; /* can be set by dmi scanners */
1112a05180fSIngo Molnar 
1122a05180fSIngo Molnar static int hp_ht_bigsmp(const struct dmi_system_id *d)
1132a05180fSIngo Molnar {
1142a05180fSIngo Molnar 	printk(KERN_NOTICE "%s detected: force use of apic=bigsmp\n", d->ident);
1152a05180fSIngo Molnar 	dmi_bigsmp = 1;
1162a05180fSIngo Molnar 
1172a05180fSIngo Molnar 	return 0;
1182a05180fSIngo Molnar }
1192a05180fSIngo Molnar 
1202a05180fSIngo Molnar 
1212a05180fSIngo Molnar static const struct dmi_system_id bigsmp_dmi_table[] = {
1222a05180fSIngo Molnar 	{ hp_ht_bigsmp, "HP ProLiant DL760 G2",
1232a05180fSIngo Molnar 		{	DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
1242a05180fSIngo Molnar 			DMI_MATCH(DMI_BIOS_VERSION, "P44-"),
1252a05180fSIngo Molnar 		}
1262a05180fSIngo Molnar 	},
1272a05180fSIngo Molnar 
1282a05180fSIngo Molnar 	{ hp_ht_bigsmp, "HP ProLiant DL740",
1292a05180fSIngo Molnar 		{	DMI_MATCH(DMI_BIOS_VENDOR, "HP"),
1302a05180fSIngo Molnar 			DMI_MATCH(DMI_BIOS_VERSION, "P47-"),
1312a05180fSIngo Molnar 		}
1322a05180fSIngo Molnar 	},
1332a05180fSIngo Molnar 	{ } /* NULL entry stops DMI scanning */
1342a05180fSIngo Molnar };
1352a05180fSIngo Molnar 
1362a05180fSIngo Molnar static int probe_bigsmp(void)
1372a05180fSIngo Molnar {
1382a05180fSIngo Molnar 	if (def_to_bigsmp)
1392a05180fSIngo Molnar 		dmi_bigsmp = 1;
1402a05180fSIngo Molnar 	else
1412a05180fSIngo Molnar 		dmi_check_system(bigsmp_dmi_table);
1422a05180fSIngo Molnar 
1432a05180fSIngo Molnar 	return dmi_bigsmp;
1442a05180fSIngo Molnar }
1452a05180fSIngo Molnar 
146404f6aacSKees Cook static struct apic apic_bigsmp __ro_after_init = {
1472a05180fSIngo Molnar 
1482a05180fSIngo Molnar 	.name				= "bigsmp",
1492a05180fSIngo Molnar 	.probe				= probe_bigsmp,
1502a05180fSIngo Molnar 	.acpi_madt_oem_check		= NULL,
151fa63030eSDaniel J Blueman 	.apic_id_valid			= default_apic_id_valid,
1522a05180fSIngo Molnar 	.apic_id_registered		= bigsmp_apic_id_registered,
1532a05180fSIngo Molnar 
1542a05180fSIngo Molnar 	.irq_delivery_mode		= dest_Fixed,
1552a05180fSIngo Molnar 	/* phys delivery to target CPU: */
1562a05180fSIngo Molnar 	.irq_dest_mode			= 0,
1572a05180fSIngo Molnar 
158bf721d3aSAlexander Gordeev 	.target_cpus			= default_target_cpus,
1592a05180fSIngo Molnar 	.disable_esr			= 1,
1602a05180fSIngo Molnar 	.dest_logical			= 0,
1612a05180fSIngo Molnar 	.check_apicid_used		= bigsmp_check_apicid_used,
1622a05180fSIngo Molnar 
1639d8e1066SAlexander Gordeev 	.vector_allocation_domain	= default_vector_allocation_domain,
1642a05180fSIngo Molnar 	.init_apic_ldr			= bigsmp_init_apic_ldr,
1652a05180fSIngo Molnar 
1662a05180fSIngo Molnar 	.ioapic_phys_id_map		= bigsmp_ioapic_phys_id_map,
1672a05180fSIngo Molnar 	.setup_apic_routing		= bigsmp_setup_apic_routing,
1682a05180fSIngo Molnar 	.cpu_present_to_apicid		= bigsmp_cpu_present_to_apicid,
1697abc0753SCyrill Gorcunov 	.apicid_to_cpu_present		= physid_set_mask_of_physid,
1702a05180fSIngo Molnar 	.check_phys_apicid_present	= bigsmp_check_phys_apicid_present,
1712a05180fSIngo Molnar 	.phys_pkg_id			= bigsmp_phys_pkg_id,
1722a05180fSIngo Molnar 
1732a05180fSIngo Molnar 	.get_apic_id			= bigsmp_get_apic_id,
1742a05180fSIngo Molnar 	.set_apic_id			= NULL,
1752a05180fSIngo Molnar 
17691cd9cb7SThomas Gleixner 	.cpu_mask_to_apicid		= default_cpu_mask_to_apicid,
1772a05180fSIngo Molnar 
1785789a12eSThomas Gleixner 	.send_IPI			= default_send_IPI_single_phys,
179500bd02fSThomas Gleixner 	.send_IPI_mask			= default_send_IPI_mask_sequence_phys,
1802a05180fSIngo Molnar 	.send_IPI_mask_allbutself	= NULL,
1812a05180fSIngo Molnar 	.send_IPI_allbutself		= bigsmp_send_IPI_allbutself,
1822a05180fSIngo Molnar 	.send_IPI_all			= bigsmp_send_IPI_all,
1832a05180fSIngo Molnar 	.send_IPI_self			= default_send_IPI_self,
1842a05180fSIngo Molnar 
1852a05180fSIngo Molnar 	.inquire_remote_apic		= default_inquire_remote_apic,
1862a05180fSIngo Molnar 
1872a05180fSIngo Molnar 	.read				= native_apic_mem_read,
1882a05180fSIngo Molnar 	.write				= native_apic_mem_write,
1892a43195dSMichael S. Tsirkin 	.eoi_write			= native_apic_mem_write,
1902a05180fSIngo Molnar 	.icr_read			= native_apic_icr_read,
1912a05180fSIngo Molnar 	.icr_write			= native_apic_icr_write,
1922a05180fSIngo Molnar 	.wait_icr_idle			= native_apic_wait_icr_idle,
1932a05180fSIngo Molnar 	.safe_wait_icr_idle		= native_safe_apic_wait_icr_idle,
194acb8bc09STejun Heo 
19512bf24a4STejun Heo 	.x86_32_early_logical_apicid	= bigsmp_early_logical_apicid,
1962a05180fSIngo Molnar };
197107e0e0cSSuresh Siddha 
198838312beSJan Beulich void __init generic_bigsmp_probe(void)
19969c252ffSSuresh Siddha {
200838312beSJan Beulich 	unsigned int cpu;
20169c252ffSSuresh Siddha 
202838312beSJan Beulich 	if (!probe_bigsmp())
203838312beSJan Beulich 		return;
204838312beSJan Beulich 
205838312beSJan Beulich 	apic = &apic_bigsmp;
206838312beSJan Beulich 
207838312beSJan Beulich 	for_each_possible_cpu(cpu) {
208838312beSJan Beulich 		if (early_per_cpu(x86_cpu_to_logical_apicid,
209838312beSJan Beulich 				  cpu) == BAD_APICID)
210838312beSJan Beulich 			continue;
211838312beSJan Beulich 		early_per_cpu(x86_cpu_to_logical_apicid, cpu) =
212838312beSJan Beulich 			bigsmp_early_logical_apicid(cpu);
213838312beSJan Beulich 	}
214838312beSJan Beulich 
215838312beSJan Beulich 	pr_info("Overriding APIC driver with %s\n", apic_bigsmp.name);
21669c252ffSSuresh Siddha }
21769c252ffSSuresh Siddha 
218107e0e0cSSuresh Siddha apic_driver(apic_bigsmp);
219