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->otherend_id, 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
149 mutex_lock(&pdev->dev_lock); in xen_pcibk_attach()
151 if (xenbus_read_driver_state(pdev->xdev->nodename) != in xen_pcibk_attach()
156 if (xenbus_read_driver_state(pdev->xdev->otherend) != in xen_pcibk_attach()
160 dev_dbg(&pdev->xdev->dev, "Reading frontend config\n"); in xen_pcibk_attach()
162 err = xenbus_gather(XBT_NIL, pdev->xdev->otherend, in xen_pcibk_attach()
168 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_attach()
174 xenbus_dev_fatal(pdev->xdev, -EFAULT, in xen_pcibk_attach()
182 err = xen_pcibk_do_attach(pdev, gnt_ref, remote_evtchn); in xen_pcibk_attach()
186 dev_dbg(&pdev->xdev->dev, "Connecting...\n"); in xen_pcibk_attach()
188 err = xenbus_switch_state(pdev->xdev, XenbusStateConnected); in xen_pcibk_attach()
190 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_attach()
193 dev_dbg(&pdev->xdev->dev, "Connected? %d\n", err); in xen_pcibk_attach()
195 mutex_unlock(&pdev->dev_lock); in xen_pcibk_attach()
202 static int xen_pcibk_publish_pci_dev(struct xen_pcibk_device *pdev, in xen_pcibk_publish_pci_dev() argument
217 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str, in xen_pcibk_publish_pci_dev()
225 static int xen_pcibk_export_device(struct xen_pcibk_device *pdev, in xen_pcibk_export_device() argument
232 dev_dbg(&pdev->xdev->dev, "exporting dom %x bus %x slot %x func %x\n", in xen_pcibk_export_device()
235 dev = pcistub_get_pci_dev_by_slot(pdev, domain, bus, slot, func); in xen_pcibk_export_device()
238 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_export_device()
246 err = xen_pcibk_add_pci_dev(pdev, dev, devid, in xen_pcibk_export_device()
251 dev_info(&dev->dev, "registering for %d\n", pdev->xdev->otherend_id); in xen_pcibk_export_device()
253 pdev->xdev->otherend_id) != 0) { in xen_pcibk_export_device()
257 xen_register_device_domain_owner(dev, pdev->xdev->otherend_id); in xen_pcibk_export_device()
272 static int xen_pcibk_remove_device(struct xen_pcibk_device *pdev, in xen_pcibk_remove_device() argument
278 dev_dbg(&pdev->xdev->dev, "removing dom %x bus %x slot %x func %x\n", in xen_pcibk_remove_device()
281 dev = xen_pcibk_get_pci_dev(pdev, domain, bus, PCI_DEVFN(slot, func)); in xen_pcibk_remove_device()
284 dev_dbg(&pdev->xdev->dev, "Couldn't locate PCI device " in xen_pcibk_remove_device()
290 dev_dbg(&dev->dev, "unregistering for %d\n", pdev->xdev->otherend_id); in xen_pcibk_remove_device()
295 xen_pcibk_release_pci_dev(pdev, dev, true /* use the lock. */); in xen_pcibk_remove_device()
301 static int xen_pcibk_publish_pci_root(struct xen_pcibk_device *pdev, in xen_pcibk_publish_pci_root() argument
308 dev_dbg(&pdev->xdev->dev, "Publishing pci roots\n"); in xen_pcibk_publish_pci_root()
310 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, in xen_pcibk_publish_pci_root()
325 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, in xen_pcibk_publish_pci_root()
346 dev_dbg(&pdev->xdev->dev, "writing root %d at %04x:%02x\n", in xen_pcibk_publish_pci_root()
349 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, str, in xen_pcibk_publish_pci_root()
354 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, in xen_pcibk_publish_pci_root()
361 static int xen_pcibk_reconfigure(struct xen_pcibk_device *pdev, in xen_pcibk_reconfigure() argument
373 dev_dbg(&pdev->xdev->dev, "Reconfiguring device ...\n"); in xen_pcibk_reconfigure()
375 mutex_lock(&pdev->dev_lock); in xen_pcibk_reconfigure()
376 if (xenbus_read_driver_state(pdev->xdev->nodename) != state) in xen_pcibk_reconfigure()
379 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, "num_devs", "%d", in xen_pcibk_reconfigure()
384 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
393 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
398 substate = xenbus_read_unsigned(pdev->xdev->nodename, state_str, in xen_pcibk_reconfigure()
403 dev_dbg(&pdev->xdev->dev, "Attaching dev-%d ...\n", i); in xen_pcibk_reconfigure()
408 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
413 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, in xen_pcibk_reconfigure()
417 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
424 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
430 err = xen_pcibk_export_device(pdev, domain, bus, slot, in xen_pcibk_reconfigure()
436 err = xen_pcibk_publish_pci_roots(pdev, in xen_pcibk_reconfigure()
439 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
445 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, in xen_pcibk_reconfigure()
449 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
457 dev_dbg(&pdev->xdev->dev, "Detaching dev-%d ...\n", i); in xen_pcibk_reconfigure()
462 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
467 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, in xen_pcibk_reconfigure()
471 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
478 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
484 err = xen_pcibk_remove_device(pdev, domain, bus, slot, in xen_pcibk_reconfigure()
505 err = xenbus_switch_state(pdev->xdev, XenbusStateReconfigured); in xen_pcibk_reconfigure()
507 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_reconfigure()
513 mutex_unlock(&pdev->dev_lock); in xen_pcibk_reconfigure()
520 struct xen_pcibk_device *pdev = dev_get_drvdata(&xdev->dev); in xen_pcibk_frontend_changed() local
526 xen_pcibk_attach(pdev); in xen_pcibk_frontend_changed()
530 xen_pcibk_reconfigure(pdev, XenbusStateReconfiguring); in xen_pcibk_frontend_changed()
541 xen_pcibk_disconnect(pdev); in xen_pcibk_frontend_changed()
546 xen_pcibk_disconnect(pdev); in xen_pcibk_frontend_changed()
561 static int xen_pcibk_setup_backend(struct xen_pcibk_device *pdev) in xen_pcibk_setup_backend() argument
570 mutex_lock(&pdev->dev_lock); in xen_pcibk_setup_backend()
574 if (xenbus_read_driver_state(pdev->xdev->nodename) != in xen_pcibk_setup_backend()
578 dev_dbg(&pdev->xdev->dev, "getting be setup\n"); in xen_pcibk_setup_backend()
580 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, "num_devs", "%d", in xen_pcibk_setup_backend()
585 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
594 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
600 err = xenbus_scanf(XBT_NIL, pdev->xdev->nodename, dev_str, in xen_pcibk_setup_backend()
603 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
609 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
615 err = xen_pcibk_export_device(pdev, domain, bus, slot, func, i); in xen_pcibk_setup_backend()
623 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
628 err = xenbus_printf(XBT_NIL, pdev->xdev->nodename, state_str, in xen_pcibk_setup_backend()
631 xenbus_dev_fatal(pdev->xdev, err, "Error switching " in xen_pcibk_setup_backend()
637 err = xen_pcibk_publish_pci_roots(pdev, xen_pcibk_publish_pci_root); in xen_pcibk_setup_backend()
639 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
645 err = xenbus_switch_state(pdev->xdev, XenbusStateInitialised); in xen_pcibk_setup_backend()
647 xenbus_dev_fatal(pdev->xdev, err, in xen_pcibk_setup_backend()
651 mutex_unlock(&pdev->dev_lock); in xen_pcibk_setup_backend()
654 xen_pcibk_attach(pdev); in xen_pcibk_setup_backend()
661 struct xen_pcibk_device *pdev = in xen_pcibk_be_watch() local
664 switch (xenbus_read_driver_state(pdev->xdev->nodename)) { in xen_pcibk_be_watch()
666 xen_pcibk_setup_backend(pdev); in xen_pcibk_be_watch()
675 xen_pcibk_reconfigure(pdev, XenbusStateInitialised); in xen_pcibk_be_watch()
687 struct xen_pcibk_device *pdev = alloc_pdev(dev); in xen_pcibk_xenbus_probe() local
689 if (pdev == NULL) { in xen_pcibk_xenbus_probe()
702 err = xenbus_watch_path(dev, dev->nodename, &pdev->be_watch, in xen_pcibk_xenbus_probe()
707 pdev->be_watching = 1; in xen_pcibk_xenbus_probe()
712 xen_pcibk_be_watch(&pdev->be_watch, NULL, 0); in xen_pcibk_xenbus_probe()
720 struct xen_pcibk_device *pdev = dev_get_drvdata(&dev->dev); in xen_pcibk_xenbus_remove() local
722 if (pdev != NULL) in xen_pcibk_xenbus_remove()
723 free_pdev(pdev); in xen_pcibk_xenbus_remove()