aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/xen
diff options
context:
space:
mode:
authorKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2012-01-04 14:30:58 -0500
committerKonrad Rzeszutek Wilk <konrad.wilk@oracle.com>2012-01-12 12:00:19 -0500
commitcd9db80e5257682a7f7ab245a2459648b3c8d268 (patch)
tree6162d1b26e3d224aa23173bba1042346d1094aac /drivers/xen
parenta96d627abaac899e8bfaf18fd0578b228c9c752f (diff)
xen/pciback: Support pci_reset_function, aka FLR or D3 support.
We use the __pci_reset_function_locked to perform the action. Also on attaching ("bind") and detaching ("unbind") we save and restore the configuration states. When the device is disconnected from a guest we use the "pci_reset_function" to also reset the device before being passed to another guest. Signed-off-by: Konrad Rzeszutek Wilk <konrad.wilk@oracle.com>
Diffstat (limited to 'drivers/xen')
-rw-r--r--drivers/xen/xen-pciback/pci_stub.c41
-rw-r--r--drivers/xen/xen-pciback/pciback.h1
2 files changed, 39 insertions, 3 deletions
diff --git a/drivers/xen/xen-pciback/pci_stub.c b/drivers/xen/xen-pciback/pci_stub.c
index 7944a17f5cb..6f63b9d954f 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 */
diff --git a/drivers/xen/xen-pciback/pciback.h b/drivers/xen/xen-pciback/pciback.h
index e9b4011c5f9..a7def010eba 100644
--- a/drivers/xen/xen-pciback/pciback.h
+++ b/drivers/xen/xen-pciback/pciback.h
@@ -41,6 +41,7 @@ struct xen_pcibk_device {
41 41
42struct xen_pcibk_dev_data { 42struct xen_pcibk_dev_data {
43 struct list_head config_fields; 43 struct list_head config_fields;
44 struct pci_saved_state *pci_saved_state;
44 unsigned int permissive:1; 45 unsigned int permissive:1;
45 unsigned int warned_on_write:1; 46 unsigned int warned_on_write:1;
46 unsigned int enable_intx:1; 47 unsigned int enable_intx:1;