vsmp_64.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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/pci-direct.h>
  18. #include <asm/io.h>
  19. #include <asm/paravirt.h>
  20. /*
  21. * Interrupt control on vSMPowered systems:
  22. * ~AC is a shadow of IF. If IF is 'on' AC should be 'off'
  23. * and vice versa.
  24. */
  25. static unsigned long vsmp_save_fl(void)
  26. {
  27. unsigned long flags = native_save_fl();
  28. if (!(flags & X86_EFLAGS_IF) || (flags & X86_EFLAGS_AC))
  29. flags &= ~X86_EFLAGS_IF;
  30. return flags;
  31. }
  32. static void vsmp_restore_fl(unsigned long flags)
  33. {
  34. if (flags & X86_EFLAGS_IF)
  35. flags &= ~X86_EFLAGS_AC;
  36. else
  37. flags |= X86_EFLAGS_AC;
  38. native_restore_fl(flags);
  39. }
  40. static void vsmp_irq_disable(void)
  41. {
  42. unsigned long flags = native_save_fl();
  43. native_restore_fl((flags & ~X86_EFLAGS_IF) | X86_EFLAGS_AC);
  44. }
  45. static void vsmp_irq_enable(void)
  46. {
  47. unsigned long flags = native_save_fl();
  48. native_restore_fl((flags | X86_EFLAGS_IF) & (~X86_EFLAGS_AC));
  49. }
  50. static unsigned __init vsmp_patch(u8 type, u16 clobbers, void *ibuf,
  51. unsigned long addr, unsigned len)
  52. {
  53. switch (type) {
  54. case PARAVIRT_PATCH(pv_irq_ops.irq_enable):
  55. case PARAVIRT_PATCH(pv_irq_ops.irq_disable):
  56. case PARAVIRT_PATCH(pv_irq_ops.save_fl):
  57. case PARAVIRT_PATCH(pv_irq_ops.restore_fl):
  58. return paravirt_patch_default(type, clobbers, ibuf, addr, len);
  59. default:
  60. return native_patch(type, clobbers, ibuf, addr, len);
  61. }
  62. }
  63. void __init vsmp_init(void)
  64. {
  65. void *address;
  66. unsigned int cap, ctl, cfg;
  67. if (!early_pci_allowed())
  68. return;
  69. /* Check if we are running on a ScaleMP vSMP box */
  70. if ((read_pci_config_16(0, 0x1f, 0, PCI_VENDOR_ID) !=
  71. PCI_VENDOR_ID_SCALEMP) ||
  72. (read_pci_config_16(0, 0x1f, 0, PCI_DEVICE_ID) !=
  73. PCI_DEVICE_ID_SCALEMP_VSMP_CTL))
  74. return;
  75. /* If we are, use the distinguished irq functions */
  76. pv_irq_ops.irq_disable = vsmp_irq_disable;
  77. pv_irq_ops.irq_enable = vsmp_irq_enable;
  78. pv_irq_ops.save_fl = vsmp_save_fl;
  79. pv_irq_ops.restore_fl = vsmp_restore_fl;
  80. pv_init_ops.patch = vsmp_patch;
  81. /* set vSMP magic bits to indicate vSMP capable kernel */
  82. cfg = read_pci_config(0, 0x1f, 0, PCI_BASE_ADDRESS_0);
  83. address = early_ioremap(cfg, 8);
  84. cap = readl(address);
  85. ctl = readl(address + 4);
  86. printk(KERN_INFO "vSMP CTL: capabilities:0x%08x control:0x%08x\n",
  87. cap, ctl);
  88. if (cap & ctl & (1 << 4)) {
  89. /* Turn on vSMP IRQ fastpath handling (see system.h) */
  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. return;
  97. }