2 * EEH functionality support for VFIO devices. The feature is only
3 * available on sPAPR compatible platforms.
5 * Copyright Gavin Shan, IBM Corporation 2014.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include <linux/module.h>
13 #include <linux/uaccess.h>
14 #include <linux/vfio.h>
17 #define DRIVER_VERSION "0.1"
18 #define DRIVER_AUTHOR "Gavin Shan, IBM Corporation"
19 #define DRIVER_DESC "VFIO IOMMU SPAPR EEH"
21 /* We might build address mapping here for "fast" path later */
22 void vfio_spapr_pci_eeh_open(struct pci_dev *pdev)
26 EXPORT_SYMBOL_GPL(vfio_spapr_pci_eeh_open);
28 void vfio_spapr_pci_eeh_release(struct pci_dev *pdev)
30 eeh_dev_release(pdev);
32 EXPORT_SYMBOL_GPL(vfio_spapr_pci_eeh_release);
34 long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,
35 unsigned int cmd, unsigned long arg)
38 struct vfio_eeh_pe_op op;
43 case VFIO_CHECK_EXTENSION:
45 ret = eeh_enabled() ? 1 : 0;
50 pe = eeh_iommu_group_to_pe(group);
54 minsz = offsetofend(struct vfio_eeh_pe_op, op);
55 if (copy_from_user(&op, (void __user *)arg, minsz))
57 if (op.argsz < minsz || op.flags)
61 case VFIO_EEH_PE_DISABLE:
62 ret = eeh_pe_set_option(pe, EEH_OPT_DISABLE);
64 case VFIO_EEH_PE_ENABLE:
65 ret = eeh_pe_set_option(pe, EEH_OPT_ENABLE);
67 case VFIO_EEH_PE_UNFREEZE_IO:
68 ret = eeh_pe_set_option(pe, EEH_OPT_THAW_MMIO);
70 case VFIO_EEH_PE_UNFREEZE_DMA:
71 ret = eeh_pe_set_option(pe, EEH_OPT_THAW_DMA);
73 case VFIO_EEH_PE_GET_STATE:
74 ret = eeh_pe_get_state(pe);
76 case VFIO_EEH_PE_RESET_DEACTIVATE:
77 ret = eeh_pe_reset(pe, EEH_RESET_DEACTIVATE);
79 case VFIO_EEH_PE_RESET_HOT:
80 ret = eeh_pe_reset(pe, EEH_RESET_HOT);
82 case VFIO_EEH_PE_RESET_FUNDAMENTAL:
83 ret = eeh_pe_reset(pe, EEH_RESET_FUNDAMENTAL);
85 case VFIO_EEH_PE_CONFIGURE:
86 ret = eeh_pe_configure(pe);
88 case VFIO_EEH_PE_INJECT_ERR:
89 minsz = offsetofend(struct vfio_eeh_pe_op, err.mask);
92 if (copy_from_user(&op, (void __user *)arg, minsz))
95 ret = eeh_pe_inject_err(pe, op.err.type, op.err.func,
96 op.err.addr, op.err.mask);
105 EXPORT_SYMBOL_GPL(vfio_spapr_iommu_eeh_ioctl);
107 MODULE_VERSION(DRIVER_VERSION);
108 MODULE_LICENSE("GPL v2");
109 MODULE_AUTHOR(DRIVER_AUTHOR);
110 MODULE_DESCRIPTION(DRIVER_DESC);