Merge tag 'for-linus-5.12b-rc1-tag' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-2.6-microblaze.git] / include / linux / virtio_pci_modern.h
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _LINUX_VIRTIO_PCI_MODERN_H
3 #define _LINUX_VIRTIO_PCI_MODERN_H
4
5 #include <linux/pci.h>
6 #include <linux/virtio_pci.h>
7
8 struct virtio_pci_modern_device {
9         struct pci_dev *pci_dev;
10
11         struct virtio_pci_common_cfg __iomem *common;
12         /* Device-specific data (non-legacy mode)  */
13         void __iomem *device;
14         /* Base of vq notifications (non-legacy mode). */
15         void __iomem *notify_base;
16         /* Where to read and clear interrupt */
17         u8 __iomem *isr;
18
19         /* So we can sanity-check accesses. */
20         size_t notify_len;
21         size_t device_len;
22
23         /* Capability for when we need to map notifications per-vq. */
24         int notify_map_cap;
25
26         /* Multiply queue_notify_off by this value. (non-legacy mode). */
27         u32 notify_offset_multiplier;
28
29         int modern_bars;
30
31         struct virtio_device_id id;
32 };
33
34 /*
35  * Type-safe wrappers for io accesses.
36  * Use these to enforce at compile time the following spec requirement:
37  *
38  * The driver MUST access each field using the “natural” access
39  * method, i.e. 32-bit accesses for 32-bit fields, 16-bit accesses
40  * for 16-bit fields and 8-bit accesses for 8-bit fields.
41  */
42 static inline u8 vp_ioread8(const u8 __iomem *addr)
43 {
44         return ioread8(addr);
45 }
46 static inline u16 vp_ioread16 (const __le16 __iomem *addr)
47 {
48         return ioread16(addr);
49 }
50
51 static inline u32 vp_ioread32(const __le32 __iomem *addr)
52 {
53         return ioread32(addr);
54 }
55
56 static inline void vp_iowrite8(u8 value, u8 __iomem *addr)
57 {
58         iowrite8(value, addr);
59 }
60
61 static inline void vp_iowrite16(u16 value, __le16 __iomem *addr)
62 {
63         iowrite16(value, addr);
64 }
65
66 static inline void vp_iowrite32(u32 value, __le32 __iomem *addr)
67 {
68         iowrite32(value, addr);
69 }
70
71 static inline void vp_iowrite64_twopart(u64 val,
72                                         __le32 __iomem *lo,
73                                         __le32 __iomem *hi)
74 {
75         vp_iowrite32((u32)val, lo);
76         vp_iowrite32(val >> 32, hi);
77 }
78
79 u64 vp_modern_get_features(struct virtio_pci_modern_device *mdev);
80 void vp_modern_set_features(struct virtio_pci_modern_device *mdev,
81                      u64 features);
82 u32 vp_modern_generation(struct virtio_pci_modern_device *mdev);
83 u8 vp_modern_get_status(struct virtio_pci_modern_device *mdev);
84 void vp_modern_set_status(struct virtio_pci_modern_device *mdev,
85                    u8 status);
86 u16 vp_modern_queue_vector(struct virtio_pci_modern_device *mdev,
87                            u16 idx, u16 vector);
88 u16 vp_modern_config_vector(struct virtio_pci_modern_device *mdev,
89                      u16 vector);
90 void vp_modern_queue_address(struct virtio_pci_modern_device *mdev,
91                              u16 index, u64 desc_addr, u64 driver_addr,
92                              u64 device_addr);
93 void vp_modern_set_queue_enable(struct virtio_pci_modern_device *mdev,
94                                 u16 idx, bool enable);
95 bool vp_modern_get_queue_enable(struct virtio_pci_modern_device *mdev,
96                                 u16 idx);
97 void vp_modern_set_queue_size(struct virtio_pci_modern_device *mdev,
98                               u16 idx, u16 size);
99 u16 vp_modern_get_queue_size(struct virtio_pci_modern_device *mdev,
100                              u16 idx);
101 u16 vp_modern_get_num_queues(struct virtio_pci_modern_device *mdev);
102 u16 vp_modern_get_queue_notify_off(struct virtio_pci_modern_device *mdev,
103                                    u16 idx);
104 void __iomem *vp_modern_map_capability(struct virtio_pci_modern_device *mdev, int off,
105                                        size_t minlen,
106                                        u32 align,
107                                        u32 start, u32 size,
108                                        size_t *len);
109 int vp_modern_probe(struct virtio_pci_modern_device *mdev);
110 void vp_modern_remove(struct virtio_pci_modern_device *mdev);
111 #endif