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> 6*65f06713STony 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 28*65f06713STony Krowiak * @available_instances: number of mediated matrix devices that can be created 29*65f06713STony Krowiak * @info: the struct containing the output from the PQAP(QCI) instruction 30*65f06713STony Krowiak * mdev_list: the list of mediated matrix devices created 31*65f06713STony Krowiak * lock: mutex for locking the AP matrix device. This lock will be 32*65f06713STony Krowiak * taken every time we fiddle with state managed by the vfio_ap 33*65f06713STony Krowiak * driver, be it using @mdev_list or writing the state of a 34*65f06713STony Krowiak * single ap_matrix_mdev device. It's quite coarse but we don't 35*65f06713STony Krowiak * expect much contention. 361fde5734STony Krowiak */ 371fde5734STony Krowiak struct ap_matrix_dev { 381fde5734STony Krowiak struct device device; 39*65f06713STony Krowiak atomic_t available_instances; 40*65f06713STony Krowiak struct ap_config_info info; 41*65f06713STony Krowiak struct list_head mdev_list; 42*65f06713STony Krowiak struct mutex lock; 431fde5734STony Krowiak }; 441fde5734STony Krowiak 451fde5734STony Krowiak extern struct ap_matrix_dev *matrix_dev; 461fde5734STony Krowiak 47*65f06713STony Krowiak /** 48*65f06713STony Krowiak * The AP matrix is comprised of three bit masks identifying the adapters, 49*65f06713STony Krowiak * queues (domains) and control domains that belong to an AP matrix. The bits i 50*65f06713STony Krowiak * each mask, from least significant to most significant bit, correspond to IDs 51*65f06713STony Krowiak * 0 to 255. When a bit is set, the corresponding ID belongs to the matrix. 52*65f06713STony Krowiak * 53*65f06713STony Krowiak * @apm_max: max adapter number in @apm 54*65f06713STony Krowiak * @apm identifies the AP adapters in the matrix 55*65f06713STony Krowiak * @aqm_max: max domain number in @aqm 56*65f06713STony Krowiak * @aqm identifies the AP queues (domains) in the matrix 57*65f06713STony Krowiak * @adm_max: max domain number in @adm 58*65f06713STony Krowiak * @adm identifies the AP control domains in the matrix 59*65f06713STony Krowiak */ 60*65f06713STony Krowiak struct ap_matrix { 61*65f06713STony Krowiak unsigned long apm_max; 62*65f06713STony Krowiak DECLARE_BITMAP(apm, 256); 63*65f06713STony Krowiak unsigned long aqm_max; 64*65f06713STony Krowiak DECLARE_BITMAP(aqm, 256); 65*65f06713STony Krowiak unsigned long adm_max; 66*65f06713STony Krowiak DECLARE_BITMAP(adm, 256); 67*65f06713STony Krowiak }; 68*65f06713STony Krowiak 69*65f06713STony Krowiak /** 70*65f06713STony Krowiak * struct ap_matrix_mdev - the mediated matrix device structure 71*65f06713STony Krowiak * @list: allows the ap_matrix_mdev struct to be added to a list 72*65f06713STony Krowiak * @matrix: the adapters, usage domains and control domains assigned to the 73*65f06713STony Krowiak * mediated matrix device. 74*65f06713STony Krowiak */ 75*65f06713STony Krowiak struct ap_matrix_mdev { 76*65f06713STony Krowiak struct list_head node; 77*65f06713STony Krowiak struct ap_matrix matrix; 78*65f06713STony Krowiak }; 79*65f06713STony Krowiak 80*65f06713STony Krowiak extern int vfio_ap_mdev_register(void); 81*65f06713STony Krowiak extern void vfio_ap_mdev_unregister(void); 82*65f06713STony Krowiak 831fde5734STony Krowiak #endif /* _VFIO_AP_PRIVATE_H_ */ 84