blob: 70030c4092128c736f2ab087a21991fc213daf6e [file] [log] [blame]
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -04001/*
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 Wilk6221a9b2009-12-09 17:43:15 -050013#include <asm/xen/pci.h>
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040014#include <linux/workqueue.h>
15#include "pciback.h"
16
17#define INVALID_EVTCHN_IRQ (-1)
18struct workqueue_struct *pciback_wq;
19
20static struct pciback_device *alloc_pdev(struct xenbus_device *xdev)
21{
22 struct pciback_device *pdev;
23
24 pdev = kzalloc(sizeof(struct pciback_device), GFP_KERNEL);
25 if (pdev == NULL)
26 goto out;
27 dev_dbg(&xdev->dev, "allocated pdev @ 0x%p\n", pdev);
28
29 pdev->xdev = xdev;
30 dev_set_drvdata(&xdev->dev, pdev);
31
32 spin_lock_init(&pdev->dev_lock);
33
34 pdev->sh_info = NULL;
35 pdev->evtchn_irq = INVALID_EVTCHN_IRQ;
36 pdev->be_watching = 0;
37
38 INIT_WORK(&pdev->op_work, pciback_do_op);
39
40 if (pciback_init_devices(pdev)) {
41 kfree(pdev);
42 pdev = NULL;
43 }
44out:
45 return pdev;
46}
47
48static void pciback_disconnect(struct pciback_device *pdev)
49{
50 spin_lock(&pdev->dev_lock);
51
52 /* Ensure the guest can't trigger our handler before removing devices */
53 if (pdev->evtchn_irq != INVALID_EVTCHN_IRQ) {
54 unbind_from_irqhandler(pdev->evtchn_irq, pdev);
55 pdev->evtchn_irq = INVALID_EVTCHN_IRQ;
56 }
Konrad Rzeszutek Wilk494ef202010-07-23 14:35:47 -040057 spin_unlock(&pdev->dev_lock);
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040058
59 /* If the driver domain started an op, make sure we complete it
60 * before releasing the shared memory */
Konrad Rzeszutek Wilk494ef202010-07-23 14:35:47 -040061
62 /* Note, the workqueue does not use spinlocks at all.*/
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040063 flush_workqueue(pciback_wq);
64
Konrad Rzeszutek Wilk494ef202010-07-23 14:35:47 -040065 spin_lock(&pdev->dev_lock);
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040066 if (pdev->sh_info != NULL) {
67 xenbus_unmap_ring_vfree(pdev->xdev, pdev->sh_info);
68 pdev->sh_info = NULL;
69 }
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040070 spin_unlock(&pdev->dev_lock);
Konrad Rzeszutek Wilk494ef202010-07-23 14:35:47 -040071
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040072}
73
74static void free_pdev(struct pciback_device *pdev)
75{
Konrad Rzeszutek Wilk494ef202010-07-23 14:35:47 -040076 if (pdev->be_watching) {
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040077 unregister_xenbus_watch(&pdev->be_watch);
Konrad Rzeszutek Wilk494ef202010-07-23 14:35:47 -040078 pdev->be_watching = 0;
79 }
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -040080
81 pciback_disconnect(pdev);
82
83 pciback_release_devices(pdev);
84
85 dev_set_drvdata(&pdev->xdev->dev, NULL);
86 pdev->xdev = NULL;
87
88 kfree(pdev);
89}
90
91static int pciback_do_attach(struct pciback_device *pdev, int gnt_ref,
92 int remote_evtchn)
93{
94 int err = 0;
95 void *vaddr;
96
97 dev_dbg(&pdev->xdev->dev,
98 "Attaching to frontend resources - gnt_ref=%d evtchn=%d\n",
99 gnt_ref, remote_evtchn);
100
101 err = xenbus_map_ring_valloc(pdev->xdev, gnt_ref, &vaddr);
102 if (err < 0) {
103 xenbus_dev_fatal(pdev->xdev, err,
104 "Error mapping other domain page in ours.");
105 goto out;
106 }
Konrad Rzeszutek Wilk494ef202010-07-23 14:35:47 -0400107
108 spin_lock(&pdev->dev_lock);
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400109 pdev->sh_info = vaddr;
Konrad Rzeszutek Wilk494ef202010-07-23 14:35:47 -0400110 spin_unlock(&pdev->dev_lock);
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400111
112 err = bind_interdomain_evtchn_to_irqhandler(
113 pdev->xdev->otherend_id, remote_evtchn, pciback_handle_event,
114 0, "pciback", pdev);
115 if (err < 0) {
116 xenbus_dev_fatal(pdev->xdev, err,
117 "Error binding event channel to IRQ");
118 goto out;
119 }
Konrad Rzeszutek Wilk494ef202010-07-23 14:35:47 -0400120
121 spin_lock(&pdev->dev_lock);
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400122 pdev->evtchn_irq = err;
Konrad Rzeszutek Wilk494ef202010-07-23 14:35:47 -0400123 spin_unlock(&pdev->dev_lock);
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400124 err = 0;
125
126 dev_dbg(&pdev->xdev->dev, "Attached!\n");
127out:
128 return err;
129}
130
131static int pciback_attach(struct pciback_device *pdev)
132{
133 int err = 0;
134 int gnt_ref, remote_evtchn;
135 char *magic = NULL;
136
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400137
138 /* Make sure we only do this setup once */
139 if (xenbus_read_driver_state(pdev->xdev->nodename) !=
140 XenbusStateInitialised)
141 goto out;
142
143 /* Wait for frontend to state that it has published the configuration */
144 if (xenbus_read_driver_state(pdev->xdev->otherend) !=
145 XenbusStateInitialised)
146 goto out;
147
148 dev_dbg(&pdev->xdev->dev, "Reading frontend config\n");
149
150 err = xenbus_gather(XBT_NIL, pdev->xdev->otherend,
151 "pci-op-ref", "%u", &gnt_ref,
152 "event-channel", "%u", &remote_evtchn,
153 "magic", NULL, &magic, NULL);
154 if (err) {
155 /* If configuration didn't get read correctly, wait longer */
156 xenbus_dev_fatal(pdev->xdev, err,
157 "Error reading configuration from frontend");
158 goto out;
159 }
160
161 if (magic == NULL || strcmp(magic, XEN_PCI_MAGIC) != 0) {
162 xenbus_dev_fatal(pdev->xdev, -EFAULT,
163 "version mismatch (%s/%s) with pcifront - "
164 "halting pciback",
165 magic, XEN_PCI_MAGIC);
166 goto out;
167 }
168
169 err = pciback_do_attach(pdev, gnt_ref, remote_evtchn);
170 if (err)
171 goto out;
172
173 dev_dbg(&pdev->xdev->dev, "Connecting...\n");
174
175 err = xenbus_switch_state(pdev->xdev, XenbusStateConnected);
176 if (err)
177 xenbus_dev_fatal(pdev->xdev, err,
178 "Error switching to connected state!");
179
180 dev_dbg(&pdev->xdev->dev, "Connected? %d\n", err);
181out:
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400182
183 kfree(magic);
184
185 return err;
186}
187
188static int pciback_publish_pci_dev(struct pciback_device *pdev,
189 unsigned int domain, unsigned int bus,
190 unsigned int devfn, unsigned int devid)
191{
192 int err;
193 int len;
194 char str[64];
195
196 len = snprintf(str, sizeof(str), "vdev-%d", devid);
197 if (unlikely(len >= (sizeof(str) - 1))) {
198 err = -ENOMEM;
199 goto out;
200 }
201
202 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str,
203 "%04x:%02x:%02x.%02x", domain, bus,
204 PCI_SLOT(devfn), PCI_FUNC(devfn));
205
206out:
207 return err;
208}
209
210static int pciback_export_device(struct pciback_device *pdev,
211 int domain, int bus, int slot, int func,
212 int devid)
213{
214 struct pci_dev *dev;
215 int err = 0;
216
217 dev_dbg(&pdev->xdev->dev, "exporting dom %x bus %x slot %x func %x\n",
218 domain, bus, slot, func);
219
220 dev = pcistub_get_pci_dev_by_slot(pdev, domain, bus, slot, func);
221 if (!dev) {
222 err = -EINVAL;
223 xenbus_dev_fatal(pdev->xdev, err,
224 "Couldn't locate PCI device "
225 "(%04x:%02x:%02x.%01x)! "
226 "perhaps already in-use?",
227 domain, bus, slot, func);
228 goto out;
229 }
230
231 err = pciback_add_pci_dev(pdev, dev, devid, pciback_publish_pci_dev);
232 if (err)
233 goto out;
234
Konrad Rzeszutek Wilk6221a9b2009-12-09 17:43:15 -0500235 dev_dbg(&dev->dev, "registering for %d\n", pdev->xdev->otherend_id);
236 if (xen_register_device_domain_owner(dev,
237 pdev->xdev->otherend_id) != 0) {
238 dev_err(&dev->dev, "device has been assigned to another " \
239 "domain! Over-writting the ownership, but beware.\n");
240 xen_unregister_device_domain_owner(dev);
241 xen_register_device_domain_owner(dev, pdev->xdev->otherend_id);
242 }
243
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400244 /* TODO: It'd be nice to export a bridge and have all of its children
245 * get exported with it. This may be best done in xend (which will
246 * have to calculate resource usage anyway) but we probably want to
247 * put something in here to ensure that if a bridge gets given to a
248 * driver domain, that all devices under that bridge are not given
249 * to other driver domains (as he who controls the bridge can disable
250 * it and stop the other devices from working).
251 */
252out:
253 return err;
254}
255
256static int pciback_remove_device(struct pciback_device *pdev,
257 int domain, int bus, int slot, int func)
258{
259 int err = 0;
260 struct pci_dev *dev;
261
262 dev_dbg(&pdev->xdev->dev, "removing dom %x bus %x slot %x func %x\n",
263 domain, bus, slot, func);
264
265 dev = pciback_get_pci_dev(pdev, domain, bus, PCI_DEVFN(slot, func));
266 if (!dev) {
267 err = -EINVAL;
268 dev_dbg(&pdev->xdev->dev, "Couldn't locate PCI device "
269 "(%04x:%02x:%02x.%01x)! not owned by this domain\n",
270 domain, bus, slot, func);
271 goto out;
272 }
273
Konrad Rzeszutek Wilk6221a9b2009-12-09 17:43:15 -0500274 dev_dbg(&dev->dev, "unregistering for %d\n", pdev->xdev->otherend_id);
275 xen_unregister_device_domain_owner(dev);
276
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400277 pciback_release_pci_dev(pdev, dev);
278
279out:
280 return err;
281}
282
283static int pciback_publish_pci_root(struct pciback_device *pdev,
284 unsigned int domain, unsigned int bus)
285{
286 unsigned int d, b;
287 int i, root_num, len, err;
288 char str[64];
289
290 dev_dbg(&pdev->xdev->dev, "Publishing pci roots\n");
291
292 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename,
293 "root_num", "%d", &root_num);
294 if (err == 0 || err == -ENOENT)
295 root_num = 0;
296 else if (err < 0)
297 goto out;
298
299 /* Verify that we haven't already published this pci root */
300 for (i = 0; i < root_num; i++) {
301 len = snprintf(str, sizeof(str), "root-%d", i);
302 if (unlikely(len >= (sizeof(str) - 1))) {
303 err = -ENOMEM;
304 goto out;
305 }
306
307 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename,
308 str, "%x:%x", &d, &b);
309 if (err < 0)
310 goto out;
311 if (err != 2) {
312 err = -EINVAL;
313 goto out;
314 }
315
316 if (d == domain && b == bus) {
317 err = 0;
318 goto out;
319 }
320 }
321
322 len = snprintf(str, sizeof(str), "root-%d", root_num);
323 if (unlikely(len >= (sizeof(str) - 1))) {
324 err = -ENOMEM;
325 goto out;
326 }
327
328 dev_dbg(&pdev->xdev->dev, "writing root %d at %04x:%02x\n",
329 root_num, domain, bus);
330
331 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str,
332 "%04x:%02x", domain, bus);
333 if (err)
334 goto out;
335
336 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename,
337 "root_num", "%d", (root_num + 1));
338
339out:
340 return err;
341}
342
343static int pciback_reconfigure(struct pciback_device *pdev)
344{
345 int err = 0;
346 int num_devs;
347 int domain, bus, slot, func;
348 int substate;
349 int i, len;
350 char state_str[64];
351 char dev_str[64];
352
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400353
354 dev_dbg(&pdev->xdev->dev, "Reconfiguring device ...\n");
355
356 /* Make sure we only reconfigure once */
357 if (xenbus_read_driver_state(pdev->xdev->nodename) !=
358 XenbusStateReconfiguring)
359 goto out;
360
361 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, "num_devs", "%d",
362 &num_devs);
363 if (err != 1) {
364 if (err >= 0)
365 err = -EINVAL;
366 xenbus_dev_fatal(pdev->xdev, err,
367 "Error reading number of devices");
368 goto out;
369 }
370
371 for (i = 0; i < num_devs; i++) {
372 len = snprintf(state_str, sizeof(state_str), "state-%d", i);
373 if (unlikely(len >= (sizeof(state_str) - 1))) {
374 err = -ENOMEM;
375 xenbus_dev_fatal(pdev->xdev, err,
376 "String overflow while reading "
377 "configuration");
378 goto out;
379 }
380 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, state_str,
381 "%d", &substate);
382 if (err != 1)
383 substate = XenbusStateUnknown;
384
385 switch (substate) {
386 case XenbusStateInitialising:
387 dev_dbg(&pdev->xdev->dev, "Attaching dev-%d ...\n", i);
388
389 len = snprintf(dev_str, sizeof(dev_str), "dev-%d", i);
390 if (unlikely(len >= (sizeof(dev_str) - 1))) {
391 err = -ENOMEM;
392 xenbus_dev_fatal(pdev->xdev, err,
393 "String overflow while "
394 "reading configuration");
395 goto out;
396 }
397 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename,
398 dev_str, "%x:%x:%x.%x",
399 &domain, &bus, &slot, &func);
400 if (err < 0) {
401 xenbus_dev_fatal(pdev->xdev, err,
402 "Error reading device "
403 "configuration");
404 goto out;
405 }
406 if (err != 4) {
407 err = -EINVAL;
408 xenbus_dev_fatal(pdev->xdev, err,
409 "Error parsing pci device "
410 "configuration");
411 goto out;
412 }
413
414 err = pciback_export_device(pdev, domain, bus, slot,
415 func, i);
416 if (err)
417 goto out;
418
419 /* Publish pci roots. */
420 err = pciback_publish_pci_roots(pdev,
421 pciback_publish_pci_root);
422 if (err) {
423 xenbus_dev_fatal(pdev->xdev, err,
424 "Error while publish PCI root"
425 "buses for frontend");
426 goto out;
427 }
428
429 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename,
430 state_str, "%d",
431 XenbusStateInitialised);
432 if (err) {
433 xenbus_dev_fatal(pdev->xdev, err,
434 "Error switching substate of "
435 "dev-%d\n", i);
436 goto out;
437 }
438 break;
439
440 case XenbusStateClosing:
441 dev_dbg(&pdev->xdev->dev, "Detaching dev-%d ...\n", i);
442
443 len = snprintf(dev_str, sizeof(dev_str), "vdev-%d", i);
444 if (unlikely(len >= (sizeof(dev_str) - 1))) {
445 err = -ENOMEM;
446 xenbus_dev_fatal(pdev->xdev, err,
447 "String overflow while "
448 "reading configuration");
449 goto out;
450 }
451 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename,
452 dev_str, "%x:%x:%x.%x",
453 &domain, &bus, &slot, &func);
454 if (err < 0) {
455 xenbus_dev_fatal(pdev->xdev, err,
456 "Error reading device "
457 "configuration");
458 goto out;
459 }
460 if (err != 4) {
461 err = -EINVAL;
462 xenbus_dev_fatal(pdev->xdev, err,
463 "Error parsing pci device "
464 "configuration");
465 goto out;
466 }
467
468 err = pciback_remove_device(pdev, domain, bus, slot,
469 func);
470 if (err)
471 goto out;
472
473 /* TODO: If at some point we implement support for pci
474 * root hot-remove on pcifront side, we'll need to
475 * remove unnecessary xenstore nodes of pci roots here.
476 */
477
478 break;
479
480 default:
481 break;
482 }
483 }
484
485 err = xenbus_switch_state(pdev->xdev, XenbusStateReconfigured);
486 if (err) {
487 xenbus_dev_fatal(pdev->xdev, err,
488 "Error switching to reconfigured state!");
489 goto out;
490 }
491
492out:
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400493 return 0;
494}
495
496static void pciback_frontend_changed(struct xenbus_device *xdev,
497 enum xenbus_state fe_state)
498{
499 struct pciback_device *pdev = dev_get_drvdata(&xdev->dev);
500
501 dev_dbg(&xdev->dev, "fe state changed %d\n", fe_state);
502
503 switch (fe_state) {
504 case XenbusStateInitialised:
505 pciback_attach(pdev);
506 break;
507
508 case XenbusStateReconfiguring:
509 pciback_reconfigure(pdev);
510 break;
511
512 case XenbusStateConnected:
513 /* pcifront switched its state from reconfiguring to connected.
514 * Then switch to connected state.
515 */
516 xenbus_switch_state(xdev, XenbusStateConnected);
517 break;
518
519 case XenbusStateClosing:
520 pciback_disconnect(pdev);
521 xenbus_switch_state(xdev, XenbusStateClosing);
522 break;
523
524 case XenbusStateClosed:
525 pciback_disconnect(pdev);
526 xenbus_switch_state(xdev, XenbusStateClosed);
527 if (xenbus_dev_is_online(xdev))
528 break;
529 /* fall through if not online */
530 case XenbusStateUnknown:
531 dev_dbg(&xdev->dev, "frontend is gone! unregister device\n");
532 device_unregister(&xdev->dev);
533 break;
534
535 default:
536 break;
537 }
538}
539
540static int pciback_setup_backend(struct pciback_device *pdev)
541{
542 /* Get configuration from xend (if available now) */
543 int domain, bus, slot, func;
544 int err = 0;
545 int i, num_devs;
546 char dev_str[64];
547 char state_str[64];
548
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400549 /* It's possible we could get the call to setup twice, so make sure
550 * we're not already connected.
551 */
552 if (xenbus_read_driver_state(pdev->xdev->nodename) !=
553 XenbusStateInitWait)
554 goto out;
555
556 dev_dbg(&pdev->xdev->dev, "getting be setup\n");
557
558 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, "num_devs", "%d",
559 &num_devs);
560 if (err != 1) {
561 if (err >= 0)
562 err = -EINVAL;
563 xenbus_dev_fatal(pdev->xdev, err,
564 "Error reading number of devices");
565 goto out;
566 }
567
568 for (i = 0; i < num_devs; i++) {
569 int l = snprintf(dev_str, sizeof(dev_str), "dev-%d", i);
570 if (unlikely(l >= (sizeof(dev_str) - 1))) {
571 err = -ENOMEM;
572 xenbus_dev_fatal(pdev->xdev, err,
573 "String overflow while reading "
574 "configuration");
575 goto out;
576 }
577
578 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, dev_str,
579 "%x:%x:%x.%x", &domain, &bus, &slot, &func);
580 if (err < 0) {
581 xenbus_dev_fatal(pdev->xdev, err,
582 "Error reading device configuration");
583 goto out;
584 }
585 if (err != 4) {
586 err = -EINVAL;
587 xenbus_dev_fatal(pdev->xdev, err,
588 "Error parsing pci device "
589 "configuration");
590 goto out;
591 }
592
593 err = pciback_export_device(pdev, domain, bus, slot, func, i);
594 if (err)
595 goto out;
596
597 /* Switch substate of this device. */
598 l = snprintf(state_str, sizeof(state_str), "state-%d", i);
599 if (unlikely(l >= (sizeof(state_str) - 1))) {
600 err = -ENOMEM;
601 xenbus_dev_fatal(pdev->xdev, err,
602 "String overflow while reading "
603 "configuration");
604 goto out;
605 }
606 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, state_str,
607 "%d", XenbusStateInitialised);
608 if (err) {
609 xenbus_dev_fatal(pdev->xdev, err, "Error switching "
610 "substate of dev-%d\n", i);
611 goto out;
612 }
613 }
614
615 err = pciback_publish_pci_roots(pdev, pciback_publish_pci_root);
616 if (err) {
617 xenbus_dev_fatal(pdev->xdev, err,
618 "Error while publish PCI root buses "
619 "for frontend");
620 goto out;
621 }
622
623 err = xenbus_switch_state(pdev->xdev, XenbusStateInitialised);
624 if (err)
625 xenbus_dev_fatal(pdev->xdev, err,
626 "Error switching to initialised state!");
627
628out:
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400629 if (!err)
630 /* see if pcifront is already configured (if not, we'll wait) */
631 pciback_attach(pdev);
632
633 return err;
634}
635
636static void pciback_be_watch(struct xenbus_watch *watch,
637 const char **vec, unsigned int len)
638{
639 struct pciback_device *pdev =
640 container_of(watch, struct pciback_device, be_watch);
641
642 switch (xenbus_read_driver_state(pdev->xdev->nodename)) {
643 case XenbusStateInitWait:
644 pciback_setup_backend(pdev);
645 break;
646
647 default:
648 break;
649 }
650}
651
652static int pciback_xenbus_probe(struct xenbus_device *dev,
653 const struct xenbus_device_id *id)
654{
655 int err = 0;
656 struct pciback_device *pdev = alloc_pdev(dev);
657
658 if (pdev == NULL) {
659 err = -ENOMEM;
660 xenbus_dev_fatal(dev, err,
661 "Error allocating pciback_device struct");
662 goto out;
663 }
664
665 /* wait for xend to configure us */
666 err = xenbus_switch_state(dev, XenbusStateInitWait);
667 if (err)
668 goto out;
669
670 /* watch the backend node for backend configuration information */
671 err = xenbus_watch_path(dev, dev->nodename, &pdev->be_watch,
672 pciback_be_watch);
673 if (err)
674 goto out;
Konrad Rzeszutek Wilk494ef202010-07-23 14:35:47 -0400675
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400676 pdev->be_watching = 1;
677
678 /* We need to force a call to our callback here in case
679 * xend already configured us!
680 */
681 pciback_be_watch(&pdev->be_watch, NULL, 0);
682
683out:
684 return err;
685}
686
687static int pciback_xenbus_remove(struct xenbus_device *dev)
688{
689 struct pciback_device *pdev = dev_get_drvdata(&dev->dev);
690
691 if (pdev != NULL)
692 free_pdev(pdev);
693
694 return 0;
695}
696
697static const struct xenbus_device_id xenpci_ids[] = {
698 {"pci"},
699 {""},
700};
701
702static struct xenbus_driver xenbus_pciback_driver = {
Konrad Rzeszutek Wilk8bfd4e02011-07-19 20:09:43 -0400703 .name = "pciback",
704 .owner = THIS_MODULE,
705 .ids = xenpci_ids,
706 .probe = pciback_xenbus_probe,
707 .remove = pciback_xenbus_remove,
708 .otherend_changed = pciback_frontend_changed,
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400709};
710
711int __init pciback_xenbus_register(void)
712{
713 pciback_wq = create_workqueue("pciback_workqueue");
714 if (!pciback_wq) {
Konrad Rzeszutek Wilk8bfd4e02011-07-19 20:09:43 -0400715 printk(KERN_ERR "%s: create"
716 "pciback_workqueue failed\n", __func__);
Konrad Rzeszutek Wilk30edc142009-10-13 17:22:20 -0400717 return -EFAULT;
718 }
719 return xenbus_register_backend(&xenbus_pciback_driver);
720}
721
722void __exit pciback_xenbus_unregister(void)
723{
724 destroy_workqueue(pciback_wq);
725 xenbus_unregister_driver(&xenbus_pciback_driver);
726}