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