vfio_spapr_eeh.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. #include <linux/module.h>
  12. #include <linux/uaccess.h>
  13. #include <linux/vfio.h>
  14. #include <asm/eeh.h>
  15. #define DRIVER_VERSION "0.1"
  16. #define DRIVER_AUTHOR "Gavin Shan, IBM Corporation"
  17. #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)
  20. {
  21. eeh_dev_open(pdev);
  22. }
  23. EXPORT_SYMBOL_GPL(vfio_spapr_pci_eeh_open);
  24. void vfio_spapr_pci_eeh_release(struct pci_dev *pdev)
  25. {
  26. eeh_dev_release(pdev);
  27. }
  28. EXPORT_SYMBOL_GPL(vfio_spapr_pci_eeh_release);
  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. switch (cmd) {
  37. case VFIO_CHECK_EXTENSION:
  38. if (arg == VFIO_EEH)
  39. ret = eeh_enabled() ? 1 : 0;
  40. else
  41. ret = 0;
  42. break;
  43. case VFIO_EEH_PE_OP:
  44. pe = eeh_iommu_group_to_pe(group);
  45. if (!pe)
  46. return -ENODEV;
  47. minsz = offsetofend(struct vfio_eeh_pe_op, op);
  48. if (copy_from_user(&op, (void __user *)arg, minsz))
  49. return -EFAULT;
  50. if (op.argsz < minsz || op.flags)
  51. return -EINVAL;
  52. switch (op.op) {
  53. case VFIO_EEH_PE_DISABLE:
  54. ret = eeh_pe_set_option(pe, EEH_OPT_DISABLE);
  55. break;
  56. case VFIO_EEH_PE_ENABLE:
  57. ret = eeh_pe_set_option(pe, EEH_OPT_ENABLE);
  58. break;
  59. case VFIO_EEH_PE_UNFREEZE_IO:
  60. ret = eeh_pe_set_option(pe, EEH_OPT_THAW_MMIO);
  61. break;
  62. case VFIO_EEH_PE_UNFREEZE_DMA:
  63. ret = eeh_pe_set_option(pe, EEH_OPT_THAW_DMA);
  64. break;
  65. case VFIO_EEH_PE_GET_STATE:
  66. ret = eeh_pe_get_state(pe);
  67. break;
  68. case VFIO_EEH_PE_RESET_DEACTIVATE:
  69. ret = eeh_pe_reset(pe, EEH_RESET_DEACTIVATE);
  70. break;
  71. case VFIO_EEH_PE_RESET_HOT:
  72. ret = eeh_pe_reset(pe, EEH_RESET_HOT);
  73. break;
  74. case VFIO_EEH_PE_RESET_FUNDAMENTAL:
  75. ret = eeh_pe_reset(pe, EEH_RESET_FUNDAMENTAL);
  76. break;
  77. case VFIO_EEH_PE_CONFIGURE:
  78. ret = eeh_pe_configure(pe);
  79. break;
  80. case VFIO_EEH_PE_INJECT_ERR:
  81. minsz = offsetofend(struct vfio_eeh_pe_op, err.mask);
  82. if (op.argsz < minsz)
  83. return -EINVAL;
  84. if (copy_from_user(&op, (void __user *)arg, minsz))
  85. return -EFAULT;
  86. ret = eeh_pe_inject_err(pe, op.err.type, op.err.func,
  87. op.err.addr, op.err.mask);
  88. break;
  89. default:
  90. ret = -EINVAL;
  91. }
  92. }
  93. return ret;
  94. }
  95. EXPORT_SYMBOL_GPL(vfio_spapr_iommu_eeh_ioctl);
  96. MODULE_VERSION(DRIVER_VERSION);
  97. MODULE_LICENSE("GPL v2");
  98. MODULE_AUTHOR(DRIVER_AUTHOR);
  99. MODULE_DESCRIPTION(DRIVER_DESC);