drivers/vfio: Fix EEH build error
[cascardo/linux.git] / drivers / vfio / vfio_spapr_eeh.c
1 /*
2  * EEH functionality support for VFIO devices. The feature is only
3  * available on sPAPR compatible platforms.
4  *
5  * Copyright Gavin Shan, IBM Corporation 2014.
6  *
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.
10  */
11
12 #include <linux/uaccess.h>
13 #include <linux/vfio.h>
14 #include <asm/eeh.h>
15
16 /* We might build address mapping here for "fast" path later */
17 int vfio_spapr_pci_eeh_open(struct pci_dev *pdev)
18 {
19         return eeh_dev_open(pdev);
20 }
21 EXPORT_SYMBOL_GPL(vfio_spapr_pci_eeh_open);
22
23 void vfio_spapr_pci_eeh_release(struct pci_dev *pdev)
24 {
25         eeh_dev_release(pdev);
26 }
27 EXPORT_SYMBOL_GPL(vfio_spapr_pci_eeh_release);
28
29 long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group,
30                                 unsigned int cmd, unsigned long arg)
31 {
32         struct eeh_pe *pe;
33         struct vfio_eeh_pe_op op;
34         unsigned long minsz;
35         long ret = -EINVAL;
36
37         switch (cmd) {
38         case VFIO_CHECK_EXTENSION:
39                 if (arg == VFIO_EEH)
40                         ret = eeh_enabled() ? 1 : 0;
41                 else
42                         ret = 0;
43                 break;
44         case VFIO_EEH_PE_OP:
45                 pe = eeh_iommu_group_to_pe(group);
46                 if (!pe)
47                         return -ENODEV;
48
49                 minsz = offsetofend(struct vfio_eeh_pe_op, op);
50                 if (copy_from_user(&op, (void __user *)arg, minsz))
51                         return -EFAULT;
52                 if (op.argsz < minsz || op.flags)
53                         return -EINVAL;
54
55                 switch (op.op) {
56                 case VFIO_EEH_PE_DISABLE:
57                         ret = eeh_pe_set_option(pe, EEH_OPT_DISABLE);
58                         break;
59                 case VFIO_EEH_PE_ENABLE:
60                         ret = eeh_pe_set_option(pe, EEH_OPT_ENABLE);
61                         break;
62                 case VFIO_EEH_PE_UNFREEZE_IO:
63                         ret = eeh_pe_set_option(pe, EEH_OPT_THAW_MMIO);
64                         break;
65                 case VFIO_EEH_PE_UNFREEZE_DMA:
66                         ret = eeh_pe_set_option(pe, EEH_OPT_THAW_DMA);
67                         break;
68                 case VFIO_EEH_PE_GET_STATE:
69                         ret = eeh_pe_get_state(pe);
70                         break;
71                 case VFIO_EEH_PE_RESET_DEACTIVATE:
72                         ret = eeh_pe_reset(pe, EEH_RESET_DEACTIVATE);
73                         break;
74                 case VFIO_EEH_PE_RESET_HOT:
75                         ret = eeh_pe_reset(pe, EEH_RESET_HOT);
76                         break;
77                 case VFIO_EEH_PE_RESET_FUNDAMENTAL:
78                         ret = eeh_pe_reset(pe, EEH_RESET_FUNDAMENTAL);
79                         break;
80                 case VFIO_EEH_PE_CONFIGURE:
81                         ret = eeh_pe_configure(pe);
82                         break;
83                 default:
84                         ret = -EINVAL;
85                 }
86         }
87
88         return ret;
89 }
90 EXPORT_SYMBOL(vfio_spapr_iommu_eeh_ioctl);