Lines Matching refs:pdev
39 struct xen_pcibk_device *pdev; in alloc_pdev() local
41 pdev = kzalloc(sizeof(struct xen_pcibk_device), GFP_KERNEL); in alloc_pdev()
42 if (pdev == NULL) in alloc_pdev()
44 dev_dbg(&xdev->dev, "allocated pdev @ 0x%p\n", pdev); in alloc_pdev()
46 pdev->xdev = xdev; in alloc_pdev()
48 mutex_init(&pdev->dev_lock); in alloc_pdev()
50 pdev->sh_info = NULL; in alloc_pdev()
51 pdev->evtchn_irq = INVALID_EVTCHN_IRQ; in alloc_pdev()
52 pdev->be_watching = 0; in alloc_pdev()
54 INIT_WORK(&pdev->op_work, xen_pcibk_do_op); in alloc_pdev()
56 if (xen_pcibk_init_devices(pdev)) { in alloc_pdev()
57 kfree(pdev); in alloc_pdev()
58 pdev = NULL; in alloc_pdev()
61 dev_set_drvdata(&xdev->dev, pdev); in alloc_pdev()
64 return pdev; in alloc_pdev()
67 static void xen_pcibk_disconnect(struct xen_pcibk_device *pdev) in xen_pcibk_disconnect() argument
69 mutex_lock(&pdev->dev_lock); in xen_pcibk_disconnect()
71 if (pdev->evtchn_irq != INVALID_EVTCHN_IRQ) { in xen_pcibk_disconnect()
72 unbind_from_irqhandler(pdev->evtchn_irq, pdev); in xen_pcibk_disconnect()
73 pdev->evtchn_irq = INVALID_EVTCHN_IRQ; in xen_pcibk_disconnect()
79 flush_work(&pdev->op_work); in xen_pcibk_disconnect()
81 if (pdev->sh_info != NULL) { in xen_pcibk_disconnect()
82 xenbus_unmap_ring_vfree(pdev->xdev, pdev->sh_info); in xen_pcibk_disconnect()
83 pdev->sh_info = NULL; in xen_pcibk_disconnect()
85 mutex_unlock(&pdev->dev_lock); in xen_pcibk_disconnect()
88 static void free_pdev(struct xen_pcibk_device *pdev) in free_pdev() argument
90 if (pdev->be_watching) { in free_pdev()
91 unregister_xenbus_watch(&pdev->be_watch); in free_pdev()
92 pdev->be_watching = 0; in free_pdev()
95 xen_pcibk_disconnect(pdev); in free_pdev()
99 xen_pcibk_release_devices(pdev); in free_pdev()
101 dev_set_drvdata(&pdev->xdev->dev, NULL); in free_pdev()
102 pdev->xdev = NULL; in free_pdev()
104 kfree(pdev); in free_pdev()
107 static int xen_pcibk_do_attach(struct xen_pcibk_device *pdev, int gnt_ref, in xen_pcibk_do_attach() argument
113 dev_dbg(&pdev->xdev->dev, in xen_pcibk_do_attach()
117 err = xenbus_map_ring_valloc(pdev->xdev, &gnt_ref, 1, &vaddr); in xen_pcibk_do_attach()
119 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_do_attach()
124 pdev->sh_info = vaddr; in xen_pcibk_do_attach()
127 pdev->xdev, remote_evtchn, xen_pcibk_handle_event, in xen_pcibk_do_attach()
128 0, DRV_NAME, pdev); in xen_pcibk_do_attach()
130 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_do_attach()
134 pdev->evtchn_irq = err; in xen_pcibk_do_attach()
137 dev_dbg(&pdev->xdev->dev, "Attached!\n"); in xen_pcibk_do_attach()
142 static int xen_pcibk_attach(struct xen_pcibk_device *pdev) in xen_pcibk_attach() argument
150 mutex_lock(&pdev->dev_lock); in xen_pcibk_attach()
152 if (xenbus_read_driver_state(pdev->xdev->nodename) != in xen_pcibk_attach()
157 if (xenbus_read_driver_state(pdev->xdev->otherend) != in xen_pcibk_attach()
161 dev_dbg(&pdev->xdev->dev, "Reading frontend config\n"); in xen_pcibk_attach()
163 err = xenbus_gather(XBT_NIL, pdev->xdev->otherend, in xen_pcibk_attach()
169 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_attach()
175 xenbus_dev_fatal(pdev->xdev, -EFAULT, in xen_pcibk_attach()
183 err = xen_pcibk_do_attach(pdev, gnt_ref, remote_evtchn); in xen_pcibk_attach()
187 dev_dbg(&pdev->xdev->dev, "Connecting...\n"); in xen_pcibk_attach()
189 err = xenbus_switch_state(pdev->xdev, XenbusStateConnected); in xen_pcibk_attach()
191 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_attach()
194 dev_dbg(&pdev->xdev->dev, "Connected? %d\n", err); in xen_pcibk_attach()
196 mutex_unlock(&pdev->dev_lock); in xen_pcibk_attach()
203 static int xen_pcibk_publish_pci_dev(struct xen_pcibk_device *pdev, in xen_pcibk_publish_pci_dev() argument
218 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str, in xen_pcibk_publish_pci_dev()
226 static int xen_pcibk_export_device(struct xen_pcibk_device *pdev, in xen_pcibk_export_device() argument
233 dev_dbg(&pdev->xdev->dev, "exporting dom %x bus %x slot %x func %x\n", in xen_pcibk_export_device()
236 dev = pcistub_get_pci_dev_by_slot(pdev, domain, bus, slot, func); in xen_pcibk_export_device()
239 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_export_device()
247 err = xen_pcibk_add_pci_dev(pdev, dev, devid, in xen_pcibk_export_device()
252 dev_info(&dev->dev, "registering for %d\n", pdev->xdev->otherend_id); in xen_pcibk_export_device()
254 pdev->xdev->otherend_id) != 0) { in xen_pcibk_export_device()
258 xen_register_device_domain_owner(dev, pdev->xdev->otherend_id); in xen_pcibk_export_device()
273 static int xen_pcibk_remove_device(struct xen_pcibk_device *pdev, in xen_pcibk_remove_device() argument
279 dev_dbg(&pdev->xdev->dev, "removing dom %x bus %x slot %x func %x\n", in xen_pcibk_remove_device()
282 dev = xen_pcibk_get_pci_dev(pdev, domain, bus, PCI_DEVFN(slot, func)); in xen_pcibk_remove_device()
285 dev_dbg(&pdev->xdev->dev, "Couldn't locate PCI device " in xen_pcibk_remove_device()
291 dev_dbg(&dev->dev, "unregistering for %d\n", pdev->xdev->otherend_id); in xen_pcibk_remove_device()
296 xen_pcibk_release_pci_dev(pdev, dev, true /* use the lock. */); in xen_pcibk_remove_device()
302 static int xen_pcibk_publish_pci_root(struct xen_pcibk_device *pdev, in xen_pcibk_publish_pci_root() argument
309 dev_dbg(&pdev->xdev->dev, "Publishing pci roots\n"); in xen_pcibk_publish_pci_root()
311 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, in xen_pcibk_publish_pci_root()
326 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, in xen_pcibk_publish_pci_root()
347 dev_dbg(&pdev->xdev->dev, "writing root %d at %04x:%02x\n", in xen_pcibk_publish_pci_root()
350 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str, in xen_pcibk_publish_pci_root()
355 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, in xen_pcibk_publish_pci_root()
362 static int xen_pcibk_reconfigure(struct xen_pcibk_device *pdev, in xen_pcibk_reconfigure() argument
374 dev_dbg(&pdev->xdev->dev, "Reconfiguring device ...\n"); in xen_pcibk_reconfigure()
376 mutex_lock(&pdev->dev_lock); in xen_pcibk_reconfigure()
377 if (xenbus_read_driver_state(pdev->xdev->nodename) != state) in xen_pcibk_reconfigure()
380 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, "num_devs", "%d", in xen_pcibk_reconfigure()
385 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
394 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
399 substate = xenbus_read_unsigned(pdev->xdev->nodename, state_str, in xen_pcibk_reconfigure()
404 dev_dbg(&pdev->xdev->dev, "Attaching dev-%d ...\n", i); in xen_pcibk_reconfigure()
409 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
414 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, in xen_pcibk_reconfigure()
418 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
425 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
431 err = xen_pcibk_export_device(pdev, domain, bus, slot, in xen_pcibk_reconfigure()
437 err = xen_pcibk_publish_pci_roots(pdev, in xen_pcibk_reconfigure()
440 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
446 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, in xen_pcibk_reconfigure()
450 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
458 dev_dbg(&pdev->xdev->dev, "Detaching dev-%d ...\n", i); in xen_pcibk_reconfigure()
463 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
468 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, in xen_pcibk_reconfigure()
472 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
479 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
485 err = xen_pcibk_remove_device(pdev, domain, bus, slot, in xen_pcibk_reconfigure()
506 err = xenbus_switch_state(pdev->xdev, XenbusStateReconfigured); in xen_pcibk_reconfigure()
508 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
514 mutex_unlock(&pdev->dev_lock); in xen_pcibk_reconfigure()
521 struct xen_pcibk_device *pdev = dev_get_drvdata(&xdev->dev); in xen_pcibk_frontend_changed() local
527 xen_pcibk_attach(pdev); in xen_pcibk_frontend_changed()
531 xen_pcibk_reconfigure(pdev, XenbusStateReconfiguring); in xen_pcibk_frontend_changed()
542 xen_pcibk_disconnect(pdev); in xen_pcibk_frontend_changed()
547 xen_pcibk_disconnect(pdev); in xen_pcibk_frontend_changed()
562 static int xen_pcibk_setup_backend(struct xen_pcibk_device *pdev) in xen_pcibk_setup_backend() argument
571 mutex_lock(&pdev->dev_lock); in xen_pcibk_setup_backend()
575 if (xenbus_read_driver_state(pdev->xdev->nodename) != in xen_pcibk_setup_backend()
579 dev_dbg(&pdev->xdev->dev, "getting be setup\n"); in xen_pcibk_setup_backend()
581 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, "num_devs", "%d", in xen_pcibk_setup_backend()
586 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
595 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
601 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, dev_str, in xen_pcibk_setup_backend()
604 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
610 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
616 err = xen_pcibk_export_device(pdev, domain, bus, slot, func, i); in xen_pcibk_setup_backend()
624 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
629 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, state_str, in xen_pcibk_setup_backend()
632 xenbus_dev_fatal(pdev->xdev, err, "Error switching " in xen_pcibk_setup_backend()
638 err = xen_pcibk_publish_pci_roots(pdev, xen_pcibk_publish_pci_root); in xen_pcibk_setup_backend()
640 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
646 err = xenbus_switch_state(pdev->xdev, XenbusStateInitialised); in xen_pcibk_setup_backend()
648 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
652 mutex_unlock(&pdev->dev_lock); in xen_pcibk_setup_backend()
655 xen_pcibk_attach(pdev); in xen_pcibk_setup_backend()
662 struct xen_pcibk_device *pdev = in xen_pcibk_be_watch() local
665 switch (xenbus_read_driver_state(pdev->xdev->nodename)) { in xen_pcibk_be_watch()
667 xen_pcibk_setup_backend(pdev); in xen_pcibk_be_watch()
676 xen_pcibk_reconfigure(pdev, XenbusStateInitialised); in xen_pcibk_be_watch()
688 struct xen_pcibk_device *pdev = alloc_pdev(dev); in xen_pcibk_xenbus_probe() local
690 if (pdev == NULL) { in xen_pcibk_xenbus_probe()
703 err = xenbus_watch_path(dev, dev->nodename, &pdev->be_watch, in xen_pcibk_xenbus_probe()
708 pdev->be_watching = 1; in xen_pcibk_xenbus_probe()
713 xen_pcibk_be_watch(&pdev->be_watch, NULL, NULL); in xen_pcibk_xenbus_probe()
721 struct xen_pcibk_device *pdev = dev_get_drvdata(&dev->dev); in xen_pcibk_xenbus_remove() local
723 if (pdev != NULL) in xen_pcibk_xenbus_remove()
724 free_pdev(pdev); in xen_pcibk_xenbus_remove()