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 };
44 
45 extern struct ap_matrix_dev *matrix_dev;
46 
47 /**
48  * The AP matrix is comprised of three bit masks identifying the adapters,
49  * queues (domains) and control domains that belong to an AP matrix. The bits i
50  * each mask, from least significant to most significant bit, correspond to IDs
51  * 0 to 255. When a bit is set, the corresponding ID belongs to the matrix.
52  *
53  * @apm_max: max adapter number in @apm
54  * @apm identifies the AP adapters in the matrix
55  * @aqm_max: max domain number in @aqm
56  * @aqm identifies the AP queues (domains) in the matrix
57  * @adm_max: max domain number in @adm
58  * @adm identifies the AP control domains in the matrix
59  */
60 struct ap_matrix {
61 	unsigned long apm_max;
62 	DECLARE_BITMAP(apm, 256);
63 	unsigned long aqm_max;
64 	DECLARE_BITMAP(aqm, 256);
65 	unsigned long adm_max;
66 	DECLARE_BITMAP(adm, 256);
67 };
68 
69 /**
70  * struct ap_matrix_mdev - the mediated matrix device structure
71  * @list:	allows the ap_matrix_mdev struct to be added to a list
72  * @matrix:	the adapters, usage domains and control domains assigned to the
73  *		mediated matrix device.
74  * @group_notifier: notifier block used for specifying callback function for
75  *		    handling the VFIO_GROUP_NOTIFY_SET_KVM event
76  * @kvm:	the struct holding guest's state
77  */
78 struct ap_matrix_mdev {
79 	struct list_head node;
80 	struct ap_matrix matrix;
81 	struct notifier_block group_notifier;
82 	struct kvm *kvm;
83 };
84 
85 extern int vfio_ap_mdev_register(void);
86 extern void vfio_ap_mdev_unregister(void);
87 
88 #endif /* _VFIO_AP_PRIVATE_H_ */
89