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