xref: /linux/drivers/vfio/cdx/private.h (revision ff57d59200baadfdb41f94a49fed7d161a9a8124)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2022-2023, Advanced Micro Devices, Inc.
4  */
5 
6 #ifndef VFIO_CDX_PRIVATE_H
7 #define VFIO_CDX_PRIVATE_H
8 
9 #include <linux/mutex.h>
10 
11 #define VFIO_CDX_OFFSET_SHIFT    40
12 
13 static inline u64 vfio_cdx_index_to_offset(u32 index)
14 {
15 	return ((u64)(index) << VFIO_CDX_OFFSET_SHIFT);
16 }
17 
18 struct vfio_cdx_irq {
19 	u32			flags;
20 	u32			count;
21 	int			irq_no;
22 	struct eventfd_ctx	*trigger;
23 	char			*name;
24 };
25 
26 struct vfio_cdx_region {
27 	u32			flags;
28 	u32			type;
29 	u64			addr;
30 	resource_size_t		size;
31 };
32 
33 struct vfio_cdx_device {
34 	struct vfio_device	vdev;
35 	struct vfio_cdx_region	*regions;
36 	struct mutex		cdx_irqs_lock;
37 	struct vfio_cdx_irq	*cdx_irqs;
38 	u32			flags;
39 #define BME_SUPPORT BIT(0)
40 	u32			msi_count;
41 };
42 
43 #ifdef CONFIG_GENERIC_MSI_IRQ
44 int vfio_cdx_set_irqs_ioctl(struct vfio_cdx_device *vdev,
45 			    u32 flags, unsigned int index,
46 			    unsigned int start, unsigned int count,
47 			    void *data);
48 
49 void vfio_cdx_irqs_cleanup(struct vfio_cdx_device *vdev);
50 #else
51 static int vfio_cdx_set_irqs_ioctl(struct vfio_cdx_device *vdev,
52 				   u32 flags, unsigned int index,
53 				   unsigned int start, unsigned int count,
54 				   void *data)
55 {
56 	return -EINVAL;
57 }
58 
59 static void vfio_cdx_irqs_cleanup(struct vfio_cdx_device *vdev)
60 {
61 }
62 #endif
63 
64 #endif /* VFIO_CDX_PRIVATE_H */
65