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