Annotation of qemu/hw/virtio.h, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Virtio Support
                      3:  *
                      4:  * Copyright IBM, Corp. 2007
                      5:  *
                      6:  * Authors:
                      7:  *  Anthony Liguori   <[email protected]>
                      8:  *
                      9:  * This work is licensed under the terms of the GNU GPL, version 2.  See
                     10:  * the COPYING file in the top-level directory.
                     11:  *
                     12:  */
                     13: 
                     14: #ifndef _QEMU_VIRTIO_H
                     15: #define _QEMU_VIRTIO_H
                     16: 
                     17: #include "hw.h"
                     18: #include "pci.h"
                     19: 
                     20: /* from Linux's linux/virtio_config.h */
                     21: 
                     22: /* Status byte for guest to report progress, and synchronize features. */
                     23: /* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
                     24: #define VIRTIO_CONFIG_S_ACKNOWLEDGE     1
                     25: /* We have found a driver for the device. */
                     26: #define VIRTIO_CONFIG_S_DRIVER          2
                     27: /* Driver has used its parts of the config, and is happy */
                     28: #define VIRTIO_CONFIG_S_DRIVER_OK       4
                     29: /* We've given up on this device. */
                     30: #define VIRTIO_CONFIG_S_FAILED          0x80
                     31: 
                     32: /* We notify when the ring is completely used, even if the guest is supressing
                     33:  * callbacks */
                     34: #define VIRTIO_F_NOTIFY_ON_EMPTY        24
                     35: 
                     36: /* from Linux's linux/virtio_ring.h */
                     37: 
                     38: /* This marks a buffer as continuing via the next field. */
                     39: #define VRING_DESC_F_NEXT       1
                     40: /* This marks a buffer as write-only (otherwise read-only). */
                     41: #define VRING_DESC_F_WRITE      2
                     42: 
                     43: /* This means don't notify other side when buffer added. */
                     44: #define VRING_USED_F_NO_NOTIFY  1
                     45: /* This means don't interrupt guest when buffer consumed. */
                     46: #define VRING_AVAIL_F_NO_INTERRUPT      1
                     47: 
                     48: struct VirtQueue;
                     49: 
                     50: static inline target_phys_addr_t vring_align(target_phys_addr_t addr,
                     51:                                              unsigned long align)
                     52: {
                     53:     return (addr + align - 1) & ~(align - 1);
                     54: }
                     55: 
                     56: typedef struct VirtQueue VirtQueue;
                     57: typedef struct VirtIODevice VirtIODevice;
                     58: 
                     59: #define VIRTQUEUE_MAX_SIZE 1024
                     60: 
                     61: typedef struct VirtQueueElement
                     62: {
                     63:     unsigned int index;
                     64:     unsigned int out_num;
                     65:     unsigned int in_num;
                     66:     target_phys_addr_t in_addr[VIRTQUEUE_MAX_SIZE];
                     67:     struct iovec in_sg[VIRTQUEUE_MAX_SIZE];
                     68:     struct iovec out_sg[VIRTQUEUE_MAX_SIZE];
                     69: } VirtQueueElement;
                     70: 
                     71: #define VIRTIO_PCI_QUEUE_MAX 16
                     72: 
                     73: struct VirtIODevice
                     74: {
                     75:     PCIDevice pci_dev;
                     76:     const char *name;
                     77:     uint32_t addr;
                     78:     uint8_t status;
                     79:     uint8_t isr;
                     80:     uint16_t queue_sel;
                     81:     uint32_t features;
                     82:     size_t config_len;
                     83:     void *config;
                     84:     uint32_t (*get_features)(VirtIODevice *vdev);
                     85:     void (*set_features)(VirtIODevice *vdev, uint32_t val);
                     86:     void (*get_config)(VirtIODevice *vdev, uint8_t *config);
                     87:     void (*set_config)(VirtIODevice *vdev, const uint8_t *config);
                     88:     void (*reset)(VirtIODevice *vdev);
                     89:     VirtQueue *vq;
                     90: };
                     91: 
                     92: VirtIODevice *virtio_init_pci(PCIBus *bus, const char *name,
                     93:                               uint16_t vendor, uint16_t device,
                     94:                               uint16_t subvendor, uint16_t subdevice,
                     95:                               uint16_t class_code, uint8_t pif,
                     96:                               size_t config_size, size_t struct_size);
                     97: 
                     98: VirtQueue *virtio_add_queue(VirtIODevice *vdev, int queue_size,
                     99:                             void (*handle_output)(VirtIODevice *,
                    100:                                                   VirtQueue *));
                    101: 
                    102: void virtqueue_push(VirtQueue *vq, const VirtQueueElement *elem,
                    103:                     unsigned int len);
                    104: void virtqueue_flush(VirtQueue *vq, unsigned int count);
                    105: void virtqueue_fill(VirtQueue *vq, const VirtQueueElement *elem,
                    106:                     unsigned int len, unsigned int idx);
                    107: 
                    108: int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem);
                    109: int virtqueue_avail_bytes(VirtQueue *vq, int in_bytes, int out_bytes);
                    110: 
                    111: void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
                    112: 
                    113: void virtio_save(VirtIODevice *vdev, QEMUFile *f);
                    114: 
                    115: void virtio_load(VirtIODevice *vdev, QEMUFile *f);
                    116: 
                    117: void virtio_notify_config(VirtIODevice *vdev);
                    118: 
                    119: void virtio_queue_set_notification(VirtQueue *vq, int enable);
                    120: 
                    121: int virtio_queue_ready(VirtQueue *vq);
                    122: 
                    123: int virtio_queue_empty(VirtQueue *vq);
                    124: 
                    125: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.