Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_VIRTIO_PCI_MODERN_H
0003 #define _LINUX_VIRTIO_PCI_MODERN_H
0004 
0005 #include <linux/pci.h>
0006 #include <linux/virtio_pci.h>
0007 
0008 struct virtio_pci_modern_common_cfg {
0009     struct virtio_pci_common_cfg cfg;
0010 
0011     __le16 queue_notify_data;   /* read-write */
0012     __le16 queue_reset;     /* read-write */
0013 };
0014 
0015 struct virtio_pci_modern_device {
0016     struct pci_dev *pci_dev;
0017 
0018     struct virtio_pci_common_cfg __iomem *common;
0019     /* Device-specific data (non-legacy mode)  */
0020     void __iomem *device;
0021     /* Base of vq notifications (non-legacy mode). */
0022     void __iomem *notify_base;
0023     /* Physical base of vq notifications */
0024     resource_size_t notify_pa;
0025     /* Where to read and clear interrupt */
0026     u8 __iomem *isr;
0027 
0028     /* So we can sanity-check accesses. */
0029     size_t notify_len;
0030     size_t device_len;
0031 
0032     /* Capability for when we need to map notifications per-vq. */
0033     int notify_map_cap;
0034 
0035     /* Multiply queue_notify_off by this value. (non-legacy mode). */
0036     u32 notify_offset_multiplier;
0037 
0038     int modern_bars;
0039 
0040     struct virtio_device_id id;
0041 };
0042 
0043 /*
0044  * Type-safe wrappers for io accesses.
0045  * Use these to enforce at compile time the following spec requirement:
0046  *
0047  * The driver MUST access each field using the “natural” access
0048  * method, i.e. 32-bit accesses for 32-bit fields, 16-bit accesses
0049  * for 16-bit fields and 8-bit accesses for 8-bit fields.
0050  */
0051 static inline u8 vp_ioread8(const u8 __iomem *addr)
0052 {
0053     return ioread8(addr);
0054 }
0055 static inline u16 vp_ioread16 (const __le16 __iomem *addr)
0056 {
0057     return ioread16(addr);
0058 }
0059 
0060 static inline u32 vp_ioread32(const __le32 __iomem *addr)
0061 {
0062     return ioread32(addr);
0063 }
0064 
0065 static inline void vp_iowrite8(u8 value, u8 __iomem *addr)
0066 {
0067     iowrite8(value, addr);
0068 }
0069 
0070 static inline void vp_iowrite16(u16 value, __le16 __iomem *addr)
0071 {
0072     iowrite16(value, addr);
0073 }
0074 
0075 static inline void vp_iowrite32(u32 value, __le32 __iomem *addr)
0076 {
0077     iowrite32(value, addr);
0078 }
0079 
0080 static inline void vp_iowrite64_twopart(u64 val,
0081                     __le32 __iomem *lo,
0082                     __le32 __iomem *hi)
0083 {
0084     vp_iowrite32((u32)val, lo);
0085     vp_iowrite32(val >> 32, hi);
0086 }
0087 
0088 u64 vp_modern_get_features(struct virtio_pci_modern_device *mdev);
0089 u64 vp_modern_get_driver_features(struct virtio_pci_modern_device *mdev);
0090 void vp_modern_set_features(struct virtio_pci_modern_device *mdev,
0091              u64 features);
0092 u32 vp_modern_generation(struct virtio_pci_modern_device *mdev);
0093 u8 vp_modern_get_status(struct virtio_pci_modern_device *mdev);
0094 void vp_modern_set_status(struct virtio_pci_modern_device *mdev,
0095            u8 status);
0096 u16 vp_modern_queue_vector(struct virtio_pci_modern_device *mdev,
0097                u16 idx, u16 vector);
0098 u16 vp_modern_config_vector(struct virtio_pci_modern_device *mdev,
0099              u16 vector);
0100 void vp_modern_queue_address(struct virtio_pci_modern_device *mdev,
0101                  u16 index, u64 desc_addr, u64 driver_addr,
0102                  u64 device_addr);
0103 void vp_modern_set_queue_enable(struct virtio_pci_modern_device *mdev,
0104                 u16 idx, bool enable);
0105 bool vp_modern_get_queue_enable(struct virtio_pci_modern_device *mdev,
0106                 u16 idx);
0107 void vp_modern_set_queue_size(struct virtio_pci_modern_device *mdev,
0108                   u16 idx, u16 size);
0109 u16 vp_modern_get_queue_size(struct virtio_pci_modern_device *mdev,
0110                  u16 idx);
0111 u16 vp_modern_get_num_queues(struct virtio_pci_modern_device *mdev);
0112 void __iomem * vp_modern_map_vq_notify(struct virtio_pci_modern_device *mdev,
0113                        u16 index, resource_size_t *pa);
0114 int vp_modern_probe(struct virtio_pci_modern_device *mdev);
0115 void vp_modern_remove(struct virtio_pci_modern_device *mdev);
0116 int vp_modern_get_queue_reset(struct virtio_pci_modern_device *mdev, u16 index);
0117 void vp_modern_set_queue_reset(struct virtio_pci_modern_device *mdev, u16 index);
0118 #endif