aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/xen/xen-pciback/pci_stub.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/xen/xen-pciback/pci_stub.c')
-rw-r--r--drivers/xen/xen-pciback/pci_stub.c41
1 files changed, 38 insertions, 3 deletions
diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c
index 19834d1c7c36..097e536e8672 100644
--- a/drivers/xen/xen-pciback/pci_stub.c
+++ b/drivers/xen/xen-pciback/pci_stub.c
@@ -85,19 +85,34 @@ static struct pcistub_device *pcistub_device_alloc(struct pci_dev *dev)
85static void pcistub_device_release(struct kref *kref) 85static void pcistub_device_release(struct kref *kref)
86{ 86{
87 struct pcistub_device *psdev; 87 struct pcistub_device *psdev;
88 struct xen_pcibk_dev_data *dev_data;
88 89
89 psdev = container_of(kref, struct pcistub_device, kref); 90 psdev = container_of(kref, struct pcistub_device, kref);
91 dev_data = pci_get_drvdata(psdev->dev);
90 92
91 dev_dbg(&psdev->dev->dev, "pcistub_device_release\n"); 93 dev_dbg(&psdev->dev->dev, "pcistub_device_release\n");
92 94
93 xen_unregister_device_domain_owner(psdev->dev); 95 xen_unregister_device_domain_owner(psdev->dev);
94 96
95 /* Clean-up the device */ 97 /* Call the reset function which does not take lock as this
98 * is called from "unbind" which takes a device_lock mutex.
99 */
100 __pci_reset_function_locked(psdev->dev);
101 if (pci_load_and_free_saved_state(psdev->dev,
102 &dev_data->pci_saved_state)) {
103 dev_dbg(&psdev->dev->dev, "Could not reload PCI state\n");
104 } else
105 pci_restore_state(psdev->dev);
106
107 /* Disable the device */
96 xen_pcibk_reset_device(psdev->dev); 108 xen_pcibk_reset_device(psdev->dev);
109
110 kfree(dev_data);
111 pci_set_drvdata(psdev->dev, NULL);
112
113 /* Clean-up the device */
97 xen_pcibk_config_free_dyn_fields(psdev->dev); 114 xen_pcibk_config_free_dyn_fields(psdev->dev);
98 xen_pcibk_config_free_dev(psdev->dev); 115 xen_pcibk_config_free_dev(psdev->dev);
99 kfree(pci_get_drvdata(psdev->dev));
100 pci_set_drvdata(psdev->dev, NULL);
101 116
102 psdev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED; 117 psdev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
103 pci_dev_put(psdev->dev); 118 pci_dev_put(psdev->dev);
@@ -231,7 +246,17 @@ void pcistub_put_pci_dev(struct pci_dev *dev)
231 /* Cleanup our device 246 /* Cleanup our device
232 * (so it's ready for the next domain) 247 * (so it's ready for the next domain)
233 */ 248 */
249
250 /* This is OK - we are running from workqueue context
251 * and want to inhibit the user from fiddling with 'reset'
252 */
253 pci_reset_function(dev);
254 pci_restore_state(psdev->dev);
255
256 /* This disables the device. */
234 xen_pcibk_reset_device(found_psdev->dev); 257 xen_pcibk_reset_device(found_psdev->dev);
258
259 /* And cleanup up our emulated fields. */
235 xen_pcibk_config_free_dyn_fields(found_psdev->dev); 260 xen_pcibk_config_free_dyn_fields(found_psdev->dev);
236 xen_pcibk_config_reset_dev(found_psdev->dev); 261 xen_pcibk_config_reset_dev(found_psdev->dev);
237 262
@@ -328,6 +353,16 @@ static int __devinit pcistub_init_device(struct pci_dev *dev)
328 if (err) 353 if (err)
329 goto config_release; 354 goto config_release;
330 355
356 dev_dbg(&dev->dev, "reseting (FLR, D3, etc) the device\n");
357 __pci_reset_function_locked(dev);
358
359 /* We need the device active to save the state. */
360 dev_dbg(&dev->dev, "save state of device\n");
361 pci_save_state(dev);
362 dev_data->pci_saved_state = pci_store_saved_state(dev);
363 if (!dev_data->pci_saved_state)
364 dev_err(&dev->dev, "Could not store PCI conf saved state!\n");
365
331 /* Now disable the device (this also ensures some private device 366 /* Now disable the device (this also ensures some private device
332 * data is setup before we export) 367 * data is setup before we export)
333 */ 368 */