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