vfio: ap: register IOMMU VFIO notifier
[linux-block.git] / drivers / s390 / crypto / vfio_ap_private.h
CommitLineData
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>
1fde5734
TK
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>
e5282de9 19#include <linux/kvm_host.h>
1fde5734
TK
20
21#include "ap_bus.h"
22
23#define VFIO_AP_MODULE_NAME "vfio_ap"
24#define VFIO_AP_DRV_NAME "vfio_ap"
25
26/**
27 * ap_matrix_dev - the AP matrix device structure
28 * @device: generic device structure associated with the AP matrix device
65f06713
TK
29 * @available_instances: number of mediated matrix devices that can be created
30 * @info: the struct containing the output from the PQAP(QCI) instruction
31 * mdev_list: the list of mediated matrix devices created
32 * lock: mutex for locking the AP matrix device. This lock will be
33 * taken every time we fiddle with state managed by the vfio_ap
34 * driver, be it using @mdev_list or writing the state of a
35 * single ap_matrix_mdev device. It's quite coarse but we don't
36 * expect much contention.
1fde5734
TK
37 */
38struct ap_matrix_dev {
39 struct device device;
65f06713
TK
40 atomic_t available_instances;
41 struct ap_config_info info;
42 struct list_head mdev_list;
43 struct mutex lock;
36360658 44 struct ap_driver *vfio_ap_drv;
1fde5734
TK
45};
46
47extern struct ap_matrix_dev *matrix_dev;
48
65f06713
TK
49/**
50 * The AP matrix is comprised of three bit masks identifying the adapters,
51 * queues (domains) and control domains that belong to an AP matrix. The bits i
52 * each mask, from least significant to most significant bit, correspond to IDs
53 * 0 to 255. When a bit is set, the corresponding ID belongs to the matrix.
54 *
55 * @apm_max: max adapter number in @apm
56 * @apm identifies the AP adapters in the matrix
57 * @aqm_max: max domain number in @aqm
58 * @aqm identifies the AP queues (domains) in the matrix
59 * @adm_max: max domain number in @adm
60 * @adm identifies the AP control domains in the matrix
61 */
62struct ap_matrix {
63 unsigned long apm_max;
64 DECLARE_BITMAP(apm, 256);
65 unsigned long aqm_max;
66 DECLARE_BITMAP(aqm, 256);
67 unsigned long adm_max;
68 DECLARE_BITMAP(adm, 256);
69};
70
71/**
72 * struct ap_matrix_mdev - the mediated matrix device structure
73 * @list: allows the ap_matrix_mdev struct to be added to a list
74 * @matrix: the adapters, usage domains and control domains assigned to the
75 * mediated matrix device.
258287c9
TK
76 * @group_notifier: notifier block used for specifying callback function for
77 * handling the VFIO_GROUP_NOTIFY_SET_KVM event
78 * @kvm: the struct holding guest's state
65f06713
TK
79 */
80struct ap_matrix_mdev {
81 struct list_head node;
82 struct ap_matrix matrix;
258287c9 83 struct notifier_block group_notifier;
62e358ce 84 struct notifier_block iommu_notifier;
258287c9 85 struct kvm *kvm;
e5282de9 86 struct kvm_s390_module_hook pqap_hook;
62e358ce 87 struct mdev_device *mdev;
65f06713
TK
88};
89
90extern int vfio_ap_mdev_register(void);
91extern void vfio_ap_mdev_unregister(void);
92
1fde5734 93#endif /* _VFIO_AP_PRIVATE_H_ */