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>
8 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/rwsem.h>
14 #include <linux/list.h>
15 #include <linux/spinlock.h>
16 #include <linux/kref.h>
17 #include <linux/pci.h>
18 #include <linux/wait.h>
19 #include <linux/sched.h>
20 #include <linux/atomic.h>
21 #include <xen/events.h>
22 #include <asm/xen/pci.h>
23 #include <asm/xen/hypervisor.h>
24 #include <xen/interface/physdev.h>
26 #include "conf_space.h"
27 #include "conf_space_quirks.h"
29 #define PCISTUB_DRIVER_NAME "pciback"
31 static char *pci_devs_to_hide
;
32 wait_queue_head_t xen_pcibk_aer_wait_queue
;
33 /*Add sem for sync AER handling and xen_pcibk remove/reconfigue ops,
34 * We want to avoid in middle of AER ops, xen_pcibk devices is being removed
36 static DECLARE_RWSEM(pcistub_sem
);
37 module_param_named(hide
, pci_devs_to_hide
, charp
, 0444);
39 struct pcistub_device_id
{
40 struct list_head slot_list
;
45 static LIST_HEAD(pcistub_device_ids
);
46 static DEFINE_SPINLOCK(device_ids_lock
);
48 struct pcistub_device
{
50 struct list_head dev_list
;
54 struct xen_pcibk_device
*pdev
;/* non-NULL if struct pci_dev is in use */
57 /* Access to pcistub_devices & seized_devices lists and the initialize_devices
58 * flag must be locked with pcistub_devices_lock
60 static DEFINE_SPINLOCK(pcistub_devices_lock
);
61 static LIST_HEAD(pcistub_devices
);
63 /* wait for device_initcall before initializing our devices
64 * (see pcistub_init_devices_late)
66 static int initialize_devices
;
67 static LIST_HEAD(seized_devices
);
69 static struct pcistub_device
*pcistub_device_alloc(struct pci_dev
*dev
)
71 struct pcistub_device
*psdev
;
73 dev_dbg(&dev
->dev
, "pcistub_device_alloc\n");
75 psdev
= kzalloc(sizeof(*psdev
), GFP_KERNEL
);
79 psdev
->dev
= pci_dev_get(dev
);
85 kref_init(&psdev
->kref
);
86 spin_lock_init(&psdev
->lock
);
91 /* Don't call this directly as it's called by pcistub_device_put */
92 static void pcistub_device_release(struct kref
*kref
)
94 struct pcistub_device
*psdev
;
96 struct xen_pcibk_dev_data
*dev_data
;
98 psdev
= container_of(kref
, struct pcistub_device
, kref
);
100 dev_data
= pci_get_drvdata(dev
);
102 dev_dbg(&dev
->dev
, "pcistub_device_release\n");
104 xen_unregister_device_domain_owner(dev
);
106 /* Call the reset function which does not take lock as this
107 * is called from "unbind" which takes a device_lock mutex.
109 __pci_reset_function_locked(dev
);
111 pci_load_and_free_saved_state(dev
, &dev_data
->pci_saved_state
))
112 dev_info(&dev
->dev
, "Could not reload PCI state\n");
114 pci_restore_state(dev
);
117 struct physdev_pci_device ppdev
= {
118 .seg
= pci_domain_nr(dev
->bus
),
119 .bus
= dev
->bus
->number
,
122 int err
= HYPERVISOR_physdev_op(PHYSDEVOP_release_msix
,
125 if (err
&& err
!= -ENOSYS
)
126 dev_warn(&dev
->dev
, "MSI-X release failed (%d)\n",
130 /* Disable the device */
131 xen_pcibk_reset_device(dev
);
134 pci_set_drvdata(dev
, NULL
);
136 /* Clean-up the device */
137 xen_pcibk_config_free_dyn_fields(dev
);
138 xen_pcibk_config_free_dev(dev
);
140 pci_clear_dev_assigned(dev
);
146 static inline void pcistub_device_get(struct pcistub_device
*psdev
)
148 kref_get(&psdev
->kref
);
151 static inline void pcistub_device_put(struct pcistub_device
*psdev
)
153 kref_put(&psdev
->kref
, pcistub_device_release
);
156 static struct pcistub_device
*pcistub_device_find_locked(int domain
, int bus
,
159 struct pcistub_device
*psdev
;
161 list_for_each_entry(psdev
, &pcistub_devices
, dev_list
) {
162 if (psdev
->dev
!= NULL
163 && domain
== pci_domain_nr(psdev
->dev
->bus
)
164 && bus
== psdev
->dev
->bus
->number
165 && slot
== PCI_SLOT(psdev
->dev
->devfn
)
166 && func
== PCI_FUNC(psdev
->dev
->devfn
)) {
174 static struct pcistub_device
*pcistub_device_find(int domain
, int bus
,
177 struct pcistub_device
*psdev
;
180 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
182 psdev
= pcistub_device_find_locked(domain
, bus
, slot
, func
);
184 pcistub_device_get(psdev
);
186 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
190 static struct pci_dev
*pcistub_device_get_pci_dev(struct xen_pcibk_device
*pdev
,
191 struct pcistub_device
*psdev
)
193 struct pci_dev
*pci_dev
= NULL
;
196 pcistub_device_get(psdev
);
198 spin_lock_irqsave(&psdev
->lock
, flags
);
201 pci_dev
= psdev
->dev
;
203 spin_unlock_irqrestore(&psdev
->lock
, flags
);
206 pcistub_device_put(psdev
);
211 struct pci_dev
*pcistub_get_pci_dev_by_slot(struct xen_pcibk_device
*pdev
,
215 struct pcistub_device
*psdev
;
216 struct pci_dev
*found_dev
= NULL
;
219 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
221 psdev
= pcistub_device_find_locked(domain
, bus
, slot
, func
);
223 found_dev
= pcistub_device_get_pci_dev(pdev
, psdev
);
225 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
229 struct pci_dev
*pcistub_get_pci_dev(struct xen_pcibk_device
*pdev
,
232 struct pcistub_device
*psdev
;
233 struct pci_dev
*found_dev
= NULL
;
236 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
238 list_for_each_entry(psdev
, &pcistub_devices
, dev_list
) {
239 if (psdev
->dev
== dev
) {
240 found_dev
= pcistub_device_get_pci_dev(pdev
, psdev
);
245 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
251 * - XenBus state has been reconfigure (pci unplug). See xen_pcibk_remove_device
252 * - XenBus state has been disconnected (guest shutdown). See xen_pcibk_xenbus_remove
253 * - 'echo BDF > unbind' on pciback module with no guest attached. See pcistub_remove
254 * - 'echo BDF > unbind' with a guest still using it. See pcistub_remove
256 * As such we have to be careful.
258 * To make this easier, the caller has to hold the device lock.
260 void pcistub_put_pci_dev(struct pci_dev
*dev
)
262 struct pcistub_device
*psdev
, *found_psdev
= NULL
;
264 struct xen_pcibk_dev_data
*dev_data
;
267 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
269 list_for_each_entry(psdev
, &pcistub_devices
, dev_list
) {
270 if (psdev
->dev
== dev
) {
276 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
277 if (WARN_ON(!found_psdev
))
280 /*hold this lock for avoiding breaking link between
281 * pcistub and xen_pcibk when AER is in processing
283 down_write(&pcistub_sem
);
284 /* Cleanup our device
285 * (so it's ready for the next domain)
287 device_lock_assert(&dev
->dev
);
288 __pci_reset_function_locked(dev
);
290 dev_data
= pci_get_drvdata(dev
);
291 ret
= pci_load_saved_state(dev
, dev_data
->pci_saved_state
);
294 * The usual sequence is pci_save_state & pci_restore_state
295 * but the guest might have messed the configuration space up.
296 * Use the initial version (when device was bound to us).
298 pci_restore_state(dev
);
300 dev_info(&dev
->dev
, "Could not reload PCI state\n");
301 /* This disables the device. */
302 xen_pcibk_reset_device(dev
);
304 /* And cleanup up our emulated fields. */
305 xen_pcibk_config_reset_dev(dev
);
306 xen_pcibk_config_free_dyn_fields(dev
);
308 dev_data
->allow_interrupt_control
= 0;
310 xen_unregister_device_domain_owner(dev
);
312 spin_lock_irqsave(&found_psdev
->lock
, flags
);
313 found_psdev
->pdev
= NULL
;
314 spin_unlock_irqrestore(&found_psdev
->lock
, flags
);
316 pcistub_device_put(found_psdev
);
317 up_write(&pcistub_sem
);
320 static int pcistub_match_one(struct pci_dev
*dev
,
321 struct pcistub_device_id
*pdev_id
)
323 /* Match the specified device by domain, bus, slot, func and also if
324 * any of the device's parent bridges match.
326 for (; dev
!= NULL
; dev
= dev
->bus
->self
) {
327 if (pci_domain_nr(dev
->bus
) == pdev_id
->domain
328 && dev
->bus
->number
== pdev_id
->bus
329 && dev
->devfn
== pdev_id
->devfn
)
332 /* Sometimes topmost bridge links to itself. */
333 if (dev
== dev
->bus
->self
)
340 static int pcistub_match(struct pci_dev
*dev
)
342 struct pcistub_device_id
*pdev_id
;
346 spin_lock_irqsave(&device_ids_lock
, flags
);
347 list_for_each_entry(pdev_id
, &pcistub_device_ids
, slot_list
) {
348 if (pcistub_match_one(dev
, pdev_id
)) {
353 spin_unlock_irqrestore(&device_ids_lock
, flags
);
358 static int pcistub_init_device(struct pci_dev
*dev
)
360 struct xen_pcibk_dev_data
*dev_data
;
363 dev_dbg(&dev
->dev
, "initializing...\n");
365 /* The PCI backend is not intended to be a module (or to work with
366 * removable PCI devices (yet). If it were, xen_pcibk_config_free()
367 * would need to be called somewhere to free the memory allocated
368 * here and then to call kfree(pci_get_drvdata(psdev->dev)).
370 dev_data
= kzalloc(sizeof(*dev_data
) + strlen(DRV_NAME
"[]")
371 + strlen(pci_name(dev
)) + 1, GFP_KERNEL
);
376 pci_set_drvdata(dev
, dev_data
);
379 * Setup name for fake IRQ handler. It will only be enabled
380 * once the device is turned on by the guest.
382 sprintf(dev_data
->irq_name
, DRV_NAME
"[%s]", pci_name(dev
));
384 dev_dbg(&dev
->dev
, "initializing config\n");
386 init_waitqueue_head(&xen_pcibk_aer_wait_queue
);
387 err
= xen_pcibk_config_init_dev(dev
);
391 /* HACK: Force device (& ACPI) to determine what IRQ it's on - we
392 * must do this here because pcibios_enable_device may specify
393 * the pci device's true irq (and possibly its other resources)
394 * if they differ from what's in the configuration space.
395 * This makes the assumption that the device's resources won't
396 * change after this point (otherwise this code may break!)
398 dev_dbg(&dev
->dev
, "enabling device\n");
399 err
= pci_enable_device(dev
);
404 struct physdev_pci_device ppdev
= {
405 .seg
= pci_domain_nr(dev
->bus
),
406 .bus
= dev
->bus
->number
,
410 err
= HYPERVISOR_physdev_op(PHYSDEVOP_prepare_msix
, &ppdev
);
411 if (err
&& err
!= -ENOSYS
)
412 dev_err(&dev
->dev
, "MSI-X preparation failed (%d)\n",
416 /* We need the device active to save the state. */
417 dev_dbg(&dev
->dev
, "save state of device\n");
419 dev_data
->pci_saved_state
= pci_store_saved_state(dev
);
420 if (!dev_data
->pci_saved_state
)
421 dev_err(&dev
->dev
, "Could not store PCI conf saved state!\n");
423 dev_dbg(&dev
->dev
, "resetting (FLR, D3, etc) the device\n");
424 __pci_reset_function_locked(dev
);
425 pci_restore_state(dev
);
427 /* Now disable the device (this also ensures some private device
428 * data is setup before we export)
430 dev_dbg(&dev
->dev
, "reset device\n");
431 xen_pcibk_reset_device(dev
);
433 pci_set_dev_assigned(dev
);
437 xen_pcibk_config_free_dev(dev
);
440 pci_set_drvdata(dev
, NULL
);
446 * Because some initialization still happens on
447 * devices during fs_initcall, we need to defer
448 * full initialization of our devices until
451 static int __init
pcistub_init_devices_late(void)
453 struct pcistub_device
*psdev
;
457 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
459 while (!list_empty(&seized_devices
)) {
460 psdev
= container_of(seized_devices
.next
,
461 struct pcistub_device
, dev_list
);
462 list_del(&psdev
->dev_list
);
464 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
466 err
= pcistub_init_device(psdev
->dev
);
468 dev_err(&psdev
->dev
->dev
,
469 "error %d initializing device\n", err
);
474 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
477 list_add_tail(&psdev
->dev_list
, &pcistub_devices
);
480 initialize_devices
= 1;
482 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
487 static void pcistub_device_id_add_list(struct pcistub_device_id
*new,
488 int domain
, int bus
, unsigned int devfn
)
490 struct pcistub_device_id
*pci_dev_id
;
494 spin_lock_irqsave(&device_ids_lock
, flags
);
496 list_for_each_entry(pci_dev_id
, &pcistub_device_ids
, slot_list
) {
497 if (pci_dev_id
->domain
== domain
&& pci_dev_id
->bus
== bus
&&
498 pci_dev_id
->devfn
== devfn
) {
505 new->domain
= domain
;
508 list_add_tail(&new->slot_list
, &pcistub_device_ids
);
511 spin_unlock_irqrestore(&device_ids_lock
, flags
);
517 static int pcistub_seize(struct pci_dev
*dev
,
518 struct pcistub_device_id
*pci_dev_id
)
520 struct pcistub_device
*psdev
;
524 psdev
= pcistub_device_alloc(dev
);
530 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
532 if (initialize_devices
) {
533 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
535 /* don't want irqs disabled when calling pcistub_init_device */
536 err
= pcistub_init_device(psdev
->dev
);
538 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
541 list_add(&psdev
->dev_list
, &pcistub_devices
);
543 dev_dbg(&dev
->dev
, "deferring initialization\n");
544 list_add(&psdev
->dev_list
, &seized_devices
);
547 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
551 pcistub_device_put(psdev
);
552 } else if (pci_dev_id
)
553 pcistub_device_id_add_list(pci_dev_id
, pci_domain_nr(dev
->bus
),
554 dev
->bus
->number
, dev
->devfn
);
559 /* Called when 'bind'. This means we must _NOT_ call pci_reset_function or
560 * other functions that take the sysfs lock. */
561 static int pcistub_probe(struct pci_dev
*dev
, const struct pci_device_id
*id
)
564 struct pcistub_device_id
*pci_dev_id
= NULL
;
566 dev_dbg(&dev
->dev
, "probing...\n");
568 match
= pcistub_match(dev
);
570 if ((dev
->driver_override
&&
571 !strcmp(dev
->driver_override
, PCISTUB_DRIVER_NAME
)) ||
574 if (dev
->hdr_type
!= PCI_HEADER_TYPE_NORMAL
575 && dev
->hdr_type
!= PCI_HEADER_TYPE_BRIDGE
) {
576 dev_err(&dev
->dev
, "can't export pci devices that "
577 "don't have a normal (0) or bridge (1) "
584 pci_dev_id
= kmalloc(sizeof(*pci_dev_id
), GFP_KERNEL
);
591 dev_info(&dev
->dev
, "seizing device\n");
592 err
= pcistub_seize(dev
, pci_dev_id
);
594 /* Didn't find the device */
601 /* Called when 'unbind'. This means we must _NOT_ call pci_reset_function or
602 * other functions that take the sysfs lock. */
603 static void pcistub_remove(struct pci_dev
*dev
)
605 struct pcistub_device
*psdev
, *found_psdev
= NULL
;
608 dev_dbg(&dev
->dev
, "removing\n");
610 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
612 xen_pcibk_config_quirk_release(dev
);
614 list_for_each_entry(psdev
, &pcistub_devices
, dev_list
) {
615 if (psdev
->dev
== dev
) {
621 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
624 dev_dbg(&dev
->dev
, "found device to remove %s\n",
625 found_psdev
->pdev
? "- in-use" : "");
627 if (found_psdev
->pdev
) {
628 int domid
= xen_find_device_domain_owner(dev
);
630 dev_warn(&dev
->dev
, "****** removing device %s while still in-use by domain %d! ******\n",
631 pci_name(found_psdev
->dev
), domid
);
632 dev_warn(&dev
->dev
, "****** driver domain may still access this device's i/o resources!\n");
633 dev_warn(&dev
->dev
, "****** shutdown driver domain before binding device\n");
634 dev_warn(&dev
->dev
, "****** to other drivers or domains\n");
636 /* N.B. This ends up calling pcistub_put_pci_dev which ends up
638 xen_pcibk_release_pci_dev(found_psdev
->pdev
,
640 false /* caller holds the lock. */);
643 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
644 list_del(&found_psdev
->dev_list
);
645 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
647 /* the final put for releasing from the list */
648 pcistub_device_put(found_psdev
);
652 static const struct pci_device_id pcistub_ids
[] = {
654 .vendor
= PCI_ANY_ID
,
655 .device
= PCI_ANY_ID
,
656 .subvendor
= PCI_ANY_ID
,
657 .subdevice
= PCI_ANY_ID
,
662 #define PCI_NODENAME_MAX 40
663 static void kill_domain_by_device(struct pcistub_device
*psdev
)
665 struct xenbus_transaction xbt
;
667 char nodename
[PCI_NODENAME_MAX
];
670 snprintf(nodename
, PCI_NODENAME_MAX
, "/local/domain/0/backend/pci/%d/0",
671 psdev
->pdev
->xdev
->otherend_id
);
674 err
= xenbus_transaction_start(&xbt
);
676 dev_err(&psdev
->dev
->dev
,
677 "error %d when start xenbus transaction\n", err
);
680 /*PV AER handlers will set this flag*/
681 xenbus_printf(xbt
, nodename
, "aerState" , "aerfail");
682 err
= xenbus_transaction_end(xbt
, 0);
686 dev_err(&psdev
->dev
->dev
,
687 "error %d when end xenbus transaction\n", err
);
692 /* For each aer recovery step error_detected, mmio_enabled, etc, front_end and
693 * backend need to have cooperation. In xen_pcibk, those steps will do similar
694 * jobs: send service request and waiting for front_end response.
696 static pci_ers_result_t
common_process(struct pcistub_device
*psdev
,
697 pci_channel_state_t state
, int aer_cmd
,
698 pci_ers_result_t result
)
700 pci_ers_result_t res
= result
;
701 struct xen_pcie_aer_op
*aer_op
;
702 struct xen_pcibk_device
*pdev
= psdev
->pdev
;
703 struct xen_pci_sharedinfo
*sh_info
= pdev
->sh_info
;
706 /*with PV AER drivers*/
707 aer_op
= &(sh_info
->aer_op
);
708 aer_op
->cmd
= aer_cmd
;
709 /*useful for error_detected callback*/
712 ret
= xen_pcibk_get_pcifront_dev(psdev
->dev
, psdev
->pdev
,
713 &aer_op
->domain
, &aer_op
->bus
, &aer_op
->devfn
);
715 dev_err(&psdev
->dev
->dev
, "failed to get pcifront device\n");
716 return PCI_ERS_RESULT_NONE
;
720 dev_dbg(&psdev
->dev
->dev
, "aer_op %x dom %x bus %x devfn %x\n",
721 aer_cmd
, aer_op
->domain
, aer_op
->bus
, aer_op
->devfn
);
722 /*local flag to mark there's aer request, xen_pcibk callback will use
723 * this flag to judge whether we need to check pci-front give aer
726 set_bit(_PCIB_op_pending
, (unsigned long *)&pdev
->flags
);
728 /*It is possible that a pcifront conf_read_write ops request invokes
729 * the callback which cause the spurious execution of wake_up.
730 * Yet it is harmless and better than a spinlock here
732 set_bit(_XEN_PCIB_active
,
733 (unsigned long *)&sh_info
->flags
);
735 notify_remote_via_irq(pdev
->evtchn_irq
);
737 /* Enable IRQ to signal "request done". */
738 xen_pcibk_lateeoi(pdev
, 0);
740 ret
= wait_event_timeout(xen_pcibk_aer_wait_queue
,
741 !(test_bit(_XEN_PCIB_active
, (unsigned long *)
742 &sh_info
->flags
)), 300*HZ
);
744 /* Enable IRQ for pcifront request if not already active. */
745 if (!test_bit(_PDEVF_op_active
, &pdev
->flags
))
746 xen_pcibk_lateeoi(pdev
, 0);
749 if (test_bit(_XEN_PCIB_active
,
750 (unsigned long *)&sh_info
->flags
)) {
751 dev_err(&psdev
->dev
->dev
,
752 "pcifront aer process not responding!\n");
753 clear_bit(_XEN_PCIB_active
,
754 (unsigned long *)&sh_info
->flags
);
755 aer_op
->err
= PCI_ERS_RESULT_NONE
;
759 clear_bit(_PCIB_op_pending
, (unsigned long *)&pdev
->flags
);
761 res
= (pci_ers_result_t
)aer_op
->err
;
766 * xen_pcibk_slot_reset: it will send the slot_reset request to pcifront in case
767 * of the device driver could provide this service, and then wait for pcifront
769 * @dev: pointer to PCI devices
770 * return value is used by aer_core do_recovery policy
772 static pci_ers_result_t
xen_pcibk_slot_reset(struct pci_dev
*dev
)
774 struct pcistub_device
*psdev
;
775 pci_ers_result_t result
;
777 result
= PCI_ERS_RESULT_RECOVERED
;
778 dev_dbg(&dev
->dev
, "xen_pcibk_slot_reset(bus:%x,devfn:%x)\n",
779 dev
->bus
->number
, dev
->devfn
);
781 down_write(&pcistub_sem
);
782 psdev
= pcistub_device_find(pci_domain_nr(dev
->bus
),
784 PCI_SLOT(dev
->devfn
),
785 PCI_FUNC(dev
->devfn
));
787 if (!psdev
|| !psdev
->pdev
) {
788 dev_err(&dev
->dev
, "device is not found/assigned\n");
792 if (!psdev
->pdev
->sh_info
) {
793 dev_err(&dev
->dev
, "device is not connected or owned"
794 " by HVM, kill it\n");
795 kill_domain_by_device(psdev
);
799 if (!test_bit(_XEN_PCIB_AERHANDLER
,
800 (unsigned long *)&psdev
->pdev
->sh_info
->flags
)) {
802 "guest with no AER driver should have been killed\n");
805 result
= common_process(psdev
, 1, XEN_PCI_OP_aer_slotreset
, result
);
807 if (result
== PCI_ERS_RESULT_NONE
||
808 result
== PCI_ERS_RESULT_DISCONNECT
) {
810 "No AER slot_reset service or disconnected!\n");
811 kill_domain_by_device(psdev
);
815 pcistub_device_put(psdev
);
816 up_write(&pcistub_sem
);
822 /*xen_pcibk_mmio_enabled: it will send the mmio_enabled request to pcifront
823 * in case of the device driver could provide this service, and then wait
825 * @dev: pointer to PCI devices
826 * return value is used by aer_core do_recovery policy
829 static pci_ers_result_t
xen_pcibk_mmio_enabled(struct pci_dev
*dev
)
831 struct pcistub_device
*psdev
;
832 pci_ers_result_t result
;
834 result
= PCI_ERS_RESULT_RECOVERED
;
835 dev_dbg(&dev
->dev
, "xen_pcibk_mmio_enabled(bus:%x,devfn:%x)\n",
836 dev
->bus
->number
, dev
->devfn
);
838 down_write(&pcistub_sem
);
839 psdev
= pcistub_device_find(pci_domain_nr(dev
->bus
),
841 PCI_SLOT(dev
->devfn
),
842 PCI_FUNC(dev
->devfn
));
844 if (!psdev
|| !psdev
->pdev
) {
845 dev_err(&dev
->dev
, "device is not found/assigned\n");
849 if (!psdev
->pdev
->sh_info
) {
850 dev_err(&dev
->dev
, "device is not connected or owned"
851 " by HVM, kill it\n");
852 kill_domain_by_device(psdev
);
856 if (!test_bit(_XEN_PCIB_AERHANDLER
,
857 (unsigned long *)&psdev
->pdev
->sh_info
->flags
)) {
859 "guest with no AER driver should have been killed\n");
862 result
= common_process(psdev
, 1, XEN_PCI_OP_aer_mmio
, result
);
864 if (result
== PCI_ERS_RESULT_NONE
||
865 result
== PCI_ERS_RESULT_DISCONNECT
) {
867 "No AER mmio_enabled service or disconnected!\n");
868 kill_domain_by_device(psdev
);
872 pcistub_device_put(psdev
);
873 up_write(&pcistub_sem
);
877 /*xen_pcibk_error_detected: it will send the error_detected request to pcifront
878 * in case of the device driver could provide this service, and then wait
880 * @dev: pointer to PCI devices
881 * @error: the current PCI connection state
882 * return value is used by aer_core do_recovery policy
885 static pci_ers_result_t
xen_pcibk_error_detected(struct pci_dev
*dev
,
886 pci_channel_state_t error
)
888 struct pcistub_device
*psdev
;
889 pci_ers_result_t result
;
891 result
= PCI_ERS_RESULT_CAN_RECOVER
;
892 dev_dbg(&dev
->dev
, "xen_pcibk_error_detected(bus:%x,devfn:%x)\n",
893 dev
->bus
->number
, dev
->devfn
);
895 down_write(&pcistub_sem
);
896 psdev
= pcistub_device_find(pci_domain_nr(dev
->bus
),
898 PCI_SLOT(dev
->devfn
),
899 PCI_FUNC(dev
->devfn
));
901 if (!psdev
|| !psdev
->pdev
) {
902 dev_err(&dev
->dev
, "device is not found/assigned\n");
906 if (!psdev
->pdev
->sh_info
) {
907 dev_err(&dev
->dev
, "device is not connected or owned"
908 " by HVM, kill it\n");
909 kill_domain_by_device(psdev
);
913 /*Guest owns the device yet no aer handler regiested, kill guest*/
914 if (!test_bit(_XEN_PCIB_AERHANDLER
,
915 (unsigned long *)&psdev
->pdev
->sh_info
->flags
)) {
916 dev_dbg(&dev
->dev
, "guest may have no aer driver, kill it\n");
917 kill_domain_by_device(psdev
);
920 result
= common_process(psdev
, error
, XEN_PCI_OP_aer_detected
, result
);
922 if (result
== PCI_ERS_RESULT_NONE
||
923 result
== PCI_ERS_RESULT_DISCONNECT
) {
925 "No AER error_detected service or disconnected!\n");
926 kill_domain_by_device(psdev
);
930 pcistub_device_put(psdev
);
931 up_write(&pcistub_sem
);
935 /*xen_pcibk_error_resume: it will send the error_resume request to pcifront
936 * in case of the device driver could provide this service, and then wait
938 * @dev: pointer to PCI devices
941 static void xen_pcibk_error_resume(struct pci_dev
*dev
)
943 struct pcistub_device
*psdev
;
945 dev_dbg(&dev
->dev
, "xen_pcibk_error_resume(bus:%x,devfn:%x)\n",
946 dev
->bus
->number
, dev
->devfn
);
948 down_write(&pcistub_sem
);
949 psdev
= pcistub_device_find(pci_domain_nr(dev
->bus
),
951 PCI_SLOT(dev
->devfn
),
952 PCI_FUNC(dev
->devfn
));
954 if (!psdev
|| !psdev
->pdev
) {
955 dev_err(&dev
->dev
, "device is not found/assigned\n");
959 if (!psdev
->pdev
->sh_info
) {
960 dev_err(&dev
->dev
, "device is not connected or owned"
961 " by HVM, kill it\n");
962 kill_domain_by_device(psdev
);
966 if (!test_bit(_XEN_PCIB_AERHANDLER
,
967 (unsigned long *)&psdev
->pdev
->sh_info
->flags
)) {
969 "guest with no AER driver should have been killed\n");
970 kill_domain_by_device(psdev
);
973 common_process(psdev
, 1, XEN_PCI_OP_aer_resume
,
974 PCI_ERS_RESULT_RECOVERED
);
977 pcistub_device_put(psdev
);
978 up_write(&pcistub_sem
);
982 /*add xen_pcibk AER handling*/
983 static const struct pci_error_handlers xen_pcibk_error_handler
= {
984 .error_detected
= xen_pcibk_error_detected
,
985 .mmio_enabled
= xen_pcibk_mmio_enabled
,
986 .slot_reset
= xen_pcibk_slot_reset
,
987 .resume
= xen_pcibk_error_resume
,
991 * Note: There is no MODULE_DEVICE_TABLE entry here because this isn't
992 * for a normal device. I don't want it to be loaded automatically.
995 static struct pci_driver xen_pcibk_pci_driver
= {
996 /* The name should be xen_pciback, but until the tools are updated
997 * we will keep it as pciback. */
998 .name
= PCISTUB_DRIVER_NAME
,
999 .id_table
= pcistub_ids
,
1000 .probe
= pcistub_probe
,
1001 .remove
= pcistub_remove
,
1002 .err_handler
= &xen_pcibk_error_handler
,
1005 static inline int str_to_slot(const char *buf
, int *domain
, int *bus
,
1006 int *slot
, int *func
)
1010 switch (sscanf(buf
, " %x:%x:%x.%x %n", domain
, bus
, slot
, func
,
1014 sscanf(buf
, " %x:%x:%x.* %n", domain
, bus
, slot
, &parsed
);
1018 sscanf(buf
, " %x:%x:*.* %n", domain
, bus
, &parsed
);
1021 if (parsed
&& !buf
[parsed
])
1024 /* try again without domain */
1026 switch (sscanf(buf
, " %x:%x.%x %n", bus
, slot
, func
, &parsed
)) {
1029 sscanf(buf
, " %x:%x.* %n", bus
, slot
, &parsed
);
1033 sscanf(buf
, " %x:*.* %n", bus
, &parsed
);
1036 if (parsed
&& !buf
[parsed
])
1042 static inline int str_to_quirk(const char *buf
, int *domain
, int *bus
, int
1043 *slot
, int *func
, int *reg
, int *size
, int *mask
)
1047 sscanf(buf
, " %x:%x:%x.%x-%x:%x:%x %n", domain
, bus
, slot
, func
,
1048 reg
, size
, mask
, &parsed
);
1049 if (parsed
&& !buf
[parsed
])
1052 /* try again without domain */
1054 sscanf(buf
, " %x:%x.%x-%x:%x:%x %n", bus
, slot
, func
, reg
, size
,
1056 if (parsed
&& !buf
[parsed
])
1062 static int pcistub_device_id_add(int domain
, int bus
, int slot
, int func
)
1064 struct pcistub_device_id
*pci_dev_id
;
1065 int rc
= 0, devfn
= PCI_DEVFN(slot
, func
);
1068 for (slot
= 0; !rc
&& slot
< 32; ++slot
)
1069 rc
= pcistub_device_id_add(domain
, bus
, slot
, func
);
1074 for (func
= 0; !rc
&& func
< 8; ++func
)
1075 rc
= pcistub_device_id_add(domain
, bus
, slot
, func
);
1080 #if !defined(MODULE) /* pci_domains_supported is not being exported */ \
1081 || !defined(CONFIG_PCI_DOMAINS)
1082 !pci_domains_supported
? domain
:
1084 domain
< 0 || domain
> 0xffff)
1085 || bus
< 0 || bus
> 0xff
1086 || PCI_SLOT(devfn
) != slot
1087 || PCI_FUNC(devfn
) != func
)
1090 pci_dev_id
= kmalloc(sizeof(*pci_dev_id
), GFP_KERNEL
);
1094 pr_debug("wants to seize %04x:%02x:%02x.%d\n",
1095 domain
, bus
, slot
, func
);
1097 pcistub_device_id_add_list(pci_dev_id
, domain
, bus
, devfn
);
1102 static int pcistub_device_id_remove(int domain
, int bus
, int slot
, int func
)
1104 struct pcistub_device_id
*pci_dev_id
, *t
;
1106 unsigned long flags
;
1108 spin_lock_irqsave(&device_ids_lock
, flags
);
1109 list_for_each_entry_safe(pci_dev_id
, t
, &pcistub_device_ids
,
1111 if (pci_dev_id
->domain
== domain
&& pci_dev_id
->bus
== bus
1112 && (slot
< 0 || PCI_SLOT(pci_dev_id
->devfn
) == slot
)
1113 && (func
< 0 || PCI_FUNC(pci_dev_id
->devfn
) == func
)) {
1114 /* Don't break; here because it's possible the same
1115 * slot could be in the list more than once
1117 list_del(&pci_dev_id
->slot_list
);
1122 pr_debug("removed %04x:%02x:%02x.%d from seize list\n",
1123 domain
, bus
, slot
, func
);
1126 spin_unlock_irqrestore(&device_ids_lock
, flags
);
1131 static int pcistub_reg_add(int domain
, int bus
, int slot
, int func
,
1132 unsigned int reg
, unsigned int size
,
1136 struct pcistub_device
*psdev
;
1137 struct pci_dev
*dev
;
1138 struct config_field
*field
;
1140 if (reg
> 0xfff || (size
< 4 && (mask
>> (size
* 8))))
1143 psdev
= pcistub_device_find(domain
, bus
, slot
, func
);
1150 field
= kzalloc(sizeof(*field
), GFP_KERNEL
);
1156 field
->offset
= reg
;
1160 field
->reset
= NULL
;
1161 field
->release
= NULL
;
1162 field
->clean
= xen_pcibk_config_field_free
;
1164 err
= xen_pcibk_config_quirks_add_field(dev
, field
);
1169 pcistub_device_put(psdev
);
1173 static ssize_t
new_slot_store(struct device_driver
*drv
, const char *buf
,
1176 int domain
, bus
, slot
, func
;
1179 err
= str_to_slot(buf
, &domain
, &bus
, &slot
, &func
);
1183 err
= pcistub_device_id_add(domain
, bus
, slot
, func
);
1190 static DRIVER_ATTR_WO(new_slot
);
1192 static ssize_t
remove_slot_store(struct device_driver
*drv
, const char *buf
,
1195 int domain
, bus
, slot
, func
;
1198 err
= str_to_slot(buf
, &domain
, &bus
, &slot
, &func
);
1202 err
= pcistub_device_id_remove(domain
, bus
, slot
, func
);
1209 static DRIVER_ATTR_WO(remove_slot
);
1211 static ssize_t
slots_show(struct device_driver
*drv
, char *buf
)
1213 struct pcistub_device_id
*pci_dev_id
;
1215 unsigned long flags
;
1217 spin_lock_irqsave(&device_ids_lock
, flags
);
1218 list_for_each_entry(pci_dev_id
, &pcistub_device_ids
, slot_list
) {
1219 if (count
>= PAGE_SIZE
)
1222 count
+= scnprintf(buf
+ count
, PAGE_SIZE
- count
,
1223 "%04x:%02x:%02x.%d\n",
1224 pci_dev_id
->domain
, pci_dev_id
->bus
,
1225 PCI_SLOT(pci_dev_id
->devfn
),
1226 PCI_FUNC(pci_dev_id
->devfn
));
1228 spin_unlock_irqrestore(&device_ids_lock
, flags
);
1232 static DRIVER_ATTR_RO(slots
);
1234 static ssize_t
irq_handlers_show(struct device_driver
*drv
, char *buf
)
1236 struct pcistub_device
*psdev
;
1237 struct xen_pcibk_dev_data
*dev_data
;
1239 unsigned long flags
;
1241 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
1242 list_for_each_entry(psdev
, &pcistub_devices
, dev_list
) {
1243 if (count
>= PAGE_SIZE
)
1247 dev_data
= pci_get_drvdata(psdev
->dev
);
1251 scnprintf(buf
+ count
, PAGE_SIZE
- count
,
1252 "%s:%s:%sing:%ld\n",
1253 pci_name(psdev
->dev
),
1254 dev_data
->isr_on
? "on" : "off",
1255 dev_data
->ack_intr
? "ack" : "not ack",
1258 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
1261 static DRIVER_ATTR_RO(irq_handlers
);
1263 static ssize_t
irq_handler_state_store(struct device_driver
*drv
,
1264 const char *buf
, size_t count
)
1266 struct pcistub_device
*psdev
;
1267 struct xen_pcibk_dev_data
*dev_data
;
1268 int domain
, bus
, slot
, func
;
1271 err
= str_to_slot(buf
, &domain
, &bus
, &slot
, &func
);
1275 psdev
= pcistub_device_find(domain
, bus
, slot
, func
);
1281 dev_data
= pci_get_drvdata(psdev
->dev
);
1287 dev_dbg(&psdev
->dev
->dev
, "%s fake irq handler: %d->%d\n",
1288 dev_data
->irq_name
, dev_data
->isr_on
,
1291 dev_data
->isr_on
= !(dev_data
->isr_on
);
1292 if (dev_data
->isr_on
)
1293 dev_data
->ack_intr
= 1;
1296 pcistub_device_put(psdev
);
1301 static DRIVER_ATTR_WO(irq_handler_state
);
1303 static ssize_t
quirks_store(struct device_driver
*drv
, const char *buf
,
1306 int domain
, bus
, slot
, func
, reg
, size
, mask
;
1309 err
= str_to_quirk(buf
, &domain
, &bus
, &slot
, &func
, ®
, &size
,
1314 err
= pcistub_reg_add(domain
, bus
, slot
, func
, reg
, size
, mask
);
1322 static ssize_t
quirks_show(struct device_driver
*drv
, char *buf
)
1325 unsigned long flags
;
1326 struct xen_pcibk_config_quirk
*quirk
;
1327 struct xen_pcibk_dev_data
*dev_data
;
1328 const struct config_field
*field
;
1329 const struct config_field_entry
*cfg_entry
;
1331 spin_lock_irqsave(&device_ids_lock
, flags
);
1332 list_for_each_entry(quirk
, &xen_pcibk_quirks
, quirks_list
) {
1333 if (count
>= PAGE_SIZE
)
1336 count
+= scnprintf(buf
+ count
, PAGE_SIZE
- count
,
1337 "%02x:%02x.%01x\n\t%04x:%04x:%04x:%04x\n",
1338 quirk
->pdev
->bus
->number
,
1339 PCI_SLOT(quirk
->pdev
->devfn
),
1340 PCI_FUNC(quirk
->pdev
->devfn
),
1341 quirk
->devid
.vendor
, quirk
->devid
.device
,
1342 quirk
->devid
.subvendor
,
1343 quirk
->devid
.subdevice
);
1345 dev_data
= pci_get_drvdata(quirk
->pdev
);
1347 list_for_each_entry(cfg_entry
, &dev_data
->config_fields
, list
) {
1348 field
= cfg_entry
->field
;
1349 if (count
>= PAGE_SIZE
)
1352 count
+= scnprintf(buf
+ count
, PAGE_SIZE
- count
,
1353 "\t\t%08x:%01x:%08x\n",
1354 cfg_entry
->base_offset
+
1355 field
->offset
, field
->size
,
1361 spin_unlock_irqrestore(&device_ids_lock
, flags
);
1365 static DRIVER_ATTR_RW(quirks
);
1367 static ssize_t
permissive_store(struct device_driver
*drv
, const char *buf
,
1370 int domain
, bus
, slot
, func
;
1372 struct pcistub_device
*psdev
;
1373 struct xen_pcibk_dev_data
*dev_data
;
1375 err
= str_to_slot(buf
, &domain
, &bus
, &slot
, &func
);
1379 psdev
= pcistub_device_find(domain
, bus
, slot
, func
);
1385 dev_data
= pci_get_drvdata(psdev
->dev
);
1386 /* the driver data for a device should never be null at this point */
1391 if (!dev_data
->permissive
) {
1392 dev_data
->permissive
= 1;
1393 /* Let user know that what they're doing could be unsafe */
1394 dev_warn(&psdev
->dev
->dev
, "enabling permissive mode "
1395 "configuration space accesses!\n");
1396 dev_warn(&psdev
->dev
->dev
,
1397 "permissive mode is potentially unsafe!\n");
1400 pcistub_device_put(psdev
);
1407 static ssize_t
permissive_show(struct device_driver
*drv
, char *buf
)
1409 struct pcistub_device
*psdev
;
1410 struct xen_pcibk_dev_data
*dev_data
;
1412 unsigned long flags
;
1413 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
1414 list_for_each_entry(psdev
, &pcistub_devices
, dev_list
) {
1415 if (count
>= PAGE_SIZE
)
1419 dev_data
= pci_get_drvdata(psdev
->dev
);
1420 if (!dev_data
|| !dev_data
->permissive
)
1423 scnprintf(buf
+ count
, PAGE_SIZE
- count
, "%s\n",
1424 pci_name(psdev
->dev
));
1426 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
1429 static DRIVER_ATTR_RW(permissive
);
1431 static ssize_t
allow_interrupt_control_store(struct device_driver
*drv
,
1432 const char *buf
, size_t count
)
1434 int domain
, bus
, slot
, func
;
1436 struct pcistub_device
*psdev
;
1437 struct xen_pcibk_dev_data
*dev_data
;
1439 err
= str_to_slot(buf
, &domain
, &bus
, &slot
, &func
);
1443 psdev
= pcistub_device_find(domain
, bus
, slot
, func
);
1449 dev_data
= pci_get_drvdata(psdev
->dev
);
1450 /* the driver data for a device should never be null at this point */
1455 dev_data
->allow_interrupt_control
= 1;
1457 pcistub_device_put(psdev
);
1464 static ssize_t
allow_interrupt_control_show(struct device_driver
*drv
,
1467 struct pcistub_device
*psdev
;
1468 struct xen_pcibk_dev_data
*dev_data
;
1470 unsigned long flags
;
1472 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
1473 list_for_each_entry(psdev
, &pcistub_devices
, dev_list
) {
1474 if (count
>= PAGE_SIZE
)
1478 dev_data
= pci_get_drvdata(psdev
->dev
);
1479 if (!dev_data
|| !dev_data
->allow_interrupt_control
)
1482 scnprintf(buf
+ count
, PAGE_SIZE
- count
, "%s\n",
1483 pci_name(psdev
->dev
));
1485 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
1488 static DRIVER_ATTR_RW(allow_interrupt_control
);
1490 static void pcistub_exit(void)
1492 driver_remove_file(&xen_pcibk_pci_driver
.driver
, &driver_attr_new_slot
);
1493 driver_remove_file(&xen_pcibk_pci_driver
.driver
,
1494 &driver_attr_remove_slot
);
1495 driver_remove_file(&xen_pcibk_pci_driver
.driver
, &driver_attr_slots
);
1496 driver_remove_file(&xen_pcibk_pci_driver
.driver
, &driver_attr_quirks
);
1497 driver_remove_file(&xen_pcibk_pci_driver
.driver
,
1498 &driver_attr_permissive
);
1499 driver_remove_file(&xen_pcibk_pci_driver
.driver
,
1500 &driver_attr_allow_interrupt_control
);
1501 driver_remove_file(&xen_pcibk_pci_driver
.driver
,
1502 &driver_attr_irq_handlers
);
1503 driver_remove_file(&xen_pcibk_pci_driver
.driver
,
1504 &driver_attr_irq_handler_state
);
1505 pci_unregister_driver(&xen_pcibk_pci_driver
);
1508 static int __init
pcistub_init(void)
1512 int domain
, bus
, slot
, func
;
1515 if (pci_devs_to_hide
&& *pci_devs_to_hide
) {
1519 err
= sscanf(pci_devs_to_hide
+ pos
,
1520 " (%x:%x:%x.%x) %n",
1521 &domain
, &bus
, &slot
, &func
, &parsed
);
1525 sscanf(pci_devs_to_hide
+ pos
,
1527 &domain
, &bus
, &slot
, &parsed
);
1531 sscanf(pci_devs_to_hide
+ pos
,
1533 &domain
, &bus
, &parsed
);
1539 err
= sscanf(pci_devs_to_hide
+ pos
,
1541 &bus
, &slot
, &func
, &parsed
);
1545 sscanf(pci_devs_to_hide
+ pos
,
1547 &bus
, &slot
, &parsed
);
1551 sscanf(pci_devs_to_hide
+ pos
,
1561 err
= pcistub_device_id_add(domain
, bus
, slot
, func
);
1566 } while (pci_devs_to_hide
[pos
]);
1569 /* If we're the first PCI Device Driver to register, we're the
1570 * first one to get offered PCI devices as they become
1571 * available (and thus we can be the first to grab them)
1573 err
= pci_register_driver(&xen_pcibk_pci_driver
);
1577 err
= driver_create_file(&xen_pcibk_pci_driver
.driver
,
1578 &driver_attr_new_slot
);
1580 err
= driver_create_file(&xen_pcibk_pci_driver
.driver
,
1581 &driver_attr_remove_slot
);
1583 err
= driver_create_file(&xen_pcibk_pci_driver
.driver
,
1584 &driver_attr_slots
);
1586 err
= driver_create_file(&xen_pcibk_pci_driver
.driver
,
1587 &driver_attr_quirks
);
1589 err
= driver_create_file(&xen_pcibk_pci_driver
.driver
,
1590 &driver_attr_permissive
);
1592 err
= driver_create_file(&xen_pcibk_pci_driver
.driver
,
1593 &driver_attr_allow_interrupt_control
);
1596 err
= driver_create_file(&xen_pcibk_pci_driver
.driver
,
1597 &driver_attr_irq_handlers
);
1599 err
= driver_create_file(&xen_pcibk_pci_driver
.driver
,
1600 &driver_attr_irq_handler_state
);
1608 pr_err("Error parsing pci_devs_to_hide at \"%s\"\n",
1609 pci_devs_to_hide
+ pos
);
1615 * fs_initcall happens before device_initcall
1616 * so xen_pcibk *should* get called first (b/c we
1617 * want to suck up any device before other drivers
1618 * get a chance by being the first pci device
1619 * driver to register)
1621 fs_initcall(pcistub_init
);
1624 #ifdef CONFIG_PCI_IOV
1625 static struct pcistub_device
*find_vfs(const struct pci_dev
*pdev
)
1627 struct pcistub_device
*psdev
= NULL
;
1628 unsigned long flags
;
1631 spin_lock_irqsave(&pcistub_devices_lock
, flags
);
1632 list_for_each_entry(psdev
, &pcistub_devices
, dev_list
) {
1633 if (!psdev
->pdev
&& psdev
->dev
!= pdev
1634 && pci_physfn(psdev
->dev
) == pdev
) {
1639 spin_unlock_irqrestore(&pcistub_devices_lock
, flags
);
1645 static int pci_stub_notifier(struct notifier_block
*nb
,
1646 unsigned long action
, void *data
)
1648 struct device
*dev
= data
;
1649 const struct pci_dev
*pdev
= to_pci_dev(dev
);
1651 if (action
!= BUS_NOTIFY_UNBIND_DRIVER
)
1654 if (!pdev
->is_physfn
)
1658 struct pcistub_device
*psdev
= find_vfs(pdev
);
1661 device_release_driver(&psdev
->dev
->dev
);
1666 static struct notifier_block pci_stub_nb
= {
1667 .notifier_call
= pci_stub_notifier
,
1671 static int __init
xen_pcibk_init(void)
1675 if (!xen_initial_domain())
1678 err
= xen_pcibk_config_init();
1683 err
= pcistub_init();
1688 pcistub_init_devices_late();
1689 err
= xen_pcibk_xenbus_register();
1692 #ifdef CONFIG_PCI_IOV
1694 bus_register_notifier(&pci_bus_type
, &pci_stub_nb
);
1700 static void __exit
xen_pcibk_cleanup(void)
1702 #ifdef CONFIG_PCI_IOV
1703 bus_unregister_notifier(&pci_bus_type
, &pci_stub_nb
);
1705 xen_pcibk_xenbus_unregister();
1709 module_init(xen_pcibk_init
);
1710 module_exit(xen_pcibk_cleanup
);
1712 MODULE_LICENSE("Dual BSD/GPL");
1713 MODULE_ALIAS("xen-backend:pci");