vsmp_64.c 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  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 <asm/apic.h>
  19. #include <asm/pci-direct.h>
  20. #include <asm/io.h>
  21. #include <asm/paravirt.h>
  22. #include <asm/setup.h>
  23. #define TOPOLOGY_REGISTER_OFFSET 0x10
  24. #if defined CONFIG_PCI && defined CONFIG_PARAVIRT
  25. /*
  26. * Interrupt control on vSMPowered systems:
  27. * ~AC is a shadow of IF. If IF is 'on' AC should be 'off'
  28. * and vice versa.
  29. */
  30. static unsigned long vsmp_save_fl(void)
  31. {
  32. unsigned long flags = native_save_fl();
  33. if (!(flags & X86_EFLAGS_IF) || (flags & X86_EFLAGS_AC))
  34. flags &= ~X86_EFLAGS_IF;
  35. return flags;
  36. }
  37. PV_CALLEE_SAVE_REGS_THUNK(vsmp_save_fl);
  38. static void vsmp_restore_fl(unsigned long flags)
  39. {
  40. if (flags & X86_EFLAGS_IF)
  41. flags &= ~X86_EFLAGS_AC;
  42. else
  43. flags |= X86_EFLAGS_AC;
  44. native_restore_fl(flags);
  45. }
  46. PV_CALLEE_SAVE_REGS_THUNK(vsmp_restore_fl);
  47. static void vsmp_irq_disable(void)
  48. {
  49. unsigned long flags = native_save_fl();
  50. native_restore_fl((flags & ~X86_EFLAGS_IF) | X86_EFLAGS_AC);
  51. }
  52. PV_CALLEE_SAVE_REGS_THUNK(vsmp_irq_disable);
  53. static void vsmp_irq_enable(void)
  54. {
  55. unsigned long flags = native_save_fl();
  56. native_restore_fl((flags | X86_EFLAGS_IF) & (~X86_EFLAGS_AC));
  57. }
  58. PV_CALLEE_SAVE_REGS_THUNK(vsmp_irq_enable);
  59. static unsigned __init_or_module vsmp_patch(u8 type, u16 clobbers, void *ibuf,
  60. unsigned long addr, unsigned len)
  61. {
  62. switch (type) {
  63. case PARAVIRT_PATCH(pv_irq_ops.irq_enable):
  64. case PARAVIRT_PATCH(pv_irq_ops.irq_disable):
  65. case PARAVIRT_PATCH(pv_irq_ops.save_fl):
  66. case PARAVIRT_PATCH(pv_irq_ops.restore_fl):
  67. return paravirt_patch_default(type, clobbers, ibuf, addr, len);
  68. default:
  69. return native_patch(type, clobbers, ibuf, addr, len);
  70. }
  71. }
  72. static void __init set_vsmp_pv_ops(void)
  73. {
  74. void __iomem *address;
  75. unsigned int cap, ctl, cfg;
  76. /* set vSMP magic bits to indicate vSMP capable kernel */
  77. cfg = read_pci_config(0, 0x1f, 0, PCI_BASE_ADDRESS_0);
  78. address = early_ioremap(cfg, 8);
  79. cap = readl(address);
  80. ctl = readl(address + 4);
  81. printk(KERN_INFO "vSMP CTL: capabilities:0x%08x control:0x%08x\n",
  82. cap, ctl);
  83. if (cap & ctl & (1 << 4)) {
  84. /* Setup irq ops and turn on vSMP IRQ fastpath handling */
  85. pv_irq_ops.irq_disable = PV_CALLEE_SAVE(vsmp_irq_disable);
  86. pv_irq_ops.irq_enable = PV_CALLEE_SAVE(vsmp_irq_enable);
  87. pv_irq_ops.save_fl = PV_CALLEE_SAVE(vsmp_save_fl);
  88. pv_irq_ops.restore_fl = PV_CALLEE_SAVE(vsmp_restore_fl);
  89. pv_init_ops.patch = vsmp_patch;
  90. ctl &= ~(1 << 4);
  91. writel(ctl, address + 4);
  92. ctl = readl(address + 4);
  93. printk(KERN_INFO "vSMP CTL: control set to:0x%08x\n", ctl);
  94. }
  95. early_iounmap(address, 8);
  96. }
  97. #else
  98. static void __init set_vsmp_pv_ops(void)
  99. {
  100. }
  101. #endif
  102. #ifdef CONFIG_PCI
  103. static int is_vsmp = -1;
  104. static void __init detect_vsmp_box(void)
  105. {
  106. is_vsmp = 0;
  107. if (!early_pci_allowed())
  108. return;
  109. /* Check if we are running on a ScaleMP vSMPowered box */
  110. if (read_pci_config(0, 0x1f, 0, PCI_VENDOR_ID) ==
  111. (PCI_VENDOR_ID_SCALEMP | (PCI_DEVICE_ID_SCALEMP_VSMP_CTL << 16)))
  112. is_vsmp = 1;
  113. }
  114. int is_vsmp_box(void)
  115. {
  116. if (is_vsmp != -1)
  117. return is_vsmp;
  118. else {
  119. WARN_ON_ONCE(1);
  120. return 0;
  121. }
  122. }
  123. #else
  124. static void __init detect_vsmp_box(void)
  125. {
  126. }
  127. int is_vsmp_box(void)
  128. {
  129. return 0;
  130. }
  131. #endif
  132. static void __init vsmp_cap_cpus(void)
  133. {
  134. #if !defined(CONFIG_X86_VSMP) && defined(CONFIG_SMP)
  135. void __iomem *address;
  136. unsigned int cfg, topology, node_shift, maxcpus;
  137. /*
  138. * CONFIG_X86_VSMP is not configured, so limit the number CPUs to the
  139. * ones present in the first board, unless explicitly overridden by
  140. * setup_max_cpus
  141. */
  142. if (setup_max_cpus != NR_CPUS)
  143. return;
  144. /* Read the vSMP Foundation topology register */
  145. cfg = read_pci_config(0, 0x1f, 0, PCI_BASE_ADDRESS_0);
  146. address = early_ioremap(cfg + TOPOLOGY_REGISTER_OFFSET, 4);
  147. if (WARN_ON(!address))
  148. return;
  149. topology = readl(address);
  150. node_shift = (topology >> 16) & 0x7;
  151. if (!node_shift)
  152. /* The value 0 should be decoded as 8 */
  153. node_shift = 8;
  154. maxcpus = (topology & ((1 << node_shift) - 1)) + 1;
  155. pr_info("vSMP CTL: Capping CPUs to %d (CONFIG_X86_VSMP is unset)\n",
  156. maxcpus);
  157. setup_max_cpus = maxcpus;
  158. early_iounmap(address, 4);
  159. #endif
  160. }
  161. void __init vsmp_init(void)
  162. {
  163. detect_vsmp_box();
  164. if (!is_vsmp_box())
  165. return;
  166. vsmp_cap_cpus();
  167. set_vsmp_pv_ops();
  168. return;
  169. }