2018-09-25 19:16:19 -04:00
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Private data and functions for adjunct processor VFIO matrix driver .
*
* Author ( s ) : Tony Krowiak < akrowiak @ linux . ibm . com >
2018-09-25 19:16:20 -04:00
* Halil Pasic < pasic @ linux . ibm . com >
2019-05-21 17:34:36 +02:00
* Pierre Morel < pmorel @ linux . ibm . com >
2018-09-25 19:16:19 -04:00
*
* Copyright IBM Corp . 2018
*/
# ifndef _VFIO_AP_PRIVATE_H_
# define _VFIO_AP_PRIVATE_H_
# include <linux/types.h>
# include <linux/device.h>
# include <linux/mdev.h>
# include <linux/delay.h>
# include <linux/mutex.h>
2019-05-21 17:34:34 +02:00
# include <linux/kvm_host.h>
2021-08-23 11:42:04 -03:00
# include <linux/vfio.h>
2018-09-25 19:16:19 -04:00
# include "ap_bus.h"
# define VFIO_AP_MODULE_NAME "vfio_ap"
# define VFIO_AP_DRV_NAME "vfio_ap"
/**
2021-10-19 12:57:32 -04:00
* struct ap_matrix_dev - Contains the data for the matrix device .
*
2018-09-25 19:16:19 -04:00
* @ device : generic device structure associated with the AP matrix device
2018-09-25 19:16:20 -04:00
* @ available_instances : number of mediated matrix devices that can be created
* @ info : the struct containing the output from the PQAP ( QCI ) instruction
2021-10-19 12:57:32 -04:00
* @ mdev_list : the list of mediated matrix devices created
* @ lock : mutex for locking the AP matrix device . This lock will be
2018-09-25 19:16:20 -04:00
* taken every time we fiddle with state managed by the vfio_ap
* driver , be it using @ mdev_list or writing the state of a
* single ap_matrix_mdev device . It ' s quite coarse but we don ' t
* expect much contention .
2021-10-19 12:57:32 -04:00
* @ vfio_ap_drv : the vfio_ap device driver
2018-09-25 19:16:19 -04:00
*/
struct ap_matrix_dev {
struct device device ;
2018-09-25 19:16:20 -04:00
atomic_t available_instances ;
struct ap_config_info info ;
struct list_head mdev_list ;
struct mutex lock ;
2019-02-12 16:53:45 +01:00
struct ap_driver * vfio_ap_drv ;
2018-09-25 19:16:19 -04:00
} ;
extern struct ap_matrix_dev * matrix_dev ;
2018-09-25 19:16:20 -04:00
/**
2021-10-19 12:57:32 -04:00
* struct ap_matrix - matrix of adapters , domains and control domains
2018-09-25 19:16:20 -04:00
*
* @ apm_max : max adapter number in @ apm
2021-10-19 12:57:32 -04:00
* @ apm : identifies the AP adapters in the matrix
2018-09-25 19:16:20 -04:00
* @ aqm_max : max domain number in @ aqm
2021-10-19 12:57:32 -04:00
* @ aqm : identifies the AP queues ( domains ) in the matrix
2018-09-25 19:16:20 -04:00
* @ adm_max : max domain number in @ adm
2021-10-19 12:57:32 -04:00
* @ adm : identifies the AP control domains in the matrix
*
* The AP matrix is comprised of three bit masks identifying the adapters ,
* queues ( domains ) and control domains that belong to an AP matrix . The bits in
* each mask , from left to right , correspond to IDs 0 to 255. When a bit is set
* the corresponding ID belongs to the matrix .
2018-09-25 19:16:20 -04:00
*/
struct ap_matrix {
unsigned long apm_max ;
DECLARE_BITMAP ( apm , 256 ) ;
unsigned long aqm_max ;
DECLARE_BITMAP ( aqm , 256 ) ;
unsigned long adm_max ;
DECLARE_BITMAP ( adm , 256 ) ;
} ;
/**
2021-10-19 12:57:32 -04:00
* struct ap_matrix_mdev - Contains the data associated with a matrix mediated
* device .
* @ vdev : the vfio device
* @ node : allows the ap_matrix_mdev struct to be added to a list
2018-09-25 19:16:20 -04:00
* @ matrix : the adapters , usage domains and control domains assigned to the
* mediated matrix device .
2018-09-25 19:16:26 -04:00
* @ group_notifier : notifier block used for specifying callback function for
* handling the VFIO_GROUP_NOTIFY_SET_KVM event
2021-10-19 12:57:32 -04:00
* @ iommu_notifier : notifier block used for specifying callback function for
* handling the VFIO_IOMMU_NOTIFY_DMA_UNMAP even
2018-09-25 19:16:26 -04:00
* @ kvm : the struct holding guest ' s state
2021-10-19 12:57:32 -04:00
* @ pqap_hook : the function pointer to the interception handler for the
* PQAP ( AQIC ) instruction .
* @ mdev : the mediated device
2018-09-25 19:16:20 -04:00
*/
struct ap_matrix_mdev {
2021-08-23 11:42:04 -03:00
struct vfio_device vdev ;
2018-09-25 19:16:20 -04:00
struct list_head node ;
struct ap_matrix matrix ;
2018-09-25 19:16:26 -04:00
struct notifier_block group_notifier ;
2019-05-21 17:34:35 +02:00
struct notifier_block iommu_notifier ;
2018-09-25 19:16:26 -04:00
struct kvm * kvm ;
2021-08-23 17:20:46 -04:00
crypto_hook pqap_hook ;
2019-05-21 17:34:35 +02:00
struct mdev_device * mdev ;
2018-09-25 19:16:20 -04:00
} ;
2021-10-19 12:57:32 -04:00
/**
* struct vfio_ap_queue - contains the data associated with a queue bound to the
* vfio_ap device driver
* @ matrix_mdev : the matrix mediated device
* @ saved_pfn : the guest PFN pinned for the guest
* @ apqn : the APQN of the AP queue device
* @ saved_isc : the guest ISC registered with the GIB interface
*/
2019-05-21 17:34:36 +02:00
struct vfio_ap_queue {
struct ap_matrix_mdev * matrix_mdev ;
unsigned long saved_pfn ;
int apqn ;
# define VFIO_AP_ISC_INVALID 0xff
unsigned char saved_isc ;
} ;
2020-12-22 20:15:53 -05:00
int vfio_ap_mdev_register ( void ) ;
void vfio_ap_mdev_unregister ( void ) ;
int vfio_ap_mdev_reset_queue ( struct vfio_ap_queue * q ,
unsigned int retry ) ;
2018-09-25 19:16:19 -04:00
# endif /* _VFIO_AP_PRIVATE_H_ */