xref: /linux/drivers/s390/crypto/vfio_ap_private.h (revision 258287c994de8f2f52430b8d79b4fdf2c95f8c91)
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>
191fde5734STony Krowiak 
201fde5734STony Krowiak #include "ap_bus.h"
211fde5734STony Krowiak 
221fde5734STony Krowiak #define VFIO_AP_MODULE_NAME "vfio_ap"
231fde5734STony Krowiak #define VFIO_AP_DRV_NAME "vfio_ap"
241fde5734STony Krowiak 
251fde5734STony Krowiak /**
261fde5734STony Krowiak  * ap_matrix_dev - the AP matrix device structure
271fde5734STony Krowiak  * @device:	generic device structure associated with the AP matrix device
2865f06713STony Krowiak  * @available_instances: number of mediated matrix devices that can be created
2965f06713STony Krowiak  * @info:	the struct containing the output from the PQAP(QCI) instruction
3065f06713STony Krowiak  * mdev_list:	the list of mediated matrix devices created
3165f06713STony Krowiak  * lock:	mutex for locking the AP matrix device. This lock will be
3265f06713STony Krowiak  *		taken every time we fiddle with state managed by the vfio_ap
3365f06713STony Krowiak  *		driver, be it using @mdev_list or writing the state of a
3465f06713STony Krowiak  *		single ap_matrix_mdev device. It's quite coarse but we don't
3565f06713STony Krowiak  *		expect much contention.
361fde5734STony Krowiak  */
371fde5734STony Krowiak struct ap_matrix_dev {
381fde5734STony Krowiak 	struct device device;
3965f06713STony Krowiak 	atomic_t available_instances;
4065f06713STony Krowiak 	struct ap_config_info info;
4165f06713STony Krowiak 	struct list_head mdev_list;
4265f06713STony Krowiak 	struct mutex lock;
431fde5734STony Krowiak };
441fde5734STony Krowiak 
451fde5734STony Krowiak extern struct ap_matrix_dev *matrix_dev;
461fde5734STony Krowiak 
4765f06713STony Krowiak /**
4865f06713STony Krowiak  * The AP matrix is comprised of three bit masks identifying the adapters,
4965f06713STony Krowiak  * queues (domains) and control domains that belong to an AP matrix. The bits i
5065f06713STony Krowiak  * each mask, from least significant to most significant bit, correspond to IDs
5165f06713STony Krowiak  * 0 to 255. When a bit is set, the corresponding ID belongs to the matrix.
5265f06713STony Krowiak  *
5365f06713STony Krowiak  * @apm_max: max adapter number in @apm
5465f06713STony Krowiak  * @apm identifies the AP adapters in the matrix
5565f06713STony Krowiak  * @aqm_max: max domain number in @aqm
5665f06713STony Krowiak  * @aqm identifies the AP queues (domains) in the matrix
5765f06713STony Krowiak  * @adm_max: max domain number in @adm
5865f06713STony Krowiak  * @adm identifies the AP control domains in the matrix
5965f06713STony Krowiak  */
6065f06713STony Krowiak struct ap_matrix {
6165f06713STony Krowiak 	unsigned long apm_max;
6265f06713STony Krowiak 	DECLARE_BITMAP(apm, 256);
6365f06713STony Krowiak 	unsigned long aqm_max;
6465f06713STony Krowiak 	DECLARE_BITMAP(aqm, 256);
6565f06713STony Krowiak 	unsigned long adm_max;
6665f06713STony Krowiak 	DECLARE_BITMAP(adm, 256);
6765f06713STony Krowiak };
6865f06713STony Krowiak 
6965f06713STony Krowiak /**
7065f06713STony Krowiak  * struct ap_matrix_mdev - the mediated matrix device structure
7165f06713STony Krowiak  * @list:	allows the ap_matrix_mdev struct to be added to a list
7265f06713STony Krowiak  * @matrix:	the adapters, usage domains and control domains assigned to the
7365f06713STony Krowiak  *		mediated matrix device.
74*258287c9STony Krowiak  * @group_notifier: notifier block used for specifying callback function for
75*258287c9STony Krowiak  *		    handling the VFIO_GROUP_NOTIFY_SET_KVM event
76*258287c9STony Krowiak  * @kvm:	the struct holding guest's state
7765f06713STony Krowiak  */
7865f06713STony Krowiak struct ap_matrix_mdev {
7965f06713STony Krowiak 	struct list_head node;
8065f06713STony Krowiak 	struct ap_matrix matrix;
81*258287c9STony Krowiak 	struct notifier_block group_notifier;
82*258287c9STony Krowiak 	struct kvm *kvm;
8365f06713STony Krowiak };
8465f06713STony Krowiak 
8565f06713STony Krowiak extern int vfio_ap_mdev_register(void);
8665f06713STony Krowiak extern void vfio_ap_mdev_unregister(void);
8765f06713STony Krowiak 
881fde5734STony Krowiak #endif /* _VFIO_AP_PRIVATE_H_ */
89