Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


9e6e69f76f227c2e7c9a322491bbccf56b01c36e
[palacios.git] / palacios / include / devices / lnx_virtio_pci.h
1 /* 
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.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
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.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21 #ifndef __DEVICES_LNX_VIRTIO_PCI_H__
22 #define __DEVICES_LNX_VIRTIO_PCI_H__
23
24 #ifdef __V3VEE__
25
26
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
31
32 // PCI Device IDs
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
38 #define VIRTIO_BLOCK_SUBDEVICE_ID 2
39 #define VIRTIO_BALLOON_SUBDEVICE_ID 5
40
41
42 #define HOST_FEATURES_PORT 0
43 #define GUEST_FEATURES_PORT 4
44 #define VRING_PG_NUM_PORT 8
45 #define VRING_SIZE_PORT 12
46 #define VRING_Q_SEL_PORT 14
47 #define VRING_Q_NOTIFY_PORT 16
48 #define VIRTIO_STATUS_PORT 18
49 #define VIRTIO_ISR_PORT 19
50
51 #define VIRTIO_PAGE_SHIFT 12
52
53
54 /* Descriptor flags */
55 /* This marks a buffer as continuing via the next field. */
56 #define VIRTIO_NEXT_FLAG       0x1
57 /* This marks a buffer as write-only (otherwise read-only). */
58 #define VIRTIO_WR_ONLY_FLAG      0x2
59
60
61 /* Used Flags */
62 /* This means don't notify other side when buffer added. */
63 #define VRING_NO_NOTIFY_FLAG  0x1
64
65
66 /* Avail Flags */
67 /* This means don't interrupt guest when buffer consumed. */
68 #define VIRTIO_NO_IRQ_FLAG      0x1
69
70 /* The virtio configuration space is a hybrid io/memory mapped model 
71  * All IO is done via IO port accesses
72  * The IO ports access fields in a virtio data structure, and the base io port 
73  *    coincides with the base address of the in memory structure
74  * There is a standard virtio structure of 20 bytes, followed by a 
75  *    device specific structure of n bytes.
76  * 
77  */
78 struct virtio_config {
79     uint32_t host_features;
80     uint32_t guest_features;
81     uint32_t vring_page_num;
82     uint16_t vring_ring_size;
83     uint16_t vring_queue_selector;
84     uint16_t vring_queue_notifier;
85     uint8_t status;
86     uint8_t pci_isr;
87 } __attribute__((packed));
88
89
90 struct vring_desc {
91     uint64_t addr_gpa;
92     uint32_t length;
93     uint16_t flags;
94     uint16_t next;
95 } __attribute__((packed));
96
97 struct vring_avail {
98     uint16_t flags;
99     uint16_t index;
100     uint16_t ring[0];
101 } __attribute__((packed));
102
103
104 struct vring_used_elem {
105     uint32_t id;
106     uint32_t length;
107 } __attribute__((packed));
108
109 struct vring_used {
110     uint16_t flags;
111     uint16_t index;
112     struct vring_used_elem ring[0];
113 } __attribute__((packed));
114
115
116
117 struct virtio_queue {
118     uint16_t queue_size;
119   
120     uint16_t cur_avail_idx;
121
122     addr_t ring_desc_addr;
123     addr_t ring_avail_addr;
124     addr_t ring_used_addr;
125   
126
127     struct vring_desc * desc; // We can treat this as an array...
128     struct vring_avail * avail;
129     struct vring_used * used;
130
131     uint32_t pfn;
132 };
133
134
135
136 #endif
137
138 #endif