~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86/xen/platform-pci-unplug.c

Version: ~ [ linux-5.11-rc3 ] ~ [ linux-5.10.7 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.89 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.167 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.215 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.251 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.251 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

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

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp