1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Private stuff for vfio_ccw driver
5 * Copyright IBM Corp. 2017
6 * Copyright Red Hat, Inc. 2019
8 * Author(s): Dong Jia Shi <bjsdjshi@linux.vnet.ibm.com>
9 * Xiao Feng Ren <renxiaof@linux.vnet.ibm.com>
10 * Cornelia Huck <cohuck@redhat.com>
13 #ifndef _VFIO_CCW_PRIVATE_H_
14 #define _VFIO_CCW_PRIVATE_H_
16 #include <linux/completion.h>
17 #include <linux/eventfd.h>
18 #include <linux/workqueue.h>
19 #include <linux/vfio_ccw.h>
22 #include "vfio_ccw_cp.h"
24 #define VFIO_CCW_OFFSET_SHIFT 10
25 #define VFIO_CCW_OFFSET_TO_INDEX(off) (off >> VFIO_CCW_OFFSET_SHIFT)
26 #define VFIO_CCW_INDEX_TO_OFFSET(index) ((u64)(index) << VFIO_CCW_OFFSET_SHIFT)
27 #define VFIO_CCW_OFFSET_MASK (((u64)(1) << VFIO_CCW_OFFSET_SHIFT) - 1)
29 /* capability chain handling similar to vfio-pci */
30 struct vfio_ccw_private;
31 struct vfio_ccw_region;
33 struct vfio_ccw_regops {
34 ssize_t (*read)(struct vfio_ccw_private *private, char __user *buf,
35 size_t count, loff_t *ppos);
36 ssize_t (*write)(struct vfio_ccw_private *private,
37 const char __user *buf, size_t count, loff_t *ppos);
38 void (*release)(struct vfio_ccw_private *private,
39 struct vfio_ccw_region *region);
42 struct vfio_ccw_region {
45 const struct vfio_ccw_regops *ops;
51 int vfio_ccw_register_dev_region(struct vfio_ccw_private *private,
53 const struct vfio_ccw_regops *ops,
54 size_t size, u32 flags, void *data);
56 int vfio_ccw_register_async_dev_regions(struct vfio_ccw_private *private);
59 * struct vfio_ccw_private
60 * @sch: pointer to the subchannel
61 * @state: internal state of the device
62 * @completion: synchronization helper of the I/O completion
63 * @avail: available for creating a mediated device
64 * @mdev: pointer to the mediated device
65 * @nb: notifier for vfio events
66 * @io_region: MMIO region to input/output I/O arguments/results
67 * @io_mutex: protect against concurrent update of I/O regions
68 * @region: additional regions for other subchannel operations
69 * @cmd_region: MMIO region for asynchronous I/O commands other than START
70 * @num_regions: number of additional regions
71 * @cp: channel program for the current I/O operation
72 * @irb: irb info received from interrupt
74 * @io_trigger: eventfd ctx for signaling userspace I/O results
75 * @io_work: work for deferral process of I/O handling
77 struct vfio_ccw_private {
78 struct subchannel *sch;
80 struct completion *completion;
82 struct mdev_device *mdev;
83 struct notifier_block nb;
84 struct ccw_io_region *io_region;
85 struct mutex io_mutex;
86 struct vfio_ccw_region *region;
87 struct ccw_cmd_region *cmd_region;
90 struct channel_program cp;
94 struct eventfd_ctx *io_trigger;
95 struct work_struct io_work;
98 extern int vfio_ccw_mdev_reg(struct subchannel *sch);
99 extern void vfio_ccw_mdev_unreg(struct subchannel *sch);
101 extern int vfio_ccw_sch_quiesce(struct subchannel *sch);
104 * States of the device statemachine.
106 enum vfio_ccw_state {
107 VFIO_CCW_STATE_NOT_OPER,
108 VFIO_CCW_STATE_STANDBY,
110 VFIO_CCW_STATE_CP_PROCESSING,
111 VFIO_CCW_STATE_CP_PENDING,
117 * Asynchronous events of the device statemachine.
119 enum vfio_ccw_event {
120 VFIO_CCW_EVENT_NOT_OPER,
121 VFIO_CCW_EVENT_IO_REQ,
122 VFIO_CCW_EVENT_INTERRUPT,
123 VFIO_CCW_EVENT_ASYNC_REQ,
129 * Action called through jumptable.
131 typedef void (fsm_func_t)(struct vfio_ccw_private *, enum vfio_ccw_event);
132 extern fsm_func_t *vfio_ccw_jumptable[NR_VFIO_CCW_STATES][NR_VFIO_CCW_EVENTS];
134 static inline void vfio_ccw_fsm_event(struct vfio_ccw_private *private,
137 vfio_ccw_jumptable[private->state][event](private, event);
140 extern struct workqueue_struct *vfio_ccw_work_q;