vfio_ap_private.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Private data and functions for adjunct processor VFIO matrix driver.
  4. *
  5. * Author(s): Tony Krowiak <akrowiak@linux.ibm.com>
  6. * Halil Pasic <pasic@linux.ibm.com>
  7. * Pierre Morel <pmorel@linux.ibm.com>
  8. *
  9. * Copyright IBM Corp. 2018
  10. */
  11. #ifndef _VFIO_AP_PRIVATE_H_
  12. #define _VFIO_AP_PRIVATE_H_
  13. #include <linux/types.h>
  14. #include <linux/device.h>
  15. #include <linux/mdev.h>
  16. #include <linux/delay.h>
  17. #include <linux/mutex.h>
  18. #include <linux/kvm_host.h>
  19. #include "ap_bus.h"
  20. #define VFIO_AP_MODULE_NAME "vfio_ap"
  21. #define VFIO_AP_DRV_NAME "vfio_ap"
  22. /**
  23. * ap_matrix_dev - the AP matrix device structure
  24. * @device: generic device structure associated with the AP matrix device
  25. * @available_instances: number of mediated matrix devices that can be created
  26. * @info: the struct containing the output from the PQAP(QCI) instruction
  27. * mdev_list: the list of mediated matrix devices created
  28. * lock: mutex for locking the AP matrix device. This lock will be
  29. * taken every time we fiddle with state managed by the vfio_ap
  30. * driver, be it using @mdev_list or writing the state of a
  31. * single ap_matrix_mdev device. It's quite coarse but we don't
  32. * expect much contention.
  33. */
  34. struct ap_matrix_dev {
  35. struct device device;
  36. atomic_t available_instances;
  37. struct ap_config_info info;
  38. struct list_head mdev_list;
  39. struct mutex lock;
  40. struct ap_driver *vfio_ap_drv;
  41. };
  42. extern struct ap_matrix_dev *matrix_dev;
  43. /**
  44. * The AP matrix is comprised of three bit masks identifying the adapters,
  45. * queues (domains) and control domains that belong to an AP matrix. The bits i
  46. * each mask, from least significant to most significant bit, correspond to IDs
  47. * 0 to 255. When a bit is set, the corresponding ID belongs to the matrix.
  48. *
  49. * @apm_max: max adapter number in @apm
  50. * @apm identifies the AP adapters in the matrix
  51. * @aqm_max: max domain number in @aqm
  52. * @aqm identifies the AP queues (domains) in the matrix
  53. * @adm_max: max domain number in @adm
  54. * @adm identifies the AP control domains in the matrix
  55. */
  56. struct ap_matrix {
  57. unsigned long apm_max;
  58. DECLARE_BITMAP(apm, 256);
  59. unsigned long aqm_max;
  60. DECLARE_BITMAP(aqm, 256);
  61. unsigned long adm_max;
  62. DECLARE_BITMAP(adm, 256);
  63. };
  64. /**
  65. * struct ap_matrix_mdev - the mediated matrix device structure
  66. * @list: allows the ap_matrix_mdev struct to be added to a list
  67. * @matrix: the adapters, usage domains and control domains assigned to the
  68. * mediated matrix device.
  69. * @group_notifier: notifier block used for specifying callback function for
  70. * handling the VFIO_GROUP_NOTIFY_SET_KVM event
  71. * @kvm: the struct holding guest's state
  72. */
  73. struct ap_matrix_mdev {
  74. struct list_head node;
  75. struct ap_matrix matrix;
  76. struct notifier_block group_notifier;
  77. struct notifier_block iommu_notifier;
  78. struct kvm *kvm;
  79. struct kvm_s390_module_hook pqap_hook;
  80. struct mdev_device *mdev;
  81. };
  82. struct vfio_ap_queue {
  83. struct ap_matrix_mdev *matrix_mdev;
  84. unsigned long saved_pfn;
  85. int apqn;
  86. #define VFIO_AP_ISC_INVALID 0xff
  87. unsigned char saved_isc;
  88. };
  89. int vfio_ap_mdev_register(void);
  90. void vfio_ap_mdev_unregister(void);
  91. int vfio_ap_mdev_reset_queue(struct vfio_ap_queue *q,
  92. unsigned int retry);
  93. #endif /* _VFIO_AP_PRIVATE_H_ */