vfio: Pass in starting IOVA to vfio_pin/unpin_pages API
[linux-2.6-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>
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>
1fde5734
TK
22
23#include "ap_bus.h"
24
25#define VFIO_AP_MODULE_NAME "vfio_ap"
26#define VFIO_AP_DRV_NAME "vfio_ap"
27
28/**
5ef4f710
TK
29 * struct ap_matrix_dev - Contains the data for the matrix device.
30 *
1fde5734 31 * @device: generic device structure associated with the AP matrix device
65f06713
TK
32 * @available_instances: number of mediated matrix devices that can be created
33 * @info: the struct containing the output from the PQAP(QCI) instruction
5ef4f710
TK
34 * @mdev_list: the list of mediated matrix devices created
35 * @lock: mutex for locking the AP matrix device. This lock will be
65f06713
TK
36 * taken every time we fiddle with state managed by the vfio_ap
37 * driver, be it using @mdev_list or writing the state of a
38 * single ap_matrix_mdev device. It's quite coarse but we don't
39 * expect much contention.
5ef4f710 40 * @vfio_ap_drv: the vfio_ap device driver
1fde5734
TK
41 */
42struct ap_matrix_dev {
43 struct device device;
65f06713
TK
44 atomic_t available_instances;
45 struct ap_config_info info;
46 struct list_head mdev_list;
47 struct mutex lock;
36360658 48 struct ap_driver *vfio_ap_drv;
1fde5734
TK
49};
50
51extern struct ap_matrix_dev *matrix_dev;
52
65f06713 53/**
5ef4f710 54 * struct ap_matrix - matrix of adapters, domains and control domains
65f06713
TK
55 *
56 * @apm_max: max adapter number in @apm
5ef4f710 57 * @apm: identifies the AP adapters in the matrix
65f06713 58 * @aqm_max: max domain number in @aqm
5ef4f710 59 * @aqm: identifies the AP queues (domains) in the matrix
65f06713 60 * @adm_max: max domain number in @adm
5ef4f710
TK
61 * @adm: identifies the AP control domains in the matrix
62 *
63 * The AP matrix is comprised of three bit masks identifying the adapters,
64 * queues (domains) and control domains that belong to an AP matrix. The bits in
65 * each mask, from left to right, correspond to IDs 0 to 255. When a bit is set
66 * the corresponding ID belongs to the matrix.
65f06713
TK
67 */
68struct ap_matrix {
69 unsigned long apm_max;
70 DECLARE_BITMAP(apm, 256);
71 unsigned long aqm_max;
72 DECLARE_BITMAP(aqm, 256);
73 unsigned long adm_max;
74 DECLARE_BITMAP(adm, 256);
75};
76
77/**
5ef4f710
TK
78 * struct ap_matrix_mdev - Contains the data associated with a matrix mediated
79 * device.
80 * @vdev: the vfio device
81 * @node: allows the ap_matrix_mdev struct to be added to a list
65f06713
TK
82 * @matrix: the adapters, usage domains and control domains assigned to the
83 * mediated matrix device.
258287c9 84 * @kvm: the struct holding guest's state
5ef4f710
TK
85 * @pqap_hook: the function pointer to the interception handler for the
86 * PQAP(AQIC) instruction.
87 * @mdev: the mediated device
65f06713
TK
88 */
89struct ap_matrix_mdev {
eb0feefd 90 struct vfio_device vdev;
65f06713
TK
91 struct list_head node;
92 struct ap_matrix matrix;
258287c9 93 struct kvm *kvm;
1e753732 94 crypto_hook pqap_hook;
62e358ce 95 struct mdev_device *mdev;
65f06713
TK
96};
97
5ef4f710
TK
98/**
99 * struct vfio_ap_queue - contains the data associated with a queue bound to the
100 * vfio_ap device driver
101 * @matrix_mdev: the matrix mediated device
102 * @saved_pfn: the guest PFN pinned for the guest
103 * @apqn: the APQN of the AP queue device
104 * @saved_isc: the guest ISC registered with the GIB interface
105 */
ec89b55e
PM
106struct vfio_ap_queue {
107 struct ap_matrix_mdev *matrix_mdev;
108 unsigned long saved_pfn;
109 int apqn;
110#define VFIO_AP_ISC_INVALID 0xff
111 unsigned char saved_isc;
112};
6c12a638
TK
113
114int vfio_ap_mdev_register(void);
115void vfio_ap_mdev_unregister(void);
116int vfio_ap_mdev_reset_queue(struct vfio_ap_queue *q,
117 unsigned int retry);
118
1fde5734 119#endif /* _VFIO_AP_PRIVATE_H_ */