Commit | Line | Data |
---|---|---|
1fde5734 TK |
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> | |
65f06713 | 6 | * Halil Pasic <pasic@linux.ibm.com> |
ec89b55e | 7 | * Pierre Morel <pmorel@linux.ibm.com> |
1fde5734 TK |
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> | |
e5282de9 | 20 | #include <linux/kvm_host.h> |
eb0feefd | 21 | #include <linux/vfio.h> |
11cb2419 | 22 | #include <linux/hashtable.h> |
1fde5734 TK |
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 | /** | |
5ef4f710 TK |
30 | * struct ap_matrix_dev - Contains the data for the matrix device. |
31 | * | |
1fde5734 | 32 | * @device: generic device structure associated with the AP matrix device |
65f06713 TK |
33 | * @available_instances: number of mediated matrix devices that can be created |
34 | * @info: the struct containing the output from the PQAP(QCI) instruction | |
5ef4f710 | 35 | * @mdev_list: the list of mediated matrix devices created |
d0786556 | 36 | * @mdevs_lock: mutex for locking the AP matrix device. This lock will be |
65f06713 TK |
37 | * taken every time we fiddle with state managed by the vfio_ap |
38 | * driver, be it using @mdev_list or writing the state of a | |
39 | * single ap_matrix_mdev device. It's quite coarse but we don't | |
40 | * expect much contention. | |
5ef4f710 | 41 | * @vfio_ap_drv: the vfio_ap device driver |
21195eb0 TK |
42 | * @guests_lock: mutex for controlling access to a guest that is using AP |
43 | * devices passed through by the vfio_ap device driver. This lock | |
44 | * will be taken when the AP devices are plugged into or unplugged | |
45 | * from a guest, and when an ap_matrix_mdev device is added to or | |
46 | * removed from @mdev_list or the list is iterated. | |
1fde5734 TK |
47 | */ |
48 | struct ap_matrix_dev { | |
49 | struct device device; | |
65f06713 TK |
50 | atomic_t available_instances; |
51 | struct ap_config_info info; | |
52 | struct list_head mdev_list; | |
d0786556 | 53 | struct mutex mdevs_lock; /* serializes access to each ap_matrix_mdev */ |
36360658 | 54 | struct ap_driver *vfio_ap_drv; |
21195eb0 | 55 | struct mutex guests_lock; /* serializes access to each KVM guest */ |
1fde5734 TK |
56 | }; |
57 | ||
58 | extern struct ap_matrix_dev *matrix_dev; | |
59 | ||
65f06713 | 60 | /** |
5ef4f710 | 61 | * struct ap_matrix - matrix of adapters, domains and control domains |
65f06713 TK |
62 | * |
63 | * @apm_max: max adapter number in @apm | |
5ef4f710 | 64 | * @apm: identifies the AP adapters in the matrix |
65f06713 | 65 | * @aqm_max: max domain number in @aqm |
5ef4f710 | 66 | * @aqm: identifies the AP queues (domains) in the matrix |
65f06713 | 67 | * @adm_max: max domain number in @adm |
5ef4f710 TK |
68 | * @adm: identifies the AP control domains in the matrix |
69 | * | |
70 | * The AP matrix is comprised of three bit masks identifying the adapters, | |
71 | * queues (domains) and control domains that belong to an AP matrix. The bits in | |
72 | * each mask, from left to right, correspond to IDs 0 to 255. When a bit is set | |
73 | * the corresponding ID belongs to the matrix. | |
65f06713 TK |
74 | */ |
75 | struct ap_matrix { | |
76 | unsigned long apm_max; | |
77 | DECLARE_BITMAP(apm, 256); | |
78 | unsigned long aqm_max; | |
79 | DECLARE_BITMAP(aqm, 256); | |
80 | unsigned long adm_max; | |
81 | DECLARE_BITMAP(adm, 256); | |
82 | }; | |
83 | ||
11cb2419 TK |
84 | /** |
85 | * struct ap_queue_table - a table of queue objects. | |
86 | * | |
87 | * @queues: a hashtable of queues (struct vfio_ap_queue). | |
88 | */ | |
89 | struct ap_queue_table { | |
90 | DECLARE_HASHTABLE(queues, 8); | |
91 | }; | |
92 | ||
65f06713 | 93 | /** |
5ef4f710 TK |
94 | * struct ap_matrix_mdev - Contains the data associated with a matrix mediated |
95 | * device. | |
96 | * @vdev: the vfio device | |
97 | * @node: allows the ap_matrix_mdev struct to be added to a list | |
65f06713 TK |
98 | * @matrix: the adapters, usage domains and control domains assigned to the |
99 | * mediated matrix device. | |
49b0109f | 100 | * @shadow_apcb: the shadow copy of the APCB field of the KVM guest's CRYCB |
5ef4f710 TK |
101 | * @iommu_notifier: notifier block used for specifying callback function for |
102 | * handling the VFIO_IOMMU_NOTIFY_DMA_UNMAP even | |
258287c9 | 103 | * @kvm: the struct holding guest's state |
5ef4f710 TK |
104 | * @pqap_hook: the function pointer to the interception handler for the |
105 | * PQAP(AQIC) instruction. | |
106 | * @mdev: the mediated device | |
11cb2419 | 107 | * @qtable: table of queues (struct vfio_ap_queue) assigned to the mdev |
65f06713 TK |
108 | */ |
109 | struct ap_matrix_mdev { | |
eb0feefd | 110 | struct vfio_device vdev; |
65f06713 TK |
111 | struct list_head node; |
112 | struct ap_matrix matrix; | |
49b0109f | 113 | struct ap_matrix shadow_apcb; |
62e358ce | 114 | struct notifier_block iommu_notifier; |
258287c9 | 115 | struct kvm *kvm; |
1e753732 | 116 | crypto_hook pqap_hook; |
62e358ce | 117 | struct mdev_device *mdev; |
11cb2419 | 118 | struct ap_queue_table qtable; |
65f06713 TK |
119 | }; |
120 | ||
5ef4f710 TK |
121 | /** |
122 | * struct vfio_ap_queue - contains the data associated with a queue bound to the | |
123 | * vfio_ap device driver | |
124 | * @matrix_mdev: the matrix mediated device | |
125 | * @saved_pfn: the guest PFN pinned for the guest | |
126 | * @apqn: the APQN of the AP queue device | |
127 | * @saved_isc: the guest ISC registered with the GIB interface | |
11cb2419 | 128 | * @mdev_qnode: allows the vfio_ap_queue struct to be added to a hashtable |
70aeefe5 | 129 | * @reset_rc: the status response code from the last reset of the queue |
5ef4f710 | 130 | */ |
ec89b55e PM |
131 | struct vfio_ap_queue { |
132 | struct ap_matrix_mdev *matrix_mdev; | |
133 | unsigned long saved_pfn; | |
134 | int apqn; | |
135 | #define VFIO_AP_ISC_INVALID 0xff | |
136 | unsigned char saved_isc; | |
11cb2419 | 137 | struct hlist_node mdev_qnode; |
70aeefe5 | 138 | unsigned int reset_rc; |
ec89b55e | 139 | }; |
6c12a638 TK |
140 | |
141 | int vfio_ap_mdev_register(void); | |
142 | void vfio_ap_mdev_unregister(void); | |
260f3ea1 TK |
143 | |
144 | int vfio_ap_mdev_probe_queue(struct ap_device *queue); | |
145 | void vfio_ap_mdev_remove_queue(struct ap_device *queue); | |
6c12a638 | 146 | |
1fde5734 | 147 | #endif /* _VFIO_AP_PRIVATE_H_ */ |