Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1 | /* |
| 2 | * PCI Backend Xenbus Setup - handles setup with frontend and xend |
| 3 | * |
| 4 | * Author: Ryan Wilson <hap9@epoch.ncsc.mil> |
| 5 | */ |
| 6 | #include <linux/module.h> |
| 7 | #include <linux/init.h> |
| 8 | #include <linux/list.h> |
| 9 | #include <linux/vmalloc.h> |
| 10 | #include <linux/workqueue.h> |
| 11 | #include <xen/xenbus.h> |
| 12 | #include <xen/events.h> |
Konrad Rzeszutek Wilk | 6221a9b | 2009-12-09 17:43:15 -0500 | [diff] [blame] | 13 | #include <asm/xen/pci.h> |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 14 | #include "pciback.h" |
| 15 | |
| 16 | #define INVALID_EVTCHN_IRQ (-1) |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 17 | struct workqueue_struct *xen_pcibk_wq; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 18 | |
Rusty Russell | 90ab5ee | 2012-01-13 09:32:20 +1030 | [diff] [blame^] | 19 | static bool __read_mostly passthrough; |
Konrad Rzeszutek Wilk | 2ebdc42 | 2011-07-11 16:49:41 -0400 | [diff] [blame] | 20 | module_param(passthrough, bool, S_IRUGO); |
| 21 | MODULE_PARM_DESC(passthrough, |
| 22 | "Option to specify how to export PCI topology to guest:\n"\ |
| 23 | " 0 - (default) Hide the true PCI topology and makes the frontend\n"\ |
| 24 | " there is a single PCI bus with only the exported devices on it.\n"\ |
| 25 | " For example, a device at 03:05.0 will be re-assigned to 00:00.0\n"\ |
| 26 | " while second device at 02:1a.1 will be re-assigned to 00:01.1.\n"\ |
| 27 | " 1 - Passthrough provides a real view of the PCI topology to the\n"\ |
| 28 | " frontend (for example, a device at 06:01.b will still appear at\n"\ |
| 29 | " 06:01.b to the frontend). This is similar to how Xen 2.0.x\n"\ |
| 30 | " exposed PCI devices to its driver domains. This may be required\n"\ |
| 31 | " for drivers which depend on finding their hardward in certain\n"\ |
| 32 | " bus/slot locations."); |
| 33 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 34 | static struct xen_pcibk_device *alloc_pdev(struct xenbus_device *xdev) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 35 | { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 36 | struct xen_pcibk_device *pdev; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 37 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 38 | pdev = kzalloc(sizeof(struct xen_pcibk_device), GFP_KERNEL); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 39 | if (pdev == NULL) |
| 40 | goto out; |
| 41 | dev_dbg(&xdev->dev, "allocated pdev @ 0x%p\n", pdev); |
| 42 | |
| 43 | pdev->xdev = xdev; |
| 44 | dev_set_drvdata(&xdev->dev, pdev); |
| 45 | |
Konrad Rzeszutek Wilk | b1766b6 | 2011-09-16 14:43:14 -0400 | [diff] [blame] | 46 | mutex_init(&pdev->dev_lock); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 47 | |
| 48 | pdev->sh_info = NULL; |
| 49 | pdev->evtchn_irq = INVALID_EVTCHN_IRQ; |
| 50 | pdev->be_watching = 0; |
| 51 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 52 | INIT_WORK(&pdev->op_work, xen_pcibk_do_op); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 53 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 54 | if (xen_pcibk_init_devices(pdev)) { |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 55 | kfree(pdev); |
| 56 | pdev = NULL; |
| 57 | } |
| 58 | out: |
| 59 | return pdev; |
| 60 | } |
| 61 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 62 | static void xen_pcibk_disconnect(struct xen_pcibk_device *pdev) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 63 | { |
Konrad Rzeszutek Wilk | b1766b6 | 2011-09-16 14:43:14 -0400 | [diff] [blame] | 64 | mutex_lock(&pdev->dev_lock); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 65 | /* Ensure the guest can't trigger our handler before removing devices */ |
| 66 | if (pdev->evtchn_irq != INVALID_EVTCHN_IRQ) { |
| 67 | unbind_from_irqhandler(pdev->evtchn_irq, pdev); |
| 68 | pdev->evtchn_irq = INVALID_EVTCHN_IRQ; |
| 69 | } |
| 70 | |
| 71 | /* If the driver domain started an op, make sure we complete it |
| 72 | * before releasing the shared memory */ |
Konrad Rzeszutek Wilk | 494ef20 | 2010-07-23 14:35:47 -0400 | [diff] [blame] | 73 | |
| 74 | /* Note, the workqueue does not use spinlocks at all.*/ |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 75 | flush_workqueue(xen_pcibk_wq); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 76 | |
| 77 | if (pdev->sh_info != NULL) { |
| 78 | xenbus_unmap_ring_vfree(pdev->xdev, pdev->sh_info); |
| 79 | pdev->sh_info = NULL; |
| 80 | } |
Konrad Rzeszutek Wilk | b1766b6 | 2011-09-16 14:43:14 -0400 | [diff] [blame] | 81 | mutex_unlock(&pdev->dev_lock); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 82 | } |
| 83 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 84 | static void free_pdev(struct xen_pcibk_device *pdev) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 85 | { |
Konrad Rzeszutek Wilk | 494ef20 | 2010-07-23 14:35:47 -0400 | [diff] [blame] | 86 | if (pdev->be_watching) { |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 87 | unregister_xenbus_watch(&pdev->be_watch); |
Konrad Rzeszutek Wilk | 494ef20 | 2010-07-23 14:35:47 -0400 | [diff] [blame] | 88 | pdev->be_watching = 0; |
| 89 | } |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 90 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 91 | xen_pcibk_disconnect(pdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 92 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 93 | xen_pcibk_release_devices(pdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 94 | |
| 95 | dev_set_drvdata(&pdev->xdev->dev, NULL); |
| 96 | pdev->xdev = NULL; |
| 97 | |
| 98 | kfree(pdev); |
| 99 | } |
| 100 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 101 | static int xen_pcibk_do_attach(struct xen_pcibk_device *pdev, int gnt_ref, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 102 | int remote_evtchn) |
| 103 | { |
| 104 | int err = 0; |
| 105 | void *vaddr; |
| 106 | |
| 107 | dev_dbg(&pdev->xdev->dev, |
| 108 | "Attaching to frontend resources - gnt_ref=%d evtchn=%d\n", |
| 109 | gnt_ref, remote_evtchn); |
| 110 | |
| 111 | err = xenbus_map_ring_valloc(pdev->xdev, gnt_ref, &vaddr); |
| 112 | if (err < 0) { |
| 113 | xenbus_dev_fatal(pdev->xdev, err, |
| 114 | "Error mapping other domain page in ours."); |
| 115 | goto out; |
| 116 | } |
Konrad Rzeszutek Wilk | 494ef20 | 2010-07-23 14:35:47 -0400 | [diff] [blame] | 117 | |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 118 | pdev->sh_info = vaddr; |
| 119 | |
| 120 | err = bind_interdomain_evtchn_to_irqhandler( |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 121 | pdev->xdev->otherend_id, remote_evtchn, xen_pcibk_handle_event, |
| 122 | 0, DRV_NAME, pdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 123 | if (err < 0) { |
| 124 | xenbus_dev_fatal(pdev->xdev, err, |
| 125 | "Error binding event channel to IRQ"); |
| 126 | goto out; |
| 127 | } |
| 128 | pdev->evtchn_irq = err; |
| 129 | err = 0; |
| 130 | |
| 131 | dev_dbg(&pdev->xdev->dev, "Attached!\n"); |
| 132 | out: |
| 133 | return err; |
| 134 | } |
| 135 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 136 | static int xen_pcibk_attach(struct xen_pcibk_device *pdev) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 137 | { |
| 138 | int err = 0; |
| 139 | int gnt_ref, remote_evtchn; |
| 140 | char *magic = NULL; |
| 141 | |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 142 | |
Konrad Rzeszutek Wilk | b1766b6 | 2011-09-16 14:43:14 -0400 | [diff] [blame] | 143 | mutex_lock(&pdev->dev_lock); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 144 | /* Make sure we only do this setup once */ |
| 145 | if (xenbus_read_driver_state(pdev->xdev->nodename) != |
| 146 | XenbusStateInitialised) |
| 147 | goto out; |
| 148 | |
| 149 | /* Wait for frontend to state that it has published the configuration */ |
| 150 | if (xenbus_read_driver_state(pdev->xdev->otherend) != |
| 151 | XenbusStateInitialised) |
| 152 | goto out; |
| 153 | |
| 154 | dev_dbg(&pdev->xdev->dev, "Reading frontend config\n"); |
| 155 | |
| 156 | err = xenbus_gather(XBT_NIL, pdev->xdev->otherend, |
| 157 | "pci-op-ref", "%u", &gnt_ref, |
| 158 | "event-channel", "%u", &remote_evtchn, |
| 159 | "magic", NULL, &magic, NULL); |
| 160 | if (err) { |
| 161 | /* If configuration didn't get read correctly, wait longer */ |
| 162 | xenbus_dev_fatal(pdev->xdev, err, |
| 163 | "Error reading configuration from frontend"); |
| 164 | goto out; |
| 165 | } |
| 166 | |
| 167 | if (magic == NULL || strcmp(magic, XEN_PCI_MAGIC) != 0) { |
| 168 | xenbus_dev_fatal(pdev->xdev, -EFAULT, |
| 169 | "version mismatch (%s/%s) with pcifront - " |
Jan Beulich | 402c5e1 | 2011-09-21 16:22:11 -0400 | [diff] [blame] | 170 | "halting " DRV_NAME, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 171 | magic, XEN_PCI_MAGIC); |
| 172 | goto out; |
| 173 | } |
| 174 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 175 | err = xen_pcibk_do_attach(pdev, gnt_ref, remote_evtchn); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 176 | if (err) |
| 177 | goto out; |
| 178 | |
| 179 | dev_dbg(&pdev->xdev->dev, "Connecting...\n"); |
| 180 | |
| 181 | err = xenbus_switch_state(pdev->xdev, XenbusStateConnected); |
| 182 | if (err) |
| 183 | xenbus_dev_fatal(pdev->xdev, err, |
| 184 | "Error switching to connected state!"); |
| 185 | |
| 186 | dev_dbg(&pdev->xdev->dev, "Connected? %d\n", err); |
| 187 | out: |
Konrad Rzeszutek Wilk | b1766b6 | 2011-09-16 14:43:14 -0400 | [diff] [blame] | 188 | mutex_unlock(&pdev->dev_lock); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 189 | |
| 190 | kfree(magic); |
| 191 | |
| 192 | return err; |
| 193 | } |
| 194 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 195 | static int xen_pcibk_publish_pci_dev(struct xen_pcibk_device *pdev, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 196 | unsigned int domain, unsigned int bus, |
| 197 | unsigned int devfn, unsigned int devid) |
| 198 | { |
| 199 | int err; |
| 200 | int len; |
| 201 | char str[64]; |
| 202 | |
| 203 | len = snprintf(str, sizeof(str), "vdev-%d", devid); |
| 204 | if (unlikely(len >= (sizeof(str) - 1))) { |
| 205 | err = -ENOMEM; |
| 206 | goto out; |
| 207 | } |
| 208 | |
| 209 | err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str, |
| 210 | "%04x:%02x:%02x.%02x", domain, bus, |
| 211 | PCI_SLOT(devfn), PCI_FUNC(devfn)); |
| 212 | |
| 213 | out: |
| 214 | return err; |
| 215 | } |
| 216 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 217 | static int xen_pcibk_export_device(struct xen_pcibk_device *pdev, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 218 | int domain, int bus, int slot, int func, |
| 219 | int devid) |
| 220 | { |
| 221 | struct pci_dev *dev; |
| 222 | int err = 0; |
| 223 | |
| 224 | dev_dbg(&pdev->xdev->dev, "exporting dom %x bus %x slot %x func %x\n", |
| 225 | domain, bus, slot, func); |
| 226 | |
| 227 | dev = pcistub_get_pci_dev_by_slot(pdev, domain, bus, slot, func); |
| 228 | if (!dev) { |
| 229 | err = -EINVAL; |
| 230 | xenbus_dev_fatal(pdev->xdev, err, |
| 231 | "Couldn't locate PCI device " |
| 232 | "(%04x:%02x:%02x.%01x)! " |
| 233 | "perhaps already in-use?", |
| 234 | domain, bus, slot, func); |
| 235 | goto out; |
| 236 | } |
| 237 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 238 | err = xen_pcibk_add_pci_dev(pdev, dev, devid, |
| 239 | xen_pcibk_publish_pci_dev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 240 | if (err) |
| 241 | goto out; |
| 242 | |
Konrad Rzeszutek Wilk | 6221a9b | 2009-12-09 17:43:15 -0500 | [diff] [blame] | 243 | dev_dbg(&dev->dev, "registering for %d\n", pdev->xdev->otherend_id); |
| 244 | if (xen_register_device_domain_owner(dev, |
| 245 | pdev->xdev->otherend_id) != 0) { |
Konrad Rzeszutek Wilk | 6c254de | 2012-01-04 14:16:45 -0500 | [diff] [blame] | 246 | dev_err(&dev->dev, "Stealing ownership from dom%d.\n", |
| 247 | xen_find_device_domain_owner(dev)); |
Konrad Rzeszutek Wilk | 6221a9b | 2009-12-09 17:43:15 -0500 | [diff] [blame] | 248 | xen_unregister_device_domain_owner(dev); |
| 249 | xen_register_device_domain_owner(dev, pdev->xdev->otherend_id); |
| 250 | } |
| 251 | |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 252 | /* TODO: It'd be nice to export a bridge and have all of its children |
| 253 | * get exported with it. This may be best done in xend (which will |
| 254 | * have to calculate resource usage anyway) but we probably want to |
| 255 | * put something in here to ensure that if a bridge gets given to a |
| 256 | * driver domain, that all devices under that bridge are not given |
| 257 | * to other driver domains (as he who controls the bridge can disable |
| 258 | * it and stop the other devices from working). |
| 259 | */ |
| 260 | out: |
| 261 | return err; |
| 262 | } |
| 263 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 264 | static int xen_pcibk_remove_device(struct xen_pcibk_device *pdev, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 265 | int domain, int bus, int slot, int func) |
| 266 | { |
| 267 | int err = 0; |
| 268 | struct pci_dev *dev; |
| 269 | |
| 270 | dev_dbg(&pdev->xdev->dev, "removing dom %x bus %x slot %x func %x\n", |
| 271 | domain, bus, slot, func); |
| 272 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 273 | dev = xen_pcibk_get_pci_dev(pdev, domain, bus, PCI_DEVFN(slot, func)); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 274 | if (!dev) { |
| 275 | err = -EINVAL; |
| 276 | dev_dbg(&pdev->xdev->dev, "Couldn't locate PCI device " |
| 277 | "(%04x:%02x:%02x.%01x)! not owned by this domain\n", |
| 278 | domain, bus, slot, func); |
| 279 | goto out; |
| 280 | } |
| 281 | |
Konrad Rzeszutek Wilk | 6221a9b | 2009-12-09 17:43:15 -0500 | [diff] [blame] | 282 | dev_dbg(&dev->dev, "unregistering for %d\n", pdev->xdev->otherend_id); |
| 283 | xen_unregister_device_domain_owner(dev); |
| 284 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 285 | xen_pcibk_release_pci_dev(pdev, dev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 286 | |
| 287 | out: |
| 288 | return err; |
| 289 | } |
| 290 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 291 | static int xen_pcibk_publish_pci_root(struct xen_pcibk_device *pdev, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 292 | unsigned int domain, unsigned int bus) |
| 293 | { |
| 294 | unsigned int d, b; |
| 295 | int i, root_num, len, err; |
| 296 | char str[64]; |
| 297 | |
| 298 | dev_dbg(&pdev->xdev->dev, "Publishing pci roots\n"); |
| 299 | |
| 300 | err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, |
| 301 | "root_num", "%d", &root_num); |
| 302 | if (err == 0 || err == -ENOENT) |
| 303 | root_num = 0; |
| 304 | else if (err < 0) |
| 305 | goto out; |
| 306 | |
| 307 | /* Verify that we haven't already published this pci root */ |
| 308 | for (i = 0; i < root_num; i++) { |
| 309 | len = snprintf(str, sizeof(str), "root-%d", i); |
| 310 | if (unlikely(len >= (sizeof(str) - 1))) { |
| 311 | err = -ENOMEM; |
| 312 | goto out; |
| 313 | } |
| 314 | |
| 315 | err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, |
| 316 | str, "%x:%x", &d, &b); |
| 317 | if (err < 0) |
| 318 | goto out; |
| 319 | if (err != 2) { |
| 320 | err = -EINVAL; |
| 321 | goto out; |
| 322 | } |
| 323 | |
| 324 | if (d == domain && b == bus) { |
| 325 | err = 0; |
| 326 | goto out; |
| 327 | } |
| 328 | } |
| 329 | |
| 330 | len = snprintf(str, sizeof(str), "root-%d", root_num); |
| 331 | if (unlikely(len >= (sizeof(str) - 1))) { |
| 332 | err = -ENOMEM; |
| 333 | goto out; |
| 334 | } |
| 335 | |
| 336 | dev_dbg(&pdev->xdev->dev, "writing root %d at %04x:%02x\n", |
| 337 | root_num, domain, bus); |
| 338 | |
| 339 | err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str, |
| 340 | "%04x:%02x", domain, bus); |
| 341 | if (err) |
| 342 | goto out; |
| 343 | |
| 344 | err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, |
| 345 | "root_num", "%d", (root_num + 1)); |
| 346 | |
| 347 | out: |
| 348 | return err; |
| 349 | } |
| 350 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 351 | static int xen_pcibk_reconfigure(struct xen_pcibk_device *pdev) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 352 | { |
| 353 | int err = 0; |
| 354 | int num_devs; |
| 355 | int domain, bus, slot, func; |
| 356 | int substate; |
| 357 | int i, len; |
| 358 | char state_str[64]; |
| 359 | char dev_str[64]; |
| 360 | |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 361 | |
| 362 | dev_dbg(&pdev->xdev->dev, "Reconfiguring device ...\n"); |
| 363 | |
Konrad Rzeszutek Wilk | b1766b6 | 2011-09-16 14:43:14 -0400 | [diff] [blame] | 364 | mutex_lock(&pdev->dev_lock); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 365 | /* Make sure we only reconfigure once */ |
| 366 | if (xenbus_read_driver_state(pdev->xdev->nodename) != |
| 367 | XenbusStateReconfiguring) |
| 368 | goto out; |
| 369 | |
| 370 | err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, "num_devs", "%d", |
| 371 | &num_devs); |
| 372 | if (err != 1) { |
| 373 | if (err >= 0) |
| 374 | err = -EINVAL; |
| 375 | xenbus_dev_fatal(pdev->xdev, err, |
| 376 | "Error reading number of devices"); |
| 377 | goto out; |
| 378 | } |
| 379 | |
| 380 | for (i = 0; i < num_devs; i++) { |
| 381 | len = snprintf(state_str, sizeof(state_str), "state-%d", i); |
| 382 | if (unlikely(len >= (sizeof(state_str) - 1))) { |
| 383 | err = -ENOMEM; |
| 384 | xenbus_dev_fatal(pdev->xdev, err, |
| 385 | "String overflow while reading " |
| 386 | "configuration"); |
| 387 | goto out; |
| 388 | } |
| 389 | err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, state_str, |
| 390 | "%d", &substate); |
| 391 | if (err != 1) |
| 392 | substate = XenbusStateUnknown; |
| 393 | |
| 394 | switch (substate) { |
| 395 | case XenbusStateInitialising: |
| 396 | dev_dbg(&pdev->xdev->dev, "Attaching dev-%d ...\n", i); |
| 397 | |
| 398 | len = snprintf(dev_str, sizeof(dev_str), "dev-%d", i); |
| 399 | if (unlikely(len >= (sizeof(dev_str) - 1))) { |
| 400 | err = -ENOMEM; |
| 401 | xenbus_dev_fatal(pdev->xdev, err, |
| 402 | "String overflow while " |
| 403 | "reading configuration"); |
| 404 | goto out; |
| 405 | } |
| 406 | err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, |
| 407 | dev_str, "%x:%x:%x.%x", |
| 408 | &domain, &bus, &slot, &func); |
| 409 | if (err < 0) { |
| 410 | xenbus_dev_fatal(pdev->xdev, err, |
| 411 | "Error reading device " |
| 412 | "configuration"); |
| 413 | goto out; |
| 414 | } |
| 415 | if (err != 4) { |
| 416 | err = -EINVAL; |
| 417 | xenbus_dev_fatal(pdev->xdev, err, |
| 418 | "Error parsing pci device " |
| 419 | "configuration"); |
| 420 | goto out; |
| 421 | } |
| 422 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 423 | err = xen_pcibk_export_device(pdev, domain, bus, slot, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 424 | func, i); |
| 425 | if (err) |
| 426 | goto out; |
| 427 | |
| 428 | /* Publish pci roots. */ |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 429 | err = xen_pcibk_publish_pci_roots(pdev, |
| 430 | xen_pcibk_publish_pci_root); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 431 | if (err) { |
| 432 | xenbus_dev_fatal(pdev->xdev, err, |
| 433 | "Error while publish PCI root" |
| 434 | "buses for frontend"); |
| 435 | goto out; |
| 436 | } |
| 437 | |
| 438 | err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, |
| 439 | state_str, "%d", |
| 440 | XenbusStateInitialised); |
| 441 | if (err) { |
| 442 | xenbus_dev_fatal(pdev->xdev, err, |
| 443 | "Error switching substate of " |
| 444 | "dev-%d\n", i); |
| 445 | goto out; |
| 446 | } |
| 447 | break; |
| 448 | |
| 449 | case XenbusStateClosing: |
| 450 | dev_dbg(&pdev->xdev->dev, "Detaching dev-%d ...\n", i); |
| 451 | |
| 452 | len = snprintf(dev_str, sizeof(dev_str), "vdev-%d", i); |
| 453 | if (unlikely(len >= (sizeof(dev_str) - 1))) { |
| 454 | err = -ENOMEM; |
| 455 | xenbus_dev_fatal(pdev->xdev, err, |
| 456 | "String overflow while " |
| 457 | "reading configuration"); |
| 458 | goto out; |
| 459 | } |
| 460 | err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, |
| 461 | dev_str, "%x:%x:%x.%x", |
| 462 | &domain, &bus, &slot, &func); |
| 463 | if (err < 0) { |
| 464 | xenbus_dev_fatal(pdev->xdev, err, |
| 465 | "Error reading device " |
| 466 | "configuration"); |
| 467 | goto out; |
| 468 | } |
| 469 | if (err != 4) { |
| 470 | err = -EINVAL; |
| 471 | xenbus_dev_fatal(pdev->xdev, err, |
| 472 | "Error parsing pci device " |
| 473 | "configuration"); |
| 474 | goto out; |
| 475 | } |
| 476 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 477 | err = xen_pcibk_remove_device(pdev, domain, bus, slot, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 478 | func); |
| 479 | if (err) |
| 480 | goto out; |
| 481 | |
| 482 | /* TODO: If at some point we implement support for pci |
| 483 | * root hot-remove on pcifront side, we'll need to |
| 484 | * remove unnecessary xenstore nodes of pci roots here. |
| 485 | */ |
| 486 | |
| 487 | break; |
| 488 | |
| 489 | default: |
| 490 | break; |
| 491 | } |
| 492 | } |
| 493 | |
| 494 | err = xenbus_switch_state(pdev->xdev, XenbusStateReconfigured); |
| 495 | if (err) { |
| 496 | xenbus_dev_fatal(pdev->xdev, err, |
| 497 | "Error switching to reconfigured state!"); |
| 498 | goto out; |
| 499 | } |
| 500 | |
| 501 | out: |
Konrad Rzeszutek Wilk | b1766b6 | 2011-09-16 14:43:14 -0400 | [diff] [blame] | 502 | mutex_unlock(&pdev->dev_lock); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 503 | return 0; |
| 504 | } |
| 505 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 506 | static void xen_pcibk_frontend_changed(struct xenbus_device *xdev, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 507 | enum xenbus_state fe_state) |
| 508 | { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 509 | struct xen_pcibk_device *pdev = dev_get_drvdata(&xdev->dev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 510 | |
| 511 | dev_dbg(&xdev->dev, "fe state changed %d\n", fe_state); |
| 512 | |
| 513 | switch (fe_state) { |
| 514 | case XenbusStateInitialised: |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 515 | xen_pcibk_attach(pdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 516 | break; |
| 517 | |
| 518 | case XenbusStateReconfiguring: |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 519 | xen_pcibk_reconfigure(pdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 520 | break; |
| 521 | |
| 522 | case XenbusStateConnected: |
| 523 | /* pcifront switched its state from reconfiguring to connected. |
| 524 | * Then switch to connected state. |
| 525 | */ |
| 526 | xenbus_switch_state(xdev, XenbusStateConnected); |
| 527 | break; |
| 528 | |
| 529 | case XenbusStateClosing: |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 530 | xen_pcibk_disconnect(pdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 531 | xenbus_switch_state(xdev, XenbusStateClosing); |
| 532 | break; |
| 533 | |
| 534 | case XenbusStateClosed: |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 535 | xen_pcibk_disconnect(pdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 536 | xenbus_switch_state(xdev, XenbusStateClosed); |
| 537 | if (xenbus_dev_is_online(xdev)) |
| 538 | break; |
| 539 | /* fall through if not online */ |
| 540 | case XenbusStateUnknown: |
| 541 | dev_dbg(&xdev->dev, "frontend is gone! unregister device\n"); |
| 542 | device_unregister(&xdev->dev); |
| 543 | break; |
| 544 | |
| 545 | default: |
| 546 | break; |
| 547 | } |
| 548 | } |
| 549 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 550 | static int xen_pcibk_setup_backend(struct xen_pcibk_device *pdev) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 551 | { |
| 552 | /* Get configuration from xend (if available now) */ |
| 553 | int domain, bus, slot, func; |
| 554 | int err = 0; |
| 555 | int i, num_devs; |
| 556 | char dev_str[64]; |
| 557 | char state_str[64]; |
| 558 | |
Konrad Rzeszutek Wilk | b1766b6 | 2011-09-16 14:43:14 -0400 | [diff] [blame] | 559 | mutex_lock(&pdev->dev_lock); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 560 | /* It's possible we could get the call to setup twice, so make sure |
| 561 | * we're not already connected. |
| 562 | */ |
| 563 | if (xenbus_read_driver_state(pdev->xdev->nodename) != |
| 564 | XenbusStateInitWait) |
| 565 | goto out; |
| 566 | |
| 567 | dev_dbg(&pdev->xdev->dev, "getting be setup\n"); |
| 568 | |
| 569 | err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, "num_devs", "%d", |
| 570 | &num_devs); |
| 571 | if (err != 1) { |
| 572 | if (err >= 0) |
| 573 | err = -EINVAL; |
| 574 | xenbus_dev_fatal(pdev->xdev, err, |
| 575 | "Error reading number of devices"); |
| 576 | goto out; |
| 577 | } |
| 578 | |
| 579 | for (i = 0; i < num_devs; i++) { |
| 580 | int l = snprintf(dev_str, sizeof(dev_str), "dev-%d", i); |
| 581 | if (unlikely(l >= (sizeof(dev_str) - 1))) { |
| 582 | err = -ENOMEM; |
| 583 | xenbus_dev_fatal(pdev->xdev, err, |
| 584 | "String overflow while reading " |
| 585 | "configuration"); |
| 586 | goto out; |
| 587 | } |
| 588 | |
| 589 | err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, dev_str, |
| 590 | "%x:%x:%x.%x", &domain, &bus, &slot, &func); |
| 591 | if (err < 0) { |
| 592 | xenbus_dev_fatal(pdev->xdev, err, |
| 593 | "Error reading device configuration"); |
| 594 | goto out; |
| 595 | } |
| 596 | if (err != 4) { |
| 597 | err = -EINVAL; |
| 598 | xenbus_dev_fatal(pdev->xdev, err, |
| 599 | "Error parsing pci device " |
| 600 | "configuration"); |
| 601 | goto out; |
| 602 | } |
| 603 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 604 | err = xen_pcibk_export_device(pdev, domain, bus, slot, func, i); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 605 | if (err) |
| 606 | goto out; |
| 607 | |
| 608 | /* Switch substate of this device. */ |
| 609 | l = snprintf(state_str, sizeof(state_str), "state-%d", i); |
| 610 | if (unlikely(l >= (sizeof(state_str) - 1))) { |
| 611 | err = -ENOMEM; |
| 612 | xenbus_dev_fatal(pdev->xdev, err, |
| 613 | "String overflow while reading " |
| 614 | "configuration"); |
| 615 | goto out; |
| 616 | } |
| 617 | err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, state_str, |
| 618 | "%d", XenbusStateInitialised); |
| 619 | if (err) { |
| 620 | xenbus_dev_fatal(pdev->xdev, err, "Error switching " |
| 621 | "substate of dev-%d\n", i); |
| 622 | goto out; |
| 623 | } |
| 624 | } |
| 625 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 626 | err = xen_pcibk_publish_pci_roots(pdev, xen_pcibk_publish_pci_root); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 627 | if (err) { |
| 628 | xenbus_dev_fatal(pdev->xdev, err, |
| 629 | "Error while publish PCI root buses " |
| 630 | "for frontend"); |
| 631 | goto out; |
| 632 | } |
| 633 | |
| 634 | err = xenbus_switch_state(pdev->xdev, XenbusStateInitialised); |
| 635 | if (err) |
| 636 | xenbus_dev_fatal(pdev->xdev, err, |
| 637 | "Error switching to initialised state!"); |
| 638 | |
| 639 | out: |
Konrad Rzeszutek Wilk | b1766b6 | 2011-09-16 14:43:14 -0400 | [diff] [blame] | 640 | mutex_unlock(&pdev->dev_lock); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 641 | if (!err) |
| 642 | /* see if pcifront is already configured (if not, we'll wait) */ |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 643 | xen_pcibk_attach(pdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 644 | return err; |
| 645 | } |
| 646 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 647 | static void xen_pcibk_be_watch(struct xenbus_watch *watch, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 648 | const char **vec, unsigned int len) |
| 649 | { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 650 | struct xen_pcibk_device *pdev = |
| 651 | container_of(watch, struct xen_pcibk_device, be_watch); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 652 | |
| 653 | switch (xenbus_read_driver_state(pdev->xdev->nodename)) { |
| 654 | case XenbusStateInitWait: |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 655 | xen_pcibk_setup_backend(pdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 656 | break; |
| 657 | |
| 658 | default: |
| 659 | break; |
| 660 | } |
| 661 | } |
| 662 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 663 | static int xen_pcibk_xenbus_probe(struct xenbus_device *dev, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 664 | const struct xenbus_device_id *id) |
| 665 | { |
| 666 | int err = 0; |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 667 | struct xen_pcibk_device *pdev = alloc_pdev(dev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 668 | |
| 669 | if (pdev == NULL) { |
| 670 | err = -ENOMEM; |
| 671 | xenbus_dev_fatal(dev, err, |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 672 | "Error allocating xen_pcibk_device struct"); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 673 | goto out; |
| 674 | } |
| 675 | |
| 676 | /* wait for xend to configure us */ |
| 677 | err = xenbus_switch_state(dev, XenbusStateInitWait); |
| 678 | if (err) |
| 679 | goto out; |
| 680 | |
| 681 | /* watch the backend node for backend configuration information */ |
| 682 | err = xenbus_watch_path(dev, dev->nodename, &pdev->be_watch, |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 683 | xen_pcibk_be_watch); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 684 | if (err) |
| 685 | goto out; |
Konrad Rzeszutek Wilk | 494ef20 | 2010-07-23 14:35:47 -0400 | [diff] [blame] | 686 | |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 687 | pdev->be_watching = 1; |
| 688 | |
| 689 | /* We need to force a call to our callback here in case |
| 690 | * xend already configured us! |
| 691 | */ |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 692 | xen_pcibk_be_watch(&pdev->be_watch, NULL, 0); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 693 | |
| 694 | out: |
| 695 | return err; |
| 696 | } |
| 697 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 698 | static int xen_pcibk_xenbus_remove(struct xenbus_device *dev) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 699 | { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 700 | struct xen_pcibk_device *pdev = dev_get_drvdata(&dev->dev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 701 | |
| 702 | if (pdev != NULL) |
| 703 | free_pdev(pdev); |
| 704 | |
| 705 | return 0; |
| 706 | } |
| 707 | |
Jan Beulich | 73db144 | 2011-12-22 09:08:13 +0000 | [diff] [blame] | 708 | static const struct xenbus_device_id xen_pcibk_ids[] = { |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 709 | {"pci"}, |
| 710 | {""}, |
| 711 | }; |
| 712 | |
Jan Beulich | 73db144 | 2011-12-22 09:08:13 +0000 | [diff] [blame] | 713 | static DEFINE_XENBUS_DRIVER(xen_pcibk, DRV_NAME, |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 714 | .probe = xen_pcibk_xenbus_probe, |
| 715 | .remove = xen_pcibk_xenbus_remove, |
| 716 | .otherend_changed = xen_pcibk_frontend_changed, |
Jan Beulich | 73db144 | 2011-12-22 09:08:13 +0000 | [diff] [blame] | 717 | ); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 718 | |
Jan Beulich | 402c5e1 | 2011-09-21 16:22:11 -0400 | [diff] [blame] | 719 | const struct xen_pcibk_backend *__read_mostly xen_pcibk_backend; |
Konrad Rzeszutek Wilk | 2ebdc42 | 2011-07-11 16:49:41 -0400 | [diff] [blame] | 720 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 721 | int __init xen_pcibk_xenbus_register(void) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 722 | { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 723 | xen_pcibk_wq = create_workqueue("xen_pciback_workqueue"); |
| 724 | if (!xen_pcibk_wq) { |
Konrad Rzeszutek Wilk | 8bfd4e0 | 2011-07-19 20:09:43 -0400 | [diff] [blame] | 725 | printk(KERN_ERR "%s: create" |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 726 | "xen_pciback_workqueue failed\n", __func__); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 727 | return -EFAULT; |
| 728 | } |
Konrad Rzeszutek Wilk | 2ebdc42 | 2011-07-11 16:49:41 -0400 | [diff] [blame] | 729 | xen_pcibk_backend = &xen_pcibk_vpci_backend; |
| 730 | if (passthrough) |
| 731 | xen_pcibk_backend = &xen_pcibk_passthrough_backend; |
| 732 | pr_info(DRV_NAME ": backend is %s\n", xen_pcibk_backend->name); |
Jan Beulich | 73db144 | 2011-12-22 09:08:13 +0000 | [diff] [blame] | 733 | return xenbus_register_backend(&xen_pcibk_driver); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 734 | } |
| 735 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 736 | void __exit xen_pcibk_xenbus_unregister(void) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 737 | { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 738 | destroy_workqueue(xen_pcibk_wq); |
Jan Beulich | 73db144 | 2011-12-22 09:08:13 +0000 | [diff] [blame] | 739 | xenbus_unregister_driver(&xen_pcibk_driver); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 740 | } |