xref: /linux/drivers/s390/crypto/vfio_ap_private.h (revision 36360658eb5a6cf04bb9f2704d1e4ce54037ec99)
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;
43*36360658SPierre Morel 	struct ap_driver  *vfio_ap_drv;
441fde5734STony Krowiak };
451fde5734STony Krowiak 
461fde5734STony Krowiak extern struct ap_matrix_dev *matrix_dev;
471fde5734STony Krowiak 
4865f06713STony Krowiak /**
4965f06713STony Krowiak  * The AP matrix is comprised of three bit masks identifying the adapters,
5065f06713STony Krowiak  * queues (domains) and control domains that belong to an AP matrix. The bits i
5165f06713STony Krowiak  * each mask, from least significant to most significant bit, correspond to IDs
5265f06713STony Krowiak  * 0 to 255. When a bit is set, the corresponding ID belongs to the matrix.
5365f06713STony Krowiak  *
5465f06713STony Krowiak  * @apm_max: max adapter number in @apm
5565f06713STony Krowiak  * @apm identifies the AP adapters in the matrix
5665f06713STony Krowiak  * @aqm_max: max domain number in @aqm
5765f06713STony Krowiak  * @aqm identifies the AP queues (domains) in the matrix
5865f06713STony Krowiak  * @adm_max: max domain number in @adm
5965f06713STony Krowiak  * @adm identifies the AP control domains in the matrix
6065f06713STony Krowiak  */
6165f06713STony Krowiak struct ap_matrix {
6265f06713STony Krowiak 	unsigned long apm_max;
6365f06713STony Krowiak 	DECLARE_BITMAP(apm, 256);
6465f06713STony Krowiak 	unsigned long aqm_max;
6565f06713STony Krowiak 	DECLARE_BITMAP(aqm, 256);
6665f06713STony Krowiak 	unsigned long adm_max;
6765f06713STony Krowiak 	DECLARE_BITMAP(adm, 256);
6865f06713STony Krowiak };
6965f06713STony Krowiak 
7065f06713STony Krowiak /**
7165f06713STony Krowiak  * struct ap_matrix_mdev - the mediated matrix device structure
7265f06713STony Krowiak  * @list:	allows the ap_matrix_mdev struct to be added to a list
7365f06713STony Krowiak  * @matrix:	the adapters, usage domains and control domains assigned to the
7465f06713STony Krowiak  *		mediated matrix device.
75258287c9STony Krowiak  * @group_notifier: notifier block used for specifying callback function for
76258287c9STony Krowiak  *		    handling the VFIO_GROUP_NOTIFY_SET_KVM event
77258287c9STony Krowiak  * @kvm:	the struct holding guest's state
7865f06713STony Krowiak  */
7965f06713STony Krowiak struct ap_matrix_mdev {
8065f06713STony Krowiak 	struct list_head node;
8165f06713STony Krowiak 	struct ap_matrix matrix;
82258287c9STony Krowiak 	struct notifier_block group_notifier;
83258287c9STony Krowiak 	struct kvm *kvm;
8465f06713STony Krowiak };
8565f06713STony Krowiak 
8665f06713STony Krowiak extern int vfio_ap_mdev_register(void);
8765f06713STony Krowiak extern void vfio_ap_mdev_unregister(void);
8865f06713STony Krowiak 
891fde5734STony Krowiak #endif /* _VFIO_AP_PRIVATE_H_ */
90