xref: /linux/drivers/s390/crypto/vfio_ap_private.h (revision 62e358ce586b53562a5efcfdbaddc5bd285e6484)
11fde5734STony Krowiak /* SPDX-License-Identifier: GPL-2.0 */
21fde5734STony Krowiak /*
31fde5734STony Krowiak  * Private data and functions for adjunct processor VFIO matrix driver.
41fde5734STony Krowiak  *
51fde5734STony Krowiak  * Author(s): Tony Krowiak <akrowiak@linux.ibm.com>
665f06713STony Krowiak  *	      Halil Pasic <pasic@linux.ibm.com>
71fde5734STony Krowiak  *
81fde5734STony Krowiak  * Copyright IBM Corp. 2018
91fde5734STony Krowiak  */
101fde5734STony Krowiak 
111fde5734STony Krowiak #ifndef _VFIO_AP_PRIVATE_H_
121fde5734STony Krowiak #define _VFIO_AP_PRIVATE_H_
131fde5734STony Krowiak 
141fde5734STony Krowiak #include <linux/types.h>
151fde5734STony Krowiak #include <linux/device.h>
161fde5734STony Krowiak #include <linux/mdev.h>
171fde5734STony Krowiak #include <linux/delay.h>
181fde5734STony Krowiak #include <linux/mutex.h>
19e5282de9SPierre Morel #include <linux/kvm_host.h>
201fde5734STony Krowiak 
211fde5734STony Krowiak #include "ap_bus.h"
221fde5734STony Krowiak 
231fde5734STony Krowiak #define VFIO_AP_MODULE_NAME "vfio_ap"
241fde5734STony Krowiak #define VFIO_AP_DRV_NAME "vfio_ap"
251fde5734STony Krowiak 
261fde5734STony Krowiak /**
271fde5734STony Krowiak  * ap_matrix_dev - the AP matrix device structure
281fde5734STony Krowiak  * @device:	generic device structure associated with the AP matrix device
2965f06713STony Krowiak  * @available_instances: number of mediated matrix devices that can be created
3065f06713STony Krowiak  * @info:	the struct containing the output from the PQAP(QCI) instruction
3165f06713STony Krowiak  * mdev_list:	the list of mediated matrix devices created
3265f06713STony Krowiak  * lock:	mutex for locking the AP matrix device. This lock will be
3365f06713STony Krowiak  *		taken every time we fiddle with state managed by the vfio_ap
3465f06713STony Krowiak  *		driver, be it using @mdev_list or writing the state of a
3565f06713STony Krowiak  *		single ap_matrix_mdev device. It's quite coarse but we don't
3665f06713STony Krowiak  *		expect much contention.
371fde5734STony Krowiak  */
381fde5734STony Krowiak struct ap_matrix_dev {
391fde5734STony Krowiak 	struct device device;
4065f06713STony Krowiak 	atomic_t available_instances;
4165f06713STony Krowiak 	struct ap_config_info info;
4265f06713STony Krowiak 	struct list_head mdev_list;
4365f06713STony Krowiak 	struct mutex lock;
4436360658SPierre Morel 	struct ap_driver  *vfio_ap_drv;
451fde5734STony Krowiak };
461fde5734STony Krowiak 
471fde5734STony Krowiak extern struct ap_matrix_dev *matrix_dev;
481fde5734STony Krowiak 
4965f06713STony Krowiak /**
5065f06713STony Krowiak  * The AP matrix is comprised of three bit masks identifying the adapters,
5165f06713STony Krowiak  * queues (domains) and control domains that belong to an AP matrix. The bits i
5265f06713STony Krowiak  * each mask, from least significant to most significant bit, correspond to IDs
5365f06713STony Krowiak  * 0 to 255. When a bit is set, the corresponding ID belongs to the matrix.
5465f06713STony Krowiak  *
5565f06713STony Krowiak  * @apm_max: max adapter number in @apm
5665f06713STony Krowiak  * @apm identifies the AP adapters in the matrix
5765f06713STony Krowiak  * @aqm_max: max domain number in @aqm
5865f06713STony Krowiak  * @aqm identifies the AP queues (domains) in the matrix
5965f06713STony Krowiak  * @adm_max: max domain number in @adm
6065f06713STony Krowiak  * @adm identifies the AP control domains in the matrix
6165f06713STony Krowiak  */
6265f06713STony Krowiak struct ap_matrix {
6365f06713STony Krowiak 	unsigned long apm_max;
6465f06713STony Krowiak 	DECLARE_BITMAP(apm, 256);
6565f06713STony Krowiak 	unsigned long aqm_max;
6665f06713STony Krowiak 	DECLARE_BITMAP(aqm, 256);
6765f06713STony Krowiak 	unsigned long adm_max;
6865f06713STony Krowiak 	DECLARE_BITMAP(adm, 256);
6965f06713STony Krowiak };
7065f06713STony Krowiak 
7165f06713STony Krowiak /**
7265f06713STony Krowiak  * struct ap_matrix_mdev - the mediated matrix device structure
7365f06713STony Krowiak  * @list:	allows the ap_matrix_mdev struct to be added to a list
7465f06713STony Krowiak  * @matrix:	the adapters, usage domains and control domains assigned to the
7565f06713STony Krowiak  *		mediated matrix device.
76258287c9STony Krowiak  * @group_notifier: notifier block used for specifying callback function for
77258287c9STony Krowiak  *		    handling the VFIO_GROUP_NOTIFY_SET_KVM event
78258287c9STony Krowiak  * @kvm:	the struct holding guest's state
7965f06713STony Krowiak  */
8065f06713STony Krowiak struct ap_matrix_mdev {
8165f06713STony Krowiak 	struct list_head node;
8265f06713STony Krowiak 	struct ap_matrix matrix;
83258287c9STony Krowiak 	struct notifier_block group_notifier;
84*62e358ceSPierre Morel 	struct notifier_block iommu_notifier;
85258287c9STony Krowiak 	struct kvm *kvm;
86e5282de9SPierre Morel 	struct kvm_s390_module_hook pqap_hook;
87*62e358ceSPierre Morel 	struct mdev_device *mdev;
8865f06713STony Krowiak };
8965f06713STony Krowiak 
9065f06713STony Krowiak extern int vfio_ap_mdev_register(void);
9165f06713STony Krowiak extern void vfio_ap_mdev_unregister(void);
9265f06713STony Krowiak 
931fde5734STony Krowiak #endif /* _VFIO_AP_PRIVATE_H_ */
94