Merge branch 'virtio' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux...
[sfrench/cifs-2.6.git] / arch / x86 / xen / platform-pci-unplug.c
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
22 #include <linux/init.h>
23 #include <linux/io.h>
24 #include <linux/module.h>
25
26 #include <xen/platform_pci.h>
27
28 #define XEN_PLATFORM_ERR_MAGIC -1
29 #define XEN_PLATFORM_ERR_PROTOCOL -2
30 #define XEN_PLATFORM_ERR_BLACKLIST -3
31
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;
37
38 static int __init check_platform_magic(void)
39 {
40         short magic;
41         char protocol;
42
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;
47         }
48
49         protocol = inb(XEN_IOPORT_PROTOVER);
50
51         printk(KERN_DEBUG "Xen Platform PCI: I/O protocol version %d\n",
52                         protocol);
53
54         switch (protocol) {
55         case 1:
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;
61                 }
62                 break;
63         default:
64                 printk(KERN_WARNING "Xen Platform PCI: unknown I/O protocol version");
65                 return XEN_PLATFORM_ERR_PROTOCOL;
66         }
67
68         return 0;
69 }
70
71 void __init xen_unplug_emulated_devices(void)
72 {
73         int r;
74
75         /* check the version of the xen platform PCI device */
76         r = check_platform_magic();
77         /* If the version matches enable the Xen platform PCI driver.
78          * Also enable the Xen platform PCI driver if the version is really old
79          * and the user told us to ignore it. */
80         if (r && !(r == XEN_PLATFORM_ERR_MAGIC &&
81                         (xen_emul_unplug & XEN_UNPLUG_IGNORE)))
82                 return;
83         /* Set the default value of xen_emul_unplug depending on whether or
84          * not the Xen PV frontends and the Xen platform PCI driver have
85          * been compiled for this kernel (modules or built-in are both OK). */
86         if (!xen_emul_unplug) {
87                 if (xen_must_unplug_nics()) {
88                         printk(KERN_INFO "Netfront and the Xen platform PCI driver have "
89                                         "been compiled for this kernel: unplug emulated NICs.\n");
90                         xen_emul_unplug |= XEN_UNPLUG_ALL_NICS;
91                 }
92                 if (xen_must_unplug_disks()) {
93                         printk(KERN_INFO "Blkfront and the Xen platform PCI driver have "
94                                         "been compiled for this kernel: unplug emulated disks.\n"
95                                         "You might have to change the root device\n"
96                                         "from /dev/hd[a-d] to /dev/xvd[a-d]\n"
97                                         "in your root= kernel command line option\n");
98                         xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS;
99                 }
100         }
101         /* Now unplug the emulated devices */
102         if (!(xen_emul_unplug & XEN_UNPLUG_IGNORE))
103                 outw(xen_emul_unplug, XEN_IOPORT_UNPLUG);
104         xen_platform_pci_unplug = xen_emul_unplug;
105 }
106
107 static int __init parse_xen_emul_unplug(char *arg)
108 {
109         char *p, *q;
110         int l;
111
112         for (p = arg; p; p = q) {
113                 q = strchr(p, ',');
114                 if (q) {
115                         l = q - p;
116                         q++;
117                 } else {
118                         l = strlen(p);
119                 }
120                 if (!strncmp(p, "all", l))
121                         xen_emul_unplug |= XEN_UNPLUG_ALL;
122                 else if (!strncmp(p, "ide-disks", l))
123                         xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS;
124                 else if (!strncmp(p, "aux-ide-disks", l))
125                         xen_emul_unplug |= XEN_UNPLUG_AUX_IDE_DISKS;
126                 else if (!strncmp(p, "nics", l))
127                         xen_emul_unplug |= XEN_UNPLUG_ALL_NICS;
128                 else if (!strncmp(p, "ignore", l))
129                         xen_emul_unplug |= XEN_UNPLUG_IGNORE;
130                 else
131                         printk(KERN_WARNING "unrecognised option '%s' "
132                                  "in parameter 'xen_emul_unplug'\n", p);
133         }
134         return 0;
135 }
136 early_param("xen_emul_unplug", parse_xen_emul_unplug);
137 #endif