Stefano Stabellini | c1c5413 | 2010-05-14 12:44:30 +0100 | [diff] [blame] | 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> |
Konrad Rzeszutek Wilk | b8b0f55 | 2012-08-21 14:49:34 -0400 | [diff] [blame] | 27 | #include "xen-ops.h" |
Stefano Stabellini | c1c5413 | 2010-05-14 12:44:30 +0100 | [diff] [blame] | 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); |
Stefano Stabellini | ca65f9f | 2010-07-29 14:37:48 +0100 | [diff] [blame] | 36 | #ifdef CONFIG_XEN_PVHVM |
Stefano Stabellini | c1c5413 | 2010-05-14 12:44:30 +0100 | [diff] [blame] | 37 | static int xen_emul_unplug; |
| 38 | |
Raghavendra D Prabhu | 3c52b7b | 2011-07-09 21:59:07 +0530 | [diff] [blame] | 39 | static int check_platform_magic(void) |
Stefano Stabellini | c1c5413 | 2010-05-14 12:44:30 +0100 | [diff] [blame] | 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 | |
Stefano Stabellini | 512b109 | 2010-12-01 14:51:44 +0000 | [diff] [blame] | 72 | void xen_unplug_emulated_devices(void) |
Stefano Stabellini | c1c5413 | 2010-05-14 12:44:30 +0100 | [diff] [blame] | 73 | { |
| 74 | int r; |
| 75 | |
Ian Campbell | c93a4df | 2010-08-23 11:59:28 +0100 | [diff] [blame] | 76 | /* user explicitly requested no unplug */ |
| 77 | if (xen_emul_unplug & XEN_UNPLUG_NEVER) |
| 78 | return; |
Stefano Stabellini | c1c5413 | 2010-05-14 12:44:30 +0100 | [diff] [blame] | 79 | /* check the version of the xen platform PCI device */ |
| 80 | r = check_platform_magic(); |
| 81 | /* If the version matches enable the Xen platform PCI driver. |
Ian Campbell | 1dc7ce9 | 2010-08-23 11:59:29 +0100 | [diff] [blame] | 82 | * Also enable the Xen platform PCI driver if the host does |
| 83 | * not support the unplug protocol (XEN_PLATFORM_ERR_MAGIC) |
| 84 | * but the user told us that unplugging is unnecessary. */ |
Stefano Stabellini | c1c5413 | 2010-05-14 12:44:30 +0100 | [diff] [blame] | 85 | if (r && !(r == XEN_PLATFORM_ERR_MAGIC && |
Ian Campbell | 1dc7ce9 | 2010-08-23 11:59:29 +0100 | [diff] [blame] | 86 | (xen_emul_unplug & XEN_UNPLUG_UNNECESSARY))) |
Stefano Stabellini | c1c5413 | 2010-05-14 12:44:30 +0100 | [diff] [blame] | 87 | return; |
| 88 | /* Set the default value of xen_emul_unplug depending on whether or |
| 89 | * not the Xen PV frontends and the Xen platform PCI driver have |
| 90 | * been compiled for this kernel (modules or built-in are both OK). */ |
| 91 | if (!xen_emul_unplug) { |
| 92 | if (xen_must_unplug_nics()) { |
| 93 | printk(KERN_INFO "Netfront and the Xen platform PCI driver have " |
| 94 | "been compiled for this kernel: unplug emulated NICs.\n"); |
| 95 | xen_emul_unplug |= XEN_UNPLUG_ALL_NICS; |
| 96 | } |
| 97 | if (xen_must_unplug_disks()) { |
| 98 | printk(KERN_INFO "Blkfront and the Xen platform PCI driver have " |
| 99 | "been compiled for this kernel: unplug emulated disks.\n" |
| 100 | "You might have to change the root device\n" |
| 101 | "from /dev/hd[a-d] to /dev/xvd[a-d]\n" |
| 102 | "in your root= kernel command line option\n"); |
| 103 | xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS; |
| 104 | } |
| 105 | } |
| 106 | /* Now unplug the emulated devices */ |
Ian Campbell | 1dc7ce9 | 2010-08-23 11:59:29 +0100 | [diff] [blame] | 107 | if (!(xen_emul_unplug & XEN_UNPLUG_UNNECESSARY)) |
Stefano Stabellini | c1c5413 | 2010-05-14 12:44:30 +0100 | [diff] [blame] | 108 | outw(xen_emul_unplug, XEN_IOPORT_UNPLUG); |
| 109 | xen_platform_pci_unplug = xen_emul_unplug; |
| 110 | } |
| 111 | |
| 112 | static int __init parse_xen_emul_unplug(char *arg) |
| 113 | { |
| 114 | char *p, *q; |
| 115 | int l; |
| 116 | |
| 117 | for (p = arg; p; p = q) { |
| 118 | q = strchr(p, ','); |
| 119 | if (q) { |
| 120 | l = q - p; |
| 121 | q++; |
| 122 | } else { |
| 123 | l = strlen(p); |
| 124 | } |
| 125 | if (!strncmp(p, "all", l)) |
| 126 | xen_emul_unplug |= XEN_UNPLUG_ALL; |
| 127 | else if (!strncmp(p, "ide-disks", l)) |
| 128 | xen_emul_unplug |= XEN_UNPLUG_ALL_IDE_DISKS; |
| 129 | else if (!strncmp(p, "aux-ide-disks", l)) |
| 130 | xen_emul_unplug |= XEN_UNPLUG_AUX_IDE_DISKS; |
| 131 | else if (!strncmp(p, "nics", l)) |
| 132 | xen_emul_unplug |= XEN_UNPLUG_ALL_NICS; |
Ian Campbell | 1dc7ce9 | 2010-08-23 11:59:29 +0100 | [diff] [blame] | 133 | else if (!strncmp(p, "unnecessary", l)) |
| 134 | xen_emul_unplug |= XEN_UNPLUG_UNNECESSARY; |
Ian Campbell | c93a4df | 2010-08-23 11:59:28 +0100 | [diff] [blame] | 135 | else if (!strncmp(p, "never", l)) |
| 136 | xen_emul_unplug |= XEN_UNPLUG_NEVER; |
Stefano Stabellini | c1c5413 | 2010-05-14 12:44:30 +0100 | [diff] [blame] | 137 | else |
| 138 | printk(KERN_WARNING "unrecognised option '%s' " |
| 139 | "in parameter 'xen_emul_unplug'\n", p); |
| 140 | } |
| 141 | return 0; |
| 142 | } |
| 143 | early_param("xen_emul_unplug", parse_xen_emul_unplug); |
Stefano Stabellini | ca65f9f | 2010-07-29 14:37:48 +0100 | [diff] [blame] | 144 | #endif |