]>
Commit | Line | Data |
---|---|---|
c1c5413a SS |
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> | |
b8b0f559 | 27 | #include "xen-ops.h" |
c1c5413a SS |
28 | |
29 | #define XEN_PLATFORM_ERR_MAGIC -1 | |
30 | #define XEN_PLATFORM_ERR_PROTOCOL -2 | |
31 | #define XEN_PLATFORM_ERR_BLACKLIST -3 | |
32 | ||
33 | /* store the value of xen_emul_unplug after the unplug is done */ | |
34 | int xen_platform_pci_unplug; | |
35 | EXPORT_SYMBOL_GPL(xen_platform_pci_unplug); | |
ca65f9fc | 36 | #ifdef CONFIG_XEN_PVHVM |
c1c5413a SS |
37 | static int xen_emul_unplug; |
38 | ||
3c52b7bf | 39 | static int check_platform_magic(void) |
c1c5413a SS |
40 | { |
41 | short magic; | |
42 | char protocol; | |
43 | ||
44 | magic = inw(XEN_IOPORT_MAGIC); | |
45 | if (magic != XEN_IOPORT_MAGIC_VAL) { | |
46 | printk(KERN_ERR "Xen Platform PCI: unrecognised magic value\n"); | |
47 | return XEN_PLATFORM_ERR_MAGIC; | |
48 | } | |
49 | ||
50 | protocol = inb(XEN_IOPORT_PROTOVER); | |
51 | ||
52 | printk(KERN_DEBUG "Xen Platform PCI: I/O protocol version %d\n", | |
53 | protocol); | |
54 | ||
55 | switch (protocol) { | |
56 | case 1: | |
57 | outw(XEN_IOPORT_LINUX_PRODNUM, XEN_IOPORT_PRODNUM); | |
58 | outl(XEN_IOPORT_LINUX_DRVVER, XEN_IOPORT_DRVVER); | |
59 | if (inw(XEN_IOPORT_MAGIC) != XEN_IOPORT_MAGIC_VAL) { | |
60 | printk(KERN_ERR "Xen Platform: blacklisted by host\n"); | |
61 | return XEN_PLATFORM_ERR_BLACKLIST; | |
62 | } | |
63 | break; | |
64 | default: | |
65 | printk(KERN_WARNING "Xen Platform PCI: unknown I/O protocol version"); | |
66 | return XEN_PLATFORM_ERR_PROTOCOL; | |
67 | } | |
68 | ||
69 | return 0; | |
70 | } | |
71 | ||
51c71a3b KRW |
72 | bool xen_has_pv_devices() |
73 | { | |
74 | if (!xen_domain()) | |
75 | return false; | |
76 | ||
77 | /* PV domains always have them. */ | |
78 | if (xen_pv_domain()) | |
79 | return true; | |
80 | ||
81 | /* And user has xen_platform_pci=0 set in guest config as | |
82 | * driver did not modify the value. */ | |
83 | if (xen_platform_pci_unplug == 0) | |
84 | return false; | |
85 | ||
86 | if (xen_platform_pci_unplug & XEN_UNPLUG_NEVER) | |
87 | return false; | |
88 | ||
89 | if (xen_platform_pci_unplug & XEN_UNPLUG_ALL) | |
90 | return true; | |
91 | ||
92 | /* This is an odd one - we are going to run legacy | |
93 | * and PV drivers at the same time. */ | |
94 | if (xen_platform_pci_unplug & XEN_UNPLUG_UNNECESSARY) | |
95 | return true; | |
96 | ||
97 | /* And the caller has to follow with xen_pv_{disk,nic}_devices | |
98 | * to be certain which driver can load. */ | |
99 | return false; | |
100 | } | |
101 | EXPORT_SYMBOL_GPL(xen_has_pv_devices); | |
102 | ||
103 | static bool __xen_has_pv_device(int state) | |
104 | { | |
105 | /* HVM domains might or might not */ | |
106 | if (xen_hvm_domain() && (xen_platform_pci_unplug & state)) | |
107 | return true; | |
108 | ||
109 | return xen_has_pv_devices(); | |
110 | } | |
111 | ||
112 | bool xen_has_pv_nic_devices(void) | |
113 | { | |
114 | return __xen_has_pv_device(XEN_UNPLUG_ALL_NICS | XEN_UNPLUG_ALL); | |
115 | } | |
116 | EXPORT_SYMBOL_GPL(xen_has_pv_nic_devices); | |
117 | ||
118 | bool xen_has_pv_disk_devices(void) | |
119 | { | |
120 | return __xen_has_pv_device(XEN_UNPLUG_ALL_IDE_DISKS | | |
121 | XEN_UNPLUG_AUX_IDE_DISKS | XEN_UNPLUG_ALL); | |
122 | } | |
123 | EXPORT_SYMBOL_GPL(xen_has_pv_disk_devices); | |
124 | ||
125 | /* | |
126 | * This one is odd - it determines whether you want to run PV _and_ | |
127 | * legacy (IDE) drivers together. This combination is only possible | |
128 | * under HVM. | |
129 | */ | |
130 | bool xen_has_pv_and_legacy_disk_devices(void) | |
131 | { | |
132 | if (!xen_domain()) | |
133 | return false; | |
134 | ||
135 | /* N.B. This is only ever used in HVM mode */ | |
136 | if (xen_pv_domain()) | |
137 | return false; | |
138 | ||
139 | if (xen_platform_pci_unplug & XEN_UNPLUG_UNNECESSARY) | |
140 | return true; | |
141 | ||
142 | return false; | |
143 | } | |
144 | EXPORT_SYMBOL_GPL(xen_has_pv_and_legacy_disk_devices); | |
145 | ||
512b109e | 146 | void xen_unplug_emulated_devices(void) |
c1c5413a SS |
147 | { |
148 | int r; | |
149 | ||
c93a4dfb IC |
150 | /* user explicitly requested no unplug */ |
151 | if (xen_emul_unplug & XEN_UNPLUG_NEVER) | |
152 | return; | |
c1c5413a SS |
153 | /* check the version of the xen platform PCI device */ |
154 | r = check_platform_magic(); | |
155 | /* If the version matches enable the Xen platform PCI driver. | |
1dc7ce99 IC |
156 | * Also enable the Xen platform PCI driver if the host does |
157 | * not support the unplug protocol (XEN_PLATFORM_ERR_MAGIC) | |
158 | * but the user told us that unplugging is unnecessary. */ | |
c1c5413a | 159 | if (r && !(r == XEN_PLATFORM_ERR_MAGIC && |
1dc7ce99 | 160 | (xen_emul_unplug & XEN_UNPLUG_UNNECESSARY))) |
c1c5413a SS |
161 | return; |
162 | /* Set the default value of xen_emul_unplug depending on whether or | |
163 | * not the Xen PV frontends and the Xen platform PCI driver have | |
164 | * been compiled for this kernel (modules or built-in are both OK). */ | |
165 | if (!xen_emul_unplug) { | |
166 | if (xen_must_unplug_nics()) { | |
167 | printk(KERN_INFO "Netfront and the Xen platform PCI driver have " | |
168 | "been compiled for this kernel: unplug emulated NICs.\n"); | |
169 | xen_emul_unplug |= XEN_UNPLUG_ALL_NICS; | |
170 | } | |
171 | if (xen_must_unplug_disks()) { | |
172 | printk(KERN_INFO "Blkfront and the Xen platform PCI driver have " | |
173 | "been compiled for this kernel: unplug emulated disks.\n" | |
174 | "You might have to change the root device\n" | |
175 | "from /dev/hd[a-d] to /dev/xvd[a-d]\n" | |
176 | "in your root= kernel command line option\n"); | |
177 | xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS; | |
178 | } | |
179 | } | |
180 | /* Now unplug the emulated devices */ | |
1dc7ce99 | 181 | if (!(xen_emul_unplug & XEN_UNPLUG_UNNECESSARY)) |
c1c5413a SS |
182 | outw(xen_emul_unplug, XEN_IOPORT_UNPLUG); |
183 | xen_platform_pci_unplug = xen_emul_unplug; | |
184 | } | |
185 | ||
186 | static int __init parse_xen_emul_unplug(char *arg) | |
187 | { | |
188 | char *p, *q; | |
189 | int l; | |
190 | ||
191 | for (p = arg; p; p = q) { | |
192 | q = strchr(p, ','); | |
193 | if (q) { | |
194 | l = q - p; | |
195 | q++; | |
196 | } else { | |
197 | l = strlen(p); | |
198 | } | |
199 | if (!strncmp(p, "all", l)) | |
200 | xen_emul_unplug |= XEN_UNPLUG_ALL; | |
201 | else if (!strncmp(p, "ide-disks", l)) | |
202 | xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS; | |
203 | else if (!strncmp(p, "aux-ide-disks", l)) | |
204 | xen_emul_unplug |= XEN_UNPLUG_AUX_IDE_DISKS; | |
205 | else if (!strncmp(p, "nics", l)) | |
206 | xen_emul_unplug |= XEN_UNPLUG_ALL_NICS; | |
1dc7ce99 IC |
207 | else if (!strncmp(p, "unnecessary", l)) |
208 | xen_emul_unplug |= XEN_UNPLUG_UNNECESSARY; | |
c93a4dfb IC |
209 | else if (!strncmp(p, "never", l)) |
210 | xen_emul_unplug |= XEN_UNPLUG_NEVER; | |
c1c5413a SS |
211 | else |
212 | printk(KERN_WARNING "unrecognised option '%s' " | |
213 | "in parameter 'xen_emul_unplug'\n", p); | |
214 | } | |
215 | return 0; | |
216 | } | |
217 | early_param("xen_emul_unplug", parse_xen_emul_unplug); | |
ca65f9fc | 218 | #endif |