vsmp_64.c 3.4 KB

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