vfio_ap_private.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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 <[email protected]>
  6. * Halil Pasic <[email protected]>
  7. * Pierre Morel <[email protected]>
  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/mdev.h>
  15. #include <linux/delay.h>
  16. #include <linux/mutex.h>
  17. #include <linux/kvm_host.h>
  18. #include <linux/vfio.h>
  19. #include <linux/hashtable.h>
  20. #include "ap_bus.h"
  21. #define VFIO_AP_MODULE_NAME "vfio_ap"
  22. #define VFIO_AP_DRV_NAME "vfio_ap"
  23. /**
  24. * struct ap_matrix_dev - Contains the data for the matrix device.
  25. *
  26. * @device: generic device structure associated with the AP matrix device
  27. * @info: the struct containing the output from the PQAP(QCI) instruction
  28. * @mdev_list: the list of mediated matrix devices created
  29. * @mdevs_lock: mutex for locking the AP matrix device. This lock will be
  30. * taken every time we fiddle with state managed by the vfio_ap
  31. * driver, be it using @mdev_list or writing the state of a
  32. * single ap_matrix_mdev device. It's quite coarse but we don't
  33. * expect much contention.
  34. * @vfio_ap_drv: the vfio_ap device driver
  35. * @guests_lock: mutex for controlling access to a guest that is using AP
  36. * devices passed through by the vfio_ap device driver. This lock
  37. * will be taken when the AP devices are plugged into or unplugged
  38. * from a guest, and when an ap_matrix_mdev device is added to or
  39. * removed from @mdev_list or the list is iterated.
  40. */
  41. struct ap_matrix_dev {
  42. struct device device;
  43. struct ap_config_info info;
  44. struct list_head mdev_list;
  45. struct mutex mdevs_lock; /* serializes access to each ap_matrix_mdev */
  46. struct ap_driver *vfio_ap_drv;
  47. struct mutex guests_lock; /* serializes access to each KVM guest */
  48. struct mdev_parent parent;
  49. struct mdev_type mdev_type;
  50. struct mdev_type *mdev_types[1];
  51. };
  52. extern struct ap_matrix_dev *matrix_dev;
  53. /**
  54. * struct ap_matrix - matrix of adapters, domains and control domains
  55. *
  56. * @apm_max: max adapter number in @apm
  57. * @apm: identifies the AP adapters in the matrix
  58. * @aqm_max: max domain number in @aqm
  59. * @aqm: identifies the AP queues (domains) in the matrix
  60. * @adm_max: max domain number in @adm
  61. * @adm: identifies the AP control domains in the matrix
  62. *
  63. * The AP matrix is comprised of three bit masks identifying the adapters,
  64. * queues (domains) and control domains that belong to an AP matrix. The bits in
  65. * each mask, from left to right, correspond to IDs 0 to 255. When a bit is set
  66. * the corresponding ID belongs to the matrix.
  67. */
  68. struct ap_matrix {
  69. unsigned long apm_max;
  70. DECLARE_BITMAP(apm, 256);
  71. unsigned long aqm_max;
  72. DECLARE_BITMAP(aqm, 256);
  73. unsigned long adm_max;
  74. DECLARE_BITMAP(adm, 256);
  75. };
  76. /**
  77. * struct ap_queue_table - a table of queue objects.
  78. *
  79. * @queues: a hashtable of queues (struct vfio_ap_queue).
  80. */
  81. struct ap_queue_table {
  82. DECLARE_HASHTABLE(queues, 8);
  83. };
  84. /**
  85. * struct ap_matrix_mdev - Contains the data associated with a matrix mediated
  86. * device.
  87. * @vdev: the vfio device
  88. * @node: allows the ap_matrix_mdev struct to be added to a list
  89. * @matrix: the adapters, usage domains and control domains assigned to the
  90. * mediated matrix device.
  91. * @shadow_apcb: the shadow copy of the APCB field of the KVM guest's CRYCB
  92. * @kvm: the struct holding guest's state
  93. * @pqap_hook: the function pointer to the interception handler for the
  94. * PQAP(AQIC) instruction.
  95. * @mdev: the mediated device
  96. * @qtable: table of queues (struct vfio_ap_queue) assigned to the mdev
  97. * @apm_add: bitmap of APIDs added to the host's AP configuration
  98. * @aqm_add: bitmap of APQIs added to the host's AP configuration
  99. * @adm_add: bitmap of control domain numbers added to the host's AP
  100. * configuration
  101. */
  102. struct ap_matrix_mdev {
  103. struct vfio_device vdev;
  104. struct list_head node;
  105. struct ap_matrix matrix;
  106. struct ap_matrix shadow_apcb;
  107. struct kvm *kvm;
  108. crypto_hook pqap_hook;
  109. struct mdev_device *mdev;
  110. struct ap_queue_table qtable;
  111. DECLARE_BITMAP(apm_add, AP_DEVICES);
  112. DECLARE_BITMAP(aqm_add, AP_DOMAINS);
  113. DECLARE_BITMAP(adm_add, AP_DOMAINS);
  114. };
  115. /**
  116. * struct vfio_ap_queue - contains the data associated with a queue bound to the
  117. * vfio_ap device driver
  118. * @matrix_mdev: the matrix mediated device
  119. * @saved_iova: the notification indicator byte (nib) address
  120. * @apqn: the APQN of the AP queue device
  121. * @saved_isc: the guest ISC registered with the GIB interface
  122. * @mdev_qnode: allows the vfio_ap_queue struct to be added to a hashtable
  123. * @reset_rc: the status response code from the last reset of the queue
  124. */
  125. struct vfio_ap_queue {
  126. struct ap_matrix_mdev *matrix_mdev;
  127. dma_addr_t saved_iova;
  128. int apqn;
  129. #define VFIO_AP_ISC_INVALID 0xff
  130. unsigned char saved_isc;
  131. struct hlist_node mdev_qnode;
  132. unsigned int reset_rc;
  133. };
  134. int vfio_ap_mdev_register(void);
  135. void vfio_ap_mdev_unregister(void);
  136. int vfio_ap_mdev_probe_queue(struct ap_device *queue);
  137. void vfio_ap_mdev_remove_queue(struct ap_device *queue);
  138. int vfio_ap_mdev_resource_in_use(unsigned long *apm, unsigned long *aqm);
  139. void vfio_ap_on_cfg_changed(struct ap_config_info *new_config_info,
  140. struct ap_config_info *old_config_info);
  141. void vfio_ap_on_scan_complete(struct ap_config_info *new_config_info,
  142. struct ap_config_info *old_config_info);
  143. #endif /* _VFIO_AP_PRIVATE_H_ */