2 * This file is part of the Palacios Virtual Machine Monitor developed
3 * by the V3VEE Project with funding from the United States National
4 * Science Foundation and the Department of Energy.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
10 * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu>
11 * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org>
12 * All rights reserved.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
21 #ifndef __DEVICES_LNX_VIRTIO_PCI_H__
22 #define __DEVICES_LNX_VIRTIO_PCI_H__
27 /* PCI Vendor IDs (from Qemu) */
28 #define VIRTIO_VENDOR_ID 0x1af4 // Redhat/Qumranet
29 #define VIRTIO_SUBVENDOR_ID 0x1af4 // Redhat/Qumranet
30 #define VIRTIO_SUBDEVICE_ID 0x1100 // Qemu
33 #define VIRTIO_NET_DEV_ID 0x1000
34 #define VIRTIO_BLOCK_DEV_ID 0x1001
35 #define VIRTIO_BALLOON_DEV_ID 0x1002
36 #define VIRTIO_CONSOLE_DEV_ID 0x1003
37 #define VIRTIO_SYMBIOTIC_DEV_ID 0x100a
38 #define VIRTIO_SYMMOD_DEV_ID 0x100b
39 #define VIRTIO_VNET_CTRL_DEV_ID 0x100c
41 #define VIRTIO_NET_SUBDEVICE_ID 1
42 #define VIRTIO_BLOCK_SUBDEVICE_ID 2
43 #define VIRTIO_BALLOON_SUBDEVICE_ID 5
44 #define VIRTIO_SYMBIOTIC_SUBDEVICE_ID 10
45 #define VIRTIO_SYMMOD_SUBDEVICE_ID 11
46 #define VIRTIO_VNET_CTRL_SUBDEVICE_ID 12
48 #define HOST_FEATURES_PORT 0
49 #define GUEST_FEATURES_PORT 4
50 #define VRING_PG_NUM_PORT 8
51 #define VRING_SIZE_PORT 12
52 #define VRING_Q_SEL_PORT 14
53 #define VRING_Q_NOTIFY_PORT 16
54 #define VIRTIO_STATUS_PORT 18
55 #define VIRTIO_ISR_PORT 19
57 #define VIRTIO_PAGE_SHIFT 12
60 /* Descriptor flags */
61 /* This marks a buffer as continuing via the next field. */
62 #define VIRTIO_NEXT_FLAG 0x1
63 /* This marks a buffer as write-only (otherwise read-only). */
64 #define VIRTIO_WR_ONLY_FLAG 0x2
68 /* This means don't notify other side when buffer added. */
69 #define VRING_NO_NOTIFY_FLAG 0x1
73 /* This means don't interrupt guest when buffer consumed. */
74 #define VIRTIO_NO_IRQ_FLAG 0x1
78 #define VIRTIO_ISR_ACTIVE 0x1
79 #define VIRTIO_ISR_CFG_CHANGED 0x2
83 /* The virtio configuration space is a hybrid io/memory mapped model
84 * All IO is done via IO port accesses
85 * The IO ports access fields in a virtio data structure, and the base io port
86 * coincides with the base address of the in memory structure
87 * There is a standard virtio structure of 20 bytes, followed by a
88 * device specific structure of n bytes.
91 struct virtio_config {
92 uint32_t host_features;
93 uint32_t guest_features;
94 uint32_t vring_page_num;
95 uint16_t vring_ring_size;
96 uint16_t vring_queue_selector;
97 uint16_t vring_queue_notifier;
100 } __attribute__((packed));
108 } __attribute__((packed));
114 } __attribute__((packed));
117 struct vring_used_elem {
120 } __attribute__((packed));
125 struct vring_used_elem ring[0];
126 } __attribute__((packed));
130 struct virtio_queue {
133 uint16_t cur_avail_idx;
135 addr_t ring_desc_addr;
136 addr_t ring_avail_addr;
137 addr_t ring_used_addr;
140 struct vring_desc * desc; // We can treat this as an array...
141 struct vring_avail * avail;
142 struct vring_used * used;