1 /******************************************************************************
2 * platform-pci-unplug.c
4 * Xen platform PCI device driver
5 * Copyright (c) 2010, Citrix
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.
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
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.
22 #include <linux/init.h>
24 #include <linux/module.h>
26 #include <xen/platform_pci.h>
28 #define XEN_PLATFORM_ERR_MAGIC -1
29 #define XEN_PLATFORM_ERR_PROTOCOL -2
30 #define XEN_PLATFORM_ERR_BLACKLIST -3
32 /* store the value of xen_emul_unplug after the unplug is done */
33 int xen_platform_pci_unplug;
34 EXPORT_SYMBOL_GPL(xen_platform_pci_unplug);
35 #ifdef CONFIG_XEN_PVHVM
36 static int xen_emul_unplug;
38 static int __init check_platform_magic(void)
43 magic = inw(XEN_IOPORT_MAGIC);
44 if (magic != XEN_IOPORT_MAGIC_VAL) {
45 printk(KERN_ERR "Xen Platform PCI: unrecognised magic value\n");
46 return XEN_PLATFORM_ERR_MAGIC;
49 protocol = inb(XEN_IOPORT_PROTOVER);
51 printk(KERN_DEBUG "Xen Platform PCI: I/O protocol version %d\n",
56 outw(XEN_IOPORT_LINUX_PRODNUM, XEN_IOPORT_PRODNUM);
57 outl(XEN_IOPORT_LINUX_DRVVER, XEN_IOPORT_DRVVER);
58 if (inw(XEN_IOPORT_MAGIC) != XEN_IOPORT_MAGIC_VAL) {
59 printk(KERN_ERR "Xen Platform: blacklisted by host\n");
60 return XEN_PLATFORM_ERR_BLACKLIST;
64 printk(KERN_WARNING "Xen Platform PCI: unknown I/O protocol version");
65 return XEN_PLATFORM_ERR_PROTOCOL;
71 void __init xen_unplug_emulated_devices(void)
75 /* user explicitly requested no unplug */
76 if (xen_emul_unplug & XEN_UNPLUG_NEVER)
78 /* check the version of the xen platform PCI device */
79 r = check_platform_magic();
80 /* If the version matches enable the Xen platform PCI driver.
81 * Also enable the Xen platform PCI driver if the version is really old
82 * and the user told us to ignore it. */
83 if (r && !(r == XEN_PLATFORM_ERR_MAGIC &&
84 (xen_emul_unplug & XEN_UNPLUG_IGNORE)))
86 /* Set the default value of xen_emul_unplug depending on whether or
87 * not the Xen PV frontends and the Xen platform PCI driver have
88 * been compiled for this kernel (modules or built-in are both OK). */
89 if (!xen_emul_unplug) {
90 if (xen_must_unplug_nics()) {
91 printk(KERN_INFO "Netfront and the Xen platform PCI driver have "
92 "been compiled for this kernel: unplug emulated NICs.\n");
93 xen_emul_unplug |= XEN_UNPLUG_ALL_NICS;
95 if (xen_must_unplug_disks()) {
96 printk(KERN_INFO "Blkfront and the Xen platform PCI driver have "
97 "been compiled for this kernel: unplug emulated disks.\n"
98 "You might have to change the root device\n"
99 "from /dev/hd[a-d] to /dev/xvd[a-d]\n"
100 "in your root= kernel command line option\n");
101 xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS;
104 /* Now unplug the emulated devices */
105 if (!(xen_emul_unplug & XEN_UNPLUG_IGNORE))
106 outw(xen_emul_unplug, XEN_IOPORT_UNPLUG);
107 xen_platform_pci_unplug = xen_emul_unplug;
110 static int __init parse_xen_emul_unplug(char *arg)
115 for (p = arg; p; p = q) {
123 if (!strncmp(p, "all", l))
124 xen_emul_unplug |= XEN_UNPLUG_ALL;
125 else if (!strncmp(p, "ide-disks", l))
126 xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS;
127 else if (!strncmp(p, "aux-ide-disks", l))
128 xen_emul_unplug |= XEN_UNPLUG_AUX_IDE_DISKS;
129 else if (!strncmp(p, "nics", l))
130 xen_emul_unplug |= XEN_UNPLUG_ALL_NICS;
131 else if (!strncmp(p, "ignore", l))
132 xen_emul_unplug |= XEN_UNPLUG_IGNORE;
133 else if (!strncmp(p, "never", l))
134 xen_emul_unplug |= XEN_UNPLUG_NEVER;
136 printk(KERN_WARNING "unrecognised option '%s' "
137 "in parameter 'xen_emul_unplug'\n", p);
141 early_param("xen_emul_unplug", parse_xen_emul_unplug);