platform-pci-unplug.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /******************************************************************************
  2. * platform-pci-unplug.c
  3. *
  4. * Xen platform PCI device driver
  5. * Copyright (c) 2010, Citrix
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms and conditions of the GNU General Public License,
  9. * version 2, as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope it will be useful, but WITHOUT
  12. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  14. * more details.
  15. *
  16. * You should have received a copy of the GNU General Public License along with
  17. * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
  18. * Place - Suite 330, Boston, MA 02111-1307 USA.
  19. *
  20. */
  21. #include <linux/init.h>
  22. #include <linux/io.h>
  23. #include <linux/module.h>
  24. #include <xen/platform_pci.h>
  25. #include "xen-ops.h"
  26. #define XEN_PLATFORM_ERR_MAGIC -1
  27. #define XEN_PLATFORM_ERR_PROTOCOL -2
  28. #define XEN_PLATFORM_ERR_BLACKLIST -3
  29. /* store the value of xen_emul_unplug after the unplug is done */
  30. int xen_platform_pci_unplug;
  31. EXPORT_SYMBOL_GPL(xen_platform_pci_unplug);
  32. #ifdef CONFIG_XEN_PVHVM
  33. static int xen_emul_unplug;
  34. static int check_platform_magic(void)
  35. {
  36. short magic;
  37. char protocol;
  38. magic = inw(XEN_IOPORT_MAGIC);
  39. if (magic != XEN_IOPORT_MAGIC_VAL) {
  40. printk(KERN_ERR "Xen Platform PCI: unrecognised magic value\n");
  41. return XEN_PLATFORM_ERR_MAGIC;
  42. }
  43. protocol = inb(XEN_IOPORT_PROTOVER);
  44. printk(KERN_DEBUG "Xen Platform PCI: I/O protocol version %d\n",
  45. protocol);
  46. switch (protocol) {
  47. case 1:
  48. outw(XEN_IOPORT_LINUX_PRODNUM, XEN_IOPORT_PRODNUM);
  49. outl(XEN_IOPORT_LINUX_DRVVER, XEN_IOPORT_DRVVER);
  50. if (inw(XEN_IOPORT_MAGIC) != XEN_IOPORT_MAGIC_VAL) {
  51. printk(KERN_ERR "Xen Platform: blacklisted by host\n");
  52. return XEN_PLATFORM_ERR_BLACKLIST;
  53. }
  54. break;
  55. default:
  56. printk(KERN_WARNING "Xen Platform PCI: unknown I/O protocol version");
  57. return XEN_PLATFORM_ERR_PROTOCOL;
  58. }
  59. return 0;
  60. }
  61. void xen_unplug_emulated_devices(void)
  62. {
  63. int r;
  64. /* user explicitly requested no unplug */
  65. if (xen_emul_unplug & XEN_UNPLUG_NEVER)
  66. return;
  67. /* check the version of the xen platform PCI device */
  68. r = check_platform_magic();
  69. /* If the version matches enable the Xen platform PCI driver.
  70. * Also enable the Xen platform PCI driver if the host does
  71. * not support the unplug protocol (XEN_PLATFORM_ERR_MAGIC)
  72. * but the user told us that unplugging is unnecessary. */
  73. if (r && !(r == XEN_PLATFORM_ERR_MAGIC &&
  74. (xen_emul_unplug & XEN_UNPLUG_UNNECESSARY)))
  75. return;
  76. /* Set the default value of xen_emul_unplug depending on whether or
  77. * not the Xen PV frontends and the Xen platform PCI driver have
  78. * been compiled for this kernel (modules or built-in are both OK). */
  79. if (!xen_emul_unplug) {
  80. if (xen_must_unplug_nics()) {
  81. printk(KERN_INFO "Netfront and the Xen platform PCI driver have "
  82. "been compiled for this kernel: unplug emulated NICs.\n");
  83. xen_emul_unplug |= XEN_UNPLUG_ALL_NICS;
  84. }
  85. if (xen_must_unplug_disks()) {
  86. printk(KERN_INFO "Blkfront and the Xen platform PCI driver have "
  87. "been compiled for this kernel: unplug emulated disks.\n"
  88. "You might have to change the root device\n"
  89. "from /dev/hd[a-d] to /dev/xvd[a-d]\n"
  90. "in your root= kernel command line option\n");
  91. xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS;
  92. }
  93. }
  94. /* Now unplug the emulated devices */
  95. if (!(xen_emul_unplug & XEN_UNPLUG_UNNECESSARY))
  96. outw(xen_emul_unplug, XEN_IOPORT_UNPLUG);
  97. xen_platform_pci_unplug = xen_emul_unplug;
  98. }
  99. static int __init parse_xen_emul_unplug(char *arg)
  100. {
  101. char *p, *q;
  102. int l;
  103. for (p = arg; p; p = q) {
  104. q = strchr(p, ',');
  105. if (q) {
  106. l = q - p;
  107. q++;
  108. } else {
  109. l = strlen(p);
  110. }
  111. if (!strncmp(p, "all", l))
  112. xen_emul_unplug |= XEN_UNPLUG_ALL;
  113. else if (!strncmp(p, "ide-disks", l))
  114. xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS;
  115. else if (!strncmp(p, "aux-ide-disks", l))
  116. xen_emul_unplug |= XEN_UNPLUG_AUX_IDE_DISKS;
  117. else if (!strncmp(p, "nics", l))
  118. xen_emul_unplug |= XEN_UNPLUG_ALL_NICS;
  119. else if (!strncmp(p, "unnecessary", l))
  120. xen_emul_unplug |= XEN_UNPLUG_UNNECESSARY;
  121. else if (!strncmp(p, "never", l))
  122. xen_emul_unplug |= XEN_UNPLUG_NEVER;
  123. else
  124. printk(KERN_WARNING "unrecognised option '%s' "
  125. "in parameter 'xen_emul_unplug'\n", p);
  126. }
  127. return 0;
  128. }
  129. early_param("xen_emul_unplug", parse_xen_emul_unplug);
  130. #endif