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.


updated virtio block device to partially handle non-aligned IO requests
[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 #define VIRTIO_SYMBIOTIC_DEV_ID   0x100a
38 #define VIRTIO_SYMMOD_DEV_ID      0x100b
39 #define VIRTIO_VNET_DEV_ID        0x100c
40
41 #define VIRTIO_NET_SUBDEVICE_ID 1
42 #define VIRTIO_BLOCK_SUBDEVICE_ID 2
43 #define VIRTIO_CONSOLE_SUBDEVICE_ID 3
44 #define VIRTIO_BALLOON_SUBDEVICE_ID 5
45 #define VIRTIO_SYMBIOTIC_SUBDEVICE_ID 10
46 #define VIRTIO_SYMMOD_SUBDEVICE_ID 11
47 #define VIRTIO_VNET_SUBDEVICE_ID 12
48
49
50 #define HOST_FEATURES_PORT 0
51 #define GUEST_FEATURES_PORT 4
52 #define VRING_PG_NUM_PORT 8
53 #define VRING_SIZE_PORT 12
54 #define VRING_Q_SEL_PORT 14
55 #define VRING_Q_NOTIFY_PORT 16
56 #define VIRTIO_STATUS_PORT 18
57 #define VIRTIO_ISR_PORT 19
58
59 #define VIRTIO_PAGE_SHIFT 12
60
61
62 /* Descriptor flags */
63 /* This marks a buffer as continuing via the next field. */
64 #define VIRTIO_NEXT_FLAG       0x1
65 /* This marks a buffer as write-only (otherwise read-only). */
66 #define VIRTIO_WR_ONLY_FLAG      0x2
67
68
69 /* Used Flags */
70 /* This means don't notify other side when buffer added. */
71 #define VRING_NO_NOTIFY_FLAG  0x1
72
73
74 /* Avail Flags */
75 /* This means don't interrupt guest when buffer consumed. */
76 #define VIRTIO_NO_IRQ_FLAG      0x1
77
78
79 /* ISR Flags */
80 #define VIRTIO_ISR_ACTIVE 0x1
81 #define VIRTIO_ISR_CFG_CHANGED 0x2
82
83
84
85 /* The virtio configuration space is a hybrid io/memory mapped model 
86  * All IO is done via IO port accesses
87  * The IO ports access fields in a virtio data structure, and the base io port 
88  *    coincides with the base address of the in memory structure
89  * There is a standard virtio structure of 20 bytes, followed by a 
90  *    device specific structure of n bytes.
91  * 
92  */
93 struct virtio_config {
94     union {
95         uint8_t buf[20];
96         struct {
97             uint32_t host_features;
98             uint32_t guest_features;
99             uint32_t vring_page_num;
100             uint16_t vring_ring_size;
101             uint16_t vring_queue_selector;
102             uint16_t vring_queue_notifier;
103             uint8_t status;
104             uint8_t pci_isr;
105         } __attribute__((packed));
106     } __attribute__((packed));
107 } __attribute__((packed));
108
109
110 struct vring_desc {
111     uint64_t addr_gpa;
112     uint32_t length;
113     uint16_t flags;
114     uint16_t next;
115 } __attribute__((packed));
116
117 struct vring_avail {
118     uint16_t flags;
119     uint16_t index;
120     uint16_t ring[0];
121 } __attribute__((packed));
122
123
124 struct vring_used_elem {
125     uint32_t id;
126     uint32_t length;
127 } __attribute__((packed));
128
129 struct vring_used {
130     uint16_t flags;
131     uint16_t index;
132     struct vring_used_elem ring[0];
133 } __attribute__((packed));
134
135
136
137 struct virtio_queue {
138     uint16_t queue_size;
139   
140     uint16_t cur_avail_idx;
141
142     addr_t ring_desc_addr;
143     addr_t ring_avail_addr;
144     addr_t ring_used_addr;
145   
146     struct vring_desc * desc; // We can treat this as an array...
147     struct vring_avail * avail;
148     struct vring_used * used;
149
150     uint32_t pfn;
151 };
152
153
154
155 #endif
156
157 #endif