sched: Remove double_rq_lock() from __migrate_task()
[linux/fpc-iii.git] / drivers / xen / xen-pciback / pci_stub.c
blobd57a173685f3bddf4ff2ec42feaa5a1ed35af06e
1 /*
2 * PCI Stub Driver - Grabs devices in backend to be exported later
4 * Ryan Wilson <hap9@epoch.ncsc.mil>
5 * Chris Bookholt <hap10@epoch.ncsc.mil>
6 */
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
10 #include <linux/module.h>
11 #include <linux/init.h>
12 #include <linux/rwsem.h>
13 #include <linux/list.h>
14 #include <linux/spinlock.h>
15 #include <linux/kref.h>
16 #include <linux/pci.h>
17 #include <linux/wait.h>
18 #include <linux/sched.h>
19 #include <linux/atomic.h>
20 #include <xen/events.h>
21 #include <asm/xen/pci.h>
22 #include <asm/xen/hypervisor.h>
23 #include <xen/interface/physdev.h>
24 #include "pciback.h"
25 #include "conf_space.h"
26 #include "conf_space_quirks.h"
28 static char *pci_devs_to_hide;
29 wait_queue_head_t xen_pcibk_aer_wait_queue;
30 /*Add sem for sync AER handling and xen_pcibk remove/reconfigue ops,
31 * We want to avoid in middle of AER ops, xen_pcibk devices is being removed
33 static DECLARE_RWSEM(pcistub_sem);
34 module_param_named(hide, pci_devs_to_hide, charp, 0444);
36 struct pcistub_device_id {
37 struct list_head slot_list;
38 int domain;
39 unsigned char bus;
40 unsigned int devfn;
42 static LIST_HEAD(pcistub_device_ids);
43 static DEFINE_SPINLOCK(device_ids_lock);
45 struct pcistub_device {
46 struct kref kref;
47 struct list_head dev_list;
48 spinlock_t lock;
50 struct pci_dev *dev;
51 struct xen_pcibk_device *pdev;/* non-NULL if struct pci_dev is in use */
54 /* Access to pcistub_devices & seized_devices lists and the initialize_devices
55 * flag must be locked with pcistub_devices_lock
57 static DEFINE_SPINLOCK(pcistub_devices_lock);
58 static LIST_HEAD(pcistub_devices);
60 /* wait for device_initcall before initializing our devices
61 * (see pcistub_init_devices_late)
63 static int initialize_devices;
64 static LIST_HEAD(seized_devices);
66 static struct pcistub_device *pcistub_device_alloc(struct pci_dev *dev)
68 struct pcistub_device *psdev;
70 dev_dbg(&dev->dev, "pcistub_device_alloc\n");
72 psdev = kzalloc(sizeof(*psdev), GFP_ATOMIC);
73 if (!psdev)
74 return NULL;
76 psdev->dev = pci_dev_get(dev);
77 if (!psdev->dev) {
78 kfree(psdev);
79 return NULL;
82 kref_init(&psdev->kref);
83 spin_lock_init(&psdev->lock);
85 return psdev;
88 /* Don't call this directly as it's called by pcistub_device_put */
89 static void pcistub_device_release(struct kref *kref)
91 struct pcistub_device *psdev;
92 struct pci_dev *dev;
93 struct xen_pcibk_dev_data *dev_data;
95 psdev = container_of(kref, struct pcistub_device, kref);
96 dev = psdev->dev;
97 dev_data = pci_get_drvdata(dev);
99 dev_dbg(&dev->dev, "pcistub_device_release\n");
101 xen_unregister_device_domain_owner(dev);
103 /* Call the reset function which does not take lock as this
104 * is called from "unbind" which takes a device_lock mutex.
106 __pci_reset_function_locked(dev);
107 if (pci_load_and_free_saved_state(dev, &dev_data->pci_saved_state))
108 dev_dbg(&dev->dev, "Could not reload PCI state\n");
109 else
110 pci_restore_state(dev);
112 if (dev->msix_cap) {
113 struct physdev_pci_device ppdev = {
114 .seg = pci_domain_nr(dev->bus),
115 .bus = dev->bus->number,
116 .devfn = dev->devfn
118 int err = HYPERVISOR_physdev_op(PHYSDEVOP_release_msix,
119 &ppdev);
121 if (err)
122 dev_warn(&dev->dev, "MSI-X release failed (%d)\n",
123 err);
126 /* Disable the device */
127 xen_pcibk_reset_device(dev);
129 kfree(dev_data);
130 pci_set_drvdata(dev, NULL);
132 /* Clean-up the device */
133 xen_pcibk_config_free_dyn_fields(dev);
134 xen_pcibk_config_free_dev(dev);
136 dev->dev_flags &= ~PCI_DEV_FLAGS_ASSIGNED;
137 pci_dev_put(dev);
139 kfree(psdev);
142 static inline void pcistub_device_get(struct pcistub_device *psdev)
144 kref_get(&psdev->kref);
147 static inline void pcistub_device_put(struct pcistub_device *psdev)
149 kref_put(&psdev->kref, pcistub_device_release);
152 static struct pcistub_device *pcistub_device_find(int domain, int bus,
153 int slot, int func)
155 struct pcistub_device *psdev = NULL;
156 unsigned long flags;
158 spin_lock_irqsave(&pcistub_devices_lock, flags);
160 list_for_each_entry(psdev, &pcistub_devices, dev_list) {
161 if (psdev->dev != NULL
162 && domain == pci_domain_nr(psdev->dev->bus)
163 && bus == psdev->dev->bus->number
164 && slot == PCI_SLOT(psdev->dev->devfn)
165 && func == PCI_FUNC(psdev->dev->devfn)) {
166 pcistub_device_get(psdev);
167 goto out;
171 /* didn't find it */
172 psdev = NULL;
174 out:
175 spin_unlock_irqrestore(&pcistub_devices_lock, flags);
176 return psdev;
179 static struct pci_dev *pcistub_device_get_pci_dev(struct xen_pcibk_device *pdev,
180 struct pcistub_device *psdev)
182 struct pci_dev *pci_dev = NULL;
183 unsigned long flags;
185 pcistub_device_get(psdev);
187 spin_lock_irqsave(&psdev->lock, flags);
188 if (!psdev->pdev) {
189 psdev->pdev = pdev;
190 pci_dev = psdev->dev;
192 spin_unlock_irqrestore(&psdev->lock, flags);
194 if (!pci_dev)
195 pcistub_device_put(psdev);
197 return pci_dev;
200 struct pci_dev *pcistub_get_pci_dev_by_slot(struct xen_pcibk_device *pdev,
201 int domain, int bus,
202 int slot, int func)
204 struct pcistub_device *psdev;
205 struct pci_dev *found_dev = NULL;
206 unsigned long flags;
208 spin_lock_irqsave(&pcistub_devices_lock, flags);
210 list_for_each_entry(psdev, &pcistub_devices, dev_list) {
211 if (psdev->dev != NULL
212 && domain == pci_domain_nr(psdev->dev->bus)
213 && bus == psdev->dev->bus->number
214 && slot == PCI_SLOT(psdev->dev->devfn)
215 && func == PCI_FUNC(psdev->dev->devfn)) {
216 found_dev = pcistub_device_get_pci_dev(pdev, psdev);
217 break;
221 spin_unlock_irqrestore(&pcistub_devices_lock, flags);
222 return found_dev;
225 struct pci_dev *pcistub_get_pci_dev(struct xen_pcibk_device *pdev,
226 struct pci_dev *dev)
228 struct pcistub_device *psdev;
229 struct pci_dev *found_dev = NULL;
230 unsigned long flags;
232 spin_lock_irqsave(&pcistub_devices_lock, flags);
234 list_for_each_entry(psdev, &pcistub_devices, dev_list) {
235 if (psdev->dev == dev) {
236 found_dev = pcistub_device_get_pci_dev(pdev, psdev);
237 break;
241 spin_unlock_irqrestore(&pcistub_devices_lock, flags);
242 return found_dev;
246 * Called when:
247 * - XenBus state has been reconfigure (pci unplug). See xen_pcibk_remove_device
248 * - XenBus state has been disconnected (guest shutdown). See xen_pcibk_xenbus_remove
249 * - 'echo BDF > unbind' on pciback module with no guest attached. See pcistub_remove
250 * - 'echo BDF > unbind' with a guest still using it. See pcistub_remove
252 * As such we have to be careful.
254 void pcistub_put_pci_dev(struct pci_dev *dev)
256 struct pcistub_device *psdev, *found_psdev = NULL;
257 unsigned long flags;
259 spin_lock_irqsave(&pcistub_devices_lock, flags);
261 list_for_each_entry(psdev, &pcistub_devices, dev_list) {
262 if (psdev->dev == dev) {
263 found_psdev = psdev;
264 break;
268 spin_unlock_irqrestore(&pcistub_devices_lock, flags);
269 if (WARN_ON(!found_psdev))
270 return;
272 /*hold this lock for avoiding breaking link between
273 * pcistub and xen_pcibk when AER is in processing
275 down_write(&pcistub_sem);
276 /* Cleanup our device
277 * (so it's ready for the next domain)
280 /* This is OK - we are running from workqueue context
281 * and want to inhibit the user from fiddling with 'reset'
283 pci_reset_function(dev);
284 pci_restore_state(dev);
286 /* This disables the device. */
287 xen_pcibk_reset_device(dev);
289 /* And cleanup up our emulated fields. */
290 xen_pcibk_config_reset_dev(dev);
291 xen_pcibk_config_free_dyn_fields(dev);
293 xen_unregister_device_domain_owner(dev);
295 spin_lock_irqsave(&found_psdev->lock, flags);
296 found_psdev->pdev = NULL;
297 spin_unlock_irqrestore(&found_psdev->lock, flags);
299 pcistub_device_put(found_psdev);
300 up_write(&pcistub_sem);
303 static int pcistub_match_one(struct pci_dev *dev,
304 struct pcistub_device_id *pdev_id)
306 /* Match the specified device by domain, bus, slot, func and also if
307 * any of the device's parent bridges match.
309 for (; dev != NULL; dev = dev->bus->self) {
310 if (pci_domain_nr(dev->bus) == pdev_id->domain
311 && dev->bus->number == pdev_id->bus
312 && dev->devfn == pdev_id->devfn)
313 return 1;
315 /* Sometimes topmost bridge links to itself. */
316 if (dev == dev->bus->self)
317 break;
320 return 0;
323 static int pcistub_match(struct pci_dev *dev)
325 struct pcistub_device_id *pdev_id;
326 unsigned long flags;
327 int found = 0;
329 spin_lock_irqsave(&device_ids_lock, flags);
330 list_for_each_entry(pdev_id, &pcistub_device_ids, slot_list) {
331 if (pcistub_match_one(dev, pdev_id)) {
332 found = 1;
333 break;
336 spin_unlock_irqrestore(&device_ids_lock, flags);
338 return found;
341 static int pcistub_init_device(struct pci_dev *dev)
343 struct xen_pcibk_dev_data *dev_data;
344 int err = 0;
346 dev_dbg(&dev->dev, "initializing...\n");
348 /* The PCI backend is not intended to be a module (or to work with
349 * removable PCI devices (yet). If it were, xen_pcibk_config_free()
350 * would need to be called somewhere to free the memory allocated
351 * here and then to call kfree(pci_get_drvdata(psdev->dev)).
353 dev_data = kzalloc(sizeof(*dev_data) + strlen(DRV_NAME "[]")
354 + strlen(pci_name(dev)) + 1, GFP_ATOMIC);
355 if (!dev_data) {
356 err = -ENOMEM;
357 goto out;
359 pci_set_drvdata(dev, dev_data);
362 * Setup name for fake IRQ handler. It will only be enabled
363 * once the device is turned on by the guest.
365 sprintf(dev_data->irq_name, DRV_NAME "[%s]", pci_name(dev));
367 dev_dbg(&dev->dev, "initializing config\n");
369 init_waitqueue_head(&xen_pcibk_aer_wait_queue);
370 err = xen_pcibk_config_init_dev(dev);
371 if (err)
372 goto out;
374 /* HACK: Force device (& ACPI) to determine what IRQ it's on - we
375 * must do this here because pcibios_enable_device may specify
376 * the pci device's true irq (and possibly its other resources)
377 * if they differ from what's in the configuration space.
378 * This makes the assumption that the device's resources won't
379 * change after this point (otherwise this code may break!)
381 dev_dbg(&dev->dev, "enabling device\n");
382 err = pci_enable_device(dev);
383 if (err)
384 goto config_release;
386 if (dev->msix_cap) {
387 struct physdev_pci_device ppdev = {
388 .seg = pci_domain_nr(dev->bus),
389 .bus = dev->bus->number,
390 .devfn = dev->devfn
393 err = HYPERVISOR_physdev_op(PHYSDEVOP_prepare_msix, &ppdev);
394 if (err)
395 dev_err(&dev->dev, "MSI-X preparation failed (%d)\n",
396 err);
399 /* We need the device active to save the state. */
400 dev_dbg(&dev->dev, "save state of device\n");
401 pci_save_state(dev);
402 dev_data->pci_saved_state = pci_store_saved_state(dev);
403 if (!dev_data->pci_saved_state)
404 dev_err(&dev->dev, "Could not store PCI conf saved state!\n");
405 else {
406 dev_dbg(&dev->dev, "resetting (FLR, D3, etc) the device\n");
407 __pci_reset_function_locked(dev);
408 pci_restore_state(dev);
410 /* Now disable the device (this also ensures some private device
411 * data is setup before we export)
413 dev_dbg(&dev->dev, "reset device\n");
414 xen_pcibk_reset_device(dev);
416 dev->dev_flags |= PCI_DEV_FLAGS_ASSIGNED;
417 return 0;
419 config_release:
420 xen_pcibk_config_free_dev(dev);
422 out:
423 pci_set_drvdata(dev, NULL);
424 kfree(dev_data);
425 return err;
429 * Because some initialization still happens on
430 * devices during fs_initcall, we need to defer
431 * full initialization of our devices until
432 * device_initcall.
434 static int __init pcistub_init_devices_late(void)
436 struct pcistub_device *psdev;
437 unsigned long flags;
438 int err = 0;
440 spin_lock_irqsave(&pcistub_devices_lock, flags);
442 while (!list_empty(&seized_devices)) {
443 psdev = container_of(seized_devices.next,
444 struct pcistub_device, dev_list);
445 list_del(&psdev->dev_list);
447 spin_unlock_irqrestore(&pcistub_devices_lock, flags);
449 err = pcistub_init_device(psdev->dev);
450 if (err) {
451 dev_err(&psdev->dev->dev,
452 "error %d initializing device\n", err);
453 kfree(psdev);
454 psdev = NULL;
457 spin_lock_irqsave(&pcistub_devices_lock, flags);
459 if (psdev)
460 list_add_tail(&psdev->dev_list, &pcistub_devices);
463 initialize_devices = 1;
465 spin_unlock_irqrestore(&pcistub_devices_lock, flags);
467 return 0;
470 static int pcistub_seize(struct pci_dev *dev)
472 struct pcistub_device *psdev;
473 unsigned long flags;
474 int err = 0;
476 psdev = pcistub_device_alloc(dev);
477 if (!psdev)
478 return -ENOMEM;
480 spin_lock_irqsave(&pcistub_devices_lock, flags);
482 if (initialize_devices) {
483 spin_unlock_irqrestore(&pcistub_devices_lock, flags);
485 /* don't want irqs disabled when calling pcistub_init_device */
486 err = pcistub_init_device(psdev->dev);
488 spin_lock_irqsave(&pcistub_devices_lock, flags);
490 if (!err)
491 list_add(&psdev->dev_list, &pcistub_devices);
492 } else {
493 dev_dbg(&dev->dev, "deferring initialization\n");
494 list_add(&psdev->dev_list, &seized_devices);
497 spin_unlock_irqrestore(&pcistub_devices_lock, flags);
499 if (err)
500 pcistub_device_put(psdev);
502 return err;
505 /* Called when 'bind'. This means we must _NOT_ call pci_reset_function or
506 * other functions that take the sysfs lock. */
507 static int pcistub_probe(struct pci_dev *dev, const struct pci_device_id *id)
509 int err = 0;
511 dev_dbg(&dev->dev, "probing...\n");
513 if (pcistub_match(dev)) {
515 if (dev->hdr_type != PCI_HEADER_TYPE_NORMAL
516 && dev->hdr_type != PCI_HEADER_TYPE_BRIDGE) {
517 dev_err(&dev->dev, "can't export pci devices that "
518 "don't have a normal (0) or bridge (1) "
519 "header type!\n");
520 err = -ENODEV;
521 goto out;
524 dev_info(&dev->dev, "seizing device\n");
525 err = pcistub_seize(dev);
526 } else
527 /* Didn't find the device */
528 err = -ENODEV;
530 out:
531 return err;
534 /* Called when 'unbind'. This means we must _NOT_ call pci_reset_function or
535 * other functions that take the sysfs lock. */
536 static void pcistub_remove(struct pci_dev *dev)
538 struct pcistub_device *psdev, *found_psdev = NULL;
539 unsigned long flags;
541 dev_dbg(&dev->dev, "removing\n");
543 spin_lock_irqsave(&pcistub_devices_lock, flags);
545 xen_pcibk_config_quirk_release(dev);
547 list_for_each_entry(psdev, &pcistub_devices, dev_list) {
548 if (psdev->dev == dev) {
549 found_psdev = psdev;
550 break;
554 spin_unlock_irqrestore(&pcistub_devices_lock, flags);
556 if (found_psdev) {
557 dev_dbg(&dev->dev, "found device to remove - in use? %p\n",
558 found_psdev->pdev);
560 if (found_psdev->pdev) {
561 pr_warn("****** removing device %s while still in-use! ******\n",
562 pci_name(found_psdev->dev));
563 pr_warn("****** driver domain may still access this device's i/o resources!\n");
564 pr_warn("****** shutdown driver domain before binding device\n");
565 pr_warn("****** to other drivers or domains\n");
567 /* N.B. This ends up calling pcistub_put_pci_dev which ends up
568 * doing the FLR. */
569 xen_pcibk_release_pci_dev(found_psdev->pdev,
570 found_psdev->dev);
573 spin_lock_irqsave(&pcistub_devices_lock, flags);
574 list_del(&found_psdev->dev_list);
575 spin_unlock_irqrestore(&pcistub_devices_lock, flags);
577 /* the final put for releasing from the list */
578 pcistub_device_put(found_psdev);
582 static DEFINE_PCI_DEVICE_TABLE(pcistub_ids) = {
584 .vendor = PCI_ANY_ID,
585 .device = PCI_ANY_ID,
586 .subvendor = PCI_ANY_ID,
587 .subdevice = PCI_ANY_ID,
589 {0,},
592 #define PCI_NODENAME_MAX 40
593 static void kill_domain_by_device(struct pcistub_device *psdev)
595 struct xenbus_transaction xbt;
596 int err;
597 char nodename[PCI_NODENAME_MAX];
599 BUG_ON(!psdev);
600 snprintf(nodename, PCI_NODENAME_MAX, "/local/domain/0/backend/pci/%d/0",
601 psdev->pdev->xdev->otherend_id);
603 again:
604 err = xenbus_transaction_start(&xbt);
605 if (err) {
606 dev_err(&psdev->dev->dev,
607 "error %d when start xenbus transaction\n", err);
608 return;
610 /*PV AER handlers will set this flag*/
611 xenbus_printf(xbt, nodename, "aerState" , "aerfail");
612 err = xenbus_transaction_end(xbt, 0);
613 if (err) {
614 if (err == -EAGAIN)
615 goto again;
616 dev_err(&psdev->dev->dev,
617 "error %d when end xenbus transaction\n", err);
618 return;
622 /* For each aer recovery step error_detected, mmio_enabled, etc, front_end and
623 * backend need to have cooperation. In xen_pcibk, those steps will do similar
624 * jobs: send service request and waiting for front_end response.
626 static pci_ers_result_t common_process(struct pcistub_device *psdev,
627 pci_channel_state_t state, int aer_cmd,
628 pci_ers_result_t result)
630 pci_ers_result_t res = result;
631 struct xen_pcie_aer_op *aer_op;
632 int ret;
634 /*with PV AER drivers*/
635 aer_op = &(psdev->pdev->sh_info->aer_op);
636 aer_op->cmd = aer_cmd ;
637 /*useful for error_detected callback*/
638 aer_op->err = state;
639 /*pcifront_end BDF*/
640 ret = xen_pcibk_get_pcifront_dev(psdev->dev, psdev->pdev,
641 &aer_op->domain, &aer_op->bus, &aer_op->devfn);
642 if (!ret) {
643 dev_err(&psdev->dev->dev,
644 DRV_NAME ": failed to get pcifront device\n");
645 return PCI_ERS_RESULT_NONE;
647 wmb();
649 dev_dbg(&psdev->dev->dev,
650 DRV_NAME ": aer_op %x dom %x bus %x devfn %x\n",
651 aer_cmd, aer_op->domain, aer_op->bus, aer_op->devfn);
652 /*local flag to mark there's aer request, xen_pcibk callback will use
653 * this flag to judge whether we need to check pci-front give aer
654 * service ack signal
656 set_bit(_PCIB_op_pending, (unsigned long *)&psdev->pdev->flags);
658 /*It is possible that a pcifront conf_read_write ops request invokes
659 * the callback which cause the spurious execution of wake_up.
660 * Yet it is harmless and better than a spinlock here
662 set_bit(_XEN_PCIB_active,
663 (unsigned long *)&psdev->pdev->sh_info->flags);
664 wmb();
665 notify_remote_via_irq(psdev->pdev->evtchn_irq);
667 ret = wait_event_timeout(xen_pcibk_aer_wait_queue,
668 !(test_bit(_XEN_PCIB_active, (unsigned long *)
669 &psdev->pdev->sh_info->flags)), 300*HZ);
671 if (!ret) {
672 if (test_bit(_XEN_PCIB_active,
673 (unsigned long *)&psdev->pdev->sh_info->flags)) {
674 dev_err(&psdev->dev->dev,
675 "pcifront aer process not responding!\n");
676 clear_bit(_XEN_PCIB_active,
677 (unsigned long *)&psdev->pdev->sh_info->flags);
678 aer_op->err = PCI_ERS_RESULT_NONE;
679 return res;
682 clear_bit(_PCIB_op_pending, (unsigned long *)&psdev->pdev->flags);
684 if (test_bit(_XEN_PCIF_active,
685 (unsigned long *)&psdev->pdev->sh_info->flags)) {
686 dev_dbg(&psdev->dev->dev,
687 "schedule pci_conf service in " DRV_NAME "\n");
688 xen_pcibk_test_and_schedule_op(psdev->pdev);
691 res = (pci_ers_result_t)aer_op->err;
692 return res;
696 * xen_pcibk_slot_reset: it will send the slot_reset request to pcifront in case
697 * of the device driver could provide this service, and then wait for pcifront
698 * ack.
699 * @dev: pointer to PCI devices
700 * return value is used by aer_core do_recovery policy
702 static pci_ers_result_t xen_pcibk_slot_reset(struct pci_dev *dev)
704 struct pcistub_device *psdev;
705 pci_ers_result_t result;
707 result = PCI_ERS_RESULT_RECOVERED;
708 dev_dbg(&dev->dev, "xen_pcibk_slot_reset(bus:%x,devfn:%x)\n",
709 dev->bus->number, dev->devfn);
711 down_write(&pcistub_sem);
712 psdev = pcistub_device_find(pci_domain_nr(dev->bus),
713 dev->bus->number,
714 PCI_SLOT(dev->devfn),
715 PCI_FUNC(dev->devfn));
717 if (!psdev || !psdev->pdev) {
718 dev_err(&dev->dev,
719 DRV_NAME " device is not found/assigned\n");
720 goto end;
723 if (!psdev->pdev->sh_info) {
724 dev_err(&dev->dev, DRV_NAME " device is not connected or owned"
725 " by HVM, kill it\n");
726 kill_domain_by_device(psdev);
727 goto end;
730 if (!test_bit(_XEN_PCIB_AERHANDLER,
731 (unsigned long *)&psdev->pdev->sh_info->flags)) {
732 dev_err(&dev->dev,
733 "guest with no AER driver should have been killed\n");
734 goto end;
736 result = common_process(psdev, 1, XEN_PCI_OP_aer_slotreset, result);
738 if (result == PCI_ERS_RESULT_NONE ||
739 result == PCI_ERS_RESULT_DISCONNECT) {
740 dev_dbg(&dev->dev,
741 "No AER slot_reset service or disconnected!\n");
742 kill_domain_by_device(psdev);
744 end:
745 if (psdev)
746 pcistub_device_put(psdev);
747 up_write(&pcistub_sem);
748 return result;
753 /*xen_pcibk_mmio_enabled: it will send the mmio_enabled request to pcifront
754 * in case of the device driver could provide this service, and then wait
755 * for pcifront ack
756 * @dev: pointer to PCI devices
757 * return value is used by aer_core do_recovery policy
760 static pci_ers_result_t xen_pcibk_mmio_enabled(struct pci_dev *dev)
762 struct pcistub_device *psdev;
763 pci_ers_result_t result;
765 result = PCI_ERS_RESULT_RECOVERED;
766 dev_dbg(&dev->dev, "xen_pcibk_mmio_enabled(bus:%x,devfn:%x)\n",
767 dev->bus->number, dev->devfn);
769 down_write(&pcistub_sem);
770 psdev = pcistub_device_find(pci_domain_nr(dev->bus),
771 dev->bus->number,
772 PCI_SLOT(dev->devfn),
773 PCI_FUNC(dev->devfn));
775 if (!psdev || !psdev->pdev) {
776 dev_err(&dev->dev,
777 DRV_NAME " device is not found/assigned\n");
778 goto end;
781 if (!psdev->pdev->sh_info) {
782 dev_err(&dev->dev, DRV_NAME " device is not connected or owned"
783 " by HVM, kill it\n");
784 kill_domain_by_device(psdev);
785 goto end;
788 if (!test_bit(_XEN_PCIB_AERHANDLER,
789 (unsigned long *)&psdev->pdev->sh_info->flags)) {
790 dev_err(&dev->dev,
791 "guest with no AER driver should have been killed\n");
792 goto end;
794 result = common_process(psdev, 1, XEN_PCI_OP_aer_mmio, result);
796 if (result == PCI_ERS_RESULT_NONE ||
797 result == PCI_ERS_RESULT_DISCONNECT) {
798 dev_dbg(&dev->dev,
799 "No AER mmio_enabled service or disconnected!\n");
800 kill_domain_by_device(psdev);
802 end:
803 if (psdev)
804 pcistub_device_put(psdev);
805 up_write(&pcistub_sem);
806 return result;
809 /*xen_pcibk_error_detected: it will send the error_detected request to pcifront
810 * in case of the device driver could provide this service, and then wait
811 * for pcifront ack.
812 * @dev: pointer to PCI devices
813 * @error: the current PCI connection state
814 * return value is used by aer_core do_recovery policy
817 static pci_ers_result_t xen_pcibk_error_detected(struct pci_dev *dev,
818 pci_channel_state_t error)
820 struct pcistub_device *psdev;
821 pci_ers_result_t result;
823 result = PCI_ERS_RESULT_CAN_RECOVER;
824 dev_dbg(&dev->dev, "xen_pcibk_error_detected(bus:%x,devfn:%x)\n",
825 dev->bus->number, dev->devfn);
827 down_write(&pcistub_sem);
828 psdev = pcistub_device_find(pci_domain_nr(dev->bus),
829 dev->bus->number,
830 PCI_SLOT(dev->devfn),
831 PCI_FUNC(dev->devfn));
833 if (!psdev || !psdev->pdev) {
834 dev_err(&dev->dev,
835 DRV_NAME " device is not found/assigned\n");
836 goto end;
839 if (!psdev->pdev->sh_info) {
840 dev_err(&dev->dev, DRV_NAME " device is not connected or owned"
841 " by HVM, kill it\n");
842 kill_domain_by_device(psdev);
843 goto end;
846 /*Guest owns the device yet no aer handler regiested, kill guest*/
847 if (!test_bit(_XEN_PCIB_AERHANDLER,
848 (unsigned long *)&psdev->pdev->sh_info->flags)) {
849 dev_dbg(&dev->dev, "guest may have no aer driver, kill it\n");
850 kill_domain_by_device(psdev);
851 goto end;
853 result = common_process(psdev, error, XEN_PCI_OP_aer_detected, result);
855 if (result == PCI_ERS_RESULT_NONE ||
856 result == PCI_ERS_RESULT_DISCONNECT) {
857 dev_dbg(&dev->dev,
858 "No AER error_detected service or disconnected!\n");
859 kill_domain_by_device(psdev);
861 end:
862 if (psdev)
863 pcistub_device_put(psdev);
864 up_write(&pcistub_sem);
865 return result;
868 /*xen_pcibk_error_resume: it will send the error_resume request to pcifront
869 * in case of the device driver could provide this service, and then wait
870 * for pcifront ack.
871 * @dev: pointer to PCI devices
874 static void xen_pcibk_error_resume(struct pci_dev *dev)
876 struct pcistub_device *psdev;
878 dev_dbg(&dev->dev, "xen_pcibk_error_resume(bus:%x,devfn:%x)\n",
879 dev->bus->number, dev->devfn);
881 down_write(&pcistub_sem);
882 psdev = pcistub_device_find(pci_domain_nr(dev->bus),
883 dev->bus->number,
884 PCI_SLOT(dev->devfn),
885 PCI_FUNC(dev->devfn));
887 if (!psdev || !psdev->pdev) {
888 dev_err(&dev->dev,
889 DRV_NAME " device is not found/assigned\n");
890 goto end;
893 if (!psdev->pdev->sh_info) {
894 dev_err(&dev->dev, DRV_NAME " device is not connected or owned"
895 " by HVM, kill it\n");
896 kill_domain_by_device(psdev);
897 goto end;
900 if (!test_bit(_XEN_PCIB_AERHANDLER,
901 (unsigned long *)&psdev->pdev->sh_info->flags)) {
902 dev_err(&dev->dev,
903 "guest with no AER driver should have been killed\n");
904 kill_domain_by_device(psdev);
905 goto end;
907 common_process(psdev, 1, XEN_PCI_OP_aer_resume,
908 PCI_ERS_RESULT_RECOVERED);
909 end:
910 if (psdev)
911 pcistub_device_put(psdev);
912 up_write(&pcistub_sem);
913 return;
916 /*add xen_pcibk AER handling*/
917 static const struct pci_error_handlers xen_pcibk_error_handler = {
918 .error_detected = xen_pcibk_error_detected,
919 .mmio_enabled = xen_pcibk_mmio_enabled,
920 .slot_reset = xen_pcibk_slot_reset,
921 .resume = xen_pcibk_error_resume,
925 * Note: There is no MODULE_DEVICE_TABLE entry here because this isn't
926 * for a normal device. I don't want it to be loaded automatically.
929 static struct pci_driver xen_pcibk_pci_driver = {
930 /* The name should be xen_pciback, but until the tools are updated
931 * we will keep it as pciback. */
932 .name = "pciback",
933 .id_table = pcistub_ids,
934 .probe = pcistub_probe,
935 .remove = pcistub_remove,
936 .err_handler = &xen_pcibk_error_handler,
939 static inline int str_to_slot(const char *buf, int *domain, int *bus,
940 int *slot, int *func)
942 int parsed = 0;
944 switch (sscanf(buf, " %x:%x:%x.%x %n", domain, bus, slot, func,
945 &parsed)) {
946 case 3:
947 *func = -1;
948 sscanf(buf, " %x:%x:%x.* %n", domain, bus, slot, &parsed);
949 break;
950 case 2:
951 *slot = *func = -1;
952 sscanf(buf, " %x:%x:*.* %n", domain, bus, &parsed);
953 break;
955 if (parsed && !buf[parsed])
956 return 0;
958 /* try again without domain */
959 *domain = 0;
960 switch (sscanf(buf, " %x:%x.%x %n", bus, slot, func, &parsed)) {
961 case 2:
962 *func = -1;
963 sscanf(buf, " %x:%x.* %n", bus, slot, &parsed);
964 break;
965 case 1:
966 *slot = *func = -1;
967 sscanf(buf, " %x:*.* %n", bus, &parsed);
968 break;
970 if (parsed && !buf[parsed])
971 return 0;
973 return -EINVAL;
976 static inline int str_to_quirk(const char *buf, int *domain, int *bus, int
977 *slot, int *func, int *reg, int *size, int *mask)
979 int parsed = 0;
981 sscanf(buf, " %x:%x:%x.%x-%x:%x:%x %n", domain, bus, slot, func,
982 reg, size, mask, &parsed);
983 if (parsed && !buf[parsed])
984 return 0;
986 /* try again without domain */
987 *domain = 0;
988 sscanf(buf, " %x:%x.%x-%x:%x:%x %n", bus, slot, func, reg, size,
989 mask, &parsed);
990 if (parsed && !buf[parsed])
991 return 0;
993 return -EINVAL;
996 static int pcistub_device_id_add(int domain, int bus, int slot, int func)
998 struct pcistub_device_id *pci_dev_id;
999 unsigned long flags;
1000 int rc = 0, devfn = PCI_DEVFN(slot, func);
1002 if (slot < 0) {
1003 for (slot = 0; !rc && slot < 32; ++slot)
1004 rc = pcistub_device_id_add(domain, bus, slot, func);
1005 return rc;
1008 if (func < 0) {
1009 for (func = 0; !rc && func < 8; ++func)
1010 rc = pcistub_device_id_add(domain, bus, slot, func);
1011 return rc;
1014 if ((
1015 #if !defined(MODULE) /* pci_domains_supported is not being exported */ \
1016 || !defined(CONFIG_PCI_DOMAINS)
1017 !pci_domains_supported ? domain :
1018 #endif
1019 domain < 0 || domain > 0xffff)
1020 || bus < 0 || bus > 0xff
1021 || PCI_SLOT(devfn) != slot
1022 || PCI_FUNC(devfn) != func)
1023 return -EINVAL;
1025 pci_dev_id = kmalloc(sizeof(*pci_dev_id), GFP_KERNEL);
1026 if (!pci_dev_id)
1027 return -ENOMEM;
1029 pci_dev_id->domain = domain;
1030 pci_dev_id->bus = bus;
1031 pci_dev_id->devfn = devfn;
1033 pr_debug("wants to seize %04x:%02x:%02x.%d\n",
1034 domain, bus, slot, func);
1036 spin_lock_irqsave(&device_ids_lock, flags);
1037 list_add_tail(&pci_dev_id->slot_list, &pcistub_device_ids);
1038 spin_unlock_irqrestore(&device_ids_lock, flags);
1040 return 0;
1043 static int pcistub_device_id_remove(int domain, int bus, int slot, int func)
1045 struct pcistub_device_id *pci_dev_id, *t;
1046 int err = -ENOENT;
1047 unsigned long flags;
1049 spin_lock_irqsave(&device_ids_lock, flags);
1050 list_for_each_entry_safe(pci_dev_id, t, &pcistub_device_ids,
1051 slot_list) {
1052 if (pci_dev_id->domain == domain && pci_dev_id->bus == bus
1053 && (slot < 0 || PCI_SLOT(pci_dev_id->devfn) == slot)
1054 && (func < 0 || PCI_FUNC(pci_dev_id->devfn) == func)) {
1055 /* Don't break; here because it's possible the same
1056 * slot could be in the list more than once
1058 list_del(&pci_dev_id->slot_list);
1059 kfree(pci_dev_id);
1061 err = 0;
1063 pr_debug("removed %04x:%02x:%02x.%d from seize list\n",
1064 domain, bus, slot, func);
1067 spin_unlock_irqrestore(&device_ids_lock, flags);
1069 return err;
1072 static int pcistub_reg_add(int domain, int bus, int slot, int func,
1073 unsigned int reg, unsigned int size,
1074 unsigned int mask)
1076 int err = 0;
1077 struct pcistub_device *psdev;
1078 struct pci_dev *dev;
1079 struct config_field *field;
1081 if (reg > 0xfff || (size < 4 && (mask >> (size * 8))))
1082 return -EINVAL;
1084 psdev = pcistub_device_find(domain, bus, slot, func);
1085 if (!psdev) {
1086 err = -ENODEV;
1087 goto out;
1089 dev = psdev->dev;
1091 field = kzalloc(sizeof(*field), GFP_ATOMIC);
1092 if (!field) {
1093 err = -ENOMEM;
1094 goto out;
1097 field->offset = reg;
1098 field->size = size;
1099 field->mask = mask;
1100 field->init = NULL;
1101 field->reset = NULL;
1102 field->release = NULL;
1103 field->clean = xen_pcibk_config_field_free;
1105 err = xen_pcibk_config_quirks_add_field(dev, field);
1106 if (err)
1107 kfree(field);
1108 out:
1109 if (psdev)
1110 pcistub_device_put(psdev);
1111 return err;
1114 static ssize_t pcistub_slot_add(struct device_driver *drv, const char *buf,
1115 size_t count)
1117 int domain, bus, slot, func;
1118 int err;
1120 err = str_to_slot(buf, &domain, &bus, &slot, &func);
1121 if (err)
1122 goto out;
1124 err = pcistub_device_id_add(domain, bus, slot, func);
1126 out:
1127 if (!err)
1128 err = count;
1129 return err;
1131 static DRIVER_ATTR(new_slot, S_IWUSR, NULL, pcistub_slot_add);
1133 static ssize_t pcistub_slot_remove(struct device_driver *drv, const char *buf,
1134 size_t count)
1136 int domain, bus, slot, func;
1137 int err;
1139 err = str_to_slot(buf, &domain, &bus, &slot, &func);
1140 if (err)
1141 goto out;
1143 err = pcistub_device_id_remove(domain, bus, slot, func);
1145 out:
1146 if (!err)
1147 err = count;
1148 return err;
1150 static DRIVER_ATTR(remove_slot, S_IWUSR, NULL, pcistub_slot_remove);
1152 static ssize_t pcistub_slot_show(struct device_driver *drv, char *buf)
1154 struct pcistub_device_id *pci_dev_id;
1155 size_t count = 0;
1156 unsigned long flags;
1158 spin_lock_irqsave(&device_ids_lock, flags);
1159 list_for_each_entry(pci_dev_id, &pcistub_device_ids, slot_list) {
1160 if (count >= PAGE_SIZE)
1161 break;
1163 count += scnprintf(buf + count, PAGE_SIZE - count,
1164 "%04x:%02x:%02x.%d\n",
1165 pci_dev_id->domain, pci_dev_id->bus,
1166 PCI_SLOT(pci_dev_id->devfn),
1167 PCI_FUNC(pci_dev_id->devfn));
1169 spin_unlock_irqrestore(&device_ids_lock, flags);
1171 return count;
1173 static DRIVER_ATTR(slots, S_IRUSR, pcistub_slot_show, NULL);
1175 static ssize_t pcistub_irq_handler_show(struct device_driver *drv, char *buf)
1177 struct pcistub_device *psdev;
1178 struct xen_pcibk_dev_data *dev_data;
1179 size_t count = 0;
1180 unsigned long flags;
1182 spin_lock_irqsave(&pcistub_devices_lock, flags);
1183 list_for_each_entry(psdev, &pcistub_devices, dev_list) {
1184 if (count >= PAGE_SIZE)
1185 break;
1186 if (!psdev->dev)
1187 continue;
1188 dev_data = pci_get_drvdata(psdev->dev);
1189 if (!dev_data)
1190 continue;
1191 count +=
1192 scnprintf(buf + count, PAGE_SIZE - count,
1193 "%s:%s:%sing:%ld\n",
1194 pci_name(psdev->dev),
1195 dev_data->isr_on ? "on" : "off",
1196 dev_data->ack_intr ? "ack" : "not ack",
1197 dev_data->handled);
1199 spin_unlock_irqrestore(&pcistub_devices_lock, flags);
1200 return count;
1202 static DRIVER_ATTR(irq_handlers, S_IRUSR, pcistub_irq_handler_show, NULL);
1204 static ssize_t pcistub_irq_handler_switch(struct device_driver *drv,
1205 const char *buf,
1206 size_t count)
1208 struct pcistub_device *psdev;
1209 struct xen_pcibk_dev_data *dev_data;
1210 int domain, bus, slot, func;
1211 int err;
1213 err = str_to_slot(buf, &domain, &bus, &slot, &func);
1214 if (err)
1215 return err;
1217 psdev = pcistub_device_find(domain, bus, slot, func);
1218 if (!psdev) {
1219 err = -ENOENT;
1220 goto out;
1223 dev_data = pci_get_drvdata(psdev->dev);
1224 if (!dev_data) {
1225 err = -ENOENT;
1226 goto out;
1229 dev_dbg(&psdev->dev->dev, "%s fake irq handler: %d->%d\n",
1230 dev_data->irq_name, dev_data->isr_on,
1231 !dev_data->isr_on);
1233 dev_data->isr_on = !(dev_data->isr_on);
1234 if (dev_data->isr_on)
1235 dev_data->ack_intr = 1;
1236 out:
1237 if (psdev)
1238 pcistub_device_put(psdev);
1239 if (!err)
1240 err = count;
1241 return err;
1243 static DRIVER_ATTR(irq_handler_state, S_IWUSR, NULL,
1244 pcistub_irq_handler_switch);
1246 static ssize_t pcistub_quirk_add(struct device_driver *drv, const char *buf,
1247 size_t count)
1249 int domain, bus, slot, func, reg, size, mask;
1250 int err;
1252 err = str_to_quirk(buf, &domain, &bus, &slot, &func, &reg, &size,
1253 &mask);
1254 if (err)
1255 goto out;
1257 err = pcistub_reg_add(domain, bus, slot, func, reg, size, mask);
1259 out:
1260 if (!err)
1261 err = count;
1262 return err;
1265 static ssize_t pcistub_quirk_show(struct device_driver *drv, char *buf)
1267 int count = 0;
1268 unsigned long flags;
1269 struct xen_pcibk_config_quirk *quirk;
1270 struct xen_pcibk_dev_data *dev_data;
1271 const struct config_field *field;
1272 const struct config_field_entry *cfg_entry;
1274 spin_lock_irqsave(&device_ids_lock, flags);
1275 list_for_each_entry(quirk, &xen_pcibk_quirks, quirks_list) {
1276 if (count >= PAGE_SIZE)
1277 goto out;
1279 count += scnprintf(buf + count, PAGE_SIZE - count,
1280 "%02x:%02x.%01x\n\t%04x:%04x:%04x:%04x\n",
1281 quirk->pdev->bus->number,
1282 PCI_SLOT(quirk->pdev->devfn),
1283 PCI_FUNC(quirk->pdev->devfn),
1284 quirk->devid.vendor, quirk->devid.device,
1285 quirk->devid.subvendor,
1286 quirk->devid.subdevice);
1288 dev_data = pci_get_drvdata(quirk->pdev);
1290 list_for_each_entry(cfg_entry, &dev_data->config_fields, list) {
1291 field = cfg_entry->field;
1292 if (count >= PAGE_SIZE)
1293 goto out;
1295 count += scnprintf(buf + count, PAGE_SIZE - count,
1296 "\t\t%08x:%01x:%08x\n",
1297 cfg_entry->base_offset +
1298 field->offset, field->size,
1299 field->mask);
1303 out:
1304 spin_unlock_irqrestore(&device_ids_lock, flags);
1306 return count;
1308 static DRIVER_ATTR(quirks, S_IRUSR | S_IWUSR, pcistub_quirk_show,
1309 pcistub_quirk_add);
1311 static ssize_t permissive_add(struct device_driver *drv, const char *buf,
1312 size_t count)
1314 int domain, bus, slot, func;
1315 int err;
1316 struct pcistub_device *psdev;
1317 struct xen_pcibk_dev_data *dev_data;
1319 err = str_to_slot(buf, &domain, &bus, &slot, &func);
1320 if (err)
1321 goto out;
1323 psdev = pcistub_device_find(domain, bus, slot, func);
1324 if (!psdev) {
1325 err = -ENODEV;
1326 goto out;
1329 dev_data = pci_get_drvdata(psdev->dev);
1330 /* the driver data for a device should never be null at this point */
1331 if (!dev_data) {
1332 err = -ENXIO;
1333 goto release;
1335 if (!dev_data->permissive) {
1336 dev_data->permissive = 1;
1337 /* Let user know that what they're doing could be unsafe */
1338 dev_warn(&psdev->dev->dev, "enabling permissive mode "
1339 "configuration space accesses!\n");
1340 dev_warn(&psdev->dev->dev,
1341 "permissive mode is potentially unsafe!\n");
1343 release:
1344 pcistub_device_put(psdev);
1345 out:
1346 if (!err)
1347 err = count;
1348 return err;
1351 static ssize_t permissive_show(struct device_driver *drv, char *buf)
1353 struct pcistub_device *psdev;
1354 struct xen_pcibk_dev_data *dev_data;
1355 size_t count = 0;
1356 unsigned long flags;
1357 spin_lock_irqsave(&pcistub_devices_lock, flags);
1358 list_for_each_entry(psdev, &pcistub_devices, dev_list) {
1359 if (count >= PAGE_SIZE)
1360 break;
1361 if (!psdev->dev)
1362 continue;
1363 dev_data = pci_get_drvdata(psdev->dev);
1364 if (!dev_data || !dev_data->permissive)
1365 continue;
1366 count +=
1367 scnprintf(buf + count, PAGE_SIZE - count, "%s\n",
1368 pci_name(psdev->dev));
1370 spin_unlock_irqrestore(&pcistub_devices_lock, flags);
1371 return count;
1373 static DRIVER_ATTR(permissive, S_IRUSR | S_IWUSR, permissive_show,
1374 permissive_add);
1376 static void pcistub_exit(void)
1378 driver_remove_file(&xen_pcibk_pci_driver.driver, &driver_attr_new_slot);
1379 driver_remove_file(&xen_pcibk_pci_driver.driver,
1380 &driver_attr_remove_slot);
1381 driver_remove_file(&xen_pcibk_pci_driver.driver, &driver_attr_slots);
1382 driver_remove_file(&xen_pcibk_pci_driver.driver, &driver_attr_quirks);
1383 driver_remove_file(&xen_pcibk_pci_driver.driver,
1384 &driver_attr_permissive);
1385 driver_remove_file(&xen_pcibk_pci_driver.driver,
1386 &driver_attr_irq_handlers);
1387 driver_remove_file(&xen_pcibk_pci_driver.driver,
1388 &driver_attr_irq_handler_state);
1389 pci_unregister_driver(&xen_pcibk_pci_driver);
1392 static int __init pcistub_init(void)
1394 int pos = 0;
1395 int err = 0;
1396 int domain, bus, slot, func;
1397 int parsed;
1399 if (pci_devs_to_hide && *pci_devs_to_hide) {
1400 do {
1401 parsed = 0;
1403 err = sscanf(pci_devs_to_hide + pos,
1404 " (%x:%x:%x.%x) %n",
1405 &domain, &bus, &slot, &func, &parsed);
1406 switch (err) {
1407 case 3:
1408 func = -1;
1409 sscanf(pci_devs_to_hide + pos,
1410 " (%x:%x:%x.*) %n",
1411 &domain, &bus, &slot, &parsed);
1412 break;
1413 case 2:
1414 slot = func = -1;
1415 sscanf(pci_devs_to_hide + pos,
1416 " (%x:%x:*.*) %n",
1417 &domain, &bus, &parsed);
1418 break;
1421 if (!parsed) {
1422 domain = 0;
1423 err = sscanf(pci_devs_to_hide + pos,
1424 " (%x:%x.%x) %n",
1425 &bus, &slot, &func, &parsed);
1426 switch (err) {
1427 case 2:
1428 func = -1;
1429 sscanf(pci_devs_to_hide + pos,
1430 " (%x:%x.*) %n",
1431 &bus, &slot, &parsed);
1432 break;
1433 case 1:
1434 slot = func = -1;
1435 sscanf(pci_devs_to_hide + pos,
1436 " (%x:*.*) %n",
1437 &bus, &parsed);
1438 break;
1442 if (parsed <= 0)
1443 goto parse_error;
1445 err = pcistub_device_id_add(domain, bus, slot, func);
1446 if (err)
1447 goto out;
1449 pos += parsed;
1450 } while (pci_devs_to_hide[pos]);
1453 /* If we're the first PCI Device Driver to register, we're the
1454 * first one to get offered PCI devices as they become
1455 * available (and thus we can be the first to grab them)
1457 err = pci_register_driver(&xen_pcibk_pci_driver);
1458 if (err < 0)
1459 goto out;
1461 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1462 &driver_attr_new_slot);
1463 if (!err)
1464 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1465 &driver_attr_remove_slot);
1466 if (!err)
1467 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1468 &driver_attr_slots);
1469 if (!err)
1470 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1471 &driver_attr_quirks);
1472 if (!err)
1473 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1474 &driver_attr_permissive);
1476 if (!err)
1477 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1478 &driver_attr_irq_handlers);
1479 if (!err)
1480 err = driver_create_file(&xen_pcibk_pci_driver.driver,
1481 &driver_attr_irq_handler_state);
1482 if (err)
1483 pcistub_exit();
1485 out:
1486 return err;
1488 parse_error:
1489 pr_err("Error parsing pci_devs_to_hide at \"%s\"\n",
1490 pci_devs_to_hide + pos);
1491 return -EINVAL;
1494 #ifndef MODULE
1496 * fs_initcall happens before device_initcall
1497 * so xen_pcibk *should* get called first (b/c we
1498 * want to suck up any device before other drivers
1499 * get a chance by being the first pci device
1500 * driver to register)
1502 fs_initcall(pcistub_init);
1503 #endif
1505 static int __init xen_pcibk_init(void)
1507 int err;
1509 if (!xen_initial_domain())
1510 return -ENODEV;
1512 err = xen_pcibk_config_init();
1513 if (err)
1514 return err;
1516 #ifdef MODULE
1517 err = pcistub_init();
1518 if (err < 0)
1519 return err;
1520 #endif
1522 pcistub_init_devices_late();
1523 err = xen_pcibk_xenbus_register();
1524 if (err)
1525 pcistub_exit();
1527 return err;
1530 static void __exit xen_pcibk_cleanup(void)
1532 xen_pcibk_xenbus_unregister();
1533 pcistub_exit();
1536 module_init(xen_pcibk_init);
1537 module_exit(xen_pcibk_cleanup);
1539 MODULE_LICENSE("Dual BSD/GPL");
1540 MODULE_ALIAS("xen-backend:pci");