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