Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1 | /* |
| 2 | * PCI Stub Driver - Grabs devices in backend to be exported later |
| 3 | * |
| 4 | * Ryan Wilson <hap9@epoch.ncsc.mil> |
| 5 | * Chris Bookholt <hap10@epoch.ncsc.mil> |
| 6 | */ |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/init.h> |
| 9 | #include <linux/rwsem.h> |
| 10 | #include <linux/list.h> |
| 11 | #include <linux/spinlock.h> |
| 12 | #include <linux/kref.h> |
| 13 | #include <linux/pci.h> |
| 14 | #include <linux/wait.h> |
| 15 | #include <linux/sched.h> |
Konrad Rzeszutek Wilk | 8bfd4e0 | 2011-07-19 20:09:43 -0400 | [diff] [blame] | 16 | #include <linux/atomic.h> |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 17 | #include <xen/events.h> |
| 18 | #include <asm/xen/pci.h> |
| 19 | #include <asm/xen/hypervisor.h> |
| 20 | #include "pciback.h" |
| 21 | #include "conf_space.h" |
| 22 | #include "conf_space_quirks.h" |
| 23 | |
| 24 | static char *pci_devs_to_hide; |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 25 | wait_queue_head_t xen_pcibk_aer_wait_queue; |
| 26 | /*Add sem for sync AER handling and xen_pcibk remove/reconfigue ops, |
| 27 | * We want to avoid in middle of AER ops, xen_pcibk devices is being removed |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 28 | */ |
| 29 | static DECLARE_RWSEM(pcistub_sem); |
| 30 | module_param_named(hide, pci_devs_to_hide, charp, 0444); |
| 31 | |
| 32 | struct pcistub_device_id { |
| 33 | struct list_head slot_list; |
| 34 | int domain; |
| 35 | unsigned char bus; |
| 36 | unsigned int devfn; |
| 37 | }; |
| 38 | static LIST_HEAD(pcistub_device_ids); |
| 39 | static DEFINE_SPINLOCK(device_ids_lock); |
| 40 | |
| 41 | struct pcistub_device { |
| 42 | struct kref kref; |
| 43 | struct list_head dev_list; |
| 44 | spinlock_t lock; |
| 45 | |
| 46 | struct pci_dev *dev; |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 47 | struct xen_pcibk_device *pdev;/* non-NULL if struct pci_dev is in use */ |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 48 | }; |
| 49 | |
| 50 | /* Access to pcistub_devices & seized_devices lists and the initialize_devices |
| 51 | * flag must be locked with pcistub_devices_lock |
| 52 | */ |
| 53 | static DEFINE_SPINLOCK(pcistub_devices_lock); |
| 54 | static LIST_HEAD(pcistub_devices); |
| 55 | |
| 56 | /* wait for device_initcall before initializing our devices |
| 57 | * (see pcistub_init_devices_late) |
| 58 | */ |
| 59 | static int initialize_devices; |
| 60 | static LIST_HEAD(seized_devices); |
| 61 | |
| 62 | static struct pcistub_device *pcistub_device_alloc(struct pci_dev *dev) |
| 63 | { |
| 64 | struct pcistub_device *psdev; |
| 65 | |
| 66 | dev_dbg(&dev->dev, "pcistub_device_alloc\n"); |
| 67 | |
| 68 | psdev = kzalloc(sizeof(*psdev), GFP_ATOMIC); |
| 69 | if (!psdev) |
| 70 | return NULL; |
| 71 | |
| 72 | psdev->dev = pci_dev_get(dev); |
| 73 | if (!psdev->dev) { |
| 74 | kfree(psdev); |
| 75 | return NULL; |
| 76 | } |
| 77 | |
| 78 | kref_init(&psdev->kref); |
| 79 | spin_lock_init(&psdev->lock); |
| 80 | |
| 81 | return psdev; |
| 82 | } |
| 83 | |
| 84 | /* Don't call this directly as it's called by pcistub_device_put */ |
| 85 | static void pcistub_device_release(struct kref *kref) |
| 86 | { |
| 87 | struct pcistub_device *psdev; |
Konrad Rzeszutek Wilk | cd9db80 | 2012-01-04 14:30:58 -0500 | [diff] [blame] | 88 | struct xen_pcibk_dev_data *dev_data; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 89 | |
| 90 | psdev = container_of(kref, struct pcistub_device, kref); |
Konrad Rzeszutek Wilk | cd9db80 | 2012-01-04 14:30:58 -0500 | [diff] [blame] | 91 | dev_data = pci_get_drvdata(psdev->dev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 92 | |
| 93 | dev_dbg(&psdev->dev->dev, "pcistub_device_release\n"); |
| 94 | |
Konrad Rzeszutek Wilk | 6221a9b | 2009-12-09 17:43:15 -0500 | [diff] [blame] | 95 | xen_unregister_device_domain_owner(psdev->dev); |
| 96 | |
Konrad Rzeszutek Wilk | cd9db80 | 2012-01-04 14:30:58 -0500 | [diff] [blame] | 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 */ |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 108 | xen_pcibk_reset_device(psdev->dev); |
Konrad Rzeszutek Wilk | cd9db80 | 2012-01-04 14:30:58 -0500 | [diff] [blame] | 109 | |
| 110 | kfree(dev_data); |
| 111 | pci_set_drvdata(psdev->dev, NULL); |
| 112 | |
| 113 | /* Clean-up the device */ |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 114 | xen_pcibk_config_free_dyn_fields(psdev->dev); |
| 115 | xen_pcibk_config_free_dev(psdev->dev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 116 | |
Konrad Rzeszutek Wilk | 97309d3 | 2012-01-04 14:10:32 -0500 | [diff] [blame] | 117 | psdev->dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 118 | pci_dev_put(psdev->dev); |
| 119 | |
| 120 | kfree(psdev); |
| 121 | } |
| 122 | |
| 123 | static inline void pcistub_device_get(struct pcistub_device *psdev) |
| 124 | { |
| 125 | kref_get(&psdev->kref); |
| 126 | } |
| 127 | |
| 128 | static inline void pcistub_device_put(struct pcistub_device *psdev) |
| 129 | { |
| 130 | kref_put(&psdev->kref, pcistub_device_release); |
| 131 | } |
| 132 | |
| 133 | static struct pcistub_device *pcistub_device_find(int domain, int bus, |
| 134 | int slot, int func) |
| 135 | { |
| 136 | struct pcistub_device *psdev = NULL; |
| 137 | unsigned long flags; |
| 138 | |
| 139 | spin_lock_irqsave(&pcistub_devices_lock, flags); |
| 140 | |
| 141 | list_for_each_entry(psdev, &pcistub_devices, dev_list) { |
| 142 | if (psdev->dev != NULL |
| 143 | && domain == pci_domain_nr(psdev->dev->bus) |
| 144 | && bus == psdev->dev->bus->number |
| 145 | && PCI_DEVFN(slot, func) == psdev->dev->devfn) { |
| 146 | pcistub_device_get(psdev); |
| 147 | goto out; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /* didn't find it */ |
| 152 | psdev = NULL; |
| 153 | |
| 154 | out: |
| 155 | spin_unlock_irqrestore(&pcistub_devices_lock, flags); |
| 156 | return psdev; |
| 157 | } |
| 158 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 159 | static struct pci_dev *pcistub_device_get_pci_dev(struct xen_pcibk_device *pdev, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 160 | struct pcistub_device *psdev) |
| 161 | { |
| 162 | struct pci_dev *pci_dev = NULL; |
| 163 | unsigned long flags; |
| 164 | |
| 165 | pcistub_device_get(psdev); |
| 166 | |
| 167 | spin_lock_irqsave(&psdev->lock, flags); |
| 168 | if (!psdev->pdev) { |
| 169 | psdev->pdev = pdev; |
| 170 | pci_dev = psdev->dev; |
| 171 | } |
| 172 | spin_unlock_irqrestore(&psdev->lock, flags); |
| 173 | |
| 174 | if (!pci_dev) |
| 175 | pcistub_device_put(psdev); |
| 176 | |
| 177 | return pci_dev; |
| 178 | } |
| 179 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 180 | struct pci_dev *pcistub_get_pci_dev_by_slot(struct xen_pcibk_device *pdev, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 181 | int domain, int bus, |
| 182 | int slot, int func) |
| 183 | { |
| 184 | struct pcistub_device *psdev; |
| 185 | struct pci_dev *found_dev = NULL; |
| 186 | unsigned long flags; |
| 187 | |
| 188 | spin_lock_irqsave(&pcistub_devices_lock, flags); |
| 189 | |
| 190 | list_for_each_entry(psdev, &pcistub_devices, dev_list) { |
| 191 | if (psdev->dev != NULL |
| 192 | && domain == pci_domain_nr(psdev->dev->bus) |
| 193 | && bus == psdev->dev->bus->number |
| 194 | && PCI_DEVFN(slot, func) == psdev->dev->devfn) { |
| 195 | found_dev = pcistub_device_get_pci_dev(pdev, psdev); |
| 196 | break; |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | spin_unlock_irqrestore(&pcistub_devices_lock, flags); |
| 201 | return found_dev; |
| 202 | } |
| 203 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 204 | struct pci_dev *pcistub_get_pci_dev(struct xen_pcibk_device *pdev, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 205 | struct pci_dev *dev) |
| 206 | { |
| 207 | struct pcistub_device *psdev; |
| 208 | struct pci_dev *found_dev = NULL; |
| 209 | unsigned long flags; |
| 210 | |
| 211 | spin_lock_irqsave(&pcistub_devices_lock, flags); |
| 212 | |
| 213 | list_for_each_entry(psdev, &pcistub_devices, dev_list) { |
| 214 | if (psdev->dev == dev) { |
| 215 | found_dev = pcistub_device_get_pci_dev(pdev, psdev); |
| 216 | break; |
| 217 | } |
| 218 | } |
| 219 | |
| 220 | spin_unlock_irqrestore(&pcistub_devices_lock, flags); |
| 221 | return found_dev; |
| 222 | } |
| 223 | |
| 224 | void pcistub_put_pci_dev(struct pci_dev *dev) |
| 225 | { |
| 226 | struct pcistub_device *psdev, *found_psdev = NULL; |
| 227 | unsigned long flags; |
| 228 | |
| 229 | spin_lock_irqsave(&pcistub_devices_lock, flags); |
| 230 | |
| 231 | list_for_each_entry(psdev, &pcistub_devices, dev_list) { |
| 232 | if (psdev->dev == dev) { |
| 233 | found_psdev = psdev; |
| 234 | break; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | spin_unlock_irqrestore(&pcistub_devices_lock, flags); |
Konrad Rzeszutek Wilk | 4645bf3 | 2011-09-29 13:12:43 -0400 | [diff] [blame] | 239 | if (WARN_ON(!found_psdev)) |
| 240 | return; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 241 | |
| 242 | /*hold this lock for avoiding breaking link between |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 243 | * pcistub and xen_pcibk when AER is in processing |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 244 | */ |
| 245 | down_write(&pcistub_sem); |
| 246 | /* Cleanup our device |
| 247 | * (so it's ready for the next domain) |
| 248 | */ |
Konrad Rzeszutek Wilk | cd9db80 | 2012-01-04 14:30:58 -0500 | [diff] [blame] | 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. */ |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 257 | xen_pcibk_reset_device(found_psdev->dev); |
Konrad Rzeszutek Wilk | cd9db80 | 2012-01-04 14:30:58 -0500 | [diff] [blame] | 258 | |
| 259 | /* And cleanup up our emulated fields. */ |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 260 | xen_pcibk_config_free_dyn_fields(found_psdev->dev); |
| 261 | xen_pcibk_config_reset_dev(found_psdev->dev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 262 | |
Konrad Rzeszutek Wilk | 3167355 | 2012-01-04 15:11:02 -0500 | [diff] [blame] | 263 | xen_unregister_device_domain_owner(found_psdev->dev); |
| 264 | |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 265 | spin_lock_irqsave(&found_psdev->lock, flags); |
| 266 | found_psdev->pdev = NULL; |
| 267 | spin_unlock_irqrestore(&found_psdev->lock, flags); |
| 268 | |
| 269 | pcistub_device_put(found_psdev); |
| 270 | up_write(&pcistub_sem); |
| 271 | } |
| 272 | |
| 273 | static int __devinit pcistub_match_one(struct pci_dev *dev, |
| 274 | struct pcistub_device_id *pdev_id) |
| 275 | { |
| 276 | /* Match the specified device by domain, bus, slot, func and also if |
| 277 | * any of the device's parent bridges match. |
| 278 | */ |
| 279 | for (; dev != NULL; dev = dev->bus->self) { |
| 280 | if (pci_domain_nr(dev->bus) == pdev_id->domain |
| 281 | && dev->bus->number == pdev_id->bus |
| 282 | && dev->devfn == pdev_id->devfn) |
| 283 | return 1; |
| 284 | |
| 285 | /* Sometimes topmost bridge links to itself. */ |
| 286 | if (dev == dev->bus->self) |
| 287 | break; |
| 288 | } |
| 289 | |
| 290 | return 0; |
| 291 | } |
| 292 | |
| 293 | static int __devinit pcistub_match(struct pci_dev *dev) |
| 294 | { |
| 295 | struct pcistub_device_id *pdev_id; |
| 296 | unsigned long flags; |
| 297 | int found = 0; |
| 298 | |
| 299 | spin_lock_irqsave(&device_ids_lock, flags); |
| 300 | list_for_each_entry(pdev_id, &pcistub_device_ids, slot_list) { |
| 301 | if (pcistub_match_one(dev, pdev_id)) { |
| 302 | found = 1; |
| 303 | break; |
| 304 | } |
| 305 | } |
| 306 | spin_unlock_irqrestore(&device_ids_lock, flags); |
| 307 | |
| 308 | return found; |
| 309 | } |
| 310 | |
| 311 | static int __devinit pcistub_init_device(struct pci_dev *dev) |
| 312 | { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 313 | struct xen_pcibk_dev_data *dev_data; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 314 | int err = 0; |
| 315 | |
| 316 | dev_dbg(&dev->dev, "initializing...\n"); |
| 317 | |
| 318 | /* The PCI backend is not intended to be a module (or to work with |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 319 | * removable PCI devices (yet). If it were, xen_pcibk_config_free() |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 320 | * would need to be called somewhere to free the memory allocated |
| 321 | * here and then to call kfree(pci_get_drvdata(psdev->dev)). |
| 322 | */ |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 323 | dev_data = kzalloc(sizeof(*dev_data) + strlen(DRV_NAME "[]") |
| 324 | + strlen(pci_name(dev)) + 1, GFP_ATOMIC); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 325 | if (!dev_data) { |
| 326 | err = -ENOMEM; |
| 327 | goto out; |
| 328 | } |
| 329 | pci_set_drvdata(dev, dev_data); |
| 330 | |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 331 | /* |
| 332 | * Setup name for fake IRQ handler. It will only be enabled |
| 333 | * once the device is turned on by the guest. |
| 334 | */ |
| 335 | sprintf(dev_data->irq_name, DRV_NAME "[%s]", pci_name(dev)); |
| 336 | |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 337 | dev_dbg(&dev->dev, "initializing config\n"); |
| 338 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 339 | init_waitqueue_head(&xen_pcibk_aer_wait_queue); |
| 340 | err = xen_pcibk_config_init_dev(dev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 341 | if (err) |
| 342 | goto out; |
| 343 | |
| 344 | /* HACK: Force device (& ACPI) to determine what IRQ it's on - we |
| 345 | * must do this here because pcibios_enable_device may specify |
| 346 | * the pci device's true irq (and possibly its other resources) |
| 347 | * if they differ from what's in the configuration space. |
| 348 | * This makes the assumption that the device's resources won't |
| 349 | * change after this point (otherwise this code may break!) |
| 350 | */ |
| 351 | dev_dbg(&dev->dev, "enabling device\n"); |
| 352 | err = pci_enable_device(dev); |
| 353 | if (err) |
| 354 | goto config_release; |
| 355 | |
Konrad Rzeszutek Wilk | cd9db80 | 2012-01-04 14:30:58 -0500 | [diff] [blame] | 356 | /* We need the device active to save the state. */ |
| 357 | dev_dbg(&dev->dev, "save state of device\n"); |
| 358 | pci_save_state(dev); |
| 359 | dev_data->pci_saved_state = pci_store_saved_state(dev); |
| 360 | if (!dev_data->pci_saved_state) |
| 361 | dev_err(&dev->dev, "Could not store PCI conf saved state!\n"); |
Konrad Rzeszutek Wilk | 80ba77d | 2012-09-05 16:35:20 -0400 | [diff] [blame] | 362 | else { |
| 363 | dev_dbg(&dev->dev, "reseting (FLR, D3, etc) the device\n"); |
| 364 | __pci_reset_function_locked(dev); |
| 365 | } |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 366 | /* Now disable the device (this also ensures some private device |
| 367 | * data is setup before we export) |
| 368 | */ |
| 369 | dev_dbg(&dev->dev, "reset device\n"); |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 370 | xen_pcibk_reset_device(dev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 371 | |
Konrad Rzeszutek Wilk | 97309d3 | 2012-01-04 14:10:32 -0500 | [diff] [blame] | 372 | dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 373 | return 0; |
| 374 | |
| 375 | config_release: |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 376 | xen_pcibk_config_free_dev(dev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 377 | |
| 378 | out: |
| 379 | pci_set_drvdata(dev, NULL); |
| 380 | kfree(dev_data); |
| 381 | return err; |
| 382 | } |
| 383 | |
| 384 | /* |
| 385 | * Because some initialization still happens on |
| 386 | * devices during fs_initcall, we need to defer |
| 387 | * full initialization of our devices until |
| 388 | * device_initcall. |
| 389 | */ |
| 390 | static int __init pcistub_init_devices_late(void) |
| 391 | { |
| 392 | struct pcistub_device *psdev; |
| 393 | unsigned long flags; |
| 394 | int err = 0; |
| 395 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 396 | pr_debug(DRV_NAME ": pcistub_init_devices_late\n"); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 397 | |
| 398 | spin_lock_irqsave(&pcistub_devices_lock, flags); |
| 399 | |
| 400 | while (!list_empty(&seized_devices)) { |
| 401 | psdev = container_of(seized_devices.next, |
| 402 | struct pcistub_device, dev_list); |
| 403 | list_del(&psdev->dev_list); |
| 404 | |
| 405 | spin_unlock_irqrestore(&pcistub_devices_lock, flags); |
| 406 | |
| 407 | err = pcistub_init_device(psdev->dev); |
| 408 | if (err) { |
| 409 | dev_err(&psdev->dev->dev, |
| 410 | "error %d initializing device\n", err); |
| 411 | kfree(psdev); |
| 412 | psdev = NULL; |
| 413 | } |
| 414 | |
| 415 | spin_lock_irqsave(&pcistub_devices_lock, flags); |
| 416 | |
| 417 | if (psdev) |
| 418 | list_add_tail(&psdev->dev_list, &pcistub_devices); |
| 419 | } |
| 420 | |
| 421 | initialize_devices = 1; |
| 422 | |
| 423 | spin_unlock_irqrestore(&pcistub_devices_lock, flags); |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | static int __devinit pcistub_seize(struct pci_dev *dev) |
| 429 | { |
| 430 | struct pcistub_device *psdev; |
| 431 | unsigned long flags; |
| 432 | int err = 0; |
| 433 | |
| 434 | psdev = pcistub_device_alloc(dev); |
| 435 | if (!psdev) |
| 436 | return -ENOMEM; |
| 437 | |
| 438 | spin_lock_irqsave(&pcistub_devices_lock, flags); |
| 439 | |
| 440 | if (initialize_devices) { |
| 441 | spin_unlock_irqrestore(&pcistub_devices_lock, flags); |
| 442 | |
| 443 | /* don't want irqs disabled when calling pcistub_init_device */ |
| 444 | err = pcistub_init_device(psdev->dev); |
| 445 | |
| 446 | spin_lock_irqsave(&pcistub_devices_lock, flags); |
| 447 | |
| 448 | if (!err) |
| 449 | list_add(&psdev->dev_list, &pcistub_devices); |
| 450 | } else { |
| 451 | dev_dbg(&dev->dev, "deferring initialization\n"); |
| 452 | list_add(&psdev->dev_list, &seized_devices); |
| 453 | } |
| 454 | |
| 455 | spin_unlock_irqrestore(&pcistub_devices_lock, flags); |
| 456 | |
| 457 | if (err) |
| 458 | pcistub_device_put(psdev); |
| 459 | |
| 460 | return err; |
| 461 | } |
| 462 | |
| 463 | static int __devinit pcistub_probe(struct pci_dev *dev, |
| 464 | const struct pci_device_id *id) |
| 465 | { |
| 466 | int err = 0; |
| 467 | |
| 468 | dev_dbg(&dev->dev, "probing...\n"); |
| 469 | |
| 470 | if (pcistub_match(dev)) { |
| 471 | |
| 472 | if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL |
| 473 | && dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) { |
| 474 | dev_err(&dev->dev, "can't export pci devices that " |
| 475 | "don't have a normal (0) or bridge (1) " |
| 476 | "header type!\n"); |
| 477 | err = -ENODEV; |
| 478 | goto out; |
| 479 | } |
| 480 | |
| 481 | dev_info(&dev->dev, "seizing device\n"); |
| 482 | err = pcistub_seize(dev); |
| 483 | } else |
| 484 | /* Didn't find the device */ |
| 485 | err = -ENODEV; |
| 486 | |
| 487 | out: |
| 488 | return err; |
| 489 | } |
| 490 | |
| 491 | static void pcistub_remove(struct pci_dev *dev) |
| 492 | { |
| 493 | struct pcistub_device *psdev, *found_psdev = NULL; |
| 494 | unsigned long flags; |
| 495 | |
| 496 | dev_dbg(&dev->dev, "removing\n"); |
| 497 | |
| 498 | spin_lock_irqsave(&pcistub_devices_lock, flags); |
| 499 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 500 | xen_pcibk_config_quirk_release(dev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 501 | |
| 502 | list_for_each_entry(psdev, &pcistub_devices, dev_list) { |
| 503 | if (psdev->dev == dev) { |
| 504 | found_psdev = psdev; |
| 505 | break; |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | spin_unlock_irqrestore(&pcistub_devices_lock, flags); |
| 510 | |
| 511 | if (found_psdev) { |
| 512 | dev_dbg(&dev->dev, "found device to remove - in use? %p\n", |
| 513 | found_psdev->pdev); |
| 514 | |
| 515 | if (found_psdev->pdev) { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 516 | printk(KERN_WARNING DRV_NAME ": ****** removing device " |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 517 | "%s while still in-use! ******\n", |
| 518 | pci_name(found_psdev->dev)); |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 519 | printk(KERN_WARNING DRV_NAME ": ****** driver domain may" |
| 520 | " still access this device's i/o resources!\n"); |
| 521 | printk(KERN_WARNING DRV_NAME ": ****** shutdown driver " |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 522 | "domain before binding device\n"); |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 523 | printk(KERN_WARNING DRV_NAME ": ****** to other drivers " |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 524 | "or domains\n"); |
| 525 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 526 | xen_pcibk_release_pci_dev(found_psdev->pdev, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 527 | found_psdev->dev); |
| 528 | } |
| 529 | |
| 530 | spin_lock_irqsave(&pcistub_devices_lock, flags); |
| 531 | list_del(&found_psdev->dev_list); |
| 532 | spin_unlock_irqrestore(&pcistub_devices_lock, flags); |
| 533 | |
| 534 | /* the final put for releasing from the list */ |
| 535 | pcistub_device_put(found_psdev); |
| 536 | } |
| 537 | } |
| 538 | |
Konrad Rzeszutek Wilk | 8bfd4e0 | 2011-07-19 20:09:43 -0400 | [diff] [blame] | 539 | static DEFINE_PCI_DEVICE_TABLE(pcistub_ids) = { |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 540 | { |
| 541 | .vendor = PCI_ANY_ID, |
| 542 | .device = PCI_ANY_ID, |
| 543 | .subvendor = PCI_ANY_ID, |
| 544 | .subdevice = PCI_ANY_ID, |
| 545 | }, |
| 546 | {0,}, |
| 547 | }; |
| 548 | |
| 549 | #define PCI_NODENAME_MAX 40 |
| 550 | static void kill_domain_by_device(struct pcistub_device *psdev) |
| 551 | { |
| 552 | struct xenbus_transaction xbt; |
| 553 | int err; |
| 554 | char nodename[PCI_NODENAME_MAX]; |
| 555 | |
Konrad Rzeszutek Wilk | 72bf809 | 2011-09-29 13:43:28 -0400 | [diff] [blame] | 556 | BUG_ON(!psdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 557 | snprintf(nodename, PCI_NODENAME_MAX, "/local/domain/0/backend/pci/%d/0", |
| 558 | psdev->pdev->xdev->otherend_id); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 559 | |
| 560 | again: |
| 561 | err = xenbus_transaction_start(&xbt); |
| 562 | if (err) { |
| 563 | dev_err(&psdev->dev->dev, |
| 564 | "error %d when start xenbus transaction\n", err); |
| 565 | return; |
| 566 | } |
| 567 | /*PV AER handlers will set this flag*/ |
| 568 | xenbus_printf(xbt, nodename, "aerState" , "aerfail"); |
| 569 | err = xenbus_transaction_end(xbt, 0); |
| 570 | if (err) { |
| 571 | if (err == -EAGAIN) |
| 572 | goto again; |
| 573 | dev_err(&psdev->dev->dev, |
| 574 | "error %d when end xenbus transaction\n", err); |
| 575 | return; |
| 576 | } |
| 577 | } |
| 578 | |
| 579 | /* For each aer recovery step error_detected, mmio_enabled, etc, front_end and |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 580 | * backend need to have cooperation. In xen_pcibk, those steps will do similar |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 581 | * jobs: send service request and waiting for front_end response. |
| 582 | */ |
| 583 | static pci_ers_result_t common_process(struct pcistub_device *psdev, |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 584 | pci_channel_state_t state, int aer_cmd, |
| 585 | pci_ers_result_t result) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 586 | { |
| 587 | pci_ers_result_t res = result; |
| 588 | struct xen_pcie_aer_op *aer_op; |
| 589 | int ret; |
| 590 | |
| 591 | /*with PV AER drivers*/ |
| 592 | aer_op = &(psdev->pdev->sh_info->aer_op); |
| 593 | aer_op->cmd = aer_cmd ; |
| 594 | /*useful for error_detected callback*/ |
| 595 | aer_op->err = state; |
| 596 | /*pcifront_end BDF*/ |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 597 | ret = xen_pcibk_get_pcifront_dev(psdev->dev, psdev->pdev, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 598 | &aer_op->domain, &aer_op->bus, &aer_op->devfn); |
| 599 | if (!ret) { |
| 600 | dev_err(&psdev->dev->dev, |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 601 | DRV_NAME ": failed to get pcifront device\n"); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 602 | return PCI_ERS_RESULT_NONE; |
| 603 | } |
| 604 | wmb(); |
| 605 | |
| 606 | dev_dbg(&psdev->dev->dev, |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 607 | DRV_NAME ": aer_op %x dom %x bus %x devfn %x\n", |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 608 | aer_cmd, aer_op->domain, aer_op->bus, aer_op->devfn); |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 609 | /*local flag to mark there's aer request, xen_pcibk callback will use |
| 610 | * this flag to judge whether we need to check pci-front give aer |
| 611 | * service ack signal |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 612 | */ |
| 613 | set_bit(_PCIB_op_pending, (unsigned long *)&psdev->pdev->flags); |
| 614 | |
| 615 | /*It is possible that a pcifront conf_read_write ops request invokes |
| 616 | * the callback which cause the spurious execution of wake_up. |
| 617 | * Yet it is harmless and better than a spinlock here |
| 618 | */ |
| 619 | set_bit(_XEN_PCIB_active, |
| 620 | (unsigned long *)&psdev->pdev->sh_info->flags); |
| 621 | wmb(); |
| 622 | notify_remote_via_irq(psdev->pdev->evtchn_irq); |
| 623 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 624 | ret = wait_event_timeout(xen_pcibk_aer_wait_queue, |
| 625 | !(test_bit(_XEN_PCIB_active, (unsigned long *) |
| 626 | &psdev->pdev->sh_info->flags)), 300*HZ); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 627 | |
| 628 | if (!ret) { |
| 629 | if (test_bit(_XEN_PCIB_active, |
| 630 | (unsigned long *)&psdev->pdev->sh_info->flags)) { |
| 631 | dev_err(&psdev->dev->dev, |
| 632 | "pcifront aer process not responding!\n"); |
| 633 | clear_bit(_XEN_PCIB_active, |
| 634 | (unsigned long *)&psdev->pdev->sh_info->flags); |
| 635 | aer_op->err = PCI_ERS_RESULT_NONE; |
| 636 | return res; |
| 637 | } |
| 638 | } |
| 639 | clear_bit(_PCIB_op_pending, (unsigned long *)&psdev->pdev->flags); |
| 640 | |
| 641 | if (test_bit(_XEN_PCIF_active, |
| 642 | (unsigned long *)&psdev->pdev->sh_info->flags)) { |
| 643 | dev_dbg(&psdev->dev->dev, |
Jan Beulich | 402c5e1 | 2011-09-21 16:22:11 -0400 | [diff] [blame] | 644 | "schedule pci_conf service in " DRV_NAME "\n"); |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 645 | xen_pcibk_test_and_schedule_op(psdev->pdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 646 | } |
| 647 | |
| 648 | res = (pci_ers_result_t)aer_op->err; |
| 649 | return res; |
| 650 | } |
| 651 | |
| 652 | /* |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 653 | * xen_pcibk_slot_reset: it will send the slot_reset request to pcifront in case |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 654 | * of the device driver could provide this service, and then wait for pcifront |
| 655 | * ack. |
| 656 | * @dev: pointer to PCI devices |
| 657 | * return value is used by aer_core do_recovery policy |
| 658 | */ |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 659 | static pci_ers_result_t xen_pcibk_slot_reset(struct pci_dev *dev) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 660 | { |
| 661 | struct pcistub_device *psdev; |
| 662 | pci_ers_result_t result; |
| 663 | |
| 664 | result = PCI_ERS_RESULT_RECOVERED; |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 665 | dev_dbg(&dev->dev, "xen_pcibk_slot_reset(bus:%x,devfn:%x)\n", |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 666 | dev->bus->number, dev->devfn); |
| 667 | |
| 668 | down_write(&pcistub_sem); |
| 669 | psdev = pcistub_device_find(pci_domain_nr(dev->bus), |
| 670 | dev->bus->number, |
| 671 | PCI_SLOT(dev->devfn), |
| 672 | PCI_FUNC(dev->devfn)); |
| 673 | |
| 674 | if (!psdev || !psdev->pdev) { |
| 675 | dev_err(&dev->dev, |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 676 | DRV_NAME " device is not found/assigned\n"); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 677 | goto end; |
| 678 | } |
| 679 | |
| 680 | if (!psdev->pdev->sh_info) { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 681 | dev_err(&dev->dev, DRV_NAME " device is not connected or owned" |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 682 | " by HVM, kill it\n"); |
| 683 | kill_domain_by_device(psdev); |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 684 | goto end; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | if (!test_bit(_XEN_PCIB_AERHANDLER, |
| 688 | (unsigned long *)&psdev->pdev->sh_info->flags)) { |
| 689 | dev_err(&dev->dev, |
| 690 | "guest with no AER driver should have been killed\n"); |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 691 | goto end; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 692 | } |
| 693 | result = common_process(psdev, 1, XEN_PCI_OP_aer_slotreset, result); |
| 694 | |
| 695 | if (result == PCI_ERS_RESULT_NONE || |
| 696 | result == PCI_ERS_RESULT_DISCONNECT) { |
| 697 | dev_dbg(&dev->dev, |
| 698 | "No AER slot_reset service or disconnected!\n"); |
| 699 | kill_domain_by_device(psdev); |
| 700 | } |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 701 | end: |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 702 | if (psdev) |
| 703 | pcistub_device_put(psdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 704 | up_write(&pcistub_sem); |
| 705 | return result; |
| 706 | |
| 707 | } |
| 708 | |
| 709 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 710 | /*xen_pcibk_mmio_enabled: it will send the mmio_enabled request to pcifront |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 711 | * in case of the device driver could provide this service, and then wait |
| 712 | * for pcifront ack |
| 713 | * @dev: pointer to PCI devices |
| 714 | * return value is used by aer_core do_recovery policy |
| 715 | */ |
| 716 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 717 | static pci_ers_result_t xen_pcibk_mmio_enabled(struct pci_dev *dev) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 718 | { |
| 719 | struct pcistub_device *psdev; |
| 720 | pci_ers_result_t result; |
| 721 | |
| 722 | result = PCI_ERS_RESULT_RECOVERED; |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 723 | dev_dbg(&dev->dev, "xen_pcibk_mmio_enabled(bus:%x,devfn:%x)\n", |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 724 | dev->bus->number, dev->devfn); |
| 725 | |
| 726 | down_write(&pcistub_sem); |
| 727 | psdev = pcistub_device_find(pci_domain_nr(dev->bus), |
| 728 | dev->bus->number, |
| 729 | PCI_SLOT(dev->devfn), |
| 730 | PCI_FUNC(dev->devfn)); |
| 731 | |
| 732 | if (!psdev || !psdev->pdev) { |
| 733 | dev_err(&dev->dev, |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 734 | DRV_NAME " device is not found/assigned\n"); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 735 | goto end; |
| 736 | } |
| 737 | |
| 738 | if (!psdev->pdev->sh_info) { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 739 | dev_err(&dev->dev, DRV_NAME " device is not connected or owned" |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 740 | " by HVM, kill it\n"); |
| 741 | kill_domain_by_device(psdev); |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 742 | goto end; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 743 | } |
| 744 | |
| 745 | if (!test_bit(_XEN_PCIB_AERHANDLER, |
| 746 | (unsigned long *)&psdev->pdev->sh_info->flags)) { |
| 747 | dev_err(&dev->dev, |
| 748 | "guest with no AER driver should have been killed\n"); |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 749 | goto end; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 750 | } |
| 751 | result = common_process(psdev, 1, XEN_PCI_OP_aer_mmio, result); |
| 752 | |
| 753 | if (result == PCI_ERS_RESULT_NONE || |
| 754 | result == PCI_ERS_RESULT_DISCONNECT) { |
| 755 | dev_dbg(&dev->dev, |
| 756 | "No AER mmio_enabled service or disconnected!\n"); |
| 757 | kill_domain_by_device(psdev); |
| 758 | } |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 759 | end: |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 760 | if (psdev) |
| 761 | pcistub_device_put(psdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 762 | up_write(&pcistub_sem); |
| 763 | return result; |
| 764 | } |
| 765 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 766 | /*xen_pcibk_error_detected: it will send the error_detected request to pcifront |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 767 | * in case of the device driver could provide this service, and then wait |
| 768 | * for pcifront ack. |
| 769 | * @dev: pointer to PCI devices |
| 770 | * @error: the current PCI connection state |
| 771 | * return value is used by aer_core do_recovery policy |
| 772 | */ |
| 773 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 774 | static pci_ers_result_t xen_pcibk_error_detected(struct pci_dev *dev, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 775 | pci_channel_state_t error) |
| 776 | { |
| 777 | struct pcistub_device *psdev; |
| 778 | pci_ers_result_t result; |
| 779 | |
| 780 | result = PCI_ERS_RESULT_CAN_RECOVER; |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 781 | dev_dbg(&dev->dev, "xen_pcibk_error_detected(bus:%x,devfn:%x)\n", |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 782 | dev->bus->number, dev->devfn); |
| 783 | |
| 784 | down_write(&pcistub_sem); |
| 785 | psdev = pcistub_device_find(pci_domain_nr(dev->bus), |
| 786 | dev->bus->number, |
| 787 | PCI_SLOT(dev->devfn), |
| 788 | PCI_FUNC(dev->devfn)); |
| 789 | |
| 790 | if (!psdev || !psdev->pdev) { |
| 791 | dev_err(&dev->dev, |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 792 | DRV_NAME " device is not found/assigned\n"); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 793 | goto end; |
| 794 | } |
| 795 | |
| 796 | if (!psdev->pdev->sh_info) { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 797 | dev_err(&dev->dev, DRV_NAME " device is not connected or owned" |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 798 | " by HVM, kill it\n"); |
| 799 | kill_domain_by_device(psdev); |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 800 | goto end; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 801 | } |
| 802 | |
| 803 | /*Guest owns the device yet no aer handler regiested, kill guest*/ |
| 804 | if (!test_bit(_XEN_PCIB_AERHANDLER, |
| 805 | (unsigned long *)&psdev->pdev->sh_info->flags)) { |
| 806 | dev_dbg(&dev->dev, "guest may have no aer driver, kill it\n"); |
| 807 | kill_domain_by_device(psdev); |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 808 | goto end; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 809 | } |
| 810 | result = common_process(psdev, error, XEN_PCI_OP_aer_detected, result); |
| 811 | |
| 812 | if (result == PCI_ERS_RESULT_NONE || |
| 813 | result == PCI_ERS_RESULT_DISCONNECT) { |
| 814 | dev_dbg(&dev->dev, |
| 815 | "No AER error_detected service or disconnected!\n"); |
| 816 | kill_domain_by_device(psdev); |
| 817 | } |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 818 | end: |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 819 | if (psdev) |
| 820 | pcistub_device_put(psdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 821 | up_write(&pcistub_sem); |
| 822 | return result; |
| 823 | } |
| 824 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 825 | /*xen_pcibk_error_resume: it will send the error_resume request to pcifront |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 826 | * in case of the device driver could provide this service, and then wait |
| 827 | * for pcifront ack. |
| 828 | * @dev: pointer to PCI devices |
| 829 | */ |
| 830 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 831 | static void xen_pcibk_error_resume(struct pci_dev *dev) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 832 | { |
| 833 | struct pcistub_device *psdev; |
| 834 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 835 | dev_dbg(&dev->dev, "xen_pcibk_error_resume(bus:%x,devfn:%x)\n", |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 836 | dev->bus->number, dev->devfn); |
| 837 | |
| 838 | down_write(&pcistub_sem); |
| 839 | psdev = pcistub_device_find(pci_domain_nr(dev->bus), |
| 840 | dev->bus->number, |
| 841 | PCI_SLOT(dev->devfn), |
| 842 | PCI_FUNC(dev->devfn)); |
| 843 | |
| 844 | if (!psdev || !psdev->pdev) { |
| 845 | dev_err(&dev->dev, |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 846 | DRV_NAME " device is not found/assigned\n"); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 847 | goto end; |
| 848 | } |
| 849 | |
| 850 | if (!psdev->pdev->sh_info) { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 851 | dev_err(&dev->dev, DRV_NAME " device is not connected or owned" |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 852 | " by HVM, kill it\n"); |
| 853 | kill_domain_by_device(psdev); |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 854 | goto end; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 855 | } |
| 856 | |
| 857 | if (!test_bit(_XEN_PCIB_AERHANDLER, |
| 858 | (unsigned long *)&psdev->pdev->sh_info->flags)) { |
| 859 | dev_err(&dev->dev, |
| 860 | "guest with no AER driver should have been killed\n"); |
| 861 | kill_domain_by_device(psdev); |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 862 | goto end; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 863 | } |
| 864 | common_process(psdev, 1, XEN_PCI_OP_aer_resume, |
| 865 | PCI_ERS_RESULT_RECOVERED); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 866 | end: |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 867 | if (psdev) |
| 868 | pcistub_device_put(psdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 869 | up_write(&pcistub_sem); |
| 870 | return; |
| 871 | } |
| 872 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 873 | /*add xen_pcibk AER handling*/ |
| 874 | static struct pci_error_handlers xen_pcibk_error_handler = { |
| 875 | .error_detected = xen_pcibk_error_detected, |
| 876 | .mmio_enabled = xen_pcibk_mmio_enabled, |
| 877 | .slot_reset = xen_pcibk_slot_reset, |
| 878 | .resume = xen_pcibk_error_resume, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 879 | }; |
| 880 | |
| 881 | /* |
| 882 | * Note: There is no MODULE_DEVICE_TABLE entry here because this isn't |
| 883 | * for a normal device. I don't want it to be loaded automatically. |
| 884 | */ |
| 885 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 886 | static struct pci_driver xen_pcibk_pci_driver = { |
| 887 | /* The name should be xen_pciback, but until the tools are updated |
| 888 | * we will keep it as pciback. */ |
| 889 | .name = "pciback", |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 890 | .id_table = pcistub_ids, |
| 891 | .probe = pcistub_probe, |
| 892 | .remove = pcistub_remove, |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 893 | .err_handler = &xen_pcibk_error_handler, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 894 | }; |
| 895 | |
| 896 | static inline int str_to_slot(const char *buf, int *domain, int *bus, |
| 897 | int *slot, int *func) |
| 898 | { |
| 899 | int err; |
Jan Beulich | c3cb470 | 2012-09-18 12:29:03 +0100 | [diff] [blame] | 900 | char wc = '*'; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 901 | |
| 902 | err = sscanf(buf, " %x:%x:%x.%x", domain, bus, slot, func); |
Jan Beulich | c3cb470 | 2012-09-18 12:29:03 +0100 | [diff] [blame] | 903 | switch (err) { |
| 904 | case 3: |
| 905 | *func = -1; |
| 906 | err = sscanf(buf, " %x:%x:%x.%c", domain, bus, slot, &wc); |
| 907 | break; |
| 908 | case 2: |
| 909 | *slot = *func = -1; |
| 910 | err = sscanf(buf, " %x:%x:*.%c", domain, bus, &wc); |
| 911 | if (err >= 2) |
| 912 | ++err; |
| 913 | break; |
| 914 | } |
| 915 | if (err == 4 && wc == '*') |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 916 | return 0; |
| 917 | else if (err < 0) |
| 918 | return -EINVAL; |
| 919 | |
| 920 | /* try again without domain */ |
| 921 | *domain = 0; |
Jan Beulich | c3cb470 | 2012-09-18 12:29:03 +0100 | [diff] [blame] | 922 | wc = '*'; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 923 | err = sscanf(buf, " %x:%x.%x", bus, slot, func); |
Jan Beulich | c3cb470 | 2012-09-18 12:29:03 +0100 | [diff] [blame] | 924 | switch (err) { |
| 925 | case 2: |
| 926 | *func = -1; |
| 927 | err = sscanf(buf, " %x:%x.%c", bus, slot, &wc); |
| 928 | break; |
| 929 | case 1: |
| 930 | *slot = *func = -1; |
| 931 | err = sscanf(buf, " %x:*.%c", bus, &wc) + 1; |
| 932 | break; |
| 933 | } |
| 934 | if (err == 3 && wc == '*') |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 935 | return 0; |
| 936 | |
| 937 | return -EINVAL; |
| 938 | } |
| 939 | |
| 940 | static inline int str_to_quirk(const char *buf, int *domain, int *bus, int |
| 941 | *slot, int *func, int *reg, int *size, int *mask) |
| 942 | { |
| 943 | int err; |
| 944 | |
| 945 | err = |
Konrad Rzeszutek Wilk | e4de866 | 2012-01-25 16:00:00 -0500 | [diff] [blame] | 946 | sscanf(buf, " %04x:%02x:%02x.%d-%08x:%1x:%08x", domain, bus, slot, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 947 | func, reg, size, mask); |
| 948 | if (err == 7) |
| 949 | return 0; |
| 950 | return -EINVAL; |
| 951 | } |
| 952 | |
| 953 | static int pcistub_device_id_add(int domain, int bus, int slot, int func) |
| 954 | { |
| 955 | struct pcistub_device_id *pci_dev_id; |
| 956 | unsigned long flags; |
Jan Beulich | c3cb470 | 2012-09-18 12:29:03 +0100 | [diff] [blame] | 957 | int rc = 0; |
| 958 | |
| 959 | if (slot < 0) { |
| 960 | for (slot = 0; !rc && slot < 32; ++slot) |
| 961 | rc = pcistub_device_id_add(domain, bus, slot, func); |
| 962 | return rc; |
| 963 | } |
| 964 | |
| 965 | if (func < 0) { |
| 966 | for (func = 0; !rc && func < 8; ++func) |
| 967 | rc = pcistub_device_id_add(domain, bus, slot, func); |
| 968 | return rc; |
| 969 | } |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 970 | |
| 971 | pci_dev_id = kmalloc(sizeof(*pci_dev_id), GFP_KERNEL); |
| 972 | if (!pci_dev_id) |
| 973 | return -ENOMEM; |
| 974 | |
| 975 | pci_dev_id->domain = domain; |
| 976 | pci_dev_id->bus = bus; |
| 977 | pci_dev_id->devfn = PCI_DEVFN(slot, func); |
| 978 | |
Konrad Rzeszutek Wilk | e4de866 | 2012-01-25 16:00:00 -0500 | [diff] [blame] | 979 | pr_debug(DRV_NAME ": wants to seize %04x:%02x:%02x.%d\n", |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 980 | domain, bus, slot, func); |
| 981 | |
| 982 | spin_lock_irqsave(&device_ids_lock, flags); |
| 983 | list_add_tail(&pci_dev_id->slot_list, &pcistub_device_ids); |
| 984 | spin_unlock_irqrestore(&device_ids_lock, flags); |
| 985 | |
| 986 | return 0; |
| 987 | } |
| 988 | |
| 989 | static int pcistub_device_id_remove(int domain, int bus, int slot, int func) |
| 990 | { |
| 991 | struct pcistub_device_id *pci_dev_id, *t; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 992 | int err = -ENOENT; |
| 993 | unsigned long flags; |
| 994 | |
| 995 | spin_lock_irqsave(&device_ids_lock, flags); |
| 996 | list_for_each_entry_safe(pci_dev_id, t, &pcistub_device_ids, |
| 997 | slot_list) { |
Jan Beulich | c3cb470 | 2012-09-18 12:29:03 +0100 | [diff] [blame] | 998 | if (pci_dev_id->domain == domain && pci_dev_id->bus == bus |
| 999 | && (slot < 0 || PCI_SLOT(pci_dev_id->devfn) == slot) |
| 1000 | && (func < 0 || PCI_FUNC(pci_dev_id->devfn) == func)) { |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1001 | /* Don't break; here because it's possible the same |
| 1002 | * slot could be in the list more than once |
| 1003 | */ |
| 1004 | list_del(&pci_dev_id->slot_list); |
| 1005 | kfree(pci_dev_id); |
| 1006 | |
| 1007 | err = 0; |
| 1008 | |
Konrad Rzeszutek Wilk | e4de866 | 2012-01-25 16:00:00 -0500 | [diff] [blame] | 1009 | pr_debug(DRV_NAME ": removed %04x:%02x:%02x.%d from " |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1010 | "seize list\n", domain, bus, slot, func); |
| 1011 | } |
| 1012 | } |
| 1013 | spin_unlock_irqrestore(&device_ids_lock, flags); |
| 1014 | |
| 1015 | return err; |
| 1016 | } |
| 1017 | |
| 1018 | static int pcistub_reg_add(int domain, int bus, int slot, int func, int reg, |
| 1019 | int size, int mask) |
| 1020 | { |
| 1021 | int err = 0; |
| 1022 | struct pcistub_device *psdev; |
| 1023 | struct pci_dev *dev; |
| 1024 | struct config_field *field; |
| 1025 | |
| 1026 | psdev = pcistub_device_find(domain, bus, slot, func); |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 1027 | if (!psdev) { |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1028 | err = -ENODEV; |
| 1029 | goto out; |
| 1030 | } |
| 1031 | dev = psdev->dev; |
| 1032 | |
| 1033 | field = kzalloc(sizeof(*field), GFP_ATOMIC); |
| 1034 | if (!field) { |
| 1035 | err = -ENOMEM; |
| 1036 | goto out; |
| 1037 | } |
| 1038 | |
| 1039 | field->offset = reg; |
| 1040 | field->size = size; |
| 1041 | field->mask = mask; |
| 1042 | field->init = NULL; |
| 1043 | field->reset = NULL; |
| 1044 | field->release = NULL; |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1045 | field->clean = xen_pcibk_config_field_free; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1046 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1047 | err = xen_pcibk_config_quirks_add_field(dev, field); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1048 | if (err) |
| 1049 | kfree(field); |
| 1050 | out: |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 1051 | if (psdev) |
| 1052 | pcistub_device_put(psdev); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1053 | return err; |
| 1054 | } |
| 1055 | |
| 1056 | static ssize_t pcistub_slot_add(struct device_driver *drv, const char *buf, |
| 1057 | size_t count) |
| 1058 | { |
| 1059 | int domain, bus, slot, func; |
| 1060 | int err; |
| 1061 | |
| 1062 | err = str_to_slot(buf, &domain, &bus, &slot, &func); |
| 1063 | if (err) |
| 1064 | goto out; |
| 1065 | |
| 1066 | err = pcistub_device_id_add(domain, bus, slot, func); |
| 1067 | |
| 1068 | out: |
| 1069 | if (!err) |
| 1070 | err = count; |
| 1071 | return err; |
| 1072 | } |
Jan Beulich | 402c5e1 | 2011-09-21 16:22:11 -0400 | [diff] [blame] | 1073 | static DRIVER_ATTR(new_slot, S_IWUSR, NULL, pcistub_slot_add); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1074 | |
| 1075 | static ssize_t pcistub_slot_remove(struct device_driver *drv, const char *buf, |
| 1076 | size_t count) |
| 1077 | { |
| 1078 | int domain, bus, slot, func; |
| 1079 | int err; |
| 1080 | |
| 1081 | err = str_to_slot(buf, &domain, &bus, &slot, &func); |
| 1082 | if (err) |
| 1083 | goto out; |
| 1084 | |
| 1085 | err = pcistub_device_id_remove(domain, bus, slot, func); |
| 1086 | |
| 1087 | out: |
| 1088 | if (!err) |
| 1089 | err = count; |
| 1090 | return err; |
| 1091 | } |
Jan Beulich | 402c5e1 | 2011-09-21 16:22:11 -0400 | [diff] [blame] | 1092 | static DRIVER_ATTR(remove_slot, S_IWUSR, NULL, pcistub_slot_remove); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1093 | |
| 1094 | static ssize_t pcistub_slot_show(struct device_driver *drv, char *buf) |
| 1095 | { |
| 1096 | struct pcistub_device_id *pci_dev_id; |
| 1097 | size_t count = 0; |
| 1098 | unsigned long flags; |
| 1099 | |
| 1100 | spin_lock_irqsave(&device_ids_lock, flags); |
| 1101 | list_for_each_entry(pci_dev_id, &pcistub_device_ids, slot_list) { |
| 1102 | if (count >= PAGE_SIZE) |
| 1103 | break; |
| 1104 | |
| 1105 | count += scnprintf(buf + count, PAGE_SIZE - count, |
Konrad Rzeszutek Wilk | e4de866 | 2012-01-25 16:00:00 -0500 | [diff] [blame] | 1106 | "%04x:%02x:%02x.%d\n", |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1107 | pci_dev_id->domain, pci_dev_id->bus, |
| 1108 | PCI_SLOT(pci_dev_id->devfn), |
| 1109 | PCI_FUNC(pci_dev_id->devfn)); |
| 1110 | } |
| 1111 | spin_unlock_irqrestore(&device_ids_lock, flags); |
| 1112 | |
| 1113 | return count; |
| 1114 | } |
Jan Beulich | 402c5e1 | 2011-09-21 16:22:11 -0400 | [diff] [blame] | 1115 | static DRIVER_ATTR(slots, S_IRUSR, pcistub_slot_show, NULL); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1116 | |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 1117 | static ssize_t pcistub_irq_handler_show(struct device_driver *drv, char *buf) |
| 1118 | { |
| 1119 | struct pcistub_device *psdev; |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1120 | struct xen_pcibk_dev_data *dev_data; |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 1121 | size_t count = 0; |
| 1122 | unsigned long flags; |
| 1123 | |
| 1124 | spin_lock_irqsave(&pcistub_devices_lock, flags); |
| 1125 | list_for_each_entry(psdev, &pcistub_devices, dev_list) { |
| 1126 | if (count >= PAGE_SIZE) |
| 1127 | break; |
| 1128 | if (!psdev->dev) |
| 1129 | continue; |
| 1130 | dev_data = pci_get_drvdata(psdev->dev); |
| 1131 | if (!dev_data) |
| 1132 | continue; |
| 1133 | count += |
| 1134 | scnprintf(buf + count, PAGE_SIZE - count, |
| 1135 | "%s:%s:%sing:%ld\n", |
| 1136 | pci_name(psdev->dev), |
| 1137 | dev_data->isr_on ? "on" : "off", |
| 1138 | dev_data->ack_intr ? "ack" : "not ack", |
| 1139 | dev_data->handled); |
| 1140 | } |
| 1141 | spin_unlock_irqrestore(&pcistub_devices_lock, flags); |
| 1142 | return count; |
| 1143 | } |
Jan Beulich | 402c5e1 | 2011-09-21 16:22:11 -0400 | [diff] [blame] | 1144 | static DRIVER_ATTR(irq_handlers, S_IRUSR, pcistub_irq_handler_show, NULL); |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 1145 | |
| 1146 | static ssize_t pcistub_irq_handler_switch(struct device_driver *drv, |
| 1147 | const char *buf, |
| 1148 | size_t count) |
| 1149 | { |
| 1150 | struct pcistub_device *psdev; |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1151 | struct xen_pcibk_dev_data *dev_data; |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 1152 | int domain, bus, slot, func; |
| 1153 | int err = -ENOENT; |
| 1154 | |
| 1155 | err = str_to_slot(buf, &domain, &bus, &slot, &func); |
| 1156 | if (err) |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 1157 | return err; |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 1158 | |
| 1159 | psdev = pcistub_device_find(domain, bus, slot, func); |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 1160 | if (!psdev) |
| 1161 | goto out; |
| 1162 | |
| 1163 | dev_data = pci_get_drvdata(psdev->dev); |
| 1164 | if (!dev_data) |
| 1165 | goto out; |
| 1166 | |
| 1167 | dev_dbg(&psdev->dev->dev, "%s fake irq handler: %d->%d\n", |
| 1168 | dev_data->irq_name, dev_data->isr_on, |
| 1169 | !dev_data->isr_on); |
| 1170 | |
| 1171 | dev_data->isr_on = !(dev_data->isr_on); |
| 1172 | if (dev_data->isr_on) |
| 1173 | dev_data->ack_intr = 1; |
| 1174 | out: |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 1175 | if (psdev) |
| 1176 | pcistub_device_put(psdev); |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 1177 | if (!err) |
| 1178 | err = count; |
| 1179 | return err; |
| 1180 | } |
Jan Beulich | 402c5e1 | 2011-09-21 16:22:11 -0400 | [diff] [blame] | 1181 | static DRIVER_ATTR(irq_handler_state, S_IWUSR, NULL, |
| 1182 | pcistub_irq_handler_switch); |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 1183 | |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1184 | static ssize_t pcistub_quirk_add(struct device_driver *drv, const char *buf, |
| 1185 | size_t count) |
| 1186 | { |
| 1187 | int domain, bus, slot, func, reg, size, mask; |
| 1188 | int err; |
| 1189 | |
| 1190 | err = str_to_quirk(buf, &domain, &bus, &slot, &func, ®, &size, |
| 1191 | &mask); |
| 1192 | if (err) |
| 1193 | goto out; |
| 1194 | |
| 1195 | err = pcistub_reg_add(domain, bus, slot, func, reg, size, mask); |
| 1196 | |
| 1197 | out: |
| 1198 | if (!err) |
| 1199 | err = count; |
| 1200 | return err; |
| 1201 | } |
| 1202 | |
| 1203 | static ssize_t pcistub_quirk_show(struct device_driver *drv, char *buf) |
| 1204 | { |
| 1205 | int count = 0; |
| 1206 | unsigned long flags; |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1207 | struct xen_pcibk_config_quirk *quirk; |
| 1208 | struct xen_pcibk_dev_data *dev_data; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1209 | const struct config_field *field; |
| 1210 | const struct config_field_entry *cfg_entry; |
| 1211 | |
| 1212 | spin_lock_irqsave(&device_ids_lock, flags); |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1213 | list_for_each_entry(quirk, &xen_pcibk_quirks, quirks_list) { |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1214 | if (count >= PAGE_SIZE) |
| 1215 | goto out; |
| 1216 | |
| 1217 | count += scnprintf(buf + count, PAGE_SIZE - count, |
| 1218 | "%02x:%02x.%01x\n\t%04x:%04x:%04x:%04x\n", |
| 1219 | quirk->pdev->bus->number, |
| 1220 | PCI_SLOT(quirk->pdev->devfn), |
| 1221 | PCI_FUNC(quirk->pdev->devfn), |
| 1222 | quirk->devid.vendor, quirk->devid.device, |
| 1223 | quirk->devid.subvendor, |
| 1224 | quirk->devid.subdevice); |
| 1225 | |
| 1226 | dev_data = pci_get_drvdata(quirk->pdev); |
| 1227 | |
| 1228 | list_for_each_entry(cfg_entry, &dev_data->config_fields, list) { |
| 1229 | field = cfg_entry->field; |
| 1230 | if (count >= PAGE_SIZE) |
| 1231 | goto out; |
| 1232 | |
| 1233 | count += scnprintf(buf + count, PAGE_SIZE - count, |
| 1234 | "\t\t%08x:%01x:%08x\n", |
| 1235 | cfg_entry->base_offset + |
| 1236 | field->offset, field->size, |
| 1237 | field->mask); |
| 1238 | } |
| 1239 | } |
| 1240 | |
| 1241 | out: |
| 1242 | spin_unlock_irqrestore(&device_ids_lock, flags); |
| 1243 | |
| 1244 | return count; |
| 1245 | } |
Jan Beulich | 402c5e1 | 2011-09-21 16:22:11 -0400 | [diff] [blame] | 1246 | static DRIVER_ATTR(quirks, S_IRUSR | S_IWUSR, pcistub_quirk_show, |
| 1247 | pcistub_quirk_add); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1248 | |
| 1249 | static ssize_t permissive_add(struct device_driver *drv, const char *buf, |
| 1250 | size_t count) |
| 1251 | { |
| 1252 | int domain, bus, slot, func; |
| 1253 | int err; |
| 1254 | struct pcistub_device *psdev; |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1255 | struct xen_pcibk_dev_data *dev_data; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1256 | err = str_to_slot(buf, &domain, &bus, &slot, &func); |
| 1257 | if (err) |
| 1258 | goto out; |
Jan Beulich | c3cb470 | 2012-09-18 12:29:03 +0100 | [diff] [blame] | 1259 | if (slot < 0 || func < 0) { |
| 1260 | err = -EINVAL; |
| 1261 | goto out; |
| 1262 | } |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1263 | psdev = pcistub_device_find(domain, bus, slot, func); |
| 1264 | if (!psdev) { |
| 1265 | err = -ENODEV; |
| 1266 | goto out; |
| 1267 | } |
Jan Beulich | e6aa70a | 2012-09-24 15:55:37 +0100 | [diff] [blame^] | 1268 | |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1269 | dev_data = pci_get_drvdata(psdev->dev); |
| 1270 | /* the driver data for a device should never be null at this point */ |
| 1271 | if (!dev_data) { |
| 1272 | err = -ENXIO; |
| 1273 | goto release; |
| 1274 | } |
| 1275 | if (!dev_data->permissive) { |
| 1276 | dev_data->permissive = 1; |
| 1277 | /* Let user know that what they're doing could be unsafe */ |
| 1278 | dev_warn(&psdev->dev->dev, "enabling permissive mode " |
| 1279 | "configuration space accesses!\n"); |
| 1280 | dev_warn(&psdev->dev->dev, |
| 1281 | "permissive mode is potentially unsafe!\n"); |
| 1282 | } |
| 1283 | release: |
| 1284 | pcistub_device_put(psdev); |
| 1285 | out: |
| 1286 | if (!err) |
| 1287 | err = count; |
| 1288 | return err; |
| 1289 | } |
| 1290 | |
| 1291 | static ssize_t permissive_show(struct device_driver *drv, char *buf) |
| 1292 | { |
| 1293 | struct pcistub_device *psdev; |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1294 | struct xen_pcibk_dev_data *dev_data; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1295 | size_t count = 0; |
| 1296 | unsigned long flags; |
| 1297 | spin_lock_irqsave(&pcistub_devices_lock, flags); |
| 1298 | list_for_each_entry(psdev, &pcistub_devices, dev_list) { |
| 1299 | if (count >= PAGE_SIZE) |
| 1300 | break; |
| 1301 | if (!psdev->dev) |
| 1302 | continue; |
| 1303 | dev_data = pci_get_drvdata(psdev->dev); |
| 1304 | if (!dev_data || !dev_data->permissive) |
| 1305 | continue; |
| 1306 | count += |
| 1307 | scnprintf(buf + count, PAGE_SIZE - count, "%s\n", |
| 1308 | pci_name(psdev->dev)); |
| 1309 | } |
| 1310 | spin_unlock_irqrestore(&pcistub_devices_lock, flags); |
| 1311 | return count; |
| 1312 | } |
Jan Beulich | 402c5e1 | 2011-09-21 16:22:11 -0400 | [diff] [blame] | 1313 | static DRIVER_ATTR(permissive, S_IRUSR | S_IWUSR, permissive_show, |
| 1314 | permissive_add); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1315 | |
| 1316 | static void pcistub_exit(void) |
| 1317 | { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1318 | driver_remove_file(&xen_pcibk_pci_driver.driver, &driver_attr_new_slot); |
| 1319 | driver_remove_file(&xen_pcibk_pci_driver.driver, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1320 | &driver_attr_remove_slot); |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1321 | driver_remove_file(&xen_pcibk_pci_driver.driver, &driver_attr_slots); |
| 1322 | driver_remove_file(&xen_pcibk_pci_driver.driver, &driver_attr_quirks); |
| 1323 | driver_remove_file(&xen_pcibk_pci_driver.driver, |
| 1324 | &driver_attr_permissive); |
| 1325 | driver_remove_file(&xen_pcibk_pci_driver.driver, |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 1326 | &driver_attr_irq_handlers); |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1327 | driver_remove_file(&xen_pcibk_pci_driver.driver, |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 1328 | &driver_attr_irq_handler_state); |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1329 | pci_unregister_driver(&xen_pcibk_pci_driver); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | static int __init pcistub_init(void) |
| 1333 | { |
| 1334 | int pos = 0; |
| 1335 | int err = 0; |
| 1336 | int domain, bus, slot, func; |
| 1337 | int parsed; |
| 1338 | |
| 1339 | if (pci_devs_to_hide && *pci_devs_to_hide) { |
| 1340 | do { |
Jan Beulich | c3cb470 | 2012-09-18 12:29:03 +0100 | [diff] [blame] | 1341 | char wc = '*'; |
| 1342 | |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1343 | parsed = 0; |
| 1344 | |
| 1345 | err = sscanf(pci_devs_to_hide + pos, |
| 1346 | " (%x:%x:%x.%x) %n", |
| 1347 | &domain, &bus, &slot, &func, &parsed); |
Jan Beulich | c3cb470 | 2012-09-18 12:29:03 +0100 | [diff] [blame] | 1348 | switch (err) { |
| 1349 | case 3: |
| 1350 | func = -1; |
| 1351 | err = sscanf(pci_devs_to_hide + pos, |
| 1352 | " (%x:%x:%x.%c) %n", |
| 1353 | &domain, &bus, &slot, &wc, |
| 1354 | &parsed); |
| 1355 | break; |
| 1356 | case 2: |
| 1357 | slot = func = -1; |
| 1358 | err = sscanf(pci_devs_to_hide + pos, |
| 1359 | " (%x:%x:*.%c) %n", |
| 1360 | &domain, &bus, &wc, &parsed) + 1; |
| 1361 | break; |
| 1362 | } |
| 1363 | |
| 1364 | if (err != 4 || wc != '*') { |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1365 | domain = 0; |
Jan Beulich | c3cb470 | 2012-09-18 12:29:03 +0100 | [diff] [blame] | 1366 | wc = '*'; |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1367 | err = sscanf(pci_devs_to_hide + pos, |
| 1368 | " (%x:%x.%x) %n", |
| 1369 | &bus, &slot, &func, &parsed); |
Jan Beulich | c3cb470 | 2012-09-18 12:29:03 +0100 | [diff] [blame] | 1370 | switch (err) { |
| 1371 | case 2: |
| 1372 | func = -1; |
| 1373 | err = sscanf(pci_devs_to_hide + pos, |
| 1374 | " (%x:%x.%c) %n", |
| 1375 | &bus, &slot, &wc, |
| 1376 | &parsed); |
| 1377 | break; |
| 1378 | case 1: |
| 1379 | slot = func = -1; |
| 1380 | err = sscanf(pci_devs_to_hide + pos, |
| 1381 | " (%x:*.%c) %n", |
| 1382 | &bus, &wc, &parsed) + 1; |
| 1383 | break; |
| 1384 | } |
| 1385 | if (err != 3 || wc != '*') |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1386 | goto parse_error; |
| 1387 | } |
| 1388 | |
| 1389 | err = pcistub_device_id_add(domain, bus, slot, func); |
| 1390 | if (err) |
| 1391 | goto out; |
| 1392 | |
| 1393 | /* if parsed<=0, we've reached the end of the string */ |
| 1394 | pos += parsed; |
| 1395 | } while (parsed > 0 && pci_devs_to_hide[pos]); |
| 1396 | } |
| 1397 | |
| 1398 | /* If we're the first PCI Device Driver to register, we're the |
| 1399 | * first one to get offered PCI devices as they become |
| 1400 | * available (and thus we can be the first to grab them) |
| 1401 | */ |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1402 | err = pci_register_driver(&xen_pcibk_pci_driver); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1403 | if (err < 0) |
| 1404 | goto out; |
| 1405 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1406 | err = driver_create_file(&xen_pcibk_pci_driver.driver, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1407 | &driver_attr_new_slot); |
| 1408 | if (!err) |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1409 | err = driver_create_file(&xen_pcibk_pci_driver.driver, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1410 | &driver_attr_remove_slot); |
| 1411 | if (!err) |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1412 | err = driver_create_file(&xen_pcibk_pci_driver.driver, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1413 | &driver_attr_slots); |
| 1414 | if (!err) |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1415 | err = driver_create_file(&xen_pcibk_pci_driver.driver, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1416 | &driver_attr_quirks); |
| 1417 | if (!err) |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1418 | err = driver_create_file(&xen_pcibk_pci_driver.driver, |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1419 | &driver_attr_permissive); |
| 1420 | |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 1421 | if (!err) |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1422 | err = driver_create_file(&xen_pcibk_pci_driver.driver, |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 1423 | &driver_attr_irq_handlers); |
| 1424 | if (!err) |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1425 | err = driver_create_file(&xen_pcibk_pci_driver.driver, |
Konrad Rzeszutek Wilk | 0513fe9 | 2011-07-19 18:56:39 -0400 | [diff] [blame] | 1426 | &driver_attr_irq_handler_state); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1427 | if (err) |
| 1428 | pcistub_exit(); |
| 1429 | |
| 1430 | out: |
| 1431 | return err; |
| 1432 | |
| 1433 | parse_error: |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1434 | printk(KERN_ERR DRV_NAME ": Error parsing pci_devs_to_hide at \"%s\"\n", |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1435 | pci_devs_to_hide + pos); |
| 1436 | return -EINVAL; |
| 1437 | } |
| 1438 | |
| 1439 | #ifndef MODULE |
| 1440 | /* |
| 1441 | * fs_initcall happens before device_initcall |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1442 | * so xen_pcibk *should* get called first (b/c we |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1443 | * want to suck up any device before other drivers |
| 1444 | * get a chance by being the first pci device |
| 1445 | * driver to register) |
| 1446 | */ |
| 1447 | fs_initcall(pcistub_init); |
| 1448 | #endif |
| 1449 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1450 | static int __init xen_pcibk_init(void) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1451 | { |
| 1452 | int err; |
| 1453 | |
| 1454 | if (!xen_initial_domain()) |
| 1455 | return -ENODEV; |
| 1456 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1457 | err = xen_pcibk_config_init(); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1458 | if (err) |
| 1459 | return err; |
| 1460 | |
| 1461 | #ifdef MODULE |
| 1462 | err = pcistub_init(); |
| 1463 | if (err < 0) |
| 1464 | return err; |
| 1465 | #endif |
| 1466 | |
| 1467 | pcistub_init_devices_late(); |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1468 | err = xen_pcibk_xenbus_register(); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1469 | if (err) |
| 1470 | pcistub_exit(); |
| 1471 | |
| 1472 | return err; |
| 1473 | } |
| 1474 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1475 | static void __exit xen_pcibk_cleanup(void) |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1476 | { |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1477 | xen_pcibk_xenbus_unregister(); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1478 | pcistub_exit(); |
| 1479 | } |
| 1480 | |
Konrad Rzeszutek Wilk | a92336a | 2011-07-19 19:40:51 -0400 | [diff] [blame] | 1481 | module_init(xen_pcibk_init); |
| 1482 | module_exit(xen_pcibk_cleanup); |
Konrad Rzeszutek Wilk | 30edc14 | 2009-10-13 17:22:20 -0400 | [diff] [blame] | 1483 | |
| 1484 | MODULE_LICENSE("Dual BSD/GPL"); |
Jan Beulich | 402c5e1 | 2011-09-21 16:22:11 -0400 | [diff] [blame] | 1485 | MODULE_ALIAS("xen-backend:pci"); |