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