Lines Matching refs:pdev

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