1 // SPDX-License-Identifier: GPL-2.0-only
3 * EEH functionality support for VFIO devices. The feature is only
4 * available on sPAPR compatible platforms.
6 * Copyright Gavin Shan, IBM Corporation 2014.
9 #include <linux/module.h>
10 #include <linux/uaccess.h>
11 #include <linux/vfio.h>
14 #define DRIVER_VERSION "0.1"
15 #define DRIVER_AUTHOR "Gavin Shan, IBM Corporation"
16 #define DRIVER_DESC "VFIO IOMMU SPAPR EEH"
18 /* We might build address mapping here for "fast" path later */
19 void vfio_spapr_pci_eeh_open(struct pci_dev
*pdev
)
23 EXPORT_SYMBOL_GPL(vfio_spapr_pci_eeh_open
);
25 void vfio_spapr_pci_eeh_release(struct pci_dev
*pdev
)
27 eeh_dev_release(pdev
);
29 EXPORT_SYMBOL_GPL(vfio_spapr_pci_eeh_release
);
31 long vfio_spapr_iommu_eeh_ioctl(struct iommu_group
*group
,
32 unsigned int cmd
, unsigned long arg
)
35 struct vfio_eeh_pe_op op
;
40 case VFIO_CHECK_EXTENSION
:
42 ret
= eeh_enabled() ? 1 : 0;
47 pe
= eeh_iommu_group_to_pe(group
);
51 minsz
= offsetofend(struct vfio_eeh_pe_op
, op
);
52 if (copy_from_user(&op
, (void __user
*)arg
, minsz
))
54 if (op
.argsz
< minsz
|| op
.flags
)
58 case VFIO_EEH_PE_DISABLE
:
59 ret
= eeh_pe_set_option(pe
, EEH_OPT_DISABLE
);
61 case VFIO_EEH_PE_ENABLE
:
62 ret
= eeh_pe_set_option(pe
, EEH_OPT_ENABLE
);
64 case VFIO_EEH_PE_UNFREEZE_IO
:
65 ret
= eeh_pe_set_option(pe
, EEH_OPT_THAW_MMIO
);
67 case VFIO_EEH_PE_UNFREEZE_DMA
:
68 ret
= eeh_pe_set_option(pe
, EEH_OPT_THAW_DMA
);
70 case VFIO_EEH_PE_GET_STATE
:
71 ret
= eeh_pe_get_state(pe
);
73 case VFIO_EEH_PE_RESET_DEACTIVATE
:
74 ret
= eeh_pe_reset(pe
, EEH_RESET_DEACTIVATE
, true);
76 case VFIO_EEH_PE_RESET_HOT
:
77 ret
= eeh_pe_reset(pe
, EEH_RESET_HOT
, true);
79 case VFIO_EEH_PE_RESET_FUNDAMENTAL
:
80 ret
= eeh_pe_reset(pe
, EEH_RESET_FUNDAMENTAL
, true);
82 case VFIO_EEH_PE_CONFIGURE
:
83 ret
= eeh_pe_configure(pe
);
85 case VFIO_EEH_PE_INJECT_ERR
:
86 minsz
= offsetofend(struct vfio_eeh_pe_op
, err
.mask
);
89 if (copy_from_user(&op
, (void __user
*)arg
, minsz
))
92 ret
= eeh_pe_inject_err(pe
, op
.err
.type
, op
.err
.func
,
93 op
.err
.addr
, op
.err
.mask
);
102 EXPORT_SYMBOL_GPL(vfio_spapr_iommu_eeh_ioctl
);
104 MODULE_VERSION(DRIVER_VERSION
);
105 MODULE_LICENSE("GPL v2");
106 MODULE_AUTHOR(DRIVER_AUTHOR
);
107 MODULE_DESCRIPTION(DRIVER_DESC
);