platform-pci-unplug.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. #define XEN_PLATFORM_ERR_MAGIC -1
  26. #define XEN_PLATFORM_ERR_PROTOCOL -2
  27. #define XEN_PLATFORM_ERR_BLACKLIST -3
  28. /* store the value of xen_emul_unplug after the unplug is done */
  29. int xen_platform_pci_unplug;
  30. EXPORT_SYMBOL_GPL(xen_platform_pci_unplug);
  31. #ifdef CONFIG_XEN_PVHVM
  32. static int xen_emul_unplug;
  33. static int __init check_platform_magic(void)
  34. {
  35. short magic;
  36. char protocol;
  37. magic = inw(XEN_IOPORT_MAGIC);
  38. if (magic != XEN_IOPORT_MAGIC_VAL) {
  39. printk(KERN_ERR "Xen Platform PCI: unrecognised magic value\n");
  40. return XEN_PLATFORM_ERR_MAGIC;
  41. }
  42. protocol = inb(XEN_IOPORT_PROTOVER);
  43. printk(KERN_DEBUG "Xen Platform PCI: I/O protocol version %d\n",
  44. protocol);
  45. switch (protocol) {
  46. case 1:
  47. outw(XEN_IOPORT_LINUX_PRODNUM, XEN_IOPORT_PRODNUM);
  48. outl(XEN_IOPORT_LINUX_DRVVER, XEN_IOPORT_DRVVER);
  49. if (inw(XEN_IOPORT_MAGIC) != XEN_IOPORT_MAGIC_VAL) {
  50. printk(KERN_ERR "Xen Platform: blacklisted by host\n");
  51. return XEN_PLATFORM_ERR_BLACKLIST;
  52. }
  53. break;
  54. default:
  55. printk(KERN_WARNING "Xen Platform PCI: unknown I/O protocol version");
  56. return XEN_PLATFORM_ERR_PROTOCOL;
  57. }
  58. return 0;
  59. }
  60. void __init xen_unplug_emulated_devices(void)
  61. {
  62. int r;
  63. /* check the version of the xen platform PCI device */
  64. r = check_platform_magic();
  65. /* If the version matches enable the Xen platform PCI driver.
  66. * Also enable the Xen platform PCI driver if the version is really old
  67. * and the user told us to ignore it. */
  68. if (r && !(r == XEN_PLATFORM_ERR_MAGIC &&
  69. (xen_emul_unplug & XEN_UNPLUG_IGNORE)))
  70. return;
  71. /* Set the default value of xen_emul_unplug depending on whether or
  72. * not the Xen PV frontends and the Xen platform PCI driver have
  73. * been compiled for this kernel (modules or built-in are both OK). */
  74. if (!xen_emul_unplug) {
  75. if (xen_must_unplug_nics()) {
  76. printk(KERN_INFO "Netfront and the Xen platform PCI driver have "
  77. "been compiled for this kernel: unplug emulated NICs.\n");
  78. xen_emul_unplug |= XEN_UNPLUG_ALL_NICS;
  79. }
  80. if (xen_must_unplug_disks()) {
  81. printk(KERN_INFO "Blkfront and the Xen platform PCI driver have "
  82. "been compiled for this kernel: unplug emulated disks.\n"
  83. "You might have to change the root device\n"
  84. "from /dev/hd[a-d] to /dev/xvd[a-d]\n"
  85. "in your root= kernel command line option\n");
  86. xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS;
  87. }
  88. }
  89. /* Now unplug the emulated devices */
  90. if (!(xen_emul_unplug & XEN_UNPLUG_IGNORE))
  91. outw(xen_emul_unplug, XEN_IOPORT_UNPLUG);
  92. xen_platform_pci_unplug = xen_emul_unplug;
  93. }
  94. static int __init parse_xen_emul_unplug(char *arg)
  95. {
  96. char *p, *q;
  97. int l;
  98. for (p = arg; p; p = q) {
  99. q = strchr(p, ',');
  100. if (q) {
  101. l = q - p;
  102. q++;
  103. } else {
  104. l = strlen(p);
  105. }
  106. if (!strncmp(p, "all", l))
  107. xen_emul_unplug |= XEN_UNPLUG_ALL;
  108. else if (!strncmp(p, "ide-disks", l))
  109. xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS;
  110. else if (!strncmp(p, "aux-ide-disks", l))
  111. xen_emul_unplug |= XEN_UNPLUG_AUX_IDE_DISKS;
  112. else if (!strncmp(p, "nics", l))
  113. xen_emul_unplug |= XEN_UNPLUG_ALL_NICS;
  114. else if (!strncmp(p, "ignore", l))
  115. xen_emul_unplug |= XEN_UNPLUG_IGNORE;
  116. else
  117. printk(KERN_WARNING "unrecognised option '%s' "
  118. "in parameter 'xen_emul_unplug'\n", p);
  119. }
  120. return 0;
  121. }
  122. early_param("xen_emul_unplug", parse_xen_emul_unplug);
  123. #endif