vsmp_64.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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 <asm/apic.h>
  18. #include <asm/pci-direct.h>
  19. #include <asm/io.h>
  20. #include <asm/paravirt.h>
  21. #include <asm/setup.h>
  22. #if defined CONFIG_PCI && defined CONFIG_PARAVIRT
  23. /*
  24. * Interrupt control on vSMPowered systems:
  25. * ~AC is a shadow of IF. If IF is 'on' AC should be 'off'
  26. * and vice versa.
  27. */
  28. static unsigned long vsmp_save_fl(void)
  29. {
  30. unsigned long flags = native_save_fl();
  31. if (!(flags & X86_EFLAGS_IF) || (flags & X86_EFLAGS_AC))
  32. flags &= ~X86_EFLAGS_IF;
  33. return flags;
  34. }
  35. PV_CALLEE_SAVE_REGS_THUNK(vsmp_save_fl);
  36. static void vsmp_restore_fl(unsigned long flags)
  37. {
  38. if (flags & X86_EFLAGS_IF)
  39. flags &= ~X86_EFLAGS_AC;
  40. else
  41. flags |= X86_EFLAGS_AC;
  42. native_restore_fl(flags);
  43. }
  44. PV_CALLEE_SAVE_REGS_THUNK(vsmp_restore_fl);
  45. static void vsmp_irq_disable(void)
  46. {
  47. unsigned long flags = native_save_fl();
  48. native_restore_fl((flags & ~X86_EFLAGS_IF) | X86_EFLAGS_AC);
  49. }
  50. PV_CALLEE_SAVE_REGS_THUNK(vsmp_irq_disable);
  51. static void vsmp_irq_enable(void)
  52. {
  53. unsigned long flags = native_save_fl();
  54. native_restore_fl((flags | X86_EFLAGS_IF) & (~X86_EFLAGS_AC));
  55. }
  56. PV_CALLEE_SAVE_REGS_THUNK(vsmp_irq_enable);
  57. static unsigned __init_or_module vsmp_patch(u8 type, u16 clobbers, void *ibuf,
  58. unsigned long addr, unsigned len)
  59. {
  60. switch (type) {
  61. case PARAVIRT_PATCH(pv_irq_ops.irq_enable):
  62. case PARAVIRT_PATCH(pv_irq_ops.irq_disable):
  63. case PARAVIRT_PATCH(pv_irq_ops.save_fl):
  64. case PARAVIRT_PATCH(pv_irq_ops.restore_fl):
  65. return paravirt_patch_default(type, clobbers, ibuf, addr, len);
  66. default:
  67. return native_patch(type, clobbers, ibuf, addr, len);
  68. }
  69. }
  70. static void __init set_vsmp_pv_ops(void)
  71. {
  72. void __iomem *address;
  73. unsigned int cap, ctl, cfg;
  74. /* set vSMP magic bits to indicate vSMP capable kernel */
  75. cfg = read_pci_config(0, 0x1f, 0, PCI_BASE_ADDRESS_0);
  76. address = early_ioremap(cfg, 8);
  77. cap = readl(address);
  78. ctl = readl(address + 4);
  79. printk(KERN_INFO "vSMP CTL: capabilities:0x%08x control:0x%08x\n",
  80. cap, ctl);
  81. if (cap & ctl & (1 << 4)) {
  82. /* Setup irq ops and turn on vSMP IRQ fastpath handling */
  83. pv_irq_ops.irq_disable = PV_CALLEE_SAVE(vsmp_irq_disable);
  84. pv_irq_ops.irq_enable = PV_CALLEE_SAVE(vsmp_irq_enable);
  85. pv_irq_ops.save_fl = PV_CALLEE_SAVE(vsmp_save_fl);
  86. pv_irq_ops.restore_fl = PV_CALLEE_SAVE(vsmp_restore_fl);
  87. pv_init_ops.patch = vsmp_patch;
  88. ctl &= ~(1 << 4);
  89. writel(ctl, address + 4);
  90. ctl = readl(address + 4);
  91. printk(KERN_INFO "vSMP CTL: control set to:0x%08x\n", ctl);
  92. }
  93. early_iounmap(address, 8);
  94. }
  95. #else
  96. static void __init set_vsmp_pv_ops(void)
  97. {
  98. }
  99. #endif
  100. #ifdef CONFIG_PCI
  101. static int is_vsmp = -1;
  102. static void __init detect_vsmp_box(void)
  103. {
  104. is_vsmp = 0;
  105. if (!early_pci_allowed())
  106. return;
  107. /* Check if we are running on a ScaleMP vSMPowered box */
  108. if (read_pci_config(0, 0x1f, 0, PCI_VENDOR_ID) ==
  109. (PCI_VENDOR_ID_SCALEMP | (PCI_DEVICE_ID_SCALEMP_VSMP_CTL << 16)))
  110. is_vsmp = 1;
  111. }
  112. int is_vsmp_box(void)
  113. {
  114. if (is_vsmp != -1)
  115. return is_vsmp;
  116. else {
  117. WARN_ON_ONCE(1);
  118. return 0;
  119. }
  120. }
  121. #else
  122. static void __init detect_vsmp_box(void)
  123. {
  124. }
  125. int is_vsmp_box(void)
  126. {
  127. return 0;
  128. }
  129. #endif
  130. void __init vsmp_init(void)
  131. {
  132. detect_vsmp_box();
  133. if (!is_vsmp_box())
  134. return;
  135. set_vsmp_pv_ops();
  136. return;
  137. }