1 // SPDX-License-Identifier: GPL-2.0-only 2 /* 3 * vSMPowered(tm) systems specific initialization 4 * Copyright (C) 2005 ScaleMP Inc. 5 * 6 * Ravikiran Thirumalai <kiran@scalemp.com>, 7 * Shai Fultheim <shai@scalemp.com> 8 * Paravirt ops integration: Glauber de Oliveira Costa <gcosta@redhat.com>, 9 * Ravikiran Thirumalai <kiran@scalemp.com> 10 */ 11 12 #include <linux/init.h> 13 #include <linux/pci_ids.h> 14 #include <linux/pci_regs.h> 15 #include <linux/smp.h> 16 #include <linux/irq.h> 17 18 #include <asm/apic.h> 19 #include <asm/pci-direct.h> 20 #include <asm/io.h> 21 #include <asm/setup.h> 22 23 #define TOPOLOGY_REGISTER_OFFSET 0x10 24 25 #ifdef CONFIG_PCI 26 static void __init set_vsmp_ctl(void) 27 { 28 void __iomem *address; 29 unsigned int cap, ctl, cfg; 30 31 /* set vSMP magic bits to indicate vSMP capable kernel */ 32 cfg = read_pci_config(0, 0x1f, 0, PCI_BASE_ADDRESS_0); 33 address = early_ioremap(cfg, 8); 34 cap = readl(address); 35 ctl = readl(address + 4); 36 printk(KERN_INFO "vSMP CTL: capabilities:0x%08x control:0x%08x\n", 37 cap, ctl); 38 39 /* If possible, let the vSMP foundation route the interrupt optimally */ 40 #ifdef CONFIG_SMP 41 if (cap & ctl & BIT(8)) { 42 ctl &= ~BIT(8); 43 44 #ifdef CONFIG_PROC_FS 45 /* Don't let users change irq affinity via procfs */ 46 no_irq_affinity = 1; 47 #endif 48 } 49 #endif 50 51 writel(ctl, address + 4); 52 ctl = readl(address + 4); 53 pr_info("vSMP CTL: control set to:0x%08x\n", ctl); 54 55 early_iounmap(address, 8); 56 } 57 static int is_vsmp = -1; 58 59 static void __init detect_vsmp_box(void) 60 { 61 is_vsmp = 0; 62 63 if (!early_pci_allowed()) 64 return; 65 66 /* Check if we are running on a ScaleMP vSMPowered box */ 67 if (read_pci_config(0, 0x1f, 0, PCI_VENDOR_ID) == 68 (PCI_VENDOR_ID_SCALEMP | (PCI_DEVICE_ID_SCALEMP_VSMP_CTL << 16))) 69 is_vsmp = 1; 70 } 71 72 static int is_vsmp_box(void) 73 { 74 if (is_vsmp != -1) 75 return is_vsmp; 76 else { 77 WARN_ON_ONCE(1); 78 return 0; 79 } 80 } 81 82 #else 83 static void __init detect_vsmp_box(void) 84 { 85 } 86 static int is_vsmp_box(void) 87 { 88 return 0; 89 } 90 static void __init set_vsmp_ctl(void) 91 { 92 } 93 #endif 94 95 static void __init vsmp_cap_cpus(void) 96 { 97 #if !defined(CONFIG_X86_VSMP) && defined(CONFIG_SMP) && defined(CONFIG_PCI) 98 void __iomem *address; 99 unsigned int cfg, topology, node_shift, maxcpus; 100 101 /* 102 * CONFIG_X86_VSMP is not configured, so limit the number CPUs to the 103 * ones present in the first board, unless explicitly overridden by 104 * setup_max_cpus 105 */ 106 if (setup_max_cpus != NR_CPUS) 107 return; 108 109 /* Read the vSMP Foundation topology register */ 110 cfg = read_pci_config(0, 0x1f, 0, PCI_BASE_ADDRESS_0); 111 address = early_ioremap(cfg + TOPOLOGY_REGISTER_OFFSET, 4); 112 if (WARN_ON(!address)) 113 return; 114 115 topology = readl(address); 116 node_shift = (topology >> 16) & 0x7; 117 if (!node_shift) 118 /* The value 0 should be decoded as 8 */ 119 node_shift = 8; 120 maxcpus = (topology & ((1 << node_shift) - 1)) + 1; 121 122 pr_info("vSMP CTL: Capping CPUs to %d (CONFIG_X86_VSMP is unset)\n", 123 maxcpus); 124 setup_max_cpus = maxcpus; 125 early_iounmap(address, 4); 126 #endif 127 } 128 129 void __init vsmp_init(void) 130 { 131 detect_vsmp_box(); 132 if (!is_vsmp_box()) 133 return; 134 135 vsmp_cap_cpus(); 136 137 set_vsmp_ctl(); 138 return; 139 } 140