vfio_ap_private.h 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. *
  8. * Copyright IBM Corp. 2018
  9. */
  10. #ifndef _VFIO_AP_PRIVATE_H_
  11. #define _VFIO_AP_PRIVATE_H_
  12. #include <linux/types.h>
  13. #include <linux/device.h>
  14. #include <linux/mdev.h>
  15. #include <linux/delay.h>
  16. #include <linux/mutex.h>
  17. #include "ap_bus.h"
  18. #define VFIO_AP_MODULE_NAME "vfio_ap"
  19. #define VFIO_AP_DRV_NAME "vfio_ap"
  20. /**
  21. * ap_matrix_dev - the AP matrix device structure
  22. * @device: generic device structure associated with the AP matrix device
  23. * @available_instances: number of mediated matrix devices that can be created
  24. * @info: the struct containing the output from the PQAP(QCI) instruction
  25. * mdev_list: the list of mediated matrix devices created
  26. * lock: mutex for locking the AP matrix device. This lock will be
  27. * taken every time we fiddle with state managed by the vfio_ap
  28. * driver, be it using @mdev_list or writing the state of a
  29. * single ap_matrix_mdev device. It's quite coarse but we don't
  30. * expect much contention.
  31. */
  32. struct ap_matrix_dev {
  33. struct device device;
  34. atomic_t available_instances;
  35. struct ap_config_info info;
  36. struct list_head mdev_list;
  37. struct mutex lock;
  38. };
  39. extern struct ap_matrix_dev *matrix_dev;
  40. /**
  41. * The AP matrix is comprised of three bit masks identifying the adapters,
  42. * queues (domains) and control domains that belong to an AP matrix. The bits i
  43. * each mask, from least significant to most significant bit, correspond to IDs
  44. * 0 to 255. When a bit is set, the corresponding ID belongs to the matrix.
  45. *
  46. * @apm_max: max adapter number in @apm
  47. * @apm identifies the AP adapters in the matrix
  48. * @aqm_max: max domain number in @aqm
  49. * @aqm identifies the AP queues (domains) in the matrix
  50. * @adm_max: max domain number in @adm
  51. * @adm identifies the AP control domains in the matrix
  52. */
  53. struct ap_matrix {
  54. unsigned long apm_max;
  55. DECLARE_BITMAP(apm, 256);
  56. unsigned long aqm_max;
  57. DECLARE_BITMAP(aqm, 256);
  58. unsigned long adm_max;
  59. DECLARE_BITMAP(adm, 256);
  60. };
  61. /**
  62. * struct ap_matrix_mdev - the mediated matrix device structure
  63. * @list: allows the ap_matrix_mdev struct to be added to a list
  64. * @matrix: the adapters, usage domains and control domains assigned to the
  65. * mediated matrix device.
  66. * @group_notifier: notifier block used for specifying callback function for
  67. * handling the VFIO_GROUP_NOTIFY_SET_KVM event
  68. * @kvm: the struct holding guest's state
  69. */
  70. struct ap_matrix_mdev {
  71. struct list_head node;
  72. struct ap_matrix matrix;
  73. struct notifier_block group_notifier;
  74. struct kvm *kvm;
  75. };
  76. extern int vfio_ap_mdev_register(void);
  77. extern void vfio_ap_mdev_unregister(void);
  78. #endif /* _VFIO_AP_PRIVATE_H_ */