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