Gavin Shan | 1b69be5 | 2014-06-10 11:41:57 +1000 | [diff] [blame] | 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 | |
Alexey Kardashevskiy | 89a2edd | 2014-08-08 10:37:51 -0600 | [diff] [blame] | 12 | #include <linux/module.h> |
Gavin Shan | 1b69be5 | 2014-06-10 11:41:57 +1000 | [diff] [blame] | 13 | #include <linux/uaccess.h> |
| 14 | #include <linux/vfio.h> |
| 15 | #include <asm/eeh.h> |
| 16 | |
Alexey Kardashevskiy | 89a2edd | 2014-08-08 10:37:51 -0600 | [diff] [blame] | 17 | #define DRIVER_VERSION "0.1" |
| 18 | #define DRIVER_AUTHOR "Gavin Shan, IBM Corporation" |
| 19 | #define DRIVER_DESC "VFIO IOMMU SPAPR EEH" |
| 20 | |
Gavin Shan | 1b69be5 | 2014-06-10 11:41:57 +1000 | [diff] [blame] | 21 | /* We might build address mapping here for "fast" path later */ |
Alexey Kardashevskiy | 9b936c9 | 2014-08-08 10:39:16 -0600 | [diff] [blame] | 22 | void vfio_spapr_pci_eeh_open(struct pci_dev *pdev) |
Gavin Shan | 1b69be5 | 2014-06-10 11:41:57 +1000 | [diff] [blame] | 23 | { |
Alexey Kardashevskiy | 9b936c9 | 2014-08-08 10:39:16 -0600 | [diff] [blame] | 24 | eeh_dev_open(pdev); |
Gavin Shan | 1b69be5 | 2014-06-10 11:41:57 +1000 | [diff] [blame] | 25 | } |
Gavin Shan | 92d18a6 | 2014-08-08 10:36:20 -0600 | [diff] [blame] | 26 | EXPORT_SYMBOL_GPL(vfio_spapr_pci_eeh_open); |
Gavin Shan | 1b69be5 | 2014-06-10 11:41:57 +1000 | [diff] [blame] | 27 | |
| 28 | void vfio_spapr_pci_eeh_release(struct pci_dev *pdev) |
| 29 | { |
| 30 | eeh_dev_release(pdev); |
| 31 | } |
Gavin Shan | 92d18a6 | 2014-08-08 10:36:20 -0600 | [diff] [blame] | 32 | EXPORT_SYMBOL_GPL(vfio_spapr_pci_eeh_release); |
Gavin Shan | 1b69be5 | 2014-06-10 11:41:57 +1000 | [diff] [blame] | 33 | |
| 34 | long vfio_spapr_iommu_eeh_ioctl(struct iommu_group *group, |
| 35 | unsigned int cmd, unsigned long arg) |
| 36 | { |
| 37 | struct eeh_pe *pe; |
| 38 | struct vfio_eeh_pe_op op; |
| 39 | unsigned long minsz; |
| 40 | long ret = -EINVAL; |
| 41 | |
| 42 | switch (cmd) { |
| 43 | case VFIO_CHECK_EXTENSION: |
| 44 | if (arg == VFIO_EEH) |
| 45 | ret = eeh_enabled() ? 1 : 0; |
| 46 | else |
| 47 | ret = 0; |
| 48 | break; |
| 49 | case VFIO_EEH_PE_OP: |
| 50 | pe = eeh_iommu_group_to_pe(group); |
| 51 | if (!pe) |
| 52 | return -ENODEV; |
| 53 | |
| 54 | minsz = offsetofend(struct vfio_eeh_pe_op, op); |
| 55 | if (copy_from_user(&op, (void __user *)arg, minsz)) |
| 56 | return -EFAULT; |
| 57 | if (op.argsz < minsz || op.flags) |
| 58 | return -EINVAL; |
| 59 | |
| 60 | switch (op.op) { |
| 61 | case VFIO_EEH_PE_DISABLE: |
| 62 | ret = eeh_pe_set_option(pe, EEH_OPT_DISABLE); |
| 63 | break; |
| 64 | case VFIO_EEH_PE_ENABLE: |
| 65 | ret = eeh_pe_set_option(pe, EEH_OPT_ENABLE); |
| 66 | break; |
| 67 | case VFIO_EEH_PE_UNFREEZE_IO: |
| 68 | ret = eeh_pe_set_option(pe, EEH_OPT_THAW_MMIO); |
| 69 | break; |
| 70 | case VFIO_EEH_PE_UNFREEZE_DMA: |
| 71 | ret = eeh_pe_set_option(pe, EEH_OPT_THAW_DMA); |
| 72 | break; |
| 73 | case VFIO_EEH_PE_GET_STATE: |
| 74 | ret = eeh_pe_get_state(pe); |
| 75 | break; |
| 76 | case VFIO_EEH_PE_RESET_DEACTIVATE: |
| 77 | ret = eeh_pe_reset(pe, EEH_RESET_DEACTIVATE); |
| 78 | break; |
| 79 | case VFIO_EEH_PE_RESET_HOT: |
| 80 | ret = eeh_pe_reset(pe, EEH_RESET_HOT); |
| 81 | break; |
| 82 | case VFIO_EEH_PE_RESET_FUNDAMENTAL: |
| 83 | ret = eeh_pe_reset(pe, EEH_RESET_FUNDAMENTAL); |
| 84 | break; |
| 85 | case VFIO_EEH_PE_CONFIGURE: |
| 86 | ret = eeh_pe_configure(pe); |
| 87 | break; |
| 88 | default: |
| 89 | ret = -EINVAL; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | return ret; |
| 94 | } |
Gavin Shan | 92d18a6 | 2014-08-08 10:36:20 -0600 | [diff] [blame] | 95 | EXPORT_SYMBOL(vfio_spapr_iommu_eeh_ioctl); |
Alexey Kardashevskiy | 89a2edd | 2014-08-08 10:37:51 -0600 | [diff] [blame] | 96 | |
| 97 | MODULE_VERSION(DRIVER_VERSION); |
| 98 | MODULE_LICENSE("GPL v2"); |
| 99 | MODULE_AUTHOR(DRIVER_AUTHOR); |
| 100 | MODULE_DESCRIPTION(DRIVER_DESC); |